Index: /branches/2010_and_older/dev_001_GM/AGRIF/AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AA_make	(revision 4536)
@@ -0,0 +1,123 @@
+#- $Id$
+
+TMP=../../../tmp
+
+SRM=/bin/rm -f
+
+#-Q- sx8mercure C_L	= $(FC_L) 
+#-Q- sx8mercure C_O	= $(FC_O) 
+#-Q- sx8brodie C_L= $(FC_L) 
+#-Q- sx8brodie C_O= $(FC_O) 
+#-Q- sxdkrz C_L	= $(FC_L) 
+#-Q- sxdkrz C_O	= $(FC_O) 
+#-Q- eshpux C_L	= $(FC_L) 
+#-Q- eshpux C_O	= $(FC_O) 
+#-Q- aix F_O = $(w_w) -I$(MODDIR) -qmoddir=$(MODDIR) -qextname
+#-Q- osxxlf F_O = $(w_w) -I$(MODDIR) -qmoddir=$(MODDIR) -qextname
+#-Q- linux F_O = $(F_D) $(F_P) -Mfixed -module $(MODDIR)
+
+AGRIFOBJS=AGRIF_OBJS
+AGRIFFILES=AGRIF_FILES
+AGRIFYOURFILES=AGRIF_YOURFILES
+
+FILENAMES= modbc modmpp modcluster modinit modinitvars modinterp  \
+	   modtypes modbcfunction modutil modcurgridfunctions \
+	   modmask modsauv modupdate modinterpbasic\
+	   modupdatebasic modlinktomodel modarrays modflux
+	   
+OBJS1=$(addprefix $(AGRIFOBJS)/,$(FILENAMES))
+OBJS=$(addsuffix .o,$(OBJS1))
+
+
+AGRIF_FILES1=$(addprefix $(AGRIFFILES)/,$(FILENAMES))
+AGRIF_FILES=$(addsuffix .F,$(AGRIF_FILES1))
+
+all :   conv_exe key $(MODDIR)/libagrif.a $(SXMODEL_LIB)
+	@echo AGRIF is OK
+
+conv_exe : 
+	@( cd LIB ; $(M_K) -f Makefile C_L="$(C_L)" C_O="$(C_O)" )
+
+key : 
+	-@if [ "`cat KEY_CPP`" != "$(P_P)" ] ; then \
+	echo "$(P_P)" > KEY_CPP ; fi
+
+$(MODDIR)/libagrif.a : $(OBJS)
+	@$(A_C) $@ $(OBJS)
+
+$(SXMODEL_LIB) : $(OBJS)
+#-Q- sxdkrz     @$(A_X) $@ $(OBJS)
+#-Q- eshpux     @$(A_X) $@ $(OBJS)
+
+$(AGRIFOBJS)/%.o : $(AGRIFFILES)/%.F KEY_CPP
+	@$(SRM) $(AGRIFYOURFILES)/$(*F).f
+	@$(P_C) $(P_O) $(AGRIFFILES)/$(*F).F > $(AGRIFYOURFILES)/$(*F).f
+	@$(F_C) $(F_O) $(FFLAGS_EXTEND) $(AGRIF_OPTS) -c $(AGRIFYOURFILES)/$(*F).f -o $(AGRIFOBJS)/$(*F).o
+#-Q- linux	@$(SRM) $*.lst
+#-Q- ibm	@$(SRM) $*.lst
+#-Q- aix	@$(SRM) $*.lst
+#-Q- sx8mercure	mv *.mod $(MODDIR)
+#-Q- sx8brodie	mv *.mod $(MODDIR)
+#-Q- sxdkrz	mv *.mod $(MODDIR)
+#-Q- eshpux	mv *.mod $(MODDIR)
+#-Q- solaris	mv *.mod $(MODDIR)
+
+
+$(AGRIFOBJS)/modarrays.o: $(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modbc.o: $(AGRIFOBJS)/modinterp.o
+
+$(AGRIFOBJS)/modbcfunction.o: $(AGRIFOBJS)/modupdate.o \
+			 $(AGRIFOBJS)/modflux.o  \
+			 $(AGRIFOBJS)/modbc.o 
+
+$(AGRIFOBJS)/modcluster.o: $(AGRIFOBJS)/modsauv.o \
+			$(AGRIFOBJS)/modinitvars.o \
+			$(AGRIFOBJS)/modcurgridfunctions.o
+
+$(AGRIFOBJS)/modcurgridfunctions.o: $(AGRIFOBJS)/modinit.o
+
+$(AGRIFOBJS)/modinit.o: $(AGRIFOBJS)/modlinktomodel.o \
+			$(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modinitvars.o: $(AGRIFOBJS)/modlinktomodel.o \
+			$(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modinterpbasic.o: $(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modinterp.o: $(AGRIFOBJS)/modcurgridfunctions.o \
+			$(AGRIFOBJS)/modmask.o \
+			$(AGRIFOBJS)/modarrays.o \
+			$(AGRIFOBJS)/modmpp.o \
+			$(AGRIFOBJS)/modinterpbasic.o
+
+$(AGRIFOBJS)/modlinktomodel.o: $(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modmask.o: $(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modsauv.o: $(AGRIFOBJS)/modarrays.o \
+			$(AGRIFOBJS)/modlinktomodel.o \
+			$(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modupdatebasic.o: $(AGRIFOBJS)/modtypes.o
+
+$(AGRIFOBJS)/modupdate.o: $(AGRIFOBJS)/modmask.o \
+			$(AGRIFOBJS)/modcurgridfunctions.o \
+			$(AGRIFOBJS)/modarrays.o \
+			$(AGRIFOBJS)/modmpp.o \
+			$(AGRIFOBJS)/modupdatebasic.o
+
+$(AGRIFOBJS)/modutil.o: $(AGRIFOBJS)/modcurgridfunctions.o \
+			$(AGRIFOBJS)/modcluster.o
+
+$(AGRIFOBJS)/modmpp.o: $(AGRIFOBJS)/modtypes.o \
+			$(AGRIFOBJS)/modarrays.o
+
+clean : FORCE
+	$(SRM) $(OBJS) $(MODOBJS)$(LIBDIR)/libagrif.a 
+	
+cleanall : FORCE
+	$(SRM) $(OBJS) $(MODOBJS)$(LIBDIR)/libagrif.a 
+	@(cd LIB ; $(M_K) -f Makefile clean )
+
+FORCE :
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AA_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AA_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AA_make.ldef	(revision 4536)
@@ -0,0 +1,27 @@
+#- $Id$
+#---------------------------------------------------------------------
+#- Creation des elements relatifs a AGRIF (lib, config)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#---------------------------------------------------------------------
+LIBDIR = ../../lib
+MODDIR = $(LIBDIR)
+#---------------------------------------------------------------------
+#--- -DNC_REAL option is needed if compiled in simple precision
+#--- In case you switch to double precision use -DNC_DOUBLE
+#-
+# Compilation:
+#-Q- lxiv7 FFLAGS_EXTEND=  -I..
+#-Q- lxiv8 FFLAGS_EXTEND=  -I..
+#-Q- sun   FFLAGS_EXTEND= -I..
+#-Q- aix   FFLAGS_EXTEND = -I.. -I$(HOME)/include/ -qsuffix=f=f
+#-Q- aix   AGRIF_OPTS = -qfixed -qrecur
+#-Q- ibm   FFLAGS_EXTEND = -I.. -I$(HOME)/include/ -qsuffix=f=f
+#-Q- ibm   AGRIF_OPTS = -qfixed -qrecur
+#-
+MODEL_LIB = $(LIBDIR)/libagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxdkrz SXMODEL_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- eshpux SXMODEL_LIB = $(LIBDIR)/libsxagrif.a
+#-
+P_P=$(AGRIF_MPI)
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modarrays.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modarrays.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modarrays.F	(revision 4536)
@@ -0,0 +1,1213 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Arrays
+C      
+      Module Agrif_Arrays
+      Use Agrif_Types
+C
+      implicit none
+C      
+      Contains
+C     **************************************************************************
+CCC   Subroutine Agrif_Childbounds
+C     **************************************************************************
+C
+      Subroutine Agrif_Childbounds(nbdim,lboundloc,uboundloc,
+     &                 pttab,petab,pttruetab,cetruetab,memberin)
+C
+CCC   Description:
+CCC   Subroutine calculating the global indices of the child grid
+C
+C
+C     Declarations:
+C
+
+C
+C     Arguments
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim) :: lboundloc,uboundloc
+      INTEGER,DIMENSION(nbdim) :: pttab,petab,pttruetab,cetruetab
+      LOGICAL :: memberin
+C
+C     Local variables
+      INTEGER :: i,lbglob,ubglob
+C
+#ifdef AGRIF_MPI
+      INTEGER :: indglob1,indglob2
+#endif
+C
+C
+      do i = 1,nbdim
+C
+        lbglob = lboundloc(i)
+        ubglob = uboundloc(i)
+C
+#ifdef AGRIF_MPI
+C
+        Call AGRIF_InvLoc(lbglob,Agrif_ProcRank,i,indglob1)
+C
+        Call AGRIF_InvLoc(ubglob,Agrif_ProcRank,i,indglob2)
+C
+        pttruetab(i) = max(pttab(i),indglob1)        
+C
+        cetruetab(i) = min(petab(i),indglob2)                 
+C
+#else
+C
+        pttruetab(i) = max(pttab(i),lbglob)        
+C
+        cetruetab(i) = min(petab(i),ubglob)
+C
+#endif
+C
+      enddo
+
+      memberin = .TRUE.
+
+      do i=1,nbdim
+        IF (cetruetab(i) < pttruetab(i)) THEN
+          memberin = .FALSE.
+          EXIT
+        ENDIF
+      enddo
+C
+      Return
+C
+C
+      End Subroutine Agrif_Childbounds
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_Get_bound
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_Get_bound(Variable,
+     &                           lower,upper,indice,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to get the lower and the upper boundaries of a
+C     table. Output datas are scalar.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      ! we want extract boundaries of this table
+      TYPE(AGRIF_Variable), Pointer :: Variable    
+      INTEGER              :: lower,upper ! output data
+      ! direction in wich we want to know the dimension
+      INTEGER              :: indice      
+      INTEGER              :: nbdim       ! dimension of the table
+C
+C     Local variables
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+           lower = lbound(Variable % array1,indice)
+           upper = ubound(Variable % array1,indice)
+      CASE (2)
+           lower = lbound(Variable % array2,indice)
+           upper = ubound(Variable % array2,indice)
+      CASE (3)
+           lower = lbound(Variable % array3,indice)
+           upper = ubound(Variable % array3,indice)
+      CASE (4)
+           lower = lbound(Variable % array4,indice)
+           upper = ubound(Variable % array4,indice)
+      CASE (5)
+           lower = lbound(Variable % array5,indice)
+           upper = ubound(Variable % array5,indice)
+      CASE (6)
+           lower = lbound(Variable % array6,indice)
+           upper = ubound(Variable % array6,indice)
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_Get_bound       
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Get_bound_dimension
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_Get_bound_dimension(Variable,
+     &                              lower,upper,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to get the lower and the upper boundaries of a
+C        table. Output datas are scalar.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      ! we want extract boundaries of this table
+      TYPE(AGRIF_Variable), Pointer     :: Variable    
+      INTEGER                  :: nbdim       ! dimension of the table
+      INTEGER,DIMENSION(nbdim) :: lower,upper ! output data
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+           lower = lbound(Variable % array1)
+           upper = ubound(Variable % array1)
+      CASE (2)
+           lower = lbound(Variable % array2)
+           upper = ubound(Variable % array2)
+      CASE (3)
+           lower = lbound(Variable % array3)
+           upper = ubound(Variable % array3)
+      CASE (4)
+           lower = lbound(Variable % array4)
+           upper = ubound(Variable % array4)
+      CASE (5)
+           lower = lbound(Variable % array5)
+           upper = ubound(Variable % array5)
+      CASE (6)
+           lower = lbound(Variable % array6)
+           upper = ubound(Variable % array6)
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_Get_bound_dimension     
+      
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_allocation
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_allocation(Variable,inf,sup,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to Allocate the table Variable
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer     :: Variable    
+      INTEGER                  :: nbdim       ! dimension of the table
+      INTEGER,DIMENSION(nbdim) :: inf,sup
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+         allocate(Variable%array1(
+     &            inf(1):sup(1)))
+      CASE (2)
+          allocate(Variable%array2(
+     &            inf(1):sup(1),
+     &            inf(2):sup(2)))
+      CASE (3)
+         allocate(Variable%array3(
+     &            inf(1):sup(1),
+     &            inf(2):sup(2),
+     &            inf(3):sup(3)))
+      CASE (4)
+         allocate(Variable%array4(
+     &            inf(1):sup(1),
+     &            inf(2):sup(2),
+     &            inf(3):sup(3),
+     &            inf(4):sup(4)))
+      CASE (5)
+         allocate(Variable%array5(
+     &            inf(1):sup(1),
+     &            inf(2):sup(2),
+     &            inf(3):sup(3),
+     &            inf(4):sup(4),
+     &            inf(5):sup(5)))
+      CASE (6)
+         allocate(Variable%array6(
+     &            inf(1):sup(1),
+     &            inf(2):sup(2),
+     &            inf(3):sup(3),
+     &            inf(4):sup(4),
+     &            inf(5):sup(5),
+     &            inf(6):sup(6)))
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_allocation
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_deallocation
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_deallocation(Variable,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to give the same value to the table Variable
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer     :: Variable    
+      INTEGER                  :: nbdim       ! dimension of the table
+C
+C     Local variables       
+C
+
+      SELECT CASE (nbdim)
+      CASE (1)
+         Deallocate(Variable%array1)
+      CASE (2)
+         Deallocate(Variable%array2)
+      CASE (3)
+         Deallocate(Variable%array3)
+      CASE (4)
+         Deallocate(Variable%array4)
+      CASE (5)
+         Deallocate(Variable%array5)
+      CASE (6)
+         Deallocate(Variable%array6)
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_deallocation
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_Full_VarEQreal
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_Full_VarEQreal(Variable,Value,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to get the lower and the upper boundaries of a
+C        table. Output datas are scalar.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer :: Variable    
+      REAL                 :: Value       
+      INTEGER              :: nbdim       ! dimension of the table
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+        Variable%array1 = Value      
+      CASE (2)
+        Variable%array2 = Value
+      CASE (3)
+        Call Agrif_set_tozero3D(Variable%array3)
+!        Variable%array3 = Value
+      CASE (4)
+        Variable%array4 = Value
+      CASE (5)
+        Variable%array5 = Value
+      CASE (6)
+        Variable%array6 = Value
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_Full_VarEQreal   
+      
+      Subroutine Agrif_set_tozero3D(tab3D)
+      real,dimension(:,:,:),target :: tab3D
+      
+      tab3D = 0.
+      
+      end subroutine agrif_set_tozero3D    
+C
+C
+#if !defined AGRIF_MPI
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_VarEQreal
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_VarEQreal(Variable,inf,sup,Value,nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to give the same value to a part of 
+C        the table Variable
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer :: Variable    
+      REAL                 :: Value       
+      INTEGER              :: nbdim       ! dimension of the table
+      INTEGER,DIMENSION(nbdim) :: inf,sup
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+         Variable%array1(
+     &             inf(1):sup(1)
+     &             )  = Value
+      CASE (2)
+         Variable%array2(
+     &             inf(1):sup(1),
+     &             inf(2):sup(2)
+     &             )  = Value
+      CASE (3)
+         Variable%array3(
+     &             inf(1):sup(1),
+     &             inf(2):sup(2),
+     &             inf(3):sup(3)
+     &             )  = Value
+      CASE (4)
+         Variable%array4(
+     &             inf(1):sup(1),
+     &             inf(2):sup(2),
+     &             inf(3):sup(3),
+     &             inf(4):sup(4)
+     &             )  = Value
+      CASE (5)
+         Variable%array5(
+     &             inf(1):sup(1),
+     &             inf(2):sup(2),
+     &             inf(3):sup(3),
+     &             inf(4):sup(4),
+     &             inf(5):sup(5)
+     &             )  = Value
+      CASE (6)
+         Variable%array6(
+     &             inf(1):sup(1),
+     &             inf(2):sup(2),
+     &             inf(3):sup(3),
+     &             inf(4):sup(4),
+     &             inf(5):sup(5),
+     &             inf(6):sup(6)
+     &             )  = Value
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_VarEQreal       
+#endif
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_VarEQvar
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_VarEQvar(Variable,inf,sup,
+     &                                Variable2,inf2,sup2,
+     &                                nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to give the value of a part of the table 
+C        Variable2 to the table Variable
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer     :: Variable
+      TYPE(AGRIF_Variable), Pointer     :: Variable2
+      INTEGER                  :: nbdim       ! dimension of the table
+      INTEGER,DIMENSION(nbdim) :: inf,sup
+      INTEGER,DIMENSION(nbdim) :: inf2,sup2
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+         Variable%array1(inf(1):sup(1)) = 
+     &         Variable2%array1(inf2(1):sup2(1))
+      CASE (2)
+     
+      Call Agrif_Copy_2d(Variable%array2,Variable2%array2,
+     &  lbound(Variable%array2),
+     &  lbound(Variable2%array2),
+     &  inf,sup,inf2,sup2)
+          
+      CASE (3)
+
+      Call Agrif_Copy_3d(Variable%array3,Variable2%array3,
+     &  lbound(Variable%array3),
+     &  lbound(Variable2%array3),
+     &  inf,sup,inf2,sup2)
+
+      CASE (4)
+      
+      Call Agrif_Copy_4d(Variable%array4,Variable2%array4,
+     &  lbound(Variable%array4),
+     &  lbound(Variable2%array4),
+     &  inf,sup,inf2,sup2)
+     
+      CASE (5)
+        Variable%array5(inf(1):sup(1),
+     &                         inf(2):sup(2), 
+     &                         inf(3):sup(3),
+     &                         inf(4):sup(4), 
+     &                         inf(5):sup(5)) = 
+     &         Variable2%array5(inf2(1):sup2(1),
+     &                          inf2(2):sup2(2),
+     &                          inf2(3):sup2(3),
+     &                          inf2(4):sup2(4),
+     &                          inf2(5):sup2(5))
+      CASE (6)
+        Variable%array6(inf(1):sup(1),
+     &                         inf(2):sup(2),
+     &                         inf(3):sup(3),
+     &                         inf(4):sup(4),
+     &                         inf(5):sup(5),
+     &                         inf(6):sup(6)) = 
+     &         Variable2%array6(inf2(1):sup2(1),
+     &                          inf2(2):sup2(2),
+     &                          inf2(3):sup2(3),
+     &                          inf2(4):sup2(4),
+     &                          inf2(5):sup2(5),
+     &                          inf2(6):sup2(6))
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_VarEQvar
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_nbdim_Full_VarEQvar
+C     **************************************************************************
+C
+      Subroutine Agrif_nbdim_Full_VarEQvar(Variable,Variable2,
+     &                                nbdim)
+C
+CCC   Description:
+CCC   This subroutine is used to give the value of the table Variable2 
+C        to the table Variable
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_Variable), Pointer     :: Variable
+      TYPE(AGRIF_Variable), Pointer     :: Variable2
+      INTEGER                  :: nbdim       ! dimension of the table
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+          Variable%array1 = Variable2%array1
+      CASE (2)
+          Variable%array2 = Variable2%array2
+      CASE (3)
+          Variable%array3 = Variable2%array3
+      CASE (4)
+          Variable%array4 = Variable2%array4
+      CASE (5)
+          Variable%array5 = Variable2%array5
+      CASE (6)
+          Variable%array6 = Variable2%array6
+      END SELECT
+C
+      return
+C
+      End Subroutine Agrif_nbdim_Full_VarEQvar
+C
+C
+
+#ifdef AGRIF_MPI
+C     **************************************************************************
+CCC   Subroutine GiveAgrif_SpecialValueToTab_mpi
+C     **************************************************************************
+C
+      Subroutine GiveAgrif_SpecialValueToTab_mpi(Variable1,Variable2,
+     &                  bound1,lower,upper,Value,nbdim)
+C
+CCC   Description:
+CCC   
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_VARIABLE), Pointer    :: Variable1
+      TYPE(AGRIF_VARIABLE), Pointer    :: Variable2
+      INTEGER                  :: nbdim
+      INTEGER,DIMENSION(:,:,:) :: bound1
+      INTEGER,DIMENSION(nbdim) :: lower,upper
+      REAL                     :: Value
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+             Where (Variable1 % array1(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2)) 
+     &            == Value)
+             Variable2 % array1(lower(1):upper(1))
+     &                        = Value
+C      
+              End Where
+      CASE (2)
+             Where (Variable1 % array2(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
+     &           bound1(lower(2),2,2):bound1(upper(2),2,2)) 
+     &            == Value)
+             Variable2 % array2(lower(1):upper(1),
+     &                          lower(2):upper(2))
+     &                        = Value
+C      
+              End Where
+      CASE (3)
+             Where (Variable1 % array3(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
+     &           bound1(lower(2),2,2):bound1(upper(2),2,2), 
+     &           bound1(lower(3),3,2):bound1(upper(3),3,2)) 
+     &            == Value)
+             Variable2 % array3(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3))
+     &                         = Value
+C      
+              End Where
+      CASE (4)
+             Where (Variable1 % array4(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
+     &           bound1(lower(2),2,2):bound1(upper(2),2,2), 
+     &           bound1(lower(3),3,2):bound1(upper(3),3,2),
+     &           bound1(lower(4),4,2):bound1(upper(4),4,2)) 
+     &            == Value)
+             Variable2 % array4(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4))
+     &                        = Value
+C      
+              End Where
+      CASE (5)
+             Where (Variable1 % array5(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
+     &           bound1(lower(2),2,2):bound1(upper(2),2,2),
+     &           bound1(lower(3),3,2):bound1(upper(3),3,2),
+     &           bound1(lower(4),4,2):bound1(upper(4),4,2),
+     &           bound1(lower(5),5,2):bound1(upper(5),5,2)) 
+     &            == Value)
+             Variable2 % array5(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4),
+     &                          lower(5):upper(5))
+     &                        = Value
+C      
+              End Where
+      CASE (6)
+             Where (Variable1 % array6(
+     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
+     &           bound1(lower(2),2,2):bound1(upper(2),2,2),
+     &           bound1(lower(2),3,2):bound1(upper(3),3,2),
+     &           bound1(lower(4),4,2):bound1(upper(4),4,2),
+     &           bound1(lower(5),5,2):bound1(upper(5),5,2),
+     &           bound1(lower(6),6,2):bound1(upper(6),6,2)) 
+     &            == Value)
+             Variable2 % array6(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4),
+     &                          lower(5):upper(5),
+     &                          lower(6):upper(6))
+     &                        = Value
+C      
+              End Where
+      END SELECT
+C
+      return
+C
+      End Subroutine GiveAgrif_SpecialValueToTab_mpi    
+#else
+C     **************************************************************************
+CCC   Subroutine GiveAgrif_SpecialValueToTab
+C     **************************************************************************
+C
+      Subroutine GiveAgrif_SpecialValueToTab(Variable1,Variable2,
+     &                  lower,upper,Value,nbdim)
+C
+CCC   Description:
+CCC   
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_VARIABLE), Pointer    :: Variable1
+      TYPE(AGRIF_VARIABLE), Pointer    :: Variable2
+      INTEGER                  :: nbdim
+      INTEGER,DIMENSION(nbdim) :: lower,upper
+      REAL                     :: Value
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+             Where (Variable1 % array1(
+     &           lower(1):upper(1))
+     &            == Value)
+             Variable2 % array1(lower(1):upper(1))
+     &                        = Value
+C      
+              End Where
+      CASE (2)
+             Where (Variable1 % array2(
+     &           lower(1):upper(1),
+     &           lower(2):upper(2)) 
+     &            == Value)
+             Variable2 % array2(lower(1):upper(1),
+     &                          lower(2):upper(2))
+     &                        = Value
+C      
+              End Where
+      CASE (3)
+             Where (Variable1 % array3(
+     &           lower(1):upper(1),
+     &           lower(2):upper(2), 
+     &           lower(3):upper(3)) 
+     &            == Value)
+             Variable2 % array3(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3))
+     &                         = Value
+C      
+              End Where
+      CASE (4)
+             Where (Variable1 % array4(
+     &           lower(1):upper(1),
+     &           lower(2):upper(2), 
+     &           lower(3):upper(3),
+     &           lower(4):upper(4)) 
+     &            == Value)
+             Variable2 % array4(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4))
+     &                        = Value
+C      
+              End Where
+      CASE (5)
+             Where (Variable1 % array5(
+     &           lower(1):upper(1),
+     &           lower(2):upper(2),
+     &           lower(3):upper(3),
+     &           lower(4):upper(4),
+     &           lower(5):upper(5)) 
+     &            == Value)
+             Variable2 % array5(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4),
+     &                          lower(5):upper(5))
+     &                        = Value
+C      
+              End Where
+      CASE (6)
+             Where (Variable1 % array6(
+     &           lower(1):upper(1),
+     &           lower(2):upper(2),
+     &           lower(2):upper(3),
+     &           lower(4):upper(4),
+     &           lower(5):upper(5),
+     &           lower(6):upper(6)) 
+     &            == Value)
+             Variable2 % array6(lower(1):upper(1),
+     &                          lower(2):upper(2),
+     &                          lower(3):upper(3),
+     &                          lower(4):upper(4),
+     &                          lower(5):upper(5),
+     &                          lower(6):upper(6))
+     &                        = Value
+C      
+              End Where
+      END SELECT
+C
+      return
+C
+      End Subroutine GiveAgrif_SpecialValueToTab   
+#endif
+C
+C
+#ifdef AGRIF_MPI
+C     **************************************************************************
+CCC   Subroutine Where_ValTabToTab_mpi
+C     **************************************************************************
+C
+      Subroutine Where_ValTabToTab_mpi(
+     &                  Variable1,Variable2,
+     &                  lower,upper,Value,nbdim)
+C
+CCC   Description:
+CCC   
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+C
+      TYPE(AGRIF_VARIABLE), Pointer     :: Variable1
+      TYPE(AGRIF_VARIABLE), Pointer     :: Variable2
+      INTEGER                  :: nbdim
+      INTEGER,DIMENSION(nbdim) :: lower,upper
+      REAL                     :: Value
+      INTEGER :: i,j,k,l,m,n
+C
+C     Local variables       
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+            DO i = lower(1),upper(1)
+              IF (variable1%array1(i) == Value) then
+                variable1%array1(i)=Variable2%array1(i)
+              ENDIF
+            ENDDO
+      CASE (2)
+            DO j = lower(2),upper(2)
+            DO i = lower(1),upper(1)
+              IF (variable1%array2(i,j) == Value) then
+                variable1%array2(i,j)=Variable2%array2(i,j)
+              ENDIF
+            ENDDO
+            ENDDO
+      CASE (3)
+            DO k = lower(3),upper(3)
+            DO j = lower(2),upper(2)
+            DO i = lower(1),upper(1)
+              IF (variable1%array3(i,j,k) == Value) then
+                variable1%array3(i,j,k)=Variable2%array3(i,j,k)
+              ENDIF
+            ENDDO
+            ENDDO
+            ENDDO
+      CASE (4)
+            DO l = lower(4),upper(4)
+            DO k = lower(3),upper(3)
+            DO j = lower(2),upper(2)
+            DO i = lower(1),upper(1)
+              IF (variable1%array4(i,j,k,l) == Value) then
+                variable1%array4(i,j,k,l)=Variable2%array4(i,j,k,l)
+              ENDIF
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+      CASE (5)
+            DO m = lower(5),upper(5)
+            DO l = lower(4),upper(4)
+            DO k = lower(3),upper(3)
+            DO j = lower(2),upper(2)
+            DO i = lower(1),upper(1)
+              IF (variable1%array5(i,j,k,l,m) == Value) then
+              variable1%array5(i,j,k,l,m)=Variable2%array5(i,j,k,l,m)
+              ENDIF
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+      CASE (6)
+            DO n = lower(6),upper(6)
+            DO m = lower(5),upper(5)
+            DO l = lower(4),upper(4)
+            DO k = lower(3),upper(3)
+            DO j = lower(2),upper(2)
+            DO i = lower(1),upper(1)
+              IF (variable1%array6(i,j,k,l,m,n) == Value) then
+            variable1%array6(i,j,k,l,m,n)=Variable2%array6(i,j,k,l,m,n)
+              ENDIF
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+            ENDDO
+      END SELECT
+C
+      return
+C
+      End Subroutine Where_ValTabToTab_mpi    
+#endif
+
+C     **************************************************************************
+CCC   Subroutine PreProcessToInterpOrUpdate
+C     **************************************************************************
+C
+      Subroutine PreProcessToInterpOrUpdate(parent,child,
+     &             petab_Child,
+     &             pttab_Child,pttab_Parent,
+     &             s_Child,s_Parent,
+     &             ds_Child,ds_Parent,
+     &             nbdim)
+C
+CCC   Description:
+CCC   
+C
+C     Declarations:
+C      
+C     arguments                                   
+      TYPE(AGRIF_PVariable) :: parent   ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child    ! Variable on the child grid
+      INTEGER :: nbdim                  
+      INTEGER,DIMENSION(6) :: pttab_child  
+      INTEGER,DIMENSION(6) :: petab_child      
+      INTEGER,DIMENSION(6) :: pttab_parent  
+      TYPE(AGRIF_Variable), Pointer :: root ! Pointer on the variable of the 
+                                            ! root grid
+      TYPE(Agrif_Grid), Pointer :: Agrif_Child_Gr,Agrif_Parent_Gr
+      REAL, DIMENSION(6) :: s_child,s_parent
+      REAL, DIMENSION(6) :: ds_child,ds_parent
+C     locals variables
+      INTEGER :: n
+      
+C
+C     Arguments      
+C
+
+C
+C     Local variables       
+C
+      Agrif_Child_Gr => Agrif_Curgrid
+      Agrif_Parent_Gr => Agrif_Curgrid % parent
+C
+      root => child % var % root_var 
+C
+C     Number of dimensions of the current grid
+      nbdim = root % nbdim
+C      
+      do n=1,nbdim
+C            
+        Select case(root % interptab(n))
+C
+C       Value of interptab(n) can be either x,y,z or N for a no space 
+C       DIMENSION            
+C
+C         The DIMENSION is 'x'
+          case('x')
+C
+            pttab_Child(n) = root % point(1)
+C            
+            pttab_Parent(n) = root % point(1)
+C        
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(1)
+C
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(1)
+C        
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(1)
+C
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(1)
+C                      
+            if (root % posvar(n).EQ.1) then
+C          
+              petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(1)
+C        
+              else
+C          
+                petab_Child(n) = pttab_Child(n) + 
+     &                              Agrif_Child_Gr%nb(1) - 1
+C          
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+C
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+C        
+            endif                  
+C
+C         The DIMENSION is 'y'
+          case('y')
+C
+            pttab_Child(n) = root % point(2)
+C            
+            pttab_Parent(n) = root % point(2)
+C        
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(2)
+C
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(2) 
+C        
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(2)
+C
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(2)
+C                      
+            if (root % posvar(n).EQ.1) then
+C          
+             petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(2)
+C          
+              else
+C          
+                petab_Child(n) = pttab_Child(n) + 
+     &                       Agrif_Child_Gr%nb(2) - 1
+C          
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+C
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+C        
+            endif
+            
+C
+C         The DIMENSION is 'z'                            
+          case('z')
+C
+            pttab_Child(n) = root % point(3)
+C            
+            pttab_Parent(n) = root % point(3)
+C        
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(3)
+C
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(3)
+C        
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(3)
+C
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(3)
+C                      
+            if (root % posvar(n).EQ.1) then
+C          
+             petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(3)
+C          
+              else
+C          
+                petab_Child(n) = pttab_Child(n) + 
+     &                      Agrif_Child_Gr%nb(3) - 1
+C
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+C
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+C        
+            endif       
+C 
+C         The DIMENSION is not space                            
+          case('N')
+C
+C         The next coefficients are calculated in order to do a simple copy of 
+C         values of the grid variable when the procedure of interpolation is 
+C         called for this DIMENSION 
+C      
+            Call Agrif_nbdim_Get_bound(child % var,
+     &                           pttab_Child(n),petab_Child(n),n,nbdim)
+C
+C           No interpolation but only a copy of the values of the grid variable
+C
+            pttab_Parent(n) = pttab_Child(n)
+C              
+            s_Child(n)=0.
+C      
+            s_Parent(n)=0. 
+C      
+            ds_Child(n)=1.
+C      
+            ds_Parent(n)=1.
+C
+        End select
+C            
+      enddo     
+C
+      return
+C
+      End Subroutine PreProcessToInterpOrUpdate     
+
+#ifdef AGRIF_MPI
+C
+C     **************************************************************************
+CCC   Subroutine GetLocalBoundaries
+C     **************************************************************************
+C
+      Subroutine GetLocalBoundaries(tab1,tab2,i,lb,ub,deb,fin)
+C
+CCC   Descritpion:
+C 
+C
+C     Declarations:
+C
+
+C
+C
+C     Scalar arguments
+      INTEGER  ::  tab1,tab2
+      INTEGER  ::  i
+      INTEGER  ::  lb,ub
+      INTEGER  ::  deb,fin
+C
+C     Local scalars
+      INTEGER  ::  imin,imax
+      INTEGER  ::  i1,i2
+C
+C
+      Call AGRIF_InvLoc(lb,AGRIF_ProcRank,i,imin)
+C
+      Call AGRIF_InvLoc(ub,AGRIF_ProcRank,i,imax)
+C
+C
+      if (imin > tab2) then
+C
+          i1 = imax - imin
+C
+        else
+C
+          i1 = max(tab1 - imin,0)
+C
+      endif
+C
+      if (imax < tab1) then
+C
+          i2 = -(imax - imin)
+C
+        else
+C
+          i2 = min(tab2 - imax,0)
+C
+      endif
+C
+      deb = lb + i1
+C
+      fin = ub + i2
+C
+C
+      End Subroutine GetLocalBoundaries
+C
+#endif
+C
+C
+#ifdef AGRIF_MPI
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_GlobtoLocInd2
+C     **************************************************************************
+C
+      Subroutine Agrif_GlobtoLocInd2(tabarray,lboundl,uboundl,tab1,tab2,
+     &                              nbdim,rank,member)
+C
+CCC   Description:
+CCC   For a global index located on the current processor, tabarray gives the 
+CCC   corresponding local index   
+C
+C
+C     Declarations:
+C
+
+C
+C     Arguments
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim) :: tab1,tab2
+      INTEGER,DIMENSION(nbdim,2,2 ) :: tabarray
+      INTEGER,DIMENSION(nbdim) :: lboundl,uboundl
+      INTEGER :: rank
+      LOGICAL :: member
+C    
+C     Local variables
+      INTEGER :: i,i1,k
+      INTEGER :: nbloc(nbdim)
+C
+C
+      tabarray(:,1,:) =  HUGE(1)
+      tabarray(:,2,:) =  -HUGE(1)
+
+      nbloc = 0
+C        
+      do i = 1,nbdim
+C       
+        Call Agrif_Invloc(lboundl(i),rank,i,i1)
+        
+        do k=tab1(i)+lboundl(i)-i1,tab2(i)+lboundl(i)-i1
+          IF ((k .GE. lboundl(i)) .AND. (k.LE.uboundl(i))) THEN
+            nbloc(i) = 1
+            tabarray(i,1,1) = min(tabarray(i,1,1),k-lboundl(i)+i1)
+            tabarray(i,2,1) = max(tabarray(i,2,1),k-lboundl(i)+i1)
+        
+            tabarray(i,1,2) = min(tabarray(i,1,2),k)
+            tabarray(i,2,2) = max(tabarray(i,2,2),k)
+          ENDIF
+        enddo
+C
+      enddo
+
+      member = .FALSE.
+      IF (sum(nbloc) == nbdim) member = .TRUE.
+C
+      Return
+C
+C
+      End Subroutine Agrif_GlobtoLocInd2
+C
+#endif      
+
+      Subroutine Agrif_Copy_2d(tabout,tabin,l,m,inf,sup,inf2,sup2)
+      integer,dimension(2) :: l,m,inf,sup,inf2,sup2
+      real,target,dimension(l(1):,l(2):) :: tabout
+      real,target,dimension(m(1):,m(2):) :: tabin
+          tabout(inf(1):sup(1),
+     &                         inf(2):sup(2)) = 
+     &         tabin(inf2(1):sup2(1),
+     &                          inf2(2):sup2(2))
+      End Subroutine Agrif_Copy_2d
+      
+      Subroutine Agrif_Copy_3d(tabout,tabin,l,m,inf,sup,inf2,sup2)
+      integer,dimension(3) :: l,m,inf,sup,inf2,sup2
+      real,target,dimension(l(1):,l(2):,l(3):) :: tabout
+      real,target,dimension(m(1):,m(2):,m(3):) :: tabin
+          tabout(inf(1):sup(1),
+     &                         inf(2):sup(2), 
+     &                         inf(3):sup(3)) = 
+     &         tabin(inf2(1):sup2(1),
+     &                          inf2(2):sup2(2),
+     &                          inf2(3):sup2(3))
+      End Subroutine Agrif_Copy_3d
+      
+      Subroutine Agrif_Copy_4d(tabout,tabin,l,m,inf,sup,inf2,sup2)
+      integer,dimension(4) :: l,m,inf,sup,inf2,sup2
+      real,target,dimension(l(1):,l(2):,l(3):,l(4):) :: tabout
+      real,target,dimension(m(1):,m(2):,m(3):,m(4):) :: tabin
+          tabout(inf(1):sup(1),
+     &                         inf(2):sup(2), 
+     &                         inf(3):sup(3), 
+     &                         inf(4):sup(4)) = 
+     &         tabin(inf2(1):sup2(1),
+     &                          inf2(2):sup2(2),
+     &                          inf2(3):sup2(3),
+     &                          inf2(4):sup2(4))
+      End Subroutine Agrif_Copy_4d      
+
+      End Module Agrif_Arrays
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbc.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbc.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbc.F	(revision 4536)
@@ -0,0 +1,1312 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Boundary 
+C 
+      Module Agrif_Boundary  
+C
+CCC   Description:
+CCC   Module to calculate the boundary conditions on the child grids from their
+CCC   parent grids.
+C
+C     Modules used:  
+C   
+      Use Agrif_Interpolation        
+C
+      IMPLICIT NONE
+C        
+      CONTAINS   
+C     Define procedures contained in this module
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_1d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_1d(TypeInterp,parent,child,tab,deb,fin,
+     &                              weight,pweight)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 1D 
+CCC   grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER,DIMENSION(6) :: TypeInterp    ! TYPE of interpolation
+                                            ! (linear,...)
+      TYPE(AGRIF_PVariable) :: parent       ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child        ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp    ! Temporary variable on the child 
+                                            ! grid
+      INTEGER :: deb,fin                    ! Positions of the  interpolations 
+      REAL, DIMENSION(
+     &    lbound(child%var%array1,1):ubound(child%var%array1,1)
+     &    ), Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                    ! Indicates if weight is used for  
+                                            ! the temporal interpolation 
+      REAL :: weight                        ! Coefficient for the time 
+                                            ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid
+C     variable.  
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var
+C      
+C     Values of the grid variable
+      childtemp % var % array1 => tab  
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation 
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade  
+      childtemp % var % list_interp => child % var% list_interp          
+C
+C     Call to the procedure for the calculations of the boundary conditions
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+C
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp      
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_1D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_2d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_2d(TypeInterp,parent,child,tab,deb,fin,
+     &                              weight,pweight,procname)
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 2D 
+CCC   grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      External :: procname
+      Optional :: procname
+      INTEGER,DIMENSION(6) :: TypeInterp    ! TYPE of interpolation (linear, 
+                                            ! lagrange, spline, ... )
+      TYPE(AGRIF_PVariable) :: parent       ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child        ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp    ! Temporary variable on the child 
+                                            ! grid
+      INTEGER :: deb,fin                    ! Positions where interpolations are
+                                            ! done on the fine grid 
+      REAL, DIMENSION(
+     &         lbound(child%var%array2,1): ubound(child%var%array2,1),
+     &         lbound(child%var%array2,2): ubound(child%var%array2,2)), 
+     &         Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                    ! Indicates if weight is used for  
+                                            ! the temporal interpolation 
+      REAL :: weight                        ! Coefficient for the time 
+                                            ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid
+C     variable.   
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var
+C      
+C     Values of the grid variable
+      childtemp % var % array2 => tab  
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation 
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade   
+      childtemp % var % list_interp => child % var% list_interp    
+C
+C     Call to the procedure for the calculations of the boundary conditions
+      IF (present(procname)) THEN
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight,procname)
+      ELSE
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+      ENDIF
+
+C   
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp
+C         
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_2D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_3d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_3d(TypeInterp,parent,child,tab,deb,fin,
+     &                              weight,pweight,procname)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 3D 
+CCC   variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments 
+      External :: procname
+      Optional :: procname     
+      INTEGER,DIMENSION(6) :: TypeInterp    ! TYPE of interpolation (linear, 
+                                            ! lagrange, spline, ... )
+      TYPE(AGRIF_PVariable) :: parent       ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child        ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp    ! Temporary variable on the child
+                                            ! grid
+      INTEGER :: deb,fin                    ! Positions where interpolations 
+                                            ! are done on the fine grid 
+      REAL, DIMENSION(
+     &         lbound(child%var%array3,1):ubound(child%var%array3,1),
+     &         lbound(child%var%array3,2):ubound(child%var%array3,2),
+     &         lbound(child%var%array3,3):ubound(child%var%array3,3)
+     &         ), Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                    ! Indicates if weight is used for 
+                                            ! the temporal interpolation 
+      REAL :: weight                        ! Coefficient for the time 
+                                            ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid 
+C     variable.  
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var       
+C      
+C     Values of the grid variable
+      childtemp % var % array3 => tab
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation  
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade 
+      childtemp % var % list_interp => child % var% list_interp           
+C
+C     Call to the procedure for the calculations of the boundary conditions     
+      IF (present(procname)) THEN
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight,procname)
+      ELSE
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+      ENDIF
+C
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp      
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_3D               
+C
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_4d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_4d(TypeInterp,parent,child,tab,deb,fin,
+     &                             weight,pweight,procname)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 4D 
+CCC   grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      External :: procname
+      Optional :: procname     
+      INTEGER,DIMENSION(6) :: TypeInterp      ! TYPE of interpolation (linear, 
+                                              ! lagrange, spline, ... )
+      TYPE(AGRIF_PVariable) :: parent         ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child          ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp      ! Temporary varaiable on the child
+                                              ! grid
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid 
+      REAL, DIMENSION(
+     &        lbound(child%var%array4,1):ubound(child%var%array4,1),
+     &        lbound(child%var%array4,2):ubound(child%var%array4,2),
+     &        lbound(child%var%array4,3):ubound(child%var%array4,3),
+     &        lbound(child%var%array4,4):ubound(child%var%array4,4)
+     &        ), Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                      ! Indicates if weight is used for 
+                                              ! the temporal interpolation 
+      REAL :: weight                          ! Coefficient for the time 
+                                              ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid 
+C     variable.  
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var 
+C      
+C     Values of the grid variable
+      childtemp % var % array4 => tab  
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation       
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade  
+      childtemp % var % list_interp => child % var% list_interp          
+C
+C     Call to the procedure for the calculations of the boundary conditions
+      IF (present(procname)) THEN
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight,procname)
+      ELSE
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+      ENDIF
+C
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp      
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_4D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_5d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_5d(TypeInterp,parent,child,tab,deb,fin,
+     &                             weight,pweight,procname)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 5D 
+CCC   grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      External :: procname
+      Optional :: procname     
+      INTEGER,DIMENSION(6) :: TypeInterp      ! TYPE of interpolation (linear, 
+                                              ! lagrange, spline, ... )
+      TYPE(AGRIF_PVariable) :: parent         ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child          ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp      ! Temporary varaiable on the child
+                                              ! grid
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid 
+      REAL, DIMENSION(
+     &         lbound(child%var%array5,1):ubound(child%var%array5,1),
+     &         lbound(child%var%array5,2):ubound(child%var%array5,2),
+     &         lbound(child%var%array5,3):ubound(child%var%array5,3),
+     &         lbound(child%var%array5,4):ubound(child%var%array5,4),
+     &         lbound(child%var%array5,5):ubound(child%var%array5,5)
+     &         ), Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                      ! Indicates if weight is used for 
+                                              ! the temporal interpolation 
+      REAL :: weight                          ! Coefficient for the time 
+                                              ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid 
+C     variable.  
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var 
+C      
+C     Values of the grid variable
+      childtemp % var % array5 => tab  
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation       
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade 
+      childtemp % var % list_interp => child % var% list_interp           
+C
+C     Call to the procedure for the calculations of the boundary conditions  
+      IF (present(procname)) THEN
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight,procname)
+      ELSE
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+      ENDIF
+C
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp      
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_5D
+C
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_bc_6d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_bc_6d(TypeInterp,parent,child,tab,deb,fin,
+     &                             weight,pweight)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid for a 6D 
+CCC   grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER,DIMENSION(6) :: TypeInterp      ! TYPE of interpolation (linear, 
+                                              ! lagrange, spline, ... )
+      TYPE(AGRIF_PVariable) :: parent         ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child          ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp      ! Temporary varaiable on the child
+                                              ! grid
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid 
+      REAL, DIMENSION(
+     &         lbound(child%var%array6,1):ubound(child%var%array6,1),
+     &         lbound(child%var%array6,2):ubound(child%var%array6,2),
+     &         lbound(child%var%array6,3):ubound(child%var%array6,3),
+     &         lbound(child%var%array6,4):ubound(child%var%array6,4),
+     &         lbound(child%var%array6,5):ubound(child%var%array6,5),
+     &         lbound(child%var%array6,6):ubound(child%var%array6,6)
+     &         ), Target :: tab ! Values of the grid variable
+      LOGICAL :: pweight                      ! Indicates if weight is used for 
+                                              ! the temporal interpolation 
+      REAL :: weight                          ! Coefficient for the time 
+                                              ! interpolation
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE representing the grid 
+C     variable.  
+C
+      allocate(childtemp % var)  
+C
+      childtemp % var % root_var => child % var % root_var 
+C      
+C     Values of the grid variable
+      childtemp % var % array6 => tab  
+C
+C     Temporary results for the time interpolation before and after the space 
+C     interpolation       
+      childtemp % var % oldvalues2D => child % var % oldvalues2D
+C 
+C     Index indicating if a space interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &                 child % var % Interpolationshouldbemade 
+      childtemp % var % list_interp => child % var% list_interp           
+C
+C     Call to the procedure for the calculations of the boundary conditions
+      Call Agrif_CorrectVariable
+     &     (TypeInterp,parent,childtemp,deb,fin,pweight,weight)
+C
+      child % var % oldvalues2D => childtemp % var % oldvalues2D
+      child % var % list_interp => childtemp % var %list_interp      
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_bc_6D
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_CorrectVariable
+C     **************************************************************************
+C
+      Subroutine AGRIF_CorrectVariable(TypeInterp,parent,child,deb,fin,
+     &                                 pweight,weight,procname)
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions on a fine grid.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments
+      External :: procname
+      Optional :: procname
+      TYPE(AGRIF_PVariable) :: parent         ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child          ! Variable on the child grid
+      INTEGER,DIMENSION(6)  :: TypeInterp     ! TYPE of interpolation
+                                              !    (linear,lagrange,...)
+      INTEGER               :: deb,fin        ! Positions where boundary
+                                              !    conditions are calculated
+      LOGICAL               :: pweight        ! Indicates if weight is used 
+                                              !    for the time interpolation 
+      REAL                  :: weight         ! Coefficient for the time
+                                              !    interpolation
+C
+C     Local scalars
+      TYPE(Agrif_Grid)    , Pointer :: Agrif_Child_Gr,Agrif_Parent_Gr
+      TYPE(AGRIF_Variable), Pointer :: root   ! Variable on the root grid
+      INTEGER                       :: nbdim  ! Number of dimensions of 
+                                              !    the grid variable 
+      INTEGER                       :: n
+      INTEGER,DIMENSION(6)          :: pttab_child  ! Index of the first point
+                                                    !    inside the domain for
+                                                    !    the child grid variable
+      INTEGER,DIMENSION(6)          :: pttab_parent ! Index of the first point
+                                                    !    inside the domain for
+                                                    !    the parent grid
+                                                    !    variable
+      INTEGER,DIMENSION(6)          :: nbtab_Child  ! Number of the cells
+      INTEGER,DIMENSION(6)          :: posvartab_Child    ! Position of the
+                                                    !    variable on the cell 
+      INTEGER,DIMENSION(6)          :: loctab_Child ! Indicates if the child
+                                                    !    grid has a common
+                                                    !    border with the root
+                                                    !    grid      
+      REAL, DIMENSION(6)            :: s_child,s_parent   ! Positions of the
+                                                    !    parent and child grids
+      REAL, DIMENSION(6)            :: ds_child,ds_parent ! Space steps of the
+                                                    !    parent and child grids 
+C
+C
+      loctab_child(:) = 0
+C
+      Agrif_Child_Gr => Agrif_Curgrid
+      Agrif_Parent_Gr => Agrif_Curgrid % parent
+      root => child % var % root_var 
+      nbdim = root % nbdim
+C
+      do n = 1,nbdim
+        posvartab_child(n) = root % posvar(n)      
+      enddo
+C
+C
+      do n = 1,nbdim
+C
+        Select case(root % interptab(n))
+C
+          case('x') ! x DIMENSION
+C
+            nbtab_Child(n) = Agrif_Child_Gr % nb(1)
+            pttab_Child(n) = root % point(1)
+            pttab_Parent(n) = root % point(1)
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(1)
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(1)
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(1)
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(1)
+            if (root % posvar(n) == 2) then
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+            endif
+C
+            if (Agrif_CURGRID % NearRootBorder(1)) 
+     &         loctab_child(n) = -1
+            if (Agrif_CURGRID % DistantRootBorder(1))
+     &         loctab_child(n) = -2
+            if ((Agrif_CURGRID % NearRootBorder(1)) .AND. 
+     &          (Agrif_CURGRID % DistantRootBorder(1))) 
+     &         loctab_child(n) = -3
+C
+          case('y') ! y DIMENSION      
+C
+            nbtab_Child(n) = Agrif_Child_Gr % nb(2)
+            pttab_Child(n) = root % point(2)
+            pttab_Parent(n) = root % point(2)
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(2)
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(2) 
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(2)
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(2)
+            if (root % posvar(n) == 2) then        
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+            endif        
+C
+            if (Agrif_CURGRID % NearRootBorder(2)) 
+     &         loctab_child(n) = -1
+            if (Agrif_CURGRID % DistantRootBorder(2)) 
+     &         loctab_child(n) = -2
+            if ((Agrif_CURGRID % NearRootBorder(2)) .AND. 
+     &          (Agrif_CURGRID % DistantRootBorder(2))) 
+     &         loctab_child(n) = -3
+C
+          case('z') ! z DIMENSION
+C
+            nbtab_Child(n) = Agrif_Child_Gr % nb(3)
+            pttab_Child(n) = root % point(3)
+            pttab_Parent(n) = root % point(3)
+            s_Child(n) = Agrif_Child_Gr % Agrif_x(3)
+            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(3)
+            ds_Child(n) = Agrif_Child_Gr % Agrif_d(3)
+            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(3)
+            if (root % posvar(n) == 2) then        
+                s_Child(n) = s_Child(n) + ds_Child(n)/2.
+                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
+            endif        
+C
+            if (Agrif_CURGRID % NearRootBorder(3)) 
+     &         loctab_child(n) = -1
+            if (Agrif_CURGRID % DistantRootBorder(3)) 
+     &         loctab_child(n) = -2
+            if ((Agrif_CURGRID % NearRootBorder(3)) .AND. 
+     &          (Agrif_CURGRID % DistantRootBorder(3))) 
+     &         loctab_child(n) = -3
+C
+          case('N') ! No space DIMENSION      
+C
+            select case (nbdim) 
+C      
+              case(1)
+                nbtab_Child(n) = SIZE(child % var % array1,n) - 1
+                pttab_Child(n) = lbound(child % var % array1,n)
+              case(2)
+                nbtab_Child(n) = SIZE(child % var % array2,n) - 1
+                pttab_Child(n) = lbound(child % var % array2,n)
+              case(3)
+                nbtab_Child(n) = SIZE(child % var % array3,n) - 1
+                pttab_Child(n) = lbound(child % var % array3,n)  
+              case(4)
+                nbtab_Child(n) = SIZE(child % var % array4,n) - 1
+                pttab_Child(n) = lbound(child % var % array4,n)
+              case(5)
+                nbtab_Child(n) = SIZE(child % var % array5,n) - 1
+                pttab_Child(n) = lbound(child % var % array5,n)      
+              case(6)
+                nbtab_Child(n) = SIZE(child % var % array6,n) - 1
+                pttab_Child(n) = lbound(child % var % array6,n)      
+C
+            end select
+C
+C           No interpolation but only a copy of the values of the grid variable
+C      
+            posvartab_child(n) = 1
+            pttab_Parent(n)= pttab_Child(n)
+            s_Child(n)=0.
+            s_Parent(n)=0. 
+            ds_Child(n)=1.
+            ds_Parent(n)=1.
+            loctab_child(n) = -3
+C
+        End select
+C
+      enddo
+C
+         IF (present(procname)) THEN
+          Call AGRIF_CorrectnD
+     &         (TypeInterp,parent,child,deb,fin,pweight,weight,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim,procname)
+        ELSE
+          Call AGRIF_CorrectnD
+     &         (TypeInterp,parent,child,deb,fin,pweight,weight,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim)
+         ENDIF
+C
+C
+      End subroutine AGRIF_CorrectVariable
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Correctnd
+C     **************************************************************************
+C
+      Subroutine AGRIF_Correctnd(TypeInterp,parent,child,deb,fin,
+     &                           pweight,weight,
+     &                           pttab_child,pttab_Parent,
+     &                           nbtab_Child,posvartab_Child,
+     &                           loctab_Child,
+     &                           s_Child,s_Parent,
+     &                           ds_Child,ds_Parent,nbdim,procname)
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions for a nD grid variable on 
+CCC   a fine grid by using a space and time interpolations; it is called by the 
+CCC   Agrif_CorrectVariable procedure.
+C
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+C
+#include "mpif.h"
+C
+#endif
+C
+C     Arguments
+      External :: procname
+      Optional :: procname
+      INTEGER,DIMENSION(6) :: TypeInterp ! TYPE of interpolation (linear, 
+                                         !   spline,...)  
+      TYPE(AGRIF_PVariable)    :: parent ! Variable on the parent grid
+      TYPE(AGRIF_PVariable)    :: child  ! Variable on the child grid 
+      INTEGER                  :: deb,fin ! Positions where interpolations 
+                                         !    are done
+      LOGICAL                  :: pweight ! Indicates if weight is used for 
+                                         !    the temporal interpolation
+      REAL                     :: weight ! Coefficient for the temporal
+                                         !    interpolation
+      INTEGER                  :: nbdim  ! Number of dimensions of the grid
+                                         !    variable
+      INTEGER,DIMENSION(nbdim) :: pttab_child ! Index of the first point inside
+                                         !    the domain for the parent 
+                                         !    grid variable
+      INTEGER,DIMENSION(nbdim) :: pttab_Parent ! Index of the first point 
+                                         !   inside the domain for the 
+                                         !   child grid variable
+      INTEGER,DIMENSION(nbdim) :: nbtab_Child ! Number of cells of the child
+                                         !    grid
+      INTEGER,DIMENSION(nbdim) :: posvartab_Child ! Position of the grid
+                                         !    variable (1 or 2)
+      INTEGER,DIMENSION(nbdim) :: loctab_Child ! Indicates if the child 
+                                        !    grid has a common border with 
+                                        !    the root grid
+      REAL   ,DIMENSION(nbdim) :: s_Child,s_Parent ! Positions of the parent 
+                                        !   and child grids 
+      REAL   ,DIMENSION(nbdim) :: ds_Child,ds_Parent ! Space steps of the 
+                                        !    parent and child grids
+C
+C     Local variables
+      TYPE(AGRIF_PVariable)        :: restore ! Variable on the parent     
+      INTEGER,DIMENSION(nbdim,2)   :: lubglob
+      INTEGER                      :: i          
+      INTEGER                      :: kindex  ! Index used for safeguard 
+                                       !    and time interpolation
+      INTEGER,DIMENSION(nbdim,2,2) :: indtab ! Arrays indicating the limits 
+                                       !    of the child     
+      INTEGER,DIMENSION(nbdim,2,2) :: indtruetab ! grid variable where 
+                                       !   boundary conditions are 
+      INTEGER,DIMENSION(nbdim,2,2,nbdim)   :: ptres,ptres2 ! calculated
+      INTEGER                      :: nb,ndir,n,sizetab(1)
+      REAL, DIMENSION(:), Allocatable :: tab ! Array used for the interpolation
+      REAL    :: c1t,c2t               ! Coefficients for the time interpolation
+                                       !    (c2t=1-c1t) 
+C
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim)   :: lower,upper
+      INTEGER,DIMENSION(nbdim)   :: ltab,utab
+      INTEGER,DIMENSION(nbdim)   :: lb,ub
+      INTEGER,DIMENSION(nbdim,2) :: iminmaxg
+      INTEGER                    :: code
+C
+#endif            
+C      
+C
+      indtab(1:nbdim,2,1) = pttab_child(1:nbdim) + nbtab_child(1:nbdim)
+     &          + deb
+      indtab(1:nbdim,2,2) = indtab(1:nbdim,2,1) + ( fin - deb )
+       
+      indtab(1:nbdim,1,1) = pttab_child(1:nbdim) - fin
+      indtab(1:nbdim,1,2) = pttab_child(1:nbdim) - deb
+                  
+      WHERE (posvartab_child(1:nbdim) == 2)
+        indtab(1:nbdim,1,1) = indtab(1:nbdim,1,1) - 1
+        indtab(1:nbdim,1,2) = indtab(1:nbdim,1,2) - 1
+      END WHERE
+      
+
+#if !defined AGRIF_MPI
+      Call Agrif_nbdim_Get_bound_dimension(child%var,lubglob(:,1),
+     &              lubglob(:,2),nbdim)
+C
+#else
+C     
+      Call Agrif_nbdim_Get_bound_dimension(child%var,lb,ub,nbdim)
+      
+      DO i = 1,nbdim
+C
+        Call Agrif_Invloc(lb(i),Agrif_Procrank,i,iminmaxg(i,1))
+        Call Agrif_Invloc(ub(i),Agrif_Procrank,i,iminmaxg(i,2))
+C
+      ENDDO
+C
+      iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
+      
+      CALL MPI_ALLREDUCE(iminmaxg,lubglob,2*nbdim,MPI_INTEGER,MPI_MIN,
+     &                     MPI_COMM_WORLD,code)  
+     
+      lubglob(1:nbdim,2) = - lubglob(1:nbdim,2)      
+C
+#endif 
+C     
+      indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),
+     &     lubglob(1:nbdim,1))
+      indtruetab(1:nbdim,1,2) = max(indtab(1:nbdim,1,2),
+     &     lubglob(1:nbdim,1))
+      indtruetab(1:nbdim,2,1) = min(indtab(1:nbdim,2,1),
+     &     lubglob(1:nbdim,2))
+      indtruetab(1:nbdim,2,2) = min(indtab(1:nbdim,2,2),
+     &     lubglob(1:nbdim,2))
+
+                              
+C 
+C
+      do nb = 1,nbdim
+C
+        do ndir = 1,2      
+C
+          if (loctab_child(nb) /= (-ndir) 
+     &        .AND. loctab_child(nb) /= -3) then
+C           
+              do n = 1,2
+C
+                ptres(nb,n,ndir,nb) = indtruetab(nb,ndir,n)  
+C
+              enddo              
+C
+              do i = 1,nbdim
+C     
+                if (i .NE. nb) then      
+C
+                    if (loctab_child(i) == -1 
+     &                                 .OR. loctab_child(i) == -3) then
+C
+                        ptres(i,1,ndir,nb) = pttab_child(i)
+C
+                      else
+C
+                        ptres(i,1,ndir,nb) = indtruetab(i,1,1)
+C
+                    endif
+C
+                    if (loctab_child(i) == -2 
+     &                                 .OR. loctab_child(i) == -3) then
+C
+                        if (posvartab_child(i) == 1) then
+C
+                            ptres(i,2,ndir,nb) = pttab_child(i)
+     &                                                 + nbtab_child(i)
+C
+                          else
+C
+                            ptres(i,2,ndir,nb) = pttab_child(i)
+     &                                             + nbtab_child(i) - 1
+C
+                        endif                             
+C
+                      else
+C
+                        ptres(i,2,ndir,nb) = indtruetab(i,2,2)
+C
+                    endif                        
+C      
+                endif
+C      
+              enddo
+      
+C
+#if defined AGRIF_MPI
+                 Call Agrif_nbdim_Get_bound_dimension
+     &                    (child%var,lower,upper,nbdim)
+
+              do i = 1,nbdim
+C
+                 Call GetLocalBoundaries(ptres(i,1,ndir,nb),
+     &                                  ptres(i,2,ndir,nb),i,
+     &                                  lower(i),upper(i),
+     &                                  ltab(i),utab(i))
+                 ptres2(i,1,ndir,nb) = max(ltab(i),lower(i)) 
+                 ptres2(i,2,ndir,nb) = min(utab(i),upper(i))
+                 if ((i == nb) .AND. (ndir == 1)) then 
+                     ptres2(i,2,ndir,nb) = max(utab(i),lower(i))
+                 elseif ((i == nb) .AND. (ndir == 2)) then
+                     ptres2(i,1,ndir,nb) = min(ltab(i),upper(i)) 
+                 endif
+C
+              enddo
+#else
+              ptres2(:,:,ndir,nb) = ptres(:,:,ndir,nb)
+#endif      
+            
+        endif
+      
+        enddo
+       enddo
+C
+      if (child % var % interpIndex 
+     &        /= Agrif_Curgrid % parent % ngridstep .OR.
+     &    child%var%Interpolationshouldbemade ) then
+C
+C     Space interpolation 
+C      
+      kindex = 1    
+C
+      do nb = 1,nbdim
+C
+        do ndir = 1,2                
+C
+          if (loctab_child(nb) /= (-ndir) 
+     &        .AND. loctab_child(nb) /= -3) then  
+C
+              IF (present(procname)) THEN
+              Call Agrif_InterpnD
+     &             (TYPEInterp,parent,child,
+     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              restore,.FALSE.,nbdim,procname)
+              ELSE
+              Call Agrif_InterpnD              
+     &             (TYPEInterp,parent,child,
+     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              restore,.FALSE.,nbdim)
+              ENDIF
+     
+              IF (.NOT. child%var%interpolationshouldbemade) THEN
+C     
+C             Safeguard of the values of the grid variable (at times n and n+1
+C                on the parent grid)
+C      
+              sizetab(1) = 1
+C
+              do i = 1,nbdim
+C          
+                sizetab(1) = sizetab(1)
+     &              * (ptres2(i,2,ndir,nb)-ptres2(i,1,ndir,nb)+1)
+C      
+              enddo
+
+              Call saveAfterInterp(child,
+     &           ptres2(:,:,ndir,nb),kindex,sizetab(1),nbdim)
+C
+           ENDIF
+C
+          endif
+C
+        enddo       
+C
+      enddo     
+C
+C
+      child % var % interpIndex = Agrif_Curgrid % parent % ngridstep
+C
+C
+      endif  
+      
+              IF (.NOT. child%var%interpolationshouldbemade) THEN
+C
+C
+C     Calculation of the coefficients c1t and c2t for the temporary
+C        interpolation
+      if (pweight) then
+C
+          c1t = weight
+C
+        else
+C
+          c1t = (REAL(AGRIF_Nbstepint()) + 1.) / Agrif_Rhot()
+C
+      endif
+C                                  
+      c2t = 1. - c1t
+C           
+C     Time interpolation
+C
+      kindex = 1
+C
+      do nb = 1,nbdim
+C
+        do ndir = 1,2      
+C
+          if (loctab_child(nb) /= (-ndir) 
+     &        .AND. loctab_child(nb) /= -3) then
+
+              Call timeInterpolation
+     &             (child,ptres2(:,:,ndir,nb),kindex,c1t,c2t,nbdim)
+          endif
+C
+        enddo
+C      
+      enddo
+C      
+
+       ENDIF
+C  
+      End Subroutine Agrif_Correctnd
+C
+C
+C     **************************************************************************
+CCC   Subroutine saveAfterInterp
+C     **************************************************************************
+C
+      Subroutine saveAfterInterp(child,bounds,kindex,newsize,nbdim)
+C
+CCC   Descritpion:
+CCC   Subroutine used to save the values of the grid variable on the fine grid 
+CCC   after the space interpolation. 
+C
+C     Declarations:
+C
+      
+C
+C     argument
+      TYPE (AGRIF_PVariable) :: child   ! The fine grid variable
+      INTEGER                :: kindex  ! Index indicating where this safeguard 
+                                        ! is done on the fine grid
+      INTEGER :: nbdim, newsize
+      INTEGER,DIMENSION(nbdim,2) :: bounds
+C
+C     Local scalars
+      INTEGER                      :: ir,jr,kr,lr,mr,nr
+C
+C
+C     Allocation of the array oldvalues2d
+
+C
+      if (newsize .LE. 0) return
+C
+      Call Agrif_Checksize
+     &     (child,kindex+newsize)  
+
+      if (child % var % interpIndex 
+     &        /= Agrif_Curgrid % parent % ngridstep ) then
+       child%var%oldvalues2d(kindex:kindex+newsize-1,1)=
+     &        child%var%oldvalues2d(kindex:kindex+newsize-1,2)
+      endif
+
+      SELECT CASE (nbdim)
+      CASE (1)
+
+         do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array1(ir)
+            kindex = kindex + 1
+         enddo       
+C
+      CASE (2)
+
+        do jr=bounds(2,1),bounds(2,2)
+           do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array2(ir,jr)
+            kindex = kindex + 1
+           enddo
+         enddo      
+C
+      CASE (3)
+        do kr=bounds(3,1),bounds(3,2)
+          do jr=bounds(2,1),bounds(2,2)
+             do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array3(ir,jr,kr)
+            kindex = kindex + 1
+             enddo
+           enddo
+         enddo       
+C
+      CASE (4)
+          do lr=bounds(4,1),bounds(4,2)
+           do kr=bounds(3,1),bounds(3,2)
+             do jr=bounds(2,1),bounds(2,2)
+               do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array4(ir,jr,kr,lr)
+            kindex = kindex + 1
+               enddo
+             enddo
+           enddo
+         enddo         
+C
+      CASE (5)
+         do mr=bounds(5,1),bounds(5,2)
+           do lr=bounds(4,1),bounds(4,2)
+            do kr=bounds(3,1),bounds(3,2) 
+              do jr=bounds(2,1),bounds(2,2)
+                 do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array5(ir,jr,kr,lr,mr)
+            kindex = kindex + 1
+                 enddo
+               enddo
+             enddo
+           enddo
+         enddo   
+C
+      CASE (6)
+        do nr=bounds(6,1),bounds(6,2)
+           do mr=bounds(5,1),bounds(5,2)
+             do lr=bounds(4,1),bounds(4,2)
+               do kr=bounds(3,1),bounds(3,2)
+                do jr=bounds(2,1),bounds(2,2)
+                   do ir=bounds(1,1),bounds(1,2)
+            child%var%oldvalues2d(kindex,2) =
+     &           child%var%array6(ir,jr,kr,lr,mr,nr)
+            kindex = kindex + 1
+                   enddo
+                 enddo
+               enddo
+             enddo
+           enddo
+         enddo       
+      END SELECT
+C
+C                                                  
+      End subroutine saveAfterInterp
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine timeInterpolation
+C     **************************************************************************
+C
+      Subroutine timeInterpolation(child,bounds,kindex,c1t,c2t,nbdim) 
+C
+CCC   Descritpion:
+CCC   Subroutine for a linear time interpolation on the child grid. 
+C
+C     Declarations:
+C
+      
+C
+C     argument
+      TYPE (AGRIF_PVariable) :: child  ! The fine grid variable
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim,2) :: bounds
+      INTEGER                :: kindex ! Index indicating the values of the fine
+                                       ! grid got before and after the space 
+                                       ! interpolation and used for the time 
+                                       ! interpolation
+      REAL                   :: c1t,c2t! coefficients for the time interpolation
+                                       ! (c2t=1-c1t)  
+C
+C     Local aruments      
+      INTEGER :: i
+C     Local scalars
+      INTEGER                      :: ir,jr,kr,lr,mr,nr      
+C
+C
+      
+      SELECT CASE (nbdim)
+      CASE (1)
+
+         do ir=bounds(1,1),bounds(1,2)
+                child%var%array1(ir) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2)    
+            kindex = kindex + 1
+         enddo       
+C
+      CASE (2)
+
+        do jr=bounds(2,1),bounds(2,2)
+           do ir=bounds(1,1),bounds(1,2)
+                child%var%array2(ir,jr) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2) 
+            kindex = kindex + 1
+           enddo
+         enddo      
+C
+      CASE (3)
+        do kr=bounds(3,1),bounds(3,2)
+          do jr=bounds(2,1),bounds(2,2)
+             do ir=bounds(1,1),bounds(1,2)
+                child%var%array3(ir,jr,kr) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2) 
+            kindex = kindex + 1
+             enddo
+           enddo
+         enddo       
+C
+      CASE (4)
+          do lr=bounds(4,1),bounds(4,2)
+           do kr=bounds(3,1),bounds(3,2)
+             do jr=bounds(2,1),bounds(2,2)
+               do ir=bounds(1,1),bounds(1,2)
+                child%var%array4(ir,jr,kr,lr) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2) 
+            kindex = kindex + 1
+               enddo
+             enddo
+           enddo
+         enddo         
+C
+      CASE (5)
+         do mr=bounds(5,1),bounds(5,2)
+           do lr=bounds(4,1),bounds(4,2)
+            do kr=bounds(3,1),bounds(3,2) 
+              do jr=bounds(2,1),bounds(2,2)
+                 do ir=bounds(1,1),bounds(1,2)
+                child%var%array5(ir,jr,kr,lr,mr) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2) 
+            kindex = kindex + 1
+                 enddo
+               enddo
+             enddo
+           enddo
+         enddo   
+C
+      CASE (6)
+        do nr=bounds(6,1),bounds(6,2)
+           do mr=bounds(5,1),bounds(5,2)
+             do lr=bounds(4,1),bounds(4,2)
+               do kr=bounds(3,1),bounds(3,2)
+                do jr=bounds(2,1),bounds(2,2)
+                   do ir=bounds(1,1),bounds(1,2)
+                child%var%array6(ir,jr,kr,lr,mr,nr) =
+     &           c2t*child % var % oldvalues2d(kindex,1)   
+     &         + c1t*child % var % oldvalues2d(kindex,2) 
+            kindex = kindex + 1
+                   enddo
+                 enddo
+               enddo
+             enddo
+           enddo
+         enddo       
+      END SELECT
+                                                   
+C
+C
+      End subroutine timeInterpolation      
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Checksize
+C     **************************************************************************
+C
+      Subroutine Agrif_Checksize(child,newsize)
+C
+CCC   Descritpion:
+CCC   Subroutine used in the saveAfterInterp procedure to allocate the 
+CCC   oldvalues2d array. 
+C
+C     Declarations:
+C
+      
+C      
+C     TYPE argument
+      TYPE (AGRIF_PVariable) :: child  ! The fine grid variable
+C 
+C     Scalar arguments
+      INTEGER :: newsize               ! Size of the domains where the boundary 
+                                       ! conditions are calculated  
+C
+C     Local arrays
+      REAL, DIMENSION(:,:), Allocatable :: tempoldvalues ! Temporary array
+C                
+C
+      if (.NOT. associated(child % var % oldvalues2d)) then
+C
+          allocate(child % var % oldvalues2d(newsize,2))
+C  
+          child % var % oldvalues2d=0.
+C
+        else
+C
+          if (SIZE(child % var % oldvalues2d,1) < newsize) then   
+C
+              allocate(tempoldvalues(SIZE(child % var %
+     &                                    oldvalues2d,1),2))
+C
+              tempoldvalues = child % var % oldvalues2d
+C
+              deallocate(child % var % oldvalues2d)
+C
+              allocate(child % var % oldvalues2d(newsize,2))
+C            
+              child%var%oldvalues2d=0.
+C
+              child % var % oldvalues2d(1:SIZE(tempoldvalues,1),:) = 
+     &        tempoldvalues(:,:)
+C
+              deallocate(tempoldvalues)
+C
+          endif 
+C
+      endif                                                    
+C
+C
+      End  Subroutine Agrif_Checksize
+C
+C
+C
+C      
+      End Module AGRIF_boundary
+
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbcfunction.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbcfunction.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modbcfunction.F	(revision 4536)
@@ -0,0 +1,1565 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module AGRIF_bcfunction
+C
+C 
+      Module  Agrif_bcfunction
+CCC   Description:
+CCC   
+C
+C     Modules used:
+C  
+      Use Agrif_Boundary
+      Use Agrif_Update
+      Use Agrif_fluxmod
+C             
+      IMPLICIT NONE
+C
+      interface Agrif_Bc_variable
+          module procedure Agrif_Bc_variable0d,
+     &                     Agrif_Bc_variable1d,
+     &                     Agrif_Bc_variable2d,
+     &                     Agrif_Bc_variable3d,
+     &                     Agrif_Bc_variable4d,
+     &                     Agrif_Bc_variable5d
+      end interface       
+C
+      interface Agrif_Set_Parent
+          module procedure Agrif_Set_Parent_int,
+     &                     Agrif_Set_Parent_real
+      end interface       
+C
+      interface Agrif_Interp_variable
+          module procedure Agrif_Interp_var0d,
+     &                     Agrif_Interp_var1d,
+     &                     Agrif_Interp_var2d,
+     &                     Agrif_Interp_var3d,
+     &                     Agrif_Interp_var4d,
+     &                     Agrif_Interp_var5d
+      end interface       
+C
+      interface Agrif_Init_variable
+          module procedure Agrif_Init_variable0d,
+     &                     Agrif_Init_variable1d,
+     &                     Agrif_Init_variable2d,
+     &                     Agrif_Init_variable3d
+      end interface       
+C
+      interface Agrif_update_variable
+          module procedure Agrif_update_var0d,
+     &                     Agrif_update_var1d,
+     &                     Agrif_update_var2d,
+     &                     Agrif_update_var3d,
+     &                     Agrif_update_var4d,
+     &                     Agrif_update_var5d
+      end interface       
+C
+      Contains 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_type
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_type(tabvarsindic,posvar,point)
+C
+CCC   Description:
+CCC   To set the TYPE of the variable.
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C
+C
+C     Arguments      
+C
+      INTEGER, DIMENSION(:) :: posvar
+      INTEGER, DIMENSION(:) :: point
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: dimensio ! DIMENSION of the variable
+      INTEGER :: i
+C
+C
+C     Begin 
+C
+      dimensio = Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim
+C
+      if (.not.associated(Agrif_Mygrid % tabvars(tabvarsindic)
+     &                                 %var % posvar)) then
+      Allocate( 
+     & Agrif_Mygrid % tabvars(tabvarsindic)%var % posvar(dimensio))
+      endif 
+            
+      do i = 1 , dimensio
+         Agrif_Mygrid % tabvars(tabvarsindic) %var % posvar(i)
+     &                       = posvar(i)
+         Agrif_Mygrid % tabvars(tabvarsindic) %var % point(i) 
+     &                       = point(i)
+      enddo
+C
+C
+      End Subroutine Agrif_Set_type
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_parent_int
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_parent_int(tabvarsindic,value)
+C
+CCC   Description:
+CCC   To set the TYPE of the variable.
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C
+C
+C     Arguments      
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: Value
+C
+C     Begin 
+C
+      Agrif_Curgrid % parent % tabvars(tabvarsindic) % 
+     &         var % iarray0 = value
+C
+C
+      End Subroutine Agrif_Set_parent_int
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_parent_real
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_parent_real(tabvarsindic,value)
+C
+CCC   Description:
+CCC   To set the TYPE of the variable.
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C
+C
+C     Arguments      
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      REAL :: Value
+C
+C     Begin 
+C
+      Agrif_Curgrid % parent % tabvars(tabvarsindic) % 
+     &          var % array0 = value
+C
+C
+      End Subroutine Agrif_Set_parent_real
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_raf
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_raf(tabvarsindic,tabraf)
+C
+CCC   Description:
+CCC   Attention tabraf est de taille trois si on ne raffine pas suivant z la
+CCC             troisieme entree du tableau tabraf est 'N'
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      CHARACTER(*) ,DIMENSION(:) :: tabraf
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: dimensio ! DIMENSION of the variable
+      INTEGER :: i
+C
+C
+C     Begin 
+C
+      dimensio = Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim
+C        
+      if (.not.associated(Agrif_Mygrid % tabvars(tabvarsindic)
+     &                                 %var % interptab)) then 
+      Allocate(
+     & Agrif_Mygrid % tabvars(tabvarsindic)%var% interptab(dimensio))
+      endif
+
+      do i = 1 , dimensio
+         Agrif_Mygrid % tabvars(tabvarsindic) %var % interptab(i) 
+     &                 = TRIM(tabraf(i))
+      enddo
+C
+      End Subroutine Agrif_Set_raf
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_bc
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_bc(tabvarsindic,point,
+     &          Interpolationshouldbemade)
+C
+CCC   Description:
+CCC
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER, DIMENSION(2) :: point
+      LOGICAL, OPTIONAL :: Interpolationshouldbemade
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C
+C     Begin 
+C
+C     
+      if (Agrif_Curgrid % fixedrank .NE. 0) then  
+       IF (.Not.Associated(Agrif_Curgrid%tabvars(tabvarsindic)%var
+     &                % interpIndex)) THEN
+        Allocate(Agrif_Curgrid%tabvars(tabvarsindic)%var % interpIndex)
+          Agrif_Curgrid%tabvars(tabvarsindic)%var % interpIndex = -1
+
+        Allocate(
+     &    Agrif_Curgrid%tabvars(tabvarsindic)%var % oldvalues2D(1,2))
+          Agrif_Curgrid%tabvars(tabvarsindic)%var % oldvalues2D = 0. 
+       ENDIF      
+       if ( PRESENT(Interpolationshouldbemade) ) then
+         Agrif_Curgrid%tabvars(tabvarsindic)%var %
+     &     Interpolationshouldbemade = Interpolationshouldbemade
+       endif
+
+      endif
+C
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % bcinf = point(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % bcsup = point(2)
+C
+      End Subroutine Agrif_Set_bc
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_interp
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_interp(tabvarsindic,interp,interp1,interp2,
+     &                interp3)
+C
+CCC   Description:
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER, OPTIONAL      :: interp,interp1,interp2,interp3
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C     Begin 
+C
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp = 
+     &    Agrif_Constant
+      IF (present(interp)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp = 
+     &           interp
+      ENDIF
+      IF (present(interp1)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(1) = 
+     &           interp1
+      ENDIF
+      IF (present(interp2)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(2) = 
+     &           interp2
+      ENDIF
+      IF (present(interp3)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(3) = 
+     &           interp3
+      ENDIF
+C
+      End Subroutine Agrif_Set_interp
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_bcinterp
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_bcinterp(tabvarsindic,interp,interp1,
+     &      interp2,interp3)
+C
+CCC   Description:
+
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER, OPTIONAL      :: interp,interp1,interp2,interp3
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C
+C     Begin 
+C
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % bctypeinterp = 
+     &           Agrif_Constant
+      IF (present(interp)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % bctypeinterp = 
+     &           interp
+      ENDIF
+      IF (present(interp1)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % bctypeinterp(1) = 
+     &           interp1
+      ENDIF
+      IF (present(interp2)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % bctypeinterp(2) = 
+     &           interp2
+      ENDIF
+      IF (present(interp3)) THEN
+      Agrif_Mygrid % tabvars(tabvarsindic)% var % bctypeinterp(3) = 
+     &           interp3
+      ENDIF
+C
+      End Subroutine Agrif_Set_bcinterp
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_Update
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_Update(tabvarsindic,point)
+C
+CCC   Description:
+CCC
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER, DIMENSION(2) :: point
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C
+C     Begin 
+C
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = point(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = point(2)
+C
+      End Subroutine Agrif_Set_Update
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_UpdateType
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_UpdateType(tabvarsindic,
+     &                                  update,update1,update2,
+     &                                  update3,update4,update5)
+C
+CCC   Description:
+
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER, OPTIONAL           :: update, update1,
+     &       update2, update3,update4,update5
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C
+C     Begin 
+C
+      Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate = 
+     &                   Agrif_Update_Copy
+      
+      IF (present(update)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate = 
+     &           update
+      ENDIF
+      IF (present(update1)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(1) = 
+     &           update1
+      ENDIF  
+      IF (present(update2)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(2) = 
+     &           update2
+      ENDIF  
+      IF (present(update3)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(3) = 
+     &           update3
+      ENDIF 
+      IF (present(update4)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(4) = 
+     &           update4
+      ENDIF       
+      IF (present(update5)) THEN
+        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(5) = 
+     &           update5
+      ENDIF                  
+C
+      End Subroutine Agrif_Set_UpdateType           
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Set_restore
+C     **************************************************************************
+C 
+      Subroutine Agrif_Set_restore(tabvarsindic)
+C
+CCC   Description:
+CCC   
+C
+C     Modules used:
+C      
+
+C
+C     Declarations:
+C      
+C     Arguments      
+C
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+C     Begin 
+C
+C
+      Agrif_Mygrid%tabvars(tabvarsindic)%var % restaure = .TRUE.
+C
+      End Subroutine Agrif_Set_restore
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_variable0d
+C     **************************************************************************
+      Subroutine Agrif_Init_variable0d(tabvarsindic0,tabvarsindic)
+
+      INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C      
+      CALL Agrif_Interp_variable(tabvarsindic0,tabvarsindic)
+      CALL Agrif_Bc_variable(tabvarsindic0,tabvarsindic,1.)
+
+      End Subroutine Agrif_Init_variable0d
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_variable1d
+C     **************************************************************************
+      Subroutine Agrif_Init_variable1d(q,tabvarsindic)
+
+      REAL, DIMENSION(:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      CALL Agrif_Interp_variable(q,tabvarsindic)
+      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+
+      End Subroutine Agrif_Init_variable1d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_variable2d
+C     **************************************************************************
+      Subroutine Agrif_Init_variable2d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      CALL Agrif_Interp_variable(q,tabvarsindic)
+      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+
+      End Subroutine Agrif_Init_variable2d
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_variable3d
+C     **************************************************************************
+      Subroutine Agrif_Init_variable3d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      CALL Agrif_Interp_variable(q,tabvarsindic)
+      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+C
+      End Subroutine Agrif_Init_variable3d
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable0d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable0d(tabvarsindic0,tabvarsindic,
+     &                               calledweight,procname)
+
+      INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      External :: procname
+      Optional ::  procname
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      INTEGER :: dimensio      
+
+      if (Agrif_Root()) Return
+C
+      dimensio =  Agrif_Mygrid % tabvars(tabvarsindic) % var % nbdim    
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight      
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C
+
+      
+      if ( dimensio .EQ. 1 ) Call Agrif_Interp_Bc_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array1,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,
+     & pweight)
+C
+      if ( dimensio .EQ. 2 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array2,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)
+      ELSE
+          
+      Call Agrif_Interp_Bc_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array2,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      endif
+C
+      if ( dimensio .EQ. 3 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array3,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array3,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      endif
+C
+      if ( dimensio .EQ. 4 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array4,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array4,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      endif
+C
+      if ( dimensio .EQ. 5 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array5,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array5,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      endif
+C
+      if ( dimensio .EQ. 6 ) Call Agrif_Interp_Bc_6D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) %var % array6,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,
+     & pweight)
+C
+C
+      End Subroutine Agrif_Bc_variable0d
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable1d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable1d(q,tabvarsindic,calledweight)
+
+      REAL   , DIMENSION(:)          :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight      
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C
+      if (Agrif_Root()) Return
+      
+      Call Agrif_Interp_Bc_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,
+     & pweight)
+      End Subroutine Agrif_Bc_variable1d
+C
+C
+CC
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable2d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable2d(q,tabvarsindic,calledweight,
+     &                                 procname)
+
+      REAL   , DIMENSION(:,:)          :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C
+
+      if (Agrif_Root()) Return
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+       Call Agrif_Interp_Bc_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+
+      End Subroutine Agrif_Bc_variable2d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable3d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable3d(q,tabvarsindic,calledweight,
+     &                               procname)
+
+      REAL   , Dimension(:,:,:)          :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight      
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C      
+      If (Agrif_Root()) Return
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      End Subroutine Agrif_Bc_variable3d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable4d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable4d(q,tabvarsindic,calledweight,
+     &                               procname)
+
+      REAL   , Dimension(:,:,:,:)          :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight      
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C      
+      If (Agrif_Root()) Return
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      End Subroutine Agrif_Bc_variable4d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Bc_variable5d
+C     **************************************************************************
+      Subroutine Agrif_Bc_variable5d(q,tabvarsindic,calledweight,
+     &                              procname)
+
+      REAL   , Dimension(:,:,:,:,:)          :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C        
+      REAL, OPTIONAL :: calledweight
+      REAL    :: weight
+      LOGICAL :: pweight
+C
+      if ( PRESENT(calledweight) ) then
+        weight=calledweight      
+        pweight = .TRUE.
+      else
+        weight = 0.
+        pweight = .FALSE.
+      endif
+C      
+C      
+      If (Agrif_Root()) Return
+      IF (present(procname)) THEN
+      Call Agrif_Interp_Bc_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight,procname)      
+      ELSE
+      Call Agrif_Interp_Bc_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % bctypeinterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % bcsup,
+     & weight,pweight)
+      ENDIF
+      End Subroutine Agrif_Bc_variable5d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var0D
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var0d(tabvarsindic0,tabvarsindic)
+
+      INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic  ! indice of the variable in tabvars
+      INTEGER :: dimensio  ! indice of the variable in tabvars
+C      
+      if (Agrif_Root()) Return
+C     
+      dimensio = Agrif_Mygrid % tabvars(tabvarsindic) % var % nbdim 
+C
+      if ( dimensio .EQ. 1 )
+     & Call Agrif_Interp_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array1 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      if ( dimensio .EQ. 2 )
+     & Call Agrif_Interp_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      if ( dimensio .EQ. 3 )
+     & Call Agrif_Interp_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      if ( dimensio .EQ. 4 )
+     & Call Agrif_Interp_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      if ( dimensio .EQ. 5 )
+     & Call Agrif_Interp_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array5 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      if ( dimensio .EQ. 6 )
+     & Call Agrif_Interp_6D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array6 ,     
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+C
+      Return
+      End Subroutine Agrif_Interp_var0d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var1d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var1d(q,tabvarsindic)
+
+      REAL, DIMENSION(:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C      
+      Call Agrif_Interp_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+
+      Return
+      End Subroutine Agrif_Interp_var1d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var2d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var2d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+       if (Agrif_Root()) Return
+C
+       Call Agrif_Interp_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+
+      Return
+      End Subroutine Agrif_Interp_var2d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var3d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var3d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      Call Agrif_Interp_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+
+      Return
+      End Subroutine Agrif_Interp_var3d
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var4d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var4d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:,:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      Call Agrif_Interp_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+
+      Return
+      End Subroutine Agrif_Interp_var4d     
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_var5d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_var5d(q,tabvarsindic)
+
+      REAL,  DIMENSION(:,:,:,:,:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      if (Agrif_Root()) Return
+C
+      Call Agrif_Interp_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
+     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+
+      Return
+      End Subroutine Agrif_Interp_var5d       
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var0d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var0d(tabvarsindic0,tabvarsindic,
+     &                              locupdate,procname)
+
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
+      External :: procname
+      Optional ::  procname      
+      INTEGER :: dimensio
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate
+C
+      dimensio = Agrif_Mygrid % tabvars(tabvarsindic) % var % nbdim 
+C      
+      if (Agrif_Root()) Return
+C     
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+ 
+      if ( dimensio .EQ. 1 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Update_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array1 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array1 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+      endif
+      if ( dimensio .EQ. 2 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Update_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+      endif
+      if ( dimensio .EQ. 3 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Update_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+      endif
+      if ( dimensio .EQ. 4 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Update_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+      endif
+      if ( dimensio .EQ. 5 ) then
+      IF (present(procname)) THEN
+      Call Agrif_Update_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array5 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array5 ,     
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+      endif
+
+      Return
+      End Subroutine Agrif_update_var0d
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var1d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var1d(q,tabvarsindic,locupdate,procname)
+
+      REAL,  DIMENSION(:) :: q
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      External :: procname
+      Optional ::  procname      
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate
+C      
+      if (Agrif_Root()) Return
+C     
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+ 
+      IF (present(procname)) THEN
+      Call Agrif_Update_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_1D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+
+      Return
+      End Subroutine Agrif_update_var1d
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var2d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var2d(q,tabvarsindic,locupdate,procname)
+
+      REAL,  DIMENSION(:,:) :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate 
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C      
+      IF (Agrif_Root()) RETURN
+C 
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+ 
+      IF (present(procname)) THEN
+      Call Agrif_Update_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_2D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+
+      Return
+      End Subroutine Agrif_update_var2d
+C 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var3d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var3d(q,tabvarsindic,locupdate,procname)
+
+      REAL,  DIMENSION(:,:,:) :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C      
+      IF (Agrif_Root()) RETURN
+C      
+
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+
+      IF (present(procname)) THEN
+      Call Agrif_Update_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_3D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+
+      Return
+      End Subroutine Agrif_update_var3d
+C 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var4d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var4d(q,tabvarsindic,locupdate,procname)
+
+      REAL,  DIMENSION(:,:,:,:) :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C      
+      IF (Agrif_Root()) RETURN
+C      
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+
+      IF (present(procname)) THEN
+      Call Agrif_Update_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_4D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+
+      Return
+      End Subroutine Agrif_update_var4d  
+C 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_update_var5d
+C     **************************************************************************
+C 
+      Subroutine Agrif_update_var5d(q,tabvarsindic,locupdate,procname)
+
+      REAL,  DIMENSION(:,:,:,:,:) :: q
+      External :: procname
+      Optional ::  procname
+      INTEGER, DIMENSION(2), OPTIONAL :: locupdate
+      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+C
+      IF (Agrif_Root()) RETURN
+C      
+      IF (present(locupdate)) THEN
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = locupdate(1)
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = locupdate(2)
+      ELSE
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf = -99
+      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup = -99
+      ENDIF
+
+      IF (present(procname)) THEN
+      Call Agrif_Update_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & procname)
+      ELSE
+      Call Agrif_Update_5D(
+     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
+     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
+     & Agrif_Curgrid % tabvars(tabvarsindic),q,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
+     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+      ENDIF
+
+      Return
+      End Subroutine Agrif_update_var5d  
+          
+      Subroutine Agrif_Declare_Flux(fluxname,profilename) 
+      character*(*) :: fluxname, profilename
+      Type(Agrif_Flux), pointer :: newflux
+      Type(Agrif_Profile), pointer  :: parcours
+      logical :: foundprofile
+      integer :: i,j,n
+            
+      foundprofile = .FALSE.
+      parcours => Agrif_Myprofiles
+      
+      Do While (Associated(parcours))
+         IF (parcours % profilename == profilename) THEN
+           foundprofile = .TRUE.
+           EXIT
+         ENDIF
+         parcours => parcours%nextprofile
+      End Do      
+      
+      IF (.NOT.foundprofile) THEN
+      write(*,*) 'The profile '''
+     &           //TRIM(profilename)//''' has not been declared'  
+      stop    
+      ENDIF
+      
+      print *,'ici'
+      Allocate(Newflux)
+      
+      Newflux % fluxname = fluxname
+      
+      Newflux % profile => parcours
+      
+      Newflux % nextflux => Agrif_Curgrid % fluxes
+      
+      Agrif_Curgrid % fluxes => Newflux
+      
+      End Subroutine Agrif_Declare_Flux  
+       
+      Subroutine Agrif_Save_Flux(fluxname, fluxtab)
+      character*(*) :: fluxname
+      REAL, DIMENSION(:,:) :: fluxtab
+      
+      
+      Type(Agrif_Flux), pointer :: Flux
+      
+      Type(Agrif_pgrid), pointer :: parcours_child
+      
+      Type(Agrif_grid), Pointer :: currentgrid,oldcurgrid
+      
+      IF (.Not.Agrif_Root()) THEN
+      Flux => Agrif_Search_Flux(fluxname)
+
+      IF (.NOT.Flux%fluxallocated) THEN
+        CALL Agrif_AllocateFlux(Flux,fluxtab)
+      ENDIF
+      
+      Call Agrif_Save_Fluxtab(Flux,fluxtab)
+      
+      ENDIF
+      
+      oldcurgrid=> Agrif_Curgrid
+      
+      parcours_child => Agrif_Curgrid%child_grids
+      
+      Do While (Associated(parcours_child))
+        currentgrid => parcours_child%gr
+        Agrif_Curgrid => parcours_child%gr
+        Flux => Agrif_Search_Flux(fluxname)
+        IF (.NOT.Flux%fluxallocated) THEN
+          CALL Agrif_AllocateFlux(Flux,fluxtab)
+        ENDIF        
+        Call Agrif_Save_Fluxtab_child(Flux,fluxtab)
+        parcours_child=> parcours_child%next
+      End Do
+      
+      Agrif_Curgrid=>oldcurgrid
+      
+      End Subroutine Agrif_Save_Flux
+
+      Subroutine Agrif_Cancel_Flux(fluxname)
+      character*(*) :: fluxname
+      
+      Type(Agrif_Flux), pointer :: Flux
+      
+      Flux => Agrif_Search_Flux(fluxname)
+
+      IF (Flux%FluxAllocated) Call Agrif_Cancel_Fluxarray(Flux)
+      
+      End Subroutine Agrif_Cancel_Flux
+ 
+      Subroutine Agrif_Flux_Correction(fluxname, procname)
+      character*(*) :: fluxname
+      external :: procname
+      
+      Type(Agrif_Flux), pointer :: Flux
+      
+      Flux => Agrif_Search_Flux(fluxname)
+      
+      Call Agrif_FluxCorrect(Flux, procname)
+
+      
+      End Subroutine Agrif_Flux_Correction
+                  
+      Subroutine Agrif_Declare_Profile(profilename,posvar,firstpoint,
+     &    raf)
+      character*(*) :: profilename
+      Type(Agrif_Profile), Pointer :: newprofile
+      INTEGER, DIMENSION(:) :: posvar
+      INTEGER, DIMENSION(:) :: firstpoint
+      CHARACTER(*) ,DIMENSION(:) :: raf      
+      INTEGER :: dimensio
+            
+      dimensio = SIZE(posvar)
+C
+C    
+      Allocate(newprofile)
+      Allocate(newprofile%posvar(dimensio))
+      Allocate(newprofile%interptab(dimensio))
+      newprofile%profilename = profilename
+      newprofile%interptab = raf
+      newprofile%nbdim = dimensio
+      newprofile%posvar = posvar
+      newprofile%point(1:dimensio) = firstpoint
+      
+      newprofile % nextprofile => Agrif_myprofiles
+      
+      Agrif_myprofiles => newprofile
+      
+      End Subroutine Agrif_Declare_Profile
+              
+C
+      End module Agrif_bcfunction
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcluster.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcluster.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcluster.F	(revision 4536)
@@ -0,0 +1,1443 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module AGRIF_Clustering  
+C
+C
+      Module Agrif_Clustering 
+C
+CCC   Description:
+CCC   Module to create and initialize the grid hierarchy from the 
+CCC   AGRIF_FixedGrids.in file.
+C
+C     Modules used:
+C  
+      Use Agrif_Curgridfunctions 
+      Use Agrif_Init_Vars
+      Use Agrif_Save
+C             
+      IMPLICIT NONE
+C        
+      Contains 
+C     Define procedures contained in this module
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Cluster_All  
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Cluster_All(g,coarsegrid)
+C
+CCC   Description:
+CCC   Subroutine for the clustering. A temporary grid hierarchy, pointed by 
+CCC   coarsegrid, is created.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Pointer arguments    
+      TYPE(AGRIF_grid)     ,pointer   :: g        ! Pointer on the current grid
+      TYPE(AGRIF_rectangle),pointer   :: coarsegrid
+C      
+C     Local pointer         
+      TYPE(AGRIF_lrectangle),pointer  :: parcours 
+      TYPE(AGRIF_grid)      ,pointer  :: newgrid 
+      REAL                            :: g_eps
+      INTEGER                         :: iii
+C      
+      g_eps = huge(1.)
+      do iii = 1 , Agrif_Probdim
+         g_eps = min(g_eps,g%Agrif_d(iii))
+      enddo
+C
+      g_eps = g_eps/100.                  
+C
+C     Necessary condition for clustering 
+      do iii = 1 , Agrif_Probdim
+         if (g%Agrif_d(iii)/Agrif_coeffref(iii).LT.
+     &                   (Agrif_mind(iii)-g_eps)) Return
+      enddo
+C
+      Nullify(coarsegrid%childgrids)
+C
+      Call Agrif_ClusterGridnD(g,coarsegrid) 
+C
+      parcours => coarsegrid % childgrids                   
+C      
+      do while (associated(parcours))
+C      
+C       Newgrid is created. It is a copy of a fine grid created previously by
+C          clustering.      
+        Allocate(newgrid)
+C      
+        Nullify(newgrid%child_grids)
+C
+        do iii = 1 , Agrif_Probdim
+           newgrid % nb(iii) = (parcours % r % imax(iii) - 
+     &                          parcours % r % imin(iii)) *
+     &                          Agrif_Coeffref(iii)
+C        
+           newgrid % Agrif_x(iii) = g%Agrif_x(iii) + 
+     &                         (parcours %r % imin(iii) -1) 
+     &                         *g%Agrif_d(iii)
+C 
+           newgrid % Agrif_d(iii) = g%Agrif_d(iii) / Agrif_Coeffref(iii)
+C
+        enddo
+C
+        if ( Agrif_Probdim .EQ. 1 ) then
+           allocate(newgrid%tabpoint1D(newgrid%nb(1)+1))
+           newgrid%tabpoint1D = 0
+        endif
+C
+        if ( Agrif_Probdim .EQ. 2 ) then
+           allocate(newgrid%tabpoint2D(newgrid%nb(1)+1,
+     &                                 newgrid%nb(2)+1))
+           newgrid%tabpoint2D = 0      
+        endif
+C
+        if ( Agrif_Probdim .EQ. 3 ) then
+           allocate(newgrid%tabpoint3D(newgrid%nb(1)+1,
+     &                                 newgrid%nb(2)+1,
+     &                                 newgrid%nb(3)+1))
+           newgrid%tabpoint3D = 0
+        endif
+C       Points detection on newgrid
+        Call Agrif_TabpointsnD(Agrif_mygrid,newgrid) 
+C
+C       Recursive call to Agrif_Cluster_All            
+        Call Agrif_Cluster_All (newgrid, parcours % r)     
+C
+        parcours => parcours % next 
+C      
+        if ( Agrif_Probdim .EQ. 1 ) Deallocate(newgrid%tabpoint1D)
+        if ( Agrif_Probdim .EQ. 2 ) Deallocate(newgrid%tabpoint2D)
+        if ( Agrif_Probdim .EQ. 3 ) Deallocate(newgrid%tabpoint3D)
+C
+        Deallocate(newgrid)   
+C
+      enddo
+C
+C      
+      End Subroutine Agrif_Cluster_All
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_TabpointsnD
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_TabpointsnD(g,newgrid)
+C
+CCC   Description:
+CCC   Copy on newgrid of points detected on the grid hierarchy pointed by g.   
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Arguments
+      TYPE(Agrif_Grid),pointer   :: g,newgrid
+C
+C     Local variables      
+      TYPE(Agrif_Pgrid),pointer  :: parcours
+C
+      REAL                  :: g_eps,newgrid_eps,eps
+      REAL   , DIMENSION(3) :: newmin,newmax
+      REAL   , DIMENSION(3) :: gmin,gmax
+      REAL   , DIMENSION(3) :: xmin
+      INTEGER, DIMENSION(3) :: igmin,inewmin
+      INTEGER, DIMENSION(3) :: inewmax
+      INTEGER               :: iii
+      INTEGER               :: i,j,k
+      INTEGER               :: i0,j0,k0
+C
+C     
+      parcours => g % child_grids
+C
+      do While(associated(parcours))
+        Call Agrif_TabpointsnD(parcours%gr,newgrid)
+        parcours => parcours % next
+      enddo      
+C
+      g_eps = 10.
+      newgrid_eps = 10.
+C      
+      do iii = 1 , Agrif_probdim
+         g_eps = min( g_eps , g % Agrif_d(iii) )
+         newgrid_eps = min(newgrid_eps,newgrid%Agrif_d(iii))
+      enddo
+C
+      eps = min(g_eps,newgrid_eps)/100.                  
+C                   
+      do iii = 1 , Agrif_probdim
+         if (newgrid%Agrif_d(iii) .LT. (g%Agrif_d(iii)-eps)) Return
+C                   
+         gmin(iii) = g%Agrif_x(iii)
+         gmax(iii) = g%Agrif_x(iii) + g%nb(iii) * g%Agrif_d(iii)
+C 
+         newmin(iii) = newgrid%Agrif_x(iii)
+         newmax(iii) = newgrid%Agrif_x(iii) + newgrid%nb(iii) *
+     &                 newgrid%Agrif_d(iii)
+C      
+         if (gmax(iii) .LT. newmin(iii)) Return
+C
+         if (gmin(iii) .GT. newmax(iii)) Return
+C           
+         inewmin(iii) = 1 - floor(-(max(gmin(iii),newmin(iii))-
+     &                    newmin(iii))
+     &                   /newgrid%Agrif_d(iii)) 
+C          
+         xmin(iii) = newgrid%Agrif_x(iii) + (inewmin(iii)-1)*
+     &              newgrid%Agrif_d(iii)          
+C        
+         igmin(iii) = 1 + nint((xmin(iii)-gmin(iii))/g%Agrif_d(iii))
+C
+         inewmax(iii) = 1 + int((min(gmax(iii),newmax(iii))-
+     &                  newmin(iii))/newgrid%Agrif_d(iii))
+      enddo
+C                
+      if ( Agrif_probdim .EQ. 1 ) then
+         i0 = igmin(1)
+         do i = inewmin(1),inewmax(1)
+            newgrid%tabpoint1D(i) = max(
+     &                           newgrid%tabpoint1D(i),
+     &                           g%tabpoint1D(i0))
+         enddo
+         i0 = i0 + int(newgrid%Agrif_d(1)/g%Agrif_d(1))
+      endif
+C
+      if ( Agrif_probdim .EQ. 2 ) then
+         i0 = igmin(1)
+         do i = inewmin(1),inewmax(1)
+            j0 = igmin(2)
+            do j = inewmin(2),inewmax(2)
+               newgrid%tabpoint2D(i,j) = max(
+     &                           newgrid%tabpoint2D(i,j),
+     &                           g%tabpoint2D(i0,j0))
+               j0 = j0 + int(newgrid%Agrif_d(2)/g%Agrif_d(2))
+            enddo
+            i0 = i0 + int(newgrid%Agrif_d(1)/g%Agrif_d(1))
+         enddo
+      endif
+C
+      if ( Agrif_probdim .EQ. 3 ) then
+         i0 = igmin(1)
+         do i = inewmin(1),inewmax(1)
+            j0 = igmin(2)
+            do j = inewmin(2),inewmax(2)
+               k0 = igmin(3)
+               do k = inewmin(3),inewmax(3)
+                  newgrid%tabpoint3D(i,j,k) = max(
+     &                           newgrid%tabpoint3D(i,j,k),
+     &                           g%tabpoint3D(i0,j0,k0))
+                  k0 = k0 + int(newgrid%Agrif_d(3)/g%Agrif_d(3))
+               enddo                                        
+               j0 = j0 + int(newgrid%Agrif_d(2)/g%Agrif_d(2))
+            enddo
+            i0 = i0 + int(newgrid%Agrif_d(1)/g%Agrif_d(1))
+         enddo
+      endif
+C
+      Return
+C
+C
+      End Subroutine Agrif_TabpointsnD
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_ClusterGridnD
+C     **************************************************************************
+C      
+      Subroutine Agrif_ClusterGridnD(g,coarsegrid)
+C
+CCC   Description:
+CCC   Clustering on the grid pointed by g.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Pointer arguments
+      TYPE(AGRIF_grid)     ,pointer  :: g          ! Pointer on the current grid
+      TYPE(AGRIF_rectangle),pointer  :: coarsegrid
+C
+C     Local variables      
+      TYPE(Agrif_rectangle) :: newrect
+      TYPE(Agrif_Variable)  :: newflag
+C
+      INTEGER               :: i,j,k
+      INTEGER ,DIMENSION(3) :: sx
+      INTEGER               :: bufferwidth,flagpoints
+      INTEGER               :: n1,n2,m1,m2,o1,o2
+      INTEGER               :: iii
+C
+C      
+      bufferwidth = int(Agrif_Minwidth/5.)
+C      
+      do iii = 1 , Agrif_probdim
+         sx(iii) = g % nb(iii) + 1
+      enddo
+C                  
+      if ( Agrif_probdim .EQ. 1 ) then
+         allocate(newflag%iarray1(sx(1)))
+         newflag%iarray1 = 0      
+      endif
+      if ( Agrif_probdim .EQ. 2 ) then
+         allocate(newflag%iarray2(sx(1),sx(2)))
+         newflag%iarray2 = 0      
+      endif
+      if ( Agrif_probdim .EQ. 3 ) then
+         allocate(newflag%iarray3(sx(1),sx(2),sx(3)))
+         newflag%iarray3 = 0      
+      endif
+C
+      flagpoints = 0 
+C      
+      if (bufferwidth>0) then 
+C      
+         if ( Agrif_probdim .EQ. 1 ) then
+            do i = bufferwidth,sx(1)-bufferwidth+1      
+               if (g % tabpoint1D(i) .EQ. 1) then
+                  m1 = i - bufferwidth + 1
+                  m2 = i + bufferwidth - 1                  
+                  flagpoints = flagpoints + 1
+                  newflag%iarray1(m1:m2)=1 
+               endif 
+            enddo    
+         endif
+C
+        if ( Agrif_probdim .EQ. 2 ) then
+           do i = bufferwidth,sx(1)-bufferwidth+1      
+               do j = bufferwidth,sx(2)-bufferwidth+1
+                  if (g % tabpoint2D(i,j) .EQ. 1) then
+                     n1 = j - bufferwidth + 1
+                     n2 = j + bufferwidth - 1
+                     m1 = i - bufferwidth + 1
+                     m2 = i + bufferwidth - 1                  
+                     flagpoints = flagpoints + 1
+                     newflag%iarray2(m1:m2,n1:n2)=1 
+                  endif  
+               enddo    
+            enddo
+         endif
+C
+        if ( Agrif_probdim .EQ. 3 ) then
+            do i = bufferwidth,sx(1)-bufferwidth+1      
+               do j = bufferwidth,sx(2)-bufferwidth+1
+                  do k = bufferwidth,sx(3)-bufferwidth+1
+                     if (g % tabpoint3D(i,j,k) .EQ. 1) then
+                        o1 = k - bufferwidth + 1
+                        o2 = k + bufferwidth - 1
+                        n1 = j - bufferwidth + 1
+                        n2 = j + bufferwidth - 1
+                        m1 = i - bufferwidth + 1
+                        m2 = i + bufferwidth - 1                  
+                        flagpoints = flagpoints + 1
+                        newflag%iarray3(m1:m2,n1:n2,o1:o2)=1 
+                     endif 
+                  enddo  
+               enddo    
+            enddo
+        endif
+      else
+          flagpoints = 1       
+C
+          if ( Agrif_probdim .EQ. 1 ) then
+          newflag%iarray1 = g % tabpoint1D
+          endif
+          if ( Agrif_probdim .EQ. 2 ) then
+          newflag%iarray2 = g % tabpoint2D
+          endif
+          if ( Agrif_probdim .EQ. 3 ) then
+          newflag%iarray3 = g % tabpoint3D
+          endif
+      endif
+C       
+      if (flagpoints .EQ. 0) then       
+          if ( Agrif_probdim .EQ. 1 ) deallocate(newflag%iarray1) 
+          if ( Agrif_probdim .EQ. 2 ) deallocate(newflag%iarray2) 
+          if ( Agrif_probdim .EQ. 3 ) deallocate(newflag%iarray3) 
+          Return 
+      endif       
+C      
+      do iii = 1 , Agrif_probdim
+         newrect % imin(iii) = 1
+         newrect % imax(iii) = sx(iii)
+      enddo
+C      
+      Call Agrif_Clusternd(newflag,
+     &                     coarsegrid%childgrids,newrect) 
+C      
+      if ( Agrif_probdim .EQ. 1 ) deallocate(newflag%iarray1)
+      if ( Agrif_probdim .EQ. 2 ) deallocate(newflag%iarray2)
+      if ( Agrif_probdim .EQ. 3 ) deallocate(newflag%iarray3)
+C  
+C    
+      End Subroutine Agrif_ClusterGridnD
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_ClusternD
+C     **************************************************************************
+C
+      Recursive subroutine Agrif_Clusternd(flag,boxlib,oldB) 
+C
+CCC   Description:
+CCC   Clustering on the grid pointed by oldB.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Arguments  
+      TYPE(Agrif_rectangle) ::  oldB    
+      TYPE(Agrif_Variable)  :: flag
+c      INTEGER,DIMENSION(oldB%imin(1):oldB%imax(1),
+c     &                  oldB%imin(2):oldB%imax(2)) :: flag
+      TYPE(Agrif_lrectangle),pointer :: boxlib      
+C
+C     Local variables      
+      TYPE(Agrif_lrectangle),pointer :: tempbox,parcbox,parcbox2       
+      TYPE(Agrif_rectangle) :: newB,newB2
+      INTEGER :: i,j,k,iii
+      INTEGER,DIMENSION(:),allocatable :: i_sig 
+      INTEGER,DIMENSION(:),allocatable :: j_sig       
+      INTEGER,DIMENSION(:),allocatable :: k_sig       
+      INTEGER,DIMENSION(3) :: ipu,ipl
+      INTEGER,DIMENSION(3) :: istr,islice
+      REAL :: cureff
+      REAL :: neweff
+      INTEGER :: ValMax,ValSum,TailleTab
+      INTEGER :: nbpoints,nbpointsflag  
+      LOGICAL :: test
+C          
+      allocate(i_sig(oldB%imin(1):oldB%imax(1)))
+      if ( Agrif_probdim .GE. 2 ) 
+     & allocate(j_sig(oldB%imin(2):oldB%imax(2)))
+      if ( Agrif_probdim .EQ. 3 ) 
+     & allocate(k_sig(oldB%imin(3):oldB%imax(3)))
+C
+      test = .FALSE.
+      do iii = 1 , Agrif_probdim
+         test = test .OR. ( (oldB%imax(iii)-oldB%imin(iii)+1) 
+     &                    .LT. Agrif_Minwidth)
+      enddo
+      if ( test ) Return
+C     
+      if ( Agrif_probdim .EQ. 1 ) i_sig = flag%iarray1
+      if ( Agrif_probdim .EQ. 2 ) then
+         do i = oldB%imin(1),oldB%imax(1)
+           i_sig(i) = SUM(flag%iarray2(i,
+     &                            oldB%imin(2):oldB%imax(2)))
+         enddo
+         do j = oldB%imin(2),oldB%imax(2)
+           j_sig(j) = SUM(flag%iarray2(
+     &                            oldB%imin(1):oldB%imax(1),j))
+         enddo      
+      endif
+      if ( Agrif_probdim .EQ. 3 ) then
+         do i = oldB%imin(1),oldB%imax(1)
+            i_sig(i) = SUM(flag%iarray3(i,
+     &                            oldB%imin(2):oldB%imax(2),
+     &                            oldB%imin(3):oldB%imax(3)))
+         enddo
+         do j = oldB%imin(2),oldB%imax(2)
+            j_sig(j) = SUM(flag%iarray3(
+     &                          oldB%imin(1):oldB%imax(1),j,
+     &                          oldB%imin(3):oldB%imax(3)))
+         enddo
+         do k = oldB%imin(3),oldB%imax(3)
+            k_sig(k) = SUM(flag%iarray3(
+     &                          oldB%imin(1):oldB%imax(1),
+     &                          oldB%imin(2):oldB%imax(2),k))
+         enddo      
+      endif
+C                    
+      do iii = 1 , Agrif_probdim
+         ipl(iii) = oldB%imin(iii)
+         ipu(iii) = oldB%imax(iii)
+      enddo
+C           
+      Call Agrif_Clusterprune(i_sig,ipl(1),ipu(1)) 
+      if ( Agrif_probdim .GE. 2 ) 
+     &   Call Agrif_Clusterprune(j_sig,ipl(2),ipu(2))      
+      if ( Agrif_probdim .EQ. 3 ) 
+     &   Call Agrif_Clusterprune(k_sig,ipl(3),ipu(3))      
+C     
+      test = .TRUE.
+      do iii = 1 , Agrif_probdim
+         test = test .AND. (ipl(iii).EQ.oldB%imin(iii))
+         test = test .AND. (ipu(iii).EQ.oldB%imax(iii))
+      enddo
+      
+      if (.NOT. test) then 
+          do iii = 1 , Agrif_probdim
+             newB%imin(iii) = ipl(iii)
+             newB%imax(iii) = ipu(iii)
+          enddo
+C        
+          if ( Agrif_probdim .EQ. 1 ) 
+     &       nbpoints = SUM(flag%iarray1(newB%imin(1):newB%imax(1)))   
+          if ( Agrif_probdim .EQ. 2 ) 
+     &       nbpoints = SUM(flag%iarray2(newB%imin(1):newB%imax(1),
+     &                           newB%imin(2):newB%imax(2)))   
+          if ( Agrif_probdim .EQ. 3 ) 
+     &       nbpoints = SUM(flag%iarray3(newB%imin(1):newB%imax(1),
+     &                           newB%imin(2):newB%imax(2),   
+     &                           newB%imin(3):newB%imax(3)))
+C   
+          if ( Agrif_probdim .EQ. 1 ) 
+     &       TailleTab = newB%imax(1)-newB%imin(1)+1
+          if ( Agrif_probdim .EQ. 2 ) 
+     &       TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                   (newB%imax(2)-newB%imin(2)+1)
+          if ( Agrif_probdim .EQ. 3 ) 
+     &       TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                   (newB%imax(2)-newB%imin(2)+1)*
+     &                   (newB%imax(3)-newB%imin(3)+1)
+C
+          neweff = REAL(nbpoints)/TailleTab
+C     
+          if (nbpoints.GT.0) then
+C        
+              if ((neweff .GT .Agrif_efficiency)) then
+                  Call Agrif_Add_Rectangle(newB,boxlib)
+                  Return
+              else
+C            
+                  tempbox => boxlib
+                  newB2 = newB
+                  Call Agrif_Clusternd(flag,
+     &                      boxlib,newB)
+C     
+C                 Compute new efficiency
+C
+                  cureff = neweff
+                  parcbox2 => boxlib
+                  nbpoints = 0
+                  nbpointsflag = 0
+C
+                  do While (associated(parcbox2))
+                    if (associated(parcbox2,tempbox)) Exit
+                    newB = parcbox2%r
+C
+                    if ( Agrif_probdim .EQ. 1 ) Valsum = 
+     &                                 SUM(flag%iarray1(
+     &                                 newB%imin(1):newB%imax(1)))
+                    if ( Agrif_probdim .EQ. 2 ) Valsum = 
+     &                                 SUM(flag%iarray2(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2)))
+                    if ( Agrif_probdim .EQ. 3 ) Valsum = 
+     &                                 SUM(flag%iarray3(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2),
+     &                                 newB%imin(3):newB%imax(3)))
+C
+                    nbpointsflag = nbpointsflag + ValSum
+                    if ( Agrif_probdim .EQ. 1 ) 
+     &                 TailleTab = newB%imax(1)-newB%imin(1)+1
+                    if ( Agrif_probdim .EQ. 2 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)
+                    if ( Agrif_probdim .EQ. 3 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)*
+     &                             (newB%imax(3)-newB%imin(3)+1)
+                    nbpoints = nbpoints + TailleTab
+                    parcbox2 => parcbox2%next  
+                  enddo  
+C coefficient 1.05 avant 1.15 possibilité de laisser choix à l utilisateur
+                  if  (REAL(nbpointsflag)/REAL(nbpoints)
+     &                 .LT.(1.0001*cureff)) then
+                      parcbox2 => boxlib            
+                      do While (associated(parcbox2))
+                        if (associated(parcbox2,tempbox)) Exit
+                        deallocate(parcbox2%r)
+                        parcbox2 => parcbox2%next             
+                      enddo      
+                      boxlib => tempbox
+                      Call Agrif_Add_Rectangle(newB2,boxlib)
+                      Return
+                  endif
+              endif         
+          endif
+          Return
+      endif 
+C       
+      do iii = 1 , Agrif_Probdim
+         istr(iii) = oldB%imax(iii)
+         islice(iii) = oldB%imin(iii)
+      enddo     
+C      
+      Call Agrif_Clusterslice(i_sig,islice(1),istr(1)) 
+      if ( Agrif_probdim .GE. 2 ) 
+     & Call Agrif_Clusterslice(j_sig,islice(2),istr(2)) 
+      if ( Agrif_probdim .EQ. 3 ) 
+     & Call Agrif_Clusterslice(k_sig,islice(3),istr(3)) 
+C      
+      ValSum = 0
+      do iii = 1 , Agrif_Probdim
+         Valsum = valSum + islice(iii)
+      enddo
+C      
+      if ( Valsum .EQ. -Agrif_Probdim ) then 
+          Call Agrif_Add_Rectangle(oldB,boxlib) 
+          Return 
+      endif 
+C       
+      nullify(tempbox)
+      tempbox => boxlib
+      if ( Agrif_probdim .EQ. 1 ) 
+     &      cureff  = oldB%imax(1)-oldB%imin(1)+1
+      if ( Agrif_probdim .EQ. 2 ) 
+     &      cureff  = (oldB%imax(1)-oldB%imin(1)+1)*
+     &                (oldB%imax(2)-oldB%imin(2)+1)
+      if ( Agrif_probdim .EQ. 3 ) 
+     &       cureff = (oldB%imax(1)-oldB%imin(1)+1)*
+     &                (oldB%imax(2)-oldB%imin(2)+1)*
+     &                (oldB%imax(3)-oldB%imin(3)+1)
+      Nullify(parcbox)
+C 
+      do iii = 1 , Agrif_Probdim
+          newB%imax(iii) = oldB%imax(iii)            
+          newB%imin(iii) = oldB%imin(iii)
+      enddo     
+C
+      ValMax = 0
+      do iii = 1 , Agrif_Probdim
+         ValMax = Max(ValMax,istr(iii))
+      enddo
+C
+      if (istr(1) .EQ. ValMax ) then
+          newB%imax(1) = islice(1)
+          Call Agrif_Add_Rectangle(newB,parcbox)                   
+          newB%imin(1) = islice(1)+1
+          newB%imax(1) = oldB%imax(1)
+          Call Agrif_Add_Rectangle(newB,parcbox)
+      elseif ( Agrif_probdim .GE. 2 ) then
+         if (istr(2) .EQ. ValMax ) then
+            newB%imax(2) = islice(2)
+            Call Agrif_Add_Rectangle(newB,parcbox)
+            newB%imin(2) = islice(2)+1
+            newB%imax(2) = oldB%imax(2)
+            Call Agrif_Add_Rectangle(newB,parcbox)
+         elseif ( Agrif_probdim .EQ. 3 ) then
+            newB%imax(3) = islice(3)
+            Call Agrif_Add_Rectangle(newB,parcbox)
+            newB%imin(3) = islice(3)+1
+            newB%imax(3) = oldB%imax(3)
+            Call Agrif_Add_Rectangle(newB,parcbox)
+         endif
+      endif
+C      
+      do While (associated(parcbox))
+        newB = parcbox%r            
+C
+        if ( Agrif_probdim .EQ. 1 ) nbpoints = 
+     &                                 SUM(flag%iarray1(
+     &                                 newB%imin(1):newB%imax(1)))
+        if ( Agrif_probdim .EQ. 2 ) nbpoints = 
+     &                                 SUM(flag%iarray2(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2)))
+        if ( Agrif_probdim .EQ. 3 ) nbpoints = 
+     &                                 SUM(flag%iarray3(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2),
+     &                                 newB%imin(3):newB%imax(3)))
+C      
+       if ( Agrif_probdim .EQ. 1 ) 
+     &                 TailleTab = newB%imax(1)-newB%imin(1)+1
+       if ( Agrif_probdim .EQ. 2 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)
+       if ( Agrif_probdim .EQ. 3 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)*
+     &                             (newB%imax(3)-newB%imin(3)+1)
+
+        neweff = REAL(nbpoints) / TailleTab
+C     
+        if (nbpoints .GT. 0) then
+C      
+            if ((neweff .GT .Agrif_efficiency)) then
+                Call Agrif_Add_Rectangle(newB,boxlib)
+            else
+                tempbox => boxlib
+                newB2 = newB
+                Call Agrif_Clusternd(flag,
+     &                      boxlib,newB)
+C
+C               Compute new efficiency
+C
+                cureff = neweff
+                parcbox2 => boxlib
+                nbpoints = 0
+                nbpointsflag = 0
+C
+                do While (associated(parcbox2))
+                  if (associated(parcbox2,tempbox)) Exit
+                  newB = parcbox2%r
+C
+                  if ( Agrif_probdim .EQ. 1 ) ValSum = 
+     &                                 SUM(flag%iarray1(
+     &                                 newB%imin(1):newB%imax(1)))
+                  if ( Agrif_probdim .EQ. 2 ) ValSum = 
+     &                                 SUM(flag%iarray2(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2)))
+                  if ( Agrif_probdim .EQ. 3 ) ValSum = 
+     &                                 SUM(flag%iarray3(
+     &                                 newB%imin(1):newB%imax(1),
+     &                                 newB%imin(2):newB%imax(2),
+     &                                 newB%imin(3):newB%imax(3)))
+C
+                  nbpointsflag = nbpointsflag + ValSum
+C
+                    if ( Agrif_probdim .EQ. 1 ) 
+     &                 TailleTab = newB%imax(1)-newB%imin(1)+1
+                    if ( Agrif_probdim .EQ. 2 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)
+                    if ( Agrif_probdim .EQ. 3 ) 
+     &                 TailleTab = (newB%imax(1)-newB%imin(1)+1)*
+     &                             (newB%imax(2)-newB%imin(2)+1)*
+     &                             (newB%imax(3)-newB%imin(3)+1)
+
+                  nbpoints = nbpoints + TailleTab
+C              
+                  parcbox2 => parcbox2%next  
+                enddo   
+C            
+                if  (REAL(nbpointsflag)/REAL(nbpoints)
+     &               .LT.(1.15*cureff)) then
+                    parcbox2 => boxlib            
+                    do While (associated(parcbox2))
+                      if (associated(parcbox2,tempbox)) Exit
+                      deallocate(parcbox2%r)
+                      parcbox2 => parcbox2%next             
+                    enddo
+                    boxlib => tempbox
+                    Call Agrif_Add_Rectangle(newB2,boxlib)
+                endif
+            endif
+        endif
+        parcbox => parcbox%next
+      enddo
+C      
+C      
+      Return
+C      
+      End Subroutine Agrif_Clusternd 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Clusterslice
+C     **************************************************************************
+C                           
+      Subroutine Agrif_Clusterslice(sig,slice,str) 
+C
+C
+CCC   Description:
+CCC   
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Arguments 
+      INTEGER                      :: slice,str
+      INTEGER,DIMENSION(slice:str) :: sig 
+C
+C     Local variables      
+      INTEGER                      :: ideb,ifin
+      INTEGER                      :: i,t,a,di,ts 
+      INTEGER,DIMENSION(slice:str) :: lap 
+C
+C    
+      ideb = slice
+      ifin = str
+C    
+      if (SIZE(sig) <= 2*Agrif_Minwidth) then
+          str = -1 
+          slice = -1 
+          Return
+      endif
+C      
+      t = -1 
+      a = -1 
+C
+      do i = ideb+Agrif_Minwidth-1,ifin-Agrif_Minwidth
+          if (sig(i) .EQ. 0) then
+              if ((i-ideb) < (ifin-i)) then
+                  di = i - ideb
+                else 
+                  di = ifin - i 
+              endif
+C
+              if (di > t) then
+                a = i 
+                t = di 
+              endif
+         endif
+      enddo
+C      
+      if (a .NE. (-1)) then
+          slice = a 
+          str = t 
+          Return
+      endif
+C      
+      t = -1 
+      a = -1 
+C      
+      do i = ideb+1,ifin-1 
+        lap(i) = sig(i+1) + sig(i-1) - 2*sig(i) 
+      enddo
+C      
+      do i = ideb + Agrif_Minwidth-1,ifin-Agrif_Minwidth
+        if ((lap(i+1)*lap(i)) .LE. 0) then
+            ts = ABS(lap(i+1) - lap(i)) 
+            if (ts > t) then
+                t = ts 
+                a = i
+            endif
+       endif
+      enddo
+C      
+      if (a .EQ. (ideb + Agrif_Minwidth - 1)) then
+          a = -1
+          t = -1
+      endif
+C      
+      slice = a 
+      str = t 
+C
+C      
+      End Subroutine Agrif_Clusterslice       
+C
+C
+C    
+C     **************************************************************************
+CCC   Subroutine Agrif_Clusterprune
+C     **************************************************************************
+C      
+      Subroutine Agrif_Clusterprune(sig,pl,pu) 
+C
+C
+CCC   Description:
+CCC   
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C     Arguments
+      INTEGER                  :: pl,pu 
+      INTEGER,DIMENSION(pl:pu) :: sig
+C
+C     Local variables      
+      INTEGER :: ideb,ifin       
+      INTEGER :: diff,addl,addu,udist,ldist  
+C
+C      
+      ideb = pl
+      ifin = pu
+C      
+      if (SIZE(sig) <= Agrif_Minwidth) then
+          return 
+      endif 
+C       
+      do While ((sig(pl) .EQ. 0) .AND. (pl < ifin)) 
+        pl = pl + 1 
+      enddo 
+C       
+      do While ((sig(pu) .EQ. 0) .AND. (pu > ideb)) 
+        pu = pu - 1 
+      enddo 
+C       
+      if ((pu-pl) < Agrif_Minwidth) then
+          diff = Agrif_Minwidth - (pu - pl + 1) 
+          udist = ifin - pu 
+          ldist = pl - ideb
+          addl = diff / 2 
+          addu = diff - addl 
+          if (addu > udist) then
+              addu = udist 
+              addl = diff - addu 
+          endif
+C         
+          if (addl > ldist) then
+              addl = ldist 
+              addu = diff - addl
+          endif
+C         
+          pu = pu + addu 
+          pl = pl - addl         
+C      
+      endif 
+C       
+C
+      End Subroutine Agrif_Clusterprune
+C
+C
+C              
+C     **************************************************************************
+CCC   Subroutine Agrif_Add_Rectangle 
+C     **************************************************************************
+C        
+      Subroutine Agrif_Add_Rectangle(R,LR)
+C
+CCC   Description:
+CCC   Subroutine to add the Agrif_Rectangle R in a list managed by LR.
+C
+C     Declarations:
+C
+C     Arguments               
+      TYPE(AGRIF_rectangle)           :: R  
+      TYPE(AGRIF_lrectangle), Pointer :: LR
+C
+C     Local variable        
+      TYPE(AGRIF_lrectangle), Pointer :: newrect  
+C
+      INTEGER                         :: iii 
+C
+C        
+      allocate(newrect)
+      allocate(newrect % r)
+C
+      newrect % r = R
+C      
+      do iii = 1 , Agrif_Probdim
+         newrect % r % spaceref(iii) = Agrif_Coeffref(iii)
+         newrect % r % timeref(iii) = Agrif_Coeffreft(iii)
+      enddo
+C              
+      newrect % r % number = -1            
+      Nullify(newrect % r % childgrids)
+      newrect % next => LR  
+      LR => newrect  
+C
+C      
+      End Subroutine Agrif_Add_Rectangle   
+C  
+C
+C  
+C     **************************************************************************
+CCC   Subroutine Agrif_Read_Fix_Grd  
+C     **************************************************************************
+C      
+      Recursive Subroutine Agrif_Read_Fix_Grd(coarsegrid,j,nunit)
+C
+CCC   Description:
+CCC   Subroutine to create the grid hierarchy from the reading of the 
+CCC   AGRIF_FixedGrids.in file.
+C
+CC    Method:
+CC    Recursive subroutine and creation of a first grid hierarchy from the
+CC    reading of the AGRIF_FixedGrids.in file.        
+C
+C     Declarations:
+C
+C     Pointer argument      
+      TYPE(AGRIF_rectangle), Pointer   :: coarsegrid ! Pointer on the first grid
+                                                     ! of the grid hierarchy
+C                                    
+C     Scalar arguments                                    
+      INTEGER                          :: j          ! Number of the new grid
+      INTEGER                          :: nunit      ! unit associated with file
+C      
+C     Local variables      
+      TYPE(AGRIF_rectangle)            :: newrect    ! Pointer on a new grid   
+      TYPE(AGRIF_lrectangle), Pointer  :: parcours   ! Pointer for the recursive
+                                                     !    procedure
+      TYPE(AGRIF_lrectangle), Pointer  :: newlrect
+      TYPE(AGRIF_lrectangle), Pointer  :: end_list       
+      INTEGER                          :: i          ! for each child grid
+      INTEGER                          :: nb_grids   ! Number of child grids
+      INTEGER                          :: iii
+C          
+C
+      Nullify(newrect%childgrids)
+C      
+C     Reading of the number of child grids        
+      read(nunit,*) nb_grids
+C      
+C     coarsegrid%nbgridchild = nb_grids
+C      
+      allocate(end_list)
+C
+      nullify(end_list % r)
+      nullify(end_list % next)
+C      
+      coarsegrid % childgrids => end_list
+C
+C     Reading of imin(1),imax(1),imin(2),imax(2),imin(3),imax(3), and space and
+C        time refinement factors for each child grid.
+C     Creation and addition of the new grid to the grid hierarchy. 
+C
+      do i = 1,nb_grids
+        allocate(newlrect)      
+        newrect % number = j   ! Number of the grid
+C
+        if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+           if (Agrif_Probdim == 3) then  
+            read(nunit,*) newrect % imin(1), newrect % imax(1),
+     &                    newrect % imin(2), newrect % imax(2),
+     &                    newrect % imin(3), newrect % imax(3),
+     &                    newrect % spaceref(1),newrect % spaceref(2),
+     &                    newrect % spaceref(3),
+     &                    newrect % timeref(1),newrect % timeref(2),
+     &                    newrect % timeref(3)
+           elseif (Agrif_Probdim == 2) then            
+            read(nunit,*) newrect % imin(1),newrect % imax(1),
+     &                  newrect % imin(2),newrect % imax(2),
+     &                    newrect % spaceref(1),newrect % spaceref(2),
+     &                    newrect % timeref(1),newrect % timeref(2)
+           elseif (Agrif_Probdim == 1) then
+            read(nunit,*) newrect % imin(1), newrect % imax(1),
+     &                    newrect % spaceref(1),
+     &                    newrect % timeref(1)
+           endif
+        else
+           if (Agrif_Probdim == 3) then  
+            read(nunit,*) newrect % imin(1), newrect % imax(1),
+     &                    newrect % imin(2), newrect % imax(2),
+     &                    newrect % imin(3), newrect % imax(3),
+     &                    newrect % spaceref(1),newrect % spaceref(2),
+     &                    newrect % spaceref(3),
+     &                    newrect % timeref(1)
+           elseif (Agrif_Probdim == 2) then            
+            read(nunit,*) newrect % imin(1),newrect % imax(1),
+     &                  newrect % imin(2),newrect % imax(2),
+     &                    newrect % spaceref(1),newrect % spaceref(2),
+     &                    newrect % timeref(1)
+           elseif (Agrif_Probdim == 1) then
+            read(nunit,*) newrect % imin(1), newrect % imax(1),
+     &                    newrect % spaceref(1),
+     &                    newrect % timeref(1)
+           endif
+C
+           if ( Agrif_probdim .GE. 2 ) then
+              do iii = 2 , Agrif_probdim
+                 newrect % timeref(iii) = newrect % timeref(1) 
+              enddo
+           endif
+C
+        endif
+C
+C       Addition to the grid hierarchy
+C
+        nullify(newrect % childgrids)
+        j = j + 1
+        Allocate(newlrect%r)
+        newlrect % r = newrect 
+        nullify(newlrect % next)
+        end_list % next => newlrect
+        end_list => end_list % next
+      enddo
+C      
+      coarsegrid % childgrids => coarsegrid % childgrids % next
+      parcours => coarsegrid % childgrids
+C
+C     Recursive operation to create the grid hierarchy branch by branch
+C
+      do while (associated(parcours))
+        call Agrif_Read_Fix_Grd (parcours % r,j,nunit)
+        parcours => parcours % next
+      enddo
+C      
+C
+      End Subroutine Agrif_Read_Fix_Grd        
+C        
+C 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Create_Grids  
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Create_Grids(g,coarsegrid)
+C
+CCC   Description:
+CCC   Subroutine to create the grid hierarchy (g) from the one created with the
+CCC   Agrif_Read_Fix_Grd or Agrif_Cluster_All procedures (coarsegrid).
+C
+CC    Method:
+CC    Recursive subroutine.        
+C
+C     Declarations:
+C
+C     Pointer arguments        
+      TYPE(AGRIF_grid)     , Pointer  :: g          ! Pointer on the root coarse
+                                                    ! grid
+      TYPE(AGRIF_rectangle), Pointer  :: coarsegrid ! Pointer on the root coarse
+                                                    ! grid of the grid hierarchy
+                                                    ! created with the
+                                                    ! Agrif_Read_Fix_Grd
+                                                    ! subroutine
+C
+C     Local pointers
+      TYPE(Agrif_grid)      , Pointer :: newgrid    ! New grid
+      TYPE(Agrif_pgrid)     , Pointer :: newpgrid
+      TYPE(Agrif_pgrid)     , Pointer :: parcours2
+      TYPE(Agrif_lrectangle), Pointer :: parcours
+      TYPE(Agrif_pgrid)     , Pointer :: end_list
+      TYPE(Agrif_pgrid)     , Pointer :: parcours3
+C
+C     Local scalars      
+      LOGICAL                         :: nullliste
+      INTEGER                         :: iii
+      INTEGER                         :: moving_grid_id = 0      
+
+C
+      parcours3 => g % child_grids
+C     
+      if (associated(parcours3)) then
+          do While (associated(parcours3 % next))
+            parcours3 => parcours3 % next
+          enddo
+          end_list => parcours3
+          nullliste=.FALSE.
+        else
+          allocate(end_list)
+          nullify(end_list % gr)
+          nullify(end_list % next)      
+          g % child_grids => end_list 
+          parcours3 => end_list      
+          nullliste=.TRUE.
+      endif
+C      
+      parcours => coarsegrid % childgrids
+C      
+C     Creation of the grid hierarchy from the one created by using the 
+C     Agrif_Read_Fix_Grd subroutine 
+C
+      do while (associated(parcours))
+        allocate(newgrid)        
+        moving_grid_id=moving_grid_id+1
+        newgrid % grid_id = moving_grid_id
+        do iii = 1 , Agrif_Probdim
+           newgrid % spaceref(iii) = parcours % r % spaceref(iii)
+           newgrid % timeref(iii) = parcours % r % timeref(iii)
+        enddo
+C
+        do iii = 1 , Agrif_Probdim
+          newgrid % nb(iii) = (parcours % r % imax(iii) 
+     &                       - parcours % r % imin(iii)) 
+     &                       * parcours % r % spaceref(iii)
+C     
+          newgrid % ix(iii) =  parcours % r % imin(iii)
+C
+          newgrid % Agrif_d(iii) = g % Agrif_d(iii) 
+     &                  / REAL(newgrid % spaceref(iii))
+C
+          newgrid % Agrif_x(iii) = g % Agrif_x(iii) +
+     &      (parcours % r % imin(iii) - 1)* g % Agrif_d(iii)
+C      
+        enddo
+C
+C       Pointer on the parent grid                        
+C
+        newgrid % parent => g      
+C      
+C       Grid pointed by newgrid is a fixed grid      
+C
+        if (parcours % r % number .GT. 0) then      
+            newgrid % fixed = .true.  
+          else
+            newgrid % fixed = .false.
+        endif
+C
+C       Number of the grid pointed by newgrid
+        newgrid % fixedrank = parcours % r % number
+C           
+C       No time calculation on this grid         
+        newgrid % ngridstep = 0      
+C
+C       Test indicating if the current grid has a common border with the root 
+C       coarse grid in the x direction
+        do iii = 1 , Agrif_Probdim
+           newgrid % NearRootBorder(iii) = .FALSE.
+C        
+           if ((newgrid % parent % NearRootBorder(iii)) .AND. 
+     &         (newgrid % ix(iii) == 1)) then
+               newgrid % NearRootBorder(iii) = .TRUE.
+           endif
+C
+           newgrid % DistantRootBorder(iii) = .FALSE.
+C 
+           if ((newgrid % parent % DistantRootBorder(iii)) .AND. 
+     &         (newgrid % ix(iii) + 
+     &         (newgrid % nb(iii)/newgrid % spaceref(iii))  
+     &          - 1  == newgrid % parent % nb(iii))) then
+               newgrid % DistantRootBorder(iii) = .TRUE.
+           endif
+        enddo
+C
+C       Writing in output files
+C
+        newgrid % oldgrid = .FALSE.      
+C
+C     
+C       Definition of the CHARACTERistics of the variable of the grid pointed by
+C       newgrid 
+        Call Agrif_Create_Var (newgrid)
+C      
+C       Instanciation of the grid pointed by newgrid and its variables
+        Call Agrif_Instance (newgrid)
+C       
+C       Nullify the variable of the grid pointed by newgrid
+C
+C
+C       Addition of this grid to the grid hierarchy 
+C      
+        nullify(newgrid % child_grids)
+        allocate(newpgrid)  
+        newpgrid % gr => newgrid
+        nullify(newpgrid % next)
+        end_list % next => newpgrid
+        end_list => end_list % next               
+        parcours => parcours % next
+C
+C       Updating the total number of fixed grids
+        if (newgrid % fixed) then
+            AGRIF_nbfixedgrids = AGRIF_nbfixedgrids + 1
+        endif
+C                  
+      enddo
+C
+C
+      if (nullliste) then
+          g % child_grids => g % child_grids % next
+          parcours2 => g % child_grids
+          deallocate(parcours3)
+        else
+          parcours2 => parcours3 % next
+      endif
+C      
+      parcours => coarsegrid % childgrids
+C
+C     Recursive call to the subroutine Agrif_Create_Fixed_Grids to create the
+C     grid hierarchy
+C      
+      do while (associated(parcours))
+        Call Agrif_Create_Grids (parcours2 % gr,parcours % r)
+        parcours => parcours % next
+        parcours2 => parcours2 % next
+      enddo 
+C      
+      Return      
+C                  
+      End Subroutine Agrif_Create_Grids
+C
+C      
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_Hierarchy  
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Init_Hierarchy(g) 
+C
+CCC   Description:
+CCC   Subroutine to initialize all the grids except the root coarse grid (this 
+CCC   one, pointed by AGRIF_mygrid, is initialized by the subroutine 
+CCC   Agrif_Init_Grids defi ned in the module Agrif_Util and called in the main 
+CCC   program ). 
+C
+CC    Method:
+CC    Recursive subroutine.        
+C
+C     Declarations:
+C
+C     Pointer argument      
+      TYPE(AGRIF_grid), Pointer  :: g         ! Pointer on the root coarse grid 
+C      
+C     Local variables      
+      TYPE(AGRIF_pgrid), Pointer :: parcours  ! Pointer for the recursive call
+      LOGICAL                    :: Init_Hierarchy
+C      
+C
+      parcours=>g%child_grids
+C      
+      do while (associated(parcours))
+        Init_Hierarchy = .false.
+        if ( AGRIF_USE_FIXED_GRIDS .EQ. 1 .OR. 
+     &       AGRIF_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then
+           if ((parcours%gr%fixed) 
+     &         .AND. (Agrif_mygrid%ngridstep == 0)) then
+              Init_Hierarchy = .true.
+           endif      
+       endif
+C
+       if (.NOT. parcours%gr%fixed) Init_Hierarchy = .true.
+       if (parcours % gr % oldgrid) Init_Hierarchy = .false.
+C
+       if (Init_Hierarchy) then 
+C
+C           Instanciation of the grid pointed by parcours%gr and its variables 
+            Call Agrif_Instance (parcours % gr)
+C    
+C           Allocation of the arrays containing values of the variables of the
+C           grid pointed by parcours%gr      
+C      
+            Call Agrif_Allocation (parcours % gr)     
+C       
+            Call Agrif_Instance(parcours % gr)
+C
+            if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+              Call Agrif_Allocate_Restore (parcours % gr)
+            endif
+C
+            if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+C              Initialization by copy of the grids created by clustering 
+               Call AGRIF_CopyFromold_All (parcours%gr,
+     &                                     Agrif_oldmygrid)
+            endif
+C
+C           Initialization by interpolation 
+C           (this routine is written by the user) 
+            Call Agrif_InitValues()
+C
+            if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+               Call Agrif_Free_Restore (parcours % gr)
+            endif
+C
+       endif                                  
+       parcours => parcours % next 
+C         
+      enddo
+C
+      parcours => g % child_grids
+C      
+C     Recursive operation to initialize all the grids
+      do while (associated(parcours))
+        Call Agrif_Init_Hierarchy (parcours%gr)
+        parcours => parcours%next
+      enddo
+C      
+      End Subroutine Agrif_Init_Hierarchy 
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Allocate_Restore  
+C     **************************************************************************
+C
+      Subroutine Agrif_Allocate_Restore(Agrif_Gr)
+C      
+C      
+C     Modules used:
+C
+      TYPE(AGRIF_grid), Pointer  :: Agrif_Gr   ! Pointer on the root coarse grid
+C     
+      INTEGER                    :: i
+C
+        do i = 1 , Agrif_NbVariables
+            if ( Agrif_Mygrid%tabvars(i)%var % restaure ) then
+            if ( Agrif_Gr%tabvars(i)%var % nbdim .EQ. 1 ) then    
+            Allocate( Agrif_Gr%tabvars(i)%var%  
+     &    Restore1D(lbound(Agrif_Gr%tabvars(i)%var%array1,1) 
+     &    :ubound(Agrif_Gr%tabvars(i)%var%array1,1))) 
+            Agrif_Gr%tabvars(i)%var%Restore1D = 0
+C
+            endif
+            if ( Agrif_Gr%tabvars(i)%var % nbdim .EQ. 2 ) then
+            Allocate( Agrif_Gr%tabvars(i)%var%Restore2D(  
+     &      lbound(Agrif_Gr%tabvars(i)%var%array2,1):         
+     &      ubound(Agrif_Gr%tabvars(i)%var%array2,1),         
+     &      lbound(Agrif_Gr%tabvars(i)%var%array2,2)          
+     &      :ubound(Agrif_Gr%tabvars(i)%var%array2,2)))         
+            Agrif_Gr%tabvars(i)%var%Restore2D = 0
+C
+            endif
+            if ( Agrif_Mygrid%tabvars(i)%var % nbdim .EQ. 3 ) then
+C     
+            Allocate( Agrif_Gr%tabvars(i)%var%Restore3D( 
+     &      lbound(Agrif_Gr%tabvars(i)%var%array3,1):        
+     &      ubound(Agrif_Gr%tabvars(i)%var%array3,1),        
+     &      lbound(Agrif_Gr%tabvars(i)%var%array3,2):        
+     &      ubound(Agrif_Gr%tabvars(i)%var%array3,2),        
+     &      lbound(Agrif_Gr%tabvars(i)%var%array3,3):        
+     &      ubound(Agrif_Gr%tabvars(i)%var%array3,3)))  
+            Agrif_Gr%tabvars(i)%var%Restore3D = 0
+            endif
+C 
+            endif
+          enddo
+C
+      Return
+C
+C      
+      End Subroutine Agrif_Allocate_Restore      
+C
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Free_Restore  
+C     **************************************************************************
+C
+      Subroutine Agrif_Free_Restore(Agrif_Gr)
+C
+C      
+C     Pointer argument      
+      TYPE(AGRIF_grid), Pointer  :: Agrif_Gr   ! Pointer on the root coarse grid
+      INTEGER :: i     
+C
+      do i = 1 , Agrif_NbVariables
+         if ( Agrif_Mygrid % tabvars(i) % var % restaure) then
+C  
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore1D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore1D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore2D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore2D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore3D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore3D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore4D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore4D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore5D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore5D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%Restore6D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%Restore6D)
+            endif
+C 
+        endif
+      enddo
+C 
+      Return
+C
+C      
+      End Subroutine Agrif_Free_Restore
+C
+C
+C
+      End Module Agrif_Clustering
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcurgridfunctions.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcurgridfunctions.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modcurgridfunctions.F	(revision 4536)
@@ -0,0 +1,804 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_CurgridFunctions      
+C      
+      Module Agrif_CurgridFunctions    
+C  
+CCC   Description:
+CCC   Module to define some procedures concerning the current grid
+C
+C     Modules used: 
+C
+      Use Agrif_Init
+C
+      IMPLICIT NONE
+C
+C
+      Contains
+C     Define procedures contained in this module
+C
+C     **************************************************************************
+CCC   Function Agrif_Rhot
+C     **************************************************************************
+C
+      Function Agrif_Rhot()
+C  
+CCC   Description:
+CCC   Function returning the time refinement factor of the current grid.
+C
+C     Declarations:
+C  
+      
+C
+      REAL :: Agrif_Rhot  ! Result
+C
+C     Local scalar      
+      INTEGER :: res         ! Intermediate result
+      INTEGER :: iii
+C
+C
+      res=1
+C
+      do iii = 1 , Agrif_Probdim
+         res = max(res, AGRIF_Curgrid % timeref(iii))
+      enddo
+C
+      Agrif_Rhot = float(res)
+C
+C
+      End function Agrif_rhot
+C
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_IRhot
+C     **************************************************************************
+C
+      Function Agrif_IRhot()
+C  
+CCC   Description:
+CCC   Function returning the time refinement factor of the current grid.
+C
+C     Declarations:
+C  
+      
+C
+      INTEGER :: Agrif_IRhot  ! Result
+C
+C     Local scalar      
+      INTEGER :: res         ! Intermediate result
+      INTEGER :: iii
+C
+C
+      res=1
+C
+      do iii = 1 , Agrif_Probdim
+         res = max(res, AGRIF_Curgrid % timeref(iii))
+      enddo
+C
+      Agrif_IRhot = res
+C
+C
+      End function Agrif_IRhot
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Parent_Rhot
+C     **************************************************************************
+C
+      Function Agrif_Parent_Rhot()
+C  
+CCC   Description:
+CCC   Function returning the time refinement factor of the parent grid of the 
+CCC   current grid.
+C
+C     Declarations:
+C  
+      
+C
+      REAL :: Agrif_Parent_Rhot  ! Result
+C
+C     Local scalar      
+      INTEGER :: res         ! Intermediate result
+      INTEGER :: iii
+C
+C
+      res=1
+C
+      do iii = 1 , Agrif_Probdim
+         res = max(res, AGRIF_Curgrid % parent % timeref(iii))
+      enddo
+C
+      Agrif_Parent_Rhot = float(res)
+C
+C
+      End function Agrif_Parent_Rhot      
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Parent_IRhot
+C     **************************************************************************
+C
+      Function Agrif_Parent_IRhot()
+C  
+CCC   Description:
+CCC   Function returning the time refinement factor of the parent grid of the 
+CCC   current grid.
+C
+C     Declarations:
+C  
+      
+C
+      INTEGER :: Agrif_Parent_IRhot  ! Result
+C
+C     Local scalar      
+      INTEGER :: res         ! Intermediate result
+      INTEGER :: iii
+C
+C
+      res=1
+C
+      do iii = 1 , Agrif_Probdim
+         res = max(res, AGRIF_Curgrid % parent % timeref(iii))
+      enddo
+C
+      Agrif_Parent_IRhot = res
+C
+C
+      End function Agrif_Parent_IRhot      
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Nbstepint
+C     **************************************************************************
+C
+      Function Agrif_Nbstepint()
+C  
+CCC   Description:
+CCC   Function for the calculation of the coefficients used for the time 
+CCC   interpolation (module Agrif_Boundary).
+C
+C     Declarations:
+C  
+      
+C            
+      INTEGER :: Agrif_nbstepint  ! result
+C
+C
+      Agrif_nbstepint = mod(AGRIF_CURGRID % ngridstep,
+     &                      int(AGRIF_rhot()))
+C
+C
+      End function Agrif_Nbstepint
+C
+C
+C
+CC    **************************************************************************
+CCC   Function Agrif_Parent_Nbstepint
+C     **************************************************************************
+C
+      Function Agrif_Parent_Nbstepint()
+C  
+CCC   Description:
+CCC   Function for the calculation of the coefficients used for the time 
+CCC   interpolation (module Agrif_Boundary).
+C
+C     Declarations:
+C  
+      
+C            
+      INTEGER :: Agrif_Parent_Nbstepint  ! result
+C
+C
+      Agrif_Parent_Nbstepint = mod(AGRIF_CURGRID % parent % ngridstep, 
+     &                             int(AGRIF_Parent_Rhot()))
+C
+C
+      End function Agrif_Parent_Nbstepint
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpNearBorderX
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpNearBorderX()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the x direction) on a near border of 
+CCC   the current grid if this one has a common border with the root coarse 
+CCC   grid.   
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_CURGRID % NearRootBorder(1) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpNearBorderX 
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpDistantBorderX
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpDistantBorderX()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the x direction) on a distant border 
+CCC   of the current grid if this one has a common border with the root coarse  
+CCC   grid.
+C
+C     Declarations:
+C  
+
+C
+C
+      AGRIF_CURGRID % DistantRootBorder(1) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpDistantBorderX                 
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpNearBorderY
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpNearBorderY()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the y direction) on a near border of 
+CCC   the current grid if this one has a common border with the root coarse 
+CCC   grid.
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_CURGRID % NearRootBorder(2) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpNearBorderY
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpDistantBorderY
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpDistantBorderY()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the y direction) on a distant border 
+CCC   of the current grid if this one has a common border with the root coarse  
+CCC   grid.
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_CURGRID % DistantRootBorder(2) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpDistantBorderY      
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpNearBorderZ
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpNearBorderZ()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the z direction) on a near border of 
+CCC   the current grid if this one has a common border with the root coarse 
+CCC   grid.
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_CURGRID % NearRootBorder(3) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpNearBorderZ
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpDistantBorderZ
+C     **************************************************************************
+C
+      Subroutine Agrif_InterpDistantBorderZ()
+C  
+CCC   Description:
+CCC   Subroutine allowing to interpole (in the z direction) on a distant border 
+CCC   of the current grid if this one has a common border with the root coarse  
+CCC   grid.
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_CURGRID % DistantRootBorder(3) = .FALSE.             
+C
+C
+      End Subroutine Agrif_InterpDistantBorderZ
+C 
+C     **************************************************************************
+CCC   Function Agrif_Parent_Nb_Step
+C     ************************************************************************** 
+C 
+      Function AGRIF_Parent_Nb_Step() 
+C  
+CCC   Description:
+CCC   Function returning the number of time steps of the parent grid of the
+CCC   current grid.
+C
+C     Declarations:
+C    
+      
+C
+      INTEGER :: AGRIF_Parent_Nb_Step ! Result 
+C
+C
+      if (Agrif_Root()) then  
+C     
+          Agrif_Parent_Nb_Step = -1 
+C       
+        else
+C       
+          Agrif_Parent_Nb_Step = Agrif_Curgrid % parent % ngridstep
+C     
+      endif
+C
+C     
+      End function Agrif_Parent_Nb_Step    
+C 
+C
+C 
+C     **************************************************************************
+CCC   Function Agrif_Root
+C     **************************************************************************
+C
+      Function Agrif_Root()
+C     
+CCC   Description:
+CCC   Function indicating if the current grid is or not the root grid.
+C
+C     Declarations:
+C
+      
+C
+      LOGICAL :: Agrif_Root   ! Result
+C    
+C
+      if (AGRIF_CURGRID % fixedrank .EQ. 0) then
+C          
+          Agrif_Root = .TRUE.
+C    
+        else
+C    
+          Agrif_Root = .FALSE.
+C     
+      endif
+C
+C    
+      End function Agrif_Root
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Parent_Root
+C     **************************************************************************
+C
+      Function Agrif_Parent_Root()
+C     
+CCC   Description:
+CCC   Function indicating if the parent grid of the current grid is or not the 
+CCC   root grid.
+C
+C     Declarations:
+C
+      
+C
+      LOGICAL :: Agrif_Parent_Root   ! Result
+C    
+C
+      if (AGRIF_CURGRID % parent % fixedrank .EQ. 0) then
+C          
+          Agrif_Parent_Root = .TRUE.
+C    
+        else
+C    
+          Agrif_Parent_Root = .FALSE.
+C     
+      endif
+C
+C    
+      End function Agrif_Parent_Root     
+C 
+C
+C 
+C     **************************************************************************
+CCC   Function Agrif_Fixed
+C     **************************************************************************
+C 
+      Function Agrif_Fixed()
+C  
+CCC   Description:
+CCC   Function returning the number of the current grid.
+C
+C     Declarations:
+C   
+      
+C
+      INTEGER Agrif_Fixed   ! Result 
+C 
+C
+      if (Agrif_Curgrid % fixed) then
+C     
+          Agrif_Fixed = Agrif_Curgrid % fixedrank 
+C
+        else
+C     
+         Agrif_Fixed = -1
+C        
+      endif
+C
+C     
+      End function Agrif_Fixed 
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Parent_Fixed
+C     **************************************************************************
+ 
+      Function Agrif_Parent_Fixed()
+C  
+CCC   Description:
+CCC   Function returning the number of the parent grid of the current grid.
+C
+C     Declarations:
+C   
+      
+C
+      INTEGER Agrif_Parent_Fixed   ! Result 
+C 
+C
+      if (Agrif_Curgrid % parent % fixed) then
+C     
+          Agrif_Parent_Fixed = AGRIF_CURGRID % parent % fixedrank 
+C
+        else
+C     
+         Agrif_Parent_Fixed = 0
+C        
+      endif
+C
+C     
+      End function Agrif_Parent_Fixed
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Is_Fixed
+C     **************************************************************************
+ 
+      Function Agrif_Is_Fixed()
+C  
+CCC   Description:
+CCC   Function returning true if the current grid is fixed.
+C
+C     Declarations:
+C   
+      
+C
+      LOGICAL Agrif_Is_Fixed   ! Result 
+C 
+C
+      if (Agrif_Curgrid % fixed) then
+C     
+          Agrif_Is_Fixed = .true.
+C
+        else
+C     
+          Agrif_Is_Fixed = .false.
+C        
+      endif
+C
+C     
+      End function Agrif_Is_Fixed
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Parent_Is_Fixed
+C     **************************************************************************
+ 
+      Function Agrif_Parent_Is_Fixed()
+C  
+CCC   Description:
+CCC   Function returning true if the parent grid of the current grid is fixed.
+C
+C     Declarations:
+C   
+      
+C
+      LOGICAL Agrif_Parent_Is_Fixed   ! Result 
+C 
+C
+      if (Agrif_Curgrid % parent % fixed) then
+C     
+          Agrif_Parent_Is_Fixed = .true.
+C
+        else
+C     
+          Agrif_Parent_Is_Fixed = .false.
+C        
+      endif
+C
+C     
+      End function Agrif_Parent_Is_Fixed            
+C
+C 
+C
+C     **************************************************************************
+CCC   Function AGRIF_CFixed
+C     **************************************************************************
+ 
+            Function AGRIF_CFixed()
+C  
+CCC   Description:
+CCC   Function returning the number of the current grid.
+C
+C     Declarations:
+C   
+      
+C
+      CHARACTER(3) AGRIF_CFixed   ! Result 
+C
+C     Local variables      
+      CHARACTER(3) cfixed
+      INTEGER fixed
+C 
+C
+      fixed = Agrif_Fixed()
+C      
+      if(fixed.NE.-1) then
+C
+           if (fixed .LE. 9) then
+C
+               write(cfixed,'(i1)')fixed
+C 
+           else
+C   
+               write(cfixed,'(i2)')fixed
+C      
+           endif
+C
+           AGrif_Cfixed=cfixed
+C      
+      else
+C
+      print*,'Call to AGRIF_CFixed() on a moving grid'
+      stop
+C
+      endif     
+
+      End function AGRIF_CFixed
+C
+C
+C
+C     **************************************************************************
+CCC   Function AGRIF_Parent_CFixed
+C     **************************************************************************
+ 
+      Function AGRIF_Parent_CFixed()
+C  
+CCC   Description:
+CCC   Function returning the number of the parent grid of the current grid.
+C
+C     Declarations:
+C   
+      
+C
+      CHARACTER(3) AGRIF_Parent_CFixed   ! Result 
+C
+C     Local variables      
+      CHARACTER(3) cfixed
+      INTEGER fixed
+C 
+C
+      fixed = Agrif_Parent_Fixed()
+C      
+      if(fixed.NE.-1) then
+C
+          if (fixed .LE. 9) then
+C
+              write(cfixed,'(i1)')fixed
+C      
+          else
+C        
+              write(cfixed,'(i2)')fixed
+C      
+          endif
+C
+          AGrif_Parent_Cfixed=cfixed
+C
+      else
+C
+      print*,'Illegal call to AGRIF_Parent_CFixed()'
+      stop     
+C
+      endif
+
+      End function AGRIF_Parent_CFixed      
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_ChildGrid_to_ParentGrid
+C     **************************************************************************
+C
+      Subroutine Agrif_ChildGrid_to_ParentGrid()
+C  
+CCC   Description:
+CCC   Subroutine allowing to make the pointer AGRIF_CURGRID point on the parent
+CCC   grid of the current grid.
+C
+C     Declarations:
+C  
+      
+C
+C
+      AGRIF_saveCURGRID => AGRIF_CURGRID
+C
+      Call AGRIF_INSTANCE(AGRIF_CURGRID%parent)            
+C
+C
+      End Subroutine Agrif_ChildGrid_to_ParentGrid
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_ParentGrid_to_ChildGrid
+C     **************************************************************************
+C
+      Subroutine Agrif_ParentGrid_to_ChildGrid()
+C  
+CCC   Description:
+CCC   Subroutine allowing to make the pointer AGRIF_CURGRID point on the child 
+CCC   grid after having called the Agrif_ChildGrid_to_ParentGrid subroutine.
+C
+C     Declarations:
+C  
+      
+C
+C
+      Call AGRIF_INSTANCE(AGRIF_saveCURGRID)            
+C
+C
+      End Subroutine Agrif_ParentGrid_to_ChildGrid
+C
+C
+C
+C     **************************************************************************
+CCC   Function Agrif_Get_Unit
+C     **************************************************************************
+C
+      Function Agrif_Get_Unit()
+
+CCC   Description : return a unit not connected to any file
+C
+C     Declarations
+C
+      
+C
+      INTEGER Agrif_Get_Unit
+C
+C     Local scalars
+      INTEGER n
+      LOGICAL op
+C
+      INTEGER :: nunit
+      INTEGER :: iii,out,iiimax
+      Logical :: BEXIST
+      INTEGER,DIMENSION(1:10) :: ForbiddenUnit
+C
+C
+C     Load forbidden Unit if the file Agrif_forbidenUnit exist
+C      
+
+      INQUIRE(FILE='Agrif_forbiddenUnit.txt',EXIST=BEXIST)
+      If (.not. BEXIST) Then
+c          File Agrif_forbiddenUnit.txt not found
+      Else
+           nunit = 777
+           open(nunit,file='Agrif_forbiddenUnit.txt',form='formatted',
+     &          status="old")
+              iii = 1
+              do while ( .TRUE. )
+                 read(nunit,*,END = 99) ForbiddenUnit(iii)
+                 iii = iii + 1
+              enddo
+   99         CONTINUE
+              iiimax = iii
+           close(nunit)
+      endif     
+C 
+      do n = 7,1000
+C 
+        Inquire(Unit=n,Opened=op)
+C
+        out = 0
+        if ( BEXIST .AND. .NOT.op) then
+           do iii = 1 , iiimax
+              if ( n .EQ. ForbiddenUnit(iii) ) out = 1
+           enddo
+        endif
+C
+        if (.NOT.op .AND. out .EQ. 0) exit
+C      
+      enddo
+C
+      Agrif_Get_Unit=n
+C
+C
+      End Function Agrif_Get_Unit
+      
+      Subroutine Agrif_Set_Efficiency(eff)
+      REAL :: eff
+      
+      IF ((eff.LT.0.).OR.(eff.GT.1)) THEN
+      write(*,*)'Error Efficiency should be between 0 and 1'
+      stop
+      ELSE
+      Agrif_efficiency = eff
+      ENDIF
+      End Subroutine Agrif_Set_Efficiency
+      
+      Subroutine Agrif_Set_Regridding(regfreq)
+      INTEGER :: regfreq
+      
+      IF (regfreq.LT.0) THEN
+      write(*,*)'Regridding frequency should be positive'
+      stop
+      ELSE
+      Agrif_regridding = regfreq
+      ENDIF
+      End Subroutine Agrif_Set_Regridding
+C
+      End Module Agrif_CurgridFunctions 
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modflux.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modflux.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modflux.F	(revision 4536)
@@ -0,0 +1,339 @@
+C     Agrif (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place-Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_fluxmod
+C
+      Module Agrif_fluxmod
+      Use Agrif_types
+      Use Agrif_Arrays
+      Use Agrif_Curgridfunctions
+      
+      CONTAINS  
+      
+      
+      Subroutine Agrif_AllocateFlux(Flux,fluxtab)
+      Type(Agrif_Flux), Pointer :: Flux
+      Real, Dimension(:,:) :: fluxtab
+      Type(Agrif_Profile), Pointer :: Profile
+      Integer :: dimensio,n,n2
+      INTEGER, DIMENSION(:,:), Pointer :: normalsizes
+      INTEGER, DIMENSION(6) :: unitarray
+      Type(Agrif_Variable), Pointer :: fluxtabvar
+      Integer :: nbout
+      
+      Profile => Flux%profile
+      dimensio = Profile%nbdim
+      
+      unitarray = 1
+      
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            Allocate(Flux%fluxtabx)
+            fluxtabvar => Flux%fluxtabx
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            Allocate(Flux%fluxtaby)
+            fluxtabvar => Flux%fluxtaby
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            Allocate(Flux%fluxtabz)
+            fluxtabvar => Flux%fluxtabz
+          ENDIF
+          ALLOCATE(fluxtabvar%iarray2(2,6))
+          normalsizes=>fluxtabvar%iarray2
+          normalsizes(1,1) = 2
+          nbout = 1
+          DO n2 = 1,dimensio
+            IF (n2 .NE. n) THEN
+              nbout = nbout + 1
+              If ((Profile%posvar(n2) == 1)
+     &            .OR.(Profile%posvar(n2) == 2)) THEN
+                IF (Profile%interptab(n2) == 'x') THEN
+                  normalsizes(2,n2) = 
+     &                Agrif_Curgrid%nb(1)/agrif_Curgrid%spaceref(1)
+                  normalsizes(1,nbout) = 
+     &                Agrif_Curgrid%nb(1)/agrif_Curgrid%spaceref(1)
+                ELSE IF (Profile%interptab(n2) == 'y') THEN
+                  normalsizes(2,n2) = 
+     &                Agrif_Curgrid%nb(2)/agrif_Curgrid%spaceref(2)
+                  normalsizes(1,nbout) = 
+     &                Agrif_Curgrid%nb(2)/agrif_Curgrid%spaceref(2)
+                ELSE IF (Profile%interptab(n2) == 'z') THEN
+                  normalsizes(2,n2) = 
+     &                Agrif_Curgrid%nb(3)/agrif_Curgrid%spaceref(3)
+                  normalsizes(1,nbout) = 
+     &                Agrif_Curgrid%nb(3)/agrif_Curgrid%spaceref(3)
+                ENDIF
+              ELSE
+                normalsizes(2,n2) = SIZE(fluxtab,n2)
+                normalsizes(1,nbout) = SIZE(fluxtab,n2)
+              ENDIF
+            ENDIF
+          ENDDO          
+        ENDIF
+      enddo
+      
+      
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            fluxtabvar => Flux%fluxtabx
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            fluxtabvar => Flux%fluxtaby
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            fluxtabvar => Flux%fluxtabz
+          ENDIF
+          Call Agrif_nbdim_allocation(fluxtabvar,unitarray(1:dimensio),
+     &          fluxtabvar%iarray2(1,1:dimensio),dimensio)
+        ENDIF
+      enddo
+      
+      Flux%fluxallocated = .TRUE.
+      
+      End Subroutine Agrif_AllocateFlux
+      
+      FUNCTION Agrif_Search_Flux(fluxname)
+      character*(*) fluxname
+      Type(Agrif_Flux), Pointer :: Agrif_Search_Flux
+      
+      Type(Agrif_Flux), pointer :: parcours
+      Logical :: foundflux
+      
+      foundflux = .FALSE.
+      parcours => Agrif_Curgrid%fluxes
+      
+      Do While (Associated(parcours))
+         IF (parcours % fluxname == fluxname) THEN
+           foundflux = .TRUE.
+           EXIT
+         ENDIF
+         parcours => parcours%nextflux
+      End Do
+      
+      IF (.NOT.foundflux) THEN
+      write(*,*) 'The array flux '''
+     &           //TRIM(fluxname)//''' has not been declared'
+      stop
+      ENDIF      
+      
+      Agrif_Search_Flux => parcours
+      
+      End Function Agrif_Search_Flux
+      
+      Subroutine Agrif_Save_Fluxtab(Flux,Fluxtab)
+      Type(Agrif_Flux), Pointer :: Flux
+      Real, Dimension(:,:) :: Fluxtab
+      INTEGER, DIMENSION(:,:), Pointer :: normalsizes
+      INTEGER, DIMENSION(6) :: normalsizes2, normalsizes3
+      INTEGER, DIMENSION(6) :: unitarray2, unitarray3
+      Type(Agrif_Variable), Pointer :: fluxtabvar
+      Type(Agrif_Profile), Pointer :: Profile
+      Integer :: dimensio,n,n2,j,j1,j2
+      
+      Profile => Flux%profile
+      dimensio = Profile%nbdim
+            
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            fluxtabvar => Flux%fluxtabx
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            fluxtabvar => Flux%fluxtaby
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            fluxtabvar => Flux%fluxtabz
+          ENDIF 
+          normalsizes => fluxtabvar%iarray2
+          unitarray2 = 1
+          unitarray3 = 1
+          normalsizes2 = normalsizes(1,:)
+          normalsizes3 = normalsizes(2,:)
+          
+          unitarray3(n) = Profile%point(n)
+          normalsizes3(n) = Profile%point(n) 
+                              
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+            j1 = unitarray3(2)
+            Do j=unitarray3(2),normalsizes3(2)
+            do j2 = j1,j1+Agrif_curgrid%spaceref(2)
+!            print *,'flux stocke fiun = ',j2,fluxtab(unitarray3(1),j2)
+            enddo
+            fluxtabvar%array2(1:1,j) = 
+     &      fluxtabvar%array2(1:1,j) +
+     &             SUM(fluxtab(unitarray3(1):normalsizes3(1),
+     &                        j1:j1+Agrif_Curgrid%spaceref(2)))
+             j1 = j1+Agrif_Curgrid%spaceref(2)
+            EndDo
+          END SELECT
+          
+          unitarray3(n) = Profile%point(n)+Agrif_Curgrid%nb(n)
+          normalsizes3(n) = Profile%point(n)+Agrif_Curgrid%nb(n) 
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+            j1 = unitarray3(2)
+            Do j=unitarray3(2),normalsizes3(2)
+            fluxtabvar%array2(2:2,j) = 
+     &      fluxtabvar%array2(2:2,j) +
+     &             SUM(fluxtab(unitarray3(1):normalsizes3(1),
+     &                        j1:j1+Agrif_Curgrid%spaceref(2)))
+             j1 = j1+Agrif_Curgrid%spaceref(2)
+            EndDo
+         END SELECT
+        ENDIF
+      enddo
+                  
+      End Subroutine Agrif_Save_Fluxtab
+
+      Subroutine Agrif_Save_Fluxtab_child(Flux,Fluxtab)
+      Type(Agrif_Flux), Pointer :: Flux
+      Real, Dimension(:,:) :: Fluxtab
+      INTEGER, DIMENSION(:,:), Pointer :: normalsizes
+      INTEGER, DIMENSION(6) :: normalsizes2, normalsizes3
+      INTEGER, DIMENSION(6) :: unitarray2, unitarray3
+      Type(Agrif_Variable), Pointer :: fluxtabvar
+      Type(Agrif_Profile), Pointer :: Profile
+      Integer :: dimensio,n,n2
+      
+      Profile => Flux%profile
+      dimensio = Profile%nbdim
+            
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            fluxtabvar => Flux%fluxtabx
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            fluxtabvar => Flux%fluxtaby
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            fluxtabvar => Flux%fluxtabz
+          ENDIF 
+          normalsizes => fluxtabvar%iarray2
+          unitarray2 = 1
+          unitarray3 = 1
+          normalsizes2 = normalsizes(1,:)
+          normalsizes3 = normalsizes(2,:)
+          
+          unitarray3(n) = Profile%point(n)+Agrif_Curgrid%ix(n)
+          normalsizes3(n) = unitarray3(n)
+                              
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+            fluxtabvar%array2(1:1,
+     &                        unitarray2(2):normalsizes2(2)) = 
+     &      - fluxtab(unitarray3(1):normalsizes3(1),
+     &                        unitarray3(2):normalsizes3(2))
+!        print *,'flux stocke = ',fluxtab(unitarray3(1):normalsizes3(1),
+!     &                        unitarray3(2):normalsizes3(2))
+          END SELECT
+          
+          unitarray3(n) = unitarray3(n)+
+     &         Agrif_Curgrid%nb(n)/Agrif_Curgrid%spaceref(n)
+          normalsizes3(n) = unitarray3(n)
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+            fluxtabvar%array2(2:2,
+     &                        unitarray2(2):normalsizes2(2)) = 
+     &      - fluxtab(unitarray3(1):normalsizes3(1),
+     &                        unitarray3(2):normalsizes3(2))    
+         END SELECT
+        ENDIF
+      enddo
+                  
+      End Subroutine Agrif_Save_Fluxtab_child
+      
+      Subroutine Agrif_Cancel_Fluxarray(Flux)
+      Type(Agrif_Flux), Pointer :: Flux
+      Type(Agrif_Variable), Pointer :: fluxtabvar
+      Type(Agrif_Profile), Pointer :: Profile
+      Integer :: dimensio,n,n2
+      
+      Profile => Flux%profile
+      dimensio = Profile%nbdim
+            
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            fluxtabvar => Flux%fluxtabx
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            fluxtabvar => Flux%fluxtaby
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            fluxtabvar => Flux%fluxtabz
+          ENDIF 
+                              
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+            fluxtabvar%array2 = 0.
+          END SELECT
+        ENDIF
+      enddo
+                  
+      End Subroutine Agrif_Cancel_Fluxarray  
+      
+      Subroutine Agrif_FluxCorrect(Flux, procname)
+      Type(Agrif_Flux), Pointer :: Flux
+      External :: procname
+      Type(Agrif_Variable), Pointer :: fluxtabvar
+      Type(Agrif_Profile), Pointer :: Profile
+      Integer :: dimensio,n,n2,j1,j2
+      Integer, Dimension(:), Allocatable :: Loctab
+      Integer :: locind
+      
+      Profile => Flux%profile
+      dimensio = Profile%nbdim
+
+      do n=1,dimensio
+        IF (Profile%posvar(n) == 1) THEN
+          IF (Profile%interptab(n) == 'x') THEN
+            fluxtabvar => Flux%fluxtabx
+            locind = 1
+          ELSE IF (Profile%interptab(n) == 'y') THEN
+            fluxtabvar => Flux%fluxtaby
+            locind = 2
+          ELSE IF (Profile%interptab(n) == 'z') THEN
+            fluxtabvar => Flux%fluxtabz
+            locind = 3
+          ENDIF 
+                              
+          SELECT CASE(dimensio)
+          CASE(1)
+          CASE(2)
+           Allocate(Loctab(2))
+           Loctab(1) = Agrif_Curgrid%ix(locind)
+           Loctab(2) = Agrif_Curgrid%ix(locind)+
+     &         Agrif_Curgrid%nb(locind)/Agrif_Curgrid%spaceref(locind)
+           j1 = agrif_curgrid%ix(2)
+           j2 = agrif_curgrid%ix(2)+
+     &        agrif_curgrid%nb(2)/Agrif_curgrid%spaceref(2)
+           Call Agrif_ChildGrid_to_ParentGrid()
+            Call procname(fluxtabvar%array2,Loctab(1),Loctab(2),j1,j2)
+           Call Agrif_ParentGrid_to_ChildGrid()
+          END SELECT
+        ENDIF
+      enddo
+      
+      If (Allocated(Loctab)) Deallocate(Loctab)
+                  
+      End Subroutine Agrif_FluxCorrect 
+          
+      End Module Agrif_fluxmod
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinit.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinit.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinit.F	(revision 4536)
@@ -0,0 +1,227 @@
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Init
+C
+      Module Agrif_Init 
+C
+CCC   Description:
+CCC   Several operations on the variables of the current grid (creation,
+CCC   instanciation, ...) used during the creation of the grid hierarchy and
+CCC   during the time integration.
+C
+C     Modules used: 
+C
+      Use Agrif_Types 
+      Use Agrif_link
+C   
+      IMPLICIT NONE
+C
+      Contains
+C     Defininition of the procedures contained in this module
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Allocation  
+C     **************************************************************************
+C  
+      Subroutine Agrif_Allocation(Agrif_Gr)
+C
+CCC   Description:
+CCC   Subroutine to allocate the arrays containing the values of the variables 
+CCC   of the current grd.
+C
+CC    Method:
+CC    Use of the allocate function.  
+C
+C     Declarations:
+C      
+C     Pointer argument:
+      TYPE(AGRIF_grid), Pointer :: Agrif_Gr  ! Pointer on the current grid
+C 
+C     Allocation of the arrays of the variables  
+C     We cut this in several files to avoid long compilation timings
+C
+      Call Agrif_Allocationcalls(Agrif_Gr)
+C
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+C
+         if ( Agrif_Probdim .EQ. 1 ) 
+     &      Allocate(Agrif_Gr%tabpoint1D(Agrif_Gr%nb(1)+1))
+         if ( Agrif_Probdim .EQ. 2 ) 
+     &      Allocate(Agrif_Gr%tabpoint2D(Agrif_Gr%nb(1)+1,
+     &       Agrif_Gr%nb(2)+1))      
+         if ( Agrif_Probdim .EQ. 3 ) 
+     &      Allocate(Agrif_Gr%tabpoint3D(Agrif_Gr%nb(1)+1,
+     &       Agrif_Gr%nb(2)+1,Agrif_Gr%nb(3)+1))      
+C
+      endif
+C 
+      End Subroutine Agrif_Allocation
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Instance 
+C     **************************************************************************
+C 
+      Subroutine Agrif_Instance(Agrif_Gr)
+C
+CCC   Description:
+CCC   Subroutine to do an instance of the common variables to the variables of  
+CCC   the current grid.
+C
+CC    Method:
+CC    Pointing the common variables on these of the current grid.  
+C
+C     Declarations:
+C        
+
+C
+C
+
+C
+C     Pointer argument: 
+      Type(Agrif_Grid), Pointer :: Agrif_Gr   ! Pointer on the current grid  
+C 
+C
+      Agrif_Curgrid => Agrif_Gr
+      Agrif_tabvars => Agrif_Curgrid % tabvars
+C
+      Call Agrif_Get_numberofcells(Agrif_Gr)
+C
+C
+C     Calculation of isf,jsf,nzsf and of the index of the output file 
+      Call Agrif_InitWorkSpace() 
+C
+C 
+      End Subroutine Agrif_Instance
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_initialisations  
+C     **************************************************************************
+      Subroutine Agrif_initialisations(Agrif_Gr)
+C
+CCC   Description:
+C
+CC    Method:
+C
+C     Declarations:
+C        
+      INTEGER :: i
+C
+C     Pointer argument: 
+      Type(Agrif_Grid), Pointer  :: Agrif_Gr
+C
+      do i = 1 , Agrif_NbVariables
+C 
+         Agrif_Gr % tabvars(i) % var % nbdim = 0
+C
+         if (associated(Agrif_Gr%tabvars(i)%var%array1)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 1
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%array2)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 2
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%array3)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 3
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%array4)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 4
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%array5)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 5
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%array6)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 6
+         endif
+C
+         if (associated(Agrif_Gr%tabvars(i)%var%darray1)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 1
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%darray2)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 2
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%darray3)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 3
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%darray4)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 4
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%darray5)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 5
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%darray6)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 6
+         endif
+C
+         if (associated(Agrif_Gr%tabvars(i)%var%larray1)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 1
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%larray2)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 2
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%larray3)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 3
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%larray4)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 4
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%larray5)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 5
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%larray6)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 6
+         endif
+C
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray1)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 1
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray2)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 2
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray3)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 3
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray4)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 4
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray5)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 5
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%iarray6)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 6
+         endif
+C
+         if (associated(Agrif_Gr%tabvars(i)%var%carray1)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 1
+         endif
+         if (associated(Agrif_Gr%tabvars(i)%var%carray2)) then
+             Agrif_Gr % tabvars(i) % var % nbdim = 2
+         endif
+C 
+      enddo
+C
+      Return
+C 
+C
+      End Subroutine Agrif_initialisations
+C 
+C
+      End Module AGRIF_Init 
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinitvars.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinitvars.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinitvars.F	(revision 4536)
@@ -0,0 +1,125 @@
+!
+! $Id$
+!
+C     Agrif (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Init_Vars
+C
+      Module Agrif_Init_Vars
+C
+CCC   Description:
+CCC   Initialization of the variables of the current grid.
+C
+C     Modules used: 
+C      
+      Use Agrif_Types
+      Use Agrif_link
+C   
+      IMPLICIT NONE
+C
+      Contains
+C     Defininition of the procedures contained in this module 
+C  
+C 
+C     **************************************************************************
+CCC   Subroutine Agrif_Create_var 
+C     **************************************************************************
+C  
+      Subroutine Agrif_Create_Var(Agrif_Gr)
+C
+CCC   Description:
+CCC   Allocation of the field "var" of the grid variables.
+CCC   Fields "root_var", "nbdim" and "parent_var" of the grid variables.
+CCC   Array "tabvars" of the current grid. 
+C
+CC    Method:                  
+C 
+C     Declarations:
+C
+      
+C
+C     Pointer argument:
+      TYPE(Agrif_Grid),pointer   :: Agrif_Gr  ! Pointer on the current grid
+      INTEGER :: nb
+C
+C     Array "tabvars" of the current grid. 
+C
+      Allocate(Agrif_Gr % tabvars(Agrif_NbVariables))
+C      
+      do nb = 1, Agrif_NbVariables
+        Allocate(Agrif_Gr % tabvars(nb) % var)
+      enddo
+
+C     Fields "root_var", "nbdim" and "parent_var" of the grid variables.     
+      if (Agrif_Gr % fixedrank .NE.0) then
+         do nb = 1, Agrif_NbVariables     
+            Agrif_Gr % tabvars(nb) % parent_var => 
+     &      Agrif_Gr % parent %tabvars(nb)
+            Agrif_Gr % tabvars(nb) % var % nbdim =
+     &      Agrif_Mygrid % tabvars(nb) % var % nbdim
+            Agrif_Gr % tabvars(nb) % var % root_var =>
+     &      Agrif_Mygrid % tabvars(nb) % var          
+         enddo
+      endif
+C           
+      End Subroutine Agrif_Create_Var
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_CreateVar
+C     **************************************************************************
+C 
+      Subroutine Agrif_CreateVar(Agrif_Gr)            
+C
+CCC   Description:
+CCC   This subroutine allows to make a link between Mygrid and the current grid 
+C
+C     Modules used:
+C      
+C
+C     Declarations:
+C      
+C
+C
+C     Arguments      
+C
+      TYPE(Agrif_Grid),pointer   :: Agrif_Gr    ! Pointer on the current grid
+      INTEGER                    :: i           ! Loop
+C
+      if (Agrif_Gr % fixedrank .NE. 0) then
+C  
+         do i = 1 , Agrif_NbVariables 
+            Agrif_Gr % tabvars(i) % parent_var => 
+     &      Agrif_Gr % parent % tabvars(i) 
+            Agrif_Gr % tabvars(i) % var % root_var => 
+     &      Agrif_Mygrid % tabvars(i) % var
+            Agrif_Gr % tabvars(i) % var % nbdim  = 
+     &      Agrif_Gr % parent % tabvars(i) % var % nbdim
+         enddo 
+C	 
+      endif 
+C       
+      End Subroutine Agrif_CreateVar
+C
+C
+C
+      End Module Agrif_Init_Vars
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterp.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterp.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterp.F	(revision 4536)
@@ -0,0 +1,2060 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Interpolation
+C
+      Module Agrif_Interpolation
+C
+CCC   Description:
+CCC   Module to initialize a fine grid from its parent grid, by using a space 
+CCC   interpolation
+C
+C     Modules used:
+C  
+      Use Agrif_Interpbasic
+      Use Agrif_Arrays
+      Use Agrif_Mask 
+      Use Agrif_CurgridFunctions
+#if defined AGRIF_MPI
+      Use Agrif_mpp
+#endif
+C      
+      IMPLICIT NONE
+C
+      CONTAINS
+C     Define procedures contained in this module        
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_1d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_1d(TypeInterp,parent,child,tab,
+     &    torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 1D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &         lbound(child%var%array1,1):ubound(child%var%array1,1)
+     &         ), Target :: tab    ! Result
+C
+C
+      allocate(childtemp % var)  
+C      
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim
+C
+C     Tab is the result of the interpolation
+      childtemp % var % array1 => tab 
+C      
+      if (torestore) then
+C 
+          childtemp % var % array1 = child % var % array1
+C          
+          childtemp % var % restore1D => child % var % restore1D
+C      
+        else
+C        
+          Nullify(childtemp % var % restore1D)
+C      
+      endif     
+C 
+C     Index indicating (in the Agrif_Interp1D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade 
+      childtemp % var % list_interp => child % var% list_interp            
+C      
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+      child % var % list_interp => childtemp % var %list_interp     
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_1D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_2d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_2d(TypeInterp,parent,child,tab,
+     &                           torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 2D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &    lbound(child%var%array2,1):ubound(child%var%array2,1),
+     &    lbound(child%var%array2,2):ubound(child%var%array2,2)
+     &    ), Target :: tab    ! Result
+C
+C
+      allocate(childtemp % var)  
+C      
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim
+C
+C     Tab is the result of the interpolation
+      childtemp % var % array2 => tab  
+C      
+      if (torestore) then      
+C 
+          childtemp % var % array2 = child % var % array2
+C 
+          childtemp % var % restore2D => child % var % restore2D        
+C      
+        else
+C        
+          Nullify(childtemp % var % restore2D)
+C      
+      endif       
+C 
+C     Index indicating (in the Agrif_Interp2D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex       
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade   
+      childtemp % var % list_interp => child % var% list_interp          
+C     
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+      child % var % list_interp => childtemp % var %list_interp     
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_2D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_3d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_3d(TypeInterp,parent,child,tab,
+     &   torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 3D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &      lbound(child%var%array3,1):ubound(child%var%array3,1),
+     &      lbound(child%var%array3,2):ubound(child%var%array3,2),
+     &      lbound(child%var%array3,3):ubound(child%var%array3,3)
+     &      ), Target :: tab  ! Results
+C
+C
+      allocate(childtemp % var)  
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim  
+C     
+C     Tab is the result of the interpolation 
+      childtemp % var % array3 => tab 
+C      
+      if (torestore) then
+C     
+          childtemp % var % array3 = child % var % array3
+C
+          childtemp % var % restore3D => child % var % restore3D
+C      
+        else
+C        
+          Nullify(childtemp % var % restore3D)
+C      
+      endif
+C 
+C     Index indicating (in the Agrif_Interp3D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex    
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade   
+      childtemp % var % list_interp => child % var% list_interp          
+C     
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+      child % var % list_interp => childtemp % var %list_interp     
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_3D               
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_4d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_4d(TypeInterp,parent,child,tab,
+     &   torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 4D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &      lbound(child%var%array4,1):ubound(child%var%array4,1),
+     &      lbound(child%var%array4,2):ubound(child%var%array4,2),
+     &      lbound(child%var%array4,3):ubound(child%var%array4,3),
+     &      lbound(child%var%array4,4):ubound(child%var%array4,4)
+     &      ), Target :: tab  ! Results
+C
+C
+      allocate(childtemp % var)  
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim  
+C      
+C     Tab is the result of the interpolation
+      childtemp % var % array4 => tab 
+C 
+      if (torestore) then
+C 
+          childtemp % var % array4 = child % var % array4
+C
+          childtemp % var % restore4D => child % var % restore4D
+C      
+        else
+C        
+          Nullify(childtemp % var % restore4D)
+C      
+      endif        
+C 
+C     Index indicating (in the Agrif_Interp4D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex    
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade  
+      childtemp % var % list_interp => child % var% list_interp           
+C     
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+      child % var % list_interp => childtemp % var %list_interp
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_4D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_5d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_5d(TypeInterp,parent,child,tab,
+     &   torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 5D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &      lbound(child%var%array5,1):ubound(child%var%array5,1),
+     &      lbound(child%var%array5,2):ubound(child%var%array5,2),
+     &      lbound(child%var%array5,3):ubound(child%var%array5,3),
+     &      lbound(child%var%array5,4):ubound(child%var%array5,4),
+     &      lbound(child%var%array5,5):ubound(child%var%array5,5)
+     &      ),  Target :: tab  ! Results
+C
+C
+      allocate(childtemp % var)  
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim  
+C      
+C     Tab is the result of the interpolation
+      childtemp % var % array5 => tab  
+C      
+      if (torestore) then
+C 
+          childtemp % var % array5 = child % var % array5
+C
+          childtemp % var % restore5D => child % var % restore5D
+C      
+        else
+C        
+          Nullify(childtemp % var % restore5D)
+C      
+      endif       
+C 
+C     Index indicating (in the Agrif_Interp5D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex    
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade   
+      childtemp % var % list_interp => child % var% list_interp          
+C      
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+     
+      child % var % list_interp => childtemp % var %list_interp
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_5D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_6d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Interp_6d(TypeInterp,parent,child,tab,
+     &  torestore,nbdim)            
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions of a fine grid for a 6D
+C        grid variable.
+C
+C     Declarations:
+C      
+      
+C
+C     Arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp     ! Kind of interpolation
+                                             !    (linear,lagrange,spline)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+                                             !    grid
+      LOGICAL :: torestore
+      REAL, DIMENSION(
+     &      lbound(child%var%array6,1):ubound(child%var%array6,1),
+     &      lbound(child%var%array6,2):ubound(child%var%array6,2),
+     &      lbound(child%var%array6,3):ubound(child%var%array6,3),
+     &      lbound(child%var%array6,4):ubound(child%var%array6,4),
+     &      lbound(child%var%array6,5):ubound(child%var%array6,5),
+     &      lbound(child%var%array6,6):ubound(child%var%array6,6)
+     &      ),  Target :: tab  ! Results
+C
+C
+      allocate(childtemp % var)  
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = nbdim  
+C      
+C     Tab is the result of the interpolation
+      childtemp % var % array6 => tab  
+C      
+      if (torestore) then
+C 
+          childtemp % var % array6 = child % var % array6
+C
+          childtemp % var % restore6D => child % var % restore6D
+C      
+        else
+C        
+          Nullify(childtemp % var % restore6D)
+C      
+      endif       
+C 
+C     Index indicating (in the Agrif_Interp6D procedure) if a space
+C        interpolation is necessary
+      childtemp % var % interpIndex => child % var % interpIndex    
+      childtemp % var % Interpolationshouldbemade = 
+     &    child % var % Interpolationshouldbemade  
+     
+      childtemp % var % list_interp => child % var% list_interp           
+C      
+      Call Agrif_InterpVariable
+     &     (TypeInterp,parent,childtemp,torestore)
+C      
+      child % var % list_interp => childtemp % var %list_interp
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Interp_6D
+C
+C
+C
+C     **************************************************************************
+C     Subroutine Agrif_InterpVariable    
+C     **************************************************************************
+C   
+      Subroutine Agrif_InterpVariable(TYPEinterp,parent,child,torestore)
+C
+CCC   Description:
+CCC   Subroutine to set some arguments of subroutine Agrif_InterpnD, n being the
+CCC   DIMENSION of the grid variable.
+C
+CC    Declarations:
+C      
+c      
+C      
+C
+C     Scalar argument
+      INTEGER,DIMENSION(6) :: TYPEinterp! TYPE of interpolation
+                                        !    (linear,spline,...)
+C     Data TYPE arguments                                   
+      TYPE(AGRIF_PVariable) :: parent   ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child    ! Variable on the child grid
+C
+C     LOGICAL argument      
+      LOGICAL:: torestore               ! Its value is .false., it indicates the
+                                        ! results of the interpolation are    
+                                        ! applied on the whole current grid   
+C
+C     Local scalars      
+      INTEGER               :: nbdim          ! Number of dimensions of the
+                                              !    current grid
+      INTEGER ,DIMENSION(6) :: pttab_child  
+      INTEGER ,DIMENSION(6) :: petab_child      
+      INTEGER ,DIMENSION(6) :: pttab_parent  
+      REAL    ,DIMENSION(6) :: s_child,s_parent
+      REAL    ,DIMENSION(6) :: ds_child,ds_parent
+C
+      Call PreProcessToInterpOrUpdate(parent,child,
+     &             petab_Child(1:nbdim),
+     &             pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &             s_Child(1:nbdim),s_Parent(1:nbdim),
+     &             ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &             nbdim)
+C
+C
+C     Call to a procedure of interpolation against the number of dimensions of 
+C     the grid variable
+C
+      call Agrif_InterpnD
+     &            (TYPEinterp,parent,child,
+     &             pttab_Child(1:nbdim),petab_Child(1:nbdim),
+     &             pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &             s_Child(1:nbdim),s_Parent(1:nbdim),
+     &             ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &             child,torestore,nbdim)
+C
+      Return
+C
+C
+      End subroutine Agrif_InterpVariable       
+C
+C
+C     **************************************************************************
+C     Subroutine Agrif_InterpnD  
+C     **************************************************************************
+C  
+      Subroutine Agrif_InterpnD(TYPEinterp,parent,child,
+     &                          pttab,petab,
+     &                          pttab_Child,pttab_Parent,
+     &                          s_Child,s_Parent,ds_Child,ds_Parent,
+     &                          restore,torestore,nbdim,procname)
+C
+C     Description:
+C     Subroutine to interpolate a nD grid variable from its parent grid,
+C     by using a space interpolation. 
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+C
+#include "mpif.h"
+C
+#endif
+C
+C     Arguments
+      External :: procname
+      Optional :: procname
+      INTEGER                    :: nbdim
+      INTEGER,DIMENSION(6)       :: TYPEinterp         ! TYPE of interpolation
+                                                       !    (linear,...)
+      TYPE(AGRIF_PVARIABLE)      :: parent             ! Variable of the parent
+                                                       !    grid
+      TYPE(AGRIF_PVARIABLE)      :: child              ! Variable of the child
+                                                       !    grid
+      INTEGER,DIMENSION(nbdim)   :: pttab              ! Index of the first
+                                                       !    point inside the
+                                                       !    domain
+      INTEGER,DIMENSION(nbdim)   :: petab              ! Index of the first
+                                                       !    point inside the
+                                                       !    domain
+      INTEGER,DIMENSION(nbdim)   :: pttab_Child        ! Index of the first
+                                                       !    point inside the
+                                                       !    domain for the child
+                                                       !    grid variable
+      INTEGER,DIMENSION(nbdim)   :: pttab_Parent       ! Index of the first
+                                                       !    point inside the
+                                                       !    domain for the
+                                                       !    parent grid variable
+      TYPE(AGRIF_PVARIABLE)      :: restore            ! Indicates points where
+                                                       !    interpolation
+      REAL,DIMENSION(nbdim)      :: s_Child,s_Parent   ! Positions of the parent
+                                                       !    and child grids
+      REAL,DIMENSION(nbdim)      :: ds_Child,ds_Parent ! Space steps of the
+                                                       !    parent and child
+                                                       !    grids
+      LOGICAL                        :: torestore      ! Indicates if the array
+                                                       !    restore is used
+C
+C     Local pointers
+      TYPE(AGRIF_PVARIABLE),SAVE      :: tempP,tempPextend  ! Temporary parent grid variable
+      TYPE(AGRIF_PVARIABLE),SAVE      :: tempC      ! Temporary child grid variable
+C
+C     Local scalars        
+      INTEGER                     :: i,j,k,l,m,n
+      INTEGER,DIMENSION(nbdim)    :: pttruetab,cetruetab
+      INTEGER,DIMENSION(nbdim)    :: indmin,indmax
+      LOGICAL,DIMENSION(nbdim)    :: noraftab
+      REAL   ,DIMENSION(nbdim)    :: s_Child_temp,s_Parent_temp
+      INTEGER,DIMENSION(nbdim)    :: lowerbound,upperbound
+      INTEGER,DIMENSION(nbdim)    :: indminglob,indmaxglob
+      INTEGER,DIMENSION(nbdim,2,2) :: childarray
+      INTEGER,DIMENSION(nbdim,2,2) :: parentarray
+      LOGICAL :: memberin,member
+      TYPE(AGRIF_PVARIABLE),SAVE                      ::  parentvalues
+      LOGICAL :: find_list_interp
+      INTEGER,DIMENSION(nbdim)    :: indminglob2,indmaxglob2      
+C
+#ifdef AGRIF_MPI
+C
+      LOGICAL :: memberout
+      INTEGER,PARAMETER                          :: etiquette = 100
+      INTEGER                                    :: code
+      INTEGER,DIMENSION(nbdim,4)           :: tab3
+      INTEGER,DIMENSION(nbdim,4,0:Agrif_Nbprocs-1) :: tab4
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall
+      LOGICAL, DIMENSION(1) :: memberin1
+C
+#endif      
+C     
+C   
+C     Boundaries of the current grid where interpolation is done
+
+      
+      
+      
+      IF (Associated(child%var%list_interp)) THEN
+      Call Agrif_Find_list_interp(child%var%list_interp,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &                          indmin,indmax,indminglob,
+     &       indmaxglob,indminglob2,indmaxglob2,parentarray,
+     &       pttruetab,cetruetab,member,memberin,find_list_interp
+#if defined AGRIF_MPI
+     &       ,tab4t,memberinall
+#endif
+     &    )
+      ELSE
+      find_list_interp = .FALSE.
+      ENDIF
+      
+      IF (.not.find_list_interp) THEN
+      Call Agrif_nbdim_Get_bound_dimension(child % var,
+     &                               lowerbound,upperbound,nbdim)
+
+      Call Agrif_Childbounds(nbdim,lowerbound,upperbound,
+     &                                   pttab,petab,
+     &                                   pttruetab,cetruetab,memberin)
+     
+C
+C
+
+      Call Agrif_Parentbounds(TYPEinterp,nbdim,indminglob,indmaxglob,
+     &                        s_Parent_temp,s_Child_temp,
+     &                        s_Child,ds_Child,
+     &                        s_Parent,ds_Parent,
+     &                        pttab,petab,
+     &                        pttab_Child,pttab_Parent,
+     &                        child%var%root_var%posvar,
+     &                        child % var % root_var % interptab)
+
+
+#ifdef AGRIF_MPI
+       IF (memberin) THEN
+        Call Agrif_Parentbounds(TYPEinterp,nbdim,indmin,indmax,
+     &                        s_Parent_temp,s_Child_temp,
+     &                        s_Child,ds_Child,
+     &                        s_Parent,ds_Parent,
+     &                        pttruetab,cetruetab,
+     &                        pttab_Child,pttab_Parent,
+     &                        child%var%root_var%posvar,
+     &                        child % var % root_var % interptab)
+      ENDIF 
+
+      Call Agrif_nbdim_Get_bound_dimension(parent%var,
+     &                              lowerbound,upperbound,nbdim)
+
+      Call Agrif_ChildGrid_to_ParentGrid()
+C
+      Call Agrif_Childbounds(nbdim,
+     &                       lowerbound,upperbound,
+     &                       indminglob,indmaxglob,
+     &                       indminglob2,indmaxglob2,member)
+
+C
+      IF (member) THEN
+      Call Agrif_GlobtoLocInd2(parentarray,
+     &                     lowerbound,upperbound,
+     &                     indminglob2,indmaxglob2,
+     &                     nbdim,Agrif_Procrank,
+     &                     member)
+       endif
+       
+      Call Agrif_ParentGrid_to_ChildGrid()
+#else
+      parentarray(:,1,1) = indminglob
+      parentarray(:,2,1) = indmaxglob
+      parentarray(:,1,2) = indminglob
+      parentarray(:,2,2) = indmaxglob
+      indmin = indminglob
+      indmax = indmaxglob
+      member = .TRUE.
+#endif
+
+      ELSE
+      
+#if !defined AGRIF_MPI
+      parentarray(:,1,1) = indminglob
+      parentarray(:,2,1) = indmaxglob
+      parentarray(:,1,2) = indminglob
+      parentarray(:,2,2) = indmaxglob
+      indmin = indminglob
+      indmax = indmaxglob
+      member = .TRUE.
+      s_Parent_temp = s_Parent + (indminglob - pttab_Parent)*ds_Parent
+      s_Child_temp = s_Child + (pttab - pttab_Child) * ds_Child
+#else      
+      s_Parent_temp = s_Parent + (indmin - pttab_Parent)*ds_Parent
+      s_Child_temp = s_Child + (pttruetab - pttab_Child) * ds_Child
+#endif      
+           
+      ENDIF
+
+
+
+      IF (member) THEN
+      IF (.not.associated(tempP%var)) allocate(tempP%var)
+
+C
+      Call Agrif_nbdim_allocation(tempP%var,
+     &     parentarray(:,1,1),parentarray(:,2,1),nbdim)
+
+      Call Agrif_nbdim_Full_VarEQreal(tempP%var,0.,nbdim)
+
+
+
+      IF (present(procname)) THEN
+      Call Agrif_ChildGrid_to_ParentGrid()
+            SELECT CASE (nbdim)
+        CASE(1)
+          CALL procname(tempP%var%array1,
+     &                          parentarray(1,1,2),parentarray(1,2,2))
+        CASE(2)
+          CALL procname(tempP%var%array2,
+     &                          parentarray(1,1,2),parentarray(1,2,2),
+     &                          parentarray(2,1,2),parentarray(2,2,2))
+        CASE(3)
+          CALL procname(tempP%var%array3,
+     &                          parentarray(1,1,2),parentarray(1,2,2),
+     &                          parentarray(2,1,2),parentarray(2,2,2),
+     &                          parentarray(3,1,2),parentarray(3,2,2))
+        CASE(4)
+          CALL procname(tempP%var%array4,
+     &                          parentarray(1,1,2),parentarray(1,2,2),
+     &                          parentarray(2,1,2),parentarray(2,2,2),
+     &                          parentarray(3,1,2),parentarray(3,2,2),
+     &                          parentarray(4,1,2),parentarray(4,2,2))
+        CASE(5)
+          CALL procname(tempP%var%array5,
+     &                          parentarray(1,1,2),parentarray(1,2,2),
+     &                          parentarray(2,1,2),parentarray(2,2,2),
+     &                          parentarray(3,1,2),parentarray(3,2,2),
+     &                          parentarray(4,1,2),parentarray(4,2,2),
+     &                          parentarray(5,1,2),parentarray(5,2,2))
+        CASE(6)
+          CALL procname(tempP%var%array6,
+     &                          parentarray(1,1,2),parentarray(1,2,2),
+     &                          parentarray(2,1,2),parentarray(2,2,2),
+     &                          parentarray(3,1,2),parentarray(3,2,2),
+     &                          parentarray(4,1,2),parentarray(4,2,2),
+     &                          parentarray(5,1,2),parentarray(5,2,2),
+     &                          parentarray(6,1,2),parentarray(6,2,2))
+            END SELECT
+      Call Agrif_ParentGrid_to_ChildGrid()
+      ELSE
+
+      Call Agrif_nbdim_VarEQvar(tempP%var,
+     &        parentarray(:,1,1),parentarray(:,2,1),
+     &        parent%var,parentarray(:,1,2),parentarray(:,2,2),
+     &        nbdim)
+      ENDIF
+            endif
+
+#ifdef AGRIF_MPI
+      if (.not.find_list_interp) then
+      tab3(:,1) = indminglob2(:)
+      tab3(:,2) = indmaxglob2(:)
+      tab3(:,3) = indmin(:)
+      tab3(:,4) = indmax(:)
+C
+C
+      Call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,
+     &                   MPI_INTEGER,MPI_COMM_WORLD,code)
+
+      IF (.not.associated(tempPextend%var)) Allocate(tempPextend%var)
+
+      DO k=0,Agrif_Nbprocs-1
+       do j=1,4
+         do i=1,nbdim
+         tab4t(i,k,j) = tab4(i,j,k)
+                enddo
+      enddo
+      enddo
+      
+      memberin1(1) = memberin
+      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+     
+      endif     
+           
+      Call Get_External_Data(tempP,tempPextend,tab4t(:,:,1),
+     &            tab4t(:,:,2),
+     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,member,memberin,
+     &            memberinall)
+#else
+      tempPextend%var => tempP%var
+#endif
+
+      if (.not.find_list_interp) then
+      Call Agrif_Addto_list_interp(child%var%list_interp,pttab,petab,
+     &                          pttab_Child,pttab_Parent,indmin,indmax,
+     &   indminglob,indmaxglob,indminglob2,indmaxglob2,parentarray,
+     &   pttruetab,cetruetab,member,memberin,nbdim
+#if defined AGRIF_MPI
+     &   ,tab4t,memberinall
+#endif
+     &    )
+      endif
+      
+C
+C
+      IF (memberin) THEN
+      IF (.not.associated(tempC%var)) allocate(tempC%var)
+C
+
+      Call Agrif_nbdim_allocation(tempC%var,pttruetab,cetruetab,nbdim)
+
+C
+C
+C     Special values on the parent grid
+      if (Agrif_UseSpecialValue) then
+C
+          noraftab(1:nbdim) =
+     &         child % var % root_var % interptab(1:nbdim) .EQ. 'N'
+C
+          IF (.not.associated(parentvalues%var))
+     &            Allocate(parentvalues%var)
+C
+          Call Agrif_nbdim_allocation
+     &               (parentvalues%var,indmin,indmax,nbdim)
+          Call Agrif_nbdim_Full_VarEQvar
+     &               (parentvalues%var,tempPextend%var,nbdim)
+C
+          Call Agrif_CheckMasknD(tempPextend,
+     &                           parentvalues,
+     &                           indmin(1:nbdim),indmax(1:nbdim),
+     &                           indmin(1:nbdim),indmax(1:nbdim),
+     &                           noraftab(1:nbdim),nbdim)
+C
+          Call Agrif_nbdim_deallocation(parentvalues%var,nbdim)
+C          Deallocate(parentvalues%var)
+C
+C
+      endif      
+
+C
+C
+C     Interpolation of the current grid
+
+      IF (memberin) THEN
+      if ( nbdim .EQ. 1 ) then
+         Call Agrif_Interp_1D_recursive(TypeInterp,
+     &           tempPextend%var%array1,tempC%var%array1,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      elseif ( nbdim .EQ. 2 ) then
+
+         Call Agrif_Interp_2D_recursive(TypeInterp,
+     &           tempPextend%var%array2,tempC%var%array2,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      elseif ( nbdim .EQ. 3 ) then
+
+         Call Agrif_Interp_3D_recursive(TypeInterp,
+     &           tempPextend%var%array3,tempC%var%array3,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      elseif ( nbdim .EQ. 4 ) then
+         Call Agrif_Interp_4D_recursive(TypeInterp,
+     &           tempPextend%var%array4,tempC%var%array4,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      elseif ( nbdim .EQ. 5 ) then
+         Call Agrif_Interp_5D_recursive(TypeInterp,
+     &           tempPextend%var%array5,tempC%var%array5,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      elseif ( nbdim .EQ. 6 ) then
+         Call Agrif_Interp_6D_recursive(TypeInterp,
+     &           tempPextend%var%array6,tempC%var%array6,
+     &           indmin,indmax,
+     &           pttruetab,cetruetab,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+       endif
+
+
+C
+C
+C     Special values on the child grid  
+      if (Agrif_UseSpecialValueFineGrid) then
+C
+#ifdef AGRIF_MPI
+C        
+          Call GiveAgrif_SpecialValueToTab_mpi(child%var,tempC%var,
+     &                 childarray,
+     &                 pttruetab,cetruetab,
+     &                 Agrif_SpecialValueFineGrid,nbdim)
+C
+#else
+C
+          Call GiveAgrif_SpecialValueToTab(child%var,tempC%var,
+     &                  pttruetab,cetruetab,
+     &                  Agrif_SpecialValueFineGrid,nbdim)
+C
+#endif 
+C
+C        
+      endif
+C  
+
+      Call Agrif_nbdim_Get_bound_dimension(child % var,
+     &                               lowerbound,upperbound,nbdim)
+
+#ifdef AGRIF_MPI
+      Call Agrif_GlobtoLocInd2(childarray,
+     &                     lowerbound,upperbound,
+     &                     pttruetab,cetruetab,
+     &                     nbdim,Agrif_Procrank,
+     &                     memberout)
+
+#else
+       childarray(:,1,1) = pttruetab
+       childarray(:,2,1) = cetruetab
+       childarray(:,1,2) = pttruetab
+       childarray(:,2,2) = cetruetab
+ccccccccccccccc       memberout = .TRUE.
+#endif
+
+      endif
+
+C
+      if (torestore) then
+C
+#ifdef AGRIF_MPI
+C
+        SELECT CASE (nbdim)
+        CASE (1)
+             do i = pttruetab(1),cetruetab(1)         
+ChildarrayAModifier                if (restore%var%restore1D(i) == 0) 
+ChildarrayAModifier     &                child%var%array1(childarray(i,1,2)
+ChildarrayAModifier     &                                 ) = 
+ChildarrayAModifier     &                tempC%var%array1(i)
+             enddo
+        CASE (2)
+             do i = pttruetab(1),cetruetab(1)
+             do j = pttruetab(2),cetruetab(2)
+ChildarrayAModifier                   if (restore%var%restore2D(i,j) == 0) 
+ChildarrayAModifier     &                child%var%array2(childarray(i,1,2),
+ChildarrayAModifier     &                                 childarray(j,2,2)) = 
+ChildarrayAModifier     &                tempC%var%array2(i,j)
+             enddo
+             enddo
+        CASE (3)
+             do i = pttruetab(1),cetruetab(1)
+             do j = pttruetab(2),cetruetab(2)  
+             do k = pttruetab(3),cetruetab(3)
+ChildarrayAModifier                      if (restore%var%restore3D(i,j,k) == 0) 
+ChildarrayAModifier     &                child%var%array3(childarray(i,1,2),
+ChildarrayAModifier     &                                 childarray(j,2,2),
+ChildarrayAModifier     &                                 childarray(k,3,2)) = 
+ChildarrayAModifier     &                tempC%var%array3(i,j,k)
+             enddo
+             enddo
+             enddo
+        CASE (4)
+             do i = pttruetab(1),cetruetab(1)
+             do j = pttruetab(2),cetruetab(2)
+             do k = pttruetab(3),cetruetab(3)
+             do l = pttruetab(4),cetruetab(4)
+ChildarrayAModifier                         if (restore%var%restore4D(i,j,k,l) == 0) 
+ChildarrayAModifier     &                      child%var%array4(childarray(i,1,2),
+ChildarrayAModifier     &                                       childarray(j,2,2),
+ChildarrayAModifier     &                                       childarray(k,3,2),
+ChildarrayAModifier     &                                       childarray(l,4,2)) = 
+ChildarrayAModifier     &                      tempC%var%array4(i,j,k,l)
+             enddo
+             enddo
+             enddo
+             enddo
+        CASE (5)
+             do i = pttruetab(1),cetruetab(1)
+             do j = pttruetab(2),cetruetab(2)
+             do k = pttruetab(3),cetruetab(3)
+             do l = pttruetab(4),cetruetab(4)
+             do m = pttruetab(5),cetruetab(5)
+ChildarrayAModifier              if (restore%var%restore5D(i,j,k,l,m) == 0) 
+ChildarrayAModifier     &                child%var%array5(childarray(i,1,2),
+ChildarrayAModifier     &                                 childarray(j,2,2),
+ChildarrayAModifier     &                                 childarray(k,3,2),
+ChildarrayAModifier     &                                 childarray(l,4,2),
+ChildarrayAModifier     &                                 childarray(m,5,2)) = 
+ChildarrayAModifier     &                tempC%var%array5(i,j,k,l,m)
+             enddo
+             enddo
+             enddo
+             enddo
+             enddo
+        CASE (6)
+             do i = pttruetab(1),cetruetab(1)
+             do j = pttruetab(2),cetruetab(2)
+             do k = pttruetab(3),cetruetab(3)
+             do l = pttruetab(4),cetruetab(4)
+             do m = pttruetab(5),cetruetab(5)
+             do n = pttruetab(6),cetruetab(6)
+ChildarrayAModifier              if (restore%var%restore6D(i,j,k,l,m,n) == 0) 
+ChildarrayAModifier     &                child%var%array6(childarray(i,1,2),
+ChildarrayAModifier     &                                 childarray(j,2,2),
+ChildarrayAModifier     &                                 childarray(k,3,2),
+ChildarrayAModifier     &                                 childarray(l,4,2),
+ChildarrayAModifier     &                                 childarray(m,5,2),
+ChildarrayAModifier     &                                 childarray(n,6,2)) = 
+ChildarrayAModifier     &                tempC%var%array6(i,j,k,l,m,n)
+             enddo
+             enddo
+             enddo
+             enddo
+             enddo
+             enddo
+        END SELECT
+C
+#else
+        SELECT CASE (nbdim)
+        CASE (1)
+           do i = pttruetab(1),cetruetab(1)         
+            if (restore%var%restore1D(i) == 0)
+     &            child % var % array1(i) = 
+     &            tempC % var % array1(i)    
+          enddo
+        CASE (2)
+           do j = pttruetab(2),cetruetab(2)
+             do i = pttruetab(1),cetruetab(1)            
+              if (restore%var%restore2D(i,j) == 0)     
+     &              child % var % array2(i,j) = 
+     &              tempC % var % array2(i,j)    
+              enddo
+             enddo
+        CASE (3)
+           do k = pttruetab(3),cetruetab(3)
+           do j = pttruetab(2),cetruetab(2)
+             do i = pttruetab(1),cetruetab(1) 
+              if (restore%var%restore3D(i,j,k) == 0)
+     &                  child % var % array3(i,j,k) =
+     &                  tempC % var % array3(i,j,k)    
+                  enddo
+              enddo
+             enddo
+        CASE (4)
+           do l = pttruetab(4),cetruetab(4)
+           do k = pttruetab(3),cetruetab(3)
+          do j = pttruetab(2),cetruetab(2)
+             do i = pttruetab(1),cetruetab(1)
+                if (restore%var%restore4D(i,j,k,l) == 0)
+     &                 child % var % array4(i,j,k,l) = 
+     &                 tempC % var % array4(i,j,k,l)    
+             enddo
+             enddo
+              enddo
+             enddo
+        CASE (5)
+           do m = pttruetab(5),cetruetab(5)
+          do l = pttruetab(4),cetruetab(4)
+         do k = pttruetab(3),cetruetab(3)
+           do j = pttruetab(2),cetruetab(2)
+             do i = pttruetab(1),cetruetab(1)
+                if (restore%var%restore5D(i,j,k,l,m) == 0)
+     &                  child % var % array5(i,j,k,l,m) = 
+     &                  tempC % var % array5(i,j,k,l,m)    
+             enddo
+             enddo
+                  enddo
+              enddo
+             enddo
+        CASE (6)
+           do n = pttruetab(6),cetruetab(6)
+          do m = pttruetab(5),cetruetab(5)
+          do l = pttruetab(4),cetruetab(4)
+         do k = pttruetab(3),cetruetab(3)
+          do j = pttruetab(2),cetruetab(2)
+             do i = pttruetab(1),cetruetab(1)
+                if (restore%var%restore6D(i,j,k,l,m,n) == 0)
+     &                      child % var % array6(i,j,k,l,m,n) = 
+     &                      tempC % var % array6(i,j,k,l,m,n)    
+             enddo
+            enddo
+                      enddo
+                  enddo
+              enddo
+             enddo
+        END SELECT
+C
+#endif
+C        
+        else
+C
+C
+          IF (memberin) THEN
+          SELECT CASE (nbdim)
+          CASE (1)
+            child%var%array1(childarray(1,1,2):childarray(1,2,2)) =
+     &       tempC%var%array1(childarray(1,1,1):childarray(1,2,1))
+          CASE (2)
+            child%var%array2(childarray(1,1,2):childarray(1,2,2),
+     &                       childarray(2,1,2):childarray(2,2,2)) =
+     &      tempC%var%array2(childarray(1,1,1):childarray(1,2,1),
+     &                       childarray(2,1,1):childarray(2,2,1))
+          CASE (3)
+            child%var%array3(childarray(1,1,2):childarray(1,2,2),
+     &                       childarray(2,1,2):childarray(2,2,2),
+     &                       childarray(3,1,2):childarray(3,2,2)) =
+     &      tempC%var%array3(childarray(1,1,1):childarray(1,2,1),
+     &                       childarray(2,1,1):childarray(2,2,1),
+     &                       childarray(3,1,1):childarray(3,2,1))
+          CASE (4)
+            child%var%array4(childarray(1,1,2):childarray(1,2,2),
+     &                       childarray(2,1,2):childarray(2,2,2),
+     &                       childarray(3,1,2):childarray(3,2,2),
+     &                       childarray(4,1,2):childarray(4,2,2)) =
+     &      tempC%var%array4(childarray(1,1,1):childarray(1,2,1),
+     &                       childarray(2,1,1):childarray(2,2,1),
+     &                       childarray(3,1,1):childarray(3,2,1),
+     &                       childarray(4,1,1):childarray(4,2,1))
+          CASE (5)
+            child%var%array5(childarray(1,1,2):childarray(1,2,2),
+     &                       childarray(2,1,2):childarray(2,2,2),
+     &                       childarray(3,1,2):childarray(3,2,2),
+     &                       childarray(4,1,2):childarray(4,2,2),
+     &                       childarray(5,1,2):childarray(5,2,2)) =
+     &      tempC%var%array5(childarray(1,1,1):childarray(1,2,1),
+     &                       childarray(2,1,1):childarray(2,2,1),
+     &                       childarray(3,1,1):childarray(3,2,1),
+     &                       childarray(4,1,1):childarray(4,2,1),
+     &                       childarray(5,1,1):childarray(5,2,1))
+          CASE (6)
+            child%var%array6(childarray(1,1,2):childarray(1,2,2),
+     &                       childarray(2,1,2):childarray(2,2,2),
+     &                       childarray(3,1,2):childarray(3,2,2),
+     &                       childarray(4,1,2):childarray(4,2,2),
+     &                       childarray(5,1,2):childarray(5,2,2),
+     &                       childarray(6,1,2):childarray(6,2,2)) =
+     &      tempC%var%array6(childarray(1,1,1):childarray(1,2,1),
+     &                       childarray(2,1,1):childarray(2,2,1),
+     &                       childarray(3,1,1):childarray(3,2,1),
+     &                       childarray(4,1,1):childarray(4,2,1),
+     &                       childarray(5,1,1):childarray(5,2,1),
+     &                       childarray(6,1,1):childarray(6,2,1))
+          END SELECT
+          ENDIF
+C
+C       
+      endif
+
+        Call Agrif_nbdim_deallocation(tempPextend%var,nbdim)
+C        deallocate(tempPextend%var)
+
+      Call Agrif_nbdim_deallocation(tempC%var,nbdim)
+      
+C      Deallocate(tempC % var)
+      ELSE
+      
+C      deallocate(tempPextend%var)
+
+      ENDIF
+C
+C             
+C     Deallocations
+#ifdef AGRIF_MPI        
+      IF (member) THEN
+      Call Agrif_nbdim_deallocation(tempP%var,nbdim)
+C      Deallocate(tempP % var)
+      endif
+#endif
+C
+C
+      
+C
+C
+      End Subroutine Agrif_InterpnD 
+C
+C
+C
+C                  
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Parentbounds
+C     **************************************************************************
+C
+      Subroutine Agrif_Parentbounds(TYPEinterp,nbdim,indmin,indmax,
+     &                              s_Parent_temp,
+     &                              s_Child_temp,s_Child,ds_Child,
+     &                              s_Parent,ds_Parent,
+     &                              pttruetab,cetruetab,pttab_Child,
+     &                              pttab_Parent,posvar,interptab)
+C
+CCC   Description:
+CCC   Subroutine calculating the bounds of the parent grid for the interpolation
+CCC   of the child grid     
+C
+C
+C     Declarations:
+C
+C
+C     Arguments
+      INTEGER :: nbdim
+      INTEGER, DIMENSION(6) :: TypeInterp
+      INTEGER,DIMENSION(nbdim) :: indmin,indmax
+      REAL,DIMENSION(nbdim) :: s_Parent_temp,s_child_temp
+      REAL,DIMENSION(nbdim) :: s_Child,ds_child
+      REAL,DIMENSION(nbdim) :: s_Parent,ds_Parent
+      INTEGER,DIMENSION(nbdim) :: pttruetab,cetruetab
+      INTEGER,DIMENSION(nbdim) :: pttab_Child,pttab_Parent
+      INTEGER,DIMENSION(nbdim) :: posvar
+      CHARACTER(6), DIMENSION(nbdim) :: interptab
+C
+C     Local variables
+      INTEGER :: i
+      REAL,DIMENSION(nbdim) :: dim_newmin,dim_newmax      
+C
+      dim_newmin = s_Child + (pttruetab - pttab_Child) * ds_Child
+      dim_newmax = s_Child + (cetruetab - pttab_Child) * ds_Child
+      
+      DO i = 1,nbdim         
+C     
+        indmin(i) = pttab_Parent(i) + 
+     &         agrif_int((dim_newmin(i)-s_Parent(i))/ds_Parent(i))
+C
+        indmax(i) = pttab_Parent(i) + 
+     &                agrif_ceiling((dim_newmax(i)-
+     &                s_Parent(i))/ds_Parent(i))
+     
+C
+C
+C       Necessary for the Quadratic interpolation
+C  
+
+        IF ((pttruetab(i) == cetruetab(i)) .AND. 
+     &                           (posvar(i) == 1)) THEN
+        ELSEIF (interptab(i) .EQ. 'N') THEN
+        ELSEIF ( TYPEinterp(i) .eq. Agrif_ppm .or.
+     &      TYPEinterp(i) .eq. Agrif_eno  .or.
+     &      TYPEinterp(i) .eq. Agrif_weno) THEN            
+           indmin(i) = indmin(i) - 2  
+           indmax(i) = indmax(i) + 2                  
+        ELSE IF (( TYPEinterp(i) .ne. Agrif_constant )
+     &        .AND.( TYPEinterp(i) .ne. Agrif_linear )) THEN
+           indmin(i) = indmin(i) - 1  
+           indmax(i) = indmax(i) + 1
+        ENDIF
+        
+
+C        
+       ENDDO 
+C
+        s_Parent_temp = s_Parent + (indmin - pttab_Parent) * ds_Parent
+C     
+        s_Child_temp = s_Child + (pttruetab - pttab_Child) * ds_Child
+C
+C
+      Return
+C
+C
+      End Subroutine Agrif_Parentbounds
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_1D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_1D_recursive(TypeInterp,tabin,tabout,
+     &           indmin,indmax, 
+     &           pttab_child,petab_child,
+     &           s_child,s_parent,ds_child,ds_parent,nbdim)     
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 1D grid variable. 
+CCC   It calls Agrif_InterpBase. 
+C
+C     Declarations:
+C
+      
+C
+C     Arguments
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(1) :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim) :: s_child,s_parent
+      REAL, DIMENSION(nbdim) :: ds_child,ds_parent
+      REAL, INTENT(IN),DIMENSION(indmin(nbdim):indmax(nbdim)) :: tabin        
+      REAL, INTENT(OUT),
+     &      DIMENSION(pttab_child(nbdim):petab_child(nbdim)) :: tabout
+      INTEGER :: coeffraf
+C
+C
+C     Commentaire perso : nbdim vaut toujours 1 ici. 
+C
+      coeffraf = nint(ds_parent(nbdim)/ds_child(nbdim))
+      
+      Call Agrif_InterpBase(TypeInterp(1),
+     &                  tabin(indmin(nbdim):indmax(nbdim)),
+     &                  tabout(pttab_child(nbdim):petab_child(nbdim)),
+     &                  indmin(nbdim),indmax(nbdim),            
+     &                  pttab_child(nbdim),petab_child(nbdim),
+     &                  s_parent(nbdim),s_child(nbdim),
+     &                  ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C                
+      Return
+C
+C
+      End Subroutine Agrif_Interp_1D_recursive
+C
+C
+C      
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_2D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_2D_recursive(TypeInterp,
+     &           tabin,tabout,
+     &           indmin,indmax,   
+     &           pttab_child,petab_child,
+     &            s_child, s_parent,
+     &           ds_child,ds_parent,
+     &           nbdim)
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 2D grid variable. 
+CCC   It calls Agrif_Interp_1D_recursive and Agrif_InterpBase.    
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER,DIMENSION(2)      :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL   , DIMENSION(nbdim) ::  s_child, s_parent
+      REAL   , DIMENSION(nbdim) :: ds_child,ds_parent
+      REAL   ,INTENT(IN), DIMENSION(
+     &                indmin(nbdim-1):indmax(nbdim-1),
+     &                indmin(nbdim):indmax(nbdim)
+     &                ) :: tabin        
+      REAL   ,INTENT(OUT), DIMENSION(
+     &                pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                pttab_child(nbdim):petab_child(nbdim)
+     &                ) :: tabout
+C
+C     Local variables      
+      REAL, DIMENSION(pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                 indmin(nbdim):indmax(nbdim)) :: tabtemp
+      INTEGER i,j
+      INTEGER :: coeffraf
+C
+C
+C
+C
+C     Commentaire perso : nbdim vaut toujours 2 ici.
+C
+      do j = indmin(nbdim),indmax(nbdim)
+C        
+        Call Agrif_Interp_1D_recursive(TypeInterp(1),
+     &         tabin(indmin(nbdim-1):indmax(nbdim-1),j),
+     &         tabtemp(pttab_child(nbdim-1):petab_child(nbdim-1),j),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C        
+      enddo
+C        
+      coeffraf = nint(ds_parent(nbdim)/ds_child(nbdim))
+      
+      do i=pttab_child(nbdim-1),petab_child(nbdim-1)
+C
+        Call Agrif_InterpBase(TypeInterp(2),
+     &           tabtemp(i,indmin(nbdim):indmax(nbdim)),
+     &                  tabout(i,pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C        
+      enddo
+C
+      Return
+C
+C
+      End Subroutine Agrif_Interp_2D_recursive
+C
+C
+C      
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_3D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_3D_recursive(TypeInterp,tabin,tabout,
+     &           indmin,indmax,   
+     &           pttab_child,petab_child,
+     &           s_child,s_parent,ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 3D grid variable. 
+CCC   It calls Agrif_Interp_2D_recursive and Agrif_InterpBase.    
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(3) :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim) :: s_child,s_parent,ds_child,ds_parent
+      REAL,INTENT(IN), DIMENSION(indmin(nbdim-2):indmax(nbdim-2),
+     &                indmin(nbdim-1):indmax(nbdim-1),
+     &                indmin(nbdim)  :indmax(nbdim)) :: tabin        
+      REAL,INTENT(OUT),
+     &        DIMENSION(pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                pttab_child(nbdim):petab_child(nbdim)) :: tabout
+C
+C     Local variables      
+      REAL, DIMENSION(pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                 indmin(nbdim):indmax(nbdim)) :: tabtemp
+      INTEGER i,j,k
+      INTEGER :: coeffraf, locind_child_left, kdeb
+C
+C
+      do k = indmin(nbdim),indmax(nbdim)
+C        
+        Call Agrif_Interp_2D_recursive(TypeInterp(1:2),
+     &         tabin(indmin(nbdim-2):indmax(nbdim-2),
+     &         indmin(nbdim-1):indmax(nbdim-1),k),
+     &         tabtemp(pttab_child(nbdim-2):petab_child(nbdim-2),
+     &         pttab_child(nbdim-1):petab_child(nbdim-1),k),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C        
+      enddo
+      
+
+      Call Agrif_Compute_nbdim_interp(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+           
+      IF (coeffraf == 1) THEN
+      
+      kdeb = indmin(3)+locind_child_left-2
+      do k=pttab_child(3),petab_child(3)
+      kdeb = kdeb + 1
+      do j = pttab_child(2),petab_child(2)
+        do i = pttab_child(1),petab_child(1)
+        tabout(i,j,k) = tabtemp(i,j,kdeb)
+      enddo
+      enddo
+      enddo
+              
+      ELSE      
+C
+      do j=pttab_child(nbdim-1),petab_child(nbdim-1) 
+C        
+        do i=pttab_child(nbdim-2),petab_child(nbdim-2)
+C
+          Call Agrif_InterpBase(TypeInterp(3),
+     &           tabtemp(i,j,indmin(nbdim):indmax(nbdim)),
+     &           tabout(i,j,pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C
+        enddo 
+C       
+      enddo
+      ENDIF
+C
+      Return
+C        
+C
+      End Subroutine Agrif_Interp_3D_recursive
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_4D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_4D_recursive(TypeInterp,tabin,tabout,
+     &           indmin,indmax,   
+     &           pttab_child,petab_child,
+     &           s_child,s_parent,ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 4D grid variable. 
+CCC   It calls Agrif_Interp_3D_recursive and Agrif_InterpBase.    
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(4) :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim) :: s_child,s_parent,ds_child,ds_parent
+      REAL,INTENT(IN), DIMENSION(indmin(nbdim-3):indmax(nbdim-3),
+     &                indmin(nbdim-2):indmax(nbdim-2),
+     &                indmin(nbdim-1):indmax(nbdim-1),
+     &                indmin(nbdim):indmax(nbdim)) :: tabin        
+      REAL,INTENT(OUT),
+     &       DIMENSION(pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                pttab_child(nbdim):petab_child(nbdim)) :: tabout
+C
+C     Local variables      
+      REAL, DIMENSION(pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                 pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),  
+     &                 indmin(nbdim):indmax(nbdim)) :: tabtemp
+      INTEGER i,j,k,l
+      INTEGER :: coeffraf
+C
+C
+      do l = indmin(nbdim),indmax(nbdim)
+C        
+        Call Agrif_Interp_3D_recursive(TypeInterp(1:3),
+     &         tabin(indmin(nbdim-3):indmax(nbdim-3),
+     &               indmin(nbdim-2):indmax(nbdim-2),
+     &               indmin(nbdim-1):indmax(nbdim-1),l),
+     &         tabtemp(pttab_child(nbdim-3):petab_child(nbdim-3),
+     &         pttab_child(nbdim-2):petab_child(nbdim-2),
+     &         pttab_child(nbdim-1):petab_child(nbdim-1),l),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C        
+      enddo
+C
+      coeffraf = nint(ds_parent(nbdim)/ds_child(nbdim))
+      
+      do k = pttab_child(nbdim-1),petab_child(nbdim-1)
+C
+        do j = pttab_child(nbdim-2),petab_child(nbdim-2) 
+C        
+          do i = pttab_child(nbdim-3),petab_child(nbdim-3)
+C
+            Call Agrif_InterpBase(TypeInterp(4),
+     &           tabtemp(i,j,k,indmin(nbdim):indmax(nbdim)),
+     &           tabout(i,j,k,pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C
+          enddo
+C
+        enddo 
+C       
+      enddo
+C
+      Return
+C
+C        
+      End Subroutine Agrif_Interp_4D_recursive
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_5D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_5D_recursive(TypeInterp,tabin,tabout,
+     &           indmin,indmax,   
+     &           pttab_child,petab_child,
+     &           s_child,s_parent,ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 5D grid variable. 
+CCC   It calls Agrif_Interp_4D_recursive and Agrif_InterpBase.    
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(5) :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim) :: s_child,s_parent,ds_child,ds_parent
+      REAL,INTENT(IN), DIMENSION(indmin(nbdim-4):indmax(nbdim-4),
+     &                indmin(nbdim-3):indmax(nbdim-3),
+     &                indmin(nbdim-2):indmax(nbdim-2),
+     &                indmin(nbdim-1):indmax(nbdim-1),
+     &                indmin(nbdim):indmax(nbdim)) :: tabin  
+      REAL,INTENT(OUT),
+     &    DIMENSION(pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                pttab_child(nbdim):petab_child(nbdim)) :: tabout
+C
+C     Local variables      
+      REAL, DIMENSION(pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                 pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                 pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),    
+     &                 indmin(nbdim):indmax(nbdim)) :: tabtemp
+      INTEGER i,j,k,l,m
+      INTEGER :: coeffraf
+C
+C
+      do m = indmin(nbdim),indmax(nbdim)
+C        
+        Call Agrif_Interp_4D_recursive(TypeInterp(1:4),
+     &         tabin(indmin(nbdim-4):indmax(nbdim-4),
+     &               indmin(nbdim-3):indmax(nbdim-3),
+     &               indmin(nbdim-2):indmax(nbdim-2),
+     &               indmin(nbdim-1):indmax(nbdim-1),m),
+     &         tabtemp(pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                 pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                 pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),m),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C        
+      enddo
+      
+      coeffraf = nint(ds_parent(nbdim)/ds_child(nbdim))
+C
+      do l = pttab_child(nbdim-1),petab_child(nbdim-1) 
+C
+        do k = pttab_child(nbdim-2),petab_child(nbdim-2)
+C
+          do j = pttab_child(nbdim-3),petab_child(nbdim-3) 
+C        
+            do i = pttab_child(nbdim-4),petab_child(nbdim-4)
+C
+              Call Agrif_InterpBase(TypeInterp(5),
+     &             tabtemp(i,j,k,l,indmin(nbdim):indmax(nbdim)),
+     &                    tabout(i,j,k,l,
+     &             pttab_child(nbdim):petab_child(nbdim)),
+     &             indmin(nbdim),indmax(nbdim),
+     &             pttab_child(nbdim),petab_child(nbdim),
+     &             s_parent(nbdim),s_child(nbdim),
+     &             ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C
+            enddo
+C
+          enddo
+C
+        enddo 
+C       
+      enddo
+C
+C
+      Return
+C
+C        
+      End Subroutine Agrif_Interp_5D_recursive
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Interp_6D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Interp_6D_recursive(TypeInterp,tabin,tabout,
+     &           indmin,indmax,   
+     &           pttab_child,petab_child,
+     &           s_child,s_parent,ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine for the interpolation of a 6D grid variable. 
+CCC   It calls Agrif_Interp_4D_recursive and Agrif_InterpBase.    
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(6) :: TypeInterp
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim) :: s_child,s_parent,ds_child,ds_parent
+      REAL,INTENT(IN), DIMENSION(indmin(nbdim-5):indmax(nbdim-5),
+     &                indmin(nbdim-4):indmax(nbdim-4),
+     &                indmin(nbdim-3):indmax(nbdim-3), 
+     &                indmin(nbdim-2):indmax(nbdim-2),
+     &                indmin(nbdim-1):indmax(nbdim-1),
+     &                indmin(nbdim):indmax(nbdim)) :: tabin        
+      REAL,INTENT(OUT),
+     &    DIMENSION(pttab_child(nbdim-5):petab_child(nbdim-5),
+     &                pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                pttab_child(nbdim-1):petab_child(nbdim-1),
+     &                pttab_child(nbdim):petab_child(nbdim)) :: tabout
+C
+C     Local variables      
+      REAL, DIMENSION(pttab_child(nbdim-5):petab_child(nbdim-5),
+     &                 pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                 pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                 pttab_child(nbdim-2):petab_child(nbdim-2),    
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),    
+     &                 indmin(nbdim):indmax(nbdim)) :: tabtemp
+      INTEGER i,j,k,l,m,n
+      INTEGER :: coeffraf
+C
+C        
+C
+      do n = indmin(nbdim),indmax(nbdim)
+C        
+        Call Agrif_Interp_5D_recursive(TypeInterp(1:5),
+     &         tabin(indmin(nbdim-5):indmax(nbdim-5),
+     &               indmin(nbdim-4):indmax(nbdim-4),
+     &               indmin(nbdim-3):indmax(nbdim-3),
+     &               indmin(nbdim-2):indmax(nbdim-2),
+     &               indmin(nbdim-1):indmax(nbdim-1),n),
+     &         tabtemp(pttab_child(nbdim-5):petab_child(nbdim-5),
+     &                 pttab_child(nbdim-4):petab_child(nbdim-4),
+     &                 pttab_child(nbdim-3):petab_child(nbdim-3),
+     &                 pttab_child(nbdim-2):petab_child(nbdim-2),
+     &                 pttab_child(nbdim-1):petab_child(nbdim-1),n),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C        
+      enddo
+      
+      coeffraf = nint(ds_parent(nbdim)/ds_child(nbdim))
+C
+      do m = pttab_child(nbdim-1),petab_child(nbdim-1) 
+      do l = pttab_child(nbdim-2),petab_child(nbdim-2) 
+C
+        do k = pttab_child(nbdim-3),petab_child(nbdim-3)
+C
+          do j = pttab_child(nbdim-4),petab_child(nbdim-4) 
+C        
+            do i = pttab_child(nbdim-5),petab_child(nbdim-5)
+C
+              Call Agrif_InterpBase(TypeInterp(6),
+     &             tabtemp(i,j,k,l,m,indmin(nbdim):indmax(nbdim)),
+     &                    tabout(i,j,k,l,m,
+     &                    pttab_child(nbdim):petab_child(nbdim)),
+     &             indmin(nbdim),indmax(nbdim),
+     &             pttab_child(nbdim),petab_child(nbdim),
+     &             s_parent(nbdim),s_child(nbdim),
+     &             ds_parent(nbdim),ds_child(nbdim),coeffraf)
+C
+            enddo
+C
+          enddo
+C
+        enddo 
+C       
+      enddo
+      enddo
+C                
+C
+      Return
+C
+C        
+      End Subroutine Agrif_Interp_6D_recursive
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_InterpBase  
+C     **************************************************************************
+C  
+      Subroutine Agrif_InterpBase(TypeInterp,
+     &                           parenttab,childtab,
+     &                           indmin,indmax,pttab_child,petab_child,
+     &                           s_parent,s_child,ds_parent,ds_child,
+     &                           coeffraf)   
+C
+CCC   Description:
+CCC   Subroutine calling the interpolation method chosen by the user (linear, 
+CCC   lagrange or spline). 
+C
+C     Declarations:
+C
+      
+C
+      INTEGER                :: TypeInterp
+      INTEGER :: indmin,indmax
+      INTEGER :: pttab_child,petab_child
+      REAL,INTENT(IN),DIMENSION(indmin:indmax)           :: parenttab       
+      REAL,INTENT(OUT),DIMENSION(pttab_child:petab_child) :: childtab        
+      REAL    :: s_parent,s_child,ds_parent,ds_child 
+      INTEGER :: coeffraf
+C 
+C
+       IF ((indmin == indmax).AND.(pttab_child == petab_child)) THEN
+         childtab(pttab_child) = parenttab(indmin)
+       ELSEIF (TYPEinterp .EQ. AGRIF_LINEAR) then    
+C
+C         Linear interpolation         
+          Call linear1D
+     &         (parenttab,childtab,
+     &          indmax-indmin+1,petab_child-pttab_child+1,
+     &          s_parent,s_child,ds_parent,ds_child)
+C          
+        elseif (TYPEinterp .EQ. AGRIF_LAGRANGE) then
+C          
+C         Lagrange interpolation    
+          Call lagrange1D
+     &        (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)
+C            
+        elseif (TYPEinterp .EQ. AGRIF_ENO) then
+C          
+C         Eno interpolation
+          Call eno1D
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)
+C        
+        elseif (TYPEinterp .EQ. AGRIF_WENO) then
+C          
+C         Eno interpolation
+          Call weno1D
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)
+C            
+        Else if (TYPEinterp .EQ. AGRIF_LINEARCONSERV) then
+C          
+C         Linear conservative interpolation
+          
+          Call linear1Dconserv
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)   
+C              
+        Else if (TYPEinterp .EQ. AGRIF_LINEARCONSERVLIM) then
+C          
+C         Linear conservative interpolation
+          
+          Call linear1Dconservlim
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)         
+C              
+        elseif (TYPEinterp .EQ. AGRIF_CONSTANT) then
+C          
+          Call constant1D
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)
+C              
+      elseif ( TYPEinterp .EQ. AGRIF_PPM ) then
+          Call ppm1D         
+     &         (parenttab,childtab,
+     &         indmax-indmin+1,petab_child-pttab_child+1,
+     &         s_parent,s_child,ds_parent,ds_child)
+C
+      endif 
+C
+C      
+      End Subroutine Agrif_InterpBase 
+C
+
+      Subroutine Agrif_Compute_nbdim_interp(s_parent,s_child,
+     &  ds_parent,ds_child,coeffraf,locind_child_left)
+      real :: s_parent,s_child,ds_parent,ds_child
+      integer :: coeffraf,locind_child_left
+     
+      coeffraf = nint(ds_parent/ds_child)
+      locind_child_left = 1 + agrif_int((s_child-s_parent)/ds_parent)
+      End Subroutine Agrif_Compute_nbdim_interp
+C          
+
+      Subroutine Agrif_Find_list_interp(list_interp,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &                          indmin,indmax,indminglob,
+     &      indmaxglob,indminglob2,indmaxglob2,parentarray,
+     &       pttruetab,cetruetab,member,memberin,
+     &      find_list_interp
+#if defined AGRIF_MPI
+     &     ,tab4t,memberinall
+#endif
+     &    )     
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_interp
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      LOGICAL :: find_list_interp
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+      INTEGER,DIMENSION(nbdim)   :: indmin,indmax  
+      INTEGER,DIMENSION(nbdim)   :: indminglob,indmaxglob
+      INTEGER,DIMENSION(nbdim)   :: pttruetab,cetruetab      
+      INTEGER,DIMENSION(nbdim)   :: indminglob2,indmaxglob2  
+      INTEGER,DIMENSION(nbdim,2,2) :: parentarray
+      LOGICAL :: member, memberin
+      INTEGER :: i
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall
+#endif 
+                    
+      find_list_interp = .FALSE.
+      
+      parcours => list_interp
+      Find_loop :   Do While (associated(parcours))
+        Do i=1,nbdim
+          IF ((pttab(i) /= parcours%interp_loc%pttab(i)).OR.
+     &        (petab(i) /= parcours%interp_loc%petab(i)).OR.
+     &        (pttab_child(i) /= parcours%interp_loc%pttab_child(i)).OR.
+     &        (pttab_parent(i) /= parcours%interp_loc%pttab_parent(i)))
+     &               THEN
+            parcours=>parcours%suiv
+            Cycle Find_loop
+          ENDIF
+        EndDo
+C        print *,'ok trouve'
+        indmin = parcours%interp_loc%indmin(1:nbdim)
+        indmax = parcours%interp_loc%indmax(1:nbdim)
+        
+        pttruetab = parcours%interp_loc%pttruetab(1:nbdim)
+        cetruetab = parcours%interp_loc%cetruetab(1:nbdim)
+                
+#if !defined AGRIF_MPI
+        indminglob = parcours%interp_loc%indminglob(1:nbdim)
+        indmaxglob = parcours%interp_loc%indmaxglob(1:nbdim)
+#else
+        indminglob2 = parcours%interp_loc%indminglob2(1:nbdim)
+        indmaxglob2 = parcours%interp_loc%indmaxglob2(1:nbdim)
+        parentarray = parcours%interp_loc%parentarray(1:nbdim,:,:)
+        member = parcours%interp_loc%member
+        tab4t = parcours%interp_loc%tab4t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
+        memberinall = parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1)
+#endif        
+        memberin = parcours%interp_loc%memberin
+        find_list_interp = .TRUE.   
+        Exit Find_loop
+      End Do Find_loop  
+                              
+      End Subroutine Agrif_Find_list_interp   
+      
+      Subroutine Agrif_AddTo_list_interp(list_interp,pttab,petab,
+     &                          pttab_Child,pttab_Parent,indmin,indmax,
+     &                          indminglob,indmaxglob,
+     &                          indminglob2,indmaxglob2,
+     &                          parentarray,pttruetab,cetruetab,
+     &                          member,memberin,nbdim
+#if defined AGRIF_MPI
+     &      ,tab4t,memberinall
+#endif
+     &    )
+          
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_interp
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      INTEGER,DIMENSION(nbdim)   :: indmin,indmax
+      INTEGER,DIMENSION(nbdim)   :: indminglob,indmaxglob
+      INTEGER,DIMENSION(nbdim)   :: indminglob2,indmaxglob2
+      INTEGER,DIMENSION(nbdim)   :: pttruetab,cetruetab
+      INTEGER,DIMENSION(nbdim,2,2) :: parentarray
+      LOGICAL :: member, memberin
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t
+      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1) :: memberinall
+#endif                   
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+            
+       Allocate(parcours)
+      Allocate(parcours%interp_loc)
+      
+      parcours%interp_loc%pttab(1:nbdim) = pttab(1:nbdim)
+      parcours%interp_loc%petab(1:nbdim) = petab(1:nbdim)
+      parcours%interp_loc%pttab_child(1:nbdim) = pttab_child(1:nbdim)
+      parcours%interp_loc%pttab_parent(1:nbdim) = pttab_parent(1:nbdim)
+  
+  
+      parcours%interp_loc%indmin(1:nbdim) = indmin(1:nbdim)
+      parcours%interp_loc%indmax(1:nbdim) = indmax(1:nbdim)
+
+      parcours%interp_loc%memberin = memberin
+#if !defined AGRIF_MPI
+      parcours%interp_loc%indminglob(1:nbdim) = indminglob(1:nbdim)
+      parcours%interp_loc%indmaxglob(1:nbdim) = indmaxglob(1:nbdim)
+#else
+      parcours%interp_loc%indminglob2(1:nbdim) = indminglob2(1:nbdim)
+      parcours%interp_loc%indmaxglob2(1:nbdim) = indmaxglob2(1:nbdim)
+      parcours%interp_loc%parentarray(1:nbdim,:,:) 
+     &       = parentarray(1:nbdim,:,:)
+      parcours%interp_loc%member = member
+      Allocate(parcours%interp_loc%tab4t(nbdim,0:Agrif_Nbprocs-1,4))
+      Allocate(parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1))
+      parcours%interp_loc%tab4t=tab4t   
+      parcours%interp_loc%memberinall=memberinall   
+#endif      
+
+      parcours%interp_loc%pttruetab(1:nbdim) = pttruetab(1:nbdim)
+      parcours%interp_loc%cetruetab(1:nbdim) = cetruetab(1:nbdim)
+      
+      parcours%suiv => list_interp
+      
+      list_interp => parcours
+      End Subroutine Agrif_Addto_list_interp 
+                
+      End Module Agrif_Interpolation
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterpbasic.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterpbasic.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modinterpbasic.F	(revision 4536)
@@ -0,0 +1,1128 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Interpbasic
+C
+      Module Agrif_Interpbasic
+C
+CCC   Description:
+CCC   Module containing different procedures of interpolation (linear,lagrange,
+CCC   spline,...) used in the Agrif_Interpolation module.
+C
+C     Modules used:
+      USE Agrif_types
+C
+      IMPLICIT NONE
+C             
+      Real,Dimension(Agrif_MaxRaff) :: tabdiff2, tabdiff3
+      Real,Dimension(:),Allocatable::tabtest4      
+       
+      CONTAINS
+C     Define procedures contained in this module
+C  
+C     **************************************************************************  
+CCC   Subroutine Linear1d  
+C     ************************************************************************** 
+C 
+      Subroutine Linear1d(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a linear 1D interpolation on a child grid (vector y) from
+CCC   its parent grid (vector x).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C        
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL,INTENT(IN), DIMENSION(np) :: x      
+      REAL,INTENT(OUT), DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      INTEGER :: i,coeffraf,locind_parent_left
+      REAL    :: ypos,globind_parent_left,globind_parent_right
+      REAL    :: invds, invds2
+      REAL :: ypos2,diff
+C
+C
+
+      coeffraf = nint(ds_parent/ds_child)
+C
+      if (coeffraf == 1) then
+C
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+C        
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+C
+          return
+C
+      endif                          
+C
+      ypos = s_child 
+
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
+
+        globind_parent_left = s_parent 
+     &                        + (locind_parent_left - 1)*ds_parent
+
+        globind_parent_right = globind_parent_left + ds_parent
+
+C
+      invds = 1./ds_parent
+      invds2 = ds_child/ds_parent
+      
+      ypos2 = ypos*invds
+      globind_parent_right=globind_parent_right*invds
+      
+      do i = 1,nc-1
+C
+        if (ypos2 > globind_parent_right) then
+           locind_parent_left = locind_parent_left + 1.
+           globind_parent_right = globind_parent_right + 1.
+        endif
+        
+        diff=(globind_parent_right - ypos2)
+        
+        y(i) = (diff*x(locind_parent_left)
+     &        + (1.-diff)*x(locind_parent_left+1))
+C
+        ypos2 = ypos2 + invds2
+C
+      enddo
+C
+      ypos = s_child + (nc-1)*ds_child
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
+C
+      if (locind_parent_left == np) then
+C
+          y(nc) = x(np)
+C
+        else
+C
+          globind_parent_left = s_parent 
+     &                        + (locind_parent_left - 1)*ds_parent  
+C      
+          y(nc) = ((globind_parent_left + ds_parent - ypos)
+     &            *x(locind_parent_left)
+     &          + (ypos - globind_parent_left)
+     &            *x(locind_parent_left+1))*invds
+C
+      endif                                          
+C           
+      Return
+C
+C       
+      End Subroutine Linear1d   
+       
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Lagrange1d  
+C     **************************************************************************
+C
+      Subroutine Lagrange1d(x,y,np,nc,
+     &                      s_parent,s_child,ds_parent,ds_child)
+C
+CCC   Description:
+CCC   Subroutine to do a lagrange 1D interpolation on a child grid (vector y) 
+CCC   from its parent grid (vector x).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C             
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL,INTENT(IN), DIMENSION(np) :: x      
+      REAL,INTENT(OUT), DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child,ds_parent,ds_child 
+C
+C     Local scalars
+      INTEGER :: i,coeffraf,locind_parent_left
+      REAL    :: ypos,globind_parent_left
+      REAL    :: X1,X2,X3 
+      real :: deltax,invdsparent
+      real t1,t2,t3,t4,t5,t6,t7,t8
+C
+C 
+      if (np <= 2) then
+C      
+          Call Linear1D(x,y,np,nc,
+     &                  s_parent,s_child,ds_parent,ds_child)
+C         
+         Return
+C 
+      endif
+C
+      coeffraf = nint(ds_parent/ds_child)
+C
+      if (coeffraf == 1) then
+C
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+C        
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+C
+          return
+C
+      endif
+      
+      invdsparent=1./ds_parent
+C
+      ypos = s_child      
+C
+      do i = 1,nc
+C
+        locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
+C
+
+        globind_parent_left = s_parent 
+     &                        + (locind_parent_left - 1)*ds_parent 
+     
+        deltax = invdsparent*(ypos-globind_parent_left)
+        ypos = ypos + ds_child
+         if (abs(deltax).LE.0.0001) then
+           y(i)=x(locind_parent_left)
+           
+           cycle
+         endif
+C           
+C
+        t2 = deltax - 2.
+        t3 = deltax - 1.
+        t4 = deltax + 1.
+        
+        t5 = -(1./6.)*deltax*t2*t3
+        t6 = 0.5*t2*t3*t4
+        t7 = -0.5*deltax*t2*t4
+        t8 = (1./6.)*deltax*t3*t4
+        
+        y(i)=t5*x(locind_parent_left-1)+t6*x(locind_parent_left)
+     &  +t7*x(locind_parent_left+1)+t8*x(locind_parent_left+2)
+C
+C
+      enddo
+C
+      return
+C
+C       
+      End Subroutine Lagrange1d 
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Constant1d  
+C     ************************************************************************** 
+C 
+      Subroutine constant1d(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a linear 1D interpolation on a child grid (vector y) from
+CCC   its parent grid (vector x).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C        
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL,INTENT(IN), DIMENSION(np) :: x      
+      REAL,INTENT(OUT), DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      INTEGER :: i,coeffraf,locind_parent
+      REAL    :: ypos
+C
+C
+
+      coeffraf = nint(ds_parent/ds_child)
+C
+      if (coeffraf == 1) then
+C
+          locind_parent = 1 + nint((s_child - s_parent)/ds_parent)
+C        
+          y(1:nc) = x(locind_parent:locind_parent+nc-1)
+C
+          return
+C
+      endif                          
+C
+      ypos = s_child      
+C
+      do i = 1,nc
+C
+        locind_parent = 1 + nint((ypos - s_parent)/ds_parent)
+C
+        y(i) = x(locind_parent)
+C
+        ypos = ypos + ds_child
+C
+      enddo
+C           
+      Return
+C
+C       
+      End Subroutine constant1d   
+C
+C     **************************************************************************  
+CCC   Subroutine Linear1dconserv
+C     ************************************************************************** 
+C 
+      Subroutine Linear1dconserv(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a linear 1D interpolation on a child grid (vector y) from
+CCC   its parent grid (vector x).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc      
+      Real, Dimension(np) :: x      
+      Real, Dimension(nc) :: y
+      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Real    :: ypos
+      integer :: i1,i2,ii
+      real :: xpmin,xpmax,slope
+      INTEGER :: diffmod
+      REAL :: xdiffmod
+
+C
+C
+
+      coeffraf = nint(ds_parent/ds_child)
+C
+      If (coeffraf == 1) Then
+C
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+C        
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+C
+          return
+C
+      End If
+C              
+      diffmod = 0
+      IF (mod(coeffraf,2) == 0) diffmod = 1  
+
+      xdiffmod = real(diffmod)/2.
+                         
+      allocate(ytemp(-2*coeffraf:nc+2*coeffraf))
+C
+      ypos = s_child  
+C      
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) 
+
+      locind_parent_last = 1 +
+     &  agrif_ceiling((ypos +(nc - 1) *ds_child - s_parent)/ds_parent)
+     
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent 
+      xpmax = s_parent + (locind_parent_last-1)*ds_parent          
+      
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)
+      i2 = 1+agrif_int((xpmax-s_child)/ds_child)
+
+      i = i1
+      
+      if (locind_parent_left == 1) then
+        slope=
+     &   (x(locind_parent_left+1)-x(locind_parent_left))/(coeffraf)
+      else
+         slope=
+     &   (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf)
+      endif
+      
+        do ii=i-coeffraf/2+diffmod,i+coeffraf/2
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo 
+
+        locind_parent_left = locind_parent_left + 1
+                      
+      do i=i1 +  coeffraf, i2 - coeffraf,coeffraf
+        slope=
+     &   (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf)
+        do ii=i-coeffraf/2+diffmod,i+coeffraf/2
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo
+        locind_parent_left = locind_parent_left + 1
+      enddo
+      
+      i = i2
+      
+      if (locind_parent_left == np) then
+        slope=
+     &   (x(locind_parent_left)-x(locind_parent_left-1))/(coeffraf)
+      else
+         slope=
+     &   (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf)
+      endif
+      
+        do ii=i-coeffraf/2+diffmod,nc
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo      
+C
+      y(1:nc)=ytemp(1:nc)                                   
+C           
+      deallocate(ytemp)
+      Return
+C       
+      End Subroutine Linear1dconserv
+      
+C
+C     **************************************************************************  
+CCC   Subroutine Linear1dconservlim
+C     ************************************************************************** 
+C 
+      Subroutine Linear1dconservlim(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a linear 1D interpolation on a child grid (vector y) from
+CCC   its parent grid (vector x).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc      
+      Real, Dimension(np) :: x      
+      Real, Dimension(nc) :: y
+      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Real    :: ypos
+      integer :: i1,i2,ii
+      real :: xpmin,xpmax,slope
+      INTEGER :: diffmod
+      real :: xdiffmod
+C
+C
+
+      coeffraf = nint(ds_parent/ds_child)
+C
+      If (coeffraf == 1) Then
+C
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+C        
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+C
+          return
+C
+      End If
+C
+      IF (coeffraf .NE.3) THEN
+      print *,'LINEARCONSERVLIM not ready for refinement ratio = ',
+     &   coeffraf
+      stop
+      ENDIF   
+      
+      diffmod = 0
+      IF (mod(coeffraf,2) == 0) diffmod = 1        
+
+      xdiffmod = real(diffmod)/2.
+                         
+      allocate(ytemp(-2*coeffraf:nc+2*coeffraf))
+C
+      ypos = s_child  
+C      
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) 
+
+      locind_parent_last = 1 +
+     &  agrif_ceiling((ypos +(nc - 1) *ds_child - s_parent)/ds_parent)
+     
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent 
+      xpmax = s_parent + (locind_parent_last-1)*ds_parent          
+      
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)
+      i2 = 1+agrif_int((xpmax-s_child)/ds_child)
+
+      i = i1
+      
+      if (locind_parent_left == 1) then
+        slope=0.       
+      else
+        slope = vanleer(x(locind_parent_left-1:locind_parent_left+1))
+        slope = slope / coeffraf    
+      endif
+      
+        do ii=i-coeffraf/2+diffmod,i+coeffraf/2
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo 
+
+        locind_parent_left = locind_parent_left + 1
+                      
+      do i=i1 +  coeffraf, i2 - coeffraf,coeffraf     
+        slope = vanleer(x(locind_parent_left-1:locind_parent_left+1))
+        slope = slope / coeffraf
+
+        do ii=i-coeffraf/2+diffmod,i+coeffraf/2
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo
+        locind_parent_left = locind_parent_left + 1
+      enddo
+      
+      i = i2
+      
+      if (locind_parent_left == np) then
+        slope=0.     
+      else
+        slope = vanleer(x(locind_parent_left-1:locind_parent_left+1))
+        slope = slope / coeffraf      
+      endif
+      
+        do ii=i-coeffraf/2+diffmod,nc
+          ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope
+        enddo      
+C
+      y(1:nc)=ytemp(1:nc)                                   
+C           
+      deallocate(ytemp)
+      Return
+C       
+      End Subroutine Linear1dconservlim      
+C         
+
+C     **************************************************************************  
+CCC   Subroutine ppm1d
+C     ************************************************************************** 
+C 
+      Subroutine ppm1d(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a 1D interpolation and apply monotonicity constraints
+CCC   using piecewise parabolic method  
+CCC   on a child grid (vector y) from its parent grid (vector x).
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc      
+      Real, INTENT(IN),Dimension(np) :: x      
+      Real, INTENT(OUT),Dimension(nc) :: y
+C      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Integer :: iparent,ipos,pos,nmin,nmax
+      Real    :: ypos
+      integer :: i1,jj
+      Real :: xpmin,a
+C      
+      Real :: xrmin,xrmax,am3,s2,s1  
+      Real, Dimension(np) :: xl,delta,a6,slope
+C      Real, Dimension(:),Allocatable  :: diff,diff2,diff3    
+      INTEGER :: diffmod
+      REAL :: invcoeffraf
+C      
+      coeffraf = nint(ds_parent/ds_child)
+C
+      If (coeffraf == 1) Then
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+          return
+      End If
+      invcoeffraf = ds_child/ds_parent
+C      
+
+      IF( .NOT. allocated(tabtest4) ) THEN    
+      Allocate(tabtest4(-2*coeffraf:nc+2*coeffraf))
+      ELSE
+         IF (size(tabtest4) .LT. nc+4*coeffraf+1)THEN
+         deallocate( tabtest4 )
+         Allocate(tabtest4(-2*coeffraf:nc+2*coeffraf))
+         ENDIF
+      ENDIF  
+      ypos = s_child  
+C
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) 
+      locind_parent_last = 1 +
+     &      agrif_ceiling((ypos +(nc - 1) 
+     &      *ds_child - s_parent)/ds_parent)  
+C
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent       
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)        
+C     
+C
+      
+      Do i=1,coeffraf
+        tabdiff2(i)=(real(i)-0.5)*invcoeffraf
+      EndDo
+
+      a = invcoeffraf**2 
+      tabdiff3(1) = (1./3.)*a
+      a=2.*a
+      Do i=2,coeffraf
+        tabdiff3(i) = tabdiff3(i-1)+(real(i)-1)*a
+      EndDo
+C
+      if( locind_parent_last+2 <= np ) then
+           nmax = locind_parent_last+2    
+      else if( locind_parent_last+1 <= np ) then
+           nmax = locind_parent_last+1
+      else
+           nmax = locind_parent_last 
+      endif     
+C      
+      if(locind_parent_left-1 >= 1) then
+          nmin = locind_parent_left-1
+      else 
+          nmin = locind_parent_left
+      endif    
+C 
+C
+      Do i = nmin,nmax
+         slope(i) = x(i) - x(i-1)
+      Enddo
+
+      Do i = nmin+1,nmax-1
+         xl(i)= 0.5*(x(i-1)+x(i))
+     &      -0.08333333333333*(slope(i+1)-slope(i-1)) 
+      Enddo
+C
+C apply parabolic monotonicity
+       Do i = locind_parent_left,locind_parent_last
+          delta(i) = xl(i+1) - xl(i)
+          a6(i) = 6.*x(i)-3.*(xl(i) +xl(i+1))
+C
+       End do   
+C
+        diffmod = 0
+       IF (mod(coeffraf,2) == 0) diffmod = 1
+C
+        ipos = i1
+C               
+        Do iparent = locind_parent_left,locind_parent_last       
+             pos=1
+             Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2
+C
+               tabtest4(jj) = xl(iparent)   
+     &             + tabdiff2(pos) *  (delta(iparent)+a6(iparent))
+     &             - tabdiff3(pos) *  a6(iparent)
+               pos = pos+1 
+             End do 
+             ipos = ipos + coeffraf
+C
+        End do     
+C
+C
+        y(1:nc)=tabtest4(1:nc)
+        
+      Return
+      End Subroutine ppm1d
+      
+C     **************************************************************************  
+CCC   Subroutine weno1d
+C     ************************************************************************** 
+C 
+      Subroutine weno1dnew(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a 1D interpolation and apply monotonicity constraints
+CCC   using piecewise parabolic method  
+CCC   on a child grid (vector y) from its parent grid (vector x).
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc
+      Real, Dimension(np) :: x
+      Real, Dimension(nc) :: y
+      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Integer :: iparent,ipos,pos,nmin,nmax
+      Real    :: ypos
+      integer :: i1,jj
+      Real :: xpmin,cavg,a,b
+C      
+      Real :: xrmin,xrmax,am3,s2,s1
+      Real, Dimension(np) :: xr,xl,delta,a6,slope,slope2,smooth
+      Real, Dimension(:),Allocatable  :: diff,diff2,diff3
+      INTEGER :: diffmod
+      REAL :: invcoeffraf
+      integer :: s,l,k
+      integer :: etan, etap
+      real :: delta0, delta1, delta2
+      real :: epsilon
+      parameter (epsilon = 1.D-8)
+      real, dimension(:,:), allocatable :: ak, ck
+C      
+      coeffraf = nint(ds_parent/ds_child)
+C
+      If (coeffraf == 1) Then
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+          return
+      End If
+      invcoeffraf = ds_child/ds_parent
+      Allocate(ak(0:1,coeffraf))
+      Allocate(ck(0:1,coeffraf))
+            
+C      
+      Allocate(ytemp(-2*coeffraf:nc+2*coeffraf))
+      ypos = s_child
+C
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
+      locind_parent_last = 1 +
+     &      agrif_ceiling((ypos +(nc - 1)
+     &      *ds_child - s_parent)/ds_parent)
+C
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)
+C     
+      Allocate( diff(coeffraf),diff2(coeffraf),diff3(coeffraf) )
+C      
+      diff(1)=0.5*invcoeffraf
+      do i=2,coeffraf
+         diff(i) = diff(i-1)+invcoeffraf
+      enddo
+      
+      ak = 0.
+      ck = 0.
+      
+      do i=1,coeffraf
+         do k=0,1
+         do s=0,2
+         do l=0,2
+           if (l /= s) then
+            ak(k,i) = ak(k,i)+(diff(i)-(k-l+1.))
+           endif
+         enddo
+         enddo
+         enddo
+               
+         etap = 0
+         etan = 0
+         do k=0,1
+          if (ak(k,i) > 0) then
+            etap = etap+1
+          else if (ak(k,i) < 0) then
+            etan = etan + 1
+          endif
+         enddo
+               
+         do k=0,1
+           if (ak(k,i) == 0) then
+            Ck(k,i) = 1.
+           else if (ak(k,i) > 0) then
+            Ck(k,i) = 1./(etap * ak(k,i))
+           else
+            Ck(k,i) = -1./(etan * ak(k,i))
+           endif
+         enddo
+      enddo
+                     
+C      
+      a = 0.
+      b = invcoeffraf
+      Do i=1,coeffraf
+         diff2(i) = 0.5*(b*b - a*a)  
+         diff3(i) = (1./3.)*(b*b*b - a*a*a)
+         a = a + invcoeffraf
+         b = b + invcoeffraf
+      End do
+C
+      if( locind_parent_last+2 <= np ) then
+           nmax = locind_parent_last+2    
+      elseif( locind_parent_last+1 <= np ) then
+           nmax = locind_parent_last+1
+      else
+           nmax = locind_parent_last 
+      endif     
+C      
+      if(locind_parent_left-2 >= 1) then
+          nmin = locind_parent_left-2
+      elseif(locind_parent_left-1 >= 1) then
+          nmin = locind_parent_left-1
+      else 
+          nmin = locind_parent_left
+      endif    
+C 
+      Do i = nmin+1,nmax
+         slope(i) = (x(i) - x(i-1))
+      Enddo 
+      DO i=nmin+2,nmax
+        smooth(i) = 0.5*(slope(i)**2+slope(i-1)**2)
+     &       +(slope(i)-slope(i-1))**2
+      enddo
+C
+        diffmod = 0
+        IF (mod(coeffraf,2) == 0) diffmod = 1           
+C
+        ipos = i1
+C               
+        Do iparent = locind_parent_left,locind_parent_last       
+             pos=1
+             
+            delta0=1./(epsilon+smooth(iparent  ))**3
+            delta1=1./(epsilon+smooth(iparent+1))**3
+            delta2=1./(epsilon+smooth(iparent+2))**3   
+                      
+             Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2
+C
+               pos = pos+1 
+             End do 
+             ipos = ipos + coeffraf
+C
+        End do     
+C
+C
+        y(1:nc)=ytemp(1:nc)                                 
+        deallocate(ytemp)                
+        deallocate(diff, diff2, diff3)
+        
+        deallocate(ak,ck)
+        
+      Return
+      End Subroutine weno1dnew
+      
+C     **************************************************************************  
+CCC   Subroutine weno1d
+C     ************************************************************************** 
+C 
+      Subroutine weno1d(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a 1D interpolation and apply monotonicity constraints
+CCC   using piecewise parabolic method  
+CCC   on a child grid (vector y) from its parent grid (vector x).
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc
+      Real, Dimension(np) :: x
+      Real, Dimension(nc) :: y
+      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Integer :: iparent,ipos,pos,nmin,nmax
+      Real    :: ypos
+      integer :: i1,jj
+      Real :: xpmin,cavg,a,b
+C      
+      Real :: xrmin,xrmax,am3,s2,s1
+      Real, Dimension(np) :: xr,xl,delta,a6,slope,slope2
+      Real, Dimension(:),Allocatable  :: diff,diff2,diff3
+      INTEGER :: diffmod
+      REAL :: invcoeffraf
+      integer :: s,l,k
+      integer :: etan, etap
+      real :: delta0, delta1,sumdelta
+      real :: epsilon
+      parameter (epsilon = 1.D-8)
+C      
+      coeffraf = nint(ds_parent/ds_child)
+C
+      If (coeffraf == 1) Then
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+          return
+      End If
+      invcoeffraf = ds_child/ds_parent
+            
+C      
+      Allocate(ytemp(-2*coeffraf:nc+2*coeffraf))
+      ypos = s_child
+C
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
+      locind_parent_last = 1 +
+     &      agrif_ceiling((ypos +(nc - 1)
+     &      *ds_child - s_parent)/ds_parent)
+C
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)
+C     
+      Allocate( diff(coeffraf))
+C      
+      diff(1)=0.5*invcoeffraf
+      do i=2,coeffraf
+         diff(i) = diff(i-1)+invcoeffraf
+      enddo
+C
+      if( locind_parent_last+2 <= np ) then
+           nmax = locind_parent_last+2   
+      else if( locind_parent_last+1 <= np ) then
+           nmax = locind_parent_last+1
+      else
+           nmax = locind_parent_last 
+      endif     
+C      
+      if(locind_parent_left-1 >= 1) then
+          nmin = locind_parent_left-1
+      else 
+          nmin = locind_parent_left
+      endif    
+C 
+      Do i = nmin+1,nmax
+         slope(i) = (x(i) - x(i-1))
+      Enddo 
+C
+        diffmod = 0
+        IF (mod(coeffraf,2) == 0) diffmod = 1           
+C
+        ipos = i1
+C               
+        Do iparent = locind_parent_left,locind_parent_last       
+             pos=1
+            delta0=1./(epsilon+slope(iparent  )**2)**2
+            delta1=1./(epsilon+slope(iparent+1)**2)**2
+            sumdelta = 1./(delta0+delta1)             
+             Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2
+C                              
+          ytemp(jj) = x(iparent)+(diff(pos)-0.5)*(
+     &                delta0*slope(iparent)+
+     &                delta1*slope(iparent+1))*sumdelta
+               pos = pos+1 
+             End do 
+             ipos = ipos + coeffraf
+C
+        End do     
+C
+C
+        y(1:nc)=ytemp(1:nc)                                 
+        deallocate(ytemp)                
+        deallocate(diff)
+        
+      Return
+      End Subroutine weno1d
+                 
+C                              
+C     **************************************************************************  
+CCC   Subroutine eno1d
+C     ************************************************************************** 
+C 
+      Subroutine eno1d(x,y,np,nc,
+     &                    s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   ---- p 163-164 Computational gasdynamics ----
+CCC   Subroutine to do a 1D interpolation 
+CCC   using piecewise polynomial ENO reconstruction technique  
+CCC   on a child grid (vector y) from its parent grid (vector x).
+CC    Method:
+C
+C     Declarations:
+C
+      Implicit none
+C        
+C     Arguments
+      Integer             :: np,nc      
+      Real, Dimension(np) :: x      
+      Real, Dimension(nc) :: y
+      Real, Dimension(:),Allocatable :: ytemp
+      Real                :: s_parent,s_child,ds_parent,ds_child
+C
+C     Local scalars
+      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
+      Integer :: ipos,pos
+      Real    :: ypos,xi
+      integer :: i1,jj
+      Real :: xpmin,cavg
+C 
+      Real, Dimension(3,np) :: dd,c
+      Integer :: left
+C           
+      Real, DImension(1:np+1) :: xhalf
+      Real, Dimension(:,:),Allocatable  :: Xbar 
+      INTEGER :: diffmod     
+C
+      coeffraf = nint(ds_parent/ds_child)
+C      
+      If (coeffraf == 1) Then
+          locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent)
+          y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1)
+          return
+      End If     
+      
+      diffmod = 0
+      IF (mod(coeffraf,2) == 0) diffmod = 1  
+C      
+      Allocate(ytemp(-2*coeffraf:nc+2*coeffraf))
+      ypos = s_child  
+      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) 
+      locind_parent_last = 1 +
+     &      agrif_ceiling((ypos +(nc - 1) *ds_child - 
+     &      s_parent)/ds_parent)       
+      xpmin = s_parent + (locind_parent_left-1)*ds_parent      
+      i1 = 1+agrif_int((xpmin-s_child)/ds_child)           
+C      
+      xhalf(np+1) = np + 0.5
+      Do i = 1,np
+          xhalf(i) = i - 0.5
+      Enddo
+C
+C compute divided differences
+C
+      dd(1,1:np) = x(1:np)
+      dd(2,1:np-1) = 0.5*( dd(1,2:np) - dd(1,1:np-1) )
+      dd(3,1:np-2) = (1./3.)*( dd(2,2:np-1) - dd(2,1:np-2) )
+C
+      Allocate( Xbar( coeffraf,2 ) )
+      xi = 0.5
+      Do i = 1,coeffraf
+        Xbar(i,1) = (i-1)*ds_child/ds_parent - xi
+        Xbar(i,2) = i*ds_child/ds_parent - xi
+      Enddo
+C
+      ipos = i1
+C           
+      DO i = locind_parent_left,locind_parent_last           
+         left = i           
+         do jj = 2,3
+             If(abs(dd(jj,left)) .gt. abs(dd(jj,left-1)))
+     &               left = left-1            
+         enddo
+C           
+C  convert to Taylor series form
+C
+         Call Taylor(i,xhalf(left:left+2),dd(1:3,left),c(1:3,i))
+      ENDDO     
+C
+C evaluate the reconstruction on each cell
+C
+       DO i = locind_parent_left,locind_parent_last  
+C
+         cavg = 0.
+         pos = 1.            
+C         
+         Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2
+           ytemp(jj) =(c(1,i)*(Xbar(pos,2)-Xbar(pos,1))
+     &                +c(2,i)*(Xbar(pos,2)*Xbar(pos,2)-
+     &                         Xbar(pos,1)*Xbar(pos,1))
+     &                +c(3,i)*(Xbar(pos,2)*Xbar(pos,2)*Xbar(pos,2)-
+     &                         Xbar(pos,1)*Xbar(pos,1)*Xbar(pos,1)))
+     &                         *coeffraf
+           cavg = cavg + ytemp(jj)
+           pos = pos+1
+         Enddo                
+         ipos = ipos + coeffraf                 
+      ENDDO
+C
+      y(1:nc)=ytemp(1:nc)                                            
+      deallocate(ytemp,Xbar)                 
+C      
+      Return       
+      End Subroutine eno1d
+C 
+C      
+C     **************************************************************************  
+CCC   Subroutine taylor
+C     ************************************************************************** 
+C       
+      subroutine taylor(ind,xhalf,dd,c)      
+C      
+      Integer :: ind
+      real,dimension(3) :: dd,c     
+      real,dimension(0:3,0:3) :: d 
+      real,dimension(3) :: xhalf    
+      integer ::i,j
+C      
+C
+      d(0,0:3)=1.
+      do i = 1,3
+         d(i,0)=(ind-xhalf(i))*d(i-1,0)
+      enddo  
+C      
+      do i = 1,3
+         do j = 1,3-i
+           d(i,j) = d(i,j-1) + (ind-xhalf(i+j))*d(i-1,j)
+         enddo
+      enddo
+C         
+      do j = 1,3        
+         c(j) = 0.
+         do i=0,3-j
+            c(j) = c(j) + d(i,j)*dd(i+j)         
+         enddo
+      enddo
+C      
+      end subroutine taylor    
+      
+      
+      REAL FUNCTION vanleer(tab)
+      REAL, DIMENSION(3) :: tab
+       real res1
+       real p1,p2,p3
+       
+       p1=(tab(3)-tab(1))/2.
+       p2=2.*(tab(2)-tab(1))
+       p3=2.*(tab(3)-tab(2))
+       
+       if ((p1>0.).AND.(p2>0.).AND.(p3>0)) then
+          res1=minval((/p1,p2,p3/))
+       elseif ((p1<0.).AND.(p2<0.).AND.(p3<0)) then
+          res1=maxval((/p1,p2,p3/))
+       else
+          res1=0.
+       endif
+          
+          vanleer = res1   
+      
+      
+      END FUNCTION vanleer 
+
+C      
+      End Module Agrif_Interpbasic
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modlinktomodel.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modlinktomodel.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modlinktomodel.F	(revision 4536)
@@ -0,0 +1,173 @@
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place -  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+      Module Agrif_link
+C
+CCC   Description:
+CCC   This module is used to link AGRIF files to the model
+C
+C     Modules used: 
+C
+c        external Agrif_InitValues
+c        external Agrif_InitWorkspace
+c        external Agrif_detect
+C
+        external Agrif_probdim_modtype_def
+        external Agrif_clustering_def
+C     Interface                       
+      Interface
+         Subroutine Agrif_Set_numberofcells(Agrif_Gr)
+         Use Agrif_Types, Only : Agrif_grid
+         TYPE(Agrif_Grid), Pointer :: Agrif_Gr   ! Pointer on the current grid  
+         End Subroutine Agrif_Set_numberofcells
+      End interface
+      Interface
+         Subroutine Agrif_Get_numberofcells(Agrif_Gr)
+         Use Agrif_Types, Only : Agrif_grid
+         TYPE(Agrif_Grid), Pointer :: Agrif_Gr   ! Pointer on the current grid  
+         End Subroutine Agrif_Get_numberofcells
+      End interface
+      Interface
+         Subroutine Agrif_Allocationcalls(Agrif_Gr)
+         Use Agrif_Types, Only : Agrif_grid
+         TYPE(Agrif_Grid), Pointer :: Agrif_Gr   ! Pointer on the current grid  
+         End Subroutine Agrif_Allocationcalls
+      End interface
+C   
+      End Module Agrif_link
+C     **************************************************************************
+CCC   Function Agrif_parent
+C        modify by conv. To use : un_parent = Agrif_Parent(un)
+C     **************************************************************************
+CCC   Function Agrif_Get_Coarse_Grid
+C        modify by conv. To use : un_Mygrid = Agrif_Get_Coarse_grid(un)
+C     **************************************************************************
+CCC   Function Agrif_Rhox
+C        modify by conv. To use : var = Agrif_Rhox()
+C                    REAL(Agrif_Curgrid % spaceref(1))
+C     **************************************************************************
+CCC   Function Agrif_Parent_Rhox
+C        modify by conv. To use : var = Agrif_Parent_Rhox()
+C                    REAL(Agrif_Curgrid % parent % spaceref(1))
+C     **************************************************************************
+CCC   Function Agrif_Irhox
+C        modify by conv. To use : var = Agrif_Parent_IRhox()
+C                    Agrif_Curgrid % spaceref(1)
+C     **************************************************************************
+CCC   Function Agrif_Parent_Irhox
+C        modify by conv. To use : var = Agrif_Parent_IRhox()
+C                    Agrif_Curgrid % parent % spaceref(1)
+C     **************************************************************************
+CCC   Function Agrif_Rhoy
+C        modify by conv. To use : var = Agrif_Rhoy()
+C                    REAL(Agrif_Curgrid % spaceref(2))
+C     **************************************************************************
+CCC   Function Agrif_Parent_Rhoy
+C        modify by conv. To use : var = Agrif_Parent_Rhoy()
+C                    REAL(Agrif_Curgrid % parent % spaceref(2))
+C     **************************************************************************
+CCC   Function Agrif_Irhoy
+C        modify by conv. To use : var = Agrif_Parent_IRhoy()
+C                    Agrif_Curgrid % spaceref(2)
+C     **************************************************************************
+CCC   Function Agrif_Parent_Irhoy
+C        modify by conv. To use : var = Agrif_Parent_IRhoy()
+C                    Agrif_Curgrid % parent % spaceref(2)
+C     **************************************************************************
+CCC   Function Agrif_Rhoz
+C        modify by conv. To use : var = Agrif_Rhoz()
+C                    REAL(Agrif_Curgrid % spaceref(3))
+C     **************************************************************************
+CCC   Function Agrif_Parent_Rhoz
+C        modify by conv. To use : var = Agrif_Parent_Rhoz()
+C                    REAL(Agrif_Curgrid % parent % spaceref(3))
+C     **************************************************************************
+CCC   Function Agrif_Irhoz
+C        modify by conv. To use : var = Agrif_Parent_IRhoz()
+C                    Agrif_Curgrid % spaceref(3)
+C     **************************************************************************
+CCC   Function Agrif_Parent_Irhoz
+C        modify by conv. To use : var = Agrif_Parent_IRhoz()
+C                    Agrif_Curgrid % parent % spaceref(3)
+C     **************************************************************************
+CCC   Function Agrif_NearCommonBorderX
+C        modify by conv. To use : var = Agrif_NearCommonBorderX()
+C                       AGRIF_CURGRID % NearRootBorder(1)
+C     **************************************************************************
+CCC   Function Agrif_NearCommonBorderY
+C        modify by conv. To use : var = Agrif_NearCommonBorderY()
+C                       AGRIF_CURGRID % NearRootBorder(2)
+C     **************************************************************************
+CCC   Function Agrif_NearCommonBorderZ
+C        modify by conv. To use : var = Agrif_NearCommonBorderZ()
+C                       AGRIF_CURGRID % NearRootBorder(3)
+C     **************************************************************************
+CCC   Function Agrif_DistantCommonBorderX
+C        modify by conv. To use : var = Agrif_DistantCommonBorderX()
+C                       AGRIF_CURGRID % DistantRootBorder(1)
+C     **************************************************************************
+CCC   Function Agrif_DistantCommonBorderY
+C        modify by conv. To use : var = Agrif_DistantCommonBorderY()
+C                       AGRIF_CURGRID % DistantRootBorder(2)
+C     **************************************************************************
+CCC   Function Agrif_DistantCommonBorderZ
+C        modify by conv. To use : var = Agrif_DistantCommonBorderZ()
+C                       AGRIF_CURGRID % DistantRootBorder(3)
+C     **************************************************************************
+CCC   Function Agrif_Nb_Step
+C        modify by conv. To use : var = Agrif_Nb_Step()
+C                          AGRIF_CURGRID % ngridstep
+C     **************************************************************************
+CCC   Function Agrif_Nb_Fine_Grids
+C        modify by conv. To use : var = Agrif_Nb_Fine_Grids()
+C                         Agrif_nbfixedgrids 
+C     **************************************************************************
+CCC   Function Agrif_Ix
+C        modify by conv. To use : var = Agrif_Ix()
+C                         Agrif_CURGRID % ix(1) 
+C     **************************************************************************
+CCC   Function Agrif_Parent_Ix
+C        modify by conv. To use : var = Agrif_Parent_Ix()
+C                        Agrif_CURGRID % parent % ix(1) 
+C     **************************************************************************
+CCC   Function Agrif_Iy
+C        modify by conv. To use : var = Agrif_Iy()
+C                        AGRIF_CURGRID % ix(2) 
+C     **************************************************************************
+CCC   Function Agrif_Parent_Iy
+C        modify by conv. To use : var = Agrif_Parent_Iy()
+C                       Agrif_CURGRID % parent % ix(2) 
+C     **************************************************************************
+CCC   Function Agrif_Iz
+C        modify by conv. To use : var = Agrif_Iz()
+C                      AGRIF_CURGRID % ix(3) 
+C     **************************************************************************
+CCC   Function Agrif_Parent_Iz
+C        modify by conv. To use : var = Agrif_Parent_Iz()
+C                     Agrif_CURGRID % parent % ix(3) 
+C     **************************************************************************
+CCC   Function Agrif_Get_grid_id
+C        modify by conv. To use : var = Agrif_Get_grid_id()
+C                    Agrif_CURGRID % grid_id
+C     **************************************************************************
+CCC   Function Agrif_Get_parent_id
+C        modify by conv. To use : var = Agrif_Get_parent_id()
+C                    Agrif_CURGRID % parent % grid_id
+C     **************************************************************************
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmask.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmask.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmask.F	(revision 4536)
@@ -0,0 +1,414 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place -  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Mask
+C
+      Module Agrif_Mask
+C
+CCC   Description:
+CCC   Module for masks
+C
+C     Modules used: 
+C
+      Use Agrif_Types       
+C
+      IMPLICIT NONE
+      Integer, Parameter :: MaxSearch = 5
+C
+      CONTAINS
+C     Define procedures contained in this module
+C
+C     **************************************************************************
+C     Subroutine Agrif_CheckMasknD
+C     **************************************************************************
+C       
+      Subroutine Agrif_CheckMasknD(tempP,parent,pbtab,petab,ppbtab,
+     &               ppetab,noraftab,nbdim)
+C
+CCC   Description:
+CCC   Subroutine called in the procedure Agrif_InterpnD to recalculate the value 
+CCC   of the parent grid variable when this one is equal to Agrif_SpecialValue. 
+C
+C     Declarations:
+C
+       
+C
+C     Arrays arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim) :: pbtab  ! Limits of the parent grid used  
+      INTEGER,DIMENSION(nbdim) :: petab  ! interpolation of the child grid
+      LOGICAL,DIMENSION(nbdim) :: noraftab
+      INTEGER,DIMENSION(nbdim) :: ppbtab,ppetab
+C
+C     Pointer argument
+      TYPE(AGRIF_PVARIABLE) :: tempP  ! Part of the parent grid used for 
+                                      ! the interpolation of the child grid                     
+C     Data TYPE argument                                   
+      TYPE(AGRIF_PVARIABLE) :: parent      ! The parent grid
+C
+C     Local scalar
+      INTEGER                   :: i0,j0,k0,l0,m0,n0
+C      
+C     Local arrays
+C
+C      
+      SELECT CASE (nbdim)
+      CASE (1)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array1(i0)
+     &                        == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo
+      CASE (2)
+         do j0 = pbtab(2),petab(2)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array2(i0,j0)
+     &                        == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0,j0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo  
+         enddo
+      CASE (3)
+         do k0 = pbtab(3),petab(3)
+         do j0 = pbtab(2),petab(2)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array3(i0,j0,k0)
+     &                        == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0,j0,k0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo
+         enddo  
+         enddo
+      CASE (4)
+         do l0 = pbtab(4),petab(4)
+         do k0 = pbtab(3),petab(3)
+         do j0 = pbtab(2),petab(2)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array4(i0,j0,k0,l0) 
+     &                        == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0,j0,k0,l0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo
+         enddo
+         enddo  
+         enddo
+      CASE (5)
+         do m0 = pbtab(5),petab(5)
+         do l0 = pbtab(4),petab(4)
+         do k0 = pbtab(3),petab(3)
+         do j0 = pbtab(2),petab(2)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array5(i0,j0,k0,l0,m0) 
+     &                       == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0,j0,k0,l0,m0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo
+         enddo
+         enddo  
+         enddo
+         enddo
+      CASE (6)
+         do n0 = pbtab(6),petab(6)
+         do m0 = pbtab(5),petab(5)
+         do l0 = pbtab(4),petab(4)
+         do k0 = pbtab(3),petab(3)
+         do j0 = pbtab(2),petab(2)
+         do i0 = pbtab(1),petab(1)
+         IF (tempP%var%array6(i0,j0,k0,l0,m0,n0) 
+     &                       == Agrif_SpecialValue) Then
+            Call CalculNewValTempP((/i0,j0,k0,l0,m0,n0/),
+     &                             tempP,parent,
+     &                             ppbtab,ppetab,
+     &                             noraftab,nbdim)
+         ENDIF
+         enddo
+         enddo
+         enddo
+         enddo  
+         enddo
+         enddo
+      END SELECT
+C
+C      
+C     
+      End Subroutine Agrif_CheckMasknD
+C
+C
+C     **************************************************************************
+C     Subroutine CalculNewValTempP
+C     **************************************************************************
+C       
+      Subroutine CalculNewValTempP(indic,
+     &               tempP,parent,ppbtab,
+     &               ppetab,noraftab,nbdim)
+C
+CCC   Description:
+CCC   Subroutine called in the procedure Agrif_InterpnD to recalculate the value 
+CCC   of the parent grid variable when this one is equal to Agrif_SpecialValue. 
+C
+C     Declarations:
+C
+       
+C
+C     Arrays arguments      
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim) :: indic
+      LOGICAL,DIMENSION(nbdim) :: noraftab
+      INTEGER,DIMENSION(nbdim) :: ppbtab,ppetab
+C
+C     Pointer argument
+      TYPE(AGRIF_PVARIABLE) :: tempP  ! Part of the parent grid used for 
+                                      ! the interpolation of the child grid                     
+C     Data TYPE argument                                   
+      TYPE(AGRIF_PVARIABLE) :: parent      ! The parent grid
+C
+C     Local scalar
+      INTEGER                  :: i,ii,iii,jj,kk,ll,mm,nn 
+      INTEGER,DIMENSION(nbdim) :: imin,imax,idecal
+      INTEGER                  :: Nbvals
+      REAL                     :: Res
+      REAL                     :: ValParent
+      INTEGER                  :: ValMax
+      LOGICAL                  :: firsttest
+C      
+C     Local arrays      
+C
+      ValMax = 1
+      do iii = 1 , nbdim
+         IF (.NOT.noraftab(iii)) THEN
+         ValMax = max(ValMax,ppetab(iii)-indic(iii))
+         ValMax = max(ValMax,indic(iii)-ppbtab(iii))
+         ENDIF
+      enddo
+C
+      Valmax = min(Valmax,MaxSearch)
+C
+      imin = indic
+      imax = indic
+C
+         i = 1
+         firsttest = .TRUE.
+C
+         do While(i <= ValMax)
+C
+         IF ((i == 1).AND.(firsttest)) i = Valmax
+
+            do iii = 1 , nbdim
+               if (.NOT.noraftab(iii)) then
+                  imin(iii) = max(indic(iii) - i,ppbtab(iii))
+                  imax(iii) = min(indic(iii) + i,ppetab(iii))
+                  if (firsttest) then               
+                  if (indic(iii).GT.ppbtab(iii)) then
+
+                     idecal = indic
+                     idecal(iii) = idecal(iii)-1
+                     SELECT CASE(nbdim)
+                     CASE (1)
+                        if (tempP%var%array1(idecal(1)
+     &                            ) == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif                     
+                     CASE (2)
+                        if (tempP%var%array2(idecal(1),
+     &            idecal(2)) == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif
+                     CASE (3)
+                        if (tempP%var%array3(idecal(1),
+     &            idecal(2),idecal(3)) 
+     &                               == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif  
+                     CASE (4)
+                        if (tempP%var%array4(idecal(1),
+     &            idecal(2),idecal(3),idecal(4)) 
+     &                               == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif     
+                     CASE (5)
+                        if (tempP%var%array5(idecal(1),
+     &            idecal(2),idecal(3),idecal(4),idecal(5)) 
+     &                               == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif  
+                     CASE (6)
+                        if (tempP%var%array6(idecal(1),
+     &            idecal(2),idecal(3),idecal(4),idecal(5),idecal(6)) 
+     &                               == Agrif_SpecialValue) then
+                           imin(iii) = imax(iii)
+                        endif                                                                                           
+                     END SELECT
+                  endif
+                  endif
+               endif            
+            enddo
+C
+            Res = 0.
+            Nbvals = 0
+C
+            SELECT CASE(nbdim)
+            CASE (1)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array1(ii)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+               enddo
+C
+            CASE (2)
+               do jj = imin(2),imax(2)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array2(ii,jj)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+               enddo  
+               enddo
+               
+            CASE (3)
+               do kk = imin(3),imax(3)
+               do jj = imin(2),imax(2)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array3(ii,jj,kk)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+                        enddo
+                  enddo  
+               enddo
+
+            CASE (4)
+               do ll = imin(4),imax(4)
+               do kk = imin(3),imax(3)
+               do jj = imin(2),imax(2)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array4(ii,jj,kk,ll)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+                              enddo
+                        enddo
+                  enddo  
+               enddo
+
+            CASE (5)
+               do mm = imin(5),imax(5)
+               do ll = imin(4),imax(4)
+               do kk = imin(3),imax(3)
+               do jj = imin(2),imax(2)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array5(ii,jj,kk,ll,mm)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+                                    enddo
+                              enddo
+                        enddo
+                  enddo  
+               enddo
+
+            CASE (6)
+               do nn = imin(6),imax(6)
+               do mm = imin(5),imax(5)
+               do ll = imin(4),imax(4)
+               do kk = imin(3),imax(3)
+               do jj = imin(2),imax(2)
+               do ii = imin(1),imax(1)
+                    ValParent = parent%var%array6(ii,jj,kk,ll,mm,nn)
+                    if ( ValParent .NE. Agrif_SpecialValue) then
+                        Res = Res + ValParent
+                        Nbvals = Nbvals + 1
+                    endif 
+                                          enddo
+                                    enddo
+                              enddo
+                        enddo
+                  enddo  
+               enddo
+
+            END SELECT
+C
+C
+            
+            if (Nbvals.GT.0) then
+              if (firsttest) then
+                   firsttest = .FALSE.
+                   i=1
+                   cycle
+              endif
+            SELECT CASE(nbdim)
+            CASE (1)              
+              tempP%var%array1(indic(1)) 
+     &           = Res/Nbvals
+            CASE (2)
+              tempP%var%array2(indic(1),
+     &                            indic(2)) = Res/Nbvals
+            CASE (3)
+              tempP%var%array3(indic(1),
+     &                            indic(2),indic(3)) = Res/Nbvals
+            CASE (4)
+              tempP%var%array4(indic(1),
+     &                            indic(2),indic(3),indic(4))
+     &                = Res/Nbvals
+            CASE (5)
+              tempP%var%array5(indic(1),
+     &                            indic(2),indic(3),indic(4),
+     &                   indic(5)) = Res/Nbvals
+            CASE (6)
+              tempP%var%array6(indic(1),
+     &                            indic(2),indic(3),indic(4),
+     &                           indic(5),indic(6)) = Res/Nbvals
+            END SELECT
+              exit
+            else
+               if (firsttest) exit
+               i = i + 1                      
+            endif
+          enddo            
+C     
+      End Subroutine CalculNewValTempP
+C
+C
+      End Module Agrif_Mask       
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmpp.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmpp.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modmpp.F	(revision 4536)
@@ -0,0 +1,553 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_mpp
+C
+      Module Agrif_mpp
+      Use Agrif_Types
+      Use Agrif_Arrays
+
+      Contains
+#ifdef AGRIF_MPI
+C
+      Subroutine Get_External_Data(tempC,tempCextend,pttruetab,
+     &   cetruetab,pttruetabwhole,cetruetabwhole,nbdim,memberin,
+     &   memberout,memberoutall1)
+
+      IMPLICIT NONE
+#include "mpif.h"
+      INTEGER :: nbdim
+      TYPE(Agrif_PVariable) :: tempC, tempCextend
+      INTEGER,DIMENSION(nbdim,0:Agrif_NbProcs-1)    :: pttruetab,
+     &                                                 cetruetab
+      INTEGER,DIMENSION(nbdim,0:Agrif_NbProcs-1)    :: pttruetabwhole,
+     &                                                 cetruetabwhole
+      INTEGER :: k,i,k2
+      LOGICAL :: sendtoproc(0:Agrif_Nbprocs-1)
+      INTEGER,DIMENSION(nbdim,0:Agrif_NbProcs-1)    :: imin,imax
+      LOGICAL :: memberin, memberout
+      INTEGER :: imintmp, imaxtmp,j,i1
+      INTEGER :: imin1,imax1
+      LOGICAL :: tochange,tochangebis
+      INTEGER,DIMENSION(nbdim,0:Agrif_NbProcs-1)    :: pttruetab2,
+     &                                                 cetruetab2
+      LOGICAL :: memberout1(1),memberoutall(0:Agrif_Nbprocs-1)
+      LOGICAL, OPTIONAL :: memberoutall1(0:Agrif_Nbprocs-1)
+      INTEGER :: code
+
+C pttruetab2 and cetruetab2 are modified arraysin order to always
+C send the most inner points
+
+        
+        IF (present(memberoutall1)) THEN
+        memberoutall = memberoutall1
+        ELSE
+         memberout1(1) = memberout
+
+         CALL MPI_ALLGATHER(memberout1,1,MPI_LOGICAL,memberoutall,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+        ENDIF
+         pttruetab2(:,Agrif_Procrank) = pttruetab(:,Agrif_Procrank)
+         cetruetab2(:,Agrif_Procrank) = cetruetab(:,Agrif_Procrank)
+         do k2=0,Agrif_Nbprocs-1
+            do i=1,nbdim
+
+           tochangebis=.TRUE.
+           DO i1=1,nbdim
+            IF (i .NE. i1) THEN
+              IF ((pttruetab(i1,Agrif_Procrank).NE.pttruetab(i1,k2)).OR.
+     &          (cetruetab(i1,Agrif_Procrank).NE.cetruetab(i1,k2))) THEN
+                   tochangebis = .FALSE.
+               EXIT
+              ENDIF
+             ENDIF
+           ENDDO
+
+           IF (tochangebis) THEN
+
+
+          imin1 = max(pttruetab(i,Agrif_Procrank),
+     &                    pttruetab(i,k2))
+          imax1 = min(cetruetab(i,Agrif_Procrank),
+     &                    cetruetab(i,k2))
+
+C Always send the most interior points
+
+           tochange = .false.
+           IF (cetruetab(i,Agrif_Procrank)> cetruetab(i,k2)) THEN
+
+           DO j=imin1,imax1
+             IF ((cetruetab(i,k2)-j) >
+     &             (j-pttruetab(i,Agrif_Procrank))) THEN
+             imintmp = j+1
+             tochange = .TRUE.
+             ELSE
+              EXIT
+             ENDIF
+          ENDDO
+          ENDIF
+
+           if (tochange) then
+C
+              pttruetab2(i,Agrif_Procrank) = imintmp
+C
+          endif
+
+           tochange = .FALSE.
+           imaxtmp=0
+           IF (pttruetab(i,Agrif_Procrank) < pttruetab(i,k2)) THEN
+          DO j=imax1,imin1,-1
+            IF ((j-pttruetab(i,k2)) >
+     &             (cetruetab(i,Agrif_Procrank)-j)) THEN
+             imaxtmp = j-1
+             tochange = .TRUE.
+            ELSE
+             EXIT
+            ENDIF
+          ENDDO
+
+          ENDIF
+
+                    if (tochange) then
+C
+              cetruetab2(i,Agrif_Procrank) = imaxtmp
+C
+          endif
+C
+
+          ENDIF
+           enddo
+         enddo
+
+
+       do k = 0,Agrif_NbProcs-1
+C
+        sendtoproc(k) = .true.
+C
+        do i = 1,nbdim
+C
+          imin(i,k) = max(pttruetab2(i,Agrif_Procrank),
+     &                    pttruetabwhole(i,k))
+          imax(i,k) = min(cetruetab2(i,Agrif_Procrank),
+     &                    cetruetabwhole(i,k))
+C
+          if (imin(i,k) > imax(i,k)) then
+C
+              sendtoproc(k) = .false.
+C
+          endif
+C
+        enddo
+        IF (.NOT.memberoutall(k)) THEN
+           sendtoproc(k) = .FALSE.
+        ENDIF
+C
+      enddo
+
+
+c       IF (.NOT.memberin) sendtoproc = .FALSE.
+
+      IF (memberout) THEN
+      Call Agrif_nbdim_allocation(tempCextend%var,
+     &                 pttruetabwhole(:,Agrif_ProcRank),
+     &                 cetruetabwhole(:,Agrif_ProcRank),nbdim)
+      call Agrif_nbdim_Full_VarEQreal(tempCextend%var,0.,nbdim)
+      ENDIF
+
+      IF (sendtoproc(Agrif_ProcRank)) THEN
+           Call Agrif_nbdim_VarEQvar(tempCextend%var,
+     &                               imin(:,Agrif_Procrank),
+     &                               imax(:,Agrif_Procrank),
+     &                               tempC%var,
+     &                               imin(:,Agrif_Procrank),
+     &                               imax(:,Agrif_Procrank),
+     &                               nbdim)
+      ENDIF
+
+      Call Exchangesamelevel(sendtoproc,nbdim,imin,imax,tempC,
+     &     tempCextend)
+
+      End Subroutine Get_External_Data
+
+       Subroutine ExchangeSameLevel(sendtoproc,nbdim,imin,imax,
+     &          tempC,tempCextend)
+      Implicit None
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1) :: imin,imax
+      INTEGER,DIMENSION(nbdim,2,0:Agrif_Nbprocs-1) :: iminmax_temp
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1) :: imin_recv,imax_recv
+      TYPE(Agrif_PVARIABLE) :: tempC,tempCextend
+      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1)       :: sendtoproc
+      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1)       :: recvfromproc
+      LOGICAL                                    :: res
+      TYPE(AGRIF_PVARIABLE), SAVE                      :: temprecv
+
+#include "mpif.h"
+          INTEGER :: i,k
+          INTEGER :: etiquette = 100
+          INTEGER :: code, datasize
+          INTEGER,DIMENSION(MPI_STATUS_SIZE)   :: statut
+
+
+      do k = 0,Agrif_ProcRank-1
+C
+C
+            Call MPI_SEND(sendtoproc(k),1,MPI_LOGICAL,k,etiquette,
+     &                    MPI_COMM_WORLD,code)
+C
+            if (sendtoproc(k)) then
+C
+                iminmax_temp(:,1,k) = imin(:,k)
+                iminmax_temp(:,2,k) = imax(:,k)
+
+                Call MPI_SEND(iminmax_temp(:,:,k),
+     &                        2*nbdim,MPI_INTEGER,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+C
+                datasize = 1
+C
+                do i = 1,nbdim
+C
+                  datasize = datasize * (imax(i,k)-imin(i,k)+1)
+C
+                enddo
+C
+                SELECT CASE(nbdim)
+                CASE(1)
+                   Call MPI_SEND(tempC%var%array1(
+     &                        imin(1,k):imax(1,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(2)
+                   Call MPI_SEND(tempC%var%array2(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(3)
+                  Call Agrif_Send_3Darray(tempC%var%array3,
+     &             lbound(tempC%var%array3),imin(:,k),imax(:,k),k)
+                CASE(4)
+                   Call MPI_SEND(tempC%var%array4(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(5)
+                   Call MPI_SEND(tempC%var%array5(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(6)
+                   Call MPI_SEND(tempC%var%array6(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k),
+     &                        imin(6,k):imax(6,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                END SELECT
+C
+            endif
+
+C
+      enddo
+C
+C
+C     Reception from others processors of the necessary part of the parent grid
+      do k = Agrif_ProcRank+1,Agrif_Nbprocs-1
+C
+C
+            Call MPI_RECV(res,1,MPI_LOGICAL,k,etiquette,
+     &                    MPI_COMM_WORLD,statut,code)
+C
+            recvfromproc(k) = res
+
+C
+            if (recvfromproc(k)) then
+C
+                Call MPI_RECV(iminmax_temp(:,:,k),
+     &                        2*nbdim,MPI_INTEGER,k,etiquette,
+     &                        MPI_COMM_WORLD,statut,code)
+
+                imin_recv(:,k) = iminmax_temp(:,1,k)
+                imax_recv(:,k) = iminmax_temp(:,2,k)
+
+                datasize = 1
+C
+                do i = 1,nbdim
+C
+                datasize = datasize * (imax_recv(i,k)-imin_recv(i,k)+1)
+C
+                enddo
+
+             IF (.Not.Associated(temprecv%var)) allocate(temprecv%var)
+             call Agrif_nbdim_allocation(temprecv%var,imin_recv(:,k),
+     &   imax_recv(:,k),nbdim)
+            SELECT CASE(nbdim)
+            CASE(1)
+              Call MPI_RECV(temprecv%var%array1,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(2)
+              Call MPI_RECV(temprecv%var%array2,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(3)
+              Call MPI_RECV(temprecv%var%array3,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+
+            CASE(4)
+              Call MPI_RECV(temprecv%var%array4,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(5)
+              Call MPI_RECV(temprecv%var%array5,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(6)
+              Call MPI_RECV(temprecv%var%array6,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+       END SELECT
+            endif
+            
+            Call MPI_SEND(sendtoproc(k),1,MPI_LOGICAL,k,etiquette,
+     &                    MPI_COMM_WORLD,code)
+C
+            if (sendtoproc(k)) then
+C
+                iminmax_temp(:,1,k) = imin(:,k)
+                iminmax_temp(:,2,k) = imax(:,k)
+
+                Call MPI_SEND(iminmax_temp(:,:,k),
+     &                        2*nbdim,MPI_INTEGER,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+C
+                SELECT CASE(nbdim)
+                CASE(1)
+                datasize=SIZE(tempC%var%array1(
+     &                        imin(1,k):imax(1,k)))
+                   Call MPI_SEND(tempC%var%array1(
+     &                        imin(1,k):imax(1,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(2)
+                datasize=SIZE(tempC%var%array2(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k)))
+                   Call MPI_SEND(tempC%var%array2(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(3)
+                datasize=SIZE(tempC%var%array3(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k)))
+                   Call MPI_SEND(tempC%var%array3(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(4)
+                datasize=SIZE(tempC%var%array4(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k)))
+                   Call MPI_SEND(tempC%var%array4(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(5)
+                datasize=SIZE(tempC%var%array5(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k)))
+                   Call MPI_SEND(tempC%var%array5(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                CASE(6)
+                datasize=SIZE(tempC%var%array6(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k),
+     &                        imin(6,k):imax(6,k)))
+                   Call MPI_SEND(tempC%var%array6(
+     &                        imin(1,k):imax(1,k),
+     &                        imin(2,k):imax(2,k),
+     &                        imin(3,k):imax(3,k),
+     &                        imin(4,k):imax(4,k),
+     &                        imin(5,k):imax(5,k),
+     &                        imin(6,k):imax(6,k)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+                END SELECT
+C
+            endif            
+            
+            if (recvfromproc(k)) then
+                        
+            Call where_valtabtotab_mpi(tempCextend%var,
+     &             temprecv%var,imin_recv(:,k),imax_recv(:,k),0.,nbdim)
+     
+                Call Agrif_nbdim_deallocation(temprecv%var,nbdim)
+C                deallocate(temprecv%var)
+
+            endif
+
+C
+      enddo
+
+C
+C
+C     Reception from others processors of the necessary part of the parent grid
+      do k = Agrif_ProcRank-1,0,-1
+C
+C
+            Call MPI_RECV(res,1,MPI_LOGICAL,k,etiquette,
+     &                    MPI_COMM_WORLD,statut,code)
+C
+            recvfromproc(k) = res
+
+C
+            if (recvfromproc(k)) then
+C
+                Call MPI_RECV(iminmax_temp(:,:,k),
+     &                        2*nbdim,MPI_INTEGER,k,etiquette,
+     &                        MPI_COMM_WORLD,statut,code)
+
+C                imin_recv(:,k) = iminmax_temp(:,1,k)
+C                imax_recv(:,k) = iminmax_temp(:,2,k)
+
+C                datasize = 1
+C
+C                do i = 1,nbdim
+C
+C                datasize = datasize * (imax_recv(i,k)-imin_recv(i,k)+1)
+C
+C                enddo
+             IF (.Not.Associated(temprecv%var)) allocate(temprecv%var)
+             call Agrif_nbdim_allocation(temprecv%var,
+     &   iminmax_temp(:,1,k),iminmax_temp(:,2,k),nbdim)
+            SELECT CASE(nbdim)
+            CASE(1)
+              datasize=SIZE(temprecv%var%array1)
+              Call MPI_RECV(temprecv%var%array1,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(2)
+              datasize=SIZE(temprecv%var%array2)
+              Call MPI_RECV(temprecv%var%array2,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(3)
+              datasize=SIZE(temprecv%var%array3)
+              Call MPI_RECV(temprecv%var%array3,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+
+            CASE(4)
+              datasize=SIZE(temprecv%var%array4)
+              Call MPI_RECV(temprecv%var%array4,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(5)
+              datasize=SIZE(temprecv%var%array5)
+              Call MPI_RECV(temprecv%var%array5,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+            CASE(6)
+              datasize=SIZE(temprecv%var%array6)
+              Call MPI_RECV(temprecv%var%array6,
+     &               datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &               MPI_COMM_WORLD,statut,code)
+          END SELECT
+            
+            Call where_valtabtotab_mpi(tempCextend%var,
+     &             temprecv%var,iminmax_temp(:,1,k),iminmax_temp(:,2,k)
+     &            ,0.,nbdim)
+     
+                Call Agrif_nbdim_deallocation(temprecv%var,nbdim)
+C                deallocate(temprecv%var)
+            endif
+
+C
+      enddo
+
+          End Subroutine ExchangeSamelevel
+
+          Subroutine Agrif_Send_3Darray(tab3D,bounds,imin,imax,k)
+          integer, dimension(3) :: bounds, imin, imax
+          real,dimension(bounds(1):,bounds(2):,bounds(3):),target
+     &                             :: tab3D
+          integer :: k
+          integer :: etiquette = 100
+          integer :: datasize, code
+#include "mpif.h"   
+
+          datasize = SIZE(tab3D(
+     &                       imin(1):imax(1),
+     &                        imin(2):imax(2),
+     &                        imin(3):imax(3)))
+       
+                   Call MPI_SEND(tab3D(
+     &                        imin(1):imax(1),
+     &                        imin(2):imax(2),
+     &                        imin(3):imax(3)),
+     &                        datasize,MPI_DOUBLE_PRECISION,k,etiquette,
+     &                        MPI_COMM_WORLD,code)
+     
+         End Subroutine Agrif_Send_3Darray
+
+#else
+      Subroutine Agrif_mpp_empty()
+      End Subroutine Agrif_mpp_empty
+#endif
+
+      End Module Agrif_mpp
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modsauv.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modsauv.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modsauv.F	(revision 4536)
@@ -0,0 +1,838 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Save  
+C
+      Module Agrif_Save 
+C
+CCC   Description:   
+CCC   Module for the initialization by copy of the grids created by clustering.
+C
+C     Modules used:
+C      
+      Use Agrif_Types
+      Use Agrif_Link
+      Use Agrif_Arrays
+C
+      IMPLICIT NONE
+C
+      Contains
+C     Definition of procedures contained in this module.
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Free_data_before
+C     **************************************************************************
+C
+      Subroutine Agrif_Free_data_before(Agrif_Gr)
+C
+CCC   Description:
+CCC   
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      TYPE(Agrif_Grid),pointer   :: Agrif_Gr ! Pointer on the current grid
+      INTEGER i
+C
+C   
+      do i = 1 , AGRIF_NbVariables
+         if ( .NOT. Agrif_Mygrid % tabvars(i) % var % restaure) then
+C 
+            if (associated(Agrif_Gr%tabvars(i)%var%array1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array6)
+            endif
+C
+            if (associated(Agrif_Gr%tabvars(i)%var%darray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray6)
+            endif
+C
+            if (associated(Agrif_Gr%tabvars(i)%var%larray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray6)
+            endif
+C
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray6)
+            endif
+C
+            if (associated(Agrif_Gr%tabvars(i)%var%carray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%carray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%carray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%carray2)
+            endif
+C
+            if (associated(Agrif_Gr%tabvars(i)%var%oldvalues2D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%oldvalues2D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%interpIndex)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%interpIndex)
+            endif
+            
+            if (associated(Agrif_Gr%tabvars(i)%var%posvar)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%posvar)
+            endif     
+            
+            if (associated(Agrif_Gr%tabvars(i)%var%interptab)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%interptab)
+            endif  
+                             
+C
+            Deallocate(Agrif_Gr%tabvars(i)%var)
+C 
+        endif
+      enddo
+C
+C 
+C
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+         if ( Agrif_Probdim .EQ. 1 ) Deallocate(Agrif_Gr%tabpoint1D)
+         if ( Agrif_Probdim .EQ. 2 ) Deallocate(Agrif_Gr%tabpoint2D)
+         if ( Agrif_Probdim .EQ. 3 ) Deallocate(Agrif_Gr%tabpoint3D)
+      endif
+C          
+      Return
+C
+C
+      End Subroutine Agrif_Free_data_before
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Free_data_after
+C     **************************************************************************
+C      
+      Subroutine Agrif_Free_data_after(Agrif_Gr)
+C
+CCC   Description:
+CCC   
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+C
+      
+C
+C     Pointer argument    
+      TYPE(Agrif_Grid),pointer   :: Agrif_Gr  ! Pointer on the current grid
+      INTEGER i
+C
+C      
+      do i = 1 , AGRIF_NbVariables
+         if ( Agrif_Mygrid % tabvars(i) % var % restaure) then
+C 
+            if (associated(Agrif_Gr%tabvars(i)%var%array1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%array6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%array6)
+            endif
+!
+            if (associated(Agrif_Gr%tabvars(i)%var%darray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%darray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%darray6)
+            endif
+!
+            if (associated(Agrif_Gr%tabvars(i)%var%larray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%larray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%larray6)
+            endif
+!
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray2)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray3)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray3)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray4)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray4)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray5)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray5)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%iarray6)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%iarray6)
+            endif
+!
+            if (associated(Agrif_Gr%tabvars(i)%var%carray1)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%carray1)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%carray2)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%carray2)
+            endif
+!
+            if (associated(Agrif_Gr%tabvars(i)%var%oldvalues2D)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%oldvalues2D)
+            endif
+            if (associated(Agrif_Gr%tabvars(i)%var%interpIndex)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%interpIndex)
+            endif
+            
+            if (associated(Agrif_Gr%tabvars(i)%var%posvar)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%posvar)
+            endif     
+            
+            if (associated(Agrif_Gr%tabvars(i)%var%interptab)) then
+               Deallocate(Agrif_Gr%tabvars(i)%var%interptab)
+            endif              
+!
+            Deallocate(Agrif_Gr%tabvars(i)%var)
+! 
+         endif
+      enddo
+C
+C      
+      Return
+C
+C
+      End Subroutine Agrif_Free_data_after      
+C
+C
+CC    **************************************************************************
+CCC   Subroutine AGRIF_CopyFromold_All
+C     **************************************************************************
+C
+      Recursive Subroutine AGRIF_CopyFromold_All(g,oldchildgrids)
+C
+CCC   Description:
+CCC   Routine called in the Agrif_Init_Hierarchy procedure 
+C       (Agrif_Clustering module). 
+C
+CC    Method:        
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      TYPE(AGRIF_grid),pointer   :: g ! Pointer on the current grid
+      TYPE(AGRIF_pgrid),pointer   :: oldchildgrids
+C
+C     Local pointer
+      TYPE(AGRIF_pgrid),pointer  :: parcours ! Pointer for the recursive 
+                                             ! procedure 
+      REAL g_eps,eps,oldgrid_eps
+      INTEGER :: out
+      INTEGER :: iii
+C
+      out = 0
+C                                                                           
+      parcours => oldchildgrids  
+C
+      do while (associated(parcours))
+C 
+        if ((.NOT. g % fixed) .AND. (parcours % gr %oldgrid)) then
+C        
+            g_eps = huge(1.)
+            oldgrid_eps = huge(1.)
+            do iii = 1 , Agrif_Probdim
+               g_eps = min(g_eps,g % Agrif_d(iii))
+               oldgrid_eps = min(oldgrid_eps,
+     &                       parcours % gr % Agrif_d(iii))
+            enddo
+C
+            eps = min(g_eps,oldgrid_eps)/100.                  
+C
+            do iii = 1 , Agrif_Probdim
+
+               if (g % Agrif_d(iii) .LT. 
+     &             (parcours % gr % Agrif_d(iii) - eps)) then
+C            
+                   parcours => parcours % next
+C            
+                   out = 1
+C   
+                   Exit
+C             
+               endif
+C      
+            enddo
+        if ( out .EQ. 1 ) Cycle
+C
+            Call AGRIF_CopyFromOld(g,parcours%gr)
+C
+        endif
+C                     
+        Call Agrif_CopyFromold_All
+     &             (g, parcours % gr % child_grids)
+C        
+        parcours => parcours % next
+C        
+      enddo
+C
+C     
+      Return      
+C
+C
+      End Subroutine AGRIF_CopyFromold_All
+C
+C
+C      
+C     **************************************************************************
+CCC   Subroutine Agrif_CopyFromold
+C     **************************************************************************
+C      
+      Subroutine Agrif_CopyFromold(Agrif_New_Gr,Agrif_Old_Gr)
+C
+CCC   Description:
+CCC   Call to the Agrif_Copy procedure.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      TYPE(Agrif_Grid),Pointer   :: Agrif_New_Gr  ! Pointer on the current grid
+      TYPE(Agrif_Grid),Pointer :: Agrif_Old_Gr    ! Pointer on an old grid
+      INTEGER :: i
+C
+C      
+      do i = 1 , AGRIF_NbVariables
+         if ( Agrif_Mygrid % tabvars(i) % var % restaure ) then
+C
+            Call Agrif_Copy(Agrif_New_Gr,Agrif_Old_Gr,
+     &           Agrif_New_Gr % tabvars(i),
+     &           Agrif_Old_Gr % tabvars(i))
+C
+        endif
+      enddo
+
+C      
+C            
+      Return
+C
+C      
+      End Subroutine Agrif_CopyFromold
+C
+C
+CC
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Copy
+C     **************************************************************************
+C      
+      Subroutine Agrif_Copy(Agrif_New_Gr,Agrif_Old_Gr,New_Var,Old_Var)
+C     
+CCC   Description:
+CCC   Sets arguments of the Agrif_UpdatenD procedures, n being the number of 
+CCC   DIMENSION of the grid variable.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+      
+C
+C     Pointer argument    
+      TYPE(Agrif_Grid),Pointer   :: Agrif_New_Gr   ! Pointer on the current grid
+      TYPE(Agrif_Grid), Pointer :: Agrif_Old_Gr    ! Pointer on an old grid
+      TYPE(Agrif_Pvariable) :: New_Var, Old_Var
+      INTEGER :: nbdim                  ! Number of dimensions of the current 
+                                        ! grid      
+      INTEGER,DIMENSION(6) :: pttabnew  ! Indexes of the first point in the 
+                                        ! domain
+      INTEGER,DIMENSION(6) :: petabnew  ! Indexes of the first point in the 
+                                        ! domain
+      INTEGER,DIMENSION(6) :: pttabold  ! Indexes of the first point in the 
+                                        ! domain
+      INTEGER,DIMENSION(6) :: petabold  ! Indexes of the first point in the 
+                                        ! domain
+      INTEGER,DIMENSION(6) :: nbtabold  ! Number of cells in each direction
+      
+      INTEGER,DIMENSION(6) :: nbtabnew  ! Number of cells in each direction   
+      TYPE(AGRIF_Variable), Pointer :: root ! Pointer on the variable of the 
+                                            ! root grid
+      REAL, DIMENSION(6) :: snew,sold
+      REAL, DIMENSION(6) :: dsnew,dsold                              
+      REAL :: eps
+      INTEGER :: n
+C
+C  
+      root => New_Var % var % root_var 
+C      
+      nbdim = root % nbdim
+C         
+      do n=1,nbdim
+C  
+        select case(root % interptab(n))
+C        
+        case('x')                
+C
+          pttabnew(n) = root % point(1)
+C        
+          pttabold(n) = root % point(1)
+C        
+          snew(n) = Agrif_New_Gr % Agrif_x(1)
+C
+          sold(n) = Agrif_Old_Gr % Agrif_x(1) 
+C        
+          dsnew(n) = Agrif_New_Gr % Agrif_d(1)
+C
+          dsold(n) = Agrif_Old_Gr % Agrif_d(1)
+C                      
+          if (root % posvar(n) .EQ. 1) then
+C          
+              petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(1)
+C          
+              petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(1)         
+C        
+            else
+C          
+              petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(1) - 1
+C          
+              petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(1) - 1
+C
+              snew(n) = snew(n) + dsnew(n)/2.
+C
+              sold(n) = sold(n) + dsold(n)/2.
+C        
+          endif           
+C        
+        case('y')
+C        
+          pttabnew(n) = root % point(2)
+C        
+          pttabold(n) = root % point(2)
+C        
+          snew(n) = Agrif_New_Gr % Agrif_x(2)
+C        
+          sold(n) = Agrif_Old_Gr % Agrif_x(2)
+C        
+          dsnew(n) = Agrif_New_Gr % Agrif_d(2)
+C        
+          dsold(n) = Agrif_Old_Gr % Agrif_d(2)
+C                
+          if (root % posvar(n) .EQ. 1) then
+C        
+              petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(2)
+C          
+              petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(2)         
+C        
+            else
+C          
+              petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(2) - 1
+C          
+              petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(2) - 1
+C
+              snew(n) = snew(n) + dsnew(n)/2.
+C
+              sold(n) = sold(n) + dsold(n)/2.                    
+C        
+          endif 
+C        
+        case('z')
+C        
+          pttabnew(n) = root % point(3)
+C        
+          pttabold(n) = root % point(3)
+C        
+          snew(n) = Agrif_New_Gr % Agrif_x(3)
+C        
+          sold(n) = Agrif_Old_Gr % Agrif_x(3)
+C        
+          dsnew(n) = Agrif_New_Gr % Agrif_d(3)
+C        
+          dsold(n) = Agrif_Old_Gr % Agrif_d(3)
+C                
+          if (root % posvar(n) .EQ. 1) then
+C        
+              petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(3)
+C          
+              petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(3)         
+C        
+            else
+C          
+             petabnew(n) = pttabnew(n) + Agrif_New_Gr % nb(3) - 1
+C          
+             petabold(n) = pttabold(n) + Agrif_Old_Gr % nb(3) - 1
+C
+             snew(n) = snew(n) + dsnew(n)/2.
+C
+             sold(n) = sold(n) + dsold(n)/2.                   
+C        
+          endif
+C          
+        case('N')
+C        
+          Call Agrif_nbdim_Get_bound(New_Var%var,
+     &                           pttabnew(n),petabnew(n),
+     &                           n,nbdim)
+C        
+          pttabold(n) = pttabnew(n)
+C      
+          petabold(n) = petabnew(n)
+C              
+          snew(n) = 0.
+C      
+          sold(n) = 0. 
+C      
+          dsnew(n) = 1.
+C      
+          dsold(n) = 1.
+C        
+        end select
+C      
+      enddo
+C      
+      do n = 1,nbdim
+C      
+        nbtabnew(n) = petabnew(n) - pttabnew(n)
+C      
+        nbtabold(n) = petabold(n) - pttabold(n)      
+C 
+      enddo      
+C
+      eps = min(minval(dsnew(1:nbdim)),minval(dsold(1:nbdim)))
+C     
+      eps = eps/100.      
+C      
+      do n = 1,nbdim
+C      
+        if (snew(n) .GT. (sold(n)+dsold(n)*nbtabold(n)+eps)) Return
+C      
+        if ((snew(n)+dsnew(n)*nbtabnew(n)-eps) .LT. sold(n)) Return
+C      
+      enddo
+C            
+C
+      Call AGRIF_CopynD
+     &        (New_Var,Old_Var,pttabold,petabold,pttabnew,petabnew,
+     &         sold,snew,dsold,dsnew,nbdim) 
+C      
+C 
+      Return
+C      
+C
+      End Subroutine Agrif_Copy
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_CopynD
+C     **************************************************************************
+C      
+      Subroutine Agrif_CopynD(New_Var,Old_Var,pttabold,petabold,
+     &                        pttabnew,petabnew,sold,snew,dsold,
+     &                        dsnew,nbdim)
+C     
+CCC   Description:
+CCC   Copy of the nD New_Var variable from the nD Old_Var variable.
+C
+CC    Method:
+CC            
+C
+C     Declarations:
+C
+      
+C
+      INTEGER :: nbdim
+      TYPE(Agrif_Pvariable) :: New_Var, Old_Var     
+      INTEGER,DIMENSION(nbdim) :: pttabnew 
+      INTEGER,DIMENSION(nbdim) :: petabnew
+      INTEGER,DIMENSION(nbdim) :: pttabold
+      INTEGER,DIMENSION(nbdim) :: petabold      
+      REAL, DIMENSION(nbdim) :: snew,sold
+      REAL, DIMENSION(nbdim) :: dsnew,dsold 
+C
+      INTEGER :: i,j,k,l,m,n,i0,j0,k0,l0,m0,n0
+C
+      REAL, DIMENSION(nbdim) :: dim_gmin,dim_gmax
+      REAL, DIMENSION(nbdim) :: dim_newmin,dim_newmax
+      REAL, DIMENSION(nbdim) :: dim_min
+      INTEGER, DIMENSION(nbdim) :: ind_gmin,ind_newmin
+      INTEGER, DIMENSION(nbdim) ::  ind_newmax
+C               
+C
+      do i = 1,nbdim
+C      
+        dim_gmin(i) = sold(i)
+        dim_gmax(i) = sold(i) + (petabold(i)-pttabold(i)) * dsold(i)
+C 
+        dim_newmin(i) = snew(i)
+        dim_newmax(i) = snew(i) + (petabnew(i)-pttabnew(i)) * dsnew(i)
+C
+      enddo         
+C
+      do i = 1,nbdim
+C  
+        if (dim_gmax(i) .LT. dim_newmin(i)) Return
+C      
+        if (dim_gmin(i) .GT. dim_newmax(i)) Return
+C
+      enddo
+C
+C
+      do i = 1,nbdim
+C 
+        ind_newmin(i) = pttabnew(i) - floor(-(max(dim_gmin(i),
+     &                      dim_newmin(i))-dim_newmin(i))/dsnew(i)) 
+C      
+        dim_min(i) = snew(i) + (ind_newmin(i)-pttabnew(i))*dsnew(i)
+C      
+        ind_gmin(i) = pttabold(i) + nint((dim_min(i)-
+     &                dim_gmin(i))/dsold(i))      
+C
+        ind_newmax(i) = pttabnew(i) 
+     &                  + int((min(dim_gmax(i),dim_newmax(i))
+     &                         -dim_newmin(i))/dsnew(i))
+C
+      enddo 
+C
+C
+C
+      SELECT CASE (nbdim)
+      CASE (1)
+         i0 = ind_gmin(1)
+         do i = ind_newmin(1),ind_newmax(1)
+            New_Var % var % array1(i) =
+     &      Old_Var % var % array1(i0)
+            New_Var % var % restore1D(i) = 1   
+         i0 = i0 + int(dsnew(1)/dsold(1))
+         enddo
+      CASE (2)
+        i0 = ind_gmin(1)
+        do i = ind_newmin(1),ind_newmax(1)
+        j0 = ind_gmin(2)
+        do j = ind_newmin(2),ind_newmax(2)
+           New_Var % var % array2(i,j) =
+     &            Old_Var % var % array2(i0,j0)
+           New_Var % var % restore2D(i,j) = 1
+               j0 = j0 + int(dsnew(2)/dsold(2))
+        enddo
+        i0 = i0 + int(dsnew(1)/dsold(1))
+        enddo
+      CASE (3)
+        i0 = ind_gmin(1)
+        do i = ind_newmin(1),ind_newmax(1)
+        j0 = ind_gmin(2)
+        do j = ind_newmin(2),ind_newmax(2)
+        k0 = ind_gmin(3)
+        do k = ind_newmin(3),ind_newmax(3)
+           New_Var % var % array3(i,j,k) =
+     &                  Old_Var % var % array3(i0,j0,k0)
+           New_Var % var % restore3D(i,j,k) = 1   
+                     k0 = k0 + int(dsnew(3)/dsold(3))
+        enddo
+        j0 = j0 + int(dsnew(2)/dsold(2))
+        enddo
+        i0 = i0 + int(dsnew(1)/dsold(1))
+        enddo
+      CASE (4)
+        i0 = ind_gmin(1)
+        do i = ind_newmin(1),ind_newmax(1)
+        j0 = ind_gmin(2)
+        do j = ind_newmin(2),ind_newmax(2)
+        k0 = ind_gmin(3)
+        do k = ind_newmin(3),ind_newmax(3)
+        l0 = ind_gmin(4)
+        do l = ind_newmin(4),ind_newmax(4) 
+           New_Var % var % array4(i,j,k,l) =
+     &                        Old_Var % var % array4(i0,j0,k0,l0)
+           New_Var % var % restore4D(i,j,k,l) = 1   
+        l0 = l0 + int(dsnew(4)/dsold(4))
+        enddo
+        k0 = k0 + int(dsnew(3)/dsold(3))
+        enddo
+        j0 = j0 + int(dsnew(2)/dsold(2))
+        enddo
+        i0 = i0 + int(dsnew(1)/dsold(1))
+        enddo
+      CASE (5)
+        i0 = ind_gmin(1)
+        do i = ind_newmin(1),ind_newmax(1)
+        j0 = ind_gmin(2)
+        do j = ind_newmin(2),ind_newmax(2)
+        k0 = ind_gmin(3)
+        do k = ind_newmin(3),ind_newmax(3)
+        l0 = ind_gmin(4)
+        do l = ind_newmin(4),ind_newmax(4) 
+        m0 = ind_gmin(5)
+        do m = ind_newmin(5),ind_newmax(5)
+           New_Var % var % array5(i,j,k,l,m) =
+     &                        Old_Var % var % array5(i0,j0,k0,l0,m0)
+           New_Var % var % restore5D(i,j,k,l,m) = 1
+        m0 = m0 + int(dsnew(5)/dsold(5)) 
+        enddo
+        l0 = l0 + int(dsnew(4)/dsold(4))
+        enddo
+        k0 = k0 + int(dsnew(3)/dsold(3))
+        enddo
+        j0 = j0 + int(dsnew(2)/dsold(2))
+        enddo
+        i0 = i0 + int(dsnew(1)/dsold(1))
+        enddo
+      CASE (6)
+        i0 = ind_gmin(1)
+        do i = ind_newmin(1),ind_newmax(1)
+        j0 = ind_gmin(2)
+        do j = ind_newmin(2),ind_newmax(2)
+        k0 = ind_gmin(3)
+        do k = ind_newmin(3),ind_newmax(3)
+        l0 = ind_gmin(4)
+        do l = ind_newmin(4),ind_newmax(4) 
+        m0 = ind_gmin(5)
+        do m = ind_newmin(5),ind_newmax(5)
+        n0 = ind_gmin(6)
+        do n = ind_newmin(6),ind_newmax(6)
+           New_Var % var % array6(i,j,k,l,m,n) =
+     &                        Old_Var % var % array6(i0,j0,k0,l0,m0,n0)
+           New_Var % var % restore6D(i,j,k,l,m,n) = 1
+        n0 = n0 + int(dsnew(6)/dsold(6)) 
+        enddo
+        m0 = m0 + int(dsnew(5)/dsold(5)) 
+        enddo
+        l0 = l0 + int(dsnew(4)/dsold(4))
+        enddo
+        k0 = k0 + int(dsnew(3)/dsold(3))
+        enddo
+        j0 = j0 + int(dsnew(2)/dsold(2))
+        enddo
+        i0 = i0 + int(dsnew(1)/dsold(1))
+        enddo
+      END SELECT
+C           
+      Return
+C
+C
+      End Subroutine Agrif_CopynD                    
+C
+C
+C
+      End module Agrif_Save
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modtypes.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modtypes.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modtypes.F	(revision 4536)
@@ -0,0 +1,419 @@
+C     Agrif (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place-Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_types  
+C
+      Module Agrif_types 
+C
+CCC   Description:
+CCC   Definition of data types used in Agrif, of several variables and
+C        PARAMETERs.     
+C
+      IMPLICIT NONE
+      
+C     Maximum refinement ratio
+
+      INTEGER, PARAMETER :: Agrif_MaxRaff = 7      
+C
+C     **************************************************************************
+CCC   TYPE Agrif_LRECTANGLE
+C     **************************************************************************
+C
+CCC   Description:
+CCC   Data TYPE allowing a grid to reach a grid on the same level or its child
+CCC   grids.
+C
+      TYPE Agrif_lrectangle  
+           TYPE(Agrif_rectangle) , Pointer :: r    ! to reach a child grid
+           TYPE(Agrif_lrectangle), Pointer :: next ! to reach a grid on the 
+                                                   !    same level
+      End TYPE Agrif_lrectangle  
+C
+C     **************************************************************************
+CCC   TYPE Agrif_RECTANGLE: 
+C     **************************************************************************
+C
+CCC   Description:
+CCC   Data TYPE to define several CHARACTERistics of a grid (number,position,
+CCC   time and space refinement factors,...). 
+C
+      TYPE Agrif_rectangle
+           INTEGER                         :: number      ! Number of the grid
+           ! Number of child grids 
+           INTEGER                         :: nbgridchild 
+           ! Minimal position in the x,y and z direction
+           INTEGER, DIMENSION(3)           :: imin        
+           ! Maximal position in the x,y and z direction 
+           INTEGER, DIMENSION(3)           :: imax 
+           ! Space refinement factor in the x,y and z direction  
+           INTEGER, DIMENSION(3)           :: spaceref    
+           ! Time refinement factor in the x,y and z direction
+           INTEGER, DIMENSION(3)           :: timeref     
+           ! Pointer to reach a grid on  the same level or a child grid
+           TYPE(Agrif_lrectangle), Pointer :: childgrids  
+      End TYPE Agrif_rectangle  
+C
+C
+C
+C     **************************************************************************
+CCC   TYPE Agrif_PGrid
+C     **************************************************************************
+C
+CCC   Description:
+CCC   Data TYPE to go over the grid hierarchy (used for the creation of this 
+CCC   grid hierarchy and during the time integration).
+C 
+      TYPE Agrif_pgrid  
+           ! allows to reach a child grid  
+           TYPE(Agrif_grid) , Pointer :: gr
+           ! allows to reach the grids of the same level 
+           TYPE(Agrif_pgrid), Pointer :: next 
+      End TYPE Agrif_pgrid 
+C
+C
+C
+C     **************************************************************************
+CCC   TYPE Agrif_PVariable
+C     **************************************************************************
+C
+CCC   Description:
+CCC   Data TYPE to define a grid variable.
+C
+      TYPE Agrif_PVariable 
+           ! This field allows to get the various CHARACTERistics 
+           !   of the variable (defined by the Agrif_Variable data TYPE)
+           TYPE(Agrif_Variable) , Pointer :: var  
+           ! Pointer on the parent grid
+           TYPE(Agrif_PVariable), Pointer :: parent_var 
+      End TYPE Agrif_PVariable 
+C
+C     **************************************************************************
+CCC   TYPE Agrif_Grid
+C     **************************************************************************
+C
+CCC   Description:
+CCC   Data TYPE to define a grid (position, space and time refinement factors).
+C
+      TYPE Agrif_grid  
+           ! pointer on the parent grid 
+           TYPE(Agrif_grid)                    ,Pointer :: parent      
+           ! pointer on the child grids 
+           TYPE(Agrif_pgrid)                   ,Pointer :: child_grids 
+           ! List of the grid variables   
+           TYPE(Agrif_PVariable), DIMENSION(:) ,Pointer :: tabvars     
+C
+           ! Global x,y and z position
+           REAL    ,DIMENSION(3)                   :: Agrif_x   
+           ! Global space step in the x,y and z direction
+           REAL    ,DIMENSION(3)                   :: Agrif_d
+           ! number of cells in the x,y and z direction
+           INTEGER ,DIMENSION(3)                   :: nb        
+           ! minimal position in the x,y and z direction
+           INTEGER ,DIMENSION(3)                   :: ix        
+           ! Space refinement factor in the x,y and z direction
+           INTEGER ,DIMENSION(3)                   :: spaceref  
+           ! Time refinement factor in the x,y and z direction 
+           INTEGER ,DIMENSION(3)                   :: timeref   
+           INTEGER ,DIMENSION(:)          ,Pointer :: restore1D   
+           INTEGER ,DIMENSION(:,:)        ,Pointer :: restore2D   
+           INTEGER ,DIMENSION(:,:,:)      ,Pointer :: restore3D 
+           INTEGER ,DIMENSION(:,:,:,:)    ,Pointer :: restore4D
+           INTEGER ,DIMENSION(:,:,:,:,:)  ,Pointer :: restore5D
+           INTEGER ,DIMENSION(:,:,:,:,:,:),Pointer :: restore6D
+           ! number of time step  
+           INTEGER                                 :: ngridstep 
+           INTEGER                                 :: rank  
+           !moving grid id
+           INTEGER                                 :: grid_id
+           ! number of the grid 
+           INTEGER                                 :: fixedrank 
+           ! fixed or moving grid ?  
+           LOGICAL                                 :: fixed     
+           LOGICAL                                 :: oldgrid   
+C          LOGICALs indicating if the current grid has a common border 
+C             with the root coarse grid
+           LOGICAL ,DIMENSION(3)                   :: NearRootBorder
+           LOGICAL ,DIMENSION(3)                   :: DistantRootBorder
+C          Arrays for adaptive grid refinement
+           REAL    ,DIMENSION(:)          ,Pointer :: valtabpoint1D
+           REAL    ,DIMENSION(:,:)        ,Pointer :: valtabpoint2D
+           REAL    ,DIMENSION(:,:,:)      ,Pointer :: valtabpoint3D
+           INTEGER ,DIMENSION(:)          ,Pointer :: tabpoint1D
+           INTEGER ,DIMENSION(:,:)        ,Pointer :: tabpoint2D
+           INTEGER ,DIMENSION(:,:,:)      ,Pointer :: tabpoint3D
+           
+           Type(Agrif_Flux), Pointer               :: fluxes => NULL()
+      End TYPE Agrif_grid
+C
+C     **************************************************************************
+CCC   TYPE Agrif_VARIABLE
+C     **************************************************************************
+C     
+CCC   Description:
+CCC   Data TYPE to CHARACTERize a grid variable.   
+C
+      TYPE Agrif_Variable 
+C       
+         ! Pointer on the variable of the root grid 
+         TYPE(Agrif_Variable), Pointer :: root_var 
+C
+         ! index of the first point in the REAL domain (x,y and z direction)
+         INTEGER     ,DIMENSION(6)          :: point
+         ! position of the variable on the cell (1 for the boarder of 
+         !    the edge, 2 for the center)
+         INTEGER     ,DIMENSION(:) ,Pointer :: posvar      => NULL() 
+         ! Indication for the space interpolation (module Agrif_Boundary)
+         INTEGER                   ,Pointer :: interpIndex => NULL() 
+         ! number of DIMENSIONs of the grid variable
+         INTEGER                            :: nbdim = 0             
+         ! Array indicating the TYPE of DIMENSION (space or not) for 
+         !    each of them 
+         CHARACTER(6),DIMENSION(:) ,Pointer :: interptab   => NULL() 
+C        Arrays containing the values of the grid variables (REAL)
+         REAL                                    :: array0 
+         REAL   , DIMENSION(:)          ,Pointer :: array1    => NULL()
+         REAL   , DIMENSION(:,:)        ,Pointer :: array2    => NULL()
+         REAL   , DIMENSION(:,:,:)      ,Pointer :: array3    => NULL()
+         REAL   , DIMENSION(:,:,:,:)    ,Pointer :: array4    => NULL()
+         REAL   , DIMENSION(:,:,:,:,:)  ,Pointer :: array5    => NULL()
+         REAL   , DIMENSION(:,:,:,:,:,:),Pointer :: array6    => NULL()
+C        Arrays containing the values of the grid variables (REAL*8)
+         REAL*8                                 :: darray0
+         REAL*8, DIMENSION(:)          ,Pointer :: darray1   => NULL()
+         REAL*8, DIMENSION(:,:)        ,Pointer :: darray2   => NULL()
+         REAL*8, DIMENSION(:,:,:)      ,Pointer :: darray3   => NULL()
+         REAL*8, DIMENSION(:,:,:,:)    ,Pointer :: darray4   => NULL()
+         REAL*8, DIMENSION(:,:,:,:,:)  ,Pointer :: darray5   => NULL()
+         REAL*8, DIMENSION(:,:,:,:,:,:),Pointer :: darray6   => NULL()
+C        Arrays containing the values of the grid variables (LOGICAL)
+         LOGICAL                                 :: larray0
+         LOGICAL, DIMENSION(:)          ,Pointer :: larray1   => NULL()
+         LOGICAL, DIMENSION(:,:)        ,Pointer :: larray2   => NULL()
+         LOGICAL, DIMENSION(:,:,:)      ,Pointer :: larray3   => NULL()
+         LOGICAL, DIMENSION(:,:,:,:)    ,Pointer :: larray4   => NULL()
+         LOGICAL, DIMENSION(:,:,:,:,:)  ,Pointer :: larray5   => NULL()
+         LOGICAL, DIMENSION(:,:,:,:,:,:),Pointer :: larray6   => NULL()
+C         Arrays containing the values of the grid variables (INTEGER)   
+         INTEGER                                 :: iarray0
+         INTEGER, DIMENSION(:)          ,Pointer :: iarray1   => NULL()
+         INTEGER, DIMENSION(:,:)        ,Pointer :: iarray2   => NULL()
+         INTEGER, DIMENSION(:,:,:)      ,Pointer :: iarray3   => NULL()
+         INTEGER, DIMENSION(:,:,:,:)    ,Pointer :: iarray4   => NULL()
+         INTEGER, DIMENSION(:,:,:,:,:)  ,Pointer :: iarray5   => NULL()
+         INTEGER, DIMENSION(:,:,:,:,:,:),Pointer :: iarray6   => NULL()
+C
+         INTEGER, DIMENSION(:)          ,Pointer :: restore1D => NULL()
+         INTEGER, DIMENSION(:,:)        ,Pointer :: restore2D => NULL()
+         INTEGER, DIMENSION(:,:,:)      ,Pointer :: restore3D => NULL()
+         INTEGER, DIMENSION(:,:,:,:)    ,Pointer :: restore4D => NULL()
+         INTEGER, DIMENSION(:,:,:,:,:)  ,Pointer :: restore5D => NULL()
+         INTEGER, DIMENSION(:,:,:,:,:,:),Pointer :: restore6D => NULL()
+C   
+         CHARACTER(2050)                          :: carray0
+         CHARACTER(200), DIMENSION(:)    ,Pointer :: carray1   => NULL()
+         CHARACTER(200), DIMENSION(:,:)  ,Pointer :: carray2   => NULL()
+C
+         ! Array used for the time interpolation
+         REAL   , DIMENSION(:,:)      ,Pointer :: oldvalues2D => NULL()
+
+         ! if the variable should be restore -> =1
+         LOGICAL :: restaure = .FALSE.
+         ! the interpolation should be made in any case
+         LOGICAL :: Interpolationshouldbemade = .FALSE. 
+         INTEGER :: bcinf ! option bc
+         INTEGER :: bcsup ! option bc
+         INTEGER :: updateinf ! option update
+         INTEGER :: updatesup ! option update         
+         INTEGER, DIMENSION(6) :: bcTYPEinterp ! option bcinterp
+         INTEGER, DIMENSION(6) :: TYPEinterp ! option interp
+         INTEGER, DIMENSION(6) :: TYPEupdate ! option update
+         
+         Type(Agrif_List_Interp_Loc), Pointer :: list_interp => NULL()
+         Type(Agrif_List_Interp_Loc), Pointer :: list_update => NULL()
+C
+      End TYPE Agrif_Variable 
+      
+      Type Agrif_Interp_Loc
+      integer,dimension(6) :: pttab,petab,
+     &                          pttab_Child,pttab_Parent = -99
+      integer,dimension(6) :: indmin, indmax
+      INTEGER,DIMENSION(6)    :: pttruetab,cetruetab
+      logical :: member, memberin      
+#if !defined AGRIF_MPI      
+      integer,dimension(6) :: indminglob,indmaxglob
+#else
+      integer,dimension(6) :: indminglob2,indmaxglob2
+      INTEGER,DIMENSION(6,2,2) :: parentarray
+      INTEGER,DIMENSION(:,:,:), POINTER :: tab4t
+      LOGICAL, DIMENSION(:), POINTER :: memberinall
+      INTEGER,DIMENSION(:,:,:), POINTER :: tab5t
+      LOGICAL, DIMENSION(:), POINTER :: memberinall2
+#endif      
+      End Type Agrif_Interp_Loc
+      
+      Type Agrif_List_Interp_Loc
+      Type(Agrif_Interp_Loc), Pointer :: interp_loc
+      Type(Agrif_List_Interp_Loc), Pointer :: suiv
+      End Type Agrif_List_Interp_Loc
+        
+       TYPE Agrif_Profile
+          character*80 :: profilename
+C
+         ! index of the first point in the REAL domain (x,y and z direction)
+         INTEGER     ,DIMENSION(6)          :: point
+         ! position of the variable on the cell (1 for the boarder of 
+         !    the edge, 2 for the center)
+         INTEGER     ,DIMENSION(:) ,Pointer :: posvar      => NULL() 
+         ! Indication for the space interpolation (module Agrif_Boundary)
+         INTEGER                   ,Pointer :: interpIndex => NULL() 
+         ! number of DIMENSIONs of the grid variable
+         INTEGER                            :: nbdim = 0             
+         ! Array indicating the TYPE of DIMENSION (space or not) for 
+         !    each of them 
+         CHARACTER(6),DIMENSION(:) ,Pointer :: interptab   => NULL() 
+         Type(Agrif_Profile), Pointer :: nextprofile  => NULL()
+       END TYPE Agrif_Profile
+       
+       Type(Agrif_Profile), Pointer :: Agrif_MyProfiles => NULL()
+           
+C  Boundaries Fluxes
+
+      Type Agrif_Flux
+        Character*80 fluxname
+        Type(Agrif_Variable), Pointer :: fluxtabx
+        Type(Agrif_Variable), Pointer :: fluxtaby
+        Type(Agrif_Variable), Pointer :: fluxtabz        
+        Type(Agrif_Profile), Pointer  :: profile
+        Logical :: Fluxallocated = .FALSE.
+        Type(Agrif_Flux), Pointer     :: nextflux => NULL()
+      End Type Agrif_Flux      
+C
+C     **************************************************************************
+CCC   Different PARAMETERs
+C     **************************************************************************
+      TYPE(Agrif_PVariable), DIMENSION(:) ,Pointer :: Agrif_tabvars
+C
+      ! this pointer always points on the root grid of the grid hierarchy
+      TYPE(Agrif_grid)  ,Pointer :: Agrif_Mygrid      
+      ! Pointer used in the Agrif_regrid subroutine (Agrif_Util module). 
+      !    It contains  the safeguard of the grid hierarchy.
+      TYPE(Agrif_pgrid) ,Pointer :: Agrif_oldmygrid   
+      ! pointer to the current grid (the link is done by using the
+      !    Agrif_Instance   procedure (module Agrif_Init)) 
+      TYPE(Agrif_grid)  ,Pointer :: Agrif_Curgrid
+      ! Pointer used in the Agrif_ChildGrid_to_ParentGrid and 
+      !    Agrif_ParentGrid_to_ChildGrid subroutines 
+      !    (Agrif_CurgridFunctions module). It contains the 
+      !    safeguard of the current grid hierarchy.
+      TYPE(Agrif_grid)  ,Pointer :: Agrif_saveCURGRID
+C
+      ! Problem DIMENSION
+      INTEGER               :: Agrif_Probdim
+      ! number of variables
+      INTEGER               :: Agrif_NbVariables
+      ! number of fixed grids in the grid hierarchy
+      INTEGER               :: Agrif_nbfixedgrids            
+      ! space refinement factor
+      INTEGER ,DIMENSION(3) :: Agrif_coeffref
+      ! time refinement factor
+      INTEGER ,DIMENSION(3) :: Agrif_coeffreft
+      ! LOGICAL to use special values on the parent grid
+      LOGICAL               :: Agrif_UseSpecialValue
+      ! LOGICAL to use special values on the parent grid
+      LOGICAL               :: Agrif_UseSpecialValueInUpdate
+      ! LOGICAL to use special values on the current grid
+      LOGICAL               :: Agrif_UseSpecialValueFineGrid
+      ! Special values on the parent grid
+      REAL                  :: Agrif_SpecialValue
+      ! Special values on the current grid
+      REAL                  :: Agrif_SpecialValueFineGrid
+C   clustering PARAMETERs
+      INTEGER               :: Agrif_Regridding
+      INTEGER               :: Agrif_Minwidth
+      REAL                  :: Agrif_Efficiency = 0.7
+      REAL    ,DIMENSION(3) :: Agrif_mind
+C     PARAMETERs for the interpolation of the child grids
+      ! linear interpolation
+      INTEGER ,PARAMETER    :: Agrif_linear=1
+      ! lagrange interpolation
+      INTEGER ,PARAMETER    :: Agrif_lagrange=2
+      ! spline interpolation
+      INTEGER ,PARAMETER    :: Agrif_eno=3
+      ! user s interpolation
+      INTEGER ,PARAMETER    :: Agrif_user_interp=4
+      ! constant interpolation
+      INTEGER ,PARAMETER    :: Agrif_constant=5
+      ! linear conservative interpolation 
+      INTEGER ,PARAMETER    :: Agrif_linearconserv=6
+      ! linear conservative interpolation       
+      INTEGER ,PARAMETER    :: Agrif_linearconservlim=7
+      INTEGER ,PARAMETER    :: Agrif_ppm=8 
+      INTEGER ,PARAMETER    :: Agrif_weno=9         
+C     PARAMETERs for the update of the parent grids      
+      INTEGER ,PARAMETER    :: Agrif_Update_Copy=1           ! copy
+      INTEGER ,PARAMETER    :: Agrif_Update_Average=2        ! average
+      INTEGER ,PARAMETER    :: Agrif_Update_Full_Weighting=3 ! full-weighting 
+C     Raffinement grid switch definition
+      ! Agrif_USE_ONLY_FIXED_GRIDS =1 if fixed grid mode
+      INTEGER               :: Agrif_USE_ONLY_FIXED_GRIDS    
+      ! Agrif_USE_FIXED_GRIDS = 1 if AMR mode + fixed grid 
+      !    else only AMR mode
+      INTEGER               :: Agrif_USE_FIXED_GRIDS         
+C
+#ifdef AGRIF_MPI
+      INTEGER :: Agrif_Nbprocs  ! Number of processors
+      INTEGER :: Agrif_ProcRank ! Rank of the current processor 
+      INTEGER :: Agrif_Group    ! Group associated to MPI_COMM_WORLD
+      INTEGER :: Agrif_MPIPREC
+#endif
+C
+      contains
+C   
+      Integer Function agrif_ceiling(x)
+C             
+          Real :: x
+          Integer ::i 
+C
+          i = floor(x)
+C      
+          if( abs(x - i).le.0.0001 )then
+             agrif_ceiling = i
+          else
+             agrif_ceiling = i+1
+          endif      
+C
+      End Function
+C
+      Integer Function agrif_int(x)
+C             
+          Real :: x
+          Integer ::i 
+C
+          i = floor(x) + 1
+C      
+          if( abs(x - i).le.0.0001 )then
+             agrif_int = i
+          else
+             agrif_int = i-1
+          endif      
+C
+      End Function
+      End Module Agrif_TYPEs  
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdate.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdate.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdate.F	(revision 4536)
@@ -0,0 +1,2472 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Update
+C
+      Module Agrif_Update
+C
+CCC   Description:
+CCC   Module to update a parent grid from its child grids
+C
+C     Modules used:
+C   
+      Use Agrif_Updatebasic
+c      Use Agrif_Boundary
+      Use Agrif_Arrays
+      Use Agrif_CurgridFunctions
+      Use Agrif_Mask
+#ifdef AGRIF_MPI
+      Use Agrif_mpp
+#endif
+C
+      IMPLICIT NONE
+C      
+      CONTAINS
+C     Define procedures contained in this module
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_1d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Update_1d(TypeUpdate,parent,child,tab,deb,fin,
+     &                           procname)
+C
+CCC   Description:
+CCC   Subroutine to update a 1D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid       
+      External :: procname
+      Optional ::  procname      
+      REAL, DIMENSION(lbound(child%var%array1,1):
+     &                ubound(child%var%array1,1)), Target :: tab  ! Results
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE  
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 1  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array1 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update
+             
+C
+     
+      IF (present(procname)) THEN
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin,procname)
+      ELSE
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+      ENDIF     
+C      
+C      child % var % list_update => childtemp%var%list_update
+      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_1D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_2d
+C     **************************************************************************
+C 
+
+      Subroutine Agrif_Update_2d(TypeUpdate,parent,child,tab,deb,fin,
+     &                           procname)
+C
+CCC   Description:
+CCC   Subroutine to update a 2D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid 
+                                              
+      External :: procname
+      Optional ::  procname
+                                                          
+      REAL, DIMENSION(
+     &      lbound(child%var%array2,1):ubound(child%var%array2,1),
+     &      lbound(child%var%array2,2):ubound(child%var%array2,2)),
+     &      Target :: tab  ! Results
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 2  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array2 => tab      
+      
+C      childtemp % var % list_update => child%var%list_update      
+C
+      IF (present(procname)) THEN
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin,procname)
+      ELSE
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+      ENDIF
+C      
+C      child % var % list_update => childtemp%var%list_update
+      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_2D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_3d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Update_3d(TypeUpdate,parent,child,tab,deb,fin,
+     &                           procname)
+C
+CCC   Description:
+CCC   Subroutine to update a 3D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid    
+      External :: procname
+      Optional ::  procname
+                                                       
+      REAL, DIMENSION(
+     &      lbound(child%var%array3,1):ubound(child%var%array3,1),
+     &      lbound(child%var%array3,2):ubound(child%var%array3,2),
+     &      lbound(child%var%array3,3):ubound(child%var%array3,3)),
+     &      Target :: tab  ! Results    
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE  
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 3  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array3 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update      
+C
+      IF (present(procname)) THEN
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin,procname)
+      ELSE
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+      ENDIF
+C      
+C      child % var % list_update => childtemp%var%list_update
+      
+      DEALLOCATE(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_3D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_4d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Update_4d(TypeUpdate,parent,child,tab,deb,fin,
+     &                           procname)
+C
+CCC   Description:
+CCC   Subroutine to update a 4D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid     
+      External :: procname
+      Optional ::  procname        
+      REAL, DIMENSION(
+     &      lbound(child%var%array4,1):ubound(child%var%array4,1),
+     &      lbound(child%var%array4,2):ubound(child%var%array4,2),
+     &      lbound(child%var%array4,3):ubound(child%var%array4,3),
+     &      lbound(child%var%array4,4):ubound(child%var%array4,4)),
+     &      Target :: tab  ! Results
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE  
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 4  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array4 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update
+            
+C
+      IF (present(procname)) THEN
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin,procname)
+      ELSE
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+      ENDIF
+
+C      child % var % list_update => childtemp%var%list_update      
+C
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_4D
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_5d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Update_5d(TypeUpdate,parent,child,tab,deb,fin,
+     &                           procname)
+C
+CCC   Description:
+CCC   Subroutine to update a 5D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid     
+      External :: procname
+      Optional ::  procname
+              
+      REAL, DIMENSION(
+     &      lbound(child%var%array5,1):ubound(child%var%array5,1),
+     &      lbound(child%var%array5,2):ubound(child%var%array5,2),
+     &      lbound(child%var%array5,3):ubound(child%var%array5,3),
+     &      lbound(child%var%array5,4):ubound(child%var%array5,4),
+     &      lbound(child%var%array5,5):ubound(child%var%array5,5)),
+     &      Target :: tab  ! Results
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE  
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 5  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array5 => tab      
+      
+C      childtemp % var % list_update => child%var%list_update      
+C
+      IF (present(procname)) THEN
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin,procname)
+      ELSE
+      CALL Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+      ENDIF
+      
+C      child % var % list_update => childtemp%var%list_update
+            
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_5D
+C
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_6d
+C     **************************************************************************
+C 
+      Subroutine Agrif_Update_6d(TypeUpdate,parent,child,tab,deb,fin)
+C
+CCC   Description:
+CCC   Subroutine to update a 6D grid variable on the parent grid.
+C
+C     Declarations:
+C
+      
+C
+C     Arguments      
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
+      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
+      INTEGER :: deb,fin                      ! Positions where interpolations 
+                                              ! are done on the fine grid       
+      REAL, DIMENSION(
+     &      lbound(child%var%array6,1):ubound(child%var%array6,1),
+     &      lbound(child%var%array6,2):ubound(child%var%array6,2),
+     &      lbound(child%var%array6,3):ubound(child%var%array6,3),
+     &      lbound(child%var%array6,4):ubound(child%var%array6,4),
+     &      lbound(child%var%array6,5):ubound(child%var%array6,5),
+     &      lbound(child%var%array6,6):ubound(child%var%array6,6)),
+     &      Target :: tab  ! Results
+C
+C
+C     Definition of a temporary AGRIF_PVariable data TYPE  
+      allocate(childtemp % var)
+C
+C     Pointer on the root variable
+      childtemp % var % root_var => child % var %root_var
+C      
+C     Number of dimensions of the grid variable
+      childtemp % var % nbdim = 6  
+C      
+C     Values on the current grid used for the update
+      childtemp % var % array6 => tab      
+C      childtemp % var % list_update => child%var%list_update
+C
+      Call Agrif_UpdateVariable
+     &     (TypeUpdate,parent,child,deb,fin)
+     
+C      child % var % list_update => childtemp%var%list_update
+           
+C      
+      deallocate(childtemp % var)
+C
+C       
+      End Subroutine Agrif_Update_6D
+C
+C
+C
+C     **************************************************************************  
+C     Subroutine Agrif_UpdateVariable    
+C     **************************************************************************  
+C   
+      Subroutine Agrif_UpdateVariable(TypeUpdate,parent,child,deb,fin,
+     &                   procname)   
+C
+CCC   Description:
+CCC   Subroutine to set arguments of Agrif_UpdatenD, n being the number of
+C         dimensions of the grid variable.
+C
+CC    Declarations:
+C      
+c      
+C      
+C     Scalar argument
+      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
+C     Data TYPE arguments
+      TYPE(AGRIF_PVariable) :: parent   ! Variable on the parent grid
+      TYPE(AGRIF_PVariable) :: child    ! Variable on the child grid 
+      INTEGER               :: deb,fin  ! Positions where boundary conditions
+                                        !    are calculated     
+      External :: procname
+      Optional ::  procname
+      
+C
+C     Local scalars      
+      INTEGER :: nbdim                  ! Number of dimensions of the current
+                                        !    grid
+      INTEGER ,DIMENSION(6) :: pttab_child  
+      INTEGER ,DIMENSION(6) :: petab_child      
+      INTEGER ,DIMENSION(6) :: pttab_parent  
+      REAL    ,DIMENSION(6) :: s_child,s_parent
+      REAL    ,DIMENSION(6) :: ds_child,ds_parent
+      INTEGER,DIMENSION(6)          :: loctab_Child ! Indicates if the child
+                                        !    grid has a common border with 
+                                        !    the root grid            
+      TYPE(AGRIF_Variable), Pointer :: root               ! Variable on the root grid
+      INTEGER,DIMENSION(6)          :: posvartab_Child    ! Position of the
+                                        !    variable on the cell
+      INTEGER,DIMENSION(6)          :: nbtab_Child        ! Number of the cells    
+      INTEGER :: n              
+      LOGICAL :: wholeupdate
+C
+C 
+
+      loctab_child(:) = 0
+C
+      root => child % var % root_var 
+      nbdim = root % nbdim
+C
+      do n = 1,nbdim
+        posvartab_child(n) = root % posvar(n)
+      enddo
+C      
+      
+      Call PreProcessToInterpOrUpdate(parent,child,
+     &             petab_Child(1:nbdim),
+     &             pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &             s_Child(1:nbdim),s_Parent(1:nbdim),
+     &             ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &             nbdim)
+C
+C
+      do n = 1,nbdim
+C
+        Select case(root % interptab(n))
+C
+          case('x') ! x DIMENSION
+C
+            nbtab_Child(n) = Agrif_Curgrid % nb(1)
+C
+          case('y') ! y DIMENSION      
+C
+            nbtab_Child(n) = Agrif_Curgrid % nb(2)
+C
+          case('z') ! z DIMENSION
+C
+            nbtab_Child(n) = Agrif_Curgrid % nb(3)
+C
+          case('N') ! No space DIMENSION      
+C
+            select case (nbdim) 
+C      
+              case(1)
+                nbtab_Child(n) = SIZE(child % var % array1,n) - 1
+              case(2)
+                nbtab_Child(n) = SIZE(child % var % array2,n) - 1
+              case(3)
+                nbtab_Child(n) = SIZE(child % var % array3,n) - 1
+              case(4)
+                nbtab_Child(n) = SIZE(child % var % array4,n) - 1
+              case(5)
+                nbtab_Child(n) = SIZE(child % var % array5,n) - 1  
+              case(6)
+                nbtab_Child(n) = SIZE(child % var % array6,n) - 1 
+C
+            end select
+C
+C           No interpolation but only a copy of the values of the grid variable      
+C      
+            posvartab_child(n) = 1
+            
+            loctab_child(n) = -3
+C
+        End select
+C
+      enddo
+      
+C     Call to a procedure of update according to the number of dimensions of
+C     the grid variable
+
+      wholeupdate = .FALSE.
+
+      IF ((deb == -99) .AND. (deb == fin)) THEN
+       wholeupdate = .TRUE.
+      ENDIF
+
+      IF ((deb > fin)) THEN
+       wholeupdate = .TRUE.
+      ENDIF
+     
+       IF (present(procname)) THEN
+
+          IF (wholeupdate) THEN
+
+          Call AGRIF_UpdateWhole
+     &         (TypeUpdate,parent,child,deb,fin,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim,procname)  
+         ELSE
+          Call AGRIF_UpdateBcnD
+     &         (TypeUpdate,parent,child,deb,fin,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim,procname)  
+         ENDIF
+       ELSE
+         IF (wholeupdate) THEN
+          Call AGRIF_UpdateWhole
+     &         (TypeUpdate,parent,child,deb,fin,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim)
+         ELSE
+          Call AGRIF_UpdateBcnD
+     &         (TypeUpdate,parent,child,deb,fin,
+     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
+     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
+     &          loctab_Child(1:nbdim),
+     &          s_Child(1:nbdim),s_Parent(1:nbdim),
+     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim)
+         ENDIF
+       ENDIF
+C
+      Return
+C
+C
+      End subroutine Agrif_UpdateVariable
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_UpdateWhole
+C     **************************************************************************               
+C
+      Subroutine AGRIF_UpdateWhole(TypeUpdate,parent,child,deb,fin,
+     &                           pttab_child,pttab_Parent,
+     &                           nbtab_Child,posvartab_Child,
+     &                           loctab_Child,
+     &                           s_Child,s_Parent,
+     &                           ds_Child,ds_Parent,nbdim,procname)
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions for a nD grid variable on 
+CCC   a fine grid by using a space and time interpolations; it is called by the 
+CCC   Agrif_CorrectVariable procedure.
+C
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+C
+#include "mpif.h"
+C
+#endif
+C
+C     Arguments
+      INTEGER, DIMENSION(6) :: TypeUpdate            ! TYPE of update (copy or
+                                                     !    average) 
+      TYPE(AGRIF_PVariable)    :: parent             ! Variable on the parent
+                                                     !    grid
+      TYPE(AGRIF_PVariable)    :: child              ! Variable on the child
+                                                     !    grid 
+      INTEGER :: deb, fin
+      INTEGER                  :: nbdim              ! Number of dimensions of
+                                                     !    the grid variable
+      INTEGER,DIMENSION(nbdim) :: pttab_child        ! Index of the first point
+                                                     !    inside the domain for
+                                                     !    the parent grid
+                                                     !    variable
+      INTEGER,DIMENSION(nbdim) :: pttab_Parent       ! Index of the first point
+                                                     !    inside the domain for
+                                                     !    the child grid
+                                                     !    variable
+      INTEGER,DIMENSION(nbdim) :: nbtab_Child        ! Number of cells of the
+                                                     !    child grid
+      INTEGER,DIMENSION(nbdim) :: posvartab_Child    ! Position of the grid
+                                                     !    variable (1 or 2)
+      INTEGER,DIMENSION(nbdim) :: loctab_Child       ! Indicates if the child
+                                                     !    grid has a common
+                                                     !    border with the root
+                                                     !    grid
+      REAL   ,DIMENSION(nbdim) :: s_Child,s_Parent   ! Positions of the parent
+                                                     !    and child grids 
+      REAL   ,DIMENSION(nbdim) :: ds_Child,ds_Parent ! Space steps of the parent
+                                                     !    and child grids
+      External :: procname
+      Optional ::  procname      
+C
+C     Local variables     
+      INTEGER,DIMENSION(nbdim,2)   :: lubglob
+      INTEGER                      :: i                 
+      INTEGER,DIMENSION(nbdim,2,2) :: indtab         ! Arrays indicating the
+                                                     !    limits of the child
+      INTEGER,DIMENSION(nbdim,2,2) :: indtruetab     ! grid variable where
+                                                     !   boundary conditions are
+      integer :: coeffraf
+      INTEGER :: debloc, finloc
+C
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim)   :: lb,ub
+      INTEGER,DIMENSION(nbdim,2) :: iminmaxg
+      INTEGER                    :: code
+C
+#endif
+C      
+C
+C indtab contains the limits for the fine grid points that will be used
+C in the update scheme
+
+      DO i = 1, nbdim
+        coeffraf = nint(ds_Parent(i)/ds_Child(i))
+        debloc = 0
+        finloc = nbtab_Child(i)/coeffraf - 1
+
+        IF (posvartab_child(i) == 1) THEN
+           finloc = finloc - 1
+        ENDIF
+
+        IF (deb > fin) THEN
+          debloc = deb
+          finloc = finloc - deb
+        ENDIF
+
+        indtab(i,1,1) = pttab_child(i) + (debloc + 1) * coeffraf
+        indtab(i,1,2) = pttab_child(i) + (finloc + 1) * coeffraf
+
+        IF (posvartab_child(i) == 1) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,1,1) = indtab(i,1,1) - (coeffraf - 1)
+            indtab(i,1,2) = indtab(i,1,2) + (coeffraf - 1)        
+          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
+            indtab(i,1,1) = indtab(i,1,1) - coeffraf / 2
+            indtab(i,1,2) = indtab(i,1,2) + coeffraf / 2
+          ENDIF
+        ELSE
+          indtab(i,1,1) = indtab(i,1,1) - coeffraf
+          indtab(i,1,2) = indtab(i,1,2) - 1
+          IF ((TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting)
+     &                            .AND.(mod(coeffraf,2) == 1)) THEN
+            indtab(i,1,1) = indtab(i,1,1) - 1
+            indtab(i,1,2) = indtab(i,1,2) + 1
+          ENDIF
+        ENDIF
+        IF (loctab_child(i) == -3) THEN
+           indtab(i,1,1) = pttab_child(i)
+C
+               if (posvartab_child(i) == 1) then
+C
+               indtab(i,1,2) = pttab_child(i) + nbtab_child(i) 
+C
+               else
+C
+               indtab(i,1,2) = pttab_child(i) + nbtab_child(i) - 1
+               ENDIF
+        ENDIF
+      ENDDO
+
+C lubglob contains the global lbound and ubound of the child array
+C lubglob(:,1) : global lbound for each dimension
+C lubglob(:,2) : global lbound for each dimension
+
+#if !defined AGRIF_MPI
+        Call Agrif_nbdim_Get_bound_dimension(child % var,lubglob(:,1),
+     &               lubglob(:,2),nbdim)
+C
+#else
+C     
+        Call Agrif_nbdim_Get_bound_dimension(child % var,lb,ub,nbdim)
+      DO i = 1,nbdim
+C
+        Call Agrif_Invloc(lb(i),Agrif_Procrank,i,iminmaxg(i,1))
+        Call Agrif_Invloc(ub(i),Agrif_Procrank,i,iminmaxg(i,2))
+C
+      ENDDO
+C
+      iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
+      
+      CALL MPI_ALLREDUCE(iminmaxg,lubglob,2*nbdim,MPI_INTEGER,MPI_MIN,
+     &                     MPI_COMM_WORLD,code)
+
+      lubglob(1:nbdim,2) = - lubglob(1:nbdim,2)      
+C
+#endif 
+C
+
+      indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),
+     &     lubglob(1:nbdim,1))
+      indtruetab(1:nbdim,1,2) = min(indtab(1:nbdim,1,2),
+     &     lubglob(1:nbdim,2))
+
+C
+C
+
+           IF (present(procname)) THEN
+              Call Agrif_UpdatenD              
+     &             (TypeUpdate,parent,child,
+     &              indtruetab(1:nbdim,1,1),indtruetab(1:nbdim,1,2),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              posvartab_child,loctab_Child,
+     &              nbdim,procname)
+           ELSE
+              Call Agrif_UpdatenD              
+     &             (TypeUpdate,parent,child,
+     &              indtruetab(1:nbdim,1,1),indtruetab(1:nbdim,1,2),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              posvartab_child,loctab_Child,
+     &              nbdim)           
+           ENDIF
+C
+C      
+C  
+      End Subroutine Agrif_UpdateWhole
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_UpdateBcnd
+C     **************************************************************************               
+C
+      Subroutine AGRIF_UpdateBcnd(TypeUpdate,parent,child,deb,fin,
+     &                           pttab_child,pttab_Parent,
+     &                           nbtab_Child,posvartab_Child,
+     &                           loctab_Child,
+     &                           s_Child,s_Parent,
+     &                           ds_Child,ds_Parent,nbdim,procname)
+C
+CCC   Description:
+CCC   Subroutine to calculate the boundary conditions for a nD grid variable on
+CCC   a fine grid by using a space and time interpolations; it is called by the 
+CCC   Agrif_CorrectVariable procedure.
+C
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+C
+#include "mpif.h"
+C
+#endif
+C
+C     Arguments
+      INTEGER, DIMENSION(6) :: TypeUpdate            ! TYPE of update 
+                                                     !   (copy or average) 
+      TYPE(AGRIF_PVariable)    :: parent             ! Variable on the parent
+                                                     !   grid
+      TYPE(AGRIF_PVariable)    :: child              ! Variable on the child
+                                                     !   grid 
+      INTEGER                  :: deb,fin            ! Positions where
+                                                     !   interpolations are done
+      INTEGER                  :: nbdim              ! Number of dimensions of
+                                                     !   the grid variable
+      INTEGER,DIMENSION(nbdim) :: pttab_child        ! Index of the first point
+                                                     !   inside the domain for
+                                                     !   the parent grid
+                                                     !   variable
+      INTEGER,DIMENSION(nbdim) :: pttab_Parent       ! Index of the first point
+                                                     !   inside the domain for
+                                                     !   the child grid variable
+      INTEGER,DIMENSION(nbdim) :: nbtab_Child        ! Number of cells of the
+                                                     !   child grid
+      INTEGER,DIMENSION(nbdim) :: posvartab_Child    ! Position of the grid
+                                                     !   variable (1 or 2)
+      INTEGER,DIMENSION(nbdim) :: loctab_Child       ! Indicates if the child
+                                                     !   grid has a common
+                                                     !   border with the root
+                                                     !   grid
+      REAL   ,DIMENSION(nbdim) :: s_Child,s_Parent   ! Positions of the parent
+                                                     !   and child grids 
+      REAL   ,DIMENSION(nbdim) :: ds_Child,ds_Parent ! Space steps of the parent
+                                                     !   and child grids
+      External :: procname
+      Optional ::  procname      
+C
+C     Local variables
+      INTEGER,DIMENSION(nbdim,2)   :: lubglob
+      INTEGER                      :: i                 
+      INTEGER,DIMENSION(nbdim,2,2) :: indtab         ! Arrays indicating the
+                                                     !   limits of the child
+      INTEGER,DIMENSION(nbdim,2,2) :: indtruetab     ! grid variable where
+                                                     !  boundary conditions are 
+      INTEGER,DIMENSION(nbdim,2,2,nbdim)   :: ptres      ! calculated
+      INTEGER                      :: nb,ndir,n
+      integer :: coeffraf
+C
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim)   :: lb,ub
+      INTEGER,DIMENSION(nbdim,2) :: iminmaxg
+      INTEGER                    :: code
+C
+#endif
+C      
+C
+
+      DO i = 1, nbdim
+        coeffraf = nint(ds_Parent(i)/ds_Child(i))
+        indtab(i,1,1) = pttab_child(i) + (deb + 1) * coeffraf
+        indtab(i,1,2) = pttab_child(i) + (fin + 1) * coeffraf
+
+        indtab(i,2,1) = pttab_child(i) + nbtab_child(i)
+     &    - (fin + 1) *  coeffraf
+        indtab(i,2,2) = pttab_child(i) + nbtab_child(i)
+     &    - (deb + 1) *  coeffraf
+
+        IF (posvartab_child(i) == 1) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,:,1) = indtab(i,:,1) - (coeffraf - 1)
+            indtab(i,:,2) = indtab(i,:,2) + (coeffraf - 1)        
+          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
+            indtab(i,:,1) = indtab(i,:,1) - coeffraf / 2
+            indtab(i,:,2) = indtab(i,:,2) + coeffraf / 2
+          ENDIF
+        ELSE
+          indtab(i,1,1) = indtab(i,1,1) - coeffraf
+          indtab(i,1,2) = indtab(i,1,2) - 1
+          indtab(i,2,2) = indtab(i,2,2) + coeffraf - 1
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,1,1) = indtab(i,1,1) - 1
+            indtab(i,1,2) = indtab(i,1,2) + 1
+            indtab(i,2,1) = indtab(i,2,1) - 1
+            indtab(i,2,2) = indtab(i,2,2) + 1
+          ENDIF          
+        ENDIF
+      ENDDO
+
+#if !defined AGRIF_MPI      
+        Call Agrif_nbdim_Get_bound_dimension(child % var,lubglob(:,1),
+     &               lubglob(:,2),nbdim)
+
+C
+#else
+C     
+        Call Agrif_nbdim_Get_bound_dimension(child % var,lb,ub,nbdim)
+      DO i = 1,nbdim
+C
+        Call Agrif_Invloc(lb(i),Agrif_Procrank,i,iminmaxg(i,1))
+        Call Agrif_Invloc(ub(i),Agrif_Procrank,i,iminmaxg(i,2))
+C
+      ENDDO
+C
+      iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
+      
+      CALL MPI_ALLREDUCE(iminmaxg,lubglob,2*nbdim,MPI_INTEGER,MPI_MIN,
+     &                     MPI_COMM_WORLD,code)  
+     
+      lubglob(1:nbdim,2) = - lubglob(1:nbdim,2)      
+C
+#endif 
+C     
+      indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),
+     &     lubglob(1:nbdim,1))
+      indtruetab(1:nbdim,1,2) = max(indtab(1:nbdim,1,2),
+     &     lubglob(1:nbdim,1))
+      indtruetab(1:nbdim,2,1) = min(indtab(1:nbdim,2,1),
+     &     lubglob(1:nbdim,2))
+      indtruetab(1:nbdim,2,2) = min(indtab(1:nbdim,2,2),
+     &     lubglob(1:nbdim,2))
+                        
+C 
+C
+      do nb = 1,nbdim
+C
+        do ndir = 1,2
+C
+          if (loctab_child(nb) /= -3) then
+C           
+              do n = 1,2
+C
+                ptres(nb,n,ndir,nb) = indtruetab(nb,ndir,n)
+C
+              enddo              
+C
+              do i = 1,nbdim
+C     
+                if (i .NE. nb) then      
+C
+                    if (loctab_child(i) == -3) then
+C
+                        ptres(i,1,ndir,nb) = pttab_child(i)
+C
+                      else
+C
+                        ptres(i,1,ndir,nb) = indtruetab(i,1,1)
+C
+                    endif
+C
+                    if (loctab_child(i) == -3) then
+C
+                        if (posvartab_child(i) == 1) then
+C
+                            ptres(i,2,ndir,nb) = pttab_child(i) 
+     &                                + nbtab_child(i)
+C
+                          else
+C
+                            ptres(i,2,ndir,nb) = pttab_child(i) 
+     &                             + nbtab_child(i) - 1
+C
+                        endif                             
+C
+                      else
+C
+                        ptres(i,2,ndir,nb) = indtruetab(i,2,2)
+C
+                    endif                        
+C      
+                endif
+C      
+              enddo
+      
+C
+            
+        endif
+      
+        enddo
+       enddo
+C
+
+C
+
+      do nb = 1,nbdim
+C
+        do ndir = 1,2                
+C
+          if (loctab_child(nb) /= -3) then
+C
+           IF (present(procname)) THEN
+              Call Agrif_UpdatenD              
+     &             (TypeUpdate,parent,child,
+     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              posvartab_Child,loctab_Child,
+     &              nbdim,procname,nb,ndir)
+           ELSE
+              Call Agrif_UpdatenD              
+     &             (TypeUpdate,parent,child,
+     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
+     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
+     &              s_Child(1:nbdim),s_Parent(1:nbdim),
+     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
+     &              posvartab_Child,loctab_Child,
+     &              nbdim)           
+           ENDIF
+C
+          endif
+          
+C
+        enddo       
+C
+      enddo
+C
+C      
+C  
+      End Subroutine Agrif_UpdateBcnd
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_UpdatenD  
+C     **************************************************************************  
+C  
+      Subroutine Agrif_UpdatenD(TypeUpdate,parent,child,
+     &                          pttab,petab,
+     &                          pttab_Child,pttab_Parent,
+     &                          s_Child,s_Parent,
+     &                          ds_Child,ds_Parent,
+     &                          posvartab_Child,loctab_Child,
+     &                          nbdim,procname,nb,ndir)  
+C
+C     Description:
+C     Subroutine to update a 2D grid variable on the parent grid of 
+C        the current grid. 
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+C
+#include "mpif.h"
+C
+#endif
+C
+C     Arguments
+      INTEGER                    :: nbdim
+      INTEGER, DIMENSION(6) :: TypeUpdate              ! TYPE of update 
+                                                       !  (copy or average)
+      TYPE(AGRIF_PVARIABLE)      :: parent             ! Variable of the parent
+                                                       !   grid   
+      TYPE(AGRIF_PVARIABLE)      :: child              ! Variable of the child
+                                                       !   grid
+      INTEGER,DIMENSION(nbdim)   :: pttab              ! Index of the first
+                                                       !   point inside the
+                                                       !   domain
+      INTEGER,DIMENSION(nbdim)   :: petab              ! Index of the first
+                                                       !   point inside the
+                                                       !   domain
+      INTEGER,DIMENSION(nbdim)   :: pttab_Child        ! Index of the first
+                                                       !   point inside the
+                                                       !   domain for the child
+                                                       !   grid variable
+      INTEGER,DIMENSION(nbdim)   :: pttab_Parent       ! Index of the first
+                                                       !   point inside the
+                                                       !   domain for the parent
+                                                       !   grid variable
+      REAL,DIMENSION(nbdim)      :: s_Child,s_Parent   ! Positions of the parent
+                                                       !   and child grids
+      REAL,DIMENSION(nbdim)      :: ds_Child,ds_Parent ! Space steps of the
+                                                       !   parent and child
+                                                       !   grids 
+      External :: procname
+      Optional ::  procname
+      Integer :: nb,ndir
+      Optional :: nb,ndir
+      
+C
+C     Local pointers
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempP      ! Temporary parent grid variable
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempC      ! Temporary child grid variable
+C
+C     Local scalars
+      INTEGER,DIMENSION(nbdim)    :: pttruetab,cetruetab
+      INTEGER,DIMENSION(nbdim)    :: posvartab_Child,loctab_Child
+      INTEGER,DIMENSION(nbdim)    :: indmin,indmax
+      INTEGER,DIMENSION(nbdim)    :: indminglob,indmaxglob
+      REAL   ,DIMENSION(nbdim)    :: s_Child_temp,s_Parent_temp
+cccccccc      LOGICAL,DIMENSION(nbdim)    :: noraftab
+      INTEGER,DIMENSION(nbdim)    :: lowerbound,upperbound
+      LOGICAL :: memberin, member
+      INTEGER,DIMENSION(nbdim)    :: pttruetabwhole,cetruetabwhole
+      INTEGER,DIMENSION(nbdim,2,2) :: childarray
+      INTEGER,DIMENSION(nbdim,2,2) :: parentarray
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempCextend,tempPextend ! Temporary child
+      INTEGER :: nbin, ndirin
+C
+#ifdef AGRIF_MPI
+C
+      INTEGER,DIMENSION(nbdim)    :: indminglob2,indmaxglob2
+      INTEGER                              :: code
+      INTEGER                              :: i,j,k
+      INTEGER,DIMENSION(nbdim,4)           :: tab3
+      INTEGER,DIMENSION(nbdim,4,0:Agrif_Nbprocs-1) :: tab4
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL :: find_list_update
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
+      LOGICAL, DIMENSION(1) :: memberin1      
+C
+#endif
+C
+  
+C
+C     local lbound and ubound of the child array
+
+      Call Agrif_nbdim_Get_bound_dimension(child%var,
+     &                              lowerbound,upperbound,nbdim)
+
+C here pttab and petab corresponds to the (global) indices of the points needed
+C in the update
+C pttruetab and cetruetab contains only indices that are present
+C on the local processor
+
+      Call Agrif_Childbounds(nbdim,
+     &                       lowerbound,upperbound,
+     &                       pttab,petab,
+     &                       pttruetab,cetruetab,memberin)
+
+       Call Agrif_Prtbounds(nbdim,indminglob,indmaxglob,s_Parent_temp,
+     &                     s_Child_temp,s_Child,ds_Child,
+     &                     s_Parent,ds_Parent,
+     &                     pttab,petab,pttab_Child,
+     &                     pttab_Parent,
+     &                     posvartab_Child,TypeUpdate,loctab_Child
+#ifdef AGRIF_MPI
+     &                 ,pttruetabwhole,cetruetabwhole
+#endif
+     &     )
+
+#ifdef AGRIF_MPI
+      IF (memberin) THEN
+       Call Agrif_GlobtoLocInd2(childarray,
+     &                     lowerbound,upperbound,
+     &                     pttruetab,cetruetab,
+     &                     nbdim,Agrif_Procrank,
+     &                     member)
+
+      ENDIF
+
+
+         Call Agrif_Prtbounds(nbdim,indmin,indmax,s_Parent_temp,
+     &                     s_Child_temp,s_Child,ds_Child,
+     &                     s_Parent,ds_Parent,
+     &                     pttruetab,cetruetab,pttab_Child,
+     &                     pttab_Parent,
+     &                     posvartab_Child,TypeUpdate,loctab_Child
+     &                 ,pttruetabwhole,cetruetabwhole
+     &     )
+
+#else
+       indmin = indminglob
+       indmax = indmaxglob
+       pttruetabwhole = pttruetab
+       cetruetabwhole = cetruetab
+       childarray(:,1,2) = pttruetab
+       childarray(:,2,2) = cetruetab
+#endif
+
+       IF (present(procname)) THEN
+       IF (.Not.present(nb)) THEN
+       nbin=0
+       ndirin=0
+       ELSE
+       nbin = nb
+       ndirin = ndir
+       ENDIF
+       ENDIF
+       
+      IF (memberin) THEN
+      IF (.not.associated(tempC%var)) allocate(tempC%var)
+
+C
+      Call Agrif_nbdim_allocation(tempC%var,
+     &                 pttruetab,cetruetab,nbdim)
+
+      Call Agrif_nbdim_Full_VarEQreal(tempC%var,0.,nbdim)
+
+
+
+      IF (present(procname)) THEN
+        SELECT CASE (nbdim)
+        CASE(1)
+          CALL procname(tempC%var%array1,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        CASE(2)
+          CALL procname(tempC%var%array2,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                          childarray(2,1,2),childarray(2,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        CASE(3)
+          CALL procname(tempC%var%array3,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                          childarray(2,1,2),childarray(2,2,2),
+     &                          childarray(3,1,2),childarray(3,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        CASE(4)
+          CALL procname(tempC%var%array4,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                          childarray(2,1,2),childarray(2,2,2),
+     &                          childarray(3,1,2),childarray(3,2,2),
+     &                          childarray(4,1,2),childarray(4,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        CASE(5)
+          CALL procname(tempC%var%array5,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                          childarray(2,1,2),childarray(2,2,2),
+     &                          childarray(3,1,2),childarray(3,2,2),
+     &                          childarray(4,1,2),childarray(4,2,2),
+     &                          childarray(5,1,2),childarray(5,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        CASE(6)
+          CALL procname(tempC%var%array6,
+     &                          childarray(1,1,2),childarray(1,2,2),
+     &                          childarray(2,1,2),childarray(2,2,2),
+     &                          childarray(3,1,2),childarray(3,2,2),
+     &                          childarray(4,1,2),childarray(4,2,2),
+     &                          childarray(5,1,2),childarray(5,2,2),
+     &                          childarray(6,1,2),childarray(6,2,2),
+     &                                   .TRUE.,nbin,ndirin)
+        END SELECT
+      ELSE
+      Call Agrif_nbdim_VarEQvar(tempC%var,pttruetab,cetruetab,
+     &          child%var,childarray(:,1,2),childarray(:,2,2),
+     &                          nbdim)
+      ENDIF
+
+      ENDIF
+
+
+
+C
+C
+#ifdef AGRIF_MPI
+C
+C     tab2 contains the necessary limits of the parent grid for each processor
+
+      IF (Associated(child%var%list_update)) THEN
+      Call Agrif_Find_list_update(child%var%list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &       find_list_update,tab4t,tab5t,memberinall,memberinall2)
+      ELSE
+      find_list_update = .FALSE.
+      ENDIF
+      
+      if (.not.find_list_update) then      
+      tab3(:,1) = pttruetab(:)
+      tab3(:,2) = cetruetab(:)
+      tab3(:,3) = pttruetabwhole(:)
+      tab3(:,4) = cetruetabwhole(:)
+C
+C
+      Call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,
+     &                   MPI_INTEGER,MPI_COMM_WORLD,code)
+
+      IF (.not.associated(tempCextend%var)) Allocate(tempCextend%var)
+      DO k=0,Agrif_Nbprocs-1
+       do j=1,4
+         do i=1,nbdim
+         tab4t(i,k,j) = tab4(i,j,k)
+         enddo
+       enddo
+      enddo
+      
+      memberin1(1) = memberin
+      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+           
+      endif
+      
+      Call Get_External_Data(tempC,tempCextend,tab4t(:,:,1),
+     &            tab4t(:,:,2),
+     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,memberin,memberin,
+     &            memberinall)
+
+#else
+      tempCextend%var => tempC%var
+#endif
+
+C
+C
+C     Update of the parent grid (tempP) from the child grid (tempC)
+
+
+      IF (memberin) THEN
+
+      IF (.not.associated(tempP%var)) allocate(tempP%var)
+      Call Agrif_nbdim_allocation(tempP%var,
+     &                 indmin,indmax,nbdim)
+
+      if ( nbdim .EQ. 1 ) then
+         Call Agrif_Update_1D_recursive(TypeUpdate,
+     &           tempP%var%array1,tempCextend%var%array1,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+      if ( nbdim .EQ. 2 ) then
+         Call Agrif_Update_2D_recursive(TypeUpdate,
+     &           tempP%var%array2,tempCextend%var%array2,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+
+      if ( nbdim .EQ. 3 ) then
+         Call Agrif_Update_3D_recursive(TypeUpdate,
+     &           tempP%var%array3,tempCextend%var%array3,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+      if ( nbdim .EQ. 4 ) then
+         Call Agrif_Update_4D_recursive(TypeUpdate,
+     &           tempP%var%array4,tempCextend%var%array4,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+      if ( nbdim .EQ. 5 ) then
+         Call Agrif_Update_5D_recursive(TypeUpdate,
+     &           tempP%var%array5,tempCextend%var%array5,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+      if ( nbdim .EQ. 6 ) then
+         Call Agrif_Update_6D_recursive(TypeUpdate,
+     &           tempP%var%array6,tempCextend%var%array6,
+     &           indmin,indmax,
+     &           pttruetabwhole,cetruetabwhole,
+     &           s_Child_temp,s_Parent_temp,
+     &           ds_Child,ds_Parent,nbdim)
+      endif
+
+      Call Agrif_nbdim_deallocation(tempCextend%var,nbdim)
+C      Deallocate(tempCextend%var)
+
+      ENDIF
+
+#ifdef AGRIF_MPI
+      Call Agrif_nbdim_Get_bound_dimension(parent%var,
+     &                              lowerbound,upperbound,nbdim)
+
+      Call Agrif_ChildGrid_to_ParentGrid()
+C
+      Call Agrif_Childbounds(nbdim,
+     &                       lowerbound,upperbound,
+     &                       indminglob,indmaxglob,
+     &                       indminglob2,indmaxglob2,member)
+C
+      IF (member) THEN
+      Call Agrif_GlobtoLocInd2(parentarray,
+     &                     lowerbound,upperbound,
+     &                     indminglob2,indmaxglob2,
+     &                     nbdim,Agrif_Procrank,
+     &                     member)
+      ENDIF
+
+      Call Agrif_ParentGrid_to_ChildGrid()
+
+      if (.not.find_list_update) then
+      tab3(:,1) = indmin(:)
+      tab3(:,2) = indmax(:)
+      tab3(:,3) = indminglob2(:)
+      tab3(:,4) = indmaxglob2(:)
+C
+      Call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,
+     &                   MPI_INTEGER,MPI_COMM_WORLD,code)
+
+      IF (.not.associated(tempPextend%var)) Allocate(tempPextend%var)
+      DO k=0,Agrif_Nbprocs-1
+       do j=1,4
+         do i=1,nbdim
+         tab5t(i,k,j) = tab4(i,j,k)
+         enddo
+       enddo
+      enddo
+ 
+      memberin1(1) = member
+      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall2,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+     
+      Call Agrif_Addto_list_update(child%var%list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim
+     &   ,tab4t,tab5t,memberinall,memberinall2) 
+          
+      endif
+      
+      Call Get_External_Data(tempP,tempPextend,tab5t(:,:,1),
+     &            tab5t(:,:,2),
+     &            tab5t(:,:,3),tab5t(:,:,4),nbdim,memberin,member,
+     &            memberinall2)
+
+#else
+      tempPextend%var => tempP%var
+      parentarray(:,1,1) = indmin
+      parentarray(:,2,1) = indmax
+      parentarray(:,1,2) = indmin
+      parentarray(:,2,2) = indmax
+      member = .TRUE.
+#endif
+
+C
+C
+C
+C     Special values on the child grid
+      if (Agrif_UseSpecialValueFineGrid) then
+C
+ccc         noraftab(1:nbdim) =
+ccc     &    child % var % root_var % interptab(1:nbdim) .EQ. 'N'
+C
+#ifdef AGRIF_MPI
+C
+c          Allocate(childvalues% var)
+C
+c          Call Agrif_nbdim_allocation(childvalues%var,
+c     &                      pttruetab,cetruetab,nbdim)
+c          Call Agrif_nbdim_Full_VarEQvar(childvalues% var,
+c     &                                tempC% var,
+c     &                                nbdim)
+c          Call Agrif_CheckMasknD(tempC,childvalues,
+c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
+c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
+c     &                           noraftab(1:nbdim),nbdim)
+c          Call Agrif_nbdim_deallocation(childvalues% var,nbdim)
+c         Deallocate(childvalues % var)
+C
+#else
+C
+c          Call Agrif_nbdim_Get_bound_dimension(child%var,
+c     &                              lowerbound,upperbound,nbdim)
+c          Call Agrif_CheckMasknD(tempC,child,
+c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
+c     &                           lowerbound,
+c     &                           upperbound,
+c     &                           noraftab(1:nbdim),nbdim)
+C
+#endif
+C
+      endif
+
+
+C
+C
+C
+C
+C     Special values on the parent grid
+      if (Agrif_UseSpecialValue) then
+C
+#ifdef AGRIF_MPI
+C
+c          Call GiveAgrif_SpecialValueToTab_mpi(parent%var,tempP%var,
+c     &                 parentarray,
+c     &                 indmin,indmax,
+c     &                 Agrif_SpecialValue,nbdim)
+C
+C
+#else
+C
+c          Call GiveAgrif_SpecialValueToTab(parent%var,tempP%var,
+c     &                  indmin,indmax,
+c     &                  Agrif_SpecialValue,nbdim)
+C
+#endif
+C
+C
+      endif   
+C
+C
+        IF (member) THEN
+
+          IF (present(procname)) THEN
+            CALL Agrif_ChildGrid_to_ParentGrid()
+            SELECT CASE(nbdim)
+            CASE(1)
+            CALL procname(
+     &      tempPextend%var%array1(
+     &                      parentarray(1,1,1):parentarray(1,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            CASE(2)
+            CALL procname(
+     &      tempPextend%var%array2(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                      parentarray(2,1,2),parentarray(2,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            CASE(3)
+            CALL procname(
+     &      tempPextend%var%array3(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                      parentarray(2,1,2),parentarray(2,2,2),
+     &                      parentarray(3,1,2),parentarray(3,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            CASE(4)
+            CALL procname(
+     &      tempPextend%var%array4(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                      parentarray(2,1,2),parentarray(2,2,2),
+     &                      parentarray(3,1,2),parentarray(3,2,2),
+     &                      parentarray(4,1,2),parentarray(4,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            CASE(5)
+            CALL procname(
+     &      tempPextend%var%array5(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1),
+     &                      parentarray(5,1,1):parentarray(5,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                      parentarray(2,1,2),parentarray(2,2,2),
+     &                      parentarray(3,1,2),parentarray(3,2,2),
+     &                      parentarray(4,1,2),parentarray(4,2,2),
+     &                      parentarray(5,1,2),parentarray(5,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            CASE(6)
+            CALL procname(
+     &      tempPextend%var%array6(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1),
+     &                      parentarray(5,1,1):parentarray(5,2,1),
+     &                      parentarray(6,1,1):parentarray(6,2,1)),
+     &                      parentarray(1,1,2),parentarray(1,2,2),
+     &                      parentarray(2,1,2),parentarray(2,2,2),
+     &                      parentarray(3,1,2),parentarray(3,2,2),
+     &                      parentarray(4,1,2),parentarray(4,2,2),
+     &                      parentarray(5,1,2),parentarray(5,2,2),
+     &                      parentarray(6,1,2),parentarray(6,2,2),
+     &                                   .FALSE.,nbin,ndirin
+     &                      )
+            END SELECT
+            CALL Agrif_ParentGrid_to_ChildGrid()
+          ELSE
+            SELECT CASE(nbdim)
+            CASE(1)
+            parent%var%array1(parentarray(1,1,2):parentarray(1,2,2)) =
+     &      tempPextend%var%array1(
+     &                      parentarray(1,1,1):parentarray(1,2,1))
+            CASE(2)
+            parent%var%array2(parentarray(1,1,2):parentarray(1,2,2),
+     &                      parentarray(2,1,2):parentarray(2,2,2)) =
+     &      tempPextend%var%array2(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1))
+            CASE(3)
+            parent%var%array3(parentarray(1,1,2):parentarray(1,2,2),
+     &                      parentarray(2,1,2):parentarray(2,2,2),
+     &                      parentarray(3,1,2):parentarray(3,2,2)) =
+     &      tempPextend%var%array3(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1))
+            CASE(4)
+            parent%var%array4(parentarray(1,1,2):parentarray(1,2,2),
+     &                      parentarray(2,1,2):parentarray(2,2,2),
+     &                      parentarray(3,1,2):parentarray(3,2,2),
+     &                      parentarray(4,1,2):parentarray(4,2,2)) =
+     &      tempPextend%var%array4(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1))
+            CASE(5)
+            parent%var%array5(parentarray(1,1,2):parentarray(1,2,2),
+     &                      parentarray(2,1,2):parentarray(2,2,2),
+     &                      parentarray(3,1,2):parentarray(3,2,2),
+     &                      parentarray(4,1,2):parentarray(4,2,2),
+     &                      parentarray(5,1,2):parentarray(5,2,2)) =
+     &      tempPextend%var%array5(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1),
+     &                      parentarray(5,1,1):parentarray(5,2,1))
+            CASE(6)
+            parent%var%array6(parentarray(1,1,2):parentarray(1,2,2),
+     &                      parentarray(2,1,2):parentarray(2,2,2),
+     &                      parentarray(3,1,2):parentarray(3,2,2),
+     &                      parentarray(4,1,2):parentarray(4,2,2),
+     &                      parentarray(5,1,2):parentarray(5,2,2),
+     &                      parentarray(6,1,2):parentarray(6,2,2)) =
+     &      tempPextend%var%array6(
+     &                      parentarray(1,1,1):parentarray(1,2,1),
+     &                      parentarray(2,1,1):parentarray(2,2,1),
+     &                      parentarray(3,1,1):parentarray(3,2,1),
+     &                      parentarray(4,1,1):parentarray(4,2,1),
+     &                      parentarray(5,1,1):parentarray(5,2,1),
+     &                      parentarray(6,1,1):parentarray(6,2,1))
+            END SELECT
+          ENDIF
+
+        Call Agrif_nbdim_deallocation(tempPextend%var,nbdim)
+       ENDIF
+C
+C
+C     Deallocations
+
+      IF (memberin) THEN
+#ifdef AGRIF_MPI
+      Call Agrif_nbdim_deallocation(tempP%var,nbdim)
+      Call Agrif_nbdim_deallocation(tempC%var,nbdim)
+!      Deallocate(tempC % var)
+#endif
+!      Deallocate(tempP % var)
+      ENDIF
+#ifdef AGRIF_MPI
+!      Deallocate(tempPextend%var)
+!      IF (.Not.memberin) Deallocate(tempCextend%var)
+#endif
+
+C
+C
+      End Subroutine Agrif_UpdatenD
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Prtbounds
+C     **************************************************************************
+C
+      Subroutine Agrif_Prtbounds(nbdim,indmin,indmax,s_Parent_temp,
+     &                              s_Child_temp,s_Child,ds_Child,
+     &                              s_Parent,ds_Parent,
+     &                              pttruetab,cetruetab,pttab_Child,
+     &                              pttab_Parent,
+     &                              posvartab_child,TypeUpdate,
+     &                              loctab_Child
+#ifdef AGRIF_MPI
+     &                 ,pttruetabwhole,cetruetabwhole
+#endif
+     &                 )
+C
+CCC   Description:
+CCC   Subroutine calculating the bounds of the parent grid to be updated
+CCC   by the child grid     
+C
+C
+C     Declarations:
+C
+      
+C
+#ifdef AGRIF_MPI
+cccccccccccccccccccccccccc#include "mpif.h"
+#endif
+C
+C     Arguments
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim) :: indmin,indmax
+      REAL,DIMENSION(nbdim) :: s_Parent_temp,s_child_temp
+      REAL,DIMENSION(nbdim) :: s_Child,ds_child
+      REAL,DIMENSION(nbdim) :: s_Parent,ds_Parent
+      INTEGER,DIMENSION(nbdim) :: pttruetab,cetruetab
+      INTEGER,DIMENSION(nbdim) :: posvartab_child,TypeUpdate
+      INTEGER,DIMENSION(nbdim) :: loctab_Child
+      INTEGER,DIMENSION(nbdim) :: pttab_Child,pttab_Parent
+C
+C     Local variables
+      INTEGER :: i
+      REAL,DIMENSION(nbdim) :: dim_newmin,dim_newmax      
+#ifdef AGRIF_MPI
+      INTEGER,DIMENSION(nbdim)    :: pttruetabwhole,cetruetabwhole
+      REAL :: positionmin,positionmax
+      INTEGER :: imin,imax
+#endif
+C
+C
+      do i = 1,nbdim
+C
+        dim_newmin(i) = s_Child(i) + (pttruetab(i) -
+     &                                pttab_Child(i)) * ds_Child(i)
+C
+        dim_newmax(i) = s_Child(i) + (cetruetab(i) - 
+     &                                pttab_Child(i)) * ds_Child(i)
+C     
+        indmin(i) = pttab_Parent(i) +
+     &        agrif_ceiling((dim_newmin(i)-s_Parent(i))/ds_Parent(i))
+C
+        indmax(i) = pttab_Parent(i) +
+     &        agrif_int((dim_newmax(i)-s_Parent(i))/ds_Parent(i))
+C
+#ifdef AGRIF_MPI
+        positionmin = s_Parent(i) + (indmin(i)-
+     &                          pttab_Parent(i))*ds_Parent(i)
+        IF (loctab_Child(i) .NE. -3) THEN
+        IF (posvartab_child(i) == 1) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
+          positionmin = positionmin - ds_Parent(i)/2.
+          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmin = positionmin - (ds_Parent(i)-ds_Child(i))
+          ENDIF
+        ELSE
+        positionmin = positionmin - ds_Parent(i)/2.
+        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmin = positionmin - ds_Child(i)
+        ENDIF
+        ENDIF
+        ENDIF
+        imin = pttab_Child(i) +
+     &        agrif_ceiling((positionmin-s_Child(i))/ds_Child(i))
+
+       positionmin = s_Child(i) + (imin -
+     &                                pttab_Child(i)) * ds_Child(i)
+
+        pttruetabwhole(i) = imin
+
+        positionmax = s_Parent(i) + (indmax(i)-
+     &                          pttab_Parent(i))*ds_Parent(i)
+        IF (loctab_Child(i) .NE. -3) THEN
+        IF (posvartab_child(i) == 1) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
+        positionmax = positionmax  + ds_Parent(i)/2.
+          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmax = positionmax  + (ds_Parent(i)-ds_Child(i))
+          ENDIF
+        ELSE
+        positionmax = positionmax  + ds_Parent(i)/2.
+        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmax = positionmax + ds_Child(i)
+        ENDIF        
+        ENDIF
+        ENDIF
+        imax = pttab_Child(i) +
+     &        agrif_int((positionmax-s_Child(i))/ds_Child(i))
+
+        positionmax = s_Child(i) + (imax -
+     &                                pttab_Child(i)) * ds_Child(i)
+
+        cetruetabwhole(i) = imax
+
+#endif
+C
+        s_Parent_temp(i) = s_Parent(i) + 
+     &                     (indmin(i) - pttab_Parent(i)) * 
+     &                      ds_Parent(i) 
+C     
+        s_Child_temp(i) = dim_newmin(i)
+
+#ifdef AGRIF_MPI
+        s_Child_temp(i) = positionmin
+#endif
+C
+      enddo
+C
+      Return
+C
+C
+      End Subroutine Agrif_Prtbounds
+C
+C
+C
+C
+
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_Update_2D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_2D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 2D grid variable on the parent grid. 
+CCC   It calls Agrif_Update_1D_Recursive and Agrif_UpdateBase.   
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                indmin(2):indmax(2))           :: tempP
+C      REAL, DIMENSION(pttab_child(1):petab_child(1),
+C     &                pttab_child(2):petab_child(2)) :: tempC
+     
+      REAL, DIMENSION(:,:) :: tempC     
+C
+C     Local variables      
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                 pttab_child(2):petab_child(2)) :: tabtemp
+      INTEGER :: i,j
+      INTEGER :: coeffraf,locind_child_left
+C
+      do j = pttab_child(nbdim),petab_child(nbdim)
+C
+        Call Agrif_Update_1D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(:,j),
+     &         tempC(:,j-pttab_child(nbdim)+1),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C
+      enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+C
+      do i = indmin(1),indmax(1)
+C
+        Call Agrif_UpdateBase(TypeUpdate(2),
+     &           tempP(i,:),
+     &          tabtemp(i,:),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C        
+      enddo
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_2D_recursive
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_Update_3D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_3D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,   
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 3D grid variable on the parent grid. 
+CCC   It calls Agrif_Update_2D_Recursive and Agrif_UpdateBase.   
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                indmin(2):indmax(2),
+     &                indmin(3):indmax(3))           :: tempP
+      REAL, DIMENSION(pttab_child(1):petab_child(1),
+     &                pttab_child(2):petab_child(2),
+     &                pttab_child(3):petab_child(3)) :: tempC
+C
+C     Local variables      
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                 indmin(2):indmax(2), 
+     &                 pttab_child(3):petab_child(3)) :: tabtemp
+      INTEGER :: i,j,k
+      INTEGER :: coeffraf,locind_child_left
+      INTEGER :: kdeb
+C
+C
+      do k = pttab_child(nbdim),petab_child(nbdim)
+C
+        Call Agrif_Update_2D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(:,:,k),
+     &         tempC(:,:,k),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C
+      enddo
+C
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+      
+      IF (coeffraf == 1) THEN
+      
+      kdeb = pttab_child(3)+locind_child_left-2
+      do k=indmin(3),indmax(3)
+      kdeb = kdeb + 1
+      do j = indmin(2),indmax(2)
+        do i = indmin(1),indmax(1)
+        tempP(i,j,k) = tabtemp(i,j,kdeb)
+      enddo
+      enddo
+      enddo
+              
+      ELSE
+C
+      do j = indmin(2),indmax(2)
+C
+        do i = indmin(1),indmax(1)
+C
+          Call Agrif_UpdateBase(TypeUpdate(3),
+     &           tempP(i,j,:),
+     &          tabtemp(i,j,:),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+        enddo 
+C        
+      enddo
+      ENDIF
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_3D_recursive
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_Update_4D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_4D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,   
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 4D grid variable on the parent grid. 
+CCC   It calls Agrif_Update_3D_Recursive and Agrif_UpdateBase.    
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                indmin(2):indmax(2),
+     &                indmin(3):indmax(3),
+     &                indmin(4):indmax(4))           :: tempP
+      REAL, DIMENSION(pttab_child(1):petab_child(1),
+     &                pttab_child(2):petab_child(2),
+     &                pttab_child(3):petab_child(3),
+     &                pttab_child(4):petab_child(4)) :: tempC
+C
+C     Local variables      
+      REAL, DIMENSION(:,:,:,:), Allocatable :: tabtemp
+      INTEGER :: i,j,k,l
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      Allocate(tabtemp(indmin(1):indmax(1),
+     &                 indmin(2):indmax(2),
+     &                 indmin(3):indmax(3), 
+     &                 pttab_child(4):petab_child(4)))
+C
+      do l = pttab_child(nbdim),petab_child(nbdim)
+C
+        Call Agrif_Update_3D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(indmin(nbdim-3):indmax(nbdim-3),
+     &                 indmin(nbdim-2):indmax(nbdim-2),
+     &                 indmin(nbdim-1):indmax(nbdim-1),l),
+     &         tempC(pttab_child(nbdim-3):petab_child(nbdim-3),
+     &               pttab_child(nbdim-2):petab_child(nbdim-2),
+     &               pttab_child(nbdim-1):petab_child(nbdim-1),l),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C
+      enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+C
+      do k = indmin(3),indmax(3)
+C
+        do j = indmin(2),indmax(2)
+C
+          do i = indmin(1),indmax(1)
+C
+            Call Agrif_UpdateBase(TypeUpdate(4),
+     &           tempP(i,j,k,indmin(nbdim):indmax(nbdim)),
+     &          tabtemp(i,j,k,pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+          enddo 
+C
+        enddo 
+C        
+      enddo
+C
+      Deallocate(tabtemp)
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_4D_recursive
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_Update_5D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_5D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,   
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 5D grid variable on the parent grid. 
+CCC   It calls Agrif_Update_4D_Recursive and Agrif_UpdateBase.    
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                indmin(2):indmax(2),
+     &                indmin(3):indmax(3),
+     &                indmin(4):indmax(4),
+     &                indmin(5):indmax(5))           :: tempP
+      REAL, DIMENSION(pttab_child(1):petab_child(1),
+     &                pttab_child(2):petab_child(2),
+     &                pttab_child(3):petab_child(3),
+     &                pttab_child(4):petab_child(4),
+     &                pttab_child(5):petab_child(5)) :: tempC
+C
+C     Local variables      
+      REAL, DIMENSION(:,:,:,:,:), Allocatable :: tabtemp
+      INTEGER :: i,j,k,l,m
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      Allocate(tabtemp(indmin(1):indmax(1),
+     &                 indmin(2):indmax(2),
+     &                 indmin(3):indmax(3),
+     &                 indmin(4):indmax(4),   
+     &                 pttab_child(5):petab_child(5)))
+C
+      do m = pttab_child(nbdim),petab_child(nbdim)
+C
+        Call Agrif_Update_4D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(indmin(nbdim-4):indmax(nbdim-4),
+     &                 indmin(nbdim-3):indmax(nbdim-3),
+     &                 indmin(nbdim-2):indmax(nbdim-2),
+     &                 indmin(nbdim-1):indmax(nbdim-1),m),
+     &         tempC(pttab_child(nbdim-4):petab_child(nbdim-4),
+     &               pttab_child(nbdim-3):petab_child(nbdim-3),
+     &               pttab_child(nbdim-2):petab_child(nbdim-2),
+     &               pttab_child(nbdim-1):petab_child(nbdim-1),m),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C
+      enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+C
+      do l = indmin(4),indmax(4)
+C
+        do k = indmin(3),indmax(3)
+C
+          do j = indmin(2),indmax(2)
+C
+            do i = indmin(1),indmax(1)
+C
+              Call Agrif_UpdateBase(TypeUpdate(5),
+     &           tempP(i,j,k,l,indmin(nbdim):indmax(nbdim)),
+     &          tabtemp(i,j,k,l,
+     &                   pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+            enddo
+C
+          enddo 
+C
+        enddo 
+C        
+      enddo
+C
+      Deallocate(tabtemp)
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_5D_recursive
+C
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_Update_6D_Recursive 
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_6D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,   
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 6D grid variable on the parent grid. 
+CCC   It calls Agrif_Update_5D_Recursive and Agrif_UpdateBase.    
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C     
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                indmin(2):indmax(2),
+     &                indmin(3):indmax(3),
+     &                indmin(4):indmax(4),
+     &                indmin(5):indmax(5),
+     &                indmin(6):indmax(6))           :: tempP
+      REAL, DIMENSION(pttab_child(1):petab_child(1),
+     &                pttab_child(2):petab_child(2),
+     &                pttab_child(3):petab_child(3),
+     &                pttab_child(4):petab_child(4),
+     &                pttab_child(5):petab_child(5),
+     &                pttab_child(6):petab_child(6)) :: tempC
+C
+C     Local variables      
+      REAL, DIMENSION(:,:,:,:,:,:), Allocatable :: tabtemp
+      INTEGER :: i,j,k,l,m,n
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      Allocate(tabtemp(indmin(1):indmax(1),
+     &                 indmin(2):indmax(2),
+     &                 indmin(3):indmax(3),
+     &                 indmin(4):indmax(4),   
+     &                 indmin(5):indmax(5),   
+     &                 pttab_child(6):petab_child(6)))
+C
+      do n = pttab_child(nbdim),petab_child(nbdim)
+C
+        Call Agrif_Update_5D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(indmin(nbdim-5):indmax(nbdim-5),
+     &                 indmin(nbdim-4):indmax(nbdim-4),
+     &                 indmin(nbdim-3):indmax(nbdim-3),
+     &                 indmin(nbdim-2):indmax(nbdim-2),
+     &                 indmin(nbdim-1):indmax(nbdim-1),n),
+     &         tempC(pttab_child(nbdim-5):petab_child(nbdim-5),
+     &               pttab_child(nbdim-4):petab_child(nbdim-4),
+     &               pttab_child(nbdim-3):petab_child(nbdim-3),
+     &               pttab_child(nbdim-2):petab_child(nbdim-2),
+     &               pttab_child(nbdim-1):petab_child(nbdim-1),n),
+     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
+     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
+     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
+     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
+C
+      enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+C
+      do m = indmin(5),indmax(5)
+      do l = indmin(4),indmax(4)
+C
+        do k = indmin(3),indmax(3)
+C
+          do j = indmin(2),indmax(2)
+C
+            do i = indmin(1),indmax(1)
+C
+              Call Agrif_UpdateBase(TypeUpdate(6),
+     &           tempP(i,j,k,l,m,indmin(nbdim):indmax(nbdim)),
+     &          tabtemp(i,j,k,l,m,
+     &                   pttab_child(nbdim):petab_child(nbdim)),
+     &           indmin(nbdim),indmax(nbdim),
+     &           pttab_child(nbdim),petab_child(nbdim),
+     &           s_parent(nbdim),s_child(nbdim),
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+            enddo
+C
+          enddo 
+C
+        enddo 
+C        
+      enddo
+      enddo
+C
+      Deallocate(tabtemp)
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_6D_recursive
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Agrif_UpdateBase  
+C     **************************************************************************  
+C  
+      Subroutine Agrif_UpdateBase(TypeUpdate,
+     &                            parenttab,childtab,
+     &                            indmin,indmax,pttab_child,petab_child,
+     &                            s_parent,s_child,ds_parent,ds_child,
+     &                            coeffraf,locind_child_left)
+C
+CCC   Description:
+CCC   Subroutine calling the updating method chosen by the user (copy, average
+CCC   or full-weighting).    
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C
+      INTEGER :: TypeUpdate
+      INTEGER :: indmin,indmax
+      INTEGER :: pttab_child,petab_child
+      REAL,DIMENSION(indmin:indmax)           :: parenttab       
+      REAL,DIMENSION(pttab_child:petab_child) :: childtab      
+      REAL    :: s_parent,s_child
+      REAL    :: ds_parent,ds_child      
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      if (TypeUpdate == AGRIF_Update_copy) then
+C             
+          Call agrif_copy1D
+     &       (parenttab,childtab,
+     &          indmax-indmin+1,petab_child-pttab_child+1,
+     &          s_parent,s_child,ds_parent,ds_child)     
+C
+        elseif (TypeUpdate == AGRIF_Update_average) then
+C             
+          Call average1D
+     &       (parenttab,childtab,
+     &          indmax-indmin+1,petab_child-pttab_child+1,
+     &          s_parent,s_child,ds_parent,ds_child)    
+C
+        elseif (TypeUpdate == AGRIF_Update_full_weighting) then
+C             
+          Call full_weighting1D
+     &       (parenttab,childtab,
+     &          indmax-indmin+1,petab_child-pttab_child+1,
+     &          s_parent,s_child,ds_parent,ds_child,
+     &          coeffraf,locind_child_left)
+C
+      endif 
+C
+      Return                
+C
+C      
+      End Subroutine Agrif_UpdateBase
+C
+C
+
+      Subroutine Agrif_Compute_nbdim_update(s_parent,s_child,
+     &  ds_parent,ds_child,coeffraf,locind_child_left)
+      real :: s_parent,s_child,ds_parent,ds_child
+      integer :: coeffraf,locind_child_left
+     
+      coeffraf = nint(ds_parent/ds_child)
+      locind_child_left = 1 + agrif_int((s_parent-s_child)/ds_child)
+      
+      End Subroutine Agrif_Compute_nbdim_update
+ 
+#if defined AGRIF_MPI      
+      Subroutine Agrif_Find_list_update(list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &     find_list_update,tab4t,tab5t,memberinall,memberinall2)     
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      LOGICAL :: find_list_update
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+      INTEGER :: i
+C
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall,memberinall2
+                    
+      find_list_update = .FALSE.
+      
+      parcours => list_update
+      
+      Find_loop :   Do While (associated(parcours))
+        Do i=1,nbdim
+          IF ((pttab(i) /= parcours%interp_loc%pttab(i)).OR.
+     &        (petab(i) /= parcours%interp_loc%petab(i)).OR.
+     &        (pttab_child(i) /= parcours%interp_loc%pttab_child(i)).OR.
+     &        (pttab_parent(i) /= parcours%interp_loc%pttab_parent(i)))
+     &               THEN
+            parcours=>parcours%suiv
+            Cycle Find_loop
+          ENDIF
+        EndDo
+        
+        tab4t = parcours%interp_loc%tab4t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
+        memberinall = parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1)
+        
+        tab5t = parcours%interp_loc%tab5t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
+        memberinall2 = 
+     &       parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1)
+        
+        find_list_update = .TRUE.   
+        Exit Find_loop
+      End Do Find_loop  
+                              
+      End Subroutine Agrif_Find_list_update  
+      
+      Subroutine Agrif_AddTo_list_update(list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim
+     &      ,tab4t,tab5t,memberinall,memberinall2)
+          
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
+
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+            
+       Allocate(parcours)
+      Allocate(parcours%interp_loc)
+      
+      parcours%interp_loc%pttab(1:nbdim) = pttab(1:nbdim)
+      parcours%interp_loc%petab(1:nbdim) = petab(1:nbdim)
+      parcours%interp_loc%pttab_child(1:nbdim) = pttab_child(1:nbdim)
+      parcours%interp_loc%pttab_parent(1:nbdim) = pttab_parent(1:nbdim)
+      Allocate(parcours%interp_loc%tab4t(nbdim,0:Agrif_Nbprocs-1,4))
+      Allocate(parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1))
+      
+      Allocate(parcours%interp_loc%tab5t(nbdim,0:Agrif_Nbprocs-1,4))
+      Allocate(parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1))
+            
+      parcours%interp_loc%tab4t=tab4t   
+      parcours%interp_loc%memberinall=memberinall
+ 
+      parcours%interp_loc%tab5t=tab5t   
+      parcours%interp_loc%memberinall2=memberinall2
+            
+      parcours%suiv => list_update
+      
+      list_update => parcours
+      
+      End Subroutine Agrif_Addto_list_update
+#endif
+           
+      End Module Agrif_Update
+
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_1D_Recursive
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_1D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 1D grid variable on the parent grid.
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C
+C     Arguments
+      USE Agrif_Update
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(nbdim):indmax(nbdim))           :: tempP
+      REAL, DIMENSION(pttab_child(nbdim):petab_child(nbdim)) :: tempC
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+      
+      Call Agrif_UpdateBase(TypeUpdate(1),
+     &                  tempP(indmin(nbdim):indmax(nbdim)),
+     &                  tempC(pttab_child(nbdim):petab_child(nbdim)),
+     &                  indmin(nbdim),indmax(nbdim),           
+     &                  pttab_child(nbdim),petab_child(nbdim),
+     &                  s_parent(nbdim),s_child(nbdim),
+     &                  ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_1D_recursive      
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdatebasic.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdatebasic.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modupdatebasic.F	(revision 4536)
@@ -0,0 +1,299 @@
+!
+! $Id$
+!
+C     AGRIF (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place -  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Updatebasic
+C      
+C
+      Module Agrif_Updatebasic
+C
+CCC   Description:
+CCC   Module containing different procedures of update (copy,average,
+CCC   full_weighting) used in the Agrif_Update module.
+C
+C     Modules used:
+C
+      USE Agrif_types
+      
+      IMPLICIT NONE
+C             
+
+      CONTAINS
+C     Define procedures contained in this module
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Copy1d  
+C     ************************************************************************** 
+C
+      Subroutine agrif_copy1d(x,y,np,nc,
+     &                  s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do a copy on a parent grid (vector x) from its child grid 
+CCC   (vector y).  
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C        
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL, DIMENSION(np) :: x      
+      REAL, DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child
+      REAL                :: ds_parent,ds_child
+C
+C     Local variables
+      INTEGER :: i,locind_child_left,coeffraf
+C 
+C
+      coeffraf = nint(ds_parent/ds_child)
+C
+      if (coeffraf == 1) then
+C
+          locind_child_left = 1 + nint((s_parent - s_child)/ds_child)
+C        
+          x(1:np) = y(locind_child_left:locind_child_left+np-1)
+C
+          return
+C
+      endif
+C
+      
+      locind_child_left = 1 + nint((s_parent - s_child)/ds_child)
+      
+      do i = 1,np
+C      
+         x(i) = y(locind_child_left)
+C
+         locind_child_left = locind_child_left + coeffraf
+C         
+      enddo    
+       
+C
+      Return 
+C
+C
+      End Subroutine agrif_copy1d
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Average1d  
+C     ************************************************************************** 
+C   
+      Subroutine average1d(x,y,np,nc,
+     &                     s_parent,s_child,ds_parent,ds_child) 
+C
+CCC   Description:
+CCC   Subroutine to do an update by average on a parent grid (vector x)from its 
+CCC   child grid (vector y).
+C
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL, DIMENSION(np) :: x      
+      REAL, DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child
+      REAL                :: ds_parent,ds_child
+C
+C     Local variables
+      INTEGER :: i,locind_child_left,coeffraf,ii
+      REAL    :: xpos 
+      INTEGER :: nbnonnuls
+      INTEGER :: diffmod
+C 
+C
+      coeffraf = nint(ds_parent/ds_child)
+C
+      if (coeffraf == 1) then
+C
+          locind_child_left = 1 + nint((s_parent - s_child)/ds_child)
+C        
+          x(1:np) = y(locind_child_left:locind_child_left+np-1)
+C
+          return
+C
+      endif
+C
+      xpos = s_parent      
+      
+      x = 0.
+C
+      diffmod = 0
+      
+      IF ( mod(coeffraf,2) == 0 ) diffmod = 1
+
+        locind_child_left = 1 + agrif_int((xpos - s_child)/ds_child)
+      
+      do i = 1,np
+C
+
+C
+c        if ((locind_child_left-1 < 1) 
+c     &      .OR. (locind_child_left+1 > nc)) then 
+C
+c            x(i) = y(locind_child_left)                
+C
+c          else 
+          nbnonnuls = 0
+          Do ii = -coeffraf/2+locind_child_left+diffmod,
+     &                coeffraf/2+locind_child_left
+C 
+            IF (Agrif_UseSpecialValueInUpdate) THEN
+            IF (y(ii) .NE. Agrif_SpecialValueFineGrid) THEN
+               nbnonnuls = nbnonnuls + 1
+               x(i) = x(i) + y(ii)
+            ENDIF
+            ELSE
+               x(i) = x(i) + y(ii)
+            ENDIF
+          End Do
+            IF (Agrif_UseSpecialValueInUpdate) THEN
+                 IF (nbnonnuls .NE. 0) THEN
+                    x(i) = x(i)/nbnonnuls
+                 ELSE
+                    x(i) = Agrif_SpecialValueFineGrid
+                 ENDIF
+            ELSE
+                 x(i) = x(i)/coeffraf
+            ENDIF
+C
+c       endif
+C
+c        xpos = xpos + ds_parent
+        locind_child_left = locind_child_left + coeffraf
+C
+      enddo
+C
+      Return 
+C            
+C     
+      End Subroutine average1d
+C
+C
+C
+C     **************************************************************************  
+CCC   Subroutine Full_weighting1d  
+C     **************************************************************************  
+C
+      Subroutine full_weighting1D(x,y,np,nc,
+     &                            s_parent,s_child,ds_parent,ds_child,
+     &                            coeffraf,locind_child_left) 
+C
+CCC   Description:
+CCC   Subroutine to do an update by full_weighting on a parent grid (vector x) 
+CCC   from its child grid (vector y).
+C 
+C     Arguments
+      INTEGER             :: np,nc      
+      REAL, DIMENSION(np) :: x      
+      REAL, DIMENSION(nc) :: y  
+      REAL                :: s_parent,s_child
+      REAL                :: ds_parent,ds_child
+C
+C     Local variables
+      INTEGER :: i,locind_child_left,coeffraf
+      REAL    :: xpos,sumweight,weight
+      INTEGER :: ii,diffmod
+      REAL :: xposfin
+      INTEGER :: it1,it2
+      INTEGER :: i1,i2
+      REAL :: invsumweight
+      REAL :: weights(-(coeffraf-1):coeffraf-1)
+      
+C
+C
+      if (coeffraf == 1) then
+C        
+          x(1:np) = y(locind_child_left:locind_child_left+np-1)
+C
+          return
+C
+      endif
+C
+      xpos = s_parent      
+      
+       x = 0.
+
+       xposfin = s_child + ds_child * (locind_child_left - 1)
+       IF (abs(xposfin - xpos).LT.0.001) THEN
+          diffmod = 0
+       ELSE
+          diffmod = 1
+       ENDIF
+C
+             
+       it1 = -(coeffraf-1)
+       i1 = -(coeffraf-1)+locind_child_left+diffmod
+       i2 = 2*coeffraf - 2
+       
+      invsumweight=1./coeffraf**2
+      do i=-(coeffraf-1),0
+        weights(i) = invsumweight*(coeffraf + i)
+      enddo
+      do i=1,coeffraf-1
+        weights(i) = invsumweight*(coeffraf - i)
+      enddo
+
+      sumweight = 0                    
+      do i = 1,np
+C
+          it2 = it1
+          Do ii = i1,i1+i2
+C
+           IF (Agrif_UseSpecialValueInUpdate) THEN
+            IF (y(ii) .NE. Agrif_SpecialValueFineGrid) THEN
+               x(i) = x(i) + weights(it2)*y(ii)
+               sumweight = sumweight+weights(it2)
+            ENDIF
+           ELSE           
+               x(i) = x(i) + weights(it2)*y(ii)
+           ENDIF           
+           
+          it2 = it2+1
+          End Do
+
+           IF (Agrif_UseSpecialValueInUpdate) THEN          
+                 IF (sumweight .NE. 0.) THEN
+                    x(i) = x(i)/sumweight
+                    sumweight = 0
+                 ELSE
+                    x(i) = Agrif_SpecialValueFineGrid
+                 ENDIF
+           ENDIF
+        
+        i1 = i1 + coeffraf
+C
+      enddo    
+C
+      Return 
+C            
+C
+      End Subroutine full_weighting1D 
+
+C
+      End module AGRIF_updatebasic
Index: /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modutil.F
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modutil.F	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/AGRIF_FILES/modutil.F	(revision 4536)
@@ -0,0 +1,799 @@
+!
+! $Id$
+!
+C     Agrif (Adaptive Grid Refinement In Fortran)
+C
+C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+C                        Christophe Vouland (Christophe.Vouland@imag.fr)    
+C
+C     This program is free software; you can redistribute it and/or modify
+C     it under the terms of the GNU General Public License as published by
+C     the Free Software Foundation; either version 2 of the License, or
+C     (at your option) any later version.
+C
+C     This program is distributed in the hope that it will be useful,
+C     but WITHOUT ANY WARRANTY; without even the implied warranty of
+C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+C     GNU General Public License for more details.
+C
+C     You should have received a copy of the GNU General Public License
+C     along with this program; if not, write to the Free Software
+C     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+C
+C
+C
+CCC   Module Agrif_Util 
+C 
+      Module Agrif_Util 
+C
+C
+CCC   Description:   
+CCC   This module contains the two procedures called in the main program : 
+CCC   Agrif_Init_Grids allowing the initialization of the root coarse grid, and
+CCC   Agrif_Step allowing the creation of the grid hierarchy and the management
+CCC   of the time integration. 
+C
+C     Modules used:
+C
+      Use Agrif_Clustering    
+      Use Agrif_bcfunction
+C      
+      IMPLICIT NONE
+C
+      Contains
+C     Definition of procedures contained in this module.
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Step
+C     **************************************************************************
+C 
+      Subroutine Agrif_Step(procname) 
+C
+CCC   Description:
+CCC   Subroutine to create the grid hierarchy and to manage the time integration 
+CCC   procedure. It is called in the main program.
+C
+CC    Method:
+CC    Call on subroutines Agrif_Regrid and Agrif_Integrate.
+C
+C     Declarations:
+C
+      Optional :: procname
+      External :: procname
+C
+#ifdef AGRIF_MPI
+      Integer      :: code
+#include "mpif.h"
+C
+C
+      If (Agrif_Mygrid % ngridstep == 0) Then
+          Call MPI_COMM_SIZE(MPI_COMM_WORLD,Agrif_Nbprocs,code)
+          Call MPI_COMM_RANK(MPI_COMM_WORLD,Agrif_ProcRank,code)
+          Call MPI_COMM_GROUP(MPI_COMM_WORLD,Agrif_Group,code)
+      endif
+#endif
+C
+C     Creation and initialization of the grid hierarchy 
+C
+C  
+C    Set the clustering variables
+C
+      Call Agrif_clustering_def()
+C      
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then
+C     
+         If (Agrif_Mygrid % ngridstep == 0) then
+C
+            Call Agrif_Regrid
+C 
+            Call Agrif_Instance           
+     &          (Agrif_Mygrid)           
+         endif
+C
+      else
+C    
+         If (mod(Agrif_Mygrid % ngridstep, Agrif_Regridding) == 0) then
+C
+            Call Agrif_Regrid
+C  
+            Call Agrif_Instance           
+     &          (Agrif_Mygrid)  
+C            
+         endif
+C
+      endif
+C
+C     Time integration of the grid hierarchy
+C
+      If (present(procname)) Then
+         Call Agrif_Integrate (Agrif_Mygrid,procname)
+      Else
+         Call Agrif_Integrate (Agrif_Mygrid)      
+      endif
+C    
+      If (associated(Agrif_Mygrid%child_grids)) 
+     &   Call Agrif_Instance (Agrif_Mygrid)
+C
+      Return
+C             
+      End Subroutine Agrif_Step      
+
+C     **************************************************************************
+CCC   Subroutine Agrif_Step_Child
+C     **************************************************************************
+C
+      Subroutine Agrif_Step_Child(procname)
+C
+CCC   Description:
+CCC   Subroutine to create the grid hierarchy and to manage the time integration
+CCC   procedure. It is called in the main program.
+C
+CC    Method:
+CC    Call on subroutines Agrif_Regrid and Agrif_Integrate.
+C
+C     Declarations:
+C
+      Optional :: procname
+      External :: procname
+C
+C     Time integration of the grid hierarchy
+C
+      If (present(procname)) Then
+         Call Agrif_Integrate_Child (Agrif_Mygrid,procname)
+      Else
+         Call Agrif_Integrate_Child (Agrif_Mygrid)
+      endif
+C    
+      If (associated(Agrif_Mygrid%child_grids))
+     &   Call Agrif_Instance (Agrif_Mygrid)
+C
+      Return
+C
+      End Subroutine Agrif_Step_Child
+
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Regrid
+C     **************************************************************************
+C
+      Subroutine Agrif_Regrid
+C
+CCC   Description:
+CCC   Subroutine to create the grid hierarchy from fixed grids and 
+CC       adaptive mesh refinement.
+C
+CC    Method:        
+C
+C     Declarations:
+C
+C     Local variables      
+      Type(Agrif_Rectangle), Pointer     :: coarsegrid_fixed
+      Type(Agrif_Rectangle), Pointer     :: coarsegrid_moving  
+      INTEGER                            :: j
+      INTEGER :: nunit
+      INTEGER                            :: iii
+      Logical :: BEXIST
+C 
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 )
+     &   Call Agrif_detect_all(Agrif_Mygrid) ! Detection of areas to be refined
+C
+      Allocate(coarsegrid_fixed)
+      Allocate(coarsegrid_moving)
+C
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) 
+     &    Call Agrif_Cluster_All(Agrif_Mygrid,coarsegrid_moving) ! Clustering
+C
+      if ( Agrif_USE_FIXED_GRIDS .EQ. 1 .OR. 
+     &     Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then
+C
+      If (Agrif_Mygrid % ngridstep == 0) Then
+          nunit = Agrif_Get_Unit()
+          open(nunit,file='AGRIF_FixedGrids.in',form='formatted',
+     &           status="old",ERR=99) ! Opening of the Agrif_FixedGrids.in file
+          j = 1
+C         Creation of the grid hierarchy from the Agrif_FixedGrids.in file 
+            do iii = 1 , Agrif_Probdim
+               coarsegrid_fixed % imin(iii) = 1
+               coarsegrid_fixed % imax(iii) = Agrif_Mygrid % nb(iii) + 1
+            enddo
+C      
+            Call Agrif_Read_Fix_Grd (coarsegrid_fixed,j,nunit)     
+            close(nunit) ! Closing of the Agrif_FixedGrids.in file 
+C
+          Nullify(Agrif_oldmygrid)
+          Nullify(Agrif_Mygrid  % child_grids)
+C        
+C         Creation of the grid hierarchy from coarsegrid_fixed
+            Call Agrif_Create_Grids (Agrif_Mygrid,coarsegrid_fixed)
+        Else        
+          Agrif_oldmygrid => Agrif_Mygrid % child_grids
+         endif
+      else
+      Agrif_oldmygrid => Agrif_Mygrid % child_grids
+      Nullify(Agrif_Mygrid  % child_grids)
+      endif
+C
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then
+C      
+      Call Agrif_Free_before_All(Agrif_oldmygrid)
+C 
+C     Creation of the grid hierarchy from coarsegrid_moving    
+      Call Agrif_Create_Grids
+     &     (Agrif_Mygrid,coarsegrid_moving)
+C
+      endif
+C
+C     Initialization of the grid hierarchy by copy or interpolation
+C
+      Call Agrif_Init_Hierarchy(Agrif_Mygrid)
+C
+      if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) 
+     &        Call Agrif_Free_after_All(Agrif_oldmygrid)
+C
+      Deallocate(coarsegrid_fixed)
+      Deallocate(coarsegrid_moving)
+C      
+      Return
+C
+C     Opening error
+C
+   99 INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST)
+      If (.not. BEXIST) Then
+          print*,'ERROR : File AGRIF_FixedGrids.in not found.'
+          STOP 
+        Else
+          print*,'Error opening file AGRIF_FixedGrids.in'
+          STOP         
+      endif     
+C      
+      End Subroutine Agrif_Regrid
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_detect_All
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_detect_all(g)
+C
+CCC   Description:
+CCC   Subroutine to detect areas to be refined.
+C
+CC    Method:        
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      TYPE(Agrif_Grid) ,pointer  :: g        ! Pointer on the current grid
+C      
+C     Local variables
+      Type(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive 
+                                             ! procedure      
+      INTEGER, DIMENSION(3)      :: size
+      INTEGER                    :: iii
+      Real :: g_eps     
+C
+      parcours => g % child_grids
+C  
+C     To be positioned on the finer grids of the grid hierarchy          
+C  
+      do while (associated(parcours))       
+         Call Agrif_detect_all (parcours % gr)  
+        parcours => parcours % next             
+      enddo
+C
+      g_eps = huge(1.)
+      do iii = 1 , Agrif_Probdim
+         g_eps=min(g_eps,g%Agrif_d(iii))
+      enddo
+C
+      g_eps = g_eps/100.
+C          
+      if ( Agrif_Probdim .EQ. 1 ) g%tabpoint1D=0
+      if ( Agrif_Probdim .EQ. 2 ) g%tabpoint2D=0
+      if ( Agrif_Probdim .EQ. 3 ) g%tabpoint3D=0
+C      
+      do iii = 1 , Agrif_Probdim
+         if (g%Agrif_d(iii)/Agrif_coeffref(iii).LT.
+     &                     (Agrif_mind(iii)-g_eps)) Return
+      enddo
+C                                       
+      Call Agrif_instance(g)
+C  
+C     Detection (Agrif_detect is a user s routine)
+C      
+      do iii = 1 , Agrif_Probdim
+         size(iii) = g%nb(iii) + 1
+      enddo
+C
+      SELECT CASE (Agrif_Probdim)
+      CASE (1) 
+         Call Agrif_detect(g%tabpoint1D,size)
+      CASE (2) 
+         Call Agrif_detect(g%tabpoint2D,size)
+      CASE (3) 
+         Call Agrif_detect(g%tabpoint3D,size)
+      END SELECT
+C
+C     Addition of the areas detected on the child grids
+C      
+      parcours => g % child_grids 
+C           
+      Do while (associated(parcours))
+        Call Agrif_Add_detected_areas (g,parcours % gr)
+        parcours => parcours % next 
+      enddo
+C     
+      Return      
+C
+      End Subroutine Agrif_detect_all
+C      
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Add_detected_areas
+C     **************************************************************************
+C      
+      Subroutine Agrif_Add_detected_areas(parentgrid,childgrid)
+C
+CCC   Description:
+CCC   Subroutine to add on the parent grid the areas detected 
+CC       on its child grids.
+C
+CC    Method:        
+C
+C     Declarations:
+C
+      
+C 
+      Type(Agrif_Grid),pointer   :: parentgrid,childgrid
+C      
+      Integer :: i,j,k
+C
+      do i = 1,childgrid%nb(1)+1
+         if ( Agrif_Probdim .EQ. 1 ) then
+            If (childgrid%tabpoint1D(i).EQ.1) Then
+                parentgrid%tabpoint1D(childgrid%ix(1)+
+     &                 (i-1)/Agrif_Coeffref(1)) = 1
+            endif
+         else
+            do j=1,childgrid%nb(2)+1
+               if (Agrif_Probdim.EQ.2) then
+              If (childgrid%tabpoint2D(i,j).EQ.1) Then
+                  parentgrid%tabpoint2D(
+     &                  childgrid%ix(1)+(i-1)/Agrif_Coeffref(1),
+     &                  childgrid%ix(2)+(j-1)/Agrif_Coeffref(2)) = 1
+                  endif
+               else
+                  do k=1,childgrid%nb(3)+1
+                If (childgrid%tabpoint3D(i,j,k).EQ.1) Then
+                    parentgrid%tabpoint3D(
+     &                     childgrid%ix(1)+(i-1)/Agrif_Coeffref(1),
+     &                     childgrid%ix(2)+(j-1)/Agrif_Coeffref(2),
+     &                     childgrid%ix(3)+(k-1)/Agrif_Coeffref(3)) = 1
+                     endif
+                  enddo
+               endif
+            enddo
+         endif
+      enddo
+C      
+      Return
+C
+      End Subroutine Agrif_Add_detected_areas   
+C      
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Free_before_All
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Free_before_All(g)
+C
+CCC   Description:
+C
+CC    Method:        
+C
+C     Declarations:
+C
+C     Pointer argument    
+      Type(Agrif_pgrid),pointer   :: g        ! Pointer on the current grid
+C
+C     Local pointer
+      Type(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive 
+                                             ! procedure      
+C
+C
+      parcours => g        
+C      
+      Do while (associated(parcours))     
+        If (.not. parcours%gr%fixed) Then
+            Call Agrif_Free_data_before(parcours%gr)
+            parcours % gr % oldgrid = .TRUE.        
+        endif
+C
+        Call Agrif_Free_before_all (parcours % gr % child_grids)
+C  
+        parcours => parcours % next             
+      enddo
+C     
+      Return      
+C
+C
+      End Subroutine Agrif_Free_before_All
+C
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Free_after_All
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Free_after_All(g)
+C
+CCC   Description:
+C
+CC    Method:        
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      Type(Agrif_pgrid),pointer   :: g       ! Pointer on the current grid
+C
+C     Local pointers
+      TYPE(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive proced
+      Type(Agrif_pgrid),pointer  :: preparcours   
+      Type(Agrif_pgrid),pointer  :: preparcoursini 
+C
+C
+      Allocate(preparcours)
+C 
+      preparcoursini => preparcours
+C 
+      Nullify(preparcours % gr)
+C 
+      preparcours % next => g
+C
+      parcours => g
+C      
+      Do while (associated(parcours))
+C
+         if ( (.NOT. parcours% gr% fixed) .AND.
+     &        (parcours% gr% oldgrid    ) ) then
+          Call Agrif_Free_data_after(parcours%gr)
+         endif
+C
+         Call Agrif_Free_after_all (parcours % gr % child_grids)
+C
+      If (parcours % gr % oldgrid) Then
+          Deallocate(parcours % gr)
+          preparcours % next => parcours % next
+          Deallocate(parcours)
+          parcours => preparcours % next
+        Else
+          preparcours => preparcours % next
+          parcours => parcours % next 
+         endif       
+      enddo
+C
+      Deallocate(preparcoursini)
+C     
+      Return      
+C
+      End Subroutine Agrif_Free_after_All
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Integrate
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Integrate(g, procname)         
+C
+CCC   Description:
+CCC   Subroutine to manage the time integration of the grid hierarchy.
+C
+CC    Method:
+CC    Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step
+C
+C     Declarations:
+C
+      
+C      
+C     Pointer argument    
+      Type(Agrif_Grid),pointer   :: g        ! Pointer on the current grid
+C
+C     main procedure name
+      Optional :: procname
+      External :: procname      
+C      
+C     Local pointer
+      Type(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive 
+                                             ! procedure
+C
+C     Local scalars
+      INTEGER                    :: nbt      ! Number of time steps 
+                                             ! of the current grid
+      INTEGER                    :: k        
+      INTEGER                    :: iii
+C  
+C     Instanciation of the variables of the current grid
+      If (g%fixedrank .NE.0) Then      
+      Call Agrif_Instance
+     &     (g)
+      End If
+C       
+C     One step on the current grid      
+C
+      If (present(procname)) Then
+         Call procname ()      
+      Else
+        write(*,*) 'The name of the step subroutine has not '
+        write(*,*) 'been given in the subroutine Agrif_Integrate'
+        stop
+      endif
+C
+C     Number of time steps on the current grid      
+C
+      g%ngridstep = g % ngridstep + 1
+C      
+      parcours => g % child_grids
+C    
+C     Recursive procedure for the time integration of the grid hierarchy      
+      Do while (associated(parcours))
+C
+C       Instanciation of the variables of the current grid            
+        Call Agrif_Instance
+     &           (parcours % gr)
+C       
+C       Number of time steps
+        nbt = 1
+        do iii = 1 , Agrif_Probdim
+           nbt = max(nbt, parcours % gr % timeref(iii))
+        enddo
+C       
+        Do k = 1,nbt
+C       
+           If (present(procname)) Then
+                 Call Agrif_Integrate (parcours % gr, procname)
+           Else
+                 Call Agrif_Integrate (parcours % gr)      
+           endif
+C       
+        enddo     
+C  
+        parcours => parcours % next
+C     
+      enddo
+C
+C      
+      End Subroutine Agrif_Integrate 
+
+C     **************************************************************************
+CCC   Subroutine Agrif_Integrate_Child
+C     **************************************************************************
+C
+      Recursive Subroutine Agrif_Integrate_Child(g,procname)
+C
+CCC   Description:
+CCC   Subroutine to manage the time integration of the grid hierarchy.
+C
+CC    Method:
+CC    Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step.
+C
+C     Declarations:
+C
+
+C
+C     Pointer argument
+      Type(Agrif_Grid),pointer   :: g        ! Pointer on the current grid
+C
+C     main procedure name
+      Optional :: procname
+      External :: procname
+C
+C     Local pointer
+      Type(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive
+                                             ! procedure
+C
+C     One step on the current grid
+C
+      If (present(procname)) Then
+         Call procname ()      
+      Else
+        write(*,*) 'The name of the step subroutine has not '
+        write(*,*) 'been given in the subroutine Agrif_Integrate'
+        stop
+      endif
+C
+C     Number of time steps on the current grid
+C
+C
+      parcours => g % child_grids
+C
+C     Recursive procedure for the time integration of the grid hierarchy      
+      Do while (associated(parcours))
+C
+C       Instanciation of the variables of the current grid
+        Call Agrif_Instance
+     &           (parcours % gr)
+
+C       
+           If (present(procname)) Then
+                 Call Agrif_Integrate_Child (parcours % gr, procname)
+           Else
+                 Call Agrif_Integrate_Child (parcours % gr)
+           endif
+C  
+        parcours => parcours % next
+C     
+      enddo
+C
+C
+      End Subroutine Agrif_Integrate_Child
+
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Init_Grids
+C     **************************************************************************
+C      
+      Subroutine Agrif_Init_Grids
+C
+CCC   Description:
+CCC   Subroutine to initialize the root coarse grid pointed by Agrif_Mygrid. 
+CCC   It is called in the main program.
+C
+C     Declarations:
+C
+C
+      INTEGER :: iii
+C
+C             definition of the probdim and modtypes variables
+C
+#ifdef AGRIF_MPI
+#include "mpif.h"
+      Agrif_MPIPREC = MPI_DOUBLE_PRECISION
+#endif
+      Call Agrif_probdim_modtype_def()
+C      
+      Agrif_UseSpecialValue = .FALSE.
+      Agrif_UseSpecialValueFineGrid = .FALSE.
+      Agrif_SpecialValue = 0.
+      Agrif_SpecialValueFineGrid = 0.
+C      
+C     Allocation of Agrif_Mygrid
+      allocate(Agrif_Mygrid)
+C      
+C     Space and time refinement factors are set to 1 on the root grid
+C
+      do iii = 1 , Agrif_Probdim
+         Agrif_Mygrid % spaceref(iii) = 1
+         Agrif_Mygrid % timeref(iii) = 1
+      enddo
+C      
+C     Initialization of the number of time steps    
+      Agrif_Mygrid % ngridstep = 0
+      Agrif_Mygrid % grid_id = 0
+C
+C     No parent grid for the root coarse grid
+      Nullify(Agrif_Mygrid % parent)
+C      
+C     Initialization of the minimum positions, global abscissa and space steps  
+      do iii= 1 ,  Agrif_Probdim
+         Agrif_Mygrid % ix(iii) = 1            
+         Agrif_Mygrid % Agrif_x(iii) = 0.
+         Agrif_Mygrid % Agrif_d(iii) = 1. 
+C     Borders of the root coarse grid 
+         Agrif_Mygrid % NearRootBorder(iii) = .true.  
+         Agrif_Mygrid % DistantRootBorder(iii) = .true.      
+      enddo
+C  
+C     The root coarse grid is a fixed grid
+      Agrif_Mygrid % fixed = .TRUE.
+C      
+C     Number of the grid pointed by Agrif_Mygrid (root coarse grid)
+      Agrif_Mygrid % rank = 1      
+C 
+C     Number of the root grid as a fixed grid   
+      Agrif_Mygrid % fixedrank = 0  
+C 
+C     Initialization of some fields of the root grid variables     
+      Call Agrif_Create_Var (Agrif_Mygrid)
+C      
+C     Initialization of the other fields of the root grid variables (number of 
+C     cells, positions, number and type of its dimensions, ...)  
+      Call Agrif_Set_numberofcells(Agrif_Mygrid)
+C      
+      Call Agrif_Instance (Agrif_Mygrid)        
+C             
+C     Allocation of the array containing the values of the grid variables
+      Call Agrif_Allocation (Agrif_Mygrid)
+C        
+      Call Agrif_initialisations(Agrif_Mygrid)
+C      
+      nullify(Agrif_Mygrid % child_grids)
+C 
+C     Total number of fixed grids   
+      Agrif_nbfixedgrids = 0         
+C      
+      Call Agrif_Instance (Agrif_Mygrid)
+C        
+      End Subroutine Agrif_Init_Grids  
+C
+C
+C     **************************************************************************
+CCC   Subroutine Agrif_Deallocation
+C     **************************************************************************
+C      
+      Subroutine Agrif_Deallocation
+C
+CCC   Description:
+CCC   Subroutine to initialize the root coarse grid pointed by Agrif_Mygrid. 
+CCC   It is called in the main program.
+C
+C     Declarations:
+C
+C
+      INTEGER :: nb
+C
+C             definition of the probdim and modtypes variables
+C
+      do nb = 1, Agrif_NbVariables
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array1) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array1)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array2) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array2)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array3) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array3)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array4) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array4)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array5) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array5)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % array6) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % array6)
+C
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray1) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray1)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray2) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray2)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray3) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray3)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray4) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray4)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray5) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray5)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % iarray6) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray6)
+C
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray1) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray1)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray2) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray2)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray3) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray3)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray4) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray4)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray5) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray5)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % larray6) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray6)
+C
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % carray1) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % carray1)
+          if ( associated(Agrif_Mygrid % tabvars(nb) % var % carray2) ) 
+     &       Deallocate(Agrif_Mygrid % tabvars(nb) % var % carray2)
+      enddo
+C
+      do nb = 1, Agrif_NbVariables
+        Deallocate(Agrif_Mygrid % tabvars(nb) % var)
+      enddo
+C
+      Deallocate(Agrif_Mygrid % tabvars)
+C
+      Deallocate(Agrif_Mygrid)
+C
+      End Subroutine  Agrif_Deallocation 
+C
+      End module Agrif_Util 
Index: /branches/2010_and_older/dev_001_GM/AGRIF/KEY_CPP
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/KEY_CPP	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/KEY_CPP	(revision 4536)
@@ -0,0 +1,1 @@
+
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/DiversListe.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/DiversListe.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/DiversListe.c	(revision 4536)
@@ -0,0 +1,579 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                           Add_Common_var_1                                 */
+/******************************************************************************/
+/*  This subroutines is used to add the variable defined in common in the     */
+/*     List_Common_Var                                                        */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Common_var_1()
+{
+   listvar *newvar;
+   listvar *newvar2;
+   variable *newvariable;
+   listdim *dims;
+   char listdimension[LONGNOM];
+   char ligne[LONGNOM];
+   int out;
+
+   if ( firstpass == 1 )
+   {
+
+   newvar = (listvar *)malloc(sizeof(listvar));
+   newvariable = (variable *)malloc(sizeof(variable));
+   /*                                                                         */
+   Init_Variable(newvariable);
+   /*                                                                         */
+   strcpy(newvariable->v_nomvar,commonvar);
+   strcpy(newvariable->v_commonname,commonblockname);
+   strcpy(newvariable->v_modulename,curmodulename);
+   strcpy(newvariable->v_subroutinename,subroutinename);
+   newvariable->v_positioninblock= positioninblock;
+   newvariable->v_common=1;
+   strcpy(newvariable->v_commoninfile,mainfile);
+
+   newvar->var = newvariable;
+
+   if ( commondim )
+   {
+      newvariable->v_dimension=commondim;
+      newvariable->v_dimensiongiven=1;
+      newvariable->v_nbdim=num_dims(commondim);
+      /* Creation of the string for the dimension of this variable            */
+      dimsempty = 1;
+      strcpy(listdimension,"");
+
+      if ( commondim )
+      {
+         dims = commondim;
+         while (dims)
+         {
+            if ( strcasecmp(dims->dim.first,"") ||
+                 strcasecmp(dims->dim.last,""))  dimsempty = 0;
+            sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
+            strcat(listdimension,ligne);
+            if ( dims->suiv ) strcat(listdimension,",");
+            dims = dims->suiv;
+         }
+         if ( dimsempty == 1 ) newvariable->v_dimsempty=1;
+      }
+      strcpy(newvariable->v_readedlistdimension,listdimension);
+   }
+
+
+   newvar->suiv = NULL;
+
+   if ( !List_Common_Var )
+   {
+      List_Common_Var = newvar;
+   }
+   else
+   {
+      newvar2 = List_Common_Var;
+      out = 0 ;
+      while ( newvar2 && out == 0 )
+      {
+         if ( !strcasecmp(newvar2->var->v_nomvar,commonvar) &&
+              !strcasecmp(newvar2->var->v_commonname,commonblockname) &&
+              !strcasecmp(newvar2->var->v_subroutinename,subroutinename)
+                          ) out = 1 ;
+         else newvar2 = newvar2->suiv;
+      }
+      if ( out == 0 )
+      {
+         newvar->suiv = List_Common_Var;
+         List_Common_Var = newvar;
+      }
+      else
+      {
+         free(newvar);
+      }
+   }
+   }
+}
+
+/******************************************************************************/
+/*                           Addtolistnom                                     */
+/******************************************************************************/
+/* This subroutine is used to add a variable to the list                      */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+listnom *Addtolistnom(char *nom, listnom *listin,int value)
+{
+   listnom *newnom;
+   listnom *parcours;
+   int out;
+
+   newnom=(listnom *) malloc (sizeof (listnom));
+   strcpy(newnom->o_nom,nom);
+   newnom->o_val = value;
+   newnom->suiv = NULL;
+
+   if ( !listin ) listin = newnom;
+   else
+   {
+      parcours = listin;
+      out = 0 ;
+      while ( parcours && out == 0 )
+      {
+         if ( !strcasecmp(parcours->o_nom,nom) ) out = 1 ;
+         else parcours=parcours->suiv;
+      }
+      if ( out == 0 )
+      {
+          newnom->suiv = listin;
+          listin = newnom;
+      }
+      else
+      {
+         free(newnom);
+      }
+   }
+   return listin;
+}
+
+/******************************************************************************/
+/*                           Addtolistname                                    */
+/******************************************************************************/
+/* This subroutine is used to add a        variable to the list               */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+listname *Addtolistname(char *nom,listname *input)
+{
+   listname *newnom;
+   listname *parcours;
+   int out;
+
+   if ( !input )
+   {
+      newnom=(listname *) malloc (sizeof (listname));
+      strcpy(newnom->n_name,nom);
+      newnom->suiv = NULL;
+      input = newnom;
+   }
+   else
+   {
+      parcours = input;
+      out = 0 ;
+      while ( parcours && out == 0 )
+      {
+         if ( !strcasecmp(parcours->n_name,nom) ) out = 1;
+         else parcours=parcours->suiv;
+      }
+      if ( out == 0 )
+      {
+         newnom=(listname *) malloc (sizeof (listname));
+         strcpy(newnom->n_name,nom);
+         newnom->suiv = input;
+         input = newnom;
+      }
+   }
+   return input;
+}
+
+/******************************************************************************/
+/*                    ModuleIsDefineInInputFile                               */
+/******************************************************************************/
+/* This subroutine is used to know if the module is defined in the input file */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+int ModuleIsDefineInInputFile(char *name)
+{
+   listnom *newnom;
+   int out;
+
+   out = 0;
+   if ( listofmodules )
+   {
+      newnom = listofmodules;
+      while( newnom && out == 0 )
+      {
+         if ( !strcasecmp(newnom->o_nom,name) ) out = 1 ;
+         else newnom=newnom->suiv;
+      }
+   }
+   return out;
+}
+
+/******************************************************************************/
+/*                      Addmoduletothelisttmp                                 */
+/******************************************************************************/
+/* This subroutine is used to add a record to a list of struct                */
+/* listusemodule                                                              */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub ... USE mod1 ===> insert in list                      */
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*       list =  listofmoduletmp                                              */
+/*                                                                            */
+/******************************************************************************/
+void Addmoduletothelisttmp(char *name)
+{
+  listusemodule *newmodule;
+  listusemodule *parcours;
+  int out;
+
+  if ( !listofmoduletmp)
+  {
+    newmodule =(listusemodule *)malloc(sizeof(listusemodule));
+    strcpy(newmodule->u_usemodule,name);
+    strcpy(newmodule->u_cursubroutine,subroutinename);
+    newmodule->suiv = NULL;
+    listofmoduletmp = newmodule ;
+  }
+  else
+  {
+    parcours = listofmoduletmp;
+    out = 0;
+    while( parcours && out == 0 )
+    {
+       if ( !strcasecmp(parcours->u_usemodule,name) ) out = 1;
+       else parcours = parcours->suiv;
+    }
+    if ( out == 0 )
+    {
+       newmodule =(listusemodule *)malloc(sizeof(listusemodule));
+       strcpy(newmodule->u_usemodule,name);
+       strcpy(newmodule->u_cursubroutine,subroutinename);
+       newmodule->suiv = listofmoduletmp;
+       listofmoduletmp = newmodule;
+    }
+  }
+}
+
+/******************************************************************************/
+/*                          Add_NameOfModule_1                                */
+/******************************************************************************/
+/* This subroutine is used to add a        variable to the list               */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_NameOfModule_1(char *nom)
+{
+   listnom *newnom;
+
+   if ( firstpass == 1 )
+   {
+      newnom=(listnom *) malloc (sizeof (listnom));
+      strcpy(newnom->o_nom,nom);
+      newnom->suiv = List_NameOfModule;
+      List_NameOfModule = newnom;
+   }
+}
+
+/******************************************************************************/
+/*                          Add_NameOfCommon_1                                */
+/******************************************************************************/
+/* This subroutine is used to add a        variable to the list               */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_NameOfCommon_1(char *nom)
+{
+   listnom *newnom;
+   listnom *parcours;
+
+   if ( firstpass == 1 )
+   {
+      parcours = List_NameOfCommon;
+      while ( parcours && strcasecmp(parcours->o_nom,nom) )
+                                                      parcours = parcours->suiv;
+      if ( !parcours )
+      {
+         newnom=(listnom *) malloc (sizeof (listnom));
+         strcpy(newnom->o_nom,nom);
+         newnom->suiv = List_NameOfCommon;
+         List_NameOfCommon = newnom;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                     Add_CouplePointed_Var_1                                */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should complete the listvarpointtovar                                   */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_CouplePointed_Var_1(char *namemodule,listcouple *couple)
+{
+   listvarpointtovar *pointtmp;
+
+   if ( firstpass == 1 )
+   {
+      /* we should complete the List_CouplePointed_Var                        */
+      pointtmp=(listvarpointtovar *)malloc(sizeof(listvarpointtovar));
+      strcpy(pointtmp->t_usemodule,namemodule);
+      strcpy(pointtmp->t_cursubroutine,subroutinename);
+      pointtmp->t_couple = couple;
+      if ( List_CouplePointed_Var )
+      {
+         pointtmp->suiv = List_CouplePointed_Var;
+         List_CouplePointed_Var = pointtmp;
+      }
+      else
+      {
+         pointtmp->suiv = NULL;
+         List_CouplePointed_Var = pointtmp;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                           Add_Include_1                                    */
+/******************************************************************************/
+/* This subroutine is used to add a record to a list of struct                */
+/*  List_Include                                                              */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub ... include mod1 ===> insert in list                  */
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*       list =  List_Include                                                 */
+/*                                                                            */
+/******************************************************************************/
+void Add_Include_1(char *name)
+{
+  listusemodule *newinclude;
+
+  if ( firstpass == 1 )
+  {
+  newinclude =(listusemodule *)malloc(sizeof(listusemodule));
+  strcpy(newinclude->u_usemodule,name);
+  strcpy(newinclude->u_cursubroutine,subroutinename);
+  newinclude->suiv = NULL;
+
+  if ( !List_Include)
+  {
+     List_Include  = newinclude ;
+  }
+  else
+  {
+    newinclude->suiv = List_Include;
+    List_Include = newinclude;
+  }
+  }
+}
+
+/******************************************************************************/
+/*                     Add_ImplicitNoneSubroutine_1                           */
+/******************************************************************************/
+/* This subroutine is used to add a record to a list of struct                */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_ImplicitNoneSubroutine_1()
+{
+
+  if ( firstpass == 1 )
+  {
+     List_ImplicitNoneSubroutine = Addtolistname(subroutinename,
+                                                   List_ImplicitNoneSubroutine);
+  }
+}
+
+
+/******************************************************************************/
+/*                        WriteIncludeDeclaration                             */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void WriteIncludeDeclaration()
+{
+  listusemodule *newinclude;
+
+  newinclude = List_Include;
+  fprintf(fortranout,"\n");
+  while ( newinclude )
+  {
+     if ( !strcasecmp(newinclude->u_cursubroutine,subroutinename) )
+     {
+        fprintf(fortranout,"      INCLUDE %s \n",newinclude->u_usemodule);
+     }
+     newinclude = newinclude ->suiv;
+  }
+}
+
+/******************************************************************************/
+/*                          Add_Save_Var_1                                    */
+/******************************************************************************/
+/* This subroutine is used to add a record to List_Save_Var                   */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ Save +--->+ Save +--->+ Save +--->+  Save+             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+void Add_Save_Var_1 (char *name,listdim *d)
+{
+  listvar *newvar;
+  listdim *dims;
+  char ligne[LONGNOM];
+  char listdimension[LONGNOM];
+
+  if ( firstpass == 1 )
+  {
+     newvar=(listvar *)malloc(sizeof(listvar));
+     newvar->var=(variable *)malloc(sizeof(variable));
+     /*                                                                       */
+     Init_Variable(newvar->var);
+     /*                                                                       */
+     newvar->var->v_save=1;
+     strcpy(newvar->var->v_nomvar,name);
+     strcpy(newvar->var->v_modulename,curmodulename);
+     strcpy(newvar->var->v_subroutinename,subroutinename);
+     strcpy(newvar->var->v_commoninfile,mainfile);
+
+     newvar->var->v_dimension=d;
+     /* Creation of the string for the dimension of this variable             */
+     dimsempty = 1;
+     if ( d )
+     {
+        newvar->var->v_dimensiongiven=1;
+        dims = d;
+        while (dims)
+        {
+           if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
+                                                                  dimsempty = 0;
+           sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
+           strcat(listdimension,ligne);
+           if ( dims->suiv )
+           {
+              strcat(listdimension,",");
+           }
+           dims = dims->suiv;
+        }
+        if ( dimsempty == 1 ) newvar->var->v_dimsempty=1;
+     }
+     strcpy(newvar->var->v_readedlistdimension,listdimension);
+     /*                                                                       */
+     newvar->suiv = NULL;
+
+     if ( !List_Save_Var )
+     {
+        List_Save_Var  = newvar ;
+     }
+     else
+     {
+        newvar->suiv = List_Save_Var;
+        List_Save_Var = newvar;
+     }
+  }
+}
+
+void Add_Save_Var_dcl_1 (listvar *var)
+{
+  listvar *newvar;
+  listvar *parcours;
+  listdim *dims;
+  char ligne[LONGNOM];
+  char listdimension[LONGNOM];
+
+  if ( firstpass == 1 )
+  {
+     parcours = var;
+     while ( parcours )
+     {
+        newvar=(listvar *)malloc(sizeof(listvar));
+        newvar->var=(variable *)malloc(sizeof(variable));
+        /*                                                                    */
+        Init_Variable(newvar->var);
+        /*                                                                    */
+        newvar->var->v_save=1;
+        strcpy(newvar->var->v_nomvar,parcours->var->v_nomvar);
+        strcpy(newvar->var->v_modulename,curmodulename);
+        strcpy(newvar->var->v_subroutinename,subroutinename);
+        strcpy(newvar->var->v_commoninfile,mainfile);
+        /*                                                                    */
+        strcpy(newvar->var->v_readedlistdimension,
+             parcours->var->v_readedlistdimension);
+        newvar->var->v_nbdim = parcours->var->v_nbdim;
+        newvar->var->v_dimension = parcours->var->v_dimension;
+        /*                                                                    */
+        newvar->var->v_dimensiongiven=parcours->var->v_dimensiongiven;
+        /*                                                                    */
+        newvar->suiv = NULL;
+
+        if ( !List_Save_Var ) List_Save_Var  = newvar ;
+        else
+        {
+           newvar->suiv = List_Save_Var;
+           List_Save_Var = newvar;
+        }
+        parcours = parcours->suiv;
+     }
+  }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile	(revision 4536)
@@ -0,0 +1,47 @@
+#- option to debug
+C_D = -g # -g -Wall
+# Compilation:
+CC		= @$(C_L) $(C_O) $(C_D)
+#-
+OBJS = main.o WriteInFile.o toamr.o fortran.o  \
+       dependfile.o SubLoopCreation.o WorkWithlistvarindoloop.o \
+       WorkWithvarofsubroutineliste.o WorkWithParameterlist.o \
+       Writedeclarations.o WorkWithglobliste.o UtilFortran.o \
+       UtilNotGridDep.o WorkWithlistdatavariable.o \
+       DiversListe.o UtilAgrif.o WorkWithAllocatelist.o \
+       UtilCharacter.o UtilListe.o UtilFile.o \
+       WorkWithlistofmodulebysubroutine.o WorkWithlistmoduleinfile.o
+
+.SUFFIXES:
+.SUFFIXES: .c .o
+
+all : conv
+	@echo CONV is ok
+
+conv :  $(OBJS)
+	@$(CC) $(OBJS) -o ../$@
+
+main.o : main.c
+fortran.o : fortran.c	
+toamr.o : toamr.c decl.h
+WriteInFile.o : WriteInFile.c decl.h
+dependfile.o : dependfile.c decl.h	
+SubLoopCreation.o : SubLoopCreation.c decl.h	
+WorkWithglobliste.o : WorkWithglobliste.c decl.h	
+WorkWithlistvarindoloop.o : WorkWithlistvarindoloop.c decl.h	
+WorkWithvarofsubroutineliste.o : WorkWithvarofsubroutineliste.c decl.h	
+Writedeclarations.o : Writedeclarations.c decl.h	
+UtilFortran.o : UtilFortran.c decl.h	
+WorkWithParameterlist.o : WorkWithParameterlist.c decl.h	
+UtilNotGridDep.o : UtilNotGridDep.c decl.h	
+WorkWithlistdatavariable.o : WorkWithlistdatavariable.c decl.h	
+DiversListe.o : DiversListe.c decl.h	
+UtilAgrif.o : UtilAgrif.c decl.h	
+WorkWithAllocatelist.o : WorkWithAllocatelist.c decl.h
+UtilCharacter.o : UtilCharacter.c decl.h
+UtilListe.o : UtilListe.c decl.h
+UtilFile.o : UtilFile.c decl.h
+WorkWithlistofmodulebysubroutine.o : WorkWithlistofmodulebysubroutine.c decl.h
+WorkWithlistmoduleinfile.o : WorkWithlistmoduleinfile.c decl.h
+clean : 
+	/bin/rm -f *.o y.output
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile.lex
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile.lex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Makefile.lex	(revision 4536)
@@ -0,0 +1,71 @@
+# Compilation:
+CC		= cc -O -g
+LEX		= flex
+
+# option de flex et pas de lex
+LEXFLAGS=-i
+YACC = byacc -t -v
+
+
+OBJS = main.o WriteInFile.o toamr.o fortran.o  \
+       dependfile.o SubLoopCreation.o WorkWithlistvarindoloop.o \
+       WorkWithvarofsubroutineliste.o WorkWithParameterlist.o \
+       Writedeclarations.o WorkWithglobliste.o UtilFortran.o \
+       UtilNotGridDep.o WorkWithlistdatavariable.o \
+       DiversListe.o UtilAgrif.o WorkWithAllocatelist.o \
+       UtilCharacter.o UtilListe.o UtilFile.o \
+       WorkWithlistofmodulebysubroutine.o WorkWithlistmoduleinfile.o
+
+.SUFFIXES:
+.SUFFIXES: .c .o
+
+all : conv
+
+conv :  $(OBJS)
+	$(CC) $(OBJS)  $(LEXLIB) -o ../$@
+
+main.o : main.c
+main.c : convert.tab.c  convert.yy.c
+	rm -f main.c
+	cat convert.tab.c  convert.yy.c > main.c
+	rm -f convert.yy.c convert.tab.c
+fortran.o : fortran.c
+fortran.c : fortran.tab.c fortran.yy.c
+	rm -f fortran.c
+	cat fortran.tab.c  fortran.yy.c > fortran.c
+	rm -f fortran.yy.c fortran.tab.c
+convert.tab.c : convert.y decl.h
+	$(YACC) convert.y
+	mv -f y.tab.c convert.tab.c
+fortran.tab.c : fortran.y decl.h
+	$(YACC) -p fortran fortran.y
+	mv -f y.tab.c fortran.tab.c
+convert.yy.c : convert.lex
+	$(LEX) $(LEXFLAGS) -oconvert.yy.c convert.lex
+fortran.yy.c : fortran.lex
+	$(LEX) $(LEXFLAGS) -Pfortran -ofortran.yy.c fortran.lex
+	
+toamr.o : toamr.c decl.h
+WriteInFile.o : WriteInFile.c decl.h
+dependfile.o : dependfile.c decl.h
+SubLoopCreation.o : SubLoopCreation.c decl.h
+WorkWithglobliste.o : WorkWithglobliste.c decl.h
+WorkWithlistvarindoloop.o : WorkWithlistvarindoloop.c decl.h
+WorkWithvarofsubroutineliste.o : WorkWithvarofsubroutineliste.c decl.h
+Writedeclarations.o : Writedeclarations.c decl.h
+UtilFortran.o : UtilFortran.c decl.h
+WorkWithParameterlist.o : WorkWithParameterlist.c decl.h
+UtilNotGridDep.o : UtilNotGridDep.c decl.h
+WorkWithlistdatavariable.o : WorkWithlistdatavariable.c decl.h
+DiversListe.o : DiversListe.c decl.h
+UtilAgrif.o : UtilAgrif.c decl.h
+WorkWithAllocatelist.o : WorkWithAllocatelist.c decl.h
+UtilCharacter.o : UtilCharacter.c decl.h
+UtilListe.o : UtilListe.c decl.h
+UtilFile.o : UtilFile.c decl.h
+WorkWithlistofmodulebysubroutine.o : WorkWithlistofmodulebysubroutine.c decl.h
+WorkWithlistmoduleinfile.o : WorkWithlistmoduleinfile.c decl.h
+clean : 
+	/bin/rm -f *.o y.tab.c main.c lex.yy.c fortran.c \
+	fortran.tab.c fortran.yy.c convert.tab.c convert.yy.c \
+	y.output
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/SubLoopCreation.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/SubLoopCreation.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/SubLoopCreation.c	(revision 4536)
@@ -0,0 +1,536 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+
+/******************************************************************************/
+/*     preparation and write of the argument list of a subroutine             */
+/******************************************************************************/
+
+
+/******************************************************************************/
+/*                             writeheadnewsub_0                              */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/* We should write the head of the subroutine sub_loop_<subroutinename>       */
+/* suborfunc = 1 from subroutine                                              */
+/* suborfunc = 2 from function                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void writeheadnewsub_0(int suborfunc)
+{
+   int out;
+   char ligne[LONGNOM];
+   listusemodule *newmodule;
+
+   if ( firstpass == 0 && IsTabvarsUseInArgument_0() == 1 )
+   {
+      if ( todebug == 1 ) printf("Enter in writeheadnewsub_0\n");
+      /* we should add the use agrif_uti l if it is necessary                 */
+      WriteHeadofSubroutineLoop();
+      WriteUsemoduleDeclaration();
+      if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout,
+                                                       "      IMPLICIT NONE\n");
+      WriteIncludeDeclaration();
+      /*                                                                      */
+      /* We should write once the declaration of tables (extract              */
+      /*    from pointer) in the new subroutine                               */
+      if ( mark == 1 ) fprintf(fortranout,"!!! 000000000000000 \n");
+      if ( SubInList_ContainsSubroutine() == 0 ) WriteLocalParamDeclaration();
+      if ( mark == 1 ) fprintf(fortranout,"!!! 111111111111111 \n");
+
+      sprintf(ligne,"\n#include \"ParamFile%s.h\" \n",subroutinename);
+      tofich(fortranout,ligne,1);
+
+   /*   writesub_loopdeclaration_scalar(List_SubroutineArgument_Var,paramout);*/
+      WriteArgumentDeclaration_Sort();
+/*      writesub_loopdeclaration_tab(List_SubroutineArgument_Var,fortranout);*/
+
+      if ( mark == 1 ) fprintf(fortranout,"!!! 222222222222222 \n");
+      writesub_loopdeclaration_tab(List_UsedInSubroutine_Var,fortranout);
+      if ( mark == 1 ) fprintf(fortranout,"!!! 333333333333333 \n");
+      writesub_loopdeclaration_scalar(List_UsedInSubroutine_Var,paramout);
+      if ( mark == 1 ) fprintf(fortranout,"!!! 444444444444444 \n");
+      /* now we should write the function declaration                         */
+      /*    case if it is the                                                 */
+      WriteFunctionDeclaration();
+      if ( mark == 1 ) fprintf(fortranout,"!!! 555555555555555 \n");
+      if ( SubInList_ContainsSubroutine() == 0 ) WriteSubroutineDeclaration(1);
+      if ( mark == 1 ) fprintf(fortranout,"!!! 666666666666666 \n");
+      if ( todebug == 1 ) printf("Out of writeheadnewsub_0\n");
+   }
+   else if ( firstpass == 0 )
+   {
+      AddUseAgrifUtil_0(fortranout);
+      WriteUsemoduleDeclaration();
+      WriteIncludeDeclaration();
+      if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout,
+                                                       "      IMPLICIT NONE\n");
+      if ( mark == 1 ) fprintf(fortranout,"!!! aaaaaaaaaaaaaaa \n");
+      WriteLocalParamDeclaration();
+      if ( mark == 1 ) fprintf(fortranout,"!!! bbbbbbbbbbbbbbb \n");
+      if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration();
+      WriteArgumentDeclaration_beforecall();
+/*      writesub_loopdeclaration_scalar(List_SubroutineArgument_Var,fortranout);
+      writesub_loopdeclaration_tab(List_SubroutineArgument_Var,fortranout);*/
+      if ( mark == 1 ) fprintf(fortranout,"!!! ccccccccccccccc \n");
+      if ( mark == 1 ) fprintf(fortranout,"!!! ddddddddddddddd \n");
+      WriteSubroutineDeclaration(1);
+      if ( mark == 1 ) fprintf(fortranout,"!!! eeeeeeeeeeeeeee \n");
+   }
+}
+
+
+/******************************************************************************/
+/*                    WriteVariablelist_subloop                               */
+/******************************************************************************/
+/* This subroutine is used to write the list of the variable which            */
+/* should be called by the sub_loop_<name> subroutine                         */
+/* The first part is composed by the list of the local variables              */
+/******************************************************************************/
+/*                                                                            */
+/*    List_SubroutineDeclaration_Var    a,b,c,  &                             */
+/*                                      d,e,f,  &                             */
+/*     a,b,c,d,e,f,g,h     ========>    g,h                                   */
+/*                                                                            */
+/******************************************************************************/
+void WriteVariablelist_subloop(FILE *outputfile)
+{
+   listvar *parcours;
+   char ligne[LONGNOM];
+   int compteur;
+
+   if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop\n");
+   parcours = List_SubroutineArgument_Var;
+   didvariableadded = 0;
+   compteur = 0 ;
+
+   while ( parcours )
+   {
+      /* if the readed variable is a variable of the subroutine               */
+      /*    subroutinename we should write the name of this variable          */
+      /*    in the output file                                                */
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
+      {
+         if ( didvariableadded == 0 )
+         {
+            strcpy(ligne,"");
+         }
+         else
+         {
+            if ( compteur == 0 ) strcpy(ligne,"");
+            strcat(ligne,",");
+         }
+         strcat(ligne,parcours->var->v_nomvar);
+         didvariableadded = 1;
+         compteur = compteur + 1;
+         if ( compteur == 3 )
+         {
+            if ( retour77 == 0 )
+            {
+               strcat(ligne," &");
+               fprintf(outputfile,"\n      %s",ligne);
+            }
+            else fprintf(outputfile,"\n     & %s",ligne);
+            compteur = 0;
+         }
+      }
+      parcours = parcours -> suiv;
+   }
+   parcours = List_FunctionType_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
+      {
+         if ( didvariableadded == 0 )
+         {
+            strcpy(ligne,"");
+         }
+         else
+         {
+            if ( compteur == 0 ) strcpy(ligne,"");
+            strcat(ligne,",");
+         }
+         strcat(ligne,parcours->var->v_nomvar);
+         didvariableadded = 1;
+         compteur = compteur + 1;
+         if ( compteur == 3 )
+         {
+            if ( retour77 == 0 )
+            {
+               strcat(ligne," &");
+               fprintf(outputfile,"\n      %s",ligne);
+            }
+            else fprintf(outputfile,"\n     & %s",ligne);
+            compteur = 0;
+         }
+      }
+      parcours = parcours -> suiv;
+   }
+   if ( compteur != 3 && compteur != 0 )
+   {
+      if ( retour77 == 0 ) fprintf(outputfile,"\n      %s &",ligne);
+      else fprintf(outputfile,"\n     & %s ",ligne);
+   }
+   if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop\n");
+}
+
+
+/******************************************************************************/
+/*                     WriteVariablelist_subloop_Call                         */
+/******************************************************************************/
+/* This subroutine is used to write the list of the variable which            */
+/* should be called by the sub_loop_<name> subroutine into the called         */
+/* The second part is composed by the list of the global table                */
+/******************************************************************************/
+/*                                                                            */
+/*   List_UsedInSubroutine_Var SubloopScalar = 0 | SubloopScalar = 1          */
+/*                                a,b,c,  &      |  a,b(1,1),c,      &        */
+/*     a,b,c,d,e,f,g,h  =====>    d,e,f,  &      |  d(1),e(1,1,1),f, &        */
+/*                                g,h            |  g,h(1,1)                  */
+/*                                                                            */
+/******************************************************************************/
+void WriteVariablelist_subloop_Call(FILE *outputfile)
+{
+   listvar *parcours;
+   char ligne[LONGNOM*100];
+   char ligne2[10];
+   int i;
+
+   if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop_Call\n");
+   parcours = List_UsedInSubroutine_Var;
+   while ( parcours )
+   {
+      /* if the readed variable is a variable of the subroutine               */
+      /*    subroutinename we should write the name of this variable          */
+      /*    in the output file                                                */
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename)  &&
+           parcours->var->v_allocatable == 0                            &&
+           parcours->var->v_pointerdeclare == 0
+         )
+      {
+         if ( didvariableadded == 0 )
+         {
+            strcpy(ligne,"");
+         }
+         else
+         {
+            strcpy(ligne,"");
+            strcat(ligne,",");
+         }
+         strcat(ligne,vargridcurgridtabvars(parcours->var,0));
+         /* if it is asked in the call of the conv we should give             */
+         /* scalar in argument, so we should put (1,1,1) after the            */
+         /* the name of the variable                                          */
+         if (  SubloopScalar != 0 &&
+               (IsVarAllocatable_0(parcours->var->v_nomvar) == 0 &&
+               parcours->var->v_pointerdeclare == 0 ) &&
+               parcours->var->v_nbdim != 0 )
+         {
+             i = 1;
+             while ( i <=  parcours->var->v_nbdim )
+             {
+                if ( i == 1 ) strcat(ligne,"( ");
+                if ( SubloopScalar == 2 )
+                {
+                   strcat(ligne,":");
+                   if ( i != parcours->var->v_nbdim ) strcat(ligne,",");
+                }
+                else
+                {
+                   strcat(ligne," lbound( ");
+                   strcat(ligne,vargridcurgridtabvars(parcours->var,0));
+                   strcat(ligne,",");
+                   strcpy(ligne2,"");
+                   sprintf(ligne2,"%d",i);
+                   strcat(ligne,ligne2);
+                   if ( i != parcours->var->v_nbdim ) strcat(ligne,"),");
+                }
+                if ( i == parcours->var->v_nbdim ) strcat(ligne,"))");
+                i++;
+             }
+         }
+         didvariableadded = 1;
+         if ( retour77 == 0 )
+         {
+            strcat(ligne," &");
+            fprintf(outputfile,"\n");
+         }
+         else fprintf(outputfile,"\n     & ");
+         tofich(outputfile,ligne,0);
+      }
+      parcours = parcours -> suiv;
+   }
+   /* Now we should replace the last ", &" by " &"                            */
+   if ( didvariableadded != 0 && retour77 == 0 ) fseek(outputfile,-1,SEEK_CUR);
+   if ( didvariableadded == 0 ) fseek(outputfile,-2,SEEK_CUR);
+   if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop_Call\n");
+}
+
+
+/******************************************************************************/
+/*                       WriteVariablelist_subloop_Def                        */
+/******************************************************************************/
+/* This subroutine is used to write the list of the variable which            */
+/* should be called by the sub_loop_<name> subroutine into the def            */
+/* The second part is composed by the list of the global table                */
+/* <name>_tmp                                                                 */
+/******************************************************************************/
+/*                                                                            */
+/*       List_UsedInSubroutine_Var                                            */
+/*                                a-tmp,b-tmp,c_tmp, &                        */
+/*     a,b,c,d,e,f,g,h  =====>    d_tmp,e_tmp,f_tmp, &                        */
+/*                                g_tmp,h_tmp                                 */
+/*                                                                            */
+/******************************************************************************/
+void WriteVariablelist_subloop_Def(FILE *outputfile)
+{
+   listvar *parcours;
+   char ligne[LONGNOM];
+   int compteur;
+
+   if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop_Def\n");
+   parcours = List_UsedInSubroutine_Var;
+   compteur = 0 ;
+   while ( parcours )
+   {
+      /* if the readed variable is a variable of the subroutine               */
+      /*    subrotinename we should write the name of this variable           */
+      /*    in the output file                                                */
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename)  &&
+           parcours->var->v_allocatable == 0                            &&
+           parcours->var->v_pointerdeclare == 0
+         )
+      {
+         if ( didvariableadded == 0 )
+         {
+            strcpy(ligne,"");
+         }
+         else
+         {
+            if ( compteur == 0 ) strcpy(ligne,"");
+            strcat(ligne,",");
+         }
+         strcat(ligne,parcours->var->v_nomvar);
+         compteur = compteur + 1;
+         didvariableadded = 1;
+         if ( compteur == 3 )
+         {
+            if ( retour77 == 0 )
+            {
+               strcat(ligne," &");
+               fprintf(outputfile,"\n      %s",ligne);
+            }
+            else fprintf(outputfile,"\n     & %s",ligne);
+            compteur = 0;
+         }
+      }
+      parcours = parcours -> suiv;
+   }
+   if ( compteur != 3 && compteur != 0 )
+   {
+      if ( retour77 == 0 ) fprintf(outputfile,"\n      %s &",ligne);
+      else fprintf(outputfile,"\n     & %s",ligne);
+   }
+
+   /* Now we should replace the last ", &" by " &"                            */
+   if ( didvariableadded != 0 && retour77 == 0 ) fseek(outputfile,-1,SEEK_CUR);
+   if ( didvariableadded == 0 ) fseek(outputfile,-1,SEEK_CUR);
+   if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop_Def\n");
+}
+
+
+
+/******************************************************************************/
+/*                      WriteHeadofSubroutineLoop                             */
+/******************************************************************************/
+/* This subroutine is used to write the head of the subroutine                */
+/* Sub_Loop_<name>                                                            */
+/******************************************************************************/
+/*                 Sub_loop_subroutine.h                                      */
+/*                                                                            */
+/*                 subroutine Sub_Loop_subroutine ( &                         */
+/*                 a,b,c, &                                                   */
+/* SubLoopScalar   d,e(1,1),f(1,1,1), &                                       */
+/*                 g,h  &                                                     */
+/*                 )                                                          */
+/******************************************************************************/
+void WriteHeadofSubroutineLoop()
+{
+   char ligne[LONGNOM];
+   FILE * subloop;
+
+   if ( todebug == 1 ) printf("Enter in WriteHeadofSubroutineLoop\n");
+   tofich(fortranout,"\n",1);
+   /* Open this newfile                                                       */
+   sprintf(ligne,"Sub_Loop_%s.h",subroutinename);
+   subloop = associate(ligne);
+   /*                                                                         */
+   if ( retour77 == 0 ) sprintf(ligne,"      subroutine Sub_Loop_%s( &"
+                                                               ,subroutinename);
+   else sprintf(ligne,"      subroutine Sub_Loop_%s( ",subroutinename);
+   fprintf(subloop,ligne);
+   /*                                                                         */
+   WriteVariablelist_subloop(subloop);
+   WriteVariablelist_subloop_Def(subloop);
+   /*                                                                         */
+   sprintf(ligne,")");
+   tofich(subloop,ligne,1);
+   /* if USE agrif_Uti l should be add                                        */
+   AddUseAgrifUtil_0(subloop);
+   /*                                                                         */
+   oldfortranout = fortranout;
+   fortranout = subloop;
+   if ( todebug == 1 ) printf("Out of WriteHeadofSubroutineLoop\n");
+}
+
+/******************************************************************************/
+/*                closeandcallsubloopandincludeit_0                           */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/* We should close the sub_loop subroutine, call it and close the             */
+/* function (suborfun = 0)                                                    */
+/* subroutine (suborfun = 1)                                                  */
+/* end (suborfun = 2)                                                         */
+/* end program (suborfun = 3)                                                 */
+/* and include the sub_loop subroutine after                                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void closeandcallsubloopandincludeit_0(int suborfun, char endsub[LONGNOM])
+{
+   char ligne[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+   if ( todebug == 1 ) printf("Enter in closeandcallsubloopandincludeit_0\n");
+   if ( IsTabvarsUseInArgument_0() == 1 )
+   {
+      /* We should remove the key word end subroutine                         */
+      RemoveWordCUR_0(fortranout,(long)(-(pos_cur-pos_endsubroutine)),
+                                          pos_cur-pos_endsubroutine);
+      /* We should close the loop subroutine                                  */
+      sprintf(ligne,"\n      end subroutine Sub_Loop_%s",subroutinename);
+      tofich(fortranout,ligne,1);
+      fclose(fortranout);
+      fortranout = oldfortranout;
+      AddUseAgrifUtilBeforeCall_0(fortranout);
+      if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration();
+      WriteArgumentDeclaration_beforecall();
+      if ( !strcasecmp(subofagrifinitgrids,subroutinename) )
+                     fprintf(oldfortranout,"      Call Agrif_Init_Grids () \n");
+      /* Now we add the call af the new subroutine                            */
+      if ( retour77 == 0 ) sprintf(ligne,"\n      Call Sub_Loop_%s( &"
+                                                               ,subroutinename);
+      else sprintf(ligne,"\n      Call Sub_Loop_%s( ",subroutinename);
+      fprintf(fortranout,ligne);
+      /* Write the list of the local variables used in this new subroutine    */
+      WriteVariablelist_subloop(fortranout);
+      /* Write the list of the global tables used in this new subroutine      */
+      /*    in doloop                                                         */
+      WriteVariablelist_subloop_Call(fortranout);
+      /* Close the parenthesis of the new subroutine called                   */
+      sprintf(ligne,")");
+      tofich(fortranout,ligne,1);
+      /* We should close the original subroutine                              */
+      if ( suborfun == 3 ) sprintf(ligne,"\n      end program %s"
+                                                               ,subroutinename);
+      if ( suborfun == 2 ) sprintf(ligne,"\n      end");
+      if ( suborfun == 1 ) sprintf(ligne,"\n      end subroutine %s"
+                                                               ,subroutinename);
+      if ( suborfun == 0 ) sprintf(ligne,"\n      end function %s"
+                                                               ,subroutinename);
+      tofich(fortranout,ligne,1);
+      /* we should include the above file in the original code                */
+      sprintf(ligne,"\n#include \"Sub_Loop_%s.h\" \n",subroutinename);
+      tofich(fortranout,ligne,1);
+      }
+   if ( todebug == 1 ) printf("Out of closeandcallsubloopandincludeit_0\n");
+   }
+}
+
+
+
+
+void closeandcallsubloop_contains_0(int suborfun, char endsub[LONGNOM])
+{
+   char ligne[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+   if ( todebug == 1 ) printf("Enter in closeandcallsubloopandincludeit_0\n");
+   if ( IsTabvarsUseInArgument_0() == 1 )
+   {
+      Remove_Word_Contains_0();
+      sprintf(ligne,"\n      end subroutine Sub_Loop_%s",subroutinename);
+      tofich(fortranout,ligne,1);
+      fclose(fortranout);
+      fortranout = oldfortranout;
+      AddUseAgrifUtilBeforeCall_0(fortranout);
+      if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout,
+                                                       "      IMPLICIT NONE\n");
+      WriteLocalParamDeclaration();
+      if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration();
+      WriteArgumentDeclaration_beforecall();
+      WriteSubroutineDeclaration(0);
+      if ( !strcasecmp(subofagrifinitgrids,subroutinename) )
+                     fprintf(oldfortranout,"      Call Agrif_Init_Grids () \n");
+      /* Now we add the call af the new subroutine                            */
+      if ( retour77 == 0 ) sprintf(ligne,"\n      Call Sub_Loop_%s( &"
+                                                               ,subroutinename);
+      else sprintf(ligne,"\n      Call Sub_Loop_%s( ",subroutinename);
+      fprintf(fortranout,ligne);
+      /* Write the list of the local variables used in this new subroutine    */
+      WriteVariablelist_subloop(fortranout);
+      /* Write the list of the global tables used in this new subroutine      */
+      /*    in doloop                                                         */
+      WriteVariablelist_subloop_Call(fortranout);
+      /* Close the parenthesis of the new subroutine called                   */
+      sprintf(ligne,")");
+      tofich(fortranout,ligne,1);
+      /* We should close the original subroutine                              */
+      sprintf(ligne,"\n      contains");
+      tofich(fortranout,ligne,1);
+      /* we should include the above file in the original code                */
+      sprintf(ligne,"\n#include \"Sub_Loop_%s.h\" \n",subroutinename);
+      tofich(fortranout,ligne,1);
+      }
+   if ( todebug == 1 ) printf("Out of closeandcallsubloopandincludeit_0\n");
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilAgrif.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilAgrif.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilAgrif.c	(revision 4536)
@@ -0,0 +1,790 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+/******************************************************************************/
+/*                      Vartonumber                                           */
+/******************************************************************************/
+/* This subroutine is used to know if Agrif_ is locate in the char            */
+/* tokname                                                                    */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int Vartonumber(char *tokname)
+{
+   int agrifintheword;
+
+   agrifintheword = 0;
+        if ( !strcasecmp(tokname,"Agrif_parent")         ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_set_type")       ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_set_raf")        ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_set_bc")         ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_set_bcinterp")   ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Root")           ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_CFixed")         ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Fixed")          ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_bc_variable")    ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_set_parent")     ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_interp_variable")) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_init_variable")  ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_update_variable")) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Set_interp")     ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Set_Update")     ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Set_UpdateType") ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"Agrif_Set_restore")    ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"agrif_init_grids")     ) agrifintheword = 1;
+   else if ( !strcasecmp(tokname,"agrif_step")           ) agrifintheword = 1;
+
+   return agrifintheword;
+}
+
+/******************************************************************************/
+/*                              Agrif_in_Tok_NAME                             */
+/******************************************************************************/
+/* This subroutine is used to know if Agrif_ is locate in the char            */
+/* tokname                                                                    */
+/******************************************************************************/
+/*                                                                            */
+/*                 Agrif_name --------------> Agrif_in_Tok_NAME = 1           */
+/*                       name --------------> Agrif_in_Tok_NAME = 0           */
+/*                                                                            */
+/******************************************************************************/
+int Agrif_in_Tok_NAME(char *tokname)
+{
+   int agrifintheword;
+
+   if ( strncasecmp(tokname,"Agrif_",6) == 0 )  agrifintheword = 1;
+   else agrifintheword = 0;
+
+   return agrifintheword;
+}
+
+/******************************************************************************/
+/*                     ModifyTheVariableName_0                                */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void ModifyTheVariableName_0(char *ident)
+{
+   listvar *newvar;
+   int out;
+
+   if ( firstpass == 0 )
+   {
+      newvar = List_Global_Var;
+      out=0;
+      while ( newvar && out == 0 )
+      {
+         if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+         else newvar=newvar->suiv;
+      }
+
+      if ( out == 0 )
+      {
+         newvar = List_ModuleUsed_Var;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;
+         }
+      }
+      if ( out == 0 )
+      {
+         newvar = List_Common_Var;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;
+         }
+      }
+
+      if ( out == 0 )
+      {
+         newvar = List_ModuleUsedInModuleUsed_Var;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;
+         }
+      }
+
+      if ( out == 1 )
+      {
+         /* remove the variable                                               */
+         RemoveWordCUR_0(fortranout,(long)(-strlen(ident)),
+                               strlen(ident));
+         fseek(fortranout,(long)(-strlen(ident)),SEEK_CUR);
+         /* then write the new name                                           */
+         if ( inagrifcallargument == 1 && agrif_parentcall == 0 )
+            fprintf(fortranout,"%d",newvar->var->v_indicetabvars);
+         else
+         {
+            if ( retour77 == 0 )
+            {
+               fprintf(fortranout," Agrif_tabvars & \n      ");
+            }
+            else
+            {
+               fprintf(fortranout,"Agrif_tabvars");
+               fprintf(fortranout," \n     & ");
+            }
+            fprintf(fortranout,"%s",
+                             vargridcurgridtabvarswithoutAgrif_Gr(newvar->var));
+            colnum = strlen(vargridcurgridtabvarswithoutAgrif_Gr(newvar->var));
+         }
+      }
+      else
+      {
+         /* we should look in the List_ModuleUsed_Var                         */
+         if ( inagrifcallargument != 1 )
+         {
+            newvar = List_ModuleUsed_Var;
+            while ( newvar && out == 0 )
+            {
+               if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+               else newvar=newvar->suiv;
+            }
+            if ( out == 1 )
+            {
+               /* remove the variable                                         */
+               RemoveWordCUR_0(fortranout,(long)(-strlen(ident)),
+                                     strlen(ident));
+               fseek(fortranout,(long)(-strlen(ident)),SEEK_CUR);
+               /* then write the new name                                     */
+               if ( retour77 == 0 )
+               {
+                  fprintf(fortranout," Agrif_tabvars & \n      ");
+               }
+               else
+               {
+                  fprintf(fortranout," \n     & Agrif_tabvars");
+               }
+               fprintf(fortranout,"%s",
+                             vargridcurgridtabvarswithoutAgrif_Gr(newvar->var));
+               colnum = strlen(
+                             vargridcurgridtabvarswithoutAgrif_Gr(newvar->var));
+            }
+         }
+      }
+   }
+}
+
+
+/******************************************************************************/
+/*                         Add_SubroutineWhereAgrifUsed_1                     */
+/******************************************************************************/
+/* This subroutine is used to add a record to                                 */
+/* List_SubroutineWhereAgrifUsed                                              */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub ... Agrif_<something>                                 */
+/*                                                                            */
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + list +--->+ list +--->+ list +--->+ list +--->+ sub  +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*       list = List_SubroutineWhereAgrifUsed                                 */
+/*                                                                            */
+/******************************************************************************/
+void Add_SubroutineWhereAgrifUsed_1(char *sub,char *mod)
+{
+  listnom *listnomtmp;
+  listnom *parcours;
+
+  if ( firstpass == 1 )
+  {
+  if ( !List_SubroutineWhereAgrifUsed )
+  {
+     listnomtmp=(listnom *)malloc(sizeof(listnom));
+     strcpy(listnomtmp->o_nom,sub);
+     strcpy(listnomtmp->o_module,mod);
+     listnomtmp->suiv = NULL;
+     List_SubroutineWhereAgrifUsed  =  listnomtmp;
+  }
+  else
+  {
+    parcours = List_SubroutineWhereAgrifUsed;
+    while ( parcours && strcasecmp(parcours->o_nom,sub) )
+    {
+       parcours = parcours->suiv;
+    }
+    if ( !parcours )
+    {
+       listnomtmp=(listnom *)malloc(sizeof(listnom));
+       strcpy(listnomtmp->o_nom,sub);
+       strcpy(listnomtmp->o_module,mod);
+       listnomtmp->suiv = List_SubroutineWhereAgrifUsed;
+       List_SubroutineWhereAgrifUsed  =  listnomtmp;
+    }
+  }
+  }
+}
+
+/******************************************************************************/
+/*                                AddUseAgrifUtil_0                           */
+/******************************************************************************/
+/* Add use Agrif_Util at the beginning of the subroutine definition           */
+/* if it is necessary                                                         */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub            |  subroutine sub                          */
+/*                                 |  USE Agrif_Util                          */
+/*       implicit none             |  implicit none                           */
+/*       ...                       |  ...                                     */
+/*       ... Agrif_<something>     |  ... Agrif_<something>                   */
+/*       ...                       |  ...                                     */
+/*       end                       |  end                                     */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void  AddUseAgrifUtil_0(FILE *fileout)
+{
+  listnom *parcours;
+  listusemodule *newmodule;
+  int out;
+
+  if ( firstpass == 0 )
+  {
+     parcours = List_SubroutineWhereAgrifUsed;
+     while ( parcours && strcasecmp(parcours->o_nom,subroutinename) )
+                                                    parcours = parcours -> suiv;
+     if ( parcours && parcours->o_val != 0 )
+                                   fprintf(fileout,"\n      USE Agrif_Util \n");
+  }
+}
+
+void  AddUseAgrifUtilBeforeCall_0(FILE *fileout)
+{
+  listusemodule *parcours;
+
+  int out;
+
+  if ( firstpass == 0 )
+  {
+     parcours = List_NameOfModuleUsed;
+     out = 0 ;
+     while ( parcours && out == 0 )
+     {
+        if ( !strcasecmp(parcours->u_usemodule,"Agrif_Util")     &&
+             !strcasecmp(parcours->u_modulename,curmodulename)   &&
+             !strcasecmp(parcours->u_cursubroutine,subroutinename)
+            ) out = 1;
+        else parcours = parcours->suiv;
+     }
+     if ( out == 0 )
+     {
+        fprintf(fileout,"\n      USE Agrif_Util \n");
+     }
+  }
+}
+
+/******************************************************************************/
+/*                         NotifyAgrifFunction_0                              */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void NotifyAgrifFunction_0(char *ident)
+{
+   if ( firstpass == 0 )
+   {
+      if ( !strcasecmp(ident,"Agrif_parent") )
+      {
+         InAgrifParentDef = 1;
+         pos_curagrifparent = setposcur()-12;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Get_Coarse_grid") )
+      {
+         InAgrifParentDef = 2;
+         pos_curagrifparent = setposcur()-21;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Rhox") )
+      {
+         InAgrifParentDef = 3;
+         pos_curagrifparent = setposcur()-10;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Rhox") )
+      {
+         InAgrifParentDef = 4;
+         pos_curagrifparent = setposcur()-17;
+      }
+      else if ( !strcasecmp(ident,"Agrif_IRhox") )
+      {
+         InAgrifParentDef = 5;
+         pos_curagrifparent = setposcur()-11;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_IRhox") )
+      {
+         InAgrifParentDef = 6;
+         pos_curagrifparent = setposcur()-18;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Rhoy") )
+      {
+         InAgrifParentDef = 7;
+         pos_curagrifparent = setposcur()-10;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Rhoy") )
+      {
+         InAgrifParentDef = 8;
+         pos_curagrifparent = setposcur()-17;
+      }
+      else if ( !strcasecmp(ident,"Agrif_IRhoy") )
+      {
+         InAgrifParentDef = 9;
+         pos_curagrifparent = setposcur()-11;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_IRhoy") )
+      {
+         InAgrifParentDef = 10;
+         pos_curagrifparent = setposcur()-18;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Rhoz") )
+      {
+         InAgrifParentDef = 11;
+         pos_curagrifparent = setposcur()-10;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Rhoz") )
+      {
+         InAgrifParentDef = 12;
+         pos_curagrifparent = setposcur()-17;
+      }
+      else if ( !strcasecmp(ident,"Agrif_IRhoz") )
+      {
+         InAgrifParentDef = 13;
+         pos_curagrifparent = setposcur()-11;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_IRhoz") )
+      {
+         InAgrifParentDef = 14;
+         pos_curagrifparent = setposcur()-18;
+      }
+      else if ( !strcasecmp(ident,"Agrif_NearCommonBorderX") )
+      {
+         InAgrifParentDef = 15;
+         pos_curagrifparent = setposcur()-23;
+      }
+      else if ( !strcasecmp(ident,"Agrif_NearCommonBorderY") )
+      {
+         InAgrifParentDef = 16;
+         pos_curagrifparent = setposcur()-23;
+      }
+      else if ( !strcasecmp(ident,"Agrif_NearCommonBorderZ") )
+      {
+         InAgrifParentDef = 17;
+         pos_curagrifparent = setposcur()-23;
+      }
+      else if ( !strcasecmp(ident,"Agrif_DistantCommonBorderX") )
+      {
+         InAgrifParentDef = 18;
+         pos_curagrifparent = setposcur()-26;
+      }
+      else if ( !strcasecmp(ident,"Agrif_DistantCommonBorderY") )
+      {
+         InAgrifParentDef = 19;
+         pos_curagrifparent = setposcur()-26;
+      }
+      else if ( !strcasecmp(ident,"Agrif_DistantCommonBorderZ") )
+      {
+         InAgrifParentDef = 20;
+         pos_curagrifparent = setposcur()-26;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Get_parent_id") )
+      {
+         InAgrifParentDef = 21;
+         pos_curagrifparent = setposcur()-19;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Get_grid_id") )
+      {
+         InAgrifParentDef = 22;
+         pos_curagrifparent = setposcur()-17;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Iz") )
+      {
+         InAgrifParentDef = 23;
+         pos_curagrifparent = setposcur()-15;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Iy") )
+      {
+         InAgrifParentDef = 24;
+         pos_curagrifparent = setposcur()-15;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Parent_Ix") )
+      {
+         InAgrifParentDef = 25;
+         pos_curagrifparent = setposcur()-15;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Iz") )
+      {
+         InAgrifParentDef = 26;
+         pos_curagrifparent = setposcur()-8;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Iy") )
+      {
+         InAgrifParentDef = 27;
+         pos_curagrifparent = setposcur()-8;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Ix") )
+      {
+         InAgrifParentDef = 28;
+         pos_curagrifparent = setposcur()-8;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Nb_Fixed_Grids") )
+      {
+         InAgrifParentDef = 29;
+         pos_curagrifparent = setposcur()-20;
+      }
+      else if ( !strcasecmp(ident,"Agrif_Nb_Fine_Grids") )
+      {
+         InAgrifParentDef = 29;
+         pos_curagrifparent = setposcur()-19;
+      }
+      else if ( !strcasecmp(ident,"AGRIF_Nb_Step") )
+      {
+         InAgrifParentDef = 30;
+         pos_curagrifparent = setposcur()-13;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                       ModifyTheAgrifFunction_0                             */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void ModifyTheAgrifFunction_0(char *ident)
+{
+   if ( InAgrifParentDef != 0 )
+          AgriffunctionModify_0(ident,InAgrifParentDef);
+   /*                                                                         */
+   InAgrifParentDef = 0;
+}
+
+
+/******************************************************************************/
+/*                         AgriffunctionModify_0                              */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/* if whichone = 1 Agrif_parent ===>                                          */
+/*                                                                            */
+/* if whichone = 2 Agrif_Get_coarse_grid ===>                                 */
+/*                                                                            */
+/* if whichone = 3 Agrif_Rhox ===>                                            */
+/*                                                                            */
+/* if whichone = 4 Agrif_Parent_Rhox ===>                                     */
+/*                                                                            */
+/* if whichone = 5 Agrif_IRhox ===>                                           */
+/*                                                                            */
+/* if whichone = 6 Agrif_Parent_IRhox ===>                                    */
+/*                                                                            */
+/* if whichone = 7 Agrif_Rhoy ===>                                            */
+/*                                                                            */
+/* if whichone = 8 Agrif_Parent_Rhoy ===>                                     */
+/*                                                                            */
+/* if whichone = 9 Agrif_IRhoy ===>                                           */
+/*                                                                            */
+/* if whichone = 10 Agrif_Parent_IRhoy ===>                                   */
+/*                                                                            */
+/* if whichone = 11 Agrif_Rhoz ===>                                           */
+/*                                                                            */
+/* if whichone = 12 Agrif_Parent_Rhoz ===>                                    */
+/*                                                                            */
+/* if whichone = 13 Agrif_IRhoz ===>                                          */
+/*                                                                            */
+/* if whichone = 14 Agrif_Parent_IRhoz ===>                                   */
+/*                                                                            */
+/* if whichone = 15 Agrif_NearCommonBorderX ===>                              */
+/*                                                                            */
+/* if whichone = 16 Agrif_NearCommonBorderX ===>                              */
+/*                                                                            */
+/* if whichone = 17 Agrif_NearCommonBorderX ===>                              */
+/*                                                                            */
+/* if whichone = 18 Agrif_DistantCommonBorderX ===>                           */
+/*                                                                            */
+/* if whichone = 19 Agrif_DistantCommonBorderY ===>                           */
+/*                                                                            */
+/* if whichone = 20 Agrif_DistantCommonBorderZ ===>                           */
+/*                                                                            */
+/* if whichone = 21 Agrif_Get_parent_id ===>                                  */
+/*                                                                            */
+/* if whichone = 22 Agrif_Get_grid_id ===>                                    */
+/*                                                                            */
+/* if whichone = 23 Agrif_Parent_Iz ===>                                      */
+/*                                                                            */
+/* if whichone = 24 Agrif_Parent_Iy ===>                                      */
+/*                                                                            */
+/* if whichone = 25 Agrif_Parent_Ix ===>                                      */
+/*                                                                            */
+/* if whichone = 26 Agrif_Iz ===>                                             */
+/*                                                                            */
+/* if whichone = 27 Agrif_Iy ===>                                             */
+/*                                                                            */
+/* if whichone = 28 Agrif_Ix ===>                                             */
+/*                                                                            */
+/* if whichone = 29 Agrif_Nb_Fixed_Grids ===>                                 */
+/*                                                                            */
+/* if whichone = 29 Agrif_Nb_Fine_Grids ===>                                  */
+/*                                                                            */
+/* if whichone = 30 AGRIF_Nb_Step ===>                                        */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void AgriffunctionModify_0(char *ident,int whichone)
+{
+   char toprint[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+      strcpy(toprint,"");
+      pos_end = setposcur();
+      fseek(fortranout,pos_curagrifparent,SEEK_SET);
+      if ( whichone == 1 || whichone == 2 )
+      {
+         /*                                                                   */
+         FindAndChangeNameToTabvars(ident,toprint,List_Global_Var,1);
+         if ( !strcasecmp(ident,toprint) )
+         {
+            /* la liste des use de cette subroutine                           */
+            strcpy(toprint,"");
+            FindAndChangeNameToTabvars(ident,
+                                          toprint,List_Common_Var,whichone);
+         }
+         if ( !strcasecmp(ident,toprint) )
+         {
+            /* la liste des use de cette subroutine                           */
+            strcpy(toprint,"");
+            FindAndChangeNameToTabvars(ident,
+                                          toprint,List_ModuleUsed_Var,whichone);
+         }
+      }
+      else if ( whichone == 3 ) /* Agrif_Rhox                                 */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% spaceref(1))");
+      }
+      else if ( whichone == 4 ) /* Agrif_Parent_Rhox                          */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% parent %% spaceref(1))");
+      }
+      else if ( whichone == 5 ) /* Agrif_Rhox                                 */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% spaceref(1)");
+      }
+      else if ( whichone == 6 ) /* Agrif_Parent_Rhox                          */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% spaceref(1)");
+      }
+      else if ( whichone == 7 ) /* Agrif_Rhoy                                 */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% spaceref(2))");
+      }
+      else if ( whichone == 8 ) /* Agrif_Parent_Rhoy                          */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% parent %% spaceref(2))");
+      }
+      else if ( whichone == 9 ) /* Agrif_Rhoy                                 */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% spaceref(2)");
+      }
+      else if ( whichone == 10 ) /* Agrif_Parent_Rhoy                         */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% spaceref(2)");
+      }
+      else if ( whichone == 11 ) /* Agrif_Rhoz                                */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% spaceref(3))");
+      }
+      else if ( whichone == 12 ) /* Agrif_Parent_Rhoz                         */
+      {
+         sprintf(toprint,"REAL(Agrif_Curgrid %% parent %% spaceref(3))");
+      }
+      else if ( whichone == 13 ) /* Agrif_Rhoz                                */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% spaceref(3)");
+      }
+      else if ( whichone == 14 ) /* Agrif_Parent_Rhoz                         */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% spaceref(3)");
+      }
+      else if ( whichone == 15 ) /* Agrif_NearCommonBorderX                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% NearRootBorder(1)");
+      }
+      else if ( whichone == 16 ) /* Agrif_NearCommonBorderY                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% NearRootBorder(2)");
+      }
+      else if ( whichone == 17 ) /* Agrif_NearCommonBorderZ                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% NearRootBorder(3)");
+      }
+      else if ( whichone == 18 ) /* Agrif_NearCommonBorderX                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% DistantRootBorder(1)");
+      }
+      else if ( whichone == 19 ) /* Agrif_NearCommonBorderY                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% DistantRootBorder(2)");
+      }
+      else if ( whichone == 20 ) /* Agrif_NearCommonBorderZ                   */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% DistantRootBorder(3)");
+      }
+      else if ( whichone == 21 ) /* Agrif_Get_parent_id                       */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% grid_id");
+      }
+      else if ( whichone == 22 ) /*  Agrif_Get_grid_id                        */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% grid_id");
+      }
+      else if ( whichone == 23 ) /*  Agrif_Parent_Iz                          */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% ix(3)");
+      }
+      else if ( whichone == 24 ) /*  Agrif_Parent_Iy                          */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% ix(2)");
+      }
+      else if ( whichone == 25 ) /*  Agrif_Parent_Ix                          */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% parent %% ix(1)");
+      }
+      else if ( whichone == 26 ) /* Agrif_Iz                                  */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% ix(3)");
+      }
+      else if ( whichone == 27 ) /* Agrif_Iy                                  */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% ix(2)");
+      }
+      else if ( whichone == 28 ) /* Agrif_Ix                                  */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% ix(1)");
+      }
+      else if ( whichone == 29 ) /* Agrif_Nb_Fixed_Grids                      */
+      {
+         sprintf(toprint,"Agrif_nbfixedgrids");
+      }
+      else if ( whichone == 30 ) /* AGRIF_Nb_Step                             */
+      {
+         sprintf(toprint,"Agrif_Curgrid %% ngridstep");
+      }
+      /*                                                                      */
+      if ( whichone == 1 || whichone == 2 )
+      {
+         tofich(fortranout,toprint,2);
+      }
+      else
+      {
+         if( retour77 == 0 ) fprintf(fortranout," & \n");
+         else fprintf(fortranout,"\n     & ");
+         fprintf(fortranout,"%s",toprint);
+      }
+   }
+}
+
+
+/******************************************************************************/
+/*                             Instanciation_0                                */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void Instanciation_0(char *ident)
+{
+   listvar *newvar;
+   int out;
+
+   if ( firstpass == 0 && sameagrifargument == 1 )
+   {
+      newvar = List_Global_Var;
+
+      out=0;
+      while ( newvar && out == 0 )
+      {
+         if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+         else newvar=newvar->suiv;
+      }
+
+      if ( out == 0 )
+      {
+         newvar = List_Common_Var;
+
+         out=0;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;
+         }
+      }
+      if ( out == 0 )
+      {
+         newvar = List_ModuleUsed_Var;
+
+         out=0;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(newvar->var->v_nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;
+         }
+      }
+
+      if ( out == 1 )
+      {
+         /* then write the instanciation                                      */
+         fprintf(fortranout,"\n      %s = %s",ident,
+                                          vargridcurgridtabvars(newvar->var,3));
+         colnum = 0;
+      }
+   }
+   sameagrifargument = 0;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilCharacter.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilCharacter.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilCharacter.c	(revision 4536)
@@ -0,0 +1,405 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+
+
+
+/******************************************************************************/
+/*                         FindAndChangeNameToTabvars                         */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+/* if  whichone = 0 ----> Agrif_tabvars(i) % var % array2                     */
+/*                                                                            */
+/* if  whichone = 1 ----> Agrif_tabvars(i) % parentvar % var % array2         */
+/*                                                                            */
+/******************************************************************************/
+void FindAndChangeNameToTabvars(char name[LONGNOM],char toprint[LONGNOM],
+                                listvar * listtosee, int whichone)
+{
+   listvar *newvar;
+   int out;
+
+   if ( strcasecmp(name,"") )
+   {
+      newvar=listtosee;
+      out=0;
+      while( newvar && out == 0 )
+      {
+         if ( !strcasecmp(newvar->var->v_nomvar,name) )
+         {
+            out = 1;
+            strcat(toprint,vargridcurgridtabvars(newvar->var,whichone));
+         }
+         else newvar=newvar->suiv;
+      }
+      if ( out == 0 ) strcat(toprint,name);
+   }
+}
+
+
+/******************************************************************************/
+/*                     ChangeTheInitalvaluebyTabvarsName                      */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread,
+                                                                   int whichone)
+{
+   char toprinttmp[LONGNOM];
+   int i;
+   char chartmp[2];
+
+   i=0;
+   strcpy(toprintglob,"");
+   strcpy(toprinttmp,"");
+   /*                                                                         */
+   while ( i < strlen(nom) )
+   {
+      if ( nom[i] == '+' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,"+");
+      }
+      else if ( nom[i] == '-' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,"-");
+      }
+      else if ( nom[i] == '*' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,"*");
+      }
+      else if ( nom[i] == '/' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,"/");
+      }
+      else if ( nom[i] == '(' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,"(");
+      }
+      else if ( nom[i] == ')' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,")");
+      }
+      else if ( nom[i] == ':' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,":");
+      }
+      else if ( nom[i] == ',' )
+      {
+         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+         strcpy(toprinttmp,"");
+         strcat(toprintglob,",");
+      }
+      else
+      {
+         sprintf(chartmp,"%c",nom[i]);
+         strcat(toprinttmp,chartmp);
+      }
+      /*                                                                      */
+      i=i+1;
+   }
+   FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
+   strcpy(toprinttmp,"");
+
+   /*                                                                         */
+   return toprintglob;
+}
+
+/******************************************************************************/
+/*                            IsVariableReal                                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+int IsVariableReal(char *nom)
+{
+   int Real;
+
+   Real = 0;
+   if ( ( nom[0] >= 'a' && nom[0] <= 'h' ) ||
+        ( nom[0] >= 'A' && nom[0] <= 'H' ) ||
+        ( nom[0] >= 'o' && nom[0] <= 'z' ) ||
+        ( nom[0] >= 'O' && nom[0] <= 'Z' )
+       )
+       {
+          Real = 1;
+       }
+   /*                                                                         */
+   return Real;
+}
+/******************************************************************************/
+/*                         IsVarInUseFile                                     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void IsVarInUseFile(char *nom)
+{
+   listvar *parcours;
+   listparameter *parcoursparam;
+   int out;
+
+   out = 0;
+
+   parcours = List_Global_Var;
+   while( parcours && out == 0 )
+   {
+      if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
+     else parcours=parcours->suiv;
+   }
+   if ( out == 0 )
+   {
+      parcours = List_Common_Var;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
+        else parcours=parcours->suiv;
+      }
+   }
+   if ( out == 0 )
+   {
+      parcours = List_GlobalParameter_Var;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
+        else parcours=parcours->suiv;
+      }
+   }
+   if ( out == 0 )
+   {
+      parcours = List_Parameter_Var;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
+        else parcours=parcours->suiv;
+      }
+   }
+   if ( out == 0 )
+   {
+      parcoursparam = List_GlobParamModuleUsed_Var;
+      while( parcoursparam && out == 0 )
+      {
+         if ( !strcasecmp(nom,parcoursparam->p_name) ) out =2 ;
+         else parcoursparam=parcoursparam->suiv;
+      }
+   }
+   if ( out == 0 )
+   {
+      parcours = List_ModuleUsed_Var;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =2 ;
+        else parcours=parcours->suiv;
+      }
+   }
+   if ( out == 0 || out == 2 )
+   {
+      parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var;
+      while( parcoursparam && out != 1 )
+      {
+         if ( !strcasecmp(nom,parcoursparam->p_name) ) out =1 ;
+         else parcoursparam=parcoursparam->suiv;
+      }
+      if ( out == 1 )
+      {
+         strcpy(charusemodule,parcoursparam->p_modulename);
+         Addmoduletothelist(parcoursparam->p_modulename);
+      }
+   }
+   if ( out == 0 &&
+        strcasecmp(nom,"MAX")             &&
+        strcasecmp(nom,"mpi_status_size")
+      )
+   {
+      printf("--- in UtilCharacter we do not found the \n");
+      printf("---  variable %s, the module where this \n",nom);
+      printf("---  variable has been defined has not been\n");
+      printf("---  found.\n");
+   }
+}
+
+/******************************************************************************/
+/*                      DecomposeTheNameinlistnom                             */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout)
+{
+   char toprinttmp[LONGNOM];
+   int i;
+   char chartmp[2];
+
+   i=0;
+   strcpy(toprinttmp,"");
+   /*                                                                         */
+   while ( i < strlen(nom) )
+   {
+      if ( nom[i] == '+' ||
+           nom[i] == '-' ||
+           nom[i] == '*' ||
+           nom[i] == '/' ||
+           nom[i] == ')' ||
+           nom[i] == '(' ||
+           nom[i] == ',' ||
+           nom[i] == ':'
+         )
+      {
+         if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
+         {
+             listout = Addtolistnom(toprinttmp,listout,0);
+         }
+         strcpy(toprinttmp,"");
+      }
+      else
+      {
+         sprintf(chartmp,"%c",nom[i]);
+         strcat(toprinttmp,chartmp);
+      }
+      /*                                                                      */
+      i=i+1;
+   }
+   if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
+   {
+      listout = Addtolistnom(toprinttmp,listout,0);
+   }
+   strcpy(toprinttmp,"");
+
+   return listout;
+}
+
+
+/******************************************************************************/
+/*                      DecomposeTheName                                      */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void DecomposeTheName(char *nom)
+{
+   char toprinttmp[LONGNOM];
+   int i;
+   char chartmp[2];
+
+   i=0;
+   strcpy(toprinttmp,"");
+   /*                                                                         */
+   while ( i < strlen(nom) )
+   {
+      if ( nom[i] == '+' ||
+           nom[i] == '-' ||
+           nom[i] == '*' ||
+           nom[i] == '/' ||
+           nom[i] == ')' ||
+           nom[i] == '(' ||
+           nom[i] == ',' ||
+           nom[i] == ':'
+         )
+      {
+         if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
+         {
+            ajoutevarindoloop_definedimension (toprinttmp);
+            /* Is this variable present in globvarofusefile                   */
+            IsVarInUseFile(toprinttmp);
+         }
+         strcpy(toprinttmp,"");
+      }
+      else
+      {
+         sprintf(chartmp,"%c",nom[i]);
+         strcat(toprinttmp,chartmp);
+      }
+      /*                                                                      */
+      i=i+1;
+   }
+   if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
+   {
+      ajoutevarindoloop_definedimension (toprinttmp);
+      /* Is this variable present in globvarofusefile                         */
+      IsVarInUseFile(toprinttmp);
+   }
+   strcpy(toprinttmp,"");
+
+}
+
+void convert2lower(char *name)
+{
+   int l;
+   int i;
+   int caractere;
+
+   l=strlen(name)-1;
+   for (i=0;i<=l;i++)
+   {
+      caractere=name[i];
+      if ((caractere>=65 && caractere<=90)||(caractere>=192 && caractere<=221))
+      {
+         name[i]+=32;
+      }
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFile.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFile.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFile.c	(revision 4536)
@@ -0,0 +1,131 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+
+/******************************************************************************/
+/*                            associate                                       */
+/******************************************************************************/
+/* This subroutine is used to open a file                                     */
+/******************************************************************************/
+FILE * associate (char *filename)
+{
+  char filefich[LONGNOM];
+  sprintf(filefich,"%s/%s",nomdir,filename);
+  return fopen (filefich, "w");
+}
+
+
+/******************************************************************************/
+/*                          associateaplus                                    */
+/******************************************************************************/
+/* This subroutine is used to open a file with option a+                      */
+/******************************************************************************/
+FILE * associateaplus (char *filename)
+{
+  char filefich[LONGNOM];
+  sprintf(filefich,"%s/%s",nomdir,filename);
+  return fopen (filefich, "a+");
+}
+
+
+/******************************************************************************/
+/*                           setposcur                                        */
+/******************************************************************************/
+/* This subroutine is used to know the current position in the file           */
+/******************************************************************************/
+/*                                                                            */
+/*                      setposcur ---------> position in file                 */
+/*                                                                            */
+/******************************************************************************/
+long int setposcur()
+{
+   fflush(fortranout);
+   return ftell(fortranout);
+}
+
+/******************************************************************************/
+/*                      setposcurinoldfortranout                              */
+/******************************************************************************/
+/* This subroutine is used to know the position in the oldfortranout         */
+/******************************************************************************/
+/*                                                                            */
+/*             setposcurinoldfortranout ---------> position in file           */
+/*                                                                            */
+/******************************************************************************/
+long int setposcurinoldfortranout()
+{
+   fflush(oldfortranout);
+   return ftell(oldfortranout);
+}
+
+/******************************************************************************/
+/*                         copyuse_0                                          */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/* We should write in the fortranout the USE tok_name                         */
+/* read in the original file                                                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void copyuse_0(char *namemodule)
+{
+   if (firstpass == 0 && IsTabvarsUseInArgument_0() == 1 )
+   {
+      /* We should write this declaration into the original subroutine too    */
+      fprintf(oldfortranout,"      USE %s \n",namemodule);
+   }
+}
+
+/******************************************************************************/
+/*                         copyuseonly_0                                      */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/* We should write in the fortranout the USE tok_name, only                   */
+/* read in the original file                                                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void copyuseonly_0(char *namemodule)
+{
+   if (firstpass == 0 && IsTabvarsUseInArgument_0() == 1 )
+   {
+      /* We should write this declaration into the original subroutine too    */
+      fprintf(oldfortranout,"      USE %s , ONLY : \n",namemodule);
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFortran.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFortran.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilFortran.c	(revision 4536)
@@ -0,0 +1,690 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                            initdimprob                                     */
+/******************************************************************************/
+/* This subroutine is used to initialized grid dimension variable             */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void initdimprob(int dimprobmod, char * nx, char * ny,char* nz)
+{
+  dimprob = dimprobmod;
+
+  strcpy(nbmaillesX,nx);
+  strcpy(nbmaillesY,ny);
+  strcpy(nbmaillesZ,nz);
+}
+
+/******************************************************************************/
+/*                      Variableshouldberemove                                */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+int Variableshouldberemove(char *nom)
+{
+
+   int remove;
+
+   remove = 0 ;
+
+   if ( remove == 0 && Agrif_in_Tok_NAME(nom) == 1 ) remove = 1 ;
+
+   return remove;
+}
+
+/******************************************************************************/
+/*                          variableisglobal                                  */
+/******************************************************************************/
+/* This subroutine is to know if a variable is global                         */
+/******************************************************************************/
+int variableisglobal(listvar *curvar, listvar *listin)
+{
+  int Globalite;
+  listvar *newvar;
+
+
+  Globalite = 0;
+  newvar = listin;
+  while ( newvar && Globalite == 0 )
+  {
+     if ( !strcasecmp(newvar->var->v_nomvar,curvar->var->v_nomvar) )
+     {
+        Globalite = 1;
+        /* Now we should give the definition of the variable in the           */
+        /* table List_UsedInSubroutine_Var                                    */
+        strcpy(curvar->var->v_typevar,newvar->var->v_typevar);
+        strcpy(curvar->var->v_dimchar,newvar->var->v_dimchar);
+        curvar->var->v_nbdim = newvar->var->v_nbdim;
+        curvar->var->v_dimensiongiven = newvar->var->v_dimensiongiven;
+        curvar->var->v_allocatable = newvar->var->v_allocatable;
+        curvar->var->v_pointerdeclare = newvar->var->v_pointerdeclare;
+        curvar->var->v_indicetabvars = newvar->var->v_indicetabvars;
+        strcpy(curvar->var->v_nameinttypename,newvar->var->v_nameinttypename);
+        strcpy(curvar->var->v_precision,newvar->var->v_precision);
+        strcpy(curvar->var->v_readedlistdimension,
+                                            newvar->var->v_readedlistdimension);
+        strcpy(curvar->var->v_commoninfile,newvar->var->v_commoninfile);
+     }
+     else
+     {
+         newvar = newvar->suiv;
+     }
+  }
+
+  return Globalite ;
+}
+
+int VariableIsInListCommon(listvar *curvar,listvar *listin)
+{
+  int present;
+  listvar *newvar;
+
+  present = 0;
+  newvar = listin;
+  while ( newvar && present == 0 )
+  {
+     if ( !strcasecmp(newvar->var->v_nomvar,curvar->var->v_nomvar) &&
+          !strcasecmp(newvar->var->v_subroutinename,
+                                    curvar->var->v_subroutinename)
+        )
+     {
+        CopyRecord(curvar->var,newvar->var);
+        present = 1;
+     }
+     else newvar = newvar->suiv;
+  }
+
+  return present;
+}
+
+int VariableIsInList(listvar *curvar,listvar *listin)
+{
+  int present;
+  listvar *newvar;
+
+  present = 0;
+  newvar = listin;
+  while ( newvar && present == 0 )
+  {
+     if ( !strcasecmp(newvar->var->v_nomvar,curvar->var->v_nomvar) )
+     {
+        CopyRecord(curvar->var,newvar->var);
+        present = 1;
+     }
+     else newvar = newvar->suiv;
+  }
+
+  return present;
+}
+
+/******************************************************************************/
+/*                      variableisglobalinmodule                              */
+/******************************************************************************/
+/* This subroutine is to know if a variable is global                         */
+/******************************************************************************/
+void variableisglobalinmodule(listcouple *listin, char *module, FILE *fileout)
+{
+  int Globalite;
+  listcouple *newvar;
+  listcouple *newvarprec;
+  listvar *tempo;
+  listvar *newvar2;
+  int out;
+
+  Globalite = 1;
+  newvarprec = (listcouple *)NULL;
+  tempo = (listvar *)NULL;
+  tempo = Readthedependfile(module,tempo);
+  newvar = listin;
+  while ( newvar )
+  {
+     out = 0;
+     newvar2 = tempo;
+     while ( newvar2 && out == 0 )
+     {
+        if ( !strcasecmp(newvar2->var->v_nomvar,newvar->c_namevar) ) out = 1;
+        else newvar2 = newvar2 ->suiv;
+     }
+     if ( out == 1 )
+     {
+        /* remove from the listin                                             */
+        if ( newvar == listin )
+        {
+           listin = listin->suiv;
+           newvar = listin;
+        }
+        else
+        {
+           newvarprec->suiv = newvar->suiv;
+           newvar = newvar->suiv;
+        }
+     }
+     else
+     {
+         newvarprec = newvar;
+         newvar = newvar->suiv;
+         Globalite = 0;
+     }
+  }
+  if ( Globalite == 0 || !newvar)
+  {
+     pos_end = setposcur();
+     RemoveWordSET_0(fileout,pos_curuse,
+                                pos_end-pos_curuse);
+     newvar = listin;
+     while ( newvar )
+     {
+        fprintf(fileout,"      USE %s, ONLY : %s \n",module,newvar->c_namevar);
+        newvar = newvar->suiv;
+     }
+  }
+}
+
+
+void Remove_Word_Contains_0()
+{
+   if ( firstpass == 0 )
+   {
+      RemoveWordCUR_0(fortranout,(long)(-9),9);
+   }
+}
+
+void Remove_Word_end_module_0()
+{
+   if ( firstpass == 0 )
+   {
+      RemoveWordCUR_0(fortranout,(long)(-strlen(curmodulename)-12),
+                                         strlen(curmodulename)+11);
+   }
+}
+
+void Write_Word_Contains_0()
+{
+   if ( firstpass == 0 )
+   {
+      fprintf(fortranout,"\n      contains\n");
+   }
+}
+
+
+void Write_Word_end_module_0()
+{
+   if ( firstpass == 0 )
+   {
+      fprintf(fortranout,"\n      end module %s",curmodulename);
+   }
+}
+
+void Add_Subroutine_For_Alloc(char *nom)
+{
+   listnom *parcours;
+   listnom *newvar;
+   int out;
+
+   newvar = (listnom *)malloc(sizeof(listnom));
+   strcpy(newvar->o_nom,nom);
+   newvar->suiv = NULL;
+
+   if ( !List_Subroutine_For_Alloc )
+   {
+      List_Subroutine_For_Alloc = newvar;
+   }
+   else
+   {
+      parcours = List_Subroutine_For_Alloc;
+      out = 0 ;
+      while ( parcours->suiv && out == 0 )
+      {
+         if ( !strcasecmp(parcours->o_nom,nom) ) out = 1 ;
+         else parcours = parcours ->suiv;
+      }
+      /*                                                                      */
+      if ( out == 0 )
+      {
+         if ( strcasecmp(parcours->o_nom,nom) ) parcours->suiv = newvar;
+      }
+   }
+}
+
+
+void Write_Alloc_Subroutine_0()
+{
+   listnom *parcours_nom;
+   listnom *parcours_nomprec;
+   int out;
+   char ligne[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+      parcours_nom = List_NameOfModule;
+      out = 0 ;
+      while ( parcours_nom && out == 0 )
+      {
+         /*                                                                   */
+         if ( !strcasecmp(curmodulename,parcours_nom->o_nom) ) out = 1;
+         else parcours_nom = parcours_nom -> suiv;
+      }
+      if ( out == 1 )
+      {
+         if ( parcours_nom->o_val == 1 )
+         {
+            strcpy (ligne, "\n      PUBLIC Alloc_agrif_");
+            strcat (ligne, curmodulename);
+            strcat (ligne, "\n");
+            convert2lower(ligne);
+            fprintf(fortranout,ligne);
+         }
+      }
+      Write_Word_Contains_0();
+      if ( out == 1 )
+      {
+         if ( parcours_nom->o_val == 1 )
+         {
+            sprintf (ligne, "Subroutine Alloc_agrif_%s(Agrif_Gr)",
+                                                                 curmodulename);
+            tofich(fortranout,ligne,1);
+            strcpy(ligne,"Use Agrif_Util");
+            tofich(fortranout,ligne,1);
+            strcpy (ligne, "Type(Agrif_grid), Pointer :: Agrif_Gr");
+            tofich(fortranout,ligne,1);
+            strcpy(ligne, "INTEGER :: i");
+            tofich (fortranout, ligne,1);
+            strcpy (ligne, "\n#include \"alloc_agrif_");
+            strcat (ligne, curmodulename);
+            strcat (ligne, ".h\"\n");
+            convert2lower(ligne);
+            fprintf(fortranout,ligne);
+            strcpy (ligne, "Return");
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "End Subroutine Alloc_agrif_%s",curmodulename);
+            tofich(fortranout,ligne,1);
+            /* List all Call Alloc_agrif_                                     */
+            Add_Subroutine_For_Alloc(curmodulename);
+         }
+         else
+         {
+            parcours_nom = List_Subroutine_For_Alloc;
+            out = 0;
+            while ( parcours_nom && out == 0 )
+            {
+               if ( !strcasecmp(parcours_nom->o_nom,curmodulename) ) out = 1;
+               else
+               {
+                  parcours_nomprec = parcours_nom;
+                  parcours_nom = parcours_nom->suiv;
+               }
+            }
+            if ( out == 1 )
+            {
+               if ( parcours_nom == List_Subroutine_For_Alloc)
+               {
+                  List_Subroutine_For_Alloc = List_Subroutine_For_Alloc->suiv;
+               }
+               else
+               {
+                  parcours_nomprec->suiv = parcours_nom->suiv;
+                  parcours_nom = parcours_nomprec->suiv ;
+               }
+            }
+         }
+      }
+   }
+}
+
+
+void Write_Alloc_Subroutine_For_End_0()
+{
+   listnom *parcours_nom;
+   listnom *parcours_nomprec;
+   int out;
+   char ligne[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+      parcours_nom = List_NameOfModule;
+      out = 0 ;
+      while ( parcours_nom && out == 0 )
+      {
+         /*                                                                   */
+         if ( !strcasecmp(curmodulename,parcours_nom->o_nom) ) out = 1;
+         else parcours_nom = parcours_nom -> suiv;
+      }
+      if ( out == 1 )
+      {
+         if ( parcours_nom->o_val == 1 )
+         {
+            strcpy (ligne, "\n      PUBLIC Alloc_agrif_");
+            strcat (ligne, curmodulename);
+            strcat (ligne, "\n");
+            convert2lower(ligne);
+            fprintf(fortranout,ligne);
+            strcpy (ligne, "\n      contains\n");
+            fprintf(fortranout,ligne);
+            sprintf (ligne, "Subroutine Alloc_agrif_%s(Agrif_Gr)",
+                                                                 curmodulename);
+            tofich(fortranout,ligne,1);
+            strcpy(ligne,"Use Agrif_Util");
+            tofich(fortranout,ligne,1);
+            strcpy (ligne, "Type(Agrif_grid), Pointer :: Agrif_Gr");
+            tofich(fortranout,ligne,1);
+            strcpy(ligne, "INTEGER :: i");
+            tofich (fortranout, ligne,1);
+            strcpy (ligne, "\n#include \"alloc_agrif_");
+            strcat (ligne, curmodulename);
+            strcat (ligne, ".h\"\n");
+            convert2lower(ligne);
+            fprintf(fortranout,ligne);
+            strcpy (ligne, "Return");
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "End Subroutine Alloc_agrif_%s",curmodulename);
+            tofich(fortranout,ligne,1);
+            /* List all Call Alloc_agrif                                      */
+            Add_Subroutine_For_Alloc(parcours_nom->o_nom);
+         }
+         else
+         {
+            parcours_nom = List_Subroutine_For_Alloc;
+            out = 0;
+            while ( parcours_nom && out == 0 )
+            {
+               if ( !strcasecmp(parcours_nom->o_nom,curmodulename) ) out = 1;
+               else
+               {
+                  parcours_nomprec = parcours_nom;
+                  parcours_nom = parcours_nom->suiv;
+               }
+            }
+            if ( out == 1 )
+            {
+               if ( parcours_nom == List_Subroutine_For_Alloc)
+               {
+                  List_Subroutine_For_Alloc = List_Subroutine_For_Alloc->suiv;
+               }
+               else
+               {
+                  parcours_nomprec->suiv = parcours_nom->suiv;
+                  parcours_nom = parcours_nomprec->suiv ;
+               }
+            }
+         }
+      }
+   }
+}
+
+void Write_GlobalParameter_Declaration_0()
+{
+   listvar *parcours;
+
+   if ( firstpass == 0 )
+   {
+      parcours = List_GlobalParameter_Var;
+      while( parcours )
+      {
+         if ( !strcasecmp(parcours->var->v_modulename,curmodulename) )
+         {
+            writevardeclaration(parcours,module_declar,0);
+         }
+         parcours = parcours -> suiv;
+      }
+   }
+}
+
+void Write_NotGridDepend_Declaration_0()
+{
+   listvar *parcours;
+
+   if ( firstpass == 0 )
+   {
+      parcours = List_NotGridDepend_Var;
+      while( parcours )
+      {
+         if ( !strcasecmp(parcours->var->v_modulename,curmodulename) )
+         {
+            writevardeclaration(parcours,fortranout,0);
+         }
+         parcours = parcours -> suiv;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                          IsTabvarsUseInArgument_0                          */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int IsTabvarsUseInArgument_0()
+{
+   int out;
+   int doloopout;
+   listvar *parcours;
+
+   out=1;
+
+   if ( List_UsedInSubroutine_Var )
+   {
+      doloopout = 0;
+      parcours = List_UsedInSubroutine_Var;
+      while ( parcours && doloopout == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
+                                                                  doloopout = 1;
+         else parcours = parcours->suiv;
+      }
+      if (  doloopout == 0 ) out = 0;
+      else out = 1 ;
+   }
+   else out = 0;
+
+   return out;
+}
+
+
+/******************************************************************************/
+/*                        ImplicitNoneInSubroutine                            */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int ImplicitNoneInSubroutine()
+{
+  listname *parcours;
+  int out;
+
+  parcours= List_ImplicitNoneSubroutine;
+  out = 0 ;
+  while ( parcours && out == 0 )
+  {
+     if ( !strcasecmp(parcours->n_name,subroutinename) ) out = 1;
+     else parcours = parcours->suiv;
+  }
+  return out;
+}
+
+/******************************************************************************/
+/*                            Add_Pointer_Var_From_List_1                     */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Pointer_Var_From_List_1(listvar *listin)
+{
+   listvar *parcours;
+   int out;
+
+   if ( firstpass == 1 )
+   {
+       parcours = listin;
+       while ( parcours )
+       {
+          Add_Pointer_Var_1(parcours->var->v_nomvar);
+          parcours = parcours -> suiv ;
+       }
+   }
+}
+
+/******************************************************************************/
+/*                            Add_Pointer_Var_1                               */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Pointer_Var_1(char *nom)
+{
+   listname *newvar;
+   listname *parcours;
+   int out;
+
+   if ( firstpass == 1 )
+   {
+      if ( !List_Pointer_Var )
+      {
+         newvar = (listname *)malloc(sizeof(listname));
+         strcpy(newvar->n_name,nom);
+         newvar->suiv = NULL;
+         List_Pointer_Var = newvar;
+      }
+      else
+      {
+         parcours = List_Pointer_Var;
+         out = 0 ;
+         while ( parcours->suiv && out == 0 )
+         {
+            if (  !strcasecmp(parcours->n_name,nom) ) out = 1;
+            else
+               parcours=parcours->suiv;
+         }
+         if ( out == 0 )
+         {
+            if (  !strcasecmp(parcours->n_name,nom) ) out = 1;
+            else
+            {
+               /* add the record                                              */
+              newvar = (listname *)malloc(sizeof(listname));
+              strcpy(newvar->n_name,nom);
+              newvar->suiv = NULL;
+              parcours->suiv = newvar;
+            }
+         }
+      }
+   }
+}
+
+/******************************************************************************/
+/*                          varispointer_0                                    */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int varispointer_0(char *ident)
+{
+   listname *newname;
+   int out;
+
+   out =0;
+   if ( firstpass == 0 )
+   {
+      newname = List_Pointer_Var;
+      while( newname && out == 0 )
+      {
+         if ( !strcasecmp(ident,newname->n_name) ) out = 1 ;
+         else newname = newname->suiv;
+      }
+   }
+   return out;
+}
+
+
+/******************************************************************************/
+/*                          VariableIsNotFunction                             */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int VariableIsNotFunction(char *ident)
+{
+   int out;
+   listvar *newvar;
+
+   out =0;
+
+   if ( !strcasecmp(ident,"size") ||
+        !strcasecmp(ident,"if")   ||
+        !strcasecmp(ident,"max")  ||
+        !strcasecmp(ident,"min")
+      )
+   {
+      newvar = List_SubroutineDeclaration_Var;
+      while ( newvar && out == 0 )
+      {
+         if ( !strcasecmp(subroutinename, newvar->var->v_subroutinename) &&
+              !strcasecmp(ident, newvar->var->v_nomvar) ) out = 1;
+         newvar = newvar -> suiv ;
+      }
+      if ( out == 1 ) out = 0;
+      else out = 1;
+      /* if it has not been found                                             */
+      if ( out == 1 )
+      {
+         out = 0;
+         newvar = List_Global_Var;
+         while ( newvar && out == 0 )
+         {
+            if ( !strcasecmp(ident, newvar->var->v_nomvar) ) out = 1;
+            newvar = newvar -> suiv ;
+         }
+         if ( out == 1 ) out = 0;
+         else out = 1;
+      }
+   }
+   /*                                                                         */
+   return out;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilListe.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilListe.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilListe.c	(revision 4536)
@@ -0,0 +1,434 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+
+void Init_Variable(variable *var)
+{
+   strcpy(var->v_typevar            ,"");
+   strcpy(var->v_nomvar             ,"");
+   strcpy(var->v_oldname            ,"");
+   strcpy(var->v_dimchar            ,"");
+   strcpy(var->v_modulename         ,"");
+   strcpy(var->v_commonname         ,"");
+   strcpy(var->v_vallengspec        ,"");
+   strcpy(var->v_nameinttypename    ,"");
+   strcpy(var->v_commoninfile       ,"");
+   strcpy(var->v_subroutinename     ,"");
+   strcpy(var->v_precision          ,"");
+   strcpy(var->v_initialvalue       ,"");
+   strcpy(var->v_IntentSpec         ,"");
+   strcpy(var->v_readedlistdimension,"");
+   var->v_nbdim               = 0 ;
+   var->v_common              = 0 ;
+   var->v_positioninblock     = 0 ;
+   var->v_module              = 0 ;
+   var->v_save                = 0 ;
+   var->v_VariableIsParameter = 0 ;
+   var->v_PublicDeclare       = 0 ;
+   var->v_PrivateDeclare      = 0 ;
+   var->v_ExternalDeclare     = 0 ;
+   var->v_pointedvar          = 0 ;
+   var->v_notgrid             = 0 ;
+   var->v_dimensiongiven      = 0 ;
+   var->v_c_star              = 0 ;
+   var->v_indicetabvars       = 0 ;
+   var->v_pointerdeclare      = 0 ;
+   var->v_optionaldeclare     = 0 ;
+   var->v_allocatable         = 0 ;
+   var->v_dimsempty           = 0 ;
+   var->v_dimension = (listdim *)NULL;
+}
+/******************************************************************************/
+/*                            AddListvartolistvar                             */
+/******************************************************************************/
+/* This subroutine is used to add a listvar l at the end of a listvar         */
+/* glob.                                                                      */
+/*                                                                            */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + glob +--->+ glob +--->+ glob +--->+ glob +--->+  l   +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+listvar * AddListvarToListvar(listvar *l,listvar *glob,int ValueFirstpass)
+{
+   listvar *newvar;
+
+   if ( firstpass == ValueFirstpass )
+   {
+      if ( !glob) glob = l ;
+      else
+      {
+         newvar=glob;
+         while (newvar->suiv) newvar = newvar->suiv;
+         newvar->suiv = l;
+      }
+   }
+   return glob;
+}
+
+/******************************************************************************/
+/*                       CreateAndFillin_Curvar                               */
+/******************************************************************************/
+/* This subroutine is used to create the record corresponding to the          */
+/* list of declaration                                                        */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void CreateAndFillin_Curvar(char *type,variable *curvar)
+{
+   if (!strcasecmp(type,"character") && strcasecmp(CharacterSize,"") )
+                            strcpy(curvar->v_dimchar,CharacterSize);
+
+  /* On donne la precision de la variable si elle a ete donnee                */
+  curvar->v_c_star = 0;
+  if ( c_star == 1 ) curvar->v_c_star = 1;
+  /*                                                                          */
+  strcpy(curvar->v_vallengspec,"");
+  if ( strcasecmp(vallengspec,"") ) strcpy(curvar->v_vallengspec,vallengspec);
+
+  strcpy(curvar->v_precision,"");
+  if ( strcasecmp(NamePrecision,"") ) strcpy(curvar->v_precision,NamePrecision);
+  /* Si cette variable a ete declaree dans un module on met curvar->module=1  */
+  if ( inmoduledeclare == 1 || SaveDeclare == 1)
+  {
+      curvar->v_module = 1;
+   }
+   /* Puis on donne le nom du module dans curvar->v_modulename                */
+   strcpy(curvar->v_modulename,curmodulename);
+   /* Si cette variable a ete initialisee                                     */
+   if (InitialValueGiven == 1 ) strcpy(curvar->v_initialvalue,InitValue);
+   /* Si cette variable est declaree en save                                  */
+   if (SaveDeclare == 1 ) curvar->v_save = 1;
+   /* Si cette variable est v_allocatable                                     */
+   if (Allocatabledeclare == 1 ) curvar->v_allocatable=1;
+   /* if INTENT spec has been given                                           */
+   if ( strcasecmp(IntentSpec,"") ) strcpy(curvar->v_IntentSpec,IntentSpec);
+}
+
+
+/******************************************************************************/
+/*                        duplicatelistvar                                    */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void duplicatelistvar(listvar *orig)
+{
+   listvar *parcours;
+   listvar *tmplistvar;
+   listvar *tmplistvarprec;
+   listdim *tmplistdim;
+   variable *tmpvar;
+
+   tmplistvarprec = (listvar *)NULL;
+   parcours = orig;
+   while ( parcours )
+   {
+      tmplistvar = (listvar *)malloc(sizeof(listvar));
+      tmpvar = (variable *)malloc(sizeof(variable));
+      /*                                                                      */
+      Init_Variable(tmpvar);
+      /*                                                                      */
+      strcpy(tmpvar->v_typevar,parcours->var->v_typevar);
+      strcpy(tmpvar->v_nomvar,parcours->var->v_nomvar);
+      strcpy(tmpvar->v_oldname,parcours->var->v_oldname);
+      strcpy(tmpvar->v_dimchar,parcours->var->v_dimchar);
+      if ( parcours->var->v_dimension )
+      {
+         tmplistdim = (listdim *)malloc(sizeof(listdim));
+         tmplistdim = parcours->var->v_dimension;
+         tmpvar->v_dimension = tmplistdim;
+      }
+      tmpvar->v_nbdim=parcours->var->v_nbdim;
+      tmpvar->v_common=parcours->var->v_common;
+      tmpvar->v_positioninblock=parcours->var->v_positioninblock;
+      tmpvar->v_module=parcours->var->v_module;
+      tmpvar->v_save=parcours->var->v_save;
+      tmpvar->v_VariableIsParameter=parcours->var->v_VariableIsParameter;
+      tmpvar->v_indicetabvars=parcours->var->v_indicetabvars;
+      strcpy(tmpvar->v_modulename,parcours->var->v_modulename);
+      strcpy(tmpvar->v_commonname,parcours->var->v_commonname);
+      strcpy(tmpvar->v_vallengspec,parcours->var->v_vallengspec);
+      strcpy(tmpvar->v_nameinttypename,parcours->var->v_nameinttypename);
+      tmpvar->v_pointedvar=parcours->var->v_pointedvar;
+      strcpy(tmpvar->v_commoninfile,mainfile);
+      strcpy(tmpvar->v_subroutinename,parcours->var->v_subroutinename);
+      tmpvar->v_dimensiongiven=parcours->var->v_dimensiongiven;
+      tmpvar->v_c_star=parcours->var->v_c_star;
+      strcpy(tmpvar->v_precision,parcours->var->v_precision);
+      strcpy(tmpvar->v_initialvalue,parcours->var->v_initialvalue);
+      tmpvar->v_pointerdeclare=parcours->var->v_pointerdeclare;
+      tmpvar->v_optionaldeclare=parcours->var->v_optionaldeclare;
+      tmpvar->v_allocatable=parcours->var->v_allocatable;
+      strcpy(tmpvar->v_IntentSpec,parcours->var->v_IntentSpec);
+      tmpvar->v_dimsempty=parcours->var->v_dimsempty;
+      strcpy(tmpvar->v_readedlistdimension,
+                                          parcours->var->v_readedlistdimension);
+      /*                                                                      */
+      tmplistvar->var = tmpvar;
+      tmplistvar->suiv = NULL;
+      /*                                                                      */
+      if ( !listduplicated )
+      {
+         listduplicated = tmplistvar;
+         tmplistvarprec = listduplicated;
+      }
+      else
+      {
+         tmplistvarprec->suiv = tmplistvar;
+         tmplistvarprec = tmplistvar;
+      }
+      /*                                                                      */
+      parcours = parcours->suiv;
+   }
+}
+
+/******************************************************************************/
+/*                           insertdim                                        */
+/******************************************************************************/
+/* This subroutine is used to insert a record in a list of                    */
+/* struct : listdim                                                           */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ lin  +--->+ lin  +--->+ lin  +--->+  lin +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+listdim * insertdim(listdim *lin,typedim nom)
+{
+   listdim *newdim ;
+   listdim *parcours ;
+
+   newdim=(listdim *) malloc (sizeof (listdim));
+   newdim->dim=nom;
+   newdim->suiv=NULL;
+
+   if ( ! lin )
+   {
+      lin = newdim;
+   }
+   else
+   {
+      parcours = lin;
+      while ( parcours->suiv ) parcours=parcours->suiv;
+      parcours->suiv = newdim;
+   }
+
+   return lin;
+}
+
+/******************************************************************************/
+/*                            change_dim_char                                 */
+/******************************************************************************/
+/* This subroutine is used to change the dimension in the list lin            */
+/******************************************************************************/
+/*        _______     _______                 _______     _______             */
+/*       +  l   +    +  l   +                +  l   +    +   l  +             */
+/*       + old  +--->+ old  +--------------->+ lin  +--->+  lin +             */
+/*       +______+    +______+                +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+void change_dim_char(listdim *lin,listvar * l)
+{
+   listvar *parcours_var;
+   variable *v;
+
+   parcours_var=l;
+   while(parcours_var)
+   {
+      v=parcours_var->var;
+      strcpy(v->v_dimchar,(lin->dim).last);
+      parcours_var=parcours_var->suiv;
+   }
+}
+
+
+/******************************************************************************/
+/*                                num_dims                                    */
+/******************************************************************************/
+/* This subroutine is used to know the dimension of a table                   */
+/******************************************************************************/
+/*                                                                            */
+/*             Dimension(jpi,jpj,jpk) ----------> num_dims = 3                */
+/*                                                                            */
+/******************************************************************************/
+int num_dims(listdim *d)
+{
+   listdim *parcours;
+   int compteur = 0;
+
+   parcours = d;
+   while(parcours)
+   {
+     compteur++;
+     parcours=parcours->suiv;
+   }
+   return compteur;
+}
+
+
+/******************************************************************************/
+/*                          CREATEVAR                                         */
+/******************************************************************************/
+/* This subroutine is used to create and initialized a record of the          */
+/*      struct : variable                                                     */
+/******************************************************************************/
+variable * createvar(char *nom,listdim *d)
+{
+  variable *var;
+  listdim *dims;
+  char ligne[LONGNOM];
+  char listdimension[LONGNOM];
+
+   var=(variable *) malloc(sizeof(variable));
+   /*                                                                         */
+   Init_Variable(var);
+   /*                                                                         */
+   strcpy(var->v_nomvar,nom);
+   /*                                                                         */
+   strcpy(listdimension,"");
+   strcpy(var->v_modulename,curmodulename);
+   strcpy(var->v_commoninfile,mainfile);
+   strcpy(var->v_subroutinename,subroutinename);
+   /*                                                                         */
+   if ( strcasecmp(nameinttypename,"") )
+                                 strcpy(var->v_nameinttypename,nameinttypename);
+   if ( optionaldeclare     == 1 ) var->v_optionaldeclare = 1;
+   if ( pointerdeclare      == 1 ) var->v_pointerdeclare = 1;
+   if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ;
+   if ( PublicDeclare       == 1 ) var->v_PublicDeclare = 1 ;
+   if ( PrivateDeclare      == 1 ) var->v_PrivateDeclare = 1;
+   if ( ExternalDeclare     == 1 ) var->v_ExternalDeclare = 1;
+   /*                                                                         */
+   var->v_dimension=d;
+   /* Creation of the string for the dimension of this variable               */
+   dimsempty = 1;
+   if ( d )
+   {
+      var->v_dimensiongiven=1;
+      dims = d;
+      while (dims)
+      {
+         if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
+                                                                  dimsempty = 0;
+         sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
+         strcat(listdimension,ligne);
+         if ( dims->suiv )
+         {
+            strcat(listdimension,",");
+         }
+         dims = dims->suiv;
+      }
+      if ( dimsempty == 1 ) var->v_dimsempty=1;
+   }
+   strcpy(var->v_readedlistdimension,listdimension);
+   /*                                                                         */
+   var->v_nbdim=num_dims(d);
+   /*                                                                         */
+   return var;
+}
+
+/******************************************************************************/
+/*                            INSERTVAR                                       */
+/******************************************************************************/
+/* This subroutine is used to insert a record in a list of the                */
+/*      struct : listvar                                                      */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ NEW  +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+listvar * insertvar(listvar *lin,variable *v)
+{
+   listvar *newvar ;
+   listvar *tmpvar ;
+
+   newvar=(listvar *) malloc (sizeof (listvar));
+   newvar->var=v;
+   newvar->suiv = NULL;
+   if (!lin)
+   {
+      newvar->suiv=NULL;
+      lin = newvar;
+   }
+   else
+   {
+      tmpvar = lin ;
+      while (tmpvar->suiv)
+      {
+         tmpvar = tmpvar ->suiv ;
+      }
+      tmpvar -> suiv = newvar;
+   }
+   return lin;
+}
+
+/******************************************************************************/
+/*                             SETTYPE                                        */
+/******************************************************************************/
+/* This subroutine is used to give the same variable type at each             */
+/*      record of the list of the struct : listvar                            */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       + REAL +    + REAL +    + REAL +    + REAL +    + REAL +             */
+/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ lin  +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+listvar *settype(char *nom,listvar *lin)
+{
+   listvar *newvar;
+   variable *v;
+
+   newvar=lin;
+   while (newvar)
+   {
+      v=newvar->var;
+      strcpy(v->v_typevar,nom);
+      newvar=newvar->suiv;
+   }
+   newvar=lin;
+   return newvar ;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilNotGridDep.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilNotGridDep.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/UtilNotGridDep.c	(revision 4536)
@@ -0,0 +1,107 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                     Add_NotGridDepend_Var_1                                */
+/******************************************************************************/
+/* This subroutine is used to add a record into List_NotGridDepend_Var        */
+/*    This variable is add only if it is not present in the list              */
+/*    This variable is add at the end of the list                             */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       + not  +    + not  +    +  not +    +  not +    +      +             */
+/*       + grid +--->+ grid +--->+ grid +--->+ grid +--->+ NEW  +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+void Add_NotGridDepend_Var_1 (char *name)
+{
+   listvar *parcours;
+   listvar *newvar;
+   /*                                                                         */
+   /* look in the List_NotGridDepend_Var if this variable exist               */
+   parcours = List_NotGridDepend_Var;
+   while (parcours)
+   {
+     if (!strcasecmp(parcours->var->v_nomvar,name))
+     {
+        /* if this variable exist -> exit of the program                      */
+        printf(" The variable %s\n",name);
+        printf(" has been declared twice \n");
+        printf(" as a non grid dependent variable \n");
+        exit(1);
+     }
+     parcours= parcours->suiv;
+   }
+   /* if variable does not exist, we add it                                   */
+   newvar=(listvar *)malloc(sizeof(listvar));
+   newvar->var=(variable *)malloc(sizeof(variable));
+   strcpy(newvar->var->v_nomvar,name);
+   strcpy(newvar->var->v_commoninfile,mainfile);
+   strcpy(newvar->var->v_subroutinename,subroutinename);
+   newvar->var->v_notgrid = 1 ;
+   newvar->suiv = List_NotGridDepend_Var;
+   List_NotGridDepend_Var = newvar;
+}
+
+/******************************************************************************/
+/*                      VarIsNonGridDepend                                    */
+/******************************************************************************/
+/* This subroutine is used to know if a variable has been declared as non     */
+/* grid dependent                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  notgriddepend variable;    ----------->  VarIsNonGridDepend = 1           */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+int VarIsNonGridDepend(char *name)
+{
+   listvar *newvar;
+   int out;
+
+   newvar = List_NotGridDepend_Var;
+   out=0;
+   while (newvar && out == 0 )
+   {
+      if ( !strcasecmp(newvar->var->v_nomvar,name) ) out = 1;
+      else newvar = newvar->suiv;
+   }
+   return out;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithAllocatelist.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithAllocatelist.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithAllocatelist.c	(revision 4536)
@@ -0,0 +1,146 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                               Add_Allocate_Var_1                           */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Allocate_Var_1(char *nom,char *nommodule)
+{
+   listallocate *newvar;
+   listallocate *parcours;
+   int out;
+
+   if ( firstpass == 1 )
+   {
+      if ( !List_Allocate_Var )
+      {
+         newvar = (listallocate *)malloc(sizeof(listallocate));
+         strcpy(newvar->a_nomvar,nom);
+         strcpy(newvar->a_subroutine,subroutinename);
+         strcpy(newvar->a_module,nommodule);
+         newvar->suiv = NULL;
+         List_Allocate_Var = newvar;
+      }
+      else
+      {
+         parcours = List_Allocate_Var;
+         out = 0 ;
+         while ( parcours->suiv && out == 0 )
+         {
+            if (  !strcasecmp(parcours->a_nomvar,nom) &&
+                  !strcasecmp(parcours->a_subroutine,subroutinename) &&
+                  !strcasecmp(parcours->a_module,nommodule) ) out = 1;
+            else
+               parcours=parcours->suiv;
+         }
+         if ( out == 0 )
+         {
+            if (  !strcasecmp(parcours->a_nomvar,nom) &&
+                  !strcasecmp(parcours->a_subroutine,subroutinename) &&
+                  !strcasecmp(parcours->a_module,nommodule) ) out = 1;
+            else
+            {
+               /* add the record                                              */
+              newvar = (listallocate *)malloc(sizeof(listallocate));
+              strcpy(newvar->a_nomvar,nom);
+              strcpy(newvar->a_subroutine,subroutinename);
+              strcpy(newvar->a_module,nommodule);
+              newvar->suiv = NULL;
+              parcours->suiv = newvar;
+            }
+         }
+      }
+   }
+}
+
+
+/******************************************************************************/
+/*                            IsVarAllocatable_0                              */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int IsVarAllocatable_0(char *ident)
+{
+   listallocate *parcours;
+   int out;
+
+   out = 0 ;
+   if ( firstpass == 0 )
+   {
+      parcours = List_Allocate_Var;
+      while ( parcours && out == 0 )
+      {
+         if ( !strcasecmp(parcours->a_nomvar,ident)  ) out = 1 ;
+         else parcours=parcours->suiv;
+      }
+   }
+   return out;
+}
+
+
+/******************************************************************************/
+/*                          varisallocatable_0                                */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int varisallocatable_0(char *ident)
+{
+   listallocate *newvaralloc;
+   int out;
+
+   out =0;
+   if (firstpass == 0 )
+   {
+         newvaralloc = List_Allocate_Var;
+         while ( newvaralloc && out == 0 )
+         {
+            if ( !strcasecmp(ident,newvaralloc->a_nomvar) )  out = 1;
+            else newvaralloc = newvaralloc->suiv;
+         }
+   }
+   return out;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithParameterlist.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithParameterlist.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithParameterlist.c	(revision 4536)
@@ -0,0 +1,108 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                       Add_GlobalParameter_Var_1                            */
+/******************************************************************************/
+/*  This subroutines is used to add the variable defined in common in the     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_GlobalParameter_Var_1(listvar *listin)
+{
+   listvar *parcours;
+
+   if ( firstpass == 1 )
+   {
+      if ( VariableIsParameter == 1 ) List_GlobalParameter_Var =
+                         AddListvarToListvar(listin,List_GlobalParameter_Var,1);
+   }
+}
+
+/******************************************************************************/
+/*                       Add_Parameter_Var_1                                  */
+/******************************************************************************/
+/*  This subroutines is used to add the variable defined in common in the     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Parameter_Var_1(listvar *listin)
+{
+   listvar *parcours;
+
+   if ( firstpass == 1 && VariableIsParameter == 1 )
+   {
+      if ( !List_Parameter_Var )
+      {
+         List_Parameter_Var = listin;
+      }
+      else
+      {
+         parcours = List_Parameter_Var;
+         while (parcours->suiv) parcours=parcours->suiv;
+         parcours->suiv = listin;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                       Add_Dimension_Var_1                                  */
+/******************************************************************************/
+/*  This subroutines is used to add the variable defined in common in the     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_Dimension_Var_1(listvar *listin)
+{
+   listvar *parcours;
+
+   if ( firstpass == 1 )
+   {
+      if ( !List_Dimension_Var )
+      {
+         List_Dimension_Var = listin;
+      }
+      else
+      {
+         parcours = List_Dimension_Var;
+         while (parcours->suiv) parcours=parcours->suiv;
+         parcours->suiv = listin;
+      }
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithglobliste.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithglobliste.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithglobliste.c	(revision 4536)
@@ -0,0 +1,74 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                          Add_Globliste_1                                   */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should add this declaration to the List_Global_Var                      */
+/******************************************************************************/
+void Add_Globliste_1(listvar *listtoadd)
+{
+   if ( firstpass == 1 )
+   {
+      if ( aftercontainsdeclare == 0 &&
+           VariableIsParameter  == 0 )
+      {
+         List_Global_Var = AddListvarToListvar(listtoadd,List_Global_Var,1);
+      }
+   }
+}
+
+/******************************************************************************/
+/*                  Add_SubroutineDeclarationSave_Var_1                       */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should add this declaration to the List_Global_Var. case SAVE           */
+/******************************************************************************/
+void Add_SubroutineDeclarationSave_Var_1(listvar *listtoadd)
+{
+   if ( firstpass == 1 )
+   {
+      if ( VariableIsParameter == 0 &&
+           SaveDeclare         == 1 )
+      {
+         List_Global_Var = AddListvarToListvar(listtoadd,List_Global_Var,1);
+      }
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistdatavariable.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistdatavariable.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistdatavariable.c	(revision 4536)
@@ -0,0 +1,79 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+/******************************************************************************/
+/*                          Add_Data_Var_1                                    */
+/******************************************************************************/
+/* This subroutine is used to add a record to List_Data_Var                   */
+/******************************************************************************/
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ data +--->+ data +--->+ data +--->+  data+             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/******************************************************************************/
+void Add_Data_Var_1 (char *name,char *values)
+{
+  listvar *newvar;
+
+  if ( firstpass == 1 )
+  {
+     newvar=(listvar *)malloc(sizeof(listvar));
+     newvar->var=(variable *)malloc(sizeof(variable));
+     /*                                                                       */
+     Init_Variable(newvar->var);
+     /*                                                                       */
+     if ( inmoduledeclare == 1 ) newvar->var->v_module=1;
+     strcpy(newvar->var->v_nomvar,name);
+     strcpy(newvar->var->v_subroutinename,subroutinename);
+     strcpy(newvar->var->v_modulename,curmodulename);
+     strcpy(newvar->var->v_commoninfile,mainfile);
+     strcpy(newvar->var->v_initialvalue,values);
+     newvar->suiv = NULL;
+
+     if ( !List_Data_Var )
+     {
+        List_Data_Var  = newvar ;
+     }
+     else
+     {
+        newvar->suiv = List_Data_Var;
+        List_Data_Var = newvar;
+     }
+  }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistmoduleinfile.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistmoduleinfile.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistmoduleinfile.c	(revision 4536)
@@ -0,0 +1,38 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistofmodulebysubroutine.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistofmodulebysubroutine.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistofmodulebysubroutine.c	(revision 4536)
@@ -0,0 +1,291 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "decl.h"
+
+
+
+/******************************************************************************/
+/*                    RecordUseModulesVariables                               */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void RecordUseModulesVariables()
+{
+  listusemodule *tmplistmodule;
+
+  /* we should record all variables defined in modules used in this file      */
+  if ( List_NameOfModuleUsed )
+  {
+     tmplistmodule = List_NameOfModuleUsed;
+     while ( tmplistmodule )
+     {
+        if ( tmplistmodule->u_firstuse == 1 )
+        {
+           /* check if the file .depend<u_usemodule> exist                    */
+           List_ModuleUsed_Var = Readthedependfile
+                               (tmplistmodule->u_usemodule,List_ModuleUsed_Var);
+
+           List_GlobParamModuleUsed_Var = ReaddependParameterList
+                      (tmplistmodule->u_usemodule,List_GlobParamModuleUsed_Var);
+
+        }
+
+        tmplistmodule = tmplistmodule->suiv;
+     }
+  }
+}
+
+/******************************************************************************/
+/*                RecordUseModulesUseModulesVariables                         */
+/******************************************************************************/
+/******************************************************************************/
+void  RecordUseModulesUseModulesVariables()
+{
+  listusemodule *tmplistmodule;
+  listusemodule *tmplistmodule1;
+
+  /* we should record all variables defined in modules used in this file      */
+  if ( List_NameOfModuleUsed )
+  {
+     /* and we should read the .depend of the module used by the module used  */
+     tmplistmodule = List_NameOfModuleUsed;
+     while ( tmplistmodule )
+     {
+        Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
+        while( tmpuselocallist )
+        {
+           Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
+           tmplistmodule1 = tmpuselocallist->suiv;
+           free(tmpuselocallist);
+           tmpuselocallist = tmplistmodule1;
+        }
+        tmplistmodule = tmplistmodule->suiv;
+     }
+
+     tmplistmodule = listofmoduletmp;
+     while ( tmplistmodule )
+     {
+        Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
+        while( tmpuselocallist )
+        {
+           Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
+           tmplistmodule1 = tmpuselocallist->suiv;
+           free(tmpuselocallist);
+           tmpuselocallist = tmplistmodule1;
+        }
+        tmplistmodule = tmplistmodule->suiv;
+     }
+
+
+
+     tmplistmodule = listofmoduletmp;
+     while ( tmplistmodule )
+     {
+        /* check if the file .depend<u_usemodule> exist                       */
+        List_ModuleUsedInModuleUsed_Var = Readthedependfile
+                   (tmplistmodule->u_usemodule,List_ModuleUsedInModuleUsed_Var);
+
+        List_GlobParamModuleUsedInModuleUsed_Var = ReaddependParameterList
+          (tmplistmodule->u_usemodule,List_GlobParamModuleUsedInModuleUsed_Var);
+        tmplistmodule = tmplistmodule->suiv;
+     }
+  }
+}
+
+/******************************************************************************/
+/*                      Add_NameOfModuleUsed_1                                */
+/******************************************************************************/
+/* This subroutine is used to add a record to a list of struct                */
+/* listusemodule                                                              */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub ... USE mod1 ===> insert in list                      */
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*       list =  List_NameOfModuleUsed                                        */
+/*                                                                            */
+/******************************************************************************/
+void Add_NameOfModuleUsed_1(char *name)
+{
+  listusemodule *newmodule;
+  listusemodule *parcours;
+  int out;
+
+  if ( firstpass == 1 )
+  {
+     newmodule =(listusemodule *)malloc(sizeof(listusemodule));
+     strcpy(newmodule->u_usemodule,name);
+     strcpy(newmodule->u_charusemodule,charusemodule);
+     strcpy(newmodule->u_modulename,curmodulename);
+     strcpy(newmodule->u_cursubroutine,subroutinename);
+     newmodule->u_firstuse = 1 ;
+     newmodule->suiv = NULL;
+
+     if ( !List_NameOfModuleUsed)
+     {
+         List_NameOfModuleUsed = newmodule ;
+     }
+     else
+     {
+    parcours = List_NameOfModuleUsed;
+    while ( parcours && newmodule->u_firstuse == 1 )
+    {
+       if ( !strcasecmp(name,parcours->u_usemodule) )
+       {
+          newmodule->u_firstuse = 0 ;
+       }
+       parcours=parcours->suiv;
+    }
+    /* we can not add the same module twice for the same subroutine           */
+    parcours = List_NameOfModuleUsed;
+    out = 0 ;
+    while ( parcours && out == 0 )
+    {
+       if ( !strcasecmp(name,parcours->u_usemodule) &&
+            !strcasecmp(subroutinename,parcours->u_cursubroutine)
+           )
+       {
+          out = 1 ;
+          free(newmodule);
+       }
+       else parcours=parcours->suiv;
+    }
+    if ( out == 0 )
+    {
+       newmodule->suiv = List_NameOfModuleUsed;
+       List_NameOfModuleUsed = newmodule;
+    }
+  }
+  }
+}
+
+
+/******************************************************************************/
+/*                        Addmoduletothelist                                  */
+/******************************************************************************/
+/* This subroutine is used to add a record to a list of struct                */
+/* listusemodule                                                              */
+/******************************************************************************/
+/*                                                                            */
+/*       subroutine sub ... USE mod1 ===> insert in list                      */
+/*        _______     _______     _______     _______     _______             */
+/*       +      +    +      +    +      +    +      +    +      +             */
+/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
+/*       +______+    +______+    +______+    +______+    +______+             */
+/*                                                                            */
+/*       list =  List_NameOfModuleUsed                                     */
+/*                                                                            */
+/******************************************************************************/
+void Addmoduletothelist(char *name)
+{
+  listusemodule *newmodule;
+  listusemodule *parcours;
+  int out;
+
+     newmodule =(listusemodule *)malloc(sizeof(listusemodule));
+     strcpy(newmodule->u_usemodule,name);
+     strcpy(newmodule->u_charusemodule,charusemodule);
+     strcpy(newmodule->u_cursubroutine,subroutinename);
+     newmodule->u_firstuse = 1 ;
+     newmodule->suiv = NULL;
+
+     if ( !List_NameOfModuleUsed)
+     {
+         List_NameOfModuleUsed = newmodule ;
+     }
+     else
+     {
+    parcours = List_NameOfModuleUsed;
+    while ( parcours && newmodule->u_firstuse == 1 )
+    {
+       if ( !strcasecmp(name,parcours->u_usemodule) )
+       {
+          newmodule->u_firstuse = 0 ;
+       }
+       parcours=parcours->suiv;
+    }
+    /* we can not add the same module twice for the same subroutine           */
+    parcours = List_NameOfModuleUsed;
+    out = 0 ;
+    while ( parcours && out == 0 )
+    {
+       if ( !strcasecmp(name,parcours->u_usemodule) &&
+            !strcasecmp(subroutinename,parcours->u_cursubroutine)
+           )
+       {
+          out = 1 ;
+          free(newmodule);
+       }
+       else parcours=parcours->suiv;
+    }
+    if ( out == 0 )
+    {
+       newmodule->suiv = List_NameOfModuleUsed;
+       List_NameOfModuleUsed = newmodule;
+    }
+  }
+}
+
+
+/******************************************************************************/
+/*                        WriteUsemoduleDeclaration                           */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void WriteUsemoduleDeclaration()
+{
+  listusemodule *newmodule;
+
+  newmodule = List_NameOfModuleUsed;
+  fprintf(fortranout,"\n");
+  while ( newmodule )
+  {
+     if ( !strcasecmp(newmodule->u_cursubroutine,subroutinename) )
+     {
+             fprintf(fortranout,"      USE %s \n"
+                                                   ,newmodule->u_charusemodule);
+     }
+        newmodule = newmodule ->suiv;
+  }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistvarindoloop.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistvarindoloop.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithlistvarindoloop.c	(revision 4536)
@@ -0,0 +1,1700 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or    or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)           */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "decl.h"
+
+/******************************************************************************/
+/*                         Add_UsedInSubroutine_Var_1                         */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should complete the List_UsedInSubroutine_Var                           */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Add_UsedInSubroutine_Var_1 (char *ident)
+{
+  listvar *newvar;
+  listvar *tmpvar;
+  int out;
+
+   /* In the first pass we record all variables presents in the do loop       */
+   if (firstpass == 1 && insubroutinedeclare == 1 )
+   {
+
+  if ( !List_UsedInSubroutine_Var )
+  {
+      newvar=(listvar *)malloc(sizeof(listvar));
+      newvar->var=(variable *)malloc(sizeof(variable));
+      /*                                                                      */
+      Init_Variable(newvar->var);
+      /*                                                                      */
+      newvar->suiv = NULL;
+      strcpy(newvar->var->v_nomvar,ident);
+      strcpy(newvar->var->v_modulename,curmodulename);
+      strcpy(newvar->var->v_commoninfile,mainfile);
+      strcpy(newvar->var->v_subroutinename,subroutinename);
+      newvar->var->v_pointedvar=pointedvar;
+      List_UsedInSubroutine_Var = newvar ;
+  }
+  else
+  {
+      /* We should verify that this variable did not added                    */
+      tmpvar = List_UsedInSubroutine_Var;
+      out = 0 ;
+      while (tmpvar && out == 0 )
+      {
+         if ( !strcasecmp(tmpvar->var->v_nomvar,ident) &&
+              !strcasecmp(tmpvar->var->v_subroutinename,subroutinename))
+                                                                      out  = 1 ;
+         else tmpvar = tmpvar->suiv;
+      }
+      if ( out == 0 )
+      {
+         newvar=(listvar *)malloc(sizeof(listvar));
+         newvar->var=(variable *)malloc(sizeof(variable));
+         /*                                                                   */
+         Init_Variable(newvar->var);
+         /*                                                                   */
+         strcpy(newvar->var->v_nomvar,ident);
+         strcpy(newvar->var->v_commoninfile,mainfile);
+         strcpy(newvar->var->v_modulename,curmodulename);
+         strcpy(newvar->var->v_subroutinename,subroutinename);
+         newvar->var->v_pointedvar=pointedvar;
+         newvar->suiv = List_UsedInSubroutine_Var;
+         List_UsedInSubroutine_Var = newvar;
+      }
+  }
+
+   }
+}
+
+/******************************************************************************/
+/*                        AJOUTEVARINDOLOOP_DEFINEDIMENSION                   */
+/******************************************************************************/
+/* This subroutine is used to add a listvar to  List_UsedInSubroutine_Var     */
+/******************************************************************************/
+void ajoutevarindoloop_definedimension (char *name)
+{
+  listvar *newvar;
+  listvar *tmpvar;
+  listvar *tmpvarprec;
+  int out;
+  int tablemeet;
+
+  if ( !List_UsedInSubroutine_Var )
+  {
+      newvar=(listvar *)malloc(sizeof(listvar));
+      newvar->var=(variable *)malloc(sizeof(variable));
+      /*                                                                      */
+      Init_Variable(newvar->var);
+      /*                                                                      */
+      newvar->suiv = NULL;
+      strcpy(newvar->var->v_nomvar,name);
+      strcpy(newvar->var->v_modulename,curmodulename);
+      strcpy(newvar->var->v_commoninfile,mainfile);
+      strcpy(newvar->var->v_subroutinename,subroutinename);
+      newvar->var->v_pointedvar=pointedvar;
+      List_UsedInSubroutine_Var = newvar ;
+  }
+  else
+  {
+      /* We should verify that this variable did not added                    */
+      tmpvarprec = (listvar *)NULL;
+      tmpvar = List_UsedInSubroutine_Var;
+      out = 0 ;
+      tablemeet = 0 ;
+      while (tmpvar && out == 0 )
+      {
+         if ( tablemeet == 0 && tmpvar->var->v_nbdim != 0 ) tablemeet = 1 ;
+         /*                                                                   */
+         if ( !strcasecmp(tmpvar->var->v_nomvar,name) &&
+              !strcasecmp(tmpvar->var->v_subroutinename,subroutinename))
+         {
+            out  = 1 ;
+            /* if this variable has been define before a table we do nothing  */
+            /*    else we should remove it                                    */
+            if ( tablemeet == 1 )
+            {
+               tmpvarprec->suiv = tmpvar -> suiv;
+               out = 2;
+            }
+         }
+         else
+         {
+            tmpvarprec = tmpvar;
+            tmpvar = tmpvar->suiv;
+         }
+      }
+      if ( out == 2 || out == 0 )
+      {
+         newvar=(listvar *)malloc(sizeof(listvar));
+         newvar->var=(variable *)malloc(sizeof(variable));
+         /*                                                                   */
+         Init_Variable(newvar->var);
+         /*                                                                   */
+         strcpy(newvar->var->v_nomvar,name);
+         strcpy(newvar->var->v_modulename,curmodulename);
+         strcpy(newvar->var->v_commoninfile,mainfile);
+         strcpy(newvar->var->v_subroutinename,subroutinename);
+         newvar->var->v_pointedvar=pointedvar;
+         /* we should find this new variable to know the tabvars indice       */
+         if ( variableisglobal(newvar, List_Global_Var) == 1 )
+         {
+            newvar->suiv = List_UsedInSubroutine_Var;
+            List_UsedInSubroutine_Var = newvar;
+         }
+         else if ( variableisglobal(newvar, List_ModuleUsed_Var) == 1 )
+         {
+            newvar->suiv = List_UsedInSubroutine_Var;
+            List_UsedInSubroutine_Var = newvar;
+         }
+         else if ( variableisglobal(newvar, List_Common_Var) == 1 )
+         {
+            newvar->suiv = List_UsedInSubroutine_Var;
+            List_UsedInSubroutine_Var = newvar;
+         }
+         else
+         {
+            free(newvar);
+         }
+     }
+  }
+}
+
+/******************************************************************************/
+/*                        ModifyThelistvarindoloop                            */
+/******************************************************************************/
+/* This subroutine is to give the old name to the which has been              */
+/* declared as USE MOD, U => V in this case we should replace in the          */
+/* name V by the old name U in the List_UsedInSubroutine_Var                  */
+/******************************************************************************/
+void  ModifyThelistvarindoloop()
+{
+  listvar *newvar;
+
+  newvar = List_UsedInSubroutine_Var;
+  while ( newvar )
+  {
+     if ( strcasecmp(newvar->var->v_oldname,"") )
+     {
+        strcpy(newvar->var->v_nomvar,newvar->var->v_oldname);
+     }
+     newvar = newvar->suiv;
+  }
+}
+
+/******************************************************************************/
+/*                          CompleteThelistvarindoloop                        */
+/******************************************************************************/
+/* This subroutine is to add to the List_UsedInSubroutine_Var all variables   */
+/* which has been declared as USE MOD, U => V in this case we should replace  */
+/* in the List_UsedInSubroutine_Var the word U by the word V                  */
+/******************************************************************************/
+void  CompleteThelistvarindoloop()
+{
+  listvar *newvar;
+  listvarpointtovar *pointtmplist;
+  listcouple *coupletmp;
+  int outvar;
+
+  pointtmplist = List_CouplePointed_Var;
+
+  while ( pointtmplist )
+  {
+      coupletmp = pointtmplist->t_couple;
+      while ( coupletmp )
+      {
+         newvar = List_UsedInSubroutine_Var;
+         outvar = 0 ;
+         while ( newvar && outvar == 0)
+         {
+           /* we should find the same variable name in the same subroutine    */
+           if ( !strcasecmp(newvar->var->v_nomvar,coupletmp->c_namevar) &&
+                !strcasecmp(newvar->var->v_subroutinename,
+                                       pointtmplist->t_cursubroutine) &&
+                 strcasecmp(coupletmp->c_namepointedvar,"")
+              )
+           {
+              outvar = 1;
+              strcpy(newvar->var->v_oldname,newvar->var->v_nomvar);
+              strcpy(newvar->var->v_nomvar,coupletmp->c_namepointedvar);
+           }
+           else
+           {
+              newvar = newvar->suiv;
+           }
+         }
+         coupletmp = coupletmp->suiv;
+     }
+     pointtmplist = pointtmplist->suiv;
+  }
+}
+
+/******************************************************************************/
+/*                             CopyRecord                                     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void CopyRecord(variable *var1,variable *var2)
+{
+   if ( !strcasecmp(var1->v_typevar,"") )
+                                        strcpy(var1->v_typevar,var2->v_typevar);
+   else strcpy(var2->v_typevar,var1->v_typevar);
+
+   if ( !strcasecmp(var1->v_oldname,"") )
+                                        strcpy(var1->v_oldname,var2->v_oldname);
+   else strcpy(var2->v_oldname,var1->v_oldname);
+
+   if ( !strcasecmp(var1->v_dimchar,"") )
+                                        strcpy(var1->v_dimchar,var2->v_dimchar);
+   else strcpy(var2->v_dimchar,var1->v_dimchar);
+
+   if ( !strcasecmp(var1->v_commonname,"") )
+                                  strcpy(var1->v_commonname,var2->v_commonname);
+   else strcpy(var2->v_commonname,var1->v_commonname);
+
+   if ( !strcasecmp(var1->v_vallengspec,"") )
+                                strcpy(var1->v_vallengspec,var2->v_vallengspec);
+   else strcpy(var2->v_vallengspec,var1->v_vallengspec);
+
+   if ( !strcasecmp(var1->v_nameinttypename,"") )
+                        strcpy(var1->v_nameinttypename,var2->v_nameinttypename);
+   else strcpy(var2->v_nameinttypename,var1->v_nameinttypename);
+
+   if ( !strcasecmp(var1->v_commoninfile,"") )
+                              strcpy(var1->v_commoninfile,var2->v_commoninfile);
+   else strcpy(var2->v_commoninfile,var1->v_commoninfile);
+
+   if ( !strcasecmp(var1->v_precision,"") )
+                                    strcpy(var1->v_precision,var2->v_precision);
+   else strcpy(var2->v_precision,var1->v_precision);
+
+   if ( !strcasecmp(var1->v_initialvalue,"") )
+                              strcpy(var1->v_initialvalue,var2->v_initialvalue);
+   else strcpy(var2->v_initialvalue,var1->v_initialvalue);
+
+   if ( !strcasecmp(var1->v_IntentSpec,"") )
+                                  strcpy(var1->v_IntentSpec,var2->v_IntentSpec);
+   else strcpy(var2->v_IntentSpec,var1->v_IntentSpec);
+
+   if ( !strcasecmp(var1->v_readedlistdimension,"") )
+                strcpy(var1->v_readedlistdimension,var2->v_readedlistdimension);
+   else strcpy(var2->v_readedlistdimension,var1->v_readedlistdimension);
+
+   if ( var1->v_dimension ) var2->v_dimension = var1->v_dimension ;
+   else var1->v_dimension = var2->v_dimension ;
+
+   if ( var1->v_nbdim == 0 ) var1->v_nbdim = var2->v_nbdim ;
+   else var2->v_nbdim = var1->v_nbdim ;
+
+   if ( var1->v_common == 0 ) var1->v_common = var2->v_common ;
+   else var2->v_common = var1->v_common ;
+
+   if ( var1->v_positioninblock == 0 ) var1->v_positioninblock =
+                                                       var2->v_positioninblock ;
+   else var2->v_positioninblock = var1->v_positioninblock ;
+
+   if ( var1->v_module == 0 ) var1->v_module = var2->v_module ;
+   else var2->v_module = var1->v_module ;
+
+   if ( var1->v_save == 0 ) var1->v_save = var2->v_save ;
+   else var2->v_save = var1->v_save ;
+
+   if ( var1->v_VariableIsParameter == 0 )
+                     var1->v_VariableIsParameter = var2->v_VariableIsParameter ;
+   else var2->v_VariableIsParameter = var1->v_VariableIsParameter ;
+
+   if ( var1->v_indicetabvars == 0 )
+                                 var1->v_indicetabvars = var2->v_indicetabvars ;
+   else var2->v_indicetabvars = var1->v_indicetabvars ;
+
+   if ( var1->v_ExternalDeclare == 0 )
+                             var1->v_ExternalDeclare = var2->v_ExternalDeclare ;
+   else var2->v_ExternalDeclare = var1->v_ExternalDeclare ;
+
+   if ( var1->v_pointedvar == 0 ) var1->v_pointedvar = var2->v_pointedvar ;
+   else var2->v_pointedvar = var1->v_pointedvar ;
+
+   if ( var1->v_dimensiongiven == 0 )
+                                var1->v_dimensiongiven = var2->v_dimensiongiven;
+   else var2->v_dimensiongiven = var1->v_dimensiongiven ;
+
+   if ( var1->v_c_star == 0 ) var1->v_c_star = var2->v_c_star;
+   else var2->v_c_star = var1->v_c_star ;
+
+   if ( var1->v_pointerdeclare == 0 )
+                               var1->v_pointerdeclare = var2->v_pointerdeclare ;
+   else var2->v_pointerdeclare = var1->v_pointerdeclare ;
+
+
+   if ( var1->v_notgrid == 0 ) var1->v_notgrid = var2->v_notgrid ;
+   else var2->v_notgrid = var1->v_notgrid;
+
+   if ( var1->v_optionaldeclare == 0 )
+                              var1->v_optionaldeclare = var2->v_optionaldeclare;
+   else var2->v_optionaldeclare = var1->v_optionaldeclare ;
+
+   if ( var1->v_allocatable == 0 ) var1->v_allocatable = var2->v_allocatable ;
+   else var2->v_allocatable = var1->v_allocatable ;
+
+   if ( var1->v_dimsempty == 0 ) var1->v_dimsempty = var2->v_dimsempty ;
+   else var2->v_dimsempty = var1->v_dimsempty ;
+}
+
+
+/******************************************************************************/
+/*                      Update_List_Subroutine_Var                            */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Update_List_Subroutine_Var(listvar *list_to_modify)
+{
+   listvar *parcours;
+   listvar *parcoursprec;
+   listvar *parcours1;
+   int out;
+
+   parcours = list_to_modify;
+   while( parcours )
+   {
+      /* looking in List_SubroutineDeclaration_Var                            */
+      parcours1 = List_SubroutineDeclaration_Var;
+      out = 0;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_nomvar,
+                          parcours1->var->v_nomvar)         &&
+              !strcasecmp(parcours->var->v_subroutinename,
+                          parcours1->var->v_subroutinename) &&
+              !strcasecmp(parcours->var->v_modulename,
+                          parcours1->var->v_modulename)
+            ) out = 1;
+         else parcours1 = parcours1->suiv;
+      }
+      /* if variable has been found                                           */
+      if ( out == 1 ) CopyRecord(parcours->var,parcours1->var);
+      /* looking in List_Dimension_Var                                        */
+      if (out == 0 )
+      {
+        parcours1 = List_Dimension_Var;
+        out = 0;
+        while ( parcours1 && out == 0 )
+        {
+           if ( !strcasecmp(parcours->var->v_nomvar,
+                            parcours1->var->v_nomvar)         &&
+                !strcasecmp(parcours->var->v_subroutinename,
+                            parcours1->var->v_subroutinename) &&
+                !strcasecmp(parcours->var->v_modulename,
+                            parcours1->var->v_modulename)
+              ) out = 1;
+           else
+           {
+              parcoursprec = parcours1;
+              parcours1 = parcours1->suiv;
+           }
+        }
+        /* if variable has been found                                         */
+        if ( out == 1 )
+        {
+           CopyRecord(parcours->var,parcours1->var);
+           /* we should remove this record from the List_Dimension_Var        */
+           if ( parcours1 == List_Dimension_Var )
+           {
+              List_Dimension_Var = List_Dimension_Var -> suiv;
+           }
+           else
+           {
+              parcoursprec->suiv = parcours1 -> suiv;
+           }
+        }
+      }
+      /*                                                                      */
+      parcours = parcours->suiv;
+   }
+}
+
+void Update_List_Global_Var_From_List_Save_Var()
+{
+   listvar *parcours;
+   listvar *newvar;
+   listvar *parcours1;
+   char ligne[LONGNOM];
+   int out;
+
+   parcours = List_Save_Var;
+   while( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_modulename,"") )
+      /* Save in subroutine which is not defined in a module                  */
+      {
+         newvar = (listvar *)malloc(sizeof(listvar));
+         newvar->var = (variable *)malloc(sizeof(variable));
+         /*                                                                   */
+         Init_Variable(newvar->var);
+         /*                                                                   */
+         newvar->suiv = NULL;
+         CopyRecord(parcours->var,newvar->var);
+         strcpy(newvar->var->v_subroutinename,parcours->var->v_subroutinename);
+         strcpy(newvar->var->v_nomvar,parcours->var->v_nomvar);
+         sprintf(ligne,"save_%s",parcours->var->v_subroutinename);
+         Add_NameOfCommon_1(ligne);
+         strcpy(newvar->var->v_commonname,ligne);
+         List_Common_Var = AddListvarToListvar(newvar,List_Common_Var,1);
+      }
+      else
+      /* Save in subroutine which is defined in a module                      */
+      {
+         newvar = (listvar *)malloc(sizeof(listvar));
+         newvar->var = (variable *)malloc(sizeof(variable));
+         /*                                                                   */
+         Init_Variable(newvar->var);
+         /*                                                                   */
+         newvar->suiv = NULL;
+         CopyRecord(parcours->var,newvar->var);
+         strcpy(newvar->var->v_subroutinename,"");
+         strcpy(newvar->var->v_nomvar,parcours->var->v_nomvar);
+         strcpy(newvar->var->v_modulename,parcours->var->v_modulename);
+         List_Global_Var = AddListvarToListvar(newvar,List_Global_Var,1);
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+/******************************************************************************/
+/*                      Update_List_From_Common_Var                           */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Update_List_From_Common_Var(listvar *list_to_modify)
+{
+   listvar *parcours;
+   listvar *parcours1;
+   int out;
+
+   parcours = list_to_modify;
+   while( parcours )
+   {
+      /* looking in List_Global_Var                                           */
+      parcours1 = List_Common_Var;
+      out = 0;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_nomvar,
+                          parcours1->var->v_nomvar)         &&
+              !strcasecmp(parcours->var->v_subroutinename,
+                          parcours1->var->v_subroutinename)
+            ) out = 1;
+         else parcours1 = parcours1->suiv;
+      }
+      /* if variable has been found                                           */
+      if ( out == 1 )
+      {
+         strcpy(parcours->var->v_commoninfile,parcours1->var->v_commoninfile);
+         CopyRecord(parcours->var,parcours1->var);
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+/******************************************************************************/
+/*                          Update_List_Var                                   */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Update_List_Var(listvar *list_to_modify)
+{
+   listvar *parcours;
+   listvar *parcours1;
+   int out;
+
+   parcours = list_to_modify;
+   while( parcours )
+   {
+      /* looking in List_Global_Var                                           */
+      parcours1 = List_Global_Var;
+      out = 0;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_nomvar,
+                          parcours1->var->v_nomvar)         &&
+              !strcasecmp(parcours->var->v_modulename,
+                          parcours1->var->v_modulename)
+            ) out = 1;
+         else parcours1 = parcours1->suiv;
+      }
+      /* if variable has been found                                           */
+      if ( out == 1 ) CopyRecord(parcours->var,parcours1->var);
+      /* looking in List_SubroutineDeclaration_Var                            */
+      else
+      {
+         parcours1 = List_SubroutineDeclaration_Var ;
+         out = 0;
+         while ( parcours1 && out == 0 )
+         {
+            if ( !strcasecmp(parcours->var->v_nomvar,
+                             parcours1->var->v_nomvar)         &&
+                 !strcasecmp(parcours->var->v_subroutinename,
+                             parcours1->var->v_subroutinename) &&
+                 !strcasecmp(parcours->var->v_modulename,
+                             parcours1->var->v_modulename)
+               ) out = 1;
+            else parcours1 = parcours1->suiv;
+         }
+         /* if variable has been found                                        */
+         if ( out == 1 ) CopyRecord(parcours->var,parcours1->var);
+         else
+         {
+            parcours1 = List_Common_Var ;
+            out = 0;
+            while ( parcours1 && out == 0 )
+            {
+               if ( !strcasecmp(parcours->var->v_nomvar,
+                                parcours1->var->v_nomvar)         &&
+                    !strcasecmp(parcours->var->v_subroutinename,
+                                parcours1->var->v_subroutinename) &&
+                    !strcasecmp(parcours->var->v_modulename,
+                                parcours1->var->v_modulename)
+                  ) out = 1;
+               else parcours1 = parcours1->suiv;
+            }
+            /* if variable has been found                                     */
+            if ( out == 1 ) CopyRecord(parcours->var,parcours1->var);
+         }
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+
+void List_UsedInSubroutine_Var_Update_From_Module_Used()
+{
+   listvar *parcours;
+   listvar *parcours3;
+   listusemodule *parcours2;
+   int out;
+
+   parcours = List_UsedInSubroutine_Var;
+   while( parcours )
+   {
+      out = 0 ;
+      if ( parcours->var->v_indicetabvars == 0 )
+      {
+         parcours2 = List_NameOfModuleUsed;
+         while( parcours2 )
+         {
+            if ( !strcasecmp(parcours2->u_cursubroutine,"") &&
+                 !strcasecmp(parcours2->u_modulename,
+                             parcours->var->v_modulename)
+               )
+            {
+               parcours3 = List_Global_Var;
+               out = 0 ;
+               while ( parcours3 && out == 0 )
+               {
+                  if ( !strcasecmp(parcours->var->v_nomvar,
+                                   parcours3->var->v_nomvar)
+                     ) out = 1 ;
+                  else parcours3 = parcours3->suiv;
+               }
+               if ( out == 1 ) CopyRecord(parcours->var,parcours3->var);
+            }
+            else if ( !strcasecmp(parcours2->u_cursubroutine,
+                             parcours->var->v_subroutinename) &&
+                 !strcasecmp(parcours2->u_modulename,
+                             parcours->var->v_modulename)
+               )
+            {
+               parcours3 = List_Global_Var;
+               out = 0 ;
+               while ( parcours3 && out == 0 )
+               {
+                  if ( !strcasecmp(parcours->var->v_nomvar,
+                                   parcours3->var->v_nomvar)
+                     ) out = 1 ;
+                  else parcours3 = parcours3->suiv;
+               }
+               if ( out == 1 ) CopyRecord(parcours->var,parcours3->var);
+            }
+            parcours2 = parcours2->suiv;
+         }
+         /*                                                                   */
+         if ( out == 0 )
+         {
+            parcours3 = List_ModuleUsed_Var;
+            out = 0 ;
+            while ( parcours3 && out == 0 )
+            {
+               if ( !strcasecmp(parcours->var->v_nomvar,
+                                parcours3->var->v_nomvar)
+                  ) out = 1 ;
+               else parcours3 = parcours3->suiv;
+            }
+            if ( out == 1 ) CopyRecord(parcours->var,parcours3->var);
+         }
+         /*                                                                   */
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+
+
+/******************************************************************************/
+/*                       Update_NotGridDepend_Var                             */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void Update_NotGridDepend_Var(listvar *list_to_modify)
+{
+   listvar *parcours;
+   listvar *parcours1;
+   int out;
+
+   parcours = list_to_modify;
+   while( parcours )
+   {
+      /* looking in List_Global_Var                                           */
+      parcours1 = List_Global_Var;
+      out = 0;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_nomvar,
+                          parcours1->var->v_nomvar)
+            ) out = 1;
+         else parcours1 = parcours1->suiv;
+      }
+      /* if variable has been found                                           */
+      if ( out == 1 )
+      {
+         CopyRecord(parcours->var,parcours1->var);
+         strcpy(parcours->var->v_subroutinename,
+                parcours1->var->v_subroutinename);
+         strcpy(parcours->var->v_modulename,parcours1->var->v_modulename);
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+int LookingForVariableInList(listvar *listin,variable *var)
+{
+   listvar *parcours1;
+   int out;
+
+   parcours1 = listin;
+   out = 0 ;
+   while ( parcours1 && out == 0 )
+   {
+      if ( !strcasecmp(var->v_nomvar,parcours1->var->v_nomvar)                &&
+           !strcasecmp(var->v_subroutinename,parcours1->var->v_subroutinename)&&
+           !strcasecmp(var->v_modulename,parcours1->var->v_modulename)        &&
+                       var->v_save == 0                                       &&
+                       var->v_common == 0
+         ) out = 1 ;
+      else parcours1 = parcours1 -> suiv;
+   }
+
+   return out;
+}
+
+int LookingForVariableInListGlobal(listvar *listin,variable *var)
+{
+   listvar *parcours1;
+   int out;
+
+   parcours1 = listin;
+   out = 0 ;
+   while ( parcours1 && out == 0 )
+   {
+      if ( !strcasecmp(var->v_nomvar,parcours1->var->v_nomvar)                &&
+           !strcasecmp(var->v_subroutinename,parcours1->var->v_subroutinename)&&
+           !strcasecmp(var->v_modulename,parcours1->var->v_modulename)
+         ) out = 1 ;
+      else parcours1 = parcours1 -> suiv;
+   }
+
+   return out;
+}
+
+int LookingForVariableInListGlob(listvar *listin,variable *var)
+{
+   listvar *parcours1;
+   int out;
+
+   parcours1 = listin;
+   out = 0 ;
+   while ( parcours1 && out == 0 )
+   {
+      if ( !strcasecmp(var->v_nomvar,parcours1->var->v_nomvar)                &&
+           !strcasecmp(var->v_modulename,parcours1->var->v_modulename)
+         ) out = 1 ;
+      else parcours1 = parcours1 -> suiv;
+   }
+
+   return out;
+}
+
+int LookingForVariableInListParamGlob(listparameter *listin,variable *var)
+{
+   listparameter *parcours1;
+   int out;
+
+   parcours1 = listin;
+   out = 0 ;
+   while ( parcours1 && out == 0 )
+   {
+      if ( !strcasecmp(var->v_nomvar,parcours1->p_name)
+         ) out = 1 ;
+      else parcours1 = parcours1 -> suiv;
+   }
+
+   return out;
+}
+
+void UpdateListDeclarationWithDimensionList()
+{
+
+   List_SubroutineDeclaration_Var = AddListvarToListvar(List_Dimension_Var,
+                                              List_SubroutineDeclaration_Var,1);
+
+}
+
+
+/* Remove from List_UsedInSubroutine_Var all variables comming from :         */
+/*       - List_SubroutineArgument_Var                                        */
+/*       - List_SubroutineDeclaration_Var                                     */
+/*       - List_Parameter_Var                                                 */
+/*       - List_FunctionType_Var                                              */
+/*       - List_GlobalParameter_Var                                           */
+/*       -                                                                    */
+/*       -                                                                    */
+void Clean_List_UsedInSubroutine_Var()
+{
+   listvar *parcours;
+   listvar *parcoursprec;
+   int remove;
+
+   parcours = List_UsedInSubroutine_Var;
+   while ( parcours )
+   {
+      /*                                                                      */
+      remove = LookingForVariableInListGlobal(List_SubroutineArgument_Var,
+                                                                 parcours->var);
+      if ( remove == 0 )
+           remove = LookingForVariableInList(List_SubroutineDeclaration_Var,
+                                                                 parcours->var);
+      if ( remove == 0 )
+           remove = LookingForVariableInList(List_Parameter_Var,
+                                                                 parcours->var);
+      if ( remove == 0 )
+           remove = LookingForVariableInList(List_FunctionType_Var,
+                                                                 parcours->var);
+      if ( remove == 0 )
+           remove = LookingForVariableInListGlob(List_GlobalParameter_Var,
+                                                                 parcours->var);
+      if ( remove == 0 )
+           remove = LookingForVariableInListParamGlob(
+                                    List_GlobParamModuleUsed_Var,parcours->var);
+      if ( remove == 0 )
+      {
+         if ( VariableIsInList(parcours,List_Global_Var)                 == 1 ||
+              VariableIsInListCommon(parcours,List_Common_Var)           == 1 ||
+              VariableIsInList(parcours,List_ModuleUsed_Var)             == 1 ||
+              VariableIsInList(parcours,List_ModuleUsedInModuleUsed_Var) == 1
+            ) remove = 0;
+         else remove = 1;
+      }
+      /************************************************************************/
+      /*                         Remove                                       */
+      /************************************************************************/
+      if ( remove == 1 )
+      {
+         if ( parcours == List_UsedInSubroutine_Var )
+         {
+           List_UsedInSubroutine_Var = List_UsedInSubroutine_Var -> suiv;
+           parcours = List_UsedInSubroutine_Var;
+         }
+         else
+         {
+            parcoursprec->suiv = parcours->suiv;
+            parcours = parcoursprec -> suiv ;
+         }
+      }
+      else
+      {
+         parcoursprec = parcours;
+         parcours = parcours -> suiv ;
+      }
+   }
+
+}
+
+
+void Clean_List_SubroutineDeclaration_Var()
+{
+   listvar *parcours;
+   listvar *parcours1;
+   listvar *parcoursprec;
+   int out ;
+
+   parcours = List_SubroutineDeclaration_Var;
+   while ( parcours )
+   {
+      parcours1 = List_FunctionType_Var;
+      out = 0 ;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_subroutinename,
+                          parcours1->var->v_subroutinename) &&
+              !strcasecmp(parcours->var->v_nomvar,
+                          parcours1->var->v_nomvar)
+            ) out = 1;
+         else parcours1 = parcours1->suiv;
+      }
+      if ( out == 0 )
+      {
+         parcours1 = List_SubroutineArgument_Var;
+         out = 0 ;
+         while ( parcours1 && out == 0 )
+         {
+            if ( !strcasecmp(parcours->var->v_subroutinename,
+                             parcours1->var->v_subroutinename) &&
+                 !strcasecmp(parcours->var->v_nomvar,
+                             parcours1->var->v_nomvar)
+               ) out = 1;
+            else parcours1 = parcours1->suiv;
+         }
+      }
+
+      if ( out == 1 )
+      {
+          if ( parcours == List_SubroutineDeclaration_Var )
+          {
+             List_SubroutineDeclaration_Var =
+                                         List_SubroutineDeclaration_Var -> suiv;
+             parcours = List_SubroutineDeclaration_Var;
+          }
+          else
+          {
+             parcoursprec->suiv = parcours->suiv;
+             parcours = parcoursprec->suiv;
+          }
+      }
+      else
+      {
+         parcoursprec = parcours;
+         parcours = parcours -> suiv;
+      }
+   }
+}
+
+/******************************************************************************/
+/*                             ListClean                                      */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void ListClean()
+{
+   listvar *newvar;
+
+
+   Clean_List_UsedInSubroutine_Var();
+   Clean_List_SubroutineDeclaration_Var();
+
+
+   newvar = (listvar *)NULL;
+/*   newvar = List_Common_Var;*/
+   while(newvar)
+   {
+      printf("----- %s --- %s ---%s---%s---\n",newvar->var->v_nomvar,
+         newvar->var->v_commonname,
+         newvar->var->v_readedlistdimension,
+         newvar->var->v_subroutinename
+      );
+      newvar = newvar -> suiv;
+      printf("+++++++++++++++++++++++++\n");
+   }
+
+}
+
+
+/******************************************************************************/
+/*                             ListUpdate                                     */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void ListUpdate()
+{
+   listvar *newvar;
+
+   Update_List_Subroutine_Var(List_SubroutineArgument_Var);
+   Update_List_Subroutine_Var(List_FunctionType_Var);
+   Update_List_Var(List_Parameter_Var);
+   Update_List_Var(List_Dimension_Var);
+   Update_List_Var(List_Data_Var);
+   Update_List_Var(List_Save_Var);
+   Update_List_Var(List_GlobalParameter_Var);
+   Update_List_Var(List_Common_Var);
+   Update_List_Var(List_SubroutineDeclaration_Var);
+   Update_List_Var(List_UsedInSubroutine_Var);
+   Update_List_From_Common_Var(List_UsedInSubroutine_Var);
+   Update_NotGridDepend_Var(List_NotGridDepend_Var);
+
+   newvar =(listvar * )NULL;
+/*   newvar = List_Common_Var;*/
+/*   newvar = List_UsedInSubroutine_Var;*/
+   while(newvar)
+   {
+      printf("----- %s --- %s ---%s---\n",newvar->var->v_nomvar,
+         newvar->var->v_commonname,newvar->var->v_readedlistdimension
+      );
+      newvar = newvar -> suiv;
+   }
+}
+
+void GiveTypeOfVariables()
+{
+   listvar *parcours;
+
+   /*                                                                         */
+   parcours = List_Common_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_typevar,"") )
+      {
+         if ( IsVariableReal(parcours->var->v_nomvar) == 1 )
+                                        strcpy(parcours->var->v_typevar,"REAL");
+         else strcpy(parcours->var->v_typevar,"INTEGER");
+      }
+      parcours = parcours -> suiv ;
+   }
+   /*                                                                         */
+   parcours = List_UsedInSubroutine_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_typevar,"") )
+      {
+         if ( IsVariableReal(parcours->var->v_nomvar) == 1 )
+                                        strcpy(parcours->var->v_typevar,"REAL");
+         else strcpy(parcours->var->v_typevar,"INTEGER");
+      }
+      parcours = parcours -> suiv ;
+   }
+   /*                                                                         */
+   parcours = List_SubroutineArgument_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_typevar,"") )
+      {
+         if ( IsVariableReal(parcours->var->v_nomvar) == 1 )
+                                        strcpy(parcours->var->v_typevar,"REAL");
+         else strcpy(parcours->var->v_typevar,"INTEGER");
+      }
+      parcours = parcours -> suiv ;
+   }
+   /*                                                                         */
+   parcours = List_SubroutineDeclaration_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_typevar,"") )
+      {
+         if ( IsVariableReal(parcours->var->v_nomvar) == 1 )
+                                        strcpy(parcours->var->v_typevar,"REAL");
+         else strcpy(parcours->var->v_typevar,"INTEGER");
+      }
+      parcours = parcours -> suiv ;
+   }
+}
+
+
+
+void Sort_List_SubroutineArgument_Var()
+{
+   listvar *parcours;
+   listvar *parcours1;
+   int position;
+   int out;
+   char name_sub[LONGNOM];
+
+   parcours = List_SubroutineArgument_Var;
+   position = 1;
+   while ( parcours )
+   {
+      parcours1 = List_SubroutineDeclaration_Var;
+      out = 0;
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_nomvar,
+                         parcours1->var->v_nomvar)  &&
+              !strcasecmp(parcours->var->v_subroutinename,
+                         parcours1->var->v_subroutinename)
+             )
+         {
+            parcours1->var->v_positioninblock = position;
+            position = position +1 ;
+            out = 1;
+         }
+         else parcours1 = parcours1->suiv;
+      }
+      parcours = parcours->suiv;
+   }
+   /*                                                                         */
+   parcours = List_SubroutineDeclaration_Var;
+   strcpy(name_sub,"");
+   while ( parcours )
+   {
+      if ( !strcasecmp(name_sub,"") )
+      {
+         strcpy(name_sub,parcours->var->v_subroutinename);
+         position = 1;
+      }
+
+      if ( parcours->var->v_positioninblock != 0 )
+      {
+         parcours1 = List_SubroutineArgument_Var;
+         out = 0;
+         while ( parcours1 && out == 0 )
+         {
+            if ( !strcasecmp(parcours->var->v_nomvar,
+                            parcours1->var->v_nomvar)  &&
+                 !strcasecmp(parcours->var->v_subroutinename,
+                            parcours1->var->v_subroutinename)
+                )
+            {
+               parcours1->var->v_positioninblock = position;
+               position = position +1 ;
+               out = 1;
+            }
+            else parcours1 = parcours1->suiv;
+         }
+      }
+      if ( parcours->suiv )
+         if ( strcasecmp(name_sub,parcours->suiv->var->v_subroutinename) )
+            strcpy(name_sub,"");
+      parcours = parcours->suiv;
+   }
+}
+
+
+
+/******************************************************************************/
+/*                      IndiceTabvars_Global_Var_Treated                      */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void IndiceTabvars_Global_Var_Treated(char *nom)
+{
+   listvar *parcours;
+   listvar *parcoursprec;
+   listvar *parcours1;
+   listvar *List_ModuleUsed_Var;
+   listindice *newindice;
+   int out;
+
+   if ( mark == 1 ) printf("MODULE Treated %s \n",nom);
+
+   List_ModuleUsed_Var = (listvar *)NULL;
+   List_ModuleUsed_Var = Readthedependfile(nom,List_ModuleUsed_Var);
+
+   parcours = List_Global_Var;
+   while( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_modulename,nom) )
+      {
+         parcours1 = List_ModuleUsed_Var;
+         out = 0 ;
+         while ( parcours1 && out == 0 )
+         {
+            if ( !strcasecmp(parcours->var->v_nomvar,parcours1->var->v_nomvar)
+               ) out = 1;
+            else
+            {
+               parcoursprec = parcours1 ;
+               parcours1 = parcours1->suiv;
+            }
+         }
+         /* if we found the var Module name in the old list                   */
+         if ( out == 1 )
+         {
+            CopyRecord(parcours->var,parcours1->var);
+            /* Remove this variable from the List_ModuleUsed_Var              */
+            if ( parcours1 == List_ModuleUsed_Var )
+            {
+               List_ModuleUsed_Var = List_ModuleUsed_Var->suiv ;
+            }
+            else
+            {
+               parcoursprec->suiv = parcours1->suiv;
+               free(parcours1);
+               parcours1 = parcoursprec->suiv;
+            }
+         }
+         else
+         /* if we do not found the var Module name in the old list            */
+         {
+            if ( Listofavailableindices )
+            {
+               parcours->var->v_indicetabvars = Listofavailableindices ->
+                                                                       i_indice;
+               if ( Listofavailableindices->suiv )
+                          Listofavailableindices = Listofavailableindices->suiv;
+               else
+                          Listofavailableindices = (listindice *)NULL;
+            }
+            else
+            {
+               indicemaxtabvars = indicemaxtabvars + 1 ;
+               parcours->var->v_indicetabvars = indicemaxtabvars;
+            }
+         }
+      }
+      parcours = parcours->suiv;
+   }
+   /* if List_ModuleUsed_Var is not empty, some var have been removed from    */
+   /*    the last treatement                                                  */
+  parcours1 = List_ModuleUsed_Var;
+  while ( parcours1 )
+  {
+     newindice=(listindice *) malloc (sizeof (listindice));
+     newindice -> i_indice = parcours1 -> var -> v_indicetabvars;
+     newindice -> suiv = Listofavailableindices;
+     Listofavailableindices = newindice;
+     parcours1 = parcours1->suiv;
+  }
+}
+/******************************************************************************/
+/*                       IndiceTabvars_Global_Var_No_Treated                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void IndiceTabvars_Global_Var_No_Treated(char *nom)
+{
+   listvar *parcours;
+
+   if ( mark == 1 ) printf("MODULE No Treated %s \n",nom);
+
+   parcours = List_Global_Var;
+   while( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_modulename,nom) &&
+           parcours->var->v_VariableIsParameter == 0    &&
+           parcours->var->v_notgrid == 0
+          )
+      {
+         indicemaxtabvars = indicemaxtabvars + 1 ;
+         parcours->var->v_indicetabvars = indicemaxtabvars;
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+
+void UpdateTheRemainingList(listvar *record)
+{
+   listvar *parcours;
+
+   parcours = record;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_nomvar,record->var->v_nomvar) &&
+           !strcasecmp(parcours->var->v_commonname,record->var->v_commonname)
+         )
+      {
+         strcpy(parcours->var->v_commoninfile,record->var->v_commoninfile);
+         CopyRecord(parcours->var,record->var);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+
+
+/******************************************************************************/
+/*                      IndiceTabvars_Common_Var_Treated                      */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void IndiceTabvars_Common_Var_Treated(char *nom)
+{
+   listvar *parcours;
+   listvar *parcoursprec;
+   listvar *parcours1;
+   listvar *List_CommonUsed_Var;
+   listindice *newindice;
+   int out;
+
+   if ( mark == 1 ) printf("COMMON Treated %s \n",nom);
+
+   List_CommonUsed_Var = (listvar *)NULL;
+   List_CommonUsed_Var = Readthedependfile(nom,List_CommonUsed_Var);
+
+   parcours = List_Common_Var;
+   while( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_commonname,nom) )
+      {
+         parcours1 = List_CommonUsed_Var;
+         out = 0 ;
+         while ( parcours1 && out == 0 )
+         {
+
+            if ( !strcasecmp(parcours1->var->v_commonname,nom) &&
+                 !strcasecmp(parcours->var->v_nomvar,parcours1->var->v_nomvar)
+               ) out = 1;
+            else
+            {
+               parcoursprec = parcours1 ;
+               parcours1 = parcours1->suiv;
+            }
+         }
+         /* if we found the var common name in the old list                   */
+         if ( out == 1 )
+         {
+            strcpy(parcours->var->v_commoninfile,
+                   parcours1->var->v_commoninfile);
+            CopyRecord(parcours->var,parcours1->var);
+         }
+         else
+         /* if we do not found the var common name in the old list            */
+         {
+            if ( Listofavailableindices )
+            {
+               parcours->var->v_indicetabvars = Listofavailableindices ->
+                                                                       i_indice;
+               if ( Listofavailableindices->suiv )
+                          Listofavailableindices = Listofavailableindices->suiv;
+               else
+                          Listofavailableindices = (listindice *)NULL;
+            }
+            else
+            {
+               indicemaxtabvars = indicemaxtabvars + 1 ;
+               parcours->var->v_indicetabvars = indicemaxtabvars;
+            }
+         }
+         /* Look in the remaining list in the variable is define              */
+         UpdateTheRemainingList(parcours);
+      }
+      parcours = parcours->suiv;
+   }
+   /* if List_CommonUsed_Var is not empty, some var have been removed from    */
+   /*    the last treatement                                                  */
+  parcours1 = List_CommonUsed_Var;
+  while ( parcours1 )
+  {
+     if ( parcours1 -> var -> v_indicetabvars == 0 )
+     {
+        newindice=(listindice *) malloc (sizeof (listindice));
+        newindice -> i_indice = parcours1 -> var -> v_indicetabvars;
+        newindice -> suiv = Listofavailableindices;
+        Listofavailableindices = newindice;
+     }
+     parcours1 = parcours1->suiv;
+  }
+}
+/******************************************************************************/
+/*                     IndiceTabvars_Common_Var_No_Treated                    */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void IndiceTabvars_Common_Var_No_Treated(char *nom)
+{
+   listvar *parcours;
+   listvar *parcours2;
+
+   if ( mark == 1 ) printf("COMMON No Treated %s \n",nom);
+
+   parcours = List_Common_Var;
+   while( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_commonname,nom) &&
+           strcasecmp(parcours->var->v_subroutinename,"") &&
+           parcours->var->v_indicetabvars == 0
+          )
+      {
+         indicemaxtabvars = indicemaxtabvars + 1 ;
+         parcours->var->v_indicetabvars = indicemaxtabvars;
+         parcours2 = parcours;
+         while ( parcours2 )
+         {
+            if ( !strcasecmp(parcours->var->v_nomvar,
+                             parcours2->var->v_nomvar) &&
+                 !strcasecmp(parcours->var->v_commonname,
+                             parcours2->var->v_commonname)
+               )
+               parcours2->var->v_indicetabvars = parcours->var->v_indicetabvars;
+            parcours2 = parcours2->suiv;
+         }
+      }
+      parcours = parcours->suiv;
+   }
+}
+
+
+/******************************************************************************/
+/*                       IndiceTabvarsIdentification                          */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void IndiceTabvarsIdentification()
+{
+   listvar *parcours;
+   listnom *parcours_nom;
+
+   /* Identification of tabvars indices in List_Global_Var                    */
+   parcours_nom = List_NameOfModule;
+   while ( parcours_nom )
+   {
+      if ( Did_module_common_treaded(parcours_nom->o_nom) == 1 )
+      {
+         IndiceTabvars_Global_Var_Treated(parcours_nom->o_nom);
+      }
+      else
+      {
+         IndiceTabvars_Global_Var_No_Treated(parcours_nom->o_nom);
+      }
+      parcours_nom = parcours_nom -> suiv;
+   }
+   /* Identification of tabvars indices in List_Common_Var                    */
+   parcours_nom = List_NameOfCommon;
+   while ( parcours_nom )
+   {
+      if ( Did_module_common_treaded(parcours_nom->o_nom) == 1 )
+      {
+         IndiceTabvars_Common_Var_Treated(parcours_nom->o_nom);
+      }
+      else
+      {
+         IndiceTabvars_Common_Var_No_Treated(parcours_nom->o_nom);
+      }
+      parcours_nom = parcours_nom -> suiv;
+   }
+
+}
+
+void New_Allocate_Subroutine_Is_Necessary()
+{
+   listnom *parcours_nom;
+   listvar *parcours;
+   int out;
+
+   parcours_nom = List_NameOfModule;
+   while ( parcours_nom )
+   {
+      /*                                                                      */
+      parcours = List_Global_Var;
+      out = 0 ;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom) &&
+              !strcasecmp(parcours->var->v_subroutinename,"")            &&
+              parcours->var->v_VariableIsParameter == 0                  &&
+              parcours->var->v_allocatable == 0                          &&
+              parcours->var->v_notgrid == 0                              &&
+              ( parcours->var->v_nbdim != 0 ||
+                strcasecmp(parcours->var->v_initialvalue,"")
+              ) ) out = 1;
+         else parcours = parcours -> suiv;
+      }
+      if ( out == 1 )
+      {
+         parcours_nom->o_val = 1 ;
+      }
+      /*                                                                      */
+      parcours_nom = parcours_nom -> suiv;
+   }
+}
+
+void New_Allocate_Subroutine_For_Common_Is_Necessary()
+{
+   listnom *parcours_nom;
+   listvar *parcours;
+   int out;
+
+   parcours_nom = List_NameOfCommon;
+   while ( parcours_nom )
+   {
+      /*                                                                      */
+      parcours = List_Common_Var;
+      out = 0 ;
+      while( parcours && out == 0 )
+      {
+         if ( !strcasecmp(parcours->var->v_commonname,parcours_nom->o_nom)  &&
+              strcasecmp(parcours->var->v_subroutinename,"")                &&
+              !strcasecmp(parcours->var->v_commoninfile,mainfile)           &&
+              ( parcours->var->v_nbdim != 0 ||
+                strcasecmp(parcours->var->v_initialvalue,"")
+              ) ) out = 1;
+         else parcours = parcours -> suiv;
+      }
+      if ( out == 1 )
+      {
+         parcours_nom->o_val = 1 ;
+      }
+      /*                                                                      */
+      parcours_nom = parcours_nom -> suiv;
+   }
+}
+
+void NewModule_Creation_0()
+{
+   listvar *parcours;
+   listnom *parcours_nom;
+   char name_tmp[LONGNOM];
+   char ligne[LONGNOM];
+
+   if ( firstpass == 0 )
+   {
+      parcours_nom = List_NameOfCommon;
+      while ( parcours_nom )
+      {
+         if ( parcours_nom->o_val == 1 )
+         {
+            sprintf (ligne, "module %s",parcours_nom->o_nom);
+            tofich(fortranout,ligne,1);
+            strcpy(ligne,"implicit none");
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "public Alloc_agrif_%s",parcours_nom->o_nom);
+            tofich(fortranout,ligne,1);
+            strcpy (ligne, "contains");
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "subroutine Alloc_agrif_%s(Agrif_Gr)",
+                                                           parcours_nom->o_nom);
+            tofich(fortranout,ligne,1);
+            strcpy(ligne,"Use Agrif_Util");
+            tofich(fortranout,ligne,1);
+            strcpy (ligne, "Type(Agrif_grid), Pointer :: Agrif_Gr");
+            tofich(fortranout,ligne,1);
+            strcpy(ligne, "INTEGER :: i");
+            tofich (fortranout, ligne,1);
+            strcpy (ligne, "\n#include \"alloc_agrif_");
+            strcat (ligne, parcours_nom->o_nom);
+            strcat (ligne, ".h\"\n");
+            fprintf(fortranout,ligne);
+            strcpy (ligne, "Return");
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "end subroutine Alloc_agrif_%s",
+                                                           parcours_nom->o_nom);
+            tofich(fortranout,ligne,1);
+            sprintf (ligne, "end module %s",parcours_nom->o_nom);
+            tofich(fortranout,ligne,1);
+            /* List all Call Alloc_agrif                                      */
+            Add_Subroutine_For_Alloc(parcours_nom->o_nom);
+         }
+         parcours_nom = parcours_nom->suiv;
+      }
+   }
+}
+
+void UpdateList_SubroutineWhereAgrifUsed()
+{
+   listnom *parcours;
+   listusemodule *parcours1;
+   listallocate *parcours2;
+   listname *parcours3;
+   listvar *parcours4;
+   int out;
+   char name_module[LONGNOM];
+
+   /* We should integrate allocate and pointer variables                      */
+   parcours2 = List_Allocate_Var;
+   while ( parcours2 )
+   {
+      parcours4 = List_UsedInSubroutine_Var;
+      out = 0 ;
+      while ( parcours4 && out == 0 )
+      {
+         if ( !strcasecmp(parcours2->a_nomvar,parcours4->var->v_nomvar) )
+         {
+            Add_SubroutineWhereAgrifUsed_1(parcours4->var->v_subroutinename,
+                                           parcours4->var->v_modulename);
+            out = 1;
+         }
+         else parcours4 = parcours4 -> suiv ;
+      }
+      parcours2 = parcours2->suiv;
+   }
+   /*                                                                         */
+   parcours3 = List_Pointer_Var;
+   while ( parcours3 )
+   {
+      parcours4 = List_UsedInSubroutine_Var;
+      out = 0 ;
+      while ( parcours4 && out == 0 )
+      {
+         if ( !strcasecmp(parcours3->n_name,parcours4->var->v_nomvar) )
+         {
+            Add_SubroutineWhereAgrifUsed_1(parcours4->var->v_subroutinename,
+                                           parcours4->var->v_modulename);
+            out = 1;
+         }
+         else parcours4 = parcours4 -> suiv ;
+      }
+      parcours3 = parcours3 -> suiv;
+   }
+   /*                                                                         */
+   parcours4 = List_UsedInSubroutine_Var;
+   while ( parcours4 )
+   {
+      if ( parcours4->var->v_allocatable == 1 )
+      {
+         Add_SubroutineWhereAgrifUsed_1(parcours4->var->v_subroutinename,
+                                        parcours4->var->v_modulename);
+      }
+      parcours4 = parcours4 -> suiv ;
+   }
+   /*                                                                         */
+   parcours = List_SubroutineWhereAgrifUsed;
+   while ( parcours )
+   {
+      parcours1 = List_NameOfModuleUsed;
+      out = 0 ;
+      strcpy(name_module,"");
+      while ( parcours1 && out == 0 )
+      {
+         if ( !strcasecmp(parcours->o_nom,parcours1->u_cursubroutine) &&
+              !strcasecmp(parcours1->u_usemodule,"Agrif_Util")
+            ) out = 1;
+         else
+         {
+            if ( !strcasecmp(parcours->o_nom,parcours1->u_cursubroutine) )
+            {
+               strcpy(name_module,parcours->o_module);
+            }
+            parcours1 = parcours1->suiv;
+         }
+      }
+      /* if out == 0 we should look in the module declaration                 */
+      if ( out == 0 )
+      {
+         parcours1 = List_NameOfModuleUsed;
+         out = 0 ;
+         while ( parcours1 && out == 0 )
+         {
+            if ( !strcasecmp(name_module,parcours1->u_modulename) &&
+                 !strcasecmp(parcours1->u_cursubroutine,"")&&
+                 !strcasecmp(parcours1->u_usemodule,"Agrif_Util")
+               ) out = 1;
+            else parcours1 = parcours1->suiv;
+         }
+      }
+      if ( out == 0 ) parcours->o_val = 1;
+      /*                                                                      */
+      parcours = parcours->suiv;
+   }
+}
+
+
+void UpdateList_UsedInSubroutine_With_dimension()
+{
+   listvar *parcours;
+
+   parcours = List_UsedInSubroutine_Var;
+   while ( parcours )
+   {
+      if ( parcours->var->v_nbdim != 0 )
+      {
+         strcpy(subroutinename,parcours->var->v_subroutinename);
+         DecomposeTheName(parcours->var->v_readedlistdimension);
+         strcpy(subroutinename,"");
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void Affiche()
+{
+   listvar *parcours;
+
+   parcours = (listvar *)NULL;
+/*   parcours = List_Global_Var;                  */
+/*   parcours = List_SubroutineDeclaration_Var;   */
+
+/*   parcours = List_SubroutineArgument_Var;      */
+/*   parcours = List_FunctionType_Var;            */
+
+/*   parcours = List_Data_Var;                    */
+/*   parcours = List_Save_Var;                    */
+/*   parcours = List_UsedInSubroutine_Var;        */
+/*   parcours = List_Parameter_Var;               */
+/*   parcours = List_GlobalParameter_Var;         */
+/*   parcours = List_NotGridDepend_Var;           */
+
+/*   parcours = List_Common_Var;                  */
+
+   while( parcours )
+   {
+      printf("module- %s \n",parcours->var->v_modulename);
+      printf("subroutine- %s  \n",parcours->var->v_subroutinename);
+      printf("nom- %s  \n",parcours->var->v_nomvar);
+      printf("common- %s  \n",parcours->var->v_commonname);
+      printf("type- %s  \n",parcours->var->v_typevar);
+      printf("indice- %d  \n",parcours->var->v_indicetabvars);
+      printf("variableisparameter- %d \n",parcours->var->v_VariableIsParameter);
+      printf("module1- %d  \n",parcours->var->v_module);
+      printf("save- %d  \n",parcours->var->v_save);
+      printf("notgrid- %d  \n",parcours->var->v_notgrid);
+      printf("nbdim- %d  \n",parcours->var->v_nbdim);
+      printf("common1- %d  \n",parcours->var->v_common);
+      printf("v_dimensiongiven- %d  \n",parcours->var->v_dimensiongiven);
+      printf("v_dimsempty- %d  \n",parcours->var->v_dimsempty);
+      printf("initialvalue- %s\n \n",parcours->var->v_initialvalue);
+      printf("dim- %s\n \n",parcours->var->v_readedlistdimension);
+
+      parcours = parcours -> suiv ;
+   }
+   if ( mark == 1 ) printf("Indicemaxtabvars = %d \n",indicemaxtabvars);
+}
+
+
+
+
+int SubInList_ContainsSubroutine()
+{
+   int out;
+   listnom *parcours;
+
+   out = 0 ;
+   parcours = List_ContainsSubroutine;
+   while ( parcours && out == 0 )
+   {
+      if ( !strcasecmp(parcours->o_nom,subroutinename) ) out = 1 ;
+      else parcours = parcours -> suiv;
+   }
+
+   return out;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithvarofsubroutineliste.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithvarofsubroutineliste.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WorkWithvarofsubroutineliste.c	(revision 4536)
@@ -0,0 +1,105 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                      Add_SubroutineArgument_Var_1                          */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should complete the                                                     */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_SubroutineArgument_Var_1(listvar *listtoadd)
+{
+
+   if ( firstpass == 1 )
+   {
+       List_SubroutineArgument_Var = AddListvarToListvar
+                              (listtoadd,List_SubroutineArgument_Var,1);
+   }
+}
+
+/******************************************************************************/
+/*                             Add_FunctionType_Var_1                         */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should complete the                                                     */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_FunctionType_Var_1(char *nom)
+{
+   listvar *newvar;
+
+   if ( firstpass == 1 )
+   {
+      curvar=createvar(nom,NULL);
+      strcpy(curvar->v_typevar,DeclType);
+      newvar = insertvar(NULL,curvar);
+      List_FunctionType_Var = AddListvarToListvar
+                              (newvar,List_FunctionType_Var,1);
+   }
+}
+
+
+/******************************************************************************/
+/*                      Add_SubroutineDeclaration_Var_1                       */
+/******************************************************************************/
+/* Firstpass 1                                                                */
+/* We should complete the listvarofsubroutine                                 */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Add_SubroutineDeclaration_Var_1 (listvar *listtoadd)
+{
+   if ( firstpass == 1 )
+   {
+      if ( VariableIsParameter == 0 &&
+           SaveDeclare         == 0 )
+      {
+         listduplicated = (listvar *)NULL;
+         duplicatelistvar(listtoadd);
+         List_SubroutineDeclaration_Var = AddListvarToListvar
+                              (listduplicated,List_SubroutineDeclaration_Var,1);
+      }
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WriteInFile.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WriteInFile.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/WriteInFile.c	(revision 4536)
@@ -0,0 +1,227 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+/******************************************************************************/
+/*                            tofich_reste                                    */
+/******************************************************************************/
+/* This subroutine is used to write the string s into the fileout             */
+/******************************************************************************/
+void tofich_reste (FILE * filout, char *s,int returnlineornot)
+{
+  char temp[61];
+  char *tmp;
+  int size;
+
+
+  if (strlen (s) <= 60)
+    {
+      if ( returnlineornot == 0 ) fprintf (filout, "     & %s", s);
+      else if ( returnlineornot == 2 ) fprintf (filout, "& %s", s);
+      else if ( returnlineornot == 3 ) fprintf (filout, "& %s\n", s);
+      else                             fprintf (filout, "     & %s\n", s);
+      if ( returnlineornot == 0 ||
+           returnlineornot == 2 ) colnum=colnum+strlen(s)+6;
+      else colnum=0;
+    }
+  else
+    {
+      strncpy (temp, s, 60);
+      strcpy (&temp[60], "\0");
+
+      tmp = strrchr(temp, '+');
+
+      if ( !tmp || strlen(tmp) == 60 ) tmp = strrchr(temp, '-');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '/');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '*');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, '%');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ',');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ':');
+      if ( !tmp || strlen(tmp) == 60  ) tmp = strrchr(temp, ')');
+      if ( tmp )
+      {
+         size = strlen(tmp);
+      }
+      else
+      {
+         size = 0 ;
+      }
+
+      strcpy (&temp[60-size], "\0");
+
+      if ( retour77 == 0 ) fprintf (filout, "     & %s  &\n", temp);
+      else fprintf (filout, "     & %s  \n", temp);
+      colnum=0;
+      tofich_reste (filout, (char *) &s[60-size],returnlineornot);
+    }
+}
+
+/******************************************************************************/
+/*                            tofich                                          */
+/******************************************************************************/
+/* This subroutine is used to write the string s into the fileout             */
+/******************************************************************************/
+void tofich (FILE * filout, char *s, int returnlineornot)
+{
+  char temp[61];
+  char *tmp;
+  int size;
+
+  if (strlen (s) <= 60)
+    {
+      if ( returnlineornot == 0 ) fprintf (filout, "      %s", s);
+      else if ( returnlineornot == 2 ) fprintf (filout, "%s", s);
+      else if ( returnlineornot == 3 ) fprintf (filout, "%s\n", s);
+      else                             fprintf (filout, "      %s\n", s);
+      if ( returnlineornot == 0 || returnlineornot == 2 )
+                                                      colnum=colnum+strlen(s)+6;
+      else colnum=0;
+    }
+  else
+    {
+      strncpy (temp, s, 60);
+      strcpy (&temp[60], "\0");
+
+      tmp = strrchr(temp, ',');
+      if ( !tmp  || strlen(tmp) == strlen(temp) ) tmp = strrchr(temp, '+');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '-');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '/');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '*');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, '%');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ',');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ':');
+      if ( !tmp  || strlen(tmp) == strlen(temp)  ) tmp = strrchr(temp, ')');
+      if ( tmp )
+      {
+         size = strlen(tmp);
+      }
+      else
+      {
+         size = 0 ;
+      }
+
+      strcpy (&temp[60-size], "\0");
+
+      if ( retour77 == 0 ) fprintf (filout, "      %s  &\n", temp);
+      else fprintf (filout, "      %s  \n", temp);
+      colnum=0;
+      tofich_reste (filout, (char *) &s[60-size], returnlineornot);
+    }
+}
+
+/******************************************************************************/
+/*                       tofich_blanc                                         */
+/******************************************************************************/
+/* This subroutine is used to write size blank into the fileout               */
+/******************************************************************************/
+void tofich_blanc (FILE * filout, int size)
+{
+  int i;
+
+  if (size <= 65) fprintf (filout, "%*s\n",size,EmptyChar);
+  else
+  {
+      i=0;
+      do
+      {
+         fprintf (filout, "%*s\n",65,EmptyChar);
+         i = i+1;
+      } while ( i <= size / 65 );
+         fprintf (filout, "%*s\n",size%65,EmptyChar);
+  }
+
+}
+/******************************************************************************/
+/*                       tofich_line                                          */
+/******************************************************************************/
+/* This subroutine is used to write size blank into the fileout               */
+/******************************************************************************/
+void tofich_line (FILE * filout, int size, int long position)
+{
+  int i;
+  int retour;
+
+  if (size <= 65) fprintf (filout, "%*s",size,EmptyChar);
+  else
+  {
+      i=0;
+      do
+      {
+         fprintf (filout, "%*s",65,EmptyChar);
+         i = i+1;
+      } while ( i <= size / 65 );
+         fprintf (filout, "%*s",size%65,EmptyChar);
+  }
+
+   if ( !strstr(motparse1,"\n") ) retour=0;
+   else retour=1;
+
+   fseek(filout,position,SEEK_SET);
+   if (retour == 1 ) fprintf (filout, "\n");
+
+}
+
+
+/******************************************************************************/
+/*                           RemoveWordSET_0                                  */
+/******************************************************************************/
+/* This subroutine is used to remove a sentence in the file filout            */
+/******************************************************************************/
+void RemoveWordSET_0(FILE * filout, long int position, long int sizetoremove)
+{
+   if ( firstpass == 0 && couldaddvariable == 1 )
+   {
+      fseek(filout,position,SEEK_SET);
+      tofich_line(filout,sizetoremove,position);
+   }
+}
+
+
+/******************************************************************************/
+/*                         RemoveWordCUR_0                                    */
+/******************************************************************************/
+/* This subroutine is used to remove a sentence in the file filout            */
+/******************************************************************************/
+void RemoveWordCUR_0(FILE * filout, long int position, long int sizetoremove)
+{
+   if ( firstpass == 0  && couldaddvariable == 1 )
+   {
+      fseek(filout,position,SEEK_CUR);
+      tofich_blanc(filout,sizetoremove);
+   }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Writedeclarations.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Writedeclarations.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/Writedeclarations.c	(revision 4536)
@@ -0,0 +1,571 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "decl.h"
+
+/******************************************************************************/
+/*                         WriteBeginDeclaration                              */
+/******************************************************************************/
+/* This subroutine is used to write the begin of a declaration                */
+/* taken in a variable record                                                 */
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*       integer variable ----------->   INTEGER                              */
+/*                                                                            */
+/******************************************************************************/
+void WriteBeginDeclaration(variable *v,char ligne[LONGLIGNE])
+{
+  char tmpligne[LONGLIGNE];
+
+  if ( !strcasecmp(v->v_typevar,"") )
+  {
+     printf("WARNING : The type of the variable %s \n",v->v_nomvar);
+     printf("          is unknown. CONV should define a type\n");
+  }
+  sprintf (ligne, "%s", v->v_typevar);
+  if ( v->v_c_star == 1 ) strcat(ligne,"*");
+  /* We should give the precision of the variable if it has been given        */
+  if ( strcasecmp(v->v_precision,"") )
+  {
+     sprintf(tmpligne,"(%s)",v->v_precision);
+     strcat(ligne,tmpligne);
+  }
+  if (strcasecmp(v->v_dimchar,""))
+  {
+     sprintf(tmpligne,"(%s)",v->v_dimchar);
+     strcat(ligne,tmpligne);
+  }
+  if ( strcasecmp(v->v_nameinttypename,"") )
+  {
+     sprintf(tmpligne,"*%s",v->v_nameinttypename);
+     strcat(ligne,tmpligne);
+  }
+  if (strcasecmp (v->v_IntentSpec, ""))
+  {
+     sprintf(tmpligne,",INTENT(%s) ",v->v_IntentSpec);
+     strcat(ligne,tmpligne);
+  }
+  if ( v->v_VariableIsParameter == 1 ) strcat(ligne, ", PARAMETER");
+  if ( v->v_PublicDeclare       == 1 ) strcat(ligne, ", PUBLIC");
+  if ( v->v_PrivateDeclare      == 1 ) strcat(ligne, ", PRIVATE");
+  if ( v->v_ExternalDeclare     == 1 ) strcat(ligne, ", EXTERNAL");
+  if ( v->v_allocatable         == 1 &&
+       v->v_save                == 0 ) strcat(ligne,", ALLOCATABLE");
+  if ( v->v_optionaldeclare     == 1 ) strcat(ligne,", OPTIONAL");
+  if ( v->v_pointerdeclare      == 1 ) strcat(ligne,", POINTER");
+}
+
+
+/******************************************************************************/
+/*                         WriteScalarDeclaration                             */
+/******************************************************************************/
+/* This subroutine is used to write a scalar declaration                      */
+/* taken in a variable record                                                 */
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*       integer variable ----------->   INTEGER :: VARIABLE                  */
+/*                                                                            */
+/******************************************************************************/
+void WriteScalarDeclaration(variable *v,char ligne[LONGLIGNE])
+{
+
+  strcat (ligne, " :: ");
+  strcat (ligne, v->v_nomvar);
+  if ( strcasecmp(v->v_vallengspec,"") ) strcat(ligne,v->v_vallengspec);
+  if ( v->v_VariableIsParameter == 1 )
+  {
+     strcat(ligne," = ");
+     strcat(ligne,v->v_initialvalue);
+  }
+}
+
+
+/******************************************************************************/
+/*                         WriteTableDeclaration                              */
+/******************************************************************************/
+/* This subroutine is used to write a Table declaration                       */
+/* taken in a variable record                                                 */
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                      INTEGER, DIMENSION(1:nb) :: variable                  */
+/*                                                                            */
+/******************************************************************************/
+void WriteTableDeclaration(variable * v,char ligne[LONGLIGNE],int tmpok)
+{
+  char newname[LONGNOM];
+
+  strcat (ligne, ", Dimension(");
+  if ( v->v_dimensiongiven == 1 && tmpok == 1 )
+                                         strcat(ligne,v->v_readedlistdimension);
+  if ( v->v_dimensiongiven == 1 && tmpok == 0 )
+  {
+     strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                                  (v->v_readedlistdimension,List_Global_Var,0));
+     if ( !strcasecmp(newname,v->v_readedlistdimension) )
+     {
+        strcpy(newname,"");
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                                 (v->v_readedlistdimension,List_Common_Var,0));
+        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
+     }
+     if ( !strcasecmp(newname,v->v_readedlistdimension) )
+     {
+        strcpy(newname,"");
+        /* la liste des use de cette subroutine                               */
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                              (v->v_readedlistdimension,List_ModuleUsed_Var,0));
+        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
+     }
+     strcat(ligne,newname);
+  }
+  strcat (ligne, ")");
+  strcat (ligne, " :: ");
+  strcat (ligne, v->v_nomvar);
+  if ( strcasecmp(vallengspec,"") ) strcat(ligne,v->v_vallengspec);
+/*  if ( !strcasecmp (v->v_typevar, "character") )
+                              strcat(ligne,vargridparam(v,0));*/
+  if ( v->v_VariableIsParameter == 1 )
+  {
+     strcat(ligne," = ");
+     strcat(ligne,v->v_initialvalue);
+  }
+}
+
+/******************************************************************************/
+/*                        writevardeclaration                                 */
+/******************************************************************************/
+/* This subroutine is used to write the initial declaration in the file       */
+/* fileout of a variable                                                      */
+/*                                                                            */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                      INTEGER, DIMENSION(1:nb),Pointer :: variable          */
+/*                                                                            */
+/******************************************************************************/
+void writevardeclaration (listvar * var_record, FILE *fileout, int value)
+{
+  FILE *filecommon;
+  listvar *newvar;
+  variable *v;
+  char ligne[LONGNOM];
+
+  filecommon=fileout;
+  newvar = var_record;
+
+  if ( newvar->var->v_save == 0 || inmodulemeet == 0 )
+  {
+     v = newvar->var;
+     WriteBeginDeclaration(v,ligne);
+     if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
+     else WriteTableDeclaration(v,ligne,value);
+
+     if ( v->v_VariableIsParameter != 1 && strcasecmp(v->v_initialvalue,"") )
+     {
+        strcat(ligne," = ");
+        strcat(ligne,v->v_initialvalue);
+     }
+     tofich (filecommon, ligne,1);
+  }
+}
+
+
+void WriteLocalParamDeclaration()
+{
+   listvar *parcours;
+
+   parcours = List_Parameter_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
+      {
+         writevardeclaration(parcours,fortranout,0);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteFunctionDeclaration()
+{
+   listvar *parcours;
+
+   parcours = List_FunctionType_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+            strcasecmp(parcours->var->v_typevar,"")
+         )
+      {
+         writevardeclaration(parcours,fortranout,0);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteSubroutineDeclaration(int value)
+{
+   listvar *parcours;
+
+   parcours = List_SubroutineDeclaration_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+           parcours->var->v_save == 0                                  &&
+           parcours->var->v_allocatable == 0                           &&
+           parcours->var->v_pointerdeclare == 0                        &&
+           parcours->var->v_VariableIsParameter == 0                   &&
+           parcours->var->v_common == 0
+         )
+      {
+         writevardeclaration(parcours,fortranout,value);
+      }
+      else if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+           parcours->var->v_save == 0                                  &&
+           parcours->var->v_VariableIsParameter == 0                   &&
+           parcours->var->v_common == 0
+              )
+      {
+         writevardeclaration(parcours,fortranout,value);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteArgumentDeclaration_beforecall()
+{
+   variable *v;
+   int position;
+   listnom *neededparameter;
+   FILE *paramtoamr;
+   listvar *newvar;
+   char ligne[LONGLIGNE];
+   int out;
+   int writeit;
+   listnom *parcours;
+
+   fprintf(fortranout,"#include \"Param_BeforeCall_%s.h\" \n",subroutinename);
+   /*                                                                         */
+   sprintf(ligne,"Param_BeforeCall_%s.h",subroutinename);
+   paramtoamr = associate (ligne);
+   /*                                                                         */
+   neededparameter = (listnom * )NULL;
+   /*                                                                         */
+   position = 1;
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == position
+         )
+      {
+         position = position + 1;
+         writevardeclaration(newvar,fortranout,0);
+         neededparameter = writedeclarationintoamr(List_Parameter_Var,
+                   paramtoamr,newvar->var,newvar->var->v_subroutinename,
+                   neededparameter,subroutinename);
+
+         newvar = List_SubroutineArgument_Var;
+      }
+      else newvar = newvar -> suiv;
+   }
+   fclose(paramtoamr);
+}
+
+void WriteArgumentDeclaration_Sort()
+{
+   variable *v;
+   int position;
+/*   listnom *neededparameter;*/
+   FILE *paramtoamr;
+   listvar *newvar;
+   char ligne[LONGLIGNE];
+   int out;
+   int writeit;
+   listnom *parcours;
+
+   /*                                                                         */
+   position = 1;
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == position
+         )
+      {
+         position = position + 1;
+         writevardeclaration(newvar,fortranout,1);
+         /*                                                                   */
+         newvar = List_SubroutineArgument_Var;
+      }
+      else newvar = newvar -> suiv;
+   }
+   /*                                                                         */
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == 0           &&
+                       newvar->var->v_nbdim == 0
+         )
+      {
+         writevardeclaration(newvar,fortranout,1);
+      }
+      newvar = newvar -> suiv;
+   }
+   /*                                                                         */
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == 0           &&
+                       newvar->var->v_nbdim != 0
+         )
+      {
+         writevardeclaration(newvar,fortranout,1);
+      }
+      newvar = newvar -> suiv;
+   }
+}
+
+/******************************************************************************/
+/*                      writedeclarationintoamr                               */
+/******************************************************************************/
+/* This subroutine is used to write the declaration of parameters needed in   */
+/*    allocation subroutines creates in toamr.c                               */
+/******************************************************************************/
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+listnom *writedeclarationintoamr (listvar * deb_common, FILE *fileout,
+                              variable *var , char commonname[LONGNOM],
+                           listnom *neededparameter, char name_common[LONGNOM])
+{
+  listvar *newvar;
+  variable *v;
+  char ligne[LONGLIGNE];
+  int changeval;
+  char firstmodule[LONGNOM];
+  int out;
+  int writeit;
+  listnom *parcours;
+  listnom *parcoursprec;
+
+  parcoursprec = (listnom * )NULL;
+  /* we should list the needed parameter                                      */
+  if ( !strcasecmp(name_common,commonname) )
+     neededparameter = DecomposeTheNameinlistnom(var->v_readedlistdimension,
+                                                               neededparameter);
+  /*                                                                          */
+  parcours = neededparameter;
+  while (parcours)
+  {
+     newvar = deb_common;
+     out = 0 ;
+     while ( newvar && out == 0 )
+     {
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
+        {
+           out=1;
+        /* add the name to the list of needed parameter                       */
+           neededparameter = DecomposeTheNameinlistnom(
+                 newvar->var->v_initialvalue,
+                 neededparameter );
+        }
+        else newvar=newvar->suiv;
+     }
+     parcours=parcours->suiv;
+   }
+  /*                                                                          */
+  parcours = neededparameter;
+  while (parcours)
+  {
+     newvar = deb_common;
+     out = 0 ;
+     while ( newvar && out == 0 )
+     {
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
+        {
+           out=1;
+        /* add the name to the list of needed parameter                       */
+           neededparameter = DecomposeTheNameinlistnom(
+                 newvar->var->v_initialvalue,
+                 neededparameter );
+        }
+        else newvar=newvar->suiv;
+     }
+     parcours=parcours->suiv;
+   }
+  /*                                                                          */
+  strcpy(firstmodule,"");
+  tofich (fileout, "",1);
+  parcours = neededparameter;
+  while (parcours)
+  {
+     writeit = 0;
+     newvar = deb_common;
+     while ( newvar && writeit == 0 )
+     {
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) &&
+             parcours->o_val == 0 )
+        {
+           writeit=1;
+           parcours->o_val = 1;
+        }
+        else newvar = newvar->suiv;
+     }
+
+     if ( writeit == 1  )
+     {
+        changeval = 0;
+        v = newvar->var;
+        if ( v->v_allocatable == 1  )
+        {
+           changeval = 1;
+           v->v_allocatable = 0;
+        }
+        WriteBeginDeclaration(v,ligne);
+        if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
+        else WriteTableDeclaration(v,ligne,1);
+
+        tofich (fileout, ligne,1);
+        if ( changeval == 1 )
+        {
+           v->v_allocatable = 1;
+        }
+     }
+     else
+     {
+        if (  strncasecmp(parcours->o_nom,"mpi_",4) == 0 &&
+              shouldincludempif                     == 1 )
+        {
+           shouldincludempif = 0;
+           fprintf(fileout,"      include \'mpif.h\' \n");
+        }
+     }
+     parcours=parcours->suiv;
+  }
+  return neededparameter;
+}
+
+
+/******************************************************************************/
+/*                       writesub_loopdeclaration_scalar                      */
+/******************************************************************************/
+/* This subroutine is used to write the declaration part of subloop           */
+/*    subroutines                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                                                                            */
+/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
+/*                                                                            */
+/******************************************************************************/
+void writesub_loopdeclaration_scalar (listvar * deb_common, FILE *fileout)
+{
+  listvar *newvar;
+  variable *v;
+  char ligne[LONGLIGNE];
+
+  tofich (fileout, "",1);
+  newvar = deb_common;
+  while (newvar)
+  {
+     if ( newvar->var->v_nbdim == 0 &&
+          !strcasecmp(newvar->var->v_subroutinename,subroutinename)  &&
+           newvar->var->v_allocatable == 0                           &&
+           newvar->var->v_pointerdeclare == 0
+         )
+     {
+        v = newvar->var;
+
+        WriteBeginDeclaration(v,ligne);
+        WriteScalarDeclaration(v,ligne);
+        tofich (fileout, ligne,1);
+     }
+     newvar = newvar->suiv;
+  }
+}
+
+/******************************************************************************/
+/*                       writesub_loopdeclaration_tab                         */
+/******************************************************************************/
+/* This subroutine is used to write the declaration part of subloop           */
+/*    subroutines                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                                                                            */
+/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
+/*                                                                            */
+/******************************************************************************/
+void writesub_loopdeclaration_tab (listvar * deb_common, FILE *fileout)
+{
+  listvar *newvar;
+  variable *v;
+  char ligne[LONGLIGNE];
+  int changeval;
+
+  tofich (fileout, "",1);
+  newvar = deb_common;
+  while (newvar)
+  {
+     if ( newvar->var->v_nbdim != 0                                 &&
+          !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+          newvar->var->v_allocatable == 0                           &&
+          newvar->var->v_pointerdeclare == 0
+        )
+     {
+        changeval = 0;
+        v = newvar->var;
+        if ( v->v_allocatable == 1 )
+        {
+           changeval = 1;
+           v->v_allocatable = 0;
+        }
+        WriteBeginDeclaration(v,ligne);
+        WriteTableDeclaration(v,ligne,1);
+        tofich (fileout, ligne,1);
+        if ( changeval == 1 ) v->v_allocatable = 1;
+     }
+     newvar = newvar->suiv;
+  }
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.lex
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.lex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.lex	(revision 4536)
@@ -0,0 +1,87 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+%s character
+%{
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+int line_num=1;
+extern FILE * yyin;
+#define MAX_INCLUDE_DEPTH 30
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+%}
+
+COMMENT "%"
+SEPARATEUR "::"
+NIMPORTEQUOI .
+COMMENTAIRES1 {COMMENT}{NIMPORTEQUOI}*{COMMENT}
+PROBTYPE "1D"|"2D"|"3D"
+USEITEM "FIXED_GRIDS"|"ONLY_FIXED_GRIDS"|"F77"
+NAME [a-zA-Z\_][a-zA-Z0-9\_]*
+DIGIT [0-9]+
+NEXTLINE \n+[ \t]+"$"|\n+[ \t]+"&"
+%%
+parammodule return TOK_MODULEMAIN; /* name of the module                      */
+notgriddep  return TOK_NOTGRIDDEP; /* variable which are not grid dependent   */
+use         return TOK_USE;
+{COMMENTAIRES1}    {}
+{SEPARATEUR}        return TOK_SEP;
+{USEITEM}          {strcpy(yylval.na,yytext); return TOK_USEITEM;}
+{PROBTYPE}         {strcpy(yylval.na,yytext); return TOK_PROBTYPE;}
+                                   /* dimension of the problem                */
+{NAME}             {strcpy(yylval.na,yytext); return TOK_NAME;}
+;|\,|\(|\)|:|\[|\] {return (int) *yytext;}
+\n                 {line_num++;return (int) *yytext;}
+[ \t]+ ;
+%%
+
+
+int yywrap()
+{
+}
+
+
+yyerror(char *s)
+{
+if (!strcasecmp(curfile,mainfile))
+{
+   printf("Dans convert %s line %d, fichier %s\n",s,line_num,curfile);
+}
+else
+{
+   printf("Dans convert %s line %d, fichier %s\n",s,line_num,curfile);
+}
+exit(0);
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.y
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.y	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/convert.y	(revision 4536)
@@ -0,0 +1,337 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+%{
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "decl.h"
+%}
+
+%union {
+       int ival;
+       char na[LONGNOM];
+       listnom * ln;
+       }
+
+%token TOK_SEP
+%token TOK_USE
+%token TOK_MODULEMAIN      /* name of the module                              */
+%token TOK_NOTGRIDDEP      /* Variable which are not grid dependent           */
+%token <na> TOK_USEITEM
+%token <na> TOK_NAME
+%token <na> TOK_PROBTYPE   /* dimension of the problem                        */
+%token ','
+%token ';'
+%token ':'
+%token '('
+%token ')'
+%token '['
+%token ']'
+%%
+input :
+      | input line
+;
+line :'\n'
+      | TOK_PROBTYPE TOK_NAME ';'                   {initdimprob(1,$2,"0","0");}
+      | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';'      {initdimprob(2,$2, $4,"0");}
+      | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';'
+                                                    {initdimprob(3,$2, $4, $6);}
+      | TOK_MODULEMAIN TOK_NAME ';'
+                             {listofmodules = Addtolistnom($2,listofmodules,0);
+                                                        Addmoduletothelist($2);}
+      | TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';'       {Add_NotGridDepend_Var_1($3);}
+      | TOK_USE TOK_USEITEM ';'  {
+                                    if (!strcasecmp($2,"FIXED_GRIDS"))
+                                                                 fixedgrids=1;
+                                    if (!strcasecmp($2,"ONLY_FIXED_GRIDS"))
+                                                             onlyfixedgrids=1;
+                                 }
+      ;
+%%
+
+int main(int argc,char *argv[])
+{
+   extern FILE * yyin ;
+   FILE *dependglobaloutput;
+   char *tmp;
+   int i;
+   listnom *parcours;
+   listvar *newvar;
+
+   if (argc < 2)
+   {
+       printf("usage : conv <file> [-rm] [-incdir <directory>] \n");
+       printf(" [-comdirin   <directory>] [-comdirout <directory>]\n");
+       printf(" [-convfile  <FILENAME >] -SubloopScalar -SubloopScalar1 \n");
+       exit(0);
+   }
+/******************************************************************************/
+/*  1-  Variables initialization                                              */
+/******************************************************************************/
+   List_Global_Var=(listvar *)NULL;
+   List_GlobalParameter_Var=(listvar *)NULL;
+   List_Allocate_Var=(listallocate *)NULL;
+   List_Common_Var=(listvar *)NULL;
+   List_SubroutineWhereAgrifUsed=(listnom *)NULL;
+   List_Subroutine_For_Alloc=(listnom *)NULL;
+   List_Include=(listusemodule *)NULL;
+   List_NameOfModuleUsed=(listusemodule *)NULL;
+   listofmoduletmp=(listusemodule *)NULL;
+   List_SubroutineDeclaration_Var=(listvar *)NULL;
+   List_UsedInSubroutine_Var=(listvar *)NULL;
+   List_NotGridDepend_Var=(listvar *)NULL;
+   Listofavailableindices=(listindice *)NULL;
+   List_CouplePointed_Var=(listvarpointtovar *)NULL;
+   List_ModuleUsed_Var = (listvar *)NULL;
+   List_ModuleUsedInModuleUsed_Var = (listvar *)NULL;
+   List_GlobParamModuleUsed_Var = (listparameter *)NULL;
+   List_GlobParamModuleUsedInModuleUsed_Var = (listparameter *)NULL;
+   List_SubroutineArgument_Var = (listvar *)NULL;
+   List_FunctionType_Var = (listvar *)NULL;
+   tmpuselocallist = (listusemodule *)NULL;
+   List_ContainsSubroutine = (listnom *)NULL;
+
+   strcpy(mainfile,argv[1]);
+   strcpy(nomdir,"AGRIF_INC");
+   strcpy(commondirin,".");
+   strcpy(commondirout,".");
+   strcpy(filetoparse," ");
+   strcpy(subofagrifinitgrids,"");
+   strcpy(meetagrifinitgrids,"");
+   strcpy(mpiinitvar,"");
+
+   checkexistcommon=1;
+   todebug=0;
+   onlyfixedgrids=0;
+   fixedgrids=0;
+   InAgrifParentDef = 0;
+   IndicenbmaillesX=0;
+   IndicenbmaillesY=0;
+   IndicenbmaillesZ=0;
+   created_dimensionlist = 1;
+   indicemaxtabvars = 0;   /* current indice in the table tabvars             */
+   SubloopScalar = 0;
+   todebug = 0;
+   todebugfree = 0;
+   retour77 = 1 ;
+   mark = 0 ;
+   shouldincludempif = 0 ;
+/******************************************************************************/
+/*  2-  Program arguments                                                     */
+/******************************************************************************/
+
+   if ((yyin=fopen(argv[1],"r"))==NULL)
+   {
+      printf("the file %s doesn't exist \n",argv[1]);
+      exit(0);
+   }
+
+   i=2;
+   while (i<argc)
+   {
+      if (!strcasecmp(argv[i],"-incdir"))
+      {
+         strcpy(nomdir,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-comdirin")) /* input directory           */
+      {
+         strcpy(commondirin,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-comdirout")) /* output directory         */
+      {
+         strcpy(commondirout,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-convfile")) /* file to parse             */
+      {
+         strcpy(filetoparse,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse        */
+      {
+         SubloopScalar = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse       */
+      {
+         SubloopScalar = 2 ;
+      }
+      else if (!strcasecmp(argv[i],"-todebug")) /* file to parse       */
+      {
+         todebug = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-mark")) /* file to parse       */
+      {
+         mark = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-todebugfree")) /* file to parse       */
+      {
+         todebugfree = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-rm"))
+      {
+         checkexistcommon=0;
+      }
+      else
+      {
+         printf("Unkwon option : %s\n",argv[i]);
+         exit(0);
+      }
+      i++;
+   }
+
+/******************************************************************************/
+/*  3-  Parsing of the  conv file <name>.in                                   */
+/******************************************************************************/
+
+   if ((yyin=fopen(argv[1],"r"))==NULL)
+   {
+       printf("the file %s doesn't exist \n",argv[1]);
+       exit(0);
+   }
+   strcpy(mainfile,argv[1]);
+
+   if ( strstr(filetoparse,".f90") ||
+        strstr(filetoparse,".F90") ) retour77 = 0;
+
+   yyparse();
+
+/******************************************************************************/
+/*  4-  Preparation of the file parsing                                       */
+/******************************************************************************/
+   if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ?   */
+   {
+      printf("the file %s doesn't exist \n",filetoparse);
+      exit(0);
+   }
+   /* mainfile : the name of the file to parse                                */
+   strcpy(mainfile,filetoparse);
+   /*                                                                         */
+   if ((dependglobaloutput=fopen(".dependglobal_agrif","r"))!=NULL)
+   {
+      fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars);
+      fclose(dependglobaloutput);
+   }
+   Readthedependavailablefile();
+   /* Read the .dependnbxnby file which contains indices of nbmaillsX,        */
+   /*    nbmailleY and nbmailleZ                                              */
+   Readthedependnbxnbyfile();
+   Read_Subroutine_For_Alloc();
+/******************************************************************************/
+/*  5-  Parsing of the input file (2 times)                                   */
+/******************************************************************************/
+   /* Record all variable in list                                             */
+   firstpass = 1;
+   processfortran(filetoparse);
+   /*                                                                         */
+   CompleteThelistvarindoloop();
+   /* Read list of module used                                                */
+   RecordUseModulesVariables();
+   /* Read list of module used in module used                                 */
+   RecordUseModulesUseModulesVariables();
+   /* Save variables are considered as globals ones                           */
+   Update_List_Global_Var_From_List_Save_Var();
+   /* Update all lists                                                        */
+   ListUpdate();
+   /* Indice tabvars identification                                           */
+   IndiceTabvarsIdentification();
+   /* Update all lists                                                        */
+   ListUpdate();
+   /* The allocation subroutine is necessary ????                             */
+   New_Allocate_Subroutine_Is_Necessary();
+   /* The allocation subroutine is necessary for common list                  */
+   New_Allocate_Subroutine_For_Common_Is_Necessary();
+   /* Sort List_SubroutineArgument_Var                                        */
+   Sort_List_SubroutineArgument_Var();
+   /* Clean all lists                                                         */
+   ListClean();
+   /* Update Indice of List_UsedInSubroutine_Var from module used             */
+   List_UsedInSubroutine_Var_Update_From_Module_Used();
+   /* Update List_SubroutineWhereAgrifUsed                                    */
+   UpdateList_SubroutineWhereAgrifUsed();
+   /* Update List_UsedInSubroutine_Var with v_readedlistdimension             */
+   UpdateList_UsedInSubroutine_With_dimension();;
+   /*                                                                         */
+   ModifyThelistvarindoloop();
+   /*                                                                         */
+   UpdateListDeclarationWithDimensionList();
+   /*                                                                         */
+   GiveTypeOfVariables();
+   Affiche();
+   /* Build new subroutines                                                   */
+   firstpass = 0;
+   processfortran(filetoparse);
+
+/******************************************************************************/
+/*  6-  Write informations in output files                                    */
+/******************************************************************************/
+
+   /* Write the .dependglobal_agrif file which contain the max indice         */
+   /*    of the tabvars table                                                 */
+   dependglobaloutput = fopen(".dependglobal_agrif","w");
+   fprintf(dependglobaloutput,"%d\n",indicemaxtabvars);
+   fclose(dependglobaloutput);
+   /* Write the list of available indice                                      */
+   Writethedependavailablefile();
+   /* Write the .dependnbxnby file which contains indices of nbmaillsX,       */
+   /*    nbmailleY and nbmailleZ                                              */
+   Writethedependnbxnbyfile();
+   /* Write the .depend<namefile> file which contain general informations     */
+   /*    about variable of this file                                          */
+   parcours = List_NameOfModule;
+   while( parcours )
+   {
+      Writethedependlistofmoduleused(parcours->o_nom);
+      WritedependParameterList(parcours->o_nom);
+      Writethedependfile(parcours->o_nom,List_Global_Var);
+      parcours=parcours->suiv;
+   }
+   parcours = List_NameOfCommon;
+   while( parcours )
+   {
+      Writethedependfile(parcours->o_nom,List_Common_Var);
+      parcours=parcours->suiv;
+   }
+   Write_Subroutine_For_Alloc();
+/******************************************************************************/
+/*  7-  Create files in AGRIF_INC directory                                   */
+/******************************************************************************/
+   creefichieramr(NameTamponfile);
+
+
+   if ( todebug == 1 ) printf("Out of CONV \n");
+   return 0;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/decl.h
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/decl.h	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/decl.h	(revision 4536)
@@ -0,0 +1,610 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#define LONGNOM 800
+#define LONGLIGNE 800
+
+/******************************************************************************/
+/*********** Declaration of structures used in conv ***************************/
+/******************************************************************************/
+
+typedef struct
+{
+   char first[LONGNOM];
+   char last[LONGNOM];
+} typedim ;                /* fortran dimension as 'ndeb:nfin'                */
+
+typedef struct listdim
+{
+   typedim dim;
+   struct listdim *suiv;
+} listdim;                 /* list of the dimensions of a variable            */
+
+typedef struct variable
+{
+   char v_typevar[LONGNOM];
+   char v_nomvar[LONGNOM] ;
+   char v_oldname[LONGNOM] ;
+   char v_dimchar[LONGNOM];
+   char v_modulename[LONGNOM];
+   char v_commonname[LONGNOM];
+   char v_vallengspec[LONGNOM];
+   char v_nameinttypename[LONGNOM];
+   char v_commoninfile[LONGNOM];
+   char v_subroutinename[LONGNOM];
+   char v_precision[LONGNOM];
+   char v_initialvalue[LONGNOM];
+   char v_IntentSpec[LONGNOM];
+   char v_readedlistdimension[LONGNOM];
+   int  v_nbdim;
+   int  v_common;
+   int  v_positioninblock;
+   int  v_module;
+   int  v_save;
+   int  v_VariableIsParameter;
+   int  v_PublicDeclare;
+   int  v_PrivateDeclare;
+   int  v_ExternalDeclare;
+   int  v_pointedvar;
+   int  v_notgrid;
+   int  v_dimensiongiven;
+   int  v_c_star;
+   int  v_indicetabvars;
+   int  v_pointerdeclare;
+   int  v_optionaldeclare;
+   int  v_allocatable;
+   int  v_dimsempty;
+   listdim *v_dimension;
+} variable ;               /* type of a variable                              */
+                           /* v_typevar : type (integer, real, ...)           */
+                           /* v_nomvar : name of the variable                 */
+                           /* v_dimension : list of dimensions of the variable*/
+                           /* v_nbdim: 1 if the variable is 1d, etc ...       */
+                           /* precision : Name of the variable which          */
+                           /* determine the precision. example : wp in the    */
+                           /* case where REAL(wp)                             */
+
+typedef struct listvar
+{
+   variable *var ;
+   struct listvar * suiv;
+} listvar ;                /* list of variables                               */
+
+
+typedef struct listusemodule
+{
+   char u_usemodule[LONGNOM];
+   char u_charusemodule[LONGNOM];
+   char u_cursubroutine[LONGNOM];
+   char u_modulename[LONGNOM];
+   int  u_firstuse;
+   struct listusemodule * suiv;
+} listusemodule;           /* list of names                                   */
+
+typedef struct listparameter
+{
+   char p_name[LONGNOM];
+   char p_modulename[LONGNOM];
+   struct listparameter * suiv;
+} listparameter ;           /* list of names                                  */
+
+typedef struct listname
+{
+   char n_name[LONGNOM];
+   struct  listname* suiv;
+} listname ;            /* list of names                                  */
+
+typedef struct listcouple
+{
+   char c_namevar[LONGNOM];
+   char c_namepointedvar[LONGNOM];
+   struct listcouple * suiv;
+} listcouple;              /* list of names                                   */
+
+
+typedef struct listnom
+{
+   char o_nom[LONGNOM];
+   char o_module[LONGNOM];
+   int  o_val;
+   listcouple *couple;
+   struct listnom * suiv;
+} listnom;                 /* list of names                                   */
+
+
+typedef struct listallocate
+{
+   char a_nomvar[LONGNOM];
+   char a_subroutine[LONGNOM];
+   char a_module[LONGNOM];
+   struct listallocate * suiv;
+} listallocate ;
+
+
+typedef struct listvarpointtovar
+{
+   char t_usemodule[LONGNOM];
+   char t_cursubroutine[LONGNOM];
+   listcouple *t_couple;
+   struct  listvarpointtovar* suiv;
+}listvarpointtovar ;       /* list of names                                   */
+
+
+typedef struct listindice
+{
+   int i_indice;
+   struct  listindice * suiv;
+} listindice;              /* list of indiced                                 */
+
+ variable *curvar;
+
+ listvar *List_ModuleUsedInModuleUsed_Var;
+ listvar *List_ModuleUsed_Var;
+ listvar *listduplicated;
+
+ listvar *List_GlobalParameter_Var;
+ listvar *List_Global_Var;
+ listvar *List_Data_Var;
+ listvar *List_Save_Var;
+ listvar *List_SubroutineArgument_Var;
+ listvar *List_SubroutineDeclaration_Var;
+ listvar *List_UsedInSubroutine_Var;
+ listvar *List_Parameter_Var;
+ listvar *List_Dimension_Var;
+ listvar *List_FunctionType_Var;
+ listvar *List_NotGridDepend_Var;
+ listvar *List_Common_Var;
+
+
+ listname *List_Pointer_Var;
+ listname *List_ImplicitNoneSubroutine;
+
+ listusemodule *List_NameOfModuleUsed;
+ listusemodule *List_Include;
+ listusemodule *listofmoduletmp;
+ listusemodule *tmpuselocallist;
+
+ listparameter *List_GlobParamModuleUsedInModuleUsed_Var;
+ listparameter *List_GlobParamModuleUsed_Var;
+
+ listnom *List_ContainsSubroutine;
+ listnom *List_Subroutine_For_Alloc;
+ listnom *listofmodules;
+ listnom *List_NameOfModule;
+ listnom *List_NameOfCommon;
+ listnom *List_SubroutineWhereAgrifUsed;
+
+ listallocate *List_Allocate_Var;
+
+ listvarpointtovar *List_CouplePointed_Var;
+                           /*  variables which are pointed to an other one    */
+
+ listindice *Listofavailableindices;
+                           /* List of available indices in the tabvars table  */
+
+ listdim *curdim;
+ listdim *commondim;
+
+/******************************************************************************/
+/****************   *** COMMON Variables ***  *********************************/
+/******************************************************************************/
+
+ int positioninblock;
+ char commonvar[LONGNOM];
+ char commonblockname[LONGNOM];
+
+/******************************************************************************/
+/****************   *** AGRIF Variables ***   *********************************/
+/******************************************************************************/
+ int inagrifcallargument;
+ int sameagrifargument;
+ int InAgrifParentDef;
+ char sameagrifname[LONGNOM];
+/******************************************************************************/
+/****************   *** VAR DEF Variables ***   *******************************/
+/******************************************************************************/
+ int indicemaxtabvars;     /* Number of variables in the model i.e. last      */
+                           /*    indice used in  the tabvars table            */
+ int PublicDeclare;        /* Variable has been declared as PUBLIC */
+ int PrivateDeclare;       /* Variable has been declared as PRIVATE */
+ int ExternalDeclare;      /* Variable has been declared as EXTERNAL */
+ int InitialValueGiven;    /* An initial value has been given */
+ int Allocatabledeclare;
+ int SaveDeclare;
+ int functiondeclarationisdone;
+ int pointerdeclare;
+ int optionaldeclare;
+ int VarType;
+ int VarTypepar;
+ int VariableIsParameter;
+ int dimsgiven;
+ int shouldincludempif;
+ int c_star;
+ char DeclType[LONGNOM];
+ char nameinttypename[LONGNOM];
+ int GlobalDeclaration;
+ char InitValue[LONGNOM*2];
+ char IntentSpec[LONGNOM];
+ char NamePrecision[LONGNOM];
+ char CharacterSize[LONGNOM];
+ char curmodulename[LONGNOM];
+ char vallengspec[LONGNOM];
+ char subroutinename[LONGNOM];
+
+/******************************************************************************/
+/****************   *** CONV Variables ***   **********************************/
+/******************************************************************************/
+ int dimprob ;             /* dimension of the problem : 1 for 1D,2 for 2D,   */
+                           /*    3 for 3D                                     */
+ int onlyfixedgrids;       /* = 1 if onlyfixedgrids is true                   */
+ int todebug;
+ int mark;
+ int todebugfree;
+ int fixedgrids;           /* = 1 if fixedgrids is true                       */
+ char nbmaillesX[LONGNOM]; /* number of cells in the x direction              */
+ char nbmaillesY[LONGNOM]; /* number of cells in the y direction              */
+ char nbmaillesZ[LONGNOM]; /* number of cells in the z direction              */
+ int IndicenbmaillesX;
+ int IndicenbmaillesY;
+ int IndicenbmaillesZ;
+
+ int inmodulemeet;
+ int incalldeclare;
+ int aftercontainsdeclare; /* Signale si l'on vient d'un contains ou non */
+ int retour77;
+ int colnum;
+ int callagrifinitgrids;
+ int callmpiinit;
+ int firstpass;
+ int couldaddvariable;
+ int pointedvar;
+ int agrif_parentcall;
+ int didvariableadded;
+ int SubloopScalar;        /* = 1 we should put in argument of sub_loop       */
+                           /*    only                                         */
+                           /*    scalar and not table u(1,1,1) in place of u  */
+ int checkexistcommon;
+ int insubroutinedeclare;
+ int inmoduledeclare;
+ int dimsempty;
+ int created_dimensionlist;
+
+ char meetagrifinitgrids[LONGNOM];
+ char mpiinitvar[LONGNOM];
+ char *NameTamponfile;
+ char toprintglob[LONGNOM];
+ char tmpvargridname[LONGLIGNE];
+ char EmptyChar[LONGNOM];        /* An empty char */
+ char curfilename[LONGNOM];
+ char nomfileoutput[LONGNOM];
+ char curbuf[100*LONGNOM];
+ char motparse[LONGNOM];
+ char motparse1[LONGNOM];
+ char charusemodule[LONGNOM];
+ char subofagrifinitgrids[LONGNOM];
+ char curfile[LONGNOM];
+ char mainfile[LONGNOM];
+ char nomdir[LONGNOM];
+ char commondirout[LONGNOM];
+ char commondirin[LONGNOM];
+ char filetoparse[LONGNOM];
+
+ FILE *fortranout;          /* Output File                                    */
+ FILE *fortranin;           /* Input File                                     */
+ FILE *oldfortranout;
+ FILE *subloop;
+ FILE *module_declar;
+ FILE *allocationagrif;
+ FILE *paramout;
+
+ long int pos_cur;         /* current position in the output file             */
+ long int pos_curagrifparent;
+                           /* current position in the output file             */
+ long int pos_curcall;     /* current position in the output file             */
+ long int pos_curuse;      /* current position in the output file             */
+ long int pos_curfunction; /* current position in the output file             */
+ long int pos_cur_decl;    /* current position in the output file             */
+ long int pos_curdata;     /* current position in the output file             */
+ long int pos_curparameter;/* current position in the output file             */
+ long int pos_curcommon;   /* current position in the output file             */
+ long int pos_cursave;     /* current position in the output file             */
+ long int pos_curdimension;/* current position in the output file             */
+ long int pos_curinit;     /* current position in the output file             */
+ long int pos_curinclude;  /* final position of a line in file                */
+ long int pos_end;         /* final position of a line in file                */
+ long int pos_endsubroutine;
+                           /* final position of a line in file                */
+
+/******************************************************************************/
+/*********** Declaration of externals subroutines *****************************/
+/***************************************************** ************************/
+/******************************************************************************/
+/*********** convert.y ********************************************************/
+/******************************************************************************/
+extern int main(int argc,char *argv[]);
+/******************************************************************************/
+/*********** fortran.y ********************************************************/
+/******************************************************************************/
+extern void processfortran(char *fichier_entree);
+/******************************************************************************/
+/*********** dependfile.c *****************************************************/
+/******************************************************************************/
+extern void Writethedependnbxnbyfile();
+extern void Readthedependnbxnbyfile();
+extern void Writethedependlistofmoduleused(char *NameTampon );
+extern void Readthedependlistofmoduleused(char *NameTampon);
+extern void WritedependParameterList(char *NameTampon );
+extern listparameter *ReaddependParameterList(char *NameTampon,
+                                                        listparameter *listout);
+extern void Writethedependfile(char *NameTampon, listvar *input );
+extern listvar *Readthedependfile( char *NameTampon , listvar *listout);
+extern void Write_Subroutine_For_Alloc();
+extern void Read_Subroutine_For_Alloc();
+extern void Writethedependavailablefile();
+extern void Readthedependavailablefile();
+extern int Did_filetoparse_readed(char *NameTampon);
+extern int Did_module_common_treaded(char *NameTampon);
+/******************************************************************************/
+/*********** DiversListe.c ****************************************************/
+/******************************************************************************/
+extern void Add_Common_var_1();
+extern listnom *Addtolistnom(char *nom, listnom *listin,int value);
+extern listname *Addtolistname(char *nom,listname *input);
+extern int ModuleIsDefineInInputFile(char *name);
+extern void Addmoduletothelisttmp(char *name);
+extern void Add_NameOfModule_1(char *nom);
+extern void Add_NameOfCommon_1(char *nom);
+extern void Add_CouplePointed_Var_1(char *namemodule,listcouple *couple);
+extern void Add_Include_1(char *name);
+extern void Add_ImplicitNoneSubroutine_1();
+extern void WriteIncludeDeclaration();
+extern void Add_Save_Var_1 (char *name,listdim *d);
+/******************************************************************************/
+/*********** SubLoopCreation.c ************************************************/
+/******************************************************************************/
+extern void writeheadnewsub_0(int suborfunc);
+extern void WriteVariablelist_subloop(FILE *outputfile);
+extern void WriteVariablelist_subloop_Call(FILE *outputfile);
+extern void WriteVariablelist_subloop_Def(FILE *outputfile);
+extern void WriteHeadofSubroutineLoop();
+extern void closeandcallsubloopandincludeit_0(int suborfun,
+                                                          char endsub[LONGNOM]);
+/******************************************************************************/
+/*********** toamr.c **********************************************************/
+/******************************************************************************/
+extern char *variablenameroottabvars (variable * var);
+extern char *variablenametabvars (variable * var, int iorindice);
+extern char *variablecurgridtabvars (variable * var,int ParentOrCurgrid);
+extern char *vargridnametabvars (variable * var,int iorindice);
+extern char *vargridcurgridtabvars (variable * var,int ParentOrCurgrid);
+extern char *vargridcurgridtabvarswithoutAgrif_Gr (variable * var);
+extern char *vargridparam (variable * v, int whichone);
+extern void write_probdimagrif_file();
+extern void write_keysagrif_file();
+extern void write_modtypeagrif_file();
+extern void write_createvarnameagrif_file(variable *v,FILE *createvarname,
+                                                                int *InitEmpty);
+extern void write_Setnumberofcells_file();
+extern void write_Getnumberofcells_file();
+extern void write_initialisationsagrif_file(variable *v,FILE *initproc,
+                                                             int *VarnameEmpty);
+extern void Write_Alloc_Agrif_Files();
+extern int IndiceInlist(int indic, listindice *listin);
+extern void write_allocation_Common_0();
+extern void write_allocation_Global_0();
+extern void creefichieramr (char *NameTampon);
+/******************************************************************************/
+/*********** UtilAgrif.c ******************************************************/
+/******************************************************************************/
+extern int Vartonumber(char *tokname);
+extern int Agrif_in_Tok_NAME(char *tokname);
+extern void ModifyTheVariableName_0(char *ident);
+extern void Add_SubroutineWhereAgrifUsed_1(char *sub,char *mod);
+extern void  AddUseAgrifUtil_0(FILE *fileout);
+extern void  AddUseAgrifUtilBeforeCall_0(FILE *fileout);
+extern void NotifyAgrifFunction_0(char *ident);
+extern void ModifyTheAgrifFunction_0(char *ident);
+extern void AgriffunctionModify_0(char *ident,int whichone);
+extern void Instanciation_0(char *ident);
+/******************************************************************************/
+/*********** UtilCharacter.c **************************************************/
+/******************************************************************************/
+extern void FindAndChangeNameToTabvars(char name[LONGNOM],char toprint[LONGNOM],
+                                             listvar * listtosee, int whichone);
+extern char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread,
+                                                                  int whichone);
+extern int IsVariableReal(char *nom);
+extern void IsVarInUseFile(char *nom);
+extern listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout);
+extern void DecomposeTheName(char *nom);
+extern void convert2lower(char *name);
+/******************************************************************************/
+/*********** UtilFile.c *******************************************************/
+/******************************************************************************/
+extern FILE * associate (char *filename);
+extern FILE * associateaplus (char *filename);
+extern long int setposcur();
+extern long int setposcurinoldfortranout();
+extern void copyuse_0(char *namemodule);
+extern void copyuseonly_0(char *namemodule);
+/******************************************************************************/
+/*********** UtilFortran.c ****************************************************/
+/******************************************************************************/
+extern void initdimprob(int dimprobmod, char * nx, char * ny,char* nz);
+extern int Variableshouldberemove(char *nom);
+extern int variableisglobal(listvar *curvar, listvar *listin);
+extern int VariableIsInList(listvar *curvar,listvar *listin);
+extern void variableisglobalinmodule(listcouple *listin, char *module,
+                                                                 FILE *fileout);
+extern void Remove_Word_Contains_0();
+extern void Remove_Word_end_module_0();
+extern void Write_Word_Contains_0();
+extern void Write_Word_end_module_0();
+extern void Add_Subroutine_For_Alloc(char *nom);
+extern void Write_Alloc_Subroutine_0();
+extern void Write_Alloc_Subroutine_For_End_0();
+extern void Write_GlobalParameter_Declaration_0();
+extern void Write_NotGridDepend_Declaration_0();
+extern int IsTabvarsUseInArgument_0();
+extern int ImplicitNoneInSubroutine();
+extern void Add_Pointer_Var_From_List_1(listvar *listin);
+extern void Add_Pointer_Var_1(char *nom);
+extern int varispointer_0(char *ident);
+extern int VariableIsNotFunction(char *ident);
+/******************************************************************************/
+/*********** UtilListe.c ******************************************************/
+/******************************************************************************/
+extern void Init_Variable(variable *var);
+extern listvar * AddListvarToListvar(listvar *l,listvar *glob,
+                                                            int ValueFirstpass);
+extern void CreateAndFillin_Curvar(char *type,variable *curvar);
+extern void duplicatelistvar(listvar *orig);
+extern listdim * insertdim(listdim *lin,typedim nom);
+extern void change_dim_char(listdim *lin,listvar * l);
+extern int num_dims(listdim *d);
+extern variable * createvar(char *nom,listdim *d);
+extern listvar * insertvar(listvar *lin,variable *v);
+extern listvar *settype(char *nom,listvar *lin);
+/******************************************************************************/
+/*********** UtilNotGridDep.c *************************************************/
+/******************************************************************************/
+extern void Add_NotGridDepend_Var_1 (char *name);
+extern int VarIsNonGridDepend(char *name);
+/******************************************************************************/
+/*********** WorkWithAllocatelist.c *******************************************/
+/******************************************************************************/
+extern void Add_Allocate_Var_1(char *nom,char *nommodule);
+extern int IsVarAllocatable_0(char *ident);
+extern int varisallocatable_0(char *ident);
+/******************************************************************************/
+/*********** WorkWithglobliste.c **********************************************/
+/******************************************************************************/
+extern void Add_Globliste_1(listvar *listtoadd);
+extern void Add_SubroutineDeclarationSave_Var_1(listvar *listtoadd);
+/******************************************************************************/
+/*********** WorkWithlistdatavariable.c ***************************************/
+/******************************************************************************/
+extern void Add_Data_Var_1 (char *name,char *values);
+/******************************************************************************/
+/*********** WorkWithlistmoduleinfile.c ***************************************/
+/******************************************************************************/
+
+/******************************************************************************/
+/*********** WorkWithlistofmodulebysubroutine.c *******************************/
+/******************************************************************************/
+extern void RecordUseModulesVariables();
+extern void  RecordUseModulesUseModulesVariables();
+extern void Add_NameOfModuleUsed_1(char *name);
+extern void Addmoduletothelist(char *name);
+extern void WriteUsemoduleDeclaration();
+/******************************************************************************/
+/*********** WorkWithlistvarindoloop.c ****************************************/
+/******************************************************************************/
+extern void Add_UsedInSubroutine_Var_1 (char *ident);
+extern void ajoutevarindoloop_definedimension (char *name);
+extern void  ModifyThelistvarindoloop();
+extern void  CompleteThelistvarindoloop();
+extern void CopyRecord(variable *var1,variable *var2);
+extern void Update_List_Subroutine_Var(listvar *list_to_modify);
+extern void Update_List_Global_Var_From_List_Save_Var();
+extern void Update_List_From_Common_Var(listvar *list_to_modify);
+extern void Update_List_Var(listvar *list_to_modify);
+extern void List_UsedInSubroutine_Var_Update_From_Module_Used();
+extern void Update_NotGridDepend_Var(listvar *list_to_modify);
+extern int LookingForVariableInList(listvar *listin,variable *var);
+extern int LookingForVariableInListGlobal(listvar *listin,variable *var);
+extern int LookingForVariableInListGlob(listvar *listin,variable *var);
+extern int LookingForVariableInListParamGlob(listparameter *listin,
+                                                                 variable *var);
+extern void UpdateListDeclarationWithDimensionList();
+extern void Clean_List_UsedInSubroutine_Var();
+extern void Clean_List_SubroutineDeclaration_Var();
+extern void ListClean();
+extern void ListUpdate();
+extern void Sort_List_SubroutineArgument_Var();
+extern void IndiceTabvars_Global_Var_Treated(char *nom);
+extern void IndiceTabvars_Global_Var_No_Treated(char *nom);
+extern void UpdateTheRemainingList(listvar *record);
+extern void IndiceTabvars_Common_Var_Treated(char *nom);
+extern void IndiceTabvars_Common_Var_No_Treated(char *nom);
+extern void IndiceTabvarsIdentification();
+extern void New_Allocate_Subroutine_Is_Necessary();
+extern void New_Allocate_Subroutine_For_Common_Is_Necessary();
+extern void NewModule_Creation_0();
+extern void UpdateList_SubroutineWhereAgrifUsed();
+extern void UpdateList_UsedInSubroutine_With_dimension();
+extern void Affiche();
+extern int SubInList_ContainsSubroutine();
+/******************************************************************************/
+/*********** WorkWithParameterlist.c ******************************************/
+/******************************************************************************/
+extern void Add_GlobalParameter_Var_1(listvar *listin);
+extern void Add_Parameter_Var_1(listvar *listin);
+extern void Add_Dimension_Var_1(listvar *listin);
+/******************************************************************************/
+/*********** WorkWithvarofsubroutineliste.c ***********************************/
+/******************************************************************************/
+extern void Add_SubroutineArgument_Var_1(listvar *listtoadd);
+extern void Add_FunctionType_Var_1(char *nom);
+extern void Add_SubroutineDeclaration_Var_1 (listvar *listtoadd);
+/******************************************************************************/
+/*********** Writedeclarations.c **********************************************/
+/******************************************************************************/
+extern void WriteBeginDeclaration(variable *v,char ligne[LONGLIGNE]);
+extern void WriteScalarDeclaration(variable *v,char ligne[LONGLIGNE]);
+extern void WriteTableDeclaration(variable * v,char ligne[LONGLIGNE],int tmpok);
+extern void writevardeclaration (listvar * var_record, FILE *fileout,
+                                                                     int value);
+extern void WriteLocalParamDeclaration();
+extern void WriteFunctionDeclaration();
+extern void WriteSubroutineDeclaration(int value);
+extern void WriteArgumentDeclaration_beforecall();
+extern void WriteArgumentDeclaration_Sort();
+extern listnom *writedeclarationintoamr (listvar * deb_common, FILE *fileout,
+                                       variable *var , char commonname[LONGNOM],
+                           listnom *neededparameter, char name_common[LONGNOM]);
+extern void writesub_loopdeclaration_scalar (listvar * deb_common,
+                                                                 FILE *fileout);
+extern void writesub_loopdeclaration_tab (listvar * deb_common, FILE *fileout);
+/******************************************************************************/
+/*********** WriteInFile.c ****************************************************/
+/******************************************************************************/
+extern void tofich_reste (FILE * filout, char *s,int returnlineornot);
+extern void tofich (FILE * filout, char *s, int returnlineornot);
+extern void tofich_blanc (FILE * filout, int size);
+extern void tofich_line (FILE * filout, int size, int long position);
+extern void RemoveWordSET_0(FILE * filout, long int position,
+                                                         long int sizetoremove);
+extern void RemoveWordCUR_0(FILE * filout, long int position,
+                                                         long int sizetoremove);
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/dependfile.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/dependfile.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/dependfile.c	(revision 4536)
@@ -0,0 +1,837 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decl.h"
+
+
+/******************************************************************************/
+/*            Creation and modification of .dependfile                        */
+/******************************************************************************/
+/*  .dependnbxnby            : this file contains tabvars indices of variables*/
+/*                                given in agrif.in as number of cells        */
+/*  .dependuse<module>       : this file contains all modules used in the     */
+/*                                current file                                */
+/*  .dependparameter<module> : this file contains all parmeters defined in    */
+/*                                the current file                            */
+/*  .depend<module name>     : this file contains all globals variables       */
+/*                                informations (name, dim, etc ...)           */
+/*  .dependavailable         : this file contains all tabvars indices which   */
+/*                                are not used.                               */
+/******************************************************************************/
+
+
+/******************************************************************************/
+/*                 Writethedependnbxnbyfile                                   */
+/******************************************************************************/
+/* This subroutine is used to create the .dependnbxnby                        */
+/******************************************************************************/
+/*                                                                            */
+/*                     .dependnbxnby                                          */
+/*                                                                            */
+/*                     nbmaillesX                                             */
+/*                     nbmaillesY                                             */
+/*                     nbmaillesZ                                             */
+/*                                                                            */
+/******************************************************************************/
+void Writethedependnbxnbyfile()
+{
+  FILE *dependfileoutput;
+  listvar *parcours;
+  int out;
+
+  /* We are looking for all the variable of the current filetoparse file      */
+  /*    in the List_Global_Var                                                */
+  parcours =List_Global_Var;
+  out = 0;
+  while (parcours && out == 0 )
+  {
+     if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesX) ) out = 1;
+     else parcours = parcours->suiv;
+  }
+  if ( out == 0 )
+  {
+     parcours =List_Common_Var;
+     while (parcours && out == 0 )
+     {
+        if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesX) ) out = 1;
+        else parcours = parcours->suiv;
+     }
+  }
+  if ( out == 1 )
+  {
+     dependfileoutput = fopen(".dependnbxnby","w");
+     fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
+     IndicenbmaillesX = parcours->var->v_indicetabvars;
+
+     if ( dimprob > 1 )
+     {
+        parcours =List_Global_Var;
+        out = 0;
+        while (parcours && out == 0 )
+        {
+           if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesY) ) out = 1;
+           else parcours = parcours->suiv;
+        }
+        if ( out == 0 )
+        {
+           parcours =List_Common_Var;
+           while (parcours && out == 0 )
+           {
+              if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesY) ) out = 1;
+              else parcours = parcours->suiv;
+           }
+        }
+        if ( out == 1 )
+        {
+           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
+           IndicenbmaillesY = parcours->var->v_indicetabvars;
+        }
+     }
+
+     if ( dimprob > 2 )
+     {
+        parcours =List_Global_Var;
+        out = 0;
+        while (parcours && out == 0 )
+        {
+           if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesZ) ) out = 1;
+           else parcours = parcours->suiv;
+        }
+        if ( out == 0 )
+        {
+           parcours =List_Common_Var;
+           while (parcours && out == 0 )
+           {
+              if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesZ) ) out = 1;
+              else parcours = parcours->suiv;
+           }
+        }
+        if ( out == 1 )
+        {
+           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
+           IndicenbmaillesZ = parcours->var->v_indicetabvars;
+        }
+     }
+
+     if ( out == 1 ) fclose(dependfileoutput);
+   }
+}
+
+/******************************************************************************/
+/*                 Readthedependnbxnbyfile                                    */
+/******************************************************************************/
+/* This subroutine is used to create the .dependnbxnby                        */
+/******************************************************************************/
+/*                                                                            */
+/*                     .dependnbxnby                                          */
+/*                                                                            */
+/*                     nbmaillesX                                             */
+/*                     nbmaillesY                                             */
+/*                     nbmaillesZ                                             */
+/*                                                                            */
+/******************************************************************************/
+void Readthedependnbxnbyfile()
+{
+  FILE *dependfileoutput;
+
+  if ((dependfileoutput = fopen(".dependnbxnby","r"))!=NULL)
+  {
+     fscanf(dependfileoutput,"%d\n",&IndicenbmaillesX);
+     if ( dimprob > 1 ) fscanf(dependfileoutput,"%d\n",&IndicenbmaillesY);
+     if ( dimprob > 2 ) fscanf(dependfileoutput,"%d\n",&IndicenbmaillesZ);
+     fclose(dependfileoutput);
+  }
+}
+
+/******************************************************************************/
+/*                     Writethedependlistofmoduleused                         */
+/******************************************************************************/
+/* This subroutine is used to create the .dependuse<module>                   */
+/******************************************************************************/
+/*                                                                            */
+/*               .dependuse<name>                                             */
+/*                                                                            */
+/*               mod1                                                         */
+/*               mod2                                                         */
+/*                                                                            */
+/******************************************************************************/
+void Writethedependlistofmoduleused(char *NameTampon )
+{
+  FILE *dependfileoutput;
+  listusemodule *parcours;
+  char ligne[LONGNOM];
+
+
+  if ( List_NameOfModuleUsed )
+  {
+     convert2lower(NameTampon);
+     sprintf(ligne,".dependuse%s",NameTampon);
+     dependfileoutput = fopen(ligne,"w");
+     /*                                                                       */
+     parcours = List_NameOfModuleUsed;
+     while (parcours)
+     {
+        if ( !strcasecmp(NameTampon,parcours->u_modulename) &&
+             !strcasecmp(parcours->u_cursubroutine,"")
+           )
+        {
+           /* We are looking for all the variable of the current              */
+           /*    filetoparse file in the List_Global_Var                      */
+           fprintf(dependfileoutput,"%s\n",parcours->u_usemodule);
+        }
+        parcours = parcours->suiv;
+     }
+     fclose(dependfileoutput);
+  }
+}
+
+/******************************************************************************/
+/*                    Readthedependlistofmoduleused                           */
+/******************************************************************************/
+/* This subroutine is used to create the .dependuse<module>                   */
+/******************************************************************************/
+/*                                                                            */
+/*               .dependuse<name>                                             */
+/*                                                                            */
+/*               mod1                                                         */
+/*               mod2                                                         */
+/*                                                                            */
+/******************************************************************************/
+void Readthedependlistofmoduleused(char *NameTampon)
+{
+  FILE *dependfileoutput;
+  listusemodule *parcours;
+  char ligne[LONGNOM];
+
+  convert2lower(NameTampon);
+  sprintf(ligne,".dependuse%s",NameTampon);
+
+  tmpuselocallist = (listusemodule *)NULL;
+  if ((dependfileoutput = fopen(ligne,"r"))==NULL)
+  {
+  }
+  else
+  {
+    /* if the file exist we should verify that this file has changed          */
+      while (!feof(dependfileoutput))
+      {
+         parcours=(listusemodule *)malloc(sizeof(listusemodule));
+         fscanf(dependfileoutput,"%s\n",parcours->u_usemodule);
+
+         parcours->suiv = tmpuselocallist;
+         tmpuselocallist = parcours;
+
+         parcours = NULL;
+      }
+      fclose(dependfileoutput);
+  }
+}
+
+
+/******************************************************************************/
+/*                        WritedependParameterList                            */
+/******************************************************************************/
+/* This subroutine is used to create the .dependparameter<name>               */
+/******************************************************************************/
+/*                                                                            */
+/*               .dependparameter<name>                                       */
+/*                                                                            */
+/*               mod1                                                         */
+/*               mod2                                                         */
+/*                                                                            */
+/******************************************************************************/
+void WritedependParameterList(char *NameTampon )
+{
+  FILE *dependfileoutput;
+  listvar *parcours;
+  char ligne[LONGNOM];
+
+  if ( List_GlobalParameter_Var )
+  {
+     convert2lower(NameTampon);
+     sprintf(ligne,".dependparameter%s",NameTampon);
+     dependfileoutput = fopen(ligne,"w");
+     /*                                                                       */
+     parcours = List_GlobalParameter_Var;
+     while (parcours)
+     {
+        if ( !strcasecmp(NameTampon,parcours->var->v_modulename) )
+        {
+           fprintf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
+           fprintf(dependfileoutput,"%s\n",parcours->var->v_modulename);
+        }
+        parcours = parcours->suiv;
+     }
+     fclose(dependfileoutput);
+  }
+}
+
+
+/******************************************************************************/
+/*                         ReaddependParameterList                            */
+/******************************************************************************/
+/* This subroutine is used to create the .dependparameter<name>               */
+/******************************************************************************/
+/*                                                                            */
+/*               .dependparameter<name>                                       */
+/*                                                                            */
+/*               mod1                                                         */
+/*               mod2                                                         */
+/*                                                                            */
+/******************************************************************************/
+listparameter *ReaddependParameterList(char *NameTampon,listparameter *listout)
+{
+  FILE *dependfileoutput;
+  listparameter *parcours;
+  char ligne[LONGNOM];
+
+  convert2lower(NameTampon);
+  sprintf(ligne,".dependparameter%s",NameTampon);
+
+  if ((dependfileoutput = fopen(ligne,"r"))==NULL)
+  {
+  }
+  else
+  {
+    /* if the file exist we should verify that this file has changed          */
+      while (!feof(dependfileoutput))
+      {
+         parcours=(listparameter *)malloc(sizeof(listparameter));
+         fscanf(dependfileoutput,"%s\n",parcours->p_name);
+         fscanf(dependfileoutput,"%s\n",parcours->p_modulename);
+
+         parcours->suiv = listout;
+         listout = parcours;
+
+         parcours = NULL;
+      }
+      fclose(dependfileoutput);
+  }
+  return listout;
+}
+
+/******************************************************************************/
+/*                   Writethedependfile                                       */
+/******************************************************************************/
+/* This subroutine is used to create the .depend<name>                        */
+/******************************************************************************/
+/*                                                                            */
+/*                     .depend<name>                                          */
+/*                                                                            */
+/*                      REAL                                                  */
+/*                      Variable                                              */
+/*                      char dimension or T                                   */
+/*                      table dimension                                       */
+/*                      is type given                                         */
+/*                      precision or T                                        */
+/*                      initial value or T                                    */
+/*                      indice in the tabvars                                 */
+/*                      listdimension or T                                    */
+/*                      -------------------------                             */
+/*                                                                            */
+/******************************************************************************/
+void Writethedependfile(char *NameTampon, listvar *input )
+{
+  FILE *dependfileoutput;
+  listvar *parcours;
+  listdim *dims;
+  char ligne[LONGNOM];
+  char listdimension[LONGNOM];
+  char curname[LONGNOM];
+  int out;
+
+  if ( input )
+  {
+  convert2lower(NameTampon);
+
+  sprintf(ligne,".depend%s",NameTampon);
+  dependfileoutput = fopen(ligne,"w");
+  /* We are looking for all the variable of the current filetoparse file      */
+  /*    in the input                                                          */
+  parcours =input;
+  out = 0;
+  strcpy(curname,"");
+  while (parcours && out == 0 )
+  {
+     if ( !strcasecmp(parcours->var->v_modulename,NameTampon) ||
+          !strcasecmp(parcours->var->v_commonname,NameTampon) )
+     {
+        /*                                                                    */
+        if (  strcasecmp(curname,"") &&
+             !strcasecmp(curname,parcours->var->v_nomvar) ) out = 1 ;
+        if ( !strcasecmp(curname,"") ) strcpy(curname,parcours->var->v_nomvar);
+        /*                                                                    */
+        if ( out == 0 )
+        {
+           /********** TYPEVAR ************************************************/
+           fprintf(dependfileoutput,"%s\n",parcours->var->v_typevar);
+           /********** NOMVAR *************************************************/
+           fprintf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
+           /********** DIMCHAR ************************************************/
+           if ( strcasecmp(parcours->var->v_dimchar,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_dimchar);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /********** COMMONINFILE *******************************************/
+           if ( strcasecmp(parcours->var->v_commoninfile,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_commoninfile);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /********** COMMONNAME *********************************************/
+           if ( strcasecmp(parcours->var->v_commonname,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_commonname);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /********** NBDIM **************************************************/
+/*           fprintf(dependfileoutput,"%d\n",parcours->var->v_nbdim);*/
+           /********** DIMENSIONGIVEN *****************************************/
+/*           fprintf(dependfileoutput,"%d\n",parcours->var->v_dimensiongiven);*/
+           /********** ALLOCATABLE ********************************************/
+           fprintf(dependfileoutput,"%d\n",parcours->var->v_allocatable);
+           /********** POINTERDECLARE *****************************************/
+           fprintf(dependfileoutput,"%d\n",parcours->var->v_pointerdeclare);
+           /********** PRECISION **********************************************/
+           if ( strcasecmp(parcours->var->v_precision,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_precision);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /********** INITIALVALUE *******************************************/
+/*           if ( strcasecmp(parcours->var->v_initialvalue,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_initialvalue);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }*/
+           /********** NAMEINTYPENAME *****************************************/
+           if ( strcasecmp(parcours->var->v_nameinttypename,"") )
+           {
+              fprintf(dependfileoutput,"%s\n",parcours->var->v_nameinttypename);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /********** INDICETABVARS ******************************************/
+           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
+           /********** READEDLISTDIMENSION ************************************/
+           if ( parcours->var->v_dimensiongiven == 1 )
+           {
+              dims = parcours->var->v_dimension;
+              strcpy(listdimension,"");
+              while (dims)
+              {
+                 sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
+                 strcat(listdimension,ligne);
+                 if ( dims->suiv )
+                 {
+                    strcat(listdimension,",");
+                 }
+                 dims = dims->suiv;
+              }
+              fprintf(dependfileoutput,"%s\n",listdimension);
+           }
+           else
+           {
+              fprintf(dependfileoutput,"T\n");
+           }
+           /*******************************************************************/
+           fprintf(dependfileoutput,"------------------------\n");
+        }
+     }
+     parcours = parcours->suiv;
+  }
+  fclose(dependfileoutput);
+  }
+}
+
+/******************************************************************************/
+/*                         Readthedependfile                                  */
+/******************************************************************************/
+/* This subroutine is used to read the .dependfile<name> and to insert new    */
+/*    information in the listout list.                                        */
+/******************************************************************************/
+/*                                                                            */
+/*           .dependmodule -------->                      = list of var       */
+/*                                                                            */
+/*        not.dependmodule -------->                                          */
+/*                                                                            */
+/******************************************************************************/
+listvar *Readthedependfile( char *NameTampon , listvar *listout)
+{
+  char ligne[LONGNOM];
+  FILE *dependfileoutput;
+  listvar *parcours0;
+  listvar *parcours;
+  listvar *parcoursprec;
+  char nothing[LONGNOM];
+  int i;
+
+  parcoursprec = (listvar *)NULL;
+
+  convert2lower(NameTampon);
+  sprintf(ligne,".depend%s",NameTampon);
+  if ((dependfileoutput = fopen(ligne,"r"))==NULL)
+  {
+    /* if the file doesn't exist it means that it is the first time           */
+    /*    we tried to parse this file                                         */
+  }
+  else
+  {
+    /* if the file exist we should verify that this file has changed          */
+      while (!feof(dependfileoutput))
+      {
+         parcours=(listvar *)malloc(sizeof(listvar));
+         parcours->var=(variable *)malloc(sizeof(variable));
+         /*                                                                   */
+         Init_Variable(parcours->var);
+         /*                                                                   */
+           /********** TYPEVAR ************************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_typevar);
+           /********** NOMVAR *************************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
+           /********** DIMCHAR ************************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_dimchar);
+         if ( !strcasecmp(parcours->var->v_dimchar,"T") )
+         {
+            strcpy(parcours->var->v_dimchar,"");
+         }
+           /********** COMMONINFILE *******************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_commoninfile);
+         if ( !strcasecmp(parcours->var->v_commoninfile,"T") )
+         {
+            strcpy(parcours->var->v_commoninfile,"");
+         }
+           /********** COMMONNAME *********************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_commonname);
+         if ( !strcasecmp(parcours->var->v_commonname,"T") )
+         {
+            strcpy(parcours->var->v_commonname,"");
+         }
+           /********** NBDIM **************************************************/
+/*         fscanf(dependfileoutput,"%d\n",&parcours->var->v_nbdim);*/
+           /********** DIMENSIONGIVEN *****************************************/
+/*         fscanf(dependfileoutput,"%d\n",&parcours->var->v_dimensiongiven);*/
+           /********** ALLOCATABLE ********************************************/
+         fscanf(dependfileoutput,"%d\n",&parcours->var->v_allocatable);
+         if ( parcours->var->v_allocatable == 1 )
+         {
+            Add_Allocate_Var_1(parcours->var->v_nomvar,
+                               parcours->var->v_commonname);
+         }
+           /********** POINTERDECLARE *****************************************/
+         fscanf(dependfileoutput,"%d\n",&parcours->var->v_pointerdeclare);
+         if ( parcours->var->v_pointerdeclare == 1 )
+         {
+            Add_Pointer_Var_1(parcours->var->v_nomvar);
+         }
+           /********** PRECISION **********************************************/
+         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_precision);
+         if ( !strcasecmp(parcours->var->v_precision,"T") )
+         {
+            strcpy(parcours->var->v_precision,"");
+         }
+           /********** INITIALVALUE *******************************************/
+/*         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_initialvalue);
+         if ( !strcasecmp(parcours->var->v_initialvalue,"T") )
+         {
+            strcpy(parcours->var->v_initialvalue,"");
+         }*/
+           /********** NAMEINTYPENAME *****************************************/
+         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_nameinttypename);
+         if ( !strcasecmp(parcours->var->v_nameinttypename,"T") )
+         {
+            strcpy(parcours->var->v_nameinttypename,"");
+         }
+           /********** INDICETABVARS ******************************************/
+         fscanf(dependfileoutput,"%d\n",&parcours->var->v_indicetabvars);
+           /********** READEDLISTDIMENSION ************************************/
+         fscanf(dependfileoutput,"%s\n",parcours->var->v_readedlistdimension);
+         if ( !strcasecmp(parcours->var->v_readedlistdimension,"T") )
+         {
+            strcpy(parcours->var->v_readedlistdimension,"");
+         }
+         else
+         {
+            parcours->var->v_dimensiongiven = 1;
+            parcours->var->v_nbdim = 1;
+            i = 1;
+            /*                                                                */
+            while ( i < strlen(parcours->var->v_readedlistdimension) )
+            {
+               if ( parcours->var->v_readedlistdimension[i] == ',' )
+               {
+                  parcours->var->v_nbdim = parcours->var->v_nbdim + 1 ;
+               }
+               /*                                                             */
+               i=i+1;
+            }
+         }
+           /*******************************************************************/
+         fscanf(dependfileoutput,"%s\n",nothing);
+         parcours->suiv = NULL;
+         if ( !listout )
+         {
+            listout = parcours;
+            parcoursprec = parcours;
+         }
+         else
+         {
+            if ( parcoursprec )
+            {
+               parcoursprec->suiv = parcours;
+               parcoursprec = parcours;
+            }
+            else
+            {
+               parcours0 = listout;
+               while ( parcours0->suiv ) parcours0=parcours0->suiv;
+               parcours0->suiv = parcours;
+               parcoursprec = parcours0->suiv;
+            }
+         }
+         parcours = NULL;
+      }
+      fclose(dependfileoutput);
+  }
+  return listout;
+}
+
+void Write_Subroutine_For_Alloc()
+{
+   FILE *dependfileoutput;
+   listnom *parcours;
+
+   if ( List_Subroutine_For_Alloc )
+   {
+      if ((dependfileoutput=fopen(".dependAllocAgrif","w"))!=NULL)
+      {
+         parcours = List_Subroutine_For_Alloc;
+         while (parcours)
+         {
+            fprintf(dependfileoutput,"%s\n",parcours->o_nom);
+            parcours = parcours->suiv;
+         }
+         fclose(dependfileoutput);
+      }
+   }
+}
+
+void Read_Subroutine_For_Alloc()
+{
+  FILE *dependfileoutput;
+  listnom *parcours;
+  listnom *ref;
+
+  if ((dependfileoutput=fopen(".dependAllocAgrif","r"))!=NULL)
+  {
+     List_Subroutine_For_Alloc = (listnom *)NULL;
+     while (!feof(dependfileoutput))
+     {
+        parcours=(listnom *)malloc(sizeof(listnom));
+        fscanf(dependfileoutput,"%s\n",&parcours->o_nom);
+        parcours->suiv = NULL;
+
+        if ( !List_Subroutine_For_Alloc )
+        {
+           List_Subroutine_For_Alloc = parcours;
+           ref = parcours;
+        }
+        else
+        {
+            ref->suiv = parcours;
+            ref = parcours;
+        }
+     }
+     fclose(dependfileoutput);
+  }
+}
+
+/******************************************************************************/
+/*                        Writethedependavailablefile                         */
+/******************************************************************************/
+/* This subroutine is used to write the .dependfileavailable file             */
+/******************************************************************************/
+/*                                                                            */
+/*                                  .dependavailable                          */
+/*     tabvars(1) = var1                                                      */
+/*     tabvars(3) = var1                  2                                   */
+/*     tabvars(4) = var1         =====>   5                                   */
+/*     tabvars(6) = var1                                                      */
+/*     tabvars(7) = var1                                                      */
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Writethedependavailablefile()
+{
+  FILE *dependfileoutput;
+  listindice *parcours;
+
+  if ((dependfileoutput=fopen(".dependavailable","w"))!=NULL)
+  {
+     /* We are looking for all the indices of the Listofavailableindices      */
+     parcours = Listofavailableindices;
+     while (parcours)
+     {
+        if ( parcours->i_indice != 0 )
+        {
+           fprintf(dependfileoutput,"%d\n",parcours->i_indice);
+        }
+        parcours = parcours->suiv;
+     }
+     fclose(dependfileoutput);
+  }
+}
+
+/******************************************************************************/
+/*                        Readthedependavailablefile                          */
+/******************************************************************************/
+/* This subroutine is used to read the .dependfileavailable file              */
+/******************************************************************************/
+/*                                                                            */
+/*                                  .dependavailable                          */
+/*     tabvars(1) = var1                                                      */
+/*     tabvars(3) = var1                  2                                   */
+/*     tabvars(4) = var1         =====>   5  ==> Listofavailableindices       */
+/*     tabvars(6) = var1                                                      */
+/*     tabvars(7) = var1                                                      */
+/*                                                                            */
+/*                                                                            */
+/*                                                                            */
+/******************************************************************************/
+void Readthedependavailablefile()
+{
+  FILE *dependfileoutput;
+  listindice *parcours;
+
+  if ((dependfileoutput=fopen(".dependavailable","r"))!=NULL)
+  {
+     /* We are looking for all the indices of the Listofavailableindices      */
+     Listofavailableindices = (listindice *)NULL;
+     while (!feof(dependfileoutput))
+     {
+        parcours=(listindice *)malloc(sizeof(listindice));
+        fscanf(dependfileoutput,"%d\n",&parcours->i_indice);
+        if ( parcours->i_indice != 0 && parcours->i_indice < 10000000 )
+        {
+           parcours -> suiv = Listofavailableindices;
+           Listofavailableindices = parcours;
+        }
+        else
+        {
+           free(parcours);
+        }
+     }
+     fclose(dependfileoutput);
+  }
+}
+
+
+/******************************************************************************/
+/*                      Did_filetoparse_readed                                */
+/******************************************************************************/
+/* This subroutine is used to know if the .depend<NameTampon> exist           */
+/*    it means if the file has been ever parsed                               */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int Did_filetoparse_readed(char *NameTampon)
+{
+  FILE *dependfileoutput;
+  char ligne[LONGNOM];
+  int out;
+
+  convert2lower(NameTampon);
+  sprintf(ligne,".depend%s",NameTampon);
+  if ((dependfileoutput = fopen(ligne,"r"))==NULL)
+  {
+      out = 0;
+  }
+  else
+  {
+      out = 1;
+      fclose(dependfileoutput);
+  }
+  return out;
+}
+
+
+/******************************************************************************/
+/*                      Did_module_common_treaded                             */
+/******************************************************************************/
+/* This subroutine is used to know if the .depend<NameTampon> exist           */
+/*    it means if the file has been ever parsed                               */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+int Did_module_common_treaded(char *NameTampon)
+{
+  FILE *dependfileoutput;
+  char ligne[LONGNOM];
+  int out;
+
+  convert2lower(NameTampon);
+  sprintf(ligne,".depend%s",NameTampon);
+  if ((dependfileoutput = fopen(ligne,"r"))==NULL)
+  {
+      out = 0;
+  }
+  else
+  {
+      out = 1;
+      fclose(dependfileoutput);
+  }
+  return out;
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.c	(revision 4536)
@@ -0,0 +1,13086 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
+#endif
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+#define yyclearin (yychar=(-1))
+#define yyerrok (yyerrflag=0)
+#define YYRECOVERING (yyerrflag!=0)
+extern int yyparse(void);
+#define yyparse fortranparse
+#define yylex fortranlex
+#define yyerror fortranerror
+#define yychar fortranchar
+#define yyval fortranval
+#define yylval fortranlval
+#define yydebug fortrandebug
+#define yynerrs fortrannerrs
+#define yyerrflag fortranerrflag
+#define yyss fortranss
+#define yyssp fortranssp
+#define yyvs fortranvs
+#define yyvsp fortranvsp
+#define yylhs fortranlhs
+#define yylen fortranlen
+#define yydefred fortrandefred
+#define yydgoto fortrandgoto
+#define yysindex fortransindex
+#define yyrindex fortranrindex
+#define yygindex fortrangindex
+#define yytable fortrantable
+#define yycheck fortrancheck
+#define yyname fortranname
+#define yyrule fortranrule
+#define YYPREFIX "fortran"
+#line 36 "fortran.y"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "decl.h"
+extern int line_num_fortran;
+extern int line_num_fortran_common;
+char *tmp;
+char c_selectorname[LONGNOM];
+char ligne[LONGNOM];
+char identcopy[LONGNOM];
+int c_selectorgiven=0;
+int incom;
+listvar *curlistvar;
+typedim c_selectordim;
+listcouple *coupletmp;
+listdim *parcoursdim;
+int removeline=0;
+listvar *test;
+#line 56 "fortran.y"
+typedef union {
+       char      na[LONGNOM];
+       listdim  *d;
+       listvar  *l;
+       listnom  *ln;
+       listcouple  *lc;
+       typedim   dim1;
+       variable *v;
+       } YYSTYPE;
+#line 66 "y.tab.c"
+#define TOK_BINARY_OP 257
+#define EQV 258
+#define NEQV 259
+#define TOK_OR 260
+#define TOK_XOR 261
+#define TOK_AND 262
+#define TOK_NOT 263
+#define TOK_LT 264
+#define TOK_GT 265
+#define TOK_LE 266
+#define TOK_GE 267
+#define TOK_EQ 268
+#define TOK_NE 269
+#define TOK_UNARY_OP 270
+#define TOK_DSLASH 271
+#define TOK_SLASH 272
+#define TOK_DASTER 273
+#define TOK_SEP 274
+#define TOK_NEXTLINE 275
+#define TOK_PARAMETER 276
+#define TOK_RESULT 277
+#define TOK_ONLY 278
+#define TOK_INCLUDE 279
+#define TOK_SUBROUTINE 280
+#define TOK_PROGRAM 281
+#define TOK_FUNCTION 282
+#define TOK_OMP 283
+#define TOK_DOLLAR 284
+#define TOK_FORMAT 285
+#define TOK_MAX 286
+#define TOK_TANH 287
+#define TOK_WHERE 288
+#define TOK_ELSEWHERE 289
+#define TOK_ENDWHERE 290
+#define TOK_MAXVAL 291
+#define TOK_TRIM 292
+#define TOK_SUM 293
+#define TOK_SQRT 294
+#define TOK_CASE 295
+#define TOK_SELECTCASE 296
+#define TOK_FILE 297
+#define TOK_END 298
+#define TOK_ERR 299
+#define TOK_DONOTTREAT 300
+#define TOK_ENDDONOTTREAT 301
+#define TOK_EXIST 302
+#define TOK_MIN 303
+#define TOK_INT 304
+#define TOK_FLOAT 305
+#define TOK_EXP 306
+#define TOK_COS 307
+#define TOK_COSH 308
+#define TOK_ACOS 309
+#define TOK_NINT 310
+#define TOK_CYCLE 311
+#define TOK_SIN 312
+#define TOK_SINH 313
+#define TOK_ASIN 314
+#define TOK_EQUIVALENCE 315
+#define TOK_BACKSPACE 316
+#define TOK_LOG 317
+#define TOK_TAN 318
+#define TOK_ATAN 319
+#define TOK_RECURSIVE 320
+#define TOK_ABS 321
+#define TOK_MOD 322
+#define TOK_SIGN 323
+#define TOK_MINLOC 324
+#define TOK_MAXLOC 325
+#define TOK_EXIT 326
+#define TOK_MINVAL 327
+#define TOK_PUBLIC 328
+#define TOK_PRIVATE 329
+#define TOK_ALLOCATABLE 330
+#define TOK_IN 331
+#define TOK_RETURN 332
+#define TOK_THEN 333
+#define TOK_ELSEIF 334
+#define TOK_ELSE 335
+#define TOK_ENDIF 336
+#define TOK_PRINT 337
+#define TOK_PLAINGOTO 338
+#define TOK_CONSTRUCTID 339
+#define TOK_LOGICALIF 340
+#define TOK_PLAINDO 341
+#define TOK_CONTAINS 342
+#define TOK_ENDDO 343
+#define TOK_MODULE 344
+#define TOK_ENDMODULE 345
+#define TOK_DOWHILE 346
+#define TOK_ALLOCATE 347
+#define TOK_OPEN 348
+#define TOK_CLOSE 349
+#define TOK_INQUIRE 350
+#define TOK_WRITE 351
+#define TOK_READ 352
+#define TOK_REWIND 353
+#define TOK_DEALLOCATE 354
+#define TOK_NULLIFY 355
+#define TOK_FIN 356
+#define TOK_DEBUT 357
+#define TOK_OUT 358
+#define TOK_INOUT 359
+#define TOK_DIMENSION 360
+#define TOK_ENDSELECT 361
+#define TOK_EXTERNAL 362
+#define TOK_INTENT 363
+#define TOK_INTRINSIC 364
+#define TOK_NAMELIST 365
+#define TOK_CASEDEFAULT 366
+#define TOK_OPTIONAL 367
+#define TOK_POINTER 368
+#define TOK_CONTINUE 369
+#define TOK_SAVE 370
+#define TOK_TARGET 371
+#define TOK_QUOTE 372
+#define TOK_IMPLICIT 373
+#define TOK_NONE 374
+#define TOK_CALL 375
+#define TOK_STAT 376
+#define TOK_POINT_TO 377
+#define TOK_COMMON 378
+#define TOK_GLOBAL 379
+#define TOK_INTERFACE 380
+#define TOK_ENDINTERFACE 381
+#define TOK_LEFTAB 382
+#define TOK_RIGHTAB 383
+#define TOK_PAUSE 384
+#define TOK_PROCEDURE 385
+#define TOK_STOP 386
+#define TOK_NAMEEQ 387
+#define TOK_REAL8 388
+#define TOK_USE 389
+#define TOK_TRUE 390
+#define TOK_FALSE 391
+#define TOK_LABEL 392
+#define TOK_TYPE 393
+#define TOK_TYPEPAR 394
+#define TOK_ENDTYPE 395
+#define TOK_REAL 396
+#define TOK_INTEGER 397
+#define TOK_LOGICAL 398
+#define TOK_DOUBLEPRECISION 399
+#define TOK_DOUBLEREAL 400
+#define TOK_ENDSUBROUTINE 401
+#define TOK_ENDFUNCTION 402
+#define TOK_ENDPROGRAM 403
+#define TOK_ENDUNIT 404
+#define TOK_CHARACTER 405
+#define TOK_CHAR_CONSTANT 406
+#define TOK_CHAR_CUT 407
+#define TOK_DATA 408
+#define TOK_CHAR_INT 409
+#define TOK_CHAR_MESSAGE 410
+#define TOK_CSTREAL 411
+#define TOK_CSTREALDP 412
+#define TOK_CSTREALQP 413
+#define TOK_SFREAL 414
+#define TOK_COMPLEX 415
+#define TOK_DOUBLECOMPLEX 416
+#define TOK_NAME 417
+#define TOK_NAME_CHAR 418
+#define TOK_PROBTYPE 419
+#define TOK_INTERPTYPE 420
+#define TOK_VARTYPE 421
+#define TOK_BC 422
+#define TOK_OP 423
+#define TOK_CSTINT 424
+#define TOK_COMMENT 425
+#define TOK_FILENAME 426
+#define YYERRCODE 256
+short fortranlhs[] = {                                        -1,
+    0,    0,   66,   66,   66,   66,   66,   69,   69,   74,
+   74,   74,   74,   74,   80,   76,   70,   70,   70,   70,
+   67,   68,   68,   71,   71,   81,   73,   82,   82,   75,
+   75,   75,   75,   75,   75,   16,   72,   78,   64,    6,
+    6,    6,   83,   83,   83,    5,    5,   22,   22,   77,
+   77,   77,   77,   77,   77,   77,   77,   77,   77,   77,
+   77,   77,   77,   77,   77,   77,   77,   77,   77,   77,
+   84,   84,  103,  103,  103,  103,  103,  103,  103,  103,
+  103,  103,  103,  103,  103,  103,  103,  103,  103,  103,
+  103,  103,  103,  103,  103,  103,   98,   98,   86,   86,
+   99,   99,  105,  106,  106,  104,  104,   85,   85,    2,
+    2,  108,   87,  100,  101,  101,  101,   49,   49,   89,
+   89,   89,   89,  111,  112,  112,  110,  110,  110,   35,
+   35,   35,   35,   35,   62,   62,   96,  113,  113,  113,
+  113,  114,   95,   95,  115,    3,    3,   92,   92,   91,
+   91,   97,   97,   88,   88,   88,  117,  117,  118,  118,
+  119,   15,   15,  109,  109,    4,    4,   14,   94,  120,
+  120,   90,   90,  121,    1,    1,  107,   21,   21,   21,
+   21,  127,  126,  126,  126,  126,  129,  129,  129,  125,
+   24,   23,   23,   23,   23,   23,   23,  116,  116,   65,
+   65,  124,  124,  124,  131,  131,  128,  128,  128,  128,
+   20,   20,  130,  130,  122,  122,  122,  132,  132,  133,
+  133,  133,  133,  133,  133,  133,  133,  133,  133,  133,
+   59,   59,   59,  102,  102,   11,   11,   12,   12,   13,
+   13,   13,   13,   13,   60,   60,   54,   54,   54,   54,
+   52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+   52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+   52,   52,   52,   52,   52,   52,   52,   26,   26,   25,
+   25,   25,   25,   25,   25,   61,   61,   63,   63,   63,
+   63,   63,   63,   63,   63,   63,   63,   63,   63,   63,
+   63,   63,   63,   63,   63,   63,   50,   50,   50,   50,
+   51,   51,   28,   28,   28,   36,   39,   39,   39,   39,
+   17,   38,   30,   40,   40,   42,   42,   41,   41,   43,
+   43,   43,   43,   43,   43,   43,   37,   29,   29,   29,
+   29,   29,   29,   29,   29,   45,   45,   45,   45,   46,
+   46,   44,   48,   48,   47,   47,  123,  123,  134,   27,
+   93,   93,   93,   93,  135,   18,    9,    9,   10,    7,
+    7,    8,    8,   79,   79,   79,   79,   79,   79,   79,
+   79,   79,   79,   79,   79,   79,   79,   79,   79,   79,
+   79,   79,   79,   79,   79,   79,   55,   58,   57,   56,
+  143,  143,  143,  141,  141,  141,  146,  146,  146,  145,
+  145,   19,   19,  148,  148,  144,  147,  149,  149,  136,
+  136,  136,  136,  136,  136,  136,  136,  136,  136,  136,
+  136,  157,  150,  150,  156,  156,  151,  151,  154,  159,
+  159,  160,  160,  158,  162,  161,  161,  163,  163,  155,
+  155,  153,  153,  153,  153,  170,  170,  171,  171,  171,
+  172,  172,  173,  173,  168,  168,  177,  177,  176,  176,
+  166,  166,  169,  169,  169,  169,  169,  178,  178,  180,
+  180,  180,  180,  180,  180,  180,  180,  165,  165,  175,
+  175,  167,  167,  167,  167,  179,  179,  181,  181,  181,
+  181,  181,  181,  181,  181,  181,  181,  181,  181,  181,
+  182,  182,  174,  174,  184,  184,  183,  183,  183,  183,
+  183,  185,  185,  185,   31,   31,   32,   32,   32,   32,
+   32,   32,   32,   32,   33,   33,   33,   33,   33,   34,
+   34,  186,  186,  164,  152,  152,  137,  137,  137,  187,
+  187,  187,  188,  189,  189,  139,  139,  138,  138,  140,
+  140,  190,  190,  191,  191,  142,   53,
+};
+short fortranlen[] = {                                         2,
+    0,    2,    2,    2,    1,    3,    3,    1,    3,    2,
+    2,    3,    3,    2,    2,    2,    1,    1,    1,    1,
+    0,    0,    2,    0,    1,    0,    0,    0,    1,    0,
+    4,    2,    5,    3,    2,    1,    0,    1,    1,    0,
+    2,    3,    0,    2,    3,    1,    3,    1,    1,    2,
+    4,    2,    2,    4,    2,    1,    1,    1,    1,    1,
+    1,    1,    1,    1,    1,    4,    3,    3,    2,    3,
+    0,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+    1,    1,    1,    1,    1,    1,    1,    3,    3,    5,
+    1,    3,    3,    2,    4,    1,    3,    0,    2,    2,
+    3,    1,    1,    1,    4,    6,    4,    1,    3,    2,
+    3,    5,    3,    1,    0,    2,    1,    4,    3,    2,
+    3,    3,    3,    3,    0,    1,    2,    2,    3,    5,
+    3,    0,    2,    2,    1,    5,    5,    2,    3,    2,
+    3,    1,    3,    2,    3,    5,    1,    2,    1,    3,
+    2,    1,    3,    0,    1,    1,    3,    3,    2,    1,
+    3,    2,    2,    0,    6,    7,    0,    2,    2,    3,
+    3,    1,    0,    2,    4,    3,    3,    4,    2,    1,
+    1,    1,    1,    1,    1,    1,    1,    0,    2,    1,
+    3,    0,    2,    3,    1,    3,    2,    3,    1,    1,
+    1,    1,    0,    3,    0,    2,    4,    1,    3,    1,
+    1,    1,    2,    1,    2,    1,    1,    1,    1,    1,
+    1,    1,    1,    1,    1,    0,    3,    1,    3,    1,
+    1,    2,    2,    3,    1,    1,    1,    3,    1,    1,
+    3,    3,    4,    4,    3,    4,    4,    3,    4,    4,
+    4,    4,    4,    4,    4,    4,    4,    4,    4,    4,
+    4,    4,    3,    4,    4,    4,    4,    1,    3,    1,
+    1,    1,    2,    2,    2,    1,    1,    2,    2,    2,
+    2,    2,    2,    2,    2,    2,    2,    3,    2,    3,
+    2,    2,    2,    2,    2,    2,    0,    1,    2,    2,
+    2,    1,    1,    1,    1,    0,    1,    2,    4,    5,
+    4,    3,    3,    1,    2,    1,    3,    1,    1,    3,
+    5,    4,    3,    2,    2,    1,    1,    1,    1,    1,
+    1,    1,    1,    2,    2,    1,    2,    1,    1,    0,
+    1,    5,    0,    1,    1,    1,    0,    3,    0,    5,
+    2,    4,    6,    6,    1,    1,    1,    3,    3,    1,
+    3,    3,    1,    1,    5,    5,    4,    1,    2,    2,
+    2,    2,    1,    2,    5,    1,    1,    2,    5,    1,
+    2,    3,    4,    1,    1,    1,    1,    1,    1,    1,
+    1,    3,    3,    3,    2,    2,    0,    5,    7,    0,
+    2,    1,    1,    0,    1,    1,    1,    0,    1,    1,
+    2,    1,    1,    1,    5,    5,    2,    2,    2,    2,
+    1,    0,    4,    6,    1,    3,    2,    2,    2,    0,
+    3,    0,    1,    2,    1,    1,    3,    1,    2,    1,
+    1,    2,    2,    2,    1,    0,    2,    1,    1,    1,
+    0,    2,    0,    1,    2,    2,    0,    1,    0,    2,
+    3,    3,    3,    3,    1,    3,    1,    1,    3,    1,
+    1,    1,    2,    4,    4,    2,    2,    1,    1,    1,
+    1,    1,    1,    1,    1,    1,    3,    1,    1,    3,
+    3,    3,    3,    2,    3,    2,    2,    2,    2,    3,
+    1,    1,    1,    3,    0,    1,    2,    4,    2,    2,
+    5,    0,    1,    2,    1,    1,    3,    3,    3,    3,
+    3,    3,    1,    1,    1,    3,    5,    5,    5,    5,
+    7,    1,    3,    1,    8,    2,    1,    1,    3,    1,
+    1,    1,    4,    1,    3,    1,    3,    0,    4,    1,
+    3,    0,    1,    0,    2,    3,    1,
+};
+short fortrandefred[] = {                                      1,
+    0,   37,   19,   20,   17,   18,   27,    5,   21,    2,
+    0,    0,   27,   23,    3,  113,   38,    0,    0,  455,
+    0,  386,  387,    0,    0,    0,    0,    0,   29,    0,
+    0,    0,    0,    0,  390,    0,  495,    0,    0,  416,
+  396,    0,    0,    0,  417,    0,  488,  489,  493,  494,
+  492,    0,    0,    0,  145,  395,    0,    0,    0,  394,
+    0,  420,  124,    0,  445,  157,    0,    0,    0,  450,
+    0,  451,  365,    0,  182,    0,  193,  192,  197,  195,
+  397,  400,  399,  398,  190,  114,  194,  196,  337,  435,
+    0,    0,    0,    0,    0,    0,    0,    0,  378,    4,
+    0,   21,   21,    0,    0,   21,    0,    0,    0,    0,
+   58,   60,   61,   62,   63,   64,   65,    0,    0,    0,
+    0,    0,    0,    0,    0,  374,  383,    0,    0,    0,
+    0,  422,  423,  424,    0,    0,    0,    0,    0,    0,
+   25,   37,    7,   36,   32,    0,    0,    0,  286,  287,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  338,  339,    0,
+  346,  349,  348,  341,  342,  343,  340,    0,    0,  247,
+  249,    0,    0,  282,    0,    0,  315,    0,  250,    0,
+    0,    0,    0,  355,  429,    0,    0,    0,  101,    0,
+  427,    0,    0,  150,    0,  148,    0,  428,    0,  413,
+  412,  391,  544,    0,  546,    0,  415,  406,   35,  382,
+    0,  477,  475,    0,  454,    0,    0,    0,    0,  162,
+    0,    0,  138,    0,    0,  172,  173,  158,  143,  144,
+  170,    0,  234,  235,    0,   72,   52,    0,    0,    0,
+  112,    0,   50,    0,  174,    0,    0,    0,  178,   15,
+    0,  380,  381,  379,    0,    0,   10,   11,   39,   21,
+   37,   14,    0,    0,    0,    0,  166,  165,    0,    0,
+    0,    0,    0,    0,    0,    0,  120,    0,    0,  137,
+    0,    0,    0,    0,  159,    0,    0,  179,    0,  210,
+    0,  366,    0,  388,    0,    0,  432,  384,    0,    0,
+    0,    0,    0,    0,  421,  430,    0,    0,  439,  444,
+    0,  452,  511,  512,  491,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  453,    0,    0,    0,    0,    6,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  249,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  318,    0,  344,  316,  316,  347,  351,
+  345,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  283,    0,
+    0,    0,  392,    0,    0,    0,    0,    0,  109,  152,
+    0,    0,    0,    0,  566,    0,    0,    0,    0,    0,
+  547,  552,    0,    0,    0,    0,    0,  556,  560,    0,
+    0,   74,   75,   78,   73,   79,   76,   81,   82,   83,
+   84,   85,   80,   86,   87,   88,   89,   90,   91,   92,
+   93,   94,   95,   77,   96,    0,   97,    0,  139,    0,
+    0,    0,    0,    0,    0,  220,  222,    0,  224,    0,
+  226,  227,  228,  229,  230,  221,    0,  218,  216,  174,
+  110,    0,    0,  180,    0,    0,  203,    0,    0,    0,
+    9,   16,   12,   13,    0,    0,    0,    0,    0,  123,
+    0,    0,    0,   70,    0,    0,    0,  126,  121,  141,
+    0,    0,  161,    0,    0,  184,    0,  212,    0,    0,
+    0,    0,    0,  207,  181,    0,    0,    0,  411,  567,
+    0,  404,    0,    0,  432,  436,    0,    0,    0,    0,
+  446,  481,  482,    0,    0,    0,    0,  478,  496,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  465,
+    0,  513,    0,    0,  466,    0,    0,    0,    0,    0,
+    0,   49,   48,   41,    0,   46,    0,    0,    0,  252,
+    0,    0,    0,  251,  258,  255,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  273,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  323,    0,    0,    0,    0,  248,    0,    0,    0,    0,
+    0,    0,  306,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  305,    0,
+    0,    0,    0,    0,    0,    0,    0,  393,  104,    0,
+  103,  102,   66,    0,    0,    0,    0,    0,    0,  474,
+  476,  473,    0,    0,    0,  377,    0,  163,    0,   99,
+    0,  171,   51,    0,  223,  231,  232,  233,  225,    0,
+    0,    0,  111,    0,    0,  204,    0,  245,    0,  238,
+    0,  240,  433,   31,    0,   54,  167,    0,    0,    0,
+    0,  136,    0,    0,    0,    0,  129,    0,    0,    0,
+  160,    0,    0,    0,    0,  189,  186,  208,    0,    0,
+    0,  367,    0,    0,    0,    0,  449,  441,    0,  486,
+  487,    0,    0,    0,    0,  471,  472,    0,    0,    0,
+  523,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,   42,    0,   33,  385,    0,  253,  254,  257,
+  260,  262,  263,  264,  265,  266,  261,  267,  268,  269,
+  270,  271,  272,  274,  275,  276,  277,  256,    0,    0,
+    0,  248,  528,    0,  532,    0,  530,    0,  259,    0,
+    0,    0,  326,    0,  329,    0,  321,    0,    0,    0,
+    0,    0,    0,    0,  153,  389,    0,    0,    0,  549,
+  375,  557,  376,  561,   98,    0,    0,    0,  147,  219,
+  217,    0,    0,  206,    0,    0,  237,    0,    0,  122,
+    0,    0,    0,    0,    0,  115,    0,  128,    0,  117,
+  140,  146,  185,    0,  187,    0,    0,    0,    0,    0,
+    0,    0,    0,  447,    0,    0,    0,  497,    0,  479,
+    0,    0,  524,  514,   47,   44,    0,    0,    0,    0,
+    0,  360,    0,    0,    0,    0,    0,  320,  105,    0,
+  553,    0,  100,    0,    0,  199,    0,    0,  239,    0,
+  244,  119,    0,    0,    0,    0,    0,  188,  214,    0,
+  363,    0,  370,  369,  368,  425,  426,    0,  434,  485,
+    0,    0,    0,   45,    0,  537,  539,  538,  352,    0,
+    0,  327,    0,    0,  559,    0,    0,  175,    0,  116,
+    0,    0,    0,  521,    0,    0,    0,    0,  201,  176,
+    0,  372,  371,    0,    0,    0,    0,    0,    0,    0,
+    0,
+};
+short fortrandgoto[] = {                                       1,
+  262,  263,   91,  286,  595,  352,  922,  923,  741,  742,
+  510,  709,  710,  287,  242,  145,  189,  313,  222,  540,
+   92,  596,   93,   94,  190,  355,  191,  192,  193,  194,
+  385,  386,  803,  889,  720,  639,  195,  196,  197,  640,
+  813,  814,  815,  394,  198,  401,  205,  211,  721,  659,
+  643,  199,  551,  356,   96,   97,   98,   99,  699,  712,
+  201,  723,  419,  280,  906,   10,  276,   11,  100,   12,
+  142,   13,   14,  101,  102,  277,  103,  104,  105,  106,
+    0,  107,  775,  255,  215,  245,  108,  109,  110,  111,
+  112,  113,  114,  115,  116,  117,  431,  476,  208,  118,
+  293,  496,  477,  481,  209,  426,  501,  264,  289,  294,
+  119,  297,  120,  300,  121,  839,  122,  304,  305,  252,
+  503,  265,  948,  269,  123,  308,  124,  311,  542,  736,
+  507,  497,  498,  949,  125,  126,  439,  679,  447,  450,
+  127,  128,  202,  129,  320,  552,  130,  228,    0,  131,
+  325,  132,  133,  134,  135,  136,  271,  137,  329,  559,
+  560,  138,  561,  225,  139,  332,  140,  345,  235,    0,
+    0,    0,  580,  581,  346,  585,    0,  566,  347,  568,
+  569,  349,  582,  583,  762,    0,  441,  442,    0,    0,
+    0,
+};
+short fortransindex[] = {                                      0,
+   22,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+26786, -322,    0,    0,    0,    0,    0, -309, -309,    0,
+  100,    0,    0,25041,  106,  886,  127,  138,    0,25041,
+   97,  103,  886,  142,    0,    8,    0,  -15,25041,    0,
+    0, -223, -218,    8,    0,  165,    0,    0,    0,    0,
+    0,  -13,  177,  193,    0,    0,   92,   92, -153,    0,
+  196,    0,    0, -222,    0,    0, -138,    8,    8,    0,
+ -160,    0,    0,  -84,    0,    8,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  221,   27,  228,  216,  217,    8,    8,    8,    0,    0,
+  225,    0,    0, -105, -322,    0,   36,  -12,  277,  281,
+    0,    0,    0,    0,    0,    0,    0,  -49,  -88,  359,
+  277,  -80,  240, -255,   33,    0,    0, 4745,  -16,25041,
+   41,    0,    0,    0,  886,  391,  417,   65,  449,  379,
+    0,    0,    0,    0,    0,  480,25041,25041,    0,    0,
+25041,  492,  514,  536,25041,25041,25041,  538,  543,  548,
+  552,  553,  554,  563,  565,  577,  581,  590,  591,  595,
+25041,  597,  599,  604,  609,  610,25093,    0,    0,  622,
+    0,    0,    0,    0,    0,    0,    0,25041,  634,    0,
+    0,  453,  135,    0,  640,  644,    0,  -11,    0,26791,
+25041,  110,25041,    0,    0,26791,  150,  487,    0,25041,
+    0,26791,  511,    0,  243,    0,  243,    0,25041,    0,
+    0,    0,    0,25041,    0,16959,    0,    0,    0,    0,
+  150,    0,    0,25222,    0,  150,  150,  243, 1417,    0,
+  249,  150,    0,25041,  641,    0,    0,    0,    0,    0,
+    0,  648,    0,    0,   92,    0,    0,  279,  490,  646,
+    0,  668,    0, -309,    0,  294,25270, -255,    0,    0,
+  686,    0,    0,    0,26786, -322,    0,    0,    0,    0,
+    0,    0, -309,  658,  313,  703,    0,    0,  226,  335,
+  226,    1,   84,   30,  686,  335,    0,  150,  226,    0,
+  337,  686,  350,  728,    0,   -9, 1465,    0,24013,    0,
+  732,    0,  730,    0,  744,  759,    0,    0,  277,  150,
+26791,25041,25041,  150,    0,    0,  369, 2564,    0,    0,
+  834,    0,    0,    0,    0,25041,25041,25041,25041,  760,
+  834,  453,  135, 1958,    0,  771,  289,    0,  826,    0,
+    9,  546,25737,  491,  178,26791,25041,25041,25041,  395,
+25759,  429,25041,25041,25041,25041,25041,25041,25041,25041,
+25041,25041,25041,25041,25041,25785,25041,25041,25041,25041,
+25041,25093,  785,    0,  451,  791,  797,    0,26791,25041,
+  803,25841,25041,    0,  150,    0,    0,    0,    0,    0,
+    0,24395,25041,25041,25041,25041,25041,25041,25041,25041,
+25041,25041,25041,25041,24061,25041,24524,24576,    0,26791,
+25041,25041,    0,25855,  686,  439,  127,25869,    0,    0,
+  807,  807,25883, 2174,    0,  453,  815,  644,  812,  822,
+    0,    0,  821,  823,  334,  815,  819,    0,    0,  503,
+  807,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  824,    0,  593,    0,26791,
+  505,  827,  458,    8,  686,    0,    0,  686,    0, -210,
+    0,    0,    0,    0,    0,    0,  114,    0,    0,    0,
+    0,  480,  461,    0, 3107,26791,    0,  840,24190,  686,
+    0,    0,    0,    0,  480,25041,  527,  313,  277,    0,
+  277,  494,25041,    0,  465,  466,  494,    0,    0,    0,
+  277,  686,    0,  728,  350,    0, 1465,    0,24347,  841,
+26791,  843, 3650,    0,    0, -219,  150,  150,    0,    0,
+  828,    0,26791,26791,    0,    0,  473,26791,  859,  857,
+    0,    0,    0,23867,  826,  560,   47,    0,    0,26791,
+26791,26791,26791,25041,  245, 1958,  453, 4747,26791,    0,
+  861,    0,26791, 1958,    0,  826,  826,  826,  826,  826,
+  633,    0,    0,    0,  566,    0,  867,  886,25041,    0,
+  578,  582,25919,    0,    0,    0,25933,25973,25999,26021,
+26035,26116,26166,26213,26268,26282,26296,26310,26349,    0,
+  584,  607,  613,  614,  615,  864,  866,  868,26363,25093,
+    0,25093,25093,  620,25041,    0,  855,  453,24705,  873,
+  874,25041,    0,26791, 1067, 1067,  491,  192,  192,  192,
+  192,  192,  192,  170,  170,   82,25041,25041,    0,26791,
+   82,25041,  192,25041,  192,26791,26791,    0,    0,  150,
+    0,    0,    0,  499,  588,25041,24705, -272,  887,    0,
+    0,    0, -272,  889,  150,    0, 1417,    0,25041,    0,
+25041,    0,    0,  885,    0,    0,    0,    0,    0,  490,
+  877,  515,    0,  686,  897,    0,25041,    0,  629,    0,
+26463,    0,    0,    0,26791,    0,    0,  350,  335,  467,
+  667,    0,  420,26399,  671,  902,    0,  675,  150,  885,
+    0,  903, 3650,  841,  531,    0,    0,    0,  894,  586,
+  915,    0,  812,  819,25041,  686,    0,    0, 2564,    0,
+    0,24705,  626,  250,  834,    0,    0,26791,    0,  631,
+    0,26791,26791, 1958,26791,  861,  234,  633,  633,  633,
+   24,    3,    0,   11,    0,    0,26791,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,25399,25399,
+25399,    0,    0,26791,    0,26791,    0,26791,    0,  923,
+25041,24864,    0,  922,    0,26542,    0,  634,  192,  192,
+   82,  192,  192,  686,    0,    0,26427,  638,  906,    0,
+    0,    0,    0,    0,    0,26791,  649,25447,    0,    0,
+    0,  686,  885,    0,26791,24190,    0, 4193,  728,    0,
+  494,  494,  494,  494,  494,    0,  135,    0,  494,    0,
+    0,    0,    0,  841,    0, 3650,   10,  569,  570,  947,
+  950,26595,  686,    0,  978,17399,  150,    0,  289,    0,
+ 2020,26791,    0,    0,    0,    0,  650,  959,  981,  987,
+ 1004,    0, 1005,25041,26695,24705,25041,    0,    0, 1003,
+    0,  150,    0,24912,26791,    0,  885,    0,    0,26791,
+    0,    0,   83,   83, 1001,  544,  780,    0,    0,  684,
+    0, 1012,    0,    0,    0,    0,    0,25041,    0,    0,
+  822, 1019,26791,    0,25041,    0,    0,    0,    0,26791,
+25041,    0,26709,25041,    0, 1022,    0,    0, 1010,    0,
+  655,  659,26641,    0,26730,26791,25041,26791,    0,    0,
+25041,    0,    0,25041,25041,26791,26791,26791,26756,25041,
+26791,
+};
+short fortranrindex[] = {                                      0,
+23644,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  116,23498,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,23345,
+  660,  660,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,22737,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  660, 1518,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    6,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+18169,  698,   21,   28,   -4,    0,    0,    0,    0,    0,
+22890,    0,    0,    0,23498,    0,    0,    0,13877,14035,
+    0,    0,    0,    0,    0,    0,    0,    0,18331,14185,
+  702,    0,   29,    0,    0,    0,    0,    0,23041,    0,
+    0,    0,    0,    0,    0,18481,18635,    0,    0,    0,
+    0,    0,    0,    0,    0,17136,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0, 1264,    0,
+    0, 2740, 2906,    0, 1641, 1807,    0, 1098,    0,  130,
+    0,    0,    0,    0,    0,18785,    0,18939,    0,    0,
+    0,14435,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,19089,    0,    0,    0,    0,    0,
+    0,19243,    0,    0,   16,    0,    0,    0,    0,    0,
+    0,19393,    0,    0,    0,    0,    0,    0,    0,    0,
+   -7,    0,    0,    0,  116,23498,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,19547,    0,    0,    0,14585,
+    0, 1021,  702,    0,12267,14585,    0,  253,    0,    0,
+    0,12267,    0,14743,    0,    0,    0,    0, 1025,    0,
+    0,    0,19697,    0,    0,    0,    0,    0,19851,23194,
+20001,    0,    0,    0,    0,    0,    0, 1048,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0, 5591,
+    0,10069,10219, 5074,    0,20155,    0,10479,    0,    0,
+    0,20305,    0, 5968,    0,  656,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0, 5306,    0,    0,  720,  733,16990,    0,    0,
+24021,    0, 1053,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0, 4912,    0,    0,    0,    0,11455,
+    0,    0,    0,    0,  657,    0,    0,    0,    0,    0,
+20459,20609,    0,    0,    0,    0,  218,  501, 1076,  662,
+    0,    0, 4797,26827,25608,  529, 1076,    0,    0,    0,
+20763,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,20913,    0,    0,    0,  664,
+    0,    0,    0,    0,14952,    0,    0,  149,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,21067,    0,    0,    0,   71,    0,    0,    0,   -7,
+    0,    0,    0,    0,21067,    0,    0,    0,  702,    0,
+15110,  512,    0,    0,    0,    0,  512,    0,    0,    0,
+  702,14952,    0,15260,    0,    0,    0,    0,  540, 1077,
+  670,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,21217,21371,    0,    0,    0,  672,    0, 1079,
+    0,    0,    0,   56,    0,    0, 1078,    0,    0,12517,
+12667,12917,13067,    0, 1078,25686, 3992,17394,15510,    0,
+21521,    0,15510, 5441,    0,    0,    0,    0,    0,    0,
+10629,    0,    0,    0,    0,    0,21675,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,26449,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0, 2197, 1080,    0,
+    0,    0,    0,11705, 9657, 9807, 6118, 6495, 6645, 7022,
+ 7172, 7549, 7699, 4369, 4535, 3283,    0,    0,    0,11855,
+ 3449,    0, 8076,    0, 8226,  132,  160,    0,    0,    0,
+    0,    0,    0,    0,    0,    0, 1085,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,17545,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,13327,    0,    0,  679,    0,    0,    0,
+  683,    0,    0,    0,15660,    0,    0,    0,14585,  858,
+    0,    0,    0,    0,    0,   54,    0,    0,    0,17545,
+    0,    0,    0, 1077,    0,    0,    0,    0,    0,    0,
+21825,    0, 1076, 1076,    0,   -7,    0,    0,    0,    0,
+    0,    0,  694,    0,    0,    0,    0,13477,  689,    0,
+    0,15887,16037, 5441,16264,21979,13727,10892,11042,11305,
+12117,    0,    0,    0,    0,    0,  695,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   -6,    0,   18,    0,   51,    0,26777,
+ 1093,  699,    0, 1096,    0,  700,    0, 2363, 8603, 8753,
+ 3826, 9130, 9280,  657,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  701,    0,    0,    0,    0,
+    0,13327,16414,    0,  721,    0,    0,  727,16572,    0,
+  512,  512,  512,  512,  512,    0,   94,    0,  512,    0,
+    0,    0,    0, 1077,    0,    0,    0,    0,    0,    0,
+    0,    0,   -7,    0,    0,    0,    0,    0,  737,    0,
+25686,15510,    0,    0,    0,    0,    0,25018,    0,    0,
+    0,    0,    0,    0,  738,    0,  739,    0,    0,    0,
+    0,    0,    0,    0,17707,    0,16414,16727,    0,  683,
+    0,    0,   90,  450,  204,   61,    0,    0,    0,17857,
+    0,22129,    0,    0,    0,    0,    0,    0,    0,    0,
+  753,    0,16985,    0,    0,    0,    0,    0,    0,  754,
+    0,    0,  784,    0,    0,    0,16727,    0,    0,    0,
+    0,    0,22283,    0,    0,  802,    0,22433,    0,    0,
+    0,    0,    0,    0,    0,  804,18019,22587, 1097,    0,
+ 1103,
+};
+short fortrangindex[] = {                                      0,
+    0,    0,    0,  862,  372, -388,    0,  198,    0,  282,
+ -260,    0,  302,  635,  -38,   93,    0,    0,  -21, -301,
+    0,  380,    0,    0, -167,  459, -158, -135, -128,    0,
+    0,  772, -155, -718, -256,    0,   32, -187,    0,  757,
+  265,  485,  411, -194,    0,    0,  -26, -380, -488,    0,
+    0, -174,    0,  -24,    0,    0,    0,    0,    0,  316,
+ -296,    0, -398,    0,    0,    0, 1156,    0,  891,    0,
+  -65,  -79, 1154,    0,    0,   14,    0,    0,    0,    0,
+    0,    0,    0,    0,   99,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  -95,    0,    0,    0,
+    0, 1094,  482,  479,  747,    0,    0,    0,  -52,  645,
+    0, -279,    0,    0,    0, -684,    0, -289,  647,    0,
+  676,    0,  236,    0,    0,    0,    0,  907,  651, -635,
+    0,    0,  481,    0,    0, 1056,  639, -337,  637,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0, -230,
+    0,    0,    0,    0,    0,    0,  632,    0,    0,    0,
+    0,    0,  448,  661,    0, 1061,    0,    0,    0,    0,
+    0,    0,    0, -387,    0,    0,    0,    0,  -60,  447,
+ 1066, -267, -694,    0, -523,    0, -212,    0,    0,    0,
+    0,
+};
+#define YYTABLESIZE 27210
+short fortrantable[] = {                                     200,
+  440,  206,  388,  400,  342,  212,  218,  544,  206,  383,
+  520,  343,  637,  534,  226,   71,  529,  221,  384,  921,
+  391,  387,  230,  448,  224,  108,  234,  285,  393,  236,
+  537,    9,  432,  236,  528,  432,  236,  527,  728,  281,
+  523,  533,   95,  438,  592,  862,  249,  250,  438,  594,
+  592,  886,  592,  236,  257,  763,  432,  291,  739,  765,
+  191,  531,  350,   71,  191,  587,  444,  299,  301,  884,
+  259,  202,  183,  526,  272,  273,  274,  324,  191,  590,
+  296,  890,  891,  303,  260,  202,  183,  757,  587,  333,
+  243,  334,  337,  524,  529,  436,  337,  127,  865,  337,
+  436,  322,  141,  829,  134,  321,  214,  144,  326,  684,
+  206,  146,  216,  703,  205,   30,  278,  240,  241,  282,
+  696,  432,  353,  354,  854,   30,  714,  288,  205,  855,
+  217,  361,  131,  131,  131,  130,  130,  130,  130,  147,
+  130,  417,  451,  418,   89,  203,  376,  697,  698,  213,
+  423,  246,  389,  421,  213,  238,  239,  700,  908,  317,
+  213,  309,  932,  392,  669,  247,  207,  422,  310,  579,
+  401,  701,  402,  401,   30,  402,  420,  210,  424,  761,
+  761,  219,  240,  241,  761,  428,  884,  401,  760,  402,
+  240,  241,  236,  227,  433,  342,  766,  740,  229,  434,
+  403,  514,  343,  403,  231,  342,  236,  388,  577,  389,
+  512,  414,  343,  342,  626,  578,  236,  403,  600,  480,
+  343,  599,  947,  384,  694,  722,  628,  695,  918,  417,
+  722,  418,  237,  414,  412,  244,  413,  734,  425,  248,
+  525,  738,  506,  253,  254,  133,  133,  133,  133,  713,
+  519,  417,  521,  418,  313,  268,  251,  267,  432,  638,
+  531,  432,  437,   89,  258,  445,  549,  446,  449,  266,
+  567,  730,  522,  479,  270,  587,  333,    2,  334,  307,
+  575,  306,  541,  275,  541,  759,  587,  333,  591,  334,
+  878,  587,  333,  513,  334,  588,  589,  553,  554,  590,
+  279,  527,  191,  558,    3,    4,   95,  590,  261,  202,
+  183,  570,  571,  572,  573,  283,  440,  586,  588,  589,
+  288,    5,    6,  590,  290,  127,  337,  337,  295,  530,
+  587,  333,  134,  334,  603,  448,  302,  391,  607,  608,
+  609,  610,  611,  612,  613,  614,  615,  616,  617,  618,
+  619,  550,  205,  484,  416,  555,  502,  629,  933,  438,
+  438,  131,  912,  883,  883,  130,  883,  292,  212,  236,
+  917,   30,  432,  397,  682,  515,  527,  644,  645,  646,
+  647,  648,  649,  650,  651,  652,  653,  654,  655,  656,
+  660,  661,  663,  665,  399,   28,  666,  667,   30,   30,
+  531,  579,  298,  232,  284,  870,  871,  319,  223,  579,
+  233,  436,  436,    7,  536,   30,   30,  323,  341,  593,
+  335,  333,   71,  334,  220,  593,  920,  593,  849,  342,
+  893,  864,  108,  529,  327,  604,  343,  191,  599,  850,
+  577,  415,  416,  843,  202,  183,    8,  578,  577,  312,
+  342,  342,  342,  342,  342,  578,  328,  343,  343,  343,
+  343,  343,  693,  415,  416,  830,  718,  810,  719,  606,
+  832,  384,  599,  384,  384,  133,  805,  807,  729,  671,
+  392,  330,  670,  761,  711,  873,  590,  205,  331,  395,
+  438,  715,  132,  132,  132,  438,  240,  241,  724,  590,
+  590,  590,  590,  590,  754,  588,  589,   30,  854,  852,
+  851,  853,  541,  855,  541,  586,  588,  589,  541,  351,
+  586,  588,  589,  165,  165,  767,  768,  769,  770,  771,
+  427,  357,  414,  412,  883,  413,  149,  314,  150,  753,
+   30,  551,  436,  686,  551,  690,  685,  436,  689,  758,
+  417,  396,  418,  358,  722,  722,  722,  722,  722,  586,
+  588,  589,  722,  899,  919,  313,   89,  716,  429,  550,
+  518,  776,  550,  206,  777,  359,  337,  363,  437,  446,
+  337,  907,  364,  337,  391,  854,  852,  365,  853,  579,
+  855,  366,  367,  368,  857,  913,  914,  915,  916,  337,
+  756,  337,  369,  755,  370,  804,  773,  806,  808,  772,
+  389,  590,  929,  360,  816,  362,  371,  819,  778,  342,
+  372,  599,  779,  898,  794,  599,  343,  599,  577,  373,
+  374,  810,  820,  821,  375,  578,  377,  822,  378,  823,
+  384,  384,  384,  379,  805,  807,  931,  795,  380,  381,
+  599,  827,  816,  796,  797,  798,  599,  599,  599,  430,
+  809,  390,  877,  599,  836,  478,  480,  414,  412,  847,
+  413,  882,  846,  393,  881,  336,  337,  338,  901,  397,
+  339,  896,  845,  398,  482,  417,  402,  418,  472,  903,
+  934,  483,  689,  772,  879,  485,  278,  236,  472,  278,
+  236,  824,  548,  499,  106,  548,  579,  106,  541,  446,
+  211,  500,  448,  211,  446,  448,  834,  504,  516,  241,
+  872,  132,  241,  246,  558,  509,  246,  876,  472,  284,
+  472,  472,  472,  472,  483,  279,  391,  483,  279,  336,
+  328,  107,  336,  328,  107,  577,  518,  472,  472,  472,
+  472,  295,  578,  532,  406,  407,  408,  409,  410,  411,
+  861,  243,  415,  416,  243,  486,  302,  242,  178,  179,
+  242,  535,  545,  546,  804,  806,  808,  480,  334,  335,
+  480,  334,  335,  547,  181,  182,  212,  895,  183,  184,
+  185,  186,  556,  484,  333,  340,  484,  333,  548,  337,
+  337,  337,  187,  337,  337,  337,  337,  337,  337,  178,
+  179,  337,  337,  905,  584,  601,  602,  253,  254,  487,
+  574,  711,  597,  910,  330,  181,  182,  330,  630,  183,
+  184,  185,  186,  631,  632,  621,  622,  623,  624,  625,
+  633,  541,  332,  187,  331,  332,  635,  331,  634,  488,
+  674,  489,  490,  491,  677,  678,  492,  493,  324,  494,
+  495,  680,  683,  681,  688,  565,  691,  687,  333,  940,
+  334,  816,  943,  565,  692,  562,  333,  704,  334,  392,
+  706,  725,  726,  737,  735,  403,  404,  405,  745,  406,
+  407,  408,  409,  410,  411,  204,  223,  415,  416,  748,
+  749,  135,  135,  953,  764,  589,  774,  799,  317,  800,
+  955,  801,  811,  817,  818,  825,  956,  135,  135,  958,
+  826,  135,  135,  135,  135,  188,  838,  831,  149,  833,
+  150,  842,  966,  945,  841,  135,  967,  844,  856,  968,
+  969,  523,  859,  863,  472,  971,  860,  866,  472,  472,
+  472,  867,  472,  472,  472,  472,  472,  472,  869,  497,
+  472,  472,  868,  892,  472,  896,  902,  472,  472,  472,
+  472,  472,  472,  472,  472,  472,  472,  472,  472,  472,
+  472,  472,  472,  472,  472,  924,  740,  926,  472,  472,
+  927,  472,  472,  472,  472,  472,  472,  472,  472,  472,
+  472,  472,  472,  472,  472,  472,  472,  472,  472,  472,
+  472,  472,  472,  472,  472,  472,  472,  472,  930,  935,
+  472,  936,  472,  472,  472,  472,  472,  937,  472,  472,
+  472,  472,  472,  472,  472,  472,  472,  472,  472,  472,
+  472,  472,  472,  472,  938,  939,  944,  855,  472,  472,
+  472,  950,  472,  472,  472,  952,  472,  472,  472,  954,
+  951,  472,  959,  472,  127,  209,  472,  472,  472,  472,
+  961,  962,  472,  472,  472,  920,  108,  472,  472,  472,
+  472,  472,  472,  472,  472,  472,  472,  472,  442,  472,
+  472,  472,  472,  472,  472,  472,  472,  350,  472,  472,
+  472,  472,  526,  472,  472,  472,  563,  350,  414,  412,
+  353,  413,  472,  472,  215,  525,  558,  213,  164,  443,
+  324,  480,  336,  337,  338,  316,  417,  339,  418,  118,
+  336,  337,  338,  353,  350,  339,  325,  540,  350,  350,
+  350,  350,  350,  541,  350,  887,  517,  909,  148,  963,
+  925,  885,  717,  627,  641,  350,  350,  350,  350,  350,
+  942,  828,  875,  911,   15,  511,  143,  256,  835,  837,
+  727,  151,  152,  672,  508,  702,  153,  154,  155,  156,
+  840,  731,  960,  318,  744,  743,  746,  732,  157,  158,
+  159,  160,  161,  162,  163,  164,  874,  165,  166,  167,
+  344,  880,  168,  169,  170,  348,  171,  172,  173,  174,
+  175,    0,  176,    0,    0,  178,  179,  747,    0,    0,
+    0,    0,    0,  178,  179,    0,    0,    0,    0,    0,
+    0,  181,  182,    0,    0,  183,  184,  185,  186,  181,
+  182,    0,  340,  183,  184,  185,  186,    0,    0,  187,
+  564,    0,    0,    0,    0,    0,    0,  187,    0,    0,
+    0,    0,    0,  317,    0,    0,    0,  177,    0,    0,
+    0,    0,    0,  317,    0,  178,  179,    0,    0,    0,
+    0,  180,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  181,  182,    0,    0,  183,  184,  185,  186,    0,
+  317,    0,   89,    0,  317,  317,  317,  317,  317,  187,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  317,  317,  317,  317,  317,    0,    0,  405,    0,
+  406,  407,  408,  409,  410,  411,    0,    0,  415,  416,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  350,    0,    0,    0,  350,  350,  350,
+    0,  350,  350,  350,  350,  350,  350,    0,  350,  350,
+  350,    0,    0,  350,    0,    0,  350,  350,  350,  350,
+  350,  350,  350,    0,    0,  350,  350,  350,    0,    0,
+    0,    0,  350,  350,    0,    0,    0,  350,  350,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  350,    0,
+    0,    0,  350,  350,    0,    0,    0,  350,    0,    0,
+    0,    0,    0,  350,    0,  350,  350,    0,    0,  350,
+    0,  350,  350,  350,  350,  350,    0,  350,  350,  350,
+  350,  350,  350,  350,  350,  350,  350,  350,  350,  350,
+  350,  350,  350,    0,    0,    0,    0,  350,  350,  350,
+    0,  350,  350,  350,    0,  350,  350,  350,    0,    0,
+  350,    0,  350,    0,    0,  350,  350,  350,  350,    0,
+  350,  350,  350,  350,    0,    0,  350,    0,    0,  350,
+  350,  350,  350,  350,  350,  350,  350,    0,  350,  350,
+  350,  350,  350,    0,  188,  350,  538,  149,    0,  150,
+    0,    0,  350,  350,  350,    0,    0,    0,    0,  317,
+    0,  350,  350,  317,  317,  317,    0,  317,  317,  317,
+  317,  317,  317,    0,  317,  317,  317,    0,    0,  317,
+    0,    0,  317,  317,  317,  317,  317,  317,  317,    0,
+    0,  317,  317,  317,    0,    0,    0,    0,  317,  317,
+    0,    0,    0,  317,  317,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  317,    0,    0,    0,  317,  317,
+    0,    0,    0,  317,    0,    0,    0,    0,    0,  317,
+    0,  317,  317,    0,    0,  317,    0,  317,  317,  317,
+  317,  317,    0,  317,  317,  317,  317,  317,  317,  317,
+  317,  317,  317,  317,  317,  317,  317,  317,  317,    0,
+    0,    0,    0,  317,  317,  317,    0,  317,  317,  317,
+    0,  317,  317,  317,    0,    0,  317,    0,  317,    0,
+  313,  317,  317,  317,  317,    0,  317,  317,  317,  317,
+  313,    0,  317,    0,    0,  317,  317,  317,  317,  317,
+  317,  317,  317,    0,  317,  317,  317,  317,  317,    0,
+    0,  317,    0,    0,    0,    0,    0,  313,  317,  317,
+  317,  313,  313,  313,  313,  313,    0,  317,  317,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  313,  313,
+  313,  313,  313,  452,    0,    0,    0,  453,  454,  455,
+  456,    0,    0,    0,    0,    0,    0,    0,    0,  457,
+    0,  458,  459,  460,  461,  462,  463,  148,  464,  465,
+  466,    0,    0,  467,  468,  469,    0,    0,  470,  471,
+  472,  473,    0,  474,    0,    0,    0,    0,    0,    0,
+  151,  152,    0,    0,    0,  153,  154,  155,  156,    0,
+    0,    0,    0,    0,    0,    0,    0,  157,  158,  159,
+  160,  161,  162,  163,  164,    0,  165,  166,  167,    0,
+    0,  168,  169,  170,    0,  171,  172,  173,  174,  175,
+    0,  176,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  108,    0,  314,    0,  108,  108,
+  108,  108,    0,    0,    0,    0,  314,    0,    0,    0,
+  108,    0,  108,  108,  108,  108,  108,  108,    0,  108,
+  108,  108,    0,  475,  108,  108,  108,    0,    0,  108,
+  108,  108,  108,  314,  108,    0,  177,  314,  314,  314,
+  314,  314,    0,    0,  178,  179,    0,    0,    0,    0,
+  180,    0,    0,    0,  314,  314,  314,  314,  314,    0,
+  181,  182,    0,    0,  183,  184,  185,  186,    0,    0,
+    0,  539,    0,    0,    0,    0,    0,    0,  187,    0,
+    0,    0,    0,    0,    0,    0,  313,    0,    0,    0,
+  313,  313,  313,    0,  313,  313,  313,  313,  313,  313,
+    0,  313,  313,  313,    0,    0,  313,    0,    0,  313,
+  313,  313,  313,  313,  313,  313,    0,    0,  313,  313,
+  313,    0,    0,    0,  108,  313,  313,    0,    0,    0,
+  313,  313,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  313,    0,    0,    0,  313,  313,    0,    0,    0,
+  313,    0,    0,    0,    0,    0,  313,    0,  313,  313,
+    0,    0,  313,    0,  313,  313,  313,  313,  313,    0,
+  313,  313,  313,  313,  313,  313,  313,  313,  313,  313,
+  313,  313,  313,  313,  313,  313,    0,  576,    0,    0,
+  313,  313,  313,    0,  313,  313,  313,    0,  313,  313,
+  313,    0,    0,  313,    0,  313,    0,    0,  313,  313,
+  313,  313,    0,  313,  313,  313,  313,    0,    0,  313,
+    0,    0,  313,  313,  313,  313,  313,  313,  313,  313,
+    0,  313,  313,  313,  313,  313,    0,    0,  313,    0,
+    0,    0,    0,    0,    0,  313,  313,  313,    0,  576,
+    0,    0,  314,    0,  313,  313,  314,  314,  314,    0,
+  314,  314,  314,  314,  314,  314,    0,  314,  314,  314,
+    0,    0,  314,    0,    0,  314,  314,  314,  314,  314,
+  314,  314,    0,    0,  314,  314,  314,    0,    0,    0,
+    0,  314,  314,    0,    0,    0,  314,  314,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  314,    0,    0,
+    0,  314,  314,    0,    0,    0,  314,    0,    0,    0,
+    0,    0,  314,    0,  314,  314,    0,    0,  314,    0,
+  314,  314,  314,  314,  314,    0,  314,  314,  314,  314,
+  314,  314,  314,  314,  314,  314,  314,  314,  314,  314,
+  314,  314,    0,    0,    0,    0,  314,  314,  314,    0,
+  314,  314,  314,    0,  314,  314,  314,    0,    0,  314,
+    0,  314,    0,    0,  314,  314,  314,  314,    0,  314,
+  314,  314,  314,    0,    0,  314,  322,    0,  314,  314,
+  314,  314,  314,  314,  314,  314,  322,  314,  314,  314,
+  314,  314,    0,    0,  314,  414,  412,  676,  413,    0,
+    0,  314,  314,  314,    0,    0,    0,    0,    0,    0,
+  314,  314,    0,  417,  402,  418,  322,  322,  322,  322,
+  322,  322,    0,  151,  152,    0,    0,    0,  153,  154,
+  155,  156,    0,    0,  322,  322,  322,  322,  322,    0,
+  157,  158,  159,  160,  161,  162,  163,  164,    0,  165,
+  166,  167,    0,    0,  168,  169,  170,    0,  171,  172,
+  173,  174,  175,    0,  176,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  151,  152,    0,    0,    0,
+  153,  154,  155,  156,    0,    0,    0,    0,    0,    0,
+    0,    0,  157,  158,  159,  160,  161,  162,  163,  164,
+    0,  165,  166,  167,    0,    0,  168,  169,  170,    0,
+  171,  172,  173,  174,  175,    0,  176,  178,  179,    0,
+    0,    0,    0,  180,    0,    0,    0,    0,    0,    0,
+    0,    0,  319,  181,  182,    0,    0,  183,  184,  185,
+  186,    0,  319,    0,   89,    0,    0,    0,    0,    0,
+    0,  187,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  319,
+    0,    0,    0,  319,  319,  319,  319,  319,    0,  178,
+  179,    0,    0,    0,    0,  180,    0,    0,    0,    0,
+  319,  319,  319,  319,  319,  181,  182,    0,    0,  183,
+  184,  185,  186,  403,  404,  405,  888,  406,  407,  408,
+  409,  410,  411,  187,    0,  415,  416,    0,    0,    0,
+    0,    0,  322,    0,    0,    0,  322,  322,  322,    0,
+  322,  322,  322,  322,  322,  322,    0,  322,  322,  322,
+    0,    0,  322,    0,    0,  322,  322,  322,  322,  322,
+  322,  322,    0,    0,  322,  322,  322,    0,    0,    0,
+    0,  322,  322,    0,    0,    0,  322,  322,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  322,    0,    0,
+    0,  322,  322,    0,    0,    0,  322,    0,    0,    0,
+    0,    0,  322,    0,  322,  322,    0,    0,  322,    0,
+  322,  322,  322,  322,  322,    0,  322,  322,  322,  322,
+  322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
+  322,  322,    0,    0,    0,    0,  322,  322,  322,    0,
+  322,  322,  322,    0,  322,  322,  322,    0,    0,  322,
+    0,  322,    0,    0,  322,  322,  322,  322,    0,  322,
+  322,  322,  322,    0,    0,  322,    0,    0,  322,  322,
+  322,  322,  322,  322,  322,  322,    0,  322,  322,  322,
+  322,  322,    0,  188,  322,  557,  149,    0,  150,    0,
+    0,  322,  322,  322,    0,    0,    0,    0,  319,    0,
+  322,  322,  319,  319,  319,    0,  319,  319,  319,  319,
+  319,  319,    0,  319,  319,  319,    0,    0,  319,    0,
+    0,  319,  319,  319,  319,  319,  319,  319,    0,    0,
+  319,  319,  319,    0,    0,    0,    0,  319,  319,    0,
+    0,    0,  319,  319,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  319,    0,    0,    0,  319,  319,    0,
+    0,    0,  319,    0,    0,    0,    0,    0,  319,    0,
+  319,  319,    0,    0,  319,    0,  319,  319,  319,  319,
+  319,    0,  319,  319,  319,  319,  319,  319,  319,  319,
+  319,  319,  319,  319,  319,  319,  319,  319,    0,    0,
+    0,    0,  319,  319,  319,    0,  319,  319,  319,    0,
+  319,  319,  319,    0,    0,  319,    0,  319,    0,  280,
+  319,  319,  319,  319,    0,  319,  319,  319,  319,  280,
+    0,  319,    0,    0,  319,  319,  319,  319,  319,  319,
+  319,  319,    0,  319,  319,  319,  319,  319,    0,    0,
+  319,    0,    0,    0,    0,    0,    0,  319,  319,  319,
+  280,  280,  280,  280,  280,    0,  319,  319,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  280,  280,  280,
+  280,  280,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  148,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  151,
+  152,    0,    0,    0,  153,  154,  155,  156,    0,    0,
+    0,    0,    0,    0,    0,    0,  157,  158,  159,  160,
+  161,  162,  163,  164,    0,  165,  166,  167,    0,    0,
+  168,  169,  170,    0,  171,  172,  173,  174,  175,    0,
+  176,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  281,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  281,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  281,    0,    0,  177,  281,  281,  281,  281,
+  281,    0,    0,  178,  179,    0,    0,    0,    0,  180,
+    0,    0,    0,  281,  281,  281,  281,  281,    0,  181,
+  182,    0,    0,  183,  184,  185,  186,    0,    0,    0,
+   89,    0,    0,    0,    0,    0,    0,  187,    0,    0,
+    0,    0,    0,    0,    0,  280,    0,    0,    0,  280,
+  280,  280,    0,  280,  280,  280,  280,  280,  280,    0,
+  280,  280,  280,    0,    0,  280,    0,    0,  280,  280,
+  280,  280,  280,  280,  280,    0,    0,  280,  280,  280,
+    0,    0,    0,    0,  280,  280,    0,    0,    0,  280,
+  280,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  280,    0,    0,    0,  280,  280,    0,    0,    0,  280,
+    0,    0,    0,    0,    0,  280,    0,  280,  280,    0,
+    0,  280,    0,  280,  280,  280,  280,  280,    0,  280,
+  280,  280,  280,  280,  280,  280,  280,  280,  280,  280,
+  280,  280,  280,  280,  280,    0,    0,    0,    0,  280,
+  280,  280,    0,  280,  280,  280,    0,  280,  280,  280,
+    0,    0,  280,    0,  280,    0,    0,  280,  280,  280,
+  280,    0,  280,  280,  280,  280,    0,    0,  280,    0,
+    0,  280,  280,  280,  280,  280,  280,  280,  280,    0,
+  280,  280,  280,  280,  280,    0,  188,  280,  705,  149,
+    0,  150,    0,    0,  280,  280,  280,    0,    0,    0,
+    0,  281,    0,  280,  280,  281,  281,  281,    0,  281,
+  281,  281,  281,  281,  281,    0,  281,  281,  281,    0,
+    0,  281,    0,    0,  281,  281,  281,  281,  281,  281,
+  281,    0,    0,  281,  281,  281,    0,    0,    0,    0,
+  281,  281,    0,    0,    0,  281,  281,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  281,    0,    0,    0,
+  281,  281,    0,    0,    0,  281,    0,    0,    0,    0,
+    0,  281,    0,  281,  281,    0,    0,  281,    0,  281,
+  281,  281,  281,  281,    0,  281,  281,  281,  281,  281,
+  281,  281,  281,  281,  281,  281,  281,  281,  281,  281,
+  281,    0,    0,    0,    0,  281,  281,  281,    0,  281,
+  281,  281,    0,  281,  281,  281,    0,    0,  281,    0,
+  281,    0,  290,  281,  281,  281,  281,    0,  281,  281,
+  281,  281,  290,    0,  281,    0,    0,  281,  281,  281,
+  281,  281,  281,  281,  281,    0,  281,  281,  281,  281,
+  281,    0,    0,  281,    0,    0,    0,    0,    0,  290,
+  281,  281,    0,  290,  290,  290,  290,  290,    0,  281,
+  281,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  290,  290,    0,  290,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  148,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  151,  152,    0,    0,    0,  153,  154,  155,
+  156,    0,    0,    0,    0,    0,    0,    0,    0,  157,
+  158,  159,  160,  161,  162,  163,  164,    0,  165,  166,
+  167,    0,    0,  168,  169,  170,    0,  171,  172,  173,
+  174,  175,    0,  176,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  291,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  291,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  291,    0,    0,  177,  291,
+  291,  291,  291,  291,    0,    0,  178,  179,    0,    0,
+    0,    0,  180,    0,    0,    0,  291,  291,    0,  291,
+    0,    0,  181,  182,    0,    0,  183,  184,  185,  186,
+    0,    0,    0,   89,    0,    0,    0,    0,    0,    0,
+  187,    0,    0,    0,    0,    0,    0,    0,  290,    0,
+    0,    0,  290,  290,  290,    0,  290,  290,  290,  290,
+  290,  290,    0,  290,  290,    0,    0,    0,  290,    0,
+    0,  290,  290,  290,  290,  290,  290,  290,    0,    0,
+  290,  290,  290,    0,    0,    0,    0,  290,  290,    0,
+    0,    0,  290,  290,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  290,    0,    0,    0,  290,  290,    0,
+    0,    0,  290,    0,    0,    0,    0,    0,  290,    0,
+  290,  290,    0,    0,  290,    0,  290,  290,  290,  290,
+  290,    0,  290,  290,  290,  290,  290,  290,  290,  290,
+  290,  290,  290,  290,  290,  290,  290,  290,    0,    0,
+    0,    0,  290,  290,  290,    0,  290,  290,  290,    0,
+  290,  290,  290,    0,    0,  290,    0,  290,    0,    0,
+  290,  290,  290,  290,    0,  290,  290,  290,  290,    0,
+    0,  290,    0,    0,  290,  290,  290,  290,  290,  290,
+  290,  290,    0,  290,  290,  290,  290,  290,    0,  188,
+  290,  538,  149,    0,  150,    0,    0,  290,  290,  290,
+    0,    0,    0,    0,  291,    0,  290,  290,  291,  291,
+  291,    0,  291,  291,  291,  291,  291,  291,    0,  291,
+  291,    0,    0,    0,  291,    0,    0,  291,  291,  291,
+  291,  291,  291,  291,    0,    0,  291,  291,  291,    0,
+    0,    0,    0,  291,  291,    0,    0,    0,  291,  291,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  291,
+    0,    0,    0,  291,  291,    0,    0,    0,  291,    0,
+    0,    0,    0,    0,  291,    0,  291,  291,    0,    0,
+  291,    0,  291,  291,  291,  291,  291,    0,  291,  291,
+  291,  291,  291,  291,  291,  291,  291,  291,  291,  291,
+  291,  291,  291,  291,    0,    0,    0,    0,  291,  291,
+  291,    0,  291,  291,  291,    0,  291,  291,  291,    0,
+    0,  291,    0,  291,    0,  310,  291,  291,  291,  291,
+    0,  291,  291,  291,  291,  310,    0,  291,    0,    0,
+  291,  291,  291,  291,  291,  291,  291,  291,    0,  291,
+  291,  291,  291,  291,    0,    0,  291,    0,    0,    0,
+    0,    0,  310,  291,  291,  291,  310,  310,  310,  310,
+  310,    0,  291,  291,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  310,  310,    0,  310,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  148,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  151,  152,    0,    0,    0,
+  153,  154,  155,  156,    0,    0,    0,    0,    0,    0,
+    0,    0,  157,  158,  159,  160,  161,  162,  163,  164,
+    0,  165,  166,  167,    0,    0,  168,  169,  170,    0,
+  171,  172,  173,  174,  175,    0,  176,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  516,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  516,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  177,  516,  516,  516,  516,  516,    0,    0,  178,
+  179,    0,    0,    0,    0,  180,    0,    0,    0,    0,
+  516,  516,  516,  516,    0,  181,  182,    0,    0,  183,
+  184,  185,  186,    0,    0,    0,   89,    0,    0,    0,
+    0,    0,    0,  187,    0,    0,    0,    0,    0,    0,
+    0,  310,    0,    0,    0,  310,  310,  310,    0,  310,
+  310,  310,  310,  310,  310,    0,  310,  310,    0,    0,
+    0,  310,    0,    0,  310,  310,  310,  310,  310,  310,
+  310,    0,    0,  310,  310,  310,    0,    0,    0,    0,
+  310,  310,    0,    0,    0,  310,  310,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  310,    0,    0,    0,
+  310,  310,    0,    0,    0,  310,    0,    0,    0,    0,
+    0,  310,    0,  310,  310,    0,    0,  310,    0,  310,
+  310,  310,  310,  310,    0,  310,  310,  310,  310,  310,
+  310,  310,  310,  310,  310,  310,  310,  310,  310,  310,
+  310,    0,    0,    0,    0,  310,  310,  310,    0,  310,
+  310,  310,    0,  310,  310,  310,    0,    0,  310,    0,
+  310,    0,    0,  310,  310,  310,  310,    0,  310,  310,
+  310,  310,    0,    0,  310,    0,    0,  310,  310,  310,
+  310,  310,  310,  310,  310,    0,  310,  310,  310,  310,
+  310,    0,  188,  310,  708,  149,    0,  150,    0,    0,
+  310,  310,  310,    0,    0,    0,    0,  516,    0,  310,
+  310,  516,  516,  516,    0,  516,  516,  516,  516,  516,
+  516,    0,    0,  516,  516,    0,    0,  516,    0,    0,
+  516,  516,  516,  516,  516,  516,  516,    0,    0,  516,
+  516,  516,    0,    0,    0,    0,  516,  516,    0,    0,
+    0,  516,  516,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  516,    0,    0,    0,  516,  516,    0,    0,
+    0,  516,    0,    0,    0,    0,    0,  516,    0,  516,
+  516,    0,    0,  516,    0,  516,  516,  516,  516,  516,
+    0,  516,  516,  516,  516,  516,  516,  516,  516,  516,
+  516,  516,  516,  516,  516,  516,  516,    0,    0,    0,
+    0,  516,  516,  516,    0,  516,  516,  516,    0,  516,
+  516,  516,    0,    0,  516,    0,  516,    0,  288,  516,
+  516,  516,  516,    0,    0,  516,  516,  516,  288,    0,
+  516,    0,    0,  516,  516,  516,  516,  516,  516,  516,
+  516,    0,  516,  516,  516,  516,  516,    0,    0,  516,
+    0,    0,    0,    0,    0,  288,  516,  516,  516,  288,
+    0,  288,  288,  288,    0,  516,  516,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  288,  288,    0,  288,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  148,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  151,  152,
+    0,    0,    0,  153,  154,  155,  156,    0,    0,    0,
+    0,    0,    0,    0,    0,  157,  158,  159,  160,  161,
+  162,  163,  164,    0,  165,  166,  167,    0,    0,  168,
+  169,  170,    0,  171,  172,  173,  174,  175,    0,  176,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  289,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  289,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  289,    0,    0,  177,  289,    0,  289,  289,  289,
+    0,    0,  178,  179,    0,    0,    0,    0,  180,    0,
+    0,    0,  289,  289,    0,  289,    0,    0,  181,  182,
+    0,    0,  183,  184,  185,  186,    0,    0,    0,   89,
+    0,    0,    0,    0,    0,    0,  187,    0,    0,    0,
+    0,    0,    0,    0,  288,    0,    0,    0,  288,  288,
+  288,    0,  288,  288,  288,  288,  288,  288,    0,  288,
+    0,    0,    0,    0,  288,    0,    0,  288,  288,  288,
+  288,  288,  288,  288,    0,    0,  288,  288,  288,    0,
+    0,    0,    0,  288,  288,    0,    0,    0,  288,  288,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  288,
+    0,    0,    0,  288,  288,    0,    0,    0,  288,    0,
+    0,    0,    0,    0,  288,    0,  288,  288,    0,    0,
+  288,    0,  288,  288,  288,  288,  288,    0,  288,  288,
+  288,  288,  288,  288,  288,  288,  288,  288,  288,  288,
+  288,  288,  288,  288,    0,    0,    0,    0,  288,  288,
+  288,    0,  288,  288,  288,    0,  288,  288,  288,    0,
+    0,  288,    0,  288,    0,    0,  288,  288,  288,  288,
+    0,  288,  288,  288,  288,    0,    0,  288,    0,    0,
+  288,  288,  288,  288,  288,  288,  288,  288,    0,  288,
+  288,  288,  288,  288,    0,    0,  288,    0,    0,    0,
+    0,    0,    0,  288,  288,  288,    0,    0,  414,  412,
+  289,  413,  288,  288,  289,  289,  289,    0,  289,  289,
+  289,  289,  289,  289,    0,  289,  417,  402,  418,    0,
+  289,    0,    0,  289,  289,  289,  289,  289,  289,  289,
+    0,    0,  289,  289,  289,    0,    0,    0,    0,  289,
+  289,    0,    0,    0,  289,  289,    0,    0,  340,  340,
+    0,  340,    0,    0,    0,  289,    0,    0,    0,  289,
+  289,    0,    0,    0,  289,    0,  340,  340,  340,    0,
+  289,    0,  289,  289,    0,    0,  289,    0,  289,  289,
+  289,  289,  289,    0,  289,  289,  289,  289,  289,  289,
+  289,  289,  289,  289,  289,  289,  289,  289,  289,  289,
+    0,    0,    0,    0,  289,  289,  289,    0,  289,  289,
+  289,    0,  289,  289,  289,    0,    0,  289,    0,  289,
+    0,  307,  289,  289,  289,  289,    0,  289,  289,  289,
+  289,  307,    0,  289,    0,    0,  289,  289,  289,  289,
+  289,  289,  289,  289,    0,  289,  289,  289,  289,  289,
+    0,    0,  289,    0,    0,    0,    0,    0,  307,  289,
+  289,  289,  307,  307,    0,  307,    0,    0,  289,  289,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  307,
+  307,  307,    0,  307,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  403,  404,  405,    0,
+  406,  407,  408,  409,  410,  411,    0,    0,  415,  416,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,   20,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,   26,  340,  340,  340,    0,
+  340,  340,  340,  340,  340,  340,    0,    0,  340,  340,
+   30,    0,    0,  463,    0,    0,   33,  314,    0,    0,
+    0,   37,   38,  463,    0,    0,    0,    0,    0,    0,
+    0,  315,   47,   48,   49,   50,   51,   52,  316,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   62,    0,  515,  515,  515,  515,   65,
+    0,    0,    0,    0,    0,    0,    0,    0,   70,    0,
+   72,    0,  463,  515,  515,  515,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,   89,    0,  396,    0,    0,    0,  307,   90,    0,
+    0,  307,  307,  307,    0,  307,  307,  307,  307,  307,
+  307,    0,  307,    0,  307,    0,    0,  307,    0,    0,
+  307,  307,  307,  307,  307,  307,  307,    0,    0,  307,
+  307,  307,    0,    0,    0,    0,  307,  307,    0,    0,
+    0,  307,  307,  340,    0,    0,    0,    0,    0,    0,
+    0,    0,  307,    0,    0,    0,  307,  307,    0,    0,
+    0,  307,    0,    0,    0,    0,    0,  307,    0,  307,
+  307,    0,    0,  307,    0,  307,  307,  307,  307,  307,
+    0,  307,  307,  307,  307,  307,  307,  307,  307,  307,
+  307,  307,  307,  307,  307,  307,  307,    0,    0,    0,
+    0,  307,  307,  307,    0,  307,  307,  307,    0,  307,
+  307,  307,    0,    0,  307,    0,  307,    0,    0,  307,
+  307,  307,  307,    0,  307,  307,  307,  307,    0,    0,
+  307,    0,    0,  307,  307,  307,  307,    0,  307,  307,
+  307,    0,  307,  307,  307,  307,  307,    0,    0,  307,
+    0,    0,    0,    0,    0,    0,  307,  307,    0,  463,
+    0,    0,    0,  515,  515,  515,  307,  515,  515,  515,
+  515,  515,  515,    0,    0,  515,  515,  247,  247,  463,
+  247,    0,  463,  463,  463,  463,  463,  463,  463,    0,
+    0,  463,  463,  463,    0,  247,  247,  247,  463,  463,
+    0,    0,    0,  463,  463,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  463,    0,    0,    0,  463,  463,
+    0,    0,    0,  463,    0,    0,    0,    0,    0,  463,
+    0,  463,  463,    0,    0,  463,    0,  463,  463,  463,
+  463,  463,    0,  463,  463,  463,  463,  463,  463,  463,
+  463,  463,  463,  463,  463,  463,  463,  463,  463,    0,
+    0,    0,    0,  463,  463,  463,    0,  463,  463,  463,
+  515,  463,  463,  463,    0,    0,  463,    0,  463,    0,
+  515,  463,  463,  463,  463,    0,    0,  463,  463,  463,
+    0,    0,  463,    0,    0,  463,  463,  463,  463,    0,
+  463,  463,  463,    0,  463,  463,  463,  463,  463,    0,
+    0,  463,  515,  515,  515,  515,    0,    0,  463,  463,
+    0,    0,    0,    0,    0,    0,    0,    0,  463,  515,
+  515,  515,  515,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  247,  247,  247,    0,  247,
+  247,  247,  247,  247,  247,    0,    0,  247,  247,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  337,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  337,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  337,    0,    0,
+  337,  337,  337,  337,  337,  337,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  337,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  533,    0,
+    0,    0,    0,    0,    0,    0,  515,    0,    0,    0,
+  515,  515,  515,    0,  515,  515,  515,  515,  515,  515,
+    0,    0,  515,  515,    0,    0,  515,    0,    0,  515,
+  515,  515,  515,  515,  515,  515,    0,    0,  515,  515,
+  515,    0,    0,    0,    0,  515,  515,    0,    0,    0,
+  515,  515,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  515,    0,    0,    0,  515,  515,    0,    0,    0,
+  515,    0,    0,    0,    0,    0,  515,    0,  515,  515,
+    0,    0,  515,    0,  515,  515,  515,  515,  515,    0,
+  515,  515,  515,  515,  515,  515,  515,  515,  515,  515,
+  515,  515,  515,  515,  515,  515,    0,    0,    0,    0,
+  515,  515,  515,    0,  515,  515,  515,    0,  515,  515,
+  515,    0,    0,  515,    0,  515,    0,    0,  515,  515,
+  515,  515,    0,    0,  515,  515,  515,    0,    0,  515,
+    0,    0,  515,  515,  515,  515,    0,  515,  515,  515,
+    0,  515,  515,  515,  515,  515,  337,    0,  515,    0,
+    0,    0,    0,    0,    0,  515,  515,    0,    0,    0,
+    0,  337,  337,  337,    0,  515,  337,    0,    0,  337,
+  337,  337,  337,  337,  337,  337,    0,    0,  337,  337,
+  337,    0,    0,    0,    0,  337,  337,    0,    0,    0,
+  337,  337,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  337,    0,    0,    0,  337,  337,    0,    0,    0,
+  337,    0,    0,    0,    0,    0,  337,    0,  337,  337,
+    0,    0,  337,    0,  337,  337,  337,  337,  337,    0,
+  337,  337,  337,  337,  337,  337,  337,  337,  337,  337,
+  337,  337,  337,  337,  337,  337,    0,    0,    0,    0,
+  337,  337,  337,    0,  337,  337,  337,    0,  337,  337,
+  337,    0,    0,  337,    0,  337,    0,  285,  337,  337,
+  337,  337,    0,    0,  337,  337,  337,  285,    0,  337,
+    0,    0,  337,  337,  337,  337,  337,  337,  337,  337,
+    0,  337,  337,  337,  337,  337,    0,    0,  337,    0,
+    0,    0,    0,    0,  285,  337,  337,  337,  285,    0,
+    0,  285,    0,    0,  337,  337,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  285,  285,    0,  285,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  304,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  304,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  304,    0,    0,    0,  304,    0,
+    0,  304,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  304,  304,    0,  304,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  285,    0,    0,    0,  285,  285,  285,
+    0,    0,    0,    0,    0,    0,    0,    0,  285,    0,
+    0,    0,    0,  285,    0,    0,  285,  285,  285,  285,
+  285,  285,  285,    0,    0,  285,  285,  285,    0,    0,
+    0,    0,  285,  285,    0,    0,    0,  285,  285,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  285,    0,
+    0,    0,  285,  285,    0,    0,    0,  285,    0,    0,
+    0,    0,    0,  285,    0,  285,  285,    0,    0,  285,
+    0,  285,  285,  285,  285,  285,    0,  285,  285,  285,
+  285,  285,  285,  285,  285,  285,  285,  285,  285,  285,
+  285,  285,  285,    0,    0,    0,    0,  285,  285,  285,
+    0,  285,  285,  285,    0,  285,  285,  285,    0,    0,
+  285,    0,  285,    0,    0,  285,  285,  285,  285,    0,
+  285,  285,  285,  285,    0,    0,  285,    0,    0,  285,
+  285,  285,  285,  285,  285,  285,  285,    0,  285,  285,
+  285,  285,  285,  304,    0,  285,    0,  304,  304,  304,
+    0,    0,  285,  285,  285,    0,    0,    0,  304,    0,
+    0,  285,  285,  304,    0,    0,  304,  304,  304,  304,
+  304,  304,  304,    0,    0,  304,  304,  304,    0,    0,
+    0,    0,  304,  304,    0,    0,    0,  304,  304,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  304,    0,
+    0,    0,  304,  304,    0,    0,    0,  304,    0,    0,
+    0,    0,    0,  304,    0,  304,  304,    0,    0,  304,
+    0,  304,  304,  304,  304,  304,    0,  304,  304,  304,
+  304,  304,  304,  304,  304,  304,  304,  304,  304,  304,
+  304,  304,  304,    0,    0,    0,    0,  304,  304,  304,
+    0,  304,  304,  304,    0,  304,  304,  304,    0,    0,
+  304,    0,  304,    0,  295,  304,  304,  304,  304,    0,
+  304,  304,  304,  304,  295,    0,  304,    0,    0,  304,
+  304,  304,  304,  304,  304,  304,  304,    0,  304,  304,
+  304,  304,  304,    0,    0,  304,    0,    0,    0,    0,
+    0,  295,  304,  304,  304,  295,    0,    0,  295,    0,
+    0,  304,  304,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  295,  295,    0,  295,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  293,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  293,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  293,    0,    0,    0,  293,    0,    0,  293,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  293,  293,    0,  293,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  295,    0,    0,    0,  295,  295,  295,    0,    0,    0,
+    0,    0,    0,    0,    0,  295,    0,    0,    0,    0,
+  295,    0,    0,  295,  295,  295,  295,  295,  295,  295,
+    0,    0,  295,  295,  295,    0,    0,    0,    0,  295,
+  295,    0,    0,    0,  295,  295,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  295,    0,    0,    0,  295,
+  295,    0,    0,    0,  295,    0,    0,    0,    0,    0,
+  295,    0,  295,  295,    0,    0,  295,    0,  295,  295,
+  295,  295,  295,    0,  295,  295,  295,  295,  295,  295,
+  295,  295,  295,  295,  295,  295,  295,  295,  295,  295,
+    0,    0,    0,    0,  295,  295,  295,    0,  295,  295,
+  295,    0,  295,  295,  295,    0,    0,  295,    0,  295,
+    0,    0,  295,  295,  295,  295,    0,  295,  295,  295,
+  295,    0,    0,  295,    0,    0,  295,  295,  295,  295,
+  295,  295,  295,  295,    0,  295,  295,  295,  295,  295,
+  293,    0,  295,    0,  293,  293,  293,    0,    0,  295,
+  295,  295,    0,    0,    0,  293,    0,    0,  295,  295,
+  293,    0,    0,  293,  293,  293,  293,  293,  293,  293,
+    0,    0,  293,  293,  293,    0,    0,    0,    0,  293,
+  293,    0,    0,    0,  293,  293,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  293,    0,    0,    0,  293,
+  293,    0,    0,    0,  293,    0,    0,    0,    0,    0,
+  293,    0,  293,  293,    0,    0,  293,    0,  293,  293,
+  293,  293,  293,    0,  293,  293,  293,  293,  293,  293,
+  293,  293,  293,  293,  293,  293,  293,  293,  293,  293,
+    0,    0,    0,    0,  293,  293,  293,    0,  293,  293,
+  293,    0,  293,  293,  293,    0,    0,  293,    0,  293,
+    0,  299,  293,  293,  293,  293,    0,  293,  293,  293,
+  293,  299,    0,  293,    0,    0,  293,  293,  293,  293,
+  293,  293,  293,  293,    0,  293,  293,  293,  293,  293,
+    0,    0,  293,    0,    0,    0,    0,    0,  299,  293,
+  293,  293,  299,    0,    0,  299,    0,    0,  293,  293,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  299,
+  299,    0,  299,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  297,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  297,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  297,    0,
+    0,    0,  297,    0,    0,  297,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  297,
+  297,    0,  297,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  299,    0,    0,
+    0,  299,  299,  299,    0,    0,    0,    0,    0,    0,
+    0,    0,  299,    0,    0,    0,    0,  299,    0,    0,
+  299,  299,  299,  299,  299,  299,  299,    0,    0,  299,
+  299,  299,    0,    0,    0,    0,  299,  299,    0,    0,
+    0,  299,  299,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  299,    0,    0,    0,  299,  299,    0,    0,
+    0,  299,    0,    0,    0,    0,    0,  299,    0,  299,
+  299,    0,    0,  299,    0,  299,  299,  299,  299,  299,
+    0,  299,  299,  299,  299,  299,  299,  299,  299,  299,
+  299,  299,  299,  299,  299,  299,  299,    0,    0,    0,
+    0,  299,  299,  299,    0,  299,  299,  299,    0,  299,
+  299,  299,    0,    0,  299,    0,  299,    0,    0,  299,
+  299,  299,  299,    0,  299,  299,  299,  299,    0,    0,
+  299,    0,    0,  299,  299,  299,  299,  299,  299,  299,
+  299,    0,  299,  299,  299,  299,  299,  297,    0,  299,
+    0,  297,  297,  297,    0,    0,  299,  299,  299,    0,
+    0,    0,  297,    0,    0,  299,  299,  297,    0,    0,
+  297,  297,  297,  297,  297,  297,  297,    0,    0,  297,
+  297,  297,    0,    0,    0,    0,  297,  297,    0,    0,
+    0,  297,  297,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  297,    0,    0,    0,  297,  297,    0,    0,
+    0,  297,    0,    0,    0,    0,    0,  297,    0,  297,
+  297,    0,    0,  297,    0,  297,  297,  297,  297,  297,
+    0,  297,  297,  297,  297,  297,  297,  297,  297,  297,
+  297,  297,  297,  297,  297,  297,  297,    0,    0,    0,
+    0,  297,  297,  297,    0,  297,  297,  297,    0,  297,
+  297,  297,    0,    0,  297,    0,  297,    0,  292,  297,
+  297,  297,  297,    0,  297,  297,  297,  297,  292,    0,
+  297,    0,    0,  297,  297,  297,  297,  297,  297,  297,
+  297,    0,  297,  297,  297,  297,  297,    0,    0,  297,
+    0,    0,    0,    0,    0,  292,  297,  297,  297,  292,
+    0,    0,  292,    0,    0,  297,  297,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  292,  292,    0,  292,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  301,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  301,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  301,    0,    0,    0,  301,
+    0,    0,  301,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  301,  301,    0,  301,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  292,    0,    0,    0,  292,  292,
+  292,    0,    0,    0,    0,    0,    0,    0,    0,  292,
+    0,    0,    0,    0,  292,    0,    0,  292,  292,  292,
+  292,  292,  292,  292,    0,    0,  292,  292,  292,    0,
+    0,    0,    0,  292,  292,    0,    0,    0,  292,  292,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  292,
+    0,    0,    0,  292,  292,    0,    0,    0,  292,    0,
+    0,    0,    0,    0,  292,    0,  292,  292,    0,    0,
+  292,    0,  292,  292,  292,  292,  292,    0,  292,  292,
+  292,  292,  292,  292,  292,  292,  292,  292,  292,  292,
+  292,  292,  292,  292,    0,    0,    0,    0,  292,  292,
+  292,    0,  292,  292,  292,    0,  292,  292,  292,    0,
+    0,  292,    0,  292,    0,    0,  292,  292,  292,  292,
+    0,  292,  292,  292,  292,    0,    0,  292,    0,    0,
+  292,  292,  292,  292,  292,  292,  292,  292,    0,  292,
+  292,  292,  292,  292,  301,    0,  292,    0,  301,  301,
+  301,    0,    0,  292,  292,  292,    0,    0,    0,  301,
+    0,    0,  292,  292,  301,    0,    0,  301,  301,  301,
+  301,  301,  301,  301,    0,    0,  301,  301,  301,    0,
+    0,    0,    0,  301,  301,    0,    0,    0,  301,  301,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  301,
+    0,    0,    0,  301,  301,    0,    0,    0,  301,    0,
+    0,    0,    0,    0,  301,    0,  301,  301,    0,    0,
+  301,    0,  301,  301,  301,  301,  301,    0,  301,  301,
+  301,  301,  301,  301,  301,  301,  301,  301,  301,  301,
+  301,  301,  301,  301,    0,    0,    0,    0,  301,  301,
+  301,    0,  301,  301,  301,    0,  301,  301,  301,    0,
+    0,  301,    0,  301,    0,  296,  301,  301,  301,  301,
+    0,  301,  301,  301,  301,  296,    0,  301,    0,    0,
+  301,  301,  301,  301,  301,  301,  301,  301,    0,  301,
+  301,  301,  301,  301,    0,    0,  301,    0,    0,    0,
+    0,    0,  296,  301,  301,  301,  296,    0,    0,  296,
+    0,    0,  301,  301,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  296,  296,    0,  296,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  294,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  294,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  294,    0,    0,    0,  294,    0,    0,  294,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  294,  294,    0,  294,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  296,    0,    0,    0,  296,  296,  296,    0,    0,
+    0,    0,    0,    0,    0,    0,  296,    0,    0,    0,
+    0,  296,    0,    0,  296,  296,  296,  296,  296,  296,
+  296,    0,    0,  296,  296,  296,    0,    0,    0,    0,
+  296,  296,    0,    0,    0,  296,  296,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  296,    0,    0,    0,
+  296,  296,    0,    0,    0,  296,    0,    0,    0,    0,
+    0,  296,    0,  296,  296,    0,    0,  296,    0,  296,
+  296,  296,  296,  296,    0,  296,  296,  296,  296,  296,
+  296,  296,  296,  296,  296,  296,  296,  296,  296,  296,
+  296,    0,    0,    0,    0,  296,  296,  296,    0,  296,
+  296,  296,    0,  296,  296,  296,    0,    0,  296,    0,
+  296,    0,    0,  296,  296,  296,  296,    0,  296,  296,
+  296,  296,    0,    0,  296,    0,    0,  296,  296,  296,
+  296,  296,  296,  296,  296,    0,  296,  296,  296,  296,
+  296,  294,    0,  296,    0,  294,  294,  294,    0,    0,
+  296,  296,  296,    0,    0,    0,  294,    0,    0,  296,
+  296,  294,    0,    0,  294,  294,  294,  294,  294,  294,
+  294,    0,    0,  294,  294,  294,    0,    0,    0,    0,
+  294,  294,    0,    0,    0,  294,  294,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  294,    0,    0,    0,
+  294,  294,    0,    0,    0,  294,    0,    0,    0,    0,
+    0,  294,    0,  294,  294,    0,    0,  294,    0,  294,
+  294,  294,  294,  294,    0,  294,  294,  294,  294,  294,
+  294,  294,  294,  294,  294,  294,  294,  294,  294,  294,
+  294,    0,    0,    0,    0,  294,  294,  294,    0,  294,
+  294,  294,    0,  294,  294,  294,    0,    0,  294,    0,
+  294,    0,  311,  294,  294,  294,  294,    0,  294,  294,
+  294,  294,  311,    0,  294,    0,    0,  294,  294,  294,
+  294,  294,  294,  294,  294,    0,  294,  294,  294,  294,
+  294,    0,    0,  294,    0,    0,    0,    0,    0,  311,
+  294,  294,  294,  311,    0,    0,  311,    0,    0,  294,
+  294,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  311,  311,    0,  311,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  309,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  309,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  309,
+    0,    0,    0,  309,    0,    0,  309,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  309,  309,    0,  309,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  311,    0,
+    0,    0,  311,  311,  311,    0,    0,    0,    0,    0,
+    0,    0,    0,  311,    0,    0,    0,    0,  311,    0,
+    0,  311,  311,  311,  311,  311,  311,  311,    0,    0,
+  311,  311,  311,    0,    0,    0,    0,  311,  311,    0,
+    0,    0,  311,  311,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  311,    0,    0,    0,  311,  311,    0,
+    0,    0,  311,    0,    0,    0,    0,    0,  311,    0,
+  311,  311,    0,    0,  311,    0,  311,  311,  311,  311,
+  311,    0,  311,  311,  311,  311,  311,  311,  311,  311,
+  311,  311,  311,  311,  311,  311,  311,  311,    0,    0,
+    0,    0,  311,  311,  311,    0,  311,  311,  311,    0,
+  311,  311,  311,    0,    0,  311,    0,  311,    0,    0,
+  311,  311,  311,  311,    0,  311,  311,  311,  311,    0,
+    0,  311,    0,    0,  311,  311,  311,  311,  311,  311,
+  311,  311,    0,  311,  311,  311,  311,  311,  309,    0,
+  311,    0,  309,  309,  309,    0,    0,  311,  311,  311,
+    0,    0,    0,  309,    0,    0,  311,  311,  309,    0,
+    0,  309,  309,  309,  309,  309,  309,  309,    0,    0,
+  309,  309,  309,    0,    0,    0,    0,  309,  309,    0,
+    0,    0,  309,  309,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  309,    0,    0,    0,  309,  309,    0,
+    0,    0,  309,    0,    0,    0,    0,    0,  309,    0,
+  309,  309,    0,    0,  309,    0,  309,  309,  309,  309,
+  309,    0,  309,  309,  309,  309,  309,  309,  309,  309,
+  309,  309,  309,  309,  309,  309,  309,  309,    0,    0,
+    0,    0,  309,  309,  309,    0,  309,  309,  309,    0,
+  309,  309,  309,    0,    0,  309,    0,  309,    0,  300,
+  309,  309,  309,  309,    0,  309,  309,  309,  309,  300,
+    0,  309,    0,    0,  309,  309,  309,  309,  309,  309,
+  309,  309,    0,  309,  309,  309,  309,  309,    0,    0,
+  309,    0,    0,    0,    0,    0,  300,  309,  309,  309,
+  300,    0,    0,  300,    0,    0,  309,  309,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  300,  300,    0,
+  300,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  298,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  298,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  298,    0,    0,    0,
+  298,    0,    0,  298,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  298,  298,    0,
+  298,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  300,    0,    0,    0,  300,
+  300,  300,    0,    0,    0,    0,    0,    0,    0,    0,
+  300,    0,    0,    0,    0,  300,    0,    0,  300,  300,
+  300,  300,  300,  300,  300,    0,    0,  300,  300,  300,
+    0,    0,    0,    0,  300,  300,    0,    0,    0,  300,
+  300,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  300,    0,    0,    0,  300,  300,    0,    0,    0,  300,
+    0,    0,    0,    0,    0,  300,    0,  300,  300,    0,
+    0,  300,    0,  300,  300,  300,  300,  300,    0,  300,
+  300,  300,  300,  300,  300,  300,  300,  300,  300,  300,
+  300,  300,  300,  300,  300,    0,    0,    0,    0,  300,
+  300,  300,    0,  300,  300,  300,    0,  300,  300,  300,
+    0,    0,  300,    0,  300,    0,    0,  300,  300,  300,
+  300,    0,  300,  300,  300,  300,    0,    0,  300,    0,
+    0,  300,  300,  300,  300,  300,  300,  300,  300,    0,
+  300,  300,  300,  300,  300,  298,    0,  300,    0,  298,
+  298,  298,    0,    0,  300,  300,  300,    0,    0,    0,
+  298,    0,    0,  300,  300,  298,    0,    0,  298,  298,
+  298,  298,  298,  298,  298,    0,    0,  298,  298,  298,
+    0,    0,    0,    0,  298,  298,    0,    0,    0,  298,
+  298,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  298,    0,    0,    0,  298,  298,    0,    0,    0,  298,
+    0,    0,    0,    0,    0,  298,    0,  298,  298,    0,
+    0,  298,    0,  298,  298,  298,  298,  298,    0,  298,
+  298,  298,  298,  298,  298,  298,  298,  298,  298,  298,
+  298,  298,  298,  298,  298,    0,    0,    0,    0,  298,
+  298,  298,    0,  298,  298,  298,    0,  298,  298,  298,
+    0,    0,  298,    0,  298,    0,  303,  298,  298,  298,
+  298,    0,  298,  298,  298,  298,  303,    0,  298,    0,
+    0,  298,  298,  298,  298,  298,  298,  298,  298,    0,
+  298,  298,  298,  298,  298,    0,    0,  298,    0,    0,
+    0,    0,    0,  303,  298,  298,  298,  303,    0,    0,
+  303,    0,    0,  298,  298,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  303,  303,    0,  303,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  302,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  302,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  302,    0,    0,    0,  302,    0,    0,
+  302,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  302,  302,    0,  302,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  303,    0,    0,    0,  303,  303,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  303,    0,    0,
+    0,    0,  303,    0,    0,  303,  303,  303,  303,  303,
+  303,  303,    0,    0,  303,  303,  303,    0,    0,    0,
+    0,  303,  303,    0,    0,    0,  303,  303,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  303,    0,    0,
+    0,  303,  303,    0,    0,    0,  303,    0,    0,    0,
+    0,    0,  303,    0,  303,  303,    0,    0,  303,    0,
+  303,  303,  303,  303,  303,    0,  303,  303,  303,  303,
+  303,  303,  303,  303,  303,  303,  303,  303,  303,  303,
+  303,  303,    0,    0,    0,    0,  303,  303,  303,    0,
+  303,  303,  303,    0,  303,  303,  303,    0,    0,  303,
+    0,  303,    0,    0,  303,  303,  303,  303,    0,  303,
+  303,  303,  303,    0,    0,  303,    0,    0,  303,  303,
+  303,  303,  303,  303,  303,  303,    0,  303,  303,  303,
+  303,  303,  302,    0,  303,    0,  302,  302,  498,    0,
+    0,  303,  303,  303,    0,    0,    0,  302,  498,    0,
+  303,  303,  302,    0,    0,  302,  302,  302,  302,  302,
+  302,  302,    0,    0,  302,  302,  302,    0,    0,    0,
+    0,  302,  302,    0,    0,    0,  302,  302,    0,  498,
+  498,  498,  498,  498,    0,    0,    0,  302,    0,    0,
+    0,  302,  302,    0,    0,    0,  302,  498,    0,    0,
+    0,    0,  302,    0,  302,  302,    0,    0,  302,    0,
+  302,  302,  302,  302,  302,    0,  302,  302,  302,  302,
+  302,  302,  302,  302,  302,  302,  302,  302,  302,  302,
+  302,  302,    0,    0,    0,    0,  302,  302,  302,    0,
+  302,  302,  302,    0,  302,  302,  302,    0,    0,  302,
+    0,  302,    0,    0,  302,  302,  302,  302,    0,  302,
+  302,  302,  302,    0,    0,  302,    0,    0,  302,  302,
+  302,  302,  302,  302,  302,  302,    0,  302,  302,  302,
+  302,  302,    0,    0,  302,    0,    0,    0,  499,    0,
+    0,  302,  302,  302,    0,    0,    0,    0,  499,    0,
+  302,  302,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  499,
+  499,  499,  499,  499,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  499,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  498,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  498,
+  498,  498,    0,    0,  498,    0,    0,  498,  498,  498,
+  498,  498,  498,  498,    0,    0,  498,  498,  498,    0,
+    0,    0,    0,  498,  498,    0,    0,    0,  498,  498,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  498,
+    0,    0,    0,  498,  498,    0,    0,    0,  498,    0,
+    0,    0,    0,    0,  498,    0,  498,  498,    0,    0,
+  498,    0,  498,  498,  498,  498,  498,    0,  498,  498,
+  498,  498,  498,  498,  498,  498,  498,  498,  498,  498,
+  498,  498,  498,  498,    0,    0,    0,    0,  498,  498,
+  498,    0,  498,  498,  498,    0,  498,  498,  498,    0,
+    0,  498,    0,  498,    0,    0,  498,  498,  498,  498,
+    0,    0,  498,  498,  498,    0,    0,  498,    0,    0,
+  498,  498,  498,  498,  498,  498,  498,  498,    0,  498,
+  498,  498,  498,  498,  499,    0,  498,    0,  490,    0,
+    0,    0,    0,  498,  498,  498,    0,    0,  490,  499,
+  499,  499,  498,  498,  499,    0,    0,  499,  499,  499,
+  499,  499,  499,  499,    0,    0,  499,  499,  499,    0,
+    0,    0,    0,  499,  499,    0,    0,    0,  499,  499,
+  496,  496,  490,  496,    0,    0,    0,    0,    0,  499,
+    0,    0,    0,  499,  499,    0,    0,  490,  499,    0,
+    0,    0,    0,    0,  499,    0,  499,  499,    0,    0,
+  499,    0,  499,  499,  499,  499,  499,    0,  499,  499,
+  499,  499,  499,  499,  499,  499,  499,  499,  499,  499,
+  499,  499,  499,  499,    0,    0,    0,    0,  499,  499,
+  499,    0,  499,  499,  499,    0,  499,  499,  499,    0,
+    0,  499,    0,  499,    0,    0,  499,  499,  499,  499,
+    0,    0,  499,  499,  499,    0,    0,  499,    0,    0,
+  499,  499,  499,  499,  499,  499,  499,  499,    0,  499,
+  499,  499,  499,  499,    0,    0,  499,    0,  504,    0,
+    0,    0,    0,  499,  499,    0,    0,    0,  504,    0,
+    0,    0,  499,  499,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  504,
+  504,  504,  504,  504,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  504,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  490,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  496,
+  496,  496,    0,    0,  490,    0,    0,  490,  490,  490,
+  490,  490,  490,  490,    0,    0,  490,  490,  490,    0,
+    0,    0,    0,  490,  490,    0,    0,    0,  490,  490,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  490,
+    0,    0,    0,  490,  490,    0,    0,    0,  490,    0,
+    0,    0,    0,    0,  490,    0,  490,  490,    0,    0,
+  490,    0,  490,  490,  490,  490,  490,    0,  490,  490,
+  490,  490,  490,  490,  490,  490,  490,  490,  490,  490,
+  490,  490,  490,  490,    0,    0,    0,    0,  490,  490,
+  490,    0,  490,  490,  490,    0,  490,  490,  490,    0,
+    0,  490,    0,  490,    0,    0,  490,  490,  490,  490,
+    0,    0,  490,  490,  490,    0,    0,  490,    0,    0,
+  490,  490,  490,  490,  490,  490,  490,  490,    0,  490,
+  490,  490,  490,  490,  504,    0,  490,    0,    0,    0,
+    0,  501,    0,  490,  490,  490,    0,    0,    0,  504,
+  504,  501,  490,  490,  504,    0,    0,  504,  504,  504,
+  504,  504,  504,  504,    0,    0,  504,  504,  504,    0,
+    0,    0,    0,  504,  504,    0,    0,    0,  504,  504,
+    0,    0,  501,  501,  501,  501,  501,    0,    0,  504,
+    0,    0,    0,  504,  504,    0,    0,    0,  504,    0,
+  501,    0,    0,    0,  504,    0,  504,  504,    0,    0,
+  504,    0,  504,  504,  504,  504,  504,    0,  504,  504,
+  504,  504,  504,  504,  504,  504,  504,  504,  504,  504,
+  504,  504,  504,  504,    0,    0,    0,    0,  504,  504,
+  504,    0,  504,  504,  504,    0,  504,  504,  504,    0,
+    0,  504,    0,  504,    0,    0,  504,  504,  504,  504,
+    0,    0,  504,  504,  504,    0,    0,  504,    0,    0,
+  504,  504,  504,  504,  504,  504,  504,  504,    0,  504,
+  504,  504,  504,  504,    0,    0,  504,    0,    0,    0,
+    0,  502,    0,  504,  504,  504,    0,    0,    0,    0,
+    0,  502,  504,  504,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  502,  502,  502,  502,  502,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  502,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  501,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  501,  501,    0,    0,    0,  501,    0,    0,
+  501,  501,  501,  501,  501,  501,  501,    0,    0,  501,
+  501,  501,    0,    0,    0,    0,  501,  501,    0,    0,
+    0,  501,  501,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  501,    0,    0,    0,  501,  501,    0,    0,
+    0,  501,    0,    0,    0,    0,    0,  501,    0,  501,
+  501,    0,    0,  501,    0,  501,  501,  501,  501,  501,
+    0,  501,  501,  501,  501,  501,  501,  501,  501,  501,
+  501,  501,  501,  501,  501,  501,  501,    0,    0,    0,
+    0,  501,  501,  501,    0,  501,  501,  501,    0,  501,
+  501,  501,    0,    0,  501,    0,  501,    0,    0,  501,
+  501,  501,  501,    0,    0,  501,  501,  501,    0,    0,
+  501,    0,    0,  501,  501,  501,  501,  501,  501,  501,
+  501,    0,  501,  501,  501,  501,  501,  502,    0,  501,
+    0,    0,    0,    0,  503,    0,  501,  501,  501,    0,
+    0,    0,  502,  502,  503,  501,  501,  502,    0,    0,
+  502,  502,  502,  502,  502,  502,  502,    0,    0,  502,
+  502,  502,    0,    0,    0,    0,  502,  502,    0,    0,
+    0,  502,  502,    0,    0,  503,  503,  503,  503,  503,
+    0,    0,  502,    0,    0,    0,  502,  502,    0,    0,
+    0,  502,    0,  503,    0,    0,    0,  502,    0,  502,
+  502,    0,    0,  502,    0,  502,  502,  502,  502,  502,
+    0,  502,  502,  502,  502,  502,  502,  502,  502,  502,
+  502,  502,  502,  502,  502,  502,  502,    0,    0,    0,
+    0,  502,  502,  502,    0,  502,  502,  502,    0,  502,
+  502,  502,    0,    0,  502,    0,  502,    0,    0,  502,
+  502,  502,  502,    0,    0,  502,  502,  502,    0,    0,
+  502,    0,    0,  502,  502,  502,  502,  502,  502,  502,
+  502,    0,  502,  502,  502,  502,  502,    0,    0,  502,
+    0,    0,    0,    0,  284,    0,  502,  502,  502,    0,
+    0,    0,    0,    0,  284,  502,  502,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  284,    0,    0,    0,  284,    0,    0,  284,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  284,  284,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  503,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  503,  503,    0,    0,    0,
+  503,    0,    0,  503,  503,  503,  503,  503,  503,  503,
+    0,    0,  503,  503,  503,    0,    0,    0,    0,  503,
+  503,    0,    0,    0,  503,  503,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  503,    0,    0,    0,  503,
+  503,    0,    0,    0,  503,    0,    0,    0,    0,    0,
+  503,    0,  503,  503,    0,    0,  503,    0,  503,  503,
+  503,  503,  503,    0,  503,  503,  503,  503,  503,  503,
+  503,  503,  503,  503,  503,  503,  503,  503,  503,  503,
+    0,    0,    0,    0,  503,  503,  503,    0,  503,  503,
+  503,    0,  503,  503,  503,    0,    0,  503,    0,  503,
+    0,    0,  503,  503,  503,  503,    0,    0,  503,  503,
+  503,    0,    0,  503,    0,    0,  503,  503,  503,  503,
+  503,  503,  503,  503,  312,  503,  503,  503,  503,  503,
+  284,    0,  503,    0,  312,    0,    0,    0,    0,  503,
+  503,  503,    0,    0,    0,  284,    0,    0,  503,  503,
+  284,    0,    0,  284,  284,  284,  284,  284,  284,  284,
+    0,  312,  284,  284,  284,  312,    0,    0,  312,  284,
+  284,    0,    0,    0,  284,  284,    0,    0,    0,    0,
+    0,    0,  312,  312,    0,  284,    0,    0,    0,  284,
+  284,    0,    0,    0,  284,    0,    0,    0,    0,    0,
+  284,    0,  284,  284,    0,    0,  284,    0,  284,  284,
+  284,  284,  284,    0,  284,  284,  284,  284,  284,  284,
+  284,  284,  284,  284,  284,  284,  284,  284,  284,  284,
+    0,    0,    0,    0,  284,  284,  284,    0,  284,  284,
+  284,    0,  284,  284,  284,    0,    0,  284,    0,  284,
+    0,    0,  284,  284,  284,  284,    0,  284,  284,  284,
+  284,    0,    0,  284,    0,    0,  284,  284,  284,  284,
+  284,  284,  284,  284,  308,  284,  284,  284,  284,  284,
+    0,    0,  284,    0,  308,    0,    0,    0,    0,  284,
+  284,  284,    0,    0,    0,    0,    0,    0,  284,  284,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  308,    0,    0,    0,  308,    0,    0,  308,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  308,  308,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  312,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  312,    0,    0,    0,    0,
+  312,    0,    0,  312,  312,  312,  312,  312,  312,  312,
+    0,    0,  312,  312,  312,    0,    0,    0,    0,  312,
+  312,    0,    0,    0,  312,  312,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  312,    0,    0,    0,  312,
+  312,    0,    0,    0,  312,    0,    0,    0,    0,    0,
+  312,    0,  312,  312,    0,    0,  312,    0,  312,  312,
+  312,  312,  312,    0,  312,  312,  312,  312,  312,  312,
+  312,  312,  312,  312,  312,  312,  312,  312,  312,  312,
+    0,    0,    0,    0,  312,  312,  312,    0,  312,  312,
+  312,    0,  312,  312,  312,    0,    0,  312,    0,  312,
+    0,    0,  312,  312,  312,  312,    0,  312,  312,  312,
+  312,    0,    0,  312,    0,    0,  312,  312,  312,  312,
+  312,  312,  312,  312,    0,  312,  312,  312,  312,  312,
+  308,    0,  312,    0,    0,    0,  500,    0,    0,  312,
+  312,  312,    0,    0,    0,  308,  500,    0,  312,  312,
+  308,    0,    0,  308,  308,  308,  308,  308,  308,  308,
+    0,    0,  308,  308,  308,    0,    0,    0,    0,  308,
+  308,    0,    0,    0,  308,  308,    0,  500,    0,  500,
+  500,  500,    0,    0,    0,  308,    0,    0,    0,  308,
+  308,    0,    0,    0,  308,  500,    0,    0,    0,    0,
+  308,    0,  308,  308,    0,    0,  308,    0,  308,  308,
+  308,  308,  308,    0,  308,  308,  308,  308,  308,  308,
+  308,  308,  308,  308,  308,  308,  308,  308,  308,  308,
+    0,    0,    0,    0,  308,  308,  308,    0,  308,  308,
+  308,    0,  308,  308,  308,    0,    0,  308,    0,  308,
+    0,    0,  308,  308,  308,  308,    0,  308,  308,  308,
+  308,    0,    0,  308,    0,    0,  308,  308,  308,  308,
+  308,  308,  308,  308,    0,  308,  308,  308,  308,  308,
+    0,    0,  308,    0,    0,    0,  236,    0,    0,  308,
+  308,  308,    0,    0,    0,    0,  236,    0,  308,  308,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  236,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  236,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  500,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  500,    0,    0,
+    0,    0,  500,    0,    0,  500,  500,  500,  500,  500,
+  500,  500,    0,    0,  500,  500,  500,    0,    0,    0,
+    0,  500,  500,    0,    0,    0,  500,  500,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  500,    0,    0,
+    0,  500,  500,    0,    0,    0,  500,    0,    0,    0,
+    0,    0,  500,    0,  500,  500,    0,    0,  500,    0,
+  500,  500,  500,  500,  500,    0,  500,  500,  500,  500,
+  500,  500,  500,  500,  500,  500,  500,  500,  500,  500,
+  500,  500,    0,    0,    0,    0,  500,  500,  500,    0,
+  500,  500,  500,    0,  500,  500,  500,    0,    0,  500,
+    0,  500,    0,    0,  500,  500,  500,  500,    0,    0,
+  500,  500,  500,    0,    0,  500,    0,    0,  500,  500,
+  500,  500,  500,  500,  500,  500,  506,  500,  500,  500,
+  500,  500,  236,    0,  500,    0,  506,    0,    0,    0,
+    0,  500,  500,  500,    0,    0,    0,  236,  236,    0,
+  500,  500,  236,    0,    0,  236,  236,  236,  236,  236,
+  236,  236,    0,    0,  236,  236,  236,  506,    0,    0,
+  506,  236,  236,    0,    0,    0,  236,  236,    0,    0,
+    0,    0,    0,    0,    0,  506,    0,  236,    0,    0,
+    0,  236,  236,    0,    0,    0,  236,    0,    0,    0,
+    0,    0,  236,    0,  236,  236,    0,    0,  236,    0,
+  236,  236,  236,  236,  236,    0,  236,  236,  236,  236,
+  236,  236,  236,  236,  236,  236,  236,  236,  236,  236,
+  236,  236,    0,    0,    0,    0,  236,  236,  236,    0,
+  236,  236,  236,    0,  236,  236,  236,    0,    0,  236,
+    0,  236,    0,    0,  236,  236,  236,  236,    0,    0,
+  236,  236,  236,    0,    0,  236,    0,    0,  236,  236,
+  236,  236,  236,  236,  236,  236,  509,  236,  236,  236,
+  236,  236,    0,    0,  236,    0,  509,    0,    0,    0,
+    0,  236,  236,  236,    0,    0,    0,    0,    0,    0,
+  236,  236,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  509,    0,    0,
+  509,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  509,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  506,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  506,    0,    0,
+    0,    0,  506,    0,    0,  506,  506,  506,  506,  506,
+  506,  506,    0,    0,  506,  506,  506,    0,    0,    0,
+    0,  506,  506,    0,    0,    0,  506,  506,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  506,    0,    0,
+    0,  506,  506,    0,    0,    0,  506,    0,    0,    0,
+    0,    0,  506,    0,  506,  506,    0,    0,  506,    0,
+  506,  506,  506,  506,  506,    0,  506,  506,  506,  506,
+  506,  506,  506,  506,  506,  506,  506,  506,  506,  506,
+  506,  506,    0,    0,    0,    0,  506,  506,  506,    0,
+  506,  506,  506,    0,  506,  506,  506,    0,    0,  506,
+    0,  506,    0,    0,  506,  506,  506,  506,    0,    0,
+  506,  506,  506,    0,    0,  506,    0,    0,  506,  506,
+  506,  506,  506,  506,  506,  506,  508,  506,  506,  506,
+  506,  506,  509,    0,  506,    0,  508,    0,    0,    0,
+    0,  506,  506,  506,    0,    0,    0,  509,    0,    0,
+  506,  506,  509,    0,    0,  509,  509,  509,  509,  509,
+  509,  509,    0,    0,  509,  509,  509,  508,    0,    0,
+  508,  509,  509,    0,    0,    0,  509,  509,    0,    0,
+    0,    0,    0,    0,    0,  508,    0,  509,    0,    0,
+    0,  509,  509,    0,    0,    0,  509,    0,    0,    0,
+    0,    0,  509,    0,  509,  509,    0,    0,  509,    0,
+  509,  509,  509,  509,  509,    0,  509,  509,  509,  509,
+  509,  509,  509,  509,  509,  509,  509,  509,  509,  509,
+  509,  509,    0,    0,    0,    0,  509,  509,  509,    0,
+  509,  509,  509,    0,  509,  509,  509,    0,    0,  509,
+    0,  509,    0,    0,  509,  509,  509,  509,    0,    0,
+  509,  509,  509,    0,    0,  509,    0,    0,  509,  509,
+  509,  509,  509,  509,  509,  509,  507,  509,  509,  509,
+  509,  509,    0,    0,  509,    0,  507,    0,    0,    0,
+    0,  509,  509,  509,    0,    0,    0,    0,    0,    0,
+  509,  509,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  507,    0,    0,
+  507,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  507,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  508,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  508,    0,    0,
+    0,    0,  508,    0,    0,  508,  508,  508,  508,  508,
+  508,  508,    0,    0,  508,  508,  508,    0,    0,    0,
+    0,  508,  508,    0,    0,    0,  508,  508,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  508,    0,    0,
+    0,  508,  508,    0,    0,    0,  508,    0,    0,    0,
+    0,    0,  508,    0,  508,  508,    0,    0,  508,    0,
+  508,  508,  508,  508,  508,    0,  508,  508,  508,  508,
+  508,  508,  508,  508,  508,  508,  508,  508,  508,  508,
+  508,  508,    0,    0,    0,    0,  508,  508,  508,    0,
+  508,  508,  508,    0,  508,  508,  508,    0,    0,  508,
+    0,  508,    0,    0,  508,  508,  508,  508,    0,    0,
+  508,  508,  508,    0,    0,  508,    0,    0,  508,  508,
+  508,  508,  508,  508,  508,  508,    0,  508,  508,  508,
+  508,  508,  507,    0,  508,    0,  236,    0,    0,    0,
+    0,  508,  508,  508,    0,    0,  236,  507,    0,    0,
+  508,  508,  507,    0,    0,  507,  507,  507,  507,  507,
+  507,  507,    0,    0,  507,  507,  507,    0,    0,    0,
+    0,  507,  507,    0,    0,    0,  507,  507,  236,    0,
+  236,    0,    0,    0,    0,    0,    0,  507,    0,    0,
+    0,  507,  507,    0,    0,  236,  507,  236,    0,    0,
+    0,    0,  507,    0,  507,  507,    0,    0,  507,    0,
+  507,  507,  507,  507,  507,    0,  507,  507,  507,  507,
+  507,  507,  507,  507,  507,  507,  507,  507,  507,  507,
+  507,  507,    0,    0,    0,    0,  507,  507,  507,    0,
+  507,  507,  507,    0,  507,  507,  507,    0,    0,  507,
+    0,  507,    0,    0,  507,  507,  507,  507,    0,    0,
+  507,  507,  507,    0,    0,  507,    0,    0,  507,  507,
+  507,  507,  507,  507,  507,  507,    0,  507,  507,  507,
+  507,  507,    0,    0,  507,    0,  510,    0,    0,    0,
+    0,  507,  507,  507,    0,    0,  510,    0,    0,    0,
+  507,  507,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  510,    0,    0,
+  510,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  510,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  236,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  236,    0,    0,  236,  236,  236,  236,  236,
+  236,  236,    0,    0,  236,  236,  236,    0,    0,    0,
+    0,  236,  236,    0,    0,    0,  236,  236,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  236,    0,    0,
+    0,  236,  236,    0,    0,    0,  236,    0,    0,    0,
+    0,    0,  236,    0,  236,  236,    0,    0,  236,    0,
+  236,  236,  236,  236,  236,    0,  236,  236,  236,  236,
+  236,  236,  236,  236,  236,  236,  236,  236,  236,  236,
+  236,  236,    0,    0,    0,    0,  236,  236,  236,    0,
+  236,  236,  236,    0,  236,  236,  236,    0,    0,  236,
+    0,  236,    0,    0,  236,  236,  236,  236,    0,    0,
+  236,  236,  236,    0,    0,  236,    0,    0,  236,  236,
+  236,  236,  236,  236,  236,  236,  505,  236,  236,  236,
+  236,  236,  510,    0,  236,    0,  505,    0,    0,    0,
+    0,  236,  236,  236,    0,    0,    0,  510,    0,    0,
+  236,  236,  510,    0,    0,  510,  510,  510,  510,  510,
+  510,  510,    0,    0,  510,  510,  510,  505,    0,    0,
+  505,  510,  510,    0,    0,    0,  510,  510,    0,    0,
+    0,    0,    0,    0,    0,  505,    0,  510,    0,    0,
+    0,  510,  510,    0,    0,    0,  510,    0,    0,    0,
+    0,    0,  510,    0,  510,  510,    0,    0,  510,    0,
+  510,  510,  510,  510,  510,    0,  510,  510,  510,  510,
+  510,  510,  510,  510,  510,  510,  510,  510,  510,  510,
+  510,  510,    0,    0,    0,    0,  510,  510,  510,    0,
+  510,  510,  510,    0,  510,  510,  510,    0,    0,  510,
+    0,  510,    0,    0,  510,  510,  510,  510,    0,    0,
+  510,  510,  510,    0,    0,  510,    0,    0,  510,  510,
+  510,  510,  510,  510,  510,  510,   56,  510,  510,  510,
+  510,  510,    0,    0,  510,    0,   56,    0,    0,    0,
+    0,  510,  510,  510,    0,    0,    0,    0,    0,    0,
+  510,  510,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,   56,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  505,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  505,    0,    0,
+    0,    0,  505,    0,    0,  505,  505,  505,  505,  505,
+  505,  505,    0,    0,  505,  505,  505,    0,    0,    0,
+    0,  505,  505,    0,    0,    0,  505,  505,    0,    0,
+    0,    0,    0,    0,   57,    0,    0,  505,    0,    0,
+    0,  505,  505,    0,   57,    0,  505,    0,    0,    0,
+    0,    0,  505,    0,  505,  505,    0,    0,  505,    0,
+  505,  505,  505,  505,  505,    0,  505,  505,  505,  505,
+  505,  505,  505,  505,  505,  505,  505,  505,  505,  505,
+  505,  505,    0,    0,    0,    0,  505,  505,  505,    0,
+  505,  505,  505,   57,  505,  505,  505,    0,    0,  505,
+    0,  505,    0,    0,  505,  505,  505,  505,    0,    0,
+  505,  505,  505,    0,    0,  505,    0,    0,  505,  505,
+  505,  505,  505,  505,  505,  505,    0,  505,  505,  505,
+  505,  505,   56,    0,  505,    0,    0,    0,    0,    0,
+    0,  505,  505,  505,    0,    0,    0,  164,  164,    0,
+  505,  505,   56,    0,    0,   56,   56,   56,   56,   56,
+   56,   56,    0,    0,   56,   56,   56,    0,    0,    0,
+    0,   56,   56,    0,    0,    0,   56,   56,    0,    0,
+    0,    0,    0,    0,  142,    0,    0,   56,    0,    0,
+    0,   56,   56,    0,  142,    0,   56,    0,    0,    0,
+    0,    0,   56,    0,   56,   56,    0,    0,   56,    0,
+   56,   56,   56,   56,   56,    0,   56,   56,   56,   56,
+   56,   56,   56,   56,   56,   56,   56,   56,   56,   56,
+   56,   56,    0,    0,    0,    0,   56,   56,   56,    0,
+   56,   56,   56,  142,   56,   56,   56,    0,    0,   56,
+    0,   56,    0,    0,   56,   56,   56,   56,    0,    0,
+   56,   56,   56,    0,    0,   56,    0,    0,   56,   56,
+   56,   56,   56,   56,   56,   56,    0,   56,   56,   56,
+   56,   56,    0,    0,   56,    0,    0,    0,    0,    0,
+   57,   56,   56,   56,    0,    0,    0,    0,    0,    0,
+   56,   56,    0,    0,    0,  164,  164,    0,    0,    0,
+   57,    0,    0,   57,   57,   57,   57,   57,   57,   57,
+    0,    0,   57,   57,   57,    0,    0,    0,    0,   57,
+   57,    0,    0,    0,   57,   57,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,   57,    0,    0,    0,   57,
+   57,    0,    0,    0,   57,    0,    0,    0,    0,    0,
+   57,    0,   57,   57,    0,    0,   57,    0,   57,   57,
+   57,   57,   57,    0,   57,   57,   57,   57,   57,   57,
+   57,   57,   57,   57,   57,   57,   57,   57,   57,   57,
+    0,    0,    0,    0,   57,   57,   57,    0,   57,   57,
+   57,    0,   57,   57,   57,    0,    0,   57,    0,   57,
+    0,    0,   57,   57,   57,   57,    0,    0,   57,   57,
+   57,    0,    0,   57,    0,    0,   57,   57,   57,   57,
+   57,   57,   57,   57,  354,   57,   57,   57,   57,   57,
+  142,    0,   57,    0,  354,    0,    0,    0,    0,   57,
+   57,   57,    0,    0,    0,  164,  164,    0,   57,   57,
+  142,    0,    0,  142,  142,  142,  142,  142,  142,  142,
+    0,    0,  142,  142,  142,  354,    0,    0,    0,  142,
+  142,    0,    0,    0,  142,  142,    0,    0,    0,    0,
+    0,    0,  354,  354,    0,  142,    0,    0,    0,  142,
+  142,    0,    0,    0,  142,    0,    0,    0,    0,    0,
+  142,    0,  142,  142,    0,    0,  142,    0,  142,  142,
+  142,  142,  142,    0,  142,  142,  142,  142,  142,  142,
+  142,  142,  142,  142,  142,  142,  142,  142,  142,  142,
+    0,    0,    0,    0,  142,  142,  142,    0,  142,  142,
+  142,    0,  142,  142,  142,    0,    0,  142,    0,  142,
+    0,    0,  142,  142,  142,  142,    0,    0,  142,  142,
+  142,    0,    0,  142,    0,    0,  142,  142,  142,  142,
+  142,  142,  142,  142,  125,  142,  142,  142,  142,  142,
+    0,    0,  142,    0,  125,    0,    0,    0,    0,  142,
+  142,  142,    0,    0,    0,    0,    0,    0,  142,  142,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  125,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  125,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  354,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  354,    0,    0,  354,  354,  354,  354,  354,  354,  354,
+    0,    0,  354,  354,  354,    0,    0,    0,    0,  354,
+  354,    0,    0,    0,  354,  354,    0,    0,    0,    0,
+    0,    0,  154,    0,    0,  354,    0,    0,    0,  354,
+  354,    0,  154,    0,  354,    0,    0,    0,    0,    0,
+  354,    0,  354,  354,    0,    0,  354,    0,  354,  354,
+  354,  354,  354,    0,  354,  354,  354,  354,  354,  354,
+  354,  354,  354,  354,  354,  354,  354,  354,  354,  354,
+    0,    0,    0,    0,  354,  354,  354,    0,  354,  354,
+  354,  154,  354,  354,  354,    0,    0,  354,    0,  354,
+    0,    0,  354,  354,  354,  354,    0,    0,  354,  354,
+  354,    0,    0,  354,    0,    0,  354,  354,  354,  354,
+  354,  354,  354,  354,    0,  354,  354,  354,  354,  354,
+  125,    0,  354,    0,    0,    0,    0,    0,    0,  354,
+  354,  354,    0,    0,    0,  125,  125,    0,  354,  354,
+  125,    0,    0,  125,  125,  125,  125,  125,  125,  125,
+    0,    0,  125,  125,  125,    0,    0,    0,    0,  125,
+  125,    0,    0,    0,  125,  125,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  125,    0,    0,    0,  125,
+  125,    0,    0,    0,  125,    0,    0,    0,    0,    0,
+  125,    0,  125,  125,    0,    0,  125,    0,  125,  125,
+  125,  125,  125,    0,  125,  125,  125,  125,  125,  125,
+  125,  125,  125,  125,  125,  125,  125,  125,  125,  125,
+    0,    0,    0,    0,  125,  125,  125,    0,  125,  125,
+  125,  236,  125,  125,  125,    0,    0,  125,    0,  125,
+    0,  236,  125,  125,  125,  125,    0,    0,  125,  125,
+  125,    0,    0,  125,    0,    0,  125,  125,  125,  125,
+  125,  125,  125,  125,    0,  125,  125,  125,  125,  125,
+    0,    0,  125,  236,    0,  236,    0,    0,  154,  125,
+  125,    0,    0,    0,    0,    0,    0,    0,  125,  125,
+  236,    0,    0,  154,  154,    0,    0,    0,  154,    0,
+    0,  154,  154,  154,  154,  154,  154,  154,    0,    0,
+  154,  154,  154,    0,    0,    0,    0,  154,  154,    0,
+    0,    0,  154,  154,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  154,    0,    0,    0,  154,  154,    0,
+    0,    0,  154,    0,    0,    0,    0,    0,  154,    0,
+  154,  154,    0,    0,  154,    0,  154,  154,  154,  154,
+  154,    0,  154,  154,  154,  154,  154,  154,  154,  154,
+  154,  154,  154,  154,  154,  154,  154,  154,    0,    0,
+    0,    0,  154,  154,  154,    0,  154,  154,  154,  164,
+  154,  154,  154,    0,    0,  154,    0,  154,    0,  164,
+  154,  154,  154,  154,    0,    0,  154,  154,  154,    0,
+    0,  154,    0,    0,  154,  154,  154,  154,  154,  154,
+  154,  154,    0,  154,  154,  154,  154,  154,    0,    0,
+  154,    0,    0,    0,    0,    0,    0,  154,  154,  154,
+    0,    0,    0,    0,    0,    0,  154,  154,  164,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  236,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  236,    0,    0,
+  236,  236,  236,  236,  236,  236,  236,    0,    0,  236,
+  236,  236,    0,    0,    0,    0,  236,  236,    0,    0,
+    0,  236,  236,    0,    0,    0,    0,    0,    0,  155,
+    0,    0,  236,    0,    0,    0,  236,  236,    0,  155,
+    0,  236,    0,    0,    0,    0,    0,  236,    0,  236,
+  236,    0,    0,  236,    0,  236,  236,  236,  236,  236,
+    0,  236,  236,  236,  236,  236,  236,  236,  236,  236,
+  236,  236,  236,  236,  236,  236,  236,    0,    0,    0,
+    0,  236,  236,  236,    0,  236,  236,  236,  155,  236,
+  236,  236,    0,    0,  236,    0,  236,    0,    0,  236,
+  236,  236,  236,    0,    0,  236,  236,  236,    0,    0,
+  236,    0,    0,  236,  236,  236,  236,  236,  236,  236,
+  236,    0,  236,  236,  236,  236,  236,    0,    0,  236,
+    0,    0,    0,    0,    0,  164,  236,  236,  236,    0,
+    0,    0,    0,    0,    0,  236,  236,    0,    0,    0,
+  164,  164,    0,    0,    0,  164,    0,    0,  164,  164,
+  164,  164,  164,  164,  164,    0,    0,  164,  164,  164,
+    0,    0,    0,    0,  164,  164,    0,    0,    0,  164,
+  164,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  164,    0,    0,    0,  164,  164,    0,    0,    0,  164,
+    0,    0,    0,    0,    0,  164,    0,  164,  164,    0,
+    0,  164,    0,  164,  164,  164,  164,  164,    0,  164,
+  164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
+  164,  164,  164,  164,  164,    0,    0,    0,    0,  164,
+  164,  164,    0,  164,  164,  164,    0,  164,  164,  164,
+    0,    0,  164,    0,  164,    0,    0,  164,  164,  164,
+  164,    0,    0,  164,  164,  164,    0,    0,  164,    0,
+    0,  164,  164,  164,  164,  164,  164,  164,  164,  522,
+  164,  164,  164,  164,  164,  155,    0,  164,    0,  522,
+    0,    0,    0,    0,  164,  164,  164,    0,    0,    0,
+  155,  155,    0,  164,  164,  155,    0,    0,  155,  155,
+  155,  155,  155,  155,  155,    0,    0,  155,  155,  155,
+  522,    0,    0,  522,  155,  155,    0,    0,    0,  155,
+  155,    0,    0,    0,    0,    0,    0,    0,  522,    0,
+  155,    0,    0,    0,  155,  155,    0,    0,    0,  155,
+    0,    0,    0,    0,    0,  155,    0,  155,  155,    0,
+    0,  155,    0,  155,  155,  155,  155,  155,    0,  155,
+  155,  155,  155,  155,  155,  155,  155,  155,  155,  155,
+  155,  155,  155,  155,  155,    0,    0,    0,    0,  155,
+  155,  155,    0,  155,  155,  155,    0,  155,  155,  155,
+    0,    0,  155,    0,  155,    0,    0,  155,  155,  155,
+  155,    0,    0,  155,  155,  155,    0,    0,  155,    0,
+    0,  155,  155,  155,  155,  155,  155,  155,  155,  168,
+  155,  155,  155,  155,  155,    0,    0,  155,    0,  168,
+    0,    0,    0,    0,  155,  155,  155,    0,    0,    0,
+    0,    0,    0,  155,  155,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  168,    0,    0,  168,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  168,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  522,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  522,    0,    0,  522,  522,
+  522,  522,  522,  522,  522,    0,    0,  522,  522,  522,
+    0,    0,    0,    0,  522,  522,    0,    0,    0,  522,
+  522,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  522,    0,    0,    0,  522,  522,    0,    0,    0,  522,
+    0,    0,    0,    0,    0,  522,    0,  522,  522,    0,
+    0,  522,    0,  522,  522,  522,  522,  522,    0,  522,
+  522,  522,  522,  522,  522,  522,  522,  522,  522,  522,
+  522,  522,  522,  522,  522,    0,    0,    0,    0,  522,
+  522,  522,    0,  522,  522,  522,    0,  522,  522,  522,
+    0,    0,  522,    0,  522,    0,  520,  522,  522,  522,
+  522,    0,    0,  522,  522,  522,  520,    0,  522,    0,
+    0,  522,  522,  522,  522,  522,  522,  522,  522,    0,
+  522,  522,  522,  522,  522,  168,    0,  522,    0,    0,
+    0,    0,    0,    0,  522,  522,  522,  520,    0,    0,
+  520,    0,    0,  522,  522,  168,    0,    0,  168,  168,
+  168,  168,  168,  168,  168,  520,    0,  168,  168,  168,
+    0,    0,    0,    0,  168,  168,    0,    0,    0,  168,
+  168,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  168,    0,    0,    0,  168,  168,    0,    0,    0,  168,
+    0,    0,    0,    0,    0,  168,    0,  168,  168,    0,
+    0,  168,    0,  168,  168,  168,  168,  168,    0,  168,
+  168,  168,  168,  168,  168,  168,  168,  168,  168,  168,
+  168,  168,  168,  168,  168,    0,    0,    0,    0,  168,
+  168,  168,    0,  168,  168,  168,    0,  168,  168,  168,
+    0,    0,  168,    0,  168,    0,  519,  168,  168,  168,
+  168,    0,    0,  168,  168,  168,  519,    0,  168,    0,
+    0,  168,  168,  168,  168,  168,  168,  168,  168,    0,
+  168,  168,  168,  168,  168,    0,    0,  168,    0,    0,
+    0,    0,    0,    0,  168,  168,  168,  519,    0,    0,
+  519,    0,    0,  168,  168,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  519,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  520,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  520,    0,    0,  520,  520,  520,  520,  520,
+  520,  520,    0,    0,  520,  520,  520,    0,    0,    0,
+    0,  520,  520,    0,    0,    0,  520,  520,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  520,    0,    0,
+    0,  520,  520,    0,    0,    0,  520,    0,    0,    0,
+    0,    0,  520,    0,  520,  520,    0,    0,  520,    0,
+  520,  520,  520,  520,  520,    0,  520,  520,  520,  520,
+  520,  520,  520,  520,  520,  520,  520,  520,  520,  520,
+  520,  520,    0,    0,    0,    0,  520,  520,  520,    0,
+  520,  520,  520,    0,  520,  520,  520,    0,    0,  520,
+    0,  520,    0,  517,  520,  520,  520,  520,    0,    0,
+  520,  520,  520,  517,    0,  520,    0,    0,  520,  520,
+  520,  520,  520,  520,  520,  520,    0,  520,  520,  520,
+  520,  520,  519,    0,  520,    0,    0,    0,    0,    0,
+    0,  520,  520,  520,  517,    0,    0,  517,    0,    0,
+  520,  520,  519,    0,    0,  519,  519,  519,  519,  519,
+  519,  519,  517,    0,  519,  519,  519,    0,    0,    0,
+    0,  519,  519,    0,    0,    0,  519,  519,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  519,    0,    0,
+    0,  519,  519,    0,    0,    0,  519,    0,    0,    0,
+    0,    0,  519,    0,  519,  519,    0,    0,  519,    0,
+  519,  519,  519,  519,  519,    0,  519,  519,  519,  519,
+  519,  519,  519,  519,  519,  519,  519,  519,  519,  519,
+  519,  519,    0,    0,    0,    0,  519,  519,  519,    0,
+  519,  519,  519,    0,  519,  519,  519,    0,    0,  519,
+    0,  519,    0,  198,  519,  519,  519,  519,    0,    0,
+  519,  519,  519,  198,    0,  519,    0,    0,  519,  519,
+  519,  519,  519,  519,  519,  519,    0,  519,  519,  519,
+  519,  519,    0,    0,  519,    0,    0,    0,    0,    0,
+    0,  519,  519,  519,    0,    0,    0,  198,    0,    0,
+  519,  519,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  198,    0,  198,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  517,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  517,
+    0,    0,  517,  517,  517,  517,  517,  517,  517,    0,
+    0,  517,  517,  517,    0,    0,    0,    0,  517,  517,
+    0,    0,    0,  517,  517,    0,    0,    0,    0,    0,
+    0,  156,    0,    0,  517,    0,    0,    0,  517,  517,
+    0,  156,    0,  517,    0,    0,    0,    0,    0,  517,
+    0,  517,  517,    0,    0,  517,    0,  517,  517,  517,
+  517,  517,    0,  517,  517,  517,  517,  517,  517,  517,
+  517,  517,  517,  517,  517,  517,  517,  517,  517,    0,
+    0,    0,    0,  517,  517,  517,    0,  517,  517,  517,
+  156,  517,  517,  517,    0,    0,  517,    0,  517,    0,
+    0,  517,  517,  517,  517,    0,    0,  517,  517,  517,
+    0,    0,  517,    0,    0,  517,  517,  517,  517,  517,
+  517,  517,  517,    0,  517,  517,  517,  517,  517,  198,
+    0,  517,    0,    0,    0,    0,    0,    0,  517,  517,
+  517,    0,    0,    0,    0,    0,    0,  517,  517,  198,
+    0,    0,  198,  198,  198,  198,  198,  198,  198,    0,
+    0,  198,  198,  198,    0,    0,    0,    0,  198,  198,
+    0,    0,    0,  198,  198,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  198,    0,  357,    0,  198,  198,
+    0,    0,    0,  198,    0,    0,  357,    0,    0,  198,
+    0,  198,  198,    0,    0,  198,    0,  198,  198,  198,
+  198,  198,    0,  198,  198,  198,  198,  198,  198,  198,
+  198,  198,  198,  198,  198,  198,  198,  198,  198,    0,
+  357,    0,    0,  198,  198,  198,    0,  198,  198,  198,
+    0,  198,  198,  198,    0,  357,  198,  359,  198,    0,
+    0,  198,  198,  198,  198,    0,    0,  198,  198,  198,
+    0,    0,  198,    0,    0,  198,  198,  198,  198,  198,
+  198,  198,  198,    0,  198,  198,  198,  198,  198,    0,
+    0,  198,    0,    0,    0,    0,    0,  156,  198,  198,
+  198,    0,    0,    0,    0,    0,    0,  198,  198,    0,
+    0,    0,  156,  156,    0,    0,    0,  156,    0,    0,
+  156,  156,  156,  156,  156,  156,  156,    0,    0,  156,
+  156,  156,    0,    0,    0,    0,  156,  156,    0,    0,
+    0,  156,  156,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  156,    0,    0,    0,  156,  156,    0,    0,
+    0,  156,    0,    0,    0,    0,    0,  156,    0,  156,
+  156,    0,    0,  156,    0,  156,  156,  156,  156,  156,
+    0,  156,  156,  156,  156,  156,  156,  156,  156,  156,
+  156,  156,  156,  156,  156,  156,  156,    0,    0,    0,
+    0,  156,  156,  156,    0,  156,  156,  156,    0,  156,
+  156,  156,    0,    0,  156,    0,  156,    0,    0,  156,
+  156,  156,  156,    0,    0,  156,  156,  156,    0,    0,
+  156,    0,    0,  156,  156,  156,  156,  156,  156,  156,
+  156,    0,  156,  156,  156,  156,  156,    0,    0,  156,
+    0,    0,  357,    0,  518,    0,  156,  156,  156,    0,
+    0,    0,    0,    0,  518,  156,  156,    0,    0,  435,
+  414,  412,  357,  413,    0,  357,  357,  357,  357,  357,
+  357,  357,    0,    0,  357,  357,  357,    0,  417,  402,
+  418,  357,  357,    0,    0,  518,  357,  357,  518,    0,
+  250,  250,  250,  534,  250,    0,    0,  357,    0,    0,
+    0,  357,  357,  518,    0,    0,  357,    0,    0,  250,
+  250,  250,  357,    0,  357,  357,    0,    0,  357,    0,
+  357,  357,  357,  357,  357,    0,  357,  357,  357,  357,
+  357,  357,  357,  357,  357,  357,  357,  357,  357,  357,
+  357,  357,    0,    0,    0,    0,  357,  357,  357,    0,
+  357,  357,  357,    0,  357,  357,  357,    0,    0,  357,
+    0,  357,    0,    0,  357,  357,  357,  357,    0,    0,
+  357,  357,  357,    0,    0,  357,    0,    0,  357,  357,
+  357,  357,  357,  357,  357,  357,    0,  357,  357,  357,
+  357,  357,    0,    0,  357,   40,    0,    0,    0,    0,
+    0,  357,  357,  357,    0,   40,    0,    0,    0,    0,
+  357,  357,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,   40,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,    0,    0,    0,    0,    0,    0,    0,    0,
+  518,    0,    0,    0,    0,    0,    0,    0,    0,  250,
+  250,  250,    0,  250,  250,  250,  250,  250,  250,    0,
+  518,  250,  250,  518,  518,  518,  518,  518,  518,  518,
+    0,    0,  518,  518,  518,    0,    0,    0,    0,  518,
+  518,    0,    0,    0,  518,  518,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  518,    0,    0,    0,  518,
+  518,    0,    0,    0,  518,    0,    0,    0,    0,    0,
+  518,    0,  518,  518,    0,    0,  518,    0,  518,  518,
+  518,  518,  518,    0,  518,  518,  518,  518,  518,  518,
+  518,  518,  518,  518,  518,  518,  518,  518,  518,  518,
+    0,    0,    0,    0,  518,  518,  518,    0,  518,  518,
+  518,    0,  518,  518,  518,    0,    0,  518,    0,  518,
+    0,    0,  518,  518,  518,  518,    0,    0,  518,  518,
+  518,    0,  534,  518,    0,    0,  518,  518,  518,  518,
+  518,  518,  518,  518,    0,  518,  518,  518,  518,  518,
+    0,   40,  518,  522,    0,    0,    0,    0,    0,  518,
+  518,  518,    0,  522,    0,    0,    0,    0,  518,  518,
+    0,   40,   40,    0,   40,   40,   40,   40,   40,   40,
+   40,    0,    0,   40,   40,   40,    0,    0,    0,    0,
+   40,   40,    0,    0,  522,   40,   40,  522,    0,  636,
+  414,  412,    0,  413,    0,    0,   40,    0,    0,    0,
+   40,   40,  522,    0,    0,   40,  897,    0,  417,  402,
+  418,   40,    0,   40,   40,    0,    0,   40,    0,   40,
+   40,   40,   40,   40,    0,   40,   40,   40,   40,   40,
+   40,   40,   40,   40,   40,   40,   40,   40,   40,   40,
+   40,    0,    0,    0,    0,   40,   40,   40,    0,   40,
+   40,   40,    0,   40,   40,   40,    0,    0,   40,    0,
+   40,    0,    0,   40,   40,   40,   40,    0,    0,   40,
+   40,   40,    0,    0,   40,    0,    0,   40,   40,   40,
+   40,   40,   40,   40,   40,    0,   40,   40,   40,   40,
+   40,    0,    0,   40,  198,    0,    0,    0,    0,    0,
+   40,   40,   40,    0,  198,    0,    0,    0,    0,   40,
+   40,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  198,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  198,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  522,
+    0,    0,    0,    0,    0,    0,    0,    0,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,  522,
+  415,  416,  522,  522,  522,  522,  522,  522,  522,    0,
+    0,  522,  522,  522,    0,    0,    0,    0,  522,  522,
+    0,    0,    0,  522,  522,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  522,    0,  200,    0,  522,  522,
+    0,    0,    0,  522,    0,    0,  200,    0,    0,  522,
+    0,  522,  522,    0,    0,  522,    0,  522,  522,  522,
+  522,  522,    0,  522,  522,  522,  522,  522,  522,  522,
+  522,  522,  522,  522,  522,  522,  522,  522,  522,    0,
+  200,    0,    0,  522,  522,  522,    0,  522,  522,  522,
+    0,  522,  522,  522,    0,  200,  522,    0,  522,    0,
+    0,  522,  522,  522,  522,    0,    0,  522,  522,  522,
+    0,    0,  522,    0,    0,  522,  522,  522,  522,  522,
+  522,  522,  522,    0,  522,  522,  522,  522,  522,    0,
+  198,  522,    0,    0,    0,    0,    0,    0,  522,  522,
+    0,    0,    0,    0,    0,    0,    0,  522,  522,    0,
+  198,    0,    0,  198,  198,  198,  198,  198,  198,  198,
+    0,    0,  198,  198,  198,    0,    0,    0,    0,  198,
+  198,    0,    0,    0,  198,  198,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  198,  373,    0,    0,  198,
+  198,    0,    0,    0,  198,    0,  373,    0,    0,    0,
+  198,    0,  198,  198,    0,    0,  198,    0,  198,  198,
+  198,  198,  198,    0,  198,  198,  198,  198,  198,  198,
+  198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
+  373,    0,    0,    0,  198,  198,  198,    0,  198,  198,
+  198,    0,  198,  198,  198,  373,    0,  198,    0,  198,
+    0,    0,  198,  198,  198,  198,    0,    0,  198,  198,
+  198,    0,    0,  198,    0,    0,  198,  198,  198,  198,
+  198,  198,  198,  198,    0,  198,  198,  198,  198,  198,
+    0,    0,  198,    0,    0,    0,    0,    0,    0,  198,
+  198,  198,  200,    0,    0,    0,    0,    0,  198,  198,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  200,    0,    0,  200,  200,  200,  200,  200,
+  200,  200,    0,    0,  200,  200,  200,    0,    0,    0,
+    0,  200,  200,    0,    0,    0,  200,  200,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  200,  358,    0,
+    0,  200,  200,    0,    0,    0,  200,    0,  358,    0,
+    0,    0,  200,    0,  200,  200,    0,    0,  200,    0,
+  200,  200,  200,  200,  200,    0,  200,  200,  200,  200,
+  200,  200,  200,  200,  200,  200,  200,  200,  200,  200,
+  200,  200,  358,    0,    0,    0,  200,  200,  200,    0,
+  200,  200,  200,    0,  200,  200,  200,  358,    0,  200,
+    0,  200,    0,    0,  200,  200,  200,  200,    0,    0,
+  200,  200,  200,    0,    0,  200,    0,    0,  200,  200,
+  200,  200,  200,  200,  200,  200,    0,  200,  200,  200,
+  200,  200,  373,    0,  200,    0,    0,    0,    0,    0,
+    0,  200,  200,  200,    0,    0,    0,    0,    0,    0,
+  200,  200,  373,    0,    0,  373,  373,  373,  373,  373,
+  373,  373,    0,    0,  373,  373,  373,    0,    0,    0,
+    0,  373,  373,    0,    0,    0,  373,  373,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  373,   59,    0,
+    0,  373,  373,    0,    0,    0,  373,    0,   59,    0,
+    0,    0,  373,    0,  373,  373,    0,    0,  373,    0,
+  373,  373,  373,  373,  373,    0,  373,  373,  373,  373,
+  373,  373,  373,  373,  373,  373,  373,  373,  373,  373,
+  373,  373,    0,    0,    0,    0,  373,  373,  373,    0,
+  373,  373,  373,    0,  373,  373,  373,   59,    0,  373,
+    0,  373,    0,    0,  373,  373,  373,  373,    0,    0,
+  373,  373,  373,    0,    0,  373,    0,    0,  373,  373,
+  373,  373,  373,  373,  373,  373,    0,  373,  373,  373,
+  373,  373,    0,    0,  373,    0,    0,    0,    0,    0,
+    0,  373,  373,  373,  358,    0,    0,    0,    0,    0,
+  373,  373,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  358,    0,    0,  358,  358,  358,
+  358,  358,  358,  358,    0,    0,  358,  358,  358,    0,
+    0,    0,    0,  358,  358,    0,    0,    0,  358,  358,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  358,
+  125,    0,    0,  358,  358,    0,    0,    0,  358,    0,
+  125,    0,    0,    0,  358,    0,  358,  358,    0,    0,
+  358,    0,  358,  358,  358,  358,  358,    0,  358,  358,
+  358,  358,  358,  358,  358,  358,  358,  358,  358,  358,
+  358,  358,  358,  358,  125,    0,    0,    0,  358,  358,
+  358,    0,  358,  358,  358,    0,  358,  358,  358,  125,
+    0,  358,    0,  358,    0,    0,  358,  358,  358,  358,
+    0,    0,  358,  358,  358,    0,    0,  358,    0,    0,
+  358,  358,  358,  358,  358,  358,  358,  358,    0,  358,
+  358,  358,  358,  358,   59,    0,  358,    0,    0,    0,
+    0,    0,    0,  358,  358,  358,    0,    0,    0,    0,
+    0,    0,  358,  358,   59,    0,    0,   59,   59,   59,
+   59,   59,   59,   59,    0,    0,   59,   59,   59,    0,
+    0,    0,    0,   59,   59,    0,    0,    0,   59,   59,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,   59,
+  431,    0,    0,   59,   59,    0,    0,    0,   59,    0,
+  431,    0,    0,    0,   59,    0,   59,   59,    0,    0,
+   59,    0,   59,   59,   59,   59,   59,    0,   59,   59,
+   59,   59,   59,   59,   59,   59,   59,   59,   59,   59,
+   59,   59,   59,   59,    0,    0,    0,    0,   59,   59,
+   59,    0,   59,   59,   59,    0,   59,   59,   59,  431,
+    0,   59,    0,   59,    0,    0,   59,   59,   59,   59,
+    0,    0,   59,   59,   59,    0,    0,   59,    0,    0,
+   59,   59,   59,   59,   59,   59,   59,   59,    0,   59,
+   59,   59,   59,   59,    0,    0,   59,    0,    0,    0,
+    0,    0,    0,   59,   59,   59,  125,    0,    0,    0,
+    0,    0,   59,   59,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  125,    0,    0,  125,
+  125,  125,  125,  125,  125,  125,    0,    0,  125,  125,
+  125,    0,    0,    0,    0,  125,  125,    0,    0,    0,
+  125,  125,    0,    0,  440,    0,    0,    0,    0,    0,
+    0,  125,    0,    0,  440,  125,  125,    0,    0,    0,
+  125,    0,    0,    0,    0,    0,  125,    0,  125,  125,
+    0,    0,  125,    0,  125,  125,  125,  125,  125,    0,
+  125,  125,  125,  125,  125,  125,  125,  125,  125,  125,
+  125,  125,  125,  125,  125,  125,    0,    0,    0,    0,
+  125,  125,  125,  440,  125,  125,  125,    0,  125,  125,
+  125,    0,    0,  125,    0,  125,    0,    0,  125,  125,
+  125,  125,    0,    0,  125,  125,  125,    0,    0,  125,
+    0,    0,  125,  125,  125,  125,  125,  125,  125,  125,
+    0,  125,  125,  125,  125,  125,  431,    0,  125,    0,
+    0,    0,    0,    0,    0,  125,  125,    0,    0,    0,
+    0,    0,    0,    0,  125,  125,  431,    0,    0,  431,
+  431,  431,  431,  431,  431,  431,    0,    0,  431,  431,
+  431,    0,    0,    0,    0,  431,  431,    0,    0,    0,
+  431,  431,    0,    0,  356,    0,    0,    0,    0,    0,
+    0,  431,    0,    0,  356,  431,  431,    0,    0,    0,
+  431,    0,    0,    0,    0,    0,  431,    0,  431,  431,
+    0,    0,  431,    0,  431,  431,  431,  431,  431,    0,
+  431,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+  431,  431,  431,  431,  431,  431,    0,    0,    0,    0,
+  431,  431,  431,  356,  431,  431,  431,    0,  431,  431,
+  431,    0,    0,  431,    0,  431,    0,    0,  431,  431,
+  431,  431,    0,    0,  431,  431,  431,    0,    0,  431,
+    0,    0,  431,  431,  431,  431,  431,  431,  431,  431,
+    0,  431,  431,  431,  431,  431,    0,    0,  431,    0,
+  440,    0,    0,    0,    0,  431,  431,  431,    0,    0,
+    0,    0,    0,    0,  431,  431,    0,    0,    0,    0,
+  440,    0,    0,  440,  440,  440,  440,  440,  440,  440,
+    0,    0,  440,  440,  440,    0,    0,    0,    0,  440,
+  440,    0,    0,    0,  440,  440,    0,    0,   69,    0,
+    0,    0,    0,    0,    0,  440,    0,    0,   69,  440,
+  440,    0,    0,    0,  440,    0,    0,    0,    0,    0,
+  440,    0,  440,  440,    0,    0,  440,    0,  440,  440,
+  440,  440,  440,    0,  440,  440,  440,  440,  440,  440,
+  440,  440,  440,  440,  440,  440,  440,  440,  440,  440,
+    0,    0,    0,    0,  440,  440,  440,   69,  440,  440,
+  440,    0,  440,  440,  440,    0,    0,  440,    0,  440,
+    0,    0,  440,  440,  440,  440,    0,    0,  440,  440,
+  440,    0,    0,  440,    0,    0,  440,  440,  440,  440,
+  440,  440,  440,  440,    0,  440,  440,  440,  440,  440,
+  356,    0,  440,    0,    0,    0,    0,    0,    0,  440,
+  440,  440,    0,    0,    0,    0,    0,    0,  440,  440,
+  356,    0,    0,  356,  356,  356,  356,  356,  356,  356,
+    0,    0,  356,  356,  356,    0,    0,    0,    0,  356,
+  356,    0,    0,    0,  356,  356,    0,    0,   53,    0,
+    0,    0,    0,    0,    0,  356,    0,    0,   53,  356,
+  356,    0,    0,    0,  356,    0,    0,    0,    0,    0,
+  356,    0,  356,  356,    0,    0,  356,    0,  356,  356,
+  356,  356,  356,    0,  356,  356,  356,  356,  356,  356,
+  356,  356,  356,  356,  356,  356,  356,  356,  356,  356,
+    0,    0,    0,    0,  356,  356,  356,   53,  356,  356,
+  356,    0,  356,  356,  356,    0,    0,  356,    0,  356,
+    0,    0,  356,  356,  356,  356,    0,    0,  356,  356,
+  356,    0,    0,  356,    0,    0,  356,  356,  356,  356,
+  356,  356,  356,  356,    0,  356,  356,  356,  356,  356,
+    0,    0,  356,    0,   69,    0,    0,    0,    0,  356,
+  356,  356,    0,    0,    0,    0,    0,    0,  356,  356,
+    0,    0,    0,    0,   69,    0,    0,   69,   69,   69,
+   69,   69,   69,   69,    0,    0,   69,   69,   69,    0,
+    0,    0,    0,   69,   69,    0,    0,    0,   69,   69,
+    0,    0,  169,    0,    0,    0,    0,    0,    0,   69,
+    0,    0,  169,   69,   69,    0,    0,    0,   69,    0,
+    0,    0,    0,    0,   69,    0,   69,   69,    0,    0,
+   69,    0,   69,   69,   69,   69,   69,    0,   69,   69,
+   69,   69,   69,   69,   69,   69,   69,   69,   69,   69,
+   69,   69,   69,   69,    0,    0,    0,    0,   69,   69,
+   69,  169,   69,   69,   69,    0,   69,   69,   69,    0,
+    0,   69,    0,   69,    0,    0,   69,   69,   69,   69,
+    0,    0,   69,   69,   69,    0,    0,   69,    0,    0,
+   69,   69,   69,   69,   69,   69,   69,   69,    0,   69,
+   69,   69,   69,   69,   53,    0,   69,    0,    0,    0,
+    0,    0,    0,   69,   69,   69,    0,    0,    0,    0,
+    0,    0,   69,   69,   53,    0,    0,   53,   53,   53,
+   53,   53,   53,   53,    0,    0,   53,   53,   53,    0,
+    0,    0,    0,   53,   53,    0,    0,    0,   53,   53,
+    0,    0,  177,    0,    0,    0,    0,    0,    0,   53,
+    0,    0,  177,   53,   53,    0,    0,    0,   53,    0,
+    0,    0,    0,    0,   53,    0,   53,   53,    0,    0,
+   53,    0,   53,   53,   53,   53,   53,    0,   53,   53,
+   53,   53,   53,   53,   53,   53,   53,   53,   53,   53,
+   53,   53,   53,   53,    0,    0,    0,    0,   53,   53,
+   53,  177,   53,   53,   53,    0,   53,   53,   53,    0,
+    0,   53,    0,   53,    0,    0,   53,   53,   53,   53,
+    0,    0,   53,   53,   53,    0,    0,   53,    0,    0,
+   53,   53,   53,   53,   53,   53,   53,   53,    0,   53,
+   53,   53,   53,   53,    0,    0,   53,    0,  169,    0,
+    0,    0,    0,   53,   53,   53,    0,    0,    0,    0,
+    0,    0,   53,   53,    0,    0,    0,    0,  169,    0,
+    0,  169,  169,  169,  169,  169,  169,  169,    0,    0,
+  169,  169,  169,    0,    0,    0,    0,  169,  169,    0,
+    0,    0,  169,  169,    0,    0,   55,    0,    0,    0,
+    0,    0,    0,  169,    0,    0,   55,  169,  169,    0,
+    0,    0,  169,    0,    0,    0,    0,    0,  169,    0,
+  169,  169,    0,    0,  169,    0,  169,  169,  169,  169,
+  169,    0,  169,  169,  169,  169,  169,  169,  169,  169,
+  169,  169,  169,  169,  169,  169,  169,  169,    0,    0,
+    0,    0,  169,  169,  169,   55,  169,  169,  169,    0,
+  169,  169,  169,    0,    0,  169,    0,  169,    0,    0,
+  169,  169,  169,  169,    0,    0,  169,  169,  169,    0,
+    0,  169,    0,    0,  169,  169,  169,  169,  169,  169,
+  169,  169,    0,  169,  169,  169,  169,  169,  177,    0,
+  169,    0,    0,    0,    0,    0,    0,  169,  169,  169,
+    0,    0,    0,    0,    0,    0,  169,  169,  177,    0,
+    0,  177,  177,  177,  177,  177,  177,  177,    0,    0,
+  177,  177,  177,    0,    0,    0,    0,  177,  177,    0,
+    0,    0,  177,  177,    0,    0,  361,    0,    0,    0,
+    0,    0,    0,  177,    0,    0,  361,  177,  177,    0,
+    0,    0,  177,    0,    0,    0,    0,    0,  177,    0,
+  177,  177,    0,    0,  177,    0,  177,  177,  177,  177,
+  177,    0,  177,  177,  177,  177,  177,  177,  177,  177,
+  177,  177,  177,  177,  177,  177,  177,  177,    0,    0,
+    0,    0,  177,  177,  177,  361,  177,  177,  177,    0,
+  177,  177,  177,    0,    0,  177,    0,  177,    0,    0,
+  177,  177,  177,  177,    0,    0,  177,  177,  177,    0,
+    0,  177,    0,    0,  177,  177,  177,  177,  177,  177,
+  177,  177,    0,  177,  177,  177,  177,  177,    0,    0,
+  177,    0,   55,    0,    0,    0,    0,  177,  177,  177,
+    0,    0,    0,    0,    0,    0,  177,  177,    0,    0,
+    0,    0,   55,    0,    0,   55,   55,   55,   55,   55,
+   55,   55,    0,    0,   55,   55,   55,    0,    0,    0,
+    0,   55,   55,    0,    0,    0,   55,   55,    0,    0,
+  164,    0,    0,    0,    0,    0,    0,   55,    0,    0,
+  164,   55,   55,    0,    0,    0,   55,    0,    0,    0,
+    0,    0,   55,    0,   55,   55,    0,    0,   55,    0,
+   55,   55,   55,   55,   55,    0,   55,   55,   55,   55,
+   55,   55,   55,   55,   55,   55,   55,   55,   55,   55,
+   55,   55,    0,    0,    0,    0,   55,   55,   55,  164,
+   55,   55,   55,    0,   55,   55,   55,    0,    0,   55,
+    0,   55,    0,    0,   55,   55,   55,   55,    0,    0,
+   55,   55,   55,    0,    0,   55,    0,    0,   55,   55,
+   55,   55,   55,   55,   55,   55,    0,   55,   55,   55,
+   55,   55,  361,    0,   55,    0,    0,    0,    0,    0,
+    0,   55,   55,   55,    0,    0,    0,    0,    0,    0,
+   55,   55,  361,    0,    0,  361,  361,  361,  361,  361,
+  361,  361,    0,    0,  361,  361,  361,    0,    0,    0,
+    0,  361,  361,    0,    0,    0,  361,  361,    0,    0,
+  405,    0,    0,    0,    0,    0,    0,  361,    0,    0,
+  405,  361,  361,    0,    0,    0,  361,    0,    0,    0,
+    0,    0,  361,    0,  361,  361,    0,    0,  361,    0,
+  361,  361,  361,  361,  361,    0,  361,  361,  361,  361,
+  361,  361,  361,  361,  361,  361,  361,  361,  361,  361,
+  361,  361,    0,    0,    0,    0,  361,  361,  361,  405,
+  361,  361,  361,    0,  361,  361,  361,    0,    0,  361,
+    0,  361,    0,    0,  361,  361,  361,  361,    0,    0,
+  361,  361,  361,    0,    0,  361,    0,    0,  361,  361,
+  361,  361,  361,  361,  361,  361,    0,  361,  361,  361,
+  361,  361,    0,    0,  361,    0,  164,    0,    0,    0,
+    0,  361,  361,  361,    0,    0,    0,    0,    0,    0,
+  361,  361,    0,    0,    0,    0,  164,    0,    0,  164,
+  164,  164,  164,  164,  164,  164,    0,    0,  164,  164,
+  164,    0,    0,    0,    0,  164,  164,    0,    0,    0,
+  164,  164,    0,    0,  469,    0,    0,    0,    0,    0,
+    0,  164,    0,    0,  469,  164,  164,    0,    0,    0,
+  164,    0,    0,    0,    0,    0,  164,    0,  164,  164,
+    0,    0,  164,    0,  164,  164,  164,  164,  164,    0,
+  164,  164,  164,  164,  164,  164,  164,  164,  164,  164,
+  164,  164,  164,  164,  164,  164,    0,    0,    0,    0,
+  164,  164,  164,  469,  164,  164,  164,    0,  164,  164,
+  164,    0,    0,  164,    0,  164,    0,    0,  164,  164,
+  164,  164,    0,    0,  164,  164,  164,    0,    0,  164,
+    0,    0,  164,  164,  164,  164,  164,  164,  164,  164,
+    0,  164,  164,  164,  164,  164,  405,    0,  164,    0,
+    0,    0,    0,    0,    0,  164,  164,  164,    0,    0,
+    0,    0,    0,    0,  164,  164,  405,    0,    0,  405,
+  405,  405,  405,  405,  405,  405,    0,    0,  405,  405,
+  405,    0,    0,    0,    0,  405,  405,    0,    0,    0,
+  405,  405,    0,    0,   34,    0,    0,    0,    0,    0,
+    0,  405,    0,    0,   34,  405,  405,    0,    0,    0,
+  405,    0,    0,    0,    0,    0,  405,    0,  405,  405,
+    0,    0,  405,    0,  405,  405,  405,  405,  405,    0,
+  405,  405,  405,  405,  405,  405,  405,  405,  405,  405,
+  405,  405,  405,  405,  405,  405,    0,    0,    0,    0,
+  405,  405,  405,   34,  405,  405,  405,    0,  405,  405,
+  405,    0,    0,  405,    0,  405,    0,    0,  405,  405,
+  405,  405,    0,    0,  405,  405,  405,    0,    0,  405,
+    0,    0,  405,  405,  405,  405,  405,  405,  405,  405,
+    0,  405,  405,  405,  405,  405,    0,    0,  405,    0,
+  469,    0,    0,    0,    0,  405,  405,  405,    0,    0,
+    0,    0,    0,    0,  405,  405,    0,    0,    0,    0,
+  469,    0,    0,  469,  469,  469,  469,  469,  469,  469,
+    0,    0,  469,  469,  469,    0,    0,    0,    0,  469,
+  469,    0,    0,    0,  469,  469,    0,    0,  151,    0,
+    0,    0,    0,    0,    0,  469,    0,    0,  151,  469,
+  469,    0,    0,    0,  469,    0,    0,    0,    0,    0,
+  469,    0,  469,  469,    0,    0,  469,    0,  469,  469,
+  469,  469,  469,    0,  469,  469,  469,  469,  469,  469,
+  469,  469,  469,  469,  469,  469,  469,  469,  469,  469,
+    0,    0,    0,    0,  469,  469,  469,  151,  469,  469,
+  469,    0,  469,  469,  469,    0,    0,  469,    0,  469,
+    0,    0,  469,  469,  469,  469,    0,    0,  469,  469,
+  469,    0,    0,  469,    0,    0,  469,  469,  469,  469,
+  469,  469,  469,  469,    0,  469,  469,  469,  469,  469,
+   34,    0,  469,    0,    0,    0,    0,    0,    0,  469,
+  469,  469,    0,    0,    0,    0,    0,    0,  469,  469,
+   34,    0,    0,   34,   34,   34,   34,   34,   34,   34,
+    0,    0,   34,   34,   34,    0,    0,    0,    0,   34,
+   34,    0,    0,    0,   34,   34,    0,    0,  149,    0,
+    0,    0,    0,    0,    0,   34,    0,    0,  149,   34,
+   34,    0,    0,    0,   34,    0,    0,    0,    0,    0,
+   34,    0,   34,   34,    0,    0,   34,    0,   34,   34,
+   34,   34,   34,    0,   34,   34,   34,   34,   34,   34,
+   34,   34,   34,   34,   34,   34,   34,   34,   34,   34,
+    0,    0,    0,    0,   34,   34,   34,  149,   34,   34,
+   34,    0,   34,   34,   34,    0,    0,   34,    0,   34,
+    0,    0,   34,   34,   34,   34,    0,    0,   34,   34,
+   34,    0,    0,   34,    0,    0,   34,   34,   34,   34,
+   34,   34,   34,   34,    0,   34,   34,   34,   34,   34,
+    0,    0,   34,    0,  151,    0,    0,    0,    0,   34,
+   34,   34,    0,    0,    0,    0,    0,    0,   34,   34,
+    0,    0,    0,    0,  151,    0,    0,  151,  151,  151,
+  151,  151,  151,  151,    0,    0,  151,  151,  151,    0,
+    0,    0,    0,  151,  151,    0,    0,    0,  151,  151,
+    0,    0,   67,    0,    0,    0,    0,    0,    0,  151,
+    0,    0,   67,  151,  151,    0,    0,    0,  151,    0,
+    0,    0,    0,    0,  151,    0,  151,  151,    0,    0,
+  151,    0,  151,  151,  151,  151,  151,    0,  151,  151,
+  151,  151,  151,  151,  151,  151,  151,  151,  151,  151,
+  151,  151,  151,  151,    0,    0,    0,    0,  151,  151,
+  151,   67,  151,  151,  151,    0,  151,  151,  151,    0,
+    0,  151,    0,  151,    0,    0,  151,  151,  151,  151,
+    0,    0,  151,  151,  151,    0,    0,  151,    0,    0,
+  151,  151,  151,  151,  151,  151,  151,  151,    0,  151,
+  151,  151,  151,  151,  149,    0,  151,    0,    0,    0,
+    0,    0,    0,  151,  151,  151,    0,    0,    0,    0,
+    0,    0,  151,  151,  149,    0,    0,  149,  149,  149,
+  149,  149,  149,  149,    0,    0,  149,  149,  149,    0,
+    0,    0,    0,  149,  149,    0,    0,    0,  149,  149,
+    0,    0,   68,    0,    0,    0,    0,    0,    0,  149,
+    0,    0,   68,  149,  149,    0,    0,    0,  149,    0,
+    0,    0,    0,    0,  149,    0,  149,  149,    0,    0,
+  149,    0,  149,  149,  149,  149,  149,    0,  149,  149,
+  149,  149,  149,  149,  149,  149,  149,  149,  149,  149,
+  149,  149,  149,  149,    0,    0,    0,    0,  149,  149,
+  149,   68,  149,  149,  149,    0,  149,  149,  149,    0,
+    0,  149,    0,  149,    0,    0,  149,  149,  149,  149,
+    0,    0,  149,  149,  149,    0,    0,  149,    0,    0,
+  149,  149,  149,  149,  149,  149,  149,  149,    0,  149,
+  149,  149,  149,  149,    0,    0,  149,    0,   67,    0,
+    0,    0,    0,  149,  149,  149,    0,    0,    0,    0,
+    0,    0,  149,  149,    0,    0,    0,    0,   67,    0,
+    0,   67,   67,   67,   67,   67,   67,   67,    0,    0,
+   67,   67,   67,    0,    0,    0,    0,   67,   67,    0,
+    0,    0,   67,   67,    0,    0,   40,    0,    0,    0,
+    0,    0,    0,   67,    0,    0,   40,   67,   67,    0,
+    0,    0,   67,    0,    0,    0,    0,    0,   67,    0,
+   67,   67,    0,    0,   67,    0,   67,   67,   67,   67,
+   67,    0,   67,   67,   67,   67,   67,   67,   67,   67,
+   67,   67,   67,   67,   67,   67,   67,   67,    0,    0,
+    0,    0,   67,   67,   67,   40,   67,   67,   67,    0,
+   67,   67,   67,    0,    0,   67,    0,   67,    0,    0,
+   67,   67,   67,   67,    0,    0,   67,   67,   67,    0,
+    0,   67,    0,    0,   67,   67,   67,   67,   67,   67,
+   67,   67,    0,   67,   67,   67,   67,   67,   68,    0,
+   67,    0,    0,    0,    0,    0,    0,   67,   67,   67,
+    0,    0,    0,    0,    0,    0,   67,   67,   68,    0,
+    0,   68,   68,   68,   68,   68,   68,   68,    0,    0,
+   68,   68,   68,    0,    0,    0,    0,   68,   68,    0,
+    0,    0,   68,   68,    0,    0,  437,    0,    0,    0,
+    0,    0,    0,   68,    0,    0,  437,   68,   68,    0,
+    0,    0,   68,    0,    0,    0,    0,    0,   68,    0,
+   68,   68,    0,    0,   68,    0,   68,   68,   68,   68,
+   68,    0,   68,   68,   68,   68,   68,   68,   68,   68,
+   68,   68,   68,   68,   68,   68,   68,   68,    0,    0,
+    0,    0,   68,   68,   68,  437,   68,   68,   68,    0,
+   68,   68,   68,    0,    0,   68,    0,   68,    0,    0,
+   68,   68,   68,   68,    0,    0,   68,   68,   68,    0,
+    0,   68,    0,    0,   68,   68,   68,   68,   68,   68,
+   68,   68,    0,   68,   68,   68,   68,   68,    0,    0,
+   68,    0,   40,    0,    0,    0,    0,   68,   68,   68,
+    0,    0,    0,    0,    0,    0,   68,   68,    0,    0,
+    0,    0,   40,    0,    0,   40,   40,   40,   40,   40,
+   40,   40,    0,    0,   40,   40,   40,    0,    0,    0,
+    0,   40,   40,    0,    0,    0,   40,   40,    0,    0,
+  438,    0,    0,    0,    0,    0,    0,   40,    0,    0,
+  438,   40,   40,    0,    0,    0,   40,    0,    0,    0,
+    0,    0,   40,    0,   40,   40,    0,    0,   40,    0,
+   40,   40,   40,   40,   40,    0,   40,   40,   40,   40,
+   40,   40,   40,   40,   40,   40,   40,   40,   40,   40,
+   40,   40,    0,    0,    0,    0,   40,   40,   40,  438,
+   40,   40,   40,    0,   40,   40,   40,    0,    0,   40,
+    0,   40,    0,    0,   40,   40,   40,   40,    0,    0,
+   40,   40,   40,    0,    0,   40,    0,    0,   40,   40,
+   40,   40,   40,   40,   40,   40,    0,   40,   40,   40,
+   40,   40,  437,    0,   40,    0,    0,    0,    0,    0,
+    0,   40,   40,   40,    0,    0,    0,    0,    0,    0,
+   40,   40,  437,    0,    0,  437,  437,  437,  437,  437,
+  437,  437,    0,    0,  437,  437,  437,    0,    0,    0,
+    0,  437,  437,    0,    0,    0,  437,  437,    0,    0,
+  464,    0,    0,    0,    0,    0,    0,  437,    0,    0,
+  464,  437,  437,    0,    0,    0,  437,    0,    0,    0,
+    0,    0,  437,    0,  437,  437,    0,    0,  437,    0,
+  437,  437,  437,  437,  437,    0,  437,  437,  437,  437,
+  437,  437,  437,  437,  437,  437,  437,  437,  437,  437,
+  437,  437,    0,    0,    0,    0,  437,  437,  437,  464,
+  437,  437,  437,    0,  437,  437,  437,    0,    0,  437,
+    0,  437,    0,    0,  437,  437,  437,  437,    0,    0,
+  437,  437,  437,    0,    0,  437,    0,    0,  437,  437,
+  437,  437,  437,  437,  437,  437,    0,  437,  437,  437,
+  437,  437,    0,    0,  437,    0,  438,    0,    0,    0,
+    0,  437,  437,  437,    0,    0,    0,    0,    0,    0,
+  437,  437,    0,    0,    0,    0,  438,    0,    0,  438,
+  438,  438,  438,  438,  438,  438,    0,    0,  438,  438,
+  438,    0,    0,    0,    0,  438,  438,    0,    0,    0,
+  438,  438,    0,    0,   43,    0,    0,    0,    0,    0,
+    0,  438,    0,    0,   43,  438,  438,    0,    0,    0,
+  438,    0,    0,    0,    0,    0,  438,    0,  438,  438,
+    0,    0,  438,    0,  438,  438,  438,  438,  438,    0,
+  438,  438,  438,  438,  438,  438,  438,  438,  438,  438,
+  438,  438,  438,  438,  438,  438,    0,    0,    0,    0,
+  438,  438,  438,   43,  438,  438,  438,    0,  438,  438,
+  438,    0,    0,  438,    0,  438,    0,    0,  438,  438,
+  438,  438,    0,    0,  438,  438,  438,    0,    0,  438,
+    0,    0,  438,  438,  438,  438,  438,  438,  438,  438,
+    0,  438,  438,  438,  438,  438,  464,    0,  438,    0,
+    0,    0,    0,    0,    0,  438,  438,  438,    0,    0,
+    0,    0,    0,    0,  438,  438,  464,    0,    0,  464,
+  464,  464,  464,  464,  464,  464,    0,    0,  464,  464,
+  464,    0,    0,    0,    0,  464,  464,    0,    0,    0,
+  464,  464,    0,    0,  362,    0,    0,    0,    0,    0,
+    0,  464,    0,    0,  362,  464,  464,    0,    0,    0,
+  464,    0,    0,    0,    0,    0,  464,    0,  464,  464,
+    0,    0,  464,    0,  464,  464,  464,  464,  464,    0,
+  464,  464,  464,  464,  464,  464,  464,  464,  464,  464,
+  464,  464,  464,  464,  464,  464,    0,    0,    0,    0,
+  464,  464,  464,  362,  464,  464,  464,    0,  464,  464,
+  464,    0,    0,  464,    0,  464,    0,    0,  464,  464,
+  464,  464,    0,    0,  464,  464,  464,    0,    0,  464,
+    0,    0,  464,  464,  464,  464,  464,  464,  464,  464,
+    0,  464,  464,  464,  464,  464,    0,    0,  464,    0,
+   43,    0,    0,    0,    0,  464,  464,  464,    0,    0,
+    0,    0,    0,    0,  464,  464,    0,    0,    0,    0,
+   43,    0,    0,   43,   43,   43,   43,   43,   43,   43,
+    0,    0,   43,   43,   43,    0,    0,    0,    0,   43,
+   43,    0,    0,    0,   43,   43,    0,    0,  470,    0,
+    0,    0,    0,    0,    0,   43,    0,    0,  470,   43,
+   43,    0,    0,    0,   43,    0,    0,    0,    0,    0,
+   43,    0,   43,   43,    0,    0,   43,    0,   43,   43,
+   43,   43,   43,    0,   43,   43,   43,   43,   43,   43,
+   43,   43,   43,   43,   43,   43,   43,   43,   43,   43,
+    0,    0,    0,    0,   43,   43,   43,  470,   43,   43,
+   43,    0,   43,   43,   43,    0,    0,   43,    0,   43,
+    0,    0,   43,   43,   43,   43,    0,    0,   43,   43,
+   43,    0,    0,   43,    0,    0,   43,   43,   43,   43,
+   43,   43,   43,   43,    0,   43,   43,   43,   43,   43,
+  362,    0,   43,    0,    0,    0,    0,    0,    0,   43,
+   43,   43,    0,    0,    0,    0,    0,    0,   43,   43,
+  362,    0,    0,  362,  362,  362,  362,  362,  362,  362,
+    0,    0,  362,  362,  362,    0,    0,    0,    0,  362,
+  362,    0,    0,    0,  362,  362,    0,    0,  364,    0,
+    0,    0,    0,    0,    0,  362,    0,    0,  364,  362,
+  362,    0,    0,    0,  362,    0,    0,    0,    0,    0,
+  362,    0,  362,  362,    0,    0,  362,    0,  362,  362,
+  362,  362,  362,    0,  362,  362,  362,  362,  362,  362,
+  362,  362,  362,  362,  362,  362,  362,  362,  362,  362,
+    0,    0,    0,    0,  362,  362,  362,  364,  362,  362,
+  362,    0,  362,  362,  362,    0,    0,  362,    0,  362,
+    0,    0,  362,  362,  362,  362,    0,    0,  362,  362,
+  362,    0,    0,  362,    0,    0,  362,  362,  362,  362,
+  362,  362,  362,  362,    0,  362,  362,  362,  362,  362,
+    0,    0,  362,    0,  470,    0,    0,    0,    0,  362,
+  362,  362,    0,    0,    0,    0,    0,    0,  362,  362,
+    0,    0,    0,    0,  470,    0,    0,  470,  470,  470,
+  470,  470,  470,  470,    0,    0,  470,  470,  470,    0,
+    0,    0,    0,  470,  470,    0,    0,    0,  470,  470,
+    0,    0,  408,    0,    0,    0,    0,    0,    0,  470,
+    0,    0,  408,  470,  470,    0,    0,    0,  470,    0,
+    0,    0,    0,    0,  470,    0,  470,  470,    0,    0,
+  470,    0,  470,  470,  470,  470,  470,    0,  470,  470,
+  470,  470,  470,  470,  470,  470,  470,  470,  470,  470,
+  470,  470,  470,  470,    0,    0,    0,    0,  470,  470,
+  470,  408,  470,  470,  470,    0,  470,  470,  470,    0,
+    0,  470,    0,  470,    0,    0,  470,  470,  470,  470,
+    0,    0,  470,  470,  470,    0,    0,  470,    0,    0,
+  470,  470,  470,  470,  470,  470,  470,  470,    0,  470,
+  470,  470,  470,  470,  364,    0,  470,    0,    0,    0,
+    0,    0,    0,  470,  470,  470,    0,    0,    0,    0,
+    0,    0,  470,  470,  364,    0,    0,  364,  364,  364,
+  364,  364,  364,  364,    0,    0,  364,  364,  364,    0,
+    0,    0,    0,  364,  364,    0,    0,    0,  364,  364,
+    0,    0,  545,    0,    0,    0,    0,    0,    0,  364,
+    0,    0,  545,  364,  364,    0,    0,    0,  364,    0,
+    0,    0,    0,    0,  364,    0,  364,  364,    0,    0,
+  364,    0,  364,  364,  364,  364,  364,    0,  364,  364,
+  364,  364,  364,  364,  364,  364,  364,  364,  364,  364,
+  364,  364,  364,  364,    0,    0,    0,    0,  364,  364,
+  364,  545,  364,  364,  364,    0,  364,  364,  364,    0,
+    0,  364,    0,  364,    0,    0,  364,  364,  364,  364,
+    0,    0,  364,  364,  364,    0,    0,  364,    0,    0,
+  364,  364,  364,  364,  364,  364,  364,  364,    0,  364,
+  364,  364,  364,  364,    0,    0,  364,    0,  408,    0,
+    0,    0,    0,  364,  364,  364,    0,    0,    0,    0,
+    0,    0,  364,  364,    0,    0,    0,    0,  408,    0,
+    0,  408,  408,  408,  408,  408,  408,  408,    0,    0,
+  408,  408,  408,    0,    0,    0,    0,  408,  408,    0,
+    0,    0,  408,  408,    0,    0,  409,    0,    0,    0,
+    0,    0,    0,  408,    0,    0,  409,  408,  408,    0,
+    0,    0,  408,    0,    0,    0,    0,    0,  408,    0,
+  408,  408,    0,    0,  408,    0,  408,  408,  408,  408,
+  408,    0,  408,  408,  408,  408,  408,  408,  408,  408,
+  408,  408,  408,  408,  408,  408,  408,  408,    0,    0,
+    0,    0,  408,  408,  408,  409,  408,  408,  408,    0,
+  408,  408,  408,    0,    0,  408,    0,  408,    0,    0,
+  408,  408,  408,  408,    0,    0,  408,  408,  408,    0,
+    0,  408,    0,    0,  408,  408,  408,  408,  408,  408,
+  408,  408,    0,  408,  408,  408,  408,  408,  545,    0,
+  408,    0,    0,    0,    0,    0,    0,  408,  408,  408,
+    0,    0,    0,    0,    0,    0,  408,  408,  545,    0,
+    0,  545,  545,  545,  545,  545,  545,  545,    0,    0,
+  545,  545,  545,    0,    0,    0,    0,  545,  545,    0,
+    0,    0,  545,  545,    0,    0,  414,    0,    0,    0,
+    0,    0,    0,  545,    0,    0,  414,  545,  545,    0,
+    0,    0,  545,    0,    0,    0,    0,    0,  545,    0,
+  545,  545,    0,    0,  545,    0,  545,  545,  545,  545,
+  545,    0,  545,  545,  545,  545,  545,  545,  545,  545,
+  545,  545,  545,  545,  545,  545,  545,  545,    0,    0,
+    0,    0,  545,  545,  545,  414,  545,  545,  545,    0,
+  545,  545,  545,    0,    0,  545,    0,  545,    0,    0,
+  545,  545,  545,  545,    0,    0,  545,  545,  545,    0,
+    0,  545,    0,    0,  545,  545,  545,  545,  545,  545,
+  545,  545,    0,  545,  545,  545,  545,  545,    0,    0,
+  545,    0,  409,    0,    0,    0,    0,  545,  545,  545,
+    0,    0,    0,    0,    0,    0,  545,  545,    0,    0,
+    0,    0,  409,    0,    0,  409,  409,  409,  409,  409,
+  409,  409,    0,    0,  409,  409,  409,    0,    0,    0,
+    0,  409,  409,    0,    0,    0,  409,  409,    0,    8,
+    0,    0,    0,    0,    0,    0,    0,  409,    0,    8,
+    0,  409,  409,    0,    0,    0,  409,    0,    0,    0,
+    0,    0,  409,    0,  409,  409,    0,    0,  409,    0,
+  409,  409,  409,  409,  409,    0,  409,  409,  409,  409,
+  409,  409,  409,  409,  409,  409,  409,  409,  409,  409,
+  409,  409,    0,    0,    0,    0,  409,  409,  409,    0,
+  409,  409,  409,    0,  409,  409,  409,    0,    0,  409,
+    0,  409,    0,    0,  409,  409,  409,  409,    0,    0,
+  409,  409,  409,    0,    0,  409,    0,    0,  409,  409,
+  409,  409,  409,  409,  409,  409,    0,  409,  409,  409,
+  409,  409,  414,    0,  409,    0,    0,    0,    0,    0,
+    0,  409,  409,  409,    0,    0,    0,    0,    0,    0,
+  409,  409,  414,    0,    0,  414,  414,  414,  414,  414,
+  414,  414,    0,    0,  414,  414,  414,    0,    0,    0,
+    0,  414,  414,    0,    0,    0,  414,  414,    0,    0,
+  410,    0,    0,    0,    0,    0,    0,  414,    0,    0,
+  410,  414,  414,    0,    0,    0,  414,    0,    0,    0,
+    0,    0,  414,    0,  414,  414,    0,    0,  414,    0,
+  414,  414,  414,  414,  414,    0,  414,  414,  414,  414,
+  414,  414,  414,  414,  414,  414,  414,  414,  414,  414,
+  414,  414,    0,    0,    0,    0,  414,  414,  414,  410,
+  414,  414,  414,    0,  414,  414,  414,    0,    0,  414,
+    0,  414,    0,    0,  414,  414,  414,  414,    0,    0,
+  414,  414,  414,    0,    0,  414,    0,    0,  414,  414,
+  414,  414,  414,  414,  414,  414,    0,  414,  414,  414,
+  414,  414,    0,    0,  414,    8,    0,    0,    0,    0,
+    0,  414,  414,    0,    0,    0,    0,    0,    0,    0,
+  414,  414,    0,    0,    0,    8,    0,    0,    8,    8,
+    8,    8,    8,    8,    8,    0,    0,    8,    8,    8,
+    0,    0,    0,    0,    8,    8,    0,    0,    0,    8,
+    8,    0,    0,  407,    0,    0,    0,    0,    0,    0,
+    8,    0,    0,  407,    8,    8,    0,    0,    0,    8,
+    0,    0,    0,    0,    0,    8,    0,    8,    8,    0,
+    0,    8,    0,    8,    8,    8,    8,    8,    0,    8,
+    8,    8,    8,    8,    8,    8,    8,    8,    8,    8,
+    8,    8,    8,    8,    8,    0,    0,    0,    0,    8,
+    8,    8,  407,    8,    8,    8,    0,    8,    8,    8,
+    0,    0,    8,    0,    8,    0,    0,    8,    8,    8,
+    8,    0,    0,    8,    8,    8,    0,    0,    8,    0,
+    0,    8,    8,    8,    8,    8,    8,    8,    8,    0,
+    8,    8,    8,    8,    8,    0,  410,    8,    0,    0,
+    0,    0,    0,    0,    8,    8,    8,    0,    0,    0,
+    0,    0,    0,    8,    8,    0,  410,    0,    0,  410,
+  410,  410,  410,  410,  410,  410,    0,    0,  410,  410,
+  410,    0,    0,    0,    0,  410,  410,    0,    0,    0,
+  410,  410,    0,    0,  353,    0,    0,    0,    0,    0,
+    0,  410,    0,    0,  353,  410,  410,    0,    0,    0,
+  410,    0,    0,    0,    0,    0,  410,    0,  410,  410,
+    0,    0,  410,    0,  410,  410,  410,  410,  410,    0,
+  410,  410,  410,  410,  410,  410,  410,  410,  410,  410,
+  410,  410,  410,  410,  410,  410,    0,    0,    0,    0,
+  410,  410,  410,  353,  410,  410,  410,    0,  410,  410,
+  410,    0,    0,  410,    0,  410,    0,    0,  410,  410,
+  410,  410,    0,    0,  410,  410,  410,    0,    0,  410,
+    0,    0,  410,  410,  410,  410,  410,  410,  410,  410,
+    0,  410,  410,  410,  410,  410,    0,    0,  410,  407,
+    0,    0,    0,    0,    0,  410,  410,  410,    0,    0,
+    0,    0,    0,    0,    0,  410,    0,    0,    0,  407,
+    0,    0,  407,  407,  407,  407,  407,  407,  407,    0,
+    0,  407,  407,  407,    0,    0,    0,    0,  407,  407,
+    0,    0,    0,  407,  407,    0,    0,   24,    0,    0,
+    0,    0,    0,    0,  407,    0,    0,   24,  407,  407,
+    0,    0,    0,  407,    0,    0,    0,    0,    0,  407,
+    0,  407,  407,    0,    0,  407,    0,  407,  407,  407,
+  407,  407,    0,  407,  407,  407,  407,  407,  407,  407,
+  407,  407,  407,  407,  407,  407,  407,  407,  407,    0,
+    0,    0,    0,  407,  407,  407,   24,  407,  407,  407,
+    0,  407,  407,  407,    0,    0,  407,    0,  407,    0,
+    0,  407,  407,  407,  407,    0,    0,  407,  407,  407,
+    0,    0,  407,    0,    0,  407,  407,  407,  407,  407,
+  407,  407,  407,    0,  407,  407,  407,  407,  407,    0,
+  353,  407,    0,    0,    0,    0,    0,    0,  407,  407,
+    0,    0,    0,    0,    0,    0,    0,  407,  407,    0,
+  353,    0,    0,  353,  353,  353,  353,  353,  353,  353,
+    0,    0,  353,  353,  353,    0,    0,    0,    0,  353,
+  353,    0,    0,   22,  353,  353,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  353,    0,    0,    0,  353,
+  353,    0,    0,    0,  353,    0,    0,    0,    0,    0,
+  353,    0,  353,  353,    0,    0,  353,    0,  353,  353,
+  353,  353,  353,    0,  353,  353,  353,  353,  353,  353,
+  353,  353,  353,  353,  353,  353,  353,  353,  353,  353,
+    0,    0,   22,    0,  353,  353,  353,    0,  353,  353,
+  353,    0,  353,  353,  353,    0,    0,  353,    0,  353,
+    0,    0,  353,  353,  353,  353,    0,    0,  353,  353,
+  353,    0,    0,  353,    0,    0,  353,  353,  353,  353,
+    0,  353,  353,  353,    0,  353,  353,  353,  353,  353,
+    0,    0,  353,   24,    0,    0,    0,    0,    0,  353,
+  353,    0,    0,    0,    0,    0,    0,    0,    0,  353,
+    0,    0,    0,   24,    0,    0,   24,   24,   24,   24,
+   24,   24,   24,    0,    0,   24,   24,   24,    0,    0,
+    0,    0,   24,   24,    0,    0,    0,   24,   24,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,   24,    0,
+    0,    0,   24,   24,    0,    0,    0,   24,    0,    0,
+    0,    0,    0,   24,    0,   24,   24,    0,    0,   24,
+    0,   24,   24,   24,   24,   24,    0,   24,   24,   24,
+   24,   24,   24,   24,   24,   24,   24,   24,   24,   24,
+   24,   24,   24,    0,    0,    0,    0,   24,   24,   24,
+    0,   24,   24,   24,    0,   24,   24,   24,    0,    0,
+   24,    0,   24,    0,    0,   24,   24,   24,   24,    0,
+    0,   24,   24,   24,    0,    0,   24,    0,    0,   24,
+   24,   24,   24,   24,   24,   24,   24,    0,   24,   24,
+   24,   24,   24,    0,    0,   24,  752,    0,  750,  149,
+    0,  150,   24,   24,   24,    0,    0,    0,    0,   22,
+    0,   24,   22,   22,   22,   22,    0,  574,   22,    0,
+    0,   22,   22,   22,    0,    0,    0,    0,   22,   22,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,   22,    0,    0,    0,   22,   22,
+    0,    0,    0,   22,    0,    0,    0,    0,    0,   22,
+    0,   22,   22,    0,    0,   22,    0,   22,   22,   22,
+   22,   22,    0,   22,   22,   22,   22,   22,   22,   22,
+   22,   22,   22,   22,   22,   22,   22,   22,   22,    0,
+    0,    0,    0,   22,   22,   22,    0,   22,   22,   22,
+    0,   22,   22,   22,    0,    0,   22,    0,   22,    0,
+    0,   22,   22,   22,   22,    0,    0,   22,   22,   22,
+    0,    0,   22,    0,    0,    0,   22,   22,   22,   22,
+   22,   22,   22,    0,   22,   22,   22,   22,   22,    0,
+    0,   22,  188,    0,  538,  149,    0,  150,   22,   22,
+   22,  247,  247,  247,    0,  247,    0,   22,    0,    0,
+    0,    0,    0,  543,    0,    0,    0,    0,  247,    0,
+  247,  247,  247,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  188,    0,    0,  149,    0,  150,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  657,    0,    0,    0,    0,    0,    0,    0,  148,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  751,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  151,  152,    0,    0,    0,  153,  154,  155,
+  156,    0,    0,    0,    0,    0,    0,    0,    0,  157,
+  158,  159,  160,  161,  162,  163,  164,    0,  165,  166,
+  167,    0,    0,  168,  169,  170,    0,  171,  172,  173,
+  174,  175,    0,  176,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  188,
+    0,  708,  149,    0,  150,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  707,  177,    0,
+    0,    0,    0,    0,    0,    0,  178,  179,    0,    0,
+    0,    0,  180,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  181,  182,    0,  148,  183,  184,  185,  186,
+  247,  247,  247,   89,  247,  247,  247,  247,  247,  247,
+  187,    0,  247,  247,    0,    0,    0,    0,  151,  152,
+    0,    0,    0,  153,  154,  155,  156,    0,    0,    0,
+    0,    0,    0,    0,    0,  157,  158,  159,  160,  161,
+  162,  163,  164,  148,  165,  166,  167,    0,    0,  168,
+  169,  170,  658,  171,  172,  173,  174,  175,    0,  176,
+    0,    0,    0,    0,    0,    0,  151,  152,    0,    0,
+    0,  153,  154,  155,  156,    0,    0,    0,    0,    0,
+    0,    0,    0,  157,  158,  159,  160,  161,  162,  163,
+  164,    0,  165,  166,  167,    0,    0,  168,  169,  170,
+    0,  171,  172,  173,  174,  175,  188,  176,  538,  149,
+    0,  150,    0,    0,  177,    0,    0,    0,    0,    0,
+    0,    0,  178,  179,    0,    0,    0,  733,  180,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  181,  182,
+    0,    0,  183,  184,  185,  186,    0,    0,    0,   89,
+    0,    0,    0,    0,  188,    0,  187,  149,    0,  150,
+    0,    0,  177,    0,    0,    0,    0,    0,    0,    0,
+  178,  179,  148,    0,    0,  642,  180,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  181,  182,    0,    0,
+  183,  184,  185,  186,    0,  151,  152,   89,    0,    0,
+  153,  154,  155,  156,  187,    0,    0,    0,    0,    0,
+    0,    0,  157,  158,  159,  160,  161,  162,  163,  164,
+    0,  165,  166,  167,    0,    0,  168,  169,  170,    0,
+  171,  172,  173,  174,  175,    0,  176,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  188,    0,    0,  149,    0,  150,    0,
+    0,  177,    0,    0,    0,    0,    0,    0,    0,  178,
+  179,    0,    0,    0,  662,  180,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  181,  182,    0,    0,  183,
+  184,  185,  186,    0,    0,    0,   89,    0,    0,  148,
+    0,    0,    0,  187,    0,  188,    0,    0,  149,    0,
+  150,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  151,  152,    0,    0,  664,  153,  154,  155,
+  156,    0,    0,    0,    0,    0,    0,    0,    0,  157,
+  158,  159,  160,  161,  162,  163,  164,  148,  165,  166,
+  167,    0,    0,  168,  169,  170,    0,  171,  172,  173,
+  174,  175,    0,  176,    0,    0,    0,    0,    0,    0,
+  151,  152,    0,    0,    0,  153,  154,  155,  156,    0,
+    0,    0,    0,    0,    0,    0,    0,  157,  158,  159,
+  160,  161,  162,  163,  164,    0,  165,  166,  167,    0,
+    0,  168,  169,  170,    0,  171,  172,  173,  174,  175,
+    0,  176,    0,    0,    0,    0,    0,    0,  177,    0,
+    0,    0,    0,    0,    0,    0,  178,  179,    0,    0,
+    0,    0,  180,    0,  188,    0,    0,  149,    0,  150,
+    0,    0,  181,  182,    0,    0,  183,  184,  185,  186,
+    0,    0,  812,   89,    0,    0,    0,    0,    0,    0,
+  187,    0,    0,    0,    0,    0,  177,    0,    0,    0,
+    0,    0,    0,    0,  178,  179,  148,    0,    0,    0,
+  180,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  181,  182,    0,    0,  183,  184,  185,  186,    0,  151,
+  152,   89,    0,    0,  153,  154,  155,  156,  187,    0,
+    0,    0,    0,    0,    0,    0,  157,  158,  159,  160,
+  161,  162,  163,  164,    0,  165,  166,  167,  148,    0,
+  168,  169,  170,    0,  171,  172,  173,  174,  175,    0,
+  176,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  151,  152,    0,    0,    0,  153,  154,  155,  156,
+    0,    0,    0,    0,    0,    0,    0,    0,  157,  158,
+  159,  160,  161,  162,  163,  164,    0,  165,  166,  167,
+    0,    0,  168,  169,  170,    0,  171,  172,  173,  174,
+  175,    0,  176,  188,    0,  177,  149,    0,  150,    0,
+    0,    0,    0,  178,  179,    0,    0,    0,    0,  180,
+    0,  894,    0,    0,    0,    0,    0,    0,    0,  181,
+  182,    0,    0,  183,  184,  185,  186,    0,    0,    0,
+   89,    0,    0,    0,    0,    0,    0,  187,    0,    0,
+    0,  188,    0,  946,  149,    0,  150,  177,    0,    0,
+    0,    0,    0,    0,    0,  178,  179,  148,    0,    0,
+    0,  180,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,  181,  182,    0,    0,  183,  184,  185,  186,    0,
+  151,  152,   89,    0,    0,  153,  154,  155,  156,  187,
+    0,    0,    0,    0,    0,    0,    0,  157,  158,  159,
+  160,  161,  162,  163,  164,    0,  165,  166,  167,    0,
+    0,  168,  169,  170,    0,  171,  172,  173,  174,  175,
+    0,  176,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  337,    0,    0,  337,  337,  337,
+  337,  337,  337,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  337,    0,  337,
+  188,    0,    0,  149,    0,  150,  177,    0,    0,    0,
+    0,    0,    0,    0,  178,  179,    0,    0,    0,    0,
+  180,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  181,  182,    0,    0,  183,  184,  185,  186,    0,    0,
+    0,   89,    0,    0,    0,    0,  148,    0,  187,    0,
+    0,    0,  382,    0,    0,  149,    0,  150,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  151,
+  152,    0,    0,    0,  153,  154,  155,  156,    0,    0,
+    0,    0,    0,    0,    0,    0,  157,  158,  159,  160,
+  161,  162,  163,  164,  148,  165,  166,  167,    0,    0,
+  168,  169,  170,    0,  171,  172,  173,  174,  175,    0,
+  176,    0,    0,    0,    0,    0,    0,  151,  152,    0,
+    0,    0,  153,  154,  155,  156,    0,    0,    0,    0,
+    0,    0,    0,    0,  157,  158,  159,  160,  161,  162,
+  163,  164,    0,  165,  166,  167,    0,    0,  168,  169,
+  170,    0,  171,  172,  173,  174,  175,    0,  176,    0,
+    0,    0,    0,    0,    0,  177,    0,    0,    0,    0,
+    0,    0,    0,  178,  179,    0,    0,    0,    0,  180,
+    0,  188,    0,    0,  149,    0,  150,    0,    0,  181,
+  182,    0,    0,  183,  184,  185,  186,  337,  337,  337,
+   89,  337,  337,  337,  337,  337,  337,  187,    0,  337,
+  337,    0,    0,  177,    0,    0,    0,    0,    0,    0,
+    0,  178,  179,  148,    0,    0,    0,  180,    0,  505,
+    0,    0,  149,    0,  150,    0,    0,  181,  182,    0,
+    0,  183,  184,  185,  186,    0,  151,  152,   89,    0,
+    0,  153,  154,  155,  156,  187,    0,    0,    0,    0,
+    0,    0,    0,  157,  158,  159,  160,  161,  162,  163,
+  164,    0,  165,  166,  167,  148,    0,  168,  169,  170,
+    0,  171,  172,  173,  174,  175,    0,  176,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  151,  152,
+    0,    0,    0,  153,  154,  155,  156,    0,    0,    0,
+    0,    0,    0,    0,    0,  157,  158,  159,  160,  161,
+  162,  163,  164,    0,  165,  166,  167,    0,    0,  168,
+  169,  170,    0,  171,  172,  173,  174,  175,    0,  176,
+    0,    0,  177,    0,    0,    0,    0,    0,    0,    0,
+  178,  179,    0,    0,    0,    0,  180,    0,  382,    0,
+    0,  149,    0,  150,    0,    0,  181,  182,    0,    0,
+  183,  184,  185,  186,    0,    0,    0,   89,    0,    0,
+    0,    0,    0,    0,  187,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  177,    0,    0,    0,    0,    0,
+    0,    0,  178,  179,  148,    0,  904,    0,  180,  149,
+    0,  150,    0,    0,    0,    0,    0,    0,  181,  182,
+    0,    0,  183,  184,  185,  186,    0,  151,  152,   89,
+    0,    0,  153,  154,  155,  156,  187,    0,    0,    0,
+    0,    0,    0,    0,  157,  158,  159,  160,  161,  162,
+  163,  164,  148,  165,  166,  167,    0,    0,  168,  169,
+  170,    0,  171,  172,  173,  174,  175,    0,  176,    0,
+    0,    0,    0,    0,    0,  151,  152,    0,    0,    0,
+  153,  154,  155,  156,    0,    0,    0,    0,    0,    0,
+    0,    0,  157,  158,  159,  160,  161,  162,  163,  164,
+    0,  165,  166,  167,    0,    0,  168,  169,  170,    0,
+  171,  172,  173,  174,  175,    0,  176,    0,    0,    0,
+    0,    0,    0,  177,    0,    0,    0,    0,    0,    0,
+    0,  178,  179,    0,    0,    0,    0,  180,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,  181,  182,    0,
+    0,  183,  184,  185,  186,    0,    0,    0,   89,    0,
+    0,    0,    0,    0,  313,  443,    0,    0,    0,  313,
+  313,  177,  313,    0,    0,    0,    0,    0,    0,  178,
+  179,  148,    0,    0,    0,  180,    0,  313,  313,  313,
+    0,    0,    0,    0,    0,  181,  182,    0,    0,  183,
+  184,  185,  186,    0,  151,  152,   89,    0,    0,  153,
+  154,  155,  156,  187,    0,    0,    0,    0,    0,    0,
+    0,  157,  158,  159,  160,  161,  162,  163,  164,  148,
+  165,  166,  167,    0,    0,  168,  169,  170,    0,  171,
+  172,  173,  174,  175,    0,  176,  515,  515,  515,  515,
+  515,    0,  151,  152,    0,    0,    0,  153,  154,  155,
+  156,    0,    0,    0,    0,  515,  515,  515,    0,  157,
+  158,  159,  160,  161,  162,  163,  164,    0,  165,  166,
+  167,    0,    0,  168,  169,  170,    0,  171,  172,  173,
+  174,  175,    0,  176,    0,    0,    0,  598,  414,  412,
+  177,  413,    0,    0,    0,    0,    0,    0,  178,  179,
+    0,    0,    0,    0,  180,    0,  417,  402,  418,  605,
+  414,  412,    0,  413,  181,  182,    0,    0,  183,  184,
+  185,  186,    0,    0,    0,  888,    0,    0,  417,  402,
+  418,    0,  187,    0,    0,  620,  414,  412,  177,  413,
+    0,    0,    0,    0,    0,    0,  178,  179,    0,    0,
+    0,    0,  180,    0,  417,  402,  418,    0,    0,    0,
+    0,    0,  181,  182,    0,    0,  183,  184,  185,  186,
+    0,    0,    0,   89,    0,    0,    0,  313,  313,  313,
+  187,  313,  313,  313,  313,  313,  313,    0,    0,  313,
+  313,  636,  414,  412,    0,  413,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  668,  414,  412,    0,  413,
+  417,  402,  418,    0,    0,    0,    0,    0,    0,  673,
+  414,  412,    0,  413,  417,  402,  418,    0,    0,    0,
+    0,    0,    0,  675,  414,  412,    0,  413,  417,  402,
+  418,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  417,  402,  418,  515,  515,  515,    0,  515,
+  515,  515,  515,  515,  515,    0,    0,  515,  515,  780,
+  414,  412,    0,  413,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  781,  414,  412,    0,  413,  417,  402,
+  418,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  417,  402,  418,    0,  403,  404,  405,    0,
+  406,  407,  408,  409,  410,  411,    0,    0,  415,  416,
+    0,    0,    0,  782,  414,  412,    0,  413,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,  417,  402,  418,    0,    0,    0,    0,  783,
+  414,  412,    0,  413,  403,  404,  405,    0,  406,  407,
+  408,  409,  410,  411,    0,    0,  415,  416,  417,  402,
+  418,  784,  414,  412,    0,  413,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  785,  414,  412,    0,  413,
+  417,  402,  418,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  417,  402,  418,    0,    0,    0,
+  403,  404,  405,    0,  406,  407,  408,  409,  410,  411,
+    0,    0,  415,  416,  403,  404,  405,    0,  406,  407,
+  408,  409,  410,  411,    0,    0,  415,  416,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,  786,  414,  412,    0,
+  413,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  417,  402,  418,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,  787,  414,  412,    0,
+  413,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  417,  402,  418,    0,    0,
+    0,    0,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,    0,    0,    0,    0,
+    0,    0,    0,  788,  414,  412,    0,  413,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,  417,  402,  418,    0,    0,    0,    0,    0,
+  403,  404,  405,    0,  406,  407,  408,  409,  410,  411,
+    0,    0,  415,  416,  403,  404,  405,    0,  406,  407,
+  408,  409,  410,  411,    0,    0,  415,  416,  789,  414,
+  412,    0,  413,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  790,  414,  412,    0,  413,  417,  402,  418,
+    0,    0,    0,    0,    0,    0,  791,  414,  412,    0,
+  413,  417,  402,  418,    0,    0,    0,    0,    0,    0,
+  792,  414,  412,    0,  413,  417,  402,  418,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  417,
+  402,  418,    0,    0,    0,  403,  404,  405,    0,  406,
+  407,  408,  409,  410,  411,    0,    0,  415,  416,  793,
+  414,  412,    0,  413,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  802,  414,  412,    0,  413,  417,  402,
+  418,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  417,  402,  418,  403,  404,  405,    0,  406,
+  407,  408,  409,  410,  411,    0,    0,  415,  416,  858,
+  414,  412,    0,  413,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,  417,  402,
+  418,    0,    0,    0,    0,    0,    0,  900,  414,  412,
+    0,  413,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,  417,  402,  418,  247,
+  247,  247,    0,  247,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  414,  412,    0,  413,  247,  247,
+  247,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  848,    0,  417,  402,  418,    0,    0,  403,  404,  405,
+    0,  406,  407,  408,  409,  410,  411,    0,    0,  415,
+  416,  403,  404,  405,    0,  406,  407,  408,  409,  410,
+  411,    0,    0,  415,  416,  403,  404,  405,    0,  406,
+  407,  408,  409,  410,  411,    0,    0,  415,  416,  403,
+  404,  405,    0,  406,  407,  408,  409,  410,  411,    0,
+    0,  415,  416,  414,  412,    0,  413,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  897,
+    0,  417,  402,  418,    0,    0,    0,    0,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,  414,  412,  928,  413,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  417,  402,  418,    0,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  414,  412,  964,  413,  403,  404,  405,    0,
+  406,  407,  408,  409,  410,  411,    0,    0,  415,  416,
+  417,  402,  418,    0,    0,    0,    0,    0,  247,  247,
+  247,    0,  247,  247,  247,  247,  247,  247,    0,    0,
+  247,  247,  403,  404,  405,    0,  406,  407,  408,  409,
+  410,  411,    0,    0,  415,  416,  414,  412,    0,  413,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  414,  412,  941,  413,  417,  402,  418,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  957,    0,  417,  402,
+  418,  414,  412,  965,  413,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,  417,
+  402,  418,    0,    0,    0,    0,    0,  414,  412,  970,
+  413,  403,  404,  405,    0,  406,  407,  408,  409,  410,
+  411,    0,    0,  415,  416,  417,  402,  418,  247,  247,
+  247,  247,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,  414,  412,    0,  413,  247,  247,  247,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  417,  402,  418,    0,  403,  404,  405,    0,  406,  407,
+  408,  409,  410,  411,    0,    0,  415,  416,  247,  247,
+    0,  247,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,  247,  247,  247,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+  403,  404,  405,    0,  406,  407,  408,  409,  410,  411,
+    0,    0,  415,  416,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,  403,  404,  405,    0,  406,  407,
+  408,  409,  410,  411,    0,    0,  415,  416,  403,  404,
+  405,    0,  406,  407,  408,  409,  410,  411,    0,    0,
+  415,  416,    0,    0,    0,    0,    0,    0,    0,  403,
+  404,  405,    0,  406,  407,  408,  409,  410,  411,    0,
+    0,  415,  416,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,  403,  404,  405,    0,  406,
+  407,  408,  409,  410,  411,    0,    0,  415,  416,    0,
+    0,    0,    0,    0,    0,    0,  247,  247,  247,    0,
+  247,  247,  247,  247,  247,  247,    0,    0,  247,  247,
+  403,  404,  405,    0,  406,  407,  408,  409,  410,  411,
+    0,   16,  415,  416,   17,    0,   18,   19,    0,    0,
+   20,    0,    0,   21,   22,   23,    0,    0,    0,    0,
+   24,   25,    0,    0,    0,    0,  247,  247,  247,    0,
+  247,  247,  247,  247,  247,  247,   26,    0,  247,  247,
+   27,   28,    0,    0,    0,   29,    0,    0,    0,    0,
+    0,   30,    0,   31,   32,    0,    0,   33,    0,   34,
+   35,   36,   37,   38,    0,   39,   40,   41,   42,   43,
+   44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
+   54,    0,    0,    0,    0,   55,   56,   57,    0,   58,
+   59,   60,    0,   61,   62,   63,    0,    0,   64,    0,
+   65,    0,    0,   66,   67,   68,   69,    0,    0,   70,
+   71,   72,    0,    0,   73,    0,    0,    0,   74,   75,
+   76,   77,   78,   79,   80,    0,   81,   82,   83,   84,
+   85,    0,    0,   86,    0,    0,    0,    0,    0,    0,
+   87,   88,   89,    0,    0,    0,    0,    0,    0,   90,
+};
+short fortrancheck[] = {                                      24,
+  231,   26,  177,  198,  140,   30,   33,  309,   33,  177,
+  290,  140,  393,  303,   39,   10,  296,   10,  177,   10,
+  188,  177,   44,  236,   40,   10,   40,   40,   40,   37,
+   40,   10,   37,   41,  295,   40,   44,   44,  527,  105,
+   40,  302,   11,  231,   42,  730,   68,   69,  236,   41,
+   42,   41,   42,   61,   76,  579,   61,  110,  278,  583,
+   40,   44,  142,   58,   44,   42,  234,  120,  121,  764,
+   44,   44,   44,   44,   96,   97,   98,   37,   58,  347,
+  119,  800,  801,  122,   58,   58,   58,   41,   42,   43,
+   59,   45,   37,   10,   44,  231,   41,   44,  734,   44,
+  236,   61,  425,  376,   44,  130,   10,  417,  135,  447,
+  135,   19,   10,  502,   44,    0,  103,  271,  272,  106,
+  331,  217,  147,  148,   42,   10,  515,   44,   58,   47,
+   32,  156,   43,   44,   45,   42,   43,   44,   45,   40,
+   47,   60,  238,   62,  417,   40,  171,  358,  359,   58,
+   41,  374,  177,   44,   58,   57,   58,   44,  843,  128,
+   58,  417,  881,  188,  425,  388,   40,   58,  424,  344,
+   41,   58,   41,   44,   59,   44,  201,   40,  203,  578,
+  579,   40,  271,  272,  583,  210,  881,   58,  576,   58,
+  271,  272,   44,  417,  219,  331,  584,  417,  417,  224,
+   41,  281,  331,   44,   40,  341,   58,  382,  344,  234,
+  276,   42,  341,  349,  382,  344,   40,   58,   41,  244,
+  349,   44,  907,  382,  485,  522,  382,  488,  864,   60,
+  527,   62,   40,   42,   43,   40,   45,  539,  207,  378,
+  293,  543,  267,  328,  329,   42,   43,   44,   45,  510,
+  289,   60,  291,   62,   37,   40,  417,   42,   41,  395,
+  299,   44,  231,  417,   44,  234,  319,  236,  237,   42,
+  331,  532,  272,  242,   58,   42,   43,  256,   45,   40,
+  341,   42,  307,   59,  309,   41,   42,   43,  349,   45,
+   41,   42,   43,  280,   45,  272,  273,  322,  323,  567,
+  406,  272,  282,  328,  283,  284,  275,  575,  282,  282,
+  282,  336,  337,  338,  339,  280,  547,  271,  272,  273,
+   44,  300,  301,  591,   44,  272,  271,  272,  417,  298,
+   42,   43,  272,   45,  359,  548,  417,  505,  363,  364,
+  365,  366,  367,  368,  369,  370,  371,  372,  373,  374,
+  375,  320,  282,  255,  273,  324,  264,  382,  882,  547,
+  548,  272,  851,  762,  763,  272,  765,  417,  393,  377,
+  859,  256,  377,   40,   41,  283,  383,  402,  403,  404,
+  405,  406,  407,  408,  409,  410,  411,  412,  413,  414,
+  415,  416,  417,  418,  406,  280,  421,  422,  283,  284,
+  383,  576,   44,  417,  417,  743,  744,  424,  424,  584,
+  424,  547,  548,  392,  424,  300,  301,  377,   40,  417,
+   42,   43,  417,   45,  417,  417,  417,  417,  718,  565,
+  811,  733,  417,  383,   44,   41,  565,  417,   44,  719,
+  576,  272,  273,  704,  417,  417,  425,  576,  584,  417,
+  586,  587,  588,  589,  590,  584,   40,  586,  587,  588,
+  589,  590,  484,  272,  273,  678,  519,  635,  521,   41,
+  683,  630,   44,  632,  633,  272,  632,  633,  531,   41,
+  505,  417,   44,  882,  509,  746,  754,  417,   40,   37,
+  678,  516,   43,   44,   45,  683,  271,  272,  523,  767,
+  768,  769,  770,  771,  565,  272,  273,  392,   42,   43,
+   44,   45,  537,   47,  539,  271,  272,  273,  543,   40,
+  271,  272,  273,  271,  272,  586,  587,  588,  589,  590,
+   44,   40,   42,   43,  933,   45,   43,   37,   45,  564,
+  425,   41,  678,   41,   44,   41,   44,  683,   44,  574,
+   60,  417,   62,   40,  851,  852,  853,  854,  855,  271,
+  272,  273,  859,  824,  866,   37,  417,   41,   58,   41,
+   44,  598,   44,  598,  599,   40,   37,   40,  547,  548,
+   41,  842,   40,   44,  752,   42,   43,   40,   45,  764,
+   47,   40,   40,   40,  723,  852,  853,  854,  855,   60,
+   41,   62,   40,   44,   40,  630,   41,  632,  633,   44,
+  635,  879,  873,  155,  639,  157,   40,  642,   41,  755,
+   40,   44,   41,  818,   41,   44,  755,   44,  764,   40,
+   40,  799,  657,  658,   40,  764,   40,  662,   40,  664,
+  799,  800,  801,   40,  800,  801,  877,   41,   40,   40,
+   44,  676,  677,   41,   41,   41,   44,   44,   44,  417,
+   41,   40,   37,   44,  689,  417,  691,   42,   43,   41,
+   45,   41,   44,   40,   44,  297,  298,  299,   41,   40,
+  302,   44,  707,   40,   44,   60,   61,   62,    0,   41,
+   41,   44,   44,   44,  755,  417,   41,   41,   10,   44,
+   44,  670,   41,   58,   41,   44,  881,   44,  733,  678,
+   41,   44,   41,   44,  683,   44,  685,  424,   61,   41,
+  745,  272,   44,   41,  749,   40,   44,  752,   40,  417,
+   42,   43,   44,   45,   41,   41,  904,   44,   44,   41,
+   41,   41,   44,   44,   44,  881,   44,   59,   60,   61,
+   62,  417,  881,  417,  264,  265,  266,  267,  268,  269,
+  729,   41,  272,  273,   44,  276,  417,   41,  390,  391,
+   44,   44,   41,   44,  799,  800,  801,   41,   41,   41,
+   44,   44,   44,   40,  406,  407,  811,  812,  410,  411,
+  412,  413,  424,   41,   41,  417,   44,   44,   40,  260,
+  261,  262,  424,  264,  265,  266,  267,  268,  269,  390,
+  391,  272,  273,  838,   44,  357,  358,  328,  329,  330,
+   61,  846,  277,  848,   41,  406,  407,   44,   44,  410,
+  411,  412,  413,  383,   44,  377,  378,  379,  380,  381,
+   44,  866,   41,  424,   41,   44,   44,   44,  390,  360,
+   44,  362,  363,  364,   40,   44,  367,  368,   37,  370,
+  371,   41,   44,   41,  272,   40,   40,   44,   43,  894,
+   45,  896,  897,   40,  417,   42,   43,  417,   45,  904,
+   41,  417,  417,   41,   44,  260,  261,  262,   61,  264,
+  265,  266,  267,  268,  269,   10,  424,  272,  273,   41,
+   44,  390,  391,  928,   44,  273,   40,   44,  877,   44,
+  935,   44,   58,   41,   41,  417,  941,  406,  407,  944,
+  333,  410,  411,  412,  413,   40,   42,   41,   43,   41,
+   45,  417,  957,  902,   58,  424,  961,   41,  272,  964,
+  965,   40,  272,   41,  256,  970,  272,  417,  260,  261,
+  262,   58,  264,  265,  266,  267,  268,  269,   44,  271,
+  272,  273,  377,   41,  276,   44,   61,  279,  280,  281,
+  282,  283,  284,  285,  286,  287,  288,  289,  290,  291,
+  292,  293,  294,  295,  296,  417,  417,   41,  300,  301,
+   41,  303,  304,  305,  306,  307,  308,  309,  310,  311,
+  312,  313,  314,  315,  316,  317,  318,  319,  320,  321,
+  322,  323,  324,  325,  326,  327,  328,  329,   41,   61,
+  332,   41,  334,  335,  336,  337,  338,   41,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   41,   41,   44,   47,  360,  361,
+  362,  272,  364,  365,  366,   44,  368,  369,  370,   41,
+  377,  373,   41,  375,   44,   41,  378,  379,  380,  381,
+   61,  417,  384,  385,  386,  417,  417,  389,  390,  391,
+  392,  393,  394,  395,  396,  397,  398,  399,   41,  401,
+  402,  403,  404,  405,  406,  407,  408,    0,  410,  411,
+  412,  413,  383,  415,  416,  417,  273,   10,   42,   43,
+   58,   45,  424,  425,  417,  383,   41,   41,  417,   41,
+   41,   44,  297,  298,  299,   41,   60,  302,   62,  272,
+  297,  298,  299,   41,   37,  302,   41,   41,   41,   42,
+   43,   44,   45,   41,   47,  774,  285,  846,  263,  952,
+  869,  772,  518,  382,  398,   58,   59,   60,   61,   62,
+  896,  677,  752,  848,    9,  275,   13,   74,  687,  691,
+  526,  286,  287,  427,  268,  500,  291,  292,  293,  294,
+  700,  535,  947,  128,  548,  547,  555,  537,  303,  304,
+  305,  306,  307,  308,  309,  310,  749,  312,  313,  314,
+  140,  755,  317,  318,  319,  140,  321,  322,  323,  324,
+  325,   -1,  327,   -1,   -1,  390,  391,  557,   -1,   -1,
+   -1,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,   -1,
+   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,  406,
+  407,   -1,  417,  410,  411,  412,  413,   -1,   -1,  424,
+  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,   -1,   -1,
+   -1,   -1,   -1,    0,   -1,   -1,   -1,  382,   -1,   -1,
+   -1,   -1,   -1,   10,   -1,  390,  391,   -1,   -1,   -1,
+   -1,  396,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,   -1,
+   37,   -1,  417,   -1,   41,   42,   43,   44,   45,  424,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   58,   59,   60,   61,   62,   -1,   -1,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,  261,  262,
+   -1,  264,  265,  266,  267,  268,  269,   -1,  271,  272,
+  273,   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,
+  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,
+   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,
+   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,
+   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,
+   -1,  334,  335,  336,  337,  338,   -1,  340,  341,  342,
+  343,  344,  345,  346,  347,  348,  349,  350,  351,  352,
+  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,
+   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,
+  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,
+  383,  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,
+  393,  394,  395,  396,  397,  398,  399,   -1,  401,  402,
+  403,  404,  405,   -1,   40,  408,   42,   43,   -1,   45,
+   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,  256,
+   -1,  424,  425,  260,  261,  262,   -1,  264,  265,  266,
+  267,  268,  269,   -1,  271,  272,  273,   -1,   -1,  276,
+   -1,   -1,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,
+    0,  378,  379,  380,  381,   -1,  383,  384,  385,  386,
+   10,   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+   -1,  408,   -1,   -1,   -1,   -1,   -1,   37,  415,  416,
+  417,   41,   42,   43,   44,   45,   -1,  424,  425,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,
+   60,   61,   62,  287,   -1,   -1,   -1,  291,  292,  293,
+  294,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,
+   -1,  305,  306,  307,  308,  309,  310,  263,  312,  313,
+  314,   -1,   -1,  317,  318,  319,   -1,   -1,  322,  323,
+  324,  325,   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,
+  286,  287,   -1,   -1,   -1,  291,  292,  293,  294,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,
+  306,  307,  308,  309,  310,   -1,  312,  313,  314,   -1,
+   -1,  317,  318,  319,   -1,  321,  322,  323,  324,  325,
+   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  287,   -1,    0,   -1,  291,  292,
+  293,  294,   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,
+  303,   -1,  305,  306,  307,  308,  309,  310,   -1,  312,
+  313,  314,   -1,  417,  317,  318,  319,   -1,   -1,  322,
+  323,  324,  325,   37,  327,   -1,  382,   41,   42,   43,
+   44,   45,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,
+  396,   -1,   -1,   -1,   58,   59,   60,   61,   62,   -1,
+  406,  407,   -1,   -1,  410,  411,  412,  413,   -1,   -1,
+   -1,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,  271,  272,  273,   -1,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,  417,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   40,   -1,   -1,
+  360,  361,  362,   -1,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,  383,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   40,
+   -1,   -1,  256,   -1,  424,  425,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,  271,  272,  273,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,
+  384,  385,  386,   -1,   -1,  389,    0,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   10,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   42,   43,   44,   45,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   60,   61,   62,   40,   41,   42,   43,
+   44,   45,   -1,  286,  287,   -1,   -1,   -1,  291,  292,
+  293,  294,   -1,   -1,   58,   59,   60,   61,   62,   -1,
+  303,  304,  305,  306,  307,  308,  309,  310,   -1,  312,
+  313,  314,   -1,   -1,  317,  318,  319,   -1,  321,  322,
+  323,  324,  325,   -1,  327,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  286,  287,   -1,   -1,   -1,
+  291,  292,  293,  294,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  303,  304,  305,  306,  307,  308,  309,  310,
+   -1,  312,  313,  314,   -1,   -1,  317,  318,  319,   -1,
+  321,  322,  323,  324,  325,   -1,  327,  390,  391,   -1,
+   -1,   -1,   -1,  396,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,    0,  406,  407,   -1,   -1,  410,  411,  412,
+  413,   -1,   10,   -1,  417,   -1,   -1,   -1,   -1,   -1,
+   -1,  424,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   37,
+   -1,   -1,   -1,   41,   42,   43,   44,   45,   -1,  390,
+  391,   -1,   -1,   -1,   -1,  396,   -1,   -1,   -1,   -1,
+   58,   59,   60,   61,   62,  406,  407,   -1,   -1,  410,
+  411,  412,  413,  260,  261,  262,  417,  264,  265,  266,
+  267,  268,  269,  424,   -1,  272,  273,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,  271,  272,  273,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   40,  408,   42,   43,   -1,   45,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,  256,   -1,
+  424,  425,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,  271,  272,  273,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,    0,
+  378,  379,  380,  381,   -1,  383,  384,  385,  386,   10,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,  417,
+   41,   42,   43,   44,   45,   -1,  424,  425,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   60,
+   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  263,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  286,
+  287,   -1,   -1,   -1,  291,  292,  293,  294,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,
+  307,  308,  309,  310,   -1,  312,  313,  314,   -1,   -1,
+  317,  318,  319,   -1,  321,  322,  323,  324,  325,   -1,
+  327,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   37,   -1,   -1,  382,   41,   42,   43,   44,
+   45,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,  396,
+   -1,   -1,   -1,   58,   59,   60,   61,   62,   -1,  406,
+  407,   -1,   -1,  410,  411,  412,  413,   -1,   -1,   -1,
+  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,
+  261,  262,   -1,  264,  265,  266,  267,  268,  269,   -1,
+  271,  272,  273,   -1,   -1,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,
+  381,   -1,  383,  384,  385,  386,   -1,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,   -1,   40,  408,   42,   43,
+   -1,   45,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,
+   -1,  256,   -1,  424,  425,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,  271,  272,  273,   -1,
+   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,  284,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,
+  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,
+   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,    0,  378,  379,  380,  381,   -1,  383,  384,
+  385,  386,   10,   -1,  389,   -1,   -1,  392,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   37,
+  415,  416,   -1,   41,   42,   43,   44,   45,   -1,  424,
+  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   58,   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  263,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  286,  287,   -1,   -1,   -1,  291,  292,  293,
+  294,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,
+  304,  305,  306,  307,  308,  309,  310,   -1,  312,  313,
+  314,   -1,   -1,  317,  318,  319,   -1,  321,  322,  323,
+  324,  325,   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   10,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   37,   -1,   -1,  382,   41,
+   42,   43,   44,   45,   -1,   -1,  390,  391,   -1,   -1,
+   -1,   -1,  396,   -1,   -1,   -1,   58,   59,   -1,   61,
+   -1,   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,
+   -1,   -1,   -1,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,
+   -1,   -1,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,  271,  272,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,  383,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   40,
+  408,   42,   43,   -1,   45,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,  256,   -1,  424,  425,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,  271,
+  272,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,    0,  378,  379,  380,  381,
+   -1,  383,  384,  385,  386,   10,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   37,  415,  416,  417,   41,   42,   43,   44,
+   45,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   58,   59,   -1,   61,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  263,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  286,  287,   -1,   -1,   -1,
+  291,  292,  293,  294,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  303,  304,  305,  306,  307,  308,  309,  310,
+   -1,  312,  313,  314,   -1,   -1,  317,  318,  319,   -1,
+  321,  322,  323,  324,  325,   -1,  327,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   10,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  382,   41,   42,   43,   44,   45,   -1,   -1,  390,
+  391,   -1,   -1,   -1,   -1,  396,   -1,   -1,   -1,   -1,
+   59,   60,   61,   62,   -1,  406,  407,   -1,   -1,  410,
+  411,  412,  413,   -1,   -1,   -1,  417,   -1,   -1,   -1,
+   -1,   -1,   -1,  424,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  256,   -1,   -1,   -1,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,  271,  272,   -1,   -1,
+   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,  284,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,
+  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,
+   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,
+  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,   -1,   40,  408,   42,   43,   -1,   45,   -1,   -1,
+  415,  416,  417,   -1,   -1,   -1,   -1,  256,   -1,  424,
+  425,  260,  261,  262,   -1,  264,  265,  266,  267,  268,
+  269,   -1,   -1,  272,  273,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,    0,  378,
+  379,  380,  381,   -1,   -1,  384,  385,  386,   10,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,   -1,   -1,   -1,   37,  415,  416,  417,   41,
+   -1,   43,   44,   45,   -1,  424,  425,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,   61,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  263,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  286,  287,
+   -1,   -1,   -1,  291,  292,  293,  294,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,  307,
+  308,  309,  310,   -1,  312,  313,  314,   -1,   -1,  317,
+  318,  319,   -1,  321,  322,  323,  324,  325,   -1,  327,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   37,   -1,   -1,  382,   41,   -1,   43,   44,   45,
+   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,  396,   -1,
+   -1,   -1,   58,   59,   -1,   61,   -1,   -1,  406,  407,
+   -1,   -1,  410,  411,  412,  413,   -1,   -1,   -1,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,  271,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,  383,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   42,   43,
+  256,   45,  424,  425,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,  271,   60,   61,   62,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   42,   43,
+   -1,   45,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   60,   61,   62,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,    0,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   10,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   37,  415,
+  416,  417,   41,   42,   -1,   44,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,
+   59,   60,   -1,   62,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  285,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+  326,   -1,   -1,    0,   -1,   -1,  332,  333,   -1,   -1,
+   -1,  337,  338,   10,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  347,  348,  349,  350,  351,  352,  353,  354,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  369,   -1,   42,   43,   44,   45,  375,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  384,   -1,
+  386,   -1,   59,   60,   61,   62,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  417,   -1,  417,   -1,   -1,   -1,  256,  424,   -1,
+   -1,  260,  261,  262,   -1,  264,  265,  266,  267,  268,
+  269,   -1,  271,   -1,  273,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,  383,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,   -1,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,   -1,  256,
+   -1,   -1,   -1,  260,  261,  262,  425,  264,  265,  266,
+  267,  268,  269,   -1,   -1,  272,  273,   42,   43,  276,
+   45,   -1,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   60,   61,   62,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+    0,  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,
+   10,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,   -1,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+   -1,  408,   42,   43,   44,   45,   -1,   -1,  415,  416,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  425,   59,
+   60,   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   10,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   37,   -1,   -1,
+   40,   41,   42,   43,   44,   45,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   59,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  383,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,   -1,  272,  273,   -1,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   -1,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,   -1,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,  256,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   -1,  415,  416,   -1,   -1,   -1,
+   -1,  271,  272,  273,   -1,  425,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   -1,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,    0,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   10,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   37,  415,  416,  417,   41,   -1,
+   -1,   44,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,   61,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   10,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   37,   -1,   -1,   -1,   41,   -1,
+   -1,   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,   61,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,  261,  262,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,
+   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,
+  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,
+   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,
+   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,
+   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,
+   -1,  334,  335,  336,  337,  338,   -1,  340,  341,  342,
+  343,  344,  345,  346,  347,  348,  349,  350,  351,  352,
+  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,
+   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,
+  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,
+  383,  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,
+  393,  394,  395,  396,  397,  398,  399,   -1,  401,  402,
+  403,  404,  405,  256,   -1,  408,   -1,  260,  261,  262,
+   -1,   -1,  415,  416,  417,   -1,   -1,   -1,  271,   -1,
+   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,  282,
+  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,
+   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,
+   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,
+   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,
+   -1,  334,  335,  336,  337,  338,   -1,  340,  341,  342,
+  343,  344,  345,  346,  347,  348,  349,  350,  351,  352,
+  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,
+   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,
+  373,   -1,  375,   -1,    0,  378,  379,  380,  381,   -1,
+  383,  384,  385,  386,   10,   -1,  389,   -1,   -1,  392,
+  393,  394,  395,  396,  397,  398,  399,   -1,  401,  402,
+  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,
+   -1,   37,  415,  416,  417,   41,   -1,   -1,   44,   -1,
+   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,   61,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   37,   -1,   -1,   -1,   41,   -1,   -1,   44,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,   61,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  256,   -1,   -1,   -1,  260,  261,  262,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,  260,  261,  262,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,  271,   -1,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,    0,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   10,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   37,  415,
+  416,  417,   41,   -1,   -1,   44,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,
+   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   10,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   37,   -1,
+   -1,   -1,   41,   -1,   -1,   44,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,
+   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,
+   -1,  260,  261,  262,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  271,   -1,   -1,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,  383,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,  256,   -1,  408,
+   -1,  260,  261,  262,   -1,   -1,  415,  416,  417,   -1,
+   -1,   -1,  271,   -1,   -1,  424,  425,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,    0,  378,
+  379,  380,  381,   -1,  383,  384,  385,  386,   10,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,   -1,   -1,   -1,   37,  415,  416,  417,   41,
+   -1,   -1,   44,   -1,   -1,  424,  425,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,   61,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   10,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   37,   -1,   -1,   -1,   41,
+   -1,   -1,   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,   61,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,  261,
+  262,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,  383,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,  260,  261,
+  262,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,  271,
+   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,    0,  378,  379,  380,  381,
+   -1,  383,  384,  385,  386,   10,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   37,  415,  416,  417,   41,   -1,   -1,   44,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   58,   59,   -1,   61,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   37,   -1,   -1,   -1,   41,   -1,   -1,   44,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   58,   59,   -1,   61,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  256,   -1,   -1,   -1,  260,  261,  262,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,   -1,
+   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,  284,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,
+  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,
+   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,
+  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,  256,   -1,  408,   -1,  260,  261,  262,   -1,   -1,
+  415,  416,  417,   -1,   -1,   -1,  271,   -1,   -1,  424,
+  425,  276,   -1,   -1,  279,  280,  281,  282,  283,  284,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,
+  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,
+   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,    0,  378,  379,  380,  381,   -1,  383,  384,
+  385,  386,   10,   -1,  389,   -1,   -1,  392,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   37,
+  415,  416,  417,   41,   -1,   -1,   44,   -1,   -1,  424,
+  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   58,   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   10,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   37,
+   -1,   -1,   -1,   41,   -1,   -1,   44,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   58,   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,
+   -1,   -1,  260,  261,  262,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  271,   -1,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,  383,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,  256,   -1,
+  408,   -1,  260,  261,  262,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,  271,   -1,   -1,  424,  425,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,    0,
+  378,  379,  380,  381,   -1,  383,  384,  385,  386,   10,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   37,  415,  416,  417,
+   41,   -1,   -1,   44,   -1,   -1,  424,  425,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,
+   61,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   10,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   37,   -1,   -1,   -1,
+   41,   -1,   -1,   44,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,   59,   -1,
+   61,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,
+  261,  262,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  271,   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,
+  381,   -1,  383,  384,  385,  386,   -1,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,  256,   -1,  408,   -1,  260,
+  261,  262,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,
+  271,   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,    0,  378,  379,  380,
+  381,   -1,  383,  384,  385,  386,   10,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,
+   -1,   -1,   -1,   37,  415,  416,  417,   41,   -1,   -1,
+   44,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   58,   59,   -1,   61,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   10,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   37,   -1,   -1,   -1,   41,   -1,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   58,   59,   -1,   61,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,  260,  261,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,  260,  261,    0,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,  271,   10,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   41,
+   42,   43,   44,   45,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   59,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,  383,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   -1,   -1,    0,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   10,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,
+   42,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,
+  272,  273,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,    0,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   10,  271,
+  272,  273,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   42,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   59,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,    0,   -1,
+   -1,   -1,   -1,  415,  416,   -1,   -1,   -1,   10,   -1,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,
+   42,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,
+  272,  273,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,   -1,
+   -1,    0,   -1,  415,  416,  417,   -1,   -1,   -1,  271,
+  272,   10,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   41,   42,   43,   44,   45,   -1,   -1,  311,
+   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   59,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,
+   -1,    0,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   10,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   41,   42,   43,   44,   45,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   59,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  271,  272,   -1,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,  256,   -1,  408,
+   -1,   -1,   -1,   -1,    0,   -1,  415,  416,  417,   -1,
+   -1,   -1,  271,  272,   10,  424,  425,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   41,   42,   43,   44,   45,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   59,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,   -1,   -1,    0,   -1,  415,  416,  417,   -1,
+   -1,   -1,   -1,   -1,   10,  424,  425,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   37,   -1,   -1,   -1,   41,   -1,   -1,   44,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  271,  272,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,    0,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   10,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,  271,   -1,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   37,  288,  289,  290,   41,   -1,   -1,   44,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,    0,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   10,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   37,   -1,   -1,   -1,   41,   -1,   -1,   44,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   -1,   -1,    0,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,  271,   10,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   41,   -1,   43,
+   44,   45,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   59,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,  383,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   -1,   -1,    0,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   10,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,  271,  272,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   41,   -1,   -1,
+   44,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,   -1,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,  271,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   41,   -1,   -1,
+   44,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,   -1,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,    0,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   10,  271,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   42,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   59,  320,   61,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,    0,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   10,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   41,   -1,   -1,
+   44,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,  271,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   41,   -1,   -1,
+   44,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,    0,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   10,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  271,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,    0,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   10,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   59,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,  271,  272,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,    0,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   10,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   59,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+  256,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,  271,  272,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,    0,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   10,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,  271,  272,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   41,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   58,   59,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,    0,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   10,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   44,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,    0,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   10,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   59,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,  271,  272,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,    0,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   10,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   42,   -1,   44,   -1,   -1,  256,  415,
+  416,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   59,   -1,   -1,  271,  272,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,    0,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   10,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   59,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,    0,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   10,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   59,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,   -1,   -1,   -1,  256,  415,  416,  417,   -1,
+   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,   -1,
+  271,  272,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,
+  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,    0,
+  401,  402,  403,  404,  405,  256,   -1,  408,   -1,   10,
+   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,
+  271,  272,   -1,  424,  425,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   41,   -1,   -1,   44,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   59,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,
+  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,    0,
+  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,   10,
+   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,
+   -1,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   41,   -1,   -1,   44,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   59,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,    0,  378,  379,  380,
+  381,   -1,   -1,  384,  385,  386,   10,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,
+   -1,   -1,   -1,   -1,  415,  416,  417,   41,   -1,   -1,
+   44,   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   59,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   -1,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,    0,  378,  379,  380,
+  381,   -1,   -1,  384,  385,  386,   10,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,
+   -1,   -1,   -1,   -1,  415,  416,  417,   41,   -1,   -1,
+   44,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,    0,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   10,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   41,   -1,   -1,   44,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   59,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,    0,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   10,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   44,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   59,   -1,   61,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  276,
+   -1,   -1,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,
+   -1,    0,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,
+   -1,   10,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+   59,  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,
+   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,  256,
+   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,
+  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,  276,
+   -1,   -1,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,    0,   -1,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   10,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   44,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+   -1,  368,  369,  370,   -1,   59,  373,   61,  375,   -1,
+   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+   -1,  408,   -1,   -1,   -1,   -1,   -1,  256,  415,  416,
+  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,
+   -1,   -1,  271,  272,   -1,   -1,   -1,  276,   -1,   -1,
+  279,  280,  281,  282,  283,  284,  285,   -1,   -1,  288,
+  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,
+   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  311,   -1,   -1,   -1,  315,  316,   -1,   -1,
+   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,
+  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,
+   -1,  340,  341,  342,  343,  344,  345,  346,  347,  348,
+  349,  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,
+   -1,  360,  361,  362,   -1,  364,  365,  366,   -1,  368,
+  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,
+  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,
+  389,   -1,   -1,  392,  393,  394,  395,  396,  397,  398,
+  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,
+   -1,   -1,  256,   -1,    0,   -1,  415,  416,  417,   -1,
+   -1,   -1,   -1,   -1,   10,  424,  425,   -1,   -1,   41,
+   42,   43,  276,   45,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   60,   61,
+   62,  295,  296,   -1,   -1,   41,  300,  301,   44,   -1,
+   41,   42,   43,   44,   45,   -1,   -1,  311,   -1,   -1,
+   -1,  315,  316,   59,   -1,   -1,  320,   -1,   -1,   60,
+   61,   62,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,    0,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   10,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  256,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  260,
+  261,  262,   -1,  264,  265,  266,  267,  268,  269,   -1,
+  276,  272,  273,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,  383,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,  256,  408,    0,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   10,   -1,   -1,   -1,   -1,  424,  425,
+   -1,  276,  277,   -1,  279,  280,  281,  282,  283,  284,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   41,  300,  301,   44,   -1,   41,
+   42,   43,   -1,   45,   -1,   -1,  311,   -1,   -1,   -1,
+  315,  316,   59,   -1,   -1,  320,   58,   -1,   60,   61,
+   62,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,
+  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,   -1,   -1,  408,    0,   -1,   -1,   -1,   -1,   -1,
+  415,  416,  417,   -1,   10,   -1,   -1,   -1,   -1,  424,
+  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   44,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   59,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,  276,
+  272,  273,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,    0,   -1,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   10,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   44,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+   -1,  368,  369,  370,   -1,   59,  373,   -1,  375,   -1,
+   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+  256,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,    0,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   10,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   44,   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   59,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,  256,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,    0,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   10,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   44,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   59,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,    0,   -1,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   10,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   59,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,  256,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+    0,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   10,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   44,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   59,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+    0,   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,
+   10,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   -1,  364,  365,  366,   -1,  368,  369,  370,   59,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,  256,   -1,   -1,   -1,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,  256,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   -1,  415,  416,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,
+  256,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,  256,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,  256,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,  256,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,  256,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   10,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   59,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   10,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   59,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,  256,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,  256,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,
+  256,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,  256,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,  256,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,  256,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,  256,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   10,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   59,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   10,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   59,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,   -1,  256,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,  256,   -1,  408,   -1,
+   -1,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,   -1,
+  256,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+  396,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,   -1,  256,   -1,   -1,   -1,   -1,  415,
+  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,
+   -1,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,  256,   -1,  408,   -1,   -1,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,  276,   -1,   -1,  279,  280,  281,
+  282,  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,
+   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,
+   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,
+   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,   -1,
+   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,
+  332,   -1,  334,  335,  336,  337,  338,   -1,  340,  341,
+  342,  343,  344,  345,  346,  347,  348,  349,  350,  351,
+  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,
+  362,   59,  364,  365,  366,   -1,  368,  369,  370,   -1,
+   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,
+   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,
+  392,  393,  394,  395,  396,  397,  398,  399,   -1,  401,
+  402,  403,  404,  405,   -1,   -1,  408,   -1,  256,   -1,
+   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,   -1,
+   -1,   -1,  424,  425,   -1,   -1,   -1,   -1,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,  256,   -1,
+  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,  276,   -1,
+   -1,  279,  280,  281,  282,  283,  284,  285,   -1,   -1,
+  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,   -1,
+   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,   -1,
+   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,   -1,
+   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,
+  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,  337,
+  338,   -1,  340,  341,  342,  343,  344,  345,  346,  347,
+  348,  349,  350,  351,  352,  353,  354,  355,   -1,   -1,
+   -1,   -1,  360,  361,  362,   59,  364,  365,  366,   -1,
+  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,   -1,
+  378,  379,  380,  381,   -1,   -1,  384,  385,  386,   -1,
+   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,  397,
+  398,  399,   -1,  401,  402,  403,  404,  405,   -1,   -1,
+  408,   -1,  256,   -1,   -1,   -1,   -1,  415,  416,  417,
+   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,   -1,
+   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,    0,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   10,
+   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,  256,   -1,  408,   -1,   -1,   -1,   -1,   -1,
+   -1,  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,  276,   -1,   -1,  279,  280,  281,  282,  283,
+  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,
+   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,   -1,
+    0,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,
+   10,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,
+   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,
+  334,  335,  336,  337,  338,   -1,  340,  341,  342,  343,
+  344,  345,  346,  347,  348,  349,  350,  351,  352,  353,
+  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,   59,
+  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,
+   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,
+  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,  393,
+  394,  395,  396,  397,  398,  399,   -1,  401,  402,  403,
+  404,  405,   -1,   -1,  408,  256,   -1,   -1,   -1,   -1,
+   -1,  415,  416,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,  425,   -1,   -1,   -1,  276,   -1,   -1,  279,  280,
+  281,  282,  283,  284,  285,   -1,   -1,  288,  289,  290,
+   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,  300,
+  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,
+  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,  320,
+   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,   -1,
+   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,  340,
+  341,  342,  343,  344,  345,  346,  347,  348,  349,  350,
+  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,  360,
+  361,  362,   59,  364,  365,  366,   -1,  368,  369,  370,
+   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,  380,
+  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,   -1,
+   -1,  392,  393,  394,  395,  396,  397,  398,  399,   -1,
+  401,  402,  403,  404,  405,   -1,  256,  408,   -1,   -1,
+   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,   -1,
+   -1,   -1,   -1,  424,  425,   -1,  276,   -1,   -1,  279,
+  280,  281,  282,  283,  284,  285,   -1,   -1,  288,  289,
+  290,   -1,   -1,   -1,   -1,  295,  296,   -1,   -1,   -1,
+  300,  301,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
+   -1,  311,   -1,   -1,   10,  315,  316,   -1,   -1,   -1,
+  320,   -1,   -1,   -1,   -1,   -1,  326,   -1,  328,  329,
+   -1,   -1,  332,   -1,  334,  335,  336,  337,  338,   -1,
+  340,  341,  342,  343,  344,  345,  346,  347,  348,  349,
+  350,  351,  352,  353,  354,  355,   -1,   -1,   -1,   -1,
+  360,  361,  362,   59,  364,  365,  366,   -1,  368,  369,
+  370,   -1,   -1,  373,   -1,  375,   -1,   -1,  378,  379,
+  380,  381,   -1,   -1,  384,  385,  386,   -1,   -1,  389,
+   -1,   -1,  392,  393,  394,  395,  396,  397,  398,  399,
+   -1,  401,  402,  403,  404,  405,   -1,   -1,  408,  256,
+   -1,   -1,   -1,   -1,   -1,  415,  416,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  425,   -1,   -1,   -1,  276,
+   -1,   -1,  279,  280,  281,  282,  283,  284,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,  300,  301,   -1,   -1,    0,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,   -1,   10,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   -1,   -1,   -1,  360,  361,  362,   59,  364,  365,  366,
+   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,
+   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+  256,  408,   -1,   -1,   -1,   -1,   -1,   -1,  415,  416,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  424,  425,   -1,
+  276,   -1,   -1,  279,  280,  281,  282,  283,  284,  285,
+   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,
+  296,   -1,   -1,    0,  300,  301,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,
+  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,
+  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,
+  336,  337,  338,   -1,  340,  341,  342,  343,  344,  345,
+  346,  347,  348,  349,  350,  351,  352,  353,  354,  355,
+   -1,   -1,   59,   -1,  360,  361,  362,   -1,  364,  365,
+  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,
+   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,
+  386,   -1,   -1,  389,   -1,   -1,  392,  393,  394,  395,
+   -1,  397,  398,  399,   -1,  401,  402,  403,  404,  405,
+   -1,   -1,  408,  256,   -1,   -1,   -1,   -1,   -1,  415,
+  416,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  425,
+   -1,   -1,   -1,  276,   -1,   -1,  279,  280,  281,  282,
+  283,  284,  285,   -1,   -1,  288,  289,  290,   -1,   -1,
+   -1,   -1,  295,  296,   -1,   -1,   -1,  300,  301,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  311,   -1,
+   -1,   -1,  315,  316,   -1,   -1,   -1,  320,   -1,   -1,
+   -1,   -1,   -1,  326,   -1,  328,  329,   -1,   -1,  332,
+   -1,  334,  335,  336,  337,  338,   -1,  340,  341,  342,
+  343,  344,  345,  346,  347,  348,  349,  350,  351,  352,
+  353,  354,  355,   -1,   -1,   -1,   -1,  360,  361,  362,
+   -1,  364,  365,  366,   -1,  368,  369,  370,   -1,   -1,
+  373,   -1,  375,   -1,   -1,  378,  379,  380,  381,   -1,
+   -1,  384,  385,  386,   -1,   -1,  389,   -1,   -1,  392,
+  393,  394,  395,  396,  397,  398,  399,   -1,  401,  402,
+  403,  404,  405,   -1,   -1,  408,   40,   -1,   42,   43,
+   -1,   45,  415,  416,  417,   -1,   -1,   -1,   -1,  276,
+   -1,  424,  279,  280,  281,  282,   -1,   61,  285,   -1,
+   -1,  288,  289,  290,   -1,   -1,   -1,   -1,  295,  296,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  311,   -1,   -1,   -1,  315,  316,
+   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,   -1,  326,
+   -1,  328,  329,   -1,   -1,  332,   -1,  334,  335,  336,
+  337,  338,   -1,  340,  341,  342,  343,  344,  345,  346,
+  347,  348,  349,  350,  351,  352,  353,  354,  355,   -1,
+   -1,   -1,   -1,  360,  361,  362,   -1,  364,  365,  366,
+   -1,  368,  369,  370,   -1,   -1,  373,   -1,  375,   -1,
+   -1,  378,  379,  380,  381,   -1,   -1,  384,  385,  386,
+   -1,   -1,  389,   -1,   -1,   -1,  393,  394,  395,  396,
+  397,  398,  399,   -1,  401,  402,  403,  404,  405,   -1,
+   -1,  408,   40,   -1,   42,   43,   -1,   45,  415,  416,
+  417,   41,   42,   43,   -1,   45,   -1,  424,   -1,   -1,
+   -1,   -1,   -1,   61,   -1,   -1,   -1,   -1,   58,   -1,
+   60,   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   40,   -1,   -1,   43,   -1,   45,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   61,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  263,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  273,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  286,  287,   -1,   -1,   -1,  291,  292,  293,
+  294,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,
+  304,  305,  306,  307,  308,  309,  310,   -1,  312,  313,
+  314,   -1,   -1,  317,  318,  319,   -1,  321,  322,  323,
+  324,  325,   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   40,
+   -1,   42,   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,  382,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  390,  391,   -1,   -1,
+   -1,   -1,  396,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  406,  407,   -1,  263,  410,  411,  412,  413,
+  260,  261,  262,  417,  264,  265,  266,  267,  268,  269,
+  424,   -1,  272,  273,   -1,   -1,   -1,   -1,  286,  287,
+   -1,   -1,   -1,  291,  292,  293,  294,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,  307,
+  308,  309,  310,  263,  312,  313,  314,   -1,   -1,  317,
+  318,  319,  272,  321,  322,  323,  324,  325,   -1,  327,
+   -1,   -1,   -1,   -1,   -1,   -1,  286,  287,   -1,   -1,
+   -1,  291,  292,  293,  294,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  303,  304,  305,  306,  307,  308,  309,
+  310,   -1,  312,  313,  314,   -1,   -1,  317,  318,  319,
+   -1,  321,  322,  323,  324,  325,   40,  327,   42,   43,
+   -1,   45,   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  390,  391,   -1,   -1,   -1,   61,  396,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  406,  407,
+   -1,   -1,  410,  411,  412,  413,   -1,   -1,   -1,  417,
+   -1,   -1,   -1,   -1,   40,   -1,  424,   43,   -1,   45,
+   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  390,  391,  263,   -1,   -1,   61,  396,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  406,  407,   -1,   -1,
+  410,  411,  412,  413,   -1,  286,  287,  417,   -1,   -1,
+  291,  292,  293,  294,  424,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  303,  304,  305,  306,  307,  308,  309,  310,
+   -1,  312,  313,  314,   -1,   -1,  317,  318,  319,   -1,
+  321,  322,  323,  324,  325,   -1,  327,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   40,   -1,   -1,   43,   -1,   45,   -1,
+   -1,  382,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  390,
+  391,   -1,   -1,   -1,   61,  396,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  406,  407,   -1,   -1,  410,
+  411,  412,  413,   -1,   -1,   -1,  417,   -1,   -1,  263,
+   -1,   -1,   -1,  424,   -1,   40,   -1,   -1,   43,   -1,
+   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  286,  287,   -1,   -1,   61,  291,  292,  293,
+  294,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,
+  304,  305,  306,  307,  308,  309,  310,  263,  312,  313,
+  314,   -1,   -1,  317,  318,  319,   -1,  321,  322,  323,
+  324,  325,   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,
+  286,  287,   -1,   -1,   -1,  291,  292,  293,  294,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,
+  306,  307,  308,  309,  310,   -1,  312,  313,  314,   -1,
+   -1,  317,  318,  319,   -1,  321,  322,  323,  324,  325,
+   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,  382,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  390,  391,   -1,   -1,
+   -1,   -1,  396,   -1,   40,   -1,   -1,   43,   -1,   45,
+   -1,   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,
+   -1,   -1,   58,  417,   -1,   -1,   -1,   -1,   -1,   -1,
+  424,   -1,   -1,   -1,   -1,   -1,  382,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  390,  391,  263,   -1,   -1,   -1,
+  396,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  406,  407,   -1,   -1,  410,  411,  412,  413,   -1,  286,
+  287,  417,   -1,   -1,  291,  292,  293,  294,  424,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,
+  307,  308,  309,  310,   -1,  312,  313,  314,  263,   -1,
+  317,  318,  319,   -1,  321,  322,  323,  324,  325,   -1,
+  327,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  286,  287,   -1,   -1,   -1,  291,  292,  293,  294,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,
+  305,  306,  307,  308,  309,  310,   -1,  312,  313,  314,
+   -1,   -1,  317,  318,  319,   -1,  321,  322,  323,  324,
+  325,   -1,  327,   40,   -1,  382,   43,   -1,   45,   -1,
+   -1,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,  396,
+   -1,   58,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  406,
+  407,   -1,   -1,  410,  411,  412,  413,   -1,   -1,   -1,
+  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,   -1,   -1,
+   -1,   40,   -1,   42,   43,   -1,   45,  382,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  390,  391,  263,   -1,   -1,
+   -1,  396,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,   -1,
+  286,  287,  417,   -1,   -1,  291,  292,  293,  294,  424,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,
+  306,  307,  308,  309,  310,   -1,  312,  313,  314,   -1,
+   -1,  317,  318,  319,   -1,  321,  322,  323,  324,  325,
+   -1,  327,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   37,   -1,   -1,   40,   41,   42,
+   43,   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   60,   -1,   62,
+   40,   -1,   -1,   43,   -1,   45,  382,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,
+  396,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  406,  407,   -1,   -1,  410,  411,  412,  413,   -1,   -1,
+   -1,  417,   -1,   -1,   -1,   -1,  263,   -1,  424,   -1,
+   -1,   -1,   40,   -1,   -1,   43,   -1,   45,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  286,
+  287,   -1,   -1,   -1,  291,  292,  293,  294,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,
+  307,  308,  309,  310,  263,  312,  313,  314,   -1,   -1,
+  317,  318,  319,   -1,  321,  322,  323,  324,  325,   -1,
+  327,   -1,   -1,   -1,   -1,   -1,   -1,  286,  287,   -1,
+   -1,   -1,  291,  292,  293,  294,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  303,  304,  305,  306,  307,  308,
+  309,  310,   -1,  312,  313,  314,   -1,   -1,  317,  318,
+  319,   -1,  321,  322,  323,  324,  325,   -1,  327,   -1,
+   -1,   -1,   -1,   -1,   -1,  382,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  390,  391,   -1,   -1,   -1,   -1,  396,
+   -1,   40,   -1,   -1,   43,   -1,   45,   -1,   -1,  406,
+  407,   -1,   -1,  410,  411,  412,  413,  260,  261,  262,
+  417,  264,  265,  266,  267,  268,  269,  424,   -1,  272,
+  273,   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  390,  391,  263,   -1,   -1,   -1,  396,   -1,   40,
+   -1,   -1,   43,   -1,   45,   -1,   -1,  406,  407,   -1,
+   -1,  410,  411,  412,  413,   -1,  286,  287,  417,   -1,
+   -1,  291,  292,  293,  294,  424,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,  303,  304,  305,  306,  307,  308,  309,
+  310,   -1,  312,  313,  314,  263,   -1,  317,  318,  319,
+   -1,  321,  322,  323,  324,  325,   -1,  327,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  286,  287,
+   -1,   -1,   -1,  291,  292,  293,  294,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  303,  304,  305,  306,  307,
+  308,  309,  310,   -1,  312,  313,  314,   -1,   -1,  317,
+  318,  319,   -1,  321,  322,  323,  324,  325,   -1,  327,
+   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  390,  391,   -1,   -1,   -1,   -1,  396,   -1,   40,   -1,
+   -1,   43,   -1,   45,   -1,   -1,  406,  407,   -1,   -1,
+  410,  411,  412,  413,   -1,   -1,   -1,  417,   -1,   -1,
+   -1,   -1,   -1,   -1,  424,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  390,  391,  263,   -1,   40,   -1,  396,   43,
+   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,  406,  407,
+   -1,   -1,  410,  411,  412,  413,   -1,  286,  287,  417,
+   -1,   -1,  291,  292,  293,  294,  424,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  303,  304,  305,  306,  307,  308,
+  309,  310,  263,  312,  313,  314,   -1,   -1,  317,  318,
+  319,   -1,  321,  322,  323,  324,  325,   -1,  327,   -1,
+   -1,   -1,   -1,   -1,   -1,  286,  287,   -1,   -1,   -1,
+  291,  292,  293,  294,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,  303,  304,  305,  306,  307,  308,  309,  310,
+   -1,  312,  313,  314,   -1,   -1,  317,  318,  319,   -1,
+  321,  322,  323,  324,  325,   -1,  327,   -1,   -1,   -1,
+   -1,   -1,   -1,  382,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  390,  391,   -1,   -1,   -1,   -1,  396,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  406,  407,   -1,
+   -1,  410,  411,  412,  413,   -1,   -1,   -1,  417,   -1,
+   -1,   -1,   -1,   -1,   37,  424,   -1,   -1,   -1,   42,
+   43,  382,   45,   -1,   -1,   -1,   -1,   -1,   -1,  390,
+  391,  263,   -1,   -1,   -1,  396,   -1,   60,   61,   62,
+   -1,   -1,   -1,   -1,   -1,  406,  407,   -1,   -1,  410,
+  411,  412,  413,   -1,  286,  287,  417,   -1,   -1,  291,
+  292,  293,  294,  424,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  303,  304,  305,  306,  307,  308,  309,  310,  263,
+  312,  313,  314,   -1,   -1,  317,  318,  319,   -1,  321,
+  322,  323,  324,  325,   -1,  327,   41,   42,   43,   44,
+   45,   -1,  286,  287,   -1,   -1,   -1,  291,  292,  293,
+  294,   -1,   -1,   -1,   -1,   60,   61,   62,   -1,  303,
+  304,  305,  306,  307,  308,  309,  310,   -1,  312,  313,
+  314,   -1,   -1,  317,  318,  319,   -1,  321,  322,  323,
+  324,  325,   -1,  327,   -1,   -1,   -1,   41,   42,   43,
+  382,   45,   -1,   -1,   -1,   -1,   -1,   -1,  390,  391,
+   -1,   -1,   -1,   -1,  396,   -1,   60,   61,   62,   41,
+   42,   43,   -1,   45,  406,  407,   -1,   -1,  410,  411,
+  412,  413,   -1,   -1,   -1,  417,   -1,   -1,   60,   61,
+   62,   -1,  424,   -1,   -1,   41,   42,   43,  382,   45,
+   -1,   -1,   -1,   -1,   -1,   -1,  390,  391,   -1,   -1,
+   -1,   -1,  396,   -1,   60,   61,   62,   -1,   -1,   -1,
+   -1,   -1,  406,  407,   -1,   -1,  410,  411,  412,  413,
+   -1,   -1,   -1,  417,   -1,   -1,   -1,  260,  261,  262,
+  424,  264,  265,  266,  267,  268,  269,   -1,   -1,  272,
+  273,   41,   42,   43,   -1,   45,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   41,   42,   43,   -1,   45,
+   60,   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,   41,
+   42,   43,   -1,   45,   60,   61,   62,   -1,   -1,   -1,
+   -1,   -1,   -1,   41,   42,   43,   -1,   45,   60,   61,
+   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   60,   61,   62,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,   41,
+   42,   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   41,   42,   43,   -1,   45,   60,   61,
+   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   60,   61,   62,   -1,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+   -1,   -1,   -1,   41,   42,   43,   -1,   45,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,   60,   61,   62,   -1,   -1,   -1,   -1,   41,
+   42,   43,   -1,   45,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,   -1,  272,  273,   60,   61,
+   62,   41,   42,   43,   -1,   45,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   41,   42,   43,   -1,   45,
+   60,   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   60,   61,   62,   -1,   -1,   -1,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,   -1,  272,  273,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,   -1,  272,  273,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   41,   42,   43,   -1,
+   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   60,   61,   62,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   41,   42,   43,   -1,
+   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   60,   61,   62,   -1,   -1,
+   -1,   -1,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   41,   42,   43,   -1,   45,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,   60,   61,   62,   -1,   -1,   -1,   -1,   -1,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,   -1,  272,  273,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,   -1,  272,  273,   41,   42,
+   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   41,   42,   43,   -1,   45,   60,   61,   62,
+   -1,   -1,   -1,   -1,   -1,   -1,   41,   42,   43,   -1,
+   45,   60,   61,   62,   -1,   -1,   -1,   -1,   -1,   -1,
+   41,   42,   43,   -1,   45,   60,   61,   62,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   60,
+   61,   62,   -1,   -1,   -1,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,   41,
+   42,   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   41,   42,   43,   -1,   45,   60,   61,
+   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   60,   61,   62,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,   41,
+   42,   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   60,   61,
+   62,   -1,   -1,   -1,   -1,   -1,   -1,   41,   42,   43,
+   -1,   45,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   60,   61,   62,   41,
+   42,   43,   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   42,   43,   -1,   45,   60,   61,
+   62,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   58,   -1,   60,   61,   62,   -1,   -1,  260,  261,  262,
+   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,  272,
+  273,  260,  261,  262,   -1,  264,  265,  266,  267,  268,
+  269,   -1,   -1,  272,  273,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,  260,
+  261,  262,   -1,  264,  265,  266,  267,  268,  269,   -1,
+   -1,  272,  273,   42,   43,   -1,   45,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   58,
+   -1,   60,   61,   62,   -1,   -1,   -1,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   42,   43,   44,   45,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   60,   61,   62,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   42,   43,   44,   45,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+   60,   61,   62,   -1,   -1,   -1,   -1,   -1,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,  260,  261,  262,   -1,  264,  265,  266,  267,
+  268,  269,   -1,   -1,  272,  273,   42,   43,   -1,   45,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   42,   43,   58,   45,   60,   61,   62,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   58,   -1,   60,   61,
+   62,   42,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   60,
+   61,   62,   -1,   -1,   -1,   -1,   -1,   42,   43,   44,
+   45,  260,  261,  262,   -1,  264,  265,  266,  267,  268,
+  269,   -1,   -1,  272,  273,   60,   61,   62,   42,   43,
+   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   42,   43,   -1,   45,   60,   61,   62,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   60,   61,   62,   -1,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,   -1,  272,  273,   42,   43,
+   -1,   45,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   60,   61,   62,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,   -1,  272,  273,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  260,  261,  262,   -1,  264,  265,
+  266,  267,  268,  269,   -1,   -1,  272,  273,  260,  261,
+  262,   -1,  264,  265,  266,  267,  268,  269,   -1,   -1,
+  272,  273,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  260,
+  261,  262,   -1,  264,  265,  266,  267,  268,  269,   -1,
+   -1,  272,  273,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  260,  261,  262,   -1,  264,
+  265,  266,  267,  268,  269,   -1,   -1,  272,  273,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,   -1,   -1,  272,  273,
+  260,  261,  262,   -1,  264,  265,  266,  267,  268,  269,
+   -1,  276,  272,  273,  279,   -1,  281,  282,   -1,   -1,
+  285,   -1,   -1,  288,  289,  290,   -1,   -1,   -1,   -1,
+  295,  296,   -1,   -1,   -1,   -1,  260,  261,  262,   -1,
+  264,  265,  266,  267,  268,  269,  311,   -1,  272,  273,
+  315,  316,   -1,   -1,   -1,  320,   -1,   -1,   -1,   -1,
+   -1,  326,   -1,  328,  329,   -1,   -1,  332,   -1,  334,
+  335,  336,  337,  338,   -1,  340,  341,  342,  343,  344,
+  345,  346,  347,  348,  349,  350,  351,  352,  353,  354,
+  355,   -1,   -1,   -1,   -1,  360,  361,  362,   -1,  364,
+  365,  366,   -1,  368,  369,  370,   -1,   -1,  373,   -1,
+  375,   -1,   -1,  378,  379,  380,  381,   -1,   -1,  384,
+  385,  386,   -1,   -1,  389,   -1,   -1,   -1,  393,  394,
+  395,  396,  397,  398,  399,   -1,  401,  402,  403,  404,
+  405,   -1,   -1,  408,   -1,   -1,   -1,   -1,   -1,   -1,
+  415,  416,  417,   -1,   -1,   -1,   -1,   -1,   -1,  424,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 1
+#endif
+#define YYMAXTOKEN 427
+#if YYDEBUG
+char *fortranname[] = {
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,"'!'",0,0,0,"'%'",0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,
+0,0,0,0,0,"':'","';'","'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,"'['",0,"']'",0,"'_'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"TOK_BINARY_OP","EQV","NEQV","TOK_OR",
+"TOK_XOR","TOK_AND","TOK_NOT","TOK_LT","TOK_GT","TOK_LE","TOK_GE","TOK_EQ",
+"TOK_NE","TOK_UNARY_OP","TOK_DSLASH","TOK_SLASH","TOK_DASTER","TOK_SEP",
+"TOK_NEXTLINE","TOK_PARAMETER","TOK_RESULT","TOK_ONLY","TOK_INCLUDE",
+"TOK_SUBROUTINE","TOK_PROGRAM","TOK_FUNCTION","TOK_OMP","TOK_DOLLAR",
+"TOK_FORMAT","TOK_MAX","TOK_TANH","TOK_WHERE","TOK_ELSEWHERE","TOK_ENDWHERE",
+"TOK_MAXVAL","TOK_TRIM","TOK_SUM","TOK_SQRT","TOK_CASE","TOK_SELECTCASE",
+"TOK_FILE","TOK_END","TOK_ERR","TOK_DONOTTREAT","TOK_ENDDONOTTREAT","TOK_EXIST",
+"TOK_MIN","TOK_INT","TOK_FLOAT","TOK_EXP","TOK_COS","TOK_COSH","TOK_ACOS",
+"TOK_NINT","TOK_CYCLE","TOK_SIN","TOK_SINH","TOK_ASIN","TOK_EQUIVALENCE",
+"TOK_BACKSPACE","TOK_LOG","TOK_TAN","TOK_ATAN","TOK_RECURSIVE","TOK_ABS",
+"TOK_MOD","TOK_SIGN","TOK_MINLOC","TOK_MAXLOC","TOK_EXIT","TOK_MINVAL",
+"TOK_PUBLIC","TOK_PRIVATE","TOK_ALLOCATABLE","TOK_IN","TOK_RETURN","TOK_THEN",
+"TOK_ELSEIF","TOK_ELSE","TOK_ENDIF","TOK_PRINT","TOK_PLAINGOTO",
+"TOK_CONSTRUCTID","TOK_LOGICALIF","TOK_PLAINDO","TOK_CONTAINS","TOK_ENDDO",
+"TOK_MODULE","TOK_ENDMODULE","TOK_DOWHILE","TOK_ALLOCATE","TOK_OPEN",
+"TOK_CLOSE","TOK_INQUIRE","TOK_WRITE","TOK_READ","TOK_REWIND","TOK_DEALLOCATE",
+"TOK_NULLIFY","TOK_FIN","TOK_DEBUT","TOK_OUT","TOK_INOUT","TOK_DIMENSION",
+"TOK_ENDSELECT","TOK_EXTERNAL","TOK_INTENT","TOK_INTRINSIC","TOK_NAMELIST",
+"TOK_CASEDEFAULT","TOK_OPTIONAL","TOK_POINTER","TOK_CONTINUE","TOK_SAVE",
+"TOK_TARGET","TOK_QUOTE","TOK_IMPLICIT","TOK_NONE","TOK_CALL","TOK_STAT",
+"TOK_POINT_TO","TOK_COMMON","TOK_GLOBAL","TOK_INTERFACE","TOK_ENDINTERFACE",
+"TOK_LEFTAB","TOK_RIGHTAB","TOK_PAUSE","TOK_PROCEDURE","TOK_STOP","TOK_NAMEEQ",
+"TOK_REAL8","TOK_USE","TOK_TRUE","TOK_FALSE","TOK_LABEL","TOK_TYPE",
+"TOK_TYPEPAR","TOK_ENDTYPE","TOK_REAL","TOK_INTEGER","TOK_LOGICAL",
+"TOK_DOUBLEPRECISION","TOK_DOUBLEREAL","TOK_ENDSUBROUTINE","TOK_ENDFUNCTION",
+"TOK_ENDPROGRAM","TOK_ENDUNIT","TOK_CHARACTER","TOK_CHAR_CONSTANT",
+"TOK_CHAR_CUT","TOK_DATA","TOK_CHAR_INT","TOK_CHAR_MESSAGE","TOK_CSTREAL",
+"TOK_CSTREALDP","TOK_CSTREALQP","TOK_SFREAL","TOK_COMPLEX","TOK_DOUBLECOMPLEX",
+"TOK_NAME","TOK_NAME_CHAR","TOK_PROBTYPE","TOK_INTERPTYPE","TOK_VARTYPE",
+"TOK_BC","TOK_OP","TOK_CSTINT","TOK_COMMENT","TOK_FILENAME","\"* \"",
+};
+char *fortranrule[] = {
+"$accept : input",
+"input :",
+"input : input line",
+"line : '\\n' position",
+"line : thislabel suite_line_list",
+"line : TOK_COMMENT",
+"line : keyword cmnt writedeclar",
+"line : error writedeclar nulcurbuf",
+"suite_line_list : suite_line",
+"suite_line_list : suite_line ';' suite_line_list",
+"suite_line : entry fin_line",
+"suite_line : spec fin_line",
+"suite_line : before_include filename fin_line",
+"suite_line : exec cmnt writedeclar",
+"suite_line : instr fin_line",
+"instr : ident ':'",
+"fin_line : position cmnt",
+"keyword : TOK_DONOTTREAT",
+"keyword : TOK_ENDDONOTTREAT",
+"keyword : TOK_OMP",
+"keyword : TOK_DOLLAR",
+"position :",
+"thislabel :",
+"thislabel : TOK_LABEL nulcurbuf",
+"cmnt :",
+"cmnt : TOK_COMMENT",
+"incomment :",
+"nulcurbuf :",
+"opt_recursive :",
+"opt_recursive : TOK_RECURSIVE",
+"entry :",
+"entry : opt_recursive TOK_SUBROUTINE name_routine arglist",
+"entry : TOK_PROGRAM name_routine",
+"entry : TOK_FUNCTION name_routine arglist TOK_RESULT arglist1",
+"entry : TOK_FUNCTION name_routine arglist",
+"entry : TOK_MODULE TOK_NAME",
+"name_routine : TOK_NAME",
+"writedeclar :",
+"before_include : TOK_INCLUDE",
+"filename : TOK_CHAR_CONSTANT",
+"arglist :",
+"arglist : '(' ')'",
+"arglist : '(' args ')'",
+"arglist1 :",
+"arglist1 : '(' ')'",
+"arglist1 : '(' args ')'",
+"args : arg",
+"args : args ',' arg",
+"arg : TOK_NAME",
+"arg : '*'",
+"spec : type after_type",
+"spec : TOK_TYPE opt_spec opt_sep opt_name",
+"spec : TOK_ENDTYPE opt_name",
+"spec : TOK_POINTER list_couple",
+"spec : before_parameter '(' paramlist ')'",
+"spec : before_parameter paramlist",
+"spec : common",
+"spec : save",
+"spec : implicit",
+"spec : dimension",
+"spec : public",
+"spec : private",
+"spec : use_stat",
+"spec : module_proc_stmt",
+"spec : interface",
+"spec : namelist",
+"spec : TOK_BACKSPACE '(' expr ')'",
+"spec : TOK_EXTERNAL opt_sep use_name_list",
+"spec : TOK_INTRINSIC opt_sep use_intrinsic_list",
+"spec : TOK_EQUIVALENCE list_expr_equi",
+"spec : before_data data '\\n'",
+"opt_spec :",
+"opt_spec : access_spec",
+"name_intrinsic : TOK_SUM",
+"name_intrinsic : TOK_TANH",
+"name_intrinsic : TOK_MAXVAL",
+"name_intrinsic : TOK_MIN",
+"name_intrinsic : TOK_MINVAL",
+"name_intrinsic : TOK_TRIM",
+"name_intrinsic : TOK_SQRT",
+"name_intrinsic : TOK_NINT",
+"name_intrinsic : TOK_FLOAT",
+"name_intrinsic : TOK_EXP",
+"name_intrinsic : TOK_COS",
+"name_intrinsic : TOK_COSH",
+"name_intrinsic : TOK_ACOS",
+"name_intrinsic : TOK_SIN",
+"name_intrinsic : TOK_SINH",
+"name_intrinsic : TOK_ASIN",
+"name_intrinsic : TOK_LOG",
+"name_intrinsic : TOK_TAN",
+"name_intrinsic : TOK_ATAN",
+"name_intrinsic : TOK_MOD",
+"name_intrinsic : TOK_SIGN",
+"name_intrinsic : TOK_MINLOC",
+"name_intrinsic : TOK_MAXLOC",
+"name_intrinsic : TOK_NAME",
+"use_intrinsic_list : name_intrinsic",
+"use_intrinsic_list : use_intrinsic_list ',' name_intrinsic",
+"list_couple : '(' list_expr ')'",
+"list_couple : list_couple ',' '(' list_expr ')'",
+"list_expr_equi : expr_equi",
+"list_expr_equi : list_expr_equi ',' expr_equi",
+"expr_equi : '(' list_expr_equi1 ')'",
+"list_expr_equi1 : ident dims",
+"list_expr_equi1 : list_expr_equi1 ',' ident dims",
+"list_expr : expr",
+"list_expr : list_expr ',' expr",
+"opt_sep :",
+"opt_sep : ':' ':'",
+"after_type : dcl nodimsgiven",
+"after_type : before_function name_routine arglist",
+"before_function : TOK_FUNCTION",
+"before_parameter : TOK_PARAMETER",
+"before_data : TOK_DATA",
+"data : TOK_NAME TOK_SLASH datavallist TOK_SLASH",
+"data : data opt_comma TOK_NAME TOK_SLASH datavallist TOK_SLASH",
+"data : datanamelist TOK_SLASH datavallist TOK_SLASH",
+"datavallist : expr_data",
+"datavallist : expr_data ',' datavallist",
+"save : before_save varsave",
+"save : before_save comblock varsave",
+"save : save opt_comma comblock opt_comma varsave",
+"save : save ',' varsave",
+"before_save : TOK_SAVE",
+"varsave :",
+"varsave : TOK_NAME dims",
+"datanamelist : TOK_NAME",
+"datanamelist : TOK_NAME '(' expr ')'",
+"datanamelist : datanamelist ',' datanamelist",
+"expr_data : opt_signe simple_const",
+"expr_data : expr_data '+' expr_data",
+"expr_data : expr_data '-' expr_data",
+"expr_data : expr_data '*' expr_data",
+"expr_data : expr_data '/' expr_data",
+"opt_signe :",
+"opt_signe : signe",
+"namelist : namelist_action after_namelist",
+"namelist_action : TOK_NAMELIST ident",
+"namelist_action : TOK_NAMELIST comblock ident",
+"namelist_action : namelist_action opt_comma comblock opt_comma ident",
+"namelist_action : namelist_action ',' ident",
+"after_namelist :",
+"interface : TOK_INTERFACE opt_name",
+"interface : TOK_ENDINTERFACE opt_name",
+"before_dimension : TOK_DIMENSION",
+"dimension : before_dimension opt_comma TOK_NAME dims lengspec",
+"dimension : dimension ',' TOK_NAME dims lengspec",
+"private : TOK_PRIVATE '\\n'",
+"private : TOK_PRIVATE opt_sep use_name_list",
+"public : TOK_PUBLIC '\\n'",
+"public : TOK_PUBLIC opt_sep use_name_list",
+"use_name_list : TOK_NAME",
+"use_name_list : use_name_list ',' TOK_NAME",
+"common : before_common var_common_list",
+"common : before_common comblock var_common_list",
+"common : common opt_comma comblock opt_comma var_common_list",
+"before_common : TOK_COMMON",
+"before_common : TOK_GLOBAL TOK_COMMON",
+"var_common_list : var_common",
+"var_common_list : var_common_list ',' var_common",
+"var_common : TOK_NAME dims",
+"comblock : TOK_DSLASH",
+"comblock : TOK_SLASH TOK_NAME TOK_SLASH",
+"opt_comma :",
+"opt_comma : ','",
+"paramlist : paramitem",
+"paramlist : paramlist ',' paramitem",
+"paramitem : TOK_NAME '=' expr",
+"module_proc_stmt : TOK_PROCEDURE proc_name_list",
+"proc_name_list : TOK_NAME",
+"proc_name_list : proc_name_list ',' TOK_NAME",
+"implicit : TOK_IMPLICIT TOK_NONE",
+"implicit : TOK_IMPLICIT TOK_REAL8",
+"opt_retour :",
+"dcl : options opt_retour TOK_NAME dims lengspec initial_value",
+"dcl : dcl ',' opt_retour TOK_NAME dims lengspec initial_value",
+"nodimsgiven :",
+"type : typespec selector",
+"type : before_character c_selector",
+"type : typename '*' TOK_CSTINT",
+"type : before_typepar attribute ')'",
+"before_typepar : TOK_TYPEPAR",
+"c_selector :",
+"c_selector : '*' TOK_CSTINT",
+"c_selector : '*' '(' c_attribute ')'",
+"c_selector : '(' c_attribute ')'",
+"c_attribute : TOK_NAME clause opt_clause",
+"c_attribute : TOK_NAME '=' clause opt_clause",
+"c_attribute : clause opt_clause",
+"before_character : TOK_CHARACTER",
+"typespec : typename",
+"typename : TOK_INTEGER",
+"typename : TOK_REAL",
+"typename : TOK_COMPLEX",
+"typename : TOK_DOUBLEPRECISION",
+"typename : TOK_DOUBLECOMPLEX",
+"typename : TOK_LOGICAL",
+"lengspec :",
+"lengspec : '*' proper_lengspec",
+"proper_lengspec : expr",
+"proper_lengspec : '(' '*' ')'",
+"selector :",
+"selector : '*' proper_selector",
+"selector : '(' attribute ')'",
+"proper_selector : expr",
+"proper_selector : '(' '*' ')'",
+"attribute : TOK_NAME clause",
+"attribute : TOK_NAME '=' clause",
+"attribute : TOK_NAME",
+"attribute : TOK_CSTINT",
+"clause : expr",
+"clause : '*'",
+"opt_clause :",
+"opt_clause : ',' TOK_NAME clause",
+"options :",
+"options : ':' ':'",
+"options : ',' attr_spec_list ':' ':'",
+"attr_spec_list : attr_spec",
+"attr_spec_list : attr_spec_list ',' attr_spec",
+"attr_spec : TOK_PARAMETER",
+"attr_spec : access_spec",
+"attr_spec : TOK_ALLOCATABLE",
+"attr_spec : TOK_DIMENSION dims",
+"attr_spec : TOK_EXTERNAL",
+"attr_spec : TOK_INTENT intent_spec",
+"attr_spec : TOK_INTRINSIC",
+"attr_spec : TOK_OPTIONAL",
+"attr_spec : TOK_POINTER",
+"attr_spec : TOK_SAVE",
+"attr_spec : TOK_TARGET",
+"intent_spec : TOK_IN",
+"intent_spec : TOK_OUT",
+"intent_spec : TOK_INOUT",
+"access_spec : TOK_PUBLIC",
+"access_spec : TOK_PRIVATE",
+"dims :",
+"dims : '(' dimlist ')'",
+"dimlist : dim",
+"dimlist : dimlist ',' dim",
+"dim : ubound",
+"dim : ':'",
+"dim : expr ':'",
+"dim : ':' expr",
+"dim : expr ':' ubound",
+"ubound : '*'",
+"ubound : expr",
+"expr : uexpr",
+"expr : '(' expr ')'",
+"expr : complex_const",
+"expr : predefinedfunction",
+"predefinedfunction : TOK_SUM minmaxlist ')'",
+"predefinedfunction : TOK_MAX minmaxlist ')'",
+"predefinedfunction : TOK_TANH '(' minmaxlist ')'",
+"predefinedfunction : TOK_MAXVAL '(' minmaxlist ')'",
+"predefinedfunction : TOK_MIN minmaxlist ')'",
+"predefinedfunction : TOK_MINVAL '(' minmaxlist ')'",
+"predefinedfunction : TOK_TRIM '(' expr ')'",
+"predefinedfunction : TOK_SQRT expr ')'",
+"predefinedfunction : TOK_REAL '(' minmaxlist ')'",
+"predefinedfunction : TOK_INT '(' expr ')'",
+"predefinedfunction : TOK_NINT '(' expr ')'",
+"predefinedfunction : TOK_FLOAT '(' expr ')'",
+"predefinedfunction : TOK_EXP '(' expr ')'",
+"predefinedfunction : TOK_COS '(' expr ')'",
+"predefinedfunction : TOK_COSH '(' expr ')'",
+"predefinedfunction : TOK_ACOS '(' expr ')'",
+"predefinedfunction : TOK_SIN '(' expr ')'",
+"predefinedfunction : TOK_SINH '(' expr ')'",
+"predefinedfunction : TOK_ASIN '(' expr ')'",
+"predefinedfunction : TOK_LOG '(' expr ')'",
+"predefinedfunction : TOK_TAN '(' expr ')'",
+"predefinedfunction : TOK_ATAN '(' expr ')'",
+"predefinedfunction : TOK_ABS expr ')'",
+"predefinedfunction : TOK_MOD '(' minmaxlist ')'",
+"predefinedfunction : TOK_SIGN '(' minmaxlist ')'",
+"predefinedfunction : TOK_MINLOC '(' minmaxlist ')'",
+"predefinedfunction : TOK_MAXLOC '(' minmaxlist ')'",
+"minmaxlist : expr",
+"minmaxlist : minmaxlist ',' expr",
+"uexpr : lhs",
+"uexpr : simple_const",
+"uexpr : vec",
+"uexpr : expr operation",
+"uexpr : signe expr",
+"uexpr : TOK_NOT expr",
+"signe : '+'",
+"signe : '-'",
+"operation : '+' expr",
+"operation : '-' expr",
+"operation : '*' expr",
+"operation : TOK_DASTER expr",
+"operation : TOK_EQ expr",
+"operation : TOK_GT expr",
+"operation : '>' expr",
+"operation : TOK_LT expr",
+"operation : '<' expr",
+"operation : TOK_GE expr",
+"operation : '>' '=' expr",
+"operation : TOK_LE expr",
+"operation : '<' '=' expr",
+"operation : TOK_NE expr",
+"operation : TOK_XOR expr",
+"operation : TOK_OR expr",
+"operation : TOK_AND expr",
+"operation : TOK_SLASH after_slash",
+"operation : '=' after_equal",
+"after_slash :",
+"after_slash : expr",
+"after_slash : '=' expr",
+"after_slash : TOK_SLASH expr",
+"after_equal : '=' expr",
+"after_equal : expr",
+"lhs : ident",
+"lhs : structure_component",
+"lhs : array_ele_substring_func_ref",
+"beforefunctionuse :",
+"array_ele_substring_func_ref : begin_array",
+"array_ele_substring_func_ref : begin_array substring",
+"array_ele_substring_func_ref : structure_component '(' funarglist ')'",
+"array_ele_substring_func_ref : structure_component '(' funarglist ')' substring",
+"begin_array : ident '(' funarglist ')'",
+"structure_component : lhs '%' lhs",
+"vec : TOK_LEFTAB outlist TOK_RIGHTAB",
+"funarglist : beforefunctionuse",
+"funarglist : beforefunctionuse funargs",
+"funargs : funarg",
+"funargs : funargs ',' funarg",
+"funarg : expr",
+"funarg : triplet",
+"triplet : expr ':' expr",
+"triplet : expr ':' expr ':' expr",
+"triplet : ':' expr ':' expr",
+"triplet : ':' ':' expr",
+"triplet : ':' expr",
+"triplet : expr ':'",
+"triplet : ':'",
+"ident : TOK_NAME",
+"simple_const : TOK_TRUE",
+"simple_const : TOK_FALSE",
+"simple_const : TOK_CSTINT",
+"simple_const : TOK_CSTREAL",
+"simple_const : TOK_CSTREALDP",
+"simple_const : TOK_CSTREALQP",
+"simple_const : simple_const TOK_NAME",
+"simple_const : string_constant opt_substring",
+"string_constant : TOK_CHAR_CONSTANT",
+"string_constant : string_constant TOK_CHAR_CONSTANT",
+"string_constant : TOK_CHAR_MESSAGE",
+"string_constant : TOK_CHAR_CUT",
+"opt_substring :",
+"opt_substring : substring",
+"substring : '(' optexpr ':' optexpr ')'",
+"optexpr :",
+"optexpr : expr",
+"opt_expr : '\\n'",
+"opt_expr : expr",
+"initial_value :",
+"initial_value : before_initial '=' expr",
+"before_initial :",
+"complex_const : '(' uexpr ',' uexpr ')'",
+"use_stat : word_use module_name",
+"use_stat : word_use module_name ',' rename_list",
+"use_stat : word_use module_name ',' TOK_ONLY ':' '\\n'",
+"use_stat : word_use module_name ',' TOK_ONLY ':' only_list",
+"word_use : TOK_USE",
+"module_name : TOK_NAME",
+"rename_list : rename_name",
+"rename_list : rename_list ',' rename_name",
+"rename_name : TOK_NAME TOK_POINT_TO TOK_NAME",
+"only_list : only_name",
+"only_list : only_list ',' only_name",
+"only_name : TOK_NAME TOK_POINT_TO TOK_NAME",
+"only_name : TOK_NAME",
+"exec : iffable",
+"exec : TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'",
+"exec : TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'",
+"exec : TOK_NULLIFY '(' pointer_name_list ')'",
+"exec : word_endunit",
+"exec : word_endprogram opt_name",
+"exec : word_endsubroutine opt_name",
+"exec : word_endfunction opt_name",
+"exec : TOK_ENDMODULE opt_name",
+"exec : boucledo",
+"exec : logif iffable",
+"exec : TOK_WHERE '(' expr ')' opt_expr",
+"exec : TOK_ELSEWHERE",
+"exec : TOK_ENDWHERE",
+"exec : logif TOK_THEN",
+"exec : TOK_ELSEIF '(' expr ')' TOK_THEN",
+"exec : TOK_ELSE",
+"exec : TOK_ENDIF opt_name",
+"exec : TOK_CASE caselist ')'",
+"exec : TOK_SELECTCASE '(' expr ')'",
+"exec : TOK_CASEDEFAULT",
+"exec : TOK_ENDSELECT",
+"exec : TOK_CONTAINS",
+"word_endsubroutine : TOK_ENDSUBROUTINE",
+"word_endunit : TOK_ENDUNIT",
+"word_endprogram : TOK_ENDPROGRAM",
+"word_endfunction : TOK_ENDFUNCTION",
+"caselist : expr",
+"caselist : caselist ',' expr",
+"caselist : caselist ':' expr",
+"boucledo : worddo opt_int do_arg",
+"boucledo : wordwhile expr",
+"boucledo : TOK_ENDDO optname",
+"do_arg :",
+"do_arg : do_var '=' expr ',' expr",
+"do_arg : do_var '=' expr ',' expr ',' expr",
+"opt_int :",
+"opt_int : TOK_CSTINT opt_comma",
+"opt_name : '\\n'",
+"opt_name : TOK_NAME",
+"optname :",
+"optname : TOK_NAME",
+"worddo : TOK_PLAINDO",
+"wordwhile : TOK_DOWHILE",
+"dotarget :",
+"dotarget : TOK_CSTINT",
+"iffable : TOK_CONTINUE",
+"iffable : ident_dims after_ident_dims",
+"iffable : goto",
+"iffable : io",
+"iffable : call",
+"iffable : TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'",
+"iffable : TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'",
+"iffable : TOK_EXIT optexpr",
+"iffable : TOK_RETURN opt_expr",
+"iffable : TOK_CYCLE opt_expr",
+"iffable : stop opt_expr",
+"iffable : int_list",
+"before_dims :",
+"ident_dims : ident before_dims dims dims",
+"ident_dims : ident_dims '%' ident before_dims dims dims",
+"int_list : TOK_CSTINT",
+"int_list : int_list ',' TOK_CSTINT",
+"after_ident_dims : '=' expr",
+"after_ident_dims : TOK_POINT_TO expr",
+"call : keywordcall opt_call",
+"opt_call :",
+"opt_call : '(' opt_callarglist ')'",
+"opt_callarglist :",
+"opt_callarglist : callarglist",
+"keywordcall : before_call TOK_NAME",
+"before_call : TOK_CALL",
+"callarglist : callarg",
+"callarglist : callarglist ',' callarg",
+"callarg : expr",
+"callarg : '*' label",
+"stop : TOK_PAUSE",
+"stop : TOK_STOP",
+"io : iofctl ioctl",
+"io : read option_read",
+"io : TOK_REWIND after_rewind",
+"io : TOK_FORMAT",
+"opt_CHAR_INT :",
+"opt_CHAR_INT : TOK_CSTINT TOK_NAME",
+"idfile : '*'",
+"idfile : TOK_CSTINT",
+"idfile : ident",
+"option_print :",
+"option_print : ',' outlist",
+"option_inlist :",
+"option_inlist : inlist",
+"option_read : ioctl option_inlist",
+"option_read : infmt opt_inlist",
+"opt_outlist :",
+"opt_outlist : outlist",
+"opt_inlist :",
+"opt_inlist : ',' inlist",
+"ioctl : '(' ctllist ')'",
+"ioctl : '(' fexpr ')'",
+"after_rewind : '(' ident ')'",
+"after_rewind : '(' TOK_CSTINT ')'",
+"after_rewind : TOK_CSTINT",
+"after_rewind : '(' uexpr ')'",
+"after_rewind : TOK_NAME",
+"ctllist : ioclause",
+"ctllist : ctllist ',' ioclause",
+"ioclause : fexpr",
+"ioclause : '*'",
+"ioclause : TOK_DASTER",
+"ioclause : TOK_NAME expr",
+"ioclause : TOK_NAME expr '%' ident_dims",
+"ioclause : TOK_NAME '(' triplet ')'",
+"ioclause : TOK_NAME '*'",
+"ioclause : TOK_NAME TOK_DASTER",
+"iofctl : TOK_OPEN",
+"iofctl : TOK_CLOSE",
+"infmt : unpar_fexpr",
+"infmt : '*'",
+"read : TOK_READ",
+"read : TOK_INQUIRE",
+"read : TOK_WRITE",
+"read : TOK_PRINT",
+"fexpr : unpar_fexpr",
+"fexpr : '(' fexpr ')'",
+"unpar_fexpr : lhs",
+"unpar_fexpr : simple_const",
+"unpar_fexpr : fexpr addop fexpr",
+"unpar_fexpr : fexpr '*' fexpr",
+"unpar_fexpr : fexpr TOK_SLASH fexpr",
+"unpar_fexpr : fexpr TOK_DASTER fexpr",
+"unpar_fexpr : addop fexpr",
+"unpar_fexpr : fexpr TOK_DSLASH fexpr",
+"unpar_fexpr : TOK_FILE expr",
+"unpar_fexpr : TOK_EXIST expr",
+"unpar_fexpr : TOK_ERR expr",
+"unpar_fexpr : TOK_END expr",
+"unpar_fexpr : TOK_NAME '=' expr",
+"addop : '+'",
+"addop : '-'",
+"inlist : inelt",
+"inlist : inlist ',' inelt",
+"opt_lhs :",
+"opt_lhs : lhs",
+"inelt : opt_lhs opt_operation",
+"inelt : '(' inlist ')' opt_operation",
+"inelt : predefinedfunction opt_operation",
+"inelt : simple_const opt_operation",
+"inelt : '(' inlist ',' dospec ')'",
+"opt_operation :",
+"opt_operation : operation",
+"opt_operation : opt_operation operation",
+"outlist : other",
+"outlist : out2",
+"out2 : uexpr ',' expr",
+"out2 : uexpr ',' other",
+"out2 : other ',' expr",
+"out2 : other ',' other",
+"out2 : out2 ',' expr",
+"out2 : out2 ',' other",
+"out2 : uexpr",
+"out2 : predefinedfunction",
+"other : complex_const",
+"other : '(' expr ')'",
+"other : '(' uexpr ',' dospec ')'",
+"other : '(' other ',' dospec ')'",
+"other : '(' out2 ',' dospec ')'",
+"dospec : TOK_NAME '=' expr ',' expr",
+"dospec : TOK_NAME '=' expr ',' expr ',' expr",
+"labellist : label",
+"labellist : labellist ',' label",
+"label : TOK_CSTINT",
+"goto : TOK_PLAINGOTO '(' expr ',' expr ')' ',' expr",
+"goto : TOK_PLAINGOTO label",
+"allocation_list : allocate_object",
+"allocation_list : ident_dims",
+"allocation_list : allocation_list ',' allocate_object",
+"allocate_object : ident",
+"allocate_object : structure_component",
+"allocate_object : array_element",
+"array_element : ident '(' funargs ')'",
+"subscript_list : expr",
+"subscript_list : subscript_list ',' expr",
+"allocate_object_list : allocate_object",
+"allocate_object_list : allocate_object_list ',' allocate_object",
+"opt_stat_spec :",
+"opt_stat_spec : ',' TOK_STAT '=' ident",
+"pointer_name_list : ident",
+"pointer_name_list : pointer_name_list ',' ident",
+"opt_construct_name :",
+"opt_construct_name : TOK_NAME",
+"opt_construct_name_colon :",
+"opt_construct_name_colon : TOK_CONSTRUCTID ':'",
+"logif : TOK_LOGICALIF expr ')'",
+"do_var : ident",
+};
+#endif
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH 500
+#endif
+#endif
+int yydebug;
+int yynerrs;
+int yyerrflag;
+int yychar;
+short *yyssp;
+YYSTYPE *yyvsp;
+YYSTYPE yyval;
+YYSTYPE yylval;
+short yyss[YYSTACKSIZE];
+YYSTYPE yyvs[YYSTACKSIZE];
+#define yystacksize YYSTACKSIZE
+#line 2419 "fortran.y"
+
+void processfortran(char *fichier_entree)
+{
+   extern FILE *fortranin;
+   extern FILE *fortranout;
+   char nomfile[LONGNOM];
+   int c;
+   int confirmyes;
+
+   /*fortrandebug = 1;*/
+   if ( mark == 1 ) printf("Firstpass == %d \n",firstpass);
+/******************************************************************************/
+/*  1-  Open input and output files                                           */
+/******************************************************************************/
+   strcpy(nomfile,commondirin);
+   strcat(nomfile,"/");
+   strcat(nomfile,fichier_entree);
+   fortranin=fopen( nomfile,"r");
+   if (! fortranin)
+   {
+      printf("Error : File %s does not exist\n",nomfile);
+      exit(1);
+   }
+
+   strcpy(curfile,nomfile);
+   strcpy(nomfile,commondirout);
+   strcat(nomfile,"/");
+   strcat(nomfile,fichier_entree);
+   strcpy(nomfileoutput,nomfile);
+   if (firstpass == 1)
+   {
+      if (checkexistcommon == 1)
+      {
+         if (fopen(nomfile,"r"))
+         {
+            printf("Warning : file %s already exist\n",nomfile);
+            confirmyes = 0;
+            while (confirmyes==0)
+            {
+               printf("Override file %s ? [Y/N]\n",nomfile);
+               c=getchar();
+               getchar();
+               if (c==79 || c==110)
+               {
+                  printf("We stop\n");
+                  exit(1);
+               }
+               if (c==89 || c==121)
+               {
+                  confirmyes=1;
+               }
+            }
+         }
+      }
+   }
+
+/******************************************************************************/
+/*  2-  Variables initialization                                              */
+/******************************************************************************/
+
+   line_num_fortran_common=1;
+   line_num_fortran=1;
+   PublicDeclare = 0;
+   PrivateDeclare = 0;
+   ExternalDeclare = 0;
+   SaveDeclare = 0;
+   pointerdeclare = 0;
+   optionaldeclare = 0;
+   incalldeclare = 0;
+   VarType = 0;
+   VarTypepar = 0;
+   Allocatabledeclare = 0 ;
+   strcpy(NamePrecision," ");
+   VariableIsParameter =  0 ;
+   strcpy(NamePrecision,"");
+   c_star = 0 ;
+   functiondeclarationisdone = 0;
+   insubroutinedeclare = 0 ;
+   strcpy(subroutinename," ");
+   InitialValueGiven = 0 ;
+   strcpy(EmptyChar," ");
+   inmoduledeclare = 0;
+   colnum=0;
+   incom=0;
+   couldaddvariable=1;
+   aftercontainsdeclare = 1;
+   /* Name of the file without format                                         */
+   tmp = strchr(fichier_entree, '.');
+   strncpy(curfilename,fichier_entree,strlen(fichier_entree)-strlen(tmp));
+/******************************************************************************/
+/*  3-  Parsing of the input file (1 time)                                    */
+/******************************************************************************/
+   if (firstpass == 0 )
+   {
+      fortranout=fopen(nomfileoutput,"w");
+
+      NewModule_Creation_0();
+   }
+
+   fortranparse();
+
+   strcpy(curfile,mainfile);
+
+   if (firstpass == 0 ) fclose(fortranout);
+}
+#line 6892 "y.tab.c"
+#define YYABORT goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR goto yyerrlab
+int
+yyparse(void)
+{
+    register int yym, yyn, yystate;
+#if YYDEBUG
+    register char *yys;
+    extern char *getenv();
+
+    if (yys = getenv("YYDEBUG"))
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = (-1);
+
+    yyssp = yyss;
+    yyvsp = yyvs;
+    *yyssp = yystate = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yyssp >= yyss + yystacksize - 1)
+        {
+            goto yyoverflow;
+        }
+        *++yyssp = yystate = yytable[yyn];
+        *++yyvsp = yylval;
+        yychar = (-1);
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+#ifdef lint
+    goto yynewerror;
+#endif
+yynewerror:
+    yyerror("syntax error");
+#ifdef lint
+    goto yyerrlab;
+#endif
+yyerrlab:
+    ++yynerrs;
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
+#endif
+                if (yyssp >= yyss + yystacksize - 1)
+                {
+                    goto yyoverflow;
+                }
+                *++yyssp = yystate = yytable[yyn];
+                *++yyvsp = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yyssp);
+#endif
+                if (yyssp <= yyss) goto yyabort;
+                --yyssp;
+                --yyvsp;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = (-1);
+        goto yyloop;
+    }
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    yyval = yyvsp[1-yym];
+    switch (yyn)
+    {
+case 7:
+#line 335 "fortran.y"
+{yyerrok;yyclearin;}
+break;
+case 12:
+#line 343 "fortran.y"
+{
+                     if (inmoduledeclare == 0 )
+                     {
+                        pos_end = setposcur();
+                        RemoveWordSET_0(fortranout,pos_curinclude,
+                                              pos_end-pos_curinclude);
+                     }
+                  }
+break;
+case 17:
+#line 359 "fortran.y"
+{
+            /* we should ignore the declaration until the keyword             */
+            /*    TOK_ENDDONOTTREAT                                           */
+            couldaddvariable = 0 ;
+            RemoveWordCUR_0(fortranout,-20,20);
+         }
+break;
+case 18:
+#line 366 "fortran.y"
+{
+             couldaddvariable = 1 ;
+             RemoveWordCUR_0(fortranout,-24,24);
+          }
+break;
+case 21:
+#line 373 "fortran.y"
+{pos_cur = setposcur();}
+break;
+case 26:
+#line 382 "fortran.y"
+{incom = 1;}
+break;
+case 27:
+#line 385 "fortran.y"
+{if (incom !=1) {strcpy(curbuf,"");incom=0;}}
+break;
+case 31:
+#line 392 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,yyvsp[-1].na);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
+                      Add_SubroutineArgument_Var_1(yyvsp[0].l);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(1);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            writeheadnewsub_0(1);
+                      }
+                      }
+                   }
+break;
+case 32:
+#line 420 "fortran.y"
+{
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,yyvsp[0].na);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
+                      strcpy(subroutinename,yyvsp[0].na);
+                      /* Common case                                          */
+                      insubroutinedeclare = 1;
+                      /* in the second step we should write the head of       */
+                      /*    the subroutine sub_loop_<subroutinename>          */
+                      writeheadnewsub_0(1);
+                   }
+break;
+case 33:
+#line 438 "fortran.y"
+{
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,yyvsp[-3].na);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,yyvsp[-3].na);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1(yyvsp[-2].l);
+                         strcpy(DeclType,"");
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            /* we should to list of the subroutine argument   */
+                            /* name of the function which has to be defined   */
+                            Add_SubroutineArgument_Var_1(yyvsp[-2].l);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1(yyvsp[-3].na);
+                            writeheadnewsub_0(2);
+                      }
+                   }
+break;
+case 34:
+#line 471 "fortran.y"
+{
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,yyvsp[-1].na);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,yyvsp[-1].na);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1(yyvsp[0].l);
+                         strcpy(DeclType,"");
+                         Add_FunctionType_Var_1(yyvsp[-1].na);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            /* we should to list of the subroutine argument   */
+                            /* name of the function which has to be defined   */
+                            Add_SubroutineArgument_Var_1(yyvsp[0].l);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1(yyvsp[-1].na);
+                            writeheadnewsub_0(2);
+                      }
+                   }
+break;
+case 35:
+#line 505 "fortran.y"
+{
+                      GlobalDeclaration = 0;
+                      strcpy(curmodulename,yyvsp[0].na);
+                      strcpy(subroutinename,"");
+                      Add_NameOfModule_1(yyvsp[0].na);
+                      if ( inmoduledeclare == 0 )
+                      {
+                         /* To know if there are in the module declaration    */
+                         inmoduledeclare = 1;
+                         /* to know if a module has been met                  */
+                         inmodulemeet = 1;
+                         /* to know if we are after the keyword contains      */
+                         aftercontainsdeclare = 0 ;
+                      }
+                   }
+break;
+case 36:
+#line 522 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy(yyval.na,yyvsp[0].na);strcpy(subroutinename,yyvsp[0].na);
+                      }
+                   }
+break;
+case 38:
+#line 531 "fortran.y"
+{
+                      pos_curinclude = setposcur()-9;
+                   }
+break;
+case 39:
+#line 535 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) Add_Include_1(yyvsp[0].na);
+                   }
+break;
+case 40:
+#line 539 "fortran.y"
+{
+                      if ( firstpass == 1 && couldaddvariable == 1) yyval.l=NULL;
+                   }
+break;
+case 41:
+#line 542 "fortran.y"
+{
+                      if ( firstpass == 1 && couldaddvariable == 1 ) yyval.l=NULL;
+                   }
+break;
+case 42:
+#line 546 "fortran.y"
+{
+                       if ( firstpass == 1 && couldaddvariable == 1 ) yyval.l=yyvsp[-1].l;
+                   }
+break;
+case 45:
+#line 553 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         Add_SubroutineArgument_Var_1(yyvsp[-1].l);
+                      }
+                   }
+break;
+case 46:
+#line 560 "fortran.y"
+{
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar(yyvsp[0].na,NULL);
+                         curlistvar=insertvar(NULL,curvar);
+                         yyval.l=settype("",curlistvar);
+                      }
+                   }
+break;
+case 47:
+#line 569 "fortran.y"
+{
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar(yyvsp[0].na,NULL);
+                         yyval.l=insertvar(yyvsp[-2].l,curvar);
+                      }
+                   }
+break;
+case 48:
+#line 577 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 49:
+#line 578 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,"*");}
+break;
+case 50:
+#line 581 "fortran.y"
+{
+                      if ( VarTypepar == 1 )
+                      {
+                         couldaddvariable = 1 ;
+                         VarTypepar = 0;
+                      }
+                   }
+break;
+case 51:
+#line 589 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         VarType = 1;
+                         couldaddvariable = 0 ;
+                      }
+                   }
+break;
+case 52:
+#line 597 "fortran.y"
+{
+                      if ( VarType == 1 ) couldaddvariable = 1 ;
+                      VarType = 0;
+                      VarTypepar = 0;
+                   }
+break;
+case 54:
+#line 604 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1(yyvsp[-1].l);
+                         else Add_Parameter_Var_1(yyvsp[-1].l);
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
+                   }
+break;
+case 55:
+#line 617 "fortran.y"
+{
+                     if ( couldaddvariable == 1 )
+                     {
+                        if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1(yyvsp[0].l);
+                         else Add_Parameter_Var_1(yyvsp[0].l);
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
+                   }
+break;
+case 57:
+#line 631 "fortran.y"
+{
+                     pos_end = setposcur();
+                     RemoveWordSET_0(fortranout,pos_cursave,
+                                                pos_end-pos_cursave);
+                  }
+break;
+case 59:
+#line 638 "fortran.y"
+{
+                   /* if the variable is a parameter we can suppose that is   */
+                   /*    value is the same on each grid. It is not useless to */
+                   /*    create a copy of it on each grid                     */
+                      if ( couldaddvariable == 1 )
+                      {
+                         Add_Globliste_1(yyvsp[0].l);
+                         /* if variableparamlists has been declared in a      */
+                         /*    subroutine                                     */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            Add_Dimension_Var_1(yyvsp[0].l);
+                         }
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curdimension,
+                                                pos_end-pos_curdimension);
+                      }
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
+                      c_star = 0;
+                      InitialValueGiven = 0 ;
+                      strcpy(IntentSpec,"");
+                      VariableIsParameter =  0 ;
+                      Allocatabledeclare = 0 ;
+                      SaveDeclare = 0;
+                      pointerdeclare = 0;
+                      optionaldeclare = 0 ;
+                      dimsgiven=0;
+                      c_selectorgiven=0;
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
+                   }
+break;
+case 70:
+#line 684 "fortran.y"
+{
+                      /* we should remove the data declaration                */
+                      if ( couldaddvariable == 1 && aftercontainsdeclare == 0 )
+                      {
+                        pos_end = setposcur();
+                        RemoveWordSET_0(fortranout,pos_curdata,
+                                              pos_end-pos_curdata);
+                      }
+                  }
+break;
+case 72:
+#line 696 "fortran.y"
+{
+         PublicDeclare = 0 ;
+         PrivateDeclare = 0 ;
+      }
+break;
+case 110:
+#line 747 "fortran.y"
+{
+                      /* if the variable is a parameter we can suppose that is*/
+                      /*    value is the same on each grid. It is not useless */
+                      /*    to create a copy of it on each grid               */
+                      if ( couldaddvariable == 1 )
+                      {
+                      pos_end = setposcur();
+                      RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                 pos_end-pos_cur_decl);
+                      if ( firstpass == 0 &&
+                           GlobalDeclaration == 0 &&
+                           insubroutinedeclare == 0 )
+                      {
+                         sprintf(ligne,"\n#include \"Module_Declar_%s.h\"\n"
+                                                                ,curmodulename);
+                         tofich(fortranout,ligne,1);
+                         sprintf (ligne, "Module_Declar_%s.h",curmodulename);
+                         module_declar = associate(ligne);
+                         sprintf (ligne, " ");
+                         tofich (module_declar, ligne,1);
+                         GlobalDeclaration = 1 ;
+                      }
+                         yyval.l = yyvsp[-1].l;
+                         Add_Globliste_1(yyvsp[-1].l);
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1(yyvsp[-1].l);
+                         else
+                         {
+                            if ( pointerdeclare == 1 )
+                                                Add_Pointer_Var_From_List_1(yyvsp[-1].l);
+                            Add_Parameter_Var_1(yyvsp[-1].l);
+                         }
+
+                         /* if variables has been declared in a subroutine    */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                           Add_SubroutineDeclaration_Var_1(yyvsp[-1].l);
+                         }
+                         /* If there are a SAVE declarations in module's      */
+                         /*    subroutines we should remove it from the       */
+                         /*    subroutines declaration and add it in the      */
+                         /*    global declarations                            */
+                         if ( aftercontainsdeclare == 1 &&
+                              SaveDeclare == 1 && firstpass == 1 )
+                         {
+                              if ( inmodulemeet == 0 ) Add_Save_Var_dcl_1(yyvsp[-1].l);
+                              else  Add_SubroutineDeclarationSave_Var_1(yyvsp[-1].l);
+                         }
+                      }
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
+                      c_star = 0;
+                      InitialValueGiven = 0 ;
+                      strcpy(IntentSpec,"");
+                      VariableIsParameter =  0 ;
+                      Allocatabledeclare = 0 ;
+                      SaveDeclare = 0;
+                      pointerdeclare = 0;
+                      optionaldeclare = 0 ;
+                      dimsgiven=0;
+                      c_selectorgiven=0;
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
+                   }
+break;
+case 111:
+#line 815 "fortran.y"
+{
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,yyvsp[-1].na);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,yyvsp[-1].na);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1(yyvsp[0].l);
+                         Add_FunctionType_Var_1(yyvsp[-1].na);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1(yyvsp[0].l);
+                         Add_FunctionType_Var_1(yyvsp[-1].na);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                   }
+break;
+case 112:
+#line 850 "fortran.y"
+{
+                       functiondeclarationisdone = 1;
+                   }
+break;
+case 113:
+#line 856 "fortran.y"
+{
+                      VariableIsParameter = 1;
+                      pos_curparameter = setposcur()-9;
+                   }
+break;
+case 114:
+#line 861 "fortran.y"
+{
+                      pos_curdata = setposcur()-strlen(yyvsp[0].na);
+                   }
+break;
+case 115:
+#line 865 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",yyvsp[-1].na);
+                      Add_Data_Var_1(yyvsp[-3].na,ligne);
+                      }
+                   }
+break;
+case 116:
+#line 874 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",yyvsp[-1].na);
+                      Add_Data_Var_1(yyvsp[-3].na,ligne);
+                      }
+                   }
+break;
+case 117:
+#line 883 "fortran.y"
+{
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                   }
+break;
+case 118:
+#line 894 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy(yyval.na,yyvsp[0].na);
+                      }
+                   }
+break;
+case 119:
+#line 901 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);
+                      }
+                   }
+break;
+case 124:
+#line 915 "fortran.y"
+{
+                     pos_cursave = setposcur()-4;
+                  }
+break;
+case 126:
+#line 921 "fortran.y"
+{
+                     if ( couldaddvariable == 1 ) Add_Save_Var_1(yyvsp[-1].na,yyvsp[0].d);
+                  }
+break;
+case 130:
+#line 930 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 131:
+#line 932 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s+%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 132:
+#line 934 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s-%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 133:
+#line 936 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s*%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 134:
+#line 938 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s/%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 135:
+#line 941 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,"");}
+break;
+case 136:
+#line 943 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 145:
+#line 958 "fortran.y"
+{
+                      positioninblock=0;
+                      pos_curdimension = setposcur()-9;
+                   }
+break;
+case 146:
+#line 964 "fortran.y"
+{
+         if ( couldaddvariable == 1 )
+         {
+            /*                                                                */
+            curvar=createvar(yyvsp[-2].na,yyvsp[-1].d);
+            /*                                                                */
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar(NULL,curvar);
+            /*                                                                */
+            yyval.l=settype("",curlistvar);
+            /*                                                                */
+            strcpy(vallengspec,"");
+         }
+      }
+break;
+case 147:
+#line 980 "fortran.y"
+{
+         if ( couldaddvariable == 1 )
+         {
+            /*                                                                */
+            curvar=createvar(yyvsp[-2].na,yyvsp[-1].d);
+            /*                                                                */
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar(yyvsp[-4].l,curvar);
+            /*                                                                */
+            yyval.l=curlistvar;
+            /*                                                                */
+            strcpy(vallengspec,"");
+         }
+      }
+break;
+case 154:
+#line 1006 "fortran.y"
+{
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcommon,
+                                                  pos_end-pos_curcommon);
+                   }
+break;
+case 155:
+#line 1012 "fortran.y"
+{
+                         if ( couldaddvariable == 1 )
+                         {
+                            sprintf(charusemodule,"%s",yyvsp[-1].na);
+                            Add_NameOfCommon_1(yyvsp[-1].na);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
+                         }
+                   }
+break;
+case 156:
+#line 1023 "fortran.y"
+{
+                         if ( couldaddvariable == 1 )
+                         {
+                            sprintf(charusemodule,"%s",yyvsp[-2].na);
+                            Add_NameOfCommon_1(yyvsp[-2].na);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
+                         }
+                   }
+break;
+case 157:
+#line 1035 "fortran.y"
+{
+                      positioninblock=0;
+                      pos_curcommon = setposcur()-6;
+                   }
+break;
+case 158:
+#line 1040 "fortran.y"
+{
+                      positioninblock=0;
+                      pos_curcommon = setposcur()-6-7;
+                   }
+break;
+case 159:
+#line 1046 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
+                   }
+break;
+case 160:
+#line 1051 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
+                   }
+break;
+case 161:
+#line 1055 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         positioninblock = positioninblock + 1 ;
+                         strcpy(commonvar,yyvsp[-1].na);
+                         commondim = yyvsp[0].d;
+                      }
+                   }
+break;
+case 162:
+#line 1065 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy(yyval.na,"");
+                         positioninblock=0;
+                         strcpy(commonblockname,"");
+                      }
+                   }
+break;
+case 163:
+#line 1074 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy(yyval.na,yyvsp[-1].na);
+                         positioninblock=0;
+                         strcpy(commonblockname,yyvsp[-1].na);
+                      }
+                   }
+break;
+case 166:
+#line 1087 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) yyval.l=insertvar(NULL,yyvsp[0].v);
+                   }
+break;
+case 167:
+#line 1091 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) yyval.l=insertvar(yyvsp[-2].l,yyvsp[0].v);
+                   }
+break;
+case 168:
+#line 1096 "fortran.y"
+{
+                     if ( couldaddvariable == 1 )
+                     {
+                         curvar=(variable *) malloc(sizeof(variable));
+                         /*                                                   */
+                         Init_Variable(curvar);
+                         /*                                                   */
+                         curvar->v_VariableIsParameter=1;
+                         strcpy(curvar->v_nomvar,yyvsp[-2].na);
+                         strcpy(curvar->v_subroutinename,subroutinename);
+                         strcpy(curvar->v_modulename,curmodulename);
+                         strcpy(curvar->v_initialvalue,yyvsp[0].na);
+                         strcpy(curvar->v_commoninfile,mainfile);
+                         yyval.v=curvar;
+                      }
+                   }
+break;
+case 172:
+#line 1119 "fortran.y"
+{
+                       if ( insubroutinedeclare == 1 )
+                       {
+                          Add_ImplicitNoneSubroutine_1();
+                          pos_end = setposcur();
+                          RemoveWordSET_0(fortranout,pos_end-13,
+                                                             13);
+                       }
+                    }
+break;
+case 175:
+#line 1133 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         /*                                                   */
+                         if (dimsgiven == 1)
+                         {
+                            curvar=createvar(yyvsp[-3].na,curdim);
+                         }
+                         else
+                         {
+                            curvar=createvar(yyvsp[-3].na,yyvsp[-2].d);
+                         }
+                         /*                                                   */
+                         CreateAndFillin_Curvar(DeclType,curvar);
+                         /*                                                   */
+                         curlistvar=insertvar(NULL,curvar);
+                         if (!strcasecmp(DeclType,"character"))
+                         {
+                            if (c_selectorgiven == 1)
+                            {
+                               strcpy(c_selectordim.first,"1");
+                               strcpy(c_selectordim.last,c_selectorname);
+                               change_dim_char
+                                     (insertdim(NULL,c_selectordim),curlistvar);
+                            }
+                         }
+                         yyval.l=settype(DeclType,curlistvar);
+                      }
+                      strcpy(vallengspec,"");
+                   }
+break;
+case 176:
+#line 1164 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         if (dimsgiven == 1)
+                         {
+                            curvar=createvar(yyvsp[-3].na,curdim);
+                         }
+                         else
+                         {
+                            curvar=createvar(yyvsp[-3].na,yyvsp[-2].d);
+                         }
+                         /*                                                   */
+                         CreateAndFillin_Curvar(yyvsp[-6].l->var->v_typevar,curvar);
+                         /*                                                   */
+                         strcpy(curvar->v_typevar,(yyvsp[-6].l->var->v_typevar));
+                         /*                                                   */
+                         curlistvar=insertvar(yyvsp[-6].l,curvar);
+                         if (!strcasecmp(DeclType,"character"))
+                         {
+                            if (c_selectorgiven == 1)
+                            {
+                               strcpy(c_selectordim.first,"1");
+                               strcpy(c_selectordim.last,c_selectorname);
+                               change_dim_char
+                                     (insertdim(NULL,c_selectordim),curlistvar);
+                            }
+                         }
+                         yyval.l=curlistvar;
+                      }
+                      strcpy(vallengspec,"");
+                   }
+break;
+case 177:
+#line 1196 "fortran.y"
+{dimsgiven=0;}
+break;
+case 178:
+#line 1199 "fortran.y"
+{strcpy(DeclType,yyvsp[-1].na);}
+break;
+case 179:
+#line 1201 "fortran.y"
+{
+                      strcpy(DeclType,"CHARACTER");
+                   }
+break;
+case 180:
+#line 1205 "fortran.y"
+{
+                      strcpy(DeclType,yyvsp[-2].na);
+                      strcpy(nameinttypename,yyvsp[0].na);
+                   }
+break;
+case 181:
+#line 1210 "fortran.y"
+{
+                      strcpy(DeclType,"TYPE");
+                   }
+break;
+case 182:
+#line 1215 "fortran.y"
+{
+                      if ( couldaddvariable == 1 ) VarTypepar = 1 ;
+                      couldaddvariable = 0 ;
+                      pos_cur_decl = setposcur()-5;
+                   }
+break;
+case 184:
+#line 1223 "fortran.y"
+{c_selectorgiven=1;strcpy(c_selectorname,yyvsp[0].na);}
+break;
+case 185:
+#line 1224 "fortran.y"
+{c_star = 1;}
+break;
+case 190:
+#line 1232 "fortran.y"
+{
+                      pos_cur_decl = setposcur()-9;
+                   }
+break;
+case 191:
+#line 1236 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 192:
+#line 1239 "fortran.y"
+{
+                      strcpy(yyval.na,"INTEGER");
+                      pos_cur_decl = setposcur()-7;
+                   }
+break;
+case 193:
+#line 1243 "fortran.y"
+{
+                      strcpy(yyval.na,"REAL");
+                      pos_cur_decl = setposcur()-4;
+                   }
+break;
+case 194:
+#line 1248 "fortran.y"
+{strcpy(yyval.na,"COMPLEX");}
+break;
+case 195:
+#line 1250 "fortran.y"
+{
+                      pos_cur_decl = setposcur()-16;
+                      strcpy(yyval.na,"REAL");
+                      strcpy(nameinttypename,"8");
+                   }
+break;
+case 196:
+#line 1256 "fortran.y"
+{strcpy(yyval.na,"DOUBLE COMPLEX");}
+break;
+case 197:
+#line 1258 "fortran.y"
+{
+                      strcpy(yyval.na,"LOGICAL");
+                      pos_cur_decl = setposcur()-7;
+                   }
+break;
+case 199:
+#line 1264 "fortran.y"
+{strcpy(vallengspec,yyvsp[0].na);}
+break;
+case 200:
+#line 1266 "fortran.y"
+{sprintf(yyval.na,"*%s",yyvsp[0].na);}
+break;
+case 201:
+#line 1267 "fortran.y"
+{strcpy(yyval.na,"*(*)");}
+break;
+case 208:
+#line 1278 "fortran.y"
+{
+                      if ( strstr(yyvsp[0].na,"0.d0") )
+                      {
+                         strcpy(nameinttypename,"8");
+                         sprintf(NamePrecision,"");
+                      }
+                      else sprintf(NamePrecision,"%s = %s",yyvsp[-2].na,yyvsp[0].na);
+                   }
+break;
+case 209:
+#line 1287 "fortran.y"
+{
+                      strcpy(NamePrecision,yyvsp[0].na);
+                   }
+break;
+case 210:
+#line 1291 "fortran.y"
+{
+                      strcpy(NamePrecision,yyvsp[0].na);
+                   }
+break;
+case 211:
+#line 1295 "fortran.y"
+{strcpy(CharacterSize,yyvsp[0].na);
+                    strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 212:
+#line 1297 "fortran.y"
+{strcpy(CharacterSize,"*");
+                    strcpy(yyval.na,"*");}
+break;
+case 220:
+#line 1311 "fortran.y"
+{
+                      VariableIsParameter = 1;
+                   }
+break;
+case 222:
+#line 1316 "fortran.y"
+{Allocatabledeclare = 1;}
+break;
+case 223:
+#line 1318 "fortran.y"
+{
+                      dimsgiven=1;
+                      curdim=yyvsp[0].d;
+                   }
+break;
+case 224:
+#line 1323 "fortran.y"
+{ExternalDeclare = 1;}
+break;
+case 225:
+#line 1325 "fortran.y"
+{strcpy(IntentSpec,yyvsp[0].na);}
+break;
+case 227:
+#line 1327 "fortran.y"
+{optionaldeclare = 1 ;}
+break;
+case 228:
+#line 1328 "fortran.y"
+{pointerdeclare = 1 ;}
+break;
+case 229:
+#line 1329 "fortran.y"
+{
+/*                       if ( inmodulemeet == 1 )
+                       {*/
+                          SaveDeclare = 1 ;
+                     /*  }*/
+                    }
+break;
+case 231:
+#line 1337 "fortran.y"
+{sprintf(yyval.na,"in");}
+break;
+case 232:
+#line 1338 "fortran.y"
+{sprintf(yyval.na,"out");}
+break;
+case 233:
+#line 1339 "fortran.y"
+{sprintf(yyval.na,"inout");}
+break;
+case 234:
+#line 1342 "fortran.y"
+{PublicDeclare = 1;}
+break;
+case 235:
+#line 1344 "fortran.y"
+{PrivateDeclare = 1;}
+break;
+case 236:
+#line 1346 "fortran.y"
+{if ( created_dimensionlist == 1 )
+                       {
+                           yyval.d=(listdim *)NULL;
+                       }
+                   }
+break;
+case 237:
+#line 1352 "fortran.y"
+{if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) yyval.d=yyvsp[-1].d;}
+break;
+case 238:
+#line 1355 "fortran.y"
+{if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) yyval.d=insertdim(NULL,yyvsp[0].dim1);}
+break;
+case 239:
+#line 1358 "fortran.y"
+{if ( couldaddvariable == 1 )
+                         if ( created_dimensionlist == 1 ) yyval.d=insertdim(yyvsp[-2].d,yyvsp[0].dim1);}
+break;
+case 240:
+#line 1361 "fortran.y"
+{strcpy(yyval.dim1.first,"1");strcpy(yyval.dim1.last,yyvsp[0].na);}
+break;
+case 241:
+#line 1362 "fortran.y"
+{strcpy(yyval.dim1.first,"");strcpy(yyval.dim1.last,"");}
+break;
+case 242:
+#line 1363 "fortran.y"
+{strcpy(yyval.dim1.first,yyvsp[-1].na);strcpy(yyval.dim1.last,"");}
+break;
+case 243:
+#line 1364 "fortran.y"
+{strcpy(yyval.dim1.first,"");strcpy(yyval.dim1.last,yyvsp[0].na);}
+break;
+case 244:
+#line 1366 "fortran.y"
+{strcpy(yyval.dim1.first,yyvsp[-2].na);strcpy(yyval.dim1.last,yyvsp[0].na);}
+break;
+case 245:
+#line 1368 "fortran.y"
+{strcpy(yyval.na,"*");}
+break;
+case 246:
+#line 1369 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 247:
+#line 1371 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 248:
+#line 1373 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"(%s)",yyvsp[-1].na);}
+break;
+case 249:
+#line 1375 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 250:
+#line 1377 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 251:
+#line 1381 "fortran.y"
+{sprintf(yyval.na,"SUM(%s)",yyvsp[-1].na);}
+break;
+case 252:
+#line 1383 "fortran.y"
+{sprintf(yyval.na,"MAX(%s)",yyvsp[-1].na);}
+break;
+case 253:
+#line 1385 "fortran.y"
+{sprintf(yyval.na,"TANH(%s)",yyvsp[-1].na);}
+break;
+case 254:
+#line 1387 "fortran.y"
+{sprintf(yyval.na,"MAXVAL(%s)",yyvsp[-1].na);}
+break;
+case 255:
+#line 1389 "fortran.y"
+{sprintf(yyval.na,"MIN(%s)",yyvsp[-1].na);}
+break;
+case 256:
+#line 1391 "fortran.y"
+{sprintf(yyval.na,"MINVAL(%s)",yyvsp[-1].na);}
+break;
+case 257:
+#line 1393 "fortran.y"
+{sprintf(yyval.na,"TRIM(%s)",yyvsp[-1].na);}
+break;
+case 258:
+#line 1395 "fortran.y"
+{sprintf(yyval.na,"SQRT(%s)",yyvsp[-1].na);}
+break;
+case 259:
+#line 1397 "fortran.y"
+{sprintf(yyval.na,"REAL(%s)",yyvsp[-1].na);}
+break;
+case 260:
+#line 1399 "fortran.y"
+{sprintf(yyval.na,"INT(%s)",yyvsp[-1].na);}
+break;
+case 261:
+#line 1401 "fortran.y"
+{sprintf(yyval.na,"NINT(%s)",yyvsp[-1].na);}
+break;
+case 262:
+#line 1403 "fortran.y"
+{sprintf(yyval.na,"FLOAT(%s)",yyvsp[-1].na);}
+break;
+case 263:
+#line 1405 "fortran.y"
+{sprintf(yyval.na,"EXP(%s)",yyvsp[-1].na);}
+break;
+case 264:
+#line 1407 "fortran.y"
+{sprintf(yyval.na,"COS(%s)",yyvsp[-1].na);}
+break;
+case 265:
+#line 1409 "fortran.y"
+{sprintf(yyval.na,"COSH(%s)",yyvsp[-1].na);}
+break;
+case 266:
+#line 1411 "fortran.y"
+{sprintf(yyval.na,"ACOS(%s)",yyvsp[-1].na);}
+break;
+case 267:
+#line 1413 "fortran.y"
+{sprintf(yyval.na,"SIN(%s)",yyvsp[-1].na);}
+break;
+case 268:
+#line 1415 "fortran.y"
+{sprintf(yyval.na,"SINH(%s)",yyvsp[-1].na);}
+break;
+case 269:
+#line 1417 "fortran.y"
+{sprintf(yyval.na,"ASIN(%s)",yyvsp[-1].na);}
+break;
+case 270:
+#line 1419 "fortran.y"
+{sprintf(yyval.na,"LOG(%s)",yyvsp[-1].na);}
+break;
+case 271:
+#line 1421 "fortran.y"
+{sprintf(yyval.na,"TAN(%s)",yyvsp[-1].na);}
+break;
+case 272:
+#line 1423 "fortran.y"
+{sprintf(yyval.na,"ATAN(%s)",yyvsp[-1].na);}
+break;
+case 273:
+#line 1425 "fortran.y"
+{sprintf(yyval.na,"ABS(%s)",yyvsp[-1].na);}
+break;
+case 274:
+#line 1427 "fortran.y"
+{sprintf(yyval.na,"MOD(%s)",yyvsp[-1].na);}
+break;
+case 275:
+#line 1429 "fortran.y"
+{sprintf(yyval.na,"SIGN(%s)",yyvsp[-1].na);}
+break;
+case 276:
+#line 1431 "fortran.y"
+{sprintf(yyval.na,"MINLOC(%s)",yyvsp[-1].na);}
+break;
+case 277:
+#line 1433 "fortran.y"
+{sprintf(yyval.na,"MAXLOC(%s)",yyvsp[-1].na);}
+break;
+case 278:
+#line 1435 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 279:
+#line 1437 "fortran.y"
+{if ( couldaddvariable == 1 )
+                   { strcpy(yyval.na,yyvsp[-2].na);strcat(yyval.na,",");strcat(yyval.na,yyvsp[0].na);}}
+break;
+case 280:
+#line 1440 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 281:
+#line 1442 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 282:
+#line 1444 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 283:
+#line 1446 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 284:
+#line 1448 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 285:
+#line 1450 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 286:
+#line 1452 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,"+");}
+break;
+case 287:
+#line 1453 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,"-");}
+break;
+case 288:
+#line 1456 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"+%s",yyvsp[0].na);}
+break;
+case 289:
+#line 1458 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"-%s",yyvsp[0].na);}
+break;
+case 290:
+#line 1460 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"*%s",yyvsp[0].na);}
+break;
+case 291:
+#line 1462 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 292:
+#line 1464 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 293:
+#line 1466 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 294:
+#line 1468 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," > %s",yyvsp[0].na);}
+break;
+case 295:
+#line 1470 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 296:
+#line 1472 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," < %s",yyvsp[0].na);}
+break;
+case 297:
+#line 1474 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 298:
+#line 1476 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," >= %s",yyvsp[0].na);}
+break;
+case 299:
+#line 1478 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 300:
+#line 1480 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," <= %s",yyvsp[0].na);}
+break;
+case 301:
+#line 1482 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 302:
+#line 1484 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 303:
+#line 1486 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 304:
+#line 1488 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 305:
+#line 1490 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s",yyvsp[0].na);}
+break;
+case 306:
+#line 1492 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s",yyvsp[0].na);}
+break;
+case 307:
+#line 1494 "fortran.y"
+{strcpy(yyval.na,"");}
+break;
+case 308:
+#line 1496 "fortran.y"
+{sprintf(yyval.na,"/%s",yyvsp[0].na);}
+break;
+case 309:
+#line 1498 "fortran.y"
+{sprintf(yyval.na,"/= %s",yyvsp[0].na);}
+break;
+case 310:
+#line 1500 "fortran.y"
+{sprintf(yyval.na,"//%s",yyvsp[0].na);}
+break;
+case 311:
+#line 1503 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"==%s",yyvsp[0].na);}
+break;
+case 312:
+#line 1505 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"= %s",yyvsp[0].na);}
+break;
+case 313:
+#line 1508 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 314:
+#line 1510 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 315:
+#line 1512 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 316:
+#line 1514 "fortran.y"
+{
+                      agrif_parentcall =0;
+                      if (!strcasecmp(identcopy,"Agrif_Parent") )
+                                                            agrif_parentcall =1;
+                      if ( Agrif_in_Tok_NAME(identcopy) == 1 )
+                      {
+                         inagrifcallargument = 1;
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                      }
+                   }
+break;
+case 317:
+#line 1527 "fortran.y"
+{
+                     strcpy(yyval.na,yyvsp[0].na);
+                     if ( incalldeclare == 0 ) inagrifcallargument = 0;
+                   }
+break;
+case 318:
+#line 1532 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," %s %s ",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 319:
+#line 1534 "fortran.y"
+{if ( couldaddvariable == 1 )
+                                                sprintf(yyval.na," %s ( %s )",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 320:
+#line 1537 "fortran.y"
+{if ( couldaddvariable == 1 )
+                                         sprintf(yyval.na," %s ( %s ) %s ",yyvsp[-4].na,yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 321:
+#line 1541 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf(yyval.na," %s ( %s )",yyvsp[-3].na,yyvsp[-1].na);
+                         ModifyTheAgrifFunction_0(yyvsp[-1].na);
+                         agrif_parentcall =0;
+                      }
+                   }
+break;
+case 322:
+#line 1551 "fortran.y"
+{
+                      sprintf(yyval.na," %s %% %s ",yyvsp[-2].na,yyvsp[0].na);
+                      if ( incalldeclare == 0 ) inagrifcallargument = 0;
+                   }
+break;
+case 323:
+#line 1557 "fortran.y"
+{sprintf(yyval.na,"(/%s/)",yyvsp[-1].na);}
+break;
+case 324:
+#line 1559 "fortran.y"
+{strcpy(yyval.na," ");}
+break;
+case 325:
+#line 1561 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 326:
+#line 1563 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 327:
+#line 1565 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 328:
+#line 1567 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 329:
+#line 1568 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 330:
+#line 1571 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s:%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 331:
+#line 1573 "fortran.y"
+{if ( couldaddvariable == 1 )
+                                               sprintf(yyval.na,"%s:%s:%s",yyvsp[-4].na,yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 332:
+#line 1576 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,":%s:%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 333:
+#line 1577 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,": : %s",yyvsp[0].na);}
+break;
+case 334:
+#line 1578 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,":%s",yyvsp[0].na);}
+break;
+case 335:
+#line 1579 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s:",yyvsp[-1].na);}
+break;
+case 336:
+#line 1580 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,":");}
+break;
+case 337:
+#line 1582 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                       if ( Vartonumber(yyvsp[0].na) == 1 )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if (!strcasecmp(yyvsp[0].na,"Agrif_Parent") )
+                                                            agrif_parentcall =1;
+                       if ( VariableIsNotFunction(yyvsp[0].na) == 0 )
+                       {
+                          if ( inagrifcallargument == 1 )
+                          {
+                             if ( !strcasecmp(yyvsp[0].na,identcopy) )
+                             {
+                                strcpy(sameagrifname,identcopy);
+                                sameagrifargument = 1;
+                             }
+                          }
+                          strcpy(identcopy,yyvsp[0].na);
+                          pointedvar=0;
+                          if ( VarIsNonGridDepend(yyvsp[0].na) == 0 &&
+                               Variableshouldberemove(yyvsp[0].na) == 0 )
+                          {
+                             if ( inagrifcallargument == 1 ||
+                                  varisallocatable_0(yyvsp[0].na) == 1 ||
+                                  varispointer_0(yyvsp[0].na) == 1 )
+                             {
+                                ModifyTheVariableName_0(yyvsp[0].na);
+                             }
+                             if ( inagrifcallargument != 1 ||
+                                  sameagrifargument ==1 )
+                                  Add_UsedInSubroutine_Var_1(yyvsp[0].na);
+                          }
+                          NotifyAgrifFunction_0(yyvsp[0].na);
+                       }
+                       }
+                    }
+break;
+case 338:
+#line 1623 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,".TRUE.");}
+break;
+case 339:
+#line 1624 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,".FALSE.");}
+break;
+case 340:
+#line 1625 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 341:
+#line 1626 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 342:
+#line 1627 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 343:
+#line 1628 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 344:
+#line 1630 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s%s",yyvsp[-1].na,yyvsp[0].na);}
+break;
+case 346:
+#line 1634 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 348:
+#line 1637 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 349:
+#line 1639 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 350:
+#line 1641 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na," ");}
+break;
+case 351:
+#line 1642 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 352:
+#line 1645 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"(%s:%s)",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 353:
+#line 1647 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na," ");}
+break;
+case 354:
+#line 1648 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 355:
+#line 1650 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na," ");}
+break;
+case 356:
+#line 1651 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 357:
+#line 1653 "fortran.y"
+{InitialValueGiven = 0;}
+break;
+case 358:
+#line 1655 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                          strcpy(InitValue,yyvsp[0].na);
+                          InitialValueGiven = 1;
+                       }
+                    }
+break;
+case 359:
+#line 1663 "fortran.y"
+{pos_curinit = setposcur();}
+break;
+case 360:
+#line 1666 "fortran.y"
+{sprintf(yyval.na,"(%s,%s)",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 361:
+#line 1669 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                      /* if variables has been declared in a subroutine       */
+                      if (insubroutinedeclare == 1)
+                      {
+                         copyuse_0(yyvsp[0].na);
+                      }
+                      sprintf(charusemodule,"%s",yyvsp[0].na);
+                      Add_NameOfModuleUsed_1(yyvsp[0].na);
+
+                      if ( inmoduledeclare == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curuse,
+                                               pos_end-pos_curuse);
+                      }
+                      }
+                    }
+break;
+case 362:
+#line 1689 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                      if (insubroutinedeclare == 1)
+                      {
+                         Add_CouplePointed_Var_1(yyvsp[-2].na,yyvsp[0].lc);
+                      }
+                      if ( firstpass == 1 )
+                      {
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            coupletmp = yyvsp[0].lc;
+                            strcpy(ligne,"");
+                            while ( coupletmp )
+                            {
+                               strcat(ligne,coupletmp->c_namevar);
+                               strcat(ligne," => ");
+                               strcat(ligne,coupletmp->c_namepointedvar);
+                               coupletmp = coupletmp->suiv;
+                               if ( coupletmp ) strcat(ligne,",");
+                            }
+                            sprintf(charusemodule,"%s",yyvsp[-2].na);
+                         }
+                         Add_NameOfModuleUsed_1(yyvsp[-2].na);
+                      }
+                      if ( inmoduledeclare == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curuse,
+                                               pos_end-pos_curuse);
+                      }
+                      }
+                    }
+break;
+case 363:
+#line 1723 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                      /* if variables has been declared in a subroutine       */
+                      if (insubroutinedeclare == 1)
+                      {
+                         copyuseonly_0(yyvsp[-4].na);
+                      }
+                      sprintf(charusemodule,"%s",yyvsp[-4].na);
+                      Add_NameOfModuleUsed_1(yyvsp[-4].na);
+
+                       if ( inmoduledeclare == 0 )
+                       {
+                          pos_end = setposcur();
+                          RemoveWordSET_0(fortranout,pos_curuse,
+                                                pos_end-pos_curuse);
+                       }
+                       }
+                    }
+break;
+case 364:
+#line 1743 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                       /* if variables has been declared in a subroutine      */
+                       if (insubroutinedeclare == 1)
+                       {
+                          Add_CouplePointed_Var_1(yyvsp[-4].na,yyvsp[0].lc);
+                       }
+                       if ( firstpass == 1 )
+                       {
+                         if ( insubroutinedeclare == 1 )
+                         {
+                             coupletmp = yyvsp[0].lc;
+                             strcpy(ligne,"");
+                             while ( coupletmp )
+                             {
+                                strcat(ligne,coupletmp->c_namevar);
+                               if ( strcasecmp(coupletmp->c_namepointedvar,"") )
+                                                           strcat(ligne," => ");
+                                strcat(ligne,coupletmp->c_namepointedvar);
+                                coupletmp = coupletmp->suiv;
+                                if ( coupletmp ) strcat(ligne,",");
+                             }
+                             sprintf(charusemodule,"%s",yyvsp[-4].na);
+                          }
+                          Add_NameOfModuleUsed_1(yyvsp[-4].na);
+                       }
+                       if ( firstpass == 0 )
+                       {
+                          if ( inmoduledeclare == 0 )
+                          {
+                             pos_end = setposcur();
+                             RemoveWordSET_0(fortranout,pos_curuse,
+                                                   pos_end-pos_curuse);
+                          }
+                          else
+                          {
+                             /* if we are in the module declare and if the    */
+                             /* onlylist is a list of global variable         */
+                             variableisglobalinmodule(yyvsp[0].lc, yyvsp[-4].na, fortranout);
+                          }
+                       }
+                       }
+                    }
+break;
+case 365:
+#line 1789 "fortran.y"
+{
+                      pos_curuse = setposcur()-strlen(yyvsp[0].na);
+                   }
+break;
+case 366:
+#line 1794 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 367:
+#line 1797 "fortran.y"
+{
+                       if ( couldaddvariable == 1 ) yyval.lc = yyvsp[0].lc;
+                    }
+break;
+case 368:
+#line 1801 "fortran.y"
+{
+                        if ( couldaddvariable == 1 )
+                        {
+                        /* insert the variable in the list $1                 */
+                        yyvsp[0].lc->suiv = yyvsp[-2].lc;
+                        yyval.lc = yyvsp[0].lc;
+                        }
+                    }
+break;
+case 369:
+#line 1811 "fortran.y"
+{
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,yyvsp[-2].na);
+                       strcpy(coupletmp->c_namepointedvar,yyvsp[0].na);
+                       coupletmp->suiv = NULL;
+                       yyval.lc = coupletmp;
+                     }
+break;
+case 370:
+#line 1820 "fortran.y"
+{
+                       if ( couldaddvariable == 1 ) yyval.lc = yyvsp[0].lc;
+                    }
+break;
+case 371:
+#line 1824 "fortran.y"
+{
+                        if ( couldaddvariable == 1 )
+                        {
+                        /* insert the variable in the list $1                 */
+                        yyvsp[0].lc->suiv = yyvsp[-2].lc;
+                        yyval.lc = yyvsp[0].lc;
+                        }
+                    }
+break;
+case 372:
+#line 1834 "fortran.y"
+{
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,yyvsp[-2].na);
+                       strcpy(coupletmp->c_namepointedvar,yyvsp[0].na);
+                       coupletmp->suiv = NULL;
+                       yyval.lc = coupletmp;
+                       pointedvar=1;
+                       Add_UsedInSubroutine_Var_1(yyvsp[-2].na);
+                    }
+break;
+case 373:
+#line 1843 "fortran.y"
+{
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,yyvsp[0].na);
+                       strcpy(coupletmp->c_namepointedvar,"");
+                       coupletmp->suiv = NULL;
+                       yyval.lc = coupletmp;
+                     }
+break;
+case 375:
+#line 1853 "fortran.y"
+{
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+break;
+case 376:
+#line 1858 "fortran.y"
+{
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                         curmodulename);
+                     }
+break;
+case 378:
+#line 1864 "fortran.y"
+{
+                       GlobalDeclaration = 0 ;
+                       if ( firstpass == 0 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                          if ( module_declar && insubroutinedeclare == 0 )
+                          {
+                              fclose(module_declar);
+                          }
+                       }
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                       if ( inmodulemeet == 1 )
+                       {
+                         /* we are in a module                                */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            /* it is like an end subroutine <name>            */
+                            insubroutinedeclare = 0 ;
+                            /*                                                */
+                            pos_cur = setposcur();
+                            closeandcallsubloopandincludeit_0(1,yyvsp[0].na);
+                            functiondeclarationisdone = 0;
+                         }
+                         else
+                         {
+                            /* it is like an end module <name>                */
+                            inmoduledeclare = 0 ;
+                            inmodulemeet = 0 ;
+                         }
+                       }
+                       else
+                       {
+                          insubroutinedeclare = 0;
+                          /*                                                  */
+                          pos_cur = setposcur();
+                          closeandcallsubloopandincludeit_0(2,yyvsp[0].na);
+                            functiondeclarationisdone = 0;
+                          if ( firstpass == 0 )
+                          {
+                             if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                             else fprintf(paramout,"C\n");
+                             fclose(paramout);
+                           }
+                        }
+                      }
+                      strcpy(subroutinename,"");
+                    }
+break;
+case 379:
+#line 1914 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(3,yyvsp[-1].na);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+break;
+case 380:
+#line 1932 "fortran.y"
+{
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(1,yyvsp[-1].na);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+break;
+case 381:
+#line 1951 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(0,yyvsp[-1].na);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+break;
+case 382:
+#line 1969 "fortran.y"
+{
+                       if ( couldaddvariable == 1 )
+                       {
+                       /* if we never meet the contains keyword               */
+                      Remove_Word_end_module_0();
+                       if ( inmoduledeclare == 1 )
+                       {
+                          if ( aftercontainsdeclare == 0 )
+                          {
+                             Write_GlobalParameter_Declaration_0();
+                             Write_NotGridDepend_Declaration_0();
+                             Write_Alloc_Subroutine_For_End_0();
+                          }
+                       }
+                       inmoduledeclare = 0 ;
+                       inmodulemeet = 0 ;
+
+                      Write_Word_end_module_0();
+                      strcpy(curmodulename,"");
+                      aftercontainsdeclare = 1;
+                      if ( firstpass == 0 )
+                      {
+                         if ( module_declar && insubroutinedeclare == 0)
+                         {
+                           fclose(module_declar);
+                         }
+                      }
+                      GlobalDeclaration = 0 ;
+                      }
+                  }
+break;
+case 396:
+#line 2013 "fortran.y"
+{
+                      if (inmoduledeclare == 1 )
+                      {
+                         Remove_Word_Contains_0();
+                         Write_GlobalParameter_Declaration_0();
+                         Write_NotGridDepend_Declaration_0();
+                         Write_Alloc_Subroutine_0();
+                         inmoduledeclare = 0 ;
+                         aftercontainsdeclare = 1;
+                      }
+                      else
+                      {
+                       if ( couldaddvariable == 1 )
+                       {
+                          if ( firstpass == 1 ) List_ContainsSubroutine =
+                                                Addtolistnom(subroutinename,
+                                                     List_ContainsSubroutine,0);
+                          insubroutinedeclare = 0;
+                          /*                                                  */
+                          closeandcallsubloop_contains_0();
+                            functiondeclarationisdone = 0;
+                         if ( firstpass == 0 )
+                         {
+                            if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                            else fprintf(paramout,"C\n");
+                            fclose(paramout);
+                         }
+                         }
+                         strcpy(subroutinename,"");
+                      }
+                   }
+break;
+case 397:
+#line 2046 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy(yyval.na,yyvsp[0].na);
+                       pos_endsubroutine = setposcur()-strlen(yyvsp[0].na);
+                       functiondeclarationisdone = 0;
+                       }
+                    }
+break;
+case 398:
+#line 2056 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy(yyval.na,yyvsp[0].na);
+                       pos_endsubroutine = setposcur()-strlen(yyvsp[0].na);
+                       }
+                    }
+break;
+case 399:
+#line 2065 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy(yyval.na,yyvsp[0].na);
+                       pos_endsubroutine = setposcur()-strlen(yyvsp[0].na);
+                       }
+                    }
+break;
+case 400:
+#line 2074 "fortran.y"
+{
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy(yyval.na,yyvsp[0].na);
+                       pos_endsubroutine = setposcur()-strlen(yyvsp[0].na);
+                       }
+                    }
+break;
+case 412:
+#line 2096 "fortran.y"
+{strcpy(yyval.na,"");}
+break;
+case 413:
+#line 2097 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 425:
+#line 2117 "fortran.y"
+{
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+break;
+case 426:
+#line 2122 "fortran.y"
+{
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+break;
+case 432:
+#line 2132 "fortran.y"
+{if ( couldaddvariable == 1 ) created_dimensionlist = 0;}
+break;
+case 433:
+#line 2134 "fortran.y"
+{
+                  created_dimensionlist = 1;
+                  if  ( agrif_parentcall == 1 )
+                  {
+                      ModifyTheAgrifFunction_0(yyvsp[-1].d->dim.last);
+                      agrif_parentcall =0;
+                      fprintf(fortranout," = ");
+                  }
+              }
+break;
+case 434:
+#line 2144 "fortran.y"
+{created_dimensionlist = 1;}
+break;
+case 439:
+#line 2152 "fortran.y"
+{
+                      inagrifcallargument = 0 ;
+                      incalldeclare=0;
+                      if ( oldfortranout &&
+                           !strcasecmp(meetagrifinitgrids,subroutinename) &&
+                           firstpass == 0 &&
+                           callmpiinit == 1)
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcall,
+                                               pos_end-pos_curcall);
+                         fprintf(oldfortranout,"      Call MPI_Init (%s) \n"
+                                                                   ,mpiinitvar);
+                      }
+                      if ( oldfortranout           &&
+                           callagrifinitgrids == 1 &&
+                           firstpass == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcall,
+                                               pos_end-pos_curcall);
+
+                         strcpy(subofagrifinitgrids,subroutinename);
+                      }
+                      Instanciation_0(sameagrifname);
+                   }
+break;
+case 444:
+#line 2186 "fortran.y"
+{
+                       if (!strcasecmp(yyvsp[0].na,"MPI_Init") )
+                       {
+                          callmpiinit = 1;
+                       }
+                       else
+                       {
+                          callmpiinit = 0;
+                       }
+                       if (!strcasecmp(yyvsp[0].na,"Agrif_Init_Grids") )
+                       {
+                          callagrifinitgrids = 1;
+                          strcpy(meetagrifinitgrids,subroutinename);
+                       }
+                       else callagrifinitgrids = 0;
+                       if ( !strcasecmp(yyvsp[0].na,"Agrif_Open_File") )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if ( Vartonumber(yyvsp[0].na) == 1 )
+                       {
+                          incalldeclare=1;
+                          inagrifcallargument = 1 ;
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                    }
+break;
+case 445:
+#line 2216 "fortran.y"
+{pos_curcall=setposcur()-4;}
+break;
+case 448:
+#line 2221 "fortran.y"
+{
+                  if ( callmpiinit == 1 )
+                  {
+                     strcpy(mpiinitvar,yyvsp[0].na);
+                     if ( firstpass == 1 )
+                     {
+                        Add_UsedInSubroutine_Var_1 (mpiinitvar);
+/*                        curvar=createvar($1,NULL);
+                        curlistvar=insertvar(NULL,curvar);
+                        List_Subr outineArgument_Var = AddListvarToListvar
+                         (curlistvar,List_SubroutineAr gument_Var,1);*/
+                     }
+                  }
+               }
+break;
+case 525:
+#line 2338 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 526:
+#line 2339 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 527:
+#line 2342 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 528:
+#line 2344 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 529:
+#line 2346 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 530:
+#line 2348 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 531:
+#line 2350 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 532:
+#line 2352 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"%s,%s",yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 533:
+#line 2353 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 534:
+#line 2354 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 535:
+#line 2357 "fortran.y"
+{if ( couldaddvariable == 1 ) strcpy(yyval.na,yyvsp[0].na);}
+break;
+case 536:
+#line 2359 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na," (%s)",yyvsp[-1].na);}
+break;
+case 537:
+#line 2361 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"(%s,%s)",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 538:
+#line 2363 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"(%s,%s)",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 539:
+#line 2365 "fortran.y"
+{if ( couldaddvariable == 1 ) sprintf(yyval.na,"(%s,%s)",yyvsp[-3].na,yyvsp[-1].na);}
+break;
+case 540:
+#line 2369 "fortran.y"
+{if ( couldaddvariable == 1 )
+                                              sprintf(yyval.na,"%s=%s,%s)",yyvsp[-4].na,yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 541:
+#line 2372 "fortran.y"
+{if ( couldaddvariable == 1 )
+                                        sprintf(yyval.na,"%s=%s,%s,%s)",yyvsp[-6].na,yyvsp[-4].na,yyvsp[-2].na,yyvsp[0].na);}
+break;
+case 550:
+#line 2388 "fortran.y"
+{Add_Allocate_Var_1(yyvsp[0].na,curmodulename);}
+break;
+case 553:
+#line 2393 "fortran.y"
+{Add_Allocate_Var_1(yyvsp[-3].na,curmodulename);}
+break;
+case 567:
+#line 2416 "fortran.y"
+{strcpy(yyval.na,yyvsp[0].na);}
+break;
+#line 9288 "y.tab.c"
+    }
+    yyssp -= yym;
+    yystate = *yyssp;
+    yyvsp -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yyssp = YYFINAL;
+        *++yyvsp = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yyssp, yystate);
+#endif
+    if (yyssp >= yyss + yystacksize - 1)
+    {
+        goto yyoverflow;
+    }
+    *++yyssp = yystate;
+    *++yyvsp = yyval;
+    goto yyloop;
+yyoverflow:
+    yyerror("yacc stack overflow");
+yyabort:
+    return (1);
+yyaccept:
+    return (0);
+}
+#define yy_create_buffer fortran_create_buffer
+#define yy_delete_buffer fortran_delete_buffer
+#define yy_scan_buffer fortran_scan_buffer
+#define yy_scan_string fortran_scan_string
+#define yy_scan_bytes fortran_scan_bytes
+#define yy_flex_debug fortran_flex_debug
+#define yy_init_buffer fortran_init_buffer
+#define yy_flush_buffer fortran_flush_buffer
+#define yy_load_buffer_state fortran_load_buffer_state
+#define yy_switch_to_buffer fortran_switch_to_buffer
+#define yyin fortranin
+#define yyleng fortranleng
+#define yylex fortranlex
+#define yyout fortranout
+#define yyrestart fortranrestart
+#define yytext fortrantext
+#define yywrap fortranwrap
+
+#line 20 "fortran.yy.c"
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ * $Header$
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+#include <unistd.h>
+
+
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else	/* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif	/* __STDC__ */
+#endif	/* ! __cplusplus */
+
+#ifdef __TURBOC__
+ #pragma warn -rch
+ #pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index.  If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition.  This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state.  The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* The funky do-while in the following #define is used to turn the definition
+ * int a single C statement (which needs a semi-colon terminator).  This
+ * avoids problems with code like:
+ *
+ * 	if ( condition_holds )
+ *		yyless( 5 );
+ *	else
+ *		do_something_else();
+ *
+ * Prior to using the do-while the compiler would get upset at the
+ * "else" because it interpreted the "if" statement as being all
+ * done when it reached the ';' after the yyless() call.
+ */
+
+/* Return all but the first 'n' matched characters back to the input stream. */
+
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		*yy_cp = yy_hold_char; \
+		YY_RESTORE_YY_MORE_OFFSET \
+		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+		} \
+	while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+
+struct yy_buffer_state
+	{
+	FILE *yy_input_file;
+
+	char *yy_ch_buf;		/* input buffer */
+	char *yy_buf_pos;		/* current position in input buffer */
+
+	/* Size of input buffer in bytes, not including room for EOB
+	 * characters.
+	 */
+	yy_size_t yy_buf_size;
+
+	/* Number of characters read into yy_ch_buf, not including EOB
+	 * characters.
+	 */
+	int yy_n_chars;
+
+	/* Whether we "own" the buffer - i.e., we know we created it,
+	 * and can realloc() it to grow it, and should free() it to
+	 * delete it.
+	 */
+	int yy_is_our_buffer;
+
+	/* Whether this is an "interactive" input source; if so, and
+	 * if we're using stdio for input, then we want to use getc()
+	 * instead of fread(), to make sure we stop fetching input after
+	 * each newline.
+	 */
+	int yy_is_interactive;
+
+	/* Whether we're considered to be at the beginning of a line.
+	 * If so, '^' rules will be active on the next match, otherwise
+	 * not.
+	 */
+	int yy_at_bol;
+
+	/* Whether to try to fill the input buffer when we reach the
+	 * end of it.
+	 */
+	int yy_fill_buffer;
+
+	int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+	/* When an EOF's been seen but there's still some text to process
+	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+	 * shouldn't try reading from the input source any more.  We might
+	 * still have a bunch of tokens to match, though, because of
+	 * possible backing-up.
+	 *
+	 * When we actually see the EOF, we change the status to "new"
+	 * (via yyrestart()), so that the user can continue scanning by
+	 * just pointing yyin at a new input file.
+	 */
+#define YY_BUFFER_EOF_PENDING 2
+	};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars;		/* number of characters read into yy_ch_buf */
+
+
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1;		/* whether we need to initialize */
+static int yy_start = 0;	/* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin.  A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO(( FILE *input_file ));
+
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+void yy_load_buffer_state YY_PROTO(( void ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_is_interactive = is_interactive; \
+	}
+
+#define yy_set_bol(at_bol) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_at_bol = at_bol; \
+	}
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( void ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+	yytext_ptr = yy_bp; \
+	yyleng = (int) (yy_cp - yy_bp); \
+	yy_hold_char = *yy_cp; \
+	*yy_cp = '\0'; \
+	yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 169
+#define YY_END_OF_BUFFER 170
+static yyconst short int yy_accept[1051] =
+    {   0,
+        0,    0,    0,    0,    0,    0,  170,  169,  162,  158,
+      161,  168,  150,  149,  152,  164,  150,  152,  152,  153,
+      151,  137,  148,  152,  156,  155,  157,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  162,  158,  161,  168,  152,
+      148,  143,  143,  143,  143,  143,  169,    0,    0,  162,
+      163,    0,  161,  168,  168,  168,    0,  141,    0,    0,
+      164,  164,  164,  164,    0,    0,    0,  140,    0,    0,
+        0,  132,    0,    0,   25,    0,  144,    0,    0,    0,
+        0,    0,    0,    0,  133,    0,  148,   24,    0,  143,
+
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,   40,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  162,  160,    0,  160,
+        0,    0,    0,    0,    0,  163,  159,  160,    0,  168,
+      167,  168,  168,    0,    0,  166,   25,    0,    0,  160,
+      148,    4,    0,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,    0,    0,    0,  168,  168,
+
+        0,    0,  164,  164,    0,    0,    0,    0,  139,    0,
+        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+        0,    0,    0,    0,    0,    0,  147,  144,    0,    0,
+        0,  142,    0,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  113,  143,  143,  143,
+        0,  143,  143,  143,  143,  143,   15,  143,  143,  143,
+      112,  143,  143,  143,  143,  143,    0,  143,    0,   93,
+      143,  143,  143,  109,  119,  143,  143,  124,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,  143,  116,  143,
+
+      143,  143,  143,  143,  120,  143,  143,  143,  143,  143,
+      162,  160,    0,  163,    0,    0,    0,    0,    0,    0,
+        0,  160,    0,  160,  168,  168,    0,    0,  166,    0,
+        0,  148,    4,    4,    4,    4,  142,    0,  143,  143,
+        0,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+      143,    0,    0,    0,  168,  168,    0,    0,  164,  164,
+        0,    0,    0,    0,   82,    0,    0,    0,  145,    0,
+      144,    0,  146,    0,   26,   28,   27,   30,   29,   31,
+        0,   33,    0,  144,    0,  145,    0,  144,    0,  146,
+        0,  142,    0,  143,  143,  123,  115,  143,  118,  121,
+
+      143,   21,  143,  143,  143,  143,  143,  114,  143,  143,
+      143,    0,  143,  143,  143,   91,    0,  105,  143,  143,
+      143,  143,  143,  143,  143,  143,  143,    0,  106,  143,
+      143,  143,  143,  143,  143,  143,    0,   85,  143,  143,
+      143,  143,  143,  143,    0,   95,  143,  143,    0,  108,
+      143,  143,  143,  143,  110,   20,   57,   71,  143,  143,
+      143,  143,  143,  143,  143,  143,   76,   41,  143,  143,
+      143,  143,   66,  143,  125,  117,  143,   69,   51,  143,
+        0,   94,   96,  143,   89,   98,  143,  143,  162,  160,
+      163,    0,    0,    0,    0,    0,    0,  160,    0,  160,
+
+      168,  168,    0,    0,  148,    4,    4,    0,  142,    0,
+      143,  143,  143,  143,  143,  143,  143,  143,  143,   17,
+        0,    0,    0,  168,  168,    0,    0,  164,  164,    0,
+        0,    0,    0,   86,   35,   32,   34,    0,  142,    0,
+      142,  143,  143,  143,  143,  143,   46,  143,  143,  143,
+      122,  143,  143,    0,  143,  143,  143,    0,  143,  143,
+        0,    0,    0,    0,    0,    0,    0,    0,   39,  143,
+       92,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+       73,   73,   73,   73,  143,    0,  104,  111,  143,  143,
+       85,  143,  143,  143,  143,  143,  143,  143,  143,  143,
+
+      143,  143,  143,  143,  143,  143,  143,   49,  143,   74,
+      143,  143,  143,    0,  143,  143,  143,  143,  143,   99,
+      143,  143,   52,   78,  162,  160,  163,    0,    0,    0,
+        0,    0,  160,    0,  160,  168,  168,    0,    0,  148,
+        4,    3,    0,  142,    0,  142,    0,  101,  143,  143,
+       46,  143,  143,  122,   83,  143,   67,   68,   67,    0,
+       22,    0,  168,   22,    0,   22,   22,  164,   22,    0,
+       22,   22,   22,    0,  143,   22,   22,   22,  143,  143,
+      143,   60,  143,  143,  143,  143,    0,  143,  143,  138,
+        0,    0,   90,  143,   39,    0,   92,    0,    0,    0,
+
+        0,    0,    0,    0,  143,  143,  143,  143,  143,  143,
+      143,  143,  143,    0,  107,  143,  143,  143,  143,  143,
+      143,  143,   63,  143,  143,  143,  127,   97,  126,  128,
+       36,  143,  143,  143,  143,  143,  143,   80,    0,  143,
+       10,   72,   18,  143,  143,   79,  162,  160,  163,    0,
+        0,    0,  160,  168,   22,    0,   22,    4,    3,    3,
+      143,  143,  143,   22,   22,   22,  143,   23,  165,   23,
+       23,   23,   23,   23,   23,   23,    0,   87,   23,   23,
+       23,  143,  143,  143,   55,  143,  143,  143,    0,    0,
+      143,  143,   37,   90,    0,  143,    0,    0,    0,    0,
+
+        0,    0,    0,    0,  143,  143,  143,  143,  143,  143,
+       70,  143,  143,  143,    0,    0,  143,  143,   16,   47,
+       42,  143,  143,   43,    0,  143,  143,  143,  143,   64,
+       81,    7,    0,    0,  143,    0,  143,  143,    0,    0,
+        0,   23,   23,    4,  143,   23,   23,   23,  143,   61,
+      143,    8,  143,  143,   84,  143,  143,   37,    0,    0,
+      143,  143,    0,  143,    0,    0,    0,    0,    0,    0,
+       70,    0,  143,  143,  143,  143,  143,  143,   53,  143,
+       62,    0,    0,    0,  134,   11,   19,  143,  143,    0,
+      143,   77,   65,  143,    0,  143,    0,  143,  143,    0,
+
+        0,    4,  143,   56,  143,  130,   44,  143,   48,    0,
+        0,  143,  143,    0,   54,    0,    0,    0,    0,    0,
+        0,   53,  143,  143,   38,  143,  103,  143,  143,    0,
+        0,    0,    0,  134,  129,   88,    0,  143,   58,    0,
+       59,    0,  143,  143,    0,   56,    4,    4,  143,  143,
+        9,    0,    0,  143,  143,   54,    0,    0,   38,    0,
+      103,    0,  143,  143,   13,  143,  143,    0,    0,    0,
+      143,    0,    0,  100,    6,    0,    4,    4,  143,   45,
+        0,    0,  143,  143,    0,    0,   13,    0,   14,  143,
+      143,   50,    0,    0,    0,  143,    0,  100,    0,    4,
+
+        2,  102,    0,    0,  143,  143,   14,    0,    0,  131,
+      143,    0,    0,    0,  143,    0,  102,    4,    0,    0,
+      136,  143,  131,    0,   12,    0,    0,    0,  143,    0,
+        1,  136,    0,  143,   12,    0,    0,    0,  143,    0,
+        0,  135,    0,    0,    0,   75,    5,  135,   75,    0
+    } ;
+
+static yyconst int yy_ec[256] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    4,    5,    6,    7,    8,    9,   10,   11,   12,
+       13,   14,   15,   16,   17,   18,   19,   20,   21,   22,
+       23,   24,   25,   26,   27,   28,   20,   29,   30,   31,
+       32,   33,    1,    1,   37,   38,   39,   40,   41,   42,
+       43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
+       53,   54,   55,   56,   57,   58,   59,   60,   61,   62,
+       34,    1,   35,    1,   36,    1,   37,   38,   39,   40,
+
+       41,   42,   43,   44,   45,   46,   47,   48,   49,   50,
+       51,   52,   53,   54,   55,   56,   57,   58,   59,   60,
+       61,   62,   63,   63,   63,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1
+    } ;
+
+static yyconst int yy_meta[64] =
+    {   0,
+        1,    2,    3,    4,    1,    5,    1,    1,    1,    6,
+        1,    1,    1,    1,    7,    1,    7,    8,    1,    9,
+        9,    9,    9,    9,    9,    9,    9,    9,    1,    1,
+        1,    1,    1,    1,    1,   10,   11,   10,   10,   12,
+       13,   14,   15,   16,   10,   10,   10,   15,   15,   15,
+       11,   10,   12,   15,   15,   14,   15,   10,   17,   10,
+       10,   10,    5
+    } ;
+
+static yyconst short int yy_base[1103] =
+    {   0,
+        0,   62,    0,    0,    0,    0, 4018,   35,   66,   67,
+       70,   36,   67,   37,   38,   72,   93,   96,   83,   39,
+      151,   94,   88,   57,   68,   78,   75,  194,  233,  148,
+      186,  228,  247,  113,  188,  263,  223,  274,  279,  276,
+      295,  292,  314,  324,  329,  389,  125,  445,  139,  360,
+      141,  502, 3980,  341,  360,  303, 4019, 3979, 3961,  144,
+      158,  161,  165,    0, 3977, 3959, 4006, 4005,  176,  126,
+     4007, 4006,  153,  130,  195,  288,  235, 4019,  402,  407,
+      431, 4019, 3958, 3950, 4019,  564,  187, 3956, 3952,  207,
+      221,  159, 3950, 3952, 4019,  605,  339, 4019,  469,  385,
+
+      528,  530,  548,  555,  593,  612,  614,  634,  302,  361,
+      103,  198,  370,  405,  154,  233,  689,  406,  397,  256,
+      420,  172,  647,  427,  537,  269,  586,  693,  696,  426,
+      624,  555,  583,  668,  347,  682,  684,  687,  691,  686,
+      585,  627,  706,  540,  715,  425,  707,  722,  369,  243,
+      726,  729,  736,  629,  741,  744,  782,  789, 3999,  133,
+      449, 3964, 3952,  281, 3944,  801, 4019,  857,  572, 3995,
+     4019,  228,  306, 3994,  614, 4019, 3993,  342,  650,  609,
+      792,  805,  912,  940, 3977,  764,  419,  590,  798,  404,
+      634,  760,  776,  763,  783, 3946, 3936,  692, 3944, 3934,
+
+      681,  696,  118,  319,  823,  861,  884,  840, 4019,  863,
+      865, 1002, 3934,  741,  874,  875, 3949, 3970, 3969, 3968,
+     3967, 3966, 3965, 3926, 3963, 3926, 4019,  863,  884,  890,
+      891, 3938, 3937,  872,  731,  993,  873,  970,  875,  972,
+      971,  975,  865,  973,  982,  979,  995, 1000, 1003, 1001,
+     3918,  629, 1006, 1008, 1004, 1009, 1062, 1022, 1066, 1019,
+     1024, 1028, 1042, 1034, 1035, 1054, 1083, 1055,  919, 4019,
+     1075, 1076, 1043, 1078, 1088, 1124, 1133, 1090, 1097, 1094,
+     1112, 1103, 1104, 1115, 1068, 1119, 1109, 1125, 1134, 1147,
+     1149, 1139, 1148, 1153, 1155, 1157, 1167, 1162, 1169, 1177,
+
+     1178, 1183, 1182, 1226, 1185, 1203, 1204, 1206, 1188, 1208,
+     1246, 1265, 3915, 1272, 3972, 3919, 3923, 3916, 3920, 3802,
+     3796, 1328,  716,  845,  450,  867, 3817, 1269, 4019, 1107,
+     1221, 1243, 3795, 1288, 1223,  820, 1383, 1422,    0, 3778,
+     1461, 1242,  714,  749, 1244,  836, 1247, 1190, 1256, 1247,
+     1283, 3657, 3654, 1009, 3623, 3632,  651,  347, 1162,  397,
+     1296, 1306, 1316, 1321, 4019, 3614, 1356, 1319, 1352, 1367,
+     1392, 1406, 1431, 3650, 4019, 4019, 4019, 4019, 4019, 4019,
+     3649, 4019, 3647,  877, 1445, 1470, 1479, 1488, 1497, 1506,
+     1347, 3620, 1348, 1281, 1329, 4019, 1260, 1384, 1344, 1345,
+
+     1385, 1423, 1424, 1498, 1425, 1499, 1500, 1501, 1503, 1511,
+     1506, 3615, 1513, 1504, 1509, 1564, 1622, 4019, 1525, 1532,
+     1533, 1534, 1536, 1537, 1543, 1556, 1544, 1580, 4019, 1559,
+     1681, 1562, 1601, 1571, 1574, 1580, 3605, 1577, 1585, 1583,
+     1598, 1607, 1604, 1609, 1617, 4019, 1605, 1614, 1668, 4019,
+     1708, 1639, 1709, 1710, 1711, 1712, 1713, 1714, 1718, 1724,
+     1733, 1723, 1734, 1738, 1739, 1744, 1743, 1768, 1746, 1747,
+     1748, 1749, 1754, 1757, 1767, 1769, 1795, 1772, 1773, 1777,
+     1813, 4019, 1775, 1779, 1776, 1781, 1797, 1799, 1837, 1852,
+     1859, 3614, 3597, 3613, 3611, 3607, 3643, 1915, 1010, 1091,
+
+     1592, 1177, 1816, 1356, 1840, 1821, 1834, 1970, 1996, 2035,
+     1870, 1382, 1825, 1833, 1827, 1842, 1877, 1811, 1947, 3642,
+     3604,    0, 1671, 3603,    0, 1395, 3636, 1604, 3638, 1886,
+     1901, 3584, 1919, 4019, 4019, 4019, 4019, 1954, 1982, 2005,
+     2019, 1847, 2063, 1836, 1876, 1907, 1868, 1910, 1911, 1916,
+     1896, 1932, 1999, 3594, 2090, 1908, 2091, 2128, 2092, 2096,
+     3586, 3576,  545, 3581, 3557, 1211, 3548, 3545, 1997, 2099,
+     2012, 2100, 2101, 2106, 2110, 2114, 2111, 2125, 2105, 2165,
+     4019, 2168, 2162, 2124, 2161, 2168, 4019, 2147, 2149, 2167,
+     4019, 2169, 2170, 2172, 2176, 2177, 2183, 2185, 2190, 2195,
+
+     2192, 2199, 2204, 2206, 2205, 2211, 2214, 2191, 2225, 2217,
+     2219, 2220, 2230, 3537, 2226, 2233, 2240, 2245, 2239, 4019,
+     2246, 2251, 2254, 2255, 2308, 2315, 2327, 2294, 3527, 1750,
+     3524, 2312, 2383, 1392, 1431, 1926, 3555, 2136, 3552, 2268,
+     1923, 2009, 2438, 2464, 2490, 2516, 2334, 4019, 2285, 1916,
+     3530, 2290, 2544, 3529, 2172, 2267, 2341, 4019, 2357,    0,
+     4019, 2601,    0,    0, 3510, 3505, 3412, 3398, 3370, 2172,
+     2330, 2339, 4019, 2376, 2629, 2374, 2338, 2315, 2323, 2353,
+     2354, 2366, 2367, 2374, 2375, 2379, 3322, 2442, 2376, 2378,
+     3322, 3315, 2381, 2397, 4019, 3308, 4019, 3269, 3284, 3260,
+
+     3255, 3225, 3183, 3175, 2415, 2416, 2388, 2466, 2441, 2382,
+     2467, 2418, 2656, 2445, 4019, 2419, 2693, 2446, 2657, 2659,
+     2662, 2468, 2469, 2470, 2664, 2661, 2669, 2670, 2671, 2675,
+     2718, 2677, 2680, 2684, 2689, 2696, 2690, 2691, 2523, 2704,
+     2698, 2699, 2705, 2744, 2717, 2714, 2760, 2772, 2782, 3138,
+     3122, 3104,    0, 3123, 3052, 3047, 3041, 1843, 3034, 2472,
+     2724, 2839, 2738, 2900,    0, 3013, 2765, 4019, 4019,    0,
+     3010, 2978, 2955, 2523, 2607, 4019, 2791, 4019, 2884, 2742,
+     2726, 2753, 2752, 2760, 2772, 2783, 2773, 2781, 2916, 2911,
+     2879, 2776, 2877, 4019, 2904, 2880, 2784, 2767, 2748, 2742,
+
+     2716, 2702, 2591, 2567, 2881, 2882, 2892, 2895, 2902, 2901,
+     2905, 2906, 2907, 2914, 2962, 2962, 2917, 2932, 2916, 2936,
+     2939, 2940, 2944, 2941, 2446, 2943, 2945, 2948, 2946, 2954,
+     2955, 2966, 3002, 2583, 2968, 3008, 2970, 2974, 2571, 2482,
+     2497, 2499, 2477, 1629, 2976, 3045,    0, 2453, 2978, 2526,
+     2980, 2984, 2986, 2988, 2992, 2998, 2999, 4019, 2417, 2389,
+     3002, 3004, 2383, 3020, 2353, 2352, 2334, 2327, 2337, 2317,
+     4019, 2321, 3038, 3022, 3040, 3006, 3026, 3041, 3025, 3047,
+     3048, 3083, 2527, 3096, 3097, 3050, 3051, 3071, 3074, 2276,
+     3066, 3077, 3078, 3079, 2306, 3081, 2274, 3082, 3084, 2264,
+
+     2242, 3087, 3086, 3087, 3102, 3093, 3105, 3107, 3108, 2169,
+     2144, 3112, 3114, 2140, 3109, 2126, 2006, 1994, 1978, 1958,
+     1943, 4019, 3118, 3117, 3120, 3121, 3123, 3128, 3139, 2610,
+     3170, 3184, 3182, 3186, 3144, 3153, 1938, 3163, 3154, 1944,
+     3164, 1851, 3168, 3169, 1846, 4019, 2261, 2360, 3166, 3174,
+     3167, 1848, 1828, 3176, 3182, 4019, 1808, 1818, 4019, 1803,
+     4019, 1700, 3175, 3194, 3189, 3195, 3197, 2829, 3242, 1714,
+     3200, 1663, 1628, 3202, 3205, 1618, 1539, 1603, 3210, 3213,
+     1612, 1547, 3216, 3221, 1522, 1512, 4019, 1435, 3223, 3224,
+     3231, 3225, 2832, 3270, 1434, 3247, 1423, 4019, 1268, 1256,
+
+     1246, 3232, 1127, 1112, 3234, 3245, 4019, 1102,  967, 3252,
+     3254, 3087, 3294,  858, 3255,  819, 4019,  679,  771,  680,
+     3256, 3263, 4019,  621, 3265, 3313, 3340,  564, 3268,  518,
+      496, 4019,  287, 3276, 4019, 3342, 3353,  190, 3292,  219,
+      139, 3278, 3344, 3359,   75, 3311, 4019, 4019, 4019, 4019,
+     3381, 3398, 3415, 3432, 3449, 3459, 3466, 3483, 3500, 3514,
+     3528, 3537, 3550, 3567, 3581, 3590, 3604, 3613, 3309, 3342,
+     3462, 3622, 3463, 3512, 3517, 1068, 1077, 3634, 3648, 3654,
+     3518, 3579, 3660, 3666, 3675, 3692, 3709, 3726, 3743, 3760,
+     3777, 3791, 3800, 3817, 3834, 3851, 3868, 3885, 3902, 3919,
+
+     3936, 3953
+    } ;
+
+static yyconst short int yy_def[1103] =
+    {   0,
+     1050,    1, 1051, 1051,    1,    2, 1050, 1050, 1050, 1050,
+     1050, 1052, 1053, 1050, 1050, 1054, 1055, 1050, 1050, 1050,
+     1050, 1050, 1056, 1050, 1050, 1050, 1050, 1057, 1057,   29,
+       29,   29,   29,   32,   32,   32,   32,   32,   32,   32,
+       32,   32,   32,   31,   31, 1050, 1050, 1050, 1058, 1059,
+     1060, 1050,   32,   32,   31,   32, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1052, 1052, 1052, 1053, 1053, 1053, 1053,
+     1054, 1050, 1054, 1054, 1055, 1061, 1055, 1050, 1055, 1055,
+     1050, 1050, 1050, 1050, 1050, 1050, 1062, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1063, 1056, 1050, 1050,   32,
+
+       32,   32,   32,   32,   32,   29,   32,   32,  108,  108,
+      108,  108,  108,  108,  108,  108, 1057,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108, 1050, 1050, 1064, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1065, 1058,
+     1050, 1058, 1058, 1066, 1066, 1050, 1066, 1066, 1066, 1065,
+     1067, 1068, 1066, 1050,  184,  108,  184,  184,  108,  184,
+      184,  108,  108,  108,  108, 1050, 1050, 1050, 1052, 1052,
+
+     1053, 1053, 1054, 1054, 1061, 1061, 1061, 1061, 1050, 1055,
+     1055, 1050, 1050, 1069, 1070, 1071, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1072, 1073, 1074,
+     1075, 1076, 1077,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+     1078,  117,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108, 1050,  108, 1050, 1050,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+     1050, 1050, 1050, 1050, 1064, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1079, 1079, 1058, 1058, 1066, 1066, 1050, 1066,
+     1066, 1080, 1068, 1068, 1068, 1068, 1066, 1066,  184,  184,
+     1066,  108,  184,  184,  108,  184,  184,  108,  108,  108,
+      108, 1050, 1050, 1050, 1052, 1052, 1053, 1053, 1054, 1054,
+     1061, 1055, 1055, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1072, 1050, 1050, 1050, 1050, 1050, 1050,
+     1081, 1077, 1082,  108,  108, 1050,  108,  108,  108,  108,
+
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108, 1050,  108,  108,  108,  108, 1050, 1050,  108,  108,
+      108,  108,  108,  108,  108,  108,  108, 1050, 1050,  108,
+     1050,  108,  108,  108,  108,  108, 1050,  108,  108,  108,
+      108,  108,  108,  108, 1050, 1050,  108,  108, 1050, 1050,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+     1050, 1050,  108,  108,  108,  108,  108,  108, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1083, 1083,
+
+     1058, 1058, 1066, 1066, 1084, 1068, 1068, 1066, 1066, 1066,
+      108,  184,  184,  108,  184,  184,  108,  108,  108, 1050,
+     1050, 1085, 1050, 1052, 1086, 1053, 1087, 1054, 1088, 1055,
+     1089, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050,  108, 1050,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108, 1050,  108,  108,  108, 1050,  108,  108,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+     1050, 1050,  108,  108,  108, 1050, 1050,  108,  108,  108,
+     1050,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108, 1050,  108,  108,  108,  108,  108, 1050,
+      108,  108,  108,  108, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1058, 1090, 1066, 1091, 1092,
+     1068, 1093, 1066, 1066, 1066, 1066, 1050, 1050,  108,  184,
+      184,  108, 1050,  184, 1050,  108, 1050, 1050, 1050, 1094,
+     1050, 1050, 1095, 1052, 1096, 1053, 1053, 1097, 1054, 1098,
+     1055, 1055, 1050, 1050, 1050, 1050,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108, 1050,  108,  108,  108,
+     1050, 1050,  108,  108, 1050, 1050, 1050, 1050, 1050, 1050,
+
+     1050, 1050, 1050, 1050,  108,  108,  108,  108,  108,  108,
+      108,  108,  108, 1050, 1050,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108,  108,  108,  108,  108, 1050,  108,
+      108,  108,  108,  108,  108,  108, 1050, 1050, 1050, 1050,
+     1050, 1050,  633, 1099, 1058, 1100, 1066, 1068, 1093, 1093,
+      108, 1050,  108, 1066,  184,  184,  108, 1050, 1050, 1052,
+     1053, 1053, 1054, 1055, 1055, 1050, 1050, 1050, 1050,  108,
+      108,  108,  108,  108,  108,  108,  108,  108, 1050, 1050,
+      108,  108,  108, 1050, 1050,  108, 1050, 1050, 1050, 1050,
+
+     1050, 1050, 1050, 1050,  108,  108,  108,  108,  108,  108,
+      108,  108,  108,  108, 1050, 1101,  108,  108,  108,  108,
+      108,  108,  108,  108, 1050,  108,  108,  108,  108,  108,
+      108,  108, 1050, 1050,  108, 1050,  108,  108, 1050, 1050,
+     1050, 1058, 1066, 1068,  108, 1066,  184,  184,  108, 1050,
+      108,  108,  108,  108,  108,  108,  108, 1050, 1050, 1050,
+      108,  108, 1050,  108, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050,  108,  108,  108,  108,  108,  108,  108,  108,
+      108, 1101, 1050, 1102, 1101,  108,  108,  108,  108, 1050,
+      108,  108,  108,  108, 1050,  108, 1050,  108,  108, 1050,
+
+     1050, 1068,  108,  108,  108,  108,  108,  108,  108, 1050,
+     1050,  108,  108, 1050,  108, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050,  108,  108,  108,  108,  108,  108,  108, 1050,
+     1102, 1101, 1102, 1102,  108,  108, 1050,  108,  108, 1050,
+      108, 1050,  108,  108, 1050, 1050, 1068, 1068,  108,  108,
+      108, 1050, 1050,  108,  108, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050,  108,  108,  108,  108,  108, 1050, 1101, 1050,
+      108, 1050, 1050,  108,  108, 1050, 1068, 1068,  108,  108,
+     1050, 1050,  108,  108, 1050, 1050, 1050, 1050,  108,  108,
+      108,  108, 1050, 1101, 1050,  108, 1050, 1050, 1050, 1068,
+
+     1068,  108, 1050, 1050,  108,  108, 1050, 1050, 1050,  108,
+      108, 1050, 1101, 1050,  108, 1050, 1050, 1068, 1050, 1050,
+      108,  108, 1050, 1050,  108, 1050, 1101, 1050,  108, 1050,
+     1068, 1050, 1050,  108, 1050, 1101, 1101, 1050,  108, 1050,
+     1050,  108, 1101, 1102, 1050,  108, 1050, 1050, 1050,    0,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+
+     1050, 1050
+    } ;
+
+static yyconst short int yy_nxt[4083] =
+    {   0,
+        8,    9,   10,   11,   12,   13,    8,   14,   15,   16,
+       17,   18,   15,   19,   15,   20,   15,   21,   22,   23,
+       23,   23,   23,   23,   23,   23,   23,   23,   15,   24,
+       25,   26,   27,   15,   15,   28,   29,   30,   31,   32,
+       33,   34,   35,   28,   36,   28,   28,   37,   38,   39,
+       40,   41,   28,   42,   43,   44,   28,   28,   45,   28,
+       28,   28,    8,   46,   47,   48,   49,   60,   62,   61,
+       62,   61,   68,   63,   72,   50,   58,   65,   58,   58,
+       58,   51,   51,   51,   51,   51,   51,   51,   51,   51,
+       59,   66,   59,   59,   59,   76,   85,   81,   58,   81,
+
+       52,   53,   77,   78,   54,   96,   95,   58,   69,   58,
+       98,   58,   59,   73,   82, 1049,   58,   55,   56,   58,
+       72,   59,   70,   59,   58,   59,   62,   74,   62,   58,
+       59,   68,   72,   59,   79,   58,  160,   58,   59,  243,
+       83,  171,  160,   59,  180,   60,   84,   61,   80,   59,
+      160,   59,   86,  101,   86,   72,  101,  124,   96,   61,
+      125,   61,  198,  126,  198,  359,   61,  101,   63,  127,
+       87,   87,   87,   87,   87,   87,   87,   87,   87,  202,
+      172,   68,   58,  204,  109,  101,  101,   88, 1048,  203,
+      249,   89,   58,   90,  173,  101,   59,   76,   91,  223,
+
+       92,   93,  101,  103,   77,   78,   59,  101,  101,  224,
+       94,   99,  201,  100,  100,  100,  100,  100,  100,  100,
+      100,  100,  110,  101,  101,  259,  214,  215,  101,  111,
+      171, 1047,  101,  112,  101,  102,  113,   76,  128,  216,
+      101,  103,  101, 1045,   77,   78,  114,  219,  244,  103,
+       99,  101,  100,  100,  100,  100,  100,  100,  100,  100,
+      100,  221,  220,  101,  325,  101,  101,  101,  115,  101,
+      104,  105,  116,  132,  102,  101,  222,  101,  117,  301,
+      106,  250,  118,  103,  101,  101,  101,  107,  108,  206,
+      207,  206,  101,  302,  119,  257,  120,  208,  209,  121,
+
+      122,  101,  103,  101,  129,  101,  123,  101,  171,  101,
+      133,  130,  131,  101,  101,  136,  101,  101,  134,  101,
+      101,   72,  265,  137,  135,  139,  101,  140,  101,  138,
+      101,  141,  145,  101,  197,  101,  101, 1041,  101,  101,
+      241,  320,  101,  101,  176,  142,  101,  101,  143,  101,
+      146,  144,   68,  101,  147,  101,   96,  195,  148,  326,
+      152,  175,  176,  175,  101,  101,  149,  153,  101,  150,
+      151,  101,  155,  177,  101,  360,  101,  154,  330,  101,
+     1050,  101,  156,  101,  101,  101,  278,  527,  193,  101,
+      157,  128,  158,  159, 1050,  101,  152,  101,  160,   72,
+
+      101,  178,  233,  153,   76,  101,  101,  101,  242,   76,
+      101,   77,   78,  154,  101,  179,   77,   78,  245,  246,
+      194,  341,  300,  101,  247,  101,  101,  161,  162,  101,
+       58,  163,   81,  101,   81,  101,  341,  529,  210,  101,
+      101,  101,  101,  248,  164,  165,  166,  167,  168,  159,
+      101,  256,  171,  255,  160,  343,  101,  346,  101,  101,
+      211,  101,  101,  101,  169,  169,  169,  169,  169,  169,
+      169,  169,  169,  101,  263,   83,  258,  271,  101,  101,
+      101,   84,  296,  161,  162,  316,   58,  163,  232,  232,
+      232,  232,  232,  232,  232,  232,  232,  501,  176,  317,
+
+      164,  165,  174,  175,  176,  175,  174,  174,  174,  182,
+      174,  174,  174,  174,  174,  174,  174,  174,  174,  183,
+      174,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      174,  174,  174,  174,  174,  174,  174,  185,  186,  185,
+      185,  185,  185,  187,  185,  111,  185,  185,  185,  188,
+      185,  185,  189,  185,  185,  185,  185,  190,  185,  185,
+      185,  185,  191,  185,  174,   86,  234,   86,  101,  101,
+      101,  101,  101,  101,  101,  324,  101,  290,  101, 1040,
+      101,  160,  101,  101,  101,  101,  697,  264,  101,  101,
+      101,  101,  101,  101,  698,  101,  101,  275,  101,  101,
+
+       88,  235,  101,  101,   89,  101,   90,  341,  101,  236,
+      101,   91,  324,   92,   93,  328,  329,  328,  160,  101,
+     1038,  101,  101,   94,  228,  228,  228,  228,  228,  228,
+      228,  228,  228,  101,  101,  266,  101,  101,  285,  101,
+      344,  286,  276,  237,  229,  230,  233,  101,  101,  101,
+      101,  341,  176,  101,  101,  101,   68,  231,  239,  238,
+      101, 1035,  272,  101,  101,  101,  101,  101,  101,  101,
+      240,  287,  347,  308,  101,  101,  273,  101,  101,  274,
+      101,  176,  101,  101,  101,  101,   68,  235,  101,  101,
+      251,  260,  251,  354,  267,  354,  267,  269,  261,  269,
+
+      101,   68,  262,  331,  101,  526,   99,  270,  252,  252,
+      252,  252,  252,  252,  252,  252,  252,  277,  101,  500,
+      101,  101,  101,  101, 1033,  160,  283,  101,  357,  101,
+      279,  341,  234,  280, 1031,  101,  281,  101,  282,  101,
+      101,  284,  101,  101,  101,  253,  101,  254,  268,  101,
+      288,  291,  358,  292,  297,  368,  289,  368,  101,  101,
+      101,  512,  101,  303,  298,  101,  341,  101,  101,  293,
+      294,  299,  101,  295,  304,  101,  307,  101,  305,  101,
+      101,  309,  306,  311,  101,  312,  159,  395,  310,  101,
+      314,  160,  312,  159,  101,  324,  101,  101,  160,  101,
+
+      101,  160,  314,  513,  312,  159,  334,  176,  334,   96,
+      160,  242,  101,  101,  350,  348,  101,  101,  342,  101,
+      161,  162,  176,  351,  163,  207,  349,  161,  162,  101,
+     1032,  163,  361,  209,  101, 1030,  101,  313,  165,  161,
+      162,  335,  207,  163,  313,  165,  245,  345,  500,  361,
+      209,  101,  247,  341,  160,  336,  313,  165,  314,  167,
+      322,  159,  206,  207,  206,   76,  160,   76,  507,  171,
+      208,  209,   77,   78,   77,   78,  323,  323,  323,  323,
+      323,  323,  323,  323,  323,  206,  207,  206,  370,  372,
+      370,  372,  515,  208,  209,  161,  162, 1028,  385,  163,
+
+      385,  101,  214,  215,  387,  389,  387,  389,  101,  101,
+      362,  101,  313,  165,  176,  216,  214,  215,  403,  394,
+      269,  363,  269,  502,  399,  101,  101,  397,  101,  216,
+      270,  337,  337,  337,  337,  337,  337,  337,  337,  337,
+      327,  327,  176,  327,  327,  327,  327,  327,  327,  327,
+      327,  327,  327,  327,  327,  327,  327,  338,  327,  339,
+      339,  339,  339,  339,  339,  339,  339,  339,  327,  327,
+      327,  327,  327,  327,  327,  340,  340,  340,  340,  340,
+      340,  340,  340,  340,  340,  340,  340,  340,  340,  340,
+      340,  340,  340,  340,  340,  340,  340,  340,  340,  340,
+
+      340,  340,  327,  364,  396,  364,  101,  101,  101,  101,
+      523,  101,  523,  635,  365,  101, 1024,  401,  101,  160,
+      398,  400,  402,  101,  101,  101,  101,  404,  101,  101,
+      405,  101,  101,  406,  407,  101,  101,  101,  408,  101,
+      415,  411,  101,  413,  101,  101,  101,  409,  101,  416,
+      410,  414,  366,  101,  101,  101,  101,  101,  101,  101,
+      101,  101,  101,  417,  101,  417,  427,  428,  432,  428,
+      434,  101,  101,  430,  431,  101,  232,  101,  101,  101,
+      232,  101,  433,  435,  267,  392,  267,  101,  101,  392,
+      101,  101,  436,  418,  635,  101,  101,  429,  101,  441,
+
+      160,  419,  101,  420,  460,  438,  421,  101,  101,  176,
+      422,  101,  101,  423,  101,  101,  424,  425,  442,  101,
+      426,  101,  439,  440,  101,  445,  101,  445,  101,  101,
+      101,  443,  444,  101,  449,  446,  449,  454,  437,  101,
+      101,  101, 1023,  101,  450,  101,  453,  101,  101,  455,
+      101,  101,  456,  458,  503,  101,  101,  101,  462,  459,
+      101,  101,  101,  457,   72,  101, 1020, 1019,  101,  101,
+      101,  447,  101,  461,  463,  101,  465,  101,  101,  171,
+      451,  448,  464,  101,  101,  101,  101,  101,  467,  101,
+      452,  101,  101,  101,  466,  469,  468,  473,  101,  472,
+
+      101,  101,  101,  101,  470,  101,  101,  474,  101,  471,
+      101,  475,  476,  101,  101,  101,  528,  637,  101,  101,
+      101,  101,  101,  176,  101,  176,  517,  481,  483,  481,
+      101,  101,  477,  478,  479,  480,  101,  482,  101,  101,
+      101,  487,  101,  101,  101,  484,  500,  489,  176,  490,
+      159,  701,  160,  485,  486,  160,  101,  101,  176,  101,
+       96,  101,  101,  488,  341,  506,  491,  702,  490,  159,
+      328,  329,  328,  491,  160,  490,  159,  504,  101,  101,
+      101,  160,  511,  101,  161,  162,  520,  519,  163,  334,
+      176,  334,  101,  518,  516,  101,  101,  101,  207,  514,
+
+      101,  313,  165,  161,  162,  361,  209,  163,   76,  101,
+      161,  162, 1018,  101,  163,   77,   78,  101,   76,  101,
+      313,  165,  364, 1017,  364,   77,   78,  313,  165,  491,
+      167,  498,  159,  365,  101,  542,  101,  160,  369,  369,
+      369,  369,  369,  369,  369,  369,  369,  499,  499,  499,
+      499,  499,  499,  499,  499,  499,  531,  533,  176,  533,
+      530,  538,  540,  538,  540,  101,  161,  162,  534,  543,
+      163,  369,  369,  369,  369,  369,  369,  369,  369,  369,
+      101,  101,  101,  313,  165,  176,  371,  371,  371,  371,
+      371,  371,  371,  371,  371,  160,  639,  101,  101,  341,
+
+       68,  160,  337,  337,  337,  337,  337,  337,  337,  337,
+      337,  371,  371,  371,  371,  371,  371,  371,  371,  371,
+      101,  101,  544,  508,  176,  373,  373,  373,  373,  373,
+      373,  373,  373,  373,  160,  665,  650,  101,  101,  545,
+      160,  509,  509,  509,  509,  509,  509,  509,  509,  509,
+      373,  373,  373,  373,  373,  373,  373,  373,  373,  101,
+      546,  101,  510,  176,  386,  386,  386,  386,  386,  386,
+      386,  386,  386, 1016, 1014,  548,  101,  101,  101, 1009,
+      337,  337,  337,  337,  337,  337,  337,  337,  337,  386,
+      386,  386,  386,  386,  386,  386,  386,  386,  388,  388,
+
+      388,  388,  388,  388,  388,  388,  388,  388,  388,  388,
+      388,  388,  388,  388,  388,  388,  390,  390,  390,  390,
+      390,  390,  390,  390,  390,  390,  390,  390,  390,  390,
+      390,  390,  390,  390,  101,  101,  101,  101,  547,  101,
+      101,  176,  101,  551,  550,  101,  549,  101,  556,  101,
+     1008,  101,  101,  101,  101,  553,  101,  101,  552,  101,
+      555,  101,  101,  557,  101,  558,  101,  558,  101,  101,
+      101, 1007,  101,  101,  571,  569, 1000,  575,  101,  101,
+      101,  428,  572,  428,  573,  101,  101,  101,  570,  574,
+      101, 1004,  101,  576,  171,  101,  101,  101,  101,  578,
+
+      101,  579,  586,  577,  586,  176,   72,  101,  559,  101,
+      589,  429,  101,  101,  580,  585,  101,  101,  445,  101,
+      445,  101,  560,  417,  101,  417,  588,  101,  446,  592,
+      101,  176,  587,  101,  101,  590,  101,  101,  101,  593,
+      101,  101,  594,  101,  668,  101,  636,  599,  598,  595,
+      601,  101, 1001,  418,  101,  600,  596,  101,  101, 1003,
+      597,  561,  101,  562,  902,  999,  563,  101,  998,  449,
+      564,  449,  662,  565,  662,  603,  566,  567,  997,  450,
+      568,  581,  581,  581,  581,  581,  581,  581,  581,  581,
+      581,  581,  101,  581,  581,  581,  581,  581,  582,  581,
+
+      583,  583,  583,  583,  583,  583,  583,  583,  583,  581,
+      581,  581,  581,  581,  581,  581,  584,  584,  584,  584,
+      584,  584,  584,  584,  584,  584,  584,  584,  584,  584,
+      584,  584,  584,  584,  584,  584,  584,  584,  584,  584,
+      584,  584,  584,  581,  101,  101,  101,  101,  101,  101,
+      101,  655,  995,  655,  101,  988,  604,  605,  602,  101,
+      101,  101,  101,  101,  101,  101,  101,  101,  606,  101,
+      101,  101,  607,  608,  611,  101,  101,  101,  609,  101,
+      101,  614,  101,  101,  101,  101,  101,  101,  613,  610,
+      101,  101,  612,  101,  616,  619,  101,  101,  618,  615,
+
+      101,  617,  101,  101,  101,  101,  620,  101,  101,  101,
+      101,  101,  101,  101,  481,  101,  481,  101,  176,  622,
+      101,  101,  101,  176,  482,  101,  101,  621,  101,  101,
+      101,  101,  101,  101,  101,  101,  176,  623,  625,  624,
+      626,  159,  341,  635,  341,  176,  160,  656,  101,  160,
+      101,  987,  101,  627,  986,  626,  159,   96,  985,  341,
+      627,  160,  626,  159,  101,  651,  982,  653,  160,  652,
+      638,  647,  679,  647,  641,  161,  162,  550,  655,  163,
+      655,  648,  654,  101,  844,  642,  101,  675,   76,  101,
+      161,  162,  313,  165,  163,   77,   78,  161,  162,  981,
+
+      101,  163,  976,   76,  101,  973,  101,  313,  165,  649,
+      672,  673,  101,  101,  313,  165,  627,  167,  633,  159,
+      533,  101,  533,  101,  160,  176,  670,  680,  171,  101,
+      101,  534,  101,  341,  634,  634,  634,  634,  634,  634,
+      634,  634,  634,  101,  101,  681,  101,  101,  657,  101,
+      657,  683,  101,  161,  162,  689,  762,  163,  658,  682,
+      101,  101,  659,  101,  101,  684,  754,  758,  101,  101,
+      313,  165,  176,  539,  539,  539,  539,  539,  539,  539,
+      539,  539,  685,  101,  643,  101,  643,  972,  970,  644,
+      644,  644,  644,  644,  644,  644,  644,  644,  176,  962,
+
+      101,  539,  539,  539,  539,  539,  539,  539,  539,  539,
+      760,  176,  760,  961,  960,  509,  509,  509,  509,  509,
+      509,  509,  509,  509,  541,  541,  541,  541,  541,  541,
+      541,  541,  541,  101,  959,  101,  508,  176,  541,  541,
+      541,  541,  541,  541,  541,  541,  541,  958,  101,  645,
+      101,  645,  101,  686,  646,  646,  646,  646,  646,  646,
+      646,  646,  646,  661,  661,  101,  661,  661,  661,  661,
+      661,  661,  661,  661,  661,  661,  661,  661,  661,  661,
+      676,  661,  677,  677,  677,  677,  677,  677,  677,  677,
+      677,  661,  661,  661,  661,  661,  661,  661,  678,  678,
+
+      678,  678,  678,  678,  678,  678,  678,  678,  678,  678,
+      678,  678,  678,  678,  678,  678,  678,  678,  678,  678,
+      678,  678,  678,  678,  678,  661,  101,  101,  101,  558,
+      688,  558,  101,  693,  690,  101,  101,  101,  176,  694,
+      707,  713,  101,  101,  101,  101,  101,  101,  705,  101,
+      101,  710,  101,  101,  101,  706,  708,  709,  101,  101,
+      101,  101,  711,  101,  101,  712,  714,  101,  714,  586,
+      957,  586,  691,  655,   76,  655,  756,  101,  101,  233,
+      956,  775,  776,  101,  953,  101,  692,  232,  232,  232,
+      232,  232,  232,  232,  232,  232,  715,  101,  101,  587,
+
+      101,  101,  101,  101,  717,  101,  101,  719,  101,  720,
+      716,  718,  101,  101,  101,  101,  722,  952,  101,  101,
+      101,  101,  101,  101,  724,  721,  726,  101,  101,  101,
+      101,  101,  723,  727,  725,  101,  101,  729,  101,  728,
+      101,  101,  101,  101,  101,  101,  731,  101,  101,  732,
+      101,  730,  101,  101,  734,  101,  737,  101,  101,  101,
+      733,  101,  101,  176,  101,  735,  101,  101,  738,  101,
+      101,  160,  101,  101,  736,  101,  101,  160,  101,  101,
+      740,  101,  101,  101,  743,   96,  101,  101,  741,  742,
+      101,  101,  101,  101,  744,  647,  946,  647,  101,  101,
+
+      945,  977,  745,  101,  101,  648,  746,  101,  101,  747,
+      942,  748,  159,  657,  767,  657,  749,  160,  748,  159,
+      101,  101,  940,  658,  160,  761,  101,  659,  749,  937,
+      748,  159,   76,  750,  763,  647,  160,  647,  101,   77,
+       78,   76,  657,  101,  657,  648,  161,  162,   77,   78,
+      163,  101,  658,  161,  162,  233,  659,  163,  659,  101,
+      659,  922,  176,  313,  165,  161,  162,  921,  101,  163,
+      313,  165,  659,  750,  101,  920,  101,  777,  782,  777,
+      919,  918,  313,  165,  749,  167,  753,  159,  778,  783,
+      101,  101,  160,  232,  232,  232,  232,  232,  232,  232,
+
+      232,  232,  101,  101,  978,  917,  101,  101,  916,  784,
+      101,  101,  101,  787,  101,  101,  793,  101,  101,  101,
+      101,  161,  162,  788,  101,  163,  785,  101,  101,  101,
+      786,  101,  101,  101,  101,  810,  914,  796,  313,  165,
+      176,  101,  911,  790,  807,  790,  714,  825,  714,  825,
+      101,  101,  101,  805,  101,  814,  806,  644,  644,  644,
+      644,  644,  644,  644,  644,  644,  176,  910,  101,  101,
+      341,  812,  101,  760,  176,  760,  715,  101,  101,  176,
+      791,  809,  101,  644,  644,  644,  644,  644,  644,  644,
+      644,  644,  176,  792,  101,  101,  817,  890,  850,  101,
+
+      850,  171,  101,  101,  101,  101,  822,  811,  808,  646,
+      646,  646,  646,  646,  646,  646,  646,  646,  176,  101,
+      101,  821,  101,  101,  833,   76,  833,  850,  930,  850,
+      930,  901,   77,   78,  834,  646,  646,  646,  646,  646,
+      646,  646,  646,  646,  757,  757,  176,  757,  757,  757,
+      757,  757,  757,  757,  757,  757,  757,  757,  757,  757,
+      757,  764,  757,  765,  765,  765,  765,  765,  765,  765,
+      765,  765,  757,  757,  757,  757,  757,  757,  757,  766,
+      766,  766,  766,  766,  766,  766,  766,  766,  766,  766,
+      766,  766,  766,  766,  766,  766,  766,  766,  766,  766,
+
+      766,  766,  766,  766,  766,  766,  757,  769,  769,   76,
+      769,  968,  900,  968,  769,  769,   77,   78,  769,  895,
+      872,  769,  769,  769,  769,  769,  769,  769,  769,  768,
+      768,  871,  768,  768,  768,  768,  768,  768,  768,  768,
+      768,  768,  768,  768,  768,  768,  779,  768,  780,  780,
+      780,  780,  780,  780,  780,  780,  780,  768,  768,  768,
+      768,  768,  768,  768,  781,  781,  781,  781,  781,  781,
+      781,  781,  781,  781,  781,  781,  781,  781,  781,  781,
+      781,  781,  781,  781,  781,  781,  781,  781,  781,  781,
+      781,  768,  101,  101,  815,  101,  815,  101,  101,  819,
+
+      101,  818,  820,  813,  816,  101,  101,  101,  824,  101,
+      101,  101,  101,  101,  101,  101,  828,  101,  823,  825,
+      101,  825,  101,  101,  101,  101,  101,  101,  101,  101,
+      101,  827,  101,  101,  101,  101,  831,  101,  832,  829,
+      101,  101,  830,  101,  101,  836,  101,  836,  835,  101,
+      101,  101,  101,  101,  101,  870,  869,  101,  101,  233,
+      101,  747,  101,  749,  159,  845,  850,  101,  850,  826,
+      101,  101,  838,  749,  101,  748,  159,  101,  101,  101,
+      101,  160,  837,  749,  868,  749,  159,  849,  101,  851,
+      853,  101,  777,  852,  777,  101,  101,  101,  161,  162,
+
+      854,  101,  163,  778,  867,  101,  101,  866,  101,  856,
+      161,  162,  101,  101,  163,  313,  165,  101,  101,  101,
+      161,  162,  865,  855,  163,  101,  101,  313,  165,  862,
+      993,  857,  993, 1012,  101, 1012,  101,  313,  165,  843,
+      843,  176,  843,  843,  843,  843,  843,  843,  843,  843,
+      843,  843,  843,  843,  843,  843,  846,  843,  847,  847,
+      847,  847,  847,  847,  847,  847,  847,  843,  843,  843,
+      843,  843,  843,  843,  848,  848,  848,  848,  848,  848,
+      848,  848,  848,  848,  848,  848,  848,  848,  848,  848,
+      848,  848,  848,  848,  848,  848,  848,  848,  848,  848,
+
+      848,  843,  176,  232,  232,  232,  232,  232,  232,  232,
+      232,  232,  790,  101,  790,  101,  101,  101,  101,  337,
+      337,  337,  337,  337,  337,  337,  337,  337,  101,  861,
+      101,  101,  101,  864,  101,  874,  873,  101,  101,  875,
+      877,  101,  101,  101,  863,  101,  879,  880,  876,  859,
+      101,  878,  101,  101,  101,  101,  858,   72,  101,  101,
+      101,  881,  860,  815,  883,  815,  886,  101,  101,  101,
+      101,  884,  101,  816,  885,  101,  101,  101,  888,  101,
+      101,  101,  101,   68,  101,  101,  894,  887,  889,  101,
+      101,  101,  101,  101,  101,  893,  891,  101,  101,  101,
+
+      892,  101,  101,  833,  101,  833,  898,  101,  101,  836,
+      101,  836,  903,  834,  101,   68,  101,  905,  899,  101,
+      101,  101,  101,  101,  101,  896,  906,  101,  101,  101,
+      341,  101,  904,  101,  101,  101,  176,  101,  101,  101,
+      101,  907,  926,  176,  913,  101,  897,  176,  909,  176,
+      912,  101,  101,  908,  171,  101,  101,  101,  101,  101,
+      915,  101,  101,  924,  337,  337,  337,  337,  337,  337,
+      337,  337,  337,  101,  101,  101,  101,  101,  101,  101,
+      925,  927,  923,  101,  101,  883,  101,  101, 1026,  176,
+     1026,  101,  884,  101,  101,  885,  929,  928,  932,  883,
+
+      101,  101,  101,  101,  101,  933,  884,  101,  934,  885,
+      101,  935,  936,  101,  101,  101,  938,  101,  101,  101,
+      101,  941,  101,  101,  101,  171,  947,  101,  948,  101,
+      101,  101,  939,  944,  101,  101,  943,  101,  101,  101,
+      101,  101,  949,  101,  101,  101,  101,  951,  101,  950,
+      101,  841,  955,  964,  101,  101,  101,  101,  101,  101,
+      101,  101,  101,  954,  101,  101,  840,  101,  963,  965,
+      101,  101,  932,  101,  101,  101,  101,  967,  839,  933,
+      101,  101,  934,  966,  932,  969,  932,  969,  932,  101,
+      101,  933,  101,  884,  934,  933,  885,  101,  934,  101,
+
+      101,  971,  101,  101,  101,  101,  101,  101,  974,  975,
+      101,  101,  101,  979,  980,  804,  101,  101,  101,  101,
+      101,  101,  101,  983,  989,  101,  984,  101,  101,  101,
+      101,  101,  990,  101,  803,  101,  101,  992,  101,  991,
+      996,  101,  101,  994,  883,  994,  101,  101,  101,  101,
+      101,  884,  101,  101,  885,  101, 1005,  101,  101,  101,
+      101,  101,  802,  101, 1010, 1002,  101,  101,  101,  101,
+      101, 1013,  883, 1013,  101, 1006,  101,  101,  101,  884,
+     1011,  101,  885,  101,  101,  101, 1015,  101,  101, 1022,
+      101,  101,  101, 1021, 1025, 1027,  883, 1027,  101,  101,
+
+      101,  101,  801,  884,  101,  101,  885,  101,  101,  101,
+      800, 1029,  101, 1034,  101,  369,  101,  369,  101, 1036,
+     1036, 1039, 1036,  799,  798, 1042, 1036, 1036,  101,  101,
+     1036,  101, 1046, 1036, 1036, 1036, 1036, 1036, 1036, 1036,
+     1036, 1037,  883, 1037,  883,  101,  883,  101,  371,  884,
+      371,  884,  885,  884,  885,  883,  885,  797,  795, 1043,
+     1043,  932, 1044,  794,  101,  885, 1043, 1043,  933,  789,
+     1043,  934,   72, 1043, 1043, 1043, 1043, 1043, 1043, 1043,
+     1043,   57,   57,   57,   57,   57,   57,   57,   57,   57,
+       57,   57,   57,   57,   57,   57,   57,   57,   64,   64,
+
+       72,   64,   64,   64,   64,   64,   64,   64,   64,   64,
+       64,   64,   64,   64,   64,   67,   67,   68,   67,   67,
+       67,   67,   67,   67,   67,   67,   67,   67,   67,   67,
+       67,   67,   71,   71,   71,   71,   71,   71,   71,   71,
+       71,   71,   71,   71,   71,   71,   71,   71,   71,   75,
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
+       75,   75,   75,   75,   75,   75,   97,   97,  373,  386,
+      373,  386,   97,  101,  101,  101,  101,  101,  101,  101,
+      101,  101,  101,  170,  170,  170,  170,  170,  170,  170,
+      170,  170,  170,  170,  170,  170,  170,  170,  170,  170,
+
+      174,  174,  174,  174,  174,  174,  174,  174,  174,  174,
+       68,  174,  174,  174,  174,  772,  174,  181,  388,  181,
+      388,  181,  181,  390,  539,  390,  539,  181,  205,  205,
+      205,  205,  205,  205,  205,  205,  205,  205,  205,  205,
+      205,  205,  205,  205,  205,   87,  341,  341,   87,   87,
+      227,  227,  227,  227,  176,  227,  227,  171,  227,  227,
+      752,  227,  227,  751,  739,  227,  227,  315,  315,  315,
+      315,  315,  315,  315,  315,  315,  315,  315,  315,  315,
+      315,  315,  315,  315,  323,  541,  323,  541,  704,  323,
+      327,  327,  327,  327,  327,  327,  327,  327,  327,  327,
+
+      327,  327,  327,  327,  327,  327,  327,  332,  703,  332,
+      700,  332,  332,  333,  333,  333,  333,  333,  333,  333,
+      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
+      384,  699,  696,  384,  384,  251,  695,  251,  687,  674,
+       72,  667,  251,  663,  660,  520,  520,  632,  631,  630,
+      251,  499,  629,  499,  628,  591,  499,  505,  554,  505,
+      391,  505,  505,  634,  537,  634,  536,  535,  634,  640,
+      532,  640,  525,  640,  640,  661,  661,  524,  661,  661,
+      661,  661,  661,  661,  661,  661,  661,  661,  661,  661,
+      661,  661,  664,  664,  522,  664,  664,  664,  664,  664,
+
+      664,  664,  664,  664,  664,  664,  664,  664,  664,  666,
+      666,  521,  666,  666,  666,  666,  666,  666,  666,  666,
+      666,  666,  666,  666,  666,  666,  669,  669,  669,  669,
+      669,  669,  669,  669,  669,  669,  669,  669,  669,  669,
+      669,  669,  669,  671,  671,  671,  671,  671,  671,  671,
+      671,  671,  671,  671,  671,  671,  671,  671,  671,  671,
+      755,  755,  755,  755,  755,  755,  755,  755,  755,  755,
+      755,  755,  755,  755,  755,  755,  755,  757,  757,  757,
+      757,  757,  757,  757,  757,  757,  757,  757,  757,  757,
+      757,  757,  757,  757,   97,  341,   97,  176,   97,   97,
+
+      759,  759,  759,  759,  759,  759,  759,  759,  759,  759,
+      759,  759,  759,  759,  759,  759,  759,  768,  768,  176,
+      768,  768,  768,  768,  768,  768,  768,  768,  768,  768,
+      768,  768,  768,  768,  770,  770,  497,  770,  770,  770,
+      770,  770,  770,  770,  770,  770,  770,  770,  770,  770,
+      770,  771,  771,  496,  771,  771,  771,  771,  771,  771,
+      771,  771,  771,  771,  771,  771,  771,  771,  773,  773,
+      773,  773,  773,  773,  773,  773,  773,  773,  773,  773,
+      773,  773,  773,  773,  773,  774,  774,  774,  774,  774,
+      774,  774,  774,  774,  774,  774,  774,  774,  774,  774,
+
+      774,  774,  842,  842,  842,  842,  842,  842,  842,  842,
+      842,  842,  842,  842,  842,  842,  842,  842,  842,  843,
+      843,  843,  843,  843,  843,  843,  843,  843,  843,  843,
+      843,  843,  843,  843,  843,  843,  882,  882,  882,  882,
+      882,  882,  882,  882,  882,  882,  882,  882,  882,  882,
+      882,  882,  882,  931,  931,  931,  931,  931,  931,  931,
+      931,  931,  931,  931,  931,  931,  931,  931,  931,  931,
+      495,  494,  493,  492,  171,  320,  412,  393,  391,  383,
+      382,  381,  380,  379,  378,  377,  376,  375,  374,  367,
+      356,  355,  353,  352,  341,  176,  176,  171,  321,  319,
+
+      318,  171,  226,  225,  218,  217,  213,  212,   72,   72,
+       68,   68,  200,  199,  197,  196,  192, 1050,    7, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050
+    } ;
+
+static yyconst short int yy_chk[4083] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    2,    2,    2,    2,    9,   10,    9,
+       10,   11,   13,   11,   16,    2,    8,   12,   14,   15,
+       20,    2,    2,    2,    2,    2,    2,    2,    2,    2,
+        8,   12,   14,   15,   20,   17,   19,   18,   24,   18,
+
+        2,    2,   17,   17,    2,   23,   22,    9,   13,   25,
+       26,   11,   24,   16,   18, 1045,   27,    2,    2,   26,
+      203,    9,   13,   25,   19,   11,   47,   16,   47,   23,
+       27,   70,   74,   26,   17,   22,  160,   18,   19,  111,
+       18,   49,  160,   23,   51,   60,   18,   60,   17,   22,
+       51,   18,   21,   34,   21,   73,  111,   34,   51,   61,
+       34,   61,   62,   34,   62,  203,   63,   34,   63,   34,
+       21,   21,   21,   21,   21,   21,   21,   21,   21,   70,
+       49,   69,   51,   74,   30,   30,   30,   21, 1041,   73,
+      115,   21,   21,   21,   49,   30,   51,   75,   21,   92,
+
+       21,   21,   30,   30,   75,   75,   21,  115,  122,   92,
+       21,   28,   69,   28,   28,   28,   28,   28,   28,   28,
+       28,   28,   31,   31,   31,  122,   87,   87,   35,   31,
+      172, 1040,   35,   31,  112,   28,   31,   77,   35,   87,
+       31,   31,   35, 1038,   77,   77,   31,   90,  112,   28,
+       29,  112,   29,   29,   29,   29,   29,   29,   29,   29,
+       29,   91,   90,   37,  172,   32,   32,   37,   32,  116,
+       29,   29,   32,   37,   29,   32,   91,   37,   32,  150,
+       29,  116,   32,   32,   33,   33,  116,   29,   29,   76,
+       76,   76,  120,  150,   33,  120,   33,   76,   76,   33,
+
+       33,   33,   33,   36,   36,  126,   33,   36,  173,  120,
+       38,   36,   36,   36,   38,   39,   40,   36,   38,   39,
+       40,  204,  126,   39,   38,   40,   40,   40,   38,   39,
+       40,   41,   42,   39,  164,   41,   42, 1033,  109,   41,
+      109,  164,   42,   56,  178,   41,   42,   56,   41,   41,
+       43,   41,  358,   56,   43,  109,   97,   56,   43,  173,
+       44,   50,   50,   50,   43,   45,   43,   44,   43,   43,
+       43,   44,   45,   50,   44,  204,   45,   44,  178,   45,
+       97,   54,   45,  135,   44,   54,  135,  358,   54,   45,
+       46,   54,   46,   46,   97,   54,   55,  110,   46,  360,
+
+      135,   50,  100,   55,   79,  149,  113,   55,  110,   80,
+       55,   79,   79,   55,  110,   50,   80,   80,  113,  113,
+       55,  190,  149,  113,  113,  100,  100,   46,   46,  100,
+       46,   46,   81,  119,   81,  100,  187,  360,   79,  100,
+      100,  114,  118,  114,   46,   46,   48,   48,   48,   48,
+      119,  119,  325,  118,   48,  187,  121,  190,  114,  118,
+       80,  146,  130,  124,   48,   48,   48,   48,   48,   48,
+       48,   48,   48,  121,  124,   81,  121,  130,  146,  130,
+      124,   81,  146,   48,   48,  161,   48,   48,   99,   99,
+       99,   99,   99,   99,   99,   99,   99,  325, 1031,  161,
+
+       48,   48,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   52,   52,   52,   52,   52,
+       52,   52,   52,   52,   52,   86,  102,   86,  101,  101,
+      102,  102,  101,  125,  102,  169,  144,  144,  101, 1030,
+      102,  169,  101,  101,  102,  102,  563,  125,  103,  103,
+      125,  132,  103,  144,  563,  104,  104,  132,  103,  104,
+
+       86,  103,  103,  103,   86,  104,   86,  188,  132,  104,
+      104,   86,  180,   86,   86,  175,  175,  175,  180,  133,
+     1028,  141,  127,   86,   96,   96,   96,   96,   96,   96,
+       96,   96,   96,  105,  105,  127,  133,  105,  141,  127,
+      188,  141,  133,  105,   96,   96,  252,  105,  105,  106,
+      106,  191,  179,  106,  107,  107,  357,   96,  107,  106,
+      131, 1024,  131,  142,  107,  154,  106,  106,  107,  107,
+      108,  142,  191,  154,  108,  108,  131,  131,  108,  131,
+      142, 1018,  154,  123,  108,  252,  201,  108,  108,  108,
+      117,  123,  117,  198,  128,  198,  128,  129,  123,  129,
+
+      123,  202,  123,  179,  134,  357,  117,  129,  117,  117,
+      117,  117,  117,  117,  117,  117,  117,  134,  136,  323,
+      137,  134,  140,  138, 1020,  323,  140,  139,  201,  128,
+      136,  343,  129,  137, 1018,  136,  138,  137,  139,  140,
+      138,  140,  143,  147,  139,  117,  128,  117,  128,  129,
+      143,  145,  202,  145,  147,  214,  143,  214,  148,  143,
+      147,  343,  151,  151,  148,  152,  344,  235,  145,  145,
+      145,  148,  153,  145,  151,  148,  153,  155,  152,  151,
+      156,  155,  152,  157,  235,  157,  157,  235,  156,  153,
+      158,  157,  158,  158,  155,  181,  192,  156,  158,  194,
+
+      186,  181,  166,  344,  166,  166,  182,  182,  182,  181,
+      166,  186,  193,  192,  194,  192,  194,  186,  186,  195,
+      157,  157,  336,  195,  157,  205,  193,  158,  158,  193,
+     1019,  158,  205,  205,  189, 1016,  195,  157,  157,  166,
+      166,  182,  208,  166,  158,  158,  189,  189,  324,  208,
+      208,  189,  189,  346,  324,  182,  166,  166,  168,  168,
+      168,  168,  206,  206,  206,  210,  168,  211,  336,  326,
+      206,  206,  210,  210,  211,  211,  168,  168,  168,  168,
+      168,  168,  168,  168,  168,  207,  207,  207,  215,  216,
+      215,  216,  346,  207,  207,  168,  168, 1014,  229,  168,
+
+      229,  243,  228,  228,  230,  231,  230,  231,  234,  237,
+      210,  239,  168,  168,  183,  228,  384,  384,  243,  234,
+      269,  211,  269,  326,  239,  234,  237,  237,  239,  384,
+      269,  183,  183,  183,  183,  183,  183,  183,  183,  183,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
+
+      184,  184,  184,  212,  236,  212,  238,  241,  240,  244,
+      354,  242,  354,  499,  212,  246, 1009,  241,  245,  499,
+      238,  240,  242,  238,  241,  240,  244,  244,  242,  236,
+      245,  247,  246,  245,  246,  245,  248,  250,  247,  249,
+      255,  250,  253,  253,  254,  256,  236,  248,  247,  256,
+      249,  254,  212,  248,  250,  260,  249,  255,  258,  253,
+      261,  254,  256,  257,  262,  257,  258,  259,  262,  259,
+      264,  265,  260,  260,  260,  258, 1076,  261,  263,  273,
+     1076,  262,  263,  265,  267, 1077,  267,  264,  265, 1077,
+      266,  268,  266,  257,  500,  263,  273,  259,  257,  273,
+
+      500,  257,  259,  257,  285,  268,  257,  266,  268,  330,
+      257,  271,  272,  257,  274,  257,  257,  257,  274,  259,
+      257,  285,  271,  272,  275,  276,  278,  276,  271,  272,
+      280,  274,  275,  279,  277,  276,  277,  279,  267,  282,
+      283,  275, 1008,  278,  277,  287,  278,  280,  281,  280,
+      279,  284,  281,  283,  330,  286,  282,  283,  287,  284,
+      276,  288,  287,  282,  359,  281, 1004, 1003,  284,  277,
+      289,  276,  286,  286,  288,  292,  289,  276,  288,  502,
+      277,  276,  288,  290,  293,  291,  277,  289,  291,  294,
+      277,  295,  292,  296,  290,  292,  291,  296,  298,  295,
+
+      290,  293,  291,  297,  293,  299,  294,  297,  295,  294,
+      296,  298,  299,  300,  301,  298,  359,  502,  303,  302,
+      297,  305,  299,  331,  309,  335,  348,  304,  305,  304,
+      300,  301,  300,  301,  302,  303,  302,  304,  305,  306,
+      307,  309,  308,  348,  310,  306,  332,  311, 1001,  311,
+      311,  566,  332,  307,  308,  311,  306,  307, 1000,  308,
+      332,  310,  304,  310,  347,  335,  312,  566,  312,  312,
+      328,  328,  328,  314,  312,  314,  314,  331,  342,  304,
+      345,  314,  342,  350,  311,  311,  351,  350,  311,  334,
+      334,  334,  349,  349,  347,  342,  397,  345,  361,  345,
+
+      350,  311,  311,  312,  312,  361,  361,  312,  362,  349,
+      314,  314, 1000,  397,  314,  362,  362,  394,  363,  351,
+      312,  312,  364,  999,  364,  363,  363,  314,  314,  322,
+      322,  322,  322,  364,  394,  394,  351,  322,  368,  368,
+      368,  368,  368,  368,  368,  368,  368,  322,  322,  322,
+      322,  322,  322,  322,  322,  322,  363,  367,  504,  367,
+      362,  391,  393,  391,  393,  395,  322,  322,  367,  395,
+      322,  369,  369,  369,  369,  369,  369,  369,  369,  369,
+      399,  400,  395,  322,  322,  337,  370,  370,  370,  370,
+      370,  370,  370,  370,  370,  634,  504,  399,  400,  512,
+
+      526,  634,  337,  337,  337,  337,  337,  337,  337,  337,
+      337,  371,  371,  371,  371,  371,  371,  371,  371,  371,
+      398,  401,  398,  337,  338,  372,  372,  372,  372,  372,
+      372,  372,  372,  372,  635,  526,  512,  398,  401,  401,
+      635,  338,  338,  338,  338,  338,  338,  338,  338,  338,
+      373,  373,  373,  373,  373,  373,  373,  373,  373,  402,
+      403,  405,  338,  341,  385,  385,  385,  385,  385,  385,
+      385,  385,  385,  997,  995,  405,  402,  403,  405,  988,
+      341,  341,  341,  341,  341,  341,  341,  341,  341,  386,
+      386,  386,  386,  386,  386,  386,  386,  386,  387,  387,
+
+      387,  387,  387,  387,  387,  387,  387,  388,  388,  388,
+      388,  388,  388,  388,  388,  388,  389,  389,  389,  389,
+      389,  389,  389,  389,  389,  390,  390,  390,  390,  390,
+      390,  390,  390,  390,  404,  406,  407,  408,  404,  409,
+      414,  977,  411,  409,  407,  415,  406,  410,  414,  413,
+      986,  404,  406,  407,  408,  411,  409,  414,  410,  411,
+      413,  419,  415,  415,  410,  416,  413,  416,  420,  421,
+      422,  985,  423,  424,  421,  419,  977,  424,  419,  425,
+      427,  428,  421,  428,  422,  420,  421,  422,  420,  423,
+      424,  982,  426,  424,  501,  430,  425,  427,  432,  426,
+
+      416,  427,  433,  425,  433,  978,  528,  434,  416,  426,
+      435,  428,  430,  438,  430,  432,  436,  416,  445,  440,
+      445,  439,  416,  417,  434,  417,  434,  435,  445,  439,
+      438,  844,  433,  436,  441,  436,  440,  433,  439,  440,
+      443,  447,  441,  442,  528,  444,  501,  444,  443,  442,
+      448,  441,  978,  417,  433,  447,  442,  443,  447,  981,
+      442,  417,  444,  417,  844,  976,  417,  448,  973,  449,
+      417,  449,  523,  417,  523,  452,  417,  417,  972,  449,
+      417,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+      431,  431,  452,  431,  431,  431,  431,  431,  431,  431,
+
+      431,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+      431,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+      431,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+      431,  431,  431,  431,  431,  431,  431,  431,  431,  431,
+      431,  431,  431,  431,  451,  453,  454,  455,  456,  457,
+      458,  630,  970,  630,  459,  962,  453,  454,  451,  462,
+      460,  451,  453,  454,  455,  456,  457,  458,  459,  461,
+      463,  459,  460,  461,  464,  465,  462,  460,  462,  467,
+      466,  468,  469,  470,  471,  472,  461,  463,  466,  463,
+      473,  464,  465,  474,  470,  474,  467,  466,  472,  469,
+
+      470,  471,  472,  475,  468,  476,  477,  473,  478,  479,
+      474,  483,  485,  480,  481,  484,  481,  486,  503,  484,
+      475,  468,  476,  506,  481,  478,  479,  480,  483,  485,
+      480,  477,  484,  487,  486,  488,  507,  487,  489,  488,
+      489,  489,  513,  505,  515,  758,  489,  518,  477,  505,
+      487,  960,  488,  490,  958,  490,  490,  505,  957,  516,
+      491,  490,  491,  491,  518,  513,  953,  515,  491,  514,
+      503,  511,  544,  511,  506,  489,  489,  514,  517,  489,
+      517,  511,  516,  542,  758,  507,  514,  542,  530,  544,
+      490,  490,  489,  489,  490,  530,  530,  491,  491,  952,
+
+      542,  491,  945,  531,  547,  942,  511,  490,  490,  511,
+      531,  531,  545,  517,  491,  491,  498,  498,  498,  498,
+      533,  547,  533,  511,  498,  641,  530,  545,  636,  545,
+      517,  533,  551,  650,  498,  498,  498,  498,  498,  498,
+      498,  498,  498,  546,  556,  546,  548,  549,  519,  551,
+      519,  549,  550,  498,  498,  556,  650,  498,  519,  548,
+      546,  556,  519,  548,  549,  550,  636,  641,  552,  550,
+      498,  498,  508,  538,  538,  538,  538,  538,  538,  538,
+      538,  538,  552,  519,  508,  552,  508,  940,  937,  508,
+      508,  508,  508,  508,  508,  508,  508,  508,  509,  921,
+
+      519,  539,  539,  539,  539,  539,  539,  539,  539,  539,
+      642,  642,  642,  920,  919,  509,  509,  509,  509,  509,
+      509,  509,  509,  509,  540,  540,  540,  540,  540,  540,
+      540,  540,  540,  569,  918,  553,  509,  510,  541,  541,
+      541,  541,  541,  541,  541,  541,  541,  917,  571,  510,
+      569,  510,  553,  553,  510,  510,  510,  510,  510,  510,
+      510,  510,  510,  543,  543,  571,  543,  543,  543,  543,
+      543,  543,  543,  543,  543,  543,  543,  543,  543,  543,
+      543,  543,  543,  543,  543,  543,  543,  543,  543,  543,
+      543,  543,  543,  543,  543,  543,  543,  543,  543,  543,
+
+      543,  543,  543,  543,  543,  543,  543,  543,  543,  543,
+      543,  543,  543,  543,  543,  543,  543,  543,  543,  543,
+      543,  543,  543,  543,  543,  543,  555,  557,  559,  558,
+      555,  558,  560,  559,  557,  570,  572,  573,  638,  560,
+      573,  579,  574,  555,  557,  559,  575,  577,  570,  560,
+      576,  576,  570,  572,  573,  572,  574,  575,  579,  574,
+      584,  578,  577,  575,  577,  578,  580,  576,  580,  586,
+      916,  586,  558,  655,  670,  655,  638,  584,  578,  583,
+      914,  670,  670,  588,  911,  589,  558,  582,  582,  582,
+      582,  582,  582,  582,  582,  582,  580,  585,  583,  586,
+
+      588,  580,  589,  590,  589,  592,  593,  592,  594,  593,
+      585,  590,  595,  596,  585,  583,  595,  910,  580,  597,
+      590,  598,  592,  593,  597,  594,  599,  608,  601,  595,
+      596,  600,  596,  600,  598,  602,  597,  602,  598,  601,
+      603,  605,  604,  599,  608,  601,  604,  606,  600,  605,
+      607,  603,  602,  610,  607,  611,  612,  603,  605,  604,
+      606,  609,  615,  947,  606,  609,  613,  607,  613,  616,
+      610,  640,  611,  612,  611,  619,  617,  640,  609,  615,
+      615,  618,  621,  613,  618,  640,  616,  622,  616,  617,
+      623,  624,  619,  617,  619,  628,  901,  628,  618,  621,
+
+      900,  947,  621,  656,  622,  628,  622,  623,  624,  625,
+      897,  625,  625,  632,  656,  632,  626,  625,  626,  626,
+      656,  649,  895,  632,  626,  649,  652,  632,  627,  890,
+      627,  627,  671,  628,  652,  647,  627,  647,  649,  671,
+      671,  672,  657,  652,  657,  647,  625,  625,  672,  672,
+      625,  678,  657,  626,  626,  677,  657,  626,  659,  679,
+      659,  872,  948,  625,  625,  627,  627,  870,  678,  627,
+      626,  626,  659,  647,  677,  869,  679,  674,  679,  674,
+      868,  867,  627,  627,  633,  633,  633,  633,  674,  680,
+      681,  677,  633,  676,  676,  676,  676,  676,  676,  676,
+
+      676,  676,  682,  683,  948,  866,  680,  681,  865,  681,
+      684,  685,  689,  685,  690,  686,  689,  693,  710,  682,
+      683,  633,  633,  686,  707,  633,  683,  684,  685,  689,
+      684,  690,  686,  694,  693,  710,  863,  694,  633,  633,
+      643,  707,  860,  688,  707,  688,  714,  825,  714,  825,
+      694,  705,  706,  705,  712,  716,  706,  643,  643,  643,
+      643,  643,  643,  643,  643,  643,  644,  859,  705,  706,
+      848,  712,  716,  760,  760,  760,  714,  709,  688,  843,
+      688,  709,  718,  644,  644,  644,  644,  644,  644,  644,
+      644,  644,  645,  688,  709,  688,  718,  825,  841,  718,
+
+      841,  842,  708,  711,  722,  723,  724,  711,  708,  645,
+      645,  645,  645,  645,  645,  645,  645,  645,  646,  708,
+      711,  722,  723,  724,  739,  774,  739,  850,  883,  850,
+      883,  840,  774,  774,  739,  646,  646,  646,  646,  646,
+      646,  646,  646,  646,  653,  653,  653,  653,  653,  653,
+      653,  653,  653,  653,  653,  653,  653,  653,  653,  653,
+      653,  653,  653,  653,  653,  653,  653,  653,  653,  653,
+      653,  653,  653,  653,  653,  653,  653,  653,  653,  653,
+      653,  653,  653,  653,  653,  653,  653,  653,  653,  653,
+      653,  653,  653,  653,  653,  653,  653,  653,  653,  653,
+
+      653,  653,  653,  653,  653,  653,  653,  662,  662,  775,
+      662,  930,  839,  930,  662,  662,  775,  775,  662,  834,
+      804,  662,  662,  662,  662,  662,  662,  662,  662,  675,
+      675,  803,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  675,  675,  675,  675,  675,  675,  675,  675,
+      675,  675,  713,  719,  717,  720,  717,  726,  721,  720,
+
+      725,  719,  721,  713,  717,  727,  728,  729,  726,  713,
+      719,  730,  720,  732,  726,  721,  733,  725,  725,  731,
+      734,  731,  727,  728,  729,  735,  737,  738,  730,  717,
+      732,  732,  736,  733,  741,  742,  736,  734,  737,  734,
+      740,  743,  735,  737,  738,  744,  717,  744,  740,  736,
+      746,  741,  742,  745,  731,  802,  801,  740,  743,  780,
+      761,  747,  781,  747,  747,  761,  767,  746,  767,  731,
+      745,  731,  745,  748,  763,  748,  748,  761,  780,  781,
+      744,  748,  744,  749,  800,  749,  749,  763,  783,  782,
+      783,  763,  777,  782,  777,  780,  784,  744,  747,  747,
+
+      784,  767,  747,  777,  799,  783,  782,  798,  785,  787,
+      748,  748,  792,  784,  748,  747,  747,  788,  767,  786,
+      749,  749,  797,  786,  749,  785,  787,  748,  748,  792,
+      968,  788,  968,  993,  788,  993,  786,  749,  749,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+      762,  762,  762,  762,  762,  762,  762,  762,  762,  762,
+
+      762,  762,  764,  779,  779,  779,  779,  779,  779,  779,
+      779,  779,  790,  793,  790,  791,  796,  805,  806,  764,
+      764,  764,  764,  764,  764,  764,  764,  764,  807,  791,
+      793,  808,  791,  796,  805,  806,  805,  810,  809,  807,
+      809,  811,  812,  813,  795,  807,  812,  813,  808,  790,
+      814,  810,  819,  817,  810,  809,  789,  773,  811,  812,
+      813,  814,  790,  815,  816,  815,  817,  814,  818,  819,
+      817,  816,  820,  815,  816,  821,  822,  824,  822,  826,
+      823,  827,  829,  772,  828,  818,  829,  818,  823,  820,
+      830,  831,  821,  822,  824,  828,  826,  823,  827,  829,
+
+      827,  828,  832,  833,  835,  833,  837,  830,  831,  836,
+      838,  836,  845,  833,  849,  771,  851,  851,  838,  832,
+      852,  835,  853,  837,  854,  835,  853,  838,  855,  845,
+      766,  849,  849,  851,  856,  857,  759,  852,  861,  853,
+      862,  854,  876,  757,  862,  855,  836,  846,  857,  756,
+      861,  856,  857,  856,  755,  861,  864,  862,  874,  876,
+      864,  879,  877,  874,  846,  846,  846,  846,  846,  846,
+      846,  846,  846,  864,  873,  874,  875,  878,  879,  877,
+      875,  877,  873,  880,  881,  882,  886,  887, 1012,  902,
+     1012,  873,  882,  875,  878,  882,  880,  878,  884,  885,
+
+      880,  881,  891,  886,  887,  884,  885,  888,  884,  885,
+      889,  888,  889,  892,  893,  894,  891,  896,  898,  891,
+      899,  896,  903,  904,  888,  754,  902,  889,  902,  906,
+      892,  893,  894,  899,  896,  898,  898,  899,  905,  903,
+      904,  907,  903,  908,  909,  915,  906,  908,  912,  905,
+      913,  752,  913,  924,  923,  905,  925,  926,  907,  927,
+      908,  909,  915,  912,  928,  912,  751,  913,  923,  926,
+      924,  923,  931,  925,  926,  929,  927,  929,  750,  931,
+      935,  928,  931,  928,  933,  932,  932,  932,  934,  936,
+      939,  933,  929,  932,  933,  934,  932,  935,  934,  938,
+
+      941,  938,  949,  951,  943,  944,  936,  939,  943,  944,
+      950,  963,  954,  949,  950,  704,  938,  941,  955,  949,
+      951,  943,  944,  954,  963,  965,  955,  950,  963,  954,
+      964,  966,  964,  967,  703,  955,  971,  967,  974,  966,
+      971,  975,  965,  969,  969,  969,  979,  964,  966,  980,
+      967,  969,  983,  971,  969,  974,  983,  984,  975,  989,
+      990,  992,  702,  979,  990,  979,  980,  991, 1002,  983,
+     1005,  994,  994,  994,  984,  984,  989,  990,  992,  994,
+      991, 1006,  994,  996,  991, 1002,  996, 1005, 1010, 1006,
+     1011, 1015, 1021, 1005, 1011, 1013, 1013, 1013, 1006, 1022,
+
+      996, 1025,  701, 1013, 1029, 1010, 1013, 1011, 1015, 1021,
+      700, 1015, 1034, 1022, 1042, 1069, 1022, 1069, 1025, 1026,
+     1026, 1029, 1026,  699,  698, 1034, 1026, 1026, 1039, 1034,
+     1026, 1042, 1039, 1026, 1026, 1026, 1026, 1026, 1026, 1026,
+     1026, 1027, 1027, 1027, 1036, 1039, 1043, 1046, 1070, 1027,
+     1070, 1036, 1027, 1043, 1036, 1037, 1043,  696,  692, 1037,
+     1037, 1044, 1037,  691, 1046, 1037, 1037, 1037, 1044,  687,
+     1037, 1044,  669, 1037, 1037, 1037, 1037, 1037, 1037, 1037,
+     1037, 1051, 1051, 1051, 1051, 1051, 1051, 1051, 1051, 1051,
+     1051, 1051, 1051, 1051, 1051, 1051, 1051, 1051, 1052, 1052,
+
+      668, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052, 1052,
+     1052, 1052, 1052, 1052, 1052, 1053, 1053,  667, 1053, 1053,
+     1053, 1053, 1053, 1053, 1053, 1053, 1053, 1053, 1053, 1053,
+     1053, 1053, 1054, 1054, 1054, 1054, 1054, 1054, 1054, 1054,
+     1054, 1054, 1054, 1054, 1054, 1054, 1054, 1054, 1054, 1055,
+     1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055,
+     1055, 1055, 1055, 1055, 1055, 1055, 1056, 1056, 1071, 1073,
+     1071, 1073, 1056, 1057, 1057, 1057, 1057, 1057, 1057, 1057,
+     1057, 1057, 1057, 1058, 1058, 1058, 1058, 1058, 1058, 1058,
+     1058, 1058, 1058, 1058, 1058, 1058, 1058, 1058, 1058, 1058,
+
+     1059, 1059, 1059, 1059, 1059, 1059, 1059, 1059, 1059, 1059,
+      666, 1059, 1059, 1059, 1059,  665, 1059, 1060, 1074, 1060,
+     1074, 1060, 1060, 1075, 1081, 1075, 1081, 1060, 1061, 1061,
+     1061, 1061, 1061, 1061, 1061, 1061, 1061, 1061, 1061, 1061,
+     1061, 1061, 1061, 1061, 1061, 1062,  654,  651, 1062, 1062,
+     1063, 1063, 1063, 1063,  639, 1063, 1063,  637, 1063, 1063,
+      631, 1063, 1063,  629,  614, 1063, 1063, 1064, 1064, 1064,
+     1064, 1064, 1064, 1064, 1064, 1064, 1064, 1064, 1064, 1064,
+     1064, 1064, 1064, 1064, 1065, 1082, 1065, 1082,  568, 1065,
+     1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066, 1066,
+
+     1066, 1066, 1066, 1066, 1066, 1066, 1066, 1067,  567, 1067,
+      565, 1067, 1067, 1068, 1068, 1068, 1068, 1068, 1068, 1068,
+     1068, 1068, 1068, 1068, 1068, 1068, 1068, 1068, 1068, 1068,
+     1072,  564,  562, 1072, 1072, 1078,  561, 1078,  554,  532,
+      529,  527, 1078,  524,  521,  520,  497,  496,  495,  494,
+     1078, 1079,  493, 1079,  492,  437, 1079, 1080,  412, 1080,
+      392, 1080, 1080, 1083,  383, 1083,  381,  374, 1083, 1084,
+      366, 1084,  356, 1084, 1084, 1085, 1085,  355, 1085, 1085,
+     1085, 1085, 1085, 1085, 1085, 1085, 1085, 1085, 1085, 1085,
+     1085, 1085, 1086, 1086,  353, 1086, 1086, 1086, 1086, 1086,
+
+     1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1086, 1087,
+     1087,  352, 1087, 1087, 1087, 1087, 1087, 1087, 1087, 1087,
+     1087, 1087, 1087, 1087, 1087, 1087, 1088, 1088, 1088, 1088,
+     1088, 1088, 1088, 1088, 1088, 1088, 1088, 1088, 1088, 1088,
+     1088, 1088, 1088, 1089, 1089, 1089, 1089, 1089, 1089, 1089,
+     1089, 1089, 1089, 1089, 1089, 1089, 1089, 1089, 1089, 1089,
+     1090, 1090, 1090, 1090, 1090, 1090, 1090, 1090, 1090, 1090,
+     1090, 1090, 1090, 1090, 1090, 1090, 1090, 1091, 1091, 1091,
+     1091, 1091, 1091, 1091, 1091, 1091, 1091, 1091, 1091, 1091,
+     1091, 1091, 1091, 1091, 1092,  340, 1092,  333, 1092, 1092,
+
+     1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
+     1093, 1093, 1093, 1093, 1093, 1093, 1093, 1094, 1094,  327,
+     1094, 1094, 1094, 1094, 1094, 1094, 1094, 1094, 1094, 1094,
+     1094, 1094, 1094, 1094, 1095, 1095,  321, 1095, 1095, 1095,
+     1095, 1095, 1095, 1095, 1095, 1095, 1095, 1095, 1095, 1095,
+     1095, 1096, 1096,  320, 1096, 1096, 1096, 1096, 1096, 1096,
+     1096, 1096, 1096, 1096, 1096, 1096, 1096, 1096, 1097, 1097,
+     1097, 1097, 1097, 1097, 1097, 1097, 1097, 1097, 1097, 1097,
+     1097, 1097, 1097, 1097, 1097, 1098, 1098, 1098, 1098, 1098,
+     1098, 1098, 1098, 1098, 1098, 1098, 1098, 1098, 1098, 1098,
+
+     1098, 1098, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099,
+     1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1100,
+     1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100,
+     1100, 1100, 1100, 1100, 1100, 1100, 1101, 1101, 1101, 1101,
+     1101, 1101, 1101, 1101, 1101, 1101, 1101, 1101, 1101, 1101,
+     1101, 1101, 1101, 1102, 1102, 1102, 1102, 1102, 1102, 1102,
+     1102, 1102, 1102, 1102, 1102, 1102, 1102, 1102, 1102, 1102,
+      319,  318,  317,  316,  315,  313,  251,  233,  232,  226,
+      225,  224,  223,  222,  221,  220,  219,  218,  217,  213,
+      200,  199,  197,  196,  185,  177,  174,  170,  165,  163,
+
+      162,  159,   94,   93,   89,   88,   84,   83,   72,   71,
+       68,   67,   66,   65,   59,   58,   53,    7, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
+     1050, 1050
+    } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "fortran.lex"
+#define INITIAL 0
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#define parameter 1
+
+#define character 2
+
+#line 38 "fortran.lex"
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+extern FILE * yyin;
+#define MAX_INCLUDE_DEPTH 30
+#define tabsize 6
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+int line_num_fortran=1;
+int line_num_fortran_common=1;
+int newlinef90 = 0;
+char *tmp;
+char tmpc;
+/******************************************************************************/
+/**************PETITS PB NON PREVUS *******************************************/
+/******************************************************************************/
+/* NEXTLINF77 un ligne fortran 77 peut commencer par -      &a=b or on        */
+/*            a prevu seulement       & a=b avec l'espace entre le symbole    */
+/*            de la 7eme et le debut de la ligne de commande                  */
+/*            le ! est aussi interdit comme symbole de la 7 eme colonne       */
+/*            Normalement NEXTLINEF77 \n+[ ]{5}[^ ]                           */
+/******************************************************************************/
+#define YY_USER_ACTION \
+        {\
+           if (firstpass == 0) \
+           {\
+              strcat(curbuf,yytext); \
+              strcpy(motparse,yytext);\
+              colnum = colnum + strlen(motparse);\
+              /*printf("motparse = %s %d\n",motparse,strlen(motparse)); */\
+              ECHO; \
+           }\
+           strcpy(motparse1,yytext);\
+        /*if ( firstpass == 1 ) 
+                      printf("yytext = %s %d\n",yytext,strlen(yytext));*/\
+        }
+#line 1714 "fortran.yy.c"
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO(( void ));
+#else
+extern int yywrap YY_PROTO(( void ));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO(( void ));
+#else
+static int input YY_PROTO(( void ));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/* Just try to get by without declaring the routines.  This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+	if ( yy_current_buffer->yy_is_interactive ) \
+		{ \
+		int c = '*', n; \
+		for ( n = 0; n < max_size && \
+			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+			buf[n] = (char) c; \
+		if ( c == '\n' ) \
+			buf[n++] = (char) c; \
+		if ( c == EOF && ferror( yyin ) ) \
+			YY_FATAL_ERROR( "input in flex scanner failed" ); \
+		result = n; \
+		} \
+	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+		  && ferror( yyin ) ) \
+		YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+	if ( yyleng > 0 ) \
+		yy_current_buffer->yy_at_bol = \
+				(yytext[yyleng - 1] == '\n'); \
+	YY_USER_ACTION
+
+YY_DECL
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp, *yy_bp;
+	register int yy_act;
+
+#line 101 "fortran.lex"
+
+
+#line 1871 "fortran.yy.c"
+
+	if ( yy_init )
+		{
+		yy_init = 0;
+
+#ifdef YY_USER_INIT
+		YY_USER_INIT;
+#endif
+
+		if ( ! yy_start )
+			yy_start = 1;	/* first start state */
+
+		if ( ! yyin )
+			yyin = stdin;
+
+		if ( ! yyout )
+			yyout = stdout;
+
+		if ( ! yy_current_buffer )
+			yy_current_buffer =
+				yy_create_buffer( yyin, YY_BUF_SIZE );
+
+		yy_load_buffer_state();
+		}
+
+	while ( 1 )		/* loops until end-of-file is reached */
+		{
+		yy_cp = yy_c_buf_p;
+
+		/* Support of yytext. */
+		*yy_cp = yy_hold_char;
+
+		/* yy_bp points to the position in yy_ch_buf of the start of
+		 * the current run.
+		 */
+		yy_bp = yy_cp;
+
+		yy_current_state = yy_start;
+		yy_current_state += YY_AT_BOL();
+yy_match:
+		do
+			{
+			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+			if ( yy_accept[yy_current_state] )
+				{
+				yy_last_accepting_state = yy_current_state;
+				yy_last_accepting_cpos = yy_cp;
+				}
+			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+				{
+				yy_current_state = (int) yy_def[yy_current_state];
+				if ( yy_current_state >= 1051 )
+					yy_c = yy_meta[(unsigned int) yy_c];
+				}
+			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+			++yy_cp;
+			}
+		while ( yy_base[yy_current_state] != 4019 );
+
+yy_find_action:
+		yy_act = yy_accept[yy_current_state];
+		if ( yy_act == 0 )
+			{ /* have to back up */
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			yy_act = yy_accept[yy_current_state];
+			}
+
+		YY_DO_BEFORE_ACTION;
+
+
+do_action:	/* This label is used only to access EOF actions. */
+
+
+		switch ( yy_act )
+	{ /* beginning of action switch */
+			case 0: /* must back up */
+			/* undo the effects of YY_DO_BEFORE_ACTION */
+			*yy_cp = yy_hold_char;
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 103 "fortran.lex"
+return TOK_DEBUT;
+	YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 104 "fortran.lex"
+return TOK_FIN;
+	YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 105 "fortran.lex"
+return TOK_OMP;
+	YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 106 "fortran.lex"
+return TOK_DOLLAR;
+	YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 108 "fortran.lex"
+{return TOK_REAL8;}
+	YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 109 "fortran.lex"
+{return TOK_SUBROUTINE;}
+	YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 110 "fortran.lex"
+{return TOK_PROGRAM;}
+	YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 111 "fortran.lex"
+{return TOK_ALLOCATE;}
+	YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 112 "fortran.lex"
+{return TOK_DEALLOCATE;}
+	YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 113 "fortran.lex"
+{return TOK_RESULT;}
+	YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 114 "fortran.lex"
+{return TOK_FUNCTION;}
+	YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 115 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
+	YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 116 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
+	YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 117 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
+	YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 118 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
+	YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 119 "fortran.lex"
+return TOK_INCLUDE;
+	YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 120 "fortran.lex"
+{
+                            strcpy(yylval.na,yytext);
+                            tmpc = input();
+                            unput(tmpc);
+                            if ( (
+                               tmpc >= 'a' && tmpc <= 'z'
+                                  ) || (
+                               tmpc >= 'A' && tmpc <= 'Z'
+                               )  )
+                               {
+                                  return TOK_USE;
+                               }
+                               else
+                               {
+                                  return TOK_NAME;
+                               }
+                         }
+	YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 137 "fortran.lex"
+{return TOK_REWIND;}
+	YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 138 "fortran.lex"
+return TOK_IMPLICIT;
+	YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 139 "fortran.lex"
+return TOK_NONE;
+	YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 140 "fortran.lex"
+return TOK_CALL;
+	YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 141 "fortran.lex"
+return TOK_TRUE;
+	YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 142 "fortran.lex"
+return TOK_FALSE;
+	YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 143 "fortran.lex"
+{return TOK_POINT_TO;}
+	YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 144 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_DASTER;}
+	YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 145 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_EQ;}
+	YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 146 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_GT;}
+	YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 147 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_GE;}
+	YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 148 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_LT;}
+	YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 149 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_LE;}
+	YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 150 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_NE;}
+	YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 151 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_NOT;}
+	YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 152 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_OR;}
+	YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 153 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_XOR;}
+	YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 154 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_AND;}
+	YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 155 "fortran.lex"
+{return TOK_MODULE;}
+	YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 156 "fortran.lex"
+{return TOK_DOWHILE;}
+	YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 157 "fortran.lex"
+return TOK_ENDMODULE;
+	YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 158 "fortran.lex"
+return TOK_ENDDO;
+	YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 159 "fortran.lex"
+{return TOK_PLAINDO;}
+	YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 160 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_REAL;}
+	YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 161 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_INTEGER;}
+	YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 162 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_LOGICAL;}
+	YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 163 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CHARACTER;}
+	YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 164 "fortran.lex"
+{return TOK_ALLOCATABLE;}
+	YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 165 "fortran.lex"
+return TOK_CLOSE;
+	YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 166 "fortran.lex"
+return TOK_INQUIRE;
+	YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 167 "fortran.lex"
+{return TOK_DIMENSION;}
+	YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 168 "fortran.lex"
+return TOK_PAUSE;
+	YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 169 "fortran.lex"
+return TOK_EQUIVALENCE;
+	YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 170 "fortran.lex"
+return TOK_STOP;
+	YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 171 "fortran.lex"
+return TOK_WHERE;
+	YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 172 "fortran.lex"
+return TOK_ENDWHERE;
+	YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 173 "fortran.lex"
+return TOK_ELSEWHERE;
+	YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 174 "fortran.lex"
+{return TOK_COMPLEX;}
+	YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 175 "fortran.lex"
+{return TOK_CONTAINS;}
+	YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 176 "fortran.lex"
+{return TOK_ONLY;}
+	YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 177 "fortran.lex"
+{return TOK_PARAMETER;}
+	YY_BREAK
+case 59:
+YY_RULE_SETUP
+#line 178 "fortran.lex"
+{return TOK_RECURSIVE;}
+	YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 179 "fortran.lex"
+{return TOK_COMMON;}
+	YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 180 "fortran.lex"
+{return TOK_GLOBAL;}
+	YY_BREAK
+case 62:
+YY_RULE_SETUP
+#line 181 "fortran.lex"
+{return TOK_EXTERNAL;}
+	YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 182 "fortran.lex"
+{return TOK_INTENT;}
+	YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 183 "fortran.lex"
+{return TOK_POINTER;}
+	YY_BREAK
+case 65:
+YY_RULE_SETUP
+#line 184 "fortran.lex"
+{return TOK_OPTIONAL;}
+	YY_BREAK
+case 66:
+YY_RULE_SETUP
+#line 185 "fortran.lex"
+{return TOK_SAVE;}
+	YY_BREAK
+case 67:
+YY_RULE_SETUP
+#line 186 "fortran.lex"
+{return TOK_TYPE;}
+	YY_BREAK
+case 68:
+YY_RULE_SETUP
+#line 187 "fortran.lex"
+{return TOK_TYPEPAR;}
+	YY_BREAK
+case 69:
+YY_RULE_SETUP
+#line 188 "fortran.lex"
+{return TOK_STAT;}
+	YY_BREAK
+case 70:
+YY_RULE_SETUP
+#line 189 "fortran.lex"
+{return TOK_ENDTYPE;}
+	YY_BREAK
+case 71:
+YY_RULE_SETUP
+#line 190 "fortran.lex"
+return TOK_OPEN;
+	YY_BREAK
+case 72:
+YY_RULE_SETUP
+#line 191 "fortran.lex"
+return TOK_RETURN;
+	YY_BREAK
+case 73:
+YY_RULE_SETUP
+#line 192 "fortran.lex"
+return TOK_EXIT;
+	YY_BREAK
+case 74:
+YY_RULE_SETUP
+#line 193 "fortran.lex"
+return TOK_PRINT;
+	YY_BREAK
+case 75:
+YY_RULE_SETUP
+#line 194 "fortran.lex"
+{return TOK_PROCEDURE;}
+	YY_BREAK
+case 76:
+YY_RULE_SETUP
+#line 195 "fortran.lex"
+{return TOK_READ;}
+	YY_BREAK
+case 77:
+YY_RULE_SETUP
+#line 196 "fortran.lex"
+{return TOK_NAMELIST;}
+	YY_BREAK
+case 78:
+YY_RULE_SETUP
+#line 197 "fortran.lex"
+{return TOK_WRITE;}
+	YY_BREAK
+case 79:
+YY_RULE_SETUP
+#line 198 "fortran.lex"
+{return TOK_TARGET;}
+	YY_BREAK
+case 80:
+YY_RULE_SETUP
+#line 199 "fortran.lex"
+{return TOK_PUBLIC;}
+	YY_BREAK
+case 81:
+YY_RULE_SETUP
+#line 200 "fortran.lex"
+{return TOK_PRIVATE;}
+	YY_BREAK
+case 82:
+YY_RULE_SETUP
+#line 201 "fortran.lex"
+{return TOK_IN;}
+	YY_BREAK
+case 83:
+YY_RULE_SETUP
+#line 202 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_DATA;}
+	YY_BREAK
+case 84:
+YY_RULE_SETUP
+#line 203 "fortran.lex"
+return TOK_CONTINUE;
+	YY_BREAK
+case 85:
+YY_RULE_SETUP
+#line 204 "fortran.lex"
+{return TOK_PLAINGOTO;}
+	YY_BREAK
+case 86:
+YY_RULE_SETUP
+#line 205 "fortran.lex"
+{return TOK_OUT;}
+	YY_BREAK
+case 87:
+YY_RULE_SETUP
+#line 206 "fortran.lex"
+{return TOK_INOUT;}
+	YY_BREAK
+case 88:
+YY_RULE_SETUP
+#line 207 "fortran.lex"
+{return TOK_INTRINSIC;}
+	YY_BREAK
+case 89:
+YY_RULE_SETUP
+#line 208 "fortran.lex"
+{return TOK_THEN;}
+	YY_BREAK
+case 90:
+YY_RULE_SETUP
+#line 209 "fortran.lex"
+{return TOK_ELSEIF;}
+	YY_BREAK
+case 91:
+YY_RULE_SETUP
+#line 210 "fortran.lex"
+{return TOK_ELSE;}
+	YY_BREAK
+case 92:
+YY_RULE_SETUP
+#line 211 "fortran.lex"
+{return TOK_ENDIF;}
+	YY_BREAK
+case 93:
+YY_RULE_SETUP
+#line 212 "fortran.lex"
+{return TOK_LOGICALIF;}
+	YY_BREAK
+case 94:
+YY_RULE_SETUP
+#line 213 "fortran.lex"
+{return TOK_SUM;}
+	YY_BREAK
+case 95:
+YY_RULE_SETUP
+#line 214 "fortran.lex"
+{return TOK_MAX;}
+	YY_BREAK
+case 96:
+YY_RULE_SETUP
+#line 215 "fortran.lex"
+{return TOK_TANH;}
+	YY_BREAK
+case 97:
+YY_RULE_SETUP
+#line 216 "fortran.lex"
+{return TOK_MAXVAL;}
+	YY_BREAK
+case 98:
+YY_RULE_SETUP
+#line 217 "fortran.lex"
+{return TOK_TRIM;}
+	YY_BREAK
+case 99:
+YY_RULE_SETUP
+#line 218 "fortran.lex"
+{return TOK_SQRT;}
+	YY_BREAK
+case 100:
+YY_RULE_SETUP
+#line 219 "fortran.lex"
+{return TOK_SELECTCASE;}
+	YY_BREAK
+case 101:
+YY_RULE_SETUP
+#line 220 "fortran.lex"
+{return TOK_CASE;}
+	YY_BREAK
+case 102:
+YY_RULE_SETUP
+#line 221 "fortran.lex"
+{return TOK_CASEDEFAULT;}
+	YY_BREAK
+case 103:
+YY_RULE_SETUP
+#line 222 "fortran.lex"
+{return TOK_ENDSELECT;}
+	YY_BREAK
+case 104:
+YY_RULE_SETUP
+#line 223 "fortran.lex"
+{return TOK_FILE;}
+	YY_BREAK
+case 105:
+YY_RULE_SETUP
+#line 224 "fortran.lex"
+{return TOK_END;}
+	YY_BREAK
+case 106:
+YY_RULE_SETUP
+#line 225 "fortran.lex"
+{return TOK_ERR;}
+	YY_BREAK
+case 107:
+YY_RULE_SETUP
+#line 226 "fortran.lex"
+{return TOK_EXIST;}
+	YY_BREAK
+case 108:
+YY_RULE_SETUP
+#line 227 "fortran.lex"
+{return TOK_MIN;}
+	YY_BREAK
+case 109:
+YY_RULE_SETUP
+#line 228 "fortran.lex"
+{return TOK_INT;}
+	YY_BREAK
+case 110:
+YY_RULE_SETUP
+#line 229 "fortran.lex"
+{return TOK_NINT;}
+	YY_BREAK
+case 111:
+YY_RULE_SETUP
+#line 230 "fortran.lex"
+{return TOK_FLOAT;}
+	YY_BREAK
+case 112:
+YY_RULE_SETUP
+#line 231 "fortran.lex"
+{return TOK_EXP;}
+	YY_BREAK
+case 113:
+YY_RULE_SETUP
+#line 232 "fortran.lex"
+{return TOK_COS;}
+	YY_BREAK
+case 114:
+YY_RULE_SETUP
+#line 233 "fortran.lex"
+{return TOK_COSH;}
+	YY_BREAK
+case 115:
+YY_RULE_SETUP
+#line 234 "fortran.lex"
+{return TOK_ACOS;}
+	YY_BREAK
+case 116:
+YY_RULE_SETUP
+#line 235 "fortran.lex"
+{return TOK_SIN;}
+	YY_BREAK
+case 117:
+YY_RULE_SETUP
+#line 236 "fortran.lex"
+{return TOK_SINH;}
+	YY_BREAK
+case 118:
+YY_RULE_SETUP
+#line 237 "fortran.lex"
+{return TOK_ASIN;}
+	YY_BREAK
+case 119:
+YY_RULE_SETUP
+#line 238 "fortran.lex"
+{return TOK_LOG;}
+	YY_BREAK
+case 120:
+YY_RULE_SETUP
+#line 239 "fortran.lex"
+{return TOK_TAN;}
+	YY_BREAK
+case 121:
+YY_RULE_SETUP
+#line 240 "fortran.lex"
+{return TOK_ATAN;}
+	YY_BREAK
+case 122:
+YY_RULE_SETUP
+#line 241 "fortran.lex"
+{return TOK_CYCLE;}
+	YY_BREAK
+case 123:
+YY_RULE_SETUP
+#line 242 "fortran.lex"
+{return TOK_ABS;}
+	YY_BREAK
+case 124:
+YY_RULE_SETUP
+#line 243 "fortran.lex"
+{return TOK_MOD;}
+	YY_BREAK
+case 125:
+YY_RULE_SETUP
+#line 244 "fortran.lex"
+{return TOK_SIGN;}
+	YY_BREAK
+case 126:
+YY_RULE_SETUP
+#line 245 "fortran.lex"
+{return TOK_MINLOC;}
+	YY_BREAK
+case 127:
+YY_RULE_SETUP
+#line 246 "fortran.lex"
+{return TOK_MAXLOC;}
+	YY_BREAK
+case 128:
+YY_RULE_SETUP
+#line 247 "fortran.lex"
+{return TOK_MINVAL;}
+	YY_BREAK
+case 129:
+YY_RULE_SETUP
+#line 248 "fortran.lex"
+{return TOK_INTERFACE;}
+	YY_BREAK
+case 130:
+YY_RULE_SETUP
+#line 249 "fortran.lex"
+{return TOK_BACKSPACE;}
+	YY_BREAK
+case 131:
+YY_RULE_SETUP
+#line 250 "fortran.lex"
+{return TOK_ENDINTERFACE;}
+	YY_BREAK
+case 132:
+YY_RULE_SETUP
+#line 251 "fortran.lex"
+{return TOK_LEFTAB;}
+	YY_BREAK
+case 133:
+YY_RULE_SETUP
+#line 252 "fortran.lex"
+{return TOK_RIGHTAB;}
+	YY_BREAK
+case 134:
+YY_RULE_SETUP
+#line 253 "fortran.lex"
+{return TOK_FORMAT;}
+	YY_BREAK
+case 135:
+YY_RULE_SETUP
+#line 254 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
+	YY_BREAK
+case 136:
+YY_RULE_SETUP
+#line 255 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
+	YY_BREAK
+case 137:
+YY_RULE_SETUP
+#line 256 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_SLASH;}
+	YY_BREAK
+case 138:
+YY_RULE_SETUP
+#line 257 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_DSLASH;}
+	YY_BREAK
+case 139:
+YY_RULE_SETUP
+#line 258 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
+	YY_BREAK
+case 140:
+YY_RULE_SETUP
+#line 259 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
+	YY_BREAK
+case 141:
+YY_RULE_SETUP
+#line 260 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
+	YY_BREAK
+case 142:
+YY_RULE_SETUP
+#line 261 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
+	YY_BREAK
+case 143:
+YY_RULE_SETUP
+#line 262 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_NAME;}
+	YY_BREAK
+case 144:
+YY_RULE_SETUP
+#line 263 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CSTREAL;}
+	YY_BREAK
+case 145:
+YY_RULE_SETUP
+#line 264 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
+	YY_BREAK
+case 146:
+YY_RULE_SETUP
+#line 265 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
+	YY_BREAK
+case 147:
+*yy_cp = yy_hold_char; /* undo effects of setting up yytext */
+yy_c_buf_p = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 266 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CSTREAL;}
+	YY_BREAK
+case 148:
+YY_RULE_SETUP
+#line 267 "fortran.lex"
+{strcpy(yylval.na,yytext);return TOK_CSTINT;}
+	YY_BREAK
+case 149:
+YY_RULE_SETUP
+#line 268 "fortran.lex"
+{}
+	YY_BREAK
+case 150:
+YY_RULE_SETUP
+#line 269 "fortran.lex"
+{return TOK_QUOTE;}
+	YY_BREAK
+case 151:
+YY_RULE_SETUP
+#line 270 "fortran.lex"
+{}
+	YY_BREAK
+case 152:
+YY_RULE_SETUP
+#line 271 "fortran.lex"
+{strcpy(yylval.na,yytext);return (int) *yytext;}
+	YY_BREAK
+case 153:
+YY_RULE_SETUP
+#line 272 "fortran.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 154:
+YY_RULE_SETUP
+#line 273 "fortran.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 155:
+YY_RULE_SETUP
+#line 274 "fortran.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 156:
+YY_RULE_SETUP
+#line 275 "fortran.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 157:
+YY_RULE_SETUP
+#line 276 "fortran.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 158:
+YY_RULE_SETUP
+#line 277 "fortran.lex"
+{colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
+	YY_BREAK
+case 159:
+*yy_cp = yy_hold_char; /* undo effects of setting up yytext */
+yy_c_buf_p = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 278 "fortran.lex"
+
+	YY_BREAK
+case 160:
+YY_RULE_SETUP
+#line 279 "fortran.lex"
+{if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
+	YY_BREAK
+case 161:
+YY_RULE_SETUP
+#line 280 "fortran.lex"
+
+	YY_BREAK
+case 162:
+YY_RULE_SETUP
+#line 281 "fortran.lex"
+{colnum=colnum-1+tabsize;}
+	YY_BREAK
+case 163:
+YY_RULE_SETUP
+#line 282 "fortran.lex"
+;
+	YY_BREAK
+case 164:
+YY_RULE_SETUP
+#line 283 "fortran.lex"
+{line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
+	YY_BREAK
+case 165:
+YY_RULE_SETUP
+#line 284 "fortran.lex"
+{line_num_fortran++;line_num_fortran_common++;colnum=0;}
+	YY_BREAK
+case 166:
+YY_RULE_SETUP
+#line 285 "fortran.lex"
+{
+                           convert2lower(motparse1);
+                           if ( strncasecmp(motparse1,"contains",8) == 0 )
+                           {
+                              return TOK_CONTAINS;
+                           }
+                           else
+                           {
+                              colnum=0;line_num_fortran++;line_num_fortran_common++;
+                             if ( !strcasecmp(motparse1,"C$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                           }
+                         }
+	YY_BREAK
+case 167:
+YY_RULE_SETUP
+#line 298 "fortran.lex"
+{
+                             colnum = 0;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                          }
+	YY_BREAK
+case 168:
+YY_RULE_SETUP
+#line 303 "fortran.lex"
+{
+                             colnum = 0;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                          }
+	YY_BREAK
+case 169:
+YY_RULE_SETUP
+#line 308 "fortran.lex"
+ECHO;
+	YY_BREAK
+#line 2842 "fortran.yy.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(parameter):
+case YY_STATE_EOF(character):
+	yyterminate();
+
+	case YY_END_OF_BUFFER:
+		{
+		/* Amount of text matched not including the EOB char. */
+		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
+
+		/* Undo the effects of YY_DO_BEFORE_ACTION. */
+		*yy_cp = yy_hold_char;
+		YY_RESTORE_YY_MORE_OFFSET
+
+		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
+			{
+			/* We're scanning a new file or input source.  It's
+			 * possible that this happened because the user
+			 * just pointed yyin at a new source and called
+			 * yylex().  If so, then we have to assure
+			 * consistency between yy_current_buffer and our
+			 * globals.  Here is the right place to do so, because
+			 * this is the first action (other than possibly a
+			 * back-up) that will match for the new input source.
+			 */
+			yy_n_chars = yy_current_buffer->yy_n_chars;
+			yy_current_buffer->yy_input_file = yyin;
+			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+			}
+
+		/* Note that here we test for yy_c_buf_p "<=" to the position
+		 * of the first EOB in the buffer, since yy_c_buf_p will
+		 * already have been incremented past the NUL character
+		 * (since all states make transitions on EOB to the
+		 * end-of-buffer state).  Contrast this with the test
+		 * in input().
+		 */
+		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			{ /* This was really a NUL. */
+			yy_state_type yy_next_state;
+
+			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+			yy_current_state = yy_get_previous_state();
+
+			/* Okay, we're now positioned to make the NUL
+			 * transition.  We couldn't have
+			 * yy_get_previous_state() go ahead and do it
+			 * for us because it doesn't know how to deal
+			 * with the possibility of jamming (and we don't
+			 * want to build jamming into it because then it
+			 * will run more slowly).
+			 */
+
+			yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+			yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+			if ( yy_next_state )
+				{
+				/* Consume the NUL. */
+				yy_cp = ++yy_c_buf_p;
+				yy_current_state = yy_next_state;
+				goto yy_match;
+				}
+
+			else
+				{
+				yy_cp = yy_c_buf_p;
+				goto yy_find_action;
+				}
+			}
+
+		else switch ( yy_get_next_buffer() )
+			{
+			case EOB_ACT_END_OF_FILE:
+				{
+				yy_did_buffer_switch_on_eof = 0;
+
+				if ( yywrap() )
+					{
+					/* Note: because we've taken care in
+					 * yy_get_next_buffer() to have set up
+					 * yytext, we can now set up
+					 * yy_c_buf_p so that if some total
+					 * hoser (like flex itself) wants to
+					 * call the scanner after we return the
+					 * YY_NULL, it'll still work - another
+					 * YY_NULL will get returned.
+					 */
+					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+					yy_act = YY_STATE_EOF(YY_START);
+					goto do_action;
+					}
+
+				else
+					{
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+					}
+				break;
+				}
+
+			case EOB_ACT_CONTINUE_SCAN:
+				yy_c_buf_p =
+					yytext_ptr + yy_amount_of_matched_text;
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_match;
+
+			case EOB_ACT_LAST_MATCH:
+				yy_c_buf_p =
+				&yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_find_action;
+			}
+		break;
+		}
+
+	default:
+		YY_FATAL_ERROR(
+			"fatal flex scanner internal error--no action found" );
+	} /* end of action switch */
+		} /* end of scanning one token */
+	} /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ *	EOB_ACT_LAST_MATCH -
+ *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ *	EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+	{
+	register char *dest = yy_current_buffer->yy_ch_buf;
+	register char *source = yytext_ptr;
+	register int number_to_move, i;
+	int ret_val;
+
+	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+		YY_FATAL_ERROR(
+		"fatal flex scanner internal error--end of buffer missed" );
+
+	if ( yy_current_buffer->yy_fill_buffer == 0 )
+		{ /* Don't try to fill the buffer, so this is an EOF. */
+		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+			{
+			/* We matched a single character, the EOB, so
+			 * treat this as a final EOF.
+			 */
+			return EOB_ACT_END_OF_FILE;
+			}
+
+		else
+			{
+			/* We matched some text prior to the EOB, first
+			 * process it.
+			 */
+			return EOB_ACT_LAST_MATCH;
+			}
+		}
+
+	/* Try to read more data. */
+
+	/* First move last chars to start of buffer. */
+	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+	for ( i = 0; i < number_to_move; ++i )
+		*(dest++) = *(source++);
+
+	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+		/* don't do the read, it's not guaranteed to return an EOF,
+		 * just force an EOF
+		 */
+		yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+	else
+		{
+		int num_to_read =
+			yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+		while ( num_to_read <= 0 )
+			{ /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+			YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+			/* just a shorter name for the current buffer */
+			YY_BUFFER_STATE b = yy_current_buffer;
+
+			int yy_c_buf_p_offset =
+				(int) (yy_c_buf_p - b->yy_ch_buf);
+
+			if ( b->yy_is_our_buffer )
+				{
+				int new_size = b->yy_buf_size * 2;
+
+				if ( new_size <= 0 )
+					b->yy_buf_size += b->yy_buf_size / 8;
+				else
+					b->yy_buf_size *= 2;
+
+				b->yy_ch_buf = (char *)
+					/* Include room in for 2 EOB chars. */
+					yy_flex_realloc( (void *) b->yy_ch_buf,
+							 b->yy_buf_size + 2 );
+				}
+			else
+				/* Can't grow it, we don't own it. */
+				b->yy_ch_buf = 0;
+
+			if ( ! b->yy_ch_buf )
+				YY_FATAL_ERROR(
+				"fatal error - scanner input buffer overflow" );
+
+			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+			num_to_read = yy_current_buffer->yy_buf_size -
+						number_to_move - 1;
+#endif
+			}
+
+		if ( num_to_read > YY_READ_BUF_SIZE )
+			num_to_read = YY_READ_BUF_SIZE;
+
+		/* Read in more data. */
+		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+			yy_n_chars, num_to_read );
+
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	if ( yy_n_chars == 0 )
+		{
+		if ( number_to_move == YY_MORE_ADJ )
+			{
+			ret_val = EOB_ACT_END_OF_FILE;
+			yyrestart( yyin );
+			}
+
+		else
+			{
+			ret_val = EOB_ACT_LAST_MATCH;
+			yy_current_buffer->yy_buffer_status =
+				YY_BUFFER_EOF_PENDING;
+			}
+		}
+
+	else
+		ret_val = EOB_ACT_CONTINUE_SCAN;
+
+	yy_n_chars += number_to_move;
+	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+	return ret_val;
+	}
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp;
+
+	yy_current_state = yy_start;
+	yy_current_state += YY_AT_BOL();
+
+	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+		{
+		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+		if ( yy_accept[yy_current_state] )
+			{
+			yy_last_accepting_state = yy_current_state;
+			yy_last_accepting_cpos = yy_cp;
+			}
+		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+			{
+			yy_current_state = (int) yy_def[yy_current_state];
+			if ( yy_current_state >= 1051 )
+				yy_c = yy_meta[(unsigned int) yy_c];
+			}
+		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+		}
+
+	return yy_current_state;
+	}
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ *	next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+	{
+	register int yy_is_jam;
+	register char *yy_cp = yy_c_buf_p;
+
+	register YY_CHAR yy_c = 1;
+	if ( yy_accept[yy_current_state] )
+		{
+		yy_last_accepting_state = yy_current_state;
+		yy_last_accepting_cpos = yy_cp;
+		}
+	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+		{
+		yy_current_state = (int) yy_def[yy_current_state];
+		if ( yy_current_state >= 1051 )
+			yy_c = yy_meta[(unsigned int) yy_c];
+		}
+	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+	yy_is_jam = (yy_current_state == 1050);
+
+	return yy_is_jam ? 0 : yy_current_state;
+	}
+
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput( int c, register char *yy_bp )
+#else
+static void yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+#endif
+	{
+	register char *yy_cp = yy_c_buf_p;
+
+	/* undo effects of setting up yytext */
+	*yy_cp = yy_hold_char;
+
+	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+		{ /* need to shift things up to make room */
+		/* +2 for EOB chars. */
+		register int number_to_move = yy_n_chars + 2;
+		register char *dest = &yy_current_buffer->yy_ch_buf[
+					yy_current_buffer->yy_buf_size + 2];
+		register char *source =
+				&yy_current_buffer->yy_ch_buf[number_to_move];
+
+		while ( source > yy_current_buffer->yy_ch_buf )
+			*--dest = *--source;
+
+		yy_cp += (int) (dest - source);
+		yy_bp += (int) (dest - source);
+		yy_current_buffer->yy_n_chars =
+			yy_n_chars = yy_current_buffer->yy_buf_size;
+
+		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+			YY_FATAL_ERROR( "flex scanner push-back overflow" );
+		}
+
+	*--yy_cp = (char) c;
+
+
+	yytext_ptr = yy_bp;
+	yy_hold_char = *yy_cp;
+	yy_c_buf_p = yy_cp;
+	}
+#endif	/* ifndef YY_NO_UNPUT */
+
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+	{
+	int c;
+
+	*yy_c_buf_p = yy_hold_char;
+
+	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+		{
+		/* yy_c_buf_p now points to the character we want to return.
+		 * If this occurs *before* the EOB characters, then it's a
+		 * valid NUL; if not, then we've hit the end of the buffer.
+		 */
+		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			/* This was really a NUL. */
+			*yy_c_buf_p = '\0';
+
+		else
+			{ /* need more input */
+			int offset = yy_c_buf_p - yytext_ptr;
+			++yy_c_buf_p;
+
+			switch ( yy_get_next_buffer() )
+				{
+				case EOB_ACT_LAST_MATCH:
+					/* This happens because yy_g_n_b()
+					 * sees that we've accumulated a
+					 * token and flags that we need to
+					 * try matching the token before
+					 * proceeding.  But for input(),
+					 * there's no matching to consider.
+					 * So convert the EOB_ACT_LAST_MATCH
+					 * to EOB_ACT_END_OF_FILE.
+					 */
+
+					/* Reset buffer status. */
+					yyrestart( yyin );
+
+					/* fall through */
+
+				case EOB_ACT_END_OF_FILE:
+					{
+					if ( yywrap() )
+						return EOF;
+
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+#ifdef __cplusplus
+					return yyinput();
+#else
+					return input();
+#endif
+					}
+
+				case EOB_ACT_CONTINUE_SCAN:
+					yy_c_buf_p = yytext_ptr + offset;
+					break;
+				}
+			}
+		}
+
+	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
+	*yy_c_buf_p = '\0';	/* preserve yytext */
+	yy_hold_char = *++yy_c_buf_p;
+
+	yy_current_buffer->yy_at_bol = (c == '\n');
+
+	return c;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+	{
+	if ( ! yy_current_buffer )
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+	yy_init_buffer( yy_current_buffer, input_file );
+	yy_load_buffer_state();
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+	{
+	if ( yy_current_buffer == new_buffer )
+		return;
+
+	if ( yy_current_buffer )
+		{
+		/* Flush out information for old buffer. */
+		*yy_c_buf_p = yy_hold_char;
+		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	yy_current_buffer = new_buffer;
+	yy_load_buffer_state();
+
+	/* We don't actually know whether we did this switch during
+	 * EOF (yywrap()) processing, but the only time this flag
+	 * is looked at is after yywrap() is called, so it's safe
+	 * to go ahead and always set it.
+	 */
+	yy_did_buffer_switch_on_eof = 1;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state( void )
+#else
+void yy_load_buffer_state()
+#endif
+	{
+	yy_n_chars = yy_current_buffer->yy_n_chars;
+	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+	yyin = yy_current_buffer->yy_input_file;
+	yy_hold_char = *yy_c_buf_p;
+	}
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_buf_size = size;
+
+	/* yy_ch_buf has to be 2 characters longer than the size given because
+	 * we need to put in 2 end-of-buffer characters.
+	 */
+	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
+	if ( ! b->yy_ch_buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_is_our_buffer = 1;
+
+	yy_init_buffer( b, file );
+
+	return b;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+	{
+	if ( ! b )
+		return;
+
+	if ( b == yy_current_buffer )
+		yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+	if ( b->yy_is_our_buffer )
+		yy_flex_free( (void *) b->yy_ch_buf );
+
+	yy_flex_free( (void *) b );
+	}
+
+
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+	{
+	yy_flush_buffer( b );
+
+	b->yy_input_file = file;
+	b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+	b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+	b->yy_is_interactive = 0;
+#else
+	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+#endif
+#endif
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+	{
+	if ( ! b )
+		return;
+
+	b->yy_n_chars = 0;
+
+	/* We always need two end-of-buffer characters.  The first causes
+	 * a transition to the end-of-buffer state.  The second causes
+	 * a jam in that state.
+	 */
+	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+	b->yy_buf_pos = &b->yy_ch_buf[0];
+
+	b->yy_at_bol = 1;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	if ( b == yy_current_buffer )
+		yy_load_buffer_state();
+	}
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	if ( size < 2 ||
+	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
+	     base[size-1] != YY_END_OF_BUFFER_CHAR )
+		/* They forgot to leave room for the EOB's. */
+		return 0;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
+	b->yy_buf_pos = b->yy_ch_buf = base;
+	b->yy_is_our_buffer = 0;
+	b->yy_input_file = 0;
+	b->yy_n_chars = b->yy_buf_size;
+	b->yy_is_interactive = 0;
+	b->yy_at_bol = 1;
+	b->yy_fill_buffer = 0;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	yy_switch_to_buffer( b );
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+	{
+	int len;
+	for ( len = 0; yy_str[len]; ++len )
+		;
+
+	return yy_scan_bytes( yy_str, len );
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+	{
+	YY_BUFFER_STATE b;
+	char *buf;
+	yy_size_t n;
+	int i;
+
+	/* Get memory for full buffer, including space for trailing EOB's. */
+	n = len + 2;
+	buf = (char *) yy_flex_alloc( n );
+	if ( ! buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+	for ( i = 0; i < len; ++i )
+		buf[i] = bytes[i];
+
+	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+	b = yy_scan_buffer( buf, n );
+	if ( ! b )
+		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+	/* It's okay to grow etc. this buffer, and we should throw it
+	 * away when we're done.
+	 */
+	b->yy_is_our_buffer = 1;
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+	{
+	if ( yy_start_stack_ptr >= yy_start_stack_depth )
+		{
+		yy_size_t new_size;
+
+		yy_start_stack_depth += YY_START_STACK_INCR;
+		new_size = yy_start_stack_depth * sizeof( int );
+
+		if ( ! yy_start_stack )
+			yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+		else
+			yy_start_stack = (int *) yy_flex_realloc(
+					(void *) yy_start_stack, new_size );
+
+		if ( ! yy_start_stack )
+			YY_FATAL_ERROR(
+			"out of memory expanding start-condition stack" );
+		}
+
+	yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+	BEGIN(new_state);
+	}
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+	{
+	if ( --yy_start_stack_ptr < 0 )
+		YY_FATAL_ERROR( "start-condition stack underflow" );
+
+	BEGIN(yy_start_stack[yy_start_stack_ptr]);
+	}
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+	{
+	return yy_start_stack[yy_start_stack_ptr - 1];
+	}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+	{
+	(void) fprintf( stderr, "%s\n", msg );
+	exit( YY_EXIT_FAILURE );
+	}
+
+
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		yytext[yyleng] = yy_hold_char; \
+		yy_c_buf_p = yytext + n; \
+		yy_hold_char = *yy_c_buf_p; \
+		*yy_c_buf_p = '\0'; \
+		yyleng = n; \
+		} \
+	while ( 0 )
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+	{
+	register int i;
+	for ( i = 0; i < n; ++i )
+		s1[i] = s2[i];
+	}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+	{
+	register int n;
+	for ( n = 0; s[n]; ++n )
+		;
+
+	return n;
+	}
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+	{
+	return (void *) malloc( size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+	{
+	/* The cast to (char *) in the following accommodates both
+	 * implementations that use char* generic pointers, and those
+	 * that use void* generic pointers.  It works with the latter
+	 * because both ANSI C and C++ allow castless assignment from
+	 * any pointer type to void*, and deal with argument conversions
+	 * as though doing an assignment.
+	 */
+	return (void *) realloc( (char *) ptr, size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+	{
+	free( ptr );
+	}
+
+#if YY_MAIN
+int main()
+	{
+	yylex();
+	return 0;
+	}
+#endif
+#line 308 "fortran.lex"
+
+
+fortranerror(char *s)
+{
+   if (!strcasecmp(curfile,mainfile))
+   {
+      printf("%s line %d, fichier %s\n",s,line_num_fortran,curfile);
+   }
+   else
+   {
+      printf("%s line %d, fichier %s\n",s,line_num_fortran_common,curfile);
+   }
+}
+
+int fortranwrap()
+{
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.lex
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.lex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.lex	(revision 4536)
@@ -0,0 +1,324 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+%x parameter
+%s character
+%{
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+extern FILE * yyin;
+#define MAX_INCLUDE_DEPTH 30
+#define tabsize 6
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+int line_num_fortran=1;
+int line_num_fortran_common=1;
+int newlinef90 = 0;
+char *tmp;
+char tmpc;
+/******************************************************************************/
+/**************PETITS PB NON PREVUS *******************************************/
+/******************************************************************************/
+/* NEXTLINF77 un ligne fortran 77 peut commencer par -      &a=b or on        */
+/*            a prevu seulement       & a=b avec l'espace entre le symbole    */
+/*            de la 7eme et le debut de la ligne de commande                  */
+/*            le ! est aussi interdit comme symbole de la 7 eme colonne       */
+/*            Normalement NEXTLINEF77 \n+[ ]{5}[^ ]                           */
+/******************************************************************************/
+#define YY_USER_ACTION \
+        {\
+           if (firstpass == 0) \
+           {\
+              strcat(curbuf,yytext); \
+              strcpy(motparse,yytext);\
+              colnum = colnum + strlen(motparse);\
+              /*printf("motparse = %s %d\n",motparse,strlen(motparse)); */\
+              ECHO; \
+           }\
+           strcpy(motparse1,yytext);\
+        /*if ( firstpass == 1 ) 
+                      printf("yytext = %s %d\n",yytext,strlen(yytext));*/\
+        }
+%}
+AGRIFDEB "Agrif_debut"
+AGRIFFIN "Agrif_fin"
+REAL8 "real*8"[ \t]*"(a-h,o-z)"
+NOTTREAT Agrif_do_not_treat
+ENDNOTTREAT Agrif_end_do_not_treat
+
+NIMPORTEQUOI .
+SLASH "/"
+DSLASH "/"[ \t]*"/"
+NAME [a-zA-Z\_][a-zA-Z0-9\_]*
+DIGIT [0-9]+
+INT {DIGIT}
+EXPONENT e[-+]?{DIGIT}
+DEXPONENT d[-+]?{DIGIT}
+QEXPONENT q[-+]?{DIGIT}
+REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT}
+REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT}
+REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT}
+ENDFUNCTION end[ \t]*function
+DOUBLEPRECISION double[ \t]*precision
+DOUBLECOMPLEX double[ \t]*complex
+
+COMMENTAIRESFORTRAN77 ^([Cc*](([ \t]*\n)|([^AaHhOo\n]{NIMPORTEQUOI}*\n)))
+COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n)
+COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*)
+NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]*
+NEXTLINEF77 \n[ \t]{5}("&"|"+"|"$"|"*"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"."|"#")
+%%
+
+^C${AGRIFDEB}            return TOK_DEBUT;
+^C${AGRIFFIN}            return TOK_FIN;
+^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
+^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
+
+{REAL8}                 {return TOK_REAL8;}
+subroutine              {return TOK_SUBROUTINE;}
+program                 {return TOK_PROGRAM;}
+allocate                {return TOK_ALLOCATE;}
+deallocate              {return TOK_DEALLOCATE;}
+result                  {return TOK_RESULT;}
+function                {return TOK_FUNCTION;}
+end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
+end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
+end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
+end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
+include                  return TOK_INCLUDE;
+^[ \t]*use[ ]+           {
+                            strcpy(yylval.na,yytext);
+                            tmpc = input();
+                            unput(tmpc);
+                            if ( (
+                               tmpc >= 'a' && tmpc <= 'z'
+                                  ) || (
+                               tmpc >= 'A' && tmpc <= 'Z'
+                               )  )
+                               {
+                                  return TOK_USE;
+                               }
+                               else
+                               {
+                                  return TOK_NAME;
+                               }
+                         }
+rewind                  {return TOK_REWIND;}
+implicit                 return TOK_IMPLICIT;
+none                     return TOK_NONE;
+call                     return TOK_CALL;
+.true.                   return TOK_TRUE;
+.false.                  return TOK_FALSE;
+\=\>                    {return TOK_POINT_TO;}
+\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
+\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
+\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
+\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
+\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
+\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
+\.[ \t]*ne\.            {strcpy(yylval.na,yytext);return TOK_NE;}
+\.[ \t]*not\.           {strcpy(yylval.na,yytext);return TOK_NOT;}
+\.[ \t]*or\.            {strcpy(yylval.na,yytext);return TOK_OR;}
+\.[ \t]*xor\.           {strcpy(yylval.na,yytext);return TOK_XOR;}
+\.[ \t]*and\.           {strcpy(yylval.na,yytext);return TOK_AND;}
+module                  {return TOK_MODULE;}
+do[ 0-9\t]*while           {return TOK_DOWHILE;}
+end[ \t]*module          return TOK_ENDMODULE;
+end[ \t]*do              return TOK_ENDDO;
+do                      {return TOK_PLAINDO;}
+real                    {strcpy(yylval.na,yytext);return TOK_REAL;}
+integer                 {strcpy(yylval.na,yytext);return TOK_INTEGER;}
+logical                 {strcpy(yylval.na,yytext);return TOK_LOGICAL;}
+character               {strcpy(yylval.na,yytext);return TOK_CHARACTER;}
+allocatable             {return TOK_ALLOCATABLE;}
+close                    return TOK_CLOSE;
+inquire                  return TOK_INQUIRE;
+dimension               {return TOK_DIMENSION;}
+pause                    return TOK_PAUSE;
+equivalence              return TOK_EQUIVALENCE;
+stop                     return TOK_STOP;
+where                    return TOK_WHERE;
+end[ \t]*where           return TOK_ENDWHERE;
+else[ \t]*where          return TOK_ELSEWHERE;
+complex                 {return TOK_COMPLEX;}
+^[ \t]*contains         {return TOK_CONTAINS;}
+only                    {return TOK_ONLY;}
+parameter               {return TOK_PARAMETER;}
+recursive               {return TOK_RECURSIVE;}
+common                  {return TOK_COMMON;}
+^[ \t]*global[ \t]+     {return TOK_GLOBAL;}
+external                {return TOK_EXTERNAL;}
+intent                  {return TOK_INTENT;}
+pointer                 {return TOK_POINTER;}
+optional                {return TOK_OPTIONAL;}
+save                    {return TOK_SAVE;}
+^[ \t]*type[ \t\,]+       {return TOK_TYPE;}
+^[ \t]*type[ \t]*\(     {return TOK_TYPEPAR;}
+stat                    {return TOK_STAT;}
+end[ \t]*type           {return TOK_ENDTYPE;}
+open                     return TOK_OPEN;
+return                   return TOK_RETURN;
+exit[^(]                 return TOK_EXIT;
+print                    return TOK_PRINT;
+module[ \t]*procedure   {return TOK_PROCEDURE;}
+read                    {return TOK_READ;}
+namelist                {return TOK_NAMELIST;}
+write                   {return TOK_WRITE;}
+target                  {return TOK_TARGET;}
+public                  {return TOK_PUBLIC;}
+private                 {return TOK_PRIVATE;}
+\([ \t]*in[ \t]*\)      {return TOK_IN;}
+^[ \t]*data[ \t]+       {strcpy(yylval.na,yytext);return TOK_DATA;}
+continue                 return TOK_CONTINUE;
+go[ \t]*to              {return TOK_PLAINGOTO;}
+\([ \t]*out[ \t]*\)     {return TOK_OUT;}
+\([ \t]*inout[ \t]*\)   {return TOK_INOUT;}
+intrinsic               {return TOK_INTRINSIC;}
+then                    {return TOK_THEN;}
+else[ \t]*if            {return TOK_ELSEIF;}
+else                    {return TOK_ELSE;}
+end[ \t]*if             {return TOK_ENDIF;}
+if[ \t]*\(              {return TOK_LOGICALIF;}
+sum[ \t]*\(             {return TOK_SUM;}
+max[ \t]*\(             {return TOK_MAX;}
+tanh                    {return TOK_TANH;}
+maxval                  {return TOK_MAXVAL;}
+trim                    {return TOK_TRIM;}
+sqrt\(                  {return TOK_SQRT;}
+select[ \t]*case        {return TOK_SELECTCASE;}
+^[ \t]*case[ \t]*\(     {return TOK_CASE;}
+^[ \t]*case[ \t]*default       {return TOK_CASEDEFAULT;}
+end[ \t]*select         {return TOK_ENDSELECT;}
+file[ \t]*\=            {return TOK_FILE;}
+end[ \t]*\=             {return TOK_END;}
+err[ \t]*\=             {return TOK_ERR;}
+exist[ \t]*\=           {return TOK_EXIST;}
+min[ \t]*\(             {return TOK_MIN;}
+int                     {return TOK_INT;}
+nint                    {return TOK_NINT;}
+float                   {return TOK_FLOAT;}
+exp                     {return TOK_EXP;}
+cos                     {return TOK_COS;}
+cosh                    {return TOK_COSH;}
+acos                    {return TOK_ACOS;}
+sin                     {return TOK_SIN;}
+sinh                    {return TOK_SINH;}
+asin                    {return TOK_ASIN;}
+log                     {return TOK_LOG;}
+tan                     {return TOK_TAN;}
+atan                    {return TOK_ATAN;}
+cycle                   {return TOK_CYCLE;}
+abs\(                   {return TOK_ABS;}
+mod                     {return TOK_MOD;}
+sign                    {return TOK_SIGN;}
+minloc                  {return TOK_MINLOC;}
+maxloc                  {return TOK_MAXLOC;}
+minval                  {return TOK_MINVAL;}
+interface               {return TOK_INTERFACE;}
+backspace               {return TOK_BACKSPACE;}
+end[ \t]*interface      {return TOK_ENDINTERFACE;}
+\({SLASH}               {return TOK_LEFTAB;}
+{SLASH}\)               {return TOK_RIGHTAB;}
+format[ \t]*\(({NIMPORTEQUOI}|{NEXTLINEF90}|{NEXTLINEF77})*\)  {return TOK_FORMAT;}
+{DOUBLEPRECISION}       {strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
+{DOUBLECOMPLEX}         {strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
+{SLASH}                 {strcpy(yylval.na,yytext);return TOK_SLASH;}
+DSLASH                  {strcpy(yylval.na,yytext);return TOK_DSLASH;}
+(\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
+(\')[^\n']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
+(\")[^\n]*(\")          {strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
+({NAME}{REAL})          {strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
+{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
+{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
+{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
+{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
+({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
+{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
+\$ {}
+\'|\"                   {return TOK_QUOTE;}
+\.                      {}
+;|\(|\)|:|\[|\]|\+|\-|\*|\% {strcpy(yylval.na,yytext);return (int) *yytext;}
+\,                      {return (int) *yytext;}
+\;                      {return (int) *yytext;}
+\=                      {return (int) *yytext;}
+\<                      {return (int) *yytext;}
+\>                      {return (int) *yytext;}
+\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
+^[ ]*$
+^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
+[ ]+
+[\t]+                   {colnum=colnum-1+tabsize;}
+[ \t]+ ;
+{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
+{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
+{COMMENTAIRESFORTRAN77} {
+                           convert2lower(motparse1);
+                           if ( strncasecmp(motparse1,"contains",8) == 0 )
+                           {
+                              return TOK_CONTAINS;
+                           }
+                           else
+                           {
+                              colnum=0;line_num_fortran++;line_num_fortran_common++;
+                             if ( !strcasecmp(motparse1,"C$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                           }
+                         }
+{COMMENTAIRESFORTRAN90}   {
+                             colnum = 0;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                          }
+{COMMENTAIRESFORTRAN90_2} {
+                             colnum = 0;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
+                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
+                          }
+%%
+
+fortranerror(char *s)
+{
+   if (!strcasecmp(curfile,mainfile))
+   {
+      printf("%s line %d, fichier %s\n",s,line_num_fortran,curfile);
+   }
+   else
+   {
+      printf("%s line %d, fichier %s\n",s,line_num_fortran_common,curfile);
+   }
+}
+
+int fortranwrap()
+{
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.y
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.y	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/fortran.y	(revision 4536)
@@ -0,0 +1,2523 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+%{
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "decl.h"
+extern int line_num_fortran;
+extern int line_num_fortran_common;
+char *tmp;
+char c_selectorname[LONGNOM];
+char ligne[LONGNOM];
+char identcopy[LONGNOM];
+int c_selectorgiven=0;
+int incom;
+listvar *curlistvar;
+typedim c_selectordim;
+listcouple *coupletmp;
+listdim *parcoursdim;
+int removeline=0;
+listvar *test;
+%}
+
+%union {
+       char      na[LONGNOM];
+       listdim  *d;
+       listvar  *l;
+       listnom  *ln;
+       listcouple  *lc;
+       typedim   dim1;
+       variable *v;
+       }
+
+%left ','
+%nonassoc ':'
+%right '='
+%left TOK_BINARY_OP
+%left EQV NEQV
+%left TOK_OR TOK_XOR
+%left TOK_AND
+%left TOK_NOT
+%nonassoc TOK_LT TOK_GT TOK_LE TOK_GE TOK_EQ TOK_NE
+%nonassoc TOK_UNARY_OP
+%left TOK_DSLASH
+%left '+' '-'
+%left '*' TOK_SLASH
+%right TOK_DASTER
+
+%token TOK_SEP
+%token TOK_NEXTLINE
+%token TOK_PARAMETER
+%token TOK_RESULT
+%token TOK_ONLY
+%token TOK_INCLUDE
+%token TOK_SUBROUTINE
+%token TOK_PROGRAM
+%token TOK_FUNCTION
+%token TOK_OMP
+%token TOK_DOLLAR
+%token TOK_FORMAT
+%token TOK_MAX
+%token TOK_TANH
+%token TOK_WHERE
+%token TOK_ELSEWHERE
+%token TOK_ENDWHERE
+%token TOK_MAXVAL
+%token TOK_TRIM
+%token TOK_SUM
+%token TOK_SQRT
+%token TOK_CASE
+%token TOK_SELECTCASE
+%token TOK_FILE
+%token TOK_END
+%token TOK_ERR
+%token TOK_DONOTTREAT
+%token TOK_ENDDONOTTREAT
+%token TOK_EXIST
+%token TOK_MIN
+%token TOK_INT
+%token TOK_FLOAT
+%token TOK_EXP
+%token TOK_COS
+%token TOK_COSH
+%token TOK_ACOS
+%token TOK_NINT
+%token TOK_CYCLE
+%token TOK_SIN
+%token TOK_SINH
+%token TOK_ASIN
+%token TOK_EQUIVALENCE
+%token TOK_BACKSPACE
+%token TOK_LOG
+%token TOK_TAN
+%token TOK_ATAN
+%token TOK_RECURSIVE
+%token TOK_ABS
+%token TOK_MOD
+%token TOK_SIGN
+%token TOK_MINLOC
+%token TOK_MAXLOC
+%token TOK_EXIT
+%token TOK_MINVAL
+%token TOK_PUBLIC
+%token TOK_PRIVATE
+%token TOK_ALLOCATABLE
+%token TOK_IN
+%token TOK_RETURN
+%token TOK_THEN
+%token TOK_ELSEIF
+%token TOK_ELSE
+%token TOK_ENDIF
+%token TOK_PRINT
+%token TOK_PLAINGOTO
+%token TOK_CONSTRUCTID
+%token TOK_LOGICALIF
+%token TOK_PLAINDO
+%token TOK_CONTAINS
+%token TOK_ENDDO
+%token TOK_MODULE
+%token TOK_ENDMODULE
+%token TOK_DOWHILE
+%token TOK_ALLOCATE
+%token TOK_OPEN
+%token TOK_CLOSE
+%token TOK_INQUIRE
+%token TOK_WRITE
+%token TOK_READ
+%token TOK_REWIND
+%token TOK_DEALLOCATE
+%token TOK_NULLIFY
+%token TOK_FIN
+%token TOK_DEBUT
+%token TOK_OUT
+%token TOK_INOUT
+%token TOK_DIMENSION
+%token TOK_ENDSELECT
+%token TOK_EXTERNAL
+%token TOK_INTENT
+%token TOK_INTRINSIC
+%token TOK_NAMELIST
+%token TOK_CASEDEFAULT
+%token TOK_OPTIONAL
+%token TOK_POINTER
+%token TOK_CONTINUE
+%token TOK_SAVE
+%token TOK_TARGET
+%token TOK_QUOTE
+%token TOK_IMPLICIT
+%token TOK_NONE
+%token TOK_CALL
+%token TOK_STAT
+%token TOK_POINT_TO
+%token TOK_COMMON
+%token TOK_GLOBAL
+%token TOK_INTERFACE
+%token TOK_ENDINTERFACE
+%token TOK_LEFTAB
+%token TOK_RIGHTAB
+%token TOK_PAUSE
+%token TOK_PROCEDURE
+%token TOK_STOP
+%token TOK_NAMEEQ
+%token TOK_REAL8
+%token <na> TOK_USE
+%token <na> TOK_DSLASH
+%token <na> TOK_DASTER
+%token <na> TOK_EQ
+%token <na> TOK_GT
+%token <na> TOK_LT
+%token <na> TOK_GE
+%token <na> TOK_NE
+%token <na> TOK_LE
+%token <na> TOK_OR
+%token <na> TOK_XOR
+%token <na> TOK_NOT
+%token <na> TOK_AND
+%token <na> TOK_TRUE
+%token <na> TOK_FALSE
+%token <na> TOK_LABEL
+%token <na> TOK_TYPE
+%token <na> TOK_TYPEPAR
+%token <na> TOK_ENDTYPE
+%token <na> TOK_REAL
+%token <na> TOK_INTEGER
+%token <na> TOK_LOGICAL
+%token <na> TOK_DOUBLEPRECISION
+%token <na> TOK_DOUBLEREAL
+%token <na> TOK_ENDSUBROUTINE
+%token <na> TOK_ENDFUNCTION
+%token <na> TOK_ENDPROGRAM
+%token <na> TOK_ENDUNIT
+%token <na> TOK_CHARACTER
+%token <na> TOK_CHAR_CONSTANT
+%token <na> TOK_CHAR_CUT
+%token <na> TOK_DATA
+%token <na> TOK_CHAR_INT
+%token <na> TOK_CHAR_MESSAGE
+%token <na> TOK_CSTREAL
+%token <na> TOK_CSTREALDP
+%token <na> TOK_CSTREALQP
+%token <na> TOK_SFREAL
+%token <na> TOK_COMPLEX
+%token <na> TOK_DOUBLECOMPLEX
+%token <na> TOK_NAME
+%token <na> TOK_NAME_CHAR
+%token <na> TOK_PROBTYPE  /* dimension of the problem                         */
+%token <na> TOK_INTERPTYPE/* kind of interpolation                            */
+%token <na> TOK_VARTYPE   /* posit ion of the grid variable on the cells of   */
+                          /*     the mesh                                     */
+%token <na> TOK_SLASH
+%token <na> TOK_BC        /* calculation of the boundary conditions           */
+%token <na> TOK_OP
+%token <na> TOK_CSTINT
+%token <na> TOK_COMMENT
+%token <na> TOK_FILENAME
+%token ','
+%token ';'
+%token ':'
+%token '('
+%token ')'
+%token '['
+%token ']'
+%token '!'
+%token '_'
+%token '<'
+%token '>'
+%type <l> dcl
+%type <l> after_type
+%type <l> dimension
+%type <l> paramlist
+%type <l> args
+%type <l> arglist
+%type <lc> only_list
+%type <lc> only_name
+%type <lc> rename_list
+%type <lc> rename_name
+%type <d> dims
+%type <d> dimlist
+%type <dim1> dim
+%type <v> paramitem
+%type <na> comblock
+%type <na> name_routine
+%type <na> begin_array
+%type <na> module_name
+%type <na> opt_name
+%type <na> clause
+%type <na> type
+%type <na> arg
+%type <na> typename
+%type <na> typespec
+%type <na> uexpr
+%type <na> minmaxlist
+%type <na> complex_const
+%type <na> lhs
+%type <na> simple_const
+%type <na> vec
+%type <na> outlist
+%type <na> out2
+%type <na> other
+%type <na> dospec
+%type <na> expr_data
+%type <na> beforefunctionuse
+%type <na> ident
+%type <na> structure_component
+%type <na> array_ele_substring_func_ref
+%type <na> funarglist
+%type <na> funarg
+%type <na> funargs
+%type <na> triplet
+%type <na> substring
+%type <na> string_constant
+%type <na> opt_substring
+%type <na> opt_expr
+%type <na> optexpr
+%type <na> datavallist
+%type <na> after_slash
+%type <na> after_equal
+%type <na> predefinedfunction
+%type <na> do_var
+%type <na> expr
+%type <na> word_endsubroutine
+%type <na> word_endfunction
+%type <na> word_endprogram
+%type <na> word_endunit
+%type <na> intent_spec
+%type <na> ubound
+%type <na> signe
+%type <na> opt_signe
+%type <na> operation
+%type <na> filename
+%type <na> proper_lengspec
+
+%left TOK_OP
+%%
+input :
+      | input line
+      ;
+line :  '\n' position
+      | thislabel suite_line_list
+      | TOK_COMMENT
+      | keyword cmnt writedeclar
+      | error writedeclar nulcurbuf
+                   {yyerrok;yyclearin;}
+      ;
+suite_line_list : suite_line
+      |   suite_line ';' suite_line_list
+      ;
+suite_line : entry fin_line/* subroutine, function, module                    */
+      | spec fin_line      /* declaration                                     */
+      | before_include filename fin_line
+                  {
+                     if (inmoduledeclare == 0 )
+                     {
+                        pos_end = setposcur();
+                        RemoveWordSET_0(fortranout,pos_curinclude,
+                                              pos_end-pos_curinclude);
+                     }
+                  }
+      | exec cmnt writedeclar /* if, do etc ...                               */
+      | instr fin_line    /* instruction ident  : do i = 1 ...                */
+      ;
+instr : ident ':'
+      ;
+fin_line : position cmnt
+      ;
+keyword : TOK_DONOTTREAT
+         {
+            /* we should ignore the declaration until the keyword             */
+            /*    TOK_ENDDONOTTREAT                                           */
+            couldaddvariable = 0 ;
+            RemoveWordCUR_0(fortranout,-20,20);
+         }
+      | TOK_ENDDONOTTREAT
+         {
+             couldaddvariable = 1 ;
+             RemoveWordCUR_0(fortranout,-24,24);
+          }
+      | TOK_OMP
+      | TOK_DOLLAR
+      ;
+position: {pos_cur = setposcur();}
+      ;
+thislabel:
+      | TOK_LABEL nulcurbuf
+      ;
+cmnt:
+      | TOK_COMMENT
+      ;
+incomment:
+                   {incom = 1;}
+      ;
+nulcurbuf:
+                   {if (incom !=1) {strcpy(curbuf,"");incom=0;}}
+      ;
+opt_recursive :
+      | TOK_RECURSIVE
+      ;
+entry:
+      | opt_recursive TOK_SUBROUTINE name_routine arglist
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$3);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
+                      Add_SubroutineArgument_Var_1($4);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(1);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            writeheadnewsub_0(1);
+                      }
+                      }
+                   }
+      | TOK_PROGRAM name_routine
+                   {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
+                      strcpy(subroutinename,$2);
+                      /* Common case                                          */
+                      insubroutinedeclare = 1;
+                      /* in the second step we should write the head of       */
+                      /*    the subroutine sub_loop_<subroutinename>          */
+                      writeheadnewsub_0(1);
+                   }
+      | TOK_FUNCTION name_routine arglist TOK_RESULT arglist1
+                   {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,$2);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1($3);
+                         strcpy(DeclType,"");
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            /* we should to list of the subroutine argument   */
+                            /* name of the function which has to be defined   */
+                            Add_SubroutineArgument_Var_1($3);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1($2);
+                            writeheadnewsub_0(2);
+                      }
+                   }
+      | TOK_FUNCTION name_routine arglist
+                   {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,$2);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1($3);
+                         strcpy(DeclType,"");
+                         Add_FunctionType_Var_1($2);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                            insubroutinedeclare = 1;
+                            /* we should to list of the subroutine argument   */
+                            /* name of the function which has to be defined   */
+                            Add_SubroutineArgument_Var_1($3);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1($2);
+                            writeheadnewsub_0(2);
+                      }
+                   }
+      | TOK_MODULE TOK_NAME
+                   {
+                      GlobalDeclaration = 0;
+                      strcpy(curmodulename,$2);
+                      strcpy(subroutinename,"");
+                      Add_NameOfModule_1($2);
+                      if ( inmoduledeclare == 0 )
+                      {
+                         /* To know if there are in the module declaration    */
+                         inmoduledeclare = 1;
+                         /* to know if a module has been met                  */
+                         inmodulemeet = 1;
+                         /* to know if we are after the keyword contains      */
+                         aftercontainsdeclare = 0 ;
+                      }
+                   }
+      ;
+name_routine : TOK_NAME
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,$1);strcpy(subroutinename,$1);
+                      }
+                   }
+writedeclar :
+      ;
+before_include : TOK_INCLUDE
+                   {
+                      pos_curinclude = setposcur()-9;
+                   }
+filename: TOK_CHAR_CONSTANT
+                   {
+                      if ( couldaddvariable == 1 ) Add_Include_1($1);
+                   }
+      ;
+arglist:           {
+                      if ( firstpass == 1 && couldaddvariable == 1) $$=NULL;
+                   }
+      | '(' ')'    {
+                      if ( firstpass == 1 && couldaddvariable == 1 ) $$=NULL;
+                   }
+      | '(' args ')'
+                   {
+                       if ( firstpass == 1 && couldaddvariable == 1 ) $$=$2;
+                   }
+      ;
+arglist1:
+      | '(' ')'
+      | '(' args ')'
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         Add_SubroutineArgument_Var_1($2);
+                      }
+                   }
+      ;
+args:arg           {
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar($1,NULL);
+                         curlistvar=insertvar(NULL,curvar);
+                         $$=settype("",curlistvar);
+                      }
+                   }
+      | args ',' arg
+                   {
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar($3,NULL);
+                         $$=insertvar($1,curvar);
+                      }
+                   }
+      ;
+arg: TOK_NAME      {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '*'        {if ( couldaddvariable == 1 ) strcpy($$,"*");}
+      ;
+spec: type after_type
+                   {
+                      if ( VarTypepar == 1 )
+                      {
+                         couldaddvariable = 1 ;
+                         VarTypepar = 0;
+                      }
+                   }
+      | TOK_TYPE opt_spec opt_sep opt_name
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         VarType = 1;
+                         couldaddvariable = 0 ;
+                      }
+                   }
+      | TOK_ENDTYPE opt_name
+                   {
+                      if ( VarType == 1 ) couldaddvariable = 1 ;
+                      VarType = 0;
+                      VarTypepar = 0;
+                   }
+      | TOK_POINTER list_couple
+      | before_parameter  '(' paramlist ')'
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($3);
+                         else Add_Parameter_Var_1($3);
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
+                   }
+      | before_parameter  paramlist
+                   {
+                     if ( couldaddvariable == 1 )
+                     {
+                        if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($2);
+                         else Add_Parameter_Var_1($2);
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
+                   }
+      | common
+      | save
+                  {
+                     pos_end = setposcur();
+                     RemoveWordSET_0(fortranout,pos_cursave,
+                                                pos_end-pos_cursave);
+                  }
+      | implicit
+      | dimension
+                  {
+                   /* if the variable is a parameter we can suppose that is   */
+                   /*    value is the same on each grid. It is not useless to */
+                   /*    create a copy of it on each grid                     */
+                      if ( couldaddvariable == 1 )
+                      {
+                         Add_Globliste_1($1);
+                         /* if variableparamlists has been declared in a      */
+                         /*    subroutine                                     */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            Add_Dimension_Var_1($1);
+                         }
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curdimension,
+                                                pos_end-pos_curdimension);
+                      }
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
+                      c_star = 0;
+                      InitialValueGiven = 0 ;
+                      strcpy(IntentSpec,"");
+                      VariableIsParameter =  0 ;
+                      Allocatabledeclare = 0 ;
+                      SaveDeclare = 0;
+                      pointerdeclare = 0;
+                      optionaldeclare = 0 ;
+                      dimsgiven=0;
+                      c_selectorgiven=0;
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
+                   }
+      | public
+      | private
+      | use_stat
+      | module_proc_stmt
+      | interface
+      | namelist
+      | TOK_BACKSPACE '(' expr ')'
+      | TOK_EXTERNAL opt_sep use_name_list
+      | TOK_INTRINSIC opt_sep use_intrinsic_list
+      | TOK_EQUIVALENCE list_expr_equi
+      | before_data data '\n'
+                   {
+                      /* we should remove the data declaration                */
+                      if ( couldaddvariable == 1 && aftercontainsdeclare == 0 )
+                      {
+                        pos_end = setposcur();
+                        RemoveWordSET_0(fortranout,pos_curdata,
+                                              pos_end-pos_curdata);
+                      }
+                  }
+      ;
+opt_spec :
+      | access_spec
+      {
+         PublicDeclare = 0 ;
+         PrivateDeclare = 0 ;
+      }
+      ;
+name_intrinsic : TOK_SUM
+      | TOK_TANH
+      | TOK_MAXVAL
+      | TOK_MIN
+      | TOK_MINVAL
+      | TOK_TRIM
+      | TOK_SQRT
+      | TOK_NINT
+      | TOK_FLOAT
+      | TOK_EXP
+      | TOK_COS
+      | TOK_COSH
+      | TOK_ACOS
+      | TOK_SIN
+      | TOK_SINH
+      | TOK_ASIN
+      | TOK_LOG
+      | TOK_TAN
+      | TOK_ATAN
+      | TOK_MOD
+      | TOK_SIGN
+      | TOK_MINLOC
+      | TOK_MAXLOC
+      | TOK_NAME
+      ;
+use_intrinsic_list : name_intrinsic
+      | use_intrinsic_list ',' name_intrinsic
+      ;
+list_couple : '(' list_expr ')'
+      | list_couple ',' '(' list_expr ')'
+      ;
+list_expr_equi : expr_equi
+      | list_expr_equi ',' expr_equi
+      ;
+expr_equi : '(' list_expr_equi1 ')'
+      ;
+list_expr_equi1 : ident dims
+      | list_expr_equi1 ',' ident dims
+      ;
+list_expr : expr
+      | list_expr ',' expr
+      ;
+opt_sep :
+      | ':' ':'
+      ;
+after_type : dcl nodimsgiven
+                   {
+                      /* if the variable is a parameter we can suppose that is*/
+                      /*    value is the same on each grid. It is not useless */
+                      /*    to create a copy of it on each grid               */
+                      if ( couldaddvariable == 1 )
+                      {
+                      pos_end = setposcur();
+                      RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                 pos_end-pos_cur_decl);
+                      if ( firstpass == 0 &&
+                           GlobalDeclaration == 0 &&
+                           insubroutinedeclare == 0 )
+                      {
+                         sprintf(ligne,"\n#include \"Module_Declar_%s.h\"\n"
+                                                                ,curmodulename);
+                         tofich(fortranout,ligne,1);
+                         sprintf (ligne, "Module_Declar_%s.h",curmodulename);
+                         module_declar = associate(ligne);
+                         sprintf (ligne, " ");
+                         tofich (module_declar, ligne,1);
+                         GlobalDeclaration = 1 ;
+                      }
+                         $$ = $1;
+                         Add_Globliste_1($1);
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($1);
+                         else
+                         {
+                            if ( pointerdeclare == 1 )
+                                                Add_Pointer_Var_From_List_1($1);
+                            Add_Parameter_Var_1($1);
+                         }
+
+                         /* if variables has been declared in a subroutine    */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                           Add_SubroutineDeclaration_Var_1($1);
+                         }
+                         /* If there are a SAVE declarations in module's      */
+                         /*    subroutines we should remove it from the       */
+                         /*    subroutines declaration and add it in the      */
+                         /*    global declarations                            */
+                         if ( aftercontainsdeclare == 1 &&
+                              SaveDeclare == 1 && firstpass == 1 )
+                         {
+                              if ( inmodulemeet == 0 ) Add_Save_Var_dcl_1($1);
+                              else  Add_SubroutineDeclarationSave_Var_1($1);
+                         }
+                      }
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
+                      c_star = 0;
+                      InitialValueGiven = 0 ;
+                      strcpy(IntentSpec,"");
+                      VariableIsParameter =  0 ;
+                      Allocatabledeclare = 0 ;
+                      SaveDeclare = 0;
+                      pointerdeclare = 0;
+                      optionaldeclare = 0 ;
+                      dimsgiven=0;
+                      c_selectorgiven=0;
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
+                   }
+      | before_function name_routine arglist
+                   {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
+                      strcpy(subroutinename,$2);
+                      if ( inmodulemeet == 1 )
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1($3);
+                         Add_FunctionType_Var_1($2);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                      else
+                      {
+                         insubroutinedeclare = 1;
+                         /* we should to list of the subroutine argument the  */
+                         /*    name of the function which has to be defined   */
+                         Add_SubroutineArgument_Var_1($3);
+                         Add_FunctionType_Var_1($2);
+                         /* in the second step we should write the head of    */
+                         /*    the subroutine sub_loop_<subroutinename>       */
+                         writeheadnewsub_0(2);
+                      }
+                   }
+      ;
+before_function : TOK_FUNCTION
+                   {
+                       functiondeclarationisdone = 1;
+                   }
+                   ;
+
+before_parameter : TOK_PARAMETER
+                   {
+                      VariableIsParameter = 1;
+                      pos_curparameter = setposcur()-9;
+                   }
+before_data : TOK_DATA
+                   {
+                      pos_curdata = setposcur()-strlen($1);
+                   }
+data: TOK_NAME TOK_SLASH datavallist TOK_SLASH
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",$3);
+                      Add_Data_Var_1($1,ligne);
+                      }
+                   }
+      | data opt_comma TOK_NAME TOK_SLASH datavallist TOK_SLASH
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",$5);
+                      Add_Data_Var_1($3,ligne);
+                      }
+                   }
+      | datanamelist TOK_SLASH datavallist TOK_SLASH
+                   {
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                       /*******************************************************/
+                   }
+      ;
+datavallist : expr_data
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,$1);
+                      }
+                   }
+      | expr_data ',' datavallist
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf($$,"%s,%s",$1,$3);
+                      }
+                   }
+      ;
+
+save:  before_save varsave
+      | before_save  comblock varsave
+      | save opt_comma comblock opt_comma varsave
+      | save ',' varsave
+      ;
+before_save : TOK_SAVE
+                  {
+                     pos_cursave = setposcur()-4;
+                  }
+      ;
+varsave:
+      | TOK_NAME dims
+                  {
+                     if ( couldaddvariable == 1 ) Add_Save_Var_1($1,$2);
+                  }
+      ;
+datanamelist : TOK_NAME
+      | TOK_NAME '(' expr ')'
+      | datanamelist ',' datanamelist
+      ;
+expr_data : opt_signe simple_const
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      | expr_data '+' expr_data
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s+%s",$1,$3);}
+      | expr_data '-' expr_data
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s-%s",$1,$3);}
+      | expr_data '*' expr_data
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s*%s",$1,$3);}
+      | expr_data '/' expr_data
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s/%s",$1,$3);}
+      ;
+opt_signe :
+                   {if ( couldaddvariable == 1 ) strcpy($$,"");}
+      | signe
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+namelist:  namelist_action after_namelist
+      ;
+namelist_action : TOK_NAMELIST  ident
+      | TOK_NAMELIST  comblock ident
+      | namelist_action opt_comma comblock opt_comma ident
+      | namelist_action ',' ident
+      ;
+after_namelist :
+      ;
+interface: TOK_INTERFACE opt_name
+      | TOK_ENDINTERFACE opt_name
+      ;
+before_dimension : TOK_DIMENSION
+                   {
+                      positioninblock=0;
+                      pos_curdimension = setposcur()-9;
+                   }
+
+dimension:  before_dimension opt_comma TOK_NAME dims lengspec
+      {
+         if ( couldaddvariable == 1 )
+         {
+            /*                                                                */
+            curvar=createvar($3,$4);
+            /*                                                                */
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar(NULL,curvar);
+            /*                                                                */
+            $$=settype("",curlistvar);
+            /*                                                                */
+            strcpy(vallengspec,"");
+         }
+      }
+      | dimension ',' TOK_NAME dims lengspec
+      {
+         if ( couldaddvariable == 1 )
+         {
+            /*                                                                */
+            curvar=createvar($3,$4);
+            /*                                                                */
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar($1,curvar);
+            /*                                                                */
+            $$=curlistvar;
+            /*                                                                */
+            strcpy(vallengspec,"");
+         }
+      }
+      ;
+private: TOK_PRIVATE '\n'
+      | TOK_PRIVATE opt_sep use_name_list
+      ;
+public: TOK_PUBLIC '\n'
+      | TOK_PUBLIC opt_sep use_name_list
+      ;
+use_name_list: TOK_NAME
+      | use_name_list ',' TOK_NAME
+      ;
+common: before_common var_common_list
+                   {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcommon,
+                                                  pos_end-pos_curcommon);
+                   }
+      | before_common comblock var_common_list
+                   {
+                         if ( couldaddvariable == 1 )
+                         {
+                            sprintf(charusemodule,"%s",$2);
+                            Add_NameOfCommon_1($2);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
+                         }
+                   }
+      | common opt_comma comblock opt_comma var_common_list
+                   {
+                         if ( couldaddvariable == 1 )
+                         {
+                            sprintf(charusemodule,"%s",$3);
+                            Add_NameOfCommon_1($3);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
+                         }
+                   }
+      ;
+before_common : TOK_COMMON
+                   {
+                      positioninblock=0;
+                      pos_curcommon = setposcur()-6;
+                   }
+      | TOK_GLOBAL TOK_COMMON
+                   {
+                      positioninblock=0;
+                      pos_curcommon = setposcur()-6-7;
+                   }
+      ;
+var_common_list : var_common
+                   {
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
+                   }
+
+     | var_common_list ',' var_common
+                   {
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
+                   }
+var_common: TOK_NAME dims
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         positioninblock = positioninblock + 1 ;
+                         strcpy(commonvar,$1);
+                         commondim = $2;
+                      }
+                   }
+      ;
+comblock: TOK_DSLASH
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,"");
+                         positioninblock=0;
+                         strcpy(commonblockname,"");
+                      }
+                   }
+      | TOK_SLASH TOK_NAME TOK_SLASH
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,$2);
+                         positioninblock=0;
+                         strcpy(commonblockname,$2);
+                      }
+                   }
+      ;
+opt_comma:
+      | ','
+      ;
+paramlist: paramitem
+                   {
+                      if ( couldaddvariable == 1 ) $$=insertvar(NULL,$1);
+                   }
+      | paramlist ',' paramitem
+                   {
+                      if ( couldaddvariable == 1 ) $$=insertvar($1,$3);
+                   }
+      ;
+paramitem : TOK_NAME '=' expr
+                   {
+                     if ( couldaddvariable == 1 )
+                     {
+                         curvar=(variable *) malloc(sizeof(variable));
+                         /*                                                   */
+                         Init_Variable(curvar);
+                         /*                                                   */
+                         curvar->v_VariableIsParameter=1;
+                         strcpy(curvar->v_nomvar,$1);
+                         strcpy(curvar->v_subroutinename,subroutinename);
+                         strcpy(curvar->v_modulename,curmodulename);
+                         strcpy(curvar->v_initialvalue,$3);
+                         strcpy(curvar->v_commoninfile,mainfile);
+                         $$=curvar;
+                      }
+                   }
+      ;
+module_proc_stmt: TOK_PROCEDURE proc_name_list
+      ;
+proc_name_list: TOK_NAME
+      | proc_name_list ',' TOK_NAME
+      ;
+implicit: TOK_IMPLICIT TOK_NONE
+                    {
+                       if ( insubroutinedeclare == 1 )
+                       {
+                          Add_ImplicitNoneSubroutine_1();
+                          pos_end = setposcur();
+                          RemoveWordSET_0(fortranout,pos_end-13,
+                                                             13);
+                       }
+                    }
+      | TOK_IMPLICIT TOK_REAL8
+      ;
+opt_retour :
+      ;
+dcl : options opt_retour TOK_NAME dims lengspec initial_value
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         /*                                                   */
+                         if (dimsgiven == 1)
+                         {
+                            curvar=createvar($3,curdim);
+                         }
+                         else
+                         {
+                            curvar=createvar($3,$4);
+                         }
+                         /*                                                   */
+                         CreateAndFillin_Curvar(DeclType,curvar);
+                         /*                                                   */
+                         curlistvar=insertvar(NULL,curvar);
+                         if (!strcasecmp(DeclType,"character"))
+                         {
+                            if (c_selectorgiven == 1)
+                            {
+                               strcpy(c_selectordim.first,"1");
+                               strcpy(c_selectordim.last,c_selectorname);
+                               change_dim_char
+                                     (insertdim(NULL,c_selectordim),curlistvar);
+                            }
+                         }
+                         $$=settype(DeclType,curlistvar);
+                      }
+                      strcpy(vallengspec,"");
+                   }
+      | dcl ',' opt_retour TOK_NAME dims lengspec initial_value
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         if (dimsgiven == 1)
+                         {
+                            curvar=createvar($4,curdim);
+                         }
+                         else
+                         {
+                            curvar=createvar($4,$5);
+                         }
+                         /*                                                   */
+                         CreateAndFillin_Curvar($1->var->v_typevar,curvar);
+                         /*                                                   */
+                         strcpy(curvar->v_typevar,($1->var->v_typevar));
+                         /*                                                   */
+                         curlistvar=insertvar($1,curvar);
+                         if (!strcasecmp(DeclType,"character"))
+                         {
+                            if (c_selectorgiven == 1)
+                            {
+                               strcpy(c_selectordim.first,"1");
+                               strcpy(c_selectordim.last,c_selectorname);
+                               change_dim_char
+                                     (insertdim(NULL,c_selectordim),curlistvar);
+                            }
+                         }
+                         $$=curlistvar;
+                      }
+                      strcpy(vallengspec,"");
+                   }
+      ;
+nodimsgiven:       {dimsgiven=0;}
+      ;
+type:typespec selector
+                   {strcpy(DeclType,$1);}
+      | before_character c_selector
+                   {
+                      strcpy(DeclType,"CHARACTER");
+                   }
+      | typename '*' TOK_CSTINT
+                   {
+                      strcpy(DeclType,$1);
+                      strcpy(nameinttypename,$3);
+                   }
+      | before_typepar attribute ')'
+                   {
+                      strcpy(DeclType,"TYPE");
+                   }
+      ;
+before_typepar : TOK_TYPEPAR
+                   {
+                      if ( couldaddvariable == 1 ) VarTypepar = 1 ;
+                      couldaddvariable = 0 ;
+                      pos_cur_decl = setposcur()-5;
+                   }
+      ;
+c_selector:
+      | '*' TOK_CSTINT
+                   {c_selectorgiven=1;strcpy(c_selectorname,$2);}
+      | '*' '(' c_attribute ')' {c_star = 1;}
+      | '(' c_attribute ')'
+      ;
+c_attribute: TOK_NAME clause opt_clause
+      | TOK_NAME '=' clause opt_clause
+      | clause opt_clause
+      ;
+before_character : TOK_CHARACTER
+                   {
+                      pos_cur_decl = setposcur()-9;
+                   }
+      ;
+typespec: typename {strcpy($$,$1);}
+      ;
+typename: TOK_INTEGER
+                   {
+                      strcpy($$,"INTEGER");
+                      pos_cur_decl = setposcur()-7;
+                   }
+      | TOK_REAL   {
+                      strcpy($$,"REAL");
+                      pos_cur_decl = setposcur()-4;
+                   }
+      | TOK_COMPLEX
+                   {strcpy($$,"COMPLEX");}
+      | TOK_DOUBLEPRECISION
+                   {
+                      pos_cur_decl = setposcur()-16;
+                      strcpy($$,"REAL");
+                      strcpy(nameinttypename,"8");
+                   }
+      | TOK_DOUBLECOMPLEX
+                   {strcpy($$,"DOUBLE COMPLEX");}
+      | TOK_LOGICAL
+                   {
+                      strcpy($$,"LOGICAL");
+                      pos_cur_decl = setposcur()-7;
+                   }
+      ;
+lengspec:
+      | '*' proper_lengspec {strcpy(vallengspec,$2);}
+      ;
+proper_lengspec: expr {sprintf($$,"*%s",$1);}
+      | '(' '*' ')'{strcpy($$,"*(*)");}
+      ;
+selector:
+      | '*' proper_selector
+      | '(' attribute ')'
+      ;
+proper_selector: expr
+      | '(' '*' ')'
+      ;
+attribute: TOK_NAME clause
+      | TOK_NAME '=' clause
+                   {
+                      if ( strstr($3,"0.d0") )
+                      {
+                         strcpy(nameinttypename,"8");
+                         sprintf(NamePrecision,"");
+                      }
+                      else sprintf(NamePrecision,"%s = %s",$1,$3);
+                   }
+      | TOK_NAME
+                   {
+                      strcpy(NamePrecision,$1);
+                   }
+      | TOK_CSTINT
+                   {
+                      strcpy(NamePrecision,$1);
+                   }
+      ;
+clause: expr       {strcpy(CharacterSize,$1);
+                    strcpy($$,$1);}
+      | '*'        {strcpy(CharacterSize,"*");
+                    strcpy($$,"*");}
+      ;
+opt_clause:
+      | ',' TOK_NAME clause
+      ;
+options:
+      | ':' ':'
+      | ',' attr_spec_list ':' ':'
+      ;
+attr_spec_list: attr_spec
+      | attr_spec_list ',' attr_spec
+      ;
+attr_spec: TOK_PARAMETER
+                   {
+                      VariableIsParameter = 1;
+                   }
+      | access_spec
+      | TOK_ALLOCATABLE
+                   {Allocatabledeclare = 1;}
+      | TOK_DIMENSION dims
+                   {
+                      dimsgiven=1;
+                      curdim=$2;
+                   }
+      | TOK_EXTERNAL
+                   {ExternalDeclare = 1;}
+      | TOK_INTENT intent_spec
+                   {strcpy(IntentSpec,$2);}
+      | TOK_INTRINSIC
+      | TOK_OPTIONAL{optionaldeclare = 1 ;}
+      | TOK_POINTER {pointerdeclare = 1 ;}
+      | TOK_SAVE    {
+/*                       if ( inmodulemeet == 1 )
+                       {*/
+                          SaveDeclare = 1 ;
+                     /*  }*/
+                    }
+      | TOK_TARGET
+      ;
+intent_spec: TOK_IN {sprintf($$,"in");}
+      | TOK_OUT     {sprintf($$,"out");}
+      | TOK_INOUT   {sprintf($$,"inout");}
+      ;
+access_spec: TOK_PUBLIC
+                   {PublicDeclare = 1;}
+      | TOK_PRIVATE
+                   {PrivateDeclare = 1;}
+      ;
+dims:              {if ( created_dimensionlist == 1 )
+                       {
+                           $$=(listdim *)NULL;
+                       }
+                   }
+      | '(' dimlist ')'
+                   {if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) $$=$2;}
+      ;
+dimlist:   dim     {if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) $$=insertdim(NULL,$1);}
+      | dimlist ',' dim
+                   {if ( couldaddvariable == 1 )
+                         if ( created_dimensionlist == 1 ) $$=insertdim($1,$3);}
+      ;
+dim:ubound         {strcpy($$.first,"1");strcpy($$.last,$1);}
+      | ':'        {strcpy($$.first,"");strcpy($$.last,"");}
+      | expr ':'   {strcpy($$.first,$1);strcpy($$.last,"");}
+      | ':' expr   {strcpy($$.first,"");strcpy($$.last,$2);}
+      | expr ':' ubound
+                   {strcpy($$.first,$1);strcpy($$.last,$3);}
+      ;
+ubound:  '*'       {strcpy($$,"*");}
+      | expr       {strcpy($$,$1);}
+      ;
+expr:  uexpr       {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '(' expr ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s)",$2);}
+      | complex_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | predefinedfunction
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+
+predefinedfunction : TOK_SUM minmaxlist ')'
+                   {sprintf($$,"SUM(%s)",$2);}
+      | TOK_MAX minmaxlist ')'
+                   {sprintf($$,"MAX(%s)",$2);}
+      | TOK_TANH '(' minmaxlist ')'
+                   {sprintf($$,"TANH(%s)",$3);}
+      | TOK_MAXVAL '(' minmaxlist ')'
+                   {sprintf($$,"MAXVAL(%s)",$3);}
+      | TOK_MIN minmaxlist ')'
+                   {sprintf($$,"MIN(%s)",$2);}
+      | TOK_MINVAL '(' minmaxlist ')'
+                   {sprintf($$,"MINVAL(%s)",$3);}
+      | TOK_TRIM '(' expr ')'
+                   {sprintf($$,"TRIM(%s)",$3);}
+      | TOK_SQRT expr ')'
+                   {sprintf($$,"SQRT(%s)",$2);}
+      | TOK_REAL '(' minmaxlist ')'
+                   {sprintf($$,"REAL(%s)",$3);}
+      | TOK_INT '(' expr ')'
+                   {sprintf($$,"INT(%s)",$3);}
+      | TOK_NINT '(' expr ')'
+                   {sprintf($$,"NINT(%s)",$3);}
+      | TOK_FLOAT '(' expr ')'
+                   {sprintf($$,"FLOAT(%s)",$3);}
+      | TOK_EXP '(' expr ')'
+                   {sprintf($$,"EXP(%s)",$3);}
+      | TOK_COS '(' expr ')'
+                   {sprintf($$,"COS(%s)",$3);}
+      | TOK_COSH '(' expr ')'
+                   {sprintf($$,"COSH(%s)",$3);}
+      | TOK_ACOS '(' expr ')'
+                   {sprintf($$,"ACOS(%s)",$3);}
+      | TOK_SIN '(' expr ')'
+                   {sprintf($$,"SIN(%s)",$3);}
+      | TOK_SINH '(' expr ')'
+                   {sprintf($$,"SINH(%s)",$3);}
+      | TOK_ASIN '(' expr ')'
+                   {sprintf($$,"ASIN(%s)",$3);}
+      | TOK_LOG '(' expr ')'
+                   {sprintf($$,"LOG(%s)",$3);}
+      | TOK_TAN '(' expr ')'
+                   {sprintf($$,"TAN(%s)",$3);}
+      | TOK_ATAN '(' expr ')'
+                   {sprintf($$,"ATAN(%s)",$3);}
+      | TOK_ABS expr ')'
+                   {sprintf($$,"ABS(%s)",$2);}
+      | TOK_MOD '(' minmaxlist ')'
+                   {sprintf($$,"MOD(%s)",$3);}
+      | TOK_SIGN '(' minmaxlist ')'
+                   {sprintf($$,"SIGN(%s)",$3);}
+      | TOK_MINLOC '(' minmaxlist ')'
+                   {sprintf($$,"MINLOC(%s)",$3);}
+      | TOK_MAXLOC '(' minmaxlist ')'
+                   {sprintf($$,"MAXLOC(%s)",$3);}
+      ;
+minmaxlist : expr {strcpy($$,$1);}
+      | minmaxlist ',' expr
+                   {if ( couldaddvariable == 1 )
+                   { strcpy($$,$1);strcat($$,",");strcat($$,$3);}}
+      ;
+uexpr:  lhs        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | simple_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | vec
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | expr operation
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      | signe expr %prec '* ' 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      | TOK_NOT expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      ;
+signe : '+'        {if ( couldaddvariable == 1 ) strcpy($$,"+");}
+      | '-'        {if ( couldaddvariable == 1 ) strcpy($$,"-");}
+      ;
+operation : '+' expr %prec '+'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"+%s",$2);}
+      |  '-' expr %prec '+'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"-%s",$2);}
+      |  '*' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"*%s",$2);}
+      |  TOK_DASTER expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_EQ expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_GT expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '>' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," > %s",$2);}
+      |  TOK_LT expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '<' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," < %s",$2);}
+      |  TOK_GE expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '>''=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," >= %s",$3);}
+      |  TOK_LE expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '<''=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," <= %s",$3);}
+      |  TOK_NE expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_XOR expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_OR expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_AND expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_SLASH after_slash
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s",$2);}
+      |  '=' after_equal
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s",$2);}
+
+after_slash : {strcpy($$,"");}
+      | expr
+                   {sprintf($$,"/%s",$1);}
+      | '=' expr %prec TOK_EQ
+                   {sprintf($$,"/= %s",$2);}
+      | TOK_SLASH expr
+                   {sprintf($$,"//%s",$2);}
+      ;
+after_equal : '=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"==%s",$2);}
+      | expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"= %s",$1);}
+      ;
+
+lhs: ident         {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | structure_component
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | array_ele_substring_func_ref
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+beforefunctionuse : {
+                      agrif_parentcall =0;
+                      if (!strcasecmp(identcopy,"Agrif_Parent") )
+                                                            agrif_parentcall =1;
+                      if ( Agrif_in_Tok_NAME(identcopy) == 1 )
+                      {
+                         inagrifcallargument = 1;
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                      }
+                   }
+      ;
+array_ele_substring_func_ref: begin_array
+                   {
+                     strcpy($$,$1);
+                     if ( incalldeclare == 0 ) inagrifcallargument = 0;
+                   }
+      | begin_array substring
+                   {if ( couldaddvariable == 1 ) sprintf($$," %s %s ",$1,$2);}
+      | structure_component '(' funarglist ')'
+                   {if ( couldaddvariable == 1 )
+                                                sprintf($$," %s ( %s )",$1,$3);}
+      | structure_component '(' funarglist ')' substring
+                   {if ( couldaddvariable == 1 )
+                                         sprintf($$," %s ( %s ) %s ",$1,$3,$5);}
+      ;
+begin_array : ident '(' funarglist ')'
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf($$," %s ( %s )",$1,$3);
+                         ModifyTheAgrifFunction_0($3);
+                         agrif_parentcall =0;
+                      }
+                   }
+      ;
+structure_component: lhs '%' lhs
+                   {
+                      sprintf($$," %s %% %s ",$1,$3);
+                      if ( incalldeclare == 0 ) inagrifcallargument = 0;
+                   }
+      ;
+vec:  TOK_LEFTAB outlist TOK_RIGHTAB
+                   {sprintf($$,"(/%s/)",$2);}
+      ;
+funarglist: beforefunctionuse    {strcpy($$," ");}
+      | beforefunctionuse funargs
+                   {strcpy($$,$2);}
+      ;
+funargs: funarg     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | funargs ',' funarg
+                    {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      ;
+funarg: expr       {strcpy($$,$1);}
+      | triplet    {strcpy($$,$1);}
+      ;
+triplet: expr ':' expr
+                    {if ( couldaddvariable == 1 ) sprintf($$,"%s:%s",$1,$3);}
+      | expr ':' expr ':' expr
+                    {if ( couldaddvariable == 1 )
+                                               sprintf($$,"%s:%s:%s",$1,$3,$5);}
+      | ':' expr ':' expr
+                    {if ( couldaddvariable == 1 ) sprintf($$,":%s:%s",$2,$4);}
+      | ':' ':' expr{if ( couldaddvariable == 1 ) sprintf($$,": : %s",$3);}
+      | ':' expr    {if ( couldaddvariable == 1 ) sprintf($$,":%s",$2);}
+      | expr ':'    {if ( couldaddvariable == 1 ) sprintf($$,"%s:",$1);}
+      | ':'         {if ( couldaddvariable == 1 ) sprintf($$,":");}
+      ;
+ident : TOK_NAME    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       if ( Vartonumber($1) == 1 )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if (!strcasecmp($1,"Agrif_Parent") )
+                                                            agrif_parentcall =1;
+                       if ( VariableIsNotFunction($1) == 0 )
+                       {
+                          if ( inagrifcallargument == 1 )
+                          {
+                             if ( !strcasecmp($1,identcopy) )
+                             {
+                                strcpy(sameagrifname,identcopy);
+                                sameagrifargument = 1;
+                             }
+                          }
+                          strcpy(identcopy,$1);
+                          pointedvar=0;
+                          if ( VarIsNonGridDepend($1) == 0 &&
+                               Variableshouldberemove($1) == 0 )
+                          {
+                             if ( inagrifcallargument == 1 ||
+                                  varisallocatable_0($1) == 1 ||
+                                  varispointer_0($1) == 1 )
+                             {
+                                ModifyTheVariableName_0($1);
+                             }
+                             if ( inagrifcallargument != 1 ||
+                                  sameagrifargument ==1 )
+                                  Add_UsedInSubroutine_Var_1($1);
+                          }
+                          NotifyAgrifFunction_0($1);
+                       }
+                       }
+                    }
+      ;
+simple_const: TOK_TRUE
+                     {if ( couldaddvariable == 1 ) strcpy($$,".TRUE.");}
+      | TOK_FALSE    {if ( couldaddvariable == 1 ) strcpy($$,".FALSE.");}
+      | TOK_CSTINT   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREAL  {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREALDP{if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREALQP{if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | simple_const TOK_NAME
+                     {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      | string_constant opt_substring
+      ;
+string_constant: TOK_CHAR_CONSTANT
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | string_constant TOK_CHAR_CONSTANT
+      | TOK_CHAR_MESSAGE
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CHAR_CUT
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+opt_substring:      {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | substring   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+substring: '(' optexpr ':' optexpr ')'
+                    {if ( couldaddvariable == 1 ) sprintf($$,"(%s:%s)",$2,$4);}
+      ;
+optexpr:           {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | expr        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+opt_expr: '\n'          {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | expr        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+initial_value:      {InitialValueGiven = 0;}
+      | before_initial '=' expr
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                          strcpy(InitValue,$3);
+                          InitialValueGiven = 1;
+                       }
+                    }
+      ;
+before_initial : {pos_curinit = setposcur();}
+      ;
+complex_const: '(' uexpr ',' uexpr ')'
+                    {sprintf($$,"(%s,%s)",$2,$4);}
+      ;
+use_stat: word_use  module_name
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                      /* if variables has been declared in a subroutine       */
+                      if (insubroutinedeclare == 1)
+                      {
+                         copyuse_0($2);
+                      }
+                      sprintf(charusemodule,"%s",$2);
+                      Add_NameOfModuleUsed_1($2);
+
+                      if ( inmoduledeclare == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curuse,
+                                               pos_end-pos_curuse);
+                      }
+                      }
+                    }
+      | word_use  module_name ',' rename_list
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                      if (insubroutinedeclare == 1)
+                      {
+                         Add_CouplePointed_Var_1($2,$4);
+                      }
+                      if ( firstpass == 1 )
+                      {
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            coupletmp = $4;
+                            strcpy(ligne,"");
+                            while ( coupletmp )
+                            {
+                               strcat(ligne,coupletmp->c_namevar);
+                               strcat(ligne," => ");
+                               strcat(ligne,coupletmp->c_namepointedvar);
+                               coupletmp = coupletmp->suiv;
+                               if ( coupletmp ) strcat(ligne,",");
+                            }
+                            sprintf(charusemodule,"%s",$2);
+                         }
+                         Add_NameOfModuleUsed_1($2);
+                      }
+                      if ( inmoduledeclare == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curuse,
+                                               pos_end-pos_curuse);
+                      }
+                      }
+                    }
+      | word_use  module_name ',' TOK_ONLY ':' '\n'
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                      /* if variables has been declared in a subroutine       */
+                      if (insubroutinedeclare == 1)
+                      {
+                         copyuseonly_0($2);
+                      }
+                      sprintf(charusemodule,"%s",$2);
+                      Add_NameOfModuleUsed_1($2);
+
+                       if ( inmoduledeclare == 0 )
+                       {
+                          pos_end = setposcur();
+                          RemoveWordSET_0(fortranout,pos_curuse,
+                                                pos_end-pos_curuse);
+                       }
+                       }
+                    }
+      | word_use  module_name ',' TOK_ONLY ':' only_list
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       /* if variables has been declared in a subroutine      */
+                       if (insubroutinedeclare == 1)
+                       {
+                          Add_CouplePointed_Var_1($2,$6);
+                       }
+                       if ( firstpass == 1 )
+                       {
+                         if ( insubroutinedeclare == 1 )
+                         {
+                             coupletmp = $6;
+                             strcpy(ligne,"");
+                             while ( coupletmp )
+                             {
+                                strcat(ligne,coupletmp->c_namevar);
+                               if ( strcasecmp(coupletmp->c_namepointedvar,"") )
+                                                           strcat(ligne," => ");
+                                strcat(ligne,coupletmp->c_namepointedvar);
+                                coupletmp = coupletmp->suiv;
+                                if ( coupletmp ) strcat(ligne,",");
+                             }
+                             sprintf(charusemodule,"%s",$2);
+                          }
+                          Add_NameOfModuleUsed_1($2);
+                       }
+                       if ( firstpass == 0 )
+                       {
+                          if ( inmoduledeclare == 0 )
+                          {
+                             pos_end = setposcur();
+                             RemoveWordSET_0(fortranout,pos_curuse,
+                                                   pos_end-pos_curuse);
+                          }
+                          else
+                          {
+                             /* if we are in the module declare and if the    */
+                             /* onlylist is a list of global variable         */
+                             variableisglobalinmodule($6, $2, fortranout);
+                          }
+                       }
+                       }
+                    }
+      ;
+word_use : TOK_USE
+                   {
+                      pos_curuse = setposcur()-strlen($1);
+                   }
+      ;
+module_name: TOK_NAME
+                    {strcpy($$,$1);}
+      ;
+rename_list: rename_name
+                    {
+                       if ( couldaddvariable == 1 ) $$ = $1;
+                    }
+      | rename_list ',' rename_name
+                    {
+                        if ( couldaddvariable == 1 )
+                        {
+                        /* insert the variable in the list $1                 */
+                        $3->suiv = $1;
+                        $$ = $3;
+                        }
+                    }
+      ;
+rename_name: TOK_NAME TOK_POINT_TO TOK_NAME
+                    {
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,$3);
+                       coupletmp->suiv = NULL;
+                       $$ = coupletmp;
+                     }
+      ;
+only_list: only_name
+                    {
+                       if ( couldaddvariable == 1 ) $$ = $1;
+                    }
+      | only_list ',' only_name
+                    {
+                        if ( couldaddvariable == 1 )
+                        {
+                        /* insert the variable in the list $1                 */
+                        $3->suiv = $1;
+                        $$ = $3;
+                        }
+                    }
+      ;
+only_name: TOK_NAME TOK_POINT_TO TOK_NAME
+                    {
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,$3);
+                       coupletmp->suiv = NULL;
+                       $$ = coupletmp;
+                       pointedvar=1;
+                       Add_UsedInSubroutine_Var_1($1);
+                    }
+      | TOK_NAME    {
+                       coupletmp =(listcouple *)malloc(sizeof(listcouple));
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,"");
+                       coupletmp->suiv = NULL;
+                       $$ = coupletmp;
+                     }
+      ;
+exec: iffable
+      | TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'
+                     {
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+      | TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                         curmodulename);
+                     }
+      | TOK_NULLIFY '(' pointer_name_list ')'
+      | word_endunit /* end                                                   */
+                    {
+                       GlobalDeclaration = 0 ;
+                       if ( firstpass == 0 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                          if ( module_declar && insubroutinedeclare == 0 )
+                          {
+                              fclose(module_declar);
+                          }
+                       }
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                       if ( inmodulemeet == 1 )
+                       {
+                         /* we are in a module                                */
+                         if ( insubroutinedeclare == 1 )
+                         {
+                            /* it is like an end subroutine <name>            */
+                            insubroutinedeclare = 0 ;
+                            /*                                                */
+                            pos_cur = setposcur();
+                            closeandcallsubloopandincludeit_0(1,$1);
+                            functiondeclarationisdone = 0;
+                         }
+                         else
+                         {
+                            /* it is like an end module <name>                */
+                            inmoduledeclare = 0 ;
+                            inmodulemeet = 0 ;
+                         }
+                       }
+                       else
+                       {
+                          insubroutinedeclare = 0;
+                          /*                                                  */
+                          pos_cur = setposcur();
+                          closeandcallsubloopandincludeit_0(2,$1);
+                            functiondeclarationisdone = 0;
+                          if ( firstpass == 0 )
+                          {
+                             if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                             else fprintf(paramout,"C\n");
+                             fclose(paramout);
+                           }
+                        }
+                      }
+                      strcpy(subroutinename,"");
+                    }
+      | word_endprogram opt_name
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(3,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+      | word_endsubroutine opt_name
+                    {
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(1,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+      | word_endfunction opt_name
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       insubroutinedeclare = 0;
+                       /*                                                     */
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(0,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
+                    }
+      | TOK_ENDMODULE opt_name
+                    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       /* if we never meet the contains keyword               */
+                      Remove_Word_end_module_0();
+                       if ( inmoduledeclare == 1 )
+                       {
+                          if ( aftercontainsdeclare == 0 )
+                          {
+                             Write_GlobalParameter_Declaration_0();
+                             Write_NotGridDepend_Declaration_0();
+                             Write_Alloc_Subroutine_For_End_0();
+                          }
+                       }
+                       inmoduledeclare = 0 ;
+                       inmodulemeet = 0 ;
+
+                      Write_Word_end_module_0();
+                      strcpy(curmodulename,"");
+                      aftercontainsdeclare = 1;
+                      if ( firstpass == 0 )
+                      {
+                         if ( module_declar && insubroutinedeclare == 0)
+                         {
+                           fclose(module_declar);
+                         }
+                      }
+                      GlobalDeclaration = 0 ;
+                      }
+                  }
+      | boucledo
+      | logif iffable
+      | TOK_WHERE '(' expr ')' opt_expr
+      | TOK_ELSEWHERE
+      | TOK_ENDWHERE
+      | logif TOK_THEN
+      | TOK_ELSEIF  '(' expr ')' TOK_THEN
+      | TOK_ELSE
+      | TOK_ENDIF opt_name
+      | TOK_CASE caselist ')'
+      | TOK_SELECTCASE '(' expr ')'
+      | TOK_CASEDEFAULT
+      | TOK_ENDSELECT
+      | TOK_CONTAINS
+                   {
+                      if (inmoduledeclare == 1 )
+                      {
+                         Remove_Word_Contains_0();
+                         Write_GlobalParameter_Declaration_0();
+                         Write_NotGridDepend_Declaration_0();
+                         Write_Alloc_Subroutine_0();
+                         inmoduledeclare = 0 ;
+                         aftercontainsdeclare = 1;
+                      }
+                      else
+                      {
+                       if ( couldaddvariable == 1 )
+                       {
+                          if ( firstpass == 1 ) List_ContainsSubroutine =
+                                                Addtolistnom(subroutinename,
+                                                     List_ContainsSubroutine,0);
+                          insubroutinedeclare = 0;
+                          /*                                                  */
+                          closeandcallsubloop_contains_0();
+                            functiondeclarationisdone = 0;
+                         if ( firstpass == 0 )
+                         {
+                            if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                            else fprintf(paramout,"C\n");
+                            fclose(paramout);
+                         }
+                         }
+                         strcpy(subroutinename,"");
+                      }
+                   }
+      ;
+word_endsubroutine: TOK_ENDSUBROUTINE
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       functiondeclarationisdone = 0;
+                       }
+                    }
+      ;
+word_endunit: TOK_ENDUNIT
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
+word_endprogram:  TOK_ENDPROGRAM
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
+word_endfunction: TOK_ENDFUNCTION
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
+caselist: expr
+      | caselist ',' expr
+      | caselist ':' expr
+      ;
+boucledo : worddo opt_int do_arg
+      | wordwhile expr
+      | TOK_ENDDO optname
+      ;
+do_arg :
+      | do_var '=' expr ',' expr
+      | do_var '=' expr ',' expr ',' expr
+opt_int :
+      | TOK_CSTINT opt_comma
+      ;
+opt_name : '\n'  {strcpy($$,"");}
+      | TOK_NAME {strcpy($$,$1);}
+      ;
+optname :
+      | TOK_NAME
+      ;
+worddo :  TOK_PLAINDO
+      ;
+wordwhile :TOK_DOWHILE
+      ;
+
+dotarget:
+      | TOK_CSTINT
+      ;
+
+iffable: TOK_CONTINUE
+      | ident_dims after_ident_dims
+      | goto
+      | io
+      | call
+      | TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+      | TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
+      | TOK_EXIT optexpr
+      | TOK_RETURN opt_expr
+      | TOK_CYCLE opt_expr
+      | stop opt_expr
+      | int_list
+      ;
+before_dims : {if ( couldaddvariable == 1 ) created_dimensionlist = 0;}
+ident_dims : ident before_dims dims dims
+              {
+                  created_dimensionlist = 1;
+                  if  ( agrif_parentcall == 1 )
+                  {
+                      ModifyTheAgrifFunction_0($3->dim.last);
+                      agrif_parentcall =0;
+                      fprintf(fortranout," = ");
+                  }
+              }
+      | ident_dims '%' ident before_dims dims dims
+      {created_dimensionlist = 1;}
+int_list : TOK_CSTINT
+      | int_list ',' TOK_CSTINT
+      ;
+after_ident_dims : '=' expr
+      | TOK_POINT_TO expr
+      ;
+call: keywordcall opt_call
+                   {
+                      inagrifcallargument = 0 ;
+                      incalldeclare=0;
+                      if ( oldfortranout &&
+                           !strcasecmp(meetagrifinitgrids,subroutinename) &&
+                           firstpass == 0 &&
+                           callmpiinit == 1)
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcall,
+                                               pos_end-pos_curcall);
+                         fprintf(oldfortranout,"      Call MPI_Init (%s) \n"
+                                                                   ,mpiinitvar);
+                      }
+                      if ( oldfortranout           &&
+                           callagrifinitgrids == 1 &&
+                           firstpass == 0 )
+                      {
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcall,
+                                               pos_end-pos_curcall);
+
+                         strcpy(subofagrifinitgrids,subroutinename);
+                      }
+                      Instanciation_0(sameagrifname);
+                   }
+      ;
+opt_call :
+      | '(' opt_callarglist  ')'
+      ;
+opt_callarglist :
+      | callarglist
+      ;
+keywordcall : before_call TOK_NAME
+                    {
+                       if (!strcasecmp($2,"MPI_Init") )
+                       {
+                          callmpiinit = 1;
+                       }
+                       else
+                       {
+                          callmpiinit = 0;
+                       }
+                       if (!strcasecmp($2,"Agrif_Init_Grids") )
+                       {
+                          callagrifinitgrids = 1;
+                          strcpy(meetagrifinitgrids,subroutinename);
+                       }
+                       else callagrifinitgrids = 0;
+                       if ( !strcasecmp($2,"Agrif_Open_File") )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if ( Vartonumber($2) == 1 )
+                       {
+                          incalldeclare=1;
+                          inagrifcallargument = 1 ;
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                    }
+      ;
+before_call : TOK_CALL
+                    {pos_curcall=setposcur()-4;}
+callarglist:  callarg
+      | callarglist ',' callarg
+      ;
+
+callarg:  expr {
+                  if ( callmpiinit == 1 )
+                  {
+                     strcpy(mpiinitvar,$1);
+                     if ( firstpass == 1 )
+                     {
+                        Add_UsedInSubroutine_Var_1 (mpiinitvar);
+/*                        curvar=createvar($1,NULL);
+                        curlistvar=insertvar(NULL,curvar);
+                        List_Subr outineArgument_Var = AddListvarToListvar
+                         (curlistvar,List_SubroutineAr gument_Var,1);*/
+                     }
+                  }
+               }
+      | '*' label
+      ;
+
+stop: TOK_PAUSE
+      | TOK_STOP
+      ;
+
+io: iofctl ioctl
+      | read option_read
+      | TOK_REWIND after_rewind
+      | TOK_FORMAT
+      ;
+opt_CHAR_INT :
+      | TOK_CSTINT TOK_NAME
+      ;
+idfile : '*'
+      | TOK_CSTINT
+      | ident
+      ;
+option_print :
+      | ',' outlist
+      ;
+option_inlist :
+      | inlist
+      ;
+option_read : ioctl option_inlist
+      | infmt opt_inlist
+      ;
+opt_outlist :
+      | outlist
+      ;
+opt_inlist :
+      | ',' inlist
+      ;
+ioctl:  '(' ctllist ')'
+      | '(' fexpr ')'
+      ;
+after_rewind:  '(' ident ')'
+      | '(' TOK_CSTINT ')'
+      | TOK_CSTINT
+      | '(' uexpr ')'
+      | TOK_NAME
+      ;
+ctllist: ioclause
+      | ctllist ',' ioclause
+      ;
+ioclause: fexpr
+      | '*'
+      | TOK_DASTER
+      | TOK_NAME expr
+      | TOK_NAME expr '%' ident_dims
+      | TOK_NAME '(' triplet ')'
+      | TOK_NAME '*'
+      | TOK_NAME TOK_DASTER
+      ;
+iofctl: TOK_OPEN
+      | TOK_CLOSE
+      ;
+infmt:  unpar_fexpr
+      | '*'
+      ;
+
+read:TOK_READ
+      | TOK_INQUIRE
+      | TOK_WRITE
+      | TOK_PRINT
+      ;
+fexpr: unpar_fexpr
+      | '(' fexpr ')'
+      ;
+unpar_fexpr: lhs
+      | simple_const
+      | fexpr addop fexpr %prec '+'
+      | fexpr '*' fexpr
+      | fexpr TOK_SLASH fexpr
+      | fexpr TOK_DASTER fexpr
+      | addop fexpr %prec '*'
+      | fexpr TOK_DSLASH fexpr
+      | TOK_FILE expr
+      | TOK_EXIST expr
+      | TOK_ERR expr
+      | TOK_END expr
+      | TOK_NAME '=' expr
+      ;
+addop: '+'
+      | '-'
+      ;
+inlist: inelt
+      | inlist ',' inelt
+      ;
+opt_lhs :
+      | lhs
+      ;
+inelt: opt_lhs opt_operation
+      | '(' inlist ')' opt_operation
+      | predefinedfunction opt_operation
+      | simple_const opt_operation
+      | '(' inlist ',' dospec ')'
+      ;
+opt_operation :
+      | operation
+      | opt_operation operation
+      ;
+outlist: other      {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | out2       {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+out2: uexpr ',' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | uexpr ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | other ',' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | other ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | out2 ',' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | out2 ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | uexpr     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | predefinedfunction {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+other:  complex_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '(' expr ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$," (%s)",$2);}
+      | '(' uexpr ',' dospec ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
+      | '(' other ',' dospec ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
+      | '(' out2 ',' dospec ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
+      ;
+
+dospec: TOK_NAME '=' expr ',' expr
+                   {if ( couldaddvariable == 1 )
+                                              sprintf($$,"%s=%s,%s)",$1,$3,$5);}
+      | TOK_NAME '=' expr ',' expr ',' expr
+                   {if ( couldaddvariable == 1 )
+                                        sprintf($$,"%s=%s,%s,%s)",$1,$3,$5,$7);}
+      ;
+labellist: label
+      | labellist ',' label
+      ;
+label: TOK_CSTINT
+      ;
+goto: TOK_PLAINGOTO '(' expr ',' expr ')' ',' expr
+      | TOK_PLAINGOTO label
+      ;
+allocation_list: allocate_object
+      | ident_dims
+      | allocation_list ',' allocate_object
+      ;
+allocate_object: ident
+                   {Add_Allocate_Var_1($1,curmodulename);}
+      | structure_component
+      | array_element
+      ;
+array_element: ident '(' funargs ')'
+                   {Add_Allocate_Var_1($1,curmodulename);}
+      ;
+subscript_list: expr
+      | subscript_list ',' expr
+      ;
+
+allocate_object_list:allocate_object
+      | allocate_object_list ',' allocate_object
+      ;
+opt_stat_spec:
+      | ',' TOK_STAT '=' ident
+      ;
+pointer_name_list: ident
+      | pointer_name_list ',' ident
+      ;
+opt_construct_name:
+      | TOK_NAME
+      ;
+opt_construct_name_colon:
+      | TOK_CONSTRUCTID ':'
+      ;
+logif: TOK_LOGICALIF expr ')'
+      ;
+do_var: ident {strcpy($$,$1);}
+      ;
+%%
+
+void processfortran(char *fichier_entree)
+{
+   extern FILE *fortranin;
+   extern FILE *fortranout;
+   char nomfile[LONGNOM];
+   int c;
+   int confirmyes;
+
+   /*fortrandebug = 1;*/
+   if ( mark == 1 ) printf("Firstpass == %d \n",firstpass);
+/******************************************************************************/
+/*  1-  Open input and output files                                           */
+/******************************************************************************/
+   strcpy(nomfile,commondirin);
+   strcat(nomfile,"/");
+   strcat(nomfile,fichier_entree);
+   fortranin=fopen( nomfile,"r");
+   if (! fortranin)
+   {
+      printf("Error : File %s does not exist\n",nomfile);
+      exit(1);
+   }
+
+   strcpy(curfile,nomfile);
+   strcpy(nomfile,commondirout);
+   strcat(nomfile,"/");
+   strcat(nomfile,fichier_entree);
+   strcpy(nomfileoutput,nomfile);
+   if (firstpass == 1)
+   {
+      if (checkexistcommon == 1)
+      {
+         if (fopen(nomfile,"r"))
+         {
+            printf("Warning : file %s already exist\n",nomfile);
+            confirmyes = 0;
+            while (confirmyes==0)
+            {
+               printf("Override file %s ? [Y/N]\n",nomfile);
+               c=getchar();
+               getchar();
+               if (c==79 || c==110)
+               {
+                  printf("We stop\n");
+                  exit(1);
+               }
+               if (c==89 || c==121)
+               {
+                  confirmyes=1;
+               }
+            }
+         }
+      }
+   }
+
+/******************************************************************************/
+/*  2-  Variables initialization                                              */
+/******************************************************************************/
+
+   line_num_fortran_common=1;
+   line_num_fortran=1;
+   PublicDeclare = 0;
+   PrivateDeclare = 0;
+   ExternalDeclare = 0;
+   SaveDeclare = 0;
+   pointerdeclare = 0;
+   optionaldeclare = 0;
+   incalldeclare = 0;
+   VarType = 0;
+   VarTypepar = 0;
+   Allocatabledeclare = 0 ;
+   strcpy(NamePrecision," ");
+   VariableIsParameter =  0 ;
+   strcpy(NamePrecision,"");
+   c_star = 0 ;
+   functiondeclarationisdone = 0;
+   insubroutinedeclare = 0 ;
+   strcpy(subroutinename," ");
+   InitialValueGiven = 0 ;
+   strcpy(EmptyChar," ");
+   inmoduledeclare = 0;
+   colnum=0;
+   incom=0;
+   couldaddvariable=1;
+   aftercontainsdeclare = 1;
+   /* Name of the file without format                                         */
+   tmp = strchr(fichier_entree, '.');
+   strncpy(curfilename,fichier_entree,strlen(fichier_entree)-strlen(tmp));
+/******************************************************************************/
+/*  3-  Parsing of the input file (1 time)                                    */
+/******************************************************************************/
+   if (firstpass == 0 )
+   {
+      fortranout=fopen(nomfileoutput,"w");
+
+      NewModule_Creation_0();
+   }
+
+   fortranparse();
+
+   strcpy(curfile,mainfile);
+
+   if (firstpass == 0 ) fclose(fortranout);
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/main.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/main.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/main.c	(revision 4536)
@@ -0,0 +1,2309 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
+#endif
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+#define yyclearin (yychar=(-1))
+#define yyerrok (yyerrflag=0)
+#define YYRECOVERING (yyerrflag!=0)
+extern int yyparse(void);
+#define YYPREFIX "yy"
+#line 36 "convert.y"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "decl.h"
+#line 42 "convert.y"
+typedef union {
+       int ival;
+       char na[LONGNOM];
+       listnom * ln;
+       } YYSTYPE;
+#line 24 "y.tab.c"
+#define TOK_SEP 257
+#define TOK_USE 258
+#define TOK_MODULEMAIN 259
+#define TOK_NOTGRIDDEP 260
+#define TOK_USEITEM 261
+#define TOK_NAME 262
+#define TOK_PROBTYPE 263
+#define YYERRCODE 256
+short yylhs[] = {                                        -1,
+    0,    0,    1,    1,    1,    1,    1,    1,    1,
+};
+short yylen[] = {                                         2,
+    0,    2,    1,    3,    5,    7,    3,    4,    3,
+};
+short yydefred[] = {                                      1,
+    0,    0,    0,    0,    0,    3,    2,    0,    0,    0,
+    0,    9,    7,    0,    0,    4,    8,    0,    0,    5,
+    0,    6,
+};
+short yydgoto[] = {                                       1,
+    7,
+};
+short yysindex[] = {                                      0,
+  -10, -258, -257, -253, -256,    0,    0,  -52,  -51, -252,
+  -43,    0,    0,  -50, -251,    0,    0,  -42, -250,    0,
+  -46,    0,
+};
+short yyrindex[] = {                                      0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,
+};
+short yygindex[] = {                                      0,
+    0,
+};
+#define YYTABLESIZE 253
+short yytable[] = {                                       6,
+   15,   19,    8,   10,    9,   11,   12,   13,   17,   14,
+   18,   21,   22,    0,    0,   16,   20,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    2,    3,    4,
+    0,    0,    5,
+};
+short yycheck[] = {                                      10,
+   44,   44,  261,  257,  262,  262,   59,   59,   59,  262,
+  262,  262,   59,   -1,   -1,   59,   59,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,  259,  260,
+   -1,   -1,  263,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 1
+#endif
+#define YYMAXTOKEN 263
+#if YYDEBUG
+char *yyname[] = {
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'","';'",0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'",0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+"TOK_SEP","TOK_USE","TOK_MODULEMAIN","TOK_NOTGRIDDEP","TOK_USEITEM","TOK_NAME",
+"TOK_PROBTYPE",
+};
+char *yyrule[] = {
+"$accept : input",
+"input :",
+"input : input line",
+"line : '\\n'",
+"line : TOK_PROBTYPE TOK_NAME ';'",
+"line : TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';'",
+"line : TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';'",
+"line : TOK_MODULEMAIN TOK_NAME ';'",
+"line : TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';'",
+"line : TOK_USE TOK_USEITEM ';'",
+};
+#endif
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH 500
+#endif
+#endif
+int yydebug;
+int yynerrs;
+int yyerrflag;
+int yychar;
+short *yyssp;
+YYSTYPE *yyvsp;
+YYSTYPE yyval;
+YYSTYPE yylval;
+short yyss[YYSTACKSIZE];
+YYSTYPE yyvs[YYSTACKSIZE];
+#define yystacksize YYSTACKSIZE
+#line 83 "convert.y"
+
+int main(int argc,char *argv[])
+{
+   extern FILE * yyin ;
+   FILE *dependglobaloutput;
+   char *tmp;
+   int i;
+   listnom *parcours;
+   listvar *newvar;
+
+   if (argc < 2)
+   {
+       printf("usage : conv <file> [-rm] [-incdir <directory>] \n");
+       printf(" [-comdirin   <directory>] [-comdirout <directory>]\n");
+       printf(" [-convfile  <FILENAME >] -SubloopScalar -SubloopScalar1 \n");
+       exit(0);
+   }
+/******************************************************************************/
+/*  1-  Variables initialization                                              */
+/******************************************************************************/
+   List_Global_Var=(listvar *)NULL;
+   List_GlobalParameter_Var=(listvar *)NULL;
+   List_Allocate_Var=(listallocate *)NULL;
+   List_Common_Var=(listvar *)NULL;
+   List_SubroutineWhereAgrifUsed=(listnom *)NULL;
+   List_Subroutine_For_Alloc=(listnom *)NULL;
+   List_Include=(listusemodule *)NULL;
+   List_NameOfModuleUsed=(listusemodule *)NULL;
+   listofmoduletmp=(listusemodule *)NULL;
+   List_SubroutineDeclaration_Var=(listvar *)NULL;
+   List_UsedInSubroutine_Var=(listvar *)NULL;
+   List_NotGridDepend_Var=(listvar *)NULL;
+   Listofavailableindices=(listindice *)NULL;
+   List_CouplePointed_Var=(listvarpointtovar *)NULL;
+   List_ModuleUsed_Var = (listvar *)NULL;
+   List_ModuleUsedInModuleUsed_Var = (listvar *)NULL;
+   List_GlobParamModuleUsed_Var = (listparameter *)NULL;
+   List_GlobParamModuleUsedInModuleUsed_Var = (listparameter *)NULL;
+   List_SubroutineArgument_Var = (listvar *)NULL;
+   List_FunctionType_Var = (listvar *)NULL;
+   tmpuselocallist = (listusemodule *)NULL;
+   List_ContainsSubroutine = (listnom *)NULL;
+
+   strcpy(mainfile,argv[1]);
+   strcpy(nomdir,"AGRIF_INC");
+   strcpy(commondirin,".");
+   strcpy(commondirout,".");
+   strcpy(filetoparse," ");
+   strcpy(subofagrifinitgrids,"");
+   strcpy(meetagrifinitgrids,"");
+   strcpy(mpiinitvar,"");
+
+   checkexistcommon=1;
+   todebug=0;
+   onlyfixedgrids=0;
+   fixedgrids=0;
+   InAgrifParentDef = 0;
+   IndicenbmaillesX=0;
+   IndicenbmaillesY=0;
+   IndicenbmaillesZ=0;
+   created_dimensionlist = 1;
+   indicemaxtabvars = 0;   /* current indice in the table tabvars             */
+   SubloopScalar = 0;
+   todebug = 0;
+   todebugfree = 0;
+   retour77 = 1 ;
+   mark = 0 ;
+   shouldincludempif = 0 ;
+/******************************************************************************/
+/*  2-  Program arguments                                                     */
+/******************************************************************************/
+
+   if ((yyin=fopen(argv[1],"r"))==NULL)
+   {
+      printf("the file %s doesn't exist \n",argv[1]);
+      exit(0);
+   }
+
+   i=2;
+   while (i<argc)
+   {
+      if (!strcasecmp(argv[i],"-incdir"))
+      {
+         strcpy(nomdir,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-comdirin")) /* input directory           */
+      {
+         strcpy(commondirin,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-comdirout")) /* output directory         */
+      {
+         strcpy(commondirout,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-convfile")) /* file to parse             */
+      {
+         strcpy(filetoparse,argv[i+1]);
+         i++;
+      }
+      else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse        */
+      {
+         SubloopScalar = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse       */
+      {
+         SubloopScalar = 2 ;
+      }
+      else if (!strcasecmp(argv[i],"-todebug")) /* file to parse       */
+      {
+         todebug = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-mark")) /* file to parse       */
+      {
+         mark = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-todebugfree")) /* file to parse       */
+      {
+         todebugfree = 1 ;
+      }
+      else if (!strcasecmp(argv[i],"-rm"))
+      {
+         checkexistcommon=0;
+      }
+      else
+      {
+         printf("Unkwon option : %s\n",argv[i]);
+         exit(0);
+      }
+      i++;
+   }
+
+/******************************************************************************/
+/*  3-  Parsing of the  conv file <name>.in                                   */
+/******************************************************************************/
+
+   if ((yyin=fopen(argv[1],"r"))==NULL)
+   {
+       printf("the file %s doesn't exist \n",argv[1]);
+       exit(0);
+   }
+   strcpy(mainfile,argv[1]);
+
+   if ( strstr(filetoparse,".f90") ||
+        strstr(filetoparse,".F90") ) retour77 = 0;
+
+   yyparse();
+
+/******************************************************************************/
+/*  4-  Preparation of the file parsing                                       */
+/******************************************************************************/
+   if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ?   */
+   {
+      printf("the file %s doesn't exist \n",filetoparse);
+      exit(0);
+   }
+   /* mainfile : the name of the file to parse                                */
+   strcpy(mainfile,filetoparse);
+   /*                                                                         */
+   if ((dependglobaloutput=fopen(".dependglobal_agrif","r"))!=NULL)
+   {
+      fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars);
+      fclose(dependglobaloutput);
+   }
+   Readthedependavailablefile();
+   /* Read the .dependnbxnby file which contains indices of nbmaillsX,        */
+   /*    nbmailleY and nbmailleZ                                              */
+   Readthedependnbxnbyfile();
+   Read_Subroutine_For_Alloc();
+/******************************************************************************/
+/*  5-  Parsing of the input file (2 times)                                   */
+/******************************************************************************/
+   /* Record all variable in list                                             */
+   firstpass = 1;
+   processfortran(filetoparse);
+   /*                                                                         */
+   CompleteThelistvarindoloop();
+   /* Read list of module used                                                */
+   RecordUseModulesVariables();
+   /* Read list of module used in module used                                 */
+   RecordUseModulesUseModulesVariables();
+   /* Save variables are considered as globals ones                           */
+   Update_List_Global_Var_From_List_Save_Var();
+   /* Update all lists                                                        */
+   ListUpdate();
+   /* Indice tabvars identification                                           */
+   IndiceTabvarsIdentification();
+   /* Update all lists                                                        */
+   ListUpdate();
+   /* The allocation subroutine is necessary ????                             */
+   New_Allocate_Subroutine_Is_Necessary();
+   /* The allocation subroutine is necessary for common list                  */
+   New_Allocate_Subroutine_For_Common_Is_Necessary();
+   /* Sort List_SubroutineArgument_Var                                        */
+   Sort_List_SubroutineArgument_Var();
+   /* Clean all lists                                                         */
+   ListClean();
+   /* Update Indice of List_UsedInSubroutine_Var from module used             */
+   List_UsedInSubroutine_Var_Update_From_Module_Used();
+   /* Update List_SubroutineWhereAgrifUsed                                    */
+   UpdateList_SubroutineWhereAgrifUsed();
+   /* Update List_UsedInSubroutine_Var with v_readedlistdimension             */
+   UpdateList_UsedInSubroutine_With_dimension();;
+   /*                                                                         */
+   ModifyThelistvarindoloop();
+   /*                                                                         */
+   UpdateListDeclarationWithDimensionList();
+   /*                                                                         */
+   GiveTypeOfVariables();
+   Affiche();
+   /* Build new subroutines                                                   */
+   firstpass = 0;
+   processfortran(filetoparse);
+
+/******************************************************************************/
+/*  6-  Write informations in output files                                    */
+/******************************************************************************/
+
+   /* Write the .dependglobal_agrif file which contain the max indice         */
+   /*    of the tabvars table                                                 */
+   dependglobaloutput = fopen(".dependglobal_agrif","w");
+   fprintf(dependglobaloutput,"%d\n",indicemaxtabvars);
+   fclose(dependglobaloutput);
+   /* Write the list of available indice                                      */
+   Writethedependavailablefile();
+   /* Write the .dependnbxnby file which contains indices of nbmaillsX,       */
+   /*    nbmailleY and nbmailleZ                                              */
+   Writethedependnbxnbyfile();
+   /* Write the .depend<namefile> file which contain general informations     */
+   /*    about variable of this file                                          */
+   parcours = List_NameOfModule;
+   while( parcours )
+   {
+      Writethedependlistofmoduleused(parcours->o_nom);
+      WritedependParameterList(parcours->o_nom);
+      Writethedependfile(parcours->o_nom,List_Global_Var);
+      parcours=parcours->suiv;
+   }
+   parcours = List_NameOfCommon;
+   while( parcours )
+   {
+      Writethedependfile(parcours->o_nom,List_Common_Var);
+      parcours=parcours->suiv;
+   }
+   Write_Subroutine_For_Alloc();
+/******************************************************************************/
+/*  7-  Create files in AGRIF_INC directory                                   */
+/******************************************************************************/
+   creefichieramr(NameTamponfile);
+
+
+   if ( todebug == 1 ) printf("Out of CONV \n");
+   return 0;
+}
+#line 425 "y.tab.c"
+#define YYABORT goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR goto yyerrlab
+int
+yyparse(void)
+{
+    register int yym, yyn, yystate;
+#if YYDEBUG
+    register char *yys;
+    extern char *getenv();
+
+    if (yys = getenv("YYDEBUG"))
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = (-1);
+
+    yyssp = yyss;
+    yyvsp = yyvs;
+    *yyssp = yystate = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yyssp >= yyss + yystacksize - 1)
+        {
+            goto yyoverflow;
+        }
+        *++yyssp = yystate = yytable[yyn];
+        *++yyvsp = yylval;
+        yychar = (-1);
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+#ifdef lint
+    goto yynewerror;
+#endif
+yynewerror:
+    yyerror("syntax error");
+#ifdef lint
+    goto yyerrlab;
+#endif
+yyerrlab:
+    ++yynerrs;
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
+#endif
+                if (yyssp >= yyss + yystacksize - 1)
+                {
+                    goto yyoverflow;
+                }
+                *++yyssp = yystate = yytable[yyn];
+                *++yyvsp = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yyssp);
+#endif
+                if (yyssp <= yyss) goto yyabort;
+                --yyssp;
+                --yyvsp;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = (-1);
+        goto yyloop;
+    }
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    yyval = yyvsp[1-yym];
+    switch (yyn)
+    {
+case 4:
+#line 67 "convert.y"
+{initdimprob(1,yyvsp[-1].na,"0","0");}
+break;
+case 5:
+#line 68 "convert.y"
+{initdimprob(2,yyvsp[-3].na, yyvsp[-1].na,"0");}
+break;
+case 6:
+#line 70 "convert.y"
+{initdimprob(3,yyvsp[-5].na, yyvsp[-3].na, yyvsp[-1].na);}
+break;
+case 7:
+#line 72 "convert.y"
+{listofmodules = Addtolistnom(yyvsp[-1].na,listofmodules,0);
+                                                        Addmoduletothelist(yyvsp[-1].na);}
+break;
+case 8:
+#line 74 "convert.y"
+{Add_NotGridDepend_Var_1(yyvsp[-1].na);}
+break;
+case 9:
+#line 75 "convert.y"
+{
+                                    if (!strcasecmp(yyvsp[-1].na,"FIXED_GRIDS"))
+                                                                 fixedgrids=1;
+                                    if (!strcasecmp(yyvsp[-1].na,"ONLY_FIXED_GRIDS"))
+                                                             onlyfixedgrids=1;
+                                 }
+break;
+#line 596 "y.tab.c"
+    }
+    yyssp -= yym;
+    yystate = *yyssp;
+    yyvsp -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yyssp = YYFINAL;
+        *++yyvsp = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yyssp, yystate);
+#endif
+    if (yyssp >= yyss + yystacksize - 1)
+    {
+        goto yyoverflow;
+    }
+    *++yyssp = yystate;
+    *++yyvsp = yyval;
+    goto yyloop;
+yyoverflow:
+    yyerror("yacc stack overflow");
+yyabort:
+    return (1);
+yyaccept:
+    return (0);
+}
+#line 2 "convert.yy.c"
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ * $Header$
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+#include <unistd.h>
+
+
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else	/* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif	/* __STDC__ */
+#endif	/* ! __cplusplus */
+
+#ifdef __TURBOC__
+ #pragma warn -rch
+ #pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index.  If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition.  This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state.  The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* The funky do-while in the following #define is used to turn the definition
+ * int a single C statement (which needs a semi-colon terminator).  This
+ * avoids problems with code like:
+ *
+ * 	if ( condition_holds )
+ *		yyless( 5 );
+ *	else
+ *		do_something_else();
+ *
+ * Prior to using the do-while the compiler would get upset at the
+ * "else" because it interpreted the "if" statement as being all
+ * done when it reached the ';' after the yyless() call.
+ */
+
+/* Return all but the first 'n' matched characters back to the input stream. */
+
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		*yy_cp = yy_hold_char; \
+		YY_RESTORE_YY_MORE_OFFSET \
+		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+		} \
+	while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+
+struct yy_buffer_state
+	{
+	FILE *yy_input_file;
+
+	char *yy_ch_buf;		/* input buffer */
+	char *yy_buf_pos;		/* current position in input buffer */
+
+	/* Size of input buffer in bytes, not including room for EOB
+	 * characters.
+	 */
+	yy_size_t yy_buf_size;
+
+	/* Number of characters read into yy_ch_buf, not including EOB
+	 * characters.
+	 */
+	int yy_n_chars;
+
+	/* Whether we "own" the buffer - i.e., we know we created it,
+	 * and can realloc() it to grow it, and should free() it to
+	 * delete it.
+	 */
+	int yy_is_our_buffer;
+
+	/* Whether this is an "interactive" input source; if so, and
+	 * if we're using stdio for input, then we want to use getc()
+	 * instead of fread(), to make sure we stop fetching input after
+	 * each newline.
+	 */
+	int yy_is_interactive;
+
+	/* Whether we're considered to be at the beginning of a line.
+	 * If so, '^' rules will be active on the next match, otherwise
+	 * not.
+	 */
+	int yy_at_bol;
+
+	/* Whether to try to fill the input buffer when we reach the
+	 * end of it.
+	 */
+	int yy_fill_buffer;
+
+	int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+	/* When an EOF's been seen but there's still some text to process
+	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+	 * shouldn't try reading from the input source any more.  We might
+	 * still have a bunch of tokens to match, though, because of
+	 * possible backing-up.
+	 *
+	 * When we actually see the EOF, we change the status to "new"
+	 * (via yyrestart()), so that the user can continue scanning by
+	 * just pointing yyin at a new input file.
+	 */
+#define YY_BUFFER_EOF_PENDING 2
+	};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars;		/* number of characters read into yy_ch_buf */
+
+
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1;		/* whether we need to initialize */
+static int yy_start = 0;	/* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin.  A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO(( FILE *input_file ));
+
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+void yy_load_buffer_state YY_PROTO(( void ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_is_interactive = is_interactive; \
+	}
+
+#define yy_set_bol(at_bol) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_at_bol = at_bol; \
+	}
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( void ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+	yytext_ptr = yy_bp; \
+	yyleng = (int) (yy_cp - yy_bp); \
+	yy_hold_char = *yy_cp; \
+	*yy_cp = '\0'; \
+	yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 12
+#define YY_END_OF_BUFFER 13
+static yyconst short int yy_accept[74] =
+    {   0,
+        0,    0,    0,    0,   13,   12,   11,   10,   12,    9,
+       12,   12,   12,    9,    8,    8,    8,    8,    8,    8,
+       11,    0,    4,    7,    5,    8,    8,    8,    8,    8,
+        8,    8,    6,    8,    8,    8,    8,    3,    8,    8,
+        8,    8,    8,    8,    8,    8,    8,    8,    8,    8,
+        8,    8,    8,    8,    8,    8,    8,    8,    8,    8,
+        8,    8,    8,    2,    8,    8,    8,    1,    8,    8,
+        8,    8,    0
+    } ;
+
+static yyconst int yy_ec[256] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    2,    1,    1,    1,    1,    4,    1,    1,    5,
+        6,    1,    1,    7,    1,    1,    1,    8,    9,   10,
+       11,    8,    8,    8,   12,    8,    8,   13,   14,    1,
+        1,    1,    1,    1,   18,   19,   19,   20,   21,   22,
+       23,   19,   24,   19,   19,   25,   26,   27,   28,   29,
+       19,   30,   31,   32,   33,   19,   19,   34,   35,   19,
+       15,    1,   16,    1,   17,    1,   18,   19,   19,   20,
+
+       21,   22,   23,   19,   24,   19,   19,   25,   26,   27,
+       28,   29,   19,   30,   31,   32,   33,   19,   19,   34,
+       35,   19,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1
+    } ;
+
+static yyconst int yy_meta[36] =
+    {   0,
+        1,    1,    2,    1,    1,    1,    1,    3,    3,    3,
+        3,    3,    1,    1,    1,    1,    3,    3,    3,    3,
+        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
+        3,    3,    3,    3,    3
+    } ;
+
+static yyconst short int yy_base[76] =
+    {   0,
+        0,    0,    0,    0,   96,   97,   93,   97,   90,   97,
+       73,   72,   71,   77,    0,   24,   61,   61,   69,   55,
+       83,   80,   79,   97,   97,    0,   70,   47,   48,   54,
+       48,   56,    0,   55,   52,   39,   55,    0,   52,   41,
+       53,   43,   51,   43,   44,   39,   41,   43,   38,   33,
+       30,   39,   24,   37,   32,   34,   33,   20,   32,   21,
+       27,   21,   14,    0,   27,   22,   19,    0,   11,   16,
+       19,    7,   97,   48,   34
+    } ;
+
+static yyconst short int yy_def[76] =
+    {   0,
+       73,    1,    1,    1,   73,   73,   73,   73,   74,   73,
+       73,   73,   73,   73,   75,   75,   75,   75,   75,   75,
+       73,   74,   74,   73,   73,   75,   75,   75,   75,   75,
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
+       75,   75,    0,   73,   73
+    } ;
+
+static yyconst short int yy_nxt[133] =
+    {   0,
+        6,    7,    8,    9,   10,   10,   10,    6,   11,   12,
+       13,    6,   14,   10,   10,   10,   15,   15,   15,   15,
+       15,   16,   15,   15,   15,   15,   17,   18,   19,   15,
+       15,   15,   20,   15,   15,   27,   26,   33,   72,   71,
+       70,   69,   68,   67,   33,   66,   65,   28,   22,   64,
+       22,   63,   62,   61,   60,   59,   58,   57,   56,   55,
+       54,   53,   52,   51,   50,   49,   48,   47,   46,   45,
+       44,   43,   42,   41,   40,   39,   38,   37,   36,   35,
+       34,   33,   23,   23,   21,   32,   31,   30,   29,   25,
+       24,   24,   24,   23,   21,   73,    5,   73,   73,   73,
+
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73
+    } ;
+
+static yyconst short int yy_chk[133] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,   16,   75,   72,   71,   70,
+       69,   67,   66,   65,   63,   62,   61,   16,   74,   60,
+       74,   59,   58,   57,   56,   55,   54,   53,   52,   51,
+       50,   49,   48,   47,   46,   45,   44,   43,   42,   41,
+       40,   39,   37,   36,   35,   34,   32,   31,   30,   29,
+       28,   27,   23,   22,   21,   20,   19,   18,   17,   14,
+       13,   12,   11,    9,    7,    5,   73,   73,   73,   73,
+
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
+       73,   73
+    } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "convert.lex"
+#define INITIAL 0
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#define character 1
+
+#line 37 "convert.lex"
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+int line_num=1;
+extern FILE * yyin;
+#define MAX_INCLUDE_DEPTH 30
+YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+#line 460 "convert.yy.c"
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO(( void ));
+#else
+extern int yywrap YY_PROTO(( void ));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO(( void ));
+#else
+static int input YY_PROTO(( void ));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/* Just try to get by without declaring the routines.  This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+	if ( yy_current_buffer->yy_is_interactive ) \
+		{ \
+		int c = '*', n; \
+		for ( n = 0; n < max_size && \
+			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+			buf[n] = (char) c; \
+		if ( c == '\n' ) \
+			buf[n++] = (char) c; \
+		if ( c == EOF && ferror( yyin ) ) \
+			YY_FATAL_ERROR( "input in flex scanner failed" ); \
+		result = n; \
+		} \
+	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+		  && ferror( yyin ) ) \
+		YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+	YY_USER_ACTION
+
+YY_DECL
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp, *yy_bp;
+	register int yy_act;
+
+#line 55 "convert.lex"
+
+#line 613 "convert.yy.c"
+
+	if ( yy_init )
+		{
+		yy_init = 0;
+
+#ifdef YY_USER_INIT
+		YY_USER_INIT;
+#endif
+
+		if ( ! yy_start )
+			yy_start = 1;	/* first start state */
+
+		if ( ! yyin )
+			yyin = stdin;
+
+		if ( ! yyout )
+			yyout = stdout;
+
+		if ( ! yy_current_buffer )
+			yy_current_buffer =
+				yy_create_buffer( yyin, YY_BUF_SIZE );
+
+		yy_load_buffer_state();
+		}
+
+	while ( 1 )		/* loops until end-of-file is reached */
+		{
+		yy_cp = yy_c_buf_p;
+
+		/* Support of yytext. */
+		*yy_cp = yy_hold_char;
+
+		/* yy_bp points to the position in yy_ch_buf of the start of
+		 * the current run.
+		 */
+		yy_bp = yy_cp;
+
+		yy_current_state = yy_start;
+yy_match:
+		do
+			{
+			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+			if ( yy_accept[yy_current_state] )
+				{
+				yy_last_accepting_state = yy_current_state;
+				yy_last_accepting_cpos = yy_cp;
+				}
+			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+				{
+				yy_current_state = (int) yy_def[yy_current_state];
+				if ( yy_current_state >= 74 )
+					yy_c = yy_meta[(unsigned int) yy_c];
+				}
+			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+			++yy_cp;
+			}
+		while ( yy_base[yy_current_state] != 97 );
+
+yy_find_action:
+		yy_act = yy_accept[yy_current_state];
+		if ( yy_act == 0 )
+			{ /* have to back up */
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			yy_act = yy_accept[yy_current_state];
+			}
+
+		YY_DO_BEFORE_ACTION;
+
+
+do_action:	/* This label is used only to access EOF actions. */
+
+
+		switch ( yy_act )
+	{ /* beginning of action switch */
+			case 0: /* must back up */
+			/* undo the effects of YY_DO_BEFORE_ACTION */
+			*yy_cp = yy_hold_char;
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 56 "convert.lex"
+return TOK_MODULEMAIN; /* name of the module                      */
+	YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 57 "convert.lex"
+return TOK_NOTGRIDDEP; /* variable which are not grid dependent   */
+	YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 58 "convert.lex"
+return TOK_USE;
+	YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 59 "convert.lex"
+{}
+	YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 60 "convert.lex"
+return TOK_SEP;
+	YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 61 "convert.lex"
+{strcpy(yylval.na,yytext); return TOK_USEITEM;}
+	YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 62 "convert.lex"
+{strcpy(yylval.na,yytext); return TOK_PROBTYPE;}
+	YY_BREAK
+/* dimension of the problem                */
+case 8:
+YY_RULE_SETUP
+#line 64 "convert.lex"
+{strcpy(yylval.na,yytext); return TOK_NAME;}
+	YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 65 "convert.lex"
+{return (int) *yytext;}
+	YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 66 "convert.lex"
+{line_num++;return (int) *yytext;}
+	YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 67 "convert.lex"
+;
+	YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 68 "convert.lex"
+ECHO;
+	YY_BREAK
+#line 757 "convert.yy.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(character):
+	yyterminate();
+
+	case YY_END_OF_BUFFER:
+		{
+		/* Amount of text matched not including the EOB char. */
+		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
+
+		/* Undo the effects of YY_DO_BEFORE_ACTION. */
+		*yy_cp = yy_hold_char;
+		YY_RESTORE_YY_MORE_OFFSET
+
+		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
+			{
+			/* We're scanning a new file or input source.  It's
+			 * possible that this happened because the user
+			 * just pointed yyin at a new source and called
+			 * yylex().  If so, then we have to assure
+			 * consistency between yy_current_buffer and our
+			 * globals.  Here is the right place to do so, because
+			 * this is the first action (other than possibly a
+			 * back-up) that will match for the new input source.
+			 */
+			yy_n_chars = yy_current_buffer->yy_n_chars;
+			yy_current_buffer->yy_input_file = yyin;
+			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+			}
+
+		/* Note that here we test for yy_c_buf_p "<=" to the position
+		 * of the first EOB in the buffer, since yy_c_buf_p will
+		 * already have been incremented past the NUL character
+		 * (since all states make transitions on EOB to the
+		 * end-of-buffer state).  Contrast this with the test
+		 * in input().
+		 */
+		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			{ /* This was really a NUL. */
+			yy_state_type yy_next_state;
+
+			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+			yy_current_state = yy_get_previous_state();
+
+			/* Okay, we're now positioned to make the NUL
+			 * transition.  We couldn't have
+			 * yy_get_previous_state() go ahead and do it
+			 * for us because it doesn't know how to deal
+			 * with the possibility of jamming (and we don't
+			 * want to build jamming into it because then it
+			 * will run more slowly).
+			 */
+
+			yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+			yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+			if ( yy_next_state )
+				{
+				/* Consume the NUL. */
+				yy_cp = ++yy_c_buf_p;
+				yy_current_state = yy_next_state;
+				goto yy_match;
+				}
+
+			else
+				{
+				yy_cp = yy_c_buf_p;
+				goto yy_find_action;
+				}
+			}
+
+		else switch ( yy_get_next_buffer() )
+			{
+			case EOB_ACT_END_OF_FILE:
+				{
+				yy_did_buffer_switch_on_eof = 0;
+
+				if ( yywrap() )
+					{
+					/* Note: because we've taken care in
+					 * yy_get_next_buffer() to have set up
+					 * yytext, we can now set up
+					 * yy_c_buf_p so that if some total
+					 * hoser (like flex itself) wants to
+					 * call the scanner after we return the
+					 * YY_NULL, it'll still work - another
+					 * YY_NULL will get returned.
+					 */
+					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+					yy_act = YY_STATE_EOF(YY_START);
+					goto do_action;
+					}
+
+				else
+					{
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+					}
+				break;
+				}
+
+			case EOB_ACT_CONTINUE_SCAN:
+				yy_c_buf_p =
+					yytext_ptr + yy_amount_of_matched_text;
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_match;
+
+			case EOB_ACT_LAST_MATCH:
+				yy_c_buf_p =
+				&yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_find_action;
+			}
+		break;
+		}
+
+	default:
+		YY_FATAL_ERROR(
+			"fatal flex scanner internal error--no action found" );
+	} /* end of action switch */
+		} /* end of scanning one token */
+	} /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ *	EOB_ACT_LAST_MATCH -
+ *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ *	EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+	{
+	register char *dest = yy_current_buffer->yy_ch_buf;
+	register char *source = yytext_ptr;
+	register int number_to_move, i;
+	int ret_val;
+
+	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+		YY_FATAL_ERROR(
+		"fatal flex scanner internal error--end of buffer missed" );
+
+	if ( yy_current_buffer->yy_fill_buffer == 0 )
+		{ /* Don't try to fill the buffer, so this is an EOF. */
+		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+			{
+			/* We matched a single character, the EOB, so
+			 * treat this as a final EOF.
+			 */
+			return EOB_ACT_END_OF_FILE;
+			}
+
+		else
+			{
+			/* We matched some text prior to the EOB, first
+			 * process it.
+			 */
+			return EOB_ACT_LAST_MATCH;
+			}
+		}
+
+	/* Try to read more data. */
+
+	/* First move last chars to start of buffer. */
+	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+	for ( i = 0; i < number_to_move; ++i )
+		*(dest++) = *(source++);
+
+	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+		/* don't do the read, it's not guaranteed to return an EOF,
+		 * just force an EOF
+		 */
+		yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+	else
+		{
+		int num_to_read =
+			yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+		while ( num_to_read <= 0 )
+			{ /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+			YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+			/* just a shorter name for the current buffer */
+			YY_BUFFER_STATE b = yy_current_buffer;
+
+			int yy_c_buf_p_offset =
+				(int) (yy_c_buf_p - b->yy_ch_buf);
+
+			if ( b->yy_is_our_buffer )
+				{
+				int new_size = b->yy_buf_size * 2;
+
+				if ( new_size <= 0 )
+					b->yy_buf_size += b->yy_buf_size / 8;
+				else
+					b->yy_buf_size *= 2;
+
+				b->yy_ch_buf = (char *)
+					/* Include room in for 2 EOB chars. */
+					yy_flex_realloc( (void *) b->yy_ch_buf,
+							 b->yy_buf_size + 2 );
+				}
+			else
+				/* Can't grow it, we don't own it. */
+				b->yy_ch_buf = 0;
+
+			if ( ! b->yy_ch_buf )
+				YY_FATAL_ERROR(
+				"fatal error - scanner input buffer overflow" );
+
+			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+			num_to_read = yy_current_buffer->yy_buf_size -
+						number_to_move - 1;
+#endif
+			}
+
+		if ( num_to_read > YY_READ_BUF_SIZE )
+			num_to_read = YY_READ_BUF_SIZE;
+
+		/* Read in more data. */
+		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+			yy_n_chars, num_to_read );
+
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	if ( yy_n_chars == 0 )
+		{
+		if ( number_to_move == YY_MORE_ADJ )
+			{
+			ret_val = EOB_ACT_END_OF_FILE;
+			yyrestart( yyin );
+			}
+
+		else
+			{
+			ret_val = EOB_ACT_LAST_MATCH;
+			yy_current_buffer->yy_buffer_status =
+				YY_BUFFER_EOF_PENDING;
+			}
+		}
+
+	else
+		ret_val = EOB_ACT_CONTINUE_SCAN;
+
+	yy_n_chars += number_to_move;
+	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+	return ret_val;
+	}
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp;
+
+	yy_current_state = yy_start;
+
+	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+		{
+		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+		if ( yy_accept[yy_current_state] )
+			{
+			yy_last_accepting_state = yy_current_state;
+			yy_last_accepting_cpos = yy_cp;
+			}
+		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+			{
+			yy_current_state = (int) yy_def[yy_current_state];
+			if ( yy_current_state >= 74 )
+				yy_c = yy_meta[(unsigned int) yy_c];
+			}
+		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+		}
+
+	return yy_current_state;
+	}
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ *	next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+	{
+	register int yy_is_jam;
+	register char *yy_cp = yy_c_buf_p;
+
+	register YY_CHAR yy_c = 1;
+	if ( yy_accept[yy_current_state] )
+		{
+		yy_last_accepting_state = yy_current_state;
+		yy_last_accepting_cpos = yy_cp;
+		}
+	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+		{
+		yy_current_state = (int) yy_def[yy_current_state];
+		if ( yy_current_state >= 74 )
+			yy_c = yy_meta[(unsigned int) yy_c];
+		}
+	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+	yy_is_jam = (yy_current_state == 73);
+
+	return yy_is_jam ? 0 : yy_current_state;
+	}
+
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput( int c, register char *yy_bp )
+#else
+static void yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+#endif
+	{
+	register char *yy_cp = yy_c_buf_p;
+
+	/* undo effects of setting up yytext */
+	*yy_cp = yy_hold_char;
+
+	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+		{ /* need to shift things up to make room */
+		/* +2 for EOB chars. */
+		register int number_to_move = yy_n_chars + 2;
+		register char *dest = &yy_current_buffer->yy_ch_buf[
+					yy_current_buffer->yy_buf_size + 2];
+		register char *source =
+				&yy_current_buffer->yy_ch_buf[number_to_move];
+
+		while ( source > yy_current_buffer->yy_ch_buf )
+			*--dest = *--source;
+
+		yy_cp += (int) (dest - source);
+		yy_bp += (int) (dest - source);
+		yy_current_buffer->yy_n_chars =
+			yy_n_chars = yy_current_buffer->yy_buf_size;
+
+		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+			YY_FATAL_ERROR( "flex scanner push-back overflow" );
+		}
+
+	*--yy_cp = (char) c;
+
+
+	yytext_ptr = yy_bp;
+	yy_hold_char = *yy_cp;
+	yy_c_buf_p = yy_cp;
+	}
+#endif	/* ifndef YY_NO_UNPUT */
+
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+	{
+	int c;
+
+	*yy_c_buf_p = yy_hold_char;
+
+	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+		{
+		/* yy_c_buf_p now points to the character we want to return.
+		 * If this occurs *before* the EOB characters, then it's a
+		 * valid NUL; if not, then we've hit the end of the buffer.
+		 */
+		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			/* This was really a NUL. */
+			*yy_c_buf_p = '\0';
+
+		else
+			{ /* need more input */
+			int offset = yy_c_buf_p - yytext_ptr;
+			++yy_c_buf_p;
+
+			switch ( yy_get_next_buffer() )
+				{
+				case EOB_ACT_LAST_MATCH:
+					/* This happens because yy_g_n_b()
+					 * sees that we've accumulated a
+					 * token and flags that we need to
+					 * try matching the token before
+					 * proceeding.  But for input(),
+					 * there's no matching to consider.
+					 * So convert the EOB_ACT_LAST_MATCH
+					 * to EOB_ACT_END_OF_FILE.
+					 */
+
+					/* Reset buffer status. */
+					yyrestart( yyin );
+
+					/* fall through */
+
+				case EOB_ACT_END_OF_FILE:
+					{
+					if ( yywrap() )
+						return EOF;
+
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+#ifdef __cplusplus
+					return yyinput();
+#else
+					return input();
+#endif
+					}
+
+				case EOB_ACT_CONTINUE_SCAN:
+					yy_c_buf_p = yytext_ptr + offset;
+					break;
+				}
+			}
+		}
+
+	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
+	*yy_c_buf_p = '\0';	/* preserve yytext */
+	yy_hold_char = *++yy_c_buf_p;
+
+
+	return c;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+	{
+	if ( ! yy_current_buffer )
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+	yy_init_buffer( yy_current_buffer, input_file );
+	yy_load_buffer_state();
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+	{
+	if ( yy_current_buffer == new_buffer )
+		return;
+
+	if ( yy_current_buffer )
+		{
+		/* Flush out information for old buffer. */
+		*yy_c_buf_p = yy_hold_char;
+		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	yy_current_buffer = new_buffer;
+	yy_load_buffer_state();
+
+	/* We don't actually know whether we did this switch during
+	 * EOF (yywrap()) processing, but the only time this flag
+	 * is looked at is after yywrap() is called, so it's safe
+	 * to go ahead and always set it.
+	 */
+	yy_did_buffer_switch_on_eof = 1;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state( void )
+#else
+void yy_load_buffer_state()
+#endif
+	{
+	yy_n_chars = yy_current_buffer->yy_n_chars;
+	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+	yyin = yy_current_buffer->yy_input_file;
+	yy_hold_char = *yy_c_buf_p;
+	}
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_buf_size = size;
+
+	/* yy_ch_buf has to be 2 characters longer than the size given because
+	 * we need to put in 2 end-of-buffer characters.
+	 */
+	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
+	if ( ! b->yy_ch_buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_is_our_buffer = 1;
+
+	yy_init_buffer( b, file );
+
+	return b;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+	{
+	if ( ! b )
+		return;
+
+	if ( b == yy_current_buffer )
+		yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+	if ( b->yy_is_our_buffer )
+		yy_flex_free( (void *) b->yy_ch_buf );
+
+	yy_flex_free( (void *) b );
+	}
+
+
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+	{
+	yy_flush_buffer( b );
+
+	b->yy_input_file = file;
+	b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+	b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+	b->yy_is_interactive = 0;
+#else
+	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+#endif
+#endif
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+	{
+	if ( ! b )
+		return;
+
+	b->yy_n_chars = 0;
+
+	/* We always need two end-of-buffer characters.  The first causes
+	 * a transition to the end-of-buffer state.  The second causes
+	 * a jam in that state.
+	 */
+	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+	b->yy_buf_pos = &b->yy_ch_buf[0];
+
+	b->yy_at_bol = 1;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	if ( b == yy_current_buffer )
+		yy_load_buffer_state();
+	}
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	if ( size < 2 ||
+	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
+	     base[size-1] != YY_END_OF_BUFFER_CHAR )
+		/* They forgot to leave room for the EOB's. */
+		return 0;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
+	b->yy_buf_pos = b->yy_ch_buf = base;
+	b->yy_is_our_buffer = 0;
+	b->yy_input_file = 0;
+	b->yy_n_chars = b->yy_buf_size;
+	b->yy_is_interactive = 0;
+	b->yy_at_bol = 1;
+	b->yy_fill_buffer = 0;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	yy_switch_to_buffer( b );
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+	{
+	int len;
+	for ( len = 0; yy_str[len]; ++len )
+		;
+
+	return yy_scan_bytes( yy_str, len );
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+	{
+	YY_BUFFER_STATE b;
+	char *buf;
+	yy_size_t n;
+	int i;
+
+	/* Get memory for full buffer, including space for trailing EOB's. */
+	n = len + 2;
+	buf = (char *) yy_flex_alloc( n );
+	if ( ! buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+	for ( i = 0; i < len; ++i )
+		buf[i] = bytes[i];
+
+	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+	b = yy_scan_buffer( buf, n );
+	if ( ! b )
+		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+	/* It's okay to grow etc. this buffer, and we should throw it
+	 * away when we're done.
+	 */
+	b->yy_is_our_buffer = 1;
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+	{
+	if ( yy_start_stack_ptr >= yy_start_stack_depth )
+		{
+		yy_size_t new_size;
+
+		yy_start_stack_depth += YY_START_STACK_INCR;
+		new_size = yy_start_stack_depth * sizeof( int );
+
+		if ( ! yy_start_stack )
+			yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+		else
+			yy_start_stack = (int *) yy_flex_realloc(
+					(void *) yy_start_stack, new_size );
+
+		if ( ! yy_start_stack )
+			YY_FATAL_ERROR(
+			"out of memory expanding start-condition stack" );
+		}
+
+	yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+	BEGIN(new_state);
+	}
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+	{
+	if ( --yy_start_stack_ptr < 0 )
+		YY_FATAL_ERROR( "start-condition stack underflow" );
+
+	BEGIN(yy_start_stack[yy_start_stack_ptr]);
+	}
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+	{
+	return yy_start_stack[yy_start_stack_ptr - 1];
+	}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+	{
+	(void) fprintf( stderr, "%s\n", msg );
+	exit( YY_EXIT_FAILURE );
+	}
+
+
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		yytext[yyleng] = yy_hold_char; \
+		yy_c_buf_p = yytext + n; \
+		yy_hold_char = *yy_c_buf_p; \
+		*yy_c_buf_p = '\0'; \
+		yyleng = n; \
+		} \
+	while ( 0 )
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+	{
+	register int i;
+	for ( i = 0; i < n; ++i )
+		s1[i] = s2[i];
+	}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+	{
+	register int n;
+	for ( n = 0; s[n]; ++n )
+		;
+
+	return n;
+	}
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+	{
+	return (void *) malloc( size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+	{
+	/* The cast to (char *) in the following accommodates both
+	 * implementations that use char* generic pointers, and those
+	 * that use void* generic pointers.  It works with the latter
+	 * because both ANSI C and C++ allow castless assignment from
+	 * any pointer type to void*, and deal with argument conversions
+	 * as though doing an assignment.
+	 */
+	return (void *) realloc( (char *) ptr, size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+	{
+	free( ptr );
+	}
+
+#if YY_MAIN
+int main()
+	{
+	yylex();
+	return 0;
+	}
+#endif
+#line 68 "convert.lex"
+
+
+
+int yywrap()
+{
+}
+
+
+yyerror(char *s)
+{
+if (!strcasecmp(curfile,mainfile))
+{
+   printf("Dans convert %s line %d, fichier %s\n",s,line_num,curfile);
+}
+else
+{
+   printf("Dans convert %s line %d, fichier %s\n",s,line_num,curfile);
+}
+exit(0);
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/run
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/run	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/run	(revision 4536)
@@ -0,0 +1,2 @@
+gmake -f Makefile.lex clean
+gmake -f Makefile.lex
Index: /branches/2010_and_older/dev_001_GM/AGRIF/LIB/toamr.c
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/LIB/toamr.c	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/LIB/toamr.c	(revision 4536)
@@ -0,0 +1,1090 @@
+/******************************************************************************/
+/*                                                                            */
+/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
+/*                                                                            */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.6                                                                */
+/******************************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "decl.h"
+char lvargridname[LONGNOM];
+char lvargridname2[LONGNOM];
+
+
+/******************************************************************************/
+/*                       variablenameroottabvars                              */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/*  ----------->  Agrif_Mygrid % tabvars (i) % var                            */
+/*                                                                            */
+/******************************************************************************/
+char *variablenameroottabvars (variable * var)
+{
+  char *ligne;
+
+  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
+  sprintf (ligne, "Agrif_Mygrid %% tabvars(%d) %% var ", var->v_indicetabvars);
+  return ligne;
+}
+
+
+/******************************************************************************/
+/*                        variablenametabvars                                 */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/*  if iorindice = 0 ---------->  Agrif_Gr % tabvars (i) % var                */
+/*                                                                            */
+/*  if iorindice = 1 ---------->  Agrif_Gr % tabvars (12) % var               */
+/*                                                                            */
+/******************************************************************************/
+char *variablenametabvars (variable * var, int iorindice)
+{
+  char *ligne;
+
+  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
+  if ( iorindice == 0 ) sprintf (ligne, " Agrif_Gr %% tabvars(%d)%% var",
+                                 var->v_indicetabvars);
+  else sprintf (ligne, " Agrif_Gr %% tabvars(i)%% var");
+  return ligne;
+}
+
+/******************************************************************************/
+/*                        variablecurgridtabvars                              */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/*  ----------->  Agrif_Curgrid % tabvars (i) % var                           */
+/*                                                                            */
+/******************************************************************************/
+char *variablecurgridtabvars (variable * var,int ParentOrCurgrid)
+{
+  char *ligne;
+
+  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
+  if ( ParentOrCurgrid == 0 ) sprintf (ligne, " Agrif_tabvars(%d) %% var",
+                              var->v_indicetabvars);
+  else if ( ParentOrCurgrid == 1 ) sprintf (ligne,
+                              " Agrif_tabvars(%d) %% parent_var %% var",
+                               var->v_indicetabvars);
+  else if ( ParentOrCurgrid == 2 ) sprintf (ligne,
+                              " Agrif_Mygrid %% tabvars(%d) %% var",
+                               var->v_indicetabvars);
+  else if ( ParentOrCurgrid == 3 ) sprintf (ligne,
+                              " Agrif_Curgrid %% tabvars(%d) %% var",
+                               var->v_indicetabvars);
+  else sprintf (ligne, " AGRIF_Mygrid %% tabvars(%d) %% var",
+                               var->v_indicetabvars);
+  return ligne;
+}
+
+/******************************************************************************/
+/*                           vargridnametabvars                               */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/*  if iorindice == 0 ----------->  Agrif_Gr % tabvars (i) % var % array1     */
+/*                                                                            */
+/*  if iorindice == 1 ----------->  Agrif_Gr % tabvars (12) % var % array1    */
+/*                                                                            */
+/******************************************************************************/
+char *vargridnametabvars (variable * var,int iorindice)
+{
+  char *tmp;
+  char tmp1[LONGNOM];
+
+  tmp = variablenametabvars (var,iorindice);
+  strcpy(tmp1,tmp);
+  if ( todebugfree == 1 ) free(tmp);
+
+  sprintf (lvargridname, "%s", tmp1);
+  if (!strcasecmp (var->v_typevar, "REAL"))
+    {
+      if ( !strcasecmp(var->v_nameinttypename,"8") )
+                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
+      else if ( !strcasecmp(var->v_nameinttypename,"4") )
+                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
+      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "INTEGER"))
+    {
+      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
+    {
+      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
+    {
+      sprintf (lvargridname2, "%% carray%d", var->v_nbdim);
+    }
+
+  strcat (lvargridname, lvargridname2);
+
+  return lvargridname;
+}
+
+/******************************************************************************/
+/*                           vargridcurgridtabvars                            */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/* if ParentOrCurgrid == 0 -->  Agrif_Curgrid % tabvars (i) % var % array1    */
+/*                                                                            */
+/* if ParentOrCurgrid == 1 -->  Agrif_tabvars (i) % parent_var %var % array1  */
+/*                                                                            */
+/* if ParentOrCurgrid == 2 -->  Agrif_Gr % tabvars (i) % var % array1         */
+/*                                                                            */
+/******************************************************************************/
+char *vargridcurgridtabvars (variable * var,int ParentOrCurgrid)
+{
+  char *tmp;
+  char tmp1[LONGNOM];
+
+  tmp = variablecurgridtabvars (var,ParentOrCurgrid);
+  strcpy(tmp1,tmp);
+  if ( todebugfree == 1 ) free(tmp);
+
+  sprintf (lvargridname, "%s", tmp1);
+  if (!strcasecmp (var->v_typevar, "REAL"))
+    {
+      if ( !strcasecmp(var->v_nameinttypename,"8") )
+                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
+      else if ( !strcasecmp(var->v_nameinttypename,"4") )
+                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
+      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "INTEGER"))
+    {
+      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
+    {
+      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
+    {
+      sprintf (lvargridname2, "%% carray%d", var->v_nbdim);
+    }
+
+  strcat (lvargridname, lvargridname2);
+
+  return lvargridname;
+}
+
+/******************************************************************************/
+/*                  vargridcurgridtabvarswithoutAgrif_Gr                      */
+/******************************************************************************/
+/* This subroutine is used to create the string                               */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+char *vargridcurgridtabvarswithoutAgrif_Gr (variable * var)
+{
+
+  sprintf (lvargridname, "(%d) %% var", var->v_indicetabvars);
+
+  if (!strcasecmp (var->v_typevar, "REAL"))
+    {
+      if ( !strcasecmp(var->v_nameinttypename,"8") )
+                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
+      else if ( !strcasecmp(var->v_nameinttypename,"4") )
+                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
+      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "INTEGER"))
+    {
+      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
+    {
+      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
+    }
+  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
+    {
+      sprintf (lvargridname2, "%% carray%d", var->v_nbdim);
+    }
+
+  strcat (lvargridname, lvargridname2);
+
+  return lvargridname;
+}
+
+/******************************************************************************/
+/*                               vargridparam                                 */
+/******************************************************************************/
+/* This subroutine is used to create the string which contains                */
+/* dimension list                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  DIMENSION(jpi,0:jpj) ----------->"1:jpi,0:jpj"                            */
+/*                                                                            */
+/******************************************************************************/
+char *vargridparam (variable * v, int whichone)
+{
+  typedim dim;
+  listdim *newdim;
+  char newname[LONGNOM];
+
+  newdim = v->v_dimension;
+  if (!newdim) return "";
+
+  strcpy (tmpvargridname, "(");
+  while (newdim)
+  {
+     dim = newdim->dim;
+
+     strcpy(newname,"");
+     strcpy(newname,
+            ChangeTheInitalvaluebyTabvarsName(dim.first,List_Global_Var,
+                                                                     whichone));
+     if ( !strcasecmp(newname,dim.first))
+     {
+        strcpy(newname,"");
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,
+                       List_Common_Var,whichone));
+     }
+     if ( !strcasecmp(newname,dim.first))
+     {
+        strcpy(newname,"");
+        /* la liste des use de cette subroutine                               */
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,
+                       List_ModuleUsed_Var,whichone));
+     }
+     strcat (tmpvargridname, newname);
+     strcat (tmpvargridname, " : ");
+     strcpy(newname,"");
+     strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                        (dim.last,List_Global_Var,whichone));
+     if ( !strcasecmp(newname,dim.last))
+     {
+        strcpy(newname,"");
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                       (dim.last, List_Common_Var,whichone));
+     }
+     if ( !strcasecmp(newname,dim.last))
+     {
+        strcpy(newname,"");
+        /* la liste des use de cette subroutine                               */
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                       (dim.last, List_ModuleUsed_Var,whichone));
+     }
+     strcat (tmpvargridname, newname);
+     newdim = newdim->suiv;
+     if (newdim) strcat (tmpvargridname, ",");
+  }
+  strcat (tmpvargridname, ")");
+  strcat (tmpvargridname, "\0");
+  return tmpvargridname;
+}
+
+/******************************************************************************/
+/*                        write_probdimagrif_file                             */
+/******************************************************************************/
+/* This subroutine is used to create the file probdim_agrif.h                 */
+/******************************************************************************/
+/*                                                                            */
+/*               probdim_agrif.h                                              */
+/*                                                                            */
+/*               Agrif_probdim = <number>                                     */
+/*                                                                            */
+/******************************************************************************/
+void write_probdimagrif_file()
+{
+  FILE *probdim;
+  char ligne[LONGLIGNE*100];
+
+  probdim = associate("probdim_agrif.h");
+  sprintf (ligne, "Agrif_Probdim = %d", dimprob);
+  tofich (probdim, ligne,1);
+  fclose (probdim);
+}
+
+/******************************************************************************/
+/*                             write_keysagrif_file                           */
+/******************************************************************************/
+/* This subroutine is used to create the file keys_agrif.h                    */
+/******************************************************************************/
+/*                                                                            */
+/*               keys_agrif.h                                                 */
+/*                                                                            */
+/*               AGRIF_USE_FIXED_GRIDS = 0                                    */
+/*               AGRIF_USE_ONLY_FIXED_GRIDS = 0                               */
+/*               AGRIF_USE_(ONLY)_FIXED_GRIDS = 1                             */
+/*                                                                            */
+/******************************************************************************/
+void write_keysagrif_file()
+{
+  FILE *keys;
+
+  keys = associate ("keys_agrif.h");
+  fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 0\n");
+  fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 0\n");
+  if (fixedgrids     == 1) fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 1\n");
+  if (onlyfixedgrids == 1)
+                         fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 1\n");
+
+  fclose(keys);
+}
+
+/******************************************************************************/
+/*                      write_modtypeagrif_file                               */
+/******************************************************************************/
+/* This subroutine is used to create the file typedata                        */
+/******************************************************************************/
+/*                                                                            */
+/*               modtype_agrif.h                                              */
+/*                                                                            */
+/*               Agrif_NbVariables =                                          */
+/*                                                                            */
+/******************************************************************************/
+void write_modtypeagrif_file()
+{
+  char ligne[LONGLIGNE*100];
+  FILE *typedata;
+
+  typedata = associate ("modtype_agrif.h");
+  /* AGRIF_NbVariables : number of variables                                  */
+  sprintf (ligne, "AGRIF_NbVariables = %d",indicemaxtabvars);
+  tofich(typedata,ligne,1);
+  fclose (typedata);
+}
+
+/******************************************************************************/
+/*                   write_createvarnameagrif_file                            */
+/******************************************************************************/
+/* This subroutine is used to create the file  createvarname                  */
+/******************************************************************************/
+/*                                                                            */
+/*    Agrif_Gr % tabvars (i) % var % namevar = "variable"                     */
+/*                                                                            */
+/******************************************************************************/
+void write_createvarnameagrif_file(variable *v,FILE *createvarname,
+                                                       int *InitEmpty)
+{
+  char ligne[LONGLIGNE*100];
+  char *tmp;
+  char temp1[LONGLIGNE];
+
+  tmp =  variablenametabvars(v,0);
+  strcpy (temp1, tmp);
+  if ( todebugfree == 1 ) free(tmp);
+
+  *InitEmpty = 0 ;
+  sprintf(ligne, "%s %% namevar = \"%s\"",temp1,v->v_nomvar);
+  tofich(createvarname,ligne,1);
+}
+
+/******************************************************************************/
+/*                        write_Setnumberofcells_file                         */
+/******************************************************************************/
+/* This subroutine is used to create the file  setnumberofcells               */
+/******************************************************************************/
+/*                                                                            */
+/*              Agrif_Gr % n(i) = nbmailles                                   */
+/*                                                                            */
+/******************************************************************************/
+void write_Setnumberofcells_file()
+{
+  char ligne[LONGLIGNE*100];
+  FILE *setnumberofcells;
+
+  if ( IndicenbmaillesX != 0 )
+  {
+  setnumberofcells=associate("SetNumberofcells.h");
+
+  if (onlyfixedgrids != 1 )
+  {
+  sprintf (ligne,
+           "Agrif_Gr %% nb(1) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesX);
+  }
+  else
+  {
+  sprintf (ligne,
+           "Agrif_Gr %% nb(1) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesX);
+  }
+  tofich (setnumberofcells, ligne,1);
+  if (dimprob > 1)
+  {
+     if (onlyfixedgrids != 1 )
+     {
+     sprintf (ligne,
+           "Agrif_Gr %% nb(2) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesY);
+     }
+     else
+     {
+     sprintf (ligne,
+           "Agrif_Gr %% nb(2) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesY);
+     }
+
+     tofich (setnumberofcells, ligne,1);
+  }
+  if (dimprob > 2)
+  {
+     if (onlyfixedgrids != 1 )
+     {
+     sprintf (ligne,
+           "Agrif_Gr %% nb(3) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesZ);
+     }
+     else
+     {
+     sprintf (ligne,
+           "Agrif_Gr %% nb(3) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
+           IndicenbmaillesZ);
+     }
+     tofich (setnumberofcells, ligne,1);
+  }
+
+  fclose (setnumberofcells);
+  }
+}
+
+/******************************************************************************/
+/*                       write_Getnumberofcells_file                          */
+/******************************************************************************/
+/* This subroutine is used to create the file  getnumberofcells               */
+/******************************************************************************/
+/*                                                                            */
+/*              nbmailles = Agrif_Gr % n(i)                                   */
+/*                                                                            */
+/******************************************************************************/
+void write_Getnumberofcells_file()
+{
+  char ligne[LONGLIGNE*100];
+  FILE *getnumberofcells;
+
+  if ( IndicenbmaillesX != 0 )
+  {
+  getnumberofcells=associate("GetNumberofcells.h");
+  sprintf (ligne,
+           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(1)",
+           IndicenbmaillesX);
+  tofich (getnumberofcells, ligne,1);
+  if (dimprob > 1)
+    {
+      sprintf (ligne,
+           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(2)",
+           IndicenbmaillesY);
+      tofich (getnumberofcells, ligne,1);
+    }
+  if (dimprob > 2)
+    {
+      sprintf (ligne,
+           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(3)",
+           IndicenbmaillesZ);
+      tofich (getnumberofcells, ligne,1);
+    }
+  fclose (getnumberofcells);
+  }
+}
+
+
+/******************************************************************************/
+/*                      write_initialisationsagrif_file                       */
+/******************************************************************************/
+/* This subroutine is used to create the file initproc                        */
+/******************************************************************************/
+/*                                                                            */
+/*              ! variable                                                    */
+/*              Agrif_Gr % tabvars(i) % var % nbdim = 1                       */
+/*                                                                            */
+/******************************************************************************/
+void write_initialisationsagrif_file(variable *v,FILE *initproc,
+                                     int *VarnameEmpty)
+{
+  char ligne[LONGLIGNE*100];
+  char temp1[LONGLIGNE];
+  char *tmp;
+
+  tmp = variablenameroottabvars (v);
+  strcpy (temp1, tmp);
+  if ( todebugfree == 1 ) free(tmp);
+
+  if ( v->v_nbdim != 0 )
+  {
+     *VarnameEmpty = 0 ;
+     sprintf (ligne, "%s %% nbdim = %d", temp1, v->v_nbdim);
+     tofich (initproc, ligne,1);
+  }
+}
+
+
+void Write_Alloc_Agrif_Files()
+{
+   listnom *parcours;
+   FILE *alloccalls;
+   FILE *AllocUSE;
+
+   AllocUSE= associate("include_use_Alloc_agrif.h");
+   alloccalls = associate("allocations_calls_agrif.h");
+
+   parcours = List_Subroutine_For_Alloc;
+   while ( parcours )
+   {
+      fprintf(AllocUSE,"      USE %s\n", parcours -> o_nom );
+      fprintf (alloccalls,"      Call Alloc_agrif_%s(Agrif_Gr)\n",
+                                                            parcours -> o_nom );
+      parcours = parcours -> suiv;
+   }
+
+   fclose (AllocUSE);
+   fclose (alloccalls);
+}
+
+int IndiceInlist(int indic, listindice *listin)
+{
+   listindice *parcoursindic;
+   int out;
+
+   out = 0 ;
+
+   parcoursindic = listin;
+   while ( parcoursindic && out == 0 )
+   {
+      if ( parcoursindic->i_indice == indic ) out = 1;
+      else parcoursindic = parcoursindic -> suiv;
+   }
+
+   return out;
+}
+void write_allocation_Common_0()
+{
+   listnom *parcours_nom;
+   listnom *neededparameter;
+   listvar *parcours;
+   listvar *parcoursprec;
+   listvar *parcours1;
+   FILE *allocationagrif;
+   FILE *paramtoamr;
+   char ligne[LONGNOM];
+   variable *v;
+   int IndiceMax;
+   int IndiceMin;
+   int compteur;
+   int out;
+   int indiceprec;
+   int ValeurMax;
+   char initialvalue[LONGNOM];
+   listindice *list_indic;
+   listindice *parcoursindic;
+   int i;
+
+   parcours_nom = List_NameOfCommon;
+   ValeurMax = 2;
+   while ( parcours_nom  )
+   {
+      /*                                                                      */
+      if ( parcours_nom->o_val == 1 )
+      {
+         /* Open the file to create the Alloc_agrif subroutine                */
+         sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
+         allocationagrif = associate (ligne);
+         /*                                                                   */
+         fprintf(allocationagrif,"#include \"Param_toamr_%s.h\" \n",
+                                                           parcours_nom->o_nom);
+         /*                                                                   */
+         sprintf(ligne,"Param_toamr_%s.h",parcours_nom->o_nom);
+         paramtoamr = associate (ligne);
+         neededparameter = (listnom * )NULL;
+         /*                                                                   */
+         list_indic = (listindice *)NULL;
+         /*                                                                   */
+         shouldincludempif = 1 ;
+         parcours = List_Common_Var;
+         while ( parcours )
+         {
+            if ( !strcasecmp(parcours->var->v_commonname,parcours_nom->o_nom) &&
+                  IndiceInlist(parcours->var->v_indicetabvars,list_indic) == 0
+               )
+            {
+               /***************************************************************/
+               /***************************************************************/
+               /***************************************************************/
+               v = parcours->var;
+               IndiceMax = 0;
+               IndiceMin = indicemaxtabvars;
+  /* body of the file                                                         */
+  if ( !strcasecmp(v->v_commoninfile,mainfile) )
+  {
+     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
+     {
+        strcpy (ligne, "If (.not. associated(");
+        strcat (ligne, vargridnametabvars(v,0));
+        strcat (ligne, "))                       then");
+        tofich (allocationagrif, ligne,1);
+     }
+     if ( v->v_allocatable != 1 && ( v->v_dimsempty != 1) )
+     {
+        /*                ALLOCATION                                          */
+        if ( v->v_dimension != 0  )
+        {
+           if ( v->v_indicetabvars < IndiceMin ||
+                v->v_indicetabvars > IndiceMax )
+           {
+              parcours1 = parcours;
+              compteur = -1;
+              out = 0;
+              indiceprec = parcours->var->v_indicetabvars -1 ;
+              while ( parcours1 && out == 0 &&
+                      !strcasecmp(  parcours->var->v_readedlistdimension,
+                                  parcours1->var->v_readedlistdimension) &&
+                      !strcasecmp(  parcours->var->v_typevar,
+                                  parcours1->var->v_typevar) &&
+                            ( parcours1->var->v_indicetabvars == indiceprec+1 )
+                     )
+              {
+
+               if ( !strcasecmp(parcours1->var->v_modulename,
+                                parcours_nom->o_nom) ||
+                    !strcasecmp(parcours1->var->v_commonname,
+                                parcours_nom->o_nom) )
+                 {
+                      compteur = compteur +1 ;
+                      indiceprec = parcours1->var->v_indicetabvars;
+                      parcoursprec = parcours1;
+                      parcours1 = parcours1->suiv;
+                 }
+                 else out = 1;
+              }
+
+              if ( compteur > ValeurMax )
+              {
+                 fprintf(allocationagrif,"      DO i = %d , %d\n",
+                                         parcours->var->v_indicetabvars,
+                                       parcours->var->v_indicetabvars+compteur);
+                 IndiceMin = parcours->var->v_indicetabvars;
+                 IndiceMax = parcours->var->v_indicetabvars+compteur;
+                 strcpy (ligne, "allocate ");
+                 strcat (ligne, "(");
+                 strcat (ligne, vargridnametabvars(v,1));
+                 strcat (ligne, vargridparam(v,0));
+                 strcat (ligne, ")");
+                 tofich (allocationagrif, ligne,1);
+                 fprintf(allocationagrif,"      end do\n");
+                 i=parcours->var->v_indicetabvars;
+                 do
+                 {
+                    parcoursindic =  (listindice *)malloc(sizeof(listindice));
+                    parcoursindic -> i_indice = i;
+                    parcoursindic -> suiv = list_indic;
+                    list_indic = parcoursindic;
+                    i = i + 1;
+                 } while ( i <= parcours->var->v_indicetabvars+compteur );
+                 parcours = parcoursprec;
+                 /*                                                           */
+              }
+              else
+              {
+                 strcpy (ligne, "allocate ");
+                 strcat (ligne, "(");
+                 strcat (ligne, vargridnametabvars(v,0));
+                 strcat (ligne, vargridparam(v,0));
+                 strcat (ligne, ")");
+                 tofich (allocationagrif, ligne,1);
+                 /*                                                           */
+                 parcoursindic =  (listindice *)malloc(sizeof(listindice));
+                 parcoursindic -> i_indice = parcours->var->v_indicetabvars;
+                 parcoursindic -> suiv = list_indic;
+                 list_indic = parcoursindic;
+              }
+                neededparameter = writedeclarationintoamr(List_Parameter_Var,
+                              paramtoamr,v,parcours_nom->o_nom,neededparameter,
+                                                               v->v_commonname);
+              /*                                                              */
+           }
+        } /* end of the allocation part                                       */
+        /*                INITIALISATION                                      */
+        if ( strcasecmp(v->v_initialvalue,"") )
+        {
+           strcpy (ligne, "");
+           strcat (ligne, vargridnametabvars(v,0));
+           /* We should modify the initialvalue in the case of variable has   */
+           /*    been defined with others variables                           */
+           strcpy(initialvalue,
+                  ChangeTheInitalvaluebyTabvarsName
+                                      (v->v_initialvalue,List_Global_Var,0));
+           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
+           {
+              strcpy(initialvalue,"");
+              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
+                                      (v->v_initialvalue,List_Common_Var,0));
+           }
+           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
+           {
+              strcpy(initialvalue,"");
+              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
+                                     (v->v_initialvalue,List_ModuleUsed_Var,0));
+           }
+           strcat (ligne," = ");
+           strcat (ligne,initialvalue);
+           /*                                                                 */
+           tofich (allocationagrif, ligne,1);
+        }
+     }
+     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
+     {
+        strcpy (ligne, "   End if");
+        tofich (allocationagrif, ligne,1);
+     }
+  }
+               /***************************************************************/
+               /***************************************************************/
+               /***************************************************************/
+            }
+            parcours = parcours -> suiv;
+         }
+         /* Close the file Alloc_agrif                                        */
+         fclose(allocationagrif);
+         fclose(paramtoamr);
+      }
+      /*                                                                      */
+      parcours_nom = parcours_nom -> suiv;
+   }
+
+}
+
+
+
+void write_allocation_Global_0()
+{
+   listnom *parcours_nom;
+   listvar *parcours;
+   listvar *parcoursprec;
+   listvar *parcours1;
+   FILE *allocationagrif;
+   char ligne[LONGNOM];
+   variable *v;
+   int IndiceMax;
+   int IndiceMin;
+   int compteur;
+   int out;
+   int indiceprec;
+   int ValeurMax;
+   char initialvalue[LONGNOM];
+
+   parcours_nom = List_NameOfModule;
+   ValeurMax = 2;
+   while ( parcours_nom  )
+   {
+      /*                                                                      */
+      if ( parcours_nom->o_val == 1 )
+      {
+         IndiceMax = 0;
+         IndiceMin = indicemaxtabvars;
+         /* Open the file to create the Alloc_agrif subroutine                */
+         sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
+         allocationagrif = associate (ligne);
+         /*                                                                   */
+         if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
+         {
+             /* add the call to initworkspace                                 */
+            tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
+            fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
+            tofich(allocationagrif,"else ",1);
+            fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
+            tofich(allocationagrif,"endif ",1);
+            tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
+         }
+
+         parcours = List_Global_Var;
+         while ( parcours )
+         {
+            if ( !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom) &&
+                 parcours->var->v_VariableIsParameter == 0                  &&
+                 parcours->var->v_notgrid == 0                              &&
+                 !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom)  )
+            {
+               /***************************************************************/
+               /***************************************************************/
+               /***************************************************************/
+               v = parcours->var;
+               IndiceMax = 0;
+               IndiceMin = indicemaxtabvars;
+  /* body of the file                                                         */
+  if ( !strcasecmp(v->v_commoninfile,mainfile) )
+  {
+     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
+     {
+        strcpy (ligne, "If (.not. associated(");
+        strcat (ligne, vargridnametabvars(v,0));
+        strcat (ligne, "))                       then");
+        tofich (allocationagrif, ligne,1);
+     }
+     if ( v->v_allocatable != 1 && ( v->v_dimsempty != 1) )
+     {
+        /*                ALLOCATION                                          */
+        if ( v->v_dimension != 0  )
+        {
+           if ( v->v_indicetabvars < IndiceMin ||
+                v->v_indicetabvars > IndiceMax )
+           {
+              parcours1 = parcours;
+              compteur = -1;
+              out = 0;
+              indiceprec = parcours->var->v_indicetabvars -1 ;
+              while ( parcours1 && out == 0 &&
+                      !strcasecmp(  parcours->var->v_readedlistdimension,
+                                  parcours1->var->v_readedlistdimension) &&
+                      !strcasecmp(  parcours->var->v_typevar,
+                                  parcours1->var->v_typevar) &&
+                             ( parcours1->var->v_indicetabvars == indiceprec+1 )
+                     )
+              {
+
+               if ( !strcasecmp(parcours1->var->v_modulename,
+                                parcours_nom->o_nom) ||
+                    !strcasecmp(parcours1->var->v_commonname,
+                                parcours_nom->o_nom) )
+                 {
+                      compteur = compteur +1 ;
+                      indiceprec = parcours1->var->v_indicetabvars;
+                      parcoursprec = parcours1;
+                      parcours1 = parcours1->suiv;
+                 }
+                 else out = 1;
+              }
+              if ( compteur > ValeurMax )
+              {
+                 fprintf(allocationagrif,"      DO i = %d , %d\n",
+                                          parcours->var->v_indicetabvars,
+                                       parcours->var->v_indicetabvars+compteur);
+                 IndiceMin = parcours->var->v_indicetabvars;
+                 IndiceMax = parcours->var->v_indicetabvars+compteur;
+                 strcpy (ligne, "allocate ");
+                 strcat (ligne, "(");
+                 strcat (ligne, vargridnametabvars(v,1));
+                 strcat (ligne, vargridparam(v,0));
+                 strcat (ligne, ")");
+                 tofich (allocationagrif, ligne,1);
+                 fprintf(allocationagrif,"      end do\n");
+                 parcours = parcoursprec;
+              }
+              else
+              {
+                 strcpy (ligne, "allocate ");
+                 strcat (ligne, "(");
+                 strcat (ligne, vargridnametabvars(v,0));
+                 strcat (ligne, vargridparam(v,0));
+                 strcat (ligne, ")");
+                 tofich (allocationagrif, ligne,1);
+              }
+           }
+        } /* end of the allocation part                                       */
+        /*                INITIALISATION                                      */
+        if ( strcasecmp(v->v_initialvalue,"") )
+        {
+           strcpy (ligne, "");
+           strcat (ligne, vargridnametabvars(v,0));
+           /* We should modify the initialvalue in the case of variable has   */
+           /*    been defined with others variables                           */
+           strcpy(initialvalue,
+                  ChangeTheInitalvaluebyTabvarsName
+                                      (v->v_initialvalue,List_Global_Var,0));
+           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
+           {
+              strcpy(initialvalue,"");
+              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
+                                      (v->v_initialvalue,List_Common_Var,0));
+           }
+           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
+           {
+              strcpy(initialvalue,"");
+              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
+                                     (v->v_initialvalue,List_ModuleUsed_Var,0));
+           }
+           strcat (ligne," = ");
+           strcat (ligne,initialvalue);
+           /*                                                                 */
+           tofich (allocationagrif, ligne,1);
+        }
+     }
+     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
+     {
+        strcpy (ligne, "   End if");
+        tofich (allocationagrif, ligne,1);
+     }
+  }
+               /***************************************************************/
+               /***************************************************************/
+               /***************************************************************/
+            }
+            parcours = parcours -> suiv;
+         }
+         /*                                                                   */
+         if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
+         {
+            /* add the call to initworkspace                                  */
+            tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
+            fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
+            tofich(allocationagrif,"else ",1);
+            fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
+            tofich(allocationagrif,"endif ",1);
+            tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
+         }
+         /* Close the file Alloc_agrif                                        */
+         fclose(allocationagrif);
+      } /* end parcours_nom == 1                                              */
+      /*                                                                      */
+      parcours_nom = parcours_nom -> suiv;
+   }
+}
+
+/******************************************************************************/
+/*                           creefichieramr                                   */
+/******************************************************************************/
+/* This subroutine is the main one to create AGRIF_INC files                  */
+/******************************************************************************/
+/*                                                                            */
+/******************************************************************************/
+void creefichieramr (char *NameTampon)
+{
+  listvar *newvar;
+  variable *v;
+  int erreur;
+  char filefich[LONGNOM];
+  char ligne[LONGNOM];
+  char ligne1[LONGNOM];
+  int IndiceMax;
+  int IndiceMin;
+  int InitEmpty;
+  int VarnameEmpty;
+  int donotwrite;
+
+  FILE *initproc;
+  FILE *initglobal;
+  FILE *createvarname;
+  FILE *createvarnameglobal;
+  FILE *modulealloc;
+  FILE *dependfileoutput;
+
+  if ( todebug == 1 ) printf("Enter in creefichieramr\n");
+  strcpy (filefich, "cd ");
+  strcat (filefich, nomdir);
+  erreur = system (filefich);
+  if (erreur)
+  {
+     strcpy (filefich, "mkdir ");
+     strcat (filefich, nomdir);
+     system (filefich);
+     printf ("%s: Directory created\n", nomdir);
+  }
+
+/******************************************************************************/
+/******************** Creation of AGRIF_INC files *****************************/
+/******************************************************************************/
+
+/*----------------------------------------------------------------------------*/
+  if ( todebug == 1 )
+  {
+     strcpy(ligne,"initialisations_agrif_");
+     strcat(ligne,NameTampon);
+     strcat(ligne,".h");
+     initproc = associate (ligne);
+/*----------------------------------------------------------------------------*/
+     strcpy(ligne,"createvarname_agrif_");
+     strcat(ligne,NameTampon);
+     strcat(ligne,".h");
+     createvarname = associate (ligne);
+/*----------------------------------------------------------------------------*/
+     InitEmpty = 1 ;
+     VarnameEmpty = 1 ;
+
+     newvar = List_Global_Var;
+     while ( newvar && todebug == 1 )
+     {
+        donotwrite = 0;
+        v = newvar->var;
+
+        if ( ( v->v_common == 1 || v->v_module == 1 ) && donotwrite == 0 )
+        {
+          write_createvarnameagrif_file(v,createvarname,&VarnameEmpty);
+          write_initialisationsagrif_file(v,initproc,&InitEmpty);
+        }
+        newvar = newvar->suiv;
+     }
+  /*                                                                          */
+     fclose (createvarname);
+     fclose (initproc);
+  /*--------------------------------------------------------------------------*/
+     if ( Did_filetoparse_readed(curmodulename) == 0 )
+     {
+        if ( InitEmpty != 1  )
+        {
+           initglobal = associateaplus("initialisations_agrif.h");
+           strcpy(ligne,"#include \"initialisations_agrif_");
+           strcat(ligne,NameTampon);
+           strcat(ligne,".h\"\n");
+           fprintf(initglobal,ligne);
+           fclose(initglobal);
+        }
+  /*--------------------------------------------------------------------------*/
+        if ( VarnameEmpty != 1 )
+        {
+           createvarnameglobal= associateaplus("createvarname_agrif.h");
+           strcpy(ligne,"#include \"createvarname_agrif_");
+           strcat(ligne,NameTampon);
+           strcat(ligne,".h\"\n");
+           fprintf(createvarnameglobal,ligne);
+           fclose(createvarnameglobal);
+        }
+     }
+  }
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+  IndiceMax = 0;
+  IndiceMin = 0;
+
+  write_allocation_Common_0();
+  write_allocation_Global_0();
+
+  Write_Alloc_Agrif_Files();
+  write_probdimagrif_file();
+  write_keysagrif_file();
+  write_modtypeagrif_file();
+  write_Setnumberofcells_file();
+  write_Getnumberofcells_file();
+  if ( todebug == 1 ) printf("Out of creefichieramr\n");
+}
Index: /branches/2010_and_older/dev_001_GM/AGRIF/agrif_opa.in
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/agrif_opa.in	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/agrif_opa.in	(revision 4536)
@@ -0,0 +1,12 @@
+% Number of cells in each direction %
+ 2D nbcellsx,nbcellsy;
+% Name of the common file : an include file (paramfile) OR a module (parammodule) %  
+ parammodule par_oce ;
+
+USE ONLY_FIXED_GRIDS;
+
+% Variables which are not grid dependent %
+% notgriddep :: name of the variable; %
+notgriddep :: nstop;
+
+%USE DEBUG;%
Index: /branches/2010_and_older/dev_001_GM/AGRIF/efface
===================================================================
--- /branches/2010_and_older/dev_001_GM/AGRIF/efface	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/AGRIF/efface	(revision 4536)
@@ -0,0 +1,9 @@
+rm -f AGRIF_INC/*
+rm -f AGRIF_MODELFILES/*
+rm -f AGRIF_OBJS/*
+rm -f AGRIF_YOURFILES/*
+rm -f SORTIE/*
+
+rm -f .depend*
+rm -f .agrif*
+rm -f LIB/*.o
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make	(revision 4536)
@@ -0,0 +1,13 @@
+# $Header$
+all: ioipsl opa
+
+ioipsl:
+	(cd ../../modeles/IOIPSL/src; $(M_K) ;)
+
+
+opa:
+	(cd ../../modeles/NEMO/WORK;  $(M_K) ;)
+
+
+clean:
+	(cd ../../modeles/NEMO/WORK;  $(M_K) clean ;)
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/AA_make.ldef	(revision 4536)
@@ -0,0 +1,11 @@
+#---------------------------------------------------------------------
+#- Creation des elements relatifs a ORCA :
+#-      ORCA  (lib, executable : opa)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#---------------------------------------------------------------------
+LIBDIR = ../../../../lib
+BINDIR = ../../../../bin
+MODDIR = $(LIBDIR)
+#---------------------------------------------------------------------
+#-
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/AA_job
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/AA_job	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/AA_job	(revision 4536)
@@ -0,0 +1,142 @@
+#-Q- sxnec ##################
+#-Q- sxnec ## SXNEC IDRIS
+#-Q- sxnec ##################
+#-Q- sxnec #@$-r :XXX:XXX:XXX:           # job name
+#-Q- sxnec #@$-o output_XXXXXXX.1        # outputfile name
+#-Q- sxnec #@$-me                        # sends a mail at the end of execution
+#-Q- sxnec #@$-eo                        # merge standard error and output
+#-Q- sxnec #@$-jo                        # print a short performance analysis
+#-Q- sxnec #@$-lT 00:30:00                # Max total CPU time
+#-Q- sxnec #@$-lt 00:30:00                # Max CPU time per process
+#-Q- sxnec #@$-lM 500Mb                    # Max memory
+#-Q- sxnec ##@$-c 4                     # Max number of simultaneous procs used (here=4)
+#-Q- sxnec ##@$-q multi                 # Use more than 1 proc
+#-Q- aix ##################
+#-Q- aix ## IBM   IDRIS  ##
+#-Q- aix ##################
+#-Q- aix #@job_name= :XXX:XXX:XXX:          
+#-Q- aix #@output= output_XXXXXXX.1          
+#-Q- aix #@error= error_XXXXXXX.1          
+#-Q- aix #@cpu_limit= 1800
+#-Q- aix #@stack_limit= 200Mb        
+#-Q- aix #@data_limit= 1.8Gb         
+#-Q- aix #@notification= complete
+#-Q- aix #@total_tasks= 1 
+#-Q- aix #@job_type= parallel
+#-Q- aix #@queue
+#-Q- sx8brodie ##################
+#-Q- sx8brodie ## SX8NEC IDRIS ##
+#-Q- sx8brodie ##################
+#-Q- sx8brodie #PBS -N :XXX:XXX:XXX:        # job name
+#-Q- sx8brodie #PBS -o output_XXXXXXX.1     # outputfile name
+#-Q- sx8brodie #PBS -j o                    # merge standard error and output
+#-Q- sx8brodie #PBS -S /usr/bin/ksh         # user shell
+#-Q- sx8brodie #PBS -l memsz_job=3.6gb      # Max memory
+#-Q- sx8brodie #PBS -l cputim_prc=1:01:00   # Max CPU time/prc
+#-Q- sx8brodie #PBS -l cputim_job=1:01:00   # Max CPU time/job
+#-Q- sx8brodie ##PBS -l cpunum_job=4
+#-Q- sx8brodie ##PBS -q multi
+#-Q- sx6nec ##################
+#-Q- sx6nec ## SX6NEC   CEA ##
+#-Q- sx6nec ##################
+#-Q- sx6nec #PBS -N :XXX:XXX:XXX:        # job name
+#-Q- sx6nec #PBS -o output_XXXXXXX.1     # outputfile name
+#-Q- sx6nec #PBS -j o                    # merge standard error and output
+#-Q- sx6nec #PBS -S /usr/bin/ksh         # user shell
+#-Q- sx6nec #PBS -l memsz_job=500mb      # Max memory
+#-Q- sx6nec #PBS -l cputim_job=00:30:00   # Max CPU time
+#-Q- sx6nec #PBS -q prod
+#-Q- sx6nec ##PBS -l cpunum_prc=4
+#-Q- sx6nec ##PBS -q parallel
+########################################################################
+##
+##      Script to run a short experiment when installing the
+##      GYRE configuration 
+##
+##            Rachid Benshila, OPA System Team
+##
+##
+#########################################################################
+##-- print echo of commands before and after shell interpretation
+date
+set -vx
+
+#################################
+# Beginning of user modification
+#################################
+
+##-- define some directories:
+#- Launching run repository
+#-Q- sxnec R_EXPER=${QSUB_WORKDIR:-${PWD}}
+#-Q- sx8brodie R_EXPER=${PBS_O_WORKDIR}
+#-Q- aix R_EXPER=${QSUB_WORKDIR:-${PWD}}
+#-Q- sx6nec R_EXPER=${PWD}
+#- modipsl repository
+R_EXEDIR=MMMMMMM     
+#- output files storing 
+R_SORTIE_OCE=AAAAAAA/GYRE
+#- execution repository
+R_TMP=$TMPDIR         
+
+#################################
+# End of user modification
+#################################
+
+[ -d ${R_TMP} ] || mkdir ${R_TMP}
+cd ${R_TMP}
+
+#--  get the executable
+#-Q- sxnec rcp ${LOGNAME}@rhodes:${R_EXEDIR}/bin/opa opa.xx
+#-Q- sx8brodie rcp ${LOGNAME}@brodie:${R_EXEDIR}/bin/opa opa.xx
+#-Q- aix cp ${R_EXEDIR}/bin/opa opa.xx
+#-Q- sx6nec cp ${R_EXEDIR}/bin/opa opa.xx
+chmod 777 opa.xx
+
+## --  Copy ancillary files
+#
+#- Namelist for the configuration 
+cp ${R_EXPER}/namelist namelist
+ls -alF
+
+#-Q- sxnec export F_PROGINF=yes
+#-Q- sxnec export F_ERRCNT=5
+#-Q- sx8brodie export F_PROGINF=yes
+#-Q- sx8brodie export F_ERRCNT=5
+#-Q- sx6nec export F_PROGINF=yes
+#-Q- sx6nec export F_ERRCNT=5
+
+#-Q- sxnec #- To be use for a mpp run
+#-Q- sxnec #mpirun -np ${NB_PROC} ./opa.xx
+#-Q- sx8brodie #- To be use for a mpp run
+#-Q- sx8brodie #mpirun -np ${NB_PROC} ./opa.xx
+#-Q- sx6nec #- To be use for a mpp run
+#-Q- sx6nec #mpirun -np ${NB_PROC} ./opa.xx
+
+./opa.xx
+
+## -- Save output files
+ls -alF
+#- to copy on a storage machine
+#-Q- sxnec DPUT=mfput
+#-Q- sx8brodie DPUT=mfput
+#-Q- aix DPUT=mfput
+#-Q- sx6nec DPUT=putfer 
+#-Q- sx6nec [ -d ${R_SORTIE_OCE} ] || mkdir -p ${R_SORTIE_OCE}
+
+#- Save ocean output files
+$DPUT ocean.output ${R_SORTIE_OCE}/ocean.output
+$DPUT solver.stat ${R_SORTIE_OCE}/solver.stat
+[ -f mpp.output* ] && $DPUT mpp.output* ${R_SORTIE_OCE}/.
+for file_netcdf in *_grid_*.nc
+do
+$DPUT $file_netcdf ${R_SORTIE_OCE}/$file_netcdf
+done
+#
+#- Save restart files
+for restart in *restart*
+do
+$DPUT $restart ${R_SORTIE_OCE}/$restart 
+done
+#
+#- Save ftrace file
+[ -f ftrace.out* ] && $DPUT ftrace.out* ${R_SORTIE_OCE}/.
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/namelist
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/namelist	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/EXP00/namelist	(revision 4536)
@@ -0,0 +1,757 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+! OPA namelist :  model option and parameter input
+! -------------
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!-----------------------------------------------------------------------
+!       namrun   parameters of the run
+!-----------------------------------------------------------------------
+!  no         job number
+!  cexper     experience name for vairmer format
+!  ln_rstart  boolean term for restart (true or false)
+!  nrstdt     control of the restart timestep:
+!                = 0 restart, do not control nit000 in the restart file.
+!                = 1 restart, control nit000 in the restart file. Do not
+!                    use the date in the restart file (use ndate0 in namelist)
+!                = 2 restart, control nit000 in the restart file, use the date
+!                    in the restart file. ndate0 in the namelist is ignored.
+!  nit000     number of the first time step
+!  nitend     number of the last time step
+!  ndate0     initial calendar date aammjj
+!  nleapy     Leap year calendar (0/1)
+!  ninist     initial state output flag (0/1)
+!  nstock     frequency of restart file
+!  nwrite     frequency of OUTPUT file
+!  nrunoff    = 0 no, 1 runoff, 2 runoff+river mouth ups adv
+!  ln_dimgnnn (F/T) 1 DIMG file - (for all proc/per proc)
+!
+!  CAUTION: for usual run scripts, logical value of
+!  *******  ln_rstart must be .true. or .false.
+!                     and NOT .TRUE. or .FALSE.
+&namrun
+   no         =       0
+   cexper     =  "GYRE"
+   ln_rstart  = .false.
+   nrstdt     =       0
+   nit000     =       1
+   nitend     =    4320
+   ndate0     =  010101
+   nleapy     =      30
+   ninist     =       0
+   nstock     =    4320 
+   nwrite     =      60 
+   nrunoff    =       0
+   ln_dimgnnn = .FALSE.
+/
+!-----------------------------------------------------------------------
+!       nam_ctl      Control prints & Benchmark
+!-----------------------------------------------------------------------
+!  ln_ctl     trends control print (expensive!)
+!  nprint     level of print (0 no print)
+!  nictls     start i indice to make the control SUM (very usefull to compare mono-
+!  nictle     end   i indice to make the control SUM (-versus multi processor runs)
+!  njctls     start j indice to make the control SUM (very usefull to compare mono-
+!  njctle     end   j indice to make the control SUM (-versus multi processor runs)
+!  nisplt     number of processors following i
+!  njsplt     number of processors following j
+!  nbench     Bench parameter (0/1): CAUTION it must be zero except for bench
+!             for which we don't care about physical meaning of the results
+!  nbit_cmp   bit comparison mode parameter (0/1): enables bit comparison between 
+!             single and multiple processor runs.
+&namctl
+   ln_ctl =  .false.
+   nprint =       0
+   nictls =       0
+   nictle =       0
+   njctls =       0
+   njctle =       0
+   isplt  =       1
+   jsplt  =       1
+   nbench =       0
+   nbit_cmp =     0
+/
+!-----------------------------------------------------------------------
+!       nam_mpp      Massively Parallel Processing
+!-----------------------------------------------------------------------
+!  c_mpi_send         mpi send/recieve type
+!                      = 'S'  : standard blocking send
+!                      = 'B'  : buffer blocking send
+!                      = 'I'  : immediate non-blocking send
+&nam_mpp
+   c_mpi_send =  'S'
+/
+!-----------------------------------------------------------------------
+!       nam_mpp_dyndist      Massively Parallel Distribution
+!              #ifdef ( key_agrif && key_mpp_dyndist )
+!-----------------------------------------------------------------------
+!  jpni   number of processors following i
+!  jpnj   number of processors following j
+!  jpnij  number of local domains
+&nam_mpp_dyndist
+   jpni  = 1
+   jpnj  = 1
+   jpnij = 1
+/
+!-----------------------------------------------------------------------
+!       nam_zgr       vertical coordinate
+!-----------------------------------------------------------------------
+!  ln_zco     z-coordinate - full steps      (T/F)
+!  ln_zps     z-coordinate - partial steps   (T/F)
+!  ln_sco     s- or hybrid z-s-coordinate    (T/F)
+&nam_zgr
+   ln_zco   =  .true.
+   ln_zps   =  .false.
+   ln_sco   =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_zgr_sco   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+!  sbot_min   minimum depth of s-bottom surface (>0) (m)
+!  sbot_max   maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+!  theta      surface control parameter (0<=theta<=20)
+!  thetb      bottom control parameter  (0<=thetb<= 1)
+!  r_max      maximum cut-off r-value allowed (0<r_max<1)
+&nam_zgr_sco
+   sbot_min =  300.
+   sbot_max = 5250.
+   theta    =    6.0
+   thetb    =    0.75
+   r_max    =    0.15
+/
+!-----------------------------------------------------------------------
+!       nam_traadv   advection scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_traadv_cen2     2nd order centered scheme    (default T)
+!  ln_traadv_tvd      TVD scheme                   (default F)
+!  ln_traadv_muscl    MUSCL scheme                 (default F)
+!  ln_traadv_muscl2   MUSCL2 scheme                (default F)
+!  ln_traadv_ubs      UBS scheme                   (default F)
+!  ln_traadv_qck      QUICKEST scheme              (default F)
+&nam_traadv
+   ln_traadv_cen2   =  .false.
+   ln_traadv_tvd    =  .true.
+   ln_traadv_muscl  =  .false.
+   ln_traadv_muscl2 =  .false.
+   ln_traadv_ubs    =  .false.
+   ln_traadv_qck    =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_traldf   lateral diffusion scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_traldf_lap    laplacian operator          (default T)
+!     ln_traldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_traldf_level  iso-level                   (default F)
+!     ln_traldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_traldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!     aht0    horizontal eddy diffusivity for tracers (m2/s)
+!     ahtb0   background eddy diffusivity for isopycnal diffusion (m2/s)
+!     aeiv0   eddy induced velocity coefficient (m2/s)
+! ^* require key_ldfslp to compute the direction of the lateral diffusion
+! ^** require key_ldfslp in s-coordinate
+&nam_traldf
+   ln_traldf_lap    =  .true.
+   ln_traldf_bilap  =  .false.
+   ln_traldf_level  =  .false.
+   ln_traldf_hor    =  .false.
+   ln_traldf_iso    =  .true.
+   aht0    =  1000.
+   ahtb0   =     0.
+   aeiv0   =  1000.
+/
+!-----------------------------------------------------------------------
+!       nam_dynldf   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_dynldf_lap    laplacian operator          (default T)
+!     ln_dynldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_dynldf_level  iso-level                   (default F)
+!     ln_dynldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_dynldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!  ahm0    horizontal eddy viscosity for the dynamics (m2/s)
+!  ahmb0   background eddy viscosity for isopycnal diffusion (m2/s)
+&nam_dynldf
+   ln_dynldf_lap    =  .true.
+   ln_dynldf_bilap  =  .false.
+   ln_dynldf_level  =  .false.
+   ln_dynldf_hor    =  .true.
+   ln_dynldf_iso    =  .false.
+   ahm0    = 100000.
+   ahmb0   =      0.
+/
+!-----------------------------------------------------------------------
+!       namflg   algorithm flags (algorithm not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynhpg_imp   hydrostatic pressure gradient: semi-implicit time scheme  (T)
+!                                                  centered      time scheme  (F)
+!   nn_dynhpg_rst  add dynhpg implicit variables in restart ot not (1/0)
+&namflg
+   ln_dynhpg_imp   =  .false.
+   nn_dynhpg_rst   =  0
+/
+!-----------------------------------------------------------------------
+!       nam_dynhpg   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+!  type of pressure gradient scheme (choose one only!)
+!     ln_hpg_zco    z-coordinate - full steps                   (default T)
+!     ln_hpg_zps    z-coordinate - partial steps (interpolation)
+!     ln_hpg_sco    s-coordinate (standard jacobian formulation)
+!     ln_hpg_hel    s-coordinate (helsinki modification)
+!     ln_hpg_wdj    s-coordinate (weighted density jacobian)
+!     ln_hpg_djc    s-coordinate (Density Jacobian with Cubic polynomial)
+!     ln_hpg_rot    s-coordinate (ROTated axes scheme)
+!  parameters
+!    gamm          weighting coefficient (wdj scheme)
+&nam_dynhpg
+   ln_hpg_zco = .true.
+   ln_hpg_zps = .false.
+   ln_hpg_sco = .false.
+   ln_hpg_hel = .false.
+   ln_hpg_wdj = .false.
+   ln_hpg_djc = .false.
+   ln_hpg_rot = .false.
+   gamm       = 0.e0
+/
+!-----------------------------------------------------------------------
+!       nam_dynadv   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynadv_vec      vector form flag
+!  ln_dynadv_cen2     flux form - 2nd order centered scheme    (default T)
+!  ln_dynadv_ubs      flux form - 3rd order UBS scheme         (default F)
+&nam_dynadv   
+   ln_dynadv_vec   = .TRUE.
+   ln_dynadv_cen2  = .FALSE.
+   ln_dynadv_ubs   = .FALSE.
+/  
+!-----------------------------------------------------------------------
+!       nam_dynvor   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynvor_ens   vorticity trends: enstrophy conserving scheme (default T)
+!  ln_dynvor_ene      "         "  : energy conserving scheme    (default F)
+!  ln_dynvor_mix      "         "  : mixed scheme                (default F)
+!  ln_dynvor_een      "         "  : energy & enstrophy scheme   (default F)
+&nam_dynvor
+   ln_dynvor_ene = .TRUE.
+   ln_dynvor_ens = .FALSE.
+   ln_dynvor_mix = .FALSE.
+   ln_dynvor_een = .FALSE.
+/
+!-----------------------------------------------------------------------
+!       namtau   surface wind stress
+!-----------------------------------------------------------------------
+!  ntau000   gently increase the stress over the first ntau_rst time-steps
+!  tau0x     uniform value used as default surface heat flux
+!  tau0y     uniform value used as default solar radiation flux
+&namtau
+   ntau000 =    100
+   tau0x   =      0.1e0
+   tau0y   =      0.e0
+/
+!-----------------------------------------------------------------------
+!       namflx   surface fluxes
+!-----------------------------------------------------------------------
+!  q0       uniform value used as default surface heat flux
+!  qsr0     uniform value used as default solar radiation flux
+!  emp0     uniform value used as default surface freswater budget (E-P)
+!  dqdt0    feedback coefficient for SST damping (W/m2/K)
+!  deds0    feedback coefficient for SSS damping (mm/day)
+&namflx
+   q0      =      0.e0
+   qsr0    =      0.e0
+   emp0    =      0.e0
+   dqdt0   =     -40.0
+   deds0   =      27.7
+/
+!-----------------------------------------------------------------------
+!       namalb   albedo parameters
+!-----------------------------------------------------------------------
+!  cgren    correction of the snow or ice albedo to take into account
+!  albice   albedo of melting ice in the arctic and antarctic
+!  alphd    coefficients for linear interpolation used to compute albedo
+!           between two extremes values (Pyane, 1972)
+!  alphc     "                                         "
+!  alphdi    "                                         "
+&namalb
+   cgren    =      0.06
+   albice   =      0.5
+   alphd    =      0.80
+   alphc    =      0.65
+   alphdi   =      0.72
+/
+!-----------------------------------------------------------------------
+!       namdom   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+!  ntopo      = 0/1 ,compute/read the bathymetry file
+!               (mbathy, nb of T-ocean levels)
+!  e3zps_min  the thickness of the partial step is set larger than the
+!  e3zps_rat     the minimum of e3zps_min and e3zps_rat * e3t
+!                (N.B. 0<e3zps_rat<1)
+!  nmsh       =1 create a mesh file (coordinates, scale factors, masks)
+!  nacc       the acceleration of convergence method
+!             = 0, no acceleration, rdt = rdttra
+!             = 1, acceleration used, rdt < rdttra(k)
+!  atfp       asselin time filter parameter
+!  rdt        time step for the dynamics (and tracer if nacc=0)
+!  rdtmin     minimum time step on tracers
+!  rdtmax     maximum time step on tracers
+!  rdth       depth variation of tracer time step
+!  rdtbt      barotropic time step (for the time splitting algorithm)
+!  nfice      frequency of ice model call
+!  nfbulk     frequency of bulk formulea call (not used if ice used)
+!  nclosea    = 0 no closed sea 
+!             = 1 closed sea (Black Sea, Caspian Sea, Great US Lakes...) 
+&namdom
+   ntopo     =     0
+   e3zps_min =     5.
+   e3zps_rat =     0.1
+   nmsh      =     0
+   nacc      =     0
+   atfp      =     0.1
+   rdt       =  7200.
+   rdtmin    =  7200.
+   rdtmax    =  7200.
+   rdth      =   800.
+   rdtbt     =   120.
+   nfice     =     5  
+   nfbulk    =     5  
+   nclosea   =     0
+/
+!-----------------------------------------------------------------------
+!       namfwb   freshwater budget correction
+!-----------------------------------------------------------------------
+!  ln_fwb     logical flag for freshwater budget correction (0 annual mean)
+&namfwb
+   ln_fwb    = .false.
+/
+!-----------------------------------------------------------------------
+!       namptr   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+!  ln_diaptr  logical flag for Poleward transport computation
+!  ln_subbas  logical flag for Atlantic/Pacific/Indian basins computation
+!             need input basins mask file named "subbasins.nc"
+!  nf_ptr     Frequency of computation
+&namptr
+   ln_diaptr = .false.
+   ln_subbas = .false.
+   nf_ptr    =  15
+/
+!-----------------------------------------------------------------------
+!       namcro   cross land advection
+!-----------------------------------------------------------------------
+!  n_cla   advection between 2 ocean pts separates by land 
+&namcla
+   n_cla   = 0
+/
+!-----------------------------------------------------------------------
+!       namzdf   vertical physics
+!-----------------------------------------------------------------------
+!  ln_zdfevd  enhanced vertical diffusion         (default T)
+!  ln_zdfnpc  Non-Penetrative Convection          (default T)
+!  avm0       vertical eddy viscosity for the dynamic (m2/s)
+!  avt0       vertical eddy diffusivity for tracers (m2/s)
+!  avevd      vertical coefficient for enhanced diffusion scheme (m2/s)
+!  nevdm      = 0  apply enhanced mixing on tracer only
+!             = 1  apply enhanced mixing on both tracer and momentum
+!  ln_zdfexp   vertical physics: (=T)  time splitting (T)     (Default=F)
+!                               (=F)  euler backward (F)
+!  n_zdfexp   number of sub-timestep for time splitting scheme
+&namzdf
+   ln_zdfevd = .true.
+   ln_zdfnpc = .false.
+   avm0      = 1.2e-4
+   avt0      = 1.2e-5
+   avevd     =   100.
+   n_evdm    =     1
+   ln_zdfexp =  .false.
+   n_zdfexp  =     3
+/
+!-----------------------------------------------------------------------
+!       namnpc   vnon penetrative convection
+!-----------------------------------------------------------------------
+!  nnpc1   non penetrative convective scheme frequency
+!  nnpc2   non penetrative convective scheme print frequency
+&namnpc
+   nnpc1  =      1
+   nnpc2  =    365
+/
+!-----------------------------------------------------------------------
+!       nambbl   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+!  atrbbl   lateral tracer coeff. for bottom boundary layer scheme(m2/s)
+&nambbl
+   atrbbl = 10000.
+/
+!-----------------------------------------------------------------------
+!       namric   richardson number dependent vertical diffusion
+!                ( #ifdef "key_zdfrichardson" )
+!-----------------------------------------------------------------------
+!  avmri   maximum value of the vertical viscosity
+!  alp     coefficient of the parameterization
+!  nric    coefficient of the parameterization
+&namric
+   avmri = 100.e-4
+   alp   =      5.
+   nric  =       2
+/
+!-----------------------------------------------------------------------
+!       namtke   turbulent eddy kinetic dependent vertical diffusion
+!                ( #ifdef "key_zdftke" )
+!-----------------------------------------------------------------------
+!  ln_rstke flag to restart with tke from a run without tke (default F)
+!  ediff    coef. to compute vertical eddy coef. (avt=ediff*mxl*sqrt(e) )
+!  ediss    coef. of the Kolmogoroff dissipation  
+!  ebb      coef. of the surface input of tke
+!  efave    coef. to applied to the tke diffusion ( avtke=efave*avm )
+!  emin     minimum value of tke (m^2/s^2)
+!  emin0    surface minimum value of tke (m^2/s^2)
+!  nitke    number of restart iterative loops
+!  ri_c     critic richardson number
+!  nmxl     flag on mixing length used
+!           = 0 bounded by the distance to surface and bottom
+!           = 1 bounded by the local vertical scale factor
+!           = 2 first vertical derivative of mixing length bounded by 1
+!  npdl     flag on prandtl number
+!           = 0 no vertical prandtl number (avt=avm)
+!           = 1 prandtl number function of richarson number (avt=pdl*avm)
+!           = 2 same as = 1 but a shapiro filter is applied on pdl
+!  nave     =  horizontal averaged (=1) or not (=0) of avt  (default =1)
+!  navb     = 0 cst background avt0, avm0 / =1 profile used on avtb
+&namtke
+   ln_rstke = .false.
+   ediff =       0.1
+   ediss =       0.7
+   ebb   =      3.75
+   efave =        1.
+   emin  =     1.e-5 
+   emin0 =     1.e-4
+   nitke =        50
+   nmxl  =         2
+   npdl  =         1
+   navb  =         0
+/
+!-----------------------------------------------------------------------
+!       namkpp   K-Profile Parameterization dependent vertical diffusion
+!                ( #ifdef "key_zdfkpp" )
+!-----------------------------------------------------------------------
+!  ln_kpprimix   shear instability mixing  (default T)
+!  difmiw        constant internal wave viscosity (m2/s)
+!  difsiw        constant internal wave diffusivity (m2/s)
+!  Riinfty       local Richardson Number limit for shear instability
+!  difri         maximum shear mixing at Rig = 0    (m2/s)
+!  bvsqcon       Brunt-Vaisala squared (1/s**2) for maximum convection
+!  difcon        maximum mixing in interior convection (m2/s)
+!  nave          = 0/1 flag for horizontal average on avt, avmu, avmv
+!  navb          = 0/1 flag for constant or profile background avt
+&namkpp
+   ln_kpprimix  = .true.
+   difmiw       =  1.e-04
+   difsiw       =  0.1e-04
+   Riinfty      =  0.8
+   difri        =  0.0050
+   bvsqcon      = -0.01e-07
+   difcon       =  1.
+   navb         =  0
+   nave         =  1
+/
+!-----------------------------------------------------------------------
+!       namddm   double diffusive mixing parameterization
+!-----------------------------------------------------------------------
+!   avts    maximum avs for dd mixing 
+!   hsbfr   heat/salt buoyancy flux ratio
+&namddm
+      avts  = 1.e-4
+      hsbfr = 1.6
+/
+!-----------------------------------------------------------------------
+!       namlbc   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+!  shlat   lateral boundary condition on velocity
+!                   shlat = 0 , free slip
+!               0 < shlat < 2 , partial slip
+!                   shlat = 2 , no slip
+!               2 < shlat     , strong slip
+&namlbc
+   shlat  =      0.
+/
+!-----------------------------------------------------------------------
+!       nambfr   bottom friction
+!-----------------------------------------------------------------------
+!  nbotfr  type of bottom friction 
+!                  nbotfr = 0 , no slip 
+!                  nbotfr = 1 , linear friction
+!                  nbotfr = 2 , nonlinear friction
+!                  nbotfr = 3 , free slip
+!  bfri1   bottom drag coefficient (linear case)
+!  bfri2   bottom drag coefficient (non linear case)
+!  bfeb2   bottom turbulent kinetic energy  (m^2/s^2)
+&nambfr
+   nbotfr =       2
+   bfri1  =   4.e-4
+   bfri2  =   1.e-3
+   bfeb2  =  2.5e-3
+/
+!-----------------------------------------------------------------------
+!       nambbc   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+!  ngeo_flux  = 0 no geothermal heat flux
+!             = 1 constant geothermal heat flux
+!             = 2 variable geothermal heat flux (read in geothermal_heating.nc) 
+!                 ( C A U T I O N : flux in mW/m2 in the NetCDF file )
+!  ngeo_flux_const   Constant value of geothermal heat flux (W/m2) 
+&nambbc
+   ngeo_flux =  0
+   ngeo_flux_const = 86.4e-3
+/
+!-----------------------------------------------------------------------
+!       namqsr   penetrative solar radiation
+!-----------------------------------------------------------------------
+!  ln_traqsr : penetrative solar radiation (T) or not (F)     (Default=T)
+!  rabs       fraction of qsr associated with xsi1
+!  xsi1       first depth of extinction
+!  xsi2       second depth of extinction
+&namqsr
+   ln_traqsr = .true.
+   rabs     =   0.58
+   xsi1     =   0.35
+   xsi2     =   23.0
+/
+!-----------------------------------------------------------------------
+!       namtdp   tracer newtonian damping ('key_tradmp')
+!-----------------------------------------------------------------------
+!  ndmp    type of damping in temperature and salinity 
+!          (='latitude', damping poleward of 'ndmp' degrees and function 
+!             of the distance-to-coast. Red and Med Seas as ndmp=-1)
+!          (=-1 damping only in Med and Red Seas)
+!  ndmpf   =1 create a damping.coeff NetCDF file (the 3D damping array)
+!  nmldmp  type of damping in the mixed layer
+!          (=0 damping throughout the water column)
+!	   (=1 no damping in the mixed layer defined by avt >5cm2/s )
+!	   (=2 no damping in the mixed layer defined rho<rho(surf)+.01 )
+!  sdmp    surface time scale for internal damping (days)
+!  bdmp    bottom time scale for internal damping (days)
+!  hdmp    depth of transition between sdmp and bdmp (meters)
+&namtdp
+   ndmp   =   -1
+   ndmpf  =    1
+   nmldmp =    1
+   sdmp   =  50.
+   bdmp   = 360.
+   hdmp   = 800.
+/
+!-----------------------------------------------------------------------
+!       nameos   ocean physical parameters
+!-----------------------------------------------------------------------
+!  neos    type of equation of state and Brunt-Vaisala frequency
+!          = 0, UNESCO (formulation of Jackett and McDougall (1994)
+!                                         and of McDougall (1987) )
+!          = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+!          = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+!                               with rau0=1020 set in parcst routine
+!  ralpha  thermal expension coefficient (linear equation of state)
+!  rbeta   saline  expension coefficient (linear equation of state)
+&nameos
+   neos   =      2
+   ralpha =  2.e-4
+   rbeta  =  7.7e-4
+/
+!-----------------------------------------------------------------------
+!       namsol   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+!  nsolv     elliptic solver (=1 preconditioned conjugate gradient: pcg)
+!                            (=2 successive-over-relaxation: sor)
+!                            (=3 FETI: fet, all require "key_feti" defined)
+!                            (=4 sor with extra outer halo)
+!  nsol_arp  absolute/relative (0/1) precision convergence test
+!  nmin      minimum of iterations for the SOR solver
+!  nmax      maximum of iterations for the SOR solver
+!  nmod      frequency of test for the SOR solver
+!  eps       absolute precision of the solver
+!  resmax    absolute precision for the SOR solver
+!  sor       optimal coefficient for SOR solver
+!  epsisl    absolute precision on stream function solver
+!  nmisl     maximum pcg iterations for island
+!  rnu       strength of the additional force used in free surface b.c.
+&namsol
+   nsolv     =      2
+   nsol_arp  =      0
+   nmin      =    210
+   nmax      =    800
+   nmod      =     10
+   eps       =  1.E-6
+   resmax    = 1.E-10
+   sor       =   1.96
+   epsisl    = 1.e-10
+   nmisl     =   4000
+   rnu       =     1.
+/
+!=======================================================================
+!   Diagnostics namelists
+!       namtrd    dynamics and/or tracer trends
+!       namgap    level mean model-data gap
+!       namznl    zonal mean heat & freshwater fluxes computation
+!       namspr    surface pressure in rigid-lid
+!=======================================================================
+!-----------------------------------------------------------------------
+!       namtrd    diagnostics on dynamics and/or tracer trends
+!                         ('key_trdyn' and/or 'key_trdtra')
+!                 or mixed-layer trends ('key_trdmld')
+!-----------------------------------------------------------------------
+!  ntrd              time step frequency dynamics and tracers trends
+!  nctls             control surface type in mixed-layer trends (0,1 or n<jpk)
+!  ln_trdmld_restart restart for ML diagnostics
+!  ucf               unit conversion factor (=1 -> /seconds | =86400. -> /day)
+!  ln_trdmld_instant flag to diagnose trends of instantantaneous or mean ML T/S
+&namtrd
+   ntrd  = 365
+   nctls =   0
+   ln_trdmld_restart = .false.
+   ucf   =  1.
+   ln_trdmld_instant = .false.
+/
+!-----------------------------------------------------------------------
+!       namgap    level mean model-data gap ('key_diagap')
+!-----------------------------------------------------------------------
+!  ngap    time-step frequency of model-data gap computation
+!  nprg    time-step frequency of gap print in model output
+&namgap
+   ngap =  15
+   nprg =  10
+/
+!-----------------------------------------------------------------------
+!       namznl    zonal mean heat & freshwater fluxes computation
+!                 (#ifdef "key_diaznl")
+!-----------------------------------------------------------------------
+!  nfznl   time-step frequency of zonal mean fluxes computation
+&namznl
+   nfznl =  15
+/
+!-----------------------------------------------------------------------
+!       namspr  surface pressure diagnostic
+!-----------------------------------------------------------------------
+!  nmaxp   maximum of iterations for the solver
+!  epsp    absolute precision of the solver
+!  niterp  number of iteration done by the solver
+&namspr
+   nmaxp   =   1000
+   epsp    =  1.e-3
+   niterp  =    400
+/
+!-----------------------------------------------------------------------
+!       namcpl    coupled ocean/atmosphere model  (#ifdef "key_coupled")
+!-----------------------------------------------------------------------
+!  nexco   coupling frequency in time steps
+!  cchan   coupling technique 'PIPE' or 'CLIM'
+&namcpl
+   nexco            =         24
+   cchan            =     'PIPE'
+   nmodcpl          =          2
+   cplmodnam        =   'opa.xx'
+   cploasis         =    'Oasis'
+   nfldo2c          =          2
+   nflxc2o          =          6
+   ntauc2o          =          4
+   cpl_writ(1)      = 'SOSSTSST'
+   cpl_f_writ(1)    =   'ocesst'
+   cpl_writ(2)      = 'SOICECOV'
+   cpl_f_writ(2)    =   'oceice'
+   cpl_readflx(1)   = 'SONSFLDO'
+   cpl_f_readflx(1) =   'oceflx'
+   cpl_readflx(2)   = 'SOSHFLDO'
+   cpl_f_readflx(2) =   'oceflx'
+   cpl_readflx(3)   = 'SOTOPRSU'
+   cpl_f_readflx(3) =   'oceflx'
+   cpl_readflx(4)   = 'SOTFSHSU'
+   cpl_f_readflx(4) =   'oceflx'
+   cpl_readflx(5)   = 'SORUNCOA'
+   cpl_f_readflx(5) =   'oceflx'
+   cpl_readflx(6)   = 'SORIVFLU'
+   cpl_f_readflx(6) =   'oceflx'
+   cpl_readtau(1)   = 'SOZOTAUX'
+   cpl_f_readtau(1) =   'ocetau'
+   cpl_readtau(2)   = 'SOZOTAU2'
+   cpl_f_readtau(2) =   'ocetau'
+   cpl_readtau(3)   = 'SOMETAUY'
+   cpl_f_readtau(3) =   'ocetau'
+   cpl_readtau(4)   = 'SOMETAU2'
+   cpl_f_readtau(4) =   'ocetau'
+/
+!-----------------------------------------------------------------------
+!       namobc    open boundaries parameters (#ifdef key_obc)
+!-----------------------------------------------------------------------
+!  nobc_dta   = 0 the obc data are equal to the initial state
+!             = 1 the obc data are read in 'obc   .dta' files
+!  rdpeob  time relaxation (days) for the east open boundary
+!  rdpwob  time relaxation (days) for the west open boundary
+!  rdpnob  time relaxation (days) for the north open boundary
+!  rdpsob  time relaxation (days) for the south open boundary
+!  zbsic1  barotropic stream function on isolated coastline 1
+!  zbsic2  barotropic stream function on isolated coastline 2
+!  zbsic3  barotropic stream function on isolated coastline 3
+!  ln_obc_clim  climatological obc data files (default T)
+!  ln_vol_cst   total volume conserved
+&namobc
+    nobc_dta =    0
+    rdpein   =    1.
+    rdpwin   =    1.
+    rdpnin   =   30.
+    rdpsin   =    1.
+    rdpeob   = 1500.
+    rdpwob   =   15.
+    rdpnob   =  150.
+    rdpsob   =   15.
+    zbsic1   =  140.e+6
+    zbsic2   =    1.e+6
+    zbsic3   =    0.
+    ln_obc_clim = .true.
+    ln_vol_cst  = .false.
+/
+!-----------------------------------------------------------------------
+!       namflo    float parameters (#ifdef key_float)
+!-----------------------------------------------------------------------
+!  ln_rstflo   boolean term for float restart (true or false)
+!  nwritefl   frequency of float output file 
+!  nstockfl   frequency of float restart file 
+!  ln_argo    Argo type floats (stay at the surface each 10 days)
+!  ln_flork4  = T trajectories computed with a 4th order Runge-Kutta
+!             = F  (default)   computed with Blanke' scheme
+&namflo
+    ln_rstflo = .false.
+    nwritefl  =      75
+    nstockfl  =    5475
+    ln_argo   = .false.
+    ln_flork4 = .false.
+/
+!-----------------------------------------------------------------------
+!       namcore  CORE
+!-----------------------------------------------------------------------
+!  
+!  In this version there are 8 files ( jpfile = 8)
+!  THE ORDER OF THE FILES MATTER:                      
+!  1 - precipitation total (rain+snow)  in kg/m2/s
+!  2,3 -  u10,v10 -> scalar wind at 10m in m/s -  ON 'T' GRID POINTS!!!
+!  4 - solar radiation (short wave)     in W/m2
+!  5 - thermal radiation (long wave)    in W/m2
+!  6 - specific humidity                in %
+!  7 - temperature at 10m               in degrees K
+!  8 - precipitation (snow only)        in kg/m2/s
+!  
+!  ln_2m         boolean (default F), used to indicate that Tair & humidity 
+!                are given at 2m. In this case, the default file names & 
+!                variables are t2.nc, t2, q2.nc, q2
+!  alpha_precip  real coefficient used as a multiplying  factor  for the precip
+!  clname        file names (256 char max for each)
+!  clvarname     name of variable in netcdf file (32 char max)
+!  freqh         frequency of fields in the file
+!                it is in hours (6 hourly, daily) if positive.
+!                if freqh = -12 the file contains 12 monthly data.
+&namcore
+   ln_2m        = .FALSE.
+   alpha_precip = 1.
+   clname    = 'precip.nc' 'u10.nc' 'q10.nc' 'v10.nc' 'radsw.nc' 'radlw.nc' 't10.nc' 'snow.nc'
+   clvarname =  'precip'    'u10'    'q10'    'v10'    'radsw'    'radlw'    't10'    'snow'
+   freqh     =    -12        24        24       24       24         24        24       -12
+/
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make	(revision 4536)
@@ -0,0 +1,11967 @@
+# $Header$
+# some variables
+TMP = ../../../tmp
+#-Q- sx8mercure  # Compiler options NEMO (CEA SX6-NEC) 
+#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -C vopt -Wf"-P nh" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8mercure  F_F = $(F_O) -f3
+#-Q- sx8mercure  L_X = $(L_O) -ftrace
+#-Q- sx8brodie  # Compiler options NEMO (CEA SX6-NEC) 
+#-Q- sx8brodie  F_O = -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8brodie  F_F = $(F_O) -f3
+#-Q- sx8brodie  L_X = $(L_O)
+#-Q- sxdkrz  # Compiler options for NEMO (DKRZ SX6-NEC) 
+#-Q- sxdkrz  F_O = -ew -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sxdkrz  F_F = $(F_O) -f3
+#-Q- sxdkrz  L_X = $(L_O) -ftrace
+#-Q- eshpux  # Compiler options for NEMO (Earth Simulator)
+#-Q- eshpux  # for super perfs!
+#-Q- eshpux  # F_O = $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- eshpux  # regular options!
+#-Q- eshpux  F_O = $(FTRACE) -Wf,-A idbl4 -C vopt -P stack -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- eshpux  F_F = $(F_O) -f3
+#-Q- eshpux  L_X = $(L_O)
+#-Q- linux  # Compiler options for NEMO (pgf version)
+#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- linux  F_F = $(F_O)-Mextend
+#-Q- linux  L_X = -r8 -O3
+#-Q- lxiv7  # Compiler options for NEMO (ifc version)
+#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- lxiv7  F_F = $(F_O) -extend_source 
+#-Q- lxiv7  L_X = -r8 -O3
+#-Q- lxiv8  # Compiler options for NEMO (ifort version)
+#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- lxiv8  F_F = $(F_O) -extend_source 
+#-Q- lxiv8  L_X = -r8 -O3
+#-Q- g95  # Compiler options for NEMO (g95 version)
+#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- g95  F_F = $(F_O)-ffixed-form -ffixed-line-length-132
+#-Q- g95  L_X = -r8 -O3
+#-Q- aix    # Compiler options for NEMO (aix version)
+#-Q- aix    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- aix    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- aix   L_O = $(F_P) -q64 -O3
+#-Q- aix   L_X = $(L_O)
+#-Q- osxxlf    # Compiler options for NEMO (osxxlf version)
+#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- osxxlf    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- osxxlf    L_X = -qrealsize=8 -O3
+PREF=
+#-Q- sx8mercure	PREF=i.
+#-Q- sx8brodie	PREF=i.
+#-Q- sxdkrz	PREF=i.
+#-Q- eshpux	PREF=i.
+
+# add suffix to P_P
+P_P := $(P_P:%=$(prefix)%)
+
+# Some tests to define variables related to Agrif compilation
+# Please do not change 
+ifneq (,$(findstring key_agrif,$(P_P)))
+AGRIF=use
+else
+AGRIF=notuse
+AGRIF_LIB=
+endif
+ifneq (,$(findstring key_mpp_mpi,$(P_P)))
+AGRIF_MPI=-DAGRIF_MPI
+else
+AGRIF_MPI=
+endif
+
+KEY_LIST = \
+     key_agrif \
+     key_agrif \
+     key_agrif \
+     key_agrif \
+     key_antarctic \
+     key_arctic \
+     key_cfg_1d \
+     key_cfg_1d \
+     key_coupled \
+     key_coupled \
+     key_coupled \
+     key_coupled \
+     key_cpl_albedo \
+     key_cpl_discharge \
+     key_cpl_ocevel \
+     key_cpl_rootexchg \
+     key_diaeiv \
+     key_diagap \
+     key_diahdy \
+     key_diahth \
+     key_diahth \
+     key_diainstant \
+     key_diainstant \
+     key_diaspr \
+     key_diaspr \
+     key_diaspr \
+     key_dimgout \
+     key_dimgout \
+     key_dtasal \
+     key_dtasal \
+     key_dtasss \
+     key_dtasst \
+     key_dtatem \
+     key_dtatem \
+     key_dynldf_c1d \
+     key_dynldf_c2d \
+     key_dynldf_c3d \
+     key_dynspg_exp \
+     key_dynspg_exp \
+     key_dynspg_exp \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_ts \
+     key_dynspg_ts \
+     key_dynspg_ts \
+     key_eel_r2 \
+     key_eel_r5 \
+     key_eel_r6 \
+     key_esopa \
+     key_esopa \
+     key_feti \
+     key_floats \
+     key_flx_bulk_daily \
+     key_flx_bulk_monthly \
+     key_flx_bulk_monthly \
+     key_flx_core \
+     key_flx_core \
+     key_flx_forced_daily \
+     key_gyre \
+     key_ice_lim \
+     key_ice_lim \
+     key_ice_lim \
+     key_ice_lim \
+     key_islands \
+     key_kppcustom \
+     key_kppcustom \
+     key_kpplktb \
+     key_ldfslp \
+     key_ldfslp \
+     key_lim_cp1 \
+     key_lim_cp1 \
+     key_lim_cp2 \
+     key_lim_cp3 \
+     key_lim_fdd \
+     key_lim_fdd \
+     key_lim_fdd \
+     key_mpp_dyndist \
+     key_mpp_mpi \
+     key_mpp_mpi \
+     key_mpp_omp \
+     key_mpp_shmem \
+     key_noslip_accurate \
+     key_oasis3 \
+     key_oasis3 \
+     key_oasis3 \
+     key_oasis4 \
+     key_obc \
+     key_obc \
+     key_obc \
+     key_orca_lev10 \
+     key_orca_r025 \
+     key_orca_r05 \
+     key_orca_r2 \
+     key_orca_r2 \
+     key_orca_r4 \
+     key_passivetrc \
+     key_passivetrc \
+     key_tau_daily \
+     key_tau_monthly \
+     key_trabbc \
+     key_trabbl_adv \
+     key_trabbl_adv \
+     key_trabbl_dif \
+     key_trabbl_dif \
+     key_tradmp \
+     key_tradmp \
+     key_traldf_ano \
+     key_traldf_c1d \
+     key_traldf_c2d \
+     key_traldf_c2d \
+     key_traldf_c3d \
+     key_traldf_eiv \
+     key_traldf_eiv \
+     key_traldf_eiv \
+     key_trc_pisces \
+     key_trddyn \
+     key_trddyn \
+     key_trddyn \
+     key_trdmld \
+     key_trdmld \
+     key_trdtra \
+     key_trdtra \
+     key_trdtra \
+     key_trdvor \
+     key_trdvor \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_memory \
+     key_vvl \
+     key_zco \
+     key_zco \
+     key_zdfcst \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfkpp \
+     key_zdfkpp \
+     key_zdfric \
+     key_zdftke \
+     key_zdftke 
+# .o file list in the library
+LIB_OBJ = \
+		$(MODEL_LIB)(lib_cray.o)\
+		$(MODEL_LIB)(lib_isml.o)\
+		$(MODEL_LIB)(lib_print.o)\
+		$(MODEL_LIB)(agrif_opa_interp.o)\
+		$(MODEL_LIB)(agrif_opa_sponge.o)\
+		$(MODEL_LIB)(agrif_opa_update.o)\
+		$(MODEL_LIB)(albedo.o)\
+		$(MODEL_LIB)(blk_oce.o)\
+		$(MODEL_LIB)(bulk.o)\
+		$(MODEL_LIB)(cla_div.o)\
+		$(MODEL_LIB)(cla_dynspg.o)\
+		$(MODEL_LIB)(cla.o)\
+		$(MODEL_LIB)(closea.o)\
+		$(MODEL_LIB)(cpl.o)\
+		$(MODEL_LIB)(cpl_oasis3.o)\
+		$(MODEL_LIB)(cpl_oasis4.o)\
+		$(MODEL_LIB)(cpl_oce.o)\
+		$(MODEL_LIB)(ctlopn.o)\
+		$(MODEL_LIB)(daymod.o)\
+		$(MODEL_LIB)(diadimg.o)\
+		$(MODEL_LIB)(diafwb.o)\
+		$(MODEL_LIB)(diagap.o)\
+		$(MODEL_LIB)(diahdy.o)\
+		$(MODEL_LIB)(diahth.o)\
+		$(MODEL_LIB)(dianam.o)\
+		$(MODEL_LIB)(diaptr.o)\
+		$(MODEL_LIB)(diaspr.o)\
+		$(MODEL_LIB)(diawri1d.o)\
+		$(MODEL_LIB)(diawri.o)\
+		$(MODEL_LIB)(divcur.o)\
+		$(MODEL_LIB)(domain.o)\
+		$(MODEL_LIB)(domcfg.o)\
+		$(MODEL_LIB)(domhgr.o)\
+		$(MODEL_LIB)(dom_ice.o)\
+		$(MODEL_LIB)(dommsk.o)\
+		$(MODEL_LIB)(dom_oce.o)\
+		$(MODEL_LIB)(domstp.o)\
+		$(MODEL_LIB)(domvvl.o)\
+		$(MODEL_LIB)(domwri.o)\
+		$(MODEL_LIB)(domzgr.o)\
+		$(MODEL_LIB)(dtasal.o)\
+		$(MODEL_LIB)(dtasss.o)\
+		$(MODEL_LIB)(dtasst.o)\
+		$(MODEL_LIB)(dtatem.o)\
+		$(MODEL_LIB)(dynadv_cen2.o)\
+		$(MODEL_LIB)(dynadv.o)\
+		$(MODEL_LIB)(dynadv_ubs.o)\
+		$(MODEL_LIB)(dyncor1d.o)\
+		$(MODEL_LIB)(dynhpg.o)\
+		$(MODEL_LIB)(dynhpg_jki.o)\
+		$(MODEL_LIB)(dynkeg.o)\
+		$(MODEL_LIB)(dynldf_bilap.o)\
+		$(MODEL_LIB)(dynldf_bilapg.o)\
+		$(MODEL_LIB)(dynldf.o)\
+		$(MODEL_LIB)(dynldf_iso.o)\
+		$(MODEL_LIB)(dynldf_lap.o)\
+		$(MODEL_LIB)(dynnxt1d.o)\
+		$(MODEL_LIB)(dynnxt.o)\
+		$(MODEL_LIB)(dynspg_exp.o)\
+		$(MODEL_LIB)(dynspg_exp_jki.o)\
+		$(MODEL_LIB)(dynspg.o)\
+		$(MODEL_LIB)(dynspg_flt.o)\
+		$(MODEL_LIB)(dynspg_flt_jki.o)\
+		$(MODEL_LIB)(dynspg_oce.o)\
+		$(MODEL_LIB)(dynspg_rl.o)\
+		$(MODEL_LIB)(dynspg_ts.o)\
+		$(MODEL_LIB)(dynspg_ts_jki.o)\
+		$(MODEL_LIB)(dynvor.o)\
+		$(MODEL_LIB)(dynzad.o)\
+		$(MODEL_LIB)(dynzdf_exp.o)\
+		$(MODEL_LIB)(dynzdf.o)\
+		$(MODEL_LIB)(dynzdf_imp.o)\
+		$(MODEL_LIB)(dynzdf_imp_jki.o)\
+		$(MODEL_LIB)(eosbn2.o)\
+		$(MODEL_LIB)(flo4rk.o)\
+		$(MODEL_LIB)(floats.o)\
+		$(MODEL_LIB)(floblk.o)\
+		$(MODEL_LIB)(flodom.o)\
+		$(MODEL_LIB)(flo_oce.o)\
+		$(MODEL_LIB)(flowri.o)\
+		$(MODEL_LIB)(flxblk.o)\
+		$(MODEL_LIB)(flxfwb.o)\
+		$(MODEL_LIB)(flxmod.o)\
+		$(MODEL_LIB)(flx_oce.o)\
+		$(MODEL_LIB)(flxrnf.o)\
+		$(MODEL_LIB)(geo2ocean.o)\
+		$(MODEL_LIB)(ice.o)\
+		$(MODEL_LIB)(iceini.o)\
+		$(MODEL_LIB)(ice_oce.o)\
+		$(MODEL_LIB)(icestp1d.o)\
+		$(MODEL_LIB)(icestp.o)\
+		$(MODEL_LIB)(ini1d.o)\
+		$(MODEL_LIB)(initrc.o)\
+		$(MODEL_LIB)(in_out_manager.o)\
+		$(MODEL_LIB)(iom_def.o)\
+		$(MODEL_LIB)(iom.o)\
+		$(MODEL_LIB)(iom_ioipsl.o)\
+		$(MODEL_LIB)(iom_nf90.o)\
+		$(MODEL_LIB)(iom_rstdimg.o)\
+		$(MODEL_LIB)(istate.o)\
+		$(MODEL_LIB)(lbclnk.o)\
+		$(MODEL_LIB)(ldfdyn.o)\
+		$(MODEL_LIB)(ldfdyn_oce.o)\
+		$(MODEL_LIB)(ldfeiv.o)\
+		$(MODEL_LIB)(ldfslp.o)\
+		$(MODEL_LIB)(ldftra.o)\
+		$(MODEL_LIB)(ldftra_oce.o)\
+		$(MODEL_LIB)(lib_feti.o)\
+		$(MODEL_LIB)(lib_mpp.o)\
+		$(MODEL_LIB)(limadv.o)\
+		$(MODEL_LIB)(limdia.o)\
+		$(MODEL_LIB)(limdmp.o)\
+		$(MODEL_LIB)(limdyn.o)\
+		$(MODEL_LIB)(limflx.o)\
+		$(MODEL_LIB)(limhdf.o)\
+		$(MODEL_LIB)(limistate.o)\
+		$(MODEL_LIB)(limmsh.o)\
+		$(MODEL_LIB)(limrhg.o)\
+		$(MODEL_LIB)(limrst.o)\
+		$(MODEL_LIB)(limtab.o)\
+		$(MODEL_LIB)(limthd.o)\
+		$(MODEL_LIB)(limthd_lac.o)\
+		$(MODEL_LIB)(limthd_zdf.o)\
+		$(MODEL_LIB)(limtrp.o)\
+		$(MODEL_LIB)(limwri.o)\
+		$(MODEL_LIB)(mppini.o)\
+		$(MODEL_LIB)(oasis4_date.o)\
+		$(MODEL_LIB)(obccli.o)\
+		$(MODEL_LIB)(obcdom.o)\
+		$(MODEL_LIB)(obcdta.o)\
+		$(MODEL_LIB)(obcdyn_bt.o)\
+		$(MODEL_LIB)(obcdyn.o)\
+		$(MODEL_LIB)(obcfla.o)\
+		$(MODEL_LIB)(obcini.o)\
+		$(MODEL_LIB)(obc_oce.o)\
+		$(MODEL_LIB)(obc_par.o)\
+		$(MODEL_LIB)(obcrad.o)\
+		$(MODEL_LIB)(obcrst.o)\
+		$(MODEL_LIB)(obcspg.o)\
+		$(MODEL_LIB)(obctra.o)\
+		$(MODEL_LIB)(obcvol.o)\
+		$(MODEL_LIB)(oce.o)\
+		$(MODEL_LIB)(ocesbc.o)\
+		$(MODEL_LIB)(ocfzpt.o)\
+		$(MODEL_LIB)(opa.o)\
+		$(MODEL_LIB)(par_ice.o)\
+		$(MODEL_LIB)(par_kind.o)\
+		$(MODEL_LIB)(par_oce.o)\
+		$(MODEL_LIB)(phycst.o)\
+		$(MODEL_LIB)(prtctl.o)\
+		$(MODEL_LIB)(restart.o)\
+		$(MODEL_LIB)(sms.o)\
+		$(MODEL_LIB)(solfet.o)\
+		$(MODEL_LIB)(solisl.o)\
+		$(MODEL_LIB)(solmat.o)\
+		$(MODEL_LIB)(sol_oce.o)\
+		$(MODEL_LIB)(solpcg.o)\
+		$(MODEL_LIB)(solsor_e.o)\
+		$(MODEL_LIB)(solsor.o)\
+		$(MODEL_LIB)(solver.o)\
+		$(MODEL_LIB)(step1d.o)\
+		$(MODEL_LIB)(step.o)\
+		$(MODEL_LIB)(stpctl.o)\
+		$(MODEL_LIB)(taumod.o)\
+		$(MODEL_LIB)(thd_ice.o)\
+		$(MODEL_LIB)(traadv_cen2.o)\
+		$(MODEL_LIB)(traadv_cen2_jki.o)\
+		$(MODEL_LIB)(traadv_eiv.o)\
+		$(MODEL_LIB)(traadv.o)\
+		$(MODEL_LIB)(traadv_muscl2.o)\
+		$(MODEL_LIB)(traadv_muscl.o)\
+		$(MODEL_LIB)(traadv_qck.o)\
+		$(MODEL_LIB)(traadv_tvd.o)\
+		$(MODEL_LIB)(traadv_ubs.o)\
+		$(MODEL_LIB)(trabbc.o)\
+		$(MODEL_LIB)(trabbl.o)\
+		$(MODEL_LIB)(tradmp.o)\
+		$(MODEL_LIB)(traldf_bilap.o)\
+		$(MODEL_LIB)(traldf_bilapg.o)\
+		$(MODEL_LIB)(traldf.o)\
+		$(MODEL_LIB)(traldf_iso.o)\
+		$(MODEL_LIB)(traldf_lap.o)\
+		$(MODEL_LIB)(tranpc.o)\
+		$(MODEL_LIB)(tranxt.o)\
+		$(MODEL_LIB)(traqsr.o)\
+		$(MODEL_LIB)(trasbc.o)\
+		$(MODEL_LIB)(trazdf_exp.o)\
+		$(MODEL_LIB)(trazdf.o)\
+		$(MODEL_LIB)(trazdf_imp.o)\
+		$(MODEL_LIB)(trazdf_imp_jki.o)\
+		$(MODEL_LIB)(trc_oce.o)\
+		$(MODEL_LIB)(trcstp.o)\
+		$(MODEL_LIB)(trdicp.o)\
+		$(MODEL_LIB)(trdicp_oce.o)\
+		$(MODEL_LIB)(trdmld.o)\
+		$(MODEL_LIB)(trdmld_oce.o)\
+		$(MODEL_LIB)(trdmld_rst.o)\
+		$(MODEL_LIB)(trdmod.o)\
+		$(MODEL_LIB)(trdmod_oce.o)\
+		$(MODEL_LIB)(trdvor.o)\
+		$(MODEL_LIB)(trdvor_oce.o)\
+		$(MODEL_LIB)(wzvmod.o)\
+		$(MODEL_LIB)(zdfbfr.o)\
+		$(MODEL_LIB)(zdfddm.o)\
+		$(MODEL_LIB)(zdfevd.o)\
+		$(MODEL_LIB)(zdfini.o)\
+		$(MODEL_LIB)(zdfkpp.o)\
+		$(MODEL_LIB)(zdfmxl.o)\
+		$(MODEL_LIB)(zdf_oce.o)\
+		$(MODEL_LIB)(zdfric.o)\
+		$(MODEL_LIB)(zdftke.o)\
+		$(MODEL_LIB)(zdftke_jki.o)\
+		$(MODEL_LIB)(zpshde.o)
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all: 		diroce $(EXEC_BIN)
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPA model is OK
+# Cleaning objects, libraries and executables
+clean:
+ifeq ($(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		$(RM) model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB) $(EXEC_BIN)
+		@echo OPA model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/oce ] ; then mkdir ../../../lib/oce ; fi
+
+$(EXEC_BIN) :	libioipsl firstagrif mpiagrif key keyverif src_file_list libagrif $(MODEL_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) agrif2model.o model.o
+ifeq ($(AGRIF),use)
+		$(F_L) $(L_X) -o $(EXEC_BIN) model.o agrif2model.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+else
+		$(F_L) $(L_X) -o $(EXEC_BIN) model.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+endif
+
+# Agrif library and conv
+libagrif :
+ifeq ($(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../AGRIF ; $(M_K) -f Makefile P_P="$(AGRIF_MPI)" )
+	@cp -rf ../../AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../AGRIF/conv OPAFILES/. 
+	@cp -rf ../../AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq ($(AGRIF),use)
+	@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+	@$(F_C) \
+#-Q- aix		-qsuffix=f=F90 \
+#-Q- osxxlf		-qsuffix=f=F90 \
+	$(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+	   OPAFILES/$*.F90 || { mv $(PREF).L $(TMP) ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux			@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../IOIPSL/src ; $(M_K) -f Makefile )
+
+# Main program
+model.o :	model.f90
+		@$(F_C) $(F_O) -c model.f90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : $(MODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : $(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : $(SXMODEL_LIB)
+
+# library dependancies
+$(MODEL_LIB):	$(LIB_OBJ)
+		@echo
+		@echo La bibliotheque est a jour
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+.f90.a :           
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.f90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F90 files
+.F90.a :  
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- lxiv8		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F90 > OPAFILES/AGRIF_MODELFILES/$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		OPAFILES/$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F files
+.F.a :           
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F > OPAFILES/$*.F 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- lxiv8		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F > OPAFILES/AGRIF_MODELFILES/$*.F
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(F_C) $(P_P) $(F_F) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		OPAFILES/$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the library from the .f files 
+.f.a : 		
+		@$(F_C) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.f|| { if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) -f $*.o
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux	@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi
+
+$(MODEL_LIB)(agrif_opa_interp.o) :	\
+	agrif_opa_interp.F90
+$(MODEL_LIB)(agrif_opa_sponge.o) :	\
+	agrif_opa_sponge.F90
+$(MODEL_LIB)(agrif_opa_update.o) :	\
+	agrif_opa_update.F90
+$(MODEL_LIB)(albedo.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	albedo.F90
+$(MODEL_LIB)(blk_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	blk_oce.F90
+$(MODEL_LIB)(bulk.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	blk_oce.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flx_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	KEY_CPP \
+	bulk.F90
+$(MODEL_LIB)(cla_div.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	cla_div.F90
+$(MODEL_LIB)(cla_dynspg.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla_dynspg.F90
+$(MODEL_LIB)(cla.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla.F90
+$(MODEL_LIB)(closea.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	closea.F90
+$(MODEL_LIB)(cpl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	cpl.F90
+$(MODEL_LIB)(cpl_oasis3.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	cpl_oasis3.F90
+$(MODEL_LIB)(cpl_oasis4.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oasis4_date.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	cpl_oasis4.F90
+$(MODEL_LIB)(cpl_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	cpl_oce.F90
+$(MODEL_LIB)(ctlopn.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	ctlopn.F90
+$(MODEL_LIB)(daymod.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90
+$(MODEL_LIB)(diadimg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diadimg.F90
+$(MODEL_LIB)(diafwb.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	blk_oce.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	diafwb.F90
+$(MODEL_LIB)(diagap.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diagap.F90
+$(MODEL_LIB)(diahdy.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahdy.F90
+$(MODEL_LIB)(diahth.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahth.F90
+$(MODEL_LIB)(dianam.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	dianam.F90
+$(MODEL_LIB)(diaptr.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diaptr.F90
+$(MODEL_LIB)(diaspr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	KEY_CPP \
+	diaspr.F90
+$(MODEL_LIB)(diawri1d.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trazdf_exp.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri1d.F90
+$(MODEL_LIB)(diawri.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dtasst.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	diawri_dimg.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri.F90
+$(MODEL_LIB)(divcur.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	divcur.F90
+$(MODEL_LIB)(domain.o) :	\
+	blk_oce.F90 \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solisl.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solisl.F90 \
+	blk_oce.F90 \
+	closea.F90 \
+	daymod.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	dom_oce.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	domain.F90
+$(MODEL_LIB)(domcfg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solisl.o) \
+	phycst.F90 \
+	solisl.F90 \
+	domcfg.F90
+$(MODEL_LIB)(domhgr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	domhgr.F90
+$(MODEL_LIB)(dom_ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	dom_ice.F90
+$(MODEL_LIB)(dommsk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solisl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dommsk.F90
+$(MODEL_LIB)(dom_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dom_oce.F90
+$(MODEL_LIB)(domstp.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	domstp.F90
+$(MODEL_LIB)(domvvl.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domvvl.F90
+$(MODEL_LIB)(domwri.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	domwri.F90
+$(MODEL_LIB)(domzgr.o) :	\
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	closea.F90 \
+	dom_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	oce.F90 \
+	solisl.F90 \
+	domzgr_substitute.h90 \
+	domzgr_zps.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domzgr.F90
+$(MODEL_LIB)(dtasal.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtasal.F90
+$(MODEL_LIB)(dtasss.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	KEY_CPP \
+	dtasss.F90
+$(MODEL_LIB)(dtasst.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	KEY_CPP \
+	dtasst.F90
+$(MODEL_LIB)(dtatem.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtatem.F90
+$(MODEL_LIB)(dynadv_cen2.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_cen2.F90
+$(MODEL_LIB)(dynadv.o) :	\
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv.F90
+$(MODEL_LIB)(dynadv_ubs.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_ubs.F90
+$(MODEL_LIB)(dyncor1d.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dyncor1d.F90
+$(MODEL_LIB)(dynhpg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynhpg_jki.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynhpg_jki.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg.F90
+$(MODEL_LIB)(dynhpg_jki.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg_jki.F90
+$(MODEL_LIB)(dynkeg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynkeg.F90
+$(MODEL_LIB)(dynldf_bilap.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilap.F90
+$(MODEL_LIB)(dynldf_bilapg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilapg.F90
+$(MODEL_LIB)(dynldf.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf.F90
+$(MODEL_LIB)(dynldf_iso.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_iso.F90
+$(MODEL_LIB)(dynldf_lap.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_lap.F90
+$(MODEL_LIB)(dynnxt1d.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	dynnxt1d.F90
+$(MODEL_LIB)(dynnxt.o) :	\
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obcdyn_bt.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynnxt.F90
+$(MODEL_LIB)(dynspg_exp.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_exp.F90
+$(MODEL_LIB)(dynspg_exp_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynspg_exp.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_exp_jki.F90
+$(MODEL_LIB)(dynspg.o) :	\
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg.F90
+$(MODEL_LIB)(dynspg_flt.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynspg_flt.F90
+$(MODEL_LIB)(dynspg_flt_jki.o) :	\
+	agrif_opa_interp.F90 \
+	blk_oce.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	dynspg_flt.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynspg_flt_jki.F90
+$(MODEL_LIB)(dynspg_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dynspg_oce.F90
+$(MODEL_LIB)(dynspg_rl.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_rl.F90
+$(MODEL_LIB)(dynspg_ts.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_ts.F90
+$(MODEL_LIB)(dynspg_ts_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_ts_jki.F90
+$(MODEL_LIB)(dynvor.o) :	\
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynadv.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynvor.F90
+$(MODEL_LIB)(dynzad.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzad.F90
+$(MODEL_LIB)(dynzdf_exp.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_exp.F90
+$(MODEL_LIB)(dynzdf.o) :	\
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	dynzdf.F90
+$(MODEL_LIB)(dynzdf_imp.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp.F90
+$(MODEL_LIB)(dynzdf_imp_jki.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp_jki.F90
+$(MODEL_LIB)(eosbn2.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	eosbn2.F90
+$(MODEL_LIB)(flo4rk.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	KEY_CPP \
+	flo4rk.F90
+$(MODEL_LIB)(floats.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	flo4rk.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flo_oce.F90 \
+	flowri.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	floats.F90
+$(MODEL_LIB)(floblk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	floblk.F90
+$(MODEL_LIB)(flodom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flodom.F90
+$(MODEL_LIB)(flo_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	flo_oce.F90
+$(MODEL_LIB)(flowri.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flowri.F90
+$(MODEL_LIB)(flxblk.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	flxblk.F90
+$(MODEL_LIB)(flxfwb.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	flxfwb.F90
+$(MODEL_LIB)(flxmod.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oasis4_date.F90 \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	blk_oce.F90 \
+	bulk.F90 \
+	dtatem.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(bulk.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	taumod.F90 \
+	domzgr_substitute.h90 \
+	flx_bulk_daily.h90 \
+	flx_bulk_monthly.h90 \
+	flx_core.h90 \
+	flx_forced_daily.h90 \
+	flx_oasis_ice.h90 \
+	KEY_CPP \
+	flxmod.F90
+$(MODEL_LIB)(flx_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	flx_oce.F90
+$(MODEL_LIB)(flxrnf.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	flxrnf_ORCA_R05.h90 \
+	KEY_CPP \
+	flxrnf.F90
+$(MODEL_LIB)(geo2ocean.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	geo2ocean.F90
+$(MODEL_LIB)(ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	KEY_CPP \
+	ice.F90
+$(MODEL_LIB)(iceini.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	ocfzpt.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	iceini.F90
+$(MODEL_LIB)(ice_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	blk_oce.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ice_oce.F90
+$(MODEL_LIB)(icestp1d.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	thd_ice.F90 \
+	tradmp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	icestp1d.F90
+$(MODEL_LIB)(icestp.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limadv.F90 \
+	limhdf.F90 \
+	limistate.F90 \
+	limrhg.F90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limadv.o) \
+	$(MODEL_LIB)(limhdf.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limrhg.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	thd_ice.F90 \
+	tradmp.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limdia.F90 \
+	limdmp.F90 \
+	limdyn.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limtrp.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limdia.o) \
+	$(MODEL_LIB)(limdmp.o) \
+	$(MODEL_LIB)(limdyn.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limtrp.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	icestp.F90
+$(MODEL_LIB)(ini1d.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	ini1d.F90
+$(MODEL_LIB)(initrc.o) :	\
+	initrc.F90
+$(MODEL_LIB)(in_out_manager.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90
+$(MODEL_LIB)(iom_def.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	iom_def.F90
+$(MODEL_LIB)(iom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	KEY_CPP \
+	iom.F90
+$(MODEL_LIB)(iom_ioipsl.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(IOIPSL_LIB) \
+	iom_ioipsl.F90
+$(MODEL_LIB)(iom_nf90.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	iom_nf90.F90
+$(MODEL_LIB)(iom_rstdimg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	iom_rstdimg.F90
+$(MODEL_LIB)(istate.o) :	\
+	agrif_opa_interp.F90 \
+	blk_oce.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynspg_exp.F90 \
+	dynspg.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solisl.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	istate.F90
+$(MODEL_LIB)(lbclnk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	KEY_CPP \
+	lbclnk.F90
+$(MODEL_LIB)(ldfdyn.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	domzgr_substitute.h90 \
+	ldfdyn_antarctic.h90 \
+	ldfdyn_arctic.h90 \
+	ldfdyn_c1d.h90 \
+	ldfdyn_c2d.h90 \
+	ldfdyn_c3d.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldfdyn.F90
+$(MODEL_LIB)(ldfdyn_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldfdyn_oce.F90
+$(MODEL_LIB)(ldfeiv.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfeiv.F90
+$(MODEL_LIB)(ldfslp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfslp.F90
+$(MODEL_LIB)(ldftra.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	ldftra_c1d.h90 \
+	ldftra_c2d.h90 \
+	ldftra_c3d.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldftra.F90
+$(MODEL_LIB)(ldftra_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldftra_oce.F90
+$(MODEL_LIB)(lib_cray.o) :	\
+	lib_cray.f90
+$(MODEL_LIB)(lib_feti.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(lib_mpp.o) \
+	KEY_CPP \
+	lib_feti.F90
+$(MODEL_LIB)(lib_isml.o) :	\
+	lib_isml.f90
+$(MODEL_LIB)(lib_mpp.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	lib_mpp.F90
+$(MODEL_LIB)(lib_print.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	lib_print.f90
+$(MODEL_LIB)(limadv.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	prtctl.F90 \
+	KEY_CPP \
+	limadv.F90
+$(MODEL_LIB)(limdia.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_ice.F90 \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limdia.F90
+$(MODEL_LIB)(limdmp.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	phycst.F90 \
+	tradmp.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limdmp.F90
+$(MODEL_LIB)(limdyn.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	limistate.F90 \
+	limrhg.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limrhg.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	limdyn.F90
+$(MODEL_LIB)(limflx.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	albedo.F90 \
+	flxblk.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	ocfzpt.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limflx.F90
+$(MODEL_LIB)(limhdf.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limhdf.F90
+$(MODEL_LIB)(limistate.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	limistate.F90
+$(MODEL_LIB)(limmsh.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	limmsh.F90
+$(MODEL_LIB)(limrhg.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	limrhg.F90
+$(MODEL_LIB)(limrst.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	KEY_CPP \
+	limrst.F90
+$(MODEL_LIB)(limtab.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	KEY_CPP \
+	limtab.F90
+$(MODEL_LIB)(limthd.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	thd_ice.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limthd.F90
+$(MODEL_LIB)(limthd_lac.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	KEY_CPP \
+	limthd_lac.F90
+$(MODEL_LIB)(limthd_zdf.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	KEY_CPP \
+	limthd_zdf.F90
+$(MODEL_LIB)(limtrp.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	limadv.F90 \
+	limhdf.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(limadv.o) \
+	$(MODEL_LIB)(limhdf.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limtrp.F90
+$(MODEL_LIB)(limwri.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	diadimg.F90 \
+	$(MODEL_LIB)(diadimg.o) \
+	limwri_dimg.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	limwri.F90
+$(MODEL_LIB)(model.o) :	\
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	iceini.F90 \
+	ini1d.F90 \
+	initrc.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(initrc.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(step1d.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	mppini.F90 \
+	obcini.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	step1d.F90 \
+	step.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(opa.o) \
+	opa.F90 \
+	model.f90
+$(MODEL_LIB)(mppini.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	sol_oce.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(iom.o) \
+	domzgr_substitute.h90 \
+	mppini_2.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	mppini.F90
+$(MODEL_LIB)(oasis4_date.o) :	\
+	KEY_CPP \
+	oasis4_date.F90
+$(MODEL_LIB)(obccli.o) :	\
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	obccli.F90
+$(MODEL_LIB)(obcdom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdom.F90
+$(MODEL_LIB)(obcdta.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcdta.F90
+$(MODEL_LIB)(obcdyn_bt.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn_bt.F90
+$(MODEL_LIB)(obcdyn.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn.F90
+$(MODEL_LIB)(obcfla.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcfla.F90
+$(MODEL_LIB)(obcini.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obcdom.F90 \
+	obc_oce.F90 \
+	obcrst.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcini.F90
+$(MODEL_LIB)(obc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	obc_oce.F90
+$(MODEL_LIB)(obc_par.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	obc_par_EEL_R5.h90 \
+	KEY_CPP \
+	obc_par.F90
+$(MODEL_LIB)(obcrad.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcrad.F90
+$(MODEL_LIB)(obcrst.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcrst.F90
+$(MODEL_LIB)(obcspg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcspg.F90
+$(MODEL_LIB)(obctra.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obctra.F90
+$(MODEL_LIB)(obcvol.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcvol.F90
+$(MODEL_LIB)(oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	oce.F90
+$(MODEL_LIB)(ocesbc.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ocesbc.F90
+$(MODEL_LIB)(ocfzpt.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	ocfzpt.F90
+$(MODEL_LIB)(opa.o) :	\
+	agrif_opa_sponge.F90 \
+	blk_oce.F90 \
+	cla_div.F90 \
+	cla.F90 \
+	closea.F90 \
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri1d.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	domhgr.F90 \
+	dom_ice.F90 \
+	dommsk.F90 \
+	dom_oce.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dyncor1d.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt1d.F90 \
+	dynnxt.F90 \
+	dynspg_exp.F90 \
+	dynspg.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	floats.F90 \
+	flo_oce.F90 \
+	flxblk.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	icestp1d.F90 \
+	icestp.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri1d.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt1d.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp1d.o) \
+	$(MODEL_LIB)(icestp.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke_jki.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oasis4_date.F90 \
+	obcdom.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	wzvmod.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdftke_jki.F90 \
+	zpshde.F90 \
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	iceini.F90 \
+	ini1d.F90 \
+	initrc.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(initrc.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(step1d.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	mppini.F90 \
+	obcini.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	step1d.F90 \
+	step.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	KEY_CPP \
+	opa.F90
+$(MODEL_LIB)(par_ice.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	par_ice.F90
+$(MODEL_LIB)(par_kind.o) :	\
+	par_kind.F90
+$(MODEL_LIB)(par_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	par_EEL_R2.h90 \
+	par_EEL_R5.h90 \
+	par_EEL_R6.h90 \
+	par_GYRE.h90 \
+	par_ORCA_R025.h90 \
+	par_ORCA_R05.h90 \
+	par_ORCA_R2.h90 \
+	par_ORCA_R4.h90 \
+	KEY_CPP \
+	par_oce.F90
+$(MODEL_LIB)(phycst.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	phycst.F90
+$(MODEL_LIB)(prtctl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	prtctl.F90
+$(MODEL_LIB)(restart.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	restart.F90
+$(MODEL_LIB)(sms.o) :	\
+	sms.F90
+$(MODEL_LIB)(solfet.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solfet.F90
+$(MODEL_LIB)(solisl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	solisl.F90
+$(MODEL_LIB)(solmat.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solmat.F90
+$(MODEL_LIB)(sol_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	sol_oce.F90
+$(MODEL_LIB)(solpcg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	solpcg.F90
+$(MODEL_LIB)(solsor_e.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	solsor_e.F90
+$(MODEL_LIB)(solsor.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	solsor.F90
+$(MODEL_LIB)(solver.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	KEY_CPP \
+	solver.F90
+$(MODEL_LIB)(step1d.o) :	\
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	eosbn2.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obctra.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	traqsr.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trc_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	diawri1d.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynnxt1d.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	icestp1d.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diawri1d.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynnxt1d.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	step1d.F90
+$(MODEL_LIB)(step.o) :	\
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv_cen2.F90 \
+	dynadv.F90 \
+	dynadv_ubs.F90 \
+	dynhpg_jki.F90 \
+	dynkeg.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	dynzad.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	eosbn2.F90 \
+	flo4rk.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flo_oce.F90 \
+	flowri.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limdia.F90 \
+	limdmp.F90 \
+	limdyn.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limtrp.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynhpg_jki.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limdia.o) \
+	$(MODEL_LIB)(limdmp.o) \
+	$(MODEL_LIB)(limdyn.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limtrp.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv_cen2_jki.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn_bt.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obctra.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	traadv_cen2.F90 \
+	traadv_cen2_jki.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl2.F90 \
+	traadv_muscl.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	traqsr.F90 \
+	trazdf_exp.F90 \
+	trazdf.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trc_oce.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	agrif_opa_sponge.F90 \
+	cla_div.F90 \
+	cla.F90 \
+	closea.F90 \
+	cpl.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt.F90 \
+	dynspg.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	floats.F90 \
+	flo_oce.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	icestp.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke_jki.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obcdta.F90 \
+	obc_par.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	wzvmod.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdftke_jki.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	step.F90
+$(MODEL_LIB)(stpctl.o) :	\
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	stpctl.F90
+$(MODEL_LIB)(taumod.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oasis4_date.F90 \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	tau_forced_daily.h90 \
+	tau_forced_monthly.h90 \
+	tau_oasis_ice.h90 \
+	KEY_CPP \
+	taumod.F90
+$(MODEL_LIB)(thd_ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	thd_ice.F90
+$(MODEL_LIB)(traadv_cen2.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2.F90
+$(MODEL_LIB)(traadv_cen2_jki.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2_jki.F90
+$(MODEL_LIB)(traadv_eiv.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_eiv.F90
+$(MODEL_LIB)(traadv.o) :	\
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traadv_cen2_jki.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	oce.F90 \
+	prtctl.F90 \
+	traadv_cen2.F90 \
+	traadv_cen2_jki.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl2.F90 \
+	traadv_muscl.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv.F90
+$(MODEL_LIB)(traadv_muscl2.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl2.F90
+$(MODEL_LIB)(traadv_muscl.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl.F90
+$(MODEL_LIB)(traadv_qck.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_qck.F90
+$(MODEL_LIB)(traadv_tvd.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_tvd.F90
+$(MODEL_LIB)(traadv_ubs.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_ubs.F90
+$(MODEL_LIB)(trabbc.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	trabbc.F90
+$(MODEL_LIB)(trabbl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	eosbn2.F90 \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	trabbl_adv.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trabbl.F90
+$(MODEL_LIB)(tradmp.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	tradmp.F90
+$(MODEL_LIB)(traldf_bilap.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_bilap.F90
+$(MODEL_LIB)(traldf_bilapg.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	KEY_CPP \
+	traldf_bilapg.F90
+$(MODEL_LIB)(traldf.o) :	\
+	diaptr.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	trazdf.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf.F90
+$(MODEL_LIB)(traldf_iso.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_iso.F90
+$(MODEL_LIB)(traldf_lap.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_lap.F90
+$(MODEL_LIB)(tranpc.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	tranpc.F90
+$(MODEL_LIB)(tranxt.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obctra.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	tranxt.F90
+$(MODEL_LIB)(traqsr.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sms.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traqsr.F90
+$(MODEL_LIB)(trasbc.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	traqsr.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trasbc.F90
+$(MODEL_LIB)(trazdf_exp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_exp.F90
+$(MODEL_LIB)(trazdf.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf.F90
+$(MODEL_LIB)(trazdf_imp.o) :	\
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_imp.F90
+$(MODEL_LIB)(trazdf_imp_jki.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	zdfddm_substitute.h90 \
+	zdf.matrixsolver.h90 \
+	KEY_CPP \
+	trazdf_imp_jki.F90
+$(MODEL_LIB)(trc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sms.o) \
+	par_oce.F90 \
+	sms.F90 \
+	KEY_CPP \
+	trc_oce.F90
+$(MODEL_LIB)(trcstp.o) :	\
+	trcstp.F90
+$(MODEL_LIB)(trdicp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdicp.F90
+$(MODEL_LIB)(trdicp_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdicp_oce.F90
+$(MODEL_LIB)(trdmld.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdmld.F90
+$(MODEL_LIB)(trdmld_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdmld_oce.F90
+$(MODEL_LIB)(trdmld_rst.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	restart.F90 \
+	trdmod_oce.F90 \
+	KEY_CPP \
+	trdmld_rst.F90
+$(MODEL_LIB)(trdmod.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdmod.F90
+$(MODEL_LIB)(trdmod_oce.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	KEY_CPP \
+	trdmod_oce.F90
+$(MODEL_LIB)(trdvor.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdvor.F90
+$(MODEL_LIB)(trdvor_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdvor_oce.F90
+$(MODEL_LIB)(wzvmod.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	wzvmod.F90
+$(MODEL_LIB)(zdfbfr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfbfr.F90
+$(MODEL_LIB)(zdfddm.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfddm.F90
+$(MODEL_LIB)(zdfevd.o) :	\
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfevd.F90
+$(MODEL_LIB)(zdfini.o) :	\
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	par_oce.F90 \
+	tranpc.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdfini.F90
+$(MODEL_LIB)(zdfkpp.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfkpp.F90
+$(MODEL_LIB)(zdfmxl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfmxl.F90
+$(MODEL_LIB)(zdf_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	zdf_oce.F90
+$(MODEL_LIB)(zdfric.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfric.F90
+$(MODEL_LIB)(zdftke.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdftke.F90
+$(MODEL_LIB)(zdftke_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdftke_jki.F90
+$(MODEL_LIB)(zpshde.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zpshde.F90
+# agrif previous use
+firstagrif:
+ifeq ($(AGRIF),use)
+	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+else
+	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp
+#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC
+# recompile all in this case
+mpiagrif:
+ifeq ($(AGRIF),use)
+ifeq (,$(AGRIF_MPI))
+	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+endif
+# key changing control
+key: 
+	@echo CHANGE of CPP KEYS yes/no ?
+	-@if [ "`cat KEY_CPP`" != "$(P_P:$(prefix)%=%)" ] ; then \
+		echo CPP options changed ; echo "$(P_P:$(prefix)%=%)" > KEY_CPP ; fi 
+# check key values
+keyverif:
+	@echo CHECKING KEY
+	@echo KEY USED : 
+	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \
+	do \
+	echo $$v ;\
+        w=`echo $$v | cut -c1-3` ; \
+        if [ $$w = `echo "key"` ] ; then \
+        r=n ; \
+        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \
+           if [ $$r != "n" ] ; then \
+              echo "UNKNOWN KEY" ;\
+              false ;  \
+              exit ;  \
+           fi \
+        fi \
+	done
+# Checking the number of routines
+src_file_list: 
+	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES 
+	@$(RM) `ls | fgrep -v -f .patron` 
+	@check=`grep OPA_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OPA_SRC files"                ; \
+	    ln -sf ../OPA_SRC/*.[Ffh]90          . ; \
+	    ln -sf ../OPA_SRC/DYN/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/TRA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/TRD/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DIA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DOM/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/OBC/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/FLO/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/LDF/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/ZDF/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/SOL/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DTA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/SBC/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/IOM/*.[Ffh]90      . ; \
+  fi 
+	@check=`grep LIM_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use LIM_SRC files"                ; \
+      ln -sf ../LIM_SRC/*.[Ffh]90          . ; \
+  fi 
+	@check=`grep C1D_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use C1D_SRC files"                ; \
+      ln -sf ../C1D_SRC/*.[Ffh]90          . ; \
+  fi 
+	@check=`grep TOP_SRC .config`              ; \
+	if [ -n "$$check" ] ; then  \
+	echo "   use TOP_SRC files"                ; \
+      \$(RM) trcstp.F90                      ; \
+      \$(RM) sms.F90                         ; \
+      \$(RM) initrc.F90                      ; \
+      ln -sf ../TOP_SRC/*.[Ffh]90          . ; \
+      ln -sf ../TOP_SRC/SMS/*.[Ffh]        . ; \
+      ln -sf ../TOP_SRC/SMS/*.[Ffh]90      . ; \
+      ln -sf ../TOP_SRC/TRP/*.[Ffh]90      . ; \
+  fi 
+	@check=`grep OFF_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OFF_SRC files"                ; \
+      ln -sf ../OFF_SRC/*.[Ffh]90          . ; \
+      ln -sf ../OFF_SRC/*/*.[Ffh]90        . ; \
+  fi 
+	@check=`grep NST_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use NST_SRC files"                ; \
+      \$(RM) agrif_opa_interp.F90           ; \
+      \$(RM) agrif_opa_sponge.F90           ; \
+      \$(RM) agrif_opa_update.F90           ; \
+      ln -sf ../NST_SRC/*.[Ffh]90      .     ; \
+  fi 
+	@\$(RM) tmplist
+	@ls -1 | fgrep -v -f .patron  >tmplist
+	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \
+	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \
+	\$(RM) model.o \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN) ; \
+	echo "Rebuilding the AA_make files" ; \
+	cd ..  ; ../UTIL/fait_AA_make ; echo " " ; \
+	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \
+	echo "========================================== " ; \
+	../../util/ins_make ; echo " " ;  false ; exit ; }
Index: /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/GYRE/scripts/BB_make.ldef	(revision 4536)
@@ -0,0 +1,46 @@
+#---------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model (BB_make.ldef in scripts)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+MODDIR = $(LIBDIR)
+MODEL_LIB = $(LIBDIR)/oce/libopa.a
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxdkrz  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- eshpux  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxdkrc AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- eshpux  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxdkrz  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- eshpux  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opa
+
+#-
+#- Key options for GYRE ocean configuration: Analytical forcing ---
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P = key_zco key_gyre key_dynspg_flt key_ldfslp key_zdftke key_vectopt_loop key_vectopt_memory   
+
+#-
+#- Prefix for preprocessing ---
+#-Q- sx8mercure prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make	(revision 4536)
@@ -0,0 +1,13 @@
+# $Header$
+all: ioipsl opa
+
+ioipsl:
+	(cd ../../modeles/IOIPSL/src; $(M_K) ;)
+
+
+opa:
+	(cd ../../modeles/NEMO/WORK;  $(M_K) ;)
+
+
+clean:
+	(cd ../../modeles/NEMO/WORK;  $(M_K) clean ;)
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/AA_make.ldef	(revision 4536)
@@ -0,0 +1,11 @@
+#---------------------------------------------------------------------
+#- Creation des elements relatifs a ORCA :
+#-      ORCA  (lib, executable : opa)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#---------------------------------------------------------------------
+LIBDIR = ../../../../lib
+BINDIR = ../../../../bin
+MODDIR = $(LIBDIR)
+#---------------------------------------------------------------------
+#-
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 4536)
@@ -0,0 +1,767 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+! OPA namelist :  model option and parameter input
+! -------------
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!-----------------------------------------------------------------------
+!       namrun   parameters of the run
+!-----------------------------------------------------------------------
+!  no         job number
+!  cexper     experience name for vairmer format
+!  ln_rstart  boolean term for restart (true or false)
+!  nrstdt     control of the restart timestep:
+!                = 0 restart, do not control nit000 in the restart file.
+!                = 1 restart, control nit000 in the restart file. Do not
+!                    use the date in the restart file (use ndate0 in namelist)
+!                = 2 restart, control nit000 in the restart file, use the date
+!                    in the restart file. ndate0 in the namelist is ignored.
+!  nit000     number of the first time step
+!  nitend     number of the last time step
+!  ndate0     initial calendar date aammjj
+!  nleapy     Leap year calendar (0/1)
+!  ninist     initial state output flag (0/1)
+!  nstock     frequency of restart file
+!  nwrite     frequency of OUTPUT file
+!  nrunoff    = 0 no, 1 runoff, 2 runoff+river mouth ups adv
+!  ln_dimgnnn (F/T) 1 DIMG file - (for all proc/per proc)
+!
+!  CAUTION: for usual run scripts, logical value of
+!  *******  ln_rstart must be .true. or .false.
+!                     and NOT .TRUE. or .FALSE.
+&namrun
+   no         =       0
+   cexper     =  "Agulhas"
+   ln_rstart  = .false.
+   nrstdt     =       0
+   nit000     =       1
+   nitend     =   10950
+   ndate0     =  010101
+   nleapy     =       0
+   ninist     =       0
+   nstock     =   10950
+   nwrite     =   10950
+   nrunoff    =       0
+   ln_dimgnnn = .FALSE.
+/
+!-----------------------------------------------------------------------
+!       nam_ctl      Control prints & Benchmark
+!-----------------------------------------------------------------------
+!  ln_ctl     trends control print (expensive!)
+!  nprint     level of print (0 no print)
+!  nictls     start i indice to make the control SUM (very usefull to compare mono-
+!  nictle     end   i indice to make the control SUM (-versus multi processor runs)
+!  njctls     start j indice to make the control SUM (very usefull to compare mono-
+!  njctle     end   j indice to make the control SUM (-versus multi processor runs)
+!  nisplt     number of processors following i
+!  njsplt     number of processors following j
+!  nbench     Bench parameter (0/1): CAUTION it must be zero except for bench
+!             for which we don't care about physical meaning of the results
+!  nbit_cmp   bit comparison mode parameter (0/1): enables bit comparison between 
+!             single and multiple processor runs.
+&namctl
+   ln_ctl =  .false.
+   nprint =       0
+   nictls =       0
+   nictle =       0
+   njctls =       0
+   njctle =       0
+   isplt  =       1
+   jsplt  =       1
+   nbench =       0
+   nbit_cmp =     0
+/
+!!-----------------------------------------------------------------------
+!       nam_mpp      Massively Parallel Processing
+!-----------------------------------------------------------------------
+!  c_mpi_send         mpi send/recieve type
+!                      = 'S'  : standard blocking send
+!                      = 'B'  : buffer blocking send
+!                      = 'I'  : immediate non-blocking send
+&nam_mpp
+   c_mpi_send =  'S'
+/
+!-----------------------------------------------------------------------
+!       nam_mpp_dyndist      Massively Parallel Distribution
+!              #ifdef ( key_agrif && key_mpp_dyndist )
+!-----------------------------------------------------------------------
+!  jpni   number of processors following i
+!  jpnj   number of processors following j
+!  jpnij  number of local domains
+&nam_mpp_dyndist
+   jpni  = 1
+   jpnj  = 1
+   jpnij = 1
+/
+!-----------------------------------------------------------------------
+!       nam_zgr       vertical coordinate
+!-----------------------------------------------------------------------
+!  ln_zco     z-coordinate - full steps      (T/F)
+!  ln_zps     z-coordinate - partial steps   (T/F)
+!  ln_sco     s- or hybrid z-s-coordinate    (T/F)
+&nam_zgr
+   ln_zco   =  .false.
+   ln_zps   =  .true.
+   ln_sco   =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_zgr_sco   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+!  sbot_min   minimum depth of s-bottom surface (>0) (m)
+!  sbot_max   maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+!  theta      surface control parameter (0<=theta<=20)
+!  thetb      bottom control parameter  (0<=thetb<= 1)
+!  r_max      maximum cut-off r-value allowed (0<r_max<1)
+&nam_zgr_sco
+   sbot_min =  300.
+   sbot_max = 5250.
+   theta    =    6.0
+   thetb    =    0.75
+   r_max    =    0.15
+/
+!-----------------------------------------------------------------------
+!       nam_traadv   advection scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_traadv_cen2     2nd order centered scheme    (default T)
+!  ln_traadv_tvd      TVD scheme                   (default F)
+!  ln_traadv_muscl    MUSCL scheme                 (default F)
+!  ln_traadv_muscl2   MUSCL2 scheme                (default F)
+!  ln_traadv_ubs      UBS scheme                   (default F)
+!  ln_traadv_qck      QUICKEST scheme              (default F)
+&nam_traadv
+   ln_traadv_cen2   =  .false.
+   ln_traadv_tvd    =  .true.
+   ln_traadv_muscl  =  .false.
+   ln_traadv_muscl2 =  .false.
+   ln_traadv_ubs    =  .false.
+   ln_traadv_qck    =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_traldf   lateral diffusion scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_traldf_lap    laplacian operator          (default T)
+!     ln_traldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_traldf_level  iso-level                   (default F)
+!     ln_traldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_traldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!     aht0    horizontal eddy diffusivity for tracers (m2/s)
+!     ahtb0   background eddy diffusivity for isopycnal diffusion (m2/s)
+!     aeiv0   eddy induced velocity coefficient (m2/s)
+! ^* require key_ldfslp to compute the direction of the lateral diffusion
+! ^** require key_ldfslp in s-coordinate
+&nam_traldf
+   ln_traldf_lap    =  .true.
+   ln_traldf_bilap  =  .false.
+   ln_traldf_level  =  .false.
+   ln_traldf_hor    =  .false.
+   ln_traldf_iso    =  .true.
+   aht0    =  1000.
+   ahtb0   =     0.
+   aeiv0   =     0.
+/
+!-----------------------------------------------------------------------
+!       nam_dynldf   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_dynldf_lap    laplacian operator          (default T)
+!     ln_dynldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_dynldf_level  iso-level                   (default F)
+!     ln_dynldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_dynldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!  ahm0    horizontal eddy viscosity for the dynamics (m2/s)
+!  ahmb0   background eddy viscosity for isopycnal diffusion (m2/s)
+&nam_dynldf
+   ln_dynldf_lap    =  .false.
+   ln_dynldf_bilap  =  .true.
+   ln_dynldf_level  =  .false.
+   ln_dynldf_hor    =  .true.
+   ln_dynldf_iso    =  .false.
+   ahm0    = -8.5e+11
+   ahmb0   =     0.
+/
+!-----------------------------------------------------------------------
+!       namflg   algorithm flags (algorithm not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynhpg_imp   hydrostatic pressure gradient: semi-implicit time scheme  (T)
+!                                                  centered      time scheme  (F)
+!   nn_dynhpg_rst  add dynhpg implicit variables in restart ot not (1/0)
+&namflg
+   ln_dynhpg_imp   =  .false.
+   nn_dynhpg_rst   =  0
+/
+!-----------------------------------------------------------------------
+!       nam_dynhpg   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+!  type of pressure gradient scheme (choose one only!)
+!     ln_hpg_zco    z-coordinate - full steps                   (default T)
+!     ln_hpg_zps    z-coordinate - partial steps (interpolation)
+!     ln_hpg_sco    s-coordinate (standard jacobian formulation)
+!     ln_hpg_hel    s-coordinate (helsinki modification)
+!     ln_hpg_wdj    s-coordinate (weighted density jacobian)
+!     ln_hpg_djc    s-coordinate (Density Jacobian with Cubic polynomial)
+!     ln_hpg_rot    s-coordinate (ROTated axes scheme)
+!  parameters
+!    gamm          weighting coefficient (wdj scheme)
+&nam_dynhpg
+   ln_hpg_zco = .false.
+   ln_hpg_zps = .true.
+   ln_hpg_sco = .false.
+   ln_hpg_hel = .false.
+   ln_hpg_wdj = .false.
+   ln_hpg_djc = .false.
+   ln_hpg_rot = .false.
+   gamm       = 0.e0
+/
+!-----------------------------------------------------------------------
+!       nam_dynadv   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynadv_vec      vector form flag
+!  ln_dynadv_cen2     flux form - 2nd order centered scheme    (default T)
+!  ln_dynadv_ubs      flux form - 3rd order UBS scheme         (default F)
+&nam_dynadv   
+   ln_dynadv_vec   = .TRUE.
+   ln_dynadv_cen2  = .FALSE.
+   ln_dynadv_ubs   = .FALSE.
+/  
+!-----------------------------------------------------------------------
+!       nam_dynvor   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynvor_ens   vorticity trends: enstrophy conserving scheme (default T)
+!  ln_dynvor_ene      "         "  : energy conserving scheme    (default F)
+!  ln_dynvor_mix      "         "  : mixed scheme                (default F)
+!  ln_dynvor_een      "         "  : energy & enstrophy scheme   (default F)
+&nam_dynvor
+   ln_dynvor_ene = .FALSE.
+   ln_dynvor_ens = .FALSE.
+   ln_dynvor_mix = .FALSE.
+   ln_dynvor_een = .TRUE.
+/
+!-----------------------------------------------------------------------
+!       namtau   surface wind stress
+!-----------------------------------------------------------------------
+!  ntau000   gently increase the stress over the first ntau_rst time-steps
+!  tau0x     uniform value used as default surface heat flux
+!  tau0y     uniform value used as default solar radiation flux
+&namtau
+   ntau000 =      0
+   tau0x   =      0.e0
+   tau0y   =      0.e0
+/
+!-----------------------------------------------------------------------
+!       namflx   surface fluxes
+!-----------------------------------------------------------------------
+!  q0       uniform value used as default surface heat flux
+!  qsr0     uniform value used as default solar radiation flux
+!  emp0     uniform value used as default surface freswater budget (E-P)
+!  dqdt0    feedback coefficient for SST damping (W/m2/K)
+!  deds0    feedback coefficient for SSS damping (mm/day)
+&namflx
+   q0      =      0.e0
+   qsr0    =      0.e0
+   emp0    =      0.e0
+   dqdt0   =      -40.
+   deds0   =        0.
+/
+!-----------------------------------------------------------------------
+!       namalb   albedo parameters
+!-----------------------------------------------------------------------
+!  cgren    correction of the snow or ice albedo to take into account
+!  albice   albedo of melting ice in the arctic and antarctic
+!  alphd    coefficients for linear interpolation used to compute albedo
+!           between two extremes values (Pyane, 1972)
+!  alphc     "                                         "
+!  alphdi    "                                         "
+&namalb
+   cgren    =      0.06
+   albice   =      0.5
+   alphd    =      0.80
+   alphc    =      0.65
+   alphdi   =      0.72
+/
+!-----------------------------------------------------------------------
+!       namdom   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+!  ntopo      = 0/1 ,compute/read the bathymetry file
+!               (mbathy, nb of T-ocean levels)
+!  e3zps_min  the thickness of the partial step is set larger than the
+!  e3zps_rat     the minimum of e3zps_min and e3zps_rat * e3t
+!                (N.B. 0<e3zps_rat<1)
+!                  (coordinates, scale factors)
+!  nmsh       =1 create a mesh file (coordinates, scale factors, masks)
+!  nacc       the acceleration of convergence method
+!             = 0, no acceleration, rdt = rdttra
+!             = 1, acceleration used, rdt < rdttra(k)
+!  atfp       asselin time filter parameter
+!  rdt        time step for the dynamics (and tracer if nacc=0)
+!  rdtmin     minimum time step on tracers
+!  rdtmax     maximum time step on tracers
+!  rdth       depth variation of tracer time step
+!  rdtbt      barotropic time step (for the time splitting algorithm)
+!  nfice      frequency of ice model call
+!  nfbulk     frequency of bulk formulea call (not used if ice used)
+!  nclosea    = 0 no closed sea 
+!             = 1 closed sea (Black Sea, Caspian Sea, Great US Lakes...) 
+&namdom
+   ntopo     =     1
+   e3zps_min =     5.
+   e3zps_rat =     0.1
+   nmsh      =     0
+   nacc      =     0
+   atfp      =     0.1
+   rdt       =  2880.
+   rdtmin    =  2880.
+   rdtmax    =  2880.
+   rdth      =   800.
+   rdtbt     =    90.
+   nfice     =     5  
+   nfbulk    =     5  
+   nclosea   =     0
+/
+!-----------------------------------------------------------------------
+!       namfwb   freshwater budget correction
+!-----------------------------------------------------------------------
+!  ln_fwb     logical flag for freshwater budget correction (0 annual mean)
+&namfwb
+   ln_fwb    = .false.
+/
+!-----------------------------------------------------------------------
+!       namptr   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+!  ln_diaptr  logical flag for Poleward transport computation
+!  ln_subbas  logical flag for Atlantic/Pacific/Indian basins computation
+!             need input basins mask file named "subbasins.nc"
+!  nf_ptr     Frequency of computation
+&namptr
+   ln_diaptr = .false.
+   ln_subbas = .false.
+   nf_ptr    =  15
+/
+!-----------------------------------------------------------------------
+!       namcro   cross land advection
+!-----------------------------------------------------------------------
+!  n_cla   advection between 2 ocean pts separates by land 
+&namcla
+   n_cla   = 0
+/
+!-----------------------------------------------------------------------
+!       namzdf   vertical physics
+!-----------------------------------------------------------------------
+!  ln_zdfevd  enhanced vertical diffusion         (default T)
+!  ln_zdfnpc  Non-Penetrative Convection          (default T)
+!  avm0       vertical eddy viscosity for the dynamic (m2/s)
+!  avt0       vertical eddy diffusivity for tracers (m2/s)
+!  avevd      vertical coefficient for enhanced diffusion scheme (m2/s)
+!  nevdm      = 0  apply enhanced mixing on tracer only
+!             = 1  apply enhanced mixing on both tracer and momentum
+!  ln_zdfexp   vertical physics: (=T)  time splitting (T)     (Default=F)
+!                               (=F)  euler backward (F)
+!  n_zdfexp   number of sub-timestep for time splitting scheme
+&namzdf
+   ln_zdfevd = .true.
+   ln_zdfnpc = .false.
+   avm0      = 1.2e-4
+   avt0      = 1.2e-5
+   avevd     =   100.
+   n_evdm    =     1
+   ln_zdfexp =  .false.
+   n_zdfexp  =     3
+/
+!-----------------------------------------------------------------------
+!       namnpc   vnon penetrative convection
+!-----------------------------------------------------------------------
+!  nnpc1   non penetrative convective scheme frequency
+!  nnpc2   non penetrative convective scheme print frequency
+&namnpc
+   nnpc1  =      1
+   nnpc2  =    365
+/
+!-----------------------------------------------------------------------
+!       nambbl   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+!  atrbbl   lateral tracer coeff. for bottom boundary layer scheme(m2/s)
+&nambbl
+   atrbbl = 10000.
+/
+!-----------------------------------------------------------------------
+!       namric   richardson number dependent vertical diffusion
+!                ( #ifdef "key_zdfrichardson" )
+!-----------------------------------------------------------------------
+!  avmri   maximum value of the vertical viscosity
+!  alp     coefficient of the parameterization
+!  nric    coefficient of the parameterization
+&namric
+   avmri = 100.e-4
+   alp   =      5.
+   nric  =       2
+/
+!-----------------------------------------------------------------------
+!       namtke   turbulent eddy kinetic dependent vertical diffusion
+!                ( #ifdef "key_zdftke" )
+!-----------------------------------------------------------------------
+!  ln_rstke flag to restart with tke from a run without tke (default F)
+!  ediff    coef. to compute vertical eddy coef. (avt=ediff*mxl*sqrt(e) )
+!  ediss    coef. of the Kolmogoroff dissipation  
+!  ebb      coef. of the surface input of tke
+!  efave    coef. to applied to the tke diffusion ( avtke=efave*avm )
+!  emin     minimum value of tke (m^2/s^2)
+!  emin0    surface minimum value of tke (m^2/s^2)
+!  nitke    number of restart iterative loops
+!  ri_c     critic richardson number
+!  nmxl     flag on mixing length used
+!           = 0 bounded by the distance to surface and bottom
+!           = 1 bounded by the local vertical scale factor
+!           = 2 first vertical derivative of mixing length bounded by 1
+!  npdl     flag on prandtl number
+!           = 0 no vertical prandtl number (avt=avm)
+!           = 1 prandtl number function of richarson number (avt=pdl*avm)
+!           = 2 same as = 1 but a shapiro filter is applied on pdl
+!  nave     =  horizontal averaged (=1) or not (=0) of avt  (default =1)
+!  navb     = 0 cst background avt0, avm0 / =1 profile used on avtb
+&namtke
+   ln_rstke = .false.
+   ediff =       0.1
+   ediss =       0.7
+   ebb   =       60. 
+   efave =        1.
+   emin  =     1.e-6
+   emin0 =     1.e-4
+   nitke =        50
+   nmxl  =         2
+   npdl  =         1
+   navb  =         0
+/
+!-----------------------------------------------------------------------
+!       namkpp   K-Profile Parameterization dependent vertical diffusion
+!                ( #ifdef "key_zdfkpp" )
+!-----------------------------------------------------------------------
+!  ln_kpprimix   shear instability mixing  (default T)
+!  difmiw        constant internal wave viscosity (m2/s)
+!  difsiw        constant internal wave diffusivity (m2/s)
+!  Riinfty       local Richardson Number limit for shear instability
+!  difri         maximum shear mixing at Rig = 0    (m2/s)
+!  bvsqcon       Brunt-Vaisala squared (1/s**2) for maximum convection
+!  difcon        maximum mixing in interior convection (m2/s)
+!  nave          = 0/1 flag for horizontal average on avt, avmu, avmv
+!  navb          = 0/1 flag for constant or profile background avt
+&namkpp
+   ln_kpprimix  = .true.
+   difmiw       =  1.e-04
+   difsiw       =  0.1e-04
+   Riinfty      =  0.8
+   difri        =  0.0050
+   bvsqcon      = -0.01e-07
+   difcon       =  1.
+   navb         =  0
+   nave         =  1
+/
+!-----------------------------------------------------------------------
+!       namddm   double diffusive mixing parameterization
+!-----------------------------------------------------------------------
+!   avts    maximum avs for dd mixing 
+!   hsbfr   heat/salt buoyancy flux ratio
+&namddm
+      avts  = 1.e-4
+      hsbfr = 1.6
+/
+!-----------------------------------------------------------------------
+!       namlbc   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+!  shlat   lateral boundary condition on velocity
+!                   shlat = 0 , free slip
+!               0 < shlat < 2 , partial slip
+!                   shlat = 2 , no slip
+!               2 < shlat     , strong slip
+&namlbc
+   shlat  =      2.
+/
+!-----------------------------------------------------------------------
+!       nambfr   bottom friction
+!-----------------------------------------------------------------------
+!  nbotfr  type of bottom friction 
+!                  nbotfr = 0 , no slip 
+!                  nbotfr = 1 , linear friction
+!                  nbotfr = 2 , nonlinear friction
+!                  nbotfr = 3 , free slip
+!  bfri1   bottom drag coefficient (linear case)
+!  bfri2   bottom drag coefficient (non linear case)
+!  bfeb2   bottom turbulent kinetic energy  (m^2/s^2)
+&nambfr
+   nbotfr =       1
+   bfri1  =   4.e-4
+   bfri2  =   1.e-3
+   bfeb2  =  2.5e-3
+/
+!-----------------------------------------------------------------------
+!       nambbc   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+!  ngeo_flux  = 0 no geothermal heat flux
+!             = 1 constant geothermal heat flux
+!             = 2 variable geothermal heat flux (read in geothermal_heating.nc) 
+!                 ( C A U T I O N : flux in mW/m2 in the NetCDF file )
+!  ngeo_flux_const   Constant value of geothermal heat flux (W/m2) 
+&nambbc
+   ngeo_flux =  2
+   ngeo_flux_const = 86.4e-3
+/
+!-----------------------------------------------------------------------
+!       namqsr   penetrative solar radiation
+!-----------------------------------------------------------------------
+!  ln_traqsr : penetrative solar radiation (T) or not (F)     (Default=T)
+!  rabs       fraction of qsr associated with xsi1
+!  xsi1       first depth of extinction
+!  xsi2       second depth of extinction
+&namqsr
+   ln_traqsr = .true.
+   rabs     =   0.58
+   xsi1     =   0.35
+   xsi2     =   23.0
+/
+!-----------------------------------------------------------------------
+!       namtdp   tracer newtonian damping ('key_tradmp')
+!-----------------------------------------------------------------------
+!  ndmp    type of damping in temperature and salinity 
+!          (='latitude', damping poleward of 'ndmp' degrees and function 
+!             of the distance-to-coast. Red and Med Seas as ndmp=-1)
+!          (=-1 damping only in Med and Red Seas)
+!  ndmpf   =1 create a damping.coeff NetCDF file (the 3D damping array)
+!  nmldmp  type of damping in the mixed layer
+!          (=0 damping throughout the water column)
+!	   (=1 no damping in the mixed layer defined by avt >5cm2/s )
+!	   (=2 no damping in the mixed layer defined rho<rho(surf)+.01 )
+!  sdmp    surface time scale for internal damping (days)
+!  bdmp    bottom time scale for internal damping (days)
+!  hdmp    depth of transition between sdmp and bdmp (meters)
+&namtdp
+   ndmp   =   90 
+   ndmpf  =    1
+   nmldmp =    1
+   sdmp   =  50.
+   bdmp   = 360.
+   hdmp   = 800.
+/
+!-----------------------------------------------------------------------
+!       nameos   ocean physical parameters
+!-----------------------------------------------------------------------
+!  neos    type of equation of state and Brunt-Vaisala frequency
+!          = 0, UNESCO (formulation of Jackett and McDougall (1994)
+!                                         and of McDougall (1987) )
+!          = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+!          = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+!                               with rau0=1020 set in parcst routine
+!  ralpha  thermal expension coefficient (linear equation of state)
+!  rbeta   saline  expension coefficient (linear equation of state)
+&nameos
+   neos   =      0
+   ralpha =  2.e-4
+   rbeta  =  0.001
+/
+!-----------------------------------------------------------------------
+!       namsol   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+!  nsolv     elliptic solver (=1 preconditioned conjugate gradient: pcg)
+!                            (=2 successive-over-relaxation: sor)
+!                            (=3 FETI: fet, all require "key_feti" defined)
+!                            (=4 sor with extra outer halo)
+!  nsol_arp  absolute/relative (0/1) precision convergence test
+!  nmin      minimum of iterations for the SOR solver
+!  nmax      maximum of iterations for the SOR solver
+!  nmod      frequency of test for the SOR solver
+!  eps       absolute precision of the solver
+!  resmax    absolute precision for the SOR solver
+!  sor       optimal coefficient for SOR solver
+!  epsisl    absolute precision on stream function solver
+!  nmisl     maximum pcg iterations for island
+!  rnu       strength of the additional force used in free surface b.c.
+&namsol
+   nsolv     =      1
+   nsol_arp  =      0
+   nmin      =    300
+   nmax      =    800
+   nmod      =     10
+   eps       =  1.E-6
+   resmax    = 1.E-10
+   sor       =   1.92
+   epsisl    = 1.e-10
+   nmisl     =   4000
+   rnu       =     1.
+/
+!=======================================================================
+!   Diagnostics namelists
+!       namtrd    dynamics and/or tracer trends
+!       namgap    level mean model-data gap
+!       namznl    zonal mean heat & freshwater fluxes computation
+!       namspr    surface pressure in rigid-lid
+!=======================================================================
+!-----------------------------------------------------------------------
+!       namtrd    diagnostics on dynamics and/or tracer trends
+!                         ('key_trdyn' and/or 'key_trdtra')
+!                 or mixed-layer trends ('key_trdmld')
+!-----------------------------------------------------------------------
+!  ntrd              time step frequency dynamics and tracers trends
+!  nctls             control surface type in mixed-layer trends (0,1 or n<jpk)
+!  ln_trdmld_restart restart for ML diagnostics
+!  ucf               unit conversion factor (=1 -> /seconds | =86400. -> /day)
+!  ln_trdmld_instant flag to diagnose trends of instantantaneous or mean ML T/S
+&namtrd
+   ntrd  = 365
+   nctls =   0
+   ln_trdmld_restart = .false.
+   ucf   =  1.
+   ln_trdmld_instant = .false.
+/
+!-----------------------------------------------------------------------
+!       namgap    level mean model-data gap ('key_diagap')
+!-----------------------------------------------------------------------
+!  ngap    time-step frequency of model-data gap computation
+!  nprg    time-step frequency of gap print in model output
+&namgap
+   ngap =  15
+   nprg =  10
+/
+!-----------------------------------------------------------------------
+!       namznl    zonal mean heat & freshwater fluxes computation
+!                 (#ifdef "key_diaznl")
+!-----------------------------------------------------------------------
+!  nfznl   time-step frequency of zonal mean fluxes computation
+&namznl
+   nfznl =  15
+/
+!-----------------------------------------------------------------------
+!       namspr  surface pressure diagnostic
+!-----------------------------------------------------------------------
+!  nmaxp   maximum of iterations for the solver
+!  epsp    absolute precision of the solver
+!  niterp  number of iteration done by the solver
+&namspr
+   nmaxp   =   1000
+   epsp    =  1.e-3
+   niterp  =    400
+/
+!-----------------------------------------------------------------------
+!       namcpl    coupled ocean/atmosphere model  (#ifdef "key_coupled")
+!-----------------------------------------------------------------------
+!  nexco   coupling frequency in time steps
+!  cchan   coupling technique 'PIPE' or 'CLIM'
+&namcpl
+   nexco            =         24
+   cchan            =     'PIPE'
+   nmodcpl          =          2
+   cplmodnam        =   'opa.xx'
+   cploasis         =    'Oasis'
+   nfldo2c          =          2
+   nflxc2o          =          6
+   ntauc2o          =          4
+   cpl_writ(1)      = 'SOSSTSST'
+   cpl_f_writ(1)    =   'ocesst'
+   cpl_writ(2)      = 'SOICECOV'
+   cpl_f_writ(2)    =   'oceice'
+   cpl_readflx(1)   = 'SONSFLDO'
+   cpl_f_readflx(1) =   'oceflx'
+   cpl_readflx(2)   = 'SOSHFLDO'
+   cpl_f_readflx(2) =   'oceflx'
+   cpl_readflx(3)   = 'SOTOPRSU'
+   cpl_f_readflx(3) =   'oceflx'
+   cpl_readflx(4)   = 'SOTFSHSU'
+   cpl_f_readflx(4) =   'oceflx'
+   cpl_readflx(5)   = 'SORUNCOA'
+   cpl_f_readflx(5) =   'oceflx'
+   cpl_readflx(6)   = 'SORIVFLU'
+   cpl_f_readflx(6) =   'oceflx'
+   cpl_readtau(1)   = 'SOZOTAUX'
+   cpl_f_readtau(1) =   'ocetau'
+   cpl_readtau(2)   = 'SOZOTAU2'
+   cpl_f_readtau(2) =   'ocetau'
+   cpl_readtau(3)   = 'SOMETAUY'
+   cpl_f_readtau(3) =   'ocetau'
+   cpl_readtau(4)   = 'SOMETAU2'
+   cpl_f_readtau(4) =   'ocetau'
+/
+!-----------------------------------------------------------------------
+!       namobc    open boundaries parameters (#ifdef key_obc)
+!-----------------------------------------------------------------------
+!  nobc_dta   = 0 the obc data are equal to the initial state
+!             = 1 the obc data are read in 'obc   .dta' files
+!  rdpeob  time relaxation (days) for the east open boundary
+!  rdpwob  time relaxation (days) for the west open boundary
+!  rdpnob  time relaxation (days) for the north open boundary
+!  rdpsob  time relaxation (days) for the south open boundary
+!  zbsic1  barotropic stream function on isolated coastline 1
+!  zbsic2  barotropic stream function on isolated coastline 2
+!  zbsic3  barotropic stream function on isolated coastline 3
+!  ln_obc_clim  climatological obc data files (default T)
+!  ln_vol_cst   total volume conserved
+&namobc
+    nobc_dta =    0
+    rdpein   =    1.
+    rdpwin   =    1.
+    rdpnin   =   30.
+    rdpsin   =    1.
+    rdpeob   = 1500.
+    rdpwob   =   15.
+    rdpnob   =  150.
+    rdpsob   =   15.
+    zbsic1   =  140.e+6
+    zbsic2   =    1.e+6
+    zbsic3   =    0.
+    ln_obc_clim = .true.
+    ln_vol_cst  = .false.
+/
+!-----------------------------------------------------------------------
+!       namflo    float parameters (#ifdef key_float)
+!-----------------------------------------------------------------------
+!  ln_rstflo   boolean term for float restart (true or false)
+!  nwritefl   frequency of float output file 
+!  nstockfl   frequency of float restart file 
+!  ln_argo    Argo type floats (stay at the surface each 10 days)
+!  ln_flork4  = T trajectories computed with a 4th order Runge-Kutta
+!             = F  (default)   computed with Blanke' scheme
+&namflo
+    ln_rstflo = .false.
+    nwritefl  =      75
+    nstockfl  =    5475
+    ln_argo   = .false.
+    ln_flork4 = .false.
+/
+!-----------------------------------------------------------------------
+!       namcore  CORE
+!-----------------------------------------------------------------------
+!
+!  In this version there are 8 files ( jpfile = 8)
+!  THE ORDER OF THE FILES MATTER:
+!  1 - precipitation total (rain+snow)  in kg/m2/s
+!  2,3 -  u10,v10 -> scalar wind at 10m in m/s -  ON 'T' GRID POINTS!!!
+!  4 - solar radiation (short wave)     in W/m2
+!  5 - thermal radiation (long wave)    in W/m2
+!  6 - specific humidity                in %
+!  7 - temperature at 10m               in degrees K
+!  8 - precipitation (snow only)        in kg/m2/s
+!
+!  ln_2m         boolean (default F), used to indicate that Tair & humidity
+!                are given at 2m. In this case, the default file names &
+!                variables are t2.nc, t2, q2.nc, q2
+!  alpha_precip  real coefficient used as a multiplying  factor  for the precip
+!  clname        file names (256 char max for each)
+!  clvarname     name of variable in netcdf file (32 char max)
+!  freqh         frequency of fields in the file
+!                it is in hours (6 hourly, daily) if positive.
+!                if freqh = -12 the file contains 12 monthly data.
+&namcore
+   ln_2m        = .FALSE.
+   alpha_precip = 1.
+   clname    = 'precip.nc' 'u10.nc' 'q10.nc' 'v10.nc' 'radsw.nc' 'radlw.nc' 't10.nc' 'snow.nc'
+   clvarname =  'precip'    'u10'    'q10'    'v10'    'radsw'    'radlw'    't10'    'snow'
+   freqh     =    -12        24        24       24       24         24        24       -12
+/
+!-----------------------------------------------------------------------
+!       namagrif    agrif parameters (#ifdef key_agrif)
+!-----------------------------------------------------------------------
+! visc_tra viscosity coeeficient for tracers sponge layer
+! visc_dyn viscosity coeeficient for dynamics sponge layer
+&namagrif
+    visc_tra = 2880.
+    visc_dyn = 2880.
+/
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist_ice
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist_ice	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/1_namelist_ice	(revision 4536)
@@ -0,0 +1,186 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! ICE namelist :  ice model option and parameter input
+! -------------
+!
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicerun   Share parameters for dynamics/advection/thermo
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  ln_limdyn   : switch for ice dynamics (true) or not (false)
+!  ln_limdmp   : restoring Ice thickness and Fraction leads flag
+!  acrit(1/2)  : minimum fraction for leads in the Northern (Southern) Hemisphere
+!  hnsdif      : computation of temperature in snow (=0.0) or not (=9999.0)
+!  hicdif      : computation of temperature in ice  (=0.0) or not (=9999.0)
+!
+&namicerun
+   ln_limdyn = .true. 
+   ln_limdmp = .FALSE. 
+   acrit     = 1.0e-06 , 1.0e-06
+   hsndif    = 0.0 
+   hicdif    = 0.0
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namiceini   parameters for ice initialisation
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  ln_limini : Ice initialization state flag
+!  ttest     : threshold water temperature for initial sea ice
+!  hninn     : initial snow thickness in the north
+!  hginn     : initial ice thickness in the north
+!  alinn     : initial leads area in the north
+!  hnins     : initial snow thickness in the south
+!  hgins     : initial ice thickness in the south
+!  alins     : initial leads area in the south
+!
+&namiceini
+   ln_limini = .FALSE. 
+   ttest = 2.0
+   hninn = 0.5
+   hginn = 3.0
+   alinn = 0.05
+   hnins = 0.1
+   hgins = 1.0
+   alins = 0.1
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicedia   parameters for ice diagnostics
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  fmtinf : format of the output values 
+!  nfrinf : number of variables written in one line
+!  ntmoy  : instantaneous values of ice evolution or averaging
+!  ninfo  : frequency of ouputs on file ice_evolu in case of averaging
+!
+&namicedia
+   fmtinf = '1PE13.5 '
+   nfrinf = 4
+   ntmoy  = 1
+   ninfo  = 1
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicedyn   parameters for ice dynamic
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  epsd   : tolerance parameter
+!  alpha  : coefficient for semi-implicit coriolis
+!  bound  : boundary conditions (=0.0 no-slip, =1.0 free-slip)
+!  dm     : diffusion constant for dynamics.
+!  nbiter : number of sub-time steps for relaxation
+!  nbitdr : maximum number of iterations for relaxation
+!  om     : relaxation constant 
+!  resl   : maximum value for the residual of relaxation 
+!  cw     : drag coefficient for oceanic stress
+!  angvg  : turning angle for oceanic stress
+!  pstar  : first bulk-rheology parameter
+!  c_rhg  : second bulk-rhelogy parameter
+!  etamn  : minimun value for viscosity
+!  creepl : creep limit
+!  ecc    : eccentricity of the elliptical yield curve
+!  ahi0   : horizontal eddy diffusivity coefficient for sea-ice (m2/s)
+!
+&namicedyn 
+   epsd   = 1.0e-20
+   alpha  = 0.5
+   dm     = 0.6e+03
+   nbiter = 1
+   nbitdr = 100
+   om     = 0.5
+   resl   = 5.0e-05
+   cw     = 5.0e-03
+   angvg  = 0.0
+   pstar  = 1.0e+04 
+   c_rhg  = 20.0
+   etamn  = 0.0e+07
+   creepl = 2.0e-08
+   ecc    = 2.0
+   ahi0   = 350.e0
+/
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicetrp   parameters for ice advection
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!  bound  : boundary conditions (=0.0 no-slip, =1.0 free-slip)
+&namicetrp 
+   bound  = 0.
+/
+
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicethd   parameters for thermodynamic computation
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  hmelt       : maximum melting at the bottom
+!  hiccrit(1/2): ice thickness for lateral accretion in the Northern (Southern) Hemisphere
+!                caution 1.0, 1.0 best value to be used!!! (gilles G.)
+!  hicmin      : ice thickness corr. to max. energy stored in brine pocket
+!  hiclim      : minimum ice thickness
+!  amax        : maximum lead fraction
+!  swiqst      : energy stored in brine pocket (=1) or not (=0)	
+!  sbeta       : numerical caracteritic of the scheme for diffusion in ice
+!               Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)
+!  parlat      : percentage of energy used for lateral ablation
+!  hakspl      : slope of distr. for Hakkinen-Mellor's lateral melting
+!  hibspl      : slope of distribution for Hibler's lateral melting
+!  exld        : exponent for leads-closure rate
+!  hakdif      : coefficient for diffusions of ice and snow
+!  thth         : threshold thickness for comp. of eq. thermal conductivity
+!  hnzst       : thickness of the surf. layer in temp. computation
+!  parsub      : switch for snow sublimation or not
+!  alphs       : coefficient for snow density when snow ice formation
+! 
+&namicethd
+   hmelt   = -0.15
+   hiccrit = 0.3 , 0.3
+   hicmin  = 0.2
+   hiclim  = 0.05
+   amax    = 0.999 
+   swiqst  = 1.
+   sbeta   = 1.
+   parlat  = 0.0
+   hakspl  = 0.5
+   hibspl  = 0.5
+   exld    = 2.0
+   hakdif  = 1.0
+   thth    = 0.2
+   hnzst   = 0.1
+   parsub  = 1.0
+   alphs   = 1.0
+/
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namiceout   parameters for outputs
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!   noumef      : number of fields
+!   field
+!        title  : title of the field
+!        name   : name of the field
+!        unit   : unit of the field
+!        nc     : switch for saving field ( = 1 ) or not ( = 0 )
+!        cmulti : multiplicative constant
+!        cadd   : additive constant
+!
+&namiceout
+   noumef   = 19
+   field_1  = 'Snow thickness                     ', 'isnowthi', 'm       ', 1, 1.0, 0.0
+   field_2  = 'Ice thickness                      ', 'iicethic', 'm       ', 1, 1.0, 0.0
+   field_3  = 'Ice produced                       ', 'iiceprod', 'm/kt    ', 1, 1.0, 0.0
+   field_4  = 'Ice concentration                  ', 'ileadfra', '%       ', 1, -1.0, 1.0
+   field_5  = 'Ice temperature                    ', 'iicetemp', 'C       ', 1, 1.0, -273.15
+   field_6  = 'Oceanic flux at the ice base       ', 'ioceflxb', 'w/m2    ', 1, 1.0, 0.0
+   field_7  = 'Ice velocity u                     ', 'iicevelu', 'm/s     ', 1, 1.0, 0.0
+   field_8  = 'Ice velocity v                     ', 'iicevelv', 'm/s     ', 1, 1.0, 0.0
+   field_9  = 'Sea surface temperature            ', 'isstempe', 'C       ', 1, 1.0, -273.15
+   field_10 = 'Sea surface salinity               ', 'isssalin', 'PSU     ', 1, 1.0, 0.0
+   field_11 = 'Total flux at ocean surface        ', 'iocetflx', 'w/m2    ', 1, 1.0, 0.0
+   field_12 = 'Solar flux at ocean surface        ', 'iocesflx', 'w/m2    ', 1, 1.0, 0.0
+   field_13 = 'Non-solar flux at ocean surface    ', 'iocwnsfl', 'w/m2    ', 1, 1.0, 0.0
+   field_14 = 'Salt flux at ocean surface         ', 'iocesafl', 'kg/m2/kt', 1, 1.0, 0.0
+   field_15 = 'Wind stress u                      ', 'iocestru', 'Pa      ', 1, 1.0, 0.0
+   field_16 = 'Wind stress v                      ', 'iocestrv', 'Pa      ', 1, 1.0, 0.0 
+   field_17 = 'Solar flux at ice/ocean surface    ', 'iicesflx', 'w/m2    ', 1, 1.0, 0.0
+   field_18 = 'Non-solar flux at ice/ocean surface', 'iicenflx', 'w/m2    ', 1, 1.0, 0.0
+   field_19 = 'Snow precipitation                 ', 'isnowpre', 'kg/day  ', 1, 1.0, 0.0
+/      
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AA_job
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AA_job	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AA_job	(revision 4536)
@@ -0,0 +1,173 @@
+#-Q- sxnec ##################
+#-Q- sxnec ## SXNEC IDRIS
+#-Q- sxnec ##################
+#-Q- sxnec #@$-r :XXX:XXX:XXX:           # job name
+#-Q- sxnec #@$-o output_XXXXXXX.1        # outputfile name
+#-Q- sxnec #@$-me                        # sends a mail at the end of execution
+#-Q- sxnec #@$-eo                        # merge standard error and output
+#-Q- sxnec #@$-jo                        # print a short performance analysis
+#-Q- sxnec #@$-lT 1:00:00                # Max total CPU time
+#-Q- sxnec #@$-lt 0:59:00                # Max CPU time per process
+#-Q- sxnec #@$-lM 2Gb                    # Max memory
+#-Q- sxnec ##@$-c 4                     # Max number of simultaneous procs used (here=4)
+#-Q- sxnec ##@$-q multi                 # Use more than 1 proc
+#-Q- aix ##################
+#-Q- aix ## IBM   IDRIS  ##
+#-Q- aix ##################
+#-Q- aix #@job_name= :XXX:XXX:XXX:          
+#-Q- aix #@output= output_XXXXXXX.1          
+#-Q- aix #@error= error_XXXXXXX.1          
+#-Q- aix #@cpu_limit= 5000
+#-Q- aix #@stack_limit= 200Mb        
+#-Q- aix #@data_limit= 1.8Gb         
+#-Q- aix #@notification= complete
+#-Q- aix #@total_tasks= 1 
+#-Q- aix #@job_type= parallel
+#-Q- aix #@queue
+#-Q- sx8brodie ##################
+#-Q- sx8brodie ## SX8NEC IDRIS ##
+#-Q- sx8brodie ##################
+#-Q- sx8brodie #PBS -N :XXX:XXX:XXX:        # job name
+#-Q- sx8brodie #PBS -o output_XXXXXXX.1     # outputfile name
+#-Q- sx8brodie #PBS -j o                    # merge standard error and output
+#-Q- sx8brodie #PBS -S /usr/bin/ksh         # user shell
+#-Q- sx8brodie #PBS -l memsz_job=3.6gb      # Max memory
+#-Q- sx8brodie #PBS -l cputim_prc=1:01:00   # Max CPU time/prc
+#-Q- sx8brodie #PBS -l cputim_job=1:01:00   # Max CPU time/job
+#-Q- sx8brodie ##PBS -l cpunum_job=4
+#-Q- sx8brodie ##PBS -q multi
+#-Q- sx6nec ##################
+#-Q- sx6nec ## SX6NEC   CEA ##
+#-Q- sx6nec ##################
+#-Q- sx6nec #PBS -N :XXX:XXX:XXX:        # job name
+#-Q- sx6nec #PBS -o output_XXXXXXX.1     # outputfile name
+#-Q- sx6nec #PBS -j o                    # merge standard error and output
+#-Q- sx6nec #PBS -S /usr/bin/ksh         # user shell
+#-Q- sx6nec #PBS -l memsz_job=3.6gb      # Max memory
+#-Q- sx6nec #PBS -l cputim_job=1:01:00   # Max CPU time
+#-Q- sx6nec #PBS -q prod
+#-Q- sx6nec ##PBS -l cpunum_prc=4
+#-Q- sx6nec ##PBS -q parallel
+########################################################################
+##
+##      Script to run a short experiment when installing the
+##      ORCA2_LIM configuration 
+##
+##            Rachid Benshila, OPA System Team
+##
+##
+#########################################################################
+##-- print echo of commands before and after shell interpretation
+date
+set -vx
+
+#################################
+# Beginning of user modification
+#################################
+
+##-- define some directories : 
+#- Input file storing 
+#-Q- sxnec R_FORCING="gaya:/u/rech/eee/reee512/NEMO"
+#-Q- sx8brodie R_FORCING="gaya:/u/rech/eee/reee512/NEMO"
+#-Q- aix R_FORCING="gaya:/u/rech/eee/reee512/NEMO"
+#-Q- sx6nec R_FORCING="/dmnfs/p86bensh/NEMO"
+#- Launching run repository
+#-Q- sxnec R_EXPER=${QSUB_WORKDIR:-${PWD}}
+#-Q- sx8brodie R_EXPER=${PBS_O_WORKDIR}
+#-Q- aix R_EXPER=${QSUB_WORKDIR:-${PWD}}
+#-Q- sx6nec R_EXPER=${PWD}
+#- modipsl repository
+R_EXEDIR=MMMMMMM     
+#- output files storing 
+R_SORTIE_OCE=AAAAAAA/ORCA2_LIM
+#- execution repository
+R_TMP=$TMPDIR         
+
+##-- define processus number : to change when running in mpp
+NB_PROC=1
+
+#################################
+# End of user modification
+#################################
+
+#--  define a fonction to get the input tarfile
+#-Q- sxnec Rapatrie () { [ -f $1/$2 ] || ( rcp ${R_FORCING}/$2 $1 ; cd $1; tar xvf $2 ;) }
+#-Q- sx8brodie Rapatrie () { [ -f $1/$2 ] || ( rcp ${R_FORCING}/$2 $1 ; cd $1; tar xvf $2 ;) }
+#-Q- aix Rapatrie () { [ -f $1/$2 ] || ( rcp ${R_FORCING}/$2 $1 ; cd $1; tar xvf $2 ;) }
+#-Q- sx6nec Rapatrie () { [ -f $1/$2 ] || ( cp ${R_FORCING}/$2 $1 ; cd $1; tar xvf $2 ;) }
+
+[ -d ${R_TMP} ] || mkdir ${R_TMP}
+cd ${R_TMP}
+
+#--  get the executable
+#-Q- sxnec rcp ${LOGNAME}@rhodes:${R_EXEDIR}/bin/opa opa.xx
+#-Q- sx8brodie rcp ${LOGNAME}@brodie:${R_EXEDIR}/bin/opa opa.xx
+#-Q- aix cp ${R_EXEDIR}/bin/opa opa.xx
+#-Q- sx6nec cp ${R_EXEDIR}/bin/opa opa.xx
+chmod 777 opa.xx
+
+## --  Copy ancillary files
+#
+#- Namelist for ocean and ice
+cp ${R_EXPER}/namelist_ice namelist_ice 
+cp ${R_EXPER}/namelist namelist
+
+#- Namelist for ocean and ice (agrif fine grid)
+cp ${R_EXPER}/1_namelist_ice 1_namelist_ice 
+cp ${R_EXPER}/1_namelist 1_namelist
+cp ${R_EXPER}/AGRIF_FixedGrids.in AGRIF_FixedGrids.in
+
+#- Files for the configuration and ocean dynamics
+Rapatrie ${R_TMP} ORCA2_LIM_nemo_v2.tar
+
+ls -alF
+
+#-Q- sxnec export F_PROGINF=yes
+#-Q- sxnec export F_ERRCNT=5
+#-Q- sx8brodie export F_PROGINF=yes
+#-Q- sx8brodie export F_ERRCNT=5
+#-Q- sx6nec export F_PROGINF=yes
+#-Q- sx6nec export F_ERRCNT=5
+
+#-Q- sxnec #- To be use for a mpp run
+#-Q- sxnec #mpirun -np ${NB_PROC} ./opa.xx
+#-Q- sx8brodie #- To be use for a mpp run
+#-Q- sx8brodie #mpirun -np ${NB_PROC} ./opa.xx
+#-Q- sx6nec #- To be use for a mpp run
+#-Q- sx6nec #mpirun -np ${NB_PROC} ./opa.xx
+
+./opa.xx
+
+## -- Save output files
+ls -alF
+#- to copy on a storage machine
+#-Q- sxnec DPUT=mfput
+#-Q- sx8brodie DPUT=mfput
+#-Q- aix DPUT=mfput
+#-Q- sx6nec DPUT=putfer 
+#-Q- sx6nec [ -d ${R_SORTIE_OCE} ] || mkdir -p ${R_SORTIE_OCE}
+
+#- Save ocean output files
+$DPUT *ocean.output ${R_SORTIE_OCE}/.
+$DPUT *solver.stat ${R_SORTIE_OCE}/.
+[ -f *mpp.output* ] && $DPUT *mpp.output* ${R_SORTIE_OCE}/.
+for file_netcdf in *_grid_*.nc
+do
+$DPUT ${file_netcdf} ${R_SORTIE_OCE}/${file_netcdf}
+done
+#
+#- Save ice output files
+for file_netcdf in *icemod*
+do
+$DPUT ${file_netcdf} ${R_SORTIE_OCE}/${file_netcdf} 
+done
+$DPUT ice.evolu ${R_SORTIE_OCE}/ice.evolu 
+#
+#- Save restart files
+for restart in *restart*
+do
+$DPUT ${restart} ${R_SORTIE_OCE}/${restart} 
+done
+#
+#- Save ftrace file
+[ -f ftrace.out* ] && $DPUT ftrace.out* ${R_SORTIE_OCE}/.
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AGRIF_FixedGrids.in
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AGRIF_FixedGrids.in	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/AGRIF_FixedGrids.in	(revision 4536)
@@ -0,0 +1,3 @@
+1
+125 170 36 63 4 4 2
+0
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/EMPave_old.dat
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/EMPave_old.dat	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/EMPave_old.dat	(revision 4536)
@@ -0,0 +1,1 @@
+                               0  0.0000000000000000E+00  0.0000000000000000E+00
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 4536)
@@ -0,0 +1,757 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+! OPA namelist :  model option and parameter input
+! -------------
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!-----------------------------------------------------------------------
+!       namrun   parameters of the run
+!-----------------------------------------------------------------------
+!  no         job number
+!  cexper     experience name for vairmer format
+!  ln_rstart  boolean term for restart (true or false)
+!  nrstdt     control of the restart timestep:
+!                = 0 restart, do not control nit000 in the restart file.
+!                = 1 restart, control nit000 in the restart file. Do not
+!                    use the date in the restart file (use ndate0 in namelist)
+!                = 2 restart, control nit000 in the restart file, use the date
+!                    in the restart file. ndate0 in the namelist is ignored.
+!  nit000     number of the first time step
+!  nitend     number of the last time step
+!  ndate0     initial calendar date aammjj
+!  nleapy     Leap year calendar (0/1)
+!  ninist     initial state output flag (0/1)
+!  nstock     frequency of restart file
+!  nwrite     frequency of OUTPUT file
+!  nrunoff    = 0 no, 1 runoff, 2 runoff+river mouth ups adv
+!  ln_dimgnnn (F/T) 1 DIMG file - (for all proc/per proc)
+!
+!  CAUTION: for usual run scripts, logical value of
+!  *******  ln_rstart must be .true. or .false.
+!                     and NOT .TRUE. or .FALSE.
+&namrun
+   no         =       0
+   cexper     =  "ORCA2"
+   ln_rstart  = .false.
+   nrstdt     =       0
+   nit000     =       1
+   nitend     =    5475
+   ndate0     =  010101
+   nleapy     =       0
+   ninist     =       0
+   nstock     =    5475 
+   nwrite     =    5475 
+   nrunoff    =       2
+   ln_dimgnnn = .FALSE.
+/
+!-----------------------------------------------------------------------
+!       nam_ctl      Control prints & Benchmark
+!-----------------------------------------------------------------------
+!  ln_ctl     trends control print (expensive!)
+!  nprint     level of print (0 no print)
+!  nictls     start i indice to make the control SUM (very usefull to compare mono-
+!  nictle     end   i indice to make the control SUM (-versus multi processor runs)
+!  njctls     start j indice to make the control SUM (very usefull to compare mono-
+!  njctle     end   j indice to make the control SUM (-versus multi processor runs)
+!  nisplt     number of processors following i
+!  njsplt     number of processors following j
+!  nbench     Bench parameter (0/1): CAUTION it must be zero except for bench
+!             for which we don't care about physical meaning of the results
+!  nbit_cmp   bit comparison mode parameter (0/1): enables bit comparison between 
+!             single and multiple processor runs.
+&namctl
+   ln_ctl =  .false.
+   nprint =       0
+   nictls =       0
+   nictle =       0
+   njctls =       0
+   njctle =       0
+   isplt  =       1
+   jsplt  =       1
+   nbench =       0
+   nbit_cmp =     0
+/
+!-----------------------------------------------------------------------
+!       nam_mpp      Massively Parallel Processing
+!-----------------------------------------------------------------------
+!  c_mpi_send         mpi send/recieve type
+!                      = 'S'  : standard blocking send
+!                      = 'B'  : buffer blocking send
+!                      = 'I'  : immediate non-blocking send
+&nam_mpp
+   c_mpi_send =  'S'
+/
+!-----------------------------------------------------------------------
+!       nam_mpp_dyndist      Massively Parallel Distribution
+!              #ifdef ( key_agrif && key_mpp_dyndist )
+!-----------------------------------------------------------------------
+!  jpni   number of processors following i
+!  jpnj   number of processors following j
+!  jpnij  number of local domains
+&nam_mpp_dyndist
+   jpni  = 1
+   jpnj  = 1
+   jpnij = 1
+/
+!-----------------------------------------------------------------------
+!       nam_zgr       vertical coordinate
+!-----------------------------------------------------------------------
+!  ln_zco     z-coordinate - full steps      (T/F)
+!  ln_zps     z-coordinate - partial steps   (T/F)
+!  ln_sco     s- or hybrid z-s-coordinate    (T/F)
+&nam_zgr
+   ln_zco   =  .false.
+   ln_zps   =  .true.
+   ln_sco   =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_zgr_sco   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+!  sbot_min   minimum depth of s-bottom surface (>0) (m)
+!  sbot_max   maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+!  theta      surface control parameter (0<=theta<=20)
+!  thetb      bottom control parameter  (0<=thetb<= 1)
+!  r_max      maximum cut-off r-value allowed (0<r_max<1)
+&nam_zgr_sco
+   sbot_min =  300.
+   sbot_max = 5250.
+   theta    =    6.0
+   thetb    =    0.75
+   r_max    =    0.15
+/
+!-----------------------------------------------------------------------
+!       nam_traadv   advection scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_traadv_cen2     2nd order centered scheme    (default T)
+!  ln_traadv_tvd      TVD scheme                   (default F)
+!  ln_traadv_muscl    MUSCL scheme                 (default F)
+!  ln_traadv_muscl2   MUSCL2 scheme                (default F)
+!  ln_traadv_ubs      UBS scheme                   (default F)
+!  ln_traadv_qck      QUICKEST scheme              (default F)
+&nam_traadv
+   ln_traadv_cen2   =  .true.
+   ln_traadv_tvd    =  .false.
+   ln_traadv_muscl  =  .false.
+   ln_traadv_muscl2 =  .false.
+   ln_traadv_ubs    =  .false.
+   ln_traadv_qck    =  .false.
+/
+!-----------------------------------------------------------------------
+!       nam_traldf   lateral diffusion scheme for tracer (option not control by CPP keys)
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_traldf_lap    laplacian operator          (default T)
+!     ln_traldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_traldf_level  iso-level                   (default F)
+!     ln_traldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_traldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!     aht0    horizontal eddy diffusivity for tracers (m2/s)
+!     ahtb0   background eddy diffusivity for isopycnal diffusion (m2/s)
+!     aeiv0   eddy induced velocity coefficient (m2/s)
+! ^* require key_ldfslp to compute the direction of the lateral diffusion
+! ^** require key_ldfslp in s-coordinate
+&nam_traldf
+   ln_traldf_lap    =  .true.
+   ln_traldf_bilap  =  .false.
+   ln_traldf_level  =  .false.
+   ln_traldf_hor    =  .false.
+   ln_traldf_iso    =  .true.
+   aht0    =  2000.
+   ahtb0   =     0.
+   aeiv0   =  2000.
+/
+!-----------------------------------------------------------------------
+!       nam_dynldf   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+!  Type of the operator : 
+!     ln_dynldf_lap    laplacian operator          (default T)
+!     ln_dynldf_bilap  bilaplacian operator        (default F)
+!  Direction of action  : 
+!     ln_dynldf_level  iso-level                   (default F)
+!     ln_dynldf_hor    horizontal (geopotential)   (default F)^**
+!     ln_dynldf_iso    iso-neutral                 (default T)^*
+!  Coefficient
+!  ahm0    horizontal eddy viscosity for the dynamics (m2/s)
+!  ahmb0   background eddy viscosity for isopycnal diffusion (m2/s)
+&nam_dynldf
+   ln_dynldf_lap    =  .true.
+   ln_dynldf_bilap  =  .false.
+   ln_dynldf_level  =  .false.
+   ln_dynldf_hor    =  .true.
+   ln_dynldf_iso    =  .false.
+   ahm0    = 40000.
+   ahmb0   =     0.
+/
+!-----------------------------------------------------------------------
+!       namflg   algorithm flags (algorithm not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynhpg_imp   hydrostatic pressure gradient: semi-implicit time scheme  (T)
+!                                                  centered      time scheme  (F)
+!   nn_dynhpg_rst  add dynhpg implicit variables in restart ot not (1/0)
+&namflg
+   ln_dynhpg_imp   =  .false.
+   nn_dynhpg_rst   =  0
+/
+!-----------------------------------------------------------------------
+!       nam_dynhpg   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+!  type of pressure gradient scheme (choose one only!)
+!     ln_hpg_zco    z-coordinate - full steps                   (default T)
+!     ln_hpg_zps    z-coordinate - partial steps (interpolation)
+!     ln_hpg_sco    s-coordinate (standard jacobian formulation)
+!     ln_hpg_hel    s-coordinate (helsinki modification)
+!     ln_hpg_wdj    s-coordinate (weighted density jacobian)
+!     ln_hpg_djc    s-coordinate (Density Jacobian with Cubic polynomial)
+!     ln_hpg_rot    s-coordinate (ROTated axes scheme)
+!  parameters
+!    gamm          weighting coefficient (wdj scheme)
+&nam_dynhpg
+   ln_hpg_zco = .false.
+   ln_hpg_zps = .true.
+   ln_hpg_sco = .false.
+   ln_hpg_hel = .false.
+   ln_hpg_wdj = .false.
+   ln_hpg_djc = .false.
+   ln_hpg_rot = .false.
+   gamm       = 0.e0
+/
+!-----------------------------------------------------------------------
+!       nam_dynadv   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynadv_vec      vector form flag
+!  ln_dynadv_cen2     flux form - 2nd order centered scheme    (default T)
+!  ln_dynadv_ubs      flux form - 3rd order UBS scheme         (default F)
+&nam_dynadv   
+   ln_dynadv_vec   = .TRUE.
+   ln_dynadv_cen2  = .FALSE.
+   ln_dynadv_ubs   = .FALSE.
+/  
+!-----------------------------------------------------------------------
+!       nam_dynvor   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+!  ln_dynvor_ens   vorticity trends: enstrophy conserving scheme (default T)
+!  ln_dynvor_ene      "         "  : energy conserving scheme    (default F)
+!  ln_dynvor_mix      "         "  : mixed scheme                (default F)
+!  ln_dynvor_een      "         "  : energy & enstrophy scheme   (default F)
+&nam_dynvor
+   ln_dynvor_ene = .FALSE.
+   ln_dynvor_ens = .TRUE.
+   ln_dynvor_mix = .FALSE.
+   ln_dynvor_een = .FALSE.
+/
+!-----------------------------------------------------------------------
+!       namtau   surface wind stress
+!-----------------------------------------------------------------------
+!  ntau000   gently increase the stress over the first ntau_rst time-steps
+!  tau0x     uniform value used as default surface heat flux
+!  tau0y     uniform value used as default solar radiation flux
+&namtau
+   ntau000 =      0
+   tau0x   =      0.e0
+   tau0y   =      0.e0
+/
+!-----------------------------------------------------------------------
+!       namflx   surface fluxes
+!-----------------------------------------------------------------------
+!  q0       uniform value used as default surface heat flux
+!  qsr0     uniform value used as default solar radiation flux
+!  emp0     uniform value used as default surface freswater budget (E-P)
+!  dqdt0    feedback coefficient for SST damping (W/m2/K)
+!  deds0    feedback coefficient for SSS damping (mm/day)
+&namflx
+   q0      =      0.e0
+   qsr0    =      0.e0
+   emp0    =      0.e0
+   dqdt0   =      -40.
+   deds0   =        0.
+/
+!-----------------------------------------------------------------------
+!       namalb   albedo parameters
+!-----------------------------------------------------------------------
+!  cgren    correction of the snow or ice albedo to take into account
+!  albice   albedo of melting ice in the arctic and antarctic
+!  alphd    coefficients for linear interpolation used to compute albedo
+!           between two extremes values (Pyane, 1972)
+!  alphc     "                                         "
+!  alphdi    "                                         "
+&namalb
+   cgren    =      0.06
+   albice   =      0.5
+   alphd    =      0.80
+   alphc    =      0.65
+   alphdi   =      0.72
+/
+!-----------------------------------------------------------------------
+!       namdom   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+!  ntopo      = 0/1 ,compute/read the bathymetry file
+!               (mbathy, nb of T-ocean levels)
+!  e3zps_min  the thickness of the partial step is set larger than the
+!  e3zps_rat     the minimum of e3zps_min and e3zps_rat * e3t
+!                (N.B. 0<e3zps_rat<1)
+!  nmsh       =1 create a mesh file (coordinates, scale factors, masks)
+!  nacc       the acceleration of convergence method
+!             = 0, no acceleration, rdt = rdttra
+!             = 1, acceleration used, rdt < rdttra(k)
+!  atfp       asselin time filter parameter
+!  rdt        time step for the dynamics (and tracer if nacc=0)
+!  rdtmin     minimum time step on tracers
+!  rdtmax     maximum time step on tracers
+!  rdth       depth variation of tracer time step
+!  rdtbt      barotropic time step (for the time splitting algorithm)
+!  nfice      frequency of ice model call
+!  nfbulk     frequency of bulk formulea call (not used if ice used)
+!  nclosea    = 0 no closed sea 
+!             = 1 closed sea (Black Sea, Caspian Sea, Great US Lakes...) 
+&namdom
+   ntopo     =     1
+   e3zps_min =     5.
+   e3zps_rat =     0.1
+   nmsh      =     0
+   nacc      =     0
+   atfp      =     0.1
+   rdt       =  5760.
+   rdtmin    =  5760.
+   rdtmax    =  5760.
+   rdth      =   800.
+   rdtbt     =    90.
+   nfice     =     5  
+   nfbulk    =     5  
+   nclosea   =     0
+/
+!-----------------------------------------------------------------------
+!       namfwb   freshwater budget correction
+!-----------------------------------------------------------------------
+!  ln_fwb     logical flag for freshwater budget correction (0 annual mean)
+&namfwb
+   ln_fwb    = .true.
+/
+!-----------------------------------------------------------------------
+!       namptr   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+!  ln_diaptr  logical flag for Poleward transport computation
+!  ln_subbas  logical flag for Atlantic/Pacific/Indian basins computation
+!             need input basins mask file named "subbasins.nc"
+!  nf_ptr     Frequency of computation
+&namptr
+   ln_diaptr = .false.
+   ln_subbas = .false.
+   nf_ptr    =  15
+/
+!-----------------------------------------------------------------------
+!       namcro   cross land advection
+!-----------------------------------------------------------------------
+!  n_cla   advection between 2 ocean pts separates by land 
+&namcla
+   n_cla   = 1
+/
+!-----------------------------------------------------------------------
+!       namzdf   vertical physics
+!-----------------------------------------------------------------------
+!  ln_zdfevd  enhanced vertical diffusion         (default T)
+!  ln_zdfnpc  Non-Penetrative Convection          (default T)
+!  avm0       vertical eddy viscosity for the dynamic (m2/s)
+!  avt0       vertical eddy diffusivity for tracers (m2/s)
+!  avevd      vertical coefficient for enhanced diffusion scheme (m2/s)
+!  nevdm      = 0  apply enhanced mixing on tracer only
+!             = 1  apply enhanced mixing on both tracer and momentum
+!  ln_zdfexp   vertical physics: (=T)  time splitting (T)     (Default=F)
+!                               (=F)  euler backward (F)
+!  n_zdfexp   number of sub-timestep for time splitting scheme
+&namzdf
+   ln_zdfevd = .true.
+   ln_zdfnpc = .false.
+   avm0      = 1.2e-4
+   avt0      = 1.2e-5
+   avevd     =   100.
+   n_evdm    =     1
+   ln_zdfexp =  .false.
+   n_zdfexp  =     3
+/
+!-----------------------------------------------------------------------
+!       namnpc   vnon penetrative convection
+!-----------------------------------------------------------------------
+!  nnpc1   non penetrative convective scheme frequency
+!  nnpc2   non penetrative convective scheme print frequency
+&namnpc
+   nnpc1  =      1
+   nnpc2  =    365
+/
+!-----------------------------------------------------------------------
+!       nambbl   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+!  atrbbl   lateral tracer coeff. for bottom boundary layer scheme(m2/s)
+&nambbl
+   atrbbl = 10000.
+/
+!-----------------------------------------------------------------------
+!       namric   richardson number dependent vertical diffusion
+!                ( #ifdef "key_zdfrichardson" )
+!-----------------------------------------------------------------------
+!  avmri   maximum value of the vertical viscosity
+!  alp     coefficient of the parameterization
+!  nric    coefficient of the parameterization
+&namric
+   avmri = 100.e-4
+   alp   =      5.
+   nric  =       2
+/
+!-----------------------------------------------------------------------
+!       namtke   turbulent eddy kinetic dependent vertical diffusion
+!                ( #ifdef "key_zdftke" )
+!-----------------------------------------------------------------------
+!  ln_rstke flag to restart with tke from a run without tke (default F)
+!  ediff    coef. to compute vertical eddy coef. (avt=ediff*mxl*sqrt(e) )
+!  ediss    coef. of the Kolmogoroff dissipation  
+!  ebb      coef. of the surface input of tke
+!  efave    coef. to applied to the tke diffusion ( avtke=efave*avm )
+!  emin     minimum value of tke (m^2/s^2)
+!  emin0    surface minimum value of tke (m^2/s^2)
+!  nitke    number of restart iterative loops
+!  ri_c     critic richardson number
+!  nmxl     flag on mixing length used
+!           = 0 bounded by the distance to surface and bottom
+!           = 1 bounded by the local vertical scale factor
+!           = 2 first vertical derivative of mixing length bounded by 1
+!  npdl     flag on prandtl number
+!           = 0 no vertical prandtl number (avt=avm)
+!           = 1 prandtl number function of richarson number (avt=pdl*avm)
+!           = 2 same as = 1 but a shapiro filter is applied on pdl
+!  nave     =  horizontal averaged (=1) or not (=0) of avt  (default =1)
+!  navb     = 0 cst background avt0, avm0 / =1 profile used on avtb
+&namtke
+   ln_rstke = .false.
+   ediff =       0.1
+   ediss =       0.7
+   ebb   =      3.75
+   efave =        1.
+   emin  =     1.e-6
+   emin0 =     1.e-4
+   nitke =        50
+   nmxl  =         2
+   npdl  =         1
+   navb  =         0
+/
+!-----------------------------------------------------------------------
+!       namkpp   K-Profile Parameterization dependent vertical diffusion
+!                ( #ifdef "key_zdfkpp" )
+!-----------------------------------------------------------------------
+!  ln_kpprimix   shear instability mixing  (default T)
+!  difmiw        constant internal wave viscosity (m2/s)
+!  difsiw        constant internal wave diffusivity (m2/s)
+!  Riinfty       local Richardson Number limit for shear instability
+!  difri         maximum shear mixing at Rig = 0    (m2/s)
+!  bvsqcon       Brunt-Vaisala squared (1/s**2) for maximum convection
+!  difcon        maximum mixing in interior convection (m2/s)
+!  nave          = 0/1 flag for horizontal average on avt, avmu, avmv
+!  navb          = 0/1 flag for constant or profile background avt
+&namkpp
+   ln_kpprimix  = .true.
+   difmiw       =  1.e-04
+   difsiw       =  0.1e-04
+   Riinfty      =  0.8
+   difri        =  0.0050
+   bvsqcon      = -0.01e-07
+   difcon       =  1.
+   navb         =  0
+   nave         =  1
+/
+!-----------------------------------------------------------------------
+!       namddm   double diffusive mixing parameterization
+!-----------------------------------------------------------------------
+!   avts    maximum avs for dd mixing 
+!   hsbfr   heat/salt buoyancy flux ratio
+&namddm
+      avts  = 1.e-4
+      hsbfr = 1.6
+/
+!-----------------------------------------------------------------------
+!       namlbc   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+!  shlat   lateral boundary condition on velocity
+!                   shlat = 0 , free slip
+!               0 < shlat < 2 , partial slip
+!                   shlat = 2 , no slip
+!               2 < shlat     , strong slip
+&namlbc
+   shlat  =      2.
+/
+!-----------------------------------------------------------------------
+!       nambfr   bottom friction
+!-----------------------------------------------------------------------
+!  nbotfr  type of bottom friction 
+!                  nbotfr = 0 , no slip 
+!                  nbotfr = 1 , linear friction
+!                  nbotfr = 2 , nonlinear friction
+!                  nbotfr = 3 , free slip
+!  bfri1   bottom drag coefficient (linear case)
+!  bfri2   bottom drag coefficient (non linear case)
+!  bfeb2   bottom turbulent kinetic energy  (m^2/s^2)
+&nambfr
+   nbotfr =       1
+   bfri1  =   4.e-4
+   bfri2  =   1.e-3
+   bfeb2  =  2.5e-3
+/
+!-----------------------------------------------------------------------
+!       nambbc   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+!  ngeo_flux  = 0 no geothermal heat flux
+!             = 1 constant geothermal heat flux
+!             = 2 variable geothermal heat flux (read in geothermal_heating.nc) 
+!                 ( C A U T I O N : flux in mW/m2 in the NetCDF file )
+!  ngeo_flux_const   Constant value of geothermal heat flux (W/m2) 
+&nambbc
+   ngeo_flux =  2
+   ngeo_flux_const = 86.4e-3
+/
+!-----------------------------------------------------------------------
+!       namqsr   penetrative solar radiation
+!-----------------------------------------------------------------------
+!  ln_traqsr : penetrative solar radiation (T) or not (F)     (Default=T)
+!  rabs       fraction of qsr associated with xsi1
+!  xsi1       first depth of extinction
+!  xsi2       second depth of extinction
+&namqsr
+   ln_traqsr = .true.
+   rabs     =   0.58
+   xsi1     =   0.35
+   xsi2     =   23.0
+/
+!-----------------------------------------------------------------------
+!       namtdp   tracer newtonian damping ('key_tradmp')
+!-----------------------------------------------------------------------
+!  ndmp    type of damping in temperature and salinity 
+!          (='latitude', damping poleward of 'ndmp' degrees and function 
+!             of the distance-to-coast. Red and Med Seas as ndmp=-1)
+!          (=-1 damping only in Med and Red Seas)
+!  ndmpf   =1 create a damping.coeff NetCDF file (the 3D damping array)
+!  nmldmp  type of damping in the mixed layer
+!          (=0 damping throughout the water column)
+!	   (=1 no damping in the mixed layer defined by avt >5cm2/s )
+!	   (=2 no damping in the mixed layer defined rho<rho(surf)+.01 )
+!  sdmp    surface time scale for internal damping (days)
+!  bdmp    bottom time scale for internal damping (days)
+!  hdmp    depth of transition between sdmp and bdmp (meters)
+&namtdp
+   ndmp   =   -1
+   ndmpf  =    1
+   nmldmp =    1
+   sdmp   =  50.
+   bdmp   = 360.
+   hdmp   = 800.
+/
+!-----------------------------------------------------------------------
+!       nameos   ocean physical parameters
+!-----------------------------------------------------------------------
+!  neos    type of equation of state and Brunt-Vaisala frequency
+!          = 0, UNESCO (formulation of Jackett and McDougall (1994)
+!                                         and of McDougall (1987) )
+!          = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+!          = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+!                               with rau0=1020 set in parcst routine
+!  ralpha  thermal expension coefficient (linear equation of state)
+!  rbeta   saline  expension coefficient (linear equation of state)
+&nameos
+   neos   =      0
+   ralpha =  2.e-4
+   rbeta  =  0.001
+/
+!-----------------------------------------------------------------------
+!       namsol   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+!  nsolv     elliptic solver (=1 preconditioned conjugate gradient: pcg)
+!                            (=2 successive-over-relaxation: sor)
+!                            (=3 FETI: fet, all require "key_feti" defined)
+!                            (=4 sor with extra outer halo)
+!  nsol_arp  absolute/relative (0/1) precision convergence test
+!  nmin      minimum of iterations for the SOR solver
+!  nmax      maximum of iterations for the SOR solver
+!  nmod      frequency of test for the SOR solver
+!  eps       absolute precision of the solver
+!  resmax    absolute precision for the SOR solver
+!  sor       optimal coefficient for SOR solver
+!  epsisl    absolute precision on stream function solver
+!  nmisl     maximum pcg iterations for island
+!  rnu       strength of the additional force used in free surface b.c.
+&namsol
+   nsolv     =      1
+   nsol_arp  =      0
+   nmin      =    300
+   nmax      =    800
+   nmod      =     10
+   eps       =  1.E-6
+   resmax    = 1.E-10
+   sor       =   1.92
+   epsisl    = 1.e-10
+   nmisl     =   4000
+   rnu       =     1.
+/
+!=======================================================================
+!   Diagnostics namelists
+!       namtrd    dynamics and/or tracer trends
+!       namgap    level mean model-data gap
+!       namznl    zonal mean heat & freshwater fluxes computation
+!       namspr    surface pressure in rigid-lid
+!=======================================================================
+!-----------------------------------------------------------------------
+!       namtrd    diagnostics on dynamics and/or tracer trends
+!                         ('key_trdyn' and/or 'key_trdtra')
+!                 or mixed-layer trends ('key_trdmld')
+!-----------------------------------------------------------------------
+!  ntrd              time step frequency dynamics and tracers trends
+!  nctls             control surface type in mixed-layer trends (0,1 or n<jpk)
+!  ln_trdmld_restart restart for ML diagnostics
+!  ucf               unit conversion factor (=1 -> /seconds | =86400. -> /day)
+!  ln_trdmld_instant flag to diagnose trends of instantantaneous or mean ML T/S
+&namtrd
+   ntrd  = 365
+   nctls =   0
+   ln_trdmld_restart = .false.
+   ucf   =  1.
+   ln_trdmld_instant = .false.
+/
+!-----------------------------------------------------------------------
+!       namgap    level mean model-data gap ('key_diagap')
+!-----------------------------------------------------------------------
+!  ngap    time-step frequency of model-data gap computation
+!  nprg    time-step frequency of gap print in model output
+&namgap
+   ngap =  15
+   nprg =  10
+/
+!-----------------------------------------------------------------------
+!       namznl    zonal mean heat & freshwater fluxes computation
+!                 (#ifdef "key_diaznl")
+!-----------------------------------------------------------------------
+!  nfznl   time-step frequency of zonal mean fluxes computation
+&namznl
+   nfznl =  15
+/
+!-----------------------------------------------------------------------
+!       namspr  surface pressure diagnostic
+!-----------------------------------------------------------------------
+!  nmaxp   maximum of iterations for the solver
+!  epsp    absolute precision of the solver
+!  niterp  number of iteration done by the solver
+&namspr
+   nmaxp   =   1000
+   epsp    =  1.e-3
+   niterp  =    400
+/
+!-----------------------------------------------------------------------
+!       namcpl    coupled ocean/atmosphere model  (#ifdef "key_coupled")
+!-----------------------------------------------------------------------
+!  nexco   coupling frequency in time steps
+!  cchan   coupling technique 'PIPE' or 'CLIM'
+&namcpl
+   nexco            =         24
+   cchan            =     'PIPE'
+   nmodcpl          =          2
+   cplmodnam        =   'opa.xx'
+   cploasis         =    'Oasis'
+   nfldo2c          =          2
+   nflxc2o          =          6
+   ntauc2o          =          4
+   cpl_writ(1)      = 'SOSSTSST'
+   cpl_f_writ(1)    =   'ocesst'
+   cpl_writ(2)      = 'SOICECOV'
+   cpl_f_writ(2)    =   'oceice'
+   cpl_readflx(1)   = 'SONSFLDO'
+   cpl_f_readflx(1) =   'oceflx'
+   cpl_readflx(2)   = 'SOSHFLDO'
+   cpl_f_readflx(2) =   'oceflx'
+   cpl_readflx(3)   = 'SOTOPRSU'
+   cpl_f_readflx(3) =   'oceflx'
+   cpl_readflx(4)   = 'SOTFSHSU'
+   cpl_f_readflx(4) =   'oceflx'
+   cpl_readflx(5)   = 'SORUNCOA'
+   cpl_f_readflx(5) =   'oceflx'
+   cpl_readflx(6)   = 'SORIVFLU'
+   cpl_f_readflx(6) =   'oceflx'
+   cpl_readtau(1)   = 'SOZOTAUX'
+   cpl_f_readtau(1) =   'ocetau'
+   cpl_readtau(2)   = 'SOZOTAU2'
+   cpl_f_readtau(2) =   'ocetau'
+   cpl_readtau(3)   = 'SOMETAUY'
+   cpl_f_readtau(3) =   'ocetau'
+   cpl_readtau(4)   = 'SOMETAU2'
+   cpl_f_readtau(4) =   'ocetau'
+/
+!-----------------------------------------------------------------------
+!       namobc    open boundaries parameters (#ifdef key_obc)
+!-----------------------------------------------------------------------
+!  nobc_dta   = 0 the obc data are equal to the initial state
+!             = 1 the obc data are read in 'obc   .dta' files
+!  rdpeob  time relaxation (days) for the east open boundary
+!  rdpwob  time relaxation (days) for the west open boundary
+!  rdpnob  time relaxation (days) for the north open boundary
+!  rdpsob  time relaxation (days) for the south open boundary
+!  zbsic1  barotropic stream function on isolated coastline 1
+!  zbsic2  barotropic stream function on isolated coastline 2
+!  zbsic3  barotropic stream function on isolated coastline 3
+!  ln_obc_clim  climatological obc data files (default T)
+!  ln_vol_cst   total volume conserved
+&namobc
+    nobc_dta =    0
+    rdpein   =    1.
+    rdpwin   =    1.
+    rdpnin   =   30.
+    rdpsin   =    1.
+    rdpeob   = 1500.
+    rdpwob   =   15.
+    rdpnob   =  150.
+    rdpsob   =   15.
+    zbsic1   =  140.e+6
+    zbsic2   =    1.e+6
+    zbsic3   =    0.
+    ln_obc_clim = .true.
+    ln_vol_cst  = .false.
+/
+!-----------------------------------------------------------------------
+!       namflo    float parameters (#ifdef key_float)
+!-----------------------------------------------------------------------
+!  ln_rstflo   boolean term for float restart (true or false)
+!  nwritefl   frequency of float output file 
+!  nstockfl   frequency of float restart file 
+!  ln_argo    Argo type floats (stay at the surface each 10 days)
+!  ln_flork4  = T trajectories computed with a 4th order Runge-Kutta
+!             = F  (default)   computed with Blanke' scheme
+&namflo
+    ln_rstflo = .false.
+    nwritefl  =      75
+    nstockfl  =    5475
+    ln_argo   = .false.
+    ln_flork4 = .false.
+/
+!-----------------------------------------------------------------------
+!       namcore  CORE
+!-----------------------------------------------------------------------
+!  
+!  In this version there are 8 files ( jpfile = 8)
+!  THE ORDER OF THE FILES MATTER:                      
+!  1 - precipitation total (rain+snow)  in kg/m2/s
+!  2,3 -  u10,v10 -> scalar wind at 10m in m/s -  ON 'T' GRID POINTS!!!
+!  4 - solar radiation (short wave)     in W/m2
+!  5 - thermal radiation (long wave)    in W/m2
+!  6 - specific humidity                in %
+!  7 - temperature at 10m               in degrees K
+!  8 - precipitation (snow only)        in kg/m2/s
+!  
+!  ln_2m         boolean (default F), used to indicate that Tair & humidity 
+!                are given at 2m. In this case, the default file names & 
+!                variables are t2.nc, t2, q2.nc, q2
+!  alpha_precip  real coefficient used as a multiplying  factor  for the precip
+!  clname        file names (256 char max for each)
+!  clvarname     name of variable in netcdf file (32 char max)
+!  freqh         frequency of fields in the file
+!                it is in hours (6 hourly, daily) if positive.
+!                if freqh = -12 the file contains 12 monthly data.
+&namcore
+   ln_2m        = .FALSE.
+   alpha_precip = 1.
+   clname    = 'precip.nc' 'u10.nc' 'q10.nc' 'v10.nc' 'radsw.nc' 'radlw.nc' 't10.nc' 'snow.nc'
+   clvarname =  'precip'    'u10'    'q10'    'v10'    'radsw'    'radlw'    't10'    'snow'
+   freqh     =    -12        24        24       24       24         24        24       -12
+/
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist_ice
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist_ice	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/EXP00/namelist_ice	(revision 4536)
@@ -0,0 +1,186 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! ICE namelist :  ice model option and parameter input
+! -------------
+!
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicerun   Share parameters for dynamics/advection/thermo
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  ln_limdyn   : switch for ice dynamics (true) or not (false)
+!  ln_limdmp   : restoring Ice thickness and Fraction leads flag
+!  acrit(1/2)  : minimum fraction for leads in the Northern (Southern) Hemisphere
+!  hnsdif      : computation of temperature in snow (=0.0) or not (=9999.0)
+!  hicdif      : computation of temperature in ice  (=0.0) or not (=9999.0)
+!
+&namicerun
+   ln_limdyn = .true. 
+   ln_limdmp = .FALSE. 
+   acrit     = 1.0e-06 , 1.0e-06
+   hsndif    = 0.0 
+   hicdif    = 0.0
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namiceini   parameters for ice initialisation
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  ln_limini : Ice initialization state flag
+!  ttest     : threshold water temperature for initial sea ice
+!  hninn     : initial snow thickness in the north
+!  hginn     : initial ice thickness in the north
+!  alinn     : initial leads area in the north
+!  hnins     : initial snow thickness in the south
+!  hgins     : initial ice thickness in the south
+!  alins     : initial leads area in the south
+!
+&namiceini
+   ln_limini = .FALSE. 
+   ttest = 2.0
+   hninn = 0.5
+   hginn = 3.0
+   alinn = 0.05
+   hnins = 0.1
+   hgins = 1.0
+   alins = 0.1
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicedia   parameters for ice diagnostics
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  fmtinf : format of the output values 
+!  nfrinf : number of variables written in one line
+!  ntmoy  : instantaneous values of ice evolution or averaging
+!  ninfo  : frequency of ouputs on file ice_evolu in case of averaging
+!
+&namicedia
+   fmtinf = '1PE13.5 '
+   nfrinf = 4
+   ntmoy  = 1
+   ninfo  = 1
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicedyn   parameters for ice dynamic
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  epsd   : tolerance parameter
+!  alpha  : coefficient for semi-implicit coriolis
+!  bound  : boundary conditions (=0.0 no-slip, =1.0 free-slip)
+!  dm     : diffusion constant for dynamics.
+!  nbiter : number of sub-time steps for relaxation
+!  nbitdr : maximum number of iterations for relaxation
+!  om     : relaxation constant 
+!  resl   : maximum value for the residual of relaxation 
+!  cw     : drag coefficient for oceanic stress
+!  angvg  : turning angle for oceanic stress
+!  pstar  : first bulk-rheology parameter
+!  c_rhg  : second bulk-rhelogy parameter
+!  etamn  : minimun value for viscosity
+!  creepl : creep limit
+!  ecc    : eccentricity of the elliptical yield curve
+!  ahi0   : horizontal eddy diffusivity coefficient for sea-ice (m2/s)
+!
+&namicedyn 
+   epsd   = 1.0e-20
+   alpha  = 0.5
+   dm     = 0.6e+03
+   nbiter = 1
+   nbitdr = 100
+   om     = 0.5
+   resl   = 5.0e-05
+   cw     = 5.0e-03
+   angvg  = 0.0
+   pstar  = 1.0e+04 
+   c_rhg  = 20.0
+   etamn  = 0.0e+07
+   creepl = 2.0e-08
+   ecc    = 2.0
+   ahi0   = 350.e0
+/
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicetrp   parameters for ice advection
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!  bound  : boundary conditions (=0.0 no-slip, =1.0 free-slip)
+&namicetrp 
+   bound  = 0.
+/
+
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namicethd   parameters for thermodynamic computation
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  hmelt       : maximum melting at the bottom
+!  hiccrit(1/2): ice thickness for lateral accretion in the Northern (Southern) Hemisphere
+!                caution 1.0, 1.0 best value to be used!!! (gilles G.)
+!  hicmin      : ice thickness corr. to max. energy stored in brine pocket
+!  hiclim      : minimum ice thickness
+!  amax        : maximum lead fraction
+!  swiqst      : energy stored in brine pocket (=1) or not (=0)	
+!  sbeta       : numerical caracteritic of the scheme for diffusion in ice
+!               Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)
+!  parlat      : percentage of energy used for lateral ablation
+!  hakspl      : slope of distr. for Hakkinen-Mellor's lateral melting
+!  hibspl      : slope of distribution for Hibler's lateral melting
+!  exld        : exponent for leads-closure rate
+!  hakdif      : coefficient for diffusions of ice and snow
+!  thth         : threshold thickness for comp. of eq. thermal conductivity
+!  hnzst       : thickness of the surf. layer in temp. computation
+!  parsub      : switch for snow sublimation or not
+!  alphs       : coefficient for snow density when snow ice formation
+! 
+&namicethd
+   hmelt   = -0.15
+   hiccrit = 0.3 , 0.3
+   hicmin  = 0.2
+   hiclim  = 0.05
+   amax    = 0.999 
+   swiqst  = 1.
+   sbeta   = 1.
+   parlat  = 0.0
+   hakspl  = 0.5
+   hibspl  = 0.5
+   exld    = 2.0
+   hakdif  = 1.0
+   thth    = 0.2
+   hnzst   = 0.1
+   parsub  = 1.0
+   alphs   = 1.0
+/
+!
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namiceout   parameters for outputs
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!   noumef      : number of fields
+!   field
+!        title  : title of the field
+!        name   : name of the field
+!        unit   : unit of the field
+!        nc     : switch for saving field ( = 1 ) or not ( = 0 )
+!        cmulti : multiplicative constant
+!        cadd   : additive constant
+!
+&namiceout
+   noumef   = 19
+   field_1  = 'Snow thickness                     ', 'isnowthi', 'm       ', 1, 1.0, 0.0
+   field_2  = 'Ice thickness                      ', 'iicethic', 'm       ', 1, 1.0, 0.0
+   field_3  = 'Ice produced                       ', 'iiceprod', 'm/kt    ', 1, 1.0, 0.0
+   field_4  = 'Ice concentration                  ', 'ileadfra', '%       ', 1, -1.0, 1.0
+   field_5  = 'Ice temperature                    ', 'iicetemp', 'C       ', 1, 1.0, -273.15
+   field_6  = 'Oceanic flux at the ice base       ', 'ioceflxb', 'w/m2    ', 1, 1.0, 0.0
+   field_7  = 'Ice velocity u                     ', 'iicevelu', 'm/s     ', 1, 1.0, 0.0
+   field_8  = 'Ice velocity v                     ', 'iicevelv', 'm/s     ', 1, 1.0, 0.0
+   field_9  = 'Sea surface temperature            ', 'isstempe', 'C       ', 1, 1.0, -273.15
+   field_10 = 'Sea surface salinity               ', 'isssalin', 'PSU     ', 1, 1.0, 0.0
+   field_11 = 'Total flux at ocean surface        ', 'iocetflx', 'w/m2    ', 1, 1.0, 0.0
+   field_12 = 'Solar flux at ocean surface        ', 'iocesflx', 'w/m2    ', 1, 1.0, 0.0
+   field_13 = 'Non-solar flux at ocean surface    ', 'iocwnsfl', 'w/m2    ', 1, 1.0, 0.0
+   field_14 = 'Salt flux at ocean surface         ', 'iocesafl', 'kg/m2/kt', 1, 1.0, 0.0
+   field_15 = 'Wind stress u                      ', 'iocestru', 'Pa      ', 1, 1.0, 0.0
+   field_16 = 'Wind stress v                      ', 'iocestrv', 'Pa      ', 1, 1.0, 0.0 
+   field_17 = 'Solar flux at ice/ocean surface    ', 'iicesflx', 'w/m2    ', 1, 1.0, 0.0
+   field_18 = 'Non-solar flux at ice/ocean surface', 'iicenflx', 'w/m2    ', 1, 1.0, 0.0
+   field_19 = 'Snow precipitation                 ', 'isnowpre', 'kg/day  ', 1, 1.0, 0.0
+/      
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make	(revision 4536)
@@ -0,0 +1,12243 @@
+# $Header$
+# some variables
+TMP = ../../../tmp
+#-Q- sx8mercure  # Compiler options NEMO (CEA SX6-NEC) 
+#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -C vopt -Wf"-P nh" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8mercure  F_F = $(F_O) -f3
+#-Q- sx8mercure  L_X = $(L_O) -ftrace
+#-Q- sx8brodie  # Compiler options NEMO (CEA SX6-NEC) 
+#-Q- sx8brodie  F_O = -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sx8brodie  F_F = $(F_O) -f3
+#-Q- sx8brodie  L_X = $(L_O)
+#-Q- sxdkrz  # Compiler options for NEMO (DKRZ SX6-NEC) 
+#-Q- sxdkrz  F_O = -ew -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- sxdkrz  F_F = $(F_O) -f3
+#-Q- sxdkrz  L_X = $(L_O) -ftrace
+#-Q- eshpux  # Compiler options for NEMO (Earth Simulator)
+#-Q- eshpux  # for super perfs!
+#-Q- eshpux  # F_O = $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- eshpux  # regular options!
+#-Q- eshpux  F_O = $(FTRACE) -Wf,-A idbl4 -C vopt -P stack -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- eshpux  F_F = $(F_O) -f3
+#-Q- eshpux  L_X = $(L_O)
+#-Q- linux  # Compiler options for NEMO (pgf version)
+#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- linux  F_F = $(F_O)-Mextend
+#-Q- linux  L_X = -r8 -O3
+#-Q- lxiv7  # Compiler options for NEMO (ifc version)
+#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- lxiv7  F_F = $(F_O) -extend_source 
+#-Q- lxiv7  L_X = -r8 -O3
+#-Q- lxiv8  # Compiler options for NEMO (ifort version)
+#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)
+#-Q- lxiv8  F_F = $(F_O) -extend_source 
+#-Q- lxiv8  L_X = -r8 -O3
+#-Q- g95  # Compiler options for NEMO (g95 version)
+#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- g95  F_F = $(F_O)-ffixed-form -ffixed-line-length-132
+#-Q- g95  L_X = -r8 -O3
+#-Q- aix    # Compiler options for NEMO (aix version)
+#-Q- aix    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- aix    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- aix   L_O = $(F_P) -q64 -O3
+#-Q- aix   L_X = $(L_O)
+#-Q- osxxlf    # Compiler options for NEMO (osxxlf version)
+#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- osxxlf    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)
+#-Q- osxxlf    L_X = -qrealsize=8 -O3
+PREF=
+#-Q- sx8mercure	PREF=i.
+#-Q- sx8brodie	PREF=i.
+#-Q- sxdkrz	PREF=i.
+#-Q- eshpux	PREF=i.
+
+# add suffix to P_P
+P_P := $(P_P:%=$(prefix)%)
+
+# Some tests to define variables related to Agrif compilation
+# Please do not change 
+ifneq (,$(findstring key_agrif,$(P_P)))
+AGRIF=use
+else
+AGRIF=notuse
+AGRIF_LIB=
+endif
+ifneq (,$(findstring key_mpp_mpi,$(P_P)))
+AGRIF_MPI=-DAGRIF_MPI
+else
+AGRIF_MPI=
+endif
+
+KEY_LIST = \
+     key_agrif \
+     key_agrif \
+     key_agrif \
+     key_agrif \
+     key_antarctic \
+     key_arctic \
+     key_cfg_1d \
+     key_cfg_1d \
+     key_coupled \
+     key_coupled \
+     key_coupled \
+     key_coupled \
+     key_cpl_albedo \
+     key_cpl_discharge \
+     key_cpl_ocevel \
+     key_cpl_rootexchg \
+     key_diaeiv \
+     key_diagap \
+     key_diahdy \
+     key_diahth \
+     key_diahth \
+     key_diainstant \
+     key_diainstant \
+     key_diaspr \
+     key_diaspr \
+     key_diaspr \
+     key_dimgout \
+     key_dimgout \
+     key_dtasal \
+     key_dtasal \
+     key_dtasss \
+     key_dtasst \
+     key_dtatem \
+     key_dtatem \
+     key_dynldf_c1d \
+     key_dynldf_c2d \
+     key_dynldf_c3d \
+     key_dynspg_exp \
+     key_dynspg_exp \
+     key_dynspg_exp \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_flt \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_rl \
+     key_dynspg_ts \
+     key_dynspg_ts \
+     key_dynspg_ts \
+     key_eel_r2 \
+     key_eel_r5 \
+     key_eel_r6 \
+     key_esopa \
+     key_esopa \
+     key_feti \
+     key_floats \
+     key_flx_bulk_daily \
+     key_flx_bulk_monthly \
+     key_flx_bulk_monthly \
+     key_flx_core \
+     key_flx_core \
+     key_flx_forced_daily \
+     key_gyre \
+     key_ice_lim \
+     key_ice_lim \
+     key_ice_lim \
+     key_ice_lim \
+     key_islands \
+     key_kppcustom \
+     key_kppcustom \
+     key_kpplktb \
+     key_ldfslp \
+     key_ldfslp \
+     key_lim_cp1 \
+     key_lim_cp1 \
+     key_lim_cp2 \
+     key_lim_cp3 \
+     key_lim_fdd \
+     key_lim_fdd \
+     key_lim_fdd \
+     key_mpp_dyndist \
+     key_mpp_dyndist \
+     key_mpp_mpi \
+     key_mpp_mpi \
+     key_mpp_omp \
+     key_mpp_shmem \
+     key_noslip_accurate \
+     key_oasis3 \
+     key_oasis3 \
+     key_oasis3 \
+     key_oasis4 \
+     key_obc \
+     key_obc \
+     key_obc \
+     key_orca_lev10 \
+     key_orca_r025 \
+     key_orca_r025 \
+     key_orca_r05 \
+     key_orca_r2 \
+     key_orca_r2 \
+     key_orca_r4 \
+     key_passivetrc \
+     key_passivetrc \
+     key_tau_daily \
+     key_tau_monthly \
+     key_trabbc \
+     key_trabbl_adv \
+     key_trabbl_adv \
+     key_trabbl_dif \
+     key_trabbl_dif \
+     key_tradmp \
+     key_tradmp \
+     key_tradmp \
+     key_traldf_ano \
+     key_traldf_c1d \
+     key_traldf_c2d \
+     key_traldf_c2d \
+     key_traldf_c3d \
+     key_traldf_eiv \
+     key_traldf_eiv \
+     key_traldf_eiv \
+     key_trc_pisces \
+     key_trddyn \
+     key_trddyn \
+     key_trddyn \
+     key_trdmld \
+     key_trdmld \
+     key_trdtra \
+     key_trdtra \
+     key_trdtra \
+     key_trdvor \
+     key_trdvor \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_loop \
+     key_vectopt_memory \
+     key_vvl \
+     key_zco \
+     key_zco \
+     key_zdfcst \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfddm \
+     key_zdfkpp \
+     key_zdfkpp \
+     key_zdfric \
+     key_zdftke \
+     key_zdftke 
+# .o file list in the library
+LIB_OBJ = \
+		$(MODEL_LIB)(lib_cray.o)\
+		$(MODEL_LIB)(lib_isml.o)\
+		$(MODEL_LIB)(lib_print.o)\
+		$(MODEL_LIB)(agrif_opa_interp.o)\
+		$(MODEL_LIB)(agrif_opa_sponge.o)\
+		$(MODEL_LIB)(agrif_opa_update.o)\
+		$(MODEL_LIB)(agrif_top_interp.o)\
+		$(MODEL_LIB)(agrif_top_update.o)\
+		$(MODEL_LIB)(agrif_user.o)\
+		$(MODEL_LIB)(albedo.o)\
+		$(MODEL_LIB)(blk_oce.o)\
+		$(MODEL_LIB)(bulk.o)\
+		$(MODEL_LIB)(cla_div.o)\
+		$(MODEL_LIB)(cla_dynspg.o)\
+		$(MODEL_LIB)(cla.o)\
+		$(MODEL_LIB)(closea.o)\
+		$(MODEL_LIB)(cpl.o)\
+		$(MODEL_LIB)(cpl_oasis3.o)\
+		$(MODEL_LIB)(cpl_oasis4.o)\
+		$(MODEL_LIB)(cpl_oce.o)\
+		$(MODEL_LIB)(ctlopn.o)\
+		$(MODEL_LIB)(daymod.o)\
+		$(MODEL_LIB)(diadimg.o)\
+		$(MODEL_LIB)(diafwb.o)\
+		$(MODEL_LIB)(diagap.o)\
+		$(MODEL_LIB)(diahdy.o)\
+		$(MODEL_LIB)(diahth.o)\
+		$(MODEL_LIB)(dianam.o)\
+		$(MODEL_LIB)(diaptr.o)\
+		$(MODEL_LIB)(diaspr.o)\
+		$(MODEL_LIB)(diawri1d.o)\
+		$(MODEL_LIB)(diawri.o)\
+		$(MODEL_LIB)(divcur.o)\
+		$(MODEL_LIB)(domain.o)\
+		$(MODEL_LIB)(domcfg.o)\
+		$(MODEL_LIB)(domhgr.o)\
+		$(MODEL_LIB)(dom_ice.o)\
+		$(MODEL_LIB)(dommsk.o)\
+		$(MODEL_LIB)(dom_oce.o)\
+		$(MODEL_LIB)(domstp.o)\
+		$(MODEL_LIB)(domvvl.o)\
+		$(MODEL_LIB)(domwri.o)\
+		$(MODEL_LIB)(domzgr.o)\
+		$(MODEL_LIB)(dtasal.o)\
+		$(MODEL_LIB)(dtasss.o)\
+		$(MODEL_LIB)(dtasst.o)\
+		$(MODEL_LIB)(dtatem.o)\
+		$(MODEL_LIB)(dynadv_cen2.o)\
+		$(MODEL_LIB)(dynadv.o)\
+		$(MODEL_LIB)(dynadv_ubs.o)\
+		$(MODEL_LIB)(dyncor1d.o)\
+		$(MODEL_LIB)(dynhpg.o)\
+		$(MODEL_LIB)(dynhpg_jki.o)\
+		$(MODEL_LIB)(dynkeg.o)\
+		$(MODEL_LIB)(dynldf_bilap.o)\
+		$(MODEL_LIB)(dynldf_bilapg.o)\
+		$(MODEL_LIB)(dynldf.o)\
+		$(MODEL_LIB)(dynldf_iso.o)\
+		$(MODEL_LIB)(dynldf_lap.o)\
+		$(MODEL_LIB)(dynnxt1d.o)\
+		$(MODEL_LIB)(dynnxt.o)\
+		$(MODEL_LIB)(dynspg_exp.o)\
+		$(MODEL_LIB)(dynspg_exp_jki.o)\
+		$(MODEL_LIB)(dynspg.o)\
+		$(MODEL_LIB)(dynspg_flt.o)\
+		$(MODEL_LIB)(dynspg_flt_jki.o)\
+		$(MODEL_LIB)(dynspg_oce.o)\
+		$(MODEL_LIB)(dynspg_rl.o)\
+		$(MODEL_LIB)(dynspg_ts.o)\
+		$(MODEL_LIB)(dynspg_ts_jki.o)\
+		$(MODEL_LIB)(dynvor.o)\
+		$(MODEL_LIB)(dynzad.o)\
+		$(MODEL_LIB)(dynzdf_exp.o)\
+		$(MODEL_LIB)(dynzdf.o)\
+		$(MODEL_LIB)(dynzdf_imp.o)\
+		$(MODEL_LIB)(dynzdf_imp_jki.o)\
+		$(MODEL_LIB)(eosbn2.o)\
+		$(MODEL_LIB)(flo4rk.o)\
+		$(MODEL_LIB)(floats.o)\
+		$(MODEL_LIB)(floblk.o)\
+		$(MODEL_LIB)(flodom.o)\
+		$(MODEL_LIB)(flo_oce.o)\
+		$(MODEL_LIB)(flowri.o)\
+		$(MODEL_LIB)(flxblk.o)\
+		$(MODEL_LIB)(flxfwb.o)\
+		$(MODEL_LIB)(flxmod.o)\
+		$(MODEL_LIB)(flx_oce.o)\
+		$(MODEL_LIB)(flxrnf.o)\
+		$(MODEL_LIB)(geo2ocean.o)\
+		$(MODEL_LIB)(ice.o)\
+		$(MODEL_LIB)(iceini.o)\
+		$(MODEL_LIB)(ice_oce.o)\
+		$(MODEL_LIB)(icestp1d.o)\
+		$(MODEL_LIB)(icestp.o)\
+		$(MODEL_LIB)(ini1d.o)\
+		$(MODEL_LIB)(initrc.o)\
+		$(MODEL_LIB)(in_out_manager.o)\
+		$(MODEL_LIB)(iom_def.o)\
+		$(MODEL_LIB)(iom.o)\
+		$(MODEL_LIB)(iom_ioipsl.o)\
+		$(MODEL_LIB)(iom_nf90.o)\
+		$(MODEL_LIB)(iom_rstdimg.o)\
+		$(MODEL_LIB)(istate.o)\
+		$(MODEL_LIB)(lbclnk.o)\
+		$(MODEL_LIB)(ldfdyn.o)\
+		$(MODEL_LIB)(ldfdyn_oce.o)\
+		$(MODEL_LIB)(ldfeiv.o)\
+		$(MODEL_LIB)(ldfslp.o)\
+		$(MODEL_LIB)(ldftra.o)\
+		$(MODEL_LIB)(ldftra_oce.o)\
+		$(MODEL_LIB)(lib_feti.o)\
+		$(MODEL_LIB)(lib_mpp.o)\
+		$(MODEL_LIB)(limadv.o)\
+		$(MODEL_LIB)(limdia.o)\
+		$(MODEL_LIB)(limdmp.o)\
+		$(MODEL_LIB)(limdyn.o)\
+		$(MODEL_LIB)(limflx.o)\
+		$(MODEL_LIB)(limhdf.o)\
+		$(MODEL_LIB)(limistate.o)\
+		$(MODEL_LIB)(limmsh.o)\
+		$(MODEL_LIB)(limrhg.o)\
+		$(MODEL_LIB)(limrst.o)\
+		$(MODEL_LIB)(limtab.o)\
+		$(MODEL_LIB)(limthd.o)\
+		$(MODEL_LIB)(limthd_lac.o)\
+		$(MODEL_LIB)(limthd_zdf.o)\
+		$(MODEL_LIB)(limtrp.o)\
+		$(MODEL_LIB)(limwri.o)\
+		$(MODEL_LIB)(mppini.o)\
+		$(MODEL_LIB)(oasis4_date.o)\
+		$(MODEL_LIB)(obccli.o)\
+		$(MODEL_LIB)(obcdom.o)\
+		$(MODEL_LIB)(obcdta.o)\
+		$(MODEL_LIB)(obcdyn_bt.o)\
+		$(MODEL_LIB)(obcdyn.o)\
+		$(MODEL_LIB)(obcfla.o)\
+		$(MODEL_LIB)(obcini.o)\
+		$(MODEL_LIB)(obc_oce.o)\
+		$(MODEL_LIB)(obc_par.o)\
+		$(MODEL_LIB)(obcrad.o)\
+		$(MODEL_LIB)(obcrst.o)\
+		$(MODEL_LIB)(obcspg.o)\
+		$(MODEL_LIB)(obctra.o)\
+		$(MODEL_LIB)(obcvol.o)\
+		$(MODEL_LIB)(oce.o)\
+		$(MODEL_LIB)(ocesbc.o)\
+		$(MODEL_LIB)(ocfzpt.o)\
+		$(MODEL_LIB)(opa.o)\
+		$(MODEL_LIB)(par_ice.o)\
+		$(MODEL_LIB)(par_kind.o)\
+		$(MODEL_LIB)(par_oce.o)\
+		$(MODEL_LIB)(phycst.o)\
+		$(MODEL_LIB)(prtctl.o)\
+		$(MODEL_LIB)(restart.o)\
+		$(MODEL_LIB)(sms.o)\
+		$(MODEL_LIB)(solfet.o)\
+		$(MODEL_LIB)(solisl.o)\
+		$(MODEL_LIB)(solmat.o)\
+		$(MODEL_LIB)(sol_oce.o)\
+		$(MODEL_LIB)(solpcg.o)\
+		$(MODEL_LIB)(solsor_e.o)\
+		$(MODEL_LIB)(solsor.o)\
+		$(MODEL_LIB)(solver.o)\
+		$(MODEL_LIB)(step1d.o)\
+		$(MODEL_LIB)(step.o)\
+		$(MODEL_LIB)(stpctl.o)\
+		$(MODEL_LIB)(taumod.o)\
+		$(MODEL_LIB)(thd_ice.o)\
+		$(MODEL_LIB)(traadv_cen2.o)\
+		$(MODEL_LIB)(traadv_cen2_jki.o)\
+		$(MODEL_LIB)(traadv_eiv.o)\
+		$(MODEL_LIB)(traadv.o)\
+		$(MODEL_LIB)(traadv_muscl2.o)\
+		$(MODEL_LIB)(traadv_muscl.o)\
+		$(MODEL_LIB)(traadv_qck.o)\
+		$(MODEL_LIB)(traadv_tvd.o)\
+		$(MODEL_LIB)(traadv_ubs.o)\
+		$(MODEL_LIB)(trabbc.o)\
+		$(MODEL_LIB)(trabbl.o)\
+		$(MODEL_LIB)(tradmp.o)\
+		$(MODEL_LIB)(traldf_bilap.o)\
+		$(MODEL_LIB)(traldf_bilapg.o)\
+		$(MODEL_LIB)(traldf.o)\
+		$(MODEL_LIB)(traldf_iso.o)\
+		$(MODEL_LIB)(traldf_lap.o)\
+		$(MODEL_LIB)(tranpc.o)\
+		$(MODEL_LIB)(tranxt.o)\
+		$(MODEL_LIB)(traqsr.o)\
+		$(MODEL_LIB)(trasbc.o)\
+		$(MODEL_LIB)(trazdf_exp.o)\
+		$(MODEL_LIB)(trazdf.o)\
+		$(MODEL_LIB)(trazdf_imp.o)\
+		$(MODEL_LIB)(trazdf_imp_jki.o)\
+		$(MODEL_LIB)(trc_oce.o)\
+		$(MODEL_LIB)(trcstp.o)\
+		$(MODEL_LIB)(trdicp.o)\
+		$(MODEL_LIB)(trdicp_oce.o)\
+		$(MODEL_LIB)(trdmld.o)\
+		$(MODEL_LIB)(trdmld_oce.o)\
+		$(MODEL_LIB)(trdmld_rst.o)\
+		$(MODEL_LIB)(trdmod.o)\
+		$(MODEL_LIB)(trdmod_oce.o)\
+		$(MODEL_LIB)(trdvor.o)\
+		$(MODEL_LIB)(trdvor_oce.o)\
+		$(MODEL_LIB)(wzvmod.o)\
+		$(MODEL_LIB)(zdfbfr.o)\
+		$(MODEL_LIB)(zdfddm.o)\
+		$(MODEL_LIB)(zdfevd.o)\
+		$(MODEL_LIB)(zdfini.o)\
+		$(MODEL_LIB)(zdfkpp.o)\
+		$(MODEL_LIB)(zdfmxl.o)\
+		$(MODEL_LIB)(zdf_oce.o)\
+		$(MODEL_LIB)(zdfric.o)\
+		$(MODEL_LIB)(zdftke.o)\
+		$(MODEL_LIB)(zdftke_jki.o)\
+		$(MODEL_LIB)(zpshde.o)
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all: 		diroce $(EXEC_BIN)
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPA model is OK
+# Cleaning objects, libraries and executables
+clean:
+ifeq ($(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		$(RM) model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB) $(EXEC_BIN)
+		@echo OPA model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/oce ] ; then mkdir ../../../lib/oce ; fi
+
+$(EXEC_BIN) :	libioipsl firstagrif mpiagrif key keyverif src_file_list libagrif $(MODEL_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) agrif2model.o model.o
+ifeq ($(AGRIF),use)
+		$(F_L) $(L_X) -o $(EXEC_BIN) model.o agrif2model.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(AGRIF_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+else
+		$(F_L) $(L_X) -o $(EXEC_BIN) model.o $(SXMODEL_LIB) $(OASISMPI2_LIB) $(IOIPSL_LIB) $(NCDF_LIB) $(LIBMPI) $(LIBMP)
+endif
+
+# Agrif library and conv
+libagrif :
+ifeq ($(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../AGRIF ; $(M_K) -f Makefile P_P="$(AGRIF_MPI)" )
+	@cp -rf ../../AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../AGRIF/conv OPAFILES/. 
+	@cp -rf ../../AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq ($(AGRIF),use)
+	@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+	@$(F_C) \
+#-Q- aix		-qsuffix=f=F90 \
+#-Q- osxxlf		-qsuffix=f=F90 \
+	$(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+	   OPAFILES/$*.F90 || { mv $(PREF).L $(TMP) ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux			@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../IOIPSL/src ; $(M_K) -f Makefile )
+
+# Main program
+model.o :	model.f90
+		@$(F_C) $(F_O) -c model.f90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : $(MODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : $(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : $(SXMODEL_LIB)
+
+# library dependancies
+$(MODEL_LIB):	$(LIB_OBJ)
+		@echo
+		@echo La bibliotheque est a jour
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+.f90.a :           
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.f90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F90 files
+.F90.a :  
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F90 > OPAFILES/$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- lxiv8		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F90 > OPAFILES/AGRIF_MODELFILES/$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F90 OPAFILES/$*.F90
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		OPAFILES/$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.F90 || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the .F files
+.F.a :           
+ifeq ($(AGRIF),use) 
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC $*.F > OPAFILES/$*.F 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \
+#-Q- linux		-SubloopScalar \
+#-Q- lxiv8		-SubloopScalar \
+#-Q- g95			-SubloopScalar \
+#-Q- f95			-SubloopScalar \
+#-Q- osf1			-SubloopScalar \
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile $*.F)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(P_C) $(P_O) -IOPAFILES/AGRIF_INC OPAFILES/$*.F > OPAFILES/AGRIF_MODELFILES/$*.F
+		-@mv -f OPAFILES/AGRIF_MODELFILES/$*.F OPAFILES/$*.F
+		@$(F_C) $(P_P) $(F_F) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		OPAFILES/$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; } 
+else
+		@$(F_C) $(P_P) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.F || { if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) $*.[of]
+		@if [ -f $*.mod ] ; then mv $*.mod $(MODDIR)/oce ; fi
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $(PREF)$*.L $(TMP) ; fi
+
+# rules for the library from the .f files 
+.f.a : 		
+		@$(F_C) $(F_O) \
+#-Q- fjvpp		-Z $*.L \
+#-Q- sx8mercure		-R2 \
+#-Q- sx8brodie		-R2 \
+#-Q- sxdkrz		-R2 \
+#-Q- eshpux		-R2 \
+#-Q- aix		-qsource \
+		$*.f|| { if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+#-Q- eshpux		@$(A_X) $(SXMODEL_LIB) $*.o  > /dev/null
+		@$(A_C) $(MODEL_LIB) $*.o  > /dev/null
+		@$(RM) -f $*.o
+#-Q- aix		@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- linux	@mv $(PREF)$*.lst $(PREF)$*.L
+#-Q- osxxlf		@mv $(PREF)$*.lst $(PREF)$*.L
+		@if [ -f $(PREF)$*.L ] ; then mv $*.L $(TMP) ; fi
+
+$(MODEL_LIB)(agrif_opa_interp.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	agrif_opa_interp.F90
+$(MODEL_LIB)(agrif_opa_sponge.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	agrif_opa_sponge.F90
+$(MODEL_LIB)(agrif_opa_update.o) :	\
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cla_div.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_oce.F90 \
+	wzvmod.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	agrif_opa_update.F90
+$(MODEL_LIB)(agrif_top_interp.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	oce.F90 \
+	par_oce.F90 \
+	sms.F90 \
+	sol_oce.F90 \
+	trcstp.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	agrif_top_interp.F90
+$(MODEL_LIB)(agrif_top_update.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	oce.F90 \
+	par_oce.F90 \
+	sms.F90 \
+	trcstp.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	agrif_top_update.F90
+$(MODEL_LIB)(agrif_user.o) :	\
+	blk_oce.F90 \
+	cla_div.F90 \
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	divcur.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	iceini.F90 \
+	ini1d.F90 \
+	initrc.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(initrc.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(step1d.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	mppini.F90 \
+	obcini.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sms.F90 \
+	sol_oce.F90 \
+	step1d.F90 \
+	step.F90 \
+	trcstp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	wzvmod.F90 \
+	zdfini.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	agrif_opa_interp.F90 \
+	agrif_opa_sponge.F90 \
+	agrif_opa_update.F90 \
+	agrif_top_interp.F90 \
+	agrif_top_update.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(agrif_top_interp.o) \
+	$(MODEL_LIB)(agrif_top_update.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(opa.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	opa.F90 \
+	par_oce.F90 \
+	sms.F90 \
+	sol_oce.F90 \
+	tradmp.F90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	agrif_user.F90
+$(MODEL_LIB)(albedo.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	albedo.F90
+$(MODEL_LIB)(blk_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	blk_oce.F90
+$(MODEL_LIB)(bulk.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	blk_oce.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flx_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	KEY_CPP \
+	bulk.F90
+$(MODEL_LIB)(cla_div.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	cla_div.F90
+$(MODEL_LIB)(cla_dynspg.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla_dynspg.F90
+$(MODEL_LIB)(cla.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	cla.F90
+$(MODEL_LIB)(closea.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	closea.F90
+$(MODEL_LIB)(cpl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	cpl.F90
+$(MODEL_LIB)(cpl_oasis3.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	cpl_oasis3.F90
+$(MODEL_LIB)(cpl_oasis4.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oasis4_date.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	cpl_oasis4.F90
+$(MODEL_LIB)(cpl_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	cpl_oce.F90
+$(MODEL_LIB)(ctlopn.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	ctlopn.F90
+$(MODEL_LIB)(daymod.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90
+$(MODEL_LIB)(diadimg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diadimg.F90
+$(MODEL_LIB)(diafwb.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	blk_oce.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	diafwb.F90
+$(MODEL_LIB)(diagap.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diagap.F90
+$(MODEL_LIB)(diahdy.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahdy.F90
+$(MODEL_LIB)(diahth.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	diahth.F90
+$(MODEL_LIB)(dianam.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	dianam.F90
+$(MODEL_LIB)(diaptr.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diaptr.F90
+$(MODEL_LIB)(diaspr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	KEY_CPP \
+	diaspr.F90
+$(MODEL_LIB)(diawri1d.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trazdf_exp.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri1d.F90
+$(MODEL_LIB)(diawri.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dtasst.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	diawri_dimg.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	diawri.F90
+$(MODEL_LIB)(divcur.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	divcur.F90
+$(MODEL_LIB)(domain.o) :	\
+	blk_oce.F90 \
+	closea.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solisl.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solisl.F90 \
+	blk_oce.F90 \
+	closea.F90 \
+	daymod.F90 \
+	domhgr.F90 \
+	dommsk.F90 \
+	dom_oce.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	domain.F90
+$(MODEL_LIB)(domcfg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solisl.o) \
+	phycst.F90 \
+	solisl.F90 \
+	domcfg.F90
+$(MODEL_LIB)(domhgr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	domhgr.F90
+$(MODEL_LIB)(dom_ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	dom_ice.F90
+$(MODEL_LIB)(dommsk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solisl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dommsk.F90
+$(MODEL_LIB)(dom_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dom_oce.F90
+$(MODEL_LIB)(domstp.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	domstp.F90
+$(MODEL_LIB)(domvvl.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domvvl.F90
+$(MODEL_LIB)(domwri.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	domwri.F90
+$(MODEL_LIB)(domzgr.o) :	\
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	closea.F90 \
+	dom_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	oce.F90 \
+	solisl.F90 \
+	domzgr_substitute.h90 \
+	domzgr_zps.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	domzgr.F90
+$(MODEL_LIB)(dtasal.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtasal.F90
+$(MODEL_LIB)(dtasss.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	KEY_CPP \
+	dtasss.F90
+$(MODEL_LIB)(dtasst.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	KEY_CPP \
+	dtasst.F90
+$(MODEL_LIB)(dtatem.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	dtatem.F90
+$(MODEL_LIB)(dynadv_cen2.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_cen2.F90
+$(MODEL_LIB)(dynadv.o) :	\
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv.F90
+$(MODEL_LIB)(dynadv_ubs.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynadv_ubs.F90
+$(MODEL_LIB)(dyncor1d.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dyncor1d.F90
+$(MODEL_LIB)(dynhpg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynhpg_jki.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynhpg_jki.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg.F90
+$(MODEL_LIB)(dynhpg_jki.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynhpg_jki.F90
+$(MODEL_LIB)(dynkeg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynkeg.F90
+$(MODEL_LIB)(dynldf_bilap.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilap.F90
+$(MODEL_LIB)(dynldf_bilapg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	KEY_CPP \
+	dynldf_bilapg.F90
+$(MODEL_LIB)(dynldf.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf.F90
+$(MODEL_LIB)(dynldf_iso.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_iso.F90
+$(MODEL_LIB)(dynldf_lap.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynldf_lap.F90
+$(MODEL_LIB)(dynnxt1d.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	dynnxt1d.F90
+$(MODEL_LIB)(dynnxt.o) :	\
+	cla_div.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	wzvmod.F90 \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obcdyn_bt.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynnxt.F90
+$(MODEL_LIB)(dynspg_exp.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_exp.F90
+$(MODEL_LIB)(dynspg_exp_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynspg_exp.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_exp_jki.F90
+$(MODEL_LIB)(dynspg.o) :	\
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_exp.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg.F90
+$(MODEL_LIB)(dynspg_flt.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynspg_flt.F90
+$(MODEL_LIB)(dynspg_flt_jki.o) :	\
+	agrif_opa_interp.F90 \
+	blk_oce.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	agrif_opa_interp.F90 \
+	cla_dynspg.F90 \
+	dom_oce.F90 \
+	dynspg_flt.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	dynspg_flt_jki.F90
+$(MODEL_LIB)(dynspg_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	dynspg_oce.F90
+$(MODEL_LIB)(dynspg_rl.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_rl.F90
+$(MODEL_LIB)(dynspg_ts.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_ts.F90
+$(MODEL_LIB)(dynspg_ts_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	obcdta.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynspg_ts_jki.F90
+$(MODEL_LIB)(dynvor.o) :	\
+	dom_oce.F90 \
+	dynadv_cen2.F90 \
+	dynadv_ubs.F90 \
+	dynkeg.F90 \
+	dynzad.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynadv.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynvor.F90
+$(MODEL_LIB)(dynzad.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzad.F90
+$(MODEL_LIB)(dynzdf_exp.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_exp.F90
+$(MODEL_LIB)(dynzdf.o) :	\
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	dynzdf.F90
+$(MODEL_LIB)(dynzdf_imp.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp.F90
+$(MODEL_LIB)(dynzdf_imp_jki.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	dynzdf_imp_jki.F90
+$(MODEL_LIB)(eosbn2.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	eosbn2.F90
+$(MODEL_LIB)(flo4rk.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	KEY_CPP \
+	flo4rk.F90
+$(MODEL_LIB)(floats.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	flo4rk.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flo_oce.F90 \
+	flowri.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	floats.F90
+$(MODEL_LIB)(floblk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	floblk.F90
+$(MODEL_LIB)(flodom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flodom.F90
+$(MODEL_LIB)(flo_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	flo_oce.F90
+$(MODEL_LIB)(flowri.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flo_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	flowri.F90
+$(MODEL_LIB)(flxblk.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	flxblk.F90
+$(MODEL_LIB)(flxfwb.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flxblk.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	flxfwb.F90
+$(MODEL_LIB)(flxmod.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oasis4_date.F90 \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	blk_oce.F90 \
+	bulk.F90 \
+	dtatem.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(bulk.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	taumod.F90 \
+	domzgr_substitute.h90 \
+	flx_bulk_daily.h90 \
+	flx_bulk_monthly.h90 \
+	flx_core.h90 \
+	flx_forced_daily.h90 \
+	flx_oasis_ice.h90 \
+	KEY_CPP \
+	flxmod.F90
+$(MODEL_LIB)(flx_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	flx_oce.F90
+$(MODEL_LIB)(flxrnf.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	flxrnf_ORCA_R05.h90 \
+	KEY_CPP \
+	flxrnf.F90
+$(MODEL_LIB)(geo2ocean.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	geo2ocean.F90
+$(MODEL_LIB)(ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	KEY_CPP \
+	ice.F90
+$(MODEL_LIB)(iceini.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	ocfzpt.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	iceini.F90
+$(MODEL_LIB)(ice_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	blk_oce.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ice_oce.F90
+$(MODEL_LIB)(icestp1d.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	thd_ice.F90 \
+	tradmp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	icestp1d.F90
+$(MODEL_LIB)(icestp.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limadv.F90 \
+	limhdf.F90 \
+	limistate.F90 \
+	limrhg.F90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limadv.o) \
+	$(MODEL_LIB)(limhdf.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limrhg.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	thd_ice.F90 \
+	tradmp.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limdia.F90 \
+	limdmp.F90 \
+	limdyn.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limtrp.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limdia.o) \
+	$(MODEL_LIB)(limdmp.o) \
+	$(MODEL_LIB)(limdyn.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limtrp.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	icestp.F90
+$(MODEL_LIB)(ini1d.o) :	\
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	ini1d.F90
+$(MODEL_LIB)(initrc.o) :	\
+	initrc.F90
+$(MODEL_LIB)(in_out_manager.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90
+$(MODEL_LIB)(iom_def.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	iom_def.F90
+$(MODEL_LIB)(iom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	KEY_CPP \
+	iom.F90
+$(MODEL_LIB)(iom_ioipsl.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(IOIPSL_LIB) \
+	iom_ioipsl.F90
+$(MODEL_LIB)(iom_nf90.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	iom_nf90.F90
+$(MODEL_LIB)(iom_rstdimg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	iom_rstdimg.F90
+$(MODEL_LIB)(istate.o) :	\
+	agrif_opa_interp.F90 \
+	blk_oce.F90 \
+	cla_dynspg.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	dynvor.F90 \
+	eosbn2.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_dynspg.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obcfla.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor_e.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(solver.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obcdta.F90 \
+	obcdyn.F90 \
+	obcfla.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor_e.F90 \
+	solsor.F90 \
+	solver.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	dynspg_exp.F90 \
+	dynspg.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	eosbn2.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	phycst.F90 \
+	restart.F90 \
+	solisl.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	istate.F90
+$(MODEL_LIB)(lbclnk.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	KEY_CPP \
+	lbclnk.F90
+$(MODEL_LIB)(ldfdyn.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	domzgr_substitute.h90 \
+	ldfdyn_antarctic.h90 \
+	ldfdyn_arctic.h90 \
+	ldfdyn_c1d.h90 \
+	ldfdyn_c2d.h90 \
+	ldfdyn_c3d.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldfdyn.F90
+$(MODEL_LIB)(ldfdyn_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldfdyn_oce.F90
+$(MODEL_LIB)(ldfeiv.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfeiv.F90
+$(MODEL_LIB)(ldfslp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ldfslp.F90
+$(MODEL_LIB)(ldftra.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	ldftra_c1d.h90 \
+	ldftra_c2d.h90 \
+	ldftra_c3d.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	ldftra.F90
+$(MODEL_LIB)(ldftra_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	ldftra_oce.F90
+$(MODEL_LIB)(lib_cray.o) :	\
+	lib_cray.f90
+$(MODEL_LIB)(lib_feti.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(lib_mpp.o) \
+	KEY_CPP \
+	lib_feti.F90
+$(MODEL_LIB)(lib_isml.o) :	\
+	lib_isml.f90
+$(MODEL_LIB)(lib_mpp.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	lib_mpp.F90
+$(MODEL_LIB)(lib_print.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	lib_print.f90
+$(MODEL_LIB)(limadv.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	prtctl.F90 \
+	KEY_CPP \
+	limadv.F90
+$(MODEL_LIB)(limdia.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(phycst.o) \
+	par_ice.F90 \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limdia.F90
+$(MODEL_LIB)(limdmp.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	phycst.F90 \
+	tradmp.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limdmp.F90
+$(MODEL_LIB)(limdyn.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	limistate.F90 \
+	limrhg.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limrhg.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	limdyn.F90
+$(MODEL_LIB)(limflx.o) :	\
+	albedo.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	albedo.F90 \
+	flxblk.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(albedo.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	ocfzpt.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limflx.F90
+$(MODEL_LIB)(limhdf.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	prtctl.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limhdf.F90
+$(MODEL_LIB)(limistate.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	limistate.F90
+$(MODEL_LIB)(limmsh.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	KEY_CPP \
+	limmsh.F90
+$(MODEL_LIB)(limrhg.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_ice.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	KEY_CPP \
+	limrhg.F90
+$(MODEL_LIB)(limrst.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	KEY_CPP \
+	limrst.F90
+$(MODEL_LIB)(limtab.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	KEY_CPP \
+	limtab.F90
+$(MODEL_LIB)(limthd.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	limtab.F90 \
+	limthd_lac.F90 \
+	limthd_zdf.F90 \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limtab.o) \
+	$(MODEL_LIB)(limthd_lac.o) \
+	$(MODEL_LIB)(limthd_zdf.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	phycst.F90 \
+	prtctl.F90 \
+	thd_ice.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limthd.F90
+$(MODEL_LIB)(limthd_lac.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	KEY_CPP \
+	limthd_lac.F90
+$(MODEL_LIB)(limthd_zdf.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(thd_ice.o) \
+	par_oce.F90 \
+	phycst.F90 \
+	thd_ice.F90 \
+	KEY_CPP \
+	limthd_zdf.F90
+$(MODEL_LIB)(limtrp.o) :	\
+	blk_oce.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	ice.F90 \
+	iceini.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	limadv.F90 \
+	limhdf.F90 \
+	limistate.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(limadv.o) \
+	$(MODEL_LIB)(limhdf.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	limtrp.F90
+$(MODEL_LIB)(limwri.o) :	\
+	blk_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	diadimg.F90 \
+	$(MODEL_LIB)(diadimg.o) \
+	limwri_dimg.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	limwri.F90
+$(MODEL_LIB)(model.o) :	\
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	iceini.F90 \
+	ini1d.F90 \
+	initrc.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(initrc.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(step1d.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	mppini.F90 \
+	obcini.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	step1d.F90 \
+	step.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	$(MODEL_LIB)(opa.o) \
+	opa.F90 \
+	model.f90
+$(MODEL_LIB)(mppini.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	sol_oce.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(iom.o) \
+	domzgr_substitute.h90 \
+	mppini_2.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	mppini.F90
+$(MODEL_LIB)(oasis4_date.o) :	\
+	KEY_CPP \
+	oasis4_date.F90
+$(MODEL_LIB)(obccli.o) :	\
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	obccli.F90
+$(MODEL_LIB)(obcdom.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdom.F90
+$(MODEL_LIB)(obcdta.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcdta.F90
+$(MODEL_LIB)(obcdyn_bt.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn_bt.F90
+$(MODEL_LIB)(obcdyn.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcdyn.F90
+$(MODEL_LIB)(obcfla.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obccli.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obcdta.F90 \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcfla.F90
+$(MODEL_LIB)(obcini.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obcdom.F90 \
+	obc_oce.F90 \
+	obcrst.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcini.F90
+$(MODEL_LIB)(obc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	par_oce.F90 \
+	KEY_CPP \
+	obc_oce.F90
+$(MODEL_LIB)(obc_par.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	obc_par_EEL_R5.h90 \
+	KEY_CPP \
+	obc_par.F90
+$(MODEL_LIB)(obcrad.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcrad.F90
+$(MODEL_LIB)(obcrst.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	KEY_CPP \
+	obcrst.F90
+$(MODEL_LIB)(obcspg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcspg.F90
+$(MODEL_LIB)(obctra.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obctra.F90
+$(MODEL_LIB)(obcvol.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	obc_vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	obcvol.F90
+$(MODEL_LIB)(oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	oce.F90
+$(MODEL_LIB)(ocesbc.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	flx_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	ocesbc.F90
+$(MODEL_LIB)(ocfzpt.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	dom_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	ocfzpt.F90
+$(MODEL_LIB)(opa.o) :	\
+	agrif_opa_sponge.F90 \
+	blk_oce.F90 \
+	cla_div.F90 \
+	cla.F90 \
+	closea.F90 \
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri1d.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	domhgr.F90 \
+	dom_ice.F90 \
+	dommsk.F90 \
+	dom_oce.F90 \
+	domstp.F90 \
+	domvvl.F90 \
+	domwri.F90 \
+	domzgr.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dyncor1d.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt1d.F90 \
+	dynnxt.F90 \
+	dynspg_exp.F90 \
+	dynspg.F90 \
+	dynspg_flt.F90 \
+	dynspg_oce.F90 \
+	dynspg_ts.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	floats.F90 \
+	flo_oce.F90 \
+	flxblk.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	icestp1d.F90 \
+	icestp.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limistate.F90 \
+	limmsh.F90 \
+	limrst.F90 \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri1d.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(domhgr.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dommsk.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domstp.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(domwri.o) \
+	$(MODEL_LIB)(domzgr.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt1d.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp1d.o) \
+	$(MODEL_LIB)(icestp.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limistate.o) \
+	$(MODEL_LIB)(limmsh.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(obcdom.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke_jki.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oasis4_date.F90 \
+	obcdom.F90 \
+	obcdta.F90 \
+	obc_oce.F90 \
+	obc_par.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	wzvmod.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdftke_jki.F90 \
+	zpshde.F90 \
+	cpl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diaptr.F90 \
+	domain.F90 \
+	domcfg.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	iceini.F90 \
+	ini1d.F90 \
+	initrc.F90 \
+	in_out_manager.F90 \
+	istate.F90 \
+	ldfdyn.F90 \
+	ldftra.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(domain.o) \
+	$(MODEL_LIB)(domcfg.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(iceini.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(initrc.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(istate.o) \
+	$(MODEL_LIB)(ldfdyn.o) \
+	$(MODEL_LIB)(ldftra.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(mppini.o) \
+	$(MODEL_LIB)(obcini.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(step1d.o) \
+	$(MODEL_LIB)(step.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfini.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	mppini.F90 \
+	obcini.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	ocfzpt.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	step1d.F90 \
+	step.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfini.F90 \
+	zpshde.F90 \
+	KEY_CPP \
+	opa.F90
+$(MODEL_LIB)(par_ice.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	par_ice.F90
+$(MODEL_LIB)(par_kind.o) :	\
+	par_kind.F90
+$(MODEL_LIB)(par_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	par_EEL_R2.h90 \
+	par_EEL_R5.h90 \
+	par_EEL_R6.h90 \
+	par_GYRE.h90 \
+	par_ORCA_R025.h90 \
+	par_ORCA_R05.h90 \
+	par_ORCA_R2.h90 \
+	par_ORCA_R4.h90 \
+	KEY_CPP \
+	par_oce.F90
+$(MODEL_LIB)(phycst.o) :	\
+	lib_print.f90 \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	phycst.F90
+$(MODEL_LIB)(prtctl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	prtctl.F90
+$(MODEL_LIB)(restart.o) :	\
+	blk_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmld_oce.F90 \
+	zpshde.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	restart.F90
+$(MODEL_LIB)(sms.o) :	\
+	sms.F90
+$(MODEL_LIB)(solfet.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solfet.F90
+$(MODEL_LIB)(solisl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	solisl.F90
+$(MODEL_LIB)(solmat.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	phycst.F90 \
+	sol_oce.F90 \
+	KEY_CPP \
+	solmat.F90
+$(MODEL_LIB)(sol_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	sol_oce.F90
+$(MODEL_LIB)(solpcg.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	solpcg.F90
+$(MODEL_LIB)(solsor_e.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	solsor_e.F90
+$(MODEL_LIB)(solsor.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	solsor.F90
+$(MODEL_LIB)(solver.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_feti.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_feti.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	obc_oce.F90 \
+	obc_par.F90 \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(solmat.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	solisl.F90 \
+	solmat.F90 \
+	sol_oce.F90 \
+	zdf_oce.F90 \
+	KEY_CPP \
+	solver.F90
+$(MODEL_LIB)(step1d.o) :	\
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	eosbn2.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obctra.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	traqsr.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trc_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	diawri1d.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dyncor1d.F90 \
+	dynnxt1d.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	icestp1d.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diawri1d.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dyncor1d.o) \
+	$(MODEL_LIB)(dynnxt1d.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	step1d.F90
+$(MODEL_LIB)(step.o) :	\
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	dom_ice.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv_cen2.F90 \
+	dynadv.F90 \
+	dynadv_ubs.F90 \
+	dynhpg_jki.F90 \
+	dynkeg.F90 \
+	dynldf_bilap.F90 \
+	dynldf_bilapg.F90 \
+	dynldf_iso.F90 \
+	dynldf_lap.F90 \
+	dynspg_exp.F90 \
+	dynspg_exp_jki.F90 \
+	dynspg_flt.F90 \
+	dynspg_flt_jki.F90 \
+	dynspg_oce.F90 \
+	dynspg_rl.F90 \
+	dynspg_ts.F90 \
+	dynspg_ts_jki.F90 \
+	dynzad.F90 \
+	dynzdf_exp.F90 \
+	dynzdf_imp.F90 \
+	dynzdf_imp_jki.F90 \
+	eosbn2.F90 \
+	flo4rk.F90 \
+	floblk.F90 \
+	flodom.F90 \
+	flo_oce.F90 \
+	flowri.F90 \
+	flxblk.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	limdia.F90 \
+	limdmp.F90 \
+	limdyn.F90 \
+	limflx.F90 \
+	limrst.F90 \
+	limthd.F90 \
+	limtrp.F90 \
+	limwri.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_ice.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv_cen2.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynadv_ubs.o) \
+	$(MODEL_LIB)(dynhpg_jki.o) \
+	$(MODEL_LIB)(dynkeg.o) \
+	$(MODEL_LIB)(dynldf_bilapg.o) \
+	$(MODEL_LIB)(dynldf_bilap.o) \
+	$(MODEL_LIB)(dynldf_iso.o) \
+	$(MODEL_LIB)(dynldf_lap.o) \
+	$(MODEL_LIB)(dynspg_exp_jki.o) \
+	$(MODEL_LIB)(dynspg_exp.o) \
+	$(MODEL_LIB)(dynspg_flt_jki.o) \
+	$(MODEL_LIB)(dynspg_flt.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynspg_rl.o) \
+	$(MODEL_LIB)(dynspg_ts_jki.o) \
+	$(MODEL_LIB)(dynspg_ts.o) \
+	$(MODEL_LIB)(dynzad.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(dynzdf_imp_jki.o) \
+	$(MODEL_LIB)(dynzdf_imp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flo4rk.o) \
+	$(MODEL_LIB)(floblk.o) \
+	$(MODEL_LIB)(flodom.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flowri.o) \
+	$(MODEL_LIB)(flxblk.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(limdia.o) \
+	$(MODEL_LIB)(limdmp.o) \
+	$(MODEL_LIB)(limdyn.o) \
+	$(MODEL_LIB)(limflx.o) \
+	$(MODEL_LIB)(limrst.o) \
+	$(MODEL_LIB)(limthd.o) \
+	$(MODEL_LIB)(limtrp.o) \
+	$(MODEL_LIB)(limwri.o) \
+	$(MODEL_LIB)(obccli.o) \
+	$(MODEL_LIB)(obcdyn_bt.o) \
+	$(MODEL_LIB)(obcdyn.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(obcvol.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv_cen2_jki.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obccli.F90 \
+	obcdyn_bt.F90 \
+	obcdyn.F90 \
+	obc_oce.F90 \
+	obctra.F90 \
+	obcvol.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	solfet.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	traadv_cen2.F90 \
+	traadv_cen2_jki.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl2.F90 \
+	traadv_muscl.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	traqsr.F90 \
+	trazdf_exp.F90 \
+	trazdf.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trc_oce.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	zpshde.F90 \
+	agrif_opa_sponge.F90 \
+	cla_div.F90 \
+	cla.F90 \
+	closea.F90 \
+	cpl.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	diafwb.F90 \
+	diagap.F90 \
+	diahdy.F90 \
+	diahth.F90 \
+	diaptr.F90 \
+	diaspr.F90 \
+	diawri.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynadv.F90 \
+	dynhpg.F90 \
+	dynldf.F90 \
+	dynnxt.F90 \
+	dynspg.F90 \
+	dynspg_oce.F90 \
+	dynvor.F90 \
+	dynzdf.F90 \
+	eosbn2.F90 \
+	floats.F90 \
+	flo_oce.F90 \
+	flxfwb.F90 \
+	flxmod.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	icestp.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfeiv.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(agrif_opa_sponge.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cla.o) \
+	$(MODEL_LIB)(closea.o) \
+	$(MODEL_LIB)(cpl.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diafwb.o) \
+	$(MODEL_LIB)(diagap.o) \
+	$(MODEL_LIB)(diahdy.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynadv.o) \
+	$(MODEL_LIB)(dynhpg.o) \
+	$(MODEL_LIB)(dynldf.o) \
+	$(MODEL_LIB)(dynnxt.o) \
+	$(MODEL_LIB)(dynspg.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynvor.o) \
+	$(MODEL_LIB)(dynzdf.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(floats.o) \
+	$(MODEL_LIB)(flo_oce.o) \
+	$(MODEL_LIB)(flxfwb.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(icestp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfeiv.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(obcdta.o) \
+	$(MODEL_LIB)(obc_par.o) \
+	$(MODEL_LIB)(obcrad.o) \
+	$(MODEL_LIB)(obcrst.o) \
+	$(MODEL_LIB)(obcspg.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(stpctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(traadv.o) \
+	$(MODEL_LIB)(trabbc.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(traldf.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(tranxt.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trasbc.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trcstp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdfbfr.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke_jki.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	obcdta.F90 \
+	obc_par.F90 \
+	obcrad.F90 \
+	obcrst.F90 \
+	obcspg.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	stpctl.F90 \
+	taumod.F90 \
+	traadv.F90 \
+	trabbc.F90 \
+	trabbl.F90 \
+	tradmp.F90 \
+	traldf.F90 \
+	tranpc.F90 \
+	tranxt.F90 \
+	traqsr.F90 \
+	trasbc.F90 \
+	trazdf.F90 \
+	trcstp.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	wzvmod.F90 \
+	zdfbfr.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdftke_jki.F90 \
+	zpshde.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	step.F90
+$(MODEL_LIB)(stpctl.o) :	\
+	daymod.F90 \
+	diadimg.F90 \
+	diahth.F90 \
+	dianam.F90 \
+	diaspr.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(diahth.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(diaspr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(solfet.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(solpcg.o) \
+	$(MODEL_LIB)(solsor.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	solfet.F90 \
+	sol_oce.F90 \
+	solpcg.F90 \
+	solsor.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diawri.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diawri.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(solisl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	oce.F90 \
+	solisl.F90 \
+	sol_oce.F90 \
+	stpctl.F90
+$(MODEL_LIB)(taumod.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	flx_oce.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oasis4_date.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_ice.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oasis4_date.F90 \
+	oce.F90 \
+	par_ice.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(phycst.o) \
+	phycst.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	tau_forced_daily.h90 \
+	tau_forced_monthly.h90 \
+	tau_oasis_ice.h90 \
+	KEY_CPP \
+	taumod.F90
+$(MODEL_LIB)(thd_ice.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(par_ice.o) \
+	par_ice.F90 \
+	thd_ice.F90
+$(MODEL_LIB)(traadv_cen2.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2.F90
+$(MODEL_LIB)(traadv_cen2_jki.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_cen2_jki.F90
+$(MODEL_LIB)(traadv_eiv.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfmxl.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_eiv.F90
+$(MODEL_LIB)(traadv.o) :	\
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	eosbn2.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traadv_cen2_jki.o) \
+	$(MODEL_LIB)(traadv_cen2.o) \
+	$(MODEL_LIB)(traadv_eiv.o) \
+	$(MODEL_LIB)(traadv_muscl2.o) \
+	$(MODEL_LIB)(traadv_muscl.o) \
+	$(MODEL_LIB)(traadv_qck.o) \
+	$(MODEL_LIB)(traadv_tvd.o) \
+	$(MODEL_LIB)(traadv_ubs.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	oce.F90 \
+	prtctl.F90 \
+	traadv_cen2.F90 \
+	traadv_cen2_jki.F90 \
+	traadv_eiv.F90 \
+	traadv_muscl2.F90 \
+	traadv_muscl.F90 \
+	traadv_qck.F90 \
+	traadv_tvd.F90 \
+	traadv_ubs.F90 \
+	trabbl.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv.F90
+$(MODEL_LIB)(traadv_muscl2.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl2.F90
+$(MODEL_LIB)(traadv_muscl.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_muscl.F90
+$(MODEL_LIB)(traadv_qck.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	flxrnf.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_qck.F90
+$(MODEL_LIB)(traadv_tvd.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trabbl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trabbl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_tvd.F90
+$(MODEL_LIB)(traadv_ubs.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traadv_ubs.F90
+$(MODEL_LIB)(trabbc.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	trabbc.F90
+$(MODEL_LIB)(trabbl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	eosbn2.F90 \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(oce.o) \
+	oce.F90 \
+	domzgr_substitute.h90 \
+	trabbl_adv.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trabbl.F90
+$(MODEL_LIB)(tradmp.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtatem.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	tradmp.F90
+$(MODEL_LIB)(traldf_bilap.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_bilap.F90
+$(MODEL_LIB)(traldf_bilapg.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfeiv_substitute.h90 \
+	ldftra_substitute.h90 \
+	KEY_CPP \
+	traldf_bilapg.F90
+$(MODEL_LIB)(traldf.o) :	\
+	diaptr.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traldf_bilapg.o) \
+	$(MODEL_LIB)(traldf_bilap.o) \
+	$(MODEL_LIB)(traldf_iso.o) \
+	$(MODEL_LIB)(traldf_lap.o) \
+	$(MODEL_LIB)(trazdf.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	traldf_bilap.F90 \
+	traldf_bilapg.F90 \
+	traldf_iso.F90 \
+	traldf_lap.F90 \
+	trazdf.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf.F90
+$(MODEL_LIB)(traldf_iso.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_iso.F90
+$(MODEL_LIB)(traldf_lap.o) :	\
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	diaptr.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(diaptr.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traldf_lap.F90
+$(MODEL_LIB)(tranpc.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	tranpc.F90
+$(MODEL_LIB)(tranxt.o) :	\
+	blk_oce.F90 \
+	cla_div.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	divcur.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cla_div.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(divcur.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(obc_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sol_oce.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(wzvmod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obc_oce.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sol_oce.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	wzvmod.F90 \
+	zdf_oce.F90 \
+	agrif_opa_interp.F90 \
+	agrif_opa_update.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(agrif_opa_interp.o) \
+	$(MODEL_LIB)(agrif_opa_update.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(obctra.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	obctra.F90 \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	$(AGRIF_LIB) \
+	KEY_CPP \
+	tranxt.F90
+$(MODEL_LIB)(traqsr.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(sms.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	sms.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trc_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	traqsr.F90
+$(MODEL_LIB)(trasbc.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trc_oce.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trc_oce.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(traqsr.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	traqsr.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trasbc.F90
+$(MODEL_LIB)(trazdf_exp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_exp.F90
+$(MODEL_LIB)(trazdf.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	trazdf_exp.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trazdf_imp_jki.o) \
+	$(MODEL_LIB)(trazdf_imp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trazdf_exp.F90 \
+	trazdf_imp.F90 \
+	trazdf_imp_jki.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf.F90
+$(MODEL_LIB)(trazdf_imp.o) :	\
+	dom_oce.F90 \
+	dynspg_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	zdfddm_substitute.h90 \
+	KEY_CPP \
+	trazdf_imp.F90
+$(MODEL_LIB)(trazdf_imp_jki.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdicp_oce.F90 \
+	trdmld.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	zdfddm_substitute.h90 \
+	zdf.matrixsolver.h90 \
+	KEY_CPP \
+	trazdf_imp_jki.F90
+$(MODEL_LIB)(trc_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(sms.o) \
+	par_oce.F90 \
+	sms.F90 \
+	KEY_CPP \
+	trc_oce.F90
+$(MODEL_LIB)(trcstp.o) :	\
+	trcstp.F90
+$(MODEL_LIB)(trdicp.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdicp.F90
+$(MODEL_LIB)(trdicp_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdicp_oce.F90
+$(MODEL_LIB)(trdmld.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldftra_substitute.h90 \
+	zdfddm_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdmld.F90
+$(MODEL_LIB)(trdmld_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdmld_oce.F90
+$(MODEL_LIB)(trdmld_rst.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zpshde.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	restart.F90 \
+	trdmod_oce.F90 \
+	KEY_CPP \
+	trdmld_rst.F90
+$(MODEL_LIB)(trdmod.o) :	\
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	daymod.F90 \
+	diadimg.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(diadimg.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmld_rst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdmld_rst.F90 \
+	trdmod_oce.F90 \
+	trdvor_oce.F90 \
+	zdfddm.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	ldftra_oce.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdicp.o) \
+	$(MODEL_LIB)(trdmld.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(trdvor.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	taumod.F90 \
+	trdicp.F90 \
+	trdmld.F90 \
+	trdmod_oce.F90 \
+	trdvor.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	trdmod.F90
+$(MODEL_LIB)(trdmod_oce.o) :	\
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	KEY_CPP \
+	trdmod_oce.F90
+$(MODEL_LIB)(trdvor.o) :	\
+	daymod.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(trdicp_oce.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdvor_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	trdicp_oce.F90 \
+	trdmld_oce.F90 \
+	trdvor_oce.F90 \
+	zdf_oce.F90 \
+	daymod.F90 \
+	dianam.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dianam.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	trdmod_oce.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	ldfdyn_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	$(IOIPSL_LIB) \
+	KEY_CPP \
+	trdvor.F90
+$(MODEL_LIB)(trdvor_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	trdvor_oce.F90
+$(MODEL_LIB)(wzvmod.o) :	\
+	blk_oce.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	dynspg_oce.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(dynspg_oce.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	dom_oce.F90 \
+	domvvl.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(domvvl.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	wzvmod.F90
+$(MODEL_LIB)(zdfbfr.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfbfr.F90
+$(MODEL_LIB)(zdfddm.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfddm.F90
+$(MODEL_LIB)(zdfevd.o) :	\
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfevd.F90
+$(MODEL_LIB)(zdfini.o) :	\
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	ldfdyn_oce.F90 \
+	ldftra_oce.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdfmxl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdfkpp.F90 \
+	zdfmxl.F90 \
+	zdf_oce.F90 \
+	in_out_manager.F90 \
+	ldfdyn_oce.F90 \
+	ldfslp.F90 \
+	ldftra_oce.F90 \
+	lib_mpp.F90 \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(ldfdyn_oce.o) \
+	$(MODEL_LIB)(ldfslp.o) \
+	$(MODEL_LIB)(ldftra_oce.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(tranpc.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdfevd.o) \
+	$(MODEL_LIB)(zdfkpp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdfric.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	par_oce.F90 \
+	tranpc.F90 \
+	zdfddm.F90 \
+	zdfevd.F90 \
+	zdfkpp.F90 \
+	zdf_oce.F90 \
+	zdfric.F90 \
+	zdftke.F90 \
+	zdfini.F90
+$(MODEL_LIB)(zdfkpp.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dtasal.F90 \
+	dtasss.F90 \
+	dtasst.F90 \
+	dtatem.F90 \
+	flxmod.F90 \
+	flx_oce.F90 \
+	flxrnf.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dtasal.o) \
+	$(MODEL_LIB)(dtasss.o) \
+	$(MODEL_LIB)(dtasst.o) \
+	$(MODEL_LIB)(dtatem.o) \
+	$(MODEL_LIB)(flxmod.o) \
+	$(MODEL_LIB)(flx_oce.o) \
+	$(MODEL_LIB)(flxrnf.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocfzpt.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(tradmp.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocfzpt.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	tradmp.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(ocesbc.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	ocesbc.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdfkpp.F90
+$(MODEL_LIB)(zdfmxl.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	prtctl.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfmxl.F90
+$(MODEL_LIB)(zdf_oce.o) :	\
+	$(MODEL_LIB)(par_kind.o) \
+	par_kind.F90 \
+	$(MODEL_LIB)(par_oce.o) \
+	par_oce.F90 \
+	KEY_CPP \
+	zdf_oce.F90
+$(MODEL_LIB)(zdfric.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	KEY_CPP \
+	zdfric.F90
+$(MODEL_LIB)(zdftke.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom_def.F90 \
+	iom.F90 \
+	iom_ioipsl.F90 \
+	iom_nf90.F90 \
+	iom_rstdimg.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom_def.o) \
+	$(MODEL_LIB)(iom_ioipsl.o) \
+	$(MODEL_LIB)(iom_nf90.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(iom_rstdimg.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(trdmod.o) \
+	$(MODEL_LIB)(trdmod_oce.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	taumod.F90 \
+	trdmld_oce.F90 \
+	trdmod.F90 \
+	trdmod_oce.F90 \
+	zdfddm.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	zdf_oce.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdftke.F90
+$(MODEL_LIB)(zdftke_jki.o) :	\
+	blk_oce.F90 \
+	cpl_oasis3.F90 \
+	cpl_oasis4.F90 \
+	cpl_oce.F90 \
+	daymod.F90 \
+	dom_oce.F90 \
+	dynzdf_exp.F90 \
+	eosbn2.F90 \
+	geo2ocean.F90 \
+	ice.F90 \
+	ice_oce.F90 \
+	ini1d.F90 \
+	in_out_manager.F90 \
+	iom.F90 \
+	lbclnk.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(blk_oce.o) \
+	$(MODEL_LIB)(cpl_oasis3.o) \
+	$(MODEL_LIB)(cpl_oasis4.o) \
+	$(MODEL_LIB)(cpl_oce.o) \
+	$(MODEL_LIB)(daymod.o) \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(dynzdf_exp.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(geo2ocean.o) \
+	$(MODEL_LIB)(ice.o) \
+	$(MODEL_LIB)(ice_oce.o) \
+	$(MODEL_LIB)(ini1d.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(iom.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(trazdf_exp.o) \
+	$(MODEL_LIB)(trdmld_oce.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zpshde.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	trazdf_exp.F90 \
+	trdmld_oce.F90 \
+	zdf_oce.F90 \
+	zpshde.F90 \
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(restart.o) \
+	$(MODEL_LIB)(taumod.o) \
+	$(MODEL_LIB)(zdf_oce.o) \
+	$(MODEL_LIB)(zdftke.o) \
+	oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	restart.F90 \
+	taumod.F90 \
+	zdf_oce.F90 \
+	zdftke.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zdftke_jki.F90
+$(MODEL_LIB)(zpshde.o) :	\
+	dom_oce.F90 \
+	in_out_manager.F90 \
+	lib_mpp.F90 \
+	lib_print.f90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lib_mpp.o) \
+	$(MODEL_LIB)(lib_print.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(par_kind.o) \
+	$(MODEL_LIB)(par_oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	$(MODEL_LIB)(prtctl.o) \
+	$(MODEL_LIB)(zdfddm.o) \
+	oce.F90 \
+	par_kind.F90 \
+	par_oce.F90 \
+	phycst.F90 \
+	prtctl.F90 \
+	zdfddm.F90 \
+	dom_oce.F90 \
+	eosbn2.F90 \
+	in_out_manager.F90 \
+	lbclnk.F90 \
+	$(MODEL_LIB)(dom_oce.o) \
+	$(MODEL_LIB)(eosbn2.o) \
+	$(MODEL_LIB)(in_out_manager.o) \
+	$(MODEL_LIB)(lbclnk.o) \
+	$(MODEL_LIB)(oce.o) \
+	$(MODEL_LIB)(phycst.o) \
+	oce.F90 \
+	phycst.F90 \
+	domzgr_substitute.h90 \
+	vectopt_loop_substitute.h90 \
+	KEY_CPP \
+	zpshde.F90
+# agrif previous use
+firstagrif:
+ifeq ($(AGRIF),use)
+	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+else
+	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp
+#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC
+# recompile all in this case
+mpiagrif:
+ifeq ($(AGRIF),use)
+ifeq (,$(AGRIF_MPI))
+	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi
+endif
+endif
+# key changing control
+key: 
+	@echo CHANGE of CPP KEYS yes/no ?
+	-@if [ "`cat KEY_CPP`" != "$(P_P:$(prefix)%=%)" ] ; then \
+		echo CPP options changed ; echo "$(P_P:$(prefix)%=%)" > KEY_CPP ; fi 
+# check key values
+keyverif:
+	@echo CHECKING KEY
+	@echo KEY USED : 
+	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \
+	do \
+	echo $$v ;\
+        w=`echo $$v | cut -c1-3` ; \
+        if [ $$w = `echo "key"` ] ; then \
+        r=n ; \
+        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \
+           if [ $$r != "n" ] ; then \
+              echo "UNKNOWN KEY" ;\
+              false ;  \
+              exit ;  \
+           fi \
+        fi \
+	done
+# Checking the number of routines
+src_file_list: 
+	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES 
+	@$(RM) `ls | fgrep -v -f .patron` 
+	@check=`grep OPA_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OPA_SRC files"                ; \
+	    ln -sf ../OPA_SRC/*.[Ffh]90          . ; \
+	    ln -sf ../OPA_SRC/DYN/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/TRA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/TRD/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DIA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DOM/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/OBC/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/FLO/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/LDF/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/ZDF/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/SOL/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/DTA/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/SBC/*.[Ffh]90      . ; \
+	    ln -sf ../OPA_SRC/IOM/*.[Ffh]90      . ; \
+  fi 
+	@check=`grep LIM_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use LIM_SRC files"                ; \
+      ln -sf ../LIM_SRC/*.[Ffh]90          . ; \
+  fi 
+	@check=`grep C1D_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use C1D_SRC files"                ; \
+      ln -sf ../C1D_SRC/*.[Ffh]90          . ; \
+  fi 
+	@check=`grep TOP_SRC .config`              ; \
+	if [ -n "$$check" ] ; then  \
+	echo "   use TOP_SRC files"                ; \
+      \$(RM) trcstp.F90                      ; \
+      \$(RM) sms.F90                         ; \
+      \$(RM) initrc.F90                      ; \
+      ln -sf ../TOP_SRC/*.[Ffh]90          . ; \
+      ln -sf ../TOP_SRC/SMS/*.[Ffh]        . ; \
+      ln -sf ../TOP_SRC/SMS/*.[Ffh]90      . ; \
+      ln -sf ../TOP_SRC/TRP/*.[Ffh]90      . ; \
+  fi 
+	@check=`grep OFF_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use OFF_SRC files"                ; \
+      ln -sf ../OFF_SRC/*.[Ffh]90          . ; \
+      ln -sf ../OFF_SRC/*/*.[Ffh]90        . ; \
+  fi 
+	@check=`grep NST_SRC .config`              ; \
+	if [ -n "$$check" ] ; then                   \
+	echo "   use NST_SRC files"                ; \
+      \$(RM) agrif_opa_interp.F90           ; \
+      \$(RM) agrif_opa_sponge.F90           ; \
+      \$(RM) agrif_opa_update.F90           ; \
+      ln -sf ../NST_SRC/*.[Ffh]90      .     ; \
+  fi 
+	@\$(RM) tmplist
+	@ls -1 | fgrep -v -f .patron  >tmplist
+	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \
+	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \
+	\$(RM) model.o \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN) ; \
+	echo "Rebuilding the AA_make files" ; \
+	cd ..  ; ../UTIL/fait_AA_make ; echo " " ; \
+	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \
+	echo "========================================== " ; \
+	../../util/ins_make ; echo " " ;  false ; exit ; }
Index: /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CONFIG/ORCA2_LIM/scripts/BB_make.ldef	(revision 4536)
@@ -0,0 +1,46 @@
+#----------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model + Sea Ice Model   (BB_make.ldef in scripts)
+#----------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+MODDIR = $(LIBDIR)
+MODEL_LIB = $(LIBDIR)/oce/libopa.a
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxdkrz IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- eshpux IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxdkrz AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- eshpux AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxdkrz SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- eshpux SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opa
+
+#-
+#- Key options for OPA ocean model + LIM sea ice model : ORCA_R2 - FORCED (CLIO)
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P = key_trabbl_dif key_vectopt_loop key_vectopt_memory key_orca_r2 key_ice_lim key_lim_fdd key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_dtatem key_dtasal key_tau_monthly key_flx_bulk_monthly key_tradmp key_trabbc key_zdftke key_zdfddm
+
+#-
+#- Prefix for preprocessing ---
+#-Q- sx8mercure prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/checkoutlist
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/checkoutlist	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/checkoutlist	(revision 4536)
@@ -0,0 +1,13 @@
+# The "checkoutlist" file is used to support additional version controlled
+# administrative files in $CVSROOT/CVSROOT, such as template files.
+#
+# The first entry on a line is a filename which will be checked out from
+# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
+# The remainder of the line is an error message to use if the file cannot
+# be checked out.
+#
+# File format:
+#
+#	[<whitespace>]<filename><whitespace><error message><end-of-line>
+#
+# comment lines begin with '#'
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/commitinfo
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/commitinfo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/commitinfo	(revision 4536)
@@ -0,0 +1,15 @@
+# The "commitinfo" file is used to control pre-commit checks.
+# The filter on the right is invoked with the repository and a list 
+# of files to check.  A non-zero exit of the filter program will 
+# cause the commit to be aborted.
+#
+# The first entry on a line is a regular expression which is tested
+# against the directory that the change is being committed to, relative
+# to the $CVSROOT.  For the first match that is found, then the remainder
+# of the line is the name of the filter to run.
+#
+# If the repository name does not match any of the regular expressions in this
+# file, the "DEFAULT" line is used, if it is specified.
+#
+# If the name "ALL" appears as a regular expression it is always used
+# in addition to the first matching regex or "DEFAULT".
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/config
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/config	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/config	(revision 4536)
@@ -0,0 +1,21 @@
+# Set this to "no" if pserver shouldn't check system users/passwords
+#SystemAuth=no
+
+# Put CVS lock files in this directory rather than directly in the repository.
+#LockDir=/var/lock/cvs
+
+# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top
+# level of the new working directory when using the `cvs checkout'
+# command.
+#TopLevelAdmin=no
+
+# Set `LogHistory' to `all' or `TOFEWGCMAR' to log all transactions to the
+# history file, or a subset as needed (ie `TMAR' logs all write operations)
+#LogHistory=TOFEWGCMAR
+
+# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg
+# script to change the log message.  Set it to `stat' to force CVS to verify# that the file has changed before reading it (this can take up to an extra
+# second per directory being committed, so it is not recommended for large
+# repositories.  Set it to `never' (the previous CVS behavior) to prevent
+# verifymsg scripts from changing the log message.
+#RereadLogAfterVerify=always
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/cvswrappers
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/cvswrappers	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/cvswrappers	(revision 4536)
@@ -0,0 +1,19 @@
+# This file affects handling of files based on their names.
+#
+# The -m option specifies whether CVS attempts to merge files.
+#
+# The -k option specifies keyword expansion (e.g. -kb for binary).
+#
+# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
+#
+#  wildcard	[option value][option value]...
+#
+#  where option is one of
+#  -f		from cvs filter		value: path to filter
+#  -t		to cvs filter		value: path to filter
+#  -m		update methodology	value: MERGE or COPY
+#  -k		expansion mode		value: b, o, kkv, &c
+#
+#  and value is a single-quote delimited value.
+# For example:
+#*.gif -k 'b'
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/editinfo
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/editinfo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/editinfo	(revision 4536)
@@ -0,0 +1,21 @@
+# The "editinfo" file is used to allow verification of logging
+# information.  It works best when a template (as specified in the
+# rcsinfo file) is provided for the logging procedure.  Given a
+# template with locations for, a bug-id number, a list of people who
+# reviewed the code before it can be checked in, and an external
+# process to catalog the differences that were code reviewed, the
+# following test can be applied to the code:
+#
+#   Making sure that the entered bug-id number is correct.
+#   Validating that the code that was reviewed is indeed the code being
+#       checked in (using the bug-id number or a seperate review
+#       number to identify this particular code set.).
+#
+# If any of the above test failed, then the commit would be aborted.
+#
+# Actions such as mailing a copy of the report to each reviewer are
+# better handled by an entry in the loginfo file.
+#
+# One thing that should be noted is the the ALL keyword is not
+# supported.  There can be only one entry that matches a given
+# repository.
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/loginfo
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/loginfo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/loginfo	(revision 4536)
@@ -0,0 +1,26 @@
+# The "loginfo" file controls where "cvs commit" log information
+# is sent.  The first entry on a line is a regular expression which must match
+# the directory that the change is being made to, relative to the
+# $CVSROOT.  If a match is found, then the remainder of the line is a filter
+# program that should expect log information on its standard input.
+#
+# If the repository name does not match any of the regular expressions in this
+# file, the "DEFAULT" line is used, if it is specified.
+#
+# If the name ALL appears as a regular expression it is always used
+# in addition to the first matching regex or DEFAULT.
+#
+# You may specify a format string as part of the
+# filter.  The string is composed of a `%' followed
+# by a single format character, or followed by a set of format
+# characters surrounded by `{' and `}' as separators.  The format
+# characters are:
+#
+#   s = file name
+#   V = old version number (pre-checkin)
+#   v = new version number (post-checkin)
+#
+# For example:
+#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
+# or
+#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/modules
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/modules	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/modules	(revision 4536)
@@ -0,0 +1,26 @@
+# Three different line formats are valid:
+#	key	-a    aliases...
+#	key [options] directory
+#	key [options] directory files...
+#
+# Where "options" are composed of:
+#	-i prog		Run "prog" on "cvs commit" from top-level of module.
+#	-o prog		Run "prog" on "cvs checkout" of module.
+#	-e prog		Run "prog" on "cvs export" of module.
+#	-t prog		Run "prog" on "cvs rtag" of module.
+#	-u prog		Run "prog" on "cvs update" of module.
+#	-d dir		Place module in directory "dir" instead of module name.
+#	-l		Top-level directory only -- do not recurse.
+#
+# NOTE:  If you change any of the "Run" options above, you'll have to
+# release and re-checkout any working directories of these modules.
+#
+# And "directory" is a path to a directory relative to $CVSROOT.
+#
+# The "-a" option specifies an alias.  An alias is interpreted as if
+# everything on the right of the "-a" had been typed on the command line.
+#
+# You can encode a module within a module by using the special '&'
+# character to interpose another module into the current module.  This
+# can be useful for creating a module that consists of many directories
+# spread out over the entire source repository.
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/notify
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/notify	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/notify	(revision 4536)
@@ -0,0 +1,12 @@
+# The "notify" file controls where notifications from watches set by
+# "cvs watch add" or "cvs edit" are sent.  The first entry on a line is
+# a regular expression which is tested against the directory that the
+# change is being made to, relative to the $CVSROOT.  If it matches,
+# then the remainder of the line is a filter program that should contain
+# one occurrence of %s for the user to notify, and information on its
+# standard input.
+#
+# "ALL" or "DEFAULT" can be used in place of the regular expression.
+#
+# For example:
+#ALL mail -s "CVS notification" %s
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/rcsinfo
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/rcsinfo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/rcsinfo	(revision 4536)
@@ -0,0 +1,13 @@
+# The "rcsinfo" file is used to control templates with which the editor
+# is invoked on commit and import.
+#
+# The first entry on a line is a regular expression which is tested
+# against the directory that the change is being made to, relative to the
+# $CVSROOT.  For the first match that is found, then the remainder of the
+# line is the name of the file that contains the template.
+#
+# If the repository name does not match any of the regular expressions in this
+# file, the "DEFAULT" line is used, if it is specified.
+#
+# If the name "ALL" appears as a regular expression it is always used
+# in addition to the first matching regex or "DEFAULT".
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/taginfo
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/taginfo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/taginfo	(revision 4536)
@@ -0,0 +1,20 @@
+# The "taginfo" file is used to control pre-tag checks.
+# The filter on the right is invoked with the following arguments:
+#
+# $1 -- tagname
+# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
+# $3 -- repository
+# $4->  file revision [file revision ...]
+#
+# A non-zero exit of the filter program will cause the tag to be aborted.
+#
+# The first entry on a line is a regular expression which is tested
+# against the directory that the change is being committed to, relative
+# to the $CVSROOT.  For the first match that is found, then the remainder
+# of the line is the name of the filter to run.
+#
+# If the repository name does not match any of the regular expressions in this
+# file, the "DEFAULT" line is used, if it is specified.
+#
+# If the name "ALL" appears as a regular expression it is always used
+# in addition to the first matching regex or "DEFAULT".
Index: /branches/2010_and_older/dev_001_GM/CVSROOT/verifymsg
===================================================================
--- /branches/2010_and_older/dev_001_GM/CVSROOT/verifymsg	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/CVSROOT/verifymsg	(revision 4536)
@@ -0,0 +1,21 @@
+# The "verifymsg" file is used to allow verification of logging
+# information.  It works best when a template (as specified in the
+# rcsinfo file) is provided for the logging procedure.  Given a
+# template with locations for, a bug-id number, a list of people who
+# reviewed the code before it can be checked in, and an external
+# process to catalog the differences that were code reviewed, the
+# following test can be applied to the code:
+#
+#   Making sure that the entered bug-id number is correct.
+#   Validating that the code that was reviewed is indeed the code being
+#       checked in (using the bug-id number or a seperate review
+#       number to identify this particular code set.).
+#
+# If any of the above test failed, then the commit would be aborted.
+#
+# Actions such as mailing a copy of the report to each reviewer are
+# better handled by an entry in the loginfo file.
+#
+# One thing that should be noted is the the ALL keyword is not
+# supported.  There can be only one entry that matches a given
+# repository.
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Biblio/Biblio.bib
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Biblio/Biblio.bib	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Biblio/Biblio.bib	(revision 4536)
@@ -0,0 +1,2003 @@
+This file was created with JabRef 2.2.
+Encoding: UTF8
+
+@STRING{AP = {Academic Press}}
+
+@STRING{AREPS = {Annual Review of Earth Planetary Science}}
+
+@STRING{ARFM = {Annual Review of Fluid Mechanics}}
+
+@STRING{ASL = {Atmospheric Science Letters}}
+
+@STRING{AW = {Addison-Wesley}}
+
+@STRING{CD = {Clim. Dyn.}}
+
+@STRING{CP = {Clarendon Press}}
+
+@STRING{CUP = {Cambridge University Press}}
+
+@STRING{D = {Dover Publications}}
+
+@STRING{DAO = {Dyn. Atmos. Ocean}}
+
+@STRING{DSR = {Deep-Sea Res.}}
+
+@STRING{E = {Eyrolles}}
+
+@STRING{GRL = {Geophys. Res. Let.}}
+
+@STRING{I = {Interscience}}
+
+@STRING{JAOT = {J. Atmos. Ocean Tech.}}
+
+@STRING{JAS = {J. Atmos. Sc.}}
+
+@STRING{JC = {J. Climate}}
+
+@STRING{JCP = {J. Comput. Phys.}}
+
+@STRING{JGR = {J. Geophys. Res}}
+
+@STRING{JHUP = {The Johns Hopkins University Press}}
+
+@STRING{JMR = {J. Mar. Res.}}
+
+@STRING{JMS = {J. Mar. Sys.}}
+
+@STRING{JMSJ = {J. Met. Soc. Japan}}
+
+@STRING{JPO = {J. Phys. Oceanogr.}}
+
+@STRING{JWS = {John Wiley and Sons}}
+
+@STRING{M = {Macmillan}}
+
+@STRING{MGH = {McGraw-Hill}}
+
+@STRING{MWR = {Mon. Wea. Rev.}}
+
+@STRING{Nature = {Nat.}}
+
+@STRING{NH = {North-Holland}}
+
+@STRING{Ocean = {Oceanology}}
+
+@STRING{OS = {Ocean Science}}
+
+@STRING{OUP = {Oxford University Press}}
+
+@STRING{PH = {Prentice-Hall}}
+
+@STRING{PO = {Prog. Oceangr.}}
+
+@STRING{PP = {Pergamon Press}}
+
+@STRING{PRSL = {Proceedings of the Royal Society of London}}
+
+@STRING{QJRMS = {Quart J Roy Meteor Soc}}
+
+@STRING{Recherche = {La Recherche}}
+
+@STRING{Science = {Science}}
+
+@STRING{SV = {Springer-Verlag}}
+
+@STRING{Tellus = {Tellus}}
+
+@ARTICLE{Arakawa1966,
+  author = {A. Arakawa},
+  title = {Computational design for long term numerical integration of the equations
+	of fluid motion, two-dimensional incompressible flow, Part. I.},
+  journal = JCP,
+  year = {1966},
+  volume = {I},
+  pages = {119-149},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Arakawa1990,
+  author = {A. Arakawa and Y.-J. G. Hsu},
+  title = {Energy Conserving and Potential-Enstrophy Dissipating Schemes for
+	the Shallow Water Equations},
+  journal = MWR,
+  year = {1990},
+  volume = {118},
+  pages = {1960--1969
+	
+	},
+  number = {10},
+  abstract = {To incorporate potential enstrophy dissipation into discrete shallow
+	water equations with no or arbitrarily small energy dissipation,
+	a family of finite-difference schemes have been derived with which
+	potential enstrophy is guaranteed to decrease while energy is conserved
+	(when the mass flux is nondivergent and time is continuous). Among
+	this family of schemes, there is a member that minimizes the spurious
+	impact of infinite potential vorticities associated with infinitesimal
+	fluid depth. The scheme is, therefore, useful for problems in which
+	the free surface may intersect with the lower boundary.},
+  date = {October 01, 1990},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Arakawa1981,
+  author = {Arakawa, Akio and Lamb, Vivian R.},
+  title = {A Potential Enstrophy and Energy Conserving Scheme for the Shallow
+	Water Equations},
+  journal = MWR,
+  year = {1981},
+  volume = {109},
+  pages = {18--36
+	
+	},
+  number = {1},
+  abstract = {To improve the simulation of nonlinear aspects of the flow over steep
+	topography, a potential enstrophy and energy conserving scheme for
+	the shallow water equations is derived. It is pointed out that a
+	family of schemes can conserve total energy for general flow and
+	potential enstrophy for flow with no mass flux divergence. The newly
+	derived scheme is a unique member of this family, that conserves
+	both potential enstrophy and energy for general flow. Comparison
+	by means of numerical experiment with a scheme that conserves (potential)
+	enstrophy for purely horizontal nondivergent flow demonstrated the
+	considerable superiority of the newly derived potential enstrophy
+	and energy conserving scheme, not only in suppressing a spurious
+	energy cascade but also in determining the overall flow regime. The
+	potential enstrophy and energy conserving scheme for a spherical
+	grid is also presented.},
+  date = {January 01, 1981},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{ASSELIN1972,
+  author = {R. Asselin},
+  title = {Frequency Filter for Time Integrations},
+  journal = MWR,
+  year = {1972},
+  volume = {100},
+  pages = {487-490},
+  number = {6},
+  abstract = {A simple filter for controlling high-frequency computational and physical
+	modes arising in time integrations is proposed. A linear analysis
+	of the filter with leapfrog, implicit, and semi-implicit, differences
+	is made. The filter very quickly removes the computational mode and
+	is also very useful in damping high-frequency physical waves. The
+	stability of the leapfrog scheme is adversely affected when a large
+	filter parameter is used, but the analysis shows that the use of
+	centered differences with frequency filter is still more advantageous
+	than the use of the Euler-backward method. An example of the use
+	of the filter in an actual forecast with the meteorological equations
+	is shown.},
+  date = {June 01, 1972},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Beckmann1998,
+  author = {A. Beckmann},
+  title = {The representation of bottom boundary layer processes in numerical
+	ocean circulation models.},
+  journal = {Ocean modelling and parameterization, E. P. Chassignet and J. Verron
+	(eds.), NATO Science Series, Kluwer Academic Publishers},
+  year = {1998},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{BeckDos1998,
+  author = {A. Beckmann and R. D\"{o}scher},
+  title = {A method for improved representation of dense water spreading over
+	topography in geopotential-coordinate models},
+  journal = JPO,
+  year = {1998},
+  volume = {27},
+  pages = {581-591},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Beckmann1993,
+  author = {A. Beckmann and D. B. Haidvogel},
+  title = {Numerical Simulation of Flow around a Tall Isolated Seamount. Part
+	I - Problem Formulation and Model Accuracy},
+  journal = {Journal of Physical Oceanography},
+  year = {1993},
+  volume = {23},
+  pages = {1736--1753
+	
+	},
+  number = {8},
+  abstract = {A sigma coordinate ocean circulation model is employed to study flow
+	trapped to a tall seamount in a periodic f-plane channel. In Part
+	I, errors arising from the pressure gradient formulation in the steep
+	topography&#47;strong stratification limit are examined. To illustrate
+	the error properties, a linearized adiabatic version of the model
+	is considered, both with and without forcing, and starting from a
+	resting state with level isopycnals. The systematic discretization
+	errors from the horizontal pressure gradient terms are shown analytically
+	to increase with steeper topography (relative to a fixed horizontal
+	grid) and for stronger stratification (as measured by the Burger
+	number). For an initially quiescent unforced ocean, the pressure
+	gradient errors produce a spurious oscillating current that, at the
+	end of 10 days, is approximately 1 cm s&#8722;1 in amplitude. The
+	period of the spurious oscillation (about 0.5 days) is shown to be
+	a consequence of the particular form of the pressure gradient terms
+	in the sigma coordinate system. With the addition of an alongchannel
+	diurnal forcing, resonantly generated seamount-trapped waves are
+	observed to form. Error levels in these solutions are less than those
+	in the unforced cases; spurious time-mean currents are several orders
+	of magnitude less in amplitude than the resonant propagating waves.
+	However, numerical instability is encountered in a wider range of
+	parameter space. The properties of these resonantly generated waves
+	is explored in detail in Part II of this study. Several new formulations
+	of the pressure gradient terms are tested. Two of the formulations&#8212;constructed
+	to have additional conservation properties relative to the traditional
+	form of the pressure gradient terms (conservation of JEBAR and conservation
+	of energy)&#8212;are found to have error properties generally similar
+	to those of the traditional formulation. A corrected gradient algorithm,
+	based upon vertical interpolation of the pressure field, has a dramatically
+	reduced error level but a much more restrictive range of stable behavior.},
+  date = {August 01, 1993},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Blanke1993,
+  author = {B. Blanke and P. Delecluse},
+  title = {Low frequency variability of the tropical Atlantic ocean simulated
+	by a general circulation model with mixed layer physics},
+  journal = JPO,
+  year = {1993},
+  volume = {23},
+  pages = {1363-1388}
+}
+
+@ARTICLE{blanketal97,
+  author = {B. Blanke and J. D. Neelin and D. Gutzler},
+  title = {Estimating the effect of stochastic wind forcing on ENSO irregularity},
+  journal = JC,
+  year = {1997},
+  volume = {10},
+  pages = {1473-1486},
+  abstract = {One open question in El NinoSouthern Oscillation (ENSO) simulation
+	and predictability is the role of random
+	
+	forcing by atmospheric variability with short correlation times, on
+	coupled variability with interannual timescales.
+	
+	The discussion of this question requires a quantitative assessment
+	of the stochastic component of the wind stress
+	
+	forcing. Self-consistent estimates of this noise (the stochastic forcing)
+	can be made quite naturally in an empirical
+	
+	atmospheric model that uses a statistical estimate of the relationship
+	between sea surface temperature (SST) and
+	
+	wind stress anomaly patterns as the deterministic feedback between
+	the ocean and the atmosphere. The authors
+	
+	use such an empirical model as the atmospheric component of a hybrid
+	coupled model, coupled to the GFDL
+	
+	ocean general circulation model. The authors define as residual the
+	fraction of the Florida State University wind
+	
+	stress not explained by the empirical atmosphere run from observed
+	SST, and a noise product is constructed by
+	
+	random picks among monthly maps of this residual.
+	
+	The impact of included or excluded noise is assessed with several
+	ensembles of simulations. The model is
+	
+	run in coupled regimes where, in the absence of noise, it is perfectly
+	periodic: in the presence of prescribed
+	
+	seasonal variability, the model is strongly frequency locked on a
+	2-yr period; in annual average conditions it
+	
+	has a somewhat longer inherent ENSO period (30 months). Addition of
+	noise brings an irregular behavior that
+	
+	is considerably richer in spatial patterns as well as in temporal
+	structures. The broadening of the model ENSO
+	
+	spectral peak is roughly comparable to observed. The tendency to frequency
+	lock to subharmonic resonances
+	
+	of the seasonal cycle tends to increase the broadening and to emphasize
+	lower frequencies. An inclination to
+	
+	phase lock to preferred seasons persists even in the presence of noise-induced
+	irregularity. Natural uncoupled
+	
+	atmospheric variability is thus a strong candidate for explaining
+	the observed aperiodicity in ENSO time series.
+	
+	Modelmodel hindcast experiments also suggest the importance of atmospheric
+	noise in setting limits to ENSO
+	
+	predictability.},
+  pdf = {Blanke_etal_JC97.pdf}
+}
+
+@ARTICLE{Bougeault1989,
+  author = {P. Bougeault and P. Lacarrere},
+  title = {Parameterization of Orography-Induced Turbulence in a Mesobeta--Scale
+	Model},
+  journal = MWR,
+  year = {1989},
+  volume = {117},
+  pages = {1872-1890},
+  number = {8},
+  abstract = {The possibility of extending existing techniques for turbulence parameterization
+	in the planetary boundary layer to attitude, orography-induced turbulence
+	events is examined. Starting from a well-tested scheme, we show that
+	it is possible to generalize the specification method of the length
+	scales, with no deterioration of the scheme performance in the boundary
+	layer. The new scheme is implemented in a two-dimensional version
+	of a limited-area, numerical model used for the simulation of mesobeta-scale
+	atmospheric flows. Three well-known cases of orographically induced
+	turbulence are studied. The comparison with observations and former
+	studies shows a satisfactory behavior of the new scheme.},
+  date = {August 01, 1989},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Brown1978,
+  author = {J. A. Brown and K. A. Campana},
+  title = {An Economical Time-Differencing System for Numerical Weather Prediction},
+  journal = MWR,
+  year = {1978},
+  volume = {106},
+  pages = {1125-1136},
+  number = {8},
+  month = aug,
+  abstract = {A simple method for integrating the primitive equations is presented
+	which allows for a timestep increment up to twice that of the conventional
+	leapfrog scheme. It consists of a time-averaging operator, which
+	incorporates three consecutive time levels, on the pressure gradient
+	terms in the equations of motion. An attractive feature of the method
+	is its case in programming, since the resulting finite-difference
+	equations can he solved explicitly.Presented here are linear analyses
+	of the method applied to the barotropic and two-layer baroclinic
+	gravity waves. Also presented is an analysis of the method with a
+	time-damping device incorporated, which is an alternative in controlling
+	linearly amplifying computational modes.},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Bryan1997,
+  author = {K. Bryan},
+  title = {A Numerical Method for the Study of the Circulation of the World
+	Ocean},
+  journal = JCP,
+  year = {1997},
+  volume = {135, 2},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@ARTICLE{Bryan1984,
+  author = {K. Bryan},
+  title = {Accelerating the convergence to equilibrium of ocean-climate models},
+  journal = JPO,
+  year = {1984},
+  volume = {14},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@ARTICLE{Bryden1973,
+  author = {H. L. Bryden},
+  title = {New polynomials for thermal expansion, adiabatic temperature gradient
+	
+	and potential temperature of sea water},
+  journal = DSR,
+  year = {1973},
+  volume = {20},
+  pages = {401-408},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Campin2004,
+  author = {J.-M. Campin and A. Adcroft and C. Hill and J. Marshall},
+  title = {Conservation of properties in a free-surface model},
+  journal = {Ocean Modelling},
+  year = {2004},
+  volume = {6, 3-4},
+  pages = {221-244},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Cox1987,
+  author = {M. Cox},
+  title = {Isopycnal diffusion in a z-coordinate ocean model},
+  journal = {Ocean Modelling},
+  year = {1987},
+  volume = {74},
+  pages = {1-5},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Dukowicz1994,
+  author = {J. K. Dukowicz and R. D. Smith},
+  title = {Implicit free-surface method for the Bryan-Cox-Semtner ocean model},
+  journal = JGR,
+  year = {1994},
+  volume = {99},
+  pages = {7991-8014},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Dutay.J.C2004,
+  author = {J. -C. Dutay and P. J. -Baptiste and J. -M. Campin and A. Ishida
+	and E. M. -Reimer and R. J. Matear and A. Mouchet and I. J. Totterdell
+	and Y. Yamanaka and K. Rodgers and G. Madec and J.C. Orr},
+  title = {Evaluation of OCMIP-2 ocean models deep circulation
+	
+	with mantle helium-3},
+  journal = {Journal of Marine Systems},
+  year = {2004},
+  pages = {1-22},
+  abstract = {We compare simulations of the injection of mantle helium-3 into the
+	deep ocean from six global coarse resolution models which participated
+	in the Ocean Carbon Model Intercomparison Project (OCMIP). We also
+	discuss the results of a study carried out with one of the models,
+	which examines the effect of the subgrid-scale mixing parameterization.
+	These sensitivity tests provide useful information to interpret the
+	differences among the OCMIP models and between model simulations
+	and the data.
+	
+	We find that the OCMIP models, which parameterize subgrid-scale mixing
+	using an eddy-induced velocity, tend to
+	
+	underestimate the ventilation of the deep ocean, based on diagnostics
+	with d3He. In these models, this parameterization is implemented
+	with a constant thickness diffusivity coefficient. In future simulations,
+	we recommend using such a parameterization with spatially and temporally
+	varying coefficients in order to moderate its effect on stratification.
+	
+	The performance of the models with regard to the formation of AABW
+	confirms the conclusion from a previous evaluation with CFC-11. Models
+	coupled with a sea-ice model produce a substantial bottom water formation
+	in the Southern Ocean that tends to overestimate AABW ventilation,
+	while models that are not coupled with a sea-ice model systematically
+	underestimate the formation of AABW.
+	
+	We also analyze specific features of the deep 3He distribution (3He
+	plumes) that are particularly well depicted in the data and which
+	put severe constraints on the deep circulation. We show that all
+	the models fail to reproduce a correct propagation of these plumes
+	in the deep ocean. The resolution of the models may be too coarse
+	to reproduce the strong and narrow currents in the deep ocean, and
+	the models do not incorporate the geothermal heating that may also
+	contribute to the generation of these currents. We also use the context
+	of OCMIP-2 to explore the potential of mantle helium-3 as a tool
+	to compare and evaluate modeled deep-ocean circulations. Although
+	the source function of mantle helium is known with a rather large
+	uncertainty, we find that the parameterization used for the injection
+	of mantle helium-3 is sufficient to generate realistic results, even
+	in the Atlantic Ocean where a previous pioneering study [J. Geophys.
+	Res. 100 (1995) 3829] claimed this parameterization generates
+	
+	inadequate results. These results are supported by a multi-tracer
+	evaluation performed by considering the simulated distributions of
+	both helium-3 and natural 14C, and comparing the simulated tracer
+	fields with available data.},
+  owner = {sandra},
+  pdf = {Dutay_etal_OCMIP_JMS04.pdf},
+  timestamp = {2006.10.17}
+}
+
+@ARTICLE{Eiseman1980,
+  author = {P. R. Eiseman and A. P. Stone},
+  title = {Conservation lows of fluid dynamics -- A survey},
+  journal = {SIAM Review},
+  year = {1980},
+  volume = {22},
+  pages = {12-27},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@PHDTHESIS{Farge1987,
+  author = {M. Farge},
+  title = {Dynamique non lineaire des ondes et des tourbillons dans les equations
+	de Saint Venant},
+  school = {Doctorat es Mathematiques, Paris VI University, 401 pp.},
+  year = {1987},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Farrow1995,
+  author = {D. E. Farrow and D. P. Stevens},
+  title = {A new tracer advection scheme for Bryan--Cox type ocean general circulation
+	models},
+  journal = JPO,
+  year = {1995},
+  volume = {25},
+  pages = {1731-1741.},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Fujio1991,
+  author = {S. Fujio and N. Imasato},
+  title = {Diagnostic calculation for circulation and water mass movement in
+	the deep Pacific},
+  journal = JGR,
+  year = {1991},
+  volume = {96},
+  pages = {759-774},
+  month = jan,
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Gargett1984,
+  author = {A. E. Gargett},
+  title = {Vertical eddy diffusivity in the ocean interior},
+  journal = JMR,
+  year = {1984},
+  volume = {42},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Gaspar1990,
+  author = {P. Gaspar and Y. Gr{\'e}goris and J.-M. Lefevre},
+  title = {A simple eddy kinetic energy model for simulations of the oceanic
+	vertical mixing\: Tests at Station Papa and long-term upper ocean
+	study site},
+  journal = JGR,
+  year = {1990},
+  volume = {95(C9)},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Gent1990,
+  author = {P. R. Gent and J. C. Mcwilliams},
+  title = {Isopycnal Mixing in Ocean Circulation Models},
+  journal = JPO,
+  year = {1990},
+  volume = {20},
+  pages = {150-155},
+  number = {1},
+  abstract = {A subgrid-scale form for mesoscale eddy mixing on isopycnal surfaces
+	is proposed for use in non-eddy-resolving ocean circulation models.
+	The mixing is applied in isopycnal coordinates to isopycnal layer
+	thickness, or inverse density gradient, as well as to passive scalars,
+	temperature and salinity. The transformation of these mixing forms
+	to physical coordinates is also presented.},
+  date = {January 01, 1990},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Gerdes1993a,
+  author = {R. Gerdes},
+  title = {A primitive equation ocean circulation model using a general vertical
+	coordinate transformation 1. Description and testing of the model},
+  journal = JGR,
+  year = {1993},
+  volume = {98},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Gerdes1993b,
+  author = {R. Gerdes},
+  title = {A primitive equation ocean circulation model using a general vertical
+	coordinate transformation 2. Application to an overflow problem},
+  journal = JGR,
+  year = {1993},
+  volume = {98},
+  pages = {14703-14726},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@BOOK{Gill1982,
+  title = {Atmosphere-Ocean Dynamics},
+  publisher = {International Geophysics Series, Academic Press, New-York},
+  year = {1982},
+  author = {A. E. Gill}
+}
+
+@ARTICLE{Griffes2005,
+  author = {S. M. Griffes and A. Gnanadesikan and K. W. Dixon and J. P. Dunne
+	and R. Gerdes and M. J. Harrison and A. Rosati and J. L. Russell
+	and B. L. Samuels and M. J. Spelman and M. Winton and R. Zhang},
+  title = {Formulation of an ocean model for global climate simulations},
+  journal = OS,
+  year = {2005},
+  pages = {165246},
+  abstract = {This paper summarizes the formulation of the ocean component to the
+	Geophysical
+	
+	Fluid Dynamics Laboratorys (GFDL) coupled climate model used for
+	the 4th IPCC As- Assessment
+	
+	(AR4) of global climate change. In particular, it reviews elements
+	of ocean
+	
+	sessment climate models and how they are pieced together for use in
+	a state-of-the-art coupled 5
+	
+	model. Novel issues are also highlighted, with particular attention
+	given to sensitivity of
+	
+	the coupled simulation to physical parameterizations and numerical
+	methods. Features
+	
+	of the model described here include the following: (1) tripolar grid
+	to resolve the Arctic
+	
+	Ocean without polar filtering, (2) partial bottom step representation
+	of topography to
+	
+	better represent topographically influenced advective and wave processes,
+	(3) more 10
+	
+	accurate equation of state, (4) three-dimensional flux limited tracer
+	advection to reduce
+	
+	overshoots and undershoots, (5) incorporation of regional climatological
+	variability in
+	
+	shortwave penetration, (6) neutral physics parameterization for representation
+	of the
+	
+	pathways of tracer transport, (7) staggered time stepping for tracer
+	conservation and
+	
+	numerical eciency, (8) anisotropic horizontal viscosities for representation
+	of equato- 15
+	
+	rial currents, (9) parameterization of exchange with marginal seas,
+	(10) incorporation
+	
+	of a free surface that accomodates a dynamic ice model and wave propagation,
+	(11)
+	
+	transport of water across the ocean free surface to eliminate unphysical
+	virtual tracer
+	
+	flux methods, (12) parameterization of tidal mixing on continental
+	shelves.},
+  owner = {sandra},
+  pdf = {Griffies_al_OSD05.pdf},
+  timestamp = {2007.01.25}
+}
+
+@BOOK{Griffies2004,
+  title = {Fundamentals of ocean climate models},
+  publisher = {Princeton University Press, 434pp},
+  year = {2004},
+  author = {S. M. Griffies},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Griffies1998,
+  author = {S. M. Griffies and A. Gnanadesikan and R. C. Pacanowski and V. D.
+	Larichev and J. K. Dukowicz and R. D. Smith},
+  title = {Isoneutral Diffusion in a z-Coordinate Ocean Model},
+  journal = JPO,
+  year = {1998},
+  volume = {28},
+  pages = {805-830},
+  number = {5},
+  abstract = {This paper considers the requirements that must be satisfied in order
+	to provide a stable and physically based isoneutral tracer diffusion
+	scheme in a z-coordinate ocean model. Two properties are emphasized:
+	1) downgradient orientation of the diffusive fluxes along the neutral
+	directions and 2) zero isoneutral diffusive flux of locally referenced
+	potential density. It is shown that the Cox diffusion scheme does
+	not respect either of these properties, which provides an explanation
+	for the necessity to add a nontrivial background horizontal diffusion
+	to that scheme. A new isoneutral diffusion scheme is proposed that
+	aims to satisfy the stated properties and is found to require no
+	horizontal background diffusion.},
+  date = {May 01, 1998},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Griffies2001,
+  author = {S. M. Griffies and R. C. Pacanowski and M. Schmidt and V. Balaji},
+  title = {Tracer Conservation with an Explicit Free Surface Method for z-Coordinate
+	Ocean Models},
+  journal = MWR,
+  year = {2001},
+  volume = {129},
+  pages = {1081-1098},
+  number = {5},
+  abstract = {This paper details a free surface method using an explicit time stepping
+	scheme for use in z-coordinate ocean models. One key property that
+	makes the method especially suitable for climate simulations is its
+	very stable numerical time stepping scheme, which allows for the
+	use of a long density time step, as commonly employed with coarse-resolution
+	rigid-lid models. Additionally, the effects of the undulating free
+	surface height are directly incorporated into the baroclinic momentum
+	and tracer equations. The novel issues related to local and global
+	tracer conservation when allowing for the top cell to undulate are
+	the focus of this work. The method presented here is quasi-conservative
+	locally and globally of tracer when the baroclinic and tracer time
+	steps are equal. Important issues relevant for using this method
+	in regional as well as large-scale climate models are discussed and
+	illustrated, and examples of scaling achieved on parallel computers
+	provided.},
+  date = {May 01, 2001},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Guily2001,
+  author = {E. Guilyardi and G. Madec and L. Terray},
+  title = {The role of lateral ocean physics in the upper ocean thermal balance
+	of a coupled ocean-atmosphere GCM},
+  journal = CD,
+  year = {2001},
+  volume = {17},
+  pages = {589-599},
+  number = {8},
+  pdf = {/home/ericg/TeX/Papers/Published_pdfs/Guilyardi_al_CD01.pdf}
+}
+
+@BOOK{Haltiner1980,
+  title = {Numerical prediction and dynamic meteorology},
+  publisher = {John Wiley {\&} Sons Eds., second edition, 477pp},
+  year = {1980},
+  author = {G. J. Haltiner and R. T. Williams},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Haney1991,
+  author = {R. L. Haney},
+  title = {On the Pressure Gradient Force over Steep Topography in Sigma Coordinate
+	Ocean Models},
+  journal = JPO,
+  year = {1991},
+  volume = {21},
+  pages = {610--619
+	
+	},
+  number = {4},
+  abstract = {The error in computing the pressure gradient force near steep topography
+	using terms following (&#963;) coordinates is investigated in an
+	ocean model using the family of vertical differencing schemes proposed
+	by Arakawa and Suarez. The truncation error is estimated by substituting
+	known buoyancy profiles into the finite difference hydrostatic and
+	pressure gradient terms. The error due to &#8220;hydrostatic inconsistency,&#8221;
+	which is not simply a space truncation error, is also documented.
+	The results show that the pressure gradient error is spread throughout
+	the water column, and it is sensitive to the vertical resolution
+	and to the placement of the grid points relative to the vertical
+	structure of the buoyancy field being modeled. Removing a reference
+	state, as suggested for the atmosphere by Gary, reduces the truncation
+	error associated with the two lowest vertical modes by a factor of
+	2 to 3. As an example, the error in computing the pressure gradient
+	using a standard 10-level primitive equation model applied to buoyancy
+	profiles and topographic slopes typical of the California Current
+	region corresponds to a false geostrophic current of the order of
+	10&#8211;12 cm s&#8722;1. The analogous error in a hydrostatically
+	consistent 30-level model with the reference state removed is about
+	an order of magnitude smaller.},
+  date = {April 01, 1991},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Hsu1990,
+  author = {Hsu, Yueh-Jiuan G. and Arakawa, Akio},
+  title = {Numerical Modeling of the Atmosphere with an Isentropic Vertical
+	Coordinate},
+  journal = MWR,
+  year = {1990},
+  volume = {118},
+  pages = {1933--1959
+	
+	},
+  number = {10},
+  abstract = {In constructing a numerical model of the atmosphere, we must choose
+	an appropriate vertical coordinate. Among the various possibilities,
+	isentropic vertical coordinates such as the &#952;-coordinate seem
+	to have the greatest potential, in spite of the technical difficulties
+	in treating the intersections of coordinate surfaces with the lower
+	boundary. The purpose of this paper is to describe the &#952;-coordinate
+	model we have developed and to demonstrate its potential through
+	simulating the nonlinear evolution of a baroclinic wave.In the model
+	we have developed, vertical discretization maintains important integral
+	constraints, such as conservation of the angular momentum and total
+	energy. In treating the intersections of coordinate surfaces with
+	the lower boundary, we have followed the massless-layer approach
+	in which the intersecting coordinate surfaces are extended along
+	the boundary by introducing massless layers. Although this approach
+	formally eliminates the intersection problem, it raises other computational
+	problems. Horizontal discretization of the continuity and momentum
+	equations in the model has been carefully designed to overcome these
+	problems.Selected results from a 10-day integration with the 25-layer,
+	&#946;-plane version of the model are presented. It seems that the
+	model can simulate the nonlinear evolution of a baroclinic wave and
+	associated dynamical processes without major computational difficulties.},
+  date = {October 01, 1990},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{JackMcD1995,
+  author = {D. R. Jackett and T. J. McDougall},
+  title = {Minimal adjustment of hydrographic data to achieve static stability},
+  journal = JAOT,
+  year = {1995},
+  volume = {12},
+  pages = {381-389},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@BOOK{Jerlov1968,
+  title = {Optical Oceanography},
+  publisher = {194pp},
+  year = {1968},
+  author = {N. G. Jerlov},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@INPROCEEDINGS{Killworth1989,
+  author = {P. D. Killworth},
+  title = {On the parameterization of deep convection in ocean models},
+  booktitle = {Parameterization of small-scale processes},
+  year = {1989},
+  editor = {Hawaiian winter workshop},
+  month = {January 17-20},
+  organization = {University of Hawaii at Manoa},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Killworth1991,
+  author = {Killworth, P. D. and Stainforth, D. and Webb, D. J. and Paterson,
+	S. M.},
+  title = {The Development of a Free-Surface Bryan-Cox-Semtner Ocean Model},
+  journal = JPO,
+  year = {1991},
+  volume = {21},
+  pages = {1333--1348},
+  number = {9},
+  abstract = {A version of the Bryan&#8211;Cox&#8211;Semtner numerical ocean general
+	circulation model, adapted to include a free surface, is described.
+	The model is designed for the following uses&#058; tidal studies
+	(a tidal option is explicitly included); assimilation of altimetric
+	data (since the surface elevation is now a prognostic variable);
+	and in situations where accurate relaxation to obtain the streamfunction
+	in the original model is too time consuming. Comparison is made between
+	a 300-year run of the original model and the free-surface version,
+	using a very coarse North Atlantic calculation as the basis. The
+	results are very similar, differing only in the streamfunction over
+	topography; this is to be expected, since the treatment of topographic
+	torques on the barotropic flow differs because of the nature of the
+	modifications.},
+  date = {September 01, 1991},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Kolmogorov1942,
+  author = {A. N. Kolmogorov},
+  title = {The equation of turbulent motion in an incompressible fluid},
+  journal = {Izv. Akad. Nauk SSSR, Ser. Fiz.},
+  year = {1942},
+  volume = {6},
+  pages = {56-58},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@PHDTHESIS{Levy1996,
+  author = {M. L\'{e}vy},
+  title = {Mod\'{e}lisation des processus biog\'{e}ochimiques en M\'{e}diterran\'{e}e
+	nord-occidentale. Cycle saisonnier et variabilit\'{e} m\'{e}so\'{e}chelle},
+  school = {Universit\'{e} Pierre et Marie Curie, Paris, France, 207pp},
+  year = {1996},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Levy2001,
+  author = {M. L\'{e}vy and A. Estubier and G Madec},
+  title = {Choice of an advection scheme for biogeochemical models},
+  journal = GRL,
+  year = {2001},
+  volume = {28},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Levy1998,
+  author = {M. L\'{e}vy and L. M\'{e}mery and G. Madec},
+  title = {The onset of a bloom after deep winter convection in the Northwestern
+	Mediterranean Sea: mesoscale 
+	
+	process study with a primitive equation model},
+  journal = JMS,
+  year = {1998},
+  volume = {16/1-2},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@BOOK{LargeYeager2004,
+  title = {Diurnal to decadal global forcing for ocean and sea-ice models: the
+	data sets and flux climatologies},
+  publisher = {NCAR Technical Note, NCAR/TN-460+STR, CGD Division of the National
+	Center for Atmospheric Research},
+  year = {2004},
+  author = {W. Large and S. Yeager},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{large1994,
+  author = {W. G. Large and J. C. McWilliams and S. C. Doney},
+  title = {Oceanic vertical mixing - a review and a model with a nonlocal boundary
+	layer parameterization},
+  journal = {Reviews of Geophysics},
+  year = {1994},
+  volume = {32},
+  pages = {363-404},
+  doi = {10.1029/94RG01872},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@PHDTHESIS{Lazar1997,
+  author = {A. Lazar},
+  title = {La branche froide de la circulation thermohaline - sensibilit\'{e}
+	\`{a} la diffusion turbulente dans un mod\`{e}le de circulation g\'{e}n\'{e}rale
+	id\'{e}alis\'{e}e},
+  school = {Universit\'{e} Pierre et Marie Curie, Paris, France, 200pp},
+  year = {1997},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Lazar1999,
+  author = {A. Lazar and G. Madec and P. Delecluse},
+  title = {The Deep Interior Downwelling, the Veronis Effect, and Mesoscale
+	Tracer Transport Parameterizations in an OGCM},
+  journal = JPO,
+  year = {1999},
+  volume = {29},
+  pages = {2945-2961},
+  number = {11},
+  abstract = {Numerous numerical simulations of basin-scale ocean circulation display
+	a vast interior downwelling and a companion intense western boundary
+	layer upwelling at midlatitude below the thermocline. These features,
+	related to the so-called Veronis effect, are poorly rationalized
+	and depart strongly from the classical vision of the deep circulation
+	where upwelling is considered to occur in the interior. Furthermore,
+	they significantly alter results of ocean general circulation models
+	(OGCMs) using horizontal Laplacian diffusion. Recently, some studies
+	showed that the parameterization for mesoscale eddy effects formulated
+	by Gent and McWilliams allows integral quantities like the streamfunction
+	and meridional heat transport to be free of these undesired effects.
+	In this paper, an idealized OGCM is used to validate an analytical
+	rationalization of the processes at work and help understand the
+	physics. The results show that the features associated with the Veronis
+	effect can be related quantitatively to three different width scales
+	that characterize the baroclinic structure of the deep western boundary
+	current. In addition, since one of these scales may be smaller than
+	the Munk barotropic layer, usually considered to determine the minimum
+	resolution and horizontal viscosity for numerical models, the authors
+	recommend that it be taken into account. Regarding the introduction
+	of the new parameterization, diagnostics in terms of heat balances
+	underline some interesting similarities between local heat fluxes
+	by eddy-induced velocities and horizontal diffusion at low and midlatitudes
+	when a common large diffusivity (here 2000 m2 s&#8722;1) is used.
+	The near-quasigeostrophic character of the flow explains these results.
+	As a consequence, the response of the Eulerian-mean circulation is
+	locally similar for runs using either of the two parameterizations.
+	However, it is shown that the advective nature of the eddy-induced
+	heat fluxes results in a very different effective circulation, which
+	is the one felt by tracers.},
+  date = {November 01, 1999},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Leonard1991,
+  author = {B. P. Leonard},
+  title = {The ULTIMATE conservative difference scheme applied to unsteady one--dimensional
+	advection},
+  journal = {Computer Methods in Applied Mechanics and Engineering},
+  year = {1991},
+  pages = {17-74},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@TECHREPORT{Leonard1988,
+  author = {B. P. Leonard},
+  title = {Universal limiter for transient interpolation modelling of the advective
+	transport equations},
+  institution = {Technical Memorandum TM-100916 ICOMP-88-11, NASA},
+  year = {1988},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Leonard1979,
+  author = {B. P. Leonard},
+  title = {A stable and accurate convective modelling procedure based on quadratic
+	upstream interpolation},
+  journal = {Computer Methods in Applied Mechanics and Engineering},
+  year = {1979},
+  volume = {19},
+  pages = {59-98},
+  month = jun,
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@TECHREPORT{Levier2007,
+  author = {B. Levier and A.-M. Tr\'{e}guier and G. Madec and V. Garnier},
+  title = {Free surface and variable volume in the NEMO code},
+  institution = {MERSEA MERSEA IP report WP09-CNRS-STR-03-1A, 47pp, available on the
+	NEMO web site},
+  year = {2007},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@BOOK{levitus82,
+  title = {Climatological Atlas of the world ocean},
+  publisher = {NOAA professional paper No. 13, 174pp},
+  year = {1982},
+  author = {S Levitus },
+  note = {173 p.}
+}
+
+@TECHREPORT{Lott1989,
+  author = {F. Lott and G. Madec},
+  title = {Implementation of bottom topography in the Ocean General Circulation
+	Model OPA of the LODYC: formalism and experiments.},
+  institution = {LODYC, France, 36pp.},
+  year = {1989},
+  number = {3},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Lott1990,
+  author = {F. Lott and G. Madec and J. Verron},
+  title = {Topographic experiments in an Ocean General Circulation Model},
+  journal = {Ocean Modelling},
+  year = {1990},
+  volume = {88},
+  pages = {1-4},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@PHDTHESIS{Madec1990,
+  author = {G. Madec},
+  title = {La formation d'eau profonde et son impact sur la circulation r\'{e}gionale
+	en M\'{e}diterran\'{e}e Occidentale - une approche num\'{e}rique},
+  school = {Universit\'{e}Pierre et Marie Curie, Paris,  France, 194pp.},
+  year = {1990},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@ARTICLE{Madec1991a,
+  author = {G. Madec and M. Chartier and M. Cr\'{e}pon},
+  title = {Effect of thermohaline forcing variability on deep water formation
+	in the Northwestern Mediterranean Sea - a high resulution three-dimensional
+	study},
+  journal = DAO,
+  year = {1991},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Madec1991b,
+  author = {G. Madec and M. Chartier and P. Delecluse and M. Cr\'{e}pon},
+  title = {A three-dimensional numerical study of deep water formation in the
+	
+	
+	Northwestern Mediterranean Sea .},
+  journal = JPO,
+  year = {1991},
+  volume = {21},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@INBOOK{Madec1991c,
+  chapter = {Thermohaline-driven deep water formation in the Northwestern Mediterranean
+	Sea},
+  title = {Deep convection and deep water formation in the oceans},
+  publisher = {Elsevier Oceanographic Series},
+  year = {1991},
+  author = {G. Madec and M. Cr\'{e}pon},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Madec1997,
+  author = {G. Madec and P. Delecluse},
+  title = {The OPA/ARPEGE and OPA/LMD Global Ocean-Atmosphere Coupled Model},
+  journal = {Int. WOCE Newsletter},
+  year = {1997},
+  volume = {26},
+  pages = {12-15},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@TECHREPORT{Madec1998,
+  author = {G. Madec and P. Delecluse and M. Imbard and C. Levy},
+  title = {OPA 8 Ocean General Circulation Model - Reference Manual},
+  institution = {LODYC/IPSL Note 11},
+  year = {1998}
+}
+
+@ARTICLE{MadecImb1996,
+  author = {G Madec and M Imbard},
+  title = {A global ocean mesh to overcome the north pole singularity},
+  journal = CD,
+  year = {1996},
+  volume = {12},
+  pages = {381-388}
+}
+
+@ARTICLE{Madec1996,
+  author = {G. Madec and F. Lott and P. Delecluse and M. Cr\'{e}pon},
+  title = {Large-Scale Preconditioning of Deep-Water Formation in the Northwestern
+	Mediterranean Sea},
+  journal = JPO,
+  year = {1996},
+  volume = {26},
+  pages = {1393-1408},
+  number = {8},
+  month = aug,
+  abstract = {The large-scale processes preconditioning the winter deep-water formation
+	in the northwestern Mediterranean Sea are investigated with a primitive
+	equation numerical model where convection is parameterized by a non-penetrative
+	convective adjustment algorithm. The ocean is forced by momentum
+	and buoyancy fluxes that have the gross features of mean winter forcing
+	found in the MEDOC area. The wind-driven barotropic circulation appears
+	to be a major ingredient of the preconditioning phase of deep-water
+	formation. After three months, the ocean response is dominated by
+	a strong barotropic cyclonic vortex located under the forcing area,
+	which fits the Sverdrup balance away from the northern coast. In
+	the vortex center, the whole water column remains trapped under the
+	forcing area all winter. This trapping enables the thermohaline forcing
+	to drive deep-water formation efficiently. Sensitivity studies show
+	that, &#946; effect and bottom topography play a paramount role and
+	confirm that deep convection occurs only in areas that combine a
+	strong surface thermohaline forcing and a weak barotropic advection
+	so that water masses are submitted to the negative buoyancy fluxes
+	for a much longer time. In particular, the impact of the Rh&#244;ne
+	Deep Sea Fan on the barotropic circulation dominates the &#946; effect:
+	the barotropic flow is constrained to follow the bathymetric contours
+	and the cyclonic vortex is shifted southward so that the fluid above
+	the fan remains quiescent. Hence, buoyancy fluxes trigger deep convection
+	above the fan in agreement with observations. The selection of the
+	area of deep-water formation through the defection of the barotropic
+	circulation by the topography seems a more efficient mechanism than
+	those associated with the wind- driven barotropic vortex. This is
+	due to its permanency, while the latter may be too sensitive to time
+	and space variations of the forcing.},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Madec1988,
+  author = {G. Madec and C. Rahier and M. Chartier},
+  title = {A comparison of two-dimensional elliptic solvers for the barotropic
+	streamfunction in a multilevel OGCM},
+  journal = {Ocean Modelling},
+  year = {1988},
+  volume = {78},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@ARTICLE{Maltrud1998,
+  author = {M. E. Maltrud and R. D. Smith and A. J. Semtner and R. C. Malone},
+  title = {Global eddy-resolving ocean simulations driven by 1985-1995 atmospheric
+	winds},
+  journal = JGR,
+  year = {1998},
+  volume = {103(C13)},
+  pages = {30,825-30,854},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@PHDTHESIS{MartiTh1992,
+  author = {O. Marti},
+  title = {Etude de l'oc\'{e}an mondial : mod\'{e}lisation de la circulation
+	et du transport de traceurs anthropog\'{e}niques},
+  school = {Universit\'{e} Pierre et Marie Curie, Paris, France, 201pp},
+  year = {1992},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Marti1992,
+  author = {O. Marti and G. Madec and P. Delecluse},
+  title = {Comment on "Net diffusivity in ocean general circulation models with
+	nonuniform grids" by F. L. Yin and I. Y. Fung},
+  journal = JGR,
+  year = {1992},
+  volume = {97},
+  pages = {12763-12766},
+  month = aug,
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{McDougall1987,
+  author = {T. J. McDougall},
+  title = {Neutral Surfaces},
+  journal = {Journal of Physical Oceanography},
+  year = {1987},
+  volume = {17},
+  pages = {1950-1964},
+  number = {11},
+  abstract = {Scalar properties in the ocean are stirred (and subsequently mixed)
+	rather efficiently by mesoscale eddies and two-dimensional turbulence
+	along &#8220;neutral surfaces&#8221;, defined such that when water
+	parcels are moved small distances in the neutral surface, they experience
+	no buoyant restoring forces. By contrast, work would have to be done
+	on a moving fluid parcel in order to keep it on a potential density
+	surface. The differences between neutral surfaces and potential density
+	surfaces are due to the variation of &#945;&#47;&#946; with pressure
+	(where &#945; is the thermal expansion coefficient and &#946; is
+	the saline contraction coefficient). By regarding the equation of
+	state of seawater as a function of salinity, potential temperature,
+	and pressure, rather than in terms of salinity, temperature, and
+	pressure, it is possible to quantify the differences between neutral
+	surfaces and potential density surfaces. In particular, the spatial
+	gradients of scalar properties (e.g., S, &#952;, tritium or potential
+	vorticity) on a neutral surface can be quite different to the corresponding
+	gradients in a potential density surface. For example, at a potential
+	temperature of 4&#176;C and a pressure of 1000 db, the lateral gradient
+	of potential temperature in a potential density surface (referenced
+	to sea level) is too large by between 50&#37; and 350&#37; (depending
+	on the stability ratio Rp of the water column) compared with the
+	physically relevant gradient of potential temperature on the neutral
+	surface. Three-examples of neutral surfaces are presented, based
+	on the Levitus atlas of the North Atlantic.},
+  date = {November 01, 1987},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Merryfield1999,
+  author = {W. J. Merryfield and G. Holloway and A. E. Gargett},
+  title = {A Global Ocean Model with Double-Diffusive Mixing},
+  journal = JPO,
+  year = {1999},
+  volume = {29},
+  pages = {1124-1142},
+  number = {6},
+  abstract = {A global ocean model is described in which parameterizations of diapycnal
+	mixing by double-diffusive fingering and layering are added to a
+	stability-dependent background turbulent diffusivity. Model runs
+	with and without double-diffusive mixing are compared for annual-mean
+	and seasonally varying surface forcing. Sensitivity to different
+	double-diffusive mixing parameterizations is considered. In all cases,
+	the locales and extent of salt fingering (as diagnosed from buoyancy
+	ratio R&#961;) are grossly comparable to climatology, although fingering
+	in the models tends to be less intense than observed. Double-diffusive
+	mixing leads to relatively minor changes in circulation but exerts
+	significant regional influences on temperature and salinity.},
+  date = {June 01, 1999},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Murray1996,
+  author = {R. J. Murray},
+  title = {Explicit Generation of Orthogonal Grids for Ocean Models},
+  journal = JCP,
+  year = {1996},
+  volume = {126},
+  pages = {251-273},
+  number = {2},
+  month = {July},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@PHDTHESIS{OlivierPh2001,
+  author = {F. Olivier},
+  title = {Etude de l'activit\'{e} biologique et de la circulation oc\'{e}anique
+	dans un jet g\'{e}ostrophique: le front Alm\'{e}ria-Oran},
+  school = {Universit\'{e} Pierre et Marie Curie, Paris, France},
+  year = {2001},
+  owner = {gm},
+  timestamp = {2007.08.14}
+}
+
+@ARTICLE{PacPhil1981,
+  author = {R.C. Pacanowski and S.G.H. Philander},
+  title = {Parameterization of Vertical Mixing in Numerical Models of Tropical
+	Oceans},
+  journal = JPO,
+  year = {1981},
+  volume = {11},
+  pages = {1443-1451},
+  number = {11},
+  abstract = {Measurements indicate that mixing processes are intense in the surface
+	layers of the ocean but weak below the thermocline, except for the
+	region below the core of the Equatorial Undercurrent where vertical
+	temperature gradients are small and the shear is large. Parameterization
+	of these mixing processes by means of coefficients of eddy mixing
+	that are Richardson-number dependent, leads to realistic simulations
+	of the response of the equatorial oceans to different windstress
+	patterns. In the case of eastward winds results agree well with measurements
+	in the Indian Ocean. In the case of westward winds it is of paramount
+	importance that the nonzero heat flux into the ocean be taken into
+	account. This beat flux stabilizes the upper layers and reduces the
+	intensity of the mixing, especially in the cast. With an appropriate
+	surface boundary condition, the results are relatively insensitive
+	to values assigned to constants in the parameterization formula.},
+  date = {November 01, 1981},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Paulson1977,
+  author = {C. A. Paulson and J. J. Simpson},
+  title = {Irradiance Measurements in the Upper Ocean},
+  journal = JPO,
+  year = {1977},
+  volume = {7},
+  pages = {952-956},
+  number = {6},
+  abstract = {Observations were made of downward solar radiation as a function of
+	depth during an experiment in the North Pacific (35&#176;N, 155&#176;W).
+	The irradiance meter employed was sensitive to solar radiation of
+	wavelength 400&#8211;1000 nm arriving from above at a horizontal
+	surface. Because of selective absorption of the short and long wavelengths,
+	the irradiance decreases much faster than exponential in the upper
+	few meters, falling to one-third of the incident value between 2
+	and 3 m depth. Below 10 m the decrease was exponential at a rate
+	characteristic of moderately clear water of Type IA. Neglecting one
+	case having low sun altitude, the observations are well represented
+	by the expression I&#47;I0&#61;Rez&#47;&#950;1&#43;(1&#8722;R)ez&#950;2,
+	where I is the irradiance at depth &#8722;z, I0 is the irradiance
+	at the surface less reflected solar radiation, R&#61;0.62, &#950;1
+	and &#950;2 are attenuation lengths equal to 1.5 and 20 m, respectively,
+	and z is the vertical space coordinate, positive upward with the
+	origin at mean sea level. The depth at which the irradiance falls
+	to 10&#37; of its surface value is nearly the same as observations
+	of Secchi depth when cases with high wind speed or low solar altitude
+	are neglected. Parameters R, &#950;1, and &#950;2 are computed for
+	the entire range of oceanic water types.},
+  date = {November 01, 1977},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Phillips1959,
+  author = {R. S.  Phillips},
+  title = {Dissipative Operators and Hyperbolic Systems of Partial Differential
+	Equations},
+  journal = {Transactions of the American Mathematical Society},
+  year = {1959},
+  volume = {90(2)},
+  pages = {193-254},
+  doi = {doi:10.2307/1993202},
+  owner = {gm},
+  timestamp = {2007.08.10}
+}
+
+@ARTICLE{Reverdin1991,
+  author = {G. Reverdin and P. Delecluse and C. L\'{e}vy and P. Andrich and A.
+	Morli\`{e}re and J. M. Verstraete},
+  title = {The near surface tropical Atlantic in 1982-1984 : results from a
+	numerical simulation and a data analysis},
+  journal = PO,
+  year = {1991},
+  volume = {27},
+  pages = {273-340},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@BOOK{Richtmyer1967,
+  title = {Difference methods for initial-value problems},
+  publisher = {Interscience Publisher, Second Edition, 405pp},
+  year = {1967},
+  author = {R. D. Richtmyer and K. W. Morton},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Robert1966,
+  author = {A. J. Robert},
+  title = {The integration of a Low order spectral form of the primitive meteorological
+	equations},
+  journal = {J. Meteo. Soc. Japan},
+  year = {1966},
+  volume = {44, 2},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Roullet2000,
+  author = {G. Roullet and G. Madec},
+  title = {salt conservation, free surface, and varying levels: a new formulation
+	for ocean general circulation models},
+  journal = JGR,
+  year = {2000},
+  volume = {105},
+  pages = {23,927-23,942},
+  owner = {sandra},
+  pdf = {Roullet_Madec_JGR00.pdf},
+  timestamp = {2007.03.22}
+}
+
+@ARTICLE{Sadourny1975,
+  author = {R. Sadourny},
+  title = {The Dynamics of Finite-Difference Models of the Shallow-Water Equations},
+  journal = JAS,
+  year = {1975},
+  volume = {32},
+  pages = {680-689},
+  number = {4},
+  abstract = {Two simple numerical models of the shallow-water equations identical
+	in all respects but for their con-servation properties have been
+	tested regarding their internal mixing processes. The experiments
+	show that violation of enstrophy conservation results in a spurious
+	accumulation of rotational energy in the smaller scales, reflected
+	by an unrealistic increase of enstrophy, which ultimately produces
+	a finite rate of energy dissipation in the zero viscosity limit,
+	thus violating the well-known dynamics of two-dimensional flow. Further,
+	the experiments show a tendency to equipartition of the kinetic energy
+	of the divergent part of the flow in the inviscid limit, suggesting
+	the possibility of a divergent energy cascade in the physical system,
+	as well as a possible influence of the energy mixing on the process
+	of adjustment toward balanced flow.},
+  date = {April 01, 1975},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Sarmiento1982,
+  author = {J. L. Sarmiento and K. Bryan},
+  title = {Ocean transport model for the North Atlantic},
+  journal = JGR,
+  year = {1982},
+  volume = {87},
+  pages = {394-409},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Sacha2005,
+  author = {A. F. Shchepetkin and J. C. McWilliams},
+  title = {The regional oceanic modeling system (ROMS) - a split-explicit, free-surface,
+	topography-following-coordinate oceanic modelr},
+  journal = {Ocean Modelling},
+  year = {2005},
+  volume = {9, 4},
+  pages = {347-404},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Sacha2003,
+  author = {A. F. Shchepetkin and J. C. McWilliams},
+  title = {A method for computing horizontal pressure-gradient force in an oceanic
+	model with a nonaligned 
+	
+	vertical coordinate},
+  journal = JGR,
+  year = {2003},
+  volume = {108(C3)},
+  pages = {3090, doi:10.1029/2001JC001047},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Shchepetkin1996,
+  author = {A. F. Shchepetkin and J. J. O'Brien},
+  title = {A Physically Consistent Formulation of Lateral Friction in Shallow-Water
+	Equation Ocean Models},
+  journal = MWR,
+  year = {1996},
+  volume = {124},
+  pages = {1285-1300},
+  number = {6},
+  abstract = {Dissipation in numerical ocean models has two purposes: to simulate
+	processes in which the friction is physically relevant and to prevent
+	numerical instability by suppressing accumulation of energy in the
+	smallest resolved scales. This study shows that even for the latter
+	case the form of the friction term should be chosen in a physically
+	consistent way. Violation of fundamental physical principles reduces
+	the fidelity of the numerical solution, even if the friction is small.
+	Several forms of the lateral friction, commonly used in numerical
+	ocean models, are discussed in the context of shallow-water equations
+	with nonuniform layer thickness. It is shown that in a numerical
+	model tuned for the minimal dissipation, the improper form of the
+	friction term creates finite artificial vorticity sources that do
+	not vanish with increased resolution, even if the viscous coefficient
+	is reduced consistently with resolution. An alternative numerical
+	implementation of the no-slip boundary conditions for an arbitrary
+	coast line is considered. It was found that the quality of the numerical
+	solution may be considerably improved by discretization of the viscous
+	stress tensor in such a way that the numerical boundary scheme approximates
+	not only the stress tensor to a certain order of accuracy but also
+	simulates the truncation error of the numerical scheme used in the
+	interior of the domain. This ensures error cancellation during subsequent
+	use of the elements of the tensor in the discrete version of the
+	momentum equations, allowing for approximation of them without decrease
+	in the order of accuracy near the boundary.},
+  date = {June 01, 1996},
+  owner = {gm},
+  timestamp = {2007.08.14}
+}
+
+@ARTICLE{Simmons2003,
+  author = {H. L. Simmons and S. R. Jayne and L. C. St. Laurent and A. J. Weaver},
+  title = {Tidally driven mixing in a numerical model of the
+	
+	ocean general circulation},
+  journal = OM,
+  year = {2003},
+  pages = {1-19},
+  abstract = {Astronomical data reveals that approximately 3.5 terawatts (TW) of
+	tidal energy is dissipated in the
+	
+	ocean. Tidal models and satellite altimetry suggest that 1 TW of this
+	energy is converted from the barotropic
+	
+	to internal tides in the deep ocean, predominantly around regions
+	of rough topography such as midocean
+	
+	ridges. Aglobal tidal model is used to compute turbulent energy levels
+	associated with the dissipation
+	
+	of internal tides, and the diapycnal mixing supported by this energy
+	?ux is computed using a simple parameterization.
+	
+	The mixing parameterization has been incorporated into a coarse resolution
+	numerical model of the
+	
+	global ocean. This parameterization o?ers an energetically consistent
+	and practical means of improving the
+	
+	representation of ocean mixing processes in climate models. Novel
+	features of this implementation are that
+	
+	the model explicitly accounts for the tidal energy source for mixing,
+	and that the mixing evolves both
+	
+	spatially and temporally with the model state. At equilibrium, the
+	globally averaged di?usivity pro?le
+	
+	ranges from 0.3 cm2 s1 at thermocline depths to 7.7 cm2 s1 in the
+	abyss with a depth average of 0.9
+	
+	cm2 s1, in close agreement with inferences from global balances.
+	Water properties are strongly in?uenced
+	
+	by the combination of weak mixing in the main thermocline and enhanced
+	mixing in the deep ocean.
+	
+	Climatological comparisons show that the parameterized mixing scheme
+	results in a substantial reduction},
+  owner = {sandra},
+  pdf = {Simmons_mixing_OM2003.pdf},
+  timestamp = {2007.03.22}
+}
+
+@ARTICLE{Song1994,
+  author = {Y. Song and D. Haidvogel},
+  title = {A Semi-implicit Ocean Circulation Model Using a Generalized Topography-Following
+	Coordinate System
+	
+	Authors:},
+  journal = JCP,
+  year = {1994},
+  volume = {115, 1},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Song1998,
+  author = {Y. T. Song},
+  title = {A General Pressure Gradient Formulation for Ocean Models. Part I:
+	Scheme Design and Diagnostic Analysis},
+  journal = MWR,
+  year = {1998},
+  volume = {126},
+  pages = {3213-3230},
+  number = {12},
+  abstract = {A Jacobian formulation of the pressure gradient force for use in models
+	with topography-following coordinates is proposed. It can be used
+	in conjunction with any vertical coordinate system and is easily
+	implemented. Vertical variations in the pressure gradient are expressed
+	in terms of a vertical integral of the Jacobian of density and depth
+	with respect to the vertical computational coordinate. Finite difference
+	approximations are made on the density field, consistent with piecewise
+	linear and continuous fields, and accurate pressure gradients are
+	obtained by vertically integrating the discrete Jacobian from sea
+	surface.Two discrete schemes are derived and examined in detail:
+	the first using standard centered differencing in the generalized
+	vertical coordinate and the second using a vertical weighting such
+	that the finite differences are centered with respect to the Cartesian
+	z coordinate. Both schemes achieve second-order accuracy for any
+	vertical coordinate system and are significantly more accurate than
+	conventional schemes based on estimating the pressure gradients by
+	finite differencing a previously determined pressure field.The standard
+	Jacobian formulation is constructed to give exact pressure gradient
+	results, independent of the bottom topography, if the buoyancy field
+	varies bilinearly with horizontal position, x, and the generalized
+	vertical coordinate, s, over each grid cell. Similarly, the weighted
+	Jacobian scheme is designed to achieve exact results, when the buoyancy
+	field varies linearly with z and arbitrarily with x, that is, b(x,z)
+	&#61; b0(x) &#43; b1(x)z.When horizontal resolution cannot be made
+	fine enough to avoid hydrostatic inconsistency, errors can be substantially
+	reduced by the choice of an appropriate vertical coordinate. Tests
+	with horizontally uniform, vertically varying, and with horizontally
+	and vertically varying buoyancy fields show that the standard Jacobian
+	formulation achieves superior results when the condition for hydrostatic
+	consistency is satisfied, but when coarse horizontal resolution causes
+	this condition to be strongly violated, the weighted Jacobian may
+	give superior results.},
+  date = {December 01, 1998},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{SongWright1998,
+  author = {Y. T. Song and D. G. Wright},
+  title = {A General Pressure Gradient Formulation for Ocean Models. Part II
+	- Energy, Momentum, and Bottom Torque Consistency},
+  journal = MWR,
+  year = {1998},
+  volume = {126},
+  pages = {3231-3247},
+  number = {12},
+  abstract = {A new formulation of the pressure gradient force for use in models
+	with topography-following coordinates is proposed and diagnostically
+	analyzed in Part I. Here, it is shown that important properties of
+	the continuous equations are retained by the resulting numerical
+	schemes, and their performance in prognostic simulations is examined.
+	Numerical consistency is investigated with respect to global energy
+	conservation, depth-integrated momentum changes, and the representation
+	of the bottom pressure torque. The performances of the numerical
+	schemes are tested in prognostic integrations of an ocean model to
+	demonstrate numerical accuracy and long-term integral stability.
+	Two typical geometries, an isolated tall seamount and an unforced
+	basin with sloping boundaries, are considered for the special case
+	of no external forcing and horizontal isopycnals to test numerical
+	accuracy. These test problems confirm that the proposed schemes yield
+	accurate approximations to the pressure gradient force. Integral
+	consistency conditions are verified and the energetics of the &#8220;advective
+	elimination&#8221; of the pressure gradient error (Mellor et al)
+	is considered.A large-scale wind-driven basin with and without topography
+	is used to test the model&#8217;s long-term integral performance
+	and the effects of bottom pressure torque on the transport in western
+	boundary currents. Integrations are carried out for 10 years in each
+	case and results show that the schemes are stable, and the steep
+	topography causes no obvious numerical problems. A realistic meandering
+	western boundary current is well developed with detached cold cyclonic
+	and warm anticyclonic eddies as it extends across the basin. In addition,
+	the results with topography show earlier separation and enhanced
+	transport in the western boundary currents due to the bottom pressure
+	torque.},
+  date = {December 01, 1998},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@PHDTHESIS{Speich1992,
+  author = {S. Speich},
+  title = {Etude du for\c{c}age de la circulation g\'{e}n\'{e}rale oc\'{e}anique
+	par les d\'{e}troits - cas de la mer d'Alboran},
+  school = {Universit\'{e} Pierre et Marie Curie, Paris, France},
+  year = {1992},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Speich1996,
+  author = {S. Speich and G. Madec and M. Cr\'{e}pon},
+  title = {The circulation in the Alboran Sea - a sensitivity study},
+  journal = JPO,
+  year = {1996},
+  volume = {26},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Steele2001,
+  author = {M. Steele and R. Morley and W. Ermold},
+  title = {PHC- A Global Ocean Hydrography with a High-Quality Arctic Ocean},
+  journal = {Journal of Climate},
+  year = {2001},
+  volume = {14},
+  pages = {2079--2087
+	
+	},
+  number = {9},
+  abstract = {A new gridded ocean climatology, the Polar Science Center Hydrographic
+	Climatology (PHC), has been created that merges the 1998 version
+	of the World Ocean Atlas with the new regional Arctic Ocean Atlas.
+	The result is a global climatology for temperature and salinity that
+	contains a good description of the Arctic Ocean and its environs.
+	Monthly, seasonal, and annual average products have been generated.
+	How the original datasets were prepared for merging, how the optimal
+	interpolation procedure was performed, and characteristics of the
+	resulting dataset are discussed, followed by a summary and discussion
+	of future plans.},
+  date = {May 01, 2001},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Stein1992,
+  author = {C. A. Stein and S. Stein},
+  title = {A model for the global variation in oceanic depth and heat flow with
+	lithospheric age},
+  journal = {Nature},
+  year = {1992},
+  volume = {359},
+  pages = {123-129},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Thiem2006,
+  author = {O. Thiem and J. Berntsen},
+  title = {Internal pressure errors in sigma-coordinate ocean models due to
+	anisotropy},
+  journal = {Ocean Modelling},
+  year = {2006},
+  volume = {12, 1-2},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@ARTICLE{Treguier1996,
+  author = {A.-M. Tr\'{e}guier and J. Dukowicz and K. Bryan},
+  title = {Properties of nonuniform grids used in ocean general circulation
+	models},
+  journal = JGR,
+  year = {1996},
+  volume = {101},
+  pages = {20877-20881},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@ARTICLE{Treguier1997,
+  author = {A. M. Tr\'{e}guier and I. M. Held and V. D. Larichev},
+  title = {Parameterization of Quasigeostrophic Eddies in Primitive Equation
+	Ocean Models},
+  journal = JPO,
+  year = {1997},
+  volume = {27},
+  pages = {567-580},
+  number = {4},
+  abstract = {A parameterization of mesoscale eddy fluxes in the ocean should be
+	consistent with the fact that the ocean interior is nearly adiabatic.
+	Gent and McWilliams have described a framework in which this can
+	be approximated in z-coordinate primitive equation models by incorporating
+	the effects of eddies on the buoyancy field through an eddy-induced
+	velocity. It is also natural to base a parameterization on the simple
+	picture of the mixing of potential vorticity in the interior and
+	the mixing of buoyancy at the surface. The authors discuss the various
+	constraints imposed by these two requirements and attempt to clarify
+	the appropriate boundary conditions on the eddy-induced velocities
+	at the surface. Quasigeostrophic theory is used as a guide to the
+	simplest way of satisfying these constraints.},
+  date = {April 01, 1997},
+  owner = {gm},
+  timestamp = {2007.08.03}
+}
+
+@BOOK{UNESCO1983,
+  title = {Algorithms for computation of fundamental property of sea water},
+  publisher = {Techn. Paper in Mar. Sci, 44, UNESCO},
+  year = {1983},
+  author = {UNESCO},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@TECHREPORT{OASIS2006,
+  author = {S. Valcke},
+  title = {OASIS3 User Guide (prism\_2-5)},
+  institution = {PRISM Support Initiative Report No 3, CERFACS, Toulouse, France,
+	64 pp},
+  year = {2006},
+  owner = {gm},
+  timestamp = {2007.08.05}
+}
+
+@TECHREPORT{valal00,
+  author = {S. Valcke and L. Terray and A. Piacentini },
+  title = {The OASIS Coupled User Guide Version 2.4},
+  institution = {CERFACS},
+  year = {2000},
+  number = {TR/CMGC/00-10}
+}
+
+@ARTICLE{Weatherly1984,
+  author = {G. L. Weatherly},
+  title = {An estimate of bottom frictional dissipation by Gulf Stream fluctuations},
+  journal = JMR,
+  year = {1984},
+  volume = {42, 2},
+  pages = {289-301},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Weaver1997,
+  author = {A. J. Weaver and M. Eby},
+  title = {On the numerical implementation of advection schemes for use in conjuction
+	with various mixing 
+	
+	parameterizations in the GFDL ocean model},
+  journal = JPO,
+  year = {1997},
+  volume = {27},
+  owner = {gm},
+  timestamp = {2007.08.06}
+}
+
+@ARTICLE{Webb1998,
+  author = {D. J. Webb and B. A. de Cuevas and C. S. Richmond},
+  title = {Improved Advection Schemes for Ocean Models},
+  journal = JAOT,
+  year = {1998},
+  volume = {15},
+  pages = {1171-1187},
+  number = {5},
+  abstract = {Leonard&#8217;s widely used QUICK advection scheme is, like the Bryan&#8211;Cox&#8211;Semtner
+	ocean model, based on a control volume form of the advection equation.
+	Unfortunately, in its normal form it cannot be used with the leapfrog&#8211;Euler
+	forward time-stepping schemes used by the ocean model. Farrow and
+	Stevens overcame the problem by implementing a predictor&#8211;corrector
+	time-stepping scheme, but this is computationally expensive to run.
+	The present paper shows that the problem can be overcome by splitting
+	the QUICK operator into an O(&#948;x2) advective term and a velocity
+	dependent biharmonic diffusion term. These can then be time-stepped
+	using the combined leapfrog and Euler forward schemes of the Bryan&#8211;Cox&#8211;Semtner
+	ocean model, leading to a significant increase in model efficiency.
+	A small change in the advection operator coefficients may also be
+	made leading to O(&#948;x4) accuracy. Tests of the improved schemes
+	are carried out making use of a global eddy-permitting ocean model.
+	Results are presented from cases where the schemes were applied to
+	only the tracer fields and also from cases where they were applied
+	to both the tracer and velocity fields. It is found that the new
+	schemes have the most effect in the western boundary current regions,
+	where, for example, the warm core of the Agulhas Current is no longer
+	broken up by numerical noise.},
+  date = {October 01, 1998},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Willebrand2001,
+  author = {J. Willebrand and B. Barnier and C. Boning and C. Dieterich and P.
+	D. Killworth and C. Le Provost and Y. Jia and J.-M. Molines and A.
+	L. New},
+  title = {Circulation characteristics in three eddy-permitting models of the
+	North Atlantic},
+  journal = {Progress in Oceanography},
+  year = {2001},
+  volume = {48, 2},
+  pages = {123-161},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Zalesak1979,
+  author = {S. T. Zalesak},
+  title = {Fully multidimensional flux corrected transport algorithms for fluids},
+  journal = JCP,
+  year = {1979},
+  volume = {31},
+  owner = {gm},
+  timestamp = {2007.08.04}
+}
+
+@ARTICLE{Zhang1992,
+  author = {Zhang, R.-H. and Endoh, M.},
+  title = {A free surface general circulation model for the tropical Pacific
+	Ocean},
+  journal = JGR,
+  year = {1992},
+  volume = {97},
+  pages = {11237-11255},
+  month = jul,
+  owner = {gm}
+}
+
+@INBOOK{Delecluse2000,
+  chapter = {Ocean modelling and the role of the ocean in the climate system},
+  pages = {237-313},
+  title = {Modeling the Earth's Climate and its Variability, Les Houches, Session
+	LXVII 1997},
+  year = {2000},
+  editor = {W. R. Holland and  S. Jaussaume and F. David},
+  owner = {gm},
+  timestamp = {2007.08.17}
+}
+
+@comment{jabref-meta: groupsversion:3;}
+
+@comment{jabref-meta: groupstree:
+0 AllEntriesGroup:;
+1 ExplicitGroup:El Nino\;2\;blanketal97\;;
+2 ExplicitGroup:97/98 event\;0\;;
+2 ExplicitGroup:Forecast\;0\;;
+2 ExplicitGroup:GHG change\;0\;;
+2 ExplicitGroup:in GCMs\;0\;;
+2 ExplicitGroup:in MIPs\;0\;;
+2 ExplicitGroup:momentum balance\;0\;;
+2 ExplicitGroup:Obs analysis\;0\;;
+2 ExplicitGroup:Paleo\;0\;;
+2 ExplicitGroup:Previous events\;0\;;
+2 ExplicitGroup:Reviews\;0\;;
+2 ExplicitGroup:Simple models\;0\;Zhang1992\;;
+2 ExplicitGroup:SPL, SC, mean\;0\;;
+2 ExplicitGroup:Teleconnections\;0\;;
+2 ExplicitGroup:Low freq\;0\;;
+2 ExplicitGroup:Theory\;0\;;
+2 ExplicitGroup:Energetics\;0\;;
+1 ExplicitGroup:Diurnal in tropics\;0\;;
+1 ExplicitGroup:Indian\;0\;;
+1 ExplicitGroup:Atlantic\;0\;;
+1 ExplicitGroup:MJO, IO, TIW\;2\;;
+2 ExplicitGroup:Obs\;0\;;
+2 ExplicitGroup:GCM\;0\;;
+2 ExplicitGroup:Mechanims\;0\;;
+2 ExplicitGroup:TIW\;0\;;
+1 ExplicitGroup:Observations\;2\;;
+2 ExplicitGroup:ERBE\;0\;;
+2 ExplicitGroup:Tropical\;0\;;
+2 ExplicitGroup:Global\;0\;;
+2 ExplicitGroup:Clouds\;0\;;
+2 ExplicitGroup:Scale interactions\;0\;;
+1 ExplicitGroup:Mechanisms\;2\;;
+2 ExplicitGroup:CRF\;0\;;
+2 ExplicitGroup:Water vapor\;0\;;
+2 ExplicitGroup:Atmos mechanisms\;0\;;
+1 ExplicitGroup:GCMs\;2\;;
+2 ExplicitGroup:Uncertainty\;0\;;
+2 ExplicitGroup:Momentum balance\;0\;;
+1 ExplicitGroup:Climate change\;0\;;
+2 ExplicitGroup:IPCC AR4\;0\;;
+1 ExplicitGroup:Analysis tools\;0\;;
+1 KeywordGroup:EG publis\;0\;author\;guilyardi\;0\;0\;;
+}
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/0_page_de_garde_old.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/0_page_de_garde_old.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/0_page_de_garde_old.tex	(revision 4536)
@@ -0,0 +1,317 @@
+%\begin{figure}[htbp]
+%\centerline{\includegraphics[width=1.64in,height=11.72in]{OPA9_Chap_0_Introduction1.eps}}
+%\label{fig1}
+%\end{figure}
+
+\textbf{Institut Pierre Simon Laplace}
+
+\textbf{des Sciences de l'Environnement Global}
+
+\textit{Notes du P\^{o}le de Mod\'{e}lisation}
+
+NEMO : the OPA ocean engine
+
+(NEMO version 2.3)
+
+Gurvan Madec, {\ldots} 
+
+Laboratoire d'Oc\'{e}anographie et du Climat: Exp\'{e}rimentation 
+
+et Approches Num\'{e}riques
+
+%\begin{figure}[htbp]
+%\centerline{\includegraphics[width=4.58in,height=4.35in]{OPA9_Chap_0_Introduction2.eps}}
+%\label{fig2}
+%\end{figure}
+
+\newpage 
+\begin{center}
+NEMO : the OPA ocean engine
+\end{center}
+
+Gurvan Madec
+
+Laboratoire d'Oc\'{e}anographie et du Climat: Exp\'{e}rimentation Approches 
+Num\'{e}riques
+
+CNRS/IRD/UPMC, UMR 7617
+
+\subsection{Abstract}
+\label{subsec:abstract}
+OPA is the ocean engine of NEMO, a framework of ocean related components 
+developed for both research and operational purposes. It is a primitive 
+equation model adapted to regional and global ocean circulation. It is 
+intended to be a flexible tool for studying the ocean and its interactions 
+with the others components of the earth climate system (atmosphere, sea-ice, 
+biogeochemical tracers, ...) over a wide range of space and time scales. 
+Prognostic variables are the three-dimensional velocity field, the sea 
+surface height, the temperature and the salinity. In the horizontal 
+direction, the model uses a curvilinear orthogonal grid and in the vertical 
+direction, a $z$ full or partial step coordinate, or $s$-coordinate, or a mixture 
+of the two. The distribution of variables is a three-dimensional Arakawa 
+C-type grid. Various physical choices are available to describe ocean 
+physics, including a 1.5 turbulent closure or a KPP scheme for the vertical 
+mixing. Within NEMO, OPA is interfaced with a sea-ice model (LIM), passive 
+tracer and biogeochemical models (TOP) and, via the OASIS coupler, with 
+several atmospheric general circulation models. In addition, it can be run 
+on many different computers, including shared and distributed memory 
+multiprocessor computers.
+
+\textsc{\textbf{R\'{e}sum\'{e}}}
+
+OPA est le moteur oc\'{e}anique de NEMO, un syst\`{e}me de mod\'{e}lisation 
+de l'oc\'{e}an d\'{e}velopp\'{e} \`{a} des fins de recherche et 
+d'oc\'{e}anographie op\'{e}rationnelle. Ce moteur est un mod\`{e}le aux 
+\'{e}quations primitives de la circulation oc\'{e}anique r\'{e}gionale et 
+globale. Il se veut un outil flexible pour \'{e}tudier sur un vaste spectre 
+spatiotemporel l'oc\'{e}an et ses interactions avec les autres composantes 
+du syst\`{e}me climatique terrestre (atmosph\`{e}re, glace de mer, traceurs 
+biog\'{e}ochimiques...). Les variables pronostiques sont le champ 
+tridimensionnel de vitesse, la hauteur de la mer , la temperature et la 
+salinit\'{e}. La distribution des variables se fait sur une grille $C$ 
+d'Arakawa tridimensionnelle utilisant une coordonn\'{e}e verticale $z$ \`{a} 
+niveaux entiers ou partiels, ou une coordonn\'{e}e$ s$, ou encore une 
+combinaison des deux. Diff\'{e}rents choix sont propos\'{e}s pour 
+d\'{e}crire la physique oc\'{e}anique, incluant notamment une fermeture 
+turbulente d'ordre 1.5 ou un sch\'{e}ma KPP pour le m\'{e}lange vertical. 
+Via l'infrastructure NEMO, OPA est interfac\'{e} avec un mod\`{e}le de glace 
+de mer, des mod\`{e}les biog\'{e}ochimiques et de traceur passif, et, via le 
+coupleur OASIS, \`{a} plusieurs mod\`{e}les de circulation g\'{e}n\'{e}rale 
+atmosph\'{e}rique. En outre, il peut \^{e}tre ex\'{e}cut\'{e} sur de 
+nombreux calculateurs, y compris des calculateurs multiprocesseurs \`{a} 
+m\'{e}moire partag\'{e}e ou distribu\'{e}e.
+
+\newpage 
+\textbf{PLAN :}
+
+Put it here
+
+\textsc{\textbf{Disclaimer 1}}
+
+\textsc{\textbf{Foreword 3}}
+
+\textsc{\textbf{Introduction 4}}
+
+\textsc{\textbf{Disclaimer}}
+
+OPA (an acronym for Ocean PArall\'{e}lis\'{e}) is the ocean component of 
+NEMO (Nucleus for European Modelling of the Ocean (\underline 
+{www.locean-ipsl.upmc.fr/NEMO}). Like all components of NEMO, it is 
+developed under the CECILL license, which is a french adaptation of the GNU 
+\textbf{GPL} (General Public license). Anyone may use OPA freely for 
+research purposes, and is encouraged to communicate back to the NEMO team 
+its own developments and improvements. The model and the present document 
+have been made available as a service to the community. We cannot certify 
+that the code and its manual are free of errors. Bugs are inevitable and 
+some have undoubtedly survived the testing phase. Users are encouraged to 
+bring them to our attention. The author assumes no responsibility for 
+problems, errors, or incorrect usage of OPA.
+
+The OPA OGCM reference in papers and other publications is as follows: 
+
+Madec, G., 2007: NEMO: the OPA ocean engine. Note du P\^{o}le de 
+mod\'{e}lisation, Institut Pierre-Simon Laplace (IPSL), France, N\r{ }XX, 
+YYpp.
+
+Gurvan Madec: gm@locean-ipsl.upmc.fr
+
+{\ldots}.
+
+\textsc{\textbf{Foreword}}
+
+OPA is the ocean engine of the Nucleus of European Model of the Ocean 
+(NEMO). This model, like all research tools, is in perpetual evolution. The 
+present document describes the OPA model include in the release 2.3 of NEMO. 
+This is the release 9 of OPA. This version differs significantly from 
+version 8, documented in Madec \textit{et al.} (1998). The major modifications are 
+
+(1) transition to full native Fortran 90, deep code restructuring and 
+drastic reduction of CPP keys, 
+
+(2) introduction of partial step representation of bottom topography 
+
+(3) reactivation of a terrain-following vertical coordinate 
+($s-$coordinates) with the addition of several options for pressure gradient 
+computation, 
+
+(4) mixed $z-s$ coordinate
+
+(5) more choices for the treatment of the free surface: full explicit, 
+split-explicit , filtered and rigid-lid 
+
+(6) non linear free surface option (variable level thickness distributed on 
+the whole water column) 
+
+(7) additional schemes for vector and flux forms of the momentum advection
+
+(8) addition of several advection schemes on tracers
+
+(9) implementation of the AGRIF package (Adaptative Grid Refinement in 
+Fortran)
+
+(10) online diagnostics : tracers trend in the mixed layer and vorticity 
+balance
+
+(11) rewriting of the I/O management
+
+(12) OASIS 3 and 4 couplers interfacing with atmospheric global circulation 
+models.
+
+In addition, several minor modifications in the coding have been introduced 
+with the constant concern of improving performance on both scalar and vector 
+computers. 
+
+At the time of this writing, the current release is NEMO 2.3. The new 
+surface module described in this document is not yet part of the current 
+distribution.
+
+\newpage 
+
+\textsc{\textbf{Introduction}}
+
+The Nucleus for European Modelling of the Ocean (NEMO) is a framework of 
+ocean related engines, namely OPA for the Ocean dynamics and thermodynamics, 
+LIM for the sea-ice dynamics and thermodynamics, TOP for the biogeochemistry 
+(both transport (TRP) and sources minus sinks (LOBSTER, PISCES). It is 
+intended to be a flexible tool for studying the ocean and its interactions 
+with the others components of the earth climate system (atmosphere, sea-ice, 
+biogeochemical tracers, ...) over a wide range of space and time scales. 
+This documentation provides information about the physics represented by the 
+OPA ocean model and the rationale for the choice of numerical schemes and 
+the model design. More specific information about running the model on 
+different computers, or how to set up a configuration, are found on the NEMO 
+web site (\underline {www.locean-ipsl.upmc.fr/NEMO}). 
+
+The ocean component of NEMO has been developed from the OPA8.2 model 
+described in Madec \textit{et al.} (1998). This model has been used for a wide range of 
+applications, either regional or global, as a forced ocean model or coupled 
+with the atmosphere. A complete list of references is found on the NEMO web 
+site. 
+
+This manual is organised in four parts. The first part presents the model 
+basics, i.e. the equations and their assumptions, the vertical coordinates 
+used, and the subgrid scale physics. This part deals with the continuous 
+equations of the model (primitive equations, with potential temperature, 
+salinity and an equation of state). The equations are written in a 
+curvilinear coordinate system, with a choice of vertical coordinates ($z$, $s$, 
+and variable volumes). Momentum equations are formulated in the vector 
+invariant form. The model equations are written in dimensional units in the 
+meter, kilogram, second (MKS) international system 
+
+The following chapters deal with the discrete equations. The second chapter 
+presents the space and time domain. The model is discretised on a staggered 
+grid (Arakawa C grid) with masking of land areas. Vertical discretisation 
+uses $z$ coordinates (including partial step), $s$ (terrain-following) coordinate 
+(fixed volume thickness and linear free surface), or$ s* $coordinate (variable 
+volume thickness and nonlinear free surface). The following chapters 
+describe the discretisation of the prognostic equations (momentum and 
+tracers). Explicit, split-explicit or implicit free surface formulations are 
+implemented as well as arid-lid approximation. A number of numerical schemes 
+are available for momentum advection, for the computation of the pressure 
+gradients, as well as for the advection of tracers (second or higher order 
+advection schemes, including positive ones).
+
+Physical parameterisations are described in chapters The model includes an 
+implicit treatment of vertical viscosity and diffusivity. The lateral 
+Laplacian and biharmonic viscosity and diffusion can be rotated following a 
+geopotential or neutral direction. There is an optional eddy induced 
+velocity (Gent and McWilliams 1992) with a space and time variable 
+coefficient, with options to compute the coefficients with Tr\'{e}guier et 
+al. (199X), or Visbeck et al. XXX) schemes. The model has vertical harmonic 
+viscosity and diffusion with a space and time variable coefficient, with 
+options to compute the coefficients with Blanke and Delecluse (1992), Large 
+et al. (1994), or Pacanowski and Philander (1981) mixing schemes.
+
+Optional tidal mixing parametrisation
+
+Other model characteristics (chapter {\ldots}) are the lateral boundary 
+conditions. Global configurations of the model make use of the ORCA tripolar 
+grid, with special north fold boundary condition. Free-slip or no-slip 
+boundary conditions are allowed at land boundaries. Closed basin geometries 
+as well as periodic domains and open boundary conditions are possible. 
+
+Surface boundary conditions can be implemented as prescribed fluxes, or bulk 
+formulations for the surface fluxes (wind stress, heat, freshwater). The 
+model allows penetration of solar radiation There is an optional geothermal 
+heating at the ocean bottom. Within the NEMO system the ocean model is 
+interactively coupled with a sea ice model (LIM) and with biogeochemistry 
+models (PISCES, LOBSTER).Interactive coupling to Atmospheric models is 
+possible via the OASIS (ref!!!) coupler. 
+
+Specific online diagnostics are available in the model: output of all the 
+tendencies of the momentum and tracers equations, output of tracers 
+tendencies averaged over the time evolving mixed layer.
+
+The model is implemented in Fortran 90, with preprocessing (C preprocessor). 
+It runs under UNIX. It is optimized for vector computers and parallelised by 
+domain decomposition with MPI. All input and output is done in NetCDF 
+(Network Common Data Format) with a optional direct access format for 
+output. To ensure the clarity and readability of the code it is necessary to 
+follow \textit{coding rules}. The coding rules for OPA include conventions for naming variables, 
+with different starting letters for different types of variables (real, 
+integer, parameter{\ldots}) Those rules are presented in a document 
+available on the NEMO web site..
+
+The model is organized with a high internal modularity based on physics. In 
+particular, each trend (e.g., a term in the rhs of the prognostic equation) 
+for momentum and tracers is computed in a dedicated module. To make it 
+easier for the user to find his way around the code, the module names follow 
+the \textit{three-letter rule}. Each module name is made of three-letter sequences. For example, 
+TRADMP.F90 is a module related to the TRAcers equation, computing the 
+DaMPing. The complete list of module names is presented in annex. 
+Furthermore, modules are organized in a few directories that correspond to 
+their category, as indicated by the first three letters of their name. 
+
+The manual follows this organization. After the presentation of the 
+continuous equations (chapter 1), the following chapters refer to specific 
+terms of the equations each associated with a group of modules .
+
+\begin{table}[htbp]
+\begin{center}
+\begin{tabular}{|p{143pt}|l|l|}
+\hline
+Chapter 2& 
+DOM& 
+Model DOMain \\
+\hline
+Chapter 3& 
+DYN& 
+DYNamic equations (momentum) \\
+\hline
+Chapter 4& 
+TRA& 
+TRAcer equations (potential temperature and salinity) \\
+\hline
+Chapter 5 & 
+SBC& 
+Surface Boundary Conditions \\
+\hline
+Chapter 6& 
+LDF& 
+Lateral DiFfusion (parameterisations) \\
+\hline
+Chapter 7& 
+ZDF& 
+Vertical DiFfusion  \\
+\hline
+Chapter 8& 
+OBC, lbclnk module& 
+Lateral boundary conditions  \\
+\hline
+Chapter 9& 
+miscellaneous& 
+ \\
+\hline
+\end{tabular}
+\label{tab1}
+\end{center}
+\end{table}
+
+\textbf{Nota Bene :}
+
+Red color : not in the current reference version (v2.3beta) but expected 
+soon
+
+Yellow : missing references, text to be updated{\ldots}
+
+\end{document}
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword - save.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword - save.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword - save.tex	(revision 4536)
@@ -0,0 +1,52 @@
+
+% ================================================================
+% Abstract (English)
+% ================================================================
+
+\chapter*{Abstract}
+
+OPA is the ocean engine of NEMO, a framework of ocean related components developed for both research and operational purposes. It is a primitive equation model adapted to regional and global ocean circulation. It is intended to be a flexible tool for studying the ocean and its interactions with the others components of the earth climate system (atmosphere, sea-ice, biogeochemical tracers, ...) over a wide range of space and time scales. Prognostic variables are the three-dimensional velocity field, the sea surface height, the temperature and the salinity. In the horizontal direction, the model uses a curvilinear orthogonal grid and in the vertical direction, a z full or partial step coordinate, or s-coordinate, or a mixture of the two. The distribution of variables is a three-dimensional Arakawa C-type grid. Various physical choices are available to describe ocean physics, including a 1.5 turbulent closure  or a KPP scheme for the vertical mixing. Within NEMO, OPA is interfaced with a sea-ice model (LIM), passive tracer and biogeochemical models (TOP) and, via the OASIS coupler, with several atmospheric general circulation models. In addition, it can be run on many different computers, including shared and distributed memory multiprocessor computers.
+
+% ================================================================
+% Abstract (French)
+% ================================================================
+\chapter*{R\'{e}sum\'{e}}
+
+OPA est le moteur oc\'{e}anique de NEMO, un syst\`{e}me de mod\'{e}lisation de l'oc\'{e}an d\'{e}velopp\'{e} \`{a} des fins de recherche et d'oc\'{e}anographie op\'{e}rationnelle. Ce moteur est un mod\`{e}le aux \'{e}quations primitives de la circulation oc\'{e}anique r\'{e}gionale et globale. Il se veut un outil flexible pour \'{e}tudier sur un vaste spectre spatiotemporel l'oc\'{e}an et ses interactions avec les autres composantes du syst\`{e}me climatique terrestre (atmosph\`{e}re, glace de mer, traceurs biog\'{e}ochimiques...). Les variables pronostiques sont le champ tridimensionnel de vitesse, la hauteur de la mer , la temperature et la salinit\'{e}. La distribution des variables se fait sur une grille C d'Arakawa tridimensionnelle utilisant une coordonn\'{e}e verticale z \`{a} niveaux entiers ou partiels, ou une coordonn\'{e}e s, ou encore une combinaison des deux. Diff\'{e}rents choix sont propos\'{e}s pour d\'{e}crire la physique oc\'{e}anique, incluant notamment une fermeture turbulente d'ordre 1.5 ou un sch\'{e}ma KPP pour le m\'{e}lange vertical. Via l'infrastructure NEMO, OPA est interfac\'{e} avec un mod\`{e}le de glace de mer, des mod\`{e}les biog\'{e}ochimiques et de traceur passif, et, via le coupleur OASIS, \`{a} plusieurs mod\`{e}les de circulation g\'{e}n\'{e}rale atmosph\'{e}rique. En outre, il peut \^etre ex\'{e}cut\'{e} sur de nombreux calculateurs, y compris des calculateurs multiprocesseurs \`{a} m\'{e}moire partag\'{e}e ou distribu\'{e}e.
+
+
+% ================================================================
+% Disclaimer
+% ================================================================
+\chapter*{Disclaimer}
+
+OPA (an acronym for Ocean PArall\'{e}lis\'{e}) is the ocean component of NEMO (Nucleus for European Modelling of the Ocean (www.locean-ipsl.upmc.fr/NEMO). Like all components of NEMO, it is developed under the CECILL license, which is a french adaptation of the GNU GPL (General Public license). Anyone may use OPA freely for research purposes, and is encouraged to communicate back to the NEMO team its own developments and improvements. The model and the present document have been made available as a service to the community. We cannot certify that the code and its manual are free of errors. Bugs are inevitable and some have undoubtedly survived the testing phase. Users are encouraged to bring them to our attention. The author assumes no responsibility for problems, errors, or incorrect usage of OPA.
+
+ \vspace{1cm}
+The OPA OGCM reference in papers and other publications is as follows:
+ \vspace{0.5cm}
+
+Madec, G., 2007: NEMO ocean engine. \textit{Note du P\^ole de mod\'{e}lisation}, Institut Pierre-Simon Laplace (IPSL), France, NXX, \colorbox{yellow}{YYpp}.\\
+
+% ================================================================
+% Foreword
+% ================================================================
+\chapter*{Foreword}
+
+OPA is the ocean engine of the NEMO. This model, like all research tools, is in perpetual evolution. The present document describes the OPA model include in the release 2.3 of NEMO. This is the release 9 of OPA. This version differs significantly from version 8, documented in \citet{Madec1998}. The major modifications are :\\
+(1) transition to full native \textsc{Fortran} 90, deep code restructuring and drastic reduction of CPP keys, \\
+(2) introduction of partial step representation of bottom topography \\
+(3) partial reactivation of a terrain-following vertical coordinate ($s$- and hybrid $s$-$z$) with the addition of several options for pressure gradient computation \footnote{Partial support of $s$-coordinate: there is presently no support for neutral physics in $s$-coordinate and for the new options for horizontal pressure gradient computation with true equation of state.}, \\ 
+(4) more choices for the treatment of the free surface: full explicit, split-explicit , filtered and rigid-lid \\
+(5) non linear free surface option (variable level thickness distributed on the whole water column) \\
+(6) additional schemes for vector and flux forms of the momentum  advection \\
+(7) addition of several advection schemes on tracers \\
+ (8) implementation of the AGRIF package (Adaptative Grid Refinement in \textsc{Fortran} ) \\
+(9) online diagnostics : tracers trend in the mixed layer and vorticity balance \\
+(10) rewriting of the I/O management \\
+(11) OASIS 3 and 4 couplers interfacing with atmospheric global circulation models. 
+
+In addition, several minor modifications in the coding have been introduced with the constant concern of improving performance on both scalar and vector computers. 
+
+At the time of this writing, the current release is NEMO 2.3. The new surface module described in this document is not yet part of the current distribution.
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Abstracts_Foreword.tex	(revision 4536)
@@ -0,0 +1,31 @@
+
+% ================================================================
+% Abstract (English / French)
+% ================================================================
+
+\chapter*{Abstract / R\'{e}sum\'{e}}
+
+\vspace{-40pt}
+
+\small{ 
+The ocean engine of NEMO is a primitive equation model adapted to regional and global ocean circulation. It is intended to be a flexible tool for studying the ocean and its interactions with the others components of the earth climate system (atmosphere, sea-ice, biogeochemical tracers, ...) over a wide range of space and time scales. Prognostic variables are the three-dimensional velocity field, the sea surface height, the temperature and the salinity. In the horizontal direction, the model uses a curvilinear orthogonal grid and in the vertical direction, a z full or partial step coordinate, or s-coordinate, or a mixture of the two. The distribution of variables is a three-dimensional Arakawa C-type grid. Various physical choices are available to describe ocean physics, including TKE and KPP turbulent closures for the vertical mixing. Within NEMO, the ocean is interfaced with a sea-ice model (LIM), passive tracer and biogeochemical models (TOP) and, via the OASIS coupler, with several atmospheric general circulation models. 
+
+% ================================================================
+ \vspace{0.25cm}
+
+Le moteur oc\'{e}anique de NEMO est un mod\`{e}le aux \'{e}quations primitives de la circulation oc\'{e}anique r\'{e}gionale et globale. Il se veut un outil flexible pour \'{e}tudier sur un vaste spectre spatiotemporel l'oc\'{e}an et ses interactions avec les autres composantes du syst\`{e}me climatique terrestre (atmosph\`{e}re, glace de mer, traceurs biog\'{e}ochimiques...). Les variables pronostiques sont le champ tridimensionnel de vitesse, la hauteur de la mer, la temperature et la salinit\'{e}. La distribution des variables se fait sur une grille C d'Arakawa tridimensionnelle utilisant une coordonn\'{e}e verticale z \`{a} niveaux entiers ou partiels, ou une coordonn\'{e}e s, ou encore une combinaison des deux. Diff\'{e}rents choix sont propos\'{e}s pour d\'{e}crire la physique oc\'{e}anique, incluant notamment une fermeture turbulente TKE et KPP pour le m\'{e}lange vertical. Via l'infrastructure NEMO, l'oc\'{e}an est interfac\'{e} avec un mod\`{e}le de glace de mer, des mod\`{e}les biog\'{e}ochimiques et de traceur passif, et, via le coupleur OASIS, \`{a} plusieurs mod\`{e}les de circulation g\'{e}n\'{e}rale atmosph\'{e}rique. 
+} 
+
+% ================================================================
+% Disclaimer
+% ================================================================
+\chapter*{Disclaimer}
+
+OPA (an acronym for Ocean PArall\'{e}lis\'{e}) is the ocean component of NEMO (Nucleus for European Modelling of the Ocean (www.locean-ipsl.upmc.fr/NEMO). Like all components of NEMO, it is developed under the CECILL license, which is a french adaptation of the GNU GPL (General Public license). Anyone may use OPA freely for research purposes, and is encouraged to communicate back to the NEMO team its own developments and improvements. The model and the present document have been made available as a service to the community. We cannot certify that the code and its manual are free of errors. Bugs are inevitable and some have undoubtedly survived the testing phase. Users are encouraged to bring them to our attention. The author assumes no responsibility for problems, errors, or incorrect usage of OPA.
+
+ \vspace{1cm}
+The OPA OGCM reference in papers and other publications is as follows:
+ \vspace{0.5cm}
+
+Madec, G., 2007: NEMO ocean engine. \textit{Note du P\^ole de mod\'{e}lisation}, Institut Pierre-Simon Laplace (IPSL), France, NXX, \colorbox{yellow}{YYpp}.\\
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_A.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_A.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_A.tex	(revision 4536)
@@ -0,0 +1,199 @@
+
+% ================================================================
+% Chapter Ñ Appendix A : Curvilinear s-Coordinate Equations
+% ================================================================
+\chapter{Appendix A : Curvilinear $s$-Coordinate Equations}
+\label{Apdx_A}
+\minitoc
+
+In order to establish the set of Primitive Equation in curvilinear 
+$s$-coordinates (i.e. orthogonal curvilinear coordinates in the horizontal and 
+$s$-coordinates in the vertical), we start from the set of equation established 
+in {\S}~I.3 for the special case $k = z$ and thus $e_3 = 1$, and we introduce an arbitrary 
+vertical coordinate $s = s(i,j,z)$. Let us define a new vertical scale factor by $e_3 = \partial z / \partial s$ (which now depends on $(i,j,z)$) and the horizontal slope of $s$-surfaces by :
+\begin{equation} \label{Apdx_A_A1}
+\sigma _1 =\frac{1}{e_1 }\;\left. {\frac{\partial z}{\partial i}} \right|_s 
+\quad \text{and}
+\sigma _2 =\frac{1}{e_2 }\;\left. {\frac{\partial z}{\partial j}} \right|_s 
+\end{equation}
+
+The chain rule to establish the model equations in the curvilinear 
+s-coordinate system is:
+\begin{equation} \label{Apdx_A_A2}
+\begin{aligned}
+&\left. {\frac{\partial \bullet }{\partial i}} \right|_z  =\left. 
+{\frac{\partial \bullet }{\partial i}} \right|_s +\frac{\partial \bullet 
+}{\partial s}\;\frac{\partial s}{\partial i}=\left. {\frac{\partial \bullet 
+}{\partial i}} \right|_s -\frac{e_1 }{e_3 }\sigma _1 \frac{\partial \bullet 
+}{\partial s} \\
+&\left. {\frac{\partial \bullet }{\partial j}} \right|_z  =\left. 
+{\frac{\partial \bullet }{\partial j}} \right|_s +\frac{\partial \bullet 
+}{\partial s}\;\frac{\partial s}{\partial j}=\left. {\frac{\partial \bullet 
+}{\partial j}} \right|_s -\frac{e_2 }{e_3 }\sigma _2 \frac{\partial \bullet 
+}{\partial s} \\
+&\;\frac{\partial \bullet }{\partial z}  =\frac{1}{e_3 }\frac{\partial \bullet 
+}{\partial s} \\
+\end{aligned}
+\end{equation}
+
+Using (\ref{Apdx_A_A2}), the divergence of the velocity is transformed as follows:
+
+
+\begin{equation*}
+\nabla \cdot {\rm {\bf U}}=\frac{1}{e_1 \,e_2 }\left[ {\left. 
+{\frac{\partial (e_2 \,u)}{\partial i}} \right|_z +\left. {\frac{\partial 
+(e_1 \,v)}{\partial j}} \right|_z } \right]+\frac{\partial w}{\partial z} \\
+\end{equation*}
+
+%\begin{equation} \label{   }
+\begin{multline*}
+=\frac{1}{e_1 \,e_2 }\left[ {\left. {\frac{\partial (e_2 \,u)}{\partial i}} 
+\right|_s -\frac{e_1 }{e_3 }\sigma _1 \frac{\partial (e_2 \,u)}{\partial s}} 
+\right. \\ 
+\shoveright { \left. { +\left. {\frac{\partial (e_1 \,v)}{\partial j}} \right|_s -\frac{e_2 }{e_3 }\sigma _2 \frac{\partial (e_1 v)}{\partial s}} \right]+\frac{\partial w}{\partial s}\frac{\partial s}{\partial z} }\\ 
+\end{multline*}
+%\end{equation}
+
+\begin{equation*}
+%\begin{multline}
+=\frac{1}{e_1 \,e_2 }\left[ {\left. {\frac{\partial (e_2 \,u)}{\partial i}} 
+\right|_s +\left. {\frac{\partial (e_1 \,v)}{\partial j}} \right|_s } 
+\right]+\frac{1}{e_3 }\left[ {\frac{\partial w}{\partial s}-\sigma _1 
+\frac{\partial u}{\partial s}-\sigma _2 \frac{\partial v}{\partial s}} 
+\right]
+%\end{multline}
+\end{equation*}
+
+%\begin{equation} \label{   }
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\frac{\partial (e_2 \,e_3 
+\,u)}{\partial i}} \right|_s -\left. {e_2 \,u\frac{\partial e_3 }{\partial 
+i}} \right|_s +\left. {\frac{\partial (e_1 \,e_3 \,v)}{\partial j}} 
+\right|_s -\left. {e_1 v\frac{\partial e_3 }{\partial j}} \right|_s } 
+\right] \\ 
+\shoveright{ +\frac{1}{e_3 }\left[ {\frac{\partial w}{\partial s}-\sigma _1 
+\frac{\partial u}{\partial s}-\sigma _2 \frac{\partial v}{\partial s}} 
+\right]} \\ 
+\end{multline*}
+%\end{equation}
+
+
+Noting that $\frac{1}{e_1 }\left. {\frac{\partial e_3 }{\partial i}} 
+\right|_s =\frac{1}{e_1 }\left. {\frac{\partial ^2z}{\partial i\,\partial 
+s}} \right|_s =\frac{\partial }{\partial s}\left( {\frac{1}{e_1 }\left. 
+{\frac{\partial z}{\partial i}} \right|_s } \right)=\frac{\partial \sigma _1 
+}{\partial s}$ and $\frac{1}{e_2 }\left. {\frac{\partial e_3 }{\partial j}} 
+\right|_s =\frac{\partial \sigma _2 }{\partial s}$, it becomes:
+
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\frac{\partial (e_2 \,e_3 
+\,u)}{\partial i}} \right|_s +\left. {\frac{\partial (e_1 \,e_3 
+\,v)}{\partial j}} \right|_s } \right] \\ 
+\shoveright{ +\frac{1}{e_3 }\left[ {\frac{\partial w}{\partial s}-u\frac{\partial \sigma _1 }{\partial s}-v\frac{\partial \sigma _2 }{\partial s}-\sigma _1 \frac{\partial u}{\partial s}-\sigma _2 \frac{\partial v}{\partial s}} \right]} \\ 
+ \end{multline*}
+ 
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\frac{\partial (e_2 \,e_3 
+\,u)}{\partial i}} \right|_s +\left. {\frac{\partial (e_1 \,e_3 
+\,v)}{\partial j}} \right|_s } \right] \\ 
+\shoveright{ +\frac{1}{e_3 }\left[ {\frac{\partial w}{\partial 
+s}-\frac{\partial (u\;\sigma _1 )}{\partial s}-\frac{\partial (v\;\sigma _2 
+)}{\partial s}} \right]} \\ 
+ \end{multline*}
+ 
+Introducing a "vertical" velocity $\omega $ as the velocity normal to $s$-surfaces:
+
+\begin{equation} \label{Apdx_A_A3}
+\omega =w-\sigma _1 \,u-\sigma _2 \,v
+\end{equation}
+
+the divergence of the velocity is given in curvilinear $s$-coordinates by:
+\begin{equation} \label{Apdx_A_A4}
+\nabla \cdot {\rm {\bf U}}=\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. 
+{\frac{\partial (e_2 \,e_3 \,u)}{\partial i}} \right|_s +\left. 
+{\frac{\partial (e_1 \,e_3 \,v)}{\partial j}} \right|_s } 
+\right]+\frac{1}{e_3 }\frac{\partial \omega }{\partial s}
+\end{equation}
+
+
+As a result, the continuity equation (I.1.3) in $s$-coordinates becomes:
+\begin{equation} \label{Apdx_A_A5}
+\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\frac{\partial (e_2 \,e_3 
+\,u)}{\partial i}} \right|_s +\left. {\frac{\partial (e_1 \,e_3 
+\,v)}{\partial j}} \right|_s } \right]+\frac{1}{e_3 }\frac{\partial \omega 
+}{\partial s}=0
+\end{equation}
+
+
+\textbf{Momentum equation:}
+
+As an example let us consider (I.3.10), the first component of the momentum 
+equation. Its non linear term can be transformed as follows:
+
+\begin{equation*}
+\begin{aligned}
+&+\left. \zeta \right|_z v-\frac{1}{2e_1 }\left. {\frac{\partial 
+(u^2+v^2)}{\partial i}} \right|_z -w\frac{\partial u}{\partial z} \\
+&=\frac{1}{e_1 \,e_2 }\left[ {\left. {\frac{\partial (e_2 \,v)}{\partial i}} 
+\right|_z -\left. {\frac{\partial (e_1 \,u)}{\partial j}} \right|_z } 
+\right]\;v-\frac{1}{2e_1 }\left. {\frac{\partial (u^2+v^2)}{\partial i}} 
+\right|_z -w\frac{\partial u}{\partial z}
+\end{aligned}
+\end{equation*}
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 }\left[ {\left. {\frac{\partial (e_2 \,v)}{\partial i}} 
+\right|_s -\left. {\frac{\partial (e_1 \,u)}{\partial j}} \right|_s } 
+\right. \\ 
+ \left. {-\frac{e_1 }{e_3 }\sigma _1 \frac{\partial (e_2 \,v)}{\partial s}+\frac{e_2 }{e_3 }\sigma _2 \frac{\partial (e_1 \,u)}{\partial s}} \right]\;v \\ 
+\shoveright{ -\frac{1}{2e_1 }\left( {\left. {\frac{\partial (u^2+v^2)}{\partial i}} \right|_s -\frac{e_1 }{e_3 }\sigma _1 \frac{\partial (u^2+v^2)}{\partial s}} \right)-\frac{w}{e_3 }\frac{\partial u}{\partial s} }\\
+ \end{multline*}
+
+\begin{equation*}
+ =\left. \zeta \right|_s \;v-\frac{1}{2e_1 }\left. {\frac{\partial 
+(u^2+v^2)}{\partial i}} \right|_s -\frac{w}{e_3 }\frac{\partial u}{\partial 
+s}-\left[ {\frac{\sigma _1 }{e_3 }\frac{\partial v}{\partial s}-\frac{\sigma 
+_2 }{e_3 }\frac{\partial u}{\partial s}} \right]\;v \\ 
+ +\frac{\sigma _1 }{2e_3 }\frac{\partial (u^2+v^2)}{\partial s} 
+\end{equation*}
+
+
+\begin{multline*}
+ =\left. \zeta \right|_s \;v-\frac{1}{2e_1 }\left. {\frac{\partial (u^2+v^2)}{\partial i}} \right|_s \\ 
+\shoveright{ -\frac{1}{e_3 }\left[ {w\frac{\partial u}{\partial s}+\sigma _1 v\frac{\partial v}{\partial s}-\sigma _2 v\frac{\partial u}{\partial s}-\sigma _1 u\frac{\partial u}{\partial s}-\sigma _1 v\frac{\partial v}{\partial s}} \right] }\\ 
+ \end{multline*}
+
+\begin{equation} \label{Apdx_A_A6}
+=\left. \zeta \right|_s \;v-\frac{1}{2e_1 }\left. {\frac{\partial (u^2+v^2)}{\partial i}} \right|_s -\frac{1}{e_3 }\omega \frac{\partial u}{\partial s} 
+\end{equation}
+
+Therefore, the non-linear terms of the momentum equation have the same form 
+in $z- $and $s-$coordinates
+
+The pressure gradient term can be transformed as follows:
+\begin{equation} \label{Apdx_A_A7}
+\begin{split}
+ -\frac{1}{\rho _o e_1 }\left. {\frac{\partial p}{\partial i}} \right|_z& =-\frac{1}{\rho _o e_1 }\left[ {\left. {\frac{\partial p}{\partial i}} \right|_s -\frac{e_1 }{e_3 }\sigma _1 \frac{\partial p}{\partial s}} \right] \\
+& =-\frac{1}{\rho _o \,e_1 }\left. {\frac{\partial p}{\partial i}} \right|_s +\frac{\sigma _1 }{\rho _o \,e_3 }\left( {-g\;\rho \;e_3 } \right) \\
+&=-\frac{1}{\rho _o \,e_1 }\left. {\frac{\partial p}{\partial i}} \right|_s -\frac{g\;\rho }{\rho _o }\sigma _1
+\end{split}
+\end{equation}
+
+An additional term appears in (\ref{Apdx_A_A7}) which accounts for the tilt of model 
+levels.
+
+\textbf{Tracer equation:}
+
+The tracer equation is obtained using the same calculation as for the 
+continuity equation:
+
+%\begin{equation} \label{Eq_   }
+\begin{multline} \label{Apdx_A_A8}
+ \frac{\partial T}{\partial t} = -\frac{1}{e_1 \,e_2 \,e_3 } \left[ {\frac{\partial }{\partial i}} \left( {e_2 \,e_3 \;Tu} \right) + \frac{\partial }{\partial j} \left( {e_1 \,e_3 \;Tv} \right) \;\right .\\
+ \shoveright{\left . +\frac{\partial }{\partial k} \left( {e_1 \,e_2 \;T\omega } \right) \right] +D^{lT} +D^{vT} }\\
+\end{multline}
+%\end{equation}
+
+
+The expression of the advection term is a straight consequence of (A.4), the 
+expression of the 3D divergence in $s$-coordinates established above.
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_B.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_B.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_B.tex	(revision 4536)
@@ -0,0 +1,291 @@
+% ================================================================
+% Chapter Ñ Appendix B : Diffusive Operators
+% ================================================================
+\chapter{Appendix B : Diffusive Operators}
+\label{Apdx_B}
+\minitoc
+
+% ================================================================
+% Horizontal/Vertical 2nd Order Tracer Diffusive Operators
+% ================================================================
+\section{Horizontal/Vertical 2nd Order Tracer Diffusive Operators}
+\label{Apdx_B_1}
+
+
+In $z$-coordinates, the horizontal/vertical second order tracer diffusive 
+operator is given by:
+
+
+
+\begin{equation} \label{Apdx_B1}
+\begin{split}
+ D^T&=D^{lT}+D^{vT} \\ 
+ &=\frac{1}{e_1 e_2 }\left[ {\left. {\frac{\partial }{\partial i}\left( 
+{\frac{e_2 }{e_1 }A^{lT} \;\left. {\frac{\partial T}{\partial i}} \right|_z 
+} \right)} \right|_z +\left. {\frac{\partial }{\partial j}\left( {\frac{e_1 
+}{e_2 }A^{lT} \;\left. {\frac{\partial T}{\partial j}} \right|_z } \right)} 
+\right|_z } \right] +\frac{\partial }{\partial z}\left( {A^{vT} \;\frac{\partial T}{\partial 
+z}} \right) \\ 
+\end{split}
+\end{equation}
+
+
+In $s$-coordinates, we defined the slopes of $s-$surfaces, $\sigma_1$ and $\sigma_2$ by (A.1), the vertical/horizontal ratio of diffusive coefficient by $\epsilon = A^{vT} / A^{lT}$. The diffusive operator is given by:
+
+\begin{equation} \label{Apdx_B2}
+\begin{aligned} 
+&D^T=D^{lT}+D^{vT} =\left. \nabla \right|_s \cdot \left[ {A^{lT} \;\Re \cdot \left. \nabla 
+\right|_s \left( T \right)} \right] \\
+&\text{where} \;\Re =\left( {{\begin{array}{*{20}c}
+ 1 \hfill & 0 \hfill & {-\sigma _1 } \hfill \\
+ 0 \hfill & 1 \hfill & {-\sigma _2 } \hfill \\
+ {-\sigma _1 } \hfill & {-\sigma _2 } \hfill & {\varepsilon +\sigma _1 
+^2+\sigma _2 ^2} \hfill \\
+\end{array} }} \right)
+\end{aligned}
+\end{equation}
+
+or in expended form:
+
+\begin{multline} \label{Apdx_B3}
+D^T=\frac{1}{e_1 e_2 e_3 }\;\left[ {\;\,e_2 e_3 A^{lT} \;\left. 
+{\frac{\partial }{\partial i}\left( {\frac{1}{e_1 }\;\left. {\frac{\partial 
+T}{\partial i}} \right|_s -\frac{\sigma _1 }{e_3 }\;\frac{\partial 
+T}{\partial s}} \right)} \right|_s } \right.  \\
+\;\;+e_1 e_3 A^{lT} \;\left. {\frac{\partial }{\partial j}\left( {\frac{1}{e_2 }\;\left. {\frac{\partial T}{\partial j}} \right|_s -\frac{\sigma _2 }{e_3 }\;\frac{\partial T}{\partial s}} \right)} \right|_s \\
+ \;\;+e_1 e_2 A^{lT} \;\frac{\partial }{\partial s}\left( {-\frac{\sigma _1 }{e_1 }\;\left. {\frac{\partial T}{\partial i}} \right|_s -\frac{\sigma _2 }{e_2 }\;\left. {\frac{\partial T}{\partial j}} \right|_s } \right. \\
+\shoveright{\;\;\left. {\left. {+\left( {\varepsilon +\sigma _1^2+\sigma _2 ^2} \right)\;\frac{1}{e_3 }\;\frac{\partial T}{\partial s}} \right)\;\;\,} \right]} \\ 
+\end{multline}
+
+
+Equation (\ref{Apdx_B2}) (or equivalently (\ref{Apdx_B3})~) is obtained from (\ref{Apdx_B1}) without any additional assumption. Indeed, for the special case $k=z$ and thus $e_3 =1$, 
+we introduce an arbitrary vertical coordinate $s = s (i,j,z)$ as in Appendix A 
+\newline
+\newline
+and use (A.1) and (A.2). Since no cross horizontal derivate $\partial _i \,\partial _j $ appears neither in (B.1) nor in (A.2), there is a decoupling between $(i,z)$ and $(j,z)$ plans as well as 
+$(i,s)$ and $(j,s)$ plans. The demonstration can then be done for the $(i,s)\;\to \;(j,s)$ transformation without loss of generality:
+
+\begin{equation*}
+D^T=\frac{1}{e_1 \,e_2 }\left. {\frac{\partial }{\partial i}\left( {\frac{e_2 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_z } \right)} \right|_z +\frac{\partial }{\partial z}\left( {A^{vT}\;\frac{\partial T}{\partial z}} \right)
+\end{equation*}
+
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 }\left[ {\left. {\;\frac{\partial }{\partial i}\left( {\frac{e_2 }{e_1 }A^{lT}\;\left( {\left. {\frac{\partial T}{\partial i}} \right|_s -\frac{e_1 \,\sigma _1 }{e_3 }\frac{\partial T}{\partial s}} \right)} \right)} \right|_s } \right. \\ 
+ \left. { -\frac{e_1 \,\sigma _1 }{e_3 }\frac{\partial }{\partial s}\left( {\frac{e_2 }{e_1 }A^{lT}\;\left. {\left( {\left. {\frac{\partial T}{\partial i}} \right|_s -\frac{e_1 \,\sigma _1 }{e_3 }\frac{\partial T}{\partial s}} \right)} \right|_s } \right)\;} \right] \\ 
+\shoveright{ +\frac{1}{e_3 }\frac{\partial }{\partial s}\left[ {\frac{A^{vT}}{e_3 }\;\frac{\partial T}{\partial s}} \right]} \\ 
+\end{multline*}
+
+
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\;\;\frac{\partial }{\partial i}\left( {\frac{e_2 \,e_3 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right)} \right|_s -\left. {\frac{e_2 }{e_1 
+}A^{lT}\;\frac{\partial e_3 }{\partial i}} \right|_s \left. {\frac{\partial T}{\partial i}} \right|_s } \right. \\ 
+ \left. {-e_3 \frac{\partial }{\partial i}\left( {\frac{e_2 \,\sigma _1 }{e_3 }A^{lT}\;\frac{\partial T}{\partial s}} \right)} \right|_s -e_1 \,\sigma _1 \frac{\partial }{\partial s}\left( 
+{\frac{e_2 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right) \\
+ \shoveright{ -e_1 \,\sigma _1 \frac{\partial }{\partial s}\left( {-\frac{e_2 \,\sigma _1 }{e_3 }A^{lT}\;\frac{\partial T}{\partial s}} \right)\;\,\left. {+\frac{\partial }{\partial s}\left( {\frac{e_1 \,e_2 }{e_3 }A^{vT}\;\frac{\partial T}{\partial s}} \right)\;\;} \right] }\\ 
+\end{multline*}
+
+
+Noting that $\frac{1}{e_1} \left. \frac{\partial e_3 }{\partial i} \right|_s = \frac{\partial \sigma _1 }{\partial s}$, it becomes:
+
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\;\;\;\frac{\partial }{\partial i}\left( {\frac{e_2 \,e_3 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right)} \right|_s \left. {-e_3 \frac{\partial }{\partial 
+i}\left( {\frac{e_2 \,\sigma _1 }{e_3 }A^{lT}\;\frac{\partial T}{\partial s}} \right)} \right|_s } \right. \\ 
+ -e_2 A^{lT}\;\frac{\partial \sigma _1 }{\partial s}\left. {\frac{\partial T}{\partial i}} \right|_s -e_1 \,\sigma_1 \frac{\partial }{\partial s}\left( {\frac{e_2 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right) \\ 
+\shoveright{ \left. { +e_1 \,\sigma _1 \frac{\partial }{\partial s}\left( {\frac{e_2 \,\sigma _1 }{e_3 }A^{lT}\;\frac{\partial T}{\partial s}} \right)+\frac{\partial }{\partial s}\left( {\frac{e_1 \,e_2 }{e_3 }A^{vT}\;\frac{\partial T}{\partial z}} \right)\;\;\;} \right] }\\ 
+\end{multline*}
+
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 } \left[ {\left. {\;\;\;\frac{\partial }{\partial i} \left( {\frac{e_2 \,e_3 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right)} \right|_s \left. {-\frac{\partial }{\partial 
+i}\left( {e_2 \,\sigma _1 A^{lT}\;\frac{\partial T}{\partial s}} \right)} \right|_s } \right. \\ 
+ \left. {+\frac{e_2 \,\sigma _1 }{e_3}A^{lT}\;\frac{\partial T}{\partial s} \;\frac{\partial e_3 }{\partial i}}  \right|_s -e_2 A^{lT}\;\frac{\partial \sigma _1 }{\partial s}\left. {\frac{\partial T}{\partial i}} \right|_s \\ 
+-e_2 \,\sigma _1 \frac{\partial}{\partial s}\left( {A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right)+\frac{\partial }{\partial s}\left( {\frac{e_1 \,e_2 \,\sigma _1 ^2}{e_3 }A^{lT}\;\frac{\partial T}{\partial s}} \right) \\ 
+\shoveright{ \left. {-\frac{\partial \left( {e_1 \,e_2 \,\sigma _1 } \right)}{\partial s} \left( {\frac{\sigma _1 }{e_3}A^{lT}\;\frac{\partial T}{\partial s}} \right) + \frac{\partial }{\partial s}\left( {\frac{e_1 \,e_2 }{e_3 }A^{vT}\;\frac{\partial T}{\partial s}} \right)\;\;\;} \right]} \\ 
+\end{multline*}
+using the same remark as just above, it becomes:
+\begin{multline*}
+= \frac{1}{e_1 \,e_2 \,e_3 } \left[ {\left. {\;\;\;\frac{\partial }{\partial i} \left( {\frac{e_2 \,e_3 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s -e_2 \,\sigma _1 A^{lT}\;\frac{\partial T}{\partial s}} \right)} \right|_s } \right.\;\;\; \\ 
++\frac{e_1 \,e_2 \,\sigma _1 }{e_3 }A^{lT}\;\frac{\partial T}{\partial s}\;\frac{\partial \sigma _1 }{\partial s} - \frac {\sigma _1 }{e_3} A^{lT} \;\frac{\partial \left( {e_1 \,e_2 \,\sigma _1 } \right)}{\partial s}\;\frac{\partial T}{\partial s} \\ 
+-e_2 \left( {A^{lT}\;\frac{\partial \sigma _1 }{\partial s}\left. {\frac{\partial T}{\partial i}} \right|_s +\frac{\partial }{\partial s}\left( {\sigma _1 A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right)-\frac{\partial \sigma _1 }{\partial s}\;A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s } \right) \\ 
+\shoveright{\left. {+\frac{\partial }{\partial s}\left( {\frac{e_1 \,e_2 \,\sigma _1 ^2}{e_3 }A^{lT}\;\frac{\partial T}{\partial s}+\frac{e_1 \,e_2}{e_3 }A^{vT}\;\frac{\partial T}{\partial s}} \right)\;\;\;} \right] }\\ 
+\end{multline*}
+
+Since the horizontal scale factor do not depend on the vertical coordinates, the last term of the first line and the first term of the last line cancel, while the second line reduces to a single vertical derivative, so it becomes:
+\begin{multline*}
+ =\frac{1}{e_1 \,e_2 \,e_3 }\left[ {\left. {\;\;\;\frac{\partial }{\partial i}\left( {\frac{e_2 \,e_3 }{e_1 }A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s -e_2 \,\sigma _1 \,A^{lT}\;\frac{\partial T}{\partial s}} \right)} \right|_s } \right. \\ 
+ \shoveright{ \left. {+\frac{\partial }{\partial s}\left( {-e_2 \,\sigma _1 \,A^{lT}\;\left. {\frac{\partial T}{\partial i}} \right|_s +A^{lT}\frac{e_1 \,e_2 }{e_3 }\;\left( {\varepsilon +\sigma _1 ^2} \right)\frac{\partial T}{\partial s}} \right)\;\;\;} \right]} \\ 
+\end{multline*}
+
+in other words:
+
+\begin{equation*}
+D^T = {\frac{1}{e_1\,e_2\,e_3}}
+\left( {{\begin{array}{*{20}c}
+{\left. {\frac{\partial \left( {e_2 e_3 \bullet } \right)}{\partial i}} \right|_s } \hfill \\
+{\frac{\partial \left( {e_1 e_2 \bullet } \right)}{\partial s}} \hfill \\
+\end{array}}}\right)
+\cdot \left[ {A^{lT}
+\left( {{\begin{array}{*{20}c}
+ {1} \hfill & {-\sigma_1 } \hfill \\
+ {-\sigma_1} \hfill & {\varepsilon_1^2} \hfill \\
+\end{array} }} \right)
+\cdot 
+\left( {{\begin{array}{*{20}c}
+{\frac{1}{e_1 }\;\left. {\frac{\partial \bullet }{\partial i}} \right|_s } \hfill \\
+{\frac{1}{e_3 }\;\frac{\partial \bullet }{\partial s}} \hfill \\
+\end{array}}}
+\right) \left( T \right)} \right]
+\end{equation*}
+
+
+% ================================================================
+% Isopycnal/Vertical Second Order Tracer Diffusive Operators
+% ================================================================
+\section{Isopycnal/Vertical Second Order Tracer Diffusive Operators}
+\label{Apdx_B_2}
+
+
+The isopycnal diffusive tensor $\textbf {A}_{\textbf I}$ expressed in the curvilinear coordinate system $(i,j,k)$, in which the equations of the ocean circulation model are formulated, takes the following expression [Redi 1982]:
+
+\begin{equation*}
+\textbf {A}_{\textbf I} = \frac{A^{lT}}{\left( {1+a_1 ^2+a_2 ^2} \right)}
+\left[ {{\begin{array}{*{20}c}
+ {1+a_1 ^2} \hfill & {-a_1 a_2 } \hfill & {-a_1 } \hfill \\
+ {-a_1 a_2 } \hfill & {1+a_2 ^2} \hfill & {-a_2 } \hfill \\
+ {-a_1 } \hfill & {-a_2 } \hfill & {\varepsilon +a_1 ^2+a_2 ^2} \hfill \\
+\end{array} }} \right]
+\end{equation*}
+where$(a_1$, $a_2)$ are the isopycnal slopes in $(\textbf{i}$, $\textbf{j})$ directions:
+\begin{equation*}
+a_1 =\frac{e_3 }{e_1 }\left( {\frac{\partial \rho }{\partial i}} \right)\left( {\frac{\partial \rho }{\partial k}} \right)^{-1}
+\end{equation*}
+\begin{equation*}
+a_2 =\frac{e_3 }{e_2 }\left( {\frac{\partial \rho }{\partial j}} 
+\right)\left( {\frac{\partial \rho }{\partial k}} \right)^{-1}
+\end{equation*}
+In practice, the isopycnal slopes are generally less than $10${\small $^{-2}$ in the ocean, so $\textbf {A}_{\textbf I}$ can be simplified appreciably (Cox, 1987) :
+\begin{equation*}
+{\textbf{A}_{\textbf{I}}} =A^{lT}
+\left[ {{\begin{array}{*{20}c}
+ 1 \hfill & 0 \hfill & {-a_1 } \hfill \\
+ 0 \hfill & 1 \hfill & {-a_2 } \hfill \\
+ {-a_1 } \hfill & {-a_2 } \hfill & {\varepsilon +a_1 ^2+a_2 ^2} \hfill \\
+\end{array} }} \right]
+\end{equation*}
+The resulting isopycnal operator conserves the quantity it diffuses, and dissipates the square of this quantity. The demonstration of the first property is trivial. Let us demonstrate the second one:
+\begin{equation*}
+\iiint\limits_D T\;\nabla .\left( {\textbf{A}}_{\textbf{I}} \nabla T \right)\,dv = -\iiint\limits_D \nabla T\;.\left( {\textbf{A}}_{\textbf{I}} \nabla T \right)\,dv
+\end{equation*}
+since
+\begin{multline*}
+ \nabla T\;.\left( {{\rm {\bf A}}_{\rm {\bf I}} \nabla T} 
+\right)=A^{lT}\left[ {\left( {\frac{\partial T}{\partial i}} \right)^2-2a_1 
+\frac{\partial T}{\partial i}\frac{\partial T}{\partial k}+\left( 
+{\frac{\partial T}{\partial j}} \right)^2} \right. \\ 
+\shoveright{ \left. {-2a_2 \frac{\partial T}{\partial j}\frac{\partial T}{\partial 
+k}+\left( {a_1 ^2+a_2 ^2} \right)\left( {\frac{\partial T}{\partial k}} 
+\right)^2} \right]} \\
+\end{multline*}
+
+\begin{equation*}
+=A_h \left[ {\left( {\frac{\partial T}{\partial i}-a_1 \frac{\partial T}{\partial k}} \right)^2+\left( {\frac{\partial T}{\partial j}-a_2 \frac{\partial T}{\partial k}} \right)^2} \right]\quad \geq 0
+\end{equation*}
+the property becomes obvious.
+\\
+Note that the resulting tensor is similar to those obtained for geopotential diffusion in $s$-coordinates. The simplification leads to a decoupling between $(i,z)$ and $(j,z)$ plans.
+
+The resulting diffusive operator in $z$-coordinates has the following 
+expression :
+\begin{multline*}
+ D^T=\frac{1}{e_1 e_2 }\left\{ {\;\frac{\partial }{\partial i}\left[ {A_h \left( {\frac{e_2 }{e_1 }\frac{\partial T}{\partial i}-a_1 \frac{e_2}{e_3}\frac{\partial T}{\partial k}} \right)} \right]\;} \right.\;\; \\ 
+ \;\left. {\;\;\;+\frac{\partial}{\partial j}\left[ {A_h \left( {\frac{e_1 }{e_2 }\frac{\partial T}{\partial j}-a_2 \frac{e_1 }{e_3 }\frac{\partial T}{\partial k}} \right)} \right]\;} \right\} \\
+\shoveright{+\frac{1}{e_3 }\frac{\partial }{\partial k}\left[ {A_h \left( {-\frac{a_1 }{e_1 }\frac{\partial T}{\partial i}-\frac{a_2 }{e_2 }\frac{\partial T}{\partial j}+\frac{\left( {a_1 ^2+a_2 ^2} \right)}{e_3 }\frac{\partial T}{\partial k}} \right)} \right]} \\ 
+\end{multline*}
+
+
+% ================================================================
+% Lateral/Vertical Momentum Diffusive Operators
+% ================================================================
+\section{Lateral/Vertical Momentum Diffusive Operators}
+\label{Apdx_B_3}
+
+
+*{\footnotesize }lateral/vertical{\footnotesize }2{\small nd}{\footnotesize 
+}order{\footnotesize }momentum diffusive operator
+
+Following (I.3.6), the Laplacian of the horizontal velocity can be expressed 
+in $z$-coordinates:
+\begin{equation*}
+\Delta {\textbf{U}}_h =\nabla \left( {\nabla \cdot {\textbf{U}}_h } \right)-
+\nabla \times \left( {\nabla \times {\textbf{U}}_h } \right)
+\end{equation*}
+
+\begin{equation*}
+=\left( {{\begin{array}{*{20}c}
+ {\frac{1}{e_1 }\frac{\partial \chi }{\partial i}} \hfill \\
+ {\frac{1}{e_2 }\frac{\partial \chi }{\partial j}} \hfill \\
+ {\frac{1}{e_3 }\frac{\partial \chi }{\partial k}} \hfill \\
+\end{array} }} \right)-\left( {{\begin{array}{*{20}c}
+ {\frac{1}{e_2 }\frac{\partial \zeta }{\partial j}-\frac{1}{e_3 
+}\frac{\partial }{\partial k}\left( {\frac{1}{e_3 }\frac{\partial 
+u}{\partial k}} \right)} \hfill \\
+ {\frac{1}{e_3 }\frac{\partial }{\partial k}\left( {-\frac{1}{e_3 
+}\frac{\partial v}{\partial k}} \right)-\frac{1}{e_1 }\frac{\partial \zeta 
+}{\partial i}} \hfill \\
+ {\frac{1}{e_1 e_2 }\left[ {\frac{\partial }{\partial i}\left( {\frac{e_2 
+}{e_3 }\frac{\partial u}{\partial k}} \right)-\frac{\partial }{\partial 
+j}\left( {-\frac{e_1 }{e_3 }\frac{\partial v}{\partial k}} \right)} \right]} 
+\hfill \\
+\end{array} }} \right)
+\end{equation*}
+\begin{equation*}
+=\left( {{\begin{array}{*{20}c}
+{\frac{1}{e_1 }\frac{\partial \chi }{\partial i}-\frac{1}{e_2 }\frac{\partial \zeta }{\partial j}} \\
+{\frac{1}{e_2 }\frac{\partial \chi }{\partial j}+\frac{1}{e_1 }\frac{\partial \zeta }{\partial i}} \\
+0 \\
+\end{array} }} \right)
++\frac{1}{e_3 }
+\left( {{\begin{array}{*{20}c}
+{\frac{\partial }{\partial k}\left( {\frac{1}{e_3 }\frac{\partial u}{\partial k}} \right)} \\
+{\frac{\partial }{\partial k}\left( {\frac{1}{e_3 }\frac{\partial v}{\partial k}} \right)} \\
+{\frac{\partial \chi }{\partial k}-\frac{1}{e_1 e_2 }\left( {\frac{\partial ^2\left( {e_2 \,u} \right)}{\partial i\partial k}+\frac{\partial ^2\left( {e_1 \,v} \right)}{\partial j\partial k}} \right)} \\
+\end{array} }} \right)
+\end{equation*}
+Using (I.3.8), the definition of the horizontal divergence, the third componant of the second vector is obviously zero and thus :
+\begin{equation*}
+\Delta {\textbf{U}}_h = \nabla _h \left( \chi \right) - \nabla _h \times \left( \zeta \right) + \frac {1}{e_3 } \frac {\partial }{\partial k} \left( {\frac {1}{e_3 } \frac{\partial {\textbf{ U}}_h }{\partial k}} \right)
+\end{equation*}
+
+
+The lateral/vertical second order (Laplacian type) operator used to diffuse 
+horizontal momentum in $z$-coordinates therefore takes the following expression :
+\begin{equation*}
+\begin{split}
+ {\textbf{D}}^{\textbf{U}}&={\textbf{D}}^{lm}+{\textbf{D}}^{vm} \\ 
+&=\nabla _h \left( {A^{lm}\;\chi } \right)-\nabla _h \times \left( {A^{lm}\;\zeta \;{\textbf{k}}} \right)+\frac{1}{e_3 }\frac{\partial }{\partial k}\left( {\frac{A^{vm}\;}{e_3 }\frac{\partial {\rm {\bf U}}_h }{\partial k}} \right) \\ 
+\end{split}
+\end{equation*}
+
+\begin{equation*}
+{\textbf{D}}^{\textbf{U}}=
+\left( {{\begin{array}{*{20}c}
+{\frac{1}{e_1 }\frac{\partial \left( {A^{lm}\chi } \right)}{\partial i}-\frac{1}{e_2 }\frac{\partial \left( {A^{lm}\zeta } \right)}{\partial j}} \\
+{\frac{1}{e_2 }\frac{\partial \left( {A^{lm}\chi } \right)}{\partial j}+\frac{1}{e_1 }\frac{\partial \left( {A^{lm}\zeta } \right)}{\partial i}} \\
+\end{array} }} \right)
++\frac{1}{e_3 }\frac{\partial }{\partial k}
+\left( {{\begin{array}{*{20}c}
+{\frac{A^{vm}}{e_3 }\frac{\partial u}{\partial k}} \\
+{\frac{A^{vm}}{e_3 }\frac{\partial v}{\partial k}} \\
+\end{array} }} \right)
+\end{equation*}
+
+% ================================================================
+% References
+% ================================================================
+\section{References}
+
+
+{\small Cox, M. D., 1987 : Isopycnal diffusion in a z-coordinate ocean 
+model. }{\small \textit{Ocean Modelling}}{\small , 74, 1-9.}
+
+{\small Redi, M. H., 1982 : oceanic isopycnal mixing by coordinate rotation. 
+}{\small \textit{J. Phys. Oceanogr., 13}}{\small , 1154-1158.}
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_C.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_C.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_C.tex	(revision 4536)
@@ -0,0 +1,1627 @@
+% ================================================================
+% Chapter Ñ Appendix C : Discrete Invariants of the Equations
+% ================================================================
+\chapter{Appendix C : Discrete Invariants of the Equations}
+\label{Apdx_C}
+\minitoc
+
+% ================================================================
+% Conservation Properties on Ocean Dynamics
+% ================================================================
+\section{Conservation Properties on Ocean Dynamics}
+\label{Apdx_C.1}
+
+
+First, the boundary condition on the vertical velocity (no flux through the surface and the bottom) is established for the discrete set of momentum equations. Then, it is shown that the non linear terms of the momentum equation are written such that the potential enstrophy of a horizontally non divergent flow is preserved while all the other non-diffusive terms preserve the kinetic energy: the energy is also preserved in practice. In addition, an option is also offer for the vorticity term discretization which provides 
+a total kinetic energy conserving discretization for that term. Note that although these properties are established in the curvilinear $s$-coordinate system, they still hold in the curvilinear $z$-coordinate system.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Bottom Boundary Condition on Vertical Velocity Field
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Bottom Boundary Condition on Vertical Velocity Field}
+\label{Apdx_C.1.1}
+
+
+The discrete set of momentum equations used in rigid lid approximation 
+automatically satisfies the surface and bottom boundary conditions 
+($w_{surface} =w_{bottom} =~0$, no flux through the surface and the bottom). 
+Indeed, taking the discrete horizontal divergence of the vertical sum of the 
+horizontal momentum equations (Eqs. (II.2.1) and (II.2.2)~) wheighted by the 
+vertical scale factors, it becomes:
+\begin{flalign*}
+\frac{\partial } {\partial t}
+	\left( 
+	\sum\limits_k \chi 
+	\right)
+\equiv \frac{\partial } {\partial t}
+	\left( 
+	w_{surface} -w_{bottom}  
+	\right)
+	&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv \frac{1} {e_{1T}\,e_{2T}\,e_{3T}} 
+	\biggl\{ \quad
+	\delta_i 
+		&\left[ 
+		e_{2u}\,H_u 
+			\left( 
+			M_u - M_u - \frac{1} {H_u\,e_{2u}} \delta_j 
+				\left[ \partial_t\, \psi \right] 
+			\right) 
+		\right] &&
+	\biggr. \\
+	\biggl. 
+	+ \delta_j 
+		&\left[ 
+		e_{1v}\,H_v 
+			\left( M_v - M_v - \frac{1} {H_v\,e_{1v}} \delta_i 
+				\left[ \partial_i\, \psi \right] 
+			\right) 
+		\right] 
+	\biggr\}&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv \frac{1} {e_{1T} \,e_{2T} \,e_{3T}} \;
+	\biggl\{ 
+	- \delta_i 
+		\Bigl[ 
+		\delta_j 
+			\left[ \partial_t \psi  \right] 
+		\Bigr]
+	+ \delta_j 
+		\Bigl[ 
+		\delta_i 
+			\left[ \partial_t \psi  \right] 
+		\Bigr]\; 
+	\biggr\}\;
+	\equiv 0
+	&&&\\
+\end{flalign*}
+
+
+The surface boundary condition associated with the rigid lid approximation ($w_{surface} =0)$ is imposed in the computation of the vertical velocity (II.2.5). Therefore, it turns out to be:
+\begin{equation*}
+\frac{\partial } {\partial t}w_{bottom} \equiv 0
+\end{equation*}
+As the bottom velocity is initially set to zero, it remains zero all the time. Symmetrically, if $w_{bottom} =0$ is used in the computation of the vertical velocity (upward integral of the horizontal divergence), the same computation leads to $w_{surface} =0$ as soon as the surface vertical velocity is initially set to zero.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Coriolis and advection terms: vector invariant form
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Coriolis and advection terms: vector invariant form}
+\label{Apdx_C.1.2}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Vorticity Term
+% -------------------------------------------------------------------------------------------------------------
+\subsubsection{Vorticity Term}
+\label{Apdx_C.1.2.1} 
+
+Potential vorticity is located at $f$-points and defined as: $\zeta / e_{3f}$. The standard discrete formulation of the relative vorticity term obviously conserves potential vorticity. It also conserves the potential enstrophy for a horizontally non-divergent flow (i.e. $\chi $=0) but not the total kinetic energy. Indeed, using the symmetry or skew symmetry properties of the operators (Eqs (II.1.10) and (II.1.11)), it can be shown that:
+\begin{equation} \label{Apdx_C_1.1}
+\int_D {\zeta / e_3\,\;{\textbf{k}}\cdot \frac{1} {e_3 }\nabla \times \left( {\zeta \;{\textbf{k}}\times {\textbf{U}}_h } \right)\;dv} \equiv 0
+\end{equation}
+
+where $dv=e_1 \,e_2 \,e_3 \;di\,dj\,dk$ is the volume element. Indeed, using 
+(II.2.11), the discrete form of the right hand side of (C.1.1) can be 
+transformed as follow:
+\begin{flalign*} 
+\int_D \zeta / e_3\,\; \textbf{k} \cdot \frac{1} {e_3 } \nabla \times 
+	\left( 
+	\zeta \; \textbf{k} \times  \textbf{U}_h  
+	\right)\;
+	dv
+	&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+\frac{\zeta / e_{3f}} {e_{1f}\,e_{2f}\,e_{3f}} 
+	\biggl\{ \quad
+	\delta_{i+1/2} 
+		&\left[ 
+		   - \overline {\left( {\zeta / e_{3f}} \right)}^{\,i}\;
+		      \overline{\overline {\left( e_{2u}\,e_{3u}\,u \right)}}^{\,i,j+1/ 2} 
+		 \right]  
+	&&
+	\biggr. \\ 
+	\biggl. 
+	- \delta_{j+1/2} 
+		&\left[	\;\;\;
+		     \overline {\left( \zeta / e_{3f} \right)}^{\,j}\;
+		     \overline{\overline {\left( e_{1v}\,e_{3v}\,v \right)}}^{\,i+1/2,j} 
+		\right] 
+	\biggr\} \;
+	e_{1f}\,e_{2f}\,e_{3f}
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{	\quad
+	\delta_i 
+		&\left[ \zeta / e_{3f} \right] \;
+		\overline {\left( \zeta / e_{3f} \right)}^{\,i}\; 
+		\overline{\overline {\left( e_{1u}\,e_{3u}\,u \right)}}^{\,i,j+1/2} 
+		&& 
+	\biggr. \\ 
+	\biggl. 
+	+ \delta_j 
+		&\left[ \zeta / e_{3f} \right] \;
+		\overline {\left( \zeta / e_{3f} \right)}^{\,j} \; 
+		\overline{\overline {\left( e_{2v}\,e_{3v}\,v \right)}}^{\,i+1/2,j}	\;
+	\biggr\} 
+		&&  \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \frac{1} {2} \sum\limits_{i,j,k}  
+	\biggl\{	\quad
+	\delta_i 
+		&\Bigl[ 
+			\left( \zeta / e_{3f} \right)^2 
+		\Bigr]\;
+	\overline{\overline {\left( e_{2u}\,e_{3u}\,u \right)}}^{\,i,j+1/2} 
+	&&
+	\biggr. \\ 
+	\biggl. 
+	+ \delta_j 
+		&\Bigl[ 
+			\left( \zeta / e_{3f} \right)^2 
+		\Bigr]\; 
+		\overline{\overline {\left( e_{1v}\,e_{3v}\,v \right)}}^{\,i+1/2,j} 
+	\biggr\} 
+	&&  \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv - \frac{1} {2} \sum\limits_{i,j,k} 	\left( \zeta / e_{3f} \right)^2\;
+	\biggl\{		\quad
+	\delta_{i+1/2} 
+		&\left[ 
+		\overline{\overline {\left( e_{2u}\,e_{3u}\,u \right)}}^{\,i,j+1/2} 
+		\right]  
+		&&
+	\biggr. \\ 
+	\biggl. 
+	+ \delta_{j+1/2}
+		&\left[ 
+		\overline{\overline {\left( e_{1v}\,e_{3v}\,v \right)}}^{\,i+1/2,j} 
+		\right]  
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+
+
+Since $\overline {\;\cdot \;} $ and $\delta $ operators commute: $\delta_{i+1/2} 
+\left[ {\overline a^{\,i}} \right] = \overline {\delta_i \left[ a \right]}^{\,i+1/2}$, 
+and introducing the horizontal divergence $\chi $, it becomes:
+\begin{equation*}
+\equiv \sum\limits_{i,j,k} - \frac{1} {2} \left( \zeta / e_{3f} \right)^2 \; \overline{\overline{ e_1T\,e_2T\,e_3T\, \chi}}^{\,i+1/2,j+1/2} \equiv 0
+\end{equation*}
+
+Note that the demonstration is done here for the relative potential 
+vorticity but it still hold for the planetary ($f/e_3$ ) and the total 
+potential vorticity $((\zeta +f) /e_3 )$. Another formulation of 
+the two components of the vorticity term is optionally offered :
+\begin{equation*}
+\frac{1} {e_3 }\nabla \times 
+	\left( 
+	\zeta \;{\textbf{k}}\times {\textbf {U}}_h 
+	\right)
+\equiv 
+	\left( {{
+	\begin{array} {*{20}c}
+		+ \frac{1} {e_{1u}} \; 
+		\overline {\left( \zeta / e_{3f} 	  \right)	
+		\overline {\left( e_{1v}\,e_{3v}\,v \right)}^{\,i+1/2}} ^{\,j} 
+		\hfill \\
+		- \frac{1} {e_{2v}} \; 
+		\overline {\left( \zeta / e_{3f}  	  \right)
+		\overline {\left( e_{2u}\,e_{3u}\,u \right)}^{\,j+1/2}} ^{\,i} 
+		\hfill \\
+	\end{array}} } 
+	\right)
+\end{equation*}
+
+This formulation does not conserve the enstrophy but the total kinetic 
+energy. It is also possible to mix the two formulations in order to conserve 
+enstrophy on the relative vorticity term and energy on the Coriolis term.
+\begin{flalign*}
+\int\limits_D \textbf{U}_h \times 
+	\left( 
+	\zeta \;\textbf{k} \times \textbf{U}_h 
+	\right)\;
+	dv
+	&&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ 	\quad
+	&   \overline {\left( \zeta / e_{3f}      \right) 
+	     \overline {\left( e_{1v}\,e_{3v}\,v \right)}^{\,i+1/2}} ^{\,j} \; e_{2u}\,e_{3u}\,u 
+	&&
+	\biggr. \\
+	\biggl. 
+	-& \overline {\left( \zeta / e_{3f}       \right) 
+	    \overline {\left( e_{2u}\,e_{3u}\,u \right)}^{\,j+1/2}} ^{\,i} \; e_{1v}\,e_{3v}\,v \;
+	\biggr\} 
+	&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}
+\Bigl( 
+\zeta / e_{3f} 
+\Bigr)\;
+	\biggl\{	\quad
+	&  \overline {\left( e_{1v}\,e_{3v} \,v \right)}^{\,i+1/2}\;\;
+	    \overline {\left( e_{2u}\,e_{3u} \,u \right)}^{\,j+1/2} 
+	&&
+	\biggr. \\ 
+	\biggl. 
+	-& \overline {\left( e_{2u}\,e_{3u} \,u \right)}^{\,j+1/2}\;\;
+	     \overline {\left( e_{1v}\,e_{3v} \,v \right)}^{\,i+1/2}\; 
+	\biggr\} \; 
+	\equiv 0
+	&& \\ 
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Gradient of Kinetic Energy / Vertical Advection
+% -------------------------------------------------------------------------------------------------------------
+\subsubsection{Gradient of Kinetic Energy / Vertical Advection}
+\label{Apdx_C.1.2.2} 
+
+The change of Kinetic Energy (KE) due to the vertical advection is exactly 
+balanced by the change of KE due to the horizontal gradient of KE~:
+\begin{equation*}
+      \int_D \textbf{U}_h \cdot \nabla_h \left( 1/2\;\textbf{U}_h^2 \right)\;dv
+ = - \int_D \textbf{U}_h \cdot w \frac{\partial \textbf{U}_h} {\partial k}\;dv
+\end{equation*}
+Indeed, using successively (II.1.10) and the continuity of mass (II.2.5), 
+(II.1.10), and the commutativity of operators $\overline {\,\cdot \,} $ and 
+$\delta$, and finally (II.1.11) successively in the horizontal and in the vertical 
+direction, it becomes:
+\begin{flalign*}
+\int_D \textbf{U}_h \cdot \nabla_h \left( 1/2\; \textbf{U}_h^2 \right)\;dv	&&&\\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \frac{1} {2} \sum\limits_{i,j,k} 
+	\biggl\{	\quad
+	&\frac{1} {e_{1u}}  \delta_{i+1/2} 
+		\left[ 
+		   \overline {u^2}^{\,i} 
+		+ \overline {v^2}^{\,j} 
+		\right]
+		\;u\;e_{1u}\,e_{2u}\,e_{3u}  
+		&&
+	\biggr. \\ 
+	\biggl. 
+	& + \frac{1} {e_{2v}}  \delta_{j+1/2} 
+		\left[ 
+		   \overline {u^2}^{\,i} 
+		+ \overline {v^2}^{\,j} 
+		\right]
+		\;v\;e_{1v}\,e_{2v}\,e_{3v}  \;
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv  &\frac{1} {2}\quad \sum\limits_{i,j,k} 
+	\left( 
+	   \overline {u^2}^{\,i}
+	+ \overline {v^2}^{\,j} 
+	\right)\;
+\delta_k 
+	\left[
+	 e_{1T}\,e_{2T} \,w 
+	 \right]
+	 && \\
+\end{flalign*}
+\begin{flalign*}
+\equiv &\frac{1} {2} - \sum\limits_{i,j,k}  \delta_{k+1/2} 
+	\left[ 
+	   \overline{ u^2}^{\,i} 
+	+ \overline{ v^2}^{\,j} 
+	\right] \;
+	e_{1v}\,e_{2v}\,w 
+	&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv &\frac{1} {2} \quad \sum\limits_{i,j,k} 
+	\left( 
+	   \overline {\delta_{k+1/2} \left[ u^2 \right]}^{\,i} 
+	+ \overline {\delta_{k+1/2} \left[ v^2 \right]}^{\,j} 
+	\right)\;
+	e_{1T}\,e_{2T} \,w 
+	&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv \frac{1} {2} \quad \sum\limits_{i,j,k} 
+	\biggl\{	\quad
+	& \overline {e_{1T}\,e_{2T} \,w}^{\,i+1/2}\;2 	\overline {u}^{\,k+1/2}\; \delta_{k+1/2} 
+		\left[ u \right] 
+	&&
+	\biggr. \\ 
+	\biggl.
+	& + \overline {e_{1T}\,e_{2T} \,w}^{\,j+1/2}\;2 	\overline {v}^{\,k+1/2}\; \delta_{k+1/2} 			\left[ v \right]  \;
+	\biggr\} 
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \quad -\sum\limits_{i,j,k}  
+	\biggl\{	\quad
+	&\frac{1} {b_u } \;
+	\overline {\Bigl\{ \overline {e_{1T}\,e_{2T} \,w}^{\,i+1/2}\,\delta_{k+1/2}
+		\left[ u \right] 
+		       \Bigr\} }^{\,k} \;u\;e_{1u}\,e_{2u}\,e_{3u}  
+	&&
+	\biggr. \\ 
+	\biggl.  
+	& + \frac{1} {b_v } \;
+	\overline {\Bigl\{ \overline {e_{1T}\,e_{2T} \,w}^{\,j+1/2} \delta_{k+1/2}
+		 \left[ v \right] 
+		 	\Bigr\} }^{\,k} \;v\;e_{1v}\,e_{2v}\,e_{3v}  \;
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv -\int\limits_D \textbf{U}_h \cdot w \frac{\partial \textbf{U}_h} {\partial k}\;dv	&&&\\
+\end{flalign*}
+
+The main point here is that the respect of this property links the choice of the discrete formulation of vertical advection and of horizontal gradient of KE. Choosing one imposes the other. For example KE can also be defined as $1/2(\overline u^{\,i} + \overline v^{\,j})$, but this leads to the following expression for the vertical advection~:
+\begin{equation*}
+\frac{1} {e_3 }\; w\; \frac{\partial \textbf{U}_h } {\partial k}
+\equiv \left( {{\begin{array} {*{20}c}
+\frac{1} {e_{1u}\,e_{2u}\,e_{3u}} \;
+\overline{\overline {e_{1T}\,e_{2T} \,w\;\delta_{k+1/2} 
+\left[ \overline u^{\,i+1/2} \right]}}^{\,i+1/2,k}  \hfill \\
+\frac{1} {e_{1v}\,e_{2v}\,e_{3v}} \;
+\overline{\overline {e_{1T}\,e_{2T} \,w\;\delta_{k+1/2}
+\left[ \overline v^{\,j+1/2} \right]}}^{\,j+1/2,k} \hfill \\
+\end{array}} } \right)
+\end{equation*}
+
+This formulation requires one more horizontal mean, and thus the use of 9 velocity points instead of 3. This is the reason why it has not been retained in the model.
+% -------------------------------------------------------------------------------------------------------------
+%       Coriolis and advection terms: flux form
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Coriolis and advection terms: flux form}
+\label{Apdx_C.1.3}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Coriolis plus ``metric'' Term
+% -------------------------------------------------------------------------------------------------------------
+\subsubsection{Coriolis plus ``metric'' Term}
+\label{Apdx_C.1.3.1} 
+
+In flux from the vorticity term reduces to a Coriolis term in which the Coriolis parameter has been modified to account for the ``metric'' term. This altered Coriolis parameter is thus discretised at F-point. It is given by: 
+\begin{equation*}
+f+\frac{1} {e_1 e_2 } 
+\left( v \frac{\partial e_2 } {\partial i} - u \frac{\partial e_1 } {\partial j}\right)\;
+\equiv \;
+f+\frac{1} {e_{1f}\,e_{2f}} 
+\left( \overline v^{\,i+1/2} \delta_{i+1/2} \left[ e_{2u} \right] 
+-\overline u^{\,j+1/2} \delta_{j+1/2} \left[ e_{1u}  \right] \right)
+\end{equation*}
+
+Then any of the scheme presented above for the vorticity term in the vector invariant formulation can be used, except of course the mixed scheme. However, the energy conserving scheme has exclusively been used to date.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Flux form advection
+% -------------------------------------------------------------------------------------------------------------
+\subsubsection{Flux form advection}
+\label{Apdx_C.1.3.2} 
+
+The flux form operator of the momentum advection is evaluated using a second order finite difference scheme. Because of the flux form, the discrete operator does not contribute to the global budget of linear momentum. Moreover, it conserves the horizontal kinetic energy, that is :
+
+\begin{equation} \label{Apdx_C_I.3.10}
+\int_D \textbf{U}_h \cdot 
+\left( {{\begin{array} {*{20}c}
+\nabla \cdot \left( \textbf{U}\,u \right) \hfill \\
+\nabla \cdot \left( \textbf{U}\,v \right) \hfill \\
+\end{array}} } \right)\;dv =\;0
+\end{equation}
+
+Let us demonstrate this property for the first term of the scalar product (i.e. considering just the the terms associated with the i-component of the advection):
+\begin{flalign*}
+\int_D u \cdot \nabla \cdot \left( \textbf{U}\,u \right)\;dv	&&&\\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ 
+	\frac{1} {e_{1u}\, e_{2u}\,e_{3u}} 
+		\biggl(	\quad	\biggr.
+		&    \delta_{i+1/2} 
+			\left[ 
+			\overline {e_{2u}\,e_{3u}\,u}^{\,i}\;\overline u^{\,i} 
+			\right]
+		&& \\
+		& + \delta_j 
+			\left[ 
+			\overline {e_{1u}\,e_{3u}\,v}^{\,i+1/2}\;\overline u^{\,j+1/2} 
+			\right] 
+		&&
+	\biggr.\\ 
+	\biggl. 
+		& + \delta_k  		\biggl. 
+			\left[ 
+			\overline {e_{1w}\,e_{2w}\,w}^{\,i+1/2}\;\overline u^{\,k+1/2} 
+			\right]\; 
+		\biggr)\; 
+	\biggr\} \, 
+	e_{1u}\,e_{2u}\,e_{3u} \;u 
+	&& \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ 
+	\delta_{i+1/2} 
+		\left[ 
+		\overline {e_{2u}\,e_{3u}\,u}^{\,i}\;	  \overline u^{\,i} 
+		\right]
+	& + \delta_j 
+		\left[ 
+		\overline {e_{1u}\,e_{3u}\,v}^{\,i+1/2}\;\overline u^{\,j+1/2} 
+		\right]
+	&&
+	\biggr.\\
+	\biggl.
+	& + \delta_k 
+		\left[ 
+		\overline {e_{1w}\,e_{2w}\,w}^{\,i+12}\;\overline u^{\,k+1/2} 
+		\right]\; 
+	\biggr\}
+	&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}
+	\biggl\{ 
+	   \overline {e_{2u}\,e_{3u}\,u}^{\,i}\;			\overline u^{\,i} 		\delta_i 
+		\left[ u \right] 
+	& + \overline {e_{1u}\,e_{3u}\,v}^{\,i+1/2}\;	\overline u^{\,j+1/2} 	\delta_{j+1/2} 
+		\left[ u \right] 
+	&&
+	\biggr. \\
+	\biggl.
+	& + \overline {e_{1w}\,e_{2w}\,w}^{\,i+1/2}\;	\overline u^{\,k+1/2}	\delta_{k+1/2} 
+		\left[ u \right] 
+	\biggr\} 
+	&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}
+	\biggl\{ 
+	     \overline {e_{2u}\,e_{3u}\,u}^{\,i} 			\delta_i 		\left[ u^2 \right] 
+	& + \overline {e_{1u}\,e_{3u}\,v}^{\,i+1/2} 		\delta_{j+/2} 	\left[ u^2 \right]
+	&& 
+	\biggr. \\
+	\biggl.
+	& + \overline {e_{1w}\,e_{2w}\,w}^{\,i+1/2} 	\delta_{k+1/2} 	\left[ u^2 \right] 
+	\biggr\} 
+	&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}
+	\bigg\{ 
+	   e_{2u}\,e_{3u}\,u\;		\delta_{i+1/2} 	   \left[ \overline {u^2}^{\,i} \right]
+	& + e_{1u}\,e_{3u}\,v\;	\delta_{j+1/2} 	\; \left[ \overline {u^2}^{\,i} \right]
+	&&
+	\biggr.\\
+	\biggl.
+	& + e_{1w}\,e_{2w}\,w\;	\delta_{k+1/2}  	   \left[ \overline {u^2}^{\,i} \right] 
+	\biggr\} 
+	&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}
+\overline {u^2}^{\,i} 
+	\biggl\{ 
+	   \delta_{i+1/2} 	\left[ e_{2u}\,e_{3u}\,u  \right]
+	+ \delta_{j+1/2} 	\left[ e_{1u}\,e_{3u}\,v  \right]
+	+ \delta_{k+1/2} 	\left[ e_{1w}\,e_{2w}\,w \right] 
+	\biggr\} 
+	&&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv 0 	&&&\\
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Hydrostatic Pressure Gradient Term
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Hydrostatic Pressure Gradient Term}
+\label{Apdx_C.1.4}
+
+
+A pressure gradient has no contribution to the evolution of the vorticity as the curl of a gradient is zero. In $z-$coordinates, this properties is satisfied locally with the choice of discretization we have made (property (II.1.9)~). When the equation of state is linear (i.e. when a advective-diffusive equation for density can be derived from those of temperature and salinity) the change of KE due to the work of pressure forces is balanced by the change of potential energy due to buoyancy forces. 
+\begin{equation*}
+\int_D - \frac{1} {\rho_o} \left. \nabla p^h \right|_z \cdot \textbf{U}_h \;dv 
+= \int_D \nabla \cdot \left( \rho \,\textbf {U} \right)\;g\;z\;\;dv
+\end{equation*}
+
+This property is satisfied in both $z- $and $s-$coordinates. Indeed, defining the depth of a $T$-point, $z_T$ defined as the sum of the vertical scale factors at $w$-points starting from the surface, it can be written as:
+\begin{flalign*}
+\int_D - \frac{1} {\rho_o} \left. \nabla p^h \right|_z \cdot \textbf{U}_h \;dv 	&&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ \;		
+	& - \frac{1} {\rho_o e_{1u}} 
+		\Bigl( 
+		\delta_{i+1/2} \left[ p^h \right] - g\;\overline \rho^{\,i+1/2}\;\delta_{i+1/2} 
+			\left[ z_T \right] 
+		\Bigr)\;
+		u\;e_{1u}\,e_{2u}\,e_{3u}  
+	&&
+	\biggr. \\ 
+	\biggl.
+	& - \frac{1} {\rho_o e_{2v}} 	 
+		\Bigl( 
+		\delta_{j+1/2} \left[ p^h \right] - g\;\overline \rho^{\,j+1/2}\delta_{j+1/2} 
+			\left[ z_T \right] 
+		\Bigr)\;
+		v\;e_{1v}\,e_{2v}\,e_{3v} \;
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+
+Using (II.1.10), the continuity equation (II.2.5), and the hydrostatic 
+equation (II.2.4), it turns out to be: 
+\begin{multline*} 
+\equiv \frac{1} {\rho_o} \sum\limits_{i,j,k} 	
+	\biggl\{ 
+		e_{2u}\,e_{3u} \;u\;g\;	\overline \rho^{\,i+1/2}\;\delta_{i+1/2}[ z_T]    
+	+ 	e_{1v}\,e_{3v} \;v\;g\;	\overline \rho^{\,j+1/2}\;\delta_{j+1/2}[ z_T]  
+	 \biggr. \\  
+\shoveright {
+	+\biggl. 
+		\Bigl(
+		 \delta_i[ e_{2u}\,e_{3u}\,u] + \delta_j [ e_{1v}\,e_{3v}\,v]
+		 \Bigr)\;p^h
+	\biggr\} } \\
+\end{multline*}
+
+\begin{multline*}
+\equiv \frac{1} {\rho_o } \sum\limits_{i,j,k}
+	\biggl\{ 
+		 e_{2u}\,e_{3u} \;u\;g\;	\overline \rho^{\,i+1/2} \delta_{i+1/2} \left[ z_T \right]
+	+ 	e_{1v}\,e_{3v} \;v\;g\;	\overline \rho^{\,j+1/2} \delta_{j+1/2} \left[ z_T \right] 
+	\biggr. \\ 
+\shoveright {
+	\biggl. 
+	 - \delta_k 
+		\left[ e_{1w} e_{2w}\,w \right]\;p^h 
+	\biggr\} } \\ 
+\end{multline*}
+
+\begin{multline*}
+\equiv \frac{1} {\rho_o } \sum\limits_{i,j,k}
+	\biggl\{ 
+		e_{2u}\,e_{3u} \;u\;g\;	\overline \rho^{\,i+1/2}\;\delta_{i+1/2} \left[ z_T \right]
+	+ 	e_{1v}\,e_{3v} \;v\;g\;	\overline \rho^{\,j+1/2} \;\delta_{j+1/2} \left[ z_T \right] 	\biggr. \\ 
+\shoveright{
+	\biggl. 
+	+	 e_{1w} e_{2w} \;w\;\delta_{k+1/2} \left[ p_h \right] 
+	\biggr\} }  \\ 
+\end{multline*}
+
+\begin{multline*}
+\equiv \frac{g} {\rho_o}  \sum\limits_{i,j,k}
+	\biggl\{ 
+		e_{2u}\,e_{3u} \;u\;	\overline \rho^{\,i+1/2}\;\delta_{i+1/2} \left[ z_T \right]
+	+	e_{1v}\,e_{3v} \;v\;	\overline \rho^{\,j+1/2}\;\delta_{j+1/2} \left[ z_T \right] 		\biggr. \\
+\shoveright{ 
+	\biggl. 
+	- 	e_{1w} e_{2w} \;w\;e_{3w} \overline \rho^{\,k+1/2} 
+	\biggr\} }  \\ 
+\end{multline*}
+noting that by definition of $z_T$, $\delta_{k+1/2} \left[ z_T \right] \equiv - e_{3w} $, thus:
+\begin{multline*}
+\equiv \frac{g} {\rho_o}  \sum\limits_{i,j,k}
+	\biggl\{ 
+		e_{2u}\,e_{3u} \;u\;	\overline \rho^{\,i+1/2}\;\delta_{i+1/2} \left[ z_T \right]
+	+ 	e_{1v}\,e_{3v} \;v\;	\overline \rho^{\,j+1/2} \delta_{j+1/2} \left[ z_T \right]
+	\biggr. \\ 
+\shoveright{
+	\biggl. 
+	+ 	e_{1w} e_{2w} \;w\;	\overline \rho^{\,k+1/2}\;\delta_{k+1/2} \left[ z_T \right] 
+	\biggr\} } \\ 
+\end{multline*}
+Using (II.1.10), it becomes~:
+\begin{flalign*}
+\equiv - \frac{g} {\rho_o} \sum\limits_{i,j,k} z_T 
+	\biggl\{ 
+		\delta_i 	\left[ e_{2u}\,e_{3u}\,u\;	\overline \rho^{\,i+1/2} 	\right]
+	+ 	\delta_j 	\left[ e_{1v}\,e_{3v}\,v\;	\overline \rho^{\,j+1/2} 	\right]
+	+ 	\delta_k 	\left[ e_{1w} e_{2w}\,w\;	\overline \rho^{\,k+1/2} 	\right] 
+	\biggr\} 
+	&&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv -\int_D \nabla \cdot \left( \rho \, \textbf{U} \right)\;g\;z\;\;dv 	&&& \\
+\end{flalign*}
+
+Note that this property strongly constraints the discrete expression of both 
+the depth of $T-$points and of the term added to the pressure gradient in 
+$s-$coordinates. 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Surface Pressure Gradient Term
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Surface Pressure Gradient Term}
+\label{Apdx_C.1.5}
+
+
+The surface pressure gradient has no contribution to the evolution of the vorticity. This property is trivially satisfied locally as the equation verified by $\psi $ has been derived from the discrete formulation of the momentum equation and of the curl. But it has to be noticed that since the elliptic equation verified by $\psi $ is solved numerically by an iterative solver (preconditioned conjugate gradient or successive over relaxation), the 
+property is only satisfied at the precision required on the solver used.
+
+With the rigid-lid approximation, the change of KE due to the work of surface pressure forces is exactly zero. This is satisfied in discrete form, at the precision required on the elliptic solver used to solve this equation. This can be demonstrated as follows:
+\begin{flalign*}
+\int\limits_D  - \frac{1} {\rho_o} \nabla_h \left( p_s \right) \cdot \textbf{U}_h \;dv	&&& \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ 	\quad
+		& \left( 
+		 - M_u - \frac{1} {H_u \,e_{2u}}  \delta_j 	\left[ \partial_t \psi  \right] 
+		  \right)\;
+		  u\;e_{1u}\,e_{2u}\,e_{3u} 
+	&&
+	\biggr. \\
+	\biggl. 
+		+ & \left( 
+		   - M_v + \frac{1} {H_v \,e_{1v}}  \delta_i \left[ \partial_t \psi \right] 
+		    \right)\;
+		    v\;e_{1v}\,e_{2v}\,e_{3v} 	\;
+	\biggr\} 
+	&&  \\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j} 
+	\Biggl\{ 	\quad
+		&\biggl( 
+		- M_u - \frac{1} {H_u \,e_{2u}}  \delta_j \left[ \partial_t \psi  \right] 
+		\biggr)
+		\biggl( 
+		\sum\limits_k  u\;e_{3u}  
+		\biggr)\;
+		e_{1u}\,e_{2u} 
+	&&
+	\Biggr.  \\
+	\Biggl. 
+	+ & \biggl( 
+		- M_v + \frac{1} {H_v \,e_{1v}}  \delta_i \left[ \partial_t \psi  \right]
+	      \biggr)
+	      \biggl( 
+	      \sum\limits_k   v\;e_{3v}
+	       \biggr)\;
+	       e_{1v}\,e_{2v} \;
+	\Biggr\} 
+	&& \\ 
+\end{flalign*}
+using the relation between \textit{$\psi $} and the vertically sum of the velocity, it becomes~:
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j} 
+	\biggl\{ 	\quad
+		&\left( 
+		M_u + \frac{1} {H_u \,e_{2u}}  \delta_j \left[ \partial_t \psi \right] 
+		\right)\;
+		e_{1u} \,\delta_j 
+			\left[ \partial_t \psi  \right] 
+	&&
+	\biggr. \\ 
+	\biggl. 
+		+& \left( 
+		- M_v + \frac{1} {H_v \,e_{1v}}  \delta_i \left[ \partial_t \psi \right] 
+		\right)\;
+		e_{2v} \,\delta_i \left[ \partial_t \psi \right] 	\;
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+applying the adjoint of the $\delta$ operator, it is now:
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j}  - \partial_t \psi \;
+	\biggl\{ 	\quad
+	&  \delta_{j+1/2} \left[ e_{1u} M_u \right] 
+	  - \delta_{i+1/2} \left[ e_{1v} M_v \right] 
+	&&
+	\biggr.  \\ 
+	\biggl. 
+	+& \delta_{i+1/2} 
+		\left[ \frac{e_{2v}} {H_v \,e_{2v}}  \delta_i \left[ \partial_t \psi \right] 
+		\right] 
+	+ \delta_{j+1/2} 
+	 	 \left[ \frac{e_{1u}} {H_u \,e_{2u}}  \delta_j \left[ \partial_t \psi \right] 
+		 \right]  
+	\biggr\} 
+	\equiv 0 
+	&& \\ 
+\end{flalign*}
+
+The last equality is obtained using (II.2.3), the discrete barotropic streamfunction time evolution equation. By the way, this shows that (II.2.3) is the only way do compute the streamfunction, otherwise the surface pressure forces will work. Nevertheless, since the elliptic equation verified by $\psi $ is solved numerically by an iterative solver, the property is only satisfied at the precision required on the solver.
+
+% ================================================================
+% Conservation Properties on Tracers
+% ================================================================
+\section{Conservation Properties on Tracers}
+\label{Apdx_C.2}
+
+
+The numerical schemes are written such that the heat and salt contents are conserved by the internal dynamics (equations in flux form, second order centered finite differences). As a form flux is used to compute the temperature and salinity, the quadratic form of these quantities (i.e. their variance) is globally conserved, too. There is generally no strict conservation of mass, as the equation of state is non linear with respect to $T$ and $S$. In practice, the mass is conserved with a very good accuracy. 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Advection Term
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Advection Term}
+\label{Apdx_C.2.1}
+
+Conservation of the tracer
+
+The flux form 
+\begin{flalign*}
+\int_D \nabla \cdot \left( T \textbf{U} \right)\;dv &&&
+\end{flalign*}
+\begin{flalign*}
+ \equiv  \sum\limits_{i,j,k}     \left\{
+	 \frac{1} {e_{1T}\,e_{2T}\,e_{3T}} 
+	 \left( 
+	  \delta_i 
+	  	\left[ 
+		e_{2u}\,e_{3u} \,\overline T^{\,i+1/2}\,u 
+		\right]
+	 \right. \right.
+& + \left. \delta_j \left[ e_{1v}\,e_{3v} \,\overline T^{\,j+1/2}\,v \right] \right) && \\ 
+ & + \left. \frac{1} {e_{3T}} \delta_k \left[ \overline T^{\,k+1/2}\,w \right] \ \ \right\} 
+ 	\ \ e_{1T}\,e_{2T}\,e_{3T} &&
+\end{flalign*}
+
+\begin{flalign*}
+ \equiv&  \sum\limits_{i,j,k}     \left\{
+	   \delta_i  \left[ e_{2u}\,e_{3u}  \,\overline T^{\,i+1/2}\,u \right]
+       	+ \delta_j  \left[ e_{1v}\,e_{3v}  \,\overline T^{\,j+1/2}\,v \right] 
+ 	+ \delta_k \left[ e_{1T}\,e_{2T} \,\overline T^{\,k+1/2}\,w \right] \right\} 
+ 	 && 
+\end{flalign*}
+\begin{flalign*}
+ \equiv 0 &&&
+\end{flalign*}
+
+Conservation of the variance of tracer
+\begin{flalign*}
+\int\limits_D T\;\nabla \cdot \left( T\; \textbf{U} \right)\;dv &&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv& \sum\limits_{i,j,k} T\;
+	\left\{
+	   \delta_i  \left[ e_{2u}\,e_{3u} \overline T^{\,i+1/2}\,u \right]
+	+ \delta_j  \left[ e_{1v}\,e_{3v} \overline T^{\,j+1/2}\,v \right]
+	+ \delta_k \left[ e_{1T}\,e_{2T} \overline T^{\,k+1/2}w \right]
+	\right\} 
+	&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\left\{
+	-           e_{2u}\,e_{3u} \overline T^{\,i+1/2}\,u\,\delta_{i+1/2}  \left[ T \right] \right.
+	-&        e_{1v}\,e_{3v}  \overline T^{\,j+1/2}\,v\;\delta_{j+1/2}  \left[ T \right]
+	 &&\\
+	-& \left. e_{1T}\,e_{2T} \overline T^{\,k+1/2}w\;\delta_{k+1/2} \left[ T \right]
+	\right\} 
+	&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv&  -\frac{1} {2}  \sum\limits_{i,j,k}
+	\Bigl\{
+	   e_{2u}\,e_{3u} \;  u\;\delta_{i+1/2} \left[ T^2 \right]
+	+ e_{1v}\,e_{3v} \;  v\;\delta_{j+1/2}  \left[ T^2 \right]
+	+ e_{1T}\,e_{2T} \;w\;\delta_{k+1/2} \left[ T^2 \right]
+	\Bigr\} 
+	&& \\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv& \frac{1} {2}  \sum\limits_{i,j,k} T^2
+	\Bigl\{
+	   \delta_i  \left[ e_{2u}\,e_{3u}\,u \right]
+	+ \delta_j  \left[ e_{1v}\,e_{3v}\,v \right]
+	+ \delta_k \left[ e_{1T}\,e_{2T}\,w \right]
+	\Bigr\} 
+	&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv 0 &&&
+\end{flalign*}
+
+
+% ================================================================
+% Conservation Properties on Lateral Momentum Physics
+% ================================================================
+\section{Conservation Properties on Lateral Momentum Physics}
+\label{Apdx_C.3}
+
+
+The discrete formulation of the horizontal diffusion of momentum ensures the 
+conservation of potential vorticity and horizontal divergence and the 
+dissipation of the square of these quantities (i.e. enstrophy and the 
+variance of the horizontal divergence) as well as the dissipation of the 
+horizontal kinetic energy. In particular, when the eddy coefficients are 
+horizontally uniform, it ensures a complete separation of vorticity and 
+horizontal divergence fields, so that diffusion (dissipation) of vorticity 
+(enstrophy) does not generate horizontal divergence (variance of the 
+horizontal divergence) and \textit{vice versa}. 
+
+These properties of the horizontal diffusive operator are a direct 
+consequence of properties (II.1.8) and (II.1.9). When the vertical curl of 
+the horizontal diffusion of momentum (discrete sense) is taken, the term 
+associated to the horizontal gradient of the divergence is zero locally. 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation of Potential Vorticity
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Conservation of Potential Vorticity}
+\label{Apdx_C.3.1}
+
+The lateral momentum diffusion term conserves the potential vorticity :
+\begin{flalign*}
+\int \limits_D \frac{1} {e_3 } \textbf{k} \cdot \nabla \times 
+	\Bigl[ \nabla_h 
+		\left( A^{\,lm}\;\chi  \right)
+	- \nabla_h \times
+		\left( A^{\,lm}\;\zeta \; \textbf{k} \right)
+	\Bigr]\;dv &&& \\
+\end{flalign*}
+\begin{flalign*}
+= \int \limits_D  -\frac{1} {e_3 } \textbf{k} \cdot \nabla \times 
+	\Bigl[ \nabla_h \times 
+		\left( A^{\,lm}\;\zeta \; \textbf{k} \right) 
+	\Bigr]\;dv &&& \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv& \sum\limits_{i,j}
+	\left\{
+	\delta_{i+1/2} 
+	\left[ 
+	\frac {e_{2v}} {e_{1v}\,e_{3v}}  \delta_i
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]
+	 \right]
+ 	+ \delta_{j+1/2} 
+	\left[ 
+	\frac {e_{1u}} {e_{2u}\,e_{3u}} \delta_j 
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]
+	\right]
+	\right\} 
+	&& \\ 
+\end{flalign*}
+Using (II.1.10), it follows:
+
+\begin{flalign*}
+\equiv& \sum\limits_{i,j,k} 
+	-\,\left\{
+	   \frac{e_{2v}} {e_{1v}\,e_{3v}}  \delta_i
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]\;\delta_i \left[ 1\right]
+	+ \frac{e_{1u}} {e_{2u}\,e_{3u}} \delta_j 
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]\;\delta_j \left[ 1\right]
+	\right\} \quad \equiv 0 
+	&& \\ 
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Dissipation of Horizontal Kinetic Energy
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Dissipation of Horizontal Kinetic Energy}
+\label{Apdx_C.3.2}
+
+
+The lateral momentum diffusion term dissipates the horizontal kinetic 
+energy:
+\begin{flalign*}
+\int_D \textbf{U}_h \cdot 
+	\left[ \nabla_h 
+		\left( A^{\,lm}\;\chi \right)
+	- \nabla_h \times 
+		\left( A^{\,lm}\;\zeta \;\textbf{k} \right) 
+	\right]\;dv &&& \\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} \quad
+	&\left\{
+	\frac{1} {e_{1u}}            \delta_{i+1/2}
+		\left[ A_T^{\,lm} \chi  \right]
+	- \frac{1} {e_{2u}\,e_{3u}}  \delta_j
+		\left[ A_f^{\,lm} e_{3f} \zeta   \right]
+	\right\}\; 
+	e_{1u}\,e_{2u}\,e_{3u} \;u 
+	 &&\\
+	& + \left\{
+	\frac{1} {e_{2u}}             \delta_{j+1/2}
+		\left[ A_T^{\,lm} \chi  \right] 
+	+ \frac{1} {e_{1v}\,e_{3v}} \delta_i
+	\left[ A_f^{\,lm} e_{3f} \zeta  \right] 
+	\right\}\; 
+	e_{1v}\,e_{2u}\,e_{3v} \;v  
+	&& \\ 
+\end{flalign*}
+\begin{flalign*} 
+\equiv \sum\limits_{i,j,k} \quad
+ 	&\left\{
+	  e_{2u}\,e_{3u} \;u\;\delta_{i+1/2} 
+		\left[ A_T^{\,lm} \chi  \right]
+	- e_{1u} \;u\;\delta_j 
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]
+	 \right\} 
+	 &&\\ 
+	& + \left\{
+	   e_{1v}\,e_{3v} \;v\;\delta_{j+1/2} 
+		\left[ A_T^{\,lm} \chi  \right]
+	+ e_{2v} \;v\;\delta_i 
+		\left[ A_f^{\,lm} e_{3f} \zeta  \right]
+	\right\} 
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} \quad
+	-& \Bigl(
+	  \delta_i 
+		\left[ e_{2u}\,e_{3u} \;u \right]
+	+ \delta_j 
+		\left[ e_{1v}\,e_{3v} \;v \right] 
+	     \Bigr)\;
+	A_T^{\,lm} \chi 
+	&& \\ 
+	-& \Bigl(
+	  \delta_{i+1/2} 
+		\left[ e_{2v} \;v \right]
+	- \delta_{j+1/2} 
+		\left[ e_{1u} \;u \right] 
+	     \Bigr)\;
+	A_f^{\,lm} e_{3f} \zeta 
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	- A_T^{\,lm} \,\chi^2   \;e_{1T}\,e_{2T}\,e_{3T}
+	- A_f^{\,lm}  \,\zeta^2 \;e_{1f}\,e_{2f}\,e_{3f}  
+	\quad \leq 0
+	&&&\\
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Dissipation of Enstrophy
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Dissipation of Enstrophy}
+\label{Apdx_C.3.3}
+
+
+The lateral momentum diffusion term dissipates the enstrophy when the eddy 
+coefficients are horizontally uniform:
+\begin{flalign*}
+\int\limits_D  \zeta \; \textbf{k} \cdot \nabla \times 
+	\left[ 
+	  \nabla_h 
+		\left( A^{\,lm}\;\chi  \right)
+	-\nabla_h \times 
+		\left( A^{\,lm}\;\zeta \; \textbf{k} \right)
+	\right]\;dv &&&\\
+\end{flalign*}
+\begin{flalign*}
+ = A^{\,lm} \int \limits_D \zeta \textbf{k} \cdot \nabla \times 
+ 	\left[ 
+	\nabla_h \times 
+		\left( \zeta \; \textbf{k} \right)
+	\right]\;dv &&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv A^{\,lm} \sum\limits_{i,j,k}  \zeta \;e_{3f} 
+	\left\{
+	  \delta_{i+1/2} 
+	\left[ 
+	\frac{e_{2v}} {e_{1v}\,e_{3v}} \delta_i 
+		\left[ e_{3f} \zeta  \right]
+	\right]
+	+ \delta_{j+1/2} 
+	\left[
+	\frac{e_{1u}} {e_{2u}\,e_{3u}} \delta_j 
+		\left[ e_{3f} \zeta  \right]
+	\right]
+	\right\} 
+	&&&\\ 
+\end{flalign*}
+Using (II.1.10), it becomes~:
+
+\begin{flalign*}
+\equiv  - A^{\,lm} \sum\limits_{i,j,k} 
+	\left\{
+	  \left( 
+	  \frac{1} {e_{1v}\,e_{3v}}  \delta_i 
+		\left[ e_{3f} \zeta  \right] 
+	  \right)^2   e_{1v}\,e_{2v}\,e_{3v}
+	+ \left(
+	  \frac{1} {e_{2u}\,e_{3u}}  \delta_j 
+	  	\left[ e_{3f} \zeta  \right]
+	  \right)^2   e_{1u}\,e_{2u}\,e_{3u}
+	  \right\} 
+	  \; \leq \;0 
+	  &&&\\ 
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation of Horizontal Divergence
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Conservation of Horizontal Divergence}
+\label{Apdx_C.3.4}
+
+When the horizontal divergence of the horizontal diffusion of momentum 
+(discrete sense) is taken, the term associated to the vertical curl of the 
+vorticity is zero locally, due to (II.1.8). The resulting term conserves the 
+$\chi$ and dissipates $\chi^2$ when the eddy coefficients are 
+horizontally uniform.
+\begin{flalign*}
+  \int\limits_D  \nabla_h \cdot 
+	\Bigl[ 
+	  \nabla_h 
+		\left( A^{\,lm}\;\chi \right)
+	- \nabla_h \times 
+		\left( A^{\,lm}\;\zeta \;\textbf{k} \right)
+	\Bigr]
+	dv
+= \int\limits_D  \nabla_h \cdot \nabla_h 
+	\left( A^{\,lm}\;\chi  \right)
+	dv 
+&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\left\{ 
+	  \delta_i
+		\left[ 
+		A_u^{\,lm} \frac{e_{2u}\,e_{3u}} {e_{1u}}  \delta_{i+1/2} 
+			\left[ \chi \right] 
+		\right]
+	+ \delta_j 
+		\left[ 
+		A_v^{\,lm} \frac{e_{1v}\,e_{3v}} {e_{2v}}  \delta_{j+1/2} 
+			\left[ \chi \right] 
+		\right] 
+	\right\}
+	&&&\\ 
+\end{flalign*}
+Using (II.1.10), it follows:
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	- \left\{
+	\frac{e_{2u}\,e_{3u}} {e_{1u}}  A_u^{\,lm} \delta_{i+1/2} 
+		\left[ \chi \right]
+	\delta_{i+1/2} 
+		\left[ 1 \right] 
+	+ \frac{e_{1v}\,e_{3v}} {e_{2v}}  A_v^{\,lm} \delta_{j+1/2} 
+		\left[ \chi \right]
+	\delta_{j+1/2} 
+		\left[ 1 \right]
+	\right\} \;
+	\equiv 0 
+	&&& \\ 
+\end{flalign*}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Dissipation of Horizontal Divergence Variance
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Dissipation of Horizontal Divergence Variance}
+\label{Apdx_C.3.5}
+
+\begin{flalign*}
+		\int\limits_D \chi \;\nabla_h \cdot 
+	\left[ 
+	  \nabla_h 
+		\left( A^{\,lm}\;\chi  \right)
+	- \nabla_h \times 
+		\left( A^{\,lm}\;\zeta \;\textbf{k} \right)
+	\right]\;
+	dv
+ = A^{\,lm}   \int\limits_D \chi \;\nabla_h \cdot \nabla_h 
+ 	\left( \chi \right)\;
+	dv
+&&&\\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv A^{\,lm}  \sum\limits_{i,j,k}  \frac{1} {e_{1T}\,e_{2T}\,e_{3T}}  \chi 
+	\left\{
+	\delta_i 
+	\left[ 
+	\frac{e_{2u}\,e_{3u}} {e_{1u}}  \delta_{i+1/2} 
+		\left[ \chi \right] 
+	\right]
+	+ \delta_j 
+	\left[ 
+	\frac{e_{1v}\,e_{3v}} {e_{2v}}  \delta_{j+1/2} 
+		\left[ \chi \right]
+	\right]
+	\right\} \;
+	e_{1T}\,e_{2T}\,e_{3T} 
+	&&&\\ 
+\end{flalign*}
+Using (II.1.10), it turns out to be:
+
+\begin{flalign*}
+\equiv - A^{\,lm} \sum\limits_{i,j,k}
+	\left\{ 
+	\left( 
+	\frac{1} {e_{1u}}  \delta_{i+1/2} 
+		\left[ \chi \right]
+	\right)^2   
+	e_{1u}\,e_{2u}\,e_{3u}
+	+ \left(
+	\frac{1} {e_{2v}}  \delta_{j+1/2} 
+		\left[ \chi \right]
+	\right)^2
+	e_{1v}\,e_{2v}\,e_{3v}
+	\right\} \; 
+	\leq 0 
+	&&&\\
+\end{flalign*}
+
+% ================================================================
+% Conservation Properties on Vertical Momentum Physics
+% ================================================================
+\section{Conservation Properties on Vertical Momentum Physics}
+\label{Apdx_C_4}
+
+
+As for the lateral momentum physics, the continuous form of the vertical diffusion of momentum satisfies the several integral constraints. The first two are associated to the conservation of momentum and the dissipation of horizontal kinetic energy:
+\begin{flalign*}
+ \int\limits_D  
+	 \frac{1} {e_3 }\; \frac{\partial } {\partial k}
+ 	\left( 
+	\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k}
+	\right)\;
+	dv \quad  = \vec{\textbf{0}}
+	&&&\\
+\end{flalign*}
+and
+\begin{flalign*}
+\int\limits_D 
+	\textbf{U}_h \cdot 
+	\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+	\left(
+	\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k}
+	\right)\;
+	dv \quad \leq 0
+	&&&\\
+\end{flalign*}
+The first property is obvious. The second results from:
+
+\begin{flalign*}
+\int\limits_D 
+	\textbf{U}_h \cdot 
+	\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+	\left( 
+	\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+	\right)\;dv
+	&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\left( 
+	  u\; \delta_k 
+		\left[ 
+		\frac{A_u^{\,vm}} {e_{3uw}} \delta_{k+1/2} 
+			\left[ u \right] 
+		\right]\;
+		e_{1u}\,e_{2u} 
+	+ v\;\delta_k 
+		\left[
+		\frac{A_v^{\,vm}} {e_{3vw}} \delta_{k+1/2} 
+			\left[ v \right] 
+		\right]\;
+		e_{1v}\,e_{2v} 
+	\right)
+	&&&\\ 
+\end{flalign*}
+as the horizontal scale factor do not depend on $k$, it follows:
+
+\begin{flalign*}
+\equiv - \sum\limits_{i,j,k} 
+	\left( 
+	   \frac{A_u^{\,vm}} {e_{3uw}}
+		\left( 
+		\delta_{k+1/2} 
+			\left[ u \right] 
+		\right)^2\;
+		e_{1u}\,e_{2u} 
+	+ \frac{A_v^{\,vm}} {e_{3vw}} 
+		\left( \delta_{k+1/2} 
+			\left[ v \right] 
+		\right)^2\;
+		e_{1v}\,e_{2v}
+	\right)
+	 \quad \leq 0
+	 &&&\\
+\end{flalign*}
+The vorticity is also conserved. Indeed:
+\begin{flalign*}
+\int \limits_D 
+	\frac{1} {e_3 } \textbf{k} \cdot \nabla \times 
+		\left( 
+		\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+			\left( 
+			\frac{A^{\,vm}} {e_3}\; \frac{\partial \textbf{U}_h } {\partial k} 
+			\right)
+		\right)\;
+		dv
+		&&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k}  \frac{1} {e_{3f}}\; \frac{1} {e_{1f}\,e_{2f}}
+	\bigg\{    \biggr.   \quad
+	\delta_{i+1/2} 
+		&\left(
+		\frac{e_{2v}} {e_{3v}} \delta_k 
+			\left[
+			\frac{1} {e_{3vw}} \delta_{k+1/2} 
+				\left[ v \right] 
+			\right]
+		\right)
+	 &&\\
+	\biggl. 
+	- \delta_{j+1/2} 
+		&\left(
+		\frac{e_{1u}} {e_{3u}} \delta_k 
+			\left[
+			\frac{1} {e_{3uw}}\delta_{k+1/2} 
+				\left[ u \right]
+			\right]
+		\right)
+	\biggr\} \;
+	e_{1f}\,e_{2f}\,e_{3f} \; \equiv 0
+	&& \\
+\end{flalign*}
+If the vertical diffusion coefficient is uniform over the whole domain, the 
+enstrophy is dissipated, i.e.
+\begin{flalign*}
+\int\limits_D \zeta \, \textbf{k} \cdot \nabla \times 
+	\left( 
+	\frac{1} {e_3}\; \frac{\partial } {\partial k}
+		\left( 
+		\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+		\right) 
+	\right)\;
+	dv = 0
+	&&&\\
+\end{flalign*}
+This property is only satisfied in $z$-coordinates:
+
+\begin{flalign*}
+\int\limits_D \zeta \, \textbf{k} \cdot \nabla \times 
+	\left( 
+	\frac{1} {e_3}\; \frac{\partial } {\partial k}
+		\left( 
+		\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+		\right)
+	\right)\;
+	dv
+	&&& \\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} \zeta \;e_{3f} \;
+	\biggl\{ 	\biggr.	\quad
+	\delta_{i+1/2} 
+		&\left( 
+		   \frac{e_{2v}} {e_{3v}} \delta_k 
+			\left[ 
+			\frac{A_v^{\,vm}} {e_{3vw}} \delta_{k+1/2} 
+				\left[ v \right] 
+			\right]
+		   \right)
+		   &&\\
+	- \delta_{j+1/2} 
+		&\biggl.
+		\left( 	
+		   \frac{e_{1u}} {e_{3u}} \delta_k 
+			\left[ 
+			\frac{A_u^{\,vm}} {e_{3uw}} \delta_{k+1/2} 
+				\left[ u \right]
+			 \right] 
+		   \right) 
+	\biggr\} 
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} \zeta \;e_{3f} 
+	\biggl\{		\biggr.	\quad
+	\frac{1} {e_{3v}} \delta_k 
+		&\left[ 
+		\frac{A_v^{\,vm}} {e_{3vw}} \delta_{k+1/2} 
+			\left[ \delta_{i+1/2} 
+				\left[ e_{2v}\,v \right]
+			 \right]
+		\right]
+		&&\\ 
+ 	 \biggl. 
+	- \frac{1} {e_{3u}} \delta_k 
+		&\left[ 
+		\frac{A_u^{\,vm}} {e_{3uw}} \delta_{k+1/2} 
+			\left[ \delta_{j+1/2} 
+				\left[ e_{1u}\,u \right]
+			 \right]
+		\right]
+	\biggr\} 
+	&&\\ 
+\end{flalign*}
+Using the fact that the vertical diffusive coefficients are uniform and that in $z$-coordinates, the vertical scale factors do not depends on $i$ and $j$ so that: $e_{3f} =e_{3u} =e_{3v} =e_{3T} $ and $e_{3w} =e_{3uw} =e_{3vw} $, it follows:
+\begin{flalign*}
+\equiv A^{\,vm} \sum\limits_{i,j,k} \zeta \;\delta_k 
+	\left[ 
+	\frac{1} {e_{3w}} \delta_{k+1/2} 
+		\Bigl[ 
+		\delta_{i+1/2} 
+			\left[ e_{2v}\,v \right]
+		- \delta_{j+1/ 2} 
+			\left[ e_{1u}\,u \right]
+		 \Bigr] 
+	\right] 
+	&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv - A^{\,vm} \sum\limits_{i,j,k} \frac{1} {e_{3w}}
+	\left( 
+	\delta_{k+1/2} 
+		\left[ \zeta  \right]
+	 \right)^2 \;
+	 e_{1f}\,e_{2f} 
+	 \; \leq 0
+	 &&&\\
+\end{flalign*}
+Similarly, the horizontal divergence is obviously conserved:
+
+\begin{flalign*}
+\int\limits_D \nabla \cdot 
+	\left( 
+	\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+		\left( 
+		\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+		\right) 
+	\right)\;
+	dv = 0
+	&&&\\
+\end{flalign*}
+and the square of the horizontal divergence decreases (i.e. the horizontal divergence is dissipated) if vertical diffusion coefficient is uniform over the whole domain:
+
+\begin{flalign*}
+\int\limits_D \chi \;\nabla \cdot 
+	\left( 
+	\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+		\left( 
+		\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+		\right) 
+	\right)\;
+	dv = 0
+	&&&\\
+\end{flalign*}
+This property is only satisfied in $z$-coordinates:
+
+\begin{flalign*}
+\int\limits_D \chi \;\nabla \cdot 
+	\left( 
+	\frac{1} {e_3 }\; \frac{\partial } {\partial k}
+		\left( 
+		\frac{A^{\,vm}} {e_3 }\; \frac{\partial \textbf{U}_h } {\partial k} 
+		\right) 
+	\right)\;
+	dv
+	&&&\\
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} \frac{\chi } {e_{1T}\,e_{2T}}
+	\biggl\{ 	\Biggr.	\quad
+	\delta_{i+1/2} 
+		&\left( 
+		   \frac{e_{2u}} {e_{3u}} \delta_k 
+		   	\left[ 
+			\frac{A_u^{\,vm}} {e_{3uw}} \delta_{k+1/2} 
+				\left[ u \right] 
+			\right]
+		 \right)
+		 &&\\ 
+ 	\Biggl. 
+	+ \delta_{j+1/2} 
+		&\left( 
+		\frac{e_{1v}} {e_{3v}} \delta_k 
+			\left[ 
+			\frac{A_v^{\,vm}} {e_{3vw}} \delta_{k+1/2} 
+				\left[ v \right]
+			 \right]
+		\right)
+	\Biggr\} \;
+	e_{1T}\,e_{2T}\,e_{3T} 
+	&&\\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv A^{\,vm} \sum\limits_{i,j,k}  \chi \,
+	\biggl\{	\biggr.	\quad
+	\delta_{i+1/2}
+		&\left( 
+		   \delta_k 
+			\left[ 
+			\frac{1} {e_{3uw}} \delta_{k+1/2} 
+				\left[ e_{2u}\,u \right]
+			 \right]
+		   \right) 
+		   && \\ 
+	\biggl. 
+	+ \delta_{j+1/2} 
+		&\left( 
+		   \delta_k 
+			\left[ 
+			\frac{1} {e_{3vw}} \delta_{k+1/2} 
+				\left[ e_{1v}\,v \right]
+			 \right] 
+		   \right)
+	\biggr\} 
+	&& \\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv -A^{\,vm} \sum\limits_{i,j,k} 
+\frac{\delta_{k+1/2} \left[ \chi \right]} {e_{3w}}\;
+	\biggl\{ 
+	\delta_{k+1/2} 
+		\Bigl[
+		   \delta_{i+1/2} 
+			\left[ e_{2u}\,u \right]
+		+ \delta_{j+1/2} 
+			\left[ e_{1v}\,v \right]
+		\Bigr]
+	\biggr\} 
+	&&&\\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv -A^{\,vm} \sum\limits_{i,j,k}
+ \frac{1} {e_{3w}} 
+\delta_{k+1/2} 
+	\left[ \chi \right]\;
+\delta_{k+1/2} 
+	\left[ e_{1T}\,e_{2T} \;\chi \right]
+&&&\\
+\end{flalign*}
+
+\begin{flalign*}
+\equiv -A^{\,vm} \sum\limits_{i,j,k} 
+\frac{e_{1T}\,e_{2T}} {e_{3w}}\;
+	\left( 
+	\delta_{k+1/2} 
+		\left[ \chi \right]
+	\right)^2
+	\quad  \equiv 0
+&&&\\
+\end{flalign*}
+
+% ================================================================
+% Conservation Properties on Tracer Physics
+% ================================================================
+\section{Conservation Properties on Tracer Physics}
+\label{Apdx_C.5}
+
+
+
+The numerical schemes used for tracer subgridscale physics are written such that the heat and salt contents are conserved (equations in flux form, second order centered finite differences). As a form flux is used to compute the temperature and salinity, the quadratic form of these quantities (i.e. their variance) globally tends to diminish. As for the advection term, there is generally no strict conservation of mass even if, in practice, the mass is conserved with a very good accuracy. 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation of Tracers
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Conservation of Tracers}
+\label{Apdx_C.5.1}
+
+constraint of conservation of tracers:
+\begin{flalign*}
+\int\limits_D  T\;\nabla  \cdot \left( A\;\nabla T \right)\;dv  &&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} 
+	\biggl\{ 	\biggr.
+	\delta_i 
+		\left[ 
+		A_u^{\,lT} \frac{e_{2u}\,e_{3u}} {e_{1u}} \delta_{i+1/2} 
+			\left[ T \right]
+		\right]
+	+ \delta_j 
+		&\left[ 
+		A_v^{\,lT} \frac{e_{1v}\,e_{3v}} {e_{2v}} \delta_{j+1/2} 
+			\left[ T \right] 
+		\right]
+	&&\\ 
+	\biggl. 
+	+ \delta_k 
+		&\left[ 
+		A_w^{\,vT} \frac{e_{1T}\,e_{2T}} {e_{3T}} \delta_{k+1/2} 
+			\left[ T \right] 
+		\right]
+	\biggr\} 
+	&&\\ 
+\end{flalign*}
+\begin{flalign*}
+\equiv 0	&&&\\
+\end{flalign*}
+
+
+% -------------------------------------------------------------------------------------------------------------
+%       Dissipation of Tracer Variance
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Dissipation of Tracer Variance}
+\label{Apdx_C.5.2}
+
+constraint of dissipation of tracer variance:
+\begin{flalign*}
+\int\limits_D T\;\nabla \cdot \left( A\;\nabla T \right)\;dv	&&&\\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv \sum\limits_{i,j,k} T
+	\biggl\{ 	\biggr.
+	\delta_i 
+		\left[ 
+		A_u^{\,lT} \frac{e_{2u}\,e_{3u}} {e_{1u}} \delta_{i+1/2} 
+			\left[ T \right] 
+		\right]
+	+ \delta_j 
+		&\left[ 
+		A_v^{\,lT} \frac{e_{1v}\,e_{3v}} {e_{2v}} \delta_{j+1/2} 
+			\left[ T \right] 
+		\right] 
+		&& \\ 
+	 \biggl. 
+	 + \delta_k 
+	 	&\left[ 
+		A_w^{\,vT} \frac{e_{1T}\,e_{2T}} {e_{3T}} \delta_{k+1/2} 
+			\left[ T \right] 
+		\right]
+	\biggr\} 
+	&&\\ 
+\end{flalign*}
+
+\begin{flalign*}
+\equiv - \sum\limits_{i,j,k} 
+	\biggl\{ 	\biggr.	\quad
+	& A_u^{\,lT} 
+		\left( 
+		\frac{1} {e_{1u}} \delta_{i+1/2} 
+			\left[ T \right]
+		\right)^2
+		e_{1u}\,e_{2u}\,e_{3u}
+	&& \\
+	& + A_v^{\,lT} 
+		\left( 
+		\frac{1} {e_{2v}} \delta_{j+1/2} 
+			\left[ T \right] 
+		\right)^2
+		e_{1v}\,e_{2v}\,e_{3v}
+	&& \\ 
+ 	\biggl. 
+	& + A_w^{\,vT} 
+		\left( 
+		\frac{1} {e_{3w}} \delta_{k+1/2} 
+			\left[ T \right] 
+		\right)^2
+		e_{1w}\,e_{2w}\,e_{3w} 
+	\biggr\} 
+	\quad \leq 0 
+	&& \\ 
+\end{flalign*}
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_D.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_D.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_D.tex	(revision 4536)
@@ -0,0 +1,185 @@
+% ================================================================
+% Chapter Ñ Appendix D : Coding Rules
+% ================================================================
+\chapter{Appendix D : Coding Rules}
+\label{Apdx_D}
+\minitoc
+
+
+The "model life" is about ten years and its software, composed by about one 
+hundred programs, is used by many people who are scientists or students and 
+do not necessary know very well all computer aspects. Moreover, a well 
+thought-out programme is easy to read and understand, less difficult to 
+modify, produces fewer bugs and is easier to maintain. Therefore, it is 
+essential that the model development follows some rules :
+
+- well planned and designed
+
+- well written
+
+- well documented (both on- and off-line)
+
+- maintainable
+
+- easily portable
+
+- flexible.
+
+To satisfy part of these aims, OPA is written with a coding standard which 
+is close to the ECMWF rule, named DOCTOR [Gibson,1986]. These rules present 
+some advantages like :
+
+- to provide a well presented program
+
+- to enable the extraction of several levels of on-line documentation
+
+- to use rules for variable names which allow recognition of their type 
+(integer, real, parameter, common variables, etc. ) so that debugging is 
+facilitated.
+
+\textbf{The program structure}
+
+Each program begins with a set of headline comments containing :
+
+- the program title
+
+- the purpose of the routine
+
+- the method and algorithms used
+
+- the detail of input and output interfaces
+
+- the external routines and functions used (if exist)
+
+- references (if exist)
+
+- the author name (s), the date of creation and of updates.
+
+- Each program is splitted into several well separated sections and 
+sub-sections with a underlined title and specific labelled statements.
+
+- A program has not more than 200 to 300 lines.
+
+\textbf{Coding conventions}
+
+- Use of the universal language \textsc{Fortran} 5 ANSI 77, with non 
+standard extensions, NAMELIST and \textsc{Fortran} 90 (matrix resolution 
+algorithm), and some well-identified particular statements or functions for 
+weak and massive parallelism, and vectorization 
+
+- A comment line begins with a uppercase character C at the first column. A 
+space line must have a C. For the on-line documentation, comments are 
+classified into three levels :
+
+Overview, triggered by CCC in columns 1 to 3. Only the title and the purpose 
+of the program are identified like that. This overview documentation can be 
+extracted by the UNIX function : grep -e '\^{}CCC' *
+
+External, triggered by CC in columns 1 to 2, and which correspond to 
+headlines of each programme, extracted by : grep -e '\^{}CC' *
+
+Internal which are all the comments, extracted by : grep -e '\^{}C' *
+
+- Statements GO TO, EQUIVALENCE are forbidden.
+
+- A section is numbered with labels which are in agreement with the 
+paragraph label and increase from the begin to the end of routine. Labels of 
+a hundred ( 200, 201.. 220..) are reserved to a unique section. The 
+\textsc{Fortran} 90 extension syntax DO/ENDDO is used except for multitasked 
+do-loop. In this case labels 1000, 2000, ... are used. The FORMAT statement 
+are labelled with numbers in the range 9000 to 9999.
+
+- A continuation line begins with the character {\$} in column 6.
+
+- All statements begin in column 7 with the following gaps :
+
+2 spaces toward the right in a DO loop.
+
+4 spaces toward the right in IF, ELSEIF, ELSE and ENDIF statements, with 
+only 2 spaces for ELSE and ELSEIF lines. All IF statement must be followed 
+by a ELSE statement.
+
+Some spaces in the continuation line for alignment.
+
+- Use of different labels for each DO loop statement.
+
+- STOP must be well documented with the name of the subroutine or a number.
+
+\textbf{Naming Conventions.}
+
+The purpose of the naming conventions is to use prefix letters to classify 
+model variables. These conventions allow to know easily the variable type 
+and to identify them rapidly:
+
+
+%--------------------------------------------------TABLE--------------------------------------------------
+\begin{table}[htbp]
+\begin{center}
+\begin{tabular}{|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|}
+\hline
+Type \par / \par Status & 
+integer& 
+real& 
+logical & 
+character& 
+double \par precision& 
+complex \\
+\hline
+global \par or \par common& 
+\textbf{m n} \par \textit{but not } \par \textbf{nam}& 
+\textbf{a b e f g h o} \textbf{q} \textit{to} \textbf{x} \par but not \par \textbf{sf}& 
+\textbf{l} \par \textit{but not} \par \textbf{lp ld ll}& 
+\textbf{c} \par \textit{but not} \par \textbf{cp cd cl } \par \textbf{com cim}& 
+\textbf{d} \par \textit{but not} \par \textbf{dp dd dl}& 
+\textbf{y} \par \textit{but not} \par \textbf{yp yd yl} \\
+\hline
+dummy \par argument& 
+\textbf{k} \par \textit{but not} \par \textbf{kf}& 
+\textbf{p} \par \textit{but not}  \par \textbf{pp pf}& 
+\textbf{ld}& 
+\textbf{cd}& 
+\textbf{dd}& 
+\textbf{yd} \\
+\hline
+local \par variable& 
+\textbf{i}& 
+\textbf{z}& 
+\textbf{ll}& 
+\textbf{cl}& 
+\textbf{cd}& 
+\textbf{yl} \\
+\hline
+loop \par control& 
+\textbf{j} \par \textit{but not } \par \textbf{jp}& 
+& 
+& 
+& 
+& 
+ \\
+\hline
+parameter& 
+\textbf{jp}& 
+\textbf{pp}& 
+\textbf{lp}& 
+\textbf{cp}& 
+\textbf{dp}& 
+\textbf{yp} \\
+\hline
+statement \par function& 
+\textbf{kf}& 
+\textbf{sf} \par & 
+& 
+& 
+& 
+ \\
+\hline
+\end{tabular}
+\label{tab1}
+\end{center}
+\end{table}
+%--------------------------------------------------------------------------------------------------------------
+
+\textbf{References}
+
+{\small Gibson, J. K., 1986: Standard software development and maintenance. }{\small \textit{Tech. memorandum}}{\small , Operational Dep., ECMWF, Reading, UK.}
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_E.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_E.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Annex_E.tex	(revision 4536)
@@ -0,0 +1,210 @@
+% ================================================================
+% Appendix E : UBS scheme
+% ================================================================
+\chapter{UBS scheme}
+\label{AN_E}
+\minitoc
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        UBS scheme  
+% -------------------------------------------------------------------------------------------------------------
+\section{Upstream Biased Scheme (UBS) (\np{ln\_traadv\_ubs}=T)}
+\label{TRA_adv_ubs}
+
+The UBS advection scheme is an upstream biased third order scheme based on 
+an upstream-biased parabolic interpolation. It is also known as Cell 
+Averaged QUICK scheme (Quadratic Upstream Interpolation for Convective 
+Kinematics). For example, in the $i$-direction :
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\tau _u^{ubs} = \left\{	 \begin{aligned}
+  & \tau _u^{cen4} + \frac{1}{12} \,\tau"_i	   & \quad \text{if }\ u_{i+1/2} \geqslant 0 \\
+  & \tau _u^{cen4} - \frac{1}{12} \,\tau"_{i+1} & \quad \text{if }\ u_{i+1/2}       <       0
+  						 \end{aligned}    \right.
+\end{equation}
+or equivalently, the advective flux is
+\begin{equation} \label{Eq_tra_adv_ubs2}
+U_{i+1/2} \ \tau _u^{ubs} 
+=U_{i+1/2} \ \overline{ T_i - \frac{1}{6}\,\tau"_i }^{\,i+1/2}
+- \frac{1}{2}\, |U|_{i+1/2} \;\frac{1}{6} \;\delta_{i+1/2}[\tau"_i]
+\end{equation}
+where $U_{i+1/2} = e_{1u}\,e_{3u}\,u_{i+1/2}$ and $\tau "_i =\delta _i \left[ {\delta _{i+1/2} \left[ \tau \right]} \right]$. By choosing this expression for $\tau "$ we consider a fourth order approximation of $\partial_i^2$ with a constant i-grid spacing ($\Delta i=1$). 
+
+Alternative choice: introduce the scale factors:  $\tau "_i =\frac{e_{1T}}{e_{2T}\,e_{3T}}\delta _i \left[ \frac{e_{2u} e_{3u} }{e_{1u} }\delta _{i+1/2}[\tau] \right]$.
+
+
+This results in a dissipatively dominant (i.e. hyper-diffusive) truncation 
+error \citep{Sacha2005}. The overall performance of the 
+advection scheme is similar to that reported in \cite{Farrow1995}. 
+It is a relatively good compromise between accuracy and smoothness. It is 
+not a \emph{positive} scheme meaning false extrema are permitted but the 
+amplitude of such are significantly reduced over the centred second order 
+method. Nevertheless it is not recommended to apply it to a passive tracer 
+that requires positivity. 
+
+The intrinsic diffusion of UBS makes its use risky in the vertical direction 
+where the control of artificial diapycnal fluxes is of paramount importance. 
+It has therefore been preferred to evaluate the vertical flux using the TVD 
+scheme when \np{ln\_traadv\_ubs}=T.
+
+For stability reasons, in \eqref{Eq_tra_adv_ubs}, the first term which corresponds to a 
+second order centred scheme is evaluated using the \textit{now} velocity (centred in 
+time) while the second term which is the diffusive part of the scheme, is 
+evaluated using the \textit{before} velocity (forward in time. This is discussed by \citet{Webb1998} in the context of the Quick advection scheme. UBS and QUICK 
+schemes only differ by one coefficient. Substituting 1/6 with 1/8 in 
+(\ref{Eq_tra_adv_ubs}) leads to the QUICK advection scheme \citep{Webb1998}. This 
+option is not available through a namelist parameter, since the 1/6 
+coefficient is hard coded. Nevertheless it is quite easy to make the 
+substitution in \mdl{traadv\_ubs} module and obtain a QUICK scheme
+
+NB 1: When a high vertical resolution $O(1m)$ is used, the model stability can 
+be controlled by vertical advection (not vertical diffusion which is usually 
+solved using an implicit scheme). Computer time can be saved by using a 
+time-splitting technique on vertical advection. This possibility have been 
+implemented and validated in ORCA05-L301. It is not currently offered in the 
+current reference version. 
+
+NB 2 : In a forthcoming release four options will be proposed for the 
+vertical component used in the UBS scheme. $\tau _w^{ubs}$ will be 
+evaluated using either \textit{(a)} a centred $2^{nd}$ order scheme , or  \textit{(b)} a TVD 
+scheme, or  \textit{(c)} an interpolation based on conservative parabolic splines 
+following \citet{Sacha2005} implementation of UBS in ROMS, 
+or  \textit{(d)} an UBS. The $3^{rd}$ case has dispersion properties similar to an 
+eight-order accurate conventional scheme.
+
+NB 3 : It is straight forward to rewrite \eqref{Eq_tra_adv_ubs} as follows:
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\tau _u^{ubs} = \left\{	 \begin{aligned}
+	& \tau _u^{cen4} + \frac{1}{12} \tau"_i		& \quad \text{if }\ u_{i+1/2} \geqslant 0 \\
+	& \tau _u^{cen4} - \frac{1}{12} \tau"_{i+1}	& \quad \text{if }\ u_{i+1/2}       <       0
+  						 \end{aligned}    \right.
+\end{equation}
+or equivalently 
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\begin{split}
+e_{2u} e_{3u}\,u_{i+1/2} \ \tau _u^{ubs} 
+&= e_{2u} e_{3u}\,u_{i+1/2} \ \overline{ T - \frac{1}{6}\,\tau"_i }^{\,i+1/2} \\
+& - \frac{1}{2} e_{2u} e_{3u}\,|u|_{i+1/2} \;\frac{1}{6} \;\delta_{i+1/2}[\tau"_i]
+\end{split}
+\end{equation}
+\eqref{Eq_tra_adv_ubs2} has several advantages. First it clearly evidence that the UBS scheme is based on the fourth order scheme to which is added an upstream biased diffusive term. Second, this emphasises that the $4^{th}$ order part have to be evaluated at \emph{now} time step, not only the $2^{th}$ order part as stated above using \eqref{Eq_tra_adv_ubs}. Third, the diffusive term is in fact a biharmonic operator with a eddy coefficient with is simply proportional to the velocity.
+
+
+laplacian diffusion:
+\begin{equation} \label{Eq_tra_ldf_lap}
+\begin{split}
+D_T^{lT} =\frac{1}{e_{1T} \; e_{2T}\;  e_{3T} } &\left[ {\quad \delta _i 
+\left[ {A_u^{lT} \frac{e_{2u} e_{3u} }{e_{1u} }\;\delta _{i+1/2} 
+\left[ T \right]} \right]} \right.
+\\
+&\ \left. {+\; \delta _j \left[ 
+{A_v^{lT} \left( {\frac{e_{1v} e_{3v} }{e_{2v} }\;\delta _{j+1/2} \left[ T 
+\right]} \right)} \right]\quad } \right]
+\end{split}
+\end{equation}
+
+bilaplacian:
+\begin{equation} \label{Eq_tra_ldf_lap}
+\begin{split}
+D_T^{lT} =&-\frac{1}{e_{1T} \; e_{2T}\;  e_{3T}} \\
+& \delta _i \left[  \sqrt{A_u^{lT}}\ \frac{e_{2u}\,e_{3u}}{e_{1u}}\;\delta _{i+1/2} 
+		  \left[ \frac{1}{e_{1T}\,e_{2T}\, e_{3T}}
+    \delta _i \left[ \sqrt{A_u^{lT}}\ \frac{e_{2u}\,e_{3u}}{e_{1u}}\;\delta _{i+1/2} 
+    		  [T] \right] \right] \right]
+\end{split}
+\end{equation}
+with ${A_u^{lT}}^2 = \frac{1}{12} {e_{1u}}^3\ |u|$, 
+$i.e.$ $A_u^{lT} = \frac{1}{\sqrt{12}} \,e_{1u}\ \sqrt{ e_{1u}\,|u|\,}$
+it comes :
+\begin{equation} \label{Eq_tra_ldf_lap}
+\begin{split}
+D_T^{lT} =&-\frac{1}{12}\,\frac{1}{e_{1T} \; e_{2T}\;  e_{3T}} \\
+& \delta _i \left[ e_{2u}\,e_{3u}\,\sqrt{ e_{1u}\,|u|\,}\;\delta _{i+1/2} 
+		 \left[ \frac{1}{e_{1T}\,e_{2T}\, e_{3T}} 
+    \delta _i \left[ e_{2u}\,e_{3u}\,\sqrt{ e_{1u}\,|u|\,}\;\delta _{i+1/2} 
+    		[T] \right] \right] \right]
+\end{split}
+\end{equation}
+if the velocity is uniform ($i.e.$ $|u|=cst$) then the diffusive flux is
+\begin{equation} \label{Eq_tra_ldf_lap}
+\begin{split}
+F_u^{lT} = - \frac{1}{12}
+ e_{2u}\,e_{3u}\,|u| \;\sqrt{ e_{1u}}\,\delta _{i+1/2} 
+		 \left[ \frac{1}{e_{1T}\,e_{2T}\, e_{3T}} 
+    \delta _i \left[ e_{2u}\,e_{3u}\,\sqrt{ e_{1u}}\:\delta _{i+1/2} 
+    		[T] \right] \right]
+\end{split}
+\end{equation}
+beurk....  reverte the logic: starting from the diffusive part of the advective flux it comes:
+
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\begin{split}
+F_u^{lT}
+&= - \frac{1}{2} e_{2u} e_{3u}\,|u|_{i+1/2} \;\frac{1}{6} \;\delta_{i+1/2}[\tau"_i]
+\end{split}
+\end{equation}
+if the velocity is uniform ($i.e.$ $|u|=cst$) and choosing $\tau "_i =\frac{e_{1T}}{e_{2T}\,e_{3T}}\delta _i \left[ \frac{e_{2u} e_{3u} }{e_{1u} } \delta _{i+1/2}[\tau] \right]$
+
+sol 1 coefficient at T-point ( add $e_{1u}$ and $e_{1T}$ on both side of first $\delta$):
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\begin{split}
+F_u^{lT}
+&= - \frac{1}{12} \frac{e_{2u} e_{3u}}{e_{1u}}\;\delta_{i+1/2}\left[ \frac{e_{1T}^3\,|u|}{e_{1T}e_{2T}\,e_{3T}}\,\delta _i \left[ \frac{e_{2u} e_{3u} }{e_{1u} } \delta _{i+1/2}[\tau] \right] \right]
+\end{split}
+\end{equation}
+which leads to ${A_T^{lT}}^2 = \frac{1}{12} {e_{1T}}^3\ \overline{|u|}^{\,i+1/2}$
+
+sol 2 coefficient at u-point: split $|u|$ into $\sqrt{|u|}$ and $e_{1T}$ into $\sqrt{e_{1u}}$
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\begin{split}
+F_u^{lT}
+&= - \frac{1}{12} {e_{1u}}^1 \sqrt{e_{1u}|u|} \frac{e_{2u} e_{3u}}{e_{1u}}\;\delta_{i+1/2}\left[ \frac{1}{e_{2T}\,e_{3T}}\,\delta _i \left[ \sqrt{e_{1u}|u|} \frac{e_{2u} e_{3u} }{e_{1u} } \delta _{i+1/2}[\tau] \right] \right] \\
+&= - \frac{1}{12} e_{1u} \sqrt{e_{1u}|u|\,} \frac{e_{2u} e_{3u}}{e_{1u}}\;\delta_{i+1/2}\left[ \frac{1}{e_{1T}\,e_{2T}\,e_{3T}}\,\delta _i \left[ e_{1u} \sqrt{e_{1u}|u|\,} \frac{e_{2u} e_{3u} }{e_{1u}} \delta _{i+1/2}[\tau] \right] \right]
+\end{split}
+\end{equation}
+which leads to ${A_u^{lT}} = \frac{1}{12} {e_{1u}}^3\ |u|$
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        Leap-Frog energetic  
+% -------------------------------------------------------------------------------------------------------------
+\section{Leap-Frog energetic }
+\label{LF}
+
+We adopt the following semi-discrete notation for time derivative. Given the values of a variable $q$ at successive time step, the time derivation and averaging operators at the mid time step are:
+\begin{subequations} \label{dt_mt}
+\begin{align}
+ \delta _{t+\Delta t/2} [q]     &=  \  \ \,   q^{t+\Delta t}  - q^{t}		\\
+ \overline q^{\,t+\Delta t/2} &= \left\{ q^{t+\Delta t} + q^{t} \right\} \; / \; 2
+\end{align}
+\end{subequations}
+As for space operator, the adjoint of the derivation and averaging time operators are $\delta_t^*=\delta_{t+\Delta t/2}$ and $\overline{\cdot}^{\,t\,*}= \overline{\cdot}^{\,t+\Delta/2}$, respectively. 
+
+The Leap-frog time stepping given by \eqref{Eq_DOM_nxt} can be defined as:
+\begin{equation} \label{LF}
+   \frac{\partial q}{\partial t} 
+   		\equiv \frac{1}{\Delta t} \overline{ \delta _{t+\Delta t/2}[q]}^{\,t} 
+		=         \frac{q^{t+\Delta t}-q^{t-\Delta t}}{2\Delta t}
+\end{equation} 
+Note that \eqref{LF} shows that the leapfrog time step is $\Delta t$, not $2\Delta t$ as it can be found sometime in literature. 
+The leap-Frog time stepping is a second order centered scheme. As such it respects the quadratic invariant in integral forms, $i.e.$ the following continuous property,
+\begin{equation} \label{Energy}
+\int_{t_0}^{t_1} {q\, \frac{\partial q}{\partial t} \;dt} 
+	=\int_{t_0}^{t_1} {\frac{1}{2}\, \frac{\partial q^2}{\partial t} \;dt} 
+	=  \frac{1}{2} \left( {q_{t_1}}^2 - {q_{t_0}}^2 \right) ,
+\end{equation}
+is satisfied in discrete form. Indeed, 
+\begin{equation} \begin{split}
+\int_{t_0}^{t_1} {q\, \frac{\partial q}{\partial t} \;dt} 
+	&\equiv \sum\limits_{0}^{N} 
+			{\frac{1}{\Delta t} q^t \ \overline{ \delta _{t+\Delta t/2}[q]}^{\,t} \ \Delta t} 
+	   \equiv \sum\limits_{0}^{N}  { q^t \ \overline{ \delta _{t+\Delta t/2}[q]}^{\,t} } \\
+	&\equiv \sum\limits_{0}^{N}  { \overline{q}^{\,t+\Delta/2}{ \delta _{t+\Delta t/2}[q]}}
+	   \equiv \sum\limits_{0}^{N}  { \frac{1}{2} \delta _{t+\Delta t/2}[q^2] }\\
+	&\equiv \sum\limits_{0}^{N}  { \frac{1}{2} \delta _{t+\Delta t/2}[q^2] }
+	   \equiv \frac{1}{2} \left( {q_{t_1}}^2 - {q_{t_0}}^2 \right)
+\end{split} \end{equation}
+NB here pb of boundary condition when applying the adjoin! In space, setting to 0 the quantity in land area is sufficient to get rid of the boundary condition (equivalently of the boundary value of the integration by part). In time this boundary condition is not physical and \textbf{add something here!!!}
+
+
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Conservation.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Conservation.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Conservation.tex	(revision 4536)
@@ -0,0 +1,332 @@
+
+% ================================================================
+% Invariant of the Equations
+% ================================================================
+\chapter{Annex --- Invariants of the Primitive Equations}
+\label{Invariant}
+\minitoc
+
+The continuous equations of motion have many analytic properties. Many 
+quantities (total mass, energy, enstrophy, etc.) are strictly conserved in 
+the inviscid and unforced limit, while ocean physics conserve the total 
+quantities on which they act (momentum, temperature, salinity) but dissipate 
+their total variance (energy, enstrophy, etc.). Unfortunately, the finite 
+difference form of these equations is not guaranteed to retain all these 
+important properties. In constructing the finite differencing schemes, we 
+wish to ensure that certain integral constraints will be maintained. In 
+particular, it is desirable to construct the finite difference equations so 
+that horizontal kinetic energy and/or potential enstrophy of horizontally 
+non-divergent flow, and variance of temperature and salinity will be 
+conserved in the absence of dissipative effects and forcing. \citet{Arakawa1966} 
+has first pointed out the advantage of this approach. He showed that if 
+integral constraints on energy are maintained, the computation will be free 
+of the troublesome "non linear" instability originally pointed out by 
+\citet{Phillips1959}. A consistent formulation of the energetic properties is 
+also extremely important in carrying out long-term numerical simulations for 
+an oceanographic model. Such a formulation avoids systematic errors that 
+accumulate with time \citep{Bryan1997}.
+
+The general philosophy of OPA which has led to the discrete formulation 
+presented in {\S}II.2 and II.3 is to choose second order non-diffusive 
+scheme for advective terms for both dynamical and tracer equations. At this 
+level of complexity, the resulting schemes are dispersive schemes. 
+Therefore, they require the addition of a diffusive operator to be stable. 
+The alternative is to use diffusive schemes such as upstream or flux 
+corrected schemes. This last option was rejected because we prefer a 
+complete handling of the model diffusion, i.e. of the model physics rather 
+than letting the advective scheme produces its own implicit diffusion 
+without controlling the space and time structure of this implicit diffusion. 
+Note that in some very specific cases as passive tracer studies, the 
+positivity of the advective scheme is required. In that case, and in that 
+case only, the advective scheme used for passive tracer is a flux correction 
+scheme \citep{Marti1992, Levy1996, Levy1998}.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation Properties on Ocean Dynamics
+% -------------------------------------------------------------------------------------------------------------
+\section{Conservation Properties on Ocean Dynamics}
+\label{Invariant_dyn}
+
+The non linear term of the momentum equations has been split into a 
+vorticity term, a gradient of horizontal kinetic energy and a vertical 
+advection term. Three schemes are available for the former (see {\S}~II.2) 
+according to the CPP variable defined (default option\textbf{ 
+}or \textbf{key{\_}vorenergy } or \textbf{key{\_}vorcombined 
+} defined). They differ in their conservative 
+properties (energy or enstrophy conserving scheme). The two latter terms 
+preserve the total kinetic energy: the large scale kinetic energy is also 
+preserved in practice. The remaining non-diffusive terms of the momentum 
+equation (namely the hydrostatic and surface pressure gradient terms) also 
+preserve the total kinetic energy and have no effect on the vorticity of the 
+flow.
+
+\textbf{* relative, planetary and total vorticity term:}
+
+Let us define as either the relative, planetary and total potential 
+vorticity, i.e. , , and , respectively. The continuous formulation of the 
+vorticity term satisfies following integral constraints:
+\begin{equation} \label{Eq_vor_vorticity}
+\int_D {{\textbf {k}}\cdot \frac{1}{e_3 }\nabla \times \left( {\varsigma 
+\;{\rm {\bf k}}\times {\textbf {U}}_h } \right)\;dv} =0
+\end{equation}
+
+\begin{equation} \label{Eq_vor_enstrophy}
+if\quad \chi =0\quad \quad \int\limits_D {\varsigma \;{\textbf{k}}\cdot 
+\frac{1}{e_3 }\nabla \times \left( {\varsigma {\textbf{k}}\times {\textbf{U}}_h } \right)\;dv} =-\int\limits_D {\frac{1}{2}\varsigma ^2\,\chi \;dv} 
+=0
+\end{equation}
+
+\begin{equation} \label{Eq_vor_energy}
+\int_D {{\textbf{U}}_h \times \left( {\varsigma \;{\textbf{k}}\times {\textbf{U}}_h } \right)\;dv} =0
+\end{equation}
+where $dv = e_1\, e_2\, e_3\, di\, dj\, dk$ is the volume element. 
+(II.4.1a) means that $\varsigma $ is conserved. (II.4.1b) is obtained by an integration by part. It means that $\varsigma^2$ is conserved for a horizontally non-divergent flow. 
+(II.4.1c) is even satisfied locally since the vorticity term is orthogonal 
+to the horizontal velocity. It means that the vorticity term has no 
+contribution to the evolution of the total kinetic energy. (II.4.1a) is 
+obviously always satisfied, but (II.4.1b) and (II.4.1c) cannot be satisfied 
+simultaneously with a second order scheme. Using the symmetry or 
+anti-symmetry properties of the operators (Eqs II.1.10 and 11), it can be 
+shown that the scheme (II.2.11) satisfies (II.4.1b) but not (II.4.1c), while 
+scheme (II.2.12) satisfies (II.4.1c) but not (II.4.1b) (see appendix C). 
+Note that the enstrophy conserving scheme on total vorticity has been chosen 
+as the standard discrete form of the vorticity term.
+
+\textbf{* Gradient of kinetic energy / vertical advection}
+
+In continuous formulation, the gradient of horizontal kinetic energy has no 
+contribution to the evolution of the vorticity as the curl of a gradient is 
+zero. This property is satisfied locally with the discrete form of both the 
+gradient and the curl operator we have made (property (II.1.9)~). Another 
+continuous property is that the change of horizontal kinetic energy due to 
+vertical advection is exactly balanced by the change of horizontal kinetic 
+energy due to the horizontal gradient of horizontal kinetic energy:
+
+\begin{equation} \label{Eq_keg_zad}
+\int_D {{\textbf{U}}_h \cdot \nabla _h \left( {1/2\;{\textbf{U}}_h ^2} \right)\;dv} =-\int_D {{\textbf{U}}_h \cdot \frac{w}{e_3 }\;\frac{\partial 
+{\textbf{U}}_h }{\partial k}\;dv}
+\end{equation}
+
+Using the discrete form given in {\S}II.2-a and the symmetry or 
+anti-symmetry properties of the mean and difference operators, \eqref{Eq_keg_zad} is 
+demonstrated in the Appendix C. The main point here is that satisfying 
+\eqref{Eq_keg_zad} links the choice of the discrete forms of the vertical advection 
+and of the horizontal gradient of horizontal kinetic energy. Choosing one 
+imposes the other. The discrete form of the vertical advection given in 
+{\S}II.2-a is a direct consequence of formulating the horizontal kinetic 
+energy as $1/2 \left( \overline{u^2}^i + \overline{v^2}^j \right) $ in the gradient term.
+
+\textbf{* hydrostatic pressure gradient term}
+
+In continuous formulation, a pressure gradient has no contribution to the 
+evolution of the vorticity as the curl of a gradient is zero. This 
+properties is satisfied locally with the choice of discretization we have 
+made (property (II.1.9)~). In addition, when the equation of state is linear 
+(i.e. when an advective-diffusive equation for density can be derived from 
+those of temperature and salinity) the change of horizontal kinetic energy 
+due to the work of pressure forces is balanced by the change of potential 
+energy due to buoyancy forces:
+
+\begin{equation} \label{Eq_hpg_pe}
+\int_D {-\frac{1}{\rho _o }\left. {\nabla p^h} \right|_z \cdot {\textbf {U}}_h \;dv} \;=\;\int_D {\nabla .\left( {\rho \,{\textbf{U}}} \right)\;g\;z\;\;dv}
+\end{equation}
+
+Using the discrete form given in {\S}~II.2-a and the symmetry or 
+anti-symmetry properties of the mean and difference operators, (II.4.3) is 
+demonstrated in the Appendix C. The main point here is that satisfying 
+(II.4.3) strongly constraints the discrete expression of the depth of 
+$T$-points and of the term added to the pressure gradient in $s-$coordinates: the 
+depth of a $T$-point, $z_T$, is defined as the sum the vertical scale 
+factors at $w$-points starting from the surface.
+
+\textbf{* surface pressure gradient term}
+
+In continuous formulation, the surface pressure gradient has no contribution 
+to the evolution of vorticity. This properties is trivially satisfied 
+locally as (II.2.3) (the equation verified by $\psi$ has been 
+derived from the discrete formulation of the momentum equations, vertical 
+sum and curl. Nevertheless, the $\psi$-equation is solved numerically by an 
+iterative solver (see {\S}~III.5), thus the property is only satisfied with 
+the accuracy required on the solver. In addition, with the rigid-lid 
+approximation, the change of horizontal kinetic energy due to the work of 
+surface pressure forces is exactly zero:
+\begin{equation} \label{Eq_spg}
+\int_D {-\frac{1}{\rho _o }\nabla _h } \left( {p_s } \right)\cdot {\textbf{U}}_h \;dv=0
+\end{equation}
+
+(II.4.4) is satisfied in discrete form only if the discrete barotropic 
+streamfunction time evolution equation is given by (II.2.3) (see appendix 
+C). This shows that (II.2.3) is the only way to compute the streamfunction, 
+otherwise there is no guarantee that the surface pressure force work 
+vanishes.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation Properties on Ocean Thermodynamics
+% -------------------------------------------------------------------------------------------------------------
+\section{Conservation Properties on Ocean Thermodynamics}
+\label{Invariant_tra}
+
+In continuous formulation, the advective terms of the tracer equations 
+conserve the tracer content and the quadratic form of the tracer, i.e.
+\begin{equation} \label{Eq_tra_tra2}
+\int_D {\nabla .\left( {T\;{\textbf{U}}} \right)\;dv} =0
+\;\text{and}
+\int_D {T\;\nabla .\left( {T\;{\textbf{U}}} \right)\;dv} =0
+\end{equation}
+
+The numerical scheme used ({\S}II.2-b) (equations in flux form, second order 
+centred finite differences) satisfies (II.4.5) (see appendix C). Note that 
+in both continuous and discrete formulations, there is generally no strict 
+conservation of mass, since the equation of state is non linear with respect 
+to $T$ and $S$. In practice, the mass is conserved with a very good accuracy. 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation Properties on Momentum Physics
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Conservation Properties on Momentum Physics}
+\label{Invariant_dyn_physics}
+
+\textbf{* lateral momentum diffusion term}
+
+The continuous formulation of the horizontal diffusion of momentum satisfies 
+the following integral constraints~:
+\begin{equation} \label{Eq_dynldf_dyn}
+\int\limits_D {\frac{1}{e_3 }{\rm {\bf k}}\cdot \nabla \times \left[ {\nabla 
+_h \left( {A^{lm}\;\chi } \right)-\nabla _h \times \left( {A^{lm}\;\zeta 
+\;{\rm {\bf k}}} \right)} \right]\;dv} =0
+\end{equation}
+
+\begin{equation} \label{Eq_dynldf_div}
+\int\limits_D {\nabla _h \cdot \left[ {\nabla _h \left( {A^{lm}\;\chi } 
+\right)-\nabla _h \times \left( {A^{lm}\;\zeta \;{\rm {\bf k}}} \right)} 
+\right]\;dv} =0
+\end{equation}
+
+\begin{equation} \label{Eq_dynldf_curl}
+\int_D {{\rm {\bf U}}_h \cdot \left[ {\nabla _h \left( {A^{lm}\;\chi } 
+\right)-\nabla _h \times \left( {A^{lm}\;\zeta \;{\rm {\bf k}}} \right)} 
+\right]\;dv} \leqslant 0
+\end{equation}
+
+\begin{equation} \label{Eq_dynldf_curl2}
+\mbox{if}\quad A^{lm}=cste\quad \quad \int_D {\zeta \;{\rm {\bf k}}\cdot 
+\nabla \times \left[ {\nabla _h \left( {A^{lm}\;\chi } \right)-\nabla _h 
+\times \left( {A^{lm}\;\zeta \;{\rm {\bf k}}} \right)} \right]\;dv} 
+\leqslant 0
+\end{equation}
+
+\begin{equation} \label{Eq_dynldf_div2}
+\mbox{if}\quad A^{lm}=cste\quad \quad \int_D {\chi \;\nabla _h \cdot \left[ 
+{\nabla _h \left( {A^{lm}\;\chi } \right)-\nabla _h \times \left( 
+{A^{lm}\;\zeta \;{\rm {\bf k}}} \right)} \right]\;dv} \leqslant 0
+\end{equation}
+
+
+(II.4.6a) and (II.4.6b) means that the horizontal diffusion of momentum 
+conserve both the potential vorticity and the divergence of the flow, while 
+Eqs (II.4.6c) to (II.4.6e) mean that it dissipates the energy, the enstrophy 
+and the square of the divergence. The two latter properties are only 
+satisfied when the eddy coefficients are horizontally uniform.
+
+Using (II.1.8) and (II.1.9), and the symmetry or anti-symmetry properties of 
+the mean and difference operators, it is shown that the discrete form of the 
+lateral momentum diffusion given in {\S}II.2-c satisfies all the integral 
+constraints (II.4.6) (see appendix C). In particular, when the eddy 
+coefficients are horizontally uniform, a complete separation of vorticity 
+and horizontal divergence fields is ensured, so that diffusion (dissipation) 
+of vorticity (enstrophy) does not generate horizontal divergence (variance 
+of the horizontal divergence) and \textit{vice versa}. When the vertical curl of the horizontal 
+diffusion of momentum (discrete sense) is taken, the term associated to the 
+horizontal gradient of the divergence is zero locally. When the horizontal 
+divergence of the horizontal diffusion of momentum (discrete sense) is 
+taken, the term associated to the vertical curl of the vorticity is zero 
+locally. The resulting term conserves $\chi$ and dissipates 
+$\chi^2$ when the 
+eddy coefficient is horizontally uniform.
+
+\textbf{* vertical momentum diffusion term}
+
+As for the lateral momentum physics, the continuous form of the vertical 
+diffusion of momentum satisfies following integral constraints~:
+
+conservation of momentum, dissipation of horizontal kinetic energy
+
+\begin{equation} \label{Eq_dynzdf_dyn}
+\begin{aligned}
+& \int_D {\frac{1}{e_3 }}  \frac{\partial }{\partial k}\left( \frac{A^{vm}}{e_3 }\frac{\partial {\textbf{U}}_h }{\partial k} \right) \;dv = \overrightarrow{\textbf{0}} \\ 
+& \int_D \textbf{U}_h \cdot \frac{1}{e_3} \frac{\partial}{\partial k} \left( {\frac{A^{vm}}{e_3 }}{\frac{\partial \textbf{U}_h }{\partial k}} \right) \;dv \leq 0 \\ 
+ \end{aligned} 
+ \end{equation}
+conservation of vorticity, dissipation of enstrophy
+\begin{equation} \label{Eq_dynzdf_vor}
+\begin{aligned}
+& \int_D {\frac{1}{e_3 }{\rm {\bf k}}\cdot \nabla \times \left( {\frac{1}{e_3 
+}\frac{\partial }{\partial k}\left( {\frac{A^{vm}}{e_3 }\frac{\partial {\rm 
+{\bf U}}_h }{\partial k}} \right)} \right)\;dv} =0 \\ 
+& \int_D {\zeta \,{\rm {\bf k}}\cdot \nabla \times \left( {\frac{1}{e_3 
+}\frac{\partial }{\partial k}\left( {\frac{A^{vm}}{e_3 }\frac{\partial {\rm 
+{\bf U}}_h }{\partial k}} \right)} \right)\;dv} \leq 0 \\ 
+\end{aligned}
+\end{equation}
+conservation of horizontal divergence, dissipation of square of the 
+horizontal divergence
+\begin{equation} \label{Eq_dynzdf_div}
+\begin{aligned}
+ &\int_D {\nabla \cdot \left( {\frac{1}{e_3 }\frac{\partial }{\partial 
+k}\left( {\frac{A^{vm}}{e_3 }\frac{\partial {\rm {\bf U}}_h }{\partial k}} 
+\right)} \right)\;dv} =0 \\ 
+& \int_D {\chi \;\nabla \cdot \left( {\frac{1}{e_3 }\frac{\partial }{\partial 
+k}\left( {\frac{A^{vm}}{e_3 }\frac{\partial {\rm {\bf U}}_h }{\partial k}} 
+\right)} \right)\;dv} \leq 0 \\ 
+\end{aligned}
+\end{equation}
+
+In discrete form, all these properties are satisfied in $z$-coordinate (see 
+Appendix C). In $s$-coordinates, only first order properties can be 
+demonstrated, i.e. the vertical momentum physics conserve momentum, 
+potential vorticity, and horizontal divergence.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Conservation Properties on Tracer Physics
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Conservation Properties on Tracer Physics}
+\label{Invariant_tra_physics}
+
+The numerical schemes used for tracer subgridscale physics are written in 
+such a way that the heat and salt contents are conserved (equations in flux 
+form, second order centred finite differences). As a form flux is used to 
+compute the temperature and salinity, the quadratic form of these quantities 
+(i.e. their variance) globally tends to diminish. As for the advective term, 
+there is generally no strict conservation of mass even if, in practice, the 
+mass is conserved with a very good accuracy. 
+
+\textbf{* lateral physics: }conservation of tracer, dissipation of tracer 
+variance, i.e.
+
+\begin{equation} \label{Eq_traldf_t_t2}
+\begin{aligned}
+&\int_D \nabla\, \cdot\, \left( A^{lT} \,\Re \,\nabla \,T \right)\;dv = 0 \\ 
+&\int_D \,T\, \nabla\, \cdot\, \left( A^{lT} \,\Re \,\nabla \,T \right)\;dv \leq 0 \\ 
+\end{aligned}
+\end{equation}
+
+\textbf{* vertical physics: }conservation of tracer, dissipation of tracer 
+variance, i.e.
+
+\begin{equation} \label{Eq_trazdf_t_t2}
+\begin{aligned}
+& \int_D \frac{1}{e_3 } \frac{\partial }{\partial k}\left( \frac{A^{vT}}{e_3 }  \frac{\partial T}{\partial k}  \right)\;dv = 0 \\ 
+& \int_D \,T \frac{1}{e_3 } \frac{\partial }{\partial k}\left( \frac{A^{vT}}{e_3 }  \frac{\partial T}{\partial k}  \right)\;dv \leq 0 \\ 
+\end{aligned}
+\end{equation}
+
+Using the symmetry or anti-symmetry properties of the mean and difference 
+operators, it is shown that the discrete form of tracer physics given in 
+{\S}~II.2-c satisfies all the integral constraints (II.4.8) and (II.4.9) 
+except the dissipation of the square of the tracer when non-geopotential 
+diffusion is used (see appendix C). A discrete form of the lateral tracer 
+physics can be derived which satisfies these last properties. Nevertheless, 
+it requires a horizontal averaging of the vertical component of the lateral 
+physics that prevents the use of implicit resolution in the vertical. It has 
+not been implemented.
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DOM.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DOM.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DOM.tex	(revision 4536)
@@ -0,0 +1,738 @@
+
+% ================================================================
+% Chapter 2 Ñ Space and Time Domain (DOM)
+% ================================================================
+\chapter{Space and Time Domain (DOM) }
+\label{DOM}
+\minitoc
+
+% Missing things:
+% 	- istate: description of the initial state
+%	- daymod: definition of the time domain (nit000, nitend andd the calendar)
+% 	-geo2ocean:  how to switch from geographic to mesh coordinate
+%  - domclo:  closed sea and lakes.... management of closea sea area : specific to global configuration, both forced and coupled
+
+
+
+
+
+Having defined the continuous equations in Chap.~\ref{PE}, we need to choose a discretization on a grid, and numerical algorithms. In the present chapter, we provide a general description of the staggered grid used in OPA, and other information relevant to the main directory routines (time stepping, main program) as well as the DOM (DOMain) directory. 
+
+% ================================================================
+% Fundamentals of the Discretisation
+% ================================================================
+\section{Fundamentals of the Discretisation}
+\label{DOM_basics}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Arrangement of Variables 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Arrangement of Variables}
+\label{DOM_cell}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_cell}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_cell.pdf}
+\caption{Arrangement of variables. $T$ indicates scalar points where temperature, salinity, density, pressure and horizontal divergence are defined. ($u$,$v$,$w$) indicates vector points, and $f$ indicates vorticity points where both relative and planetary vorticities are defined}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The numerical techniques used to solve the Primitive Equations in this model are based on the traditional, centred second-order finite difference approximation. Special attention has been given to the homogeneity of the solution in the three space directions. The arrangement of variables is the 
+same in all directions. It consists in cells centred on scalar points ($T$, $S$, $p$, $\rho$) with vector points $(u, v, w)$ defined in the centre of each face of the cells (Fig. \ref{Fig_cell}). This is the generalisation to three dimensions of the well-known ``C'' grid in Arakawa's classification. The relative and planetary vorticity, $\zeta$ and $f$, are defined in the centre of each vertical edge and the barotropic stream function $\psi$ is defined at horizontal points overlying the $\zeta$ and $f$-points.
+
+The ocean mesh ($i.e.$ the position of all the scalar and vector points) is defined by the transformation that gives ($\lambda$ ,$\varphi$ ,$z$) as a function of $(i,j,k)$. The grid-points are located at integer or integer and a half value of $(i,j,k)$ as indicated on Table \ref{Tab_cell}. In all the following, subscripts $u$, $v$, $w$, $f$, $uw$, $vw$ or $fw$ indicate the position of the grid-point where the scale factors are defined. Each scale factor is defined as the local analytical value provided by \eqref{Eq_scale_factors}. As a result, the mesh on which partial derivatives $\frac{\partial}{\partial \lambda}, \frac{\partial}{\partial \varphi}$, and $\frac{\partial}{\partial z} $ are evaluated is a uniform mesh with a grid size unity. Discrete partial derivatives are formulated by the traditional, centred second order finite difference approximation while the scale factors are chosen equal to their local analytical value. An important point here is that the partial derivative of the scale factors must be evaluated by centred finite difference approximation, not from their 
+analytical expression. This preserves the symmetry of the discrete set of equations and therefore allows satisfying many of the continuous properties (see { \colorbox{yellow}{Annexe C}). A similar, related remark can be made about the domain size: when needed, an area, volume, or the total ocean depth must be evaluated as the sum of the relevant scale factors (see \eqref{DOM_bar}) in the next section). 
+
+\begin{table}[!tb] \label{Tab_cell}
+\begin{center} \begin{tabular}{|p{46pt}|p{56pt}|p{56pt}|p{56pt}|}
+\hline
+T	&$i$ 		& $j$		& $k$		 \\ \hline
+u	& $i+1/2$	& $j$		& $k$	 	\\ \hline
+v	& $i$	 	& $j+1/2$	& $k$	 	\\ \hline
+w	& $i$	 	& $j$		& $k+1/2$ 	\\ \hline
+f	& $i+1/2$ 	& $j+1/2$	& $k$	 	\\ \hline
+uw	& $i+1/2$ 	& $j$		& $k+1/2$ 	\\ \hline
+vw	& $i$	 	& $j+1/2$	& $k+1/2$ 	\\ \hline
+fw	& $i+1/2$ 	& $j+1/2$	& $k+1/2$ 	\\ \hline
+\end{tabular}
+\caption{Location of grid-points as a function of integer or integer and a half value of the column, line or level. This indexation is only used for the writing of semi-discrete equation. In the code, the indexation use integer value only and has a reverse direction in the vertical (see \S\ref{DOM_Num_Index})}
+\end{center}
+\end{table}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Vector Invariant Formulation 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Discrete Operators}
+\label{DOM_operators}
+
+Given the values of a variable $q$ at adjacent points, the derivation and averaging operators at the midpoint between them are:
+\begin{subequations} \label{Eq_di_mi}
+\begin{align}
+ \delta _i [q]  &=  \  \    q(i+1/2)  - q(i-1/2)		\\
+ \overline q^i &= \left\{ q(i+1/2) + q(i-1/2) \right\} \; / \; 2
+\end{align}
+\end{subequations}
+
+Similar operators are defined with respect to $i+1/2$, $j$, $j+1/2$, $k$, and $k+1/2$. Following 
+\eqref{Eq_PE_grad} and \eqref{Eq_PE_lap}, the gradient of a variable $q$ defined at $T$-point has its three components defined at $(u,v,w)$ while its Laplacien is defined at $T$-point. These operators have the following discrete forms in the curvilinear $s$-coordinate system:
+\begin{equation} \label{Eq_DOM_grad}
+\nabla q\equiv 	\frac{1}{e_{1u} }\delta _{i+1/2} \left[ q \right]\;\,{\rm {\bf i}}
+			+	\frac{1}{e_{2v} }\delta _{j+1/2} \left[ q \right]\;\,{\rm {\bf j}}
+			+	\frac{1}{e_{3w} }\delta _{k+1/2} \left[ q \right]\;\,{\rm {\bf k}}
+\end{equation}
+\begin{multline} \label{Eq_DOM_lap}
+\Delta q\equiv \frac{1}{e_{1T} {\kern 1pt}e_{2T} {\kern 1pt}e_{3T} }\;\left( 
+{\delta _i \left[ {\frac{e_{2u} e_{3u} }{e_{1u} }\;\delta _{i+1/2} 
+\left[ q \right]} \right]
++\delta _j \left[ {\frac{e_{1v} e_{3v} }{e_{2v} 
+}\;\delta _{j+1/2} \left[ q \right]} \right]\;} \right)		\\
++\frac{1}{e_{3T} }\delta _k \left[ {\frac{1}{e_{3w} }\;\delta _{k+1/2} 
+\left[ q \right]} \right]
+\end{multline}
+
+Following \eqref{Eq_PE_curl} and \eqref{Eq_PE_div}, a vector ${\rm {\bf A}}=\left( a_1,a_2,a_3\right)$ defined at vector points $(u,v,w)$ has its three curl components defined at $(vw,uw,f)$ and its divergence defined at $T$-points:
+\begin{equation} \label{Eq_DOM_curl}
+\begin{split}
+ \nabla \times {\rm {\bf A}}\equiv \frac{1}{e_{2v} {\kern 1pt}e_{3vw} 
+}{\kern 1pt}\,\;\left( {\delta _{j+1/2} \left[ {e_{3w} a_3 } \right]-\delta 
+_{k+1/2} \left[ {e_{2v} a_2 } \right]} \right)	&\;\;{\rm {\bf i}} \\ 
+ +\frac{1}{e_{2u} {\kern 1pt}e_{3uw} }\;\left( {\delta _{k+1/2} \left[ {e_{1u} a_1 } 
+\right]-\delta _{i+1/2} \left[ {e_{3w} a_3 } \right]} \right) 	&\;\;{\rm{\bf j}} \\ 
+ +\frac{e_{3f} }{e_{1f} {\kern 1pt}e_{2f} }\,{\kern 1pt}\;\left( {\delta 
+_{i+1/2} \left[ {e_{2v} a_2 } \right]-\delta _{j+12} \left[ {e_{1u} a_1 } \right]} 
+\right)	&\;\;{\rm {\bf k}}
+ \end{split}
+\end{equation}
+\begin{equation} \label{Eq_DOM_div}
+\nabla \cdot {\rm {\bf A}}=\frac{1}{e_{1T} e_{2T} e_{3T} }\left( {\delta 
+_i \left[ {e_{2u} e_{3u} a_1 } \right]+\delta _j \left[ {e_{1v} e_{3v} a_2 } 
+\right]} \right)+\frac{1}{e_{3T} }\delta _k \left[ {a_3 } \right]
+\end{equation}
+
+In the special case of pure $z$-coordinates system, \eqref{Eq_DOM_lap} and \eqref{Eq_DOM_div} can be simplified. In this case, the vertical scale factor becomes a function of the single variable $k$ and thus does not depend on the horizontal location of a grid point. It can be simplified from outside and inside the $\delta _i$ and $\delta_j$ operators. 
+
+The vertical average over the whole water column denoted by an overbar becomes for a quantity $q$ which is a masked field (i.e. equal to zero inside solid area):
+\begin{equation} \label{DOM_bar}
+\bar q 	= \frac{1}{H}\int_{k^b}^{k^o} {q\;e_{3q} \,dk} 
+		\equiv \frac{1}{H_q }\sum\limits_k {q\;e_{3q} }
+\end{equation}
+where $H_q$  the ocean depth, is the masked sum of the vertical scale factors at q points, $k^b$ and $k^o$ are the bottom and surface $k$-index, and the symbol $k^o$ referring to a summation over all grid points of the same species in the direction indicated by the subscript (here $k$). 
+
+In continuous, the following properties are satisfied:
+\begin{equation} \label{Eq_DOM_curl_grad}
+\nabla \times \nabla q ={\rm {\bf {0}}}
+\end{equation}
+\begin{equation} \label{Eq_DOM_div_curl}
+\nabla \cdot \left( {\nabla \times {\rm {\bf A}}} \right)=0
+\end{equation}
+
+It is straight forward to demonstrate that these properties are verified locally in discrete form as soon as the scalar $q$ is taken at $T$-points and the vector \textbf{A} has its components defined at vector points $(u,v,w)$.
+
+Let $a$ and $b$ be two fields defined on the ocean mesh, extended to zero inside continental area. By integration by part it can be shown that the derivation operators ($\delta_i$, $\delta_j$ and $\delta_k$) are anti-symmetric linear operators, and further that the averaging operators $\overline{\cdot}^i$, $\overline{\cdot}^j$ and $\overline{\cdot}^k$) are symmetric linear operators, i.e.,
+\begin{equation} \label{DOM_di_adj}
+\sum\limits_i {a_i \;\delta _i \left[ b \right]} \equiv -\sum\limits_i 
+{\delta _{i+1/2} \left[ a \right]\;b_{i+1/2} }
+\end{equation}
+\begin{equation} \label{DOM_mi_adj}
+\sum\limits_i {a_i \;\overline b ^i} \equiv \sum\limits_i {\overline a ^{i+1/2}\;b_{i+1/2} } 
+\end{equation}
+
+In other words, the adjoint of the derivation and averaging operators are $\delta_i^*=\delta_{i+1/2}$ and $\overline{\cdot}^{i\,*}= \overline{\cdot}^{i+1/2}$, respectively. These two properties will be used extensively in the \colorbox{yellow} {Appendix C} to 
+demonstrate integral conservative properties of the discrete formulation chosen.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Numerical Indexation 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Numerical Indexation}
+\label{DOM_Num_Index}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_index_hor}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_index_hor.pdf}
+\caption{Horizontal integer indexation used in the \textsc{Fortran} code. The dashed area indicates the cell in which variables contained in arrays have the same $i$- and $j$-indices}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The array representation used in the \textsc{Fortran} code requires an integer indexation while the analytical definition of the mesh (see \S\ref{DOM_cell}) is associated with the use of integer values of $(i,j,k)$ for $T$-points whereas all the other points use both integer and integer and a half values of $(i,j,k)$. Therefore a specific integer indexation must be defined for the latter grid-points 
+(i.e. velocity and vorticity grid-points). Furthermore, it has been chosen to change the direction of the vertical indexation so that the surface level is at $k=1$.
+
+% -----------------------------------
+%        Horizontal Indexation 
+% -----------------------------------
+\subsubsection{Horizontal Indexation}
+\label{DOM_Num_Index_hor}
+
+The indexation in the horizontal plane has been chosen as shown in Fig.\ref{Fig_index_hor}. For an increasing $i$ index ($j$ index), the $T$-point and the eastward $u$-point (northward $v$-point) have the same index (see the dashed area in Fig.\ref{Fig_index_hor}). A $T$-point and its nearby northeast $f$-point have the same $i$-and $j$-indices.
+
+% -----------------------------------
+%        Vertical Indexation 
+% -----------------------------------
+\subsubsection{Vertical Indexation}
+\label{DOM_Num_Index_vertical}
+
+In the vertical plane, the chosen indexation requires special attention since the $k$-axis is re-oriented downward in the \textsc{Fortran} code compared to the indexation used for the semi-discrete equations and given in \S\ref{DOM_cell}. The sea surface corresponds to the $w$-level $k=1$ like the $T-$level just below (Fig.\ref{Fig_index_vert}). The last $w$-level ($k=jpk$) is either the ocean bottom or inside the ocean floor while the last $T-$level is always inside the floor (Fig.\ref{Fig_index_vert}). Note that for an increasing $k$ index, a $w$-point and the $T$-point just below have the same $k$ index, in opposition to what is done in the horizontal plane where 
+it is the $T-$point and the nearby velocity points in the direction of the horizontal axis that have the same $i$ or $j$ index (compare the dashed area in Fig.\ref{Fig_index_hor} and \ref{Fig_index_vert}). As the scale factors are chosen to be strictly positive, \emph{a minus sign appears in the \textsc{Fortran} code before all the vertical derivatives of the discrete equations given in this documentation}.
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!pt] \label{Fig_index_vert}  \begin{center}
+\includegraphics[width=.90\textwidth]{./Figures/Fig_index_vert.pdf}
+\caption{Vertical integer indexation used in the \textsc{Fortran } code. Note that the $k$-axis is oriented downward. The dashed area indicates the cell in which variables contained in arrays have the same $k$-index.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -----------------------------------
+%        Vertical Indexation 
+% -----------------------------------
+\subsubsection{Domain size}
+\label{DOM_size}
+
+The total size of the computational domain is set by the parameters \jp{jpiglo}, \jp{jpjglo} and \jp{jpk} in the $i$, $j$ and $k$ directions respectively. They are given as parameters in the \mdl{par\_oce} module (or additional files included in this module such as \textit{par\_ORCA\_R2.h90}, specific to a given configuration). The use of parameters rather than variables (together with dynamic allocation of arrays) was made because it ensured that the compiler would optimize the executable code efficiently, especially on vector machines (optimization may be less efficient when the problem size is unknown at the time of compilation). Nevertheless, it is possible to set up the code with full dynamical allocation by using the AGRIF packaged \colorbox{yellow}{(ref agrif!+ ref part of the doc)}. Note that are other parameters in \mdl{par\_oce} that refer to the domain size. The two parameters $jpidta$ and $jpjdta$, may be larger than $jpiglo$, $jpjglo$ when the user wants to use only a sub-region of a given configuration. This is the "zoom" capability described in \S\ref{MISC_zoom}. In most applications of the model, $jpidta=jpiglo$, $jpjdta=jpjglo$, and $jpizoom=jpjzoom=1$. Parameters $jpi$ and $jpj$ refer to the size of each processor subdomain when the code is run in parallel using domain decomposition (\key{mpp\_mpi} defined, see \S\ref{LBC_mpp}).
+
+% ================================================================
+% Domain: Horizontal Grid (mesh) 
+% ================================================================
+\section{Domain: Horizontal Grid (mesh) (\mdl{domhgr} module)}
+\label{DOM_hgr}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Coordinates and scale factors 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Coordinates and scale factors}
+\label{DOM_hgr_coord_e}
+
+The ocean mesh (i.e. the position of all the scalar and vector points) is defined by the transformation that gives $(\lambda,\varphi,z)$ as a function of $(i,j,k)$. The grid-points are located at integer or integer and a half values of as indicated in Table~\ref{Tab_cell}. The associated scale factors are defined using the analytical first derivative of the transformation \eqref{Eq_scale_factors}. These definitions are done in two modules, \mdl{domhgr} and \mdl{domzgr}, which provide the horizontal and vertical meshes, respectively. This section deals with the horizontal mesh parameters.
+
+In a horizontal plane, the location of all the model grid points is defined from the analytical expressions of the latitude $\varphi$ and the longitude $\lambda$ as a function of  $(i,j)$. The horizontal scale factors are calculated using \eqref{Eq_scale_factors}. For example, when the latitude and longitude are function of a single value ($j$ and $i$, respectively) (geographical configuration of the mesh), the horizontal mesh definition reduces to define the wanted $\varphi(j)$, $\varphi'(j)$, $\lambda(i)$, and $\lambda'(i)$ in the \mdl{domhgr} module. The model computes the grid-point positions and scale factors in the horizontal plane as follows:
+\begin{flalign*}
+\lambda_T &\equiv \text{glamt} = \lambda(i)	&		\varphi_T &\equiv \text{gphit} = \varphi(j)\\
+\lambda_u &\equiv \text{glamu}= \lambda(i+1/2)&		\varphi_u &\equiv \text{gphiu}= \varphi(j)\\
+\lambda_v &\equiv \text{glamv}= \lambda(i)		&		\varphi_v &\equiv \text{gphiv} = \varphi(j+1/2)\\
+\lambda_f &\equiv \text{glamf }= \lambda(i+1/2)&		\varphi_f &\equiv \text{gphif }= \varphi(j+1/2) 
+\end{flalign*}
+\begin{flalign*}
+e_{1T} &\equiv \text{e1t} = r_a |\lambda'(i)		\; \cos\varphi(j)  |&
+e_{2T} &\equiv \text{e2t} = r_a |\varphi'(j)|\\
+e_{1u} &\equiv \text{e1t} = r_a |\lambda'(i+1/2)	\; \cos\varphi(j)  |&
+e_{2u} &\equiv \text{e2t} = r_a |\varphi'(j)|\\
+e_{1v} &\equiv \text{e1t} = r_a |\lambda'(i)		\; \cos\varphi(j+1/2)  |&
+e_{2v} &\equiv \text{e2t} = r_a |\varphi'(j+1/2)|\\
+e_{1f} &\equiv \text{e1t} = r_a |\lambda'(i+1/2)\; \cos\varphi(j+1/2)  |&
+e_{2f} &\equiv \text{e2t} = r_a |\varphi'(j+1/2)|
+\end{flalign*}
+where the last letter of each computational name indicates the grid point considered and $r_a$ is the earth radius (defined in \mdl{phycst} along with all universal constants). Note that the horizontal position and scale factors of $w$-points are exactly equal to those of $T-$points, thus no specific arrays are defined at those grid-points. 
+
+Note that the definition of the scale factors --- as the analytical first derivative of the transformation that gives $(\lambda,\varphi,z)$ as a function of $(i,j,k)$ --- is specific to the OPA model \citep{Marti1992}. As an example, $e_{1T}$ is defined locally at a $T$-point, whereas many other models on a C grid choose to define such a scale factor as the distance between the $U$-points on each side of the $T$-point. Relying on an analytical transformation has two advantages: firstly, there is no ambiguity in the scale factors appearing in the discrete equations, since they are first introduced in the continuous equations; secondly, analytical transformations encourage good practice by the definition of smooth grids \citep{Treguier1996}. An example of the effect of such a choice is shown in Fig.~\ref{Fig_zgr_e3}.
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_zgr_e3}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_zgr_e3.pdf}
+\caption{(a) Traditional definition of grid-point position and grid-size in the vertical versus (b) analytically derived grid-point position and scale factors. For both grid here,a same $w$-point depth has been chosen but in (a) the $T$-points are set at the middle of $w$-points while in (b) they are defined from an analytical function: $z(k)=5\,(i-1/2)^3 - 45\,(i-1/2)^2 + 140\,(i-1/2) - 150$. Note the resulting difference between the value of the grid-size $\Delta_k$ and those of the scale factor $e_k$. }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -------------------------------------------------------------------------------------------------------------
+%        Choice of horizontal grids 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Choice of horizontal grids}
+\label{DOM_hgr_msh_choice}
+
+The user has three options to define a horizontal grid, involving the parameter $jphgr\_mesh$ of the \mdl{par\_oce} module. 
+\begin{enumerate}
+\item For the most general curvilinear orthogonal grids, the coordinates and their first derivatives with respect to $i$ and $j$ are provided in a file, read in \rou{hgr\_read} subroutine of the domhgr module: \jp{jphgr\_mesh}=0.
+\item A few simple analytical grids are provided as examples, that can be selected by setting \jp{jphgr\_mesh}=1 to 5 (see below) 
+\item For other analytical grids, the \mdl{domhgr} module must be modified by the user. 
+\end{enumerate}
+
+There are two simple cases of geographical grids on the sphere. With \jp{jphgr\_mesh}=1, the grid is regular in space, with grid sizes specified by parameters \pp{ppe1\_deg} and \pp{ppe2\_deg}, respectively. A geographical grid 
+can be very anisotropic at high latitudes, because of the convergence of meridians (the zonal scale factors $e_1$ become much smaller than the meridional scale factors $e_2$). The Mercator grid (\jp{jphgr\_mesh}=4) avoids this anisotropy by refining the meridional scale factors in the same way as the zonal ones. In that case, meridional scale factors and latitudes are calculated analytically using the formulae appropriate for a Mercator projection, based on \pp{ppe1\_deg} which is a reference grid spacing at the equator (this applies even when the geographical equator is situated outside the model domain). In those two cases (\jp{jphgr\_mesh}=1 or 4), the grid position is defined by the longitude and latitude of the south-westhernmost point (\pp{ppglamt0} and \pp{ppgphi0}). Note that for the Mercator grid the user need only provide an approximate starting latitude: the real latitude will be recalculated analytically, so as to ensure that the equator corresponds to a $T$- and$ U$-point.  
+
+Rectangular grids ignoring the spherical geometry are defined with \jp{jphgr\_mesh} = 2, 3, 5. The domain is either a $f$-plane (\jp{jphgr\_mesh} = 2, Coriolis factor is constant) or a beta-plane (\jp{jphgr\_mesh} = 3, the Coriolis factor is linear in the $j$-direction). The grid size is uniform in each direction, and given in meters by the parameters \pp{ppe1\_m} and \pp{ppe2\_m} respectively. The zonal grid coordinate (glam. arrays) is in kilometers, starting at zero with the first T point. The meridional coordinate (gphi. arrays) is in kilometers, and the second $T$-point corresponds to coordinate gphit=0. The input parameter \pp{ppglam0} is ignored. \pp{ppgphi0} is used to set the reference latitude for computation of the Coriolis parameter. In the case of the beta plane, \pp{ppgphi0} corresponds to the center of the domain. Finally, the special case \jp{jphgr\_mesh}=5 corresponds to a beta plane in a rotated domain for the GYRE configuration representing a classical mid-latitude double gyre system. The rotation allows to maximize the jet length relative to the gyre areas (and the number of grid points). 
+
+The choice of the grid must be consistent with the boundary conditions specified by the parameter \jp{jperio} (see {\S\ref{LBC}).
+
+% -------------------------------------------------------------------------------------------------------------
+%        Grid files
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Grid files}
+\label{DOM_hgr_files}
+
+All the arrays related to a particular ocean model configuration (grid-point position, scale factors, masks) can be saved in files if $\np{nmsh} \not= 0$ (namelist parameter). This can be particularly useful for plots and off-line diagnostics. In some cases, the user may choose to make a local modification of a scale factor in the code. This is the case in global configurations when restricting the width of a specific strait (usually a one-grid-point strait that happens to be too wide due to the insufficient model resolution). On example is Lombok Strait in the ORCA2 configuration. When such modifications are done, the output grid written when $\np{nmsh} \not=0$ is not exactly equal to the input grid.
+
+% ================================================================
+% Domain: Vertical Grid (domzgr)
+% ================================================================
+\section{Domain: Vertical Grid (\mdl{domzgr} module)}
+\label{DOM_zgr}
+%-----------------------------------------nam_zgr & namdom-------------------------------------------
+\namdisplay{nam_zgr} 
+\namdisplay{namdom} 
+%-------------------------------------------------------------------------------------------------------------
+
+In the vertical, the model mesh is determined by four things: (1) the bathymetry given in meters ; (2) the number of levels of the model (\jp{jpk}) ; (3) the analytical transformation $z(i,j,k)$ and the vertical scale factors 
+(derivatives of the transformation) ; and (4) the masking system, i.e. the number of wet model levels at each $(i,j)$.
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_z_zps_s_sps}  \begin{center}
+\includegraphics[width=1.0\textwidth]{./Figures/Fig_z_zps_s_sps.pdf}
+\caption{The ocean bottom as seen by the model: (a) $z$-coordinate with full step, (b) $z$-coordinate with partial step, (c) $s$-coordinate: terrain following representation, (d) hybrid $s-z$ coordinate, (e) hybrid $s-z$ coordinate with partial step, and (f) same as (e) but with variable volume level associated with the non-linear free surface. Note that the variable volume level (\key{vvl}) could be used with any of the 5 coordinates (a) to (e).}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The choice of a vertical coordinate among all those offered in NEMO, even if it is made through a namelist parameter, must be done once of all at the beginning of an experiment. It is not intended as an option which can be 
+enabled or disabled in the middle of an experiment. Three main choices are offered (Fig.~\ref{Fig_z_zps_s_sps}a to c): $z$-coordinate with full step bathymetry (\np{ln\_zco}=true), $z$-coordinate with partial step bathymetry (\np{ln\_zps}=true), or generalized, $s$-coordinate (\np{ln\_sco}=true). Hybridation of the three main 
+coordinates are available: hybrid $s-z$ or $s-zps$ coordinate (Fig.~\ref{Fig_z_zps_s_sps}d and \ref{Fig_z_zps_s_sps}e). When using the variable volume option \key{vvl}), the coordinate follow the time-variation of the free surface so that the transformation is time dependent: $z(i,j,k,t)$ (Fig.~\ref{Fig_z_zps_s_sps}f). This option can be used with full step bathymetry or $s$-coordinates (hybride and partial step coordinates not yet implemented in NEMO v2.3). 
+
+Contrary to the horizontal grid, the vertical grid is computed in the code and no provision is made for reading it from a file. The only input file is the bathymetry (in meters). After reading the bathymetry, the algorithm for vertical grid definition differs between the different options:
+\begin{description}
+\item[\textit{zco}] set a reference coordinate transformation $z_0 (k)$, and set $z(i,j,k,t)=z_0 (k)$.
+\item[\textit{zps}] set a reference coordinate transformation $z_0 (k)$, and 
+calculate the height at the deepest levels using the bathymetry, to obtain the final three-dimensional depth and scale factor arrays.
+\item[\textit{sco}] Smooth the bathymetry to fullfill the hydrostatic consistency criteria and set the three-dimensional transformation.
+\item[\textit{s-z} and \textit{s-zps}] Smooth the bathymetry to fullfill the hydrostatic consistency criteria and set the three-dimensional transformation $z(i,j,k)$, and possibly introduce masking of extra land points to better fit the original bathymetry file
+\end{description}
+
+Generally, the arrays describing the grid point depths and vertical scale factors are three dimensional arrays $(i,j,k)$. In the special case of $z$-coordinates with full step bottom topography, it is possible to define 
+those arrays as one-dimensional, in order to save memory. This is performed by defining the \key{zco} C-Pre-Processor (CPP) key. To improve the code readability while providing this flexibility, the vertical coordinates and scale factors are defined as functions of $(i,j,k)$ with "fs" as prefix (examples: \textit{fsdeptht, fse3t,} etc) that can be equal to three-dimensional arrays, or a one dimensional array when \key{zco} is defined. These functions are defined in the file 
+\textit{domzgr\_substitute.h90} of the DOM directory. They are used through the code, and replaced by the corresponding arrays at the time of pre-processing (CPP capability).
+
+% -------------------------------------------------------------------------------------------------------------
+%        Meter Bathymetry
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Meter Bathymetry}
+\label{DOM_bathy}
+
+Three options are possible for defining the bathymetry, according to the 
+namelist variable \np{ntopo}: 
+\begin{description}
+\item[\np{ntopo} = 0] a flat-bottom domain is defined. The total depth $z_w (jpk)$ is given by the coordinate transformation. The domain can either a closed basin or a periodic channel according to the parameter \jp{jperio}. 
+\item[\np{ntopo} = -1] a domain with a bump of topography at the central latitude and 1/3 of the domain width. This is meant for the "EEL-R5" configuration, a periodic or open boundary channel with a seamount. 
+\item[\np{ntopo} = 1] read a bathymetry. The bathymetry file (Netcdf format) provides the ocean depth (positive, in meters) at each grid point of the model grid. The bathymetry is usually built by interpolating a standard bathymetry product (e.g., ETOPO2) onto the horizontal ocean mesh. The bathymetry file defines the coastline: where the bathymetry is zero, no model levels are defined (all levels are masked).
+\end{description}
+
+When using the rigid lid approximation (\key{dynspg\_rl} defined) isolated land masses (islands) must be identified by negative integers in the input bathymetry file (see \S\ref{MISC_solisl}).
+
+When the ocean is coupled to an atmospheric model it is better to represent 
+all large water bodies (e.g, great lakes, Caspian sea...) even if the model 
+resolution does not allow to represent their communication with the rest of 
+the ocean. This is unnecessary when the ocean is forced by fixed atmospheric 
+conditions. A possibility is offered to the user to set to zero the 
+bathymetry in rectangular regions covering those closed seas (see \S\ref{MISC_closea})
+
+% -------------------------------------------------------------------------------------------------------------
+%        z-coordinate  and reference coordinate transformation
+% -------------------------------------------------------------------------------------------------------------
+\subsection	[$z$-coordinate (\np{ln\_zco}=T or \key{zco})]
+			{$z$-coordinate (\np{ln\_zco}=T or \key{zco}) and reference coordinate}
+\label{DOM_zco}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_zgr}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_zgr.pdf}
+\caption{Default vertical mesh for ORCA2-L30. Vertical level functions for (a) T-point depth and (b) the associated scale factor as computed from (III.2.1) in z-coordinates.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The reference coordinate transformation $z_0 (k)$ defines the arrays \textit{gdept0} and \textit{gdepw0} for $T$- and $w$-points, respectively. As indicated on Fig.\ref{Fig_index_vert} \jp{jpk} is the number of $w$-levels. $gdepw(1)$ being the ocean surface. There are at most \jp{jpk}-1 $T$-points in the ocean, the additional $T$-point at $jk=jpk$ is below the sea floor and is not used. The vertical location of $w$- and $T$-levels is defined from the analytic expression of the depth $z_0 (k)$ whose analytic derivative with respect to $k$ provides the vertical scale factors. The user must provide the analytical expression of both $z_0 $and its first derivative with respect to $k$. This is done in routine \mdl{domzgr} through statement functions, using parameters provided in the \textit{par\_oce.h90} file. 
+
+It is possible to define a simple regular vertical grid by giving zero stretching (\pp{ppacr=0}). In that case, the parameters \jp{jpk} (number of $w$-levels) and \pp{pphmax} (total ocean depth in meters) fully define the grid. 
+
+For climate-related studies it is often desirable to concentrate the vertical resolution near the ocean surface. The following function is proposed as a standard for $z$-coordinates and partial steps: 
+\begin{equation} \label{DOM_zgr_ana}
+\begin{split}
+ z_0 (k) 	&= h_{sur} -h_0 \;k-\;h_1 \;\log \left[ {\,\cosh \left( {{(k-h_{th} )} / {h_{cr} }} \right)\,} \right] \\ 
+ e_3^0 (k) 	&= \left| -h_0 -h_1 \;\tanh \left( {{(k-h_{th} )} / {h_{cr} }} \right) \right| 
+\end{split}
+\end{equation}
+where $k=1$ to \jp{jpk} for $w$-levels and $k=1$ to $k=1$ for $T-$levels. Such an expression allows us to define a nearly uniform vertical location of levels at the ocean top and bottom with a smooth hyperbolic tangent transition in between (Fig.~\ref{Fig_zgr}).
+
+The first grid defined for ORCA2 had $10~m$ ($500~m)$ resolution in the surface (bottom) layers and a depth which varies from 0 at the sea surface to a minimum of $-5000~m$. This leads to the following conditions:
+\begin{equation} \label{DOM_zgr_coef}
+\begin{split}
+ e_3 (1+1/2)		&=10. \\ 
+ e_3 (jpk-1/2)	&=500. \\ 
+ z(1)			&=0. \\ 
+ z(jpk)			&=-5000. \\ 
+\end{split}
+\end{equation}
+
+With the choice of the stretching $h_{cr} =3$ and the number of levels \jp{jpk}=$31$, the four coefficients $h_{sur}$, $h_{0}$, $h_{1}$, and $h_{th}$ in \eqref{DOM_zgr_ana} have been determined such that \eqref{DOM_zgr_coef} is satisfied, through an optimisation procedure using a bisection method. For the first standard 
+ORCA2 vertial grid this led to the following values: $h_{sur} =4762.96$, $h_0 =255.58, h_1 =245.5813$, and $h_{th} =21.43336$. The resulting depths and scale factors as a function of the model levels are shown in Fig.~\ref{Fig_zgr} and given in Table \ref{Tab_orca_zgr}. Those values correspond to the parameters \pp{ppsur}, \pp{ppa0}, \pp{ppa1}, \pp{ppkth} in the parameter file \mdl{par\_oce}. 
+
+Rather than entering parameters $h_{sur}$, $h_{0}$, and $h_{1}$ directly, it is 
+possible to recalculate them. In that case the user sets 
+\pp{ppsur}=\pp{ppa0}=\pp{ppa1}=\pp{pp\_to\_be\_computed}, in \mdl{par\_oce}, and specifies instead the four following parameters:
+\begin{itemize}
+\item 	\pp{ppacr}=$h_{cr} $: stretching factor (nondimensional). The larger \pp{ppacr}, the smaller the stretching. Values from $3$ to $10$ are usual.
+\item 	\pp{ppkth}=$h_{th} $: is approximately the model level at which maximum stretching occurs (nondimensional, usually of order 1/2 or 2/3 of \jp{jpk})
+\item 	\pp{ppdzmin}: minimum thickness for the top layer (in meters)
+\item 	\pp{pphmax}: total depth of the ocean (meters).
+\end{itemize}
+As an example, for the $45$ layers used in DRAKKAR configuration those parameters are: \jp{jpk}=46, \pp{ppacr}=9, \pp{ppkth}=23.563, \pp{ppdzmin}=6m, \pp{pphmax}=5750m.
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{table} \label{Tab_orca_zgr}
+\begin{center} \begin{tabular}{c||r|r|r|r}
+\hline
+\textbf{LEVEL}& \textbf{GDEPT}& \textbf{GDEPW}& \textbf{E3T }& \textbf{E3W  } \\ \hline
+1	&	\textbf{  5.00}	&       0.00 &	\textbf{ 10.00} &	 10.00 \\	\hline
+2	&	\textbf{15.00}	& 	  10.00 &	\textbf{ 10.00} &	 10.00 \\	\hline
+3	&	\textbf{25.00}	&	  20.00 &	\textbf{ 10.00} & 	 10.00 \\	\hline
+4	&	\textbf{35.01}	&	  30.00 & 	\textbf{ 10.01} & 	 10.00 \\	\hline
+5	&	\textbf{45.01}	&	  40.01 &	\textbf{ 10.01} &	 10.01 \\	\hline
+6	&	\textbf{55.03}	&	  50.02 &	\textbf{ 10.02} & 	 10.02 \\	\hline
+7	&	\textbf{65.06}	&	  60.04 &	\textbf{ 10.04} &	 10.03 \\	\hline
+8	&	\textbf{75.13}	&	  70.09 &	\textbf{ 10.09} &	 10.06 \\	\hline
+9	&	\textbf{85.25}	&	  80.18 &	\textbf{ 10.17} &	 10.12 \\	\hline
+10	& 	\textbf{95.49}	& 	  90.35 &	\textbf{ 10.33} &	 10.24 \\	\hline
+11	& 	\textbf{105.97}	& 	 100.69 &	\textbf{ 10.65} &	 10.47 \\	\hline
+12	& 	\textbf{116.90}	& 	 111.36 &	\textbf{ 11.27} &	 10.91 \\	\hline
+13	& 	\textbf{128.70}	& 	 122.65 &	\textbf{ 12.47} &	 11.77 \\	\hline
+14	& 	\textbf{142.20}	& 	 135.16 &	\textbf{ 14.78} &	 13.43 \\	\hline
+15	& 	\textbf{158.96}	& 	 150.03 &	\textbf{ 19.23} &	 16.65 \\	\hline
+16	& 	\textbf{181.96}	& 	 169.42 &	\textbf{ 27.66} &	 22.78 \\	\hline
+17	& 	\textbf{216.65}	& 	 197.37 & 	\textbf{ 43.26} &	 34.30 \\ \hline
+18	& 	\textbf{272.48}	& 	 241.13 & 	\textbf{ 70.88} &	 55.21 \\ \hline
+19	& 	\textbf{364.30}	& 	 312.74 & 	\textbf{116.11} &	 90.99 \\ \hline
+20	& 	\textbf{511.53}	& 	 429.72 & 	\textbf{181.55} & 	146.43 \\ \hline
+21	& 	\textbf{732.20}	& 	 611.89 & 	\textbf{261.03} & 	220.35 \\ \hline
+22	& 	\textbf{1033.22}&	 872.87 & 	\textbf{339.39} & 	301.42 \\ \hline
+23	& 	\textbf{1405.70}&	1211.59 & 	\textbf{402.26} & 	373.31 \\ \hline
+24	& 	\textbf{1830.89}&	1612.98 & 	\textbf{444.87} & 	426.00 \\ \hline
+25	& 	\textbf{2289.77}&	2057.13 & 	\textbf{470.55} & 	459.47 \\ \hline
+26	& 	\textbf{2768.24}&	2527.22 & 	\textbf{484.95} & 	478.83 \\ \hline
+27	& 	\textbf{3257.48}&	3011.90 & 	\textbf{492.70} & 	489.44 \\ \hline
+28	& 	\textbf{3752.44}&	3504.46 & 	\textbf{496.78} & 	495.07 \\ \hline
+29	& 	\textbf{4250.40}&	4001.16 & 	\textbf{498.90} & 	498.02 \\ \hline
+30	& 	\textbf{4749.91}&	4500.02 & 	\textbf{500.00} &	499.54 \\ \hline
+31	& 	\textbf{5250.23}&	5000.00 &	\textbf{500.56} &	500.33 \\ \hline
+\end{tabular} \end{center} 
+\caption{Default vertical mesh in $z$-coordinate for 30 layers ORCA2 configuration as computed from \eqref{DOM_zgr_ana} using the coefficients given in \eqref{DOM_zgr_coef}}
+\end{table}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -------------------------------------------------------------------------------------------------------------
+%        z-coordinate with partial step
+% -------------------------------------------------------------------------------------------------------------
+\subsection{z-coordinate with partial step (\np{ln\_zps}=T)}
+\label{DOM_zps}
+%--------------------------------------------namdom-----------------------------------------------------
+\namdisplay{namdom} 
+%--------------------------------------------------------------------------------------------------------------
+
+In that case, the depths of the model levels are still defined by the 
+reference analytical function $z_0 (k)$ as described in the previous 
+section, excepted in the bottom layer. The thickness of the bottom layer is 
+allowed to vary as a function of geographical location $(\lambda,\varphi)$ to allow a 
+better representation of the bathymetry, especially in the case of small 
+slopes (where the bathymetry varies by less than one level thickness from 
+one grid point to the next). The reference layer thicknesses $e_{3t}^0$ have been 
+defined in the absence of bathymetry. With partial steps, layers from 1 to 
+\jp{jpk}-2 can have a thickness smaller than $e_{3t}(jk)$. The model deepest layer (\jp{jpk}-1) is 
+allowed to have either a smaller or larger thickness than $e_{3t}(jpk)$: the 
+maximum thickness allowed is $2*e_{3t}(jpk-1)$. This has to be kept in mind when 
+specifying the maximum depth \pp{pphmax} in partial steps: for example, with 
+\pp{pphmax}$=5750~m$ for the DRAKKAR 45 layers grid, the maximum ocean depth allowed is actually $6000~m$ (the default thickness $e_{3t}(jpk-1)$ being $250~m$). Two 
+variables in the namdom namelist are used to define the partial step 
+vertical grid. The mimimum water thickness (in meters) allowed for a cell 
+partially filled with bathymetry at level jk is the minimum of \np{e3zpsmin} 
+(thickness in meters, usually $20~m$) or $e_{3t}(jk)*\np{e3zps\_rat}$ (a fraction, 
+usually 10\%, of the default thickness $e_{3t}(jk)$).
+
+ \colorbox{yellow}{Add a figure here of pstep especially at last ocean level }
+
+% -------------------------------------------------------------------------------------------------------------
+%        s-coordinate
+% -------------------------------------------------------------------------------------------------------------
+\subsection{$s$-coordinate (\np{ln\_sco}=T)}
+\label{DOM_sco}
+%--------------------------------------------nam_zgr_sco---------------------------------------------------
+\namdisplay{nam_zgr_sco} 
+%--------------------------------------------------------------------------------------------------------------
+In s-coordinate (\key{sco} defined), the depths of the model 
+levels are defined from the product of a depth field and a stretching 
+function and its derivative, respectively:
+\begin{equation} \label{DOM_sco_ana}
+\begin{split}
+ z(k) 	&= h(i,j) \; z_0(k)	\\
+ e_3(k)	&= h(i,j) \; z_0'(k)
+\end{split}
+\end{equation}
+where $h$ is the depth of the last $w$-level ($z_0(k)$) defined at $T-$point location 
+in the horizontal and $z_0 (k)$ is a function which varies from $0$ at the sea 
+surface to $1$ at the ocean bottom. The depth field $h$ is not necessary the ocean 
+depth as a mixed step-like and bottom following representation of the 
+topography can be used (Fig.~\ref{Fig_z_zps_s_sps}d-e). In the example provided (\hf{zgr\_s} file) $h$ is a smooth envelope bathymetry and steps are used to represent sharp bathymetric gradients.
+
+A new flexible stretching function, modified from \citet{Song1994} is provided as an example:
+\begin{equation} \label{DOM_sco_function}
+\begin{split}
+z	&= h_c +( h-h_c)\;c s)	\\
+c(s)	&=  \frac{ \left[	  \tanh{ \left( \theta \, (s+b) \right)} 
+	  	 			- \tanh{ \left(  \theta \, b      \right)}  \right]}
+		      {2\;\sinh \left( \theta \right)}
+\end{split}
+\end{equation}
+where $h_c $is the thermocline depth and $\theta $ and $b$ are the surface and 
+bottom control parameters such that $0\leqslant \theta \leqslant 20$, and 
+$0\leqslant b\leqslant 1$. Examples of the stretching function applied to a seamount are given in Fig.~\ref{Fig_sco_function}.
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_sco_function}  \begin{center}
+\includegraphics[width=1.0\textwidth]{./Figures/Fig_sco_function.pdf}
+\caption{examples of the stretching function applied to a sea mont: from left to right, surface, surface and bottom, and bottom intensified resolution}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -------------------------------------------------------------------------------------------------------------
+%        z*- or s*-coordinate
+% -------------------------------------------------------------------------------------------------------------
+\subsection{$z^*$- or $s^*$-coordinate (add \key{vvl}) }
+\label{DOM_zgr_vvl}
+
+This option is described in the report by Levier \textit{et al.} (2007), available on the NEMO web site. 
+
+%gm% key advantage: minimise the diffusion/dispertion associated with advection in response to high frequency surface disturbances
+
+% -------------------------------------------------------------------------------------------------------------
+%        level bathymetry and mask 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{level bathymetry and mask}
+\label{DOM_msk}
+
+Whatever the vertical coordinate used, the model offers the possibility of 
+representing the bottom topography with steps that follow the face of the 
+model cells (step like topography) \citep{Madec1996}. The distribution of 
+the steps in the horizontal is defined in a 2D integer array, mbathy, which 
+gives the number of ocean levels ($i.e.$ those that are not masked) at each 
+$T$-point. mbathy is computed from the meter bathymetry using the definiton of 
+gdept as the number of $T$-points which gdept $\leq$ bathy. Note that in version 
+NEMO v2.3, the user still has to provide the "level" bathymetry in a NetCDF
+file when using the full step option (\np{ln\_zco}), rather than the bathymetry 
+in meters: both will be allowed in future versions.
+
+Modifications of the model bathymetry are performed in the \textit{bat\_ctl} 
+routine (see \mdl{domzgr} module) after mbathy is computed. Isolated grid points that do not 
+communicate with another ocean point at the same level are eliminated.
+
+In case of rigid-lid approximation and islands in the computational domain (\np{ln\_dynspg\_rl}=true and \key{island} defined), the \textit{mbathy} array must be provided and takes values from $-N$ to \jp{jpk}-1. It provides the 
+following information: $mbathy(i,j) = -n, \ n \in \left] 0,N \right]$, $T-$points are land points of the $n^{th}$ island ; $mbathy(i,j) =0$, $T-$points are land points of the main land (continent) ; $mbathy(i,j) =k$, the first $k$ $T$- and $w$-points are ocean points, the others land points. This is used to compute the island barotropic stream function used in rigid lid computation (see \S\ref{LBC_isl}).
+
+From the \textit{mbathy} array, the mask fields are defined as follows:
+\begin{align*}
+tmask(i,j,k) &= \begin{cases}   1&   \text{ if $k\leq mbathy(i,j)$  }    \\
+                                              0&   \text{ if $k\leq mbathy(i,j)$  }    \end{cases}     \\
+umask(i,j,k) &= \; tmask(i,j,k) \;.\; tmask(i+1,j,k)	\\
+umask(i,j,k) &= \; tmask(i,j,k) \;.\; tmask(i,j+1,k)	\\
+umask(i,j,k) &= \; tmask(i,j,k) \;.\; tmask(i+1,j,k)	\\
+                  & \quad . \; tmask(i,j,k) \;.\; tmask(i+1,j,k)
+\end{align*}
+
+Note that \textit{wmask} is not defined as it is exactly equal to \textit{tmask} with the numerical 
+indexation used (\S~\ref{DOM_Num_Index}). Moreover, the specification of closed lateral 
+boundaries requires that at least the first and last rows and columns of 
+\textit{mbathy} array are set to zero. In the particular case of an east-west cyclic 
+boundary condition, \textit{mbathy} has its last column equal to the second one and its 
+first column equal to the last but one (and so the mask arrays) (see \S~\ref{LBC_jperio}).
+
+\colorbox{yellow}{Add one word on tricky trick !} mbathy in further modified in zdfbfr{\ldots}.
+
+% ================================================================
+% Time discretisation
+% ================================================================
+\section{Time Discretisation}
+\label{DOM_nxt}
+
+The time stepping used in OPA is a three level scheme that can be presented as follows:
+\begin{equation} \label{Eq_DOM_nxt}
+   x^{t+\Delta t} = x^{t-\Delta t} + 2 \, \Delta t \  \text{RHS}_x^{t-\Delta t,t,t+\Delta t}
+\end{equation} 
+where $x$ stand for $u$, $v$, $T$ or $S$, RHS is the Right-Hand-Side of the corresponding time 
+evolution equation, $\Delta t$ is the time step and the overscripts indicate 
+the time at which a quantity is evaluated. Each term of the RHS is evaluated at 
+specific time step(s) depending on the physics to which it is associated. 
+The choice of the time step used for this evaluation is discussed below as 
+well as the implication in term of starting or restarting a model 
+simulation. Note that the time stepping is generally performed in a one step 
+operation: it would be dangerous to let a prognostic variable evolve in time for each term successively.
+
+The three level scheme requires three arrays for the prognostic variables. For each variable $x$ there is $x_b$ (before) and $x_n$ (now). The third array, although referred to as $x_a$ (after) in the code, is usually not the variable $x_a$ at the next time step; rather, it is used to store the time derivative (RHS in \eqref{Eq_DOM_nxt}) prior to time-stepping the equation. Generally, the time stepping is performed once at each time step in \mdl{tranxt} and \mdl{dynnxt} modules, excepted for implicit vertical diffusion or sea surface height when time-splitting options are used.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Non-Diffusive Part---Leapfrog Scheme
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Non-Diffusive Part --- Leapfrog Scheme}
+\label{DOM_nxt_leap_frog}
+
+The time stepping used for non-diffusive processes is the well-known 
+leapfrog scheme. It is a time centred scheme, i.e. the RHS are evaluated at 
+time step $t$, the now time step. It is only used for non-diffusive terms, 
+that is momentum and tracer advection, pressure gradient, and coriolis 
+terms. This scheme is widely used for advective processes in low-viscosity 
+fluids. It is an efficient method that achieves second-order accuracy with 
+just one right hand side evaluation per time step. Moreover, it does not 
+artificially damp linear oscillatory motion nor does it produce instability 
+by amplifying the oscillations. These advantages are somewhat diminished by 
+the large phase-speed error of the leapfrog scheme, and the unsuitability of 
+leapfrog differencing for the representation of diffusive and Rayleigh 
+damping processes. However, the most serious problem associated with the 
+leapfrog scheme is a high-frequency computational noise called 
+"time-splitting" \citep{Haltiner1980} that develops when the method 
+is used to model non linear fluid dynamics: the even and odd time steps tend 
+to diverge between a physical and a computational mode. Time splitting can 
+be controlled through the use of an Asselin time filter (first designed by 
+\citep{Robert1966} and more comprehensively studied by \citet{Asselin1972}) or by 
+periodically reinitialising the leapfrog solution through a single 
+integration step with a two-level scheme. In OPA we follow the first 
+strategy:
+\begin{equation} \label{Eq_DOM_nxt_asselin}
+x_F^t  = x^t + \gamma \, \left[ x_f^{t-\Delta t} - 2 x^t + x^{t+\Delta t} \right]
+\end{equation} 
+where the subscript $f$ denotes filtered values and $\gamma$ is the asselin coefficient. $\gamma$ is initialized as \np{atfp} (namelist parameter). Its default value is \np{atfp}=0.1.  This default value causes a significant dissipation of high frequency motions. Recommanded values in idealized studies of shallow water turbulence are two order of magnitude lower (\citep{Farge1987}). Both strategies do, nevertheless, degrade the accuracy of the calculation from second to first order. The leapfrog scheme associated to a Robert-Asselin 
+time filter has been preferred to other time differencing schemes such as 
+predictor corrector or trapezoidal schemes because the user can better 
+control the magnitude and the spatial structure of the time diffusion of the 
+scheme. In association with the centred space discretisation of the 
+advective terms in the momentum and tracer equations, it avoids implicit 
+numerical diffusion in both the time and space discretisation of the 
+advective term: they are both set explicitly by the user through the Robert-Asselin filter parameter and the viscous and diffusive coefficients.
+
+%gm - reflexion about leapfrog: ongoing work with Matthieu Leclair
+% to be updated latter with addition of new time stepping strategy
+\amtcomment{
+\colorbox{yellow}{Note}: 
+1- There is no reason why one should apply a same value of $\gamma$ on both momentum and tracer equations. In climate applications, one could found useful to use a lower value on tracer (quantity that one wants to conserve) than on the dynamics. We never explore this possibility.
+The Robert-Asselin time filter slightly departs from a simple second order time diffusive operator computed with a forward time stepping due to the presence of $x_f^{t-\Delta t}$ in the right hand side of  \ref{Eq_DOM_nxt_asselin}. The original willing of Robert1966 and Asselin1972 was to design a time filter that allow much larger parameter than 0.5.   is due to computer saving consideration. In the original asselin filter, $x^{t-\Delta t}$ is used instead:
+ \begin{equation} \label{Eq_DOM_nxt_asselin_true}
+x_f^t  = x^t + \gamma \, \left[ x^{t-\Delta t} - 2 x^t + x^{t+\Delta t} \right]
+\end{equation} 
+Applying a "true" Asselin time filter is nothing more than adding a harmonic diffusive operator in time. Indeed, equations \ref{Eq_DOM_nxt} and \ref{Eq_DOM_nxt_asselin_true} can be rewritten together as:
+\begin{equation} \label{Eq_DOM_nxt2}
+\begin{split}
+  \frac{ x^{t+\Delta t} - x^{t-\Delta t} } { 2 \,\Delta t } 
+  &=  \text{RHS}_x^{t-\Delta t,t,t+\Delta t} + \frac{ x_f^t  - x^t }{2 \,\Delta t} \\
+  &=  \text{RHS}_x^{t-\Delta t,t,t+\Delta t} + \gamma\ \frac{  \, \left[ x^{t-\Delta t} - 2 x^t + x^{t+\Delta t} \right] }{2 \,\Delta t}  \\
+  &=  \text{RHS}_x^{t-\Delta t,t,t+\Delta t} 
+  + 2 \Delta t \ \gamma \ \frac{1}{{2 \Delta t}^2}  
+  	\,\delta_{t-1}\,\left[ \delta_{t+1/2}\left[ x^t \right] \right] 
+  \end{split}
+\end{equation} 
+expressing this again in a continuous form, one finds that the Asselin filter leads to :
+\begin{equation} \label{Eq_DOM_nxt3}
+  \frac{ \partial x} { \partial t } =  \text{RHS} + 2 \,\Delta t \ \gamma \ \frac{ {\partial}^2 x}{ \partial t ^2 }
+\end{equation} 
+
+Equations  \ref{Eq_DOM_nxt2} and \ref{Eq_DOM_nxt3} suggest several remarks. First the Asselin filter is definitively a second order time diffusive operator which is evaluated at centered time step. The magnitude of this diffusion is proportional to the time step (with $\gamma$ usually taken between $10^{-1}$ to $10^{-3}$). Second, this term have to be taken into account in all budget of the equations (mass, heat content, salt content, kinetic energy...). Nevertheless, we stress here that it is small and does not systematic biases. Indeed let evaluates how it contributes to time evolution of $x$ between $t_o$ and $t_1$:
+\begin{equation} \label{Eq_DOM_nxt4}
+\begin{split}
+ t_1-t_o &= \int_{t_o}^{t_1} \frac{ \partial x} { \partial t } dt \\
+ 		&= \int_{t_o}^{t_1} \text{RHS} dt + 2 \,\Delta t \ \gamma \left(
+		  \left. \frac{ \partial x}{ \partial t } \right|_1 
+		- \left. \frac{ \partial x}{ \partial t } \right|_o  \right)
+ \end{split}
+\end{equation} 
+}
+
+Alternative time stepping schemes are currently under investigation.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Diffusive Part---Forward or Backward Scheme
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Diffusive Part --- Forward or Backward Scheme}
+\label{DOM_nxt_forward_imp}
+
+The leapfrog differencing is unsuitable for the representation of diffusive 
+and damping processes. For $D$, a horizontal diffusive terms and/or the 
+restoring terms to a tracer climatology (when they are present, see 
+\S~\ref{TRA_dmp}), a forward time differencing scheme is used :
+\begin{equation} \label{Eq_DOM_nxt_euler}
+   x^{t+\Delta t} = x^{t-\Delta t} + 2 \, \Delta t \  \text{RHS}_x^{t-\Delta t}
+\end{equation} 
+
+This is diffusive in time and conditionally stable. For example, the 
+condition of stability for a second and fourth order horizontal diffusions are \citep{Griffies2004}:
+\begin{equation} \label{Eq_DOM_nxt_euler_stability}
+A^h < \left\{
+\begin{aligned}
+                    &\frac{e^2}{  8 \; \Delta t } 	&&\quad \text{laplacian diffusion} 	\\
+                    &\frac{e^4}{64 \; \Delta t } 	&&\quad \text{bilaplacian diffusion} 
+            \end{aligned}
+\right.
+\end{equation}
+where $e$ is the smallest grid size in the two horizontal direction and $A^h$ the mixing coefficient. The linear constraint \eqref{Eq_DOM_nxt_euler_stability} is a necessary condition, but not sufficient. If it is not satisfied, even mildly, then the model soon becomes wildly unstable. The instability can be removed by either reducing the time steps or reducing the mixing coefficient.
+
+For the vertical diffusion terms, a forward time differencing scheme can be 
+used, but usually the numerical stability condition implies a strong 
+constraint on the time step. Two solutions are available in OPA to overcome 
+the stability constraint: $(a)$ a forward time differencing scheme using a 
+time splitting technique (\np{ln\_zdfexp}=T) or $(b)$ a backward (or implicit) 
+time differencing scheme by \np{ln\_zdfexp}=F). In $(a)$, the master 
+time step $\Delta $t is cut into $N$ fractional time steps so that the 
+stability criterion is reduced by a factor of $N$. The computation is done as 
+follows:
+\begin{equation} \label{Eq_DOM_nxt_ts}
+\begin{split}
+& u_\ast ^{t-\Delta t} = u^{t-\Delta t}   \\
+& u_\ast ^{t-\Delta t+L\frac{2\Delta t}{N}}=u_\ast ^{t-\Delta t+\left( {L-1} 
+\right)\frac{2\Delta t}{N}}+\frac{2\Delta t}{N}\;\text{DF}^{t-\Delta t+\left( {L-1} \right)\frac{2\Delta t}{N}}
+        \quad \text{for $L=1$ to $N$}      \\
+& u^{t+\Delta t} = u_\ast^{t+\Delta t}
+\end{split}
+\end{equation}
+with DF a vertical diffusion term. The number of fractional time steps, $N$, is given by setting \np{n\_zdfexp}, (namelist parameter). The scheme $(b)$ is unconditionally stable but diffusive. It can be written as follows:
+\begin{equation} \label{Eq_DOM_nxt_imp}
+   x^{t+\Delta t} = x^{t-\Delta t} + 2 \, \Delta t \  \text{RHS}_x^{t+\Delta t}
+\end{equation} 
+
+This scheme is rather time consuming since it requires a matrix inversion, 
+but it becomes attractive since a splitting factor of 3 or more is needed 
+for the forward time differencing scheme. For example, the finite difference 
+approximation of the temperature equation is:
+\begin{equation} \label{Eq_DOM_nxt_imp_zdf}
+\frac{T(k)^{t+1}-T(k)^{t-1}}{2\;\Delta t}\equiv \text{RHS}+\frac{1}{e_{3T} }\delta 
+_k \left[ {\frac{A_w^{vT} }{e_{3w} }\delta _{k+1/2} \left[ {T^{t+1}} \right]} 
+\right]
+\end{equation}
+where RHS is the right hand side of the equation except the vertical diffusion term. We rewrite \eqref{Eq_DOM_nxt_imp} as:
+\begin{equation} \label{Eq_DOM_nxt_imp_mat}
+-c(k+1)\;u^{t+1}(k+1)+d(k)\;u^{t+1}(k)-\;c(k)\;u^{t+1}(k-1) \equiv b(k)
+\end{equation}
+where 
+\begin{align*} 
+ c(k) &= A_w^{vm} (k) \, / \, e_{3uw} (k)     \\
+ d(k) &= e_{3u} (k)       \, / \, (2\Delta t) + c_k + c_{k+1}    \\
+ b(k) &= e_{3u} (k) \; \left( u^{t-1}(k) \, / \, (2\Delta t) + \text{RHS} \right)    
+\end{align*}
+
+\eqref{Eq_DOM_nxt_imp_mat} is a linear system of equations. All the elements of the corresponding matrix vanish except those on the diagonals. Moreover, $c(k)$ and $d(k)$ are positive and the diagonal term is greater than the sum of the 
+two extra-diagonal terms, therefore a special adaptation of the Gauss elimination procedure is used to find the solution (see for example \citet{Richtmyer1967}).
+
+% -------------------------------------------------------------------------------------------------------------
+%        Start/Restart strategy
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Start/Restart strategy}
+\label{DOM_nxt_rst}
+%--------------------------------------------namrun-------------------------------------------
+\namdisplay{namrun}         
+%--------------------------------------------------------------------------------------------------------------
+The first time step of this three level scheme when starting from initial conditions is a forward step (Euler time integration): $x^1 = x^0 + \Delta t \ \text{RHS}^0$.
+
+It is also possible to restart from a previous computation, by using a 
+restart file. The restart strategy is designed to ensure perfect 
+restartability of the code: the user should obtain the same results to 
+machine precision either by running the model for $2N$ time steps in one go, 
+or by performing two consecutive experiments of $N$ steps with a restart. This 
+requires saving two time levels and many auxiliary data in the restart files 
+in double precision. 
+
+
+%-------------------------------------------------------------------------------------------------------------
+%        Time Domain
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Time domain}
+\label{DOM_nxt_time}
+
+ \colorbox{yellow}{add here a few word on nit000 and nitend}
+
+ \colorbox{yellow}{Write documentation on the calendar and the key variable adatrj}
+
+
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DYN.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DYN.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_DYN.tex	(revision 4536)
@@ -0,0 +1,831 @@
+% ================================================================
+% Chapter Ñ Ocean Dynamics (DYN)
+% ================================================================
+\chapter{Ocean Dynamics (DYN)}
+\label{DYN}
+\minitoc
+
+% add a figure for  dynvor ens, ene latices
+
+
+$\ $\newline      %force an empty line
+
+Using the representation described in Chap.~\ref{DOM}, several semi-discrete space forms of the dynamical equations are available depending on the vertical coordinate used and on the conservative properties of the vorticity term. In all the equations presented here, the masking has been omitted for simplicity. One must be aware that all the quantities are masked fields and that each time a mean or difference operator is used, the resulting field is multiplied by a mask.
+
+The prognostic ocean dynamics equation can be summarized as follows:
+\begin{equation*}
+\text{NXT} = \dbinom	{\text{VOR} + \text{KEG} + \text {ZAD} }
+						{\text{COR} + \text{ADV}                       }
+			+ \text{HPG} + \text{SPG} + \text{LDF} + \text{ZDF}
+\end{equation*}
+
+NXT stands for next, referring to the time-stepping. The first group of terms on the rhs of the momentum equations corresponds to the Coriolis and advection terms that are decomposed in a vorticity part (VOR), a kinetic energy part (KEG) and the vertical advection (ZAD) in the vector invariant formulation, and into Coriolis and advection (COR+ADV) in the flux formulation. The following terms are the pressure gradient contributions (HPG, Hydrostatic Pressure Gradient, and SPG, Surface Pressure Gradient). Contributions from lateral diffusion and vertical diffusion are added to the rhs in the \mdl{dynldf} and \mdl{dynzdf} modules; the latter includes the surface and bottom stresses. The external forcings and parameterisations require complex inputs (surface wind stress calculation using bulk formulae, estimation of mixing coefficients) that are carried out in modules of the SBC, LDF and ZDF categories and described in Chapters \ref{SBC}, \ref{LDF} and \ref{ZDF}, respectively. 
+
+In the present chapter we also describe the diagnostic equations used to compute the horizontal divergence and curl of the velocities (\emph{divcur} module) as well as the vertical velocity (\emph{wzvmod} module).
+
+The different options available to the user are managed by namelist variables. For equation term \textit{ttt}, the logical namelist variables are \textit{ln\_dynttt\_xxx}, where \textit{xxx} is a 3 or 4 letter acronym accounting for each optional scheme. If a CPP key is used for this term its name is \textbf{key\_ttt}. The corresponding code can be found in the \textit{dynttt\_xxx} module, in the DYN directory, and it is usually computed in the \textit{dyn\_ttt\_xxx} subroutine.
+
+The user has the option of extracting each tendency term on the rhs of the 3D momentum equation (\key{trddyn} defined) and of the 2D barotropic vorticity balance (\key{trdvor} defined), as described in Chap.~\ref{MISC}.
+
+% ================================================================
+% Coriolis and Advection terms: vector invariant form
+% ================================================================
+\section{Coriolis and Advection: vector invariant form}
+\label{DYN_adv_cor_vect}
+%-----------------------------------------nam_dynadv----------------------------------------------------
+\namdisplay{nam_dynadv} 
+%-------------------------------------------------------------------------------------------------------------
+
+The vector invariant form of the momentum equations is the most often used in applications of the ocean model. The flux form option (next section) has been introduced recently in version $2$ of NEMO. Coriolis and momentum 
+advection terms are evaluated using a leapfrog scheme, i.e. the velocity appearing in their expressions is centred in time (\textit{now} velocity). At the lateral boundaries either free slip, no slip or partial slip boundary conditions are applied following Chap.~\ref{LBC}.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Vorticity term 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Vorticity term (\mdl{dynvor})}
+\label{DYN_vor}
+%------------------------------------------nam_dynvor----------------------------------------------------
+\namdisplay{nam_dynvor} 
+%-------------------------------------------------------------------------------------------------------------
+
+Different discretisations of the vorticity term (selected by the \textit{ln\_dynvor\_xxx} namelist variable to true) are available, that conserve potential enstrophy of horizontally non-divergent flow, horizontal kinetic energy, or potential enstrophy for the relative vorticity term and horizontal kinetic energy for the planetary vorticity term (see  \colorbox{yellow} { appendix C } ). The vorticity terms are given below for the general case ($s$-coordinate or partial step topography), but note that in full step $z$-coordinate (\key{zco} defined), $e_{3u} =e_{3v} =e_{3f}$ so that the vertical scale factors disappear.
+
+%-------------------------------------------------------------
+%                 enstrophy conserving scheme
+%-------------------------------------------------------------
+\subsubsection{enstrophy conserving scheme (\np{ln\_dynvor\_ens}=T)}
+\label{DYN_vor_ens}
+
+In this case, the discrete formulation of the vorticity term provides a global conservation of the enstrophy ($ [ (\zeta +f ) / e_{3f} ]^2 $ in $s$-coordinates) for a horizontally non-divergent flow (i.e. $\chi=0$), but does not conserve of the total kinetic energy. It is given by:
+
+\begin{equation} \label{Eq_dynvor_ens}
+\left\{ 
+\begin{aligned}
+{-\frac{1}{e_{1u} } } & {\overline {\left( { \frac{\zeta +f}{e_{3f} }} \right)} }^{\,i} & {\overline{\overline {\left( {e_{1v} e_{3v} v} \right)}} }^{\,i, j+1/2}    \\
+{+\frac{1}{e_{2v} } } & {\overline {\left( {\frac{\zeta +f}{e_{3f} }} \right)} }^{\,j}  & {\overline{\overline {\left( {e_{2u} e_{3u} u} \right)}} }^{\,i+1/2, j}  
+\end{aligned} 
+ \right.
+\end{equation} 
+
+%-------------------------------------------------------------
+%                 energy conserving scheme
+%-------------------------------------------------------------
+\subsubsection{energy conserving scheme (\np{ln\_dynvor\_ene}=T)}
+\label{DYN_vor_ene}
+
+The kinetic energy conserving scheme conserves the global kinetic energy but 
+not the global enstrophy. It is given by:
+\begin{equation} \label{Eq_dynvor_ene}
+\left\{ {
+\begin{aligned}
+{-\frac{1}{e_{1u} }\; {\overline {\left( {\frac{\zeta +f}{e_{3f} }} \right)
+\;\overline {\left( {e_{1v} e_{3v} v} \right)} ^{\,i+1/2}} }^{\,j} }    \\
+{+\frac{1}{e_{2v} }\; {\overline {\left( {\frac{\zeta +f}{e_{3f} }} \right)
+\;\overline {\left( {e_{2u} e_{3u} u} \right)} ^{\,j+1/2}} }^{\,i} }
+\end{aligned} 
+} \right.
+\end{equation} 
+
+%-------------------------------------------------------------
+%                 mix energy/enstrophy conserving scheme
+%-------------------------------------------------------------
+\subsubsection{mixed energy/enstrophy conserving scheme (\np{ln\_dynvor\_mix}=T) }
+\label{DYN_vor_mix}
+
+In this case, a mixture of the two previous schemes is used. It consists of the enstrophy conserving scheme (\ref{Eq_dynvor_ens}) applied to the relative vorticity term and of the horizontal kinetic energy conserving scheme (\ref{Eq_dynvor_ene}) applied to the planetary vorticity term.
+\begin{equation} \label{Eq_dynvor_mix}
+\left\{ {
+\begin{aligned}
+ {-\frac{1}{e_{1u} }\; {\overline {\left( {\frac{\zeta }{e_{3f} }} \right)} }^{\,i} 
+ \; {\overline{\overline {\left( {e_{1v} \; e_{3v} \ v} \right)}} }^{\,i,j+1/2} -\frac{1}{e_{1u} }
+ \; {\overline {\left( {\frac{f}{e_{3f} }} \right) 
+ \;\overline {\left( {e_{1v} \; e_{3v} \ v} \right)} ^{\,i+1/2}} }^{\,j} } \\
+{+\frac{1}{e_{2v} }\; {\overline {\left( {\frac{\zeta }{e_{3f} }} \right)} }^j
+ \; {\overline{\overline {\left( {e_{2u} \; e_{3u} \ u} \right)}} }^{\,i+1/2,j} +\frac{1}{e_{2v} }
+ \; {\overline {\left( {\frac{f}{e_{3f} }} \right)
+ \;\overline {\left( {e_{2u}\; e_{3u} \ u} \right)} ^{\,j+1/2}} }^{\,i} } \hfill
+\end{aligned} 
+} \right.
+\end{equation} 
+
+%-------------------------------------------------------------
+%                 energy and enstrophy conserving scheme
+%-------------------------------------------------------------
+\subsubsection{energy and enstrophy conserving scheme (\np{ln\_dynvor\_een}=T) }
+\label{DYN_vor_een}
+
+In this case, the vorticity term is evaluated using the vorticity advection scheme of \citet{Arakawa1990}. This scheme conserves both total energy and potential enstrophy in the limit of horizontally nondivergent flow (i.e. $\chi$=0), While this scheme is more complicated that the vorticity advection scheme of \citet{Sadourny1975} and does not conserve potential enstrophy and total energy in general flow, as does a scheme from \citet{Arakawa1981}, it tolerates arbitrarily thin layers. This feature is essential for simulating either outcropping isopycnals or large amplitude topography. 
+
+The \citet{Arakawa1990} vorticity advection scheme for a single layer is modified for spherical coordinates as described by \citet{Arakawa1981}. 
+
+The potential vorticity, defined at $f$-point, is: 
+\begin{equation} \label{Eq_pot_vor}
+q_f  = \frac{\zeta +f} {e_{3f} }
+\end{equation}
+where the relative vorticity is defined by (\ref{Eq_divcur_cur}), the Coriolis parameter is given by $f=2 \,\Omega \;\sin \varphi _f $ and the layer thickness at $F$-points is: 
+\begin{equation} \label{Eq_een_e3f}
+e_{3f} = \overline{\overline {e_{3t} }} ^{\,i+1/2,j+1/2}
+\end{equation}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_DYN_een_triad}
+\begin{center}
+\includegraphics[width=0.70\textwidth]{./Figures/Fig_DYN_een_triad.pdf}
+\caption{Triads used in the energy and enstrophy conserving scheme (een) for u-component (upper panel) and v-component (lower panel).}
+\end{center}
+\end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+Note that a key point in \eqref{Eq_een_e3f} is that the averaging in \textbf{i}- and \textbf{j}- directions uses the masked vertical scale factor but is always divided by $4$, not by the sum of the mask at $T$-point. This preserves the continuity of $e_{3f}$ when one or more of the neighbouring $e_{3T}$ tends to zero and extends by continuity the value of $e_{3f}$ in the land areas. 
+
+The vorticity terms are represented as: 
+\begin{equation} \label{Eq_dynvor_een}
+\left\{ {
+\begin{aligned}
+ +q\,e_3 \, v 	&\equiv +\frac{1}{e_{1u} }  \left[ 
+{{\begin{array}{*{20}c}
+    	{\,\ \ a_{j+1/2}^{i   } \left( {e_{1v} e_{3v} \ v} \right)_{j+1}^{i+1/2} } 
+  	{\,+\,b_{j+1/2}^{i   } \left( {e_{1v} e_{3v} \ v} \right)_{j+1}^{i-1/2}  } \\
+ \\
+     {  +\,c_{j-1/2}^{i   }  \left( {e_{1v} e_{3v} \ v} \right)_{j    }^{i+1/2}         } 
+ 	{\,+\,d_{j+1/2}^{i   } \left( {e_{1v} e_{3v} \ v} \right)_{j+1}^{i+1/2} } \\
+\end{array} }} \right] \\ 
+\\
+-q\,e_3 \,u  		&\equiv -\frac{1}{e_{2v} }  \left[ 
+{{\begin{array}{*{20}c}
+ 	{\,\ \ a_{j-1/2}^{i   }  \left( {e_{2u} e_{3v} \ u} \right)_{j+1}^{i+1/2} } 
+  	{\,+\,b_{j-1/2}^{i+1}  \left( {e_{2u} e_{3v} \ u} \right)_{j+1/2}^{i+1} } \\
+ \\
+     	{  +\,c_{j+1/2}^{i+1} \left( {e_{2u} e_{3v} \ u} \right)_{j+1/2}^{i+1} } 
+  	{\,+\,d_{j+1/2}^{i   }  \left( {e_{2u} e_{3v} \ u} \right)_{j+1/2}^{i   } } \\
+\end{array} }} \right]
+\end{aligned} 
+} \right.
+\end{equation} 
+where $a$, $b$, $c$ and $d$ are triad combinations of the neighbouring potential vorticities (Fig. \ref{Fig_DYN_een_triad}): 
+\begin{equation} \label{Eq_een_triads}
+\left\{ 
+\begin{aligned}
+ a_{\,j+1/2}^i & = \frac{1}  {12} \left( q_{j+1/2}^{i+1} + q_{j+1 /2}^i + q_{j-1/2}^i  \right)    \\ 
+ \\
+ b_{\,j+1/2}^i & = \frac{1}  {12} \left( q_{j+1/2}^{i-1} +q_{j+1/2}^i +q_{j-1/2}^i   \right)     \\ 
+\\
+ c_{\,j+1/2}^i & = \frac{1}  {12} \left( q_{j-1/2}^{i-1} +q_{j+1/2}^i +q_{j-1/2}^i   \right)     \\ 
+\\
+ d_{\,j+1/2}^i & = \frac{1}  {12} \left( q_{j-1/2}^{i+1} +q_{j+1/2}^i +q_{j-1/2}^i  \right)     \\ 
+\end{aligned} 
+\right.
+\end{equation}
+
+%--------------------------------------------------------------------------------------------------------------
+%           Kinetic Energy Gradient term
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Kinetic Energy Gradient term (\mdl{dynkeg})}
+\label{DYN_keg}
+
+There is a single discrete formulation of the kinetic energy gradient term, that conserves the total kinetic energy together with the formulation chosen for the vertical advection (see below). 
+\begin{equation} \label{Eq_dynkeg}
+\left\{ \begin{aligned}
+ -\frac{1}{2 \; e_{1u} } 
+ & \ \delta _{i+1/2} \left[ {\overline {u^2}^{\,i} + \overline{v^2}^{\,j}} \right]   \\
+ -\frac{1}{2 \; e_{2v} } 
+ & \ \delta _{j+1/2} \left[ {\overline {u^2}^{\,i} + \overline{v^2}^{\,j}} \right]    
+\end{aligned} \right.
+\end{equation} 
+
+%--------------------------------------------------------------------------------------------------------------
+%           Vertical advection term
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Vertical advection term (\mdl{dynzad}) }
+\label{DYN_zad}
+
+The discrete formulation of the vertical advection term conserves the total kinetic energy together with the formulation chosen for the gradient of kinetic energy (KE). Indeed, the change of KE due to the vertical advection is exactly balanced by the change of KE due to the gradient of KE (see \colorbox{yellow}{Annexe C}).
+\begin{equation} \label{Eq_dynzad}
+\left\{ 		\begin{aligned}
+ -\frac{1}  { e_{1u}\,e_{2u}\,e_{3u} }  &  
+  \ {\overline {\overline{ e_{1T}\,e_{2T}\,w } ^{\,i+1/2}  \;\delta _{k+1/2} \left[ u \right]  }^{\,k}   } \\
+ -\frac{1}  { e_{1v}\,e_{2v}\,e_{3v} }  &
+  \ {\overline {\overline{ e_{1T}\,e_{2T}\,w } ^{\,j+1/2}  \;\delta _{k+1/2} \left[ u \right]  }^{\,k}   }
+\end{aligned} \right.
+\end{equation} 
+
+% ================================================================
+% Coriolis and Advection : flux form
+% ================================================================
+\section{Coriolis and Advection: flux form}
+\label{DYN_adv_cor_flux}
+%------------------------------------------nam_dynadv----------------------------------------------------
+\namdisplay{nam_dynadv} 
+%-------------------------------------------------------------------------------------------------------------
+
+In the flux form (as in the vector invariant form), the Coriolis and momentum advection terms are evaluated using a leapfrog scheme, $i.e.$ the velocity appearing in their expressions is centred in time (\textit{now} velocity). At the lateral boundaries either free slip, no slip or partial slip boundary conditions are applied following Chap.~\ref{LBC}.
+
+
+%--------------------------------------------------------------------------------------------------------------
+%           Coriolis plus curvature metric terms
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Coriolis plus curvature metric terms (\mdl{dynvor}) }
+\label{DYN_cor_flux}
+
+In flux form, the vorticity term reduces to a Coriolis term in which the Coriolis parameter has been modified to account for the "metric" term. This altered Coriolis parameter is thus discretised at $F$-points. It is given by: 
+\begin{multline} \label{Eq_dyncor_metric}
+f+\frac{1}{e_1 e_2 }\left( {v\frac{\partial e_2 }{\partial i}  -  u\frac{\partial e_1 }{\partial j}} \right)  \\
+   \equiv   f + \frac{1}{e_{1f} e_{2f} } 
+	\left( { \ \overline v ^{i+1/2}\delta _{i+1/2} \left[ {e_{2u} } \right]  
+	         -  \overline u ^{j+1/2}\delta _{j+1/2} \left[ {e_{1u} } \right]  }  \ \right)
+\end{multline} 
+
+Any of the (\ref{Eq_dynvor_ens}), (\ref{Eq_dynvor_ene}) and (\ref{Eq_dynvor_een}) schemes can be used to compute the product of the Coriolis parameter and the vorticity. However, the energy-conserving scheme  (\ref{Eq_dynvor_een}) has exclusively been used to date. This term is evaluated using a leapfrog scheme, i.e. the velocity is centred in time (\textit{now} velocity).
+
+%--------------------------------------------------------------------------------------------------------------
+%           Flux form Advection term
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Flux form Advection term (\mdl{dynadv}) }
+\label{DYN_adv_flux}
+
+The discrete expression of the advection term is given by :
+\begin{equation} \label{Eq_dynadv}
+\left\{ 
+\begin{aligned}
+\frac{1}{e_{1u}\,e_{2u}\,e_{3u}} 
+\left(      \delta _{i+1/2} \left[ \overline{e_{2u}\,e_{3u}\ u }^{i       }  \ u_T      \right]    
+          + \delta _{j       } \left[ \overline{e_{1u}\,e_{3u}\ v }^{i+1/2}  \ u_F      \right] \right.  \ \;   \\
+\left.   + \delta _{k      } \left[ \overline{e_{1w}\,e_{2w} w}^{i+1/2}  \ u_{uw} \right] \right)   \\
+\\
+\frac{1}{e_{1v}\,e_{2v}\,e_{3v}} 
+\left( 	\delta _{i      } \left[  \overline{e_{2u}\,e_{3u } \ u }^{j+1/2} \ v_F       \right] 
+         + \delta _{j+1/2} \left[ \overline{e_{1u}\,e_{3u } \ v }^{i       } \ v_T       \right] \right.  \ \, \\
+\left.  + \delta _{k     } \left[  \overline{e_{1w}\,e_{2w} \ w}^{j+1/2} \ v_{vw}  \right] \right) \\
+\end{aligned}
+\right.
+\end{equation}
+
+Two advection schemes ($2^{nd}$ order centered finite difference scheme, CEN2, or a $3^{rd}$ order upstream biased scheme, UBS). The latter is described in \citet{Sacha2005}. The schemes are selected using the namelist variable \textit{ln\_dynadv\_xxx} In flux form, the advection schemes differ by the choice of a space and time interpolation to define the value of $u$ and $v$ at the centre of each face of $u$- and $v$-cells, i.e. at the $T$-, $f$-, and $uw$-points and $f$-, $T$- and $vw$-points for $u$ and $v$, respectively. 
+
+%-------------------------------------------------------------
+%                 2nd order centred scheme
+%-------------------------------------------------------------
+\subsubsection{$2^{nd}$ order centred scheme (cen2) (\np{ln\_dynadv\_cen2}=T)}
+\label{DYN_adv_cen2}
+
+In the centered $2^{nd}$ order formulation, the velocity is evaluated as the 
+mean of the two neighbouring points :
+\begin{equation} \label{Eq_dynadv_cen2}
+\left\{ 		\begin{aligned}
+ u_T^{cen2} &=\overline u^{i }		\quad & 	
+ u_F^{cen2} &=\overline u^{j+1/2}		\quad &
+ u_{uw}^{cen2} &=\overline u^{k+1/2}      \\
+ v_F^{cen2} &=\overline v ^{i+1/2}		\quad &
+ v_F^{cen2} &=\overline v^j		\quad &
+ v_{vw}^{cen2} &=\overline v ^{k+1/2}      \\
+\end{aligned} \right.
+\end{equation} 
+
+The scheme is non diffusive (i.e. conserves the kinetic energy) but dispersive (i.e. it may create false extrema). It is therefore notoriously noisy and must be used in conjunction with an explicit diffusion operator to produce a sensible solution. The associated time-stepping is performed using a leapfrog scheme in conjunction with an Asselin time-filter, so $u$ and $v$ are the \emph{now} velocities.
+
+%-------------------------------------------------------------
+%                 UBS scheme
+%-------------------------------------------------------------
+\subsubsection{Upstream Biased Scheme (UBS) (\np{ln\_dynadv\_ubs}=T)}
+\label{DYN_adv_ubs}
+
+The UBS advection scheme is an upstream biased third order scheme based on 
+an upstream-biased parabolic interpolation. For example, the evaluation of 
+$u_T^{ubs} $ is done as follows:
+\begin{equation} \label{Eq_dynadv_ubs}
+u_T^{ubs} =\overline u ^i-\;\frac{1}{6} 	\begin{cases}
+		u"_{i-1/2}& 	\text{if $\ \overline{e_{2u}\,e_{3u} \ u}^i  \geqslant 0$ } 	\\
+		u"_{i+1/2}& 	\text{if $\ \overline{e_{2u}\,e_{3u} \ u}^i  < 0$ }
+\end{cases}
+\end{equation}
+where $u"_{i+1/2} =\delta _{i+1/2} \left[ {\delta _i \left[ u \right]} \right]$. This results in a dissipatively dominant (i.e. hyper-diffusive) truncation error \citep{Sacha2005}. The overall performance of the advection scheme is similar to that reported in \citet{Farrow1995}. It is a relatively good compromise between accuracy and smoothness. It is not a \emph{positive} scheme, meaning that false extrema are permitted but their amplitude is significantly reduced over the centred second order method. 
+
+The UBS scheme is not used in all the direction. In the vertical, it has been preferred to keep the centred $2^{nd}$ order evaluation of the advection, i.e. $u_{uw}^{ubs}$ and $u_{vw}^{ubs}$ in (\ref{Eq_dynadv_cen2}) are used. Indeed, UBS is diffusive, it is associated with vertical mixing of momentum. Since vertical mixing of momentum is source term of the TKE equation{\ldots}
+
+For stability reasons, in (\ref{Eq_dynadv_ubs}), the first term which corresponds to a second order centred scheme is evaluated using the \textit{now} velocity (centred in time) while the second term which is the diffusive part of the scheme, is 
+evaluated using the \textit{before} velocity (forward in time). This is discussed by \citet{Webb1998} in the context of the Quick advection scheme.
+
+NB 1: UBS and Quadratic Upstream Interpolation for Convective Kinematics (QUICK) schemes only differ by one coefficient. Substituting $1/6$ with $1/8$ in (\ref{Eq_dynadv_ubs}) leads to the QUICK advection scheme \citep{Webb1998}. This option is not available through a namelist parameter, since the $1/6$ coefficient is hard coded. Nevertheless it is quite easy to make the substitution in \mdl{dynadv\_ubs} module and obtain a QUICK scheme.
+
+NB 2 : In the current version of \mdl{dynadv\_ubs}, there is also a possibility of using a $4^{th}$ order evaluation of the advective velocity as in ROMS. This is an error and should be suppressed soon.
+
+% ================================================================
+%           Hydrostatic pressure gradient term
+% ================================================================
+\section{Hydrostatic pressure gradient (\mdl{dynhpg})}
+\label{DYN_hpg}
+%------------------------------------------nam_dynhpg---------------------------------------------------
+\namdisplay{nam_dynhpg} 
+\namdisplay{namflg} 
+%-------------------------------------------------------------------------------------------------------------
+\colorbox{red} {Suppress the namflg namelist and incorporate it in the namhpg namelist}
+
+The key distinction between the different algorithms is the vertical coordinate used, since HPG is a horizontal pressure gradient, i.e. computed along geopotential surfaces. As a result, any tilt of the surface of the computational levels will require a specific treatment to compute the hydrostatic pressure gradient.
+
+The hydrostatic pressure gradient term is evaluated either using a leapfrog scheme, i.e. the density appearing in its expression is centred in time (\emph{now} velocity), or a semi-implcit scheme. At the lateral boundaries either free slip, no slip or partial slip boundary conditions are applied.
+
+%--------------------------------------------------------------------------------------------------------------
+%           z-coordinate with full step
+%--------------------------------------------------------------------------------------------------------------
+\subsection{\textit{z}-coordinate with full step (\np{ln\_dynhpg\_zco}=T)}
+\label{DYN_hpg_zco}
+
+The hydrostatic pressure can be obtained by integrating the hydrostatic equation vertically from the surface. Nevertheless, the pressure is quite large at great depth while its horizontal gradient is several orders of magnitude smaller. This may lead to large truncation error in the pressure gradient terms. Thus, the two horizontal components of the hydrostatic pressure gradient are computed directly as follows:
+
+for $k=km$ (surface layer, $jk=1$ in the code)
+\begin{equation} \label{Eq_dynhpg_zco_surf}
+\left\{ \begin{aligned}
+					\left. \delta _{i+1/2} \left[  p^h 			 \right] \right|_{k=km} 
+&= \frac{1}{2} g \ 	\left. \delta _{i+1/2} \left[  e_{3w} \ \rho \right] \right|_{k=km}   \\
+     					\left. \delta _{j+1/2} \left[  p^h  			 \right] \right|_{k=km} 
+&= \frac{1}{2} g \ 	\left. \delta _{j+1/2} \left[  e_{3w} \ \rho \right] \right|_{k=km}   \\
+\end{aligned} \right.
+\end{equation} 
+
+for $1<k<km$ (interior layer)
+\begin{equation} \label{Eq_dynhpg_zco}
+\left\{ \begin{aligned}
+					\left. \delta _{i+1/2} \left[  p^h 			 \right] \right|_{k} 
+&=					\left. \delta _{i+1/2} \left[  p^h 			 \right] \right|_{k-1} 
++    \frac{1}{2}\;g\;	\left. \delta _{i+1/2} \left[  e_{3w} \ \overline {\rho}^{k+1/2} \right] \right|_{k}   \\
+     					\left. \delta _{j+1/2} \left[  p^h  			 \right] \right|_{k} 
+&=     				\left. \delta _{j+1/2} \left[  p^h  			 \right] \right|_{k-1} 
++    \frac{1}{2}\;g\;	\left. \delta _{j+1/2} \left[  e_{3w} \ \overline {\rho}^{k+1/2} \right] \right|_{k}   \\
+\end{aligned} \right.
+\end{equation} 
+
+Note that the $1/2$ factor in (\ref{Eq_dynhpg_zco_surf}) is adequate because of the definition of $e_{3w}$ as the vertical derivative of the scale factor at the surface level ($z=0)$. 
+
+%--------------------------------------------------------------------------------------------------------------
+%           z-coordinate with partial step
+%--------------------------------------------------------------------------------------------------------------
+\subsection{\textit{z}-coordinate with partial step (\np{ln\_dynhpg\_zps}=T )}
+\label{DYN_hpg_zps}
+
+With partial bottom cells, tracers in horizontally adjacent cells generally live at different depths. Before taking horizontal gradients between these tracers, a linear interpolation is used to approximate the deeper tracer as if it actually lived at the depth of the shallower tracer point. 
+
+It is necessary to do so at the last ocean level; otherwise the horizontal hydrostatic pressure gradient evaluated in z-coordinate with partial step is exactly as in pure z-coordinate case. As explained in detail in section \S\ref{TRA_zpshde}, the nonlinearity of pressure effects in the equation of state is such that it is better to interpolate vertically temperature and salinity before computing the density. Horizontal gradients of and salinity are needed for the TRA modules, which is the reason why the horizontal gradients of density at the deepest model level are computed in module \mdl{zpsdhe} located in the TRA directory and described in \S\ref{TRA_zpshde}.
+
+%--------------------------------------------------------------------------------------------------------------
+%           s- and s-z-coordinates
+%--------------------------------------------------------------------------------------------------------------
+\subsection{\textit{s}- and \textit{s-z} coordinates}
+\label{DYN_hpg_sco}
+
+Pressure gradient formulations in $s$ coordinates have been the subject of a vast literature ($e.g.$, \citet{Song1998, Sacha2003}). A number of different pressure gradient options are coded, but they are not yet fully documented nor tested. 
+
+Traditional coding (see for example \citet{Madec1996}: (\np{ln\_dynhpg\_sco}, \np{ln\_dynhpg\_hel})
+\begin{equation} \label{Eq_dynhpg_sco}
+\left\{ \begin{aligned}
+ - \frac{1}    						{\rho_o \, e_{1u}} \;	\delta _{i+1/2} \left[  p^h  \right] 
++ \frac{g\; \overline {\rho}^{i+1/2}}	{\rho_o \, e_{1u}} \;	\delta _{i+1/2} \left[  z_T  \right]    \\
+ - \frac{1}    						{\rho_o \, e_{2v}} \;	\delta _{j+1/2} \left[  p^h  \right]  
++ \frac{g\; \overline {\rho}^{j+1/2}}	{\rho_o \, e_{2v}} \;	\delta _{j+1/2} \left[  z_T  \right]    \\
+\end{aligned} \right.
+\end{equation} 
+
+Where the first term is the pressure gradient along coordinates, computed as in (II.3.2), and $z_T$ is the depth of $T$-point evaluated from the sum of the vertical scale factor at W-point ($e_{3w})$. The version \np{ln\_dynhpg\_hel} has been added by Aike Beckmann and involves a redefinition of the relative position of $T$ points relative to $w$ points. 
+
+Weighted density Jacobian (wdj) \citep{Song1998} (\np{ln\_dynhpg\_wdj}=T)
+
+Density Jacobian with cubic polynomial scheme (djc) \citep{Sacha2003} (\np{ln\_dynhpg\_djc}=T)
+
+Rotated axes scheme (rot) \citep{Thiem2006} (\np{ln\_dynhpg\_rot}=T)
+
+Note that expression (\ref{Eq_dynhpg_sco}) is used when the variable volume formulation is activated (key\_vvl) because in that case, even with a flat bottom, the coordinate surface are not horizontal but follow the free surface \citep{Levier2007}. The other pressure gradient options are not yet available.
+
+%--------------------------------------------------------------------------------------------------------------
+%           Time-scheme
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Time-scheme (\np{ln\_dynhpg\_imp}=T/F)}
+\label{DYN_hpg_imp}
+
+The default time differencing scheme used for the horizontal pressure gradient is a leapfrog scheme and therefore the density used in all discrete expressions given above is the  \textit{now} density, computed from the \textit{now} temperature and salinity. In some specific cases (usually high resolution simulations over a ocean domain including weakly stratified regions) the physical phenomena that control the time-step are internal gravity waves (IGWs). A semi-implicit scheme for doubling the stability limit associated with IGWs can be used \citep{Brown1978, Maltrud1998}. It consists in evaluating the hydrostatic pressure gradient as an average over the three time levels $t-\Delta t$, $t$, and $t+\Delta t$ (i.e.  \textit{before},  \textit{now} and  \textit{after} time-steps), rather than at central time level $t$ only as in standard leapfrog scheme. 
+
+leapfrog scheme (\np{ln\_dynhpg\_imp}=F):
+
+\begin{equation} \label{Eq_dynhpg_lf}
+\frac{u^{t+\Delta t}-u^{t-\Delta t}}{2\Delta t}
+=\;\cdots \;-\frac{1}{\rho _o \,e_{1u} }\delta _{i+1/2} \left[ {p_h^t } \right]
+\end{equation}
+
+semi-implicit scheme (\np{ln\_dynhpg\_imp}=T):
+\begin{equation} \label{Eq_dynhpg_imp}
+\frac{u^{t+\Delta t}-u^{t-\Delta t}}{2\Delta t}
+=\;\cdots \;-\frac{1}{\rho _o \,e_{1u} } \delta _{i+1/2} \left[ \frac{ p_h^{t+\Delta t} +2p_h^t 
++p_h^{t-\Delta t} } { 4 }  \right]
+\end{equation}
+
+The semi-implicit time scheme (\ref{Eq_dynhpg_imp}) is made possible without significant additional computation as the density can be updated to time level $t+\Delta t$ before computing the horizontal hydrostatic pressure gradient. It can be easily shown that the Courant-Friedrichs-Lewy (CFL) limit associated to the hydrostatic pressure gradient double using (\ref{Eq_dynhpg_imp}) compared to the standard leapfrog scheme (\ref{Eq_dynhpg_lf}). Note that (\ref{Eq_dynhpg_imp}) is equivalent to applying a time filter to the pressure gradient to eliminate high frequency IGWs. Obviously, when using (\ref{Eq_dynhpg_imp}), the doubling of the time-step is achievable only if no other factors control the time-step, such as the CFL limits associated with advection or diffusion.
+
+In practice, the semi-implicit scheme is used when \np{ln\_dynhpg\_imp}=T.
+ In this case, we choose to apply the time filter to temperature and salinity used in the equation of state, instead of applying it to the hydrostatic pressure or to the density, so that no additional storage array has to be defined. The density used to compute the hydrostatic pressure gradient (whatever the formulation) is evaluated as follows:
+\begin{equation} \label{Eq_rho_flt}
+	\rho^t = \rho( \widetilde{T},\widetilde {S},z_T)
+ \quad	  \text{with}	\quad 
+	\widetilde{\bullet} = \frac{  \bullet^{t+\Delta t} +2 \,\bullet^t + \bullet^{t-\Delta t}  } {4}
+\end{equation}
+
+Note that in the semi-implicit case, it is necessary to save one extra three-dimentional field in the restart file to restart the model with exact reproducibility, namely, the filtered density. This option is controlled by the namelist parameter \np{nn\_dynhpg\_rst}.
+
+% ================================================================
+% Surface Pressure Gradient
+% ================================================================
+\section{Surface pressure gradient (\mdl{dynspg})}
+\label{DYN_hpg_spg}
+%-----------------------------------------nam_dynspg----------------------------------------------------
+\namdisplay{nam_dynspg} 
+%------------------------------------------------------------------------------------------------------------
+The surface pressure gradient term is related to the representation of the free surface (\S\ref{PE_hor_pg}). The main distinction is between the fixed volume case (linear free surface or rigid lid) and the variable volume case (nonlinear free surface, \key{vvl} is active). In the linear free surface case (\S\ref{PE_free_surface}) and rigid lid (\S\ref{PE_rigid_lid}), the vertical scale factors $e_{3}$ are fixed in time, while in the nonlinear case (\S\ref{PE_free_surface}) they are time-dependent. With both linear and nonlinear free surface, external gravity waves are allowed in the equations, which imposes a very small time step when an explicit time stepping is used. Two methods are proposed to allow a longer time step for the three-dimensional equations: the filtered free surface, which is a modification of the continuous equations (see \eqref{Eq_PE_flt}), and the split-explicit free surface described below. The extra term introduced in the filtered method is calculated implicitly, so that the update of the next velocities is done in module \mdl{dynspg\_flt} and not in \mdl{dynnxt}.
+
+%--------------------------------------------------------------------------------------------------------------
+% Linear free surface formulation
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Linear free surface formulation (\textbf{key\_exp} or \textbf{\_ts} or \textbf{\_flt})}
+\label{DYN_spg_linear}
+
+In the linear free surface formulation, the sea surface height is assumed to be small compared to the thickness of the ocean levels, so that $(a)$ the time evolution of the sea surface height becomes a linear equation, and $(b)$ the thickness of the ocean levels is assumed to be constant with time. As mentioned in (\S\ref{PE_free_surface}) the linearization affects the conservation of tracers. 
+
+%-------------------------------------------------------------
+% Explicit
+%-------------------------------------------------------------
+\subsubsection{Explicit (\key{dynspg\_exp})}
+\label{DYN_spg_exp}
+
+In the explicit free surface formulation, the model time step is chosen small enough to describe the external gravity waves (typically a few ten seconds). The sea surface height is given by :
+\begin{equation} \label{Eq_dynspg_ssh}
+\frac{\partial \eta }{\partial t}\equiv \frac{\text{EMP}}{\rho _w }+\frac{1}{e_{1T} 
+e_{2T} }\sum\limits_k {\left( {\delta _i \left[ {e_{2u} e_{3u} u} 
+\right]+\delta _j \left[ {e_{1v} e_{3v} v} \right]} \right)} 
+\end{equation}
+
+where EMP is the surface freshwater budget (evaporation minus precipitation, and minus river runoffs (if the later are introduced as a surface freshwater flux, see \S\ref{SBC}) expressed in $Kg.m^{-2}.s^{-1}$, and $\rho _w =1,000\,Kg.m^{-3}$ is the volumic mass of pure water. The sea-surface height is evaluated using a leapfrog scheme in combination with an Asselin time filter, i.e. the velocity appearing in (\ref{Eq_dynspg_ssh}) is centred in time (\textit{now} velocity). 
+
+The surface pressure gradient, also evaluated using a leap-frog scheme, is then simply given by :
+\begin{equation} \label{Eq_dynspg_exp}
+\left\{ \begin{aligned}
+ - \frac{1}    						{e_{1u}} \;	\delta _{i+1/2} \left[  \,\eta\,  \right] 	\\
+ \\
+ - \frac{1}    						{e_{2v}} \;	\delta _{j+1/2} \left[  \,\eta\,  \right]  
+\end{aligned} \right.
+\end{equation} 
+
+Consistent with the linearization, a $\left. \rho \right|_{k=1} / \rho _o$ factor is omitted in (\ref{Eq_dynspg_exp}). 
+
+%-------------------------------------------------------------
+% Split-explicit time-stepping
+%-------------------------------------------------------------
+\subsubsection{Split-explicit time-stepping (\key{dynspg\_ts})}
+\label{DYN_spg_ts}
+%--------------------------------------------namdom----------------------------------------------------
+\namdisplay{namdom} 
+%--------------------------------------------------------------------------------------------------------------
+The split-explicit free surface formulation used in OPA follows the one proposed by \citet{Griffies2004}. The general idea is to solve the free surface equation with a small time step, while the three dimensional prognostic variables are solved with a longer time step that is a multiple of \np{rdtbt} (Figure III.3). 
+
+%>   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >
+\begin{figure}[!t] \label{Fig_DYN_dynspg_ts}
+\begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_DYN_dynspg_ts.pdf}
+\caption{Schematic of the split-explicit time stepping scheme for the barotropic and baroclinic modes, after \citet{Griffies2004}. Time increases to the right. Baroclinic time steps are denoted by $t-\Delta t$, $t, t+\Delta t$, and $t+2\Delta t$. The curved line represents a leap-frog time step, and the smaller barotropic time steps $N \Delta t=2\Delta t$ are denoted by the zig-zag line. The vertically integrated forcing \textbf{M}(t) computed at baroclinic time step t represents the interaction between the barotropic and baroclinic motions. While keeping the total depth, tracer, and freshwater forcing fields fixed, a leap-frog integration carries the surface height and vertically integrated velocity from t to $t+2 \Delta t$ using N barotropic time steps of length $\Delta t$. Time averaging the barotropic fields over the N+1 time steps (endpoints included) centers the vertically integrated velocity at the baroclinic timestep $t+\Delta t$. A baroclinic leap-frog time step carries the surface height to $t+\Delta t$ using the convergence of the time averaged vertically integrated velocity taken from baroclinic time step t. }
+\end{center}
+\end{figure}
+%>   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >
+
+The split-explicit formulation has a damping effect on external gravity waves, which is weaker than the filtered free surface but still significant as shown by \citet{Levier2007} in the case of an analytical barotropic Kelvin wave. 
+
+%-------------------------------------------------------------
+% Filtered formulation 
+%-------------------------------------------------------------
+\subsubsection{Filtered formulation (\key{dynspg\_flt})}
+\label{DYN_spg_flt}
+
+The filtered formulation follows the \citet{Roullet2000} implementation. The extra term introduced in the equations (see {\S}I.2.2) is solved implicitly. The elliptic solvers available in the code are 
+documented in \S\ref{MISC}. The amplitude of the extra term is given by the namelist variable \np{rnu}. The default value is 1, as recommended by \citet{Roullet2000}
+
+\colorbox{red}{\np{rnu}=1 to be suppressed from namelist !}
+
+%-------------------------------------------------------------
+% Non-linear free surface formulation 
+%-------------------------------------------------------------
+\subsection{Non-linear free surface formulation (\key{vvl})}
+\label{DYN_spg_vvl}
+
+In the non-linear free surface formulation, the variations of volume are fully taken into account. This option is presented in a report \citep{Levier2007} available on the NEMO web site. The three time-stepping methods (explicit, split-explicit and filtered) are the same as in \S\ref{DYN_spg_linear} except that the ocean depth is now time-dependent. In particular, this means that in filtered case, the matrix to be inverted has to be recomputed at each time-step.
+
+%--------------------------------------------------------------------------------------------------------------
+%           Rigid-lid formulation
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Rigid-lid formulation (\key{dynspg\_rl})}
+\label{DYN_spg_rl}
+
+With the rigid lid formulation, an elliptic equation has to be solved for 
+the barotropic streamfunction. For consistency this equation is obtained by 
+taking the discrete curl of the discrete vertical sum of the discrete 
+momentum equation: 
+\begin{equation}\label{Eq_dynspg_rl}
+\frac{1}{\rho _o }\nabla _h p_s \equiv \left( {{\begin{array}{*{20}c}
+ {\overline M_u +\frac{1}{H\;e_2 } \delta_ j \left[ \partial_t \psi \right]}		 \\
+ \\
+ {\overline M_v -\frac{1}{H\;e_1 }  \delta_i  \left[ \partial_t \psi \right]} 		 \\
+\end{array} }} \right)
+\end{equation}
+
+Here ${\rm {\bf M}}= \left( M_u,M_v \right)$ represents the collected contributions of nonlinear, 
+viscous and hydrostatic pressure gradient terms in \eqref{Eq_PE_dyn} and the overbar indicates a vertical average over the whole water column (i.e. from $z=-H$, the ocean bottom, to $z=0$, the rigid-lid). The time derivative of $\psi$ is the solution of an elliptic equation:
+\begin{multline} \label{Eq_bsf}
+   \delta_{i+1/2} \left[ \frac{e_{2v}}{H_v\;e_{1v}} \delta_{i} \left[  \partial_t \psi \right] \right]
++ \delta_{j+1/2} \left[ \frac{e_{1u}}{H_u\;e_{2u}} \delta_{j} \left[  \partial_t \psi \right] \right]
+\\ =
+  \delta_{i+1/2} \left[ e_{2v} M_v  \right]
+- \delta_{j+1/2} \left[ e_{1u} M_u  \right]
+\end{multline}
+
+The elliptic solvers available in the code are documented in 
+\S\ref{MISC}). The boundary conditions must be given on all separate 
+landmasses (islands), which is done by integrating the vorticity equation 
+around each island. This requires identifying each island in the bathymetry 
+file, a cumbersome task. This explains why the rigid lid option is not 
+recommended with complex domains such as the global ocean. Parameters jpisl 
+(number of islands) and jpnisl (maximum number of points per island) of the 
+par\_oce.h90 file are related to this option.
+
+
+% ================================================================
+% Lateral diffusion term
+% ================================================================
+\section{Lateral diffusion term (\mdl{dynldf})}
+\label{DYN_ldf}
+%------------------------------------------nam_dynldf----------------------------------------------------
+\namdisplay{nam_dynldf} 
+%-------------------------------------------------------------------------------------------------------------
+The options available for lateral diffusion are laplacian (rotated or not) 
+or biharmonic operators. The coefficients may be constant or spatially 
+variable; the description of the coefficients is found in the chapter on lateral
+physics (Chap.~\ref{LDF}). The lateral diffusion of momentum is evaluated using a 
+forward scheme, i.e. the velocity appearing in its expression is the 
+\textit{before} velocity in time, except for the pure vertical component that appears when 
+a tensor of rotation is used. This latter term is solved implicitly together 
+with the vertical diffusion term (see \S\ref{DOM_nxt}) 
+
+At the lateral boundaries either free slip, no slip or partial slip boundary 
+conditions are applied following user's choice (see Chap. \S\ref{LBC}).
+
+% ================================================================
+\subsection{Iso-level laplacian operator (\np{ln\_dynldf\_lap}=T)}
+\label{DYN_ldf_lap}
+
+For lateral iso-level diffusion, the discrete operator is: 
+\begin{equation} \label{Eq_dynldf_lap}
+\left\{ \begin{aligned}
+ D_u^{l{\rm {\bf U}}} =\frac{1}{e_{1u} }\delta _{i+1/2} \left[ {A_T^{lm} 
+\;\chi } \right]-\frac{1}{e_{2u} {\kern 1pt}e_{3u} }\delta _j \left[ 
+{A_f^{lm} \;e_{3f} \zeta } \right] \\ 
+\\
+ D_v^{l{\rm {\bf U}}} =\frac{1}{e_{2v} }\delta _{j+1/2} \left[ {A_T^{lm} 
+\;\chi } \right]+\frac{1}{e_{1v} {\kern 1pt}e_{3v} }\delta _i \left[ 
+{A_f^{lm} \;e_{3f} \zeta } \right] \\ 
+\end{aligned} \right.
+\end{equation} 
+
+As explained in \S\ref{PE_ldf}, this formulation (as the gradient of a divergence 
+and curl of the vorticity) preserves symmetry and ensures a complete 
+separation between the vorticity and divergence parts. Note that in pure 
+z-coordinate (\key{zco} defined), $e_{3u} =e_{3v} =e_{3f}$ so that they disappear 
+from the rotational part of \eqref{Eq_dynldf_lap}.
+
+%--------------------------------------------------------------------------------------------------------------
+%           Rotated laplacian operator
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Rotated laplacian operator (\np{ln\_dynldf\_iso}=T)}
+\label{DYN_ldf_iso}
+
+A rotation of lateral momentum diffusive operator is needed for isoneutral 
+diffusion in $z$-coordinates (\np{ln\_dynldf\_iso}=T) and for either 
+isoneutral (\np{ln\_dynldf\_iso}=T) or geopotential 
+(\np{ln\_dynldf\_hor}=T) diffusion in $s$-coordinates. In the partial step 
+case, coordinates are horizontal excepted at the deepest level and no 
+rotation is performed when \np{ln\_dynldf\_hor}=T. The diffusive operator 
+is defined simply as the divergence of down gradient momentum fluxes on each 
+momentum components. It must be emphasized that this formulation ignores 
+constraints on the stress tensor such as symmetry. The resulting discrete 
+representation is:
+\begin{equation} \label{Eq_dyn_ldf_iso}
+\begin{split}
+ D_u^{l\textbf{U}} &= \frac{1}{e_{1u} \, e_{2u} \, e_{3u} }	\\
+&  \left\{\quad  {\delta _{i+1/2} \left[ {A_T^{lm}  \left( 
+	 {\frac{e_{2T} \; e_{3T} }{e_{1T} } \,\delta _{i}[u]
+	-e_{2T} \; r_{1T} \,\overline{\overline {\delta _{k+1/2}[u]}}^{\,i,\,k}}
+ \right)} \right]} 	\right.
+\\ 
+& \qquad +\ \delta_j \left[ {A_f^{lm} \left( {\frac{e_{1f}\,e_{3f} }{e_{2f} 
+}\,\delta _{j+1/2} [u] - e_{1f}\, r_{2f} 
+\,\overline{\overline {\delta _{k+1/2} [u]}} ^{\,j+1/2,\,k}} 
+\right)} \right] 
+\\ 
+&\qquad +\ \delta_k \left[ {A_{uw}^{lm} \left( {-e_{2u} \, r_{1uw} \,\overline{\overline 
+{\delta_{i+1/2} [u]}}^{\,i+1/2,\,k+1/2} } 
+\right.} \right. 
+\\ 
+&  \ \qquad \qquad \qquad \quad\ 
+- e_{1u} \, r_{2uw} \,\overline{\overline {\delta_{j+1/2} [u]}} ^{\,j,\,k+1/2}
+\\ 
+& \left. {\left. { \ \qquad \qquad \qquad \ \ \ \left. {\ 
++\frac{e_{1u}\, e_{2u} }{e_{3uw} }\,\left( {r_{1uw}^2+r_{2uw}^2} 
+\right)\,\delta_{k+1/2} [u]} \right)} \right]\;\;\;} \right\} 
+\\
+\\
+ D_v^{l\textbf{V}} &= \frac{1}{e_{1v} \, e_{2v} \, e_{3v} }    \\
+&  \left\{\quad  {\delta _{i+1/2} \left[ {A_f^{lm}  \left( 
+	 {\frac{e_{2f} \; e_{3f} }{e_{1f} } \,\delta _{i+1/2}[v]
+	-e_{2f} \; r_{1f} \,\overline{\overline {\delta _{k+1/2}[v]}}^{\,i+1/2,\,k}}
+ \right)} \right]} 	\right.
+\\ 
+& \qquad +\ \delta_j \left[ {A_T^{lm} \left( {\frac{e_{1T}\,e_{3T} }{e_{2T} 
+}\,\delta _{j} [v] - e_{1T}\, r_{2T} 
+\,\overline{\overline {\delta _{k+1/2} [v]}} ^{\,j,\,k}} 
+\right)} \right] 
+\\ 
+& \qquad +\ \delta_k \left[ {A_{vw}^{lm} \left( {-e_{2v} \, r_{1vw} \,\overline{\overline 
+{\delta_{i+1/2} [v]}}^{\,i+1/2,\,k+1/2} }\right.} \right. 
+\\
+&  \ \qquad \qquad \qquad \quad\ 
+- e_{1v} \, r_{2vw} \,\overline{\overline {\delta_{j+1/2} [v]}} ^{\,j+1/2,\,k+1/2}
+\\ 
+& \left. {\left. { \ \qquad \qquad \qquad \ \ \ \left. {\ 
++\frac{e_{1v}\, e_{2v} }{e_{3vw} }\,\left( {r_{1vw}^2+r_{2vw}^2} 
+\right)\,\delta_{k+1/2} [v]} \right)} \right]\;\;\;} \right\} 
+ \end{split}
+\end{equation}
+where $r_1$ and $r_2$ are the slopes 
+between the surface along which the diffusive operator acts and the surface 
+of computation ($z$- or $s$-surfaces). The way these slopes are evaluated is given 
+in lateral physics chapter (Chap.~\S\ref{LDF}).
+
+%--------------------------------------------------------------------------------------------------------------
+%           Iso-level bilaplacian operator
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Iso-level bilaplacian operator}
+\label{DYN_ldf_bilap}
+
+The lateral fourth order operator formulation on momentum is obtained by 
+applying \eqref{Eq_dynldf_lap} twice. It requires an additional assumption on boundary 
+conditions: the first derivative term normal to the coast depends on the 
+free or no-slip lateral boundary conditions chosen, while the third 
+derivative terms normal to the coast are set to zero (see Chap.~\ref{LBC}).
+
+\colorbox{yellow}{add a remark on the the change in the position of the coefficient}
+
+% ================================================================
+%           Vertical diffusion term
+% ================================================================
+\section{Vertical diffusion term (\mdl{dynzdf})}
+\label{DYN_zdf}
+%----------------------------------------------namzdf------------------------------------------------------
+\namdisplay{namzdf} 
+%-------------------------------------------------------------------------------------------------------------
+
+The large vertical diffusion coefficient found in the surface mixed layer, together with high vertical resolution, implies a too restrictive constraint on the time step in a pure explicit time stepping 
+case. Two time stepping schemes can be used for the vertical diffusion term : $(a)$ a forward time differencing scheme (\np{ln\_zdfexp}=T) using a time splitting technique (\np{n\_zdfexp} $>$ 1) or $(b)$ a backward (or implicit) time differencing scheme (\np{ln\_zdfexp}=F) (see \S\ref{DOM_nxt}). Note that namelist variables \np{ln\_zdfexp} and \np{n\_zdfexp} apply to both tracers and dynamics. 
+
+The formulation of the vertical subgrid scale physics is the same whatever 
+the vertical coordinate is. The vertical diffusive operators given by 
+\eqref{Eq_PE_zdf} take the following semi-discrete space form:
+\begin{equation} \label{Eq_dynzdf}
+\left\{   \begin{aligned}
+D_u^{vm} &\equiv \frac{1}{e_{3u}} \ \delta _k \left[ \frac{A_{uw}^{vm} }{e_{3uw} }
+                              \ \delta _{k+1/2} [\,u\,]         \right]     \\
+\\
+D_v^{vm} &\equiv \frac{1}{e_{3v}} \ \delta _k \left[ \frac{A_{vw}^{vm} }{e_{3vw} }
+                              \ \delta _{k+1/2} [\,v\,]         \right]
+\end{aligned}   \right.
+\end{equation} 
+where $A_{uw}^{vm} $ and$A_{vw}^{vm} $ are the vertical eddy viscosity and 
+diffusivity coefficients. The way these coefficients can be evaluated 
+depends on the vertical physics used (see \S\ref{ZDF}).
+
+The surface boundary condition on momentum is given by the stress exerted by 
+the wind. At the surface, the momentum fluxes are prescribed as the boundary 
+condition on the vertical turbulent momentum fluxes,
+\begin{equation} \label{Eq_dynzdf_sbc}
+\left.{\left( {\frac{A^{vm} }{e_3 }\ \frac{\partial \textbf{U}_h}{\partial k}} \right)} \right|_{z=1}
+	 = \frac{1}{\rho _o} \binom{\tau _u}{\tau _v }
+\end{equation}
+where $\left( \tau _u ,\tau _v \right)$ are the two components of the wind stress vector in the 
+(\textbf{i},\textbf{j}) coordinate system. The high mixing coefficients in the 
+surface mixed layer ensure that the surface wind stress is distributed in 
+the vertical over the mixed layer depth. If the vertical mixing coefficient 
+is small (when no mixed layer scheme is used) the surface stress enters only 
+the top model level, as a body force. The surface wind stress is calculated 
+in the surface module routines (SBC, see Chap.~\S\ref{SBC})
+
+The turbulent flux of momentum at the bottom is specified through a bottom 
+friction parameterization (see \S\ref{ZDF_bfr})
+
+% ================================================================
+% External Forcing
+% ================================================================
+\section{External Forcings}
+\label{DYN_forcing}
+
+Besides the surface and bottom stresses (see the above section) which are 
+introduced as boundary conditions on the vertical mixing, two other forcings 
+enter the dynamical equations. 
+
+One is the effect of atmospheric pressure on the ocean dynamics (to be introduced later). 
+
+Another forcing term is the tidal potential, which will be introduced in the reference version soon. 
+
+% ================================================================
+% Time evolution term 
+% ================================================================
+\section{Time evolution term (\mdl{dynnxt})}
+\label{DYN_nxt}
+
+%----------------------------------------------namdom----------------------------------------------------
+\namdisplay{namdom} 
+%-------------------------------------------------------------------------------------------------------------
+
+The general framework of dynamics time stepping is a leap-frog scheme, i.e. 
+a three level centred time scheme associated with a Asselin time filter (cf. \S\ref{DOM_nxt})
+\begin{equation} \label{Eq_dynnxt}
+\begin{split}
+&u^{t+\Delta t} = u^{t-\Delta t} + 2 \, \Delta t  \ \text{RHS}_u^t  	\\
+\\
+&u_f^t \;\quad = u^t+\gamma \,\left[ {u_f^{t-\Delta t} -2u^t+u^{t+\Delta t}} \right]
+\end{split}
+\end{equation} 
+where RHS is the right hand side of the momentum equation, the subscript $f$ denotes 
+filtered values and $\gamma$ is the Asselin coefficient. $\gamma$ is 
+initialized as \np{atfp} (namelist parameter). Its default value is \np{atfp}=0.1.
+
+Note that whith the filtered free surface, the update of the next velocities 
+is done in the \mdl{dynsp\_flt} module, and nly the swap of arrays 
+and Asselin filter is done in \mdl{dynnxt.}
+
+% ================================================================
+% Diagnostic variables
+% ================================================================
+\section{Diagnostic variables ($\zeta$, $\chi$, $w$)}
+\label{DYN_divcur_wzv}
+
+%--------------------------------------------------------------------------------------------------------------
+%           z-coordinate with partial step
+%--------------------------------------------------------------------------------------------------------------
+\subsection{horizontal divergence and relative vorticity (\mdl{divcur})}
+\label{DYN_divcur}
+
+The vorticity is defined at F-point (i.e. corner point) as follows:
+
+\begin{equation} \label{Eq_divcur_cur}
+\zeta =\frac{1}{e_{1f}\,e_{2f} }\left( {\;\delta _{i+1/2} \left[ {e_{2v}\;v} \right]
+									     -\delta _{j+1/2} \left[ {e_{1u}\;u} \right]\;} \right)
+\end{equation} 
+
+The horizontal divergence is defined at T-point. It is given by:
+
+\begin{equation} \label{Eq_divcur_div}
+\chi =\frac{1}{e_{1T}\,e_{2T}\,e_{3T} }
+		\left( {\delta _i \left[ {e_{2u}\,e_{3u}\,u} \right]
+			  +\delta _j \left[ {e_{1v}\,e_{3v}\,v} \right]} \right)
+\end{equation} 
+
+Note that in z-coordinate with full step (\key{zco} defined), $e_{3u} =e_{3v} =e_{3f}$ so that they disappear from \eqref{Eq_divcur_div}.
+
+Note also that whereas the vorticity have the same discrete expression in $z$- and $s$-coordinate, its physical meaning is not identical. $\zeta$ is a pseudo vorticity along $s$-surfaces (only pseudo because $(u,v)$ are still defined along geopotential surfaces, but are no more necessary defined at the same depth).
+
+The vorticity and divergence at the \textit{before} step are used in the computation of the horizontal diffusion of momentum. Note that because they have been calculated prior to the Asselin filtering of the \textit{before} velocities, the \textit{before} vorticity and divergence arrays must be included 
+in the restart file to ensure perfect restartability. The vorticity and divergence at the \textit{now} time step are used respectively for the nonlinear advection and the computation of the vertical velocity. 
+
+%--------------------------------------------------------------------------------------------------------------
+%           Vertical Velocity
+%--------------------------------------------------------------------------------------------------------------
+\subsection{Vertical velocity (\mdl{wzvmod})}
+\label{DYN_wzv}
+
+The vertical velocity is computed by an upward integration of the horizontal 
+divergence from the bottom :
+
+\begin{equation} \label{Eq_wzv}
+\left\{   \begin{aligned}
+&\left. w \right|_{3/2} \quad= 0   	\\
+\\
+&\left. w \right|_{k+1/2}     = \left. w \right|_{k+1/2}  + e_{3t}\;  \left. \chi \right|_k  
+\end{aligned}   \right.
+\end{equation} 
+
+With a free surface, the top vertical velocity is non-zero, due the 
+freshwater forcing and the variations of the free surface elevation. When 
+the free surface is linear or with a rigid lid, the upper boundary condition 
+applies at a fixed level $z=0$. Note that in the rigid-lid case (\key{dynspg\_rl} defined), the surface 
+boundary condition ($\left. w \right|_\text{surface} =0)$ is automatically 
+achieved at least at the computer accuracy, due to the discrete expression 
+of the surface pressure gradient (\colorbox{yellow}{Appendix C}).
+
+Note also that whereas the vertical velocity has the same discrete 
+expression in $z$- and $s$-coordinate, its physical meaning is not the same: in 
+the second case, $w$ is the velocity normal to the $s$-surfaces. 
+
+With the variable volume option, the calculation of the vertical velocity is 
+modified (see \citet{Levier2007}, report available on the NEMO web site). 
+
+% ================================================================
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LBC.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LBC.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LBC.tex	(revision 4536)
@@ -0,0 +1,216 @@
+% ================================================================
+% Chapter Ñ Lateral Boundary Condition (LBC) 
+% ================================================================
+\chapter{Lateral Boundary Condition (LBC) }
+\label{LBC}
+\minitoc
+
+%gm% add here introduction to this chapter
+
+% ================================================================
+% Boundary Condition at the Coast
+% ================================================================
+\section{Boundary Condition at the Coast (\np{shlat})}
+\label{LBC_coast}
+%--------------------------------------------nam_lbc-------------------------------------------------------
+\namdisplay{nam_lbc} 
+%--------------------------------------------------------------------------------------------------------------
+
+%The lateral ocean boundary condition continuous to coastlines are Neumann conditions for heat and salt (no flux across boundaries) and Dirichlet conditions for momentum (from free-slip to "strong" no-slip). They are handled automatically by the mask system (see \S\ref{DOM_msk}). 
+
+%OPA works with land and topography grid points in the computational domain due to the presence of continents or islands,and to the use of full or partial step representation of bottom topography. The computation is performed over the whole domain, i.e. we did not try to restrict the computation to ocean point only areas. This choice has two motivations. First, working on ocean only grid point overload the code and harms the code readability. Second,, and more importantly, it drastically reduce the vector portion of the computation, leading to a dramatic increase of CPU time requirement on vector computers. The process of defining which areas are to be masked is described in \S\ref{DOM_msk}, while this section describes how the masking affects the computation of the various terms of the equations with respect to the boundary condition at solid walls.
+
+The discrete representation of a domain with complex boundaries (coastlines and bottom topography) leads to arrays that include large portions where a computation is not required as the model variables remain at zero. Nevertheless, vectorial supercomputers are far more efficient when computing over a whole array, and the readability of a code is greatly improved when boundary conditions are applied in an automatic way rather than by a specific computation before or after each do loop. An efficient way to work over the whole domain while specifying the boundary conditions is to use the multiplication by mask arrays in the computation. A mask array is a matrix 
+which elements are $1 $in the ocean domain and $0$ elsewhere. A simple multiplication of a variable by its own mask ensures that it will remain zero over land areas. Since most of the boundary conditions consist of a zero flux across the solid boundaries, they can be simply settled by 
+multiplying variables by the right mask arrays, i.e. the mask array of the grid point where the flux is evaluated. For example, the heat flux in the \textbf{i}-direction is evaluated at $u$-points. Evaluating this quantity as,
+
+\begin{equation} \label{Eq_lbc_aaaa}
+\frac{A^{lT} }{e_1 }\frac{\partial T}{\partial i}\equiv \frac{A_u^{lT} 
+}{e_{1u} }\delta _{i+1 / 2} \left[ T \right]\;\;mask_u 
+\end{equation}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_LBC_uv}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_LBC_uv.pdf}
+\caption {Lateral boundary (thick line) at T-level. The velocity normal to the boundary is set to zero.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+where mask$_{u}$ is the mask array at $u$-point, ensures that the heat flux is 
+zero inside land and at the boundaries as mask$_{u}$ is zero at solid 
+boundaries defined at $u$-points in this case (normal velocity $u$ remains zero at 
+the coast) (Fig.~\ref{Fig_LBC_uv}). 
+
+On momentum the situation is a bit more complex as two boundary conditions must be provided along the coast (one on the normal velocity and the other on the tangential velocity). The boundary of the ocean in C-grid is defined by the velocity-faces. For example, at a given $T$-level, the lateral boundary (coastline or intersection with the bottom topography) is made of segments 
+joining $f$-points, and normal velocity points are located between two $f-$points (Fig.~\ref{Fig_LBC_uv}). The boundary condition on the normal velocity (no flux through solid boundaries) can thus be easily settled by the mask system. The boundary condition on the tangential velocity requires a more specific treatment. It influences the relative vorticity and momentum diffusive trends, and is only required to compute the vorticity at the coast. Four different type of the lateral boundary condition are available, controlled by the value of \np{shlat} namelist parameter (which is equal to the value of the mask$_{f}$ array along the coastline):
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!p] \label{Fig_LBC_shlat}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_LBC_shlat.pdf}
+\caption {lateral boundary condition (a) free-slip ($shlat=0$) ; (b) no-slip ($shlat=2$) ; (c) "partial" free-slip ($0<shlat<2$) and (d) "strong" no-slip ($2<shlat$). Implied "ghost" velocity inside land area is display in grey. }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+\begin{description}
+
+\item[free-slip boundary condition (\np{shlat}=0): ]  the tangential velocity at the coastline is equal to the offshore velocity, $i.e.$ the normal derivative of the tangential velocity is zero at the coast, so the vorticity: mask$_{f}$ array is set to zero inside the land and just at the coast (Fig.~\ref{Fig_LBC_shlat}-a).
+
+\item[no-slip boundary condition (\np{shlat}=2): ] the tangential velocity vanishes at the coastline. Assuming that the tangential velocity decreases linearly from the closest ocean velocity grid point to the coastline, the normal derivative is evaluated as if the closest land velocity gridpoint were of the same magnitude as the closest ocean velocity gridpoint but in the opposite direction (Fig.~\ref{Fig_LBC_shlat}-b). Therefore, the vorticity along the coastlines is given by: 
+\begin{equation*}
+\zeta \equiv 2 \left(\delta_{i+1/2} \left[e_{2v} v \right] - \delta_{j+1/2} \left[e_{1u} u \right] \right) / \left(e_{1f} e_{2f} \right) \ ,
+\end{equation*}
+where $u$ and $v$ are masked fields. Setting the mask$_{f}$ array to $2$ along the coastline allows to provide a vorticity field computed with the no-slip boundary condition simply by multiplying it by the mask$_{f}$ :
+\begin{equation} \label{Eq_lbc_bbbb}
+\zeta \equiv \frac{1}{e_{1f} {\kern 1pt}e_{2f} }\left( {\delta _{i+1/2} 
+\left[ {e_{2v} \,v} \right]-\delta _{j+1/2} \left[ {e_{1u} \,u} \right]} 
+\right)\;\mbox{mask}_f 
+\end{equation}
+
+\item["partial" free-slip boundary condition (0$<$\np{shlat}$<$2): ] the tangential velocity at the coastline is smaller than the offshore velocity, $i.e.$ there is a lateral friction but not strong enough to vanish the tangential velocity at the coast (Fig.~\ref{Fig_LBC_shlat}-c). This can be settled by providing a value of mask$_{f}$ strictly inbetween $0$ and $2$.
+
+\item["strong" no-slip boundary condition (2$<$\np{shlat}): ] the viscous boundary layer is assumed to be smaller than half the grid size (Fig.~\ref{Fig_LBC_shlat}-d). The friction is thus larger than in the no-slip case.
+
+\end{description}
+
+Note that when the bottom topography is entirely represented by the $s$-coordinates (pure $s$-coordinate), the lateral boundary condition on momentum tangential velocity is of much  little importance as it is only applied next to the coast where the minimum water depth can be quite shallow.
+
+The alternative numerical implementation of the no-slip boundary conditions for an arbitrary coast line of \citet{Shchepetkin1996} is also available through the activation of \key{noslip\_accurate}. It is based on a fourth order evaluation of the shear at the coast which, in turn, allows a true second order scheme in the interior of the domain ($i.e.$ the numerical boundary scheme simulates the truncation error of the numerical scheme used in the interior of the domain). \citet{Shchepetkin1996} found that such a technique considerably improves the quality of the numerical solution. In \NEMO, the improvement have not been found so spectacular in the half-degree global ocean (ORCA05), but significant reduction of numerically induced coast upwellings were found in eddy resolving simulation of the Alboran Sea \citep{OlivierPh2001}. Nevertheless, as no-slip boundary condition is not recommended in eddy permitting or resolving simulation \citep{Penduff2007}, the use of this option is not recommended.
+
+In practice, the no-slip accurate option changes the way the curl is evaluated at the coast (see \mdl{divcur} module), and requires to qualify the nature of coastline grid point (convex or concave corners, straight north-south or east-west coast) which is performed in \mdl{domask} module, \rou{dom\_msk\_nsa} routine.
+
+% ================================================================
+% Boundary Condition around the Model Domain
+% ================================================================
+\section{Model Domain Boundary Condition (\jp{jperio})}
+\label{LBC_jperio}
+
+At the model domain boundaries several choices are offered: closed, cyclic east-west, south symmetric across the equator, a north-fold, and combination closed-north fold or cyclic-north-fold. The north-fold boundary condition is associated with the 3-pole ORCA mesh. 
+
+% -------------------------------------------------------------------------------------------------------------
+%        Closed, cyclic, south symmetric (\jp{jperio} = 0, 1 or 2) 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Closed, cyclic, south symmetric (\jp{jperio} = 0, 1 or 2)}
+\label{LBC_jperio012}
+
+The choice of closed, cyclic or symmetric model domain boundary condition is made by setting \jp{jperio} to 0, 1 or 2 in \mdl{par\_oce} file. Each time such a boundary condition is needed, it is set by a call to \mdl{lbclnk} routine. The computation of momentum and tracer trends proceed from $i=2$ to $i=jpi-1$ and from $j=2$ to $j=jpj-1$, $i.e.$in the inner model domain. To choose a lateral model boundary condition is to specify the first and last rows and columns of the model variables.
+
+- For closed boundary (\textit{jperio=0}), solid walls are imposed at all model boundaries: 
+first and last rows and columns are set to zero.
+
+- For cyclic east-west boundary (\textit{jperio=1}), first and last rows are set to zero 
+(closed) while first column is set to the value of the before last column 
+and last column to the value of the second one (Fig.~\ref{Fig_LBC_jperio}-a). Whatever flows 
+out of the eastern (western) end of the basin enters the western (eastern) 
+end. Note that there is neither option for north-south cyclic nor doubly 
+cyclic cases.
+
+- For symmetric boundary condition across the equator (\textit{jperio=2}), last rows, and 
+first and last columns are set to zero (closed). The row of symmetry is 
+chosen to be the $u$- and $T-$points equator line ($j=2$, i.e. at the southern end 
+of the domain). For arrays defined at $u-$ or $T-$points, the first row is set to 
+the value of the third row while for most of $v$- and $f$-points arrays (v, $\zeta$, 
+$j\psi$, but scalar arrays such as eddy coefficients) the first row is set to 
+minus the value of the second row (Fig.~\ref{Fig_LBC_jperio}-b). Note that this boundary 
+condition is not yet available on massively parallel computer 
+(\textbf{key{\_}mpp} defined).
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_LBC_jperio}  \begin{center}
+\includegraphics[width=1.0\textwidth]{./Figures/Fig_LBC_jperio.pdf}
+\caption {setting of (a) east-west cyclic  (b) symmetric across the equator boundary conditions.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -------------------------------------------------------------------------------------------------------------
+%        North fold (\textit{jperio = 3 }to $6)$ 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{North-fold (\textit{jperio = 3 }to $6)$ }
+\label{LBC_north_fold}
+
+The north fold boundary condition have been introduced in order to handle the north boundary of an three-polar ORCA grid. Such a grid has two poles in the northern hemisphere. \colorbox{yellow}{to be completed...}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_North_Fold_T}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_North_Fold_T.pdf}
+\caption {North fold boundary with a $T$-point pivot and cyclic east-west boundary condition ($jperio=4$), as used in ORCA 2, 1/4, and 1/12. Pink shaded area corresponds to the inner domain mask (see text). }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% ================================================================
+% Exchanged with neighbouring processors 
+% ================================================================
+\section{Exchanged with neighbouring processors (\mdl{lbclnk}, \mdl{lib\_mpp})}
+\label{LBC_mpp}
+
+For massively parallel processing (mpp), a domain decomposition method is used. The basis of the method consists in splitting the large computation domain of a numerical experiment into several smaller domains and solving the set of equations by addressing independent local problems. Each processor has its own local memory and computes the model equation over a subdomain of the whole model domain. The subdomain boundary conditions are specified through communications between processors which are explicitly organized by specific statements (message passing method). 
+
+A big advantage is that the method does not need many modifications of the initial FORTRAN code. For the modeller's point of view, each sub domain running on a processor is identical to the "mono-domain" code. In addition, the programmer manages the communications between subdomains, and the code presents more scalability when the number of processors is increased. The porting of OPA code on a iPSC860 was achieved during Guyon's PhD [Guyon et al. 1994, 1995] in collaboration with CETIIS and ONERA. The implementation in the operational context and the studies of performances on a T3D and T3E Cray computers have been made in collaboration with IDRIS and CNRS. The present implementation is largely inspired from Guyon's work  [Guyon 1995].
+
+	The parallelization strategy is defined by the physical characteristics of the ocean model. Second order finite difference schemes leads to local discrete operators that depend at the very most on one neighbouring point. The only non-local computations concerne the vertical physics (implicit diffusion, 1.5 turbulent closure scheme, ...) (delocalization over the whole water column), and the solving of the elliptic equation associated with the surface pressure gradient computation (delocalization over the whole horizontal domain). Therefore, a pencil strategy is used for the data sub-structuration: the 3D initial domain is laid out on local processor memories following a 2D horizontal topological splitting. Each sub-domain computes its own surface and bottom boundary conditions and has a side wall overlapping interface which stocks lateral boundary conditions for computations in the inner sub-domain. The overlapping area is reduced to one row. After a computation, a communication phase starts: each processor sends to its neighbouring processors the update values of the point corresponding to the overlapping area of its neighbouring sub-domain. The communication is done through message passing. Usually the parallel virtual language, PVM, is used as it is a standard language available on  nearly  all MPP cumputers. More specific languages (i.e. computer dependant languages) can be easily used to speed up the communication, such as SHEM on T3E computer. The data exchanges between processors are required at the very place where lateral domain boundary conditions are set in the mono-domain computation (\S III.10-c): the lbc\_lnk routine which manages such conditions is substituted by mpplnk.F or mpplnk2.F routine when running on MPP computer (\key{mpp\_mpi} defined). It has to be noticed that when using MPP version of the model, the east-west cyclic boundary condition is implicitly done, while the south-symmetric boundary condition option is not available.
+ 
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_mpp}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_mpp.pdf}
+\caption {Positioning of a sub-domain when massively parallel processing is used. }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+	In the standard version of the OPA model, the splitting is regular and arithmetic. the i-axis is divided by \jp{jpni} and the j-axis by \jp{jpnj} for a number of processors \jp{jpnij} most often equal to $jpni \times jpnj$ (model parameters set in \mdl{par\_oce}). Each processor is independent and without message passing or synchronous process, programs run alone and access just at its own local memory. For this reason, the main model dimensions are now the local dimensions of the subdomain (pencil) that are noted \jp{jpi}, \jp{jpj}, \jp{jpk}. These dimensions include the internal domain and the overlapping rows. The number of overlapping rows is usually set to one (\jp{jpreci}=1, in \mdl{par\_oce}). The whole domain dimensions are named \jp{jpiglo}, \jp{jpjglo} and \jp{jpk}. The relationship between the whole domain and a sub-domain is:
+\begin{eqnarray} 
+      jpi & = & ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci  \nonumber \\
+      jpj & = & ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj  \label{Eq_lbc_jpi}
+\end{eqnarray}
+where \jp{jpni}, \jp{jpnj} are the number of processors following the i- and j-axis.
+
+\colorbox{yellow}{Figure IV.3: example of a domain splitting with 9 processors and no east-west cyclic boundary conditions.}
+
+	One defines also variables nldi and nlei which correspond to the internal domain bounds, and the variables nimpp and njmpp which are the position of the (1,1) grid-point in the global domain. An element of $T_{l}$, a local array (subdomain) corresponds to an element of $T_{g}$, a global array (whole domain) by the relationship: 
+\begin{equation} \label{Eq_lbc_nimpp}
+T_{g} (i+nimpp-1,j+njmpp-1,k) = T_{l} (i,j,k),
+\end{equation}
+with  $1 \leq i \leq jpi$, $1  \leq j \leq jpj $ , and  $1  \leq k \leq jpk$.
+
+	Processors are numbered from 0 to $jpnij-1$, the number is saved in the variable nproc. In the standard version, a processor has no more than four neighbouring processors named nono (for north), noea (east), noso (south) and nowe (west) and two variables, nbondi and nbondj, indicate the situation of the processor \colorbox{yellow}{(see Fig.IV.3)}:
+\begin{itemize}
+\item 		nbondi = -1 	an east neighbour, no west processor,
+\item 		nbondi =  0	an east neighbour, a west neighbour,
+\item 		nbondi =  1 	no east processor, a west neighbour,
+\item 		nbondi =  2 	no splitting following the i-axis.
+\end{itemize}
+	During the simulation, processors exchange data with their neighbours. If there is effectively a neighbour, the processor receives variables from this processor on its overlapping row, and sends the data issued from internal domain corresponding to the overlapping row of the other processor.
+		 
+
+\colorbox{yellow}{Figure IV.4: pencil splitting with the additional outer halos }
+
+
+	The OPA model computes equation terms with the help of mask arrays ( 0 onto land points and 1 onto sea points). It is easily readable and very efficient in the context of the vectorial architecture. But in the case of scalar processor, computations over the land regions becomes more expensive in term of CPU time. It is all the more when we use a complex configuration with a realistic bathymetry like the global ocean where more than 50 \% of points are land points. For this reason, a pre-processing tool allows to search in the mpp domain decomposition strategy if a splitting can be found with a maximum number of only land points processors which could be eliminated (mppini2 program). This optimisation is made with the knowledge of the specific bathymetry in a first time and after, the OPA model, in its initialization part, take account only processors with a sea region. For that, one must indicate in the parameter file the initial cutting along i- and j-axes with jpni and jpnjand the ocean processor number jpnij < jpni x jpnj. Each processor name and neighbour parameters (nbound, nono, noea,...) are modified by an algorithm in the inimpp2.F subroutine.
+
+	The OPA model computes equation terms with the help of mask arrays (0 onto land points and 1 onto sea points). It is easily readable and very efficient in the context of the vectorial architecture. But in the case of scalar processor, computations over the land regions becomes more expensive in term of CPU time. It is all the more so when we use a complex configuration with a realistic bathymetry like the global ocean where more than 50 \% of points are land points. For this reason, a pre-processing tool allows to search in the mpp domain decomposition strategy if a splitting can be found with a maximum number of only land points processors which could be eliminated: the mpp\_optimiz tools (available from the DRAKKAR web site). This optimisation is made with the knowledge of the specific bathymetry. The user chooses optimal parameters \jp{jpni}, \jp{jpnj} and \jp{jpnij} with $jpnij < jpni \times jpnj$, leading to the elimination of $jpni \times jpnj - jpnij$ land processors. When those parameters are specified in module \mdl{par\_oce}, the algorithm in the \rou{inimpp2} routine set each processor name and neighbour parameters (nbound, nono, noea,...) so that the land processors are not taken into account. 
+
+\colorbox{yellow}{Note that the inimpp2 routine is general so that the original inimpp routine should be suppressed from the code.}
+
+When land processors are eliminated, the value corresponding to these locations in the model output files is zero. Note that this is a problem for a mesh output file written by such a model configuration, because model users often divide by the scale factors ($e1t$, $e2t$, etc) and do not expect the grid size to be zero, even on land. It may be best not to eliminate land processors when running the model especially to write the mesh files as outputs (when \np{nmsh} namelist parameter differs from 0).
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_mppini2}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_mppini2.pdf}
+\caption {Example of Atlantic domain defined for the CLIPPER projet. Initial grid is composed by 773 x 1236 horizontal points. (a) the domain is splitting onto 9 \time 20 subdomains (jpni=9, jpnj=20). 52 subdomains are land areas. (b) 52 subdomains are eliminated (white rectangles) and the resulting number of processors really used during the computation is jpnij=128.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+
+% ================================================================
+% Open Boundary Conditions 
+% ================================================================
+\section{Open Boundary Conditions (\key{obc})}
+\label{LBC_obc}
+
+%gm%  to be update from documentation already written by J.M. Molines + Mercator input
+
+% ================================================================
+% Flow Relaxation Scheme 
+% ================================================================
+\section{Flow Relaxation Scheme (???)}
+\label{LBC_bdy}
+
+%gm% to be updated by Met Office
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LDF.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LDF.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_LDF.tex	(revision 4536)
@@ -0,0 +1,293 @@
+
+% ================================================================
+% Chapter Ñ Lateral Ocean Physics (LDF)
+% ================================================================
+\chapter{Lateral Ocean Physics (LDF)}
+\label{LDF}
+\minitoc
+
+$\ $\newline    % force a new ligne
+
+The lateral physics on momentum and tracer equations have been given in \S\ref{PE_zdf} and their discrete formulation in \S\ref{TRA_ldf} and \S\ref{DYN_ldf}). In this section we 
+further discuss the choices that underlie each lateral physics option. 
+Choosing one lateral physics means for the user defining, (1) the space and time variations of the eddy coefficients ; (2) the direction along which the lateral diffusive fluxes are evaluated (model level, geopotential or isopycnal surfaces); and (3) the type of operator used (harmonic, or biharmonic operators, and for tracers only, eddy induced advection on tracers). These 
+three aspects of the lateral diffusion are set through namelist parameters and CPP keys (see the nam\_traldf and nam\_dynldf below).
+%-----------------------------------nam_traldf - nam_dynldf--------------------------------------------
+\namdisplay{nam_traldf} 
+\namdisplay{nam_dynldf} 
+%--------------------------------------------------------------------------------------------------------------
+
+
+% ================================================================
+% Lateral Mixing Coefficients
+% ================================================================
+\section{Lateral Mixing Coefficient (key\_ldftra\_c.d and key\_ldfdyn\_c.d)}
+\label{LDF_coef}
+
+
+Introducing a space variation in the lateral eddy mixing coefficients changes 
+the model core memory requirement, adding up to four three-dimensional 
+arrays for geopotential or isopycnal second order operator applied to 
+momentum. Six cpp keys control the space variation of eddy 
+coefficients: three for momentum and three for tracer. They 
+allow to specify a space variation in the three space directions, in the 
+horizontal plane, or in the vertical only. The default option is a constant 
+value over the whole ocean on momentum and tracers. 
+
+The number of additional arrays that have to be defined and the gridpoint 
+position at which they are defined depend on both the space variation chosen 
+and the type of operator used. The resulting eddy viscosity and 
+diffusivity coefficients can be either single or multiple valued functions. 
+Changes in the computer code when switching from one option to another have 
+been minimized by introducing the eddy coefficients as statement function 
+(include file \hf{ldftra\_substitute} and \hf{ldfdyn\_substitute}). The functions are replaced by their actual meaning during the preprocessing step (cpp capability). The specification of the space variation of the coefficient is settled in \mdl{ldftra} and \mdl{ldfdyn}, or more precisely in include files \textit{ldftra\_cNd.h90} and \textit{ldfdyn\_cNd.h90}, with N=1, 2 or 3. The user can change these include files following his desiderata. The way the mixing coefficient are set in the reference version can be briefly described as follows:
+
+\subsubsection{Constant Mixing Coefficients (default option)}
+When none of the \textbf{key\_ldfdyn\_...} and \textbf{key\_ldftra\_...} keys are defined, a constant value over the whole ocean on momentum and tracers that is specified through 
+\np{ahm0} and \np{aht0} namelist parameters.
+
+\subsubsection{Vertically varying Mixing Coefficients (\key{ldftra\_c1d} and \key{ldfdyn\_c1d})} 
+The 1D option is only available in $z$-coordinate with full step. Indeed in all the other type of vertical coordinate, the depth is a 3D function of (\textbf{i},\textbf{j},\textbf{j}) and therefore, introducing depth-dependant mixing coefficients will requires 3D arrays, $i.e.$ \key{ldftra\_c3d} and \key{ldftra\_c3d}.  In the 1D option, a hyperbolic variation of the lateral mixing coefficient is introduced in which the surface value is \np{aht0} (\np{ahm0}), the bottom value is 1/4 of the surface value, and the transition is round z=300~m with a width of 300~m ($i.e.$ both the depth and the width of the inflection point are set to 300~m). This profile is hard coded in \hf{ldftra\_c1d} file, but can be easily modified by users.
+
+\subsubsection{Horizontally Varying Mixing Coefficients (\key{ldftra\_c2d} and \key{ldfdyn\_c2d})}
+
+By default the horizontal variation of the eddy coefficient depend on the local mesh size and the type of operator used:
+\begin{equation} \label{Eq_title}
+  A_l = \left\{     
+   \begin{aligned}
+         & \frac{\max(e_1,e_2)}{e_{max}} A_o^l  			& \text{for laplacian operator } \\
+         & \frac{\max(e_1,e_2)^{3}}{e_{max}^{3}} A_o^l  & \text{for bilaplacian operator } 
+   \end{aligned}    \right.
+\quad \text{comments}
+\end{equation}
+where $e_{max}$ is the max of $e_1$ and $e_2$ taken over the whole masked ocean domain, and $A_o^l$ is \np{ahm0} (momentum) or \np{aht0} (tracer) namelist parameters. This variation is intended to reflect the lesser need for subgrid scale eddy mixing where the grid size is smaller in the domain. It was introduced in the context of the DYNAMO modelling project \citep{Willebrand2001}. %gm  not only that! stability reasons: with non uniform grid size, it is common to face a blow up of the model due to to large diffusive coefficient compare to the smallest grid size... this is especially true for bilaplacian (to be added in the text!)  
+
+Other formulations can be introduced by the user for a given configuration. For example, in the ORCA2 global ocean model (\key{orca\_r2}), the laplacian viscous operator uses \np{ahm0}~=~$4.10^4 m^2.s^{-1}$ poleward of 20$^{\circ}$ north and south and decreases to \np{aht0}~=~$2.10^3 m^2.s^{-1}$ at the equator \citep{Madec1996, Delecluse2000}. This specification can be found in \rou{ldf\_dyn\_c2d\_orca} routine defined in \mdl{ldfdyn\_c2d}. Similar specific horizontal variation can be found for Antarctic or Arctic sub-domain of ORCA2 and ORCA05 (\key{antarctic} or \key{arctic} defined, see \hf{ldfdyn\_antarctic} and \hf{ldfdyn\_arctic}).
+
+\subsubsection{Space Varying Mixing Coefficients (\key{ldftra\_c3d} and \key{ldfdyn\_c3d})}
+
+The 3D space variation of the mixing coefficient is simply the combination of the 1D and 2D cases, $i.e.$ a hyperbolic tangent variation with depth associated with a grid size dependence of the magnitude of the coefficient. 
+
+\subsubsection{Space and time Varying Mixing Coefficients}
+
+There is no default specification of space and time varying mixing coefficient. The only case available is specific to ORCA2 and ORCA05 global ocean configurations (\key{orca\_r2} or \key{orca\_r05}). It provides only a tracer mixing coefficient for eddy induced velocity (ORCA2) or both iso-neutral and eddy induced velocity (ORCA05) that depends on the local growth rate of baroclinic instability. This specification is actually used when a ORCA key plus \key{traldf\_eiv} plus \key{traldf\_c2d} are defined.
+
+A space variation in the eddy coefficient appeals several remarks:
+
+(1) the momentum diffusive operator acting along model level surfaces is 
+written in terms of curl and divergent components of the horizontal current 
+(see \S\ref{PE_ldf}). Although the eddy coefficient can be set to different values 
+in these two terms, this option is not available. 
+
+(2) with a horizontal varying viscosity, the quadratic integral constraints 
+on enstrophy and on the square of the horizontal divergence for operators 
+acting along model-surfaces are no more satisfied (\colorbox{yellow}{Appendix C}).
+
+(3) for isopycnal diffusion on momentum or tracers, an additional purely 
+horizontal background diffusion with uniform coefficient can be added by 
+setting a non zero value of \np{ahmb0} or \np{ahtb0}, a background horizontal eddy 
+viscosity or diffusivity coefficient (\textbf{namelist parameters} which default value are $0$). Nevertheless, the technique used to compute the isopycnal slopes allows to get rid of such a background diffusion which introduces spurious diapycnal diffusion (see {\S\ref{LDF_slp}).
+
+(4) when an eddy induced advection is used (\key{trahdf\_eiv}), $A^{eiv}$ , the eddy induced coefficient has to be defined. Its space variations are controlled by the same CPP variable as for the eddy diffusivity coefficient (i.e. \textbf{key\_traldf\_cNd}). 
+
+(5) the eddy coefficient associated to a biharmonic operator must be set to a \emph{negative} value.
+
+
+% ================================================================
+% Direction of lateral Mixing
+% ================================================================
+\section{Direction of Lateral Mixing (\mdl{ldfslp})}
+\label{LDF_slp}
+
+%gm%  we should emphasize here that the implementation is a rather old one. Better work can be achieved by using \citet{Griffies1998, Griffies2004} iso-neutral scheme.
+
+
+A direction for lateral mixing has to be defined when the desired operator does not act along the model levels. This occurs when $(a)$ horizontal mixing is required on tracer or momentum (\np{ln\_traldf\_hor} or \np{ln\_dynldf\_hor}) in $s$ or mixed $s$-$z$-coordinate, and $(b)$ isoneutral mixing is required whatever the vertical coordinate is. This direction of mixing is defined by its slopes in the \textbf{i}- and \textbf{j}-directions at the face of the cell of the quantity to be diffused. For tracer, this leads to the following four slopes : $r_{1u}$, $r_{1w}$, $r_{2v}$, $r_{2w}$ (see \eqref{Eq_tra_ldf_iso}), while for momentum the slopes are  $r_{1T}$, $r_{1uw}$, $r_{2f}$, $r_{2uw}$ for $u$ and  $r_{1f}$, $r_{1vw}$, $r_{2T}$, $r_{2vw}$ for $v$. 
+%gm% add here afigure of the slope in i-direction
+
+\subsection{slopes for tracer geopotential mixing in $s$-coordinate}
+
+In $s$-coordinates, geopotential mixing ($i.e.$ horizontal one) $r_1$ and $r_2$ are the slopes between the geopotential and computational surfaces. Their discrete formulation is found by locally 
+vanishing the diffusive fluxes when $T$ is horizontally uniform, i.e. by replacing in \eqref{Eq_tra_ldf_iso} $T$ by $z_T$, the depth of $T$-point, and setting to zero the diffusive fluxes in the three directions. This leads to the following expression for the slopes:
+
+\begin{equation} \label{Eq_ldfslp_geo}
+\begin{aligned}
+ r_{1u} &= \frac{e_{3u}}{ \left( e_{1u}\;\overline{\overline{e_{3w}}}^{\,i+1/2,\,k} \right)}
+ 			  \;\delta_{i+1/2}[z_T] 
+ 		&\approx \frac{1}{e_{1u}}\; \delta_{i+1/2}[z_T] 
+\\
+ r_{2v} &= \frac{e_{3v}}{\left( e_{2v}\;\overline{\overline{e_{3w}}}^{\,j+1/2,\,k} \right)} 
+ 			  \;\delta_{j+1/2} [z_T] 
+		&\approx \frac{1}{e_{2v}}\; \delta_{j+1/2}[z_T] 
+\\
+ r_{1w} &= \frac{1}{e_{1w}}\;\overline{\overline{\delta_{i+1/2}[z_T]}}^{\,i,\,k+1/2}
+ 		&\approx \frac{1}{e_{1w}}\; \delta_{i+1/2}[z_{uw}] 
+ \\
+ r_{2w} &= \frac{1}{e_{2w}}\;\overline{\overline{\delta_{j+1/2}[z_T]}}^{\,j,\,k+1/2}
+		&\approx \frac{1}{e_{2w}}\; \delta_{j+1/2}[z_{vw}] 
+ \\
+\end{aligned}
+\end{equation}
+
+%gm%  caution I'm not sure the simplification was a good idea! 
+These slopes are computed once in \rou{ldfslp\_init} when \np{ln\_sco}=T and \np{ln\_traldf\_hor}=T or \np{ln\_dynldf\_hor}=T. 
+
+\subsection{slopes for tracer iso-neutral mixing}
+In iso-neutral mixing  $r_1$ and $r_2$ are the slopes between the iso-neutral and computational 
+surfaces. Their formulation does not depend on the vertical coordinate used. Their discrete formulation is found using the fact that the diffusive fluxes of locally referenced potential density ($i.e.$ $in situ$ density) vanish. So, substituting $T$ by $\rho$ in \eqref{Eq_tra_ldf_iso} and setting to zero diffusive fluxes in the three directions leads to the following definition for the neutral slopes:
+
+\begin{equation} \label{Eq_ldfslp_iso}
+\begin{split}
+ r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac{\delta_{i+1/2}[\rho]}
+ 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,i+1/2,\,k}}
+\\
+ r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac{\delta_{j+1/2}\left[\rho \right]}
+ 								{\overline{\overline{\delta_{k+1/2}[\rho]}}^{\,j+1/2,\,k}}
+\\
+ r_{1w} &= \frac{e_{3w}}{e_{1w}}\; 
+ 			\frac{\overline{\overline{\delta_{i+1/2}[\rho]}}^{\,i,\,k+1/2}}
+				 {\delta_{k+1/2}[\rho]}
+\\
+ r_{2w} &= \frac{e_{3w}}{e_{2w}}\; 
+ 			\frac{\overline{\overline{\delta_{j+1/2}[\rho]}}^{\,j,\,k+1/2}}
+				 {\delta_{k+1/2}[\rho]}
+\\
+\end{split}
+\end{equation}
+
+%gm% rewrite this as the explanation in not very clear !!!
+%In practice, \eqref{Eq_ldfslp_iso} is of little help in evaluating the neutral surface slopes. Indeed, for an unsimplified equation of state, the density has a strong dependancy on pressure (here approximated as the depth), therefore applying \eqref{Eq_ldfslp_iso} using the $in situ$ density, $\rho$, computed at T-points leads to a flattening of slopes as the depth increases. This is due to the strong increase of the $in situ$ density with depth. 
+
+%By definition, neutral surfaces are tangent to the local $in situ$ density \citep{McDougall1987}, therefore in \eqref{Eq_ldfslp_iso}, all the derivatives have to be evaluated at the same local pressure (which in decibars is approximated by the depth in meters).
+
+%In $z$-coordinate, the derivative of the  \eqref{Eq_ldfslp_iso} numerator is evaluated at a same depth ($T$-level which is also $u$- and $v$-levels), so  the $in situ$ density can be used for its evaluation. 
+
+As the mixing is performed along neutral surfaces, the gradient of $\rho$ in \eqref{Eq_ldfslp_iso} have to be evaluated at the same local pressure (which, in decibars, is approximated by the depth in meters in the model). Therefore \eqref{Eq_ldfslp_iso} cannot be used as such, but further transformation is needed depending on the vertical coordinate used:
+
+\begin{description}
+
+\item[$z$-coordinate with full step : ] in \eqref{Eq_ldfslp_iso} the densities appearing in the $i$ and $j$ derivatives  are taken at the same depth, thus the $in situ$ density can be used. it is not the case for the vertical derivatives. $\delta_{k+1/2}[\rho]$ is replaced by $-\rho N^2/g$, where $N^2$ is the local Brunt-Vais\"{a}l\"{a} frequency evaluated following \citet{McDougall1987} (see \S\ref{TRA_bn2}). 
+
+\item[$z$-coordinate with partial step : ] the technique is identical to the full step case except that at partial step level, the \emph{horizontal} density gradient is evaluated as described in \S\ref{TRA_zps}.
+
+\item[$s$- or hybrid $s$-$z$ coordinate : ] in the current release of \NEMO, there is no specific treatment for iso-neutral mixing in $s$-coordinate. In other word, iso-neutral mixing will only be accurately represented with a linear equation of state (\np{neos}=1 or 2). In the case of a "true" equation of state, the evaluation of $i$ and $j$ derivatives in \eqref{Eq_ldfslp_iso} will include a pressure dependent part, leading to a wrong evaluation of the neutral slopes.
+
+%gm% 
+Note: The solution for $s$-coordinate passes trough the use of different (and better) expression for the constraint on iso-neutral fluxes. Following \citet{Griffies2004}, instead of specifying directly that there is a zero neutral diffusive flux of locally referenced potential density, we stay in the $T$-$S$ plane and consider the balance between the neutral direction diffusive fluxes of potential temperature and salinity:
+\begin{equation}
+\alpha \ \textbf{F}(T) = \beta \ \textbf{F}(S)
+\end{equation}
+
+This constraint leads to the following definition for the slopes:
+
+\begin{equation} \label{Eq_ldfslp_iso2}
+\begin{split}
+ r_{1u} &= \frac{e_{3u}}{e_{1u}}\; \frac
+ 		{\alpha_u \;\delta_{i+1/2}[T] - \beta_u \;\delta_{i+1/2}[S]}
+		{\alpha_u \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,i+1/2,\,k}
+		 -\beta_u  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,i+1/2,\,k} }
+\\
+ r_{2v} &= \frac{e_{3v}}{e_{2v}}\; \frac
+ 		{\alpha_v \;\delta_{j+1/2}[T] - \beta_v \;\delta_{j+1/2}[S]}
+		{\alpha_v \;\overline{\overline{\delta_{k+1/2}[T]}}^{\,j+1/2,\,k}
+		 -\beta_v  \;\overline{\overline{\delta_{k+1/2}[S]}}^{\,j+1/2,\,k} }
+\\
+ r_{1w} &= \frac{e_{3w}}{e_{1w}}\; \frac
+		{\alpha_w \;\overline{\overline{\delta_{i+1/2}[T]}}^{\,i,\,k+1/2}
+		 -\beta_w  \;\overline{\overline{\delta_{i+1/2}[S]}}^{\,i,\,k+1/2} }
+ 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
+\\
+ r_{2w} &= \frac{e_{3w}}{e_{2w}}\; \frac
+		{\alpha_w \;\overline{\overline{\delta_{j+1/2}[T]}}^{\,j,\,k+1/2}
+		 -\beta_w  \;\overline{\overline{\delta_{j+1/2}[S]}}^{\,j,\,k+1/2} }
+ 		{\alpha_w \;\delta_{k+1/2}[T] - \beta_w \;\delta_{k+1/2}[S]}
+\\
+\end{split}
+\end{equation}
+where $\alpha$ and $\beta$, the thermal expansion and saline contracion coefficients introduced in \S\ref{TRA_bn2}, have to be evaluated at the three velocity point. Inorder to save computation time, they should be approximated by the mean of their values at $T$-points (for example in the case of $\alpha$:  $\alpha_u=\overline{\alpha_T}^{i+1/2}$,  $\alpha_v=\overline{\alpha_T}^{j+1/2}$ and $\alpha_w=\overline{\alpha_T}^{k+1/2}$).
+
+Note that such a formulation could be also used in $z$ and $zps$ cases.
+
+
+\end{description}
+
+This implementation is a rather old one. It is similar to the one proposed by Cox [1987], except for 
+the background horizontal diffusion. Indeed, the Cox implementation of isopycnal diffusion in GFDL-type models requires a minimum background horizontal diffusion for numerical stability reasons. To overcome this problem, several techniques have been proposed in which the numerical 
+schemes of the OGCM are modified \citep{Weaver1997, Griffies1998}. 
+Here, another strategy has been chosen \citep{Lazar1997}: a local filtering of the iso-neutral slopes (made on 9 grid-points) prevents the development of grid point noise generated by the iso-neutral diffusive operator (Fig.~\ref{Fig_LDF_ZDF1}). 
+This allows an iso-neutral diffusion scheme without additional background horizontal mixing. This technique can be viewed as a diffusive operator that acts along large-scale (2~$\Delta$x) iso-neutral surfaces. The diapycnal diffusion required for numerical stability is thus minimized and its net effect on the flow is quite small when compared to the effect of a horizontal background mixing. 
+
+Nevertheless, this iso-neutral operator does not ensure that variance cannot increase, contrary to the \citet{Griffies1998} operator which has that property. 
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_LDF_ZDF1}  \begin{center}
+\includegraphics[width=0.70\textwidth]{./Figures/Fig_LDF_ZDF1.pdf}
+\caption {averaging procedure for isopycnal slope computation.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+%There is three additional questions about the slope calculation. First the expression of the rotation tensor used have been obtain assuming the "small slope" approximation, so a bound has to be specified on slopes. Second, numerical stability issues also require a bound on slopes. Third, the question of boundary condition spefified on slopes...
+
+%from griffies: chapter 13.1....
+
+
+
+In addition and also for numerical stability reasons \citep{Cox1987, Griffies2004}, the slopes are bounded by $1/100$ everywhere. This limit is decreasing linearly to zero fom $70$ meters depth 
+and the surface (the fact that the eddies "feel" the surface motivates this 
+flattening of isopycnals near the surface).
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_eiv_slp}  \begin{center}
+\includegraphics[width=0.70\textwidth]{./Figures/Fig_eiv_slp.pdf}
+\caption {Vertical profile of the slope used for lateral mixing in the mixed layer : \textit{(a)} in the real ocean the slope is the iso-neutral slope in the ocean interior and their have to adjust to the surface boundary (i.e. tend to zero at the surface as there is no mixing across the air-sea interface: wall boundary condition). Nevertheless, the profile between surface zero value and interior iso-neutral one is unknown, and especially the value at the based of the mixed layer ; \textit{(b)} profile of slope using a linear tapering of the slope near the surface and imposing a maximum slope of 1/100 ; \textit{(c)} profile of slope actuelly used in \NEMO: linear decrease of the slope from zero at the surface to its ocean interior value computed just below the mixed layer. Note the huge change in the slope at the based of the mixed layer between  \textit{(b)}  and \textit{(c)}. 
+.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+\colorbox{yellow}{add here a discussion about the flattening of the slopes, vs  tapering the coefficient.}
+
+\subsection{slopes for momentum iso-neutral mixing}
+
+The diffusive iso-neutral operator on momentum is the same as the on used on tracer but applied to each component of the velocity (see \eqref{Eq_dyn_ldf_iso} in section~\ref{DYN_ldf_iso}). The slopes between the surface along which the diffusive operator acts and the surface of computation ($z$- or $s$-surfaces) are defined at $T$-, $f-$, and \textit{uw-}points for the $u$-component, and $f-T$-, \textit{vw}-points for the $v$-component. They are computed as follows from the slopes used for tracer diffusion, i.e. \eqref{Eq_ldfslp_geo} and \eqref{Eq_ldfslp_iso} :
+
+\begin{equation} \label{Eq_ldfslp_dyn}
+\begin{aligned}
+&r_{1T}\ \ = \overline{r_{1u}}^{\,i}       &&&    r_{1f}\ \ &= \overline{r_{1u}}^{\,i+1/2} \\
+&r_{2f} \ \ = \overline{r_{2v}}^{\,j+1/2} &&& 	r_{2T}\ &= \overline{r_{2v}}^{\,j} \\
+&r_{1uw}  = \overline{r_{1w}}^{\,i+1/2} &&\ \ \text{and} \ \ &   r_{1vw}&= \overline{r_{1w}}^{\,j+1/2} \\
+&r_{2uw}= \overline{r_{2w}}^{\,j+1/2} &&&         r_{2vw}&= \overline{r_{2w}}^{\,j+1/2}\\
+\end{aligned}
+\end{equation}
+
+The major issue remains in the specification of the boundary conditions. The 
+choice made consists in keeping the same boundary conditions as for lateral 
+diffusion along model level surfaces, i.e. using the shear computed along 
+the model levels and with no additional friction at the ocean bottom (see 
+{\S\ref{LBC_coast}).
+
+
+% ================================================================
+% Eddy Induced Mixing
+% ================================================================
+\section{Eddy Induced Velocity (\mdl{traadv\_eiv}, \mdl{ldfeiv})}
+\label{LDF_eiv}
+
+
+When Gent and McWilliams [1990] diffusion is used (\key{traldf\_eiv} defined), an eddy induced tracer advection term is added, the formulation of which depends on the slopes of iso-neutral surfaces. Contrary to iso-neutral mixing, the slopes use here are referenced to the geopotential surfaces, i.e. \eqref{Eq_ldfslp_geo} is used in $z$-coordinates, and the sum \eqref{Eq_ldfslp_geo}  + \eqref{Eq_ldfslp_iso} in $s$-coordinates. The eddy induced velocity is given by:
+\begin{equation} \label{Eq_ldfeiv}
+\begin{split}
+ u^* & = \frac{1}{e_{2u}e_{3u}}\; \delta_k \left[e_{2u} \, A_{uw}^{eiv} \; \overline{r_{1w}}^{\,i+1/2} \right]\\
+v^* & = \frac{1}{e_{1u}e_{3v}}\; \delta_k \left[e_{1v} \, A_{vw}^{eiv} \; \overline{r_{2w}}^{\,j+1/2} \right]\\
+w^* & = \frac{1}{e_{1w}e_{2w}}\; \left\{ \delta_i \left[e_{2u} \, A_{uw}^{eiv} \; \overline{r_{1w}}^{\,i+1/2} \right] + \delta_j \left[e_{1v} \, A_{vw}^{eiv} \; \overline{r_{2w}}^{\,j+1/2} \right] \right\} \\
+\end{split}
+\end{equation}
+where $A^{eiv}$ is the eddy induced velocity coefficient set through \np{aeiv}, a \textit{nam\_traldf} namelist parameter. 
+The three components of the eddy induced velocity are computed and add to the eulerian velocity in the mdl{traadv\_eiv}. This has been preferred to a separate computation of the advective trends associated to the eiv velocity as it allows to take advantage of all the advection schemes offered for the tracers (see \S\ref{TRA_adv}) and not only the $2^{nd}$ order advection scheme as in previous release of OPA \citep{Madec1998}. This is particularly useful for passive tracers where \emph{positivity}of the advection scheme is of paramount importance. 
+
+At surface, lateral and bottom boundaries, the eddy induced velocity and thus the 
+advective eddy fluxes of heat and salt are set to zero. 
+
+
+
+
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_MISC.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_MISC.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_MISC.tex	(revision 4536)
@@ -0,0 +1,588 @@
+% ================================================================
+% Chapter Ñ Miscellaneous Topics
+% ================================================================
+\chapter{Miscellaneous Topics (xxx)}
+\label{MISC}
+\minitoc
+
+% ================================================================
+% Representation of Unresolved Straits
+% ================================================================
+\section{Representation of Unresolved Straits}
+\label{MISC_strait}
+
+% In climate modeling, it is often necessary to allow water masses that are separated by land to exchange properties. This situation arises in models when the grid mesh is too coarse to resolve narrow passageways that in reality provide crucial connections between water masses. For example, coarse grid spacing typically closes off the Mediterranean from the Atlantic at the Straits of Gibraltar. In this case, it is important for climate models to include the effects of salty water entering the Atlantic from the Mediterranean. Likewise, it is important for the Mediterranean to replenish its supply of water from the Atlantic to balance the net evaporation occurring over the Mediterranean region. 
+% also same problem as soon as important straits are not properly resolve by the mesh. For example in ORCA 1/4\r{}, this occors in several straits of the Indonesian archipelagos (Ombai, Lombok...).
+% We describe here the three methods that can be used in NEMO to handle such unproperly resolved straits. 
+%The communication consists of mixing tracers and mass/volume between non-adjacent water columns. Momentum is not mixed. The scheme conserves total tracer content, and total volume (the latter in $z*$- or $s*$-coordinate), and maintains compatibility between the tracer and mass/volume budgets.  
+
+% Note: such changes are so specific to a given configuration that no attempt have been made to set them in a generic way. Nevertheless, example of how they can be set up is given in the ORCA2 configuration (\key{ORCA_R2}).
+
+% -------------------------------------------------------------------------------------------------------------
+%       Hand made geometry changes
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Hand made geometry changes}
+\label{MISC_strait_hand}
+
+$\bullet$ reduced scale factor, also called partially open face (Hallberg, personnal communication 2006)
+%also called partially open cell  or partial closed cells
+$\bullet$ increase of the viscous boundary layer by local increase of the fmask value at the coast
+
+\colorbox{yellow}{Add a short description of scale factor changes staff and fmask increase}
+
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tbp] \label{Fig_MISC_strait_hand}  \begin{center}
+\includegraphics[width=0.80\textwidth]{./Figures/Fig_Gibraltar.pdf}
+\includegraphics[width=0.80\textwidth]{./Figures/Fig_Gibraltar2.pdf}
+\caption {Example of the Gibraltar strait defined in a 1\r{} x 1\r{} mesh. \textit{Top}: using partially open cells. The meridional scale factor at $V$-point is reduced on both sides of the strait to account for the real width of the strait (about 20 km). Note that the scale factors of the strait $T$-point remains unchanged. \textit{Bottom}: using viscous boundary layers. The four fmask along the strait coastlines are set to a value larger than 4, $i.e.$ "strong" no-slip case (see Fig.\ref{Fig_LBC_shlat}) creating a large viscous boundary layer that allows a reduced transport through the strait.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+% -------------------------------------------------------------------------------------------------------------
+% Cross Land Advection 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Cross Land Advection (\textit{tracla} module)}
+\label{MISC_strait_cla}
+
+%--------------------------------------------namcro--------------------------------------------------------
+\namdisplay{namcro} 
+%--------------------------------------------------------------------------------------------------------------
+
+\colorbox{yellow}{Add a short description of CLA staff here or in lateral boundary condition chapter?}
+
+% ================================================================
+% Closed seas
+% ================================================================
+\section{Closed seas}
+\label{MISC_closea}
+
+
+% ================================================================
+% Sub-Domain Functionality (\textit{nizoom, njzoom}, namelist parameters)
+% ================================================================
+\section{Sub-Domain Functionality (\jp{jpizoom}, \jp{jpjzoom})}
+\label{MISC_zoom}
+
+The sub-domain functionality, also improperly called zoom option (improperly because it is not associated with a change in model resolution) is a quite simple function that allows to 
+perform a simulation over a sub-domain of an already defined configuration 
+(i.e. without defining a new set of mesh, initial state and forcings). This 
+option can be useful for testing the user setting of surface boundary 
+conditions, or the initial ocean state of a huge ocean model configuration 
+while having a small central memory requirement. It can also be used to 
+easily test specific physics in a sub-domain (for example, test of the 
+coupling between sea-ice and ocean model over the Arctic or Antarctic ocean 
+as they are set in the global ocean version of OPA \citep{Madec1996}. 
+In standard, this option does not include any specific treatment for ocean 
+boundaries of the sub-domain: they are considered as artificial vertical 
+walls. Nevertheless, it is quite easy to add a restoring term toward a 
+climatology in the vicinity of those boundaries (see \S\ref{TRA_dmp}).
+
+In order to easily define a sub-domain over which the computation can be 
+performed, the dimension of all input arrays (ocean mesh, bathymetry, 
+forcing, initial state, ...) are defined as \jp{jpidta}, \jp{jpjdta} and \jp{jpkdta} (\mdl{par\_oce} module), while the 
+computational domain is defined through \jp{jpiglo}, \jp{jpjglo} and \jp{jpk} (\mdl{par\_oce} module). When running the model 
+over the whole configuration, the user set \jp{jpiglo}=\jp{jpidta} \jp{jpjglo}=\jp{jpjdta }and \jp{jpk}=\jp{jpkdta}. When running the model 
+over a sub-domain, the user have to provide the size of the sub-domain, 
+(\jp{jpiglo}, \jp{jpjglo}, \jp{jpkglo}), and the indices of the south western corner as \jp{jpizoom} and \jp{jpjzoom} in the \mdl{par\_oce} module (Fig.~\ref{Fig_LBC_zoom}). 
+
+Note that a third set of dimension exist, \jp{jpi}, \jp{jpj} and \jp{jpk} which is actually used to 
+perform the computation. It is set by default to \jp{jpi}=\jp{jpjglo} and \jp{jpj}=\jp{jpjglo}, except for massively 
+parallel computing where the computational domain is laid out on local 
+processor memories following a 2D horizontal splitting (see {\S}IV.2-c)
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_LBC_zoom}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_LBC_zoom.pdf}
+\caption {position of a model domain compared to the data input domain when the zoom functionality is used.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+
+% ================================================================
+% 1D model functionality
+% ================================================================
+\section{Water column model: 1D model (\key{cfg\_1d})}
+\label{MISC_1D}
+
+The 1D model is a stand alone water column based on the 3D NEMO system. It can be applied to the ocean alone or to the ocean-ice system and can include passive tracers or a biogeochemical model. It is set up by defining the \key{cfg\_1d} CPP key. This 1D model is a very useful tool  \textit{(a)} to learn about the physics and numerical treatment of vertical mixing processes ; \textit{(b)} to investigate suitable parameterizations of unresolved turbulence (wind steering, langmuir circulation, skin layers) ; \textit{(c)} to compare the behaviour of different mixing vertical scheme  ; \textit{(d)} to perform sensitivity study to the vertical diffusion on a particular point of the ocean global domain ; \textit{(d)} to access to specific diagnostics, aside from the standard model variables,  because of having small in core memory requirement.
+
+The methodology is based on the use of the zoom functionality (see \S\ref{MISC_zoom}), and the addition of some specific routines. There is no need of defining a new set of mesh, bathymetry, initial state and forcing, as the 1D model will use those of the configuration it is a zoom of. 
+
+ 
+
+% ================================================================
+% Accelerating the Convergence 
+% ================================================================
+\section{Accelerating the Convergence (\np{nn\_acc} = 1)}
+\label{MISC_acc}
+%--------------------------------------------namdom-------------------------------------------------------
+\namdisplay{namdom} 
+%--------------------------------------------------------------------------------------------------------------
+
+Searching an equilibrium state with an ocean model requires very long time 
+integration (a few thousand years for a global model). Due to the size of 
+the time step required for numerical stability consideration (less than a 
+few hours), this is usually requires a large elapse time. In order overcome 
+this problem, \citet{Bryan1984} introduces a technique that allows to accelerate 
+the spin up to the equilibrium. It consists in using a larger time step in 
+the thermodynamic evolution equations than in the dynamic evolution 
+equations. It does not affect the equilibrium solution but modifies the 
+trajectory to reach it.
+
+The acceleration of convergence is used when \np{nn\_acc}=1. In that case, $\Delta t=rdt$ is 
+the time step of dynamics while $\widetilde{\Delta t}=rdttra$ is the tracer time-step. Both are settled from \np{rdt} and \np{rdttra}  namelist parameters. The set of prognostic equations to solve becomes:
+\begin{equation} \label{Eq_acc}
+\begin{split}
+\frac{\partial \textbf{U}_h }{\partial t} 
+	&\equiv \frac{\textbf{U}_h ^{t+1}-\textbf{U}_h^{t-1} }{2\Delta t} = \ldots \\ 
+\frac{\partial T}{\partial t} &\equiv \frac{T^{t+1}-T^{t-1}}{2 \widetilde{\Delta t}} = \ldots \\ 
+\frac{\partial S}{\partial t} &\equiv \frac{S^{t+1} -S^{t-1}}{2 \widetilde{\Delta t}} = \ldots \\ 
+\end{split}
+\end{equation}
+
+\citet{Bryan1984} has analysed the consequences of this distorted physics. Free 
+waves have a slower phase speed, their meridional structure is slightly 
+modified, and the growth rate of baroclinically unstable waves is reduced 
+but there is a wider range of instability. This technique is efficient for 
+searching an equilibrium state in coarse resolution models. However its 
+application is not suitable for many oceanic problems: it cannot be used for 
+transient or time evolving problems (in particular, it is very questionable 
+to keep this technique when using a seasonal cycle in the forcing fields), 
+and it cannot be used in high-resolution models where baroclinically 
+unstable processes are important. Moreover, the vertical variation of 
+$\Delta \tilde {t}$ implies that the heat and salt contents are no more 
+conserved due to the vertical coupling of the ocean level through both 
+advection and diffusion.
+
+
+% ================================================================
+% Model optimisation, Control Print and Benchmark
+% ================================================================
+\section{Model optimisation, Control Print and Benchmark}
+\label{MISC_opt}
+%--------------------------------------------namdom-------------------------------------------------------
+\namdisplay{nam_ctl} 
+%--------------------------------------------------------------------------------------------------------------
+
+Three points to be described here:
+
+$\bullet$ Vector and memory optimisation:
+
+ \key{vectopt\_loop} enable the internal loop collapse, a very efficient way to increase the length of vector and thus speed up the model on vector computers.
+ 
+ Add here also one word on NPROMA technique that has been found useless, since compiler have made significant progress during the last decade.
+ 
+ Add also one word on NEC specific optimisation (Novercheck option for example)
+
+ \key{vectopt\_memory} has been introduced in order to reduce the memory requirement of the model. This is obviously done by incresing the CPU time requirement, as it suppress intermediate computation saved in in-core memory. This possibility have not been intensively used. In fact up to now, it only concern the TKE physics, in which,  when \key{vectopt\_memory} is defined, the coefficient used for horizontal smoothing of $A_v^T$ and $A_v^m$ are no more computed once for all. This reduces the memory requirement by three 2D arrays.
+ 
+$\bullet$ Control print: describe here 4 things:
+
+1- \np{ln\_ctl} : compute and print the inner domain averaged trends in all TRA, DYN LDF and ZDF modules. Very useful to detect the origin of an undesired change in model results. 
+
+2- also \np{ln\_ctl} but using the nictl. njctl. namelist parameters to check the origin of differences between mono and multi processor
+
+3- \key{esopa} (to be rename key\_nemo) : also a option of model management. When defined, this key force the activation of all options and CPP keys. For example, all the tracer and momentum advection scheme are called ! There is therefore no physical meaning associated with model results. In fact, this option allows both the compilator and the model run to go through all the Fortran lines of the model. This allows to check is there is obvious compilation or running bugs for CPP options, and running bugs for namelist options.
+
+5- last digit comparison (\np{nbit\_cmp}). In MPP simulation, the computation of sum of the whole domain is performed as the sum over all processors of the sum of the inner domain of each processor. This double sum nevr give exactly the same result as a single sum over the whole domain, due to truncature differences. The "bit comparison" option has been introduced in order to be able to check that mono-processor and multi-processor give exactly the same results. 
+
+
+$\bullet$  Benchmark (\np{nbench}). This option, defines a benchmark run based on GYRE configuration in which the resolution remains the same whatever the domain size is. This allows to run very large model domain by just changing the domain size (\jp{jpiglo}, \jp{jpjglo}) without adjusting neither the time-step nor the physical parametrisations. 
+
+
+% ================================================================
+% Elliptic solvers (SOL)
+% ================================================================
+\section{Elliptic solvers (SOL)}
+\label{MISC_sol}
+%--------------------------------------------namdom-------------------------------------------------------
+\namdisplay{namsol} 
+%--------------------------------------------------------------------------------------------------------------
+
+The computation of the surface pressure gradient with a rigid lid assumption 
+requires to compute $\partial_t \psi$, the time evolution of the 
+barotropic streamfunction. $\partial_t \psi$ is solution of an elliptic 
+equation (I.2.4) for which two solvers are available, a 
+Successive-Over-Relaxation (SOR) or a preconditioned conjugate gradient 
+(PCG) \citep{Madec1988, Madec1990}. The PCG is a very efficient 
+method for solving elliptic equations on vector computers. It is a fast and 
+rather easy to use method, which is an attractive feature for a large number 
+of ocean situations (variable bottom topography, complex coastal geometry, 
+variable grid spacing, islands, open or cyclic boundaries, etc ...). It does 
+not require the search of an optimal parameter as in the SOR method. 
+Nevertheless, the SOR has been kept because it is a linear solver, a very 
+useful property when using the adjoint model of OPA.
+
+The surface pressure gradient is computed in \mdl{dynspg}. The 
+default option is the use of PCG or SOR 
+depending on \np{nsolv} (namelist parameter). 
+At each time step the time derivative of the barotropic streamfunction is 
+the solution of (II.2.3). Introducing the following coefficients:
+
+\begin{equation} 
+\begin{aligned}
+&C_{i,j}^{NS} &&= \frac{e_{2v}(i,j)}{\left( H_v (i,j) e_{1v} (i,j)\right)}\\
+&C_{i,j}^{EW} &&= \frac{e_{1u}(i,j)}{\left( H_u (i,j) e_{2u} (i,j)\right)}\\
+&B_{i,j} &&= \delta_i \left( e_{2v}M_v \right) - \delta_j \left( e_{1u}M_u \right)\\
+\end{aligned}
+\end{equation}
+
+the five-point finite difference equivalent equation (II.2.3) can be rewritten as:
+
+\begin{multline} \label{Eq_solmat}
+C_{i+1,j}^{NS} {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i+1,j} + \;
+C_{i,j+1}^{EW}{   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j+1} + \;
+C_{i,j}    ^{NS} {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i-1,j} + \;
+C_{i,j}    ^{EW}{   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j-1}\\
+-\left(C_{i+1,j}^{NS} + C_{i,j+1}^{EW} + C_{i,j}^{NS} + C_{i,j}^{EW} \right)   {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j}  =  B_{i,j}
+\end{multline}
+\eqref{Eq_solmat} is a linear symmetric system of equations. All the elements of the 
+corresponding matrix \textbf{A} vanish except those of five diagonals. With 
+the natural ordering of the grid points (i.e. from west to east and from 
+south to north), the structure of \textbf{A} is block-tridiagonal with 
+tridiagonal or diagonal blocks. \textbf{A} is a positive-definite symmetric 
+matrix of size $(jpi \cdot jpj)^2$, and \textbf{B}, the right hand side of 
+\eqref{Eq_solmat}, is a vector.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Successive Over Relaxation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Successive Over Relaxation \np{nsolv}=2}
+\label{MISC_solsor}
+
+Let us introduce the four cardinal coefficients: $A_{i,j}^S = C_{i,j}^{NS}/D_{i,j}\,$, 
+$A_{i,j}^W = C_{i,j}^{EW}/D_{i,j}\,$, $A_{i,j}^E = C_{i,j+1}^{EW}/D_{i,j}\,$ and $A_{i,j}^N = C_{i+1,j}^{NS}/D_{i,j}\,$, and define 
+$\tilde B_{i,j} = B_{i,j}/D_{i,j}\,$, where $D_{i,j} = C_{i,j}^{NS}+ C_{i+1,j}^{NS} + C_{i,j}^{EW} + C_{i,j+1}^{EW} $ (i.e. the diagonal of 
+\textbf{A}). (VII.5.1) can be rewritten as:
+
+\begin{multline} 
+    A_{i,j}^{N}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i+1,j   } 
++\,A_{i,j}^{E}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i    ,j+1} 		\\
++\,A_{i,j}^{S}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i-1 ,j    } 
++\,A_{i,j}^{W} {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i    ,j-1} 	
+               -  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j} = \tilde B_{i,j}
+\end{multline}
+
+The SOR method used is an iterative method. Its algorithm can be summarised 
+as follows [see \citet{Haltiner1980} for further discussion]:
+
+initialisation (evaluate a first guess from former time step computations)
+\begin{equation}
+\left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^0 = 2{\left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^t} - {\left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^{t-1}}
+\end{equation}
+iteration $n,$ from $n=0 $until convergence, do :
+\begin{multline} 
+R_{i,j}^n
+= A_{i,j}^{N}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i+1,j}^n 
++\,A_{i,j}^{E}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j+1} ^n		\\
++\,A_{i,j}^{S}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i-1,j} ^{n+1}
++\,A_{i,j}^{W} {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j-1} ^{n+1}	
+                   -  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j}^n - \tilde B_{i,j}
+\end{multline}
+\begin{equation} 
+     {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j} ^{n+1}
+  = {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j} ^{n}
+  + \omega \;R_{i,j}^n
+\end{equation}
+where \textit{$\omega $ }satisfies $1\leq \omega \leq 2$. An optimal value exists for \textit{$\omega $ }which 
+accelerates significantly the convergence, but it has to be adjusted 
+empirically for each model domain, except for an uniform grid where an 
+analytical expression for \textit{$\omega $ }can be found \citep{Richtmyer1967}. This 
+parameter is defined as \textit{sor}, a \textbf{namelist} parameter. The convergence test is of the form:
+\begin{equation}
+\delta = \frac{\sum\limits_{i,j}{R_{i,j}^n}{R_{i,j}^n}}{\sum\limits_{i,j}{ \tilde B_{i,j}^n}{\tilde B_{i,j}^n}} \leq \epsilon
+\end{equation}
+where $\epsilon $ is the absolute precision that is required. It is highly recommended 
+to use a $\epsilon $ smaller or equal to $10^{-2}$ as larger values may leads 
+to numerically induced basin scale barotropic oscillations, and to use a two 
+or three order of magnitude smaller value in eddy resolving configuration. 
+The precision of the solver is not only a numerical parameter, but 
+influences the physics. Indeed, the zero change of kinetic energy due to the 
+work of surface pressure forces in rigid-lid approximation is only achieved 
+at the precision demanded on the solver ({\S}~C.1-e). The precision is 
+specified by setting \textit{eps} (\textbf{namelist parameter}). In addition, two other tests are used to stop the iterative 
+algorithm. They concern the number of iterations and the module of the right 
+hand side. If the former exceeds a specified value, \textit{nmax} (\textbf{namelist parameter}), or the latter is greater than 
+$10^{15}$, the whole model computation is stopped while the last 
+computed time step fields are saved in the standard output file. In both 
+cases, this usually indicates that there is something wrong in the model 
+configuration (error in the mesh, the initial state, the input forcing, or 
+the magnitude of the time step or of the mixing coefficients). A typical 
+value of $nmax$ is a few hundred for $\epsilon = 10^{-2}$, increasing to a few 
+thousand for $\epsilon = 10^{-12}$.
+
+The vectorization of the SOR algorithm is not straightforward. (VII.5.4) 
+contains two linear recurrences on $i$ and $j$. This inhibits the vectorisation 
+({\S}~IV.2-a). Therefore (VII.5.4a) has been rewritten as:
+
+\begin{multline} 
+R_{i,j}^n
+= A_{i,j}^{N}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i+1,j}^n 
++\,A_{i,j}^{E}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j+1} ^n		\\
++\,A_{i,j}^{S}  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i-1,j} ^{n}
++\,A_{i,j}^{W} {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j-1} ^{n}	
+                   -  {   \left(  \frac{\partial \psi}{\partial t } \right)    }_{i,j}^n - \tilde B_{i,j}
+\end{multline}
+
+\begin{equation}
+R_{i,j}^n = R_{i,j}^n - \omega \;A_{i,j}^{S}\; R_{i,j-1}^n
+\end{equation}
+
+\begin{equation}
+R_{i,j}^n = R_{i,j}^n - \omega \;A_{i,j}^{W}\; R_{i-1,j}^n
+\end{equation}
+
+If the three equations in (VII.5.6) are solved inside the same do-loop, 
+(VII.5.4a) and (VII.5.6) are strictly equivalent. In the model they are 
+solved successively over the whole domain. The convergence is slower but 
+(VII.5.6a) and (VII.5.6b) are vector loops on $i$-index (the inner loop) and 
+(VII.5.6c) is adapted to Cray vector computers by using a routine from the 
+Cray library (namely the FOLR routine) to solve the first-order linear 
+recurrence. The SOR method is very flexible and can be used under a wide 
+range of conditions, including irregular boundaries, interior boundary 
+points, etc. Proofs of convergence, etc. may be found in the standard 
+numerical methods texts for partial equations.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Preconditioned Conjugate Gradient
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Preconditioned Conjugate Gradient}
+\label{MISC_solpcg}
+
+\begin{flushright}
+(\textit{nbsfs=1}, \textbf{namelist parameter})
+\end{flushright}
+
+\textbf{A} is a definite positive symmetric matrix, thus solving the linear 
+system (VII.5.1) is equivalent to the minimisation of a quadratic 
+functional:
+\begin{equation*}
+\textbf{Ax} = \textbf{b} \leftrightarrow \textbf{x} =\text{inf}_{y} \,\phi (\textbf{y})
+\quad , \qquad
+\phi (\textbf{y}) = 1/2 \langle \textbf{Ay},\textbf{y}\rangle - \langle \textbf{b},\textbf{y} \rangle 
+\end{equation*}
+where $\langle , \rangle$ is the canonical dot product. The idea of the 
+conjugate gradient method is to search the solution in the following 
+iterative way: assuming that $\textbf{x}^n$ is obtained, $\textbf{x}^{n+1}$ is searched under the form $\textbf {x}^{n+1}={\textbf {x}}^n+\alpha^n{\textbf {d}}^n$ which satisfies:
+\begin{equation*}
+{\textbf{ x}}^{n+1}=\text{inf} _{{\textbf{ y}}={\textbf{ x}}^n+\alpha \,{\textbf{ d}}^n} \,\phi ({\textbf{ y}})\;\;\Leftrightarrow \;\;\frac{d\phi }{d\alpha}=0
+\end{equation*}
+and expressing $\phi (\textbf{y})$ as a function of \textit{$\alpha $}, we obtain the value that minimises the functional: 
+\begin{equation*}
+\alpha ^n = \langle{ \textbf{r}^n , \textbf{r}^n} \rangle  / \langle {\textbf{ A d}^n, \textbf{d}^n} \rangle
+\end{equation*}
+where $\textbf{r}^n = \textbf{b}-\textbf{A x}^n = \textbf{A} (\textbf{x}-\textbf{x}^n)$ is the error at rank $n$. The choice of the descent vector $\textbf{d}^n$ depends on the error: $\textbf{d}^n = \textbf{r}^n + \beta^n \,\textbf{d}^{n-1}$. $\beta ^n$ is searched such that the descent vectors form an orthogonal base for the dot product linked to \textbf{A}. Expressing the condition 
+$\langle \textbf{A d}^n, \textbf{d}^{n-1} \rangle = 0$ the value of $\beta ^n$ is found:
+ $\beta ^n = \langle{ \textbf{r}^n , \textbf{r}^n} \rangle  / \langle {\textbf{r}^{n-1}, \textbf{r}^{n-1}} \rangle$. As a result, the errors $ \textbf{r}^n$ form an orthogonal base 
+for the canonic dot product while the descent vectors $\textbf{d}^n$ form 
+an orthogonal base for the dot product linked to \textbf{A}. The resulting 
+algorithm is thus the following one:
+
+initialisation :
+
+
+\begin{equation*} 
+\textbf{x}^0 = \left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^0 = 2{\left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^t} - {\left(  \frac{\partial \psi}{\partial t } \right)_{i,j}^{t-1}}
+, \text{the initial guess }
+\end{equation*}
+
+\begin{equation*}
+\textbf{r}^0 = \textbf{d}^0 = \textbf{b} - \textbf{A x}^0
+\end{equation*}
+\begin{equation*}
+\gamma_0 = \langle{ \textbf{r}^0 , \textbf{r}^0} \rangle
+\end{equation*}
+iteration $n,$ from $n=0$ until convergence, do :
+
+\begin{equation} 
+\begin{split}
+\text{z}^n& = \textbf{A d}^n \\
+\alpha_n &= \gamma_n  \langle{ \textbf{z}^n , \textbf{d}^n} \rangle \\
+\textbf{x}^{n+1} &= \textbf{x}^n + \alpha_n \,\textbf{d}^n \\
+\textbf{r}^{n+1} &= \textbf{r}^n - \alpha_n \,\textbf{z}^n \\
+\gamma_{n+1} &= \langle{ \textbf{r}^{n+1} , \textbf{r}^{n+1}} \rangle \\
+\beta_{n+1} &= \gamma_{n+1}/\gamma_{n}  \\
+\textbf{d}^{n+1} &= \textbf{r}^{n+1} + \beta_{n+1}\; \textbf{d}^{n}\\
+\end{split}
+\end{equation}
+
+
+The convergence test is:
+
+\begin{equation}
+\delta = \gamma_{n}\; / \langle{ \textbf{b} , \textbf{b}} \rangle \leq \epsilon
+\end{equation}
+where $\epsilon $ is the absolute precision that is required. As for the SOR algorithm, 
+both the PCG algorithm and the whole model computation are stopped when the 
+number of iteration, $nmax$, or the module of the right hand side exceeds a 
+specified value (see {\S}~VII.5-a for further discussion). The precision and 
+the maximum number of iteration are specified by setting $eps$ and $nmax$ (\textbf{namelist parameters}).
+
+It can be demonstrated that the algorithm is optimal, provides the exact 
+solution in a number of iterations equal to the size of the matrix, and that 
+the convergence rate is all the more fast as the matrix is closed to 
+identity (i.e. the eigen values are closed to 1). Therefore, it is more 
+efficient to solve a better conditioned system which has the same solution. 
+For that purpose, we introduce a preconditioning matrix \textbf{Q 
+}which is an approximation of \textbf{A} but much easier to invert 
+than \textbf{A} and solve the system:
+\begin{equation} 
+\textbf{Q}^{-1} \textbf{A x} = \textbf{Q}^{-1} \textbf{b}
+\end{equation}
+
+The same algorithm can be used to solve (VII.5.7) if instead of the 
+canonical dot product the following one is used: ${\langle{ \textbf{a} , \textbf{b}} \rangle}_Q = \langle{ \textbf{a} , \textbf{Q b}} \rangle$, and if $\textbf{\~{b}} = \textbf{Q}^{-1}\;\textbf{b}$ and $\textbf{\~{A}} = \textbf{Q}^{-1}\;\textbf{A}$ are substituted to \textbf{b} and \textbf{A} \citep{Madec1988}. In OPA, \textbf{Q} is chosen as the diagonal 
+of\textbf{ A}, i.e. the simplest form for \textbf{Q} so that it can be 
+easily inverted. In this case, the discrete formulation of (VII.5.8) is in 
+fact given by (VII.5.2) and thus the matrix and right hand side are computed 
+independently from the solver used.
+
+% -------------------------------------------------------------------------------------------------------------
+%       FETI
+% -------------------------------------------------------------------------------------------------------------
+\subsection{FETI}
+\label{MISC_solfeti}
+
+FETI is a powerfull solver that was developed by Marc Guyon (ref !!!).  It as been just converted from Fortan 77 to 90, but never successfully tested after that. Since then, nobody has found enough time to further investigate the implmenntationof FETI and debug it.
+
+Its main advantaged is to save a lot of CPU time compared to SOR or PCG algorithm. Nevertheless, its main drawbacks is that the solution is depends on the domain decomposition chosen. Using a different number of processors, the solution is the same at the precision required, but not the same at the computer precision. This make it hard to debug.  
+
+% -------------------------------------------------------------------------------------------------------------
+%       Boundary Conditions --- Islands
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Boundary Conditions --- Islands (key{\_}islands defined)}
+\label{MISC_solisl}
+
+The boundary condition used for both solvers is that the time derivative of 
+the barotropic streamfunction is zero along all the coastlines. When islands 
+are present in the model domain, additional computations must be done to 
+determine the barotropic streamfunction with the correct boundary 
+conditions. This is detailed below.
+
+The model does not recognise itself the islands which must be defined using 
+bathymetry information, i.e. $mbathy$ array, equals $-1$ over the first island, $-2$ over 
+the second, ... , $-N$ over the $N^{th}$ island (see {\S}~VII.2-b). The model 
+determines the position of island grid-points and defines a closed contour 
+around each island which will be used to compute the circulation around each 
+island. The closed contour is formed of the ocean grid-points which are the 
+closest to the island.
+
+First, the island barotropic streamfunctions $\psi_n$ are computed 
+using the PCG (they are solutions of (VII.5.1) with the right-hand side 
+equals to zero and with $\psi_n = 1$ along the island $n$ and $\psi_n = 0$ along the other coastlines) (Note that specifying $1$ as boundary 
+condition on an island for $\psi$ is equivalent to define a 
+specific right hand side for (VII.5.1)~). The precision of this computation 
+can be very high since it is done once. The absolute precision, $epsisl$, and the 
+maximum number of iteration, $nmisl$, are the \textbf{namelist parameters} used for that 
+computation. Their typical values are $epsisl = 10^{-10}$ and $nmisl = 4000$. Then the island matrix A is computed from (I.2.8) and reversed. At 
+each time step, $\psi_0$, the solution of (I.2.4) with $\psi_0 = 0$ along all coastlines, is computed using either SOR or PCG. It has to 
+be noted that the first guess of this computation is defined as in (VII.5.3) 
+except that $\partial_t \psi_0$ is used, not $\partial_t \psi$. Indeed we are 
+computing $\partial_t \psi_0$ which is usually far different from $\partial_t \psi$. Then, it is easy to find the time evolution of the barotropic 
+streamfunction on each island and to deduce $\partial_t \psi$ using (I.2.9) 
+in order to compute the surface pressure gradient. Note that the value of 
+the barotropic streamfunction itself is also computed as the time 
+integration of $\partial_t \psi$ for further diagnostics.
+
+% ================================================================
+% Diagnostics
+% ================================================================
+\section{Diagnostics }
+\label{MISC_diag}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Standard Model Output 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Standard Model Output (default option or \key{dimg})}
+\label{MISC_iom}
+
+%to be updated with Seb documentation on the IO
+\amtcomment{ 
+The model outputs are of three types: the restart file, the output listing, 
+and the output file(s). The restart file is used internally by the code when 
+the user wants to start the model with initial conditions defined by a 
+previous simulation. It contains all the information that is necessary not 
+to introduce changes in the model results (even at the computer precision) 
+between a run performed with several restarts and the same run performed in 
+one time. It has to be noticed that this requires that the restart file 
+contains two consecutive time steps for all the prognostic variables, and 
+that it is save in the same binary format as the one used by the computer to 
+calculate (in particular, 32 bits binary IEEE format for this file must not 
+be used). The output listing and file(s) are defined but should be checked 
+and eventually adapted to the user's needs. The output listing is stored in 
+the $ocean.output$ file. The information are printed all the way through the code on the 
+logical unit $numout$. To locate these prints, use the UNIX command "$grep -i numout^*$" in the source code directory.
+
+In the standard configuration, the user will find the model results in two 
+output files for every time-step where output is demanded: a \textbf{VO} 
+file containing all the three dimensional fields in logical unit $numwvo$, and a 
+\textbf{SO} file containing all the two dimensional (horizontal) fields in 
+logical unit $numwso$. These outputs are defined in the $diawri.F$ routine. The standard and available on-line diagnostics are described in {\S}III-12-c.
+
+The default output is 32 bits binary IEEE format, compatible with the 
+Vairmer software (see the Climate Modelling and global Change team WEB 
+server at CERFACS: http://www.cerfacs.fr). The model's reference directory 
+also contains a visualisation tool based on \textbf{NCAR Graphics 
+}(http://ngwww.ucar.edu). If a user has access to the NCAR software, he or 
+she can copy the \textbf{LODMODEL/UTILS/OPADRA} directory from the reference 
+and, following the \textbf{README}, create the graphic outputs from the 
+model's results.
+}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Tracer/Dynamics Trends
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Tracer/Dynamics Trends (\key{trdlmd}, \key{diatrdtra})}
+\label{MISC_tratrd}
+
+%to be udated this corresponds to OPA8
+When \key{diatrddyn} and/or \key{diatrddyn} cpp 
+variables are defined, each trends of the dynamics and/or temperature and 
+salinity time evolution equations are stored in three-dimensional arrays 
+just after their computation (i.e. at the end of each $dyn\cdots .F$ 
+and/or $tra\cdots .F$ routines). These trends are then used in diagnostic 
+routines $diadyn.F$ and $diatra.F$ respectively. In standard, these routines check the basin averaged properties of the momentum and tracer equations every \textit{ntrd } time-steps (\textbf{namelist parameter}). These routines 
+are given as an example; they must be adapted by the user to his/her 
+desiderata.
+
+These two options imply the definition of several arrays in the in core 
+memory, increasing quite sensitively the code memory requirements (search 
+for \key{diatrddyn} or 
+\key{diatrdtra}in \textit{common.h} file)
+
+% -------------------------------------------------------------------------------------------------------------
+%       On-line Floats trajectories
+% -------------------------------------------------------------------------------------------------------------
+\subsection{On-line Floats trajectories}
+\label{FLO}
+%--------------------------------------------namflo-------------------------------------------------------
+\namdisplay{namflo} 
+%--------------------------------------------------------------------------------------------------------------
+
+\colorbox{yellow}{a description is to be added here}
+
+% -------------------------------------------------------------------------------------------------------------
+%       Other Diagnostics
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Other Diagnostics}
+\label{MISC_diag_others}
+
+%To be updated  this corresponds to OPA 8
+
+Aside from the standard model variables, some other diagnostics are computed 
+on-line or can be added in the model. The available ready-to-add diagnostics 
+can be found in DIA. Among the available diagnostics one can 
+quote:
+
+- the mixed layer depth (based on a density criterion) (\mdl{diamxl})
+
+- the turbocline depth (based on a turbulent mixing coefficient criterion) (\mdl{diamxl})
+
+- the depth of the 20\r{}C isotherm (\mdl{diahth})
+
+- the depth of the thermocline (maximum of the vertical temperature gradient) (\mdl{diahth})
+
+- the meridional heat and salt transports and their decomposition (\mdl{diamfl})
+
+- the surface pressure (\mdl{diaspr})
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics.tex	(revision 4536)
@@ -0,0 +1,939 @@
+% ================================================================
+% Chapter 1 Ñ Model Basics
+% ================================================================
+
+\chapter{Model basics}
+\label{PE}
+\minitoc
+
+
+% ================================================================
+% Primitive Equations
+% ================================================================
+\section{Primitive Equations}
+\label{PE_PE}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Vector Invariant Formulation 
+% -------------------------------------------------------------------------------------------------------------
+
+\subsection{Vector Invariant Formulation}
+\label{PE_Vector}
+
+
+The ocean is a fluid that can be described to a good approximation by the primitive equations, i.e. the Navier-Stokes equations along with a nonlinear equation of state which couples the two active tracers (temperature and salinity) to the fluid velocity, plus the following additional assumptions made from scale considerations:
+
+\textit{(1) spherical earth approximation: }the geopotential surfaces are assumed to be spheres so that gravity (local vertical) is parallel to the earth's radius
+
+\textit{(2) thin-shell approximation: }the ocean depth is neglected compared to the earth's radius
+
+\textit{(3) turbulent closure hypothesis: }the turbulent fluxes (which represent the effect of small scale processes on the large-scale) are expressed in terms of large-scale features
+
+\textit{(4) Boussinesq hypothesis:} density variations are neglected except in their contribution to the buoyancy force
+
+\textit{(5) Hydrostatic hypothesis: }the vertical momentum equation is reduced to a balance between the vertical pressure gradient and buoyancy force (this removes convective processes from 
+the initial Navier-Stokes equations: they must be parameterized)
+
+\textit{(6) Incompressibility hypothesis: }the three dimensional divergence of the velocity vector is assumed to be zero.
+
+Because the gravitational force is so dominant in the equations of large-scale motions, it is quite useful to choose an orthogonal set of unit vectors (\textbf{i},\textbf{j},\textbf{k}) linked to the earth such that \textbf{k} is the local upward vector and (\textbf{i},\textbf{j}) are two vectors orthogonal to \textbf{k}, i.e. tangent to the geopotential surfaces. Let us define the following variables: \textbf{U} the vector velocity, $\textbf{U}=\textbf{U}_h + w\, \textbf{k}$ (the subscript $h$ denotes the local horizontal vector, i.e. over the (\textbf{i},\textbf{j}) plan), $T$ the potential temperature, $S$ the salinity, \textit{$\rho $} the \textit{in situ} density. The vector invariant form of the primitive equations in the (\textbf{i},\textbf{j},\textbf{k}) vector system provides the following six equations (namely the momentum balance, the hydrostatic equilibrium, the incompressibility, the heat and salt conservation and an equation of state):
+\begin{subequations} \label{Eq_PE}
+  \begin{equation}     \label{Eq_PE_dyn}
+\frac{\partial {\rm {\bf U}}_h }{\partial t}=
+-\left[    {\left( {\nabla \times {\rm {\bf U}}} \right)\times {\rm {\bf U}}
+            +\frac{1}{2}\nabla \left( {{\rm {\bf U}}^2} \right)}    \right]_h
+ -f\;{\rm {\bf k}}\times {\rm {\bf U}}_h 
+-\frac{1}{\rho _o }\nabla _h p + {\rm {\bf D}}^{\rm {\bf U}}
+  \end{equation}
+  \begin{equation}     \label{Eq_PE_hydrostatic}
+\frac{\partial p }{\partial z} = - \rho \ g
+  \end{equation}
+  \begin{equation}     \label{Eq_PE_continuity}
+\nabla \cdot {\bf U}=  0
+  \end{equation}
+\begin{equation} \label{Eq_PE_tra_T}
+\frac{\partial T}{\partial t} = - \nabla \cdot  \left( T \ \rm{\bf U} \right) + D^T
+  \end{equation}
+  \begin{equation}     \label{Eq_PE_tra_S}
+\frac{\partial S}{\partial t} = - \nabla \cdot  \left( S \ \rm{\bf U} \right) + D^S
+  \end{equation}
+  \begin{equation}     \label{Eq_PE_eos}
+\rho = \rho \left( T,S,p \right)
+  \end{equation}
+\end{subequations}
+where $\nabla$ is the generalised derivative vector operator in $(\bf i,\bf j, \bf k)$ directions, $t$ the time, $z$ the vertical coordinate, $\rho $ the \textit{in situ} density given by the equation of state (\ref{Eq_PE_eos}), $\rho_o$ a reference density, $p$ the pressure, $f=2 \bf \Omega \cdot \bf k$ the Coriolis acceleration (where $\bf \Omega$ is the Earth angular velocity vector), and $g$ the gravitational acceleration. ${\rm {\bf D}}^{\rm {\bf U}}$, $D^T$ and $D^S$ are the parameterizations of small-scale physics for momentum, temperature and salinity, including surface forcing terms. Their nature and formulation are discussed in \S\ref{PE_zdf_ldf}, page~\pageref{PE_zdf_ldf}.
+
+.
+
+% -------------------------------------------------------------------------------------------------------------
+% Boundary condition
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Boundary Conditions}
+\label{PE_boundary_condition}
+
+An ocean is bounded by complex coastlines and bottom topography at its base and by an air-sea or ice-sea interface at its top. These boundaries can be defined by two surfaces, $z=-H(i,j)$ and $z=\eta(i,j,k,t)$, where $H$ is the depth of the ocean bottom and $\eta$ the height of the sea surface. Both $H$ and $\eta$ are usually referenced to a given surface, $z=0$, chosen as a mean sea surface (Fig.~\ref{Fig_ocean_bc}). Through these two boundaries, the ocean can exchange fluxes of heat, fresh water, salt, and momentum with the solid earth, the continental surfaces, the sea ice and the atmosphere. However, some of these fluxes are so weak that even on climatic time scales of thousands of years they can be neglected. In the following, we briefly review the fluxes exchanged at the interfaces between the ocean and the other components of the earth system.
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_ocean_bc}  \begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_I_ocean_bc.pdf}
+\caption{The ocean is bounded by two surfaces, $z=-H(i,j)$ and $z=\eta(i,j,k,t)$, where $H$ is the depth of the sea floor and $\eta$ the height of the sea surface. Both $H$ and $\eta $ are referenced to $z=0$.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+\begin{description}
+\item[Land - ocean interface:] the major flux between continental surfaces and the ocean is a mass exchange of fresh water through river runoff. Such an exchange modifies locally the sea surface salinity especially in the vicinity of major river mouths. It can be neglected for short range integrations but has to be taken into account for long term integrations as it influences the characteristics of water masses formed (especially at high latitudes). It is required to close the water cycle of the climatic system. It is usually specified as a fresh water flux at the air-sea interface in the vicinity of river mouths.
+\item[Solid earth - ocean interface:] heat and salt fluxes across the sea floor are negligibly small, except in special areas of little extent. They are always neglected in the model. The boundary condition is thus set to no flux of heat and salt across solid boundaries. For momentum, the situation is different. There is no flow across solid boundaries, i.e. the velocity normal to the ocean bottom and coastlines is zero (in other words, the bottom velocity is parallel to solid boundaries). This kinematic boundary condition can be expressed as:
+\begin{equation} \label{Eq_PE_w_bbc}
+w = -{\rm {\bf U}}_h \cdot  \nabla _h \left( H \right)
+\end{equation}
+In addition, the ocean exchanges momentum with the earth through friction processes. Such momentum transfer occurs at small scales in a boundary layer. It must be parameterized in terms of turbulent fluxes through bottom and/or lateral boundary conditions. Its specification depends on the nature of the physical parameterization used for ${\rm {\bf D}}^{\rm {\bf U}}$ in \eqref{Eq_PE_dyn}. They are discussed in  in \S\ref{PE_zdf}, page~\pageref{PE_zdf}.% and Chap. III.6 to 9.
+\item[Atmosphere - ocean interface:] the kinematic surface condition plus the mass flux of fresh water PE  (the precipitation minus evaporation budget) leads to: 
+\begin{equation} \label{Eq_PE_w_sbc}
+w = \frac{\partial \eta }{\partial t} 
+    + \left. {{\rm {\bf U}}_h } \right|_{z=\eta } \cdot  \nabla _h \left( \eta \right) 
+    + P-E
+\end{equation}
+The dynamic boundary condition, neglecting the surface tension (which removes capillary waves from the system) leads to the continuity of pressure across the interface $z=\eta$. The atmosphere and ocean also exchange horizontal momentum (wind stress), and heat.
+\item[Sea ice - ocean interface:] the two media exchange heat, salt, fresh water and momentum. The sea surface temperature is constrained to be at the freezing point at the interface. Sea ice salinity is very low ($\sim5 \,psu$) compared to those of the ocean ($\sim34 \,psu$). The cycle of freezing/melting is associated with fresh water and salt fluxes that cannot be neglected.
+\end{description}
+
+
+% ================================================================
+% The Horizontal Pressure Gradient
+% ================================================================
+\section{The Horizontal Pressure Gradient }
+\label{PE_hor_pg}
+
+% -------------------------------------------------------------------------------------------------------------
+% Pressure Formulation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Pressure Formulation}
+\label{PE_p_formulation}
+
+The total pressure at a given depth $z$ is composed of a surface pressure $p_s$ at a reference geopotential surface ($z=0$) and an hydrostatic pressure $p_h$ such that: $p(i,j,k,t)=p_s(i,j,t)+p_h(i,j,k,t)$. The latter is computed by integrating (\ref{Eq_PE_hydrostatic}), assuming that pressure in decibars can be approximated by depth in meters in (\ref{Eq_PE_eos}). The hydrostatic pressure is then given by:
+\begin{equation} \label{Eq_PE_pressure}
+p_h \left( {i,j,z,t} \right)
+ = \int_{\varsigma =z}^{\varsigma =0} {g\;\rho \left( {T,S,z} \right)\;d\varsigma } 
+\end{equation}
+The surface pressure requires a more specific treatment. Two strategies can be considered: $(a)$ the introduction of a new variable $\eta$, the free-surface elevation, for which a prognostic equation can be established and solved; $(b)$ the assumption that the ocean surface is a rigid lid, on which the pressure (or its horizontal gradient) can be diagnosed. When the former strategy is used, a solution of the free-surface elevation consists in the excitation of external gravity waves. The flow is barotropic and the surface moves up and down with gravity as the restoring force. The phase speed of such waves is high (some hundreds of metres per second) so that the time step would have to be very short if they were present in the model. The latter strategy filters these waves as the rigid lid approximation implies $\eta=0$, i.e. the sea surface is the surface $z=0$. This well known approximation increases the surface wave speed to infinity and modifies certain other longwave dynamics (e.g. barotropic Rossby or planetary waves). In the present release of OPA, both strategies are still available. They are further described in the next two sub-sections.
+
+% -------------------------------------------------------------------------------------------------------------
+% Free Surface Formulation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Free Surface Formulation}
+\label{PE_free_surface}
+
+In the free surface formulation, a variable $\eta$, the sea-surface height, is introduced which describes the shape of the air-sea interface. This variable is solution of a prognostic equation which is established by forming the vertical average of the kinematics surface condition (\ref{Eq_PE_w_bbc}):
+\begin{equation} \label{Eq_PE_ssh}
+\frac{\partial \eta }{\partial t}=-D+P-E
+ 	\quad \text{where} \ 
+D=\nabla \cdot \left[ {\left( {H+\eta } \right) \; {\rm{\bf \overline{U}}}_h \,} \right]
+\end{equation}
+and using (\ref{Eq_PE_hydrostatic}) the surface pressure is given by: $p_s = \rho \, g \, \eta$.
+
+Allowing the air-sea interface to move introduces the external gravity waves (EGWs) as a class of solution of the primitive equations. These waves are barotropic because of hydrostatic assumption, and their phase speed is quite high. Their time scale is short with respect to the other processes described by the primitive equations.
+
+Three choices can be made regarding the implementation of the free surface in the model, depending on the physical processes of interest. 
+
+$\bullet$ If one is interested in EGWs, in particular the tides and their interaction 
+with the baroclinic structure of the ocean (internal waves) possibly in 
+shallow seas, then a non linear free surface is the most adequate: this 
+means that no approximation is made in (\ref{Eq_PE_ssh}) and that the variation of the 
+ocean volume is fully taken into account. Note that in order to study the 
+fast time scales associated with EGWs it is necessary to minimize time 
+filtering effects (use an explicit time scheme with very small time step, or 
+a split-explicit scheme with reasonably small time step, see \S\ref{DYN_spg_exp} or
+\S\ref{DYN_spg_ts}.
+
+$\bullet$ If one is not interested in EGW but rather sees them as high frequency 
+noise, it is possible to apply a filter to slow down the fastest waves while 
+not altering the slow barotropic Rossby waves. In that case it is also 
+generally sufficient to solve a linearized version of (\ref{Eq_PE_ssh}), which allows 
+to take into account freshwater fluxes applied at the ocean surface \citep{Roullet2000}.
+
+$\bullet$ For process studies not involving external waves nor surface freshwater 
+fluxes, it is possible to use the rigid lid approximation see (next 
+section). The ocean surface is considered as a fixed surface, so that all 
+external waves are removed from the system. 
+
+The filtering of EGWs in models with a free surface is usually a matter of discretisation of the temporal derivatives, using the time splitting method \citep{Killworth1991, Zhang1992} or the implicit scheme \citep{Dukowicz1994}. In OPA, we use a slightly different approach developed by \citet{Roullet2000}: the damping of EGWs is ensured by introducing an additional force in the momentum equation. \eqref{Eq_PE_dyn} becomes: 
+\begin{equation} \label{Eq_PE_flt}
+\frac{\partial {\rm {\bf U}}_h }{\partial t}= {\rm {\bf M}}
+- g \nabla \left( \tilde{\rho} \ \eta \right) 
+- g \ T_c \nabla \left( \widetilde{\rho} \ \partial_t \eta \right) 
+\end{equation}
+where $T_c$, is a parameter homogeneous to a time which characterizes the force, $\widetilde{\rho} = \rho / \rho_o$ is the dimensionless density, and   represents the collected contributions of the Coriolis, hydrostatic pressure gradient, non-linear and viscous terms in \eqref{Eq_PE_dyn}.
+
+The new force can be interpreted as a diffusion of vertically integrated volume flux divergence. The time evolution of $D$ is thus governed by a balance of two terms, $-g$ \textbf{A} $\eta$ and $g \, T_c \,$ \textbf{A} $D$, associated with a propagative regime and a diffusive regime in the temporal spectrum, respectively. In the diffusive regime, the EGWs no longer propagates, $i.e.$ they are stationary and damped. The diffusion regime applies to the modes shorter than $T_c$. For longer ones, the diffusion term vanishes. Hence, the temporally unresolved EGWs can be damped by choosing $T_c > \Delta t$. \citet{Roullet2000} demonstrate that (\ref{Eq_PE_flt}) can be integrated with a leap frog scheme except the additional term which has to be computed implicitly. This is not surprising since the use of a large time step has a necessarily numerical cost. Two gains arise in comparison with the previous formulations. Firstly, the damping of EGWs can be quantified through the magnitude of the additional term. Secondly, the numerical scheme does not need any tuning. Numerical stability is ensured as soon as $T_c > \Delta t$.
+
+When the variations of free surface elevation are small compared to the thickness of the model layers, the free surface equation (\ref{Eq_PE_ssh}) can be linearized. As emphasized by \citet{Roullet2000} the linearization of (\ref{Eq_PE_ssh}) has consequences on the conservation of salt in the model. With the nonlinear free surface equation, the time evolution of the total salt content is 
+\begin{equation} \label{Eq_PE_salt_content}
+\frac{\partial }{\partial t}\int\limits_{D\eta } {S\;dv} =\int\limits_S 
+{S\;(-\frac{\partial \eta }{\partial t}-D+P-E)\;ds}
+\end{equation}
+where $S$ is the salinity, and the total salt is integrated in the whole ocean volume $D_\eta$ bounded by the time-dependent free surface. The right hand side (which is an integral over the free surface) vanishes when the nonlinear equation (\ref{Eq_PE_ssh}) is satisfied, so that the salt is perfectly conserved. When the free surface equation is linearized, \citet{Roullet2000} show that the total salt content integrated in the fixed volume $D$ (bounded by the surface $z=0$) is no longer conserved:
+\begin{equation} \label{Eq_PE_salt_content_linear}
+\frac{\partial }{\partial t}\int\limits_D {S\;dv} =-\int\limits_S 
+{S\;\frac{\partial \eta }{\partial t}ds} 
+\end{equation}
+
+The right hand side of (\ref{Eq_PE_salt_content_linear}) is small in equilibrium solutions \citep{Roullet2000}. It can be significant when the freshwater forcing is not balanced and the globally averaged free surface is drifting. An increase in sea surface height \textit{$\eta $} results in a decrease of the salinity in the fixed volume $D$. Even in that case though, the total salt integrated in the variable volume $D_{\eta}$ varies much less, since (\ref{Eq_PE_salt_content_linear}) can be rewritten as 
+\begin{equation} \label{Eq_PE_salt_content_corrected}
+\frac{\partial }{\partial t}\int\limits_{D\eta } {S\;dv} 
+=\frac{\partial}{\partial t} \left[ \;{\int\limits_D {S\;dv} +\int\limits_S {S\eta \;ds} } \right]
+=\int\limits_S {\eta \;\frac{\partial S}{\partial t}ds}
+\end{equation}
+
+Although the total salt content is not exactly conserved with the linearized free surface, its variations are driven by correlations of the time variation of surface salinity with the sea surface height, which is a negligible term. This situation contrasts with 
+the case of the rigid lid approximation (following section) in which case freshwater forcing is represented by a virtual salt flux, leading to spurious sources or sinks of salt \citep{Roullet2000}.
+
+% -------------------------------------------------------------------------------------------------------------
+% Rigid-Lid Formulation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Rigid-Lid formulation}
+\label{PE_rigid_lid}
+
+With the rigid lid approximation, we assume that the ocean surface ($z=0$) is a rigid lid on which a pressure $p_s$ is exerted. This implies that the vertical velocity at the surface is equal to zero. From the continuity equation (\ref{Eq_PE_continuity}) and the kinematic condition at the bottom (\ref{Eq_PE_w_bbc}) (no flux across the bottom), it can be shown that the vertically integrated flow $H{\rm {\bf \bar {U}}}_h$ is non-divergent (where the overbar indicates a vertical average over the whole water column, i.e. from $z=-H$ , the ocean bottom, to $z=0$ , the rigid-lid). Thus,  can be derived from a volume transport streamfunction $\psi$:
+\begin{equation} \label{Eq_PE_u_psi}
+\overline{\vect{U}}_h =\frac{1}{H}\left(   \vect{k} \times \nabla \psi   \right)
+\end{equation}
+
+As $p_s$ does not depend on depth, its horizontal gradient is obtained by forming the vertical average of \eqref{Eq_PE_dyn} and using \eqref{Eq_PE_u_psi}:
+
+\begin{equation} \label{Eq_PE_u_barotrope}
+\frac{1}{\rho _o }\nabla _h p_s 
+=\overline{\vect{M}} -\frac{\partial \overline{\vect{U}} _h }{\partial t}
+=\overline{\vect{M}} 
+-\frac{1}{H} \left[   \vect{k} \times \nabla \left( \frac{\partial \psi}{\partial t} \right)   \right]
+\end{equation}
+
+Here ${\rm {\bf M}} = \left( M_u,M_v \right)$ represents the collected contributions of the Coriolis, hydrostatic pressure gradient, nonlinear and viscous terms in \eqref{Eq_PE_dyn}. The time derivative of $\psi $ is the solution of an elliptic equation which is obtained from the vertical component of the curl of (\ref{Eq_PE_u_barotrope}):
+\begin{equation} \label{Eq_PE_psi}
+\left[   {\nabla \times \left[ {\frac{1}{H} \vect{\bf k} 
+  \times \nabla \left(   {\frac{\partial \psi }{\partial t}} \right)}   \right]} \; \right]_z 
+=\left[   {\nabla \times \overline{\vect{M}} }   \right]_z 
+\end{equation}
+
+Using the proper boundary conditions, (\ref{Eq_PE_psi}) can be solved to find $\partial_t \psi$ and thus using (\ref{Eq_PE_u_barotrope}) the horizontal surface pressure gradient. It should be noted that $p_s$ can be computed by taking the divergence of (\ref{Eq_PE_u_barotrope}) and solving the resulting elliptic equation. Thus the surface pressure is a diagnostic quantity that can be recovered for analysis purposes.
+
+A difficulty lies in the determination of the boundary condition on $\partial_t \psi$. The boundary condition on velocity is that there is no flow normal to a solid wall, i.e. the coastlines are streamlines. Therefore (I.2.7 is solved with the following Dirichlet boundary condition: $\partial_t \psi$ is constant along each coastline of the same continent or of the same island. When all the coastlines are connected (there are no islands), the constant value of $\partial_t \psi$ along the coast can be arbitrarily chosen to be zero. When islands are present in the domain, the value of the barotropic streamfunction will generally be different for each island and for the continent, and will vary with respect to time. So the boundary condition is: $\psi=0$ along the continent and $\psi=\mu_n$ along island $n$ ($1 \leq n \leq Q$), where $Q$ is the number of islands present in the domain and $\mu_n$ is a time dependent variable. A time evolution equation of the unknown $\mu_n$ can be found by evaluating the circulation of the time derivative of the vertical average (barotropic) velocity field along a closed contour around each island. Since the circulation of a 
+gradient field along a closed contour is zero, from (\ref{Eq_PE_u_barotrope}) we have:
+\begin{equation} \label{Eq_PE_isl_circulation}
+\oint_n {\frac{1}{H}\left[ {{\rm {\bf k}}\times \nabla \left( 
+{\frac{\partial \psi }{\partial t}} \right)} \right] \cdot {\rm {\bf d}}\ell } 
+= \oint_n {\overline {\rm {\bf M}} \cdot {\rm {\bf d}}\ell } 
+\qquad  1 \leq n \leq Q
+\end{equation}
+
+Since (\ref{Eq_PE_psi}) is linear, its solution \textit{$\psi $} can be decomposed as follows:
+\begin{equation} \label{Eq_PE_psi_isl}
+\psi =\psi _o +\sum\limits_{n=1}^{n=Q} {\mu _n \psi _n } 
+\end{equation}
+where $\psi _o$ is the solution of (\ref{Eq_PE_psi}) with $\psi _o=0$ long all the coastlines, and where $\psi _n$ is the solution of (\ref{Eq_PE_psi}) with the right-hand side equal to $0$, and with $\psi _n =1$ long the island $n$, $\psi _n =0$ along the other boundaries. The function $\psi _n$ is thus independent of time. Introducing (\ref{Eq_PE_psi_isl}) into (\ref{Eq_PE_isl_circulation}) yields:
+\begin{multline} \label{Eq_PE_psi_isl_circulation}
+\left[ {\oint_n {\frac{1}{H}\left[ {{\rm {\bf k}}\times \nabla \psi _m } 
+\right]\cdot {\rm {\bf d}}\ell } } \right]_{1\leq m\leqslant Q \atop 1\leq n\leqslant Q  }
+ \left( {\frac{\partial \mu _n }{\partial t}} 
+\right)_{1\leqslant n\leqslant Q}        \\
+ =\left( {\oint_n {\left[ {\overline {\rm 
+{\bf M}} -\frac{1}{H}\left[ {{\rm {\bf k}}\times \nabla \left( 
+{\frac{\partial \psi _o }{\partial t}} \right)} \right]} \right]\cdot {\rm 
+{\bf d}}\ell } } \right)_{1\leqslant n\leqslant Q} 
+\end{multline}
+which can be rewritten as:
+\begin{equation} \label{Eq_PE_psi_isl_matrix}
+{\rm {\bf A}}\;\left( {\frac{\partial \mu _n }{\partial t}} 
+\right)_{1\leqslant n\leqslant Q} ={\rm {\bf B}}
+\end{equation}
+where \textbf{A} is a $Q  \times Q$ matrix and \textbf{B} is a time dependent vector. As \textbf{A} is independent of time, it can be calculated and inverted once. The time derivative of the  streamfunction when islands are present is thus given by:
+\begin{equation} \label{Eq_PE_psi_isl_dt}
+\frac{\partial \psi }{\partial t}=\frac{\partial \psi _o }{\partial 
+t}+\sum\limits_{n=1}^{n=Q} {{\rm {\bf A}}^{-1}{\rm {\bf B}}\;\psi _n } 
+\end{equation}
+
+
+
+% ================================================================
+% Curvilinear z-coordinate System
+% ================================================================
+\section{Curvilinear \textit{z-}coordinate System}
+\label{PE_zco}
+
+
+
+% -------------------------------------------------------------------------------------------------------------
+% Tensorial Formalism
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Tensorial Formalism}
+\label{PE_tensorial}
+
+In many ocean circulation problems, the flow field has regions of enhanced dynamics (i.e. surface layers, western boundary currents, equatorial currents, or ocean fronts). The representation of such dynamical processes can be improved by specifically increasing the model resolution in these regions. As well, it may be convenient to use a lateral boundary-following coordinate system to better represent coastal dynamics. Moreover, the common geographical coordinate system has a singular point at the North Pole that cannot be easily treated in a global model without filtering. A solution consists in introducing an appropriate coordinate transformation that shifts the singular point on land \citep{MadecImb1996, Murray1996}. As a conclusion, it is important to solve the primitive equations in various curvilinear coordinate systems. An efficient way of introducing an appropriate coordinate transform can be found when using a tensorial formalism. This formalism is suited to any multidimensional curvilinear coordinate system. Ocean modellers mainly use three-dimensional orthogonal grids on the sphere, with conservation of the local vertical. Here we give the simplified equations for this particular case. The general case is detailed by \citet{Eiseman1980} in their survey of the conservation laws of fluid dynamics.
+
+Let (\textbf{i},\textbf{j},\textbf{k}) be a set of orthogonal curvilinear coordinates on the sphere associated with the positively oriented orthogonal set of unit vectors (\textbf{i},\textbf{j},\textbf{k}) linked to the earth such that \textbf{k} is the local upward vector and (\textbf{i},\textbf{j}) are two vectors orthogonal to \textbf{k}, i.e. along geopotential surfaces (\ref{Fig_referential}). Let $(\lambda,\varphi,z)$ be the geographical coordinates system in which a position is defined by the latitude $\varphi(i,j)$, the longitude $\lambda(i,j)$ and the distance from the centre of the 
+earth $a+z(k)$ where $a$ is the earth's radius and $z$ the altitude above a reference sea level (\ref{Fig_referential}). The local deformation of the curvilinear coordinate system is given by $e_1$, $e_2$ and $e_3$, the three scale factors:
+\begin{equation} \label{Eq_scale_factors}
+\begin{aligned}
+ e_1 &=\left( {a+z} \right)\;\left[ {\left( {\frac{\partial \lambda 
+}{\partial i}\cos \varphi } \right)^2+\left( {\frac{\partial \varphi 
+}{\partial i}} \right)^2} \right]^{1/2} \\ 
+ e_2 &=\left( {a+z} \right)\;\left[ {\left( {\frac{\partial \lambda 
+}{\partial j}\cos \varphi } \right)^2+\left( {\frac{\partial \varphi 
+}{\partial j}} \right)^2} \right]^{1/2} \\ 
+ e_3 &=\left( {\frac{\partial z}{\partial k}} \right) \\ 
+ \end{aligned}
+ \end{equation}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!tb] \label{Fig_referential}  \begin{center}
+\includegraphics[width=0.60\textwidth]{./Figures/Fig_I_earth_referential.pdf}
+\caption{the geographical coordinate system $(\lambda,\varphi,z)$ and the curvilinear coordinate system (\textbf{i},\textbf{j},\textbf{k}). }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+Since the ocean depth is far smaller than the earth's radius, $a+z$, can be replaced by $a$ in (\ref{Eq_scale_factors}) (thin-shell approximation). The resulting horizontal scale factors $e_1$, $e_2$  are independent of $k$ while the vertical scale factor is a single function of $k$ as \textbf{k} is parallel to \textbf{z}. The scalar and vector operators that appear in the primitive equations (Eqs. \eqref{Eq_PE_dyn} to \eqref{Eq_PE_eos}) can be written in the tensorial form, invariant in any orthogonal horizontal curvilinear coordinate system transformation:
+\begin{subequations} \label{Eq_PE_discrete_operators}
+\begin{equation} \label{Eq_PE_grad}
+\nabla q=\frac{1}{e_1 }\frac{\partial q}{\partial i}\;{\rm {\bf 
+i}}+\frac{1}{e_2 }\frac{\partial q}{\partial j}\;{\rm {\bf j}}+\frac{1}{e_3 
+}\frac{\partial q}{\partial k}\;{\rm {\bf k}}    \\
+\end{equation}
+\begin{equation} \label{Eq_PE_div}
+\nabla \cdot {\rm {\bf A}} 
+= \frac{1}{e_1 \; e_2} \left[ 
+  \frac{\partial \left(e_2 \; a_1\right)}{\partial i }
++\frac{\partial \left(e_1 \; a_2\right)}{\partial j }    	\right]
++ \frac{1}{e_3} \left[ \frac{\partial a_3}{\partial k }   \right]
+\end{equation}
+\begin{equation} \label{Eq_PE_curl}
+   \begin{split}
+\nabla \times \vect{A} = 
+    \left[ {\frac{1}{e_2 }\frac{\partial a_3}{\partial j}
+            -\frac{1}{e_3 }\frac{\partial a_2 }{\partial k}} \right] \; \vect{i}
+&+\left[ {\frac{1}{e_3 }\frac{\partial a_1 }{\partial k}
+           -\frac{1}{e_1 }\frac{\partial a_3 }{\partial i}} \right] \; \vect{j} 		\\
+&+\frac{1}{e_1 e_2 } \left[ {\frac{\partial \left( {e_2 a_2 } \right)}{\partial i}
+                                       -\frac{\partial \left( {e_1 a_1 } \right)}{\partial j}} \right] \; \vect{k} 
+   \end{split}
+\end{equation}
+\begin{equation} \label{Eq_PE_lap}
+\Delta q = \nabla \cdot \left(  \nabla q \right)
+\end{equation}
+\begin{equation} \label{Eq_PE_lap_vector}
+\Delta {\rm {\bf A}} =
+  \nabla \left( \nabla \cdot {\rm {\bf A}} \right)
+- \nabla \times \left(  \nabla \times {\rm {\bf A}} \right)
+\end{equation}
+\end{subequations}
+where $q$ is a scalar quantity and ${\rm {\bf A}}=(a_1,a_2,a_3)$ a vector in 
+the $(i,j,k)$ coordinate system.
+
+% -------------------------------------------------------------------------------------------------------------
+% Continuous Model Equations
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Continuous Model Equations}
+\label{PE_zco_Eq}
+
+In order to express the primitive equations in tensorial formalism, it is necessary to compute the horizontal component of the non-linear and viscous terms of the equation using \eqref{Eq_PE_grad}) to \eqref{Eq_PE_lap_vector}. Let us set $\vect U=(u,v,w)={\vect{U}}_h +w\;\vect{k}$, the velocity in the $(i,j,k)$ coordinate system and define the relative vorticity $\zeta$ and the divergence of the horizontal velocity field $\chi$, by:
+\begin{equation} \label{Eq_PE_curl_Uh}
+\zeta =\frac{1}{e_1 e_2 }\left[ {\frac{\partial \left( {e_2 \,v} 
+\right)}{\partial i}-\frac{\partial \left( {e_1 \,u} \right)}{\partial j}} 
+\right]
+\end{equation}
+\begin{equation} \label{Eq_PE_div_Uh}
+\chi =\frac{1}{e_1 e_2 }\left[ {\frac{\partial \left( {e_2 \,u} 
+\right)}{\partial i}+\frac{\partial \left( {e_1 \,v} \right)}{\partial j}} 
+\right]
+\end{equation}
+
+Using the fact that horizontal scale factors $e_1$ and $e_2$ are independent of $k$ and that $e_3$  is a function of the single variable $k$, the nonlinear term of \eqref{Eq_PE_dyn} can be transformed as follows:
+\begin{flalign*}
+&\left[ {\left( {	\nabla \times {\rm {\bf U}}    } \right) \times {\rm {\bf U}}
++\frac{1}{2}	\nabla \left( {{\rm {\bf U}}^2} \right)}	 \right]_h 			&
+\end{flalign*}
+\begin{flalign*}
+&=\left( {{\begin{array}{*{20}c}
+ {\left[ 	{	 \frac{1}{e_3}	\frac{\partial u	}{\partial k}
+			-\frac{1}{e_1}	\frac{\partial w	}{\partial i} } \right] w - \zeta \; v } 	 	\\
+ 		{\zeta \; u - \left[ {	 \frac{1}{e_2} \frac{\partial w}{\partial j}
+							-\frac{1}{e_3} \frac{\partial v}{\partial k} } \right] \ w}	 \\
+		 \end{array} }} \right)			
++\frac{1}{2}	\left( {{\begin{array}{*{20}c}
+		 {	\frac{1}{e_1}	\frac{\partial \left( u^2+v^2+w^2 \right)}{\partial i}} 	\hfill	 \\
+		 {	\frac{1}{e_2}	\frac{\partial \left( u^2+v^2+w^2 \right)}{\partial j}} 	\hfill	 \\
+		 \end{array} }} \right)			&
+\end{flalign*}
+\begin{flalign*}
+&=\left( {{	\begin{array}{*{20}c}
+ {-\zeta \; v} \hfill \\
+ { \zeta \; u} \hfill \\
+			\end{array} }} \right)
++\frac{1}{2}\left( {{	\begin{array}{*{20}c}
+ {\frac{1}{e_1 }\frac{\partial \left( {u^2+v^2} \right)}{\partial i}} \hfill 	\\
+ {\frac{1}{e_2 }\frac{\partial \left( {u^2+v^2} \right)}{\partial j}} \hfill 	\\
+						\end{array} }} \right)			
++\frac{1}{e_3 }\left( {{		\begin{array}{*{20}c}
+ { w \; \frac{\partial u}{\partial k}} 	\\
+ { w \; \frac{\partial v}{\partial k}} 	\\
+							\end{array} }} \right)	
+-\left( {{	\begin{array}{*{20}c}
+ {\frac{w}{e_1}\frac{\partial w}{\partial i}
+ -\frac{1}{2e_1}\frac{\partial w^2}{\partial i}} \hfill \\
+ {\frac{w}{e_2}\frac{\partial w}{\partial j}
+  -\frac{1}{2e_2}\frac{\partial w^2}{\partial j}} \hfill \\
+			\end{array} }} \right) 			&
+\end{flalign*}
+
+The last term of the right hand side is obviously zero, and thus the nonlinear term of \eqref{Eq_PE_dyn} is written in the $(i,j,k)$ coordinate system:
+\begin{equation} \label{Eq_PE_vector_form}
+\left[ {\left( {	\nabla \times {\rm {\bf U}}    } \right) \times {\rm {\bf U}}
++\frac{1}{2}	\nabla \left( {{\rm {\bf U}}^2} \right)}	 \right]_h 
+=\zeta 
+\;{\rm {\bf k}}\times {\rm {\bf U}}_h +\frac{1}{2}\nabla _h \left( {{\rm 
+{\bf U}}_h^2 } \right)+\frac{1}{e_3 }w\frac{\partial {\rm {\bf U}}_h 
+}{\partial k}   	
+\end{equation}
+
+This is the so-called \textit{vector invariant form} of the momentum advection. For some purposes, it can be advantageous to write this term in the so-called flux form, i.e. to write it as the divergence of fluxes. For example, the first component of (\ref{Eq_PE_vector_form}) (the $i$-component) is transformed as follows:
+\begin{flalign*}
+&{	\begin{array}{*{20}l}
+\left[ {\left( {\nabla \times \vect{U}} \right)\times \vect{U}
+          +\frac{1}{2}\nabla \left( {\vect{U}}^2 \right)} \right]_i    \\
+\\
+     = - \zeta \;v 
+     + \frac{1}{2\;e_1 } \frac{\partial \left( {u^2+v^2} \right)}{\partial i}
+     + \frac{1}{e_3}w \ \frac{\partial u}{\partial k} 			\\
+\\
+=\frac{1}{e_1 \; e_2} \left( 	-v\frac{\partial \left( {e_2 \,v} \right)}{\partial i}
+							+v\frac{\partial \left( {e_1 \,u} \right)}{\partial j}	 \right)
++\frac{1}{e_1 e_2 }\left( 	+e_2 \; u\frac{\partial u}{\partial i}
+ 							+e_2 \; v\frac{\partial v}{\partial i}	  				 \right) 
++\frac{1}{e_3}       \left( 	w\;\frac{\partial u}{\partial k} 		\right)   \\
+\end{array} } 			&
+\end{flalign*}
+\begin{flalign*}
+&{	\begin{array}{*{20}l}
+=\frac{1}{e_1 \; e_2} 	\left\{ 
+ -\left(   	    v^2 	\frac{\partial e_2                                }{\partial i} 
+ 		+e_2 \,v		\frac{\partial v                                   }{\partial i}  	\right)
++\left( 				\frac{\partial \left( {e_1 \,u\,v} 	\right)}{\partial j}
+		-e_1 \,u		\frac{\partial v                                   }{\partial j} 	\right) 	\right. 
+\\  \left.	\qquad \qquad \quad
++\left( 				\frac{\partial \left( {e_2 u\,u}     \right)}{\partial i}
+		-u			\frac{\partial \left( {e_2 u}         \right)}{\partial i} 	\right)
++e_2 v		 		\frac{\partial v                                    }{\partial i}
+ 						\right\} 
++\frac{1}{e_3} \left(
+ 					\frac{\partial \left( {w\,v} \right)         }{\partial k}
+		 -u			\frac{\partial w 						   }{\partial k} 	\right) \\
+\end{array} } 		&
+\end{flalign*}
+\begin{flalign*}
+&{	\begin{array}{*{20}l}
+=\frac{1}{e_1 \; e_2} 	\left( 
+					\frac{\partial \left( {e_2 \,u\,u} \right)}{\partial i}
+		+			\frac{\partial \left( {e_1 \,u\,v} \right)}{\partial j}	\right)
++\frac{1}{e_3 }		\frac{\partial \left( {w\,v		 } \right)}{\partial k}
+\\  \qquad \qquad \quad
++\frac{1}{e_1 e_2 }		\left( 
+ 		-u	\left( 	\frac{\partial \left( {e_1 v	 } \right)}{\partial j}
+	 				-v\,\frac{\partial e_1 }{\partial j}				 \right)
+		-u			\frac{\partial \left( {e_2 u	 } \right)}{\partial i}
+						\right)
+ -\frac{1}{e_3 }	 	\frac{\partial w}{\partial k}	u
+ +\frac{1}{e_1 e_2 }\left( 	-v^2\frac{\partial e_2	 }{\partial i}		 \right)	
+\end{array} } 		&
+\end{flalign*}
+\begin{flalign*}
+&{	\begin{array}{*{20}l}
+= \nabla \cdot \left( {{\rm {\bf U}}\,u}	\right)
+-  \nabla \cdot {\rm {\bf U}} \ u
++\frac{1}{e_1 e_2 }\left( 
+		-v^2		\frac{\partial e_2 }{\partial i}
+		+uv	\,		\frac{\partial e_1 }{\partial j} 	\right) \\
+\end{array} } 		&
+\end{flalign*}
+as $\nabla \cdot {\rm {\bf U}}\;=0$ (incompressibility) it comes:
+\begin{flalign*}
+&{	\begin{array}{*{20}l}
+= \nabla \cdot \left( 	{{\rm {\bf U}}\,u}		\right)
++	\frac{1}{e_1 e_2 }   \left( v \; \frac{\partial e_2}{\partial i}
+						       -u \; \frac{\partial e_1}{\partial j} 	\right)  \left( -v \right)	
+\end{array} } 		&
+\end{flalign*}
+
+The flux form of the momentum advection is therefore given by:
+\begin{multline} \label{Eq_PE_flux_form}
+		\left[ 
+  \left( 	{\nabla \times {\rm {\bf U}}} 	\right) \times {\rm {\bf U}}
++\frac{1}{2}	\nabla \left( 	{{\rm {\bf U}}^2} 	\right)
+		\right]_h 
+=	\nabla \cdot 	\left( {{\begin{array}{*{20}c}	{\rm {\bf U}} \, u 	\hfill \\
+												{\rm {\bf U}} \, v	\hfill \\
+						\end{array} }} 	
+				\right)
+\\
++\frac{1}{e_1 e_2 }		\left( 
+		 v\frac{\partial e_2}{\partial i}
+		-u\frac{\partial e_1}{\partial j} 
+						\right) {\rm {\bf k}} \times {\rm {\bf U}}_h
+\end{multline}
+
+The flux form has two terms, the first one is expressed as the divergence of momentum fluxes (so the flux form name given to this formulation) and the second one is due to the curvilinear nature of the coordinate system used. The latter is called the \emph{metric} term and can be viewed as a modification of the Coriolis parameter: 
+\begin{equation} \label{Eq_PE_cor+metric}
+f \to f + \frac{1}{e_1 \; e_2}	\left( 	 v \frac{\partial e_2}{\partial i}
+										-u \frac{\partial e_1}{\partial j} 	\right)
+\end{equation}
+
+Note that in the case of geographical coordinate, i.e. when $(i,j) \to (\lambda ,\varphi )$ and $(e_1 ,e_2) \to (a \,\cos \varphi ,a)$, we recover the commonly used modification of the Coriolis parameter $f \to f+(u/a) \tan \varphi$.
+
+The equations solved by the ocean model can be written in the following tensorial formalism:
+
+$\bullet$ vector invariant form of the momentum equations :
+\begin{subequations} \label{Eq_PE_dyn_vect}
+\begin{equation} \label{Eq_PE_dyn_vect_u}
+\frac{\partial u}{\partial t}=
++   \left( {\zeta +f} \right)\,v   -   \frac{1}{e_3 }w\frac{\partial u}{\partial k}
+-   \frac{1}{e_1 }\frac{\partial}{\partial i}\left( 
+		{\frac{1}{2}\left( {u^2+v^2} \right)+\frac{p_h+p_s }{\rho _o }}    \right)
++   D_u^{\vect{U}} 
+\end{equation}
+\begin{equation} \label{Eq_PE_dyn_vect_v}
+\frac{\partial v}{\partial t}=
+-   \left( {\zeta +f} \right)\,u   -   \frac{1}{e_3 }w\frac{\partial v}{\partial k}
+-   \frac{1}{e_2 }\frac{\partial }{\partial j}\left( 
+		{\frac{1}{2}\left( {u^2+v^2} \right)+\frac{p_h+p_s }{\rho _o }}    \right)
++  D_v^{\vect{U}} 
+\end{equation}
+\end{subequations}
+
+where $\zeta$ is given by (\ref{Eq_PE_curl_Uh}) and the surface pressure gradient is given by:
+
+$*$ free surface formulation
+\begin{equation}\label{Eq_PE_dyn_sco}
+\frac{1}{\rho _o }\nabla _h p_s =\left( {{\begin{array}{*{20}c}
+ {\frac{g}{\;e_1 }\frac{\partial \eta }{\partial i}} \hfill \\
+ {\frac{g}{\;e_2 }\frac{\partial \eta }{\partial j}} \hfill \\
+\end{array} }} \right)
+\qquad \text{where $\eta$ is solution of \eqref{Eq_PE_ssh} }
+\end{equation}
+
+$*$ rigid-lid approximation
+\begin{equation}\label{Eq_PE_dyn_zco}
+\frac{1}{\rho _o }\nabla _h p_s =\left( {{\begin{array}{*{20}c}
+ {\overline M _u +\frac{1}{H\;e_2 }\frac{\partial }{\partial j}\left( 
+{\frac{\partial \psi }{\partial t}} \right)}		 \\
+ {\overline M _v -\frac{1}{H\;e_1 }\frac{\partial }{\partial i}\left( 
+{\frac{\partial \psi }{\partial t}} \right)} 		 \\
+\end{array} }} \right)
+\end{equation}
+where ${\vect{M}}= \left( M_u,M_v \right)$ represents the collected contributions of nonlinear, 
+viscous and hydrostatic pressure gradient terms in \eqref{Eq_PE_dyn_vect} and the overbar indicates a vertical average over the whole water column ($i.e.$ from $z=-H$, the ocean bottom, to $z=0$, the rigid-lid), and where the time derivative of $\psi$ is the solution of an elliptic equation:
+\begin{multline} \label{Eq_psi_total}
+  \frac{\partial }{\partial i}\left[ {\frac{e_2 }{H\,e_1}\frac{\partial}{\partial i}
+								 \left( {\frac{\partial \psi }{\partial t}} \right)}   \right]
++\frac{\partial }{\partial j}\left[ {\frac{e_1 }{H\,e_2}\frac{\partial }{\partial j}
+								 \left( {\frac{\partial \psi }{\partial t}} \right)} \right]
+= \\
+  \frac{\partial }{\partial i}\left( {e_2 \overline M _v } \right)
+- \frac{\partial }{\partial j}\left( {e_1 \overline M _u } \right)
+\end{multline}
+
+The vertical velocity and the hydrostatic pressure are diagnosed from the following equations:
+\begin{equation} \label{Eq_w_diag}
+\frac{\partial w}{\partial k}=-\chi \;e_3 
+\end{equation}
+\begin{equation} \label{Eq_hp_diag}
+\frac{\partial p_h }{\partial k}=-\rho \;g\;e_3 
+\end{equation}
+
+where the divergence of the horizontal velocity, $\chi$ is given by (I.3.8).
+
+$\bullet$ tracer equations:
+\begin{equation} \label{Eq_S}
+\frac{\partial T}{\partial t}=-\frac{1}{e_1 e_2 }\left[ {\frac{\partial 
+\left( {e_2 T\,u} \right)}{\partial i}+\frac{\partial \left( {e_1 T\,v} 
+\right)}{\partial j}} \right]-\frac{1}{e_3 }\frac{\partial \left( {T\,w} 
+\right)}{\partial k}+D^T
+\end{equation}
+\begin{equation} \label{Eq_T}
+\frac{\partial S}{\partial t}=-\frac{1}{e_1 e_2 }\left[ {\frac{\partial 
+\left( {e_2 S\,u} \right)}{\partial i}+\frac{\partial \left( {e_1 S\,v} 
+\right)}{\partial j}} \right]-\frac{1}{e_3 }\frac{\partial \left( {S\,w} 
+\right)}{\partial k}+D^S
+\end{equation}
+\begin{equation} \label{Eq_rho}
+\rho =\rho \left( {T,S,z(k)} \right)
+\end{equation}
+
+The expression of \textbf{D}$^{U}$, $D^{S}$ and$ D^{T}$ depends on the subgrid 
+scale parameterization used. It will be defined in \S\ref{PE_zdf}.
+
+\newpage 
+% ================================================================
+% Curvilinear s-coordinate System
+% ================================================================
+\section{Curvilinear \textit{s}-coordinate System}
+\label{PE_sco}
+
+% -------------------------------------------------------------------------------------------------------------
+% Introduction
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Introduction}
+
+Several important aspects of the ocean circulation are influenced by bottom topography. Of course, the most important is that bottom topography determines deep ocean sub-basins, barriers, sills and channels that strongly constrain the path of water masses, but more subtle effects exist. For 
+example, the topographic $\beta$-effect is usually larger than the planetary one along continental slopes. Topographic Rossby waves can be excited and can interact with the mean current. In the $z-$coordinate system presented in the previous section (\S\ref{PE_zco}), $z-$surfaces are geopotential surfaces. The bottom topography is discretised by steps. This often leads to a misrepresentation of a gradually sloping bottom and to large localized depth gradients associated with large localized vertical velocities. The response to such a velocity field often leads to numerical dispersion effects.
+
+A terrain-following coordinate system (hereafter $s-$coordinates) avoids the discretisation error in the depth field since the layers of computation are gradually adjusted with depth to the ocean bottom. Relatively shallow topographic features in the deep ocean, which would be ignored in typical $z-$model applications with the largest grid spacing at greatest depths, can easily be represented (with relatively low vertical resolution) as can gentle, large-scale slopes of the sea floor. A terrain-following model (hereafter $s-$model) also facilitates the modelling of the boundary layer flows over a large depth range, which in the framework of the $z-$model would require high vertical resolution over the whole depth range. Moreover, with $s-$coordinates it is possible, at least in principle, to have the bottom and the sea surface as the only boundaries of the domain. Nevertheless, $s-$coordinates also have its drawbacks. Perfectly adapted to a homogeneous ocean, it has strong limitations as soon as stratification is introduced. The main two problems come from the truncation error in the horizontal pressure gradient and a possibly increased diapycnal diffusion. The horizontal pressure force in $s-$coordinates consists of two terms (see \colorbox{yellow}{Appendix A}),
+
+\begin{equation} \label{Eq_PE_p_sco}
+\left. {\nabla p} \right|_z =\left. {\nabla p} \right|_s -\frac{\partial 
+p}{\partial s}\left. {\nabla z} \right|_s 
+\end{equation}
+
+The second term in (\ref{Eq_PE_p_sco}) depends on the tilt of the coordinate surface and 
+introduces a truncation error that is not present in a $z-$model. In the special case of $\sigma-$coordinate (i.e. a depth-normalised coordinate system $\sigma = z/H$), \cite{Haney1991} and \citet{Beckmann1993} have given estimates of the magnitude of this truncation error. It depends on topographic slope, stratification, horizontal and vertical resolution, and the finite difference scheme. This error limits the possible topographic slopes that a model can handle at a given horizontal and vertical resolution. This is a severe restriction for large-scale applications using realistic bottom topography. The large-scale slopes require high horizontal resolution, and the computational cost becomes prohibitive. This problem can be, at least partially, overcome by mixing $s-$coordinates and step-like representation of bottom topography \citep{Madec1996}. However, another problem is then raised in the definition of the model domain. 
+
+\colorbox{yellow}{Aike Beckmann's solution}
+
+A minimum of diffusion along the coordinate surfaces of any finite difference model is always required for numerical reasons. It causes spurious diapycnal mixing when coordinate surfaces do not coincide with isoneutral surfaces. This is the case for a $z-$model as well as for a $s-$model. 
+However, density varies more strongly on $s-$surfaces than on horizontal surfaces in regions of large topographic slopes, implying larger diapycnal diffusion in a $s-$model than in a $z-$model. Whereas such a diapycnal diffusion in a $z-$model tends to weaken horizontal density (pressure) gradients and thus the horizontal circulation, it usually reinforces these gradients in a $s-$model, creating spurious circulation. For example, imagine an isolated bump of topography in an ocean at rest with a horizontally uniform stratification. Spurious diffusion along $s-$surfaces will induce a bump of isoneutral surfaces over the topography, and thus will generate there a baroclinic eddy. In contrast, the ocean will stay at rest in a $z-$model. As for the truncation error, the problem can be reduced by introducing the terrain-following coordinate below the strongly stratified portion of the 
+water column (i.e. the main thermocline) \citep{Madec1996}. An alternate solution consists in rotating the lateral diffusive tensor to geopotential or to isoneutral surfaces (see \S\ref{PE_zdf} and \colorbox{yellow}{Appendix B}.
+
+%AMT
+\amtcomment{ 
+The $s-$coordinates introduced here \citep{Lott1990,Madec1996} 
+\colorbox{yellow}{ to be update $==>$}
+differ mainly in two aspects from 
+similar models. It combines the properties which make OPA suitable for 
+climate applications with a good representation of bottom topography 
+allowing mixed step-like/terrain following topography. It also offers a 
+completely general transformation, $s=s(i,j,z)$, for the vertical coordinate which goes beyond those of previous hybrid models except the GFDL version developed by \citep{Gerdes1993a,Gerdes1993b} 
+which has similar properties as the OPA release presented here.
+\colorbox{yellow}{ <== end update}
+}
+% -------------------------------------------------------------------------------------------------------------
+% The s-coordinate Formulation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{The \textit{s-}coordinate Formulation}
+
+Starting from the set of equations established in \S\ref{PE_zco} for the special case $k=z$ and thus $e_3=1$, we introduce an arbitrary vertical coordinate $s=s(i,j,k)$, which includes $z-$ and $\sigma-$coordinates as special cases ($s=z$ and $s=\sigma=z/H$, resp.). A formal derivation of the transformed equations is given in \colorbox{yellow}{Appendix A}. Let us define the vertical scale factor by $e_3=\partial_s z$  ($e_3$ is now a function of $(i,j,k)$ ), and the slopes in the (\textbf{i},\textbf{j}) directions between $s-$ and $z-$surfaces by :
+\begin{equation} \label{Eq_PE_sco_slope}
+\sigma _1 =\frac{1}{e_1 }\;\left. {\frac{\partial z}{\partial i}} \right|_s 
+\quad \text{, and } \quad 
+\sigma _2 =\frac{1}{e_2 }\;\left. {\frac{\partial z}{\partial j}} \right|_s
+\end{equation}
+
+We also introduce a "vertical" velocity $\omega$ defined as the velocity normal to $s-$surfaces:
+\begin{equation} \label{Eq_PE_sco_w}
+\omega = w - \sigma_1 \; u - \sigma_2 \; v
+\end{equation}
+The equations solved by the ocean model \eqref{Eq_PE} in $s-$coordinates can be written as follows:
+
+* momentum equation:
+\begin{multline} \label{Eq_PE_sco_u}
+\frac{\partial u}{\partial t}=+\left( {\zeta +f} \right)\,v-\frac{1}{e_3 
+}\omega \frac{\partial u}{\partial k}-\frac{1}{e_1 }\frac{\partial 
+}{\partial i}\left( {\frac{1}{2}\left( {u^2+v^2} \right)+\frac{p_h }{\rho _o}} \right)   \\
++g\frac{\rho }{\rho _o }\sigma _1 -\frac{1}{\rho _o e_1 
+}\frac{\partial p_s }{\partial i}+D_u^{\rm {\bf U}} 
+\end{multline}
+\begin{multline} \label{Eq_PE_sco_v}
+\frac{\partial v}{\partial t}=-\left( {\zeta +f} \right)\,u-\frac{1}{e_3 
+}\omega \frac{\partial v}{\partial k}-\frac{1}{e_2 }\frac{\partial 
+}{\partial j}\left( {\frac{1}{2}\left( {u^2+v^2} \right)+\frac{p_h }{\rho _o}} \right)   \\
++g\frac{\rho }{\rho _o }\sigma _2 -\frac{1}{\rho _o e_2 
+}\frac{\partial p_s }{\partial j}+D_v^{\rm {\bf U}} 
+\end{multline}
+where the relative vorticity, \textit{$\zeta $}, the surface pressure gradient, and the hydrostatic pressure have the same expressions as in $z-$coordinates although they do not represent exactly the same quantities. $\omega $ is provided by the same equation as w, i.e. (\ref{Eq_w_diag}), with $\chi$, the divergence of the horizontal velocity field given by:
+
+\begin{equation} \label{Eq_PE_sco_div}
+\chi =\frac{1}{e_1 e_2 e_3 }\left[ {\frac{\partial \left( {e_2 e_3 \,u} 
+\right)}{\partial i}+\frac{\partial \left( {e_1 e_3 \,v} \right)}{\partial 
+j}} \right]
+\end{equation}
+
+* tracer equations:
+
+\begin{equation} \label{Eq_PE_sco_t}
+\frac{\partial T}{\partial t}=-\frac{1}{e_1 e_2 e_3 }\left[ {\frac{\partial 
+\left( {e_2 e_3 T\,u} \right)}{\partial i}+\frac{\partial \left( {e_1 e_3 
+T\,v} \right)}{\partial j}} \right]-\frac{1}{e_3 }\frac{\partial \left( 
+{T\,\omega } \right)}{\partial k}+D^T
+\end{equation}
+
+\begin{equation} \label{Eq_PE_sco_s}
+\frac{\partial S}{\partial t}=-\frac{1}{e_1 e_2 e_3 }\left[ {\frac{\partial 
+\left( {e_2 e_3 S\,u} \right)}{\partial i}+\frac{\partial \left( {e_1 e_3 
+S\,v} \right)}{\partial j}} \right]-\frac{1}{e_3 }\frac{\partial \left( 
+{S\,\omega } \right)}{\partial k}+D^S
+\end{equation}
+
+The equation of state has the same expression as in $z-$coordinates. The expression of \textbf{D}$^{U}$, $D^{S}$ and$ D^{T}$ depends on the subgrid scale parameterization used. It will be defined in \S\ref{PE_zdf_ldf}. 
+
+\colorbox{yellow}{ to be updated $= = >$}
+The whole set of the continuous equations solved by the model in the $s-$coordinate system is summarised in Table~I.2. 
+
+Add a few works on z and zps and s and underlies the differences between all of them
+\colorbox{yellow}{ $< = =$ end update}
+
+\newpage 
+% ================================================================
+% Curvilinear z*- s*-coordinate System
+% ================================================================
+\section{Curvilinear \textit{z*}- or \textit{s*} coordinate System}
+
+% -------------------------------------------------------------------------------------------------------------
+% ????
+% -------------------------------------------------------------------------------------------------------------
+
+\colorbox{yellow}{ to be updated $= = >$}
+
+In that case, the free surface equation is nonlinear, and the variations of 
+volume are fully taken into account. These coordinates systems is presented in a report 
+\citep{Levier2007} available on the \NEMO web site. 
+
+\colorbox{yellow}{ $< = =$ end update}
+
+\newpage 
+% ================================================================
+% Subgrid Scale Physics
+% ================================================================
+\section{Subgrid Scale Physics}
+\label{PE_zdf_ldf}
+
+The primitive equations describe the behaviour of a geophysical fluid at 
+space and time scales larger than a few kilometres in the horizontal, a few 
+meters in the vertical and a few minutes. They are usually solved at larger 
+scales, the specified grid spacing and time step of the numerical model. The 
+effects of smaller scale motions (coming from the advective terms in the 
+Navier-Stokes equations) must be represented entirely in terms of 
+large-scale patterns to close the equations. These effects appear in the 
+equations as the divergence of turbulent fluxes (i.e. fluxes associated with 
+the mean correlation of small scale perturbations). Assuming a turbulent 
+closure hypothesis is equivalent to choose a formulation for these fluxes. 
+It is usually called the subgrid scale physics. It must be emphasized that 
+this is the weakest part of the primitive equations, but also one of the 
+most important for long-term simulations as small scale processes \textit{in fine} balance 
+the surface input of kinetic energy and heat.
+
+The control exerted by gravity on the flow induces a strong anisotropy 
+between the lateral and vertical motions. Therefore subgrid-scale physics  \textbf{D}$^{\vect{U}}$, $D^{S}$ and $D^{T}$  in \eqref{Eq_PE_dyn}, \eqref{Eq_PE_tra_T} and \eqref{Eq_PE_tra_S} are divided into a lateral part  \textbf{D}$^{l \vect{U}}$, $D^{lS}$ and $D^{lT}$ and a vertical part  \textbf{D}$^{vU}$, $D^{vS}$ and $D^{vT}$ . The formulation of these terms and their underlying physics are briefly discussed in the next two subsections.
+
+% -------------------------------------------------------------------------------------------------------------
+% Vertical Subgrid Scale Physics
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Vertical Subgrid Scale Physics}
+\label{PE_zdf}
+
+The model resolution is always larger than the scale at which the major 
+sources of vertical turbulence occurs (shear instability, internal wave 
+breaking...). Turbulent motions are thus never explicitly solved, even 
+partially, but always parameterized. The vertical turbulent fluxes are 
+assumed to depend linearly on the gradients of large-scale quantities (for 
+example, the turbulent heat flux is given by $\overline{T'w'}=-A^{vT} \partial_z \overline T$, where $A^{vT}$ is an eddy coefficient). This formulation is 
+analogous to that of molecular diffusion and dissipation. This is quite 
+clearly a necessary compromise: considering only the molecular viscosity 
+acting on large scale severely underestimates the role of turbulent 
+diffusion and dissipation, while an accurate consideration of the details of 
+turbulent motions is simply impractical. The resulting vertical momentum and 
+tracer diffusive operators are of second order:
+\begin{equation} \label{Eq_PE_zdf}
+   \begin{split}
+{\vect{D}}^{v \vect{U}}
+&=\frac{\partial }{\partial z}\left( {A^{vm}\frac{\partial {\vect{U}}_h }{\partial z}} \right) \ , \\         D^{vT} &= \frac{\partial }{\partial z}\left( {A^{vT}\frac{\partial T}{\partial z}} \right) \ ,
+\quad
+D^{vS}=\frac{\partial }{\partial z}\left( {A^{vT}\frac{\partial S}{\partial z}} \right)
+   \end{split}
+\end{equation}
+where $A^{vm}$ and $A^{vT}$ are the vertical eddy viscosity and diffusivity coefficients, respectively. At the sea surface and at the bottom, turbulent fluxes of momentum, heat and salt must 
+be specified (see Chap.~\ref{SBC}). All the vertical physics is embedded in the specification of the eddy coefficients. They can be assumed to be either constant, or function of the local fluid properties (as Richardson number, Brunt-Vais\"{a}l\"{a} frequency...), or computed from a turbulent closure model. The choices available in OPA are discussed in \S\ref{ZDF}).
+
+% -------------------------------------------------------------------------------------------------------------
+% Lateral Diffusive and Viscous Operators Formulation
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Lateral Diffusive and Viscous Operators Formulation}
+\label{PE_ldf}
+
+Lateral turbulence can be roughly divided into a mesoscale turbulence 
+associated to eddies which can be solved explicitly if the resolution is 
+sufficient as their underlying physics are included in the primitive 
+equations, and a sub mesoscale turbulence which is never explicitly solved 
+even partially, but always parameterized. The formulation of lateral eddy 
+fluxes depends on whether the mesoscale is below or above the grid-spacing 
+(i.e. the model is eddy-resolving or not).
+
+In non-eddy- resolving configurations, the closure is similar to that used 
+for the vertical physics. The lateral turbulent fluxes are assumed to depend 
+linearly on the lateral gradients of large-scale quantities. The resulting 
+lateral diffusive and dissipative operators are of second order. 
+Observations show that lateral mixing induced by mesoscale turbulence tends 
+to be along isoneutral surfaces (or more precisely neutral surfaces, i.e. 
+isoneutral surfaces referenced at the local depth) rather than across them. 
+As the slope of isoneutral surfaces is small in the ocean, a common 
+approximation is to assume that the `lateral' direction is the horizontal, 
+i.e. the lateral mixing is performed along geopotential surfaces. This leads 
+to a geopotential second order operator for lateral subgrid scale physics. 
+This assumption can be relaxed: the eddy-induced turbulent fluxes can be 
+better approached by assuming that they depend linearly on the gradients of 
+large-scale quantities computed along isoneutral surfaces. In such a case, 
+the diffusive operator is an isoneutral second order operator and it has 
+components in the three space directions. However, both horizontal and 
+isoneutral operators have no effect on mean (i.e. large scale) potential 
+energy whereas potential energy is a main source of turbulence (through 
+baroclinic instabilities). \citet{Gent1990} have proposed a 
+parameterization of mesoscale eddy-induced turbulence which associates an 
+eddy-induced velocity to the isoneutral diffusion. Its mean effect is to 
+reduce the mean potential energy of the ocean. This leads to a formulation 
+of lateral subgrid-scale physics made up of an isoneutral second order 
+operator and an eddy induced advective part. In all these lateral diffusive 
+formulations, the specification of the lateral eddy coefficients remains the 
+problematic point as there is no satisfactory formulation of these 
+coefficients as a function of large-scale features.
+
+In eddy-resolving configurations, a second order operator can be used, but 
+usually a more scale selective one (biharmonic operator) is preferred as the 
+grid-spacing is usually not small enough compared to the scale of the 
+eddies. The role devoted to the subgrid-scale physics is to dissipate the 
+energy that cascades toward the grid scale and thus ensures the stability of 
+the model while not interfering with the solved mesoscale activity.
+
+All these parameterizations of subgrid scale physics present advantages and 
+disadvantages. There are not all available in OPA. In the $z-$coordinate 
+formulation, four options are offered for active tracers (temperature and 
+salinity): second order geopotential operator, second order isoneutral 
+operator, \citet{Gent1990} parameterization and fourth order 
+geopotential operator. The same options are available for momentum, except 
+\citet{Gent1990} parameterization which only involves tracers. In 
+$s-$coordinate formulation, an additional option is offered for tracers: second 
+order operator acting along $s-$surfaces, and for momentum: fourth order 
+operator acting along $s-$surfaces (see \S\ref{LDF}).
+
+\subsubsection{lateral second order tracer diffusive operator}
+
+The lateral second order tracer diffusive operator is defined by (see \colorbox{yellow}{Appendix B}):
+\begin{equation} \label{Eq_PE_iso_tensor}
+D^{lT}=\nabla {\rm {\bf .}}\left( {A^{lT}\;\Re \;\nabla T} \right) \qquad 
+\mbox{with}\quad \;\;\Re =\left( {{\begin{array}{*{20}c}
+ 1 \hfill & 0 \hfill & {-r_1 } \hfill \\
+ 0 \hfill & 1 \hfill & {-r_2 } \hfill \\
+ {-r_1 } \hfill & {-r_2 } \hfill & {r_1 ^2+r_2 ^2} \hfill \\
+\end{array} }} \right)
+\end{equation}
+where $r_1 \;\mbox{and}\;r_2 $ are the slopes between the surface along 
+which the diffusive operator acts and the surface of computation ($z-$ or 
+$s-$surfaces), and $r_1$ and $r_2$ is the differential operator defined 
+in \S\ref{PE_zco} or \S\ref{PE_sco} depending on the vertical coordinate used. Note that the formulation of $r_1$ and $r_2 $ is exact for the 
+slopes between geopotential and $s-$surfaces, while it is only an approximation 
+for the slopes between isoneutral and $z$ or $s-$surfaces. Indeed, in the latter 
+case, two assumptions are made to simplify $r_1$ and $r_2$ \citep{Cox1987}: the ratio between lateral and vertical diffusive coefficients is 
+known to be several orders of magnitude smaller than unity, and the slopes 
+are, generally less than $10^{2}$ in the ocean (see \colorbox{yellow}{Appendix B}). This leads to 
+the linear tensor (\ref{Eq_PE_iso_tensor}) where the two isoneutral directions of diffusion 
+are independent and where the diapycnal diffusivity contribution is solely along the vertical.
+
+For \textit{geopotential} diffusion, $r_1$ and $r_2 $ are the slopes between the 
+geopotential and computational surfaces: in $z$-coordinates they are zero ($r_1$ and $r_2)$ while in $s-$coordinate they are equal to $\sigma _1$ and $\sigma _2$, respectively (see \eqref{Eq_PE_sco_slope} ).
+
+For \textit{isoneutral} diffusion $r_1$ and $r_2$ are the slopes between the isoneutral and computational surfaces. Therefore, they have a same expression in $z-$and $s-$coor-dinates:
+\begin{equation} \label{Eq_PE_iso_slopes}
+r_1 =\frac{e_3 }{e_1 }	\left( {\frac{\partial \rho }{\partial i}} \right)
+						\left( {\frac{\partial \rho }{\partial k}} \right)^{-1} \ , \quad
+r_1 =\frac{e_3 }{e_1 }	\left( {\frac{\partial \rho }{\partial i}} \right)
+						\left( {\frac{\partial \rho }{\partial k}} \right)^{-1}
+\end{equation}
+
+When the \textit{Eddy Induced Velocity} parametrisation (eiv) \citep{Gent1990} is used, an additional tracer advection is introduced in combination with the isoneutral diffusion of tracers:
+\begin{equation} \label{Eq_PE_iso+eiv}
+D^{lT}=\nabla \cdot \left( {A^{lT}\;\Re \;\nabla T} \right)
+           +\nabla \cdot \left( {{\vect{U}}^\ast \,T} \right)
+\end{equation}
+where ${\vect{U}}^\ast =\left( {u^\ast ,v^\ast ,w^\ast } \right)$ is a non-divergent, eddy-induced transport velocity. This velocity field is defined by:
+\begin{equation} \label{Eq_PE_eiv}
+   \begin{split}
+ u^\ast  &= +\frac{1}{e_3       }\frac{\partial }{\partial k}\left[ {A^{eiv}\;\tilde{r}_1 } \right] \\ 
+ v^\ast  &= +\frac{1}{e_3       }\frac{\partial }{\partial k}\left[ {A^{eiv}\;\tilde{r}_2 } \right] \\ 
+ w^\ast &=  -\frac{1}{e_1 e_2 }\left[ 
+                      \frac{\partial }{\partial i}\left( {A^{eiv}\;e_2\,\tilde{r}_1 } \right)
+                    +\frac{\partial }{\partial j}\left( {A^{eiv}\;e_1\,\tilde{r}_2 } \right)      \right]
+   \end{split}
+\end{equation}
+where $A^{eiv}$ is the eddy induced velocity coefficient (or equivalently the isoneutral thickness diffusivity coefficient), and $\tilde{r}_1$ and $\tilde{r}_2$ are the slopes between isoneutral and \emph{geopotential} surfaces and thus depends on the coordinate considered: 
+\begin{align} \label{Eq_PE_slopes_eiv}
+\tilde{r}_n = \begin{cases}
+   r_n                  &      \text{in $z-$coordinate}    \\
+   r_n + \sigma_n &      \text{in $s-$coordinate}  
+                   \end{cases}
+\quad \text{where } n=1,2
+\end{align}
+
+The normal component of the eddy induced velocity is zero at all the boundaries. this can be achieved by tapering either the eddy coefficient or the slopes to zero in the vicinity of the boundaries. 
+
+\subsubsection{lateral fourth order tracer diffusive operator}
+
+The lateral fourth order tracer diffusive operator is defined by:
+\begin{equation} \label{Eq_PE_bilapT}
+D^{lT}=\Delta \left( {A^{lT}\;\Delta T} \right) 
+\qquad \text{where} \  D^{lT}=\Delta \left( {A^{lT}\;\Delta T} \right)
+ \end{equation}
+
+It is the second order operator given by (\ref{Eq_PE_iso_tensor}) applied twice with the eddy 
+diffusion coefficient correctly placed. 
+
+\subsubsection{lateral second order momentum diffusive operator}
+
+The second order momentum diffusive operator along $z-$ or $s-$surfaces is found by 
+applying \eqref{Eq_PE_curl} to the horizontal velocity vector (see Appendix B):
+\begin{equation} \label{Eq_PE_lapU}
+\begin{split}
+{\rm {\bf D}}^{l{\rm {\bf U}}} 
+&= \quad \  \nabla _h \left( {A^{lm}\chi } \right)
+   \ - \ \nabla _h \times \left( {A^{lm}\,\zeta \;{\rm {\bf k}}} \right)     \\
+&=   \left(      \begin{aligned}
+             \frac{1}{e_1      } \frac{\partial \left( A^{lm} \chi          \right)}{\partial i} 
+         &-\frac{1}{e_2 e_3}\frac{\partial \left( {A^{lm} \;e_3 \zeta} \right)}{\partial j}  \\
+             \frac{1}{e_2      }\frac{\partial \left( {A^{lm} \chi         } \right)}{\partial j}   
+         &+\frac{1}{e_1 e_3}\frac{\partial \left( {A^{lm} \;e_3 \zeta} \right)}{\partial i}
+        \end{aligned}    \right)
+\end{split}
+\end{equation}
+
+Such a formulation ensures a complete separation between the vorticity and 
+horizontal divergence fields ({\S}~II.4c). Unfortunately, it is not 
+available for geopotential diffusion in $s-$coordinates and for isoneutral 
+diffusion. In these two cases, the $u$ and $v-$fields are considered as independent 
+scalar fields, so that the diffusive operator is given by:
+\begin{equation} \label{Eq_PE_lapU_iso}
+\begin{split}
+ D_u^{l{\rm {\bf U}}} &= \nabla .\left( {\Re \;\nabla u} \right) \\ 
+ D_v^{l{\rm {\bf U}}} &= \nabla .\left( {\Re \;\nabla v} \right)
+ \end{split}
+ \end{equation}
+where $\Re$ is given by (I.5.2). It is the same expression as those used 
+for diffusive operator on tracers.
+
+\subsubsection{lateral fourth order momentum diffusive operator}
+
+As for tracers, the fourth order momentum diffusive operator along $z$ or $s-$surfaces is a re-entering second order operator \eqref{Eq_PE_lapU} or \eqref{Eq_PE_lapU} with the eddy viscosity coefficient correctly placed:
+
+geopotential diffusion in $z-$coordinates:
+\begin{equation} \label{Eq_PE_bilapU}
+\begin{split}
+{\rm {\bf D}}^{l{\rm {\bf U}}} &=\nabla _h \left\{ {\;\nabla _h {\rm {\bf 
+.}}\left[ {A^{lm}\,\nabla _h \left( \chi \right)} \right]\;} 
+\right\}\;   \\
+&+\nabla _h \times \left\{ {\;{\rm {\bf k}}\cdot \nabla \times 
+\left[ {A^{lm}\,\nabla _h \times \left( {\zeta \;{\rm {\bf k}}} \right)} 
+\right]\;} \right\}
+\end{split}
+\end{equation}
+
+geopotential diffusion in $s-$coordinates:
+\begin{equation} \label{Eq_bilapU_iso}
+   \left\{   \begin{aligned}
+         D_u^{l{\rm {\bf U}}} =\Delta \left( {A^{lm}\;\Delta u} \right) \\ 
+         D_v^{l{\rm {\bf U}}} =\Delta \left( {A^{lm}\;\Delta v} \right)
+   \end{aligned}    \right.
+   \quad \text{where} \quad 
+   \Delta \left( \bullet \right) = \nabla \cdot \left( \Re \nabla(\bullet) \right) 
+\end{equation}
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics_zstar.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics_zstar.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_Model_Basics_zstar.tex	(revision 4536)
@@ -0,0 +1,243 @@
+% ================================================================
+% Chapter 1 Ñ Model Basics
+% ================================================================
+% ================================================================
+% Curvilinear z*- s*-coordinate System
+% ================================================================
+\chapter{ essai z* s*}
+\section{Curvilinear \textit{z*}- or \textit{s*} coordinate System}
+
+% -------------------------------------------------------------------------------------------------------------
+% ????
+% -------------------------------------------------------------------------------------------------------------
+
+\colorbox{yellow}{ to be updated }
+
+In that case, the free surface equation is nonlinear, and the variations of 
+volume are fully taken into account. These coordinates systems is presented in a report 
+\citep{Levier2007} available on the \NEMO web site. 
+
+\colorbox{yellow}{  end of to be updated}
+\newline
+
+% from MOM4p1 documentation
+
+To overcome problems with vanishing surface and/or bottom cells, we consider the 
+zstar coordinate 
+\begin{equation} \label{PE_}
+	z^\star = H \left( \frac{z-\eta}{H+\eta} \right)
+\end{equation}
+
+This coordinate is closely related to the "eta" coordinate used in many atmospheric 
+models (see Black (1994) for a review of eta coordinate atmospheric models). It 
+was originally used in ocean models by Stacey et al. (1995) for studies of tides 
+next to shelves, and it has been recently promoted by Adcroft and Campin (2004) 
+for global climate modelling.
+
+The surfaces of constant $z^\star$ are quasi-horizontal. Indeed, the $z^\star$ coordinate reduces to $z$ when $\eta$ is zero. In general, when noting the large differences between 
+undulations of the bottom topography versus undulations in the surface height, it 
+is clear that surfaces constant $z^\star$ are very similar to the depth surfaces. These properties greatly reduce difficulties of computing the horizontal pressure gradient relative to terrain following sigma models discussed in \S\ref{PE_sco}. 
+Additionally, since $z^\star$ when $\eta = 0$, no flow is spontaneously generated in an 
+unforced ocean starting from rest, regardless the bottom topography. This behaviour is in contrast to the case with "s"-models, where pressure gradient errors in 
+the presence of nontrivial topographic variations can generate nontrivial spontaneous flow from a resting state, depending on the sophistication of the pressure 
+gradient solver. The quasi-horizontal nature of the coordinate surfaces also facilitates the implementation of neutral physics parameterizations in $z^\star$ models using 
+the same techniques as in $z$-models (see Chapters 13-16 of Griffies (2004) for a 
+discussion of neutral physics in $z$-models, as well as Section \S\ref{LDF_slp} 
+in this document for treatment in \NEMO). 
+
+The range over which $z^\star$ varies is time independent $-H \leq z^\star \leq 0$. Hence, all 
+cells remain nonvanishing, so long as the surface height maintains $\eta > ?H$. This 
+is a minor constraint relative to that encountered on the surface height when using 
+$s = z$ or $s = z - \eta$. 
+
+Because $z^\star$ has a time independent range, all grid cells have static increments 
+ds, and the sum of the ver tical increments yields the time independent ocean 
+depth %·k ds = H. 
+The $z^\star$ coordinate is therefore invisible to undulations of the 
+free surface, since it moves along with the free surface. This proper ty means that 
+no spurious ver tical transpor t is induced across surfaces of constant $z^\star$ by the 
+motion of external gravity waves. Such spurious transpor t can be a problem in 
+z-models, especially those with tidal forcing. Quite generally, the time independent 
+range for the $z^\star$ coordinate is a very convenient proper ty that allows for a nearly 
+arbitrary ver tical resolution even in the presence of large amplitude fluctuations of 
+the surface height, again so long as $\eta > -H$. 
+
+
+
+%%%
+%  essai update time splitting...
+%%%
+
+
+% ================================================================
+% Surface Pressure Gradient and Sea Surface Height
+% ================================================================
+\section{Surface pressure gradient and Sea Surface Heigth (\mdl{dynspg})}
+\label{DYN_hpg_spg}
+%-----------------------------------------nam_dynspg----------------------------------------------------
+\namdisplay{nam_dynspg} 
+%------------------------------------------------------------------------------------------------------------
+The surface pressure gradient term is related to the representation of the free surface (\S\ref{PE_hor_pg}). The main distinction is between the fixed volume case (linear free surface or rigid lid) and the variable volume case (nonlinear free surface, \key{vvl} is active). In the linear free surface case (\S\ref{PE_free_surface}) and rigid lid (\S\ref{PE_rigid_lid}), the vertical scale factors $e_{3}$ are fixed in time, while in the nonlinear case (\S\ref{PE_free_surface}) they are time-dependent. With both linear and nonlinear free surface, external gravity waves are allowed in the equations, which imposes a very small time step when an explicit time stepping is used. Two methods are proposed to allow a longer time step for the three-dimensional equations: the filtered free surface, which is a modification of the continuous equations (see \eqref{Eq_PE_flt}), and the split-explicit free surface described below. The extra term introduced in the filtered method is calculated implicitly, so that the update of the next velocities is done in module \mdl{dynspg\_flt} and not in \mdl{dynnxt}.
+
+%-------------------------------------------------------------
+% Explicit
+%-------------------------------------------------------------
+\subsubsection{Explicit (\key{dynspg\_exp})}
+\label{DYN_spg_exp}
+
+In the explicit free surface formulation, the model time step is chosen small enough to describe the external gravity waves (typically a few ten seconds). The sea surface height is given by :
+\begin{equation} \label{Eq_dynspg_ssh}
+\frac{\partial \eta }{\partial t}\equiv \frac{\text{EMP}}{\rho _w }+\frac{1}{e_{1T} 
+e_{2T} }\sum\limits_k {\left( {\delta _i \left[ {e_{2u} e_{3u} u} 
+\right]+\delta _j \left[ {e_{1v} e_{3v} v} \right]} \right)} 
+\end{equation}
+
+where EMP is the surface freshwater budget (evaporation minus precipitation, and minus river runoffs (if the later are introduced as a surface freshwater flux, see \S\ref{SBC}) expressed in $Kg.m^{-2}.s^{-1}$, and $\rho _w =1,000\,Kg.m^{-3}$ is the volumic mass of pure water. The sea-surface height is evaluated using a leapfrog scheme in combination with an Asselin time filter, i.e. the velocity appearing in (\ref{Eq_dynspg_ssh}) is centred in time (\textit{now} velocity). 
+
+The surface pressure gradient, also evaluated using a leap-frog scheme, is then simply given by :
+\begin{equation} \label{Eq_dynspg_exp}
+\left\{ \begin{aligned}
+ - \frac{1}    						{e_{1u}} \;	\delta _{i+1/2} \left[  \,\eta\,  \right] 	\\
+ \\
+ - \frac{1}    						{e_{2v}} \;	\delta _{j+1/2} \left[  \,\eta\,  \right]  
+\end{aligned} \right.
+\end{equation} 
+
+Consistent with the linearization, a $\left. \rho \right|_{k=1} / \rho _o$ factor is omitted in (\ref{Eq_dynspg_exp}). 
+
+%-------------------------------------------------------------
+% Split-explicit time-stepping
+%-------------------------------------------------------------
+\subsubsection{Split-explicit time-stepping (\key{dynspg\_ts})}
+\label{DYN_spg_ts}
+%--------------------------------------------namdom----------------------------------------------------
+\namdisplay{namdom} 
+%--------------------------------------------------------------------------------------------------------------
+The split-explicit free surface formulation used in OPA follows the one proposed by \citet{Griffies2004}. The general idea is to solve the free surface equation with a small time step, while the three dimensional prognostic variables are solved with a longer time step that is a multiple of \np{rdtbt} (Figure III.3). 
+
+%>   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >
+\begin{figure}[!t] \label{Fig_DYN_dynspg_ts}
+\begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_DYN_dynspg_ts.pdf}
+\caption{Schematic of the split-explicit time stepping scheme for the barotropic and baroclinic modes, after \citet{Griffies2004}. Time increases to the right. Baroclinic time steps are denoted by $t-\Delta t$, $t, t+\Delta t$, and $t+2\Delta t$. The curved line represents a leap-frog time step, and the smaller barotropic time steps $N \Delta t=2\Delta t$ are denoted by the zig-zag line. The vertically integrated forcing \textbf{M}(t) computed at baroclinic time step t represents the interaction between the barotropic and baroclinic motions. While keeping the total depth, tracer, and freshwater forcing fields fixed, a leap-frog integration carries the surface height and vertically integrated velocity from t to $t+2 \Delta t$ using N barotropic time steps of length $\Delta t$. Time averaging the barotropic fields over the N+1 time steps (endpoints included) centers the vertically integrated velocity at the baroclinic timestep $t+\Delta t$. A baroclinic leap-frog time step carries the surface height to $t+\Delta t$ using the convergence of the time averaged vertically integrated velocity taken from baroclinic time step t. }
+\end{center}
+\end{figure}
+%>   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >   >
+
+The split-explicit formulation has a damping effect on external gravity waves, which is weaker than the filtered free surface but still significant as shown by \citet{Levier2007} in the case of an analytical barotropic Kelvin wave. 
+
+%from griffies book: .....   copy past !
+
+\textbf{title: Time stepping the barotropic system }
+
+Assume knowledge of the full velocity and tracer fields at baroclinic time $\tau$. Hence, 
+we can update the surface height and vertically integrated velocity with a leap-frog 
+scheme using the small barotropic time step $\Delta t$. We have 
+
+\begin{equation} \label{DYN_spg_ts_eta}
+\eta^{(b)}(\tau,t_{n+1}) - \eta^{(b)}(\tau,t_{n+1}) (\tau,t_{n-1})
+	= 2 \Delta t \left[-\nabla \cdot \textbf{U}^{(b)}(\tau,t_n) + \text{EMP}_w(\tau) \right] 
+\end{equation}
+\begin{multline} \label{DYN_spg_ts_u}
+\textbf{U}^{(b)}(\tau,t_{n+1}) - \textbf{U}^{(b)}(\tau,t_{n-1})  \\
+	= 2\Delta t \left[ - f \textbf{k} \times \textbf{U}^{(b)}(\tau,t_{n}) 
+	- H(\tau) \nabla p_s^{(b)}(\tau,t_{n}) +\textbf{M}(\tau) \right]
+\end{multline}
+\
+
+In these equations, araised (b) denotes values of surface height and vertically integrated velocity updated with the barotropic time steps. The $\tau$ time label on $\eta^{(b)}$ 
+and $U^{(b)}$ denotes the baroclinic time at which the vertically integrated forcing $\textbf{M}(\tau)$ (note that this forcing includes the surface freshwater forcing), the tracer fields, the freshwater flux $\text{EMP}_w(\tau)$, and total depth of the ocean $H(\tau)$ are held for the duration of the barotropic time stepping over a single cycle. This is also the time 
+that sets the barotropic time steps via 
+\begin{equation} \label{DYN_spg_ts_t}
+t_n=\tau+n\Delta t   
+\end{equation}
+with $n$ an integer. The density scaled surface pressure is evaluated via 
+\begin{equation} \label{DYN_spg_ts_ps}
+p_s^{(b)}(\tau,t_{n}) = \begin{cases}
+	g \;\eta_s^{(b)}(\tau,t_{n}) \;\rho(\tau)_{k=1}) / \rho_o  &      \text{non-linear case} \\
+	g \;\eta_s^{(b)}(\tau,t_{n})  &      \text{linear case} 
+	\end{cases}
+\end{equation}
+To get started, we assume the following initial conditions 
+\begin{equation} \label{DYN_spg_ts_eta}
+\begin{split}
+\eta^{(b)}(\tau,t_{n=0}) &= \overline{\eta^{(b)}(\tau)}
+\\
+\eta^{(b)}(\tau,t_{n=1}) &= \eta^{(b)}(\tau,t_{n=0}) + \Delta t \ \text{RHS}_{n=0} 
+\end{split}
+\end{equation}
+with 
+\begin{equation} \label{DYN_spg_ts_etaF}
+ \overline{\eta^{(b)}(\tau)} = \frac{1}{N+1} \sum\limits_{n=0}^N \eta^{(b)}(\tau-\Delta t,t_{n})
+\end{equation}
+the time averaged surface height taken from the previous barotropic cycle. Likewise, 
+\begin{equation} \label{DYN_spg_ts_u}
+\textbf{U}^{(b)}(\tau,t_{n=0}) = \overline{\textbf{U}^{(b)}(\tau)}	\\
+\\
+\textbf{U}(\tau,t_{n=1}) = \textbf{U}^{(b)}(\tau,t_{n=0}) + \Delta t \ \text{RHS}_{n=0}  	
+\end{equation}
+with 
+\begin{equation} \label{DYN_spg_ts_u}
+ \overline{\textbf{U}^{(b)}(\tau)} 
+ 	= \frac{1}{N+1} \sum\limits_{n=0}^N\textbf{U}^{(b)}(\tau-\Delta t,t_{n})
+\end{equation}
+the time averaged vertically integrated transport. Notably, there is no Robert-Asselin time filter used in the barotropic portion of the integration. 
+
+Upon reaching $t_{n=N} = \tau + 2\Delta \tau$ , the vertically integrated velocity is time averaged to produce the updated vertically integrated velocity at baroclinic time $\tau + \Delta \tau$ 
+\begin{equation} \label{DYN_spg_ts_u}
+\textbf{U}(\tau+\Delta t) = \overline{\textbf{U}^{(b)}(\tau+\Delta t)} 
+ 	= \frac{1}{N+1} \sum\limits_{n=0}^N\textbf{U}^{(b)}(\tau,t_{n})
+\end{equation}
+The surface height on the new baroclinic time step is then determined via a baroclinic leap-frog using the following form 
+
+\begin{equation} \label{DYN_spg_ts_ssh}
+\eta(\tau+\Delta) - \eta^{F}(\tau-\Delta) = 2\Delta t \ \left[ - \nabla \cdot \textbf{U}(\tau) + \text{EMP}_w \right]  
+\end{equation}
+
+ The use of this "big-leap-frog" scheme for the surface height ensures compatibility between the mass/volume budgets and the tracer budgets. More discussion of this point is provided in Chapter 10 (see in particular Section 10.2). 
+ 
+In general, some form of time filter is needed to maintain integrity of the surface 
+height field due to the leap-frog splitting mode in equation \ref{DYN_spg_ts_ssh}. We 
+have tried various forms of such filtering, with the following method discussed in 
+Griffies et al. (2001) chosen due to its stability and reasonably good maintenance of 
+tracer conservation properties (see Section ??) 
+
+\begin{equation} \label{DYN_spg_ts_sshf}
+\eta^{F}(\tau-\Delta) =  \overline{\eta^{(b)}(\tau)} 
+\end{equation}
+Another approach tried was 
+
+\begin{equation} \label{DYN_spg_ts_sshf2}
+\eta^{F}(\tau-\Delta) = \eta(\tau) 
+	+ (\alpha/2) \left[\overline{\eta^{(b)}}(\tau+\Delta t)
+				    + \overline{\eta^{(b)}}(\tau-\Delta t) -2 \;\eta(\tau) \right]
+\end{equation}
+
+which is useful since it isolates all the time filtering aspects into the term multiplied 
+by $\alpha$. This isolation allows for an easy check that tracer conservation is exact when 
+eliminating tracer and surface height time filtering (see Section ?? for more complete discussion). However, in the general case with a non-zero $\alpha$, the filter \ref{DYN_spg_ts_sshf} was found to be more conservative, and so is recommended. 
+
+
+
+
+
+%-------------------------------------------------------------
+% Filtered formulation 
+%-------------------------------------------------------------
+\subsubsection{Filtered formulation (\key{dynspg\_flt})}
+\label{DYN_spg_flt}
+
+The filtered formulation follows the \citet{Roullet2000} implementation. The extra term introduced in the equations (see {\S}I.2.2) is solved implicitly. The elliptic solvers available in the code are 
+documented in \S\ref{MISC}. The amplitude of the extra term is given by the namelist variable \np{rnu}. The default value is 1, as recommended by \citet{Roullet2000}
+
+\colorbox{red}{\np{rnu}=1 to be suppressed from namelist !}
+
+%-------------------------------------------------------------
+% Non-linear free surface formulation 
+%-------------------------------------------------------------
+\subsection{Non-linear free surface formulation (\key{vvl})}
+\label{DYN_spg_vvl}
+
+In the non-linear free surface formulation, the variations of volume are fully taken into account. This option is presented in a report \citep{Levier2007} available on the NEMO web site. The three time-stepping methods (explicit, split-explicit and filtered) are the same as in \S\ref{DYN_spg_linear} except that the ocean depth is now time-dependent. In particular, this means that in filtered case, the matrix to be inverted has to be recomputed at each time-step.
+
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_SBC.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_SBC.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_SBC.tex	(revision 4536)
@@ -0,0 +1,447 @@
+% ================================================================
+% Chapter Ñ Surface Boundary Condition (SBC) 
+% ================================================================
+\chapter{Surface Boundary Condition (SBC) }
+\label{SBC}
+\minitoc
+
+\begin{verbatim}
+At the time of this writing, the new surface module 
+that is described in this chapter (SBC) is not yet part
+of the current distribution. The current way to specify 
+the surface boundary condition is such a mess that we 
+did not attempt to describe it. Nevertheless, apart from 
+the way the surface forcing is implemented, the infor-
+mation given here are relevant for a NEMO v2.3 user.
+\end{verbatim}
+
+The ocean needs 7 fields as surface boundary condition:
+
+The two components of the surface ocean stress $\left( {\tau _u \;,\;\tau _v} \right)$
+
+The incoming solar and non solar heat fluxes $\left( {Q_{ns} \;,\;Q_{sr} } \right)$
+
+The surface freshwater budget $\left( {\text{EMP}\;,\;\text{EMP}_S } \right)$
+
+\colorbox {yellow}{ The river runoffs (RUNOFF)}
+
+Four different ways are offered to provide those 7 fields to the ocean: an 
+analytical formulation, a flux formulation, a bulk formulae formulation 
+(CORE or CLIO bulk formulae) and a coupled formulation (exchanges with a 
+atmospheric model via OASIS coupler). In addition, the resulting fields can 
+be further modified on used demand via several namelist option. These option 
+control the addition of a surface restoring term to observed SST and/or SSS, 
+the modification of fluxes below ice-covered area (using observed ice-cover 
+or a sea-ice model), the addition of river runoffs as surface freshwater 
+fluxes, and the addition of a freshwater flux adjustment on order to avoid a 
+mean sea-level drift.
+
+In this chapter we first discuss where the surface boundary condition 
+appears in the model equations. Then we present the four ways of providing 
+the surface boundary condition. Finally, the different options that modify 
+the fluxes inside the ocean are discussed.
+
+
+
+
+
+
+
+
+
+
+
+% ================================================================
+% Surface boundary condition for the ocean
+% ================================================================
+\section{Surface boundary condition for the ocean}
+\label{SBC_general}
+
+
+The surface ocean stress is the stress exerted by the wind and the sea-ice 
+on the ocean. Their two components are assumed to be interpolated on the 
+ocean mesh, i.e. provided at U- and V-points and projected onto the 
+(\textbf{i},\textbf{j}) referential. They are applied as a surface boundary 
+condition of the computation of the momentum vertical mixing trend 
+(\textbf{dynzdf} module) :
+\begin{equation} \label{Eq_sbc_dynzdf}
+\left.{\left( {\frac{A^{vm} }{e_3 }\ \frac{\partial \textbf{U}_h}{\partial k}} \right)} \right|_{z=1}
+	 = \frac{1}{\rho _o} \binom{\tau _u}{\tau _v }
+\end{equation}
+where $(\tau _u ,\;\tau _v )=(utau,vtau)$ are the two components of the wind 
+stress vector in the $(\textbf{i},\textbf{j})$ coordinate system.
+
+The surface heat flux is decomposed in two parts, a non solar and solar heat 
+fluxes. The former is the non penetrative part of the heat flux (i.e. 
+sensible plus latent plus long wave heat fluxes). It is applied as a surface 
+boundary condition trend of the first level temperature time evolution 
+equation (\mdl{trasbc} module). 
+\begin{equation} \label{Eq_sbc_trasbc_q}
+\frac{\partial T}{\partial t}\equiv \cdots \;+\;\left. {\frac{Q_{ns} }{\rho 
+_o \;C_p \;e_{3T} }} \right|_{k=1} \quad
+\end{equation}
+
+The latter is the penetrative part of the heat flux. It is applied as a 3D 
+trends of the temperature equation (\mdl{traqsr} module) when \np{ln\_traqsr}=T.
+
+\begin{equation} \label{Eq_sbc_traqsr}
+\frac{\partial T}{\partial t}\equiv \cdots \;+\frac{Q_{sr} }{\rho _o C_p 
+\,e_{3T} }\delta _k \left[ {I_w } \right]
+\end{equation}
+
+where $I_w$ is an adimensional function that describes the way the light 
+penetrates inside the water column. It is generally a sum of decreasing 
+exponential (see \S\ref{TRA_qsr}).
+
+The surface freshwater budget is provided through two non-necessary 
+identical fields EMP and EMP$_S $. Indeed, a surface freshwater 
+flux has two effects: it changes the volume of the ocean and it changes the 
+surface concentration of salt (an others tracers). Therefore it appears in 
+the sea surface height and salinity time evolution equations as a volume 
+flux, EMP (\textit{dynspg\_xxx} modules), and concentration/dilution effect, 
+EMP$_{S}$ (\mdl{trasbc} module), respectively. 
+\begin{equation} \label{Eq_trasbc_emp}
+\begin{aligned}
+&\frac{\partial \eta }{\partial t}\equiv \cdots \;+\;\text{EMP}\quad  \\ 
+\\
+ &\frac{\partial S}{\partial t}\equiv \cdots \;+\left. {\frac{\text{EMP}_S \;S}{e_{3T} }} \right|_{k=1} \\ 
+ \end{aligned}
+\end{equation} 
+
+In the real ocean, EMP=EMP$_S$ and the ocean salt content is conserved, 
+but it exist several numerical reason why this equality should be broken. 
+For example:
+
+When rigid-lid assumption is made, the ocean volume becomes constant and 
+thus, EMP=0, not EMP$_{S }$.
+
+When a sea-ice model is considered, the water exchanged between ice and 
+ocean is not fresh as mean ice salinity is $\sim $\textit{4 psu}. In this case, 
+EMP$_{S}$ take into account both concentration/dilution effect associated with 
+freezing/melting together with salt flux between ice and ocean, while EMP is 
+only the volume flux. In addition, in the current version of \NEMO, the 
+sea-ice is assumed to be above the ocean. Freezing/melting does not change 
+the ocean volume (not impact on EMP) while it modifies the SSS 
+\colorbox{yellow}{(see {\S} on LIM sea-ice model)}.
+
+Note that SST can also be modified by a freshwater flux. Precipitations (in 
+particular solid one) may have a temperature significantly different from 
+the SST. Due to the lack of information about the temperature of 
+precipitations, we assume it is equal to the SST. Therefore, no 
+concentration/dilution term appears in the temperature equation. It has to 
+be emphasised that this absence does not mean that there is not heat flux 
+associated with precipitation! An excess of precipitation will change the 
+ocean heat content and is therefore associated with a heat flux (not 
+diagnosed in the model) \citep{Roullet2000}).
+
+\colorbox{yellow}{Miss: }
+
+A extensive description of all namsbc namelist (parameter that have to be 
+created!)
+
+Especially the \np{nf\_sbc}, the \mdl{sbc\_oce} module (fluxes + mean sst sss ssu 
+ssv) i.e. information required by flux computation or sea-ice
+
+\colorbox{red}{Add nqsr = 0 / 1 replace key{\_}traqsr}
+
+\mdl{sbc\_oce} containt the definition in memory of the 7 fields (6+runoff), add 
+a word on runoff: included in surface bc or add as lateral obc{\ldots}.
+
+Sbcmod manage the ``providing'' (fourniture) to the ocean the 7 fields
+
+Fluxes update only each nf{\_}sbc time step (namsbc) explain relation 
+between nf{\_}sbc and nf{\_}ice, do we define nf{\_}blk??? ? only one 
+nf{\_}sbc
+
+Explain here all the namlist namsbc variable{\ldots}.
+
+\colorbox{yellow}{End Miss }
+
+The ocean model provides the following variables averaged over nf{\_}sbc 
+time-step:
+
+%-------------------------------------------------TABLE---------------------------------------------------
+\begin{table}[htbp]  \label{Tab_ssm}
+\begin{center}
+\begin{tabular}{|l|l|l|l|}
+\hline
+Variable desciption					& Computer name	& Units	& point \\	\hline
+i-component of the surface current	& ssu\_u	& $m.s^{-1}$	& U \\	\hline
+j-component of the surface current	& ssv\_m	& $m.s^{-1}$	& V \\	\hline
+Sea surface temperature				& sst\_m	& \r{}$K$		& T \\	\hline
+Sea surface salinty					& sss\_m	& $psu$			& T \\	\hline
+\end{tabular}
+\end{center}
+\end{table}
+%--------------------------------------------------------------------------------------------------------------
+
+The mean computation is done in sbcmod (
+
+\colorbox{yellow}{Penser a} mettre dans le restant l'info nf{\_}sbc ET nf{\_}sbc*rdt de sorte de 
+reinitialiser la moyenne si on change la frequence ou le pdt
+
+NB: creer cn{\_}sbc{\_}ice (cn{\_} = character in the namelist) with 3 
+cases:
+
+= `noice' no specific call
+
+= `iceif ` ``ice-if'' sea ice, i.e. read observed ice-cover and modified sbc 
+bellow those area.
+
+= `lim' LIM sea-ice model is called which update the sbc fields in ice 
+covered area
+
+? modify the nsbc{\_}ice variable depending of this parameter (from --1, 0 
+to 1)
+\colorbox{yellow}{End Penser a}
+
+% ================================================================
+% Analytical formulation (sbcana module) 
+% ================================================================
+\section{Analytical formulation (\textit{sbcana} module) }
+\label{SBC_ana}
+
+%---------------------------------------namtau - namflx--------------------------------------------------
+\namdisplay{namtau}
+\namdisplay{namflx}
+%--------------------------------------------------------------------------------------------------------------
+
+
+The analytical formulation of the surface boundary condition is set by 
+default. In this case, all the 6 fluxes needed by the ocean are assumed to 
+be uniform in space. They take constant values given in the namlist 
+namsbc{\_}ana : \textit{utau0}, \textit{vtau0}, \textit{qns0}, \textit{qsr0}, \textit{emp0} and \textit{emps0}. while the runoff is set to zero. In addition, 
+the wind is allowed to reach its nominal value within a given number of time 
+step (\textit{ntau000}).
+
+If a user wants to applied a different analytical forcing, \mdl{sbcana} 
+module is the very place to do that. As an example, one can have a look to 
+the \mdl{sbc\_ana\_gyre} routine which provides the analytical forcing of the 
+GYRE configuration (see GYRE configuration manual, in preparation).
+
+
+% ================================================================
+% Flux formulation 
+% ================================================================
+\section{Flux formulation (\mdl{sbcflx} module, \key{sbcflx}) }
+\label{SBC_flx}
+
+In the flux formulation (\key{sbcflx} defined), the surface boundary 
+condition fields are directly read from input files. The user has to define 
+in the namelist namsbc{\_}flx the name of the file, the name of the variable 
+read in the file, the time frequency at which it is given, and a logical 
+setting whether a time interpolation to the model time step is asked are not 
+for this field). (fld\_i namelist structure).
+
+\colorbox{yellow}{ Describe the information given?  }
+
+\colorbox{yellow}{  Add an info about on-line interpolation or not ? at with which scale{\ldots} }
+
+
+\textbf{Caution}: when the frequency is set to --12, the data are monthly 
+values. There are assumed to be climatological values, so time interpolation 
+between December the 15$^{th}$ and January the 15$^{th}$ is done using 
+record 12 and 1
+
+When higher frequency is set and time interpolation is demanded, the model 
+will try to read the last (first) record of previous (next) year in a file 
+having the same name but a suffix {\_}prev{\_}year (next{\_}year) being 
+added. These file must only content a single record. If they don't exist, 
+the will assume that the previous year last record is equal to the first 
+record of the previous year, and similarly, that the first record of the 
+next year is equal to the last record of the current year. This will cause 
+the forcing to remain constant over the first and last half fld\_frequ 
+hours.
+
+Note that in general, a flux formulation is used in associated with a 
+damping term to observed SST and/or SSS. See \S\ref{SBC_ssr} for its 
+specification.
+
+
+% ================================================================
+% Bulk formulation
+% ================================================================
+\section{Bulk formulation (\mdl{sbcblk\_core} or\mdl{sbcblk\_clio} module) }
+\label{SBC_blk}
+
+In the bulk formulation, the surface boundary condition fields are computed 
+using bulk formulae and atmospheric fields and ocean (and ice) variables. 
+
+The atmospheric fields used depends on the bulk formulae used. Two of them 
+are available : the CORE and CLIO bulk formulea. The choice is made by 
+activating the CPP key \key{sbcblk\_core} or 
+\key{sbcblk\_clio}, respectively.
+
+\colorbox{yellow}{Note : if a sea-ice model is used then blah blah blah{\ldots}}
+
+CORE bulk formulea
+
+The CORE bulk formulae have been developed by \citet{LargeYeager2004}. They 
+have been design to handle the CORE forcing, a mixture of NCEP reanalysis 
+and satellite data. They use an inertial dissipative method to compute the 
+turbulent transfer coefficients (momentum, sensible heat and evaporation) 
+from the 10 meter wind speed, air temperature and specific humidity).
+
+The required 8 input fields are:
+
+%--------------------------------------------------TABLE--------------------------------------------------
+\begin{table}[htbp]   \label{Tab_CORE}
+\begin{center}
+\begin{tabular}{|l|l|l|l|}
+\hline
+Variable desciption					& Computer name	& Units			& point \\		\hline
+i-component of the 10m air velocity	& utau		& $m.s^{-1}$			& T or U \\ 	\hline
+j-component of the 10m air velocity	& vtau		& $m.s^{-1}$			& T or V \\	\hline
+10m air temperature					& tair		& \r{}$K$				& T 	\\	\hline
+Specific humidity					& humi		& \%					& T \\		\hline
+Incoming long wave radiation		& qlw		& $W.m^{-2}$			& T \\		\hline
+Incoming short wave radiation		& qsr		& $W.m^{-2}$			& T \\		\hline
+Total precipitation (liquid + solid)	& precip	& $Kg.m^{-2}.s^{-1}$	& T \\ 	\hline
+Solid precipitation					& snow		& $Kg.m^{-2}.s^{-1}$	& T \\	\hline
+\end{tabular}
+\end{center}
+\end{table}
+%--------------------------------------------------------------------------------------------------------------
+
+Note that the air velocity can be provided at either tracer ocean point or 
+velocity ocean point. 
+
+\colorbox{yellow}{Explain low resolution, better to provide it at U-V, high resolution better}
+
+\colorbox{yellow}{at T-point{\ldots} Explain why, scheme?}
+
+\colorbox{yellow}{Add a namelist parameter to provide a switch from U/V or T (or I??) point}
+
+\colorbox{yellow}{ for utau/vtau}
+
+CLIO bulk formulea
+
+The CLIO bulk formulae have been developed several years ago for the 
+Louvain-la-neuve coupled ice-ocean model (CLIO, Goosse et al. 1997). It is a 
+simpler bulk formulae that assumed the stress to be known and computes the 
+radiative fluxes from a climatological cloud cover. 
+
+The required 7 input fields are:
+
+%--------------------------------------------------TABLE--------------------------------------------------
+\begin{table}[htbp]   \label{Tab_CLIO}
+\begin{center}
+\begin{tabular}{|l|l|l|l|}
+\hline
+Variable desciption				& Computer name	& Units					& point \\	\hline
+i-component of the ocean stress		& utau			& $N.m^{-2}$			& U \\	\hline
+j-component of the ocean stress		& vtau			& $N.m^{-2}$			& V \\	\hline
+Wind speed module					& vatm			& $m.s^{-1}$			& T \\	\hline
+10m air temperature					& tair			& \r{}$K$				& T \\	\hline
+Secific humidity						& humi			& \%					& T \\	\hline
+Cloud cover							& 				& \%					& T \\	\hline
+Total precipitation (liquid + solid)	& precip		& $Kg.m^{-2}.s^{-1}$	& T \\	\hline
+Solid precipitation 					& snow			& $Kg.m^{-2}.s^{-1}$	& T \\	\hline
+\end{tabular}
+\end{center}
+\end{table}
+%--------------------------------------------------------------------------------------------------------------
+
+As for the flux formulation, the input data information required by the 
+model is provided in the namsbc\_blk\_core or namsbc\_blk\_clio 
+namelist (via the structure fld\_i). The same assumption is made about the 
+value of the first and last record in each file.
+
+
+% ================================================================
+% Coupled formulation
+% ================================================================
+\section{Coupled formulation (\mdl{sbccpl} module)}
+\label{SBC_cpl}
+
+In the coupled formulation of the surface boundary condition, the fluxes are 
+provided by the OASIS coupler at each \np{nf\_cpl} time-step, while sea and ice 
+surface temperature, ocean and ice albedo, and ocean currents are sent to 
+the atmospheric component.
+
+
+% ================================================================
+% Miscellanea options
+% ================================================================
+\section{Miscellanea options}
+\label{SBC_misc}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Surface restoring to observed SST and/or SSS
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Surface restoring to observed SST and/or SSS (\mdl{sbcssr})}
+\label{SBC_ssr}
+
+In forced mode using flux formulation (default option or \key{flx} defined), a 
+feedback term \emph{must} be added to the specified surface heat flux $Q_{ns}^o$:
+\begin{equation} \label{Eq_sbc_dmp_q}
+Q_{ns} = Q_{ns}^o + \frac{dQ}{dT} \left( \left. T \right|_{k=1} - SST_{Obs} \right)
+\end{equation}
+where SST is a sea surface temperature field (observed or climatological), $T$ is 
+the model surface layer temperature and $\frac{dQ}{dT}$ is a negative feedback 
+coefficient usually taken equal to $-40~W.m^{-2}.$\r{}K$^{-1}$. For a $50~m$ mixed-layer depth, 
+this value corresponds to a relaxation time scale of two months. This term 
+ensures that if $T$ perfectly fits SST then $Q$ is equal to $Q_o$. 
+
+In the fresh water budget, a feedback term can also be added:
+
+\begin{equation} \label{Eq_sbc_dmp_emp}
+EMP = EMP_o +\gamma_s^{-1} \left(S-SSS_{Obs}\right)\left|S\right.
+\end{equation}
+
+where EMP$_{o }$ is a net surface fresh water flux (observed, climatological or 
+atmospheric model product), \textit{SSS}$_{Obs}$is a sea surface salinity (usually a time 
+interpolation of the monthly mean PHC climatology \citep{Steele2001}, $S$ is the model 
+surface layer salinity and $\gamma_s$ is a negative feedback coefficient 
+which is provided as a namelist parameter. Unlike heat flux, there is no 
+physical justification for the feedback term in (III.4.4) as the atmosphere 
+does not care about ocean surface salinity \citep{Madec1997}. The 
+SSS restoring term can only be view as a flux correction on freshwater 
+fluxes to reduce the uncertainties we have on the observed freshwater 
+budget.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Handling of ice-covered area
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Handling of ice-covered area}
+\label{SBC_ice-cover}
+The presence of sea-ice at the top of the ocean 
+strongly modify the surface fluxes
+
+The presence at the sea surface of an ice cover area modified all the fluxes 
+transmitted to the ocean. There is two cases whereas a sea-ice model is used 
+or not. 
+
+Without sea ice model, the information of ice-cover / open ocean is read in 
+a file (either the directly the ice-cover or the observed SST from which 
+ice-cover is deduced using a criteria on freezing point temperature). 
+
+% -------------------------------------------------------------------------------------------------------------
+%        Addition of river runoffs
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Addition of river runoffs (\mdl{sbcrnf})}
+\label{SBC_rnf}
+
+It is convenient to introduce the river runoff in the model as a surface 
+fresh water fluxes. \colorbox{yellow}{{\ldots} blah blah{\ldots}.}
+
+\colorbox{yellow}{Nevertheless, Pb of vertical resolution and increase of Kz in vicinity of }
+
+\colorbox{yellow}{river mouths{\ldots}}
+
+Control of the mean sea level
+
+% -------------------------------------------------------------------------------------------------------------
+%        Addition of river runoffs
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Freshwater budget control (\mdl{sbcfwb})}
+\label{SBC_fwb}
+%--------------------------------------------namfwb--------------------------------------------------------
+\namdisplay{namfwb}
+%--------------------------------------------------------------------------------------------------------------
+
+\colorbox{yellow}{freshwater budget correction{\ldots}}
+
+
+
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_TRA.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_TRA.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_TRA.tex	(revision 4536)
@@ -0,0 +1,912 @@
+% ================================================================
+% Chapter 1 Ñ Ocean Tracers (TRA)
+% ================================================================
+\chapter{Ocean Tracers (TRA)}
+\label{TRA}
+\minitoc
+
+% missing/update 
+% traqsr: need to coordinate with SBC module
+% trabbl : advective case to be discussed
+%			diffusive case : add : only the bottom ocean cell is concerned
+%			==> addfigure on bbl
+
+
+$\ $\newline    % force a new ligne
+
+Using the representation described in Chap.~\ref{DOM}, several semi-discrete space 
+forms of the tracer equations are available depending on the vertical 
+coordinate used and on the physics used. In all the equations presented 
+here, the masking has been omitted for simplicity. One must be aware that 
+all the quantities are masked fields and that each time a mean or difference 
+operator is used, the resulting field is multiplied by a mask.
+
+The two active tracers are potential temperature and salinity. Their prognostic equation can be summarized as follows:
+\begin{equation*}
+\text{NXT} = \text{ADV}+\text{LDF}+\text{ZDF}+\text{SBC}
+                   \ (+\text{QSR})\ (+\text{BBC})\ (+\text{BBL})\ (+\text{DMP})
+\end{equation*}
+
+NXT stands for next, referring to the time-stepping. From left to right, the terms on the rhs of the tracer equations are the advection (ADV), the lateral diffusion (LDF), the vertical diffusion (ZDF), the contributions from the external forcings (SBC: Surface Boundary Condition, QSR: Solar Radiation penetration, and BBC: Bottom Boundary Condition), the contribution from the bottom boundary Layer (BBL) parametrisation, and an internal damping (DMP) term. The last four have been put inside brackets as they are optional. The external forcings and parameterizations require complex inputs and calculations (bulk formulae, estimation of mixing coefficients) that are carried out in modules of the SBC, LDF and ZDF categories and described in chapters \S\ref{SBC}, \S\ref{LDF} and  \S\ref{ZDF}, respectively. Note that \mdl{tranpc}, the non-penetrative convection module,  although (temporarily) located in the NEMO/OPA//TRA directory, is described with the model vertical physics (ZDF).
+
+In the present chapter we also describe the diagnostic equations used to compute the sea-water properties (density, Brunt-Vais\"{a}l\"{a} frequency, specific heat and freezing point) although the associated modules ($i.e.$ \mdl{eosbn2}, \mdl{ocfzpt} and \mdl{phycst}) are (temporarily) located in the NEMO/OPA directory.
+
+The different options available to the user are managed by namelist logical or CPP keys. For each equation term ttt, the namelist logicals are \textit{ln\_trattt\_xxx}, where \textit{xxx} is a 3 or 4 letter acronym accounting for each optional scheme. The CPP key (when it exists) is \textbf{key\_trattt}. The corresponding code can be found in the \textit{trattt} or \textit{trattt\_xxx} module, in the NEMO/OPA/TRA directory.
+
+The user has the option of extracting each tendency term on the rhs of the tracer equation (\key {trdtra} defined), as described in Chap.~\ref{MISC}.
+
+% ================================================================
+% Tracer Advection
+% ================================================================
+\section{Tracer Advection (\mdl{traadv})}
+\label{TRA_adv}
+%------------------------------------------nam_traadv-----------------------------------------------------
+\namdisplay{nam_traadv}
+%-------------------------------------------------------------------------------------------------------------
+
+The advection tendency in flux form is the divergence of the advective 
+fluxes. Its discrete expression is given by :
+\begin{equation} \label{Eq_tra_adv}
+ADV_\tau =-\frac{1}{e_{1T} {\kern 1pt}e_{2T} {\kern 1pt}e_{3T} }\left( 
+{\;\delta _i \left[ {e_{2u} {\kern 1pt}e_{3u} {\kern 1pt}\;u\;\tau _u } 
+\right]+\delta _j \left[ {e_{1v} {\kern 1pt}e_{3v} {\kern 1pt}v\;\tau _v } 
+\right]\;} \right)-\frac{1}{\mathop e\nolimits_{3T} }\delta _k \left[ 
+{w\;\tau _w } \right]
+\end{equation}
+which, in pure z-coordinate (\key{zco} defined), reduces to :
+\begin{equation} \label{Eq_tra_adv_zco}
+ADV_\tau =-\frac{1}{e_{1T} {\kern 1pt}e_{2T} {\kern 1pt}}\left( {\;\delta _i 
+\left[ {e_{2u} {\kern 1pt}{\kern 1pt}\;u\;\tau _u } \right]+\delta _j \left[ 
+{e_{1v} {\kern 1pt}v\;\tau _v } \right]\;} \right)-\frac{1}{\mathop 
+e\nolimits_{3T} }\delta _k \left[ {w\;\tau _w } \right]
+\end{equation}
+as the vertical scale factors are function of $k$ only, and thus $e_{3u} 
+=e_{3v} =e_{3T} $.
+
+The flux form requires implicitly the use of the continuity equation: 
+$\nabla \cdot \left( \vect{U}\,T \right)=\vect{U} \cdot \nabla T$ 
+using $\nabla \cdot \vect{U}=0)$ or $\partial _t e_3 +\nabla \cdot \vect{U}=0$ in variable volume case ($i.e.$ \key{vvl} defined). Therefore it is of 
+paramount importance to design the discrete analogue of the advection 
+tendency so that it is consistent with the continuity equation in order to 
+enforce conservation properties of the continuous equations. In other words, 
+by substituting $\tau$ by 1 in (\ref{Eq_tra_adv}) we recover discrete form of the 
+continuity equation which is used to calculate the vertical velocity.
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_adv_scheme}  \begin{center}
+\includegraphics[width=0.9\textwidth]{./Figures/Fig_adv_scheme.pdf}
+\caption{Schematic representation of some ways used to evaluate the tracer value at $u$-point and the amount of tracer exchanged between two neighbouring grid points. Upsteam biased scheme (ups): the upstream value is used and the black area is exchanged. Piecewise parabolic method (ppm): a parabolic interpolation is used and black + dark grey areas is exchanged. Monotonic upstream scheme for conservative laws (muscl):  a parabolic interpolation is used and black + dark grey + grey areas are exchanged. Second order scheme (cen2): the mean value is used and black + dark grey + grey + light grey areas are exchanged. Note that this illustration does not include the flux limiter used in ppm and muscl schemes.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+The advection schemes used in OPA differ by the choice made in space and 
+time interpolation to define the value of the tracer at the velocity points (\ref{Fig_adv_scheme}). 
+Along solid lateral and bottom boundaries a zero tracer flux is naturally 
+specified, since the normal velocity is zero there. At the sea surface the 
+boundary condition depends on the type of sea surface chosen: (1) in 
+rigid-lid formulation, $w=0$ at the surface, so the advective fluxes through the 
+surface is zero ; (2) in non-linear free surface (variable volume case, 
+\key{vvl} defined), convergence/divergence in the first ocean level moves 
+up/down the free surface: there is no tracer advection through it so that 
+the advective fluxes through the surface is also zero ; (3) in the linear 
+free surface, the first level thickness is constant in time. The vertical 
+boundary condition is applied at the fixed surface $z=0$ rather than on the 
+moving surface $z=\eta$. There is a non-zero advective flux which is set for all 
+advection schemes as the product of surface velocity (at $z=0$) by the first level 
+tracer value: $\left. {\tau _w } \right|_{k=1 \mathord{\left/ {\vphantom {1 
+2}} \right. \kern-\nulldelimiterspace} 2} =T_{k=1} $. This boundary 
+condition retains local conservation of tracer. Strict global conservation 
+is not possible in linear free surface but is achieved to a good 
+approximation since the non-conservative term is the product of the time 
+derivative of the tracer and the free surface height, two quantities that are not correlated (see \S\ref{PE_free_surface}, and also \citet{Roullet2000,Griffies2001,Campin2004}).
+
+The velocity field that appears in (\ref{Eq_tra_adv}) and (\ref{Eq_tra_adv_zco}) is the centred (\textit{now}) \textit{eulerian} ocean velocity (see \S\ref{DYN}). Nevertheless, when advective bottom boundary layer (\textit{bbl}) and/or eddy induced velocity (\textit{eiv}) parameterisations are used it is the \textit{now} \textit{effective} velocity (i.e. the sum of the eulerian, the bbl and/or the eiv velocities) which is used.
+
+The choice of an advection scheme is made in the \np{nam\_traadv} namelist, by 
+setting to \textit{true} one and only one of the logicals \textit{ln\_traadv\_xxx}. The 
+corresponding code can be found in \textit{traadv\_xxx.F90} module, where 
+\textit{xxx} is a 3 or 4 letter acronym accounting for each scheme. Details 
+of the advection schemes are given below. The choice of an advection scheme 
+is a complex matter which depends on the model physics, model resolution, 
+type of tracer, as well as the issue of numerical cost. 
+
+Note that (1) cen2, cen4 and TVD schemes require an explicit diffusion 
+operator while the other schemes are diffusive enough so that they do not 
+require additional diffusion ; (2) cen2, cen4, MUSCL2, and UBS are not 
+\textit{positive} schemes, meaning false extrema are permitted. It is not recommended to use 
+them on passive tracers ; (3) It is highly recommended to use the same 
+advection-diffusion scheme on both active and passive tracers. In 
+particular, if a source or sink of a passive tracer depends on a active one, 
+the difference of treatment of active and passive tracers can create very 
+nice-looking frontal structures that are pure numerical artefacts. 
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        2nd order centred scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{$2^{nd}$ order centred scheme (cen2) (\np{ln\_traadv\_cen2}=T)}
+\label{TRA_adv_cen2}
+
+In the centred second order formulation, the tracer at velocity points is 
+evaluated as the mean of the two neighbouring $T$-points. For example, in the 
+$i$-direction :
+\begin{equation} \label{Eq_tra_adv_cen2}
+\tau _u^{cen2} =\overline T ^{i+1/2}
+\end{equation}
+
+The scheme is non diffusive ($i.e.$ it conserves the tracer variance, $\tau^2)$ but dispersive ($i.e.$ it may create false extrema). It is therefore notoriously noisy and must be used in conjunction with an explicit diffusion operator to produce a sensible solution. The associated time-stepping is performed using a leapfrog scheme in conjunction with an Asselin time-filter, so $T$ in (\ref{Eq_tra_adv_cen2}) is the \textit{now} tracer value.
+
+Note that using cen2 scheme, the overall tracer advection is of second order accuracy since both (\ref{Eq_tra_adv}) and (\ref{Eq_tra_adv_cen2}) have this order of accuracy.
+
+% -------------------------------------------------------------------------------------------------------------
+%        4nd order centred scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{$4^{nd}$ order centred scheme (cen4) (\np{ln\_traadv\_cen4}=T)}
+\label{TRA_adv_cen4}
+
+In the $4^{th}$ order formulation (to be implemented), tracer is evaluated 
+at velocity points as the $4^{th}$ order interpolation of $T$, and thus use the 
+four neighbouring $T$-points. For example, in the $i$-direction:
+\begin{equation} \label{Eq_tra_adv_cen4}
+\tau _u^{cen4} 
+=\overline{   T - \frac{1}{6}\,\delta _i \left[ \delta_{i+1/2}[T] \,\right]   }^{\,i+1/2}
+\end{equation}
+
+Strictly speaking, the cen4 scheme is not a $4^{th}$ order advection scheme 
+but a $4^{th}$ order evaluation of advective fluxes since the divergence of 
+advective fluxes, (\ref{Eq_tra_adv}), is kept at $2^{nd}$ order. The ``$4^{th}$ order 
+scheme'' denomination used in oceanographic literature is usually associated 
+with the scheme presented here. Introducing a \textit{true} $4^{th}$ order advection 
+scheme is feasible but, for consistency reasons, it requires changes in the 
+discretisation of the tracer advection together with changes in both the 
+continuity equation and the momentum advection. 
+
+A direct consequence of the pseudo-fourth order nature of the scheme is that 
+it is not non-diffusive, i.e. the global variance of a tracer is not 
+preserved through \textit{cen4}. Furthermore, it must be used in conjunction with an 
+explicit diffusion operator to produce a sensible solution. The 
+time-stepping is also performed using a leapfrog scheme in conjunction with 
+an Asselin time-filter, so $T$ in (\ref{Eq_tra_adv_cen4}) is the \textit{now} tracer.
+
+At $T$-grid cell abutted to a boundary (coastline, bottom and surface), an 
+additional hypothesis must be made to evaluate $\tau _u^{cen4}$. This 
+hypothesis usually reduces the order of the scheme. Here we choose to set 
+the gradient of $T$ across the boundary to zero. Alternative conditions can be 
+specified such as the reduction to a second order scheme for near boundary 
+grid point.
+
+% -------------------------------------------------------------------------------------------------------------
+%        TVD scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Total Variance Dissipation scheme (TVD) (\np{ln\_traadv\_tvd}=T)}
+\label{TRA_adv_tvd}
+
+In the Total Variance Dissipation (TVD) formulation, the tracer at velocity 
+points is evaluated as a combination of upstream and centred scheme. For 
+example, in the $i$-direction :
+\begin{equation} \label{Eq_tra_adv_tvd}
+\begin{split}
+\tau _u^{ups}&= \begin{cases}
+ 					T_{i+1} 	& \text{if $\ u_{i+1/2} <     0$} \hfill \\
+ 					T_i   		& \text{if $\ u_{i+1/2} \geq 0$} \hfill \\
+				  \end{cases}     \\
+\\
+\tau _u^{tvd}&=\tau _u^{ups} +c_u \;\left( {\tau _u^{cen2} -\tau _u^{ups} } \right)
+\end{split}
+\end{equation}
+where $c_u$ is a flux limiter function taking values between 0 and 1. There 
+exists many ways to define $c_u$., each correcponding to a different total 
+variance decreasing scheme. The one chosen in OPA is described in \citet{Zalesak1979}. $c_u$ only departs from $1$ when the advective term produces a local 
+extremum in the tracer field. The resulting scheme is quite expensive but 
+\emph{positive}. It can be used on both active and passive tracers. This scheme is tested 
+and compared with MUSCL and the MPDATA scheme in \citet{Levy2001}; note that 
+in this paper it is referred to as "FCT" (Flux corrected transport) 
+rather than TVD.
+
+For stability reasons in (\ref{Eq_tra_adv_tvd}) $\tau _u^{cen2}$ is evaluated using the 
+\textit{now} velocity (leap-frog environment: centred in time) while $\tau _u^{ups}$ is 
+evaluated using the \textit{before} velocity (diffusive part: forward in time). 
+
+% -------------------------------------------------------------------------------------------------------------
+%        MUSCL scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection[MUSCL scheme  (\np{ln\_traadv\_muscl}=T)]
+	{Monotone Upstream Scheme for Conservative Laws (MUSCL) (\np{ln\_traadv\_muscl}=T)}
+\label{TRA_adv_muscl}
+
+The Monotone Upstream Scheme for Conservative Laws (MUSCL) has been 
+implemented by \citet{Levy2001}. In its formulation, the tracer at 
+velocity points is evaluated assuming a linear tracer variation between two 
+$T$-points (Fig.\ref{Fig_adv_scheme}). For example, in the $i$-direction :
+\begin{equation} \label{Eq_tra_adv_muscl}
+   \tau _u^{mus} = \left\{      \begin{aligned}
+         &\tau _i  &+ \frac{1}{2} \;\left( 1-\frac{u_{i+1/2} \;\Delta t}{e_{1u}} \right)
+         &\ \widetilde{\partial _i \tau}  & \quad \text{if }\;u_{i+1/2} \geqslant 0      \\
+         &\tau _{i+1/2} &+\frac{1}{2}\;\left( 1+\frac{u_{i+1/2} \;\Delta t}{e_{1u} } \right)
+         &\ \widetilde{\partial_{i+1/2} \tau } & \text{if }\;u_{i+1/2} <0
+   \end{aligned}    \right.
+\end{equation}
+where $\widetilde{\partial _i \tau}$ is the slope of the tracer 
+on which a limitation is imposed to ensure the \textit{positive} character of the scheme.
+
+The time stepping is performed using a forward scheme, that is the \textit{before} tracer 
+field is used to evaluate $\tau _u^{mus}$.
+
+For an ocean grid point abutted to land and where the ocean velocity is 
+toward land, two choices are available: use of an upstream flux 
+(\np{ln\_traadv\_muscl}=T) or use of second order flux 
+(\np{ln\_traadv\_muscl2}=T). Note that the latter choice does not insure the 
+\textit{positive} character of the scheme. Only the former can be used on both active and 
+passive tracers.
+
+% -------------------------------------------------------------------------------------------------------------
+%        UBS scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Upstream Biased Scheme (UBS) (\np{ln\_traadv\_ubs}=T)}
+\label{TRA_adv_ubs}
+
+The UBS advection scheme is an upstream biased third order scheme based on 
+an upstream-biased parabolic interpolation. It is also known as Cell 
+Averaged QUICK scheme (Quadratic Upstream Interpolation for Convective 
+Kinematics). For example, in the $i$-direction :
+\begin{equation} \label{Eq_tra_adv_ubs}
+   \tau _u^{ubs} =\overline T ^{i+1/2}-\;\frac{1}{6} \left\{      
+   \begin{aligned}
+         &\tau"_i        	& \quad \text{if }\ u_{i+1/2} \geqslant 0      \\
+         &\tau"_{i+1}	& \quad \text{if }\ u_{i+1/2}       <       0
+   \end{aligned}    \right.
+\end{equation}
+where $\tau "_i =\delta _i \left[ {\delta _{i+1/2} \left[ \tau \right]} \right]$.
+
+This results in a dissipatively dominant (i.e. hyper-diffusive) truncation 
+error \citep{Sacha2005}. The overall performance of the 
+advection scheme is similar to that reported in \cite{Farrow1995}. 
+It is a relatively good compromise between accuracy and smoothness. It is 
+not a \emph{positive} scheme meaning false extrema are permitted but the 
+amplitude of such are significantly reduced over the centred second order 
+method. Nevertheless it is not recommended to apply it to a passive tracer 
+that requires positivity. 
+
+The intrinsic diffusion of UBS makes its use risky in the vertical direction 
+where the control of artificial diapycnal fluxes is of paramount importance. 
+It has therefore been preferred to evaluate the vertical flux using the TVD 
+scheme when \np{ln\_traadv\_ubs}=T.
+
+For stability reasons, in \eqref{Eq_tra_adv_ubs}, the first term which corresponds to a 
+second order centred scheme is evaluated using the \textit{now} velocity (centred in 
+time) while the second term which is the diffusive part of the scheme, is 
+evaluated using the \textit{before} velocity (forward in time. This is discussed by \citet{Webb1998} in the context of the Quick advection scheme. UBS and QUICK 
+schemes only differ by one coefficient. Substituting 1/6 with 1/8 in 
+(\ref{Eq_tra_adv_ubs}) leads to the QUICK advection scheme \citep{Webb1998}. This 
+option is not available through a namelist parameter, since the 1/6 
+coefficient is hard coded. Nevertheless it is quite easy to make the 
+substitution in \mdl{traadv\_ubs} module and obtain a QUICK scheme
+
+NB 1: When a high vertical resolution $O(1m)$ is used, the model stability can 
+be controlled by vertical advection (not vertical diffusion which is usually 
+solved using an implicit scheme). Computer time can be saved by using a 
+time-splitting technique on vertical advection. This possibility have been 
+implemented and validated in ORCA05-L301. It is not currently offered in the 
+current reference version. 
+
+NB 2 : In a forthcoming release four options will be proposed for the 
+vertical component used in the UBS scheme. $\tau _w^{ubs}$ will be 
+evaluated using either \textit{(a)} a centred $2^{nd}$ order scheme , or  \textit{(b)} a TVD 
+scheme, or  \textit{(c)} an interpolation based on conservative parabolic splines 
+following \citet{Sacha2005} implementation of UBS in ROMS, 
+or  \textit{(d)} an UBS. The $3^{rd}$ case has dispersion properties similar to an 
+eight-order accurate conventional scheme.
+
+NB 3 : It is straight forward to rewrite \eqref{Eq_tra_adv_ubs} as follows:
+\begin{equation} \label{Eq_tra_adv_ubs2}
+\tau _u^{ubs} = \left\{	 \begin{aligned}
+	& \tau _u^{cen4} + \frac{1}{12} \tau"_i		& \quad \text{if }\ u_{i+1/2} \geqslant 0 \\
+	& \tau _u^{cen4} - \frac{1}{12} \tau"_{i+1}	& \quad \text{if }\ u_{i+1/2}       <       0
+  						 \end{aligned}    \right.
+\end{equation}
+or equivalently 
+\begin{equation} \label{Eq_tra_adv_ubs2}
+u_{i+1/2} \ \tau _u^{ubs} 
+=u_{i+1/2} \ \overline{ T - \frac{1}{6}\,\delta _i\left[ \delta_{i+1/2}[T] \,\right] }^{\,i+1/2}
+- \frac{1}{2} |u|_{i+1/2} \;\frac{1}{6} \;\delta_{i+1/2}[\tau"_i]
+\end{equation}
+\eqref{Eq_tra_adv_ubs2} has several advantages. First it clearly evidence that the UBS scheme is based on the fourth order scheme to which is added an upstream biased diffusive term. Second, this emphasises that the $4^{th}$ order part have to be evaluated at \emph{now} time step, not only the $2^{th}$ order part as stated above using \eqref{Eq_tra_adv_ubs} and also as it is coded in NEMO v2.3. Third, the diffusive term is in fact a biharmonic operator with a eddy coefficient with is simply proportional to the velocity: $A_u^{lm}= - \frac{1}{12}\,{e_{1u}}^3\,|u|$. Note that the current version of NEMO uses \eqref{Eq_tra_adv_ubs}, not \eqref{Eq_tra_adv_ubs2}. 
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        QCK scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{QUICKEST scheme (QCK) (\np{ln\_traadv\_qck}=T)}
+\label{TRA_adv_qck}
+
+The Quadratic Upstream Interpolation for Convective Kinematics with 
+Estimated Streaming Terms (QUICKEST) scheme proposed by \citet{Leonard1979} is 
+the third order Godunov scheme. It is associated with ULTIMATE QUICKEST 
+limiter \citep{Leonard1991}. It has been implemented in NEMO by G. Reffray 
+(MERCATOR-ocean).
+
+The resulting scheme is quite expensive but \emph{positive}. It can be used on both active 
+and passive tracers.
+
+% -------------------------------------------------------------------------------------------------------------
+%        PPM scheme  
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Piecewise Parabolic Method (PPM) (\np{ln\_traadv\_ppm}=T)}
+\label{TRA_adv_ppm}
+
+The Piecewise Parabolic Method (PPM) proposed by Colella and Woodward (1984) 
+is based on a quadradic piecewise rebuilding. As QCK scheme, it is associated with 
+ULTIMATE QUICKEST limiter \citep{Leonard1991}. It has been implemented in \NEMO by G. Reffray (MERCATOR-ocean) but is not yet offered in the current reference 
+version.
+
+% ================================================================
+% Tracer Lateral Diffusion
+% ================================================================
+\section{Tracer Lateral Diffusion (\mdl{traldf})}
+\label{TRA_ldf}
+%-----------------------------------------nam_traldf------------------------------------------------------
+\namdisplay{nam_traldf}
+%-------------------------------------------------------------------------------------------------------------
+ 
+The options available for lateral diffusion are laplacian (rotated or not) 
+or biharmonic operators, that latter being more scale-selective (more 
+diffusive at small scales). The specification of eddy diffusivity 
+coefficients (either constant, variable in space and time) as well as the 
+computation of the slope along which the operators act are performed in 
+\mdl{ldftra} and \mdl{ldfslp} modules, respectively. This is described in Chap.~\ref{LDF}. The lateral diffusion of tracers is evaluated using a forward scheme, 
+i.e. the tracers appearing in its expression are the \textit{before} tracers in time, 
+except for the pure vertical component that appears when a tensor of 
+rotation is used. This latter term is solved implicitly together with the 
+vertical diffusion term (see \S\ref{DOM_nxt}) 
+
+% -------------------------------------------------------------------------------------------------------------
+%        Iso-level laplacian operator
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Iso-level laplacian operator (\mdl{traldf\_lap}, \np{ln\_traldf\_lap}) }
+\label{TRA_ldf_lap}
+
+A laplacian diffusive operator (i.e. a harmonic operator) acting along the model surfaces is given by: 
+\begin{equation} \label{Eq_tra_ldf_lap}
+\begin{split}
+D_T^{lT} =\frac{1}{e_{1T} \; e_{2T}\;  e_{3T} } &\left[ {\quad \delta _i 
+\left[ {A_u^{lT} \left( {\frac{e_{2u} e_{3u} }{e_{1u} }\;\delta _{i+1/2} 
+\left[ T \right]} \right)} \right]} \right.
+\\
+&\ \left. {+\; \delta _j \left[ 
+{A_v^{lT} \left( {\frac{e_{1v} e_{3v} }{e_{2v} }\;\delta _{j+1/2} \left[ T 
+\right]} \right)} \right]\quad } \right]
+\end{split}
+\end{equation}
+
+This lateral operator is a \emph{horizontal} one (i.e. acting along geopotential surfaces) in 
+$z$-coordinate with or without partial step, but it is simply an iso-level operator in $s$-coordinate. 
+It is thus used when, in addition to \np{ln\_traldf\_lap}=T, we have \np{ln\_traldf\_level}=T, or both \np{ln\_traldf\_hor}=T and \np{ln\_zco}=F. In both cases, it significantly contributes to diapycnal mixing. It is therefore not recommended to use it.
+
+\textit{Notes} : In pure z-coordinate (\key{zco} defined), $e_{3u}=e_{3v}=e_{3T}$, so that the vertical scale factors disappear from (\ref{Eq_tra_ldf_lap}). 
+
+\textit{Notes} : In partial step $z$-coordinate (\np{ln\_zps}=T), tracers in horizontally adjacent cells are located at different depths in vicinity of the bottom. In this case, horizontal derivatives in (\ref{Eq_tra_ldf_lap}) at the bottom level require a specific treatment. They are calculated in module zpshde, described in \S\ref{TRA_zpshde}.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Rotated laplacian operator
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Rotated laplacian operator (\mdl{traldf\_iso}, \np{ln\_traldf\_lap})}
+\label{TRA_ldf_iso}
+
+The general form of the second order lateral tracer subgrid scale physics (\ref{Eq_PE_zdf}) takes the following semi-discrete space form in $z$- and $s$-coordinates:
+
+\begin{equation} \label{Eq_tra_ldf_iso}
+\begin{split}
+ D_T^{lT} =& \frac{1}{e_{1T}\,e_{2T}\,e_{3T} }
+ \\
+& \left\{ {\delta _i \left[ {A_u^{lT}  \left( 
+	 {\frac{e_{2u} \; e_{3u} }{e_{1u} } \,\delta _{i+1/2}[T]
+	-e_{2u} \; r_{1u} \,\overline{\overline {\delta _{k+1/2}[T]}}^{\,i+1/2,k}}
+ \right)} \right]} \right. 
+\\ 
+& +\delta 
+_j \left[ {A_v^{lT} \left( {\frac{e_{1v}\,e_{3v} }{e_{2v} 
+}\,\delta _{j+1/2} \left[ T \right]-e_{1v}\,r_{2v} 
+\,\overline{\overline {\delta _{k+1/2} \left[ T \right]}} ^{\,j+1/2,k}} 
+\right)} \right] 
+\\ 
+& +\delta 
+_k \left[ {A_w^{lT} \left( 
+-e_{2w}\,r_{1w} \,\overline{\overline {\delta _{i+1/2} \left[ T \right]}} ^{\,i,k+1/2}
+\right.} \right. 
+\\ 
+& \qquad \qquad \quad 
+-e_{1w}\,r_{2w} \,\overline{\overline {\delta _{j+1/2} \left[ T \right]}} ^{\,j,k+1/2}
+\\
+& \left. {\left. { 
+ \quad \quad \quad \left. {{\kern 
+1pt}+\frac{e_{1w}\,e_{2w} }{e_{3w} }\,\left( {r_{1w} ^2+r_{2w} ^2} 
+\right)\,\delta _{k+1/2} \left[ T \right]} \right)} \right]\;\;\;} \right\} 
+ \end{split}
+ \end{equation}
+where $r_1$ and $r_2$ are the slopes between the surface of computation ($z$- or $s$-surfaces) and the surface along which the diffusive operator acts ($i.e.$ horizontal or iso-neutral surfaces). 
+ It is thus used when, in addition to \np{ln\_traldf\_lap}=T, we have \np{ln\_traldf\_iso}=T, or both \np{ln\_traldf\_hor}=T and \np{ln\_zco}=T. The way these slopes are evaluated is given in \S\ref{LDF_slp}. At the surface, bottom and lateral boundaries, the turbulent fluxes of heat and salt are set to zero using the mask technique (see \S\ref{LBC_coast}). 
+
+The operator in \eqref{Eq_tra_ldf_iso} involves both lateral and vertical derivatives. For numerical stability, the vertical second derivative must be solved using the same implicit time scheme as those used in the vertical physics (see \S\ref{TRA_zdf}). For computer efficiency reasons, this term is not computed in \mdl{traldf} module, but in \mdl{trazdf} module where, if iso-neutral mixing is used, the vertical mixing coefficient is simply increased by $\frac{e_{1w}\,e_{2w} }{e_{3w} }\ \left( {r_{1w} ^2+r_{2w} ^2} \right)$. 
+
+This formulation conserves the tracer but does not ensure the decrease of the tracer variance. Nevertheless the treatment performed on the slopes (see \S\ref{LDF}) allows to run safely without any additional background horizontal diffusion \citep{Guily2001}. An alternate scheme \citep{Griffies1998} which preserves both tracer and its variance is currently been tested in \NEMO.
+
+Note that in partial step $z$-coordinate (\np{ln\_zps}=T), the horizontal derivatives in \eqref{Eq_tra_ldf_iso} at the bottom level require a specific treatment. They are calculated in module zpshde, described in \S\ref{TRA_zpshde}.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Iso-level bilaplacian operator
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Iso-level bilaplacian operator (\mdl{traldf\_bilap}, \np{ln\_traldf\_bilap})}
+\label{TRA_ldf_bilap}
+
+The lateral fourth order operator formulation on tracers is obtained by applying (\ref{Eq_tra_ldf_lap}) twice. It requires an additional assumption on boundary conditions: first and third derivative terms normal to the coast are set to zero.
+
+It is used when, in addition to \np{ln\_traldf\_bilap}=T, we have \np{ln\_traldf\_level}=T, or both \np{ln\_traldf\_hor}=T and \np{ln\_zco}=F. In both cases, it can contributes to diapycnal mixing even if it should be less than in the laplacian case. It is therefore not recommended to use it.
+
+\textit{Notes:} In the code, the bilaplacian routine does not call twice the laplacian 
+routine but is rather a specific routine. This is due to the fact that we 
+introduce the eddy diffusivity coefficient, A, in the operator as: $\nabla 
+\cdot \nabla \left( {A\nabla \cdot \nabla T} \right)$ and instead of 
+$-\nabla \cdot a\nabla \left( {\nabla \cdot a\nabla T} \right)$ where 
+$a=\sqrt{|A|}$ and $A<0$. This was a mistake: both formulations 
+ensure the total variance decrease, but the former requires a larger number 
+of code-lines. It will be corrected in a forthcoming release.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Rotated bilaplacian operator
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Rotated bilaplacian operator (\mdl{traldf\_bilapg}, \np{ln\_traldf\_bilap})}
+\label{TRA_ldf_bilapg}
+
+The lateral fourth order operator formulation on tracers is obtained by applying (\ref{Eq_tra_ldf_iso}) twice. It requires an additional assumption on boundary conditions: first and third derivative terms normal to the coast, the bottom and the surface are set to zero.
+
+ It is used when, in addition to \np{ln\_traldf\_bilap}=T, we have \np{ln\_traldf\_iso}=T, or both \np{ln\_traldf\_hor}=T and \np{ln\_zco}=T. Nevertheless, this rotated bilaplacian operator has never been seriously tested. No warranties that it is neither free of bugs or correctly formulated. 
+Moreover, the stability range of such an operator will be probably quite narrow, requiring a significantly smaller time-step than the one used on unrotated operator.
+
+% ================================================================
+% Tracer Vertical Diffusion
+% ================================================================
+\section{Tracer Vertical Diffusion (\mdl{trazdf})}
+\label{TRA_zdf}
+%--------------------------------------------namzdf---------------------------------------------------------
+\namdisplay{namzdf}
+%--------------------------------------------------------------------------------------------------------------
+
+The formulation of the vertical subgrid scale tracer physics is the same for all the vertical coordinates, based on a laplacian operator. The vertical diffusive operator given by (\ref{Eq_PE_zdf}) takes the following semi-discrete space form:
+\begin{equation} \label{Eq_tra_zdf}
+\begin{split}
+D^{vT}_T &= \frac{1}{e_{3T}} \; \delta_k \left[ 
+\frac{A^{vT}_w}{e_{3w}}  \delta_{k+1/2}[T] 	\right] 
+\\
+D^{vS}_T &= \frac{1}{e_{3T}} \; \delta_k \left[ 
+\frac{A^{vS}_w}{e_{3w}}  \delta_{k+1/2}[S] 	\right] 
+\end{split}
+\end{equation}
+
+where $A_w^{vT}$ and $A_w^{vS}$ are the vertical eddy diffusivity 
+coefficients on Temperature and Salinity, respectively. Generally, $A_w^{vT}=A_w^{vS}$ ecept when double diffusion mixing is parameterised (\key{zdfddm} defined). The way these coefficients can be evaluated is given in \S\ref{ZDF} (ZDF). Furthermore, when iso-neutral mixing is used, the both mixing coefficient are increased by $\frac{e_{1w}\,e_{2w} }{e_{3w} }\ \left( {r_{1w} ^2+r_{2w} ^2} \right)$ to account for the vertical second derivative of \eqref{Eq_tra_ldf_iso}. 
+
+At the surface and bottom boundaries, the turbulent fluxes of momentum, heat and salt must be specified. At the surface they are prescribed from the surface forcing (see \S\ref{TRA_sbc}), while at the bottom they are set to zero for heat and salt, unless a geothermal flux forcing is prescribed as a bottom boundary condition (\S\ref{TRA_bbc}). 
+
+The large eddy coefficient found in the mixed layer together with high 
+vertical resolution implies a too restrictive constraint on the time step in 
+explicit time stepping case (\np{ln\_zdfexp}=True). Therefore, the default implicit time stepping is generally preferred for the vertical diffusion as it overcomes the stability 
+constraint. A forward time differencing scheme (\np{ln\_zdfexp}=T) using a time splitting technique (\np{n\_zdfexp} $> 1$) is provided as an alternative. Namelist variables 
+\np{ln\_zdfexp} and \np{n\_zdfexp} apply to both tracers and dynamics. 
+
+% ================================================================
+% External Forcing
+% ================================================================
+\section{External Forcing}
+\label{TRA_sbc_qsr_bbc}
+
+% -------------------------------------------------------------------------------------------------------------
+%        surface boundary condition
+% -------------------------------------------------------------------------------------------------------------
+\subsection{surface boundary condition (\mdl{trasbc})}
+\label{TRA_sbc}
+
+The surface boundary condition for tracers is implemented in a separate 
+module (\mdl{trasbc}) instead of entering as a boundary condition on the vertical 
+diffusion operator (as in the case of momentum). This has been found to 
+enhance readability of the code. The two formulations are completely 
+equivalent; the forcing terms in trasbc are the surface fluxes divided by 
+the thickness of the top model layer. Following \citet{Roullet2000} the 
+forcing on an ocean tracer, $c$, can be split into two parts: $F_{ext}^C $, the 
+flux of tracer crossing the sea surface and not linked with the water 
+exchange d at the surface with the atmosphere, and $F_{wf}^C$ the forcing 
+on the concentration associated with the water flux. The latter forcing has 
+also two components: a direct effect of change in concentration associated 
+with the tracer carried by the water flux, and an indirect concentration/dilution effect :
+\begin{equation*}
+\begin{split}
+ F^C &= F_{ext} + F_{wf}^d                                          +F_{wf}^i  	\\
+\\ 
+        &= F_{ext} - \left( c_E \, E - c_p \,P - c_R \,R \right) +c\left( E-P-R \right)
+\end{split}
+\end{equation*} 
+
+Two cases must be distinguished, the nonlinear free surface case (\key{vvl} defined) and the linear free surface case. The first case is simpler, because the indirect concentration/dilution effect is naturally taken into 
+account by letting the vertical scale factors vary in time. The salinity of 
+water exchanged at the surface is assumed to be zero, so there is no salt 
+flux at the free surface, excepted in the presence of sea ice. The heat flux 
+at the free surface is the sum of $F_{ext}$, the direct heating/cooling 
+(by the total non-penetrative heat flux) and $F_{wf}^e$ the heat carried by 
+the water exchanged through the surface (evaporation, precipitation, 
+runoff). The temperature of precipitations is not well known. In the model 
+we assume that this water has the same temperature as the sea surface 
+temperature, The resulting forcing terms for temperature T and salinity S 
+are: 
+\begin{equation} \label{Eq_tra_forcing}
+\begin{aligned}
+ &F^T =\frac{Q_{ns} }{\rho _o \;C_p \,e_{3T} }-\frac{\text{EMP}\;\left. T 
+\right|_{k=1} }{e_{3T} }  & \\ 
+\\
+& F^S =\frac{\text{EMP}_S\;\left. S \right|_{k=1} }{e_{3T} }   &
+ \end{aligned}
+\end{equation} 
+
+where EMP is the freshwater budget (evaporation minus precipitation minus river runoff) which forces the ocean volume, $Q_{ns}$ is the non-penetrative part of the net surface heat flux (difference between the total surface heat flux and the fraction of the short wave flux that penetrates in the water column), the product EMP$_S\;.\left. S \right|_{k=1}$ is  the ice-ocean salt flux, and $\left. S\right|_{k=1}$ is the sea surface salinity (\textit{SSS}). The total salt content is conserved in this formulation (excepted for the effect of the Asselin filter).
+%AMT note: the ice-ocean flux had been forgotten in the first release of the key_vvl option, 
+%AMT  has this been corrected in the code? 
+
+In the second case (linear free surface), the vertical scale factors are fixed in time so that the concentration/dilution effect must be added in trasbc. Because of the hypothesis made for the temperature of precipitation and runoffs, for temperature $F_{wf}^e +F_{wf}^i =0$. The resulting forcing term for temperature is: 
+
+\begin{equation} \label{Eq_tra_forcing_q}
+F^T=\frac{Q_{ns} }{\rho _o \;C_p \,e_{3T} }
+\end{equation} 
+
+The salinity forcing is still given by \eqref{Eq_tra_forcing} but the definition of EMP$_S$ is 
+different: it is the total surface freshwater budget (evaporation minus 
+precipitation minus river runoff plus the rate of change of the sea ice 
+thickness). The total salt content is not exactly conserved (\citet{Roullet2000}, see also 
+\S\ref{PE_free_surface}).
+
+In the case of the rigid lid approximation, the surface salinity forcing $F^s$ 
+is also expressed by \eqref{Eq_tra_forcing} but now the global integral of the product 
+EMP*S is not compensated by the advection of fluid through the top level: in 
+the rigid lid case (contrary to the linear free surface), because \textit{w(k=1) = 0}. As a 
+result, even if the budget of \textit{EMP} is zero in average over the whole ocean 
+domain, the associated salt flux is not, as sea-surface salinity and \textit{EMP} are 
+intrinsically correlated (high \textit{SSS} are found where evaporation is strong while 
+low \textit{SSS} is usually associated with high precipitation or river runoff input).
+
+The $Q_{ns} $ and \textit{EMP} fields are defined and updated in \mdl{sbcmod} module (see 
+\S\ref{SBC}).
+
+% -------------------------------------------------------------------------------------------------------------
+%        Solar Radiation Penetration 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Solar Radiation Penetration (\mdl{traqsr})}
+\label{TRA_qsr}
+%--------------------------------------------namqsr---------------------------------------------------------
+\namdisplay{namqsr}
+%--------------------------------------------------------------------------------------------------------------
+
+When the penetrative solar radiation option is used (\np{ln\_flxqsr}=T, the solar radiation penetrates the top few meters of the ocean, otherwise all the heat flux is absorbed in the first ocean level (\np{ln\_flxqsr}=F). A term is thus added to the time evolution equation of temperature \eqref{Eq_PE_tra_T} while the surface boundary condition is modified to take into account only the non-penetrative part of the surface heat flux:
+\begin{equation} \label{Eq_PE_qsr}
+\begin{split}
+\frac{\partial T}{\partial t} &= {\ldots} + \frac{1}{\rho_o\, C_p \,e_3} \; \frac{\partial I}{\partial k}	\\
+Q_{ns} &= Q_\text{Total} - Q_{sr}
+\end{split}
+\end{equation}
+
+where $I$ is the downward irradiance. The additional term in \eqref{Eq_PE_qsr} is discretized as follows:
+\begin{equation} \label{Eq_tra_qsr}
+\frac{1}{\rho_o\, C_p \,e_3} \; \frac{\partial I}{\partial k} \equiv \frac{1}{\rho_o\, C_p\, e_{3T}} \delta_k \left[ I_w \right]
+\end{equation}
+
+A formulation including extinction coefficients is assumed for the downward irradiance $I$ 
+\citep{Paulson1977}:
+\begin{equation} \label{Eq_traqsr_iradiance}
+I(z) = Q_{sr} \left[Re^{-z / \xi_1} + \left( 1-R\right) e^{-z / \xi_2} \right]
+\end{equation}
+where $Q_{sr}$ is the penetrative part of the surface heat flux, 
+$\xi_1$ and $\xi_2$ are two extinction length scales and $R$ determines the relative 
+contribution of the two terms. The default values used correspond to a Type 
+I water in Jerlov's [1968] classification: $\xi_1 = 0.35m$, $\xi_2 = 0.23m$ and 
+$R = 0.58$ ((corresponding to \np{xsi1}, \np{xsi2} and \np{rabs} namelist parameters, respectively). $I$ is masked (no flux through the ocean bottom), so all the solar radiation that reaches the last ocean level is absorbed in that level. The trend in \eqref{Eq_tra_qsr} associated with the penetration of the solar radiation is added to the temperature trend and the surface heat flux modified in routine \mdl{traqsr}. Note that in $z$-coordinates, the depth of $T-$levels depends on the single variable $k$. A one dimensional array of the coefficients $gdsr(k) = Re^{-z_w (k)/\xi_1} + (1-R)e^{-z_w (k)/\xi_2}$ can then be computed once and saved in central memory. Moreover \textit{nksr}, the level at which $gdrs$ becomes negligible (less than the computer precision) is computed once and the trend associated with the penetration of the solar radiation is only added until that level. At last, note that when the ocean is shallow (< 200~m), the part of the solar radiation can reach the ocean floor. In this case, we have chosen that all the radiation is absorbed at the last ocean level ($i.e.$ $I_w$ is masked). 
+
+When coupling with a biology model (PISCES or LOBSTER), it is possible to calculate the light attenuation using information from the biology model. At the time of this writing, reading the light attenuation from a file is not implemented yet in the reference version.
+
+\colorbox{yellow}{case 4 bands and bio-coupling to add !!!}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Bottom Boundary Condition
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Bottom Boundary Condition (\mdl{trabbc} + \key{bbc})}
+\label{TRA_bbc}
+%--------------------------------------------nambbc--------------------------------------------------------
+\namdisplay{nambbc}
+%--------------------------------------------------------------------------------------------------------------
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_geothermal}  \begin{center}
+\includegraphics[width=1.0\textwidth]{./Figures/Fig_TRA_geoth.pdf}
+\caption{Geothermal Heat flux (in $mW.m^{-2}$) as inferred from the age of the sea floor and the formulae of \citet{Stein1992}.}
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+Usually it is considered that there is no exchange of heat nor salt through 
+the ocean bottom, i.e. a no flux boundary condition is applied on active 
+tracers at the bottom. This is the default option in NEMO, and it is 
+implemented using the masking technique. Nevertheless, there exists a 
+non-zero heat flux across the seafloor that is associated with the solid 
+earth cooling. This flux is weak compared with surface fluxes --- a mean 
+global value of $\sim0.1\;W/m^2$ \citep{Stein1992} --- but it is 
+systematically positive and it acts only on the densest water masses. Taking 
+this flux into account in a global ocean model increases by a few Sverdrups 
+the deepest overturning cell (i.e. the one associated with the Antarctic 
+Bottom Water). 
+
+The presence or not of a geothermal heating is controlled by the namelist 
+parameter  \np{ngeo\_flux}. Set to 1, a constant geothermal heatingis 
+introducted which value is given by the \np{ngeo\_flux\_const}, also a 
+namelist parameter. Set to 2, a spatially varying geothermal heat flux is 
+introducted which is provided in the geothermal\_heating.nc NetCDF 
+file (Fig.\ref{Fig_geothermal}).
+
+% ================================================================
+% Bottom Boundary Layer
+% ================================================================
+\section{Bottom Boundary Layer (\mdl{trabbl} + \key{bbl\_diff} or \key{bbl\_adv})}
+\label{TRA_bbl}
+%--------------------------------------------nambbl---------------------------------------------------------
+\namdisplay{nambbl}
+%--------------------------------------------------------------------------------------------------------------
+
+In z-coordinate configuration, the bottom topography is represented as a 
+series of discrete steps. This is not adequate to represent gravity driven 
+downslope flows. Such flows arise downstream of sills such as the Strait of 
+Gibraltar, Bab El Mandeb, or Denmark Strait, where dense water formed in 
+marginal seas flows into a basin filled with less dense water. The amount of 
+entrainment that occurs in those gravity plumes is critical to determine the 
+density and volume flux of the densest waters of the ocean, such as the 
+Antarctic Bottom water, or the North Atlantic Deep Water. $z$-coordinate 
+models tend to overestimate the entrainment because the gravity flow is 
+mixed down vertically by convection as it goes ``downstairs'' following the 
+step topography, sometimes over a thickness much larger than the thickness 
+of the observed gravity plume. A similar problem occurs in $s$-coordinate when 
+the thickness of the bottom level varies in large proportions downstream of 
+a sill \citep{Willebrand2001}, and the thickness of the plume is not 
+resolved. 
+
+The idea of the bottom boundary layer parameterization first introduced by 
+\citet{BeckDos1998} is to allow a direct communication between 
+two adjacent bottom cells at varying level, whenever the densest water is 
+located above the less dense water. The communication can be by diffusive 
+fluxes (diffusive BBL), advective fluxes (advective BBL) or both. Only 
+tracers are modified, not the velocities. Implementing a BBL 
+parameterization for momentum is a more complex problem because of the 
+pressure gradient errors. 
+
+% -------------------------------------------------------------------------------------------------------------
+%        Diffusive BBL
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Diffusive Bottom Boundary layer (\mdl{trabbl})}
+\label{TRA_bbl_diff}
+
+The lateral diffusivity $A_l^\sigma $ in the BBL can be prescribed with a 
+spatial dependence, e.g., in the conditional form
+\begin{equation} \label{Eq_tra_bbl}
+A_l^\sigma (i,j,t)=\left\{ {\begin{array}{l}
+ \mbox{large}\quad if\;\nabla \rho \cdot \nabla H<0 \\ 
+ \\
+ 0\quad \quad \;\,\mbox{otherwise} \\ 
+ \end{array}} \right.
+\end{equation} 
+
+The large value of the coefficient when the diffusive BBL is active is given 
+by the namelist parameter \np{atrbbl.}
+
+% -------------------------------------------------------------------------------------------------------------
+%        Advective BBL
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Advective Bottom Boundary Layer (\mdl{trabb\_adv})}
+\label{TRA_bbl_adv}
+
+Implemented in NEMO v2. 
+
+\colorbox{yellow} {Documentation to be added here }
+
+% ================================================================
+% Tracer damping
+% ================================================================
+\section{Tracer damping (\mdl{tradmp})}
+\label{TRA_dmp}
+%--------------------------------------------namdmp-----------------------------------------------------
+\namdisplay{namdmp}
+%--------------------------------------------------------------------------------------------------------------
+
+In some applications it can be useful to add a Newtonian damping term in the 
+temperature and salinity equations:
+\begin{equation} \label{Eq_tra_dmp}
+\begin{split}
+ \frac{\partial T}{\partial t}=\;\cdots \;-\gamma \,\left( {T-T_o } \right)  \\
+\\ 
+ \frac{\partial S}{\partial t}=\;\cdots \;-\gamma \,\left( {S-S_o } \right) 
+ \end{split}
+ \end{equation} 
+where $\gamma$ is the inverse of a time scale, and $T_o$ and $S_o$ are given temperature and salinity fields (usually a climatology). The restoring term is added when \key{tradmp} is defined. It also requires that both \key{temdta} and \key{saldta} are defined ($i.e.$ that $T_o$ and $S_o$ are read). The restoring coefficient $S_o$ is a three-dimensional array initialized by the user in 
+\rou{dtacof} routine also located in  \mdl{tradmp}. 
+
+The two main cases in which \eqref{Eq_tra_dmp} is used are \textit{(a)} the specification of 
+the boundary conditions along artificial walls of a limited domain basin and 
+\textit{(b)} the computation of the velocity field associated with a given $T$-$S$ field 
+(for example to build the initial state of a prognostic simulation, or to 
+use the resulting velocity field for a passive tracer study). The first case 
+applies to regional models that have artificial walls instead of open 
+boundaries. In the vicinity of these walls, $S_o$ takes large values 
+(equivalent to a few day time scale) whereas it is zero in the interior of 
+the model domain. The second case corresponds to the use of the robust 
+diagnostic method \citep{Sarmiento1982}. It allows to find the velocity 
+field consistent with the model dynamics while having a $T$-$S$ field close to a 
+given climatology field ($T_o -S_o$). The time scale associated with 
+$S_o$ is generally not a constant but spatially varying in order to respect 
+some considerations. For example, it is usually set to zero in the mixed 
+layer (defined either on a density or $S_o$ criterion) \citep{Madec1996} and in the equatorial region \citep{Reverdin1991, Fujio1991, MartiTh1992} as those two regions have a small time scale of adjustment, 
+while smaller $S_o$ are used in the deep ocean where the typical time scale 
+is long \citep{Sarmiento1982}. In addition it is reduced (and even 
+zero) along the western boundary to allow the model to reconstruct its own 
+western boundary structure in equilibrium with its physics. The choice of a 
+Newtonian damping acting in the mixed layer or not is controlled by \np{nmldmp} 
+(\textbf{namelist} \np{nmldmp}parameter).
+
+The robust diagnostic method is very efficient to prevent the temperature drift in intermediate waters but it produces artificial sources of heat and salt within the ocean. It has also undesirable effects on the ocean convection. It tends to prevent deep convection and subsequent deep-water formation by stabilising too much the water columns.
+
+An example of computation of $S_o$ for robust diagnostic experiments with the ORCA2 model is provided in the \mdl{tradmp} module (subroutines \rou{dtacof} and \rou{cofdis} which compute coefficient and the distance to the bathymetry, respectively). Those routines are provided as examples and can be customised by the user. 
+
+% ================================================================
+% Tracer time evolution
+% ================================================================
+\section{Tracer time evolution (\mdl{tranxt})}
+\label{TRA_nxt}
+%--------------------------------------------namdom-----------------------------------------------------
+\namdisplay{namdom}
+%--------------------------------------------------------------------------------------------------------------
+
+The general framework of dynamics time stepping is a leap-frog scheme, $i.e.$ a three level centred time scheme associated with a Asselin time filter (cf. \S\ref{DOM_nxt}):
+\begin{equation} \label{Eq_tra_nxt}
+\begin{split}
+T^{t+\Delta t} &= T^{t-\Delta t} + 2 \, \Delta t  \ \text{RHS}_T^t 	\\
+\\
+T_f^t  \;\ \quad &= T^t \;\quad +\gamma \,\left[ {T_f^{t-\Delta t} -2T^t+T^{t+\Delta t}} \right]
+\end{split}
+\end{equation} 
+
+where $\text{RHS}_T$ is the right hand side of the temperature equation, the subscript $f$ denotes 
+filtered values and $\gamma$ is the Asselin coefficient. $\gamma$ is initialized as \np{atfp} (\textbf{namelist} parameter). Its default value is \np{atfp=0.1}. 
+
+When the vertical mixing is solved implicitly, the update of the next tracer 
+fields is done in module \mdl{trazdf}. In that case only the swap of arrays 
+and the Asselin filtering is done in \mdl{tranxt} module.
+
+In order to prepare the computation of the next time step, a swap of tracer arrays is performed: $T^{t-\Delta t} = T^t$ and $T^t = T_f$. 
+
+% ================================================================
+% Equation of State (eosbn2) 
+% ================================================================
+\section{Equation of State (\mdl{eosbn2}) }
+\label{TRA_eosbn2}
+%--------------------------------------------nameos-----------------------------------------------------
+\namdisplay{nameos}
+%--------------------------------------------------------------------------------------------------------------
+
+% -------------------------------------------------------------------------------------------------------------
+%        Equation of State
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Equation of State (\np{neos} = 0, 1 or 2)}
+\label{TRA_eos}
+
+It is necessary to know the equation of state for the ocean very accurately to determine stability properties (especially the Brunt-Vais\"{a}l\"{a} frequency), particularly in the deep ocean. The ocean density is a non linear empirical function of \textit{in situ }temperature, salinity and pressure. The reference is the equation of state defined by the Joint Panel on Oceanographic Tables 
+and Standards \citep{UNESCO1983}. It was the standard equation of state used in early releases of OPA. Even though this computation is fully vectorised, it is quite time consuming ($15$ to $20${\%} of the total CPU time) as it requires the prior computation of the \textit{in situ} temperature from the model \textit{potential} temperature using the \citep{Bryden1973} polynomial for adiabatic lapse rate and a $4^th$ order Runge-Kutta integration scheme. Since OPA6, we have chosen the \citet{JackMcD1995} equation of state for seawater. It allows the computation of the \textit{in situ} ocean density directly as a function of \textit{potential} temperature relative to the sea surface (an OPA variable), the practical salinity (another OPA variable) and the pressure (assuming no pressure variation along geopotential surfaces, i.e. the pressure in decibars is 
+approximated by the depth in meters). Both the \citet{UNESCO1983} and \citet{JackMcD1995} equations of state have the same expression except that the values of the various coefficients have been adjusted by \citet{JackMcD1995} in order to use directly the \textit{potential} temperature instead of the \textit{in situ} one. This reduces the CPU time of the in situ density computation to about $3${\%} of the total CPU time, while maintaining a quite accurate equation of state.
+
+In the computer code, a \textit{true} density, $d$, is computed, i.e. the ratio of seawater volumic mass over $\rho_o$, a reference volumic mass (\textit{rau0} defined in \mdl{phycst}, usually $rau0= 1,020~Kg/m^3$). The default option (\np{neos}=0) is the \citet{JackMcD1995} equation of state. It is highly recommended to use it. Nevertheless, for process studies, it is often convenient to use a linear approximation of the density$^{\ast}$\footnote{$^{\ast }$ With the linear equation of state there is no longer 
+a distinction between \textit{in situ} and \textit{potential} density. Cabling and thermobaric effects are also removed.}. Two linear formulations are available: a function of $T$ only (\np{neos}=1) and a function of both $T$ and $S$ (\np{neos}=2):
+\begin{equation} \label{Eq_tra_eos_linear}
+\begin{aligned}
+ d(T)    &= {\rho (T)} / {\rho _0 } &&= 1.028 - \alpha \;T     \\ 
+ d(T,S) &= {\rho (T,S)}                &&= \ \ \ \beta \;S - \alpha \;T 
+\end{aligned}
+\end{equation} 
+where $\alpha $ and $\beta $ are the thermal and haline expansion coefficients, and $\rho_o$, the reference volumic mass, $rau0$. $\alpha $ and $\beta$ can be modified through \np{ralpha} and \np{rbeta} namelist parameters). Note that when $d$ is a function of $T$ only (\np{neos}=1), the salinity is a passive tracer and can be used as such.
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        Brunt-Vais\"{a}l\"{a} Frequency
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Brunt-Vais\"{a}l\"{a} Frequency (\np{neos} = 0, 1 or 2)}
+\label{TRA_bn2}
+
+An accurate computation of the ocean stability (i.e. of $N$, the brunt-Vais\"{a}l\"{a} frequency) is of paramount importance as it is used in several ocean parameterisations (namely TKE, KPP, Richardson number dependent vertical diffusion, enhanced vertical diffusion, non-penetrative convection, iso-neutral diffusion). In particular, one must be aware that $N^2$ has to be computed with an \textit{in situ} reference. The expression of $N^2$ depends on the type of equation of state used (\np{neos} namelist parameter).
+
+For \np{neos}=0 (\citet{JackMcD1995} equation of state), the \citet{McDougall1987} 
+polynomial expression is used with the pressure in decibar approximated by 
+the depth in meters: 
+\begin{multline} \label{Eq_tra_bn2}
+N^2 =	\frac{g}{e_{3w}} \; \beta ( \overline{T}^{\,k+1/2},\widetilde{S},z_w )   \\
+		\left\{  \alpha / \beta ( \overline{T}^{\,k+1/2},\widetilde{S},z_w )
+			\ \delta_{k+1/2}[T]     - \delta_{k+1/2}[S]
+		 \right\}
+\end{multline} 
+where $T$ is the \textit{potential} temperature, $\widetilde{S}=\overline{S}^{\,k+1/2} - 35.$ a salinity anomaly, and $\alpha$ ($\beta\,$) the thermal (haline) expansion coefficient. Both $\alpha$ and $\beta$ depend on \textit{potential} temperature, salinity which are averaged at $w$-points prior to the computation.
+
+When a linear equation of state is used (\np{neos}=1 or 2, \eqref{Eq_tra_bn2} reduces to:
+\begin{equation} \label{Eq_tra_bn2_linear}
+N^2 =	\frac{g}{e_{3w}} \left(   \beta \;\delta_{k+1/2}[S] - \alpha \;\delta_{k+1/2}[T]   \right)
+\end{equation} 
+where $\alpha$ and $\beta $ are the constant coefficients used to defined the linear 
+equation of state \eqref{Eq_tra_eos_linear}.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Specific Heat
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Specific Heat (\textit{rcp}, \mdl{phycst})}
+\label{TRA_adv_ldf}
+
+The specific heat of sea water, $C_p$, is a function of temperature, salinity and pressure \citep{UNESCO1983}. It is only used in the model to convert surface heat fluxes into surface temperature increase, thus the pressure dependence is neglected. The dependence on $T$ and $S$ is weak. For example, with $S=35~psu$, $C_p$ increases from $3989$ to $4002$ when $T$ varies from -2~\degres C to 31~\degres C. Therefore, $C_p$ has been chosen as a constant: $C_p=4.10^3~J\,Kg^{-1}\,\degres K^{-1}$. Its computer name is \textit{rcp} and its value is set in \mdl{phycst} module.
+
+% -------------------------------------------------------------------------------------------------------------
+%        Freezing Point of Seawater
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Freezing Point of Seawater (\mdl{ocfzpt})}
+\label{TRA_fzp}
+
+The freezing point of seawater is a function of salinity and pressure \citep{UNESCO1983}:
+\begin{equation} \label{Eq_tra_eos_fzp}
+   \begin{split}
+T_f (S,p) &= \left( -0.0575 + 1.710523 \;10^{-3} \, \sqrt{S} 
+						     -  2.154996 \;10^{-4} \,S  \right) \ S    \\
+               & - 7.53\,10^{-3}\,p 
+   \end{split}
+\end{equation}
+
+\eqref{Eq_tra_eos_fzp} is only used to compute the potential freezing point of sea water 
+($i.e.$ referenced to the surface $p=0$), thus the pressure dependent terms in \eqref{Eq_tra_eos_fzp} (last term) has been dropped. The \textit{before} and \textit{now} surface freezing point is introduced in the code as $fzptb$ and $fzptn$ 2D arrays together with a  \textit{now} mask (\textit{freezn}) which takes 0 or 1 whether the ocean temperature is above or at the freezing point. Caution: do not confuse \textit{freezn} with the fraction of lead (\textit{frld}) defined in LIM. 
+
+% ================================================================
+% Horizontal Derivative in zps-coordinate 
+% ================================================================
+\section{Horizontal Derivative in \textit{zps}-coordinate (\mdl{zpshde})}
+\label{TRA_zpshde}
+
+With partial bottom cells (\np{ln\_zps}=T), tracers in horizontally adjacent cells generally live at different depths. Horizontal gradients of tracers are needed for horizontal diffusion (\mdl{traldf} module) and for the hydrostatic pressure gradient (\mdl{dynhpg} module). Before taking horizontal gradients between the tracers next to the bottom, a linear interpolation is used to approximate the deeper tracer as if it actually lived at the depth of the shallower tracer point (Fig.~\ref{Fig_Partial_step_scheme}). For example on temperature in the i-direction, the needed interpolated temperature, $\widetilde{T}$, is:
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!p] \label{Fig_Partial_step_scheme}  \begin{center}
+\includegraphics[width=0.9\textwidth]{./Figures/Partial_step_scheme.pdf}
+\caption{ Discretisation of horizontal derivative and mean of tracers in z-partial step coordinate (\np{ln\_zps}=T) in the case $( e3w_k^{i+1} - e3w_k^i  )>0$. A linear interpolation is used to estimate $\widetilde{T}_k^{i+1}$, the tracer value at the depth of the shallower tracer point of the two adjacent bottom $T$-points. The horizontal derivative is then given by: $\delta _{i+1/2} T_k=  \widetilde{T}_k^{\,i+1} -T_k^{\,i}$ and the mean by: $\overline{T}_k^{\,i+1/2}= ( \widetilde{T}_k^{\,i+1/2} - T_k^{\,i} ) / 2$.  }
+\end{center}   \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{equation*}
+\widetilde{T}= \left\{  \begin{aligned}  
+&T^{\,i+1}      -\frac{ \left( e_{3w}^{i+1} -e_{3w}^i \right)}{ e_{3w}^{i+1} }\;\delta _k T^{i+1}	
+ 								&& \quad\text{if  $\ e_{3w}^{i+1} \geq e_{3w}^i$   } 	\\
+										\\
+&T^{\,i} \ \ \ \,+\frac{ \left( e_{3w}^{i+1} -e_{3w}^i \right) }{e_{3w}^i       }\;\delta _k T^{i+1}
+			 					&& \quad\text{if  $\ e_{3w}^{i+1}    <   e_{3w}^i$   } 
+            \end{aligned}   \right.
+\end{equation*}
+and the resulting formulation of horizontal derivative and horizontal mean value of $T$ at $U$-point are: 
+\begin{equation} \label{Eq_zps_hde}
+\begin{aligned}
+ \delta _{i+1/2} T= 	\begin{cases}
+\ \ \ \widetilde {T}\quad\ -T^i	 	& \ \ \quad\quad\text{if  $\ e_{3w}^{i+1} \geq e_{3w}^i$ } \\
+										\\
+\ \ \ T^{\,i+1}-\widetilde{T}		& \ \ \quad\quad\text{if  $\ e_{3w}^{i+1}    <   e_{3w}^i$   } 
+            		\end{cases}     \\
+\\
+\overline {T}^{\,i+1/2} \ = 	\begin{cases}
+( \widetilde {T}\ \ \;\,-T^{\,i})	 / 2	& \;\ \ \quad\text{if  $\ e_{3w}^{i+1} \geq e_{3w}^i$ } \\
+										\\
+( T^{\,i+1}-\widetilde{T} ) / 2		& \;\ \ \quad\text{if  $\ e_{3w}^{i+1}    <   e_{3w}^i$   } 
+            \end{cases}
+\end{aligned}
+\end{equation}
+
+The computation of horizontal derivative of tracers as well as of density is performed once for all at each time step in \mdl{zpshde} module and stored in shared arrays to be used when needed. It has to be emphasized that the computation of the interpolated density, $\widetilde{\rho}$, is not identical to the one of $T$ and $S$. Instead of forming a linear approximation of density, we compute $\widetilde{\rho }$ from the interpolated value of $T$ and $S$, and the pressure of at $u$-point (in the equation of state pressure is approximated by depth, see \S\ref{TRA_eos} ) : 
+\begin{equation} \label{Eq_zps_hde_rho}
+\widetilde{\rho } = \rho ( {\widetilde{T},\widetilde {S},z_u }) 
+\quad \text{where }\  z_u = \min \left( {z_T^{i+1} ,z_T^i } \right)
+\end{equation} 
+
+This is a much better approximation as the variation of $\rho$ with depth (and thus pressure) is highly non-linear with a true equation of state and thus is badly approximated with a linear interpolation. This approximation is used to compute both the horizontal pressure gradient (\S\ref{DYN_hpg}) and the slopes of neutral surfaces (\S\ref{LDF_slp})
+
+\textit{Notes}: in almost all the advection schemes presented in this Chapter, both mean and derivative operators appear. Yet, it has been chosen not to use \eqref{Eq_zps_hde} in those schemes.: contrary to diffusion and pressure gradient computation, no correction for partial steps is applied for advection.The main motivation was to preserve the domain averaged mean variance of the field advected when using $2^{nd}$ order centred scheme. Sensitivity of the advection schemes to the way horizontal means are performed in the vicinity of partial cells should be further investigated in a near future.
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_ZDF.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_ZDF.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Chap_ZDF.tex	(revision 4536)
@@ -0,0 +1,476 @@
+% ================================================================
+% Chapter Ñ Vertical Ocean Physics (ZDF)
+% ================================================================
+\chapter{Vertical Ocean Physics (ZDF)}
+\label{ZDF}
+\minitoc
+
+%gm% Add here a small introduction to ZDF and naming of the different physics (similar to what have been written for TRA and DYN.
+
+% ================================================================
+% Vertical Mixing
+% ================================================================
+\section{Vertical Mixing}
+\label{ZDF_zdf}
+
+The discrete form of the ocean subgrid scale physics has been presented in \S\ref{TRA_zdf} and \S\ref{DYN_zdf}. At the surface and bottom boundaries, the turbulent fluxes of momentum, heat and salt have to be defined. At the surface they are prescribed from the surface forcing (see Chap.~\ref{SBC}), while at the bottom they are set to zero for heat and salt, unless a geothermal flux forcing is prescribed as a bottom boundary condition ($i.e.$ \key{trabbl} defined, see \S\ref{TRA_bbc}), and specified through a bottom friction parameterization for momentum (see \S\ref{ZDF_bfr}).
+
+In this section we briefly discuss the various choices offered to compute 
+the vertical eddy viscosity and diffusivity coefficients, $A_u^{vm}$ , $A_v^{vm}$ and $A^{vT}$ ($A^{vS}$), defined at $uw$-, $vw$- and $w$-points, respectively (see \S\ref{TRA_zdf} and \S\ref{DYN_zdf}). These coefficients can be assumed to be either constant, or a function of the local Richardson number, or computed from a turbulent closure model (either TKE or KPP formulation). The computation of these coefficients is initialized in \mdl{zdfini} module and performed in \mdl{zdfric}, \mdl{zdftke} or \mdl{zdfkpp} modules. The trends due to the vertical momentum and tracer diffusion, including the surface forcing, 
+are computed and added to the general trend in \mdl{dynzdf} and \mdl{trazdf} modules, respectively. These trends can be computed using either a forward time scheme (cpp variable 
+\np{np\_zdfexp} or a backward time scheme (default option) depending on the magnitude of the mixing coefficients used, and thus of the formulation used (see \S\ref{DOM_nxt}).
+
+% -------------------------------------------------------------------------------------------------------------
+%        Constant 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Constant (\key{zdfcst})}
+\label{ZDF_cst}
+%--------------------------------------------namzdf---------------------------------------------------------
+\namdisplay{namzdf}
+%--------------------------------------------------------------------------------------------------------------
+
+When the \key{zdfcst} is defined, the momentum and tracer vertical eddy coefficients are set to 
+constant values over the whole ocean. This is the crudest way to define the 
+vertical ocean physics. It is recommended to use this option only in process 
+studies, not in basin scale simulation. Typical values used in this case 
+are:
+\begin{align*} 
+A_u^{vm} = A_v^{vm} &= 1.2\ 10^{-4}~m^2.s^{-1} 	\\
+\\
+A^{vT} = A^{vS} &= 1.2\ 10^{-5}~m^2.s^{-1}
+\end{align*}
+
+These values are set through \np{avm0} and \np{avt0} namelist parameters. In any case, do not use 
+values smaller that those associated to the molecular viscosity and diffusivity, that is $\sim10^{-6}~m^2.s^{-1}$ for momentum, $\sim10^{-7}~m^2.s^{-1}$ for temperature and $\sim10^{-9}~m^2.s^{-1}$ for salinity.
+
+
+% -------------------------------------------------------------------------------------------------------------
+%        Richardson Number Dependent
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Richardson Number Dependent (\key{zdfric})}
+\label{ZDF_ric}
+
+%--------------------------------------------namric---------------------------------------------------------
+\namdisplay{namric}
+%--------------------------------------------------------------------------------------------------------------
+
+When \key{zdfric} is defined, a local Richardson number dependent formulation of the vertical momentum and tracer eddy coefficients is set. The vertical mixing coefficients are diagnosed from the large scale variables computed by the model (order 0.5 closure scheme). \textit{In situ} measurements allow to link vertical turbulent activity to large scale ocean structures. The hypothesis of a mixing mainly maintained by the growth of Kelvin-Helmholtz like instabilities leads to a dependency between the vertical turbulent eddy coefficients and the local Richardson number ($i.e.$ ratio of stratification over vertical shear). Following \citet{PacPhil1981}, the following formulation has been implemented:
+\begin{equation} \label{Eq_zdfric}
+   \left\{      \begin{aligned}
+         A^{vT} &= \frac {A_{ric}^{vT}}{\left( 1+a \; Ri \right)^n} + A_b^{vT}       \\
+         \\
+         A^{vm} &= \frac{A^{vT}        }{\left( 1+ a \;Ri  \right)   } + A_b^{vm}
+   \end{aligned}    \right.
+\end{equation}
+where $Ri = N^2 / \left(\partial_z \textbf{U}_h \right)^2$ is the local Richardson number, $N$ is the local brunt-Vais\"{a}l\"{a} frequency (see \S\ref{TRA_bn2}), $A_b^{vT} $ and $A_b^{vm}$ are the constant background values set as in constant case (see \S\ref{ZDF_cst}), and $A_{ric}^{vT} = 10^{-4}~m^2.s^{-1} $ is the maximum value that can be reached by the coefficient when $Ri\leq 0$, $a=5$ and $n=2$. The last three coefficients can be modified by setting \np{avmri}, \np{alp} and \np{nric} namelist parameter, respectively.
+
+% -------------------------------------------------------------------------------------------------------------
+%        TKE Turbulent Closure Scheme 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{TKE Turbulent Closure Scheme (\key{zdftke})}
+\label{ZDF_tke}
+
+%--------------------------------------------namtke---------------------------------------------------------
+\namdisplay{nam_tke}
+%--------------------------------------------------------------------------------------------------------------
+
+The vertical eddy viscosity and diffusivity coefficients are computed from a TKE turbulent closure model based on a prognostic equation for $\bar {e}$, the turbulent kinetic energy, and a closure assumption for the turbulent length scales. This turbulent closure model has been developed by \citet{Bougeault1989} in atmospheric cases, adapted by \citet{Gaspar1990} for oceanic cases, and embedded in OPA by \citet{Blanke1993} for equatorial Atlantic simulations. Since then, significant modifications have been introduced by \citet{Madec1998} in both the implementation and the formulation of the mixing length scale. The time evolution of $\bar{e}$ is the result of the production of $\bar{e}$ through vertical shear, its destruction through stratification, its vertical diffusion and its dissipation of \citet{Kolmogorov1942} type:
+\begin{equation} \label{Eq_zdftke_e}
+\frac{\partial \bar{e}}{\partial t} = 
+\frac{A^{vm}}{e_3 }\;\left[ {\left( {\frac{\partial u}{\partial k}} \right)^2
+							+\left( {\frac{\partial v}{\partial k}} \right)^2} \right]
+-A^{vT}\,N^2
++\frac{1}{e_3}	\;\frac{\partial }{\partial k}\left[ {\frac{A^{vm}}{e_3 }
+				\;\frac{\partial \bar{e}}{\partial k}} \right]
+- c_\epsilon \;\frac{\bar {e}^{3/2}}{l_\epsilon }
+\end{equation}
+\begin{equation} \label{Eq_zdftke_kz}
+   \begin{split}
+         A^{vm} &= C_k\  l_k\  \sqrt {\bar{e}}
+    \\
+         A^{vT} &= A^{vm} / P_{rt}
+   \end{split}
+\end{equation}
+where $N$ designates the local Brunt-Vais\"{a}l\"{a} frequency (see \S\ref{TRA_bn2}), 
+$l_{\epsilon }$ and $l_{\kappa }$ are the dissipation and mixing turbulent 
+length scales, $P_{rt} $ is the Prandtl number. The constants $C_k = \sqrt {2} /2$ and 
+$C_\epsilon = 0.1$ are designed to deal with vertical mixing at any depth \citep{Gaspar1990}. They are set through namelist parameter \np{ediff} and \np{ediss}. $P_{rt} $ can be 
+set to unity or, following \citet{Blanke1993}, be a function of the 
+local Richardson number, $R_i $:
+\begin{align*} \label{Eq_prt}
+P_{rt} = \begin{cases}
+                    \ \ \ 1 &      \text{if $\ R_i \leq 0.2$} 	\\
+                    5\,R_i &      \text{if $\ 0.2 \leq R_i \leq 2$} 	\\
+                    \ \ 10 &      \text{if $\ 2 \leq R_i$} 
+            \end{cases}
+\end{align*}
+Note that a horizontal Shapiro filter can be optionally applied to $R_i$. Nevertheless it is an obsolescent option that is notrecommanded.  The choice of $P_{rt} $ is controlled by \np{npdl} namelist parameter.
+
+For computational efficiency, the original formulation of the turbulent length scales proposed by \citet{Gaspar1990} has been simplified. Four formulations are proposed, the choice of which is controlled by \np{nmxl} namelist parameter. The first two are based on the following first order approximation \citep{Blanke1993}:
+\begin{equation} \label{Eq_tke_mxl0_1}
+l_k = l_\epsilon = \sqrt {2 \bar e} / N
+\end{equation}
+which is obtained in a stable stratified region with constant values of the brunt-Vais\"{a}l\"{a} frequency. The resulting turbulent length scale is bounded by the distance to the surface or to the bottom (\np{nmxl}=0) or by the local vertical scale factor (\np{nmxl}=1). \citet{Blanke1993} notice that this simplification has two major drawbacks: it has no sense for local unstable 
+stratification and the computation no longer uses the whole information contained in the vertical density profile. To overcome this drawbacks, \citet{Madec1998} introduces the \np{nmxl}=2 or 3 cases, which add of an hypothesis on the vertical gradient of the computed length scale. So, the length scales are first evaluated as in \eqref{Eq_tke_mxl0_1} and then bounded such that:
+\begin{equation} \label{Eq_tke_mxl_constraint}
+\frac{1}{e_3 }\left| {\frac{\partial l}{\partial k}} \right| \leq 1
+\qquad \text{with }\  l =  l_k = l_\epsilon
+\end{equation}
+
+\eqref{Eq_tke_mxl_constraint} means that the vertical variations of the length scale cannot be 
+larger than the variations of depth. It provides a better approximation of the \citet{Gaspar1990} formulation while being much less time consuming. In particular, it allows the length scale to be limited not only by the distance to the surface or to the ocean bottom but also by the distance to a 
+strongly stratified portion of the water column such as the thermocline (Fig.~\ref{Fig_mixing_length}). In order to imposed \eqref{Eq_tke_mxl_constraint} constraint, we introduce two additonnal length scal: $l_{up}$ and $l_{dwn}$, the upward and downward length scale, and evaluate the dissipation and mixing turbulent length scales as (caution here we use the numerical indexation):
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_mixing_length}  \begin{center}
+\includegraphics[width=1.00\textwidth]{./Figures/Fig_mixing_length.pdf}
+\caption {Illustration of the mixing length computation. }
+\end{center}  
+\end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{equation} \label{Eq_tke_mxl2}
+\begin{aligned}
+ l_{up  }^{(k)} &= \min \left(  l^{(k)} \ , \ l_{up}^{(k+1)} + e_{3T}^{(k)} \right)
+    \quad &\text{ from $k=1$ to $jpk$ }\ \\
+ l_{dwn}^{(k)} &= \min \left(  l^{(k)} \ , \ l_{dwn}^{(k-1)} + e_{3T}^{(k-1)}  \right)   
+    \quad &\text{ from $k=jpk$ to $1$ }\ \\
+\end{aligned}
+\end{equation}
+where $l^{(k)}$ is compute using \eqref{Eq_tke_mxl0_1}, $i.e.$ $l^{(k)} = \sqrt {2 \bar e^{(k)} / N^{(k)} }$.
+
+In the \np{nmxl}=2 case, the dissipation and mixing turbulent length scales take a same value: $ l_k=  l_\epsilon = \min \left(\ l_{up} \;,\;  l_{dwn}\ \right)$, while in the \np{nmxl}=2 case, the dissipation and mixing turbulent length scales are give as in \citet{Gaspar1990}:
+\begin{equation} \label{Eq_tke_mxl_gaspar}
+\begin{aligned}
+& l_k          = \sqrt{\  l_{up} \ \ l_{dwn}\ }  	\\
+& l_\epsilon = \min \left(\ l_{up} \;,\;  l_{dwn}\ \right) 
+\end{aligned}
+\end{equation}
+
+At the sea surface the value of $\bar{e}$ is prescribed from the wind 
+stress field: $\bar{e}=ebb\;\left| \tau \right|$ ($ebb=60$ by default) 
+with a minimal threshold of $emin0=10^{-4}~m^2.s^{-2}$ (namelist
+parameters). Its bottom value is assumed to be equal to the value of the level just above. The time 
+integration of the $\bar{e}$ equation may formally lead to negative values 
+because the numerical scheme does not ensure the positivity. To overcome 
+this problem, a cut-off in the minimum value of $\bar{e}$ is used. Following 
+\citet{Gaspar1990}, the cut-off value is set to $\sqrt{2}/2~10^{-6}~m^2.s^{-2}$. This allows the subsequent formulations to match 
+\citet{Gargett1984} one for the diffusion in the thermocline and deep ocean 
+$(A^{vT} = 10^{-3} / N)$. In addition, a 
+cut-off is applied on $A^{vm}$ and $A^{vT}$ to avoid numerical 
+instabilities associated with too weak vertical diffusion. They must be 
+specified at least larger than the molecular values, and are set through 
+\textit{avm0} and \textit{avt0} (\textbf{namelist} parameters).
+
+% -------------------------------------------------------------------------------------------------------------
+%        K Profile Parametrisation (KPP) 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{K Profile Parametrisation (KPP) (\key{zdfkpp}) }
+\label{ZDF_kpp}
+
+%--------------------------------------------namkpp--------------------------------------------------------
+\namdisplay{namkpp}
+%--------------------------------------------------------------------------------------------------------------
+
+The KKP scheme has been implemented by J. Chanut ...
+\colorbox{yellow}{Add a description of KPP here.}
+
+
+% ================================================================
+% Convection
+% ================================================================
+\section{Convection}
+\label{ZDF_conv}
+
+%--------------------------------------------namzdf--------------------------------------------------------
+\namdisplay{namzdf}
+%--------------------------------------------------------------------------------------------------------------
+
+Static instabilities (i.e. light potential densities under heavy ones) may 
+occur at particular ocean grid points. In nature, convective processes 
+quickly re-establish the static stability of the water column. These 
+processes have been removed from the model via the hydrostatic assumption: 
+they must be parameterized. Three parameterisations are available to deal 
+with convective processes: either a non-penetrative convective adjustment or 
+an enhanced vertical diffusion, or/and the use of a turbulent closure 
+scheme.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Non-Penetrative Convective Adjustment 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Non-Penetrative Convective Adjustment (\np{ln\_tranpc}=T) }
+\label{ZDF_npc}
+
+%--------------------------------------------namnpc--------------------------------------------------------
+\namdisplay{namnpc}
+%--------------------------------------------------------------------------------------------------------------
+
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!ht] \label{Fig_npc}  	\begin{center}
+\includegraphics[width=0.90\textwidth]{./Figures/Fig_npc.pdf}
+\caption {Example of an unstable density profile treated by the non penetrative convective adjustment algorithm. $1^{st}$ step: the initial profile is checked from the surface to the bottom. It is found to be unstable between levels 3 and 4. They are mixed. The resulting $\rho$ is still larger than $\rho$(5): levels 3 to 5 are mixed. The resulting $\rho$ is still larger than $\rho$(6): levels 3 to 6 are mixed. The $1^{st}$ step ends since the density profile is then stable below the level 3. $2^{nd}$ step: the new $\rho$ profile is checked following the same procedure as in $1^{st}$ step: levels 2 to 5 are mixed. The new density profile is checked. It is found stable: end of algorithm.}
+\end{center}  	\end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The non-penetrative convective adjustment algorithm is used when \np{ln\_zdfnpc}=T. It is applied at each \np{nnpc1} time step and mixes downwards instantaneously the statically unstable portion of the water column, but only until the density structure becomes neutrally stable ($i.e.$ until the mixed portion of the water column has \textit{exactly} the density of the water just below) \citep{Madec1991a}. This algorithm is an iterative process used in the following way 
+(Fig. \ref{Fig_npc}): going from the top of the ocean towards the bottom, the first 
+instability is searched. Assume in the following that the instability is 
+located between levels $k$ and $k+1$. The two levels are vertically mixed, for 
+potential temperature and salinity, conserving the heat and salt contents of 
+the water column. The new density is then computed by a linear 
+approximation. If the new density profile is still unstable between levels 
+$k+1$ and $k+2$, levels $k$, $k+1$ and $k+2$ are then mixed. This process is repeated until 
+stability is established below the level $k$ (the mixing process can go down to 
+the ocean bottom). The algorithm is repeated to check if the density profile 
+between level $k-1$ and $k$ is unstable and/or if there is no deeper instability.
+
+This algorithm is significantly different from mixing two by two statically unstable levels. The latter procedure cannot converge with a finite number 
+of iterations for some vertical profiles while the algorithm used in OPA 
+converges for any profile in a number of iterations less than the number of 
+vertical levels. This property is of paramount importance as pointed out by 
+\citet{Killworth1989}: it avoids the existence of permanent and unrealistic 
+static instabilities at the sea surface. This non-penetrative convective 
+algorithm has been proved successful in studying the deep water formation in 
+the north-western Mediterranean Sea \citep{Madec1991a, Madec1991b, Madec1991c}.
+
+Note that in this algorithm the potential density referenced to the sea 
+surface is used to check whether the density profile is stable or not. 
+Moreover, the mixing in potential density is assumed to be linear. This 
+assures the convergence of the algorithm even when the equation of state is 
+non-linear. Small static instabilities can thus persist due to cabbeling: 
+they will be treated at the next time step. Moreover, temperature and 
+salinity, and thus density, are mixed, but the corresponding velocity fields 
+remain unchanged. When using a Richardson dependent eddy viscosity, the 
+mixing of momentum is done through the vertical diffusion: after a static 
+adjustment, the Richardson number is zero and thus the eddy viscosity 
+coefficient is at a maximum. When this algorithm is used with constant 
+vertical eddy viscosity, spurious solution can occur as the vertical 
+momentum diffusion remains small even after a static adjustment. In that 
+latter case, we recommend to add momentum mixing in a manner that mimics the 
+mixing in temperature and salinity \citep{Speich1992, Speich1996}.
+
+%AMT This presentation fails to mention the big drawback of this scheme: many water masses of the world ocean, especially AABW, are unstable when represented in surface-referenced potential density sigma_0. The scheme erroneously mixes them up.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Enhanced Vertical Diffusion 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Enhanced Vertical Diffusion (\np{ln\_zdfevd}=T)}
+\label{ZDF_evd}
+
+%--------------------------------------------namzdf--------------------------------------------------------
+\namdisplay{namzdf}
+%--------------------------------------------------------------------------------------------------------------
+
+The enhanced vertical diffusion parameterization is used when \np{ln\_zdfevd} is 
+defined. In this case, the vertical eddy mixing coefficients are assigned to be very large (a typical value is $1\;m^2s^{-1})$ in regions where the stratification is unstable (i.e. when the Brunt-Vais\"{a}l\"{a} frequency is negative) \citep{Lazar1997, Lazar1999}. This is done either on tracers only (\np{n\_evdm}=0) or on both momentum and 
+tracers (\np{n\_evdm}=1) mixing coefficients.
+
+In practice, when $N^2\leq 10^{-12}$, $A_T^{vT}$ and $A_T^{vS}$ are set to a large value, 
+\np{avevd}, and  if \np{n\_evdm}=1, the four neighbouring $A_u^{vm} \;\mbox{and}\;A_v^{vm} $ . Typical value for $avevd$ is in-between 1 and $100~m^2.s^{-1}$. This parameterisation of convective processes is less time consuming than the convective adjustment algorithm presented above when mixing both tracers and momentum in case of static instabilities. It requires the use of an implicit time stepping on vertical diffusion terms (i.e. \np{ln\_zdfexp}=F). 
+
+% -------------------------------------------------------------------------------------------------------------
+%       Turbulent Closure Scheme 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Turbulent Closure Scheme (\key{zdftke})}
+\label{ZDF_tcs}
+
+The turbulent closure scheme presented in \S\ref{ZDF_tke} and used when the 
+\key{zdftke} is defined allows, in theory, to deal with 
+statically unstable density profiles. In such a 
+case, the term of destruction of turbulent kinetic energy through 
+stratification in \eqref{Eq_zdftke_e} becomes a source term as $N^2$ is negative. It 
+results large values of both $A_T^{vT}$ and the four neighbouring$A_u^{vm} 
+{and}\;A_v^{vm} $ (up to $1\;m^2s^{-1})$ that are able to restore the 
+static stability of the water column in a way similar to that of the 
+enhanced vertical diffusion parameterization (\S\ref{ZDF_evd}). Nevertheless, the 
+eddy coefficients computed by the turbulent scheme do usually not exceed
+$10^{-2}m.s^{-1}$ in the vicinity of the sea surface (first ocean layer) due to 
+the bound of the turbulent length scale by the distance to the sea surface 
+(see {\S}VI.7-c). It can thus be useful to combine the enhanced vertical 
+diffusion with the turbulent closure, i.e. defining \np{np\_zdfevd} and 
+\key{zdftke} CPP variables all together.
+
+The KPP scheme includes enhanced vertical diffusion in the case of convection, as governed by the variables $bvsqcon$ and $difcon$ found in \mdl{zdfkpp}, therefore \np{np\_zdfevd} should not be used with the KPP scheme. %gm%  + one word on non local flux with KPP scheme
+
+
+% ================================================================
+% Double Diffusion Mixing
+% ================================================================
+\section{Double Diffusion Mixing (\key{zdfddm})}
+\label{ZDF_ddm}
+
+%-------------------------------------------namddm--------------------------------------------------------
+\namdisplay{namddm}
+%--------------------------------------------------------------------------------------------------------------
+
+Double diffusion occurs when relatively warm, salty water overlies cooler, fresher water, or vice versa. The former condition leads to salt fingering and the latter to diffusive convection. Double-diffusive phenomena contribute to diapycnal mixing in extensive regions of the oceans.  \citet{Merryfield1999} include a parameterization of such phenomena in a global ocean model and show that it leads to relatively minor changes in circulation but exerts significant regional influences on temperature and salinity. 
+
+Diapycnal mixing of S and T are described by diapycnal diffusion coefficients 
+\begin{align*} % \label{Eq_zdfddm_Kz}
+    &A^{vT} = A_o^{vT}+A_f^{vT}+A_d^{vT}	\\
+    &A^{vS} = A_o^{vS}+A_f^{vS}+A_d^{vS}
+\end{align*}
+where subscript $f$ represents mixing by salt fingering, 
+$d$ by diffusive convection, and $o$ by processes other than 
+double diffusion. The rates of double-diffusive mixing depend on buoyancy ratio $R_\rho = \alpha \partial_z T / \partial_z S$, where $\alpha$ and $\beta$ are coefficients of thermal expansion and saline contraction (see \S\ref{TRA_eos}. To represent mixing of $S$ and $T$ by salt fingering, we adopt the diapycnal diffusivities suggested by Schmitt (1981):
+\begin{align} \label{Eq_zdfddm_f}
+A_f^{vS} &= 	\begin{cases}
+	\frac{A^{\ast v}}{1+(R_\rho / R_c)^n   } &\text{if  $R_\rho > 1$ and $N^2>0$ } \\
+	0 				  					    &\text{otherwise} 
+				\end{cases}   
+\\
+A_f^{vT} &= 0.7 \ A_f^{vS} / R_\rho 
+\end{align}
+
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+\begin{figure}[!t] \label{Fig_zdfddm}  \begin{center}
+\includegraphics[width=0.99\textwidth]{./Figures/Fig_zdfddm.pdf}
+\caption {From \citet{Merryfield1999} : (a) Diapycnal diffusivities $A_f^{vT}$ and $A_f^{vS}$ for temperature and salt in regions of salt fingering. Heavy curves denote $A^{\ast v} = 10^{-3}~m^2.s^{-1}$ and thin curves $A^{\ast v} = 10^{-4}~m^2.s^{-1}$ ; (b) diapycnal diffusivities $A_d^{vT}$ and $A_d^{vT}$ for temperature and salt in regions of diffusive convection. Heavy curves denote the Federov parameterization and thin curves the Kelley parameterization. The latter is not implemented in \NEMO }
+\end{center}    \end{figure}
+%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+The factor 0.7 in \eqref{Eq_zdfddm_f} reflects the measured ratio $\alpha F_T /\beta F_S \approx  0.7$ of buoyancy fluxes due to transport of heat and salt (e.g., McDougall and Taylor 1984). Following  \citet{Merryfield1999}, we adopt $R_c = 1.6$, $n = 6$, and $A^{\ast v} = 10^{-4}~m^2.s^{-1}$.
+
+To represent mixing of S and T by diffusive layering,  the diapycnal diffusivities suggested by Federov (1988) is used: 
+\begin{align} \label{Eq_zdfddm_d}
+A_d^{vT} &= 	\begin{cases}
+	1.3635 \, \exp{\left( 4.6\, \exp{ \left[  -0.54\,( R_{\rho}^{-1} - 1 )  \right] }    \right)}
+									&\text{if  $0<R_\rho < 1$ and $N^2>0$ } \\
+	0 								&\text{otherwise} 
+				\end{cases}   
+\\
+A_d^{vS} &= 	\begin{cases}
+	A_d^{vT}\ \left( 1.85\,R_{\rho} - 0.85 \right)
+									&\text{if  $0.5 \leq R_\rho<1$ and $N^2>0$ } \\
+	A_d^{vT} \ 0.15 \ R_\rho
+									&\text{if  $\ \ 0 < R_\rho<0.5$ and $N^2>0$ } \\
+	0 								&\text{otherwise} 
+				\end{cases}   
+\end{align}
+
+The dependences of \eqref{Eq_zdfddm_f} to \eqref{Eq_zdfddm_d} on $R_\rho$ are illustrated in Fig.~\ref{Fig_zdfddm}. Implementing this requires computing $R_\rho$ at each 
+grid point and time step. This is done in \mdl{eosbn2} at the same time as $N^2$ is computed. This avoids duplication in the computation of $\alpha$ and $\beta$ (which is usually quite expensive).
+
+
+% ================================================================
+% Bottom Friction
+% ================================================================
+\section{Bottom Friction}
+\label{ZDF_bfr}
+
+%--------------------------------------------nambfr--------------------------------------------------------
+\namdisplay{nambfr}
+%--------------------------------------------------------------------------------------------------------------
+
+Both surface momentum flux (wind stress) and the bottom momentum flux 
+(bottom friction) enter the equations as a condition on the vertical 
+diffusive flux. For the bottom boundary layer, one has:
+\begin{equation} \label{Eq_zdfbfr_flux}
+A^{vm} \left( \partial \textbf{U}_h / \partial z \right) = \textbf{F}_h
+\end{equation}
+where $\textbf{F}_h$ is supposed to represent the horizontal momentum flux 
+outside the logarithmic turbulent boundary layer (thickness of the order of 
+1~m in the ocean). How $\textbf{F}_h$ influences the interior depends on the 
+vertical resolution of the model near the bottom relative to the Ekman layer 
+depth. For example, in order to obtain an Ekman layer depth $d = \sqrt{2\;A^{vm}} / f = 50$~m, one needs a vertical diffusion coefficient $A^{vm} = 0.125$~m$^2$s$^{-1}$ (for a Coriolis 
+frequency $f = 10^{-4}$~m$^2$s$^{-1}$). With a background diffusion coefficient 
+$A^{vm} = 10^{-4}$~m$^2$s$^{-1}$, the Ekman layer depth is only 1.4~m. When the vertical mixing coefficient is this small, using a flux condition is equivalent to entering the 
+viscous forces (either wind stress or bottom friction) as a body force over 
+the depth of the top or bottom model layer. To illustrate this, consider the 
+equation for $u$ at $k$, the last ocean level:
+\begin{equation} \label{Eq_zdfbfr_flux2}
+\frac{\partial u \; (k)}{\partial t} = \frac{1}{e_{3u}} \left[ A^{vm} \; (k) \frac{U \; (k-1) - U \; (k)}{e_{3uw} \; (k-1)} - F_u \right] \approx - \frac{F_u}{e_{3u}}
+\end{equation}
+For example, if the bottom layer thickness is 200~m, the Ekman transport will be 
+distributed over that depth. On the other hand, if the vertical resolution 
+is high (1~m or less) and a turbulent closure model is used, the turbulent 
+Ekman layer will be represented explicitly by the model. However, the 
+logarithmic layer is never represented in current primitive equation model 
+applications: it is \emph{necessary} to parameterize the flux $\textbf{F}_h $. Two 
+choices are available in OPA: a linear and a quadratic bottom friction. Note 
+that in both cases, the rotation between the interior velocity and the 
+bottom friction is neglected in the present release of OPA.
+
+% -------------------------------------------------------------------------------------------------------------
+%       Linear Bottom Friction
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Linear Bottom Friction}
+\label{ZDF_bfr_linear}
+
+%-------------------------------------------nambfr--------------------------------------------------------
+\begin{flushright}
+(\textbf{namelist} !nbotfr :\textit{ nbotfr = 0, = 1 or = 3})
+\end{flushright}
+
+The linear bottom friction parameterization assumes that the bottom friction is proportional to the interior velocity (i.e. the velocity of the last model level):
+\begin{equation} \label{Eq_zdfbfr_linear}
+\textbf{F}_h = \frac{A^{vm}}{e_3} \; \frac{\partial \textbf{U}_h}{\partial k} = r \textbf{U}_h^b
+\end{equation}
+where $\textbf{U}_h^b$ is the horizontal velocity vector of the bottom 
+ocean layer and $r$ a friction coefficient expressed in m.s$^{-1}$. This 
+coefficient is generally estimated by setting a typical decay time $\tau $ in the 
+deep ocean, $r = H / \tau$. Commonly accepted values of $\tau$ are of the 
+order of 100 to 200 days \citep{Weatherly1984}. A value $\tau^{-1} = 10^{-7}$~s$^{-1}$ 
+corresponding to 115 days is usually used in quasi-geostrophic models. One may 
+consider the linear friction as an approximation of quadratic friction, 
+$r \approx 2\;C_D\;U_{av}$ (\citet{Gill1982}, Eq. 9.6.6). With a drag coefficient $C_D = 0.002$, a typical value of tidal currents $U_{av} =0.1$~m.s$^{-1}$, 
+and assuming an ocean depth $H = 4000$~m, the resulting friction 
+coefficient is $r = 4\;10^{-4}$~m.s$^{-1}$. This is the default value used in 
+OPA. It corresponds to a decay time scale of 115~days. It can be changed by 
+specifying \np{bfric1} (namelist parameter).
+
+In the code, the bottom friction is specified by updating the value of the 
+vertical eddy coefficient at the bottom level. Indeed, the discrete 
+formulation of (\ref{Eq_zdfbfr_linear}) at the last ocean $T-$level, using the fact that 
+$\textbf {U}_h =0$ inside the bottom, leads to
+\begin{equation} \label{Eq_zdfbfr_linKz}
+\begin{split}
+A_u^{vm} &= r\;e_{3uw}\\
+A_v^{vm} &= r\;e_{3uw}\\
+\end{split}
+\end{equation}
+
+Such an update is done in \mdl{zdfbfr} when \np{nbotfr}=1 and the value of $r$ used is 
+\np{bfric1}. Setting \np{nbotfr}=3 is equivalent to set $r=0$ and leads to a free-slip bottom boundary condition, 
+while setting \np{nbotfr}=0 imposes $r=2\;A_{vb}^{\rm {\bf U}} $, where $A_{vb}^{\rm {\bf U}} $ is the 
+background vertical eddy coefficient: a no-slip boundary condition is used. 
+Note that this latter choice generally leads to an underestimation of the 
+bottom friction: for a deepest level thickness of $200~m$ and $A_{vb}^{\rm {\bf U}} 
+=10^{-4}$m$^2$.s$^{-1}$, the friction coefficient is only $r=10^{-6}$m.s$^{-1}$.
+
+
+% -------------------------------------------------------------------------------------------------------------
+%       Non-Linear Bottom Friction
+% -------------------------------------------------------------------------------------------------------------
+\subsection{Non-Linear Bottom Friction}
+\label{ZDF_bfr_nonlinear}
+
+\begin{center}
+(\textbf{namelist} !nbotfr : \textit{nbotfr = 2})
+\end{center}
+
+The non-linear bottom friction parameterization assumes that the bottom 
+friction is quadratic: 
+\begin{equation} \label{Eq_zdfbfr_nonlinear}
+\textbf {F}_h = \frac{A^{vm}}{e_3 }\frac{\partial \textbf {U}_h 
+}{\partial k}=C_D \;\sqrt {u_b ^2+v_b ^2+e_b } \;\; \textbf {U}_h^b 
+\end{equation}
+
+with $\textbf{U}_h^b = (u_b\;,\;v_b)$ the horizontal interior velocity (i.e. the horizontal velocity of the bottom ocean layer), $C_D$ a drag coefficient, and $e_b $ a bottom turbulent kinetic energy due to tides, internal waves breaking and other short time scale currents. A typical value of the drag coefficient is $C_D = 10^{-3} $. As an example, the CME experiment \citep{Treguier1992} uses $C_D = 10^{-3}$ and $e_b = 2.5\;10^{-3}$m$^2$.s$^{-2}$, while the FRAM experiment \citep{Killworth1992} uses $e_b =0$ 
+and $e_b =2.5\;\;10^{-3}$m$^2$.s$^{-2}$. The FRAM choices have been set as 
+default value (\np{bfric2} and \np{bfeb2} namelist parameters).
+
+As for the linear case, the bottom friction is specified in the code by 
+updating the value of the vertical eddy coefficient at the bottom level:
+
+\begin{equation} \label{Eq_zdfbfr_nonlinKz}
+\begin{split}
+A_u^{vm} &=C_D\; e_{3uw} \left[ u^2 + \left(\bar{\bar{v}}^{i+1,j}\right)^2 + e_b \right]^
+{1/2}\\
+A_v^{vm} &=C_D\; e_{3uw} \left[  \left(\bar{\bar{u}}^{i+1,j}\right)^2 + v^2 + e_b \right]^{1/2}\\
+\end{split}
+\end{equation}
+
+This update is done in \mdl{zdfbfr}. The coefficients that control the strength of the 
+non-linear bottom friction are initialized as namelist parameters: ($C_D$= \np{bfri2}, and $e_b$ =\np{bfeb2}).
+
+% ================================================================
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Introduction.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Introduction.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Chapters/Introduction.tex	(revision 4536)
@@ -0,0 +1,69 @@
+
+% ================================================================
+% INTRODUCTION
+% ================================================================
+
+\chapter{Introduction}
+
+The Nucleus for European Modelling of the Ocean (\NEMO) is a framework of ocean related engines, namely OPA for the Ocean dynamics and thermodynamics, LIM for the sea-ice dynamics and thermodynamics, TOP for the biogeochemistry (both transport (TRP) and sources minus sinks (LOBSTER, PISCES). It is intended to be a flexible tool for studying the ocean and its interactions with the others components of the earth climate system (atmosphere, sea-ice, biogeochemical tracers, ...) over a wide range of space and time scales. This documentation provides information about the physics represented by the OPA ocean model and the rationale for the choice of numerical schemes and the model design. More specific information about running the model on different computers, or how to set up a configuration, are found on the \NEMO web site (www.locean-ipsl.upmc.fr/NEMO). 
+
+The ocean component of \NEMO has been developed from the OPA8.2 model described in \citet{Madec1998}. This model has been used for a wide range of applications, either regional or global, as a forced ocean model or coupled with the atmosphere. A complete list of references is found on the \NEMO web site. 
+
+This manual is organised in as follows. Chapter~\ref{PE} presents the model basics, $i.e.$ the equations and their assumptions, the vertical coordinates used, and the subgrid scale physics. This part deals with the continuous equations of the model (primitive equations, with potential temperature, salinity and an equation of state). The equations are written in a curvilinear coordinate system, with a choice of vertical coordinates (z, s, and variable volumes). Momentum equations are formulated in the vector invariant form. The model equations are written in dimensional units in the meter, kilogram, second (MKS) international system.
+
+The following chapters deal with the discrete equations. Chapter~\ref{DOM} presents the space and time domain. The model is discretised on a staggered grid (Arakawa C grid) with masking of land areas. Vertical discretisation uses $z$-coordinates (including partial step), $s$- (terrain-following) coordinate (fixed volume thickness and linear free surface), or $s*$-coordinate (variable volume thickness and nonlinear free surface). The following chapters describe the discretisation of the  prognostic  equations (momentum and tracers). Explicit, split-explicit or implicit free surface formulations are implemented as well as arid-lid approximation. A number of numerical schemes are available for momentum advection, for the computation of the pressure gradients, as well as for the advection of tracers (second or higher order advection schemes, including positive ones).
+
+Other model characteristics are the lateral boundary conditions (chapter~\ref{LBC}).  Global configurations of the model make use of the ORCA tripolar grid, with special north fold boundary condition. Free-slip or no-slip boundary conditions are allowed at land boundaries. Closed basin geometries as well as periodic domains and open boundary conditions are possible. 
+
+Surface boundary conditions (chapter~\ref{SBC}) can be implemented as prescribed fluxes, or bulk formulations for the surface fluxes (wind stress, heat, freshwater). The model allows penetration of solar radiation  There is an optional geothermal heating at the ocean bottom. Within the \NEMO system the ocean model is interactively coupled with a sea ice model (LIM) and with biogeochemistry models (PISCES, LOBSTER). Interactive coupling to Atmospheric models is possible via the OASIS coupler \citep{OASIS2006}. 
+
+Physical parameterisations are described in chapters~\ref{LDF} and \ref{ZDF}. The model includes an implicit treatment of vertical viscosity and diffusivity. The lateral Laplacian and biharmonic viscosity and diffusion can be rotated following a geopotential or neutral direction. There is an optional eddy induced velocity \citep{Gent1990} with a space and time variable coefficient \citet{Treguier1997}. The model has vertical harmonic viscosity and diffusion with a space and time variable coefficient, with options to compute the coefficients with \citet{Blanke1993}, \citet{Large1994}, or \citet{PacPhil1981} mixing schemes.
+
+Specific online diagnostics (not documented yet) are available in the model: output of all the tendencies of the momentum and tracers equations, output of tracers tendencies averaged over the time evolving mixed layer.
+
+The model is implemented in \textsc{Fortran 90}, with preprocessing (C-pre-processor). It runs under UNIX. It is optimized for vector computers and parallelised by domain  decomposition with MPI. All input and output is done in NetCDF (Network Common Data Format) with a optional direct access format for output. To ensure the clarity and readability of the code it is necessary to follow coding rules. The coding rules for OPA include conventions for naming variables, with different starting letters for different types of variables (real, integer, parameter\ldots) Those rules are presented in a document available on the \NEMO web site..
+
+The model is organized with a high internal modularity based on physics. In particular, each trend (e.g., a term in the rhs of the prognostic equation) for momentum and tracers is computed in a dedicated module.  To make it easier for the user to find his way around the code, the module names follow the three-letter rule.  Each module name is made of three-letter sequences. For example, \mdl{tradmp} is a module related to the TRAcers equation, computing the DaMPing. The complete list of module names is presented in annex. Furthermore, modules are  organized in a few directories that correspond to their category, as indicated by the first three letters of their name. 
+The manual follows this organization. After the presentation of the continuous equations (Chapter \ref{PE}), the following chapters refer to specific terms of the equations each associated with a group of modules .
+
+
+\begin{table}[htbp] \label{tab1}
+%\begin{center} \begin{tabular}{|p{143pt}|l|l|}	\hline
+\begin{center} \begin{tabular}{|l|l|l|}	\hline
+Chapter \ref{DOM}	& DOM		& Model DOMain \\		\hline
+Chapter \ref{TRA}	& TRA		& TRAcer equations (potential temperature and salinity) \\   \hline
+Chapter \ref{DYN}	& DYN		& DYNamic equations (momentum) \\		\hline
+Chapter \ref{SBC} 	& SBC		& Surface Boundary Conditions \\			\hline
+Chapter \ref{LBC}	& LBC		& Lateral Boundary Conditions  \\ 		\hline
+Chapter \ref{LDF}	& LDF		& Lateral DiFfusion (parameterisations) \\	\hline
+Chapter \ref{ZDF}	& ZDF		& Vertical DiFfusion  \\		\hline
+Chapter \ref{MISC}	& ...		& Miscellaneous  topics	 \\			\hline
+\end{tabular} 	\end{center}
+\end{table}
+
+In the current release (v2.3), LBC directory (see Chap.~\ref{LBC}) does not yet exist. When created LBC will gather OBC directory (Open Boundary Condition), \mdl{lbclnk}, \mdl{mppini} and \mdl{lib\_mpp} modules. 
+
+ \vspace{1cm}   Nota Bene : \vspace{0.25cm}
+
+OPA, like all research tools, is in perpetual evolution. The present document describes the OPA model include in the release 2.3 of NEMO. This release differs significantly from version 8, documented in \citet{Madec1998}. The major modifications are :\\
+(1) transition to full native \textsc{Fortran} 90, deep code restructuring and drastic reduction of CPP keys, \\
+(2) introduction of partial step representation of bottom topography \\
+(3) partial reactivation of a terrain-following vertical coordinate ($s$- and hybrid $s$-$z$) with the addition of several options for pressure gradient computation \footnote{Partial support of $s$-coordinate: there is presently no support for neutral physics in $s$-coordinate and for the new options for horizontal pressure gradient computation with true equation of state.}, \\ 
+(4) more choices for the treatment of the free surface: full explicit, split-explicit , filtered and rigid-lid \\
+(5) non linear free surface option (variable level thickness distributed on the whole water column) \\
+(6) additional schemes for vector and flux forms of the momentum  advection \\
+(7) addition of several advection schemes on tracers \\
+ (8) implementation of the AGRIF package (Adaptative Grid Refinement in \textsc{Fortran} ) \\
+(9) online diagnostics : tracers trend in the mixed layer and vorticity balance \\
+(10) rewriting of the I/O management \\
+(11) OASIS 3 and 4 couplers interfacing with atmospheric global circulation models. 
+
+In addition, several minor modifications in the coding have been introduced with the constant concern of improving performance on both scalar and vector computers. 
+
+At the time of this writing, the current release is NEMO 2.3. The new surface module described in this document is not yet part of the current distribution.
+
+
+\colorbox{red}{Red color}: not in the current reference version (v2.3) but expected soon.
+ 
+\colorbox{yellow}{Yellow color}: missing references, text to be updated.
+
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO.ist
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO.ist	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO.ist	(revision 4536)
@@ -0,0 +1,3 @@
+delim_0 "\\dotfill"
+delim_1 "\\dotfill"
+delim_2 "\\dotfill"
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO_book.tex
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO_book.tex	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/NEMO_book.tex	(revision 4536)
@@ -0,0 +1,270 @@
+%description: Book template
+
+% template of document for LaTeX
+% (C) Xavier Perseguers 2002 - xavier.perseguers@epfl.ch
+
+\documentclass[a4paper,12pt]{book}
+
+% ================================================================
+% HEADERS DEFINITION
+% ================================================================
+
+\usepackage[french]{babel}
+\usepackage{fancyhdr}
+
+\usepackage{alltt}  		%%  alltt for namelist
+\usepackage{verbatim}  	%%  alltt for namelist
+
+%\usepackage{amssymb}
+\pagestyle{fancy}
+% with this we ensure that the chapter and section
+% headings are in lowercase.
+\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
+\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
+\fancyhf{}             % delete current setting for header and footer
+\fancyhead[LE,RO]{\bfseries\thepage}
+\fancyhead[LO]{\bfseries\hspace{-0em}\rightmark}
+\fancyhead[RE]{\bfseries\leftmark}
+\renewcommand{\headrulewidth}{0.5pt}
+\renewcommand{\footrulewidth}{0pt}
+\addtolength{\headheight}{2.6pt}   % make space for the rule
+%\addtolength{\headheight}{1.6pt}   % make space for the rule
+\fancypagestyle{plain}{
+  \fancyhead{}         % get rid of headers on plain pages
+  \renewcommand{\headrulewidth}{0pt}  % and the line
+}
+
+% Leave blank pages completely empty, w/o header
+\makeatletter
+\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
+  \hbox{}
+  \vspace*{\fill}
+  \vspace{\fill}
+  \thispagestyle{empty}
+  \newpage
+  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
+\makeatother
+
+\usepackage{makeidx}
+
+\usepackage{minitoc}				%in french : \usepackage[french]{minitoc}
+
+%\usepackage{mtcoff}				% invalidate the use of minitocs
+\usepackage[latin1]{inputenc}
+\usepackage{graphics}				% allows insertion of pictures
+\usepackage{times}					% use vector fonts instead of bitmap
+\usepackage{fancybox}
+\usepackage{color}
+\usepackage{colortbl}
+
+%%%% add by Word2Tex
+%\documentclass{amsart}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{amsmath}
+\usepackage{graphicx}
+%%%%
+
+%%%%
+%\usepackage{mathtime}      % font for illustrator to work (belleek fonts )
+%%%%
+
+%\usepackage{showidx}				% show the index entry
+
+
+
+%%%% define the style of title for chapter  %%%
+\usepackage{pstricks}
+\makeatletter
+\def\LigneVerticale{\vrule height 5cm depth 2cm\hspace{0.1cm}\relax}
+\def\LignesVerticales{%
+  \let\LV\LigneVerticale\LV\LV\LV\LV\LV\LV\LV\LV\LV\LV}
+\def\GrosCarreAvecUnChiffre#1{%
+  \rlap{\vrule height 0.8cm width 1cm depth 0.2cm}%
+  \rlap{\hbox to 1cm{\hss\mbox{\white #1}\hss}}%
+  \vrule height 0pt width 1cm depth 0pt}
+\def\GrosCarreAvecTroisChiffre#1{%
+  \rlap{\vrule height 0.8cm width 1.6cm depth 0.2cm}%
+  \rlap{\hbox to 1.5cm{\hss\mbox{\white #1}\hss}}%
+  \vrule height 0pt width 1cm depth 0pt}
+
+\def\@makechapterhead#1{\hbox{%
+    \huge 
+    \LignesVerticales
+    \hspace{-0.5cm}%
+    \GrosCarreAvecUnChiffre{\thechapter}
+    \hspace{0.2cm}\hbox{#1}%
+%    \GrosCarreAvecTroisChiffre{\thechapter}
+%    \hspace{1cm}\hbox{#1}%
+%}\par\vskip 2cm}
+}\par\vskip 1cm}
+\def\@makeschapterhead#1{\hbox{%
+    \huge 
+    \LignesVerticales
+    %\hspace{0.5cm}%
+    \hbox{#1}%
+}\par\vskip 2cm}
+
+%\def\thechapter{\Roman{chapter}}   	% chapter number to be Roman
+
+%%%% end style chapter %%%
+
+%%% eqution shortcut:
+\newcommand{\vect} [1] { \rm{\textbf{#1}} }    % vector style: non-italic bold
+
+%%% essai commande
+\newcommand{\nl} [1] {\texttt{\small {\textcolor{blue}{#1}} } } 
+
+%essai commande  
+\newcommand{\mdl} [1] {\textit{#1.F90}\index{Modules!#1}}			%module (mdl)
+\newcommand{\rou} [1] {\textit{#1}\index{Routines!#1}}			%module (routine)
+\newcommand{\hf} [1] {\textit{#1.h90}\index{h90 file!#1}}			%module (h90 files)
+\newcommand{\np} [1] {\textit{#1}\index{Namelist parameters!#1}}%namelist parameter (nampar)
+\newcommand{\jp} [1] {\textit{#1}\index{Model parameters!#1}}%model parameter (jp)
+\newcommand{\pp} [1] {\textit{#1}\index{Model parameters!#1}}%namelist parameter (pp)
+\newcommand{\key} [1] {\textbf{key\_#1}\index{CPP keys!key\_#1}}	%key_cpp (key)
+\newcommand{\NEMO} {\textit{NEMO}}						%NEMO (nemo)
+\newcommand{\amtcomment}[1]{}   	% command to allow "commented out" portions of 
+%                                    				% text that span line breaks
+
+%--------------------------------------------namlist---------------------------------------------------------
+\newcommand{\namdisplay} [1] {	\vspace{-25pt}
+	\begin{alltt}  \textcolor{blue}{{\scriptsize \verbatiminput{./Namelist/#1}}}  \end{alltt}
+									\vspace{-20pt}	}
+%--------------------------------------------------------------------------------------------------------------
+
+%Red (NR) or Yellow(WARN)
+%\newcommand{\NR} {\colorbox{red}{#1}}
+%\newcommand{\WARN} {{ \colorbox{yellow}{#1}} }
+
+%---------------------%%%%%  Section number in Margin  %%%%%-----------------------------
+% typeset the number of each section in the left margin, with the start of each instance of
+% sectional heading text aligned with the left hand edge of  the body text.
+\makeatletter 
+\def\@seccntformat#1{\protect\makebox[0pt][r]{\csname the#1\endcsname\quad}} 
+\makeatother 
+%--------------------------------------------------------------------------------------------------------------
+
+%----------------------------%%%%%   Bilbiography   %%%%%%-------------------------------%
+\usepackage[nottoc, notlof, notlot]{tocbibind}
+\usepackage[square, comma]{natbib}
+\bibpunct{[}{]}{,}{a}{}{;}                           %suppress "," after "et al."
+\newcommand{\bibfont}{\small}
+%--------------------------------------------------------------------------------------------------------------
+
+% ================================================================
+% FRONT PAGE
+% ================================================================
+\title{ \includegraphics[width=0.4\textwidth]{./Figures/NEMO_logo.pdf} \\
+\rule{345pt}{1.5pt} \\
+\vspace{0.45cm}
+ {\Huge NEMO ocean engine} 
+\rule{345pt}{1.5pt} \\ 
+{\small NEMO v2.3} \\
+{ -- Draft --}   }
+\date{\today}
+
+%%    \hbox{\mbox{%
+%%        \hspace{4pt}%
+%%         \fbox{\includegraphics[width=3em]{./NEMO_logo.pdf}}%
+%%        \hspace{4pt}
+%%        }  }%
+
+\author{Gurvan Madec - \texttt{{\small gurvan.madec@locean-ipsl.umpc.fr}} \\
+{\small Laboratoire d'Oc\'{e}anographie  et du Climat: Exp\'{e}rimentation et Approches Num\'{e}riques}
+}
+
+\dominitoc
+\makeindex  		%type this first :     makeindex -s NEMO.ist NEMO_book.idx
+
+% ================================================================
+% ================================================================
+%      Include ONLY order
+% ================================================================
+
+%\includeonly{./Chapters/Annex_E,./Chapters/Annex_C}
+%\includeonly{./Chapters/Chap_LBC,./Chapters/Chap_MISC}
+%\includeonly{./Chapters/Chap_Model_Basics_zstar}
+%\includeonly{./Chapters/Annex_A,./Chapters/Annex_B,./Chapters/Annex_C,./Chapters/Annex_D}
+
+% ================================================================
+% ================================================================
+\begin{document}
+
+\maketitle						% generate the title
+
+\frontmatter
+
+\tableofcontents					% generate a table of content
+%\listoffigures					% generate a table of content
+%\listoftables					% generate a table of content
+
+\mainmatter
+
+% ================================================================
+% Abstract - Foreword
+% ================================================================
+
+\include{./Chapters/Abstracts_Foreword}
+
+% ================================================================
+% INTRODUCTION
+% ================================================================
+
+\include{./Chapters/Introduction}
+
+% ================================================================
+% CHAPTERS
+% ================================================================
+
+\include{./Chapters/Chap_Model_Basics}
+
+%\include{./Chapters/Chap_Model_Basics_zstar}			% attent to describe z*-s*
+
+\include{./Chapters/Chap_DOM}
+
+\include{./Chapters/Chap_TRA}
+
+\include{./Chapters/Chap_DYN}
+
+\include{./Chapters/Chap_SBC}
+
+\include{./Chapters/Chap_LBC}
+
+\include{./Chapters/Chap_LDF}
+
+\include{./Chapters/Chap_ZDF}
+
+\include{./Chapters/Chap_MISC}
+
+% ================================================================
+% APPENDIX
+% ================================================================
+
+%\appendix
+
+%\include{./Chapters/Chap_Conservation}
+%\include{./Chapters/Annex_A}
+%\include{./Chapters/Annex_B}
+%\include{./Chapters/Annex_C}
+%\include{./Chapters/Annex_D}
+%\include{./Chapters/Annex_E}
+
+%%%%\include{./Chapters/0_page_de_garde_old}
+% ================================================================
+% INDEX
+% ================================================================
+
+\addcontentsline{toc}{chapter}{Index}
+\printindex
+
+% ================================================================
+% BIBLIOGRAPHY
+% ================================================================
+
+%%\bibliographystyle{plainnat}
+\bibliographystyle{./ametsoc}			% AMS biblio style (JPO)
+\bibliography{./Biblio/biblio}
+
+% ================================================================
+\end{document}
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_ctl
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_ctl	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_ctl	(revision 4536)
@@ -0,0 +1,16 @@
+!-----------------------------------------------------------------------
+&nam_ctl      !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+   ln_ctl =  .false.       !  trends control print (expensive!)
+   nprint =       0        !  level of print (0 no print)
+   nictls =       0        !  start i indice to make the control SUM (very usefull to compare mono-
+   nictle =       0        !  end   i indice to make the control SUM (-versus multi processor runs)
+   njctls =       0        !  start j indice to make the control SUM (very usefull to compare mono-
+   njctle =       0        !  end   j indice to make the control SUM (-versus multi processor runs)
+   isplt  =       1        !  number of processors following i
+   jsplt  =       1        !  number of processors following j
+   nbench =       0        !  = 1 Bench run (no physical meaning)
+                           !  = 0 Standard simulation
+   nbit_cmp =     0        !  = 1 enables bit comparison between mono and mpp runs
+                           !  = 0 faster mpp run 
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynadv
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynadv	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynadv	(revision 4536)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&nam_dynadv  !   option of physics/algorithm (not control by CPP keys)
+!----------------------------------------------------------------------- 
+   ln_dynadv_vec   = .TRUE.    !  vector form (T) flux form (F)
+   ln_dynadv_cen2  = .FALSE.   !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs   = .FALSE.   !  flux form - 3rd order UBS scheme   
+/  
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynhpg
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynhpg	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynhpg	(revision 4536)
@@ -0,0 +1,12 @@
+!-----------------------------------------------------------------------
+&nam_dynhpg   !   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+   ln_hpg_zco = .false.       !  z-coordinate - full steps                   
+   ln_hpg_zps = .true.        !  z-coordinate - partial steps (interpolation)
+   ln_hpg_sco = .false.       !  s-coordinate (standard jacobian formulation)
+   ln_hpg_hel = .false.       !  s-coordinate (helsinki modification)
+   ln_hpg_wdj = .false.       !  s-coordinate (weighted density jacobian)
+   ln_hpg_djc = .false.       !  s-coordinate (Density Jacobian with Cubic polynomial)
+   ln_hpg_rot = .false.       !  s-coordinate (ROTated axes scheme)
+   gamm       = 0.e0          !  weighting coefficient (wdj scheme)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynldf
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynldf	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynldf	(revision 4536)
@@ -0,0 +1,17 @@
+!-----------------------------------------------------------------------
+&nam_dynldf   !   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+   !                             !  Type of the operator : 
+   ln_dynldf_lap    =  .true.    !     laplacian operator          
+   ln_dynldf_bilap  =  .false.   !     bilaplacian operator       
+                                 !  Direction of action  : 
+   ln_dynldf_level  =  .false.   !     iso-level                  
+   ln_dynldf_hor    =  .true.    !     horizontal  (+ "key_ldfslp" if ln_sco=T)
+   ln_dynldf_iso    =  .false.   !     iso-neutral (+ "key_ldfslp")
+   !                             !  Coefficient
+   !  "key_ldfdyn_c1d"           !     Ahm = F(k)
+   !  "key_ldfdyn_c2d"           !     Ahm = F(i,j)
+   !  "key_ldfdyn_c3d"           !     Ahm = F(i,j,k)
+   ahm0    = 40000.              !     horizontal eddy viscosity for the dynamics (m2/s)
+   ahmb0   =     0.              !     background eddy viscosity for isopycnal diffusion (m2/s)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynspg
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynspg	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynspg	(revision 4536)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&nam_dynspg   !   surface pressure gradient   (CPP key only)
+!-----------------------------------------------------------------------
+!  "key_vvl"                     !  Activate the variable volume level
+!  "key_dynspg_exp"              !  explicit free surface              
+!  "key_dynspg_flt"              !  filtered free surface           
+!  "key_dynspg_ts"               !  split-explicit free surface    
+!  "key_dynspg_rl"               !  rigid-lid                  
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynvor
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynvor	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_dynvor	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&nam_dynvor   !   option of physics/algorithm 
+!-----------------------------------------------------------------------
+   ln_dynvor_ene = .false.    !  enstrophy conserving scheme 
+   ln_dynvor_ens = .true.     !  energy conserving scheme   
+   ln_dynvor_mix = .false.    !  mixed energy/enstrophy conserving scheme               
+   ln_dynvor_een = .false.    !  energy and enstrophy scheme   
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_lbc
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_lbc	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_lbc	(revision 4536)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&namlbc   !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+! "key_noslip_accurate"    ! Activate accurate no-slip boundary condition
+   shlat  =      2.        !      shlat = 0 :           free slip
+                           !  0 < shlat < 2 : "partial" free-slip
+                           !      shlat = 2 :           no slip
+                           !  2 < shlat     : "strong"  no-slip
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_mpp
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_mpp	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_mpp	(revision 4536)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&nam_mpp      !   Massively Parallel Processing
+!-----------------------------------------------------------------------
+   c_mpi_send =  'S'       !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
+                           !  buffer blocking send or immediate non-blocking sends, resp.
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_sbc_tot
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_sbc_tot	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_sbc_tot	(revision 4536)
@@ -0,0 +1,42 @@
+!-----------------------------------------------------------------------
+&namtau   !   surface wind stress
+!-----------------------------------------------------------------------
+   ntau000 =      0        !  gently increase the stress over the first ntau_rst time-steps
+   tau0x   =      0.e0     !  uniform value used as default surface heat flux
+   tau0y   =      0.e0     !  uniform value used as default solar radiation flux
+/
+!-----------------------------------------------------------------------
+&namflx   !   surface fluxes
+!-----------------------------------------------------------------------
+   q0      =      0.e0     !  uniform value used as default surface heat flux
+   qsr0    =      0.e0     !  uniform value used as default solar radiation flux
+   emp0    =      0.e0     !  uniform value used as default surface freswater budget (E-P)
+   dqdt0   =      -40.     !  feedback coefficient for SST damping (W/m2/K)
+   deds0   =        0.     !  feedback coefficient for SSS damping (mm/day)
+/
+!-----------------------------------------------------------------------
+&namqsr   !   penetrative solar radiation
+!-----------------------------------------------------------------------
+   ln_traqsr = .true.      !  penetrative solar radiation (T) or not (F)   
+   rabs     =   0.58       !  fraction of qsr associated with xsi1
+   xsi1     =   0.35       !  first depth of extinction
+   xsi2     =   23.0       !  second depth of extinction
+/
+!-----------------------------------------------------------------------
+&namfwb   !   freshwater budget correction
+!-----------------------------------------------------------------------
+   ln_fwb    = .true.      !  flag for freshwater budget correction (0 annual mean)
+/
+!-----------------------------------------------------------------------
+&namalb   !   albedo parameters
+!-----------------------------------------------------------------------
+   cgren    =      0.06    !  correction of the snow or ice albedo to take into account
+   albice   =      0.5     !  albedo of melting ice in the arctic and antarctic
+   alphd    =      0.80    !  coefficients for linear interpolation used to
+   alphc    =      0.65    !  compute albedo between two extremes values 
+   alphdi   =      0.72    !  (Pyane, 1972)
+/
+!-----------------------------------------------------------------------
+&namcpl   !   coupled ocean/atmosphere model   ("key_coupled")
+!-----------------------------------------------------------------------
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_tke
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_tke	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_tke	(revision 4536)
@@ -0,0 +1,25 @@
+!-----------------------------------------------------------------------
+&namtke   !   turbulent eddy kinetic dependent vertical diffusion       
+!-----------------------------------------------------------------------
+!  "key_zdftke"               !  Activate the TKE physics
+   ln_rstke = .false.         !  restart with tke from a run without tke
+   nitke =        50          !  number of restart iterative loops
+   ediff =       0.1          !  coef. for avt (avt=ediff*mxl*sqrt(e))
+   ediss =       0.7          !  coef. for Kolmogoroff dissipation
+   ebb   =      3.75          !  coef. for surface input of tke
+   efave =        1.          !  coef. for enhance Kz on tke (avtke=efave*avm)
+   emin  =     1.e-6          !  background value of tke (m^2/s^2)
+   emin0 =     1.e-4          !  surface minimum value of tke (m^2/s^2)
+!! ri_c  =         0.22222222 !  critic richardson number (default = 2/9)
+   nmxl  =         2          !  mixing length type  
+   !                          !    = 0 bounded by the distance to surface & bottom
+   !                          !    = 1 bounded by the local vertical scale factor
+   !                          !    = 2 abs( dz(mxl) /e3 ) < 1
+   !                          !    = 3 same as 2 with ldiss /= lmix
+   npdl  =         1          !  prandtl number 
+   !                          !    = 0 no vertical prandtl number (avt=avm)
+   !                          !    = 1 prandtl number = F(Ri) (avt=pdl*avm)
+   !                          !    = 2 same as =1 but with a shapiro filter on pdl
+   nave  =         1          !  horizontal filter on avt and amv (=1) or not (=0)
+   navb  =         0          !  constant (=0) or profile (=1) background on avt
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traadv
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traadv	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traadv	(revision 4536)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&nam_traadv   !   advection scheme for tracer 
+!-----------------------------------------------------------------------
+   ln_traadv_cen2   =  .true.    !  2nd order centered scheme    
+   ln_traadv_tvd    =  .false.   !  TVD scheme                  
+   ln_traadv_muscl  =  .false.   !  MUSCL scheme               
+   ln_traadv_muscl2 =  .false.   !  MUSCL2 scheme              
+   ln_traadv_ubs    =  .false.   !  UBS scheme                
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traldf
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traldf	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_traldf	(revision 4536)
@@ -0,0 +1,19 @@
+!-----------------------------------------------------------------------
+&nam_traldf   !   lateral diffusion scheme for tracer 
+!-----------------------------------------------------------------------
+                                 !  Type of the operator : 
+   ln_traldf_lap    =  .true.    !     laplacian operator        
+   ln_traldf_bilap  =  .false.   !     bilaplacian operator      
+                                 !  Direction of action  :
+   ln_traldf_level  =  .false.   !     iso-level                  
+   ln_traldf_hor    =  .false.   !     horizontal  (+ "key_ldfslp" if ln_sco=T)
+   ln_traldf_iso    =  .true.    !     iso-neutral (+ "key_ldfslp")
+                                 !  Coefficient
+   !  "key_ldftra_c1d"           !     Aht = F(k)
+   !  "key_ldftra_c2d"           !     Aht = F(i,j)
+   !  "key_ldftra_c3d"           !     Aht = F(i,j,k)
+   aht0    =  2000.              !     lateral eddy diffusivity coef. (m2/s)
+   ahtb0   =     0.              !     background coef. for isopycnal diffusion (m2/s)
+   aeiv0   =  2000.              !     eddy induced velocity coefficient (m2/s)  
+   !                             !     (+ "key_traldf_eiv")
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&nam_zgr       !   vertical coordinate
+!-----------------------------------------------------------------------
+   ln_zco   =  .false.     !   z-coordinate - full    steps  
+   !                       !       ("key_zco" may also be defined)
+   ln_zps   =  .true.      !  z-coordinate - partial steps   
+   ln_sco   =  .false.     !  s- or hybrid z-s-coordinate   
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr_sco
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr_sco	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nam_zgr_sco	(revision 4536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&nam_zgr_sco   !   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+   sbot_min =  300.        !  minimum depth of s-bottom surface (>0) (m)
+   sbot_max = 5250.        !  maximum depth of s-bottom surface (>0) (m)
+   !                       !  (= maximum ocean depth allowed) 
+   theta    =    6.0       !  surface control parameter (0<=theta<=20)
+   thetb    =    0.75      !  bottom control parameter  (0<=thetb<= 1)
+   r_max    =    0.15      !  maximum cut-off r-value allowed (0<r_max<1)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namalb
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namalb	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namalb	(revision 4536)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&namalb   !   albedo parameters
+!-----------------------------------------------------------------------
+   cgren    =      0.06    !  correction of the snow or ice albedo 
+   albice   =      0.5     !  albedo of melting ice
+   alphd    =      0.80    !  coefficients for linear interpolation used to
+   alphc    =      0.65    !  compute albedo between two extremes values 
+   alphdi   =      0.72    !  (Pyane, 1972)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbc
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbc	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbc	(revision 4536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&nambbc   !   bottom boundary condition (on temperature only)                 
+!-----------------------------------------------------------------------
+!  "key_trabbc"               ! Activate geothermal forcing (bbc)
+   ngeo_flux =  2             !  = 0 no geothermal heat flux
+   !                          !  = 1 constant geothermal heat flux
+   !                          !  = 2 variable geothermal heat flux 
+   !                          !      (read in geothermal_heating.nc in mW/m2) 
+   ngeo_flux_const = 86.4e-3  !  Constant value of geothermal heat flux (W/m2)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbl
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbl	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambbl	(revision 4536)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&nam_trabbl   !   bottom boundary layer scheme                          
+!-----------------------------------------------------------------------
+!  "key_trabbl_dif"              !  Activate the diffusive bbl 
+!  "key_trabbl_adv"              !  Activate the advective bbl 
+   atrbbl = 10000.               !  lateral tracer coeff. for bbl scheme (m2/s)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambfr
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambfr	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nambfr	(revision 4536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&nambfr   !   bottom friction
+!-----------------------------------------------------------------------
+   nbotfr =       1        !  type of bottom friction 
+   !                       !   = 0 : no slip        ,  = 2 : nonlinear friction
+                           !   = 1 : linear friction,  = 3 : free slip
+   bfri1  =   4.e-4        !  bottom drag coefficient (linear case)
+   bfri2  =   1.e-3        !  bottom drag coefficient (non linear case)
+   bfeb2  =  2.5e-3        !  bottom tke background (m^2/s^2)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcpl
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcpl	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcpl	(revision 4536)
@@ -0,0 +1,4 @@
+!-----------------------------------------------------------------------
+&namcpl   !   coupled ocean/atmosphere model                            ("key_coupled")
+!-----------------------------------------------------------------------
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcro
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcro	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namcro	(revision 4536)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&namcro   !   cross land advection
+!-----------------------------------------------------------------------
+!  n_cla   advection between 2 ocean pts separates by land 
+   n_cla   = 1
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namddm
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namddm	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namddm	(revision 4536)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&namddm   !   double diffusive mixing parameterization                  
+!-----------------------------------------------------------------------
+!     "key_zdfddm"            !  Activate ddm phisics
+      avts  = 1.e-4           !  maximum avs (vertical mixing on salinity)
+      hsbfr = 1.6             !  heat/salt buoyancy flux ratio
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdmp
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdmp	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdmp	(revision 4536)
@@ -0,0 +1,17 @@
+!-----------------------------------------------------------------------
+&namdmp   tracer newtonian damping ('key_tradmp')
+!-----------------------------------------------------------------------
+   ndmp   =   -1                 !  type of damping in temperature and salinity 
+   !                             !     ='latitude', damping poleward of 'ndmp' degrees 
+   !                             !       and function of the distance-to-coast. 
+   !                             !       Red and Med Seas as ndmp=-1
+   !                             !     =-1 damping only in Med and Red Seas
+   ndmpf  =    1                 !  =1 create a damping.coeff NetCDF file
+   nmldmp =    1                 !  type of damping in the mixed layer
+   !                             !     =0 damping throughout the water column
+   !                             !     =1 no damping in the mixing layer (avt >5cm2/s )
+   !                             !     =2 no damping in the mixed  layer (rho<rho(surf)+.01 )
+   sdmp   =  50.                 !  surface time scale for internal damping (days)
+   bdmp   = 360.                 !  bottom  time scale for internal damping (days)
+   hdmp   = 800.                 !  depth of transition between sdmp and bdmp (meters)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdom
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdom	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namdom	(revision 4536)
@@ -0,0 +1,21 @@
+!-----------------------------------------------------------------------
+&namdom   !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   ntopo     =     1       !  = 1 read the bathymetry_level 
+   e3zps_min =     5.      !  minimum thickness of the partial step is the min of
+   e3zps_rat =     0.1     !  e3zps_min and e3zps_rat * e3t  (with 0<e3zps_rat<1)
+   nmsh      =     0       !  =1 create a mesh file (coordinates, scale factors, masks)
+   nacc      =     0       !  the acceleration of convergence method
+   !                       !     = 0, no acceleration, rdt = rdttra
+   !                       !     = 1, acceleration used, rdt < rdttra(k)
+   atfp      =     0.1     !  asselin time filter parameter
+   rdt       =  5760.      !  time step for the dynamics (and tracer if nacc=0)
+   rdtmin    =  5760.      !  minimum time step on tracers
+   rdtmax    =  5760.      !  maximum time step on tracers
+   rdth      =   800.      !  depth variation of tracer time step
+   rdtbt     =    90.      !  barotropic time step (for the time splitting algorithm)
+   nfice     =     5       !  frequency of ice model call
+   nfbulk    =     5       !  frequency of bulk formulea call (not used if ice used)
+   nclosea   =     0       !  = 0 no closed sea in the model domain
+!                          !  = 1 closed sea (Caspian Sea, Great US Lakes...) 
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nameos
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nameos	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/nameos	(revision 4536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&nameos   !   ocean physical parameters
+!-----------------------------------------------------------------------
+   neos   =      0         !  type of equation of state and Brunt-Vaisala frequency
+                           !     = 0, Jackett and McDougall (1994) and of McDougall (1987)
+                           !     = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+                           !     = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+   ralpha =  2.e-4         !  thermal expension coefficient (neos= 1 or 2)
+   rbeta  =  0.001         !  saline  expension coefficient (neos= 2)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflg
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflg	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflg	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namflg   !   algorithm flags (algorithm not control by CPP keys)
+!-----------------------------------------------------------------------
+   ln_dynhpg_imp   =  .false. !  hydrostatic pressure gradient:
+   !                          !     = T : semi-implicit time scheme 
+   !                          !     = f : centered      time scheme
+   nn_dynhpg_rst   =  0       !  add dynhpg implicit variables in restart ot not (1/0)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflo
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflo	(revision 4536)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&namflo    !   float parameters                                         ("key_float")
+!-----------------------------------------------------------------------
+    ln_rstflo = .false.          !  boolean term for float restart (true or false)
+    nwritefl  =      75          !  frequency of float output file 
+    nstockfl  =    5475          !  frequency of float restart file 
+    ln_argo   = .false.          !  Argo type floats (stay at the surface each 10 days)
+    ln_flork4 = .false.          !  = T trajectories computed with a 4th order Runge-Kutta
+                                 !  = F  (default)   computed with Blanke' scheme
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflx
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflx	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namflx	(revision 4536)
@@ -0,0 +1,9 @@
+!-----------------------------------------------------------------------
+&namflx   !   surface fluxes
+!-----------------------------------------------------------------------
+   q0      =      0.e0     !  uniform value used as default surface heat flux
+   qsr0    =      0.e0     !  uniform value used as default solar radiation flux
+   emp0    =      0.e0     !  uniform value used as default surface freswater budget (E-P)
+   dqdt0   =      -40.     !  feedback coefficient for SST damping (W/m2/K)
+   deds0   =        0.     !  feedback coefficient for SSS damping (mm/day)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namfwb
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namfwb	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namfwb	(revision 4536)
@@ -0,0 +1,5 @@
+!-----------------------------------------------------------------------
+&namfwb   !   freshwater budget correction
+!-----------------------------------------------------------------------
+   ln_fwb    = .true.      !  flag for freshwater budget correction (0 annual mean)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namgap
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namgap	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namgap	(revision 4536)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&namgap    !   level mean model-data gap                                ('key_diagap')
+!-----------------------------------------------------------------------
+   ngap =  15                    !  time-step frequency of model-data gap computation
+   nprg =  10                    !  time-step frequency of gap print in model output
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namkpp
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namkpp	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namkpp	(revision 4536)
@@ -0,0 +1,16 @@
+!-----------------------------------------------------------------------
+&namkpp   !   K-Profile Parameterization dependent vertical mixing      
+!-----------------------------------------------------------------------
+!  "key_zdfkpp"               !  activate the KPP physics
+!  "key_kppcustom"            !  KPP option 1
+!  "key_kpplktb"              !  KPP option 2    
+   ln_kpprimix  = .true.      !  shear instability mixing  (default T)
+   difmiw       =  1.0e-04    !  constant internal wave viscosity (m2/s)
+   difsiw       =  0.1e-04    !  constant internal wave diffusivity (m2/s)
+   Riinfty      =  0.8        !  local Richardson Number limit for shear instability
+   difri        =  0.0050     !  maximum shear mixing at Rig = 0    (m2/s)
+   bvsqcon      = -0.01e-07   !  Brunt-Vaisala squared (1/s**2) for maximum convection
+   difcon       =  1.         !  maximum mixing in interior convection (m2/s)
+   navb         =  0          !  horizontal averaged (=1) or not (=0) on avt and amv  
+   nave         =  1          !  constant (=0) or profile (=1) background on avt
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namlbc
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namlbc	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namlbc	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namlbc   !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   shlat  =      2.        !      shlat = 0 : free slip
+                           !  0 < shlat < 2 : partial slip
+                           !      shlat = 2 : no slip
+                           !  2 < shlat     : strong slip
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namnpc
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namnpc	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namnpc	(revision 4536)
@@ -0,0 +1,6 @@
+!-----------------------------------------------------------------------
+&namnpc   !   non penetrative convective adjustment
+!-----------------------------------------------------------------------
+   nnpc1  =      1            !  computation frequency    (time-step)
+   nnpc2  =    365            !  control print frequency  (time-step)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namobc
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namobc	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namobc	(revision 4536)
@@ -0,0 +1,19 @@
+!-----------------------------------------------------------------------
+&namobc   !   open boundaries parameters                            ("key_obc")
+!-----------------------------------------------------------------------
+    nobc_dta    =    0     !  = 0 the obc data are equal to the initial state
+                           !  = 1 the obc data are read in 'obc   .dta' files
+    rdpein      =    1.    !  ???
+    rdpwin      =    1.    !  ???
+    rdpnin      =   30.    !  ???
+    rdpsin      =    1.    !  ???
+    rdpeob      = 1500.    !  time relaxation (days) for the east  open boundary
+    rdpwob      =   15.    !    "        "           for the west  open boundary
+    rdpnob      =  150.    !    "        "           for the north open boundary
+    rdpsob      =   15.    !    "        "           for the south open boundary
+    zbsic1      =  140.e+6 !  barotropic stream function on first  isolated coastline
+    zbsic2      =    1.e+6 !    "                   "    on second isolated coastline
+    zbsic3      =    0.    !    "                   "    on thrid  isolated coastline
+    ln_obc_clim = .true.   !  climatological obc data files (default T)
+    ln_vol_cst  = .true.   !  total volume conserved
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namptr
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namptr	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namptr	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namptr   !   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+   ln_diaptr = .false.           !  logical flag for Poleward transport computation
+   ln_subbas = .false.           !  logical flag for Atlantic/Pacific/Indian basins computation
+                                 !  need input basins mask file named "subbasins.nc"
+   nf_ptr    =  15               !  Frequency of computation
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namqsr
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namqsr	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namqsr	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namqsr   !   penetrative solar radiation
+!-----------------------------------------------------------------------
+   ln_traqsr = .true.      !  penetrative solar radiation (T) or not (F)
+   rabs     =   0.58       !  fraction of qsr associated with xsi1
+   xsi1     =   0.35       !  first depth of extinction
+   xsi2     =   23.0       !  second depth of extinction
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namric
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namric	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namric	(revision 4536)
@@ -0,0 +1,8 @@
+!-----------------------------------------------------------------------
+&namric   richardson number dependent vertical diffusion               
+!-----------------------------------------------------------------------
+!  "key_zdfric"               !  Activate Kz =function of Ri
+   avmri = 100.e-4            !  maximum value of the vertical viscosity
+   alp   =      5.            !  coefficient of the parameterization
+   nric  =       2            !  coefficient of the parameterization
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namrun
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namrun	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namrun	(revision 4536)
@@ -0,0 +1,20 @@
+!-----------------------------------------------------------------------
+&namrun   !   parameters of the run
+!-----------------------------------------------------------------------
+   no         =       0    !  job number
+   cexper     =  "ORCA2"   !  experience name for vairmer format
+   ln_rstart  = .false.    !  boolean term for restart (true or false)
+   nrstdt     =       0    !  restart control = 0 restart, do not control nit000 in the restart file.
+                           !                  = 1 restart, control nit000 in the restart file. Do not
+                           !                      use the date in the restart file (use ndate0 in namelist)
+                           !                  = 2 restart, control nit000 in the restart file, use the date
+                           !                      in the restart file. ndate0 in the namelist is ignored.
+   nit000     =       1    !  number of the first time step
+   nitend     =    5475    !  number of the first time step
+   ndate0     =  010101    !  initial calendar date aammjj
+   nleapy     =       0    !  Leap year calendar (0/1)
+   ninist     =       0    !  initial state output flag (0/1)
+   nstock     =    5475    !  number of the first time step
+   nwrite     =    5475    !  frequency of OUTPUT file
+   nrunoff    =       2    !  = 0 no, 1 runoff, 2 runoff+river mouth ups adv
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namsol
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namsol	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namsol	(revision 4536)
@@ -0,0 +1,19 @@
+!-----------------------------------------------------------------------
+&namsol   !   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+   nsolv     =      1         !  type of elliptic solver  
+   !                          !     =1 preconditioned conjugate gradient (pcg)
+                              !     =2 successive-over-relaxation (sor)
+                              !     =3 FETI (fet) (+ "key_feti")
+                              !     =4 sor with extra outer halo
+   nsol_arp  =      0         !  absolute/relative (0/1) precision convergence test
+   nmin      =    300         !  minimum of iterations for the SOR solver
+   nmax      =    800         !  maximum of iterations for the SOR solver
+   nmod      =     10         !  frequency of test for the SOR solver
+   eps       =  1.E-6         !  absolute precision of the solver
+   resmax    = 1.E-10         !  absolute precision for the SOR solver
+   sor       =   1.92         !  optimal coefficient for SOR solver
+   epsisl    = 1.e-10         !  absolute precision on stream function solver
+   nmisl     =   4000         !  maximum pcg iterations for island ("key_islands")
+   rnu       =     1.         !  strength of the additional force ("key_dynspg_flt)
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namspr
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namspr	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namspr	(revision 4536)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&namspr  !   surface pressure diagnostic
+!-----------------------------------------------------------------------
+   nmaxp   =   1000              !  maximum of iterations for the solver
+   epsp    =  1.e-3              !  absolute precision of the solver
+   niterp  =    400              !  number of iteration done by the solver
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtau
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtau	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtau	(revision 4536)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&namtau   !   surface wind stress
+!-----------------------------------------------------------------------
+   ntau000 =      0        !  gently increase the stress over the first ntau_rst time-steps
+   tau0x   =      0.e0     !  uniform value used as default surface heat flux
+   tau0y   =      0.e0     !  uniform value used as default solar radiation flux
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtrd
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtrd	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namtrd	(revision 4536)
@@ -0,0 +1,11 @@
+!-----------------------------------------------------------------------
+&namtrd    !   diagnostics on dynamics and/or tracer trends             ("key_trddyn" and/or "key_trdtra")
+!                          or mixed-layer trends                        ('key_trdmld')
+!                          or barotropic vorticity                      ("key_trdvor")
+!-----------------------------------------------------------------------
+   ntrd  = 365                   !  time step frequency dynamics and tracers trends
+   nctls =   0                   !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   ln_trdmld_restart = .false.   !  restart for ML diagnostics
+   ucf   =  1.                   !  unit conversion factor (=1 -> /seconds | =86400. -> /day)
+   ln_trdmld_instant = .false.   !  flag to diagnose trends of instantantaneous or mean ML T/S
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namzdf
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namzdf	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/Namelist/namzdf	(revision 4536)
@@ -0,0 +1,15 @@
+!-----------------------------------------------------------------------
+&namzdf   !   vertical physics
+!-----------------------------------------------------------------------
+   ln_zdfnpc = .false.        !  Non-Penetrative Convection          
+   avm0      = 1.2e-4         !  Kz on momemtum (m2/s)   
+   !                          !  (background Kz if not "key_zdfcst")
+   avt0      = 1.2e-5         !  Kz for tracers (m2/s) 
+   !                          !  (background Kz if not "key_zdfcst")
+   ln_zdfevd = .true.         !  enhanced vertical diffusion        
+   avevd     =   100.         !  Kz for enhanced diffusion scheme (m2/s)
+   n_evdm    =     0          !  enhanced mixing Kz apply on tracer (=0) 
+   !                          !      or on both tracer and momentum (=1)
+   ln_zdfexp =  .false.       !  =T/F  split explicit / implicit 
+   n_zdfexp  =     3          !  number of sub-timestep for ln_zdfexp=T
+/
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/ametsoc.bst
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/ametsoc.bst	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/ametsoc.bst	(revision 4536)
@@ -0,0 +1,1662 @@
+%%
+%% This is file `ametsoc7.bst',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% merlin.mbs  (with options: `ay,nat,nm-rev1,ed-rev,jnrlst,nmdash,nmd-3,dt-beg,yr-com,yrp-col,thtit-a,vol-2bf,vnum-sp,volp-com,pgsep-s,num-xser,numser,ser-vol,bkpg-x,pg-bk,pre-edn,agu-doi,doi,edparc,bkedcap,edby,edbyy,blk-tit,in-x,pp,ed,abr,ednx,ord,jabr,eprint,url,url-nt,em-it,nfss,')
+%% ----------------------------------------
+%% *** Bibliography style file for ALL AMS Journals...version 1.0  ***
+%% *** Brian Papa - American Meteorological Society ***
+%% 
+%% Copyright 1994-2004 Patrick W Daly
+ % ===============================================================
+ % IMPORTANT NOTICE:
+ % This bibliographic style (bst) file has been generated from one or
+ % more master bibliographic style (mbs) files, listed above.
+ %
+ % This generated file can be redistributed and/or modified under the terms
+ % of the LaTeX Project Public License Distributed from CTAN
+ % archives in directory macros/latex/base/lppl.txt; either
+ % version 1 of the License, or any later version.
+ % ===============================================================
+ % Name and version information of the main mbs file:
+ % \ProvidesFile{merlin.mbs}[2004/02/09 4.13 (PWD, AO, DPC)]
+ %   For use with BibTeX version 0.99a or later
+ %-------------------------------------------------------------------
+ % This bibliography style file is intended for texts in ENGLISH
+ % This is an author-year citation style bibliography. As such, it is
+ % non-standard LaTeX, and requires a special package file to function properly.
+ % Such a package is    natbib.sty   by Patrick W. Daly
+ % The form of the \bibitem entries is
+ %   \bibitem[Jones et al.(1990)]{key}...
+ %   \bibitem[Jones et al.(1990)Jones, Baker, and Smith]{key}...
+ % The essential feature is that the label (the part in brackets) consists
+ % of the author names, as they should appear in the citation, with the year
+ % in parentheses following. There must be no space before the opening
+ % parenthesis!
+ % With natbib v5.3, a full list of authors may also follow the year.
+ % In natbib.sty, it is possible to define the type of enclosures that is
+ % really wanted (brackets or parentheses), but in either case, there must
+ % be parentheses in the label.
+ % The \cite command functions as follows:
+ %   \citet{key} ==>>                Jones et al. (1990)
+ %   \citet*{key} ==>>               Jones, Baker, and Smith (1990)
+ %   \citep{key} ==>>                (Jones et al., 1990)
+ %   \citep*{key} ==>>               (Jones, Baker, and Smith, 1990)
+ %   \citep[chap. 2]{key} ==>>       (Jones et al., 1990, chap. 2)
+ %   \citep[e.g.][]{key} ==>>        (e.g. Jones et al., 1990)
+ %   \citep[e.g.][p. 32]{key} ==>>   (e.g. Jones et al., p. 32)
+ %   \citeauthor{key} ==>>           Jones et al.
+ %   \citeauthor*{key} ==>>          Jones, Baker, and Smith
+ %   \citeyear{key} ==>>             1990
+ %---------------------------------------------------------------------
+
+ENTRY
+  { address
+    archive
+    author
+    booktitle
+    chapter
+    doi
+    edition
+    editor
+    eid
+    eprint
+    howpublished
+    department
+    institution
+    journal
+    key
+    month
+    note
+    number
+    organization
+    pages
+    publisher
+    school
+    series
+    title
+    type
+    url
+    volume
+    year
+  }
+  {}
+  { label extra.label sort.label short.list }
+INTEGERS { output.state before.all mid.sentence after.sentence after.block }
+FUNCTION {init.state.consts}
+{ #0 'before.all :=
+  #1 'mid.sentence :=
+  #2 'after.sentence :=
+  #3 'after.block :=
+}
+STRINGS { s t}
+FUNCTION {output.nonnull}
+{ 's :=
+  output.state mid.sentence =
+    { ", " * write$ }
+    { output.state after.block =
+        { add.period$ write$
+          newline$
+          "\newblock " write$
+        }
+        { output.state before.all =
+            'write$
+            { add.period$ " " * write$ }
+          if$
+        }
+      if$
+      mid.sentence 'output.state :=
+    }
+  if$
+  s
+}
+FUNCTION {output}
+{ duplicate$ empty$
+    'pop$
+    'output.nonnull
+  if$
+}
+FUNCTION {output.check}
+{ 't :=
+  duplicate$ empty$
+    { pop$ "empty " t * " in " * cite$ * warning$ }
+    'output.nonnull
+  if$
+}
+FUNCTION {fin.entry}
+{ add.period$
+  write$
+  newline$
+}
+
+FUNCTION {new.block}
+{ output.state before.all =
+    'skip$
+    { after.block 'output.state := }
+  if$
+}
+FUNCTION {new.sentence}
+{ output.state after.block =
+    'skip$
+    { output.state before.all =
+        'skip$
+        { after.sentence 'output.state := }
+      if$
+    }
+  if$
+}
+FUNCTION {add.blank}
+{  " " * before.all 'output.state :=
+}
+
+FUNCTION {date.block}
+{
+  ":" *
+  add.blank
+}
+
+FUNCTION {not}
+{   { #0 }
+    { #1 }
+  if$
+}
+FUNCTION {and}
+{   'skip$
+    { pop$ #0 }
+  if$
+}
+FUNCTION {or}
+{   { pop$ #1 }
+    'skip$
+  if$
+}
+FUNCTION {new.block.checkb}
+{ empty$
+  swap$ empty$
+  and
+    'skip$
+    'new.block
+  if$
+}
+FUNCTION {field.or.null}
+{ duplicate$ empty$
+    { pop$ "" }
+    'skip$
+  if$
+}
+FUNCTION {emphasize}
+{ duplicate$ empty$
+    { pop$ "" }
+    { "\textit{" swap$ * "}" * }
+  if$
+}
+FUNCTION {bolden}
+{ duplicate$ empty$
+    { pop$ "" }
+    { "\textbf{" swap$ * "}" * }
+  if$
+}
+FUNCTION {tie.or.space.prefix}
+{ duplicate$ text.length$ #3 <
+    { "~" }
+    { " " }
+  if$
+  swap$
+}
+
+FUNCTION {capitalize}
+{ "u" change.case$ "t" change.case$ }
+
+FUNCTION {space.word}
+{ " " swap$ * " " * }
+ % Here are the language-specific definitions for explicit words.
+ % Each function has a name bbl.xxx where xxx is the English word.
+ % The language selected here is ENGLISH
+FUNCTION {bbl.and}
+{ "and"}
+
+FUNCTION {bbl.etal}
+{ "et~al." }
+
+FUNCTION {bbl.editors}
+{ "Eds." }
+
+FUNCTION {bbl.editor}
+{ "Ed." }
+
+FUNCTION {bbl.edby}
+{ "edited by" }
+
+FUNCTION {bbl.edition}
+{ "ed." }
+
+FUNCTION {bbl.volume}
+{ "Vol." }
+
+FUNCTION {bbl.of}
+{ "of" }
+
+FUNCTION {bbl.number}
+{ "No." }
+
+FUNCTION {bbl.nr}
+{ "No." }
+
+FUNCTION {bbl.in}
+{ "in" }
+
+FUNCTION {bbl.pages}
+{ "pp." }
+
+FUNCTION {bbl.page}
+{ "p." }
+
+FUNCTION {bbl.chapter}
+{ "chap." }
+
+FUNCTION {bbl.techrep}
+{ "Tech. Rep." }
+
+FUNCTION {bbl.mthesis}
+{ "Master's thesis" }
+
+FUNCTION {bbl.phdthesis}
+{ "Ph.D. thesis" }
+
+FUNCTION {bbl.first}
+{ "1st" }
+
+FUNCTION {bbl.second}
+{ "2d" }
+
+FUNCTION {bbl.third}
+{ "3d" }
+
+FUNCTION {bbl.fourth}
+{ "4th" }
+
+FUNCTION {bbl.fifth}
+{ "5th" }
+
+FUNCTION {bbl.st}
+{ "st" }
+
+FUNCTION {bbl.nd}
+{ "d" }
+
+FUNCTION {bbl.rd}
+{ "d" }
+
+FUNCTION {bbl.th}
+{ "th" }
+
+MACRO {jan} {"Jan."}
+
+MACRO {feb} {"Feb."}
+
+MACRO {mar} {"Mar."}
+
+MACRO {apr} {"Apr."}
+
+MACRO {may} {"May"}
+
+MACRO {jun} {"Jun."}
+
+MACRO {jul} {"Jul."}
+
+MACRO {aug} {"Aug."}
+
+MACRO {sep} {"Sep."}
+
+MACRO {oct} {"Oct."}
+
+MACRO {nov} {"Nov."}
+
+MACRO {dec} {"Dec."}
+
+FUNCTION {eng.ord}
+{ duplicate$ "1" swap$ *
+  #-2 #1 substring$ "1" =
+     { bbl.th * }
+     { duplicate$ #-1 #1 substring$
+       duplicate$ "1" =
+         { pop$ bbl.st * }
+         { duplicate$ "2" =
+             { pop$ bbl.nd * }
+             { "3" =
+                 { bbl.rd * }
+                 { bbl.th * }
+               if$
+             }
+           if$
+          }
+       if$
+     }
+   if$
+}
+
+MACRO {acmcs} {"ACM Comput. Surv."}
+
+MACRO {acta} {"Acta Inf."}
+
+MACRO {cacm} {"Commun. ACM"}
+
+MACRO {ibmjrd} {"IBM J. Res. Dev."}
+
+MACRO {ibmsj} {"IBM Syst.~J."}
+
+MACRO {ieeese} {"IEEE Trans. Software Eng."}
+
+MACRO {ieeetc} {"IEEE Trans. Comput."}
+
+MACRO {ieeetcad}
+ {"IEEE Trans. Comput. Aid. Des."}
+
+MACRO {ipl} {"Inf. Process. Lett."}
+
+MACRO {jacm} {"J.~ACM"}
+
+MACRO {jcss} {"J.~Comput. Syst. Sci."}
+
+MACRO {scp} {"Sci. Comput. Program."}
+
+MACRO {sicomp} {"SIAM J. Comput."}
+
+MACRO {tocs} {"ACM Trans. Comput. Syst."}
+
+MACRO {tods} {"ACM Trans. Database Syst."}
+
+MACRO {tog} {"ACM Trans. Graphic."}
+
+MACRO {toms} {"ACM Trans. Math. Software"}
+
+MACRO {toois} {"ACM Trans. Office Inf. Syst."}
+
+MACRO {toplas} {"ACM Trans. Progr. Lang. Syst."}
+
+MACRO {tcs} {"Theor. Comput. Sci."}
+
+FUNCTION {bibinfo.check}
+{ swap$
+  duplicate$ missing$
+    {
+      pop$ pop$
+      ""
+    }
+    { duplicate$ empty$
+        {
+          swap$ pop$
+        }
+        { swap$
+          pop$
+        }
+      if$
+    }
+  if$
+}
+FUNCTION {bibinfo.warn}
+{ swap$
+  duplicate$ missing$
+    {
+      swap$ "missing " swap$ * " in " * cite$ * warning$ pop$
+      ""
+    }
+    { duplicate$ empty$
+        {
+          swap$ "empty " swap$ * " in " * cite$ * warning$
+        }
+        { swap$
+          pop$
+        }
+      if$
+    }
+  if$
+}
+FUNCTION {format.eprint}
+{ eprint duplicate$ empty$
+    'skip$
+    { "\eprint"
+      archive empty$
+        'skip$
+        { "[" * archive * "]" * }
+      if$
+      "{" * swap$ * "}" *
+    }
+  if$
+}
+STRINGS  { bibinfo}
+INTEGERS { nameptr namesleft numnames }
+
+FUNCTION {format.names}
+{ 'bibinfo :=
+  duplicate$ empty$ 'skip$ {
+  's :=
+  "" 't :=
+  #1 'nameptr :=
+  s num.names$ 'numnames :=
+  numnames 'namesleft :=
+    { namesleft #0 > }
+    { s nameptr
+      duplicate$ #1 >
+        { "{f.~}{vv~}{ll}{, jj}" }
+        { "{vv~}{ll}{, f.}{, jj}" }
+      if$
+      format.name$
+      bibinfo bibinfo.check
+      't :=
+      nameptr #1 >
+        {
+          namesleft #1 >
+            { ", " * t * }
+            {
+              numnames #2 >
+                { "," * }
+                'skip$
+              if$
+              s nameptr "{ll}" format.name$ duplicate$ "others" =
+                { 't := }
+                { pop$ }
+              if$
+              t "others" =
+                {
+                  " " * bbl.etal *
+                }
+                {
+                  bbl.and
+                  space.word * t *
+                }
+              if$
+            }
+          if$
+        }
+        't
+      if$
+      nameptr #1 + 'nameptr :=
+      namesleft #1 - 'namesleft :=
+    }
+  while$
+  } if$
+}
+FUNCTION {format.names.ed}
+{
+  format.names
+}
+FUNCTION {format.key}
+{ empty$
+    { key field.or.null }
+    { "" }
+  if$
+}
+
+FUNCTION {format.authors}
+{ author "author" format.names
+}
+FUNCTION {get.bbl.editor}
+{ editor num.names$ #1 > 'bbl.editors 'bbl.editor if$ }
+
+FUNCTION {format.editors}
+{ editor "editor" format.names duplicate$ empty$ 'skip$
+    {
+      "," *
+      " " *
+      get.bbl.editor
+      capitalize
+   "(" swap$ * ")" *
+      *
+    }
+  if$
+}
+FUNCTION {format.book.pages}
+{ pages "pages" bibinfo.check
+  duplicate$ empty$ 'skip$
+    { " " * bbl.pages * }
+  if$
+}
+FUNCTION {format.doi}
+{ doi "doi" bibinfo.check
+  duplicate$ empty$ 'skip$
+    {
+      "\doi{" swap$ * "}" *
+    }
+  if$
+}
+FUNCTION {format.note}
+{
+  url empty$
+    'skip$
+    { "\urlprefix\url{" url * "}" * output }
+  if$
+ note empty$
+    { "" }
+    { note #1 #1 substring$
+      duplicate$ "{" =
+        'skip$
+        { output.state mid.sentence =
+          { "l" }
+          { "u" }
+        if$
+        change.case$
+        }
+      if$
+      note #2 global.max$ substring$ * "note" bibinfo.check
+    }
+  if$
+}
+
+FUNCTION {format.title}
+{ title
+  duplicate$ empty$ 'skip$
+    { "t" change.case$ }
+  if$
+  "title" bibinfo.check
+}
+FUNCTION {format.full.names}
+{'s :=
+ "" 't :=
+  #1 'nameptr :=
+  s num.names$ 'numnames :=
+  numnames 'namesleft :=
+    { namesleft #0 > }
+    { s nameptr
+      "{vv~}{ll}" format.name$
+      't :=
+      nameptr #1 >
+        {
+          namesleft #1 >
+            { ", " * t * }
+            {
+              s nameptr "{ll}" format.name$ duplicate$ "others" =
+                { 't := }
+                { pop$ }
+              if$
+              t "others" =
+                {
+                  " " * bbl.etal *
+                }
+                {
+                  numnames #2 >
+                    { "," * }
+                    'skip$
+                  if$
+                  bbl.and
+                  space.word * t *
+                }
+              if$
+            }
+          if$
+        }
+        't
+      if$
+      nameptr #1 + 'nameptr :=
+      namesleft #1 - 'namesleft :=
+    }
+  while$
+}
+
+FUNCTION {author.editor.key.full}
+{ author empty$
+    { editor empty$
+        { key empty$
+            { cite$ #1 #3 substring$ }
+            'key
+          if$
+        }
+        { editor format.full.names }
+      if$
+    }
+    { author format.full.names }
+  if$
+}
+
+FUNCTION {author.key.full}
+{ author empty$
+    { key empty$
+         { cite$ #1 #3 substring$ }
+          'key
+      if$
+    }
+    { author format.full.names }
+  if$
+}
+
+FUNCTION {editor.key.full}
+{ editor empty$
+    { key empty$
+         { cite$ #1 #3 substring$ }
+          'key
+      if$
+    }
+    { editor format.full.names }
+  if$
+}
+
+FUNCTION {make.full.names}
+{ type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.key.full
+    { type$ "proceedings" =
+        'editor.key.full
+        'author.key.full
+      if$
+    }
+  if$
+}
+
+FUNCTION {output.bibitem}
+{ newline$
+  "\bibitem[{" write$
+  label write$
+  ")" make.full.names duplicate$ short.list =
+     { pop$ }
+     { * }
+   if$
+  "}]{" * write$
+  cite$ write$
+  "}" write$
+  newline$
+  ""
+  before.all 'output.state :=
+}
+
+FUNCTION {if.digit}
+{ duplicate$ "0" =
+  swap$ duplicate$ "1" =
+  swap$ duplicate$ "2" =
+  swap$ duplicate$ "3" =
+  swap$ duplicate$ "4" =
+  swap$ duplicate$ "5" =
+  swap$ duplicate$ "6" =
+  swap$ duplicate$ "7" =
+  swap$ duplicate$ "8" =
+  swap$ "9" = or or or or or or or or or
+}
+FUNCTION {n.separate}
+{ 't :=
+  ""
+  #0 'numnames :=
+  { t empty$ not }
+  { t #-1 #1 substring$ if.digit
+      { numnames #1 + 'numnames := }
+      { #0 'numnames := }
+    if$
+    t #-1 #1 substring$ swap$ *
+    t #-2 global.max$ substring$ 't :=
+    numnames #5 =
+      { duplicate$ #1 #2 substring$ swap$
+        #3 global.max$ substring$
+        "\," swap$ * *
+      }
+      'skip$
+    if$
+  }
+  while$
+}
+FUNCTION {n.dashify}
+{
+  n.separate
+  't :=
+  ""
+    { t empty$ not }
+    { t #1 #1 substring$ "-" =
+        { t #1 #2 substring$ "--" = not
+            { "--" *
+              t #2 global.max$ substring$ 't :=
+            }
+            {   { t #1 #1 substring$ "-" = }
+                { "-" *
+                  t #2 global.max$ substring$ 't :=
+                }
+              while$
+            }
+          if$
+        }
+        { t #1 #1 substring$ *
+          t #2 global.max$ substring$ 't :=
+        }
+      if$
+    }
+  while$
+}
+
+FUNCTION {word.in}
+{ "" }
+
+FUNCTION {format.date}
+{ year "year" bibinfo.check duplicate$ empty$
+    {
+      "empty year in " cite$ * "; set to ????" * warning$
+       pop$ "????"
+    }
+    'skip$
+  if$
+  extra.label *
+  before.all 'output.state :=
+  ", " swap$ *
+}
+FUNCTION {format.btitle}
+{ title "title" bibinfo.check
+  duplicate$ empty$ 'skip$
+    {
+      emphasize
+    }
+  if$
+}
+FUNCTION {either.or.check}
+{ empty$
+    'pop$
+    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
+  if$
+}
+FUNCTION {format.bvolume}
+{ volume empty$
+    { "" }
+    { bbl.volume volume tie.or.space.prefix
+      "volume" bibinfo.check * *
+      series "series" bibinfo.check
+      duplicate$ empty$ 'pop$
+%%% NO ITALIC SERIES        { emphasize ", " * swap$ * }
+      {", " * swap$ * }
+      if$
+      "volume and number" number either.or.check
+    }
+  if$
+}
+FUNCTION {format.number.series}
+{ volume empty$
+    { number empty$
+        { series field.or.null }
+        { series empty$
+            { number "number" bibinfo.check }
+            { output.state mid.sentence =
+                { bbl.number }
+                { bbl.number capitalize }
+              if$
+              number tie.or.space.prefix "number" bibinfo.check * *
+              bbl.in space.word *
+              series "series" bibinfo.check *
+            }
+          if$
+        }
+      if$
+    }
+    { "" }
+  if$
+}
+FUNCTION {is.num}
+{ chr.to.int$
+  duplicate$ "0" chr.to.int$ < not
+  swap$ "9" chr.to.int$ > not and
+}
+
+FUNCTION {extract.num}
+{ duplicate$ 't :=
+  "" 's :=
+  { t empty$ not }
+  { t #1 #1 substring$
+    t #2 global.max$ substring$ 't :=
+    duplicate$ is.num
+      { s swap$ * 's := }
+      { pop$ "" 't := }
+    if$
+  }
+  while$
+  s empty$
+    'skip$
+    { pop$ s }
+  if$
+}
+
+FUNCTION {convert.edition}
+{ extract.num "l" change.case$ 's :=
+  s "first" = s "1" = or
+    { bbl.first 't := }
+    { s "second" = s "2" = or
+        { bbl.second 't := }
+        { s "third" = s "3" = or
+            { bbl.third 't := }
+            { s "fourth" = s "4" = or
+                { bbl.fourth 't := }
+                { s "fifth" = s "5" = or
+                    { bbl.fifth 't := }
+                    { s #1 #1 substring$ is.num
+                        { s eng.ord 't := }
+                        { edition 't := }
+                      if$
+                    }
+                  if$
+                }
+              if$
+            }
+          if$
+        }
+      if$
+    }
+  if$
+  t
+}
+
+FUNCTION {format.edition}
+{ edition duplicate$ empty$ 'skip$
+    {
+      convert.edition
+      output.state mid.sentence =
+        { "l" }
+        { "t" }
+      if$ change.case$
+      "edition" bibinfo.check
+      " " * bbl.edition *
+    }
+  if$
+}
+INTEGERS { multiresult }
+FUNCTION {multi.page.check}
+{ 't :=
+  #0 'multiresult :=
+    { multiresult not
+      t empty$ not
+      and
+    }
+    { t #1 #1 substring$
+      duplicate$ "-" =
+      swap$ duplicate$ "," =
+      swap$ "+" =
+      or or
+        { #1 'multiresult := }
+        { t #2 global.max$ substring$ 't := }
+      if$
+    }
+  while$
+  multiresult
+}
+FUNCTION {format.pages}
+{ pages duplicate$ empty$ 'skip$
+    { duplicate$ multi.page.check
+        {
+          n.dashify
+        }
+        {
+        }
+      if$
+      "pages" bibinfo.check
+    }
+  if$
+}
+FUNCTION {format.journal.pages}
+{ pages duplicate$ empty$ 'pop$
+    { swap$ duplicate$ empty$
+        { pop$ pop$ format.pages }
+        {
+          ", " *
+          swap$
+          n.dashify
+          "pages" bibinfo.check
+          *
+        }
+      if$
+    }
+  if$
+}
+FUNCTION {format.journal.eid}
+{ eid "eid" bibinfo.check
+  duplicate$ empty$ 'pop$
+    { swap$ duplicate$ empty$ 'skip$
+      {
+          ", " *
+      }
+      if$
+      swap$ *
+    }
+  if$
+}
+FUNCTION {format.vol.num.pages}
+{ volume field.or.null
+  duplicate$ empty$ 'skip$
+    {
+      "volume" bibinfo.check
+    }
+  if$
+  number "number" bibinfo.check duplicate$ empty$ 'skip$
+    {
+      swap$ duplicate$ empty$
+        { "there's a number but no volume in " cite$ * warning$ }
+        'skip$
+      if$
+      swap$
+      "~(" swap$ * ")" *
+    }
+  if$ *
+  bolden
+  eid empty$
+    { format.journal.pages }
+    { format.journal.eid }
+  if$
+}
+
+FUNCTION {format.chapter.pages}
+{ chapter empty$
+    'format.pages
+    { type empty$
+        { bbl.chapter }
+        { type "l" change.case$
+          "type" bibinfo.check
+        }
+      if$
+      chapter tie.or.space.prefix
+      "chapter" bibinfo.check
+      * *
+      pages empty$
+        'skip$
+        { ", " * format.pages * }
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.booktitle}
+{
+  booktitle "booktitle" bibinfo.check
+  emphasize
+}
+FUNCTION {format.in.ed.booktitle}
+{ format.booktitle duplicate$ empty$ 'skip$
+    {
+      editor "editor" format.names.ed duplicate$ empty$ 'pop$
+        {
+          get.bbl.editor
+          swap$ "," *
+          " " * swap$ *
+          swap$
+          "," *
+          " " * swap$
+          * }
+      if$
+      word.in swap$ *
+    }
+  if$
+}
+FUNCTION {format.thesis.type}
+{ type duplicate$ empty$
+    'pop$
+    { swap$ pop$
+      "t" change.case$ "type" bibinfo.check
+    }
+  if$
+}
+FUNCTION {format.tr.number}
+{ number "number" bibinfo.check
+  type duplicate$ empty$
+    { pop$ bbl.techrep }
+    'skip$
+  if$
+  "type" bibinfo.check
+  swap$ duplicate$ empty$
+    { pop$ "t" change.case$ }
+    { tie.or.space.prefix * * }
+  if$
+}
+FUNCTION {format.article.crossref}
+{
+  word.in
+  " \cite{" * crossref * "}" *
+}
+FUNCTION {format.book.crossref}
+{ volume duplicate$ empty$
+    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
+      pop$ word.in
+    }
+    { bbl.volume
+      capitalize
+      swap$ tie.or.space.prefix "volume" bibinfo.check * * bbl.of space.word *
+    }
+  if$
+  " \cite{" * crossref * "}" *
+}
+FUNCTION {format.incoll.inproc.crossref}
+{
+  word.in
+  " \cite{" * crossref * "}" *
+}
+FUNCTION {format.org.or.pub}
+{ 't :=
+  ""
+  address empty$ t empty$ and
+    'skip$
+    {
+      t empty$
+        { address "address" bibinfo.check *
+        }
+        { t *
+          address empty$
+            'skip$
+            { ", " * address "address" bibinfo.check * }
+          if$
+        }
+      if$
+    }
+  if$
+}
+FUNCTION {format.publisher.address}
+{ publisher "publisher" bibinfo.warn format.org.or.pub
+}
+
+FUNCTION {format.organization.address}
+{ organization "organization" bibinfo.check format.org.or.pub
+}
+
+STRINGS {oldname}
+
+FUNCTION {name.or.dash}
+{ 's :=
+   oldname empty$
+     { s 'oldname := s }
+     { s oldname =
+         { "---{}---{}---" }
+         { s 'oldname := s }
+       if$
+     }
+   if$
+}
+
+FUNCTION {article}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title "title" output.check
+  new.sentence
+  crossref missing$
+    {
+      journal
+      "journal" bibinfo.check
+      emphasize
+      "journal" output.check
+      format.vol.num.pages output
+  format.doi output
+    }
+    { format.article.crossref output.nonnull
+      format.pages output
+    }
+  if$
+  format.note output
+  format.eprint output
+  fin.entry
+}
+FUNCTION {book}
+{ output.bibitem
+  author empty$
+    { format.editors "author and editor" output.check
+      editor format.key output
+      add.blank
+      name.or.dash
+    }
+    { format.authors output.nonnull
+      name.or.dash
+      crossref missing$
+        { "author and editor" editor either.or.check }
+        'skip$
+      if$
+    }
+  if$
+  format.date "year" output.check
+  date.block
+  format.btitle "title" output.check
+  crossref missing$
+    { format.bvolume output
+  new.sentence
+      format.edition output
+      format.number.series output
+      format.publisher.address output
+    }
+    {
+  new.sentence
+      format.book.crossref output.nonnull
+    }
+  if$
+  format.book.pages output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+FUNCTION {booklet}
+{ output.bibitem
+  format.authors output
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title "title" output.check
+  new.sentence
+  howpublished "howpublished" bibinfo.check output
+  address "address" bibinfo.check output
+  format.book.pages output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {inbook}
+{ output.bibitem
+  author empty$
+    { format.editors "author and editor" output.check
+      editor format.key output
+      name.or.dash
+    }
+    { format.authors output.nonnull
+      name.or.dash
+      crossref missing$
+        { "author and editor" editor either.or.check }
+        'skip$
+      if$
+    }
+  if$
+  format.date "year" output.check
+  date.block
+  format.btitle "title" output.check
+  crossref missing$
+    {
+      format.bvolume output
+      format.chapter.pages "chapter and pages" output.check
+  new.sentence
+      format.edition output
+      format.number.series output
+      format.publisher.address output
+    }
+    {
+      format.chapter.pages "chapter and pages" output.check
+  new.sentence
+      format.book.crossref output.nonnull
+    }
+  if$
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {incollection}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title "title" output.check
+  new.sentence
+  crossref missing$
+    { format.in.ed.booktitle "booktitle" output.check
+      format.publisher.address output      
+      format.bvolume output
+      format.number.series output
+      format.edition output
+      format.chapter.pages output
+    }
+    { format.incoll.inproc.crossref output.nonnull
+      format.chapter.pages output
+    }
+  if$
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+FUNCTION {inproceedings}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title "title" output.check
+  new.sentence
+  crossref missing$
+    { format.in.ed.booktitle "booktitle" output.check
+      publisher empty$
+        { format.organization.address output }
+        { organization "organization" bibinfo.check output
+          format.publisher.address output
+        }
+      if$
+      format.bvolume output
+      format.pages output
+      format.number.series output
+      howpublished "howpublished" bibinfo.check output
+    }
+    { format.incoll.inproc.crossref output.nonnull
+      format.pages output
+    }
+  if$
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+FUNCTION {conference} { inproceedings }
+FUNCTION {manual}
+{ output.bibitem
+  format.authors output
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.btitle "title" output.check
+  new.sentence
+  organization "organization" bibinfo.check output
+  address "address" bibinfo.check output
+  format.edition output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {mastersthesis}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title
+  "title" output.check
+  new.sentence
+  bbl.mthesis format.thesis.type output.nonnull
+  department "department" bibinfo.warn output
+  school "school" bibinfo.warn output
+  address "address" bibinfo.check output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {misc}
+{ output.bibitem
+  format.authors output
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title output
+  new.sentence
+  howpublished "howpublished" bibinfo.check output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+FUNCTION {phdthesis}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title
+  "title" output.check
+  new.sentence
+  bbl.phdthesis format.thesis.type output.nonnull
+  school "school" bibinfo.warn output
+  address "address" bibinfo.check output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {proceedings}
+{ output.bibitem
+  format.editors output
+  editor format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.btitle "title" output.check
+  format.bvolume output
+  format.number.series output
+  publisher empty$
+    { format.organization.address output }
+    { organization "organization" bibinfo.check output
+      format.publisher.address output
+    }
+  if$
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {techreport}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title
+  "title" output.check
+  new.sentence
+  format.tr.number output.nonnull
+  institution "institution" bibinfo.warn output
+  address "address" bibinfo.check output
+  format.doi output
+  format.note output
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {unpublished}
+{ output.bibitem
+  format.authors "author" output.check
+  author format.key output
+  name.or.dash
+  format.date "year" output.check
+  date.block
+  format.title "title" output.check
+  format.doi output
+  format.note "note" output.check
+  format.eprint output
+  fin.entry
+}
+
+FUNCTION {default.type} { misc }
+READ
+FUNCTION {sortify}
+{ purify$
+  "l" change.case$
+}
+INTEGERS { len }
+FUNCTION {chop.word}
+{ 's :=
+  'len :=
+  s #1 len substring$ =
+    { s len #1 + global.max$ substring$ }
+    's
+  if$
+}
+FUNCTION {format.lab.names}
+{ 's :=
+  "" 't :=
+  s #1 "{vv~}{ll}" format.name$
+  s num.names$ duplicate$
+  #2 >
+    { pop$
+      " " * bbl.etal *
+    }
+    { #2 <
+        'skip$
+        { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
+            {
+              " " * bbl.etal *
+            }
+            { bbl.and space.word * s #2 "{vv~}{ll}" format.name$
+              * }
+          if$
+        }
+      if$
+    }
+  if$
+}
+
+FUNCTION {author.key.label}
+{ author empty$
+    { key empty$
+        { cite$ #1 #3 substring$ }
+        'key
+      if$
+    }
+    { author format.lab.names }
+  if$
+}
+
+FUNCTION {author.editor.key.label}
+{ author empty$
+    { editor empty$
+        { key empty$
+            { cite$ #1 #3 substring$ }
+            'key
+          if$
+        }
+        { editor format.lab.names }
+      if$
+    }
+    { author format.lab.names }
+  if$
+}
+
+FUNCTION {editor.key.label}
+{ editor empty$
+    { key empty$
+        { cite$ #1 #3 substring$ }
+        'key
+      if$
+    }
+    { editor format.lab.names }
+  if$
+}
+
+FUNCTION {calc.short.authors}
+{ type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.key.label
+    { type$ "proceedings" =
+        'editor.key.label
+        'author.key.label
+      if$
+    }
+  if$
+  'short.list :=
+}
+
+FUNCTION {calc.label}
+{ calc.short.authors
+  short.list
+  "("
+  *
+  year duplicate$ empty$
+     { pop$ "????" }
+     { purify$ #-1 #4 substring$ }
+  if$
+  *
+  'label :=
+}
+
+FUNCTION {sort.format.names}
+{ 's :=
+  #1 'nameptr :=
+  ""
+  s num.names$ 'numnames :=
+  numnames 'namesleft :=
+    { namesleft #0 > }
+    { s nameptr
+      "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}"
+      format.name$ 't :=
+      nameptr #1 >
+        {
+          "   "  *
+          namesleft #1 = t "others" = and
+            { "zzzzz" * }
+            { t sortify * }
+          if$
+        }
+        { t sortify * }
+      if$
+      nameptr #1 + 'nameptr :=
+      namesleft #1 - 'namesleft :=
+    }
+  while$
+}
+
+FUNCTION {sort.format.title}
+{ 't :=
+  "A " #2
+    "An " #3
+      "The " #4 t chop.word
+    chop.word
+  chop.word
+  sortify
+  #1 global.max$ substring$
+}
+FUNCTION {author.sort}
+{ author empty$
+    { key empty$
+        { "to sort, need author or key in " cite$ * warning$
+          ""
+        }
+        { key sortify }
+      if$
+    }
+    { author sort.format.names }
+  if$
+}
+FUNCTION {author.editor.sort}
+{ author empty$
+    { editor empty$
+        { key empty$
+            { "to sort, need author, editor, or key in " cite$ * warning$
+              ""
+            }
+            { key sortify }
+          if$
+        }
+        { editor sort.format.names }
+      if$
+    }
+    { author sort.format.names }
+  if$
+}
+FUNCTION {editor.sort}
+{ editor empty$
+    { key empty$
+        { "to sort, need editor or key in " cite$ * warning$
+          ""
+        }
+        { key sortify }
+      if$
+    }
+    { editor sort.format.names }
+  if$
+}
+FUNCTION {presort}
+{ calc.label
+  label sortify
+  "    "
+  *
+  type$ "book" =
+  type$ "inbook" =
+  or
+    'author.editor.sort
+    { type$ "proceedings" =
+        'editor.sort
+        'author.sort
+      if$
+    }
+  if$
+  #1 entry.max$ substring$
+  'sort.label :=
+  sort.label
+  *
+  "    "
+  *
+  title field.or.null
+  sort.format.title
+  *
+  #1 entry.max$ substring$
+  'sort.key$ :=
+}
+
+ITERATE {presort}
+SORT
+STRINGS { last.label next.extra }
+INTEGERS { last.extra.num number.label }
+FUNCTION {initialize.extra.label.stuff}
+{ #0 int.to.chr$ 'last.label :=
+  "" 'next.extra :=
+  #0 'last.extra.num :=
+  #0 'number.label :=
+}
+FUNCTION {forward.pass}
+{ last.label label =
+    { last.extra.num #1 + 'last.extra.num :=
+      last.extra.num int.to.chr$ 'extra.label :=
+    }
+    { "a" chr.to.int$ 'last.extra.num :=
+      "" 'extra.label :=
+      label 'last.label :=
+    }
+  if$
+  number.label #1 + 'number.label :=
+}
+FUNCTION {reverse.pass}
+{ next.extra "b" =
+    { "a" 'extra.label := }
+    'skip$
+  if$
+  extra.label 'next.extra :=
+  extra.label
+  duplicate$ empty$
+    'skip$
+    { "{\natexlab{" swap$ * "}}" * }
+  if$
+  'extra.label :=
+  label extra.label * 'label :=
+}
+EXECUTE {initialize.extra.label.stuff}
+ITERATE {forward.pass}
+REVERSE {reverse.pass}
+FUNCTION {bib.sort.order}
+{ sort.label
+  "    "
+  *
+  year field.or.null sortify
+  *
+  "    "
+  *
+  title field.or.null
+  sort.format.title
+  *
+  #1 entry.max$ substring$
+  'sort.key$ :=
+}
+ITERATE {bib.sort.order}
+SORT
+FUNCTION {begin.bib}
+{ preamble$ empty$
+    'skip$
+    { preamble$ write$ newline$ }
+  if$
+  "\begin{thebibliography}{" number.label int.to.str$ * "}" *
+  write$ newline$
+  "\providecommand{\natexlab}[1]{#1}"
+  write$ newline$
+  "\providecommand{\url}[1]{\texttt{#1}}"
+  write$ newline$
+  "\providecommand{\urlprefix}{URL }"
+  write$ newline$
+  "\expandafter\ifx\csname urlstyle\endcsname\relax"
+  write$ newline$
+  "  \providecommand{\doi}[1]{doi:\discretionary{}{}{}#1}\else"
+  write$ newline$
+  "  \providecommand{\doi}{doi:\discretionary{}{}{}\begingroup \urlstyle{rm}\Url}\fi"
+  write$ newline$
+  "\providecommand{\eprint}[2][]{\url{#2}}"
+  write$ newline$
+}
+EXECUTE {begin.bib}
+EXECUTE {init.state.consts}
+ITERATE {call.type$}
+FUNCTION {end.bib}
+{ newline$
+  "\end{thebibliography}" write$ newline$
+}
+EXECUTE {end.bib}
+%% End of customized bst file
+%%
+%% End of file `ametsoc7.bst'.
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/clean.sh
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/clean.sh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/clean.sh	(revision 4536)
@@ -0,0 +1,2 @@
+rm -f $( ls -1 NEMO_book.* | egrep -v "(tex|pdf)" ) *mpgraph*
+rm -f Chapters/*.aux Chapters/*.log
Index: /branches/2010_and_older/dev_001_GM/DOC/BETA/namlist_opa_New
===================================================================
--- /branches/2010_and_older/dev_001_GM/DOC/BETA/namlist_opa_New	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/DOC/BETA/namlist_opa_New	(revision 4536)
@@ -0,0 +1,513 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! OPA namelists :   1 - run manager      (namrun, nam_ctl, nam_mpp)
+!!                   2 - Domain           (nam_zgr, nam_zgr_sco, namdom)
+!!                   3 - Surface boundary (namtau, namflx, namqsr, namfwb, namalb, namcpl)
+!!                   4 - lateral boundary (namlbc, namobc, namcla)
+!!                   5 - bottom  boundary (nambfr, nambbc, nambbl)
+!!                   6 - Tracer           (nam_traadv, nam_traldf, namtdp)
+!!                   7 - dynamics         (nam_dynvor, nam_dynhpg, namcfg, nam_dynldf)
+!!                   8 - Verical physics  (namzdf, namnpc, namgap, namznl, namspr, namflo)
+!!                   9 - diagnostics      (namtrd, namgap, namznl, namptr, namspr, namflo)
+!!                   9 - miscellaneous    (solver)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!  CAUTION: some scripts does not support CAPITALs for logical definition 
+!  *******       use .true. or .false. and NOT .TRUE. or .FALSE.
+
+!!======================================================================
+!!                   ***  Run management namelists  ***
+!!======================================================================
+!!   namrun       parameters of the run
+!!   nam_ctl      Control prints & Benchmark
+!!   nam_mpp      Massively Parallel Processing
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namrun   !   parameters of the run
+!-----------------------------------------------------------------------
+   no         =       0    !  job number
+   cexper     =  "ORCA2"   !  experience name for vairmer format
+   ln_rstart  = .false.    !  boolean term for restart (true or false)
+   nrstdt     =       0    !  restart control = 0 restart, do not control nit000 in the restart file.
+                           !                  = 1 restart, control nit000 in the restart file. Do not
+                           !                      use the date in the restart file (use ndate0 in namelist)
+                           !                  = 2 restart, control nit000 in the restart file, use the date
+                           !                      in the restart file. ndate0 in the namelist is ignored.
+   nit000     =       1    !  number of the first time step
+   nitend     =    5475    !  number of the first time step
+   ndate0     =  010101    !  initial calendar date aammjj
+   nleapy     =       0    !  Leap year calendar (0/1)
+   ninist     =       0    !  initial state output flag (0/1)
+   nstock     =    5475    !  number of the first time step
+   nwrite     =    5475    !  frequency of OUTPUT file
+   nrunoff    =       2    !  = 0 no, 1 runoff, 2 runoff+river mouth ups adv
+/
+!-----------------------------------------------------------------------
+&nam_ctl      !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+   ln_ctl =  .false.       !  trends control print (expensive!)
+   nprint =       0        !  level of print (0 no print)
+   nictls =       0        !  start i indice to make the control SUM (very usefull to compare mono-
+   nictle =       0        !  end   i indice to make the control SUM (-versus multi processor runs)
+   njctls =       0        !  start j indice to make the control SUM (very usefull to compare mono-
+   njctle =       0        !  end   j indice to make the control SUM (-versus multi processor runs)
+   isplt  =       1        !  number of processors following i
+   jsplt  =       1        !  number of processors following j
+   nbench =       0        !  Bench parameter (0/1): CAUTION it must be zero except for bench
+                           !     for which we don't care about physical meaning of the results
+   nbit_cmp =     0        !  bit comparison mode parameter (0/1): enables bit comparison between 
+                           !             single and multiple processor runs
+/
+!-----------------------------------------------------------------------
+&nam_mpp      !   Massively Parallel Processing
+!-----------------------------------------------------------------------
+   c_mpi_send =  'S'       !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
+                           !  buffer blocking send or immediate non-blocking sends, resp.
+/
+
+!!======================================================================
+!!                      ***  Domain namelists  ***
+!!======================================================================
+!!   nam_zgr       vertical coordinate
+!!   nam_zgr_sco   s-coordinate or hybrid z-s-coordinate
+!!   namdom        space and time domain (bathymetry, mesh, timestep)
+!!======================================================================
+!-----------------------------------------------------------------------
+&nam_zgr       !   vertical coordinate
+!-----------------------------------------------------------------------
+   ln_zco   =  .false.     !  z-coordinate - full    steps   (T/F)      ("key_zco" may also be defined)
+   ln_zps   =  .true.      !  z-coordinate - partial steps   (T/F)
+   ln_sco   =  .false.     !  s- or hybrid z-s-coordinate    (T/F)
+/
+!-----------------------------------------------------------------------
+&nam_zgr_sco   !   s-coordinate or hybrid z-s-coordinate
+!-----------------------------------------------------------------------
+   sbot_min =  300.        !  minimum depth of s-bottom surface (>0) (m)
+   sbot_max = 5250.        !  maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+   theta    =    6.0       !  surface control parameter (0<=theta<=20)
+   thetb    =    0.75      !  bottom control parameter  (0<=thetb<= 1)
+   r_max    =    0.15      !  maximum cut-off r-value allowed (0<r_max<1)
+/
+!-----------------------------------------------------------------------
+&namdom   !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   ntopo     =     1       !  = 0/1 ,compute/read the bathymetry file (mbathy, nb of T-ocean levels)
+   e3zps_min =     5.      !  the thickness of the partial step is set larger than the minimum
+   e3zps_rat =     0.1     !  of e3zps_min and e3zps_rat * e3t   (N.B. 0<e3zps_rat<1)
+   nmsh      =     0       !  =1 create a mesh file (coordinates, scale factors, masks)
+   nacc      =     0       !  the acceleration of convergence method   = 0, no acceleration, rdt = rdttra
+                           !                                           = 1, acceleration used, rdt < rdttra(k)
+   atfp      =     0.1     !  asselin time filter parameter
+   rdt       =  5760.      !  time step for the dynamics (and tracer if nacc=0)
+   rdtmin    =  5760.      !  minimum time step on tracers
+   rdtmax    =  5760.      !  maximum time step on tracers
+   rdth      =   800.      !  depth variation of tracer time step
+   rdtbt     =    90.      !  barotropic time step (for the time splitting algorithm)
+   nfice     =     5       !  frequency of ice model call
+   nfbulk    =     5       !  frequency of bulk formulea call (not used if ice used)
+   nclosea   =     0       !  = 0 no closed sea in the model domain
+                           !  = 1 closed sea (Black Sea, Caspian Sea, Great US Lakes...) 
+/
+
+!!======================================================================
+!!            ***  Surface Boundary Condition namelists  ***
+!!======================================================================
+!!   namtau      surface wind stress
+!!   namflx      surface fluxes
+!!   namqsr      penetrative solar radiation
+!!   namfwb      freshwater budget correction
+!!   namalb      albedo parameters
+!!   namcpl      coupled ocean/atmosphere model (#ifdef "key_coupled")
+!!======================================================================
+!-----------------------------------------------------------------------
+&namtau   !   surface wind stress
+!-----------------------------------------------------------------------
+   ntau000 =      0        !  gently increase the stress over the first ntau_rst time-steps
+   tau0x   =      0.e0     !  uniform value used as default surface heat flux
+   tau0y   =      0.e0     !  uniform value used as default solar radiation flux
+/
+!-----------------------------------------------------------------------
+&namflx   !   surface fluxes
+!-----------------------------------------------------------------------
+   q0      =      0.e0     !  uniform value used as default surface heat flux
+   qsr0    =      0.e0     !  uniform value used as default solar radiation flux
+   emp0    =      0.e0     !  uniform value used as default surface freswater budget (E-P)
+   dqdt0   =      -40.     !  feedback coefficient for SST damping (W/m2/K)
+   deds0   =        0.     !  feedback coefficient for SSS damping (mm/day)
+/
+!-----------------------------------------------------------------------
+&namqsr   !   penetrative solar radiation
+!-----------------------------------------------------------------------
+   ln_traqsr = .true.      !  penetrative solar radiation (T) or not (F)     (Default=T)
+   rabs     =   0.58       !  fraction of qsr associated with xsi1
+   xsi1     =   0.35       !  first depth of extinction
+   xsi2     =   23.0       !  second depth of extinction
+/
+!-----------------------------------------------------------------------
+&namfwb   !   freshwater budget correction
+!-----------------------------------------------------------------------
+   ln_fwb    = .true.      !  flag for freshwater budget correction (0 annual mean)
+/
+!-----------------------------------------------------------------------
+&namalb   !   albedo parameters
+!-----------------------------------------------------------------------
+   cgren    =      0.06    !  correction of the snow or ice albedo to take into account
+   albice   =      0.5     !  albedo of melting ice in the arctic and antarctic
+   alphd    =      0.80    !  coefficients for linear interpolation used to
+   alphc    =      0.65    !  compute albedo between two extremes values 
+   alphdi   =      0.72    !  (Pyane, 1972)
+/
+!-----------------------------------------------------------------------
+&namcpl   !   coupled ocean/atmosphere model                            ("key_coupled")
+!-----------------------------------------------------------------------
+/
+
+!!======================================================================
+!!               ***  Lateral boundary condition  ***
+!!======================================================================
+!!   namlbc        lateral momentum boundary condition
+!!   namcro        cross land advection
+!!   namobc        open boundaries parameters                           ("key_obc")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namlbc   !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   shlat  =      2.        !      shlat = 0 : free slip
+                           !  0 < shlat < 2 : partial slip
+                           !      shlat = 2 : no slip
+                           !  2 < shlat     : strong slip
+/
+!-----------------------------------------------------------------------
+&namcro   !   cross land advection
+!-----------------------------------------------------------------------
+!  n_cla   advection between 2 ocean pts separates by land 
+   n_cla   = 1
+/
+!-----------------------------------------------------------------------
+&namobc   !   open boundaries parameters                            ("key_obc")
+!-----------------------------------------------------------------------
+    nobc_dta    =    0     !  = 0 the obc data are equal to the initial state
+                           !  = 1 the obc data are read in 'obc   .dta' files
+    rdpein      =    1.    !  ???
+    rdpwin      =    1.    !  ???
+    rdpnin      =   30.    !  ???
+    rdpsin      =    1.    !  ???
+    rdpeob      = 1500.    !  time relaxation (days) for the east  open boundary
+    rdpwob      =   15.    !    "        "           for the west  open boundary
+    rdpnob      =  150.    !    "        "           for the north open boundary
+    rdpsob      =   15.    !    "        "           for the south open boundary
+    zbsic1      =  140.e+6 !  barotropic stream function on first  isolated coastline
+    zbsic2      =    1.e+6 !    "                   "    on second isolated coastline
+    zbsic3      =    0.    !    "                   "    on thrid  isolated coastline
+    ln_obc_clim = .true.   !  climatological obc data files (default T)
+    ln_vol_cst  = .true.   !  total volume conserved
+/
+
+!!======================================================================
+!!                 ***  Bottom boundary condition  ***
+!!======================================================================
+!!   nambfr        bottom friction
+!!   nambbc        bottom temperature boundary condition                ("key_trabbc")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&nambfr   !   bottom friction
+!-----------------------------------------------------------------------
+   nbotfr =       1        !  type of bottom friction :   = 0 : no slip        ,  = 2 : nonlinear friction
+                           !                              = 1 : linear friction,  = 3 : free slip
+   bfri1  =   4.e-4        !  bottom drag coefficient (linear case)
+   bfri2  =   1.e-3        !  bottom drag coefficient (non linear case)
+   bfeb2  =  2.5e-3        !  bottom turbulent kinetic energy background  (m^2/s^2)
+/
+!-----------------------------------------------------------------------
+&nambbc   !   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+   ngeo_flux =  2             !  = 0 no geothermal heat flux
+                              !  = 1 constant geothermal heat flux
+                              !  = 2 variable geothermal heat flux (read in geothermal_heating.nc in mW/m2) 
+   ngeo_flux_const = 86.4e-3  !  Constant value of geothermal heat flux (W/m2)
+/
+
+!!======================================================================
+!!                        Tracer (T & S ) namelists
+!!======================================================================
+!!   nameos        equation of state
+!!   nam_traadv    advection scheme
+!!   nam_traldf    lateral diffusion scheme
+!!   nambbl        bottom boundary layer scheme                         ("key_trabbl_dif","key_trabbl_adv")
+!!   namdmp        tracer newtonian damping                             ("key_tradmp")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&nameos   !   ocean physical parameters
+!-----------------------------------------------------------------------
+   neos   =      0         !  type of equation of state and Brunt-Vaisala frequency
+                           !     = 0, UNESCO (formulation of Jackett and McDougall (1994) and of McDougall (1987) )
+                           !     = 1, linear: rho(T)   = rau0 * ( 1.028 - ralpha * T )
+                           !     = 2, linear: rho(T,S) = rau0 * ( rbeta * S - ralpha * T )
+   ralpha =  2.e-4         !  thermal expension coefficient (neos= 1 or 2)
+   rbeta  =  0.001         !  saline  expension coefficient (neos= 2)
+/
+!-----------------------------------------------------------------------
+&nam_traadv   !   advection scheme for tracer 
+!-----------------------------------------------------------------------
+   ln_traadv_cen2   =  .true.    !  2nd order centered scheme    (default T)
+   ln_traadv_tvd    =  .false.   !  TVD scheme                   (default F)
+   ln_traadv_muscl  =  .false.   !  MUSCL scheme                 (default F)
+   ln_traadv_muscl2 =  .false.   !  MUSCL2 scheme                (default F)
+   ln_traadv_ubs    =  .false.   !  UBS scheme                   (default F)
+/
+!-----------------------------------------------------------------------
+&nam_traldf   !   lateral diffusion scheme for tracer 
+!-----------------------------------------------------------------------
+!                                !  Type of the operator : 
+   ln_traldf_lap    =  .true.    !     laplacian operator          (default T)
+   ln_traldf_bilap  =  .false.   !     bilaplacian operator        (default F)
+                                 !  Direction of action  :
+   ln_traldf_level  =  .false.   !     iso-level                   (default F)
+   ln_traldf_hor    =  .false.   !     horizontal (geopotential)   (default F)   (require "key_ldfslp" when ln_sco=T)
+   ln_traldf_iso    =  .true.    !     iso-neutral                 (default T)   (require "key_ldfslp")
+!                                !  Coefficient
+   aht0    =  2000.              !     horizontal eddy diffusivity for tracers (m2/s)
+   ahtb0   =     0.              !     background eddy diffusivity for isopycnal diffusion (m2/s)
+   aeiv0   =  2000.              !     eddy induced velocity coefficient (m2/s)  (require "key_traldf_eiv")
+/
+!-----------------------------------------------------------------------
+&nam_trabbl   !   bottom boundary layer scheme                          ("key_trabbl_dif","key_trabbl_adv")
+!-----------------------------------------------------------------------
+!  "key_trabbl	                  ! diffusive bbl 
+!  "key_trabbl_adv               ! advective bbl 
+   atrbbl = 10000.               !  lateral tracer coeff. for bottom boundary layer scheme (m2/s)
+/
+!-----------------------------------------------------------------------
+&namdmp   tracer newtonian damping ('key_tradmp')
+!-----------------------------------------------------------------------
+   ndmp   =   -1                 !  type of damping in temperature and salinity 
+                                 !     ='latitude', damping poleward of 'ndmp' degrees and function 
+                                 !                  of the distance-to-coast. Red and Med Seas as ndmp=-1
+                                 !     =-1 damping only in Med and Red Seas
+   ndmpf  =    1                 !  =1 create a damping.coeff NetCDF file (the 3D damping array)
+   nmldmp =    1                 !  type of damping in the mixed layer
+                                 !     =0 damping throughout the water column
+                                 !     =1 no damping in the mixed layer defined by avt >5cm2/s )
+                                 !     =2 no damping in the mixed layer defined rho<rho(surf)+.01 )
+   sdmp   =  50.                 !  surface time scale for internal damping (days)
+   bdmp   = 360.                 !  bottom  time scale for internal damping (days)
+   hdmp   = 800.                 !  depth of transition between sdmp and bdmp (meters)
+/
+
+!!======================================================================
+!!                      ***  Dynamics namelists  ***
+!!======================================================================
+!!   nam_dynvor    advection scheme
+!!   nam_dynhpg    hydrostatic pressure gradient
+!!   namflg        hydrostatic pressure gradient time stepping
+!!   nam_dynldf    lateral diffusion scheme
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&nam_dynvor   !   option of physics/algorithm 
+!-----------------------------------------------------------------------
+   ln_dynvor_ene = .false.    !  enstrophy conserving scheme (default T)
+   ln_dynvor_ens = .true.     !  energy conserving scheme    (default F)
+   ln_dynvor_mix = .false.    !  mixed scheme                (default F)
+   ln_dynvor_een = .false.    !  energy & enstrophy scheme   (default F)
+/
+!-----------------------------------------------------------------------
+&nam_dynhpg   !   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+   ln_hpg_zco = .false.       !  z-coordinate - full steps                   
+   ln_hpg_zps = .true.        !  z-coordinate - partial steps (interpolation)
+   ln_hpg_sco = .false.       !  s-coordinate (standard jacobian formulation)
+   ln_hpg_hel = .false.       !  s-coordinate (helsinki modification)
+   ln_hpg_wdj = .false.       !  s-coordinate (weighted density jacobian)
+   ln_hpg_djc = .false.       !  s-coordinate (Density Jacobian with Cubic polynomial)
+   ln_hpg_rot = .false.       !  s-coordinate (ROTated axes scheme)
+   gamm       = 0.e0          !  weighting coefficient (wdj scheme)
+/
+!-----------------------------------------------------------------------
+&namflg   !   algorithm flags (algorithm not control by CPP keys)
+!-----------------------------------------------------------------------
+   ln_dynhpg_imp   =  .false. !  hydrostatic pressure gradient: semi-implicit time scheme  (T)
+                              !                                 centered      time scheme  (F)
+   nn_dynhpg_rst   =  0       !  add dynhpg implicit variables in restart ot not (1/0)
+/
+!-----------------------------------------------------------------------
+!nam_dynspg   !   surface pressure gradient   (CPP key only)
+!-----------------------------------------------------------------------
+!                                !  explicit free surface               ("key_dynspg_exp")
+!                                !  filtered free surface               ("key_dynspg_flt")
+!                                !  split-explicit free surface         ("key_dynspg_ts")
+!                                !  rigid-lid                           ("key_dynspg_rl")
+
+!-----------------------------------------------------------------------
+&nam_dynldf   !   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+                                 !  Type of the operator : 
+   ln_dynldf_lap    =  .true.    !     laplacian operator          (default T)
+   ln_dynldf_bilap  =  .false.   !     bilaplacian operator        (default F)
+                                 !  Direction of action  : 
+   ln_dynldf_level  =  .false.   !     iso-level                   (default F)
+   ln_dynldf_hor    =  .true.    !     horizontal (geopotential)   (default F)   (require "key_ldfslp" in s-coord.)
+   ln_dynldf_iso    =  .false.   !     iso-neutral                 (default T)   (require "key_ldfslp")
+                                 !  Coefficient
+   ahm0    = 40000.              !     horizontal eddy viscosity for the dynamics (m2/s)
+   ahmb0   =     0.              !     background eddy viscosity for isopycnal diffusion (m2/s)
+/
+
+!!======================================================================
+!!             Tracers & Dynamics vertical physics namelists
+!!======================================================================
+!!       namzdf        vertical physics
+!!       namnpc        non penetrative convection                       
+!!       nambbl        bottom boundary layer scheme                     ("key_trabbl_dif", "key_trabbl_adv")
+!!       namric        richardson number dependent vertical mixing      ("key_zdfric"      )
+!!       namtke        TKE dependent vertical mixing                    ("key_zdftke"      )
+!!       namkpp        KPP dependent vertical mixing                    ("key_zdfkpp"      )
+!!       namddm        double diffusive mixing parameterization         ("key_zdfddm"      )
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namzdf   !   vertical physics
+!-----------------------------------------------------------------------
+   ln_zdfnpc = .false.        !  Non-Penetrative Convection          (default T)
+   avm0      = 1.2e-4         !  vertical eddy viscosity   for the dynamic (m2/s)   (background Kz if not "key_zdfcst")
+   avt0      = 1.2e-5         !  vertical eddy diffusivity for tracers     (m2/s)   (background Kz if not "key_zdfcst")
+   ln_zdfevd = .true.         !  enhanced vertical diffusion         (default T)
+   avevd     =   100.         !  vertical coefficient for enhanced diffusion scheme (m2/s)
+   n_evdm    =     0          !  enhanced mixing apply on tracer (=0) or on tracer and momentum (=1)
+   ln_zdfexp =  .false.       !  =T/F  split explicit / implicit      (Default=F)
+   n_zdfexp  =     3          !  number of sub-timestep for ln_zdfexp=T
+/
+!-----------------------------------------------------------------------
+&namnpc   !   non penetrative convection
+!-----------------------------------------------------------------------
+   nnpc1  =      1            !  non penetrative convective scheme computation frequency
+   nnpc2  =    365            !  non penetrative convective scheme print frequency
+/
+!-----------------------------------------------------------------------
+&namric   richardson number dependent vertical diffusion                ("key_zdfric" )
+!-----------------------------------------------------------------------
+   avmri = 100.e-4            !  maximum value of the vertical viscosity
+   alp   =      5.            !  coefficient of the parameterization
+   nric  =       2            !  coefficient of the parameterization
+/
+!-----------------------------------------------------------------------
+&namtke   !   turbulent eddy kinetic dependent vertical diffusion       ("key_zdftke" )
+!-----------------------------------------------------------------------
+   ln_rstke = .false.         !  flag to restart with tke from a run without tke (default F)
+   ediff =       0.1          !  coef. to compute vertical eddy coef. (avt=ediff*mxl*sqrt(e) )
+   ediss =       0.7          !  coef. of the Kolmogoroff dissipation
+   ebb   =      3.75          !  coef. of the surface input of tke
+   efave =        1.          !  coef. to applied to the tke diffusion ( avtke=efave*avm )
+   emin  =     1.e-6          !  minimum value of tke (m^2/s^2)
+   emin0 =     1.e-4          !  surface minimum value of tke (m^2/s^2)
+   nitke =        50          !  number of restart iterative loops
+!! ri_c  =         0.22222222 !  critic richardson number (default = 2/9)
+   nmxl  =         2          !  mixing length    = 0 bounded by the distance to surface and bottom
+                              !                   = 1 bounded by the local vertical scale factor
+                              !                   = 2 first vertical derivative of mixing length bounded by 1
+   npdl  =         1          !  prandtl number   = 0 no vertical prandtl number (avt=avm)
+                              !                   = 1 prandtl number function of richarson number (avt=pdl*avm)
+                              !                   = 2 same as = 1 but a shapiro filter is applied on pdl
+   nave  =         1          !  horizontal averaged (=1) or not (=0) on avt and amv   (default =1)
+   navb  =         0          !  constant (=0) or profile (=1) background on avt
+/
+!-----------------------------------------------------------------------
+&namkpp   !   K-Profile Parameterization dependent vertical mixing      ("key_zdfkpp", and optionnally:
+!                                                                        "key_kppcustom" or "key_kpplktb")
+!-----------------------------------------------------------------------
+   ln_kpprimix  = .true.      !  shear instability mixing  (default T)
+   difmiw       =  1.0e-04    !  constant internal wave viscosity (m2/s)
+   difsiw       =  0.1e-04    !  constant internal wave diffusivity (m2/s)
+   Riinfty      =  0.8        !  local Richardson Number limit for shear instability
+   difri        =  0.0050     !  maximum shear mixing at Rig = 0    (m2/s)
+   bvsqcon      = -0.01e-07   !  Brunt-Vaisala squared (1/s**2) for maximum convection
+   difcon       =  1.         !  maximum mixing in interior convection (m2/s)
+   navb         =  0          !  horizontal averaged (=1) or not (=0) on avt and amv   (default =1)
+   nave         =  1          !  constant (=0) or profile (=1) background on avt
+/
+!-----------------------------------------------------------------------
+&namddm   !   double diffusive mixing parameterization                  ("key_zdfddm")
+!-----------------------------------------------------------------------
+      avts  = 1.e-4           !  maximum avs (vertical mixing on salinity)
+      hsbfr = 1.6             !  heat/salt buoyancy flux ratio
+/
+
+!!======================================================================
+!!                  ***  Miscelaneous namelists  ***
+!!======================================================================
+!!   namsol      elliptic solver / island / free surface 
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namsol   !   elliptic solver / island / free surface 
+!-----------------------------------------------------------------------
+   nsolv     =      1         !  type of elliptic solver  =1 preconditioned conjugate gradient (pcg)
+                              !                           =2 successive-over-relaxation (sor)
+                              !                           =3 FETI (fet)                               ("key_feti")
+                              !                           =4 sor with extra outer halo
+   nsol_arp  =      0         !  absolute/relative (0/1) precision convergence test
+   nmin      =    300         !  minimum of iterations for the SOR solver
+   nmax      =    800         !  maximum of iterations for the SOR solver
+   nmod      =     10         !  frequency of test for the SOR solver
+   eps       =  1.E-6         !  absolute precision of the solver
+   resmax    = 1.E-10         !  absolute precision for the SOR solver
+   sor       =   1.92         !  optimal coefficient for SOR solver
+   epsisl    = 1.e-10         !  absolute precision on stream function solver
+   nmisl     =   4000         !  maximum pcg iterations for island                                    ("key_islands")
+   rnu       =     1.         !  strength of the additional force used in filtered free surface
+/
+
+!!======================================================================
+!!                       ***  Diagnostics namelists  ***
+!!======================================================================
+!!   namtrd       dynamics and/or tracer trends                         ("key_trddyn","key_trdtra","key_trdmld")
+!!   namgap       level mean model-data gap                             ("key_diagap")
+!!   namptr       Poleward Transport Diagnostics                        ("key_diaspr")
+!!   namspr       surface pressure diagnosed in rigid-lid               ("key_diaspr")
+!!   namflo       float parameters                                      ("key_float")
+!!======================================================================
+
+!-----------------------------------------------------------------------
+&namtrd    !   diagnostics on dynamics and/or tracer trends             ("key_trddyn" and/or "key_trdtra")
+!                          or mixed-layer trends                        ('key_trdmld')
+!                          or barotropic vorticity                      ("key_trdvor")
+!-----------------------------------------------------------------------
+   ntrd  = 365                   !  time step frequency dynamics and tracers trends
+   nctls =   0                   !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   ln_trdmld_restart = .false.   !  restart for ML diagnostics
+   ucf   =  1.                   !  unit conversion factor (=1 -> /seconds | =86400. -> /day)
+   ln_trdmld_instant = .false.   !  flag to diagnose trends of instantantaneous or mean ML T/S
+/
+!-----------------------------------------------------------------------
+&namgap    !   level mean model-data gap                                ('key_diagap')
+!-----------------------------------------------------------------------
+   ngap =  15                    !  time-step frequency of model-data gap computation
+   nprg =  10                    !  time-step frequency of gap print in model output
+/
+!-----------------------------------------------------------------------
+&namptr   !   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+   ln_diaptr = .false.           !  logical flag for Poleward transport computation
+   ln_subbas = .false.           !  logical flag for Atlantic/Pacific/Indian basins computation
+                                 !  need input basins mask file named "subbasins.nc"
+   nf_ptr    =  15               !  Frequency of computation
+/
+!-----------------------------------------------------------------------
+&namspr  !   surface pressure diagnostic
+!-----------------------------------------------------------------------
+   nmaxp   =   1000              !  maximum of iterations for the solver
+   epsp    =  1.e-3              !  absolute precision of the solver
+   niterp  =    400              !  number of iteration done by the solver
+/
+!-----------------------------------------------------------------------
+&namflo    !   float parameters                                         ("key_float")
+!-----------------------------------------------------------------------
+    ln_rstflo = .false.          !  boolean term for float restart (true or false)
+    nwritefl  =      75          !  frequency of float output file 
+    nstockfl  =    5475          !  frequency of float restart file 
+    ln_argo   = .false.          !  Argo type floats (stay at the surface each 10 days)
+    ln_flork4 = .false.          !  = T trajectories computed with a 4th order Runge-Kutta
+                                 !  = F  (default)   computed with Blanke' scheme
+/
Index: /branches/2010_and_older/dev_001_GM/HEAD/Makefile
===================================================================
--- /branches/2010_and_older/dev_001_GM/HEAD/Makefile	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/HEAD/Makefile	(revision 4536)
@@ -0,0 +1,69 @@
+#####################################################################
+# Author : Claude Talandier for ESOPA
+# Contact : opatlod@locean-ipsl.upmc.fr
+#
+# INPUT ARGS: 3 + 1 (optional)
+#     - NAM_V      : name of the current test
+#     - LISTE_CONF : configurations name (ORCA2_LIM, GYRE ...)
+#     - BUILD_MAKE : run type (mon, mpi ... )
+#     - MAK_TIME   : to perform a CPU time measure making a one year run
+#                    use key word 'timing' or 'notiming'
+#     - REF_TAGV   : (optional) reference tag name. If specified, 
+#                    current results will be compare to the results 
+#                    of this tag (for a given configuration and run type)
+#
+# WORK: Allows to launch all the validation process, i.e. 
+#     I.   compilations
+#     II.  simulations
+#     III. final report
+#
+#####################################################################
+SHELL = /bin/ksh
+#####################################################################
+##### Begin Users modifications
+#####################################################################
+#-
+#- Name of the test
+NAM_V = nemo_v2_3
+#-
+#- Configurations list which must be tested
+LISTE_CONF = GYRE ORCA2_LIM
+#-
+#- Compilation list type to perform, mon (mono) &/or mpi &/or omp (Open-MP)
+BUILD_MAKE =  mon mpi
+#-
+#- Proceed to a timing, use key word 'timing' or 'notiming'
+MAK_TIME = notiming
+#-
+#- Reference Tag version
+REF_TAGV = nemo_v2
+#-
+#####################################################################
+##### End Users modifications
+#####################################################################
+
+##
+all: $(LISTE_CONF)
+	@echo '      '
+	@echo '             ----->>>>>>>>>   Compilation process ended for configuration(s) :' $(LISTE_CONF)
+	@echo '      '
+
+#- Make good links & launch the compilation process
+$(LISTE_CONF):
+	@echo 
+	@echo "CONFIGURATION :" $@
+	( MYREP_LIST=`(cd 2TEST ; ls *.[Ffh]90 *.[Ffh])` ; \
+          cd ../$@/MY_SRC ; rm -rf *.[Ffh]90 ; if [ -n "$$MYREP_LIST" ] ; \
+        then ln -sf ../../HEAD/2TEST/*.[Ffh]90 . ; fi ; ) 
+	@echo "test=" $(NAM_V) > ../$@/specifs.txt
+	@echo "runs=" $(BUILD_MAKE) >> ../$@/specifs.txt
+	@echo "time=" $(MAK_TIME) >> ../$@/specifs.txt
+	@echo "tagname=" $(REF_TAGV) >> ../$@/specifs.txt
+	@echo 
+	@echo '             ----->>>>>>>>>   Links from' $@/MY_SRC ' to HEAD/2TEST done'
+	@echo 
+	@echo '                              Build the Makefile for' $@ 'configuration'
+	../../util/ins_make -w $@
+	@echo
+	@echo
+	gmake -C ../$@ RUN='$(BUILD_MAKE)' RTG=$(REF_TAGV) MKTE=$(MAK_TIME) -j 2 > $@_step.txt
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/diawri1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/diawri1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/diawri1d.F90	(revision 4536)
@@ -0,0 +1,470 @@
+MODULE diawri1d
+   !!======================================================================
+   !!                     ***  MODULE  diawri1d  ***
+   !! Ocean diagnostics :  write ocean output files
+   !!=====================================================================
+#if defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'               1D Configuration
+   !!----------------------------------------------------------------------  
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE zdftke          ! TKE vertical mixing
+   USE zdfkpp          ! KPP vertical mixing
+   USE sol_oce         ! solver variables
+   USE ice_oce         ! ice variables
+   USE phycst          ! physical constants
+   USE ocfzpt          ! ???
+   USE ocesbc          ! surface thermohaline fluxes
+   USE taumod          ! surface stress
+   USE flxrnf          ! ???
+   USE zdfmxl          ! mixed layer
+   USE daymod          ! calendar
+   USE dianam          ! build name of file (routine)
+   USE diawri
+   USE zdfddm          ! vertical  physics: double diffusion
+   USE diahth          ! thermocline diagnostics
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dia_wri_1d                 ! routines called by step.F90
+   !! * Module variables
+   INTEGER ::   &
+      nid_T, nz_T, nh_T, ndim_T, ndim_hT,      &   ! grid_T file
+      ndex(1)                                      ! ???
+   INTEGER, DIMENSION(jpi*jpj) ::   &
+      ndex_hT
+   INTEGER, DIMENSION(jpi*jpj*jpk) ::   &
+      ndex_T
+
+   !! * Substitutions
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   !!----------------------------------------------------------------------
+   !!   Default option                                   NetCDF output file
+   !!----------------------------------------------------------------------
+   !!   dia_wri_1d       : create the standart NetCDF output files
+   !!   dia_wri_state_1d : create an output NetCDF file for a single
+   !!                      instantaeous ocean state and forcing fields
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dia_wri_1d( kt, kindic )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_wri_1d  ***
+      !!                   
+      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
+      !!      NETCDF format is used by default 
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), 
+      !!      define all the NETCDF files and fields
+      !!      At each time step call histdef to compute the mean if ncessary
+      !!      Each nwrite time step, output the instantaneous or mean fields
+      !!      IF kindic <0, output of fields before the model interruption.
+      !!      IF kindic =0, time step loop
+      !!      IF kindic >0, output of fields before the time step loop
+      !!
+      !! History :
+      !!        !  91-03  (M.-A. Foujols)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  correction restart file
+      !!        !  92-07  (M. Imbard)  split into diawri and rstwri
+      !!        !  93-03  (M. Imbard)  suppress writibm
+      !!        !  98-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
+      !!        !  99-02  (E. Guilyardi)  name of netCDF files + variables
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-10  (C. Ethe)   1D Configuration
+      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kindic  ! 
+
+      !! * Local declarations
+      LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
+      CHARACTER (len=40) ::           &
+         clhstnam, clop, clmx            ! temporary names
+      INTEGER ::   inum = 11             ! temporary logical unit
+      INTEGER ::   &
+         ji, jj, ik                      ! dummy loop indices
+      INTEGER ::   &
+         iimi, iima, ipk, it,         &  ! temporary integers
+         ijmi, ijma                      !    "          "
+      REAL(wp) ::   &
+         zsto, zout, zmax,            &  ! temporary scalars
+         zjulian, zdt                    !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zw2d                            ! temporary workspace
+      !!----------------------------------------------------------------------
+      
+      ! 0. Initialisation
+      ! -----------------
+      
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+#if defined key_diainstant
+      zsto = nwrite * zdt
+      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
+      !!! clop="inst(only(x))"   ! put 1.e+20 on land (very expensive!!)
+#else
+      zsto=zdt
+      clop="ave(x)"              ! no use of the mask value (require less cpu time)
+      !!! clop="ave(only(x))"    ! put 1.e+20 on land (very expensive!!)
+#endif
+      zout = nwrite * zdt
+      zmax = ( nitend - nit000 + 1 ) * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nit000 + 1
+
+
+      ! 1. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      IF(ll_print) WRITE(numout,*) 'dia_wri_1d kt = ', kt, ' kindic ', kindic
+
+      IF( kt == nit000 ) THEN
+
+         ! Define the NETCDF files (one per grid)
+         
+         ! Compute julian date from starting date of the run
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
+            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
+         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
+                                 ' limit storage in depth = ', ipk
+
+         ! WRITE root name in date.file for use by postpro
+         CALL dia_nam( clhstnam, nwrite,' ' )
+         CALL ctlopn( inum, 'date.file', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+         WRITE(inum,*) clhstnam
+         CLOSE(inum)
+         
+         ! Define the T grid FILE ( nid_T )
+         
+         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
+            &          0, zjulian, zdt, nh_T, nid_T, domain_id=nidom )
+         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
+            &           "m", ipk, gdept_0, nz_T )
+         !                                                            ! Index of ocean points
+         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
+         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
+
+
+         ! Declare all the output fields as NETCDF variables
+
+         !                                                                                      !!! nid_T : 3D
+         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !                                                                                      !!! nid_T : 2D
+         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+
+#if ! defined key_dynspg_rl && defined key_ice_lim
+         ! sowaflup = sowaflep + sorunoff + sowafldp + a term associated to
+         !    internal damping to Levitus that can be diagnosed from others
+         ! sowaflcd = sowaflep + sorunoff + sowafldp + iowaflup
+         CALL histdef( nid_T, "iowaflup", "Ice=>ocean net freshwater"          , "kg/m2/s",   &  ! fsalt
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowaflep", "atmos=>ocean net freshwater"        , "kg/m2/s",   &  ! fmass
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! emp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sorunoff", "Runoffs"                            , "Kg/m2/s",   &  ! runoffs
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowaflcd", "concentration/dilution water flux"  , "kg/m2/s",   &  ! emps
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosalflx", "Surface Salt Flux"                  , "Kg/m2/s",   &  ! emps * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qt
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#if defined key_zdfkpp
+         CALL histdef( nid_T, "sokppekd", "Ekman depth                     "   , "m"      ,   &  ! sokppekd
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sokppbld", "Boundary Layer Depth            "   , "m"      ,   &  ! sokppbld
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+         CALL histdef( nid_T, "somxlavt", "AVT : bottom of the mixed layer    ", "m"      ,   &  ! avt_mxl
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "soicecov", "Ice Cover"                          , "[0,1]"  ,   &  ! freeze
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#if ! defined key_coupled 
+         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+
+#if ( defined key_coupled && ! defined key_ice_lim ) 
+         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+         clmx ="l_max(only(x))"    ! max index on a period
+         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
+#if defined key_diahth
+         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "W"      ,   & ! htc3
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+
+#if defined key_ice_lim && defined key_coupled
+         CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif 
+
+         !                                                                                      !!! nid_U : 3D
+         CALL histdef( nid_T, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! un
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#if defined key_diaeiv
+         CALL histdef( nid_T, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#endif
+         !                                                                                      !!! nid_U : 2D
+         CALL histdef( nid_T, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! taux
+            &          jpi, jpj, nh_T, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+
+         !                                                                                      !!! nid_V : 3D
+         CALL histdef( nid_T, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vn
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#if defined key_diaeiv
+         CALL histdef( nid_T, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#endif
+         !                                                                                      !!! nid_V : 2D
+         CALL histdef( nid_T, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! tauy
+            &          jpi, jpj, nh_T, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+#if defined key_zdftke
+         !                                                                                      !!! nid_W : 3D
+         CALL histdef( nid_T, "votlsdis", " Dissipation Turbulent Lenght Scale", "m"      ,   &  ! e_dis
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "votlsmix", " Mixing Turbulent Lenght Scale"     , "m"      ,   &  ! e_mix
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "votlspdl", " Prandl Number",                      "-"       ,   &  ! e_pdl
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "votlsric", " Local Richardson Number",            "-"       ,   &  ! e_ric
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "votkeend", "TKE: Turbulent kinetic energy"       , "m2/s"   ,   &  ! TKE
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#endif
+#if defined key_zdfkpp
+         !                                                                                      !!! nid_W : 3D
+         CALL histdef( nid_T, "vokpprig", " Gradient Richardson Number"        ,  "-"      ,   &  ! rig
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "vokpprib", " Bulk Richardson Number    "        ,  "-"      ,   &   ! rib
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "vokppbsf", " Buoyancy forcing          "        , "N/m2"    ,   &  ! sokppbsf
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "vokppmol", "Moning Obukhov length scale     "   , "m"       ,   &  ! sokppmol
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+#endif
+         !
+         CALL histdef( nid_T, "voeosbn2", "Brunt-Vaisala Frequency"             , "m2/s2"  ,   &  ! rn2
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+
+         CALL histdef( nid_T, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+
+         CALL histdef( nid_T, "votkeevd", "Enhanced Vertical Diffusivity",       "m2/s"   ,   &  ! avt_evd
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+
+         CALL histdef( nid_T, "votkeavm", "Vertical Eddy Viscosity",             "m2/s"   ,   &  ! avmu
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_T, "votkeevm", "Enhanced Vertical Viscosity",         "m2/s"   ,   &  ! avmu_evd
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+
+         IF( lk_zdfddm ) THEN
+            CALL histdef( nid_T,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
+               &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         ENDIF
+
+         CALL histend( nid_T )
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
+         IF(ll_print) CALL FLUSH(numout )
+
+      ENDIF
+
+      ! 2. Start writing data
+      ! ---------------------
+
+      ! ndex(1) est utilise ssi l'avant dernier argument est diffferent de 
+      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
+      ! donne le nombre d'elements, et ndex la liste des indices a sortir
+
+      IF( lwp .AND. MOD( kt, nwrite ) == 0 ) THEN 
+         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      ! Write fields on T grid
+      CALL histwrite( nid_T, "votemper", it, tn            , ndim_T , ndex_T  )   ! temperature
+      CALL histwrite( nid_T, "vosaline", it, sn            , ndim_T , ndex_T  )   ! salinity
+      CALL histwrite( nid_T, "sosstsst", it, tn(:,:,1)     , ndim_hT, ndex_hT )   ! sea surface temperature
+      CALL histwrite( nid_T, "sosaline", it, sn(:,:,1)     , ndim_hT, ndex_hT )   ! sea surface salinity
+#if ! defined key_dynspg_rl && defined key_ice_lim
+      CALL histwrite( nid_T, "iowaflup", it, fsalt(:,:)    , ndim_hT, ndex_hT )   ! ice=>ocean water flux
+      CALL histwrite( nid_T, "sowaflep", it, fmass(:,:)    , ndim_hT, ndex_hT )   ! atmos=>ocean water flux
+#endif
+      CALL histwrite( nid_T, "sowaflup", it, emp           , ndim_hT, ndex_hT )   ! upward water flux
+      CALL histwrite( nid_T, "sorunoff", it, runoff        , ndim_hT, ndex_hT )   ! runoff
+      CALL histwrite( nid_T, "sowaflcd", it, emps          , ndim_hT, ndex_hT )   ! c/d water flux
+      zw2d(:,:) = emps(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosalflx", it, zw2d          , ndim_hT, ndex_hT )   ! c/d salt flux
+      CALL histwrite( nid_T, "sohefldo", it, qt            , ndim_hT, ndex_hT )   ! total heat flux
+      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
+      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
+#if defined key_zdfkpp
+      CALL histwrite( nid_T, "sokppekd", it, ekdp          , ndim_hT, ndex_hT )   ! Ekman depht
+      CALL histwrite( nid_T, "sokppbld", it, hkpp          , ndim_hT, ndex_hT )   ! boundary layer depth 
+#endif  
+      ! store the vertical eddy diffusivity coef. at the bottom of the mixed layer
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ik = nmln(ji,jj)
+            zw2d(ji,jj) = avt(ji,jj,ik) * tmask(ji,jj,1)
+         END DO
+      END DO
+      CALL histwrite( nid_T, "somxlavt", it, zw2d          , ndim_hT, ndex_hT )   ! Kz at bottom of mixed layer 
+      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
+      CALL histwrite( nid_T, "soicecov", it, freeze        , ndim_hT, ndex_hT )   ! ice cover 
+#if ! defined key_coupled
+      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+      zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+#endif
+#if ( defined key_coupled && ! defined key_ice_lim ) 
+      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+         zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+#endif
+         zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
+
+#if defined key_diahth
+      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
+      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
+      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
+      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
+#endif
+#if defined key_ice_lim &&  defined key_coupled 
+      CALL histwrite( nid_T, "soicetem", it, tn_ice        , ndim_hT, ndex_hT )   ! surf. ice temperature
+      CALL histwrite( nid_T, "soicealb", it, alb_ice       , ndim_hT, ndex_hT )   ! ice albedo
+#endif
+
+      CALL histwrite( nid_T, "vozocrtx", it, un            , ndim_T , ndex_T )    ! i-current
+      CALL histwrite( nid_T, "sozotaux", it, taux          , ndim_hT, ndex_hT )   ! i-wind stress
+      CALL histwrite( nid_T, "vomecrty", it, vn            , ndim_T , ndex_T  )   ! j-current
+      CALL histwrite( nid_T, "sometauy", it, tauy          , ndim_hT, ndex_hT )   ! j-wind stress
+#if defined key_zdftke
+      CALL histwrite( nid_T, "votlsdis", it, e_dis         , ndim_T , ndex_T )    ! Diss. Turb. lenght scale
+      CALL histwrite( nid_T, "votlsmix", it, e_mix         , ndim_T , ndex_T )    ! Mixing Turb. lenght scale
+      CALL histwrite( nid_T, "votlspdl", it, e_pdl         , ndim_T , ndex_T )    ! Prandl number
+      CALL histwrite( nid_T, "votlsric", it, e_ric         , ndim_T , ndex_T )    ! local Richardson number
+      CALL histwrite( nid_T, "votkeend", it, en            , ndim_T , ndex_T )    ! TKE
+#endif
+#if defined key_zdfkpp
+      CALL histwrite( nid_T, "vokpprig", it, rig           , ndim_T , ndex_T )    ! gradient Richardson number
+      CALL histwrite( nid_T, "vokpprib", it, rib           , ndim_T , ndex_T )    ! bulk Richardson number
+      CALL histwrite( nid_T, "vokppbsf", it, buof          , ndim_T , ndex_T )    ! buoyancy forcing
+      CALL histwrite( nid_T, "vokppmol", it, mols          , ndim_T , ndex_T )    ! Moning-Obukov length scale
+#endif
+      CALL histwrite( nid_T, "voeosbn2", it, rn2           , ndim_T , ndex_T )    ! Brunt-Vaisala Frequency
+      CALL histwrite( nid_T, "votkeavt", it, avt           , ndim_T , ndex_T )    ! T vert. eddy diff. coef.
+      CALL histwrite( nid_T, "votkeevd", it, avt_evd       , ndim_T , ndex_T )    ! T enhan. vert. eddy diff. coef.
+      CALL histwrite( nid_T, "votkeavm", it, avmu          , ndim_T , ndex_T )    ! T vert. eddy visc. coef.
+      CALL histwrite( nid_T, "votkeevm", it, avmu_evd      , ndim_T , ndex_T )    ! T enhan. vert. eddy visc. coef.
+      IF( lk_zdfddm ) THEN
+         CALL histwrite( nid_T, "voddmavs", it, fsavs(:,:,:), ndim_T, ndex_T )    ! S vert. eddy diff. coef.
+      ENDIF
+
+      ! 3. Synchronise and close all files
+      ! ---------------------------------------
+      IF( MOD( kt, nwrite ) == 0 .OR. kindic < 0 ) THEN
+         CALL histsync( nid_T )
+      ENDIF
+
+      !  Create an output files (output.abort.nc) if S < 0 or u > 20 m/s
+      IF( kindic < 0 )   CALL dia_wri_state( 'output.abort' )
+
+      IF( kt == nitend .OR. kindic < 0 ) THEN
+         CALL histclo( nid_T )
+      ENDIF
+
+   END SUBROUTINE dia_wri_1d
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO 1D Config
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dia_wri_1d ( kt, kindic )
+      WRITE(*,*) 'dia_wri_1d: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE dia_wri_1d
+#endif
+
+   !!======================================================================
+END MODULE diawri1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dyncor1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dyncor1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dyncor1d.F90	(revision 4536)
@@ -0,0 +1,169 @@
+MODULE dyncor1d
+   !!======================================================================
+   !!                     ***  MODULE  ini1D  ***
+   !! Ocean state   :  1D initialization
+   !!=====================================================================
+#if defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'               1D Configuration
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   fcorio_1d   : Coriolis factor at T-point
+   !!   dyn_cor_1d  : vorticity trend due to Coriolis
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC fcorio_1d   ! routine called by OPA.F90
+   PUBLIC dyn_cor_1d  ! routine called by step1d.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE fcorio_1d
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE fcorio_1d  ***
+      !! 
+      !! ** Purpose : Compute the Coriolis factor at T-point
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  04-09  (C. Ethe) 1D configuration
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   &
+         zphi0, zbeta, zf0         !  temporary scalars
+ 
+
+      !!----------------------------------------------------------------------
+
+      ! ================= !
+      !  Coriolis factor  !
+      ! ================= !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'fcorio_1d : Coriolis factor at T-point'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+      SELECT CASE( jphgr_msh )   ! type of horizontal mesh
+
+      CASE ( 0, 1, 4 )               ! mesh on the sphere
+
+         ff(:,:) = 2. * omega * SIN( rad * gphit(:,:) ) 
+
+      CASE ( 2 )                     ! f-plane at ppgphi0 
+
+         ff(:,:) = 2. * omega * SIN( rad * ppgphi0 )
+
+         IF(lwp) WRITE(numout,*) '          f-plane: Coriolis parameter = constant = ', ff(1,1)
+
+      CASE ( 3 )                     ! beta-plane
+
+         zbeta   = 2. * omega * COS( rad * ppgphi0 ) / ra                     ! beta at latitude ppgphi0
+         zphi0   = ppgphi0 - FLOAT( jpjglo/2) * ppe2_m *1.e-3  / ( ra * rad ) ! latitude of the first row F-points
+         zf0     = 2. * omega * SIN( rad * zphi0 )                            ! compute f0 1st point south
+
+         ff(:,:) = ( zf0  + zbeta * gphit(:,:) * 1.e+3 )                      ! f = f0 +beta* y ( y=0 at south)
+
+         IF(lwp) WRITE(numout,*) '          Beta-plane: Beta parameter = constant = ', ff(1,1)
+         IF(lwp) WRITE(numout,*) '                      Coriolis parameter varies from ', ff(1,1),' to ', ff(1,jpj)
+
+      CASE ( 5 )                     ! beta-plane and rotated domain
+
+         zbeta = 2. * omega * COS( rad * ppgphi0 ) / ra                     ! beta at latitude ppgphi0
+         zphi0 = 15.e0                                                      ! latitude of the first row F-points
+         zf0   = 2. * omega * SIN( rad * zphi0 )                            ! compute f0 1st point south
+
+         ff(:,:) = ( zf0 + zbeta * ABS( gphit(:,:) - zphi0 ) * rad * ra )   ! f = f0 +beta* y ( y=0 at south)
+
+         IF(lwp) WRITE(numout,*) '          Beta-plane: Beta parameter = constant = ', ff(1,1)
+         IF(lwp) WRITE(numout,*) '                      Coriolis parameter varies from ', ff(1,1),' to ', ff(1,jpj)
+
+      END SELECT
+
+   END SUBROUTINE fcorio_1d
+
+
+   SUBROUTINE dyn_cor_1d( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_cor_1d  ***
+      !! 
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!               the general trend of the momentum equation
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  04-09  (C. Ethe) 1D configuration
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt        ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk              ! dummy loop indices
+      REAL(wp) ::   &
+         zua, zva                          ! temporary scalars
+
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_cor_1d : total vorticity trend in 1D'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+      ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zua =    ff(ji,jj) * vn(ji,jj,jk)
+               zva =  - ff(ji,jj) * un(ji,jj,jk)
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+      END DO   
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=ua, clinfo1=' cor  - Ua: ', mask1=umask, &
+            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask)
+      ENDIF
+
+!     IF(l_ctl) THEN         ! print sum trends (used for debugging)
+!        zua = SUM( ua(2:nictl,2:njctl,1:jpkm1) * umask(2:nictl,2:njctl,1:jpkm1) )
+!        zva = SUM( va(2:nictl,2:njctl,1:jpkm1) * vmask(2:nictl,2:njctl,1:jpkm1) )
+!        WRITE(numout,*) ' cor  - Ua: ', zua-u_ctl, ' Va: ', zva-v_ctl
+!        u_ctl = zua   ;   v_ctl = zva
+!     ENDIF
+
+   END SUBROUTINE dyn_cor_1d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO 1D Config
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE fcorio_1d      ! Empty routine
+   END SUBROUTINE fcorio_1d   
+   SUBROUTINE dyn_cor_1d ( kt )
+      WRITE(*,*) 'dyn_cor_1d: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_cor_1d
+#endif
+
+   !!=====================================================================
+END MODULE dyncor1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dynnxt1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dynnxt1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/dynnxt1d.F90	(revision 4536)
@@ -0,0 +1,150 @@
+MODULE dynnxt1d
+   !!======================================================================
+   !!                       ***  MODULE  dynnxt1d  ***
+   !! Ocean dynamics: time stepping in 1D configuration
+   !!======================================================================
+#if defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'               1D Configuration
+   !!----------------------------------------------------------------------  
+   !!----------------------------------------------------------------------
+   !!   dyn_nxt_1d   : update the horizontal velocity from the momentum trend
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! lateral boundary condition (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_nxt_1d                ! routine called by step.F90
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_nxt_1d ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_nxt_1d  ***
+      !!                   
+      !! ** Purpose :   Compute the after horizontal velocity from the 
+      !!      momentum trend.
+      !!
+      !! ** Method  :   Apply lateral boundary conditions on the trends (ua,va) 
+      !!      through calls to routine lbc_lnk.
+      !!      After velocity is compute using a leap-frog scheme environment:
+      !!         (ua,va) = (ub,vb) + 2 rdt (ua,va)
+      !!      Time filter applied on now horizontal velocity to avoid the
+      !!      divergence of two consecutive time-steps and swap of dynamics
+      !!      arrays to start the next time step:
+      !!         (ub,vb) = (un,vn) + atfp [ (ub,vb) + (ua,va) - 2 (un,vn) ]
+      !!         (un,vn) = (ua,va) 
+      !!
+      !! ** Action : - Update ub,vb arrays, the before horizontal velocity
+      !!             - Update un,vn arrays, the now horizontal velocity
+      !!
+      !! History :
+      !!        !  87-02  (P. Andrich, D. L Hostis)  Original code
+      !!        !  90-10  (C. Levy, G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  97-02  (G. Madec & M. Imbard)  opa, release 8.0
+      !!        !  97-04  (A. Weaver)  Euler forward step
+      !!        !  97-06  (G. Madec)  lateral boudary cond., lbc routine
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!        !  04-10  (C. Ethe) 1D configuration
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   z2dt         ! temporary scalar
+      !!----------------------------------------------------------------------
+      !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_nxt_1d : time stepping on 1D configuation'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      z2dt = 2. * rdt
+      IF( neuler == 0 .AND. kt == nit000 )  z2dt = rdt
+
+      ! Lateral boundary conditions on ( ua, va )
+      CALL lbc_lnk( ua, 'U', -1. )
+      CALL lbc_lnk( va, 'V', -1. )
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Next velocity
+         ! -------------
+         DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop
+            DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+               ! Leap-frog time stepping
+               ua(ji,jj,jk) = ( ub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) * umask(ji,jj,jk)
+               va(ji,jj,jk) = ( vb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+ 
+     !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Time filter and swap of dynamics arrays
+         ! ------------------------------------------
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  ! Euler (forward) time stepping
+                  ub(ji,jj,jk) = un(ji,jj,jk)
+                  vb(ji,jj,jk) = vn(ji,jj,jk)
+                  un(ji,jj,jk) = ua(ji,jj,jk)
+                  vn(ji,jj,jk) = va(ji,jj,jk)
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  ! Leap-frog time stepping
+                  ub(ji,jj,jk) = atfp * ( ub(ji,jj,jk) + ua(ji,jj,jk) ) + atfp1 * un(ji,jj,jk)
+                  vb(ji,jj,jk) = atfp * ( vb(ji,jj,jk) + va(ji,jj,jk) ) + atfp1 * vn(ji,jj,jk)
+                  un(ji,jj,jk) = ua(ji,jj,jk)
+                  vn(ji,jj,jk) = va(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=un, clinfo1=' nxt_1d  - Un: ', mask1=umask, &
+            &         tab3d_2=vn, clinfo2=' Vn: ', mask2=vmask)
+      ENDIF
+
+!     IF(l_ctl)   WRITE(numout,*) ' nxt  - Un: ', SUM(un(2:nictl,2:njctl,1:jpkm1)*umask(2:nictl,2:njctl,1:jpkm1)), &
+!     &                                  ' Vn: ', SUM(vn(2:nictl,2:njctl,1:jpkm1)*vmask(2:nictl,2:njctl,1:jpkm1))
+
+   END SUBROUTINE dyn_nxt_1d
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO 1D Config
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_nxt_1d ( kt )
+      WRITE(*,*) 'dyn_nxt_1d: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_nxt_1d
+#endif
+   !!======================================================================
+END MODULE dynnxt1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/icestp1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/icestp1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/icestp1d.F90	(revision 4536)
@@ -0,0 +1,392 @@
+MODULE icestp1d
+   !!======================================================================
+   !!                       ***  MODULE icestp1d   ***
+   !!   Sea-Ice model : 1D LIM Sea ice model time-stepping
+   !!======================================================================
+   !! History :   9.0  !  04-10  (C. Ethe)  from icestp, 1D configuration
+   !!----------------------------------------------------------------------
+#if defined key_cfg_1d && defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'  .AND.                                1D Configuration
+   !!   'key_ice_lim'                                     Lim sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   ice_stp_1d       : sea-ice model time-stepping
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE oce             ! dynamics and tracers variables
+   USE in_out_manager  ! I/O manager
+   USE ice_oce         ! ice variables
+   USE flx_oce         ! forcings variables
+   USE dom_ice         ! LIM sea-ice domain
+   USE cpl_oce         ! coupled ocean-atmosphere variables
+   USE blk_oce         ! bulk variables
+   USE daymod          ! calendar
+   USE phycst          ! Define parameters for the routines
+   USE taumod          ! surface stress forcing
+   USE ice             ! ice variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE limthd
+   USE limflx
+   USE limwri
+   USE limrst
+
+   USE ocesbc          ! thermohaline fluxes
+   USE flxmod          ! thermohaline forcing
+   USE flxrnf          ! runoffs forcing
+   USE tradmp          ! damping salinity trend
+   USE dtatem          ! ocean temperature data
+   USE dtasal          ! ocean salinity data
+   USE ocfzpt          ! surface ocean freezing point
+   USE prtctl          ! Print control
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_stp_1d  ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0 , UCL-LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ice_stp_1d ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_stp_1d  ***
+      !!                   
+      !! ** Purpose :   Louvain la Neuve Sea Ice Model time stepping 
+      !!
+      !! ** Action  : - call the ice dynamics routine 
+      !!              - call the ice advection/diffusion routine 
+      !!              - call the ice thermodynamics routine 
+      !!              - call the routine that computes mass and 
+      !!                heat fluxes at the ice/ocean interface
+      !!              - save the outputs 
+      !!              - save the outputs for restart when necessary
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt         ! ocean time-step index
+
+      INTEGER                      ::   ji, jj                        ! dummy loop indices
+      REAL(wp)                     ::   ztair2                        ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsss_io, zsss2_io, zsss3_io   ! tempory workspaces
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ice_stp_1d : Louvain la Neuve Ice Model (LIM)' 
+         IF(lwp) WRITE(numout,*) '~~~~~~~   forced case using bulk formulea'
+         !  Initialize fluxes fields
+         gtaux(:,:) = 0.e0
+         gtauy(:,:) = 0.e0
+      ENDIF
+
+      ! Temperature , salinity and horizonta wind
+      ! sst_io  and sss_io, u_io and v_io  are initialized at nit000 in limistate.F90 (or limrst.F90) with :
+      !              sst_io = sst_io + (nfice - 1) * (tn(:,:,1)+rt0 )
+      !              sss_io = sss_io + (nfice - 1) * sn(:,:,1)
+      !              u_io   = u_io   + (nfice - 1) * un(:,:,1)
+      !              v_io   = v_io   + (nfice - 1) * vn(:,:,1)
+      !    cumulate fields
+      !
+      sst_io(:,:) = sst_io(:,:) + tn(:,:,1) + rt0
+      sss_io(:,:) = sss_io(:,:) + sn(:,:,1)
+      u_io  (:,:) = u_io  (:,:) + un(:,:,1)
+      v_io  (:,:) = v_io  (:,:) + vn(:,:,1)
+ 
+      
+      IF( MOD( kt-1, nfice ) == 0 ) THEN
+         
+         ! The LIM model is going to be call
+         sst_io(:,:) = sst_io(:,:) / FLOAT( nfice ) * tmask(:,:,1)
+         sss_io(:,:) = sss_io(:,:) / FLOAT( nfice )
+         u_io  (:,:) = u_io  (:,:) / FLOAT( nfice )
+         v_io  (:,:) = v_io  (:,:) / FLOAT( nfice )
+         gtaux (:,:) = taux  (:,:)
+         gtauy (:,:) = tauy  (:,:)
+
+         zsss_io (:,:) = SQRT( sss_io(:,:) ) 
+         zsss2_io(:,:) =  sss_io(:,:) *  sss_io(:,:)
+         zsss3_io(:,:) = zsss_io(:,:) * zsss_io(:,:) * zsss_io(:,:)
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               tfu(ji,jj)  = ABS ( rt0 - 0.0575       *   sss_io(ji,jj)   &
+                  &                    + 1.710523e-03 * zsss3_io(ji,jj)   &
+                  &                    - 2.154996e-04 * zsss2_io(ji,jj) ) * tms(ji,jj)
+            END DO
+         END DO
+         
+         
+         IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+            CALL prt_ctl_info('Ice Forcings ')
+            CALL prt_ctl(tab2d_1=qsr_oce ,clinfo1=' qsr_oce  : ', tab2d_2=qsr_ice , clinfo2=' qsr_ice   : ')
+            CALL prt_ctl(tab2d_1=qnsr_oce,clinfo1=' qnsr_oce : ', tab2d_2=qnsr_ice, clinfo2=' qnsr_ice  : ')
+            CALL prt_ctl(tab2d_1=evap    ,clinfo1=' evap     : ')
+            CALL prt_ctl(tab2d_1=tprecip ,clinfo1=' precip   : ', tab2d_2=sprecip , clinfo2=' Snow      : ')
+            CALL prt_ctl(tab2d_1=gtaux   ,clinfo1=' u-stress : ', tab2d_2=gtauy   , clinfo2=' v-stress  : ')
+            CALL prt_ctl(tab2d_1=sst_io  ,clinfo1=' sst      : ', tab2d_2=sss_io  , clinfo2=' sss       : ')
+            CALL prt_ctl(tab2d_1=u_io    ,clinfo1=' u_io     : ', tab2d_2=v_io    , clinfo2=' v_io      : ')
+            CALL prt_ctl(tab2d_1=hsnif   ,clinfo1=' hsnif  1 : ', tab2d_2=hicif   , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld    ,clinfo1=' frld   1 : ', tab2d_2=sist    , clinfo2=' sist      : ')
+         ENDIF
+                                                                      
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               tio_u(ji,jj) = - gtaux(ji,jj) / rau0
+               tio_v(ji,jj) = - gtauy(ji,jj) / rau0               
+               ztair2       = gtaux(ji,jj) * gtaux(ji,jj) + gtauy(ji,jj) * gtauy(ji,jj)           
+               ust2s(ji,jj) = ( SQRT( ztair2  )  / rau0 )  * tms(ji,jj)  
+            END DO
+         END DO
+
+         !                                                           !-----------------------!
+         CALL lim_rst_opn( kt )                                      ! Open Ice restart file !
+         !                                                           !-----------------------!
+
+         !                                                           !--------------------!
+         CALL lim_thd( kt )                                          ! Ice thermodynamics !
+         !                                                           !--------------------!
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=hsnif ,clinfo1=' hsnif  2 : ', tab2d_2=hicif , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld  ,clinfo1=' frld   2 : ', tab2d_2=sist  , clinfo2=' sist      : ')
+            CALL prt_ctl(tab2d_1=u_io  ,clinfo1=' u_io   4 : ', tab2d_2=v_io  , clinfo2=' v_io      : ')
+            CALL prt_ctl(tab2d_1=tio_u  ,clinfo1=' tio_u  4 : ', tab2d_2=tio_v  , clinfo2=' tio_v     : ')
+         ENDIF
+
+
+
+         ! Mass and heat fluxes from ice to ocean
+         !                                                           !------------------------------!
+         CALL lim_flx                                                ! Ice/Ocean Mass & Heat fluxes !
+         !                                                           !------------------------------!
+
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=hsnif ,clinfo1=' hsnif  7 : ', tab2d_2=hicif , clinfo2=' hicif   : ')
+            CALL prt_ctl(tab2d_1=frld  ,clinfo1=' frld   7 : ', tab2d_2=sist  , clinfo2=' sist      : ')
+            CALL prt_ctl(tab2d_1=tio_u  ,clinfo1=' tio_u  7 : ', tab2d_2=tio_v  , clinfo2=' tio_v     : ')
+         ENDIF
+         !                                                           !-------------!
+         CALL lim_wri( kt )                                          ! Ice outputs !
+         !                                                           !-------------!
+
+         !                                                           !------------------------!
+         IF( lrst_ice ) CALL lim_rst_write( kt )                     ! Write Ice restart file !
+         !                                                           !------------------------!
+
+         ! Re-initialization of forcings
+         qsr_oce (:,:) = 0.e0
+         qsr_ice (:,:) = 0.e0
+         qnsr_oce(:,:) = 0.e0
+         qnsr_ice(:,:) = 0.e0 
+         dqns_ice(:,:) = 0.e0 
+         tprecip (:,:) = 0.e0 
+         sprecip (:,:) = 0.e0
+         qla_ice (:,:) = 0.e0
+         dqla_ice(:,:) = 0.e0
+         fr1_i0  (:,:) = 0.e0
+         fr2_i0  (:,:) = 0.e0
+         evap    (:,:) = 0.e0
+
+        CALL oce_sbc_1d ( kt )
+
+      ENDIF
+
+   END SUBROUTINE ice_stp_1d
+   
+   
+   SUBROUTINE oce_sbc_1d( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE oce_sbc_1d  ***
+      !!                    
+      !! ** Purpose : - Ocean surface boundary conditions with LIM sea-ice
+      !!        model in forced mode using bulk formulea
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      !
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   ztxy
+      !!----------------------------------------------------------------------
+
+      ! 1. initialization to zero at kt = nit000
+      ! ---------------------------------------
+      
+      IF( kt == nit000 ) THEN     
+         qsr    (:,:) = 0.e0
+         qt     (:,:) = 0.e0
+         qrp    (:,:) = 0.e0
+         emp    (:,:) = 0.e0
+         emps   (:,:) = 0.e0
+         erp    (:,:) = 0.e0
+#if ! defined key_dynspg_rl 
+         dmp    (:,:) = 0.e0
+#endif
+      ENDIF
+
+      CALL oce_sbc_dmp       ! Computation of internal and evaporation damping terms       
+
+      ! Surface Ocean fluxes
+      ! ====================
+      
+      ! Surface heat flux (W/m2)
+      ! -----------------
+      
+      qt  (:,:) = fnsolar(:,:) + fsolar(:,:)     ! non solar heat flux + solar flux
+      qsr (:,:) = fsolar(:,:)                     ! solar flux
+      
+#if ! defined key_dynspg_rl     
+      ! total concentration/dilution effect (use on SSS)
+      emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:) + empold
+      
+      ! total volume flux (use on sea-surface height)
+      emp (:,:) = fmass(:,:) -   dmp(:,:) + runoff(:,:) + erp(:,:) + empold      
+#else
+      ! Rigid-lid (emp=emps=E-P-R+Erp)
+      emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:)     ! freshwater flux
+      emp (:,:) = emps(:,:)
+      
+#endif
+      
+      ! Surface stress
+      ! --------------
+      
+      ! update the stress beloww sea-ice area
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vertor opt.
+            ztxy        = freezn(ji,jj)             ! ice/ocean indicator at T-points
+            taux(ji,jj) = (1.-ztxy) * taux(ji,jj) + ztxy * ftaux(ji,jj)    ! stress at the ocean surface
+            tauy(ji,jj) = (1.-ztxy) * tauy(ji,jj) + ztxy * ftauy(ji,jj)
+         END DO
+      END DO
+      
+      ! boundary condition on the stress (taux,tauy)
+      CALL lbc_lnk( taux, 'U', -1. )
+      CALL lbc_lnk( tauy, 'V', -1. )
+      
+      ! Re-initialization of fluxes
+      sst_io(:,:) = 0.e0
+      sss_io(:,:) = 0.e0
+      u_io  (:,:) = 0.e0
+      v_io  (:,:) = 0.e0
+      !
+   END SUBROUTINE oce_sbc_1d
+   
+#if defined key_dtasal
+   !!----------------------------------------------------------------------
+   !!   'key_dtasal'                                          salinity data
+   !!----------------------------------------------------------------------
+   SUBROUTINE oce_sbc_dmp
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE oce_sbc_dmp  ***
+      !!                    
+      !! ** Purpose : Computation of internal and evaporation damping terms 
+      !!        for ocean surface boundary conditions 
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   zerp, zsrp
+#if ! defined key_dynspg_rl
+      REAL(wp) ::   zwei
+      REAL(wp) ::   zerpplus(jpi,jpj), zerpminus(jpi,jpj)
+      REAL(wp) ::   zplus, zminus, zadefi
+# if defined key_tradmp
+      INTEGER jk
+      REAL(wp), DIMENSION(jpi,jpj) ::   zstrdmp
+# endif
+#endif
+      !!----------------------------------------------------------------------
+
+      ! sea ice indicator (1 or 0)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            freezn(ji,jj) = MAX(0., SIGN(1., freeze(ji,jj)-rsmall) )
+         END DO
+      END DO
+
+      ! Initialisation
+      ! --------------
+      ! Restoring coefficients on SST and SSS   
+      zsrp = dqdt0 * ro0cpr * rauw   ! (Kg/m2/s) 
+
+#if ! defined key_dynspg_rl 
+      ! Free-surface
+         
+      ! Internal damping
+# if defined key_tradmp
+      ! Vertical mean of dampind trend (computed in tradmp module)
+      zstrdmp(:,:) = 0.e0
+      DO jk = 1, jpk
+         zstrdmp(:,:) = zstrdmp(:,:) + strdmp(:,:,jk) * fse3t(:,:,jk)
+      END DO
+      ! volume flux associated to internal damping to climatology
+      dmp(:,:) = zstrdmp(:,:) * rauw / ( sss_io(:,:) + 1.e-20 )
+# else
+      dmp(:,:) = 0.e0            ! No internal damping
+# endif
+      
+      !   evaporation damping term ( Surface restoring )
+      zerpplus (:,:) = 0.e0
+      zerpminus(:,:) = 0.e0
+      zplus          =  15. / rday
+      zminus         = -15. / rday
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zerp = ( 1. - 2.*upsrnfh(ji,jj) ) * zsrp   &
+               & * ( sss_io(ji,jj) - s_dta(ji,jj,1) )     &
+               & / ( sss_io(ji,jj) + 1.e-20        )
+            erp(ji,jj) = zerp
+            zerpplus (ji,jj) = MAX( erp(ji,jj), 0.e0 )
+            zerpminus(ji,jj) = MIN( erp(ji,jj), 0.e0 )
+         END DO
+      END DO
+
+      aplus  = 0.e0
+      aminus = 0.e0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zwei   = e1t(ji,jj) * e2t(ji,jj) * tmask_i(ji,jj)
+            aplus  = aplus  + zerpplus (ji,jj) * zwei
+            aminus = aminus - zerpminus(ji,jj) * zwei
+         END DO
+      END DO
+
+      IF(ln_ctl)   WRITE(numout,*) ' oce_sbc_dmp : a+ = ', aplus, ' a- = ', aminus
+#else
+      ! Rigid-lid (emp=emps=E-P-R+Erp)
+      
+      erp(:,:) = ( 1. - freezn(:,:) ) * zsrp    &   ! surface restoring term
+         &     * ( sss_io(:,:) - s_dta(:,:,1) )     &
+         &     / ( sss_io(:,:) + 1.e-20      )
+#endif
+
+   END SUBROUTINE oce_sbc_dmp
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy routine                                      NO salinity data
+   !!----------------------------------------------------------------------
+   SUBROUTINE oce_sbc_dmp         ! Dummy routine
+      WRITE(*,*) 'oce_sbc_dmp: you should not have seen that print! error?'
+   END SUBROUTINE oce_sbc_dmp
+#endif
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module   NO 1D && NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_stp_1d ( kt )     ! Dummy routine
+      WRITE(*,*) 'ice_stp_1d: You should not have seen this print! error?', kt
+   END SUBROUTINE ice_stp_1d
+   SUBROUTINE oce_sbc_1d ( kt )     ! Dummy routine
+      WRITE(*,*) 'oce_sbc_1d: You should not have seen this print! error?', kt
+   END SUBROUTINE oce_sbc_1d
+#endif   
+
+   !!======================================================================
+END MODULE icestp1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/ini1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/ini1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/ini1d.F90	(revision 4536)
@@ -0,0 +1,70 @@
+MODULE ini1d
+   !!======================================================================
+   !!                     ***  MODULE  ini1D  ***
+   !! Ocean state   :  1D initialization
+   !!=====================================================================
+#if defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'               1D Configuration
+   !!----------------------------------------------------------------------
+   !!   init_1d   : initial mask
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain 
+   USE phycst
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share Module variables
+   LOGICAL, PUBLIC, PARAMETER ::  lk_cfg_1d = .TRUE.       !: 1D flag
+
+   !! * Routine accessibility
+   PUBLIC init_1d   ! routine called by OPA.F90
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE init_1d
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE init_1d  ***
+      !! 
+      !! ** Purpose :   Re-Initialization of masks on 1D configuration
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  04-09  (C. Ethe) 1D configuration
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'init_1d :  masks on 1D configuration'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~'
+
+      ! set umask and vmask equal tmask in 1D configuration
+      umask(:,:,:) = tmask(:,:,:)
+      vmask(:,:,:) = tmask(:,:,:)     
+
+   END SUBROUTINE init_1d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO 1D Config
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_cfg_1d = .FALSE.    !: internal damping flag
+CONTAINS
+   SUBROUTINE init_1d       ! Empty routine
+
+   END SUBROUTINE init_1d
+#endif
+
+   !!=====================================================================
+END MODULE ini1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/step1d.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/step1d.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/C1D_SRC/step1d.F90	(revision 4536)
@@ -0,0 +1,291 @@
+MODULE step1d
+   !!======================================================================
+   !!                       ***  MODULE step1D  ***
+   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
+   !!======================================================================
+#if defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!   'key_cfg_1d'               1D Configuration
+   !!----------------------------------------------------------------------  
+   !!----------------------------------------------------------------------
+   !!   stp_1d           : OPA system time-stepping on 1 direction
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE ldftra_oce
+   USE ldfdyn_oce
+   USE in_out_manager  ! I/O manager
+   USE lbclnk
+
+   USE daymod          ! calendar                         (day     routine)
+
+   USE dtatem          ! ocean temperature data           (dta_tem routine)
+   USE dtasal          ! ocean salinity    data           (dta_sal routine)
+   USE dtasst          ! ocean sea surface temerature     (dta_sst routine)
+   USE taumod          ! surface stress                   (tau     routine)
+   USE flxmod          ! thermohaline fluxes              (flx     routine)
+   USE ocesbc          ! thermohaline fluxes              (oce_sbc routine)
+   USE flxrnf          ! runoffs                          (flx_rnf routine)
+   USE flxfwb          ! freshwater budget correction     (flx_fwb routine)
+   USE ocfzpt          ! surface ocean freezing point    (oc_fz_pt routine)
+
+   USE trcstp          ! passive tracer time-stepping     (trc_stp routine)
+
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE tranxt          ! time-stepping                    (tra_nxt routine)
+   USE trazdf          ! vertical diffusion               (tra_zdf routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+
+   USE eosbn2
+
+   USE zdfbfr          ! bottom friction                  (zdf_bfr routine)
+   USE zdftke          ! TKE vertical mixing              (zdf_tke routine)
+   USE zdfkpp          ! KPP vertical mixing              (zdf_kpp routine)
+   USE zdfddm          ! double diffusion mixing          (zdf_ddm routine)
+   USE zdfevd          ! enhanced vertical diffusion      (zdf_evd routine)
+   USE zdfric          ! Richardson vertical mixing       (zdf_ric routine)
+   USE zdfmxl          ! Mixed-layer depth                (zdf_mxl routine)
+
+   USE dyncor1d
+   USE dynnxt1d
+   USE diawri1d        ! Standard run outputs             (dia_wri_1d routine)
+
+   USE ice_oce         ! sea-ice variable
+   USE icestp1d        ! sea-ice time-stepping             (ice_stp routine)
+
+   USE diawri          ! Standard run outputs             (dia_wri_state routine)
+
+
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC stp_1d            ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE stp_1d( kstp )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp1D  ***
+      !!                      
+      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
+      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
+      !! 
+      !! ** Method  : -1- Update forcings and data  
+      !!              -2- Update ocean physics 
+      !!              -3- Compute the t and s trends 
+      !!              -4- Update t and s 
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
+      !!              -8- Outputs and diagnostics
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  add a first output record
+      !!        !  96-04  (G. Madec)  introduction of dynspg
+      !!        !  96-04  (M.A. Foujols)  introduction of passive tracer
+      !!   8.0  !  97-06  (G. Madec)  new architecture of call
+      !!   8.2  !  97-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+      !!   8.2  !  99-02  (G. Madec, N. Grima)  hpg implicit
+      !!   8.2  !  00-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+      !!   9.0  !  02-06  (G. Madec)  free form, suppress macro-tasking
+      !!        !  04-10  (C. Ethe) 1D configuration
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kstp   ! ocean time-step index
+
+      !! * local declarations
+      INTEGER ::   indic    ! error indicator if < 0
+!!      INTEGER ::   ii0, ii1, ij0, ij1   ! temporary integers
+      !! ---------------------------------------------------------------------
+
+      indic = 1                    ! reset to no error condition
+      adatrj = adatrj + rdt/86400._wp
+
+      CALL day( kstp )             ! Calendar
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update data, open boundaries and Forcings
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_dtatem  )   CALL dta_tem( kstp )         ! update 3D temperature data
+
+      IF( lk_dtasal  )   CALL dta_sal( kstp )         ! Salinity data
+
+      IF( lk_dtasst  )   CALL dta_sst( kstp )         ! Sea Surface Temperature data
+
+                         CALL tau( kstp )             ! wind stress
+
+                         CALL flx_rnf( kstp )         ! runoff data
+
+                         CALL flx( kstp )             ! heat and freshwater fluxes
+
+      IF( lk_ice_lim )  THEN 
+                        CALL ice_stp_1d( kstp )      ! sea-ice model (Update stress & fluxes)
+      ELSE
+                        CALL oce_sbc( kstp )         ! ocean surface boudaries
+      ENDIF
+
+      IF( ln_fwb     )   CALL flx_fwb( kstp )         ! freshwater budget
+
+
+      IF( kstp == nit000 ) THEN 
+         IF( ninist == 1 ) THEN                       ! Output the initial state and forcings
+            CALL dia_wri_state( 'output.init' )
+         ENDIF
+      ENDIF
+
+      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+         CALL prt_ctl(tab2d_1=emp    , clinfo1=' emp  -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=emps   , clinfo1=' emps -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=qt     , clinfo1=' qt   -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=qsr    , clinfo1=' qsr  -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=runoff , clinfo1=' runoff   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab3d_1=tmask  , clinfo1=' tmask    : ', mask1=tmask, ovlap=1, kdim=jpk)
+         CALL prt_ctl(tab3d_1=tn     , clinfo1=' sst  -   : ', mask1=tmask, ovlap=1, kdim=1)
+         CALL prt_ctl(tab3d_1=sn     , clinfo1=' sss  -   : ', mask1=tmask, ovlap=1, kdim=1)
+         CALL prt_ctl(tab2d_1=taux   , clinfo1=' tau  - x : ', mask1=umask, &
+            &         tab2d_2=tauy   , clinfo2='      - y : ', mask2=vmask, ovlap=1)
+      ENDIF
+
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                       CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
+      
+      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
+      IF( lk_zdfric )   CALL zdf_ric( kstp )                       ! Richardson number dependent Kz
+      IF( lk_zdftke )   CALL zdf_tke( kstp )                       ! TKE closure scheme for Kz
+      IF( lk_zdfkpp )   CALL zdf_kpp( kstp )                       ! KPP scheme for Kz
+      IF( lk_zdfcst )   avt (:,:,:) = avt0 * tmask(:,:,:)          ! Constant Kz (reset avt to the background value)
+
+
+      IF( ln_zdfevd )   CALL zdf_evd( kstp )                 ! enhanced vertical eddy diffusivity
+
+      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp)   &
+         &              CALL zdf_ddm( kstp )                 ! double diffusive mixing
+
+                        CALL zdf_bfr( kstp )                 ! bottom friction
+
+                        CALL zdf_mxl( kstp )                 ! mixed layer depth
+
+
+#if defined key_passivetrc
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                               CALL trc_stp( kstp, indic )            ! time-stepping
+
+#endif
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                               ta(:,:,:) = 0.e0               ! set tracer trends to zero
+                               sa(:,:,:) = 0.e0
+
+                               CALL tra_sbc( kstp )           ! surface boundary condition
+
+      IF( ln_traqsr        )   CALL tra_qsr( kstp )           ! penetrative solar radiation qsr
+
+      IF( lk_zdfkpp        )   CALL tra_kpp( kstp )           ! KPP non-local tracer fluxes
+
+                               CALL tra_zdf( kstp )           ! vertical mixing
+
+                               CALL tra_nxt( kstp )           ! tracer fields at next time step
+
+                               CALL eos( tb, sb, rhd, rhop )       ! now (swap=before) in situ density for dynhpg module
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ta, sa arrays are used as workspace in this section 
+      !-----------------------------------------------------------------------
+
+                               ua(:,:,:) = 0.e0               ! set dynamics trends to zero
+                               va(:,:,:) = 0.e0
+  
+                               CALL dyn_cor_1d     ( kstp )
+      !                                                       ! vertical diffusion
+                               CALL dyn_zdf( kstp )      
+
+!i bug lbc sur emp
+      CALL lbc_lnk( emp, 'T', 1. )
+!i
+ 
+                                CALL dyn_nxt_1d( kstp )          ! lateral velocity at next time step 
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Computation of diagnostic variables
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                               CALL oc_fz_pt                    ! ocean surface freezing temperature
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control, diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      !                                            ! Time loop: control and print
+                       CALL stp_ctl( kstp, indic )
+                       IF ( indic < 0 ) CALL ctl_stop( 'step1d: indic < 0' )
+
+      IF ( nstop == 0 ) THEN
+         !                                         ! Diagnostics:
+         !                                         ! save and outputs
+                           CALL rst_write  ( kstp )              ! ocean model: restart file output
+                           CALL dia_wri_1d ( kstp, indic )       ! ocean model: outputs
+
+      ENDIF
+
+
+   END SUBROUTINE stp_1d
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO 1D Config
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE stp_1d ( kt )
+      WRITE(*,*) 'stp_1d: You should not have seen this print! error?', kt
+   END SUBROUTINE stp_1d
+#endif
+   !!======================================================================
+END MODULE step1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/dom_ice.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/dom_ice.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/dom_ice.F90	(revision 4536)
@@ -0,0 +1,35 @@
+MODULE dom_ice
+   !!======================================================================
+   !!                   ***  MODULE  dom_ice  ***
+   !! LIM Sea Ice :   Domain  variables
+   !!======================================================================
+   !! History :   2.0  !  03-08  (C. Ethe)  Free form and module
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_ice
+
+   IMPLICIT NONE
+   PRIVATE
+
+   LOGICAL, PUBLIC ::   l_jeq     = .TRUE.     !: Equator inside the domain flag
+   LOGICAL, PUBLIC ::   ln_limini = .FALSE.    !: Ice initialization state
+   LOGICAL, PUBLIC ::   ln_limdmp = .FALSE.    !: Ice damping
+
+   INTEGER, PUBLIC ::   njeq , njeqm1          !: j-index of the equator if it is inside the domain
+      !                                        !  (otherwise = jpj+10 (SH) or -10 (SH) )
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)         ::   fs2cor , fcor,   &  !: coriolis factor and coeficient
+      &                                              covrai ,         &  !: sine of geographic latitude
+      &                                              area   ,         &  !: surface of grid cell 
+      &                                              tms    , tmu        !: temperature and velocity points masks
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2)     ::   wght   ,         &  !: weight of the 4 neighbours to compute averages
+      &                                              akappa , bkappa     !: first and third group of metric coefficients
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2,2,2,2) ::   alambd   !: second group of metric coefficients
+
+   !!======================================================================
+END MODULE dom_ice
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/ice.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/ice.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/ice.F90	(revision 4536)
@@ -0,0 +1,130 @@
+MODULE ice
+   !!======================================================================
+   !!                        ***  MODULE ice  ***
+   !! Sea Ice physics:  diagnostics variables of ice defined in memory
+   !!=====================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   2.0  !  03-08  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_ice          ! LIM sea-ice parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share Module variables
+   INTEGER , PUBLIC ::   & !!: ** ice-dynamic namelist (namicedyn) **
+      nbiter = 1      ,  &  !: number of sub-time steps for relaxation
+      nbitdr = 250          !: maximum number of iterations for relaxation
+
+   REAL(wp), PUBLIC ::   & !!: ** ice-dynamic namelist (namicedyn) **
+      epsd   = 1.0e-20,  &  !: tolerance parameter for dynamic
+      alpha  = 0.5    ,  &  !: coefficient for semi-implicit coriolis
+      dm     = 0.6e+03,  &  !: diffusion constant for dynamics
+      om     = 0.5    ,  &  !: relaxation constant
+      resl   = 5.0e-05,  &  !: maximum value for the residual of relaxation
+      cw     = 5.0e-03,  &  !: drag coefficient for oceanic stress
+      angvg  = 0.e0   ,  &  !: turning angle for oceanic stress
+      pstar  = 1.0e+04,  &  !: first bulk-rheology parameter
+      c_rhg  = 20.e0  ,  &  !: second bulk-rhelogy parameter
+      etamn  = 0.e+07,   &  !: minimun value for viscosity
+      creepl = 2.e-08,   &  !: creep limit
+      ecc    = 2.e0   ,  &  !: eccentricity of the elliptical yield curve
+      ahi0   = 350.e0       !: sea-ice hor. eddy diffusivity coeff. (m2/s)
+
+   REAL(wp), PUBLIC ::   &  !:
+      usecc2          ,  &  !:  = 1.0 / ( ecc * ecc )
+      rhoco           ,  &  !: = rau0 * cw
+      sangvg, cangvg  ,  &  !: sin and cos of the turning angle for ocean stress
+      pstarh                !: pstar / 2.0
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &  !:
+      u_oce, v_oce,      &  !: surface ocean velocity used in ice dynamics
+      ahiu , ahiv ,      &  !: hor. diffusivity coeff. at ocean U- and V-points (m2/s)
+      pahu , pahv ,      &  !: ice hor. eddy diffusivity coef. at ocean U- and V-points
+      hsnm , hicm ,      &  !: mean snow and ice thicknesses
+      ust2s                 !: friction velocity
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &  !:
+        sst_ini,         &  !: sst read from a file for ice model initialization 
+        sss_ini             !: sss read from a file for ice model initialization 
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      firic  ,   &  !: IR flux over the ice (only used for outputs)
+      fcsic  ,   &  !: Sensible heat flux over the ice (only used for outputs)
+      fleic  ,   &  !: Latent heat flux over the ice (only used for outputs)
+      qlatic ,   &  !: latent flux
+      rdvosif,   &  !: Variation of volume at surface (only used for outputs)
+      rdvobif,   &  !: Variation of ice volume at the bottom ice (only used for outputs)
+      fdvolif,   &  !: Total variation of ice volume (only used for outputs)
+      rdvonif,   &  !: Lateral Variation of ice volume (only used for outputs)
+      sist   ,   &  !: Sea-Ice Surface Temperature (Kelvin ??? degree ??? I don't know)
+      tfu    ,   &  !: Melting point temperature of sea water
+      hsnif  ,   &  !: Snow thickness
+      hicif  ,   &  !: Ice thickness
+      hicifp ,   &  !: Ice production/melting
+      frld   ,   &  !: Leads fraction = 1-a/totalarea
+      phicif ,   &  !: ice thickness  at previous time 
+      pfrld  ,   &  !: Leads fraction at previous time  
+      qstoif ,   &  !: Energy stored in the brine pockets
+      fbif   ,   &  !: Heat flux at the ice base
+      rdmsnif,   &  !: Variation of snow mass
+      rdmicif,   &  !: Variation of ice mass
+      qldif  ,   &  !: heat balance of the lead (or of the open ocean)
+      qcmif  ,   &  !: Energy needed to bring the ocean surface layer until its freezing 
+      fdtcn  ,   &  !: net downward heat flux from the ice to the ocean
+      qdtcn  ,   &  !: energy from the ice to the ocean
+      !             !  point (at a factor 2)
+      thcm   ,   &  !: part of the solar energy used in the lead heat budget
+      fstric ,   &  !: Solar flux transmitted trough the ice
+      ffltbif,   &  !: Array linked with the max heat contained in brine pockets (?)
+      fscmbq ,   &  !: Linked with the solar flux below the ice (?)
+      fsbbq  ,   &  !: Also linked with the solar flux below the ice (?)
+      qfvbq  ,   &  !: Array used to store energy in case of toral lateral ablation (?)
+      dmgwi         !: Variation of the mass of snow ice
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      albege ,   &  !: Albedo of the snow or ice (only for outputs)
+      albecn ,   &  !: Albedo of the ocean (only for outputs)
+      tauc   ,   &  !: Cloud optical depth
+      sdvt          !: u*^2/(Stress/density)
+
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      u_ice, v_ice,   &  !: two components of the ice velocity (m/s)
+      tio_u, tio_v       !: two components of the ice-ocean stress (N/m2)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpsmax) ::   &  !:
+      scal0              !: ???
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jplayersp1) ::   &  !:
+      tbif          !: Temperature inside the ice/snow layer
+
+   REAL(wp), DIMENSION(jpi,jpj,0:jpkmax+1) ::    &  !:
+      reslum        !: Relative absorption of solar radiation in each ocean level
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+         sxice, syice, sxxice, syyice, sxyice,      &  !: moments for advection
+         sxsn,  sysn,  sxxsn,  syysn,  sxysn,       &  !:
+         sxa,   sya,   sxxa,   syya,   sxya,        &  !:
+         sxc0,  syc0,  sxxc0,  syyc0,  sxyc0,       &  !:
+         sxc1,  syc1,  sxxc1,  syyc1,  sxyc1,       &  !:
+         sxc2,  syc2,  sxxc2,  syyc2,  sxyc2,       &  !:
+         sxst,  syst,  sxxst,  syyst,  sxyst           !:
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module            NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE ice
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/iceini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/iceini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/iceini.F90	(revision 4536)
@@ -0,0 +1,132 @@
+MODULE iceini
+   !!======================================================================
+   !!                       ***  MODULE iceini   ***
+   !!   Sea-ice model : LIM Sea ice model Initialization
+   !!======================================================================
+   !! History :   1.0  !  02-08  (G. Madec)  F90: Free form and modules
+   !!             2.0  !  03-08  (C. Ethe)  add ice_run
+   !!----------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   ice_init       : sea-ice model initialization
+   !!   ice_run        : Definition some run parameter for ice model
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE dom_ice
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce
+   USE phycst          ! Define parameters for the routines
+   USE ocfzpt
+   USE ice
+   USE limmsh
+   USE limistate
+   USE limrst   
+   USE ini1d           ! initialization of the 1D configuration
+      
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_init                 ! called by opa.F90
+
+   LOGICAL , PUBLIC               ::   ln_limdyn = .TRUE.   !: flag for ice dynamics (T) or not (F)
+   REAL(wp), PUBLIC               ::   hsndif = 0.e0        !: computation of temp. in snow (0) or not (9999)
+   REAL(wp), PUBLIC               ::   hicdif = 0.e0        !: computation of temp. in ice (0) or not (9999)
+   REAL(wp), PUBLIC, DIMENSION(2) ::   acrit  = (/ 1.e-06 , 1.e-06 /)    !: minimum fraction for leads in 
+      !                                                                  !  north and south hemisphere
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ice_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_init  ***
+      !!
+      !! ** purpose :   
+      !!----------------------------------------------------------------------
+      CHARACTER(len=80) :: namelist_icename
+      !!----------------------------------------------------------------------
+      !
+      ! Open the namelist file 
+      namelist_icename = 'namelist_ice'
+      CALL ctlopn(numnam_ice,namelist_icename,'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+                     1,numout,.FALSE.,1)      
+      CALL ice_run                    !  read in namelist some run parameters
+                 
+      ! Louvain la Neuve Ice model
+      IF( nacc == 1 ) THEN
+          dtsd2   = nfice * rdtmin * 0.5
+          rdt_ice = nfice * rdtmin
+      ELSE
+          dtsd2   = nfice * rdt * 0.5
+          rdt_ice = nfice * rdt
+      ENDIF
+
+      CALL lim_msh                    ! ice mesh initialization
+     
+      ! Initial sea-ice state
+      IF( .NOT.ln_rstart ) THEN
+         CALL lim_istate              ! start from rest: sea-ice deduced from sst
+      ELSE
+         CALL lim_rst_read            ! start from a restart file
+      ENDIF
+      
+      tn_ice(:,:) = sist(:,:)         ! initialisation of ice temperature   
+      freeze(:,:) = 1.0 - frld(:,:)   ! initialisation of sea/ice cover    
+# if defined key_coupled
+      alb_ice(:,:) = albege(:,:)      ! sea-ice albedo
+# endif
+      !
+   END SUBROUTINE ice_init
+
+
+   SUBROUTINE ice_run
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_run ***
+      !!                 
+      !! ** Purpose :   Definition some run parameter for ice model
+      !!
+      !! ** Method  :   Read the namicerun namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicerun
+      !!-------------------------------------------------------------------
+      NAMELIST/namicerun/ ln_limdyn, ln_limdmp, acrit, hsndif, hicdif
+      !!-------------------------------------------------------------------
+      !                    
+      REWIND ( numnam_ice )                       ! Read Namelist namicerun 
+      READ   ( numnam_ice , namicerun )
+
+      IF( lk_cfg_1d  )   ln_limdyn = .FALSE.      ! No ice transport in 1D configuration
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_run : ice share parameters for dynamics/advection/thermo of sea-ice'
+         WRITE(numout,*) ' ~~~~~~'
+         WRITE(numout,*) '   switch for ice dynamics (1) or not (0)      ln_limdyn   = ', ln_limdyn
+         WRITE(numout,*) '   Ice damping                                 ln_limdmp   = ', ln_limdmp
+         WRITE(numout,*) '   minimum fraction for leads in the NH (SH)  acrit(1/2)   = ', acrit(:)
+         WRITE(numout,*) '   computation of temp. in snow (=0) or not (=9999) hsndif = ', hsndif
+         WRITE(numout,*) '   computation of temp. in ice  (=0) or not (=9999) hicdif = ', hicdif
+      ENDIF
+      !
+   END SUBROUTINE ice_run
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :        Empty module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_init        ! Empty routine
+   END SUBROUTINE ice_init
+#endif
+
+   !!======================================================================
+END MODULE iceini
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/icestp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/icestp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/icestp.F90	(revision 4536)
@@ -0,0 +1,286 @@
+MODULE icestp
+   !!======================================================================
+   !!                       ***  MODULE icestp   ***
+   !!   Sea-Ice model : LIM Sea ice model time-stepping
+   !!======================================================================
+   !! History :   1.0  !  99-11  (M. Imbard)  Original code
+   !!        !  01-03  (D. Ludicone, E. Durand, G. Madec) free surf.
+   !!   2.0  !  02-09  (G. Madec, C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   Lim sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   ice_stp       : sea-ice model time-stepping
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE oce  ! dynamics and tracers variables
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce         ! forcings variables
+   USE dom_ice
+   USE cpl_oce
+   USE daymod
+   USE phycst          ! Define parameters for the routines
+   USE taumod
+   USE ice
+   USE ocesbc
+   USE lbclnk
+   USE limdyn
+   USE limtrp
+   USE limthd
+   USE limflx
+   USE limdia
+   USE limwri
+   USE limrst
+   USE limdmp          ! Ice damping
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_stp    ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!-----------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!-----------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ice_stp ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_stp  ***
+      !!                   
+      !! ** Purpose :   Louvain la Neuve Sea Ice Model time stepping 
+      !!
+      !! ** Action  : - call the ice dynamics routine 
+      !!              - call the ice advection/diffusion routine 
+      !!              - call the ice thermodynamics routine 
+      !!              - call the routine that computes mass and 
+      !!                heat fluxes at the ice/ocean interface
+      !!              - save the outputs 
+      !!              - save the outputs for restart when necessary
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)          ::   kt       ! ocean time-step index
+
+      INTEGER                      ::   ji, jj   ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsss_io, zsss2_io, zsss3_io          ! tempory workspaces
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF( lk_cpl ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'ice_stp : Louvain la Neuve Ice Model (LIM)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~   coupled case'
+         ELSE
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'ice_stp : Louvain la Neuve Ice Model (LIM)' 
+            IF(lwp) WRITE(numout,*) '~~~~~~~   forced case using bulk formulea'
+         ENDIF
+         !  Initialize fluxes fields
+         gtaux(:,:) = 0.e0
+         gtauy(:,:) = 0.e0
+      ENDIF
+
+      ! Temperature , salinity and horizonta wind
+      ! sst_io  and sss_io, u_io and v_io  are initialized at nit000 in limistate.F90 (or limrst.F90) with :
+      !              sst_io = sst_io + (nfice - 1) * (tn(:,:,1)+rt0 )
+      !              sss_io = sss_io + (nfice - 1) * sn(:,:,1)
+      !              u_io  = u_io  + (nfice - 1) * 0.5 * ( un(ji-1,jj  ,1) + un(ji-1,jj-1,1) )
+      !              v_io  = v_io  + (nfice - 1) * 0.5 * ( vn(ji  ,jj-1,1) + vn(ji-1,jj-1,1) )
+      !    cumulate fields
+      !
+      sst_io(:,:) = sst_io(:,:) + tn(:,:,1) + rt0
+      sss_io(:,:) = sss_io(:,:) + sn(:,:,1)
+
+ 
+      ! vectors at F-point
+      DO jj = 2, jpj
+         DO ji = fs_2, jpi   ! vector opt.
+            u_io(ji,jj) = u_io(ji,jj) + 0.5 * ( un(ji-1,jj  ,1) + un(ji-1,jj-1,1) )
+            v_io(ji,jj) = v_io(ji,jj) + 0.5 * ( vn(ji  ,jj-1,1) + vn(ji-1,jj-1,1) )
+         END DO
+      END DO
+      
+      
+      IF( MOD( kt-1, nfice ) == 0 ) THEN
+         
+         ! The LIM model is going to be call
+         sst_io(:,:) = sst_io(:,:) / FLOAT( nfice ) * tmask(:,:,1)
+         sss_io(:,:) = sss_io(:,:) / FLOAT( nfice )
+
+         ! stress from ocean U- and V-points to ice U,V point
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               gtaux(ji,jj) = 0.5 * ( taux(ji-1,jj  ) + taux(ji-1,jj-1) )
+               gtauy(ji,jj) = 0.5 * ( tauy(ji  ,jj-1) + tauy(ji-1,jj-1) )
+               u_io  (ji,jj) = u_io(ji,jj) / FLOAT( nfice )
+               v_io  (ji,jj) = v_io(ji,jj) / FLOAT( nfice )
+            END DO
+         END DO
+
+         ! lateral boundary condition
+         CALL lbc_lnk( gtaux(:,:), 'I', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( gtauy(:,:), 'I', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( u_io (:,:), 'I', -1. )   ! I-point (i.e. ice U-V point)
+         CALL lbc_lnk( v_io (:,:), 'I', -1. )   ! I-point (i.e. ice U-V point)
+
+!!gmbug  in the ocean freezing point computed as :
+!!gm           fzptn (ji,jj) = ( -0.0575 + 1.710523e-3 * SQRT( sn(ji,jj,1) )   &
+!!gm                                     - 2.154996e-4 *       sn(ji,jj,1)   ) * sn(ji,jj,1)   !!   &
+!!gm           !!                        - 7.53e-4 * pressure
+!!gm
+!!gm!bug this is much more accurate and efficient computation
+!!gm       **************************************************
+!!gm freezing point from unesco:
+!!gm     real function tf(s,p)
+!!gm   function to compute the freezing point of seawater
+!!gm
+!!gm   reference: unesco tech. papers in the marine science no. 28. 1978
+!!gm   eighth report jpots
+!!gm   annex 6 freezing point of seawater f.j. millero pp.29-35.
+!!gm
+!!gm  units:
+!!gm         pressure      p          decibars
+!!gm         salinity      s          pss-78
+!!gm         temperature   tf         degrees celsius
+!!gm         freezing pt.
+!!gm************************************************************
+!!gm  checkvalue: tf= -2.588567 deg. c for s=40.0, p=500. decibars
+!!gm     tf=(-.0575+1.710523e-3*sqrt(abs(s))-2.154996e-4*s)*s-7.53e-4*p
+!!gm     return
+!!gm     end
+!!gm!bug
+
+
+!!gm      DO jj = 1, jpj
+!!gm         DO ji = 1, jpi
+!!gm            tfu(ji,jj)  = (  rt0 + ( - 0.0575                              &
+!!gm               &                     + 1.710523e-3 * SQRT( sss_io(ji,jj) )   &
+!!gm               &                     - 2.154996e-4 *       sss_io(ji,jj)   ) * sss_io(ji,jj)  ) * tms(ji,jj)
+!!gm         END DO
+!!gm      END DO
+!!gm
+      zsss_io (:,:) = SQRT( sss_io(:,:) ) 
+      zsss2_io(:,:) =  sss_io(:,:) *  sss_io(:,:)
+      zsss3_io(:,:) = zsss_io(:,:) * zsss_io(:,:) * zsss_io(:,:)
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            tfu(ji,jj)  = ABS ( rt0 - 0.0575       *   sss_io(ji,jj)   &
+               &                    + 1.710523e-03 * zsss3_io(ji,jj)   &
+               &                    - 2.154996e-04 * zsss2_io(ji,jj) ) * tms(ji,jj)
+         END DO
+      END DO
+   
+         
+
+         IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+            CALL prt_ctl_info('Ice Forcings ')
+            CALL prt_ctl(tab2d_1=qsr_oce ,clinfo1=' qsr_oce  : ', tab2d_2=qsr_ice , clinfo2=' qsr_ice   : ')
+            CALL prt_ctl(tab2d_1=qnsr_oce,clinfo1=' qnsr_oce : ', tab2d_2=qnsr_ice, clinfo2=' qnsr_ice  : ')
+            CALL prt_ctl(tab2d_1=evap    ,clinfo1=' evap     : ')
+            CALL prt_ctl(tab2d_1=tprecip ,clinfo1=' precip   : ', tab2d_2=sprecip , clinfo2=' Snow      : ')
+            CALL prt_ctl(tab2d_1=gtaux   ,clinfo1=' u-stress : ', tab2d_2=gtauy   , clinfo2=' v-stress  : ')
+            CALL prt_ctl(tab2d_1=sst_io  ,clinfo1=' sst      : ', tab2d_2=sss_io  , clinfo2=' sss       : ')
+            CALL prt_ctl(tab2d_1=u_io    ,clinfo1=' u_io     : ', tab2d_2=v_io    , clinfo2=' v_io      : ')
+            CALL prt_ctl(tab2d_1=hsnif   ,clinfo1=' hsnif  1 : ', tab2d_2=hicif   , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld    ,clinfo1=' frld   1 : ', tab2d_2=sist    , clinfo2=' sist      : ')
+         ENDIF
+
+         !                                                           !-----------------------!
+         CALL lim_rst_opn( kt )                                   ! Open Ice restart file !
+         !                                                           !-----------------------!
+
+         !                                                           !--------------!
+         CALL lim_dyn( kt )                                          ! Ice dynamics !   ( rheology/dynamics )
+         !                                                           !--------------!
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=hsnif ,clinfo1=' hsnif  2 : ', tab2d_2=hicif , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld  ,clinfo1=' frld   2 : ', tab2d_2=sist  , clinfo2=' sist      : ')
+         ENDIF
+
+
+         !                                                           !---------------!
+         CALL lim_trp( kt )                                          ! Ice transport !  ( Advection/diffusion )
+         !                                                           !---------------!
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=hsnif ,clinfo1=' hsnif  3 : ', tab2d_2=hicif , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld  ,clinfo1=' frld   3 : ', tab2d_2=sist  , clinfo2=' sist      : ')
+         ENDIF
+
+         !                                                           !-------------!
+         IF( ln_limdmp ) THEN                                        ! Ice damping !
+         !                                                           !-------------!
+#if defined key_agrif
+            IF( Agrif_Root() )   CALL lim_dmp(kt)
+#else
+            CALL lim_dmp(kt)                                         
+#endif
+         ENDIF
+         !                                                           !--------------------!
+         CALL lim_thd( kt )                                          ! Ice thermodynamics !
+         !                                                           !--------------------!
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=hsnif ,clinfo1=' hsnif  4 : ', tab2d_2=hicif , clinfo2=' hicif     : ')
+            CALL prt_ctl(tab2d_1=frld  ,clinfo1=' frld   4 : ', tab2d_2=sist  , clinfo2=' sist      : ')
+         ENDIF
+
+
+         ! Mass and heat fluxes from ice to ocean
+         !                                                           !------------------------------!
+         CALL lim_flx                                                ! Ice/Ocean Mass & Heat fluxes !
+         !                                                           !------------------------------!
+
+         IF( MOD( kt + nfice -1, ninfo ) == 0 .OR. ntmoy == 1 )  THEN        !-----------------!
+            CALL lim_dia( kt )                                    ! Ice Diagnostics !
+         ENDIF                                                       !-----------------!
+
+         !                                                           !-------------!
+         CALL lim_wri( kt )                                          ! Ice outputs !
+         !                                                           !-------------!
+
+         !                                                           !------------------------!
+         IF( lrst_ice ) CALL lim_rst_write( kt )                  ! Write Ice restart file !
+         !                                                           !------------------------!
+
+         ! Re-initialization of forcings
+         qsr_oce (:,:) = 0.e0
+         qsr_ice (:,:) = 0.e0
+         qnsr_oce(:,:) = 0.e0
+         qnsr_ice(:,:) = 0.e0 
+         dqns_ice(:,:) = 0.e0 
+         tprecip (:,:) = 0.e0 
+         sprecip (:,:) = 0.e0
+         fr1_i0  (:,:) = 0.e0
+         fr2_i0  (:,:) = 0.e0
+         evap    (:,:) = 0.e0
+#if defined key_coupled 
+         rrunoff (:,:) = 0.e0
+         calving (:,:) = 0.e0
+#else
+         qla_ice (:,:) = 0.e0
+         dqla_ice(:,:) = 0.e0
+#endif
+      ENDIF
+      !
+   END SUBROUTINE ice_stp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_stp ( kt )     ! Dummy routine
+      WRITE(*,*) 'ice_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE ice_stp
+#endif
+
+   !!======================================================================
+END MODULE icestp
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limadv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limadv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limadv.F90	(revision 4536)
@@ -0,0 +1,448 @@
+MODULE limadv 
+   !!======================================================================
+   !!                       ***  MODULE limadv   ***
+   !! LIM sea-ice model : sea-ice advection
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_adv_x  : advection of sea ice on x axis
+   !!   lim_adv_y  : advection of sea ice on y axis
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce
+   USE dom_ice
+   USE ice_oce         ! ice variables
+   USE in_out_manager  ! I/O manager
+   USE lbclnk
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_adv_x    ! called by lim_trp
+   PUBLIC lim_adv_y    ! called by lim_trp
+
+   !! * Module variables
+   REAL(wp)  ::            &  ! constant values
+      epsi20 = 1e-20    ,  &
+      rzero  = 0.e0     ,  &
+      rone   = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_x  **
+      !!  
+      !! ** purpose :   Computes and adds the advection trend to sea-ice
+      !!      variable on x axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects
+      !!      tracers but also theirquadratic forms. The method preserves
+      !!      tracer structures by conserving second order moments.
+      !!      Ref.: "Numerical Advection by Conservation of Second Order
+      !!      Moments", JGR, VOL. 91. NO. D6. PAGES 6671-6681. MAY 20, 1986
+      !!     
+      !! History :
+      !!        !  00-01 (LIM)
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!        !  03-10 (C. Ethe) F90, module
+      !!        !  03-12 (R. Hordoir, G. Madec) mpp
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp)                    , INTENT(in)  ::  &
+         pdf ,       &  ! ???
+         pcrh           ! = 1. : lim_adv_x is called before lim_adv_y
+         !              ! = 0. : lim_adv_x is called after  lim_adv_y
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)  ::  &
+         put            ! i-direction ice velocity at ocean U-point (m/s)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::  & 
+         ps0 , psm , &  ! ???
+         psx , psy , &  ! ??? 
+         psxx, psyy, psxy
+
+      !! * Local declarations
+      INTEGER ::   ji, jj      ! dummy loop indices
+      REAL(wp)       ::  &
+         zrdt, zslpmax, ztemp, zin0,     &  ! temporary scalars
+         zs1max, zs1new, zs2new,         &  !    "         "
+         zalf, zalfq, zalf1, zalf1q,     &  !    "         "
+         zbt , zbt1                         !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)  ::   &  ! temporary workspace
+         zf0 , zfx , zfy , zbet,         &  !    "           "
+         zfxx, zfyy, zfxy,               &  !    "           "
+         zfm, zalg, zalg1, zalg1q           !    "           "
+      !---------------------------------------------------------------------
+
+      ! Limitation of moments.                                           
+
+      zrdt      = rdt_ice * pdf   ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( rzero, ps0(ji,jj) )
+            zs1max  = 1.5 * zslpmax
+            zs1new  = MIN( zs1max, MAX( -zs1max, psx(ji,jj) ) )
+            zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
+               &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
+            zin0    = ( 1.0 - MAX( rzero, sign ( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = zs1new      * zin0
+            psxx(ji,jj) = zs2new      * zin0
+            psy (ji,jj) = psy (ji,jj) * zin0
+            psyy(ji,jj) = psyy(ji,jj) * zin0
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * zin0
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
+      psm (:,:)  = MAX( pcrh * area(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+      !  Calculate fluxes and moments between boxes i<-->i+1              
+      DO jj = 2, jpjm1                    !  Flux from i to i+1 WHEN u GT 0 
+!i bug   DO ji = 1, jpim1 
+!i    DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
+         DO ji = 1, jpi
+            zbet(ji,jj)  =  MAX( rzero, SIGN( rone, put(ji,jj) ) )
+            zalf         =  MAX( rzero, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            zfm (ji,jj)  =  zalf  * psm(ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj)  ) )
+            zfx (ji,jj)  =  zalfq * ( psx(ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
+            zfxx(ji,jj)  =  zalf  * zalfq * psxx(ji,jj)
+            zfy (ji,jj)  =  zalf  * ( psy(ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+            zfyy(ji,jj)  =  zalf  * psyy(ji,jj)
+
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
+            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
+            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
+            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                      !  Flux from i+1 to i when u LT 0.
+!i    DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
+         DO ji = 1, jpim1
+            zalf          = MAX( rzero, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  * psm(ji+1,jj)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0(ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
+            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx(ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  * zalfq * psxx(ji+1,jj)
+            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy(ji+1,jj) - zalf1 * psxy(ji+1,jj) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq * psxy(ji+1,jj)
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  * psyy(ji+1,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
+         DO ji = 2, jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
+            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
+            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
+            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
+            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
+         DO ji = 2, jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
+            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
+            ps0(ji,jj)  = zbt * (ps0(ji,jj) + zf0(ji-1,jj)) + zbt1 * ps0(ji,jj)
+            psx(ji,jj)  = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
+            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)   &
+               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
+               &        + zbt1 * psxx(ji,jj)
+            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
+               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
+               &         + zbt1 * psxy(ji,jj)
+            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
+            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
+         DO ji = 2, jpim1
+            zbt  =       zbet(ji,jj)
+            zbt1 = 1.0 - zbet(ji,jj)
+            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = -zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+            ps0(ji,jj)  = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+            psx(ji,jj)  = zbt  * psx(ji,jj)   &
+               &        + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
+            psxx(ji,jj) = zbt  * psxx(ji,jj)   &
+               &        + zbt1 * (  zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
+               &                 + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) ) + ( zalf1 - zalf ) * ztemp ) )
+            psxy(ji,jj) = zbt  * psxy(ji,jj)   &
+               &        + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
+               &                 + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
+            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk( psm , 'T', 1. )
+      CALL lbc_lnk( ps0 , 'T', 1. )
+      CALL lbc_lnk( psx , 'T', 1. )
+      CALL lbc_lnk( psxx, 'T', 1. )
+      CALL lbc_lnk( psy , 'T', 1. )
+      CALL lbc_lnk( psyy, 'T', 1. )
+      CALL lbc_lnk( psxy, 'T', 1. )
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_x: psxy :')
+      ENDIF
+
+   END SUBROUTINE lim_adv_x
+
+
+   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
+      &                  psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine lim_adv_y  **
+      !!            
+      !! ** purpose :   Computes and adds the advection trend to sea-ice 
+      !!      variable on y axis
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects tracers
+      !!      but also their quadratic forms. The method preserves tracer
+      !!      structures by conserving second order moments.
+      !!
+      !! History :
+      !!   1.0  !  00-01 (LIM)
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!   2.0  !  03-10 (C. Ethe) F90, module
+      !!        !  03-12 (R. Hordoir, G. Madec) mpp
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp),                     INTENT(in)  :: &
+         pdf,        &  ! ???
+         pcrh           ! = 1. : lim_adv_x is called before lim_adv_y
+         !              ! = 0. : lim_adv_x is called after  lim_adv_y
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)  :: &
+         pvt            ! j-direction ice velocity at ocean V-point (m/s)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: &
+         psm , ps0 , psx , psy,   &
+         psxx, psyy, psxy
+
+      !! * Local Variables
+      INTEGER  ::   ji, jj                ! dummy loop indices
+      REAL(wp) ::   &
+         zrdt, zslpmax, zin0, ztemp,  &   ! temporary scalars
+         zs1max, zs1new, zs2new,      &   !    "         "
+         zalf, zalfq, zalf1, zalf1q,  &   !    "         "
+         zbt , zbt1                       !
+      REAL(wp), DIMENSION(jpi,jpj)  :: &
+         zf0 , zfx , zfy ,             &  ! temporary workspace
+         zfxx, zfyy, zfxy,             &  !    "           "
+         zfm , zbet,                   &  !    "           "
+         zalg, zalg1, zalg1q              !    "           "
+      !---------------------------------------------------------------------
+
+      ! Limitation of moments.
+
+      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
+
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+             zslpmax = MAX( rzero, ps0(ji,jj) )
+             zs1max  = 1.5 * zslpmax
+             zs1new  = MIN( zs1max, MAX( -zs1max, psy(ji,jj) ) )
+             zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
+                &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
+             zin0    = ( 1.0 - MAX( rzero, sign ( rone, -zslpmax) ) ) * tms(ji,jj)   ! Case of empty boxes & Apply mask
+             ps0 (ji,jj) = zslpmax  
+             psx (ji,jj)  = psx (ji,jj) * zin0
+             psxx(ji,jj)  = psxx(ji,jj) * zin0
+             psy (ji,jj) = zs1new * zin0
+             psyy(ji,jj) = zs2new * zin0
+             psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * zin0
+          END DO
+       END DO
+
+       !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
+       psm (:,:)  = MAX( pcrh * area(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+       !  Calculate fluxes and moments between boxes j<-->j+1              
+!!bug  DO jj = 2, jpjm1
+       DO jj = 1, jpj
+          DO ji = 2, jpim1
+!!bug     DO ji = 1, jpim1
+             !  Flux from j to j+1 WHEN v GT 0   
+             zbet(ji,jj)  =  MAX( rzero, SIGN( rone, pvt(ji,jj) ) )
+             zalf         =  MAX( rzero, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
+             zalfq        =  zalf * zalf
+             zalf1        =  1.0 - zalf
+             zalf1q       =  zalf1 * zalf1
+             zfm (ji,jj)  =  zalf  * psm(ji,jj)
+             zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
+             zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
+             zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
+             zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
+             zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+             zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
+
+             !  Readjust moments remaining in the box.
+             psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+             ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+             psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
+             psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
+             psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
+             psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
+             psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+          END DO
+       END DO
+
+       DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+          DO ji = 2, jpim1
+!i     DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+!i        DO ji = 2, jpim1
+             zalf          = ( MAX(rzero, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
+             zalg  (ji,jj) = zalf
+             zalfq         = zalf * zalf
+             zalf1         = 1.0 - zalf
+             zalg1 (ji,jj) = zalf1
+             zalf1q        = zalf1 * zalf1
+             zalg1q(ji,jj) = zalf1q
+             zfm   (ji,jj) = zfm (ji,jj) + zalf  * psm(ji,jj+1)
+             zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0(ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
+             zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy(ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
+             zfyy  (ji,jj) = zfyy(ji,jj) + zalf  * zalfq * psyy(ji,jj+1)
+             zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx(ji,jj+1) - zalf1 * psxy(ji,jj+1) )
+             zfxy  (ji,jj) = zfxy(ji,jj) + zalfq * psxy(ji,jj+1)
+             zfxx  (ji,jj) = zfxx(ji,jj) + zalf  * psxx(ji,jj+1)
+          END DO
+       END DO
+ 
+       !  Readjust moments remaining in the box. 
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             zbt  =         zbet(ji,jj-1)
+             zbt1 = ( 1.0 - zbet(ji,jj-1) )
+             psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
+             ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
+             psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
+             psyy(ji,jj) = zalg1 (ji,jj-1)  * zalg1q(ji,jj-1) * psyy(ji,jj)
+             psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
+             psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
+             psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
+          END DO
+       END DO
+
+       !   Put the temporary moments into appropriate neighboring boxes.    
+       DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
+          DO ji = 2, jpim1
+             zbt  =         zbet(ji,jj-1)
+             zbt1 = ( 1.0 - zbet(ji,jj-1) )
+             psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
+             zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
+             zalf1       = 1.0 - zalf
+             ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
+             ps0(ji,jj)  = zbt * (ps0(ji,jj) + zf0(ji,jj-1)) + zbt1 * ps0(ji,jj)
+
+             psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
+                &        + zbt1 * psy(ji,jj)  
+
+             psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
+                &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
+                &        + zbt1 * psyy(ji,jj)
+
+             psxy(ji,jj) = zbt  * ( zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)              &
+                                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) ) )   &
+                         + zbt1 * psxy(ji,jj)
+             psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
+             psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
+          END DO
+       END DO
+
+       DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
+          DO ji = 2, jpim1
+             zbt  =         zbet(ji,jj)
+             zbt1 = ( 1.0 - zbet(ji,jj) )
+             psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+             zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+             zalf1       = 1.0 - zalf
+             ztemp       = -zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+             ps0(ji,jj)  = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+             psy(ji,jj)  = zbt  * psy(ji,jj)  &
+                &        + zbt1 * ( zalf*zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
+             psyy(ji,jj) = zbt  * psyy(ji,jj)  &
+                &        + zbt1 * ( zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
+                &                 + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) ) + ( zalf1 - zalf ) * ztemp ) )
+             psxy(ji,jj) = zbt  * psxy(ji,jj)   &
+                &        + zbt1 * ( zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)   &
+                &                 + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) ) )
+             psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
+             psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
+          END DO
+       END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk( psm , 'T', 1. )
+      CALL lbc_lnk( ps0 , 'T', 1. )
+      CALL lbc_lnk( psx , 'T', 1. )
+      CALL lbc_lnk( psxx, 'T', 1. )
+      CALL lbc_lnk( psy , 'T', 1. )
+      CALL lbc_lnk( psyy, 'T', 1. )
+      CALL lbc_lnk( psxy, 'T', 1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_y: psxy :')
+      ENDIF
+
+   END SUBROUTINE lim_adv_y
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy module         NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_adv_x         ! Empty routine
+   END SUBROUTINE lim_adv_x
+   SUBROUTINE lim_adv_y           ! Empty routine
+   END SUBROUTINE lim_adv_y
+
+#endif
+
+END MODULE limadv
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdia.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdia.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdia.F90	(revision 4536)
@@ -0,0 +1,288 @@
+MODULE limdia
+   !!======================================================================
+   !!                       ***  MODULE limdia   ***
+   !!                      diagnostics of ice model 
+   !!======================================================================
+   !! History :   8.0  !  97-06  (Louvain-La-Neuve)  Original code
+   !!             8.5  !  02-09  (C. Ethe , G. Madec )  F90: Free form and module
+   !!             9.0  !  06-08  (S. Masson)  change frequency output control
+   !!-------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lim_dia      : computation of the time evolution of keys var.
+   !!   lim_dia_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   USE phycst          ! 
+   USE par_ice         ! ice parameters
+   USE ice_oce         ! ice variables
+   USE daymod          !
+   USE dom_ice         !
+   USE ice             !
+   USE limistate       !
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC               lim_dia            ! called by ice_step
+   INTEGER, PUBLIC ::   ntmoy   = 1 ,   &  !: instantaneous values of ice evolution or averaging ntmoy
+      &                 ninfo   = 1        !: frequency of ouputs on file ice_evolu in case of averaging
+
+   INTEGER, PARAMETER ::   &  ! Parameters for outputs to files "evolu"
+      jpinfmx = 100         ,    &  ! maximum number of key variables
+      jpchinf = 5           ,    &  ! ???
+      jpchsep = jpchinf + 2         ! ???
+
+   INTEGER ::   &
+      nfrinf  = 4 ,     &  ! number of variables written in one line 
+      nferme ,          &  ! last time step at which the var. are written on file
+      nvinfo ,          &  ! number of total variables 
+      nbvt   ,          &  ! number of time variables
+      naveg                ! number of step for accumulation before averaging
+
+   CHARACTER(len= 8) ::   fmtinf  = '1PE13.5 ' ! format of the output values  
+   CHARACTER(len=30) ::   fmtw  ,           &  ! formats
+      &                   fmtr  ,           &  ! ???
+      &                   fmtitr               ! ???
+   CHARACTER(len=jpchsep), DIMENSION(jpinfmx) ::   titvar               ! title of key variables
+ 
+   REAL(wp)                     ::   epsi06 = 1.e-06      ! ???
+   REAL(wp), DIMENSION(jpinfmx) ::   vinfom               ! temporary working space
+   REAL(wp), DIMENSION(jpi,jpj) ::   aire                 ! masked grid cell area
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limdia.F90,v 1.9 2007/06/29 17:03:12 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_dia( kt )
+      !!--------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_dia  ***
+      !!   
+      !! ** Purpose : Computation and outputs on file ice.evolu 
+      !!      the temporal evolution of some key variables
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+      !!
+      INTEGER  ::   jv,ji, jj   ! dummy loop indices
+      INTEGER  ::   nv          ! indice of variable 
+      REAL(wp) ::   zarea    , zldarea  ,    &  ! sea-ice and leads area
+         &          zextent15, zextent85,    &  ! sea-ice extent (15% and 85%)
+         &          zicevol  , zsnwvol  ,    &  ! sea-ice and snow volume volume
+         &          zicespd                     ! sea-ice velocity
+      REAL(wp), DIMENSION(jpinfmx) ::   vinfor  ! temporary working space 
+      !!-------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL lim_dia_init   ! initialisation of ice_evolu file      
+
+      ! computation of key variables at each time step   
+
+      nv = 1 
+      vinfor(nv) = REAL( kt + nfice - 1 )
+      nv = nv + 1
+      vinfor(nv) = nyear
+ 
+      DO jv = nbvt + 1, nvinfo
+         vinfor(jv) = 0.e0
+      END DO
+
+      zextent15 = 0.e0
+      zextent85 = 0.e0
+      ! variables in northern Hemis
+      DO jj = njeq, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            IF( tms(ji,jj) == 1 ) THEN
+               zarea = ( 1.0 - frld(ji,jj) ) * aire(ji,jj)
+               IF (frld(ji,jj) <= 0.15 ) zextent15 = aire(ji,jj)    
+               IF (frld(ji,jj) <= 0.85 ) zextent85 = aire(ji,jj)   
+               zldarea = zarea   / MAX( ( 1 - frld(ji,jj) ) , epsi06 )
+               zicevol = zarea   * hicif(ji,jj)
+               zsnwvol = zarea   * hsnif(ji,jj)
+               zicespd = zicevol * ( u_ice(ji,jj) * u_ice(ji,jj)   &
+                  &                + v_ice(ji,jj) * v_ice(ji,jj) )
+               vinfor(nv+ 1) = vinfor(nv+ 1) + zarea
+               vinfor(nv+ 3) = vinfor(nv+ 3) + zextent15
+               vinfor(nv+ 5) = vinfor(nv+ 5) + zextent85
+               vinfor(nv+ 7) = vinfor(nv+ 7) + zldarea
+               vinfor(nv+ 9) = vinfor(nv+ 9) + zicevol
+               vinfor(nv+11) = vinfor(nv+11) + zsnwvol
+               vinfor(nv+13) = vinfor(nv+13) + zicespd
+            ENDIF
+         END DO
+      END DO
+      vinfor(nv+13) = SQRT( vinfor(nv+13) / MAX( vinfor(nv+9) , epsi06 ) )
+
+
+      ! variables in southern Hemis
+       nv = nv + 1
+       DO jj = 2, njeqm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             IF( tms(ji,jj) == 1 ) THEN
+                zarea = ( 1.0 - frld(ji,jj) ) * aire(ji,jj)
+                IF (frld(ji,jj) <= 0.15 ) zextent15 = aire(ji,jj)    
+                IF (frld(ji,jj) <= 0.85 ) zextent85 = aire(ji,jj)   
+                zldarea = zarea   / MAX( ( 1 - frld(ji,jj) ) , epsi06 )
+                zicevol = zarea   * hicif(ji,jj)
+                zsnwvol = zarea   * hsnif(ji,jj)
+                zicespd = zicevol * ( u_ice(ji,jj) * u_ice(ji,jj)   &
+                   &                + v_ice(ji,jj) * v_ice(ji,jj) )
+                vinfor(nv+ 1) = vinfor(nv+ 1) + zarea
+                vinfor(nv+ 3) = vinfor(nv+ 3) + zextent15
+                vinfor(nv+ 5) = vinfor(nv+ 5) + zextent85
+                vinfor(nv+ 7) = vinfor(nv+ 7) + zldarea
+                vinfor(nv+ 9) = vinfor(nv+ 9) + zicevol
+                vinfor(nv+11) = vinfor(nv+11) + zsnwvol
+                vinfor(nv+13) = vinfor(nv+13) + zicespd
+             ENDIF
+          END DO
+       END DO
+       vinfor(nv+13) = SQRT( vinfor(nv+13) / MAX( vinfor(nv+9) , epsi06 ) )    
+
+       !  Accumulation before averaging 
+       DO jv = 1, nvinfo
+          vinfom(jv) = vinfom(jv) + vinfor(jv)
+       END DO
+       naveg = naveg + 1  
+    
+       ! oututs on file ice_evolu    
+       IF( MOD( kt + nfice - 1, ninfo ) == 0 ) THEN
+          WRITE(numevo_ice,fmtw) ( titvar(jv), vinfom(jv)/naveg, jv = 1, nvinfo )
+          naveg = 0
+          DO jv = 1, nvinfo
+             vinfom(jv) = 0.e0
+          END DO
+       ENDIF
+       !
+    END SUBROUTINE lim_dia
+ 
+
+    SUBROUTINE lim_dia_init
+       !!-------------------------------------------------------------------
+       !!                  ***  ROUTINE lim_dia_init  ***
+       !!             
+       !! ** Purpose : Preparation of the file ice_evolu for the output of
+       !!      the temporal evolution of key variables
+       !!
+       !! ** input   : Namelist namicedia
+       !!-------------------------------------------------------------------
+       CHARACTER(len=jpchinf) ::   titinf
+       CHARACTER(len=50)      ::   clname 
+       INTEGER  ::   jv            ! dummy loop indice
+       INTEGER  ::   ntot , ndeb , irecl
+       INTEGER  ::   nv            ! indice of variable 
+       REAL(wp) ::   zxx0, zxx1    ! temporary scalars
+
+       NAMELIST/namicedia/fmtinf, nfrinf, ninfo, ntmoy
+       !!-------------------------------------------------------------------
+
+       ! Read Namelist namicedia
+       REWIND ( numnam_ice )
+       READ   ( numnam_ice  , namicedia )
+       
+       IF(lwp) THEN
+          WRITE(numout,*)
+          WRITE(numout,*) 'lim_dia_init : ice parameters for ice diagnostics '
+          WRITE(numout,*) '~~~~~~~~~~~~'
+          WRITE(numout,*) '   format of the output values                                 fmtinf = ', fmtinf
+          WRITE(numout,*) '   number of variables written in one line                     nfrinf = ', nfrinf 
+          WRITE(numout,*) '   Instantaneous values of ice evolution or averaging          ntmoy  = ', ntmoy
+          WRITE(numout,*) '   frequency of ouputs on file ice_evolu in case of averaging  ninfo  = ', ninfo
+       ENDIF
+
+       ! masked grid cell area
+       aire(:,:) = area(:,:) * tms(:,:)
+
+       ! Titles of ice key variables :
+       nv = 1
+       titvar(nv) = 'NoIt'  ! iteration number
+       nv = nv + 1
+       titvar(nv) = 'T yr'  ! time step in years
+       
+       nbvt = nv - 1
+
+       nv = nv + 1   ;   titvar(nv) = 'AEFN' ! sea ice area in the northern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'AEFS' ! sea ice area in the southern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'A15N'  ! sea ice extent (15%) in the northern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'A15S'  ! sea ice extent (15%) in the southern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'A85N'  ! sea ice extent (85%) in the northern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'A85S'  ! sea ice extent (85%) in the southern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'ALEN'  ! leads area in the northern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'ALES'  ! leads area in the southern Hemisp.(10^12 km2)
+       nv = nv + 1   ;   titvar(nv) = 'VOLN'  ! sea ice volume in the northern Hemisp.(10^3 km3)
+       nv = nv + 1   ;   titvar(nv) = 'VOLS'  ! sea ice volume in the southern Hemisp.(10^3 km3)
+       nv = nv + 1   ;   titvar(nv) = 'VONN'  ! snow volume over sea ice in the northern Hemisp.(10^3 km3)
+       nv = nv + 1   ;   titvar(nv) = 'VONS'  ! snow volume over sea ice in the southern Hemisp.(10^3 km3)
+       nv = nv + 1   ;   titvar(nv) = 'ECGN'  ! mean sea ice velocity in the northern Hemisp.(m/s)
+       nv = nv + 1   ;   titvar(nv) = 'ECGS'  ! mean sea ice velocity in the southern Hemisp.(m/s)
+
+       nvinfo = nv
+
+       ! Definition et Ecriture de l'entete : nombre d'enregistrements 
+       ndeb   = ( nit000 - 1 + nfice - 1 ) / ninfo
+       IF( nit000 - 1 + nfice == 1 ) ndeb = -1
+
+       nferme = ( nitend + nfice - 1 ) / ninfo ! nit000 - 1 + nfice - 1 + nitend - nit000 + 1
+       ntot   = nferme - ndeb
+       ndeb   = ninfo * ( 1 + ndeb )
+       nferme = ninfo * nferme
+
+       ! definition of formats 
+       WRITE( fmtw  , '(A,I3,A2,I1,A)' )  '(', nfrinf, '(A', jpchsep, ','//fmtinf//'))'
+       WRITE( fmtr  , '(A,I3,A,I1,A)'  )  '(', nfrinf, '(', jpchsep, 'X,'//fmtinf//'))'
+       WRITE( fmtitr, '(A,I3,A,I1,A)'  )  '(', nvinfo, 'A', jpchinf, ')'
+
+       ! opening  "ice_evolu" file
+       clname = 'ice_evolu' 
+       irecl = ( jpchinf + 1 ) * nvinfo 
+       CALL ctlopn( numevo_ice, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+          &           irecl, numout, lwp, 1 )
+
+       !- ecriture de 2 lignes d''entete :
+       WRITE(numevo_ice,1000) fmtr, fmtw, fmtitr, nvinfo, ntot, 0, nfrinf
+       zxx0 = 0.001 * REAL( ninfo )
+       zxx1 = 0.001 * REAL( ndeb  )
+       WRITE(numevo_ice,1111) REAL(jpchinf), 0., zxx1, zxx0, 0., 0., 0
+
+       !- ecriture de 2 lignes de titre :
+       WRITE(numevo_ice,'(A,I8,A,I8,A,I5)')                 &
+          'Evolution chronologique - Experience '//cexper   &
+          //'   de', ndeb, ' a', nferme, ' pas', ninfo
+       WRITE(numevo_ice,fmtitr) ( titvar(jv), jv = 1, nvinfo )
+
+
+       !--preparation de "titvar" pour l''ecriture parmi les valeurs numeriques :
+       DO  jv = 2 , nvinfo
+          titinf     = titvar(jv)(:jpchinf)
+          titvar(jv) = '  '//titinf
+       END DO
+
+       !--Initialisation of the arrays for the accumulation
+       DO  jv = 1, nvinfo
+          vinfom(jv) = 0.
+       END DO
+       naveg = 0
+
+1000   FORMAT( 3(A20),4(1x,I6) )
+1111   FORMAT( 3(F7.1,1X,F7.3,1X),I3,A )  
+      !
+    END SUBROUTINE lim_dia_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                               NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_dia         ! Empty routine
+   END SUBROUTINE lim_dia
+#endif
+
+   !!======================================================================
+END MODULE limdia
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdmp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdmp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdmp.F90	(revision 4536)
@@ -0,0 +1,182 @@
+MODULE limdmp
+   !!======================================================================
+   !!                       ***  MODULE limdmp   ***
+   !!  Ice model : restoring Ice thickness and Fraction leads
+   !!======================================================================
+   !! History :   2.0  !  04-04 (S. Theetten) Original code
+   !!----------------------------------------------------------------------
+#if defined key_ice_lim   &&   defined key_tradmp
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'  AND                                LIM sea-ice model
+   !!   'key_tradmp'                                                Damping
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lim_dmp      : ice model damping
+   !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE ice
+   USE ice_oce
+   USE tradmp
+   USE dom_oce
+   USE oce
+   USE daymod          ! calendar
+   USE iom
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_dmp     ! called by ice_step
+   
+   INTEGER                        ::   nice1, nice2,  &  ! first and second record used
+      &                                inumice_dmp       ! logical unit for ice variables (damping)
+   REAL(wp), DIMENSION(jpi,jpj)   ::   hicif_dta  ,   &  ! ice thickness at a given time
+      &                                frld_dta          ! fraction lead at a given time
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   hicif_data ,   &  ! ice thickness data at two consecutive times
+      &                                frld_data         ! fraction lead data at two consecutive times
+
+   !! * Substitution
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0 , UCL-LOCEAN-IPSL  (2006)
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_dmp(kt)
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_dmp ***
+      !!
+      !! ** purpose : ice model damping : restoring ice thickness and 
+      !!              fraction leads
+      !!
+      !! ** method  : the key_tradmp must be used to compute resto(:,:) coef.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !
+      INTEGER             ::   ji, jj         ! dummy loop indices
+      !!---------------------------------------------------------------------
+      !
+      CALL dta_lim( kt )
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            hicif(ji,jj) = hicif(ji,jj) - rdt_ice * resto(ji,jj,1) * ( hicif(ji,jj) - hicif_dta(ji,jj) )
+            frld(ji,jj)  = frld (ji,jj) - rdt_ice * resto(ji,jj,1) * ( frld(ji,jj)  - frld_dta (ji,jj) )  
+         END DO
+      END DO
+      !
+   END SUBROUTINE lim_dmp
+
+
+   SUBROUTINE dta_lim( kt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dta_lim  ***
+      !!
+      !! ** Purpose :   Reads monthly ice thickness and fraction lead  data
+      !!
+      !! ** Method  :   Read on unit numicedt the interpolated ice variable
+      !!      onto the model grid.
+      !!      Data begin at january.
+      !!      The value is centered at the middle of month.
+      !!      In the opa model, kt=1 agree with january 1.
+      !!      At each time step, a linear interpolation is applied between
+      !!      two monthly values.
+      !!      
+      !! ** Action  :   define hicif_dta and frld_dta arrays at time-step kt
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !
+      INTEGER  ::   imois, iman, i15          ! temporary integers
+      REAL(wp) ::   zxy
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialization
+      ! -----------------
+      iman  = INT( raamo )
+!!! better but change the results     i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+      i15   = nday / 16
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+      
+      ! 1. First call kt=nit000: Initialization and Open
+      ! -----------------------
+      IF( kt == nit000 ) THEN
+         nice1 = 0
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dtalim : Ice thickness and lead fraction  monthly fields'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '             NetCDF FORMAT'
+         IF(lwp) WRITE(numout,*)
+         ! open file
+         CALL iom_open( 'ice_damping_ATL4.nc', inumice_dmp )
+      ENDIF
+
+
+      ! 2. Read monthly file
+      ! --------------------
+      IF( ( kt == nit000 ) .OR. imois /= nice1 ) THEN
+         !
+         ! Calendar computation
+         nice1 = imois        ! first file record used 
+         nice2 = nice1 + 1    ! last  file record used
+         nice1 = MOD( nice1, iman )
+         nice2 = MOD( nice2, iman )
+         IF( nice1 == 0 )   nice1 = iman
+         IF( nice2 == 0 )   nice2 = iman
+         IF(lwp) WRITE(numout,*) 'first record file used nice1 ', nice1
+         IF(lwp) WRITE(numout,*) 'last  record file used nice2 ', nice2
+         
+         ! Read monthly ice thickness Levitus 
+         CALL iom_get( inumice_dmp, jpdom_data, 'iicethic', hicif_data(:,:,1), nice1 ) 
+         CALL iom_get( inumice_dmp, jpdom_data, 'iicethic', hicif_data(:,:,2), nice2 ) 
+         
+         ! Read monthly ice thickness Levitus 
+         CALL iom_get( inumice_dmp, jpdom_data, 'ileadfra', frld_data(:,:,1), nice1 ) 
+         CALL iom_get( inumice_dmp, jpdom_data, 'ileadfra', frld_data(:,:,2), nice2 ) 
+         
+         ! The fraction lead read in the file is in fact the 
+         ! ice concentration which is 1 - the fraction lead
+         frld_data = 1 - frld_data          
+         
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' Ice thickness month ', nice1,' and ', nice2
+            WRITE(numout,*)
+            WRITE(numout,*) ' Ice thickness month = ', nice1
+            CALL prihre( hicif_data(1,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            WRITE(numout,*)
+            WRITE(numout,*) ' Fraction lead months ', nice1,' and ', nice2
+            WRITE(numout,*)
+            WRITE(numout,*) ' Fraction lead month = ', nice1
+            CALL prihre( frld_data(1,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+         ENDIF
+
+         CALL FLUSH(numout)
+
+      ENDIF
+        
+      ! 3. At every time step compute ice thickness and fraction lead data
+      ! ------------------------------------------------------------------
+      zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
+      hicif_dta(:,:) = (1.-zxy) * hicif_data(:,:,1) + zxy * hicif_data(:,:,2)
+      frld_dta (:,:) = (1.-zxy) * frld_data (:,:,1) + zxy * frld_data (:,:,2)
+
+      IF( kt == nitend )   CALL iom_close( inumice_dmp )
+      !
+   END SUBROUTINE dta_lim
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module                  No ice damping
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_dmp( kt )        ! Dummy routine
+      WRITE(*,*) 'lim_dmp: You should not see this print! error? ', kt
+   END SUBROUTINE lim_dmp
+#endif
+
+   !!======================================================================
+END MODULE limdmp
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdyn.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdyn.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limdyn.F90	(revision 4536)
@@ -0,0 +1,327 @@
+MODULE limdyn
+   !!======================================================================
+   !!                     ***  MODULE  limdyn  ***
+   !!   Sea-Ice dynamics :  
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!    lim_dyn      : computes ice velocities
+   !!    lim_dyn_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE in_out_manager  ! I/O manager
+   USE dom_ice
+   USE dom_oce         ! ocean space and time domain
+   USE ice
+   USE ice_oce
+   USE iceini
+   USE limistate
+   USE limrhg          ! ice rheology
+   USE lbclnk
+   USE lib_mpp
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_dyn  ! routine called by ice_step
+
+   !! * Module variables
+   REAL(wp)  ::  rone    = 1.e0   ! constant value
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_dyn( kt )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE lim_dyn  ***
+      !!               
+      !! ** Purpose :   compute ice velocity and ocean-ice stress
+      !!                
+      !! ** Method  : 
+      !!
+      !! ** Action  : - Initialisation
+      !!              - Call of the dynamic routine for each hemisphere
+      !!              - computation of the stress at the ocean surface         
+      !!              - treatment of the case if no ice dynamic
+      !! History :
+      !!   1.0  !  01-04  (LIM)  Original code
+      !!   2.0  !  02-08  (C. Ethe, G. Madec)  F90, mpp
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+      INTEGER ::   ji, jj             ! dummy loop indices
+      INTEGER ::   i_j1, i_jpj        ! Starting/ending j-indices for rheology
+      REAL(wp) ::   &
+         ztairx, ztairy,           &  ! tempory scalars
+         zsang , zmod,             &
+         ztglx , ztgly ,           &
+         zt11, zt12, zt21, zt22 ,  &
+         zustm, zsfrld, zsfrldm4,  &
+         zu_ice, zv_ice, ztair2
+      REAL(wp),DIMENSION(jpj) ::   &
+         zind,                     &  ! i-averaged indicator of sea-ice
+         zmsk                         ! i-averaged of tmask
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL lim_dyn_init   ! Initialization (first time-step only)
+      
+      IF ( ln_limdyn ) THEN
+
+         ! Mean ice and snow thicknesses.          
+         hsnm(:,:)  = ( 1.0 - frld(:,:) ) * hsnif(:,:)
+         hicm(:,:)  = ( 1.0 - frld(:,:) ) * hicif(:,:)
+
+         u_oce(:,:)  = u_io(:,:) * tmu(:,:)
+         v_oce(:,:)  = v_io(:,:) * tmu(:,:)
+       
+         !                                         ! Rheology (ice dynamics)
+         !                                         ! ========
+         
+         !  Define the j-limits where ice rheology is computed
+         ! ---------------------------------------------------
+         
+         IF( lk_mpp .OR. nbit_cmp == 1 ) THEN                    ! mpp: compute over the whole domain
+            i_j1 = 1   
+            i_jpj = jpj
+            IF(ln_ctl)    THEN
+               CALL prt_ctl_info('lim_dyn  :    i_j1 = ', ivar1=i_j1, clinfo2=' ij_jpj = ', ivar2=i_jpj)
+            ENDIF
+            CALL lim_rhg( i_j1, i_jpj )
+
+         ELSE                                 ! optimization of the computational area
+
+            DO jj = 1, jpj
+               zind(jj) = SUM( frld (:,jj  ) )   ! = FLOAT(jpj) if ocean everywhere on a j-line
+               zmsk(jj) = SUM( tmask(:,jj,1) )   ! = 0          if land  everywhere on a j-line
+   !!i         write(numout,*) narea, 'limdyn' , jj, zind(jj), zmsk(jj)
+            END DO
+
+            IF( l_jeq ) THEN                     ! local domain include both hemisphere
+               !                                 ! Rheology is computed in each hemisphere
+               !                                 ! only over the ice cover latitude strip
+               ! Northern hemisphere
+               i_j1  = njeq
+               i_jpj = jpj
+               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
+                  i_j1 = i_j1 + 1
+               END DO
+               i_j1 = MAX( 1, i_j1-1 )
+               IF(ln_ctl)   WRITE(numout,*) 'lim_dyn : NH i_j1 = ', i_j1, ' ij_jpj = ', i_jpj
+    
+               CALL lim_rhg( i_j1, i_jpj )
+    
+               ! Southern hemisphere
+               i_j1  =  1 
+               i_jpj = njeq
+               DO WHILE ( i_jpj >= 1 .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
+                  i_jpj = i_jpj - 1
+               END DO
+               i_jpj = MIN( jpj, i_jpj+2 )
+               IF(ln_ctl)   WRITE(numout,*) 'lim_dyn : SH i_j1 = ', i_j1, ' ij_jpj = ', i_jpj
+    
+               CALL lim_rhg( i_j1, i_jpj )
+    
+            ELSE                                 ! local domain extends over one hemisphere only
+               !                                 ! Rheology is computed only over the ice cover
+               !                                 ! latitude strip
+               i_j1  = 1
+               DO WHILE ( i_j1 <= jpj .AND. zind(i_j1) == FLOAT(jpi) .AND. zmsk(i_j1) /=0 )
+                  i_j1 = i_j1 + 1
+               END DO
+               i_j1 = MAX( 1, i_j1-1 )
+    
+               i_jpj  = jpj
+               DO WHILE ( i_jpj >= 1  .AND. zind(i_jpj) == FLOAT(jpi) .AND. zmsk(i_jpj) /=0 )
+                  i_jpj = i_jpj - 1
+               END DO
+               i_jpj = MIN( jpj, i_jpj+2)
+    
+               IF(ln_ctl)   WRITE(numout,*) 'lim_dyn : one hemisphere: i_j1 = ', i_j1, ' ij_jpj = ', i_jpj
+    
+               CALL lim_rhg( i_j1, i_jpj )
+
+            ENDIF
+
+         ENDIF
+
+         IF(ln_ctl)   THEN 
+            CALL prt_ctl(tab2d_1=u_oce , clinfo1=' lim_dyn  : u_oce :', tab2d_2=v_oce , clinfo2=' v_oce :')
+            CALL prt_ctl(tab2d_1=u_ice , clinfo1=' lim_dyn  : u_ice :', tab2d_2=v_ice , clinfo2=' v_ice :')
+         ENDIF
+         
+         !                                         ! Ice-Ocean stress
+         !                                         ! ================
+         DO jj = 2, jpjm1
+            zsang  = SIGN(1.e0, gphif(1,jj-1) ) * sangvg
+            DO ji = 2, jpim1
+               ! computation of wind stress over ocean in X and Y direction
+#if defined key_coupled && defined key_lim_cp1
+               ztairx =  frld(ji-1,jj  ) * gtaux(ji-1,jj  ) + frld(ji,jj  ) * gtaux(ji,jj  )      &
+                  &    + frld(ji-1,jj-1) * gtaux(ji-1,jj-1) + frld(ji,jj-1) * gtaux(ji,jj-1)
+
+               ztairy =  frld(ji-1,jj  ) * gtauy(ji-1,jj  ) + frld(ji,jj  ) * gtauy(ji,jj  )      &
+                  &    + frld(ji-1,jj-1) * gtauy(ji-1,jj-1) + frld(ji,jj-1) * gtauy(ji,jj-1)
+#else
+               zsfrld  = frld(ji,jj) + frld(ji-1,jj) + frld(ji-1,jj-1) + frld(ji,jj-1)
+               ztairx  = zsfrld * gtaux(ji,jj)
+               ztairy  = zsfrld * gtauy(ji,jj)
+#endif
+               zsfrldm4 = 4 - frld(ji,jj) - frld(ji-1,jj) - frld(ji-1,jj-1) - frld(ji,jj-1)
+               zu_ice   = u_ice(ji,jj) - u_oce(ji,jj)
+               zv_ice   = v_ice(ji,jj) - v_oce(ji,jj)
+               zmod     = SQRT( zu_ice * zu_ice + zv_ice * zv_ice ) 
+               ztglx   = zsfrldm4 * rhoco * zmod * ( cangvg * zu_ice - zsang * zv_ice ) 
+               ztgly   = zsfrldm4 * rhoco * zmod * ( cangvg * zv_ice + zsang * zu_ice ) 
+
+               tio_u(ji,jj) = - ( ztairx + 1.0 * ztglx ) / ( 4 * rau0 )
+               tio_v(ji,jj) = - ( ztairy + 1.0 * ztgly ) / ( 4 * rau0 )
+            END DO
+         END DO
+         
+         ! computation of friction velocity
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+
+               zu_ice   = u_ice(ji-1,jj-1) - u_oce(ji-1,jj-1)
+               zv_ice   = v_ice(ji-1,jj-1) - v_oce(ji-1,jj-1)
+               zt11  = rhoco * ( zu_ice * zu_ice + zv_ice * zv_ice )
+
+               zu_ice   = u_ice(ji-1,jj) - u_oce(ji-1,jj)
+               zv_ice   = v_ice(ji-1,jj) - v_oce(ji-1,jj)
+               zt12  = rhoco * ( zu_ice * zu_ice + zv_ice * zv_ice ) 
+
+               zu_ice   = u_ice(ji,jj-1) - u_oce(ji,jj-1)
+               zv_ice   = v_ice(ji,jj-1) - v_oce(ji,jj-1)
+               zt21  = rhoco * ( zu_ice * zu_ice + zv_ice * zv_ice ) 
+
+               zu_ice   = u_ice(ji,jj) - u_oce(ji,jj)
+               zv_ice   = v_ice(ji,jj) - v_oce(ji,jj)
+               zt22  = rhoco * ( zu_ice * zu_ice + zv_ice * zv_ice ) 
+
+               ztair2 = gtaux(ji,jj) * gtaux(ji,jj) + gtauy(ji,jj) * gtauy(ji,jj)
+
+               zustm =  ( 1 - frld(ji,jj) ) * 0.25 * ( zt11 + zt12 + zt21 + zt22 )        &
+                  &  +        frld(ji,jj)   * SQRT( ztair2 )
+
+               ust2s(ji,jj) = ( zustm / rau0 ) * ( rone + sdvt(ji,jj) ) * tms(ji,jj)
+            END DO
+         END DO
+
+       ELSE      ! no ice dynamics : transmit directly the atmospheric stress to the ocean
+                    
+          DO jj = 2, jpjm1
+             DO ji = 2, jpim1
+#if defined key_coupled && defined key_lim_cp1
+                tio_u(ji,jj) = - (  gtaux(ji  ,jj  ) + gtaux(ji-1,jj  )       &
+                   &              + gtaux(ji-1,jj-1) + gtaux(ji  ,jj-1) ) / ( 4 * rau0 )
+
+                tio_v(ji,jj) = - (  gtauy(ji  ,jj )  + gtauy(ji-1,jj  )       &
+                   &              + gtauy(ji-1,jj-1) + gtauy(ji  ,jj-1) ) / ( 4 * rau0 )
+#else
+                tio_u(ji,jj) = - gtaux(ji,jj) / rau0
+                tio_v(ji,jj) = - gtauy(ji,jj) / rau0 
+#endif
+                ztair2       = gtaux(ji,jj) * gtaux(ji,jj) + gtauy(ji,jj) * gtauy(ji,jj)
+                zustm        = SQRT( ztair2  )
+
+                ust2s(ji,jj) = ( zustm / rau0 ) * ( rone + sdvt(ji,jj) ) * tms(ji,jj)
+            END DO
+         END DO
+
+      ENDIF
+
+      CALL lbc_lnk( ust2s, 'T',  1. )   ! T-point
+      CALL lbc_lnk( tio_u, 'I', -1. )   ! I-point (i.e. ice U-V point)
+      CALL lbc_lnk( tio_v, 'I', -1. )   ! I-point (i.e. ice U-V point)
+
+      IF(ln_ctl) THEN 
+            CALL prt_ctl(tab2d_1=tio_u , clinfo1=' lim_dyn  : tio_u :', tab2d_2=tio_v , clinfo2=' tio_v :')
+            CALL prt_ctl(tab2d_1=ust2s , clinfo1=' lim_dyn  : ust2s :')
+      ENDIF
+
+   END SUBROUTINE lim_dyn
+
+
+   SUBROUTINE lim_dyn_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_dyn_init  ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to the ice
+      !!      dynamics
+      !!
+      !! ** Method  :  Read the namicedyn namelist and check the ice-dynamic
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicedyn
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicedyn/ epsd, alpha,     &
+         &                dm, nbiter, nbitdr, om, resl, cw, angvg, pstar,   &
+         &                c_rhg, etamn, creepl, ecc, ahi0
+      !!-------------------------------------------------------------------
+
+      ! Define the initial parameters
+      ! -------------------------
+
+      ! Read Namelist namicedyn
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namicedyn )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_dyn_init : ice parameters for ice dynamics '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '       tolerance parameter                              epsd   = ', epsd
+         WRITE(numout,*) '       coefficient for semi-implicit coriolis           alpha  = ', alpha
+         WRITE(numout,*) '       diffusion constant for dynamics                  dm     = ', dm
+         WRITE(numout,*) '       number of sub-time steps for relaxation          nbiter = ', nbiter
+         WRITE(numout,*) '       maximum number of iterations for relaxation      nbitdr = ', nbitdr
+         WRITE(numout,*) '       relaxation constant                              om     = ', om
+         WRITE(numout,*) '       maximum value for the residual of relaxation     resl   = ', resl
+         WRITE(numout,*) '       drag coefficient for oceanic stress              cw     = ', cw
+         WRITE(numout,*) '       turning angle for oceanic stress                 angvg  = ', angvg
+         WRITE(numout,*) '       first bulk-rheology parameter                    pstar  = ', pstar
+         WRITE(numout,*) '       second bulk-rhelogy parameter                    c_rhg  = ', c_rhg
+         WRITE(numout,*) '       minimun value for viscosity                      etamn  = ', etamn
+         WRITE(numout,*) '       creep limit                                      creepl = ', creepl
+         WRITE(numout,*) '       eccentricity of the elliptical yield curve       ecc    = ', ecc
+         WRITE(numout,*) '       horizontal diffusivity coeff. for sea-ice        ahi0   = ', ahi0
+      ENDIF
+
+      !  Initialization
+      usecc2 = 1.0 / ( ecc * ecc )
+      rhoco  = rau0 * cw
+      angvg  = angvg * rad
+      sangvg = SIN( angvg )
+      cangvg = COS( angvg )
+      pstarh = pstar / 2.0
+      sdvt(:,:) = 0.e0
+
+      !  Diffusion coefficients.
+      ahiu(:,:) = ahi0 * umask(:,:,1)
+      ahiv(:,:) = ahi0 * vmask(:,:,1)
+
+   END SUBROUTINE lim_dyn_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Empty module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_dyn         ! Empty routine
+   END SUBROUTINE lim_dyn
+#endif 
+
+   !!======================================================================
+END MODULE limdyn
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limflx.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limflx.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limflx.F90	(revision 4536)
@@ -0,0 +1,219 @@
+MODULE limflx
+   !!======================================================================
+   !!                       ***  MODULE limflx   ***
+   !!           computation of the flux at the sea ice/ocean interface
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_flx  : flux at the ice / ocean interface
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE phycst           ! physical constants
+   USE ocfzpt           ! surface ocean freezing point
+   USE ice_oce          ! sea-ice variable
+   USE flx_oce          ! sea-ice/ocean forcings variables
+   USE ice              ! LIM sea-ice variables
+   USE flxblk           ! bulk formulea
+   USE lbclnk           ! ocean lateral boundary condition
+   USE in_out_manager   ! I/O manager
+   USE albedo           ! albedo parameters
+   USE prtctl           ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_flx       ! called by lim_step
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi16 = 1.e-16  ,  &
+      rzero  = 0.e0    ,  &
+      rone   = 1.e0
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_flx
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_flx ***
+      !!  
+      !! ** Purpose : Computes the mass and heat fluxes to the ocean
+      !!         
+      !! ** Action  : - Initialisation of some variables
+      !!              - comput. of the fluxes at the sea ice/ocean interface
+      !!     
+      !! ** Outputs : - fsolar  : solar heat flux at sea ice/ocean interface
+      !!              - fnsolar : non solar heat flux 
+      !!              - fsalt   : salt flux at sea ice/ocean interface
+      !!              - fmass   : freshwater flux at sea ice/ocean interface
+      !!
+      !! ** References :
+      !!       H. Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
+      !!         original    : 00-01 (LIM)
+      !!         addition    : 02-07 (C. Ethe, G. Madec)
+      !!---------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji, jj         ! dummy loop indices
+
+      INTEGER ::   &
+         ifvt, i1mfr, idfr ,   &  ! some switches
+         iflt, ial, iadv, ifral, ifrdv
+      
+      REAL(wp) ::   &
+         zinda  ,              &  ! switch for testing the values of ice concentration
+         z1mthcm                  ! 1 - thcm
+!!         zfcm1  ,              &  ! solar  heat fluxes
+!!         zfcm2  ,              &  !  non solar heat fluxes
+#if defined key_lim_fdd   
+      REAL(wp) ::   &
+         zfons,                &  ! salt exchanges at the ice/ocean interface
+         zpme                     ! freshwater exchanges at the ice/ocean interface
+#else
+      REAL(wp) ::   &
+         zprs  , zfons,        &  ! salt exchanges at the ice/ocean interface
+         zpmess                   ! freshwater exchanges at the ice/ocean interface
+#endif
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zfcm1  ,              &  ! solar  heat fluxes
+         zfcm2                    !  non solar heat fluxes      
+#if defined key_coupled    
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zalb  ,               &  ! albedo of ice under overcast sky
+         zalcn ,               &  ! albedo of ocean under overcast sky
+         zalbp ,               &  ! albedo of ice under clear sky
+         zaldum                   ! albedo of ocean under clear sky
+#endif
+      !!---------------------------------------------------------------------
+     
+      !---------------------------------!
+      !      Sea ice/ocean interface    !
+      !---------------------------------!
+       
+       
+      !      heat flux at the ocean surface
+      !-------------------------------------------------------
+       
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zinda   = 1.0 - MAX( rzero , SIGN( rone , - ( 1.0 - pfrld(ji,jj) ) ) )
+            ifvt    = zinda  *  MAX( rzero , SIGN( rone, -phicif(ji,jj) ) )
+            i1mfr   = 1.0 - MAX( rzero , SIGN( rone ,  - ( 1.0 - frld(ji,jj) ) ) )
+            idfr    = 1.0 - MAX( rzero , SIGN( rone , frld(ji,jj) - pfrld(ji,jj) ) )
+            iflt    = zinda  * (1 - i1mfr) * (1 - ifvt )
+            ial     = ifvt   * i1mfr + ( 1 - ifvt ) * idfr
+            iadv    = ( 1  - i1mfr ) * zinda
+            ifral   = ( 1  - i1mfr * ( 1 - ial ) )   
+            ifrdv   = ( 1  - ifral * ( 1 - ial ) ) * iadv 
+            z1mthcm =   1. - thcm(ji,jj)       
+            !   computation the solar flux at ocean surface
+            zfcm1(ji,jj)   = pfrld(ji,jj) * qsr_oce(ji,jj)  + ( 1. - pfrld(ji,jj) ) * fstric(ji,jj)
+            !  computation the non solar heat flux at ocean surface
+            zfcm2(ji,jj) =  - z1mthcm * zfcm1(ji,jj)   &
+               &           + iflt    * ( fscmbq(ji,jj) + ffltbif(ji,jj) )                            &
+               &           + ifral   * ( ial * qcmif(ji,jj) + (1 - ial) * qldif(ji,jj) ) / rdt_ice   &
+               &           + ifrdv   * ( qfvbq(ji,jj) + qdtcn(ji,jj) ) / rdt_ice
+
+            fsbbq(ji,jj) = ( 1.0 - ( ifvt + iflt ) ) * fscmbq(ji,jj)     ! ???
+            
+            fsolar (ji,jj) = zfcm1(ji,jj)                                       ! solar heat flux 
+
+            fnsolar(ji,jj) = zfcm2(ji,jj) - fdtcn(ji,jj)                        ! non solar heat flux
+         END DO
+      END DO
+  
+       
+      !      mass flux at the ocean surface
+      !-------------------------------------------------------
+       
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#if defined key_lim_fdd
+            !  case of realistic freshwater flux (Tartinville et al., 2001)
+            
+            !  computing freshwater exchanges at the ice/ocean interface
+            zpme = - evap(ji,jj) * frld(ji,jj)            &   !  evaporation over oceanic fraction
+               &   + tprecip(ji,jj)                            &   !  total precipitation
+               &   - sprecip(ji,jj) * ( 1. - pfrld(ji,jj) )  &   !  remov. snow precip over ice
+               &   - rdmsnif(ji,jj) / rdt_ice                   !  freshwaterflux due to snow melting 
+            
+            !  computing salt exchanges at the ice/ocean interface
+            zfons =  ( soce - sice ) * ( rdmicif(ji,jj) / rdt_ice ) 
+            
+            !  converting the salt flux from ice to a freshwater flux from ocean
+            fsalt(ji,jj) = zfons / ( sss_io(ji,jj) + epsi16 )
+            
+            !  freshwater masses
+            fmass(ji,jj) = - zpme 
+#else
+            !  case of freshwater flux equivalent as salt flux
+            !  dilution effect due to evaporation and precipitation
+            zprs  = ( tprecip(ji,jj) - sprecip(ji,jj) * ( 1. - pfrld(ji,jj) ) ) * soce  
+            !  freshwater flux
+            zfons = rdmicif(ji,jj) * ( soce - sice )  &  !  fwf : ice formation and melting
+               &   -  dmgwi(ji,jj) * sice             &  !  fwf : salt flx needed to bring the fresh snow to sea/ice salinity
+               &   + rdmsnif(ji,jj) * soce               !  fwf to ocean due to snow melting 
+            !  salt exchanges at the ice/ocean interface
+            zpmess         =  zprs - zfons / rdt_ice - evap(ji,jj) * soce * frld(ji,jj)
+            fsalt(ji,jj) =  - zpmess
+#endif
+         END DO
+      END DO
+
+
+      !-------------------------------------------------------------------!
+      !  computation of others transmitting variables from ice to ocean   !
+      !------------------------------------------ ------------------------!
+
+      !-----------------------------------------------!
+      !   Storing the transmitted variables           !
+      !-----------------------------------------------!
+
+      ftaux (:,:) = - tio_u(:,:) * rau0   ! taux ( ice: N/m2/rau0, ocean: N/m2 )
+      ftauy (:,:) = - tio_v(:,:) * rau0   ! tauy ( ice: N/m2/rau0, ocean: N/m2 )                
+      freeze(:,:) = 1.0 - frld(:,:)       ! Sea ice cover            
+      tn_ice(:,:) = sist(:,:)             ! Ice surface temperature                      
+
+#if defined key_coupled            
+      zalb  (:,:) = 0.e0
+      zalcn (:,:) = 0.e0
+      zalbp (:,:) = 0.e0
+      zaldum(:,:) = 0.e0
+
+      !------------------------------------------------!
+      !  2) Computation of snow/ice and ocean albedo   !
+      !------------------------------------------------!
+      CALL flx_blk_albedo( zalb, zalcn, zalbp, zaldum )
+
+      alb_ice(:,:) =  0.5 * zalbp(:,:) + 0.5 * zalb (:,:)   ! Ice albedo                       
+#endif
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=fsolar, clinfo1=' lim_flx: fsolar : ', tab2d_2=fnsolar, clinfo2=' fnsolar : ')
+         CALL prt_ctl(tab2d_1=fmass , clinfo1=' lim_flx: fmass  : ', tab2d_2=fsalt  , clinfo2=' fsalt   : ')
+         CALL prt_ctl(tab2d_1=ftaux , clinfo1=' lim_flx: ftaux  : ', tab2d_2=ftauy  , clinfo2=' ftauy   : ')
+         CALL prt_ctl(tab2d_1=freeze, clinfo1=' lim_flx: freeze : ', tab2d_2=tn_ice , clinfo2=' tn_ice  : ')
+      ENDIF 
+   
+    END SUBROUTINE lim_flx
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :        Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_flx         ! Dummy routine
+   END SUBROUTINE lim_flx
+#endif 
+
+   !!======================================================================
+END MODULE limflx
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limhdf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limhdf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limhdf.F90	(revision 4536)
@@ -0,0 +1,185 @@
+MODULE limhdf
+   !!======================================================================
+   !!                    ***  MODULE limhdf   ***
+   !! LIM ice model : horizontal diffusion of sea-ice quantities
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_hdf  : diffusion trend on sea-ice variable
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce
+   USE ice_oce         ! ice variables
+   USE in_out_manager
+   USE ice
+   USE lbclnk
+   USE lib_mpp
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_hdf    ! called by lim_tra
+
+   !! * Module variables
+   LOGICAL  ::   linit = .TRUE.              ! ???
+   REAL(wp) ::   epsi04 = 1e-04              ! constant
+   REAL(wp), DIMENSION(jpi,jpj) ::   zfact   ! ???
+
+   !! * Substitution 
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_hdf( ptab )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_hdf  ***
+      !!
+      !! ** purpose :   Compute and add the diffusive trend on sea-ice
+      !!      variables
+      !!
+      !! ** method  :   Second order diffusive operator evaluated using a
+      !!      Cranck-Nicholson time Scheme.
+      !!
+      !! ** Action  :    update ptab with the diffusive contribution
+      !!
+      !! History :
+      !!        !  00-01 (LIM) Original code
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!        !  02-08 (C. Ethe)  F90, free form
+      !!-------------------------------------------------------------------
+      ! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         ptab                 ! Field on which the diffusion is applied  
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ptab0                ! ???
+
+      ! * Local variables
+      INTEGER ::  ji, jj      ! dummy loop indices
+      INTEGER ::  &
+         its, iter            ! temporary integers
+      CHARACTER (len=55) :: charout
+      REAL(wp) ::  &
+         zalfa, zrlxint, zconv, zeps   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::  & 
+         zrlx, zflu, zflv, &  ! temporary workspaces
+         zdiv0, zdiv          !    "           "
+      !!-------------------------------------------------------------------
+
+      ! Initialisation
+      ! ---------------   
+      ! Time integration parameters
+      zalfa = 0.5       ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
+      its   = 100       ! Maximum number of iteration
+      zeps  =  2. * epsi04
+
+      ! Arrays initialization
+      ptab0 (:, : ) = ptab(:,:)
+!bug  zflu (:,jpj) = 0.e0
+!bug  zflv (:,jpj) = 0.e0
+      zdiv0(:, 1 ) = 0.e0
+      zdiv0(:,jpj) = 0.e0
+      IF( .NOT.lk_vopt_loop ) THEN
+         zflu (jpi,:) = 0.e0   
+         zflv (jpi,:) = 0.e0
+         zdiv0(1,  :) = 0.e0
+         zdiv0(jpi,:) = 0.e0
+      ENDIF
+
+      ! Metric coefficient (compute at the first call and saved in
+      IF( linit ) THEN
+         DO jj = 2, jpjm1  
+            DO ji = fs_2 , fs_jpim1   ! vector opt.
+               zfact(ji,jj) = ( e2u(ji,jj) + e2u(ji-1,jj  ) + e1v(ji,jj) + e1v(ji,jj-1) ) &
+                  &          / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+         linit = .FALSE.
+      ENDIF
+
+
+      ! Sub-time step loop
+      zconv = 1.e0
+      iter  = 0
+
+      !                                                   !===================
+      DO WHILE ( ( zconv > zeps ) .AND. (iter <= its) )   ! Sub-time step loop
+         !                                                !===================
+         ! incrementation of the sub-time step number
+         iter = iter + 1
+
+         ! diffusive fluxes in U- and V- direction
+         DO jj = 1, jpjm1
+            DO ji = 1 , fs_jpim1   ! vector opt.
+               zflu(ji,jj) = pahu(ji,jj) * e2u(ji,jj) / e1u(ji,jj) * ( ptab(ji+1,jj) - ptab(ji,jj) )
+               zflv(ji,jj) = pahv(ji,jj) * e1v(ji,jj) / e2v(ji,jj) * ( ptab(ji,jj+1) - ptab(ji,jj) )
+            END DO
+         END DO
+
+         ! diffusive trend : divergence of the fluxes
+         DO jj= 2, jpjm1
+            DO ji = fs_2 , fs_jpim1   ! vector opt. 
+               zdiv (ji,jj) = (  zflu(ji,jj) - zflu(ji-1,jj  )   &
+                  &            + zflv(ji,jj) - zflv(ji  ,jj-1)  ) / ( e1t (ji,jj) * e2t (ji,jj) )
+            END DO
+         END DO
+
+         ! save the first evaluation of the diffusive trend in zdiv0
+         IF( iter == 1 )   zdiv0(:,:) = zdiv(:,:)       
+
+         ! XXXX iterative evaluation?????
+         DO jj = 2, jpjm1
+            DO ji = fs_2 , fs_jpim1   ! vector opt.
+               zrlxint = (   ptab0(ji,jj)    &
+                  &       +  rdt_ice * (           zalfa   * ( zdiv(ji,jj) + zfact(ji,jj) * ptab(ji,jj) )   &
+                  &                      + ( 1.0 - zalfa ) *   zdiv0(ji,jj) )  )                             & 
+                  &    / ( 1.0 + zalfa * rdt_ice * zfact(ji,jj) )
+               zrlx(ji,jj) = ptab(ji,jj) + om * ( zrlxint - ptab(ji,jj) )
+            END DO
+         END DO
+
+         ! lateral boundary condition on ptab
+         CALL lbc_lnk( zrlx, 'T', 1. )
+
+         ! convergence test
+         zconv = 0.e0
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zconv = MAX( zconv, ABS( zrlx(ji,jj) - ptab(ji,jj) )  )
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_max( zconv )   ! max over the global domain
+
+         ptab(:,:) = zrlx(:,:)
+
+         !                                         !==========================
+      END DO                                       ! end of sub-time step loop
+      !                                            !==========================
+
+      IF(ln_ctl)   THEN
+         zrlx(:,:) = ptab(:,:) - ptab0(:,:)
+         WRITE(charout,FMT="(' lim_hdf  : zconv =',D23.16, ' iter =',I4,2X)") zconv, iter
+         CALL prt_ctl(tab2d_1=zrlx, clinfo1=charout)
+      ENDIF
+
+   END SUBROUTINE lim_hdf
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_hdf         ! Empty routine
+   END SUBROUTINE lim_hdf
+#endif
+
+   !!======================================================================
+END MODULE limhdf
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limistate.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limistate.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limistate.F90	(revision 4536)
@@ -0,0 +1,287 @@
+MODULE limistate
+   !!======================================================================
+   !!                     ***  MODULE  limistate  ***
+   !!              Initialisation of diagnostics ice variables
+   !!======================================================================
+   !! History :   2.0  !  01-04  (C. Ethe, G. Madec)  Original code
+   !!                  !  04-04  (S. Theetten) initialization from a file
+   !!                  !  06-07  (S. Masson)  IOM to read the restart
+   !!--------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lim_istate      :  Initialisation of diagnostics ice variables
+   !!   lim_istate_init :  initialization of ice state and namelist read
+   !!----------------------------------------------------------------------
+   USE phycst
+   USE ocfzpt
+   USE oce             ! dynamics and tracers variables      !!gm used???
+   USE dom_oce                                                     !!gm used???
+   USE par_ice         ! ice parameters
+   USE ice_oce         ! ice variables
+   USE dom_ice
+   USE ice             ! ???
+   USE lbclnk
+   USE ice
+   USE iom
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC lim_istate      ! routine called by lim_init.F90
+
+   REAL(wp) ::           &  !!! ** init namelist (namiceini) **
+      ttest  = 2.0  ,    &  ! threshold water temperature for initial sea ice
+      hninn  = 0.5  ,    &  ! initial snow thickness in the north
+      hginn  = 3.0  ,    &  ! initial ice thickness in the north
+      alinn  = 0.05 ,    &  ! initial leads area in the north
+      hnins  = 0.1  ,    &  ! initial snow thickness in the south
+      hgins  = 1.0  ,    &  ! initial ice thickness in the south
+      alins  = 0.1          ! initial leads area in the south
+
+   REAL(wp)  ::          &  ! constant values
+      zzero   = 0.e0  ,  &
+      zone    = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_istate
+      !!-------------------------------------------------------------------
+      !!                    ***  ROUTINE lim_istate  ***
+      !!
+      !! ** Purpose :   defined the sea-ice initial state
+      !!
+      !! ** Method  :   restart from a state defined in a binary file
+      !!                or from arbitrary sea-ice conditions
+      !!--------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zidto, zs0, ztf, zbin     ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztn   ! workspace
+      !--------------------------------------------------------------------
+
+       CALL lim_istate_init     !  reading the initials parameters of the ice
+
+      !-- Initialisation of sst,sss,u,v do i=1,jpi
+      u_io(:,:)  = 0.e0       ! ice velocity in x direction
+      v_io(:,:)  = 0.e0       ! ice velocity in y direction
+
+      IF( ln_limini ) THEN    ! 
+        
+         ! Initialisation at tn if no ice or sst_ini if ice
+         ! Idem for salinity
+
+      !--- Criterion for presence (zidto=1.) or absence (zidto=0.) of ice
+         DO jj = 1 , jpj
+            DO ji = 1 , jpi
+               
+               zidto = MAX(zzero, - SIGN(1.,frld(ji,jj) - 1.))
+               
+               sst_io(ji,jj) = ( nfice - 1 ) * (zidto * sst_ini(ji,jj)  + &   ! use the ocean initial values
+                    &          (1.0 - zidto ) * ( tn(ji,jj,1) + rt0 ))        ! tricky trick *(nfice-1) !
+               sss_io(ji,jj) = ( nfice - 1 ) * (zidto * sss_ini(ji,jj) + &
+                    &          (1.0 - zidto ) *  sn(ji,jj,1) )
+
+               ! to avoid the the melting of ice, several layers (mixed layer) should be
+               ! set to sst_ini (sss_ini) if there is ice
+               ! example for one layer 
+               ! tn(ji,jj,1) = zidto * ( sst_ini(ji,jj) - rt0 )  + (1.0 - zidto ) *  tn(ji,jj,1)
+               ! sn(ji,jj,1) = zidto * sss_ini(ji,jj)  + (1.0 - zidto ) *  sn(ji,jj,1)
+               ! tb(ji,jj,1) = tn(ji,jj,1)
+               ! sb(ji,jj,1) = sn(ji,jj,1)
+            END DO
+         END DO
+         
+         
+         !  tfu: Melting point of sea water
+         tfu(:,:)  = ztf   
+         
+         tfu(:,:)  = ABS ( rt0 - 0.0575       * sss_ini(:,:)                               &
+              &                    + 1.710523e-03 * sss_ini(:,:) * SQRT( sss_ini(:,:) )    &
+              &                    - 2.154996e-04 * sss_ini(:,:) * sss_ini(:,:) )
+      ELSE                     !
+
+         
+         ! Initialisation at tn or -2 if ice
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zbin = MAX( 0., SIGN( 1., fzptn(ji,jj) - tn(ji,jj,1) ) )
+               ztn(ji,jj) = ( (1.-zbin) * tn(ji,jj,1) - 2. * zbin + rt0 ) * tmask(ji,jj,1)
+            END DO
+         END DO
+         
+         u_io  (:,:) = 0.e0
+         v_io  (:,:) = 0.e0
+         sst_io(:,:) = ( nfice - 1 ) * ( tn(:,:,1) + rt0 )   ! use the ocean initial values
+         sss_io(:,:) = ( nfice - 1 ) *   sn(:,:,1)           ! tricky trick *(nfice-1) !
+         
+         ! reference salinity 34psu
+         zs0 = 34.e0
+         ztf = ABS ( rt0 - 0.0575       * zs0                           &
+              &                    + 1.710523e-03 * zs0 * SQRT( zs0 )   &
+              &                    - 2.154996e-04 * zs0 *zs0          )
+         
+         !  tfu: Melting point of sea water
+         tfu(:,:)  = ztf   
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !--- Criterion for presence (zidto=1) or absence (zidto=0) of ice
+               zidto  = tms(ji,jj) * ( 1.0 - MAX(zzero, SIGN( zone, ztn(ji,jj) - tfu(ji,jj) - ttest) ) )
+               
+               IF( fcor(ji,jj) >= 0.e0 ) THEN     !--  Northern hemisphere.
+                  hicif(ji,jj)   = zidto * hginn
+                  frld(ji,jj)    = zidto * alinn + ( 1.0 - zidto ) * 1.0
+                  hsnif(ji,jj)   = zidto * hninn
+               ELSE                               !---  Southern hemisphere.
+                  hicif(ji,jj)   = zidto * hgins
+                  frld(ji,jj)    = zidto * alins + ( 1.0 - zidto ) * 1.0
+                  hsnif(ji,jj)   = zidto * hnins
+               ENDIF
+            END DO
+         END DO
+         
+         sist  (:,:)   = tfu(:,:)
+         tbif  (:,:,1) = tfu(:,:)
+         tbif  (:,:,2) = tfu(:,:)
+         tbif  (:,:,3) = tfu(:,:)
+      
+      ENDIF
+      fsbbq (:,:)   = 0.e0
+      qstoif(:,:)   = 0.e0
+      u_ice (:,:)   = 0.e0
+      v_ice (:,:)   = 0.e0
+# if defined key_coupled
+      albege(:,:)   = 0.8 * tms(:,:)
+# endif
+
+      !---  Moments for advection.             
+
+      sxice (:,:)  = 0.e0   ;   sxsn (:,:)  = 0.e0   ;   sxa  (:,:)  = 0.e0
+      syice (:,:)  = 0.e0   ;   sysn (:,:)  = 0.e0   ;   sya  (:,:)  = 0.e0
+      sxxice(:,:)  = 0.e0   ;   sxxsn(:,:)  = 0.e0   ;   sxxa (:,:)  = 0.e0
+      syyice(:,:)  = 0.e0   ;   syysn(:,:)  = 0.e0   ;   syya (:,:)  = 0.e0
+      sxyice(:,:)  = 0.e0   ;   sxysn(:,:)  = 0.e0   ;   sxya (:,:)  = 0.e0
+
+      sxc0  (:,:)  = 0.e0   ;   sxc1 (:,:)  = 0.e0   ;   sxc2 (:,:)  = 0.e0
+      syc0  (:,:)  = 0.e0   ;   syc1 (:,:)  = 0.e0   ;   syc2 (:,:)  = 0.e0
+      sxxc0 (:,:)  = 0.e0   ;   sxxc1(:,:)  = 0.e0   ;   sxxc2(:,:)  = 0.e0
+      syyc0 (:,:)  = 0.e0   ;   syyc1(:,:)  = 0.e0   ;   syyc2(:,:)  = 0.e0
+      sxyc0 (:,:)  = 0.e0   ;   sxyc1(:,:)  = 0.e0   ;   sxyc2(:,:)  = 0.e0
+
+      sxst  (:,:)  = 0.e0
+      syst  (:,:)  = 0.e0
+      sxxst (:,:)  = 0.e0
+      syyst (:,:)  = 0.e0
+      sxyst (:,:)  = 0.e0
+
+      !-- lateral boundary conditions
+      CALL lbc_lnk( hicif, 'T', 1. )
+      CALL lbc_lnk( frld , 'T', 1. )
+
+      ! C A U T I O N  frld = 1 over land and lbc_lnk put zero along 
+      ! *************  closed boundaries herefore we force to one over land
+      frld(:,:) = tms(:,:) * frld(:,:) + ( 1. - tms(:,:) )   
+
+      CALL lbc_lnk( hsnif, 'T', 1. )
+      CALL lbc_lnk( sist , 'T', 1. )
+      DO jk = 1, jplayersp1
+         CALL lbc_lnk(tbif(:,:,jk), 'T', 1. )
+      END DO
+      CALL lbc_lnk( fsbbq  , 'T', 1. )
+      CALL lbc_lnk( qstoif , 'T', 1. )
+      CALL lbc_lnk( sss_io , 'T', 1. )
+      !
+   END SUBROUTINE lim_istate
+
+   
+   SUBROUTINE lim_istate_init
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_istate_init  ***
+      !!        
+      !! ** Purpose :   Definition of initial state of the ice 
+      !!
+      !! ** Method  :   Read the namiceini namelist and check the parameter 
+      !!                values called at the first timestep (nit000)
+      !!                or
+      !!                Read 7 variables from a previous restart file
+      !!                sst, sst, hicif, hsnif, frld, ts & tbif
+      !!
+      !! ** input   :   Namelist namiceini
+      !!-------------------------------------------------------------------
+      INTEGER :: inum_ice
+      INTEGER :: ji,jj
+
+      NAMELIST/namiceini/ ln_limini, ttest, hninn, hginn, alinn, &
+         &                hnins, hgins, alins
+      !!-------------------------------------------------------------------
+      
+      ! Read Namelist namiceini 
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice , namiceini )
+      
+      IF(.NOT. ln_limini) THEN 
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'lim_istate_init : ice parameters inititialisation '
+            WRITE(numout,*) '~~~~~~~~~~~~~~~'
+            WRITE(numout,*) '         threshold water temp. for initial sea-ice    ttest      = ', ttest
+            WRITE(numout,*) '         initial snow thickness in the north          hninn      = ', hninn
+            WRITE(numout,*) '         initial ice thickness in the north           hginn      = ', hginn 
+            WRITE(numout,*) '         initial leads area in the north              alinn      = ', alinn            
+            WRITE(numout,*) '         initial snow thickness in the south          hnins      = ', hnins 
+            WRITE(numout,*) '         initial ice thickness in the south           hgins      = ', hgins
+            WRITE(numout,*) '         initial leads area in the south              alins      = ', alins
+         ENDIF
+      ENDIF
+
+      IF( ln_limini ) THEN                      ! Ice initialization using input file
+
+         CALL iom_open( 'Ice_initialization.nc', inum_ice )
+
+         IF( inum_ice > 0 ) THEN
+            IF(lwp) THEN
+               WRITE(numout,*) ' '
+               WRITE(numout,*) 'lim_istate_init : ice state initialization with : Ice_initialization.nc'
+               WRITE(numout,*) '~~~~~~~~~~~~~~~'
+               WRITE(numout,*) '         Ice state initialization using input file    ln_limini  = ', ln_limini
+               WRITE(numout,*) ' '
+            ENDIF
+            
+            CALL iom_get( inum_ice, jpdom_data, 'sst'  , sst_ini(:,:) )        
+            CALL iom_get( inum_ice, jpdom_data, 'sss'  , sss_ini(:,:) )       
+            CALL iom_get( inum_ice, jpdom_data, 'hicif', hicif  (:,:) )      
+            CALL iom_get( inum_ice, jpdom_data, 'hsnif', hsnif  (:,:) )      
+            CALL iom_get( inum_ice, jpdom_data, 'frld' , frld   (:,:) )     
+            CALL iom_get( inum_ice, jpdom_data, 'ts'   , sist   (:,:) )
+            CALL iom_get( inum_ice, jpdom_unknown, 'tbif', tbif(1:nlci,1:nlcj,:),   &
+                 &        kstart = (/ mig(1),mjg(1),1 /), kcount = (/ nlci,nlcj,jplayersp1 /) )
+            ! put some values in the extra-halo...
+            DO jj = nlcj+1, jpj   ;   tbif(1:nlci,jj,:) = tbif(1:nlci,nlej,:)   ;   END DO
+            DO ji = nlci+1, jpi   ;   tbif(ji    ,: ,:) = tbif(nlei  ,:   ,:)   ;   END DO
+
+            CALL iom_close( inum_ice)
+            
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE lim_istate_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_istate          ! Empty routine
+   END SUBROUTINE lim_istate
+#endif
+
+   !!======================================================================
+END MODULE limistate
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limmsh.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limmsh.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limmsh.F90	(revision 4536)
@@ -0,0 +1,259 @@
+MODULE limmsh
+   !!======================================================================
+   !!                     ***  MODULE  limmsh  ***
+   !! LIM ice model :   definition of the ice mesh parameters
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_msh   : definition of the ice mesh
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE dom_oce
+   USE dom_ice
+   USE lbclnk
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC lim_msh      ! routine called by ice_ini.F90
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_msh
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_msh  ***
+      !!              
+      !! ** Purpose : Definition of the charact. of the numerical grid
+      !!       
+      !! ** Action  : - Initialisation of some variables
+      !!              - Definition of some constants linked with the grid
+      !!              - Definition of the metric coef. for the sea/ice
+      !!              - Initialization of the ice masks (tmsk, umsk)
+      !! 
+      !! ** Refer.  : Deleersnijder et al. Ocean Modelling 100, 7-10 
+      !!
+      !! ** History :
+      !!         original    : 01-04 (LIM)
+      !!         addition    : 02-08 (C. Ethe, G. Madec)
+      !!--------------------------------------------------------------------- 
+      !! * Local variables
+      INTEGER :: ji, jj      ! dummy loop indices
+
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zd2d1 , zd1d2       ! Derivative of zh2 (resp. zh1) in the x direction
+         !                   ! (resp. y direction) (defined at the center)
+      REAL(wp) ::         &
+         zh1p  , zh2p   , &  ! Idem zh1, zh2 for the bottom left corner of the grid
+         zd2d1p, zd1d2p , &  ! Idem zd2d1, zd1d2 for the bottom left corner of the grid
+         zusden, zusden2     ! temporary scalars
+      !!---------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_msh : LIM sea-ice model, mesh initialization'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      
+      !----------------------------------------------------------                          
+      !    Initialization of local and some global (common) variables 
+      !------------------------------------------------------------------ 
+      
+      njeq   = INT( jpj / 2 )   !i bug mpp potentiel
+      njeqm1 = njeq - 1 
+
+      fcor(:,:) = 2. * omega * SIN( gphit(:,:) * rad )   !  coriolis factor
+ 
+!i    DO jj = 1, jpj
+!i       zmsk(jj) = SUM( tmask(:,jj,:) )   ! = 0          if land  everywhere on a j-line
+!!ii     write(numout,*) jj, zind(jj)
+!i    END DO
+
+      IF( fcor(1,1) * fcor(1,nlcj) < 0.e0 ) THEN   ! local domain include both hemisphere
+         l_jeq = .TRUE.
+         njeq  = 1
+         DO WHILE ( njeq <= jpj .AND. fcor(1,njeq) < 0.e0 )
+            njeq = njeq + 1
+         END DO
+         IF(lwp ) WRITE(numout,*) '          the equator is inside the domain at about njeq = ', njeq
+      ELSEIF( fcor(1,1) < 0.e0 ) THEN
+         l_jeq = .FALSE.
+         njeq = jpj
+         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the southern hemisphere: njeq = ', njeq
+      ELSE
+         l_jeq = .FALSE.
+         njeq = 2
+         IF(lwp ) WRITE(numout,*) '          the model domain is entirely in the northern hemisphere: njeq = ', njeq
+      ENDIF
+
+      njeqm1 = njeq - 1
+
+
+      !   For each grid, definition of geometric tables 
+      !------------------------------------------------------------------
+      
+      !-------------------
+      ! Conventions :    !
+      !-------------------
+      !  indices 1 \ 2 <-> localisation in the 2 direction x \ y
+      !  3rd indice <-> localisation on the mesh :
+      !  0 = Centre ;  1 = corner W x(i-1/2) ; 2 = corner S y(j-1/2) ;
+      !  3 = corner SW x(i-1/2),y(j-1/2)
+      !-------------------
+!!ibug ???
+      akappa(:,:,:,:) = 0.e0
+      wght(:,:,:,:) = 0.e0
+      alambd(:,:,:,:,:,:) = 0.e0
+      tmu(:,:) = 0.e0
+!!i
+      
+      
+      ! metric coefficients for sea ice dynamic
+      !----------------------------------------
+      !                                                       ! akappa
+      DO jj = 2, jpj
+         zd1d2(:,jj) = e1v(:,jj) - e1v(:,jj-1)
+      END DO
+      CALL lbc_lnk( zd1d2, 'T', -1. )
+
+      DO ji = 2, jpi
+         zd2d1(ji,:) = e2u(ji,:) - e2u(ji-1,:)
+      END DO
+      CALL lbc_lnk( zd2d1, 'T', -1. )
+
+      akappa(:,:,1,1) =        1.0 / ( 2.0 * e1t(:,:) )
+      akappa(:,:,1,2) = zd1d2(:,:) / ( 4.0 * e1t(:,:) * e2t(:,:) )
+      akappa(:,:,2,1) = zd2d1(:,:) / ( 4.0 * e1t(:,:) * e2t(:,:) )
+      akappa(:,:,2,2) =        1.0 / ( 2.0 * e2t(:,:) )
+      
+      !                                                      ! weights (wght)
+      DO jj = 2, jpj
+         DO ji = 2, jpi
+            zusden = 1. / (  ( e1t(ji,jj) + e1t(ji-1,jj  ) )   &
+               &           * ( e2t(ji,jj) + e2t(ji  ,jj-1) ) )
+            wght(ji,jj,1,1) = zusden * e1t(ji  ,jj) * e2t(ji,jj  )
+            wght(ji,jj,1,2) = zusden * e1t(ji  ,jj) * e2t(ji,jj-1)
+            wght(ji,jj,2,1) = zusden * e1t(ji-1,jj) * e2t(ji,jj  )
+            wght(ji,jj,2,2) = zusden * e1t(ji-1,jj) * e2t(ji,jj-1)
+         END DO
+      END DO
+      CALL lbc_lnk( wght(:,:,1,1), 'I', 1. )      ! CAUTION: even with the lbc_lnk at ice U-V-point
+      CALL lbc_lnk( wght(:,:,1,2), 'I', 1. )      ! the value of wght at jpj is wrong
+      CALL lbc_lnk( wght(:,:,2,1), 'I', 1. )      ! but it is never used
+      CALL lbc_lnk( wght(:,:,2,2), 'I', 1. )
+    
+      ! Coefficients for divergence of the stress tensor
+      !-------------------------------------------------
+
+      DO jj = 2, jpj
+         DO ji = 2, jpi
+            zh1p  =  e1t(ji  ,jj  ) * wght(ji,jj,2,2)   &
+               &   + e1t(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &   + e1t(ji  ,jj-1) * wght(ji,jj,2,1)   &
+               &   + e1t(ji-1,jj-1) * wght(ji,jj,1,1)
+
+            zh2p  =  e2t(ji  ,jj  ) * wght(ji,jj,2,2)   &
+               &   + e2t(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &   + e2t(ji  ,jj-1) * wght(ji,jj,2,1)   &
+               &   + e2t(ji-1,jj-1) * wght(ji,jj,1,1)
+
+! better written but change the last digit and thus solver in less than 100 timestep
+!           zh1p  = e1t(ji-1,jj  ) * wght(ji,jj,1,2) + e1t(ji,jj  ) * wght(ji,jj,2,2)   &
+!              &  + e1t(ji-1,jj-1) * wght(ji,jj,1,1) + e1t(ji,jj-1) * wght(ji,jj,2,1) 
+
+!           zh2p  = e2t(ji-1,jj  ) * wght(ji,jj,1,2) + e2t(ji,jj  ) * wght(ji,jj,2,2)   &
+!              &  + e2t(ji-1,jj-1) * wght(ji,jj,1,1) + e2t(ji,jj-1) * wght(ji,jj,2,1)
+
+!!ibug =0   zusden = 1.0 / ( zh1p * zh2p * 4.e0 )
+            zusden = 1.0 / MAX( zh1p * zh2p * 4.e0 , 1.e-20 )
+            zusden2 = zusden * 2.0 
+
+            zd1d2p = zusden * 0.5 * ( -e1t(ji-1,jj-1) + e1t(ji-1,jj  ) - e1t(ji,jj-1) + e1t(ji  ,jj)   )
+            zd2d1p = zusden * 0.5 * (  e2t(ji  ,jj-1) - e2t(ji-1,jj-1) + e2t(ji,jj  ) - e2t(ji-1,jj)   )
+
+            alambd(ji,jj,2,2,2,1) = zusden2 * e2t(ji  ,jj-1)
+            alambd(ji,jj,2,2,2,2) = zusden2 * e2t(ji  ,jj  )
+            alambd(ji,jj,2,2,1,1) = zusden2 * e2t(ji-1,jj-1)
+            alambd(ji,jj,2,2,1,2) = zusden2 * e2t(ji-1,jj  )
+
+            alambd(ji,jj,1,1,2,1) = zusden2 * e1t(ji  ,jj-1)
+            alambd(ji,jj,1,1,2,2) = zusden2 * e1t(ji  ,jj  )
+            alambd(ji,jj,1,1,1,1) = zusden2 * e1t(ji-1,jj-1)
+            alambd(ji,jj,1,1,1,2) = zusden2 * e1t(ji-1,jj  )
+
+            alambd(ji,jj,1,2,2,1) = zd1d2p
+            alambd(ji,jj,1,2,2,2) = zd1d2p
+            alambd(ji,jj,1,2,1,1) = zd1d2p
+            alambd(ji,jj,1,2,1,2) = zd1d2p
+
+            alambd(ji,jj,2,1,2,1) = zd2d1p
+            alambd(ji,jj,2,1,2,2) = zd2d1p
+            alambd(ji,jj,2,1,1,1) = zd2d1p
+            alambd(ji,jj,2,1,1,2) = zd2d1p
+         END DO
+      END DO
+
+      CALL lbc_lnk( alambd(:,:,2,2,2,1), 'I', 1. )      ! CAUTION: even with the lbc_lnk at ice U-V point
+      CALL lbc_lnk( alambd(:,:,2,2,2,2), 'I', 1. )      ! the value of wght at jpj is wrong
+      CALL lbc_lnk( alambd(:,:,2,2,1,1), 'I', 1. )      ! but it is never used
+      CALL lbc_lnk( alambd(:,:,2,2,1,2), 'I', 1. )      ! 
+
+      CALL lbc_lnk( alambd(:,:,1,1,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,1,1,2,2), 'I', 1. )      ! 
+      CALL lbc_lnk( alambd(:,:,1,1,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,1,1,2), 'I', 1. )      !
+
+      CALL lbc_lnk( alambd(:,:,1,2,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,1,2,2,2), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,2,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,1,2,1,2), 'I', 1. )      !
+
+      CALL lbc_lnk( alambd(:,:,2,1,2,1), 'I', 1. )      ! CAUTION: idem
+      CALL lbc_lnk( alambd(:,:,2,1,2,2), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,2,1,1,1), 'I', 1. )      !
+      CALL lbc_lnk( alambd(:,:,2,1,1,2), 'I', 1. )      !
+            
+
+      ! Initialization of ice masks
+      !----------------------------
+      
+      tms(:,:) = tmask(:,:,1)      ! ice T-point  : use surface tmask
+
+!i here we can use umask with a i and j shift of -1,-1
+      tmu(:,1) = 0.e0
+      tmu(1,:) = 0.e0
+      DO jj = 2, jpj               ! ice U.V-point: computed from ice T-point mask
+         DO ji = 2, jpim1
+            tmu(ji,jj) =  tms(ji,jj) * tms(ji-1,jj) * tms(ji,jj-1) * tms(ji-1,jj-1)            
+         END DO
+      END DO
+      
+      !--lateral boundary conditions    
+      CALL lbc_lnk( tmu(:,:), 'I', 1. )
+      
+      ! unmasked and masked area of T-grid cell
+      area(:,:) = e1t(:,:) * e2t(:,:)
+      
+   END SUBROUTINE lim_msh
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy Module         NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_msh           ! Dummy routine
+   END SUBROUTINE lim_msh
+#endif
+
+   !!======================================================================
+END MODULE limmsh
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrhg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrhg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrhg.F90	(revision 4536)
@@ -0,0 +1,665 @@
+MODULE limrhg
+   !!======================================================================
+   !!                     ***  MODULE  limrhg  ***
+   !!   Ice rheology :  performs sea ice rheology
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_rhg   : computes ice velocities
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE par_oce
+   USE ice_oce         ! ice variables
+   USE dom_ice
+   USE ice
+   USE lbclnk
+   USE lib_mpp
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_rhg  ! routine called by lim_dyn
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      rzero   = 0.e0   ,  &
+      rone    = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_rhg( k_j1, k_jpj )
+      !!-------------------------------------------------------------------
+      !!                 ***  SUBROUTINR lim_rhg  ***
+      !!
+      !! ** purpose :   determines the velocity field of sea ice by using
+      !!  atmospheric (wind stress) and oceanic (water stress and surface
+      !!  tilt) forcings. Ice-ice interaction is described by a non-linear
+      !!  viscous-plastic law including shear strength and a bulk rheology.
+      !!
+      !! ** Action  : - compute u_ice, v_ice the sea-ice velocity
+      !!
+      !! History :
+      !!   0.0  !  93-12  (M.A. Morales Maqueda.)  Original code
+      !!   1.0  !  94-12  (H. Goosse) 
+      !!   2.0  !  03-12  (C. Ethe, G. Madec)  F90, mpp
+      !!-------------------------------------------------------------------
+      ! * Arguments
+      INTEGER, INTENT(in) ::   k_j1 ,  &  ! southern j-index for ice computation
+         &                     k_jpj      ! northern j-index for ice computation
+
+      ! * Local variables
+      INTEGER ::   ji, jj              ! dummy loop indices
+
+      INTEGER  :: &
+         iim1, ijm1, iip1 , ijp1   , & ! temporary integers
+         iter, jter                    !    "          "
+
+      CHARACTER (len=50) :: charout
+
+      REAL(wp) :: &
+         ze11  , ze12  , ze22  , ze21  ,   &  ! temporary scalars
+         zt11  , zt12  , zt21  , zt22  ,   &  !    "         "
+         zvis11, zvis21, zvis12, zvis22,   &  !    "         "
+         zgphsx, ztagnx, zusw  ,           &  !    "         "
+         zgphsy, ztagny                       !    "         "
+      REAL(wp) :: &
+         zresm, zunw, zvnw, zur, zvr, zmod, za, zac, &
+         zmpzas, zstms, zindu, zindu1, zusdtp, zmassdt, zcorlal,  &
+         ztrace2, zdeter, zdelta, zsang, zmask, zdgp, zdgi, zdiag
+      REAL(wp),DIMENSION(jpi,jpj) ::   &
+         zpresh, zfrld, zmass, zcorl,     &
+         zu0, zv0, zviszeta, zviseta,     &
+         zc1u, zc1v, zc2u, zc2v, za1ct, za2ct, za1, za2, zb1, zb2,  &
+         zc1, zc2, zd1, zd2, zden, zu_ice, zv_ice, zresr
+      REAL(wp),DIMENSION(jpi,jpj,2,2) :: &
+         zs11, zs12, zs22, zs21
+      !!-------------------------------------------------------------------
+      
+      !  Store initial velocities
+      !  ------------------------
+      zu0(:,:) = u_ice(:,:)
+      zv0(:,:) = v_ice(:,:)
+
+      ! Ice mass, ice strength, and wind stress at the center            |
+      ! of the grid squares.                                             |
+      !-------------------------------------------------------------------
+
+      DO jj = k_j1 , k_jpj-1
+         DO ji = 1 , jpi
+            za1(ji,jj)    = tms(ji,jj) * ( rhosn * hsnm(ji,jj) + rhoic * hicm(ji,jj) )
+            zpresh(ji,jj) = tms(ji,jj) *  pstarh * hicm(ji,jj) * EXP( -c_rhg * frld(ji,jj) )
+#if defined key_lim_cp1 && defined key_coupled
+            zb1(ji,jj)    = tms(ji,jj) * gtaux(ji,jj) * ( 1.0 - frld(ji,jj) )
+            zb2(ji,jj)    = tms(ji,jj) * gtauy(ji,jj) * ( 1.0 - frld(ji,jj) )
+#else
+            zb1(ji,jj)    = tms(ji,jj) * ( 1.0 - frld(ji,jj) )
+            zb2(ji,jj)    = tms(ji,jj) * ( 1.0 - frld(ji,jj) )
+#endif
+         END DO
+      END DO
+
+
+      !---------------------------------------------------------------------------
+      !  Wind stress, coriolis and mass terms at the corners of the grid squares |
+      !  Gradient of ice strenght.                                               |
+      !---------------------------------------------------------------------------
+         
+      DO jj = k_j1+1, k_jpj-1
+         DO ji = 2, jpi
+            zstms = tms(ji,jj  ) * wght(ji,jj,2,2) + tms(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &  + tms(ji,jj-1) * wght(ji,jj,2,1) + tms(ji-1,jj-1) * wght(ji,jj,1,1)
+            zusw  = 1.0 / MAX( zstms, epsd )
+
+            zt11 = tms(ji  ,jj  ) * frld(ji  ,jj  ) 
+            zt12 = tms(ji-1,jj  ) * frld(ji-1,jj  ) 
+            zt21 = tms(ji  ,jj-1) * frld(ji  ,jj-1) 
+            zt22 = tms(ji-1,jj-1) * frld(ji-1,jj-1)
+
+            ! Leads area.
+            zfrld(ji,jj) =  (  zt11 * wght(ji,jj,2,2) + zt12 * wght(ji,jj,1,2)   &
+               &             + zt21 * wght(ji,jj,2,1) + zt22 * wght(ji,jj,1,1) ) * zusw
+
+            ! Mass and coriolis coeff.
+            zmass(ji,jj) = ( za1(ji,jj  ) * wght(ji,jj,2,2) + za1(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &           + za1(ji,jj-1) * wght(ji,jj,2,1) + za1(ji-1,jj-1) * wght(ji,jj,1,1) ) * zusw
+            zcorl(ji,jj) = zmass(ji,jj) * fcor(ji,jj)
+
+            ! Wind stress.
+#if defined key_lim_cp1 && defined key_coupled
+            ztagnx = ( zb1(ji,jj  ) * wght(ji,jj,2,2) + zb1(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &     + zb1(ji,jj-1) * wght(ji,jj,2,1) + zb1(ji-1,jj-1) * wght(ji,jj,1,1) ) * zusw
+            ztagny = ( zb2(ji,jj  ) * wght(ji,jj,2,2) + zb2(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &     + zb2(ji,jj-1) * wght(ji,jj,2,1) + zb2(ji-1,jj-1) * wght(ji,jj,1,1) ) * zusw
+#else
+            ztagnx = ( zb1(ji,jj  ) * wght(ji,jj,2,2) + zb1(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &     + zb1(ji,jj-1) * wght(ji,jj,2,1) + zb1(ji-1,jj-1) * wght(ji,jj,1,1) ) * zusw * gtaux(ji,jj)
+            ztagny = ( zb2(ji,jj  ) * wght(ji,jj,2,2) + zb2(ji-1,jj  ) * wght(ji,jj,1,2)   &
+               &     + zb2(ji,jj-1) * wght(ji,jj,2,1) + zb2(ji-1,jj-1) * wght(ji,jj,1,1) ) * zusw * gtauy(ji,jj)
+#endif
+
+            ! Gradient of ice strength
+            zgphsx =   ( alambd(ji,jj,2,2,2,1) - alambd(ji,jj,2,1,2,1) ) * zpresh(ji  ,jj-1)   &
+               &     + ( alambd(ji,jj,2,2,2,2) - alambd(ji,jj,2,1,2,2) ) * zpresh(ji  ,jj  )   &
+               &     - ( alambd(ji,jj,2,2,1,1) + alambd(ji,jj,2,1,1,1) ) * zpresh(ji-1,jj-1)   &
+               &     - ( alambd(ji,jj,2,2,1,2) + alambd(ji,jj,2,1,1,2) ) * zpresh(ji-1,jj  )
+
+            zgphsy = - ( alambd(ji,jj,1,1,2,1) + alambd(ji,jj,1,2,2,1) ) * zpresh(ji  ,jj-1)   &
+               &     - ( alambd(ji,jj,1,1,1,1) + alambd(ji,jj,1,2,1,1) ) * zpresh(ji-1,jj-1)   &
+               &     + ( alambd(ji,jj,1,1,2,2) - alambd(ji,jj,1,2,2,2) ) * zpresh(ji  ,jj  )   &
+               &     + ( alambd(ji,jj,1,1,1,2) - alambd(ji,jj,1,2,1,2) ) * zpresh(ji-1,jj  )
+
+            ! Computation of the velocity field taking into account the ice-ice interaction.                                 
+            ! Terms that are independent of the velocity field.
+            za1ct(ji,jj) = ztagnx - zcorl(ji,jj) * v_oce(ji,jj) - zgphsx
+            za2ct(ji,jj) = ztagny + zcorl(ji,jj) * u_oce(ji,jj) - zgphsy
+         END DO
+      END DO
+
+!! inutile!!
+!!??    CALL lbc_lnk( za1ct, 'I', -1. )
+!!??    CALL lbc_lnk( za2ct, 'I', -1. )
+
+
+      ! SOLUTION OF THE MOMENTUM EQUATION.
+      !------------------------------------------
+      !                                                   ! ==================== !
+      DO iter = 1 , 2 * nbiter                            !    loop over iter    !
+         !                                                ! ==================== !        
+         zindu = MOD( iter , 2 )
+         zusdtp = ( zindu * 2.0 + ( 1.0 - zindu ) * 1.0 )  * REAL( nbiter ) / rdt_ice
+
+         ! Computation of free drift field for free slip boundary conditions.
+
+           DO jj = k_j1, k_jpj-1
+              DO ji = 1, jpim1
+                 !- Rate of strain tensor.
+                 zt11 =   akappa(ji,jj,1,1) * ( u_ice(ji+1,jj) + u_ice(ji+1,jj+1) - u_ice(ji,jj  ) - u_ice(ji  ,jj+1) )  &
+                    &   + akappa(ji,jj,1,2) * ( v_ice(ji+1,jj) + v_ice(ji+1,jj+1) + v_ice(ji,jj  ) + v_ice(ji  ,jj+1) )
+                 zt12 = - akappa(ji,jj,2,2) * ( u_ice(ji  ,jj) + u_ice(ji+1,jj  ) - u_ice(ji,jj+1) - u_ice(ji+1,jj+1) )  &
+                    &   - akappa(ji,jj,2,1) * ( v_ice(ji  ,jj) + v_ice(ji+1,jj  ) + v_ice(ji,jj+1) + v_ice(ji+1,jj+1) )
+                 zt22 = - akappa(ji,jj,2,2) * ( v_ice(ji  ,jj) + v_ice(ji+1,jj  ) - v_ice(ji,jj+1) - v_ice(ji+1,jj+1) )  &
+                    &   + akappa(ji,jj,2,1) * ( u_ice(ji  ,jj) + u_ice(ji+1,jj  ) + u_ice(ji,jj+1) + u_ice(ji+1,jj+1) )
+                 zt21 =   akappa(ji,jj,1,1) * ( v_ice(ji+1,jj) + v_ice(ji+1,jj+1) - v_ice(ji,jj  ) - v_ice(ji  ,jj+1) )  &
+                    &   - akappa(ji,jj,1,2) * ( u_ice(ji+1,jj) + u_ice(ji+1,jj+1) + u_ice(ji,jj  ) + u_ice(ji  ,jj+1) )
+
+                 !- Rate of strain tensor. 
+                 zdgp = zt11 + zt22
+                 zdgi = zt12 + zt21
+                 ztrace2 = zdgp * zdgp 
+                 zdeter  = zt11 * zt22 - 0.25 * zdgi * zdgi
+
+                 !  Creep limit depends on the size of the grid.
+                 zdelta = MAX( SQRT( ztrace2 + ( ztrace2 - 4.0 * zdeter ) * usecc2),  creepl)
+
+                 !-  Computation of viscosities.
+                 zviszeta(ji,jj) = MAX( zpresh(ji,jj) / zdelta, etamn )
+                 zviseta (ji,jj) = zviszeta(ji,jj) * usecc2
+              END DO
+           END DO
+!!??       CALL lbc_lnk( zviszeta, 'I', -1. )  ! or T point???   semble reellement inutile
+!!??       CALL lbc_lnk( zviseta , 'I', -1. )
+
+
+           !-  Determination of zc1u, zc2u, zc1v and zc2v.
+           DO jj = k_j1+1, k_jpj-1
+              DO ji = 2, jpim1
+                 ze11   =  akappa(ji-1,jj-1,1,1)
+                 ze12   = +akappa(ji-1,jj-1,2,2)
+                 ze22   =  akappa(ji-1,jj-1,2,1)
+                 ze21   = -akappa(ji-1,jj-1,1,2)
+                 zvis11 = 2.0 * zviseta (ji-1,jj-1) + dm
+                 zvis22 =       zviszeta(ji-1,jj-1) - zviseta(ji-1,jj-1)
+                 zvis12 =       zviseta (ji-1,jj-1) + dm
+                 zvis21 =       zviseta (ji-1,jj-1)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,1,1) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,1,1) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,1,1) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,1,1) =  zvis12 * ze21 + zvis21 * ze12
+
+                 ze11   = -akappa(ji,jj-1,1,1)
+                 ze12   = +akappa(ji,jj-1,2,2)
+                 ze22   =  akappa(ji,jj-1,2,1)
+                 ze21   = -akappa(ji,jj-1,1,2)
+                 zvis11 = 2.0 * zviseta (ji,jj-1) + dm
+                 zvis22 =       zviszeta(ji,jj-1) - zviseta(ji,jj-1)
+                 zvis12 =       zviseta (ji,jj-1) + dm
+                 zvis21 =       zviseta (ji,jj-1)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,2,1) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,2,1) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,2,1) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,2,1) =  zvis12 * ze21 + zvis21 * ze12
+
+                 ze11   =  akappa(ji-1,jj,1,1)
+                 ze12   = -akappa(ji-1,jj,2,2)
+                 ze22   =  akappa(ji-1,jj,2,1)
+                 ze21   = -akappa(ji-1,jj,1,2)
+                 zvis11 = 2.0 * zviseta (ji-1,jj) + dm
+                 zvis22 =       zviszeta(ji-1,jj) - zviseta(ji-1,jj)
+                 zvis12 =       zviseta (ji-1,jj) + dm
+                 zvis21 =       zviseta (ji-1,jj)
+
+                 zdiag = zvis22 * ( ze11 + ze22 ) 
+                 zs11(ji,jj,1,2) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,1,2) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,1,2) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,1,2) =  zvis12 * ze21 + zvis21 * ze12
+
+                 ze11   = -akappa(ji,jj,1,1)
+                 ze12   = -akappa(ji,jj,2,2)
+                 ze22   =  akappa(ji,jj,2,1)
+                 ze21   = -akappa(ji,jj,1,2)
+                 zvis11 = 2.0 * zviseta (ji,jj) + dm
+                 zvis22 =       zviszeta(ji,jj) - zviseta(ji,jj)
+                 zvis12 =       zviseta (ji,jj) + dm
+                 zvis21 =       zviseta (ji,jj)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,2,2) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,2,2) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,2,2) =  zvis11 * ze22 + zdiag 
+                 zs21(ji,jj,2,2) =  zvis12 * ze21 + zvis21 * ze12
+              END DO
+           END DO
+
+           DO jj = k_j1+1, k_jpj-1
+              DO ji = 2, jpim1
+                 zc1u(ji,jj) =   &
+                    + alambd(ji,jj,2,2,2,1) * zs11(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs11(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs11(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,1,2,1) * zs12(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs12(ji,jj,1,1)   &
+                    + alambd(ji,jj,1,1,2,2) * zs12(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs12(ji,jj,1,2)   &
+                    + alambd(ji,jj,1,2,1,1) * zs21(ji,jj,1,1) + alambd(ji,jj,1,2,2,1) * zs21(ji,jj,2,1)   &
+                    + alambd(ji,jj,1,2,1,2) * zs21(ji,jj,1,2) + alambd(ji,jj,1,2,2,2) * zs21(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,1,1,1) * zs22(ji,jj,1,1) - alambd(ji,jj,2,1,2,1) * zs22(ji,jj,2,1)   &
+                    - alambd(ji,jj,2,1,1,2) * zs22(ji,jj,1,2) - alambd(ji,jj,2,1,2,2) * zs22(ji,jj,2,2)
+                 
+                 zc2u(ji,jj) =   &
+                    + alambd(ji,jj,2,2,2,1) * zs21(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs21(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,2,1,1) * zs21(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs21(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,1,2,1) * zs22(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs22(ji,jj,1,1)   &
+                    + alambd(ji,jj,1,1,2,2) * zs22(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs22(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,1,2,2,1) * zs11(ji,jj,2,1)   &
+                    - alambd(ji,jj,1,2,1,2) * zs11(ji,jj,1,2) - alambd(ji,jj,1,2,2,2) * zs11(ji,jj,2,2)   &
+                    + alambd(ji,jj,2,1,1,1) * zs12(ji,jj,1,1) + alambd(ji,jj,2,1,2,1) * zs12(ji,jj,2,1)   &
+                    + alambd(ji,jj,2,1,1,2) * zs12(ji,jj,1,2) + alambd(ji,jj,2,1,2,2) * zs12(ji,jj,2,2)
+             END DO
+           END DO
+
+           DO jj = k_j1+1, k_jpj-1
+              DO ji = 2, jpim1
+                 !  zc1v , zc2v.
+                 ze11   =  akappa(ji-1,jj-1,1,2)
+                 ze12   = -akappa(ji-1,jj-1,2,1)
+                 ze22   = +akappa(ji-1,jj-1,2,2)
+                 ze21   =  akappa(ji-1,jj-1,1,1)
+                 zvis11 = 2.0 * zviseta (ji-1,jj-1) + dm
+                 zvis22 =       zviszeta(ji-1,jj-1) - zviseta(ji-1,jj-1)
+                 zvis12 =       zviseta (ji-1,jj-1) + dm
+                 zvis21 =       zviseta (ji-1,jj-1)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,1,1) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,1,1) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,1,1) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,1,1) =  zvis12 * ze21 + zvis21 * ze12
+ 
+                 ze11   =  akappa(ji,jj-1,1,2)
+                 ze12   = -akappa(ji,jj-1,2,1)
+                 ze22   = +akappa(ji,jj-1,2,2)
+                 ze21   = -akappa(ji,jj-1,1,1)
+                 zvis11 = 2.0 * zviseta (ji,jj-1) + dm
+                 zvis22 =       zviszeta(ji,jj-1) - zviseta(ji,jj-1)
+                 zvis12 =       zviseta (ji,jj-1) + dm
+                 zvis21 =       zviseta (ji,jj-1)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,2,1) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,2,1) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,2,1) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,2,1) =  zvis12 * ze21 + zvis21 * ze12
+
+                 ze11   =  akappa(ji-1,jj,1,2)
+                 ze12   = -akappa(ji-1,jj,2,1)
+                 ze22   = -akappa(ji-1,jj,2,2)
+                 ze21   =  akappa(ji-1,jj,1,1)
+                 zvis11 = 2.0 * zviseta (ji-1,jj) + dm
+                 zvis22 =       zviszeta(ji-1,jj) - zviseta(ji-1,jj)
+                 zvis12 =       zviseta (ji-1,jj) + dm
+                 zvis21 =       zviseta (ji-1,jj)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,1,2) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,1,2) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,1,2) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,1,2) =  zvis12 * ze21 + zvis21 * ze12
+
+                 ze11   =  akappa(ji,jj,1,2)
+                 ze12   = -akappa(ji,jj,2,1)
+                 ze22   = -akappa(ji,jj,2,2)
+                 ze21   = -akappa(ji,jj,1,1)
+                 zvis11 = 2.0 * zviseta (ji,jj) + dm
+                 zvis22 =       zviszeta(ji,jj) - zviseta(ji,jj)
+                 zvis12 =       zviseta (ji,jj) + dm
+                 zvis21 =       zviseta (ji,jj)
+
+                 zdiag = zvis22 * ( ze11 + ze22 )
+                 zs11(ji,jj,2,2) =  zvis11 * ze11 + zdiag
+                 zs12(ji,jj,2,2) =  zvis12 * ze12 + zvis21 * ze21
+                 zs22(ji,jj,2,2) =  zvis11 * ze22 + zdiag
+                 zs21(ji,jj,2,2) =  zvis12 * ze21 + zvis21 * ze12
+
+              END DO
+           END DO
+
+           DO jj = k_j1+1, k_jpj-1
+              DO ji = 2, jpim1
+                 zc1v(ji,jj) =   &
+                    + alambd(ji,jj,2,2,2,1) * zs11(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs11(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs11(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,1,2,1) * zs12(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs12(ji,jj,1,1)   &
+                    + alambd(ji,jj,1,1,2,2) * zs12(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs12(ji,jj,1,2)   &
+                    + alambd(ji,jj,1,2,1,1) * zs21(ji,jj,1,1) + alambd(ji,jj,1,2,2,1) * zs21(ji,jj,2,1)   &
+                    + alambd(ji,jj,1,2,1,2) * zs21(ji,jj,1,2) + alambd(ji,jj,1,2,2,2) * zs21(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,1,1,1) * zs22(ji,jj,1,1) - alambd(ji,jj,2,1,2,1) * zs22(ji,jj,2,1)   &
+                    - alambd(ji,jj,2,1,1,2) * zs22(ji,jj,1,2) - alambd(ji,jj,2,1,2,2) * zs22(ji,jj,2,2)
+                 zc2v(ji,jj) =   &
+                    + alambd(ji,jj,2,2,2,1) * zs21(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs21(ji,jj,2,2)   &
+                    - alambd(ji,jj,2,2,1,1) * zs21(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs21(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,1,2,1) * zs22(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs22(ji,jj,1,1)   &
+                    + alambd(ji,jj,1,1,2,2) * zs22(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs22(ji,jj,1,2)   &
+                    - alambd(ji,jj,1,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,1,2,2,1) * zs11(ji,jj,2,1)   &
+                    - alambd(ji,jj,1,2,1,2) * zs11(ji,jj,1,2) - alambd(ji,jj,1,2,2,2) * zs11(ji,jj,2,2)   &
+                    + alambd(ji,jj,2,1,1,1) * zs12(ji,jj,1,1) + alambd(ji,jj,2,1,2,1) * zs12(ji,jj,2,1)   &
+                    + alambd(ji,jj,2,1,1,2) * zs12(ji,jj,1,2) + alambd(ji,jj,2,1,2,2) * zs12(ji,jj,2,2)
+              END DO
+           END DO
+
+         ! Relaxation.
+           
+iflag:   DO jter = 1 , nbitdr
+
+            !  Store previous drift field.   
+            DO jj = k_j1, k_jpj-1
+               zu_ice(:,jj) = u_ice(:,jj)
+               zv_ice(:,jj) = v_ice(:,jj)
+            END DO
+
+            DO jj = k_j1+1, k_jpj-1
+               zsang  = SIGN( 1.e0, fcor(1,jj) ) * sangvg   ! only the sinus changes its sign with the hemisphere
+               DO ji = 2, jpim1
+                 zur     = u_ice(ji,jj) - u_oce(ji,jj)
+                 zvr     = v_ice(ji,jj) - v_oce(ji,jj)
+                 zmod    = SQRT( zur * zur + zvr * zvr) * ( 1.0 - zfrld(ji,jj) )
+                 za      = rhoco * zmod
+                 zac     = za * cangvg
+                  zmpzas  = alpha * zcorl(ji,jj) + za * zsang
+                  zmassdt = zusdtp * zmass(ji,jj)
+                  zcorlal = ( 1.0 - alpha ) * zcorl(ji,jj)
+
+                  za1(ji,jj) =  zmassdt * zu0(ji,jj) + zcorlal * zv0(ji,jj) + za1ct(ji,jj)   &
+                     &        + za * ( cangvg * u_oce(ji,jj) - zsang * v_oce(ji,jj) )
+
+                  za2(ji,jj) =  zmassdt * zv0(ji,jj) - zcorlal * zu0(ji,jj) + za2ct(ji,jj)   &
+                     &        + za * ( cangvg * v_oce(ji,jj) + zsang * u_oce(ji,jj) )
+
+                  zb1(ji,jj)  = zmassdt + zac - zc1u(ji,jj)
+                  zb2(ji,jj)  = zmpzas  - zc2u(ji,jj)
+                  zc1(ji,jj)  = zmpzas  + zc1v(ji,jj)
+                  zc2(ji,jj)  = zmassdt + zac  - zc2v(ji,jj) 
+                  zdeter      = zc1(ji,jj) * zb2(ji,jj) + zc2(ji,jj) * zb1(ji,jj)
+                  zden(ji,jj) = SIGN( rone, zdeter) / MAX( epsd , ABS( zdeter ) )
+               END DO
+            END DO
+
+            ! The computation of ice interaction term is splitted into two parts
+            !-------------------------------------------------------------------------
+
+            ! Terms that do not involve already up-dated velocities.
+         
+            DO jj = k_j1+1, k_jpj-1
+               DO ji = 2, jpim1
+                  iim1 = ji
+                  ijm1 = jj - 1
+                  iip1 = ji + 1
+                  ijp1 = jj
+                  ze11 =   akappa(iim1,ijm1,1,1) * u_ice(iip1,ijp1) + akappa(iim1,ijm1,1,2) * v_ice(iip1,ijp1)
+                  ze12 = + akappa(iim1,ijm1,2,2) * u_ice(iip1,ijp1) - akappa(iim1,ijm1,2,1) * v_ice(iip1,ijp1)
+                  ze22 = + akappa(iim1,ijm1,2,2) * v_ice(iip1,ijp1) + akappa(iim1,ijm1,2,1) * u_ice(iip1,ijp1)
+                  ze21 =   akappa(iim1,ijm1,1,1) * v_ice(iip1,ijp1) - akappa(iim1,ijm1,1,2) * u_ice(iip1,ijp1)
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,2,1) =  zvis11 * ze11 + zdiag
+                  zs12(ji,jj,2,1) =  zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,2,1) =  zvis11 * ze22 + zdiag
+                  zs21(ji,jj,2,1) =  zvis12 * ze21 + zvis21 * ze12
+
+
+                  iim1 = ji - 1
+                  ijm1 = jj
+                  iip1 = ji
+                  ijp1 = jj + 1                   
+                  ze11 =   akappa(iim1,ijm1,1,1) * ( u_ice(iip1,ijp1) - u_ice(iim1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,1,2) * ( v_ice(iip1,ijp1) + v_ice(iim1,ijp1) )
+                  ze12 = + akappa(iim1,ijm1,2,2) * ( u_ice(iim1,ijp1) + u_ice(iip1,ijp1) )   &
+                     &   - akappa(iim1,ijm1,2,1) * ( v_ice(iim1,ijp1) + v_ice(iip1,ijp1) )
+                  ze22 = + akappa(iim1,ijm1,2,2) * ( v_ice(iim1,ijp1) + v_ice(iip1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,2,1) * ( u_ice(iim1,ijp1) + u_ice(iip1,ijp1) )
+                  ze21 =   akappa(iim1,ijm1,1,1) * ( v_ice(iip1,ijp1) - v_ice(iim1,ijp1) )   &
+                     &   - akappa(iim1,ijm1,1,2) * ( u_ice(iip1,ijp1) + u_ice(iim1,ijp1) )
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,1,2) =  zvis11 * ze11 + zdiag
+                  zs12(ji,jj,1,2) =  zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,1,2) =  zvis11 * ze22 + zdiag
+                  zs21(ji,jj,1,2) =  zvis12 * ze21 + zvis21 * ze12
+
+                  iim1 = ji
+                  ijm1 = jj
+                  iip1 = ji + 1
+                  ijp1 = jj + 1
+                  ze11 =   akappa(iim1,ijm1,1,1) * ( u_ice(iip1,ijm1) + u_ice(iip1,ijp1) - u_ice(iim1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,1,2) * ( v_ice(iip1,ijm1) + v_ice(iip1,ijp1) + v_ice(iim1,ijp1) )
+                  ze12 = - akappa(iim1,ijm1,2,2) * ( u_ice(iip1,ijm1) - u_ice(iim1,ijp1) - u_ice(iip1,ijp1) )   &
+                     &   - akappa(iim1,ijm1,2,1) * ( v_ice(iip1,ijm1) + v_ice(iim1,ijp1) + v_ice(iip1,ijp1) )
+                  ze22 = - akappa(iim1,ijm1,2,2) * ( v_ice(iip1,ijm1) - v_ice(iim1,ijp1) - v_ice(iip1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,2,1) * ( u_ice(iip1,ijm1) + u_ice(iim1,ijp1) + u_ice(iip1,ijp1) )
+                  ze21 =   akappa(iim1,ijm1,1,1) * ( v_ice(iip1,ijm1) + v_ice(iip1,ijp1) - v_ice(iim1,ijp1) )   &
+                     &   - akappa(iim1,ijm1,1,2) * ( u_ice(iip1,ijm1) + u_ice(iip1,ijp1) + u_ice(iim1,ijp1) ) 
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,2,2) =  zvis11 * ze11 + zdiag
+                  zs12(ji,jj,2,2) =  zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,2,2) =  zvis11 * ze22 + zdiag
+                  zs21(ji,jj,2,2) =  zvis12 * ze21 + zvis21 * ze12
+
+               END DO
+            END DO
+
+            ! Terms involving already up-dated velocities.
+            !-Using the arrays zu_ice and zv_ice in the computation of the terms ze leads to JACOBI's method; 
+            ! Using arrays u and v in the computation of the terms ze leads to GAUSS-SEIDEL method.
+             
+            DO jj = k_j1+1, k_jpj-1
+               DO ji = 2, jpim1
+                  iim1 = ji - 1
+                  ijm1 = jj - 1
+                  iip1 = ji
+                  ijp1 = jj
+                  ze11 =   akappa(iim1,ijm1,1,1) * ( zu_ice(iip1,ijm1) - zu_ice(iim1,ijm1) - zu_ice(iim1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,1,2) * ( zv_ice(iip1,ijm1) + zv_ice(iim1,ijm1) + zv_ice(iim1,ijp1) )
+                  ze12 = - akappa(iim1,ijm1,2,2) * ( zu_ice(iim1,ijm1) + zu_ice(iip1,ijm1) - zu_ice(iim1,ijp1) )   &
+                     &   - akappa(iim1,ijm1,2,1) * ( zv_ice(iim1,ijm1) + zv_ice(iip1,ijm1) + zv_ice(iim1,ijp1) )
+                  ze22 = - akappa(iim1,ijm1,2,2) * ( zv_ice(iim1,ijm1) + zv_ice(iip1,ijm1) - zv_ice(iim1,ijp1) )   &
+                     &   + akappa(iim1,ijm1,2,1) * ( zu_ice(iim1,ijm1) + zu_ice(iip1,ijm1) + zu_ice(iim1,ijp1) )
+                  ze21 =   akappa(iim1,ijm1,1,1) * ( zv_ice(iip1,ijm1) - zv_ice(iim1,ijm1) - zv_ice(iim1,ijp1) )   &
+                     &  -  akappa(iim1,ijm1,1,2) * ( zu_ice(iip1,ijm1) + zu_ice(iim1,ijm1) + zu_ice(iim1,ijp1) )
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,1,1) =  zvis11 * ze11 + zdiag
+                  zs12(ji,jj,1,1) =  zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,1,1) =  zvis11 * ze22 + zdiag
+                  zs21(ji,jj,1,1) =  zvis12 * ze21 + zvis21 * ze12
+
+#if defined key_agrif
+             END DO
+          END DO
+
+          DO jj = k_j1+1, k_jpj-1
+             DO ji = 2, jpim1
+#endif
+
+                  iim1 = ji
+                  ijm1 = jj - 1
+                  iip1 = ji + 1
+                  ze11 =   akappa(iim1,ijm1,1,1) * ( zu_ice(iip1,ijm1) - zu_ice(iim1,ijm1) )   &
+                     &   + akappa(iim1,ijm1,1,2) * ( zv_ice(iip1,ijm1) + zv_ice(iim1,ijm1) )
+                  ze12 = - akappa(iim1,ijm1,2,2) * ( zu_ice(iim1,ijm1) + zu_ice(iip1,ijm1) )   &
+                     &   - akappa(iim1,ijm1,2,1) * ( zv_ice(iim1,ijm1) + zv_ice(iip1,ijm1) )
+                  ze22 = - akappa(iim1,ijm1,2,2) * ( zv_ice(iim1,ijm1) + zv_ice(iip1,ijm1) )   &
+                     &   + akappa(iim1,ijm1,2,1) * ( zu_ice(iim1,ijm1) + zu_ice(iip1,ijm1) )
+                  ze21 =   akappa(iim1,ijm1,1,1) * ( zv_ice(iip1,ijm1) - zv_ice(iim1,ijm1) )   &
+                     &   - akappa(iim1,ijm1,1,2) * ( zu_ice(iip1,ijm1) + zu_ice(iim1,ijm1) )
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,2,1) =  zs11(ji,jj,2,1) + zvis11 * ze11 + zdiag
+                  zs12(ji,jj,2,1) =  zs12(ji,jj,2,1) + zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,2,1) =  zs22(ji,jj,2,1) + zvis11 * ze22 + zdiag
+                  zs21(ji,jj,2,1) =  zs21(ji,jj,2,1) + zvis12 * ze21 + zvis21 * ze12
+
+
+                  iim1 = ji - 1
+                  ijm1 = jj 
+                  ze11 = - akappa(iim1,ijm1,1,1) * zu_ice(iim1,ijm1) + akappa(iim1,ijm1,1,2) * zv_ice(iim1,ijm1)
+                  ze12 = - akappa(iim1,ijm1,2,2) * zu_ice(iim1,ijm1) - akappa(iim1,ijm1,2,1) * zv_ice(iim1,ijm1)
+                  ze22 = - akappa(iim1,ijm1,2,2) * zv_ice(iim1,ijm1) + akappa(iim1,ijm1,2,1) * zu_ice(iim1,ijm1)
+                  ze21 = - akappa(iim1,ijm1,1,1) * zv_ice(iim1,ijm1) - akappa(iim1,ijm1,1,2) * zu_ice(iim1,ijm1)
+                  zvis11 = 2.0 * zviseta (iim1,ijm1) + dm
+                  zvis22 =       zviszeta(iim1,ijm1) - zviseta(iim1,ijm1)
+                  zvis12 =       zviseta (iim1,ijm1) + dm
+                  zvis21 =       zviseta (iim1,ijm1)
+
+                  zdiag = zvis22 * ( ze11 + ze22 )
+                  zs11(ji,jj,1,2) =  zs11(ji,jj,1,2) + zvis11 * ze11 + zdiag 
+                  zs12(ji,jj,1,2) =  zs12(ji,jj,1,2) + zvis12 * ze12 + zvis21 * ze21
+                  zs22(ji,jj,1,2) =  zs22(ji,jj,1,2) + zvis11 * ze22 + zdiag
+                  zs21(ji,jj,1,2) =  zs21(ji,jj,1,2) + zvis12 * ze21 + zvis21 * ze12
+
+#if defined key_agrif
+             END DO
+          END DO
+
+          DO jj = k_j1+1, k_jpj-1
+             DO ji = 2, jpim1
+#endif
+                  zd1(ji,jj) =   &
+                     + alambd(ji,jj,2,2,2,1) * zs11(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs11(ji,jj,2,2)  &
+                     - alambd(ji,jj,2,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs11(ji,jj,1,2)  &
+                     - alambd(ji,jj,1,1,2,1) * zs12(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs12(ji,jj,1,1)  &
+                     + alambd(ji,jj,1,1,2,2) * zs12(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs12(ji,jj,1,2)  &
+                     + alambd(ji,jj,1,2,1,1) * zs21(ji,jj,1,1) + alambd(ji,jj,1,2,2,1) * zs21(ji,jj,2,1)  &
+                     + alambd(ji,jj,1,2,1,2) * zs21(ji,jj,1,2) + alambd(ji,jj,1,2,2,2) * zs21(ji,jj,2,2)  &
+                     - alambd(ji,jj,2,1,1,1) * zs22(ji,jj,1,1) - alambd(ji,jj,2,1,2,1) * zs22(ji,jj,2,1)  &
+                     - alambd(ji,jj,2,1,1,2) * zs22(ji,jj,1,2) - alambd(ji,jj,2,1,2,2) * zs22(ji,jj,2,2)
+                  zd2(ji,jj) =   &
+                     + alambd(ji,jj,2,2,2,1) * zs21(ji,jj,2,1) + alambd(ji,jj,2,2,2,2) * zs21(ji,jj,2,2)  &
+                     - alambd(ji,jj,2,2,1,1) * zs21(ji,jj,1,1) - alambd(ji,jj,2,2,1,2) * zs21(ji,jj,1,2)  &
+                     - alambd(ji,jj,1,1,2,1) * zs22(ji,jj,2,1) - alambd(ji,jj,1,1,1,1) * zs22(ji,jj,1,1)  &
+                     + alambd(ji,jj,1,1,2,2) * zs22(ji,jj,2,2) + alambd(ji,jj,1,1,1,2) * zs22(ji,jj,1,2)  &
+                     - alambd(ji,jj,1,2,1,1) * zs11(ji,jj,1,1) - alambd(ji,jj,1,2,2,1) * zs11(ji,jj,2,1)  &
+                     - alambd(ji,jj,1,2,1,2) * zs11(ji,jj,1,2) - alambd(ji,jj,1,2,2,2) * zs11(ji,jj,2,2)  &
+                     + alambd(ji,jj,2,1,1,1) * zs12(ji,jj,1,1) + alambd(ji,jj,2,1,2,1) * zs12(ji,jj,2,1)  &
+                     + alambd(ji,jj,2,1,1,2) * zs12(ji,jj,1,2) + alambd(ji,jj,2,1,2,2) * zs12(ji,jj,2,2)
+               END DO
+            END DO
+
+            DO jj = k_j1+1, k_jpj-1
+               DO ji = 2, jpim1
+                  zunw = (  ( za1(ji,jj) + zd1(ji,jj) ) * zc2(ji,jj)        &
+                     &    + ( za2(ji,jj) + zd2(ji,jj) ) * zc1(ji,jj) ) * zden(ji,jj)
+
+                  zvnw = (  ( za2(ji,jj) + zd2(ji,jj) ) * zb1(ji,jj)        &
+                     &    - ( za1(ji,jj) + zd1(ji,jj) ) * zb2(ji,jj) ) * zden(ji,jj)
+
+                  zmask = ( 1.0 - MAX( rzero, SIGN( rone , 1.0 - zmass(ji,jj) ) ) ) * tmu(ji,jj)
+
+                  u_ice(ji,jj) = ( u_ice(ji,jj) + om * ( zunw - u_ice(ji,jj) ) * tmu(ji,jj) ) * zmask
+                  v_ice(ji,jj) = ( v_ice(ji,jj) + om * ( zvnw - v_ice(ji,jj) ) * tmu(ji,jj) ) * zmask
+               END DO
+            END DO
+
+            CALL lbc_lnk( u_ice, 'I', -1. )
+            CALL lbc_lnk( v_ice, 'I', -1. )
+
+            !---  5.2.5.4. Convergence test.
+            DO jj = k_j1+1 , k_jpj-1
+               zresr(:,jj) = MAX( ABS( u_ice(:,jj) - zu_ice(:,jj) ) , ABS( v_ice(:,jj) - zv_ice(:,jj) ) )
+            END DO
+            zresm = MAXVAL( zresr( 1:jpi , k_j1+1:k_jpj-1 ) )
+            IF( lk_mpp )   CALL mpp_max( zresm )   ! max over the global domain
+
+            IF ( zresm <= resl) EXIT iflag
+
+         END DO iflag
+
+         zindu1 = 1.0 - zindu
+         DO jj = k_j1 , k_jpj-1
+            zu0(:,jj) = zindu * zu0(:,jj) + zindu1 * u_ice(:,jj)
+            zv0(:,jj) = zindu * zv0(:,jj) + zindu1 * v_ice(:,jj)
+         END DO
+      !                                                   ! ==================== !
+      END DO                                              !  end loop over iter  !
+      !                                                   ! ==================== !
+
+      IF(ln_ctl) THEN
+         WRITE(charout,FMT="('lim_rhg  : res =',D23.16, ' iter =',I4)") zresm, jter
+         CALL prt_ctl_info(charout)
+         CALL prt_ctl(tab2d_1=u_ice, clinfo1=' lim_rhg  : u_ice :', tab2d_2=v_ice, clinfo2=' v_ice :')
+      ENDIF
+
+   END SUBROUTINE lim_rhg
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_rhg( k1 , k2 )         ! Dummy routine
+      WRITE(*,*) 'lim_rhg: You should not have seen this print! error?', k1, k2
+   END SUBROUTINE lim_rhg
+#endif
+
+   !!==============================================================================
+END MODULE limrhg
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limrst.F90	(revision 4536)
@@ -0,0 +1,258 @@
+MODULE limrst
+   !!======================================================================
+   !!                     ***  MODULE  limrst  ***
+   !! Ice restart :  write the ice restart file
+   !!======================================================================
+   !! History :  2.0  !  01-04  (C. Ethe, G. Madec)  Original code
+   !!                 !  06-07  (S. Masson)  use IOM for restart read/write
+   !!----------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lim_rst_opn   : open ice restart file
+   !!   lim_rst_write : write of the ice restart file 
+   !!   lim_rst_read  : read  the ice restart file 
+   !!----------------------------------------------------------------------
+   USE ice
+   USE dom_oce
+   USE ice_oce         ! ice variables
+   USE daymod
+
+   USE in_out_manager
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_rst_opn     ! routine called by ??? module
+   PUBLIC   lim_rst_write   ! routine called by ??? module
+   PUBLIC   lim_rst_read    ! routine called by ??? module
+
+   LOGICAL, PUBLIC ::   lrst_ice         !: logical to control the ice restart write 
+   INTEGER, PUBLIC ::   numrir, numriw   !: logical unit for ice restart (read and write)
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/LIM_SRC/limrst.F90,v 1.15 2007/06/29 14:54:06 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_rst_opn( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_opn  ***
+      !!
+      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )   lrst_ice = .FALSE.
+      
+      IF( kt == nitrst - 2*nfice + 1 .OR.  nitend - nit000 + 1 <= nfice ) THEN
+         ! beware if model runs less than nfice + 1 time step
+         ! beware of the format used to write kt (default is i8.8, that should be large enough)
+         IF( nitrst > 1.0e9 ) THEN   
+            WRITE(clkt,*) nitrst
+         ELSE
+            WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         IF(lwp) WRITE(numout,*)
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_ice"
+         IF(lwp) WRITE(numout,*) '             open ice restart.output NetCDF file: '//clname
+         CALL iom_open( clname, numriw, ldwrt = .TRUE., kiolib = jprstlib )
+         lrst_ice = .TRUE.
+      ENDIF
+      !
+   END SUBROUTINE lim_rst_opn
+
+   SUBROUTINE lim_rst_write( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_write  ***
+      !!
+      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+      !!
+      INTEGER ::   iter     ! kt + nfice -1
+      !!----------------------------------------------------------------------
+
+      iter = kt + nfice -1
+
+      IF( iter == nitrst ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'lim_rst_write : write ice restart.output NetCDF file  kt =', kt
+         IF(lwp) WRITE(numout,*) '~~~~~~~'         
+      ENDIF
+
+      ! Write in numriw (if iter == nitrst)
+      ! ------------------ 
+      !                                                                     ! calendar control
+      CALL iom_rstput( iter, nitrst, numriw, 'nfice' , REAL( nfice, wp) )      ! time-step 
+      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice', REAL( iter, wp) )      ! date
+      
+      CALL iom_rstput( iter, nitrst, numriw, 'hicif' , hicif (:,:)   )      ! prognostic variables 
+      CALL iom_rstput( iter, nitrst, numriw, 'hsnif' , hsnif (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'frld'  , frld  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sist'  , sist  (:,:)   )
+# if defined key_coupled
+      CALL iom_rstput( iter, nitrst, numriw, 'albege', albege(:,:) )
+# endif
+      CALL iom_rstput( iter, nitrst, numriw, 'tbif1' , tbif  (:,:,1) )
+      CALL iom_rstput( iter, nitrst, numriw, 'tbif2' , tbif  (:,:,2) )
+      CALL iom_rstput( iter, nitrst, numriw, 'tbif3' , tbif  (:,:,3) )
+      CALL iom_rstput( iter, nitrst, numriw, 'u_ice' , u_ice (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ice' , v_ice (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'gtaux' , gtaux (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'gtauy' , gtauy (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'qstoif', qstoif(:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'fsbbq' , fsbbq (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice(:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice(:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice(:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa   (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya   (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxc0'  , sxc0  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syc0'  , syc0  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxc0' , sxxc0 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyc0' , syyc0 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyc0' , sxyc0 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxc1'  , sxc1  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syc1'  , syc1  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxc1' , sxxc1 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyc1' , syyc1 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyc1' , sxyc1 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxc2'  , sxc2  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syc2'  , syc2  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxc2' , sxxc2 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyc2' , syyc2 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyc2' , sxyc2 (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxst'  , sxst  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syst'  , syst  (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxxst' , sxxst (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'syyst' , syyst (:,:)   )
+      CALL iom_rstput( iter, nitrst, numriw, 'sxyst' , sxyst (:,:)   )
+      
+      IF( iter == nitrst ) THEN
+         CALL iom_close( numriw )                         ! close the restart file
+         lrst_ice = .FALSE.
+      ENDIF
+      !
+   END SUBROUTINE lim_rst_write
+
+
+   SUBROUTINE lim_rst_read
+      !!----------------------------------------------------------------------
+      !!                    ***  lim_rst_read  ***
+      !!
+      !! ** purpose  :   read of sea-ice variable restart in a netcdf file
+      !!----------------------------------------------------------------------
+      !
+      REAL(wp) ::   zfice, ziter
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_rst_read : read ice NetCDF restart file'
+         WRITE(numout,*) '~~~~~~~~'
+      ENDIF
+
+      CALL iom_open ( 'restart_ice_in', numrir, kiolib = jprstlib )
+
+      CALL iom_get( numrir, 'nfice' , zfice )
+      CALL iom_get( numrir, 'kt_ice', ziter )    
+      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
+      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
+
+      !Control of date
+      
+      IF( ( nit000 - INT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nit000 in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',        &
+         &                   '   control of time parameter  nrstdt' )
+      IF( INT(zfice) /= nfice          .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nfice in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',        &
+         &                   '   control of time parameter  nrstdt' )
+
+      CALL iom_get( numrir, jpdom_autoglo, 'hicif' , hicif  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'hsnif' , hsnif  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'frld'  , frld   )    
+      CALL iom_get( numrir, jpdom_autoglo, 'sist'  , sist   )    
+# if defined key_coupled 
+      CALL iom_get( numrir, jpdom_autoglo, 'albege', albege )    
+# endif
+      CALL iom_get( numrir, jpdom_autoglo, 'tbif1' , tbif(:,:,1) )    
+      CALL iom_get( numrir, jpdom_autoglo, 'tbif2' , tbif(:,:,2) )    
+      CALL iom_get( numrir, jpdom_autoglo, 'tbif3' , tbif(:,:,3) )    
+      CALL iom_get( numrir, jpdom_autoglo, 'u_ice' , u_ice  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'v_ice' , v_ice  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'gtaux' , gtaux  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'gtauy' , gtauy  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'qstoif', qstoif )    
+      CALL iom_get( numrir, jpdom_autoglo, 'fsbbq' , fsbbq  )    
+      CALL iom_get( numrir, jpdom_autoglo, 'sxice' , sxice  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syice' , syice  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxice', sxxice )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyice', syyice )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyice', sxyice )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxsn'  , sxsn   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sysn'  , sysn   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxsn' , sxxsn  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syysn' , syysn  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxysn' , sxysn  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxa'   , sxa    )
+      CALL iom_get( numrir, jpdom_autoglo, 'sya'   , sya    )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxa'  , sxxa   )
+      CALL iom_get( numrir, jpdom_autoglo, 'syya'  , syya   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxya'  , sxya   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxc0'  , sxc0   )
+      CALL iom_get( numrir, jpdom_autoglo, 'syc0'  , syc0   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxc0' , sxxc0  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyc0' , syyc0  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyc0' , sxyc0  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxc1'  , sxc1   )
+      CALL iom_get( numrir, jpdom_autoglo, 'syc1'  , syc1   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxc1' , sxxc1  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyc1' , syyc1  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyc1' , sxyc1  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxc2'  , sxc2   )
+      CALL iom_get( numrir, jpdom_autoglo, 'syc2'  , syc2   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxc2' , sxxc2  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyc2' , syyc2  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyc2' , sxyc2  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxst'  , sxst   )
+      CALL iom_get( numrir, jpdom_autoglo, 'syst'  , syst   )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxxst' , sxxst  )
+      CALL iom_get( numrir, jpdom_autoglo, 'syyst' , syyst  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sxyst' , sxyst  )
+      
+      CALL iom_close( numrir )
+      !
+   END SUBROUTINE lim_rst_read
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :       Empty module            NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE limrst
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtab.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtab.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtab.F90	(revision 4536)
@@ -0,0 +1,80 @@
+MODULE limtab
+   !!======================================================================
+   !!                       ***  MODULE limtab   ***
+   !!              transform 1D (2D) array to a 2D (1D) table
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   tab_2d_1d  : 2-D to 1-D
+   !!   tab_1d_2d  : 1-D to 2-D
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tab_2d_1d  ! called by lim_ther
+   PUBLIC tab_1d_2d  ! called by lim_ther
+
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tab_2d_1d ( ndim1d, tab1d, tab2d, ndim2d_x, ndim2d_y, tab_ind )
+
+      INTEGER, INTENT(in) :: &
+         ndim1d, ndim2d_x, ndim2d_y
+
+      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT(in) ::  &
+         tab2d
+
+      INTEGER, DIMENSION ( ndim1d), INTENT ( in) :: &
+         tab_ind
+
+      REAL(wp), DIMENSION(ndim1d), INTENT ( out) ::  & 
+         tab1d
+
+      INTEGER ::  &
+         jn , jid, jjd
+        
+      DO jn = 1, ndim1d
+         jid        = MOD( tab_ind(jn) - 1, ndim2d_x ) + 1
+         jjd        = ( tab_ind(jn) - 1 ) / ndim2d_x + 1
+         tab1d( jn) = tab2d( jid, jjd)
+      END DO 
+
+   END SUBROUTINE tab_2d_1d
+
+
+   SUBROUTINE tab_1d_2d ( ndim1d, tab2d, tab_ind, tab1d, ndim2d_x, ndim2d_y )
+
+      INTEGER, INTENT ( in) :: &
+         ndim1d, ndim2d_x, ndim2d_y
+
+      INTEGER, DIMENSION (ndim1d) , INTENT (in) :: &
+         tab_ind
+
+      REAL(wp), DIMENSION(ndim1d), INTENT (in) ::  &
+         tab1d  
+
+      REAL(wp), DIMENSION (ndim2d_x, ndim2d_y), INTENT ( out) :: &
+         tab2d
+
+      INTEGER :: &
+         jn, jid, jjd
+
+      DO jn = 1, ndim1d
+         jid             = MOD( tab_ind(jn) - 1, ndim2d_x) + 1
+         jjd             =    ( tab_ind(jn) - 1 ) / ndim2d_x  + 1
+         tab2d(jid, jjd) = tab1d( jn)
+      END DO
+
+   END SUBROUTINE tab_1d_2d
+
+#endif
+END MODULE limtab
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd.F90	(revision 4536)
@@ -0,0 +1,480 @@
+MODULE limthd
+   !!======================================================================
+   !!                  ***  MODULE limthd   ***
+   !!              LIM thermo ice model : ice thermodynamic
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_thd      : thermodynamic of sea ice
+   !!   lim_thd_init : initialisation of sea-ice thermodynamic
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst          ! physical constants
+   USE dom_oce         ! ocean space and time domain variables
+   USE lbclnk
+   USE in_out_manager  ! I/O manager
+   USE ice             ! LIM sea-ice variables
+   USE ice_oce         ! sea-ice/ocean variables
+   USE flx_oce         ! sea-ice/ocean forcings variables 
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE dom_ice         ! LIM sea-ice domain
+   USE iceini
+   USE limthd_zdf
+   USE limthd_lac
+   USE limtab
+   USE prtctl          ! Print control
+      
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd       ! called by lim_step
+
+   !! * Module variables
+   REAL(wp)  ::            &  ! constant values
+      epsi20 = 1.e-20   ,  &
+      epsi16 = 1.e-16   ,  &
+      epsi04 = 1.e-04   ,  &
+      zzero  = 0.e0     ,  &
+      zone   = 1.e0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!-------- -------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_thd( kt )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE lim_thd  ***       
+      !!  
+      !! ** Purpose : This routine manages the ice thermodynamic.
+      !!         
+      !! ** Action : - Initialisation of some variables
+      !!             - Some preliminary computation (oceanic heat flux
+      !!               at the ice base, snow acc.,heat budget of the leads)
+      !!             - selection of the icy points and put them in an array
+      !!             - call lim_vert_ther for vert ice thermodynamic
+      !!             - back to the geographic grid
+      !!             - selection of points for lateral accretion
+      !!             - call lim_lat_acc  for the ice accretion
+      !!             - back to the geographic grid
+      !!
+      !! ** References :
+      !!       H. Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
+      !!
+      !! History :
+      !!   1.0  !  00-01 (LIM)
+      !!   2.0  !  02-07 (C. Ethe, G. Madec) F90
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+      INTEGER  ::   ji, jj,    &   ! dummy loop indices
+         nbpb  ,               &   ! nb of icy pts for thermo. cal.
+         nbpac                     ! nb of pts for lateral accretion 
+      CHARACTER (len=22) :: charout
+      REAL(wp) ::  &
+         zfric_umin = 5e-03 ,  &   ! lower bound for the friction velocity
+         zfric_umax = 2e-02        ! upper bound for the friction velocity
+      REAL(wp) ::   &
+         zinda              ,  &   ! switch for test. the val. of concen.
+         zindb, zindg       ,  &   ! switches for test. the val of arg
+         za , zh, zthsnice  ,  &
+         zfric_u            ,  &   ! friction velocity 
+         zfnsol             ,  &   ! total non solar heat
+         zfontn             ,  &   ! heat flux from snow thickness
+         zfntlat, zpareff          ! test. the val. of lead heat budget
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zhicifp            ,  &   ! ice thickness for outputs
+         zqlbsbq                   ! link with lead energy budget qldif
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: &
+         zmsk                      ! working array
+      !!-------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL lim_thd_init  ! Initialization (first time-step only)
+   
+      !-------------------------------------------!
+      !   Initilization of diagnostic variables   !
+      !-------------------------------------------!
+      
+!i est-ce utile?  oui au moins en partie
+      rdvosif(:,:) = 0.e0   ! variation of ice volume at surface
+      rdvobif(:,:) = 0.e0   ! variation of ice volume at bottom
+      fdvolif(:,:) = 0.e0   ! total variation of ice volume
+      rdvonif(:,:) = 0.e0   ! lateral variation of ice volume
+      fstric (:,:) = 0.e0   ! part of solar radiation absorbing inside the ice
+      fscmbq (:,:) = 0.e0   ! linked with fstric
+      ffltbif(:,:) = 0.e0   ! linked with fstric
+      qfvbq  (:,:) = 0.e0   ! linked with fstric
+      rdmsnif(:,:) = 0.e0   ! variation of snow mass per unit area
+      rdmicif(:,:) = 0.e0   ! variation of ice mass per unit area
+      hicifp (:,:) = 0.e0   ! daily thermodynamic ice production. 
+      zmsk (:,:,:) = 0.e0
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            hsnif(ji,jj)  = hsnif(ji,jj) *  MAX( zzero, SIGN( zone , hsnif(ji,jj) - epsi04 ) )
+         END DO
+      END DO
+
+      IF(ln_ctl)   CALL prt_ctl(tab2d_1=hsnif     , clinfo1=' lim_thd: hsnif   : ')
+      
+      !-----------------------------------!
+      !   Treatment of particular cases   !
+      !-----------------------------------!
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            !  snow is transformed into ice if the original ice cover disappears.
+            zindg         = tms(ji,jj) *  MAX( zzero , SIGN( zone , -hicif(ji,jj) ) )
+            hicif(ji,jj)  = hicif(ji,jj) + zindg * rhosn * hsnif(ji,jj) / rau0
+            hsnif(ji,jj)  = ( zone - zindg ) * hsnif(ji,jj) + zindg * hicif(ji,jj) * ( rau0 - rhoic ) / rhosn
+            dmgwi(ji,jj)  = zindg * (1.0 - frld(ji,jj)) * rhoic * hicif(ji,jj)   ! snow/ice mass
+            
+            !  the lead fraction, frld, must be little than or equal to amax (ice ridging).
+            zthsnice      = hsnif(ji,jj) + hicif(ji,jj)
+            zindb         = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - zthsnice ) ) ) 
+            za            = zindb * MIN( zone, ( 1.0 - frld(ji,jj) ) * uscomi )
+            hsnif (ji,jj) = hsnif(ji,jj)  * za
+            hicif (ji,jj) = hicif(ji,jj)  * za
+            qstoif(ji,jj) = qstoif(ji,jj) * za
+            frld  (ji,jj) = 1.0 - zindb * ( 1.0 - frld(ji,jj) ) / MAX( za , epsi20 )
+            
+            !  the in situ ice thickness, hicif, must be equal to or greater than hiclim.
+            zh            = MAX( zone , zindb * hiclim  / MAX( hicif(ji,jj) , epsi20 ) )
+            hsnif (ji,jj) = hsnif(ji,jj)  * zh
+            hicif (ji,jj) = hicif(ji,jj)  * zh
+            qstoif(ji,jj) = qstoif(ji,jj) * zh
+            frld  (ji,jj) = ( frld(ji,jj) + ( zh - 1.0 ) ) / zh
+         END DO
+      END DO
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=hicif  , clinfo1=' lim_thd: hicif   : ')
+         CALL prt_ctl(tab2d_1=hsnif  , clinfo1=' lim_thd: hsnif   : ')
+         CALL prt_ctl(tab2d_1=dmgwi  , clinfo1=' lim_thd: dmgwi   : ')
+         CALL prt_ctl(tab2d_1=qstoif , clinfo1=' lim_thd: qstoif  : ')
+         CALL prt_ctl(tab2d_1=frld   , clinfo1=' lim_thd: frld    : ')
+      ENDIF
+
+      
+      !-------------------------------!
+      !   Thermodynamics of sea ice   !
+      !-------------------------------!
+      
+      !      Partial computation of forcing for the thermodynamic sea ice model.
+      !--------------------------------------------------------------------------
+
+      !CDIR NOVERRCHK
+      DO jj = 1, jpj
+         !CDIR NOVERRCHK
+         DO ji = 1, jpi
+            zthsnice       = hsnif(ji,jj) + hicif(ji,jj)
+            zindb          = tms(ji,jj) * ( 1.0 - MAX( zzero , SIGN( zone , - zthsnice ) ) ) 
+            pfrld(ji,jj)   = frld(ji,jj)
+            zinda          = 1.0 - MAX( zzero , SIGN( zone , - ( 1.0 - pfrld(ji,jj) ) ) )
+            
+            !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
+            thcm(ji,jj)    = 0.e0 
+            
+            !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
+            !  temperature and turbulent mixing (McPhee, 1992)
+            zfric_u        = MAX ( MIN( SQRT( ust2s(ji,jj) ) , zfric_umax ) , zfric_umin )  ! friction velocity
+            fdtcn(ji,jj)  = zindb * rau0 * rcp * 0.006  * zfric_u * ( sst_io(ji,jj) - tfu(ji,jj) ) 
+            qdtcn(ji,jj)  = zindb * fdtcn(ji,jj) * frld(ji,jj) * rdt_ice
+                        
+            !  partial computation of the lead energy budget (qldif)
+            zfontn         = ( sprecip(ji,jj) / rhosn ) * xlsn  !   energy for melting
+            zfnsol         = qnsr_oce(ji,jj)  !  total non solar flux
+            qldif(ji,jj)   = tms(ji,jj) * ( qsr_oce(ji,jj) * ( 1.0 - thcm(ji,jj) )   &
+               &                               + zfnsol + fdtcn(ji,jj) - zfontn     &
+               &                               + ( 1.0 - zindb ) * fsbbq(ji,jj) )   &
+               &                               * frld(ji,jj) * rdt_ice    
+            !  parlat : percentage of energy used for lateral ablation (0.0) 
+            zfntlat        = 1.0 - MAX( zzero , SIGN( zone ,  - qldif(ji,jj) ) )
+            zpareff        = 1.0 + ( parlat - 1.0 ) * zinda * zfntlat
+            zqlbsbq(ji,jj) = qldif(ji,jj) * ( 1.0 - zpareff ) / MAX( (1.0 - frld(ji,jj)) * rdt_ice , epsi16 )
+            qldif  (ji,jj) = zpareff *  qldif(ji,jj)
+            qdtcn  (ji,jj) = zpareff * qdtcn(ji,jj)
+            
+            !  energy needed to bring ocean surface layer until its freezing
+            qcmif  (ji,jj) =  rau0 * rcp * fse3t(ji,jj,1) * ( tfu(ji,jj) - sst_io(ji,jj) ) * ( 1 - zinda )
+            
+            !  calculate oceanic heat flux.
+            fbif   (ji,jj) = zindb * (  fsbbq(ji,jj) / MAX( (1.0 - frld(ji,jj)) , epsi20 ) + fdtcn(ji,jj) )
+            
+            ! computation of the daily thermodynamic ice production (only needed for output)
+            zhicifp(ji,jj) = hicif(ji,jj) * ( 1.0 - frld(ji,jj) )
+         END DO
+      END DO
+      
+      
+      !         Select icy points and fulfill arrays for the vectorial grid.
+      !----------------------------------------------------------------------
+      nbpb = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( frld(ji,jj) < 1.0 ) THEN     
+               nbpb      = nbpb + 1
+               npb(nbpb) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=pfrld, clinfo1=' lim_thd: pfrld   : ', tab2d_2=thcm   , clinfo2='  thcm    : ')
+         CALL prt_ctl(tab2d_1=fdtcn, clinfo1=' lim_thd: fdtcn   : ', tab2d_2=qdtcn  , clinfo2='  qdtcn   : ')
+         CALL prt_ctl(tab2d_1=qldif, clinfo1=' lim_thd: qldif   : ', tab2d_2=zqlbsbq, clinfo2='  zqlbsbq : ')
+         CALL prt_ctl(tab2d_1=qcmif, clinfo1=' lim_thd: qcmif   : ', tab2d_2=fbif   , clinfo2='  fbif    : ')
+         zmsk(:,:,1) = tms(:,:)
+         CALL prt_ctl(tab2d_1=qcmif  , clinfo1=' lim_thd: qcmif   : ', mask1=zmsk)
+         CALL prt_ctl(tab2d_1=zhicifp, clinfo1=' lim_thd: zhicifp : ')
+         WRITE(charout, FMT="('lim_thd: nbpb = ',I4)") nbpb
+         CALL prt_ctl_info(charout)
+      ENDIF
+      
+      
+      ! If there is no ice, do nothing. Otherwise, compute Top and Bottom accretion/ablation 
+      !------------------------------------------------------------------------------------ 
+
+      IF ( nbpb > 0) THEN
+         
+         !  put the variable in a 1-D array for thermodynamics process
+         CALL tab_2d_1d( nbpb, frld_1d    (1:nbpb)     , frld       , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, h_ice_1d   (1:nbpb)     , hicif      , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, h_snow_1d  (1:nbpb)     , hsnif      , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, sist_1d    (1:nbpb)     , sist       , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, tbif_1d    (1:nbpb , 1 ), tbif(:,:,1), jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, tbif_1d    (1:nbpb , 2 ), tbif(:,:,2), jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, tbif_1d    (1:nbpb , 3 ), tbif(:,:,3), jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, qsr_ice_1d (1:nbpb)     , qsr_ice    , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, fr1_i0_1d  (1:nbpb)     , fr1_i0     , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, fr2_i0_1d  (1:nbpb)     , fr2_i0     , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, qnsr_ice_1d(1:nbpb)     , qnsr_ice   , jpi, jpj, npb(1:nbpb) )
+#if ! defined key_coupled
+         CALL tab_2d_1d( nbpb, qla_ice_1d (1:nbpb)     , qla_ice    , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, dqla_ice_1d(1:nbpb)     , dqla_ice   , jpi, jpj, npb(1:nbpb) )
+#endif
+         CALL tab_2d_1d( nbpb, dqns_ice_1d(1:nbpb)     , dqns_ice   , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, tfu_1d     (1:nbpb)     , tfu        , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, sprecip_1d (1:nbpb)     , sprecip    , jpi, jpj, npb(1:nbpb) ) 
+         CALL tab_2d_1d( nbpb, fbif_1d    (1:nbpb)     , fbif       , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, thcm_1d    (1:nbpb)     , thcm       , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, qldif_1d   (1:nbpb)     , qldif      , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, qstbif_1d  (1:nbpb)     , qstoif     , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, rdmicif_1d (1:nbpb)     , rdmicif    , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, dmgwi_1d   (1:nbpb)     , dmgwi      , jpi, jpj, npb(1:nbpb) )
+         CALL tab_2d_1d( nbpb, qlbbq_1d   (1:nbpb)     , zqlbsbq    , jpi, jpj, npb(1:nbpb) )
+ 
+         CALL lim_thd_zdf( 1, nbpb )       !  compute ice growth
+         
+         !  back to the geographic grid.
+         CALL tab_1d_2d( nbpb, frld       , npb, frld_1d   (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, hicif      , npb, h_ice_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, hsnif      , npb, h_snow_1d (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, sist       , npb, sist_1d   (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, tbif(:,:,1), npb, tbif_1d   (1:nbpb , 1 ), jpi, jpj )   
+         CALL tab_1d_2d( nbpb, tbif(:,:,2), npb, tbif_1d   (1:nbpb , 2 ), jpi, jpj )   
+         CALL tab_1d_2d( nbpb, tbif(:,:,3), npb, tbif_1d   (1:nbpb , 3 ), jpi, jpj )   
+         CALL tab_1d_2d( nbpb, fscmbq     , npb, fscbq_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, ffltbif    , npb, fltbif_1d (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, fstric     , npb, fstbif_1d (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, qldif      , npb, qldif_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, qfvbq      , npb, qfvbq_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, qstoif     , npb, qstbif_1d (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, rdmicif    , npb, rdmicif_1d(1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, dmgwi      , npb, dmgwi_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, rdmsnif    , npb, rdmsnif_1d(1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, rdvosif    , npb, dvsbq_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, rdvobif    , npb, dvbbq_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, fdvolif    , npb, dvlbq_1d  (1:nbpb)     , jpi, jpj )
+         CALL tab_1d_2d( nbpb, rdvonif    , npb, dvnbq_1d  (1:nbpb)     , jpi, jpj ) 
+
+ 
+      ENDIF
+
+      
+      !      Up-date sea ice thickness.
+      !---------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            phicif(ji,jj) = hicif(ji,jj)  
+            hicif(ji,jj)  = hicif(ji,jj) *  ( zone -  MAX( zzero, SIGN( zone, - ( 1.0 - frld(ji,jj) ) ) ) )
+         END DO
+      END DO
+
+      
+      !      Tricky trick : add 2 to frld in the Southern Hemisphere.
+      !----------------------------------------------------------
+      IF( fcor(1,1) < 0.e0 ) THEN
+         DO jj = 1, njeqm1
+            DO ji = 1, jpi
+               frld(ji,jj) = frld(ji,jj) + 2.0
+            END DO
+         END DO
+      ENDIF
+      
+      
+      !     Select points for lateral accretion (this occurs when heat exchange
+      !     between ice and ocean is negative; ocean losing heat) 
+      !-----------------------------------------------------------------
+      nbpac = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+!i yes!     IF ( ( qcmif(ji,jj) - qldif(ji,jj) ) > 0.e0 ) THEN
+            IF ( tms(ji,jj) * ( qcmif(ji,jj) - qldif(ji,jj) ) > 0.e0 ) THEN
+               nbpac = nbpac + 1
+               npac( nbpac ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+      
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=phicif, clinfo1=' lim_thd: phicif  : ', tab2d_2=hicif, clinfo2=' hicif : ')
+         WRITE(charout, FMT="('lim_thd: nbpac = ',I4)") nbpac
+         CALL prt_ctl_info(charout)
+      ENDIF
+
+      
+      !
+      !     If ocean gains heat do nothing ; otherwise, one performs lateral accretion
+      !--------------------------------------------------------------------------------
+
+      IF( nbpac > 0 ) THEN
+         
+         !...Put the variable in a 1-D array for lateral accretion
+         CALL tab_2d_1d( nbpac, frld_1d   (1:nbpac)     , frld       , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, h_snow_1d (1:nbpac)     , hsnif      , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, h_ice_1d  (1:nbpac)     , hicif      , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, tbif_1d   (1:nbpac , 1 ), tbif(:,:,1), jpi, jpj, npac(1:nbpac) )   
+         CALL tab_2d_1d( nbpac, tbif_1d   (1:nbpac , 2 ), tbif(:,:,2), jpi, jpj, npac(1:nbpac) )   
+         CALL tab_2d_1d( nbpac, tbif_1d   (1:nbpac , 3 ), tbif(:,:,3), jpi, jpj, npac(1:nbpac) )   
+         CALL tab_2d_1d( nbpac, qldif_1d  (1:nbpac)     , qldif      , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, qcmif_1d  (1:nbpac)     , qcmif      , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, qstbif_1d (1:nbpac)     , qstoif     , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, rdmicif_1d(1:nbpac)     , rdmicif    , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, dvlbq_1d  (1:nbpac)     , fdvolif    , jpi, jpj, npac(1:nbpac) )
+         CALL tab_2d_1d( nbpac, tfu_1d    (1:nbpac)     , tfu        , jpi, jpj, npac(1:nbpac) )
+        
+         !  call lateral accretion routine.
+         CALL lim_thd_lac( 1 , nbpac )
+         
+         !   back to the geographic grid
+         CALL tab_1d_2d( nbpac, frld       , npac(1:nbpac), frld_1d   (1:nbpac)     , jpi, jpj )
+         CALL tab_1d_2d( nbpac, hsnif      , npac(1:nbpac), h_snow_1d (1:nbpac)     , jpi, jpj )
+         CALL tab_1d_2d( nbpac, hicif      , npac(1:nbpac), h_ice_1d  (1:nbpac)     , jpi, jpj )
+         CALL tab_1d_2d( nbpac, tbif(:,:,1), npac(1:nbpac), tbif_1d   (1:nbpac , 1 ), jpi, jpj )
+         CALL tab_1d_2d( nbpac, tbif(:,:,2), npac(1:nbpac), tbif_1d   (1:nbpac , 2 ), jpi, jpj )
+         CALL tab_1d_2d( nbpac, tbif(:,:,3), npac(1:nbpac), tbif_1d   (1:nbpac , 3 ), jpi, jpj )
+         CALL tab_1d_2d( nbpac, qstoif     , npac(1:nbpac), qstbif_1d (1:nbpac)     , jpi, jpj )
+         CALL tab_1d_2d( nbpac, rdmicif    , npac(1:nbpac), rdmicif_1d(1:nbpac)     , jpi, jpj )
+         CALL tab_1d_2d( nbpac, fdvolif    , npac(1:nbpac), dvlbq_1d  (1:nbpac)     , jpi, jpj )
+        
+      ENDIF
+       
+       
+      !      Recover frld values between 0 and 1 in the Southern Hemisphere (tricky trick)
+      !      Update daily thermodynamic ice production.    
+      !------------------------------------------------------------------------------
+       
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            frld  (ji,jj) = MIN( frld(ji,jj), ABS( frld(ji,jj) - 2.0 ) )
+            hicifp(ji,jj) =  hicif(ji,jj) * ( 1.0 - frld(ji,jj) ) - zhicifp(ji,jj) + hicifp(ji,jj)
+         END DO
+      END DO
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl_info(' lim_thd  end  ')
+         CALL prt_ctl(tab2d_1=hicif , clinfo1=' lim_thd: hicif   : ', tab2d_2=hsnif , clinfo2=' hsnif  : ')
+         CALL prt_ctl(tab2d_1=frld  , clinfo1=' lim_thd: frld    : ', tab2d_2=hicifp, clinfo2=' hicifp : ')
+         CALL prt_ctl(tab2d_1=phicif, clinfo1=' lim_thd: phicif  : ', tab2d_2=pfrld , clinfo2=' pfrld  : ')
+         CALL prt_ctl(tab2d_1=sist  , clinfo1=' lim_thd: sist    : ')
+         CALL prt_ctl(tab2d_1=tbif(:,:,1), clinfo1=' lim_thd: tbif 1  : ')
+         CALL prt_ctl(tab2d_1=tbif(:,:,2), clinfo1=' lim_thd: tbif 2  : ')
+         CALL prt_ctl(tab2d_1=tbif(:,:,3), clinfo1=' lim_thd: tbif 3  : ')
+         CALL prt_ctl(tab2d_1=fdtcn , clinfo1=' lim_thd: fdtcn   : ', tab2d_2=qdtcn , clinfo2=' qdtcn  : ')
+         CALL prt_ctl(tab2d_1=qstoif, clinfo1=' lim_thd: qstoif  : ', tab2d_2=fsbbq , clinfo2=' fsbbq  : ')
+      ENDIF
+
+    END SUBROUTINE lim_thd
+
+
+    SUBROUTINE lim_thd_init
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_thd_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters linked to the ice 
+      !!      thermodynamics
+      !!
+      !! ** Method  :   Read the namicethd namelist and check the ice-thermo
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicether
+      !!
+      !! history :
+      !!  8.5  ! 03-08 (C. Ethe) original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicethd/ hmelt , hiccrit, hicmin, hiclim, amax  ,        &
+         &                swiqst, sbeta  , parlat, hakspl, hibspl, exld,  &
+         &                hakdif, hnzst  , thth  , parsub, alphs
+      !!-------------------------------------------------------------------
+      
+
+      ! Define the initial parameters
+      ! -------------------------
+      REWIND( numnam_ice )
+      READ  ( numnam_ice , namicethd )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'lim_thd_init : ice parameters for ice thermodynamic computation '
+         WRITE(numout,*)'~~~~~~~~~~~~'
+         WRITE(numout,*)'       maximum melting at the bottom                           hmelt        = ', hmelt
+         WRITE(numout,*)'       ice thick. for lateral accretion in NH (SH)             hiccrit(1/2) = ', hiccrit
+         WRITE(numout,*)'       ice thick. corr. to max. energy stored in brine pocket  hicmin       = ', hicmin  
+         WRITE(numout,*)'       minimum ice thickness                                   hiclim       = ', hiclim 
+         WRITE(numout,*)'       maximum lead fraction                                   amax         = ', amax 
+         WRITE(numout,*)'       energy stored in brine pocket (=1) or not (=0)	  swiqst       = ', swiqst 
+         WRITE(numout,*)'       numerical carac. of the scheme for diffusion in ice '
+         WRITE(numout,*)'       Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)   sbeta        = ', sbeta
+         WRITE(numout,*)'       percentage of energy used for lateral ablation          parlat       = ', parlat
+         WRITE(numout,*)'       slope of distr. for Hakkinen-Mellor lateral melting     hakspl       = ', hakspl  
+         WRITE(numout,*)'       slope of distribution for Hibler lateral melting        hibspl       = ', hibspl
+         WRITE(numout,*)'       exponent for leads-closure rate                         exld         = ', exld
+         WRITE(numout,*)'       coefficient for diffusions of ice and snow              hakdif       = ', hakdif
+         WRITE(numout,*)'       threshold thick. for comp. of eq. thermal conductivity  zhth         = ', thth 
+         WRITE(numout,*)'       thickness of the surf. layer in temp. computation       hnzst        = ', hnzst
+         WRITE(numout,*)'       switch for snow sublimation  (=1) or not (=0)           parsub       = ', parsub  
+         WRITE(numout,*)'       coefficient for snow density when snow ice formation    alphs        = ', alphs
+      ENDIF
+            
+      uscomi = 1.0 / ( 1.0 - amax )   ! inverse of minimum lead fraction
+      rcdsn = hakdif * rcdsn 
+      rcdic = hakdif * rcdic
+      
+      IF ( ( hsndif > 100.e0 ) .OR. ( hicdif > 100.e0 ) ) THEN
+         cnscg = 0.e0
+      ELSE
+         cnscg = rcpsn / rcpic   ! ratio  rcpsn/rcpic
+      ENDIF
+ 
+   END SUBROUTINE lim_thd_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module           NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_thd         ! Dummy routine
+   END SUBROUTINE lim_thd
+#endif
+
+   !!======================================================================
+END MODULE limthd
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_lac.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_lac.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_lac.F90	(revision 4536)
@@ -0,0 +1,232 @@
+MODULE limthd_lac
+#if defined key_ice_lim
+   !!======================================================================
+   !!                       ***  MODULE limthd_lac   ***
+   !!                lateral thermodynamic growth of the ice 
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   lim_lat_acr    : lateral accretion of ice
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE phycst
+   USE ice_oce         ! ice variables
+   USE thd_ice
+   USE iceini
+   USE limistate 
+     
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_lac     ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1.e-20  ,  &
+      epsi13 = 1.e-13  ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+    
+   SUBROUTINE lim_thd_lac( kideb, kiut )
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE lim_thd_lac  ***
+      !!  
+      !! ** Purpose : Computation of the evolution of the ice thickness and 
+      !!      concentration as a function of the heat balance in the leads.
+      !!      It is only used for lateral accretion
+      !!       
+      !! ** Method  : Ice is formed in the open water when ocean lose heat
+      !!      (heat budget of open water Bl is negative) .
+      !!      Computation of the increase of 1-A (ice concentration) fol-
+      !!      lowing the law :
+      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
+      !!       where - h0 is the thickness of ice created in the lead
+      !!             - a is a minimum fraction for leads
+      !!             - F is a monotonic non-increasing function defined as:
+      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
+      !!             - exld is the exponent closure rate (=2 default val.)
+      !! 
+      !! ** Action : - Adjustment of snow and ice thicknesses and heat
+      !!                content in brine pockets
+      !!             - Updating ice internal temperature
+      !!             - Computation of variation of ice volume and mass
+      !!             - Computation of frldb after lateral accretion and 
+      !!               update h_snow_1d, h_ice_1d and tbif_1d(:,:)      
+      !! 
+      !! ** References :
+      !!      M. Maqueda, 1995, PhD Thesis, Univesidad Complutense Madrid
+      !!      Fichefet T. and M. Maqueda 1997, J. Geo. Res., 102(C6), 
+      !!                                                12609 -12646   
+      !! History :
+      !!   1.0  !  01-04 (LIM)  original code
+      !!   2.0  !  02-08 (C. Ethe, G. Madec)  F90, mpp
+      !!-------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT(IN)::  &
+         kideb          ,   &  ! start point on which the the computation is applied
+         kiut                  ! end point on which the the computation is applied
+
+      !! * Local variables
+      INTEGER ::            &
+         ji             ,   &  !  dummy loop indices
+         iicefr         ,   &  !  1 = existing ice ; 0 = no ice
+         iiceform       ,   &  !  1 = ice formed   ; 0 = no ice formed
+         ihemis                !  dummy indice
+      REAL(wp), DIMENSION(jpij) :: &
+         zqbgow           ,  &  !  heat budget of the open water (negative)
+         zfrl_old         ,  &  !  previous sea/ice fraction
+         zhice_old        ,  &  !  previous ice thickness
+         zhice0           ,  &  !  thickness of newly formed ice in leads
+         zfrlmin          ,  &  !  minimum fraction for leads
+         zdhicbot               !  part of thickness of newly formed ice in leads which 
+                                !  has been already used in transport for example
+      REAL(wp)  ::  &
+         zhemis           ,  &  !  hemisphere (0 = North, 1 = South)
+         zhicenew         ,  &  !  new ice thickness
+         zholds2          ,  &  !  ratio of previous ice thickness and 2 
+         zhnews2          ,  &  !  ratio of new ice thickness and 2 
+         zfrlnew          ,  &  !  new sea/ice fraction
+         zfrld            ,  &  !  ratio of sea/ice fraction and minimum fraction for leads
+         zfrrate          ,  &  !  leads-closure rate
+         zdfrl                  !  sea-ice fraction increment
+      REAL(wp)  ::  &
+         zdh1 , zdh2 , zdh3 , zdh4, zdh5   , &   ! tempory scalars
+         ztint , zta1 , zta2 , zta3 , zta4 , &
+         zah, zalpha , zbeta
+      !!---------------------------------------------------------------------      
+                   
+      !--------------------------------------------------------------
+      !   Computation of the heat budget of the open water (negative)
+      !--------------------------------------------------------------
+      
+      DO ji = kideb , kiut      
+         zqbgow(ji) = qldif_1d(ji) - qcmif_1d(ji)
+      END DO
+      
+      !-----------------------------------------------------------------
+      !   Taking the appropriate values for the corresponding hemisphere
+      !-----------------------------------------------------------------
+      DO ji = kideb , kiut
+         zhemis       = MAX( zzero , SIGN( zone , frld_1d(ji) - 2.0 ) ) 
+         ihemis       = INT( 1 + zhemis )
+         zhice0  (ji) = hiccrit( ihemis ) 
+         zfrlmin (ji) = acrit  ( ihemis )   
+         frld_1d (ji) = frld_1d(ji) - 2.0 * zhemis
+         zfrl_old(ji) = frld_1d(ji)
+      END DO
+      
+      !-------------------------------------------------------------------
+      !     Lateral Accretion (modification of the fraction of open water)
+      !     The ice formed in the leads has always a thickness zhice0, but
+      !     only a fraction zfrrate of the ice formed contributes to the 
+      !     increase of the ice fraction. The remaining part (1-zfrrate)
+      !     is rather assumed to lead to an increase in the thickness of the
+      !     pre-existing ice (transport for example). 
+      !     Morales Maqueda, 1995 - Fichefet and Morales Maqueda, 1997
+      !---------------------------------------------------------------------
+      
+      !CDIR NOVERRCHK
+      DO ji = kideb , kiut
+         iicefr       = 1 - MAX( 0, INT( SIGN( 1.5 * zone , zfrl_old(ji) - 1.0 + epsi13 ) ) )
+         !---computation of the leads-closure rate
+         zfrld        = MIN( zone , ( 1.0 - frld_1d(ji) ) / ( 1.0 - zfrlmin(ji) ) )
+         zfrrate      = ( 1.0 - zfrld**exld )**( 1.0 / exld )
+         !--computation of the sea-ice fraction increment and the new fraction 
+         zdfrl        = ( zfrrate / zhice0(ji) )  * ( zqbgow(ji) / xlic )
+         zfrlnew      = zfrl_old(ji) + zdfrl
+         !--update the sea-ice fraction 
+         frld_1d   (ji) = MAX( zfrlnew , zfrlmin(ji) )
+         !--computation of the remaining part of ice thickness which has been already used
+         zdhicbot(ji) =  ( frld_1d(ji) - zfrlnew ) * zhice0(ji) / ( 1.0 - zfrlmin(ji) ) & 
+                      -  (  ( 1.0 - zfrrate ) / ( 1.0 - frld_1d(ji) ) )  * ( zqbgow(ji) / xlic ) 
+      END DO
+ 
+      !----------------------------------------------------------------------------------------
+      !      Ajustement of snow and ice thicknesses and updating the total heat stored in brine pockets  
+      !      The thickness of newly formed ice is averaged with that of the pre-existing
+      !         (1-Anew) * hinew = (1-Aold) * hiold + ((1-Anew)-(1-Aold)) * h0
+      !      Snow is distributed over the new ice-covered area 
+      !         (1-Anew) * hsnew = (1-Aold) * hsold            
+      !--------------------------------------------------------------------------------------------
+      
+      DO ji = kideb , kiut
+         iicefr       = 1 - MAX( 0, INT( SIGN( 1.5 * zone , zfrl_old(ji) - 1.0 + epsi13 ) ) )
+         zhice_old(ji) = h_ice_1d(ji)
+         zhicenew      = iicefr * zhice_old(ji) + ( 1 - iicefr ) * zhice0(ji)
+         zalpha        = ( 1. - zfrl_old(ji) ) / ( 1.- frld_1d(ji) )
+         h_snow_1d(ji) = zalpha * h_snow_1d(ji)
+         h_ice_1d (ji) = zalpha * zhicenew + ( 1.0 - zalpha ) * zhice0(ji)
+         qstbif_1d(ji) = zalpha * qstbif_1d(ji) 
+      END DO
+      
+      !-------------------------------------------------------
+      !   Ajustement of ice internal temperatures
+      !-------------------------------------------------------
+      
+      DO ji = kideb , kiut
+         iicefr      = 1 - MAX( 0, INT( SIGN( 1.5 * zone , zfrl_old(ji) - 1.0 + epsi13 ) ) )
+         iiceform    = 1 - MAX( 0 ,INT( SIGN( 1.5 * zone , zhice0(ji) - h_ice_1d(ji) ) ) )
+         zholds2     = zhice_old(ji)/ 2.
+         zhnews2     = h_ice_1d(ji) / 2.
+         zdh1        = MAX( zzero ,  zhice_old(ji)   - zhnews2 )
+         zdh2        = MAX( zzero , -zhice_old(ji)   + zhnews2 )
+         zdh3        = MAX( zzero ,  h_ice_1d(ji) - zholds2 )
+         zdh4        = MAX( zzero , -h_ice_1d(ji) + zholds2 )
+         zdh5        = MAX( zzero , zhice0(ji)      - zholds2 )
+         ztint       =       iiceform   * (  ( zholds2 - zdh3 ) * tbif_1d(ji,3) + zdh4 * tbif_1d(ji,2) )      &
+            &                           / MAX( epsi20 , h_ice_1d(ji) - zhice0(ji) )                           &
+            &                 + ( 1 - iiceform ) * tfu_1d(ji)
+         zta1        = iicefr * ( 1.  - zfrl_old(ji) ) * tbif_1d(ji,2) 
+         zta2        = iicefr * ( 1.  - zfrl_old(ji) ) * tbif_1d(ji,3)
+         zta3        = iicefr * ( 1.  - zfrl_old(ji) ) * ztint
+         zta4        = ( zfrl_old(ji) - frld_1d   (ji) ) * tfu_1d(ji)
+         zah         = ( 1. - frld_1d(ji) ) * zhnews2 
+
+         tbif_1d(ji,2) = (  MIN( zhnews2 , zholds2 )                                              * zta1   &
+            &          + ( 1 - iiceform ) * ( zholds2 - zdh1 )                                    * zta2   &
+            &          + ( iiceform * ( zhnews2 - zhice0(ji) + zdh5 ) + ( 1 - iiceform ) * zdh2 ) * zta3   & 
+            &          + MIN ( zhnews2 , zhice0(ji) )                                             * zta4   &
+            &          ) / zah
+         
+         tbif_1d(ji,3) =     (  iiceform * ( zhnews2 - zdh3 )                                          * zta1  &
+            &              + ( iiceform * zdh3 + ( 1 - iiceform ) * zdh1 )                             * zta2  &
+            &              + ( iiceform * ( zhnews2 - zdh5 ) + ( 1 - iiceform ) * ( zhnews2 - zdh1 ) ) * zta3  & 
+            &              + ( iiceform * zdh5 + ( 1 - iiceform ) * zhnews2 )                          * zta4  &
+            &            ) / zah
+         !---removing the remaining part of ice formed which has been already used
+         zbeta         = h_ice_1d(ji) / ( h_ice_1d(ji) + zdhicbot(ji) )
+         h_ice_1d(ji)  = h_ice_1d(ji) + zdhicbot(ji)
+         tbif_1d (ji,2)= zbeta * tbif_1d(ji,2) + ( 1.0 - zbeta ) * tbif_1d(ji,3)
+         tbif_1d (ji,3)= ( 2. * zbeta - 1.0 ) * tbif_1d(ji,3) + ( 2. * zdhicbot(ji) / h_ice_1d(ji) ) * tfu_1d(ji)
+         
+      END DO
+      
+      !-------------------------------------------------------------
+      !    Computation of variation of ice volume and ice mass 
+      !           Vold = (1-Aold) * hiold ; Vnew = (1-Anew) * hinew
+      !           dV = Vnew - Vold
+      !-------------------------------------------------------------
+      
+      DO ji = kideb , kiut
+         dvlbq_1d  (ji) = ( 1. - frld_1d(ji) ) * h_ice_1d(ji) - ( 1. - zfrl_old(ji) ) * zhice_old(ji)
+         rdmicif_1d(ji) = rdmicif_1d(ji) + rhoic * dvlbq_1d(ji)
+      END DO
+      
+   END SUBROUTINE lim_thd_lac
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_lac   ***
+   !!                           no sea ice model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_lac           ! Empty routine
+   END SUBROUTINE lim_thd_lac
+#endif
+END MODULE limthd_lac
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_zdf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_zdf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limthd_zdf.F90	(revision 4536)
@@ -0,0 +1,814 @@
+MODULE limthd_zdf
+   !!======================================================================
+   !!                       ***  MODULE limthd_zdf ***
+   !!                thermodynamic growth and decay of the ice 
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_thd_zdf  : vertical accr./abl. and lateral ablation of sea ice
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE phycst           ! ???
+   USE ice_oce          ! ice variables
+   USE thd_ice
+   USE iceini
+   USE limistate
+   USE in_out_manager
+      
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_thd_zdf        ! called by lim_thd
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi20 = 1.e-20  ,  &
+      epsi13 = 1.e-13  ,  &
+      zzero  = 0.e0    ,  &
+      zone   = 1.e0
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE lim_thd_zdf( kideb , kiut )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE lim_thd_zdf  ***
+      !!              
+      !! ** Purpose : This routine determines the time evolution of snow 
+      !!      and sea-ice thicknesses, concentration and heat content 
+      !!      due to the vertical and lateral thermodynamic accretion-
+      !!      ablation processes. One only treats the case of lat. abl.
+      !!      For lateral accretion, see routine lim_lat_accr 
+      !! 
+      !! ** Method  : The representation of vertical growth and decay of 
+      !!      the sea-ice model is based upon the diffusion of heat 
+      !!      through the external and internal boundaries of a 
+      !!      three-layer system (two layers of ice and one layer and 
+      !!      one layer of snow, if present, on top of the ice).
+      !! 
+      !! ** Action  : - Calculation of some intermediates variables
+      !!              - Calculation of surface temperature
+      !!              - Calculation of available heat for surface ablation
+      !!              - Calculation of the changes in internal temperature 
+      !!                of the three-layer system, due to vertical diffusion 
+      !!                processes
+      !!              - Performs surface ablation and bottom accretion-ablation
+      !!              - Performs snow-ice formation
+      !!              - Performs lateral ablation
+      !!
+      !! References :
+      !!   Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
+      !!   Fichefet T. and M. Maqueda 1999, Clim. Dyn, 15(4), 251-268  
+      !!
+      !! History :
+      !!   original    : 01-04 (LIM)
+      !!   addition    : 02-08 (C. Ethe, G. Madec)
+      !!------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT (in) ::  &
+         kideb ,  &  ! Start point on which the  the computation is applied
+         kiut        ! End point on which the  the computation is applied
+
+      !! * Local variables
+      INTEGER ::   ji       ! dummy loop indices
+
+      REAL(wp) , DIMENSION(jpij,2) ::  &
+         zqcmlt        ! energy due to surface( /1 ) and bottom melting( /2 )
+
+      REAL(wp), DIMENSION(jpij) ::  &
+         ztsmlt      &    ! snow/ice surface melting temperature
+         ,ztbif      &    ! int. temp. at the mid-point of the 1st layer of the snow/ice sys. 
+         ,zksn       &    ! effective conductivity of snow
+         ,zkic       &    ! effective conductivity of ice
+         ,zksndh     &    ! thermal cond. at the mid-point of the 1st layer of the snow/ice sys. 
+         , zfcsu     &    ! conductive heat flux at the surface of the snow/ice system 
+         , zfcsudt   &    ! = zfcsu * dt
+         , zi0       &    ! frac. of the net SW rad. which is not absorbed at the surface
+         , z1mi0     &    ! fraction of the net SW radiation absorbed at the surface
+         , zqmax     &    ! maximum energy stored in brine pockets
+         , zrcpdt    &    ! h_su*rho_su*cp_su/dt(h_su being the thick. of surf. layer)
+         , zts_old   &    ! previous surface temperature
+         , zidsn , z1midsn , zidsnic ! tempory variables
+
+      REAL(wp), DIMENSION(jpij) :: &
+          zfnet       &  ! net heat flux at the top surface( incl. conductive heat flux)
+          , zsprecip  &    ! snow accumulation
+          , zhsnw_old &    ! previous snow thickness
+          , zdhictop  &    ! change in ice thickness due to top surf ablation/accretion
+          , zdhicbot  &    ! change in ice thickness due to bottom surf abl/acc
+          , zqsup     &    ! energy transmitted to ocean (coming from top surf abl/acc)
+          , zqocea    &    ! energy transmitted to ocean (coming from bottom sur abl/acc)
+          , zfrl_old  &    ! previous sea/ice fraction
+          , zfrld_1d    &    ! new sea/ice fraction
+          , zep            ! internal temperature of the 2nd layer of the snow/ice system
+
+       REAL(wp), DIMENSION(3) :: & 
+          zplediag  &    ! principle diagonal, subdiag. and supdiag. of the 
+          , zsubdiag  &    ! tri-diagonal matrix coming from the computation
+          , zsupdiag  &    ! of the temperatures inside the snow-ice system
+          , zsmbr          ! second member
+
+       REAL(wp) :: & 
+          zhsu     &     ! thickness of surface layer
+          , zhe      &     ! effective thickness for compu. of equ. thermal conductivity
+          , zheshth  &     ! = zhe / thth
+          , zghe     &     ! correction factor of the thermal conductivity
+          , zumsb    &     ! parameter for numerical method to solve heat-diffusion eq.
+          , zkhsn    &     ! conductivity at the snow layer
+          , zkhic    &     ! conductivity at the ice layers
+          , zkint    &     ! equivalent conductivity at the snow-ice interface
+          , zkhsnint &     ! = zkint*dt / (hsn*rhosn*cpsn)  
+          , zkhicint &     ! = 2*zkint*dt / (hic*rhoic*cpic)
+          , zpiv1 , zpiv2  &       ! tempory scalars used to solve the tri-diagonal system
+          , zb2 , zd2 , zb3 , zd3 &
+          , ztint          ! equivalent temperature at the snow-ice interface
+
+       REAL(wp) :: & 
+          zexp      &     ! exponential function of the ice thickness
+          , zfsab     &     ! part of solar radiation stored in brine pockets
+          , zfts      &     ! value of energy balance function when the temp. equal surf. temp.
+          , zdfts     &     ! value of derivative of ztfs when the temp. equal surf. temp.
+          , zdts      &     ! surface temperature increment
+          , zqsnw_mlt &     ! energy needed to melt snow
+          , zdhsmlt   &     ! change in snow thickness due to melt
+          , zhsn      &     ! snow thickness (previous+accumulation-melt)
+          , zqsn_mlt_rem &  ! remaining heat coming from snow melting
+          , zqice_top_mlt & ! energy used to melt ice at top surface
+          , zdhssub      &  ! change in snow thick. due to sublimation or evaporation
+          , zdhisub      &  ! change in ice thick. due to sublimation or evaporation    
+          , zdhsn        &  ! snow ice thickness increment
+          , zdtsn        &  ! snow internal temp. increment
+          , zdtic        &  ! ice internal temp. increment
+          , zqnes          ! conductive energy due to ice melting in the first ice layer
+
+       REAL(wp) :: & 
+          ztbot     &      ! temperature at the bottom surface
+          , zfcbot    &      ! conductive heat flux at bottom surface
+          , zqice_bot &      ! energy used for bottom melting/growing
+          , zqice_bot_mlt &  ! energy used for bottom melting
+          , zqstbif_bot  &  ! part of energy stored in brine pockets used for bottom melting
+          , zqstbif_old  &  ! tempory var. for zqstbif_bot
+          , zdhicmlt      &  ! change in ice thickness due to bottom melting
+          , zdhicm        &  ! change in ice thickness var. 
+          , zdhsnm        &  ! change in snow thickness var. 
+          , zhsnfi        &  ! snow thickness var. 
+          , zc1, zpc1, zc2, zpc2, zp1, zp2 & ! tempory variables
+          , ztb2, ztb3
+
+       REAL(wp) :: & 
+          zdrmh         &   ! change in snow/ice thick. after snow-ice formation
+          , zhicnew       &   ! new ice thickness
+          , zhsnnew       &   ! new snow thickness
+          , zquot , ztneq &   ! tempory temp. variables
+          , zqice, zqicetot & ! total heat inside the snow/ice system
+          , zdfrl         &   ! change in ice concentration
+          , zdvsnvol      &   ! change in snow volume
+          , zdrfrl1, zdrfrl2 &  ! tempory scalars
+          , zihsn, zidhb, zihic, zihe, zihq, ziexp, ziqf, zihnf, zibmlt, ziqr, zihgnew, zind
+       !!----------------------------------------------------------------------
+
+       !-----------------------------------------------------------------------
+       !  1. Boundaries conditions for snow/ice system internal temperature
+       !       - If tbif_1d(ji,1) > rt0_snow, tbif_1d(ji,1) = rt0_snow 
+       !       - If tbif_1d(ji,2/3) > rt0_ice, tbif_1d(ji,2/3) = rt0_ice 
+       !     Computation of energies due to surface and bottom melting 
+       !-----------------------------------------------------------------------
+       
+       
+       DO ji = kideb , kiut
+          zihsn = MAX( zzero , SIGN( zone , hsndif - h_snow_1d(ji) ) )
+          zihic = MAX( zzero , SIGN( zone , hicdif - h_ice_1d(ji) ) )
+          !--computation of energy due to surface melting
+          zqcmlt(ji,1) = ( MAX ( zzero ,  &
+             &                   rcpsn * h_snow_1d(ji) * ( tbif_1d(ji,1) - rt0_snow ) ) ) * ( 1.0 - zihsn )
+          !--computation of energy due to bottom melting
+          zqcmlt(ji,2) = ( MAX( zzero , &
+             &                  rcpic * ( tbif_1d(ji,2) - rt0_ice ) * ( h_ice_1d(ji) / 2. ) ) &
+             &           + MAX( zzero , &
+             &                  rcpic * ( tbif_1d(ji,3) - rt0_ice ) * ( h_ice_1d(ji) / 2. ) ) &
+             &           ) * ( 1.0 - zihic  )
+          !--limitation of  snow/ice system internal temperature
+          tbif_1d(ji,1)   = MIN( rt0_snow, tbif_1d(ji,1) )
+          tbif_1d(ji,2)   = MIN( rt0_ice , tbif_1d(ji,2) )
+          tbif_1d(ji,3)   = MIN( rt0_ice , tbif_1d(ji,3) )
+       END DO
+
+
+       !-------------------------------------------
+       !  2. Calculate some intermediate variables.  
+       !-------------------------------------------
+       
+       ! initialisation of the thickness of surface layer
+       zhsu = hnzst  
+
+       DO ji = kideb , kiut
+          zind   = MAX( zzero , SIGN( zone , zhsu - h_snow_1d(ji) ) )
+          zihsn  = MAX( zzero , SIGN( zone , hsndif - h_snow_1d(ji) ) )
+          zihsn  = MAX( zihsn , zind )
+          zihic  = MAX( zzero , sign( zone , hicdif - h_ice_1d(ji) ) )
+          !     2.1. Computation of surface melting temperature
+          !----------------------------------------------------
+          zind  = MAX( zzero , SIGN( zone , -h_snow_1d(ji) ) )
+          ztsmlt(ji) = ( 1.0 - zind ) * rt0_snow + zind * rt0_ice
+          !
+          !     2.2. Effective conductivity of snow and ice
+          !-----------------------------------------------
+
+          !---computation of the correction factor on the thermal conductivity
+          !-- (Morales Maqueda, 1995 ; Fichefet and Morales Maqueda, 1997)
+          zhe      =  ( rcdsn / ( rcdsn + rcdic ) ) * h_ice_1d(ji)   &
+             &     + ( rcdic / ( rcdsn + rcdic ) ) * h_snow_1d(ji) 
+          zihe     = MAX( zzero , SIGN( zone , 2.0 * zhe - thth ) )
+          zheshth  = zhe / thth
+          zghe     = ( 1.0 - zihe ) * zheshth * ( 2.0 - zheshth )   &
+             &     +         zihe   * 0.5 * ( 1.5 + LOG( 2.0 * zheshth ) )
+#if defined key_lim_cp3
+          zghe = 1.0
+#endif 
+
+          !---effective conductivities 
+          zksn(ji)  = zghe * rcdsn  
+          zkic(ji)  = zghe * rcdic
+
+          !
+          !     2.3. Computation of the conductive heat flux from the snow/ice 
+          !          system interior toward the top surface
+          !------------------------------------------------------------------
+
+          !---Thermal conductivity at the mid-point of the first snow/ice system layer
+          zksndh(ji) =   ( ( 1.0 - zihsn ) * 2.0 * zksn(ji) + zihsn * 4.0 * zkic(ji) )   &
+             &         / ( ( 1.0 - zihsn ) *  h_snow_1d(ji)                              &
+             &           +        zihsn   *  ( ( 1.0 + 3.0 * zihic ) * h_ice_1d(ji)      &
+             &           + 4.0 * zkic(ji)/zksn(ji) * h_snow_1d(ji) ) )
+
+          !---internal temperature at the mid-point of the first snow/ice system layer
+          ztbif(ji)  = ( 1.0 - zihsn ) * tbif_1d(ji,1)                       &
+             &       +         zihsn   * ( ( 1.0 - zihic ) * tbif_1d(ji,2)   &
+             &       +         zihic   * tfu_1d(ji)   )
+          !---conductive heat flux 
+          zfcsu(ji) = zksndh(ji) * ( ztbif(ji) - sist_1d(ji) )
+
+       END DO
+
+       !--------------------------------------------------------------------
+       !  3. Calculate : 
+       !     - fstbif_1d, part of solar radiation absorbing inside the ice
+       !       assuming an exponential absorption (Grenfell and Maykut, 1977)
+       !     - zqmax,  maximum energy stored in brine pockets
+       !     - qstbif_1d, total energy stored in brine pockets (updating)
+       !-------------------------------------------------------------------
+
+
+       DO ji = kideb , kiut
+          zihsn  = MAX( zzero , SIGN (zone , -h_snow_1d(ji) ) )
+          zihic  = MAX( zzero , 1.0 - ( h_ice_1d(ji) / zhsu ) )     
+          zind   = MAX( zzero , SIGN (zone , hicdif - h_ice_1d(ji) ) )
+          !--Computation of the fraction of the net shortwave radiation which
+          !--penetrates inside the ice cover ( See Forcat)
+          zi0(ji)  = zihsn * ( fr1_i0_1d(ji) + zihic * fr2_i0_1d(ji) )
+          zexp     = MIN( zone , EXP( -1.5 * ( h_ice_1d(ji) - zhsu ) ) )
+          fstbif_1d(ji) = zi0(ji) * qsr_ice_1d(ji) * zexp
+          !--Computation of maximum energy stored in brine pockets zqmax and update
+          !--the total energy stored in brine pockets, if less than zqmax
+          zqmax(ji) = MAX( zzero , 0.5 * xlic * ( h_ice_1d(ji) - hicmin ) )
+          zfsab   = zi0(ji) * qsr_ice_1d(ji) * ( 1.0 - zexp )
+          zihq    = ( 1.0 - zind ) * MAX(zzero, SIGN( zone , qstbif_1d(ji) - zqmax(ji) ) ) &
+             &    +         zind   * zone
+          qstbif_1d(ji) = ( qstbif_1d(ji) + ( 1.0 - zihq ) * zfsab * rdt_ice ) * swiqst
+          !--fraction of shortwave radiation absorbed at surface
+          ziexp = zihq * zexp + ( 1.0 - zihq ) * ( swiqst + ( 1.0 - swiqst ) * zexp )
+          z1mi0(ji) = 1.0 - zi0(ji) * ziexp
+       END DO
+
+
+       !--------------------------------------------------------------------------------
+       !  4. Computation of the surface temperature : determined by considering the 
+       !     budget of a thin layer of thick. zhsu at the top surface (H. Grenier, 1995) 
+       !     and based on a surface energy balance : 
+       !     hsu * rcp * dT/dt = Fsr + Fnsr(T) + Fcs(T),
+       !     where - Fsr is the net absorbed solar radiation, 
+       !           - Fnsr is the total non solar radiation (incoming and outgoing long-wave,
+       !             sensible and latent heat fluxes)
+       !           - Fcs the conductive heat flux at the top of surface
+       !------------------------------------------------------------------------------
+
+       !     4.1. Computation of intermediate values
+       !---------------------------------------------
+       DO ji = kideb, kiut
+          zrcpdt(ji) = ( rcpsn * MIN( h_snow_1d(ji) , zhsu )    &
+             &       + rcpic * MAX( zhsu - h_snow_1d(ji) , zzero ) ) / rdt_ice
+          zts_old(ji) =  sist_1d(ji)
+       END DO
+
+       !     4.2. Computation of surface temperature by expanding the eq. of energy balance
+       !          with Ts = Tp + DT. One obtain , F(Tp) + DT * DF(Tp) = 0
+       !          where  - F(Tp) = Fsr + Fnsr(Tp) + Fcs(Tp) 
+       !                 - DF(Tp)= (dFnsr(Tp)/dT) + (dFcs(Tp)/dT) - hsu*rcp/dt
+       !---------------------------------------------------------------------------------
+
+       DO ji = kideb, kiut
+          !---computation of the derivative of energy balance function 
+#if defined key_coupled
+#   if defined key_lim_cp2
+          zdfts   =   zksndh(ji)   & ! contribution of the conductive heat flux
+             &      + zrcpdt(ji)   & ! contribution of hsu * rcp / dt
+             &      - dqns_ice_1d(ji)      ! contribution of the total non solar radiation 
+#   else
+          zdfts   =   zksndh(ji)   & ! contribution of the conductive heat flux
+             &      + zrcpdt(ji)    ! contribution of hsu * rcp / dt
+#   endif
+
+#else
+          zdfts    =  zksndh(ji)   & ! contribution of the conductive heat flux
+             &      + zrcpdt(ji)   & ! contribution of hsu * rcp / dt
+             &      - dqns_ice_1d (ji)     ! contribution of the total non solar radiation 
+#endif
+          !---computation of the energy balance function 
+          zfts    = - z1mi0 (ji) * qsr_ice_1d(ji)   & ! net absorbed solar radiation
+             &      - qnsr_ice_1d(ji)                & ! total non solar radiation
+             &      - zfcsu (ji)                  ! conductive heat flux from the surface
+          !---computation of surface temperature increment  
+          zdts    = -zfts / zdfts
+#if defined key_lim_cp3
+          zdts = zdts / 3.0
+#endif
+          !---computation of the new surface temperature 
+          sist_1d(ji) = sist_1d(ji) + zdts
+
+       END DO
+
+       !----------------------------------------------------------------------------
+       !  5. Boundary condition at the top surface
+       !--    IF Tsb < Tmelt, Fnet = Fcs (the net heat flux equal the conductive heat flux)
+       !      Otherwise Tsb = Tmelt and Qnet(Tmelt) > 0 
+       !      Fnet(Tmelt) is therefore the net surface flux needed for melting
+       !----------------------------------------------------------------------------
+       
+       
+       !     5.1.  Limitation of surface temperature and update total non solar fluxes,
+       !          latent heat flux and conductive flux at the top surface 
+       !----------------------------------------------------------------------  
+                     
+       DO ji = kideb, kiut
+          sist_1d(ji) = MIN( ztsmlt(ji) , sist_1d(ji) )
+#if ! defined key_coupled
+          qnsr_ice_1d(ji) = qnsr_ice_1d(ji) + dqns_ice_1d(ji) * ( sist_1d(ji) - zts_old(ji) )
+          qla_ice_1d (ji) = qla_ice_1d (ji) + dqla_ice_1d(ji) * ( sist_1d(ji) - zts_old(ji) )
+#endif
+          zfcsu(ji)  = zksndh(ji) * ( ztbif(ji) - sist_1d(ji) )
+       END DO
+
+     
+
+       !     5.2. Calculate available heat for surface ablation. 
+       !---------------------------------------------------------------------
+
+       DO ji = kideb, kiut
+          zfnet(ji) = qnsr_ice_1d(ji) + z1mi0(ji) * qsr_ice_1d(ji) + zfcsu(ji)          
+          zfnet(ji) = MAX( zzero , zfnet(ji) )
+          zfnet(ji) = zfnet(ji) * MAX( zzero , SIGN( zone , sist_1d(ji) - ztsmlt(ji) ) )
+       END DO
+
+       !-------------------------------------------------------------------------
+       !  6. Calculate changes in internal temperature due to vertical diffusion   
+       !     processes. The evolution of this temperature is governed by the one-
+       !     dimensionnal heat-diffusion equation. 
+       !     Given the temperature tbif(1/2/3), at time m we solve a set
+       !     of finite difference equations to obtain new tempe. Each tempe is coupled
+       !     to the temp. immediatly above and below by heat conduction terms. Thus 
+       !     we have a set of equations of the form A * T = B, where A is a tridiagonal
+       !     matrix, T a vector whose components are the unknown new temp.
+       !-------------------------------------------------------------------------
+       
+       !--parameter for the numerical methode use to solve the heat-diffusion equation
+       !- implicit, explicit or Crank-Nicholson
+       zumsb = 1.0 - sbeta  
+       DO ji = kideb, kiut
+          zidsn(ji)   = MAX ( zzero, SIGN( zone, hsndif - h_snow_1d(ji) ) ) 
+          z1midsn(ji) = 1.0 - zidsn(ji)
+          zihic       = MAX ( zzero, SIGN( zone, hicdif - h_ice_1d(ji) ) ) 
+          zidsnic(ji) = zidsn(ji) *  zihic 
+          zfcsudt(ji) = zfcsu(ji) * rdt_ice 
+       END DO 
+   
+       DO ji = kideb, kiut
+
+          !     6.1 Calculate intermediate variables.
+          !----------------------------------------
+
+          !--conductivity at the snow surface
+          zkhsn = 2.0 * zksn(ji) * rdt_ice / rcpsn
+          !--conductivity at the ice surface
+          zkhic = 4.0 * zkic(ji) * rdt_ice / MAX( h_ice_1d(ji) * h_ice_1d(ji) * rcpic , epsi20 )
+          !--conductivity at the snow/ice interface 
+          zkint = 4.0 * zksn(ji) * zkic(ji)  &
+             &        / ( zksn(ji) * h_ice_1d(ji) + 2.0 * zkic(ji) * h_snow_1d(ji) * z1midsn(ji)) 
+          zkhsnint = zkint * rdt_ice / rcpsn
+          zkhicint = zkint * 2.0 * rdt_ice / MAX( h_ice_1d(ji) * rcpic , epsi20 )
+          
+          !     6.2. Fulfill the linear system matrix.
+          !-----------------------------------------
+!$$$          zplediag(1) = 1 + sbeta * z1midsn(ji) * ( zkhsn + zkhsnint )       
+          zplediag(1) =   zidsn(ji) + z1midsn(ji) * h_snow_1d(ji)   &
+             &          + sbeta * z1midsn(ji) * zkhsnint 
+          zplediag(2) = 1 + sbeta * ( z1midsn(ji) * zkhicint + zkhic ) 
+          zplediag(3) = 1 + 3.0 * sbeta * zkhic   
+
+          zsubdiag(1) =  0.e0              
+          zsubdiag(2) = -1.e0 * z1midsn(ji) * sbeta * zkhicint
+          zsubdiag(3) = -1.e0 * sbeta * zkhic 
+
+          zsupdiag(1) = -1.e0 * z1midsn(ji) * sbeta * zkhsnint 
+          zsupdiag(2) = zsubdiag(3)
+          zsupdiag(3) =  0.e0
+          
+          !     6.3. Fulfill the idependent term vector.
+          !-------------------------------------------
+          
+!$$$          zsmbr(1) = zidsn(ji) * sist_1d(ji) + z1midsn(ji) *   &
+!$$$             &         ( tbif_1d(ji,1) + zkhsn * sist_1d(ji)
+!$$$             &         - zumsb * ( zkhsn * tbif_1d(ji,1)
+!$$$             &                   + zkhsnint * ( tbif_1d(ji,1) - tbif_1d(ji,2) ) ) )
+          zsmbr(1) = zidsn(ji) * sist_1d(ji) + z1midsn(ji) *    &
+             &       ( h_snow_1d(ji) * tbif_1d(ji,1) - ( zfcsudt(ji) / rcpsn )  &
+             &       - zumsb * zkhsnint * ( tbif_1d(ji,1) - tbif_1d(ji,2) ) )
+
+          zsmbr(2) =  tbif_1d(ji,2)  &
+             &      - zidsn(ji) * ( 1.0 - zidsnic(ji) ) &
+             &        * ( zfcsudt(ji) / MAX( h_ice_1d(ji) * rcpic , epsi20 ) ) &
+             &      + zumsb * ( zkhicint * ( tbif_1d(ji,1) - tbif_1d(ji,2) ) &
+             &                   - zkhic * ( tbif_1d(ji,2) - tbif_1d(ji,3) )  )
+
+          zsmbr(3) =  tbif_1d(ji,3)  &
+             &      + zkhic * ( 2.0 * tfu_1d(ji) &
+             &                + zumsb * ( tbif_1d(ji,2) - 3.0 * tbif_1d(ji,3) ) )
+          
+          !     6.4. Solve the system (Gauss elimination method).
+          !----------------------------------------------------
+          
+          zpiv1 = zsubdiag(2) / zplediag(1) 
+          zb2   = zplediag(2) - zpiv1 * zsupdiag(1)
+          zd2   = zsmbr(2) - zpiv1 * zsmbr(1)
+
+          zpiv2 = zsubdiag(3) / zb2
+          zb3   = zplediag(3) - zpiv2 * zsupdiag(2)
+          zd3   = zsmbr(3) - zpiv2 * zd2
+
+          tbif_1d(ji,3) = zd3 / zb3
+          tbif_1d(ji,2) = ( zd2 - zsupdiag(2) * tbif_1d(ji,3) ) / zb2
+          tbif_1d(ji,1) = ( zsmbr(1) - zsupdiag(1) * tbif_1d(ji,2) ) / zplediag(1)            
+
+          !--- taking into account the particular case of  zidsnic(ji) = 1
+          ztint =  (  zkic(ji) * h_snow_1d(ji) * tfu_1d (ji)    &
+             &      + zksn(ji) * h_ice_1d(ji) * sist_1d(ji) )   &
+             &   / ( zkic(ji) * h_snow_1d(ji) + zksn(ji) * h_ice_1d(ji) ) 
+
+          tbif_1d(ji,1) = ( 1.0 - zidsnic(ji) ) * tbif_1d(ji,1)   &
+             &                + zidsnic(ji)   * ( ztint + sist_1d(ji) ) / 2.0
+          tbif_1d(ji,2) = ( 1.0 - zidsnic(ji) ) * tbif_1d(ji,2)   &
+             &                + zidsnic(ji)   * ( 3.0 * ztint + tfu_1d(ji) ) / 4.0
+          tbif_1d(ji,3) = ( 1.0 - zidsnic(ji) ) * tbif_1d(ji,3)   &
+             &                + zidsnic(ji)   * ( ztint + 3.0 * tfu_1d(ji) ) / 4.0     
+       END DO
+ 
+       !----------------------------------------------------------------------
+       !  9. Take into account surface ablation and bottom accretion-ablation.|
+       !----------------------------------------------------------------------
+       
+       !---Snow accumulation in one thermodynamic time step
+       zsprecip(kideb:kiut) = sprecip_1d(kideb:kiut) * rdt_ice / rhosn
+
+
+       DO ji = kideb, kiut
+          
+          !      9.1. Surface ablation and update of snow thickness and qstbif_1d
+          !--------------------------------------------------------------------
+          
+          !--------------------------------------------------------------------------
+          !--      Melting snow processes :
+          !--      Melt at the upper surface is computed from the difference between 
+          !--      the net heat flux (including the conductive heat flux) at the upper 
+          !--      surface and the pre-existing energy due to surface melting
+          !------------------------------------------------------------------------------
+          
+          !-- store the snow thickness
+          zhsnw_old(ji) =  h_snow_1d(ji)
+          !--computation of the energy needed to melt snow
+          zqsnw_mlt  = zfnet(ji) * rdt_ice - zqcmlt(ji,1)
+          !--change in snow thickness due to melt
+          zdhsmlt = - zqsnw_mlt / xlsn
+          
+          !-- compute new snow thickness, taking into account the part of snow accumulation
+          !   (as snow precipitation) and the part of snow lost due to melt
+          zhsn =  h_snow_1d(ji) + zsprecip(ji) + zdhsmlt
+          h_snow_1d(ji) = MAX( zzero , zhsn )
+          !-- compute the volume of snow lost after surface melting and the associated mass
+          dvsbq_1d(ji) =  ( 1.0 - frld_1d(ji) ) * ( h_snow_1d(ji) - zhsnw_old(ji) - zsprecip(ji) )
+          dvsbq_1d(ji) =  MIN( zzero , dvsbq_1d(ji) )
+          rdmsnif_1d(ji) =  rhosn * dvsbq_1d(ji)
+          !-- If the snow is completely melted the remaining heat is used to melt ice
+          zqsn_mlt_rem  = MAX( zzero , -zhsn ) * xlsn
+          zqice_top_mlt = zqsn_mlt_rem 
+          zqstbif_old   = qstbif_1d(ji)
+
+          !--------------------------------------------------------------------------
+          !--      Melting ice processes at the top surface :
+          !--      The energy used to melt ice, zqice_top_mlt, is taken from the energy
+          !--      stored in brine pockets qstbif_1d and the remaining energy coming 
+          !--      from the melting snow process zqsn_mlt_rem.
+          !--      If qstbif_1d > zqsn_mlt_rem then, one uses only a zqsn_mlt_rem part
+          !--      of qstbif_1d to melt ice,
+          !--         zqice_top_mlt = zqice_top_mlt + zqsn_mlt_rem
+          !--         qstbif_1d = qstbif_1d - zqsn_mlt_rem
+          !--      Otherwise one uses all qstbif_1d to melt ice
+          !--         zqice_top_mlt = zqice_top_mlt + qstbif_1d
+          !--         qstbif_1d = 0
+          !------------------------------------------------------
+          
+          ziqf =  MAX ( zzero , SIGN( zone , qstbif_1d(ji) - zqsn_mlt_rem  ) )
+          zqice_top_mlt =         ziqf   * ( zqice_top_mlt + zqsn_mlt_rem )   &
+             &          + ( 1.0 - ziqf ) * ( zqice_top_mlt + qstbif_1d(ji)  )
+
+          qstbif_1d(ji) =         ziqf   * ( qstbif_1d(ji) - zqsn_mlt_rem )   &
+             &        + ( 1.0 - ziqf ) * ( qstbif_1d(ji) - qstbif_1d(ji)  )
+
+          !--    The contribution of the energy stored in brine pockets qstbif_1d to melt
+          !--    ice is taking into account only when qstbif_1d is less than zqmax. 
+          !--    Otherwise, only the remaining energy coming from the melting snow 
+          !--    process is used 
+          zihq =  MAX ( zzero , SIGN( zone , qstbif_1d(ji) - zqmax(ji) ) )
+
+          zqice_top_mlt =         zihq   * zqice_top_mlt   &
+             &          + ( 1.0 - zihq ) * zqsn_mlt_rem
+
+          qstbif_1d(ji) =         zihq   * qstbif_1d(ji)   &
+             &        + ( 1.0 - zihq ) * zqstbif_old
+
+          !--change in ice thickness due to melt at the top surface
+          zdhictop(ji) = -zqice_top_mlt / xlic
+          !--compute the volume formed after surface melting
+          dvsbq_1d(ji) =  zdhictop(ji) * ( 1.0 - frld_1d(ji) )
+
+          !-------------------------------------------------------------------------
+          !--      A small variation at the surface also occurs because of sublimation
+          !--      associated with the latent flux. If qla_ice_1d is negative, snow condensates at 
+          !        the surface. Otherwise, snow evaporates
+          !-----------------------------------------------------------------------
+          !----change in snow and ice thicknesses due to sublimation or evaporation
+          zdhssub  = parsub * ( qla_ice_1d(ji) / ( rhosn * xsn ) ) * rdt_ice 
+          zhsn     = h_snow_1d(ji) - zdhssub
+          zdhisub  = MAX( zzero , -zhsn ) * rhosn/rhoic
+          zdhictop(ji) =  zdhictop(ji) - zdhisub
+          h_snow_1d(ji)  =  MAX( zzero , zhsn )
+          !-------------------------------------------------
+          !--  Update Internal temperature and qstbif_1d.
+          !-------------------------------------------
+          zihsn  =  MAX( zzero , SIGN( zone, -h_snow_1d(ji) ) )
+          tbif_1d(ji,1) = ( 1.0 - zihsn ) * tbif_1d(ji,1) + zihsn   * tfu_1d(ji)
+          !--change in snow internal temperature if snow has increased
+          zihnf = MAX( zzero , SIGN( zone , h_snow_1d(ji) - zhsnw_old(ji) ) )
+          zdhsn = 1.0 - zhsnw_old(ji) / MAX( h_snow_1d(ji) , epsi20 )
+          zdtsn = zdhsn * ( sist_1d(ji) - tbif_1d(ji,1) )
+          tbif_1d(ji,1) = tbif_1d(ji,1) + z1midsn(ji) * zihnf * zdtsn
+          !--energy created due to ice melting in the first ice layer
+          zqnes  = ( rt0_ice - tbif_1d(ji,2) ) * rcpic * ( h_ice_1d(ji) / 2. )
+          !--change in first ice layer internal temperature
+          ziqr  = MAX( zzero , SIGN( zone , qstbif_1d(ji) - zqnes ) )
+          zdtic = qstbif_1d(ji) / ( rcpic * ( h_ice_1d(ji) / 2. ) )
+          tbif_1d(ji,2) =  ziqr * rt0_ice + ( 1 - ziqr ) * ( tbif_1d(ji,2) + zdtic )
+          !--update qstbif_1d
+          qstbif_1d(ji) = ziqr * ( qstbif_1d(ji) - zqnes ) * swiqst
+
+
+          !--      9.2. Calculate bottom accretion-ablation and update qstbif_1d.
+          !             Growth and melting at bottom ice surface are governed by  
+          !                 -xlic * Dh = (Fcb - Fbot ) * Dt 
+          !             where Fbot is the net downward heat flux from ice to the ocean
+          !            and Fcb is the conductive heat flux at the bottom surface
+          !---------------------------------------------------------------------------
+          ztbot = ( 1.0 - zidsnic(ji) ) * tbif_1d(ji,3) + zidsnic(ji) * sist_1d(ji)
+          !---computes conductive heat flux at bottom surface 
+          zfcbot =  4.0 * zkic(ji) * ( tfu_1d(ji) - ztbot )   &
+             &   / ( h_ice_1d(ji) + zidsnic(ji) * ( 3. * h_ice_1d(ji) &
+             &   + 4.0 * zkic(ji)/zksn(ji) * h_snow_1d(ji) ) )
+          !---computation of net energy needed for bottom melting/growing
+          zqice_bot = ( zfcbot - ( fbif_1d(ji) + qlbbq_1d(ji) ) ) * rdt_ice
+          zqstbif_bot = qstbif_1d(ji)
+          !---switch to know if bottom surface melts ( = 1 ) or grows ( = 0 )occurs
+          zibmlt = MAX( zzero , SIGN( zone , -zqice_bot ) )
+          !--particular case of melting (in the same way as the top surface)
+          zqice_bot_mlt = zqice_bot 
+          zqstbif_old = zqstbif_bot
+
+          ziqf =  MAX ( zzero , SIGN( zone , qstbif_1d(ji) + zqice_bot_mlt  ) )
+          zqice_bot_mlt =         ziqf   * ( zqice_bot_mlt + zqice_bot_mlt ) &
+             &          + ( 1.0 - ziqf ) * ( zqice_bot_mlt + qstbif_1d(ji)  )          
+          qstbif_1d(ji)   =         ziqf   * ( qstbif_1d(ji) + zqice_bot_mlt ) &
+             &          + ( 1.0 - ziqf ) * ( qstbif_1d(ji) - qstbif_1d(ji)  )
+          !--    The contribution of the energy stored in brine pockets qstbif_1d to melt
+          !--    ice is taking into account only when qstbif_1d is less than zqmax. 
+          zihq =  MAX ( zzero , SIGN( zone , qstbif_1d(ji) - zqmax(ji) ) )
+          zqice_bot_mlt =         zihq   * zqice_bot_mlt   &
+             &          + ( 1.0 - zihq ) * zqice_bot
+          qstbif_1d(ji)   =         zihq   * qstbif_1d(ji)   &
+             &             + ( 1.0 - zihq ) * zqstbif_old
+
+          !---treatment of the case of melting/growing
+          zqice_bot   =         zibmlt   * ( zqice_bot_mlt - zqcmlt(ji,2) )   &
+             &        + ( 1.0 - zibmlt ) * ( zqice_bot - zqcmlt(ji,2)  )
+          qstbif_1d(ji) =         zibmlt   * qstbif_1d(ji)   &
+             &           + ( 1.0 - zibmlt ) * zqstbif_bot
+
+          !--computes change in ice thickness due to melt or growth
+          zdhicbot(ji) = zqice_bot / xlic
+          !--limitation of bottom melting if so : hmelt maximum melting at bottom
+          zdhicmlt  = MAX( hmelt , zdhicbot(ji) ) 
+          !--energy after bottom melting/growing
+          zqsup(ji) = ( 1.0 - frld_1d(ji) ) * xlic * ( zdhicmlt - zdhicbot(ji) )
+          !-- compute the new thickness and the newly formed volume after bottom melting/growing
+          zdhicbot(ji)  = zdhicmlt
+          dvbbq_1d(ji) = ( 1.0 - frld_1d(ji) ) * zdhicbot(ji)
+
+
+          !        9.3.  Updating ice thickness after top surface ablation 
+          !              and bottom surface accretion/ablation
+          !---------------------------------------------------------------
+          zhicnew  = h_ice_1d(ji) + zdhictop(ji) + zdhicbot(ji)
+
+          !
+          !        9.4. Case of total ablation (ice is gone but snow may be left)
+          !-------------------------------------------------------------------
+          zhsn  = h_snow_1d(ji)
+          zihgnew = 1.0 - MAX( zzero , SIGN( zone , -zhicnew ) )
+          zihsn   = MAX( zzero , SIGN( zone , -zhsn ) )
+          !---convert 
+          zdhicm  = ( 1.0 - zihgnew ) * ( zhicnew - qstbif_1d(ji) / xlic )
+          zdhsnm  = ( 1.0 - zihsn ) * zdhicm * rhoic / rhosn
+          !---updating new ice thickness and computing the newly formed ice mass
+          zhicnew   =  zihgnew * zhicnew
+          rdmicif_1d(ji) =  rdmicif_1d(ji) + ( 1.0 - frld_1d(ji) ) * ( zhicnew - h_ice_1d(ji) ) * rhoic
+          !---updating new snow thickness and computing the newly formed snow mass
+          zhsnfi   = zhsn + zdhsnm
+          h_snow_1d(ji) = MAX( zzero , zhsnfi )
+          rdmsnif_1d(ji) =  rdmsnif_1d(ji) + ( 1.0 - frld_1d(ji) ) * ( h_snow_1d(ji) - zhsn ) * rhosn
+          !--remaining energy in case of total ablation
+          zqocea(ji) = - ( zihsn * xlic * zdhicm + xlsn * ( zhsnfi - h_snow_1d(ji) ) ) * ( 1.0 - frld_1d(ji) )
+          qstbif_1d(ji) = zihgnew * qstbif_1d(ji)
+
+          !
+          !        9.5. Update internal temperature and ice thickness.
+          !-------------------------------------------------------
+          !
+          sist_1d(ji) = zihgnew * sist_1d(ji) + ( 1.0 - zihgnew ) * tfu_1d(ji)
+          zidhb  = MAX( zzero , SIGN( zone , - zdhicbot(ji) ) )
+          zc1    = - zhicnew * 0.5
+          zpc1   = MIN( 0.5 * zone , - h_ice_1d(ji) * 0.5 - zdhictop(ji) )
+          zc2    = - zhicnew
+          zpc2   =  zidhb * zc2 + ( 1.0 - zidhb ) * ( - h_ice_1d(ji) - zdhictop(ji) )
+          zp1    =  MAX( zpc1 , zc1 )
+          zp2    =  MAX( zpc2 , zc1 )
+          zep(ji) =  tbif_1d(ji,2)
+          ztb2  = 2.0 * (         - zp1   * tbif_1d(ji,2)  &
+             &  + ( zp1 - zp2 ) * tbif_1d(ji,3)  &
+             &  + ( zp2 - zc1 ) * tfu_1d(ji) ) / MAX( zhicnew , epsi20 ) 
+          tbif_1d(ji,2) = zihgnew * ztb2 + ( 1.0 - zihgnew ) * tfu_1d(ji)
+          !---
+          zp1  =  MIN( zpc1 , zc1 )
+          zp2  =  MIN( zpc2 , zc1 )
+          zp1  =  MAX( zc2  , zp1 )
+          ztb3 =  2.0 * (   ( 1.0 - zidhb ) * (  ( zc1 - zp2 ) * tbif_1d(ji,3)  &
+             &                                 + ( zp2 - zc2 ) * tfu_1d(ji) )   &
+             &               +      zidhb   * (  ( zc1 - zp1 ) * zep(ji)      &
+             &                                 + ( zp1 - zc2 ) * tbif_1d(ji,3))  ) / MAX( zhicnew , epsi20 )
+          tbif_1d(ji,3) =  zihgnew * ztb3 + ( 1.0 - zihgnew ) * tfu_1d(ji)
+          h_ice_1d(ji)  =  zhicnew
+       END DO
+
+
+       !----------------------------------------------------------------------------
+       !  10. Surface accretion. 
+       !      The change of ice thickness after snow/ice formation is such that
+       !      the interface between snow and ice is located at the same height
+       !      as the ocean surface. It is given by (Fichefet and Morales Maqueda 1999)
+       !          D(h_ice) = (- D(hsn)/alph) =  [rhosn*hsn - (rau0 - rhoic)*hic]
+       !                                     / [alph*rhosn+rau0 - rhoic]
+       !----------------------------------------------------------------------------
+       !
+       DO ji = kideb , kiut
+
+          !--  Computation of the change of ice thickness after snow-ice formation
+          zdrmh =  ( rhosn * h_snow_1d(ji) + ( rhoic - rau0 ) * h_ice_1d(ji) )  &
+             &  / ( alphs * rhosn + rau0 - rhoic )
+          zdrmh = MAX( zzero , zdrmh )
+
+          !--New ice and snow thicknesses Fichefet and Morales Maqueda (1999)
+          zhicnew  = MAX( h_ice_1d(ji) , h_ice_1d(ji) + zdrmh )
+          zhsnnew  = MIN( h_snow_1d(ji) , h_snow_1d(ji) - alphs * zdrmh )
+          !---Compute new ice temperatures. snow temperature remains unchanged
+          !   Lepparanta (1983):
+          zihic = 1.0 - MAX( zzero , SIGN( zone , -zhicnew ) )
+          zquot  = ( 1.0 - zihic ) &
+             &   +         zihic * MIN( zone , h_ice_1d(ji) / MAX( zhicnew , epsi20 ) ) 
+          ztneq  =         alphs * cnscg * tbif_1d(ji,1)    &
+             &   + ( 1.0 - alphs * ( rhosn/rhoic ) ) * tfu_1d(ji)
+          zep(ji) = tbif_1d(ji,2)
+          tbif_1d(ji,2) = ztneq - zquot * zquot * ( ztneq - tbif_1d(ji,2) )
+          tbif_1d(ji,3) = 2.0 * ztneq &
+             &        + zquot * ( tbif_1d(ji,3) + zep(ji) - 2.0 * ztneq ) - tbif_1d(ji,2)
+
+          !---  Lepparanta (1983) (latent heat released during white ice formation
+          !     goes to the ocean -for lateral ablation-)
+          qldif_1d(ji)  = qldif_1d(ji) + zdrmh * ( 1.0 - alphs * ( rhosn/rhoic ) ) * xlic * ( 1.0 - frld_1d(ji) )
+          !--   Changes in ice volume and ice mass Lepparanta (1983):
+          dvnbq_1d(ji) = ( 1.0 - frld_1d(ji) ) * ( zhicnew - h_ice_1d(ji) )
+          dmgwi_1d(ji) = dmgwi_1d(ji) + ( 1.0 -frld_1d(ji) ) * ( h_snow_1d(ji) - zhsnnew ) * rhosn
+          !  case of natural freshwater flux
+#if defined key_lim_fdd  
+          rdmicif_1d(ji) = rdmicif_1d(ji) + ( 1.0 - frld_1d(ji) )   * ( zhicnew - h_ice_1d(ji) )  * rhoic
+          rdmsnif_1d(ji) = rdmsnif_1d(ji) + ( 1.0 - frld_1d(ji) )   * ( zhsnnew - h_snow_1d(ji) ) * rhosn
+
+#else
+          rdmicif_1d(ji) = rdmicif_1d(ji) + ( 1.0 - frld_1d(ji) ) * (  ( zhicnew - h_ice_1d(ji) ) * rhoic   &
+             &                                                    + ( zhsnnew - h_snow_1d(ji) ) * rhosn )
+#endif
+
+          !---  Actualize new snow and ice thickness.
+
+          h_snow_1d(ji)  = zhsnnew
+          h_ice_1d(ji)  = zhicnew
+
+       END DO
+
+       !----------------------------------------------------
+       !  11. Lateral ablation (Changes in sea/ice fraction) 
+       !----------------------------------------------------
+       DO ji = kideb , kiut
+          zfrl_old(ji)  = frld_1d(ji)
+          zihic   = 1.0 - MAX( zzero , SIGN( zone , -h_ice_1d(ji) ) )
+          zihsn   = 1.0 - MAX( zzero , SIGN( zone , -h_snow_1d(ji) ) )
+          !--In the case of total ablation (all the ice ice has melted) frld = 1
+          frld_1d(ji)  = ( 1.0 - zihic ) + zihic * zfrl_old(ji)
+          !--Part of solar radiation absorbing inside the ice and going
+          !--through the ocean
+          fscbq_1d(ji) = ( 1.0 - zfrl_old(ji) ) * ( 1.0 - thcm_1d(ji) ) * fstbif_1d(ji)
+          !--Total remaining energy after bottom melting/growing 
+          qfvbq_1d(ji) = zqsup(ji) + ( 1.0 - zihic ) * zqocea(ji)
+          !--Updating of total heat from the ocean
+          qldif_1d(ji)  = qldif_1d(ji) + qfvbq_1d(ji) + ( 1.0 - zihic ) * fscbq_1d(ji) * rdt_ice
+          !--Computation of total heat inside the snow/ice system
+          zqice  = h_snow_1d(ji) * xlsn + h_ice_1d(ji) * xlic
+          zqicetot  = ( 1.0 - frld_1d(ji) ) * zqice
+          !--The concentration of ice is reduced (frld increases) if the heat 
+          !--exchange between ice and ocean is positive
+          ziqf = MAX( zzero , SIGN( zone ,  zqicetot - qldif_1d(ji) ) )
+          zdfrl = qldif_1d(ji) / MAX( epsi20 , zqice ) 
+          frld_1d(ji)  = ( 1.0 - ziqf )    &
+             &       +         ziqf * ( frld_1d(ji) + MAX( zzero , zdfrl ) ) 
+          fltbif_1d(ji) = ( ( 1.0 - zfrl_old(ji) ) * qstbif_1d(ji) - zqicetot  ) / rdt_ice
+          !--  Opening of leads: Hakkinen & Mellor, 1992.
+          zdfrl = - ( zdhictop(ji) + zdhicbot(ji) ) * hakspl * ( 1.0 - zfrl_old(ji) ) &
+             &  / MAX( epsi13 , h_ice_1d(ji) + h_snow_1d(ji) * rhosn/rhoic ) 
+          zfrld_1d(ji) =  frld_1d(ji) + MAX( zzero , zdfrl )
+          !--Limitation of sea-ice fraction <= 1
+          zfrld_1d(ji) = ziqf * MIN( 0.99 * zone , zfrld_1d(ji) ) + ( 1 - ziqf )
+          !---Update surface and internal temperature and snow/ice thicknesses.
+          sist_1d(ji)   = sist_1d(ji)   + ( 1.0 - ziqf ) * ( tfu_1d(ji) - sist_1d(ji)   )
+          tbif_1d(ji,1) = tbif_1d(ji,1) + ( 1.0 - ziqf ) * ( tfu_1d(ji) - tbif_1d(ji,1) )
+          tbif_1d(ji,2) = tbif_1d(ji,2) + ( 1.0 - ziqf ) * ( tfu_1d(ji) - tbif_1d(ji,2) )
+          tbif_1d(ji,3) = tbif_1d(ji,3) + ( 1.0 - ziqf ) * ( tfu_1d(ji) - tbif_1d(ji,3) )
+          !--variation of ice volume and ice mass 
+          dvlbq_1d(ji)   = zihic * ( zfrl_old(ji) - frld_1d(ji) ) * h_ice_1d(ji)
+          rdmicif_1d(ji) = rdmicif_1d(ji) + dvlbq_1d(ji) * rhoic
+          !--variation of snow volume and snow mass 
+          zdvsnvol    = zihsn * ( zfrl_old(ji) - frld_1d(ji) ) * h_snow_1d(ji)
+          rdmsnif_1d(ji) = rdmsnif_1d(ji) + zdvsnvol * rhosn
+          h_snow_1d(ji)  = ziqf * h_snow_1d(ji)
+
+          zdrfrl1 = ziqf * ( 1.0 -  frld_1d(ji) ) / MAX( epsi20 , 1.0 - zfrld_1d(ji) )
+          zdrfrl2 = ziqf * ( 1.0 - zfrl_old(ji) ) / MAX( epsi20 , 1.0 - zfrld_1d(ji) )
+
+          h_snow_1d (ji) = zdrfrl1 * h_snow_1d(ji)
+          h_ice_1d  (ji) = zdrfrl1 * h_ice_1d(ji)
+          qstbif_1d(ji) = zdrfrl2 * qstbif_1d(ji)
+          frld_1d(ji)    = zfrld_1d(ji)
+
+       END DO
+       
+    END SUBROUTINE lim_thd_zdf
+#else
+   !!======================================================================
+   !!                       ***  MODULE limthd_zdf   ***
+   !!                              no sea ice model  
+   !!======================================================================
+CONTAINS
+   SUBROUTINE lim_thd_zdf          ! Empty routine
+   END SUBROUTINE lim_thd_zdf
+#endif
+ END MODULE limthd_zdf
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtrp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtrp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limtrp.F90	(revision 4536)
@@ -0,0 +1,322 @@
+MODULE limtrp
+   !!======================================================================
+   !!                       ***  MODULE limtrp   ***
+   !! LIM transport ice model : sea-ice advection/diffusion
+   !!======================================================================
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_trp      : advection/diffusion process of sea ice
+   !!   lim_trp_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE phycst
+   USE dom_oce
+   USE daymod
+   USE in_out_manager  ! I/O manager
+   USE ice_oce         ! ice variables
+   USE dom_ice
+   USE ice
+   USE iceini
+   USE limistate
+   USE limadv
+   USE limhdf
+   USE lbclnk
+   USE lib_mpp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC lim_trp       ! called by ice_step
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC  ::   &  !:
+      bound  = 0.e0          !: boundary condit. (0.0 no-slip, 1.0 free-slip)
+
+   !! * Module variables
+   REAL(wp)  ::           &  ! constant values
+      epsi06 = 1.e-06  ,  &
+      epsi03 = 1.e-03  ,  &
+      epsi16 = 1.e-16  ,  &
+      rzero  = 0.e0    ,  &
+      rone   = 1.e0
+
+   !! * Substitution
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0,  UCL-LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lim_trp( kt )
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE lim_trp ***
+      !!                    
+      !! ** purpose : advection/diffusion process of sea ice
+      !!
+      !! ** method  : variables included in the process are scalar,   
+      !!     other values are considered as second order. 
+      !!     For advection, a second order Prather scheme is used.  
+      !!
+      !! ** action :
+      !!
+      !! History :
+      !!   1.0  !  00-01 (LIM)  Original code
+      !!        !  01-05 (G. Madec, R. Hordoir) opa norm
+      !!   2.0  !  04-01 (G. Madec, C. Ethe)  F90, mpp
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+      INTEGER  ::   ji, jj, jk,   &  ! dummy loop indices
+         &          initad           ! number of sub-timestep for the advection
+
+      REAL(wp) ::  &                              
+         zindb  ,  &
+         zacrith, &
+         zindsn , &
+         zindic , &
+         zusvosn, &
+         zusvoic, &
+         zignm  , &
+         zindhe , &
+         zvbord , &
+         zcfl   , &
+         zusnit , &
+         zrtt, ztsn, ztic1, ztic2
+
+      REAL(wp), DIMENSION(jpi,jpj)  ::   &  ! temporary workspace
+         zui_u , zvi_v , zsm   ,         &
+         zs0ice, zs0sn , zs0a  ,         &
+         zs0c0 , zs0c1 , zs0c2 ,         &
+         zs0st
+      !---------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL lim_trp_init      ! Initialization (first time-step only)
+
+      zsm(:,:) = area(:,:)
+      
+      IF( ln_limdyn ) THEN
+         !-------------------------------------!
+         !   Advection of sea ice properties   !
+         !-------------------------------------!
+
+         ! ice velocities at ocean U- and V-points (zui_u,zvi_v)
+         ! ---------------------------------------
+         ! zvbord factor between 1 and 2 to take into account slip or no-slip boundary conditions.        
+         zvbord = 1.0 + ( 1.0 - bound )
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zui_u(ji,jj) = ( u_ice(ji+1,jj  ) + u_ice(ji+1,jj+1) ) / ( MAX( tmu(ji+1,jj  ) + tmu(ji+1,jj+1), zvbord ) )
+               zvi_v(ji,jj) = ( v_ice(ji  ,jj+1) + v_ice(ji+1,jj+1) ) / ( MAX( tmu(ji  ,jj+1) + tmu(ji+1,jj+1), zvbord ) )
+            END DO
+         END DO
+         ! Lateral boundary conditions on zui_u, zvi_v
+         CALL lbc_lnk( zui_u, 'U', -1. )
+         CALL lbc_lnk( zvi_v, 'V', -1. )
+
+         ! CFL test for stability
+         ! ----------------------
+         zcfl  = 0.e0
+         zcfl  = MAX( zcfl, MAXVAL( ABS( zui_u(1:jpim1, :     ) ) * rdt_ice / e1u(1:jpim1, :     ) ) )
+         zcfl  = MAX( zcfl, MAXVAL( ABS( zvi_v( :     ,1:jpjm1) ) * rdt_ice / e2v( :     ,1:jpjm1) ) )
+
+         IF (lk_mpp ) CALL mpp_max(zcfl)
+
+         IF ( zcfl > 0.5 .AND. lwp )   WRITE(numout,*) 'lim_trp : violation of cfl criterion the ',nday,'th day, cfl = ',zcfl
+
+         ! content of properties
+         ! ---------------------
+         zs0sn (:,:) =  hsnm(:,:) * area(:,:)                 ! Snow volume.
+         zs0ice(:,:) =  hicm (:,:) * area(:,:)                ! Ice volume.
+         zs0a  (:,:) =  ( 1.0 - frld(:,:) ) * area(:,:)       ! Surface covered by ice.
+         zs0c0 (:,:) =  tbif(:,:,1) / rt0_snow * zs0sn(:,:)   ! Heat content of the snow layer.
+         zs0c1 (:,:) =  tbif(:,:,2) / rt0_ice  * zs0ice(:,:)  ! Heat content of the first ice layer.
+         zs0c2 (:,:) =  tbif(:,:,3) / rt0_ice  * zs0ice(:,:)  ! Heat content of the second ice layer.
+         zs0st (:,:) =  qstoif(:,:) / xlic     * zs0a(:,:)    ! Heat reservoir for brine pockets.
+         
+ 
+         ! Advection 
+         ! ---------
+         ! If ice drift field is too fast, use an appropriate time step for advection.         
+         initad = 1 + INT( MAX( rzero, SIGN( rone, zcfl-0.5 ) ) )
+         zusnit = 1.0 / REAL( initad ) 
+         
+         IF ( MOD( nday , 2 ) == 0) THEN
+            DO jk = 1,initad
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0ice, sxice, sxxice, syice, syyice, sxyice )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0ice, sxice, sxxice, syice, syyice, sxyice )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0sn , sxsn , sxxsn , sysn , syysn , sxysn  )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0sn , sxsn , sxxsn , sysn , syysn , sxysn  )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0a  , sxa  , sxxa  , sya  , syya  , sxya   )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0a  , sxa  , sxxa  , sya  , syya  , sxya   )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0c0 , sxc0 , sxxc0 , syc0 , syyc0 , sxyc0  )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0c0 , sxc0 , sxxc0 , syc0 , syyc0 , sxyc0  )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0c1 , sxc1 , sxxc1 , syc1 , syyc1 , sxyc1  )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0c1 , sxc1 , sxxc1 , syc1 , syyc1 , sxyc1  )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0c2 , sxc2 , sxxc2 , syc2 , syyc2 , sxyc2  )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0c2 , sxc2 , sxxc2 , syc2 , syyc2 , sxyc2  )
+               CALL lim_adv_x( zusnit, zui_u, rone , zsm, zs0st , sxst , sxxst , syst , syyst , sxyst  )
+               CALL lim_adv_y( zusnit, zvi_v, rzero, zsm, zs0st , sxst , sxxst , syst , syyst , sxyst  )
+            END DO
+         ELSE
+            DO jk = 1, initad
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0ice, sxice, sxxice, syice, syyice, sxyice )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0ice, sxice, sxxice, syice, syyice, sxyice )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0sn , sxsn , sxxsn , sysn , syysn , sxysn  )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0sn , sxsn , sxxsn , sysn , syysn , sxysn  )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0a  , sxa  , sxxa  , sya  , syya  , sxya   )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0a  , sxa  , sxxa  , sya  , syya  , sxya   )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0c0 , sxc0 , sxxc0 , syc0 , syyc0 , sxyc0  )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0c0 , sxc0 , sxxc0 , syc0 , syyc0 , sxyc0  )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0c1 , sxc1 , sxxc1 , syc1 , syyc1 , sxyc1  )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0c1 , sxc1 , sxxc1 , syc1 , syyc1 , sxyc1  )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0c2 , sxc2 , sxxc2 , syc2 , syyc2 , sxyc2  )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0c2 , sxc2 , sxxc2 , syc2 , syyc2 , sxyc2  )
+               CALL lim_adv_y( zusnit, zvi_v, rone , zsm, zs0st , sxst , sxxst , syst , syyst , sxyst  )
+               CALL lim_adv_x( zusnit, zui_u, rzero, zsm, zs0st , sxst , sxxst , syst , syyst , sxyst  )
+            END DO
+         ENDIF
+                        
+         ! recover the properties from their contents
+         ! ------------------------------------------
+         zs0ice(:,:) = zs0ice(:,:) / area(:,:)
+         zs0sn (:,:) = zs0sn (:,:) / area(:,:)
+         zs0a  (:,:) = zs0a  (:,:) / area(:,:)
+         zs0c0 (:,:) = zs0c0 (:,:) / area(:,:)
+         zs0c1 (:,:) = zs0c1 (:,:) / area(:,:)
+         zs0c2 (:,:) = zs0c2 (:,:) / area(:,:)
+         zs0st (:,:) = zs0st (:,:) / area(:,:)
+
+
+         !-------------------------------------!
+         !   Diffusion of sea ice properties   !
+         !-------------------------------------!
+
+         ! Masked eddy diffusivity coefficient at ocean U- and V-points
+         ! ------------------------------------------------------------
+         DO jj = 1, jpjm1          ! NB: has not to be defined on jpj line and jpi row
+            DO ji = 1 , fs_jpim1   ! vector opt.
+               pahu(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji  ,jj) ) ) )   &
+                  &        * ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji+1,jj) ) ) ) * ahiu(ji,jj)
+               pahv(ji,jj) = ( 1.0 - MAX( rzero, SIGN( rone, -zs0a(ji,jj  ) ) ) )   &
+                  &        * ( 1.0 - MAX( rzero, SIGN( rone,- zs0a(ji,jj+1) ) ) ) * ahiv(ji,jj)
+            END DO
+         END DO
+
+         ! diffusion
+         ! ---------
+         CALL lim_hdf( zs0ice )
+         CALL lim_hdf( zs0sn  )
+         CALL lim_hdf( zs0a   )
+         CALL lim_hdf( zs0c0  )
+         CALL lim_hdf( zs0c1  )
+         CALL lim_hdf( zs0c2  )
+         CALL lim_hdf( zs0st  )
+
+         zs0ice(:,:) = MAX( rzero, zs0ice(:,:) * area(:,:) )    !!bug:  est-ce utile
+         zs0sn (:,:) = MAX( rzero, zs0sn (:,:) * area(:,:) )    !!bug:  cf /area  juste apres
+         zs0a  (:,:) = MAX( rzero, zs0a  (:,:) * area(:,:) )    !! suppression des 2 change le resultat...
+         zs0c0 (:,:) = MAX( rzero, zs0c0 (:,:) * area(:,:) )
+         zs0c1 (:,:) = MAX( rzero, zs0c1 (:,:) * area(:,:) )
+         zs0c2 (:,:) = MAX( rzero, zs0c2 (:,:) * area(:,:) )
+         zs0st (:,:) = MAX( rzero, zs0st (:,:) * area(:,:) )
+
+
+         ! -------------------------------------------------------------------!
+         !   Up-dating and limitation of sea ice properties after transport   !
+         ! -------------------------------------------------------------------!
+
+         ! Up-dating and limitation of sea ice properties after transport.
+         DO jj = 1, jpj
+!!!iii      zindhe = REAL( MAX( 0, isign(1, jj - njeq ) ) )              !ibug mpp  !!bugmpp  njeq!
+            zindhe = MAX( 0.e0, SIGN( 1.e0, fcor(1,jj) ) )              ! = 0 for SH, =1 for NH
+            DO ji = 1, jpi
+
+               ! Recover mean values over the grid squares.
+               zs0sn (ji,jj) = MAX( rzero, zs0sn (ji,jj)/area(ji,jj) )
+               zs0ice(ji,jj) = MAX( rzero, zs0ice(ji,jj)/area(ji,jj) )
+               zs0a  (ji,jj) = MAX( rzero, zs0a  (ji,jj)/area(ji,jj) )
+               zs0c0 (ji,jj) = MAX( rzero, zs0c0 (ji,jj)/area(ji,jj) )
+               zs0c1 (ji,jj) = MAX( rzero, zs0c1 (ji,jj)/area(ji,jj) )
+               zs0c2 (ji,jj) = MAX( rzero, zs0c2 (ji,jj)/area(ji,jj) )
+               zs0st (ji,jj) = MAX( rzero, zs0st (ji,jj)/area(ji,jj) )
+
+               ! Recover in situ values.
+               zindb         = MAX( rzero, SIGN( rone, zs0a(ji,jj) - epsi06 ) )
+               zacrith       = 1.0 - ( zindhe * acrit(1) + ( 1.0 - zindhe ) * acrit(2) )
+               zs0a (ji,jj)  = zindb * MIN( zs0a(ji,jj), zacrith )
+               hsnif(ji,jj)  = zindb * ( zs0sn(ji,jj) /MAX( zs0a(ji,jj), epsi16 ) )
+               hicif(ji,jj)  = zindb * ( zs0ice(ji,jj)/MAX( zs0a(ji,jj), epsi16 ) )
+               zindsn        = MAX( rzero, SIGN( rone, hsnif(ji,jj) - epsi06 ) )
+               zindic        = MAX( rzero, SIGN( rone, hicif(ji,jj) - epsi03 ) )
+               zindb         = MAX( zindsn, zindic )
+               zs0a (ji,jj)  = zindb * zs0a(ji,jj)
+               frld (ji,jj)  = 1.0 - zs0a(ji,jj)
+               hsnif(ji,jj)  = zindsn * hsnif(ji,jj)
+               hicif(ji,jj)  = zindic * hicif(ji,jj)
+               zusvosn       = 1.0/MAX( hsnif(ji,jj) * zs0a(ji,jj), epsi16 )
+               zusvoic       = 1.0/MAX( hicif(ji,jj) * zs0a(ji,jj), epsi16 )
+               zignm         = MAX( rzero,  SIGN( rone, hsndif - hsnif(ji,jj) ) )
+               zrtt          = 173.15 * rone 
+               ztsn          =          zignm   * tbif(ji,jj,1)  &
+                              + ( 1.0 - zignm ) * MIN( MAX( zrtt, rt0_snow * zusvosn * zs0c0(ji,jj)) , tfu(ji,jj) ) 
+               ztic1          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c1(ji,jj) ) , tfu(ji,jj) )
+               ztic2          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c2(ji,jj) ) , tfu(ji,jj) )
+ 
+               tbif(ji,jj,1) = zindsn * ztsn  + ( 1.0 - zindsn ) * tfu(ji,jj)               
+               tbif(ji,jj,2) = zindic * ztic1 + ( 1.0 - zindic ) * tfu(ji,jj)
+               tbif(ji,jj,3) = zindic * ztic2 + ( 1.0 - zindic ) * tfu(ji,jj)
+               qstoif(ji,jj) = zindb  * xlic * zs0st(ji,jj) /  MAX( zs0a(ji,jj), epsi16 )
+            END DO
+         END DO
+         
+      ENDIF
+      
+   END SUBROUTINE lim_trp
+
+
+   SUBROUTINE lim_trp_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE lim_trp_init  ***
+      !!
+      !! ** Purpose :   initialization of ice advection parameters
+      !!
+      !! ** Method  : Read the namicetrp namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicetrp
+      !!
+      !! history :
+      !!   2.0  !  03-08 (C. Ethe)  Original code
+      !!-------------------------------------------------------------------
+      NAMELIST/namicetrp/ bound
+      !!-------------------------------------------------------------------
+
+      ! Read Namelist namicetrp
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namicetrp )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_trp_init : Ice parameters for advection '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   boundary conditions (0. no-slip, 1. free-slip) bound  = ', bound
+      ENDIF
+            
+   END SUBROUTINE lim_trp_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module                No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_trp        ! Empty routine
+   END SUBROUTINE lim_trp
+#endif
+
+   !!======================================================================
+END MODULE limtrp
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri.F90	(revision 4536)
@@ -0,0 +1,292 @@
+MODULE limwri
+   !!======================================================================
+   !!                     ***  MODULE  limwri  ***
+   !!         Ice diagnostics :  write ice output files
+   !!======================================================================
+   !! history :  2.0  ! 03-08  (C. Ethe) original code
+   !!            2.0  ! 04-10  (C. Ethe )  1D configuration
+   !!-------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                     LIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lim_wri      : write of the diagnostics variables in ouput file 
+   !!   lim_wri_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   USE ioipsl
+   USE dianam    ! build name of file (routine)
+   USE phycst
+   USE dom_oce
+   USE daymod
+   USE in_out_manager
+   USE ice_oce         ! ice variables
+   USE flx_oce
+   USE dom_ice
+   USE ice
+   USE lbclnk
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   lim_wri        ! routine called by lim_step.F90
+
+   INTEGER, PARAMETER                       ::   jpnoumax = 40   ! maximum number of variable for ice output
+   INTEGER                                  ::   noumef          ! number of fields
+   REAL(wp)           , DIMENSION(jpnoumax) ::   cmulti ,     &  ! multiplicative constant
+      &                                          cadd            ! additive constant
+   CHARACTER(len = 35), DIMENSION(jpnoumax) ::   titn            ! title of the field
+   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   nam             ! name of the field
+   CHARACTER(len = 8 ), DIMENSION(jpnoumax) ::   uni             ! unit of the field
+   INTEGER            , DIMENSION(jpnoumax) ::   nc              ! switch for saving field ( = 1 ) or not ( = 0 )
+
+   INTEGER ::   nice, nhorid, ndim, niter, ndepid       ! ????
+   INTEGER , DIMENSION( jpij ) ::   ndex51              ! ????
+
+   REAL(wp)  ::            &  ! constant values
+      epsi16 = 1.e-16   ,  &
+      zzero  = 0.e0     ,  &
+      zone   = 1.e0
+
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_dimgout
+   !!----------------------------------------------------------------------
+   !!   'key_dimgout'                                    Direct Access file
+   !!----------------------------------------------------------------------
+# include "limwri_dimg.h90"
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                          NetCDF file
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE lim_wri( kt )
+      !!-------------------------------------------------------------------
+      !!                    ***   ROUTINE lim_wri  ***
+      !!                
+      !! ** Purpose :   write the sea-ice output file in NetCDF
+      !!
+      !! ** Method  :   computes the average of some variables and write
+      !!      it in the NetCDF ouput files
+      !!      CAUTION: the sea-ice time-step must be an integer fraction
+      !!      of a day
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+      INTEGER  ::   ji, jj, jf                      ! dummy loop indices
+      CHARACTER(len = 40)  ::   clhstnam, clop
+      REAL(wp) ::   zsto, zsec, zjulian, zout,   &  ! temporary scalars
+         &          zindh, zinda, zindb, ztmu
+      REAL(wp), DIMENSION(1)                ::   zdept
+      REAL(wp), DIMENSION(jpi,jpj)          ::   zfield
+      REAL(wp), DIMENSION(jpi,jpj,jpnoumax) ::   zcmo
+      !!-------------------------------------------------------------------
+
+      !                                          !--------------------!
+      IF ( kt == nit000 ) THEN                !   Initialisation   !
+         !                                       !--------------------!
+         CALL lim_wri_init 
+                           
+         zsto     = rdt_ice
+!!Chris         clop     = "ave(only(x))"      !ibug  namelist parameter a ajouter
+         clop     = "ave(x)"
+         zout     = nwrite * rdt_ice / nfice
+         zsec     = 0.
+         niter    = 0
+         zdept(1) = 0.
+         
+         CALL ymds2ju ( nyear, nmonth, nday, zsec, zjulian )
+         CALL dia_nam ( clhstnam, nwrite, 'icemod' )
+         CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit,    &
+            &           1, jpi, 1, jpj, 0, zjulian, rdt_ice, nhorid, nice , domain_id=nidom)
+         CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid)
+         CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
+         
+         DO jf = 1, noumef
+            IF ( nc(jf) == 1 )   CALL histdef( nice, nam(jf), titn(jf), uni(jf), jpi, jpj   &
+                  &                                , nhorid, 1, 1, 1, -99, 32, clop, zsto, zout )
+         END DO
+         CALL histend( nice )
+         
+      ENDIF
+      !                                          !--------------------!
+      !                                          !   Cumulate at kt   !
+      !                                          !--------------------!
+
+!!gm  change the print below to have it only at output time step or when nitend =< 100
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_wri : write ice outputs in NetCDF files at time : ', nyear, nmonth, nday, kt + nfice - 1
+         WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      !-- calculs des valeurs instantanees
+      
+      zcmo(:,:, 1:jpnoumax ) = 0.e0 
+      DO jj = 2 , jpjm1
+         DO ji = 2 , jpim1
+            zindh  = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
+            zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
+            zindb  = zindh * zinda
+            ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) ) 
+            zcmo(ji,jj,1)  = hsnif (ji,jj)
+            zcmo(ji,jj,2)  = hicif (ji,jj)
+            zcmo(ji,jj,3)  = hicifp(ji,jj)
+            zcmo(ji,jj,4)  = frld  (ji,jj)
+            zcmo(ji,jj,5)  = sist  (ji,jj)
+            zcmo(ji,jj,6)  = fbif  (ji,jj)
+            zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+                                      + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+                                  / ztmu 
+
+            zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+                                      + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+                                  / ztmu
+            zcmo(ji,jj,9)  = sst_io(ji,jj)
+            zcmo(ji,jj,10) = sss_io(ji,jj)
+
+            zcmo(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+            zcmo(ji,jj,12) = fsolar (ji,jj)
+            zcmo(ji,jj,13) = fnsolar(ji,jj)
+            ! See thersf for the coefficient
+            zcmo(ji,jj,14) = - fsalt(ji,jj) * rday * ( sss_io(ji,jj) + epsi16 ) / soce
+            zcmo(ji,jj,15) = gtaux(ji,jj)
+            zcmo(ji,jj,16) = gtauy(ji,jj)
+            zcmo(ji,jj,17) = ( 1.0 - frld(ji,jj) ) * qsr_ice (ji,jj) + frld(ji,jj) * qsr_oce (ji,jj)
+            zcmo(ji,jj,18) = ( 1.0 - frld(ji,jj) ) * qnsr_ice(ji,jj) + frld(ji,jj) * qnsr_oce(ji,jj)
+            zcmo(ji,jj,19) = sprecip(ji,jj)
+         END DO
+      END DO
+      !
+      ! Write the netcdf file
+      !
+      niter = niter + 1
+      DO jf = 1 , noumef
+         DO jj = 1 , jpj
+            DO ji = 1 , jpi
+               zfield(ji,jj) = zcmo(ji,jj,jf) * cmulti(jf) + cadd(jf)
+            END DO
+         END DO
+         
+         IF ( jf == 7  .OR. jf == 8  .OR. jf == 15 .OR. jf == 16 ) THEN 
+            CALL lbc_lnk( zfield, 'T', -1. )
+         ELSE 
+            CALL lbc_lnk( zfield, 'T',  1. )
+         ENDIF
+         
+         IF ( nc(jf) == 1 ) CALL histwrite( nice, nam(jf), niter, zfield, ndim, ndex51 )
+         
+      END DO
+      
+      IF ( ( nfice * niter + nit000 - 1 ) >= nitend ) THEN
+         CALL histclo( nice ) 
+      ENDIF
+      !
+   END SUBROUTINE lim_wri
+   
+#endif
+   
+   SUBROUTINE lim_wri_init
+      !!-------------------------------------------------------------------
+      !!                    ***   ROUTINE lim_wri_init  ***
+      !!                
+      !! ** Purpose :   intialisation of LIM sea-ice output
+      !!
+      !! ** Method  : Read the namicewri namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicewri
+      !!-------------------------------------------------------------------
+      INTEGER ::   nf      ! ???
+      TYPE FIELD 
+         CHARACTER(len = 35) :: ztitle 
+         CHARACTER(len = 8 ) :: zname          
+         CHARACTER(len = 8 ) :: zunit
+         INTEGER             :: znc   
+         REAL                :: zcmulti 
+         REAL                :: zcadd        
+      END TYPE FIELD
+      TYPE(FIELD) ::  &
+         field_1 , field_2 , field_3 , field_4 , field_5 , field_6 ,   &
+         field_7 , field_8 , field_9 , field_10, field_11, field_12,   &
+         field_13, field_14, field_15, field_16, field_17, field_18,   &
+         field_19
+      TYPE(FIELD) , DIMENSION(jpnoumax) :: zfield
+
+      NAMELIST/namiceout/ noumef, &
+         field_1 , field_2 , field_3 , field_4 , field_5 , field_6 ,   &
+         field_7 , field_8 , field_9 , field_10, field_11, field_12,   &
+         field_13, field_14, field_15, field_16, field_17, field_18,   &
+         field_19
+!!gm      NAMELIST/namiceout/ noumef, &
+!!           zfield( 1), zfield( 2), zfield( 3), zfield( 4), zfield( 5),   &
+!!           zfield( 6), zfield( 7), zfield( 8), zfield( 9), zfield(10),   &
+!!           zfield(11), zfield(12), zfield(13), zfield(14), zfield(15),   &
+!!gm         zfield(16), zfield(17), zfield(18), zfield(19)
+      !!-------------------------------------------------------------------
+
+      ! Read Namelist namicewri
+      REWIND ( numnam_ice )
+      READ   ( numnam_ice  , namiceout )
+      
+      zfield(1)  = field_1
+      zfield(2)  = field_2
+      zfield(3)  = field_3
+      zfield(4)  = field_4
+      zfield(5)  = field_5
+      zfield(6)  = field_6
+      zfield(7)  = field_7
+      zfield(8)  = field_8
+      zfield(9)  = field_9
+      zfield(10) = field_10
+      zfield(11) = field_11
+      zfield(12) = field_12
+      zfield(13) = field_13
+      zfield(14) = field_14
+      zfield(15) = field_15
+      zfield(16) = field_16
+      zfield(17) = field_17
+      zfield(18) = field_18
+      zfield(19) = field_19
+      
+      DO nf = 1, noumef
+         titn  (nf) = zfield(nf)%ztitle
+         nam   (nf) = zfield(nf)%zname
+         uni   (nf) = zfield(nf)%zunit
+         nc    (nf) = zfield(nf)%znc
+         cmulti(nf) = zfield(nf)%zcmulti
+         cadd  (nf) = zfield(nf)%zcadd
+      END DO
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'lim_wri_init : Ice parameters for outputs'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '    number of fields to be stored         noumef = ', noumef
+         WRITE(numout,*) '           title                            name     unit      Saving (1/0) ',   &
+            &            '    multiplicative constant       additive constant '
+         DO nf = 1 , noumef         
+            WRITE(numout,*) '   ', titn(nf), '   ', nam(nf),'      ', uni(nf),'  ', nc(nf),'        ', cmulti(nf),   &
+               '        ', cadd(nf)
+         END DO
+      ENDIF
+      !    
+   END SUBROUTINE lim_wri_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE lim_wri          ! Empty routine
+   END SUBROUTINE lim_wri
+#endif
+
+   !!======================================================================
+END MODULE limwri
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri_dimg.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri_dimg.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/limwri_dimg.h90	(revision 4536)
@@ -0,0 +1,205 @@
+    SUBROUTINE lim_wri(kt)
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+    !!-------------------------------------------------------------------
+    !!  This routine computes the average of some variables and write it
+    !!  on the ouput files.
+    !!  ATTENTION cette routine n'est valable que si le pas de temps est
+    !!  egale a une fraction entiere de 1 jours.
+    !!  Diff 1-D 3-D : suppress common also included in etat
+    !!                 suppress cmoymo 11-18
+    !!  modif : 03/06/98
+    !!-------------------------------------------------------------------
+    USE  diadimg                ! use of dia_wri_dimg
+
+    INTEGER, INTENT(in) ::   kt     ! number of iteration
+
+    REAL(wp),DIMENSION(1) ::   zdept
+
+    REAL(wp) :: &
+         zsto, zsec, zjulian,zout, &
+         zindh,zinda,zindb,  &
+         ztmu
+    REAL(wp), DIMENSION(jpi,jpj,jpnoumax) :: &
+         zcmo
+    REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zfield
+    INTEGER, SAVE :: nmoyice, &  !: counter for averaging
+         &             nwf         !: number of fields to write on disk
+    INTEGER, SAVE,DIMENSION (:), ALLOCATABLE  :: nsubindex   !: subindex to be saved
+    ! according to namelist
+
+    REAL(wp), SAVE, DIMENSION(jpi,jpj,jpnoumax) :: rcmoy
+#if ! defined key_diainstant
+    LOGICAL, PARAMETER :: ll_dia_inst=.false.      ! local logical variable 
+#else
+    LOGICAL, PARAMETER :: ll_dia_inst=.true.
+#endif
+    INTEGER ::  ji, jj, jf, ii   ! dummy loop indices and array index
+    INTEGER :: iyear, iday, imon ! 
+
+    CHARACTER(LEN=80) :: clname, cltext, clmode
+
+
+    INTEGER , SAVE ::      &
+         nice, nhorid, ndim, niter, ndepid
+    INTEGER , DIMENSION( jpij ) , SAVE ::  &
+         ndex51  
+    !!-------------------------------------------------------------------
+    IF ( kt == nit000 ) THEN 
+
+       CALL lim_wri_init 
+
+       nwf = 0 
+       ii  = 0
+
+       IF (lwp ) THEN
+          WRITE(numout,*) 'lim_wri : Write ice outputs in dimg'
+          WRITE(numout,*) '~~~~~~~~'
+          WRITE(numout,*) '   According to namelist_ice, following fields saved:'
+          DO jf =1, noumef
+             IF (nc(jf) == 1 ) THEN
+                WRITE(numout,* ) '    -',titn(jf), nam(jf), uni(jf)
+             ENDIF
+          END DO
+       ENDIF
+
+       DO jf = 1, noumef
+          IF (nc(jf) == 1 ) nwf = nwf + 1
+       END DO
+
+       ALLOCATE( nsubindex (nwf) )
+
+       DO jf = 1, noumef
+          IF (nc(jf) == 1 ) THEN 
+             ii = ii +1 
+             nsubindex(ii) = jf
+          END IF
+       END DO
+
+       zsto     = rdt_ice
+       zout     = nwrite * rdt_ice / nfice
+       zsec     = 0.
+       niter    = 0
+       zdept(1) = 0.
+       nmoyice  = 0
+
+    ENDIF
+
+#if ! defined key_diainstant 
+    !-- calculs des valeurs instantanees
+
+    zcmo(:,:, 1:jpnoumax ) = 0.e0 
+    DO jj = 2 , jpjm1
+       DO ji = 2 , jpim1
+          zindh  = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
+          zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
+          zindb  = zindh * zinda
+          ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) ) 
+          zcmo(ji,jj,1)  = hsnif (ji,jj)
+          zcmo(ji,jj,2)  = hicif (ji,jj)
+          zcmo(ji,jj,3)  = hicifp(ji,jj)
+          zcmo(ji,jj,4)  = frld  (ji,jj)
+          zcmo(ji,jj,5)  = sist  (ji,jj)
+          zcmo(ji,jj,6)  = fbif  (ji,jj)
+          zcmo(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+               + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+               / ztmu 
+
+          zcmo(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+               + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+               / ztmu
+          zcmo(ji,jj,9)  = sst_io(ji,jj)
+          zcmo(ji,jj,10) = sss_io(ji,jj)
+
+          zcmo(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+          zcmo(ji,jj,12) = fsolar (ji,jj)
+          zcmo(ji,jj,13) = fnsolar(ji,jj)
+          ! See thersf for the coefficient
+          zcmo(ji,jj,14) = - fsalt(ji,jj) * rday * ( sss_io(ji,jj) + epsi16 ) / soce
+          zcmo(ji,jj,15) = gtaux(ji,jj)
+          zcmo(ji,jj,16) = gtauy(ji,jj)
+          zcmo(ji,jj,17) = ( 1.0 - frld(ji,jj) ) * qsr_ice (ji,jj) + frld(ji,jj) * qsr_oce (ji,jj)
+          zcmo(ji,jj,18) = ( 1.0 - frld(ji,jj) ) * qnsr_ice(ji,jj) + frld(ji,jj) * qnsr_oce(ji,jj)
+          zcmo(ji,jj,19) = sprecip(ji,jj)
+       END DO
+    END DO
+    ! Cumulates values between outputs           
+    rcmoy(:,:,:)= rcmoy(:,:,:) + zcmo(:,:,:)
+    nmoyice = nmoyice + 1 
+    ! compute mean value if it is time to write on file
+    IF ( MOD(kt+nfice-1-nit000+1,nwrite) == 0 ) THEN
+       rcmoy(:,:,:) = rcmoy(:,:,:) / FLOAT(nmoyice)
+#else  
+       IF ( MOD(kt-nfice-1-nit000+1,nwrite) == 0 ) THEN 
+          !  case of instantaneaous output rcmoy(:,:, 1:jpnoumax ) = 0.e0
+          DO jj = 2 , jpjm1
+             DO ji = 2 , jpim1
+                zindh  = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
+                zinda  = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
+                zindb  = zindh * zinda
+                ztmu   = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
+                rcmoy(ji,jj,1)  = hsnif (ji,jj)
+                rcmoy(ji,jj,2)  = hicif (ji,jj)
+                rcmoy(ji,jj,3)  = hicifp(ji,jj)
+                rcmoy(ji,jj,4)  = frld  (ji,jj)
+                rcmoy(ji,jj,5)  = sist  (ji,jj)
+                rcmoy(ji,jj,6)  = fbif  (ji,jj)
+                rcmoy(ji,jj,7)  = zindb * (  u_ice(ji,jj  ) * tmu(ji,jj  ) + u_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+                     + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+                     / ztmu
+
+                rcmoy(ji,jj,8)  = zindb * (  v_ice(ji,jj  ) * tmu(ji,jj  ) + v_ice(ji+1,jj  ) * tmu(ji+1,jj  )   &
+                     + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
+                     / ztmu
+                rcmoy(ji,jj,9)  = sst_io(ji,jj)
+                rcmoy(ji,jj,10) = sss_io(ji,jj)
+
+                rcmoy(ji,jj,11) = fnsolar(ji,jj) + fsolar(ji,jj)
+                rcmoy(ji,jj,12) = fsolar (ji,jj)
+                rcmoy(ji,jj,13) = fnsolar(ji,jj)
+                ! See thersf for the coefficient
+                rcmoy(ji,jj,14) = - fsalt(ji,jj) * rday * ( sss_io(ji,jj) + epsi16 ) / soce
+                rcmoy(ji,jj,15) = gtaux(ji,jj)
+                rcmoy(ji,jj,16) = gtauy(ji,jj)
+                rcmoy(ji,jj,17) = ( 1.0 - frld(ji,jj) ) * qsr_ice (ji,jj) + frld(ji,jj) * qsr_oce (ji,jj)
+                rcmoy(ji,jj,18) = ( 1.0 - frld(ji,jj) ) * qnsr_ice(ji,jj) + frld(ji,jj) * qnsr_oce(ji,jj)
+                rcmoy(ji,jj,19) = sprecip(ji,jj)
+             END DO
+          END DO
+#endif
+
+          !
+          niter = niter + 1
+          DO jf = 1 , noumef
+             zfield(:,:) = (rcmoy(:,:,jf) * cmulti(jf) + cadd(jf)) * tmask(:,:,1)
+
+             IF ( jf == 7  .OR. jf == 8  .OR. jf == 15 .OR. jf == 16 ) THEN 
+                CALL lbc_lnk( zfield, 'T', -1. )
+             ELSE 
+                CALL lbc_lnk( zfield, 'T',  1. )
+             ENDIF
+             rcmoy(:,:,jf) = zfield(:,:)
+          END DO
+
+          IF (ll_dia_inst) THEN
+           clmode='instantaneous'
+          ELSE
+           WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
+          END IF
+          iyear = ndastp/10000
+          imon = (ndastp-iyear*10000)/100
+          iday = ndastp - imon*100 - iyear*10000
+          WRITE(clname,9000) TRIM(cexper),'ICEMOD',iyear,imon,iday
+          cltext=TRIM(cexper)//' ice modele output'//TRIM(clmode)
+          CALL dia_wri_dimg (clname, cltext, rcmoy, nwf , 'I', nsubindex)
+9000      FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
+
+          rcmoy(:,:,:) = 0.0
+          nmoyice = 0 
+       END IF     !  MOD(kt+nfice-1-nit000+1, nwrite == 0 ) !
+
+     END SUBROUTINE lim_wri
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/par_ice.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/par_ice.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/par_ice.F90	(revision 4536)
@@ -0,0 +1,26 @@
+MODULE par_ice
+   !!======================================================================
+   !!                       ***  MODULE par_ice   ***
+   !! Sea-Ice model : definition of the parameters
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!  LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce
+
+   IMPLICIT NONE
+   PUBLIC               ! allows par_oce and par_kind to be known in ice modules
+
+   INTEGER, PUBLIC, PARAMETER ::   &  !:
+      jpkmax =  1    ,      &  !: ???
+      jpsmax =  2              !: ???
+
+   INTEGER, PUBLIC, PARAMETER ::   &  !: 
+      jplayers   = 2 ,           &  !: number of vertical ice layers
+      jplayersp1 = jplayers + 1     !: ???
+
+   !!======================================================================
+END MODULE par_ice
Index: /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/thd_ice.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/thd_ice.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/LIM_SRC/thd_ice.F90	(revision 4536)
@@ -0,0 +1,84 @@
+MODULE thd_ice
+   !!======================================================================
+   !!                       ***  MODULE thd_ice  ***
+   !! LIM sea-ice :   Ice thermodynamics in 1D
+   !!=====================================================================
+   !! History :
+   !!   2.0  !  02-11  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!   LIM 2.0, UCL-LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_ice
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share Module variables
+   REAL(wp) , PUBLIC ::   & !!! ** ice-thermo namelist (namicethd) **
+      hmelt   = -0.15  ,  &  !: maximum melting at the bottom
+      hicmin  = 0.2    ,  &  !: ice th. corr. to max. ener. in brine pocket
+      hiclim  = 0.05   ,  &  !: minimum ice thickness
+      amax    = 0.999  ,  &  !: maximum lead fraction
+      swiqst  = 1.0    ,  &  !: energy stored in brine pocket (1) or not (0)
+      sbeta   = 1.0    ,  &  !: numerical scheme for diffusion in ice 
+      parlat  = 0.0    ,  &  !: percent. of energy used for lateral ablation
+      hakspl  = 0.5    ,  &  !: slope of distr. for Hakkinen-Mellro's lat. melt
+      hibspl  = 0.5    ,  &  !: slope of distribution for Hibler's lat. melt
+      exld    = 2.0    ,  &  !: exponent for leads-closure rate
+      hakdif  = 1.0    ,  &  !: coefficient for diffusions of ice and snow
+      thth    = 0.2    ,  &  !: thick. for comp. of eq. thermal conduct
+      hnzst   = 0.1    ,  &  !: thick. of the surf. layer in temp. comp.
+      parsub  = 1.0    ,  &  !: switch for snow sublimation or not
+      alphs   = 1.0          !: coef. for snow density when snow-ice formation
+
+   REAL(wp), PUBLIC, DIMENSION(2)  ::  &  !:   
+      hiccrit = (/0.3,0.3/)  !: ice th. for lateral accretion in the NH (SH) (m)
+
+   REAL(wp) , PUBLIC ::   &  !:
+      uscomi,             &  !: inverse of minimum lead fraction
+      cnscg                  !: ratio  rcpsn/rcpic
+
+   INTEGER , PUBLIC, DIMENSION(jpij) ::   &  !:
+      npb     ,   &   !: number of points where computations has to be done
+      npac            !: correspondance between the points
+
+   REAL(wp), PUBLIC, DIMENSION(jpij) ::   &  !: 
+      qldif_1d    ,     &  !: corresponding to the 2D var  qldif
+      qcmif_1d    ,     &  !: corresponding to the 2D var  qcmif
+      thcm_1d     ,     &  !:    "                  "      thcm
+      fstbif_1d   ,     &  !:    "                  "      fstric
+      fltbif_1d   ,     &  !:    "                  "      ffltbif
+      fscbq_1d    ,     &  !:    "                  "      fscmcbq
+      qsr_ice_1d  ,     &  !:    "                  "      qsr_ice
+      fr1_i0_1d   ,     &  !:    "                  "      fr1_i0
+      fr2_i0_1d   ,     &  !:    "                  "      fr2_i0
+      qnsr_ice_1d ,     &  !:    "                  "      qns_ice
+      qfvbq_1d    ,     &  !:    "                  "      qfvbq
+      sist_1d     ,     &  !:    "                  "      sist
+      tfu_1d      ,     &  !:    "                  "      tfu
+      sprecip_1d  ,     &  !:    "                  "      sprecip
+      h_snow_1d   ,     &  !:    "                  "      h_snow
+      h_ice_1d    ,     &  !:    "                  "      h_ice
+      frld_1d     ,     &  !:    "                  "      frld
+      qstbif_1d   ,     &  !:    "                  "      qstoif
+      fbif_1d     ,     &  !:    "                  "      fbif
+      rdmicif_1d  ,     &  !:    "                  "      rdmicif
+      rdmsnif_1d  ,     &  !:    "                  "      rdmsnif
+      qlbbq_1d    ,     &  !:    "                  "      qlbsbq
+      dmgwi_1d    ,     &  !:    "                  "      dmgwi
+      dvsbq_1d    ,     &  !:    "                  "      rdvosif
+      dvbbq_1d    ,     &  !:    "                  "      rdvobif
+      dvlbq_1d    ,     &  !:    "                  "      rdvolif
+      dvnbq_1d    ,     &  !:    "                  "      rdvolif
+      dqns_ice_1d ,     &  !:    "                  "      dqns_ice
+      qla_ice_1d  ,     &  !:    "                  "      qla_ice
+      dqla_ice_1d          !:    "                  "      dqla_ice
+
+   REAL(wp), PUBLIC, DIMENSION(jpij,jplayersp1) ::   &  !:
+      tbif_1d              !: corresponding to the 2D var  tbif
+
+   !!======================================================================
+END MODULE thd_ice
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif2model.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif2model.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif2model.F90	(revision 4536)
@@ -0,0 +1,76 @@
+#if defined key_agrif
+   SUBROUTINE Agrif_Set_numberofcells(Agrif_Gr)
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Set_numberofcells ***
+      !!--------------------------------------------- 
+      USE Agrif_Types
+      IMPLICIT NONE
+
+      Type(Agrif_Grid), Pointer :: Agrif_Gr
+
+      IF ( associated(Agrif_Curgrid) )THEN
+#include "SetNumberofcells.h"
+      ENDIF
+
+   END SUBROUTINE Agrif_Set_numberofcells
+
+   SUBROUTINE Agrif_Get_numberofcells(Agrif_Gr)
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Get_numberofcells ***
+      !!--------------------------------------------- 
+      USE Agrif_Types
+      IMPLICIT NONE
+
+      Type(Agrif_Grid), Pointer :: Agrif_Gr
+
+#include "GetNumberofcells.h"
+
+   END SUBROUTINE Agrif_Get_numberofcells
+
+   SUBROUTINE Agrif_Allocationcalls(Agrif_Gr)
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Allocationscalls ***
+      !!--------------------------------------------- 
+      USE Agrif_Types 
+#include "include_use_Alloc_agrif.h"
+      IMPLICIT NONE
+
+      Type(Agrif_Grid), Pointer :: Agrif_Gr
+
+#include "allocations_calls_agrif.h"
+
+   END SUBROUTINE Agrif_Allocationcalls
+
+   SUBROUTINE Agrif_probdim_modtype_def()
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_probdim_modtype_def ***
+      !!--------------------------------------------- 
+      USE Agrif_Types
+      IMPLICIT NONE
+
+#include "modtype_agrif.h"
+#include "probdim_agrif.h"
+#include "keys_agrif.h"
+
+      Return
+
+   END SUBROUTINE Agrif_probdim_modtype_def
+
+   SUBROUTINE Agrif_clustering_def()
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_clustering_def ***
+      !!--------------------------------------------- 
+      Use Agrif_Types
+      IMPLICIT NONE
+
+      Return
+
+   END SUBROUTINE Agrif_clustering_def
+#else
+   SUBROUTINE Agrif2Model
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif2Model ***
+      !!--------------------------------------------- 
+      WRITE(*,*) 'Impossible to bet here'
+   END SUBROUTINE Agrif2model
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 4536)
@@ -0,0 +1,596 @@
+MODULE agrif_opa_interp
+#if defined key_agrif
+   USE par_oce
+   USE oce
+   USE dom_oce      
+   USE sol_oce
+
+   IMPLICIT NONE
+   PRIVATE
+    
+   PUBLIC Agrif_tra, Agrif_dyn, interpu, interpv
+
+   CONTAINS
+   
+   SUBROUTINE Agrif_tra( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Tra ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"  
+#  include "vectopt_loop_substitute.h90"
+      
+      INTEGER, INTENT(in) :: kt
+
+      INTEGER :: ji,jj,jk
+      REAL(wp) :: zrhox
+      REAL(wp) :: alpha1, alpha2, alpha3, alpha4
+      REAL(wp) :: alpha5, alpha6, alpha7
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zta, zsa
+      !
+      IF(Agrif_Root()) RETURN
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      zta = 0.e0
+      zsa = 0.e0
+
+      CALL Agrif_Bc_variable(zta,tn)
+      CALL Agrif_Bc_variable(zsa,sn)
+      Agrif_UseSpecialValue = .FALSE.
+
+      zrhox = Agrif_Rhox()
+
+      alpha1 = (zrhox-1.)/2.
+      alpha2 = 1.-alpha1
+
+      alpha3 = (zrhox-1)/(zrhox+1)
+      alpha4 = 1.-alpha3
+
+      alpha6 = 2.*(zrhox-1.)/(zrhox+1.)
+      alpha7 = -(zrhox-1)/(zrhox+3)
+      alpha5 = 1. - alpha6 - alpha7
+
+      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+
+         ta(nlci,:,:) = alpha1 * zta(nlci,:,:) + alpha2 * zta(nlci-1,:,:)
+         sa(nlci,:,:) = alpha1 * zsa(nlci,:,:) + alpha2 * zsa(nlci-1,:,:)
+
+         DO jk=1,jpk      
+            DO jj=1,jpj
+               IF (umask(nlci-2,jj,jk).EQ.0.) THEN
+                  ta(nlci-1,jj,jk) = ta(nlci,jj,jk) * tmask(nlci-1,jj,jk)
+                  sa(nlci-1,jj,jk) = sa(nlci,jj,jk) * tmask(nlci-1,jj,jk)
+               ELSE
+                  ta(nlci-1,jj,jk)=(alpha4*ta(nlci,jj,jk)+alpha3*ta(nlci-2,jj,jk))*tmask(nlci-1,jj,jk)
+                  sa(nlci-1,jj,jk)=(alpha4*sa(nlci,jj,jk)+alpha3*sa(nlci-2,jj,jk))*tmask(nlci-1,jj,jk)
+                  IF (un(nlci-2,jj,jk).GT.0.) THEN
+                     ta(nlci-1,jj,jk)=( alpha6*ta(nlci-2,jj,jk)+alpha5*ta(nlci,jj,jk)  &
+                                      + alpha7*ta(nlci-3,jj,jk) ) * tmask(nlci-1,jj,jk)
+                     sa(nlci-1,jj,jk)=( alpha6*sa(nlci-2,jj,jk)+alpha5*sa(nlci,jj,jk)  &
+                                      + alpha7*sa(nlci-3,jj,jk) ) * tmask(nlci-1,jj,jk)
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+
+         ta(:,nlcj,:) = alpha1 * zta(:,nlcj,:) + alpha2 * zta(:,nlcj-1,:)
+         sa(:,nlcj,:) = alpha1 * zsa(:,nlcj,:) + alpha2 * zsa(:,nlcj-1,:)
+
+         DO jk=1,jpk      
+            DO ji=1,jpi
+               IF (vmask(ji,nlcj-2,jk).EQ.0.) THEN
+                  ta(ji,nlcj-1,jk) = ta(ji,nlcj,jk) * tmask(ji,nlcj-1,jk)
+                  sa(ji,nlcj-1,jk) = sa(ji,nlcj,jk) * tmask(ji,nlcj-1,jk)
+               ELSE
+                  ta(ji,nlcj-1,jk)=(alpha4*ta(ji,nlcj,jk)+alpha3*ta(ji,nlcj-2,jk))*tmask(ji,nlcj-1,jk)        
+                  sa(ji,nlcj-1,jk)=(alpha4*sa(ji,nlcj,jk)+alpha3*sa(ji,nlcj-2,jk))*tmask(ji,nlcj-1,jk)
+                  IF (vn(ji,nlcj-2,jk) .GT. 0.) THEN
+                     ta(ji,nlcj-1,jk)=( alpha6*ta(ji,nlcj-2,jk)+alpha5*ta(ji,nlcj,jk)  &
+                                      + alpha7*ta(ji,nlcj-3,jk) ) * tmask(ji,nlcj-1,jk)
+                     sa(ji,nlcj-1,jk)=( alpha6*sa(ji,nlcj-2,jk)+alpha5*sa(ji,nlcj,jk)  &
+                                      + alpha7*sa(ji,nlcj-3,jk))*tmask(ji,nlcj-1,jk)
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+         ta(1,:,:) = alpha1 * zta(1,:,:) + alpha2 * zta(2,:,:)
+         sa(1,:,:) = alpha1 * zsa(1,:,:) + alpha2 * zsa(2,:,:)      
+         DO jk=1,jpk      
+            DO jj=1,jpj
+               IF (umask(2,jj,jk).EQ.0.) THEN
+                  ta(2,jj,jk) = ta(1,jj,jk) * tmask(2,jj,jk)
+                  sa(2,jj,jk) = sa(1,jj,jk) * tmask(2,jj,jk)
+               ELSE
+                  ta(2,jj,jk)=(alpha4*ta(1,jj,jk)+alpha3*ta(3,jj,jk))*tmask(2,jj,jk)        
+                  sa(2,jj,jk)=(alpha4*sa(1,jj,jk)+alpha3*sa(3,jj,jk))*tmask(2,jj,jk)
+                  IF (un(2,jj,jk).LT.0.) THEN
+                     ta(2,jj,jk)=(alpha6*ta(3,jj,jk)+alpha5*ta(1,jj,jk)+alpha7*ta(4,jj,jk))*tmask(2,jj,jk)
+                     sa(2,jj,jk)=(alpha6*sa(3,jj,jk)+alpha5*sa(1,jj,jk)+alpha7*sa(4,jj,jk))*tmask(2,jj,jk)
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+         ta(:,1,:) = alpha1 * zta(:,1,:) + alpha2 * zta(:,2,:)
+         sa(:,1,:) = alpha1 * zsa(:,1,:) + alpha2 * zsa(:,2,:)
+         DO jk=1,jpk      
+            DO ji=1,jpi
+               IF (vmask(ji,2,jk).EQ.0.) THEN
+                  ta(ji,2,jk)=ta(ji,1,jk) * tmask(ji,2,jk)
+                  sa(ji,2,jk)=sa(ji,1,jk) * tmask(ji,2,jk)
+               ELSE
+                  ta(ji,2,jk)=(alpha4*ta(ji,1,jk)+alpha3*ta(ji,3,jk))*tmask(ji,2,jk)
+                  sa(ji,2,jk)=(alpha4*sa(ji,1,jk)+alpha3*sa(ji,3,jk))*tmask(ji,2,jk) 
+                  IF (vn(ji,2,jk) .LT. 0.) THEN
+                     ta(ji,2,jk)=(alpha6*ta(ji,3,jk)+alpha5*ta(ji,1,jk)+alpha7*ta(ji,4,jk))*tmask(ji,2,jk)
+                     sa(ji,2,jk)=(alpha6*sa(ji,3,jk)+alpha5*sa(ji,1,jk)+alpha7*sa(ji,4,jk))*tmask(ji,2,jk)
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE Agrif_tra
+
+   SUBROUTINE Agrif_dyn( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_DYN ***
+      !!---------------------------------------------
+      USE phycst
+      USE in_out_manager
+
+#  include "domzgr_substitute.h90"
+      
+      INTEGER, INTENT(in) :: kt
+
+      REAL(wp) :: timeref
+      REAL(wp) :: z2dt, znugdt
+      REAL(wp) :: zrhox, rhoy
+      REAL(wp), DIMENSION(jpi,jpj) :: zua2d, zva2d
+      REAL(wp), DIMENSION(jpi,jpj) :: spgu1,spgv1
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zua, zva
+      INTEGER :: ji,jj,jk
+
+      IF (Agrif_Root()) RETURN
+
+      zrhox = Agrif_Rhox()
+      rhoy = Agrif_Rhoy()
+
+      timeref = 1.
+
+      ! time step: leap-frog
+      z2dt = 2. * rdt
+      ! time step: Euler if restart from rest
+      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
+      ! coefficients
+      znugdt =  rnu * grav * z2dt    
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      zua = 0.
+      zva = 0.
+      CALL Agrif_Bc_variable(zua,un,procname=interpu)
+      CALL Agrif_Bc_variable(zva,vn,procname=interpv)
+      zua2d = 0.
+      zva2d = 0.
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_variable(zua2d,e1u,calledweight=1.,procname=interpu2d)
+      CALL Agrif_Bc_variable(zva2d,e2v,calledweight=1.,procname=interpv2d)
+      Agrif_UseSpecialValue = .FALSE.
+
+
+      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+
+         DO jj=1,jpj
+            laplacu(2,jj) = timeref * (zua2d(2,jj)/(rhoy*e2u(2,jj)))*umask(2,jj,1)
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(1:2,jj,jk) = (zua(1:2,jj,jk)/(rhoy*e2u(1:2,jj)))
+#if ! defined key_zco
+               ua(1:2,jj,jk) = ua(1:2,jj,jk) / fse3u(1:2,jj,jk)
+#endif
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(2,jj,jk) = (ua(2,jj,jk) - z2dt * znugdt * laplacu(2,jj))*umask(2,jj,jk)
+            END DO
+         END DO
+
+         spgu(2,:)=0.
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               spgu(2,jj)=spgu(2,jj)+fse3u(2,jj,jk)*ua(2,jj,jk)
+            END DO
+         END DO
+
+         DO jj=1,jpj
+            IF (umask(2,jj,1).NE.0.) THEN
+               spgu(2,jj)=spgu(2,jj)/hu(2,jj)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(2,jj,jk) = 0.25*(ua(1,jj,jk)+2.*ua(2,jj,jk)+ua(3,jj,jk))
+               ua(2,jj,jk) = ua(2,jj,jk) * umask(2,jj,jk)
+            END DO
+         END DO
+
+         spgu1(2,:)=0.
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               spgu1(2,jj)=spgu1(2,jj)+fse3u(2,jj,jk)*ua(2,jj,jk)
+            END DO
+         END DO
+
+         DO jj=1,jpj
+            IF (umask(2,jj,1).NE.0.) THEN
+               spgu1(2,jj)=spgu1(2,jj)/hu(2,jj)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(2,jj,jk) = (ua(2,jj,jk)+spgu(2,jj)-spgu1(2,jj))*umask(2,jj,jk)
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               va(2,jj,jk) = (zva(2,jj,jk)/(zrhox*e1v(2,jj)))*vmask(2,jj,jk)
+#if ! defined key_zco
+               va(2,jj,jk) = va(2,jj,jk) / fse3v(2,jj,jk)
+#endif           
+            END DO
+         END DO
+
+         sshn(2,:)=sshn(3,:)
+         sshb(2,:)=sshb(3,:)
+
+      ENDIF
+
+      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+
+         DO jj=1,jpj
+            laplacu(nlci-2,jj) = timeref * (zua2d(nlci-2,jj)/(rhoy*e2u(nlci-2,jj)))
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2:nlci-1,jj,jk) = (zua(nlci-2:nlci-1,jj,jk)/(rhoy*e2u(nlci-2:nlci-1,jj)))
+
+#if ! defined key_zco
+               ua(nlci-2:nlci-1,jj,jk) = ua(nlci-2:nlci-1,jj,jk) / fse3u(nlci-2:nlci-1,jj,jk)
+#endif
+
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)- z2dt * znugdt * laplacu(nlci-2,jj))*umask(nlci-2,jj,jk)
+            END DO
+         END DO
+
+
+         spgu(nlci-2,:)=0.
+
+         do jk=1,jpkm1
+            do jj=1,jpj
+               spgu(nlci-2,jj)=spgu(nlci-2,jj)+fse3u(nlci-2,jj,jk)*ua(nlci-2,jj,jk)
+            enddo
+         enddo
+
+         DO jj=1,jpj
+            IF (umask(nlci-2,jj,1).NE.0.) THEN
+               spgu(nlci-2,jj)=spgu(nlci-2,jj)/hu(nlci-2,jj)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2,jj,jk) = 0.25*(ua(nlci-3,jj,jk)+2.*ua(nlci-2,jj,jk)+ua(nlci-1,jj,jk))
+
+               ua(nlci-2,jj,jk) = ua(nlci-2,jj,jk) * umask(nlci-2,jj,jk)
+
+            END DO
+         END DO
+
+         spgu1(nlci-2,:)=0.
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               spgu1(nlci-2,jj)=spgu1(nlci-2,jj)+fse3u(nlci-2,jj,jk)*ua(nlci-2,jj,jk)*umask(nlci-2,jj,jk)
+            END DO
+         END DO
+
+         DO jj=1,jpj
+            IF (umask(nlci-2,jj,1).NE.0.) THEN
+               spgu1(nlci-2,jj)=spgu1(nlci-2,jj)/hu(nlci-2,jj)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2,jj,jk) = (ua(nlci-2,jj,jk)+spgu(nlci-2,jj)-spgu1(nlci-2,jj))*umask(nlci-2,jj,jk)
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj-1
+               va(nlci-1,jj,jk) = (zva(nlci-1,jj,jk)/(zrhox*e1v(nlci-1,jj)))*vmask(nlci-1,jj,jk)
+#if ! defined key_zco
+               va(nlci-1,jj,jk) = va(nlci-1,jj,jk) / fse3v(nlci-1,jj,jk)
+#endif
+            END DO
+         END DO
+
+         sshn(nlci-1,:)=sshn(nlci-2,:)
+         sshb(nlci-1,:)=sshb(nlci-2,:)        
+      ENDIF
+
+      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+
+         DO ji=1,jpi
+            laplacv(ji,2) = timeref * (zva2d(ji,2)/(zrhox*e1v(ji,2)))
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,1:2,jk) = (zva(ji,1:2,jk)/(zrhox*e1v(ji,1:2)))
+#if ! defined key_zco
+               va(ji,1:2,jk) = va(ji,1:2,jk) / fse3v(ji,1:2,jk)
+#endif
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,2,jk) = (va(ji,2,jk) - z2dt * znugdt * laplacv(ji,2))*vmask(ji,2,jk)
+            END DO
+         END DO
+
+         spgv(:,2)=0.
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               spgv(ji,2)=spgv(ji,2)+fse3v(ji,2,jk)*va(ji,2,jk)
+            END DO
+         END DO
+
+         DO ji=1,jpi
+            IF (vmask(ji,2,1).NE.0.) THEN
+               spgv(ji,2)=spgv(ji,2)/hv(ji,2)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,2,jk)=0.25*(va(ji,1,jk)+2.*va(ji,2,jk)+va(ji,3,jk))
+               va(ji,2,jk)=va(ji,2,jk)*vmask(ji,2,jk)
+            END DO
+         END DO
+
+         spgv1(:,2)=0.
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               spgv1(ji,2)=spgv1(ji,2)+fse3v(ji,2,jk)*va(ji,2,jk)*vmask(ji,2,jk)
+            END DO
+         END DO
+
+         DO ji=1,jpi
+            IF (vmask(ji,2,1).NE.0.) THEN
+               spgv1(ji,2)=spgv1(ji,2)/hv(ji,2)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,2,jk) = (va(ji,2,jk)+spgv(ji,2)-spgv1(ji,2))*vmask(ji,2,jk)
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               ua(ji,2,jk) = (zua(ji,2,jk)/(rhoy*e2u(ji,2)))*umask(ji,2,jk) 
+#if ! defined key_zco
+               ua(ji,2,jk) = ua(ji,2,jk) / fse3u(ji,2,jk)
+#endif                
+            END DO
+         END DO
+
+         sshn(:,2)=sshn(:,3)
+         sshb(:,2)=sshb(:,3)
+      ENDIF
+
+      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+
+         DO ji=1,jpi
+            laplacv(ji,nlcj-2) = timeref * (zva2d(ji,nlcj-2)/(zrhox*e1v(ji,nlcj-2)))
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,nlcj-2:nlcj-1,jk) = (zva(ji,nlcj-2:nlcj-1,jk)/(zrhox*e1v(ji,nlcj-2:nlcj-1)))
+#if ! defined key_zco
+               va(ji,nlcj-2:nlcj-1,jk) = va(ji,nlcj-2:nlcj-1,jk) / fse3v(ji,nlcj-2:nlcj-1,jk)
+#endif
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)-z2dt * znugdt * laplacv(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+
+         spgv(:,nlcj-2)=0.
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               spgv(ji,nlcj-2)=spgv(ji,nlcj-2)+fse3v(ji,nlcj-2,jk)*va(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         DO ji=1,jpi
+            IF (vmask(ji,nlcj-2,1).NE.0.) THEN
+               spgv(ji,nlcj-2)=spgv(ji,nlcj-2)/hv(ji,nlcj-2)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,nlcj-2,jk)=0.25*(va(ji,nlcj-3,jk)+2.*va(ji,nlcj-2,jk)+va(ji,nlcj-1,jk))
+               va(ji,nlcj-2,jk) = va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         spgv1(:,nlcj-2)=0.
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               spgv1(ji,nlcj-2)=spgv1(ji,nlcj-2)+fse3v(ji,nlcj-2,jk)*va(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         DO ji=1,jpi
+            IF (vmask(ji,nlcj-2,1).NE.0.) THEN
+               spgv1(ji,nlcj-2)=spgv1(ji,nlcj-2)/hv(ji,nlcj-2)
+            ENDIF
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               va(ji,nlcj-2,jk) = (va(ji,nlcj-2,jk)+spgv(ji,nlcj-2)-spgv1(ji,nlcj-2))*vmask(ji,nlcj-2,jk)
+            END DO
+         END DO
+
+         DO jk=1,jpkm1
+            DO ji=1,jpi
+               ua(ji,nlcj-1,jk) = (zua(ji,nlcj-1,jk)/(rhoy*e2u(ji,nlcj-1)))*umask(ji,nlcj-1,jk)
+#if ! defined key_zco
+               ua(ji,nlcj-1,jk) = ua(ji,nlcj-1,jk) / fse3u(ji,nlcj-1,jk)
+#endif          
+            END DO
+         END DO
+
+         sshn(:,nlcj-1)=sshn(:,nlcj-2)
+         sshb(:,nlcj-1)=sshb(:,nlcj-2)                
+      ENDIF
+
+   END SUBROUTINE Agrif_dyn
+
+   SUBROUTINE interpu(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpu ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"   
+    
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      INTEGER :: ji,jj,jk
+
+      DO jk=k1,k2
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj,jk) = e2u(ji,jj) * un(ji,jj,jk)
+#if ! defined key_zco
+               tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3u(ji,jj,jk)
+#endif
+            END DO
+         END DO
+      END DO
+   END SUBROUTINE interpu
+
+   SUBROUTINE interpu2d(tabres,i1,i2,j1,j2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpu2d ***
+      !!---------------------------------------------
+
+      INTEGER, INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+
+      INTEGER :: ji,jj
+
+      DO jj=j1,j2
+         DO ji=i1,i2
+            tabres(ji,jj) = e2u(ji,jj) * ((gcx(ji+1,jj) - gcx(ji,jj))/e1u(ji,jj)) &
+               * umask(ji,jj,1)
+         END DO
+      END DO
+
+   END SUBROUTINE interpu2d
+
+   SUBROUTINE interpv(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpv ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90" 
+      
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      INTEGER :: ji, jj, jk
+
+      DO jk=k1,k2
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj,jk) = e1v(ji,jj) * vn(ji,jj,jk)
+#if ! defined key_zco
+               tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3v(ji,jj,jk)
+#endif           
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE interpv
+
+   SUBROUTINE interpv2d(tabres,i1,i2,j1,j2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpv2d ***
+      !!---------------------------------------------
+
+      INTEGER, INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+
+      INTEGER :: ji,jj
+
+      DO jj=j1,j2
+         DO ji=i1,i2
+            tabres(ji,jj) = e1v(ji,jj) * ((gcx(ji,jj+1) - gcx(ji,jj))/e2v(ji,jj)) &
+               * vmask(ji,jj,1)
+         END DO
+      END DO
+
+   END SUBROUTINE interpv2d
+
+#else
+CONTAINS
+
+   SUBROUTINE Agrif_OPA_Interp_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_OPA_Interp_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_opa_interp : You should not have seen this print! error?'
+   END SUBROUTINE Agrif_OPA_Interp_empty
+#endif
+END MODULE agrif_opa_interp
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 4536)
@@ -0,0 +1,442 @@
+#define SPONGE
+
+Module agrif_opa_sponge
+#if defined key_agrif
+   USE par_oce
+   USE oce
+   USE dom_oce
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC Agrif_Sponge_Tra, Agrif_Sponge_Dyn, interptn, interpsn, interpun, interpvn
+
+   !! * Namelist (namagrif)
+   REAL(wp) :: visc_tra = rdt
+   REAL(wp) :: visc_dyn = rdt
+
+   CONTAINS
+
+   SUBROUTINE Agrif_Sponge_Tra( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Sponge_Tra ***
+      !!---------------------------------------------
+#include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: kt
+
+      INTEGER :: ji,jj,jk
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: umasktemp,vmasktemp
+      INTEGER :: spongearea
+      REAL(wp) :: timecoeff
+      REAL(wp) :: zta, zsa, zabe1, zabe2, zbtr
+      REAL(wp), DIMENSION(jpi,jpj) :: localviscsponge
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztab, tbdiff, sbdiff
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztu ,ztv, zsu ,zsv
+
+#if defined SPONGE
+
+      IF( kt == nit000  )   CALL agrif_sponge_init
+
+      timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      ztab = 0.e0
+      CALL Agrif_Bc_Variable(ztab, ta,calledweight=timecoeff,procname=interptn)
+      Agrif_UseSpecialValue = .FALSE.
+
+      tbdiff(:,:,:) = tb(:,:,:) - ztab(:,:,:)
+
+      ztab = 0.e0
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_Variable(ztab, sa,calledweight=timecoeff,procname=interpsn)
+      Agrif_UseSpecialValue = .FALSE.
+
+      sbdiff(:,:,:) = sb(:,:,:) - ztab(:,:,:)
+
+      spongearea = 2 + 2 * Agrif_irhox()
+
+      localviscsponge = 0.
+      umasktemp = 0.
+      vmasktemp = 0.
+
+      IF ((nbondi == -1).OR.(nbondi == 2)) THEN
+         DO ji = 2, spongearea
+            localviscsponge(ji,:) = visc_tra * (spongearea-ji)/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(2:spongearea-1,:,jk) = umask(2:spongearea-1,:,jk) &
+               * 0.5 * (localviscsponge(2:spongearea-1,:) + localviscsponge(3:spongearea,:))
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(2:spongearea,1:jpjm1,jk) = vmask(2:spongearea,1:jpjm1,jk) &
+               * 0.5 * (localviscsponge(2:spongearea,1:jpjm1) + localviscsponge(2:spongearea,2:jpj))
+         ENDDO
+      ENDIF
+
+      IF ((nbondi == 1).OR.(nbondi == 2)) THEN
+         DO ji = nlci-spongearea + 1,nlci-1
+            localviscsponge(ji,:) = visc_tra * (ji - (nlci-spongearea+1))/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(nlci-spongearea + 1:nlci-2,:,jk) = umask(nlci-spongearea + 1:nlci-2,:,jk) &
+               * 0.5 * (localviscsponge(nlci-spongearea + 1:nlci-2,:) + localviscsponge(nlci-spongearea + 2:nlci-1,:))
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(nlci-spongearea + 1:nlci-1,1:jpjm1,jk) = vmask(nlci-spongearea + 1:nlci-1,1:jpjm1,jk) &
+               * 0.5 * (localviscsponge(nlci-spongearea + 1:nlci-1,1:jpjm1) + localviscsponge(nlci-spongearea + 1:nlci-1,2:jpj))
+         ENDDO
+      ENDIF
+
+
+      IF ((nbondj == -1).OR.(nbondj == 2)) THEN
+         DO jj = 2, spongearea
+            localviscsponge(:,jj) = visc_tra * (spongearea-jj)/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(:,2:spongearea-1,jk) = vmask(:,2:spongearea-1,jk) &
+               * 0.5 * (localviscsponge(:,2:spongearea-1) + localviscsponge(:,3:spongearea))
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(1:jpim1,2:spongearea,jk) = umask(1:jpim1,2:spongearea,jk) &
+               * 0.5 * (localviscsponge(1:jpim1,2:spongearea) + localviscsponge(2:jpi,2:spongearea))
+         ENDDO
+      ENDIF
+
+      IF ((nbondj == 1).OR.(nbondj == 2)) THEN
+         DO jj = nlcj-spongearea + 1,nlcj-1
+            localviscsponge(:,jj) = visc_tra * (jj - (nlcj-spongearea+1))/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(:,nlcj-spongearea + 1:nlcj-2,jk) = vmask(:,nlcj-spongearea + 1:nlcj-2,jk) &
+               * 0.5 * (localviscsponge(:,nlcj-spongearea + 1:nlcj-2) + localviscsponge(:,nlcj-spongearea + 2:nlcj-1))
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(1:jpim1,nlcj-spongearea + 1:nlcj-1,jk) = umask(1:jpim1,nlcj-spongearea + 1:nlcj-1,jk) &
+               * 0.5 * (localviscsponge(1:jpim1,nlcj-spongearea + 1:nlcj-1) + localviscsponge(2:jpi,nlcj-spongearea + 1:nlcj-1))
+         ENDDO
+      ENDIF
+
+      IF (.NOT. spongedoneT) THEN
+         zspe1ur(:,:) = e2u(:,:) / e1u(:,:)
+         zspe2vr(:,:) = e1v(:,:) / e2v(:,:)
+         zspbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:))
+
+         spongedoneT = .TRUE.
+      ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#if defined key_zco
+               zabe1 = umasktemp(ji,jj,jk) * zspe1ur(ji,jj)
+               zabe2 = vmasktemp(ji,jj,jk) * zspe2vr(ji,jj)
+#else
+               zabe1 = umasktemp(ji,jj,jk) * zspe1ur(ji,jj) * fse3u(ji,jj,jk)
+               zabe2 = vmasktemp(ji,jj,jk) * zspe2vr(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               ztu(ji,jj,jk) = zabe1 * ( tbdiff(ji+1,jj  ,jk) - tbdiff(ji,jj,jk) )
+               zsu(ji,jj,jk) = zabe1 * ( sbdiff(ji+1,jj  ,jk) - sbdiff(ji,jj,jk) )
+               ztv(ji,jj,jk) = zabe2 * ( tbdiff(ji  ,jj+1,jk) - tbdiff(ji,jj,jk) )
+               zsv(ji,jj,jk) = zabe2 * ( sbdiff(ji  ,jj+1,jk) - sbdiff(ji,jj,jk) )
+            ENDDO
+         ENDDO
+
+         DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+#if defined key_zco
+               zbtr = zspbtr2(ji,jj)
+#else
+               zbtr = zspbtr2(ji,jj) / fse3t(ji,jj,jk)
+#endif
+               ! horizontal diffusive trends
+               zta = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)   &
+                  &          + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+               zsa = zbtr * (  zsu(ji,jj,jk) - zsu(ji-1,jj,jk)   &
+                  &          + zsv(ji,jj,jk) - zsv(ji,jj-1,jk)  )
+               ! add it to the general tracer trends
+               ta(ji,jj,jk) = (ta(ji,jj,jk) + zta)
+               sa(ji,jj,jk) = (sa(ji,jj,jk) + zsa)
+            END DO
+         END DO
+
+      ENDDO
+
+#endif
+
+   END SUBROUTINE Agrif_Sponge_Tra
+
+   SUBROUTINE Agrif_Sponge_dyn( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Sponge_dyn ***
+      !!---------------------------------------------
+#include "domzgr_substitute.h90"
+
+      INTEGER,INTENT(in) :: kt
+
+      INTEGER :: ji,jj,jk
+      INTEGER :: spongearea
+      REAL(wp) :: timecoeff
+      REAL(wp) :: ze2u, ze1v, zua, zva
+      REAL(wp), DIMENSION(jpi,jpj) :: localviscsponge
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztab, ubdiff, vbdiff,rotdiff,hdivdiff
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: umasktemp,vmasktemp
+
+#if defined SPONGE
+
+      timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      ztab = 0.e0
+      CALL Agrif_Bc_Variable(ztab, ua,calledweight=timecoeff,procname=interpun)
+      Agrif_UseSpecialValue = .FALSE.
+
+      ubdiff(:,:,:) = ub(:,:,:) - ztab(:,:,:)
+
+      ztab = 0.e0
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      CALL Agrif_Bc_Variable(ztab, va,calledweight=timecoeff,procname=interpvn)
+      Agrif_UseSpecialValue = .FALSE.
+
+      vbdiff(:,:,:) = vb(:,:,:) - ztab(:,:,:)
+
+      spongearea = 2 + 2 * Agrif_irhox()
+
+      localviscsponge = 0.
+      umasktemp = 0.
+      vmasktemp = 0.
+
+      IF ((nbondi == -1).OR.(nbondi == 2)) THEN
+         DO ji = 2, spongearea
+            localviscsponge(ji,:) = visc_dyn * (spongearea-ji)/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(2:spongearea-1,:,jk) = umask(2:spongearea-1,:,jk) &
+               * 0.5 * (localviscsponge(2:spongearea-1,:) + localviscsponge(3:spongearea,:))
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(2:spongearea,1:jpjm1,jk) = vmask(2:spongearea,1:jpjm1,jk) &
+               * 0.5 * (localviscsponge(2:spongearea,1:jpjm1) + localviscsponge(2:spongearea,2:jpj))
+         ENDDO
+      ENDIF
+
+      IF ((nbondi == 1).OR.(nbondi == 2)) THEN
+         DO ji = nlci-spongearea + 1,nlci-1
+            localviscsponge(ji,:) = visc_dyn * (ji - (nlci-spongearea+1))/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(nlci-spongearea + 1:nlci-2,:,jk) = umask(nlci-spongearea + 1:nlci-2,:,jk) &
+               * 0.5 * (localviscsponge(nlci-spongearea + 1:nlci-2,:) + localviscsponge(nlci-spongearea + 2:nlci-1,:))
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(nlci-spongearea + 1:nlci-1,1:jpjm1,jk) = vmask(nlci-spongearea + 1:nlci-1,1:jpjm1,jk) &
+               * 0.5 * (localviscsponge(nlci-spongearea + 1:nlci-1,1:jpjm1) + localviscsponge(nlci-spongearea + 1:nlci-1,2:jpj))
+         ENDDO
+      ENDIF
+
+      IF ((nbondj == -1).OR.(nbondj == 2)) THEN
+         DO jj = 2, spongearea
+            localviscsponge(:,jj) = visc_dyn * (spongearea-jj)/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(:,2:spongearea-1,jk) = vmask(:,2:spongearea-1,jk) &
+               * 0.5 * (localviscsponge(:,2:spongearea-1) + localviscsponge(:,3:spongearea))
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(1:jpim1,2:spongearea,jk) = umask(1:jpim1,2:spongearea,jk) &
+               * 0.5 * (localviscsponge(1:jpim1,2:spongearea) + localviscsponge(2:jpi,2:spongearea))
+         ENDDO
+      ENDIF
+
+      IF ((nbondj == 1).OR.(nbondj == 2)) THEN
+         DO jj = nlcj-spongearea + 1,nlcj-1
+            localviscsponge(:,jj) = visc_dyn * (jj - (nlcj-spongearea+1))/real(spongearea-2)
+         ENDDO
+         DO jk = 1, jpkm1
+            vmasktemp(:,nlcj-spongearea + 1:nlcj-2,jk) = vmask(:,nlcj-spongearea + 1:nlcj-2,jk) &
+               * 0.5 * (localviscsponge(:,nlcj-spongearea + 1:nlcj-2) + localviscsponge(:,nlcj-spongearea + 2:nlcj-1))
+         ENDDO
+         DO jk = 1, jpkm1
+            umasktemp(1:jpim1,nlcj-spongearea + 1:nlcj-1,jk) = umask(1:jpim1,nlcj-spongearea + 1:nlcj-1,jk) &
+               * 0.5 * (localviscsponge(1:jpim1,nlcj-spongearea + 1:nlcj-1) + localviscsponge(2:jpi,nlcj-spongearea + 1:nlcj-1))
+         ENDDO
+      ENDIF
+
+      ubdiff = ubdiff * umasktemp
+      vbdiff = vbdiff * vmasktemp
+
+      hdivdiff = 0.
+      rotdiff = 0.
+
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div
+         !                                             ! --------
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1   ! vector opt.
+#if defined key_zco
+               hdivdiff(ji,jj,jk) = (  e2u(ji,jj) * ubdiff(ji,jj,jk) &
+                  - e2u(ji-1,jj  ) * ubdiff(ji-1,jj  ,jk)      &
+                  &               + e1v(ji,jj) * vbdiff(ji,jj,jk) - &
+                  &              e1v(ji  ,jj-1) * vbdiff(ji  ,jj-1,jk)  )   &
+                  &            / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               hdivdiff(ji,jj,jk) =   &
+                  (  e2u(ji,jj)*fse3u(ji,jj,jk) * & 
+                  ubdiff(ji,jj,jk) - e2u(ji-1,jj  )* &
+                  fse3u(ji-1,jj  ,jk)  * ubdiff(ji-1,jj  ,jk)       &
+                  + e1v(ji,jj)*fse3v(ji,jj,jk) * &
+                  vbdiff(ji,jj,jk) - e1v(ji  ,jj-1)* &
+                  fse3v(ji  ,jj-1,jk)  * vbdiff(ji  ,jj-1,jk)  )    &
+                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO
+         END DO
+
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1   ! vector opt.
+               rotdiff(ji,jj,jk) = (  e2v(ji+1,jj  ) * vbdiff(ji+1,jj  ,jk) - e2v(ji,jj) * vbdiff(ji,jj,jk)    &
+                  &              - e1u(ji  ,jj+1) * ubdiff(ji  ,jj+1,jk) + e1u(ji,jj) * ubdiff(ji,jj,jk)  ) &
+                  &           * fmask(ji,jj,jk) / ( e1f(ji,jj) * e2f(ji,jj) )
+            END DO
+         END DO
+
+      ENDDO
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1   ! vector opt.
+#if defined key_zco
+               ! horizontal diffusive trends
+               ze2u = rotdiff (ji,jj,jk)
+               ze1v = hdivdiff(ji,jj,jk)
+               zua = - (                ze2u                  - &
+                  rotdiff (ji,jj-1,jk) ) / e2u(ji,jj)   &
+                  + ( hdivdiff(ji+1,jj,jk) -     &
+                  ze1v                  ) / e1u(ji,jj)
+
+               zva = + (                ze2u                  - &
+                  rotdiff (ji-1,jj,jk) ) / e1v(ji,jj)   &
+                  + ( hdivdiff(ji,jj+1,jk) -       &
+                  ze1v                  ) / e2v(ji,jj)
+#else
+               ze2u = rotdiff (ji,jj,jk)*fse3f(ji,jj,jk)
+               ze1v = hdivdiff(ji,jj,jk)
+               ! horizontal diffusive trends
+               zua = - ( ze2u - rotdiff (ji,jj-1,jk)* &
+                  fse3f(ji,jj-1,jk) ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )   &
+                  + ( hdivdiff(ji+1,jj,jk) - ze1v      &
+                  ) / e1u(ji,jj)
+
+               zva = + ( ze2u - rotdiff (ji-1,jj,jk)* &
+                  fse3f(ji-1,jj,jk) ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )   &
+                  + ( hdivdiff(ji,jj+1,jk) - ze1v    &
+                  ) / e2v(ji,jj)
+#endif
+
+               ! add it to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+#endif
+
+   END SUBROUTINE Agrif_Sponge_dyn
+
+   SUBROUTINE agrif_sponge_init
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_sponge_init ***
+      !!---------------------------------------------
+      NAMELIST/namagrif/ visc_tra, visc_dyn
+      REWIND ( numnam )
+      READ   ( numnam, namagrif )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'agrif_sponge_init : agrif sponge parameters'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namagrif : set sponge parameters'
+         WRITE(numout,*) '             sponge coefficient for tracers =  ', visc_tra
+         WRITE(numout,*) '             sponge coefficient for dynamics = ', visc_dyn
+      ENDIF
+
+   END SUBROUTINE agrif_sponge_init
+
+   SUBROUTINE interptn(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interptn ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"       
+      
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      tabres(i1:i2,j1:j2,k1:k2) = tn(i1:i2,j1:j2,k1:k2)
+
+   END SUBROUTINE interptn
+
+   SUBROUTINE interpsn(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpsn ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"       
+      
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      tabres(i1:i2,j1:j2,k1:k2) = sn(i1:i2,j1:j2,k1:k2)
+
+   END SUBROUTINE interpsn
+
+
+   SUBROUTINE interpun(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpun ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"       
+      
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      tabres(i1:i2,j1:j2,k1:k2) = un(i1:i2,j1:j2,k1:k2)
+
+   END SUBROUTINE interpun
+
+   SUBROUTINE interpvn(tabres,i1,i2,j1,j2,k1,k2)
+      !!---------------------------------------------
+      !!   *** ROUTINE interpvn ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"       
+      
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+
+      tabres(i1:i2,j1:j2,k1:k2) = vn(i1:i2,j1:j2,k1:k2)
+
+   END SUBROUTINE interpvn
+
+#else
+CONTAINS
+
+   SUBROUTINE agrif_opa_sponge_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_OPA_sponge_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_opa_sponge : You should not have seen this print! error?'
+   END SUBROUTINE agrif_opa_sponge_empty
+#endif
+
+END MODULE agrif_opa_sponge
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 4536)
@@ -0,0 +1,402 @@
+#define TWO_WAY
+
+MODULE agrif_opa_update
+#if defined key_agrif
+   USE par_oce
+   USE oce
+   USE dom_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC Agrif_Update_Tra, Agrif_Update_Dyn
+
+   INTEGER, PARAMETER :: nbclineupdate = 3
+   INTEGER :: nbcline
+
+CONTAINS
+
+   SUBROUTINE Agrif_Update_Tra( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Update_Tra ***
+      !!---------------------------------------------
+      INTEGER, INTENT(in) :: kt
+
+      REAL :: ztab(jpi,jpj,jpk)
+
+      IF((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
+#if defined TWO_WAY
+      Agrif_UseSpecialValueInUpdate = .TRUE.
+      Agrif_SpecialValueFineGrid = 0.
+
+      IF (MOD(nbcline,nbclineupdate) == 0) THEN
+         CALL Agrif_Update_Variable(ztab,tn, procname=updateT)
+         CALL Agrif_Update_Variable(ztab,sn, procname=updateS)
+      ELSE
+         CALL Agrif_Update_Variable(ztab,tn,locupdate=(/0,2/), procname=updateT)
+         CALL Agrif_Update_Variable(ztab,sn,locupdate=(/0,2/), procname=updateS)
+      ENDIF
+
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+#endif
+
+   END SUBROUTINE Agrif_Update_Tra
+
+   SUBROUTINE Agrif_Update_Dyn( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Update_Dyn ***
+      !!---------------------------------------------
+      INTEGER, INTENT(in) :: kt
+
+      REAL(wp), DIMENSION(jpi,jpj) :: ztab2d
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztab
+
+      IF ((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) Return
+#if defined TWO_WAY
+
+      IF (mod(nbcline,nbclineupdate) == 0) THEN
+         CALL Agrif_Update_Variable(ztab,un,procname = updateU)
+         CALL Agrif_Update_Variable(ztab,vn,procname = updateV)
+      ELSE
+         CALL Agrif_Update_Variable(ztab,un,locupdate=(/0,1/),procname = updateU)
+         CALL Agrif_Update_Variable(ztab,vn,locupdate=(/0,1/),procname = updateV)         
+      ENDIF
+
+      CALL Agrif_Update_Variable(ztab2d,e1u,procname = updateU2d)
+      CALL Agrif_Update_Variable(ztab2d,e2v,procname = updateV2d)  
+
+      nbcline = nbcline + 1
+
+      Agrif_UseSpecialValueInUpdate = .TRUE.
+      Agrif_SpecialValueFineGrid = 0.
+      CALL Agrif_Update_Variable(ztab2d,sshn,procname = updateSSH)
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+
+
+      CALL Agrif_ChildGrid_To_ParentGrid()
+      CALL recompute_diags( kt )
+      CALL Agrif_ParentGrid_To_ChildGrid()
+
+#endif
+
+   END SUBROUTINE Agrif_Update_Dyn
+
+   SUBROUTINE recompute_diags( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE recompute_diags ***
+      !!---------------------------------------------
+      USE divcur
+      USE wzvmod
+      USE cla_div
+      USE  ocfzpt
+
+      INTEGER, INTENT(in) :: kt
+
+      ta = hdivb
+      sa = rotb
+      CALL oc_fz_pt
+      Call div_cur(kt)
+
+      hdivb = ta
+      rotb  = sa
+
+      IF( n_cla == 1 ) CALL div_cla( kt )
+      CALL wzv( kt )
+
+   END SUBROUTINE recompute_diags
+
+   SUBROUTINE updateT( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateT ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+      LOGICAL, iNTENT(in) :: before
+
+      INTEGER :: ji,jj,jk
+
+      IF (before) THEN
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj,jk) = tn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ELSE
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  IF( tabres(ji,jj,jk) .NE. 0. ) THEN
+                     tn(ji,jj,jk) = tabres(ji,jj,jk) * tmask(ji,jj,jk)
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updateT
+
+   SUBROUTINE updateS( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateS ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+      LOGICAL, iNTENT(in) :: before
+
+      INTEGER :: ji,jj,jk
+
+      IF (before) THEN
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj,jk) = sn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ELSE
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  IF (tabres(ji,jj,jk).NE.0.) THEN
+                     sn(ji,jj,jk) = tabres(ji,jj,jk) * tmask(ji,jj,jk)
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updateS
+
+   SUBROUTINE updateu( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateu ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+      LOGICAL, INTENT(in) :: before
+
+      INTEGER :: ji, jj, jk
+      REAL(wp) :: zrhoy
+
+      IF (before) THEN
+         zrhoy = Agrif_Rhoy()
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj,jk) = e2u(ji,jj) * un(ji,jj,jk)
+#if ! defined key_zco
+                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3u(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+         tabres = zrhoy * tabres
+      ELSE
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  un(ji,jj,jk) = tabres(ji,jj,jk) / (e2u(ji,jj))
+                  un(ji,jj,jk) = un(ji,jj,jk) * umask(ji,jj,jk)
+#if ! defined key_zco
+                  un(ji,jj,jk) = un(ji,jj,jk) / fse3u(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updateu
+
+   SUBROUTINE updatev( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updatev ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER :: i1,i2,j1,j2,k1,k2
+      INTEGER :: ji,jj,jk
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: tabres
+      LOGICAL :: before
+
+      REAL(wp) :: zrhox
+
+      IF (before) THEN
+         zrhox = Agrif_Rhox()
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj,jk) = e1v(ji,jj) * vn(ji,jj,jk)
+#if ! defined key_zco
+                  tabres(ji,jj,jk) = tabres(ji,jj,jk) * fse3v(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+         tabres = zrhox * tabres
+      ELSE
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  vn(ji,jj,jk) = tabres(ji,jj,jk) / (e1v(ji,jj))
+                  vn(ji,jj,jk) = vn(ji,jj,jk) * vmask(ji,jj,jk)
+#if ! defined key_zco
+                  vn(ji,jj,jk) = vn(ji,jj,jk) / fse3v(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updatev
+
+   SUBROUTINE updateu2d( tabres, i1, i2, j1, j2, before )
+      !!---------------------------------------------
+      !!          *** ROUTINE updateu2d ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      LOGICAL, INTENT(in) :: before
+
+      INTEGER :: ji, jj, jk
+      REAL(wp) :: zrhoy
+      REAL(wp) :: zhinv
+
+      IF (before) THEN
+         zrhoy = Agrif_Rhoy()
+         DO jk = 1,jpkm1
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj) = tabres(ji,jj) + fse3u(ji,jj,jk) * un(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) = tabres(ji,jj) * e2u(ji,jj)
+            END DO
+         END DO
+         tabres = zrhoy * tabres
+      ELSE
+         DO jj=j1,j2
+            DO ji=i1,i2
+               IF(umask(ji,jj,1) .NE. 0.) THEN             
+                  spgu(ji,jj) = 0.e0
+                  DO jk=1,jpk
+                     spgu(ji,jj) = spgu(ji,jj) + fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  END DO
+                  spgu(ji,jj) = spgu(ji,jj) * e2u(ji,jj)
+                  zhinv = (tabres(ji,jj)-spgu(ji,jj))/(hu(ji,jj)*e2u(ji,jj))
+                  Do jk=1,jpk              
+                     un(ji,jj,jk) = un(ji,jj,jk) + zhinv
+                     un(ji,jj,jk) = un(ji,jj,jk) * umask(ji,jj,jk)            
+                  END DO
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updateu2d
+
+   SUBROUTINE updatev2d( tabres, i1, i2, j1, j2, before )
+      !!---------------------------------------------
+      !!          *** ROUTINE updatev2d ***
+      !!---------------------------------------------
+
+      INTEGER, INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      LOGICAL, INTENT(in) :: before
+
+      INTEGER :: ji, jj, jk
+      REAL(wp) :: zrhox
+      REAL(wp) :: zhinv
+
+      IF (before) THEN
+         zrhox = Agrif_Rhox()
+         tabres = 0.e0
+         DO jk = 1,jpkm1
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  tabres(ji,jj) = tabres(ji,jj) + fse3v(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) = tabres(ji,jj) * e1v(ji,jj)
+            END DO
+         END DO
+         tabres = zrhox * tabres
+      ELSE
+         DO jj=j1,j2
+            DO ji=i1,i2
+               IF(vmask(ji,jj,1) .NE. 0.) THEN             
+                  spgv(ji,jj) = 0.
+                  DO jk=1,jpk
+                     spgv(ji,jj) = spgv(ji,jj) + fse3v(ji,jj,jk) * vn(ji,jj,jk)
+                  END DO
+                  spgv(ji,jj) = spgv(ji,jj) * e1v(ji,jj)
+                  zhinv = (tabres(ji,jj)-spgv(ji,jj))/(hv(ji,jj)*e1v(ji,jj))
+                  DO jk=1,jpk             
+                     vn(ji,jj,jk) = vn(ji,jj,jk) + zhinv
+                     vn(ji,jj,jk) = vn(ji,jj,jk) * vmask(ji,jj,jk)
+                  END DO
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updatev2d
+
+   SUBROUTINE updateSSH( tabres, i1, i2, j1, j2, before )
+      !!---------------------------------------------
+      !!          *** ROUTINE updateSSH ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      LOGICAL, INTENT(in) :: before
+
+      INTEGER :: ji, jj
+      REAL(wp) :: zrhox, zrhoy
+
+      IF (before) THEN
+         zrhox = Agrif_Rhox()
+         zrhoy = Agrif_Rhoy()
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) = e1t(ji,jj) * e2t(ji,jj) * sshn(ji,jj)
+            END DO
+         END DO
+         tabres = zrhox * zrhoy * tabres
+      ELSE
+         DO jj=j1,j2
+            DO ji=i1,i2
+               sshn(ji,jj) = tabres(ji,jj) / (e1t(ji,jj) * e2t(ji,jj))
+               sshn(ji,jj) = sshn(ji,jj) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE updateSSH
+
+#else
+CONTAINS
+   SUBROUTINE agrif_opa_update_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_opa_update_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_opa_update : You should not have seen this print! error?'
+   END SUBROUTINE agrif_opa_update_empty
+#endif
+END MODULE agrif_opa_update
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 4536)
@@ -0,0 +1,140 @@
+MODULE agrif_top_interp
+#if defined key_agrif && defined key_passivetrc
+   USE par_oce
+   USE oce
+   USE dom_oce      
+   USE sol_oce
+   USE trcstp
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC Agrif_trc
+
+   CONTAINS
+
+   SUBROUTINE Agrif_trc( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_trc ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"  
+#  include "vectopt_loop_substitute.h90"
+      
+      INTEGER, INTENT(in) :: kt
+
+      INTEGER :: ji,jj,jk,jn
+      REAL(wp) :: zrhox
+      REAL(wp) :: alpha1, alpha2, alpha3, alpha4
+      REAL(wp) :: alpha5, alpha6, alpha7
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) :: ztra
+      
+      IF (Agrif_Root()) RETURN
+
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      ztra = 0.e0
+
+      CALL Agrif_Bc_variable(ztra,trn)
+      Agrif_UseSpecialValue = .FALSE.
+
+      zrhox = Agrif_Rhox()
+
+      alpha1 = (zrhox-1.)/2.
+      alpha2 = 1.-alpha1
+
+      alpha3 = (zrhox-1)/(zrhox+1)
+      alpha4 = 1.-alpha3
+
+      alpha6 = 2.*(zrhox-1.)/(zrhox+1.)
+      alpha7 = -(zrhox-1)/(zrhox+3)
+      alpha5 = 1. - alpha6 - alpha7
+
+      IF ((nbondi == 1).OR.(nbondi == 2)) THEN
+         tra(nlci,:,:,:) = alpha1 * ztra(nlci,:,:,:) + alpha2 * ztra(nlci-1,:,:,:)
+         DO jn=1,jptra 
+            DO jk=1,jpk      
+               DO jj=1,jpj
+                  IF (umask(nlci-2,jj,jk).EQ.0.) THEN
+                     tra(nlci-1,jj,jk,jn) = tra(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
+                  ELSE
+                     tra(nlci-1,jj,jk,jn)=(alpha4*tra(nlci,jj,jk,jn)+alpha3*tra(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
+                     IF (un(nlci-2,jj,jk).GT.0.) THEN
+                        tra(nlci-1,jj,jk,jn)=(alpha6*tra(nlci-2,jj,jk,jn)+alpha5*tra(nlci,jj,jk,jn) &
+                           +alpha7*tra(nlci-3,jj,jk,jn))*tmask(nlci-1,jj,jk)
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      IF ((nbondj == 1).OR.(nbondj == 2)) THEN
+         tra(:,nlcj,:,:) = alpha1 * ztra(:,nlcj,:,:) + alpha2 * ztra(:,nlcj-1,:,:)
+         DO jn=1, jptra            
+            DO jk=1,jpk      
+               DO ji=1,jpi
+                  IF (vmask(ji,nlcj-2,jk).EQ.0.) THEN
+                     tra(ji,nlcj-1,jk,jn) = tra(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
+                  ELSE
+                     tra(ji,nlcj-1,jk,jn)=(alpha4*tra(ji,nlcj,jk,jn)+alpha3*tra(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
+                     IF (vn(ji,nlcj-2,jk) .GT. 0.) THEN
+                        tra(ji,nlcj-1,jk,jn)=(alpha6*tra(ji,nlcj-2,jk,jn)+alpha5*tra(ji,nlcj,jk,jn) &
+                           +alpha7*tra(ji,nlcj-3,jk,jn))*tmask(ji,nlcj-1,jk)
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      IF ((nbondi == -1).OR.(nbondi == 2)) THEN
+         tra(1,:,:,:) = alpha1 * ztra(1,:,:,:) + alpha2 * ztra(2,:,:,:)
+         DO jn=1, jptra
+            DO jk=1,jpk      
+               DO jj=1,jpj
+                  IF (umask(2,jj,jk).EQ.0.) THEN
+                     tra(2,jj,jk,jn) = tra(1,jj,jk,jn) * tmask(2,jj,jk)
+                  ELSE
+                     tra(2,jj,jk,jn)=(alpha4*tra(1,jj,jk,jn)+alpha3*tra(3,jj,jk,jn))*tmask(2,jj,jk)        
+                     IF (un(2,jj,jk).LT.0.) THEN
+                        tra(2,jj,jk,jn)=(alpha6*tra(3,jj,jk,jn)+alpha5*tra(1,jj,jk,jn) &
+                           +alpha7*tra(4,jj,jk,jn))*tmask(2,jj,jk)
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      IF ((nbondj == -1).OR.(nbondj == 2)) THEN
+         tra(:,1,:,:) = alpha1 * ztra(:,1,:,:) + alpha2 * ztra(:,2,:,:)
+         DO jn=1, jptra  
+            DO jk=1,jpk      
+               DO ji=1,jpi
+                  IF (vmask(ji,2,jk).EQ.0.) THEN
+                     tra(ji,2,jk,jn)=tra(ji,1,jk,jn) * tmask(ji,2,jk)
+                  ELSE
+                     tra(ji,2,jk,jn)=(alpha4*tra(ji,1,jk,jn)+alpha3*tra(ji,3,jk,jn))*tmask(ji,2,jk)
+                     IF (vn(ji,2,jk) .LT. 0.) THEN
+                        tra(ji,2,jk,jn)=(alpha6*tra(ji,3,jk,jn)+alpha5*tra(ji,1,jk,jn)&
+                           +alpha7*tra(ji,4,jk,jn))*tmask(ji,2,jk)
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+   END SUBROUTINE Agrif_trc
+
+#else
+CONTAINS
+   SUBROUTINE Agrif_TOP_Interp_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_Top_Interp_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_top_interp : You should not have seen this print! error?'
+   END SUBROUTINE Agrif_TOP_Interp_empty
+#endif
+END MODULE agrif_top_interp
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_update.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_update.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_top_update.F90	(revision 4536)
@@ -0,0 +1,94 @@
+#define TWO_WAY
+
+MODULE agrif_top_update
+
+#if defined key_agrif && defined key_passivetrc
+   USE par_oce
+   USE oce
+   USE dom_oce
+   USE trcstp
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC Agrif_Update_Trc
+
+   INTEGER, PARAMETER :: nbclineupdate = 3
+   INTEGER :: nbcline
+
+   CONTAINS
+
+   SUBROUTINE Agrif_Update_Trc( kt )
+      !!---------------------------------------------
+      !!   *** ROUTINE Agrif_Update_Trc ***
+      !!---------------------------------------------
+      INTEGER, INTENT(in) :: kt
+  
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) :: ztra
+
+      IF ((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
+
+#if defined TWO_WAY
+      Agrif_UseSpecialValueInUpdate = .TRUE.
+      Agrif_SpecialValueFineGrid = 0.
+ 
+     IF (MOD(nbcline,nbclineupdate) == 0) THEN
+         CALL Agrif_Update_Variable(ztra,trn, procname=updateTRC)
+      ELSE
+         CALL Agrif_Update_Variable(ztra,trn,locupdate=(/0,2/), procname=updateTRC)
+      ENDIF
+
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+#endif
+
+   END SUBROUTINE Agrif_Update_Trc
+
+   SUBROUTINE updateTRC(tabres,i1,i2,j1,j2,k1,k2,before)
+      !!---------------------------------------------
+      !!   *** ROUTINE UpdateTrc ***
+      !!---------------------------------------------
+#  include "domzgr_substitute.h90"
+
+      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
+      REAL, DIMENSION(i1:i2,j1:j2,k1:k2,jptra), INTENT(inout) :: tabres
+      LOGICAL, INTENT(in) :: before
+   
+      INTEGER :: ji,jj,jk,jn
+
+      DO jn=1, jptra  
+
+         IF (before) THEN
+            DO jk=k1,k2
+               DO jj=j1,j2
+                  DO ji=i1,i2
+                     tabres(ji,jj,jk,jn) = trn(ji,jj,jk,jn)
+                  ENDDO
+               ENDDO
+            ENDDO
+         ELSE
+            DO jk=k1,k2
+               DO jj=j1,j2
+                  DO ji=i1,i2
+                     IF (tabres(ji,jj,jk,jn).NE.0.) THEN
+                        trn(ji,jj,jk,jn) = tabres(ji,jj,jk,jn) * tmask(ji,jj,jk)
+                     ENDIF
+                  ENDDO
+               ENDDO
+            ENDDO
+         ENDIF
+
+      END DO
+
+   END SUBROUTINE updateTRC
+
+#else
+CONTAINS
+   SUBROUTINE agrif_top_update_empty
+      !!---------------------------------------------
+      !!   *** ROUTINE agrif_Top_update_empty ***
+      !!---------------------------------------------
+      WRITE(*,*)  'agrif_top_update : You should not have seen this print! error?'
+   END SUBROUTINE agrif_top_update_empty
+#endif
+END Module agrif_top_update
Index: /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_user.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/NST_SRC/agrif_user.F90	(revision 4536)
@@ -0,0 +1,347 @@
+#if defined key_agrif
+   SUBROUTINE Agrif_InitWorkspace
+      !!------------------------------------------
+      !!   *** ROUTINE Agrif_InitWorkspace ***
+      !!------------------------------------------ 
+      USE par_oce
+      USE dom_oce
+      USE Agrif_Util
+
+      IMPLICIT NONE
+      
+#if defined key_mpp_dyndist
+      CHARACTER(len=20) :: namelistname
+      INTEGER nummpp
+      NAMELIST/nam_mpp_dyndist/jpni,jpnj,jpnij
+
+      IF (Agrif_Nbstepint() .EQ. 0) THEN
+        nummpp = Agrif_Get_Unit()
+        namelistname='namelist'
+        IF (.NOT. Agrif_Root()) namelistname=TRIM(Agrif_CFixed())//'_namelist'
+        OPEN(nummpp,file=namelistname,status='OLD',form='formatted')
+        READ (nummpp,nam_mpp_dyndist)
+        CLOSE(nummpp)
+      ENDIF
+#endif
+
+      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
+         jpim1 = jpi-1
+         jpjm1 = jpj-1
+         jpkm1 = jpk-1                                        
+         jpij  = jpi*jpj
+         jpidta = jpiglo
+         jpjdta = jpjglo
+         jpizoom = 1
+         jpjzoom = 1
+         nperio = 0
+         jperio = 0
+      ENDIF
+
+   END SUBROUTINE Agrif_InitWorkspace
+
+   !
+   SUBROUTINE Agrif_InitValues
+      !!------------------------------------------
+      !!   *** ROUTINE Agrif_InitValues ***
+      !!
+      !! ** Purpose :: Declaration of variables to
+      !!               be interpolated
+      !!------------------------------------------
+      USE Agrif_Util
+      USE oce 
+      USE dom_oce
+      USE opa
+      USE sms
+#if defined key_tradmp   ||   defined key_esopa
+      USE tradmp
+#endif
+      USE sol_oce
+      USE in_out_manager
+#if defined key_ice_lim
+      USE ice_oce
+#endif
+#if defined key_agrif
+      USE agrif_opa_update
+      USE agrif_opa_interp
+      USE agrif_opa_sponge
+      USE agrif_top_update
+      USE agrif_top_interp
+#endif
+
+      IMPLICIT NONE
+
+      REAL(wp) :: tabtemp(jpi,jpj,jpk)
+#if defined key_passivetrc
+      REAL(wp) :: tabtrtemp(jpi,jpj,jpk,jptra)
+#endif 
+      LOGICAL check_namelist
+
+      ! 0. Initializations
+      !-------------------
+#if defined key_orca_r025 || defined key_orca_r05 || defined key_orca_r2 || defined key_orca_r4
+      jp_cfg = -1    ! set special value for jp_cfg on fine grids
+      cp_cfg = "default"
+#endif
+
+      Call opa_init  ! Initializations of each fine grid
+
+      ! Specific fine grid Initializations
+#if defined key_tradmp || defined key_esopa
+      ! no tracer damping on fine grids
+      lk_tradmp = .FALSE.
+#endif
+      ! 1. Declaration of the type of variable which have to be interpolated
+      !---------------------------------------------------------------------
+      Call Agrif_Set_type(un,(/1,2,0/),(/2,3,0/))
+      Call Agrif_Set_type(vn,(/2,1,0/),(/3,2,0/))
+
+      Call Agrif_Set_type(ua,(/1,2,0/),(/2,3,0/))
+      Call Agrif_Set_type(va,(/2,1,0/),(/3,2,0/))
+
+      Call Agrif_Set_type(e1u,(/1,2/),(/2,3/))
+      Call Agrif_Set_type(e2v,(/2,1/),(/3,2/))
+
+      Call Agrif_Set_type(tn,(/2,2,0/),(/3,3,0/))
+      Call Agrif_Set_type(sn,(/2,2,0/),(/3,3,0/)) 
+
+      Call Agrif_Set_type(tb,(/2,2,0/),(/3,3,0/))
+      Call Agrif_Set_type(sb,(/2,2,0/),(/3,3,0/)) 
+
+      Call Agrif_Set_type(ta,(/2,2,0/),(/3,3,0/))
+      Call Agrif_Set_type(sa,(/2,2,0/),(/3,3,0/))       
+
+      Call Agrif_Set_type(sshn,(/2,2/),(/3,3/))
+      Call Agrif_Set_type(gcb,(/2,2/),(/3,3/))
+
+#if defined key_passivetrc
+      Call Agrif_Set_type(trb,(/2,2,0,0/),(/3,3,0,0/))
+      Call Agrif_Set_type(trn,(/2,2,0,0/),(/3,3,0,0/))
+      Call Agrif_Set_type(tra,(/2,2,0,0/),(/3,3,0,0/))
+#endif
+      
+      ! 2. Space directions for each variables
+      !---------------------------------------
+      Call Agrif_Set_raf(un,(/'x','y','N'/))
+      Call Agrif_Set_raf(vn,(/'x','y','N'/))
+
+      Call Agrif_Set_raf(ua,(/'x','y','N'/))
+      Call Agrif_Set_raf(va,(/'x','y','N'/))
+
+      Call Agrif_Set_raf(e1u,(/'x','y'/))
+      Call Agrif_Set_raf(e2v,(/'x','y'/))
+
+      Call Agrif_Set_raf(tn,(/'x','y','N'/))
+      Call Agrif_Set_raf(sn,(/'x','y','N'/))
+
+      Call Agrif_Set_raf(tb,(/'x','y','N'/))
+      Call Agrif_Set_raf(sb,(/'x','y','N'/))
+
+      Call Agrif_Set_raf(ta,(/'x','y','N'/))
+      Call Agrif_Set_raf(sa,(/'x','y','N'/))      
+
+      Call Agrif_Set_raf(sshn,(/'x','y'/))
+      Call Agrif_Set_raf(gcb,(/'x','y'/))
+
+#if defined key_passivetrc
+      Call Agrif_Set_raf(trb,(/'x','y','N','N'/))
+      Call Agrif_Set_raf(trn,(/'x','y','N','N'/))
+      Call Agrif_Set_raf(tra,(/'x','y','N','N'/))
+#endif
+
+      ! 3. Type of interpolation
+      !------------------------- 
+      Call Agrif_Set_bcinterp(tn,interp=AGRIF_linear)
+      Call Agrif_Set_bcinterp(sn,interp=AGRIF_linear)
+
+      Call Agrif_Set_bcinterp(ta,interp=AGRIF_linear)
+      Call Agrif_Set_bcinterp(sa,interp=AGRIF_linear)
+
+      Call Agrif_Set_bcinterp(un,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      Call Agrif_Set_bcinterp(vn,interp1=AGRIF_ppm,interp2=Agrif_linear)
+
+      Call Agrif_Set_bcinterp(ua,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      Call Agrif_Set_bcinterp(va,interp1=AGRIF_ppm,interp2=Agrif_linear)
+
+      Call Agrif_Set_bcinterp(e1u,interp1=Agrif_linear,interp2=AGRIF_ppm)
+      Call Agrif_Set_bcinterp(e2v,interp1=AGRIF_ppm,interp2=Agrif_linear)
+
+#if defined key_passivetrc
+      Call Agrif_Set_bcinterp(trn,interp=AGRIF_linear)
+      Call Agrif_Set_bcinterp(tra,interp=AGRIF_linear)
+#endif
+
+      ! 4. Location of interpolation
+      !-----------------------------
+      Call Agrif_Set_bc(un,(/0,1/))
+      Call Agrif_Set_bc(vn,(/0,1/))
+
+      Call Agrif_Set_bc(e1u,(/0,0/))
+      Call Agrif_Set_bc(e2v,(/0,0/))
+
+      Call Agrif_Set_bc(tn,(/0,1/))
+      Call Agrif_Set_bc(sn,(/0,1/))
+
+      Call Agrif_Set_bc(ta,(/-3*Agrif_irhox(),0/))
+      Call Agrif_Set_bc(sa,(/-3*Agrif_irhox(),0/))
+
+      Call Agrif_Set_bc(ua,(/-2*Agrif_irhox(),0/))
+      Call Agrif_Set_bc(va,(/-2*Agrif_irhox(),0/))
+
+#if defined key_passivetrc
+      Call Agrif_Set_bc(trn,(/0,1/))
+      Call Agrif_Set_bc(tra,(/-3*Agrif_irhox(),0/))
+#endif
+
+      ! 5. Update type
+      !--------------- 
+      Call Agrif_Set_Updatetype(tn, update = AGRIF_Update_Average)
+      Call Agrif_Set_Updatetype(sn, update = AGRIF_Update_Average)
+
+      Call Agrif_Set_Updatetype(tb, update = AGRIF_Update_Average)
+      Call Agrif_Set_Updatetype(sb, update = AGRIF_Update_Average)
+
+      Call Agrif_Set_Updatetype(sshn, update = AGRIF_Update_Average)
+      Call Agrif_Set_Updatetype(gcb,update = AGRIF_Update_Average)
+
+#if defined key_passivetrc
+      Call Agrif_Set_Updatetype(trn, update = AGRIF_Update_Average)
+      Call Agrif_Set_Updatetype(trb, update = AGRIF_Update_Average)
+#endif
+
+      Call Agrif_Set_Updatetype(un,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
+      Call Agrif_Set_Updatetype(vn,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
+
+      Call Agrif_Set_Updatetype(e1u,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average)
+      Call Agrif_Set_Updatetype(e2v,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy)
+
+      ! 6. First interpolations of potentially non zero fields
+      !-------------------------------------------------------
+      Agrif_SpecialValue=0.
+      Agrif_UseSpecialValue = .TRUE.
+      Call Agrif_Bc_variable(tabtemp,tn,calledweight=1.)
+      Call Agrif_Bc_variable(tabtemp,sn,calledweight=1.)
+      Call Agrif_Bc_variable(tabtemp,un,calledweight=1.,procname=interpu)
+      Call Agrif_Bc_variable(tabtemp,vn,calledweight=1.,procname=interpv)
+
+      Call Agrif_Bc_variable(tabtemp,ta,calledweight=1.,procname=interptn)
+      Call Agrif_Bc_variable(tabtemp,sa,calledweight=1.,procname=interpsn)
+
+      Call Agrif_Bc_variable(tabtemp,ua,calledweight=1.,procname=interpun)
+      Call Agrif_Bc_variable(tabtemp,va,calledweight=1.,procname=interpvn)
+
+#if defined key_passivetrc
+      Call Agrif_Bc_variable(tabtrtemp,trn,calledweight=1.)
+      Call Agrif_Bc_variable(tabtrtemp,tra,calledweight=1.)
+#endif
+      Agrif_UseSpecialValue = .FALSE.
+
+      ! 7. Some controls
+      !-----------------
+      check_namelist = .true.
+            
+      IF( check_namelist ) THEN
+     
+         ! Check time steps           
+         IF( nint(Agrif_Rhot()) * nint(rdt) .ne. Agrif_Parent(rdt) ) THEN
+            WRITE(*,*) 'incompatible time step between grids'
+            WRITE(*,*) 'parent grid value : ',Agrif_Parent(rdt)
+            WRITE(*,*) 'child  grid value : ',nint(rdt)
+            WRITE(*,*) 'value on parent grid should be : ',rdt*Agrif_Rhot()
+            STOP
+         ENDIF
+         
+         ! Check run length
+         IF( Agrif_IRhot() * (Agrif_Parent(nitend)- &
+            Agrif_Parent(nit000)+1) .ne. (nitend-nit000+1) ) THEN
+            WRITE(*,*) 'incompatible run length between grids'
+            WRITE(*,*) 'parent grid value : ',(Agrif_Parent(nitend)- &
+               Agrif_Parent(nit000)+1),' time step'
+            WRITE(*,*) 'child  grid value : ', &
+               (nitend-nit000+1),' time step'
+            WRITE(*,*) 'value on child grid should be : ', &
+               Agrif_IRhot() * (Agrif_Parent(nitend)- &
+               Agrif_Parent(nit000)+1)
+            STOP
+         ENDIF
+         
+         ! Check coordinates
+         IF( ln_zps ) THEN
+            ! check parameters for partial steps 
+            IF( Agrif_Parent(e3zps_min) .ne. e3zps_min ) THEN
+               WRITE(*,*) 'incompatible e3zps_min between grids'
+               WRITE(*,*) 'parent grid :',Agrif_Parent(e3zps_min)
+               WRITE(*,*) 'child grid  :',e3zps_min
+               WRITE(*,*) 'those values should be identical'
+               STOP
+            ENDIF          
+            IF( Agrif_Parent(e3zps_rat) .ne. e3zps_rat ) THEN
+               WRITE(*,*) 'incompatible e3zps_rat between grids'
+               WRITE(*,*) 'parent grid :',Agrif_Parent(e3zps_rat)
+               WRITE(*,*) 'child grid  :',e3zps_rat
+               WRITE(*,*) 'those values should be identical'                  
+               STOP
+            ENDIF
+         ENDIF
+
+      ENDIF
+
+      CALL Agrif_Update_tra(0)
+      CALL Agrif_Update_dyn(0)
+
+      nbcline = 0
+
+   END SUBROUTINE Agrif_InitValues
+   !
+   
+SUBROUTINE Agrif_detect(g,sizex)
+      !!------------------------------------------
+      !!   *** ROUTINE Agrif_detect ***
+      !!------------------------------------------
+      USE Agrif_Types
+ 
+      INTEGER, DIMENSION(2) :: sizex
+      INTEGER, DIMENSION(sizex(1),sizex(2)) :: g 
+
+      Return
+
+   End SUBROUTINE Agrif_detect
+
+#if defined key_mpp_mpi
+
+   SUBROUTINE Agrif_InvLoc(indloc,nprocloc,i,indglob)
+      !!------------------------------------------
+      !!   *** ROUTINE Agrif_detect ***
+      !!------------------------------------------
+      USE dom_oce
+      
+      IMPLICIT NONE
+
+      INTEGER :: indglob,indloc,nprocloc,i
+
+      SELECT CASE(i)
+      CASE(1)
+         indglob = indloc + nimppt(nprocloc+1) - 1
+      CASE(2)
+         indglob = indloc + njmppt(nprocloc+1) - 1 
+      CASE(3)
+         indglob = indloc
+      CASE(4)
+         indglob = indloc
+      END SELECT
+
+   END SUBROUTINE Agrif_InvLoc
+
+#endif
+
+#else
+   SUBROUTINE Subcalledbyagrif
+      !!------------------------------------------
+      !!   *** ROUTINE Subcalledbyagrif ***
+      !!------------------------------------------
+      WRITE(*,*) 'Impossible to be here'
+   END SUBROUTINE Subcalledbyagrif
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DIA/dianam.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DIA/dianam.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DIA/dianam.F90	(revision 4536)
@@ -0,0 +1,330 @@
+MODULE dianam
+   !!======================================================================
+   !!                       ***  MODULE  dianam  ***
+   !! Ocean diagnostics:  Builds output file name
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dia_nam       : Builds output file name
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_nam   ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_nam( cdfnam, kfreq, cdsuff )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_nam  ***
+      !!                   
+      !! ** Purpose :   Builds output file name
+      !!
+      !! ** Method  :   File name is a function of date and output frequency
+      !!      cdfnam=<cexper>_<clave>_<idtbeg>_<idtend>_grid_<cdsuff>
+      !!      <clave> = averaging frequency (DA, MO, etc...)
+      !!      <idtbeg>,<idtend> date of beginning and end of run
+      !!
+      !! History :
+      !!        !  99-02  (E. Guilyardi)  Creation for 30 days/month
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER (len=*), INTENT( out ) ::   cdfnam   ! file name
+      CHARACTER (len=*), INTENT( in  ) ::   cdsuff   ! ???
+      INTEGER,           INTENT( in  ) ::   kfreq    ! ???
+
+      !! * Local declarations
+      CHARACTER (len=8) ::   clexper
+      CHARACTER (len=2) ::   clave
+      CHARACTER (len=5) ::   clout
+      CHARACTER (len=6) ::   clsuff
+      INTEGER :: jt, jc, jd, je            ! dummy loop indices
+      INTEGER ::   &
+         ic, id, ie, ig, ijjmm, iout,   &  ! temporary integers
+         iyear1, imonth1, iday1,        &  !    "          "
+         iyear2, imonth2, iday2            !    "          "
+      REAL(wp) ::   &
+         z5j, znbsec, zdate1, zdate2, zdrun, zdt   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' dia_nam: building output file name'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+
+      ! 0. Initialisation
+      ! -----------------
+
+      cdfnam = ''
+
+      !    number of seconds of the run
+
+      z5j = 5*rjjss
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+      zdrun = FLOAT( nitend - nit000 ) * zdt
+
+      !  date of beginning of run
+
+      iyear1  = ndastp/10000
+      imonth1 = ndastp/100 - iyear1*100
+      iday1   = ndastp - imonth1*100 - iyear1*10000
+      IF( nleapy == 1) THEN 
+         ijjmm=0
+         IF( MOD( iyear1, 4 ) == 0 ) THEN
+            DO jt = 1, imonth1-1
+               ijjmm = ijjmm + nbiss(jt)
+            END DO
+         ELSE
+            DO jt = 1, imonth1-1
+               ijjmm = ijjmm + nobis(jt)
+            END DO
+         ENDIF
+         ijjmm = ijjmm + (iyear1-1)/4
+         zdate1 = ( (iyear1-1)*365 + ijjmm +iday1-1 ) * rjjss   
+      ELSE IF( nleapy == 0 ) THEN
+         ijjmm = 0
+         DO jt = 1, imonth1-1
+            ijjmm = ijjmm + nobis(jt)
+         END DO
+         zdate1 = ( (iyear1-1)*raajj + ijjmm + iday1-1)* rjjss
+      ELSE 
+         zdate1 = ( (iyear1-1)*nleapy*raamo + (imonth1-1)*nleapy + iday1-1)* rjjss
+      ENDIF
+
+      !  date of end of run (= date of beginning of next run)
+
+      zdate2 = zdate1 + zdrun
+      IF( nleapy == 1 ) THEN 
+         iyear2 = zdate2/(365.25*rjjss)+1
+         ijjmm = INT(zdate2/rjjss)-365*(iyear2-1)-(iyear2-1)/4
+         IF( ijjmm < 0 ) THEN
+            iyear2 = iyear2-1
+            ijjmm = zdate2/rjjss-365.*(iyear2-1)-(iyear2-1)/4
+         ENDIF
+         IF( MOD( iyear2, 4 ) == 0 ) THEN
+            DO jt = 1, 12
+               ijjmm = ijjmm - nbiss(jt)
+               IF( ijjmm <= 0 ) go to 10
+            END DO
+            jt = 12
+10          CONTINUE
+            imonth2 = jt
+            ijjmm = 0
+            DO jt = 1, jt-1
+               ijjmm = ijjmm + nbiss(jt)
+            END DO
+         ELSE
+            DO jt = 1, 12
+               ijjmm = ijjmm - nobis(jt)
+               IF( ijjmm <= 0 ) go to 15
+            END DO
+            jt = 12
+15          CONTINUE
+            imonth2 = jt
+            ijjmm = 0
+            DO jt = 1, jt-1
+               ijjmm = ijjmm + nobis(jt)
+            END DO
+         ENDIF
+         iday2 = zdate2/rjjss-365.*(iyear2-1)-ijjmm+1-(iyear2-1)/4     
+      ELSE IF( nleapy == 0 ) THEN
+         iyear2 = zdate2/raass+1
+         ijjmm  = zdate2/rjjss-raajj*(iyear2-1)
+         DO jt = 1, 12
+            ijjmm = ijjmm - nobis(jt)
+            IF(ijjmm <= 0) go to 20
+         END DO
+         jt = 12
+20       CONTINUE
+         imonth2 = jt
+         ijjmm = 0
+         DO jt = 1, jt-1
+            ijjmm = ijjmm + nobis(jt)
+         END DO
+         iday2 = zdate2/rjjss-raajj*(iyear2-1)-ijjmm+1          
+      ELSE 
+         zdate2 = zdate2 / rjjss
+         imonth2 = zdate2/FLOAT(nleapy)
+         iday2 = zdate2 - imonth2*FLOAT(nleapy) + 1.
+         iyear2 = imonth2/12
+         imonth2 = imonth2 - iyear2*12
+         imonth2 = imonth2 + 1
+         iyear2 = iyear2 + 1
+         IF( iday2 == 0 ) THEN
+            iday2 = nleapy
+            imonth2 = imonth2 - 1
+            IF( imonth2 == 0 ) THEN
+               imonth2 = 12
+               iyear2 = iyear2 - 1
+            ENDIF
+         ENDIF
+      ENDIF
+
+
+      ! 1. Define time averaging period <nn><type>
+      !    ---------------------------------------
+
+      iout = 0
+#if defined key_diainstant
+      clave = 'IN'
+      IF( iyear2 <= 99 ) THEN 
+         WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE IF( iyear2 <= 999 ) THEN 
+         WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE IF( iyear2 <= 9999 ) THEN 
+         WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE
+         WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ENDIF
+#else
+
+      znbsec=kfreq*zdt
+      ! daily output
+      IF( znbsec == rjjss ) THEN
+         clave = '1d'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! 5 day output 
+      ELSE IF( znbsec == z5j ) THEN
+         clave='5d'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! monthly ouput 
+      ELSE IF( (znbsec == rmoss .AND. nleapy > 1) .OR.   &
+               (znbsec >= 28*rjjss .AND. znbsec <= 31*rjjss .AND. nleapy <= 1) ) THEN
+         clave = '1m'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! annual output
+      ELSE IF( (znbsec == raass .AND. nleapy > 1) .OR.   &
+               (znbsec >= 365*rjjss .AND. znbsec <= 366*rjjss .AND. nleapy <= 1) ) THEN
+         clave = '1y'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+      ELSE
+         ! others
+         iout = kfreq
+         ig = 0
+         clout = ''
+         IF( iout <= 9 ) THEN 
+            ig = 1
+            WRITE(clout,'(i1.1)') iout
+         ELSE IF( iout <= 99 ) THEN 
+            ig = 2
+            WRITE(clout,'(i2.2)') iout
+         ELSE IF( iout <= 999 ) THEN 
+            ig = 3
+            WRITE(clout,'(i3.3)') iout
+         ELSE IF( iout <= 9999 ) THEN 
+            ig = 4
+            WRITE(clout,'(i4.4)') iout
+         ELSE
+            ig = 5
+            WRITE(clout,'(i5.5)') iout
+         ENDIF
+         clave = 'CU'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+      ENDIF
+#endif
+      DO jc = 1, 8
+         IF( cexper(jc:jc)==' ' ) go to 120
+      END DO
+120   CONTINUE
+      ic = jc
+      clexper = cexper
+      IF( jc-1 == 0 ) THEN
+         clexper = 'orcafile'
+         ic = 9
+      ENDIF
+      DO jd = 1, 6
+         IF( cdsuff(jd:jd) == ' ' ) go to 130
+      END DO
+130   CONTINUE
+      id = jd
+      clsuff = cdsuff
+      IF( jd-1 == 0 ) THEN
+          clsuff = 'output'
+          id = 7
+      ENDIF
+      DO je = 1, 45
+        IF( cdfnam(je:je) == ' ' ) go to 140
+      END DO
+140   CONTINUE
+      ie = je
+      IF( iout == 0 ) THEN 
+         cdfnam=clexper(1:ic-1)//"_"//clave//cdfnam(1:ie-1)//clsuff(1:id-1)
+      ELSE 
+         cdfnam=clexper(1:ic-1)//"_"//clave//clout(1:ig)//cdfnam(1:ie-1)//clsuff(1:id-1)
+      ENDIF
+      IF(lwp) WRITE(numout,*) cdfnam     
+      IF(lwp) WRITE(numout,*)          
+
+      ! FORMATS
+
+ 9001 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9002 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9003 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9004 FORMAT("_",I6.6,2I2.2,"_",I6.6,2I2.2,"_")
+ 9011 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9012 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9013 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9014 FORMAT("_",I6.6,I2.2,"_",I6.6,I2.2,"_")
+ 9021 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9022 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9023 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9024 FORMAT("_",I6.6,"_",I6.6,"_")
+
+   END SUBROUTINE dia_nam
+
+   !!======================================================================
+END MODULE dianam
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dom_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dom_oce.F90	(revision 4536)
@@ -0,0 +1,197 @@
+MODULE dom_oce
+   !!----------------------------------------------------------------------
+   !!                       ***  MODULE dom_oce  ***
+   !!       
+   !! ** Purpose :   Define in memory all the ocean space domain variables
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC           ! allows the acces to par_oce when dom_oce is used
+   !                ! exception to coding rules... to be suppressed ???
+
+   !!----------------------------------------------------------------------
+   !! space domain parameters
+   !! -----------------------
+   LOGICAL, PUBLIC ::   &   !:
+      lzoom      =  .FALSE. ,   &  !: zoom flag
+      lzoom_e    =  .FALSE. ,   &  !: East  zoom type flag
+      lzoom_w    =  .FALSE. ,   &  !: West  zoom type flag
+      lzoom_s    =  .FALSE. ,   &  !: South zoom type flag
+      lzoom_n    =  .FALSE. ,   &  !: North zoom type flag
+      lzoom_arct =  .FALSE. ,   &  !: ORCA    arctic zoom flag
+      lzoom_anta =  .FALSE.        !: ORCA antarctic zoom flag
+
+   INTEGER, PUBLIC ::           & !!: namdom : space domain (bathymetry, mesh)
+      nmsh    =  0                 !: = 1 create a mesh-mask file
+
+   INTEGER, PUBLIC ::         &   !:
+      ! domain parameters linked to mpp
+      nperio,          &  !: type of lateral boundary condition
+      nimpp, njmpp,    &  !: i- & j-indexes for mpp-subdomain left bottom
+      nreci, nrecj,    &  !: overlap region in i and j
+      nproc,           &  !: number for local processor
+      narea,           &  !: number for local area
+      nbondi, nbondj,  &  !: mark of i- and j-direction local boundaries
+      npolj,           &  !: north fold mark (0, 3 or 4)
+      nlci, nlcj,      &  !: i- & j-dimensions of the local subdomain
+      nldi, nlei,      &  !: first and last indoor i- and j-indexes
+      nldj, nlej,      &  !:
+      noea, nowe,      &  !: index of the local neighboring processors in
+      noso, nono,      &  !: east, west, south and north directions
+      npne, npnw,      &  !: index of north east and north west processor
+      npse, npsw,      &  !: index of south east and south west processor
+      nbne, nbnw,      &  !: logical of north east & north west processor
+      nbse, nbsw,      &  !: logical of south east & south west processor
+      nidom
+
+   INTEGER, PUBLIC, DIMENSION(jpi) ::   &   !:
+      mig                 !: local  ==> global  domain i-indice
+   INTEGER, PUBLIC, DIMENSION(jpj) ::   &   !:
+      mjg                 !: local  ==> global  domain j-indice
+   INTEGER, PUBLIC, DIMENSION( jpidta ) ::   &  !:  !!bug ==> other solution?
+      mi0, mi1            !: global ==> local domain i-indice
+      !                   !  (mi0=1 and mi1=0 if the global indice is not in the local domain)
+   INTEGER, PUBLIC, DIMENSION( jpjdta ) ::   &  !:
+      mj0, mj1            !: global ==> local domain j-indice
+      !                   ! (mi0=1 and mi1=0 if the global indice is not in the local domain)
+
+   INTEGER, PUBLIC, DIMENSION(jpnij) ::   &  !:
+      nimppt, njmppt,  &  !: i-, j-indexes for each processor
+      ibonit, ibonjt,  &  !: i-, j- processor neighbour existence
+      nlcit, nlcjt,    &  !: dimensions of every subdomain
+      nldit, nldjt,    &  !: first, last indoor index for each i-domain
+      nleit, nlejt        !: first, last indoor index for each j-domain
+
+   !!----------------------------------------------------------------------
+   !! horizontal curvilinear coordinate and scale factors
+   !! ---------------------------------------------------------------------
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      glamt, glamu,    &  !: longitude of t-, u-, v- and f-points (degre)
+      glamv, glamf,    &  !:
+      gphit, gphiu,    &  !: latitude  of t-, u-, v- and f-points (degre)
+      gphiv, gphif,    &  !:
+      e1t, e2t,        &  !: horizontal scale factors at t-point (m)
+      e1u, e2u,        &  !: horizontal scale factors at u-point (m)
+      e1v, e2v,        &  !: horizontal scale factors at v-point (m)
+      ff                  !: coriolis factor (2.*omega*sin(yphi) ) (s-1)
+
+
+   !!----------------------------------------------------------------------
+   !! vertical coordinate and scale factors
+   !! --------------------------------------
+
+   LOGICAL, PUBLIC ::           & !!: namzgr : vertical coordinate
+      ln_zco     =  .TRUE.  ,   &  !: z-coordinate - full step
+      ln_zps     =  .FALSE. ,   &  !: z-coordinate - partial step
+      ln_sco     =  .FALSE.        !: s-coordinate or hybrid z-s coordinate
+
+#if defined key_zco
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zco = .TRUE.    !: z-coordinate flag (1D arrays)
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zco = .FALSE.   !: z-coordinate flag (3D arrays)
+
+   !! All coordinates
+   !! ---------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      gdep3w        ,    &  !: depth of T-points (sum of e3w) (m)
+      gdept , gdepw ,    &  !: analytical depth at T-W  points (m)
+      e3v   , e3f   ,    &  !: analytical vertical scale factors at  V--F
+      e3t   , e3u   ,    &  !:                                       T--U  points (m)
+      e3vw          ,    &  !: analytical vertical scale factors at  VW--
+      e3w   , e3uw          !:                                        W--UW  points (m)
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      hur, hvr,          &  !: inverse of u and v-points ocean depth (1/m)
+      hu , hv               !: depth at u- and v-points (meters)
+
+   !! z-coordinate with full steps (also used in the other cases as reference z-coordinate)
+   !! =-----------------====------
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      gdept_0, gdepw_0,       &  !: reference depth of t- and w-points (m)
+      e3t_0  , e3w_0             !: reference vertical scale factors at T- and W-pts (m)
+
+   !! z-coordinate with partial steps
+   !! =-----------------=======------
+   REAL(wp), PUBLIC ::      & !!: * namelist namdom *
+      e3zps_min = 5.0_wp,   &  !: miminum thickness for partial steps (meters)
+      e3zps_rat = 0.1_wp       !: minimum thickness ration for partial steps
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      hdept, hdepw, e3tp, e3wp   !: ???
+
+   !! s-coordinate and hybrid z-s-coordinate
+   !! =----------------======---------------
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &   !:
+      gsigt, gsigw ,   &  !: model level depth coefficient at t-, w-levels (analytic)
+      gsi3w        ,   &  !: model level depth coefficient at w-level (sum of gsigw)
+      esigt, esigw        !: vertical scale factor coef. at t-, w-levels
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      hbatv , hbatf ,   &  !: ocean depth at the vertical of  V--F
+      hbatt , hbatu ,   &  !:                                 T--U  points (m)
+      scosrf, scobot,   &  !:  ocean surface and bottom topographies (if deviating from coordinate surfaces in HYBRID)
+      hifv  , hiff  ,   &  !: interface depth between stretching    at  V--F
+      hift  , hifu         !: and quasi-uniform spacing                 T--U  points (m)
+
+
+   !!----------------------------------------------------------------------
+   !! masks, bathymetry
+   !! -----------------
+
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      mbathy         !: number of ocean level (=0, 1, ... , jpk-1)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      tmask_i           !: interior domain T-point mask
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      tmask, umask,    &  !: land/ocean mask at T-, U-, V- and F-points
+      vmask, fmask        !:
+
+   REAL(wp), PUBLIC, DIMENSION(jpiglo) ::   &   !:
+      tpol                !: north fold mask (nperio= 3 or 4)
+
+   !!----------------------------------------------------------------------
+   !! time domain
+   !!----------------------------------------------------------------------
+   INTEGER, PUBLIC ::    & !!: * Namelist * ???
+      nacc   = 0 ,       &  !: = 0/1 use of the acceleration of convergence technique
+      neuler                !: restart euler forward option (0=Euler)
+
+
+   REAL(wp), PUBLIC ::       & !!: * Namelist ??? *
+      rdt    = 3600._wp ,    &  !: time step for the dynamics (and tracer if nacc=0)
+      rdtmin = 3600._wp ,    &  !: minimum time step on tracers
+      rdtmax = 3600._wp ,    &  !: maximum time step on tracers
+      rdth   =  800._wp ,    &  !: depth variation of tracer step
+      atfp   = 0.1_wp   ,    &  !: asselin time filter parameter
+      atfp1                     !: asselin time filter coeff. (atfp1= 1-2*atfp)
+
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      rdttra                    !: vertical profile of tracer time step
+
+   !!----------------------------------------------------------------------
+   !! cross land advection
+   !!----------------------------------------------------------------------
+
+   INTEGER, PUBLIC ::       & !!: namelist ???
+      n_cla                    !: flag (0/1) for cross land advection to
+      !                        ! parameterize exchanges through straits
+
+#if defined key_off_degrad
+   !! ------------------------------------------------
+   !! Degradation method
+   !! --------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk) :: &
+      facvol  !! volume for degraded regions
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE dom_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domain.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domain.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domain.F90	(revision 4536)
@@ -0,0 +1,397 @@
+MODULE domain
+   !!==============================================================================
+   !!                       ***  MODULE domain   ***
+   !! Ocean initialization : domain initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_init       : initialize the space and time domain
+   !!   dom_nam        : read and contral domain namelists
+   !!   dom_ctl        : control print for the ocean domain
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! 
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE lib_mpp         ! distributed memory computing library
+
+   USE domstp          ! domain: set the time-step
+   USE domrea          ! domain: write the meshmask file
+   USE dommsk          ! domain : mask
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_init       ! called by opa.F90
+
+   !! * Module variables
+      REAL(wp) ::          & !!: Namelist nam_zgr_sco
+      sbot_min =  300.  ,  &  !: minimum depth of s-bottom surface (>0) (m)
+      sbot_max = 5250.  ,  &  !: maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+      theta    =    6.0 ,  &  !: surface control parameter (0<=theta<=20)
+      thetb    =    0.75,  &  !: bottom control parameter  (0<=thetb<= 1)
+      r_max    =    0.15      !: maximum cut-off r-value allowed (0<r_max<1)
+
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_init  ***
+      !!                    
+      !! ** Purpose :   Domain initialization. Call the routines that are 
+      !!      required to create the arrays which define the space and time
+      !!      domain of the ocean model.
+      !!
+      !! ** Method  :
+      !!      - dom_stp: defined the model time step
+      !!      - dom_rea: read the meshmask file if nmsh=1
+      !!
+      !! History :
+      !!        !  90-10  (C. Levy - G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-01  (M. Imbard) insert time step initialization
+      !!        !  96-06  (G. Madec) generalized vertical coordinate 
+      !!        !  97-02  (G. Madec) creation of domwri.F
+      !!        !  01-05  (E.Durand - G. Madec) insert closed sea
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   iconf = 0         ! temporary integers
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_init : domain initialization'
+         WRITE(numout,*) '~~~~~~~~'
+      ENDIF
+
+      CALL dom_nam                        ! read namelist ( namrun, namdom, namcla )
+
+      CALL dom_stp                        ! Time step
+
+      CALL dom_rea      ! Create a domain file
+
+      CALL dom_msk      ! Masks
+
+      CALL dom_ctl    ! Domain control
+
+   END SUBROUTINE dom_init
+
+
+   SUBROUTINE dom_nam
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_nam  ***
+      !!                    
+      !! ** Purpose :   read domaine namelists and print the variables.
+      !!
+      !! ** input   : - namrun namelist
+      !!              - namdom namelist
+      !!              - namcla namelist
+      !!
+      !! History :
+      !!   9.0  !  03-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+      INTEGER ::   ioptio = 0      ! temporary integer
+
+      NAMELIST/nam_run/ no    , cexper   , ln_rstart , nrstdt , nit000,          &
+         &             nitend, ndate0   , nleapy   , ninist , nstock,           &
+         &             nprint, nwrite   , ln_ctl , nictls, nictle,   &
+         &             njctls, njctle   , nbench   , isplt  , jsplt
+
+      NAMELIST/nam_zgr/ ln_zco, ln_zps, ln_sco
+
+      NAMELIST/nam_dom/ e3zps_min, e3zps_rat, nmsh  ,   &
+         &             nacc  , atfp     , rdt      , rdtmin , rdtmax,   &
+         &             rdth 
+
+      NAMELIST/nam_cla/ n_cla
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_nam  : domain initialization through namelist read'
+         WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      ! Namelist namrun : parameters of the run
+      REWIND( numnam )
+      READ  ( numnam, nam_run )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '        Namelist namrun'
+         WRITE(numout,*) '           job number                      no        = ', no
+         WRITE(numout,*) '           experiment name for output      cexper    = ', cexper
+         WRITE(numout,*) '           restart logical                 ln_rstart = ', ln_rstart
+         WRITE(numout,*) '           control of time step            nrstdt    = ', nrstdt
+         WRITE(numout,*) '           number of the first time step   nit000    = ', nit000
+         WRITE(numout,*) '           number of the last time step    nitend    = ', nitend
+         WRITE(numout,*) '           initial calendar date aammjj    ndate0    = ', ndate0
+         WRITE(numout,*) '           leap year calendar (0/1)        nleapy    = ', nleapy
+         WRITE(numout,*) '           initial state output            ninist    = ', ninist
+         WRITE(numout,*) '           level of print                  nprint    = ', nprint
+         WRITE(numout,*) '           frequency of restart file       nstock    = ', nstock
+         WRITE(numout,*) '           frequency of output file        nwrite    = ', nwrite
+         WRITE(numout,*) '           run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '           Start i indice for SUM control  nictls    = ', nictls
+         WRITE(numout,*) '           End i indice for SUM control    nictle    = ', nictle
+         WRITE(numout,*) '           Start j indice for SUM control  njctls    = ', njctls
+         WRITE(numout,*) '           End j indice for SUM control    njctle    = ', njctle
+         WRITE(numout,*) '           number of proc. following i     isplt     = ', isplt
+         WRITE(numout,*) '           number of proc. following j     jsplt     = ', jsplt
+         WRITE(numout,*) '           benchmark parameter (0/1)       nbench    = ', nbench
+      ENDIF
+
+      ndastp = ndate0                ! Assign initial date to current date
+
+! ... Control the sub-domain area indices for the print control
+      IF(ln_ctl)   THEN
+         IF( lk_mpp ) THEN
+            ! the domain is forced to the real splitted domain in MPI
+            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               IF(lwp) WRITE(numout,cform_war)
+               IF(lwp) WRITE(numout,*)'          - isplt & jsplt are equal to 1'
+               IF(lwp) WRITE(numout,*)'          - the print control will be done over the whole domain'
+               IF(lwp) WRITE(numout,*)
+            ENDIF
+
+            ! compute the total number of processors ijsplt
+            ijsplt = isplt*jsplt
+         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
+
+         ! Control the indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN
+            ! the print control is done over the default area
+            lsp_area = .FALSE.
+         ELSE
+            ! the print control is done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               IF(lwp) WRITE(numout,cform_war)
+               IF(lwp) WRITE(numout,*)'          - nictls must be 1<=nictls>=jpiglo, it is forced to 1'
+               IF(lwp) WRITE(numout,*)
+               nwarn = nwarn + 1
+               nictls = 1
+            ENDIF
+
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               IF(lwp) WRITE(numout,cform_war)
+               IF(lwp) WRITE(numout,*)'          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo'
+               IF(lwp) WRITE(numout,*)
+               nwarn = nwarn + 1
+               nictle = jpjglo
+            ENDIF
+
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               IF(lwp) WRITE(numout,cform_war)
+               IF(lwp) WRITE(numout,*)'          - njctls must be 1<=njctls>=jpjglo, it is forced to 1'
+               IF(lwp) WRITE(numout,*)
+               nwarn = nwarn + 1
+               njctls = 1
+            ENDIF
+
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               IF(lwp) WRITE(numout,cform_war)
+               IF(lwp) WRITE(numout,*)'          - njctle must be 1<=njctle>= jpjglo, it is forced to jpjglo'
+               IF(lwp) WRITE(numout,*)
+               nwarn = nwarn + 1
+               njctle = jpjglo
+            ENDIF
+
+         ENDIF          ! IF( nictls+nictle+njctls+njctle == 0 )
+       ENDIF            ! IF(ln_ctl)
+
+! ... Control of output frequency
+      IF ( nstock == 0 ) THEN
+          IF(lwp)WRITE(numout,cform_war)
+          IF(lwp)WRITE(numout,*) '           nstock = ', nstock, ' it is forced to ', nitend
+          nstock = nitend
+          nwarn = nwarn + 1
+      ENDIF
+      IF ( nwrite == 0 ) THEN
+          IF(lwp)WRITE(numout,cform_war)
+          IF(lwp)WRITE(numout,*) '           nwrite = ', nwrite, ' it is forced to ', nitend
+          nwrite = nitend
+          nwarn = nwarn + 1
+      ENDIF
+
+      SELECT CASE ( nleapy )   ! Choose calendar for IOIPSL
+      CASE (  1 ) 
+         CALL ioconf_calendar('gregorian')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "gregorian", i.e. leap year'
+      CASE (  0 )
+         CALL ioconf_calendar('noleap')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "noleap", i.e. no leap year'
+      CASE ( 30 )
+         CALL ioconf_calendar('360d')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "360d", i.e. 360 days in a year'
+      END SELECT
+
+      SELECT CASE ( nleapy )   ! year=raajj*days day=rjjhh*hours hour=rhhmm*minutes etc ...
+      CASE ( 1 )
+         raajj = 365.25
+         raass = raajj * rjjss
+         rmoss = raass/raamo
+      CASE ( 0 )
+         raajj = 365.
+         raass = raajj * rjjss
+         rmoss = raass/raamo
+      CASE DEFAULT
+         raajj = FLOAT( nleapy ) * raamo
+         raass =        raajj    * rjjss
+         rmoss = FLOAT( nleapy ) * rjjss
+      END SELECT
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           nb of days per year      raajj = ', raajj,' days'
+         WRITE(numout,*) '           nb of seconds per year   raass = ', raass, ' s'
+         WRITE(numout,*) '           nb of seconds per month  rmoss = ', rmoss, ' s'
+      ENDIF
+
+      ! Read Namelist nam_zgr : vertical coordinate'
+      ! ---------------------
+      REWIND ( numnam )
+      READ   ( numnam, nam_zgr )
+
+      ! Parameter control and print
+      ! ---------------------------
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'Namelist namzgr : vertical coordinate'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_zgr : set vertical coordinate'
+         WRITE(numout,*) '             z-coordinate - full steps      ln_zco = ', ln_zco
+         WRITE(numout,*) '             z-coordinate - partial steps   ln_zps = ', ln_zps
+         WRITE(numout,*) '             s- or hybrid z-s-coordinate    ln_sco = ', ln_sco
+      ENDIF
+
+      ! Check Vertical coordinate options
+      ioptio = 0
+      IF( ln_zco ) ioptio = ioptio + 1
+      IF( ln_zps ) ioptio = ioptio + 1
+      IF( ln_sco ) ioptio = ioptio + 1
+      IF ( ioptio /= 1 ) CALL ctl_stop( ' none or several vertical coordinate options used' )
+
+      IF( ln_zco ) THEN
+          IF(lwp) WRITE(numout,*) '          z-coordinate with reduced incore memory requirement'
+          IF( ln_zps .OR. ln_sco ) CALL ctl_stop( ' reduced memory with zps or sco option is impossible' )
+      ENDIF
+
+
+      ! Namelist namdom : space/time domain (bathymetry, mesh, timestep)
+      REWIND( numnam )
+      READ  ( numnam, nam_dom )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '        Namelist namdom'
+         WRITE(numout,*) '           minimum thickness of partial   e3zps_min = ', e3zps_min, ' (m)'
+         WRITE(numout,*) '              step level                  e3zps_rat = ', e3zps_rat
+         WRITE(numout,*) '           flag write mesh/mask file(s)   nmsh      = ', nmsh
+         WRITE(numout,*) '                = 0   no file created                 '
+         WRITE(numout,*) '                = 1   mesh_mask                       '
+         WRITE(numout,*) '                = 2   mesh and mask                   '
+         WRITE(numout,*) '                = 3   mesh_hgr, msh_zgr and mask      '
+         WRITE(numout,*) '           acceleration of converge       nacc      = ', nacc
+         WRITE(numout,*) '           asselin time filter parameter  atfp      = ', atfp
+         WRITE(numout,*) '           time step                      rdt       = ', rdt
+         WRITE(numout,*) '           minimum time step on tracers   rdtmin    = ', rdtmin
+         WRITE(numout,*) '           maximum time step on tracers   rdtmax    = ', rdtmax
+         WRITE(numout,*) '           depth variation tracer step    rdth      = ', rdth
+      ENDIF
+
+
+
+      ! Default values
+      n_cla = 0
+
+      ! Namelist cross land advection
+      REWIND( numnam )
+      READ  ( numnam, nam_cla )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '        Namelist namcla'
+         WRITE(numout,*) '           cross land advection        n_cla        = ',n_cla
+      ENDIF
+
+   END SUBROUTINE dom_nam
+
+
+   SUBROUTINE dom_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_ctl  ***
+      !!
+      !! ** Purpose :   Domain control.
+      !!
+      !! ** Method  :   compute and print extrema of masked scale factors
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)    Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   iimi1, ijmi1, iimi2, ijmi2, iima1, ijma1, iima2, ijma2
+      INTEGER, DIMENSION(2) ::   iloc      ! 
+      REAL(wp) ::   ze1min, ze1max, ze2min, ze2max
+      !!----------------------------------------------------------------------
+
+      ! Extrema of the scale factors
+
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'dom_ctl : extrema of the masked scale factors'
+      IF(lwp)WRITE(numout,*) '~~~~~~~'
+
+      IF (lk_mpp) THEN
+         CALL mpp_minloc( e1t(:,:), tmask(:,:,1), ze1min, iimi1,ijmi1 )
+         CALL mpp_minloc( e2t(:,:), tmask(:,:,1), ze2min, iimi2,ijmi2 )
+         CALL mpp_maxloc( e1t(:,:), tmask(:,:,1), ze1max, iima1,ijma1 )
+         CALL mpp_maxloc( e2t(:,:), tmask(:,:,1), ze2max, iima2,ijma2 )
+      ELSE
+         ze1min = MINVAL( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze2min = MINVAL( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze1max = MAXVAL( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze2max = MAXVAL( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+
+         iloc  = MINLOC( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iimi1 = iloc(1) + nimpp - 1
+         ijmi1 = iloc(2) + njmpp - 1
+         iloc  = MINLOC( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iimi2 = iloc(1) + nimpp - 1
+         ijmi2 = iloc(2) + njmpp - 1
+         iloc  = MAXLOC( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iima1 = iloc(1) + nimpp - 1
+         ijma1 = iloc(2) + njmpp - 1
+         iloc  = MAXLOC( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iima2 = iloc(1) + nimpp - 1
+         ijma2 = iloc(2) + njmpp - 1
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,"(14x,'e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, iima1, ijma1
+         WRITE(numout,"(14x,'e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, iimi1, ijmi1
+         WRITE(numout,"(14x,'e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, iima2, ijma2
+         WRITE(numout,"(14x,'e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, iimi2, ijmi2
+      ENDIF
+
+   END SUBROUTINE dom_ctl
+
+   !!======================================================================
+END MODULE domain
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domcfg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domcfg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domcfg.F90	(revision 4536)
@@ -0,0 +1,213 @@
+MODULE domcfg
+   !!==============================================================================
+   !!                       ***  MODULE domcfg   ***
+   !! Ocean initialization : domain configuration initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_cfg        : initialize the domain configuration
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_cfg        ! called by opa.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_cfg
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_cfg  ***
+      !!                    
+      !! ** Purpose :   set the domain configuration
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   iconf = 0         ! temporary integers
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_cfg : set the ocean configuration'
+         WRITE(numout,*) '~~~~~~~      ocean model configuration used :',   &
+            &                             ' cp_cfg = ', cp_cfg, ' jp_cfg = ', jp_cfg
+      ENDIF
+
+      ! Global domain boundary conditions
+      ! ---------------------------------
+      IF(lwp) THEN
+         WRITE(numout,*) '          global domain lateral boundaries'
+
+         IF( jperio == 0 ) WRITE(numout,*) '             jperio= 0, closed'
+         IF( jperio == 1 ) WRITE(numout,*) '             jperio= 1, cyclic east-west'
+         IF( jperio == 2 ) WRITE(numout,*) '             jperio= 2, equatorial symmetric'
+         IF( jperio == 3 ) WRITE(numout,*) '             jperio= 3, north fold with T-point pivot'
+         IF( jperio == 4 ) WRITE(numout,*) '             jperio= 4, cyclic east-west and',   &
+                                                                  ' north fold with T-point pivot'
+         IF( jperio == 5 ) WRITE(numout,*) '             jperio= 5, north fold with F-point pivot'
+         IF( jperio == 6 ) WRITE(numout,*) '             jperio= 6, cyclic east-west and',   &
+                                                                  ' north fold with F-point pivot'
+      ENDIF
+      IF( jperio <  0 .OR. jperio > 6 ) CALL ctl_stop( 'jperio is out of range' )
+
+      ! global domain versus zoom and/or local domain
+      ! ---------------------------------------------
+
+      CALL dom_glo 
+
+   END SUBROUTINE dom_cfg
+
+
+   SUBROUTINE dom_glo
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_glo  ***
+      !!
+      !! ** Purpose :   initialization for global domain, zoom and local domain
+      !!
+      !! ** Method  :   
+      !!
+      !! ** Action  : - mig  , mjg : 
+      !!              - mi0  , mi1   :
+      !!              - mj0, , mj1   :
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)    Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj            ! dummy loop argument
+      !!----------------------------------------------------------------------
+
+      ! Local domain 
+      ! ============
+
+      ! local domain indices ==> data domain indices
+      DO ji = 1, jpi
+        mig(ji) = ji + jpizoom - 1 + nimpp - 1
+      END DO
+      DO jj = 1, jpj
+        mjg(jj) = jj + jpjzoom - 1 + njmpp - 1
+      END DO
+
+      ! data domain indices ==> local domain indices
+      ! (return (m.0,m.1)=(1,0) if data domain gridpoint is to the west/south of the 
+      ! local domain, or (m.0,m.1)=(jp.+1,jp.) to the east/north of local domain. 
+      DO ji = 1, jpidta
+        mi0(ji) = MAX( 1, MIN( ji - jpizoom + 1 - nimpp + 1, jpi+1 ) )
+        mi1(ji) = MAX( 0, MIN( ji - jpizoom + 1 - nimpp + 1, jpi   ) )
+      END DO
+      DO jj = 1, jpjdta
+        mj0(jj) = MAX( 1, MIN( jj - jpjzoom + 1 - njmpp + 1, jpj+1 ) )
+        mj1(jj) = MAX( 0, MIN( jj - jpjzoom + 1 - njmpp + 1, jpj   ) )
+      END DO
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_glo : domain: data / local '
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          data input domain    : jpidta = ', jpidta,   &
+            &                                            ' jpjdta = ', jpjdta, ' jpkdta = ', jpkdta
+         WRITE(numout,*) '          global or zoom domain: jpiglo = ', jpiglo,   &
+            &                                            ' jpjglo = ', jpjglo, ' jpk    = ', jpk
+         WRITE(numout,*) '          local domain         : jpi    = ', jpi   ,   &
+            &                                            ' jpj    = ', jpj   , ' jpk    = ', jpk
+         WRITE(numout,*)
+         WRITE(numout,*) '          south-west indices    jpizoom = ', jpizoom,   &
+            &                                           ' jpjzoom = ', jpjzoom
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion local  ==> data i-index domain'
+         WRITE(numout,25)              (mig(ji),ji = 1,jpi)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion data   ==> local  i-index domain'
+         WRITE(numout,*) '             starting index'
+         WRITE(numout,25)              (mi0(ji),ji = 1,jpidta)
+         WRITE(numout,*) '             ending index'
+         WRITE(numout,25)              (mi1(ji),ji = 1,jpidta)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion local  ==> data j-index domain'
+         WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion data  ==> local j-index domain'
+         WRITE(numout,*) '             starting index'
+         WRITE(numout,25)              (mj0(jj),jj = 1,jpjdta)
+         WRITE(numout,*) '             ending index'
+         WRITE(numout,25)              (mj1(jj),jj = 1,jpjdta)
+      ENDIF
+ 25   FORMAT( 100(10x,19i4,/) )
+
+      ! Zoom domain
+      ! ===========
+
+      ! zoom control
+      IF( jpiglo + jpizoom - 1  >  jpidta .OR.   &
+          jpjglo + jpjzoom - 1  >  jpjdta      ) &
+          &   CALL ctl_stop( ' global or zoom domain exceed the data domain ! ' )
+
+      ! set zoom flag
+      IF ( jpiglo < jpidta .OR. jpjglo < jpjdta )   lzoom = .TRUE.
+
+      ! set zoom type flags
+      IF( lzoom .AND. jpizoom /= 1 )   lzoom_w = .TRUE.                     ! 
+      IF( lzoom .AND. jpjzoom /= 1 )   lzoom_s = .TRUE.
+      IF( lzoom .AND. jpiglo + jpizoom -1 /= jpidta )   lzoom_e = .TRUE.
+      IF( lzoom .AND. jpjglo + jpjzoom -1 /= jpjdta )   lzoom_n = .TRUE.
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          zoom flags : '
+         WRITE(numout,*) '             lzoom   = ', lzoom  , ' (T = zoom, F = global )'
+         WRITE(numout,*) '             lzoom_e = ', lzoom_e, ' (T = forced closed east  boundary)'
+         WRITE(numout,*) '             lzoom_w = ', lzoom_w, ' (T = forced closed west  boundary)'
+         WRITE(numout,*) '             lzoom_s = ', lzoom_s, ' (T = forced closed South boundary)'
+         WRITE(numout,*) '             lzoom_n = ', lzoom_n, ' (T = forced closed North boundary)'
+      ENDIF
+      IF(  ( lzoom_e .OR. lzoom_w )  .AND.  ( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 )  )   &
+           &   CALL ctl_stop( ' Your zoom choice is inconsistent with east-west cyclic boundary condition' )
+      IF(  lzoom_n  .AND.  ( 3 <= jperio .AND. jperio <= 6 )  )   &
+           &   CALL ctl_stop( ' Your zoom choice is inconsistent with North fold boundary condition' )
+
+
+      ! Pre-defined arctic/antarctic zoom of ORCA configuration flag
+      IF( cp_cfg == "orca" ) THEN
+         SELECT CASE ( jp_cfg )
+         !                                        ! =======================
+         CASE ( 2 )                               !  ORCA_R2 configuration
+            !                                     ! =======================
+            IF(  jpiglo  == 142    .AND. jpjglo  ==  53 .AND.   &
+               & jpizoom ==  21    .AND. jpjzoom ==  97         )   lzoom_arct = .TRUE.
+            IF(  jpiglo  == jpidta .AND. jpjglo  ==  50 .AND.   &
+               & jpizoom ==   1    .AND. jpjzoom ==   1         )   lzoom_anta = .TRUE.
+            !                                     ! =======================
+         CASE ( 05 )                              !  ORCA_R05 configuration
+            !                                     ! =======================
+            IF(  jpiglo  == 562    .AND. jpjglo  == 202 .AND.   &
+               & jpizoom ==  81    .AND. jpjzoom == 301         )   lzoom_arct = .TRUE.
+            IF(  jpiglo  == jpidta .AND. jpjglo  == 187 .AND.   &
+               & jpizoom ==   1    .AND. jpjzoom ==   1         )   lzoom_anta = .TRUE.
+         END SELECT
+         !
+         IF(lwp) WRITE(numout,*) '          ORCA configuration: antarctic/arctic zoom flags : '
+         IF(lwp) WRITE(numout,*) '             lzoom_arct = ', lzoom_arct, ' (T=   arctic zoom, F=global)'
+         IF(lwp) WRITE(numout,*) '             lzoom_anta = ', lzoom_anta, ' (T=antarctic zoom, F=global)'
+         !
+      ENDIF
+         
+   END SUBROUTINE dom_glo
+
+   !!======================================================================
+END MODULE domcfg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dommsk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dommsk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/dommsk.F90	(revision 4536)
@@ -0,0 +1,178 @@
+MODULE dommsk
+   !!==============================================================================
+   !!                       ***  MODULE dommsk   ***
+   !! Ocean initialization : domain land/sea mask 
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_msk        : compute land/ocean mask
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_msk        ! routine called by inidom.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE dom_msk
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dom_msk  ***
+      !!
+      !! ** Purpose :   Compute land/ocean mask arrays at tracer points, hori-
+      !!      zontal velocity points (u & v), vorticity points (f) and baro-
+      !!      tropic stream function  points (b).
+      !!        Set mbathy to the number of non-zero w-levels of a water column
+      !!      (if island in the domain (lk_isl=T), this is done latter in
+      !!      routine solver_init)
+      !!
+      !! ** Method  :   The ocean/land mask is computed from the basin bathy-
+      !!      metry in level (mbathy) which is defined or read in dommba.
+      !!      mbathy equals 0 over continental T-point, -n over the nth 
+      !!      island T-point, and the number of ocean level over the ocean.
+      !!
+      !!      At a given position (ji,jj,jk) the ocean/land mask is given by:
+      !!      t-point : 0. IF mbathy( ji ,jj) =< 0
+      !!                1. IF mbathy( ji ,jj) >= jk
+      !!      u-point : 0. IF mbathy( ji ,jj)  or mbathy(ji+1, jj ) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy(ji+1, jj ) >= jk.
+      !!      v-point : 0. IF mbathy( ji ,jj)  or mbathy( ji ,jj+1) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy( ji ,jj+1) >= jk.
+      !!      f-point : 0. IF mbathy( ji ,jj)  or mbathy( ji ,jj+1)
+      !!                   or mbathy(ji+1,jj)  or mbathy(ji+1,jj+1) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy( ji ,jj+1)
+      !!                and mbathy(ji+1,jj) and mbathy(ji+1,jj+1) >= jk.
+      !!      b-point : the same definition as for f-point of the first ocean
+      !!                level (surface level) but with 0 along coastlines.
+      !!
+      !!        The lateral friction is set through the value of fmask along
+      !!      the coast and topography. This value is defined by shlat, a
+      !!      namelist parameter:
+      !!         shlat = 0, free slip  (no shear along the coast)
+      !!         shlat = 2, no slip  (specified zero velocity at the coast)
+      !!         0 < shlat < 2, partial slip   | non-linear velocity profile
+      !!         2 < shlat, strong slip        | in the lateral boundary layer
+      !!
+      !!      N.B. If nperio not equal to 0, the land/ocean mask arrays
+      !!      are defined with the proper value at lateral domain boundaries,
+      !!      but bmask. indeed, bmask defined the domain over which the
+      !!      barotropic stream function is computed. this domain cannot
+      !!      contain identical columns because the matrix associated with
+      !!      the barotropic stream function equation is then no more inverti-
+      !!      ble. therefore bmask is set to 0 along lateral domain boundaries
+      !!      even IF nperio is not zero.
+      !!
+      !!      In case of open boundaries (lk_obc=T):
+      !!        - tmask is set to 1 on the points to be computed bay the open
+      !!          boundaries routines.
+      !!        - bmask is  set to 0 on the open boundaries.
+      !!
+      !!      Set mbathy to the number of non-zero w-levels of a water column
+      !!                  mbathy = min( mbathy, 1 ) + 1
+      !!      (note that the minimum value of mbathy is 2).
+      !!
+      !! ** Action :
+      !!                     tmask    : land/ocean mask at t-point (=0. or 1.)
+      !!                     umask    : land/ocean mask at u-point (=0. or 1.)
+      !!                     vmask    : land/ocean mask at v-point (=0. or 1.)
+      !!                     fmask    : land/ocean mask at f-point (=0. or 1.)
+      !!                          =shlat along lateral boundaries
+      !!                     bmask    : land/ocean mask at barotropic stream
+      !!                          function point (=0. or 1.) and set to
+      !!                          0 along lateral boundaries
+      !!                   mbathy   : number of non-zero w-levels 
+      !!
+      !! History :
+      !!        !  87-07  (G. Madec)  Original code
+      !!        !  91-12  (G. Madec)
+      !!        !  92-06  (M. Imbard)
+      !!        !  93-03  (M. Guyon)  symetrical conditions (M. Guyon)
+      !!        !  96-01  (G. Madec)  suppression of common work arrays
+      !!        !  96-05  (G. Madec)  mask computed from tmask and sup-
+      !!                 pression of the double computation of bmask
+      !!        !  97-02  (G. Madec)  mesh information put in domhgr.F
+      !!        !  97-07  (G. Madec)  modification of mbathy and fmask
+      !!        !  98-05  (G. Roullet)  free surface
+      !!        !  00-03  (G. Madec)  no slip accurate
+      !!        !  01-09  (J.-M. Molines)  Open boundaries
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! *Local declarations
+      INTEGER  ::   ji, jk     ! dummy loop indices
+      INTEGER  ::   iif, iil, ijf, ijl
+      INTEGER, DIMENSION(jpi,jpj) ::  imsk
+
+      !!---------------------------------------------------------------------
+      
+
+
+      ! Interior domain mask (used for global sum)
+      ! --------------------
+
+      tmask_i(:,:) = tmask(:,:,1)
+      iif = jpreci                         ! ???
+      iil = nlci - jpreci + 1
+      ijf = jprecj                         ! ???
+      ijl = nlcj - jprecj + 1
+
+      tmask_i( 1 :iif,   :   ) = 0.e0      ! first columns
+      tmask_i(iil:jpi,   :   ) = 0.e0      ! last  columns (including mpp extra columns)
+      tmask_i(   :   , 1 :ijf) = 0.e0      ! first rows
+      tmask_i(   :   ,ijl:jpj) = 0.e0      ! last  rows (including mpp extra rows)
+
+
+      ! north fold mask
+      tpol(1:jpiglo) = 1.e0 
+      IF( jperio == 3 .OR. jperio == 4 ) THEN      ! T-point pivot
+         tpol(jpiglo/2+1:jpiglo) = 0.e0
+      ENDIF
+      IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
+         tpol(     1    :jpiglo) = 0.e0
+      ENDIF
+
+      IF( jperio == 3 .OR. jperio == 4 ) THEN      ! T-point pivot: only half of the nlcj-1 row
+         if (mjg(ijl-1) == jpjglo-1) then
+         DO ji = iif+1, iil-1
+            tmask_i(ji,ijl-1) = tmask_i(ji,ijl-1) * tpol(mig(ji))
+         END DO
+         endif
+      ENDIF 
+
+      ! Control print
+      ! -------------
+      IF( nprint == 1 .AND. lwp ) THEN
+         imsk(:,:) = INT( tmask_i(:,:) )
+         WRITE(numout,*) ' tmask_i : '
+         CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                           1, jpj, 1, 1, numout)
+         WRITE (numout,*)
+         WRITE (numout,*) ' dommsk: tmask for each level'
+         WRITE (numout,*) ' ----------------------------'
+         DO jk = 1, jpk
+            imsk(:,:) = INT( tmask(:,:,jk) )
+
+            WRITE(numout,*)
+            WRITE(numout,*) ' level = ',jk
+            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                              1, jpj, 1, 1, numout)
+         END DO
+      ENDIF
+
+   END SUBROUTINE dom_msk
+
+END MODULE dommsk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea.F90	(revision 4536)
@@ -0,0 +1,309 @@
+MODULE domrea
+   !!======================================================================
+   !!                       ***  MODULE domrea  ***
+   !! Ocean initialization : read the ocean domain meshmask file(s)
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_rea        : read mesh and mask file(s)
+   !!                    nmsh = 1  :   mesh_mask file
+   !!                         = 2  :   mesh and mask file
+   !!                         = 3  :   mesh_hgr, mesh_zgr and mask
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dom_rea        ! routine called by inidom.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_fdir
+   !!----------------------------------------------------------------------
+   !!   'key_fdir' :                                     direct access file
+   !!----------------------------------------------------------------------
+#  include "domrea_fdir.h90"
+
+#elif ( defined key_mpp_mpi || defined key_mpp_shmem ) && defined key_dimgout
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR
+   !!   'key_mpp_shmem'
+   !!   'key_dimgout' :         each processor makes its own direct access file 
+   !!                      use build_nc_meshmask off line to retrieve 
+   !!                      a ioipsl compliant meshmask file
+   !!----------------------------------------------------------------------
+#  include "domrea_dimg.h90"
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                        NetCDF file
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dom_rea
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_rea  ***
+      !!                   
+      !! ** Purpose :  Read the NetCDF file(s) which contain(s) all the
+      !!      ocean domain informations (mesh and mask arrays). This (these)
+      !!      file(s) is (are) used for visualisation (SAXO software) and
+      !!      diagnostic computation.
+      !!
+      !! ** Method  :   Read in a file all the arrays generated in routines
+      !!      domhgr, domzgr, and dommsk. Note: the file contain depends on
+      !!      the vertical coord. used (z-coord, partial steps, s-coord)
+      !!                    nmsh = 1  :   'mesh_mask.nc' file
+      !!                         = 2  :   'mesh.nc' and mask.nc' files
+      !!                         = 3  :   'mesh_hgr.nc', 'mesh_zgr.nc' and
+      !!                                  'mask.nc' files
+      !!      For huge size domain, use option 2 or 3 depending on your 
+      !!      vertical coordinate.
+      !!
+      !! ** input file : 
+      !!      meshmask.nc  : domain size, horizontal grid-point position,
+      !!                     masks, depth and vertical scale factors
+      !!
+      !! History :
+      !!        !  97-02  (G. Madec)  Original code
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with IOIPSL
+      !!   9.0  !  02-08  (G. Madec)  F90 and several file
+      !!        !  06-07  (C. Ethe )  Use of iom module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk
+      INTEGER  ::                & !!! * temprary units for :
+         inum0 ,                 &  ! 'mesh_mask.nc' file
+         inum1 ,                 &  ! 'mesh.nc'      file
+         inum2 ,                 &  ! 'mask.nc'      file
+         inum3 ,                 &  ! 'mesh_hgr.nc'  file
+         inum4                      ! 'mesh_zgr.nc'  file
+ 
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zprt = 0.
+#if ! defined key_zco
+      INTEGER :: ik
+#endif
+      !!----------------------------------------------------------------------
+
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) 'dom_rea : read NetCDF mesh and mask information file(s)'
+       IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+
+
+      SELECT CASE (nmsh)
+         !                                     ! ============================
+         CASE ( 1 )                            !  create 'mesh_mask.nc' file
+            !                                  ! ============================
+
+            IF(lwp) WRITE(numout,*) '          one file in "mesh_mask.nc" '
+            CALL iom_open( 'mesh_mask', inum0 )
+
+            inum2 = inum0                                            ! put all the informations
+            inum3 = inum0                                            ! in unit inum0
+            inum4 = inum0
+
+            !                                  ! ============================
+         CASE ( 2 )                            !  create 'mesh.nc' and 
+            !                                  !         'mask.nc' files
+            !                                  ! ============================
+
+            IF(lwp) WRITE(numout,*) '          two files in "mesh.nc" and "mask.nc" '
+            CALL iom_open( 'mesh', inum1 )
+            CALL iom_open( 'mask', inum2 )
+
+            inum3 = inum1                                            ! put mesh informations 
+            inum4 = inum1                                            ! in unit inum1 
+
+            !                                  ! ============================
+         CASE ( 3 )                            !  create 'mesh_hgr.nc'
+            !                                  !         'mesh_zgr.nc' and
+            !                                  !         'mask.nc'     files
+            !                                  ! ============================
+
+            IF(lwp) WRITE(numout,*) '          three files in "mesh_hgr.nc" , mesh_zgr.nc" and "mask.nc" '
+            CALL iom_open( 'mesh_hgr', inum3 ) ! create 'mesh_hgr.nc'
+            CALL iom_open( 'mesh_zgr', inum4 ) ! create 'mesh_zgr.nc'
+            CALL iom_open( 'mask'    , inum2 ) ! create 'mask.nc'
+
+         END SELECT
+
+         !                                                         ! masks (inum2) 
+         CALL iom_get( inum2, jpdom_data, 'tmask', tmask )
+         CALL iom_get( inum2, jpdom_data, 'umask', umask )
+         CALL iom_get( inum2, jpdom_data, 'vmask', vmask )
+         CALL iom_get( inum2, jpdom_data, 'fmask', fmask )
+
+#if defined key_c1d
+         ! set umask and vmask equal tmask in 1D configuration
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '**********  1D configuration : set umask and vmask equal tmask ********'
+         IF(lwp) WRITE(numout,*) '**********                                                     ********'
+
+         umask(:,:,:) = tmask(:,:,:)
+         vmask(:,:,:) = tmask(:,:,:)
+#endif
+
+#if defined key_off_degrad
+         CALL iom_get( inum2, jpdom_data, 'facvolt', facvol )
+#endif
+
+         !                                                         ! horizontal mesh (inum3)
+         CALL iom_get( inum3, jpdom_data, 'glamt', glamt )
+         CALL iom_get( inum3, jpdom_data, 'glamu', glamu )
+         CALL iom_get( inum3, jpdom_data, 'glamv', glamv )
+         CALL iom_get( inum3, jpdom_data, 'glamf', glamf )
+
+         CALL iom_get( inum3, jpdom_data, 'gphit', gphit )
+         CALL iom_get( inum3, jpdom_data, 'gphiu', gphiu )
+         CALL iom_get( inum3, jpdom_data, 'gphiv', gphiv )
+         CALL iom_get( inum3, jpdom_data, 'gphif', gphif )
+
+         CALL iom_get( inum3, jpdom_data, 'e1t', e1t )
+         CALL iom_get( inum3, jpdom_data, 'e1u', e1u )
+         CALL iom_get( inum3, jpdom_data, 'e1v', e1v )
+         
+         CALL iom_get( inum3, jpdom_data, 'e2t', e2t )
+         CALL iom_get( inum3, jpdom_data, 'e2u', e2u )
+         CALL iom_get( inum3, jpdom_data, 'e2v', e2v )
+
+         CALL iom_get( inum3, jpdom_data, 'ff', ff )
+
+         CALL iom_get( inum4, jpdom_data, 'mbathy', zprt )
+         mbathy(:,:) = zprt(:,:) * tmask(:,:,1) + 1
+
+
+         ! Vertical coordinates and scales factors
+         !
+         CALL iom_get( inum4, jpdom_unknown, 'gdept_0', gdept_0 ) ! depth
+         CALL iom_get( inum4, jpdom_unknown, 'gdepw_0', gdepw_0 )
+         CALL iom_get( inum4, jpdom_unknown, 'e3t_0'  , e3t_0   )
+         CALL iom_get( inum4, jpdom_unknown, 'e3w_0'  , e3w_0   )
+
+#if ! defined key_zco
+
+         CALL iom_get( inum4, jpdom_data, 'e3t', e3t ) ! scale factors
+         CALL iom_get( inum4, jpdom_data, 'e3u', e3u )
+         CALL iom_get( inum4, jpdom_data, 'e3v', e3v )
+         CALL iom_get( inum4, jpdom_data, 'e3w', e3w )
+ 
+         DO jk = 1,jpk
+            gdept(:,:,jk) = gdept_0(jk)
+            gdepw(:,:,jk) = gdepw_0(jk)
+         END DO
+         
+         IF( ln_sco ) THEN                                         ! s-coordinate
+
+            CALL iom_get( inum4, jpdom_data, 'hbatt', hbatt )
+            CALL iom_get( inum4, jpdom_data, 'hbatu', hbatu )
+            CALL iom_get( inum4, jpdom_data, 'hbatv', hbatv )
+            CALL iom_get( inum4, jpdom_data, 'hbatf', hbatf )
+            
+            CALL iom_get( inum4, jpdom_unknown, 'gsigt', gsigt ) ! scaling coef.
+            CALL iom_get( inum4, jpdom_unknown, 'gsigw', gsigw )
+            CALL iom_get( inum4, jpdom_unknown, 'gsi3w', gsi3w ) 
+            CALL iom_get( inum4, jpdom_unknown, 'esigt', esigt )
+            CALL iom_get( inum4, jpdom_unknown, 'esigw', esigw )
+
+         ENDIF
+
+         IF( ln_zps ) THEN   
+                                      ! z-coordinate - partial steps
+            CALL iom_get( inum4, jpdom_data, 'hdept', hdept )   ! depth
+            CALL iom_get( inum4, jpdom_data, 'hdepw', hdepw )
+         
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ik = mbathy(ji,jj) - 1
+                  ! ocean point only 
+                  IF( ik > 0 ) THEN
+                     ! max ocean level case
+                     gdepw(ji,jj,ik+1) = hdepw(ji,jj)
+                     gdept(ji,jj,ik  ) = hdept(ji,jj)
+                     gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + e3t(ji,jj,ik)
+                  ENDIF
+               END DO
+            END DO
+
+         ENDIF
+            
+# endif
+
+      ! Control printing : Grid informations (if not restart)
+      ! ----------------
+
+      IF(lwp .AND. .NOT.ln_rstart ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          longitude and e1 scale factors'
+         WRITE(numout,*) '          ------------------------------'
+         WRITE(numout,9300) ( ji, glamt(ji,1), glamu(ji,1),   &
+            glamv(ji,1), glamf(ji,1),   &
+            e1t(ji,1), e1u(ji,1),   &
+            e1v(ji,1), ji = 1, jpi,10)
+9300     FORMAT( 1x, i4, f8.2,1x, f8.2,1x, f8.2,1x, f8.2, 1x,    &
+            f19.10, 1x, f19.10, 1x, f19.10 )
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          latitude and e2 scale factors'
+         WRITE(numout,*) '          -----------------------------'
+         WRITE(numout,9300) ( jj, gphit(1,jj), gphiu(1,jj),   &
+            &                     gphiv(1,jj), gphif(1,jj),   &
+            &                     e2t  (1,jj), e2u  (1,jj),   &
+            &                     e2v  (1,jj), jj = 1, jpj, 10 )
+      ENDIF
+
+
+      IF( nprint == 1 .AND. lwp ) THEN
+         WRITE(numout,*) '          e1u e2u '
+         CALL prihre( e1u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         CALL prihre( e2u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         WRITE(numout,*) '          e1v e2v  '
+         CALL prihre( e1v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         CALL prihre( e2v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '              Reference z-coordinate depth and scale factors:'
+         WRITE(numout, "(9x,' level   gdept    gdepw     e3t      e3w  ')" )
+         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_0(jk), gdepw_0(jk), e3t_0(jk), e3w_0(jk), jk = 1, jpk )
+      ENDIF
+
+      DO jk = 1, jpk
+         IF( e3w_0(jk) <= 0. .OR. e3t_0(jk) <= 0. ) CALL ctl_stop ( ' e3w_0 or e3t_0 =< 0 ' )
+         IF( gdepw_0(jk) < 0. .OR. gdept_0(jk) < 0.) CALL ctl_stop( ' gdepw_0 or gdept_0 < 0 ' )
+      END DO
+
+         !                                     ! ============================
+         !                                     !        close the files 
+         !                                     ! ============================
+         SELECT CASE ( nmsh )
+            CASE ( 1 )                
+               CALL iom_close( inum0 )
+            CASE ( 2 )
+               CALL iom_close( inum1 )
+               CALL iom_close( inum2 )
+            CASE ( 3 )
+               CALL iom_close( inum2 )
+               CALL iom_close( inum3 )
+               CALL iom_close( inum4 )
+         END SELECT
+
+   END SUBROUTINE dom_rea
+
+#endif
+
+   !!======================================================================
+END MODULE domrea
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_dimg.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_dimg.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_dimg.h90	(revision 4536)
@@ -0,0 +1,432 @@
+   SUBROUTINE dom_rea
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_rea  ***   'key_mpp'
+      !!
+      !! ** Purpose :   READ the direct access files which contains all the
+      !!      ocean domain informations (mesh and mask arrays). These
+      !!      files are used for visualisation (SAXO software) and
+      !!      diagnostic computation.
+      !!
+      !! ** Method  :   READ in a file all the arrays generated in routines
+      !!      domhgr, domzgr, and dommsk. Note: the file contain depends on
+      !!      the vertical coord. used (z-coord, partial steps, s-coord)
+      !!    For mpp output direct access files are used and each processor
+      !!    uses a record range. Off line program (build_nc_meshmask) can be used
+      !!    to reconstruct the Netcdf files
+      !!                    nmsh = 1  :   'mesh_mask.nc' file
+      !!                         = 2  :   'mesh.nc' and mask.nc' files
+      !!                         = 3  :   'mesh_hgr.nc', 'mesh_zgr.nc' and
+      !!                                  'mask.nc' files
+      !!      For huge size domain, use option 2 or 3 depending on your
+      !!      vertical coordinate.
+      !!
+      !! ** output file :
+      !!      meshmask.nc  : domain size, horizontal grid-point position,
+      !!                     masks, depth and vertical scale factors
+      !!
+      !! History :
+      !!        !  97-02  (G. Madec)  Original code
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with IOIPSL
+      !!   9.0  !  02-08  (G. Madec)  F90 and several file
+      !!        !  04-01  (J.M. Molines) MPP i/o
+      !!----------------------------------------------------------------------
+      !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+      !!   $Header$
+      !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE lib_mpp
+      USE daymod
+
+      !! * Local declarations
+      !! * Local declarations
+      INTEGER  ::                & !!! * temprary units for :
+         inum0 ,                 &  ! 'mesh_mask.nc' file
+         inum1 ,                 &  ! 'mesh.nc'      file
+         inum2 ,                 &  ! 'mask.nc'      file
+         inum3 ,                 &  ! 'mesh_hgr.nc'  file
+         inum4                      ! 'mesh_zgr.nc'  file
+      INTEGER  ::   itime           !  output from restini ???
+      INTEGER  ::   irecl8, irec    ! Record length (bytes) for output file 
+      INTEGER  ::   jk              ! loop index
+      INTEGER  ::   ios1, ios2
+      INTEGER, DIMENSION(11:15)  :: irecv ! index of this array will be inumxxx
+      REAL(wp) ::   zdate0
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zprt                       ! temporary array for bathymetry
+
+      CHARACTER (len=21) ::      &
+         clnam0 = 'mesh_mask',   &  ! filename (mesh and mask informations)
+         clnam1 = 'mesh'     ,   &  ! filename (mesh informations)
+         clnam2 = 'mask'     ,   &  ! filename (mask informations)
+         clnam3 = 'mesh_hgr' ,   &  ! filename (horizontal mesh informations)
+         clnam4 = 'mesh_zgr'        ! filename (vertical   mesh informations)
+      !!----------------------------------------------------------------------
+
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) 'dom_rea : read direct access  mesh and mask information files'
+       IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+       inum0 = 11
+       irecl8 = jpi*jpj*wp
+       ios1 = 0 ; ios2 = 0
+       IF (ln_zps ) ios1= 1 
+       IF (ln_sco ) ios2= 1
+   
+       SELECT CASE (nmsh )
+          !                                    !==============================
+          CASE ( 1 )                           !  read 'mesh_mask' file
+             !                                 !==============================
+             IF (lwp) WRITE(numout,*) '          one file in "mesh_mask.dimgproc '
+             OPEN(inum0,FILE=trim(clnam0)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp )READ(inum0,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+             inum2 = inum0
+             inum3 = inum0
+             inum4 = inum0
+
+            !                                  ! ============================
+         CASE ( 2 )                            !  read 'mesh' and
+            !                                  !         'mask' files
+            !                                  ! ============================
+
+            IF(lwp) WRITE(numout,*) '          two files in "mesh" and "mask" '
+            inum1 = 12
+            inum2 = 13
+            OPEN(inum1,FILE=trim(clnam1)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp) READ(inum1,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+             inum3 = inum1
+             inum4 = inum1
+            OPEN(inum2,FILE=trim(clnam2)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp) READ(inum2,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+            !                                  ! ============================
+         CASE ( 3 )                            !  read 'mesh_hgr'
+            !                                  !         'mesh_zgr' and
+            !                                  !         'mask'     files
+            !                                  ! ============================
+
+            IF(lwp) WRITE(numout,*) '          three files in "mesh_hgr" , mesh_zgr" and "mask" '
+            inum3 = 14
+            inum2 = 13
+            inum4 = 15
+
+            OPEN(inum3,FILE=trim(clnam3)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp) READ(inum3,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+            OPEN(inum2,FILE=trim(clnam2)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp) READ(inum2,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+
+            OPEN(inum4,FILE=trim(clnam4)//'.mpp', &
+                & FORM='UNFORMATTED', ACCESS='DIRECT', RECL = irecl8 )
+             IF (lwp) READ(inum4,REC=1 ) irecl8, nmsh, ios1,ios2 , &
+            &  ndastp, adatrj, jpi,jpj,jpk,  &
+            &  jpni,jpnj,jpnij,jpiglo,jpjglo, &
+            &  nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+         
+         END SELECT
+       
+         irecv(:) = 2
+         ! tmask
+         DO jk=1,jpk
+             irec=irecv(inum2) + (jk -1 ) + jpk * (narea - 1 )
+             READ(inum2,REC=irec) tmask(:,:,jk)
+         END DO
+         irecv(inum2) = irecv(inum2) + jpk * jpnij 
+         !
+         ! umask
+         DO jk=1,jpk
+             irec=irecv(inum2) + (jk -1 ) + jpk * (narea - 1 )
+             READ(inum2,REC=irec) umask(:,:,jk)
+         END DO
+         irecv(inum2) = irecv(inum2) + jpk * jpnij 
+         !
+         ! vmask
+         DO jk=1,jpk
+             irec=irecv(inum2) + (jk -1 ) + jpk * (narea - 1 )
+             READ(inum2,REC=irec) vmask(:,:,jk)
+         END DO
+         irecv(inum2) = irecv(inum2) + jpk * jpnij 
+         !
+         ! fmask
+         DO jk=1,jpk
+             irec=irecv(inum2) + (jk -1 ) + jpk * (narea - 1 )
+             READ(inum2,REC=irec) fmask(:,:,jk)
+         END DO
+         irecv(inum2) = irecv(inum2) + jpk * jpnij 
+         !
+         ! glam
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) glamt(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+       
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) glamu(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) glamv(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) glamf(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+         !
+         ! gphi
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) gphit(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+       
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) gphiu(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) gphiv(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) gphif(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+         !
+         ! e1
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e1t(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+       
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e1u(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e1v(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e1f(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+         !
+         ! e2
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e2t(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+       
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e2u(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e2v(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) e2f(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+         !
+         ! ff
+         irec = irecv(inum3) + (narea - 1 )
+         READ(inum3,REC=irec) ff(:,:)
+         irecv(inum3) = irecv(inum3) + jpnij 
+         !
+         ! mbathy
+         !       note that mbathy has been modified in dommsk or in solver.
+         !       it is the number of non-zero "w" levels in the water, and the minimum
+         !       value (on land) is 2. We define zprt as the number of "T" points in the ocean
+         !       at any location, and zero on land.
+         !
+         irec = irecv(inum4) + (narea - 1 )
+         READ(inum4,REC=irec) zprt(:,:)
+         irecv(inum4) = irecv(inum4) + jpnij 
+
+          mbathy=zprt*tmask(:,:,1)+1
+
+#if ! defined key_zco
+          IF( ln_sco ) THEN                                         ! s-coordinate
+             !
+             ! hbat
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hbatt(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hbatu(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hbatv(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hbatf(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             !
+             ! gsig and esig ( as vectors of jpk per record )
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gsigt(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gsigw(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gsi3w(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) esigt(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) esigw(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+
+             ! e3 (3D)
+             DO jk=1,jpk
+                irec =  irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3t(:,:,jk)
+             ENDIF
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             DO jk=1,jpk
+                irec =  irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3u(:,:,jk)
+             ENDIF
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             DO jk=1,jpk
+                irec =  irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3v(:,:,jk)
+             ENDIF
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             DO jk=1,jpk
+                irec =  irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3w(:,:,jk)
+             ENDIF
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+
+             ! gdep
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gdept_0(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gdepw_0(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             !
+          ENDIF
+             
+          IF( ln_zps ) THEN
+             !
+             ! hdep
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hdept(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec = irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) hdepw(:,:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             !
+             ! e3t_ps (3D)
+             DO jk=1,jpk
+                irec=irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3t(:,:,jk)
+             END DO
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             ! e3u_ps e3v_ps e3w_ps (3D)
+             DO jk=1,jpk
+                irec=irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3u(:,:,jk)
+             END DO
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             DO jk=1,jpk
+                irec=irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3v(:,:,jk)
+             END DO
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             
+             DO jk=1,jpk
+                irec=irecv(inum4) + (jk -1 ) + jpk * (narea - 1 )
+                READ(inum4,REC=irec) e3w(:,:,jk)
+             END DO
+             irecv(inum4) = irecv(inum4) + jpk * jpnij 
+             ! 
+             ! 
+             ! gdep
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gdept_0(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) gdepw_0(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             !
+             ! e3
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) e3t_0(:)
+             irecv(inum4) = irecv(inum4) + jpnij 
+             
+             irec =  irecv(inum4) + (narea - 1 )
+             READ(inum4,REC=irec) e3w_0(:)
+          ENDIF
+#else
+          !
+          ! gdep
+          irec =  irecv(inum4) + (narea - 1 )
+          READ(inum4,REC=irec) gdept_0(:)
+          irecv(inum4) = irecv(inum4) + jpnij 
+          
+          irec =  irecv(inum4) + (narea - 1 )
+          READ(inum4,REC=irec) gdepw_0(:)
+          irecv(inum4) = irecv(inum4) + jpnij 
+          !
+          ! e3
+          irec =  irecv(inum4) + (narea - 1 )
+          READ(inum4,REC=irec) e3t_0(:)
+          irecv(inum4) = irecv(inum4) + jpnij 
+          
+          irec =  irecv(inum4) + (narea - 1 )
+          READ(inum4,REC=irec) e3w_0(:)
+          irecv(inum4) = irecv(inum4) + jpnij 
+         !
+#endif
+         !                                     ! ============================
+         !                                     !        close the files
+         !                                     ! ============================
+         SELECT CASE ( nmsh )
+            CASE ( 1 )
+               CLOSE ( inum0 )
+            CASE ( 2 )
+               CLOSE ( inum1 )
+               CLOSE ( inum2 )
+            CASE ( 3 )
+               CLOSE ( inum2 )
+               CLOSE ( inum3 )
+               CLOSE ( inum4 )
+         END SELECT
+
+   END SUBROUTINE dom_rea
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_fdir.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_fdir.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domrea_fdir.h90	(revision 4536)
@@ -0,0 +1,100 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  domrea_fdir.h90  ***
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dom_rea
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_rea  ***
+      !!                   
+      !! ** Purpose :   Read a direct access file named meshmask
+      !!        This file contains all ocean domain informations (mesh and
+      !!      mask arrays). It is used for visualisation (SAXO software)
+      !!      and diagnostic computation.
+      !!        Caution, this file is not assigned so that diagnostics can
+      !!      be computed with a 64 bits precision.
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      CHARACTER (len=5) ::   clfield  ! field name
+      INTEGER ::   inum = 11          ! logical unit used for meshmask file
+      INTEGER :: iimlu,ijmlu,ikmlu
+      !!----------------------------------------------------------------------
+
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) 'dom_rea : read a direct acces mesh_mask file'
+       IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+       ! open meshmask file
+       CALL ctlopn( inum, 'mesh_mask','UNKNOWN', 'UNFORMATTED', 'SEQUENTIAL',   &
+                    1 , numout, lwp, 1 )
+
+
+      ! 0. Domain size
+      ! --------------
+      read(inum) iimlu, ijmlu, ikmlu
+
+
+      ! 1. Horzontal grid-point position
+      ! --------------------------------
+      clfield='GLAMT'   ;    READ(inum) clfield, glamt
+      clfield='GLAMU'   ;    READ(inum) clfield, glamu
+      clfield='GLAMV'   ;    READ(inum) clfield, glamv
+      clfield='GLAMF'   ;    READ(inum) clfield, glamf
+
+      clfield='GPHIT'   ;    READ(inum) clfield, gphit
+      clfield='GPHIU'   ;    READ(inum) clfield, gphiu
+      clfield='GPHIV'   ;    READ(inum) clfield, gphiv
+      clfield='GPHIF'   ;    READ(inum) clfield, gphif
+
+
+      ! 2. Horizontal scale factors
+      ! ---------------------------
+      clfield='E1T  '   ;    READ(inum) clfield, e1t
+      clfield='E1U  '   ;    READ(inum) clfield, e1u
+      clfield='E1V  '   ;    READ(inum) clfield, e1v
+      clfield='E1F  '   ;    READ(inum) clfield, e1f
+
+      clfield='E2T  '   ;    READ(inum) clfield, e2t
+      clfield='E2U  '   ;    READ(inum) clfield, e2u
+      clfield='E2V  '   ;    READ(inum) clfield, e2v
+      clfield='E2F  '   ;    READ(inum) clfield, e2f
+
+
+      ! 3. masks
+      ! --------
+      clfield='TMASK'   ;    READ(inum) clfield, tmask
+      clfield='UMASK'   ;    READ(inum) clfield, umask
+      clfield='VMASK'   ;    READ(inum) clfield, vmask
+      clfield='FMASK'   ;    READ(inum) clfield, fmask
+      clfield='FF   '   ;    READ(inum) clfield, ff
+
+      ! 4. depth and vertical scale factors
+      ! -----------------------------------
+#if ! defined key_zco
+      IF( ln_sco ) THEN
+         clfield='HBATT'   ;    READ(inum) clfield, hbatt
+         clfield='HBATU'   ;    READ(inum) clfield, hbatu
+         clfield='HBATV'   ;    READ(inum) clfield, hbatv
+         clfield='HBATF'   ;    READ(inum) clfield, hbatf
+         clfield='GSIGT'   ;    READ(inum) clfield, gsigt
+         clfield='GSIGW'   ;    READ(inum) clfield, gsigw
+         clfield='GSI3W'   ;    READ(inum) clfield, gsi3w
+         clfield='ESIGT'   ;    READ(inum) clfield, esigt
+         clfield='ESIGW'   ;    READ(inum) clfield, esigw
+      ENDIF
+#else
+      clfield='GDEPT'   ;    READ(inum) clfield, gdept
+      clfield='GDEPW'   ;    READ(inum) clfield, gdepw
+      clfield='E3T  '   ;    READ(inum) clfield, e3t
+      clfield='E3W  '   ;    READ(inum) clfield,  e3w
+#endif
+
+      CLOSE( inum )
+
+   END SUBROUTINE dom_read
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domstp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domstp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domstp.F90	(revision 4536)
@@ -0,0 +1,114 @@
+MODULE domstp
+   !!==============================================================================
+   !!                       ***  MODULE domstp   ***
+   !! Ocean initialization : time domain
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_stp        : ocean time domain initialization
+   !!----------------------------------------------------------------------
+   !! History :
+   !!        !  90-10  (O. Marti)  Original code
+   !!        !  96-01  (G. Madec)  terrain following coordinates
+   !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * routine accessibility
+   PUBLIC dom_stp        ! routine called by inidom.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_stp
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dom_stp  ***
+      !!          
+      !! ** Purpose :   Intialize ocean time step for the run
+      !!
+      !! ** Method  : - Initialization of a coef. use in the Asselin time
+      !!      filter:  atfp1 = 1 - 2 * atfp  where atfp is the Asselin time
+      !!      filter parameter read in namelist
+      !!              - Model time step:
+      !!      nacc = 0 : synchronous time intergration. 
+      !!      There is one time step only, defined by: rdt, rdttra(k)=rdt
+      !!      nacc = 1 : accelerating the convergence. There is 2 different
+      !!      time steps for dynamics and tracers:
+      !!        rdt      : dynamical part
+      !!        rdttra(k): temperature and salinity
+      !!      The tracer time step is a function of vertical level. the model
+      !!      reference time step ( i.e. for wind stress, surface heat and
+      !!      salt fluxes) is the surface tracer time step is rdttra(1).
+      !!         N.B. depth dependent acceleration of convergence is not im-
+      !!      plemented for s-coordinate.
+      !!
+      !! ** Action  : - rdttra   : vertical profile of tracer time step
+      !!              - atfp1    : = 1 - 2*atfp
+      !!
+      !! References :
+      !!      Bryan, K., 1984, J. Phys. Oceanogr., 14, 666-673.
+      !!----------------------------------------------------------------------
+      INTEGER ::   jk              ! dummy loop indice
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_stp : time stepping setting'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! 0. Asselin Time filter
+      ! ----------------------
+      
+      atfp1 = 1. - 2. * atfp
+
+      SELECT CASE ( nacc )
+
+         CASE ( 0 )                ! Synchronous time stepping
+            IF(lwp) WRITE(numout,*)'               synchronous time stepping'
+            IF(lwp) WRITE(numout,*)'               dynamics and tracer time step = ', rdt/3600., ' hours'
+
+            rdttra(:) = rdt
+
+         CASE ( 1 )                ! Accelerating the convergence
+            IF(lwp) WRITE(numout,*) '              no tracer damping in the turbocline'
+            IF(lwp) WRITE(numout,*)'               accelerating the convergence'
+            IF(lwp) WRITE(numout,*)'               dynamics time step = ', rdt/3600., ' hours'
+            IF( ln_sco .AND. rdtmin /= rdtmax )   &
+                 & CALL ctl_stop ( ' depth dependent acceleration of convergence not implemented in s-coordinates' )
+            IF(lwp) WRITE(numout,*)'         tracers   time step :  dt (hours)  level'
+
+            DO jk = 1, jpk
+               IF( gdept_0(jk) <= rdth ) rdttra(jk) = rdtmin
+               IF( gdept_0(jk) >  rdth ) THEN
+                  rdttra(jk) = rdtmin + ( rdtmax - rdtmin )   &
+                                      * ( EXP( ( gdept_0(jk ) - rdth ) / rdth ) - 1. )   &
+                                      / ( EXP( ( gdept_0(jpk) - rdth ) / rdth ) - 1. )
+               ENDIF
+               IF(lwp) WRITE(numout,"(36x,f5.2,5x,i3)") rdttra(jk)/3600., jk
+            END DO  
+
+         CASE DEFAULT              ! E R R O R 
+
+            WRITE(ctmp1,*) ' nacc value e r r o r, nacc= ',nacc
+            CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE dom_stp
+
+   !!======================================================================
+END MODULE domstp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domzgr_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domzgr_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DOM/domzgr_substitute.h90	(revision 4536)
@@ -0,0 +1,41 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  domzgr_substitute.h90   ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsdep. and fse.., the vert. depth and scale
+   !!      factors depending on the vertical coord. used, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!
+   !! History :
+   !!   9.0  !  05-10  (A. Beckmann, G. Madec) generalisation to all coord.
+   !!----------------------------------------------------------------------
+#if defined key_zco
+#   define  fsdept(i,j,k)  gdept_0(k)
+
+#   define  fsdepw(i,j,k)  gdepw_0(k)
+#   define  fsde3w(i,j,k)  gdepw_0(k)
+
+#   define  fse3t(i,j,k)   e3t_0(k)
+#   define  fse3u(i,j,k)   e3t_0(k)
+#   define  fse3v(i,j,k)   e3t_0(k)
+#   define  fse3f(i,j,k)   e3t_0(k)
+
+#   define  fse3w(i,j,k)   e3w_0(k)
+#   define  fse3uw(i,j,k)  e3w_0(k)
+#   define  fse3vw(i,j,k)  e3w_0(k)
+#else
+#   define  fsdept(i,j,k)  gdept(i,j,k)
+
+#   define  fsdepw(i,j,k)  gdepw(i,j,k)
+#   define  fsde3w(i,j,k)  gdep3w(i,j,k)
+ 
+#   define  fse3t(i,j,k)   e3t(i,j,k)
+#   define  fse3u(i,j,k)   e3u(i,j,k)
+#   define  fse3v(i,j,k)   e3v(i,j,k)
+#   define  fse3f(i,j,k)   e3f(i,j,k)
+
+#   define  fse3w(i,j,k)   e3w(i,j,k)
+#   define  fse3uw(i,j,k)  e3uw(i,j,k)
+#   define  fse3vw(i,j,k)  e3vw(i,j,k)
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DYN/dynspg_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DYN/dynspg_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/DYN/dynspg_oce.F90	(revision 4536)
@@ -0,0 +1,33 @@
+MODULE dynspg_oce
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_oce  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   
+   IMPLICIT NONE
+   PRIVATE
+
+#if defined key_dynspg_rl
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_rl'      rigid lid
+   !!----------------------------------------------------------------------
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_rl = .TRUE. !: rigid flag flag
+
+#elif defined key_dynspg_flt || defined key_dynspg_ts || defined key_dynspg_exp
+   !!----------------------------------------------------------------------
+   !!   Default case :       free surface 
+   !!   update the momentum trend with the surface pressure
+   !!   gradient in the free surface case with vector
+   !!   optimization
+   !!----------------------------------------------------------------------
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_rl = .FALSE.     !: rigid flag 
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 4536)
@@ -0,0 +1,176 @@
+MODULE in_out_manager   
+   !!======================================================================
+   !!                       ***  MODULE  in_out_manager  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the tke 
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !! History :   8.5  !  02-06  (G. Madec)  original code
+   !!             9.0  !  06-07  (S. Masson)  iom, add ctl_stop, ctl_warn
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
+   !!   ctl_warn   : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE par_kind
+   USE par_oce
+   USE lib_print         ! formated print library
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !!                   namrun namelist parameters
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16) ::   cexper     = "exp0"    !: experiment name used for output filename
+   LOGICAL            ::   ln_rstart  = .FALSE.   !: start from (F) rest or (T) a restart file
+   INTEGER            ::   no         = 0         !: job number
+   INTEGER            ::   nrstdt     = 0         !: control of the time step (0, 1 or 2)
+   INTEGER            ::   nn_rstssh  = 0         !: hand made initilization of ssh or not (1/0)
+   INTEGER            ::   nit000     = 1         !: index of the first time step
+   INTEGER            ::   nitend     = 10        !: index of the last time step
+   INTEGER            ::   ndate0     = 961115    !: initial calendar date aammjj
+   INTEGER            ::   nleapy     = 0         !: Leap year calendar flag (0/1 or 30)
+   INTEGER            ::   ninist     = 0         !: initial state output flag (0/1)
+   LOGICAL            ::   ln_dimgnnn = .FALSE.   !: type of dimgout. (F): 1 file for all proc
+                                                  !:                  (T): 1 file per proc
+   !!----------------------------------------------------------------------
+   !! was in restart but moved here because of the OFF line... better solution should be found...
+   !!----------------------------------------------------------------------
+   INTEGER            ::   nitrst                 !: time step at which restart file should be written
+   !!----------------------------------------------------------------------
+   !!                    output monitoring
+   !!----------------------------------------------------------------------
+   LOGICAL            ::   ln_ctl     = .FALSE.   !: run control for debugging
+   INTEGER            ::   nstock     =   10      !: restart file frequency
+   INTEGER            ::   nprint     =    0      !: level of print (0 no print)
+   INTEGER            ::   nwrite     =   10      !: restart file frequency
+   INTEGER            ::   nictls     =    0      !: Start i indice for the SUM control
+   INTEGER            ::   nictle     =    0      !: End   i indice for the SUM control
+   INTEGER            ::   njctls     =    0      !: Start j indice for the SUM control
+   INTEGER            ::   njctle     =    0      !: End   j indice for the SUM control
+   INTEGER            ::   isplt      =    1      !: number of processors following i
+   INTEGER            ::   jsplt      =    1      !: number of processors following j
+   INTEGER            ::   ijsplt     =    1      !: nb of local domain = nb of processors
+   INTEGER            ::   nbench     =    0      !: benchmark parameter (0/1)
+   INTEGER            ::   nbit_cmp   =    0      !: bit reproducibility  (0/1)
+   !!----------------------------------------------------------------------
+   !!                        logical units
+   !!----------------------------------------------------------------------
+   INTEGER            ::   numstp                 !: logical unit for time step
+   INTEGER            ::   numout                 !: logical unit for output print
+   INTEGER            ::   numnam                 !: logical unit for namelist
+   INTEGER            ::   numnam_ice             !: logical unit for ice namelist
+   INTEGER            ::   numevo_ice             !: logical unit for ice variables (temp. evolution)
+   INTEGER            ::   numsol                 !: logical unit for solver statistics
+   INTEGER            ::   numwri                 !: logical unit for output write
+   INTEGER            ::   numisp                 !: logical unit for island statistics
+   INTEGER            ::   numgap                 !: logical unit for differences diagnostic
+   INTEGER            ::   numbol                 !: logical unit for "bol" diagnostics
+   INTEGER            ::   numptr                 !: logical unit for Poleward TRansports
+   INTEGER            ::   numflo                 !: logical unit for drifting floats
+
+   !!----------------------------------------------------------------------
+   !!                          Run control  
+   !!----------------------------------------------------------------------
+
+   INTEGER            ::   nstop = 0                !: error flag (=number of reason for a premature stop run)
+   INTEGER            ::   nwarn = 0                !: warning flag (=number of warning found during the run)
+   CHARACTER(len=200) ::   ctmp1, ctmp2, ctmp3      !: temporary character
+   CHARACTER (len=64) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
+   CHARACTER (len=64) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
+   LOGICAL            ::   lwp                      !: boolean : true on the 1st processor only
+   LOGICAL            ::   lsp_area = .TRUE.        !: to make a control print over a specific area
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/in_out_manager.F90,v 1.11 2007/03/02 16:37:06 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_opa  ***
+      !!
+      !! ** Purpose : ??? blah blah....
+      !!-----------------------------------------------------------------------
+      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,"(/,' ===>>> : E R R O R',     /,'         ===========',/)") 
+         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_stop
+
+
+   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_warn  ***
+      !!
+      !! ** Purpose : ???  blah blah....
+      !!-----------------------------------------------------------------------
+      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,"(/,' ===>>> : W A R N I N G', /,'         ===============',/)") 
+         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
+
+
+   FUNCTION getunit()
+     !!-----------------------------------------------------------------------
+     !!                  ***  FUNCTION  getunit  ***
+     !!
+     !! ** Purpose : ???  blah blah....
+     !!-----------------------------------------------------------------------
+     INTEGER :: getunit
+     LOGICAL :: llopn 
+     !---------------------------------------------------------------------
+     getunit = 15   ! choose a unit that is big enough then it is
+                    !  not already used in OPA
+     llopn = .TRUE.
+     DO WHILE( (getunit < 998) .AND. llopn )
+        getunit = getunit + 1
+        INQUIRE( unit = getunit, opened = llopn )
+     END DO
+     IF( (getunit == 999) .AND. llopn ) THEN
+        CALL ctl_stop( 'getunit: All logical units until 999 are used...' )
+        getunit = -1
+     ENDIF
+
+   END FUNCTION getunit
+
+   !!=====================================================================
+END MODULE in_out_manager
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom.F90	(revision 4536)
@@ -0,0 +1,806 @@
+MODULE iom
+   !!=====================================================================
+   !!                    ***  MODULE  iom ***
+   !! Input/Output manager :  Library to read input files
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_gettime
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis cdvar in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+   USE iom_ioipsl      ! NetCDF format with IOIPSL library
+   USE iom_nf90        ! NetCDF format with native NetCDF library
+   USE iom_rstdimg     ! restarts access direct format "dimg" style...
+
+   IMPLICIT NONE
+   PUBLIC   !   must be public to be able to access iom_def through iom
+   
+   PUBLIC iom_open, iom_close, iom_varid, iom_get, iom_gettime, iom_rstput
+
+   PRIVATE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+   PRIVATE iom_g0d, iom_g1d, iom_g2d, iom_g3d, iom_get_123d
+
+   INTERFACE iom_get
+      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
+   END INTERFACE
+   INTERFACE iom_rstput
+      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+   END INTERFACE
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom.F90,v 1.10 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file (return 0 if not found)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
+      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90) 
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
+
+      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
+      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
+      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
+      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
+      CHARACTER(LEN=100)    ::   clinfo    ! info character
+      LOGICAL               ::   llok      ! check the existence 
+      LOGICAL               ::   llwrt     ! local definition of ldwrt
+      LOGICAL               ::   llstop    ! local definition of ldstop
+      INTEGER               ::   iolib     ! library do we use to open the file
+      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
+      INTEGER               ::   iln, ils  ! lengths of character
+      INTEGER               ::   idom      ! type of domain
+      INTEGER               ::   istop     ! 
+      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters: 
+      ! local number of points for x,y dimensions
+      ! position of first local point for x,y dimensions
+      ! position of last local point for x,y dimensions
+      ! start halo size for x,y dimensions
+      ! end halo size for x,y dimensions
+      !---------------------------------------------------------------------
+      ! Initializations and control
+      ! =============
+      clinfo = '                    iom_open ~~~  '
+      istop = nstop
+      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
+      ! (could be done when defining iom_file in f95 but not in f90)
+      IF( iom_init == 0 ) THEN
+         iom_file(:)%nfid = 0
+         iom_init = 1
+      ENDIF
+      ! do we read or write the file?
+      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
+      ELSE                        ;   llwrt = .FALSE.
+      ENDIF
+      ! do we call ctl_stop if we try to open a non-existing file in read mode?
+      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
+      ELSE                         ;   llstop = .TRUE.
+      ENDIF
+      ! what library do we use to open the file?
+      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
+      ELSE                         ;   iolib = jpnf90
+      ENDIF
+      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
+      ! =============
+      clname   = trim(cdname)
+#if defined key_agrif
+      if ( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+#endif    
+      ! which suffix should we use?
+      SELECT CASE (iolib)
+      CASE (jpioipsl ) ;   clsuffix = '.nc'
+      CASE (jpnf90   ) ;   clsuffix = '.nc'
+      CASE (jprstdimg) ;   clsuffix = '.dimg'
+      CASE DEFAULT     ;   clsuffix = ''
+         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+      END SELECT
+      ! Add the suffix if needed
+      iln = LEN_TRIM(clname)
+      ils = LEN_TRIM(clsuffix)
+      IF( iln <= ils .OR. INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 )   &
+         &   clname = TRIM(clname)//TRIM(clsuffix)
+      cltmpn = clname   ! store this name
+      ! try to find if the file to be opened already exist
+      ! =============
+      INQUIRE( FILE = clname, EXIST = llok )
+      IF( .NOT.llok ) THEN
+         ! we try to add the cpu number to the name
+         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
+         ELSE                            ;   WRITE(clcpu,*) narea-1
+         ENDIF
+         clcpu  = TRIM(ADJUSTL(clcpu))
+         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
+         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
+         icnt = 0
+         INQUIRE( FILE = clname, EXIST = llok ) 
+         ! we try different formats for the cpu number by adding 0
+         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
+            clcpu  = "0"//trim(clcpu)
+            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
+            INQUIRE( FILE = clname, EXIST = llok )
+            icnt = icnt + 1
+         END DO
+      ENDIF
+      IF( llwrt ) THEN
+         ! check the domain definition
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         idom = jpdom_local_noovlap   ! default definition
+         IF( jpni*jpnj == jpnij ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
+         ELSE                            ;   idom = jpdom_local_full      ! default definition
+         ENDIF
+         IF( PRESENT(kdom) )   idom = kdom
+         ! create the domain informations
+         ! =============
+         SELECT CASE (idom)
+         CASE (jpdom_local_full)
+            idompar(:,1) = (/ jpi             , jpj              /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
+         CASE (jpdom_local_noextra)
+            idompar(:,1) = (/ nlci            , nlcj             /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
+         CASE (jpdom_local_noovlap)
+            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
+            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
+            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
+            idompar(:,4) = (/ 0               , 0                /)
+            idompar(:,5) = (/ 0               , 0                /)
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
+         END SELECT
+      ENDIF
+      ! Open the NetCDF or RSTDIMG file
+      ! =============
+      ! do we have some free file identifier?
+      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
+         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
+      ! if no file was found...
+      IF( .NOT. llok ) THEN
+         IF( .NOT. llwrt ) THEN   ! we are in read mode 
+            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
+            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
+            ENDIF
+         ELSE                     ! we are in write mode so we 
+            clname = cltmpn       ! get back the file name without the cpu number
+         ENDIF
+      ENDIF
+      IF( istop == nstop ) THEN   ! no error within this routine
+         SELECT CASE (iolib)
+         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
+         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
+         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         END SELECT
+      ENDIF
+      !
+   END SUBROUTINE iom_open
+
+
+   SUBROUTINE iom_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_close  ***
+      !!
+      !! ** Purpose : close an input file, or all files opened by iom
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
+      !                                           ! No argument : all the files opened by iom are closed
+
+      INTEGER ::   jf         ! dummy loop indices
+      INTEGER ::   i_s, i_e   ! temporary integer
+      CHARACTER(LEN=100)    ::   clinfo    ! info character
+      !---------------------------------------------------------------------
+      !
+      clinfo = '                    iom_close ~~~  '
+      IF( PRESENT(kiomid) ) THEN
+         i_s = kiomid
+         i_e = kiomid
+      ELSE
+         i_s = 1
+         i_e = jpmax_files
+      ENDIF
+
+      IF( i_s > 0 ) THEN
+         DO jf = i_s, i_e
+            IF( iom_file(jf)%nfid > 0 ) THEN
+               SELECT CASE (iom_file(jf)%iolib)
+               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
+               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
+               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
+               CASE DEFAULT
+                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+               END SELECT
+               iom_file(jf)%nfid       = 0   ! free the id 
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
+            ELSEIF( PRESENT(kiomid) ) THEN
+               WRITE(ctmp1,*) '--->',  kiomid
+               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
+            ENDIF
+         END DO
+      ENDIF
+      !    
+   END SUBROUTINE iom_close
+
+
+   FUNCTION iom_varid ( kiomid, cdvar, kdimsz, ldstop )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      LOGICAL              , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if looking for non-existing variable (default = .TRUE.)
+      !
+      INTEGER                        ::   iom_varid, iiv, i_nvd
+      LOGICAL                        ::   ll_fnd
+      CHARACTER(LEN=100)             ::   clinfo                   ! info character
+      LOGICAL                        ::   llstop                   ! local definition of ldstop
+      !!-----------------------------------------------------------------------
+      iom_varid = 0                         ! default definition
+      ! do we call ctl_stop if we look for non-existing variable?
+      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
+      ELSE                         ;   llstop = .TRUE.
+      ENDIF
+      !
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+         IF( iom_file(kiomid)%nfid == 0 ) THEN 
+            CALL ctl_stop( trim(clinfo), 'the file is not open' )
+         ELSE
+            ll_fnd  = .FALSE.
+            iiv = 0
+            !
+            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
+               iiv = iiv + 1
+               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
+            END DO
+            !
+            IF( .NOT.ll_fnd ) THEN
+               iiv = iiv + 1
+               IF( iiv <= jpmax_vars ) THEN
+                  SELECT CASE (iom_file(kiomid)%iolib)
+                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
+                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid  ( kiomid, cdvar, iiv, kdimsz )
+                  CASE (jprstdimg)   ;   iom_varid = -1   ! all variables are listed in iom_file
+                  CASE DEFAULT   
+                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                  END SELECT
+               ELSE
+                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
+                        &                         'increase the parameter jpmax_vars')
+               ENDIF
+               IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
+            ELSE
+               iom_varid = iiv
+               IF( PRESENT(kdimsz) ) THEN 
+                  i_nvd = iom_file(kiomid)%ndims(iiv)
+                  IF( i_nvd == size(kdimsz) ) THEN
+                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
+                  ELSE
+                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
+                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
+                  ENDIF
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDIF
+      !
+   END FUNCTION iom_varid
+
+
+   !!----------------------------------------------------------------------
+   !!                   INTERFACE iom_get
+   !!----------------------------------------------------------------------
+   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
+      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
+      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
+      !
+      INTEGER               :: idvar   ! variable id
+      !
+      IF( kiomid > 0 ) THEN
+         idvar = iom_varid( kiomid, cdvar )
+         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
+            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
+            CASE DEFAULT    
+               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_g0d
+
+   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g1d
+
+   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g2d
+
+   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g3d
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
+         &                  pv_r1d, pv_r2d, pv_r3d,   &
+         &                  ktime , kstart, kcount  )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_get_123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
+      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
+      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
+      !
+      INTEGER                        ::   jl          ! loop on number of dimension 
+      INTEGER                        ::   idom        ! type of domain
+      INTEGER                        ::   idvar       ! id of the variable
+      INTEGER                        ::   inbdim      ! number of dimensions of the variable
+      INTEGER                        ::   idmspc      ! number of spatial dimensions 
+      INTEGER                        ::   itime       ! record number
+      INTEGER                        ::   istop       ! temporary value of nstop
+      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER                        ::   ji, jj      ! loop counters
+      INTEGER                        ::   irankpv       ! 
+      INTEGER                        ::   ind1, ind2  ! substring index
+      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
+      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis 
+      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
+      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
+      INTEGER                        ::   itmp        ! temporary integer
+      CHARACTER(LEN=100)             ::   clinfo      ! info character
+      CHARACTER(LEN=100)             ::   clname      ! file name
+      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
+      !---------------------------------------------------------------------
+      !
+      clname = iom_file(kiomid)%name   !   esier to read
+      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
+      ! local definition of the domain ?
+      idom = kdom
+      ! check kcount and kstart optionals parameters...
+      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
+      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
+      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
+
+      ! Search for the variable in the data base (eventually actualize data)
+      istop = nstop
+      idvar = iom_varid( kiomid, cdvar )
+      !
+      IF( idvar > 0 ) THEN
+         ! to write iom_file(kiomid)%dimsz in a shorter way !
+         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
+         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
+         idmspc = inbdim                                   ! number of spatial dimensions in the file
+         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
+         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
+         !
+         ! update idom definition...
+         ! Identify the domain in case of jpdom_auto(glo/dta) definition
+         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
+            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
+            ELSE                               ;   idom = jpdom_data
+            ENDIF
+            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
+            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
+            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
+         ENDIF
+         ! Identify the domain in case of jpdom_local definition
+         IF( idom == jpdom_local ) THEN
+            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
+            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
+            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
+            ENDIF
+         ENDIF
+         !
+         ! check the consistency between input array and data rank in the file
+         !
+         ! initializations
+         itime = 1
+         IF( PRESENT(ktime) ) itime = ktime
+
+         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
+         WRITE(clrankpv, fmt='(i1)') irankpv
+         WRITE(cldmspc , fmt='(i1)') idmspc
+         !
+         IF(     idmspc <  irankpv ) THEN 
+            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
+               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
+         ELSEIF( idmspc == irankpv ) THEN
+            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
+               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
+         ELSEIF( idmspc >  irankpv ) THEN
+               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
+                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
+                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
+                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
+                  idmspc = idmspc - 1
+               ELSE
+                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
+                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
+                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
+               ENDIF
+         ENDIF
+
+         !
+         ! definition of istart and icnt
+         !
+         icnt  (:) = 1
+         istart(:) = 1
+         istart(idmspc+1) = itime
+
+         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+         ELSE
+            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
+            ELSE 
+               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
+                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
+                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
+                  ENDIF
+                  ! we do not read the overlap                     -> we start to read at nldi, nldj
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  IF( jpni*jpnj == jpnij .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  IF( jpni*jpnj == jpnij ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  ELSE                            ;   icnt(1:2) = (/ nlci           , nlcj            /)
+                  ENDIF
+                  IF( PRESENT(pv_r3d) ) THEN
+                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
+                     ELSE                            ; icnt(3) = jpk
+                     ENDIF
+                  ENDIF
+               ENDIF
+            ENDIF
+         ENDIF
+
+         ! check that istart and icnt can be used with this file
+         !-
+         DO jl = 1, jpmax_dims
+            itmp = istart(jl)+icnt(jl)-1
+            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
+               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
+               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
+               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
+            ENDIF
+         END DO
+
+         ! check that icnt matches the input array
+         !-     
+         IF( idom == jpdom_unknown ) THEN
+            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
+            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
+            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
+            ctmp1 = 'd'
+         ELSE
+            IF( irankpv == 2 ) THEN
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
+               ELSE                          ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
+               ENDIF
+            ENDIF
+            IF( irankpv == 3 ) THEN 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
+               ELSE                          ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
+               ENDIF
+            ENDIF
+         ENDIF
+         
+         DO jl = 1, irankpv
+            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
+            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
+         END DO
+
+      ENDIF
+
+      ! read the data
+      !-     
+      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
+         !
+         ! find the right index of the array to be read
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+!         ENDIF
+         IF( jpni*jpnj == jpnij ) THEN
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ELSE
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ENDIF
+      
+         SELECT CASE (iom_file(kiomid)%iolib)
+         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE DEFAULT    
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         END SELECT
+
+         IF( istop == nstop ) THEN   ! no additional errors until this point...
+            IF(lwp) WRITE(numout,*) '           read '//TRIM(cdvar)//' in '//TRIM(iom_file(kiomid)%name)//' ok'
+            
+            !--- overlap areas and extra hallows (mpp)
+            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
+               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
+            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
+               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
+               IF( icnt(3) == jpk ) THEN
+                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
+               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
+                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
+                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
+               ENDIF
+            ENDIF
+            
+            !--- Apply scale_factor and offset
+            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
+            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
+            IF(     PRESENT(pv_r1d) ) THEN
+               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
+               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
+            ELSEIF( PRESENT(pv_r2d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
+            ELSEIF( PRESENT(pv_r3d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+            ENDIF
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE iom_get_123d
+
+
+   SUBROUTINE iom_gettime( kiomid, ptime, cdvar, kntime, cdunits, cdcalendar )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER                    , INTENT(in   ) ::   kiomid     ! file Identifier
+      REAL(wp), DIMENSION(:)     , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL , INTENT(in   ) ::   cdvar      ! time axis name
+      INTEGER         , OPTIONAL , INTENT(  out) ::   kntime     ! number of times in file
+      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdunits    ! units attribute of time coordinate
+      CHARACTER(len=*), OPTIONAL , INTENT(  out) ::   cdcalendar ! calendar attribute of 
+      !
+      INTEGER, DIMENSION(1) :: kdimsz
+      INTEGER            ::   idvar    ! id of the variable
+      CHARACTER(LEN=32)  ::   tname    ! local name of time coordinate
+      CHARACTER(LEN=100) ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      !
+      IF ( PRESENT(cdvar) ) THEN
+         tname = cdvar
+      ELSE
+         tname = iom_file(kiomid)%uldname
+      ENDIF
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(tname)
+         IF ( PRESENT(kntime) ) THEN
+            idvar  = iom_varid( kiomid, tname, kdimsz = kdimsz )
+            kntime = kdimsz(1)
+         ELSE
+            idvar = iom_varid( kiomid, tname )
+         ENDIF
+         !
+         ptime(:) = 0. ! default definition
+         IF( idvar > 0 ) THEN
+            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
+               IF( iom_file(kiomid)%luld(idvar) ) THEN
+                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
+                     SELECT CASE (iom_file(kiomid)%iolib)
+                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime, cdunits, cdcalendar )
+                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime, cdunits, cdcalendar )
+                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
+                     CASE DEFAULT    
+                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                     END SELECT
+                  ELSE
+                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
+                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
+                  ENDIF
+               ELSE
+                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
+               ENDIF
+            ELSE
+               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
+            ENDIF
+         ELSE
+            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE iom_gettime
+
+
+   !!----------------------------------------------------------------------
+   !!                   INTERFACE iom_rstput
+   !!----------------------------------------------------------------------
+   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp0d
+
+   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(        jpk) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp1d
+
+   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj    ) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp2d
+
+   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid( kiomid, cdvar, ldstop = .FALSE. )
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp3d
+   !!----------------------------------------------------------------------
+
+
+   !!======================================================================
+END MODULE iom
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_def.F90	(revision 4536)
@@ -0,0 +1,73 @@
+MODULE iom_def
+   !!=====================================================================
+   !!                    ***  MODULE  iom_def ***
+   !! IOM variables definitions
+   !!====================================================================
+   !! History :  9.0  ! 06 09  (S. Masson) Original code
+   !!             "   ! 07 07  (D. Storkey) Add uldname
+   !!--------------------------------------------------------------------
+   !!---------------------------------------------------------------------------------
+   !! OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_def.F90,v 1.7 2007/06/05 10:33:38 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!---------------------------------------------------------------------------------
+
+   USE par_kind
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_data          = 1   !: ( 1  :jpidta, 1  :jpjdta)
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_global        = 2   !: ( 1  :jpiglo, 1  :jpjglo)
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local         = 3   !: One of the 3 following cases
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_full    = 4   !: ( 1  :jpi   , 1  :jpi   )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_noextra = 5   !: ( 1  :nlci  , 1  :nlcj  )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_noovlap = 6   !: (nldi:nlei  ,nldj:nlej  )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_unknown       = 7   !: No dimension checking
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autoglo       = 8   !: 
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autodta       = 9   !: 
+
+   INTEGER, PARAMETER, PUBLIC ::   jpioipsl    = 100      !: Use ioipsl (fliocom only) library
+   INTEGER, PARAMETER, PUBLIC ::   jpnf90      = 101      !: Use nf90 library
+   INTEGER, PARAMETER, PUBLIC ::   jprstdimg   = 102      !: Use restart dimgs (fortran direct acces) library
+#if defined key_dimgout
+   INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jprstdimg  !: restarts io library
+#else
+   INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jpnf90     !: restarts io library
+#endif
+
+   INTEGER, PARAMETER, PUBLIC ::   jp_r8    = 200      !: write REAL(8)
+   INTEGER, PARAMETER, PUBLIC ::   jp_r4    = 201      !: write REAL(4)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i4    = 202      !: write INTEGER(4)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i2    = 203      !: write INTEGER(2)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i1    = 204      !: write INTEGER(1)
+
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_files  = 20   !: maximum number of simultaneously opened file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 360  !: maximum number of variables in one file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_dims   =  4   !: maximum number of dimensions for one variable
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  5   !: maximum number of digits for the cpu number in the file name
+
+!$AGRIF_DO_NOT_TREAT
+   INTEGER, PUBLIC            ::   iom_init = 0        !: used to initialize iom_file(:)%nfid to 0
+
+   TYPE, PUBLIC ::   file_descriptor
+      CHARACTER(LEN=240)                        ::   name     !: name of the file
+      INTEGER                                   ::   nfid     !: identifier of the file (0 if closed)
+      INTEGER                                   ::   iolib    !: library used to read the file (jpioipsl, jpnf90 or jprstdimg)
+      INTEGER                                   ::   nvars    !: number of identified varibles in the file
+      INTEGER                                   ::   iduld    !: id of the unlimited dimension
+      INTEGER                                   ::   irec     !: writing record position  
+      CHARACTER(LEN=32)                         ::   uldname  !: name of the unlimited dimension
+      CHARACTER(LEN=32), DIMENSION(jpmax_vars)  ::   cn_var   !: names of the variables
+      INTEGER, DIMENSION(jpmax_vars)            ::   nvid     !: id of the variables
+      INTEGER, DIMENSION(jpmax_vars)            ::   ndims    !: number of dimensions of the variables
+      LOGICAL, DIMENSION(jpmax_vars)            ::   luld     !: variable using the unlimited dimension
+      INTEGER, DIMENSION(jpmax_dims,jpmax_vars) ::   dimsz    !: size of variables dimensions 
+      REAL(kind=wp), DIMENSION(jpmax_vars)      ::   scf      !: scale_factor of the variables
+      REAL(kind=wp), DIMENSION(jpmax_vars)      ::   ofs      !: add_offset of the variables
+   END TYPE file_descriptor
+   TYPE(file_descriptor), DIMENSION(jpmax_files), PUBLIC ::   iom_file !: array containing the info for all opened files
+!$AGRIF_END_DO_NOT_TREAT
+
+   !!=====================================================================
+END MODULE iom_def
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 4536)
@@ -0,0 +1,430 @@
+MODULE iom_ioipsl
+   !!=====================================================================
+   !!                    ***  MODULE  iom_ioipsl ***
+   !! Input/Output manager :  Library to read input files with IOIPSL (only fliocom module)
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_ioipsl_gettime
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE iom_def         ! iom variables definitions
+   USE ioipsl          ! IOIPSL library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_ioipsl_open, iom_ioipsl_close, iom_ioipsl_varid, iom_ioipsl_get, iom_ioipsl_gettime, iom_ioipsl_rstput
+
+   INTERFACE iom_ioipsl_get
+      MODULE PROCEDURE iom_ioipsl_g0d, iom_ioipsl_g123d
+   END INTERFACE
+   INTERFACE iom_ioipsl_rstput
+      MODULE PROCEDURE iom_ioipsl_rp0123d
+   END INTERFACE
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_ioipsl.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_ioipsl_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file with IOIPSL (only fliocom module)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! ioipsl identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      INTEGER            ::   iln        ! lengths of character
+      INTEGER            ::   istop      ! temporary storage of nstop
+      INTEGER            ::   ifliodom   ! model domain identifier (see flio_dom_set)
+      INTEGER            ::   ioipslid   ! ioipsl identifier of the opened file
+      INTEGER            ::   jl         ! loop variable
+      !---------------------------------------------------------------------
+
+      clinfo = '                    iom_ioipsl_open ~~~  '
+      istop = nstop
+      !
+      IF( ldok ) THEN      ! Open existing file...
+         !                 ! =============
+         IF( ldwrt ) THEN  ! ... in write mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
+            CALL flioopfd( TRIM(cdname), ioipslid, "WRITE" )
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            CALL flioopfd( TRIM(cdname), ioipslid )
+         ENDIF
+      ELSE                 ! the file does not exist
+         !                 ! =============
+         iln = INDEX( cdname, '.nc' )
+         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+            IF( jpnij > 1 ) THEN
+               ! define the domain position regarding to the global domain (mainly useful in mpp)
+               CALL flio_dom_set( jpnij, narea-1, (/1, 2/), (/jpiglo, jpjglo/)   &
+                  &             , kdompar(:,1), kdompar(:,2), kdompar(:,3), kdompar(:,4), kdompar(:,5)   &
+                  &             , 'BOX', ifliodom )        
+               ! Note that fliocrfd may change the value of cdname (add the cpu number...)
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname(1:iln-1)//'... in WRITE mode'
+               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom )
+            ELSE              ! the file should be open for read mode so it must exist...
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname//' in WRITE mode'
+               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid )
+            ENDIF
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! start to fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name   = TRIM(cdname)
+         iom_file(kiomid)%nfid   = ioipslid
+         iom_file(kiomid)%iolib  = jpioipsl
+         iom_file(kiomid)%nvars  = 0
+         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files
+         CALL flioinqf( ioipslid, id_uld = iom_file(kiomid)%iduld )
+         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
+      ELSE
+         kiomid = 0               ! return error flag
+      ENDIF
+      !
+   END SUBROUTINE iom_ioipsl_open
+
+
+   SUBROUTINE iom_ioipsl_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_ioipsl_close  ***
+      !!
+      !! ** Purpose : close an input file with IOIPSL (only fliocom module) 
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      !---------------------------------------------------------------------
+      !
+      CALL flioclo( iom_file(kiomid)%nfid )
+      !    
+   END SUBROUTINE iom_ioipsl_close
+
+
+   FUNCTION iom_ioipsl_varid ( kiomid, cdvar, kiv, kdimsz )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file with IOIPSL (only fliocom module)
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER              , INTENT(in   )           ::   kiv   ! 
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      !
+      INTEGER                        ::   iom_ioipsl_varid  ! iom variable Id
+      INTEGER                        ::   ioipslid          ! ioipsl file identifier
+      INTEGER                        ::   ji                ! dummy loop index
+      INTEGER                        ::   i_nvd             ! number of dimension of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   idimid            ! dimension ids of the variable
+      LOGICAL                        ::   ll_fnd            ! found test
+      CHARACTER(LEN=100)             ::   clinfo            ! info character
+      !!-----------------------------------------------------------------------
+      clinfo = 'iom_ioipsl_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+      iom_ioipsl_varid = 0                  ! default definition
+      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
+      ioipslid = iom_file(kiomid)%nfid      ! get back ioipsl file identifier 
+      CALL flioinqv( ioipslid, cdvar, ll_fnd, nb_dims = i_nvd )   ! does the variable exist in the file
+      IF( ll_fnd ) THEN
+         IF( i_nvd <= jpmax_dims ) THEN
+            iom_ioipsl_varid = kiv
+            iom_file(kiomid)%nvars       = kiv
+            iom_file(kiomid)%nvid(kiv)   = -1   ! variable id is not available in ioipsl
+            iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
+            iom_file(kiomid)%ndims(kiv)  = i_nvd
+            CALL flioinqv( ioipslid, cdvar, ll_fnd,   &
+                  &           len_dims = iom_file(kiomid)%dimsz(1:i_nvd,kiv), &   ! dimensions size
+                  &           id_dims  = idimid(1:i_nvd) )                        ! dimensions ids
+            iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+            DO ji = 1, i_nvd                       ! find the unlimited dimension
+               IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.
+            END DO
+            !---------- Deal with scale_factor and add_offset
+            CALL flioinqa( ioipslid, cdvar, 'scale_factor', ll_fnd )
+            IF( ll_fnd) THEN
+               CALL fliogeta( ioipslid, cdvar, 'scale_factor', iom_file(kiomid)%scf(kiv) )
+            ELSE
+               iom_file(kiomid)%scf(kiv) = 1.
+            END IF
+            CALL flioinqa( ioipslid, cdvar, 'add_offset', ll_fnd )
+            IF( ll_fnd ) THEN
+               CALL fliogeta( ioipslid, cdvar, 'add_offset', iom_file(kiomid)%ofs(kiv) )
+            ELSE
+               iom_file(kiomid)%ofs(kiv) = 0.
+            END IF
+            ! return the simension size
+            IF( PRESENT(kdimsz) ) THEN 
+               IF( i_nvd == SIZE(kdimsz) ) THEN
+                  kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
+               ELSE
+                  WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
+                  CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
+               ENDIF
+            ENDIF
+         ELSE
+            CALL ctl_stop( TRIM(clinfo), 'Too many dimensions in the file '//iom_file(kiomid)%name,   &
+                  &                       'increase the parameter jpmax_vars')
+         ENDIF
+      ELSE  
+         iom_ioipsl_varid = -1   !   variable not found, return error code: -1
+      ENDIF
+      !
+   END FUNCTION iom_ioipsl_varid
+
+
+   SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_ioipsl_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with IOIPSL (only fliocom module)
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   ) ::   kiomid    ! Identifier of the file
+      INTEGER , INTENT(in   ) ::   kvid      ! variable id
+      REAL(wp), INTENT(  out) ::   pvar      ! read field
+      !
+      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), pvar )
+      ! 
+   END SUBROUTINE iom_ioipsl_g0d
+
+
+   SUBROUTINE iom_ioipsl_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                      pv_r1d, pv_r2d, pv_r3d)
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_ioipsl_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with IOIPSL (only fliocom module)
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kvid       ! Name of the variable
+      INTEGER                    , INTENT(in   )           ::   knbdim     ! number of dimensions of the variable
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+      !
+      INTEGER               ::   ioipslid   ! ioipsl file identifier
+      CHARACTER(LEN=100)    ::   clvn       ! variable name
+      !---------------------------------------------------------------------
+      clvn = TRIM(iom_file(kiomid)%cn_var(kvid))   ! get back variable name 
+      ioipslid = iom_file(kiomid)%nfid             ! get back IPIPSL file id
+      !
+      IF( PRESENT(pv_r1d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r1d(:                ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ELSEIF( PRESENT(pv_r2d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ELSEIF( PRESENT(pv_r3d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ENDIF
+      !
+      !
+   END SUBROUTINE iom_ioipsl_g123d
+
+
+   SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis kvid in the file with IOIPSL (only fliocom module)
+      !!--------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
+      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
+      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
+      !---------------------------------------------------------------------
+      !
+      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), ptime(:),   &
+            &         start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /) )
+      IF ( PRESENT(cdunits) ) THEN 
+         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "units", cdunits )
+      ENDIF
+      IF ( PRESENT(cdcalendar) ) THEN 
+         CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "calendar", cdcalendar )
+      ENDIF
+      !
+   END SUBROUTINE iom_ioipsl_gettime
+
+
+   SUBROUTINE iom_ioipsl_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
+         &                                 pv_r0d, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_ioipsl_rstput  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kt       ! ocean time-step
+      INTEGER                         , INTENT(in)           ::   kwrite   ! writing time-step
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! variable name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      INTEGER                         , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
+      REAL(wp)                        , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      INTEGER               :: idims                ! number of dimension
+      INTEGER               :: idvar                ! variable id
+      INTEGER               :: itype                ! variable type
+      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
+      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
+      CHARACTER(LEN=100)    :: clinfo               ! info character
+      INTEGER               :: ioipslid             ! ioipsl file identifier
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_ioipsl_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      ioipslid = iom_file(kiomid)%nfid
+      !
+      ! define dimension variables if it is not already done
+      ! ==========================
+      IF( iom_file(kiomid)%nvars == 0 ) THEN
+         ! define the dimension variables if it is not already done
+         CALL fliodefv( ioipslid,'nav_lon', (/1,2/), v_t=flio_r4   , axis='X',   &
+               &                  long_name="Longitude", units="degrees_east" )
+         CALL fliodefv( ioipslid,'nav_lat', (/1,2/), v_t=flio_r4   , axis='Y',   &
+               &                  long_name="Latitude", units="degrees_north" )
+         CALL fliodefv( ioipslid,'nav_lev', (/3/)  , v_t=flio_i4   , axis='Z',   &
+               &                  long_name="Model levels",units="model_levels")
+         CALL fliodefv( ioipslid,'time_counter', (/4/), v_t=flio_r4, axis='T',   &
+               &                  long_name="Time axis", units='seconds since 0001-01-01 00:00:00' )
+         ! update informations structure related the dimension variable we just added...
+         iom_file(kiomid)%nvars       = 4
+         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
+         iom_file(kiomid)%cn_var(1:3) = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
+         iom_file(kiomid)%cn_var(4)   = 'time_counter'
+         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1) = 0   
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
+      ENDIF
+
+      ! define the data if it is not already done
+      ! ===============
+      IF( kvid <= 0 ) THEN
+         ! variable definition
+         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
+         ENDIF
+         IF( PRESENT(ktype) ) THEN   ! variable external type
+            SELECT CASE (ktype)
+            CASE (jp_r8)  ;   itype = flio_r8
+            CASE (jp_r4)  ;   itype = flio_r4
+            CASE (jp_i4)  ;   itype = flio_i4
+            CASE (jp_i2)  ;   itype = flio_i2
+            CASE (jp_i1)  ;   itype = flio_i1   !   fliocom does not handle i1 type of variable
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
+            END SELECT
+         ELSE
+            itype = flio_r8
+         ENDIF
+         IF( PRESENT(pv_r0d) ) THEN   ;   CALL fliodefv (ioipslid, TRIM(cdvar)                 , v_t = itype)
+         ELSE                         ;   CALL fliodefv (ioipslid, TRIM(cdvar), idimid(1:idims), v_t = itype)
+         ENDIF
+         ! update informations structure related the new variable we want to add...
+         idvar                          = iom_file(kiomid)%nvars + 1
+         iom_file(kiomid)%nvars         = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(idvar)   = -1   ! netcdf variable id is not available in ioipsl
+         iom_file(kiomid)%scf(idvar)    = 1.
+         iom_file(kiomid)%ofs(idvar)    = 0.
+         iom_file(kiomid)%ndims(idvar)  = idims
+         IF( .NOT. PRESENT(pv_r0d) ) THEN
+            iom_file(kiomid)%luld(idvar) = .TRUE.
+            CALL flioinqf( ioipslid, ln_dim = idimsz )
+            iom_file(kiomid)%dimsz(1:idims-1,idvar) = idimsz(idimid(1:idims-1))
+         ELSE                               
+            iom_file(kiomid)%luld(idvar) = .FALSE.
+         ENDIF
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
+      ELSE
+         idvar = kvid
+      ENDIF
+
+      ! time step kwrite : write the variable
+      IF( kt == kwrite ) THEN
+         ! on what kind of domain must the data be written?
+         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
+            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
+            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
+               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
+               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
+               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+            ELSE 
+               CALL ctl_stop( 'iom_ioipsl_rp0123d: should have been an impossible case...' )
+            ENDIF
+
+            ! write dimension variables if it is not already done
+            ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
+            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
+               CALL flioputv( ioipslid, 'nav_lon'     , glamt(ix1:ix2, iy1:iy2) )
+               CALL flioputv( ioipslid, 'nav_lat'     , gphit(ix1:ix2, iy1:iy2) )
+               CALL flioputv( ioipslid, 'nav_lev'     , gdept_0 )
+               ! +++ WRONG VALUE: to be improved but not really useful...
+               CALL flioputv( ioipslid, 'time_counter', kt )
+               ! update the values of the variables dimensions size
+               CALL flioinqf( ioipslid, ln_dim = idimsz )
+               iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
+            ENDIF
+         ENDIF
+
+         ! write the data
+         ! =============
+         IF(     PRESENT(pv_r0d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r0d                      )
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r1d(                  :) )
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r2d(ix1:ix2, iy1:iy2   ) )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r3d(ix1:ix2, iy1:iy2, :) )
+         ENDIF
+         ! add 1 to the size of the temporal dimension (not really useful...)
+         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
+               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_ioipsl_rp0123d
+
+
+   !!======================================================================
+END MODULE iom_ioipsl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 4536)
@@ -0,0 +1,490 @@
+MODULE iom_nf90
+   !!=====================================================================
+   !!                    ***  MODULE  iom_nf90 ***
+   !! Input/Output manager :  Library to read input files with NF90 (only fliocom module)
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!             "   ! 07 07  (D. Storkey) Changes to iom_nf90_gettime
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+   USE netcdf          ! NetCDF library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_nf90_open, iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput
+
+   INTERFACE iom_nf90_get
+      MODULE PROCEDURE iom_nf90_g0d, iom_nf90_g123d
+   END INTERFACE
+   INTERFACE iom_nf90_rstput
+      MODULE PROCEDURE iom_nf90_rp0123d
+   END INTERFACE
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_nf90.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose : open an input file with NF90
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! nf90 identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo   ! info character
+      CHARACTER(LEN=100) ::   cltmp    ! temporary character
+      INTEGER            ::   iln      ! lengths of character
+      INTEGER            ::   istop    ! temporary storage of nstop
+      INTEGER            ::   if90id   ! nf90 identifier of the opened file
+      INTEGER            ::   idmy     ! dummy variable
+      INTEGER            ::   jl       ! loop variable
+      !---------------------------------------------------------------------
+
+      clinfo = '                    iom_nf90_open ~~~  '
+      istop = nstop   ! store the actual value of nstop
+      !
+      IF( ldok ) THEN      ! Open existing file...
+         !                 ! =============
+         IF( ldwrt ) THEN  ! ... in write mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
+            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_WRITE  , if90id), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy    ), clinfo)
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_NOWRITE, if90id), clinfo)
+         ENDIF
+      ELSE                 ! the file does not exist
+         !                 ! =============
+         iln = INDEX( cdname, '.nc' )
+         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+            IF( jpnij > 1 ) THEN
+               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.nc'
+               cdname = TRIM(cltmp)
+            ENDIF
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in WRITE mode'
+            CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), NF90_NOCLOBBER, if90id ), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy          ), clinfo)
+            ! define dimensions
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1)  , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', jpk           , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 't', NF90_UNLIMITED, idmy ), clinfo)
+            ! global attributes
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1     , 2     /) ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_global'    , (/jpiglo, jpjglo/) ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_local'     , kdompar(:,1)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_first' , kdompar(:,2)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_last'  , kdompar(:,3)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_start', kdompar(:,4)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , kdompar(:,5)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              ), clinfo)
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! start to fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name   = TRIM(cdname)
+         iom_file(kiomid)%nfid   = if90id
+         iom_file(kiomid)%iolib  = jpnf90
+         iom_file(kiomid)%nvars  = 0
+         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files, used to know if the file is in define mode 
+         CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
+         IF ( iom_file(kiomid)%iduld .GE. 0 ) THEN
+           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,   &
+        &                                               name = iom_file(kiomid)%uldname), clinfo)
+         ENDIF
+         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
+      ELSE
+         kiomid = 0               ! return error flag
+      ENDIF
+      !
+   END SUBROUTINE iom_nf90_open
+
+
+   SUBROUTINE iom_nf90_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_nf90_close  ***
+      !!
+      !! ** Purpose : close an input file with NF90
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      CHARACTER(LEN=100)  ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      !
+      clinfo = '      iom_nf90_close    , file: '//TRIM(iom_file(kiomid)%name)
+      CALL iom_nf90_check(NF90_CLOSE(iom_file(kiomid)%nfid), clinfo)
+      !    
+   END SUBROUTINE iom_nf90_close
+
+
+   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file with NF90
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER              , INTENT(in   )           ::   kiv   ! 
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      !
+      INTEGER                        ::   iom_nf90_varid   ! iom variable Id
+      INTEGER                        ::   if90id           ! nf90 file identifier
+      INTEGER                        ::   ji               ! dummy loop index
+      INTEGER                        ::   ivarid           ! NetCDF  variable Id
+      INTEGER                        ::   i_nvd            ! number of dimension of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   idimid           ! dimension ids of the variable
+      LOGICAL                        ::   llok             ! ok  test
+      CHARACTER(LEN=100)             ::   clinfo           ! info character
+      !!-----------------------------------------------------------------------
+      clinfo = '          iom_nf90_varid, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      iom_nf90_varid = 0                    ! default definition
+      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
+      if90id = iom_file(kiomid)%nfid        ! get back NetCDF file id
+      !
+      llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr   ! does the variable exist in the file
+      IF( llok ) THEN
+         iom_nf90_varid = kiv
+         iom_file(kiomid)%nvars       = kiv
+         iom_file(kiomid)%nvid(kiv)   = ivarid
+         iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
+         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, ndims = i_nvd), clinfo)   ! number of dimensions
+         iom_file(kiomid)%ndims(kiv)  = i_nvd
+         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
+         iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+         DO ji = 1, i_nvd                       ! dimensions size
+            CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
+            IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.   ! unlimited dimension? 
+         END DO
+         !---------- Deal with scale_factor and add_offset
+         llok = NF90_Inquire_attribute(if90id, ivarid, 'scale_factor') == nf90_noerr
+         IF( llok) THEN
+            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'scale_factor', iom_file(kiomid)%scf(kiv)), clinfo)
+         ELSE
+            iom_file(kiomid)%scf(kiv) = 1.
+         END IF
+         llok = NF90_Inquire_attribute(if90id, ivarid, 'add_offset') == nf90_noerr
+         IF( llok ) THEN
+            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'add_offset', iom_file(kiomid)%ofs(kiv)), clinfo)
+         ELSE
+            iom_file(kiomid)%ofs(kiv) = 0.
+         END IF
+         ! return the simension size
+         IF( PRESENT(kdimsz) ) THEN 
+            IF( i_nvd == SIZE(kdimsz) ) THEN
+               kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
+            ELSE
+               WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
+               CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
+            ENDIF
+         ENDIF
+      ELSE  
+         iom_nf90_varid = -1   !   variable not found, return error code: -1
+      ENDIF
+      !
+   END FUNCTION iom_nf90_varid
+
+
+   SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_nf90_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with NF90
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      INTEGER , INTENT(in   ) ::   kvid     ! variable id
+      REAL(wp), INTENT(  out) ::   pvar     ! read field
+      !
+      CHARACTER(LEN=100)      ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar), clinfo )
+      ! 
+   END SUBROUTINE iom_nf90_g0d
+
+
+   SUBROUTINE iom_nf90_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                    pv_r1d, pv_r2d, pv_r3d )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_nf90_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with NF90
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid    ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kvid      ! Name of the variable
+      INTEGER                    , INTENT(in   )           ::   knbdim    ! number of dimensions of the variable
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart    ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount    ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case)
+      !
+      CHARACTER(LEN=100) ::   clinfo               ! info character
+      INTEGER            ::   if90id               ! nf90 identifier of the opened file
+      INTEGER            ::   ivid                 ! nf90 variable id
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_g123d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      if90id = iom_file(kiomid)%nfid         ! get back NetCDF file id
+      ivid   = iom_file(kiomid)%nvid(kvid)   ! get back NetCDF var id
+      !
+      IF(     PRESENT(pv_r1d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r1d(:                ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ELSEIF( PRESENT(pv_r2d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ELSEIF( PRESENT(pv_r3d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ENDIF
+      !
+   END SUBROUTINE iom_nf90_g123d
+
+
+   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis kvid in the file with NF90
+      !!--------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   kiomid     ! file Identifier
+      INTEGER                   , INTENT(in   ) ::   kvid       ! variable id
+      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   ptime      ! the time axis
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdunits    ! units attribute
+      CHARACTER(len=*), OPTIONAL, INTENT(  out) ::   cdcalendar ! calendar attribute
+      !
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_gettime, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), ptime(:),   &
+            &                           start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /)), clinfo)
+      IF ( PRESENT(cdunits) ) THEN 
+         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "units", &
+            &                           values=cdunits), clinfo)
+      ENDIF
+      IF ( PRESENT(cdcalendar) ) THEN 
+         CALL iom_nf90_check(NF90_GET_ATT(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), "calendar", &
+            &                           values=cdcalendar), clinfo)
+      ENDIF
+      !
+   END SUBROUTINE iom_nf90_gettime
+
+
+   SUBROUTINE iom_nf90_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
+         &                               pv_r0d, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_nf90_rstput  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kt       ! ocean time-step
+      INTEGER                         , INTENT(in)           ::   kwrite   ! writing time-step
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! variable name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      INTEGER                         , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
+      REAL(wp)                        , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      INTEGER               :: idims                ! number of dimension
+      INTEGER               :: idvar                ! variable id
+      INTEGER               :: jd                   ! dimension loop counter   
+      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes   
+      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
+      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
+      CHARACTER(LEN=100)    :: clinfo               ! info character
+      CHARACTER(LEN= 12), DIMENSION(4) :: cltmp     ! temporary character
+      INTEGER               :: if90id               ! nf90 file identifier
+      INTEGER               :: idmy                 ! dummy variable
+      INTEGER               :: itype                ! variable type
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_nf90_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      if90id = iom_file(kiomid)%nfid
+      !
+      ! define dimension variables if it is not already done
+      ! ==========================
+      IF( iom_file(kiomid)%nvars == 0 ) THEN
+         ! are we in define mode?
+         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
+         ENDIF
+         ! define the dimension variables if it is not already done
+         cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'nav_lev     ', 'time_counter' /)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(1)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(1) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(2)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(2) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(3)), NF90_FLOAT , (/ 3    /), iom_file(kiomid)%nvid(3) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(4)), NF90_DOUBLE, (/ 4    /), iom_file(kiomid)%nvid(4) ), clinfo)
+         ! update informations structure related the dimension variable we just added...
+         iom_file(kiomid)%nvars       = 4
+         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
+         iom_file(kiomid)%cn_var(1:4) = cltmp
+         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)  
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1)  = 0   
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
+      ENDIF
+      ! define the data if it is not already done
+      ! ===============
+      IF( kvid <= 0 ) THEN
+         idvar = iom_file(kiomid)%nvars + 1
+         ! are we in define mode?
+         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
+         ENDIF
+         ! variable definition
+         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
+         ENDIF
+         IF( PRESENT(ktype) ) THEN   ! variable external type
+            SELECT CASE (ktype)
+            CASE (jp_r8)  ;   itype = NF90_DOUBLE
+            CASE (jp_r4)  ;   itype = NF90_FLOAT
+            CASE (jp_i4)  ;   itype = NF90_INT
+            CASE (jp_i2)  ;   itype = NF90_SHORT
+            CASE (jp_i1)  ;   itype = NF90_BYTE
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
+            END SELECT
+         ELSE
+            itype = NF90_DOUBLE
+         ENDIF
+         IF( PRESENT(pv_r0d) ) THEN
+            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype,                    &
+                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+         ELSE
+            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, idimid(1:idims),   &
+                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+         ENDIF
+         ! update informations structure related the new variable we want to add...
+         iom_file(kiomid)%nvars         = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%scf(idvar)    = 1.
+         iom_file(kiomid)%ofs(idvar)    = 0.
+         iom_file(kiomid)%ndims(idvar)  = idims
+         IF( .NOT. PRESENT(pv_r0d) ) THEN   ;   iom_file(kiomid)%luld(idvar) = .TRUE.
+         ELSE                               ;   iom_file(kiomid)%luld(idvar) = .FALSE.
+         ENDIF
+         DO jd = 1, idims
+            CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, idimid(jd), len = iom_file(kiomid)%dimsz(jd,idvar) ), clinfo)
+         END DO
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
+      ELSE
+         idvar = kvid
+      ENDIF
+
+      ! time step kwrite : write the variable
+      IF( kt == kwrite ) THEN
+         ! are we in write mode?
+         IF( iom_file(kiomid)%irec == -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = 0
+         ENDIF
+         ! on what kind of domain must the data be written?
+         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
+            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
+            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
+               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
+               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
+               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+            ELSE 
+               CALL ctl_stop( 'iom_nf90_rp0123d: should have been an impossible case...' )
+            ENDIF
+
+            ! write dimension variables if it is not already done
+            ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
+            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lon'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo)
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lat'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo)
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_0                 ), clinfo)
+               ! +++ WRONG VALUE: to be improved but not really useful...
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo)   
+               ! update the values of the variables dimensions size
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
+               iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
+               iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
+            ENDIF
+         ENDIF
+
+         ! write the data
+         ! =============
+         IF(     PRESENT(pv_r0d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r0d                      ), clinfo)
+         ELSEIF( PRESENT(pv_r1d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r1d(                  :) ), clinfo)
+         ELSEIF( PRESENT(pv_r2d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2, iy1:iy2   ) ), clinfo)
+         ELSEIF( PRESENT(pv_r3d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2, iy1:iy2, :) ), clinfo)
+         ENDIF
+         ! add 1 to the size of the temporal dimension (not really useful...)
+         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
+               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_nf90_rp0123d
+
+
+   SUBROUTINE iom_nf90_check( kstatus, cdinfo )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_nf90_check  ***
+      !!
+      !! ** Purpose :   check nf90 errors
+      !!--------------------------------------------------------------------
+      INTEGER,          INTENT(in) :: kstatus
+      CHARACTER(LEN=*), INTENT(in) :: cdinfo
+      !---------------------------------------------------------------------
+      IF(kstatus /= nf90_noerr)   CALL ctl_stop( 'iom_nf90_check : '//TRIM(nf90_strerror(kstatus)), TRIM(cdinfo) )
+   END SUBROUTINE iom_nf90_check
+
+
+   !!======================================================================
+END MODULE iom_nf90
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 4536)
@@ -0,0 +1,496 @@
+MODULE iom_rstdimg
+   !!=====================================================================
+   !!                    ***  MODULE  iom_rstdimg ***
+   !! Input/Output manager :  Library to read input rstdimg files
+   !!====================================================================
+   !! History :  9.0  ! 06 09  (S. Masson) Original code
+   !!--------------------------------------------------------------------
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_rstdimg_open, iom_rstdimg_close, iom_rstdimg_get, iom_rstdimg_rstput
+
+   INTERFACE iom_rstdimg_get
+      MODULE PROCEDURE iom_rstdimg_g0d, iom_rstdimg_g123d
+   END INTERFACE
+   INTERFACE iom_rstdimg_rstput
+      MODULE PROCEDURE iom_rstdimg_rp0d, iom_rstdimg_rp123d
+   END INTERFACE
+
+   INTEGER, PARAMETER ::   jpvnl          = 32   ! variable name length
+      
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_rstdimg.F90,v 1.9 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_rstdimg_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file read only (return 0 if not found)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters: 
+
+      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
+      CHARACTER(LEN=100)                      ::   cltmp                      ! temporary character
+      INTEGER                                 ::   jv                         ! loop counter
+      INTEGER                                 ::   istop                      ! temporary storage of nstop
+      INTEGER                                 ::   idrst                      ! logical unit of the restart file
+      INTEGER                                 ::   iln                        ! lengths of character
+      INTEGER                                 ::   irecl8                     ! record length
+      INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
+      INTEGER                                 ::   ivnum                      ! number of variables
+      INTEGER                                 ::   ishft                      ! counter shift
+      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
+      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
+      INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition 
+      INTEGER                                 ::   iiglo, ijglo               ! domain global size 
+      INTEGER                                 ::   jl                         ! loop variable
+      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
+      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
+      !                                                                               ! position for 1/2/3D variables
+      !---------------------------------------------------------------------
+      clinfo = '                    iom_rstdimg_open ~~~  '
+      istop = nstop      ! store the actual value of nstop
+      ios = 0            ! default definition
+      kiomid = 0         ! default definition
+      ! get a free unit
+      idrst = getunit()  ! get a free logical unit for the restart file
+!!$#if defined key_agrif 
+!!$      idrst = Agrif_Get_Unit()      
+!!$#endif 
+      ! Open the file...
+      ! =============
+      IF( ldok ) THEN      ! Open existing file...
+         ! find the record length
+         OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+            &       , RECL = 8, STATUS = 'old', ACTION = 'read', IOSTAT = ios, ERR = 987 )
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8
+         CLOSE( idrst )
+         ! Open the file with the appropriate record length and parameters
+         IF( ldwrt ) THEN  ! ... in readwrite mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READWRITE mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+               &       , RECL = irecl8, STATUS = 'old', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+               &       , RECL = irecl8, STATUS = 'old', ACTION = 'read'     , IOSTAT = ios, ERR = 987 )
+         ENDIF
+      ELSE                 ! the file does not exist
+         iln = INDEX( cdname, '.dimg' )
+         IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
+            irecl8= MAX( kdompar(1,1) * kdompar(2,1) * wp, ( 8*jpnij + 15 ) * 4 )
+            IF( jpnij > 1 ) THEN
+               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea, '.dimg'
+               cdname = TRIM(cltmp)
+            ENDIF
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in READWRITE mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'UNFORMATTED', ACCESS = 'DIRECT'   &
+               &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! Performs checks on the file
+      ! =============
+      IF( ldok ) THEN      ! old file
+         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
+              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+              &   ipni, ipnj, ipnij, iarea, iiglo, ijglo
+         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                       &
+            &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
+            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
+         clinfo = TRIM(clinfo)//' file '//TRIM(cdname)
+         IF( iiglo /= jpiglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in i direction' )
+         IF( ijglo /= jpjglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in j direction' )
+         IF( ldwrt ) THEN
+            IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in i direction' )
+            IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in j direction' )
+         ENDIF
+         IF( inz   /= jpk          )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in k direction' )
+         IF( ipni  /= jpni         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along I' )
+         IF( ipnj  /= jpnj         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along J' )
+         IF( ipnij /= jpnij        )   CALL ctl_stop( TRIM(clinfo), 'Total number of processors changed' )
+         IF( iarea /= narea        )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in area numbering ...' )
+      ENDIF
+      ! fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name    = TRIM(cdname)
+         iom_file(kiomid)%nfid    = idrst
+         iom_file(kiomid)%iolib   = jprstdimg
+         iom_file(kiomid)%iduld   = -1
+         IF( ldok ) THEN      ! old file
+            ! read variables informations from the file header
+            IF(  TRIM(clna0d(1)) == 'no0d' )   in0d = 0
+            IF(  TRIM(clna1d(1)) == 'no1d' )   in1d = 0
+            IF(  TRIM(clna2d(1)) == 'no2d' )   in2d = 0
+            IF(  TRIM(clna3d(1)) == 'no3d' )   in3d = 0
+            ivnum = in0d + in1d + in2d + in3d
+            iom_file(kiomid)%nvars            = ivnum
+            iom_file(kiomid)%irec             = 2 + in1d + in2d + inz * in3d
+            iom_file(kiomid)%luld(   1:ivnum) = .FALSE.
+            iom_file(kiomid)%scf(    1:ivnum) = 1.
+            ! scalar variable
+            DO jv = 1, in0d
+               iom_file(kiomid)%cn_var(jv) = TRIM(clna0d(jv))
+               iom_file(kiomid)%nvid(  jv) = 1
+               iom_file(kiomid)%ndims( jv) = 0
+               iom_file(kiomid)%ofs(   jv) = zval0d(jv)   ! warning: trick... we use ofs to store the value
+            END DO
+            ! 1d variable
+            ishft = in0d
+            DO jv = 1, in1d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna1d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval1d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 1
+               iom_file(kiomid)%dimsz(1  , ishft + jv) = jpk
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+            ! 2d variable
+            ishft = in0d + in1d
+            DO jv = 1, in2d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna2d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval2d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 2
+               iom_file(kiomid)%dimsz(1:2, ishft + jv) = (/ inx, iny /)
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+            ! 3d variable
+            ishft = in0d + in1d + in2d 
+            DO jv = 1, in3d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna3d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval3d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 3
+               iom_file(kiomid)%dimsz(1:3, ishft + jv) = (/ inx, iny, jpk /)
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+         ELSE                 ! new file
+            iom_file(kiomid)%nvars = 0
+            iom_file(kiomid)%irec  = 2
+            ! store file informations
+            WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, kdompar(:,1), jpk   ! store domain size
+         ENDIF
+      ENDIF
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo), '   error in opening file '//TRIM(cdname), ctmp1 )
+      ENDIF
+      !
+   END SUBROUTINE iom_rstdimg_open
+
+
+   SUBROUTINE iom_rstdimg_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_close  ***
+      !!
+      !! ** Purpose : close an input file
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      !
+      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
+      INTEGER                                 ::   jv                         ! loop counter
+      INTEGER                                 ::   irecl8                     ! record length
+      INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
+      INTEGER                                 ::   ivnum                      ! number of variables
+      INTEGER                                 ::   idrst                      ! file logical unit
+      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
+      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
+      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d    ! name of 0/1/2/3D variables
+      REAL(wp),          DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d    ! value of 0d variables or record
+      !                                                                               ! position for 1/2/3D variables
+      !---------------------------------------------------------------------
+      !
+      clinfo = '                    iom_rstdimg_close ~~~  '
+      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+      ! test if we can write in the file (test with INQUIRE gives alsways YES even with read only files...)
+      READ(  idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   
+      WRITE( idrst, REC = 1, IOSTAT = ios            ) irecl8, inx, iny, inz   
+      ! We can write in the file => we update its header before closing
+      IF( ios == 0 ) THEN
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   ! get back domain size
+         irhd = iom_file(kiomid)%irec
+         ivnum = iom_file(kiomid)%nvars
+         in0d = 0   ;   in1d = 0   ;   in2d = 0   ;   in3d = 0
+         DO jv = 1, ivnum   ! loop on each variable to get its name and value/record position
+            SELECT CASE (iom_file(kiomid)%ndims(jv))
+            CASE (0)   ! scalar variable
+               in0d = in0d + 1
+               clna0d(in0d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval0d(in0d) = iom_file(kiomid)%ofs(jv)   ! warning: trick... we use ofs to store the value
+            CASE (1)   ! 1d variable
+               in1d = in1d + 1
+               clna1d(in1d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval1d(in1d) = iom_file(kiomid)%nvid(jv)
+            CASE (2)   ! 2d variable
+               in2d = in2d + 1
+               clna2d(in2d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval2d(in2d) = iom_file(kiomid)%nvid(jv)
+            CASE (3)   ! 3d variable
+               in3d = in3d + 1
+               clna3d(in3d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval3d(in3d) = iom_file(kiomid)%nvid(jv)
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo), 'Should not ne there...' )
+            END SELECT
+         END DO
+         ! force to have at least 1 variable in each list (not necessary (?), but safer...)
+         IF( in0d == 0 ) THEN   ;   in0d = 1   ;   clna0d(1) = 'no0d'   ;   zval0d(1) = -1.   ;   ENDIF
+         IF( in1d == 0 ) THEN   ;   in1d = 1   ;   clna1d(1) = 'no1d'   ;   zval1d(1) = -1.   ;   ENDIF
+         IF( in2d == 0 ) THEN   ;   in2d = 1   ;   clna2d(1) = 'no2d'   ;   zval2d(1) = -1.   ;   ENDIF
+         IF( in3d == 0 ) THEN   ;   in3d = 1   ;   clna3d(1) = 'no3d'   ;   zval3d(1) = -1.   ;   ENDIF
+         ! update the file header before closing it
+         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              &
+            &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              &
+            &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+         IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN 
+            CALL ctl_stop( TRIM(clinfo),   &
+                 &   'Last record size is too big... You could reduce the value of jpvnl' )
+         ELSE 
+            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                        &
+                 &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
+                 &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
+         ENDIF
+      ELSE
+         ios = 0   ! we cannot write in the file
+      ENDIF
+      !
+      CLOSE( idrst, IOSTAT = ios, ERR = 987 )
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo),   &
+            &   '   error when updating the header of '//TRIM(iom_file(kiomid)%name), ctmp1 )
+      ENDIF
+      !    
+   END SUBROUTINE iom_rstdimg_close
+
+
+   SUBROUTINE iom_rstdimg_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_rstdimg_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with RSTDIMG
+      !!-----------------------------------------------------------------------
+      INTEGER,  INTENT(in   ) ::   kiomid    ! Identifier of the file
+      INTEGER,  INTENT(in   ) ::   kvid      ! variable id
+      REAL(wp), INTENT(  out) ::   pvar      ! read field
+      !---------------------------------------------------------------------
+      !
+      pvar = iom_file(kiomid)%ofs(kvid)   ! warning: trick... we use ofs to store the value
+      !
+   END SUBROUTINE iom_rstdimg_g0d
+
+
+   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
+      !!
+      !! ** Purpose : write a scalar with RSTDIMG
+      !!--------------------------------------------------------------------
+      INTEGER                   , INTENT(in) ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)          , INTENT(in) ::   cdvar    ! time axis name
+      INTEGER                   , INTENT(in) ::   kvid     ! variable id
+      REAL(wp)                  , INTENT(in) ::   pv_r0d   ! written 0d field
+      !
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      INTEGER            ::   idvar      ! variable id
+      !---------------------------------------------------------------------
+      !  
+      clinfo = '                    iom_rstdimg_rp0d ~~~  '
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
+      IF( idvar <= jpmax_vars ) THEN
+         iom_file(kiomid)%nvars = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(   idvar) = 1   ! useless, Od variables a strored in record 1
+         iom_file(kiomid)%ndims(  idvar) = 0
+         iom_file(kiomid)%luld(   idvar) = .FALSE.
+         iom_file(kiomid)%scf(    idvar) = 1.
+         iom_file(kiomid)%ofs(    idvar) = pv_r0d   ! warning: trick... we use ofs to store the value
+      ELSE
+         CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
+      ENDIF
+   END SUBROUTINE iom_rstdimg_rp0d
+
+
+   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid, kx1, kx2, ky1, ky2,   &
+         &                       pv_r1d, pv_r2d, pv_r3d )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_rstdimg_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with RSTDIMG
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
+      INTEGER                    , INTENT(in   )           ::   kvid       ! variable id
+      INTEGER ,                    INTENT(inout)           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+
+      CHARACTER(LEN=100) ::   clinfo               ! info character
+      INTEGER            ::   ios                  ! IO status
+      INTEGER            ::   jk                   ! loop counter
+      INTEGER            ::   idrst                ! logical unit of the restart file
+      !---------------------------------------------------------------------
+      clinfo = '                    iom_rstdimg_g123d ~~~  '
+      !
+      IF( kdom == jpdom_data .OR. kdom == jpdom_global ) THEN
+         CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' )
+      ELSE
+      !
+         idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+         ! modify the subdomain indexes because we cannot directly extract the appropriate subdomaine
+         IF(     kdom == jpdom_local_full    ) THEN   ;   kx1 = 1   ;   kx2 = jpi    ;   ky1 = 1
+         ELSEIF( kdom == jpdom_local_noextra ) THEN   ;   kx1 = 1   ;   kx2 = nlci   ;   ky1 = 1
+         ENDIF
+         !
+         IF(     PRESENT(pv_r1d) ) THEN   ! read 1D variables
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r1d(:)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ! read 2D variables
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r2d(kx1:kx2, ky1:ky2    )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ! read 3D variables
+            DO jk = 1, iom_file(kiomid)%dimsz(3,kvid)   ! do loop on each level
+               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   pv_r3d(kx1:kx2, ky1:ky2, jk)
+            END DO
+         ENDIF
+987      CONTINUE
+         IF( ios /= 0 ) THEN
+            WRITE(ctmp1,*) '           iostat = ', ios
+            CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE iom_rstdimg_g123d
+
+
+   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, kvid, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
+      !!
+      !! ** Purpose : write a 2D/3D variable with RSTDIMG
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! time axis name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      CHARACTER(LEN=100)    ::   clinfo               ! info character
+      INTEGER               ::   irecl8               ! reacord length
+      INTEGER               ::   ios                  ! IO status
+      INTEGER               ::   idrst                ! reacord length
+      INTEGER               ::   inx, iny, inz        ! x,y,z dimension of the variable
+      INTEGER               ::   idvar                ! variable id
+      INTEGER               ::   istop                ! temporary storage of nstop
+      INTEGER               ::   irec                 ! record number
+      INTEGER               ::   ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER               ::   jk                   ! loop counter
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_rstdimg_rp123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      istop = nstop                   ! store the actual value of nstop
+      irec = iom_file(kiomid)%irec    ! get back the record number of the variable
+      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
+      IF( idvar > jpmax_vars )   CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
+      IF( .NOT. PRESENT(pv_r1d) ) THEN
+         ! find which part of data must be written
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz
+         IF(     inx == (nlei - nldi + 1) .AND. iny == (nlej - nldj + 1) ) THEN
+            ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+         ELSEIF( inx == nlci              .AND. iny == nlcj              ) THEN
+            ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+         ELSEIF( inx == jpi               .AND. iny == jpj               ) THEN
+            ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+         ELSE 
+            CALL ctl_stop( clinfo, 'should have been an impossible case...' )
+         ENDIF
+      ENDIF
+      IF( istop == nstop ) THEN
+         ! write the data
+         IF(     PRESENT(pv_r1d) ) THEN   ! 1D variable
+            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r1d(:)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ! 2D variable
+            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r2d(ix1:ix2, iy1:iy2    )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ! 3D variable
+            DO jk = 1, jpk   ! do loop on each level
+               WRITE( idrst, REC = irec + jk - 1, IOSTAT = ios, ERR = 987 ) pv_r3d(ix1:ix2, iy1:iy2, jk)
+            END DO
+         ENDIF
+         ! fill the file informations
+         iom_file(kiomid)%nvars = idvar
+         IF(     PRESENT(pv_r1d) ) THEN
+            iom_file(kiomid)%irec              = irec + 1
+            iom_file(kiomid)%ndims(     idvar) = 1
+            iom_file(kiomid)%dimsz(1  , idvar) = inz
+         ELSEIF( PRESENT(pv_r2d) ) THEN
+            iom_file(kiomid)%irec              = irec + 1
+            iom_file(kiomid)%ndims(     idvar) = 2
+            iom_file(kiomid)%dimsz(1:2, idvar) = (/ inx, iny /)
+         ELSEIF( PRESENT(pv_r3d) ) THEN
+            iom_file(kiomid)%irec              = irec + inz
+            iom_file(kiomid)%ndims(     idvar) = 3
+            iom_file(kiomid)%dimsz(1:3, idvar) = (/ inx, iny, inz /)
+         ENDIF
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(  idvar) = irec
+         iom_file(kiomid)%luld(  idvar) = .FALSE.
+         iom_file(kiomid)%scf(   idvar) = 1.
+         iom_file(kiomid)%ofs(   idvar) = 0.
+      ENDIF
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+      ELSE
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_rstdimg_rp123d
+
+
+   !!======================================================================
+END MODULE iom_rstdimg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv.F90	(revision 4536)
@@ -0,0 +1,146 @@
+MODULE ldfeiv
+   !!======================================================================
+   !!                     ***  MODULE  ldfeiv  ***
+   !! Ocean physics:  variable eddy induced velocity coefficients
+   !!======================================================================
+#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
+   !!                  Same results but not same routine if 'key_autotasking'
+   !!                  is defined or not
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC ldf_eiv               ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp' :                  OpenMP /  NEC autotasking (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_eiv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_eiv  ***
+      !!
+      !! ** Purpose :   Compute the eddy induced velocity coefficient from the
+      !!      growth rate of baroclinic instability.
+      !!
+      !! ** Method : Specific to the offline model. Computes the horizontal
+      !!             values from the vertical value
+      !!
+      !! History :
+      !!   9.0  !  06-03  (O. Aumont)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step inedx
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk           ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ldf_eiv : eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   NEC autotasking / OpenMP : j-slab'
+      ENDIF
+
+      ! Average the diffusive coefficient at u- v- points
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiu(ji,jj) = .5 * (aeiw(ji,jj) + aeiw(ji+1,jj  ))
+            aeiv(ji,jj) = .5 * (aeiw(ji,jj) + aeiw(ji  ,jj+1))
+         END DO
+      END DO
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      ! lateral boundary condition on aeiu, aeiv
+      CALL lbc_lnk( aeiu, 'U', 1. )
+      CALL lbc_lnk( aeiv, 'V', 1. )
+
+   END SUBROUTINE ldf_eiv
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default key                                             k-j-i loops
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_eiv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_eiv  ***
+      !!
+      !! ** Purpose :   Compute the eddy induced velocity coefficient from the
+      !!      growth rate of baroclinic instability.
+      !!
+      !! ** Method : Specific to the offline model. Computes the horizontal
+      !!             values from the vertical value
+      !!
+      !! History :
+      !!   9.0  !  06-03  (O. Aumont)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step inedx
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk           ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ldf_eiv : eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Average the diffusive coefficient at u- v- points
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiu(ji,jj) = .5 * ( aeiw(ji,jj) + aeiw(ji+1,jj  ) )
+            aeiv(ji,jj) = .5 * ( aeiw(ji,jj) + aeiw(ji  ,jj+1) )
+         END DO
+      END DO
+
+      ! lateral boundary condition on aeiu, aeiv
+      CALL lbc_lnk( aeiu, 'U', 1. )
+      CALL lbc_lnk( aeiv, 'V', 1. )
+
+   END SUBROUTINE ldf_eiv
+
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Dummy module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ldf_eiv( kt )       ! Empty routine
+      WRITE(*,*) 'ldf_eiv: You should not have seen this print! error?', kt
+   END SUBROUTINE ldf_eiv
+#endif
+
+   !!======================================================================
+END MODULE ldfeiv
+
+
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfeiv_substitute.h90	(revision 4536)
@@ -0,0 +1,38 @@
+#if defined key_traldf_eiv   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!                   ***  ldfeiv_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsaei. the eddy induced velocity coeff.
+   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+#  if defined key_traldf_c3d
+!   'traldf_c3d' :                           eiv: 3D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(i,j,k)
+#    define   fsaeiv(i,j,k)   aeiv(i,j,k)
+#    define   fsaeiw(i,j,k)   aeiw(i,j,k)
+#  elif defined key_traldf_c2d
+!   'traldf_c2d' :                           eiv: 2D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(i,j)
+#    define   fsaeiv(i,j,k)   aeiv(i,j)
+#    define   fsaeiw(i,j,k)   aeiw(i,j)
+#  elif defined key_traldf_c1d
+!   'traldf_c1d' :                           eiv: 1D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(k)
+#    define   fsaeiv(i,j,k)   aeiv(k)
+#    define   fsaeiw(i,j,k)   aeiw(k)
+#  else
+!   Default option :                          eiv: Constant coefficient
+#    define   fsaeiu(i,j,k)   aeiv0
+#    define   fsaeiv(i,j,k)   aeiv0
+#    define   fsaeiw(i,j,k)   aeiv0
+#  endif
+#else
+!   Default option :                         eiv: dummy variables
+#    define   fsaeiu(i,j,k)   aeiv0
+#    define   fsaeiv(i,j,k)   aeiv0
+#    define   fsaeiw(i,j,k)   aeiv0
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfslp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfslp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldfslp.F90	(revision 4536)
@@ -0,0 +1,767 @@
+MODULE ldfslp
+   !!======================================================================
+   !!                       ***  MODULE  ldfslp  ***
+   !! Ocean physics: slopes of neutral surfaces
+   !!======================================================================
+#if   defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'                      Rotation of lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   ldf_slp      : compute the slopes of neutral surface
+   !!   ldf_slp_mxl  : compute the slopes of iso-neutral surface
+   !!   ldf_slp_init : initialization of the slopes computation
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce
+   USE phycst          ! physical constants
+   USE zdfmxl          ! mixed layer depth
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC ldf_slp        ! routine called by step.F90
+
+   !! * Share module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_ldfslp = .TRUE.     !: slopes flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      uslp, wslpi,         &  !: i_slope at U- and W-points
+      vslp, wslpj             !: j-slope at V- and W-points
+   
+   !! * Module variables
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      omlmask                 ! mask of the surface mixed layer at T-pt
+   REAL(wp), DIMENSION(jpi,jpj) ::   &
+      uslpml, wslpiml,     &  ! i_slope at U- and W-points just below
+   !                          ! the surface mixed layer
+      vslpml, wslpjml         ! j_slope at V- and W-points just below
+   !                          ! the surface mixed layer
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ldf_slp( kt, prd, pn2 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldf_slp  ***
+      !! 
+      !! ** Purpose :   Compute the slopes of neutral surface (slope of iso-
+      !!      pycnal surfaces referenced locally) ('key_traldfiso').
+      !!
+      !! ** Method  :   The slope in the i-direction is computed at U- and 
+      !!      W-points (uslp, wslpi) and the slope in the j-direction is 
+      !!      computed at V- and W-points (vslp, wslpj).
+      !!      They are bounded by 1/100 over the whole ocean, and within the
+      !!      surface layer they are bounded by the distance to the surface
+      !!      ( slope<= depth/l  where l is the length scale of horizontal
+      !!      diffusion (here, aht=2000m2/s ==> l=20km with a typical velocity
+      !!      of 10cm/s)
+      !!        A horizontal shapiro filter is applied to the slopes
+      !!        ln_sco=T, s-coordinate, add to the previously computed slopes
+      !!      the slope of the model level surface.
+      !!        macro-tasked on horizontal slab (jk-loop)  (2, jpk-1)
+      !!      [slopes already set to zero at level 1, and to zero or the ocean
+      !!      bottom slope (ln_sco=T) at level jpk in inildf]
+      !!
+      !! ** Action : - uslp, wslpi, and vslp, wslpj, the i- and  j-slopes 
+      !!               of now neutral surfaces at u-, w- and v- w-points, resp.
+      !!
+      !! History :
+      !!   7.0  !  94-12  (G. Madec, M. Imbard)  Original code
+      !!   8.0  !  97-06  (G. Madec)  optimization, lbc
+      !!   8.1  !  99-10  (A. Jouzeau)  NEW profile
+      !!   8.5  !  99-10  (G. Madec)  Free form, F90
+      !!   9.0  !  05-10  (A. Beckmann)  correction for s-coordinates
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce            , zgru  => ua,  &  ! use ua as workspace
+                           zgrv  => va,  &  ! use va as workspace
+                           zwy   => ta,  &  ! use ta as workspace
+                           zwz   => sa      ! use sa as workspace
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         prd,                            &  ! in situ density
+         pn2                                ! Brunt-Vaisala frequency (locally ref.)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      INTEGER  ::   ii0, ii1, ij0, ij1,  &  ! temporary integer
+         &          iku, ikv                !    "          "
+      REAL(wp) ::   &
+         zeps, zmg, zm05g,               &  ! temporary scalars
+         zcoef1, zcoef2, zcoef3,         &  !
+         zau, zbu, zav, zbv,             &
+         zai, zbi, zaj, zbj,             &
+         zcofu, zcofv, zcofw,            &
+         z1u, z1v, z1wu, z1wv,           &
+         zalpha
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zww
+      !!----------------------------------------------------------------------
+
+      
+      ! 0. Initialization (first time-step only)
+      !    --------------
+      
+      IF( kt == nit000 ) CALL ldf_slp_init
+      
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      
+      zeps  =  1.e-20
+      zmg   = -1.0 / grav
+      zm05g = -0.5 / grav
+
+      zww(:,:,:) = 0.e0
+      zwz(:,:,:) = 0.e0
+
+      ! horizontal density gradient computation
+      DO jk = 1, jpk
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zgru(ji,jj,jk) = umask(ji,jj,jk) * ( prd(ji+1,jj  ,jk) - prd(ji,jj,jk) ) 
+               zgrv(ji,jj,jk) = vmask(ji,jj,jk) * ( prd(ji  ,jj+1,jk) - prd(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      IF( ln_zps ) THEN      ! partial steps correction at the bottom ocean level (zps_hde routine)
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               ! last ocean level
+               iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+               ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+               zgru(ji,jj,iku) = gru(ji,jj) 
+               zgrv(ji,jj,ikv) = grv(ji,jj)               
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+      ENDIF
+
+      ! Slopes of isopycnal surfaces just below the mixed layer
+      ! -------------------------------------------------------
+      
+      CALL ldf_slp_mxl( prd, pn2 )
+      
+      !-------------------synchro---------------------------------------------
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! I.  slopes at u and v point
+         ! ===========================
+         
+         
+         ! I.1. Slopes of isopycnal surfaces
+         ! ---------------------------------
+         ! uslp = d/di( prd ) / d/dz( prd )
+         ! vslp = d/dj( prd ) / d/dz( prd )
+         
+         ! Local vertical density gradient evaluated from N^2
+         ! zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwy(ji,jj,jk) = zmg * ( prd(ji,jj,jk) + 1. )                &
+                  &          * ( pn2(ji,jj,jk) + pn2(ji,jj,jk+1) )       &
+                  &          / MAX( tmask(ji,jj,jk) + tmask (ji,jj,jk+1), 1. )
+            END DO
+         END DO
+         
+         ! Slope at u and v points
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal and vertical density gradient at u- and v-points
+               zau = 1. / e1u(ji,jj) * zgru(ji,jj,jk)
+               zav = 1. / e2v(ji,jj) * zgrv(ji,jj,jk)
+               zbu = 0.5 * ( zwy(ji,jj,jk) + zwy(ji+1,jj  ,jk) )
+               zbv = 0.5 * ( zwy(ji,jj,jk) + zwy(ji  ,jj+1,jk) )
+               ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+               !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+               zbu = MIN( zbu, -100.*ABS( zau ), -7.e+3/fse3u(ji,jj,jk)*ABS( zau ) )
+               zbv = MIN( zbv, -100.*ABS( zav ), -7.e+3/fse3v(ji,jj,jk)*ABS( zav ) )
+               ! uslp and vslp output in zwz and zww, resp.
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji+1,jj,jk) )
+               zwz (ji,jj,jk) = ( zau / ( zbu - zeps ) * ( 1. - zalpha)   &
+                  &           + zalpha * uslpml(ji,jj)                    &
+                  &                    * 0.5 * ( fsdept(ji+1,jj,jk)+fsdept(ji,jj,jk)-fse3u(ji,jj,1) )   &
+                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 5. ) ) * umask(ji,jj,jk)
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji,jj+1,jk) )
+               zww (ji,jj,jk) = ( zav / ( zbv - zeps ) * ( 1. - zalpha)   &
+                  &           + zalpha * vslpml(ji,jj)                    &
+                  &                    * 0.5 * ( fsdept(ji,jj+1,jk)+fsdept(ji,jj,jk)-fse3v(ji,jj,1) )   &
+                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 5. ) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============
+
+
+         ! lateral boundary conditions on zww and zwz
+         CALL lbc_lnk( zwz, 'U', -1. )
+         CALL lbc_lnk( zww, 'V', -1. )
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         
+         ! Shapiro filter applied in the horizontal direction
+         zcofu = 1. / 16.
+         zcofv = 1. / 16.
+         DO jj = 2, jpjm1, jpj-3   ! row jj=2 and =jpjm1 only
+            DO ji = 2, jpim1  
+               !uslop
+               uslp(ji,jj,jk) = zcofu * (       zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)      &
+                  &                       +     zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)      &
+                  &                       + 2.*(zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)      &
+                  &                       +     zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )    &
+                  &                       + 4.* zwz(ji  ,jj  ,jk)                       )
+               ! vslop
+               vslp(ji,jj,jk) = zcofv * (       zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)      &
+                  &                       +     zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)      &
+                  &                       + 2.*(zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)      &
+                  &                       +     zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )    &
+                  &                       + 4.* zww(ji,jj    ,jk)                       )
+            END DO
+         END DO
+
+         DO jj = 3, jpj-2
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! uslop
+               uslp(ji,jj,jk) = zcofu * (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)      &
+                  &                       +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)      &
+                  &                       + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)      &
+                  &                       +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )    &
+                  &                       + 4.*  zwz(ji  ,jj  ,jk)                       )
+               ! vslop
+               vslp(ji,jj,jk) = zcofv * (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)      &
+                  &                       +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)      &
+                  &                       + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)      &
+                  &                       +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )    &
+                  &                       + 4.*  zww(ji,jj    ,jk)                       )
+            END DO
+         END DO
+
+         ! decrease along coastal boundaries
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z1u  = ( umask(ji,jj+1,jk) + umask(ji,jj-1,jk) )*.5
+               z1v  = ( vmask(ji+1,jj,jk) + vmask(ji-1,jj,jk) )*.5
+               z1wu = ( umask(ji,jj,jk)   + umask(ji,jj,jk+1) )*.5
+               z1wv = ( vmask(ji,jj,jk)   + vmask(ji,jj,jk+1) )*.5
+               uslp(ji,jj,jk) = uslp(ji,jj,jk) * z1u * z1wu
+               vslp(ji,jj,jk) = vslp(ji,jj,jk) * z1v * z1wv
+            END DO
+         END DO
+
+
+         ! II. Computation of slopes at w point
+         ! ====================================
+         
+         
+         ! II.1 Slopes of isopycnal surfaces
+         ! ---------------------------------
+         ! wslpi = mij( d/di( prd ) / d/dz( prd )
+         ! wslpj = mij( d/dj( prd ) / d/dz( prd )
+         
+         
+         ! Local vertical density gradient evaluated from N^2
+         !     zwy = d/dz(prd)= - mk ( prd ) / grav * pn2 -- at w point
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwy (ji,jj,jk) = zm05g * pn2 (ji,jj,jk) *   &
+                  &                     ( prd (ji,jj,jk) + prd (ji,jj,jk-1) + 2. )
+            END DO
+         END DO
+         
+         ! Slope at w point
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal density i-gradient at w-points
+               zcoef1 = MAX( zeps, umask(ji-1,jj,jk  )+umask(ji,jj,jk  )    &
+                  &               +umask(ji-1,jj,jk-1)+umask(ji,jj,jk-1) )
+               zcoef1 = 1. / ( zcoef1 * e1t (ji,jj) )
+               zai = zcoef1 * (  zgru(ji  ,jj,jk  ) + zgru(ji  ,jj,jk-1)   &
+                  &            + zgru(ji-1,jj,jk-1) + zgru(ji-1,jj,jk  ) ) * tmask (ji,jj,jk)
+               ! horizontal density j-gradient at w-points
+               zcoef2 = MAX( zeps, vmask(ji,jj-1,jk  )+vmask(ji,jj,jk-1)   &
+                  &               +vmask(ji,jj-1,jk-1)+vmask(ji,jj,jk  ) )
+               zcoef2 = 1.0 / ( zcoef2 *  e2t (ji,jj) )
+               zaj = zcoef2 * (  zgrv(ji,jj  ,jk  ) + zgrv(ji,jj  ,jk-1)   &
+                  &            + zgrv(ji,jj-1,jk-1) + zgrv(ji,jj-1,jk  ) ) * tmask (ji,jj,jk)
+               ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
+               !                   static instability:
+               !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+               zbi = MIN( zwy (ji,jj,jk),- 100.*ABS(zai), -7.e+3/fse3w(ji,jj,jk)*ABS(zai) )
+               zbj = MIN( zwy (ji,jj,jk), -100.*ABS(zaj), -7.e+3/fse3w(ji,jj,jk)*ABS(zaj) )
+               ! wslpi and wslpj output in zwz and zww, resp.
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji,jj,jk-1) )
+               zcoef3 = fsdepw(ji,jj,jk) / MAX( hmlp(ji,jj), 10. )
+               zwz(ji,jj,jk) = (     zai / ( zbi - zeps)  * ( 1. - zalpha )   &
+                  &             + zcoef3 * wslpiml(ji,jj) *        zalpha   ) * tmask (ji,jj,jk)
+               zww(ji,jj,jk) = (     zaj / ( zbj - zeps)  * ( 1. - zalpha )   &
+                  &             + zcoef3 * wslpjml(ji,jj) *        zalpha   ) * tmask (ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============
+
+
+      ! lateral boundary conditions on zwz and zww
+      CALL lbc_lnk( zwz, 'T', -1. )
+      CALL lbc_lnk( zww, 'T', -1. )
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! Shapiro filter applied in the horizontal direction
+
+         DO jj = 2, jpjm1, jpj-3   ! row jj=2 and =jpjm1
+            DO ji = 2, jpim1
+               zcofw = tmask(ji,jj,jk)/16.
+               wslpi(ji,jj,jk) = (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)     &
+                  &                +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)     &
+                  &                + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)     &
+                  &                +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zwz(ji  ,jj  ,jk)                        ) * zcofw
+
+               wslpj(ji,jj,jk) = (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)     &
+                  &                +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)     &
+                  &                + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)     &
+                  &                +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zww(ji  ,jj  ,jk)                        ) * zcofw
+            END DO
+         END DO
+         
+         DO jj = 3, jpj-2
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcofw = tmask(ji,jj,jk)/16.
+               wslpi(ji,jj,jk) = (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)     &
+                  &                +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)     &
+                  &                + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)     &
+                  &                +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zwz(ji  ,jj  ,jk)                        ) * zcofw
+
+               wslpj(ji,jj,jk) = (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)     &
+                  &                +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)     &
+                  &                + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)     &
+                  &                +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zww(ji  ,jj  ,jk)                        ) * zcofw
+            END DO
+         END DO
+         
+         ! decrease the slope along the boundaries
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z1u = ( umask(ji,jj,jk) + umask(ji-1,jj,jk) ) *.5
+               z1v = ( vmask(ji,jj,jk) + vmask(ji,jj-1,jk) ) *.5
+               wslpi(ji,jj,jk) = wslpi(ji,jj,jk) * z1u * z1v
+               wslpj(ji,jj,jk) = wslpj(ji,jj,jk) * z1u * z1v
+            END DO
+         END DO
+         
+         
+         ! III. Specific grid points
+         ! -------------------------
+
+         IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN
+            !                                        ! =======================
+            ! Horizontal diffusion in                !  ORCA_R4 configuration 
+            ! specific area                          ! =======================
+            !
+            !                                             ! Gibraltar Strait
+            ij0 =  50   ;   ij1 =  53
+            ii0 =  69   ;   ii1 =  71   ;   uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ij0 =  51   ;   ij1 =  53
+            ii0 =  68   ;   ii1 =  71   ;   vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  69   ;   ii1 =  71   ;   wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  69   ;   ii1 =  71   ;   wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+
+            !                                             ! Mediterrannean Sea
+            ij0 =  49   ;   ij1 =  56
+            ii0 =  71   ;   ii1 =  90   ;   uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ij0 =  50   ;   ij1 =  56
+            ii0 =  70   ;   ii1 =  90   ;   vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  71   ;   ii1 =  90   ;   wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  71   ;   ii1 =  90   ;   wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============       
+
+      
+      ! III Lateral boundary conditions on all slopes (uslp , vslp, 
+      ! -------------------------------                wslpi, wslpj )
+      CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
+      CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab3d_1=uslp , clinfo1=' slp  - u : ', tab3d_2=vslp,  clinfo2=' v : ', kdim=jpk)
+         CALL prt_ctl(tab3d_1=wslpi, clinfo1=' slp  - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE ldf_slp
+
+
+   SUBROUTINE ldf_slp_mxl( prd, pn2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_slp_mxl  ***
+      !! ** Purpose :
+      !!     Compute the slopes of iso-neutral surface (slope of isopycnal
+      !!   surfaces referenced locally) just above the mixed layer.
+      !!
+      !! ** Method :
+      !!      The slope in the i-direction is computed at u- and w-points
+      !!   (uslp, wslpi) and the slope in the j-direction is computed at
+      !!   v- and w-points (vslp, wslpj).
+      !!   They are bounded by 1/100 over the whole ocean, and within the
+      !!   surface layer they are bounded by the distance to the surface
+      !!   ( slope<= depth/l  where l is the length scale of horizontal
+      !!   diffusion (here, aht=2000m2/s ==> l=20km with a typical velocity
+      !!   of 10cm/s)
+      !!
+      !! ** Action :
+      !!      Compute uslp, wslpi, and vslp, wslpj, the i- and  j-slopes
+      !!   of now neutral surfaces at u-, w- and v- w-points, resp.
+      !!
+      !! History :
+      !!   8.1  !  99-10  (A. Jouzeau)  Original code
+      !!   8.5  !  99-10  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce           , zgru  => ua,  &  ! ua, va used as workspace and set to hor. 
+                          zgrv  => va      ! density gradient in ldf_slp
+
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         prd,                           &  ! in situ density
+         pn2                              ! Brunt-Vaisala frequency (locally ref.)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   ik, ikm1               ! temporary integers
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zwy                               ! temporary workspace
+      REAL(wp) ::   &
+         zeps, zmg, zm05g,              &  ! temporary scalars
+         zcoef1, zcoef2,                &  !    "         "
+         zau, zbu, zav, zbv,            &  !    "         "
+         zai, zbi, zaj, zbj                !    "         "
+      !!----------------------------------------------------------------------
+
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+
+      zeps  =  1.e-20
+      zmg   = -1.0 / grav
+      zm05g = -0.5 / grav
+
+
+      uslpml (1,:) = 0.e0      ;      uslpml (jpi,:) = 0.e0
+      vslpml (1,:) = 0.e0      ;      vslpml (jpi,:) = 0.e0
+      wslpiml(1,:) = 0.e0      ;      wslpiml(jpi,:) = 0.e0
+      wslpjml(1,:) = 0.e0      ;      wslpjml(jpi,:) = 0.e0
+
+      ! surface mixed layer mask
+
+      ! mask for mixed layer
+      DO jk = 1, jpk
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+# endif
+               ! mixed layer interior (mask = 1) and exterior (mask = 0)
+               ik = nmln(ji,jj) - 1
+               IF( jk <= ik ) THEN
+                  omlmask(ji,jj,jk) = 1.e0
+               ELSE
+                  omlmask(ji,jj,jk) = 0.e0
+               ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+      END DO
+
+
+      ! Slopes of isopycnal surfaces just before bottom of mixed layer
+      ! --------------------------------------------------------------
+      ! uslpml = d/di( prd ) / d/dz( prd )
+      ! vslpml = d/dj( prd ) / d/dz( prd )
+
+      ! Local vertical density gradient evaluated from N^2
+      ! zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+
+      !-----------------------------------------------------------------------
+      zwy(:,jpj) = 0.e0
+      zwy(jpi,:) = 0.e0
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji+1,jj) )
+            ! if ik = jpk take jpkm1 values
+            ik = MIN( ik,jpkm1 )
+            zwy(ji,jj) = zmg * ( prd(ji,jj,ik) + 1. )   &
+               &             * ( pn2(ji,jj,ik) + pn2(ji,jj,ik+1) )   &
+               &             / MAX( tmask(ji,jj,ik) + tmask (ji,jj,ik+1), 1. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+      ! lateral boundary conditions on zwy
+      CALL lbc_lnk( zwy, 'U', -1. )
+
+      ! Slope at u points
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ! horizontal and vertical density gradient at u-points
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji+1,jj) )
+            ik = MIN( ik,jpkm1 )
+            zau = 1./ e1u(ji,jj) * zgru(ji,jj,ik)
+            zbu = 0.5*( zwy(ji,jj) + zwy(ji+1,jj) )
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+            !                         kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbu = MIN( zbu, -100.*ABS(zau), -7.e+3/fse3u(ji,jj,ik)*ABS(zau) )
+            ! uslpml
+            uslpml (ji,jj) = zau / ( zbu - zeps ) * umask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on uslpml
+      CALL lbc_lnk( uslpml, 'U', -1. )
+
+      ! Local vertical density gradient evaluated from N^2
+      !     zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+      zwy ( :, jpj) = 0.e0
+      zwy ( jpi, :) = 0.e0
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji,jj+1) )
+            ik = MIN( ik,jpkm1 )
+            zwy(ji,jj) = zmg * ( prd(ji,jj,ik) + 1. )   &
+               &             * ( pn2(ji,jj,ik) + pn2(ji,jj,ik+1) )   &
+               &             / MAX( tmask(ji,jj,ik) + tmask (ji,jj,ik+1), 1. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on zwy
+      CALL lbc_lnk( zwy, 'V', -1. )
+
+      ! Slope at v points
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ! horizontal and vertical density gradient at v-points
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji,jj+1) )
+            ik = MIN( ik,jpkm1 )
+            zav = 1./ e2v(ji,jj) * zgrv(ji,jj,ik)
+            zbv = 0.5*( zwy(ji,jj) + zwy(ji,jj+1) )
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+            !                         kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbv = MIN( zbv, -100.*ABS(zav), -7.e+3/fse3v(ji,jj,ik)*ABS( zav ) )
+            ! vslpml
+            vslpml (ji,jj) = zav / ( zbv - zeps ) * vmask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on vslpml
+      CALL lbc_lnk( vslpml, 'V', -1. )
+
+      ! wslpiml = mij( d/di( prd ) / d/dz( prd )
+      ! wslpjml = mij( d/dj( prd ) / d/dz( prd )
+
+
+      ! Local vertical density gradient evaluated from N^2
+      ! zwy = d/dz(prd)= - mk ( prd ) / grav * pn2 -- at w point
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+# endif
+            ik = nmln(ji,jj)+1
+            ik = MIN( ik,jpk )
+            ikm1 = MAX ( 1, ik-1)
+            zwy (ji,jj) = zm05g * pn2 (ji,jj,ik) *     &
+               &             ( prd (ji,jj,ik) + prd (ji,jj,ikm1) + 2. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Slope at w point
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ik = nmln(ji,jj)+1
+            ik = MIN( ik,jpk )
+            ikm1 = MAX ( 1, ik-1)
+            ! horizontal density i-gradient at w-points
+            zcoef1 = MAX( zeps, umask(ji-1,jj,ik  )+umask(ji,jj,ik  )   &
+               &               +umask(ji-1,jj,ikm1)+umask(ji,jj,ikm1) )
+            zcoef1 = 1. / ( zcoef1 * e1t (ji,jj) )
+            zai = zcoef1 * (  zgru(ji  ,jj,ik  ) + zgru(ji  ,jj,ikm1)   &
+               &            + zgru(ji-1,jj,ikm1) + zgru(ji-1,jj,ik  ) ) * tmask (ji,jj,ik)
+            ! horizontal density j-gradient at w-points
+            zcoef2 = MAX( zeps, vmask(ji,jj-1,ik  )+vmask(ji,jj,ikm1)    &
+               &               +vmask(ji,jj-1,ikm1)+vmask(ji,jj,ik  ) )
+            zcoef2 = 1.0 / ( zcoef2 *  e2t (ji,jj) )
+            zaj = zcoef2 * (  zgrv(ji,jj  ,ik  ) + zgrv(ji,jj  ,ikm1)   &
+               &            + zgrv(ji,jj-1,ikm1) + zgrv(ji,jj-1,ik  ) ) * tmask (ji,jj,ik)
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
+            !                   static instability:
+            !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbi = MIN ( zwy (ji,jj),- 100.*ABS(zai), -7.e+3/fse3w(ji,jj,ik)*ABS(zai) )
+            zbj = MIN ( zwy (ji,jj), -100.*ABS(zaj), -7.e+3/fse3w(ji,jj,ik)*ABS(zaj) )
+            ! wslpiml and wslpjml
+            wslpiml (ji,jj) = zai / ( zbi - zeps) * tmask (ji,jj,ik)
+            wslpjml (ji,jj) = zaj / ( zbj - zeps) * tmask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on wslpiml and wslpjml
+      CALL lbc_lnk( wslpiml, 'W', -1. )
+      CALL lbc_lnk( wslpjml, 'W', -1. )
+
+   END SUBROUTINE ldf_slp_mxl
+
+
+   SUBROUTINE ldf_slp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_slp_init  ***
+      !!
+      !! ** Purpose :   Initialization for the isopycnal slopes computation
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameter 
+      !!      values called by tra_dmp at the first timestep (nit000)
+      !!
+      !! History :
+      !!  8.5  ! 02-06 (G. Madec) original code
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      
+      
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ldf_slp : direction of lateral mixing'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Direction of lateral diffusion (tracers and/or momentum)
+      ! ------------------------------
+      ! set the slope to zero (even in s-coordinates)
+
+      uslp (:,:,:) = 0.e0
+      vslp (:,:,:) = 0.e0
+      wslpi(:,:,:) = 0.e0
+      wslpj(:,:,:) = 0.e0
+
+      uslpml (:,:) = 0.e0
+      vslpml (:,:) = 0.e0
+      wslpiml(:,:) = 0.e0
+      wslpjml(:,:) = 0.e0
+
+      IF( ln_traldf_hor ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '          Horizontal mixing in s-coordinate: slope = slope of s-surfaces'
+         ENDIF
+
+         ! geopotential diffusion in s-coordinates on tracers and/or momentum
+         ! The slopes of s-surfaces are computed once (no call to ldfslp in step)
+         ! The slopes for momentum diffusion are i- or j- averaged of those on tracers
+
+         ! set the slope of diffusion to the slope of s-surfaces
+         !      ( c a u t i o n : minus sign as fsdep has positive value )
+         DO jk = 1, jpk
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  uslp (ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept(ji+1,jj,jk) - fsdept(ji ,jj ,jk) ) * umask(ji,jj,jk)
+                  vslp (ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept(ji,jj+1,jk) - fsdept(ji ,jj ,jk) ) * vmask(ji,jj,jk)
+                  wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw(ji+1,jj,jk) - fsdepw(ji-1,jj,jk) ) * tmask(ji,jj,jk) * 0.5
+                  wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw(ji,jj+1,jk) - fsdepw(ji,jj-1,jk) ) * tmask(ji,jj,jk) * 0.5
+               END DO
+            END DO
+         END DO
+
+         ! Lateral boundary conditions on the slopes
+         CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
+         CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
+      ENDIF
+
+   END SUBROUTINE ldf_slp_init
+
+#else
+   !!------------------------------------------------------------------------
+   !!   Dummy module :                 NO Rotation of lateral mixing tensor
+   !!------------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_ldfslp = .FALSE.    !: slopes flag
+CONTAINS
+   SUBROUTINE ldf_slp( kt, prd, pn2 )        ! Dummy routine
+      INTEGER, INTENT(in) :: kt 
+      REAL,DIMENSION(:,:,:), INTENT(in) :: prd, pn2
+      WRITE(*,*) 'ldf_slp: You should not have seen this print! error?', kt, prd(1,1,1), pn2(1,1,1)
+   END SUBROUTINE ldf_slp
+#endif
+
+   !!======================================================================
+END MODULE ldfslp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra.F90	(revision 4536)
@@ -0,0 +1,165 @@
+MODULE ldftra
+   !!======================================================================
+   !!                       ***  MODULE  ldftra  ***
+   !! Ocean physics:  lateral diffusivity coefficient 
+   !!=====================================================================
+   !! History :
+   !!        !  07-97  (G. Madec)  from inimix.F split in 2 routines
+   !!        !  08-97  (G. Madec)  multi dimensional coefficients
+   !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+   !!   9.0  !  05-11  (G. Madec)  
+   !!----------------------------------------------------------------------
+   !!   ldf_tra_init : initialization, namelist read, and parameters control
+   !!   ldf_tra_c3d   : 3D eddy viscosity coefficient initialization
+   !!   ldf_tra_c2d   : 2D eddy viscosity coefficient initialization
+   !!   ldf_tra_c1d   : 1D eddy viscosity coefficient initialization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE ldfslp          ! ???
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC ldf_tra_init   ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ldf_tra_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_tra_init  ***
+      !! 
+      !! ** Purpose :   initializations of the tracer lateral mixing coeff.
+      !!
+      !! ** Method  :   the Eddy diffusivity and eddy induced velocity ceoff.
+      !!      are defined as follows:
+      !!         default option   : constant coef. aht0, aeiv0 (namelist)
+      !!        'key_traldf_c1d': depth dependent coef. defined in 
+      !!                            in ldf_tra_c1d routine
+      !!        'key_traldf_c2d': latitude and longitude dependent coef.
+      !!                            defined in ldf_tra_c2d routine
+      !!        'key_traldf_c3d': latitude, longitude, depth dependent coef.
+      !!                            defined in ldf_tra_c3d routine
+      !!
+      !!      N.B. User defined include files.  By default, 3d and 2d coef.
+      !!      are set to a constant value given in the namelist and the 1d
+      !!      coefficients are initialized to a hyperbolic tangent vertical
+      !!      profile.
+      !!
+      !!----------------------------------------------------------------------
+      USE ioipsl
+
+      INTEGER ::   ioptio               ! ???
+      LOGICAL ::   ll_print = .FALSE.   ! =T print eddy coef. in numout
+       
+      NAMELIST/nam_traldf/ ln_traldf_lap  , ln_traldf_bilap,                &
+         &                 ln_traldf_level, ln_traldf_hor, ln_traldf_iso,   &
+         &                 aht0, ahtb0, aeiv0
+      !!----------------------------------------------------------------------
+
+      !  Define the lateral tracer physics parameters
+      ! =============================================
+    
+      ! Read Namelist nam_traldf : Lateral physics on tracers
+      REWIND( numnam )
+      READ  ( numnam, nam_traldf )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ldf_tra_init : lateral tracer physics'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+         WRITE(numout,*) '          Namelist nam_traldf : lateral mixing coefficients'
+         WRITE(numout,*) '             laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
+         WRITE(numout,*) '             bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
+         WRITE(numout,*) '             lateral eddy diffusivity             aht0   = ', aht0
+         WRITE(numout,*) '             background hor. diffusivity          ahtb0  = ', ahtb0
+         WRITE(numout,*) '             eddy induced velocity coef.          aeiv0  = ', aeiv0
+         WRITE(numout,*)
+      ENDIF
+
+      ! Parameter control
+
+      ! ... Check consistency for type and direction :
+      !           ==> will be done in traldf module
+
+      ! ... Space variation of eddy coefficients
+      ioptio = 0
+#if defined key_traldf_c3d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( latitude, longitude, depth)'
+      ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c2d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( latitude, longitude)'
+      ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c1d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( depth )'
+      ioptio = ioptio + 1
+      IF( .NOT. ln_zco ) &
+           &   CALL ctl_stop( '          key_traldf_c1d can only be used in z-coordinate - full step' )
+#endif
+      IF( ioptio == 0 ) THEN
+          IF(lwp) WRITE(numout,*) '          tracer mixing coef. = constant (default option)'
+        ELSEIF( ioptio > 1 ) THEN
+           CALL ctl_stop('          use only one of the following keys:',   &
+             &           ' key_traldf_c3d, key_traldf_c2d, key_traldf_c1d' )
+      ENDIF
+
+      IF( ln_traldf_bilap ) THEN
+         IF(lwp) WRITE(numout,*) '          biharmonic tracer diffusion'
+         IF( aht0 > 0 .AND. .NOT. lk_esopa )   &
+              &   CALL ctl_stop( '          The horizontal diffusivity coef. aht0 must be negative' )
+      ELSE
+         IF(lwp) WRITE(numout,*) '          harmonic tracer diffusion (default)'
+         IF( aht0 < 0 .AND. .NOT. lk_esopa )   &
+              &   CALL ctl_stop('          The horizontal diffusivity coef. aht0 must be positive' )
+      ENDIF
+
+
+      !  Lateral eddy diffusivity and eddy induced velocity coefficients
+      ! ================================================================
+
+#if defined key_traldf_c3d
+      CALL ldf_tra_c3d( ll_print )      ! aht = 3D coef. = F( longitude, latitude, depth )
+#elif defined key_traldf_c2d
+      CALL ldf_tra_c2d( ll_print )      ! aht = 2D coef. = F( longitude, latitude )
+#elif defined key_traldf_c1d
+      CALL ldf_tra_c1d( ll_print )      ! aht = 1D coef. = F( depth )
+#else
+                                        ! Constant coefficients
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) '          constant eddy diffusivity coef.   ahtu = ahtv = ahtw = aht0 = ', aht0
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) '          constant eddy induced velocity coef.   aeiu = aeiv = aeiw = aeiv0 = ', aeiv0
+      ENDIF
+#endif
+
+   END SUBROUTINE ldf_tra_init
+
+#if defined key_traldf_c3d
+#   include "ldftra_c3d.h90"
+#elif defined key_traldf_c2d
+#   include "ldftra_c2d.h90"
+#elif defined key_traldf_c1d
+#   include "ldftra_c1d.h90"
+#endif
+
+   !!======================================================================
+END MODULE ldftra
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c1d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c1d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c1d.h90	(revision 4536)
@@ -0,0 +1,133 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldftra_c1d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_tra_c1d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldftra_c1d  ***
+      !!              
+      !! ** Purpose :   1D eddy diffusivity coefficient
+      !!
+      !! ** Method  :   1D eddy diffusivity coefficients ( depth )
+      !!       biharmonic operator    : ahtt = defined at T-level
+      !!                                ahtu,ahtv,ahtw never used
+      !!
+      !!       harmonic operator      : ahtt never used
+      !!          -1-  iso-model level: ahtu = ahtv defined at T-level
+      !!                                ahtw never used
+      !!          -2-  isopycnal or   : ahtu = ahtv defined at T-level
+      !!               geopotential     ahtw defined at w-level
+      !!
+      !!       eddy induced velocity
+      !!         always harmonic      : aeiu = aeiv defined at T-level
+      !!				  aeiw defined at w-level
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, print arrays in numout
+
+      !! * Local variables
+      INTEGER ::   jk                  ! dummy loop indices
+      REAL(wp) ::   &
+         zkah, zahr, za00 , za01,   &  ! temporary scalars
+         zahf, zahs, zahtf, zahts
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 1D eddy diffusivity and eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   -- ' 
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 1D eddy diffusivity coefficient '
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   -- '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! initialization of the profile
+
+      ! ahts, ahtf: surface and bottom values
+      zahts = aht0
+      zahtf = aht0/4. 
+      ! zkah, zahr: depth of the inflection pt and width of inflection
+      zkah =  -300.
+      zahr =   300.
+      ! computation coefficients
+      za00 = TANH( ( -fsdept(1,1,1  ) - zkah ) / zahr )
+      za01 = TANH( ( -fsdept(1,1,jpk) - zkah ) / zahr )
+      zahf = ( zahts-zahtf ) / ( za00 - za01 )
+      zahs = zahts - zahf * za00
+
+      ! biharmonic operator : (T-point)
+      ! ==================== 
+
+      ! set ahtt at T-level
+      DO jk = 1, jpk
+         ahtt(jk) = zahs + zahf * TANH( (-fsdept(1,1,jk)-zkah) / zahr )
+      END DO
+
+      ! control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         aht profile at T-level : '
+         WRITE(numout,*)
+         WRITE(numout,*) ' level    aht          depth t-level '
+         DO jk = 1, jpk
+            WRITE(numout,'(i6,2f12.4)') jk, ahtt(jk), fsdept(1,1,jk)
+         END DO
+      ENDIF
+
+      ! harmonic operator : (U-, V-, W-points)
+      ! ================== 
+
+      ! set ahtu = ahtv at T-level, and ahtw at w-level
+      DO jk = 1, jpk
+         ahtu(jk) = zahs + zahf * TANH( ( -fsdept(1,1,jk) - zkah ) / zahr )
+         ahtv(jk) = ahtu(jk)
+         ahtw(jk) = zahs + zahf * TANH( ( -fsdepw(1,1,jk) - zkah ) / zahr )
+      END DO
+
+      ! control print
+      IF(lwp .AND. ld_print ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aht profile at T-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' level    aht          depth t-level '
+         DO jk = 1, jpk
+            IF(lwp) WRITE(numout,"(i6,2f12.4)") jk, ahtu(jk), fsdept(1,1,jk)
+         END DO
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aht profile at W-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '  jk      aht          depth w-level '
+         DO jk = 1, jpk
+            IF(lwp)WRITE(numout,"(i6,2f12.4)") jk, ahtw(jk), fsdepw(1,1,jk)
+         END DO
+      ENDIF
+
+# if defined key_traldf_eiv
+      ! set aeiu = aeiv and set aeiw (here same profile as on aht)
+      aeiu(:) = ahtu(:)
+      aeiv(:) = aeiu(:)
+      aeiw(:) = ahtw(:)
+      
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aeiv profile at T-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '  jk      aeiv           depth t-level '
+         DO jk = 1, jpk
+            IF(lwp) WRITE(numout,"(i6,2f12.4)") jk, aeiu(jk), fsdept(1,1,jk)
+         END DO
+      ENDIF
+#endif
+
+   END SUBROUTINE ldf_tra_c1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c2d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c2d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c2d.h90	(revision 4536)
@@ -0,0 +1,146 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldftra_c2d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, print arrays in numout
+
+      !! * Local variables
+# if defined key_traldf_eiv && defined key_orca_r4
+      INTEGER ::   ji, jj                  ! dummy loop indices
+# endif
+# if defined key_orca_r4
+      INTEGER :: i1, i2, j1, j2
+# endif
+      REAL(wp) ::   za00, zdx_max
+      
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 2D eddy diffusivity and eddy'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   --  induced velocity coefficients'
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 2D eddy diffusivity coefficient'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   --'
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! harmonic operator : (U-, V-, W-points)
+      ! ==================
+      IF( ln_traldf_lap ) THEN
+
+         ahtu(:,:) = aht0                ! set ahtu = ahtv at u- and v-points,
+         ahtv(:,:) = aht0                ! and ahtw at w-point (idem T-point)
+         ahtw(:,:) = aht0                ! 
+
+         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. )
+
+         ! 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
+
+         zdx_max = MAXVAL( e1t(:,:) )
+         IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+         za00 = aht0 / ( zdx_max * zdx_max * zdx_max )
+         ahtt(:,:) = za00 * e1t(:,:) * e1t(:,:) *e1t(:,:)      ! set ahtt at T-point 
+
+         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: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c3d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c3d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_c3d.h90	(revision 4536)
@@ -0,0 +1,130 @@
+   !!----------------------------------------------------------------------
+   !!                        ***  ldftra_c3d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_tra_c3d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldftra_c3d  ***
+      !!                
+      !! ** Purpose :
+      !!     initializations of non uniform horizontal eddy diffusivity coef.
+      !!
+      !! ** Method :
+      !!      3D eddy diffusivity coefficients ( longitude, latitude, depth )
+      !!
+      !!       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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                   ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 3D eddy diffusivity and eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   --  '
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 3D eddy diffusivity coefficient'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   -- '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+
+      ! biharmonic operator   (T-point)
+      ! -------------------
+
+      ahtt(:,:,:) = aht0              ! set ahtt at T-point (here no space variation)
+
+      CALL lbc_lnk( ahtt, 'T', 1. )   ! Lateral boundary conditions on ( ahtt )
+
+      IF(lwp .AND. ld_print ) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtt at k = 1'
+         CALL prihre( ahtt(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+      ENDIF
+
+
+      ! harmonic operator   (U-, V-, W-points)
+      ! ----------------- 
+
+      ahtu(:,:,:) = aht0              ! set ahtu = ahtv at u- and v-points,
+      ahtv(:,:,:) = aht0              ! and ahtw at w-point
+      ahtw(:,:,:) = aht0              ! (here example: no space variation)
+      
+      CALL lbc_lnk( ahtu, 'U', 1. )   ! Lateral boundary conditions
+      CALL lbc_lnk( ahtv, 'V', 1. )
+      CALL lbc_lnk( ahtw, 'W', 1. )
+
+      IF(lwp .AND. ld_print ) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtu at k = 1'
+         CALL prihre( ahtu(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtv at k = 1'
+         CALL prihre( ahtv(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtw at k = 1'
+         CALL prihre( ahtw(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+      ENDIF
+
+# if defined key_traldf_eiv
+      aeiu(:,:,:) = aeiv0            ! set aeiu = aeiv at u- and v-points,
+      aeiv(:,:,:) = aeiv0            ! and aeiw at w-point
+      aeiw(:,:,:) = aeiv0            ! (here example: no space variation)
+
+      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
+
+      CALL lbc_lnk( aeiu, 'U', 1. )   ! Lateral boundary conditions 
+      CALL lbc_lnk( aeiv, 'V', 1. )
+      CALL lbc_lnk( aeiw, 'W', 1. )
+# endif
+
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiu at k = 1'
+         CALL prihre(aeiu(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiv at k = 1'
+         CALL prihre(aeiv(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiw at k = 1'
+         CALL prihre(aeiw(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+
+END SUBROUTINE ldf_tra_c3d
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_oce.F90	(revision 4536)
@@ -0,0 +1,90 @@
+MODULE ldftra_oce
+   !!=====================================================================
+   !!                      ***  MODULE  ldftra_oce  ***
+   !! Ocean physics :  lateral tracer mixing coefficient defined in memory 
+   !!=====================================================================
+   !!
+   !! ** Purpose : - Define in memory lateral tracer mixing coefficients
+   !!
+   !! History :
+   !!   9.0  !  02-11  (G. Madec)  Original code (from common.h)
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !!----------------------------------------------------------------------
+   !! Lateral eddy diffusivity coefficients (tracers)
+   !!----------------------------------------------------------------------
+
+   LOGICAL , PUBLIC ::              & !!: ** lateral mixing namelist (nam_traldf) **
+      ln_traldf_lap   = .TRUE.  ,   &  !: laplacian operator
+      ln_traldf_bilap = .FALSE. ,   &  !: bilaplacian operator
+      ln_traldf_level = .FALSE. ,   &  !: iso-level direction
+      ln_traldf_hor   = .FALSE. ,   &  !: horizontal (geopotential) direction
+      ln_traldf_iso   = .TRUE.         !: iso-neutral direction
+
+   REAL(wp), PUBLIC ::              & !!: ** lateral mixing namelist (namldf) **
+      aht0  = 2000._wp     ,        &  !: lateral eddy diffusivity (m2/s)
+      ahtb0 =    0._wp     ,        &  !: lateral background eddy diffusivity (m2/s)
+      aeiv0 = 2000._wp                 !: eddy induced velocity coefficient (m2/s)
+
+   LOGICAL , PUBLIC ::              &  !: flag of the lateral diff. scheme used 
+      l_traldf_lap         ,        &  !: iso-level laplacian operator
+      l_traldf_bilap       ,        &  !: iso-level bilaplacian operator
+      l_traldf_bilapg      ,        &  !: geopotential bilap. (s-coord)
+      l_traldf_iso         ,        &  !: iso-neutral laplacian or horizontal lapacian (s-coord)
+      l_trazdf_iso         ,        &  !: idem for the vertical component
+      l_trazdf_iso_vo      ,        &  !: idem with vectopt_memory
+      l_traldf_iso_zps                 !: iso-neutral laplacian (partial steps)
+
+#if defined key_traldf_c3d || defined key_off_degrad
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !: ** 3D coefficients **
+#elif defined key_traldf_c2d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   &  !: ** 2D coefficients **
+#elif defined key_traldf_c1d
+   REAL(wp), PUBLIC, DIMENSION(jpk)         ::   &  !: ** 1D coefficients **
+#else
+   REAL(wp), PUBLIC                         ::   &  !: ** 0D coefficients **
+#endif
+      ahtt, ahtu, ahtv, ahtw                !: T-, U-, V-, W-points coefficients
+
+
+#if defined key_traldf_eiv
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_eiv'                              eddy induced velocity
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_traldf_eiv   = .TRUE.   !: eddy induced velocity flag
+      
+# if defined key_traldf_c3d || defined key_off_degrad
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !: ** 3D coefficients **
+# elif defined key_traldf_c2d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   &  !: ** 2D coefficients **
+# elif defined key_traldf_c1d
+   REAL(wp), PUBLIC, DIMENSION(jpk)         ::   &  !: ** 1D coefficients **
+# else
+   REAL(wp), PUBLIC                         ::   &  !: ** 0D coefficients **
+# endif
+      aeiu, aeiv, aeiw                              !: U-, V-, W-points  induced velocity coef. (m2/s)
+
+# if defined key_diaeiv
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::    &  !:
+      u_eiv, v_eiv, w_eiv     !: The three component of the eddy induced velocity (m/s)
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                           NO eddy induced velocity
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_traldf_eiv   = .FALSE.   !: eddy induced velocity flag
+   REAL(wp), PUBLIC ::   aeiu, aeiv, aeiw
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE ldftra_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/LDF/ldftra_substitute.h90	(revision 4536)
@@ -0,0 +1,35 @@
+   !!----------------------------------------------------------------------
+   !!                    *** ldftra_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsaht. the eddy diffusivity coeff.
+   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+#if defined key_traldf_c3d
+!   'key_traldf_c3d' :                 aht: 3D coefficient
+#       define   fsahtt(i,j,k)   ahtt(i,j,k)
+#       define   fsahtu(i,j,k)   ahtu(i,j,k)
+#       define   fsahtv(i,j,k)   ahtv(i,j,k)
+#       define   fsahtw(i,j,k)   ahtw(i,j,k)
+#elif defined key_traldf_c2d
+!   'key_traldf_c2d' :                 aht: 2D coefficient
+#       define   fsahtt(i,j,k)   ahtt(i,j)
+#       define   fsahtu(i,j,k)   ahtu(i,j)
+#       define   fsahtv(i,j,k)   ahtv(i,j)
+#       define   fsahtw(i,j,k)   ahtw(i,j)
+#elif defined key_traldf_c1d
+!   'key_traldf_c1d' :                aht: 1D coefficient
+#       define   fsahtt(i,j,k)   ahtt(k)
+#       define   fsahtu(i,j,k)   ahtu(k)
+#       define   fsahtv(i,j,k)   ahtv(k)
+#       define   fsahtw(i,j,k)   ahtw(k)
+#else
+!   Default option :             aht: Constant coefficient
+#      define   fsahtt(i,j,k)   aht0
+#      define   fsahtu(i,j,k)   aht0
+#      define   fsahtv(i,j,k)   aht0
+#      define   fsahtw(i,j,k)   aht0
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/blk_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/blk_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/blk_oce.F90	(revision 4536)
@@ -0,0 +1,40 @@
+MODULE blk_oce
+   !!======================================================================
+   !!                 ***  MODULE  blk_oce  ***
+   !! Bulk   :  bulk parameter and  variables defined in memory 
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+   !!----------------------------------------------------------------------
+   !! ' key_flx_bulk_monthly or defined key_flx_bulk_daily             bulk
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+
+   LOGICAL, PUBLIC ::   l_bulk = .TRUE.   !: 
+   
+   !!----------------------------------------------------------------------
+   !! bulk common variables
+   !!----------------------------------------------------------------------
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      vatm     ,      &  !: wind speed
+      catm               !: percent of cloud cover
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC ::   l_bulk = .FALSE.  !:
+#endif
+   
+   !!----------------------------------------------------------------------
+END MODULE blk_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf.F90	(revision 4536)
@@ -0,0 +1,322 @@
+MODULE flxrnf
+   !!======================================================================
+   !!                       ***  MODULE  flxrnf  ***
+   !! Ocean forcing:  runoff
+   !!=====================================================================
+#if defined key_orca_r05
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r05'                               ORCA R05 configuration
+   !!----------------------------------------------------------------------
+#  include "flxrnf_ORCA_R05.h90"
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                     Standard runoffs
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   flx_rnf      : monthly runoff read in a NetCDF file
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE iom             ! I/O module
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC flx_rnf          ! routine call in step module
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      runoff,           &  !: monthly runoff (kg/m2/s)
+      upsadv,           &  !: mixed adv scheme in straits vicinity (hori.)
+      upsrnfh              !: mixed adv scheme in runoffs vicinity (hori.)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      upsrnfz              !: mixed adv scheme in runoffs vicinity (vert.)
+   INTEGER, PUBLIC ::   &  !:
+      nrunoff =  0         !: runoff option (namelist)
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &  !:
+      rnfdta               !: monthly runoff data array (kg/m2/s)
+   INTEGER  ::          &  !:
+      numrnf,           &  !: logical unit for runoff data
+      nrnf1, nrnf2         !: first and second record used
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx_rnf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_rnf  ***
+      !!       
+      !! ** Purpose :   Introduce a climatological run off forcing
+      !!
+      !! ** Method :
+      !!      Initialze each mouth of river with a monthly climatology 
+      !!      provided from different data.
+      !!     C a u t i o n : upward water flux, runoff is negative
+      !!                     set at the last loop of the routine
+      !!
+      !! ** Action :
+      !!
+      !! References : 
+      !!       J. D. Milliman and R. H. Meade, 1983 : world-wide delivery
+      !!          of river sediment to the oceans, journal of geology vol 91
+      !!          pp 1-21.
+      !!       G. L. Russell and J. R. Miller, 1990 : global river runoff
+      !!          calculated from a global atmospheric general circulation
+      !!          model, journal of hydrology, 117(1990), pp 241-254.
+      !!       F. Van Der Leeden, Troise F. L., Todd D. K. : the water
+      !!          encyclopedia, second edition, lewis publishers.
+      !!       J. W. Weatherly, J. E. Walsh : The effects of precipitation
+      !!          and river runoff in a coupled ice-ocean model of Arctic
+      !!          Climate dynamics 1996 12:785,798
+      !!       Jacobs et al. 1992. J. Glaciol. 38 (130) 375-387.
+      !!
+      !! History :
+      !!        !  94-10  (G.Madec, M. Pontaud, M. Imbard)  Original code
+      !!        !  97-03  (G.Madec)  time dependent version
+      !!        !  98-06  (J.M. Molines)  exact computation of zxy 
+      !!                         for months that are not 30 days
+      !!        !  98-07  (M. Imbard)  ORCA and mpp option
+      !!        !  99-08  (J.P. Boulanger H.L.Ayina)  New rivers and 
+      !!                         values given in m3/s 
+      !!        !  00-04  (G. Madec, K. Roberts) add antarctica ice discharge.
+      !!        !  00-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt       ! ocean time step
+
+      !! * Local declarations
+# if ! defined key_coupled
+      INTEGER  ::   ji, jj                 ! dummy loop indices
+      INTEGER ::   &
+         i15 , imois , iman,            &  ! temporary integers
+         idbd, idmeom                      !    "          "
+      REAL(wp) ::   zxy
+# endif
+      INTEGER  ::   ii0, ii1, ij0, ij1     !    "          "
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+
+         SELECT CASE ( nrunoff )
+
+         CASE ( 0 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : No runoff in this simulation (nrunoff=0)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+            
+         CASE ( 1 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : monthly runoff (nrunoff=1)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+         CASE ( 2 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : monthly runoff with upsteam advection'
+            IF(lwp) WRITE(numout,*) '~~~~~~~   in the vicinity of river mouths (nrunoff=2)'
+
+         CASE DEFAULT
+            WRITE(ctmp1,*) ' Error nrunoff = ', nrunoff, ' /= 0, 1 or 2'
+            CALL ctl_stop( ctmp1 )
+
+         END SELECT
+
+         ! Set runoffs and upstream coeff to zero
+         upsadv (:,:) = 0.e0
+
+      ENDIF
+
+
+      ! 1. Initialization
+      ! -----------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2 ) THEN
+# if ! defined key_coupled
+
+         ! year, month, day
+         iman  = INT( raamo )
+!!! better but change the results      i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+         i15   = nday / 16
+         imois = nmonth + i15 - 1
+         IF( imois == 0 ) imois = iman
+         ! Number of days in the month
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+# endif
+         
+         ! Open file
+
+         IF( kt == nit000 ) THEN
+
+            nrnf1 = 0   ! initialization
+            IF (lwp) WRITE(numout,*) 'flx_rnf : Monthly runoff'
+            CALL iom_open ( 'runoff_1m_nomask.nc', numrnf )
+            
+         ENDIF
+         
+# if ! defined key_coupled
+
+         ! 2. Read monthly file of runoff
+         ! ------------------------------
+
+         IF( kt == nit000 .OR. imois /= nrnf1 ) THEN
+
+            ! Calendar computation for interpolation
+            !     nrnf1 number of the first array record used in the simulation
+            !     nrnf2 number of the last  array record
+
+            nrnf1 = imois
+            nrnf2 = nrnf1 + 1
+            nrnf1 = MOD( nrnf1, iman )
+            IF( nrnf1 == 0 ) nrnf1 = iman
+            nrnf2 = MOD( nrnf2, iman )
+            IF( nrnf2 == 0 ) nrnf2 = iman
+            
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' runoff monthly field'
+               WRITE(numout,*) ' --------------------'
+               WRITE(numout,*) ' NetCDF format'
+               WRITE(numout,*)
+               WRITE(numout,*) 'first array record used nrnf1 ', nrnf1
+               WRITE(numout,*) 'last  array record used nrnf2 ', nrnf2
+               WRITE(numout,*)
+            ENDIF
+            
+            ! Read monthly runoff data in kg/m2/s
+
+            CALL iom_get ( numrnf, jpdom_data, 'sorunoff', rnfdta(:,:,1), nrnf1 )
+            CALL iom_get ( numrnf, jpdom_data, 'sorunoff', rnfdta(:,:,2), nrnf2 )
+
+         ENDIF
+
+         ! Linear interpolation and conversion in upward water flux
+         ! C a u t i o n : runoff is negative and in kg/m2/s 
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         runoff(:,:) = -( ( 1.e0 - zxy ) * rnfdta(:,:,1) + zxy * rnfdta(:,:,2) )
+
+         ! Runoff reduction only associated to the ORCA2_LIM configuration
+         ! when reading the NetCDF file runoff_1m_nomask.nc
+         IF( cp_cfg == 'orca' .AND. jp_cfg == 2 )   THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( gphit(ji,jj) > 40 .AND. gphit(ji,jj) < 65 )   runoff(ji,jj) = 0.85 * runoff(ji,jj)
+               END DO
+            END DO
+         ENDIF
+         
+# endif
+
+      ENDIF
+
+
+      ! 3. Mixed advection scheme 
+      ! -------------------------
+
+      IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+         ! Upstream and centered scheme in the vicinity of river mouths
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+
+         CALL iom_get ( numrnf, jpdom_data, 'socoefr', upsrnfh )
+         
+         upsrnfz(:)   = 0.e0
+         upsrnfz(1)   = 1.0
+         upsrnfz(2)   = 1.0
+         upsrnfz(3)   = 0.5
+         upsrnfz(4)   = 0.25
+         upsrnfz(5)   = 0.125
+         
+         IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN
+            ! ORCA_R2 configuration : upstream scheme in the Sound Strait
+            ij0 = 116   ;   ij1 = 116
+            ii0 = 144   ;   ii1 = 144   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+            ii0 = 145   ;   ii1 = 147   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+            ii0 = 148   ;   ii1 = 148   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+         ENDIF
+
+      ENDIF
+
+      ! Upstream and centered scheme in the vicinity of some straits
+
+      IF( kt == nit000 ) THEN 
+
+         IF( cp_cfg == "orca" ) THEN
+
+            SELECT CASE ( jp_cfg )
+            !                                        ! =======================
+            CASE ( 4 )                               !  ORCA_R4 configuration 
+               !                                     ! =======================
+
+               !                                          ! Gibraltar Strait
+               ii0 =  70   ;   ii1 =  71
+               ij0 =  52   ;   ij1 =  53   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+         
+               !                                     ! =======================
+            CASE ( 2 )                               !  ORCA_R2 configuration 
+               !                                     ! =======================
+
+               !                                          ! Gibraltar Strait
+               ij0 = 102   ;   ij1 = 102
+               ii0 = 138   ;   ii1 = 138   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.20
+               ii0 = 139   ;   ii1 = 139   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+               ii0 = 140   ;   ii1 = 140   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+               ij0 = 101   ;   ij1 = 102
+               ii0 = 141   ;   ii1 = 141   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+
+               !                                          ! Bab el Mandeb Strait
+               ij0 =  87   ;   ij1 =  88
+               ii0 = 164   ;   ii1 = 164   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.10
+               ij0 =  88   ;   ij1 =  88
+               ii0 = 163   ;   ii1 = 163   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+               ii0 = 162   ;   ii1 = 162   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+               ii0 = 160   ;   ii1 = 161   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+               ij0 =  89   ;   ij1 =  89
+               ii0 = 158   ;   ii1 = 160   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+               ij0 =  90   ;   ij1 =  90
+               ii0 = 160   ;   ii1 = 160   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+
+               !                                          ! Sound Strait
+               ij0 = 116   ;   ij1 = 116
+               ii0 = 145   ;   ii1 = 147   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+         
+            END SELECT 
+
+         ENDIF
+
+      ENDIF
+     
+      ! 4. Closing all files
+      ! --------------------
+
+      IF( kt == nitend .AND. nrunoff >= 1 )   CALL iom_close( numrnf )
+
+   END SUBROUTINE flx_rnf
+
+#endif
+   !!======================================================================
+END MODULE flxrnf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R05.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R05.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R05.h90	(revision 4536)
@@ -0,0 +1,1173 @@
+   !!----------------------------------------------------------------------
+   !!                  *** flxrnf_ORCA_R05.h90  ***
+   !!----------------------------------------------------------------------
+   !!   flx_rnf      : update ocean runoffs for ORCA_R05 configuration
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC flx_rnf         ! routine call by step.F90
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      runoff,            &  !: monthly runoff (kg/m2/s)
+      upsadv,            &  !: mixed adv scheme in straits vicinity (hori.)
+      upsrnfh               !: mixed adv scheme in runoffs vicinity (hori.)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      upsrnfz               !: mixed adv scheme in runoffs vicinity (vert.)
+   INTEGER , PUBLIC ::   &  !:
+      numrof  = 48 ,     &  !: logical unit for runoff data
+      nrunoff =  0 ,     &  !: runoff option (namelist)
+      nrnf1, nrnf2          !: first and second record used
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &  !:
+      rnfdta                !: monthly runoff data array (kg/m2/s)
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx_rnf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_rnf  ***
+      !!       
+      !! ** Purpose :   Introduce a climatological run off forcing
+      !!
+      !! ** Method  :   ORCA R05 configuration
+      !!      Initialze each mouth of river with a monthly climatology 
+      !!      provided from different data.
+      !!     C a u t i o n : upward water flux, runoff is negative
+      !!                     set at the last loop of the routine
+      !!
+      !! ** Action :
+      !!
+      !! References : 
+      !!       J. D. Milliman and R. H. Meade, 1983 : world-wide delivery
+      !!          of river sediment to the oceans, journal of geology vol 91
+      !!          pp 1-21.
+      !!       G. L. Russell and J. R. Miller, 1990 : global river runoff
+      !!          calculated from a global atmospheric general circulation
+      !!          model, journal of hydrology, 117(1990), pp 241-254.
+      !!       F. Van Der Leeden, Troise F. L., Todd D. K. : the water
+      !!          encyclopedia, second edition, lewis publishers.
+      !!       J. W. Weatherly, J. E. Walsh : The effects of precipitation
+      !!          and river runoff in a coupled ice-ocean model of Arctic
+      !!          Climate dynamics 1996 12:785,798
+      !!       Jacobs et al. 1992. J. Glaciol. 38 (130) 375-387.
+      !!
+      !! History :
+      !!        !  94-10  (G.Madec, M. Pontaud, M. Imbard)  Original code
+      !!        !  97-03  (G.Madec)  time dependent version
+      !!        !  98-06  (J.M. Molines)  exact computation of zxy 
+      !!                         for months that are not 30 days
+      !!        !  98-07  (M. Imbard)  ORCA and mpp option
+      !!        !  99-08  (J.P. Boulanger H.L.Ayina)  New rivers and 
+      !!                         values given in m3/s 
+      !!        !  00-04  (G. Madec, K. Roberts) add antarctica ice discharge.
+      !!        !  00-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt ! ocean time step
+
+#if defined key_coupled
+      runoff(:,:) = 0.0e0
+#else
+      !!----------------------------------------------------------------------
+      !!  ORCA_R05
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER, PARAMETER ::   &
+         jpmois=12,   &  ! number of month in the year !
+         jpriv=120,   &  ! maximum number of rivers
+         jpcoef=20       ! maximum number of gridpoints for mouth rivers
+
+      INTEGER  ::   ji, jj, jl, jm, jn, jr, jc
+      INTEGER  ::   i15, imois, iman
+      INTEGER  ::   inbp, idbd, idmeom
+      INTEGER  ::   iirnf(jpcoef,jpriv),ijrnf(jpcoef,jpriv)
+      INTEGER  ::   inb(jpriv)
+
+      REAL(wp) ::   zconv, zxy
+      REAL(wp) ::   zrup1,zrup2,zrup3
+      REAL(wp) ::   zrnfm(jpmois, jpriv)
+      REAL(wp) ::   zcoefr(jpi, jpj, 5)
+      
+      ! ====
+      ! DATA
+      ! ====
+
+      ! I NORTH AMERICA
+      ! ---------------
+
+      ! 1-Saint Lawrence (Canada) 49N30 67W00               R2
+      ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+      ! --> 13975.249m3/s
+      DATA inb(1)/3/
+      DATA (iirnf(jc,1),jc=1,jpcoef)/ 444, 444, 444, 17*0 /
+      DATA (ijrnf(jc,1),jc=1,jpcoef)/ 367, 368, 369, 17*0 /
+      DATA (zrnfm(jm,1),jm=1,jpmois)/   &
+          11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+          14211.,  13119.,  13367.,  13644.,  13463.,  12594./
+      ! 2-Hudson River (USA) 41N00 77W00                    R1
+      ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+      ! --> 407.416687m3/s
+      DATA inb(2)/1/
+      DATA (iirnf(jc,2),jc=1,jpcoef)/ 426, 19*0 /
+      DATA (ijrnf(jc,2),jc=1,jpcoef)/ 336, 19*0 /
+      DATA (zrnfm(jm,2),jm=1,jpmois)/   &
+          364.,    404.,    648.,    873.,    593.,    301.,   &
+          205.,    171.,    205.,    290.,    379.,    456./
+      ! 3-Missisipi and Atchafalaya (USA) 29N 90W           R1 
+      ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+      ! --> 17599.334m3/s
+      DATA inb(3)/2/
+      DATA (iirnf(jc,3),jc=1,jpcoef)/ 397, 398, 18*0 /
+      DATA (ijrnf(jc,3),jc=1,jpcoef)/ 312, 313, 18*0 /
+      DATA (zrnfm(jm,3),jm=1,jpmois)/   &
+          19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+          14181.,  10676.,   9578.,  10167.,  11699.,  17472./
+      ! 4-Brazos (USA) 29N58 95W53                          R1
+      ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+      ! --> 199.666656m3/s
+      DATA inb(4)/1/
+      DATA (iirnf(jc,4),jc=1,jpcoef)/ 386, 19*0 /
+      DATA (ijrnf(jc,4),jc=1,jpcoef)/ 311, 19*0 /
+      DATA (zrnfm(jm,4),jm=1,jpmois)/   &
+          165.,    224.,    200.,    266.,    457.,    327.,   &
+          143.,     69.,    102.,    132.,    160.,    151./
+      ! 5-Colorado (Mexico) 31N54 114W57                    R5
+      ! Old=20 km3/year=634m3/s
+      ! --> 634.m3/s
+      DATA inb(5)/2/
+      DATA (iirnf(jc,5),jc=1,jpcoef)/ 347, 348, 18*0 /
+      DATA (ijrnf(jc,5),jc=1,jpcoef)/ 316, 316, 18*0 /
+      DATA (zrnfm(jm,5),jm=1,jpmois)/12*634./ 
+      ! 6-Columbia (USA) 45N60 121W17                       R1
+      ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+      ! --> 5368.41602m3/s
+      DATA inb(6)/2/
+      DATA (iirnf(jc,6),jc=1,jpcoef)/ 326, 326, 18*0 /
+      DATA (ijrnf(jc,6),jc=1,jpcoef)/ 360, 361, 18*0 /
+      DATA (zrnfm(jm,6),jm=1,jpmois)/   &
+          4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+          6350.,    4112.,    3273.,    3251.,    3548.,    4106./ 
+      ! 7-Fraser (USA)                                      R5
+      ! Old=112 km3/year=3550m3/s;not found in UNESCO
+      ! --> 3549.99976m3/s
+      DATA inb(7)/2/
+      DATA (iirnf(jc,7),jc=1,jpcoef)/ 317, 317, 18*0 /
+      DATA (ijrnf(jc,7),jc=1,jpcoef)/ 378, 379, 18*0 /
+      DATA (zrnfm(jm,7),jm=1,jpmois)/12*3550./ 
+      ! 8-Yukon (USA) 63N00 165W00                          R3
+      ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+      ! --> 6017.24951m3/s
+      DATA inb(8)/2/
+      DATA (iirnf(jc,8),jc=1,jpcoef)/ 244, 244, 18*0 /
+      DATA (ijrnf(jc,8),jc=1,jpcoef)/ 413, 414, 18*0 /
+      DATA (zrnfm(jm,8),jm=1,jpmois)/   &
+           1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+          10680.,   11271.,    8658.,    5453.,    2649.,    1917./ 
+      ! 9-Copper (USA) 61N47 144W45                         R2
+      ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+      ! --> 1236.25m3/s
+      DATA inb(9)/1/
+      DATA (iirnf(jc,9),jc=1,jpcoef)/ 274, 19*0 /
+      DATA (ijrnf(jc,9),jc=1,jpcoef)/ 409, 19*0 /
+      DATA (zrnfm(jm,9),jm=1,jpmois)/   &
+           219.,    195.,    181.,    214.,    904.,   2532.,   &
+          4026.,   3627.,   1632.,    697.,    354.,    254./ 
+      ! 10-Susitna (USA)                                    R5
+      ! Old=40 km3/year=1268m3/s
+      ! --> 1268.m3/s
+      DATA inb(10)/2/
+      DATA (iirnf(jc,10),jc=1,jpcoef)/ 263, 264, 18*0 /
+      DATA (ijrnf(jc,10),jc=1,jpcoef)/ 405, 405, 18*0 /
+      DATA (zrnfm(jm,10),jm=1,jpmois)/12*1268./ 
+      ! 11-McKenzie (Canada) 70N00 135W00                   R3
+      ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+      ! ratio=1.16
+      ! --> 9606.66797m3/s
+      DATA inb(11)/3/
+      DATA (iirnf(jc,11),jc=1,jpcoef)/ 272, 272, 272, 17*0 /
+      DATA (ijrnf(jc,11),jc=1,jpcoef)/ 451, 452, 453, 17*0 /
+      DATA (zrnfm(jm,11),jm=1,jpmois)/   &
+           3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+          18954.,   15487.,   11284.,   10169.,    5901.,    3905./
+      ! 12-Kuksokwim (USA) 60N00 ~162W30                    R4
+      ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+      ! --> 1111.99988m3/s
+      DATA inb(12)/2/
+      DATA (iirnf(jc,12),jc=1,jpcoef)/ 244, 245, 18*0 /
+      DATA (ijrnf(jc,12),jc=1,jpcoef)/ 413, 414, 18*0 /
+      DATA (zrnfm(jm,12),jm=1,jpmois)/   &
+          335.,     308.,     295.,     407.,    2415.,    2027.,   &
+          1917.,   2049.,    1585.,    1072.,     545.,     389./     
+
+      DATA inb(13)/0/
+      DATA inb(14)/0/
+      DATA inb(15)/0/
+
+      ! Total run-offs(I)=60974.2539m3/s
+
+      ! II SOUTH AMERICA
+      ! -----------------
+      ! 16-Chira (Peru) 4s54 81w08                          R2
+      ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+      ! --> 158.000015m3/s
+      DATA inb(16)/1/
+      DATA (iirnf(jc,16),jc=1,jpcoef)/ 414, 19*0 /
+      DATA (ijrnf(jc,16),jc=1,jpcoef)/ 244, 19*0 /
+      DATA (zrnfm(jm,16),jm=1,jpmois)/   &
+          70.,     105.,     564.,     582.,     230.,      94.,   &
+          87.,      47.,      35.,      32.,      29.,      21./
+      ! 17-Magdalena (Colombia) 11N06 74W51                 R2
+      ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+      ! ratio=1.08
+      ! --> 7451.58301m3/s
+      DATA inb(17)/2/
+      DATA (iirnf(jc,17),jc=1,jpcoef)/ 424, 424, 18*0 /
+      DATA (ijrnf(jc,17),jc=1,jpcoef)/ 270, 271, 18*0 /
+      DATA (zrnfm(jm,17),jm=1,jpmois)/   &
+          6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+          8509.,    7428.,    7631.,    9296.,   10588.,    9949./
+      ! 18-Orinoco (Venezuela) 8N37 62W15!                  R1
+      ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+      ! HLA=26371m3/s
+      ! Data from HLA: 8.1N - 63.3W   1925/89
+      ! --> 26371.416
+      DATA inb(18)/5/
+      DATA (iirnf(jc,18),jc=1,jpcoef)/ 451, 451, 452, 452, 452, 15*0 /
+      DATA (ijrnf(jc,18),jc=1,jpcoef)/ 271, 272, 271, 272, 272, 15*0 /
+      DATA (zrnfm(jm,18),jm=1,jpmois)/   &
+          10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+          43938.,   59957.,   57435.,   39951.,   27410.,   16567./ 
+      ! 19-Amazon (Brazil) 0S05 50W00                       R1
+      ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+      ! HLA=184806m3/s
+      ! UNESCO data are at Obidos which is far inland and therefore does not
+      ! fully represent the actual discharge
+      ! Data from HLA: 1.5N - 55.3W   1970/96
+      ! --> 184845.484m3/s
+      DATA inb(19)/14/
+      DATA (iirnf(jc,19),jc=1,jpcoef)/ 475, 476, 476, 476, 476,  &
+                                       477, 477, 477, 477, 477,  &
+                                       478, 478, 478, 478, 6*0 /
+      DATA (ijrnf(jc,19),jc=1,jpcoef)/ 254, 251, 252, 253, 254,  &
+                                       250, 251, 252, 253, 254,  &
+                                       250, 251, 252, 253, 6*0 /
+      DATA (zrnfm(jm,19),jm=1,jpmois)/   &
+          152233., 176415., 199941., 225565., 244016., 244861.,   &
+          230711., 203128., 164531., 128486., 118214., 130045. /
+      ! 20-Sao Francisco (Brazil) 10S30 36W24               R1
+      ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+      ! --> 2645.3335m3/s
+      DATA inb(20)/1/
+      DATA (iirnf(jc,20),jc=1,jpcoef)/ 498, 19*0 /
+      DATA (ijrnf(jc,20),jc=1,jpcoef)/ 223, 19*0 /
+      DATA (zrnfm(jm,20),jm=1,jpmois)/   &
+          3244.,   4116.,   5139.,   4330.,   2323.,   1800.,     &
+          1587.,   1511.,   1593.,   1740.,   2190.,   2171. /
+      ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18            R1 
+      ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+      ! --> 22203.168m3/s 
+      DATA inb(21)/5/
+      DATA (iirnf(jc,21),jc=1,jpcoef)/ 462, 462, 462, 462, 463, 15*0 /
+      DATA (ijrnf(jc,21),jc=1,jpcoef)/ 172, 173, 174, 175, 175, 15*0 /
+      DATA (zrnfm(jm,21),jm=1,jpmois)/   &
+          24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+          22647.,   20403.,   19627.,   21400.,   21126.,   21923./
+      ! 22-Negro (Argentina)  41S02  62W47                  R2
+      ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+      ! --> 907.666687m3/s
+      DATA inb(22)/2/
+      DATA (iirnf(jc,22),jc=1,jpcoef)/ 446, 447, 18*0 /
+      DATA (ijrnf(jc,22),jc=1,jpcoef)/ 160, 160, 18*0 /
+      DATA (zrnfm(jm,22),jm=1,jpmois)/   &
+          882.,     587.,     519.,     482.,     623.,     984.,   &
+          1120.,   1294.,    1092.,    1166.,    1105.,    1038./
+      ! 23- Tocantins :  ~48W00 ~0.5S                       R4
+      ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+      ! --> 12173.082m3/s
+      DATA inb(23)/4/
+      DATA (iirnf(jc,23),jc=1,jpcoef)/ 479, 480, 481, 482, 16*0 /
+      DATA (ijrnf(jc,23),jc=1,jpcoef)/ 249, 249, 249, 249, 16*0 /
+      DATA (zrnfm(jm,23),jm=1,jpmois)/   &
+          15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+          4440.,   3082.,   2728.,   3417.,   5511.,  10705. /
+
+      DATA inb(24)/0/
+      DATA inb(25)/0/
+
+      ! Total run-offs(II)=256755.75
+      ! Total run-offs(I+II)=317730
+
+      ! III EUROPE
+      ! ----------
+      ! 26-Rhone (France) 43N20 4E50                        R1 
+      ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+      ! --> 1217.16663m3/s
+      DATA inb(26)/1/
+      DATA (iirnf(jc,26),jc=1,jpcoef)/ 584, 19*0 /
+      DATA (ijrnf(jc,26),jc=1,jpcoef)/ 347, 19*0 /
+      DATA (zrnfm(jm,26),jm=1,jpmois)/   &
+          1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+           937.,     796.,     794.,     962.,    1161.,    1233./
+      ! 27-Po (Italy) 11N10 1W09                            R1 
+      ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+      ! --> 1550.08337m3/s
+      DATA inb(27)/1/
+      DATA (iirnf(jc,27),jc=1,jpcoef)/ 599, 19*0 /
+      DATA (ijrnf(jc,27),jc=1,jpcoef)/ 355, 19*0 /
+      DATA (zrnfm(jm,27),jm=1,jpmois)/   &
+          1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+          1040.,    1007.,    1615.,    1907.,    1772.,    1228./
+      ! 28-Danube (Roumania) 45N20 29E40                    R1 
+      ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+      ! --> 7011.8335m3/s
+      DATA inb(28)/2/
+      DATA (iirnf(jc,28),jc=1,jpcoef)/ 632, 632, 18*0 /
+      DATA (ijrnf(jc,28),jc=1,jpcoef)/ 356, 357, 18*0 /
+      DATA (zrnfm(jm,28),jm=1,jpmois)/   &
+          6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+          7586.,    6001.,    5210.,    4989.,    4921.,    6093./
+
+      DATA inb(29)/0/
+      DATA inb(30)/0/
+
+      ! Total run-offs(III)=9779.08301m3/s
+      ! Total run-offs(I+II+III)=327509.094m3/s
+      
+      ! IV EURASIAN ARCTIC
+      ! ------------------
+      ! 31-Iana (Russia)                                    R1
+      ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+      ! --> 0m3/s
+      DATA inb(31)/0/
+      DATA (iirnf(jc,31),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,31),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,31),jm=1,jpmois)/   &
+             2.,       1.,       0.,       0.,     917.,    3514.,   &
+          2968.,    2329.,    1322.,     178.,      36.,       8./ 
+      ! 32-Ob (Russia) 66N45 69E30                          R1 
+      ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+      ! --> 12861.5m3/s
+      DATA inb(32)/8/
+      DATA (iirnf(jc,32),jc=1,jpcoef)/ 635, 635, 636, 636, 636,637, 637,637,12*0 /
+      DATA (ijrnf(jc,32),jc=1,jpcoef)/ 508, 509, 509, 508, 507,509, 508,507,12*0 /
+      DATA (zrnfm(jm,32),jm=1,jpmois)/   &
+           4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+          30773.,   22785.,   14701.,    9705.,    6078.,    5879./
+      ! 33-Yenesei (Russia) 71N50 82E40                     R1 
+      ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+      ! --> 17461.666m3/s
+      DATA inb(33)/9/
+      DATA (iirnf(jc,33),jc=1,jpcoef)/ 114,115,115,116, 117,117,117,118,118,11*0 /
+      DATA (ijrnf(jc,33),jc=1,jpcoef)/ 504,504,503,503, 501,502,503,502,501,11*0 /
+      DATA (zrnfm(jm,33),jm=1,jpmois)/   &
+           6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+          25325.,   15940.,   16050.,   12678.,    6741.,    6008./
+      ! 34-Severnaya Dvina(Russia)64N32 40E30               R5 
+      ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+      ! --> 3359.00024m3/s
+      DATA inb(34)/2/
+      DATA (iirnf(jc,34),jc=1,jpcoef)/ 620, 620, 18*0 /
+      DATA (ijrnf(jc,34),jc=1,jpcoef)/ 448, 449, 18*0 /
+      DATA (zrnfm(jm,34),jm=1,jpmois)/12*3359./
+      ! 35-Lena (Russia) 72N25 126E40                       R1 
+      ! --> 16192.333m3/s
+      DATA inb(35)/9/
+      DATA (iirnf(jc,35),jc=1,jpcoef)/ 142,143,148,148,149,149,150,150,150,11*0 /
+      DATA (ijrnf(jc,35),jc=1,jpcoef)/ 458,458,456,448,449,448,451,450,449,11*0 /
+      DATA (zrnfm(jm,35),jm=1,jpmois)/   &
+           2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+          40810.,   28310.,   25995.,   13299.,    3673.,    3077./
+      ! 36-Kolyma (Russia) 69N30 161E00                     R1
+      ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+      ! --> 2138.66675m3/s
+      DATA inb(36)/2/
+      DATA (iirnf(jc,36),jc=1,jpcoef)/ 184, 185, 18*0 /
+      DATA (ijrnf(jc,36),jc=1,jpcoef)/ 429, 429, 18*0 /
+      DATA (zrnfm(jm,36),jm=1,jpmois)/   &
+           131.,      92.,      76.,      65.,    2576.,    9143.,   &
+          4670.,    3727.,    3226.,    1119.,     630.,     209./
+      ! 37-Indigirka (russia) 70N48 148E54                  R1 
+      ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+      ! --> 1622.00012m3/s
+      DATA inb(37)/1/
+      DATA (iirnf(jc,37),jc=1,jpcoef)/ 172, 19*0 /
+      DATA (ijrnf(jc,37),jc=1,jpcoef)/ 438, 19*0 /
+      DATA (zrnfm(jm,37),jm=1,jpmois)/   &
+            32.,      17.,      11.,       7.,     354.,    5629.,   &
+          5210.,    4617.,    2823.,     559.,     142.,      63./
+
+      DATA inb(38)/0/
+      DATA inb(39)/0/
+      DATA inb(40)/0/
+
+      ! Total run-offs(IV)=40773.6641m3/s
+      ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+      ! V ASIA
+      ! ------
+      ! 41-Amur (Russia) 52N56 141E10                       R2
+      ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+      ! --> 10299.332m3/s
+      DATA inb(41)/2/
+      DATA (iirnf(jc,41),jc=1,jpcoef)/ 141, 141, 18*0 /
+      DATA (ijrnf(jc,41),jc=1,jpcoef)/ 381, 382, 18*0 /
+      DATA (zrnfm(jm,41),jm=1,jpmois)/   &
+           2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+          16100.,   20801.,   21548.,   15658.,    5188.,    2506./
+      ! 42-Liaohe (China) 40N40 122E09                      R5
+      ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+      ! --> 189.999985m3/s
+      DATA inb(42)/1/
+      DATA (iirnf(jc,42),jc=1,jpcoef)/ 100, 19*0 /
+      DATA (ijrnf(jc,42),jc=1,jpcoef)/ 342, 19*0 /
+      DATA (zrnfm(jm,42),jm=1,jpmois)/12*190./
+      ! 43-Daling (China) 40N56 121E43                      R5
+      ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+      ! --> 31.9999962m3/s
+      DATA inb(43)/2/
+      DATA (iirnf(jc,43),jc=1,jpcoef)/  99, 100, 18*0 /
+      DATA (ijrnf(jc,43),jc=1,jpcoef)/ 342, 342, 18*0 /
+      DATA (zrnfm(jm,43),jm=1,jpmois)/12*32./
+      ! 44-Haiho (China) 6N17   1E23
+      ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+      ! --> 63.9999924m3/s
+      DATA inb(44)/1/
+      DATA (iirnf(jc,44),jc=1,jpcoef)/ 121, 19*0 /
+      DATA (ijrnf(jc,44),jc=1,jpcoef)/ 348, 19*0 /
+      DATA (zrnfm(jm,44),jm=1,jpmois)/12*64./
+      ! 45-Yellow/Huangho (China) 37N32 118E19              R2 
+      ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+      ! --> 1552.5m3/s
+      DATA inb(45)/3/
+      DATA (iirnf(jc,45),jc=1,jpcoef)/  92,  92,  92, 17*0 /
+      DATA (ijrnf(jc,45),jc=1,jpcoef)/ 336, 337, 338, 17*0 /
+      DATA (zrnfm(jm,45),jm=1,jpmois)/   &
+           697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+          1964.,    3270.,    3668.,    2133.,     978.,     871./
+      ! 46-Yangtze (China) 31N48 121E10=Changjiang          R2
+      ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+      ! --> 28519.584m3/s
+      DATA inb(46)/2/
+      DATA (iirnf(jc,46),jc=1,jpcoef)/ 100, 100, 18*0 /
+      DATA (ijrnf(jc,46),jc=1,jpcoef)/ 316, 317, 18*0 /
+      DATA (zrnfm(jm,46),jm=1,jpmois)/   &
+          10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+          53891.,   42070.,   37627.,   30762.,   22046.,   12777./
+      ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang      R2 
+      ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+      ! --> 9570.75m3/s
+      DATA inb(47)/2/
+      DATA (iirnf(jc,47),jc=1,jpcoef)/  72,  73, 18*0 /
+      DATA (ijrnf(jc,47),jc=1,jpcoef)/ 294, 294, 18*0 /
+      DATA (zrnfm(jm,47),jm=1,jpmois)/   &
+           2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+          19213.,   17558.,   12312.,    7255.,    5864.,    6154./
+      ! 48-Red/Hungho (Vietnam) 20N17 106E34                R5 
+      ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+      ! --> 3897.m3/s
+      DATA inb(48)/3/
+      DATA (iirnf(jc,48),jc=1,jpcoef)/  68,  68,  68, 17*0 /
+      DATA (ijrnf(jc,48),jc=1,jpcoef)/ 288, 289, 290, 17*0 /
+      DATA (zrnfm(jm,48),jm=1,jpmois)/12*3897./
+      ! 49-Mekong (Vietnam) 10N33 105E24                    R5
+      ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+      ! --> 14893.0029m3/s
+      DATA inb(49)/3/
+      DATA (iirnf(jc,49),jc=1,jpcoef)/  69,  69,  70, 17*0 /
+      DATA (ijrnf(jc,49),jc=1,jpcoef)/ 269, 270, 270, 17*0 /
+      DATA (zrnfm(jm,49),jm=1,jpmois)/12*14893./
+      ! 50-Irrawady (Burma) 15N50  95E06                    R5
+      ! Old=428 km3/year=13563m3/s; not in UNESCO data base
+      ! --> 13563.m3/s
+      DATA inb(50)/2/
+      DATA (iirnf(jc,50),jc=1,jpcoef)/  44,  45, 18*0 /
+      DATA (ijrnf(jc,50),jc=1,jpcoef)/ 283, 282, 18*0 /
+      DATA (zrnfm(jm,50),jm=1,jpmois)/12*13563./
+      ! 51-Ganges+Brahmaputra (Beng.) 22N00  91E00          R1
+      ! Old=971 km3/year=30769m3/s; UNESCO(69-70+73-75, p367)=31760m3/s
+      ! --> 32147.498m3/s
+      DATA inb(51)/4/
+      DATA (iirnf(jc,51),jc=1,jpcoef)/  36,  37,  38,  39, 16*0 /
+      DATA (ijrnf(jc,51),jc=1,jpcoef)/ 295, 295, 295, 295, 16*0 /
+      DATA (zrnfm(jm,51),jm=1,jpmois)/   &
+           6623.,    6315.,    6432.,    9410.,   17263.,   38302.,   &
+          64688.,   80338.,   84802.,   43387.,   17888.,   10322./
+      ! 52-Mehandi (India)                                  R5
+      ! Old=67 km3/year=2123m3/s; not in UNESCO data base
+      ! --> 0m3/s
+      DATA inb(52)/0/
+      DATA (iirnf(jc,52),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,52),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,52),jm=1,jpmois)/12*2123./
+      ! 53-Damodar (India)                                  R2
+      ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+      ! --> 432.916656m3/s
+      DATA inb(53)/1/
+      DATA (iirnf(jc,53),jc=1,jpcoef)/  30, 19*0 /
+      DATA (ijrnf(jc,53),jc=1,jpcoef)/ 294, 19*0 /
+      DATA (zrnfm(jm,53),jm=1,jpmois)/   &
+           51.,      37.,      42.,      49.,      85.,     296.,   &
+          896.,    1390.,    1591.,     542.,     172.,      44./   
+      ! 54-Godavari (India) 17N00  81E45                    R2
+      ! Old=84 km3/year=2662m3/s; UNESCO(p379)=1916m3/s; ratio=1.39
+      ! --> 3670.5m3/s
+      DATA inb(54)/1/
+      DATA (iirnf(jc,54),jc=1,jpcoef)/  19, 19*0 /
+      DATA (ijrnf(jc,54),jc=1,jpcoef)/ 283, 19*0 /
+      DATA (zrnfm(jm,54),jm=1,jpmois)/   &
+           988.,     737.,     280.,     219.,     196.,    1691.,   &
+          8063.,   14571.,   11428.,    3953.,    1221.,     699./   
+      ! 55-Indus (Pakistan) 24N20  67E47             R2
+      ! Old=238 km3/year=7542m3/s; UNESCO (76-79, p428)=2396m3/s; ratio=3.15
+      ! --> 7562.m3/s
+      DATA inb(55)/4/
+      DATA (iirnf(jc,55),jc=1,jpcoef)/ 711, 711, 712, 713, 16*0 /
+      DATA (ijrnf(jc,55),jc=1,jpcoef)/ 297, 298, 297, 297, 16*0 /
+      DATA (zrnfm(jm,55),jm=1,jpmois)/   &
+            988.,     737.,    1904.,    1968.,    3625.,    6143.,   &
+          15969.,    36656.,  17173.,    3215.,    1251.,    1115./   
+      ! 56-Tigris and Euphrates (Iraq) 31N00  47E25         R1
+      ! Old=46 km3/year=1458m3/s; UNESCO(76-79, p428)=2396m3/s
+      ! --> 2248.8335m3/s
+      DATA inb(56)/3/
+      DATA (iirnf(jc,56),jc=1,jpcoef)/ 673, 673, 674, 17*0 /
+      DATA (ijrnf(jc,56),jc=1,jpcoef)/ 312, 313, 313, 17*0 /
+      DATA (zrnfm(jm,56),jm=1,jpmois)/   &
+          1872.,    2127.,    2962.,    4944.,    5036.,    3078.,   &
+          1362.,     900.,     786.,     993.,    1184.,    1742./   
+
+      DATA inb(57)/0/
+      DATA inb(58)/0/
+      DATA inb(59)/0/
+      DATA inb(60)/0/
+
+      ! Total run-offs (V)=128642.922m3/s
+      ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+
+      ! VI AFRICA
+      ! ----------
+      ! 61-Nile (Egypt) 30N10  31E06                        R1
+      ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+      ! --> 1251.33337m3/s
+      DATA inb(61)/3/
+      DATA (iirnf(jc,61),jc=1,jpcoef)/ 636, 636, 637, 17*0 /
+      DATA (ijrnf(jc,61),jc=1,jpcoef)/ 317, 318, 318, 17*0 /
+      DATA (zrnfm(jm,61),jm=1,jpmois)/   &
+          1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+          1742.,    1559.,    1191.,    1103.,    1075.,    1124./   
+      ! 62-Niger (Nigeria) 5N33   6E33                      R1
+      ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+      ! Data from HLA: 4.5N -  6  E   1950/87
+      ! --> 5545.08301m3/s
+      DATA inb(62)/3/
+      DATA (iirnf(jc,62),jc=1,jpcoef)/ 591, 592, 593, 17*0 /
+      DATA (ijrnf(jc,62),jc=1,jpcoef)/ 258, 258, 258, 17*0 /
+      DATA (zrnfm(jm,62),jm=1,jpmois)/   &
+          2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+          5272.,    9629.,   14951.,   16227.,    6842.,    2741./   
+      ! 63-Zaire/Congo (Congo) 6S04  12E24                  R1      
+      ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+      ! =39720m3/s
+      ! Data from HLA: 6S - 12  E   1902/96
+      ! --> 39719.5m3/s
+      DATA inb(63)/4/
+      DATA (iirnf(jc,63),jc=1,jpcoef)/ 599, 599, 600, 600, 16*0 /
+      DATA (ijrnf(jc,63),jc=1,jpcoef)/ 237, 238, 236, 237, 16*0 /
+      DATA (zrnfm(jm,63),jm=1,jpmois)/   &
+          47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+          30966.,   30774.,   35981.,   42825.,   51455.,   55314./  
+      ! 64-Orange (Sth Africa) 28S41 16E28                  R5
+      ! Old=11 km3/year=349m3/s
+      ! --> 349.000031m3/s
+      DATA inb(64)/2/
+      DATA (iirnf(jc,64),jc=1,jpcoef)/ 609, 609, 18*0 /
+      DATA (ijrnf(jc,64),jc=1,jpcoef)/ 188, 189, 18*0 /
+      DATA (zrnfm(jm,64),jm=1,jpmois)/12*349./
+      ! 65-Zambesi (Mozambique) 18S55 36E04                 R5
+      ! Old=223 km3/year=7066m3/s
+      ! --> 7066.00049m3/s
+      DATA inb(65)/3/
+      DATA (iirnf(jc,65),jc=1,jpcoef)/ 646, 646, 646, 17*0 /
+      DATA (ijrnf(jc,65),jc=1,jpcoef)/ 207, 208, 209, 17*0 /
+      DATA (zrnfm(jm,65),jm=1,jpmois)/12*7066./
+      ! 66-Limpopo (mozambique) 25S15 33E30                 R5
+      ! Old=5 km3/year=158m3/s
+      ! --> 158.m3/s
+      DATA inb(66)/2/
+      DATA (iirnf(jc,66),jc=1,jpcoef)/ 642, 642, 18*0 /
+      DATA (ijrnf(jc,66),jc=1,jpcoef)/ 196, 197, 18*0 /
+      DATA (zrnfm(jm,66),jm=1,jpmois)/12*158./
+      ! 67-Rufiji (tanzania) 8S00 39E20                     R5
+      ! Old=9 km3/year=285m3/s
+      ! --> 285.m3/s
+      DATA inb(67)/1/
+      DATA (iirnf(jc,67),jc=1,jpcoef)/ 655, 19*0 /
+      DATA (ijrnf(jc,67),jc=1,jpcoef)/ 235, 19*0 /
+      DATA (zrnfm(jm,67),jm=1,jpmois)/12*285./
+      ! Other rivers from the Gulf of Guinea
+      ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)         R1
+      ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+      ! --> 924.25m3/s
+      DATA inb(68)/1/
+      DATA (iirnf(jc,68),jc=1,jpcoef)/ 599, 19*0 /
+      DATA (ijrnf(jc,68),jc=1,jpcoef)/ 241, 19*0 /
+      DATA (zrnfm(jm,68),jm=1,jpmois)/   &
+          1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+           480.,     378.,     327.,     400.,    1018.,    1281./
+      ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)              R1
+      ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+      ! --> 264.166687m3/s
+      DATA inb(69)/1/
+      DATA (iirnf(jc,69),jc=1,jpcoef)/ 595, 19*0 /
+      DATA (ijrnf(jc,69),jc=1,jpcoef)/ 244, 19*0 /
+      DATA (zrnfm(jm,69),jm=1,jpmois)/   &
+          126.,      99.,     143.,     253.,     316.,     300.,   &
+          156.,      93.,     231.,     557.,     592.,     304./
+      ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)                R1
+      ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+      ! --> 4511.83301m3/s
+      DATA inb(70)/2/
+      DATA (iirnf(jc,70),jc=1,jpcoef)/ 593, 593, 18*0 /
+      DATA (ijrnf(jc,70),jc=1,jpcoef)/ 247, 248, 18*0 /
+      DATA (zrnfm(jm,70),jm=1,jpmois)/   &
+          4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+          2616.,    1961.,    2119.,    4304.,    7870.,    6810./
+      ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)        R1
+      ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+      ! --> 1982.58337m3/s
+      DATA inb(71)/2/
+      DATA (iirnf(jc,71),jc=1,jpcoef)/ 595, 595, 18*0 /
+      DATA (ijrnf(jc,71),jc=1,jpcoef)/ 255, 256, 18*0 /
+      DATA (zrnfm(jm,71),jm=1,jpmois)/   &
+           813.,     578.,     517.,     633.,     909.,    1278.,   &
+          1928.,    2653.,    4361.,    5470.,    3307.,    1344./
+      ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)         R1
+      ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+      ! --> 431.166656m3/s      
+      DATA inb(72)/1/
+      DATA (iirnf(jc,72),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,72),jc=1,jpcoef)/ 257, 19*0 /
+      DATA (zrnfm(jm,72),jm=1,jpmois)/   &
+          232.,     128.,     150.,     266.,     402.,     459.,   &
+          353.,     306.,     604.,     930.,     878.,     466./
+      ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)          R1
+      ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+      ! --> 329.75m3/s
+      DATA inb(73)/1/
+      DATA (iirnf(jc,73),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,73),jc=1,jpcoef)/ 254, 19*0 /
+      DATA (zrnfm(jm,73),jm=1,jpmois)/   &
+          452.,     455.,     492.,     466.,     482.,     251.,   &
+          151.,     108.,      87.,     133.,     395.,     485./
+      ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)           R1
+      ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+      ! --> 306.583374m3/s
+      DATA inb(74)/1/
+      DATA (iirnf(jc,74),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,74),jc=1,jpcoef)/ 258, 19*0 /
+      DATA (zrnfm(jm,74),jm=1,jpmois)/   &
+           88.,      63.,      68.,      95.,     139.,     222.,   &
+          395.,     633.,     825.,     675.,     328.,     148./
+      ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)            R1
+      ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+      ! --> 112.666664m3/s
+      DATA inb(75)/1/
+      DATA (iirnf(jc,75),jc=1,jpcoef)/ 583, 19*0 /
+      DATA (ijrnf(jc,75),jc=1,jpcoef)/ 262, 19*0 /
+      DATA (zrnfm(jm,75),jm=1,jpmois)/   &
+           0.,       0.,       0.,       0.,       1.,      18.,   &
+          96.,     324.,     531.,     319.,      58.,       5./
+      ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27)     R1
+      ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+      ! --> 96.4999924m3/s
+      DATA inb(76)/2/
+      DATA (iirnf(jc,76),jc=1,jpcoef)/ 578, 579, 18*0 /
+      DATA (ijrnf(jc,76),jc=1,jpcoef)/ 262, 262, 18*0 /
+      DATA (zrnfm(jm,76),jm=1,jpmois)/   &
+            2.,       1.,       1.,       4.,       8.,      44.,   &
+          168.,     274.,     386.,     215.,      47.,       8./
+      ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)          R1
+      ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+      ! --> 194.25m3/s
+      DATA inb(77)/1/
+      DATA (iirnf(jc,77),jc=1,jpcoef)/ 569, 19*0 /
+      DATA (ijrnf(jc,77),jc=1,jpcoef)/ 260, 19*0 /
+      DATA (zrnfm(jm,77),jm=1,jpmois)/   &
+           14.,       7.,       9.,      17.,      29.,      90.,   &
+          145.,     349.,     740.,     688.,     198.,      45./
+      ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)      R1
+      ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+      ! --> 449.333344m3/s
+      DATA inb(78)/1/
+      DATA (iirnf(jc,78),jc=1,jpcoef)/ 564, 19*0 /
+      DATA (ijrnf(jc,78),jc=1,jpcoef)/ 260, 19*0 /
+      DATA (zrnfm(jm,78),jm=1,jpmois)/   &
+          144.,     116.,     119.,     143.,     156.,     334.,   &
+          419.,     692.,    1277.,    1190.,     553.,     249./
+      
+      DATA inb(79)/0/
+      DATA inb(80)/0/
+      DATA inb(82)/0/
+      DATA inb(83)/0/
+      DATA inb(84)/0/
+      DATA inb(85)/0/
+      DATA inb(86)/0/
+      DATA inb(87)/0/
+      DATA inb(88)/0/
+      DATA inb(89)/0/
+      DATA inb(90)/0/
+
+      ! Total run-offs (VI)=63977.m3/s
+      ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+
+      ! VII OCEANIA
+      ! ------------
+      ! 91-Murray (Austrlia) 35S34 138E54                   R5
+      ! Old=22 km3/year=697m3/s
+      ! --> 696.999939m3/s
+      DATA inb(91)/3/
+      DATA (iirnf(jc,91),jc=1,jpcoef)/ 129, 130, 130, 17*0 /
+      DATA (ijrnf(jc,91),jc=1,jpcoef)/ 177, 176, 177, 17*0 /
+      DATA (zrnfm(jm,91),jm=1,jpmois)/12*697./
+      ! 92-Haast (N. Zeland) 43S50 169E02                   R5
+      ! Old=6 km3/year=190m3/s
+      ! --> 189.999985m3/s
+      DATA inb(92)/1/
+      DATA (iirnf(jc,92),jc=1,jpcoef)/ 194, 19*0 /
+      DATA (ijrnf(jc,92),jc=1,jpcoef)/ 153, 19*0 /
+      DATA (zrnfm(jm,92),jm=1,jpmois)/12*190./
+      ! 93-Fly (N. Guinea) 8S30 143E05                      R5
+      ! Old=77 km3/year=2440m3/s
+      ! --> 2440.m3/s
+      DATA inb(93)/1/
+      DATA (iirnf(jc,93),jc=1,jpcoef)/ 143, 19*0 /
+      DATA (ijrnf(jc,93),jc=1,jpcoef)/ 233, 19*0 /
+      DATA (zrnfm(jm,93),jm=1,jpmois)/12*2440./
+      ! 94-Purari (N. Guinea) 7S25 145E05                   R4
+      ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+      ! --> 2727.33325m3/s
+      DATA inb(94)/1/
+      DATA (iirnf(jc,94),jc=1,jpcoef)/ 146, 19*0 /
+      DATA (ijrnf(jc,94),jc=1,jpcoef)/ 234, 19*0 /
+      DATA (zrnfm(jm,94),jm=1,jpmois)/   &
+          1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+          2867.,    3477.,    2195.,    2967.,    2674.,    2627./
+      ! 95-Choshui ch''i (taiwan) 24N03 120E23              R2
+      ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+      ! --> 0.m3/s
+      DATA inb(95)/0/
+      DATA (iirnf(jc,95),jc=1,jpcoef)/  20*0 /
+      DATA (ijrnf(jc,95),jc=1,jpcoef)/  20*0 /
+      DATA (zrnfm(jm,95),jm=1,jpmois)/   &
+           65.,      63.,      83.,     100.,     177.,     535.,   &
+          332.,     313.,     236.,     193.,     101.,      84./
+      ! 96-Kaoping (Taiwan)                                 R5  
+      ! Old=9 km3/year=285m3/s
+      ! --> 0.m3/s
+      DATA inb(96)/0/
+      DATA (iirnf(jc,96),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,96),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,96),jm=1,jpmois)/12*285./
+      ! 97-Tsengwen (Taiwan)                                R5
+      ! Old=2 km3/year=63m3/s
+      ! --> 0.m3/s
+      DATA inb(97)/0/
+      DATA (iirnf(jc,97),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,97),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,97),jm=1,jpmois)/12*63./
+      ! 98-Hualien (Taiwan)                                 R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(98)/0/
+      DATA (iirnf(jc,98),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,98),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,98),jm=1,jpmois)/12*127./
+      ! 99-Peinan (Taiwan) 22N46 121E10                     R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 127.000008m3/s
+      DATA inb(99)/1/
+      DATA (iirnf(jc,99),jc=1,jpcoef)/  98, 19*0 /
+      DATA (ijrnf(jc,99),jc=1,jpcoef)/ 287, 19*0 /
+      DATA (zrnfm(jm,99),jm=1,jpmois)/12*127./
+      ! 100-Hsiukuluan (Taiwan)                             R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(100)/0/
+      DATA (iirnf(jc,100),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,100),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,100),jm=1,jpmois)/12*127./
+
+      DATA inb(101)/0/
+      DATA inb(102)/0/
+
+      !  Total run-offs(VII)=6181.33301m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+      !                                      = 1.588668056E-6 kg/m2/s
+      !                                      = 17883.5586 km3/Year
+      !                                      = 0.567083955 Sverdrup
+
+      DATA (inb(jr),jr=103,jpriv)/18*0/
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca05'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+         
+         i15 = nday / 16
+         
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         END IF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                     DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                           &          + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                           &          +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! ji,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr)    ), mi1(iirnf(jl,jr)    )
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr)    ), mi1(iirnf(jl,jr)    )
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     DO jj = mj0(ijrnf(jl,jr)    ), mj1(ijrnf(jl,jr)    )
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     DO jj = mj0(ijrnf(jl,jr)    ), mj1(ijrnf(jl,jr)    )
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = zrup1
+            upsrnfz(2)   = zrup1
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+         ENDIF
+      ENDIF
+    
+#endif
+
+   END SUBROUTINE flx_rnf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R2.h90	(revision 4536)
@@ -0,0 +1,1316 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flxrnf_ORCA_R2.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                  OLD ORCA R2 runoff specification
+   !!                      kept here for memory
+   !!                         ( 20/04/2000 )
+   !!----------------------------------------------------------------------
+
+      !!-------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER :: kt
+      INTEGER, PARAMETER ::   &
+         jpmois =  12,        &  ! number of months
+         jpriv  = 120,        &  ! maximum number of river
+         jpcoef = 300            ! maximum of river mouth grid-points
+      INTEGER ::   &
+         ji, jj, jl, jm,      &  ! dummy loop indices
+         jn, jr, jc              !    "         "
+      INTEGER ::   &
+         i15, imois, iman,    &  ! temporary integers
+         inbp, idbd, idmeom,  &  !    "          "
+         iipt0, iipt1, ijpt0, &  !    "          "
+         ijpt1, ii, ij           !    "          "
+      INTEGER, DIMENSION(jpriv) ::   &
+         inb                     ! ???
+      INTEGER, DIMENSION(jpcoef,jpriv) ::   &
+         iirnf, ijrnf            ! ???
+
+      REAL(wp) ::   &
+         zconv, zxy,          &  ! temporary scalars
+         zrup1, zrup2, zrup3     !    "         "
+      REAL(wp), DIMENSION(jpmois,jpriv) ::   &
+         zrnfm                   ! ???
+      REAL(wp), DIMENSION(jpi, jpj, 5) ::   &
+         zcoefr                  ! ???
+  
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+      ! ====
+      ! DATA
+      ! ====
+
+      ! I NORTH AMERICA
+      ! ---------------
+
+      ! 1-Saint Lawrence (Canada) 49N30 67W00               R2
+      ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+      ! --> 13975.249m3/s
+      DATA inb(1)/2/
+      DATA (iirnf(jc,1),jc=1,jpcoef)/ 110, 110, 298*0 /
+      DATA (ijrnf(jc,1),jc=1,jpcoef)/ 110, 111, 298*0 /
+      DATA (zrnfm(jm,1),jm=1,jpmois)/   &
+          11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+          14211.,  13119.,  13367.,  13644.,  13463.,  12594./
+      ! 2-Hudson River (USA) 41N00 77W00                    R1
+      ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+      ! --> 407.416687m3/s
+      DATA inb(2)/1/
+      DATA (iirnf(jc,2),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (ijrnf(jc,2),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,2),jm=1,jpmois)/   &
+          364.,    404.,    648.,    873.,    593.,    301.,   &
+          205.,    171.,    205.,    290.,    379.,    456./
+      ! 3-Missisipi and Atchafalaya (USA) 29N 90W           R1 
+      ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+      ! --> 17599.334m3/s
+      DATA inb(3)/2/
+      DATA (iirnf(jc,3),jc=1,jpcoef)/  97, 98, 298*0 /
+      DATA (ijrnf(jc,3),jc=1,jpcoef)/  97, 97, 298*0 /
+      DATA (zrnfm(jm,3),jm=1,jpmois)/   &
+          19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+          14181.,  10676.,   9578.,  10167.,  11699.,  17472./
+      ! 4-Brazos (USA) 29N58 95W53                          R1
+      ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+      ! --> 199.666656m3/s
+      DATA inb(4)/1/
+      DATA (iirnf(jc,4),jc=1,jpcoef)/  95, 299*0 /
+      DATA (ijrnf(jc,4),jc=1,jpcoef)/  97, 299*0 /
+      DATA (zrnfm(jm,4),jm=1,jpmois)/   &
+          165.,    224.,    200.,    266.,    457.,    327.,   &
+          143.,     69.,    102.,    132.,    160.,    151./
+      ! 5-Colorado (Mexico) 31N54 114W57                    R5
+      ! Old=20 km3/year=634m3/s
+      ! --> 634.m3/s
+      DATA inb(5)/1/
+      DATA (iirnf(jc,5),jc=1,jpcoef)/  88, 299*0 /
+      DATA (ijrnf(jc,5),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,5),jm=1,jpmois)/12*634./ 
+      ! 6-Columbia (USA) 45N60 121W17                       R1
+      ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+      ! --> 5368.41602m3/s
+      DATA inb(6)/1/
+      DATA (iirnf(jc,6),jc=1,jpcoef)/  79, 299*0 /
+      DATA (ijrnf(jc,6),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (zrnfm(jm,6),jm=1,jpmois)/   &
+          4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+          6350.,    4112.,    3273.,    3251.,    3548.,    4106./ 
+      ! 7-Fraser (USA)                                      R5
+      ! Old=112 km3/year=3550m3/s;not found in UNESCO
+      ! --> 3549.99976m3/s
+      DATA inb(7)/1/
+      DATA (iirnf(jc,7),jc=1,jpcoef)/  77, 299*0 /
+      DATA (ijrnf(jc,7),jc=1,jpcoef)/ 112, 299*0 /
+      DATA (zrnfm(jm,7),jm=1,jpmois)/12*3550./ 
+      ! 8-Yukon (USA) 63N00 165W00                          R3
+      ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+      ! --> 6017.24951m3/s
+      DATA inb(8)/1/
+      DATA (iirnf(jc,8),jc=1,jpcoef)/  58, 299*0 /
+      DATA (ijrnf(jc,8),jc=1,jpcoef)/ 122, 299*0 /
+      DATA (zrnfm(jm,8),jm=1,jpmois)/   &
+           1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+          10680.,   11271.,    8658.,    5453.,    2649.,    1917./ 
+     ! 9-Copper (USA) 61N47 144W45                          R2
+     ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+     ! --> 1236.25m3/s
+      DATA inb(9)/1/
+      DATA (iirnf(jc,9),jc=1,jpcoef)/  67, 299*0 /
+      DATA (ijrnf(jc,9),jc=1,jpcoef)/ 119, 299*0 /
+      DATA (zrnfm(jm,9),jm=1,jpmois)/   &
+           219.,    195.,    181.,    214.,    904.,   2532.,   &
+          4026.,   3627.,   1632.,    697.,    354.,    254./ 
+      ! 10-Susitna (USA)                                    R5
+      ! Old=40 km3/year=1268m3/s
+      ! --> 1268.m3/s
+      DATA inb(10)/1/
+      DATA (iirnf(jc,10),jc=1,jpcoef)/  65, 299*0 /
+      DATA (ijrnf(jc,10),jc=1,jpcoef)/ 118, 299*0 /
+      DATA (zrnfm(jm,10),jm=1,jpmois)/12*1268./ 
+      ! 11-McKenzie (Canada) 70N00 135W00                   R3
+      ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+      ! ratio=1.16
+      ! --> 9606.66797m3/s
+      DATA inb(11)/1/
+      DATA (iirnf(jc,11),jc=1,jpcoef)/  69, 299*0 /
+      DATA (ijrnf(jc,11),jc=1,jpcoef)/ 131, 299*0 /
+      DATA (zrnfm(jm,11),jm=1,jpmois)/   &
+           3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+          18954.,   15487.,   11284.,   10169.,    5901.,    3905./
+      ! 12-Kuksokwim (USA) 60N00 ~162W30                    R4
+      ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+      ! --> 1111.99988m3/s
+      DATA inb(12)/1/
+      DATA (iirnf(jc,12),jc=1,jpcoef)/  60, 299*0 /
+      DATA (ijrnf(jc,12),jc=1,jpcoef)/ 118, 299*0 /
+      DATA (zrnfm(jm,12),jm=1,jpmois)/   &
+          335.,     308.,     295.,     407.,    2415.,    2027.,   &
+          1917.,   2049.,    1585.,    1072.,     545.,     389./     
+
+      DATA inb(13)/0/
+      DATA inb(14)/0/
+      DATA inb(15)/0/
+
+      ! Total run-offs(I)=60974.2539m3/s
+
+      ! II SOUTH AMERICA
+      ! -----------------
+      ! 16-Chira (Peru) 4s54 81w08                          R2
+      ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+      ! --> 158.000015m3/s
+      DATA inb(16)/1/
+      DATA (iirnf(jc,16),jc=1,jpcoef)/ 101, 299*0 /
+      DATA (ijrnf(jc,16),jc=1,jpcoef)/  66, 299*0 /
+      DATA (zrnfm(jm,16),jm=1,jpmois)/   &
+          70.,     105.,     564.,     582.,     230.,      94.,   &
+          87.,      47.,      35.,      32.,      29.,      21./
+      ! 17-Magdalena (Colombia) 11N06 74W51                 R2
+      ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+      ! ratio=1.08
+      ! --> 7451.58301m3/s
+      DATA inb(17)/1/
+      DATA (iirnf(jc,17),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (ijrnf(jc,17),jc=1,jpcoef)/  86, 299*0 /
+      DATA (zrnfm(jm,17),jm=1,jpmois)/   &
+          6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+          8509.,    7428.,    7631.,    9296.,   10588.,    9949./
+      ! 18-Orinoco (Venezuela) 8N37 62W15!                  R1
+      ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+      ! HLA=26371m3/s
+      ! Data from HLA: 8.1N - 63.3W   1925/89
+      ! --> 26371.416
+      DATA inb(18)/1/
+      DATA (iirnf(jc,18),jc=1,jpcoef)/ 112, 299*0 /
+      DATA (ijrnf(jc,18),jc=1,jpcoef)/  86, 299*0 /
+      DATA (zrnfm(jm,18),jm=1,jpmois)/   &
+          10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+          43938.,   59957.,   57435.,   39951.,   27410.,   16567./ 
+      ! 19-Amazon (Brazil) 0S05 50W00                       R1
+      ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+      ! HLA=184806m3/s
+      ! UNESCO data are at Obidos which is far inland and therefore does not
+      ! fully represent the actual discharge
+      ! Data from HLA: 1.5N - 55.3W   1970/96
+      ! --> 184845.484m3/s
+      DATA inb(19)/2/
+      DATA (iirnf(jc,19),jc=1,jpcoef)/ 117, 117, 298*0 /
+      DATA (ijrnf(jc,19),jc=1,jpcoef)/  75,  76, 298*0 /
+      DATA (zrnfm(jm,19),jm=1,jpmois)/   &
+          152233., 176415., 199941., 225565., 244016., 244861.,   &
+          230711., 203128., 164531., 128486., 118214., 130045. /
+      ! 20-Sao Francisco (Brazil) 10S30 36W24               R1
+      ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+      ! --> 2645.3335m3/s
+      DATA inb(20)/1/
+      DATA (iirnf(jc,20),jc=1,jpcoef)/ 123, 299*0 /
+      DATA (ijrnf(jc,20),jc=1,jpcoef)/  59, 299*0 /
+      DATA (zrnfm(jm,20),jm=1,jpmois)/   &
+          3244.,   4116.,   5139.,   4330.,   2323.,   1800.,   &
+          1587.,   1511.,   1593.,   1740.,   2190.,   2171. /
+      ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18            R1 
+      ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+      ! --> 22203.168m3/s 
+      DATA inb(21)/2/
+      DATA (iirnf(jc,21),jc=1,jpcoef)/ 114, 114, 298*0 /
+      DATA (ijrnf(jc,21),jc=1,jpcoef)/  46,  47, 298*0 /
+      DATA (zrnfm(jm,21),jm=1,jpmois)/   &
+          24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+          22647.,   20403.,   19627.,   21400.,   21126.,   21923./
+      ! 22-Negro (Argentina)  41S02  62W47                  R2
+      ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+      ! --> 907.666687m3/s
+      DATA inb(22)/1/
+      DATA (iirnf(jc,22),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (ijrnf(jc,22),jc=1,jpcoef)/  43, 299*0 /
+      DATA (zrnfm(jm,22),jm=1,jpmois)/   &
+          882.,     587.,     519.,     482.,     623.,     984.,   &
+          1120.,   1294.,    1092.,    1166.,    1105.,    1038./
+     ! 23- Tocantins :  ~48W00 ~0.5S                        R4
+     ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+     ! --> 12173.082m3/s
+      DATA inb(23)/1/
+      DATA (iirnf(jc,23),jc=1,jpcoef)/118, 299*0 /
+      DATA (ijrnf(jc,23),jc=1,jpcoef)/ 73, 299*0 /
+      DATA (zrnfm(jm,23),jm=1,jpmois)/   &
+          15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+          4440.,   3082.,   2728.,   3417.,   5511.,  10705. /
+
+      DATA inb(24)/0/
+      DATA inb(25)/0/
+
+      ! Total run-offs(II)=256755.75
+      ! Total run-offs(I+II)=317730
+
+      ! III EUROPE
+      ! ----------
+      ! 26-Rhone (France) 43N20 4E50                        R1 
+      ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+      ! --> 1217.16663m3/s
+      DATA inb(26)/1/
+      DATA (iirnf(jc,26),jc=1,jpcoef)/ 150, 299*0 /
+      DATA (ijrnf(jc,26),jc=1,jpcoef)/ 108, 299*0 /
+      DATA (zrnfm(jm,26),jm=1,jpmois)/   &
+          1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+           937.,     796.,     794.,     962.,    1161.,    1233./
+      ! 27-Po (Italy) 11N10 1W09                            R1 
+      ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+      ! --> 1550.08337m3/s
+      DATA inb(27)/1/
+      DATA (iirnf(jc,27),jc=1,jpcoef)/ 159, 299*0 /
+      DATA (ijrnf(jc,27),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (zrnfm(jm,27),jm=1,jpmois)/   &
+          1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+          1040.,    1007.,    1615.,    1907.,    1772.,    1228./
+      ! 28-Danube (Roumania) 45N20 29E40                    R1 
+      ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+      ! --> 7011.8335m3/s
+      DATA inb(28)/1/
+      DATA (iirnf(jc,28),jc=1,jpcoef)/ 171, 299*0 /
+      DATA (ijrnf(jc,28),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (zrnfm(jm,28),jm=1,jpmois)/   &
+          6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+          7586.,    6001.,    5210.,    4989.,    4921.,    6093./
+
+      DATA inb(29)/0/
+      DATA inb(30)/0/
+
+      ! Total run-offs(III)=9779.08301m3/s
+      ! Total run-offs(I+II+III)=327509.094m3/s
+
+      ! IV EURASIAN ARCTIC
+      ! ------------------
+      ! 31-Iana (Russia)                                    R1
+      ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+      ! --> 0m3/s
+      DATA inb(31)/0/
+      DATA (iirnf(jc,31),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,31),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,31),jm=1,jpmois)/   &
+             2.,       1.,       0.,       0.,     917.,    3514.,   &
+          2968.,    2329.,    1322.,     178.,      36.,       8./ 
+      ! 32-Ob (Russia) 66N45 69E30                          R1 
+      ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+      ! --> 12861.5m3/s
+      DATA inb(32)/2/
+      DATA (iirnf(jc,32),jc=1,jpcoef)/ 153, 153, 298*0 /
+      DATA (ijrnf(jc,32),jc=1,jpcoef)/ 146, 147, 298*0 /
+      DATA (zrnfm(jm,32),jm=1,jpmois)/   &
+           4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+          30773.,   22785.,   14701.,    9705.,    6078.,    5879./
+      ! 33-Yenesei (Russia) 71N50 82E40                     R1 
+      ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+      ! --> 17461.666m3/s
+      DATA inb(33)/1/
+      DATA (iirnf(jc,33),jc=1,jpcoef)/  32, 299*0 /
+      DATA (ijrnf(jc,33),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (zrnfm(jm,33),jm=1,jpmois)/   &
+           6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+          25325.,   15940.,   16050.,   12678.,    6741.,    6008./
+     ! 34-Severnaya Dvina(Russia)64N32 40E30                R5 
+     ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+     ! --> 3359.00024m3/s
+      DATA inb(34)/1/
+      DATA (iirnf(jc,34),jc=1,jpcoef)/ 153, 299*0 /
+      DATA (ijrnf(jc,34),jc=1,jpcoef)/ 133, 299*0 /
+      DATA (zrnfm(jm,34),jm=1,jpmois)/12*3359./
+      ! 35-Lena (Russia) 72N25 126E40                       R1 
+      ! --> 16192.333m3/s
+      DATA inb(35)/1/
+      DATA (iirnf(jc,35),jc=1,jpcoef)/  36, 299*0 /
+      DATA (ijrnf(jc,35),jc=1,jpcoef)/ 137, 299*0 /
+      DATA (zrnfm(jm,35),jm=1,jpmois)/   &
+           2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+          40810.,   28310.,   25995.,   13299.,    3673.,    3077./
+      ! 36-Kolyma (Russia) 69N30 161E00                     R1
+      ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+      ! --> 2138.66675m3/s
+      DATA inb(36)/1/
+      DATA (iirnf(jc,36),jc=1,jpcoef)/  46, 299*0 /
+      DATA (ijrnf(jc,36),jc=1,jpcoef)/ 128, 299*0 /
+      DATA (zrnfm(jm,36),jm=1,jpmois)/   &
+           131.,      92.,      76.,      65.,    2576.,    9143.,   &
+          4670.,    3727.,    3226.,    1119.,     630.,     209./
+     ! 37-Indigirka (russia) 70N48 148E54                   R1 
+     ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+     ! --> 1622.00012m3/s
+      DATA inb(37)/1/
+      DATA (iirnf(jc,37),jc=1,jpcoef)/  42, 299*0 /
+      DATA (ijrnf(jc,37),jc=1,jpcoef)/ 131, 299*0 /
+      DATA (zrnfm(jm,37),jm=1,jpmois)/   &
+            32.,      17.,      11.,       7.,     354.,    5629.,   &
+          5210.,    4617.,    2823.,     559.,     142.,      63./
+
+      DATA inb(38)/0/
+      DATA inb(39)/0/
+      DATA inb(40)/0/
+
+      ! Total run-offs(IV)=40773.6641m3/s
+      ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+      ! V ASIA
+      ! ------
+      ! 41-Amur (Russia) 52N56 141E10                       R2
+      ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+      ! --> 10299.332m3/s
+      DATA inb(41)/1/
+      DATA (iirnf(jc,41),jc=1,jpcoef)/  33, 299*0 /
+      DATA (ijrnf(jc,41),jc=1,jpcoef)/ 116, 299*0 /
+      DATA (zrnfm(jm,41),jm=1,jpmois)/   &
+           2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+          16100.,   20801.,   21548.,   15658.,    5188.,    2506./
+      ! 42-Liaohe (China) 40N40 122E09                      R5
+      ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+      ! --> 189.999985m3/s
+      DATA inb(42)/1/
+      DATA (iirnf(jc,42),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,42),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,42),jm=1,jpmois)/12*190./
+      ! 43-Daling (China) 40N56 121E43                      R5
+      ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+      ! --> 31.9999962m3/s
+      DATA inb(43)/1/
+      DATA (iirnf(jc,43),jc=1,jpcoef)/  24, 299*0 /
+      DATA (ijrnf(jc,43),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,43),jm=1,jpmois)/12*32./
+      ! 44-Haiho (China) 6N17   1E23
+      ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+      ! --> 63.9999924m3/s
+      DATA inb(44)/1/
+      DATA (iirnf(jc,44),jc=1,jpcoef)/  28, 299*0 /
+      DATA (ijrnf(jc,44),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (zrnfm(jm,44),jm=1,jpmois)/12*64./
+      ! 45-Yellow/Huangho (China) 37N32 118E19              R2 
+      ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+      ! --> 1552.5m3/s
+      DATA inb(45)/1/
+      DATA (iirnf(jc,45),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,45),jc=1,jpcoef)/ 103, 299*0 /
+      DATA (zrnfm(jm,45),jm=1,jpmois)/   &
+           697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+          1964.,    3270.,    3668.,    2133.,     978.,     871./
+      ! 46-Yangtze (China) 31N48 121E10=Changjiang          R2
+      ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+      ! --> 28519.584m3/s
+      DATA inb(46)/1/
+      DATA (iirnf(jc,46),jc=1,jpcoef)/  23, 299*0 /
+      DATA (ijrnf(jc,46),jc=1,jpcoef)/  98, 299*0 /
+      DATA (zrnfm(jm,46),jm=1,jpmois)/   &
+          10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+          53891.,   42070.,   37627.,   30762.,   22046.,   12777./
+      ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang      R2 
+      ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+      ! --> 9570.75m3/s
+      DATA inb(47)/1/
+      DATA (iirnf(jc,47),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,47),jc=1,jpcoef)/  95, 299*0 /
+      DATA (zrnfm(jm,47),jm=1,jpmois)/   &
+           2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+          19213.,   17558.,   12312.,    7255.,    5864.,    6154./
+      ! 48-Red/Hungho (Vietnam) 20N17 106E34                R5 
+      ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+      ! --> 3897.m3/s
+      DATA inb(48)/1/
+      DATA (iirnf(jc,48),jc=1,jpcoef)/  16, 299*0 /
+      DATA (ijrnf(jc,48),jc=1,jpcoef)/  91, 299*0 /
+      DATA (zrnfm(jm,48),jm=1,jpmois)/12*3897./
+      ! 49-Mekong (Vietnam) 10N33 105E24                    R5
+      ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+      ! --> 14893.0029m3/s
+      DATA inb(49)/2/
+      DATA (iirnf(jc,49),jc=1,jpcoef)/  16,  16, 298*0 /
+      DATA (ijrnf(jc,49),jc=1,jpcoef)/  86,  87, 298*0 /
+      DATA (zrnfm(jm,49),jm=1,jpmois)/12*14893./
+      ! 50-Irrawady (Burma) 15N50  95E06                    R5
+      ! Old=428 km3/year=13563m3/s; not in UNESCO data base
+      ! --> 13563.m3/s
+      DATA inb(50)/1/
+      DATA (iirnf(jc,50),jc=1,jpcoef)/  10, 299*0 /
+      DATA (ijrnf(jc,50),jc=1,jpcoef)/  90, 299*0 /
+      DATA (zrnfm(jm,50),jm=1,jpmois)/12*13563./
+      ! 51-Ganges+Brahmaputra (Beng.) 22N00  91E00          R1
+      ! Old=971 km3/year=30769m3/s; UNESCO(69-70+73-75, p367)=31760m3/s
+      ! --> 32147.498m3/s
+      DATA inb(51)/2/
+      DATA (iirnf(jc,51),jc=1,jpcoef)/   7,  8, 298*0 /
+      DATA (ijrnf(jc,51),jc=1,jpcoef)/  93, 93, 298*0 /
+      DATA (zrnfm(jm,51),jm=1,jpmois)/   &
+           6623.,    6315.,    6432.,    9410.,   17263.,   38302.,   &
+          64688.,   80338.,   84802.,   43387.,   17888.,   10322./
+      ! 52-Mehandi (India)                                  R5
+      ! Old=67 km3/year=2123m3/s; not in UNESCO data base
+      ! --> 0m3/s
+      DATA inb(52)/0/
+      DATA (iirnf(jc,52),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,52),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,52),jm=1,jpmois)/12*2123./
+      ! 53-Damodar (India)                                  R2
+      ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+      ! --> 432.916656m3/s
+      DATA inb(53)/1/
+      DATA (iirnf(jc,53),jc=1,jpcoef)/   6, 299*0 /
+      DATA (ijrnf(jc,53),jc=1,jpcoef)/  93, 299*0 /
+      DATA (zrnfm(jm,53),jm=1,jpmois)/   &
+           51.,      37.,      42.,      49.,      85.,     296.,   &
+          896.,    1390.,    1591.,     542.,     172.,      44./   
+      ! 54-Godavari (India) 17N00  81E45                    R2
+      ! Old=84 km3/year=2662m3/s; UNESCO(p379)=1916m3/s; ratio=1.39
+      ! --> 3670.5m3/s
+      DATA inb(54)/1/
+      DATA (iirnf(jc,54),jc=1,jpcoef)/   3, 299*0 /
+      DATA (ijrnf(jc,54),jc=1,jpcoef)/  90, 299*0 /
+      DATA (zrnfm(jm,54),jm=1,jpmois)/   &
+           988.,     737.,     280.,     219.,     196.,    1691.,   &
+          8063.,   14571.,   11428.,    3953.,    1221.,     699./   
+     ! 55-Indus (Pakistan) 24N20  67E47                     R2
+     ! Old=238 km3/year=7542m3/s; UNESCO (76-79, p428)=2396m3/s; ratio=3.15
+     ! --> 7562.m3/s
+      DATA inb(55)/2/
+      DATA (iirnf(jc,55),jc=1,jpcoef)/ 176, 176, 298*0 /
+      DATA (ijrnf(jc,55),jc=1,jpcoef)/  93,  94, 298*0 /
+      DATA (zrnfm(jm,55),jm=1,jpmois)/   &
+            988.,     737.,    1904.,    1968.,    3625.,    6143.,   &
+          15969.,    36656.,  17173.,    3215.,    1251.,    1115./   
+      ! 56-Tigris and Euphrates (Iraq) 31N00  47E25         R1
+      ! Old=46 km3/year=1458m3/s; UNESCO(76-79, p428)=2396m3/s
+      ! --> 2248.8335m3/s
+      DATA inb(56)/1/
+      DATA (iirnf(jc,56),jc=1,jpcoef)/ 172, 299*0 /
+      DATA (ijrnf(jc,56),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,56),jm=1,jpmois)/   &
+          1872.,    2127.,    2962.,    4944.,    5036.,    3078.,   &
+          1362.,     900.,     786.,     993.,    1184.,    1742./   
+
+      DATA inb(57)/0/
+      DATA inb(58)/0/
+      DATA inb(59)/0/
+      DATA inb(60)/0/
+
+      ! Total run-offs (V)=128642.922m3/s
+      ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+      
+      ! VI AFRICA
+      ! ----------
+      ! 61-Nile (Egypt) 30N10  31E06                        R1
+      ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+      ! --> 1251.33337m3/s
+      DATA inb(61)/1/
+      DATA (iirnf(jc,61),jc=1,jpcoef)/ 176, 299*0 /
+      DATA (ijrnf(jc,61),jc=1,jpcoef)/  97, 299*0 /
+      DATA (zrnfm(jm,61),jm=1,jpmois)/   &
+          1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+          1742.,    1559.,    1191.,    1103.,    1075.,    1124./   
+      ! 62-Niger (Nigeria) 5N33   6E33                      R1
+      ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+      ! Data from HLA: 4.5N -  6  E   1950/87
+      ! --> 5545.08301m3/s
+      DATA inb(62)/1/
+      DATA (iirnf(jc,62),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,62),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,62),jm=1,jpmois)/   &
+          2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+          5272.,    9629.,   14951.,   16227.,    6842.,    2741./   
+      ! 63-Zaire/Congo (Congo) 6S04  12E24                  R1      
+      ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+      ! =39720m3/s
+      ! Data from HLA: 6S - 12  E   1902/96
+      ! --> 39719.5m3/s
+      DATA inb(63)/2/
+      DATA (iirnf(jc,63),jc=1,jpcoef)/ 148, 148, 298*0 /
+      DATA (ijrnf(jc,63),jc=1,jpcoef)/  63,  64, 298*0 /
+      DATA (zrnfm(jm,63),jm=1,jpmois)/   &
+          47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+          30966.,   30774.,   35981.,   42825.,   51455.,   55314./  
+      ! 64-Orange (Sth Africa) 28S41 16E28                  R5
+      ! Old=11 km3/year=349m3/s
+      ! --> 349.000031m3/s
+      DATA inb(64)/1/
+      DATA (iirnf(jc,64),jc=1,jpcoef)/ 150, 299*0 /
+      DATA (ijrnf(jc,64),jc=1,jpcoef)/  51, 299*0 /
+      DATA (zrnfm(jm,64),jm=1,jpmois)/12*349./
+      ! 65-Zambesi (Mozambique) 18S55 36E04                 R5
+      ! Old=223 km3/year=7066m3/s
+      ! --> 7066.00049m3/s
+      DATA inb(65)/1/
+      DATA (iirnf(jc,65),jc=1,jpcoef)/ 160, 299*0 /
+      DATA (ijrnf(jc,65),jc=1,jpcoef)/  56, 299*0 /
+      DATA (zrnfm(jm,65),jm=1,jpmois)/12*7066./
+      ! 66-Limpopo (mozambique) 25S15 33E30                 R5
+      ! Old=5 km3/year=158m3/s
+      ! --> 158.m3/s
+      DATA inb(66)/1/
+      DATA (iirnf(jc,66),jc=1,jpcoef)/ 159, 299*0 /
+      DATA (ijrnf(jc,66),jc=1,jpcoef)/  52, 299*0 /
+      DATA (zrnfm(jm,66),jm=1,jpmois)/12*158./
+      ! 67-Rufiji (tanzania) 8S00 39E20                     R5
+      ! Old=9 km3/year=285m3/s
+      ! --> 285.m3/s
+      DATA inb(67)/1/
+      DATA (iirnf(jc,67),jc=1,jpcoef)/ 162, 299*0 /
+      DATA (ijrnf(jc,67),jc=1,jpcoef)/  62, 299*0 /
+      DATA (zrnfm(jm,67),jm=1,jpmois)/12*285./
+      ! Other rivers from the Gulf of Guinea
+      ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)         R1
+      ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+      ! --> 924.25m3/s
+      DATA inb(68)/1/
+      DATA (iirnf(jc,68),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (ijrnf(jc,68),jc=1,jpcoef)/  67, 299*0 /
+      DATA (zrnfm(jm,68),jm=1,jpmois)/   &
+          1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+           480.,     378.,     327.,     400.,    1018.,    1281./
+      ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)              R1
+      ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+      ! --> 264.166687m3/s
+      DATA inb(69)/1/
+      DATA (iirnf(jc,69),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (ijrnf(jc,69),jc=1,jpcoef)/  68, 299*0 /
+      DATA (zrnfm(jm,69),jm=1,jpmois)/   &
+          126.,      99.,     143.,     253.,     316.,     300.,   &
+          156.,      93.,     231.,     557.,     592.,     304./
+      ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)                R1
+      ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+      ! --> 4511.83301m3/s
+      DATA inb(70)/1/
+      DATA (iirnf(jc,70),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,70),jc=1,jpcoef)/  72, 299*0 /
+      DATA (zrnfm(jm,70),jm=1,jpmois)/   &
+          4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+          2616.,    1961.,    2119.,    4304.,    7870.,    6810./
+      ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)        R1
+      ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+      ! --> 1982.58337m3/s
+      DATA inb(71)/1/
+      DATA (iirnf(jc,71),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,71),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,71),jm=1,jpmois)/   &
+           813.,     578.,     517.,     633.,     909.,    1278.,   &
+          1928.,    2653.,    4361.,    5470.,    3307.,    1344./
+      ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)         R1
+      ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+      ! --> 431.166656m3/s      
+      DATA inb(72)/1/
+      DATA (iirnf(jc,72),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,72),jc=1,jpcoef)/  80, 299*0 /
+      DATA (zrnfm(jm,72),jm=1,jpmois)/   &
+          232.,     128.,     150.,     266.,     402.,     459.,   &
+          353.,     306.,     604.,     930.,     878.,     466./
+      ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)          R1
+      ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+      ! --> 329.75m3/s
+      DATA inb(73)/1/
+      DATA (iirnf(jc,73),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,73),jc=1,jpcoef)/  79, 299*0 /
+      DATA (zrnfm(jm,73),jm=1,jpmois)/   &
+          452.,     455.,     492.,     466.,     482.,     251.,   &
+          151.,     108.,      87.,     133.,     395.,     485./
+      ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)           R1
+      ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+      ! --> 306.583374m3/s
+      DATA inb(74)/1/
+      DATA (iirnf(jc,74),jc=1,jpcoef)/ 145, 299*0 /
+      DATA (ijrnf(jc,74),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,74),jm=1,jpmois)/   &
+           88.,      63.,      68.,      95.,     139.,     222.,   &
+          395.,     633.,     825.,     675.,     328.,     148./
+      ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)            R1
+      ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+      ! --> 112.666664m3/s
+      DATA inb(75)/1/
+      DATA (iirnf(jc,75),jc=1,jpcoef)/ 144, 299*0 /
+      DATA (ijrnf(jc,75),jc=1,jpcoef)/  83, 299*0 /
+      DATA (zrnfm(jm,75),jm=1,jpmois)/   &
+           0.,       0.,       0.,       0.,       1.,      18.,   &
+          96.,     324.,     531.,     319.,      58.,       5./
+      ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27)     R1
+      ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+      ! --> 96.4999924m3/s
+      DATA inb(76)/1/
+      DATA (iirnf(jc,76),jc=1,jpcoef)/ 143, 299*0 /
+      DATA (ijrnf(jc,76),jc=1,jpcoef)/  83, 299*0 /
+      DATA (zrnfm(jm,76),jm=1,jpmois)/   &
+            2.,       1.,       1.,       4.,       8.,      44.,   &
+          168.,     274.,     386.,     215.,      47.,       8./
+      ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)          R1
+      ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+      ! --> 194.25m3/s
+      DATA inb(77)/1/
+      DATA (iirnf(jc,77),jc=1,jpcoef)/ 140, 299*0 /
+      DATA (ijrnf(jc,77),jc=1,jpcoef)/  82, 299*0 /
+      DATA (zrnfm(jm,77),jm=1,jpmois)/   &
+           14.,       7.,       9.,      17.,      29.,      90.,   &
+          145.,     349.,     740.,     688.,     198.,      45./
+      ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)      R1
+      ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+      ! --> 449.333344m3/s
+      DATA inb(78)/1/
+      DATA (iirnf(jc,78),jc=1,jpcoef)/ 139, 299*0 /
+      DATA (ijrnf(jc,78),jc=1,jpcoef)/  82, 299*0 /
+      DATA (zrnfm(jm,78),jm=1,jpmois)/   &
+          144.,     116.,     119.,     143.,     156.,     334.,   &
+          419.,     692.,    1277.,    1190.,     553.,     249./
+
+      DATA inb(79)/0/
+      DATA inb(80)/0/
+      DATA inb(82)/0/
+      DATA inb(83)/0/
+      DATA inb(84)/0/
+      DATA inb(85)/0/
+      DATA inb(86)/0/
+      DATA inb(87)/0/
+      DATA inb(88)/0/
+      DATA inb(89)/0/
+      DATA inb(90)/0/
+
+      ! Total run-offs (VI)=63977.m3/s
+      ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+      
+      ! VII OCEANIA
+      ! ------------
+      ! 91-Murray (Austrlia) 35S34 138E54                   R5
+      ! Old=22 km3/year=697m3/s
+      ! --> 696.999939m3/s
+      DATA inb(91)/1/
+      DATA (iirnf(jc,91),jc=1,jpcoef)/  30, 299*0 /
+      DATA (ijrnf(jc,91),jc=1,jpcoef)/  47, 299*0 /
+      DATA (zrnfm(jm,91),jm=1,jpmois)/12*697./
+      ! 92-Haast (N. Zeland) 43S50 169E02                   R5
+      ! Old=6 km3/year=190m3/s
+      ! --> 189.999985m3/s
+      DATA inb(92)/1/
+      DATA (iirnf(jc,92),jc=1,jpcoef)/  48, 299*0 /
+      DATA (ijrnf(jc,92),jc=1,jpcoef)/  41, 299*0 /
+      DATA (zrnfm(jm,92),jm=1,jpmois)/12*190./
+      ! 93-Fly (N. Guinea) 8S30 143E05                      R5
+      ! Old=77 km3/year=2440m3/s
+      ! --> 2440.m3/s
+      DATA inb(93)/1/
+      DATA (iirnf(jc,93),jc=1,jpcoef)/  34, 299*0 /
+      DATA (ijrnf(jc,93),jc=1,jpcoef)/  62, 299*0 /
+      DATA (zrnfm(jm,93),jm=1,jpmois)/12*2440./
+      ! 94-Purari (N. Guinea) 7S25 145E05                   R4
+      ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+      ! --> 2727.33325m3/s
+      DATA inb(94)/1/
+      DATA (iirnf(jc,94),jc=1,jpcoef)/  36, 299*0 /
+      DATA (ijrnf(jc,94),jc=1,jpcoef)/  64, 299*0 /
+      DATA (zrnfm(jm,94),jm=1,jpmois)/   &
+          1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+          2867.,    3477.,    2195.,    2967.,    2674.,    2627./
+      ! 95-Choshui ch''i (taiwan) 24N03 120E23              R2
+      ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+      ! --> 0.m3/s
+      DATA inb(95)/0/
+      DATA (iirnf(jc,95),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,95),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,95),jm=1,jpmois)/   &
+           65.,      63.,      83.,     100.,     177.,     535.,   &
+          332.,     313.,     236.,     193.,     101.,      84./
+      ! 96-Kaoping (Taiwan)                                 R5  
+      ! Old=9 km3/year=285m3/s
+      ! --> 0.m3/s
+      DATA inb(96)/0/
+      DATA (iirnf(jc,96),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,96),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,96),jm=1,jpmois)/12*285./
+      ! 97-Tsengwen (Taiwan)                                R5
+      ! Old=2 km3/year=63m3/s
+      ! --> 0.m3/s
+      DATA inb(97)/0/
+      DATA (iirnf(jc,97),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,97),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,97),jm=1,jpmois)/12*63./
+      ! 98-Hualien (Taiwan)                                 R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(98)/0/
+      DATA (iirnf(jc,98),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,98),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,98),jm=1,jpmois)/12*127./
+      ! 99-Peinan (Taiwan) 22N46 121E10                     R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 127.000008m3/s
+      DATA inb(99)/1/
+      DATA (iirnf(jc,99),jc=1,jpcoef)/  23, 299*0 /
+      DATA (ijrnf(jc,99),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,99),jm=1,jpmois)/12*127./
+      ! 100-Hsiukuluan (Taiwan)                             R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(100)/0/
+      DATA (iirnf(jc,100),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,100),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,100),jm=1,jpmois)/12*127./
+
+      DATA inb(101)/0/
+      DATA inb(102)/0/
+
+      !  Total run-offs(VII)=6181.33301m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+      !                                      = 1.588668056E-6 kg/m2/s
+      !                                      = 17883.5586 km3/Year
+      !                                      = 0.567083955 Sverdrup
+
+      ! VIII ANTARCTICA
+      ! ---------------
+      ! 103 -Antarcti! ice discharge (2 613 Gt/year) (jacobs et al 1992)
+      ! Data from Jacobs et al 92: =2613 km3/year=82857.686454 m3/s
+      ! --> 82858 m3/s
+      DATA inb(103)/295/
+      DATA (iirnf(jc,103),jc=1,jpcoef)/   &
+            1,    2,    3,    3,    4,    4,    5,    6,    7,    8,   &
+            9,    9,   10,   11,   12,   13,   14,   14,   15,   16,   &
+           17,   18,   19,   20,   21,   22,   23,   24,   25,   26,   &
+           27,   28,   29,   30,   31,   32,   32,   33,   34,   35,   &
+           35,   36,   36,   37,   38,   39,   40,   40,   41,   42,   &
+           42,   43,   43,   44,   44,   44,   44,   44,   44,   44,   &
+           45,   45,   45,   45,   46,   46,   46,   46,   46,   47,   &
+           47,   47,   47,   47,   48,   48,   48,   48,   48,   49,   &
+           50,   51,   51,   52,   53,   54,   55,   56,   57,   58,   &
+           59,   60,   61,   62,   62,   63,   63,   64,   65,   66,   &
+           66,   67,   67,   68,   69,   69,   70,   71,   71,   72,   &
+           73,   73,   74,   75,   76,   76,   77,   78,   78,   79,   &
+           80,   81,   82,   83,   83,   84,   85,   86,   87,   88,   &
+           88,   89,   89,   90,   91,   92,   93,   94,   95,   96,   &
+           97,   98,   99,  100,  101,  102,  102,  103,  104,  104,   &
+          104,  104,  104,  105,  105,  106,  106,  107,  107,  107,   &
+          108,  108,  109,  109,  110,  110,  111,  111,  112,  112,   &
+          112,  112,  112,  112,  112,  112,  112,  112,  112,  112,   &
+          112,  112,  112,  112,  112,  113,  113,  113,  113,  113,   &
+          114,  114,  114,  114,  115,  115,  115,  115,  115,  116,   &
+          116,  117,  117,  118,  118,  119,  119,  120,  121,  122,   &
+          123,  124,  124,  125,  125,  126,  126,  127,  128,  128,   &
+          129,  130,  130,  131,  132,  132,  133,  133,  133,  133,   &
+          133,  134,  135,  135,  136,  136,  136,  137,  137,  138,   &
+          139,  140,  141,  142,  142,  143,  144,  145,  146,  147,   &
+          148,  149,  150,  151,  152,  153,  154,  155,  156,  156,   &
+          157,  158,  159,  160,  161,  161,  162,  163,  163,  164,   &
+          165,  165,  166,  166,  167,  168,  169,  170,  171,  171,   &
+          172,  173,  173,  174,  175,  176,  177,  177,  178,  178,   &
+          179,  180,  180,  181,  181,    0,    0,    0,    0,    0    &
+                                      /
+      DATA (ijrnf(jc,103),jc=1,jpcoef)/   &
+           19,   20,   20,   21,   21,   22,   22,   22,   22,   22,   &
+           22,   23,   23,   23,   23,   23,   22,   23,   22,   22,   &
+           22,   22,   22,   22,   22,   22,   22,   22,   22,   22,   &
+           22,   22,   22,   22,   22,   21,   22,   21,   21,   20,   &
+           21,   19,   20,   19,   19,   19,   18,   19,   18,   17,   &
+           18,   16,   17,    3,    4,    5,    6,    7,    8,   16,   &
+            3,    8,    9,   16,    3,    9,   10,   15,   16,    3,   &
+           10,   11,   14,   15,    3,   11,   12,   13,   14,    3,   &
+            3,    2,    3,    2,    2,    2,    2,    2,    2,    2,   &
+            2,    2,    2,    2,    3,    3,    4,    4,    4,    4,   &
+            5,    5,    6,    6,    6,    7,    7,    7,    8,    8,   &
+            8,    9,    9,    9,    9,   10,   10,   10,   11,   11,   &
+           11,   11,   11,   10,   11,   10,   10,   10,   10,   10,   &
+           11,   11,   12,   12,   12,   12,   12,   12,   12,   12,   &
+           12,   12,   12,   12,   12,   12,   13,   13,   13,   14,   &
+           15,   16,   17,   17,   18,   18,   19,   19,   20,   21,   &
+           21,   22,   22,   23,   23,   24,   24,   25,    8,    9,   &
+           10,   11,   12,   13,   14,   15,   16,   17,   18,   19,   &
+           20,   21,   22,   25,   26,    7,    8,   22,   23,   26,   &
+            7,   23,   24,   26,    6,    7,   24,   25,   26,    5,   &
+            6,    4,    5,    3,    4,    2,    3,    2,    2,    2,   &
+            2,    2,    3,    3,    4,    4,    5,    5,    5,    6,   &
+            6,    6,    7,    7,    7,    8,    8,    9,   10,   11,   &
+           12,   12,   12,   13,   13,   14,   15,   15,   16,   16,   &
+           16,   16,   16,   16,   17,   17,   17,   17,   17,   17,   &
+           17,   17,   17,   17,   17,   17,   17,   17,   17,   18,   &
+           18,   18,   18,   18,   18,   19,   19,   19,   20,   20,   &
+           20,   21,   21,   22,   22,   22,   22,   22,   21,   22,   &
+           21,   20,   21,   20,   20,   20,   19,   20,   18,   19,   &
+           18,   18,   19,   19,   20,    0,    0,    0,    0,    0    &
+                                      /
+      DATA (zrnfm(jm,103),jm=1,jpmois)/12*82858./
+
+      !  Total run-offs(VIII)=82858 m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII+VIII)= 649941. m3/s
+      !                                           = 0.649940955 Sverdrup
+
+
+      DATA (inb(jr),jr=104,jpriv)/17*0/
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca2'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+         
+         i15 = nday / 16
+         
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  ii = iirnf(jl,jr) - nimpp + 1 - jpizoom + 1
+                  ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom + 1
+                  iipt0 = MAX( 1, MIN( ii, jpi   ) )
+                  iipt1 = MAX( 0, MIN( ii, jpi-1 ) )
+                  ijpt0 = MAX( 1, MIN( ij, jpj   ) )
+                  ijpt1 = MAX( 0, MIN( ij, jpj-1 ) )
+                  DO jj = ijpt0, ijpt1
+                     DO ji = iipt0, iipt1
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                                      + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                                      +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! --> zrup1 (originally, = 1 = all upstream).
+                     ! ji,jj
+                     ii = iirnf(jl,jr) - nimpp + 1 - jpizoom - 1
+                     ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom - 1
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     iipt0 = MAX( 1, MIN( ii+1, jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1, jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     ijpt0 = MAX( 1, MIN( ij, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     iipt0 = MAX( 1, MIN( ii-1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     iipt0 = MAX( 1, MIN( ii+1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     iipt0 = MAX( 1, MIN( ii+2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     iipt0 = MAX( 1, MIN( ii-2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = 1.0
+            upsrnfz(2)   = 1.0
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+
+            ! Reduces the sea surface restoring term to Levitus98
+            ! in the Sound Strait
+            DO jj = mj0(116), mj1(116)
+               DO ji = mi0(144), mi1(144)
+                  upsrnfh(ji,jj) = 0.25
+               END DO
+               DO ji = mi0(145), mi1(147)
+                  upsrnfh(ji,jj) = 0.5
+               END DO
+               DO ji = mi0(148), mi1(148)
+                  upsrnfh(ji,jj) = 0.25
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+      
+      ! Upstream and centered scheme in the vicinity of some straits
+
+      IF( kt == nit000 ) THEN
+
+         ! ORCA_R2 configuration :
+         ! Gibraltar Strait
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(138), mi1(138)
+               upsadv(ji,jj) = 0.2
+            END DO
+         END DO
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(139), mi1(139)
+               upsadv(ji,jj) = 0.4
+            END DO
+         END DO
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(140), mi1(140)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         DO jj = mj0(101), mj1(102)
+            DO ji = mi0(141), mi1(141)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         ! Bab el Mandeb Strait
+         DO jj = mj0(87), mj1(88)
+            DO ji = mi0(164), mi1(164)
+               upsadv(ji,jj) = 0.1
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(163), mi1(163)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(162), mi1(162)
+               upsadv(ji,jj) = 0.4
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(160), mi1(161)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         DO jj = mj0(89), mj1(89)
+            DO ji = mi0(158), mi1(160)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         DO jj = mj0(90), mj1(90)
+            DO ji = mi0(160), mi1(160)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         ! Sound Strait
+         DO jj = mj0(116), mj1(116)
+            DO ji = mi0(145), mi1(147)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+
+      ENDIF
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R4.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R4.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/flxrnf_ORCA_R4.h90	(revision 4536)
@@ -0,0 +1,1337 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flxrnf_ORCA_R4.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                  OLD ORCA R4 runoff specification
+   !!                      kept here for memory
+   !!                         ( 20/04/2000 )
+   !!----------------------------------------------------------------------
+
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: kt
+      INTEGER  :: jpmois
+      INTEGER  ::   &
+         jpriv,    & ! jpriv : maximum river number
+         jpcoef      ! jpcoef: maximum point number
+      INTEGER, PARAMETER ::   jpmois=12, jpriv=120, jpcoef=150
+
+      INTEGER  ::   ji, jj, jl, jm, jn, jr, jc
+      INTEGER  ::   i15, imois, iman
+      INTEGER  ::   inbp, idbd, idmeom
+      INTEGER  ::   iipt0, iipt1, ijpt0, ijpt1, ii, ij
+      INTEGER  ::   iirnf(jpcoef,jpriv),ijrnf(jpcoef,jpriv)
+      INTEGER  ::   inb(jpriv)
+
+      REAL(wp) ::   zconv, zxy
+      REAL(wp) ::   zrup1,zrup2,zrup3
+      REAL(wp) ::   zrnfm(jpmois, jpriv)
+      REAL(wp) ::   zcoefr(jpi, jpj, 5)
+      CHARACTER (len=20) ::   criver(jpriv)
+
+      REAL(wp) ::   zbilan , zero
+
+      COMMON/zzzrnf/ zrnfm, iirnf, ijrnf, inb
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+      ! ====
+      ! DATA
+      ! ====
+
+      zero = 0.0e0
+      IF( kt == nit000 ) THEN 
+          criver = "                    "
+          inb = 0
+          iirnf = 0
+          ijrnf = 0
+          zrnfm  = zero
+          runoff = zero
+         
+          ! I NORTH AMERICA
+          ! ---------------
+          
+          ! 1-Saint Lawrence (Canada) 49N30 67W00           R2
+          ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+          ! --> 13975.249m3/s
+          criver(1) = "Saint Lawrence      "
+          inb(1) = 1
+          iirnf(1:1,1) = 57
+          ijrnf(1:1,1) = 55
+          zrnfm(1:jpmois,1) = (/   &
+              11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+              14211.,  13119.,  13367.,  13644.,  13463.,  12594./)
+          ! 2-Hudson River (USA) 41N00 77W00                R1
+          ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+          ! --> 407.416687m3/s
+          criver(2) = "Hudson River        "
+          inb(2) = 1
+          iirnf(1:1,2) = 54
+          ijrnf(1:1,2) = 53
+          zrnfm(1:jpmois,2) = (/   &
+              364.,    404.,    648.,    873.,    593.,    301.,   &
+              205.,    171.,    205.,    290.,    379.,    456./)
+          ! 3-Missisipi and Atchafalaya (USA) 29N 90W       R1 
+          ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+          ! --> 17599.334m3/s
+          criver(3) = "Missisipi           "
+          inb(3) = 1
+          iirnf(1:1,3) = 50
+          ijrnf(1:1,3) = 49
+          zrnfm(1:jpmois,3) = (/   &
+              19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+              14181.,  10676.,   9578.,  10167.,  11699.,  17472./)
+          ! 4-Brazos (USA) 29N58 95W53                      R1
+          ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+          ! --> 199.666656m3/s
+          criver(4) = "Brazos              "
+          inb(4) = 1
+          iirnf(1:1,4) = 48
+          ijrnf(1:1,4) = 49
+          zrnfm(1:jpmois,4) = (/   &
+              165.,    224.,    200.,    266.,    457.,    327.,   &
+              143.,     69.,    102.,    132.,    160.,    151. /)
+          ! 5-Colorado (Mexico) 31N54 114W57                R5
+          ! Old=20 km3/year=634m3/s
+          ! --> 634.m3/s
+          criver(5) = "Colorado            "
+          inb(5) = 1
+          iirnf(1:1,5) = 43
+          ijrnf(1:1,5) = 50
+          zrnfm(1:jpmois,5) = 634. 
+          ! 6-Columbia (USA) 45N60 121W17                   R1
+          ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+          ! --> 5368.41602m3/s
+          criver(6) = "Columbia            "
+          inb(6) = 1
+          iirnf(1:1,6) = 40
+          ijrnf(1:1,6) = 56
+          zrnfm(1:jpmois,6) = (/   &
+              4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+              6350.,    4112.,    3273.,    3251.,    3548.,    4106. /)
+          ! 7-Fraser (USA) 47N 124W                         R5
+          ! Old=112 km3/year=3550m3/s;not found in UNESCO
+          ! --> 3549.99976m3/s
+          criver(7) = "Fraser              "
+          inb(7) = 1
+          iirnf(1:1,7) = 40
+          ijrnf(1:1,7) = 57
+          zrnfm(1:jpmois,7) = 3550. 
+          ! 8-Yukon (USA) 63N00 165W00                      R3
+          ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+          ! --> 6017.24951m3/s
+          criver(8) = "Yukon               "
+          inb(8) = 1
+          iirnf(1:1,8) = 30
+          ijrnf(1:1,8) = 62
+          zrnfm(1:jpmois,8) = (/   &
+              1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+              10680.,   11271.,    8658.,    5453.,    2649.,    1917./)
+          ! 9-Copper (USA) 61N47 144W45                     R2
+          ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+          ! --> 1236.25m3/s
+          criver(9) = "Copper              "
+          inb(9) = 1
+          iirnf(1:1,9) = 35
+          ijrnf(1:1,9) = 60
+          zrnfm(1:jpmois,9) = (/   &
+              219.,    195.,    181.,    214.,    904.,   2532.,   &
+              4026.,   3627.,   1632.,    697.,    354.,    254. /) 
+          ! 10-Susitna (USA)   62N 150E                     R5
+          ! Old=40 km3/year=1268m3/s
+          ! --> 1268.m3/s
+          criver(10) = "Susitna             "
+          inb(10) = 1
+          iirnf(1:1,10) = 34
+          ijrnf(1:1,10) = 60
+          zrnfm(1:jpmois,10) = 1268. 
+          ! 11-McKenzie (Canada) 70N00 135W00               R3
+          ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+          ! ratio=1.16
+          ! --> 9606.66797m3/s
+          criver(11) = "McKenzie            "
+          inb(11) = 1
+          iirnf(1:1,11) = 35
+          ijrnf(1:1,11) = 66
+          zrnfm(1:jpmois,11) = (/   &
+              3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+              18954.,   15487.,   11284.,   10169.,    5901.,    3905./)
+          ! 12-Kuksokwim (USA) 60N00 ~162W30                R4
+          ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+          ! --> 1111.99988m3/s
+          criver(12) = "Kuksokwim           "
+          inb(12) = 1
+          iirnf(1:1,12) = 30
+          ijrnf(1:1,12) = 60
+          zrnfm(1:jpmois,12) = (/   &
+              335.,     308.,     295.,     407.,    2415.,    2027.,   &
+              1917.,   2049.,    1585.,    1072.,     545.,     389./)
+          ! 13-Nelson
+          criver(13) = "Nelson              "
+          inb(13) = 1
+          iirnf(1:1,13) = 51
+          ijrnf(1:1,13) = 65
+          zrnfm(1:jpmois,13) = 0.
+
+          ! Total run-offs(I)=60974.2539m3/s
+
+          ! II SOUTH AMERICA
+          ! -----------------
+          ! 16-Chira (Peru) 4s54 81w08                      R2
+          ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+          ! --> 158.000015m3/s
+          criver(16) = "Chira               "
+          inb(16) = 1
+          iirnf(1:1,16) = 51
+          ijrnf(1:1,16) = 34
+          zrnfm(1:jpmois,16) = (/   &
+              70.,     105.,     564.,     582.,     230.,      94.,   &
+              87.,      47.,      35.,      32.,      29.,      21./)
+          ! 17-Magdalena (Colombia) 11N06 74W51             R2
+          ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+          ! ratio=1.08
+          ! --> 7451.58301m3/s
+          criver(17) = "Magdelena           "
+          inb(17) = 1
+          iirnf(1:1,17) = 53
+          ijrnf(1:1,17) = 45
+          zrnfm(1:jpmois,17) = (/   &
+              6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+              8509.,    7428.,    7631.,    9296.,   10588.,    9949./)
+          ! 18-Orinoco (Venezuela) 8N37 62W15!              R1
+          ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+          ! HLA=26371m3/s
+          ! Data from HLA: 8.1N - 63.3W   1925/89
+          ! --> 26371.416
+          criver(18) = "Orinico             "
+          inb(18) = 1
+          iirnf(1:1,18) = 57
+          ijrnf(1:1,18) = 44
+          zrnfm(1:jpmois,18) = (/   &
+              10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+              43938.,   59957.,   57435.,   39951.,   27410.,   16567./)
+          ! 19-Amazon (Brazil) 0S05 50W00                   R1
+          ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+          ! HLA=184806m3/s
+          ! UNESCO data are at Obidos which is far inland and therefore does not
+          ! fully represent the actual discharge
+          ! Data from HLA: 1.5N - 55.3W   1970/96
+          ! --> 184845.484m3/s
+          criver(19) = "Amazon              "
+          inb(19) = 3
+          iirnf(1:3,19) = (/ 60, 60, 60 /)
+          ijrnf(1:3,19) = (/ 39, 40, 41 /)
+          zrnfm(1:jpmois,19) = (/   &
+              152233., 176415., 199941., 225565., 244016., 244861.,   &
+              230711., 203128., 164531., 128486., 118214., 130045. /)
+          ! 20-Sao Francisco (Brazil) 10S30 36W24           R1
+          ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+          ! --> 2645.3335m3/s
+          criver(20) = "San Fransisco       "
+          inb(20) = 1
+          iirnf(1:1,20) = 63
+          ijrnf(1:1,20) = 31
+          zrnfm(1:jpmois,20) = (/   &
+              3244.,   4116.,   5139.,   4330.,   2323.,   1800.,     &
+              1587.,   1511.,   1593.,   1740.,   2190.,   2171. /)
+          ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18        R1 
+          ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+          ! --> 22203.168m3/s 
+          criver(21) = "Parana              "
+          inb(21) = 1
+          iirnf(1:1,21) = 58
+          ijrnf(1:1,21) = 24
+          zrnfm(1:jpmois,21) = (/   &
+              24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+              22647.,   20403.,   19627.,   21400.,   21126.,   21923./)
+          ! 22-Negro (Argentina)  41S02  62W47              R2
+          ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+          ! --> 907.666687m3/s
+          criver(22) = "Rio Negro           "
+          inb(22) = 1
+          iirnf(1:1,22) = 56
+          ijrnf(1:1,22) = 22
+          zrnfm(1:jpmois,22) = (/   &
+              882.,     587.,     519.,     482.,     623.,     984.,   &
+              1120.,   1294.,    1092.,    1166.,    1105.,    1038./)
+          ! 23- Tocantins :  ~48W00 ~0.5S                   R4
+          ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+          ! --> 12173.082m3/s
+          criver(23) = "Tocantins           "
+          inb(23) = 1
+          iirnf(1:1,23) = 60
+          ijrnf(1:1,23) = 38
+          zrnfm(1:jpmois,23) = (/   &
+              15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+              4440.,   3082.,   2728.,   3417.,   5511.,  10705. /)
+
+          ! Total run-offs(II)=256755.75
+          ! Total run-offs(I+II)=317730
+
+          ! III EUROPE
+          ! ----------
+          ! 26-Rhone (France) 43N20 4E50                    R1 
+          ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+          ! --> 1217.16663m3/s
+          criver(26) = "Rhone               "
+          inb(26) = 1
+          iirnf(1:1,26) = 76
+          ijrnf(1:1,26) = 55
+          zrnfm(1:jpmois,26) = (/   &
+              1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+              937.,     796.,     794.,     962.,    1161.,    1233./)
+          ! 27-Po (Italy) 41N10 11E09                       R1 
+          ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+          ! --> 1550.08337m3/s
+          criver(27) = "Po                  "
+          inb(27) = 1
+          iirnf(1:1,27) = 79
+          ijrnf(1:1,27) = 54
+          zrnfm(1:jpmois,27) = (/   &
+              1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+              1040.,    1007.,    1615.,    1907.,    1772.,    1228./)
+          ! 28-Danube (Roumania) 45N20 29E40                R1 
+          ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+          ! --> 7011.8335m3/s
+          criver(28) = "Danube              "
+          inb(28) = 1
+          iirnf(1:1,28) = 87
+          ijrnf(1:1,28) = 53
+          zrnfm(1:jpmois,28) = (/   &
+              6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+              7586.,    6001.,    5210.,    4989.,    4921.,    6093./)
+
+          ! 29-Volga
+          criver(29) = "Volga               "
+          inb(29) = 1
+          iirnf(1:1,29) = 4
+          ijrnf(1:1,29) = 56
+          zrnfm(1:jpmois,29) = 0.
+          ! 30-Dniepr
+          criver(30) = "Dniepr+Don          "
+          inb(30)= 2
+          iirnf(1:2,30) = (/ 89, 90 /)
+          ijrnf(1:2,30) = (/ 56, 56 /)
+
+          ! Total run-offs(III)=9779.08301m3/s
+          ! Total run-offs(I+II+III)=327509.094m3/s
+
+          ! IV EURASIAN ARCTIC
+          ! ------------------
+          ! 31-Iana (Russia)      126E40 72N25              R1
+          ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+          ! --> 0m3/s
+          criver(31) = "Iana                "
+          inb(31) = 1
+          iirnf(1:1,31) = 20
+          ijrnf(1:1,31) = 68
+          zrnfm(1:jpmois,31) = (/   &
+              2.,       1.,       0.,       0.,     917.,    3514.,   &
+              2968.,    2329.,    1322.,   178.,      36.,       8./)
+          ! 32-Ob (Russia) 66N45 69E30                      R1 
+          ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+          ! --> 12861.5m3/s
+          criver(32) = "Ob                  "
+          inb(32) = 1
+          iirnf(1:1,32) = 78
+          ijrnf(1:1,32) = 72
+          zrnfm(1:jpmois,32) = (/   &
+              4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+              30773.,   22785.,   14701.,    9705.,    6078.,    5879./)
+          ! 33-Yenesei (Russia) 71N50 82E40                 R1 
+          ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+          ! --> 17461.666m3/s
+          criver(33) = "Yenesei             "
+          inb(33) = 1
+          iirnf(1:1,33) = 77
+          ijrnf(1:1,33) = 75
+          zrnfm(1:jpmois,33) = (/   &
+              6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+              25325.,   15940.,   16050.,   12678.,    6741.,    6008./)
+          ! 34-Severnaya Dvina(Russia)64N32 40E30           R5 
+          ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+          ! --> 3359.00024m3/s
+          criver(34) = "Severnaya Dvina     "
+          inb(34) = 1
+          iirnf(1:1,34) = 78
+          ijrnf(1:1,34) = 68
+          zrnfm(1:jpmois,34) = 3359.
+          ! 35-Lena (Russia) 72N25 126E40                   R1 
+          ! --> 16192.333m3/s
+          criver(35) = "Lena                "
+          inb(35) = 1
+          iirnf(1:1,35) = 20
+          ijrnf(1:1,35) = 68
+          zrnfm(1:jpmois,35) = (/   &
+              2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+              40810.,   28310.,   25995.,   13299.,    3673.,    3077./)
+          ! 36-Kolyma (Russia) 69N30 161E00                 R1
+          ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+          ! --> 2138.66675m3/s
+          criver(36) = "Kolyma              "
+          inb(36) = 1
+          iirnf(1:1,36) = 24
+          ijrnf(1:1,36) = 65
+          zrnfm(1:jpmois,36) = (/   &
+              131.,      92.,      76.,      65.,    2576.,    9143.,   &
+              4670.,    3727.,    3226.,    1119.,     630.,     209./)
+          ! 37-Indigirka (russia) 70N48 148E54              R1 
+          ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+          ! --> 1622.00012m3/s
+          criver(37) = "Indigirka           "
+          inb(37) = 1
+          iirnf(1:1,37) = 23
+          ijrnf(1:1,37) = 66
+          zrnfm(1:jpmois,37) = (/   &
+              32.,      17.,      11.,       7.,     354.,    5629.,   &
+              5210.,    4617.,    2823.,     559.,     142.,      63./)
+          ! 38-Khatanga
+          criver(38) = "Khatanga             "
+          inb(38) = 1
+          iirnf(1:1,38) = 20
+          ijrnf(1:1,38) = 72
+          zrnfm(1:jpmois,38) = 0.
+
+          ! Total run-offs(IV)=40773.6641m3/s
+          ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+          ! V ASIA
+          ! ------
+          ! 41-Amur (Russia) 52N56 141E10                   R2
+          ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+          ! --> 10299.332m3/s
+          criver(41) = "Amur                "
+          inb(41) = 1
+          iirnf(1:1,41) = 18
+          ijrnf(1:1,41) = 59
+          zrnfm(1:jpmois,41) = (/   &
+              2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+              16100.,   20801.,   21548.,   15658.,    5188.,    2506./)
+          ! 42-Liaohe (China) 40N40 122E09                  R5
+          ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+          ! --> 189.999985m3/s
+          criver(42) = "Liaohe              "
+          inb(42) = 1
+          iirnf(1:1,42) = 15
+          ijrnf(1:1,42) = 54
+          zrnfm(1:jpmois,42) = 190.
+          ! 43-Daling (China) 40N56 121E43                  R5
+          ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+          ! --> 31.9999962m3/s
+          criver(43) = "Daling              "
+          inb(43) = 1
+          iirnf(1:1,43) = 15
+          ijrnf(1:1,43) = 54
+          zrnfm(1:jpmois,43) = 32.
+          ! 44-Haiho (China) 6N17   1E23
+          ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+          ! --> 63.9999924m3/s
+          criver(44) = "Haiho               "
+          inb(44) = 0
+          iirnf(1:1,44) = 0
+          ijrnf(1:1,44) = 0
+          zrnfm(1:jpmois,44) = 64.
+          ! 45-Yellow/Huangho (China) 37N32 118E19          R2 
+          ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+          ! --> 1552.5m3/s
+          criver(45) = "Yellow/Huangho      "
+          inb(45) = 1
+          iirnf(1:1,45) = 13
+          ijrnf(1:1,45) = 51
+          zrnfm(1:jpmois,45) = (/   &
+              697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+              1964.,    3270.,    3668.,    2133.,     978.,     871./)
+          ! 46-Yangtze (China) 31N48 121E10=Changjiang      R2
+          ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+          ! --> 28519.584m3/s
+          criver(46) = "Yangtze             "
+          inb(46) = 1
+          iirnf(1:1,46) = 13
+          ijrnf(1:1,46) = 50
+          zrnfm(1:jpmois,46) = (/   &
+              10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+              53891.,   42070.,   37627.,   30762.,   22046.,   12777./)
+          ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang  R2 
+          ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+          ! --> 9570.75m3/s
+          criver(47) = "Pearl Zhujiang       "
+          inb(47) = 1
+          iirnf(1:1,47) = 12
+          ijrnf(1:1,47) = 48
+          zrnfm(1:jpmois,47) = (/   &
+              2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+              19213.,   17558.,   12312.,    7255.,    5864.,    6154./)
+          ! 48-Red/Hungho (Vietnam) 20N17 106E34            R5 
+          ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+          ! --> 3897.m3/s
+          criver(48) = "Red Hungho          "
+          inb(48) = 1
+          iirnf(1:1,48) = 10
+          ijrnf(1:1,48) = 47
+          zrnfm(1:jpmois,48) = 3897.
+          ! 49-Mekong (Vietnam) 10N33 105E24                R5
+          ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+          ! --> 14893.0029m3/s
+          criver(49) = "Mekong              "
+          inb(49) = 1
+          iirnf(1:1,49) =  8
+          ijrnf(1:1,49) = 44
+          zrnfm(1:jpmois,49) = 14893.
+          ! 50-Irrawady (Burma) 15N50  95E06                R5
+          ! Old=428 km3/year=13563m3/s; not in UNESCO data base
+          ! --> 13563.m3/s
+          criver(50) = "Irrawady            "
+          inb(50) = 1
+          iirnf(1:1,50) =  6
+          ijrnf(1:1,50) = 46
+          zrnfm(1:jpmois,50) = 13563.
+          ! 51-Ganges+Brahmaputra (Beng.) 22N00  91E00      R1
+          ! Old=971 km3/year=30769m3/s; UNESCO(69-70+73-75, p367)=31760m3/s
+          ! --> 32147.498m3/s
+          criver(51) = "Ganges              "
+          inb(51) = 2
+          iirnf(1:2,51) = (/  4,  5 /)
+          ijrnf(1:2,51) = (/ 47, 47 /)
+          zrnfm(1:jpmois,51) = (/   &
+              6623.,    6315.,    6432.,    9410.,   17263.,   38302.,   &
+              64688.,   80338.,   84802.,   43387.,   17888.,   10322./)
+          ! 52-Mehandi (India)                              R5
+          ! Old=67 km3/year=2123m3/s; not in UNESCO data base
+          ! --> 0m3/s
+          criver(52) = "Mehandi             "
+          inb(52) = 0
+          iirnf(1:1,52) = 0
+          ijrnf(1:1,52) = 0
+          zrnfm(1:jpmois,52) = 2123.
+          ! 53-Damodar (India)                              R2
+          ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+          ! --> 432.916656m3/s
+          criver(53) = "Damodar             "
+          inb(53) = 0
+          iirnf(1:1,53) = 0
+          ijrnf(1:1,53) = 0
+          zrnfm(1:jpmois,53) = (/   &
+              51.,      37.,      42.,      49.,      85.,     296.,   &
+              896.,    1390.,    1591.,     542.,     172.,      44./)  
+          ! 54-Godavari (India) 17N00  81E45                R2
+          ! Old=84 km3/year=2662m3/s; UNESCO(p379)=1916m3/s; ratio=1.39
+          ! --> 3670.5m3/s
+          criver(54) = "Godaravi            "
+          inb(54) = 1
+          iirnf(1:1,54) =  3
+          ijrnf(1:1,54) = 46
+          zrnfm(1:jpmois,54) = (/   &
+              988.,     737.,     280.,     219.,     196.,    1691.,   &
+              8063.,   14571.,   11428.,    3953.,    1221.,     699./)
+          ! 55-Indus (Pakistan) 24N20  67E47                R2
+          ! Old=238 km3/year=7542m3/s; UNESCO (76-79, p428)=2396m3/s; ratio=3.15
+          ! --> 7562.m3/s
+          criver(55) = "Indus               "
+          inb(55) = 1
+          iirnf(1:1,55) = 89
+          ijrnf(1:1,55) = 47
+          zrnfm(1:jpmois,55) = (/   &
+              988.,     737.,    1904.,    1968.,    3625.,    6143.,   &
+              15969.,    36656.,  17173.,    3215.,    1251.,    1115./)
+          ! 56-Tigris and Euphrates (Iraq) 31N00  47E25     R1
+          ! Old=46 km3/year=1458m3/s; UNESCO(76-79, p428)=2396m3/s
+          ! --> 2248.8335m3/s
+          criver(56) = "Tigris              "
+          inb(56) = 1
+          iirnf(1:1,56) = 88
+          ijrnf(1:1,56) = 47
+          zrnfm(1:jpmois,56) = (/   &
+              1872.,    2127.,    2962.,    4944.,    5036.,    3078.,   &
+              1362.,     900.,     786.,     993.,    1184.,    1742./)
+
+          ! Total run-offs (V)=128642.922m3/s
+          ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+
+          ! VI AFRICA
+          ! ----------
+          ! 61-Nile (Egypt) 30N10  31E06                    R1
+          ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+          ! --> 1251.33337m3/s
+          criver(61) = "Nile                "
+          inb(61) = 1
+          iirnf(1:1,61) = 90
+          ijrnf(1:1,61) = 50
+          zrnfm(1:jpmois,61) = (/   &
+              1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+              1742.,    1559.,    1191.,    1103.,    1075.,    1124./)
+          ! 62-Niger (Nigeria) 5N33   6E33                  R1
+          ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+          ! Data from HLA: 4.5N -  6  E   1950/87
+          ! --> 5545.08301m3/s
+          criver(62) = "Niger               "
+          inb(62) = 1
+          iirnf(1:1,62) = 74
+          ijrnf(1:1,62) = 41
+          zrnfm(1:jpmois,62) = (/   &
+              2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+              5272.,    9629.,   14951.,   16227.,    6842.,    2741./)
+          ! 63-Zaire/Congo (Congo) 6S04  12E24              R1      
+          ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+          ! =39720m3/s
+          ! Data from HLA: 6S - 12  E   1902/96
+          ! --> 39719.5m3/s
+          criver(63) = "Zaire Congo         "
+          inb(63) = 1
+          iirnf(1:1,63) = 75
+          ijrnf(1:1,63) = 33
+          zrnfm(1:jpmois,63) = (/   &
+              47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+              30966.,   30774.,   35981.,   42825.,   51455.,   55314./)
+          ! 64-Orange (Sth Africa) 28S41 16E28              R5
+          ! Old=11 km3/year=349m3/s
+          ! --> 349.000031m3/s
+          criver(64) = "Orange              "
+          inb(64) = 1
+          iirnf(1:1,64) = 76
+          ijrnf(1:1,64) = 26
+          zrnfm(1:jpmois,64) = 349.
+          ! 65-Zambesi (Mozambique) 18S55 36E04             R5
+          ! Old=223 km3/year=7066m3/s
+          ! --> 7066.00049m3/s
+          criver(65) = "Zambesi             "
+          inb(65) = 1
+          iirnf(1:1,65) = 81
+          ijrnf(1:1,65) = 29
+          zrnfm(1:jpmois,65) = 7066.
+          ! 66-Limpopo (mozambique) 25S15 33E30             R5
+          ! Old=5 km3/year=158m3/s
+          ! --> 158.m3/s
+          criver(66) = "Limpopo             "
+          inb(66) = 1
+          iirnf(1:1,66) = 81
+          ijrnf(1:1,66) = 28
+          zrnfm(1:jpmois,66) = 158.
+          ! 67-Rufiji (tanzania) 8S00 39E20                 R5
+          ! Old=9 km3/year=285m3/s
+          ! --> 285.m3/s
+          criver(67) = "Rufiji             "
+          inb(67) = 1
+          iirnf(1:1,67) = 82
+          ijrnf(1:1,67) = 33
+          zrnfm(1:jpmois,67) = 285.
+          ! Other rivers from the Gulf of Guinea
+          ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)     R1
+          ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+          ! --> 924.25m3/s
+          criver(68) = "Kouilou            "
+          inb(68) = 1
+          iirnf(1:1,68) = 75
+          ijrnf(1:1,68) = 33
+          zrnfm(1:jpmois,68) = (/   &
+              1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+              480.,     378.,     327.,     400.,    1018.,    1281./)
+          ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)          R1
+          ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+          ! --> 264.166687m3/s
+          criver(69) = "Nyanga              "
+          inb(69) = 1
+          iirnf(1:1,69) = 74
+          ijrnf(1:1,69) = 36
+          zrnfm(1:jpmois,69) = (/   &
+              126.,      99.,     143.,     253.,     316.,     300.,   &
+              156.,      93.,     231.,     557.,     592.,     304./)
+          ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)            R1
+          ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+          ! --> 4511.83301m3/s
+          criver(70) = "Ogoue               "
+          inb(70) = 1
+          iirnf(1:1,70) = 74
+          ijrnf(1:1,70) = 37
+          zrnfm(1:jpmois,70) = (/   &
+              4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+              2616.,    1961.,    2119.,    4304.,    7870.,    6810./)
+          ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)    R1
+          ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+          ! --> 1982.58337m3/s
+          criver(71) = "Sanaga              "
+          inb(71) = 1
+          iirnf(1:1,71) = 74
+          ijrnf(1:1,71) = 41
+          zrnfm(1:jpmois,71) = (/   &
+              813.,     578.,     517.,     633.,     909.,    1278.,   &
+              1928.,    2653.,    4361.,    5470.,    3307.,    1344./)
+          ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)     R1
+          ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+          ! --> 431.166656m3/s      
+          criver(72) = "Nyong               "
+          inb(72) = 1
+          iirnf(1:1,72) = 74
+          ijrnf(1:1,72) = 41
+          zrnfm(1:jpmois,72) = (/   &
+              232.,     128.,     150.,     266.,     402.,     459.,   &
+              353.,     306.,     604.,     930.,     878.,     466./)
+          ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)      R1
+          ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+          ! --> 329.75m3/s
+          criver(73) = "Ntem                "
+          inb(73) = 1
+          iirnf(1:1,73) = 74
+          ijrnf(1:1,73) = 41
+          zrnfm(1:jpmois,73) = (/   &
+              452.,     455.,     492.,     466.,     482.,     251.,   &
+              151.,     108.,      87.,     133.,     395.,     485./)
+          ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)       R1
+          ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+          ! --> 306.583374m3/s
+          criver(74) = "Wouri               "
+          inb(74) = 1
+          iirnf(1:1,74) = 74
+          ijrnf(1:1,74) = 41
+          zrnfm(1:jpmois,74) = (/   &
+              88.,      63.,      68.,      95.,     139.,     222.,   &
+              395.,     633.,     825.,     675.,     328.,     148./)
+          ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)        R1
+          ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+          ! --> 112.666664m3/s
+          criver(75) = "Oueme               "
+          inb(75) = 1
+          iirnf(1:1,75) = 73
+          ijrnf(1:1,75) = 42
+          zrnfm(1:jpmois,75) = (/   &
+              0.,       0.,       0.,       0.,       1.,      18.,   &
+              96.,     324.,     531.,     319.,      58.,       5./)
+          ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27) R1
+          ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+          ! --> 96.4999924m3/s
+          criver(76) = "Mono                "
+          inb(76) = 1
+          iirnf(1:1,76) = 72
+          ijrnf(1:1,76) = 42
+          zrnfm(1:jpmois,76) = (/   &
+              2.,       1.,       1.,       4.,       8.,      44.,   &
+              168.,     274.,     386.,     215.,      47.,       8./)
+          ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)      R1
+          ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+          ! --> 194.25m3/s
+          criver(77) = "Comoe               "
+          inb(77) = 1
+          iirnf(1:1,77) = 71
+          ijrnf(1:1,77) = 41
+          zrnfm(1:jpmois,77) = (/   &
+              14.,       7.,       9.,      17.,      29.,      90.,   &
+              145.,     349.,     740.,     688.,     198.,      45./)
+          ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)  R1
+          ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+          ! --> 449.333344m3/s
+          criver(78) = "Sassandra           "
+          inb(78) = 1
+          iirnf(1:1,78) = 71
+          ijrnf(1:1,78) = 41
+          zrnfm(1:jpmois,78) = (/   &
+              144.,     116.,     119.,     143.,     156.,     334.,   &
+              419.,     692.,    1277.,    1190.,     553.,     249./)
+          ! 79-Jubba (Somali Coast)
+          criver(79) = "Jubba               "
+          inb(79) = 1
+          iirnf(1:1,79) = 84
+          ijrnf(1:1,79) = 39
+          zrnfm(1:jpmois,79) = 0.
+          ! 80-Senaga
+          criver(80) = "Senegal             "
+          inb(79) = 1
+          iirnf(1:1,80) = 66
+          ijrnf(1:1,80) = 47
+          zrnfm(1:jpmois,79) = 0.
+      
+          ! Total run-offs (VI)=63977.m3/s
+          ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+          
+          ! VII OCEANIA
+          ! ------------
+          ! 91-Murray (Australia) 35S34 138E54              R5
+          ! Old=22 km3/year=697m3/s
+          ! --> 696.999939m3/s
+          criver(91) = "Murray              "
+          inb(91) = 1
+          iirnf(1:1,91) = 16
+          ijrnf(1:1,91) = 24
+          zrnfm(1:jpmois,91) = 697.
+          ! 92-Haast (N. Zeland) 43S50 169E02               R5
+          ! Old=6 km3/year=190m3/s
+          ! --> 189.999985m3/s
+          criver(92) = "Haast               "
+          inb(92) = 1
+          iirnf(1:1,92) = 24
+          ijrnf(1:1,92) = 22
+          zrnfm(1:jpmois,92) = 190.
+          ! 93-Fly (N. Guinea) 8S30 143E05                  R5
+          ! Old=77 km3/year=2440m3/s
+          ! --> 2440.m3/s
+          criver(93) = "Fly                 "
+          inb(93) = 1
+          iirnf(1:1,93) = 19
+          ijrnf(1:1,93) = 31
+          zrnfm(1:jpmois,93) = 2440.
+          ! 94-Purari (N. Guinea) 7S25 145E05               R4
+          ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+          ! --> 2727.33325m3/s
+          criver(94) = "Purari              "
+          inb(94) = 1
+          iirnf(1:1,94) = 19
+          ijrnf(1:1,94) = 33
+          zrnfm(1:jpmois,94) = (/   &
+              1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+              2867.,    3477.,    2195.,    2967.,    2674.,    2627./)
+          ! 95-Choshui ch''i (taiwan) 24N03 120E23          R2
+          ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+          ! --> 0.m3/s
+          criver(95) = "Choshui             "
+          inb(95) = 1
+          iirnf(1:1,95) = 12
+          ijrnf(1:1,95) = 48
+          zrnfm(1:jpmois,95) = (/   &
+              65.,      63.,      83.,     100.,     177.,     535.,   &
+              332.,     313.,     236.,     193.,     101.,      84./)
+          ! 96-Kaoping (Taiwan)                             R5  
+          ! Old=9 km3/year=285m3/s
+          ! --> 0.m3/s
+          criver(96) = "Kaoping             "
+          inb(96) = 0
+          iirnf(1:1,96) = 0
+          ijrnf(1:1,96) = 0
+          zrnfm(1:jpmois,96) = 285.
+          ! 97-Tsengwen (Taiwan)                            R5
+          ! Old=2 km3/year=63m3/s
+          ! --> 0.m3/s
+          criver(97) = "Tsengwen            "
+          inb(97) = 0
+          iirnf(1:1,97) = 0
+          ijrnf(1:1,97) = 0
+          zrnfm(1:jpmois,97) = 63.
+          ! 98-Hualien (Taiwan)                             R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 0.m3/s
+          criver(98) = "Hualien             "
+          inb(98) = 0
+          iirnf(1:1,98) = 0
+          ijrnf(1:1,98) = 0
+          zrnfm(1:jpmois,98) = 127.
+          ! 99-Peinan (Taiwan) 22N46 121E10                 R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 127.000008m3/s
+          criver(99) = "Peinan              "
+          inb(99) = 1
+          iirnf(1:1,99) = 12
+          ijrnf(1:1,99) = 48
+          zrnfm(1:jpmois,99) = 127.
+          ! 100-Hsiukuluan (Taiwan)                         R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 0.m3/s
+          criver(100) = "Hsiukuluan          "
+          inb(100) = 0
+          iirnf(1:1,100) = 0
+          ijrnf(1:1,100) = 0
+          zrnfm(1:jpmois,100) = 127.
+
+          !  Total run-offs(VII)=6181.33301m3/s
+          
+
+          ! VIII ANTARCTICA
+          ! ---------------
+          ! 103 -Antarctic ice discharge (2 613 Gt/year) (jacobs et al 1992)
+          ! Data from Jacobs et al 92: =2613 km3/year=82857.686454 m3/s
+          ! --> 82858 m3/s
+          criver(103) = "Antarctica         "
+          inb(103) = 108
+          iirnf(1:108,103) = (/   &
+               2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,   &
+              21,22,23,24,25,25,24,24,24,25,26,27,28,29,30,31,32,33,34,   &
+              35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,51,53,   &
+              53,53,53,54,54,54,56,57,57,57,57,57,57,57,57,57,57,58,59,   &
+              60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,   &
+              79,80,81,82,83,84,85,86,87,88,89,90,91 /)
+          ijrnf(1:108,103) = (/   &
+              12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,   &
+              10,10, 9, 9, 8, 7, 6, 5, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,   &
+               3, 4, 5, 6, 6, 6, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,   &
+               8, 9,10,10,11,12,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 2,   &
+               2, 2, 2, 2, 3, 4, 4, 5, 7, 8, 9, 9, 9, 9, 9, 9,10,10,10,   &
+              10,10,10,10,11,12,12,12,12,11,11,10,10 /)
+          zrnfm(1:jpmois,100) = 82858.0
+                   
+
+          !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+          !                                      = 1.588668056E-6 kg/m2/s
+          !                                      = 17883.5586 km3/Year
+          !                                      = 0.567083955 Sverdrup
+      ENDIF
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca4'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      IF( kt == nit000 ) THEN
+         IF( nrunoff >= 1 ) THEN 
+            zbilan = 0.0 
+!OCL SCALAR
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0 ) THEN
+                  ii = mj0(iirnf(1,jr))
+                  ij = mi0(ijrnf(1,jr))
+                  ii = MAX( 2, MIN( ii, jpi-1 ) )
+                  ij = MAX( 2, MIN( ij, jpj-1 ) )
+!OCL SCALAR
+                  IF( tmask(ii,ij,1) <= 0.5 ) THEN 
+                     IF(lwp) WRITE(numout,*) 'Erreur riviere masquee   ', ii, ij, jr, criver(jr)
+                  ENDIF
+                  IF( tmask(ii-1,ij,1)*tmask(ii+1,ij,1)   &
+                     *tmask(ii,ij-1,1)*tmask(ii,ij+1,1) /= 0. )THEN 
+                     IF(lwp) WRITE(numout,*) 'Erreur riviere non cotiere ',ii, ij, jr, criver(jr)
+                  ENDIF
+                  DO nrnf1 = 1, jpmois
+                     zbilan = zbilan + zrnfm(nrnf1,jr) * tmask(ii,ij,1)
+                  END DO
+               ENDIF
+            END DO
+            IF(lwp) WRITE(numout,*) 'zrnfm (runoff) ', zero, zconv, rauw, SUM(zrnfm)
+            IF(lwp) THEN 
+               WRITE(numout,'("Total runoff : ",1E30.15)' ) zbilan
+               WRITE(numout,*) 'Run-off : POSITION and value '
+               WRITE(numout,*) 'ji jj glamt gphit annual mask 12-month '
+!OCL SCALAR
+               DO jr = 1, jpriv-1
+                  inbp = inb(jr)
+                  IF(inbp /= 0) THEN
+!OCL SCALAR
+                     DO jl = 1, inbp
+                        ii = mj0(iirnf(jl,jr))
+                        ij = mi0(ijrnf(jl,jr))
+                        WRITE(numout,'(2I3,1X,1A20,2X,2I4,2F7.1,1I3,1PE10.1,1I2,12E9.1)')   &
+                           jr, jl, criver(jr),   &
+                           ii, ij, glamt(ii,ij), gphit(ii,ij), inbp,   &
+                           SUM(zrnfm(1:jpmois,jr))/float(inbp),   &
+                           NINT(tmask(ii,ij,1)),   &
+                           zrnfm(1:jpmois,jr)/float(inbp)
+                     END DO
+                  ENDIF
+               END DO
+            ENDIF
+            IF(lwp) WRITE(numout,*) ' zrnfm (runoff) ', zero, zconv, rauw, SUM(zrnfm)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+         
+         i15 = nday/16
+         
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+            IF(lwp) WRITE(numout,*) 'total zrnfm ', SUM(zrnfm)
+            IF(lwp) WRITE(numout,*) 'total surface ', SUM(e1t*e2t*tmask(:,:,1))
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+!OCL SCALAR
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+!OCL SCALAR
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  ii = iirnf(jl,jr) - nimpp + 1 - jpizoom + 1
+                  ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom + 1
+                  iipt0 = MAX( 1, MIN( ii, jpi   ) )
+                  iipt1 = MAX( 0, MIN( ii, jpi-1 ) )
+                  ijpt0 = MAX( 1, MIN( ij, jpj   ) )
+                  ijpt1 = MAX( 0, MIN( ij, jpj-1 ) )
+                  DO jj = ijpt0, ijpt1
+                     DO ji = iipt0, iipt1
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                                      + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                                      +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)      
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! --> zrup1 (originally, = 1 = all upstream).
+                     ! ji,jj
+                     ii = iirnf(jl,jr) - nimpp + 1 - jpizoom - 1
+                     ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom - 1
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     iipt0 = MAX( 1, MIN( ii+1, jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1, jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     ijpt0 = MAX( 1, MIN( ij, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     iipt0 = MAX( 1, MIN( ii-1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     iipt0 = MAX( 1, MIN( ii+1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     iipt0 = MAX( 1, MIN( ii+2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     iipt0 = MAX( 1, MIN( ii-2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = 1.0
+            upsrnfz(2)   = 1.0
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+         ENDIF
+      ENDIF
+      
+      ! Upstream and centered scheme in the vicinity of some straits
+      
+      IF( kt == nit000 ) THEN
+
+         ! ORCA_R4 configuration :
+         ! Gibraltar Strait
+         DO jj = mj0(52), mj1(53)
+            DO ji = mi0(70), mi1(71)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+
+      ENDIF
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/ocesbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/ocesbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/ocesbc.F90	(revision 4536)
@@ -0,0 +1,29 @@
+MODULE ocesbc
+   !!======================================================================
+   !!                     ***  MODULE  ocesbc  ***
+   !!                     Ocean surface boundary conditions
+   !!======================================================================
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+   !! * Modules used
+   USE oce
+   USE lib_mpp
+   USE in_out_manager ! I/O manager
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      qt  ,         &  !: total surface heat flux (w/m2)
+      qsr ,         &  !: solar radiation (w/m2)
+      emp ,         &  !: evaporation minus precipitation (kg/m2/s = mm/s)
+      emps             !: evaporation - precipitation (free surface)
+
+
+   !!======================================================================
+END MODULE ocesbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbc_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbc_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbc_oce.F90	(revision 4536)
@@ -0,0 +1,23 @@
+MODULE sbc_oce
+   !!======================================================================
+   !!                       ***  MODULE  sbc_oce  ***
+   !! Surface module :   variables defined in core memory 
+   !!======================================================================
+   !! History :  9.0   !  06-06  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   !!----------------------------------------------------------------------
+   !!              Ocean Surface Boundary Condition fields
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   utau      !: sea surface i-stress (ocean referential)     [N/m2]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   vtau      !: sea surface j-stress (ocean referential)     [N/m2]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qns       !: sea heat flux: non solar                     [W/m2]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   qsr       !: sea heat flux:     solar                     [W/m2]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   emp       !: freshwater budget: volume flux               [Kg/m2/s]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   emps      !: freshwater budget: concentration/dillution   [Kg/m2/s]
+
+END MODULE sbc_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbcrnf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbcrnf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/sbcrnf.F90	(revision 4536)
@@ -0,0 +1,20 @@
+MODULE sbcrnf
+   !!======================================================================
+   !!                       ***  MODULE  sbcrnf  ***
+   !! Ocean forcing:  river runoff
+   !!=====================================================================
+   !! History :       !  00-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
+   !!            8.5  !  02-09  (G. Madec)  F90: Free form and module
+   !!            9.0  !  06-07  (G. Madec)  Surface module 
+   !!----------------------------------------------------------------------
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   rnfmsk      !: river mouth mask (hori.)
+   REAL(wp), PUBLIC, DIMENSION(jpk)     ::   rnfmsk_z    !: river mouth mask (vert.)
+
+   
+   !!======================================================================
+END MODULE sbcrnf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/taumod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/taumod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SBC/taumod.F90	(revision 4536)
@@ -0,0 +1,27 @@
+MODULE taumod
+   !!======================================================================
+   !!                       ***  MODULE  taumod  ***
+   !! Ocean forcing : stress at the the ocean surface
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   tau          : define the surface stress for the ocean
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce
+   USE lib_mpp
+   USE in_out_manager ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share modules variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &
+      taux, tauy          !: surface stress components 
+
+   !!======================================================================
+END MODULE taumod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SOL/sol_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SOL/sol_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/SOL/sol_oce.F90	(revision 4536)
@@ -0,0 +1,28 @@
+MODULE sol_oce
+   !!======================================================================
+   !!                    ***  MODULE  sol_oce  ***
+   !! Ocean solver :  solver variables defined in memory 
+   !!=====================================================================
+   !!
+   !! ** Purpose :   Define in memory solver variables
+   !!
+   !! History :
+   !!   9.0  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !!-----------------------------------
+   !! elliptic solver: SOR, PCG or FETI
+   !! ----------------------------------
+   INTEGER , PUBLIC ::      & !!: namsol   elliptic solver / island / free surface
+      nsolv    =    1          !: = 1/2/3/4 type of elliptic solver
+
+   !!----------------------------------------------------------------------
+END MODULE sol_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/trabbl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/trabbl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/trabbl.F90	(revision 4536)
@@ -0,0 +1,139 @@
+MODULE trabbl
+   !!==============================================================================
+   !!                       ***  MODULE  trabbl  ***
+   !! Ocean physics :  advective and/or diffusive bottom boundary layer scheme
+   !!==============================================================================
+#if   defined key_trabbl_dif   ||   defined key_trabbl_adv   || defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trabbl_dif'   or            diffusive bottom boundary layer
+   !!----------------------------------------------------------------------
+   !!   tra_bbl_dif  : update the active tracer trends due to the bottom
+   !!                  boundary layer (diffusive only)
+   !!   tra_bbl_init : initialization, namlist read, parameters control
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_bbl_dif    ! routine called by step.F90
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC ::            &  !!: * bbl namelist *
+      atrbbl = 1.e+3                  !: lateral coeff. for bottom boundary 
+      !                               !  layer scheme (m2/s)
+   REAL(wp) , PUBLIC , DIMENSION(jpi,jpj) :: &
+      bblx, bbly    ! Bottom boundary layer coefficients
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE tra_bbl_dif( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_bbl_dif  ***
+      !!
+      !! ** Purpose :   Compute the before tracer (t & s) trend associated 
+      !!      with the bottom boundary layer and add it to the general trend 
+      !!      of tracer equations. The bottom boundary layer is supposed to be
+      !!      a purely diffusive bottom boundary layer.
+      !!
+      !! ** Method  :   When the product grad( rho) * grad(h) < 0 (where grad 
+      !!      is an along bottom slope gradient) an additional lateral diffu-
+      !!      sive trend along the bottom slope is added to the general tracer
+      !!      trend, otherwise nothing is done.
+      !!      Second order operator (laplacian type) with variable coefficient
+      !!      computed as follow for temperature (idem on s): 
+      !!         difft = 1/(e1t*e2t*e3t) { di-1[ ahbt e2u*e3u/e1u di[ztb] ]
+      !!                                 + dj-1[ ahbt e1v*e3v/e2v dj[ztb] ] }
+      !!      where ztb is a 2D array: the bottom ocean temperature and ahtb
+      !!      is a time and space varying diffusive coefficient defined by:
+      !!         ahbt = zahbp    if grad(rho).grad(h) < 0
+      !!              = 0.       otherwise.
+      !!      Note that grad(.) is the along bottom slope gradient. grad(rho)
+      !!      is evaluated using the local density (i.e. referenced at the
+      !!      local depth). Typical value of ahbt is 2000 m2/s (equivalent to
+      !!      a downslope velocity of 20 cm/s if the condition for slope
+      !!      convection is satified)
+      !!      Add this before trend to the general trend (ta,sa) of the 
+      !!      botton ocean tracer point:
+      !!         ta = ta + difft
+      !!
+      !! ** Action  : - update (ta,sa) at the bottom level with the bottom
+      !!                boundary layer trend
+      !!              - save the trends in bbltrd ('key_diatrends')
+      !!
+      !! References :
+      !!     Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!
+      !! History :
+      !!   8.0  !  96-06  (L. Mortier)  Original code
+      !!   8.0  !  97-11  (G. Madec)  Optimization
+      !!   8.5  !  02-08  (G. Madec)  free form + modules
+      !!----------------------------------------------------------------------
+      !! * Arguments 
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_bbl_init
+
+   END SUBROUTINE tra_bbl_dif
+
+   SUBROUTINE tra_bbl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbl_init  ***
+      !!
+      !! ** Purpose :   Initialization for the bottom boundary layer scheme.
+      !!
+      !! ** Method  :   Read the nam_bbl namelist and check the parameters
+      !!      called by tra_bbl at the first timestep (nit000)
+      !!
+      !! History :
+      !!    8.5  !  02-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      NAMELIST/nam_bbl/ atrbbl
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nam_bbl : bottom boundary layer scheme
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, nam_bbl )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_bbl_init : * Diffusive Bottom Boundary Layer'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_bbl : set bbl parameters'
+         WRITE(numout,*)
+         WRITE(numout,*) '          bottom boundary layer coef.    atrbbl = ', atrbbl
+         WRITE(numout,*)
+      ENDIF
+ 
+   END SUBROUTINE tra_bbl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      No bottom boundary layer scheme
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_bbl_dif (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'tra_bbl_dif: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbl_dif
+#endif
+
+   !!======================================================================
+END MODULE trabbl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/traqsr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/traqsr.F90	(revision 4536)
@@ -0,0 +1,93 @@
+MODULE traqsr
+   !!======================================================================
+   !!                       ***  MODULE  traqsr  ***
+   !! Ocean physics: solar radiation penetration in the top ocean levels
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   tra_qsr      : trend due to the solar radiation penetration
+   !!   tra_qsr_init : solar radiation penetration initialization
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_qsr_init ! routine called by opa.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC ::   ln_traqsr = .TRUE.   !: qsr flag (Default=T)
+
+   !! * Module variables
+   REAL(wp), PUBLIC ::  & !!! * penetrative solar radiation namelist *
+      xsi1 = 0.35_wp    ! first depth of extinction 
+   LOGICAL , PUBLIC ::   ln_qsr_sms = .false. ! flag to use or not the biological fluxes for light
+
+
+CONTAINS
+
+   SUBROUTINE tra_qsr_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_init  ***
+      !!
+      !! ** Purpose :   Initialization for the penetrative solar radiation
+      !!
+      !! ** Method  :   The profile of solar radiation within the ocean is set
+      !!      from two length scale of penetration (xsr1,xsr2) and a ratio
+      !!      (rabs). These parameters are read in the namqsr namelist. The
+      !!      default values correspond to clear water (type I in Jerlov' 
+      !!      (1968) classification.
+      !!         called by tra_qsr at the first timestep (nit000)
+      !!
+      !! ** Action  : - initialize xsr1, xsr2 and rabs
+      !!
+      !! Reference :
+      !!   Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!
+      !! History :
+      !!   8.5  !  02-06  (G. Madec) Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      NAMELIST/nam_qsr/ ln_traqsr, xsi1
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nam_qsr : ratio and length of penetration
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, nam_qsr )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF( ln_traqsr  ) THEN
+        IF ( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_qsr_init : penetration of the surface solar radiation'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '    Namelist namqsr : set the parameter of penetration'
+         WRITE(numout,*) '        first depth of extinction        xsi1        = ',xsi1
+         WRITE(numout,*) '     Biological fluxes for light(Y/N) ln_qsr_sms  = ',ln_qsr_sms
+         WRITE(numout,*) ' '
+        END IF
+      ELSE
+        IF ( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_qsr_init : NO solar flux penetration'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+        END IF
+      ENDIF
+
+      IF( xsi1 < 0.e0  ) &
+         CALL ctl_stop( '              0<xsi1 not satisfied' )
+
+
+   END SUBROUTINE tra_qsr_init
+
+   !!======================================================================
+END MODULE traqsr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/zpshde.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/zpshde.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/TRA/zpshde.F90	(revision 4536)
@@ -0,0 +1,241 @@
+MODULE zpshde
+   !!==============================================================================
+   !!                       ***  MODULE zpshde   ***
+   !! z-coordinate - partial step : Horizontal Derivative
+   !!==============================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   zps_hde      :  Horizontal DErivative of T, S and rd at the last
+   !!                   ocean level (Z-coord. with Partial Steps)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space domain variables
+   USE oce             ! ocean dynamics and tracers variables
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE eosbn2          ! ocean equation of state
+   USE lbclnk          ! lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zps_hde          ! routine called by step.F90
+
+   !! * module variables
+   INTEGER, DIMENSION(jpi,jpj) ::   &
+      mbatu, mbatv      ! bottom ocean level index at U- and V-points
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zps_hde ( kt, ptem, psal, prd ,   &
+                            pgtu, pgsu, pgru,   &
+                            pgtv, pgsv, pgrv  )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde  ***
+      !!                    
+      !! ** Purpose :   Compute the horizontal derivative of T, S and rd
+      !!      at u- and v-points with a linear interpolation for z-coordinate
+      !!      with partial steps.
+      !!
+      !! ** Method  :   In z-coord with partial steps, scale factors on last 
+      !!      levels are different for each grid point, so that T, S and rd 
+      !!      points are not at the same depth as in z-coord. To have horizontal
+      !!      gradients again, we interpolate T and S at the good depth : 
+      !!      Linear interpolation of T, S   
+      !!         Computation of di(tb) and dj(tb) by vertical interpolation:
+      !!          di(t) = t~ - t(i,j,k) or t(i+1,j,k) - t~
+      !!          dj(t) = t~ - t(i,j,k) or t(i,j+1,k) - t~
+      !!         This formulation computes the two cases:
+      !!                 CASE 1                   CASE 2  
+      !!         k-1  ___ ___________   k-1   ___ ___________
+      !!                    Ti  T~                  T~  Ti+1
+      !!                  _____                        _____
+      !!         k        |   |Ti+1     k           Ti |   |
+      !!                  |   |____                ____|   |
+      !!              ___ |   |   |           ___  |   |   |
+      !!                  
+      !!      case 1->   e3w(i+1) >= e3w(i) ( and e3w(j+1) >= e3w(j) ) then
+      !!          t~ = t(i+1,j  ,k) + (e3w(i+1) - e3w(i)) * dk(Ti+1)/e3w(i+1)
+      !!        ( t~ = t(i  ,j+1,k) + (e3w(j+1) - e3w(j)) * dk(Tj+1)/e3w(j+1)  )
+      !!          or
+      !!      case 2->   e3w(i+1) <= e3w(i) ( and e3w(j+1) <= e3w(j) ) then
+      !!          t~ = t(i,j,k) + (e3w(i) - e3w(i+1)) * dk(Ti)/e3w(i )
+      !!        ( t~ = t(i,j,k) + (e3w(j) - e3w(j+1)) * dk(Tj)/e3w(j ) )
+      !!          Idem for di(s) and dj(s)          
+      !!
+      !!      For rho, we call eos_insitu_2d which will compute rd~(t~,s~) at 
+      !!      the good depth zh from interpolated T and S for the different
+      !!      formulation of the equation of state (eos).
+      !!      Gradient formulation for rho :
+      !!          di(rho) = rd~ - rd(i,j,k) or rd (i+1,j,k) - rd~
+      !!
+      !! ** Action  : - pgtu, pgsu, pgru: horizontal gradient of T, S
+      !!                and rd at U-points 
+      !!              - pgtv, pgsv, pgrv: horizontal gradient of T, S
+      !!                and rd at V-points 
+      !!
+      !! History :
+      !!   8.5  !  02-04  (A. Bozec)  Original code
+      !!   8.5  !  02-08  (G. Madec E. Durand)  Optimization and Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem, psal, prd            ! 3D T, S and rd fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         pgtu, pgsu, pgru,       &  ! horizontal grad. of T, S and rd at u- 
+         pgtv, pgsv, pgrv           ! and v-points of the partial step level
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,       &  ! Dummy loop indices
+                   iku,ikv          ! partial step level at u- and v-points
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zti, ztj, zsi, zsj,     &  ! interpolated value of T, S 
+         zri, zrj,               &  ! and rd
+         zhgi, zhgj                 ! depth of interpolation for eos2d
+      REAL(wp) ::   &
+         ze3wu, ze3wv,           &  ! temporary scalars
+         zmaxu1, zmaxu2,         &  !    "         "
+         zmaxv1, zmaxv2             !    "         "
+
+      ! Initialization (first time-step only): compute mbatu and mbatv
+      IF( kt == nit000 ) THEN
+         mbatu(:,:) = 0
+         mbatv(:,:) = 0
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               mbatu(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1, 2 )
+               mbatv(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1, 2 )
+            END DO
+         END DO
+         zti(:,:) = FLOAT( mbatu(:,:) )
+         ztj(:,:) = FLOAT( mbatv(:,:) )
+         ! lateral boundary conditions: T-point, sign unchanged
+         CALL lbc_lnk( zti , 'U', 1. )
+         CALL lbc_lnk( ztj , 'V', 1. )
+         mbatu(:,:) = MAX( INT( zti(:,:) ), 2 )
+         mbatv(:,:) = MAX( INT( ztj(:,:) ), 2 )
+      ENDIF
+      
+
+      ! Interpolation of T and S at the last ocean level
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ! last level
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+            zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+            zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+            zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+            ! i- direction
+
+            IF( ze3wu >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji+1,jj,iku) + zmaxu1 * ( ptem(ji+1,jj,iku-1) - ptem(ji+1,jj,iku) )
+               zsi(ji,jj) = psal(ji+1,jj,iku) + zmaxu1 * ( psal(ji+1,jj,iku-1) - psal(ji+1,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji,jj,iku)
+               ! gradient of T and S
+               pgtu(ji,jj) = umask(ji,jj,1) * ( zti(ji,jj) - ptem(ji,jj,iku) )
+               pgsu(ji,jj) = umask(ji,jj,1) * ( zsi(ji,jj) - psal(ji,jj,iku) )
+
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji,jj,iku) + zmaxu2 * ( ptem(ji,jj,iku-1) - ptem(ji,jj,iku) )
+               zsi(ji,jj) = psal(ji,jj,iku) + zmaxu2 * ( psal(ji,jj,iku-1) - psal(ji,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji+1,jj,iku)
+               ! gradient of T and S 
+               pgtu(ji,jj) = umask(ji,jj,1) * ( ptem(ji+1,jj,iku) - zti (ji,jj) )
+               pgsu(ji,jj) = umask(ji,jj,1) * ( psal(ji+1,jj,iku) - zsi (ji,jj) )
+            ENDIF
+
+            ! j- direction
+
+            IF( ze3wv >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj+1,ikv) + zmaxv1 * ( ptem(ji,jj+1,ikv-1) - ptem(ji,jj+1,ikv) )
+               zsj(ji,jj) = psal(ji,jj+1,ikv) + zmaxv1 * ( psal(ji,jj+1,ikv-1) - psal(ji,jj+1,ikv) )
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj,ikv) 
+               ! gradient of T and S
+               pgtv(ji,jj) = vmask(ji,jj,1) * ( ztj(ji,jj) - ptem(ji,jj,ikv) )
+               pgsv(ji,jj) = vmask(ji,jj,1) * ( zsj(ji,jj) - psal(ji,jj,ikv) )
+
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj,ikv) + zmaxv2 * ( ptem(ji,jj,ikv-1) - ptem(ji,jj,ikv) )
+               zsj(ji,jj) = psal(ji,jj,ikv) + zmaxv2 * ( psal(ji,jj,ikv-1) - psal(ji,jj,ikv) ) 
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj+1,ikv) 
+               ! gradient of T and S
+               pgtv(ji,jj) = vmask(ji,jj,1) * ( ptem(ji,jj+1,ikv) - ztj(ji,jj) )
+               pgsv(ji,jj) = vmask(ji,jj,1) * ( psal(ji,jj+1,ikv) - zsj(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Compute interpolated rd from zti, zsi, ztj, zsj for the 2 cases at the depth of the partial
+      ! step and store it in  zri, zrj for each  case
+      CALL eos( zti, zsi, zhgi, zri )
+      CALL eos( ztj, zsj, zhgj, zrj )
+
+
+      ! Gradient of density at the last level 
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            IF( ze3wu >= 0. ) THEN    ! i-direction: case 1
+               pgru(ji,jj) = umask(ji,jj,1) * ( zri(ji,jj) - prd(ji,jj,iku) )
+            ELSE                      ! i-direction: case 2
+               pgru(ji,jj) = umask(ji,jj,1) * ( prd(ji+1,jj,iku) - zri(ji,jj) )
+            ENDIF
+            IF( ze3wv >= 0. ) THEN    ! j-direction: case 1
+               pgrv(ji,jj) = vmask(ji,jj,1) * ( zrj(ji,jj) - prd(ji,jj,ikv) )  
+            ELSE                      ! j-direction: case 2
+               pgrv(ji,jj) = vmask(ji,jj,1) * ( prd(ji,jj+1,ikv) - zrj(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Lateral boundary conditions on each gradient
+      CALL lbc_lnk( pgtu , 'U', -1. )   ;   CALL lbc_lnk( pgtv , 'V', -1. )
+      CALL lbc_lnk( pgsu , 'U', -1. )   ;   CALL lbc_lnk( pgsv , 'V', -1. )
+      CALL lbc_lnk( pgru , 'U', -1. )   ;   CALL lbc_lnk( pgrv , 'V', -1. )
+
+   END SUBROUTINE zps_hde
+
+   !!======================================================================
+END MODULE zpshde
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.h90	(revision 4536)
@@ -0,0 +1,58 @@
+   !! 
+   !!         ZDF.MATRIXSOLVER
+   !!       ********************
+   !! 
+   !! Matrix inversion
+   !!----------------------------------------------------------------------
+   !!   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+   !!
+   !!        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+   !!        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+   !!        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+   !!        (        ...               )( ...  ) ( ...  )
+   !!        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+   !!
+   !!   m is decomposed in the product of an upper and lower triangular
+   !!   matrix
+   !!   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+   !!   The second member is in 2d array zwy
+   !!   The solution is in 2d array zwx
+   !!   The 2d arry zwt and zwz are work space arrays
+   !!
+   !!   N.B. the starting vertical index (ikst) is equal to 1 except for
+   !!   the resolution of tke matrix where surface tke value is prescribed
+   !!   so that ikstrt=2.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+      ikstp1 = ikst + 1
+      ikenm2 = jpk - 2
+      DO ji = 2, jpim1
+         zwt(ji,ikst) = zwd(ji,ikst)
+      END DO
+      DO jk = ikstp1, jpkm1
+         DO ji = 2, jpim1
+            zwt(ji,jk) = zwd(ji,jk) - zwi(ji,jk) * zws(ji,jk-1) / zwt(ji,jk-1)
+         END DO
+      END DO
+      DO ji = 2, jpim1
+         zwz(ji,ikst) = zwy(ji,ikst)
+      END DO
+      DO jk = ikstp1, jpkm1
+         DO ji = 2, jpim1
+            zwz(ji,jk) = zwy(ji,jk) - zwi(ji,jk) / zwt(ji,jk-1) * zwz(ji,jk-1)
+         END DO
+      END DO
+      DO ji = 2, jpim1
+         zwx(ji,jpkm1) = zwz(ji,jpkm1) / zwt(ji,jpkm1)
+      END DO
+      DO jk = ikenm2, ikst, -1
+         DO ji = 2, jpim1
+            zwx(ji,jk) =( zwz(ji,jk) - zws(ji,jk) * zwx(ji,jk+1) ) / zwt(ji,jk)
+         END DO
+      END DO
+      
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.vopt.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.vopt.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf.matrixsolver.vopt.h90	(revision 4536)
@@ -0,0 +1,69 @@
+   !! 
+   !!         ZDF.MATRIXSOLVER
+   !!       ********************
+   !! 
+   !! Matrix inversion
+   !!----------------------------------------------------------------------
+   !!   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+   !!
+   !!        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+   !!        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+   !!        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+   !!        (        ...               )( ...  ) ( ...  )
+   !!        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+   !!
+   !!   m is decomposed in the product of an upper and lower triangular
+   !!   matrix
+   !!   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+   !!   The second member is in 2d array zwy
+   !!   The solution is in 2d array zwx
+   !!   The 3d arry zwt is a work space array
+   !!   zwy is used and then used as a work space array : its value is modified!
+   !!
+   !!   N.B. the starting vertical index (ikst) is equal to 1 except for
+   !!   the resolution of tke matrix where surface tke value is prescribed
+   !!   so that ikstrt=2.
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+      ikstp1 = ikst + 1
+      ikenm2 = jpk - 2
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,ikst) = zwd(ji,jj,ikst)
+         END DO
+      END DO
+
+      DO jk = ikstp1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      DO jk = ikstp1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwy(ji,jj,jk) = zwy(ji,jj,jk) - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * zwy(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwx(ji,jj,jpkm1) = zwy(ji,jj,jpkm1) / zwt(ji,jj,jpkm1)
+         END DO
+      END DO
+
+      DO jk = ikenm2, ikst, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwx(ji,jj,jk) = ( zwy(ji,jj,jk) - zws(ji,jj,jk) * zwx(ji,jj,jk+1) ) / zwt(ji,jj,jk)
+            END DO
+         END DO
+      END DO
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdf_oce.F90	(revision 4536)
@@ -0,0 +1,35 @@
+MODULE zdf_oce
+   !!======================================================================
+   !!              ***  MODULE  zdf_oce  ***
+   !! Ocean physics : define vertical mixing variables
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   zdf_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! mesh and scale factors
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share Module variables
+
+   REAL(wp), PUBLIC ::   & !!: namzdf   vertical diffusion
+      avt0  = 1.e-5_wp     !: vertical eddy diffusivity (m2/s)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      avt                   !: vertical diffusivity coeff. at w-point
+ 
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &   !:
+      avtb            !: background profile of avm and avt
+
+   LOGICAL, PUBLIC ::    &   !:
+      ln_zdfnpc        = .FALSE.        !: convection: non-penetrative convection flag
+ 
+   !!======================================================================
+END MODULE zdf_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfddm.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfddm.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfddm.F90	(revision 4536)
@@ -0,0 +1,140 @@
+MODULE zdfddm
+   !!======================================================================
+   !!                       ***  MODULE  zdfddm  ***
+   !! Ocean physics : double diffusion mixing parameterization
+   !!======================================================================
+#if defined key_zdfddm   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdfddm' :                                     double diffusion
+   !!----------------------------------------------------------------------
+   !!   zdf_ddm       : compute the Ks for salinity
+   !!   zdf_ddm_init  : read namelist and control the parameters
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_ddm     ! called by step.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfddm = .TRUE.    !: double diffusive mixing flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      avs ,               &  !: salinity vertical diffusivity coeff. at w-point
+      rrau                   !: heat/salt buoyancy flux ratio
+
+   !! * Module variables
+   REAL(wp) ::            & !!! * double diffusive mixing namelist *
+      avts  = 1.e-4_wp      ! maximum value of avs for salt fingering
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE zdf_ddm( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_ddm  ***
+      !!                    
+      !! ** Purpose :   Add to the vertical eddy diffusivity coefficient the 
+      !!      effect of salt fingering and diffusive convection. 
+      !!
+      !! ** Method  :   Diapycnal mixing is increased in case of double
+      !!      diffusive mixing (i.e. salt fingering and diffusive layering)
+      !!      following Merryfield et al. (1999). The rate of double diffusive 
+      !!      mixing depend on the buoyancy ratio: Rrau=alpha/beta dk[T]/dk[S]
+      !!      which is computed in rn2.F
+      !!         * salt fingering (Schmitt 1981):
+      !!      for Rrau > 1 and rn2 > 0 : zavfs = avts / ( 1 + (Rrau/hsbfr)^6 )
+      !!      for Rrau > 1 and rn2 > 0 : zavfs = O
+      !!      otherwise                : zavft = 0.7 zavs / Rrau
+      !!         * diffusive layering (Federov 1988):
+      !!      for 0< Rrau < 1 and rn2 > 0 : zavdt = 1.3635e-6  
+      !!                                 * exp( 4.6 exp(-0.54 (1/Rrau-1) ) )
+      !!      otherwise                   : zavdt = 0 
+      !!      for .5 < Rrau < 1 and rn2 > 0 : zavds = zavdt (1.885 Rrau -0.85)
+      !!      for  0 < Rrau <.5 and rn2 > 0 : zavds = zavdt 0.15 Rrau      
+      !!      otherwise                     : zavds = 0 
+      !!         * update the eddy diffusivity:
+      !!      avt = avt + zavft + zavdt
+      !!      avs = avs + zavfs + zavds
+      !!      avmu, avmv are required to remain at least above avt and avs.
+      !!      
+      !! ** Action  :   avt, avs : update vertical eddy diffusivity coef.
+      !!                           for temperature and salinity
+      !!
+      !! References :
+      !!      Merryfield et al., JPO, 29, 1124-1142, 1999.
+      !! History :
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step indexocean time step
+
+      !!----------------------------------------------------------------------
+
+
+      IF ( kt == nit000 )   CALL zdf_ddm_init          ! Initialization (first time-step only)
+
+
+   END SUBROUTINE zdf_ddm
+   
+   
+   SUBROUTINE zdf_ddm_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_ddm_init  ***
+      !!
+      !! ** Purpose :   Initialization of double diffusion mixing scheme
+      !!
+      !! ** Method  :   Read the nam_ddm namelist and check the parameter values
+      !!      called by zdf_ddm at the first timestep (nit000)
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      NAMELIST/nam_ddm/ avts
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nam_ddm : double diffusion mixing scheme
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, nam_ddm )
+
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_ddm : double diffusive mixing'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_ddm : set dd mixing parameter'
+         WRITE(numout,*) '             maximum avs for dd mixing      avts   = ', avts
+         WRITE(numout,*)
+      ENDIF
+
+   END SUBROUTINE zdf_ddm_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :          Dummy module          No double diffusion
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfddm = .FALSE.   !: double diffusion flag
+CONTAINS
+   SUBROUTINE zdf_ddm( kt )           ! Dummy routine
+      WRITE(*,*) 'zdf_ddm: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_ddm
+#endif
+
+   !!======================================================================
+END MODULE zdfddm
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfini.F90	(revision 4536)
@@ -0,0 +1,65 @@
+MODULE zdfini
+   !!======================================================================
+   !!              ***  MODULE  zdfini  ***
+   !! Ocean physics : define vertical mixing variables
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   zdf_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! mesh and scale factors
+   USE zdf_oce         ! TKE vertical mixing          
+   USE ldfslp          ! ???
+
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC zdf_init          ! routine called by opa.F90
+   
+CONTAINS
+
+   SUBROUTINE zdf_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_init  ***
+      !! 
+      !! ** Purpose :   initializations of the vertical ocean physics
+      !!
+      !! ** Method  :   Read namelist nam_zdf, control cpp keys
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code from inimix
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      !! * Namelist
+      NAMELIST/nam_zdf/ avt0, ln_zdfnpc
+
+      ! Read nam_zdf namelist : vertical mixing parameters
+      ! --------------------
+      REWIND( numnam )
+      READ  ( numnam, nam_zdf )
+
+      ! Parameter print
+      ! ---------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_init: vertical physics'
+         WRITE(numout,*) '~~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_zdf : set vertical mixing mixing parameters'
+         WRITE(numout,*) '             non-penetrative convection       ln_zdfnpc = ', ln_zdfnpc
+         WRITE(numout,*) '             vertical eddy diffusivity           avt0   = ', avt0
+      ENDIF
+
+   END SUBROUTINE zdf_init
+
+   !!======================================================================
+END MODULE zdfini
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfmxl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfmxl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ZDF/zdfmxl.F90	(revision 4536)
@@ -0,0 +1,242 @@
+MODULE zdfmxl
+   !!======================================================================
+   !!                       ***  MODULE  zdfmxl  ***
+   !! Ocean physics: mixed layer depth 
+   !!======================================================================
+   !! History :
+   !!   9.0  !  03-08  (G. Madec)  OpenMP/autotasking optimization
+   !!----------------------------------------------------------------------
+   !!   zdf_mxl      : Compute the turbocline and mixed layer depths.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_mxl           ! called by step.F90
+
+   !! * Shared module variables
+   INTEGER, PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      nmln                  !: number of level in the mixed layer
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      hmld ,             &  !: mixing layer depth (turbocline) (m)
+      hmlp ,             &  !: mixed layer depth  (rho=rho0+zdcrit) (m)
+      hmlpt                 !: mixed layer depth at t-points (m)
+
+   !! * module variables
+   REAL(wp) ::   &
+      avt_c = 5.e-4_wp,  &  ! Kz criterion for the turbocline depth
+      rho_c = 0.01_wp       ! density criterion for mixed layer depth
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp'                                   j-k-i loop (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zdf_mxl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zdfmxl  ***
+      !!                   
+      !! ** Purpose :   Compute the turbocline depth and the mixed layer depth
+      !!      with a density criteria.
+      !!
+      !! ** Method  :   The turbocline depth is the depth at which the vertical 
+      !!      eddy diffusivity coefficient (resulting from the vertical physics
+      !!      alone, not the isopycnal part, see trazdf.F) fall below a given
+      !!      value defined locally (avt_c here taken equal to 5 cm/s2)
+      !!
+      !! ** Action  :
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   ik             ! temporary integer
+      INTEGER, DIMENSION(jpi,jpj) ::   &
+         imld                     ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'zdf_mxl : mixed layer depth, j-k-i loops'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      !                                                ! ===============
+      DO jj = 1, jpj                                   !  Vertical slab
+         !                                             ! ===============
+
+         ! 1. Turbocline depth
+         ! -------------------
+         ! last w-level at which avt<avt_c (starting from the bottom jk=jpk)
+         ! (since avt(.,.,jpk)=0, we have jpk=< imld =< 2 )
+         DO jk = jpk, 2, -1
+            DO ji = 1, jpi
+               IF( avt(ji,jj,jk) < avt_c ) imld(ji,jj) = jk 
+            END DO
+         END DO
+
+         ! Turbocline depth and sub-turbocline temperature
+         DO ji = 1, jpi
+            ik = imld(ji,jj)
+            hmld (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+         END DO
+
+!!gm idea
+!!   
+!!gm     DO jk = jpk, 2, -1
+!!gm        DO ji = 1, jpi
+!!gm           IF( avt(ji,jj,jk) < avt_c ) hmld(ji,jj) = fsdepw(ji,jj,jk) * tmask(ji,jj,1)
+!!gm        END DO
+!!gm     END DO
+!!gm
+
+         ! 2. Mixed layer depth
+         ! --------------------
+         ! Initialization to the number of w ocean point mbathy
+         nmln(:,jj) = mbathy(:,jj)
+
+         ! Last w-level at which rhop>=rho surf+rho_c (starting from jpk-1)
+         ! (rhop defined at t-point, thus jk-1 for w-level just above)
+         DO jk = jpkm1, 2, -1
+            DO ji = 1, jpi
+               IF( rhop(ji,jj,jk) > rhop(ji,jj,1) + rho_c )   nmln(ji,jj) = jk
+            END DO
+         END DO
+
+         ! Mixed layer depth
+         DO ji = 1, jpi
+            ik = nmln(ji,jj)
+            hmlp (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+            hmlpt(ji,jj) = fsdept(ji,jj,ik-1)
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmld, clinfo2=' hmld : ', ovlap=1 )
+
+   END SUBROUTINE zdf_mxl
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                         k-j-i loop
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zdf_mxl( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdfmxl  ***
+      !!                   
+      !! ** Purpose :   Compute the turbocline depth and the mixed layer depth
+      !!      with density criteria.
+      !!
+      !! ** Method  :   The turbocline depth is the depth at which the vertical
+      !!      eddy diffusivity coefficient (resulting from the vertical physics
+      !!      alone, not the isopycnal part, see trazdf.F) fall below a given
+      !!      value defined locally (avt_c here taken equal to 5 cm/s2)
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        !  94-11  (M. Imbard)  Original code
+      !!   8.0  !  96-01  (E. Guilyardi)  sub mixed layer temp.
+      !!   8.1  !  97-07  (G. Madec)  optimization
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   ik             ! temporary integer
+      INTEGER, DIMENSION(jpi,jpj) ::   &
+         imld                     ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'zdf_mxl : mixed layer depth'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+
+      ! 1. Turbocline depth
+      ! -------------------
+      ! last w-level at which avt<avt_c (starting from the bottom jk=jpk)
+      ! (since avt(.,.,jpk)=0, we have jpk=< imld =< 2 )
+      DO jk = jpk, 2, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( avt(ji,jj,jk) < avt_c ) imld(ji,jj) = jk 
+            END DO
+         END DO
+      END DO
+
+      ! Turbocline depth and sub-turbocline temperature
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ik = imld(ji,jj)
+            hmld (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+         END DO
+      END DO
+
+!!gm idea
+!!   
+!!gm  DO jk = jpk, 2, -1
+!!gm     DO jj = 1, jpj
+!!gm        DO ji = 1, jpi
+!!gm           IF( avt(ji,jj,jk) < avt_c ) hmld(ji,jj) = fsdepw(ji,jj,jk) * tmask(ji,jj,1)
+!!gm        END DO
+!!gm     END DO
+!!gm  END DO
+!!gm
+
+      ! 2. Mixed layer depth
+      ! --------------------
+      ! Initialization to the number of w ocean point mbathy
+      nmln(:,:) = mbathy(:,:)
+
+      ! Last w-level at which rhop>=rho surf+rho_c (starting from jpk-1)
+      ! (rhop defined at t-point, thus jk-1 for w-level just above)
+      DO jk = jpkm1, 2, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( rhop(ji,jj,jk) > rhop(ji,jj,1) + rho_c )   nmln(ji,jj) = jk
+            END DO
+         END DO
+      END DO
+
+      ! Mixed layer depth
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ik = nmln(ji,jj)
+            hmlp (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+            hmlpt(ji,jj) = fsdept(ji,jj,ik-1)
+         END DO
+      END DO
+
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmld, clinfo2=' hmld : ', ovlap=1 )
+
+   END SUBROUTINE zdf_mxl
+#endif
+
+   !!======================================================================
+END MODULE zdfmxl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ctlopn.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ctlopn.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ctlopn.f90	(revision 4536)
@@ -0,0 +1,157 @@
+   SUBROUTINE ctlopn ( knum, cdfile, cdstat, cdform, cdacce,   &
+                       klengh, kout, ldwp, krequ )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctlopn  ***
+      !!
+      !! ** Purpose :   Open file and check if required file is available.
+      !!
+      !! ** Method  :   Fortan open
+      !!
+      !! History :
+      !!        !  95-12  (G. Madec)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      USE in_out_manager 
+
+      IMPLICIT NONE
+
+      INTEGER, INTENT( out ) ::   &
+         knum      ! logical unit to open
+      INTEGER, INTENT( in ) ::   &
+         krequ,    & ! =1 file required (stop if not exist)
+         !           ! =0 file not required (create the file if does not exist)
+         kout,     & ! number of logical units for write
+         klengh      ! record length
+
+      INTEGER ::   iost
+      CHARACTER (len=* ), INTENT( in ) ::   &
+         cdacce,   & ! access specifier
+         cdform,   & ! formatting specifier
+         cdstat      ! disposition specifier
+      CHARACTER (len=* ), INTENT( in ) ::   &
+         cdfile      ! file name to open
+
+      LOGICAL ::  ldwp   ! boolean term for print
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+      knum=getunit()
+
+      ! 1. Required file
+      ! ----------------
+
+      IF( krequ == 1 ) THEN
+
+         iost=0
+         IF( cdacce(1:6) == 'DIRECT' )  THEN
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
+         ELSE
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, ERR=100, IOSTAT=iost)
+         ENDIF
+         IF( iost == 0 ) THEN
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' 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: ', cdfile
+               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 'ctlopn bad opening'
+         ENDIF
+         
+         
+         ! 2. Not required, file create if not exist
+         ! -----------------------------------------
+         
+      ELSEIF( krequ == 0 ) THEN
+
+         iost = 0
+         IF( cdacce(1:6) == 'DIRECT' ) THEN
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, RECL=klengh, ERR=200, IOSTAT=iost )
+         ELSE
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, ERR=200, IOSTAT=iost )
+         ENDIF
+         IF(iost == 0) THEN
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' open ok'
+               WRITE(kout,*) '     unit   = ', knum
+               WRITE(kout,*) '     status = ', cdstat
+               WRITE(kout,*) '     form   = ', cdform
+               WRITE(kout,*) '     access = ', cdacce
+               WRITE(kout,*)
+            ENDIF
+         ENDIF
+200      CONTINUE
+         IF( iost /= 0 ) THEN
+            iost = 0
+            IF(ldwp) THEN
+               WRITE(kout,*)
+               WRITE(kout,*) '     ===>>>> : file ', cdfile,   &
+                  ' does not exist: it is created'
+               WRITE(kout,*) ' =======   ===  '
+            ENDIF
+            IF( cdacce(1:6) == 'DIRECT' ) THEN
+               OPEN( UNIT=knum, FILE=cdfile, FORM=cdform,   &
+                  ACCESS=cdacce, STATUS=cdstat,   &
+                  RECL=klengh, ERR=210, IOSTAT=iost )
+            ELSE
+               OPEN( UNIT=knum, FILE=cdfile, FORM=cdform,   &
+                  ACCESS=cdacce, STATUS=cdstat, ERR=210,   &
+                  IOSTAT=iost )
+            ENDIF
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' open ok'
+               WRITE(kout,*) '     unit   = ', knum
+               WRITE(kout,*) '     status = ', cdstat
+               WRITE(kout,*) '     form   = ', cdform
+               WRITE(kout,*) '     access = ', cdacce
+               WRITE(kout,*)
+            ENDIF
+210         CONTINUE
+            IF( iost /= 0 ) THEN
+               IF(ldwp) THEN
+                  WRITE(kout,*) ' logical unit ',knum,' iostat = ', iost
+                  WRITE(kout,*) ' we stop. verify the file ', cdfile
+                  WRITE(kout,*)
+               ENDIF
+               STOP '001'
+            ENDIF
+         ENDIF
+         
+      ELSE
+         
+         IF(ldwp) THEN
+            WRITE(kout,*)
+            WRITE(kout,*) ' ctlopn : invalid option, krequ = ', krequ
+            WRITE(kout,*) ' ~~~~~~   call for file ', cdfile
+            WRITE(kout,*)
+         ENDIF
+
+
+         STOP 'ctlopn invalid option'
+      ENDIF
+      
+   END SUBROUTINE ctlopn
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/daymod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/daymod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/daymod.F90	(revision 4536)
@@ -0,0 +1,159 @@
+MODULE daymod
+   !!======================================================================
+   !!                       ***  MODULE  daymod  ***
+   !! Ocean        :  calendar 
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   day        : calendar
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC day        ! called by step.F90
+
+   !! * Shared module variables
+   INTEGER , PUBLIC ::   &  !:
+      nyear     ,   &  !: current year
+      nmonth    ,   &  !: current month
+      nday      ,   &  !: current day of the month
+      nday_year ,   &  !: curent day counted from jan 1st of the current year
+      ndastp           !: time step date in year/month/day aammjj
+   REAL(wp), PUBLIC ::   &  !:
+       adatrj   ,   &  !: number of elapsed days since the begining of the run
+       adatrj0         !: value of adatrj at nit000-1 (before the present run).
+       !               !  it is the accumulated duration of previous runs
+       !               !  that may have been run with different time steps.
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE day( kt )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE day  ***
+      !! 
+      !! ** Purpose :   Compute the date with a day iteration IF necessary.
+      !!
+      !! ** Method  : - ???
+      !!
+      !! ** Action  : - nyear     : current year
+      !!              - nmonth    : current month of the year nyear
+      !!              - nday      : current day of the month nmonth
+      !!              - nday_year : current day of the year nyear
+      !!              - ndastp    : =nyear*10000+nmonth*100+nday
+      !!              - adatrj    : date in days since the beginning of the run
+      !!
+      !! History :
+      !!        !  94-09  (M. Pontaud M. Imbard)  Original code
+      !!        !  97-03  (O. Marti)
+      !!        !  97-05  (G. Madec) 
+      !!        !  97-08  (M. Imbard)
+      !!   9.0  !  03-09  (G. Madec)  F90 + nyear, nmonth, nday
+      !!        !  04-01  (A.M. Treguier) new calculation based on adatrj
+      !!----------------------------------------------------------------------      
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step indices
+
+      !! * Local declarations
+      INTEGER  ::   js                   ! dummy loop indice
+      INTEGER  ::   iend, iday0, iday1   ! temporary integers
+      REAL(wp) :: zadatrjn, zadatrjb     ! adatrj at timestep kt-1 and kt-2 
+      CHARACTER (len=25) :: charout
+      !!----------------------------------------------------------------------
+
+      ! 0.  initialization of adatrj0 and nday, nmonth,nyear, nday_year.
+      !     ndastp has been initialized in domain.F90 or restart.F90
+      !-----------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+
+         IF( .NOT.ln_rstart )   adatrj0 = 0.e0      ! adatrj0 initialized in rst_read when restart 
+
+         adatrj  = adatrj0
+         nyear   =   ndastp / 10000
+         nmonth  = ( ndastp - (nyear * 10000) ) / 100
+         nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
+
+         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
+         nday_year =  nday
+         !                               ! accumulates days of previous months of this year
+         DO js = 1, nmonth-1
+            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+               nday_year = nday_year + nbiss(js)
+            ELSE
+               nday_year = nday_year + nobis(js)
+            ENDIF
+         END DO
+
+      ENDIF
+
+      ! I.  calculates adatrj, zadatrjn, zadatrjb.
+      ! ------------------------------------------------------------------
+
+      adatrj    = adatrj0 + ( kt - nit000 + 1 ) * rdttra(1) / rday
+      zadatrjn  = adatrj0 + ( kt - nit000     ) * rdttra(1) / rday
+      zadatrjb  = adatrj0 + ( kt - nit000 - 1 ) * rdttra(1) / rday
+
+
+      ! II.  increment the date.  The date corresponds to 'now' variables (kt-1),
+      !      which is the time step of forcing fields. 
+      !      Do not do this at nit000  unless nrstdt= 2
+      !      In that case ndastp (read in restart) was for step nit000-2
+      ! -------------------------------------------------------------------
+
+      iday0 = INT( zadatrjb )
+      iday1 = INT( zadatrjn )
+
+      IF( iday1 - iday0 >= 1 .AND. ( kt /= nit000 .OR. nrstdt == 2 ) ) THEN
+
+         ! increase calendar
+         nyear  =   ndastp / 10000
+         nmonth = ( ndastp - (nyear * 10000) ) / 100
+         nday   =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
+         nday = nday + 1
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            iend = nbiss(nmonth)
+         ELSEIF( nleapy > 1 ) THEN 
+            iend = nleapy
+         ELSE 
+            iend = nobis(nmonth)
+         ENDIF
+         IF( nday == iend + 1 ) THEN
+            nday  = 1
+            nmonth = nmonth + 1
+            IF( nmonth == 13 ) THEN
+               nmonth  = 1
+               nyear = nyear + 1
+            ENDIF
+         ENDIF
+         ndastp = nyear * 10000 + nmonth * 100 + nday
+
+         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
+         nday_year =  nday
+         !                                ! accumulates days of previous months of this year
+         DO js = 1, nmonth-1
+            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+               nday_year = nday_year + nbiss(js)
+            ELSE
+               nday_year = nday_year + nobis(js)
+            ENDIF
+         END DO
+
+         IF(lwp) WRITE(numout,*)' ==============>> time-step =', kt, ' New day, DATE= ',   &
+            &                   nyear, '/', nmonth, '/', nday, 'nday_year:', nday_year
+      ENDIF
+
+   END SUBROUTINE day
+
+   !!======================================================================
+END MODULE daymod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/dtadyn.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/dtadyn.F90	(revision 4536)
@@ -0,0 +1,924 @@
+MODULE dtadyn
+   !!======================================================================
+   !!                       ***  MODULE  dtadyn  ***
+   !! OFFLINE : interpolation of the physical fields
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dta_dyn_init : initialization, namelist read, and parameters control
+   !!   dta_dyn      : Interpolation of the fields
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE ocesbc
+   USE ldfslp
+   USE blk_oce
+   USE ldfeiv          ! eddy induced velocity coef.      (ldf_eiv routine)
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE zdfmxl
+   USE trabbl          ! tracers: bottom boundary layer
+   USE ocfzpt
+   USE zdfddm          ! vertical  physics: double diffusion
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC dta_dyn_init   ! called by opa.F90
+   PUBLIC dta_dyn        ! called by step.F90
+
+   !! * Module variables
+   INTEGER , PUBLIC, PARAMETER :: jpflx = 13
+   INTEGER , PUBLIC, PARAMETER :: &
+      jptaux = 1 , & ! indice in flux for taux
+      jptauy = 2 , & ! indice in flux for tauy
+      jpwind = 3 , & ! indice in flux for wspd
+      jpemp = 4  , & ! indice in flux for E-P
+      jpice = 5  , & ! indice in flux for ice concentration
+      jpqsr = 6      ! indice in flux for shortwave heat flux 
+
+   LOGICAL , PUBLIC :: &
+      lperdyn = .TRUE. , & ! boolean for periodic fields or not
+      lfirdyn = .TRUE.     ! boolean for the first call or not
+
+   INTEGER , PUBLIC :: &
+      ndtadyn = 12 ,  & ! Number of dat in one year
+      ndtatot = 12 ,  & ! Number of data in the input field
+      nsptint = 1 ,   & ! type of spatial interpolation
+      nficdyn = 2       ! number of dynamical fields 
+
+   INTEGER ::     &
+      ndyn1, ndyn2 , &
+      nlecoff = 0  , & ! switch for the first read
+      numfl_t, numfl_u, &
+      numfl_v, numfl_w
+      
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      tdta   ,   & ! temperature at two consecutive times
+      sdta   ,   & ! salinity at two consecutive times
+      udta   ,   & ! zonal velocity at two consecutive times
+      vdta   ,   & ! meridional velocity at two consecutive times
+      wdta   ,   & ! vertical velocity at two consecutive times
+#if defined key_trc_diatrd
+      hdivdta,   & ! horizontal divergence
+#endif
+      avtdta       ! vertical diffusivity coefficient
+
+
+#if defined key_ldfslp
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      uslpdta ,  & ! zonal isopycnal slopes
+      vslpdta ,  & ! meridional isopycnal slopes
+      wslpidta , & ! zonal diapycnal slopes
+      wslpjdta     ! meridional diapycnal slopes
+#endif
+
+#if ! defined key_off_degrad
+
+# if defined key_traldf_c2d
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &
+      ahtwdta      ! Lateral diffusivity
+# if defined key_trcldf_eiv 
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &
+      aeiwdta      ! G&M coefficient
+# endif
+# endif
+
+#else
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      ahtudta, ahtvdta, ahtwdta  !  Lateral diffusivity
+# if defined key_trcldf_eiv
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      aeiudta, aeivdta, aeiwdta  ! G&M coefficient
+# endif
+
+#endif
+# if defined key_diaeiv
+   !! GM Velocity : to be used latter
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+        eivudta, eivvdta, eivwdta
+# endif
+
+   REAL(wp), DIMENSION(jpi,jpj,jpflx,2) ::   &
+      flxdta       ! auxiliary 2-D forcing fields at two consecutive times
+   REAL(wp), DIMENSION(jpi,jpj,2) ::       &
+      zmxldta      ! mixed layer depth at two consecutive times
+
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+   REAL(wp), DIMENSION(jpi,jpj,2) ::       &
+      bblxdta ,  & ! frequency of bbl in the x direction at 2 consecutive times
+      bblydta      ! frequency of bbl in the y direction at 2 consecutive times
+#endif
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header: /home/opalod/NEMOCVSROOT/NEMO/OFF_SRC/dtadyn.F90,v 1.8 2007/10/12 09:05:29 opalod Exp $
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dta_dyn_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_dyn_init  ***
+      !!
+      !! ** Purpose :   initializations of parameters for the interpolation
+      !!
+      !! ** Method :
+      !!
+      !! History :
+      !!    ! original  : 92-01 (M. Imbard: sub domain)
+      !!    ! 98-04 (L.Bopp MA Foujols: slopes for isopyc.)
+      !!    ! 98-05 (L. Bopp read output of coupled run)
+      !!    ! 05-03 (O. Aumont and A. El Moussaoui) F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Local declarations
+
+
+      NAMELIST/nam_offdyn/ ndtadyn, ndtatot, nsptint,            & 
+          &                nficdyn, lperdyn
+      !!----------------------------------------------------------------------
+
+      !  Define the dynamical input parameters
+      ! ======================================
+
+      ! Read Namelist nam_offdyn : Lateral physics on tracers
+      REWIND( numnam )
+      READ  ( numnam, nam_offdyn )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'nam_offdyn : offline dynamical selection'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '  Namelist nam_offdyn : set parameters for the lecture of the dynamical fields'
+         WRITE(numout,*) 
+         WRITE(numout,*) ' number of elements in the FILE for a year  ndtadyn = ' , ndtadyn
+         WRITE(numout,*) ' total number of elements in the FILE       ndtatot = ' , ndtatot
+         WRITE(numout,*) ' type of interpolation                      nsptint = ' , nsptint
+         WRITE(numout,*) ' number of dynamics FILE                    nficdyn = ' , nficdyn
+         WRITE(numout,*) ' loop on the same FILE                      lperdyn = ' , lperdyn
+         WRITE(numout,*) ' '
+      ENDIF
+
+   END SUBROUTINE dta_dyn_init
+
+   SUBROUTINE dta_dyn(kt)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_dyn  ***
+      !!
+      !! ** Purpose : Prepares dynamics and physics fields from an 
+      !!              OPA9 simulation  for an off-line simulation
+      !!               for passive tracer
+      !!
+      !! ** Method : calculates the position of DATA to read READ DATA 
+      !!             (example month changement) computes slopes IF needed
+      !!             interpolates DATA IF needed
+      !!
+      !! ** History :
+      !!   ! original  : 92-01 (M. Imbard: sub domain)
+      !!   ! addition  : 98-04 (L.Bopp MA Foujols: slopes for isopyc.) 
+      !!   ! addition  : 98-05 (L. Bopp read output of coupled run)
+      !!   ! addition  : 05-03 (O. Aumont and A. El Moussaoui) F90
+      !!   ! addition  : 05-12 (C. Ethe) Adapted for DEGINT
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE eosbn2
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   iper, iperm1, iswap   
+
+      REAL(wp) :: zpdtan, zpdtpe, zdemi, zt
+      REAL(wp) :: zweigh, zweighm1
+
+      REAL(wp), DIMENSION(jpi,jpj,jpflx) ::   &
+         flx  ! auxiliary field for 2-D surface boundary conditions
+
+
+      ! 0. Initialization
+      ! -----------------
+
+      IF (lfirdyn) THEN
+      !
+      ! time step MUST BE nint000
+      !
+          IF (kt.ne.nit000) THEN
+              IF (lwp) THEN
+                  WRITE (numout,*) ' kt MUST BE EQUAL to nit000. kt=',kt  &
+                     ,' nit000=',nit000
+              END IF
+              STOP 'dtadyn'
+          END if
+      ! Initialize the parameters of the interpolation
+      CALL dta_dyn_init
+      ENDIF
+
+
+      zpdtan = raass / rdt
+      zpdtpe = ((zpdtan / FLOAT (ndtadyn)))
+      zdemi  = zpdtpe * 0.5
+      zt     = (FLOAT (kt) + zdemi ) / zpdtpe
+
+      zweigh   = zt - FLOAT(INT(zt))
+      zweighm1 = 1. - zweigh
+
+      IF (lperdyn) THEN
+         iperm1 = MOD(INT(zt),ndtadyn)
+      ELSE
+         iperm1 = MOD(INT(zt),(ndtatot-1)) + 1
+      ENDIF
+      iper = iperm1 + 1
+      IF (iperm1 == 0) THEN
+          IF (lperdyn) THEN
+              iperm1 = ndtadyn
+          ELSE 
+              IF (lfirdyn) THEN
+                  IF (lwp) THEN 
+                      WRITE (numout,*) ' dynamic file is not periodic '
+                      WRITE (numout,*) ' with or without interpolation, '
+                      WRITE (numout,*) ' we take the first value'
+                      WRITE (numout,*) ' for the previous period '
+                      WRITE (numout,*) ' iperm1 = 0  '
+                  END IF 
+              END IF
+          END IF 
+      END IF 
+
+      iswap  = 0
+
+      ! 1. First call lfirdyn = true
+      ! ----------------------------
+
+      IF (lfirdyn) THEN
+      !
+      ! store the information of the period read
+      !
+          ndyn1 = iperm1
+          ndyn2 = iper
+
+          IF (lwp) THEN
+              WRITE (numout,*)         &
+                 ' dynamics DATA READ for the period ndyn1 =',ndyn1, &
+              & ' and for the period ndyn2 = ',ndyn2
+              WRITE (numout,*) ' time step is :',kt
+              WRITE (numout,*) ' we have ndtadyn = ',ndtadyn,&
+                 &         ' records in the dynamic FILE for one year'
+          END IF 
+      !
+      ! DATA READ for the iperm1 period
+      !
+          IF( iperm1 /= 0 ) THEN
+             CALL dynrea( kt, iperm1 ) 
+          ELSE 
+             CALL dynrea( kt, 1 )
+          ENDIF
+      !
+      ! Computes dynamical fields
+      !
+                tn(:,:,:)=tdta(:,:,:,2)
+                sn(:,:,:)=sdta(:,:,:,2)
+                avt(:,:,:)=avtdta(:,:,:,2)
+
+
+         IF(lwp) THEN
+            WRITE(numout,*)' temperature '
+            WRITE(numout,*)
+            CALL prihre(tn(1,1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+            WRITE(numout,*) '  level = ',jpk/2
+            CALL prihre(tn(1,1,jpk/2),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)  
+            WRITE(numout,*) '  level = ',jpkm1
+            CALL prihre(tn(1,1,jpkm1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout) 
+        ENDIF
+
+#if defined key_ldfslp
+            CALL eos( tn, sn, rhd, rhop )   ! Time-filtered in situ density 
+            CALL bn2( tn, sn, rn2 )         ! before Brunt-Vaisala frequency
+            CALL zdf_mxl( kt )              ! mixed layer depth
+            CALL ldf_slp( kt, rhd, rn2 )
+
+            uslpdta(:,:,:,2)=uslp(:,:,:)
+            vslpdta(:,:,:,2)=vslp(:,:,:)
+            wslpidta(:,:,:,2)=wslpi(:,:,:)
+            wslpjdta(:,:,:,2)=wslpj(:,:,:)
+#endif
+       !
+       ! swap from record 2 to 1
+       !
+                udta(:,:,:,1)=udta(:,:,:,2)
+                vdta(:,:,:,1)=vdta(:,:,:,2)
+                wdta(:,:,:,1)=wdta(:,:,:,2)
+#if defined key_trc_diatrd
+                hdivdta(:,:,:,1)=hdivdta(:,:,:,2)
+#endif
+                avtdta(:,:,:,1)=avtdta(:,:,:,2)
+                tdta(:,:,:,1)=tdta(:,:,:,2)
+                sdta(:,:,:,1)=sdta(:,:,:,2)
+#if defined key_ldfslp
+                uslpdta(:,:,:,1)=uslpdta(:,:,:,2)
+                vslpdta(:,:,:,1)=vslpdta(:,:,:,2)
+                wslpidta(:,:,:,1)=wslpidta(:,:,:,2)
+                wslpjdta(:,:,:,1)=wslpjdta(:,:,:,2)
+#endif
+                flxdta(:,:,:,1) = flxdta(:,:,:,2)
+                zmxldta(:,:,1)=zmxldta(:,:,2)
+#if ! defined key_off_degrad
+
+#  if defined key_traldf_c2d
+                ahtwdta(:,:,1)= ahtwdta(:,:,2)
+#    if defined key_trcldf_eiv
+                aeiwdta(:,:,1)= aeiwdta(:,:,2)
+#    endif
+#  endif
+
+#else
+                ahtudta(:,:,:,1) = ahtudta(:,:,:,2)
+                ahtvdta(:,:,:,1) = ahtvdta(:,:,:,2)
+                ahtwdta(:,:,:,1) = ahtwdta(:,:,:,2)
+#  if defined key_trcldf_eiv
+                aeiudta(:,:,:,1) = aeiudta(:,:,:,2)
+                aeivdta(:,:,:,1) = aeivdta(:,:,:,2)
+                aeiwdta(:,:,:,1) = aeiwdta(:,:,:,2)
+#  endif
+
+#endif
+
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+                bblxdta(:,:,1)=bblxdta(:,:,2)
+                bblydta(:,:,1)=bblydta(:,:,2)
+#endif
+      !
+      ! indicates a swap
+      !
+          iswap = 1
+      !
+      ! DATA READ for the iper period
+      !
+          CALL dynrea( kt, iper )
+      !
+      ! Computes wdta (and slopes if key_trahdfiso)
+      !
+                tn(:,:,:)=tdta(:,:,:,2)
+                sn(:,:,:)=sdta(:,:,:,2)
+                avt(:,:,:)=avtdta(:,:,:,2)
+
+
+#if defined key_ldfslp
+            CALL eos( tn, sn, rhd, rhop )   ! Time-filtered in situ density
+            CALL bn2( tn, sn, rn2 )         ! before Brunt-Vaisala frequency
+            CALL zdf_mxl( kt )              ! mixed layer depth
+            CALL ldf_slp( kt, rhd, rn2 )
+
+            uslpdta(:,:,:,2)=uslp(:,:,:)
+            vslpdta(:,:,:,2)=vslp(:,:,:)
+            wslpidta(:,:,:,2)=wslpi(:,:,:)
+            wslpjdta(:,:,:,2)=wslpj(:,:,:)
+#endif
+      !
+      ! trace the first CALL
+      !
+          lfirdyn=.FALSE. 
+      ENDIF
+      !
+      ! and now what we have to DO at every time step
+      !
+      ! check the validity of the period in memory
+      !
+      IF (iperm1.NE.ndyn1) THEN 
+          IF (iperm1.EQ.0.) THEN
+              IF (lwp) THEN
+                  WRITE (numout,*) ' dynamic file is not periodic '
+                  WRITE (numout,*) ' with or without interpolation, '
+                  WRITE (numout,*) ' we take the last value'
+                  WRITE (numout,*) ' for the last period '
+                  WRITE (numout,*) ' iperm1 = 12  '
+                  WRITE (numout,*) ' iper = 13'
+              ENDIF
+              iperm1 = 12
+              iper =13
+          ENDIF
+      !
+      ! we have to prepare a NEW READ of DATA
+      !
+      ! swap from record 2 to 1
+      !
+                udta(:,:,:,1) = udta(:,:,:,2)
+                vdta(:,:,:,1) = vdta(:,:,:,2)
+                wdta(:,:,:,1) = wdta(:,:,:,2)
+#if defined key_trc_diatrd
+                hdivdta(:,:,:,1)=hdivdta(:,:,:,2)
+#endif
+                avtdta(:,:,:,1) = avtdta(:,:,:,2)
+                tdta(:,:,:,1) = tdta(:,:,:,2)
+                sdta(:,:,:,1) = sdta(:,:,:,2)
+#if defined key_ldfslp
+                uslpdta(:,:,:,1) = uslpdta(:,:,:,2)
+                vslpdta(:,:,:,1) = vslpdta(:,:,:,2)
+                wslpidta(:,:,:,1) = wslpidta(:,:,:,2)
+                wslpjdta(:,:,:,1) = wslpjdta(:,:,:,2)
+#endif
+                flxdta(:,:,:,1) = flxdta(:,:,:,2)
+                zmxldta(:,:,1) = zmxldta(:,:,2)
+
+#if ! defined key_off_degrad
+
+#  if defined key_traldf_c2d
+                ahtwdta(:,:,1)= ahtwdta(:,:,2)
+#    if defined key_trcldf_eiv
+                aeiwdta(:,:,1)= aeiwdta(:,:,2)
+#    endif
+#  endif
+
+#else
+                ahtudta(:,:,:,1) = ahtudta(:,:,:,2)
+                ahtvdta(:,:,:,1) = ahtvdta(:,:,:,2)
+                ahtwdta(:,:,:,1) = ahtwdta(:,:,:,2)
+#  if defined key_trcldf_eiv
+                aeiudta(:,:,:,1) = aeiudta(:,:,:,2)
+                aeivdta(:,:,:,1) = aeivdta(:,:,:,2)
+                aeiwdta(:,:,:,1) = aeiwdta(:,:,:,2)
+#  endif
+
+#endif
+
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+                bblxdta(:,:,1) = bblxdta(:,:,2)
+                bblydta(:,:,1) = bblydta(:,:,2)
+#endif
+      !
+      ! indicates a swap
+      !
+          iswap = 1
+      !
+      ! READ DATA for the iper period
+      !
+          CALL dynrea( kt, iper )
+      !
+      ! Computes wdta (and slopes if key_trahdfiso)
+      !
+                tn(:,:,:)=tdta(:,:,:,2)
+                sn(:,:,:)=sdta(:,:,:,2)
+                avt(:,:,:)=avtdta(:,:,:,2)
+
+#if defined key_ldfslp
+            CALL eos( tn, sn, rhd, rhop )   ! Time-filtered in situ density
+            CALL bn2( tn, sn, rn2 )         ! before Brunt-Vaisala frequency
+            CALL zdf_mxl( kt )              ! mixed layer depth
+            CALL ldf_slp( kt, rhd, rn2 )
+
+            uslpdta(:,:,:,2)=uslp(:,:,:)
+            vslpdta(:,:,:,2)=vslp(:,:,:)
+            wslpidta(:,:,:,2)=wslpi(:,:,:)
+            wslpjdta(:,:,:,2)=wslpj(:,:,:)
+#endif
+       !
+       ! store the information of the period read
+       !
+          ndyn1 = ndyn2
+          ndyn2 = iper
+       !
+       ! we have READ another period of DATA       !
+          IF (lwp) THEN
+              WRITE (numout,*) ' dynamics DATA READ for the period ndyn1 =',ndyn1
+              WRITE (numout,*) ' and the period ndyn2 = ',ndyn2
+              WRITE (numout,*) ' time step is :',kt
+          END IF 
+
+      END IF 
+
+      !
+      ! compute the DATA at the given time step
+      !
+      IF ( nsptint == 0 ) THEN
+      !
+      ! no spatial interpolation
+      !
+      ! DATA are probably correct 
+      ! we have to initialize DATA IF we have changed the period
+      !
+          IF (iswap.eq.1) THEN
+      !
+      ! initialize now fields with the NEW DATA READ
+      !
+                    un(:,:,:)=udta(:,:,:,2)
+                    vn(:,:,:)=vdta(:,:,:,2)
+                    wn(:,:,:)=wdta(:,:,:,2)
+#if defined key_trc_diatrd
+                    hdivn(:,:,:)=hdivdta(:,:,:,2)
+#endif
+#if defined key_trc_zdfddm
+                    avs(:,:,:)=avtdta(:,:,:,2)
+#endif
+                    avt(:,:,:)=avtdta(:,:,:,2)
+                    tn(:,:,:)=tdta(:,:,:,2)
+                    sn(:,:,:)=sdta(:,:,:,2)
+#if defined key_ldfslp
+                    uslp(:,:,:)=uslpdta(:,:,:,2)
+                    vslp(:,:,:)=vslpdta(:,:,:,2)
+                    wslpi(:,:,:)=wslpidta(:,:,:,2)
+                    wslpj(:,:,:)=wslpjdta(:,:,:,2)
+#endif
+                    flx(:,:,:) = flxdta(:,:,:,2)
+                    hmld(:,:)=zmxldta(:,:,2)
+#if ! defined key_off_degrad
+
+#  if defined key_traldf_c2d
+                ahtwdta(:,:,1)= ahtwdta(:,:,2)
+#    if defined key_trcldf_eiv
+                aeiwdta(:,:,1)= aeiwdta(:,:,2)
+#    endif
+#  endif
+
+#else
+                ahtudta(:,:,:,1) = ahtudta(:,:,:,2)
+                ahtvdta(:,:,:,1) = ahtvdta(:,:,:,2)
+                ahtwdta(:,:,:,1) = ahtwdta(:,:,:,2)
+#  if defined key_trcldf_eiv
+                aeiudta(:,:,:,1) = aeiudta(:,:,:,2)
+                aeivdta(:,:,:,1) = aeivdta(:,:,:,2)
+                aeiwdta(:,:,:,1) = aeiwdta(:,:,:,2)
+#  endif
+
+#endif
+
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+                    bblx(:,:)=bblxdta(:,:,2)
+                    bbly(:,:)=bblydta(:,:,2)
+#endif
+       !
+       ! keep needed fluxes
+       !
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+                    vatm(:,:) = flx(:,:,jpwind)
+#endif
+                    freeze(:,:) = flx(:,:,jpice)
+                    emp(:,:) = flx(:,:,jpemp)
+                    emps(:,:) = emp(:,:)
+                    qsr(:,:) = flx(:,:,jpqsr)
+
+          END IF 
+
+      ELSE 
+          IF ( nsptint == 1 ) THEN
+      !
+      ! linear interpolation
+      !
+      ! initialize now fields with a linear interpolation
+      !
+                    un(:,:,:) = zweighm1 * udta(:,:,:,1) + zweigh * udta(:,:,:,2) 
+                    vn(:,:,:) = zweighm1 * vdta(:,:,:,1) + zweigh * vdta(:,:,:,2)
+                    wn(:,:,:) = zweighm1 * wdta(:,:,:,1) + zweigh * wdta(:,:,:,2)
+#if defined key_trc_diatrd
+                    hdivn(:,:,:) = zweighm1 * hdivdta(:,:,:,1) + zweigh * hdivdta(:,:,:,2)
+#endif
+#if defined key_zdfddm
+                    avs(:,:,:)= zweighm1 * avtdta(:,:,:,1) + zweigh * avtdta(:,:,:,2)
+#endif
+                    avt(:,:,:)= zweighm1 * avtdta(:,:,:,1) + zweigh * avtdta(:,:,:,2)
+                    tn(:,:,:) = zweighm1 * tdta(:,:,:,1) + zweigh * tdta(:,:,:,2)
+                    sn(:,:,:) = zweighm1 * sdta(:,:,:,1) + zweigh * sdta(:,:,:,2)
+   
+         
+#if defined key_ldfslp
+                    uslp(:,:,:) = zweighm1 * uslpdta(:,:,:,1) + zweigh * uslpdta(:,:,:,2) 
+                    vslp(:,:,:) = zweighm1 * vslpdta(:,:,:,1) + zweigh * vslpdta(:,:,:,2) 
+                    wslpi(:,:,:) = zweighm1 * wslpidta(:,:,:,1) + zweigh * wslpidta(:,:,:,2) 
+                    wslpj(:,:,:) = zweighm1 * wslpjdta(:,:,:,1) + zweigh * wslpjdta(:,:,:,2) 
+#endif
+                    flx(:,:,:) = zweighm1 * flxdta(:,:,:,1) + zweigh * flxdta(:,:,:,2) 
+                    hmld(:,:) = zweighm1 * zmxldta(:,:,1) + zweigh  * zmxldta(:,:,2) 
+#if ! defined key_off_degrad
+
+#  if defined key_traldf_c2d
+                    ahtw(:,:) = zweighm1 * ahtwdta(:,:,1) + zweigh * ahtwdta(:,:,2)
+#    if defined key_trcldf_eiv
+                    aeiw(:,:) = zweighm1 * aeiwdta(:,:,1) + zweigh * aeiwdta(:,:,2)
+#    endif
+#  endif
+
+#else
+                    ahtu(:,:,:) = zweighm1 * ahtudta(:,:,:,1) + zweigh * ahtudta(:,:,:,2)
+                    ahtv(:,:,:) = zweighm1 * ahtvdta(:,:,:,1) + zweigh * ahtvdta(:,:,:,2)
+                    ahtw(:,:,:) = zweighm1 * ahtwdta(:,:,:,1) + zweigh * ahtwdta(:,:,:,2)
+#  if defined key_trcldf_eiv
+                    aeiu(:,:,:) = zweighm1 * aeiudta(:,:,:,1) + zweigh * aeiudta(:,:,:,2)
+                    aeiv(:,:,:) = zweighm1 * aeivdta(:,:,:,1) + zweigh * aeivdta(:,:,:,2)
+                    aeiw(:,:,:) = zweighm1 * aeiwdta(:,:,:,1) + zweigh * aeiwdta(:,:,:,2)
+#  endif
+                    
+#endif
+
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+                    bblx(:,:) = zweighm1 * bblxdta(:,:,1) + zweigh * bblxdta(:,:,2)
+                    bbly(:,:) = zweighm1 * bblydta(:,:,1) + zweigh * bblydta(:,:,2)
+#endif
+       !
+       ! keep needed fluxes
+       !
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+                  vatm(:,:) = flx(:,:,jpwind)
+#endif
+                  freeze(:,:) = flx(:,:,jpice)
+                  emp(:,:)    = flx(:,:,jpemp)
+                  emps(:,:)   = emp(:,:)
+                  qsr(:,:)    = flx(:,:,jpqsr)
+       !
+       ! other interpolation
+       !
+          ELSE 
+
+              WRITE (numout,*) ' this kind of interpolation don t EXIST'
+              WRITE (numout,*) ' at the moment. we STOP '
+              STOP 'dtadyn'
+
+          END IF 
+
+      END IF
+      !
+      ! lb in any case, we need rhop
+      !
+      CALL eos( tn, sn, rhd, rhop ) 
+
+#if ! defined key_off_degrad && defined key_traldf_c2d
+      ! In case of 2D varying coefficients, we need aeiv and aeiu
+      IF( lk_traldf_eiv )   CALL ldf_eiv( kt )      ! eddy induced velocity coefficient
+#endif
+
+   END SUBROUTINE dta_dyn
+
+   SUBROUTINE dynrea( kt, kenr )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dynrea  ***
+      !!
+      !! ** Purpose : READ dynamics fiels from OPA9 netcdf output
+      !! 
+      !! ** Method : READ the kenr records of DATA and store in
+      !!             in udta(...,2), ....  
+      !! 
+      !! ** History : additions : M. Levy et M. Benjelloul jan 2001 
+      !!              (netcdf FORMAT) 
+      !!              05-03 (O. Aumont and A. El Moussaoui) F90
+      !!              06-07 : (C. Ethe) use of iom module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt, kenr       ! time index
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk, jkenr
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+        zu, zv, zw, zt, zs, zavt ,   &     ! 3-D dynamical fields
+        zhdiv                              ! horizontal divergence
+
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zemp, zqsr, zmld, zice, zwspd 
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+        zbblx, zbbly
+#endif
+
+#if ! defined key_off_degrad
+
+#  if defined key_traldf_c2d
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zahtw
+#   if defined key_trcldf_eiv
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zaeiw
+#   endif
+#  endif
+
+#else
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      zahtu, zahtv, zahtw  !  Lateral diffusivity
+# if defined key_trcldf_eiv
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      zaeiu, zaeiv, zaeiw  ! G&M coefficient
+# endif
+
+#endif
+
+# if defined key_diaeiv
+   !! GM Velocity : to be used latter
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+        zeivu, zeivv, zeivw
+# endif
+
+      CHARACTER(len=45)  ::  &
+         clname_t = 'dyna_grid_T.nc', &
+         clname_u = 'dyna_grid_U.nc', &
+         clname_v = 'dyna_grid_V.nc', &
+         clname_w = 'dyna_grid_W.nc'
+      !
+      ! 0. Initialization
+      ! cas d'un fichier non periodique : on utilise deux fois le premier et
+      ! le dernier champ temporel
+
+      jkenr = kenr
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'Dynrea : reading dynamical fields, kenr = ', jkenr
+         WRITE(numout,*) ' ~~~~~~~'
+#if defined key_off_degrad
+         WRITE(numout,*) ' Degraded fields'
+#endif
+         WRITE(numout,*)
+      ENDIF
+
+
+      IF( kt == nit000 .AND. nlecoff == 0 ) THEN
+
+         nlecoff = 1
+
+         CALL  iom_open ( clname_t, numfl_t )
+         CALL  iom_open ( clname_u, numfl_u )
+         CALL  iom_open ( clname_v, numfl_v )
+         CALL  iom_open ( clname_w, numfl_w )
+
+      ENDIF
+
+      ! file grid-T
+      !---------------
+      CALL iom_get ( numfl_t, jpdom_data, 'votemper', zt   (:,:,:), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'vosaline', zs   (:,:,:), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'somixhgt', zmld (:,:  ), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'sowaflcd', zemp (:,:  ), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'soshfldo', zqsr (:,:  ), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'soicecov', zice (:,:  ), jkenr )
+      CALL iom_get ( numfl_t, jpdom_data, 'sowindsp', zwspd(:,:  ), jkenr )
+
+      ! file grid-U
+      !---------------
+      CALL iom_get ( numfl_u, jpdom_data, 'vozocrtx', zu   (:,:,:), jkenr )
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+      CALL iom_get ( numfl_u, jpdom_data, 'sobblcox', zbblx(:,:  ), jkenr )
+#endif
+
+#if defined key_diaeiv
+      !! GM Velocity : to be used latter
+      CALL iom_get ( numfl_u, jpdom_data, 'vozoeivu', zeivu(:,:,:), jkenr )
+#endif
+
+# if defined key_off_degrad
+      CALL iom_get ( numfl_u, jpdom_data, 'vozoahtu', zahtu(:,:,:), jkenr )
+# if defined key_trcldf_eiv
+      CALL iom_get ( numfl_u, jpdom_data, 'vozoaeiu', zaeiu(:,:,:), jkenr )
+# endif
+#endif
+
+      ! file grid-V
+      !---------------
+      CALL iom_get ( numfl_v, jpdom_data, 'vomecrty', zv   (:,:,:), jkenr )
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+      CALL iom_get ( numfl_v, jpdom_data, 'sobblcoy', zbbly(:,:  ), jkenr )
+#endif
+
+#if defined key_diaeiv
+      !! GM Velocity : to be used latter
+      CALL iom_get ( numfl_v, jpdom_data, 'vomeeivv', zeivv(:,:,:), jkenr )
+#endif
+
+#if defined key_off_degrad
+      CALL iom_get ( numfl_v, jpdom_data, 'vomeahtv', zahtv(:,:,:), jkenr )
+#   if defined key_trcldf_eiv
+      CALL iom_get ( numfl_v, jpdom_data, 'vomeaeiv', zaeiv(:,:,:), jkenr )
+#   endif
+#endif
+
+      ! file grid-W
+      !---------------
+!!      CALL iom_get ( numfl_w, jpdom_data, 'vovecrtz', zw   (:,:,:), jkenr )
+# if defined key_zdfddm
+      CALL iom_get ( numfl_w, jpdom_data, 'voddmavs', zavt (:,:,:), jkenr )
+#else
+      CALL iom_get ( numfl_w, jpdom_data, 'votkeavt', zavt (:,:,:), jkenr )
+#endif 
+
+# if defined key_diaeiv
+      !! GM Velocity : to be used latter
+      CALL iom_get ( numfl_w, jpdom_data, 'voveeivw', zeivw(:,:,:), jkenr )
+#endif 
+
+#if ! defined key_off_degrad
+#  if defined key_traldf_c2d
+      CALL iom_get ( numfl_w, jpdom_data, 'soleahtw', zahtw (:,: ), jkenr )
+#   if   defined key_trcldf_eiv 
+      CALL iom_get ( numfl_w, jpdom_data, 'soleaeiw', zaeiw (:,: ), jkenr )
+#   endif
+#  endif
+#else
+      !! degradation-integration
+      CALL iom_get ( numfl_w, jpdom_data, 'voveahtw', zahtw(:,:,:), jkenr )
+# if defined key_trcldf_eiv
+      CALL iom_get ( numfl_w, jpdom_data, 'voveaeiw', zaeiw(:,:,:), jkenr )
+# endif
+#endif
+
+      udta(:,:,:,2) = zu(:,:,:) * umask(:,:,:)
+      vdta(:,:,:,2) = zv(:,:,:) * vmask(:,:,:)
+!!       wdta(:,:,:,2) = zw(:,:,:) * tmask(:,:,:)
+
+
+      ! Computation of vertical velocity using horizontal divergence
+      zhdiv(:,:,:) = 0.
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               zhdiv(ji,jj,jk) = (  e2u(ji,jj) * udta(ji,jj,jk,2) - e2u(ji-1,jj  ) * udta(ji-1,jj  ,jk,2)      &
+                  &               + e1v(ji,jj) * vdta(ji,jj,jk,2) - e1v(ji  ,jj-1) * vdta(ji  ,jj-1,jk,2)  )   &
+                  &            / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               zhdiv(ji,jj,jk) =   &
+                  (  e2u(ji,jj)*fse3u(ji,jj,jk)*udta(ji,jj,jk,2) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*udta(ji-1,jj,jk,2)       &
+                  +  e1v(ji,jj)*fse3v(ji,jj,jk)*vdta(ji,jj,jk,2) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*vdta(ji,jj-1,jk,2)  )    &
+                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO
+         END DO         
+      ENDDO
+
+      ! Lateral boundary conditions on hdiv
+      CALL lbc_lnk( zhdiv, 'T', 1. )
+
+
+      ! computation of vertical velocity from the bottom
+      zw(:,:,jpk) = 0.
+      DO jk = jpkm1, 1, -1
+         zw(:,:,jk) = zw(:,:,jk+1) - fse3t(:,:,jk) * zhdiv(:,:,jk)
+      END DO
+
+      wdta(:,:,:,2) = zw(:,:,:) * tmask(:,:,:)
+#if defined key_trc_diatrd
+      hdivdta(:,:,:,2) = zhdiv(:,:,:) * tmask(:,:,:)
+#endif
+
+      tdta(:,:,:,2)   = zt(:,:,:)   * tmask(:,:,:)
+      sdta(:,:,:,2)   = zs(:,:,:)   * tmask(:,:,:)
+      avtdta(:,:,:,2) = zavt(:,:,:) * tmask(:,:,:)
+#if ! defined key_off_degrad && defined key_traldf_c2d
+      ahtwdta(:,:,2)  = zahtw(:,:) * tmask(:,:,1)
+#if defined key_trcldf_eiv
+      aeiwdta(:,:,2)  = zaeiw(:,:) * tmask(:,:,1)
+#endif
+#endif
+
+#if defined key_off_degrad
+        ahtudta(:,:,:,2) = zahtu(:,:,:) * umask(:,:,:)
+        ahtvdta(:,:,:,2) = zahtv(:,:,:) * vmask(:,:,:)
+        ahtwdta(:,:,:,2) = zahtw(:,:,:) * tmask(:,:,:)
+#  if defined key_trcldf_eiv
+        aeiudta(:,:,:,2) = zaeiu(:,:,:) * umask(:,:,:)
+        aeivdta(:,:,:,2) = zaeiv(:,:,:) * vmask(:,:,:)
+        aeiwdta(:,:,:,2) = zaeiw(:,:,:) * tmask(:,:,:)
+#  endif
+#endif
+
+      !
+      ! flux :
+      !
+      flxdta(:,:,jpwind,2) = zwspd(:,:) * tmask(:,:,1)
+      flxdta(:,:,jpice,2)  = MIN( 1., zice(:,:) ) * tmask(:,:,1)
+      flxdta(:,:,jpemp,2)  = zemp(:,:) * tmask(:,:,1)
+      flxdta(:,:,jpqsr,2)  = zqsr(:,:) * tmask(:,:,1)
+      zmxldta(:,:,2)       = zmld(:,:) * tmask(:,:,1)
+      
+#if defined key_trcbbl_dif   ||   defined key_trcbbl_adv
+      bblxdta(:,:,2) = MAX( 0., zbblx(:,:) )
+      bblydta(:,:,2) = MAX( 0., zbbly(:,:) )
+
+      WHERE( bblxdta(:,:,2) > 2. ) bblxdta(:,:,2) = 0.
+      WHERE( bblydta(:,:,2) > 2. ) bblydta(:,:,2) = 0.
+
+#endif
+
+      IF( kt == nitend ) THEN
+         CALL iom_close ( numfl_t )
+         CALL iom_close ( numfl_u )
+         CALL iom_close ( numfl_v )
+         CALL iom_close ( numfl_w )
+      ENDIF
+      
+   END SUBROUTINE dynrea
+
+
+
+END MODULE dtadyn
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/eosbn2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/eosbn2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/eosbn2.F90	(revision 4536)
@@ -0,0 +1,842 @@
+MODULE eosbn2
+   !!==============================================================================
+   !!                       ***  MODULE  eosbn2  ***
+   !! Ocean diagnostic variable : equation of state - in situ and potential density
+   !!                                               - Brunt-Vaisala frequency 
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   eos            : generic interface of the equation of state
+   !!   eos_insitu     : Compute the in situ density
+   !!   eos_insitu_pot : Compute the insitu and surface referenced potential
+   !!                    volumic mass
+   !!   eos_insitu_2d  : Compute the in situ density for 2d fields
+   !!   eos_bn2        : Compute the Brunt-Vaisala frequency
+   !!   eos_init       : set eos parameters (namelist)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE zdfddm          ! vertical physics: double diffusion
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Interface 
+   INTERFACE eos
+      MODULE PROCEDURE eos_insitu, eos_insitu_pot, eos_insitu_2d
+   END INTERFACE 
+   INTERFACE bn2
+      MODULE PROCEDURE eos_bn2
+   END INTERFACE 
+
+   !! * Routine accessibility
+   PUBLIC eos        ! called by step.F90, inidtr.F90, tranpc.F90 and intgrd.F90
+   PUBLIC bn2        ! called by step.F90
+
+   !! * Share module variables
+   INTEGER , PUBLIC ::   &  !: nam_eos : ocean physical parameters
+      neos      = 0,     &  !: = 0/1/2 type of eq. of state and Brunt-Vaisala frequ.
+      neos_init = 0         !: control flag for initialization
+
+   REAL(wp), PUBLIC ::   &  !: nam_eos : ocean physical parameters
+      ralpha = 2.0e-4,   &  !: thermal expension coeff. (linear equation of state)
+      rbeta  = 7.7e-4       !: saline  expension coeff. (linear equation of state)
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE eos_insitu ( ptem, psal, prd )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE eos_insitu  ***
+      !! 
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) from 
+      !!       potential temperature and salinity using an equation of state
+      !!       defined through the namelist parameter neos.
+      !!
+      !! ** Method  :   3 cases:
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - ralpha * t
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rbeta * s - ralpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Action  :   compute prd , the in situ density (no units)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!
+      !! History :
+      !!        !  89-03 (o. Marti)  Original code
+      !!        ! 94-08 (G. Madec)
+      !!        !  96-01 (G. Madec) statement function for e3
+      !!        !  97-07 (G. Madec) introduction of neos, OPA8.1
+      !!        !  97-07 (G. Madec) density instead of volumic mass
+      !!        !  99-02 (G. Madec, N. Grima) semi-implicit pressure gradient
+      !!        !  01-09 (M. Ben Jelloul) bugfix   
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         prd                      ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &          
+         zt , zs , zh , zsr,   &  ! temporary scalars
+         zr1, zr2, zr3, zr4,   &  !    "         " 
+         zrhop, ze, zbw, zb,   &  !    "         "
+         zd , zc , zaw, za ,   &  !    "         "
+         zb1, za1, zkw, zk0       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zws                      ! temporary workspace
+      !!----------------------------------------------------------------------
+
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  ! depth
+                  zh = fsdept(ji,jj,jk)
+                  ! square root salinity
+                  zsr= zws(ji,jj,jk)
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! masked in situ density anomaly
+                  prd(ji,jj,jk) = (  zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
+                     - rau0 ) / rau0 * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd(ji,jj,jk) = ( 0.0285 - ralpha * zt ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd(ji,jj,jk) = (   rbeta  * zs - ralpha * zt ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=prd, clinfo1=' eos  : ', ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE eos_insitu
+
+
+   SUBROUTINE eos_insitu_pot ( ptem, psal, prd, prhop)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_pot  ***
+      !!           
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) and the
+      !!      potential volumic mass (Kg/m3) from potential temperature and
+      !!      salinity fields using an equation of state defined through the 
+      !!     namelist parameter neos.
+      !!
+      !! ** Method  :
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!              rhop(t,s)  = rho(t,s,0)
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - ralpha * t
+      !!              rhop(t,s)  = rho(t,s)
+      !!
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0 
+      !!                       = rbeta * s - ralpha * tn - 1.
+      !!              rhop(t,s)  = rho(t,s)
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd  , the in situ density (no units)
+      !!              - prhop, the potential volumic mass (Kg/m3)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!      Brown, J. A. and K. A. Campana. Mon. Weather Rev., 1978
+      !!
+      !! History :
+      !!   4.0  !  89-03  (O. Marti)
+      !!        !  94-08  (G. Madec)
+      !!        !  96-01  (G. Madec) statement function for e3
+      !!        !  97-07  (G. Madec) introduction of neos, OPA8.1
+      !!        !  97-07  (G. Madec) density instead of volumic mass
+      !!        !  99-02  (G. Madec, N. Grima) semi-implicit pressure gradient
+      !!        !  01-09  (M. Ben Jelloul) bugfix   
+      !!   9.0  !  03-08  (G. Madec)  F90, free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,   &  ! potential temperature
+         psal       ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         prd,    &  ! potential density (surface referenced)
+         prhop      ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  ! depth
+                  zh = fsdept(ji,jj,jk)
+                  ! square root salinity
+!!Edmee           zsr= SQRT( ABS( zs ) )
+                  zsr= zws(ji,jj,jk)
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! save potential volumic mass
+                  prhop(ji,jj,jk) = zrhop * tmask(ji,jj,jk)
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! masked in situ density anomaly
+                  prd(ji,jj,jk) = (  zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
+                     - rau0 ) / rau0 * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd  (ji,jj,jk) = ( 0.0285 - ralpha * zt )        * tmask(ji,jj,jk)
+                  prhop(ji,jj,jk) = ( rau0 * prd(ji,jj,jk) + rau0 ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd  (ji,jj,jk) = ( rbeta  * zs - ralpha * zt ) * tmask(ji,jj,jk)
+                  prhop(ji,jj,jk) = ( rau0 * prd(ji,jj,jk) + rau0 )    * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=prd, clinfo1=' eos-p: ', tab3d_2=prhop, clinfo2=' pot : ', ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE eos_insitu_pot
+
+   SUBROUTINE eos_insitu_2d ( ptem, psal, pdep, prd )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_2d  ***
+      !!
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) from 
+      !!      potential temperature and salinity using an equation of state
+      !!      defined through the namelist parameter neos. * 2D field case
+      !!
+      !! ** Method :
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - ralpha * t
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rbeta * s - ralpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd , the in situ density (no units)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!
+      !! History :
+      !!   8.5  !  02-11  (G. Madec, A. Bozec)  partial step
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::   &
+         ptem,                           &  ! potential temperature
+         psal,                           &  ! salinity
+         pdep                               ! depth
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         prd                                ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER ::  ji, jj                    ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         zmask
+      REAL(wp), DIMENSION(jpi,jpj) :: zws
+      !!----------------------------------------------------------------------
+
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+      prd(:,:) = 0.e0
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpjm1
+!CDIR NOVERRCHK
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               zws(ji,jj) = SQRT( ABS( psal(ji,jj) ) )
+            END DO
+         END DO
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+
+               zmask = tmask(ji,jj,1)      ! land/sea bottom mask = surf. mask
+
+               zt = ptem (ji,jj)            ! interpolated T
+               zs = psal (ji,jj)            ! interpolated S
+               zsr= zws(ji,jj)            ! square root of interpolated S
+               zh = pdep(ji,jj)            ! depth at the partial step level
+
+               ! compute volumic mass pure water at atm pressure
+               zr1 = ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                         -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+               ! seawater volumic mass atm pressure
+               zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 )*zt+7.6438e-5 ) *zt   &
+                         -4.0899e-3 ) *zt+0.824493
+               zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+               zr4= 4.8314e-4
+
+               ! potential volumic mass (reference to the surface)
+               zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+               ! add the compression terms
+               ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+               zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+               zb = zbw + ze * zs
+
+               zd = -2.042967e-2
+               zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+               zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt -4.721788
+               za = ( zd*zsr + zc ) *zs + zaw
+
+               zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+               za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+               zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt   &
+                         +2098.925 ) *zt+190925.6
+               zk0= ( zb1*zsr + za1 )*zs + zkw
+
+               ! masked in situ density anomaly
+               prd(ji,jj) = ( zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  ) - rau0 )   &
+                          / rau0 * zmask
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               prd(ji,jj) = ( 0.0285 - ralpha * ptem(ji,jj) ) * tmask(ji,jj,1)
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               prd(ji,jj) = ( rbeta * psal(ji,jj) - ralpha * ptem(ji,jj) ) * tmask(ji,jj,1) 
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   CALL prt_ctl(tab2d_1=prd, clinfo1=' eos2d: ')
+
+   END SUBROUTINE eos_insitu_2d
+
+
+   SUBROUTINE eos_bn2( ptem, psal, pn2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_bn2  ***
+      !!
+      !! ** Purpose :   Compute the local Brunt-Vaisala frequency at the time-
+      !!      step of the input arguments
+      !!      
+      !! ** Method :
+      !!       * neos = 0  : UNESCO sea water properties
+      !!         The brunt-vaisala frequency is computed using the polynomial
+      !!      polynomial expression of McDougall (1987):
+      !!            N^2 = grav * beta * ( alpha/beta*dk[ t ] - dk[ s ] )/e3w
+      !!      If lk_zdfddm=T, the heat/salt buoyancy flux ratio Rrau is
+      !!      computed and used in zdfddm module :
+      !!              Rrau = alpha/beta * ( dk[ t ] / dk[ s ] )
+      !!       * neos = 1  : linear equation of state (temperature only)
+      !!            N^2 = grav * ralpha * dk[ t ]/e3w
+      !!       * neos = 2  : linear equation of state (temperature & salinity)
+      !!            N^2 = grav * (ralpha * dk[ t ] - rbeta * dk[ s ] ) / e3w
+      !!      The use of potential density to compute N^2 introduces e r r o r
+      !!      in the sign of N^2 at great depths. We recommand the use of 
+      !!      neos = 0, except for academical studies.
+      !!        Macro-tasked on horizontal slab (jk-loop)
+      !!      N.B. N^2 is set to zero at the first level (JK=1) in inidtr
+      !!      and is never used at this level.
+      !!
+      !! ** Action  : - pn2 : the brunt-vaisala frequency
+      !!
+      !! References :
+      !!      McDougall, T. J., J. Phys. Oceanogr., 17, 1950-1964, 1987.
+      !!
+      !! History :
+      !!   6.0  !  94-07  (G. Madec, M. Imbard)  Original code
+      !!   8.0  !  97-07  (G. Madec) introduction of statement functions
+      !!   8.5  !  02-07  (G. Madec) Free form, F90
+      !!   8.5  !  02-08  (G. Madec) introduction of arguments
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                           &  ! potential temperature
+         psal                               ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         pn2                               ! Brunt-Vaisala frequency
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   &
+         zgde3w, zt, zs, zh,  &  ! temporary scalars 
+         zalbet, zbeta           !    "         "
+#if defined key_zdfddm
+      REAL(wp) ::   zds          ! temporary scalars
+#endif
+      !!----------------------------------------------------------------------
+      !!  OPA8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      ! pn2 : first and last levels
+      ! ---------------------------
+      ! bn^2=0. at jk=1 and jpk set in inidtr.F : no computation
+
+
+      ! pn2 : interior points only (2=< jk =< jpkm1 )
+      ! -------------------------- 
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk)
+                  zt = 0.5 * ( ptem(ji,jj,jk) + ptem(ji,jj,jk-1) )          ! potential temperature at w-point
+                  zs = 0.5 * ( psal(ji,jj,jk) + psal(ji,jj,jk-1) ) - 35.0   ! salinity anomaly (s-35) at w-point
+                  zh = fsdepw(ji,jj,jk)                                     ! depth in meters  at w-point
+
+                  zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
+                     &                               - 0.203814e-03 ) * zt   &
+                     &                               + 0.170907e-01 ) * zt   &
+                     &   + 0.665157e-01                                      &
+                     &   +     ( - 0.678662e-05 * zs                         &
+                     &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
+                     &   +   ( ( - 0.302285e-13 * zh                         &
+                     &           - 0.251520e-11 * zs                         &
+                     &           + 0.512857e-12 * zt * zt           ) * zh   &
+                     &           - 0.164759e-06 * zs                         &
+                     &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
+                     &                               + 0.380374e-04 ) * zh
+
+                  zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
+                     &                            - 0.301985e-05 ) * zt      &
+                     &   + 0.785567e-03                                      &
+                     &   + (     0.515032e-08 * zs                           &
+                     &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
+                     &   +(  (   0.121551e-17 * zh                           &
+                     &         - 0.602281e-15 * zs                           &
+                     &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
+                     &                             + 0.408195e-10   * zs     &
+                     &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
+                     &                             - 0.121555e-07 ) * zh
+
+                  pn2(ji,jj,jk) = zgde3w * zbeta * tmask(ji,jj,jk)           &   ! N^2 
+                     &          * ( zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )   &
+                     &                     - ( psal(ji,jj,jk-1) - psal(ji,jj,jk) ) )
+#if defined key_zdfddm
+                  !                                                         !!bug **** caution a traiter zds=dk[S]= 0 !!!!
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )                    ! Rrau = (alpha / beta) (dk[t] / dk[s])
+                  IF ( ABS( zds) <= 1.e-20 ) zds = 1.e-20
+                  rrau(ji,jj,jk) = zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  pn2(ji,jj,jk) = zgde3w * ralpha * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  pn2(ji,jj,jk) = zgde3w * (  ralpha * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )   &
+                     &                      - rbeta  * ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )  )
+               END DO
+            END DO
+#if defined key_zdfddm
+            !                                                ! Rrau = (alpha / beta) (dk[t] / dk[s])
+            zalbet = ralpha / rbeta
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )
+                  IF ( ABS( zds ) <= 1.e-20 ) zds = 1.e-20
+                  rrau(ji,jj,jk) = zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+               END DO
+            END DO
+#endif
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=pn2, clinfo1=' bn2  : ', ovlap=1, kdim=jpk)
+#if defined key_zdfddm
+         CALL prt_ctl(tab3d_1=rrau, clinfo1=' rrau : ', ovlap=1, kdim=jpk)
+#endif
+      ENDIF
+
+   END SUBROUTINE eos_bn2
+
+
+   SUBROUTINE eos_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_init  ***
+      !!
+      !! ** Purpose :   initializations for the equation of state
+      !!
+      !! ** Method  :   Read the namelist nam_eos
+      !!
+      !! ** Action  :   blahblah....
+      !!
+      !! History :
+      !!   8.5  !  02-10  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      NAMELIST/nam_eos/ neos, ralpha, rbeta
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      ! set the initialization flag to 1
+      neos_init = 1           ! indicate that the initialization has been done
+
+      ! namelist nam_eos : ocean physical parameters
+
+      ! Read Namelist nam_eos : equation of state
+      REWIND( numnam )
+      READ  ( numnam, nam_eos )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'eos_init : equation of state'
+         WRITE(numout,*) '~~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_eos : set eos parameters'
+         WRITE(numout,*)
+         WRITE(numout,*) '             flag for eq. of state and N^2  neos   = ', neos
+         WRITE(numout,*) '             thermal exp. coef. (linear)    ralpha = ', ralpha
+         WRITE(numout,*) '             saline  exp. coef. (linear)    rbeta  = ', rbeta
+         WRITE(numout,*)
+      ENDIF
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+         IF(lwp) WRITE(numout,*) '          use of Jackett & McDougall (1994) equation of state and'
+         IF(lwp) WRITE(numout,*) '                 McDougall (1987) Brunt-Vaisala frequency'
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T) = rau0 * ( 1.0285 - ralpha * T )'
+         IF( lk_zdfddm ) CALL ctl_stop( '          double diffusive mixing parameterization requires',   &
+              &                         ' that T and S are used as state variables' )
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T,S) = rau0 * ( rbeta * S - ralpha * T )'
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE eos_init
+
+   !!======================================================================
+END MODULE eosbn2  
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/istate.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/istate.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/istate.F90	(revision 4536)
@@ -0,0 +1,73 @@
+MODULE istate
+   !!======================================================================
+   !!                     ***  MODULE  istate  ***
+   !! Ocean state   :  initial state setting
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   istate_init   : initial state setting
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE daymod          ! 
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC istate_init   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE istate_init
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_init  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers.
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   4.0  !  91-03  ()  Original code
+      !!        !  91-11  (G. Madec)
+      !!   9.0  !  03-09  (G. Madec)  F90: Free form, modules, orthogonality
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      !!----------------------------------------------------------------------
+
+
+      ! Initialization to zero
+      ! ----------------------
+
+      !     before fields       !       now fields        !      after fields       !
+      ;   un   (:,:,:) = 0.e0   ;   ua   (:,:,:) = 0.e0
+      ;   vn   (:,:,:) = 0.e0   ;   va   (:,:,:) = 0.e0
+      ;                         ;   wn   (:,:,:) = 0.e0   
+      ;   hdivn(:,:,:) = 0.e0   ;
+
+      ;   tn   (:,:,:) = 0.e0   ;   ta   (:,:,:) = 0.e0
+      ;   sn   (:,:,:) = 0.e0   ;   sa   (:,:,:) = 0.e0
+
+      rhd  (:,:,:) = 0.e0
+      rhop (:,:,:) = 0.e0
+      rn2  (:,:,:) = 0.e0 
+
+
+   END SUBROUTINE istate_init
+
+   !!=====================================================================
+END MODULE istate
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lbclnk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lbclnk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lbclnk.F90	(revision 4536)
@@ -0,0 +1,714 @@
+MODULE lbclnk
+   !!======================================================================
+   !!                       ***  MODULE  lbclnk  ***
+   !! Ocean        : lateral boundary conditions
+   !!=====================================================================
+#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR      MPI massively parallel processing library
+   !!   'key_mpp_shmem'         SHMEM massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk      : generic interface for mpp_lnk_3d and mpp_lnk_2d
+   !!                  routines defined in lib_mpp
+   !!   lbc_lnk_e    : generic interface for mpp_lnk_2d_e
+   !!                   routinee defined in lib_mpp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE lib_mpp          ! distributed memory computing library
+
+   INTERFACE lbc_lnk
+      MODULE PROCEDURE mpp_lnk_3d_gather, mpp_lnk_3d, mpp_lnk_2d
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e
+      MODULE PROCEDURE mpp_lnk_2d_e
+   END INTERFACE
+
+   PUBLIC lbc_lnk       ! ocean lateral boundary conditions
+   PUBLIC lbc_lnk_e
+   !!----------------------------------------------------------------------
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                              shared memory computing
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk      : generic interface for lbc_lnk_3d and lbc_lnk_2d
+   !!   lbc_lnk_3d   : set the lateral boundary condition on a 3D variable
+   !!                  on OPA ocean mesh
+   !!   lbc_lnk_2d   : set the lateral boundary condition on a 2D variable
+   !!                  on OPA ocean mesh
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE lbc_lnk
+      MODULE PROCEDURE lbc_lnk_3d_gather, lbc_lnk_3d, lbc_lnk_2d
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e
+      MODULE PROCEDURE lbc_lnk_2d
+   END INTERFACE
+
+   PUBLIC lbc_lnk       ! ocean/ice  lateral boundary conditions
+   PUBLIC  lbc_lnk_e 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnk_3d_gather  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type1, cd_type2       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d1, pt3d2          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+
+      
+      !! * Local declarations
+      INTEGER  ::   ji, jk
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+      
+      !                                                      ! ===============
+      DO jk = 1, jpk                                         ! Horizontal slab
+         !                                                   ! ===============
+
+         !                                     ! East-West boundaries
+         !                                     ! ====================
+         SELECT CASE ( nperio )
+
+         CASE ( 1 , 4 , 6 )                    ! * cyclic east-west
+            pt3d1( 1 ,:,jk) = pt3d1(jpim1,:,jk)          ! all points
+            pt3d1(jpi,:,jk) = pt3d1(  2  ,:,jk)
+            pt3d2( 1 ,:,jk) = pt3d2(jpim1,:,jk)          
+            pt3d2(jpi,:,jk) = pt3d2(  2  ,:,jk)
+
+         CASE DEFAULT                          ! * closed
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d1( 1 ,:,jk) = 0.e0
+               pt3d1(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d1(jpi,:,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d2( 1 ,:,jk) = 0.e0
+               pt3d2(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d2(jpi,:,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+
+         CASE ( 2 )                            ! *  south symmetric
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d1(:, 1 ,jk) = pt3d1(:,3,jk)
+               pt3d1(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d1(:, 1 ,jk) = psgn * pt3d1(:,2,jk)
+               pt3d1(:,jpj,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d2(:, 1 ,jk) = pt3d2(:,3,jk)
+               pt3d2(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d2(:, 1 ,jk) = psgn * pt3d2(:,2,jk)
+               pt3d2(:,jpj,jk) = 0.e0
+            END SELECT
+
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+
+            pt3d1( 1 ,jpj,jk) = 0.e0
+            pt3d1(jpi,jpj,jk) = 0.e0
+            pt3d2( 1 ,jpj,jk) = 0.e0
+            pt3d2(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d1(ji,jpjm1,jk) = psgn * pt3d1(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d1(ji,jpjm1,jk) = psgn * pt3d1(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d1(ji,  1  ,jk) = 0.e0
+                     pt3d1(ji,jpj-1,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d1(ji,jpj-1,jk) = psgn * pt3d1(iju,jpj-2,jk)
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d2(ji,jpjm1,jk) = psgn * pt3d2(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d2(ji,jpjm1,jk) = psgn * pt3d2(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d2(ji,  1  ,jk) = 0.e0
+                     pt3d2(ji,jpj-1,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d2(ji,jpj-1,jk) = psgn * pt3d2(iju,jpj-2,jk)
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+
+            pt3d1( 1 ,jpj,jk) = 0.e0
+            pt3d1(jpi,jpj,jk) = 0.e0
+            pt3d2( 1 ,jpj,jk) = 0.e0
+            pt3d2(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji, 1 ,jk) = 0.e0
+                     pt3d1(ji,jpj,jk) = psgn * pt3d1(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d1(ji, 1 ,jk) = 0.e0
+                     pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d1(ji,jpjm1,jk) = psgn * pt3d1(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji,jpjm1,jk) = psgn * pt3d1(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji, 1 ,jk) = 0.e0
+                     pt3d2(ji,jpj,jk) = psgn * pt3d2(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d2(ji, 1 ,jk) = 0.e0
+                     pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d2(ji,jpjm1,jk) = psgn * pt3d2(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji,jpjm1,jk) = psgn * pt3d2(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+
+         CASE DEFAULT                          ! *  closed
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d1(:, 1 ,jk) = 0.e0
+               pt3d1(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d1(:,jpj,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d2(:, 1 ,jk) = 0.e0
+               pt3d2(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d2(:,jpj,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+         !                                                   ! ===============
+      END DO                                                 !   End of slab
+      !                                                      ! ===============
+
+   END SUBROUTINE lbc_lnk_3d_gather
+
+
+   SUBROUTINE lbc_lnk_3d( pt3d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnk_3d  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jk
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE
+      
+      !                                                      ! ===============
+      DO jk = 1, jpk                                         ! Horizontal slab
+         !                                                   ! ===============
+
+         !                                     ! East-West boundaries
+         !                                     ! ====================
+         SELECT CASE ( nperio )
+
+         CASE ( 1 , 4 , 6 )                    ! * cyclic east-west
+            pt3d( 1 ,:,jk) = pt3d(jpim1,:,jk)          ! all points
+            pt3d(jpi,:,jk) = pt3d(  2  ,:,jk)
+
+         CASE DEFAULT                          ! * closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d( 1 ,:,jk) = 0.e0
+               pt3d(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d(jpi,:,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+
+         CASE ( 2 )                            ! *  south symmetric
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d(:, 1 ,jk) = pt3d(:,3,jk)
+               pt3d(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d(:, 1 ,jk) = psgn * pt3d(:,2,jk)
+               pt3d(:,jpj,jk) = 0.e0
+            END SELECT
+
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+
+            pt3d( 1 ,jpj,jk) = 0.e0
+            pt3d(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d(ji,jpjm1,jk) = psgn * pt3d(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d(ji,jpjm1,jk) = psgn * pt3d(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d(ji,  1  ,jk) = 0.e0
+                     pt3d(ji,jpj-1,jk) = psgn * pt3d(ijt,jpj-2,jk)
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d(ji,jpj-1,jk) = psgn * pt3d(iju,jpj-2,jk)
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+
+            pt3d( 1 ,jpj,jk) = 0.e0
+            pt3d(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji, 1 ,jk) = 0.e0
+                     pt3d(ji,jpj,jk) = psgn * pt3d(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d(ji, 1 ,jk) = 0.e0
+                     pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d(ji,jpjm1,jk) = psgn * pt3d(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji,jpjm1,jk) = psgn * pt3d(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+
+         CASE DEFAULT                          ! *  closed
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d(:, 1 ,jk) = 0.e0
+               pt3d(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d(:,jpj,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+         !                                                   ! ===============
+      END DO                                                 !   End of slab
+      !                                                      ! ===============
+   ENDIF
+   END SUBROUTINE lbc_lnk_3d
+
+
+   SUBROUTINE lbc_lnk_2d( pt2d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE lbc_lnk_2d  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!        !  01-05  (E. Durand)  correction
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-point
+         !             !   = T , U , V , F or W  gridpoints
+         !             !   = I sea-ice U-V gridpoint (= F ocean grid point with indice shift)
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is modified following the type of b.c. used
+         !             !   = 1 , no sign change
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+
+      !! * Local declarations
+      INTEGER  ::   ji
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE      
+      
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      SELECT CASE ( nperio )
+
+      CASE ( 1 , 4 , 6 )                       ! * cyclic east-west
+         pt2d( 1 ,:) = pt2d(jpim1,:)
+         pt2d(jpi,:) = pt2d(  2  ,:)
+
+      CASE DEFAULT                             ! * closed 
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'V' , 'W' )                ! T-, U-, V-, W-points
+            pt2d( 1 ,:) = 0.e0
+            pt2d(jpi,:) = 0.e0
+         CASE ( 'F' )                                  ! F-point, ice U-V point
+            pt2d(jpi,:) = 0.e0 
+         CASE ( 'I' )                                  ! F-point, ice U-V point
+            pt2d( 1 ,:) = 0.e0 
+            pt2d(jpi,:) = 0.e0 
+         END SELECT
+
+      END SELECT
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( nperio )
+
+      CASE ( 2 )                               ! * South symmetric
+
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'W' )                      ! T-, U-, W-points
+            pt2d(:, 1 ) = pt2d(:,3)
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'V' , 'F' , 'I' )                      ! V-, F-points, ice U-V point
+            pt2d(:, 1 ) = psgn * pt2d(:,2)
+            pt2d(:,jpj) = 0.e0
+         END SELECT
+
+      CASE ( 3 , 4 )                           ! * North fold  T-point pivot
+
+         pt2d( 1 , 1 ) = 0.e0        !!!!!  bug gm ??? !Edmee
+         pt2d( 1 ,jpj) = 0.e0
+         pt2d(jpi,jpj) = 0.e0
+
+         SELECT CASE ( cd_type )
+
+         CASE ( 'T' , 'W' )                            ! T-, W-point
+            DO ji = 2, jpi
+               ijt = jpi-ji+2
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi-ji+2
+               pt2d(ji,jpjm1) = psgn * pt2d(ijt,jpjm1)
+            END DO
+
+         CASE ( 'U' )                                  ! U-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-2)
+            END DO
+            DO ji = jpi/2, jpi-1
+               iju = jpi-ji+1
+               pt2d(ji,jpjm1) = psgn * pt2d(iju,jpjm1)
+            END DO
+
+         CASE ( 'V' )                                  ! V-point
+            DO ji = 2, jpi
+               ijt = jpi-ji+2
+               pt2d(ji, 1   ) = 0.e0
+               pt2d(ji,jpj-1) = psgn * pt2d(ijt,jpj-2)
+               pt2d(ji,jpj  ) = psgn * pt2d(ijt,jpj-3)
+            END DO
+
+         CASE ( 'F' )                                  ! F-point
+            DO ji = 1, jpi-1
+               iju = jpi - ji + 1
+               pt2d(ji,jpj-1) = psgn * pt2d(iju,jpj-2)
+               pt2d(ji,jpj  ) = psgn * pt2d(iju,jpj-3)
+            END DO
+
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d(:, 1 ) = 0.e0
+            pt2d(2,jpj) = psgn * pt2d(3,jpj-1)
+            DO ji = 3, jpi
+               iju = jpi - ji + 3
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-1)
+            END DO
+
+         END SELECT
+
+      CASE ( 5 , 6 )                           ! * North fold  F-point pivot
+
+         pt2d( 1 , 1 ) = 0.e0           !!bug  ???
+         pt2d( 1 ,jpj) = 0.e0
+         pt2d(jpi,jpj) = 0.e0
+
+         SELECT CASE ( cd_type )
+
+         CASE ( 'T' , 'W' )                            ! T-, W-point
+            DO ji = 1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-1)
+            END DO
+
+         CASE ( 'U' )                                  ! U-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-1)
+            END DO
+
+         CASE ( 'V' )                                  ! V-point
+            DO ji = 1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji,jpjm1) = psgn * pt2d(ijt,jpjm1)
+            END DO
+
+         CASE ( 'F' )                                  ! F-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji
+               pt2d(ji,jpj  ) = psgn * pt2d(iju,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi-1
+               iju = jpi-ji
+               pt2d(ji,jpjm1) = psgn * pt2d(iju,jpjm1)
+            END DO
+
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d( : , 1 ) = 0.e0
+            pt2d( 2 ,jpj) = 0.e0
+            DO ji = 2 , jpim1
+               ijt = jpi - ji + 2
+               pt2d(ji,jpj)= 0.5 * ( pt2d(ji,jpjm1) + psgn * pt2d(ijt,jpjm1) )
+            END DO
+
+         END SELECT
+
+      CASE DEFAULT                             ! * closed
+
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'V' , 'W' )                ! T-, U-, V-, W-points
+            pt2d(:, 1 ) = 0.e0
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'F' )                                  ! F-point
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d(:, 1 ) = 0.e0
+            pt2d(:,jpj) = 0.e0
+         END SELECT
+
+      END SELECT
+
+      ENDIF
+      
+   END SUBROUTINE lbc_lnk_2d
+
+#endif
+
+   !!======================================================================
+END MODULE lbclnk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_cray.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_cray.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_cray.f90	(revision 4536)
@@ -0,0 +1,60 @@
+!  Cray subroutines or functions used by OPA model and possibly 
+!  not found on other platforms.
+!
+!  check their existence
+!  
+!  sdot
+!  wheneq
+!  saxpy
+!  isrchne
+!!----------------------------------------------------------------------
+!!  OPA 9.0 , LOCEAN-IPSL (2005) 
+!! $Header$ 
+!! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+!!----------------------------------------------------------------------
+     FUNCTION sdot( I, X, J, Y, K )
+        DIMENSION X(1), Y(1)
+        SDOT = 0.
+        DO N = 1, I
+        SDOT = SDOT + X(1+(N-1)*J) * Y(1+(N-1)*K)
+        END DO
+     END FUNCTION sdot
+!---------------------------------------------------------
+     SUBROUTINE wheneq ( i, x, j, t, ind, nn )
+        IMPLICIT NONE
+
+        INTEGER , INTENT (  in ) :: i, j
+        INTEGER , INTENT ( out ) :: nn
+        REAL    , INTENT (  in ), DIMENSION (1+(i-1)*j) :: x
+        REAL    , INTENT (  in ) :: t
+        INTEGER , INTENT ( out ), DIMENSION (1+(i-1)*j) :: ind
+        INTEGER :: n, k
+        nn = 0
+        DO n = 1, i
+          k = 1 + (n-1) * j
+          IF ( x ( k) == t ) THEN 
+              nn = nn + 1
+              ind (nn) = k
+          ENDIF
+        END DO 
+
+     END SUBROUTINE wheneq
+!---------------------------------------------------------
+     SUBROUTINE saxpy( I, A, X, J, Y, K )
+        DIMENSION X(1),Y(1)
+        DO N = 1, I
+           Y(1+(N-1)*K)=A*X(1+(N-1)*J)+Y(1+(N-1)*K)
+        END DO
+     END SUBROUTINE saxpy
+!---------------------------------------------------------
+     FUNCTION isrchne( K, X, I, B )
+        DIMENSION X(1)
+        DO N = 1, K
+           IF( X(1+(N-1)*I) /= B ) THEN
+              ISRCHNE = N
+              RETURN
+           ELSE
+              ISRCHNE = N + 1
+           ENDIF
+        END DO
+     END FUNCTION isrchne
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_isml.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_isml.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_isml.f90	(revision 4536)
@@ -0,0 +1,674 @@
+!
+! subroutines for PCG or SOR solvers
+! (used if the ISML library is not available)
+!
+! linrg
+!   gauss
+!   vmov
+!   desremopt
+!   dtrsv
+!   dger
+!   xerbla
+!   lsame
+! folr (empty)
+!
+!!----------------------------------------------------------------------
+!!  OPA 9.0 , LOCEAN-IPSL (2005) 
+!! $Header$ 
+!! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+!!----------------------------------------------------------------------
+   SUBROUTINE linrg(kn,pa,klda,painv,kldainv)
+
+      !! compute inverse matrix
+
+      IMPLICIT NONE 
+      INTEGER kn,klda,kldainv
+      REAL (kind=8) ::   pa(kn,kn),painv(kn,kn)
+      REAL (kind=8) ::   zb(kn,kn)
+      REAL (kind=8) ::   zv(kn)
+      INTEGER iplin(kn)
+      INTEGER ji
+
+      IF( kn /= klda .OR. kn /= kldainv ) THEN 
+          write(0,*)'change your parameters'
+          STOP 
+      ENDIF 
+
+      CALL vmov( kn*kn, pa, painv )
+
+      CALL gauss( kn, painv, iplin, zv )
+
+      zb(:,:) = 0.e0   
+      DO ji = 1, kn
+        zb(ji,ji) = 1.e0
+        CALL desremopt( kn, painv, iplin, zb(1,ji), zb(1,ji), zv )
+      END DO 
+      CALL vmov( kn*kn, zb, painv )
+
+   END SUBROUTINE linrg
+!---------------------------------------------------------
+   SUBROUTINE gauss(kn,pa,kplin,pv)
+
+      IMPLICIT NONE 
+      INTEGER kn
+      INTEGER ji,jj,jk
+      INTEGER ik,ipp
+      REAL (kind=8) ::   pa(kn,kn),pv(kn)
+!!    REAL (kind=8) ::   zpivmax,zalpha
+      REAL (kind=8) ::   zalpha
+      INTEGER kplin(kn)
+      INTEGER isamax
+      EXTERNAL isamax
+
+!  factorisation de Gauss de la matrice a avec pivot partiel . 
+!  initialisation des pointeurs .
+      DO ji=1,kn
+        kplin(ji)=ji
+      END DO 
+      DO jk=1,kn-1
+!  recherche du pivot maximal .
+!!      ik=jk
+!!      zpivmax=dabs(pa(jk,jk))
+!!        DO ji=jk,kn
+!!          IF(dabs(pa(ji,jk)) > zpivmax) THEN 
+!!            zpivmax=dabs(pa(ji,jk))
+!!            ik=ji
+!!          ENDIF 
+!!        END DO 
+        ik=isamax( kn-jk+1, pa(jk,jk) )+jk-1
+!  permutation de la ligne jk et de la ligne ik .
+        IF(jk == 58) THEN
+            PRINT *,'matrix ',(pa(jk,ji),ji=1,kn)
+            PRINT *,' pivot ',ik,kplin(ik),kplin(jk)
+        ENDIF 
+        ipp=kplin(ik)
+        kplin(ik)=kplin(jk)
+        kplin(jk)=ipp
+        DO jj=1,kn
+          pv(jj)=pa(ik,jj)
+          pa(ik,jj)=pa(jk,jj)
+          pa(jk,jj)=pv(jj)
+        END DO 
+        IF(jk == 58) THEN
+            PRINT *,'matrix ',(pa(jk,ji),ji=1,kn)
+            PRINT *,' pivot ',ik,kplin(ik),kplin(jk)
+        ENDIF 
+!  calcul des coefficients de la colonne k ligne a ligne .
+        DO ji=jk+1,kn
+          IF(pa(jk,jk) == 0) THEN 
+              PRINT *,'probleme diagonale nulle',jk,pa(jk,jk)
+              pa(ji,jk)=pa(ji,jk)/1.E-20
+          ENDIF 
+          IF(pa(jk,jk) /= 0) pa(ji,jk)=pa(ji,jk)/pa(jk,jk)
+        END DO 
+!!        DO ji=jk+1,kn
+!!          DO jj=jk+1,kn
+!!            pa(ji,jj)=pa(ji,jj)-pa(ji,jk)*pa(jk,jj)
+!!          END DO 
+!!        END DO 
+        zalpha=-1.
+        CALL dger(kn-jk,kn-jk,zalpha,pa(jk+1,jk),1,pa(jk,jk+1),kn,   &
+            pa(jk+1,jk+1),kn)
+      END DO 
+
+   END SUBROUTINE gauss
+!---------------------------------------------------------
+   FUNCTION isamax( I, X )
+      DIMENSION X(I)
+      ISAMAX = 0
+      XMIN = -1e+50
+      DO N = 1, I
+         IF(ABS(X(N)) > XMIN ) THEN
+            XMIN = X(N)
+            ISAMAX = N
+         ENDIF
+      END DO
+   END FUNCTION isamax
+!---------------------------------------------------------
+   SUBROUTINE vmov(kn,px,py)
+
+      IMPLICIT NONE 
+      INTEGER kn
+      REAL (kind=8) ::   px(kn),py(kn)
+      INTEGER ji
+
+      DO ji=1,kn
+         py(ji)=px(ji)
+      END DO 
+
+   END SUBROUTINE vmov
+!---------------------------------------------------------
+   subroutine desremopt(n,a,plin,y,x,v)
+      implicit none
+      integer n,i,  j0
+!!    integer n,i,j,j0
+      real (kind=8) ::   a(n,n),x(n),y(n),v(n)
+      integer plin(n)
+!  descente remontee du systeme .
+!  initialisation du vecteur resultat .
+!  prise en compte de la permutation des lignes .
+      do i=1,n
+        v(i)=y(plin(i))
+      end do
+      do i=1,n
+        if(v(i) /= 0.) then
+          j0=i-1
+          goto 1
+        endif
+      end do
+1     continue
+!  descente du systeme L v = v , L est a diagonale unitaire .
+!!      do j=j0+1,n
+!!        do i=j+1,n
+!!          v(i)=v(i)-a(i,j)*v(j)
+!!        end do
+!!      end do
+      call dtrsv('L','N','U',n-j0,a(j0+1,j0+1),n,v(j0+1),1)
+!  remontee du systeme U v = v . 
+!!      do j=n,1,-1
+!!        v(j)=v(j)/a(j,j)
+!!        do i=1,j-1
+!!          v(i)=v(i)-a(i,j)*v(j)
+!!        end do
+!!      end do          
+      call dtrsv('U','N','N',n,a,n,v,1)
+!  prise en compte de la permutation des colonnes .
+      do i=1,n
+        x(i)=v(i)
+      end do
+
+   end SUBROUTINE desremopt
+!---------------------------------------------------------
+   SUBROUTINE DTRSV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
+!!    .. Scalar Arguments ..
+      INTEGER            INCX, LDA, N
+      CHARACTER (len=1) ::   DIAG, TRANS, UPLO
+!!    .. Array Arguments ..
+!     DOUBLE PRECISION   A( LDA, * ), X( * )
+      REAL (kind=8) ::     A( LDA, * ), X( * )
+!!    ..
+
+!! Purpose
+!! =======
+
+!! DTRSV  solves one of the systems of equations
+
+!!    A*x = b,   or   A'*x = b,
+
+!! where b and x are n element vectors and A is an n by n unit, or
+!! non-unit, upper or lower triangular matrix.
+
+!! No test for singularity or near-singularity is included in this
+!! routine. Such tests must be performed before calling this routine.
+
+!! Parameters
+!! ==========
+
+!! UPLO   - CHARACTER*1.
+!!          On entry, UPLO specifies whether the matrix is an upper or
+!!          lower triangular matrix as follows:
+
+!!             UPLO = 'U' or 'u'   A is an upper triangular matrix.
+
+!!             UPLO = 'L' or 'l'   A is a lower triangular matrix.
+
+!!          Unchanged on exit.
+
+!! TRANS  - CHARACTER*1.
+!!          On entry, TRANS specifies the equations to be solved as
+!!          follows:
+
+!!             TRANS = 'N' or 'n'   A*x = b.
+
+!!             TRANS = 'T' or 't'   A'*x = b.
+
+!!             TRANS = 'C' or 'c'   A'*x = b.
+
+!!          Unchanged on exit.
+
+!! DIAG   - CHARACTER*1.
+!!          On entry, DIAG specifies whether or not A is unit
+!!          triangular as follows:
+
+!!             DIAG = 'U' or 'u'   A is assumed to be unit triangular.
+
+!!             DIAG = 'N' or 'n'   A is not assumed to be unit
+!!                                 triangular.
+
+!!          Unchanged on exit.
+
+!! N      - INTEGER.
+!!          On entry, N specifies the order of the matrix A.
+!!          N must be at least zero.
+!!          Unchanged on exit.
+
+!! A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
+!!          Before entry with  UPLO = 'U' or 'u', the leading n by n
+!!          upper triangular part of the array A must contain the upper
+!!          triangular matrix and the strictly lower triangular part of
+!!          A is not referenced.
+!!          Before entry with UPLO = 'L' or 'l', the leading n by n
+!!          lower triangular part of the array A must contain the lower
+!!          triangular matrix and the strictly upper triangular part of
+!!          A is not referenced.
+!!          Note that when  DIAG = 'U' or 'u', the diagonal elements of
+!!          A are not referenced either, but are assumed to be unity.
+!!          Unchanged on exit.
+
+!! LDA    - INTEGER.
+!!          On entry, LDA specifies the first dimension of A as declared
+!!          in the calling (sub) program. LDA must be at least
+!!          max( 1, n ).
+!!          Unchanged on exit.
+
+!! X      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( n - 1 )*abs( INCX ) ).
+!!          Before entry, the incremented array X must contain the n
+!!          element right-hand side vector b. On exit, X is overwritten
+!!          with the solution vector x.
+
+!! INCX   - INTEGER.
+!!          On entry, INCX specifies the increment for the elements of
+!!          X. INCX must not be zero.
+!!          Unchanged on exit.
+
+
+!! Level 2 Blas routine.
+
+!! -- Written on 22-October-1986.
+!!    Jack Dongarra, Argonne National Lab.
+!!    Jeremy Du Croz, Nag Central Office.
+!!    Sven Hammarling, Nag Central Office.
+!!    Richard Hanson, Sandia National Labs.
+
+
+!!    .. Parameters ..
+!     DOUBLE PRECISION   ZERO
+!     PARAMETER        ( ZERO = 0.0D+0 )
+      REAL (kind=8) ::                 ZERO
+      PARAMETER        ( ZERO = 0.0 )
+!!    .. Local Scalars ..
+!     DOUBLE PRECISION   TEMP
+      REAL (kind=8) ::                 TEMP
+      INTEGER            I, INFO, IX, J, JX, KX
+      LOGICAL            NOUNIT
+!!    .. External Functions ..
+      LOGICAL            LSAME
+      EXTERNAL           LSAME
+!!    .. External Subroutines ..
+      EXTERNAL           XERBLA
+!!    .. Intrinsic Functions ..
+      INTRINSIC          MAX
+!!    ..
+!!    .. Executable Statements ..
+
+!!    Test the input parameters.
+
+      INFO = 0
+      IF     ( .NOT.LSAME( UPLO , 'U' ).AND.   &
+               .NOT.LSAME( UPLO , 'L' )      )THEN
+         INFO = 1
+      ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.   &
+               .NOT.LSAME( TRANS, 'T' ).AND.   &
+               .NOT.LSAME( TRANS, 'C' )      )THEN
+         INFO = 2
+      ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.   &
+               .NOT.LSAME( DIAG , 'N' )      )THEN
+         INFO = 3
+      ELSE IF( N < 0 )THEN
+         INFO = 4
+      ELSE IF( LDA < MAX( 1, N ) )THEN
+         INFO = 6
+      ELSE IF( INCX == 0 )THEN
+         INFO = 8
+      END IF
+      IF( INFO /= 0 )THEN
+         CALL XERBLA( 'DTRSV ', INFO )
+         RETURN
+      END IF
+
+!!    Quick return if possible.
+
+      IF( N == 0 )   RETURN
+
+      NOUNIT = LSAME( DIAG, 'N' )
+
+!!    Set up the start point in X if the increment is not unity. This
+!!    will be  ( N - 1 )*INCX  too small for descending loops.
+
+      IF( INCX <= 0 )THEN
+         KX = 1 - ( N - 1 )*INCX
+      ELSE IF( INCX /= 1 )THEN
+         KX = 1
+      END IF
+
+!!    Start the operations. In this version the elements of A are
+!!    accessed sequentially with one pass through A.
+
+      IF( LSAME( TRANS, 'N' ) )THEN
+
+!!       Form  x := inv( A )*x.
+
+         IF( LSAME( UPLO, 'U' ) )THEN
+            IF( INCX == 1 )THEN
+               DO 20, J = N, 1, -1
+                  IF( X( J ) /= ZERO )THEN
+                     IF( NOUNIT )   X( J ) = X( J )/A( J, J )
+                     TEMP = X( J )
+                     DO 10, I = J - 1, 1, -1
+                        X( I ) = X( I ) - TEMP*A( I, J )
+   10                CONTINUE
+                  END IF
+   20          CONTINUE
+            ELSE
+               JX = KX + ( N - 1 )*INCX
+               DO 40, J = N, 1, -1
+                  IF( X( JX ) /= ZERO )THEN
+                     IF( NOUNIT )  X( JX ) = X( JX )/A( J, J )
+                     TEMP = X( JX )
+                     IX   = JX
+                     DO 30, I = J - 1, 1, -1
+                        IX      = IX      - INCX
+                        X( IX ) = X( IX ) - TEMP*A( I, J )
+   30                CONTINUE
+                  END IF
+                  JX = JX - INCX
+   40          CONTINUE
+            END IF
+         ELSE
+            IF( INCX == 1 )THEN
+               DO 60, J = 1, N
+                  IF( X( J ) /= ZERO )THEN
+                     IF( NOUNIT )   X( J ) = X( J )/A( J, J )
+                     TEMP = X( J )
+                     DO 50, I = J + 1, N
+                        X( I ) = X( I ) - TEMP*A( I, J )
+   50                CONTINUE
+                  END IF
+   60          CONTINUE
+            ELSE
+               JX = KX
+               DO 80, J = 1, N
+                  IF( X( JX ) /= ZERO )THEN
+                     IF( NOUNIT )   X( JX ) = X( JX )/A( J, J )
+                     TEMP = X( JX )
+                     IX   = JX
+                     DO 70, I = J + 1, N
+                        IX      = IX      + INCX
+                        X( IX ) = X( IX ) - TEMP*A( I, J )
+   70                CONTINUE
+                  END IF
+                  JX = JX + INCX
+   80          CONTINUE
+            END IF
+         END IF
+      ELSE
+
+!!       Form  x := inv( A' )*x.
+
+         IF( LSAME( UPLO, 'U' ) )THEN
+            IF( INCX == 1 )THEN
+               DO 100, J = 1, N
+                  TEMP = X( J )
+                  DO 90, I = 1, J - 1
+                     TEMP = TEMP - A( I, J )*X( I )
+   90             CONTINUE
+                  IF( NOUNIT )   TEMP = TEMP/A( J, J )
+                  X( J ) = TEMP
+  100          CONTINUE
+            ELSE
+               JX = KX
+               DO 120, J = 1, N
+                  TEMP = X( JX )
+                  IX   = KX
+                  DO 110, I = 1, J - 1
+                     TEMP = TEMP - A( I, J )*X( IX )
+                     IX   = IX   + INCX
+  110             CONTINUE
+                  IF( NOUNIT )   TEMP = TEMP/A( J, J )
+                  X( JX ) = TEMP
+                  JX      = JX   + INCX
+  120          CONTINUE
+            END IF
+         ELSE
+            IF( INCX == 1 )THEN
+               DO 140, J = N, 1, -1
+                  TEMP = X( J )
+                  DO 130, I = N, J + 1, -1
+                     TEMP = TEMP - A( I, J )*X( I )
+  130             CONTINUE
+                  IF( NOUNIT )    TEMP = TEMP/A( J, J )
+                  X( J ) = TEMP
+  140          CONTINUE
+            ELSE
+               KX = KX + ( N - 1 )*INCX
+               JX = KX
+               DO 160, J = N, 1, -1
+                  TEMP = X( JX )
+                  IX   = KX
+                  DO 150, I = N, J + 1, -1
+                     TEMP = TEMP - A( I, J )*X( IX )
+                     IX   = IX   - INCX
+  150             CONTINUE
+                  IF( NOUNIT )    TEMP = TEMP/A( J, J )
+                  X( JX ) = TEMP
+                  JX      = JX   - INCX
+  160          CONTINUE
+            END IF
+         END IF
+      END IF
+
+   END SUBROUTINE DTRSV
+!---------------------------------------------------------
+   SUBROUTINE DGER  ( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )
+!!    .. Scalar Arguments ..
+!     DOUBLE PRECISION   ALPHA
+      REAL (kind=8) ::                 ALPHA
+      INTEGER            INCX, INCY, LDA, M, N
+!!    .. Array Arguments ..
+!     DOUBLE PRECISION   A( LDA, * ), X( * ), Y( * )
+      REAL (kind=8) ::   A( LDA, * ), X( * ), Y( * )
+!!    ..
+
+!! Purpose
+!! =======
+
+!! DGER   performs the rank 1 operation
+
+!!    A := alpha*x*y' + A,
+
+!! where alpha is a scalar, x is an m element vector, y is an n element
+!! vector and A is an m by n matrix.
+
+!! Parameters
+!! ==========
+
+!! M      - INTEGER.
+!!          On entry, M specifies the number of rows of the matrix A.
+!!          M must be at least zero.
+!!          Unchanged on exit.
+
+!! N      - INTEGER.
+!!          On entry, N specifies the number of columns of the matrix A.
+!!          N must be at least zero.
+!!          Unchanged on exit.
+
+!! ALPHA  - DOUBLE PRECISION.
+!!          On entry, ALPHA specifies the scalar alpha.
+!!          Unchanged on exit.
+
+!! X      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( m - 1 )*abs( INCX ) ).
+!!          Before entry, the incremented array X must contain the m
+!!          element vector x.
+!!          Unchanged on exit.
+
+!! INCX   - INTEGER.
+!!          On entry, INCX specifies the increment for the elements of
+!!          X. INCX must not be zero.
+!!          Unchanged on exit.
+
+!! Y      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( n - 1 )*abs( INCY ) ).
+!!          Before entry, the incremented array Y must contain the n
+!!          element vector y.
+!!          Unchanged on exit.
+
+!! INCY   - INTEGER.
+!!          On entry, INCY specifies the increment for the elements of
+!!          Y. INCY must not be zero.
+!!          Unchanged on exit.
+
+!! A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
+!!          Before entry, the leading m by n part of the array A must
+!!          contain the matrix of coefficients. On exit, A is
+!!          overwritten by the updated matrix.
+
+!! LDA    - INTEGER.
+!!          On entry, LDA specifies the first dimension of A as declared
+!!          in the calling (sub) program. LDA must be at least
+!!          max( 1, m ).
+!!          Unchanged on exit.
+
+
+!! Level 2 Blas routine.
+
+!! -- Written on 22-October-1986.
+!!    Jack Dongarra, Argonne National Lab.
+!!    Jeremy Du Croz, Nag Central Office.
+!!    Sven Hammarling, Nag Central Office.
+!!    Richard Hanson, Sandia National Labs.
+
+
+!!    .. Parameters ..
+!     DOUBLE PRECISION   ZERO
+!     PARAMETER        ( ZERO = 0.0D+0 )
+      REAL (kind=8) ::                 ZERO
+      PARAMETER        ( ZERO = 0.0 )
+!!    .. Local Scalars ..
+!     DOUBLE PRECISION   TEMP
+      REAL (kind=8) ::                 TEMP
+      INTEGER            I, INFO, IX, J, JY, KX
+!!    .. External Subroutines ..
+      EXTERNAL           XERBLA
+!!    .. Intrinsic Functions ..
+      INTRINSIC          MAX
+!!    ..
+!!    .. Executable Statements ..
+
+!!    Test the input parameters.
+
+      INFO = 0
+      IF     ( M < 0 )THEN
+         INFO = 1
+      ELSE IF( N < 0 )THEN
+         INFO = 2
+      ELSE IF( INCX == 0 )THEN
+         INFO = 5
+      ELSE IF( INCY == 0 )THEN
+         INFO = 7
+      ELSE IF( LDA < MAX( 1, M ) )THEN
+         INFO = 9
+      END IF
+      IF( INFO /= 0 )THEN
+         CALL XERBLA( 'DGER  ', INFO )
+         RETURN
+      END IF
+
+!!    Quick return if possible.
+
+      IF( ( M == 0 ).OR.( N == 0 ).OR.( ALPHA == ZERO ) )   &
+         RETURN
+
+!!    Start the operations. In this version the elements of A are
+!!    accessed sequentially with one pass through A.
+
+      IF( INCY > 0 )THEN
+         JY = 1
+      ELSE
+         JY = 1 - ( N - 1 )*INCY
+      END IF
+      IF( INCX == 1 )THEN
+         DO 20, J = 1, N
+            IF( Y( JY ) /= ZERO )THEN
+               TEMP = ALPHA*Y( JY )
+               DO 10, I = 1, M
+                  A( I, J ) = A( I, J ) + X( I )*TEMP
+   10          CONTINUE
+            END IF
+            JY = JY + INCY
+   20    CONTINUE
+      ELSE
+         IF( INCX > 0 )THEN
+            KX = 1
+         ELSE
+            KX = 1 - ( M - 1 )*INCX
+         END IF
+         DO 40, J = 1, N
+            IF( Y( JY ) /= ZERO )THEN
+               TEMP = ALPHA*Y( JY )
+               IX   = KX
+               DO 30, I = 1, M
+                  A( I, J ) = A( I, J ) + X( IX )*TEMP
+                  IX        = IX        + INCX
+   30          CONTINUE
+            END IF
+            JY = JY + INCY
+   40    CONTINUE
+      END IF
+
+   END SUBROUTINE DGER
+!---------------------------------------------------------
+   SUBROUTINE XERBLA ( SRNAME, INFO )
+!!    ..    Scalar Arguments ..
+      INTEGER            INFO
+      CHARACTER (len=6) ::    SRNAME
+!!    ..
+
+!! Purpose
+!! =======
+
+!! XERBLA  is an error handler for the Level 2 BLAS routines.
+
+!! It is called by the Level 2 BLAS routines if an input parameter is
+!! invalid.
+
+!! Installers should consider modifying the STOP statement in order to
+!! call system-specific exception-handling facilities.
+
+!! Parameters
+!! ==========
+
+!! SRNAME - CHARACTER*6.
+!!          On entry, SRNAME specifies the name of the routine which
+!!          called XERBLA.
+
+!! INFO   - INTEGER.
+!!          On entry, INFO specifies the position of the invalid
+!!          parameter in the parameter-list of the calling routine.
+
+
+!! Auxiliary routine for Level 2 Blas.
+
+!! Written on 20-July-1986.
+
+!!    .. Executable Statements ..
+
+      WRITE (*,99999) SRNAME, INFO
+
+      STOP
+
+99999 FORMAT ( ' ** On entry to ', A6, ' parameter number ', I2,   &
+               ' had an illegal value' )
+
+   END SUBROUTINE XERBLA
+!-----------------------------------------------------------
+   FUNCTION lsame( c1, c2 )
+      logical lsame
+      CHARACTER (len=*), INTENT(in) ::   c1, c2
+      IF( c1 == c2 ) THEN
+          lsame=.TRUE.
+      ELSE
+          lsame=.FALSE.
+      ENDIF
+   END FUNCTION lsame
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_mpp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_mpp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_mpp.F90	(revision 4536)
@@ -0,0 +1,5227 @@
+MODULE lib_mpp
+   !!======================================================================
+   !!                       ***  MODULE  lib_mpp  ***
+   !! Ocean numerics:  massively parallel processing librairy
+   !!=====================================================================
+#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR      MPI massively parallel processing library
+   !!   'key_mpp_shmem'         SHMEM massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!   mynode
+   !!   mpparent
+   !!   mppshmem
+   !!   mpp_lnk     : generic interface (defined in lbclnk) for :
+   !!                 mpp_lnk_2d, mpp_lnk_3d
+   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
+   !!   mpp_lnk_e   : interface defined in lbclnk
+   !!   mpplnks
+   !!   mpprecv
+   !!   mppsend
+   !!   mppscatter
+   !!   mppgather
+   !!   mpp_isl    : generic inteface  for :
+   !!                mppisl_int , mppisl_a_int , mppisl_real, mppisl_a_real
+   !!   mpp_min    : generic interface for : 
+   !!                mppmin_int , mppmin_a_int , mppmin_real, mppmin_a_real
+   !!   mpp_max    : generic interface for :
+   !!                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
+   !!   mppobc     : variant of mpp_lnk for open boundaries
+   !!   mpp_ini_north
+   !!   mpp_lbc_north
+   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo (nsolv=4)
+   !!----------------------------------------------------------------------
+   !! History :
+   !!        !  94 (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!        !  97  (A.M. Treguier)  SHMEM additions
+   !!        !  98  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!   9.0  !  03  (J.-M. Molines, G. Madec)  F90, free form
+   !!        !  04  (R. Bourdalle Badie)  isend option in mpi
+   !!        !  05  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce                    ! ocean space and time domain 
+   USE in_out_manager             ! I/O manager
+
+   IMPLICIT NONE
+
+   PRIVATE
+   PUBLIC  mynode, mpparent, mpp_isl, mpp_min, mpp_max, mpp_sum,  mpp_lbc_north
+   PUBLIC  mpp_lbc_north_e, mpp_minloc, mpp_maxloc, mpp_lnk_3d, mpp_lnk_2d, mpp_lnk_3d_gather, mpp_lnk_2d_e, mpplnks
+   PUBLIC  mpprecv, mppsend, mppscatter, mppgather, mppobc, mpp_ini_north, mppstop, mppsync
+
+   !! * 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_isl
+      MODULE PROCEDURE mppisl_a_int, mppisl_int, mppisl_a_real, mppisl_real
+   END INTERFACE
+   INTERFACE mpp_min
+      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE mppmax_a_real, mppmax_real
+   END INTERFACE
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real
+   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
+
+
+   !! * Share module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.       !: mpp flag
+
+   !! The processor number is a required power of two : 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,...
+   INTEGER, PARAMETER ::   &
+      nprocmax = 2**10,    &  ! maximun dimension
+      ndim_mpp = jpnij        ! dimension for this simulation
+
+#if defined key_mpp_mpi
+   !! ========================= !!
+   !!  MPI  variable definition !!
+   !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
+#  include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
+
+   INTEGER ::   &
+      size,     &  ! number of process
+      rank         ! process number  [ 0 - size-1 ]
+
+   ! variables used in case of north fold condition in mpp_mpi with jpni > 1
+   INTEGER ::      &       !
+      ngrp_world,  &       ! group ID for the world processors
+      ngrp_north,  &       ! group ID for the northern processors (to be fold)
+      ncomm_north, &       ! communicator made by the processors belonging to ngrp_north
+      ndim_rank_north, &   ! number of 'sea' processor in the northern line (can be /= jpni !)
+      njmppmax             ! value of njmpp for the processors of the northern line
+   INTEGER ::      &       !
+      north_root           ! number (in the comm_world) of proc 0 in the northern comm
+   INTEGER, DIMENSION(:), ALLOCATABLE ::   &
+      nrank_north          ! dimension ndim_rank_north, number of the procs belonging to ncomm_north
+   CHARACTER (len=1) ::  &
+      c_mpi_send = 'S'     ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
+   LOGICAL  ::           &
+      l_isend = .FALSE.    ! isend use indicator (T if c_mpi_send='I')
+
+
+#elif defined key_mpp_shmem
+   !! ========================= !!
+   !! SHMEM variable definition !!
+   !! ========================= !!
+#  include  <fpvm3.h>
+#  include <mpp/shmem.fh>
+
+   CHARACTER (len=80), PARAMETER ::   simfile    = 'pvm3_ndim'   ! file name
+   CHARACTER (len=47), PARAMETER ::   executable = 'opa'         ! executable name
+   CHARACTER, PARAMETER ::            opaall     = ""            ! group name (old def opaall*(*))
+
+   INTEGER, PARAMETER ::   & !! SHMEM control print
+      mynode_print   = 0,  &  ! flag for print, mynode   routine
+      mpprecv_print  = 0,  &  ! flag for print, mpprecv  routine
+      mppsend_print  = 0,  &  ! flag for print, mppsend  routine
+      mppsync_print  = 0,  &  ! flag for print, mppsync  routine
+      mppsum_print   = 0,  &  ! flag for print, mpp_sum  routine
+      mppisl_print   = 0,  &  ! flag for print, mpp_isl  routine
+      mppmin_print   = 0,  &  ! flag for print, mpp_min  routine
+      mppmax_print   = 0,  &  ! flag for print, mpp_max  routine
+      mpparent_print = 0      ! flag for print, mpparent routine
+
+   INTEGER, PARAMETER ::   & !! Variable definition
+      jpvmint = 21            ! ???
+
+   INTEGER, PARAMETER ::   & !! Maximum  dimension of array to sum on the processors
+      jpmsec   = 50000,    &  ! ???
+      jpmpplat =    30,    &  ! ???
+      jpmppsum = MAX( jpisl*jpisl, jpmpplat*jpk, jpmsec )   ! ???
+
+   INTEGER ::   &
+      npvm_ipas ,  &  ! pvm initialization flag
+      npvm_mytid,  &  ! pvm tid
+      npvm_me   ,  &  ! node number [ 0 - nproc-1 ]
+      npvm_nproc,  &  ! real number of nodes
+      npvm_inum       ! ???
+   INTEGER, DIMENSION(0:nprocmax-1) ::   &
+      npvm_tids       ! tids array [ 0 - nproc-1 ]
+
+   INTEGER ::   &
+      nt3d_ipas ,  &  ! pvm initialization flag
+      nt3d_mytid,  &  ! pvm tid
+      nt3d_me   ,  &  ! node number [ 0 - nproc-1 ]
+      nt3d_nproc      ! real number of nodes
+   INTEGER, DIMENSION(0:nprocmax-1) ::   &
+      nt3d_tids       ! tids array [ 0 - nproc-1 ]
+
+   !! real sum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nrs1sync_shmem,   &  ! 
+       nrs2sync_shmem
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wrs1wrk_shmem,    &  !
+       wrs2wrk_shmem        !
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wrstab_shmem         !
+
+   !! minimum and maximum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       ni1sync_shmem,    &  ! 
+       ni2sync_shmem        ! 
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wi1wrk_shmem,     &  !
+       wi2wrk_shmem
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wintab_shmem,     &  ! 
+       wi1tab_shmem,     &  ! 
+       wi2tab_shmem         ! 
+       
+       !! value not equal zero for barotropic stream function around islands
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       ni11sync_shmem,   &  !
+       ni12sync_shmem,   &  !
+       ni21sync_shmem,   &  !
+       ni22sync_shmem       !
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wi11wrk_shmem,    &  ! 
+       wi12wrk_shmem,    &  !
+       wi21wrk_shmem,    &  !
+       wi22wrk_shmem        !
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wiltab_shmem ,    &  !
+       wi11tab_shmem,    &  !
+       wi12tab_shmem,    &  ! 
+       wi21tab_shmem,    &  ! 
+       wi22tab_shmem
+
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       ni11wrk_shmem,    &  !
+       ni12wrk_shmem,    &  !
+       ni21wrk_shmem,    &  !
+       ni22wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       niitab_shmem ,    &  !
+       ni11tab_shmem,    &  !
+       ni12tab_shmem        !
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nis1sync_shmem,   &  !
+       nis2sync_shmem       !
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       nis1wrk_shmem,    &  ! 
+       nis2wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       nistab_shmem
+
+   !! integer sum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nil1sync_shmem,   &  !
+       nil2sync_shmem       !
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       nil1wrk_shmem,    &  !
+       nil2wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       niltab_shmem
+#endif
+
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   &
+       t4ns, t4sn  ! 3d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2,2) ::   &
+       t4ew, t4we  ! 3d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   &
+       t4p1, t4p2  ! 3d message passing arrays north fold
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2) ::   &
+       t3ns, t3sn  ! 3d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2) ::   &
+       t3ew, t3we  ! 3d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2) ::   &
+       t3p1, t3p2  ! 3d message passing arrays north fold
+   REAL(wp), DIMENSION(jpi,jprecj,2) ::   &
+       t2ns, t2sn  ! 2d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,2) ::   &
+       t2ew, t2we  ! 2d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,2) ::   &
+       t2p1, t2p2  ! 2d message passing arrays north fold
+   REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,jprecj+jpr2dj,2) ::   &
+       tr2ns, tr2sn  ! 2d message passing arrays north-south & south-north including extra outer halo
+   REAL(wp), DIMENSION(1-jpr2dj:jpj+jpr2dj,jpreci+jpr2di,2) ::   &
+       tr2ew, tr2we  ! 2d message passing arrays east-west & west-east including extra outer halo
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------
+
+CONTAINS
+
+   FUNCTION mynode()
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mynode  ***
+      !!                    
+      !! ** Purpose :   Find processor unit
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER ::   mynode, ierr
+      NAMELIST/nam_mpp/ c_mpi_send
+      !!----------------------------------------------------------------------
+
+      WRITE(numout,*)
+      WRITE(numout,*) 'mynode : mpi initialisation'
+      WRITE(numout,*) '~~~~~~ '
+      WRITE(numout,*)
+
+      ! Namelist namrun : parameters of the run
+      REWIND( numnam )
+      READ  ( numnam, nam_mpp )
+
+      WRITE(numout,*) '        Namelist nam_mpp'
+      WRITE(numout,*) '           mpi send type            c_mpi_send = ', c_mpi_send
+
+#if defined key_agrif
+      IF( Agrif_Root() ) THEN
+#endif
+         SELECT CASE ( c_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(numout,*) '           Standard blocking mpi send (send)'
+            CALL mpi_init( ierr )
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(numout,*) '           Buffer blocking mpi send (bsend)'
+            CALL mpi_init_opa( ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(numout,*) '           Immediate non-blocking send (isend)'
+            l_isend = .TRUE.
+            CALL mpi_init( ierr )
+         CASE DEFAULT
+            WRITE(ctmp1,*) '           bad value for c_mpi_send = ', c_mpi_send
+            CALL ctl_stop( ctmp1 )
+         END SELECT
+
+#if defined key_agrif
+      ENDIF
+#endif
+
+      CALL mpi_comm_rank( mpi_comm_world, rank, ierr )
+      CALL mpi_comm_size( mpi_comm_world, size, ierr )
+      mynode = rank
+#else
+      !! * Local variables   (SHMEM version)
+      INTEGER ::   mynode
+      INTEGER ::   &
+           imypid, imyhost, ji, info, iparent_tid
+      !!----------------------------------------------------------------------
+
+      IF( npvm_ipas /= nprocmax ) THEN
+         !         ---   first passage in mynode
+         !         -------------
+         !         enroll in pvm
+         !         -------------
+         CALL pvmfmytid( npvm_mytid )
+         IF( mynode_print /= 0 ) THEN
+            WRITE(numout,*) 'mynode, npvm_ipas =', npvm_ipas, ' nprocmax=', nprocmax
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid, ' after pvmfmytid'
+         ENDIF
+
+         !         ---------------------------------------------------------------
+         !         find out IF i am parent or child spawned processes have parents
+         !         ---------------------------------------------------------------
+         CALL mpparent( iparent_tid )
+         IF( mynode_print /= 0 ) THEN
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+               &            ' after mpparent, npvm_tids(0) = ',   &
+               &            npvm_tids(0), ' iparent_tid=', iparent_tid
+         ENDIF
+         IF( iparent_tid < 0 )  THEN
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+               &            ' after mpparent, npvm_tids(0) = ',   &
+               &            npvm_tids(0), ' iparent_tid=', iparent_tid
+            npvm_tids(0) = npvm_mytid
+            npvm_me = 0
+            IF( ndim_mpp > nprocmax ) THEN
+               WRITE(ctmp1,*) 'npvm_mytid=', npvm_mytid, ' too great'
+               CALL ctl_stop( ctmp1 )
+
+            ELSE
+               npvm_nproc = ndim_mpp
+            ENDIF
+
+            ! -------------------------
+            ! start up copies of myself
+            ! -------------------------
+            IF( npvm_nproc > 1 ) THEN
+               DO ji = 1, npvm_nproc-1
+                  npvm_tids(ji) = nt3d_tids(ji)
+               END DO
+               info=npvm_nproc-1
+  
+               IF( mynode_print /= 0 ) THEN
+                  WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                     &            ' maitre=',executable,' info=', info   &
+                     &            ,' npvm_nproc=',npvm_nproc
+                  WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                     &            ' npvm_tids ',(npvm_tids(ji),ji=0,npvm_nproc-1)
+               ENDIF
+
+               ! ---------------------------
+               ! multicast tids array to children
+               ! ---------------------------
+               CALL pvmfinitsend( pvmdefault, info )
+               CALL pvmfpack ( jpvmint, npvm_nproc, 1         , 1, info )
+               CALL pvmfpack ( jpvmint, npvm_tids , npvm_nproc, 1, info )
+               CALL pvmfmcast( npvm_nproc-1, npvm_tids(1), 10, info )
+            ENDIF
+         ELSE
+
+            ! ---------------------------------
+            ! receive the tids array and set me
+            ! ---------------------------------
+            IF( mynode_print /= 0 )   WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid, ' pvmfrecv'
+            CALL pvmfrecv( iparent_tid, 10, info )
+            IF( mynode_print /= 0 )   WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid, " fin pvmfrecv"
+            CALL pvmfunpack( jpvmint, npvm_nproc, 1         , 1, info )
+            CALL pvmfunpack( jpvmint, npvm_tids , npvm_nproc, 1, info )
+            IF( mynode_print /= 0 ) THEN
+               WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                  &            ' esclave=', executable,' info=', info,' npvm_nproc=',npvm_nproc
+               WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+                  &            'npvm_tids', ( npvm_tids(ji), ji = 0, npvm_nproc-1 )
+            ENDIF
+            DO ji = 0, npvm_nproc-1
+               IF( npvm_mytid == npvm_tids(ji) ) npvm_me = ji
+            END DO
+         ENDIF
+
+         ! ------------------------------------------------------------
+         ! all nproc tasks are equal now
+         ! and can address each other by tids(0) thru tids(nproc-1)
+         ! for each process me => process number [0-(nproc-1)]
+         ! ------------------------------------------------------------
+         CALL pvmfjoingroup ( "bidon", info )
+         CALL pvmfbarrier   ( "bidon", npvm_nproc, info )
+         DO ji = 0, npvm_nproc-1
+            IF( ji == npvm_me ) THEN
+               CALL pvmfjoingroup ( opaall, npvm_inum )
+               IF( npvm_inum /= npvm_me )   WRITE(numout,*) 'mynode not arrived in the good order for opaall'
+            ENDIF
+            CALL pvmfbarrier( "bidon", npvm_nproc, info )
+         END DO
+         CALL pvmfbarrier( opaall, npvm_nproc, info )
+  
+      ELSE
+         ! ---   other passage in mynode
+      ENDIF
+ 
+      npvm_ipas = nprocmax
+      mynode    = npvm_me
+      imypid    = npvm_mytid
+      imyhost   = npvm_tids(0)
+      IF( mynode_print /= 0 ) THEN
+         WRITE(numout,*)'mynode: npvm_mytid=', npvm_mytid, ' npvm_me=', npvm_me,   &
+            &           ' npvm_nproc=', npvm_nproc , ' npvm_ipas=', npvm_ipas
+      ENDIF
+#endif
+   END FUNCTION mynode
+
+
+   SUBROUTINE mpparent( kparent_tid )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpparent  ***
+      !!
+      !! ** Purpose :   use an pvmfparent routine for T3E (key_mpp_shmem)
+      !!              or  only return -1 (key_mpp_mpi)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(inout) ::   kparent_tid      ! ???
+  
+#if defined key_mpp_mpi
+      ! MPI version : retour -1
+
+      kparent_tid = -1
+
+#else
+      !! * Local variables   (SHMEN onto T3E version)
+      INTEGER ::   &
+           it3d_my_pe, LEADZ, ji, info
+  
+      CALL pvmfmytid( nt3d_mytid )
+      CALL pvmfgetpe( nt3d_mytid, it3d_my_pe )
+      IF( mpparent_print /= 0 ) THEN
+         WRITE(numout,*) 'mpparent: nt3d_mytid= ', nt3d_mytid ,' it3d_my_pe=',it3d_my_pe
+      ENDIF
+      IF( it3d_my_pe == 0 ) THEN
+         !-----------------------------------------------------------------!
+         !     process = 0 => receive other tids                           !
+         !-----------------------------------------------------------------!
+         kparent_tid = -1
+         IF(mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=',nt3d_mytid ,' kparent_tid=',kparent_tid
+         ENDIF
+         !          --- END receive dimension ---
+         IF( ndim_mpp > nprocmax ) THEN
+            WRITE(ctmp1,*) 'mytid=',nt3d_mytid,' too great'
+            CALL ctl_stop( ctmp1 )
+         ELSE
+            nt3d_nproc =  ndim_mpp
+         ENDIF
+         IF( mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' nt3d_nproc=', nt3d_nproc
+         ENDIF
+         !-------- receive tids from others process --------
+         DO ji = 1, nt3d_nproc-1
+            CALL pvmfrecv( ji , 100, info )
+            CALL pvmfunpack( jpvmint, nt3d_tids(ji), 1, 1, info )
+            IF( mpparent_print /= 0 ) THEN
+               WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' receive=', nt3d_tids(ji), ' from = ', ji
+            ENDIF
+         END DO
+         nt3d_tids(0) = nt3d_mytid
+         IF( mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' nt3d_tids(ji) =', (nt3d_tids(ji),   &
+                 ji = 0, nt3d_nproc-1 )
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' kparent_tid=', kparent_tid
+         ENDIF
+
+      ELSE
+         !!----------------------------------------------------------------!
+         !     process <> 0 => send  other tids                            !
+         !!----------------------------------------------------------------!
+         kparent_tid = 0
+         CALL pvmfinitsend( pvmdataraw, info )
+         CALL pvmfpack( jpvmint, nt3d_mytid, 1, 1, info )
+         CALL pvmfsend( kparent_tid, 100, info )
+      ENDIF
+#endif
+
+   END SUBROUTINE mpparent
+
+#if defined key_mpp_shmem
+
+   SUBROUTINE mppshmem
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppshmem  ***
+      !!
+      !! ** Purpose :   SHMEM ROUTINE
+      !!
+      !!----------------------------------------------------------------------
+      nrs1sync_shmem = SHMEM_SYNC_VALUE
+      nrs2sync_shmem = SHMEM_SYNC_VALUE
+      nis1sync_shmem = SHMEM_SYNC_VALUE
+      nis2sync_shmem = SHMEM_SYNC_VALUE
+      nil1sync_shmem = SHMEM_SYNC_VALUE
+      nil2sync_shmem = SHMEM_SYNC_VALUE
+      ni11sync_shmem = SHMEM_SYNC_VALUE
+      ni12sync_shmem = SHMEM_SYNC_VALUE
+      ni21sync_shmem = SHMEM_SYNC_VALUE
+      ni22sync_shmem = SHMEM_SYNC_VALUE
+      CALL barrier()
+  
+   END SUBROUTINE mppshmem
+
+#endif
+
+   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of ptab array grid-points
+         !             ! = T , U , V , F , W points
+         !             ! = S : T-point, north fold treatment ???
+         !             ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptab          ! 3D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only 
+
+      !! * Local variables
+      INTEGER ::   ji, jk, jl   ! dummy loop indices
+      INTEGER ::   imigr, iihom, ijhom, iloc, ijt, iju   ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+
+      IF( PRESENT( cd_mpp ) ) THEN
+         ! only fill extra allows with 1.
+         ptab(     1:nlci, nlcj+1:jpj, :) = 1.e0
+         ptab(nlci+1:jpi ,       :   , :) = 1.e0
+      ELSE      
+
+         !                                        ! East-West boundaries
+         !                                        ! ====================
+         IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+            &   (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            ptab( 1 ,:,:) = ptab(jpim1,:,:)
+            ptab(jpi,:,:) = ptab(  2  ,:,:)
+
+         ELSE                           ! closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T', 'U', 'V', 'W' )
+               ptab(     1       :jpreci,:,:) = 0.e0
+               ptab(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+            CASE ( 'F' )
+               ptab(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+            END SELECT 
+         ENDIF
+
+         !                                        ! North-South boundaries
+         !                                        ! ======================
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab(:,     1       :jprecj,:) = 0.e0
+            ptab(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+         CASE ( 'F' )
+            ptab(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+         END SELECT
+     
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all exept 2 
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            t3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj * jpk
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+         CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+
+      imigr = jpreci * jpj * jpk
+
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+         CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+         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, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci-jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = t3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = t3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            t3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi * jpk
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t3sn(1,1,1,2), t3sn(1,1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t3ns(1,1,1,2), t3ns(1,1,1,1), imigr, noso )
+         CALL shmem_put( t3sn(1,1,1,2), t3sn(1,1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t3ns(1,1,1,2), t3ns(1,1,1,1), imigr, noso )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+  
+      imigr=jprecj*jpi*jpk
+
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t3ns(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t3ns(1,1,1,2), imigr )
+         CALL mpprecv( 4, t3sn(1,1,1,2), imigr )
+         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, t3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t3sn(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj-jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = t3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = t3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! No north fold treatment (it is assumed to be already OK)
+     
+      ELSE      
+
+      ! 4.1 treatment without exchange (jpni odd)
+      !     T-point pivot  
+
+      SELECT CASE ( jpni )
+
+      CASE ( 1 )  ! only one proc along I, no mpp exchange
+
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )    ! T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+
+            SELECT CASE ( cd_type )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-2,jk)
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+          END SELECT
+       
+         CASE ( 5 , 6 ) ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE ( cd_type )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+            END SELECT  ! cd_type
+
+         END SELECT     !  npolj
+  
+      CASE DEFAULT ! more than 1 proc along I
+         IF ( npolj /= 0 ) CALL mpp_lbc_north (ptab, cd_type, psgn)  ! only for northern procs.
+
+      END SELECT ! jpni 
+
+      ENDIF
+      
+
+      ! 5. East and west directions exchange
+      ! ------------------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               t3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+               t3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+            END DO
+
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! SHMEM version
+
+         imigr = jpreci * jpj * jpk
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+            CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+         !! MPI version
+
+         imigr=jpreci*jpj*jpk
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+            CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+            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, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+
+         iihom = nlci-jpreci
+
+         SELECT CASE ( nbondi)
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+            END DO
+         CASE ( 0 ) 
+            DO jl = 1, jpreci
+               ptab(jl      ,:,:) = t3we(:,jl,:,2)
+               ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               ptab(jl      ,:,:) = t3we(:,jl,:,2)
+            END DO
+         END SELECT
+
+      END SELECT    ! npolj 
+
+   END SUBROUTINE mpp_lnk_3d
+
+
+   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of pt2d array grid-points
+         !             !  = T , U , V , F , W 
+         !             !  = S : T-point, north fold treatment
+         !             !  = G : F-point, north fold treatment
+         !             !  = I : sea-ice velocity at F-point with index shift
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only 
+
+      !! * Local variables
+      INTEGER  ::   ji, jj, jl      ! dummy loop indices
+      INTEGER  ::   &
+         imigr, iihom, ijhom,    &  ! temporary integers
+         iloc, ijt, iju             !    "          "
+      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER  ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill extra allows with 1.
+         pt2d(     1:nlci, nlcj+1:jpj) = 1.e0
+         pt2d(nlci+1:jpi ,       :   ) = 1.e0
+     
+      ELSE      
+
+         !                                        ! East-West boundaries
+         !                                        ! ====================
+         IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            pt2d( 1 ,:) = pt2d(jpim1,:)
+            pt2d(jpi,:) = pt2d(  2  ,:)
+
+         ELSE                           ! ... closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T', 'U', 'V', 'W' , 'I' )
+               pt2d(     1       :jpreci,:) = 0.e0
+               pt2d(nlci-jpreci+1:jpi   ,:) = 0.e0
+            CASE ( 'F' )
+               pt2d(nlci-jpreci+1:jpi   ,:) = 0.e0
+            END SELECT
+         ENDIF
+
+         !                                        ! North-South boundaries
+         !                                        ! ======================
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' , 'I' )
+            pt2d(:,     1       :jprecj) = 0.e0
+            pt2d(:,nlcj-jprecj+1:jpj   ) = 0.e0
+         CASE ( 'F' )
+            pt2d(:,nlcj-jprecj+1:jpj   ) = 0.e0
+         END SELECT
+
+      ENDIF
+
+
+      ! 2. East and west directions
+      ! ---------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all except 2
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            t2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+         CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = jpreci * jpj
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t2ew(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t2ew(1,1,2), imigr )
+         CALL mpprecv( 2, t2we(1,1,2), imigr )
+         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, t2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t2we(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci - jpreci
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            pt2d(iihom+jl,:) = t2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = t2we(:,jl,2)
+            pt2d(iihom+jl,:) = t2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = t2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            t2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr, noso )
+         CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr, noso )
+      END SELECT 
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = jprecj * jpi
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t2ns(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t2ns(1,1,2), imigr )
+         CALL mpprecv( 4, t2sn(1,1,2), imigr )
+         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, t2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t2sn(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+  
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj - jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = t2sn(:,jl,2)
+            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = t2sn(:,jl,2)
+         END DO
+      END SELECT 
+  
+
+      ! 4. north fold treatment
+      ! -----------------------
+  
+      IF (PRESENT(cd_mpp)) THEN
+         ! No north fold treatment (it is assumed to be already OK)
+     
+      ELSE      
+
+      ! 4.1 treatment without exchange (jpni odd)
+      
+      SELECT CASE ( jpni )
+  
+      CASE ( 1 ) ! only one proc along I, no mpp exchange
+  
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )   !  T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+  
+            SELECT CASE ( cd_type )
+  
+            CASE ( 'T' , 'S', 'W' )
+               DO ji = 2, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj) = psgn * pt2d(ijt,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'U' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-2)
+               END DO
+               DO ji = nlci/2, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'V' )
+               DO ji = 2, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-2)
+                  pt2d(ji,nlcj  ) = psgn * pt2d(ijt,nlcj-3)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-2)
+                  pt2d(ji,nlcj  ) = psgn * pt2d(iju,nlcj-3)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d(2,nlcj) = psgn * pt2d(3,nlcj-1)
+               DO ji = 3, nlci
+                  iju = iloc - ji + 3
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            END SELECT
+  
+         CASE ( 5 , 6 )                 ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE (cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO ji = 1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'U' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-1)
+               END DO
+
+            CASE ( 'V' )
+               DO ji = 1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj  ) = psgn * pt2d(ijt,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d( 2 ,nlcj) = 0.e0
+               DO ji = 2 , nlci-1
+                  ijt = iloc - ji + 2
+                  pt2d(ji,nlcj)= 0.5 * ( pt2d(ji,nlcj-1) + psgn * pt2d(ijt,nlcj-1) )
+               END DO
+  
+            END SELECT   ! cd_type
+  
+         END SELECT   ! npolj
+
+      CASE DEFAULT   ! more than 1 proc along I
+         IF( npolj /= 0 )   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! only for northern procs.
+
+      END SELECT   ! jpni
+
+      ENDIF
+
+      ! 5. East and west directions
+      ! ---------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               DO jj = 1, jpj
+                  t2ew(jj,jl,1) = pt2d(jpreci+jl,jj)
+                  t2we(jj,jl,1) = pt2d(iihom +jl,jj)
+               END DO
+            END DO
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! * SHMEM version
+
+         imigr=jpreci*jpj
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+            CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+  
+#elif defined key_mpp_mpi
+         !! * MPI version
+  
+         imigr=jpreci*jpj
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t2ew(1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t2ew(1,1,2), imigr )
+            CALL mpprecv( 2, t2we(1,1,2), imigr )
+            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, t2ew(1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t2we(1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT 
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+  
+         iihom = nlci - jpreci
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               pt2d(iihom+jl,:) = t2ew(:,jl,2)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jpreci
+               pt2d(jl      ,:) = t2we(:,jl,2)
+               pt2d(iihom+jl,:) = t2ew(:,jl,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               pt2d(jl,:) = t2we(:,jl,2)
+            END DO
+         END SELECT 
+  
+      END SELECT   ! npolj
+  
+   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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type1, cd_type2       ! define the nature of ptab array grid-points
+         !                        ! = T , U , V , F , W points
+         !                        ! = S : T-point, north fold treatment ???
+         !                        ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptab1, ptab2             ! 3D array on which the boundary condition is applied
+
+      !! * Local variables
+      INTEGER ::   ji, jk, jl   ! dummy loop indices
+      INTEGER ::   imigr, iihom, ijhom, iloc, ijt, iju   ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+         &   (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
+         SELECT CASE ( cd_type1 )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab1(     1       :jpreci,:,:) = 0.e0
+            ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         CASE ( 'F' )
+            ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         END SELECT 
+         SELECT CASE ( cd_type2 )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab2(     1       :jpreci,:,:) = 0.e0
+            ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         CASE ( 'F' )
+            ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         END SELECT 
+      ENDIF
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( cd_type1 )
+      CASE ( 'T', 'U', 'V', 'W' )
+         ptab1(:,     1       :jprecj,:) = 0.e0
+         ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      CASE ( 'F' )
+         ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      END SELECT
+
+      SELECT CASE ( cd_type2 )
+      CASE ( 'T', 'U', 'V', 'W' )
+         ptab2(:,     1       :jprecj,:) = 0.e0
+         ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      CASE ( 'F' )
+         ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      END SELECT
+
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all exept 2 
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+            t4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+            t4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+            t4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj * jpk *2
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+         CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+
+      imigr = jpreci * jpj * jpk *2
+
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+         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, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci-jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
+            t4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
+            t4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
+            t4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi * jpk * 2
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t4sn(1,1,1,1,2), t4sn(1,1,1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t4ns(1,1,1,1,2), t4ns(1,1,1,1,1), imigr, noso )
+         CALL shmem_put( t4sn(1,1,1,1,2), t4sn(1,1,1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t4ns(1,1,1,1,2), t4ns(1,1,1,1;,1), imigr, noso )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+  
+      imigr=jprecj * jpi * jpk * 2
+
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr )
+         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr )
+         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, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj-jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
+            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            ptab1(:,jl      ,:) = t4sn(:,jl,:,1,2)
+            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
+            ptab2(:,jl      ,:) = t4sn(:,jl,:,2,2)
+            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab1(:,jl,:) = t4sn(:,jl,:,1,2)
+            ptab2(:,jl,:) = t4sn(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+
+      ! 4.1 treatment without exchange (jpni odd)
+      !     T-point pivot  
+
+      SELECT CASE ( jpni )
+
+      CASE ( 1 )  ! only one proc along I, no mpp exchange
+
+      SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )    ! T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+
+            SELECT CASE ( cd_type1 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+            END SELECT
+            
+            SELECT CASE ( cd_type2 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+          END SELECT
+       
+         CASE ( 5 , 6 ) ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE ( cd_type1 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+            END SELECT  ! cd_type1
+
+            SELECT CASE ( cd_type2 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            END SELECT  ! cd_type2
+
+         END SELECT     !  npolj
+  
+      CASE DEFAULT ! more than 1 proc along I
+         IF ( npolj /= 0 ) THEN
+            CALL mpp_lbc_north (ptab1, cd_type1, psgn)  ! only for northern procs.
+            CALL mpp_lbc_north (ptab2, cd_type2, psgn)  ! only for northern procs.
+         ENDIF
+
+      END SELECT ! jpni 
+
+
+      ! 5. East and west directions exchange
+      ! ------------------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               t4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+               t4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+               t4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+               t4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+            END DO
+
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! SHMEM version
+
+         imigr = jpreci * jpj * jpk * 2
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+            CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+         !! MPI version
+
+         imigr = jpreci * jpj * jpk * 2
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+            CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+            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, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+
+         iihom = nlci-jpreci
+
+         SELECT CASE ( nbondi)
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+               ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+            END DO
+         CASE ( 0 ) 
+            DO jl = 1, jpreci
+               ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+               ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+               ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+               ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+               ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+            END DO
+         END SELECT
+
+      END SELECT    ! npolj 
+
+   END SUBROUTINE mpp_lnk_3d_gather
+
+
+   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!                    jpr2di : number of rows for extra outer halo
+      !!                    jpr2dj : 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
+      !!   
+      !! History :
+      !!       
+      !!   9.0  !  05-09  (R. Benshila, G. Madec)  original code
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of pt2d array grid-points
+         !             !  = T , U , V , F , W 
+         !             !  = S : T-point, north fold treatment
+         !             !  = G : F-point, north fold treatment
+         !             !  = I : sea-ice velocity at F-point with index shift
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+
+      !! * Local variables
+      INTEGER  ::   ji, jl      ! dummy loop indices
+      INTEGER  ::   &
+         imigr, iihom, ijhom,    &  ! temporary integers
+         iloc, ijt, iju             !    "          "
+      INTEGER  ::   &
+         ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for isend
+      INTEGER  ::   ml_stat(MPI_STATUS_SIZE)     ! for isend
+     !!---------------------------------------------------------------------
+
+      ! take into account outer extra 2D overlap area
+      ipreci = jpreci + jpr2di
+      iprecj = jprecj + jpr2dj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+         &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpr2di:     1    ,:) = pt2d(jpim1-jpr2di:  jpim1 ,:)
+         pt2d(   jpi  :jpi+jpr2di,:) = pt2d(     2      :2+jpr2di,:)
+
+      ELSE                           ! ... closed
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' , 'I' )
+            pt2d(  1-jpr2di   :jpreci    ,:) = 0.e0
+            pt2d(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0
+         CASE ( 'F' )
+            pt2d(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0
+         END SELECT
+      ENDIF
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( cd_type )
+      CASE ( 'T', 'U', 'V', 'W' , 'I' )
+         pt2d(:,  1-jpr2dj   :  jprecj  ) = 0.e0
+         pt2d(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0
+      CASE ( 'F' )
+         pt2d(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0
+      END SELECT
+
+
+      ! 2. East and west directions
+      ! ---------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all except 2
+         iihom = nlci-nreci-jpr2di
+         DO jl = 1, ipreci
+            tr2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            tr2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = ipreci * ( jpj + 2*jpr2dj)
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+         CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = ipreci * ( jpj + 2*jpr2dj)
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+         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, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci - jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+            pt2d( iihom+jl,:) = tr2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj-jpr2dj
+         DO jl = 1, iprecj
+            tr2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            tr2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = iprecj * ( jpi + 2*jpr2di )
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( tr2sn(1-jpr2di,1,2), tr2sn(1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( tr2ns(1-jpr2di,1,2), tr2ns(1,1,1), imigr, noso )
+         CALL shmem_put( tr2sn(1-jpr2di,1,2), tr2sn(1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( tr2ns(1-jpr2di,1,2), tr2ns(1,1,1), imigr, noso )
+      END SELECT 
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = iprecj * ( jpi + 2*jpr2di )
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr )
+         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr )
+         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, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+  
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj - jprecj  
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = tr2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
+            pt2d(:,ijhom+jl ) = tr2ns(:,jl,2)
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, iprecj
+            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
+         END DO
+      END SELECT 
+  
+
+      ! 4. north fold treatment
+      ! -----------------------
+  
+      ! 4.1 treatment without exchange (jpni odd)
+      
+      SELECT CASE ( jpni )
+  
+      CASE ( 1 ) ! only one proc along I, no mpp exchange
+  
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )   !  T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+  
+            SELECT CASE ( cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO jl = 0, iprecj-1
+                  DO ji = 2-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+2
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2+1, nlci+jpr2di
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+ 
+            CASE ( 'U' )
+               DO jl =0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1-jpr2di
+                     iju=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2, nlci-1+jpr2di
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'V' )
+               DO jl = -1, iprecj-1
+                  DO ji = 2-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+2
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-3-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO jl = -1, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-3-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               DO jl = 0, iprecj-1
+                  pt2d(2,nlcj+jl) = psgn * pt2d(3,nlcj-1-jl)
+                  DO ji = 3, nlci+jpr2di
+                     iju = iloc - ji + 3
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-1-jl)
+                  END DO
+               END DO
+  
+            END SELECT
+  
+         CASE ( 5 , 6 )                 ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE (cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-1-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'U' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-1-jl)
+                  END DO
+               END DO
+ 
+            CASE ( 'V' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-2-jl)
+                  END DO
+               END DO 
+               DO ji = nlci/2+1, nlci+jpr2di
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2+1, nlci-1+jpr2di
+                  iju=iloc-ji
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d( 2 ,nlcj) = 0.e0
+               DO jl = 0, iprecj-1
+                  DO ji = 2 , nlci-1+jpr2di
+                     ijt = iloc - ji + 2
+                     pt2d(ji,nlcj+jl)= 0.5 * ( pt2d(ji,nlcj-1-jl) + psgn * pt2d(ijt,nlcj-1-jl) )
+                  END DO
+               END DO
+  
+            END SELECT   ! cd_type
+  
+         END SELECT   ! npolj
+
+      CASE DEFAULT   ! more than 1 proc along I
+         IF( npolj /= 0 )   CALL mpp_lbc_north_e( pt2d, cd_type, psgn )   ! only for northern procs
+         
+      END SELECT   ! jpni
+
+
+      ! 5. East and west directions
+      ! ---------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci-jpr2di
+            DO jl = 1, ipreci
+               tr2ew(:,jl,1) = pt2d(jpreci+jl,:)
+               tr2we(:,jl,1) = pt2d(iihom +jl,:)
+            END DO
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! * SHMEM version
+
+         imigr = ipreci * ( jpj + 2*jpr2dj )
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+            CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+  
+#elif defined key_mpp_mpi
+         !! * MPI version
+  
+         imigr=ipreci* ( jpj + 2*jpr2dj )
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+            CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+            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, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT 
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+  
+         iihom = nlci - jpreci
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, ipreci
+               pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, ipreci
+               pt2d(jl- jpr2di,:) = tr2we(:,jl,2)
+               pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, ipreci
+               pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+            END DO
+         END SELECT 
+  
+      END SELECT   ! npolj
+  
+   END SUBROUTINE mpp_lnk_2d_e
+
+
+   SUBROUTINE mpplnks( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpplnks  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for add 2d array local boundary
+      !!
+      !! ** 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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   &
+         ptab                     ! 2D array
+  
+      !! * Local variables
+      INTEGER ::   ji, jl         ! dummy loop indices
+      INTEGER ::   &
+         imigr, iihom, ijhom      ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+
+      ! 1. north fold treatment
+      ! -----------------------
+
+      ! 1.1 treatment without exchange (jpni odd)
+  
+      SELECT CASE ( npolj )
+      CASE ( 4 )
+         DO ji = 1, nlci
+            ptab(ji,nlcj-2) = ptab(ji,nlcj-2) + t2p1(ji,1,1)
+         END DO
+      CASE ( 6 )
+         DO ji = 1, nlci
+            ptab(ji,nlcj-1) = ptab(ji,nlcj-1) + t2p1(ji,1,1)
+         END DO
+
+      ! 1.2 treatment with exchange (jpni greater than 1)
+      ! 
+      CASE ( 3 )
+#if defined key_mpp_shmem
+  
+         !! * SHMEN version
+  
+         imigr=jprecj*jpi
+  
+         CALL shmem_put(t2p1(1,1,2),t2p1(1,1,1),imigr,nono)
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+       !! * MPI version
+
+       imigr=jprecj*jpi
+
+       CALL mppsend(3,t2p1(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2p1(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+#endif      
+
+       ! Write north fold conditions
+
+       DO ji = 1, nlci
+          ptab(ji,nlcj-2) = ptab(ji,nlcj-2)+t2p1(ji,1,2)
+       END DO
+
+    CASE ( 5 )
+
+#if defined key_mpp_shmem
+
+       !! * SHMEN version
+
+       imigr=jprecj*jpi
+
+       CALL shmem_put(t2p1(1,1,2),t2p1(1,1,1),imigr,nono)
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+       !! * Local variables   (MPI version)
+
+       imigr=jprecj*jpi
+
+       CALL mppsend(3,t2p1(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2p1(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+#endif      
+
+       ! Write north fold conditions
+
+       DO ji = 1, nlci
+          ptab(ji,nlcj-1) = ptab(ji,nlcj-1)+t2p1(ji,1,2)
+       END DO
+
+    END SELECT
+
+
+    ! 2. East and west directions
+    ! ---------------------------
+
+    ! 2.1 Read Dirichlet lateral conditions
+
+    iihom = nlci-jpreci
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1, 0, 1 )  ! all except 2
+       DO jl = 1, jpreci
+             t2ew(:,jl,1) = ptab(  jl    ,:)
+             t2we(:,jl,1) = ptab(iihom+jl,:)
+       END DO
+    END SELECT
+
+    ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+
+    !! * SHMEN version
+
+    imigr=jpreci*jpj
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       CALL shmem_put(t2we(1,1,2),t2we(1,1,1),imigr,noea)
+
+    CASE ( 0 )
+       CALL shmem_put(t2ew(1,1,2),t2ew(1,1,1),imigr,nowe)
+       CALL shmem_put(t2we(1,1,2),t2we(1,1,1),imigr,noea)
+
+    CASE ( 1 )
+       CALL shmem_put(t2ew(1,1,2),t2ew(1,1,1),imigr,nowe)
+
+    END SELECT
+    CALL  barrier()
+    CALL  shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+    !! * Local variables   (MPI version)
+
+    imigr=jpreci*jpj
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req1)
+       CALL mpprecv(1,t2ew(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+    CASE ( 0 )
+       CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+       CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req2)
+       CALL mpprecv(1,t2ew(1,1,2),imigr)
+       CALL mpprecv(2,t2we(1,1,2),imigr)
+       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,t2ew(1,1,1),imigr,nowe, ml_req1)
+       CALL mpprecv(2,t2we(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+    END SELECT
+
+#endif
+
+    ! 2.3 Write Dirichlet lateral conditions
+
+       iihom = nlci-nreci
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       DO jl = 1, jpreci
+             ptab(iihom +jl,:) = ptab(iihom +jl,:)+t2ew(:,jl,2)
+       END DO
+
+    CASE ( 0 )
+       DO jl = 1, jpreci
+             ptab(jpreci+jl,:) = ptab(jpreci+jl,:)+t2we(:,jl,2)
+             ptab(iihom +jl,:) = ptab(iihom +jl,:)+t2ew(:,jl,2)
+       END DO
+
+    CASE ( 1 )
+       DO jl = 1, jpreci
+             ptab(jpreci+jl,:) = ptab(jpreci+jl,:)+t2we(:,jl,2)
+       END DO
+    END SELECT
+
+
+    ! 3. North and south directions
+    ! -----------------------------
+
+    ! 3.1 Read Dirichlet lateral conditions
+
+    ijhom = nlcj-jprecj
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1, 0, 1 )
+       DO jl = 1, jprecj
+             t2sn(:,jl,1) = ptab(:,ijhom+jl)
+             t2ns(:,jl,1) = ptab(:,   jl   )
+       END DO
+
+    END SELECT 
+
+    ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+
+    !! * SHMEN version
+
+    imigr=jprecj*jpi
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       CALL shmem_put(t2sn(1,1,2),t2sn(1,1,1),imigr,nono)
+
+    CASE ( 0 )
+       CALL shmem_put(t2ns(1,1,2),t2ns(1,1,1),imigr,noso)
+       CALL shmem_put(t2sn(1,1,2),t2sn(1,1,1),imigr,nono)
+
+    CASE ( 1 )
+       CALL shmem_put(t2ns(1,1,2),t2ns(1,1,1),imigr,noso)
+
+    END SELECT
+    CALL  barrier()
+    CALL  shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+    !! * Local variables   (MPI version)
+
+    imigr=jprecj*jpi
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2ns(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+    CASE ( 0 )
+       CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+       CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req2)
+       CALL mpprecv(3,t2ns(1,1,2),imigr)
+       CALL mpprecv(4,t2sn(1,1,2),imigr)
+       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,t2ns(1,1,1),imigr,noso, ml_req1)
+       CALL mpprecv(4,t2sn(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+    END SELECT
+
+#endif
+
+    ! 3.3 Write Dirichlet lateral conditions
+
+       ijhom = nlcj-nrecj
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       DO jl = 1, jprecj
+             ptab(:,ijhom +jl) = ptab(:,ijhom +jl)+t2ns(:,jl,2)
+       END DO
+
+    CASE ( 0 )
+       DO jl = 1, jprecj
+             ptab(:,jprecj+jl) = ptab(:,jprecj+jl)+t2sn(:,jl,2)
+             ptab(:,ijhom +jl) = ptab(:,ijhom +jl)+t2ns(:,jl,2)
+       END DO
+
+    CASE ( 1 ) 
+       DO jl = 1, jprecj
+             ptab(:,jprecj+jl) = ptab(:,jprecj+jl)+t2sn(:,jl,2)
+       END DO
+
+    END SELECT
+
+  END SUBROUTINE mpplnks
+
+
+   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req)
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsend  ***
+      !!                   
+      !! ** Purpose :   Send messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(inout) ::   pmess(*)       ! array of real
+      INTEGER , INTENT( in  ) ::   kbytes,     &  ! size of the array pmess
+         &                         kdest ,     &  ! receive process number
+         &                         ktyp,       &  ! Tag of the message
+         &                         md_req         ! Argument for isend
+      !!----------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version  :    routine not used
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+      INTEGER ::   iflag
+
+      SELECT CASE ( c_mpi_send )
+      CASE ( 'S' )                ! Standard mpi send (blocking)
+         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest, ktyp,   &
+            &                          mpi_comm_world, iflag )
+      CASE ( 'B' )                ! Buffer mpi send (blocking)
+         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest, ktyp,   &
+            &                          mpi_comm_world, 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_world, md_req, iflag )
+      END SELECT
+#endif
+
+   END SUBROUTINE mppsend
+
+
+   SUBROUTINE mpprecv( ktyp, pmess, kbytes )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpprecv  ***
+      !!
+      !! ** Purpose :   Receive messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(inout) ::   pmess(*)       ! array of real
+      INTEGER , INTENT( in  ) ::   kbytes,     &  ! suze of the array pmess
+         &                         ktyp           ! Tag of the recevied message
+      !!----------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version  :    routine not used
+
+#  elif defined key_mpp_mpi
+      !! * MPI version
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+
+      CALL mpi_recv( pmess, kbytes, mpi_double_precision, mpi_any_source, ktyp,   &
+         &                          mpi_comm_world, istatus, iflag )
+#endif
+
+   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.
+      !!
+      !! ** Method  :
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      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
+      !!---------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      CALL barrier()
+      CALL shmem_put( pio(1,1,npvm_me+1), ptab, jpi*jpj, kp )
+      CALL barrier()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER :: itaille,ierror
+  
+      itaille=jpi*jpj
+      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille,   &
+         &                            mpi_double_precision, kp , mpi_comm_world, ierror ) 
+#endif
+
+   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.
+      !!
+      !! ** Method :
+      !!
+      !!----------------------------------------------------------------------
+      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
+      !!---------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      CALL barrier()
+      CALL shmem_get( ptab, pio(1,1,npvm_me+1), jpi*jpj, kp )
+      CALL barrier()
+
+#  elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER :: itaille, ierror
+  
+      itaille=jpi*jpj
+
+      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille,   &
+         &                            mpi_double_precision, kp, mpi_comm_world, ierror )
+#endif
+
+   END SUBROUTINE mppscatter
+
+
+   SUBROUTINE mppisl_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_a_int  ***
+      !!                   
+      !! ** Purpose :   Massively parallel processors
+      !!                Find the  non zero value
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  )                  ::   kdim       ! ???
+      INTEGER, INTENT(inout), DIMENSION(kdim) ::   ktab       ! ???
+  
+#if defined key_mpp_shmem
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppisl_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+
+      DO ji = 1, kdim
+         niitab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni11wrk_shmem,ni11sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni21wrk_shmem,ni21sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      DO ji = 1, kdim
+         IF( ni11tab_shmem(ji) /= 0. ) THEN
+            ktab(ji) = ni11tab_shmem(ji)
+         ELSE
+            ktab(ji) = ni12tab_shmem(ji)
+         ENDIF
+      END DO
+  
+#  elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      LOGICAL  :: lcommute
+      INTEGER, DIMENSION(kdim) ::   iwork
+      INTEGER  :: mpi_isl,ierror
+  
+      lcommute = .TRUE.
+      CALL mpi_op_create( lc_isl, lcommute, mpi_isl, ierror )
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer   &
+           , mpi_isl, mpi_comm_world, ierror )
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppisl_a_int
+
+
+   SUBROUTINE mppisl_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_int  ***
+      !!                   
+      !! ** Purpose :   Massively parallel processors
+      !!                Find the non zero value
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( inout ) ::   ktab        ! 
+
+#if defined key_mpp_shmem
+      !! * Local variables   (SHMEM version)
+      INTEGER, SAVE :: ibool=0
+
+      niitab_shmem(1) = ktab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni11wrk_shmem,ni11sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni21wrk_shmem,ni21sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      IF( ni11tab_shmem(1) /= 0. ) THEN
+         ktab = ni11tab_shmem(1)
+      ELSE
+         ktab = ni12tab_shmem(1)
+      ENDIF
+  
+#  elif defined key_mpp_mpi
+  
+      !! * Local variables   (MPI version)
+      LOGICAL :: lcommute
+      INTEGER :: mpi_isl,ierror
+      INTEGER ::   iwork
+  
+      lcommute = .TRUE.
+      CALL mpi_op_create(lc_isl,lcommute,mpi_isl,ierror)
+      CALL mpi_allreduce(ktab, iwork, 1,mpi_integer   &
+           ,mpi_isl,mpi_comm_world,ierror)
+      ktab = iwork
+#endif
+
+   END SUBROUTINE mppisl_int
+
+
+   SUBROUTINE mppmin_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_a_int  ***
+      !! 
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
+  
+#if defined key_mpp_shmem
+      !! * Local declarations    (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppmin_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+  
+      DO ji = 1, kdim
+         niltab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      DO ji = 1, kdim
+         ktab(ji) = niltab_shmem(ji)
+      END DO
+  
+#  elif defined key_mpp_mpi
+  
+      !! * Local variables   (MPI version)
+      INTEGER :: ierror
+      INTEGER, DIMENSION(kdim) ::   iwork
+  
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer,   &
+           &                mpi_min, mpi_comm_world, ierror )
+  
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppmin_a_int
+
+
+   SUBROUTINE mppmin_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_int  ***
+      !!
+      !! ** Purpose :
+      !!     Massively parallel processors
+      !!     Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(inout) ::   ktab      ! ???
+  
+      !! * Local declarations
+
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      niltab_shmem(1) = ktab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      ktab = niltab_shmem(1)
+  
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      INTEGER ::  ierror, iwork
+  
+      CALL mpi_allreduce(ktab,iwork, 1,mpi_integer   &
+           &              ,mpi_min,mpi_comm_world,ierror)
+  
+      ktab = iwork
+#endif
+
+   END SUBROUTINE mppmin_int
+
+
+   SUBROUTINE mppsum_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_int  ***
+      !!                    
+      !! ** Purpose :   Massively parallel processors
+      !!                Global integer sum
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  )                   ::   kdim      ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
+  
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppsum_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+
+      DO ji = 1, kdim
+         nistab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem,kdim,0,0,   &
+              N$PES,nis1wrk_shmem,nis1sync_shmem)
+      ELSE
+         CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem,kdim,0,0,   &
+              N$PES,nis2wrk_shmem,nis2sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool = ibool + 1
+      ibool = MOD( ibool, 2 )
+      DO ji = 1, kdim
+         ktab(ji) = nistab_shmem(ji)
+      END DO
+  
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      INTEGER :: ierror
+      INTEGER, DIMENSION (kdim) ::  iwork
+  
+      CALL mpi_allreduce(ktab, iwork,kdim,mpi_integer   &
+           ,mpi_sum,mpi_comm_world,ierror)
+  
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppsum_a_int
+
+
+  SUBROUTINE mppsum_int( ktab )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppsum_int  ***
+    !!                  
+    !! ** Purpose :   Global integer sum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER, INTENT(inout) ::   ktab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    nistab_shmem(1) = ktab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem, 1,0,0,   &
+            N$PES,nis1wrk_shmem,nis1sync_shmem)
+    ELSE
+       CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem, 1,0,0,   &
+            N$PES,nis2wrk_shmem,nis2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ktab = nistab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror, iwork
+
+    CALL mpi_allreduce(ktab,iwork, 1,mpi_integer   &
+         ,mpi_sum,mpi_comm_world,ierror)
+
+    ktab = iwork
+
+#endif
+
+  END SUBROUTINE mppsum_int
+
+
+  SUBROUTINE mppisl_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppisl_a_real  ***
+    !!         
+    !! ** Purpose :   Massively parallel processors
+    !!           Find the non zero island barotropic stream function value
+    !!
+    !!   Modifications:
+    !!        !  93-09 (M. Imbard)
+    !!        !  96-05 (j. Escobar)
+    !!        !  98-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI 
+    !!----------------------------------------------------------------------
+    INTEGER , INTENT( in  )                  ::   kdim      ! ???
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab      ! ???
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppisl_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wiltab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi11wrk_shmem,ni11sync_shmem)
+       CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi12wrk_shmem,ni12sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi21wrk_shmem,ni21sync_shmem)
+       CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi22wrk_shmem,ni22sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       IF(wi1tab_shmem(ji) /= 0. ) THEN
+          ptab(ji) = wi1tab_shmem(ji)
+       ELSE
+          ptab(ji) = wi2tab_shmem(ji)
+       ENDIF
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    LOGICAL ::   lcommute = .TRUE.
+    INTEGER ::   mpi_isl, ierror
+    REAL(wp), DIMENSION(kdim) ::  zwork
+
+    CALL mpi_op_create(lc_isl,lcommute,mpi_isl,ierror)
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_isl,mpi_comm_world,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppisl_a_real
+
+
+   SUBROUTINE mppisl_real( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_real  ***
+      !!                  
+      !! ** Purpose :   Massively parallel processors
+      !!       Find the  non zero island barotropic stream function value
+      !!
+      !!     Modifications:
+      !!        !  93-09 (M. Imbard)
+      !!        !  96-05 (j. Escobar)
+      !!        !  98-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI 
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   ptab
+
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER, SAVE :: ibool=0
+
+      wiltab_shmem(1) = ptab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi11wrk_shmem,ni11sync_shmem)
+         CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi21wrk_shmem,ni21sync_shmem)
+         CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL barrier()
+      ibool = ibool + 1
+      ibool = MOD( ibool, 2 )
+      IF( wi1tab_shmem(1) /= 0. ) THEN
+         ptab = wi1tab_shmem(1)
+      ELSE
+         ptab = wi2tab_shmem(1)
+      ENDIF
+
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      LOGICAL  ::   lcommute = .TRUE.
+      INTEGER  ::   mpi_isl, ierror
+      REAL(wp) ::   zwork
+
+      CALL mpi_op_create( lc_isl, lcommute, mpi_isl, ierror )
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision,   &
+         &                                mpi_isl  , mpi_comm_world, ierror )
+      ptab = zwork
+
+#endif
+
+   END SUBROUTINE mppisl_real
+
+
+  FUNCTION lc_isl( py, px, kdim, kdtatyp )
+    INTEGER :: kdim
+    REAL(wp), DIMENSION(kdim) ::  px, py
+    INTEGER :: kdtatyp, ji
+    INTEGER :: lc_isl
+    DO ji = 1, kdim
+       IF( py(ji) /= 0. )   px(ji) = py(ji)
+    END DO
+    lc_isl=0
+
+  END FUNCTION lc_isl
+
+
+  SUBROUTINE mppmax_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppmax_a_real  ***
+    !!                  
+    !! ** Purpose :   Maximum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in  )                  ::   kdim
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppmax_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wintab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wintab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+    REAL(wp), DIMENSION(kdim) ::  zwork
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_max,mpi_comm_world,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppmax_a_real
+
+
+  SUBROUTINE mppmax_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppmax_real  ***
+    !!                    
+    !! ** Purpose :   Maximum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    REAL(wp), INTENT(inout) ::   ptab      ! ???
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wintab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ptab = wintab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce( ptab, zwork  , 1             , mpi_double_precision,   &
+       &                      mpi_max, mpi_comm_world, ierror     )
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppmax_real
+
+
+  SUBROUTINE mppmin_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppmin_a_real  ***
+    !!                  
+    !! ** Purpose :   Minimum
+    !!
+    !!-----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in  )                  ::   kdim
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mpprmin routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wintab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wintab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+    REAL(wp), DIMENSION(kdim) ::   zwork
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_min,mpi_comm_world,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppmin_a_real
+
+
+  SUBROUTINE mppmin_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppmin_real  ***
+    !! 
+    !! ** Purpose :   minimum in Massively Parallel Processing
+    !!                REAL scalar case
+    !!
+    !!-----------------------------------------------------------------------
+    !! * Arguments
+    REAL(wp), INTENT( inout ) ::   ptab        ! 
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wintab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ptab = wintab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce( ptab, zwork, 1,mpi_double_precision   &
+         &               ,mpi_min,mpi_comm_world,ierror)
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppmin_real
+
+
+  SUBROUTINE mppsum_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsum_a_real  ***
+    !! 
+    !! ** Purpose :   global sum in Massively Parallel Processing
+    !!                REAL ARRAY argument case
+    !!
+    !!-----------------------------------------------------------------------
+    INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
+    REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppsum_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wrstab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem,kdim,0   &
+            ,0,N$PES,wrs1wrk_shmem,nrs1sync_shmem )
+    ELSE
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem,kdim,0   &
+            ,0,N$PES,wrs2wrk_shmem,nrs2sync_shmem )
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wrstab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER                   ::   ierror    ! temporary integer
+    REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace 
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         &              ,mpi_sum,mpi_comm_world,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppsum_a_real
+
+
+  SUBROUTINE mppsum_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsum_real  ***
+    !!              
+    !! ** Purpose :   global sum in Massively Parallel Processing
+    !!                SCALAR argument case
+    !!
+    !!-----------------------------------------------------------------------
+    REAL(wp), INTENT(inout) ::   ptab        ! input scalar
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wrstab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem, 1,0   &
+            ,0,N$PES,wrs1wrk_shmem,nrs1sync_shmem )
+    ELSE
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem, 1,0   &
+            ,0,N$PES,wrs2wrk_shmem,nrs2sync_shmem )
+    ENDIF
+    CALL  barrier()
+    ibool = ibool + 1
+    ibool = MOD( ibool, 2 )
+    ptab = wrstab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce(ptab, zwork, 1,mpi_double_precision   &
+         &              ,mpi_sum,mpi_comm_world,ierror)
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppsum_real
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmin = global minimum
+    !!                O : ki,kj = global position of minimum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_minloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmin    ! Global minimum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj   ! index of minimum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmin   ! local minimum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (2)  :: ilocs
+    INTEGER :: ierror
+
+
+    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_WORLD,ierror)
+
+    pmin=zaout(1,1)
+    kj= INT(zaout(2,1)/10000.)
+    ki= INT(zaout(2,1) - 10000.*kj )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmin = global minimum
+    !!                O : ki,kj = global position of minimum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_minloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmin    ! Global minimum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj,kk ! index of minimum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmin   ! local minimum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (3)  :: ilocs
+    INTEGER :: ierror
+
+
+    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_WORLD,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. )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmax = global maximum
+    !!                O : ki,kj = global position of maximum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_maxloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmax    ! Global maximum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj   ! index of maximum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmax   ! local maximum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (2)  :: 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
+
+    zain(1,:)=zmax
+    zain(2,:)=ki+10000.*kj
+
+    CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_WORLD,ierror)
+
+    pmax=zaout(1,1)
+    kj= INT(zaout(2,1)/10000.)
+    ki= INT(zaout(2,1) - 10000.*kj )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmax = global maximum
+    !!                O : ki,kj = global position of maximum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_maxloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmax    ! Global maximum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj,kk   ! index of maximum in global frame
+
+    !! * Local variables
+    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_WORLD,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. )
+#endif
+
+  END SUBROUTINE mpp_maxloc3d
+
+  SUBROUTINE mppsync()
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsync  ***
+    !!                   
+    !! ** Purpose :   Massively parallel processors, synchroneous
+    !!
+    !!-----------------------------------------------------------------------
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    CALL barrier()
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+
+    CALL mpi_barrier(mpi_comm_world,ierror)
+
+#endif
+
+  END SUBROUTINE mppsync
+
+
+  SUBROUTINE mppstop
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppstop  ***
+    !!                   
+    !! ** purpose :   Stop massilively parallel processors method
+    !!
+    !!----------------------------------------------------------------------
+    !! * Local declarations
+    INTEGER ::   info
+    !!----------------------------------------------------------------------
+
+    ! 1. Mpp synchroneus
+    ! ------------------
+
+    CALL mppsync
+#if defined key_mpp_mpi
+    CALL mpi_finalize( info )
+#endif
+
+  END SUBROUTINE mppstop
+
+
+  SUBROUTINE mppobc( ptab, kd1, kd2, kl, kk, ktype, kij )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppobc  ***
+    !! 
+    !! ** Purpose :   Message passing manadgement for open boundary
+    !!     conditions 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
+    !!
+    !! History :
+    !!        !  98-07 (J.M. Molines) Open boundary conditions
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in ) ::   &
+         kd1, kd2,   &  ! starting and ending indices
+         kl ,        &  ! index of open boundary
+         kk,         &  ! vertical dimension
+         ktype,      &  ! define north/south or east/west cdt
+         !              !  = 1  north/south  ;  = 2  east/west
+         kij            ! horizontal dimension
+    REAL(wp), DIMENSION(kij,kk), INTENT( inout )  ::   &
+         ptab           ! variable array
+
+    !! * Local variables
+    INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+    INTEGER  ::   &
+         iipt0, iipt1, ilpt1,     &  ! temporary integers
+         ijpt0, ijpt1,            &  !    "          "
+         imigr, iihom, ijhom         !    "          "
+    INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+    INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+    REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ztab                        ! temporary workspace
+    !!----------------------------------------------------------------------
+
+
+    ! boundary condition initialization
+    ! ---------------------------------
+
+    ztab(:,:) = 0.e0
+
+    IF( ktype==1 ) THEN                                  ! north/south boundaries
+       iipt0 = MAX( 1, MIN(kd1 - nimpp+1, nlci     ) )
+       iipt1 = MAX( 0, MIN(kd2 - nimpp+1, nlci - 1 ) )
+       ilpt1 = MAX( 1, MIN(kd2 - nimpp+1, nlci     ) )
+       ijpt0 = MAX( 1, MIN(kl  - njmpp+1, nlcj     ) )
+       ijpt1 = MAX( 0, MIN(kl  - njmpp+1, nlcj - 1 ) )
+    ELSEIF( ktype==2 ) THEN                              ! east/west boundaries
+       iipt0 = MAX( 1, MIN(kl  - nimpp+1, nlci     ) )
+       iipt1 = MAX( 0, MIN(kl  - nimpp+1, nlci - 1 ) )
+       ijpt0 = MAX( 1, MIN(kd1 - njmpp+1, nlcj     ) )
+       ijpt1 = MAX( 0, MIN(kd2 - njmpp+1, nlcj - 1 ) )
+       ilpt1 = MAX( 1, MIN(kd2 - njmpp+1, nlcj     ) )
+    ELSE
+       CALL ctl_stop( 'mppobc: bad ktype' )
+    ENDIF
+
+    DO jk = 1, kk
+       IF( ktype==1 ) THEN                               ! north/south boundaries
+          DO jj = ijpt0, ijpt1
+             DO ji = iipt0, iipt1
+                ztab(ji,jj) = ptab(ji,jk)
+             END DO
+          END DO
+       ELSEIF( ktype==2 ) THEN                           ! east/west boundaries
+          DO jj = ijpt0, ijpt1
+             DO ji = iipt0, iipt1
+                ztab(ji,jj) = ptab(jj,jk)
+             END DO
+          END DO
+       ENDIF
+
+
+       ! 1. East and west directions
+       ! ---------------------------
+
+       ! 1.1 Read Dirichlet lateral conditions
+
+       IF( nbondi /= 2 ) THEN
+          iihom = nlci-nreci
+
+          DO jl = 1, jpreci
+             t2ew(:,jl,1) = ztab(jpreci+jl,:)
+             t2we(:,jl,1) = ztab(iihom +jl,:)
+          END DO
+       ENDIF
+
+       ! 1.2 Migrations
+
+#if defined key_mpp_shmem
+       !! *  (SHMEM version)
+       imigr=jpreci*jpj*jpbyt
+
+       IF( nbondi == -1 ) THEN
+          CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr/jpbyt, noea )
+       ELSEIF( nbondi == 0 ) THEN
+          CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr/jpbyt, nowe )
+          CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr/jpbyt, noea )
+       ELSEIF( nbondi == 1 ) THEN
+          CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr/jpbyt, nowe )
+       ENDIF
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif key_mpp_mpi
+       !! * (MPI version)
+
+       imigr=jpreci*jpj
+
+       IF( nbondi == -1 ) THEN
+          CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req1)
+          CALL mpprecv(1,t2ew(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ELSEIF( nbondi == 0 ) THEN
+          CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+          CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req2)
+          CALL mpprecv(1,t2ew(1,1,2),imigr)
+          CALL mpprecv(2,t2we(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+       ELSEIF( nbondi == 1 ) THEN
+          CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+          CALL mpprecv(2,t2we(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ENDIF
+#endif
+
+
+       ! 1.3 Write Dirichlet lateral conditions
+
+       iihom = nlci-jpreci
+       IF( nbondi == 0 .OR. nbondi == 1 ) THEN
+          DO jl = 1, jpreci
+             ztab(jl,:) = t2we(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( nbondi == -1 .OR. nbondi == 0 ) THEN
+          DO jl = 1, jpreci
+             ztab(iihom+jl,:) = t2ew(:,jl,2)
+          END DO
+       ENDIF
+
+
+       ! 2. North and south directions
+       ! -----------------------------
+
+       ! 2.1 Read Dirichlet lateral conditions
+
+       IF( nbondj /= 2 ) THEN
+          ijhom = nlcj-nrecj
+          DO jl = 1, jprecj
+             t2sn(:,jl,1) = ztab(:,ijhom +jl)
+             t2ns(:,jl,1) = ztab(:,jprecj+jl)
+          END DO
+       ENDIF
+
+       ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+       !! * SHMEM version
+
+       imigr=jprecj*jpi*jpbyt
+
+       IF( nbondj == -1 ) THEN
+          CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr/jpbyt, nono )
+       ELSEIF( nbondj == 0 ) THEN
+          CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr/jpbyt, noso )
+          CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr/jpbyt, nono )
+       ELSEIF( nbondj == 1 ) THEN
+          CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr/jpbyt, noso )
+       ENDIF
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif key_mpp_mpi
+       !! * Local variables   (MPI version)
+
+       imigr=jprecj*jpi
+
+       IF( nbondj == -1 ) THEN
+          CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req1)
+          CALL mpprecv(3,t2ns(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ELSEIF( nbondj == 0 ) THEN
+          CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+          CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req2)
+          CALL mpprecv(3,t2ns(1,1,2),imigr)
+          CALL mpprecv(4,t2sn(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+       ELSEIF( nbondj == 1 ) THEN
+          CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+          CALL mpprecv(4,t2sn(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ENDIF
+
+#endif
+
+       ! 2.3 Write Dirichlet lateral conditions
+
+       ijhom = nlcj - jprecj
+       IF( nbondj == 0 .OR. nbondj == 1 ) THEN
+          DO jl = 1, jprecj
+             ztab(:,jl) = t2sn(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( nbondj == 0 .OR. nbondj == -1 ) THEN
+          DO jl = 1, jprecj
+             ztab(:,ijhom+jl) = t2ns(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( ktype==1 .AND. kd1 <= jpi+nimpp-1 .AND. nimpp <= kd2 ) THEN
+          ! north/south boundaries
+          DO jj = ijpt0,ijpt1
+             DO ji = iipt0,ilpt1
+                ptab(ji,jk) = ztab(ji,jj)  
+             END DO
+          END DO
+       ELSEIF( ktype==2 .AND. kd1 <= jpj+njmpp-1 .AND. njmpp <= kd2 ) THEN
+          ! east/west boundaries
+          DO jj = ijpt0,ilpt1
+             DO ji = iipt0,iipt1
+                ptab(jj,jk) = ztab(ji,jj) 
+             END DO
+          END DO
+       ENDIF
+
+    END DO
+
+  END SUBROUTINE mppobc
+
+
+  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.
+    !!
+    !! History :
+    !!        !  03-09 (J.M. Molines, MPI only )
+    !!----------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_ini_north not available in SHMEM' )
+# elif key_mpp_mpi
+    INTEGER :: ierr
+    INTEGER :: jproc
+    INTEGER :: ii,ji
+    !!----------------------------------------------------------------------
+
+    njmppmax=MAXVAL(njmppt)
+
+    ! Look for how many procs on the northern boundary
+    !
+    ndim_rank_north=0
+    DO jproc=1,jpnij
+       IF ( njmppt(jproc) == njmppmax ) THEN
+          ndim_rank_north = ndim_rank_north + 1
+       END IF
+    END DO
+
+
+    ! Allocate the right size to 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_world,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_world,ngrp_north,ncomm_north,ierr)
+
+
+    ! find proc number in the world of proc 0 in the north
+    CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_north,1,0,ngrp_world,north_root,ierr)
+#endif
+
+  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 :
+      !!      Gather the 4 northern lines of the global domain on 1 processor and 
+      !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+      !!      back to the processors.
+      !!
+      !! History :
+      !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+      !!                                  from lbc routine
+      !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jk, jr, jproc
+      INTEGER :: ierr
+      INTEGER :: ildi,ilei,iilb
+      INTEGER :: ijpj,ijpjm1,ij,ijt,iju
+      INTEGER :: itaille
+      REAL(wp), DIMENSION(jpiglo,4,jpk) :: ztab
+      REAL(wp), DIMENSION(jpi,4,jpk,jpni) :: znorthgloio
+      REAL(wp), DIMENSION(jpi,4,jpk) :: znorthloc
+      !!----------------------------------------------------------------------
+
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+
+    ! put in znorthloc the last 4 jlines of pt3d
+    DO jk = 1, jpk 
+       DO jj = nlcj - ijpj +1, nlcj
+          ij = jj - nlcj + ijpj
+          znorthloc(:,ij,jk) = pt3d(:,jj,jk)
+       END DO
+    END DO
+
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:,:) = 0_wp
+
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*jpk*ijpj
+       CALL MPI_GATHER(znorthloc,itaille,MPI_DOUBLE_PRECISION,znorthgloio,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc = nrank_north(jr) + 1
+          ildi  = nldit (jproc)
+          ilei  = nleit (jproc)
+          iilb  = nimppt(jproc)
+          DO jk = 1, jpk 
+             DO jj = 1, 4
+                DO ji = ildi, ilei
+                   ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                END DO
+             END DO
+          END DO
+       END DO
+
+
+       ! Horizontal slab
+       ! ===============
+
+       DO jk = 1, jpk 
+
+
+          ! 2. North-Fold boundary conditions
+          ! ----------------------------------
+
+          SELECT CASE ( npolj )
+
+          CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+             ztab( 1    ,ijpj,jk) = 0.e0
+             ztab(jpiglo,ijpj,jk) = 0.e0
+
+             SELECT CASE ( cd_type )
+
+             CASE ( 'T' , 'S' , 'W' )                   ! T-, W-point
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(ijt,ijpjm1,jk)
+                END DO
+
+             CASE ( 'U' )                               ! U-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(iju,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(iju,ijpjm1,jk)
+                END DO
+
+             CASE ( 'V' )                               ! V-point
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj-1,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(ijt,ijpj-3,jk)
+                END DO
+
+             CASE ( 'F' , 'G' )                         ! F-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj-1,jk) = psgn * ztab(iju,ijpj-2,jk)
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(iju,ijpj-3,jk)
+                END DO
+
+             END SELECT
+
+          CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+             ztab( 1    ,ijpj,jk) = 0.e0
+             ztab(jpiglo,ijpj,jk) = 0.e0
+
+             SELECT CASE ( cd_type )
+
+             CASE ( 'T' , 'S' , 'W' )                   ! T-, W-point
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-1,jk)
+                END DO
+
+             CASE ( 'U' )                               ! U-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj,jk) = psgn * ztab(iju,ijpj-1,jk)
+                END DO
+
+             CASE ( 'V' )                               ! V-point
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(ijt,ijpjm1,jk)
+                END DO
+
+             CASE ( 'F' , 'G' )                         ! F-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(iju,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(iju,ijpjm1,jk)
+                END DO
+
+             END SELECT
+
+          CASE DEFAULT                           ! *  closed
+
+             SELECT CASE ( cd_type) 
+
+             CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+                ztab(:, 1  ,jk) = 0.e0
+                ztab(:,ijpj,jk) = 0.e0
+
+             CASE ( 'F' )                               ! F-point
+                ztab(:,ijpj,jk) = 0.e0
+
+             END SELECT
+
+          END SELECT
+
+          !     End of slab
+          !     ===========
+
+       END DO
+
+       !! Scatter back to pt3d
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jk=  1, jpk
+             DO jj=1,ijpj
+                DO ji=ildi,ilei
+                   znorthgloio(ji,jj,jk,jr)=ztab(ji+iilb-1,jj,jk)
+                END DO
+             END DO
+          END DO
+       END DO
+
+    ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+    not done yet in shmem : compiler error
+#elif key_mpp_mpi
+    IF ( npolj /= 0 ) THEN
+       itaille=jpi*jpk*ijpj
+       CALL MPI_SCATTER(znorthgloio,itaille,MPI_DOUBLE_PRECISION,znorthloc,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+    ENDIF
+#endif
+
+    ! put in the last ijpj jlines of pt3d znorthloc
+    DO jk = 1 , jpk 
+       DO jj = nlcj - ijpj + 1 , nlcj
+          ij = jj - nlcj + ijpj
+          pt3d(:,jj,jk)= znorthloc(:,ij,jk)
+       END DO
+    END DO
+
+  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 :
+    !!      Gather the 4 northern lines of the global domain on 1 processor and 
+    !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+    !!      back to the processors.
+    !!
+    !! History :
+    !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+    !!                                  from lbc routine
+    !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+    !!----------------------------------------------------------------------
+
+    !! * Arguments
+    CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-points
+    !             !   = T ,  U , V , F or W  gridpoints
+    REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+    REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+    !             !   = -1. , the sign is changed if north fold boundary
+    !             !   =  1. , the sign is kept  if north fold boundary
+
+
+    !! * Local declarations
+
+    INTEGER :: ji, jj,  jr, jproc
+    INTEGER :: ierr
+    INTEGER :: ildi,ilei,iilb
+    INTEGER :: ijpj,ijpjm1,ij,ijt,iju
+    INTEGER :: itaille
+
+    REAL(wp), DIMENSION(jpiglo,4) :: ztab
+    REAL(wp), DIMENSION(jpi,4,jpni) :: znorthgloio
+    REAL(wp), DIMENSION(jpi,4) :: znorthloc
+    !!----------------------------------------------------------------------
+    !!  OPA 8.5, LODYC-IPSL (2002)
+    !!----------------------------------------------------------------------
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+
+
+    ! put in znorthloc the last 4 jlines of pt2d
+    DO jj = nlcj - ijpj +1, nlcj
+       ij = jj - nlcj + ijpj
+       znorthloc(:,ij)=pt2d(:,jj)
+    END DO
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:) = 0_wp
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*ijpj
+       CALL MPI_GATHER(znorthloc,itaille,MPI_DOUBLE_PRECISION,znorthgloio,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jj=1,4
+             DO ji=ildi,ilei
+                ztab(ji+iilb-1,jj)=znorthgloio(ji,jj,jr)
+             END DO
+          END DO
+       END DO
+
+
+       ! 2. North-Fold boundary conditions
+       ! ----------------------------------
+
+       SELECT CASE ( npolj )
+
+       CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+          ztab( 1    ,ijpj) = 0.e0
+          ztab(jpiglo,ijpj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' , 'S' )                         ! T-, W-point
+             DO ji = 2, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-2)
+             END DO
+             DO ji = jpiglo/2, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO ji = 2, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpj-1) = psgn * ztab(ijt,ijpj-2)
+                ztab(ji,ijpj  ) = psgn * ztab(ijt,ijpj-3)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpj-1) = psgn * ztab(iju,ijpj-2)
+                ztab(ji,ijpj  ) = psgn * ztab(iju,ijpj-3)
+             END DO
+
+          CASE ( 'I' )                                     ! ice U-V point
+             ztab(2,ijpj) = psgn * ztab(3,ijpj-1)
+             DO ji = 3, jpiglo
+                iju = jpiglo - ji + 3
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-1)
+             END DO
+
+          END SELECT
+
+       CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+          ztab( 1 ,ijpj) = 0.e0
+          ztab(jpiglo,ijpj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' ,'S' )                          ! T-, W-point
+             DO ji = 1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO ji = 1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpj  ) = psgn * ztab(iju,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+             CASE ( 'I' )                                  ! ice U-V point
+                ztab( 2 ,ijpj) = 0.e0
+                DO ji = 2 , jpiglo-1
+                   ijt = jpiglo - ji + 2
+                   ztab(ji,ijpj)= 0.5 * ( ztab(ji,ijpj-1) + psgn * ztab(ijt,ijpj-1) )
+                END DO
+
+          END SELECT
+
+       CASE DEFAULT                           ! *  closed : the code probably never go through
+
+            SELECT CASE ( cd_type) 
+  
+            CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+               ztab(:, 1 ) = 0.e0
+               ztab(:,ijpj) = 0.e0
+
+            CASE ( 'F' )                                   ! F-point
+               ztab(:,ijpj) = 0.e0
+
+            CASE ( 'I' )                                   ! ice U-V point
+               ztab(:, 1 ) = 0.e0
+               ztab(:,ijpj) = 0.e0
+
+            END SELECT
+
+         END SELECT
+
+         !     End of slab
+         !     ===========
+
+         !! Scatter back to pt2d
+         DO jr = 1, ndim_rank_north
+            jproc=nrank_north(jr)+1
+            ildi=nldit (jproc)
+            ilei=nleit (jproc)
+            iilb=nimppt(jproc)
+            DO jj=1,ijpj
+               DO ji=ildi,ilei
+                  znorthgloio(ji,jj,jr)=ztab(ji+iilb-1,jj)
+               END DO
+            END DO
+         END DO
+
+      ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+      not done yet in shmem : compiler error
+#elif key_mpp_mpi
+      IF ( npolj /= 0 ) THEN
+         itaille=jpi*ijpj
+         CALL MPI_SCATTER(znorthgloio,itaille,MPI_DOUBLE_PRECISION,znorthloc,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+      ENDIF
+#endif
+
+      ! put in the last ijpj jlines of pt2d znorthloc
+      DO jj = nlcj - ijpj + 1 , nlcj
+         ij = jj - nlcj + ijpj
+         pt2d(:,jj)= znorthloc(:,ij)
+      END DO
+
+   END SUBROUTINE mpp_lbc_north_2d
+
+
+   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 (for 2d array with outer extra halo)
+    !!
+    !! ** Method :
+    !!      Gather the 4+2*jpr2dj northern lines of the global domain on 1 processor and 
+    !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+    !!      back to the processors.
+    !!
+    !! History :
+    !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+    !!                                  from lbc routine
+    !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+    !!   9.0  !  05-09  (R. Benshila )   adapt mpp_lbc_north_2d 
+    !!----------------------------------------------------------------------
+
+    !! * Arguments
+    CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-points
+    !             !   = T ,  U , V , F or W  gridpoints
+    REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+    REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+    !             !   = -1. , the sign is changed if north fold boundary
+    !             !   =  1. , the sign is kept  if north fold boundary
+
+
+    !! * Local declarations
+
+    INTEGER :: ji, jj,  jr, jproc, jl
+    INTEGER :: ierr
+    INTEGER :: ildi,ilei,iilb
+    INTEGER :: ijpj,ijpjm1,ij,ijt,iju, iprecj
+    INTEGER :: itaille
+
+    REAL(wp), DIMENSION(jpiglo,1-jpr2dj:4+jpr2dj) :: ztab
+    REAL(wp), DIMENSION(jpi,1-jpr2dj:4+jpr2dj,jpni) :: znorthgloio
+    REAL(wp), DIMENSION(jpi,1-jpr2dj:4+jpr2dj) :: znorthloc
+
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+    iprecj = jpr2dj+jprecj
+
+    ! put in znorthloc the last 4 jlines of pt2d
+    DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
+       ij = jj - nlcj + ijpj
+       znorthloc(:,ij)=pt2d(1:jpi,jj)
+    END DO
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:) = 0_wp
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*(ijpj+2*jpr2dj)
+       CALL MPI_GATHER(znorthloc(1,1-jpr2dj),itaille,MPI_DOUBLE_PRECISION, &
+                     & znorthgloio(1,1-jpr2dj,1),itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jj=1-jpr2dj,ijpj+jpr2dj
+             DO ji=ildi,ilei
+                ztab(ji+iilb-1,jj)=znorthgloio(ji,jj,jr)
+             END DO
+          END DO
+       END DO
+
+
+       ! 2. North-Fold boundary conditions
+       ! ----------------------------------
+
+       SELECT CASE ( npolj )
+
+       CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+          ztab( 1    ,ijpj:ijpj+jpr2dj) = 0.e0
+          ztab(jpiglo,ijpj:ijpj+jpr2dj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' , 'S' )                         ! T-, W-point
+             DO jl =0, iprecj-1
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO jl =0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+            DO jl =-1, iprecj-1
+               DO ji = 2, jpiglo
+                  ijt = jpiglo-ji+2
+                  ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-3-jl)
+               END DO
+            END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+            DO jl =-1, iprecj-1
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-3-jl)
+               END DO
+             END DO
+
+          CASE ( 'I' )                                     ! ice U-V point
+             DO jl =0, iprecj-1
+                ztab(2,ijpj+jl) = psgn * ztab(3,ijpj-1+jl)
+                DO ji = 3, jpiglo
+                   iju = jpiglo - ji + 3
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-1-jl)
+                END DO
+             END DO
+
+          END SELECT
+
+       CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+          ztab( 1 ,ijpj:ijpj+jpr2dj) = 0.e0
+          ztab(jpiglo,ijpj:ijpj+jpr2dj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' ,'S' )                          ! T-, W-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-1-jl)
+                END DO
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-1-jl)
+                END DO
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+             CASE ( 'I' )                                  ! ice U-V point
+                ztab( 2 ,ijpj:ijpj+jpr2dj) = 0.e0
+                DO jl = 0, jpr2dj
+                   DO ji = 2 , jpiglo-1
+                      ijt = jpiglo - ji + 2
+                      ztab(ji,ijpj+jl)= 0.5 * ( ztab(ji,ijpj-1-jl) + psgn * ztab(ijt,ijpj-1-jl) )
+                   END DO
+                END DO
+
+          END SELECT
+
+       CASE DEFAULT                           ! *  closed : the code probably never go through
+
+            SELECT CASE ( cd_type) 
+  
+            CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+               ztab(:, 1:1-jpr2dj     ) = 0.e0
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            CASE ( 'F' )                                   ! F-point
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            CASE ( 'I' )                                   ! ice U-V point
+               ztab(:, 1:1-jpr2dj     ) = 0.e0
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            END SELECT
+
+         END SELECT
+
+         !     End of slab
+         !     ===========
+
+         !! Scatter back to pt2d
+         DO jr = 1, ndim_rank_north
+            jproc=nrank_north(jr)+1
+            ildi=nldit (jproc)
+            ilei=nleit (jproc)
+            iilb=nimppt(jproc)
+            DO jj=1-jpr2dj,ijpj+jpr2dj
+               DO ji=ildi,ilei
+                  znorthgloio(ji,jj,jr)=ztab(ji+iilb-1,jj)
+               END DO
+            END DO
+         END DO
+
+      ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+      not done yet in shmem : compiler error
+#elif key_mpp_mpi
+      IF ( npolj /= 0 ) THEN
+         itaille=jpi*(ijpj+2*jpr2dj)
+         CALL MPI_SCATTER(znorthgloio(1,1-jpr2dj,1),itaille,MPI_DOUBLE_PRECISION, &
+                        & znorthloc(1,1-jpr2dj),itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+      ENDIF
+#endif
+
+      ! put in the last ijpj jlines of pt2d znorthloc
+      DO jj = nlcj - ijpj  -jpr2dj + 1 , nlcj +jpr2dj
+         ij = jj - nlcj + ijpj 
+         pt2d(1:jpi,jj)= znorthloc(:,ij)
+      END DO
+
+   END SUBROUTINE mpp_lbc_north_e
+
+
+   !!!!!
+
+
+   !! 
+   !!    This is valid on IBM machine ONLY. 
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -*- Mode: F90 -*- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   !! mpi_init_opa.f90 : Redefinition du point d'entree MPI_INIT de la bibliotheque
+   !!                MPI afin de faire, en plus de l'initialisation de
+   !!                l'environnement MPI, l'allocation d'une zone tampon
+   !!                qui sera ulterieurement utilisee automatiquement lors
+   !!                de tous les envois de messages par MPI_BSEND
+   !!
+   !! Auteur : CNRS/IDRIS
+   !! Date   : Tue Nov 13 12:02:14 2001
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   SUBROUTINE mpi_init_opa(code)
+      IMPLICIT NONE
+
+!$AGRIF_DO_NOT_TREAT
+#     include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
+
+      INTEGER                                 :: code,rang
+ 
+      ! La valeur suivante doit etre au moins egale a la taille
+      ! du plus grand message qui sera transfere dans le programme
+      ! (de toute facon, il y aura un message d'erreur si cette
+      ! valeur s'avere trop petite)
+      INTEGER                                 :: taille_tampon
+      CHARACTER(len=9)                        :: taille_tampon_alphanum
+      REAL(kind=8), ALLOCATABLE, DIMENSION(:) :: tampon
+ 
+      ! Le point d'entree dans la bibliotheque MPI elle-meme
+      CALL mpi_init(code)
+
+      ! La definition de la zone tampon pour les futurs envois
+      ! par MPI_BSEND (on alloue une fois pour toute cette zone
+      ! tampon, qui sera automatiquement utilisee lors de chaque
+      ! appel  a MPI_BSEND).
+      ! La desallocation sera implicite quand on sortira de
+      ! l'environnement MPI.
+
+      ! Recuperation de la valeur de la variable d'environnement
+      ! BUFFER_LENGTH
+      ! qui, si elle est definie, doit contenir une valeur superieure
+      ! a  la taille en octets du plus gros message
+      CALL getenv('BUFFER_LENGTH',taille_tampon_alphanum)
+  
+      ! Si la variable BUFFER_LENGTH n'est pas positionnee, on lui met par
+      ! defaut la plus grande valeur de la variable MP_EAGER_LIMIT, soit
+      ! 65 536 octets
+      IF (taille_tampon_alphanum == ' ') THEN
+         taille_tampon = 65536
+      ELSE
+         READ(taille_tampon_alphanum,'(i9)') taille_tampon
+      END IF
+
+      ! On est limite en mode d'adressage 32 bits a  1750 Mo pour la zone
+      ! "data" soit 7 segments, c.-a -d. 1750/8 = 210 Mo
+      IF (taille_tampon > 210000000) THEN
+         PRINT *,'Attention la valeur BUFFER_LENGTH doit etre <= 210000000'
+         CALL mpi_abort(MPI_COMM_WORLD,2,code)
+      END IF
+
+      CALL mpi_comm_rank(MPI_COMM_WORLD,rang,code)
+      IF (rang == 0 ) PRINT *,'Taille du buffer alloue : ',taille_tampon
+
+      ! Allocation du tampon et attachement
+      ALLOCATE(tampon(taille_tampon))
+      CALL mpi_buffer_attach(tampon,taille_tampon,code)
+
+   END SUBROUTINE mpi_init_opa
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case:            Dummy module        share memory computing
+   !!----------------------------------------------------------------------
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE 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_isl
+      MODULE PROCEDURE mppisl_a_int, mppisl_int, mppisl_a_real, mppisl_real
+   END INTERFACE
+   INTERFACE mppobc
+      MODULE PROCEDURE mppobc_1d, mppobc_2d, mppobc_3d, mppobc_4d
+   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
+
+CONTAINS
+
+   FUNCTION mynode() RESULT (function_value)
+      function_value = 0
+   END FUNCTION mynode
+
+   SUBROUTINE mppsync                       ! Dummy routine
+   END SUBROUTINE mppsync
+
+   SUBROUTINE mpp_sum_as( parr, kdim )      ! Dummy routine
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mpp_sum_as
+
+   SUBROUTINE mpp_sum_a2s( parr, kdim )      ! Dummy routine
+      REAL   , DIMENSION(:,:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1)
+   END SUBROUTINE mpp_sum_a2s
+
+   SUBROUTINE mpp_sum_ai( karr, kdim )      ! Dummy routine
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mpp_sum_ai
+
+   SUBROUTINE mpp_sum_s( psca )            ! Dummy routine
+      REAL                  :: psca
+      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca
+   END SUBROUTINE mpp_sum_s
+
+   SUBROUTINE mpp_sum_i( kint )            ! Dummy routine
+      integer               :: kint
+      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint
+   END SUBROUTINE mpp_sum_i
+
+   SUBROUTINE mppmax_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppmax_a_real
+
+   SUBROUTINE mppmax_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmin_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppmin_a_real
+
+   SUBROUTINE mppmin_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppmin_real
+
+   SUBROUTINE mppmin_a_int( karr, kdim )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mppmin_a_int
+
+   SUBROUTINE mppmin_int( kint )
+      INTEGER               :: kint
+      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint
+   END SUBROUTINE mppmin_int
+
+   SUBROUTINE mppobc_1d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_1d
+
+   SUBROUTINE mppobc_2d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_2d
+
+   SUBROUTINE mppobc_3d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_3d
+
+   SUBROUTINE mppobc_4d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_4d
+
+
+   SUBROUTINE mpplnks( parr )            ! Dummy routine
+      REAL, DIMENSION(:,:) :: parr
+      WRITE(*,*) 'mpplnks: You should not have seen this print! error?', parr(1,1)
+   END SUBROUTINE mpplnks
+
+   SUBROUTINE mppisl_a_int( karr, kdim )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppisl_a_int: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mppisl_a_int
+
+   SUBROUTINE mppisl_int( kint )
+      INTEGER               :: kint
+      WRITE(*,*) 'mppisl_int: You should not have seen this print! error?', kint
+   END SUBROUTINE mppisl_int
+
+   SUBROUTINE mppisl_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppisl_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppisl_a_real
+
+   SUBROUTINE mppisl_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppisl_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppisl_real
+
+   SUBROUTINE mpp_minloc2d ( ptab, pmask, pmin, ki, kj )
+      REAL                   :: pmin
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mppisl_real: You should not have seen this print! error?', pmin, ki, kj
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmin, ki, kj, kk
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmax, ki, kj
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmax, ki, kj, kk
+      WRITE(*,*) '   "      ":             "                 "            ', ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_maxloc3d
+
+   SUBROUTINE mppstop
+      WRITE(*,*) 'mppstop: You should not have seen this print! error?'
+   END SUBROUTINE mppstop
+
+#endif
+   !!----------------------------------------------------------------------
+END MODULE lib_mpp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_print.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_print.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/lib_print.f90	(revision 4536)
@@ -0,0 +1,265 @@
+MODULE lib_print
+   !!======================================================================
+   !!                    ***  MODULE  lib_print  ***
+   !! print librairy :  formated real and integer array print
+   !!=====================================================================
+      
+   !!----------------------------------------------------------------------
+   !!   prihin       : print an integer 2D horizontal field
+   !!   prihre       : print an real 2D horizontal field
+   !!   prizre       : print an real 2D vertical field
+   !!----------------------------------------------------------------------
+   !! * Mules used
+   USE par_kind      ! kind parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC prihin, prihre, prizre
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE prihin( ktab, ki   , kj   , kideb, kifin ,   &
+                      kind, kjdeb, kjfin, kjnd , kscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  prihre  ***
+      !!  
+      !! ** purpose :   Print an integer field
+      !!
+      !! ** method :   format of print is selected with the dummy argument kscale
+      !!
+      !! History :
+      !!        !  90-04 (0. Marti)  Original code
+      !!        !  92-02 (M. Imbard)
+      !!        !  03-07 (G. Madec)  F90, free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj,                 &  ! array dimensions
+         kideb, kifin, kind,     &  ! first and last index, increment for i 
+         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
+         kscale,                 &  ! kscale=0 or > 5  print ktab with format i8
+      !                             !         kscale=1 print ktab with format i1
+      !                             !         kscale=2 print ktab with format i2
+      !                             !         kscale=3 print ktab with format i3
+      !                             !         kscale=4 print ktab with format i4
+      !                             !         kscale=5 print ktab with format i5
+         kumout                     ! unit in which print
+      INTEGER, DIMENSION(ki,kj), INTENT( in ) ::   &
+         ktab                       ! integer 2D array to be print
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jn       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+      INTEGER ::   iind, ijnd       ! temporary integers
+
+      isca = 10
+      IF( kscale == 0 )   isca = 10
+      IF( kscale == 1 )   isca = 100
+      IF( kscale == 2 )   isca = 60
+      IF( kscale == 3 )   isca = 40
+      IF( kscale == 4 )   isca = 30
+      IF( kscale == 5 )   isca = 20
+
+      iind = MAX( 1, kind )
+      ijnd = MAX( 1, kjnd )
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
+
+        IF( il1 > kifin ) RETURN
+        WRITE(kumout,'(/)')
+        il2 = il1+iind*(isca-1)
+        IF( il2 > kifin )   il2 = kifin
+
+        IF( kscale == 1 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)') il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,100i1)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 2 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,60i2)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 3 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,40i3)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 4 ) THEN
+            WRITE(kumout,'(4x,30i4,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,30i4)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 5 ) THEN
+            WRITE(kumout,'(4x,20i5,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,20i5)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSE
+            WRITE(kumout,'(4x,10i8,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,10i8)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ENDIF
+
+        il1 = il1 + iind * isca
+      END DO  
+
+   END SUBROUTINE prihin
+
+
+   SUBROUTINE prihre( ptab, ki   , kj   , kideb, kifin ,   &
+                      kind, kjdeb, kjfin, kjnd , pscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE prihre  ***
+      !!      
+      !! ** purpose :   Print a real field with the format 10e12.4 or 20f6.2
+      !!
+      !! ** method  :   the print format is selected with the pscale argument
+      !!
+      !! History :
+      !!   1.0  !  86-01  (P. Andrich)  Original code
+      !!        !  89-11  (C. Levy)
+      !!        !  92-02  (M. Imbard)
+      !!        !  92-06  (M. Imbard)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj,                 &  ! array dimensions
+         kideb, kifin, kind,     &  ! first and last index, increment for i
+         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
+         kumout                     ! unit in which print
+      REAL(wp), INTENT( in ) ::   &
+         pscale                     ! = 0  print        ptab with e13.5 format
+         !                          ! else print pscale*ptab with f6.2 format
+      REAL(wp), DIMENSION(ki,kj), INTENT( in ) ::   &
+         ptab                       ! integer 2D array to be print
+
+      !! * Local variables
+      INTEGER ::   ji, jj, jn       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+
+      isca = 10
+      IF( pscale /= 0. )   isca=20
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(kind*isca) + 1
+
+        IF( il1 > kifin )   RETURN
+
+        WRITE(kumout,9100)
+
+        il2 = il1+kind*(isca-1)
+        IF(il2 > kifin) il2 = kifin
+        IF( pscale == 0.) THEN
+            WRITE(kumout,9101) ( ji, ji = il1, il2, kind )
+            DO jj = kjfin, kjdeb, -kjnd
+              WRITE(kumout,9102) jj, ( ptab(ji,jj), ji = il1, il2, kind )
+            END DO  
+        ELSE
+            WRITE(kumout,9103) ( ji, ji = il1, il2, kind )
+            DO jj = kjfin, kjdeb, -kjnd
+              WRITE(kumout,9104) jj, ( pscale*ptab(ji,jj), ji = il1, il2, kind )
+            END DO  
+        ENDIF
+        il1 = il1+kind*isca
+
+      END DO  
+
+      ! formats
+ 9100 FORMAT(/)
+ 9101 FORMAT(10i12, /)
+ 9102 FORMAT(1x, i3, 10(1pe12.4))
+ 9103 FORMAT(3x, 20i6, /)
+ 9104 FORMAT(1x, i3, 1x, 20f6.2)
+
+   END SUBROUTINE prihre
+
+
+   SUBROUTINE prizre( ptab , ki   , kj   , kk   , kjcut ,   &
+                      kideb, kifin, kid  , kkdeb, kkfin ,   &
+                      kkd  , pscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE prizre  ***
+      !!
+      !! ** purpose :   Print a vertical slab from a tridimentional real field
+      !!
+      !!   METHOD :
+      !! ** method  :   the print format is selected with the argument pscale
+      !!
+      !! History :
+      !!      original : 86-01 (o. Marti)
+      !!      addition : 92-02 (M. Imbard)
+      !!      addition : 92-06 (M. Imbard)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj, kk,             &  ! array dimensions
+         kjcut,                  &  ! index j for the vertical slab
+         kideb, kifin, kid,      &  ! first and last index, increment for i
+         kkdeb, kkfin, kkd,      &  ! first and last index, increment for k
+         kumout                     ! unit in which print
+      REAL(wp), INTENT( in ) ::   &
+         pscale                     ! = 0  print        ptab with e12.4 format
+         !                          ! else print pscale*ptab with f6.2 format
+      REAL(wp), DIMENSION(ki,kj,kk), INTENT( in ) ::   &
+         ptab                       ! integer 3D array to be print
+
+      !! * Local variables
+      INTEGER ::   ji, jn, jk       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+      INTEGER ::   iind, iknd       !    "          "
+
+
+      iind = kid
+      iknd = kkd
+      isca = 10
+      IF( pscale /= 0.) isca = 20
+
+      IF (iind == 0) iind = 1
+      IF (iknd == 0) iknd = 1
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
+
+        IF(il1 > kifin) RETURN
+        WRITE(kumout,9100)
+        il2 = il1+iind*(isca-1)
+        IF(il2 > kifin) il2 = kifin
+
+        IF( pscale == 0.) THEN
+            WRITE(kumout,9101) ( ji, ji = il1, il2, iind )
+            DO jk = kkdeb, kkfin, iknd
+              WRITE (kumout,9102) jk, ( ptab(ji,kjcut,jk), ji = il1, il2, iind )
+            END DO  
+        ELSE
+            WRITE (kumout,9103) ( ji, ji = il1, il2, iind )
+            DO jk = kkdeb, kkfin, iknd
+              WRITE(kumout,9104)jk, ( pscale*ptab(ji,kjcut,jk), ji = il1, il2, iind )
+            END DO  
+        ENDIF
+
+        il1 = il1+iind*isca
+      END DO      
+
+ 9100 FORMAT(/)
+ 9101 FORMAT(10i12, /)
+ 9102 FORMAT(1x, i3, 10(1pe12.4))
+ 9103 FORMAT(3x, 20i6, /)
+ 9104 FORMAT(1x, i3, 1x, 20f6.1)
+
+      END SUBROUTINE prizre
+
+   !!======================================================================
+END MODULE lib_print
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/model.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/model.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/model.f90	(revision 4536)
@@ -0,0 +1,21 @@
+PROGRAM model
+   !!----------------------------------------------------------------------
+   !!                     ***  PROGRAM model  ***
+   !!
+   !! ** Purpose :   encapsulate the opa model so that opa can also be 
+   !!      called together with the adjoint and linear tangent models
+   !!
+   !! History :
+   !!   8.0  !  01-02  (M. Imbard, A. Weaver)  Original code
+   !!   9.0  !  03-10  (G. Madec) F90
+   !!----------------------------------------------------------------------
+   USE opa                  ! OPA system     (opa_model routine)
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+ 
+   CALL opa_model           ! OPA system
+ 
+END PROGRAM model
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/module_example
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/module_example	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/module_example	(revision 4536)
@@ -0,0 +1,211 @@
+MODULE exampl
+   !!======================================================================
+   !!                       ***  MODULE  example  ***
+   !! Ocean physics:  brief description of the purpose of the module
+   !!                 (please no more than 2 lines)
+   !!=====================================================================
+#if defined key_example
+   !!----------------------------------------------------------------------
+   !!   'key_example'  :                brief description of the key option
+   !!----------------------------------------------------------------------
+   !!   exa_mpl      : liste of module subroutine (caution, never use the
+   !!   exa_mpl_init : name of the module for a routine)
+   !!   exa_mpl_stp  : Please try to use 3 letter block for routine names
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE module_name1            ! brief description of the used module
+   USE module_name2            ! ....
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC exa_mpl    ! routine called in xxx.F90 module
+
+   !! * Share Module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      var1    ,   &  !: var1 description (CAUTION always use !: to describe a 
+      !              !  PUBLIC variable simplify the search of where it is declared
+      var2           !: var2 description
+
+   !! * Module variables
+   INTEGER ::                 & !!! ** toto namelist (namtoto) **
+      nflag  =  1                ! default value of nflag 
+   REAL(wp) ::                & !!! ** toto namlist (namtoto) **
+      var3  = 2._wp / 9._wp      ! default value of var3
+   REAL(wp) ::   &  
+      var4          ! var4 description (local permanent variable)
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      tab1          ! coefficient used for horizontal smoothing
+
+   !! * Substitutions
+#  include "exampl_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! or LIM 2.0 , UCL-LOCEAN-IPSL (2005)
+   !! or  TOP 1.0 , LOCEAN-IPSL (2005)
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_autotasking
+   !!----------------------------------------------------------------------
+   !!   'key_autotasking'                              autotasking (j-slab)
+   !!----------------------------------------------------------------------
+#  include "exampl_autotsk.h90"
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                           vector opt. (k-j-i loop)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE exa_mpl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE exa_mpl  ***
+      !!
+      !! ** Purpose :   Brief description of the routine
+      !!
+      !! ** Method  :   description of the methodoloy used to achieve the
+      !!      objectives of the routine. Be as clear as possible!
+      !!
+      !! ** Action  : - first action (share memory array/varible modified
+      !!                in this routine
+      !!              - second action .....
+      !!              - .....
+      !!
+      !! References :
+      !!   Give references if exist otherwise suppress these lines
+      !!
+      !! History :
+      !!   9.0  !  03-08  (Autor Names)  Original code
+      !!        !  02-08  (Author names)  brief description of modifications
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE toto_module                ! description od the module
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   &  
+         kt                          ! describe it!!!
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jk        ! dummy loop arguments
+      INTEGER ::   &
+         itoto, itata,            &  ! temporary integers
+         ititi                       ! please do not forget the DOCTOR rule:
+         !                           ! local integer: name start with i
+      REAL(wp) ::   &
+         zmlmin, zbbrau,          &  ! temporary scalars
+         zfact1, zfact2, zfact3,  &  !    "         "
+         zbn2, zesurf,            &  ! local scalar: name start with z
+         zemxl                       !
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         ztoto                       ! temporary workspace
+      !!--------------------------------------------------------------------
+
+
+
+      IF( kt == nit000  )   CALL exa_mpl_init    ! Initialization (first time-step only)
+
+      ! Local constant initialization
+      zmlmin = 1.e-8
+      zbbrau =  .5 * ebb / rau0
+      zfact1 = -.5 * rdt * efave
+      zfact2 = 1.5 * rdt * ediss
+      zfact3 = 0.5 * rdt * ediss
+
+
+      SELECT CASE ( npdl )
+
+      CASE ( 0 )           ! describe case 1
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmv(ji,jj,jk) = ....
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )           ! describe case 2
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmv(ji,jj,jk) = ...
+               END DO
+            END DO
+         END DO
+
+      END SELECT
+
+      ! Lateral boundary conditions (avmu)   (unchanged sign)
+      CALL mpplnk2( avmu, 'U', 1. )
+
+   END SUBROUTINE exa_mpl
+
+# endif
+
+   SUBROUTINE exa_mpl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE exa_mpl_init  ***
+      !!                   
+      !! ** Purpose :   initialization of ....
+      !!
+      !! ** Method  :   blah blah blah ...
+      !!
+      !! ** input   :   Namlist namexa
+      !!
+      !! ** Action  :   ...  
+      !!
+      !! history :
+      !!   9.0  !  03-08  (Autor Names)  Original code
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER ::   ji, jj, jk, jit   ! dummy loop indices
+
+      NAMELIST/namexa/ exa_v1, exa_v2, nexa_0  
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namexa : example parameters
+      REWIND ( numnam )
+      READ   ( numnam, namexa )
+
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'exa_mpl_init : example '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namexa : set example parameters'
+         WRITE(numout,*) '             brief desciption               exa_v1  = ', exa_v1
+         WRITE(numout,*) '             brief desciption               exa_v1  = ', exa_v1
+         WRITE(numout,*) '             brief desciption               nexa_0  = ', nexa_0
+      ENDIF
+
+      ! Parameter control
+#if defined key_toto
+      IF(lwp) WRITE(numout,cform_err)
+      IF(lwp) WRITE(numout,*) '          this part and key_toto are incompatible'
+      nstop = nstop + 1
+#endif
+
+      ! Check nexa_0 values
+      IF( nexa_0 < 0 ) THEN
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag: nmxl is < 0 or > 3 '
+         nstop = nstop + 1
+      ENDIF
+
+   END SUBROUTINE exa_mpl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE exa_mpl              ! Empty routine
+   END SUBROUTINE exa_mpl
+#endif
+
+   !!======================================================================
+END MODULE exampl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini.F90	(revision 4536)
@@ -0,0 +1,557 @@
+MODULE mppini
+   !!==============================================================================
+   !!                       ***  MODULE mppini   ***
+   !! Ocean initialization : distributed memory computing initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   mpp_init       : Lay out the global domain over processors
+   !!   mpp_init2      : Lay out the global domain over processors 
+   !!                    with land processor elimination
+   !!   mpp_init_ioispl: IOIPSL initialization in mpp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O Manager
+   USE sol_oce         ! ocean elliptic solver
+   USE lib_mpp         ! distribued memory computing library
+   USE ioipsl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC mpp_init       ! called by opa.F90
+   PUBLIC mpp_init2      ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if ! defined key_mpp_mpi   &&   ! defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   Default option :                            shared memory computing
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE mpp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init  ***
+      !!
+      !! ** Purpose :   Lay out the global domain over processors.
+      !!
+      !! ** Method  :   Shared memory computing, set the local processor
+      !!      variables to the value of the global domain
+      !!
+      !! History :
+      !!   9.0  !  04-01  (G. Madec, J.M. Molines)  F90 : free form, north fold jpni >1
+      !!----------------------------------------------------------------------
+      ! No mpp computation
+
+      nimpp  = 1
+      njmpp  = 1
+      nlci   = jpi
+      nlcj   = jpj
+      nldi   = 1
+      nldj   = 1
+      nlei   = jpi
+      nlej   = jpj
+      nperio = jperio
+      nbondi = 2
+      nbondj = 2
+      nidom  = FLIO_DOM_NONE
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'mpp_init(2) : NO massively parallel processing'
+         WRITE(numout,*) '~~~~~~~~~~~: '
+         WRITE(numout,*) '         nperio = ', nperio
+         WRITE(numout,*) '         npolj  = ', npolj
+         WRITE(numout,*) '         nimpp  = ', nimpp
+         WRITE(numout,*) '         njmpp  = ', njmpp
+      ENDIF
+
+      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 ) THEN
+          IF(lwp)WRITE(numout,cform_err)
+          IF(lwp)WRITE(numout,*) 'equality  jpni = jpnj = jpnij = 1 is not satisfied'
+          IF(lwp)WRITE(numout,*) 'the domain is lay out for distributed memory computing! '
+          nstop = nstop + 1
+      ENDIF
+
+   END SUBROUTINE mpp_init
+
+
+   SUBROUTINE mpp_init2 
+      CALL mpp_init                             ! same routine as mpp_init
+   END SUBROUTINE mpp_init2
+
+#else
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'          OR         MPI massively parallel processing
+   !!   'key_mpp_shmem'                 SHMEM massively parallel processing
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE mpp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init  ***
+      !!                    
+      !! ** Purpose :   Lay out the global domain over processors.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!      Periodic condition is a function of the local domain position
+      !!      (global boundary or neighbouring domain) and of the global
+      !!      periodic
+      !!      Type :         jperio global periodic condition
+      !!                     nperio local  periodic condition
+      !!
+      !! ** Action  : - set domain parameters
+      !!                    nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlci      : first dimension
+      !!                    nlcj      : second dimension
+      !!                    nbondi    : mark for "east-west local boundary"
+      !!                    nbondj    : mark for "north-south local boundary"
+      !!                    nproc     : number for local processor
+      !!                    noea      : number for local neighboring processor
+      !!                    nowe      : number for local neighboring processor
+      !!                    noso      : number for local neighboring processor
+      !!                    nono      : number for local neighboring processor
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji, jj, jn               ! dummy loop indices
+      INTEGER ::   &
+         ii, ij, ifreq, il1, il2,        &  ! temporary integers
+         iresti, irestj, ijm1, imil,     &  !    "          "
+         inum                               ! temporary logical unit
+
+      INTEGER, DIMENSION(jpni,jpnj) ::   &
+         iimppt, ijmppt, ilcit, ilcjt       ! temporary workspace
+      REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      !!----------------------------------------------------------------------
+
+#if defined key_mpp_shmem
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing PVM T3E + SHMEM'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+
+      CALL mppshmem                           ! Initialisation of shmem array
+
+#endif
+#if defined key_mpp_mpi
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing MPI'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+#endif
+
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+      !  Computation of local domain sizes ilcit() ilcjt()
+      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array (cf. par_oce.F90).
+      
+      nreci  = 2 * jpreci
+      nrecj  = 2 * jprecj
+      iresti = MOD( jpiglo - nreci , jpni )
+      irestj = MOD( jpjglo - nrecj , jpnj )
+
+      IF(  iresti == 0 )   iresti = jpni
+      DO jj = 1, jpnj
+         DO ji = 1, iresti
+            ilcit(ji,jj) = jpi
+         END DO
+         DO ji = iresti+1, jpni
+            ilcit(ji,jj) = jpi -1
+         END DO
+      END DO
+      
+      IF( irestj == 0 )   irestj = jpnj
+      DO ji = 1, jpni
+         DO jj = 1, irestj
+            ilcjt(ji,jj) = jpj
+         END DO
+         DO jj = irestj+1, jpnj
+            ilcjt(ji,jj) = jpj -1
+         END DO
+      END DO
+      
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           defines mpp subdomains'
+         WRITE(numout,*) '           ----------------------'
+         WRITE(numout,*) '              iresti=',iresti,' irestj=',irestj
+         WRITE(numout,*) '              jpni=',jpni,' jpnj=',jpnj
+         ifreq = 4
+         il1   = 1
+         DO jn = 1, (jpni-1)/ifreq+1
+            il2 = MIN( jpni, il1+ifreq-1 )
+            WRITE(numout,*)
+            WRITE(numout,9201) (ji,ji = il1,il2)
+            WRITE(numout,9200) ('***',ji = il1,il2-1)
+            DO jj = 1, jpnj
+               WRITE(numout,9203) ('   ',ji = il1,il2-1)
+               WRITE(numout,9202) jj, ( ilcit(ji,jj),ilcjt(ji,jj),ji = il1,il2 )
+               WRITE(numout,9203) ('   ',ji = il1,il2-1)
+               WRITE(numout,9200) ('***',ji = il1,il2-1)
+            END DO
+            il1 = il1+ifreq
+         END DO
+ 9200    FORMAT('     ***',20('*************',a3))
+ 9203    FORMAT('     *     ',20('         *   ',a3))
+ 9201    FORMAT('        ',20('   ',i3,'          '))
+ 9202    FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+      ENDIF
+
+      zidom = nreci
+      DO ji = 1, jpni
+         zidom = zidom + ilcit(ji,1) - nreci
+      END DO
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilcit(i,1) = ', zidom, ' jpiglo = ', jpiglo
+      
+      zjdom = nrecj
+      DO jj = 1, jpnj
+         zjdom = zjdom + ilcjt(1,jj) - nrecj
+      END DO
+      IF(lwp) WRITE(numout,*)' sum ilcit(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      IF(lwp) WRITE(numout,*)
+      
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+      
+      iimppt(:,:) = 1
+      ijmppt(:,:) = 1
+      
+      IF( jpni > 1 ) THEN
+         DO jj = 1, jpnj
+            DO ji = 2, jpni
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilcit(ji-1,jj) - nreci
+            END DO
+         END DO
+      ENDIF
+
+      IF( jpnj > 1 ) THEN
+         DO jj = 2, jpnj
+            DO ji = 1, jpni
+               ijmppt(ji,jj) = ijmppt(ji,jj-1)+ilcjt(ji,jj-1)-nrecj
+            END DO
+         END DO
+      ENDIF
+      
+      ! 3. Subdomain description
+      ! ------------------------
+
+      DO jn = 1, jpnij
+         ii = 1 + MOD( jn-1, jpni )
+         ij = 1 + (jn-1) / jpni
+         nimppt(jn) = iimppt(ii,ij)
+         njmppt(jn) = ijmppt(ii,ij)
+         nlcit (jn) = ilcit (ii,ij)     
+         nlci       = nlcit (jn)     
+         nlcjt (jn) = ilcjt (ii,ij)     
+         nlcj       = nlcjt (jn)
+         nbondj = -1                                   ! general case
+         IF( jn   >  jpni          )   nbondj = 0      ! first row of processor
+         IF( jn   >  (jpnj-1)*jpni )   nbondj = 1      ! last  row of processor
+         IF( jpnj == 1             )   nbondj = 2      ! one processor only in j-direction
+         ibonjt(jn) = nbondj
+         
+         nbondi = 0                                    ! 
+         IF( MOD( jn, jpni ) == 1 )   nbondi = -1      !
+         IF( MOD( jn, jpni ) == 0 )   nbondi =  1      !
+         IF( jpni            == 1 )   nbondi =  2      ! one processor only in i-direction
+         ibonit(jn) = nbondi
+         
+         nldi =  1   + jpreci
+         nlei = nlci - jpreci
+         IF( nbondi == -1 .OR. nbondi == 2 )   nldi = 1
+         IF( nbondi ==  1 .OR. nbondi == 2 )   nlei = nlci
+         nldj =  1   + jprecj
+         nlej = nlcj - jprecj
+         IF( nbondj == -1 .OR. nbondj == 2 )   nldj = 1
+         IF( nbondj ==  1 .OR. nbondj == 2 )   nlej = nlcj
+         nldit(jn) = nldi
+         nleit(jn) = nlei
+         nldjt(jn) = nldj
+         nlejt(jn) = nlej
+      END DO
+      
+
+      ! 4. From global to local
+      ! -----------------------
+
+      nperio = 0
+      IF( jperio == 2 .AND. nbondj == -1 )   nperio = 2
+
+
+      ! 5. Subdomain neighbours
+      ! ----------------------
+
+      nproc = narea - 1
+      noso  = nproc - jpni
+      nowe  = nproc - 1
+      noea  = nproc + 1
+      nono  = nproc + jpni
+      ! great neighbours
+      npnw = nono - 1
+      npne = nono + 1
+      npsw = noso - 1
+      npse = noso + 1
+      nbsw = 1
+      nbnw = 1
+      IF( MOD( nproc, jpni ) == 0 ) THEN
+         nbsw = 0
+         nbnw = 0
+      ENDIF
+      nbse = 1
+      nbne = 1
+      IF( MOD( nproc, jpni ) == jpni-1 ) THEN
+         nbse = 0
+         nbne = 0
+      ENDIF
+      IF(nproc < jpni) THEN
+         nbsw = 0
+         nbse = 0
+      ENDIF
+      IF( nproc >= (jpnj-1)*jpni ) THEN
+         nbnw = 0
+         nbne = 0
+      ENDIF
+      nlcj = nlcjt(narea)  
+      nlci = nlcit(narea)  
+      nldi = nldit(narea)
+      nlei = nleit(narea)
+      nldj = nldjt(narea)
+      nlej = nlejt(narea)
+      nbondi = ibonit(narea)
+      nbondj = ibonjt(narea)
+      nimpp  = nimppt(narea)  
+      njmpp  = njmppt(narea)  
+
+     ! Save processor layout in layout.dat file 
+       IF (lwp) THEN
+        CALL ctlopn( inum, 'layout.dat', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+           &         1, numout, .FALSE., 1 )
+        WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
+        WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
+
+        DO  jn = 1, jpnij
+         WRITE(inum,'(9i5)') jn, nlcit(jn), nlcjt(jn), &
+                                      nldit(jn), nldjt(jn), &
+                                      nleit(jn), nlejt(jn), &
+                                      nimppt(jn), njmppt(jn)
+        END DO
+        CLOSE(inum)   
+      END IF
+
+
+      ! w a r n i n g  narea (zone) /= nproc (processors)!
+
+      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+         IF( jpni == 1 )THEN
+            nbondi = 2
+            nperio = 1
+         ELSE
+            nbondi = 0
+         ENDIF
+         IF( MOD( narea, jpni ) == 0 ) THEN
+            noea = nproc-(jpni-1)
+            npne = npne-jpni
+            npse = npse-jpni
+         ENDIF
+         IF( MOD( narea, jpni ) == 1 ) THEN
+            nowe = nproc+(jpni-1)
+            npnw = npnw+jpni
+            npsw = npsw+jpni
+         ENDIF
+         nbsw = 1
+         nbnw = 1
+         nbse = 1
+         nbne = 1
+         IF( nproc < jpni ) THEN
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         IF( nproc >= (jpnj-1)*jpni ) THEN
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+      npolj = 0
+      IF( jperio == 3 .OR. jperio == 4 ) THEN
+         ijm1 = jpni*(jpnj-1)
+         imil = ijm1+(jpni+1)/2
+         IF( narea > ijm1 ) npolj = 3
+         IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 4
+         IF( npolj == 3 ) nono = jpni*jpnj-narea+ijm1
+      ENDIF
+      IF( jperio == 5 .OR. jperio == 6 ) THEN
+          ijm1 = jpni*(jpnj-1)
+          imil = ijm1+(jpni+1)/2
+          IF( narea > ijm1) npolj = 5
+          IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 6
+          IF( npolj == 5 ) nono = jpni*jpnj-narea+ijm1
+      ENDIF
+
+      ! FETI method
+
+      IF( nperio == 1 .AND. nsolv == 3 ) THEN 
+         
+         ! general case : Earth == infinite tube
+         
+         nbnw = 1
+         npnw = narea
+         nbne = 1
+         npne = narea
+         nbsw = 1
+         npsw = (narea-2)
+         nbse = 1
+         npse = (narea-2)
+         
+         ! REAL boundary condition
+         
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         
+         IF( nbondj == 1  .OR. nbondj == 2 ) THEN 
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+
+      ! Periodicity : no corner if nbondi = 2 and nperio != 1
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' nproc  = ', nproc
+         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
+         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
+         WRITE(numout,*) ' nbondi = ', nbondi
+         WRITE(numout,*) ' nbondj = ', nbondj
+         WRITE(numout,*) ' npolj  = ', npolj
+         WRITE(numout,*) ' nperio = ', nperio
+         WRITE(numout,*) ' nlci   = ', nlci
+         WRITE(numout,*) ' nlcj   = ', nlcj
+         WRITE(numout,*) ' nimpp  = ', nimpp
+         WRITE(numout,*) ' njmpp  = ', njmpp
+         WRITE(numout,*) ' nbse   = ', nbse  , ' npse   = ', npse
+         WRITE(numout,*) ' nbsw   = ', nbsw  , ' npsw   = ', npsw
+         WRITE(numout,*) ' nbne   = ', nbne  , ' npne   = ', npne
+         WRITE(numout,*) ' nbnw   = ', nbnw  , ' npnw   = ', npnw
+      ENDIF
+
+      IF( nperio == 1 .AND. jpni /= 1 )THEN
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) ' mpp_init: error on cyclicity'
+         nstop = nstop + 1
+      ENDIF
+
+      ! Prepare mpp north fold
+
+      IF (jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
+         CALL mpp_ini_north
+      END IF
+
+      ! Prepare NetCDF output file (if necessary)
+      CALL mpp_init_ioipsl
+
+   END SUBROUTINE mpp_init
+
+#  include "mppini_2.h90"
+
+# if defined key_dimgout
+   !!----------------------------------------------------------------------
+   !!   'key_dimgout'                  NO use of NetCDF files
+   !!----------------------------------------------------------------------
+   SUBROUTINE mpp_init_ioipsl       ! Dummy routine
+   END SUBROUTINE mpp_init_ioipsl  
+# else
+   SUBROUTINE mpp_init_ioipsl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init_ioipsl  ***
+      !!
+      !! ** Purpose :   
+      !!
+      !! ** Method  :   
+      !!
+      !! History :
+      !!   9.0  !  04-03  (G. Madec)  MPP-IOIPSL 
+      !!----------------------------------------------------------------------
+      !! Local declarations
+
+      INTEGER, DIMENSION(2) ::   &
+         iglo, iloc, iabsf, iabsl, ihals, ihale, idid
+      INTEGER ::   &
+         inbondi, inbondj
+      !!----------------------------------------------------------------------
+
+      ! The domain is splitted only horizontally along i- or/and j- direction
+      ! So we need at the most only 1D arrays with 2 elements
+      iglo(1) = jpiglo
+      iglo(2) = jpjglo
+      iloc(1) = nlci
+      iloc(2) = nlcj
+      iabsf(1) = nimppt(narea)
+      iabsf(2) = njmppt(narea)
+      iabsl(:) = iabsf(:) + iloc(:) - 1
+      ihals(1) = jpreci
+      ihals(2) = jprecj
+      ihale(1) = jpreci
+      ihale(2) = jprecj
+      idid(1) = 1
+      idid(2) = 2
+
+      inbondj = -1                                   ! general case
+      IF( narea   >  jpni          )   inbondj = 0      ! first row of processor
+      IF( narea   >  (jpnj-1)*jpni )   inbondj = 1      ! last  row of processor
+      IF( jpnj    == 1             )   inbondj = 2      ! one processor only in j-direction
+      IF( inbondj == -1 .OR. inbondj == 2 )   ihals(2) = 0
+      IF( inbondj ==  1 .OR. inbondj == 2 )   ihale(2) = 0
+         
+      inbondi = 0                                    ! 
+      IF( MOD( narea, jpni ) == 1 )   inbondi = -1      !
+      IF( MOD( narea, jpni ) == 0 )   inbondi =  1      !
+      IF( jpni               == 1 )   inbondi =  2      ! one processor only in i-direction
+      IF( inbondi == -1 .OR. inbondi == 2 )   ihals(1) = 0
+      IF( inbondi ==  1 .OR. inbondi == 2 )   ihale(1) = 0
+
+
+      IF(lwp) THEN
+          WRITE(numout,*) 'mpp_init_ioipsl :   iloc  = ', iloc (1), iloc (2)
+          WRITE(numout,*) '~~~~~~~~~~~~~~~     iabsf = ', iabsf(1), iabsf(2)
+          WRITE(numout,*) '                    ihals = ', ihals(1), ihals(2)
+          WRITE(numout,*) '                    ihale = ', ihale(1), ihale(2)
+      ENDIF
+
+      CALL flio_dom_set ( jpnij, nproc, idid, iglo, iloc, iabsf, iabsl, ihals, ihale, 'BOX', nidom)
+
+   END SUBROUTINE mpp_init_ioipsl  
+
+# endif
+#endif
+
+   !!======================================================================
+END MODULE mppini
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini_2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini_2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/mppini_2.h90	(revision 4536)
@@ -0,0 +1,566 @@
+   SUBROUTINE mpp_init2
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init2  ***
+      !!
+      !! * Purpose :   Lay out the global domain over processors.
+      !!     FOR USING THIS VERSION, A PREPROCESSING TRAITMENT IS RECOMMENDED
+      !!     FOR DEFINING BETTER CUTTING OUT.
+      !!       This routine is used with a the bathymetry file.
+      !!       In this version, the land processors are avoided and the adress
+      !!     processor (nproc, narea,noea, ...) are calculated again.
+      !!     The jpnij parameter can be lesser than jpni x jpnj
+      !!     and this jpnij parameter must be calculated before with an
+      !!     algoritmic preprocessing program.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!      Periodic condition is a function of the local domain position
+      !!      (global boundary or neighbouring domain) and of the global
+      !!      periodic
+      !!      Type :         jperio global periodic condition
+      !!                     nperio local  periodic condition
+      !!
+      !! ** Action :        nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlci      : first dimension
+      !!                    nlcj      : second dimension
+      !!                    nproc     : number for local processor
+      !!                    noea      : number for local neighboring processor
+      !!                    nowe      : number for local neighboring processor
+      !!                    noso      : number for local neighboring processor
+      !!                    nono      : number for local neighboring processor
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   9.0  !  04-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+   
+      !! Local variables
+      INTEGER :: ji, jj, jn, jproc, jarea     ! dummy loop indices
+      INTEGER ::  inum                        ! temporary logical unit
+      INTEGER ::   &
+         ii, ij, ifreq, il1, il2,          &  ! temporary integers
+         icont, ili, ilj,                  &  !    "          "
+         isurf, ijm1, imil,                &  !    "          "
+         iino, ijno, iiso, ijso,           &  !    "          " 
+         iiea, ijea, iiwe, ijwe,           &  !    "          "
+         iinw, ijnw, iine, ijne,           &  !    "          "
+         iisw, ijsw, iise, ijse,           &  !    "          "
+         iresti, irestj, iproc                !    "          "
+      INTEGER, DIMENSION(jpnij) ::   &
+         iin, ijn          
+      INTEGER, DIMENSION(jpni,jpnj) ::   &
+         iimppt, ijmppt, ilci  , ilcj  ,   &  ! temporary workspace
+         ipproc, ibondj, ibondi, ipolj ,   &  !    "           "
+         ilei  , ilej  , ildi  , ildj  ,   &  !    "           "
+         ioea  , iowe  , ioso  , iono  ,   &  !    "           "
+         ione  , ionw  , iose  , iosw  ,   &  !    "           "
+         ibne  , ibnw  , ibse  , ibsw         !    "           "
+      INTEGER, DIMENSION(jpi,jpj) ::   &
+         imask                                ! temporary global workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zdta                   ! temporary data workspace
+      REAL(wp) ::   zidom , zjdom          ! temporary scalars
+
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+#if defined key_mpp_shmem
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'mpp_init : Message Passing PVM T3E + SHMEM'
+      IF(lwp)WRITE(numout,*) '~~~~~~~~'
+      IF(lwp)WRITE(numout,*) ' '
+
+      CALL mppshmem     ! Initialisation of shmem array
+
+#endif
+#if defined key_mpp_mpi
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'mpp_init : Message Passing MPI'
+      IF(lwp)WRITE(numout,*) '~~~~~~~~'
+      IF(lwp)WRITE(numout,*) ' '
+#endif
+
+      IF( jpni*jpnj < jpnij ) CALL ctl_stop( ' jpnij > jpni x jpnj impossible' )
+
+      ! 0. initialisation
+      ! -----------------
+
+      ! open the file
+      IF ( ln_zps ) THEN
+         CALL iom_open ( 'bathy_meter.nc', inum )   ! Meter bathy in case of partial steps
+         CALL iom_get ( inum, jpdom_data, 'Bathymetry' , zdta )
+      ELSE 
+         CALL iom_open ( 'bathy_level.nc', inum )   ! Level bathymetry
+         CALL iom_get ( inum, jpdom_data, 'Bathy_level', zdta )
+      ENDIF
+      CALL iom_close (inum)
+
+      ! land/sea mask over the global/zoom domain
+
+      imask(:,:)=1
+      WHERE ( zdta(:,:) <= 0. ) imask = 0
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+
+      !  Computation of local domain sizes ilci() ilcj()
+      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array.
+
+      nreci=2*jpreci
+      nrecj=2*jprecj
+      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
+      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
+
+      ilci(1:iresti      ,:) = jpi
+      ilci(iresti+1:jpni ,:) = jpi-1
+
+      ilcj(:,      1:irestj) = jpj
+      ilcj(:, irestj+1:jpnj) = jpj-1
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~  ----------------------'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'iresti=',iresti,' irestj=',irestj
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'jpni=',jpni,' jpnj=',jpnj
+
+      zidom = nreci + sum(ilci(:,1) - nreci ) 
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilci(i,1)=',zidom,' jpiglo=',jpiglo
+
+      zjdom = nrecj + sum(ilcj(1,:) - nrecj ) 
+      IF(lwp) WRITE(numout,*) ' sum ilcj(1,j)=',zjdom,' jpjglo=',jpjglo
+      IF(lwp) WRITE(numout,*)
+
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+
+      iimppt(:,:) = 1
+      ijmppt(:,:) = 1
+      ipproc(:,:) = -1
+
+      IF( jpni > 1 )THEN
+         DO jj = 1, jpnj
+            DO ji = 2, jpni
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
+            END DO
+         END DO
+      ENDIF
+
+      IF( jpnj > 1 )THEN
+         DO jj = 2, jpnj
+            DO ji = 1, jpni
+               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
+            END DO
+         END DO
+      ENDIF
+
+
+      ! 3. Subdomain description in the Regular Case
+      ! --------------------------------------------
+
+      nperio = 0
+      icont = -1
+      DO jarea = 1, jpni*jpnj
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         ili = ilci(ii,ij)
+         ilj = ilcj(ii,ij)
+
+         ibondj(ii,ij) = -1
+         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
+         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
+         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
+
+         ibondi(ii,ij) = 0
+         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
+         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
+         IF( jpni            == 1 )   ibondi(ii,ij) =  2
+
+         ! 2.4 Subdomain neighbors
+
+         iproc = jarea - 1
+         ioso(ii,ij) = iproc - jpni
+         iowe(ii,ij) = iproc - 1
+         ioea(ii,ij) = iproc + 1
+         iono(ii,ij) = iproc + jpni
+         ildi(ii,ij) = 1 + jpreci
+         ilei(ii,ij) = ili -jpreci
+         ionw(ii,ij) = iono(ii,ij) - 1
+         ione(ii,ij) = iono(ii,ij) + 1
+         iosw(ii,ij) = ioso(ii,ij) - 1
+         iose(ii,ij) = ioso(ii,ij) + 1
+         ibsw(ii,ij) = 1
+         ibnw(ii,ij) = 1
+         IF( MOD(iproc,jpni) == 0 ) THEN
+            ibsw(ii,ij) = 0
+            ibnw(ii,ij) = 0
+         ENDIF
+         ibse(ii,ij) = 1
+         ibne(ii,ij) = 1
+         IF( MOD(iproc,jpni) == jpni-1 ) THEN
+            ibse(ii,ij) = 0
+            ibne(ii,ij) = 0
+         ENDIF
+         IF( iproc < jpni ) THEN
+            ibsw(ii,ij) = 0
+            ibse(ii,ij) = 0
+         ENDIF
+         IF( iproc >= (jpnj-1)*jpni ) THEN
+            ibnw(ii,ij) = 0
+            ibne(ii,ij) = 0
+         ENDIF
+         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) = 1
+         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
+         ildj(ii,ij) =  1  + jprecj
+         ilej(ii,ij) = ilj - jprecj
+         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) = 1
+         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
+
+         ! warning ii*ij (zone) /= nproc (processors)!
+
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+            IF( jpni == 1 )THEN
+               ibondi(ii,ij) = 2
+               nperio = 1
+            ELSE
+               ibondi(ii,ij) = 0
+            ENDIF
+            IF( MOD(jarea,jpni) == 0 ) THEN
+               ioea(ii,ij) = iproc - (jpni-1)
+               ione(ii,ij) = ione(ii,ij) - jpni
+               iose(ii,ij) = iose(ii,ij) - jpni
+            ENDIF
+            IF( MOD(jarea,jpni) == 1 ) THEN
+               iowe(ii,ij) = iproc + jpni - 1
+               ionw(ii,ij) = ionw(ii,ij) + jpni
+               iosw(ii,ij) = iosw(ii,ij) + jpni 
+            ENDIF
+            ibsw(ii,ij) = 1
+            ibnw(ii,ij) = 1
+            ibse(ii,ij) = 1
+            ibne(ii,ij) = 1
+            IF( iproc < jpni ) THEN
+               ibsw(ii,ij) = 0
+               ibse(ii,ij) = 0
+            ENDIF
+            IF( iproc >= (jpnj-1)*jpni ) THEN
+               ibnw(ii,ij) = 0
+               ibne(ii,ij) = 0
+            ENDIF
+         ENDIF
+         ipolj(ii,ij) = 0
+         IF( jperio == 3 .OR. jperio == 4 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
+            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1
+         ENDIF
+         IF( jperio == 5 .OR. jperio == 6 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1) ipolj(ii,ij) = 5
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
+            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1
+         ENDIF
+
+         isurf = 0
+         DO jj = 1+jprecj, ilj-jprecj
+            DO  ji = 1+jpreci, ili-jpreci
+               IF( imask(ji, jj) == 1) isurf = isurf+1
+            END DO
+         END DO
+         IF(isurf /= 0) THEN
+            icont = icont + 1
+            ipproc(ii,ij) = icont
+            iin(icont+1) = ii
+            ijn(icont+1) = ij
+         ENDIF
+      END DO
+
+      ! Control
+      IF(icont+1 /= jpnij) THEN
+         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
+         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
+         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
+         CALL ctl_stop( ' Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
+      ENDIF
+
+      ! 4. Subdomain print
+      ! ------------------
+
+      IF(lwp) THEN
+         ifreq = 4
+         il1 = 1
+         DO jn = 1,(jpni-1)/ifreq+1
+            il2 = MIN(jpni,il1+ifreq-1)
+            WRITE(numout,*)
+            WRITE(numout,9401) (ji,ji=il1,il2)
+            WRITE(numout,9400) ('***',ji=il1,il2-1)
+            DO jj = 1, jpnj
+               ! WRITE(numout,9400)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
+               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9400) ('***',ji=il1,il2-1)
+               ! WRITE(numout,9400)
+            END DO
+            il1 = il1+ifreq
+         END DO
+ 9400     FORMAT('     ***',20('*************',a3))
+ 9403     FORMAT('     *     ',20('         *   ',a3))
+ 9401     FORMAT('        ',20('   ',i3,'          '))
+ 9402     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+ 9404     FORMAT('     *  ',20('      ',i3,'   *   '))
+      ENDIF
+
+
+      ! 5. neighbour treatment
+      ! ----------------------
+
+      DO jarea = 1, jpni*jpnj
+         iproc = jarea-1
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         IF( ipproc(ii,ij) == -1 .AND. iono(ii,ij) >= 0   &
+            .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
+            iino = 1 + MOD(iono(ii,ij),jpni)
+            ijno = 1 +    (iono(ii,ij))/jpni
+            IF( ibondj(iino,ijno) == 1 ) ibondj(iino,ijno)=2
+            IF( ibondj(iino,ijno) == 0 ) ibondj(iino,ijno) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ioso(ii,ij) >= 0   &
+            .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiso = 1 + MOD(ioso(ii,ij),jpni)
+            ijso = 1 +    (ioso(ii,ij))/jpni
+            IF( ibondj(iiso,ijso) == -1 ) ibondj(iiso,ijso) = 2
+            IF( ibondj(iiso,ijso) ==  0 ) ibondj(iiso,ijso) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ioea(ii,ij) >= 0   &
+            .AND. ioea(ii,ij) <= jpni*jpnj-1) THEN
+            iiea = 1 + MOD(ioea(ii,ij),jpni)
+            ijea = 1 +    (ioea(ii,ij))/jpni
+            IF( ibondi(iiea,ijea) == 1 ) ibondi(iiea,ijea) = 2
+            IF( ibondi(iiea,ijea) == 0 ) ibondi(iiea,ijea) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. iowe(ii,ij) >= 0   &
+            .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
+            iiwe = 1 + MOD(iowe(ii,ij),jpni)
+            ijwe = 1 +    (iowe(ii,ij))/jpni
+            IF( ibondi(iiwe,ijwe) == -1 ) ibondi(iiwe,ijwe) = 2
+            IF( ibondi(iiwe,ijwe) ==  0 ) ibondi(iiwe,ijwe) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibne(ii,ij) == 1 ) THEN
+            iine = 1 + MOD(ione(ii,ij),jpni)
+            ijne = 1 +    (ione(ii,ij))/jpni
+            IF( ibsw(iine,ijne) == 1 ) ibsw(iine,ijne) = 0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibsw(ii,ij) == 1 ) THEN
+            iisw = 1 + MOD(iosw(ii,ij),jpni)
+            ijsw = 1 +    (iosw(ii,ij))/jpni
+            IF( ibne(iisw,ijsw) == 1 ) ibne(iisw,ijsw) = 0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibnw(ii,ij) == 1 ) THEN
+            iinw = 1 + MOD(ionw(ii,ij),jpni)
+            ijnw = 1 +    (ionw(ii,ij))/jpni
+            IF( ibse(iinw,ijnw) == 1 ) ibse(iinw,ijnw)=0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibse(ii,ij) == 1 ) THEN
+            iise = 1 + MOD(iose(ii,ij),jpni)
+            ijse = 1 +    (iose(ii,ij))/jpni
+            IF( ibnw(iise,ijse) == 1 ) ibnw(iise,ijse) = 0
+         ENDIF
+      END DO
+
+
+      ! 6. Change processor name
+      ! ------------------------
+
+      nproc = narea-1
+      ii = iin(narea)
+      ij = ijn(narea)
+      IF( ioso(ii,ij) >= 0 .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiso = 1 + MOD(ioso(ii,ij),jpni)
+         ijso = 1 +    (ioso(ii,ij))/jpni
+         noso = ipproc(iiso,ijso)
+      ENDIF
+      IF( iowe(ii,ij) >= 0 .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiwe = 1 + MOD(iowe(ii,ij),jpni)
+         ijwe = 1 +    (iowe(ii,ij))/jpni
+         nowe = ipproc(iiwe,ijwe)
+      ENDIF
+      IF( ioea(ii,ij) >= 0 .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiea = 1 + MOD(ioea(ii,ij),jpni)
+         ijea = 1 +    (ioea(ii,ij))/jpni
+         noea = ipproc(iiea,ijea)
+      ENDIF
+      IF( iono(ii,ij) >= 0 .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iino = 1 + MOD(iono(ii,ij),jpni)
+         ijno = 1 +    (iono(ii,ij))/jpni
+         nono = ipproc(iino,ijno)
+      ENDIF
+      IF( iose(ii,ij) >= 0 .AND. iose(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iise = 1 + MOD(iose(ii,ij),jpni)
+         ijse = 1 +    (iose(ii,ij))/jpni
+         npse = ipproc(iise,ijse)
+      ENDIF
+      IF( iosw(ii,ij) >= 0 .AND. iosw(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iisw = 1 + MOD(iosw(ii,ij),jpni)
+         ijsw = 1 +    (iosw(ii,ij))/jpni
+         npsw = ipproc(iisw,ijsw)
+      ENDIF
+      IF( ione(ii,ij) >= 0 .AND. ione(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iine = 1 + MOD(ione(ii,ij),jpni)
+         ijne = 1 +    (ione(ii,ij))/jpni
+         npne = ipproc(iine,ijne)
+      ENDIF
+      IF( ionw(ii,ij) >= 0 .AND. ionw(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iinw = 1 + MOD(ionw(ii,ij),jpni)
+         ijnw = 1 +    (ionw(ii,ij))/jpni
+         npnw = ipproc(iinw,ijnw)
+      ENDIF
+      nbnw = ibnw(ii,ij)
+      nbne = ibne(ii,ij)
+      nbsw = ibsw(ii,ij)
+      nbse = ibse(ii,ij)
+      nlcj = ilcj(ii,ij)  
+      nlci = ilci(ii,ij)  
+      nldi = ildi(ii,ij)
+      nlei = ilei(ii,ij)
+      nldj = ildj(ii,ij)
+      nlej = ilej(ii,ij)
+      nbondi = ibondi(ii,ij)
+      nbondj = ibondj(ii,ij)
+      nimpp = iimppt(ii,ij)  
+      njmpp = ijmppt(ii,ij)  
+      DO jproc = 1, jpnij
+         ii = iin(jproc)
+         ij = ijn(jproc)
+         nimppt(jproc) = iimppt(ii,ij)  
+         njmppt(jproc) = ijmppt(ii,ij)  
+         nlcjt(jproc) = ilcj(ii,ij)
+         nlcit(jproc) = ilci(ii,ij)
+         nldit(jproc) = ildi(ii,ij)
+         nleit(jproc) = ilei(ii,ij)
+         nldjt(jproc) = ildj(ii,ij)
+         nlejt(jproc) = ilej(ii,ij)
+      END DO
+
+      ! Save processor layout in ascii file
+      IF (lwp) THEN
+         CALL ctlopn( inum, 'layout.dat', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .FALSE., 1 )
+         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
+         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
+
+        DO  jproc = 1, jpnij
+         WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
+                                      nldit(jproc), nldjt(jproc), &
+                                      nleit(jproc), nlejt(jproc), &
+                                      nimppt(jproc), njmppt(jproc)
+        END DO
+        CLOSE(inum)   
+      END IF
+
+
+      ! FETI method
+
+      IF( nperio == 1 .AND. nsolv == 3 ) THEN 
+
+         ! general CASE : Earth == infinite tube
+
+         nbnw = 1
+         npnw = narea
+         nbne = 1
+         npne = narea
+         nbsw = 1
+         npsw = (narea-2)
+         nbse = 1
+         npse = (narea-2)
+
+         ! REAL boundary condition
+
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+
+         IF( nbondj ==  1 .OR. nbondj == 2 ) THEN 
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+
+      IF( nperio == 1 .AND.jpni /= 1 ) CALL ctl_stop( ' mpp_init2:  error on cyclicity' )
+
+      ! Prepare mpp north fold
+
+      IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
+         CALL mpp_ini_north
+         IF(lwp) WRITE(numout,*) ' mpp_init2 : North fold boundary prepared for jpni >1'
+      ENDIF
+
+      ! Defined npolj, either 0, 3 , 4 , 5 , 6
+      ! In this case the important thing is that npolj /= 0
+      ! Because if we go through these line it is because jpni >1 and thus
+      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
+
+      npolj = 0
+      ij = ijn(narea)
+
+      IF( jperio == 3 .OR. jperio == 4 ) THEN
+         IF( ij == jpnj ) npolj = 3
+      ENDIF
+
+      IF( jperio == 5 .OR. jperio == 6 ) THEN
+         IF( ij == jpnj ) npolj = 5
+      ENDIF
+
+      ! Prepare NetCDF output file (if necessary)
+      CALL mpp_init_ioipsl
+
+      ! Periodicity : no corner if nbondi = 2 and nperio != 1
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' nproc=  ',nproc
+         WRITE(numout,*) ' nowe=   ',nowe
+         WRITE(numout,*) ' noea=   ',noea
+         WRITE(numout,*) ' nono=   ',nono
+         WRITE(numout,*) ' noso=   ',noso
+         WRITE(numout,*) ' nbondi= ',nbondi
+         WRITE(numout,*) ' nbondj= ',nbondj
+         WRITE(numout,*) ' npolj=  ',npolj
+         WRITE(numout,*) ' nperio= ',nperio
+         WRITE(numout,*) ' nlci=   ',nlci
+         WRITE(numout,*) ' nlcj=   ',nlcj
+         WRITE(numout,*) ' nimpp=  ',nimpp
+         WRITE(numout,*) ' njmpp=  ',njmpp
+         WRITE(numout,*) ' nbse=   ',nbse,' npse= ',npse
+         WRITE(numout,*) ' nbsw=   ',nbsw,' npsw= ',npsw
+         WRITE(numout,*) ' nbne=   ',nbne,' npne= ',npne
+         WRITE(numout,*) ' nbnw=   ',nbnw,' npnw= ',npnw
+      ENDIF
+
+   END SUBROUTINE mpp_init2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/oce.F90	(revision 4536)
@@ -0,0 +1,42 @@
+MODULE oce
+   !!======================================================================
+   !!                      ***  MODULE  oce  ***
+   !! Ocean        :  dynamics and active tracers defined in memory 
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! dynamics and tracer fields
+   !! --------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      ! before !  now      !  after  !      ! the after trends becomes the fields
+      ! fields !  fields   !  trends !      ! only in dyn(tra)_zdf and dyn(tra)_nxt
+                  un       ,  ua     ,   &  !: i-horizontal velocity (m/s)
+                  vn       ,  va     ,   &  !: j-horizontal velocity (m/s)
+                  wn       ,             &  !: vertical velocity (m/s)
+                  hdivn    ,             &  !: horizontal divergence (1/s)
+                  tn       ,  ta     ,   &  !: potential temperature (celcius)
+                  sn       ,  sa            !: salinity (psu)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      rhd ,                              &  !: in situ density anomalie rhd=(rho-rau0)/rau0 (no units)
+      rhop,                              &  !: potential volumic mass (kg/m3)
+      rn2                                   !: brunt-vaisala frequency (1/s2)
+
+   !! interpolated gradient
+   !! ---------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      gtu, gsu, gru,      &  !: t-, s- and rd horizontal gradient at u- and 
+      gtv, gsv, grv          !: v-points at bottom ocean level 
+
+   !!----------------------------------------------------------------------
+END MODULE oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ocfzpt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ocfzpt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/ocfzpt.F90	(revision 4536)
@@ -0,0 +1,72 @@
+MODULE ocfzpt
+   !!======================================================================
+   !!                       ***  MODULE  ocfzpt  ***
+   !! Ocean active tracers:  freezing point computation and freezing area
+   !!======================================================================
+   
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC oc_fz_pt        ! called by opa.F90 and step.F90
+
+   !! * Shared module variables   
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      freeze, freezn,  &  !: after and now ice mask (0 or 1)
+      fzptb, fzptn        !: before and now freezing point
+   !!----------------------------------------------------------------------
+   !! OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE oc_fz_pt
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE oc_fz_pt  ***
+      !!
+      !! ** Purpose : - Calculate ocean surface freezing temperature
+      !!              - Calculate related boolean for now ice distribution 
+      !!
+      !! ** Method  :   Caution, freezing point only for jackett & McDougall eos
+      !!
+      !! ** Action  : - fzptn  : now freezing temperature at ocean surface
+      !!              - fzptb  : before freezing temperature at ocean surface
+      !!              - freezn : boolean indicating freezing conditions at the 
+      !!                ocean surface at time step "now"
+      !!
+      !! History :
+      !!        !  94-08  (M.-A. Filiberti)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------      
+
+!CDIR NOVERRCHK
+      DO jj = 1, jpj
+!CDIR NOVERRCHK
+         DO ji = 1, jpi
+            fzptb(ji,jj) = fzptn(ji,jj)        ! swap freezing point array
+
+            !                                  ! ocean local surface freezing temperature
+            !                                  ! sn >= 0 : this is verified in stpctl at each time step
+            fzptn (ji,jj) = ( -0.0575 + 1.710523e-3 * SQRT( sn(ji,jj,1) )   &
+                                      - 2.154996e-4 *       sn(ji,jj,1)   ) * sn(ji,jj,1)   !!   &
+            !!                        - 7.53e-4 * pressure
+
+            !                                  ! Define boolean related to freezing conditions
+            freezn(ji,jj) = tmask(ji,jj,1) * MAX( 0., SIGN( 1., fzptn(ji,jj) - tn(ji,jj,1) )  )
+         END DO
+      END DO
+
+   END SUBROUTINE oc_fz_pt
+
+   !!======================================================================
+END MODULE ocfzpt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/opa.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/opa.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/opa.F90	(revision 4536)
@@ -0,0 +1,210 @@
+MODULE opa
+   !!==============================================================================
+   !!                       ***  MODULE opa   ***
+   !! Ocean system   : OPA ocean dynamics (including on-line tracers and sea-ice)
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   opa_model      : solve ocean dynamics, tracer and/or sea-ice
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space domain variables
+   USE oce             ! dynamics and tracers variables
+   USE daymod          ! calendar
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+   USE istate          ! initial state setting          (istate_init routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+
+   ! ocean physics
+   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini
+   USE traqsr          ! solar radiation penetration   (tra_qsr_init routine)
+
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
+   USE initrc          ! Initilization of the passive tracers
+   USE step            ! OPA time-stepping                  (stp     routine)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC opa_model      ! called by model.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+   !!   $Header$
+   !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE opa_model
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   opa solves the primitive equations on an orthogonal 
+      !!      curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!
+      !! References :
+      !!      Madec, Delecluse,Imbard, and Levy, 1997: reference manual.
+      !!              internal report, IPSL.
+      !!
+      !! History :
+      !!   4.0  !  90-10  (C. Levy, G. Madec)  Original code
+      !!   7.0  !  91-11  (M. Imbard, C. Levy, G. Madec)
+      !!   7.1  !  93-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 
+      !!        !  92-06  (L.Terray) coupling implementation
+      !!        !  93-11  (M.A. Filiberti) IGLOO sea-ice 
+      !!   8.0  !  96-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  !  97-06  (M. Imbard, G. Madec)
+      !!   8.2  !  99-11  (M. Imbard, H. Goosse)  LIM sea-ice model 
+      !!        !  99-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP 
+      !!        !  00-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
+      !!   9.0  !  02-08  (G. Madec)  F90: Free form and modules
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   istp       ! time step index
+      CHARACTER (len=20) ::   namelistname
+      CHARACTER (len=28) ::   file_out
+      CHARACTER (len=64) ::        &
+         cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+      !!----------------------------------------------------------------------
+
+      ! Initializations
+      ! ===============
+
+      file_out = 'ocean.output'
+
+      ! open listing and namelist units
+      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+         &         'SEQUENTIAL', 1, 6, .FALSE., 1 )
+
+      namelistname = 'namelist'
+      CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &         1, numout, .FALSE., 1 )
+
+      WRITE(numout,*)
+      WRITE(numout,*) '                 L O D Y C - I P S L'
+      WRITE(numout,*) '                     O P A model'
+      WRITE(numout,*) '            Ocean General Circulation Model'
+      WRITE(numout,*) '               version OPA 9.0  (2005) '
+      WRITE(numout,*)
+      WRITE(numout,*)
+
+      ! Nodes selection
+      narea = mynode()
+      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      IF( lk_mpp )   THEN
+         CLOSE( numout )       ! standard model output file
+         WRITE(file_out,FMT="('ocean.output_',I4.4)") narea-1
+         CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+            &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '                 L O D Y C - I P S L'
+         WRITE(numout,*) '                     O P A model'
+         WRITE(numout,*) '            Ocean General Circulation Model'
+         WRITE(numout,*) '               version OPA 9.0  (2005) '
+         WRITE(numout,*) '                   MPI Ocean output '
+         WRITE(numout,*)
+         WRITE(numout,*)
+      ENDIF
+
+
+      !                                     ! ============================== !
+      !                                     !  Model general initialization  !
+      !                                     ! ============================== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+                                            ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                          ! standard cutting out
+      ELSE
+         CALL mpp_init2                         ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+
+      CALL day( nit000 )                    ! Calendar
+
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+!!add
+                       CALL eos( tn, sn, rhd, rhop )        ! before potential and in situ densities
+
+                       CALL bn2( tn, sn, rn2 )              ! before Brunt-Vaisala frequency
+
+      IF( ln_zps    )   CALL zps_hde( nit000, tn, sn, rhd,  &  ! Partial steps: before Horizontal DErivative
+                                          gtu, gsu, gru, &  ! of t, s, rd at the bottom ocean level
+                                          gtv, gsv, grv )
+
+!!add
+
+      ! Initialization for the dynamics
+      !
+      CALL dta_dyn(nit000)     
+
+#if defined key_passivetrc
+      CALL ini_trc                           ! Passive tracers
+#endif
+
+      !                                     ! Ocean physics
+      CALL tra_qsr_init                         ! Solar radiation penetration
+
+#if ! defined key_off_degrad
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+#endif 
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      !                                     ! Ocean trends
+
+      !                                     ! =============== !
+      !                                     !  time stepping  !
+      !                                     ! =============== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      istp = nit000
+      DO WHILE ( istp <= nitend .AND. nstop == 0 )
+         CALL stp( istp )
+         istp = istp + 1
+      END DO
+      !                                     ! ========= !
+      !                                     !  Job end  !
+      !                                     ! ========= !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( nstop /= 0 ) THEN                 ! error print
+      IF(lwp) WRITE(numout,cform_err)
+      IF(lwp) WRITE(numout,*) nstop, ' error have been found' 
+      ENDIF
+
+      IF( lk_mpp )   CALL mppstop                          ! Close all files (mpp)
+
+   END SUBROUTINE opa_model
+
+   !!======================================================================
+END MODULE opa
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R2.h90	(revision 4536)
@@ -0,0 +1,87 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_EEL_R2.h90  ***
+   !!   Ocean Domain : 2 km resolution Channel (EEL_R2 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &  !:
+      cp_cfg = "eel"            !: name of the configuration
+   INTEGER, PARAMETER ::     &  !:
+      jp_cfg = 2   ,         &  !: resolution of the configuration (km)
+
+      ! data size              !!! * size of all the input files *
+      jpidta  = 83,          &  !: 1st horizontal dimension ( >= jpi )
+      jpjdta  = 242,         &  !: 2nd    "            "    ( >= jpj )
+      jpkdta  = 30,          &  !: number of levels         ( >= jpk )
+
+      ! global domain size     !!! * full domain *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data indices
+
+      ! Domain characteristics
+      jperio  =     1 ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =     1 ,      &  !: number of islands
+      jpnisl  = jpiglo          !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &  !:
+      pp_not_used       = 999999._wp  , & !: ???
+      pp_to_be_computed =      0._wp      !: ???
+   !!
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   !!
+   INTEGER,PARAMETER   ::    & !:
+      jphgr_msh = 3            !: type of horizontal mesh
+      !                        ! = 0 curvilinear coordinate on the sphere
+      !                        !     read in coordinate.nc file
+      !                        ! = 1 geographical mesh on the sphere
+      !                        !     with regular grid-spacing
+      !                        ! = 2 f-plane with regular grid-spacing
+      !                        ! = 3 beta-plane with regular grid-spacing
+      !                        ! = 4 Mercator grid with T/U point at the equator  with
+      !                        !     isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::     &  !:
+      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used ,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used ,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = 2000.0_wp,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = 2000.0_wp       !: meridional grid-spacing (meters )
+   !!
+   !!  Coefficients associated with the vertical coordinate system
+   !!
+
+   REAL(wp), PARAMETER  ::       &  !:
+      &     ppsur = -2033.194295283385_wp   ,  &  !: Computed in domzgr
+      &     ppa0  =  155.8325369664153_wp   ,  &  !:
+      &     ppa1  =  146.3615918601890_wp   ,  &  !:
+      !
+      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+   !!
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R5.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R5.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R5.h90	(revision 4536)
@@ -0,0 +1,86 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_EEL_R5.h90  ***   
+   !!   Ocean Domain : 5 km resolution Channel (EEL_R5 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &  !:
+      cp_cfg = "eel"            !: name of the configuration
+   INTEGER, PARAMETER ::     &  !:
+      jp_cfg = 5      ,      &  !: resolution of the configuration (km)
+
+      ! data size              !!! * size of all the input files
+      jpidta  = 202   ,      &  !: first horizontal dimension > or = to jpi
+      jpjdta  = 104   ,      &  !: second                     > or = to jpj
+      jpkdta  =  40   ,      &  !: number of levels           > or = to jpk
+
+      ! total domain size      !!! * full domain *
+      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data indices
+
+      ! Domain characteristics
+      jperio  =   0   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   1   ,      &  !: number of islands
+      jpnisl  = jpiglo          !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &  !:
+      pp_not_used       = 999999._wp ,  &  !:
+      pp_to_be_computed =      0._wp       !:
+
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+
+   INTEGER,PARAMETER   ::    & !:
+      jphgr_msh = 2            !: type of horizontal mesh
+      !                        ! = 0 curvilinear coordinate on the sphere
+      !                        !     read in coordinate.nc file
+      !                        ! = 1 geographical mesh on the sphere
+      !                        !     with regular grid-spacing
+      !                        ! = 2 f-plane with regular grid-spacing
+      !                        ! = 3 beta-plane with regular grid-spacing
+      !                        ! = 4 Mercator grid with T/U point at the equator  with
+      !                        !     isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::     &  !:
+      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = 5000.0_wp,   &  !: zonal      grid-spacing (meters)
+      ppe2_m   = 5000.0_wp       !: meridional grid-spacing (meters)
+   !!
+   !!  Coefficients associated with the vertical coordinate system
+   !!
+   REAL(wp), PARAMETER  ::       &   !:
+      &     ppsur = pp_to_be_computed       ,  &  !: Computed in domzgr, set ppdzmin, pphmax below
+      &     ppa0  = pp_to_be_computed       ,  &  !:
+      &     ppa1  = pp_to_be_computed       ,  &  !:
+      !
+      &     ppkth = 20._wp                  ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr = 16.00000000000_wp             !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+   !!
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &  !:
+      &     ppdzmin = 120._wp               ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = 4000._wp                    !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R6.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R6.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_EEL_R6.h90	(revision 4536)
@@ -0,0 +1,86 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_EEL_R6.h90  ***   
+   !!   Ocean Domain : 6 km resolution Channel (EEL_R6 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &  !:
+      cp_cfg = "eel"            !: name of the configuration
+   INTEGER, PARAMETER ::     &  !:
+      jp_cfg = 6      ,      &  !: resolution of the configuration (km)
+
+      ! data size              !!! * size of all the input files *
+      jpidta  = 29,          &  !: 1st lateral dimension ( >= jpi )
+      jpjdta  = 83,          &  !: 2nd    "         "    ( >= jpj )
+      jpkdta  = 30,          &  !: number of levels      ( >= jpk )
+
+      ! global domain size     !!! * full domain *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data domain indices
+
+      ! Domain characteristics
+      jperio  =      1,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =      1,      &  !: number of islands
+      jpnisl  = jpiglo          !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &  !:
+      pp_not_used       = 999999._wp ,  &  !: ???
+      pp_to_be_computed =      0._wp       !: ???
+
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+
+   INTEGER,PARAMETER   ::    & !:
+      jphgr_msh = 3            !: type of horizontal mesh
+      !                        ! = 0 curvilinear coordinate on the sphere
+      !                        !     read in coordinate.nc file
+      !                        ! = 1 geographical mesh on the sphere
+      !                        !     with regular grid-spacing
+      !                        ! = 2 f-plane with regular grid-spacing
+      !                        ! = 3 beta-plane with regular grid-spacing
+      !                        ! = 4 Mercator grid with T/U point at the equator  with
+      !                        !     isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::     &  !:
+      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                          !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = 6000.0_wp,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = 6000.0_wp       !: meridional grid-spacing (meters )
+
+   !!  Coefficients associated with the vertical coordinate system
+
+   REAL(wp), PARAMETER  ::       &  !:
+      &     ppsur = -2033.194295283385_wp   ,  &  !: Computed in domzgr
+      &     ppa0  =  155.8325369664153_wp   ,  &  !:
+      &     ppa1  =  146.3615918601890_wp   ,  &  !:
+      !
+      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &  !:
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_GYRE.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_GYRE.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_GYRE.h90	(revision 4536)
@@ -0,0 +1,91 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_GYRE.h90  ***
+   !!   Ocean Domain : GYRE configuration at 1/jp_cfg degree resolution 
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &  !:
+      cp_cfg = "gyre"           !: name of the configuration
+   INTEGER, PARAMETER ::     &  !:
+      jp_cfg =  1   ,        &  !: 
+
+      ! data size              !!! * size of all the input files *
+      jpidta  = 30*jp_cfg+2, &  !: 1st horizontal dimension ( >= jpi )
+      jpjdta  = 20*jp_cfg+2, &  !: 2nd    "            "    ( >= jpj )
+      jpkdta  = 101,         &  !: number of levels         ( >= jpk )
+
+      ! global domain size     !!! * full domain *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data indices
+
+      ! Domain characteristics
+      jperio  =     0 ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =     1 ,      &  !: number of islands
+      jpnisl  = jpiglo          !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &  !:
+      pp_not_used       = 999999._wp  , & !: ???
+      pp_to_be_computed =      0._wp      !: ???
+   !!
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   !!
+   INTEGER,PARAMETER   ::    & !:
+      jphgr_msh = 5            !: type of horizontal mesh
+      !                        ! = 0 curvilinear coordinate on the sphere
+      !                        !     read in coordinate.nc file
+      !                        ! = 1 geographical mesh on the sphere
+      !                        !     with regular grid-spacing
+      !                        ! = 2 f-plane with regular grid-spacing
+      !                        ! = 3 beta-plane with regular grid-spacing
+      !                        ! = 4 Mercator grid with T/U point at the equator  with
+      !                        !     isotropic resolution (e1_deg)
+      !                        ! =5  beta-plane with regular grid-spacing and rotated domain (GYRE configuration)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::     &  !:
+      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  =   29.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                          ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used ,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used ,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = pp_not_used,    &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used        !: meridional grid-spacing (meters )
+   !!
+   !!  Coefficients associated with the vertical coordinate system
+   !!
+
+   REAL(wp), PARAMETER  ::       &  !:
+      &     ppsur = 0.e0      ,  &  !: Computed in domzgr
+      &     ppa0  = 0.e0      ,  &  !:
+      &     ppa1  = 0.e0      ,  &  !:
+      !
+      &     ppkth =  17.28520372419791_wp   ,  &  !: (non dimensional): gives the approximate
+      !                                           !    layer number above which  stretching will
+      !                                           !    be maximum. Usually of order jpk/2.
+      &     ppacr =  5.000000000000000_wp         !: (non dimensional): stretching factor
+      !                                           !    for the grid. The highest zacr, the smallest
+      !                                           !    the stretching.
+
+   !!
+   !!  If all ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &  !:
+      &     ppdzmin = 1.0e0   ,  &  !: (meters): depth of the top (first) model layer
+      !                             !            depth of second "w" level
+      &     pphmax  = 5000.         !: (meters): maximum depth of the ocean
+      !                             !            depth of the last "w" level
+
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R025.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R025.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R025.h90	(revision 4536)
@@ -0,0 +1,83 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_ORCA_R025.h90  ***  
+   !!   Ocean Domain : 0.25 degrees resolution global ocean
+   !!                  (0RCA_R025 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &
+      cp_cfg = "orca"           !: name of the configuration
+   INTEGER, PARAMETER ::     &
+      jp_cfg = 025  ,        &  !: resolution of the configuration (degrees)
+      ! Original data size
+      jpidta  = 1442,        &  !: first horizontal dimension > or = to jpi
+      jpjdta  = 1021,        &  !: second                     > or = to jpj
+      jpkdta  = 46 ,         &  !: number of levels           > or = to jpk
+      ! total domain matrix size
+      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data indices
+      ! Domain characteristics
+      jperio  =    4  ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =  150  ,      &  !: number of islands
+      jpnisl  = 3000            !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL,PARAMETER      ::  pp_not_used = 999999_wp , &
+      &                    pp_to_be_computed = 0._wp
+   !!
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   !!
+   INTEGER, PARAMETER ::     & !
+      jphgr_msh = 0            !: type of horizontal mesh
+      !                        !  = 0 curvilinear coordinate on the sphere
+      !                        !      read in coordinate.nc file
+      !                        !  = 1 geographical mesh on the sphere
+      !                        !      with regular grid-spacing
+      !                        !  = 2 f-plane with regular grid-spacing
+      !                        !  = 3 beta-plane with regular grid-spacing
+      !                        !  = 4 Mercator grid with T/U point at the equator  with
+      !                        !      isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp), PARAMETER ::       &  !
+      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+
+   !!  Coefficients associated with the vertical coordinate system
+
+   REAL(wp), PARAMETER  ::       &
+      &     ppsur = pp_to_be_computed ,  &  !: Computed in domzgr, set ppdzmin and pphmax below
+      &     ppa0  = pp_to_be_computed ,  &  !:    "           "
+      &     ppa1  = pp_to_be_computed ,  &  !:    "           "
+      !
+      &     ppkth =  23.563_wp        ,  &  !: (non dimensional): gives the approximate
+      !                                     !: layer number above which  stretching will
+      !                                     !: be maximum. Usually of order jpk/2.
+      &     ppacr =    9.00000000000_wp     !: (non dimensional): stretching factor
+      !                                     !: for the grid. The highest zacr, the smallest
+      !                                     !: the stretching.
+
+   !!
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &
+      &     ppdzmin = 6._wp           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = 5750._wp              !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R05.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R05.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R05.h90	(revision 4536)
@@ -0,0 +1,115 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_ORCA_R05.h90  ***  
+   !!   Ocean Domain : 0.5 degrees resolution global ocean
+   !!                  (0RCA_R05 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::   &
+      cp_cfg = "orca"           !: name of the configuration
+   INTEGER, PARAMETER ::     &
+      jp_cfg = 05  ,         &  !: resolution of the configuration (degrees)
+
+      ! data size              !!! * size of all the input files *
+      jpidta  = 722,         &  !: 1st lateral dimension > or = to jpiglo
+      jpjdta  = 511,         &  !: 2nd   "         "     > or = to jpjglo
+      jpkdta  =  31,         &  !: number of levels      > or = to jpkglo
+
+#if defined key_antarctic
+      ! zoom domain size       !!! * antarctic zoom *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = 187   ,      &  !: 2nd     "                 "    --> j 
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =   1   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   1   ,      &  !: number of islands
+      jpnisl  =   1             !: maximum number of points per island
+
+#elif defined key_arctic
+      ! zoom domain size       !!! *  arctic zoom  *
+      jpiglo  = 562,         &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta-301+1,&  !: 2nd     "                 "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position
+      jpizoom =  81   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom = 301   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =   5   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   1   ,      &  !: number of islands
+      jpnisl  =   1             !: maximum number of points per island
+
+#else
+      ! global domain size     !!! * full domain *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: 2nd     "                 "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position    
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =    6  ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   79  ,      &  !: number of islands
+      jpnisl  = 2000            !: maximum number of points per island
+#endif
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &
+      pp_not_used       = 999999._wp , &  !:
+      pp_to_be_computed = 0._wp          !:
+
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+
+   INTEGER, PARAMETER   ::   & !
+      jphgr_msh = 0            !: type of horizontal mesh
+      !                        !  = 0 curvilinear coordinate on the sphere
+      !                        !      read in coordinate.nc file
+      !                        !  = 1 geographical mesh on the sphere
+      !                        !      with regular grid-spacing
+      !                        !  = 2 f-plane with regular grid-spacing
+      !                        !  = 3 beta-plane with regular grid-spacing
+      !                        !  = 4 Mercator grid with T/U point at the equator  with
+      !                        !      isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) , PARAMETER ::      &  !
+      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                            ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+
+   !!
+   !! Vertical grid parameter for domzgr
+   !! =====================================
+   !!
+   REAL(wp), PARAMETER  ::       &
+      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+      &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
+      &     ppa1  =   245.58132232490_wp    ,  &  !:
+      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+   !!
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R2.h90	(revision 4536)
@@ -0,0 +1,139 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_ORCA_R2.h90  ***  
+   !!   Ocean Domain : 2 degrees resolution global ocean
+   !!                  (0RCA_R2 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::    &  
+      cp_cfg = "orca"           !: name of the configuration 
+   INTEGER, PARAMETER ::     &
+      jp_cfg = 2,            &  !: resolution of the configuration (degrees)
+
+      ! data size              !!! * size of all input files *
+      jpidta  = 182,         &  !: 1st lateral dimension ( >= jpiglo )
+      jpjdta  = 149,         &  !: 2nd    "       "      ( >= jpjglo )
+      jpkdta  = 31,          &  !: number of levels      ( >= jpk    )
+
+#if defined key_antarctic
+      ! zoom domain size       !!! *  antarctic zoom  * 
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = 50,          &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =   1   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   3   ,      &  !: number of islands
+      jpnisl  = 400             !: maximum number of points per island
+
+#elif defined key_arctic
+      ! zoom domain size       !!! *  arctic zoom  *
+      jpiglo  = 142   ,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta-97+1, &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! zoom starting position 
+      jpizoom =  21   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =  97   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =   3   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =   7   ,      &  !: number of islands
+      jpnisl  = 400             !: maximum number of points per island
+
+#elif defined key_cfg_1d
+      ! global domain size     !!! *  global domain  *
+      jpiglo  = 3     ,      &  !: 1st dimension of global domain --> i
+      jpjglo  = 3     ,      &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom 
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   133  ,    &  !: in data domain indices (160W,75N)
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   110  ,    &  !: in data domain indices (160W,50N)
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   97   ,    &  !: in data domain indices (160W,30N)
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   86   ,    &  !: in data domain indices (160W,10N)
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   49   ,    &  !: in data domain indices (160W,30S)
+      ! jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      ! jpjzoom =   27   ,    &  !: in data domain indices (160W,60S)
+      jpizoom =   61   ,    &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =    7   ,    &  !: in data domain indices (160W,75S)
+      ! Domain characteristics
+      jperio  =   0   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =  18   ,      &  !: number of islands
+      jpnisl  = 800             !: maximum number of points per island
+#else
+      ! global domain size     !!! *  global domain  *
+      jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom 
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data domain indices
+      ! Domain characteristics
+      jperio  =   4   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =  18   ,      &  !: number of islands
+      jpnisl  = 800             !: maximum number of points per island
+#endif
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &
+      pp_not_used       = 999999_wp , &  !:
+      pp_to_be_computed = 0._wp          !:
+
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+
+   INTEGER,PARAMETER   ::    & !
+      jphgr_msh = 0            !: type of horizontal mesh
+      !                        !  = 0 curvilinear coordinate on the sphere
+      !                        !      read in coordinate.nc file
+      !                        !  = 1 geographical mesh on the sphere
+      !                        !      with regular grid-spacing
+      !                        !  = 2 f-plane with regular grid-spacing
+      !                        !  = 3 beta-plane with regular grid-spacing
+      !                        !  = 4 Mercator grid with T/U point at the equator  with
+      !                        !      isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::       &  !
+      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                            !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+
+   !!
+   !! Vertical grid parameter for domzgr
+   !! ==================================
+   !!
+   REAL(wp), PARAMETER  ::       &
+      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+      &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
+      &     ppa1  =   245.58132232490_wp    ,  &  !:
+      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+   !!
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+   !!
+   REAL(wp), PARAMETER ::        &
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R4.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R4.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_ORCA_R4.h90	(revision 4536)
@@ -0,0 +1,83 @@
+   !!---------------------------------------------------------------------
+   !!                     ***  par_ORCA_R4.h90  ***   
+   !!   Ocean Domain : 4 degrees resolution global ocean
+   !!                  (0RCA_R4 configuration)
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16), PARAMETER ::    &
+      cp_cfg = "orca"           !: name of the configuration
+   INTEGER, PARAMETER ::     &
+      jp_cfg = 4      ,      &  !: resolution of the configuration (degrees)
+      ! Original data size
+      jpidta  =  92   ,      &  !: first horizontal dimension > or = to jpi
+      jpjdta  =  76   ,      &  !: second                     > or = to jpj
+      jpkdta  =  31   ,      &  !: number of levels           > or = to jpk
+      ! global domain matrix size
+      jpiglo  = jpidta,      &  !: first  dimension of global domain --> i
+      jpjglo  = jpjdta,      &  !: second dimension of global domain --> j
+      jpk     = jpkdta,      &  !: number of vertical levels
+      ! starting position of the zoom
+      jpizoom =   1   ,      &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,      &  !: in data indices
+      ! Domain characteristics
+      jperio  =   4   ,      &  !: lateral cond. type (between 0 and 6)
+      jpisl   =  11   ,      &  !: number of islands
+      jpnisl  = 800             !: maximum number of points per island
+
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   &
+      pp_not_used       = 999999_wp , &  !:
+      pp_to_be_computed = 0._wp          !:
+
+   !! Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::     & !
+      jphgr_msh = 0            !: type of horizontal mesh
+      !                        ! = 0 curvilinear coordinate on the sphere
+      !                        !     read in coordinate.nc file
+      !                        ! = 1 geographical mesh on the sphere
+      !                        !     with regular grid-spacing
+      !                        ! = 2 f-plane with regular grid-spacing
+      !                        ! = 3 beta-plane with regular grid-spacing
+      !                        ! = 4 Mercator grid with T/U point at the equator  with
+      !                        !     isotropic resolution (e1_deg)
+
+      !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+      !   The mercator grid starts only approximately at gphi0 because
+      !   of the constraint that the equator be a T point.
+   REAL(wp) , PARAMETER ::      &  !
+      ppglam0  = pp_not_used,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  = pp_not_used,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                            ! latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg = pp_not_used,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg = pp_not_used,   &  !: meridional grid-spacing (degrees)
+      !
+      ppe1_m   = pp_not_used,   &  !: zonal      grid-spacing (meters )
+      ppe2_m   = pp_not_used       !: meridional grid-spacing (meters )
+
+
+   !! Vertical grid parameter for domzgr
+   !! ==================================
+
+   REAL(wp), PARAMETER  ::       &
+      &     ppsur = -4762.96143546300_wp    ,  &  !: ORCA r4, r2 and r05 coefficients
+      &     ppa0  =   255.58049070440_wp    ,  &  !: (default coefficients)
+      &     ppa1  =   245.58132232490_wp    ,  &  !:
+      &     ppkth =    21.43336197938_wp    ,  &  !: (non dimensional): gives the approximate
+      !                                           !: layer number above which  stretching will
+      !                                           !: be maximum. Usually of order jpk/2.
+      &     ppacr =     3.00000000000_wp          !: (non dimensional): stretching factor
+      !                                           !: for the grid. The highest zacr, the smallest
+      !                                           !: the stretching.
+
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PARAMETER ::        &
+      &     ppdzmin = pp_not_used           ,  &  !: (meters) vertical thickness of the top layer
+      &     pphmax  = pp_not_used                 !: (meters) Maximum depth of the ocean gdepw(jpk)
+   !!---------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_kind.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_kind.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_kind.F90	(revision 4536)
@@ -0,0 +1,39 @@
+MODULE par_kind
+   !!======================================================================
+   !!                   ***  MODULE par_kind  ***
+   !! Ocean :  define the kind of real for the whole model
+   !!======================================================================
+   !! History :
+   !!   8.5   02/06  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER, PUBLIC, PARAMETER ::    &  !:
+      jpbyt   = 8       ,           &  !: real size for mpp communications
+      jpbytda = 4       ,           &  !: real size in input data files 4 or 8
+      jpbi3e  = 4                      !: real size for T3E
+
+   ! Number model from which the SELECTED_*_KIND are requested:
+   !             4 byte REAL       8 byte REAL
+   ! CRAY:           -            precision = 13
+   !                              exponent = 2465
+   ! IEEE:      precision = 6     precision = 15
+   !            exponent = 37     exponent = 307
+
+   INTEGER, PUBLIC, PARAMETER ::        &  !: Floating point section
+      sp = SELECTED_REAL_KIND( 6, 37),  &  !: single precision (real 4)
+      dp = SELECTED_REAL_KIND(12,307),  &  !: double precision (real 8)
+      wp = dp                              !: working precision
+
+   INTEGER, PUBLIC, PARAMETER ::        &  !: Integer section
+      i4 = SELECTED_INT_KIND(9) ,       &  !: single precision (integer 4)
+      i8 = SELECTED_INT_KIND(14)           !: double precision (integer 8)
+
+!!----------------------------------------------------------------------
+END MODULE par_kind
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/par_oce.F90	(revision 4536)
@@ -0,0 +1,199 @@
+MODULE par_oce
+   !!======================================================================
+   !!                        ***  par_oce  ***
+   !! Ocean :   set the ocean parameters
+   !!======================================================================
+   !! History :
+   !!   4.0  !  91     (Imbard, Levy, Madec)  Original code
+   !!   9.0  !  04-01  (G. Madec, J.-M. Molines)  Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !!   Domain decomposition
+   !!----------------------------------------------------------------------
+   !! * if we dont use massively parallel computer (parameters jpni=jpnj=1)
+   !!      so jpiglo=jpi and jpjglo=jpj
+
+   INTEGER, PUBLIC, PARAMETER ::    &  !:
+      jpni   = 1,                   &  !: number of processors following i 
+      jpnj   = 1,                   &  !: number of processors following j
+      jpnij  = 1,                   &  !: nb of local domain = nb of processors 
+      !                                !  ( <= jpni x jpnj )
+      jpr2di = 0,                   &  !: number of columns for extra outer halo 
+      jpr2dj = 0,                   &  !: number of rows    for extra outer halo 
+      jpreci = 1,                   &  !: number of columns for overlap 
+      jprecj = 1                       !: number of rows    for overlap 
+
+   !! Ocean Domain sizes
+   !! ------------------
+   !!   data           domain   (jpidta,jpjdta)
+   !!   global or zoom domain   (jpiglo,jpjglo)
+   !!   local          domain   ( jpi  , jpj  )
+   
+#if   defined key_orca_r4
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r4'   :                           global ocean : ORCA R4
+   !!---------------------------------------------------------------------
+#             include "par_ORCA_R4.h90"
+#elif defined key_orca_r2
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r2'   :                           global ocean : ORCA R4
+   !!---------------------------------------------------------------------
+#             include "par_ORCA_R2.h90"
+#elif defined key_orca_r05
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r05'  :                          global ocean : ORCA R05
+   !!---------------------------------------------------------------------
+#             include "par_ORCA_R05.h90"
+#elif defined key_orca_r025
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r025' :                         global ocean : ORCA R025
+   !!---------------------------------------------------------------------
+#             include "par_ORCA_R025.h90"
+#elif defined key_eel_r2
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r2'    :                                 channel : EEL R2
+   !!---------------------------------------------------------------------
+#             include "par_EEL_R2.h90"
+#elif defined key_eel_r5
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r5'    :                                 channel : EEL R5
+   !!---------------------------------------------------------------------
+#             include "par_EEL_R5.h90"
+#elif defined key_eel_r6
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r6'    :                                 channel : EEL R6
+   !!---------------------------------------------------------------------
+#             include "par_EEL_R6.h90"
+#elif defined key_gyre
+   !!---------------------------------------------------------------------
+   !!   'key_gyre'      :                        mid-latitude basin : GYRE
+   !!---------------------------------------------------------------------
+#             include "par_GYRE.h90"
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                               small closed basin
+   !!---------------------------------------------------------------------
+   CHARACTER(len=16), PUBLIC, PARAMETER ::   &  !:
+      cp_cfg = "default"               !: name of the configuration
+   INTEGER, PARAMETER ::            &  !:
+      jp_cfg = 0  ,                 &  !: resolution of the configuration
+
+      ! data size                     !!! * size of all input files *
+      jpidta  = 10,                 &  !: 1st lateral dimension ( >= jpi )
+      jpjdta  = 12,                 &  !: 2nd    "         "    ( >= jpj )
+      jpkdta  = 31,                 &  !: number of levels      ( >= jpk )
+
+      ! global or zoom domain size    !!! * computational domain *
+      jpiglo  = jpidta,             &  !: 1st dimension of global domain --> i
+      jpjglo  = jpjdta,             &  !: 2nd    "                  "    --> j
+      jpk     = jpkdta,             &  !: number of vertical levels
+      ! zoom starting position 
+      jpizoom =   1   ,             &  !: left bottom (i,j) indices of the zoom
+      jpjzoom =   1   ,             &  !: in data domain indices
+
+      ! Domain characteristics
+      jperio  =  0,                 &  !: lateral cond. type (between 0 and 6)
+         !                             !  = 0 closed
+         !                             !  = 1 cyclic East-West
+         !                             !  = 2 equatorial symmetric
+         !                             !  = 3 North fold T-point pivot
+         !                             !  = 4 cyclic East-West AND North fold T-point pivot
+         !                             !  = 5 North fold F-point pivot
+         !                             !  = 6 cyclic East-West AND North fold F-point pivot
+      jpisl   =  0,                 &  !: number of islands (rigid-lid only)
+      jpnisl  =  0                     !: maximum number of points per island
+
+      !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+      !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+      REAL(wp), PARAMETER ::   &  !:
+         pp_not_used       = 999999._wp , &  !:
+         pp_to_be_computed = 999999._wp      !:
+
+
+   !! Horizontal grid parameters for domhgr
+   !! =====================================
+
+   INTEGER, PUBLIC, PARAMETER   ::   &  !:
+      jphgr_msh = 0            !: type of horizontal mesh
+      !                        !  = 0 curvilinear coordinate on the sphere
+      !                        !      read in coordinate.nc file
+      !                        !  = 1 geographical mesh on the sphere
+      !                        !      with regular grid-spacing
+      !                        !  = 2 f-plane with regular grid-spacing
+      !                        !  = 3 beta-plane with regular grid-spacing
+      !                        !  = 4 Mercator grid with T/U point at the equator  with
+      !                        !      isotropic resolution (e1_deg)
+
+   REAL(wp) , PUBLIC, PARAMETER ::   &   !:
+      ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
+      ppgphi0  =  -35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
+      !                          !  latitude for the Coriolis or Beta parameter (jphgr_msh = 2 or 3)
+      ppe1_deg =    1.0_wp,   &  !: zonal      grid-spacing (degrees)
+      ppe2_deg =    0.5_wp,   &  !: meridional grid-spacing (degrees)
+      ppe1_m   = 5000.0_wp,   &  !: zonal      grid-spacing (degrees)
+      ppe2_m   = 5000.0_wp       !: meridional grid-spacing (degrees)
+
+   !! Vertical grid parameter for domzgr
+   !! ==================================
+
+   REAL(wp), PUBLIC, PARAMETER  ::   &  !:
+      &     ppsur = -4762.96143546300_wp ,  &  !: ORCA r4, r2 and r05 coefficients
+      &     ppa0  =   255.58049070440_wp ,  &  !: (default coefficients)
+      &     ppa1  =   245.58132232490_wp ,  &  !:
+      &     ppkth =    21.43336197938_wp ,  &  !:
+      &     ppacr =     3.00000000000_wp       !:
+
+   !!  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !!  they are computed from ppdzmin, pphmax , ppkth, ppacr in dom_zgr
+
+   REAL(wp), PUBLIC, PARAMETER ::   &  !:
+      &     ppdzmin = 10._wp             ,  &  !: Minimum vertical spacing
+      &     pphmax  = 5000._wp                 !: Maximum depth
+
+   !!---------------------------------------------------------------------
+#endif
+
+   !!---------------------------------------------------------------------
+   !! Domain Matrix size
+   !!---------------------------------------------------------------------
+   INTEGER, PUBLIC, PARAMETER ::   &  !:
+      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ,   &  !: first  dimension
+      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ,   &  !: second dimension
+      jpim1 = jpi-1,                                             &  !: inner domain indices
+      jpjm1 = jpj-1,                                             &  !:   "            "
+      jpkm1 = jpk-1,                                             &  !:   "            "
+      jpij  = jpi*jpj                                               !:  jpi x jpj
+
+   !!---------------------------------------------------------------------
+   !! Optimization/control flags
+   !!---------------------------------------------------------------------
+#if defined key_esopa
+   LOGICAL, PUBLIC, PARAMETER ::   lk_esopa     = .TRUE.   !: flag to activate the all options
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_esopa     = .FALSE.  !: flag to activate the all options
+#endif
+
+#if defined key_vectopt_memory
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_mem  = .TRUE.   !: vector optimization flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_mem  = .FALSE.  !: vector optimization flag
+#endif
+
+#if defined key_vectopt_loop
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .TRUE.   !: vector optimization flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .FALSE.  !: vector optimization flag
+#endif
+
+   !!======================================================================
+END MODULE par_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/phycst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/phycst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/phycst.F90	(revision 4536)
@@ -0,0 +1,196 @@
+MODULE phycst
+   !!======================================================================
+   !!                    ***  MODULE  phycst  ***
+   !!     Definition of of both ocean and ice parameters used in the code
+   !!=====================================================================
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE in_out_manager   ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC phy_cst          ! routine called by inipar.F90
+
+   !! * Shared module variables
+   INTEGER, PUBLIC, DIMENSION(12) ::   &  !:
+      nbiss = (/ 31, 29, 31, 30, 31, 30,      &  !: number of days per month
+         &       31, 31, 30, 31, 30, 31 /) ,  &  !  (leap-year)
+      nobis = (/ 31, 28, 31, 30, 31, 30,      &  !: number of days per month
+         &       31, 31, 30, 31, 30, 31 /)       !  (365 days a year)
+   
+   REAL(wp), PUBLIC ::                        &  !:
+      rpi = 3.141592653589793_wp           ,  &  !: pi
+      rad = 3.141592653589793_wp / 180._wp ,  &  !: conversion from degre into radian
+      rsmall = 0.5 * EPSILON( 1. )               !: smallest real computer value
+   
+   REAL(wp), PUBLIC ::          & !:
+      rday = 24.*60.*60.  ,     & !: day (s)
+      rsiyea              ,     & !: sideral year (s)
+      rsiday              ,     & !: sideral day (s)
+      raajj = 365._wp     ,     & !: number of days in one year
+      raamo =  12._wp     ,     & !: number of months in one year
+      rjjhh =  24._wp     ,     & !: number of hours in one day
+      rhhmm =  60._wp     ,     & !: number of minutes in one hour
+      rmmss =  60._wp     ,     & !: number of seconds in one minute
+      raass               ,     & !: number of seconds in one year
+      rmoss               ,     & !: number of seconds in one month
+      rjjss               ,     & !: number of seconds in one day
+!!!   omega = 7.292115083046061e-5_wp ,  &  !: change the last digit!
+      omega               ,    &  !: earth rotation parameter
+      ra    = 6371229._wp ,    &  !: earth radius (meter)
+      grav  = 9.80665_wp          !: gravity (m/s2)
+   
+   REAL(wp), PUBLIC ::         &  !:
+      rtt      = 273.16_wp  ,  &  !: triple point of temperature (Kelvin)
+      rt0      = 273.15_wp  ,  &  !: freezing point of water (Kelvin)
+      rt0_snow = 273.15_wp  ,  &  !: melting point of snow  (Kelvin)
+      rt0_ice  = 273.05_wp  ,  &  !: melting point of ice   (Kelvin)
+      rau0     = 1020._wp   ,  &  !: volumic mass of reference (kg/m3)
+      rauw     = 1000._wp   ,  &  !: density of pure water (kg/m3)
+      rcp      =    4.e+3_wp,  &  !: ocean specific heat
+      ro0cpr                      !: = 1. / ( rau0 * rcp )
+
+   REAL(wp), PUBLIC ::            &  !:
+      rcdsn   =   0.22_wp     ,   &  !: conductivity of the snow
+      rcdic   =   2.034396_wp ,   &  !: conductivity of the ice
+      rcpsn   =   6.9069e+5_wp,   &  !: density times specific heat for snow
+      rcpic   =   1.8837e+6_wp,   &  !: volumetric latent heat fusion of sea ice
+      xlsn    = 110.121e+6_wp ,   &  !: volumetric latent heat fusion of snow
+      xlic    = 300.33e+6_wp  ,   &  !: volumetric latent heat fusion of ice
+      xsn     =   2.8e+6      ,   &  !: latent heat of sublimation of snow
+      rhoic   = 900._wp       ,   &  !: density of sea ice (kg/m3)
+      rhosn   = 330._wp       ,   &  !: density of snow (kg/m3)
+      emic    =   0.97_wp     ,   &  !: emissivity of snow or ice
+      sice    =   6.0_wp      ,   &  !: salinity of ice (psu)
+      soce    =  34.7_wp      ,   &  !: salinity of sea (psu)
+      cevap   =   2.5e+6_wp   ,   &  !: latent heat of evaporation (water)
+      srgamma =   0.9_wp      ,   &  !: correction factor for solar radiation (Oberhuber, 1974)
+      vkarmn  =   0.4_wp      ,   &  !: von Karman constant
+      stefan  =   5.67e-8_wp         !: Stefan-Boltzmann constant 
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+   
+CONTAINS
+   
+   SUBROUTINE phy_cst
+      !!----------------------------------------------------------------------
+      !!                       ***  ROUTINE phy_cst  ***
+      !!
+      !! ** Purpose :   Print model parameters and set and print the constants
+      !!
+      !! ** Method  :   no
+      !!
+      !! History :
+      !!        !  90-10  (C. Levy - G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  91-12  (M. Imbard)
+      !!   8.5  !  02-08  (G. Madec, C. Ethe)  F90, add ice constants 
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      CHARACTER (len=64) ::   cform = "(A9, 3(A13, I7) )" 
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' phy_cst : initialization of ocean parameters and constants'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+
+      ! Ocean Parameters
+      ! ----------------
+      IF(lwp) THEN
+         WRITE(numout,*) '       parameter file'
+         WRITE(numout,*)
+         WRITE(numout,*) '          dimension of model'
+         WRITE(numout,*) '              Local domain      Global domain       Data domain '
+         WRITE(numout,cform) '         ','   jpi     : ', jpi, '   jpiglo  : ', jpiglo, '   jpidta  : ', jpidta
+         WRITE(numout,cform) '         ','   jpj     : ', jpj, '   jpjglo  : ', jpjglo, '   jpjdta  : ', jpjdta
+         WRITE(numout,cform) '         ','   jpk     : ', jpk, '   jpk     : ', jpk   , '   jpkdta  : ', jpkdta
+         WRITE(numout,*)      '        ','   jpij    : ', jpij
+         WRITE(numout,*)
+         WRITE(numout,*) '          mpp local domain info (mpp)'
+         WRITE(numout,*) '             jpni    : ', jpni, '   jpreci  : ', jpreci
+         WRITE(numout,*) '             jpnj    : ', jpnj, '   jprecj  : ', jprecj
+         WRITE(numout,*) '             jpnij   : ', jpnij
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          lateral domain boundary condition type : jperio  = ', jperio
+         WRITE(numout,*) '          domain island (use in rigid-lid case)  : jpisl   = ', jpisl 
+         WRITE(numout,*) '                                                   jpnisl  = ', jpnisl
+      ENDIF
+
+      ! Define constants
+      ! ----------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '       constants'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          mathematical constant                 rpi = ', rpi
+
+      rsiyea = 365.25 * rday * 2. * rpi / 6.283076
+      rsiday = rday / ( 1. + rday / rsiyea )
+      omega  = 2. * rpi / rsiday 
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          day                                rday   = ', rday,   ' s'
+      IF(lwp) WRITE(numout,*) '          sideral year                       rsiyea = ', rsiyea, ' s'
+      IF(lwp) WRITE(numout,*) '          sideral day                        rsiday = ', rsiday, ' s'
+      IF(lwp) WRITE(numout,*) '          omega                              omega  = ', omega,  ' s-1'
+
+      rjjss = rjjhh * rhhmm * rmmss
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          nb of months per year               raamo = ', raamo, ' months'
+      IF(lwp) WRITE(numout,*) '          nb of hours per day                 rjjhh = ', rjjhh, ' hours'
+      IF(lwp) WRITE(numout,*) '          nb of minutes per hour              rhhmm = ', rhhmm, ' mn'
+      IF(lwp) WRITE(numout,*) '          nb of seconds per minute            rmmss = ', rmmss, ' s'
+      IF(lwp) WRITE(numout,*) '          nb of seconds per day               rjjss = ', rjjss, ' s'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          earth radius                         ra   = ', ra, ' m'
+      IF(lwp) WRITE(numout,*) '          gravity                              grav = ', grav , ' m/s^2'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          triple point of temperature      rtt      = ', rtt     , ' K'
+      IF(lwp) WRITE(numout,*) '          freezing point of water          rt0      = ', rt0     , ' K'
+      IF(lwp) WRITE(numout,*) '          melting point of snow            rt0_snow = ', rt0_snow, ' K'
+      IF(lwp) WRITE(numout,*) '          melting point of ice             rt0_ice  = ', rt0_ice , ' K'
+
+      ro0cpr = 1. / ( rau0 * rcp )
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          volumic mass of pure water         rauw   = ', rauw, ' kg/m^3'
+      IF(lwp) WRITE(numout,*) '          volumic mass of reference          rau0   = ', rau0, ' kg/m^3'
+      IF(lwp) WRITE(numout,*) '          ocean specific heat                rcp    = ', rcp
+      IF(lwp) WRITE(numout,*) '                       1. / ( rau0 * rcp ) = ro0cpr = ', ro0cpr
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          thermal conductivity of the snow          = ', rcdsn   , ' J/s/m/K'
+         WRITE(numout,*) '          thermal conductivity of the ice           = ', rcdic   , ' J/s/m/K'
+         WRITE(numout,*) '          density times specific heat for snow      = ', rcpsn   , ' J/m^3/K' 
+         WRITE(numout,*) '          density times specific heat for ice       = ', rcpic   , ' J/m^3/K'
+         WRITE(numout,*) '          volumetric latent heat fusion of sea ice  = ', xlic    , ' J/m' 
+         WRITE(numout,*) '          volumetric latent heat fusion of snow     = ', xlsn    , ' J/m' 
+         WRITE(numout,*) '          latent heat of sublimation of snow        = ', xsn     , ' J/kg' 
+         WRITE(numout,*) '          density of sea ice                        = ', rhoic   , ' kg/m^3'
+         WRITE(numout,*) '          density of snow                           = ', rhosn   , ' kg/m^3'
+         WRITE(numout,*) '          emissivity of snow or ice                 = ', emic  
+         WRITE(numout,*) '          salinity of ice                           = ', sice    , ' psu'
+         WRITE(numout,*) '          salinity of sea                           = ', soce    , ' psu'
+         WRITE(numout,*) '          latent heat of evaporation (water)        = ', cevap   , ' J/m^3' 
+         WRITE(numout,*) '          correction factor for solar radiation     = ', srgamma 
+         WRITE(numout,*) '          von Karman constant                       = ', vkarmn 
+         WRITE(numout,*) '          Stefan-Boltzmann constant                 = ', stefan  , ' J/s/m^2/K^4'
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion: degre ==> radian          rad = ', rad
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          smallest real computer value       rsmall = ', rsmall
+      ENDIF
+
+   END SUBROUTINE phy_cst
+
+   !!======================================================================
+END MODULE phycst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/prtctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/prtctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/prtctl.F90	(revision 4536)
@@ -0,0 +1,575 @@
+MODULE prtctl
+   !!==============================================================================
+   !!                       ***  MODULE prtctl   ***
+   !! Ocean system   : print all SUM trends for each processor domain
+   !!==============================================================================
+   USE dom_oce          ! ocean space and time domain variables
+   USE in_out_manager   ! I/O manager
+   USE lib_mpp          ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module declaration
+   INTEGER, DIMENSION(:), ALLOCATABLE :: numid
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   &  !:
+      nlditl , nldjtl ,   &  !: first, last indoor index for each i-domain
+      nleitl , nlejtl ,   &  !: first, last indoor index for each j-domain
+      nimpptl, njmpptl,   &  !: i-, j-indexes for each processor
+      nlcitl , nlcjtl ,   &  !: dimensions of every subdomain
+      ibonitl, ibonjtl
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE ::   &  !:
+      t_ctll , s_ctll ,   &  !: previous trend values
+      u_ctll , v_ctll
+
+   INTEGER ::   ktime        !: time step
+
+   !! * Routine accessibility
+   PUBLIC prt_ctl         ! called by all subroutines
+   PUBLIC prt_ctl_info    ! called by all subroutines
+   PUBLIC prt_ctl_init    ! called by opa.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+   SUBROUTINE prt_ctl (tab2d_1, tab3d_1, mask1, clinfo1, tab2d_2, tab3d_2, mask2, clinfo2, ovlap, kdim, clinfo3)
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl  ***
+      !!
+      !! ** Purpose : - print sum control of 2D or 3D arrays over the same area 
+      !!                in mono and mpp case. This way can be usefull when
+      !!                debugging a new parametrization in mono or mpp. 
+      !!
+      !! ** Method  : 2 possibilities exist when setting the ln_ctl parameter to
+      !!                .true. in the ocean namelist:
+      !!              - to debug a MPI run .vs. a mono-processor one; 
+      !!                the control print will be done over each sub-domain.
+      !!                The nictl[se] and njctl[se] parameters in the namelist must 
+      !!                be set to zero and [ij]splt to the corresponding splitted
+      !!                domain in MPI along respectively i-, j- directions.
+      !!              - to debug a mono-processor run over the whole domain/a specific area; 
+      !!                in the first case the nictl[se] and njctl[se] parameters must be set
+      !!                to zero else to the indices of the area to be controled. In both cases
+      !!                isplt and jsplt must be set to 1.
+      !!              - All arguments of the above calling sequence are optional so their
+      !!                name must be explicitly typed if used. For instance if the 3D
+      !!                array tn(:,:,:) must be passed through the prt_ctl subroutine, 
+      !!                it must looks like: CALL prt_ctl(tab3d_1=tn).
+      !!
+      !!                    tab2d_1 : first 2D array
+      !!                    tab3d_1 : first 3D array
+      !!                    mask1   : mask (3D) to apply to the tab[23]d_1 array
+      !!                    clinfo1 : information about the tab[23]d_1 array
+      !!                    tab2d_2 : second 2D array
+      !!                    tab3d_2 : second 3D array
+      !!                    mask2   : mask (3D) to apply to the tab[23]d_2 array
+      !!                    clinfo2 : information about the tab[23]d_2 array
+      !!                    ovlap   : overlap value
+      !!                    kdim    : k- direction for 3D arrays 
+      !!                    clinfo3 : additional information 
+      !!
+      !! History :
+      !!   9.0  !  05-07  (C. Talandier) original code
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(:,:)  , INTENT(in), OPTIONAL :: tab2d_1
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: tab3d_1
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: mask1
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo1
+      REAL(wp), DIMENSION(:,:)  , INTENT(in), OPTIONAL :: tab2d_2
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: tab3d_2
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: mask2
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo2
+      INTEGER                   , INTENT(in), OPTIONAL :: ovlap
+      INTEGER                   , INTENT(in), OPTIONAL :: kdim
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo3
+
+      !! * Local declarations
+      INTEGER :: overlap, jn, sind, eind, kdir,j_id
+      CHARACTER (len=15) :: cl2
+      REAL(wp) :: zsum1, zsum2, zvctl1, zvctl2
+      REAL(wp), DIMENSION(jpi,jpj) :: ztab2d_1, ztab2d_2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zmask1, zmask2, ztab3d_1, ztab3d_2
+      !!----------------------------------------------------------------------
+
+      ! Arrays, scalars initialization 
+      overlap   = 0
+      kdir      = jpkm1
+      cl2       = ''
+      zsum1     = 0.e0
+      zsum2     = 0.e0
+      zvctl1    = 0.e0
+      zvctl2    = 0.e0
+      ztab2d_1(:,:)   = 0.e0
+      ztab2d_2(:,:)   = 0.e0
+      ztab3d_1(:,:,:) = 0.e0
+      ztab3d_2(:,:,:) = 0.e0
+      zmask1  (:,:,:) = 1.e0
+      zmask2  (:,:,:) = 1.e0
+
+      ! Control of optional arguments
+      IF( PRESENT(clinfo2) )  cl2            = clinfo2
+      IF( PRESENT(ovlap)   )  overlap        = ovlap
+      IF( PRESENT(kdim)    )  kdir           = kdim
+      IF( PRESENT(tab2d_1) )  ztab2d_1(:,:)  = tab2d_1(:,:)
+      IF( PRESENT(tab2d_2) )  ztab2d_2(:,:)  = tab2d_2(:,:)
+      IF( PRESENT(tab3d_1) )  ztab3d_1(:,:,:)= tab3d_1(:,:,:)
+      IF( PRESENT(tab3d_2) )  ztab3d_2(:,:,:)= tab3d_2(:,:,:)
+      IF( PRESENT(mask1)   )  zmask1  (:,:,:)= mask1  (:,:,:)
+      IF( PRESENT(mask2)   )  zmask2  (:,:,:)= mask2  (:,:,:)
+
+      IF( lk_mpp )   THEN
+         ! processor number
+         sind = narea
+         eind = narea
+      ELSE
+         ! processors total number
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. the total number of processors ijsplt
+      DO jn = sind, eind
+         ! Set logical unit
+         j_id = numid(jn - narea + 1)
+         ! Set indices for the SUM control
+         IF( .NOT. lsp_area ) THEN
+            IF (lk_mpp )   THEN
+               nictls = MAX( 1, nlditl(jn) - overlap )
+               nictle = nleitl(jn) + overlap * MIN( 1, nlcitl(jn) - nleitl(jn)) 
+               njctls = MAX( 1, nldjtl(jn) - overlap )
+               njctle = nlejtl(jn) + overlap * MIN( 1, nlcjtl(jn) - nlejtl(jn))
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(jn) == -1 .OR. ibonitl(jn) == 2 ) nictls = MAX(2, nictls)
+               IF( ibonjtl(jn) == -1 .OR. ibonjtl(jn) == 2 ) njctls = MAX(2, njctls)
+               IF( ibonitl(jn) ==  1 .OR. ibonitl(jn) == 2 ) nictle = MIN(nictle, nleitl(jn) - 1)
+               IF( ibonjtl(jn) ==  1 .OR. ibonjtl(jn) == 2 ) njctle = MIN(njctle, nlejtl(jn) - 1)
+            ELSE
+               nictls = MAX( 1, nimpptl(jn) + nlditl(jn) - 1 - overlap )
+               nictle = nimpptl(jn) + nleitl(jn) - 1 + overlap * MIN( 1, nlcitl(jn) - nleitl(jn) ) 
+               njctls = MAX( 1, njmpptl(jn) + nldjtl(jn) - 1 - overlap )
+               njctle = njmpptl(jn) + nlejtl(jn) - 1 + overlap * MIN( 1, nlcjtl(jn) - nlejtl(jn) ) 
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(jn) == -1 .OR. ibonitl(jn) == 2 ) nictls = MAX(2, nictls)
+               IF( ibonjtl(jn) == -1 .OR. ibonjtl(jn) == 2 ) njctls = MAX(2, njctls)
+               IF( ibonitl(jn) ==  1 .OR. ibonitl(jn) == 2 ) nictle = MIN(nictle, nimpptl(jn) + nleitl(jn) - 2)
+               IF( ibonjtl(jn) ==  1 .OR. ibonjtl(jn) == 2 ) njctle = MIN(njctle, njmpptl(jn) + nlejtl(jn) - 2)
+            ENDIF
+         ENDIF
+
+         IF ( clinfo3 == 'tra' )  THEN
+             zvctl1 = t_ctll(jn)
+             zvctl2 = s_ctll(jn)
+         ELSEIF ( clinfo3 == 'dyn' )   THEN
+             zvctl1 = u_ctll(jn)
+             zvctl2 = v_ctll(jn)
+         ENDIF
+
+         ! Compute the sum control
+         ! 2D arrays
+         IF( PRESENT(tab2d_1) )   THEN
+            zsum1 = SUM( ztab2d_1(nictls:nictle,njctls:njctle)*zmask1(nictls:nictle,njctls:njctle,1) )
+            zsum2 = SUM( ztab2d_2(nictls:nictle,njctls:njctle)*zmask2(nictls:nictle,njctls:njctle,1) )
+         ENDIF
+
+         ! 3D arrays
+         IF( PRESENT(tab3d_1) )   THEN
+            zsum1 = SUM( ztab3d_1(nictls:nictle,njctls:njctle,1:kdir)*zmask1(nictls:nictle,njctls:njctle,1:kdir) )
+            zsum2 = SUM( ztab3d_2(nictls:nictle,njctls:njctle,1:kdir)*zmask2(nictls:nictle,njctls:njctle,1:kdir) )
+         ENDIF
+
+         ! Print the result
+         IF( PRESENT(clinfo3) )   THEN
+            WRITE(j_id,FMT='(a,D23.16,3x,a,D23.16)')clinfo1, zsum1-zvctl1, cl2, zsum2-zvctl2
+            SELECT CASE( clinfo3 )
+            CASE ( 'tra-ta' ) 
+               t_ctll(jn) = zsum1
+            CASE ( 'tra' ) 
+                t_ctll(jn) = zsum1
+                s_ctll(jn) = zsum2
+            CASE ( 'dyn' ) 
+                u_ctll(jn) = zsum1
+                v_ctll(jn) = zsum2 
+            END SELECT
+         ELSEIF ( PRESENT(clinfo2) .OR. PRESENT(tab2d_2) .OR. PRESENT(tab3d_2) )   THEN
+            WRITE(j_id,FMT='(a,D23.16,3x,a,D23.16)')clinfo1, zsum1, cl2, zsum2
+         ELSE
+            WRITE(j_id,FMT='(a,D23.16)')clinfo1, zsum1
+         ENDIF
+
+      ENDDO
+
+   END SUBROUTINE prt_ctl
+
+
+   SUBROUTINE prt_ctl_info (clinfo1, ivar1, clinfo2, ivar2, itime)
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_info  ***
+      !!
+      !! ** Purpose : - print information without any computation
+      !!
+      !! ** Action  : - input arguments
+      !!                    clinfo1 : information about the ivar1
+      !!                    ivar1   : value to print
+      !!                    clinfo2 : information about the ivar2
+      !!                    ivar2   : value to print
+      !!
+      !! History :
+      !!   9.0  !  05-07  (C. Talandier) original code
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER (len=*), INTENT(in) ::   clinfo1
+      INTEGER          , INTENT(in), OPTIONAL ::   ivar1
+      CHARACTER (len=*), INTENT(in), OPTIONAL ::   clinfo2
+      INTEGER          , INTENT(in), OPTIONAL ::   ivar2
+      INTEGER          , INTENT(in), OPTIONAL ::   itime
+
+      !! * Local declarations
+      INTEGER :: jn, sind, eind, iltime, j_id
+      !!----------------------------------------------------------------------
+
+      IF( lk_mpp )   THEN
+         ! processor number
+         sind = narea
+         eind = narea
+      ELSE
+         ! total number of processors
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Set to zero arrays at each new time step
+      IF( PRESENT(itime) )   THEN
+         iltime = itime
+         IF( iltime > ktime )   THEN
+            t_ctll(:) = 0.e0   ;   s_ctll(:) = 0.e0
+            u_ctll(:) = 0.e0   ;   v_ctll(:) = 0.e0
+            ktime = iltime
+         ENDIF
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. number of processors ijsplt
+      DO jn = sind, eind
+         
+         ! Set logical unit
+         j_id = numid(jn - narea + 1)
+
+         IF( PRESENT(ivar1) .AND. PRESENT(clinfo2) .AND. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, clinfo2, ivar2
+         ELSEIF ( PRESENT(ivar1) .AND. PRESENT(clinfo2) .AND. .NOT. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, clinfo2
+         ELSEIF ( PRESENT(ivar1) .AND. .NOT. PRESENT(clinfo2) .AND. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, ivar2
+         ELSEIF ( PRESENT(ivar1) .AND. .NOT. PRESENT(clinfo2) .AND. .NOT. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1
+         ELSE
+            WRITE(j_id,*)clinfo1
+         ENDIF
+
+      ENDDO
+
+
+      END SUBROUTINE prt_ctl_info
+
+   SUBROUTINE prt_ctl_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_init  ***
+      !!
+      !! ** Purpose :   open ASCII files & compute indices
+      !!
+      !! History :
+      !!   9.0  !  05-07  (C. Talandier) original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   jn, sind, eind, j_id
+      CHARACTER (len=28) :: clfile_out
+      CHARACTER (len=23) :: clb_name
+      CHARACTER (len=19) :: cl_run
+      !!----------------------------------------------------------------------
+
+      ! Allocate arrays
+      ALLOCATE(nlditl (ijsplt))
+      ALLOCATE(nldjtl (ijsplt))
+      ALLOCATE(nleitl (ijsplt))
+      ALLOCATE(nlejtl (ijsplt))
+      ALLOCATE(nimpptl(ijsplt))
+      ALLOCATE(njmpptl(ijsplt))
+      ALLOCATE(nlcitl (ijsplt))
+      ALLOCATE(nlcjtl (ijsplt))
+      ALLOCATE(t_ctll (ijsplt))
+      ALLOCATE(s_ctll (ijsplt))
+      ALLOCATE(u_ctll (ijsplt))
+      ALLOCATE(v_ctll (ijsplt))
+      ALLOCATE(ibonitl(ijsplt))
+      ALLOCATE(ibonjtl(ijsplt))
+
+      ! Initialization 
+      t_ctll(:)=0.e0
+      s_ctll(:)=0.e0
+      u_ctll(:)=0.e0
+      v_ctll(:)=0.e0
+      ktime = 1
+
+      IF( lk_mpp ) THEN
+         sind = narea
+         eind = narea
+         clb_name = "('mpp.output_',I4.4)"
+         cl_run = 'MULTI processor run'
+         ! use indices for each area computed by mpp_init subroutine
+         nlditl(:) = nldit(:) 
+         nleitl(:) = nleit(:) 
+         nldjtl(:) = nldjt(:) 
+         nlejtl(:) = nlejt(:) 
+         !
+         nimpptl(:) = nimppt(:)
+         njmpptl(:) = njmppt(:)
+         !
+         nlcitl(:) = nlcit(:)
+         nlcjtl(:) = nlcjt(:)
+         !
+         ibonitl(:) = ibonit(:)
+         ibonjtl(:) = ibonjt(:)
+      ELSE
+         sind = 1
+         eind = ijsplt
+         clb_name = "('mono.output_',I4.4)"
+         cl_run = 'MONO processor run '
+         ! compute indices for each area as done in mpp_init subroutine
+         CALL sub_dom
+      ENDIF
+
+      ALLOCATE(numid(eind-sind+1))
+
+      DO jn = sind, eind
+         WRITE(clfile_out,FMT=clb_name) jn-1
+         CALL ctlopn( numid(jn -narea + 1), clfile_out, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .FALSE., 1 )
+         j_id = numid(jn -narea + 1)
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                 L O D Y C - I P S L'
+         WRITE(j_id,*) '                     O P A model'
+         WRITE(j_id,*) '            Ocean General Circulation Model'
+         WRITE(j_id,*) '               version OPA 9.0  (2005) '
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                   PROC number: ', jn
+         WRITE(j_id,*)
+         WRITE(j_id,FMT="(19x,a20)")cl_run
+
+         ! Print the SUM control indices
+         IF( .NOT. lsp_area )   THEN
+            nictls = nimpptl(jn) + nlditl(jn) - 1
+            nictle = nimpptl(jn) + nleitl(jn) - 1
+            njctls = njmpptl(jn) + nldjtl(jn) - 1
+            njctle = njmpptl(jn) + nlejtl(jn) - 1
+         ENDIF
+         WRITE(j_id,*) 
+         WRITE(j_id,*) 'prt_ctl :  Sum control indices'
+         WRITE(j_id,*) '~~~~~~~'
+         WRITE(j_id,*)
+         WRITE(j_id,9000)'                                nlej   = ', nlejtl(jn), '              '
+         WRITE(j_id,9000)'                  ------------- njctle = ', njctle, ' -------------'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9002)'           nictls = ', nictls,  '                           nictle = ', nictle
+         WRITE(j_id,9002)'           nldi   = ', nlditl(jn),  '                           nlei   = ', nleitl(jn)
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9004)'  njmpp  = ',njmpptl(jn),'   ------------- njctls = ', njctls, ' -------------'
+         WRITE(j_id,9003)'           nimpp  = ', nimpptl(jn), '        nldj   = ', nldjtl(jn), '              '
+         WRITE(j_id,*)
+         WRITE(j_id,*)
+
+9000     FORMAT(a41,i4.4,a14)
+9001     FORMAT(a59)
+9002     FORMAT(a20,i4.4,a36,i3.3)
+9003     FORMAT(a20,i4.4,a17,i4.4)
+9004     FORMAT(a11,i4.4,a26,i4.4,a14)
+      ENDDO
+
+   END SUBROUTINE prt_ctl_init
+
+
+   SUBROUTINE sub_dom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sub_dom  ***
+      !!                    
+      !! ** Purpose :   Lay out the global domain over processors. 
+      !!                CAUTION: 
+      !!                This part has been extracted from the mpp_init
+      !!                subroutine and names of variables/arrays have been 
+      !!                slightly changed to avoid confusion but the computation
+      !!                is exactly the same. Any modification about indices of
+      !!                each sub-domain in the mppini.F90 module should be reported 
+      !!                here.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!                Periodic condition is a function of the local domain position
+      !!                (global boundary or neighbouring domain) and of the global
+      !!                periodic
+      !!                Type :         jperio global periodic condition
+      !!                               nperio local  periodic condition
+      !!
+      !! ** Action  : - set domain parameters
+      !!                    nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlcil      : first dimension
+      !!                    nlcjl      : second dimension
+      !!                    nbondil    : mark for "east-west local boundary"
+      !!                    nbondjl    : mark for "north-south local boundary"
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji, jj, jn               ! dummy loop indices
+      INTEGER ::   &
+         ii, ij,                         &  ! temporary integers
+         irestil, irestjl,               &  !    "          "
+         ijpi  , ijpj, nlcil,            &  ! temporary logical unit
+         nlcjl , nbondil, nbondjl,       &
+         nrecil, nrecjl, nldil, nleil, nldjl, nlejl
+
+      INTEGER, DIMENSION(:,:), ALLOCATABLE ::   &
+         iimpptl, ijmpptl, ilcitl, ilcjtl       ! temporary workspace
+      REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+      !  Computation of local domain sizes ilcitl() ilcjtl()
+      !  These dimensions depend on global sizes isplt,jsplt and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array (cf. par_oce.F90).
+
+      ijpi = ( jpiglo-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
+      ijpj = ( jpjglo-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj
+
+      ALLOCATE(ilcitl (isplt,jsplt))
+      ALLOCATE(ilcjtl (isplt,jsplt))
+
+      nrecil  = 2 * jpreci
+      nrecjl  = 2 * jprecj
+      irestil = MOD( jpiglo - nrecil , isplt )
+      irestjl = MOD( jpjglo - nrecjl , jsplt )
+
+      IF(  irestil == 0 )   irestil = isplt
+      DO jj = 1, jsplt
+         DO ji = 1, irestil
+            ilcitl(ji,jj) = ijpi
+         END DO
+         DO ji = irestil+1, isplt
+            ilcitl(ji,jj) = ijpi -1
+         END DO
+      END DO
+      
+      IF( irestjl == 0 )   irestjl = jsplt
+      DO ji = 1, isplt
+         DO jj = 1, irestjl
+            ilcjtl(ji,jj) = ijpj
+         END DO
+         DO jj = irestjl+1, jsplt
+            ilcjtl(ji,jj) = ijpj -1
+         END DO
+      END DO
+      
+      zidom = nrecil
+      DO ji = 1, isplt
+         zidom = zidom + ilcitl(ji,1) - nrecil
+      END DO
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilcitl(i,1) = ', zidom, ' jpiglo = ', jpiglo
+      
+      zjdom = nrecjl
+      DO jj = 1, jsplt
+         zjdom = zjdom + ilcjtl(1,jj) - nrecjl
+      END DO
+      IF(lwp) WRITE(numout,*)' sum ilcitl(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      IF(lwp) WRITE(numout,*)
+      
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+
+      ALLOCATE(iimpptl(isplt,jsplt))
+      ALLOCATE(ijmpptl(isplt,jsplt))
+      
+      iimpptl(:,:) = 1
+      ijmpptl(:,:) = 1
+      
+      IF( isplt > 1 ) THEN
+         DO jj = 1, jsplt
+            DO ji = 2, isplt
+               iimpptl(ji,jj) = iimpptl(ji-1,jj) + ilcitl(ji-1,jj) - nrecil
+            END DO
+         END DO
+      ENDIF
+
+      IF( jsplt > 1 ) THEN
+         DO jj = 2, jsplt
+            DO ji = 1, isplt
+               ijmpptl(ji,jj) = ijmpptl(ji,jj-1)+ilcjtl(ji,jj-1)-nrecjl
+            END DO
+         END DO
+      ENDIF
+      
+      ! 3. Subdomain description
+      ! ------------------------
+
+      DO jn = 1, ijsplt
+         ii = 1 + MOD( jn-1, isplt )
+         ij = 1 + (jn-1) / isplt
+         nimpptl(jn) = iimpptl(ii,ij)
+         njmpptl(jn) = ijmpptl(ii,ij)
+         nlcitl (jn) = ilcitl (ii,ij)     
+         nlcil       = nlcitl (jn)     
+         nlcjtl (jn) = ilcjtl (ii,ij)     
+         nlcjl       = nlcjtl (jn)
+         nbondjl = -1                                    ! general case
+         IF( jn   >  isplt          )   nbondjl = 0      ! first row of processor
+         IF( jn   >  (jsplt-1)*isplt )  nbondjl = 1     ! last  row of processor
+         IF( jsplt == 1             )   nbondjl = 2      ! one processor only in j-direction
+         ibonjtl(jn) = nbondjl
+         
+         nbondil = 0                                     ! 
+         IF( MOD( jn, isplt ) == 1 )   nbondil = -1      !
+         IF( MOD( jn, isplt ) == 0 )   nbondil =  1      !
+         IF( isplt            == 1 )   nbondil =  2      ! one processor only in i-direction
+         ibonitl(jn) = nbondil
+         
+         nldil =  1   + jpreci
+         nleil = nlcil - jpreci
+         IF( nbondil == -1 .OR. nbondil == 2 )   nldil = 1
+         IF( nbondil ==  1 .OR. nbondil == 2 )   nleil = nlcil
+         nldjl =  1   + jprecj
+         nlejl = nlcjl - jprecj
+         IF( nbondjl == -1 .OR. nbondjl == 2 )   nldjl = 1
+         IF( nbondjl ==  1 .OR. nbondjl == 2 )   nlejl = nlcjl
+         nlditl(jn) = nldil
+         nleitl(jn) = nleil
+         nldjtl(jn) = nldjl
+         nlejtl(jn) = nlejl
+      END DO
+
+      DEALLOCATE(iimpptl)
+      DEALLOCATE(ijmpptl)
+      DEALLOCATE(ilcitl)
+      DEALLOCATE(ilcjtl)
+
+   END SUBROUTINE sub_dom
+
+END MODULE prtctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/step.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/step.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/step.F90	(revision 4536)
@@ -0,0 +1,105 @@
+MODULE step
+   !!======================================================================
+   !!                       ***  MODULE step  ***
+   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   stp            : OPA system time-stepping
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE ldftra_oce
+   USE in_out_manager  ! I/O manager
+   USE lbclnk
+   USE trcdia
+   USE daymod          ! calendar                         (day     routine)
+   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
+   USE dtadyn          ! Lecture and interpolation of the dynamical fields
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
+   USE trcrst          ! restart for passive tracers
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC stp            ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE stp( kstp )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp  ***
+      !!                      
+      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
+      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
+      !!              - Tme stepping  of TRC (passive tracer eqs.)
+      !! 
+      !! ** Method  : -1- Update forcings and data  
+      !!              -2- Update ocean physics 
+      !!              -3- Compute the t and s trends 
+      !!              -4- Update t and s 
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
+      !!              -8- Outputs and diagnostics
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  add a first output record
+      !!        !  96-04  (G. Madec)  introduction of dynspg
+      !!        !  96-04  (M.A. Foujols)  introduction of passive tracer
+      !!   8.0  !  97-06  (G. Madec)  new architecture of call
+      !!   8.2  !  97-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+      !!   8.2  !  99-02  (G. Madec, N. Grima)  hpg implicit
+      !!   8.2  !  00-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+      !!   9.0  !  02-06  (G. Madec)  free form, suppress macro-tasking
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kstp   ! ocean time-step index
+
+      !! * local declarations
+      INTEGER ::   indic    ! error indicator if < 0
+      !! ---------------------------------------------------------------------
+
+      indic = 1                    ! reset to no error condition
+
+      CALL day( kstp )             ! Calendar
+
+      CALL dta_dyn( kstp )          ! Interpolation of the dynamical fields
+
+#if defined key_passivetrc
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                             CALL trc_stp( kstp, indic)           ! time-stepping
+
+
+#endif
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control, diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !                                            ! Time loop: control and print
+                       CALL stp_ctl( kstp )
+
+
+   END SUBROUTINE stp
+
+   !!======================================================================
+END MODULE step
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/stpctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/stpctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/stpctl.F90	(revision 4536)
@@ -0,0 +1,71 @@
+MODULE stpctl
+   !!==============================================================================
+   !!                       ***  MODULE  stpctl  ***
+   !! Ocean run control :  gross check of the ocean time stepping
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   stp_ctl      : Control the run
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC stp_ctl           ! routine called by step.F90
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE stp_ctl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE stp_ctl  ***
+      !!                     
+      !! ** Purpose :   Control the run
+      !!
+      !! ** Method  : - Save the time step in numstp
+      !!              - Print it each 50 time steps
+      !!              - Print solver statistics in numsol 
+      !!              - Stop the run IF problem for the solver ( indec < 0 )
+      !!
+      !! History :
+      !!        !  91-03  ()
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)
+      !!        !  97-06  (A.M. Treguier)
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !!----------------------------------------------------------------------
+      !!   OPA 9.0 , LOCEAN-IPSL  (2005)
+      !!   $Header$
+      !!   This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'stp_ctl : time-stepping control'
+         WRITE(numout,*) '~~~~~~~'
+         ! open time.step file
+         CALL ctlopn( numstp, 'time.step', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+      ENDIF
+
+      ! save the current time step in numstp
+      ! ------------------------------------
+      IF(lwp) WRITE(numstp,9100) kt
+      IF(lwp) REWIND(numstp)
+9100  FORMAT(1x, i8)
+
+
+   END SUBROUTINE stp_ctl
+
+   !!======================================================================
+END MODULE stpctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/vectopt_loop_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/vectopt_loop_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OFF_SRC/vectopt_loop_substitute.h90	(revision 4536)
@@ -0,0 +1,18 @@
+   !!----------------------------------------------------------------------
+   !!                   ***  vectopt_loop_substitute  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute the inner loop starting and inding indices 
+   !!      to allow unrolling of do-loop using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_vectopt_loop
+#  define fs_2     1
+#  define fs_jpim1 jpi
+#else
+#  define fs_2     2
+#  define fs_jpim1 jpim1
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diadimg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 4536)
@@ -0,0 +1,181 @@
+MODULE diadimg
+   !!======================================================================
+   !!                     ***  MODULE  diadimg  ***
+   !! Ocean diagnostics :  write ocean output files in dimg direct access format (mpp)
+   !!=====================================================================
+# if defined key_dimgout
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dia_wri_dimg            ! called by trd_mld (eg)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+  SUBROUTINE dia_wri_dimg(cd_name, cd_text, ptab, klev, cd_type , ksubi )
+    !!-------------------------------------------------------------------------
+    !!        *** ROUTINE dia_wri_dimg ***
+    !!
+    !! ** Purpose : write ptab in the dimg file cd_name, with comment cd_text.
+    !!       ptab has klev x 2D fields
+    !!
+    !! ** Action :
+    !!       Define header variables from the config parameters
+    !!       Open the dimg file on unit inum = 14 ( IEEE I4R4 file )
+    !!       Write header on record 1
+    !!       Write ptab on the following klev records
+    !!
+    !! History :
+    !!   03-12 (J.M. Molines ) : Original. Replace ctlopn, writn2d
+    !!---------------------------------------------------------------------------
+    !! * Arguments
+    CHARACTER(len=*),INTENT(in) ::   &
+         &                            cd_name,  &  ! dimg file name
+         &                            cd_text      ! comment to write on record #1
+    INTEGER, INTENT(in) ::            klev         ! number of level in ptab to write
+    REAL(wp),INTENT(in), DIMENSION(:,:,:) :: ptab  ! 3D array to write 
+    CHARACTER(LEN=1),INTENT(in) ::    cd_type      ! either 'T', 'W' or '2' , depending on the vertical
+    !                                              ! grid for ptab. 2 stands for 2D file
+    INTEGER, INTENT(in), OPTIONAL, DIMENSION(klev) :: ksubi 
+
+    !! * Local declarations
+    INTEGER :: jk, jn           ! dummy loop indices
+    INTEGER :: irecl4,             &    ! record length in bytes
+         &       inum,             &    ! logical unit (set to 14)
+         &       irec                   ! current record to be written
+    REAL(sp)                    :: zdx,zdy,zspval,zwest,ztimm
+    REAL(sp)                    :: zsouth
+    REAL(sp),DIMENSION(jpi,jpj) :: z42d        ! 2d temporary workspace (sp)
+    REAL(sp),DIMENSION(jpk)     :: z4dep       ! vertical level (sp)
+
+    CHARACTER(LEN=80) :: clname                ! name of file in case of dimgnnn
+    CHARACTER(LEN=4) :: clver='@!01'           ! dimg string identifier
+    !!---------------------------------------------------------------------------
+
+    !! * Initialisations
+
+    irecl4 = MAX(jpi*jpj*sp , 84+18*sp + (jpk+8)*jpnij*sp  )
+    inum = 14
+
+    zspval=0.0_sp    ! special values on land
+    !  the 'numerical' grid is described. The geographical one is in a grid file
+    zdx=1._sp
+    zdy=1._sp
+    zsouth=njmpp * 1._sp
+    zwest=nimpp * 1._sp
+    !  time in days since the historical begining of the run (nit000 = 0 ) 
+    ztimm=adatrj
+
+    SELECT CASE ( cd_type )
+
+    CASE ( 'T')
+       z4dep(:)=gdept_0(:)
+
+    CASE ( 'W' )
+       z4dep(:)=gdepw_0(:)
+
+    CASE ( '2' )
+       z4dep(1:klev) =(/(jk, jk=1,klev)/)
+
+    CASE ( 'I' )
+       z4dep(1:klev) = ksubi(1:klev)
+
+    CASE DEFAULT
+       IF(lwp) WRITE(numout,*) ' E R R O R : bad cd_type in dia_wri_dimg '
+       STOP 'dia_wri_dimg'
+
+    END SELECT
+
+    IF ( ln_dimgnnn  ) THEN
+       WRITE(clname,'(a,a,i3.3)') TRIM(cd_name),'.',narea
+       OPEN (inum, FILE=clname, FORM='UNFORMATTED', ACCESS='DIRECT', RECL=irecl4 )
+       WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
+            &     jpi,jpj, klev, 1 , 1 ,            &
+            &     zwest, zsouth, zdx, zdy, zspval,  &
+            &     z4dep(1:klev),                    &
+            &     ztimm,                            &
+            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
+            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
+
+       !! * Write klev levels
+       IF ( cd_type == 'I' ) THEN
+
+          DO jk = 1, klev
+             irec =1 + jk
+             z42d(:,:) = ptab(:,:,ksubi(jk))
+             WRITE(inum,REC=irec)  z42d(:,:)
+          END DO
+       ELSE
+          DO jk = 1, klev
+             irec =1 + jk
+             z42d(:,:) = ptab(:,:,jk)
+             WRITE(inum,REC=irec)  z42d(:,:)
+          END DO
+       ENDIF
+    ELSE
+       !! Standard dimgproc (1 file per variable, all procs. write to this file )
+       !! * Open file
+       OPEN (inum, FILE=cd_name, FORM='UNFORMATTED', ACCESS='DIRECT', RECL=irecl4 )
+
+       !! * Write header on record #1
+       IF(lwp) WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
+            &     jpi,jpj, klev*jpnij, 1 , 1 ,            &
+            &     zwest, zsouth, zdx, zdy, zspval,  &
+            &     (z4dep(1:klev),jn=1,jpnij),       &
+            &     ztimm,                            &
+            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
+            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
+
+       !! * Write klev levels
+       IF ( cd_type == 'I' ) THEN
+
+          DO jk = 1, klev
+             irec =1 + klev * (narea -1) + jk
+             z42d(:,:) = ptab(:,:,ksubi(jk))
+             WRITE(inum,REC=irec)  z42d(:,:)
+          END DO
+       ELSE
+          DO jk = 1, klev
+             irec =1 + klev * (narea -1) + jk
+             z42d(:,:) = ptab(:,:,jk)
+             WRITE(inum,REC=irec)  z42d(:,:)
+          END DO
+       ENDIF
+    ENDIF
+
+    !! * Close the file
+    CLOSE(inum)
+
+  END SUBROUTINE dia_wri_dimg
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dia_wri_dimg( cd_name, cd_exper, ptab, klev, cd_type )
+      REAL, DIMENSION(:,:,:) :: ptab
+      INTEGER :: klev
+      CHARACTER(LEN=80) :: cd_name, cd_exper,cd_type
+      WRITE(*,*) ' This print must never occur ', cd_name, cd_exper,ptab, klev, cd_type
+      WRITE(*,*) ' this routine is here just for compilation '
+   END SUBROUTINE dia_wri_dimg
+# endif
+   !!======================================================================
+END MODULE diadimg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diafwb.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 4536)
@@ -0,0 +1,478 @@
+MODULE diafwb
+   !!======================================================================
+   !!                       ***  MODULE  diafwb  ***
+   !! Ocean diagnostics: freshwater budget
+   !!======================================================================
+#if ( defined key_orca_r2 || defined  key_orca_r4 ) && ! defined key_dynspg_rl && ! defined key_coupled
+   !!----------------------------------------------------------------------
+   !!   NOT "key_dynspg_rl" and "key_orca_r2 or 4"
+   !!----------------------------------------------------------------------
+   !!   dia_fwb     : freshwater budget for global ocean configurations
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE flxrnf          ! ???
+   USE ocesbc          ! ???
+   USE blk_oce         ! ???
+   USE flxblk          ! atmospheric surface quantity
+   USE lib_mpp         ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_fwb    ! routine called by step.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diafwb = .TRUE.    !: fresh water budget flag
+
+   !! * Module variables
+   REAL(wp) ::   &
+      a_emp , a_precip, a_rnf,   &
+      a_sshb, a_sshn, a_salb, a_saln,   &
+      a_aminus, a_aplus
+   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"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DIA/diafwb.F90,v 1.11 2007/06/29 17:01:51 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_fwb( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_fwb  ***
+      !!     
+      !! ** Purpose :
+      !!	
+      !! ** Method :
+      !!	
+      !! 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
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      CHARACTER (len=32) ::  clname
+      INTEGER :: inum             ! temporary logical unit
+      INTEGER :: ji, jj, jk, jt   ! dummy loop indices
+      INTEGER :: ii0, ii1, ij0, ij1
+      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, zempnew
+      !!----------------------------------------------------------------------
+
+      ! Mean global salinity
+      zsm0 = 34.72654
+
+      ! To compute emp mean value mean emp
+
+      IF( kt == nit000 ) THEN
+
+         a_emp    = 0.e0
+         a_precip = 0.e0
+         a_rnf    = 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
+         a_aminus = 0.e0
+         a_aplus  = 0.e0
+         ! 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 + ( sb(ji,jj,jk) - zsm0 ) * zwei
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( a_salb )      ! sum over the global domain
+      ENDIF
+      
+      a_emp    = SUM( e1t(:,:) * e2t(:,:) * emp   (:,:) * tmask_i(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( a_emp    )       ! sum over the global domain
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+      a_precip = SUM( e1t(:,:) * e2t(:,:) * watm  (:,:) * tmask_i(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( a_precip )       ! sum over the global domain
+#endif
+      a_rnf    = SUM( e1t(:,:) * e2t(:,:) * runoff(:,:) * tmask_i(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( a_rnf    )       ! sum over the global domain
+
+      IF( aminus /= 0.e0 ) a_aminus = a_aminus + ( MIN( aplus, aminus ) / aminus )
+      IF( aplus  /= 0.e0 ) a_aplus  = a_aplus  + ( MIN( aplus, aminus ) / aplus  )
+
+      IF( kt == nitend ) THEN
+         a_sshn = 0.e0
+         a_saln = 0.e0
+         zarea = 0.e0
+         zvol  = 0.e0
+         zempnew = 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 + ( sn(ji,jj,jk) - 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
+         
+         a_aminus = a_aminus / ( nitend - nit000 + 1 )
+         a_aplus  = a_aplus  / ( nitend - nit000 + 1 )
+
+         ! Conversion in m3
+         a_emp    = a_emp * rdttra(1) * 1.e-3 
+         a_precip = a_precip * rdttra(1) * 1.e-3 / rday
+         a_rnf    = a_rnf * rdttra(1) * 1.e-3
+         
+         ! Alpha1=Alpha0-Rest/(Precip+runoff)
+         !  C A U T I O N : precipitations are negative !!     
+         
+         zempnew = 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 = 139   ;   ii1 = 139
+            ij0 = 102   ;   ij1 = 102
+            !                                        ! =======================
+         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), mi1(ii1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, 18 
+                  zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
+                  zs = 0.5 * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(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 = 102   ;   ij1 = 102
+            !                                        ! =======================
+         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), mi1(ii1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, 23 
+                  zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
+                  zs = 0.5 * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(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 = 161   ;   ii1 = 161
+            ij0 = 88    ;   ij1 = 88 
+            !                                        ! =======================
+         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), mi1(ii1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, 15 
+                  zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
+                  zs = 0.5 * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(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 DEFAULT                                !    ORCA R05 or R025
+            !                                        ! =======================
+            CALL ctl_stop( ' dia_fwb Not yet implemented in ORCA_R05 or R025' )
+            ! 
+         END SELECT
+         ! 
+         DO ji = mi0(ii0), mi1(ii1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, 20
+                  zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
+                  zs = 0.5 * ( sn(ji,jj,jk) + sn(ji+1,jj,jk) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(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 .AND. zflxo(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)
+            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 
+      ! --------------------------
+
+      IF ( kt == nitend .AND. cp_cfg == "orca" ) THEN
+
+         clname = 'STRAIT.dat'
+         CALL ctlopn( inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, lwp, 1 )
+         WRITE(inum,*)
+         WRITE(inum,*)    'Net freshwater budget '
+         WRITE(inum,9010) '  emp    = ',a_emp,   ' m3 =', a_emp   /(FLOAT(nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,9010) '  precip = ',a_precip,' m3 =', a_precip/(FLOAT(nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,9010) '  a_rnf  = ',a_rnf,   ' m3 =', a_rnf   /(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,*)    'Coeff : '
+         WRITE(inum,9030) '  Alpha+   =  ', a_aplus
+         WRITE(inum,9030) '  Alpha-   =  ', a_aminus
+         WRITE(inum,*)
+         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
+
+ 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,F8.2,A)
+
+   END SUBROUTINE dia_fwb
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Dummy Module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diafwb = .FALSE.    !: fresh water budget flag
+CONTAINS
+   SUBROUTINE dia_fwb( kt )        ! Empty routine
+      WRITE(*,*) 'dia_fwb: : You should not have seen this print! error?', kt
+   END SUBROUTINE dia_fwb
+#endif
+
+   !!======================================================================
+END MODULE diafwb
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diagap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diagap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diagap.F90	(revision 4536)
@@ -0,0 +1,286 @@
+MODULE diagap
+   !!======================================================================
+   !!                       ***  MODULE  diagap  ***
+   !! Ocean diagnostics : computation of model-data tracer gap
+   !!======================================================================
+#if defined key_diagap
+   !!----------------------------------------------------------------------
+   !!   'key_diagap' :                           model-data gap diagnostics
+   !!----------------------------------------------------------------------
+   !!   dia_gap      : model and data level mean temperature and salinity
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE dtatem          ! ???
+   USE dtasal          ! ???
+   USE daymod          ! calendar
+   USE dianam          ! build name of file (routine)
+   USE lib_mpp         ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_gap     ! called in step.F90 module
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diagap = .TRUE.   !: model-data diagnostics flag
+
+   !! * Module variables
+   INTEGER ::                 &
+      ngap  ,                 &  ! time step frequency
+      nprg                       ! switch for control print
+   ! netcdf files and index common
+   INTEGER ::   &
+      nhoridg, ndepidg,             &
+      ndex(1)
+   REAL(wp) ::     &
+      vol                        ! total ocean volume
+   REAL(wp), DIMENSION(jpk) ::   &
+      volk , volkr,           &  ! level ocean volume and its inverse
+      tdtag, sdtag,           &  ! level mean data temperature & salinity
+      tmodg, smodg               ! level mean model temperature & salinity
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_gap( kt )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dia_gap  ***
+      !!
+      !! ** Purpose :   Compute model and data level mean T and S profiles
+      !!      and output it in numgap (NetCDF or direct access file)
+      !!
+      !! ** Method :
+      !!         tracers (model) : tn, sn
+      !!         tracers (data)  : t_dta, s_dta
+      !!         difference between model and data tracers
+      !!         variance between model and data tracers
+      !!
+      !! ** Action  :   output in file numgap
+      !!
+      !! History :
+      !!   6.0  !  91-10  (G. Madec)  Original code
+      !!   7.0  !  92-07  (M. Imbard)  Add variance and mpp staff
+      !!   8.5  !  02-07  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Arguments
+      INTEGER, INTENT(in) ::   kt           ! ocean time-step index
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      INTEGER ::   it
+      CHARACTER (len=40) ::   clhstnam
+      CHARACTER (len=40) ::   clop
+      REAL(wp) ::   zbt, zdt    ! temporary scalar
+      REAL(wp) ::   zsto, zout, zmax, zjulian
+      REAL(wp), DIMENSION(jpi) ::   zfoo
+      REAL(wp), DIMENSION(jpj) ::   zloo
+
+      NAMELIST/namgap/ ngap, nprg
+      !!----------------------------------------------------------------------
+
+
+      ! 0. initialization
+      ! -----------------
+
+      zdt = rdt
+      IF( nacc == 1 )   zdt = rdtmin
+
+      IF( kt == nit000 ) THEN
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dia_gap : level mean model-data gap'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+         ! Read diagap parameters in namelist namgap
+         ngap = 15
+         nprg = 15
+
+         REWIND( numnam )
+         READ( numnam, namgap )
+
+         IF(lwp) WRITE(numout,*) '          time step frequency for gap     ngap  = ',ngap
+         IF(lwp) WRITE(numout,*) '          switch for control print gap    nprg  = ',nprg
+
+         ! horizontal slab volume (tmask_i to take into account only interior ocean domain)
+         volk(:) = 0.e0
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) * tmask_i(ji,jj)
+                  volk(jk) = volk(jk) + tmask(ji,jj,jk) * zbt
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( volk, jpk )   ! sum over the global domain
+
+         volkr(:) = 0.e0
+         DO jk = 1, jpk
+            IF( volk(jk) /= 0.e0 )   volkr(jk) = 1.e0 / volk(jk)
+         END DO
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '     volume of each horizontal slab (km3) :'
+            DO jk = 1, jpkm1
+               WRITE(numout,9010) jk, volk(jk) * 1.e-9
+            END DO
+         ENDIF
+9010     FORMAT( 9X, 'level ', i3, f15.3 )
+
+         ! basin volume
+         vol = 0.e0
+         DO jk = 1, jpkm1
+            vol = vol + volk(jk)
+         END DO
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '     basin volume : ',vol*1.e-9, '  km3'
+
+         ! OPEN netcdf file 
+
+         ! Define frequency of output and means
+         zsto = ngap * zdt
+         clop = "ave(x)"
+         zout = ngap * zdt
+         zmax = FLOAT( nitend - nit000 + 1 ) * zdt
+         zfoo(1:jpi) = 0.e0
+         zloo(1:jpj) = 0.e0
+
+         ! Compute julian date from starting date of the run
+
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+
+         CALL dia_nam( clhstnam, ngap, 'diagap' )
+         IF(lwp) WRITE(numout,*) 'Name of diagap NETCDF file ', clhstnam
+         ! Horizontal grid : zphi()
+         CALL histbeg( clhstnam, 1, zfoo, 1, zloo,   &
+                       1, 1, 1, 1, 0, zjulian, zdt, nhoridg, numgap, domain_id=nidom )
+         ! Vertical grids : gdept, gdepw
+         CALL histvert( numgap, "deptht", "Vertical T levels",   &
+                         "m", jpk, gdept_0, ndepidg )
+
+         ! define fields to be stored
+         ! mo(temp/sali)(da/mo/va): mean ocean temperature/salinity data/model/differences
+
+          CALL histdef( numgap, "motempda", "Mean Data Temperature","C",   &
+                        1, 1, nhoridg, jpk, 1, jpk, ndepidg, 32, clop,   &
+                        zsto,zout )
+          CALL histdef(numgap, "mosalida", "Mean Data Salinity","PSU",   &
+                        1, 1, nhoridg, jpk, 1, jpk, ndepidg, 32, clop,   &
+                        zsto,zout )
+          CALL histdef(numgap, "motempmo", "Mean Model Temperature","C",   &
+                        1, 1, nhoridg, jpk, 1, jpk, ndepidg, 32, clop,   &
+                        zsto,zout )
+          CALL histdef(numgap, "mosalimo", "Mean Model Salinity","PSU",   &
+                        1, 1, nhoridg, jpk, 1, jpk, ndepidg, 32, clop,   &
+                        zsto,zout )
+          CALL histend( numgap )
+          ndex(1) = 0
+      ENDIF
+
+
+      ! 1. horizontal averaged
+      ! ----------------------
+
+      IF( MOD( kt, ngap ) == 0 ) THEN
+
+         ! initialization
+         tdtag(:) = 0.e0
+         sdtag(:) = 0.e0
+         tmodg(:) = 0.e0
+         smodg(:) = 0.e0
+         
+         !  c a u t i o n  : use of tmask_i : average over the interior domain only
+         
+         ! sum
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+              DO ji = 1, jpi
+                zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) * tmask_i(ji,jj)
+                tdtag(jk) = tdtag(jk) + zbt * t_dta(ji,jj,jk) * volkr(jk)
+                sdtag(jk) = sdtag(jk) + zbt * s_dta(ji,jj,jk) * volkr(jk)
+                tmodg(jk) = tmodg(jk) + zbt * tn  (ji,jj,jk) * volkr(jk)
+                smodg(jk) = smodg(jk) + zbt * sn  (ji,jj,jk) * volkr(jk)
+              END DO  
+            END DO  
+         END DO
+
+
+         ! 2. Basin averaged
+         ! -----------------
+         
+         DO jk = 1, jpkm1
+            tdtag(jpk) = tdtag(jpk) + tdtag(jk) * volk(jk) / vol
+            sdtag(jpk) = sdtag(jpk) + sdtag(jk) * volk(jk) / vol
+            tmodg(jpk) = tmodg(jpk) + tmodg(jk) * volk(jk) / vol
+            smodg(jpk) = smodg(jpk) + smodg(jk) * volk(jk) / vol
+         END DO  
+          IF( lk_mpp)   CALL mpp_sum( tdtag, jpk )   ! sum over the global domain
+          IF( lk_mpp)   CALL mpp_sum( sdtag, jpk )
+          IF( lk_mpp)   CALL mpp_sum( tmodg, jpk )
+          IF( lk_mpp)   CALL mpp_sum( smodg, jpk )
+
+          ! 3.  Averaged output in file numgap
+          ! ----------------------------======
+
+          IF( MOD( kt, nprg ) == 0 ) THEN
+              IF(lwp) THEN
+                  WRITE(numout,*) 'dia_gap: time step = ', kt, 'model - data'
+                  WRITE(numout,9300)
+
+                  DO jk = 1, jpk
+                    WRITE(numout,9310) tdtag(jk), tmodg(jk), tdtag(jk) - tmodg(jk), jk, fsdept(1,1,jk),   &
+                                       sdtag(jk), smodg(jk), sdtag(jk) - smodg(jk)
+                  END DO  
+              ENDIF
+          ENDIF
+
+ 9300     FORMAT('  T-data  T-model    diff.   level  depth    S-data  S-model    diff.' )
+ 9310     FORMAT( 3(f8.3,1x),i5,f9.0,2x,3(f8.3,1x) )
+
+          ! Output in file numgap
+
+          ! Netcdf write
+
+          IF (lwp ) THEN   ! Ok even in mpp after the call to mpp_sum
+             it = kt - nit000 + 1       ! define time axis
+             CALL histwrite( numgap, "motempda", it, tdtag, jpk, ndex )
+             CALL histwrite( numgap, "mosalida", it, sdtag, jpk, ndex )
+             CALL histwrite( numgap, "motempmo", it, tmodg, jpk, ndex )
+             CALL histwrite( numgap, "mosalimo", it, smodg, jpk, ndex )
+          END IF
+      ENDIF
+
+      ! Closing numgap file
+
+      IF( kt == nitend ) THEN
+         CALL histclo( numgap )      !   Netcdf file
+      ENDIF 
+
+   END SUBROUTINE dia_gap
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Dummy module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diagap = .FALSE.    !: diagap flag
+CONTAINS
+   SUBROUTINE dia_gap( kt )           ! Dummy routine
+      WRITE(*,*) 'dia_gap: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_gap
+#endif
+
+   !!======================================================================
+END MODULE diagap
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahdy.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahdy.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahdy.F90	(revision 4536)
@@ -0,0 +1,267 @@
+MODULE diahdy
+   !!======================================================================
+   !!                       ***  MODULE  diahdy  ***
+   !! Ocean diagnostics : computation the dynamical heigh
+   !!======================================================================
+#if   defined key_diahdy   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_diahdy' :                          dynamical heigh diagnostics
+   !!----------------------------------------------------------------------
+   !!   dia_hdy      : dynamical heigh computation
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_hdy     ! called in step.F90 module
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diahdy = .TRUE.   !: dynamical heigh flag
+
+   !! * Module variables
+   REAL(wp), DIMENSION(jpk) ::   &
+      rhosp         ! ???
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      hdy           ! dynamical heigh
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE dia_hdy ( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_hdy  ***
+      !!
+      !! ** Purpose :   Computes the dynamical heigh
+      !!
+      !! ** Method  : Millero + Poisson
+      !!
+      !! References : 
+      !!	A. E. Gill, atmosphere-ocean dynamics 7.7 pp 215
+      !!
+      !! History :
+      !!        !  9x-xx (P. Delecluse, C. Perigaud)  Original code
+      !!        !  93-10  (C. Perigaud)  a trapezoidal vertical integration 
+      !!                                 consistent WITH the code
+      !!        !  93-12  (G. Madec M. Imbard)
+      !!        !  96-03  (N. Ferry)  integration at t-points
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jk
+      INTEGER :: ihdsup, ik
+
+      REAL(wp) :: zgdsup, za, zb, zciint, zfacto, zhd
+      REAL(wp) :: zp, zh, zt, zs, zxk, zq, zsr, zr1, zr2, zr3, zr4
+      REAL(wp) :: ze, zbw, zc, zd, zaw, zb1, za1, zkw, zk0
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zsva
+      REAL(wp), DIMENSION(jpk)         :: zwkx, zwky, zwkz
+      REAL(wp) :: fsatg
+      REAL(wp) :: pfps, pfpt, pfphp  
+
+      ! Adiabatic laspse rate fsatg, defined as the change of temperature
+      ! per unit pressure for adiabatic change of pressure of an element
+      ! of seawater (bryden,h.,1973,deep-sea res.,20,401-408).
+      ! units:
+      !      pressure        pfphp    decibars
+      !      temperature     pfpt     deg celsius (ipts-68)
+      !      salinity        pfps     (ipss-78)
+      !      adiabatic       fsatg    deg. c/decibar
+      ! checkvalue: atg=3.255976e-4 c/dbar for pfps=40 (ipss-78),
+      ! pfpt=40 deg c, pfphp=10000 decibars
+      
+      fsatg(pfps,pfpt,pfphp)   &
+         = (((-2.1687e-16*pfpt+1.8676e-14)*pfpt-4.6206e-13)*pfphp    &
+         +((2.7759e-12*pfpt-1.1351e-10)*(pfps-35.)+((-5.4481e-14*pfpt    &
+         +8.733e-12)*pfpt-6.7795e-10)*pfpt+1.8741e-8))*pfphp    &
+         +(-4.2393e-8*pfpt+1.8932e-6)*(pfps-35.)    &
+         +((6.6228e-10*pfpt-6.836e-8)*pfpt+8.5258e-6)*pfpt+3.5803e-5
+      !!----------------------------------------------------------------------
+
+      ! 1. height dynamic
+      ! -----------------
+      ! depth for reference
+
+      zgdsup = 1500.
+      
+      ! below for hdyn levitus
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dia_hdy : computation of dynamical heigh'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+         IF( .NOT. ln_zco )   &
+              &   CALL ctl_stop( '          ln_zps or ln_sco, Dynamical height diagnostics not yet implemented' )
+         DO jk = 1, jpk
+            IF( gdepw_0(jk) > zgdsup ) GOTO 110
+         END DO
+         IF(lwp) WRITE(numout,*)'problem zgdsup greater than gdepw(jpk)'
+         STOP 'dia_hdy'
+110      CONTINUE
+         ihdsup = jk - 1
+         IF(lwp) WRITE(numout,*)' ihdsup = ', ihdsup
+
+         ! Interpolation coefficients for zgdsup-gdepw(ihdsup) layer
+
+         za = gdepw_0(ihdsup  )
+         zb = gdepw_0(ihdsup+1)
+         IF( za > zgdsup .OR. zb < zgdsup ) THEN
+            IF(lwp) WRITE(numout,*) za, zb, ihdsup, zgdsup
+            IF(lwp) WRITE(numout,*) ' bad ihdsup'
+            STOP
+         ENDIF
+         
+         zciint = (zgdsup - za) / (zb - za)
+
+         ! Computes the specific volume reference in situ temperature
+         
+         DO jk = 1, jpk
+            zp = 0.e0
+            zh = gdept_0(jk)
+            zt = 0.e0
+            zs = 35.
+            zxk= zh * fsatg( zs, zt, zp )
+            zt = zt + 0.5 * zxk
+            zq = zxk
+            zp = zp + 0.5 * zh
+            zxk= zh*fsatg( zs, zt, zp )
+            zt = zt + 0.29289322 * ( zxk - zq )
+            zq = 0.58578644 * zxk + 0.121320344 * zq
+            zxk= zh * fsatg( zs, zt, zp )
+            zt = zt + 1.707106781 * ( zxk - zq )
+            zq = 3.414213562 * zxk - 4.121320344 * zq
+            zp = zp + 0.5 * zh
+            zxk= zh * fsatg( zs, zt, zp )
+            zwkx(jk) = zt + ( zxk - 2.0 * zq ) / 6.0
+         END DO
+
+         ! In situ density (add the compression terms)
+
+         DO jk = 1, jpk
+            zt = zwkx(jk)
+            zs = 35.
+            ! square root salinity
+            zsr = sqrt( abs( zs ) )
+            zwky(jk) = zsr
+            ! compute density pure water at atm pressure
+            zr1= ((((6.536332e-9*zt-1.120083e-6)*zt+1.001685e-4)*zt   &
+               -9.095290e-3)*zt+6.793952e-2)*zt+999.842594
+            ! seawater density atm pressure
+            zr2= (((5.3875e-9*zt-8.2467e-7)*zt+7.6438e-5)*zt   &
+               -4.0899e-3)*zt+8.24493e-1
+            zr3= (-1.6546e-6*zt+1.0227e-4)*zt-5.72466e-3
+            zr4= 4.8314e-4
+            zwkz(jk)= (zr4*zs + zr3*zsr + zr2)*zs + zr1
+         END DO
+
+         DO jk = 1, jpk
+            zt = zwkx(jk)
+            zs = 35.
+            zsr= zwky(jk)
+            zh = gdept_0(jk)
+
+            ze = ( 9.1697e-11*zt+2.0816e-9 ) *zt-9.9348e-8
+            zbw= ( 5.2787e-9*zt-6.12293e-7 ) * zt+8.50935e-6
+            zb = zbw + ze * zs
+
+            zd = 1.91075e-4
+            zc = (-1.6078e-6*zt-1.0981e-5)*zt+2.2838e-3
+            zaw= ((-5.77905e-7*zt+1.16092e-4)*zt+1.43713e-3)*zt+3.239908
+            za = ( zd*zsr + zc)*zs + zaw
+
+            zb1= (-5.3009e-3*zt+1.6483e-1)*zt+7.944e-1
+            za1= ((-6.1670e-4*zt+1.09987e-1)*zt-6.03459)*zt+546.746
+            zkw= (((-5.155288e-4*zt+1.360477e-1)*zt-23.27105)*zt   &
+                +1484.206)*zt+196522.1
+            zk0= (zb1*zsr + za1)*zs + zkw
+            ! evaluate pressure polynomial
+            zwkz(jk) = zwkz(jk) / ( 1.0 - zh / ( zk0+zh*(za+zb*zh) ) )
+         END DO
+
+         DO jk = 1, jpk
+            rhosp(jk) = zwkz(jk)
+         END DO
+      ENDIF
+
+      ! Computes the specific volume anomaly
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tmask(ji,jj,jk) /= 0. ) THEN
+                  zsva(ji,jj,jk) = ( rau0*rhd(ji,jj,jk)+rau0 -rhosp(jk) ) / rhosp(jk)
+               ELSE
+                  zsva(ji,jj,jk)=0.
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! zfacto coefficient to cmg
+      
+      ! zfacto= 1.  e+2
+      !           mg->cmg
+      zfacto = 1.0 * 1.e2
+      
+      ! Fisrt compute at depth ik=ihdsup
+      
+      ik = ihdsup
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zhd = zfacto * zciint * e3t_0(ik) * zsva(ji,jj,ik)
+            hdy(ji,jj,ik) = zhd * tmask(ji,jj,ik) * tmask(ji,jj,ik-1)
+         END DO
+      END DO
+      
+      ! Then compute other terms except level jk=1
+      
+      DO jk = ihdsup-1, 2, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zhd = hdy(ji,jj,jk+1) + zfacto * e3t_0(jk) * zsva(ji,jj,jk)
+               hdy(ji,jj,jk) = zhd * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      
+      ! Then compute other the last layer term jk=1
+      
+      ik = 1
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zhd = hdy(ji,jj,ik+1) + zfacto * e3t_0(ik) * zsva(ji,jj,ik)
+            hdy(ji,jj,ik) = zhd * tmask(ji,jj,ik)
+         END DO
+      END DO
+
+   END SUBROUTINE dia_hdy
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                       NO dynamic heigh diagnostics
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diahdy = .FALSE.   !: dynamical heigh flag
+CONTAINS
+   SUBROUTINE dia_hdy( kt )               ! Empty routine
+      WRITE(*,*) 'diahdy: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_hdy
+#endif
+
+   !!======================================================================
+END MODULE diahdy
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 4536)
@@ -0,0 +1,221 @@
+MODULE diahth
+   !!======================================================================
+   !!                       ***  MODULE  diahth  ***
+   !! Ocean diagnostics: thermocline and 20 degree depth
+   !!======================================================================
+#if   defined key_diahth   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_diahth' :                              thermocline depth diag.
+   !!----------------------------------------------------------------------
+   !!   dia_hth      : Compute diagnostics associated with the thermocline
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_hth    ! routine called by step.F90
+
+   !! * Shared module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_diahth = .TRUE.   !: thermocline-20d depths flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      hth  ,      &  !: depth of the max vertical temperature gradient (m)
+      hd20 ,      &  !: depth of 20 C isotherm (m)
+      hd28 ,      &  !: depth of 28 C isotherm (m)
+      htc3           !: heat content of first 300 m
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_hth( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_hth  ***
+      !!
+      !! ** Purpose :
+      !!      Computes the depth of strongest vertical temperature gradient
+      !!      Computes the depth of the 20 degree isotherm
+      !!      Computes the depth of the 28 degree isotherm
+      !!      Computes the heat content of first 300 m
+      !!
+      !! ** Method : 
+      !!
+      !! History :
+      !!        !  94-09  (J.-P. Boulanger)  Original code
+      !!        !  96-11  (E. Guilyardi)  OPA8 
+      !!        !  97-08  (G. Madec)  optimization
+      !!        !  99-07  (E. Guilyardi)  hd28 + heat content 
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!-------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jk         ! dummy loop arguments
+      INTEGER :: iid, iif, ilevel   ! temporary integers
+      INTEGER, DIMENSION(jpi) ::   idepth
+      INTEGER, DIMENSION(jpi,jpj) ::   ikc
+
+      REAL(wp) :: zd, zmoy              ! temporary scalars
+      REAL(wp), DIMENSION(jpi) ::   zmax
+      REAL(wp), DIMENSION(jpi,jpk) ::   zdzt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dia_hth : diagnostics of the thermocline depth'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+
+      ! -------------------------- !
+      !  Depth of the thermocline  !
+      ! -------------------------- !
+      ! The depth of the thermocline is defined as the depth of the 
+      ! strongest vertical temperature gradient
+      
+      DO jj = 1, jpj
+         
+         ! vertical gradient of temperature
+         DO jk = 2, jpkm1
+            zdzt(:,jk) = ( tn(:,jj,jk-1) - tn(:,jj,jk) ) / fse3w(:,jj,jk) * tmask(:,jj,jk)
+         END DO
+         
+         ! search the level of maximum vertical temperature gradient
+         zmax  (:) = 0.e0
+         idepth(:) = 1
+         DO jk = jpkm1, 2, -1
+            DO ji = 1, jpi
+               IF( zdzt(ji,jk) > zmax(ji) ) THEN
+                  zmax  (ji) = zdzt(ji,jk)
+                  idepth(ji) = jk
+               ENDIF
+            END DO
+         END DO
+
+         ! depth of the thermocline
+         DO ji = 1, jpi
+            hth(ji,jj) = fsdepw(ji,jj,idepth(ji))
+         END DO
+         
+      END DO
+
+
+      ! ----------------------- !
+      !  Depth of 20C isotherm  !
+      ! ----------------------- !
+
+      ! initialization to the number of ocean w-point mbathy
+      ! (cf dommsk, minimum value: 1)
+      ikc(:,:) = 1
+
+      ! search the depth of 20 degrees isotherm
+      ! ( starting from the top, last level above 20C, if not exist, = 1)
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tn(ji,jj,jk) >= 20. ) ikc(ji,jj) = jk
+            END DO
+         END DO
+      END DO
+      
+      ! Depth of 20C isotherm
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iid = ikc(ji,jj)
+            iif = mbathy(ji,jj)
+            IF( iid /= 1 ) THEN 
+               ! linear interpolation
+               zd =  fsdept(ji,jj,iid)   &
+                  + (    fsdept(ji,jj,iid+1) - fsdept(ji,jj,iid) )   &
+                  * ( 20.*tmask(ji,jj,iid+1) -     tn(ji,jj,iid) )   &
+                  / (        tn(ji,jj,iid+1) -     tn(ji,jj,iid)    &
+                  + (1.-tmask(ji,jj,1))                       )
+               ! bound by the ocean depth, minimum value, first T-point depth
+               hd20(ji,jj) = MIN( zd*tmask(ji,jj,1), fsdepw(ji,jj,iif))
+            ELSE 
+               hd20(ji,jj)=0.
+            ENDIF
+         END DO
+      END DO
+
+      ! ----------------------- !
+      !  Depth of 28C isotherm  ! 
+      ! ----------------------- !
+      
+      ! initialization to the number of ocean w-point mbathy
+      ! (cf dommsk, minimum value: 1)
+      ikc(:,:) = 1
+      
+      ! search the depth of 28 degrees isotherm
+      ! ( starting from the top, last level above 28C, if not exist, = 1)
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tn(ji,jj,jk) >= 28. ) ikc(ji,jj) = jk
+            END DO
+         END DO
+      END DO
+      
+      ! Depth of 28C isotherm
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iid = ikc(ji,jj)
+            iif = mbathy(ji,jj)
+            IF( iid /= 1 ) THEN 
+               ! linear interpolation
+               zd =  fsdept(ji,jj,iid)   &
+                  + (    fsdept(ji,jj,iid+1) - fsdept(ji,jj,iid) )   &
+                  * ( 28.*tmask(ji,jj,iid+1) -     tn(ji,jj,iid) )   &
+                  / (        tn(ji,jj,iid+1) -     tn(ji,jj,iid)    &
+                  + ( 1. - tmask(ji,jj,1) )  )
+               ! bound by the ocean depth, minimum value, first T-point depth
+               hd28(ji,jj) = MIN( zd*tmask(ji,jj,1), fsdepw(ji,jj,iif) )
+            ELSE 
+               hd28(ji,jj) = 0.
+            ENDIF
+         END DO
+      END DO
+
+      ! ----------------------------------------- !
+      !  Heat content of first 300 m (18 levels)  !
+      ! ----------------------------------------- !
+
+      htc3(:,:) = 0.e0
+      ilevel = 18
+      zmoy = rau0 * rcp * 0.5
+      
+      ! intregrate tn from surface to klevel
+
+      DO jk = 1, ilevel
+               htc3(:,:) = htc3(:,:)   &
+                         + zmoy * ( tn(:,:,jk) + tn(:,:,jk+1) ) * fse3w(:,:,jk) * tmask(:,:,jk)
+      END DO
+
+   END SUBROUTINE dia_hth
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_diahth = .FALSE.  !: thermocline-20d depths flag
+CONTAINS
+   SUBROUTINE dia_hth( kt )         ! Empty routine
+      WRITE(*,*) 'dia_hth: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_hth
+#endif
+
+   !!======================================================================
+END MODULE diahth
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/dianam.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/dianam.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/dianam.F90	(revision 4536)
@@ -0,0 +1,304 @@
+MODULE dianam
+   !!======================================================================
+   !!                       ***  MODULE  dianam  ***
+   !! Ocean diagnostics:  Builds output file name
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dia_nam       : Builds output file name
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_nam   ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_nam( cdfnam, kfreq, cdsuff )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_nam  ***
+      !!                   
+      !! ** Purpose :   Builds output file name
+      !!
+      !! ** Method  :   File name is a function of date and output frequency
+      !!      cdfnam=<cexper>_<clave>_<idtbeg>_<idtend>_grid_<cdsuff>
+      !!      <clave> = averaging frequency (DA, MO, etc...)
+      !!      <idtbeg>,<idtend> date of beginning and end of run
+      !!
+      !! History :
+      !!        !  99-02  (E. Guilyardi)  Creation for 30 days/month
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER (len=*), INTENT( out ) ::   cdfnam   ! file name
+      CHARACTER (len=*), INTENT( in  ) ::   cdsuff   ! ???
+      INTEGER,           INTENT( in  ) ::   kfreq    ! ???
+
+      !! * Local declarations
+      CHARACTER (len=2) ::   clave
+      CHARACTER (len=5) ::   clout
+      INTEGER :: jt                       ! dummy loop indices
+      INTEGER :: ig, ijjmm, iout          ! temporary integers
+      INTEGER :: iyear1, imonth1, iday1   !    "          "
+      INTEGER :: iyear2, imonth2, iday2   !    "          "
+      REAL(wp) ::  z5j, znbsec, zdate1, zdate2, zdrun, zdt   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' dia_nam: building output file name'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+
+      ! 0. Initialisation
+      ! -----------------
+
+      cdfnam = ''
+
+      !    number of seconds of the run
+
+      z5j = 5*rjjss
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+      zdrun = FLOAT( nitend - nit000 ) * zdt
+
+      !  date of beginning of run
+
+      iyear1  = ndastp/10000
+      imonth1 = ndastp/100 - iyear1*100
+      iday1   = ndastp - imonth1*100 - iyear1*10000
+      IF( nleapy == 1) THEN 
+         ijjmm=0
+         IF( MOD( iyear1, 4 ) == 0 ) THEN
+            DO jt = 1, imonth1-1
+               ijjmm = ijjmm + nbiss(jt)
+            END DO
+         ELSE
+            DO jt = 1, imonth1-1
+               ijjmm = ijjmm + nobis(jt)
+            END DO
+         ENDIF
+         ijjmm = ijjmm + (iyear1-1)/4
+         zdate1 = ( (iyear1-1)*365 + ijjmm +iday1-1 ) * rjjss   
+      ELSE IF( nleapy == 0 ) THEN
+         ijjmm = 0
+         DO jt = 1, imonth1-1
+            ijjmm = ijjmm + nobis(jt)
+         END DO
+         zdate1 = ( (iyear1-1)*raajj + ijjmm + iday1-1)* rjjss
+      ELSE 
+         zdate1 = ( (iyear1-1)*nleapy*raamo + (imonth1-1)*nleapy + iday1-1)* rjjss
+      ENDIF
+
+      !  date of end of run (= date of beginning of next run)
+
+      zdate2 = zdate1 + zdrun
+      IF( nleapy == 1 ) THEN 
+         iyear2 = zdate2/(365.25*rjjss)+1
+         ijjmm = INT(zdate2/rjjss)-365*(iyear2-1)-(iyear2-1)/4
+         IF( ijjmm < 0 ) THEN
+            iyear2 = iyear2-1
+            ijjmm = zdate2/rjjss-365.*(iyear2-1)-(iyear2-1)/4
+         ENDIF
+         IF( MOD( iyear2, 4 ) == 0 ) THEN
+            DO jt = 1, 12
+               ijjmm = ijjmm - nbiss(jt)
+               IF( ijjmm <= 0 ) go to 10
+            END DO
+            jt = 12
+10          CONTINUE
+            imonth2 = jt
+            ijjmm = 0
+            DO jt = 1, jt-1
+               ijjmm = ijjmm + nbiss(jt)
+            END DO
+         ELSE
+            DO jt = 1, 12
+               ijjmm = ijjmm - nobis(jt)
+               IF( ijjmm <= 0 ) go to 15
+            END DO
+            jt = 12
+15          CONTINUE
+            imonth2 = jt
+            ijjmm = 0
+            DO jt = 1, jt-1
+               ijjmm = ijjmm + nobis(jt)
+            END DO
+         ENDIF
+         iday2 = zdate2/rjjss-365.*(iyear2-1)-ijjmm+1-(iyear2-1)/4     
+      ELSE IF( nleapy == 0 ) THEN
+         iyear2 = zdate2/raass+1
+         ijjmm  = zdate2/rjjss-raajj*(iyear2-1)
+         DO jt = 1, 12
+            ijjmm = ijjmm - nobis(jt)
+            IF(ijjmm <= 0) go to 20
+         END DO
+         jt = 12
+20       CONTINUE
+         imonth2 = jt
+         ijjmm = 0
+         DO jt = 1, jt-1
+            ijjmm = ijjmm + nobis(jt)
+         END DO
+         iday2 = zdate2/rjjss-raajj*(iyear2-1)-ijjmm+1          
+      ELSE 
+         zdate2 = zdate2 / rjjss
+         imonth2 = zdate2/FLOAT(nleapy)
+         iday2 = zdate2 - imonth2*FLOAT(nleapy) + 1.
+         iyear2 = imonth2/12
+         imonth2 = imonth2 - iyear2*12
+         imonth2 = imonth2 + 1
+         iyear2 = iyear2 + 1
+         IF( iday2 == 0 ) THEN
+            iday2 = nleapy
+            imonth2 = imonth2 - 1
+            IF( imonth2 == 0 ) THEN
+               imonth2 = 12
+               iyear2 = iyear2 - 1
+            ENDIF
+         ENDIF
+      ENDIF
+
+
+      ! 1. Define time averaging period <nn><type>
+      !    ---------------------------------------
+
+      iout = 0
+#if defined key_diainstant
+      clave = 'IN'
+      IF( iyear2 <= 99 ) THEN 
+         WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE IF( iyear2 <= 999 ) THEN 
+         WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE IF( iyear2 <= 9999 ) THEN 
+         WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ELSE
+         WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+      ENDIF
+#else
+
+      znbsec=kfreq*zdt
+      ! daily output
+      IF( znbsec == rjjss ) THEN
+         clave = '1d'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! 5 day output 
+      ELSE IF( znbsec == z5j ) THEN
+         clave='5d'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! monthly ouput 
+      ELSE IF( (znbsec == rmoss .AND. nleapy > 1) .OR.   &
+               (znbsec >= 28*rjjss .AND. znbsec <= 31*rjjss .AND. nleapy <= 1) ) THEN
+         clave = '1m'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+         ! annual output
+      ELSE IF( (znbsec == raass .AND. nleapy > 1) .OR.   &
+               (znbsec >= 365*rjjss .AND. znbsec <= 366*rjjss .AND. nleapy <= 1) ) THEN
+         clave = '1y'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+      ELSE
+         ! others
+         iout = kfreq
+         ig = 0
+         clout = ''
+         IF( iout <= 9 ) THEN 
+            ig = 1
+            WRITE(clout,'(i1.1)') iout
+         ELSE IF( iout <= 99 ) THEN 
+            ig = 2
+            WRITE(clout,'(i2.2)') iout
+         ELSE IF( iout <= 999 ) THEN 
+            ig = 3
+            WRITE(clout,'(i3.3)') iout
+         ELSE IF( iout <= 9999 ) THEN 
+            ig = 4
+            WRITE(clout,'(i4.4)') iout
+         ELSE
+            ig = 5
+            WRITE(clout,'(i5.5)') iout
+         ENDIF
+         clave = 'CU'
+         IF( iyear2 <= 99 ) THEN 
+            WRITE(cdfnam,9001) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 999 ) THEN 
+            WRITE(cdfnam,9002) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE IF( iyear2 <= 9999 ) THEN 
+            WRITE(cdfnam,9003) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ELSE
+            WRITE(cdfnam,9004) iyear1,imonth1,iday1,iyear2,imonth2,iday2
+         ENDIF
+      ENDIF
+#endif
+      IF( iout == 0 ) THEN 
+         cdfnam = TRIM(cexper)//"_"//clave//TRIM(cdfnam)//TRIM(cdsuff)
+      ELSE 
+         cdfnam = TRIM(cexper)//"_"//clave//TRIM(clout)//TRIM(cdfnam)//TRIM(cdsuff)
+      ENDIF
+#if defined key_agrif
+      if ( .NOT. Agrif_Root() ) cdfnam = TRIM(Agrif_CFixed())//'_'//TRIM(cdfnam)
+#endif    
+      IF(lwp) WRITE(numout,*) cdfnam     
+      IF(lwp) WRITE(numout,*)          
+
+      ! FORMATS
+
+ 9001 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9002 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9003 FORMAT("_",I4.4,2I2.2,"_",I4.4,2I2.2,"_")
+ 9004 FORMAT("_",I6.6,2I2.2,"_",I6.6,2I2.2,"_")
+ 9011 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9012 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9013 FORMAT("_",I4.4,I2.2,"_",I4.4,I2.2,"_")
+ 9014 FORMAT("_",I6.6,I2.2,"_",I6.6,I2.2,"_")
+ 9021 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9022 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9023 FORMAT("_",I4.4,"_",I4.4,"_")
+ 9024 FORMAT("_",I6.6,"_",I6.6,"_")
+
+   END SUBROUTINE dia_nam
+
+   !!======================================================================
+END MODULE dianam
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4536)
@@ -0,0 +1,618 @@
+MODULE diaptr
+   !!======================================================================
+   !!                       ***  MODULE  diaptr  ***
+   !! Ocean physics:  brief description of the purpose of the module
+   !!                 (please no more than 2 lines)
+   !!=====================================================================
+   !! History :  9.0  !  03-09  (C. Talandir, G. Madec)  Original code
+   !!            9.0  !  06-01  (A. Biastoch)  Allow sub-basins computation
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dia_ptr      : Poleward Transport Diagnostics module
+   !!   dia_ptr_init : Initialization, namelist read
+   !!   dia_ptr_wri  : Output of poleward fluxes
+   !!   ptr_vjk      : "zonal" sum computation of a "meridional" flux array
+   !!   ptr_vtjk     : "zonal" mean computation of a tracer field
+   !!   ptr_vj       : "zonal" and vertical sum computation of a "meridional"
+   !!                : flux array; Generic interface: ptr_vj_3d, ptr_vj_2d
+   !!----------------------------------------------------------------------
+   USE oce           ! ocean dynamics and active tracers
+   USE dom_oce       ! ocean space and time domain
+   USE ldftra_oce    ! ???
+   USE lib_mpp
+   USE in_out_manager
+   USE dianam
+   USE phycst
+   USE iom
+   USE ioipsl         
+   USE daymod
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE ptr_vj
+      MODULE PROCEDURE ptr_vj_3d, ptr_vj_2d
+   END INTERFACE
+
+   PUBLIC   dia_ptr_init   ! call in opa module
+   PUBLIC   dia_ptr        ! call in step module
+   PUBLIC   ptr_vj         ! call by tra_ldf & tra_adv routines
+   PUBLIC   ptr_vjk        ! call by tra_ldf & tra_adv routines
+
+   !!! ** init namelist (namptr)
+   LOGICAL , PUBLIC                 ::   ln_diaptr = .FALSE.   !: Poleward transport flag (T) or not (F)
+   LOGICAL , PUBLIC                 ::   ln_subbas = .FALSE.   !: Atlantic/Pacific/Indian basins calculation
+   INTEGER , PUBLIC                 ::   nf_ptr = 15           !: frequency of ptr computation
+
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   pht_adv, pst_adv      !: heat and salt poleward transport: advection
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   pht_ove, pst_ove      !: heat and salt poleward transport: overturning
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   pht_ldf, pst_ldf      !: heat and salt poleward transport: lateral diffusion
+#if defined key_diaeiv
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   pht_eiv, pst_eiv      !: heat and salt poleward transport: bolus advection
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   ht_atl,ht_ind,ht_pac  !: heat
+   REAL(wp), PUBLIC, DIMENSION(jpj) ::   st_atl,st_ind,st_pac  !: salt
+
+     
+
+   REAL(wp), DIMENSION(jpj,jpk) ::   tn_jk  , sn_jk  ,  &  !: "zonal" mean temperature and salinity
+      &                              v_msf_atl       ,  &  !: "meridional" Stream-Function
+      &                              v_msf_glo       ,  &  !: "meridional" Stream-Function
+      &                              v_msf_ipc       ,  &  !: "meridional" Stream-Function
+      &                              surf_jk_r             !: inverse of the ocean "zonal" section surface
+#if defined key_diaeiv
+   REAL(wp), DIMENSION(jpj,jpk) ::   v_msf_eiv                  !: bolus "meridional" Stream-Function
+#endif
+   REAL(wp), DIMENSION(jpi,jpj) ::   abasin, pbasin, ibasin     !: return function value
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   FUNCTION ptr_vj_3d( pva )   RESULT ( p_fval )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ptr_vj_3d  ***
+      !!
+      !! ** Purpose :   "zonal" and vertical sum computation of a "meridional"
+      !!      flux array
+      !!
+      !! ** Method  : - i-k sum of pva using the interior 2D vmask (vmask_i).
+      !!      pva is supposed to be a masked flux (i.e. * vmask*e1v*e3v)
+      !!
+      !! ** Action  : - p_fval: i-k-mean poleward flux of pva
+      !!----------------------------------------------------------------------
+      REAL(wp) , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pva   ! mask flux array at V-point
+      !!
+      INTEGER                  ::   ji, jj, jk   ! dummy loop arguments
+      INTEGER                  ::   ijpj         ! ???
+      REAL(wp), DIMENSION(jpj) ::   p_fval       ! function value
+      !!--------------------------------------------------------------------
+      !
+      ijpj = jpj
+      p_fval(:) = 0.e0
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! Vector opt.
+               p_fval(jj) = p_fval(jj) + pva(ji,jj,jk) * tmask_i(ji,jj+1) * tmask_i(ji,jj) 
+            END DO
+         END DO
+      END DO
+      !
+      IF( lk_mpp )   CALL mpp_sum( p_fval, ijpj )     !!bug  I presume
+      !
+   END FUNCTION ptr_vj_3d
+
+
+   FUNCTION ptr_vj_2d( pva )   RESULT ( p_fval )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ptr_vj_2d  ***
+      !!
+      !! ** Purpose :   "zonal" and vertical sum computation of a "meridional"
+      !!      flux array
+      !!
+      !! ** Method  : - i-k sum of pva using the interior 2D vmask (vmask_i).
+      !!      pva is supposed to be a masked flux (i.e. * vmask*e1v*e3v)
+      !!
+      !! ** Action  : - p_fval: i-k-mean poleward flux of pva
+      !!----------------------------------------------------------------------
+      REAL(wp) , INTENT(in), DIMENSION(jpi,jpj) ::   pva   ! mask flux array at V-point
+      !!
+      INTEGER                  ::   ji,jj    ! dummy loop arguments
+      INTEGER                  ::   ijpj     ! ???
+      REAL(wp), DIMENSION(jpj) ::   p_fval   ! function value
+      !!--------------------------------------------------------------------
+      ! 
+      ijpj = jpj
+      p_fval(:) = 0.e0
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! Vector opt.
+            p_fval(jj) = p_fval(jj) + pva(ji,jj) * tmask_i(ji,jj+1) * tmask_i(ji,jj)
+         END DO
+      END DO
+      !
+      IF( lk_mpp )   CALL mpp_sum( p_fval, ijpj )     !!bug  I presume
+      ! 
+   END FUNCTION ptr_vj_2d
+
+
+   FUNCTION ptr_vjk( pva )   RESULT ( p_fval )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ptr_vjk  ***
+      !!
+      !! ** Purpose :   "zonal" sum computation of a "meridional" flux array
+      !!
+      !! ** Method  : - i-sum of pva using the interior 2D vmask (vmask_i).
+      !!      pva is supposed to be a masked flux (i.e. * vmask*e1v*e3v)
+      !!
+      !! ** Action  : - p_fval: i-k-mean poleward flux of pva
+      !!----------------------------------------------------------------------
+      REAL(wp) , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pva   ! mask flux array at V-point
+      !!
+      INTEGER                      ::   ji, jj, jk   ! dummy loop arguments
+      INTEGER , DIMENSION (1)      ::   ish
+      INTEGER , DIMENSION (2)      ::   ish2
+      REAL(wp), DIMENSION(jpj*jpk) ::   zwork        ! temporary vector for mpp_sum
+      REAL(wp), DIMENSION(jpj,jpk) ::   p_fval       ! return function value
+      !!--------------------------------------------------------------------
+      ! 
+      p_fval(:,:) = 0.e0
+      !
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+           DO ji = fs_2, fs_jpim1
+            p_fval(jj,jk) = p_fval(jj,jk) + pva(ji,jj,jk) * e1v(ji,jj) * fse3v(ji,jj,jk)   &
+               &                                          * tmask_i(ji,jj+1) * tmask_i(ji,jj)
+           END DO
+         END DO
+      END DO
+      !
+      IF(lk_mpp) THEN
+         ish(1) = jpj*jpk  ;  ish2(1) = jpj  ;  ish2(2) = jpk
+         zwork(:)= RESHAPE( p_fval, ish )
+         CALL mpp_sum( zwork, jpj*jpk )
+         p_fval(:,:)= RESHAPE( zwork, ish2 )
+      END IF
+      !
+   END FUNCTION ptr_vjk
+
+
+   FUNCTION ptr_vtjk( pva )   RESULT ( p_fval )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ptr_vtjk  ***
+      !!
+      !! ** Purpose :   "zonal" mean computation of a tracer field
+      !!
+      !! ** Method  : - i-sum of mj(pva) using the interior 2D vmask (vmask_i)
+      !!      multiplied by the inverse of the surface of the "zonal" ocean
+      !!      section
+      !!
+      !! ** Action  : - p_fval: i-k-mean poleward flux of pva
+      !!----------------------------------------------------------------------
+      REAL(wp) , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pva   ! mask flux array at V-point
+      !!
+      INTEGER                     ::   ji, jj, jk   ! dummy loop arguments
+      INTEGER, DIMENSION (1)      ::   ish
+      INTEGER, DIMENSION (2)      ::   ish2
+      REAL(wp),DIMENSION(jpj*jpk) ::   zwork        ! temporary vector for mpp_sum
+      REAL(wp),DIMENSION(jpj,jpk) ::   p_fval       ! return function value
+      !!-------------------------------------------------------------------- 
+      !
+      p_fval(:,:) = 0.e0
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! Vector opt.
+               p_fval(jj,jk) = p_fval(jj,jk) + ( pva(ji,jj,jk) + pva(ji,jj+1,jk) )              &
+                  &                          * e1v(ji,jj) * fse3v(ji,jj,jk) * vmask(ji,jj,jk)   &
+                  &                          * tmask_i(ji,jj+1) * tmask_i(ji,jj)
+            END DO
+         END DO
+      END DO
+      p_fval(:,:) = p_fval(:,:) * 0.5
+      IF(lk_mpp) THEN
+         ish(1) = jpj*jpk   ;   ish2(1) = jpj   ;   ish2(2) = jpk
+         zwork(:)= RESHAPE( p_fval, ish )
+         CALL mpp_sum( zwork, jpj*jpk )
+         p_fval(:,:)= RESHAPE(zwork,ish2)
+      END IF
+      !
+   END FUNCTION ptr_vtjk
+
+
+   SUBROUTINE dia_ptr( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_ptr  ***
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step index
+      !!
+      INTEGER  ::   jk, jj, ji               ! dummy loop
+      REAL(wp) ::   zsverdrup,  &              ! conversion from m3/s to Sverdrup
+         &          zpwatt,     &              ! conversion from W    to PW
+         &          zggram                     ! conversion from g    to Pg
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &
+         v_atl , v_ipc,                    &
+         vt_atl, vt_pac, vt_ind,           &
+         vs_atl, vs_pac, vs_ind             
+      INTEGER ::  inum       ! temporary logical unit
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .OR. MOD( kt, nf_ptr ) == 0 )   THEN
+
+         zsverdrup = 1.e-6
+         zpwatt    = 1.e-15
+         zggram    = 1.e-6
+   
+         ! "zonal" mean temperature and salinity at V-points
+         tn_jk(:,:) = ptr_vtjk( tn(:,:,:) ) * surf_jk_r(:,:)
+         sn_jk(:,:) = ptr_vtjk( sn(:,:,:) ) * surf_jk_r(:,:)
+
+         !--------------------------------------------------------
+         ! overturning calculation:
+ 
+         IF( ln_subbas ) THEN              ! Basins computation
+
+            IF( kt == nit000 ) THEN                ! load sub-basin mask
+               CALL iom_open( 'subbasins', inum )
+               CALL iom_get( inum, jpdom_data, 'atlmsk', abasin )      ! Atlantic basin
+               CALL iom_get( inum, jpdom_data, 'pacmsk', pbasin )      ! Pacific basin
+               CALL iom_get( inum, jpdom_data, 'indmsk', ibasin )      ! Indian basin
+               CALL iom_close( inum )
+            ENDIF
+
+            ! basin separation:
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! basin separated velocity
+                  v_atl(ji,jj,:) = vn(ji,jj,:)*abasin(ji,jj)
+                  v_ipc(ji,jj,:) = vn(ji,jj,:)*(pbasin(ji,jj)+ibasin(ji,jj))
+
+                  ! basin separated T times V on T points
+                  vt_ind(ji,jj,:) = tn(ji,jj,:) * ( vn(ji,jj,:) + vn(ji,jj-1,:) )*0.5
+                  vt_atl(ji,jj,:) = vt_ind(ji,jj,:) * abasin(ji,jj)
+                  vt_pac(ji,jj,:) = vt_ind(ji,jj,:) * pbasin(ji,jj)
+                  vt_ind(ji,jj,:) = vt_ind(ji,jj,:) * ibasin(ji,jj)
+
+                  ! basin separated S times V on T points
+                  vs_ind(ji,jj,:) = sn(ji,jj,:) * ( vn(ji,jj,:) + vn(ji,jj-1,:) )*0.5
+                  vs_atl(ji,jj,:) = vs_ind(ji,jj,:) * abasin(ji,jj)
+                  vs_pac(ji,jj,:) = vs_ind(ji,jj,:) * pbasin(ji,jj)
+                  vs_ind(ji,jj,:) = vs_ind(ji,jj,:) * ibasin(ji,jj)
+               END DO
+            END DO
+
+         ENDIF
+
+         ! horizontal integral and vertical dz 
+         v_msf_glo(:,:) = ptr_vjk( vn(:,:,:) ) 
+#if defined key_diaeiv
+         v_msf_eiv(:,:) = ptr_vjk( v_eiv(:,:,:) ) 
+#endif
+         IF( ln_subbas ) THEN
+            v_msf_atl(:,:) = ptr_vjk( v_atl (:,:,:) ) 
+            v_msf_ipc(:,:) = ptr_vjk( v_ipc (:,:,:) ) 
+            ht_atl(:) = SUM( ptr_vjk( vt_atl(:,:,:)), 2 )
+            ht_pac(:) = SUM( ptr_vjk( vt_pac(:,:,:)), 2 )
+            ht_ind(:) = SUM( ptr_vjk( vt_ind(:,:,:)), 2 )
+            st_atl(:) = SUM( ptr_vjk( vs_atl(:,:,:)), 2 )
+            st_pac(:) = SUM( ptr_vjk( vs_pac(:,:,:)), 2 )
+            st_ind(:) = SUM( ptr_vjk( vs_ind(:,:,:)), 2 )
+         ENDIF
+
+         ! poleward tracer transports: 
+         ! overturning components:
+         pht_ove(:) = SUM( v_msf_glo(:,:) * tn_jk(:,:), 2 )   ! SUM over jk
+         pst_ove(:) = SUM( v_msf_glo(:,:) * sn_jk(:,:), 2 )   ! SUM over jk
+#if defined key_diaeiv
+         pht_eiv(:) = SUM( v_msf_eiv(:,:) * tn_jk(:,:), 2 )   ! SUM over jk
+         pst_eiv(:) = SUM( v_msf_eiv(:,:) * sn_jk(:,:), 2 )   ! SUM over jk
+#endif
+      
+         ! conversion in PW and G g
+         zpwatt = zpwatt * rau0 * rcp
+         pht_adv(:) = pht_adv(:) * zpwatt  
+         pht_ove(:) = pht_ove(:) * zpwatt
+         pht_ldf(:) = pht_ldf(:) * zpwatt
+         pst_adv(:) = pst_adv(:) * zggram
+         pst_ove(:) = pst_ove(:) * zggram
+         pst_ldf(:) = pst_ldf(:) * zggram
+#if defined key_diaeiv
+         pht_eiv(:) = pht_eiv(:) * zpwatt
+         pst_eiv(:) = pst_eiv(:) * zggram
+#endif
+         IF( ln_subbas ) THEN
+            ht_atl(:) = ht_atl(:) * zpwatt
+            ht_pac(:) = ht_pac(:) * zpwatt
+            ht_ind(:) = ht_ind(:) * zpwatt
+            st_atl(:) = st_atl(:) * zggram 
+            st_pac(:) = st_pac(:) * zggram
+            st_ind(:) = st_ind(:) * zggram
+         ENDIF
+
+         ! "Meridional" Stream-Function
+         DO jk = 2,jpk 
+            v_msf_glo(:,jk) = v_msf_glo(:,jk-1) + v_msf_glo(:,jk)
+         END DO
+         v_msf_glo(:,:) = v_msf_glo(:,:) * zsverdrup
+
+#if defined key_diaeiv
+         ! Bolus "Meridional" Stream-Function
+         DO jk = 2,jpk 
+            v_msf_eiv(:,jk) = v_msf_eiv(:,jk-1) + v_msf_eiv(:,jk)
+         END DO
+         v_msf_eiv(:,:) = v_msf_eiv(:,:) * zsverdrup
+#endif
+
+         IF( ln_subbas ) THEN
+            DO jk = 2,jpk 
+               v_msf_atl(:,jk) = v_msf_atl(:,jk-1) + v_msf_atl(:,jk)
+               v_msf_ipc(:,jk) = v_msf_ipc(:,jk-1) + v_msf_ipc(:,jk)
+            END DO
+            v_msf_atl(:,:) = v_msf_atl(:,:) * zsverdrup
+            v_msf_ipc(:,:) = v_msf_ipc(:,:) * zsverdrup
+         ENDIF
+
+         ! outputs
+         CALL dia_ptr_wri( kt )
+
+      ENDIF
+
+      ! Close the file
+      IF( kt == nitend ) CALL histclo( numptr )
+      !
+   END SUBROUTINE dia_ptr
+
+
+   SUBROUTINE dia_ptr_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_ptr_init  ***
+      !!                   
+      !! ** Purpose :   Initialization, namelist read
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z_1         ! temporary workspace
+
+      NAMELIST/namptr/ ln_diaptr, ln_subbas, nf_ptr
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namptr : poleward transport parameters
+      REWIND ( numnam )
+      READ   ( numnam, namptr )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_ptr_init : poleward transport and msf initialization'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namptr : set ptr parameters'
+         WRITE(numout,*) '             Switch for ptr diagnostic (T) or not (F) ln_diaptr = ', ln_diaptr
+         WRITE(numout,*) '             Atla/Paci/Ind basins computation         ln_subbas = ', ln_subbas
+         WRITE(numout,*) '             Frequency of computation                    nf_ptr = ', nf_ptr
+      ENDIF
+
+      ! inverse of the ocean "zonal" v-point section
+      z_1(:,:,:) = 1.e0
+      surf_jk_r(:,:) = ptr_vtjk( z_1(:,:,:) )
+      WHERE( surf_jk_r(:,:) /= 0.e0 )   surf_jk_r(:,:) = 1.e0 / surf_jk_r(:,:)
+
+   END SUBROUTINE dia_ptr_init
+
+
+   SUBROUTINE dia_ptr_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                ***  ROUTINE dia_ptr_wri  ***
+      !!
+      !! ** Purpose :   output of poleward fluxes
+      !!
+      !! ** Method  :   NetCDF file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER, SAVE ::   nhoridz, ndepidzt, ndepidzw, ndex(1)
+
+      CHARACTER (len=40)       ::   clhstnam, clop                   ! temporary names
+      INTEGER                  ::   iline, it, ji                    !
+      REAL(wp)                 ::   zsto, zout, zdt, zmax, zjulian   ! temporary scalars
+      REAL(wp), DIMENSION(jpj) ::   zphi, zfoo
+      !!----------------------------------------------------------------------
+      
+      ! Define frequency of output and means
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+#if defined key_diainstant
+         zsto = nf_ptr * zdt
+         clop = "inst(x)"               ! no use of the mask value (require less cpu time)
+         !!! clop="inst(only(x))"       ! put 1.e+20 on land (very expensive!!)
+#else
+         zsto = zdt
+         clop = "ave(x)"                ! no use of the mask value (require less cpu time)
+         !!! clop="ave(only(x))"        ! put 1.e+20 on land (very expensive!!)
+#endif
+      zout = nf_ptr * zdt
+      zmax = ( nitend - nit000 + 1 ) * zdt
+      
+         
+      ! define time axis
+      it = kt - nit000 + 1
+
+      ! Initialization
+      ! --------------
+      IF( kt == nit000 ) THEN
+      
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+
+         ! Reference latitude
+         ! ------------------
+         !                                           ! =======================
+         IF( cp_cfg == "orca" ) THEN                 !   ORCA configurations
+            !                                        ! =======================
+
+            IF( jp_cfg == 05  )   iline = 192   ! i-line that passes near the North Pole
+            IF( jp_cfg == 025 )   iline = 384   ! i-line that passes near the North Pole
+            IF( jp_cfg == 2   )   iline =  48   ! i-line that passes near the North Pole
+            IF( jp_cfg == 4   )   iline =  24   ! i-line that passes near the North Pole
+            zphi(:) = 0.e0
+            DO ji = mi0(iline), mi1(iline) 
+               zphi(:) = gphiv(ji,:)         ! if iline is in the local domain
+               ! correct highest latitude for ORCA05
+               IF( jp_cfg == 05  ) zphi(jpj) = zphi(jpjm1) + (zphi(jpjm1)-zphi(jpj-2))/2.
+               IF( jp_cfg == 05  ) zphi(jpj) = MIN( zphi(jpj), 90.)
+
+            END DO
+            ! provide the correct zphi to all local domains
+            IF( lk_mpp )   CALL mpp_sum( zphi, jpj )        
+
+            !                                        ! =======================
+         ELSE                                        !   OTHER configurations
+            !                                        ! =======================
+            zphi(:) = gphiv(1,:)             ! assume lat/lon coordinate, select the first i-line
+            !
+         ENDIF
+
+         ! OPEN netcdf file 
+         ! ----------------
+         ! Define frequency of output and means
+         zsto = nf_ptr * zdt
+         clop = "ave(x)"
+         zout = nf_ptr * zdt
+         zfoo(:) = 0.e0
+
+         ! Compute julian date from starting date of the run
+
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+
+         CALL dia_nam( clhstnam, nf_ptr, 'diaptr' )
+         IF(lwp)WRITE( numout,*)" Name of diaptr NETCDF file ",clhstnam
+
+         ! Horizontal grid : zphi()
+         CALL histbeg(clhstnam, 1, zfoo, jpj, zphi,   &
+            1, 1, 1, jpj, 0, zjulian, zdt, nhoridz, numptr, domain_id=nidom )
+         ! Vertical grids : gdept_0, gdepw_0
+         CALL histvert( numptr, "deptht", "Vertical T levels",   &
+            "m", jpk, gdept_0, ndepidzt )
+         CALL histvert( numptr, "depthw", "Vertical W levels",   &
+            "m", jpk, gdepw_0, ndepidzw )
+         
+         !  Zonal mean T and S
+         
+         CALL histdef( numptr, "zotemglo", "Zonal Mean Temperature","C" ,   &
+            1, jpj, nhoridz, jpk, 1, jpk, ndepidzt, 32, clop, zsto, zout )
+         CALL histdef( numptr, "zosalglo", "Zonal Mean Salinity","PSU"  ,   &
+            1, jpj, nhoridz, jpk, 1, jpk, ndepidzt, 32, clop, zsto, zout )
+
+         !  Meridional Stream-Function (eulerian and bolus)
+         
+         CALL histdef( numptr, "zomsfglo", "Meridional Stream-Function: Global","Sv" ,   &
+            1, jpj, nhoridz, jpk, 1, jpk, ndepidzw, 32, clop, zsto, zout )
+         IF( ln_subbas ) THEN
+            CALL histdef( numptr, "zomsfatl", "Meridional Stream-Function: Atlantic","Sv" ,   &
+               1, jpj, nhoridz, jpk, 1, jpk, ndepidzw, 32, clop, zsto, zout )
+            CALL histdef( numptr, "zomsfipc", "Meridional Stream-Function: Indo-Pacific","Sv" ,&
+               1, jpj, nhoridz, jpk, 1, jpk, ndepidzw, 32, clop, zsto, zout )
+         ENDIF
+
+         !  Heat transport 
+
+         CALL histdef( numptr, "sophtadv", "Advective Heat Transport"      ,   &
+            "PW", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sophtldf", "Diffusive Heat Transport"      ,   &
+            "PW",1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sophtove", "Overturning Heat Transport"    ,   &
+            "PW",1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         IF( ln_subbas ) THEN
+            CALL histdef( numptr, "sohtatl", "Heat Transport Atlantic"      ,  &
+               "PW", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+            CALL histdef( numptr, "sohtpac", "Heat Transport Pacific"      ,   &
+               "PW", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+            CALL histdef( numptr, "sohtind", "Heat Transport Indic"      ,     &
+               "PW", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         ENDIF
+
+
+         !  Salt transport 
+
+         CALL histdef( numptr, "sopstadv", "Advective Salt Transport"      ,   &
+            "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sopstldf", "Diffusive Salt Transport"      ,   &
+            "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sopstove", "Overturning Salt Transport"    ,   &
+            "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+
+#if defined key_diaeiv
+         ! Eddy induced velocity
+         CALL histdef( numptr, "zomsfeiv", "Bolus Meridional Stream-Function: global",   &
+            "Sv"      , 1, jpj, nhoridz, jpk, 1, jpk, ndepidzw, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sophteiv", "Bolus Advective Heat Transport",   &
+            "PW"      , 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         CALL histdef( numptr, "sopsteiv", "Bolus Advective Salt Transport",   &
+            "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+#endif
+         IF( ln_subbas ) THEN
+            CALL histdef( numptr, "sostatl", "Salt Transport Atlantic"      ,    &
+               "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+            CALL histdef( numptr, "sostpac", "Salt Transport Pacific"      ,     &
+               "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+            CALL histdef( numptr, "sostind", "Salt Transport Indic"      ,       &
+               "Giga g/s", 1, jpj, nhoridz, 1, 1, 1, -99, 32, clop, zsto, zout )
+         ENDIF
+         
+
+         CALL histend( numptr )
+
+      ENDIF
+
+      IF( MOD( kt, nf_ptr ) == 0 ) THEN
+
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'dia_ptr : write Poleward Transports at time-step : ', kt
+            WRITE(numout,*) '~~~~~~~~'
+            WRITE(numout,*)
+         ENDIF
+
+         ! define time axis
+         it= kt - nit000 + 1
+         ndex(1) = 0
+         CALL histwrite( numptr, "zotemglo", it, tn_jk    , jpj*jpk, ndex )
+         CALL histwrite( numptr, "zosalglo", it, sn_jk    , jpj*jpk, ndex )
+         ! overturning outputs:
+         CALL histwrite( numptr, "zomsfglo", it, v_msf_glo , jpj*jpk, ndex )
+         IF( ln_subbas ) THEN
+            CALL histwrite( numptr, "zomsfatl", it, v_msf_atl , jpj*jpk, ndex )
+            CALL histwrite( numptr, "zomsfipc", it, v_msf_ipc , jpj*jpk, ndex )
+         ENDIF
+         ! heat transport outputs:
+         IF( ln_subbas ) THEN
+            CALL histwrite( numptr, "sohtatl", it, ht_atl  , jpj, ndex )
+            CALL histwrite( numptr, "sohtpac", it, ht_pac  , jpj, ndex )
+            CALL histwrite( numptr, "sohtind", it, ht_ind  , jpj, ndex )
+            CALL histwrite( numptr, "sostatl", it, st_atl  , jpj, ndex )
+            CALL histwrite( numptr, "sostpac", it, st_pac  , jpj, ndex )
+            CALL histwrite( numptr, "sostind", it, st_ind  , jpj, ndex )
+         ENDIF
+
+         CALL histwrite( numptr, "sophtadv", it, pht_adv  , jpj, ndex )
+         CALL histwrite( numptr, "sophtldf", it, pht_ldf  , jpj, ndex )
+         CALL histwrite( numptr, "sophtove", it, pht_ove  , jpj, ndex )
+         CALL histwrite( numptr, "sopstadv", it, pst_adv  , jpj, ndex )
+         CALL histwrite( numptr, "sopstldf", it, pst_ldf  , jpj, ndex )
+         CALL histwrite( numptr, "sopstove", it, pst_ove  , jpj, ndex )
+#if defined key_diaeiv
+         CALL histwrite( numptr, "zomsfeiv", it, v_msf_eiv, jpj*jpk, ndex )
+         CALL histwrite( numptr, "sophteiv", it, pht_eiv  , jpj    , ndex )
+         CALL histwrite( numptr, "sopsteiv", it, pst_eiv  , jpj    , ndex )
+#endif
+ 
+      ENDIF
+      !
+   END SUBROUTINE dia_ptr_wri
+
+   !!======================================================================
+END MODULE diaptr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaspr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaspr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diaspr.F90	(revision 4536)
@@ -0,0 +1,607 @@
+MODULE diaspr
+   !!======================================================================
+   !!                       ***  MODULE  diaspr  ***
+   !! Ocean diagnostics:  surface pressure (rigid-lid case) 
+   !!=====================================================================
+#if   defined key_diaspr   &&   defined key_dynspg_rl
+   !!----------------------------------------------------------------------
+   !!   'key_diaspr'        and                surface pressure diagnostics
+   !!   'key_dynspg_rl'                                      rigid-lid case
+   !!----------------------------------------------------------------------
+   !!   dia_spr      : update momentum and tracer Kz from a tke scheme
+   !!   sprmat       : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE sol_oce         ! ocean elliptic solver
+   USE solpcg          ! preconditionned conjugate gradient solver
+   USE solsor          ! Successive Over-relaxation solver
+   USE solfet          ! FETI solver
+   USE lib_mpp         ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dia_spr   ! routine called by step.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diaspr = .TRUE.    !: surface pressure diag. flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   gps         !: surface pressure
+
+   !! * Module variables
+   INTEGER ::                 &
+      nmoyps,                 &  ! time step for average
+      nindic,                 &  ! indicator of convergence of the solver
+      !                          ! namspr  surface pressure diagnostic
+      nmaxp ,                 &  ! maximum of iterations for the solver
+      niterp                     ! number of iteration done by the solver
+
+   REAL(wp) ::     &
+      ! namspr  surface pressure diagnostic
+      epsp                       ! absolute precision of the solver
+
+      !! * Namelist
+      NAMELIST/namspr/ nmaxp, epsp, niterp
+
+   REAL(wp) ::     &
+      e1e2t                      ! ???
+
+   REAL(wp), PUBLIC DIMENSION(jpi,jpj) ::   &
+      spgum, spgvm,           &  ! average value of the surface pressure gradients
+      gpsuu, gpsvv,           &  ! surface pressure gradients computed from comp. PS
+      gcdpsc,                 &  ! inverse diagonal preconditioning matrix
+      gcsmat,                 &  ! diagonal preconditioning matrix
+      spmsk                      ! surface pressure Mask
+
+   REAL(wp), DIMENSION(jpi,jpj,4) ::   &
+      gcps                       ! extra-diagonal elements of SPG matrix
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_spr( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_spr  ***
+      !!
+      !! ** Purpose :   compute the surface pressure from its gradient
+      !!
+      !! ** Method  :   rigid-lid appromimation: the surface pressure 
+      !!      gradient is given by:
+      !!           spgu = 1/rau0 d/dx(ps) = Mu + 1/(hu e2u) dj-1(bsfd)
+      !!           spgv = 1/rau0 d/dy(ps) = Mv - 1/(hv e1v) di-1(bsfd)
+      !!
+      !!      where (Mu,Mv) is the vertically averaged momentum trend, i.e.
+      !!      the vertical ponderated sum of the general momentum trend.
+      !!      where bsfd is the trend of the barotropic stream function.
+      !!
+      !!       taking the divergence of the surface pressure gradient provides
+      !!      an elliptic equation for ps which is solved using either a
+      !!      diagonal preconditioned conjugate gradient method (solpcg.f) or
+      !!      an successive-over-relaxation method (solsor.f) or FETI method
+      !!      (solfet.F).
+      !!
+      !!      n.b. this resolution is valid with topography, cyclic east-west
+      !!      boundary conditions and islands.
+      !!
+      !! History :
+      !!        !  98-01  (G. Madec & M. Ioualalen)  Original code
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj
+      INTEGER  ::   imax, ijt, iju
+      REAL(wp) ::   zpsmea, zeps, zmoyr
+      REAL(wp) ::   ztab(jpi,jpj,8)
+      REAL(wp) ::   zemin1, zemax1, zemin2, zemax2, zgwgt
+      REAL(wp) ::   z1, z2, zcompt,z3,z4
+      REAL(wp) ::   zdif1, zdif2, zvar1, zvar2
+      !!----------------------------------------------------------------------
+
+
+      ! 0. initialisation (the first time step)
+      ! ---------------------------------------
+      
+      IF( kt == nit000 ) THEN
+
+         ! Namelist namspr : surface pressure
+
+         nmaxp  = 2000
+         epsp   = 1.e-6
+         niterp = 16
+
+         ! Read Namelist namspr : surface pressure diagnostics
+         REWIND ( numnam )
+         READ(numnam,namspr)
+
+         IF(lwp) THEN
+            WRITE(numout,*) 'dia_spr : surface pressure diagnostic (rigid-lid case)'
+            WRITE(numout,*) '~~~~~~~'
+            WRITE(numout,*)
+            WRITE(numout,*) '          Namelist namspr : set solver parameters'
+            WRITE(numout,*)
+            WRITE(numout,*) '             maximum iterations for solver  nmaxp  = ', nmaxp
+            WRITE(numout,*) '             absolute precision of solver   epsp   = ', epsp
+            WRITE(numout,*) '             number of solver iterations    niterp = ', niterp
+            WRITE(numout,*) '             frequeny of averaged output    nwrite = ', nwrite
+            WRITE(numout,*)
+         ENDIF
+
+         ! control
+# if ! defined key_dynspg_rl
+      CALL ctl_stop( '          surface pressure already explicitly computed !!' )
+# endif
+
+         ! compute the ocean surface
+         e1e2t = 0.e0
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               e1e2t = e1e2t + e1t(ji,jj)*e2t(ji,jj)*tmask(ji,jj,1)
+            END DO
+         END DO
+         IF( lk_mpp )   CALL  mpp_sum( e1e2t )   ! sum over the global domain
+         
+         ! build the matrix for the surface pressure
+         CALL sprmat
+         
+         ! set to zero the mean surface pressure gradient
+         nmoyps = 0
+         spgum(:,:) = 0.e0
+         spgvm(:,:) = 0.e0
+
+      ENDIF
+
+      ! 1. cumulate the surface pressure gradient (at each time step)
+      ! -----------------------------------------
+
+      nmoyps = nmoyps + 1
+      spgum(:,:) = spgum(:,:) + spgu(:,:)
+      spgvm(:,:) = spgvm(:,:) + spgv(:,:)
+      
+
+      ! 2. ps computation each nwrite time step
+      ! ---------------------------------------
+      
+      ! RETURN IF not the right time to compute ps
+      IF ( MOD(kt-nit000+1,nwrite) /= 0 ) RETURN
+      
+      
+      ! mean surface pressure gradient
+      !   averaging and mask
+      zmoyr = 1./float(nmoyps)
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            spgum(ji,jj) = spgum(ji,jj) * zmoyr * umask(ji,jj,1)
+            spgvm(ji,jj) = spgvm(ji,jj) * zmoyr * vmask(ji,jj,1)
+         END DO
+      END DO
+
+      CALL  lbc_lnk(spgum, 'U', -1. )
+      CALL  lbc_lnk(spgvm, 'V', -1. )
+
+      
+      ! SAVE in local arrays and variables of solver informations
+      zeps   = eps
+      imax  = nmax 
+      ztab(:,:,1) = gcp   (:,:,1)
+      ztab(:,:,2) = gcp   (:,:,2)
+      ztab(:,:,3) = gcp   (:,:,3)
+      ztab(:,:,4) = gcp   (:,:,4)
+      ztab(:,:,5) = gcdprc(:,:  )
+      ztab(:,:,6) = gcdmat(:,:  )
+      ztab(:,:,7) = gcx   (:,:  )
+      ztab(:,:,8) = bmask (:,:  )
+
+      ! replace bsf solver informations by ps solver one
+      eps    = epsp
+      nmax   = nmaxp
+      gcp   (:,:,1) = gcps  (:,:,1)
+      gcp   (:,:,2) = gcps  (:,:,2)
+      gcp   (:,:,3) = gcps  (:,:,3)
+      gcp   (:,:,4) = gcps  (:,:,4)
+      gcdprc(:,:  ) = gcdpsc(:,:  )
+      gcdmat(:,:  ) = gcsmat(:,:  )
+      bmask (:,:  ) = spmsk (:,:  )
+      !    first guess: ps
+      gcx   (:,:  ) = gps   (:,:  )
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,synchro IF macrotasking,,,,,,,,,,,,,,,,,,,,,,,
+
+      ! right hand side: 2d div. of the surface pressure gradient
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            gcb(ji,jj) = -gcdpsc(ji,jj)*   &
+               (  e2u(ji,jj)*spgum(ji,jj) - e2u(ji-1,jj)*spgum(ji-1,jj)   &
+               + e1v(ji,jj)*spgvm(ji,jj) - e1v(ji,jj-1)*spgvm(ji,jj-1) )
+         END DO
+      END DO
+      
+      !,,,,,,,,,,,,,,,,,,,,,,,,synchro IF macrotasking,,,,,,,,,,,,,,,,,,,,,,,
+      
+      ! relative PRECISION
+      rnorme = 0.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            rnorme = rnorme + gcb(ji,jj) * gcsmat(ji,jj) * gcb(ji,jj)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL  mpp_sum( rnorme )   ! sum over the global domain
+
+      epsr=eps*eps*rnorme
+      ncut=0
+      !   IF the second member is 0 the solution is 0, solpcg isn't called
+      IF ( rnorme == 0.e0 ) THEN
+         gps(:,:) = 0.e0
+         res   = 0.e0
+         niter = 0
+         ncut  = 999
+      ENDIF
+      
+      !,,,,,,,,,,,,,,,,,,,,,,,,synchro IF macrotasking,,,,,,,,,,,,,,,,,,,,,,,
+      
+      nindic = 0
+
+      ! iterarive solver of the spg system (except IF sol.=0)
+      !     (OUTPUT in gcx with boundary conditions applied)
+      IF ( ncut == 0 ) THEN
+         IF ( nsolv == 1 ) THEN
+            CALL sol_pcg( nindic )         !   diagonal preconditioned conjuguate gradient
+         ELSE IF ( nsolv == 2 ) THEN
+            CALL sol_sor( nindic )     !   successive-over-relaxation
+         ELSE IF(nsolv == 3) THEN
+            CALL sol_fet( nindic )         !   FETI solver
+         ELSE
+            !   e r r o r  in nsolv namelist PARAMETER
+            IF(lwp) THEN
+               WRITE(numout,*) ' dia_spr: e r r o r, nsolv = 1 or 2'
+               WRITE(numout,*) ' ******               not = ',nsolv
+            ENDIF
+            STOP 'dia_spr'
+         ENDIF
+      ENDIF
+      
+      !,,,,,,,,,,,,,,,,,,,,,,,,synchro IF macrotasking,,,,,,,,,,,,,,,,,,,,,,,
+
+      
+      ! sp solver statistics  (i.e. problem for the solver) 
+      IF ( epsr < 0.) THEN
+         IF(lwp) THEN 
+            WRITE(numout,*)'rrrrrrrrrrrrrrr'
+            IF(lwp)WRITE(numout,*)'dia_spr-1:',epsr
+            IF(lwp)WRITE(numout,*)'rrrrrrrrrrrrrrr'
+         ENDIF
+      ENDIF
+      IF(lwp)WRITE(numout,9300) kt, niter, res, SQRT(epsr)/eps
+      IF (nindic < 0) THEN 
+         IF(lwp) THEN 
+            WRITE(numout,9100)
+            WRITE(numout,*) ' dia_spr : the surface pressure solver DO not converge'
+            WRITE(numout,*) ' ====== ' 
+            WRITE(numout,*) 
+         ENDIF
+      ENDIF
+9100  FORMAT( /,' ===>>>> : w a r n i n g',/,'          ===============',/ )
+9300  FORMAT(' it :', i8, ' niter :', i4, ' res :',e20.10,' b :', e20.10)
+
+      ! recover bsf solver informations and SAVE ps for next computation
+      eps    = zeps
+      nmax   = imax 
+      gps   (:,:  ) = gcx (:,:)
+      gcp   (:,:,1) = ztab(:,:,1)
+      gcp   (:,:,2) = ztab(:,:,2)
+      gcp   (:,:,3) = ztab(:,:,3)
+      gcp   (:,:,4) = ztab(:,:,4)
+      gcdprc(:,:  ) = ztab(:,:,5)
+      gcdmat(:,:  ) = ztab(:,:,6)
+      gcx   (:,:  ) = ztab(:,:,7)
+      bmask (:,:  ) = ztab(:,:,8)
+      
+      ! compute and substract the mean value
+      
+      zpsmea = 0.e0
+      DO jj=2,jpjm1
+         DO ji=2,jpim1
+            zpsmea = zpsmea + gps(ji,jj) * e1t(ji,jj) * e2t(ji,jj) * tmask(ji,jj,1)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL  mpp_sum( zpsmea )   ! sum over the global domain
+
+      zpsmea = zpsmea / e1e2t
+      gps(:,:) = ( gps(:,:) - zpsmea ) * tmask(:,:,1)
+ 
+      IF(lwp)WRITE(numout,*) ' mean value of ps = ',zpsmea,' is substracted'
+      ! ----------------------------------------
+      ! i. compute the surface pressure gradient
+      !    from the computed surface pressure
+      ! ----------------------------------------
+
+      DO jj=2,jpjm1
+         DO ji=2,jpim1
+            gpsuu(ji,jj)=(gps(ji+1,jj)-gps(ji,jj))/e1u(ji,jj) * umask(ji,jj,1)
+            gpsvv(ji,jj)=(gps(ji,jj+1)-gps(ji,jj))/e2v(ji,jj) * vmask(ji,jj,1)
+         END DO
+      END DO
+      
+      ! compute the max and min error
+      
+      zemax1 = 0.e0
+      zemin1 = 0.e0
+      zemax2 = 0.e0
+      zemin2 = 0.e0
+      DO jj = 2,jpj-1
+         DO ji = 2,jpi-1
+            z1 = ABS( spgum(ji,jj)-gpsuu(ji,jj) )*umask(ji,jj,1)
+            z2 = ABS( spgvm(ji,jj)-gpsvv(ji,jj) )*vmask(ji,jj,1)
+            z3 = MAX ( ABS( spgum(ji,jj) ), ABS( spgvm(ji,jj) ) )
+            z4 = MAX ( ABS( gpsuu(ji,jj) ), ABS( gpsvv(ji,jj) ) )
+            zemax1 = MAX(z1,zemax1)
+            zemax2 = MAX(z2,zemax2)
+            zemin1 = MAX(z3,zemin1)
+            zemin2 = MAX(z4,zemin2)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL  mpp_sum( zemax1 )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zemax2 )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zemin1 )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zemin2 )   ! sum over the global domain
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'pserro : time step = ', kt
+         WRITE(numout,*) '******** ------------------'
+         WRITE(numout,*)
+         WRITE(numout,*) '         gpsx error  max=',zemax1
+         WRITE(numout,*) '         gpsy error  max=',zemax2
+         WRITE(numout,*) '         gps max =',zemin1
+         WRITE(numout,*) '         gpsc max =',zemin2
+         WRITE(numout,*)
+      ENDIF
+
+      ! compute the norme and variance of this error
+
+      zcompt = 0.e0
+      zdif1  = 0.e0
+      zdif2  = 0.e0
+      zvar1  = 0.e0
+      zvar2  = 0.e0
+      DO jj = 2, jpj-1
+         DO ji = 2, jpi-1
+            z1 = ( spgum(ji,jj)-gpsuu(ji,jj) ) * umask(ji,jj,1)
+            z2 = ( spgvm(ji,jj)-gpsvv(ji,jj) ) * vmask(ji,jj,1)
+            zcompt=zcompt+tmask(ji,jj,1)
+            zdif1=zdif1+z1
+            zdif2=zdif2+z2
+            zvar1=zvar1+z1*z1
+            zvar2=zvar2+z2*z2
+         END DO
+      END DO
+      IF( lk_mpp )   CALL  mpp_sum( zcompt )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zdif1  )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zdif2  )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zvar1  )   ! sum over the global domain
+      IF( lk_mpp )   CALL  mpp_sum( zvar2  )   ! sum over the global domain
+
+      IF(lwp) WRITE(numout,*) '        zcompt = ',zcompt
+      zdif1=zdif1/zcompt
+      zdif2=zdif2/zcompt
+      IF( zvar1 < 0.) THEN 
+         IF(lwp) THEN
+            WRITE(numout,*)'rrrrrrrrrrrrrrr'
+            WRITE(numout,*)'dia_spr-2:',zvar1
+            WRITE(numout,*)'rrrrrrrrrrrrrrr'
+         ENDIF
+      ENDIF
+      zvar1 = SQRT(zvar1)/zcompt
+      IF( zvar2 < 0. ) THEN 
+         IF(lwp)THEN
+            WRITE(numout,*)'rrrrrrrrrrrrrrr'
+            WRITE(numout,*)'dia_spr-3:',zvar2
+            WRITE(numout,*)'rrrrrrrrrrrrrrr'
+         ENDIF
+      ENDIF
+      zvar2 = SQRT(zvar2)/zcompt
+      
+      IF(lwp) THEN 
+         WRITE(numout,*)
+         WRITE(numout,*) '         gpsx mean error = ',zdif1
+         WRITE(numout,*) '         gpsy mean error = ',zdif2
+         WRITE(numout,*)
+         WRITE(numout,*) '         gpsx var. error = ',zvar1
+         WRITE(numout,*) '         gpsy var. error = ',zvar2
+         WRITE(numout,*)
+         WRITE(numout,*)
+      ENDIF
+      
+      ! reset to zero nmoyps and the mean surface pressure gradient
+      nmoyps = 0
+      spgum(:,:) = 0.e0
+      spgvm(:,:) = 0.e0
+      
+   END SUBROUTINE dia_spr
+
+
+   SUBROUTINE sprmat
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sprmat  ***
+      !!               
+      !! ** Purpose :   construction of the matrix of the surface pressure
+      !!      system and the diagonal preconditioning matrix.
+      !!
+      !! ** Method :
+      !!
+      !! History :
+      !!        !  98-01  (G. Madec & M. Ioualalen)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj, jl                ! dummy loop indices
+      REAL(wp) ::   zcoefs, zcoefw, zcoefe, zcoefn
+      !!----------------------------------------------------------------------
+      
+      
+      ! 0. ocean/land mask at ps-point (computed from surface tmask): spmsk
+      ! --------------------------------------------------------------------
+      
+      ! computation
+      spmsk(:,:) = tmask(:,:,1)
+      
+      ! boundary conditions
+      ! south symmetry: psmsk must be set to 0. on 1
+      IF( nperio == 2 ) THEN
+         spmsk(:, 1 ) = 0.e0
+      ENDIF
+      
+      ! east-west cyclic: spmsk must be set to 0. on 1 and jpi
+      IF( nperio == 1 .OR. nperio == 4 .OR.nperio == 6) THEN 
+         spmsk( 1 ,:) = 0.e0
+         spmsk(jpi,:) = 0.e0
+      ENDIF
+      
+      ! north fold: spmsk must be set to 0. on ligne jpj and on half
+      !                   ligne jpj-1
+      ! T-point pivot
+      IF( nperio == 3 .OR. nperio == 4 ) THEN
+         spmsk(:,jpj) = 0.e0
+         DO ji = jpi/2+1, jpi
+            spmsk(ji,jpjm1) = 0.e0
+         END DO
+      ENDIF
+      ! F-point pivot
+      IF( nperio == 5 .OR. nperio == 6 ) THEN
+         spmsk(:,jpj) = 0.e0
+      ENDIF
+      
+      ! mpp boundary cond.: spmsk is initialized at zero on the overlap
+      ! region for both the preconjugate gradient and the sor algorithms
+
+      IF( nbondi /= -1 .AND. nbondi /= 2 ) THEN
+         DO jl = 1, jpreci
+            spmsk(jl,:) = 0.e0
+         END DO
+      ENDIF
+      IF( nbondi /= 1 .AND. nbondi /= 2 ) THEN
+         DO ji = nlci, jpi
+            spmsk(ji,:) = 0.e0
+         END DO
+      ENDIF
+      IF( nbondj /= -1 .AND. nbondj /= 2 ) THEN
+         DO jl=1,jprecj
+            spmsk(:,jl) = 0.e0
+         END DO
+      ENDIF
+      IF( nbondj /= 1 .AND. nbondj /= 2 ) THEN
+         DO jj = nlcj, jpj
+            spmsk(:,jj) = 0.e0
+         END DO
+      ENDIF
+      
+      ! 1. construction of the matrix
+      ! -----------------------------
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            
+            IF( spmsk(ji,jj) == 0. ) THEN
+               ! land points
+               gcps  (ji,jj,1) = 0.e0
+               gcps  (ji,jj,2) = 0.e0
+               gcps  (ji,jj,3) = 0.e0
+               gcps  (ji,jj,4) = 0.e0
+               gcdpsc(ji,jj  ) = 0.e0
+               gcsmat(ji,jj  ) = 0.e0
+            ELSE
+               ! south coefficient
+               zcoefs = -e1v(ji,jj-1) / e2v(ji,jj-1) * vmask(ji,jj-1,1)
+               gcps(ji,jj,1) = zcoefs
+               ! west coefficient
+               zcoefw = -e2u(ji-1,jj) / e1u(ji-1,jj) * umask(ji-1,jj,1)
+               gcps(ji,jj,2) = zcoefw
+               ! east coefficient
+               zcoefe = -e2u(ji  ,jj) / e1u(ji  ,jj) * umask(ji  ,jj,1)
+               gcps(ji,jj,3) = zcoefe
+               ! north coefficient
+               zcoefn = -e1v(ji,jj  ) / e2v(ji,jj  ) * vmask(ji,jj  ,1)
+               gcps(ji,jj,4) = zcoefn
+               
+               ! diagonal coefficient
+               gcsmat(ji,jj) = -zcoefs-zcoefw-zcoefe-zcoefn
+            ENDIF
+         END DO
+      END DO
+      
+
+      ! 2. boundary conditions 
+      ! ----------------------
+      
+      ! cyclic east-west boundary conditions
+      ! ji=2 is the column east of ji=jpim1 and reciprocally,
+      ! ji=jpim1 is the column west of ji=2
+      ! all the coef are already set to zero as spmask is initialized to
+      ! zero for ji=1 and ji=jpj.
+      
+      ! symetrical conditions
+      ! the diagonal coefficient of the southern grid points must be modify to
+      ! account for the existence of the south symmetric bassin.
+      IF( nperio == 2 ) THEN
+         DO ji = 1, jpi
+            IF( spmsk(ji,2) /= 0 ) THEN
+               zcoefs = e1v(ji,1) / e2v(ji,1)
+               gcsmat(ji,2) = gcsmat(ji,2) - zcoefs
+            ENDIF
+         END DO
+      ENDIF
+      
+      ! North fold boundary condition
+      ! all the coef are already set to zero as bmask is initialized to
+      ! zero on duplicated lignes and portion of lignes
+      
+      
+      ! 3. preconditioned matrix
+      ! ------------------------
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( spmsk(ji,jj) /= 0. ) gcdpsc(ji,jj) = 1.e0 / gcsmat(ji,jj)
+         END DO
+      END DO
+      
+      gcps(:,:,1) = gcps(:,:,1) * gcdpsc(:,:)
+      gcps(:,:,2) = gcps(:,:,2) * gcdpsc(:,:)
+      gcps(:,:,3) = gcps(:,:,3) * gcdpsc(:,:)
+      gcps(:,:,4) = gcps(:,:,4) * gcdpsc(:,:)
+      
+      
+      ! 3. initialization the arrays used in sp solver
+      ! ----------------------------------------------
+      
+      gps  (:,:) = 0.e0
+      gpsuu(:,:) = 0.e0
+      gpsvv(:,:) = 0.e0
+      
+   END SUBROUTINE sprmat
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                    NO surface pressure diagnostics
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_diaspr = .FALSE.   !: surface pressure diag. flag
+CONTAINS
+   SUBROUTINE dia_spr( kt )      ! Empty routine
+      WRITE(*,*) 'dia_spr: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_spr
+#endif
+
+   !!======================================================================
+END MODULE diaspr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4536)
@@ -0,0 +1,667 @@
+MODULE diawri
+   !!======================================================================
+   !!                     ***  MODULE  diawri  ***
+   !! Ocean diagnostics :  write ocean output files
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE sol_oce         ! solver variables
+   USE ice_oce         ! ice variables
+   USE phycst          ! physical constants
+   USE ocfzpt          ! ocean freezing point
+   USE ocesbc          ! surface thermohaline fluxes
+   USE taumod          ! surface stress
+   USE flxrnf          ! ocean runoffs
+   USE zdfmxl          ! mixed layer
+   USE daymod          ! calendar
+   USE dianam          ! build name of file (routine)
+   USE zdfddm          ! vertical  physics: double diffusion
+   USE diahth          ! thermocline diagnostics
+   USE diaspr          ! surface pressure diagnostics (rigid lid case)
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE flx_oce         ! sea-ice/ocean forcings variables
+   USE diadimg         ! dimg direct access file format output
+   USE ioipsl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dia_wri                 ! routines called by step.F90
+   PUBLIC dia_wri_state
+
+   !! * Module variables
+   INTEGER ::   &
+      nid_T, nz_T, nh_T, ndim_T, ndim_hT,      &   ! grid_T file
+      nid_U, nz_U, nh_U, ndim_U, ndim_hU,      &   ! grid_U file
+      nid_V, nz_V, nh_V, ndim_V, ndim_hV,      &   ! grid_V file
+      nid_W, nz_W, nh_W,                       &   ! grid_W file
+      ndex(1)                                      ! ???
+   INTEGER, DIMENSION(jpi*jpj) ::   &
+      ndex_hT, ndex_hU, ndex_hV
+   INTEGER, DIMENSION(jpi*jpj*jpk) ::   &
+      ndex_T, ndex_U, ndex_V
+
+   !! * Substitutions
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_dimgout
+   !!----------------------------------------------------------------------
+   !!   dia_wri       : create the dimg direct access output file (mpp)
+   !!----------------------------------------------------------------------
+#   include "diawri_dimg.h90"
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                   NetCDF output file
+   !!----------------------------------------------------------------------
+   !!   dia_wri       : create the standart NetCDF output files
+   !!   dia_wri_state : create an output NetCDF file for a single
+   !!                   instantaeous ocean state and forcing fields
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dia_wri( kt, kindic )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_wri  ***
+      !!                   
+      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
+      !!      NETCDF format is used by default 
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), 
+      !!      define all the NETCDF files and fields
+      !!      At each time step call histdef to compute the mean if ncessary
+      !!      Each nwrite time step, output the instantaneous or mean fields
+      !!      IF kindic <0, output of fields before the model interruption.
+      !!      IF kindic =0, time step loop
+      !!      IF kindic >0, output of fields before the time step loop
+      !!
+      !! History :
+      !!        !  91-03  (M.-A. Foujols)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  correction restart file
+      !!        !  92-07  (M. Imbard)  split into diawri and rstwri
+      !!        !  93-03  (M. Imbard)  suppress writibm
+      !!        !  98-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
+      !!        !  99-02  (E. Guilyardi)  name of netCDF files + variables
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kindic  ! 
+
+      !! * Local declarations
+      LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
+      CHARACTER (len=40) ::           &
+         clhstnam, clop, clmx            ! temporary names
+      INTEGER ::   inum = 11             ! temporary logical unit
+      INTEGER ::   &
+         iimi, iima, ipk, it,         &  ! temporary integers
+         ijmi, ijma                      !    "          "
+      REAL(wp) ::   &
+         zsto, zout, zmax,            &  ! temporary scalars
+         zjulian, zdt                    !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) :: &
+         zw2d                            ! temporary workspace
+      CHARACTER (len=80) :: clname
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialisation
+      ! -----------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+      IF( nacc == 1 ) zdt = rdtmin
+#if defined key_diainstant
+      zsto = nwrite * zdt
+      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
+      !!! clop="inst(only(x))"   ! put 1.e+20 on land (very expensive!!)
+#else
+      zsto=zdt
+      clop="ave(x)"              ! no use of the mask value (require less cpu time)
+      !!! clop="ave(only(x))"    ! put 1.e+20 on land (very expensive!!)
+#endif
+      zout = nwrite * zdt
+      zmax = ( nitend - nit000 + 1 ) * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nit000 + 1
+
+
+      ! 1. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      IF(ll_print) WRITE(numout,*) 'dia_wri kt = ', kt, ' kindic ', kindic
+
+      IF( kt == nit000 ) THEN
+
+         ! Define the NETCDF files (one per grid)
+
+         ! Compute julian date from starting date of the run
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
+            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
+         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
+                                 ' limit storage in depth = ', ipk
+
+         ! WRITE root name in date.file for use by postpro
+         CALL dia_nam( clhstnam, nwrite,' ' )
+         clname = 'date.file'
+         CALL ctlopn( inum, clname,  'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+         WRITE(inum,*) clhstnam
+         CLOSE(inum)
+
+         ! Define the T grid FILE ( nid_T )
+
+         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
+            &          0, zjulian, zdt, nh_T, nid_T, domain_id=nidom )
+         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
+            &           "m", ipk, gdept_0, nz_T )
+         !                                                            ! Index of ocean points
+         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
+         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
+
+         ! Define the U grid FILE ( nid_U )
+
+         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
+         CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
+            &          0, zjulian, zdt, nh_U, nid_U, domain_id=nidom )
+         CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
+            &           "m", ipk, gdept_0, nz_U )
+         !                                                            ! Index of ocean points
+         CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
+         CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
+
+         ! Define the V grid FILE ( nid_V )
+
+         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
+         CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
+            &          0, zjulian, zdt, nh_V, nid_V, domain_id=nidom )
+         CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
+            &          "m", ipk, gdept_0, nz_V )
+         !                                                            ! Index of ocean points
+         CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
+         CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
+
+         ! Define the W grid FILE ( nid_W )
+
+         CALL dia_nam( clhstnam, nwrite, 'grid_W' )                   ! filename
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
+            &          0, zjulian, zdt, nh_W, nid_W, domain_id=nidom )
+         CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
+            &          "m", ipk, gdepw_0, nz_W )
+
+
+         ! Declare all the output fields as NETCDF variables
+
+         !                                                                                      !!! nid_T : 3D
+         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
+            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         !                                                                                      !!! nid_T : 2D
+         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#if defined key_dynspg_rl
+         CALL histdef( nid_T, "sobarstf","Barotropic StreamFunction"           , "m3/s2"  ,   &  ! bsf
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#else
+         CALL histdef( nid_T, "sossheig", "Sea Surface Height"                 , "m"      ,   &  ! ssh
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+#if ! defined key_dynspg_rl && defined key_ice_lim
+         ! sowaflup = sowaflep + sorunoff + sowafldp + a term associated to
+         !    internal damping to Levitus that can be diagnosed from others
+         ! sowaflcd = sowaflep + sorunoff + sowafldp + iowaflup
+         CALL histdef( nid_T, "iowaflup", "Ice=>ocean net freshwater"          , "kg/m2/s",   &  ! fsalt
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowaflep", "atmos=>ocean net freshwater"        , "kg/m2/s",   &  ! fmass
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! emp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sorunoff", "Runoffs"                            , "Kg/m2/s",   &  ! runoffs
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowaflcd", "concentration/dilution water flux"  , "kg/m2/s",   &  ! emps
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosalflx", "Surface Salt Flux"                  , "Kg/m2/s",   &  ! emps * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qt
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "soicecov", "Ice Cover"                          , "[0,1]"  ,   &  ! freeze
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#if ! defined key_coupled 
+         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+
+#if defined key_flx_core
+         CALL histdef( nid_T, "solhflup", "Latent Heat Flux Upward"         , "W/m2"   ,   &  ! qla
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "solwfldo", "Longwave Radiation downward"     , "W/m2"   ,   &  ! qlw
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosbhfup", "Sensible Heat Flux upward"       , "W/m2"   ,   &  ! qsb
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+
+
+#if ( defined key_coupled && ! defined key_ice_lim ) 
+         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+#if defined key_diaspr
+         CALL histdef( nid_T, "sosurfps", "Surface Pressure"                   , "cm"     ,   &  ! sp
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+         clmx ="l_max(only(x))"    ! max index on a period
+         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
+#if defined key_diahth
+         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "W"      ,   & ! htc3
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif
+
+#if defined key_ice_lim && defined key_coupled
+         CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
+            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+#endif 
+
+         CALL histend( nid_T )
+
+         !                                                                                      !!! nid_U : 3D
+         CALL histdef( nid_U, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! un
+            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
+#if defined key_diaeiv
+         CALL histdef( nid_U, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
+            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
+#endif
+         !                                                                                      !!! nid_U : 2D
+         CALL histdef( nid_U, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! taux
+            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+#if defined key_dynspg_rl
+         CALL histdef( nid_U, "sozospgx", "Zonal Surface Pressure Gradient"    , "N/kg"   ,   &  ! spgu
+            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+#endif
+
+         CALL histend( nid_U )
+
+         !                                                                                      !!! nid_V : 3D
+         CALL histdef( nid_V, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vn
+            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
+#if defined key_diaeiv
+         CALL histdef( nid_V, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
+            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
+#endif
+         !                                                                                      !!! nid_V : 2D
+         CALL histdef( nid_V, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! tauy
+            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+#if defined key_dynspg_rl
+         CALL histdef( nid_V, "somespgy", "Meridional Surface Pressure Grad."  , "N/kg"   ,   &  ! spgv
+            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+#endif
+
+         CALL histend( nid_V )
+
+         !                                                                                      !!! nid_W : 3D
+         CALL histdef( nid_W, "vovecrtz", "Vertical Velocity"                  , "m/s"    ,   &  ! wn
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+#if defined key_diaeiv
+         CALL histdef( nid_W, "voveeivw", "Vertical EIV Velocity"              , "m/s"    ,   &  ! w_eiv
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+#endif
+         CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+
+         CALL histdef( nid_W, "votkeevd", "Enhanced Vertical Diffusivity",       "m2/s"   ,   &  ! avt_evd
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+         !
+         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avmu
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+
+         CALL histdef( nid_W, "votkeevm", "Enhanced Vertical Viscosity",         "m2/s"   ,   &  ! avmu_evd
+            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+
+         IF( lk_zdfddm ) THEN
+            CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
+               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
+         ENDIF
+         !                                                                                      !!! nid_W : 2D
+#if defined key_traldf_c2d
+         CALL histdef( nid_W, "soleahtw", "lateral eddy diffusivity"           , "m2/s"   ,   &  ! ahtw
+            &          jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+# if defined key_traldf_eiv 
+            CALL histdef( nid_W, "soleaeiw", "eddy induced vel. coeff. at w-point", "m2/s",   &  ! aeiw
+               &       jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
+# endif
+#endif
+
+         CALL histend( nid_W )
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
+         IF(ll_print) CALL FLUSH(numout )
+
+      ENDIF
+
+      ! 2. Start writing data
+      ! ---------------------
+
+      ! ndex(1) est utilise ssi l'avant dernier argument est diffferent de 
+      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
+      ! donne le nombre d'elements, et ndex la liste des indices a sortir
+
+      IF( lwp .AND. MOD( kt, nwrite ) == 0 ) THEN 
+         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      ! Write fields on T grid
+      CALL histwrite( nid_T, "votemper", it, tn            , ndim_T , ndex_T  )   ! temperature
+      CALL histwrite( nid_T, "vosaline", it, sn            , ndim_T , ndex_T  )   ! salinity
+      CALL histwrite( nid_T, "sosstsst", it, tn(:,:,1)     , ndim_hT, ndex_hT )   ! sea surface temperature
+      CALL histwrite( nid_T, "sosaline", it, sn(:,:,1)     , ndim_hT, ndex_hT )   ! sea surface salinity
+#if defined key_dynspg_rl
+      CALL histwrite( nid_T, "sobarstf", it, bsfn          , ndim_hT, ndex_hT )   ! barotropic streamfunction
+#else
+      CALL histwrite( nid_T, "sossheig", it, sshn          , ndim_hT, ndex_hT )   ! sea surface height
+#endif
+#if ! defined key_dynspg_rl && defined key_ice_lim
+      CALL histwrite( nid_T, "iowaflup", it, fsalt(:,:)    , ndim_hT, ndex_hT )   ! ice=>ocean water flux
+      CALL histwrite( nid_T, "sowaflep", it, fmass(:,:)    , ndim_hT, ndex_hT )   ! atmos=>ocean water flux
+#endif
+      CALL histwrite( nid_T, "sowaflup", it, emp           , ndim_hT, ndex_hT )   ! upward water flux
+      CALL histwrite( nid_T, "sorunoff", it, runoff        , ndim_hT, ndex_hT )   ! runoff
+      CALL histwrite( nid_T, "sowaflcd", it, emps          , ndim_hT, ndex_hT )   ! c/d water flux
+      zw2d(:,:) = emps(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosalflx", it, zw2d          , ndim_hT, ndex_hT )   ! c/d salt flux
+      CALL histwrite( nid_T, "sohefldo", it, qt            , ndim_hT, ndex_hT )   ! total heat flux
+      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
+      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
+      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
+      CALL histwrite( nid_T, "soicecov", it, freeze        , ndim_hT, ndex_hT )   ! ice cover 
+#if ! defined key_coupled
+      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+      zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+#endif
+#if defined key_flx_core
+      CALL histwrite( nid_T, "solhflup", it, qla           , ndim_hT, ndex_hT )   ! latent heat flux
+      CALL histwrite( nid_T, "solwfldo", it, qlw           , ndim_hT, ndex_hT )   ! longwave heat flux
+      CALL histwrite( nid_T, "sosbhfup", it, qsb           , ndim_hT, ndex_hT )   ! sensible heat flux
+#endif
+#if ( defined key_coupled && ! defined key_ice_lim ) 
+      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+         zw2d(:,:) = erp(:,:) * sn(:,:,1) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+#endif
+#if defined key_diaspr
+      CALL histwrite( nid_T, "sosurfps", it, gps           , ndim_hT, ndex_hT )   ! surface pressure
+#endif
+         zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
+      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
+
+#if defined key_diahth
+      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
+      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
+      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
+      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
+#endif
+#if defined key_ice_lim &&  defined key_coupled 
+      CALL histwrite( nid_T, "soicetem", it, tn_ice        , ndim_hT, ndex_hT )   ! surf. ice temperature
+      CALL histwrite( nid_T, "soicealb", it, alb_ice       , ndim_hT, ndex_hT )   ! ice albedo
+#endif
+         ! Write fields on U grid
+      CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
+#if defined key_diaeiv
+      CALL histwrite( nid_U, "vozoeivu", it, u_eiv         , ndim_U , ndex_U )    ! i-eiv current
+#endif
+      CALL histwrite( nid_U, "sozotaux", it, taux          , ndim_hU, ndex_hU )   ! i-wind stress
+#if defined key_dynspg_rl
+      CALL lbc_lnk( spgu, 'U', -1. )
+      CALL histwrite( nid_U, "sozospgx", it, spgu          , ndim_hU, ndex_hU )   ! i-surf. press. grad.
+#endif
+
+         ! Write fields on V grid
+      CALL histwrite( nid_V, "vomecrty", it, vn            , ndim_V , ndex_V  )   ! j-current
+#if defined key_diaeiv
+      CALL histwrite( nid_V, "vomeeivv", it, v_eiv         , ndim_V , ndex_V  )   ! j-eiv current
+#endif
+      CALL histwrite( nid_V, "sometauy", it, tauy          , ndim_hV, ndex_hV )   ! j-wind stress
+#if defined key_dynspg_rl
+      CALL lbc_lnk( spgv, 'V', -1. )
+      CALL histwrite( nid_V, "somespgy", it, spgv          , ndim_hV, ndex_hV )   ! j-surf. pressure grad.
+#endif
+
+         ! Write fields on W grid
+      CALL histwrite( nid_W, "vovecrtz", it, wn             , ndim_T, ndex_T )    ! vert. current
+#   if defined key_diaeiv
+      CALL histwrite( nid_W, "voveeivw", it, w_eiv          , ndim_T, ndex_T )    ! vert. eiv current
+#   endif
+      CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
+      CALL histwrite( nid_W, "votkeevd", it, avt_evd        , ndim_T, ndex_T )    ! T enhan. vert. eddy diff. coef.
+      CALL histwrite( nid_W, "votkeavm", it, avmu           , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
+      CALL histwrite( nid_W, "votkeevm", it, avmu_evd       , ndim_T, ndex_T )    ! T enhan. vert. eddy visc. coef.
+      IF( lk_zdfddm ) THEN
+         CALL histwrite( nid_W, "voddmavs", it, fsavs(:,:,:), ndim_T, ndex_T )    ! S vert. eddy diff. coef.
+      ENDIF
+#if defined key_traldf_c2d
+      CALL histwrite( nid_W, "soleahtw", it, ahtw          , ndim_hT, ndex_hT )   ! lateral eddy diff. coef.
+# if defined key_traldf_eiv
+         CALL histwrite( nid_W, "soleaeiw", it, aeiw       , ndim_hT, ndex_hT )   ! EIV coefficient at w-point
+# endif
+#endif
+
+      ! 3. Synchronise and close all files
+      ! ---------------------------------------
+      IF( MOD( kt, nwrite ) == 0 .OR. kindic < 0 ) THEN
+         CALL histsync( nid_T )
+         CALL histsync( nid_U )
+         CALL histsync( nid_V )
+         CALL histsync( nid_W )
+      ENDIF
+
+      !  Create an output files (output.abort.nc) if S < 0 or u > 20 m/s
+      IF( kindic < 0 )   CALL dia_wri_state( 'output.abort' )
+
+      IF( kt == nitend .OR. kindic < 0 ) THEN
+         CALL histclo( nid_T )
+         CALL histclo( nid_U )
+         CALL histclo( nid_V )
+         CALL histclo( nid_W )
+      ENDIF
+
+   END SUBROUTINE dia_wri
+
+
+   SUBROUTINE dia_wri_state( cdfile_name )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dia_wri_state  ***
+      !!        
+      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
+      !!      the instantaneous ocean state and forcing fields.
+      !!        Used to find errors in the initial state or save the last
+      !!      ocean state in case of abnormal end of a simulation
+      !!
+      !! ** Method  :   NetCDF files using ioipsl
+      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
+      !!      File 'output.abort.nc' is created in case of abnormal job end
+      !!
+      !! History :
+      !!   8.2  !  00-06  (M. Imbard)  Original code (diabort.F)
+      !!   8.5  !  02-06  (A.Bozec, E. Durand)  Original code (diainit.F)
+      !!   9.0  !  02-12  (G. Madec)  merge of diabort and diainit, F90
+      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER (len=* ), INTENT( in ) ::   &
+         cdfile_name      ! name of the file created
+
+      !! * Local declarations
+      CHARACTER (len=32) :: clname
+      CHARACTER (len=40) :: clop
+      INTEGER  ::   &
+         id_i , nz_i, nh_i       
+      INTEGER, DIMENSION(1) ::   &
+         idex             ! temprary workspace
+      REAL(wp) ::   &
+         zsto, zout, zmax,   &
+         zjulian, zdt
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialisation
+      ! -----------------
+
+      ! Define name, frequency of output and means
+      clname = cdfile_name
+#if defined key_agrif
+      if ( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+#endif
+      zdt  = rdt
+      zsto = rdt
+      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
+      zout = rdt
+      zmax = ( nitend - nit000 + 1 ) * zdt
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
+      IF(lwp) WRITE(numout,*) '                and named :', clname, '.nc'
+
+
+      ! 1. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      ! Compute julian date from starting date of the run
+      CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )         ! time axis 
+      CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
+          1, jpi, 1, jpj, 0, zjulian, zdt, nh_i, id_i, domain_id=nidom )          ! Horizontal grid : glamt and gphit
+      CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
+          "m", jpk, gdept_0, nz_i)
+
+      ! Declare all the output fields as NetCDF variables
+
+      CALL histdef( id_i, "vosaline", "Salinity"              , "PSU"    ,   &   ! salinity
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+      CALL histdef( id_i, "votemper", "Temperature"           , "C"      ,   &   ! temperature
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+#if defined key_dynspg_rl
+      CALL histdef( id_i, "sobarstf","Barotropic StreamFunction", "m3/s2"  ,   &  ! bsf
+         &          jpi, jpj, nh_i, 1  , 1, 1  , nz_i, 32, clop, zsto, zout )
+#else
+      CALL histdef( id_i, "sossheig", "Sea Surface Height"    , "m"      ,   &  ! ssh
+         &          jpi, jpj, nh_i, 1  , 1, 1  , nz_i, 32, clop, zsto, zout )
+#endif
+      CALL histdef( id_i, "vozocrtx", "Zonal Current"         , "m/s"    ,   &   ! zonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+      CALL histdef( id_i, "vomecrty", "Meridional Current"    , "m/s"    ,   &   ! meridonal current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
+      CALL histdef( id_i, "vovecrtz", "Vertical Velocity"     , "m/s"    ,   &   ! vertical current
+         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
+      CALL histdef( id_i, "sowaflup", "Net Upward Water Flux" , "Kg/m2/S",   &   ! net freshwater 
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "sohefldo", "Net Downward Heat Flux", "W/m2"   ,   &   ! net heat flux
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "soshfldo", "Shortwave Radiation"   , "W/m2"   ,   &   ! solar flux
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "soicecov", "Ice fraction"          , "[0,1]"  ,   &   ! freeze
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "sozotaux", "Zonal Wind Stress"     , "N/m2"   ,   &   ! i-wind stress
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      CALL histdef( id_i, "sometauy", "Meridional Wind Stress", "N/m2"   ,   &   ! j-wind stress
+         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+
+      CALL histend( id_i )
+
+      ! 2. Start writing data
+      ! ---------------------
+      ! idex(1) est utilise ssi l'avant dernier argument est diffferent de 
+      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
+      ! donne le nombre d'elements, et idex la liste des indices a sortir
+      idex(1) = 1   ! init to avoid compil warning
+
+      ! Write all fields on T grid
+      CALL histwrite( id_i, "votemper", 1, tn    , jpi*jpj*jpk, idex )    ! now temperature
+      CALL histwrite( id_i, "vosaline", 1, sn    , jpi*jpj*jpk, idex )    ! now salinity
+#if defined key_dynspg_rl
+      CALL histwrite( id_i, "sobarstf", 1, bsfn  , jpi*jpj    , idex )    ! barotropic streamfunction
+#else
+      CALL histwrite( id_i, "sossheig", 1, sshn  , jpi*jpj    , idex )    ! sea surface height
+#endif
+      CALL histwrite( id_i, "vozocrtx", 1, un    , jpi*jpj*jpk, idex )    ! now i-velocity
+      CALL histwrite( id_i, "vomecrty", 1, vn    , jpi*jpj*jpk, idex )    ! now j-velocity
+      CALL histwrite( id_i, "vovecrtz", 1, wn    , jpi*jpj*jpk, idex )    ! now k-velocity
+      CALL histwrite( id_i, "sowaflup", 1, emp   , jpi*jpj    , idex )    ! freshwater budget
+      CALL histwrite( id_i, "sohefldo", 1, qt    , jpi*jpj    , idex )    ! total heat flux
+      CALL histwrite( id_i, "soshfldo", 1, qsr   , jpi*jpj    , idex )    ! total heat flux
+      CALL histwrite( id_i, "soicecov", 1, freeze, jpi*jpj    , idex )    ! ice cover
+      CALL histwrite( id_i, "sozotaux", 1, taux  , jpi*jpj    , idex )    ! i-wind stress
+      CALL histwrite( id_i, "sometauy", 1, tauy  , jpi*jpj    , idex )    ! j-wind stress
+
+      ! 3. Close the file
+      ! -----------------
+      CALL histclo( id_i )
+
+   END SUBROUTINE dia_wri_state
+
+#endif
+   !!======================================================================
+END MODULE diawri
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri_dimg.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 4536)
@@ -0,0 +1,441 @@
+  !!----------------------------------------------------------------------
+  !!                        ***  diawri_dimg.h90  ***
+  !!----------------------------------------------------------------------
+  !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+  !! $Header$ 
+  !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+  !!----------------------------------------------------------------------
+
+  SUBROUTINE dia_wri (kt, kindic)
+    !!----------------------------------------------------------------------
+    !!           *** routine dia_wri ***
+    !!
+    !! ** Purpose : output dynamics and tracer fields on direct access file
+    !!              suitable for MPP computing
+    !!
+    !! ** define key : 'key_dimgout'
+    !!
+    !! **  Method : Default is to cumulate the values over the interval between
+    !!      2 output, and each nwrite time-steps  the mean value is  computed 
+    !!      and written to the direct access file.
+    !!     If 'key_diainstant' is defined, no mean values are computed and the 
+    !!     instantaneous fields are dump.
+    !!     kindic is 0 or >0 in normal condition. When < 0 it indicates an error
+    !!     condition and instantaneous file output is forced.
+    !!       Each processor creates its own file with its local data
+    !!     Merging all the files is performed off line by a dedicated program
+    !!
+    !! ** Arguments :
+    !!     kt      : time-step number
+    !!     kindinc :  error condition indicator : >=0 :  OK, < 0 : error.
+    !!
+    !! ** Naming convention for files
+    !!
+    !! {cexper}_{var}_y----m--d--.dimg
+    !!   cexper is the name of the experience, given in the namelist
+    !!   var can be either U, V, T, S, KZ, SSH, ...
+    !!   var can also be 2D, which means that each level of the file is a 2D field as described below
+    !!    y----m--d--  is the date at the time of the dump
+    !!    For mpp output, each processor dumps its own memory, on appropriate record range 
+    !!    (direct access : for level jk of a klev field on proc narea irec = 1+ klev*(narea -1) + jk )
+    !!    To be tested with a lot of procs !!!!
+    !!
+    !!  level 1:  taux(:,:) * umask(:,:,1) zonal stress in N.m-2
+    !!  level 2:  tauy(:,:) * vmask(:,:,1) meridional stress in N. m-2
+    !!  level 3:   qt  (:,:)               total heat flux (W/m2)
+    !!  level 4:   emp (:,:)               E-P flux (mm/day)
+    !!  level 5:  tb  (:,:,1)-sst          model SST -forcing sst (degree C)
+    !!  level 6:  bsfb(:,:)		   streamfunction (m**3/s)
+    !!  level 7:  qsr (:,:)		   solar flux (W/m2)
+    !!  level 8:  qrp (:,:)                relax component of T flux.
+    !!  level 9:  erp (:,:)                relax component of S flux
+    !!  level 10: hmld(:,:)                turbocline depth
+    !!  level 11: hmlp(:,:)                mixed layer depth
+    !!  level 12: freeze (:,:)             Ice cover (1. or 0.)
+    !!  level 13: sst(:,:)                 the observed SST we relax to.
+    !!  level 14: qct(:,:)                 equivalent flux due to treshold SST
+    !!  level 15: fbt(:,:)                 feedback term .
+    !!  level 16: emps(:,:)                concentration/dilution water flux
+    !!  level 17: fsalt(:,:)               Ice=>ocean net freshwater
+    !!  level 18: gps(:,:)                 the surface pressure (m).
+    !!  level 19: spgu(:,:)                the surface pressure gradient in X direction.
+    !!  level 20: spgv(:,:)                the surface pressure gradient in Y direction.
+    !! 
+    !! History 
+    !!      original  : 91-03 ()
+    !!      additions : 91-11 (G. Madec)
+    !!      additions : 92-06 (M. Imbard) correction restart file
+    !!      additions : 92-07 (M. Imbard) split into diawri and rstwri
+    !!      additions : 93-03 (M. Imbard) suppress writibm
+    !!      additions : 94-12 (M. Imbard) acces direct files
+    !!      additions : 97-2002 ( Clipper Group ) dimg files
+    !!                  dec 2003 ( J.M. Molines) f90, mpp output for OPA9.0
+    !!   9.0  !  05-05  (S. Theetten) add emps fsalt move gps spgu spgv 2 lines below
+    !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+    !!----------------------------------------------------------------------
+    !! * modules used
+    USE lib_mpp
+    USE dtasst, ONLY : sst
+
+    !! * Arguments
+    INTEGER ,INTENT(in) :: kt, kindic
+
+    !! * local declarations
+    INTEGER :: inbsel, jk
+!!  INTEGER :: iwrite
+    INTEGER :: iyear,imon,iday
+    INTEGER, SAVE :: nmoyct 
+
+#if defined key_diainstant
+    LOGICAL, PARAMETER :: ll_dia_inst=.TRUE.  !: for instantaneous output
+#else
+    LOGICAL, PARAMETER :: ll_dia_inst=.FALSE. !: for average output
+#endif
+
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  um , vm   ! used to compute mean u, v fields
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  wm        ! used to compute mean w fields
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  avtm      ! used to compute mean kz fields
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  tm , sm   ! used to compute mean t, s fields
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  fsel      ! used to compute mean 2d fields
+    REAL(wp) :: zdtj
+    !
+    CHARACTER(LEN=80) :: clname
+    CHARACTER(LEN=80) :: cltext
+    CHARACTER(LEN=80) :: clmode
+    CHARACTER(LEN= 4) :: clver
+    !
+    !  Initialization
+    !  ---------------
+    !
+#ifdef key_diaspr
+    inbsel = 20
+#else
+    inbsel = 17
+#endif
+#if defined key_flx_core
+    inbsel = 23
+#endif
+
+    IF( inbsel >  jpk) THEN
+       IF( lwp) WRITE(numout,*)  &
+            ' STOP inbsel =',inbsel,' is larger than jpk=',jpk
+       STOP
+    ENDIF
+
+
+    iyear = ndastp/10000
+    imon = (ndastp-iyear*10000)/100
+    iday = ndastp - imon*100 - iyear*10000
+
+    !     
+    !! dimg format V1.0 should start with the 4 char. string '@!01'
+    !!
+    clver='@!01'
+    !
+    IF( .NOT. ll_dia_inst ) THEN
+       !
+       !! * Mean output section
+       !! ----------------------
+       !
+       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
+            'THE OUTPUT FILES CONTAINS THE AVERAGE OF EACH FIELD'
+       !
+       IF( kt == nit000  ) THEN
+          ! reset arrays for average computation
+          nmoyct = 0
+          !
+          um(:,:,:) = 0._wp
+          vm(:,:,:) = 0._wp
+          wm(:,:,:) = 0._wp
+          avtm(:,:,:) = 0._wp
+          tm(:,:,:) = 0._wp
+          sm(:,:,:) = 0._wp
+          fsel(:,:,:) = 0._wp
+          !
+       ENDIF
+
+       !  cumulate values
+       !  ---------------
+
+       nmoyct = nmoyct+1
+       !
+       um(:,:,:)=um(:,:,:) + un (:,:,:)
+       vm(:,:,:)=vm(:,:,:) + vn (:,:,:)
+       wm(:,:,:)=wm(:,:,:) + wn (:,:,:)
+       avtm(:,:,:)=avtm(:,:,:) + avt (:,:,:)
+       tm(:,:,:)=tm(:,:,:) + tn (:,:,:)
+       sm(:,:,:)=sm(:,:,:) + sn (:,:,:)
+       !
+       fsel(:,:,1 ) = fsel(:,:,1 ) + taux(:,:) * umask(:,:,1)
+       fsel(:,:,2 ) = fsel(:,:,2 ) + tauy(:,:) * vmask(:,:,1)
+       fsel(:,:,3 ) = fsel(:,:,3 ) + qt  (:,:) 
+       fsel(:,:,4 ) = fsel(:,:,4 ) + emp (:,:)
+       fsel(:,:,5 ) = fsel(:,:,5 ) + tb  (:,:,1) - sst(:,:)
+#if ! defined key_dynspg_rl
+       fsel(:,:,6 ) = fsel(:,:,6 ) + sshn(:,:)    ! SSH
+#else
+       fsel(:,:,6 ) = fsel(:,:,6 ) + bsfn(:,:)    ! BSF
+#endif
+       fsel(:,:,7 ) = fsel(:,:,7 ) + qsr(:,:)
+       fsel(:,:,8 ) = fsel(:,:,8 ) + qrp (:,:)
+       fsel(:,:,9 ) = fsel(:,:,9 ) + erp (:,:)
+       fsel(:,:,10) = fsel(:,:,10) + hmld(:,:)
+       fsel(:,:,11) = fsel(:,:,11) + hmlp(:,:)
+       fsel(:,:,12) = fsel(:,:,12) + freeze(:,:)
+       fsel(:,:,13) = fsel(:,:,13) + sst(:,:)
+       !        fsel(:,:,14) = fsel(:,:,14) + qct(:,:)
+       !        fsel(:,:,15) = fsel(:,:,15) + fbt(:,:)
+       fsel(:,:,16) = fsel(:,:,16) + emps(:,:)
+#if defined key_ice_lim
+       fsel(:,:,17) = fsel(:,:,17) + fsalt(:,:)
+#endif
+#ifdef key_diaspr   
+       fsel(:,:,18) = fsel(:,:,18) + gps(:,:)/g 
+#endif
+#if defined key_flx_core
+       fsel(:,:,21) = fsel(:,:,21) + qla(:,:)
+       fsel(:,:,22) = fsel(:,:,22) + qlw(:,:)
+       fsel(:,:,23) = fsel(:,:,23) + qsb(:,:)
+#endif
+       !
+       ! Output of dynamics and tracer fields and selected fields (numwri)
+       ! -----------------------------------------------------------------
+       !
+       !
+       zdtj=rdt/86400.   ! time step in days
+       WRITE(clmode,'(f5.1,a)' ) nwrite*zdtj,' days average'
+
+       !       iwrite=NINT(adatrj/rwrite)
+       !      IF (abs(adatrj-iwrite*rwrite) < zdtj/2.      &
+
+       IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
+            &   .OR.       kindic <   0            &
+            &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
+          ! it is time to make a dump on file 
+          ! compute average
+          um(:,:,:) = um(:,:,:) / nmoyct
+          vm(:,:,:) = vm(:,:,:) / nmoyct
+          wm(:,:,:) = wm(:,:,:) / nmoyct
+          avtm(:,:,:) = avtm(:,:,:) / nmoyct
+          tm(:,:,:) = tm(:,:,:) / nmoyct
+          sm(:,:,:) = sm(:,:,:) / nmoyct
+          !
+          fsel(:,:,:) = fsel(:,:,:) / nmoyct
+          !
+          ! note : the surface pressure is not averaged, but rather 
+          ! computed from the averaged gradients.
+          !
+#ifdef key_diaspr
+          fsel(:,:,18)= gps(:,:)/g
+          fsel(:,:,19)= spgu(:,:)
+          fsel(:,:,20)= spgv(:,:)
+#endif
+          ! mask mean field with tmask except taux tauy (1,2)
+          DO jk=3,inbsel
+            fsel(:,:,jk)=fsel(:,:,jk)*tmask(:,:,1)
+          END DO
+       ENDIF
+       !
+    ELSE   ! ll_dia_inst true
+       !
+       !! * Instantaneous output section
+       !! ------------------------------
+       !
+       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
+            'THE OUTPUT FILES CONTAINS INSTANTANEOUS VALUES OF EACH FIELD'
+       !
+       zdtj=rdt/86400.   ! time step in days
+       !  iwrite=NINT(adatrj/rwrite)
+       clmode='instantaneous'
+       !     IF (abs(adatrj-iwrite*rwrite) < zdtj/2.  &
+       IF (  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
+            &   .OR.       kindic <   0            &
+            &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
+          !
+          ! transfer wp arrays to sp arrays for dimg files
+          fsel(:,:,:) = 0._wp
+          !
+          fsel(:,:,1 ) = taux(:,:) * umask(:,:,1)
+          fsel(:,:,2 ) = tauy(:,:) * vmask(:,:,1)
+          fsel(:,:,3 ) = qt  (:,:) * tmask(:,:,1)
+          fsel(:,:,4 ) = emp (:,:) * tmask(:,:,1)
+          fsel(:,:,5 ) = (tb  (:,:,1) -sst(:,:)) *tmask(:,:,1)
+
+#if ! defined key_dynspg_rl
+          fsel(:,:,6 ) = sshn(:,:)
+#else
+          fsel(:,:,6 ) = bsfn(:,:)
+#endif
+          fsel(:,:,7 ) = qsr (:,:) * tmask(:,:,1)
+          fsel(:,:,8 ) = qrp (:,:) * tmask(:,:,1)
+          fsel(:,:,9 ) = erp (:,:) * tmask(:,:,1)
+          fsel(:,:,10) = hmld(:,:) * tmask(:,:,1)
+          fsel(:,:,11) = hmlp(:,:) * tmask(:,:,1)
+          fsel(:,:,12) = freeze(:,:) * tmask(:,:,1)
+          fsel(:,:,13) =  sst(:,:)  
+          !         fsel(:,:,14) =  qct(:,:)
+          !         fsel(:,:,15) =  fbt(:,:)
+          fsel(:,:,16) =  emps(:,:) * tmask(:,:,1)
+#if defined key_ice_lim
+          fsel(:,:,17) =  fsalt(:,:) * tmask(:,:,1)
+#endif
+#ifdef key_diaspr           
+          fsel(:,:,18) =      gps(:,:) /g
+          fsel(:,:,19) =      spgu(:,:)
+          fsel(:,:,20) =      spgv(:,:)
+#endif
+#if defined key_flx_core
+          fsel(:,:,21) =  qla(:,:)* tmask(:,:,1)
+          fsel(:,:,22) =  qlw(:,:)* tmask(:,:,1)
+          fsel(:,:,23) =  qsb(:,:)* tmask(:,:,1)
+#endif
+          !
+          !         qct(:,:) = 0._wp
+       ENDIF
+    ENDIF
+    !
+    ! Opening of the datrj.out file with the absolute time in day of each dump
+    ! this file gives a record of the dump date for post processing ( ASCII file )
+    !
+    IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
+         &   .OR.       kindic <   0            &
+         &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
+
+       IF( lwp) WRITE(numout,*)'Days since the begining of the run :',adatrj
+
+       !! * U section
+
+       WRITE(clname,9000) TRIM(cexper),'U',iyear,imon,iday
+       cltext=TRIM(cexper)//' U(m/s) '//TRIM(clmode)
+       IF ( kindic < 0 )   cltext=TRIM(cexper)//' U(m/s)  instantaneous (explosion)'
+       !
+       IF( ll_dia_inst) THEN 
+          CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
+
+       ELSE 
+          IF( kindic ==  -3 ) THEN
+             ! ... in case of explosion on umax, dump instantateous u field instead of mean.
+             CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
+          ELSE
+             CALL dia_wri_dimg(clname, cltext, um, jpk, 'T')
+          ENDIF
+       ENDIF
+
+       !! * V section
+
+       WRITE(clname,9000) TRIM(cexper),'V',iyear,imon,iday
+       cltext=TRIM(cexper)//' V(m/s) '//TRIM(clmode)
+       !
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, vn, jpk, 'T')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, vm, jpk, 'T')
+       ENDIF
+       !
+
+       !! * KZ section
+
+       WRITE(clname,9000) TRIM(cexper),'KZ',iyear,imon,iday
+       cltext=TRIM(cexper)//' KZ(m2/s) '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, avt, jpk, 'W')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, avtm, jpk, 'W')
+       ENDIF
+       !
+
+       !! * W section
+
+       WRITE(clname,9000) TRIM(cexper),'W',iyear,imon,iday
+       cltext=TRIM(cexper)//' W(m/s) '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, wn, jpk, 'W')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, wm, jpk, 'W')
+       ENDIF
+
+       !! * T section
+
+       WRITE(clname,9000) TRIM(cexper),'T',iyear,imon,iday
+       cltext=TRIM(cexper)//' T (DegC) '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, tn, jpk, 'T')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, tm, jpk, 'T')
+       ENDIF
+       !
+
+       !! * S section
+
+       WRITE(clname,9000) TRIM(cexper),'S',iyear,imon,iday
+       cltext=TRIM(cexper)//' S (PSU) '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, sn, jpk, 'T')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, sm, jpk, 'T')
+       ENDIF
+       !
+
+       !! * 2D section
+
+       WRITE(clname,9000) TRIM(cexper),'2D',iyear,imon,iday
+       cltext='2D fields '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, fsel, inbsel, '2')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, fsel, inbsel, '2')
+       ENDIF
+
+       IF( lk_mpp )   CALL mppsync   ! synchronization in mpp
+
+       !! * Log message in numout 
+
+       IF( lwp)WRITE(numout,*) ' '
+       IF( lwp)WRITE(numout,*) ' **** WRITE in numwri ',kt
+
+       IF( lwp .AND.        ll_dia_inst) WRITE(numout,*) '    instantaneous fields'
+       IF( lwp .AND. .NOT.  ll_dia_inst) WRITE(numout,*) '    average fields with ',nmoyct,'pdt'
+       !
+       !
+       !! * Reset cumulating arrays  and counter to 0 after writing
+       !
+       IF( .NOT. ll_dia_inst ) THEN
+          nmoyct = 0
+          !
+          um(:,:,:) = 0._wp
+          vm(:,:,:) = 0._wp
+          wm(:,:,:) = 0._wp
+          tm(:,:,:) = 0._wp
+          sm(:,:,:) = 0._wp
+          fsel(:,:,:) = 0._wp
+          avtm(:,:,:) = 0._wp
+       ENDIF
+    ENDIF
+    !
+9000 FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
+
+  END SUBROUTINE dia_wri
+
+  SUBROUTINE dia_wri_state ( cdfile_name)
+    !!-------------------------------------------------------------------
+    !!        ***     ROUTINE dia_wri_state  ***
+    !!
+    !! ** Purpose :   Dummy routine for compatibility with IOIPSL output
+    !!
+    !! ** History :
+    !!      9.O  ! 03-06  (J.M. Molines ) dimgout
+    !!--------------------------------------------------------------------
+    !! * Arguments
+    CHARACTER (len=*), INTENT(in) ::   cdfile_name   ! name of the file created 
+    !!--------------------------------------------------------------------
+
+    IF( lwp) WRITE(numout,*) 'dia_wri_state: Dummy call', cdfile_name
+    IF( lwp) WRITE(numout,*) '-------------'
+    IF( lwp) WRITE(numout,*)
+
+  END SUBROUTINE dia_wri_state
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/closea.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/closea.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/closea.F90	(revision 4536)
@@ -0,0 +1,324 @@
+MODULE closea
+   !!======================================================================
+   !!                       ***  MODULE  closea  ***
+   !! Closed Seas  : 
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_clo    : modification of the ocean domain for closed seas cases
+   !!   flx_clo    : Special handling of closed seas
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE ocesbc          ! ocean surface boundary conditions (fluxes)
+   USE flxrnf          ! runoffs
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ???
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dom_clo      ! routine called by dom_init
+   PUBLIC flx_clo      ! routine called by step
+
+   !! * Share module variables
+   INTEGER, PUBLIC, PARAMETER ::   &  !:
+      jpncs   = 4               !: number of closed sea
+   INTEGER, PUBLIC ::          & !!: namclo : closed seas and lakes
+      nclosea =  0                !: = 0 no closed sea or lake
+      !                           !  = 1 closed sea or lake in the domain
+   INTEGER, PUBLIC, DIMENSION (jpncs) ::   &  !:
+      ncstt,           &  !: Type of closed sea
+      ncsi1, ncsj1,    &  !: closed sea limits                                                                 
+      ncsi2, ncsj2,    &  !: 
+      ncsnr               !: number of point where run-off pours
+   INTEGER, PUBLIC, DIMENSION (jpncs,4) ::   &
+      ncsir, ncsjr        !: Location of run-off
+
+   !! * Module variable
+   REAL(wp), DIMENSION (jpncs+1) ::   &
+      surf               ! closed sea surface
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/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
+      !!
+      !! History :
+      !!        !  01-04  (E. Durand)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   jc            ! dummy loop indices
+      !!----------------------------------------------------------------------
+      
+      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 ( 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 1 : west part of the Black Sea 
+            ncsnr(3)   = 1    ; ncstt(3)   =   2            !            (ie west of the cyclic b.c.)
+            ncsi1(3)   = 174  ; ncsj1(3)   = 107            ! put in Med Sea
+            ncsi2(3)   = 181  ; ncsj2(3)   = 112
+            ncsir(3,1) = 171  ; ncsjr(3,1) = 106 
+            !                                            ! Black Sea 2 : est part of the Black Sea 
+            ncsnr(4)   =   1  ;  ncstt(4)   =   2           !               (ie est of the cyclic b.c.)
+            ncsi1(4)   =   2  ;  ncsj1(4)   = 107           ! put in Med Sea
+            ncsi2(4)   =   6  ;  ncsj2(4)   = 112
+            ncsir(4,1) = 171  ;  ncsjr(4,1) = 106 
+
+            !                                        ! =======================
+         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 flx_clo( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_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 :
+      !!
+      !! History :
+      !!   8.2  !  00-05  (O. Marti)  Original code
+      !!   8.5  !  02-07  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT (in) :: kt
+
+      !! * Local declarations
+      REAL(wp), DIMENSION (jpncs) :: zemp
+      INTEGER  :: ji, jj, jc, jn
+      REAL(wp) :: zze2
+      !!----------------------------------------------------------------------
+
+      ! 1 - Initialisation
+      ! ------------------
+
+      IF( kt == nit000 ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'flx_clo : closed seas '
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+
+         ! Total surface of ocean
+         surf(jpncs+1) = SUM( e1t(:,:) * e2t(:,:) * tmask_i(:,:) )
+
+         DO jc = 1, jpncs
+            surf(jc) =0.e0
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  ! surface of closed seas
+                  surf(jc) = surf(jc) + e1t(ji,jj)*e2t(ji,jj)*tmask_i(ji,jj)
+                  ! upstream in closed seas
+                  upsadv(ji,jj) = 0.5
+               END DO 
+            END DO 
+            ! upstream at closed sea outflow
+            IF( ncstt(jc) >= 1 ) THEN 
+                DO jn = 1, 4
+                  ji = mi0( ncsir(jc,jn) )
+                  jj = mj0( ncsjr(jc,jn) )
+                  upsrnfh(ji,jj) = MAX( upsrnfh(ji,jj), 1.0 )
+                END DO 
+            ENDIF 
+         END DO 
+         IF( lk_mpp )   CALL mpp_sum ( surf, jpncs+1 )       ! mpp: sum over all the global domain
+
+         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
+
+         ! jpncs+1 : surface of sea, closed seas excluded
+         DO jc = 1, jpncs
+            surf(jpncs+1) = surf(jpncs+1) - surf(jc)
+         END DO           
+ 
+      ENDIF
+
+      ! 2 - Computation
+      ! ---------------
+      zemp = 0.e0
+
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               zemp(jc) = zemp(jc) + e1t(ji,jj) * e2t(ji,jj) * emp(ji,jj) * tmask_i(ji,jj)
+            END DO  
+         END DO 
+      END DO
+      IF( lk_mpp )   CALL mpp_sum ( zemp , jpncs )       ! mpp: sum over all the global domain
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
+         zze2    = ( zemp(3) + zemp(4) ) / 2.
+         zemp(3) = zze2
+         zemp(4) = zze2
+      ENDIF
+
+      DO jc = 1, jpncs
+
+         IF( ncstt(jc) == 0 ) THEN 
+            ! water/evap excess is shared by all open ocean
+            emp (:,:) = emp (:,:) + zemp(jc) / surf(jpncs+1)
+            emps(:,:) = emps(:,:) + zemp(jc) / surf(jpncs+1)
+         ELSEIF( ncstt(jc) == 1 ) THEN 
+            ! Excess water in open sea, at outflow location, excess evap shared
+            IF ( zemp(jc) <= 0.e0 ) 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 
+                      emp (ji,jj) = emp (ji,jj) + zemp(jc) /   &
+                         (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                      emps(ji,jj) = emps(ji,jj) + zemp(jc) /   &
+                          (FLOAT(ncsnr(jc)) * e1t(ji,jj) * e2t(ji,jj))
+                  END IF 
+                END DO 
+            ELSE 
+                emp (:,:) = emp (:,:) + zemp(jc) / surf(jpncs+1)
+                emps(:,:) = emps(:,:) + zemp(jc) / surf(jpncs+1)
+            ENDIF
+         ELSEIF( ncstt(jc) == 2 ) THEN 
+            ! Excess e-p+r (either sign) goes to open ocean, at outflow location
+            IF(      ji > 1 .AND. ji < jpi    &
+               .AND. jj > 1 .AND. jj < jpj ) THEN 
+                DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  emp (ji,jj) = emp (ji,jj) + zemp(jc)   &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                  emps(ji,jj) = emps(ji,jj) + zemp(jc)   &
+                      / (FLOAT(ncsnr(jc)) *  e1t(ji,jj) * e2t(ji,jj) )
+                END DO 
+            ENDIF 
+         ENDIF 
+
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               emp (ji,jj) = emp (ji,jj) - zemp(jc) / surf(jc)
+               emps(ji,jj) = emps(ji,jj) - zemp(jc) / surf(jc)
+            END DO  
+         END DO 
+
+      END DO 
+
+
+      ! 5. Boundary condition on emp and emps
+      ! -------------------------------------
+      CALL lbc_lnk( emp , 'T', 1. )
+      CALL lbc_lnk( emps, 'T', 1. )
+
+   END SUBROUTINE flx_clo
+
+   !!======================================================================
+END MODULE closea
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4536)
@@ -0,0 +1,198 @@
+MODULE dom_oce
+   !!======================================================================
+   !!                       ***  MODULE dom_oce  ***
+   !! ** Purpose :   Define in memory all the ocean space domain variables
+   !!======================================================================
+   !! History :  1.0  !  05-10  (A. Beckmann, G. Madec)  reactivate s-coordinate 
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC           ! allows the acces to par_oce when dom_oce is used
+   !                ! exception to coding rules... to be suppressed ???
+
+   !!----------------------------------------------------------------------
+   !! space domain parameters
+   !! -----------------------
+   LOGICAL, PUBLIC ::   lzoom      =  .FALSE.      !: zoom flag
+   LOGICAL, PUBLIC ::   lzoom_e    =  .FALSE.      !: East  zoom type flag
+   LOGICAL, PUBLIC ::   lzoom_w    =  .FALSE.      !: West  zoom type flag
+   LOGICAL, PUBLIC ::   lzoom_s    =  .FALSE.      !: South zoom type flag
+   LOGICAL, PUBLIC ::   lzoom_n    =  .FALSE.      !: North zoom type flag
+   LOGICAL, PUBLIC ::   lzoom_arct =  .FALSE.      !: ORCA    arctic zoom flag
+   LOGICAL, PUBLIC ::   lzoom_anta =  .FALSE.      !: ORCA antarctic zoom flag
+
+   !                                              !!! namdom : space domain (bathymetry, mesh)
+   INTEGER, PUBLIC ::   ntopo   =  0               !: = 0/1 ,compute/read the bathymetry file
+   INTEGER, PUBLIC ::   ngrid   =  0               !: = 0/1, compute/read the horizontal mesh file
+   INTEGER, PUBLIC ::   nmsh    =  0               !: = 1 create a mesh-mask file
+
+   !                                              !!! domain parameters linked to mpp
+   INTEGER, PUBLIC ::   nperio                     !: type of lateral boundary condition
+   INTEGER, PUBLIC ::   nimpp , njmpp              !: i- & j-indexes for mpp-subdomain left bottom
+   INTEGER, PUBLIC ::   nreci , nrecj              !: overlap region in i and j
+   INTEGER, PUBLIC ::   nproc                      !: number for local processor
+   INTEGER, PUBLIC ::   narea                      !: number for local area
+   INTEGER, PUBLIC ::   nbondi, nbondj             !: mark of i- and j-direction local boundaries
+   INTEGER, PUBLIC ::   npolj                      !: north fold mark (0, 3 or 4)
+   INTEGER, PUBLIC ::   nlci  , nlcj               !: i- & j-dimensions of the local subdomain
+   INTEGER, PUBLIC ::   nldi  , nlei               !: first and last indoor i- and j-indexes
+   INTEGER, PUBLIC ::   nldj  , nlej               !:
+   INTEGER, PUBLIC ::   noea  , nowe               !: index of the local neighboring processors in
+   INTEGER, PUBLIC ::   noso  , nono               !: east, west, south and north directions
+   INTEGER, PUBLIC ::   npne  , npnw               !: index of north east and north west processor
+   INTEGER, PUBLIC ::   npse  , npsw               !: index of south east and south west processor
+   INTEGER, PUBLIC ::   nbne  , nbnw               !: logical of north east & north west processor
+   INTEGER, PUBLIC ::   nbse  , nbsw               !: logical of south east & south west processor
+   INTEGER, PUBLIC ::   nidom                      !: ???
+
+   INTEGER, PUBLIC, DIMENSION(jpi)    ::   mig        !: local  ==> global  domain i-indice
+   INTEGER, PUBLIC, DIMENSION(jpj)    ::   mjg        !: local  ==> global  domain j-indice
+   INTEGER, PUBLIC, DIMENSION(jpidta) ::   mi0, mi1   !: global ==> local domain i-indice  (if the global indice is
+   !                                                  !  not in the local domain then mi0=1 and mi1=0)
+   !                                                  !!gm bug ==> other solution?
+   INTEGER, PUBLIC, DIMENSION(jpjdta) ::   mj0, mj1   !: global ==> local domain j-indice  (if the global indice is
+   !                                                  ! not in the local domain then mj0=1 and mj1=0)
+
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nimppt, njmppt   !: i-, j-indexes for each processor
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   ibonit, ibonjt   !: i-, j- processor neighbour existence
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nlcit , nlcjt    !: dimensions of every subdomain
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nldit , nldjt    !: first, last indoor index for each i-domain
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nleit , nlejt    !: first, last indoor index for each j-domain
+
+   !!----------------------------------------------------------------------
+   !! horizontal curvilinear coordinate and scale factors
+   !! ---------------------------------------------------------------------
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   glamt, glamu   !: longitude of t-, u-, v- and f-points (degre)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   glamv, glamf   !:
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   gphit, gphiu   !: latitude  of t-, u-, v- and f-points (degre)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   gphiv, gphif   !:
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   e1t  , e2t     !: horizontal scale factors at t-point (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   e1u  , e2u     !: horizontal scale factors at u-point (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   e1v  , e2v     !: horizontal scale factors at v-point (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   e1f  , e2f     !: horizontal scale factors at f-point (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   ff             !: coriolis factor (2.*omega*sin(yphi) ) (s-1)
+
+   !!----------------------------------------------------------------------
+   !! vertical coordinate and scale factors
+   !! --------------------------------------
+   !                                           !!* namzgr : vertical coordinate *
+   LOGICAL, PUBLIC ::   ln_zco     =  .TRUE.    !: z-coordinate - full step
+   LOGICAL, PUBLIC ::   ln_zps     =  .FALSE.   !: z-coordinate - partial step
+   LOGICAL, PUBLIC ::   ln_sco     =  .FALSE.   !: s-coordinate or hybrid z-s coordinate
+#if defined key_zco
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zco = .TRUE.    !: z-coordinate flag (1D arrays)
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zco = .FALSE.   !: z-coordinate flag (3D arrays)
+
+   !! All coordinates
+   !! ---------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   gdep3w          !: depth of T-points (sum of e3w) (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   gdept , gdepw   !: depth at T-W  points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3v   , e3f     !: vertical scale factors at  V--F
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3t   , e3u     !:                            T--U  points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3vw            !: vertical scale factors at VW--
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3w   , e3uw    !:                            W--UW  points (m)
+#endif
+#if defined key_vvl
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .TRUE.    !: variable grid flag
+
+   !! All coordinates
+   !! ---------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   gdep3w_1          !: depth of T-points (sum of e3w) (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   gdept_1, gdepw_1  !: depth at T-W  points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3v_1  , e3f_1    !: vertical scale factors at  V--F
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3t_1  , e3u_1    !:                            T--U  points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3vw_1            !: vertical scale factors at VW--
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e3w_1  , e3uw_1   !:                            W--UW  points (m)
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .FALSE.   !: fixed grid flag
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hur, hvr              !: inverse of u and v-points ocean depth (1/m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hu , hv               !: depth at u- and v-points (meters)
+
+   !! z-coordinate with full steps (also used in the other cases as reference z-coordinate)
+   !! =-----------------====------
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   gdept_0, gdepw_0          !: reference depth of t- and w-points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   e3t_0  , e3w_0            !: reference vertical scale factors at T- & W-pts (m)
+
+   !! z-coordinate with partial steps
+   !! =-----------------=======------
+   !                          !!: * namelist namdom *
+   REAL(wp), PUBLIC ::   e3zps_min = 5.0_wp       !: miminum thickness for partial steps (meters)
+   REAL(wp), PUBLIC ::   e3zps_rat = 0.1_wp       !: minimum thickness ration for partial steps
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hdept, hdepw, e3tp, e3wp   !: ???
+
+   !! s-coordinate and hybrid z-s-coordinate
+   !! =----------------======---------------
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   gsigt, gsigw   !: model level depth coefficient at t-, w-levels (analytic)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   gsi3w          !: model level depth coefficient at w-level (sum of gsigw)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   esigt, esigw   !: vertical scale factor coef. at t-, w-levels
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hbatv , hbatf   !: ocean depth at the vertical of  V--F
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hbatt , hbatu   !:                                 T--U  points (m)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   scosrf, scobot  !:  ocean surface and bottom topographies
+   !                                                         !   (if deviating from coordinate surfaces in HYBRID)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hifv  , hiff    !: interface depth between stretching at  V--F
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   hift  , hifu    !: and quasi-uniform spacing              T--U  points (m)
+
+   !!----------------------------------------------------------------------
+   !! masks, bathymetry
+   !! -----------------
+
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj)     ::   mbathy         !: number of ocean level (=0, 1, ... , jpk-1)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   bathy          !: ocean depth (meters)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   tmask_i        !: interior domain T-point mask
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   bmask          !: land/ocean mask of barotropic stream function
+   REAL(wp), PUBLIC, DIMENSION(jpiglo)      ::   tpol, fpol     !: north fold mask (nperio= 3 or 4)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   vmask, fmask   !: land/ocean mask at V--F
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   tmask, umask   !:             and at V--U  points
+
+
+#if defined key_noslip_accurate
+   INTEGER, PUBLIC, DIMENSION(            4,jpk) ::   npcoa          !: ???
+   INTEGER, PUBLIC, DIMENSION(2*(jpi+jpj),4,jpk) ::   nicoa, njcoa   !: ???
+#endif
+
+   !!----------------------------------------------------------------------
+   !! time domain
+   !!----------------------------------------------------------------------
+   !                                        !!! * Namelist * ???
+   INTEGER, PUBLIC  ::   nacc   = 0          !: = 0/1 use of the acceleration of convergence technique
+   INTEGER, PUBLIC  ::   neuler              !: restart euler forward option (0=Euler)
+
+   !                                        !!! * Namelist ??? *
+   REAL(wp), PUBLIC ::   rdt    = 3600._wp   !: time step for the dynamics (and tracer if nacc=0)
+   REAL(wp), PUBLIC ::   rdtmin = 3600._wp   !: minimum time step on tracers
+   REAL(wp), PUBLIC ::   rdtmax = 3600._wp   !: maximum time step on tracers
+   REAL(wp), PUBLIC ::   rdth   =  800._wp   !: depth variation of tracer step
+   REAL(wp), PUBLIC ::   rdtbt  =   90._wp   !: barotropic time step for the dynamics (lk_dynspg_ts=T)
+   REAL(wp), PUBLIC ::   atfp   =   0.1_wp   !: asselin time filter parameter
+   REAL(wp), PUBLIC ::   atfp1               !: asselin time filter coeff. (atfp1= 1-2*atfp)
+
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   rdttra   !: vertical profile of tracer time step
+
+   !!----------------------------------------------------------------------
+   !! cross land advection
+   !!----------------------------------------------------------------------
+   !                                        !!! * Namelist ??? *
+   INTEGER, PUBLIC ::   n_cla                !: flag (0/1) for cross land advection to
+      !                                      ! parameterize exchanges through straits
+
+#if defined key_agrif
+   !!----------------------------------------------------------------------
+   !! agrif sponge layer
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC :: spongedoneT = .FALSE.  !: ???
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   zspe1ur, zspe2vr ,zspbtr2    !: ???
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE dom_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domain.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domain.F90	(revision 4536)
@@ -0,0 +1,350 @@
+MODULE domain
+   !!==============================================================================
+   !!                       ***  MODULE domain   ***
+   !! Ocean initialization : domain initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_init       : initialize the space and time domain
+   !!   dom_nam        : read and contral domain namelists
+   !!   dom_ctl        : control print for the ocean domain
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! 
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE ice_oce         ! ice variables
+   USE blk_oce         ! bulk variables
+   USE flxrnf          ! runoffs
+   USE daymod          ! calendar
+   USE lib_mpp         ! distributed memory computing library
+
+   USE domhgr          ! domain: set the horizontal mesh
+   USE domzgr          ! domain: set the vertical mesh
+   USE domstp          ! domain: set the time-step
+   USE dommsk          ! domain: set the mask system
+   USE domwri          ! domain: write the meshmask file
+   USE closea          ! closed sea or lake              (dom_clo routine)
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_init       ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_init  ***
+      !!                    
+      !! ** Purpose :   Domain initialization. Call the routines that are 
+      !!      required to create the arrays which define the space and time
+      !!      domain of the ocean model.
+      !!
+      !! ** Method  :
+      !!      - dom_msk: compute the masks from the bathymetry file
+      !!      - dom_hgr: compute or read the horizontal grid-point position and
+      !!                scale factors, and the coriolis factor
+      !!      - dom_zgr: define the vertical coordinate system and the bathymetry
+      !!      - dom_stp: defined the model time step
+      !!      - dom_wri: create the meshmask file if nmsh=1
+      !!
+      !! History :
+      !!        !  90-10  (C. Levy - G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  92-01  (M. Imbard) insert time step initialization
+      !!        !  96-06  (G. Madec) generalized vertical coordinate 
+      !!        !  97-02  (G. Madec) creation of domwri.F
+      !!        !  01-05  (E.Durand - G. Madec) insert closed sea
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   jk                ! dummy loop argument
+      INTEGER ::   iconf = 0         ! temporary integers
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_init : domain initialization'
+         WRITE(numout,*) '~~~~~~~~'
+      ENDIF
+
+      CALL dom_nam                        ! read namelist ( namrun, namdom, namcla )
+
+      CALL dom_clo                        ! Closed seas and lake
+
+      CALL dom_hgr                        ! Horizontal mesh
+
+      CALL dom_zgr                        ! Vertical mesh and bathymetry
+
+      CALL dom_msk                        ! Masks
+
+      IF( lk_vvl )   CALL dom_vvl_ini     ! Vertical variable mesh
+
+      ! Local depth or Inverse of the local depth of the water column at u- and v-points
+      ! ------------------------------
+      ! Ocean depth at U- and V-points
+      hu(:,:) = 0.
+      hv(:,:) = 0.
+
+      DO jk = 1, jpk
+         hu(:,:) = hu(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
+         hv(:,:) = hv(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
+      END DO
+      ! Inverse of the local depth
+      hur(:,:) = fse3u(:,:,1)             ! Lower bound : thickness of the first model level
+      hvr(:,:) = fse3v(:,:,1)
+
+      DO jk = 2, jpk                      ! Sum of the vertical scale factors
+         hur(:,:) = hur(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
+         hvr(:,:) = hvr(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
+      END DO
+
+      ! Compute and mask the inverse of the local depth
+      hur(:,:) = 1. / hur(:,:) * umask(:,:,1)
+      hvr(:,:) = 1. / hvr(:,:) * vmask(:,:,1)
+
+
+      CALL dom_stp                        ! Time step
+
+      IF( nmsh /= 0 )   CALL dom_wri      ! Create a domain file
+
+      IF( .NOT.ln_rstart )   CALL dom_ctl    ! Domain control
+
+   END SUBROUTINE dom_init
+
+
+   SUBROUTINE dom_nam
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_nam  ***
+      !!                    
+      !! ** Purpose :   read domaine namelists and print the variables.
+      !!
+      !! ** input   : - namrun namelist
+      !!              - namdom namelist
+      !!              - namcla namelist
+      !!
+      !! History :
+      !!   9.0  !  03-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+      NAMELIST/namrun/ no    , cexper   , ln_rstart , nrstdt , nit000,         &
+         &             nitend, ndate0   , nleapy   , ninist , nstock,          &
+         &             nwrite, nrunoff  , ln_dimgnnn
+
+      NAMELIST/namdom/ ntopo , e3zps_min, e3zps_rat, ngrid  , nmsh  ,   &
+         &             nacc  , atfp     , rdt      , rdtmin , rdtmax,   &
+         &             rdth  , rdtbt    , nfice    , nfbulk , nclosea
+      NAMELIST/namcla/ n_cla
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_nam  : domain initialization through namelist read'
+         WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      ! Namelist namrun : parameters of the run
+      REWIND( numnam )
+      READ  ( numnam, namrun )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '        Namelist namrun'
+         WRITE(numout,*) '           job number                      no        = ', no
+         WRITE(numout,*) '           experiment name for output      cexper    = ', cexper
+         WRITE(numout,*) '           restart logical                 ln_rstart = ', ln_rstart
+         WRITE(numout,*) '           control of time step            nrstdt    = ', nrstdt
+         WRITE(numout,*) '           number of the first time step   nit000    = ', nit000
+         WRITE(numout,*) '           number of the last time step    nitend    = ', nitend
+         WRITE(numout,*) '           initial calendar date aammjj    ndate0    = ', ndate0
+         WRITE(numout,*) '           leap year calendar (0/1)        nleapy    = ', nleapy
+         WRITE(numout,*) '           initial state output            ninist    = ', ninist
+         WRITE(numout,*) '           frequency of restart file       nstock    = ', nstock
+         WRITE(numout,*) '           frequency of output file        nwrite    = ', nwrite
+         WRITE(numout,*) '           runoff option                   nrunoff   = ', nrunoff
+         WRITE(numout,*) '           multi file dimgout           ln_dimgnnn   = ', ln_dimgnnn
+      ENDIF
+
+      ndastp = ndate0                ! Assign initial date to current date
+
+! ... Control of output frequency
+      IF ( nstock == 0 ) THEN
+          IF(lwp)WRITE(numout,cform_war)
+          IF(lwp)WRITE(numout,*) '           nstock = ', nstock, ' it is forced to ', nitend
+          nstock = nitend
+          nwarn = nwarn + 1
+      ENDIF
+      IF ( nwrite == 0 ) THEN
+          IF(lwp)WRITE(numout,cform_war)
+          IF(lwp)WRITE(numout,*) '           nwrite = ', nwrite, ' it is forced to ', nitend
+          nwrite = nitend
+          nwarn = nwarn + 1
+      ENDIF
+
+#if defined key_agrif
+      if ( Agrif_Root() ) then
+#endif
+      SELECT CASE ( nleapy )   ! Choose calendar for IOIPSL
+      CASE (  1 ) 
+         CALL ioconf_calendar('gregorian')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "gregorian", i.e. leap year'
+      CASE (  0 )
+         CALL ioconf_calendar('noleap')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "noleap", i.e. no leap year'
+      CASE ( 30 )
+         CALL ioconf_calendar('360d')
+         IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "360d", i.e. 360 days in a year'
+      END SELECT
+#if defined key_agrif
+      endif
+#endif
+
+      SELECT CASE ( nleapy )   ! year=raajj*days day=rjjhh*hours hour=rhhmm*minutes etc ...
+      CASE ( 1 )
+         raajj = 365.25
+         raass = raajj * rjjss
+         rmoss = raass/raamo
+      CASE ( 0 )
+         raajj = 365.
+         raass = raajj * rjjss
+         rmoss = raass/raamo
+      CASE DEFAULT
+         raajj = FLOAT( nleapy ) * raamo
+         raass =        raajj    * rjjss
+         rmoss = FLOAT( nleapy ) * rjjss
+      END SELECT
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           nb of days per year      raajj = ', raajj,' days'
+         WRITE(numout,*) '           nb of seconds per year   raass = ', raass, ' s'
+         WRITE(numout,*) '           nb of seconds per month  rmoss = ', rmoss, ' s'
+      ENDIF
+
+      ! Namelist namdom : space/time domain (bathymetry, mesh, timestep)
+      REWIND( numnam )
+      READ  ( numnam, namdom )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '        Namelist namdom'
+         WRITE(numout,*) '           flag read/compute bathymetry   ntopo     = ', ntopo
+         WRITE(numout,*) '           minimum thickness of partial   e3zps_min = ', e3zps_min, ' (m)'
+         WRITE(numout,*) '              step level                  e3zps_rat = ', e3zps_rat
+         WRITE(numout,*) '           flag read/compute coordinates  ngrid     = ', ngrid
+         WRITE(numout,*) '           flag write mesh/mask file(s)   nmsh      = ', nmsh
+         WRITE(numout,*) '                = 0   no file created                 '
+         WRITE(numout,*) '                = 1   mesh_mask                       '
+         WRITE(numout,*) '                = 2   mesh and mask                   '
+         WRITE(numout,*) '                = 3   mesh_hgr, msh_zgr and mask      '
+         WRITE(numout,*) '           acceleration of converge       nacc      = ', nacc
+         WRITE(numout,*) '           asselin time filter parameter  atfp      = ', atfp
+         WRITE(numout,*) '           time step                      rdt       = ', rdt
+         WRITE(numout,*) '           minimum time step on tracers   rdtmin    = ', rdtmin
+         WRITE(numout,*) '           maximum time step on tracers   rdtmax    = ', rdtmax
+         WRITE(numout,*) '           depth variation tracer step    rdth      = ', rdth
+         WRITE(numout,*) '           barotropic time step           rdtbt     = ', rdtbt
+      ENDIF
+
+      IF( lk_ice_lim ) THEN
+         IF(lwp) WRITE(numout,*) '           ice model coupling frequency      nfice  = ', nfice
+         nfbulk = nfice
+         IF( MOD( rday, nfice*rdt ) /= 0 ) THEN 
+            IF(lwp) WRITE(numout,*) ' '
+            IF(lwp) WRITE(numout,*) 'W A R N I N G :  nfice is NOT a multiple of the number of time steps in a day'
+            IF(lwp) WRITE(numout,*) ' '
+         ENDIF
+         IF(lwp) WRITE(numout,*) '           bulk computation frequency       nfbulk  = ', nfbulk, ' = nfice if ice model used'
+         IF(lwp) WRITE(numout,*) '           flag closed sea or not           nclosea = ', nclosea
+      ENDIF
+
+      ! Default values
+      n_cla = 0
+
+      ! Namelist cross land advection
+      REWIND( numnam )
+      READ  ( numnam, namcla )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '        Namelist namcla'
+         WRITE(numout,*) '           cross land advection        n_cla        = ',n_cla
+      ENDIF
+
+      IF( nbit_cmp == 1 .AND. n_cla /= 0 ) THEN
+         CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require n_cla = 0' )
+      END IF
+
+   END SUBROUTINE dom_nam
+
+
+   SUBROUTINE dom_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_ctl  ***
+      !!
+      !! ** Purpose :   Domain control.
+      !!
+      !! ** Method  :   compute and print extrema of masked scale factors
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)    Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   iimi1, ijmi1, iimi2, ijmi2, iima1, ijma1, iima2, ijma2
+      INTEGER, DIMENSION(2) ::   iloc      ! 
+      REAL(wp) ::   ze1min, ze1max, ze2min, ze2max
+      !!----------------------------------------------------------------------
+
+      ! Extrema of the scale factors
+
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'dom_ctl : extrema of the masked scale factors'
+      IF(lwp)WRITE(numout,*) '~~~~~~~'
+
+      IF (lk_mpp) THEN
+         CALL mpp_minloc( e1t(:,:), tmask(:,:,1), ze1min, iimi1,ijmi1 )
+         CALL mpp_minloc( e2t(:,:), tmask(:,:,1), ze2min, iimi2,ijmi2 )
+         CALL mpp_maxloc( e1t(:,:), tmask(:,:,1), ze1max, iima1,ijma1 )
+         CALL mpp_maxloc( e2t(:,:), tmask(:,:,1), ze2max, iima2,ijma2 )
+      ELSE
+         ze1min = MINVAL( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze2min = MINVAL( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze1max = MAXVAL( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+         ze2max = MAXVAL( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )    
+
+         iloc  = MINLOC( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iimi1 = iloc(1) + nimpp - 1
+         ijmi1 = iloc(2) + njmpp - 1
+         iloc  = MINLOC( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iimi2 = iloc(1) + nimpp - 1
+         ijmi2 = iloc(2) + njmpp - 1
+         iloc  = MAXLOC( e1t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iima1 = iloc(1) + nimpp - 1
+         ijma1 = iloc(2) + njmpp - 1
+         iloc  = MAXLOC( e2t(:,:), mask = tmask(:,:,1) == 1.e0 )
+         iima2 = iloc(1) + nimpp - 1
+         ijma2 = iloc(2) + njmpp - 1
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,"(14x,'e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, iima1, ijma1
+         WRITE(numout,"(14x,'e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, iimi1, ijmi1
+         WRITE(numout,"(14x,'e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, iima2, ijma2
+         WRITE(numout,"(14x,'e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, iimi2, ijmi2
+      ENDIF
+
+   END SUBROUTINE dom_ctl
+
+   !!======================================================================
+END MODULE domain
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domcfg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domcfg.F90	(revision 4536)
@@ -0,0 +1,213 @@
+MODULE domcfg
+   !!==============================================================================
+   !!                       ***  MODULE domcfg   ***
+   !! Ocean initialization : domain configuration initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_cfg        : initialize the domain configuration
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+   USE solisl          ! ???
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_cfg        ! called by opa.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_cfg
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_cfg  ***
+      !!                    
+      !! ** Purpose :   set the domain configuration
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   iconf = 0         ! temporary integers
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_cfg : set the ocean configuration'
+         WRITE(numout,*) '~~~~~~~      ocean model configuration used :',   &
+            &                             ' cp_cfg = ', cp_cfg, ' jp_cfg = ', jp_cfg
+      ENDIF
+
+      ! Global domain boundary conditions
+      ! ---------------------------------
+      IF(lwp) THEN
+         WRITE(numout,*) '          global domain lateral boundaries'
+
+         IF( jperio == 0 ) WRITE(numout,*) '             jperio= 0, closed'
+         IF( jperio == 1 ) WRITE(numout,*) '             jperio= 1, cyclic east-west'
+         IF( jperio == 2 ) WRITE(numout,*) '             jperio= 2, equatorial symmetric'
+         IF( jperio == 3 ) WRITE(numout,*) '             jperio= 3, north fold with T-point pivot'
+         IF( jperio == 4 ) WRITE(numout,*) '             jperio= 4, cyclic east-west and',   &
+                                                                  ' north fold with T-point pivot'
+         IF( jperio == 5 ) WRITE(numout,*) '             jperio= 5, north fold with F-point pivot'
+         IF( jperio == 6 ) WRITE(numout,*) '             jperio= 6, cyclic east-west and',   &
+                                                                  ' north fold with F-point pivot'
+      ENDIF
+      IF( jperio <  0 .OR. jperio > 6 ) CALL ctl_stop( 'jperio is out of range' )
+
+      ! global domain versus zoom and/or local domain
+      ! ---------------------------------------------
+
+      CALL dom_glo 
+
+   END SUBROUTINE dom_cfg
+
+
+   SUBROUTINE dom_glo
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_glo  ***
+      !!
+      !! ** Purpose :   initialization for global domain, zoom and local domain
+      !!
+      !! ** Method  :   
+      !!
+      !! ** Action  : - mig  , mjg : 
+      !!              - mi0  , mi1   :
+      !!              - mj0, , mj1   :
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)    Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj            ! dummy loop argument
+      !!----------------------------------------------------------------------
+
+      ! Local domain 
+      ! ============
+
+      ! local domain indices ==> data domain indices
+      DO ji = 1, jpi
+        mig(ji) = ji + jpizoom - 1 + nimpp - 1
+      END DO
+      DO jj = 1, jpj
+        mjg(jj) = jj + jpjzoom - 1 + njmpp - 1
+      END DO
+
+      ! data domain indices ==> local domain indices
+      ! (return (m.0,m.1)=(1,0) if data domain gridpoint is to the west/south of the 
+      ! local domain, or (m.0,m.1)=(jp.+1,jp.) to the east/north of local domain. 
+      DO ji = 1, jpidta
+        mi0(ji) = MAX( 1, MIN( ji - jpizoom + 1 - nimpp + 1, jpi+1 ) )
+        mi1(ji) = MAX( 0, MIN( ji - jpizoom + 1 - nimpp + 1, jpi   ) )
+      END DO
+      DO jj = 1, jpjdta
+        mj0(jj) = MAX( 1, MIN( jj - jpjzoom + 1 - njmpp + 1, jpj+1 ) )
+        mj1(jj) = MAX( 0, MIN( jj - jpjzoom + 1 - njmpp + 1, jpj   ) )
+      END DO
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_glo : domain: data / local '
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          data input domain    : jpidta = ', jpidta,   &
+            &                                            ' jpjdta = ', jpjdta, ' jpkdta = ', jpkdta
+         WRITE(numout,*) '          global or zoom domain: jpiglo = ', jpiglo,   &
+            &                                            ' jpjglo = ', jpjglo, ' jpk    = ', jpk
+         WRITE(numout,*) '          local domain         : jpi    = ', jpi   ,   &
+            &                                            ' jpj    = ', jpj   , ' jpk    = ', jpk
+         WRITE(numout,*)
+         WRITE(numout,*) '          south-west indices    jpizoom = ', jpizoom,   &
+            &                                           ' jpjzoom = ', jpjzoom
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion local  ==> data i-index domain'
+         WRITE(numout,25)              (mig(ji),ji = 1,jpi)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion data   ==> local  i-index domain'
+         WRITE(numout,*) '             starting index'
+         WRITE(numout,25)              (mi0(ji),ji = 1,jpidta)
+         WRITE(numout,*) '             ending index'
+         WRITE(numout,25)              (mi1(ji),ji = 1,jpidta)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion local  ==> data j-index domain'
+         WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion data  ==> local j-index domain'
+         WRITE(numout,*) '             starting index'
+         WRITE(numout,25)              (mj0(jj),jj = 1,jpjdta)
+         WRITE(numout,*) '             ending index'
+         WRITE(numout,25)              (mj1(jj),jj = 1,jpjdta)
+      ENDIF
+ 25   FORMAT( 100(10x,19i4,/) )
+
+      ! Zoom domain
+      ! ===========
+
+      ! zoom control
+      IF( jpiglo + jpizoom - 1  >  jpidta .OR.   &
+          jpjglo + jpjzoom - 1  >  jpjdta      ) &
+          &   CALL ctl_stop( ' global or zoom domain exceed the data domain ! ' )
+
+      ! set zoom flag
+      IF ( jpiglo < jpidta .OR. jpjglo < jpjdta )   lzoom = .TRUE.
+
+      ! set zoom type flags
+      IF( lzoom .AND. jpizoom /= 1 )   lzoom_w = .TRUE.                     ! 
+      IF( lzoom .AND. jpjzoom /= 1 )   lzoom_s = .TRUE.
+      IF( lzoom .AND. jpiglo + jpizoom -1 /= jpidta )   lzoom_e = .TRUE.
+      IF( lzoom .AND. jpjglo + jpjzoom -1 /= jpjdta )   lzoom_n = .TRUE.
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          zoom flags : '
+         WRITE(numout,*) '             lzoom   = ', lzoom  , ' (T = zoom, F = global )'
+         WRITE(numout,*) '             lzoom_e = ', lzoom_e, ' (T = forced closed east  boundary)'
+         WRITE(numout,*) '             lzoom_w = ', lzoom_w, ' (T = forced closed west  boundary)'
+         WRITE(numout,*) '             lzoom_s = ', lzoom_s, ' (T = forced closed South boundary)'
+         WRITE(numout,*) '             lzoom_n = ', lzoom_n, ' (T = forced closed North boundary)'
+      ENDIF
+      IF(  ( lzoom_e .OR. lzoom_w )  .AND.  ( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 )  )   &
+           &   CALL ctl_stop( ' Your zoom choice is inconsistent with east-west cyclic boundary condition' )
+      IF(  lzoom_n  .AND.  ( 3 <= jperio .AND. jperio <= 6 )  )   &
+           &   CALL ctl_stop( ' Your zoom choice is inconsistent with North fold boundary condition' )
+      IF(  lzoom  .AND.  lk_isl  ) CALL ctl_stop( ' key_islands and zoom are not allowed' )
+
+      ! Pre-defined arctic/antarctic zoom of ORCA configuration flag
+      IF( cp_cfg == "orca" ) THEN
+         SELECT CASE ( jp_cfg )
+         !                                        ! =======================
+         CASE ( 2 )                               !  ORCA_R2 configuration
+            !                                     ! =======================
+            IF(  jpiglo  == 142    .AND. jpjglo  ==  53 .AND.   &
+               & jpizoom ==  21    .AND. jpjzoom ==  97         )   lzoom_arct = .TRUE.
+            IF(  jpiglo  == jpidta .AND. jpjglo  ==  50 .AND.   &
+               & jpizoom ==   1    .AND. jpjzoom ==   1         )   lzoom_anta = .TRUE.
+            !                                     ! =======================
+         CASE ( 05 )                              !  ORCA_R05 configuration
+            !                                     ! =======================
+            IF(  jpiglo  == 562    .AND. jpjglo  == 202 .AND.   &
+               & jpizoom ==  81    .AND. jpjzoom == 301         )   lzoom_arct = .TRUE.
+            IF(  jpiglo  == jpidta .AND. jpjglo  == 187 .AND.   &
+               & jpizoom ==   1    .AND. jpjzoom ==   1         )   lzoom_anta = .TRUE.
+         END SELECT
+         !
+         IF(lwp) WRITE(numout,*) '          ORCA configuration: antarctic/arctic zoom flags : '
+         IF(lwp) WRITE(numout,*) '             lzoom_arct = ', lzoom_arct, ' (T=   arctic zoom, F=global)'
+         IF(lwp) WRITE(numout,*) '             lzoom_anta = ', lzoom_anta, ' (T=antarctic zoom, F=global)'
+         !
+      ENDIF
+         
+   END SUBROUTINE dom_glo
+
+   !!======================================================================
+END MODULE domcfg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domhgr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 4536)
@@ -0,0 +1,570 @@
+MODULE domhgr
+   !!==============================================================================
+   !!                       ***  MODULE domhgr   ***
+   !! Ocean initialization : domain initialization
+   !!==============================================================================
+   !! History :       !  88-03  (G. Madec)
+   !!                 !  91-11  (G. Madec)
+   !!                 !  92-06  (M. Imbard)
+   !!                 !  96-01  (G. Madec)  terrain following coordinates
+   !!                 !  97-02  (G. Madec)  print mesh informations
+   !!                 !  99-11  (M. Imbard) NetCDF format with IO-IPSL
+   !!                 !  00-08  (D. Ludicone) Reduced section at Bab el Mandeb
+   !!                 !  01-09  (M. Levy)  eel config: grid in km, beta-plane
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module, namelist
+   !!            9.0  !  04-01  (A.M. Treguier, J.M. Molines) Case 4 (Mercator mesh)
+   !!                           use of parameters in par_CONFIG-Rxx.h90, not in namelist
+   !!                 !  04-05  (A. Koch-Larrouy) Add Gyre configuration 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_hgr        : initialize the horizontal mesh 
+   !!   hgr_read       : read "coordinate" NetCDF file 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   REAL(wp) ::   glam0, gphi0           ! variables corresponding to parameters
+      !                                 ! ppglam0 ppgphi0 set in par_oce
+
+   !! * Routine accessibility
+   PUBLIC dom_hgr        ! called by domain.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_hgr
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_hgr  ***
+      !!
+      !! ** Purpose :   Compute the geographical position (in degre) of the 
+      !!      model grid-points,  the horizontal scale factors (in meters) and 
+      !!      the Coriolis factor (in s-1).
+      !!
+      !! ** Method  :   The geographical position of the model grid-points is
+      !!      defined from analytical functions, fslam and fsphi, the deriva-
+      !!      tives of which gives the horizontal scale factors e1,e2.
+      !!      Defining two function fslam and fsphi and their derivatives in 
+      !!      the two horizontal directions (fse1 and fse2), the model grid-
+      !!      point position and scale factors are given by:
+      !!         t-point:
+      !!      glamt(i,j) = fslam(i    ,j    )   e1t(i,j) = fse1(i    ,j    )
+      !!      gphit(i,j) = fsphi(i    ,j    )   e2t(i,j) = fse2(i    ,j    )
+      !!         u-point:
+      !!      glamu(i,j) = fslam(i+1/2,j    )   e1u(i,j) = fse1(i+1/2,j    )
+      !!      gphiu(i,j) = fsphi(i+1/2,j    )   e2u(i,j) = fse2(i+1/2,j    )
+      !!         v-point:
+      !!      glamv(i,j) = fslam(i    ,j+1/2)   e1v(i,j) = fse1(i    ,j+1/2)
+      !!      gphiv(i,j) = fsphi(i    ,j+1/2)   e2v(i,j) = fse2(i    ,j+1/2)
+      !!            f-point:
+      !!      glamf(i,j) = fslam(i+1/2,j+1/2)   e1f(i,j) = fse1(i+1/2,j+1/2)
+      !!      gphif(i,j) = fsphi(i+1/2,j+1/2)   e2f(i,j) = fse2(i+1/2,j+1/2)
+      !!      Where fse1 and fse2 are defined by:
+      !!         fse1(i,j) = ra * rad * SQRT( (cos(phi) di(fslam))**2
+      !!                                     +          di(fsphi) **2 )(i,j)
+      !!         fse2(i,j) = ra * rad * SQRT( (cos(phi) dj(fslam))**2
+      !!                                     +          dj(fsphi) **2 )(i,j)
+      !!
+      !!        The coriolis factor is given at z-point by:
+      !!                     ff = 2.*omega*sin(gphif)      (in s-1)
+      !!
+      !!        This routine is given as an example, it must be modified
+      !!      following the user s desiderata. nevertheless, the output as
+      !!      well as the way to compute the model grid-point position and
+      !!      horizontal scale factors must be respected in order to insure
+      !!      second order accuracy schemes.
+      !!
+      !! N.B. If the domain is periodic, verify that scale factors are also
+      !!      periodic, and the coriolis term again.
+      !!
+      !! ** Action  : - define  glamt, glamu, glamv, glamf: longitude of t-, 
+      !!                u-, v- and f-points (in degre)
+      !!              - define  gphit, gphiu, gphiv, gphit: latitude  of t-,
+      !!               u-, v-  and f-points (in degre)
+      !!        define e1t, e2t, e1u, e2u, e1v, e2v, e1f, e2f: horizontal
+      !!      scale factors (in meters) at t-, u-, v-, and f-points.
+      !!        define ff: coriolis factor at f-point
+      !!
+      !! References :   Marti, Madec and Delecluse, 1992, JGR
+      !!                Madec, Imbard, 1996, Clim. Dyn.
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj              ! dummy loop indices
+      INTEGER  ::   ii0, ii1, ij0, ij1  ! temporary integers
+      INTEGER  ::   ijeq                ! index of equator T point (used in case 4)
+      REAL(wp) ::   &
+         zti, zui, zvi, zfi,         &  ! temporary scalars
+         ztj, zuj, zvj, zfj,         &  !
+         zphi0, zbeta, znorme,       &  !
+         zarg, zf0, zminff, zmaxff
+      REAL(wp) ::   &
+         zlam1, zcos_alpha, zim1 , zjm1 , ze1, ze1deg,   &
+         zphi1, zsin_alpha, zim05, zjm05
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_hgr : define the horizontal mesh from ithe following par_oce parameters '
+         WRITE(numout,*) '~~~~~~~      type of horizontal mesh           jphgr_msh = ', jphgr_msh
+         WRITE(numout,*) '             position of the first row and     ppglam0  = ', ppglam0
+         WRITE(numout,*) '             column grid-point (degrees)       ppgphi0  = ', ppgphi0
+         WRITE(numout,*) '             zonal      grid-spacing (degrees) ppe1_deg = ', ppe1_deg
+         WRITE(numout,*) '             meridional grid-spacing (degrees) ppe2_deg = ', ppe2_deg
+         WRITE(numout,*) '             zonal      grid-spacing (meters)  ppe1_m   = ', ppe1_m  
+         WRITE(numout,*) '             meridional grid-spacing (meters)  ppe2_m   = ', ppe2_m  
+      ENDIF
+
+
+      SELECT CASE( jphgr_msh )   ! type of horizontal mesh
+
+      CASE ( 0 )                     !  curvilinear coordinate on the sphere read in coordinate.nc file
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          curvilinear coordinate on the sphere read in "coordinate" file'
+
+         CALL hgr_read           ! Defaultl option  :   NetCDF file
+
+         !                                                ! =====================
+         IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN    ! ORCA R2 configuration
+            !                                             ! =====================
+            IF( n_cla == 0 ) THEN
+
+               ii0 = 139   ;   ii1 = 140        ! Gibraltar Strait (e2u = 20 km)
+               ij0 = 102   ;   ij1 = 102   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  20.e3
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '             orca_r2: Gibraltar : e2u reduced to 20 km'
+               ii0 = 160   ;   ii1 = 160        ! Bab el Mandeb (e2u = 18 km)
+               ij0 =  88   ;   ij1 =  88   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  18.e3
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '             orca_r2: Bab el Mandeb: e2u reduced to 18 km'
+            ENDIF
+
+            ii0 = 145   ;   ii1 = 146        ! Sound Strait (e2u = 15 km)
+            ij0 = 116   ;   ij1 = 116   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  15.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r2: Reduced e2u at the Sound Strait'
+            !
+         ENDIF
+
+         !                                                ! ======================
+         IF( cp_cfg == "orca" .AND. jp_cfg == 05 ) THEN   ! ORCA R05 configuration
+            !                                             ! ======================
+            ii0 = 563   ;   ii1 = 564        ! Gibraltar Strait (e2u = 20 km)
+            ij0 = 327   ;   ij1 = 327   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  20.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e2u at the Gibraltar Strait'
+            !
+            ii0 = 627   ;   ii1 = 628        ! Bosphore Strait (e2u = 10 km)
+            ij0 = 343   ;   ij1 = 343   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  10.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e2u at the Bosphore Strait'
+            !
+            ii0 =  93   ;   ii1 =  94        ! Sumba Strait (e2u = 40 km)
+            ij0 = 232   ;   ij1 = 232   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  40.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e2u at the Sumba Strait'
+            !
+            ii0 = 103   ;   ii1 = 103        ! Ombai Strait (e2u = 15 km)
+            ij0 = 232   ;   ij1 = 232   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  15.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e2u at the Ombai Strait'
+            !
+            ii0 =  15   ;   ii1 =  15        ! Palk Strait (e2u = 10 km)
+            ij0 = 270   ;   ij1 = 270   ;   e2u( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  10.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e2u at the Palk Strait'
+            !
+            ii0 =  87   ;   ii1 =  87        ! Lombok Strait (e1v = 10 km)
+            ij0 = 232   ;   ij1 = 233   ;   e1v( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  10.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e1v at the Lombok Strait'
+            !
+            !
+            ii0 = 662   ;   ii1 = 662        ! Bab el Mandeb (e1v = 25 km)
+            ij0 = 276   ;   ij1 = 276   ;   e1v( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  25.e3
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '             orca_r05: Reduced e1v at the Bab el Mandeb'
+            !
+         ENDIF
+
+
+         ! N.B. :  General case, lat and long function of both i and j indices:
+         !     e1t(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphit(ji,jj) ) * fsdila( zti, ztj ) )**2   &
+         !                                  + (                           fsdiph( zti, ztj ) )**2  )
+         !     e1u(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphiu(ji,jj) ) * fsdila( zui, zuj ) )**2   &
+         !                                  + (                           fsdiph( zui, zuj ) )**2  )
+         !     e1v(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphiv(ji,jj) ) * fsdila( zvi, zvj ) )**2   &
+         !                                  + (                           fsdiph( zvi, zvj ) )**2  )
+         !     e1f(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphif(ji,jj) ) * fsdila( zfi, zfj ) )**2   &
+         !                                  + (                           fsdiph( zfi, zfj ) )**2  )
+         !
+         !     e2t(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphit(ji,jj) ) * fsdjla( zti, ztj ) )**2   &
+         !                                  + (                           fsdjph( zti, ztj ) )**2  )
+         !     e2u(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphiu(ji,jj) ) * fsdjla( zui, zuj ) )**2   &
+         !                                  + (                           fsdjph( zui, zuj ) )**2  )
+         !     e2v(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphiv(ji,jj) ) * fsdjla( zvi, zvj ) )**2   &
+         !                                  + (                           fsdjph( zvi, zvj ) )**2  )
+         !     e2f(ji,jj) = ra * rad * SQRT(  ( cos( rad*gphif(ji,jj) ) * fsdjla( zfi, zfj ) )**2   &
+         !                                  + (                           fsdjph( zfi, zfj ) )**2  )
+
+
+      CASE ( 1 )                     ! geographical mesh on the sphere with regular grid-spacing
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          geographical mesh on the sphere with regular grid-spacing'
+         IF(lwp) WRITE(numout,*) '          given by ppe1_deg and ppe2_deg' 
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zti = FLOAT( ji - 1 + nimpp - 1 )         ;   ztj = FLOAT( jj - 1 + njmpp - 1 )
+               zui = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zuj = FLOAT( jj - 1 + njmpp - 1 )
+               zvi = FLOAT( ji - 1 + nimpp - 1 )         ;   zvj = FLOAT( jj - 1 + njmpp - 1 ) + 0.5
+               zfi = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zfj = FLOAT( jj - 1 + njmpp - 1 ) + 0.5
+         ! Longitude
+               glamt(ji,jj) = ppglam0 + ppe1_deg * zti
+               glamu(ji,jj) = ppglam0 + ppe1_deg * zui
+               glamv(ji,jj) = ppglam0 + ppe1_deg * zvi
+               glamf(ji,jj) = ppglam0 + ppe1_deg * zfi
+         ! Latitude
+               gphit(ji,jj) = ppgphi0 + ppe2_deg * ztj
+               gphiu(ji,jj) = ppgphi0 + ppe2_deg * zuj
+               gphiv(ji,jj) = ppgphi0 + ppe2_deg * zvj
+               gphif(ji,jj) = ppgphi0 + ppe2_deg * zfj
+         ! e1
+               e1t(ji,jj) = ra * rad * COS( rad * gphit(ji,jj) ) * ppe1_deg
+               e1u(ji,jj) = ra * rad * COS( rad * gphiu(ji,jj) ) * ppe1_deg
+               e1v(ji,jj) = ra * rad * COS( rad * gphiv(ji,jj) ) * ppe1_deg
+               e1f(ji,jj) = ra * rad * COS( rad * gphif(ji,jj) ) * ppe1_deg
+         ! e2
+               e2t(ji,jj) = ra * rad * ppe2_deg
+               e2u(ji,jj) = ra * rad * ppe2_deg
+               e2v(ji,jj) = ra * rad * ppe2_deg
+               e2f(ji,jj) = ra * rad * ppe2_deg
+            END DO
+         END DO
+
+
+      CASE ( 2:3 )                   ! f- or beta-plane with regular grid-spacing
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          f- or beta-plane with regular grid-spacing'
+         IF(lwp) WRITE(numout,*) '          given by ppe1_m and ppe2_m' 
+
+         ! Position coordinates (in kilometers)
+         !                          ==========
+         glam0 = 0.e0
+         gphi0 = - ppe2_m * 1.e-3
+         
+#if defined key_agrif && defined key_eel_r6
+         IF (.Not.Agrif_Root()) THEN
+           glam0  = Agrif_Parent(glam0) + (Agrif_ix())*Agrif_Parent(ppe1_m) * 1.e-3
+           gphi0  = Agrif_Parent(gphi0) + (Agrif_iy())*Agrif_Parent(ppe2_m) * 1.e-3
+           ppe1_m = Agrif_Parent(ppe1_m)/Agrif_Rhox()
+           ppe2_m = Agrif_Parent(ppe2_m)/Agrif_Rhoy()          
+         ENDIF
+#endif         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               glamt(ji,jj) = glam0 + ppe1_m * 1.e-3 * ( FLOAT( ji - 1 + nimpp - 1 )       )
+               glamu(ji,jj) = glam0 + ppe1_m * 1.e-3 * ( FLOAT( ji - 1 + nimpp - 1 ) + 0.5 )
+               glamv(ji,jj) = glamt(ji,jj)
+               glamf(ji,jj) = glamu(ji,jj)
+   
+               gphit(ji,jj) = gphi0 + ppe2_m * 1.e-3 * ( FLOAT( jj - 1 + njmpp - 1 )       )
+               gphiu(ji,jj) = gphit(ji,jj)
+               gphiv(ji,jj) = gphi0 + ppe2_m * 1.e-3 * ( FLOAT( jj - 1 + njmpp - 1 ) + 0.5 )
+               gphif(ji,jj) = gphiv(ji,jj)
+            END DO
+         END DO
+
+         ! Horizontal scale factors (in meters)
+         !                              ======
+         e1t(:,:) = ppe1_m      ;      e2t(:,:) = ppe2_m
+         e1u(:,:) = ppe1_m      ;      e2u(:,:) = ppe2_m
+         e1v(:,:) = ppe1_m      ;      e2v(:,:) = ppe2_m
+         e1f(:,:) = ppe1_m      ;      e2f(:,:) = ppe2_m
+
+      CASE ( 4 )                     ! geographical mesh on the sphere, isotropic MERCATOR type
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          geographical mesh on the sphere, MERCATOR type'
+         IF(lwp) WRITE(numout,*) '          longitudinal/latitudinal spacing given by ppe1_deg'
+         IF ( ppgphi0 == -90 ) CALL ctl_stop( ' Mercator grid cannot start at south pole !!!! ' )
+
+         !  Find index corresponding to the equator, given the grid spacing e1_deg
+         !  and the (approximate) southern latitude ppgphi0.
+         !  This way we ensure that the equator is at a "T / U" point, when in the domain.
+         !  The formula should work even if the equator is outside the domain.
+         zarg = rpi / 4. - rpi / 180. * ppgphi0 / 2.
+         ijeq = ABS( 180./rpi * LOG( COS( zarg ) / SIN( zarg ) ) / ppe1_deg )
+         IF(  ppgphi0 > 0 )  ijeq = -ijeq
+
+         IF(lwp) WRITE(numout,*) '          Index of the equator on the MERCATOR grid:', ijeq
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zti = FLOAT( ji - 1 + nimpp - 1 )         ;   ztj = FLOAT( jj - ijeq + njmpp - 1 )
+               zui = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zuj = FLOAT( jj - ijeq + njmpp - 1 )
+               zvi = FLOAT( ji - 1 + nimpp - 1 )         ;   zvj = FLOAT( jj - ijeq + njmpp - 1 ) + 0.5
+               zfi = FLOAT( ji - 1 + nimpp - 1 ) + 0.5   ;   zfj = FLOAT( jj - ijeq + njmpp - 1 ) + 0.5
+         ! Longitude
+               glamt(ji,jj) = ppglam0 + ppe1_deg * zti
+               glamu(ji,jj) = ppglam0 + ppe1_deg * zui
+               glamv(ji,jj) = ppglam0 + ppe1_deg * zvi
+               glamf(ji,jj) = ppglam0 + ppe1_deg * zfi
+         ! Latitude
+               gphit(ji,jj) = 1./rad * ASIN ( TANH( ppe1_deg *rad* ztj ) )
+               gphiu(ji,jj) = 1./rad * ASIN ( TANH( ppe1_deg *rad* zuj ) )
+               gphiv(ji,jj) = 1./rad * ASIN ( TANH( ppe1_deg *rad* zvj ) )
+               gphif(ji,jj) = 1./rad * ASIN ( TANH( ppe1_deg *rad* zfj ) )
+         ! e1
+               e1t(ji,jj) = ra * rad * COS( rad * gphit(ji,jj) ) * ppe1_deg
+               e1u(ji,jj) = ra * rad * COS( rad * gphiu(ji,jj) ) * ppe1_deg
+               e1v(ji,jj) = ra * rad * COS( rad * gphiv(ji,jj) ) * ppe1_deg
+               e1f(ji,jj) = ra * rad * COS( rad * gphif(ji,jj) ) * ppe1_deg
+         ! e2
+               e2t(ji,jj) = ra * rad * COS( rad * gphit(ji,jj) ) * ppe1_deg
+               e2u(ji,jj) = ra * rad * COS( rad * gphiu(ji,jj) ) * ppe1_deg
+               e2v(ji,jj) = ra * rad * COS( rad * gphiv(ji,jj) ) * ppe1_deg
+               e2f(ji,jj) = ra * rad * COS( rad * gphif(ji,jj) ) * ppe1_deg
+            END DO
+         END DO
+
+      CASE ( 5 )                   ! beta-plane with regular grid-spacing and rotated domain (GYRE configuration)
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          beta-plane with regular grid-spacing and rotated domain (GYRE configuration)'
+         IF(lwp) WRITE(numout,*) '          given by ppe1_m and ppe2_m'
+
+         ! Position coordinates (in kilometers)
+         !                          ==========
+
+         ! angle 45deg and ze1=106.e+3 / jp_cfg forced -> zlam1 = -85deg, zphi1 = 29degN
+         zlam1 = -85
+         zphi1 = 29
+         ! resolution in meters
+         ze1 = 106000. / FLOAT(jp_cfg)            
+         ! benchmark: forced the resolution to be about 100 km
+         IF( nbench /= 0 )   ze1 = 106000.e0     
+         zsin_alpha = - SQRT( 2. ) / 2.
+         zcos_alpha =   SQRT( 2. ) / 2.
+         ze1deg = ze1 / (ra * rad)
+         IF( nbench /= 0 )   ze1deg = ze1deg / FLOAT(jp_cfg)        ! benchmark: keep the lat/+lon
+         !                                                          ! at the right jp_cfg resolution
+         glam0 = zlam1 + zcos_alpha * ze1deg * FLOAT( jpjglo-2 )
+         gphi0 = zphi1 + zsin_alpha * ze1deg * FLOAT( jpjglo-2 )
+
+         IF( nprint==1 .AND. lwp )   THEN
+            WRITE(numout,*) '          ze1', ze1, 'cosalpha', zcos_alpha, 'sinalpha', zsin_alpha
+            WRITE(numout,*) '          ze1deg', ze1deg, 'glam0', glam0, 'gphi0', gphi0
+         ENDIF
+
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+             zim1 = FLOAT( ji + nimpp - 1 ) - 1.   ;   zim05 = FLOAT( ji + nimpp - 1 ) - 1.5
+             zjm1 = FLOAT( jj + njmpp - 1 ) - 1.   ;   zjm05 = FLOAT( jj + njmpp - 1 ) - 1.5
+
+             glamf(ji,jj) = glam0 + zim1  * ze1deg * zcos_alpha + zjm1  * ze1deg * zsin_alpha
+             gphif(ji,jj) = gphi0 - zim1  * ze1deg * zsin_alpha + zjm1  * ze1deg * zcos_alpha
+
+             glamt(ji,jj) = glam0 + zim05 * ze1deg * zcos_alpha + zjm05 * ze1deg * zsin_alpha
+             gphit(ji,jj) = gphi0 - zim05 * ze1deg * zsin_alpha + zjm05 * ze1deg * zcos_alpha
+
+             glamu(ji,jj) = glam0 + zim1  * ze1deg * zcos_alpha + zjm05 * ze1deg * zsin_alpha
+             gphiu(ji,jj) = gphi0 - zim1  * ze1deg * zsin_alpha + zjm05 * ze1deg * zcos_alpha
+
+             glamv(ji,jj) = glam0 + zim05 * ze1deg * zcos_alpha + zjm1  * ze1deg * zsin_alpha
+             gphiv(ji,jj) = gphi0 - zim05 * ze1deg * zsin_alpha + zjm1  * ze1deg * zcos_alpha
+           END DO
+          END DO
+
+         ! Horizontal scale factors (in meters)
+         !                              ======
+         e1t(:,:) =  ze1     ;      e2t(:,:) = ze1
+         e1u(:,:) =  ze1     ;      e2u(:,:) = ze1
+         e1v(:,:) =  ze1     ;      e2v(:,:) = ze1
+         e1f(:,:) =  ze1     ;      e2f(:,:) = ze1
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for jphgr_msh = ', jphgr_msh
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+
+      ! Control printing : Grid informations (if not restart)
+      ! ----------------
+
+      IF( lwp .AND. .NOT.ln_rstart ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          longitude and e1 scale factors'
+         WRITE(numout,*) '          ------------------------------'
+         WRITE(numout,9300) ( ji, glamt(ji,1), glamu(ji,1),   &
+            glamv(ji,1), glamf(ji,1),   &
+            e1t(ji,1), e1u(ji,1),   &
+            e1v(ji,1), e1f(ji,1), ji = 1, jpi,10)
+9300     FORMAT( 1x, i4, f8.2,1x, f8.2,1x, f8.2,1x, f8.2, 1x,    &
+            f19.10, 1x, f19.10, 1x, f19.10, 1x, f19.10 )
+         
+         WRITE(numout,*)
+         WRITE(numout,*) '          latitude and e2 scale factors'
+         WRITE(numout,*) '          -----------------------------'
+         WRITE(numout,9300) ( jj, gphit(1,jj), gphiu(1,jj),   &
+            &                     gphiv(1,jj), gphif(1,jj),   &
+            &                     e2t  (1,jj), e2u  (1,jj),   &
+            &                     e2v  (1,jj), e2f  (1,jj), jj = 1, jpj, 10 )
+      ENDIF
+
+      
+      IF( nprint == 1 .AND. lwp ) THEN
+         WRITE(numout,*) '          e1u e2u '
+         CALL prihre( e1u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         CALL prihre( e2u,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         WRITE(numout,*) '          e1v e2v  '
+         CALL prihre( e1v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         CALL prihre( e2v,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         WRITE(numout,*) '          e1f e2f  '
+         CALL prihre( e1f,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+         CALL prihre( e2f,jpi,jpj,jpi-5,jpi,1,jpj-5,jpj,1,0.,numout )
+      ENDIF
+
+
+      ! ================= !
+      !  Coriolis factor  !
+      ! ================= !
+
+      SELECT CASE( jphgr_msh )   ! type of horizontal mesh
+
+      CASE ( 0, 1, 4 )               ! mesh on the sphere
+
+         ff(:,:) = 2. * omega * SIN( rad * gphif(:,:) ) 
+
+      CASE ( 2 )                     ! f-plane at ppgphi0 
+
+         ff(:,:) = 2. * omega * SIN( rad * ppgphi0 )
+
+         IF(lwp) WRITE(numout,*) '          f-plane: Coriolis parameter = constant = ', ff(1,1)
+
+      CASE ( 3 )                     ! beta-plane
+
+         zbeta   = 2. * omega * COS( rad * ppgphi0 ) / ra                       ! beta at latitude ppgphi0
+         zphi0   = ppgphi0 - FLOAT( jpjglo/2) * ppe2_m / ( ra * rad )           ! latitude of the first row F-points
+         
+#if defined key_agrif && defined key_eel_r6
+         IF (.Not.Agrif_Root()) THEN
+           zphi0 = ppgphi0 - FLOAT( Agrif_Parent(jpjglo)/2)*Agrif_Parent(ppe2_m) / (ra * rad)
+         ENDIF
+#endif         
+         zf0     = 2. * omega * SIN( rad * zphi0 )                              ! compute f0 1st point south
+
+         ff(:,:) = ( zf0  + zbeta * gphif(:,:) * 1.e+3 )                        ! f = f0 +beta* y ( y=0 at south)
+         
+         IF(lwp) THEN
+            WRITE(numout,*) 
+            WRITE(numout,*) '          Beta-plane: Beta parameter = constant = ', ff(nldi,nldj)
+            WRITE(numout,*) '          Coriolis parameter varies from ', ff(nldi,nldj),' to ', ff(nldi,nlej)
+         ENDIF
+         IF( lk_mpp ) THEN 
+            zminff=ff(nldi,nldj)
+            zmaxff=ff(nldi,nlej)
+            CALL mpp_min( zminff )   ! min over the global domain
+            CALL mpp_max( zmaxff )   ! max over the global domain
+            IF(lwp) WRITE(numout,*) '          Coriolis parameter varies globally from ', zminff,' to ', zmaxff
+         END IF
+
+      CASE ( 5 )                     ! beta-plane and rotated domain (gyre configuration)
+
+         zbeta = 2. * omega * COS( rad * ppgphi0 ) / ra                     ! beta at latitude ppgphi0
+         zphi0 = 15.e0                                                      ! latitude of the first row F-points
+         zf0   = 2. * omega * SIN( rad * zphi0 )                            ! compute f0 1st point south
+
+         ff(:,:) = ( zf0 + zbeta * ABS( gphif(:,:) - zphi0 ) * rad * ra )   ! f = f0 +beta* y ( y=0 at south)
+
+         IF(lwp) THEN
+            WRITE(numout,*) 
+            WRITE(numout,*) '          Beta-plane and rotated domain : '
+            WRITE(numout,*) '          Coriolis parameter varies in this processor from ', ff(nldi,nldj),' to ', ff(nldi,nlej)
+         ENDIF
+
+         IF( lk_mpp ) THEN 
+            zminff=ff(nldi,nldj)
+            zmaxff=ff(nldi,nlej)
+            CALL mpp_min( zminff )   ! min over the global domain
+            CALL mpp_max( zmaxff )   ! max over the global domain
+            IF(lwp) WRITE(numout,*) '          Coriolis parameter varies globally from ', zminff,' to ', zmaxff
+         END IF
+
+      END SELECT
+
+
+      ! Control of domain for symetrical condition
+      ! ------------------------------------------
+      ! The equator line must be the latitude coordinate axe
+
+      IF( nperio == 2 ) THEN
+         znorme = SQRT( SUM( gphiu(:,2) * gphiu(:,2) ) ) / FLOAT( jpi )
+         IF( znorme > 1.e-13 ) CALL ctl_stop( ' ===>>>> : symmetrical condition: rerun with good equator line' )
+      ENDIF
+
+   END SUBROUTINE dom_hgr
+
+
+   SUBROUTINE hgr_read
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE hgr_read  ***
+      !!
+      !! ** Purpose :   Read a coordinate file in NetCDF format 
+      !!
+      !! ** Method  :   The mesh file has been defined trough a analytical 
+      !!      or semi-analytical method. It is read in a NetCDF file. 
+      !!     
+      !!----------------------------------------------------------------------
+      USE iom
+
+      INTEGER ::   inum   ! temporary logical unit
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'hgr_read : read the horizontal coordinates'
+         WRITE(numout,*) '~~~~~~~~      jpiglo = ', jpiglo, ' jpjglo = ', jpjglo, ' jpk = ', jpk
+      ENDIF
+      
+      CALL iom_open( 'coordinates', inum )
+      
+      CALL iom_get( inum, jpdom_data, 'glamt', glamt )
+      CALL iom_get( inum, jpdom_data, 'glamu', glamu )
+      CALL iom_get( inum, jpdom_data, 'glamv', glamv )
+      CALL iom_get( inum, jpdom_data, 'glamf', glamf )
+      
+      CALL iom_get( inum, jpdom_data, 'gphit', gphit )
+      CALL iom_get( inum, jpdom_data, 'gphiu', gphiu )
+      CALL iom_get( inum, jpdom_data, 'gphiv', gphiv )
+      CALL iom_get( inum, jpdom_data, 'gphif', gphif )
+      
+      CALL iom_get( inum, jpdom_data, 'e1t', e1t )
+      CALL iom_get( inum, jpdom_data, 'e1u', e1u )
+      CALL iom_get( inum, jpdom_data, 'e1v', e1v )
+      CALL iom_get( inum, jpdom_data, 'e1f', e1f )
+      
+      CALL iom_get( inum, jpdom_data, 'e2t', e2t )
+      CALL iom_get( inum, jpdom_data, 'e2u', e2u )
+      CALL iom_get( inum, jpdom_data, 'e2v', e2v )
+      CALL iom_get( inum, jpdom_data, 'e2f', e2f )
+      
+      CALL iom_close( inum )
+      
+    END SUBROUTINE hgr_read
+    
+   !!======================================================================
+END MODULE domhgr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 4536)
@@ -0,0 +1,675 @@
+MODULE dommsk
+   !!==============================================================================
+   !!                       ***  MODULE dommsk   ***
+   !! Ocean initialization : domain land/sea mask 
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_msk        : compute land/ocean mask
+   !!   dom_msk_nsa    : update land/ocean mask when no-slip accurate
+   !!                    option is used.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE obc_oce         ! ocean open boundary conditions
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp
+   USE solisl          ! ???
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_msk        ! routine called by inidom.F90
+
+   !! * Module variables
+   REAL(wp) ::   &
+      shlat = 2.   ! type of lateral boundary condition on velocity (namelist namlbc)
+   
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE dom_msk
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dom_msk  ***
+      !!
+      !! ** Purpose :   Compute land/ocean mask arrays at tracer points, hori-
+      !!      zontal velocity points (u & v), vorticity points (f) and baro-
+      !!      tropic stream function  points (b).
+      !!        Set mbathy to the number of non-zero w-levels of a water column
+      !!      (if island in the domain (lk_isl=T), this is done latter in
+      !!      routine solver_init)
+      !!
+      !! ** Method  :   The ocean/land mask is computed from the basin bathy-
+      !!      metry in level (mbathy) which is defined or read in dommba.
+      !!      mbathy equals 0 over continental T-point, -n over the nth 
+      !!      island T-point, and the number of ocean level over the ocean.
+      !!
+      !!      At a given position (ji,jj,jk) the ocean/land mask is given by:
+      !!      t-point : 0. IF mbathy( ji ,jj) =< 0
+      !!                1. IF mbathy( ji ,jj) >= jk
+      !!      u-point : 0. IF mbathy( ji ,jj)  or mbathy(ji+1, jj ) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy(ji+1, jj ) >= jk.
+      !!      v-point : 0. IF mbathy( ji ,jj)  or mbathy( ji ,jj+1) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy( ji ,jj+1) >= jk.
+      !!      f-point : 0. IF mbathy( ji ,jj)  or mbathy( ji ,jj+1)
+      !!                   or mbathy(ji+1,jj)  or mbathy(ji+1,jj+1) =< 0
+      !!                1. IF mbathy( ji ,jj) and mbathy( ji ,jj+1)
+      !!                and mbathy(ji+1,jj) and mbathy(ji+1,jj+1) >= jk.
+      !!      b-point : the same definition as for f-point of the first ocean
+      !!                level (surface level) but with 0 along coastlines.
+      !!
+      !!        The lateral friction is set through the value of fmask along
+      !!      the coast and topography. This value is defined by shlat, a
+      !!      namelist parameter:
+      !!         shlat = 0, free slip  (no shear along the coast)
+      !!         shlat = 2, no slip  (specified zero velocity at the coast)
+      !!         0 < shlat < 2, partial slip   | non-linear velocity profile
+      !!         2 < shlat, strong slip        | in the lateral boundary layer
+      !!
+      !!      N.B. If nperio not equal to 0, the land/ocean mask arrays
+      !!      are defined with the proper value at lateral domain boundaries,
+      !!      but bmask. indeed, bmask defined the domain over which the
+      !!      barotropic stream function is computed. this domain cannot
+      !!      contain identical columns because the matrix associated with
+      !!      the barotropic stream function equation is then no more inverti-
+      !!      ble. therefore bmask is set to 0 along lateral domain boundaries
+      !!      even IF nperio is not zero.
+      !!
+      !!      In case of open boundaries (lk_obc=T):
+      !!        - tmask is set to 1 on the points to be computed bay the open
+      !!          boundaries routines.
+      !!        - bmask is  set to 0 on the open boundaries.
+      !!
+      !!      Set mbathy to the number of non-zero w-levels of a water column
+      !!                  mbathy = min( mbathy, 1 ) + 1
+      !!      (note that the minimum value of mbathy is 2).
+      !!
+      !! ** Action :
+      !!                     tmask    : land/ocean mask at t-point (=0. or 1.)
+      !!                     umask    : land/ocean mask at u-point (=0. or 1.)
+      !!                     vmask    : land/ocean mask at v-point (=0. or 1.)
+      !!                     fmask    : land/ocean mask at f-point (=0. or 1.)
+      !!                          =shlat along lateral boundaries
+      !!                     bmask    : land/ocean mask at barotropic stream
+      !!                          function point (=0. or 1.) and set to
+      !!                          0 along lateral boundaries
+      !!                   mbathy   : number of non-zero w-levels 
+      !!
+      !! History :
+      !!        !  87-07  (G. Madec)  Original code
+      !!        !  91-12  (G. Madec)
+      !!        !  92-06  (M. Imbard)
+      !!        !  93-03  (M. Guyon)  symetrical conditions (M. Guyon)
+      !!        !  96-01  (G. Madec)  suppression of common work arrays
+      !!        !  96-05  (G. Madec)  mask computed from tmask and sup-
+      !!                 pression of the double computation of bmask
+      !!        !  97-02  (G. Madec)  mesh information put in domhgr.F
+      !!        !  97-07  (G. Madec)  modification of mbathy and fmask
+      !!        !  98-05  (G. Roullet)  free surface
+      !!        !  00-03  (G. Madec)  no slip accurate
+      !!        !  01-09  (J.-M. Molines)  Open boundaries
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      INTEGER  ::   iif, iil, ii0, ii1, ii
+      INTEGER  ::   ijf, ijl, ij0, ij1
+      INTEGER, DIMENSION(jpi,jpj) ::  imsk
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwf
+
+      NAMELIST/namlbc/ shlat
+      !!---------------------------------------------------------------------
+      
+      ! Namelist namlbc : lateral momentum boundary condition
+      REWIND( numnam )
+      READ  ( numnam, namlbc )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dommsk : ocean mask '
+         WRITE(numout,*) '~~~~~~'
+         WRITE(numout,*) '         Namelist namlbc'
+         WRITE(numout,*) '            lateral momentum boundary cond. shlat = ',shlat
+      ENDIF
+
+      IF ( shlat == 0. ) THEN
+          IF(lwp) WRITE(numout,*) '         ocean lateral free-slip '
+        ELSEIF ( shlat  ==  2. ) THEN
+          IF(lwp) WRITE(numout,*) '         ocean lateral  no-slip '
+        ELSEIF ( 0. < shlat .AND. shlat < 2. ) THEN
+          IF(lwp) WRITE(numout,*) '         ocean lateral  partial-slip '
+        ELSEIF ( 2. < shlat ) THEN
+          IF(lwp) WRITE(numout,*) '         ocean lateral  strong-slip '
+        ELSE
+          WRITE(ctmp1,*) ' shlat is negative = ', shlat
+          CALL ctl_stop( ctmp1 )
+      ENDIF
+
+      ! 1. Ocean/land mask at t-point (computed from mbathy)
+      ! -----------------------------
+      ! Tmask has already the right boundary conditions since mbathy is ok
+
+      tmask(:,:,:) = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( FLOAT( mbathy(ji,jj)-jk )+.1 >= 0.e0 ) tmask(ji,jj,jk) = 1.e0
+            END DO  
+         END DO  
+      END DO  
+
+#if defined key_zdfkpp
+      IF( cp_cfg == 'orca' )   THEN
+         IF( jp_cfg = 2 )   THEN
+            ! land point on Bab el Mandeb zonal section
+            ij0 =  87   ;   ij1 =  88
+            ii0 = 160   ;   ii1 = 161
+            tmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 0.e0
+         ELSE
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,cform_war)
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*)'          A mask must be applied on Bab el Mandeb strait'
+            IF(lwp) WRITE(numout,*)'          in case of ORCAs configurations'
+            IF(lwp) WRITE(numout,*)'          This is a problem which is not yet solved'
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+#endif
+
+      ! Interior domain mask (used for global sum)
+      ! --------------------
+
+      tmask_i(:,:) = tmask(:,:,1)
+      iif = jpreci                         ! ???
+      iil = nlci - jpreci + 1
+      ijf = jprecj                         ! ???
+      ijl = nlcj - jprecj + 1
+
+      tmask_i( 1 :iif,   :   ) = 0.e0      ! first columns
+      tmask_i(iil:jpi,   :   ) = 0.e0      ! last  columns (including mpp extra columns)
+      tmask_i(   :   , 1 :ijf) = 0.e0      ! first rows
+      tmask_i(   :   ,ijl:jpj) = 0.e0      ! last  rows (including mpp extra rows)
+
+      ! north fold mask
+      tpol(1:jpiglo) = 1.e0 
+      fpol(1:jpiglo) = 1.e0
+      IF( jperio == 3 .OR. jperio == 4 ) THEN      ! T-point pivot
+         tpol(jpiglo/2+1:jpiglo) = 0.e0
+         fpol(     1    :jpiglo) = 0.e0
+         ! T-point pivot: only half of the nlcj-1 row
+         IF( mjg(nlej) == jpjglo )   THEN
+            DO ji = iif+1, iil-1
+               tmask_i(ji,nlej-1) = tmask_i(ji,nlej-1) * tpol(mig(ji))
+            END DO
+         ENDIF
+      ENDIF
+      IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
+         tpol(     1    :jpiglo) = 0.e0
+         fpol(jpiglo/2+1:jpiglo) = 0.e0
+      ENDIF
+
+      ! 2. Ocean/land mask at u-,  v-, and z-points (computed from tmask)
+      ! -------------------------------------------
+      
+      ! Computation
+      DO jk = 1, jpk
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector loop
+               umask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)
+               vmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji  ,jj+1,jk)
+               fmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
+                  &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
+            END DO
+         END DO
+      END DO
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN
+         !                                           ! =======================
+         ! modified vmask value in                   !  ORCA_R2 configuration
+         ! the vicinity of some straits              ! =======================
+
+         IF( n_cla == 1 ) THEN 
+            !                                ! vmask = 0. on Gibraltar zonal section
+            ij0 = 101   ;   ij1 = 101
+            ii0 = 138   ;   ii1 = 139   ;   vmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 19:jpk ) = 0.e0
+            !                                ! vmask = 0. on Bab el Mandeb zonal section
+            ij0 =  87   ;   ij1 =  87
+            ii0 = 161   ;   ii1 = 163   ;   vmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 18:jpk ) = 0.e0
+         ENDIF
+
+      ENDIF
+      
+      ! Lateral boundary conditions
+      CALL lbc_lnk( umask, 'U', 1. )
+      CALL lbc_lnk( vmask, 'V', 1. )
+      CALL lbc_lnk( fmask, 'F', 1. )
+
+
+      ! 4. ocean/land mask for the elliptic equation
+      ! --------------------------------------------
+      
+      ! Computation
+      IF( lk_dynspg_rl ) THEN
+         bmask(:,:) = fmask(:,:,1)       ! elliptic equation is written at f-point
+      ELSE
+         bmask(:,:) = tmask(:,:,1)       ! elliptic equation is written at t-point
+      ENDIF
+      
+      ! Boundary conditions
+      !   cyclic east-west : bmask must be set to 0. on rows 1 and jpi
+      IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+         bmask( 1 ,:) = 0.e0
+         bmask(jpi,:) = 0.e0
+      ENDIF
+      
+      !   south symmetric :  bmask must be set to 0. on row 1
+      IF( nperio == 2 ) THEN
+         bmask(:, 1 ) = 0.e0
+      ENDIF
+      
+      !   north fold : 
+      IF( nperio == 3 .OR. nperio == 4 ) THEN
+         IF( lk_dynspg_rl ) THEN
+            ! T-pt pivot and F-pt elliptic eq. : bmask set to 0. on rows jpj-1 and jpj
+            bmask(:,jpj-1) = 0.e0
+            bmask(:,jpj  ) = 0.e0
+         ELSE
+            ! T-pt pivot and T-pt elliptic eq. : bmask set to 0. on row jpj and on half jpjglo-1 row
+            DO ji = 1, jpi
+               ii = ji + nimpp - 1
+               bmask(ji,jpj-1) = bmask(ji,jpj-1) * tpol(ii)
+               bmask(ji,jpj  ) = 0.e0
+            END DO
+         ENDIF
+      ENDIF
+      IF( nperio == 5 .OR. nperio == 6 ) THEN
+         IF( lk_dynspg_rl ) THEN
+            ! F-pt pivot and F-pt elliptic eq. : bmask set to 0. on row jpj and on half jpjglo-1 row
+            DO ji = 1, jpi
+               ii = ji + nimpp - 1
+               bmask(ji,jpj-1) = bmask(ji,jpj-1) * fpol(ii)
+               bmask(ji,jpj  ) = 0.e0
+            END DO
+         ELSE
+            ! F-pt pivot and T-pt elliptic eq. : bmask set to 0. on row jpj
+            bmask(:,jpj) = 0.e0
+         ENDIF
+      ENDIF
+
+      ! Mpp boundary conditions: bmask is set to zero on the overlap
+      ! region for all elliptic solvers
+
+      IF( lk_mpp ) THEN
+         IF( nbondi /= -1 .AND. nbondi /= 2 )   bmask(  1 :jpreci,:) = 0.e0
+         IF( nbondi /=  1 .AND. nbondi /= 2 )   bmask(nlci:jpi   ,:) = 0.e0
+         IF( nbondj /= -1 .AND. nbondj /= 2 )   bmask(:,  1 :jprecj) = 0.e0
+         IF( nbondj /=  1 .AND. nbondj /= 2 )   bmask(:,nlcj:jpj   ) = 0.e0
+      
+         ! north fold : bmask must be set to 0. on rows jpj-1 and jpj 
+         IF( npolj == 3 .OR. npolj == 4 ) THEN
+            IF( lk_dynspg_rl ) THEN
+               DO ji = 1, nlci
+                  bmask(ji,nlcj-1) = 0.e0
+                  bmask(ji,nlcj  ) = 0.e0
+               END DO
+            ELSE
+               DO ji = 1, nlci
+                  ii = ji + nimpp - 1
+                  bmask(ji,nlcj-1) = bmask(ji,nlcj-1) * tpol(ii)
+                  bmask(ji,nlcj  ) = 0.e0
+               END DO
+            ENDIF
+         ENDIF
+         IF( npolj == 5 .OR. npolj == 6 ) THEN
+            IF( lk_dynspg_rl ) THEN
+               DO ji = 1, nlci
+                  ii = ji + nimpp - 1
+                  bmask(ji,nlcj-1) = bmask(ji,nlcj-1) * fpol(ii)
+                  bmask(ji,nlcj  ) = 0.e0
+               END DO
+            ELSE
+               DO ji = 1, nlci
+                  bmask(ji,nlcj  ) = 0.e0
+               END DO
+            ENDIF
+         ENDIF
+      ENDIF
+
+
+      ! mask for second order calculation of vorticity
+      ! ----------------------------------------------
+      
+      CALL dom_msk_nsa
+
+      
+      ! Lateral boundary conditions on velocity (modify fmask)
+      ! ---------------------------------------
+      
+      DO jk = 1, jpk
+
+         zwf(:,:) = fmask(:,:,jk)
+         
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               IF( fmask(ji,jj,jk) == 0. ) THEN
+                  fmask(ji,jj,jk) = shlat * MIN( 1., MAX( zwf(ji+1,jj), zwf(ji,jj+1),   &
+                     &                                    zwf(ji-1,jj), zwf(ji,jj-1)  )  )
+               ENDIF
+            END DO
+         END DO
+         
+         DO jj = 2, jpjm1
+            IF( fmask(1,jj,jk) == 0. ) THEN
+               fmask(1  ,jj,jk) = shlat * MIN( 1., MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
+            ENDIF
+            IF( fmask(jpi,jj,jk) == 0. ) THEN
+               fmask(jpi,jj,jk) = shlat * MIN( 1., MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
+            ENDIF
+         END DO
+         
+         DO ji = 2, jpim1
+            IF( fmask(ji,1,jk) == 0. ) THEN
+               fmask(ji, 1 ,jk) = shlat * MIN( 1., MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
+            ENDIF
+            IF( fmask(ji,jpj,jk) == 0. ) THEN
+               fmask(ji,jpj,jk) = shlat * MIN( 1., MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
+            ENDIF
+         END DO
+      END DO
+      
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN
+         !                                           ! =======================
+         ! Increased lateral friction in             !  ORCA_R2 configuration
+         ! the vicinity of some straits              ! =======================
+         !
+         IF( n_cla == 0 ) THEN
+            !                                ! Sound  strait
+            ij0 = 116   ;   ij1 = 117
+            ii0 = 147   ;   ii1 = 148   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 10.0e0
+         ELSE
+            !                                ! Gibraltar strait and Gulf of Cadiz
+            ij0 = 102   ;   ij1 = 102
+            ii0 = 137   ;   ii1 = 139   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.0e0
+            ij0 = 101   ;   ij1 = 101
+            ii0 = 139   ;   ii1 = 139   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.0e0
+            ij0 = 100   ;   ij1 = 100
+            ii0 = 137   ;   ii1 = 139   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.0e0
+            !                                ! Sound  strait
+            ij0 = 116   ;   ij1 = 117
+            ii0 = 147   ;   ii1 = 148   ;   fmask( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 10.0e0
+         ENDIF
+         !
+      ENDIF
+      
+      ! Lateral boundary conditions on fmask
+      CALL lbc_lnk( fmask, 'F', 1. )
+      
+      ! Mbathy set to the number of w-level (minimum value 2)
+      ! -----------------------------------
+      IF( lk_isl ) THEN
+         ! this is done at the end of solver_init routine
+      ELSE
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               mbathy(ji,jj) = MAX( 1, mbathy(ji,jj) ) + 1
+            END DO
+         END DO
+      ENDIF
+      
+      ! Control print
+      ! -------------
+      IF( nprint == 1 .AND. lwp ) THEN
+         imsk(:,:) = INT( tmask_i(:,:) )
+         WRITE(numout,*) ' tmask_i : '
+         CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                           1, jpj, 1, 1, numout)
+         WRITE (numout,*)
+         WRITE (numout,*) ' dommsk: tmask for each level'
+         WRITE (numout,*) ' ----------------------------'
+         DO jk = 1, jpk
+            imsk(:,:) = INT( tmask(:,:,jk) )
+
+            WRITE(numout,*)
+            WRITE(numout,*) ' level = ',jk
+            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                              1, jpj, 1, 1, numout)
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) ' dom_msk: vmask for each level'
+         WRITE(numout,*) ' -----------------------------'
+         DO jk = 1, jpk
+            imsk(:,:) = INT( vmask(:,:,jk) )
+            WRITE(numout,*)
+            WRITE(numout,*) ' level = ',jk
+            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                              1, jpj, 1, 1, numout)
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) ' dom_msk: fmask for each level'
+         WRITE(numout,*) ' -----------------------------'
+         DO jk = 1, jpk
+            imsk(:,:) = INT( fmask(:,:,jk) )
+            WRITE(numout,*)
+            WRITE(numout,*) ' level = ',jk
+            CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                              1, jpj, 1, 1, numout )
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) ' dom_msk: bmask '
+         WRITE(numout,*) ' ---------------'
+         WRITE(numout,*)
+         imsk(:,:) = INT( bmask(:,:) )
+         CALL prihin( imsk(:,:), jpi, jpj, 1, jpi, 1,   &
+               &                           1, jpj, 1, 1, numout )
+      ENDIF
+
+   END SUBROUTINE dom_msk
+
+#if defined key_noslip_accurate
+   !!----------------------------------------------------------------------
+   !!   'key_noslip_accurate' :         accurate no-slip boundary condition
+   !!----------------------------------------------------------------------
+   
+   SUBROUTINE dom_msk_nsa
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dom_msk_nsa  ***
+      !! 
+      !! ** Purpose :
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action :
+      !!
+      !! History :
+      !!        !  00-03  (G. Madec)  no slip accurate
+      !!----------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk, jl      ! dummy loop indices
+      INTEGER ::   ine, inw, ins, inn, itest, ierror, iind, ijnd, ii
+      INTEGER, DIMENSION(jpi*jpj*jpk,3) ::  icoord
+      REAL(wp) ::   zaa
+      !!---------------------------------------------------------------------
+      
+
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'dom_msk_nsa : noslip accurate boundary condition'
+      IF(lwp)WRITE(numout,*) '~~~~~~~~~~~   using Schchepetkin and O Brian scheme'
+      IF( lk_mpp ) CALL ctl_stop( ' mpp version is not yet implemented' )
+
+      ! mask for second order calculation of vorticity
+      ! ----------------------------------------------
+      ! noslip boundary condition: fmask=1  at convex corner, store
+      ! index of straight coast meshes ( 'west', refering to a coast,
+      ! means west of the ocean, aso)
+      
+      DO jk = 1, jpk
+         DO jl = 1, 4
+            npcoa(jl,jk) = 0
+            DO ji = 1, 2*(jpi+jpj)
+               nicoa(ji,jl,jk) = 0
+               njcoa(ji,jl,jk) = 0
+            END DO
+         END DO
+      END DO
+      
+      IF( jperio == 2 ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' symetric boundary conditions need special'
+         WRITE(numout,*) ' treatment not implemented. we stop.'
+         STOP
+      ENDIF
+      
+      ! convex corners
+      
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zaa = tmask(ji  ,jj,jk) + tmask(ji  ,jj+1,jk)   &
+                  &+ tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk)
+               IF( ABS(zaa-3.) <= 0.1 )   fmask(ji,jj,jk) = 1.
+            END DO
+         END DO
+      END DO
+
+      ! north-south straight coast
+
+      DO jk = 1, jpkm1
+         inw = 0
+         ine = 0
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zaa = tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk)
+               IF( ABS(zaa-2.) <= 0.1 .AND. fmask(ji,jj,jk) == 0 ) THEN
+                  inw = inw + 1
+                  nicoa(inw,1,jk) = ji
+                  njcoa(inw,1,jk) = jj
+                  IF( nprint == 1 ) WRITE(numout,*) ' west  : ', jk, inw, ji, jj
+               ENDIF
+               zaa = tmask(ji,jj,jk) + tmask(ji,jj+1,jk)
+               IF( ABS(zaa-2.) <= 0.1 .AND. fmask(ji,jj,jk) == 0 ) THEN
+                  ine = ine + 1
+                  nicoa(ine,2,jk) = ji
+                  njcoa(ine,2,jk) = jj
+                  IF( nprint == 1 ) WRITE(numout,*) ' east  : ', jk, ine, ji, jj
+               ENDIF
+            END DO
+         END DO
+         npcoa(1,jk) = inw
+         npcoa(2,jk) = ine
+      END DO
+
+      ! west-east straight coast
+
+      DO jk = 1, jpkm1
+         ins = 0
+         inn = 0
+         DO jj = 2, jpjm1
+            DO ji =2, jpim1
+               zaa = tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk)
+               IF( ABS(zaa-2.) <= 0.1 .AND. fmask(ji,jj,jk) == 0 ) THEN
+                  ins = ins + 1
+                  nicoa(ins,3,jk) = ji
+                  njcoa(ins,3,jk) = jj
+                  IF( nprint == 1 ) WRITE(numout,*) ' south : ', jk, ins, ji, jj
+               ENDIF
+               zaa = tmask(ji+1,jj,jk) + tmask(ji,jj,jk)
+               IF( ABS(zaa-2.) <= 0.1 .AND. fmask(ji,jj,jk) == 0 ) THEN
+                  inn = inn + 1
+                  nicoa(inn,4,jk) = ji
+                  njcoa(inn,4,jk) = jj
+                  IF( nprint == 1 ) WRITE(numout,*) ' north : ', jk, inn, ji, jj
+               ENDIF
+            END DO
+         END DO
+         npcoa(3,jk) = ins
+         npcoa(4,jk) = inn
+      END DO
+
+      itest = 2 * ( jpi + jpj )
+      DO jk = 1, jpk
+         IF( npcoa(1,jk) > itest .OR. npcoa(2,jk) > itest .OR.   &
+             npcoa(3,jk) > itest .OR. npcoa(4,jk) > itest ) THEN
+            
+            WRITE(ctmp1,*) ' level jk = ',jk
+            WRITE(ctmp2,*) ' straight coast index arraies are too small.:'
+            WRITE(ctmp3,*) ' npe, npw, nps, npn = ', npcoa(1,jk), npcoa(2,jk),   &
+                &                                     npcoa(3,jk), npcoa(4,jk)
+            WRITE(ctmp4,*) ' 2*(jpi+jpj) = ',itest,'. we stop.'
+            CALL ctl_stop( ctmp1, ctmp2, ctmp3, ctmp4 )
+        ENDIF
+      END DO
+
+      ierror = 0
+      iind = 0
+      ijnd = 0
+      IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) iind = 2
+      IF( nperio == 3 .OR. nperio == 4 .OR. nperio == 5 .OR. nperio == 6 ) ijnd = 2
+      DO jk = 1, jpk
+         DO jl = 1, npcoa(1,jk)
+            IF( nicoa(jl,1,jk)+3 > jpi+iind ) THEN
+               ierror = ierror+1
+               icoord(ierror,1) = nicoa(jl,1,jk)
+               icoord(ierror,2) = njcoa(jl,1,jk)
+               icoord(ierror,3) = jk
+            ENDIF
+         END DO
+         DO jl = 1, npcoa(2,jk)
+            IF(nicoa(jl,2,jk)-2 < 1-iind ) THEN
+               ierror = ierror + 1
+               icoord(ierror,1) = nicoa(jl,2,jk)
+               icoord(ierror,2) = njcoa(jl,2,jk)
+               icoord(ierror,3) = jk
+            ENDIF
+         END DO
+         DO jl = 1, npcoa(3,jk)
+            IF( njcoa(jl,3,jk)+3 > jpj+ijnd ) THEN
+               ierror = ierror + 1
+               icoord(ierror,1) = nicoa(jl,3,jk)
+               icoord(ierror,2) = njcoa(jl,3,jk)
+               icoord(ierror,3) = jk
+            ENDIF
+         END DO
+         DO jl=1,npcoa(4,jk)
+            IF( njcoa(jl,4,jk)-2 < 1) THEN
+               ierror=ierror+1
+               icoord(ierror,1)=nicoa(jl,4,jk)
+               icoord(ierror,2)=njcoa(jl,4,jk)
+               icoord(ierror,3)=jk
+            ENDIF
+         END DO
+      END DO
+      
+      IF( ierror > 0 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '              Problem on lateral conditions'
+         IF(lwp) WRITE(numout,*) '                 Bad marking off at points:'
+         DO jl = 1, ierror
+            IF(lwp) WRITE(numout,*) 'Level:',icoord(jl,3),   &
+               &                  '  Point(',icoord(jl,1),',',icoord(jl,2),')'
+         END DO
+         CALL ctl_stop( 'We stop...' )
+      ENDIF
+
+   END SUBROUTINE dom_msk_nsa
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                      Empty routine
+   !!----------------------------------------------------------------------
+   SUBROUTINE dom_msk_nsa       
+   END SUBROUTINE dom_msk_nsa
+#endif
+   
+   !!======================================================================
+END MODULE dommsk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domstp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 4536)
@@ -0,0 +1,115 @@
+MODULE domstp
+   !!==============================================================================
+   !!                       ***  MODULE domstp   ***
+   !! Ocean initialization : time domain
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_stp        : ocean time domain initialization
+   !!----------------------------------------------------------------------
+   !! History :
+   !!        !  90-10  (O. Marti)  Original code
+   !!        !  96-01  (G. Madec)  terrain following coordinates
+   !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * routine accessibility
+   PUBLIC dom_stp        ! routine called by inidom.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_stp
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dom_stp  ***
+      !!          
+      !! ** Purpose :   Intialize ocean time step for the run
+      !!
+      !! ** Method  : - Initialization of a coef. use in the Asselin time
+      !!      filter:  atfp1 = 1 - 2 * atfp  where atfp is the Asselin time
+      !!      filter parameter read in namelist
+      !!              - Model time step:
+      !!      nacc = 0 : synchronous time intergration. 
+      !!      There is one time step only, defined by: rdt, rdttra(k)=rdt
+      !!      nacc = 1 : accelerating the convergence. There is 2 different
+      !!      time steps for dynamics and tracers:
+      !!        rdt      : dynamical part
+      !!        rdttra(k): temperature and salinity
+      !!      The tracer time step is a function of vertical level. the model
+      !!      reference time step ( i.e. for wind stress, surface heat and
+      !!      salt fluxes) is the surface tracer time step is rdttra(1).
+      !!         N.B. depth dependent acceleration of convergence is not im-
+      !!      plemented for s-coordinate.
+      !!
+      !! ** Action  : - rdttra   : vertical profile of tracer time step
+      !!              - atfp1    : = 1 - 2*atfp
+      !!
+      !! References :
+      !!      Bryan, K., 1984, J. Phys. Oceanogr., 14, 666-673.
+      !!----------------------------------------------------------------------
+      INTEGER ::   jk              ! dummy loop indice
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_stp : time stepping setting'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! 0. Asselin Time filter
+      ! ----------------------
+      
+      atfp1 = 1. - 2. * atfp
+
+      SELECT CASE ( nacc )
+
+         CASE ( 0 )                ! Synchronous time stepping
+            IF(lwp) WRITE(numout,*)'               synchronous time stepping'
+            IF(lwp) WRITE(numout,*)'               dynamics and tracer time step = ', rdt/3600., ' hours'
+
+            rdttra(:) = rdt
+
+         CASE ( 1 )                ! Accelerating the convergence
+            IF(lwp) WRITE(numout,*) '              no tracer damping in the turbocline'
+            IF(lwp) WRITE(numout,*)'               accelerating the convergence'
+            IF(lwp) WRITE(numout,*)'               dynamics time step = ', rdt/3600., ' hours'
+            IF( ln_sco .AND. rdtmin /= rdtmax .AND. lk_vvl )   &
+                 & CALL ctl_stop ( ' depth dependent acceleration of convergence not implemented in s-coordinates &
+                 &                   nor in variable volume' )
+            IF(lwp) WRITE(numout,*)'         tracers   time step :  dt (hours)  level'
+
+            DO jk = 1, jpk
+               IF( gdept_0(jk) <= rdth ) rdttra(jk) = rdtmin
+               IF( gdept_0(jk) >  rdth ) THEN
+                  rdttra(jk) = rdtmin + ( rdtmax - rdtmin )   &
+                                      * ( EXP( ( gdept_0(jk ) - rdth ) / rdth ) - 1. )   &
+                                      / ( EXP( ( gdept_0(jpk) - rdth ) / rdth ) - 1. )
+               ENDIF
+               IF(lwp) WRITE(numout,"(36x,f5.2,5x,i3)") rdttra(jk)/3600., jk
+            END DO  
+
+         CASE DEFAULT              ! E R R O R 
+
+            WRITE(ctmp1,*) ' nacc value e r r o r, nacc= ',nacc
+            CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE dom_stp
+
+   !!======================================================================
+END MODULE domstp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4536)
@@ -0,0 +1,403 @@
+MODULE domvvl
+   !!======================================================================
+   !!                       ***  MODULE domvvl   ***
+   !! Ocean : 
+   !!======================================================================
+   !! History :   9.0  !  06-06  (B. Levier, L. Marie)  original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   'key_vvl'                              variable volume
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dom_vvl         : defined scale factors & depths at each time step
+   !!   dom_vvl_ini     : defined coefficients to distribute ssh on each layers
+   !!   dom_vvl_ssh     : defined the ocean sea level at each time step
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE ocesbc          ! ocean surface boundary condition
+   USE phycst          ! physical constants
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dom_vvl_ini    ! called by dom_init.F90
+   PUBLIC dom_vvl_ssh    ! called by trazdf.F90
+   PUBLIC dom_vvl        ! called by istate.F90 and step.F90
+   PUBLIC dom_vvl_sf_ini ! 
+   PUBLIC dom_vvl_sf     ! 
+
+   !! * Module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      mut, muu, muv, muf                            !:
+
+   REAL(wp), DIMENSION(jpk) ::   r2dt               ! vertical profile time-step, = 2 rdttra 
+      !                                             ! except at nit000 (=rdttra) if neuler=0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS       
+
+#if defined key_vvl
+
+   SUBROUTINE dom_vvl_ini
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_ini  ***
+      !!                   
+      !! ** Purpose :  compute coefficients muX at T-U-V-F points to spread
+      !!               ssh over the whole water column (scale factors)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, zpk
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmut, zmuu, zmuv, zmuf   ! 2D workspace
+      !!----------------------------------------------------------------------
+
+      IF(lwp)   THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_vvl_ini : Variable volume activated'
+         WRITE(numout,*) '~~~~~~~~~~~   compute coef. used to spread ssh over each layers'
+      ENDIF
+
+      IF( ln_zps )  CALL ctl_stop( 'dom_vvl_ini : option ln_zps is incompatible with variable volume option key_vvl')
+
+#if defined key_zco  ||  defined key_dynspg_rl
+      CALL ctl_stop( 'dom_vvl_ini : options key_zco/key_dynspg_rl are incompatible with variable volume option key_vvl')
+#endif
+
+      fsvdept (:,:,:) = gdept (:,:,:)
+      fsvdepw (:,:,:) = gdepw (:,:,:)
+      fsvde3w (:,:,:) = gdep3w(:,:,:)
+      fsve3t  (:,:,:) = e3t   (:,:,:)
+      fsve3u  (:,:,:) = e3u   (:,:,:)
+      fsve3v  (:,:,:) = e3v   (:,:,:)
+      fsve3f  (:,:,:) = e3f   (:,:,:)
+      fsve3w  (:,:,:) = e3w   (:,:,:)
+      fsve3uw (:,:,:) = e3uw  (:,:,:)
+      fsve3vw (:,:,:) = e3vw  (:,:,:)
+
+      ! mu computation
+      zmut(:,:)   = 0.e0
+      zmuu(:,:)   = 0.e0
+      zmuv(:,:)   = 0.e0
+      zmuf(:,:)   = 0.e0
+      mut (:,:,:) = 0.e0
+      muu (:,:,:) = 0.e0
+      muv (:,:,:) = 0.e0
+      muf (:,:,:) = 0.e0
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zpk = mbathy(ji,jj) - 1
+            DO jk = 1, zpk
+               zmut(ji,jj) = zmut(ji,jj) + fsve3t(ji,jj,jk) * SUM( fsve3t(ji,jj,jk:zpk) )
+               zmuu(ji,jj) = zmuu(ji,jj) + fsve3u(ji,jj,jk) * SUM( fsve3u(ji,jj,jk:zpk) )
+               zmuv(ji,jj) = zmuv(ji,jj) + fsve3v(ji,jj,jk) * SUM( fsve3v(ji,jj,jk:zpk) )
+               zmuf(ji,jj) = zmuf(ji,jj) + fsve3f(ji,jj,jk) * SUM( fsve3f(ji,jj,jk:zpk) )
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zpk = mbathy(ji,jj) - 1
+            DO jk = 1, zpk
+               mut(ji,jj,jk) = SUM( fsve3t(ji,jj,jk:zpk) ) / zmut(ji,jj)
+               muu(ji,jj,jk) = SUM( fsve3u(ji,jj,jk:zpk) ) / zmuu(ji,jj)
+               muv(ji,jj,jk) = SUM( fsve3v(ji,jj,jk:zpk) ) / zmuv(ji,jj)
+               muf(ji,jj,jk) = SUM( fsve3f(ji,jj,jk:zpk) ) / zmuf(ji,jj)
+            END DO
+         END DO
+      END DO
+
+
+   END SUBROUTINE dom_vvl_ini
+
+
+
+   SUBROUTINE dom_vvl
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl  ***
+      !!                   
+      !! ** Purpose :  compute ssh at U-V-F points, T-W scale factors and local
+      !!               depths at each time step.
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshf    ! 2D workspace
+      !!----------------------------------------------------------------------
+
+      ! Sea Surface Height at u-v-fpoints
+      DO jj = 1, jpjm1
+         DO ji = 1,jpim1
+            sshu(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )  &
+               &          * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshn(ji  ,jj)     &
+               &            + e1t(ji+1,jj) * e2t(ji+1,jj) * sshn(ji+1,jj) )
+            !
+            sshv(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )  &
+               &          * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshn(ji,jj  )     &
+               &            + e1t(ji,jj+1) * e2t(ji,jj+1) * sshn(ji,jj+1) )
+            !
+            zsshf(ji,jj) = 0.25 * fmask(ji,jj,1)                 &
+               &           * ( sshn(ji  ,jj) + sshn(ji  ,jj+1)   &
+               &             + sshn(ji+1,jj) + sshn(ji+1,jj+1) )
+         END DO
+      END DO
+
+      ! Boundaries conditions
+      CALL lbc_lnk( sshu,  'U', 1. )
+      CALL lbc_lnk( sshv,  'V', 1. )
+      CALL lbc_lnk( zsshf, 'F', 1. )
+
+      ! Scale factors at T levels
+      DO jk = 1, jpkm1
+         fse3t(:,:,jk) = fsve3t(:,:,jk) * ( 1 + sshn(:,:)  * mut(:,:,jk) )
+         fse3u(:,:,jk) = fsve3u(:,:,jk) * ( 1 + sshu(:,:)  * muu(:,:,jk) )
+         fse3v(:,:,jk) = fsve3v(:,:,jk) * ( 1 + sshv(:,:)  * muv(:,:,jk) )
+         fse3f(:,:,jk) = fsve3f(:,:,jk) * ( 1 + zsshf(:,:) * muf(:,:,jk) )
+      END DO
+
+      ! Scale factors at W levels
+      fse3w (:,:,1) = fse3t(:,:,1)
+      fse3uw(:,:,1) = fse3u(:,:,1)
+      fse3vw(:,:,1) = fse3v(:,:,1)
+      DO jk = 2, jpk
+         fse3w (:,:,jk) = 0.5 * ( fse3t(:,:,jk-1) + fse3t(:,:,jk) )
+         fse3uw(:,:,jk) = 0.5 * ( fse3u(:,:,jk-1) + fse3u(:,:,jk) )
+         fse3vw(:,:,jk) = 0.5 * ( fse3v(:,:,jk-1) + fse3v(:,:,jk) )
+      END DO
+
+      ! T and W points depth
+      fsdept(:,:,1) = 0.5 * fse3w(:,:,1)
+      fsdepw(:,:,1) = 0.e0
+      fsde3w(:,:,1) = fsdept(:,:,1) - sshn(:,:)
+      DO jk = 2, jpk
+         fsdept(:,:,jk) = fsdept(:,:,jk-1) + fse3w(:,:,jk)
+         fsdepw(:,:,jk) = fsdepw(:,:,jk-1) + fse3t(:,:,jk-1)
+         fsde3w(:,:,jk) = fsdept(:,:,jk  ) - sshn(:,:)
+      END DO
+
+      ! Local depth or Inverse of the local depth of the water column at u- and v-points
+      ! ------------------------------
+
+      ! Ocean depth at U- and V-points
+      hu(:,:) = 0.e0    ;    hv(:,:) = 0.e0
+
+      DO jk = 1, jpk
+         hu(:,:) = hu(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
+         hv(:,:) = hv(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
+      END DO
+
+
+      ! Inverse of the local depth
+      hur(:,:) = fse3u(:,:,1)             ! Lower bound : thickness of the first model level
+      hvr(:,:) = fse3v(:,:,1)
+      
+      DO jk = 2, jpk                      ! Sum of the vertical scale factors
+         hur(:,:) = hur(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
+         hvr(:,:) = hvr(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
+      END DO
+
+      ! Compute and mask the inverse of the local depth
+      hur(:,:) = 1. / hur(:,:) * umask(:,:,1)
+      hvr(:,:) = 1. / hvr(:,:) * vmask(:,:,1)
+
+   END SUBROUTINE dom_vvl
+
+
+
+   SUBROUTINE dom_vvl_ssh( kt ) 
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_ssh  ***
+      !!                   
+      !! ** Purpose :  compute the ssha field used in tra_zdf, dynnxt, tranxt 
+      !!               and dynspg routines
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in )  ::    kt                         ! time step
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk                                ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur                               ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zun, zvn, zhdiv       ! 2D workspace
+      !!----------------------------------------------------------------------
+
+      !! Sea surface height after (ssha) in variable volume case
+      !! --------------------------====-----===============-----
+      !! ssha is needed for the tracer time-stepping (trazdf_imp or
+      !! tra_nxt), for the ssh time-stepping (dynspg_*) and for the
+      !! dynamics time-stepping (dynspg_flt or dyn_nxt, and wzv).
+      !! un, vn (or un_b and vn_b) and emp are needed, so it must be
+      !! done after the call of oce_sbc.
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
+         r2dt(:) =  rdttra(:)                       ! = rdtra (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
+         r2dt(:) = 2. * rdttra(:)                   ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      z2dt  = r2dt(1)
+      zraur = 1. / rauw
+
+      ! Vertically integrated quantities
+      ! --------------------------------
+      IF( .NOT. lk_dynspg_ts .OR. (neuler == 0 .AND. kt == nit000) ) THEN
+         zun(:,:) = 0.e0    ;    zvn(:,:) = 0.e0
+         !
+         DO jk = 1, jpkm1
+            !                                               ! Vertically integrated transports (now)
+            zun(:,:) = zun(:,:) + fse3u(:,:,jk) * un(:,:,jk)
+            zvn(:,:) = zvn(:,:) + fse3v(:,:,jk) * vn(:,:,jk)
+         END DO
+      ELSE ! lk_dynspg_ts is true
+         zun (:,:) = un_b(:,:)    ;    zvn (:,:) = vn_b(:,:)
+      ENDIF
+
+      ! Horizontal divergence of barotropic transports
+      !--------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1   ! vector opt.
+            zhdiv(ji,jj) = (  e2u(ji  ,jj  ) * zun(ji  ,jj  )    &
+               &            - e2u(ji-1,jj  ) * zun(ji-1,jj  )    &
+               &            + e1v(ji  ,jj  ) * zvn(ji  ,jj  )    &
+               &            - e1v(ji  ,jj-1) * zvn(ji  ,jj-1) )  &
+               &           / ( e1t(ji,jj) * e2t(ji,jj) )
+         END DO
+      END DO
+
+#if defined key_obc && ( key_dynspg_exp || key_dynspg_ts )
+      ! open boundaries (div must be zero behind the open boundary)
+      !  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
+      IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1)   = 0.e0    ! east
+      IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1)   = 0.e0    ! west
+      IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0    ! north
+      IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1)   = 0.e0    ! south
+#endif
+
+      CALL lbc_lnk( zhdiv, 'T', 1. )
+
+      ! Sea surface elevation time stepping
+      ! -----------------------------------
+      IF( .NOT. lk_dynspg_ts .OR. (neuler == 0 .AND. kt == nit000) ) THEN
+         ssha(:,:) = sshb(:,:) - z2dt * ( zraur * emp(:,:) + zhdiv(:,:) ) * tmask(:,:,1)
+      ELSE ! lk_dynspg_ts is true
+         ssha(:,:) = (  sshb_b(:,:) - z2dt * ( zraur * emp(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
+      ENDIF
+
+
+   END SUBROUTINE dom_vvl_ssh
+
+   SUBROUTINE  dom_vvl_sf( zssh, gridp, sfe3 )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_sf  ***
+      !!                   
+      !! ** Purpose :  compute vertical scale factor at each time step
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=1)                , INTENT( in ) :: gridp   ! grid point type
+      REAL(wp), DIMENSION(jpi,jpj)    , INTENT( in ) :: zssh    ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out) :: sfe3    ! 3D workspace
+
+      !! * Local declarations
+      INTEGER  ::   jk                                      ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      SELECT CASE (gridp)
+
+      CASE ('U')
+         !
+         DO jk = 1, jpk
+            sfe3(:,:,jk)  = fsve3u(:,:,jk) * ( 1 + zssh(:,:) * muu(:,:,jk) )
+         ENDDO
+
+      CASE ('V')
+         !
+         DO jk = 1, jpk
+            sfe3(:,:,jk)  = fsve3v(:,:,jk) * ( 1 + zssh(:,:) * muv(:,:,jk) )
+         ENDDO
+
+      CASE ('T')
+         !
+         DO jk = 1, jpk
+            sfe3(:,:,jk)  = fsve3t(:,:,jk) * ( 1 + zssh(:,:) * mut(:,:,jk) )
+         ENDDO
+
+      END SELECT
+
+   END SUBROUTINE dom_vvl_sf
+
+   SUBROUTINE dom_vvl_sf_ini( gridp, sfe3ini )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_sf_ini  ***
+      !!                   
+      !! ** Purpose :  affect the appropriate vertical scale factor. It is done
+      !!               to avoid compiling error when using key_zco cpp key
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(LEN=1)                , INTENT( in ) :: gridp      ! grid point type
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT (out) :: sfe3ini    ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      SELECT CASE (gridp)
+
+      CASE ('U')
+         !
+         sfe3ini(:,:,:)  = fse3u(:,:,:)
+
+      CASE ('V')
+         !
+         sfe3ini(:,:,:)  = fse3v(:,:,:)
+
+      CASE ('T')
+         !
+         sfe3ini(:,:,:)  = fse3t(:,:,:)
+
+      END SELECT
+
+   END SUBROUTINE dom_vvl_sf_ini
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                      Empty routine
+   !!----------------------------------------------------------------------
+   SUBROUTINE dom_vvl_ini
+   END SUBROUTINE dom_vvl_ini
+   SUBROUTINE dom_vvl
+   END SUBROUTINE dom_vvl
+   SUBROUTINE dom_vvl_ssh( kt ) 
+      !! * Arguments
+      INTEGER, INTENT( in )  ::    kt        ! time step
+      WRITE(*,*) 'dom_vvl_ssh: You should not have seen this print! error?', kt
+   END SUBROUTINE dom_vvl_ssh
+   SUBROUTINE dom_vvl_sf( zssh, gridp, sfe3 ) 
+      !! * Arguments
+      CHARACTER(LEN=1)                , INTENT( in ) :: gridp   ! grid point type
+      REAL(wp), DIMENSION(jpi,jpj)    , INTENT( in ) :: zssh    ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT (out) :: sfe3    ! 3D workspace
+      sfe3(:,:,:) = 0.e0
+      WRITE(*,*) 'sfe3: You should not have seen this print! error?', gridp
+      WRITE(*,*) 'sfe3: You should not have seen this print! error?', zssh(1,1)
+   END SUBROUTINE dom_vvl_sf
+   SUBROUTINE dom_vvl_sf_ini( gridp, sfe3ini ) 
+      !! * Arguments
+      CHARACTER(LEN=1)                , INTENT( in ) :: gridp    ! grid point type
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT (out) :: sfe3ini  ! 3D workspace
+      sfe3ini(:,:,:) = 0.e0
+      WRITE(*,*) 'sfe3ini: You should not have seen this print! error?', gridp
+   END SUBROUTINE dom_vvl_sf_ini
+#endif
+
+   !!======================================================================
+END MODULE domvvl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 4536)
@@ -0,0 +1,212 @@
+MODULE domwri
+   !!======================================================================
+   !!                       ***  MODULE domwri  ***
+   !! Ocean initialization : write the ocean domain mesh ask file(s)
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dom_wri        : create and write mesh and mask file(s)
+   !!                    nmsh = 1  :   mesh_mask file
+   !!                         = 2  :   mesh and mask file
+   !!                         = 3  :   mesh_hgr, mesh_zgr and mask
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dom_wri        ! routine called by inidom.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_wri
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_wri  ***
+      !!                   
+      !! ** Purpose :   Create the NetCDF file(s) which contain(s) all the
+      !!      ocean domain informations (mesh and mask arrays). This (these)
+      !!      file(s) is (are) used for visualisation (SAXO software) and
+      !!      diagnostic computation.
+      !!
+      !! ** Method  :   Write in a file all the arrays generated in routines
+      !!      domhgr, domzgr, and dommsk. Note: the file contain depends on
+      !!      the vertical coord. used (z-coord, partial steps, s-coord)
+      !!                    nmsh = 1  :   'mesh_mask.nc' file
+      !!                         = 2  :   'mesh.nc' and mask.nc' files
+      !!                         = 3  :   'mesh_hgr.nc', 'mesh_zgr.nc' and
+      !!                                  'mask.nc' files
+      !!      For huge size domain, use option 2 or 3 depending on your 
+      !!      vertical coordinate.
+      !!
+      !! ** output file : 
+      !!      meshmask.nc  : domain size, horizontal grid-point position,
+      !!                     masks, depth and vertical scale factors
+      !!
+      !! History :
+      !!        !  97-02  (G. Madec)  Original code
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with IOIPSL
+      !!   9.0  !  02-08  (G. Madec)  F90 and several file
+      !!----------------------------------------------------------------------
+      INTEGER  ::   inum0   ! temprary units for 'mesh_mask.nc' file
+      INTEGER  ::   inum1   ! temprary units for 'mesh.nc'      file
+      INTEGER  ::   inum2   ! temprary units for 'mask.nc'      file
+      INTEGER  ::   inum3   ! temprary units for 'mesh_hgr.nc'  file
+      INTEGER  ::   inum4   ! temprary units for 'mesh_zgr.nc'  file
+      REAL(wp), DIMENSION(jpi,jpj) ::    zprt   ! temporary array for bathymetry 
+      CHARACTER (len=21) ::   clnam0   ! filename (mesh and mask informations)
+      CHARACTER (len=21) ::   clnam1   ! filename (mesh informations)
+      CHARACTER (len=21) ::   clnam2   ! filename (mask informations)
+      CHARACTER (len=21) ::   clnam3   ! filename (horizontal mesh informations)
+      CHARACTER (len=21) ::   clnam4   ! filename (vertical   mesh informations)
+      !!----------------------------------------------------------------------
+
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) 'dom_wri : create NetCDF mesh and mask information file(s)'
+       IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+       clnam0 = 'mesh_mask'  ! filename (mesh and mask informations)
+       clnam1 = 'mesh'       ! filename (mesh informations)
+       clnam2 = 'mask'       ! filename (mask informations)
+       clnam3 = 'mesh_hgr'   ! filename (horizontal mesh informations)
+       clnam4 = 'mesh_zgr'   ! filename (vertical   mesh informations)
+
+!       note that mbathy has been modified in dommsk or in solver.
+!       it is the number of non-zero "w" levels in the water, and the minimum 
+!       value (on land) is 2. We define zprt as the number of "T" points in the ocean 
+!       at any location, and zero on land. 
+!
+      zprt = tmask(:,:,1)*(mbathy-1)
+
+      SELECT CASE (nmsh)
+         !                                     ! ============================
+         CASE ( 1 )                            !  create 'mesh_mask.nc' file
+            !                                  ! ============================
+            CALL iom_open( TRIM(clnam0), inum0, ldwrt = .TRUE., kiolib = jprstlib )
+            inum2 = inum0                                            ! put all the informations
+            inum3 = inum0                                            ! in unit inum0
+            inum4 = inum0
+
+            !                                  ! ============================
+         CASE ( 2 )                            !  create 'mesh.nc' and 
+            !                                  !         'mask.nc' files
+            !                                  ! ============================
+            CALL iom_open( TRIM(clnam1), inum1, ldwrt = .TRUE., kiolib = jprstlib )
+            CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
+            inum3 = inum1                                            ! put mesh informations 
+            inum4 = inum1                                            ! in unit inum1 
+            !                                  ! ============================
+         CASE ( 3 )                            !  create 'mesh_hgr.nc'
+            !                                  !         'mesh_zgr.nc' and
+            !                                  !         'mask.nc'     files
+            !                                  ! ============================
+            CALL iom_open( TRIM(clnam2), inum2, ldwrt = .TRUE., kiolib = jprstlib )
+            CALL iom_open( TRIM(clnam3), inum3, ldwrt = .TRUE., kiolib = jprstlib )
+            CALL iom_open( TRIM(clnam4), inum4, ldwrt = .TRUE., kiolib = jprstlib )
+
+         END SELECT
+
+         !                                                         ! masks (inum2) 
+         CALL iom_rstput( 0, 0, inum2, 'tmask', tmask, ktype = jp_i1 ) 
+         CALL iom_rstput( 0, 0, inum2, 'umask', umask, ktype = jp_i1 )
+         CALL iom_rstput( 0, 0, inum2, 'vmask', vmask, ktype = jp_i1 )
+         CALL iom_rstput( 0, 0, inum2, 'fmask', fmask, ktype = jp_i1 )
+
+         !                                                         ! horizontal mesh (inum3)
+         CALL iom_rstput( 0, 0, inum3, 'glamt', glamt, ktype = jp_r4 )     !    ! latitude
+         CALL iom_rstput( 0, 0, inum3, 'glamu', glamu, ktype = jp_r4 )
+         CALL iom_rstput( 0, 0, inum3, 'glamv', glamv, ktype = jp_r4 )
+         CALL iom_rstput( 0, 0, inum3, 'glamf', glamf, ktype = jp_r4 )
+
+         CALL iom_rstput( 0, 0, inum3, 'gphit', gphit, ktype = jp_r4 )     !    ! longitude
+         CALL iom_rstput( 0, 0, inum3, 'gphiu', gphiu, ktype = jp_r4 )
+         CALL iom_rstput( 0, 0, inum3, 'gphiv', gphiv, ktype = jp_r4 )
+         CALL iom_rstput( 0, 0, inum3, 'gphif', gphif, ktype = jp_r4 )
+
+         CALL iom_rstput( 0, 0, inum3, 'e1t', e1t, ktype = jp_r8 )         !    ! e1 scale factors
+         CALL iom_rstput( 0, 0, inum3, 'e1u', e1u, ktype = jp_r8 )
+         CALL iom_rstput( 0, 0, inum3, 'e1v', e1v, ktype = jp_r8 )
+         CALL iom_rstput( 0, 0, inum3, 'e1f', e1f, ktype = jp_r8 )
+
+         CALL iom_rstput( 0, 0, inum3, 'e2t', e2t, ktype = jp_r8 )         !    ! e2 scale factors
+         CALL iom_rstput( 0, 0, inum3, 'e2u', e2u, ktype = jp_r8 )
+         CALL iom_rstput( 0, 0, inum3, 'e2v', e2v, ktype = jp_r8 )
+         CALL iom_rstput( 0, 0, inum3, 'e2f', e2f, ktype = jp_r8 )
+
+         CALL iom_rstput( 0, 0, inum3, 'ff', ff, ktype = jp_r8 )           !    ! coriolis factor
+
+         CALL iom_rstput( 0, 0, inum4, 'mbathy', zprt, ktype = jp_i2 )
+
+#if ! defined key_zco
+         IF( ln_sco ) THEN                                         ! s-coordinate
+            CALL iom_rstput( 0, 0, inum4, 'hbatt', hbatt )      !    ! depth
+            CALL iom_rstput( 0, 0, inum4, 'hbatu', hbatu ) 
+            CALL iom_rstput( 0, 0, inum4, 'hbatv', hbatv )
+            CALL iom_rstput( 0, 0, inum4, 'hbatf', hbatf )
+   
+            CALL iom_rstput( 0, 0, inum4, 'gsigt', gsigt )        !    ! scaling coef.
+            CALL iom_rstput( 0, 0, inum4, 'gsigw', gsigw )  
+            CALL iom_rstput( 0, 0, inum4, 'gsi3w', gsi3w )
+            CALL iom_rstput( 0, 0, inum4, 'esigt', esigt )
+            CALL iom_rstput( 0, 0, inum4, 'esigw', esigw )
+
+            CALL iom_rstput( 0, 0, inum4, 'e3t', e3t )       !    ! scale factors
+            CALL iom_rstput( 0, 0, inum4, 'e3u', e3u )
+            CALL iom_rstput( 0, 0, inum4, 'e3v', e3v )
+            CALL iom_rstput( 0, 0, inum4, 'e3w', e3w )
+
+            CALL iom_rstput( 0, 0, inum4, 'gdept_0' , gdept_0 )  !    ! stretched system
+            CALL iom_rstput( 0, 0, inum4, 'gdepw_0' , gdepw_0 )
+         ENDIF
+
+         IF( ln_zps ) THEN                                         ! z-coordinate - partial steps
+            CALL iom_rstput( 0, 0, inum4, 'hdept' , hdept  )    !    ! depth
+            CALL iom_rstput( 0, 0, inum4, 'hdepw' , hdepw  ) 
+
+            CALL iom_rstput( 0, 0, inum4, 'e3t' , e3t )      !    ! scale factors
+            CALL iom_rstput( 0, 0, inum4, 'e3u' , e3u )
+            CALL iom_rstput( 0, 0, inum4, 'e3v' , e3v )
+            CALL iom_rstput( 0, 0, inum4, 'e3w' , e3w )
+
+            CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )   !    ! reference z-coord.
+            CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
+            CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )
+            CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+         ENDIF
+
+#endif
+
+         IF( ln_zco ) THEN
+         !                                                         ! z-coordinate - full steps
+            CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )   !    ! depth
+            CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
+            CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )   !    ! scale factors
+            CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+         ENDIF
+         !                                     ! ============================
+         !                                     !        close the files 
+         !                                     ! ============================
+         SELECT CASE ( nmsh )
+            CASE ( 1 )                
+               CALL iom_close( inum0 )
+            CASE ( 2 )
+               CALL iom_close( inum1 )
+               CALL iom_close( inum2 )
+            CASE ( 3 )
+               CALL iom_close( inum2 )
+               CALL iom_close( inum3 )
+               CALL iom_close( inum4 )
+         END SELECT
+
+   END SUBROUTINE dom_wri
+
+   !!======================================================================
+END MODULE domwri
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4536)
@@ -0,0 +1,1146 @@
+MODULE domzgr
+   !!======================================================================
+   !!                       ***  MODULE domzgr   ***
+   !! Ocean initialization : domain initialization
+   !!======================================================================
+   !! History :  NEMO !  03-08  (G. Madec)  original code
+   !!            1.0  !  05-10  (A. Beckmann)  modifications for hybrid s-ccordinates
+   !!             -   !  06-04  (R. Benshila, G. Madec)  add zgr_zco routine
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_zgr     : defined the ocean vertical coordinate system
+   !!       zgr_bat      : bathymetry fields (levels and meters)
+   !!       zgr_bat_zoom : modify the bathymetry field if zoom domain
+   !!       zgr_bat_ctl  : check the bathymetry files
+   !!       zgr_z        : reference z-coordinate 
+   !!       zgr_zco      : z-coordinate 
+   !!       zgr_zps      : z-coordinate with partial steps
+   !!       zgr_sco      : s-coordinate
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE closea
+   USE solisl
+   USE ini1d           ! initialization of the 1D configuration
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dom_zgr        ! called by dom_init.F90
+
+   !                                 !!! * Namelist nam_zgr_sco *
+   REAL(wp) ::   sbot_min =  300.     !: minimum depth of s-bottom surface (>0) (m)
+   REAL(wp) ::   sbot_max = 5250.     !: maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+   REAL(wp) ::   theta    =    6.0    !: surface control parameter (0<=theta<=20)
+   REAL(wp) ::   thetb    =    0.75   !: bottom control parameter  (0<=thetb<= 1)
+   REAL(wp) ::   r_max    =    0.15   !: maximum cut-off r-value allowed (0<r_max<1)
+ 
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS       
+
+   SUBROUTINE dom_zgr
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_zgr  ***
+      !!                   
+      !! ** Purpose :  set the depth of model levels and the resulting 
+      !!      vertical scale factors.
+      !!
+      !! ** Method  reference vertical coordinate
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio = 0      ! temporary integer
+
+      NAMELIST/nam_zgr/ ln_zco, ln_zps, ln_sco
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )                ! Read Namelist nam_zgr : vertical coordinate'
+      READ   ( numnam, nam_zgr )
+
+      IF(lwp) THEN                     ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_zgr : vertical coordinate'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_zgr : set vertical coordinate'
+         WRITE(numout,*) '             z-coordinate - full steps      ln_zco = ', ln_zco
+         WRITE(numout,*) '             z-coordinate - partial steps   ln_zps = ', ln_zps
+         WRITE(numout,*) '             s- or hybrid z-s-coordinate    ln_sco = ', ln_sco
+      ENDIF
+
+      !                                ! Check Vertical coordinate options
+      ioptio = 0
+      IF( ln_zco ) ioptio = ioptio + 1
+      IF( ln_zps ) ioptio = ioptio + 1
+      IF( ln_sco ) ioptio = ioptio + 1
+      IF ( ioptio /= 1 ) CALL ctl_stop( ' none or several vertical coordinate options used' )
+
+      IF( lk_zco ) THEN
+          IF(lwp) WRITE(numout,*) '          z-coordinate with reduced incore memory requirement'
+          IF( ln_zps .OR. ln_sco ) CALL ctl_stop( ' reduced memory with zps or sco option is impossible' )
+      ENDIF
+
+      ! Build the vertical coordinate system
+      ! ------------------------------------
+
+                     CALL zgr_z        ! Reference z-coordinate system (always called)
+
+                     CALL zgr_bat      ! Bathymetry fields (levels and meters)
+
+      IF( ln_zco )   CALL zgr_zco      ! z-coordinate
+
+      IF( ln_zps )   CALL zgr_zps      ! Partial step z-coordinate
+
+      IF( ln_sco )   CALL zgr_sco      ! s-coordinate or hybrid z-s coordinate
+
+!!bug gm control print:
+      IF( nprint == 1 .AND. lwp )   THEN
+         WRITE(numout,*) ' MIN val mbathy ', MINVAL( mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
+         WRITE(numout,*) ' MIN val depth t ', MINVAL( fsdept(:,:,:) ),   &
+            &                   ' w ',   MINVAL( fsdepw(:,:,:) ), '3w ', MINVAL( fsde3w(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL( fse3t(:,:,:) ), ' f ', MINVAL( fse3f(:,:,:) ),  &
+            &                   ' u ',   MINVAL( fse3u(:,:,:) ), ' u ', MINVAL( fse3v(:,:,:) ),  &
+            &                   ' uw',   MINVAL( fse3uw(:,:,:)), ' vw', MINVAL( fse3vw(:,:,:)),   &
+            &                   ' w ',   MINVAL( fse3w(:,:,:) )
+
+         WRITE(numout,*) ' MAX val depth t ', MAXVAL( fsdept(:,:,:) ),   &
+            &                   ' w ',   MAXVAL( fsdepw(:,:,:) ), '3w ', MAXVAL( fsde3w(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( fse3t(:,:,:) ), ' f ', MAXVAL( fse3f(:,:,:) ),  &
+            &                   ' u ',   MAXVAL( fse3u(:,:,:) ), ' u ', MAXVAL( fse3v(:,:,:) ),  &
+            &                   ' uw',   MAXVAL( fse3uw(:,:,:)), ' vw', MAXVAL( fse3vw(:,:,:)),   &
+            &                   ' w ',   MAXVAL( fse3w(:,:,:) )
+      ENDIF
+!!!bug gm
+      !
+   END SUBROUTINE dom_zgr
+
+
+   SUBROUTINE zgr_z
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zgr_z  ***
+      !!                   
+      !! ** Purpose :   set the depth of model levels and the resulting 
+      !!      vertical scale factors.
+      !!
+      !! ** Method  :   z-coordinate system (use in all type of coordinate)
+      !!        The depth of model levels is defined from an analytical
+      !!      function the derivative of which gives the scale factors.
+      !!        both depth and scale factors only depend on k (1d arrays).
+      !!              w-level: gdepw_0  = fsdep(k)
+      !!                       e3w_0(k) = dk(fsdep)(k)     = fse3(k)
+      !!              t-level: gdept_0  = fsdep(k+0.5)
+      !!                       e3t_0(k) = dk(fsdep)(k+0.5) = fse3(k+0.5)
+      !!
+      !! ** Action  : - gdept_0, gdepw_0 : depth of T- and W-point (m)
+      !!              -  e3t_0, e3w_0    : scale factors at T- and W-levels (m)
+      !!
+      !! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jk                          ! dummy loop indices
+      REAL(wp) ::   zt, zw                      ! temporary scalars
+      REAL(wp) ::   zsur , za0, za1             ! value set from parameters 
+      REAL(wp) ::   zkth, zacr, zdzmin, zhmax   !    "             "
+      !!----------------------------------------------------------------------
+
+      ! Set variables from parameters
+      ! ------------------------------
+       zkth = ppkth       ;   zacr = ppacr
+       zdzmin = ppdzmin   ;   zhmax = pphmax
+
+      ! If ppa1 and ppa0 and ppsur are et to pp_to_be_computed
+      !  za0, za1, zsur are computed from ppdzmin , pphmax, ppkth, ppacr
+      !
+      IF(   ppa1  == pp_to_be_computed  .AND.  &
+         &  ppa0  == pp_to_be_computed  .AND.  &
+         &  ppsur == pp_to_be_computed           ) THEN
+         za1 = ( ppdzmin - pphmax / FLOAT(jpk-1) )          &
+             / ( TANH((1-ppkth)/ppacr) - ppacr/FLOAT(jpk-1) &
+             &                         *  (  LOG( COSH( (jpk - ppkth) / ppacr) )      &
+             &                             - LOG( COSH( ( 1  - ppkth) / ppacr) )  )  )
+         za0  = ppdzmin - za1 * TANH( (1-ppkth) / ppacr )
+         zsur = - za0 - za1 * ppacr * LOG( COSH( (1-ppkth) / ppacr )  )
+      ELSE
+         za1 = ppa1   ;   za0 = ppa0   ;   zsur = ppsur
+      ENDIF
+
+      IF(lwp) THEN                    ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) '    zgr_z   : Reference vertical z-coordinates'
+         WRITE(numout,*) '    ~~~~~~~'
+         IF(  ppkth == 0. ) THEN              
+              WRITE(numout,*) '            Uniform grid with ',jpk-1,' layers'
+              WRITE(numout,*) '            Total depth    :', zhmax
+              WRITE(numout,*) '            Layer thickness:', zhmax/(jpk-1)
+         ELSE
+            IF( ppa1 == 0. .AND. ppa0 == 0. .AND. ppsur == 0. ) THEN
+               WRITE(numout,*) '         zsur, za0, za1 computed from '
+               WRITE(numout,*) '                 zdzmin = ', zdzmin
+               WRITE(numout,*) '                 zhmax  = ', zhmax
+            ENDIF
+            WRITE(numout,*) '           Value of coefficients for vertical mesh:'
+            WRITE(numout,*) '                 zsur = ', zsur
+            WRITE(numout,*) '                 za0  = ', za0
+            WRITE(numout,*) '                 za1  = ', za1
+            WRITE(numout,*) '                 zkth = ', zkth
+            WRITE(numout,*) '                 zacr = ', zacr
+         ENDIF
+      ENDIF
+
+
+      ! Reference z-coordinate (depth - scale factor at T- and W-points)
+      ! ======================
+      IF( ppkth == 0.e0 ) THEN            ! uniform vertical grid       
+         za1 = zhmax / FLOAT(jpk-1) 
+         DO jk = 1, jpk
+            zw = FLOAT( jk )
+            zt = FLOAT( jk ) + 0.5
+            gdepw_0(jk) = ( zw - 1 ) * za1
+            gdept_0(jk) = ( zt - 1 ) * za1
+            e3w_0  (jk) =  za1
+            e3t_0  (jk) =  za1
+         END DO
+      ELSE                                ! stretched vertical grid
+         DO jk = 1, jpk
+            zw = FLOAT( jk )
+            zt = FLOAT( jk ) + 0.5
+            gdepw_0(jk) = ( zsur + za0 * zw + za1 * zacr * LOG( COSH( (zw-zkth)/zacr ) )  )
+            gdept_0(jk) = ( zsur + za0 * zt + za1 * zacr * LOG( COSH( (zt-zkth)/zacr ) )  )
+            e3w_0  (jk) =          za0      + za1        * TANH(      (zw-zkth)/zacr   )
+            e3t_0  (jk) =          za0      + za1        * TANH(      (zt-zkth)/zacr   )
+         END DO
+         gdepw_0(1) = 0.e0                   ! force first w-level to be exactly at zero
+      ENDIF
+
+      IF(lwp) THEN                        ! Control and  print
+         WRITE(numout,*)
+         WRITE(numout,*) '              Reference z-coordinate depth and scale factors:'
+         WRITE(numout, "(9x,' level   gdept    gdepw     e3t      e3w  ')" )
+         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_0(jk), gdepw_0(jk), e3t_0(jk), e3w_0(jk), jk = 1, jpk )
+      ENDIF
+      !
+      DO jk = 1, jpk
+         IF( e3w_0(jk)  <= 0. .OR. e3t_0(jk)  <= 0. ) CALL ctl_stop( ' e3w or e3t =< 0 ' )
+         IF( gdepw_0(jk) < 0. .OR. gdept_0(jk) < 0. ) CALL ctl_stop( ' gdepw or gdept < 0 ' )
+      END DO
+      !
+   END SUBROUTINE zgr_z
+
+
+   SUBROUTINE zgr_bat
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_bat  ***
+      !! 
+      !! ** Purpose :   set bathymetry both in levels and meters
+      !!
+      !! ** Method  :   read or define mbathy and bathy arrays
+      !!       * level bathymetry:
+      !!      The ocean basin geometry is given by a two-dimensional array,
+      !!      mbathy, which is defined as follow :
+      !!            mbathy(ji,jj) = 1, ..., jpk-1, the number of ocean level
+      !!                              at t-point (ji,jj).
+      !!                            = 0  over the continental t-point.
+      !!                            = -n over the nth island t-point.
+      !!      The array mbathy is checked to verified its consistency with
+      !!      model option. in particular:
+      !!            mbathy must have at least 1 land grid-points (mbathy<=0)
+      !!                  along closed boundary.
+      !!            mbathy must be cyclic IF jperio=1.
+      !!            mbathy must be lower or equal to jpk-1.
+      !!            isolated ocean grid points are suppressed from mbathy
+      !!                  since they are only connected to remaining
+      !!                  ocean through vertical diffusion.
+      !!      ntopo=-1 :   rectangular channel or bassin with a bump 
+      !!      ntopo= 0 :   flat rectangular channel or basin 
+      !!      ntopo= 1 :   mbathy is read in 'bathy_level.nc' NetCDF file
+      !!                   bathy  is read in 'bathy_meter.nc' NetCDF file
+      !!      C A U T I O N : mbathy will be modified during the initializa-
+      !!      tion phase to become the number of non-zero w-levels of a water
+      !!      column, with a minimum value of 1.
+      !!
+      !! ** Action  : - mbathy: level bathymetry (in level index)
+      !!              - bathy : meter bathymetry (in meters)
+      !!----------------------------------------------------------------------
+      USE iom
+
+      INTEGER  ::   ji, jj, jl, jk          ! dummy loop indices
+      INTEGER  ::   inum                    ! temporary logical unit
+      INTEGER  ::   ii_bump, ij_bump, ih    ! bump center position
+      REAL(wp) ::   r_bump, h_bump, h_oce   ! bump characteristics 
+      REAL(wp) ::   zi, zj, zh                     ! temporary scalars
+      INTEGER , DIMENSION(jpidta,jpjdta) ::   idta   ! global domain integer data
+      REAL(wp), DIMENSION(jpidta,jpjdta) ::   zdta   ! global domain scalar data
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '    zgr_bat : defines level and meter bathymetry'
+      IF(lwp) WRITE(numout,*) '    ~~~~~~~'
+
+      ! ========================================
+      ! global domain level and meter bathymetry (idta,zdta)
+      ! ========================================
+      !                                               ! =============== ! 
+      IF( ntopo == 0 .OR. ntopo == -1 ) THEN          ! defined by hand !
+         !                                            ! =============== !
+
+         IF( ntopo == 0 ) THEN                        ! flat basin
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '         bathymetry field: flat basin'
+            idta(:,:) = jpkm1                            ! flat basin 
+            zdta(:,:) = gdepw_0(jpk)
+            h_oce     = gdepw_0(jpk)
+            !
+         ELSE                                         ! bump
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '         bathymetry field: flat basin with a bump'
+            ii_bump = jpidta / 2           ! i-index of the bump center
+            ij_bump = jpjdta / 2           ! j-index of the bump center
+            r_bump  = 50000.e0             ! bump radius (meters)       
+            h_bump  = 2700.e0              ! bump height (meters)
+            h_oce   = gdepw_0(jpk)         ! background ocean depth (meters)
+            IF(lwp) WRITE(numout,*) '            bump characteristics: '
+            IF(lwp) WRITE(numout,*) '               bump center (i,j)   = ', ii_bump, ii_bump
+            IF(lwp) WRITE(numout,*) '               bump height         = ', h_bump , ' meters'
+            IF(lwp) WRITE(numout,*) '               bump radius         = ', r_bump , ' index'
+            IF(lwp) WRITE(numout,*) '            background ocean depth = ', h_oce  , ' meters'
+            ! zdta :
+            DO jj = 1, jpjdta
+               DO ji = 1, jpidta
+                  zi = FLOAT( ji - ii_bump ) * ppe1_m / r_bump
+                  zj = FLOAT( jj - ij_bump ) * ppe2_m / r_bump
+                  zdta(ji,jj) = h_oce - h_bump * EXP( -( zi*zi + zj*zj ) )
+               END DO
+            END DO
+            ! idta :
+            IF( ln_sco ) THEN      ! s-coordinate (zsc       ): idta()=jpk
+               idta(:,:) = jpkm1
+            ELSE                   ! z-coordinate (zco or zps): step-like topography
+               idta(:,:) = jpkm1
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpjdta
+                     DO ji = 1, jpidta
+                        IF( gdept_0(jk) < zdta(ji,jj) .AND. zdta(ji,jj) <= gdept_0(jk+1) )   idta(ji,jj) = jk
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+
+         ! set boundary conditions (caution, idta on the global domain: use of jperio, not nperio)
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+            idta( :    , 1    ) = -1                ;      zdta( :    , 1    ) = -1.e0
+            idta( :    ,jpjdta) =  0                ;      zdta( :    ,jpjdta) =  0.e0
+         ELSEIF( jperio == 2 ) THEN
+            idta( :    , 1    ) = idta( : ,  3  )   ;      zdta( :    , 1    ) = zdta( : ,  3  )
+            idta( :    ,jpjdta) = 0                 ;      zdta( :    ,jpjdta) =  0.e0
+            idta( 1    , :    ) = 0                 ;      zdta( 1    , :    ) =  0.e0
+            idta(jpidta, :    ) = 0                 ;      zdta(jpidta, :    ) =  0.e0
+         ELSE
+            ih = 0                                  ;      zh = 0.e0
+            IF( ln_sco )   ih = jpkm1               ;      IF( ln_sco )   zh = h_oce
+            idta( :    , 1    ) = ih                ;      zdta( :    , 1    ) =  zh
+            idta( :    ,jpjdta) = ih                ;      zdta( :    ,jpjdta) =  zh
+            idta( 1    , :    ) = ih                ;      zdta( 1    , :    ) =  zh
+            idta(jpidta, :    ) = ih                ;      zdta(jpidta, :    ) =  zh
+         ENDIF
+
+         ! =======================================
+         ! local domain level and meter bathymetry (mbathy,bathy)
+         ! =======================================
+         
+         mbathy(:,:) = 0                                 ! set to zero extra halo points
+         bathy (:,:) = 0.e0                              ! (require for mpp case)
+         
+         DO jj = 1, nlcj                                 ! interior values
+            DO ji = 1, nlci
+               mbathy(ji,jj) = idta( mig(ji), mjg(jj) )
+               bathy (ji,jj) = zdta( mig(ji), mjg(jj) )
+            END DO
+         END DO
+
+         !                                            ! =============== !
+      ELSEIF( ntopo == 1 ) THEN                       !   read in file  !
+         !                                            ! =============== !
+
+         IF( ln_zco )   THEN
+            CALL iom_open ( 'bathy_level.nc', inum )   ! Level bathymetry
+            CALL iom_get ( inum, jpdom_data, 'Bathy_level', bathy )
+            CALL iom_close (inum)
+            mbathy(:,:) = INT( bathy(:,:) )
+         ENDIF
+
+         IF( ln_zps .OR. ln_sco )   THEN
+            CALL iom_open ( 'bathy_meter.nc', inum )   ! meter bathymetry
+            CALL iom_get ( inum, jpdom_data, 'Bathymetry', bathy )
+            CALL iom_close (inum)
+         ENDIF
+         !                                            ! =============== !
+      ELSE                                            !      error      !
+         !                                            ! =============== !
+         WRITE(ctmp1,*) '          parameter , ntopo = ', ntopo
+         CALL ctl_stop( '    zgr_bat : '//trim(ctmp1) )
+      ENDIF
+
+      ! =======================
+      ! NO closed seas or lakes
+      ! =======================
+
+      IF( nclosea == 0 ) THEN
+         DO jl = 1, jpncs
+            DO jj = ncsj1(jl), ncsj2(jl)
+               DO ji = ncsi1(jl), ncsi2(jl)
+                  mbathy(ji,jj) = 0                   ! suppress closed seas
+                  bathy (ji,jj) = 0.e0                ! and lakes
+!!bug gm          bathy (ji,jj) = 300.e0                ! and lakes
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+#if defined key_orca_lev10
+      ! 10 time the vertical resolution
+      mbathy(:,:) = 10 * mbathy(:,:)
+      IF(lwp) WRITE(numout,*) ' ATTENTION: 300 niveaux avec bathy levels "vraie?"'
+#endif
+      ! ===========
+      ! Zoom domain 
+      ! ===========
+
+      IF( lzoom )   CALL zgr_bat_zoom
+
+      ! ================
+      ! Bathymetry check
+      ! ================
+
+      CALL zgr_bat_ctl
+
+   END SUBROUTINE zgr_bat
+
+
+   SUBROUTINE zgr_bat_zoom
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_bat_zoom  ***
+      !!
+      !! ** Purpose : - Close zoom domain boundary if necessary
+      !!              - Suppress Med Sea from ORCA R2 and R05 arctic zoom
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : - update mbathy: level bathymetry (in level index)
+      !!----------------------------------------------------------------------
+      INTEGER ::   ii0, ii1, ij0, ij1   ! temporary integers
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '    zgr_bat_zoom : modify the level bathymetry for zoom domain'
+      IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~~'
+
+      ! Zoom domain
+      ! ===========
+
+      ! Forced closed boundary if required
+      IF( lzoom_w )   mbathy( mi0(jpizoom):mi1(jpizoom) , :  ) = 0
+      IF( lzoom_s )   mbathy(  : , mj0(jpjzoom):mj1(jpjzoom) ) = 0
+      IF( lzoom_e )   mbathy( mi0(jpiglo+jpizoom-1):mi1(jpiglo+jpizoom-1) , :  ) = 0
+      IF( lzoom_n )   mbathy(  : , mj0(jpjglo+jpjzoom-1):mj1(jpjglo+jpjzoom-1) ) = 0
+
+      ! Configuration specific domain modifications
+      ! (here, ORCA arctic configuration: suppress Med Sea)
+      IF( cp_cfg == "orca" .AND. lzoom_arct ) THEN
+         SELECT CASE ( jp_cfg )
+         !                                        ! =======================
+         CASE ( 2 )                               !  ORCA_R2 configuration
+            !                                     ! =======================
+            IF(lwp) WRITE(numout,*) '                   ORCA R2 arctic zoom: suppress the Med Sea'
+
+            ii0 = 141   ;   ii1 = 162      ! Sea box i,j indices
+            ij0 =  98   ;   ij1 = 110
+            !                                     ! =======================
+         CASE ( 05 )                              !  ORCA_R05 configuration
+            !                                     ! =======================
+            IF(lwp) WRITE(numout,*) '                   ORCA R05 arctic zoom: suppress the Med Sea'
+  
+            ii0 = 563   ;   ii1 = 642      ! zero over the Med Sea boxe
+            ij0 = 314   ;   ij1 = 370 
+
+         END SELECT
+         !
+         mbathy( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0   ! zero over the Med Sea boxe
+         !
+      ENDIF
+      !
+   END SUBROUTINE zgr_bat_zoom
+
+
+   SUBROUTINE zgr_bat_ctl
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_bat_ctl  ***
+      !!
+      !! ** Purpose :   check the bathymetry in levels
+      !!
+      !! ** Method  :   The array mbathy is checked to verified its consistency
+      !!      with the model options. in particular:
+      !!            mbathy must have at least 1 land grid-points (mbathy<=0)
+      !!                  along closed boundary.
+      !!            mbathy must be cyclic IF jperio=1.
+      !!            mbathy must be lower or equal to jpk-1.
+      !!            isolated ocean grid points are suppressed from mbathy
+      !!                  since they are only connected to remaining
+      !!                  ocean through vertical diffusion.
+      !!      C A U T I O N : mbathy will be modified during the initializa-
+      !!      tion phase to become the number of non-zero w-levels of a water
+      !!      column, with a minimum value of 1.
+      !!
+      !! ** Action  : - update mbathy: level bathymetry (in level index)
+      !!              - update bathy : meter bathymetry (in meters)
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jl                    ! dummy loop indices
+      INTEGER ::   icompt, ibtest, ikmax         ! temporary integers
+      REAL(wp), DIMENSION(jpi,jpj) ::   zbathy   ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '    zgr_bat_ctl : check the bathymetry'
+      IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~'
+
+      ! ================
+      ! Bathymetry check
+      ! ================
+
+      IF( .NOT. lk_cfg_1d )   THEN
+
+         ! Suppress isolated ocean grid points
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'                   suppress isolated ocean grid points'
+         IF(lwp) WRITE(numout,*)'                   -----------------------------------'
+
+         icompt = 0
+
+         DO jl = 1, 2
+            IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN
+               mbathy( 1 ,:) = mbathy(jpim1,:)
+               mbathy(jpi,:) = mbathy(  2  ,:)
+            ENDIF
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ibtest = MAX( mbathy(ji-1,jj), mbathy(ji+1,jj),   &
+                     &          mbathy(ji,jj-1),mbathy(ji,jj+1) )
+                  IF( ibtest < mbathy(ji,jj) ) THEN
+                     IF(lwp) WRITE(numout,*) ' the number of ocean level at ',   &
+                        &   'grid-point (i,j) =  ',ji,jj,' is changed from ', mbathy(ji,jj),' to ', ibtest
+                     mbathy(ji,jj) = ibtest
+                     icompt = icompt + 1
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         !
+         IF( icompt == 0 ) THEN   ;   IF(lwp) WRITE(numout,*)'     no isolated ocean grid points'
+         ELSE                     ;   IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points suppressed'
+         ENDIF
+         !
+         IF( lk_mpp ) THEN
+            zbathy(:,:) = FLOAT( mbathy(:,:) )
+            CALL lbc_lnk( zbathy, 'T', 1. )
+            mbathy(:,:) = INT( zbathy(:,:) )
+         ENDIF
+
+         ! East-west cyclic boundary conditions
+
+         IF( nperio == 0 ) THEN
+            IF(lwp) WRITE(numout,*) ' mbathy set to 0 along east and west',   &
+               ' boundary: nperio = ', nperio
+            IF( lk_mpp ) THEN
+               IF( nbondi == -1 .OR. nbondi == 2 ) THEN
+                  IF( jperio /= 1 )   mbathy(1,:) = 0
+               ENDIF
+               IF( nbondi == 1 .OR. nbondi == 2 ) THEN
+                  IF( jperio /= 1 )   mbathy(nlci,:) = 0
+               ENDIF
+            ELSE
+               IF( ln_zco .OR. ln_zps ) THEN
+                  mbathy( 1 ,:) = 0
+                  mbathy(jpi,:) = 0
+               ELSE
+                  mbathy( 1 ,:) = jpkm1
+                  mbathy(jpi,:) = jpkm1
+               ENDIF
+            ENDIF
+         ELSEIF( nperio == 1 .OR. nperio == 4 .OR. nperio ==  6 ) THEN
+            IF(lwp) WRITE(numout,*)' east-west cyclic boundary conditions',   &
+               ' on mbathy: nperio = ', nperio
+            mbathy( 1 ,:) = mbathy(jpim1,:)
+            mbathy(jpi,:) = mbathy(  2  ,:)
+         ELSEIF( nperio == 2 ) THEN
+            IF(lwp) WRITE(numout,*) '   equatorial boundary conditions',   &
+               ' on mbathy: nperio = ', nperio
+         ELSE
+            IF(lwp) WRITE(numout,*) '    e r r o r'
+            IF(lwp) WRITE(numout,*) '    parameter , nperio = ', nperio
+            !         STOP 'dom_mba'
+         ENDIF
+
+         ! Set to zero mbathy over islands if necessary  (lk_isl=F)
+         IF( .NOT. lk_isl ) THEN    ! No island
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '         mbathy set to 0 over islands'
+            IF(lwp) WRITE(numout,*) '         ----------------------------'
+
+            mbathy(:,:) = MAX( 0, mbathy(:,:) )
+
+            !  Boundary condition on mbathy
+            IF( .NOT.lk_mpp ) THEN 
+               !!bug ???  y reflechir!
+               !   ... mono- or macro-tasking: T-point, >0, 2D array, no slab
+               zbathy(:,:) = FLOAT( mbathy(:,:) )
+               CALL lbc_lnk( zbathy, 'T', 1. )
+               mbathy(:,:) = INT( zbathy(:,:) )
+            ENDIF
+            !
+         ENDIF
+         !
+      ENDIF
+
+      ! Number of ocean level inferior or equal to jpkm1
+
+      ikmax = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikmax = MAX( ikmax, mbathy(ji,jj) )
+         END DO
+      END DO
+!!gm      !!! test a faire:   ikmax = MAX( mbathy(:,:) )   ???
+
+      IF( ikmax > jpkm1 ) THEN
+         IF(lwp) WRITE(numout,*) ' maximum number of ocean level = ', ikmax,' >  jpk-1'
+         IF(lwp) WRITE(numout,*) ' change jpk to ',ikmax+1,' to use the exact ead bathymetry'
+      ELSE IF( ikmax < jpkm1 ) THEN
+         IF(lwp) WRITE(numout,*) ' maximum number of ocean level = ', ikmax,' < jpk-1' 
+         IF(lwp) WRITE(numout,*) ' you can decrease jpk to ', ikmax+1
+      ENDIF
+
+      IF( lwp .AND. nprint == 1 ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' bathymetric field '
+         WRITE(numout,*) ' ------------------'
+         WRITE(numout,*) ' number of non-zero T-levels '
+         CALL prihin( mbathy, jpi, jpj, 1, jpi,   &
+                      1     , 1  , jpj, 1, 3  ,   &
+                      numout )
+         WRITE(numout,*)
+      ENDIF
+      !
+   END SUBROUTINE zgr_bat_ctl
+
+
+   SUBROUTINE zgr_zco
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zgr_zco  ***
+      !!
+      !! ** Purpose :   define the z-coordinate system
+      !!
+      !! ** Method  :   set 3D coord. arrays to reference 1D array if lk_zco=T
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jk
+      !!----------------------------------------------------------------------
+      !
+      IF( .NOT.lk_zco ) THEN
+         DO jk = 1, jpk
+            fsdept(:,:,jk) = gdept_0(jk)
+            fsdepw(:,:,jk) = gdepw_0(jk)
+            fsde3w(:,:,jk) = gdepw_0(jk)
+            fse3t (:,:,jk) = e3t_0(jk)
+            fse3u (:,:,jk) = e3t_0(jk)
+            fse3v (:,:,jk) = e3t_0(jk)
+            fse3f (:,:,jk) = e3t_0(jk)
+            fse3w (:,:,jk) = e3w_0(jk)
+            fse3uw(:,:,jk) = e3w_0(jk)
+            fse3vw(:,:,jk) = e3w_0(jk)
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE zgr_zco
+
+
+#  include "domzgr_zps.h90"
+
+
+#if ! defined key_zco
+   !!----------------------------------------------------------------------
+   !!   NOT 'key_zco' :                                    3D gdep. and e3.
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zgr_sco
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zgr_sco  ***
+      !!                     
+      !! ** Purpose :   define the s-coordinate system
+      !!
+      !! ** Method  :   s-coordinate
+      !!         The depth of model levels is defined as the product of an
+      !!      analytical function by the local bathymetry, while the vertical
+      !!      scale factors are defined as the product of the first derivative
+      !!      of the analytical function by the bathymetry.
+      !!      (this solution save memory as depth and scale factors are not
+      !!      3d fields)
+      !!          - Read bathymetry (in meters) at t-point and compute the
+      !!         bathymetry at u-, v-, and f-points.
+      !!            hbatu = mi( hbatt )
+      !!            hbatv = mj( hbatt )
+      !!            hbatf = mi( mj( hbatt ) )
+      !!          - Compute gsigt, gsigw, esigt, esigw from an analytical
+      !!         function and its derivative given as statement function.
+      !!            gsigt(k) = fssig (k+0.5)
+      !!            gsigw(k) = fssig (k    )
+      !!            esigt(k) = fsdsig(k+0.5)
+      !!            esigw(k) = fsdsig(k    )
+      !!      This routine is given as an example, it must be modified
+      !!      following the user s desiderata. nevertheless, the output as
+      !!      well as the way to compute the model levels and scale factors
+      !!      must be respected in order to insure second order a!!uracy
+      !!      schemes.
+      !!
+      !! Reference : Madec, Lott, Delecluse and Crepon, 1996. JPO, 26, 1393-1408.
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl
+      REAL(wp) ::   fssigt, fssigw, pfkk
+
+      INTEGER  ::   iip1, ijp1, iim1, ijm1
+!     REAL(wp) ::   zcoeft, zcoefw
+      REAL(wp) ::   zrmax, ztaper
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   zenv, ztmp, zmsk, zri, zrj, zhbat
+
+      NAMELIST/nam_zgr_sco/ sbot_max, sbot_min, theta, thetb, r_max
+      !!----------------------------------------------------------------------
+
+      ! a. Sigma stretching coefficient
+       fssigt(pfkk) = (tanh(theta*(-(pfkk-0.5)/FLOAT(jpkm1)+thetb))-tanh(thetb*theta)) &
+                    * (cosh(theta)+cosh(theta*(2.*thetb-1.)))/(2.*sinh(theta))
+       fssigw(pfkk) = (tanh(theta*(-(pfkk-1.0)/FLOAT(jpkm1)+thetb))-tanh(thetb*theta)) &
+                    * (cosh(theta)+cosh(theta*(2.*thetb-1.)))/(2.*sinh(theta))
+
+      ! b. Vertical derivative of sigma stretching coefficient
+ 
+!!bug fsdsig(pfkk)= put here the analytical derivative of fssigt and w ...
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nam_zgr_sco : sigma-stretching parameters
+      ! -------------------------
+      REWIND( numnam )
+      READ  ( numnam, nam_zgr_sco )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom:zgr_sco : s-coordinate or hybrid z-s-coordinate'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '         Namelist nam_zgr_sco'
+         WRITE(numout,*) '            sigma-stretching coeffs '
+         WRITE(numout,*) '            maximum depth of s-bottom surface (>0)    sbot_max = ' ,sbot_max
+         WRITE(numout,*) '            minimum depth of s-bottom surface (>0)    sbot_min = ' ,sbot_min
+         WRITE(numout,*) '            surface control parameter (0<=theta<=20)  theta    = ', theta
+         WRITE(numout,*) '            bottom control parameter  (0<=thetb<= 1)  thetb    = ', thetb
+         WRITE(numout,*) '            maximum cut-off r-value allowed           r_max    = ' , r_max
+      ENDIF
+
+      ! ???
+      ! ------------------
+      hift(:,:) = sbot_min
+      hifu(:,:) = sbot_min
+      hifv(:,:) = sbot_min
+      hiff(:,:) = sbot_min
+
+
+      ! set maximum ocean depth 
+      ! -----------------------
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+             bathy(ji,jj) = MIN( sbot_max, bathy(ji,jj) )
+          END DO
+       END DO
+
+      ! Define the envelop bathymetry
+      ! =============================
+      ! Smooth the bathymetry (if required) 
+
+      scosrf(:,:) = 0.e0              ! ocean surface depth (here zero: no under ice-shelf sea)
+      scobot(:,:) = bathy(:,:)        ! ocean bottom  depth 
+
+ 
+      ! use r-value to create hybrid coordinates
+ 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zenv(ji,jj) = MAX( bathy(ji,jj), sbot_min )
+         END DO
+      END DO
+
+      jl = 0
+      zrmax = 1.e0
+      !                                                     ! ================ !
+      DO WHILE ( jl <= 10000 .AND. zrmax > r_max )          !  Iterative loop  !
+         !                                                  ! ================ !
+         jl = jl + 1
+
+         zrmax = 0.e0
+         zmsk(:,:) = 0.e0
+ 
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               iip1 = MIN( ji+1, nlci )      ! force zri = 0 on last line (ji=ncli+1 to jpi)
+               ijp1 = MIN( jj+1, nlcj )      ! force zrj = 0 on last raw  (jj=nclj+1 to jpj)
+               zri(ji,jj) = ABS( zenv(iip1,jj  ) - zenv(ji,jj) ) / ( zenv(iip1,jj  ) + zenv(ji,jj) )
+               zrj(ji,jj) = ABS( zenv(ji  ,ijp1) - zenv(ji,jj) ) / ( zenv(ji  ,ijp1) + zenv(ji,jj) )
+               zrmax = MAX( zrmax, zri(ji,jj), zrj(ji,jj) )
+               IF( zri(ji,jj) > r_max )   zmsk(ji  ,jj  ) = 1.0
+               IF( zri(ji,jj) > r_max )   zmsk(iip1,jj  ) = 1.0
+               IF( zrj(ji,jj) > r_max )   zmsk(ji  ,jj  ) = 1.0
+               IF( zrj(ji,jj) > r_max )   zmsk(ji  ,ijp1) = 1.0
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_max( zrmax )   ! max over the global domain
+         ! lateral boundary condition on zmsk: keep 1 along closed boundary (use of MAX)
+         ztmp(:,:) = zmsk(:,:)
+         CALL lbc_lnk( zmsk, 'T', 1. )
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+                zmsk(ji,jj) = MAX( zmsk(ji,jj), ztmp(ji,jj) )    
+            END DO
+         END DO
+ 
+         WRITE(numout,*) 'zgr_sco :   iter= ',jl, ' rmax= ', zrmax, ' nb of pt= ', INT( SUM(zmsk(:,:) ) )
+
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               iip1 = MIN( ji+1, nlci )     ! last  line (ji=nlci)
+               ijp1 = MIN( jj+1, nlcj )     ! last  raw  (jj=nlcj)
+               iim1 = MAX( ji-1,  1  )      ! first line (ji=nlci)
+               ijm1 = MAX( jj-1,  1  )      ! first raw  (jj=nlcj)
+               IF( zmsk(ji,jj) == 1.0 ) THEN
+                  ztmp(ji,jj) =   (                                                                                   &
+             &      zenv(iim1,ijp1)*zmsk(iim1,ijp1) + zenv(ji,ijp1)*zmsk(ji,ijp1) + zenv(iip1,ijp1)*zmsk(iip1,ijp1)   &
+             &    + zenv(iim1,jj  )*zmsk(iim1,jj  ) + zenv(ji,jj  )*    2.e0      + zenv(iip1,jj  )*zmsk(iip1,jj  )   &
+             &    + zenv(iim1,ijm1)*zmsk(iim1,ijm1) + zenv(ji,ijm1)*zmsk(ji,ijm1) + zenv(iip1,ijm1)*zmsk(iip1,ijm1)   &
+             &                    ) / (                                                                               &
+             &                      zmsk(iim1,ijp1) +               zmsk(ji,ijp1) +                 zmsk(iip1,ijp1)   &
+             &    +                 zmsk(iim1,jj  ) +                   2.e0      +                 zmsk(iip1,jj  )   &
+             &    +                 zmsk(iim1,ijm1) +               zmsk(ji,ijm1) +                 zmsk(iip1,ijm1)   &
+             &                        )
+               ENDIF
+            END DO
+         END DO
+ 
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               IF( zmsk(ji,jj) == 1.0 )   zenv(ji,jj) = MAX( ztmp(ji,jj), bathy(ji,jj) )
+            END DO
+         END DO
+
+         ! Apply lateral boundary condition   CAUTION: kept the value when the lbc field is zero
+         ztmp(:,:) = zenv(:,:)
+         CALL lbc_lnk( zenv, 'T', 1. )
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               IF( zenv(ji,jj) == 0.e0 )   zenv(ji,jj) = ztmp(ji,jj)
+            END DO
+         END DO
+         !                                                  ! ================ !
+      END DO                                                !     End loop     !
+      !                                                     ! ================ !
+
+      ! save envelop bathymetry in hbatt
+      hbatt(:,:) = zenv(:,:) 
+
+!!bug gm  :   CAUTION:  tapering hard coded !!!!  orca2 only
+!!bug gm                NOT valid in mpp ===> taper have been changed
+
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+!!bug mpp    ztaper = EXP( -(FLOAT(jj-74)/10.)**2 )
+             ztaper = EXP( -(gphit(ji,jj)/8)**2 )
+             hbatt(ji,jj) = sbot_max * ztaper + hbatt(ji,jj) * (1.-ztaper)
+          END DO
+       END DO
+
+      DO jj = 1, jpj
+         zrmax  = EXP( -(gphit(10,jj)/8)**2 )
+         ztaper = EXP( -(FLOAT(jj-74)/10.)**2 )
+         IF( nprint == 1 .AND. lwp ) WRITE(numout,*) jj, (FLOAT(jj-74)/10.), ztaper,(gphit(10,jj)/8), zrmax
+      END DO
+
+      IF( nprint == 1 .AND. lwp )   THEN
+         WRITE(numout,*) ' bathy  MAX ', MAXVAL( bathy(:,:) ), ' MIN ', MINVAL( bathy(:,:) )
+         WRITE(numout,*) ' hbatt  MAX ', MAXVAL( hbatt(:,:) ), ' MIN ', MINVAL( hbatt(:,:) )
+      ENDIF
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' domzgr: hbatt field; ocean depth in meters'
+         WRITE(numout,*)
+         CALL prihre( hbatt(1,1), jpi, jpj, 1, jpi, 1, 1, jpj, 1, 0., numout )
+      ENDIF
+
+      ! 1. computation of hbatu, hbatv, hbatf fields
+      ! --------------------------------------------
+
+      hbatu(:,:) = sbot_min
+      hbatv(:,:) = sbot_min
+      hbatf(:,:) = sbot_min
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' zgr_sco: minimum depth of the envelop topography set to : ', sbot_min
+         WRITE(numout,*)
+      ENDIF
+
+      DO jj = 1, jpjm1
+        DO ji = 1, jpim1
+           hbatu(ji,jj)= 0.5 *( hbatt(ji  ,jj)+hbatt(ji+1,jj  ) )
+           hbatv(ji,jj)= 0.5 *( hbatt(ji  ,jj)+hbatt(ji  ,jj+1) )
+           hbatf(ji,jj)= 0.25*( hbatt(ji  ,jj)+hbatt(ji  ,jj+1)   &
+                               +hbatt(ji+1,jj)+hbatt(ji+1,jj+1) )
+        END DO
+      END DO
+ 
+      ! Apply lateral boundary condition
+      ! CAUTION: retain non zero value in the initial file
+      !          this should be OK for orca cfg, not for EEL
+      zhbat(:,:) = hbatu(:,:)
+      CALL lbc_lnk( hbatu, 'U', 1. )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatu(ji,jj) == 0.e0 ) THEN
+               IF( zhbat(ji,jj) == 0.e0 )   hbatu(ji,jj) = sbot_min
+               IF( zhbat(ji,jj) /= 0.e0 )   hbatu(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+
+      zhbat(:,:) = hbatv(:,:)
+      CALL lbc_lnk( hbatv, 'V', 1. )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatv(ji,jj) == 0.e0 ) THEN
+               IF( zhbat(ji,jj) == 0.e0 )   hbatv(ji,jj) = sbot_min
+               IF( zhbat(ji,jj) /= 0.e0 )   hbatv(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+
+      zhbat(:,:) = hbatf(:,:)
+      CALL lbc_lnk( hbatf, 'F', 1. )
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hbatf(ji,jj) == 0.e0 ) THEN
+               IF( zhbat(ji,jj) == 0.e0 )   hbatf(ji,jj) = sbot_min
+               IF( zhbat(ji,jj) /= 0.e0 )   hbatf(ji,jj) = zhbat(ji,jj)
+            ENDIF
+         END DO
+      END DO
+
+
+!!bug:  key_helsinki a verifer
+      hift(:,:) = MIN( hift(:,:), hbatt(:,:) )
+      hifu(:,:) = MIN( hifu(:,:), hbatu(:,:) )
+      hifv(:,:) = MIN( hifv(:,:), hbatv(:,:) )
+      hiff(:,:) = MIN( hiff(:,:), hbatf(:,:) )
+
+      IF( nprint == 1 .AND. lwp )   THEN
+         WRITE(numout,*) ' MAX val hif   t ', MAXVAL( hift(:,:) ), ' f ', MAXVAL( hiff(:,:) ),  &
+            &                        ' u ',   MAXVAL( hifu(:,:) ), ' v ', MAXVAL( hifv(:,:) )
+         WRITE(numout,*) ' MIN val hif   t ', MINVAL( hift(:,:) ), ' f ', MINVAL( hiff(:,:) ),  &
+            &                        ' u ',   MINVAL( hifu(:,:) ), ' v ', MINVAL( hifv(:,:) )
+         WRITE(numout,*) ' MAX val hbat  t ', MAXVAL( hbatt(:,:) ), ' f ', MAXVAL( hbatf(:,:) ),  &
+            &                        ' u ',   MAXVAL( hbatu(:,:) ), ' v ', MAXVAL( hbatv(:,:) )
+         WRITE(numout,*) ' MIN val hbat  t ', MINVAL( hbatt(:,:) ), ' f ', MINVAL( hbatf(:,:) ),  &
+            &                        ' u ',   MINVAL( hbatu(:,:) ), ' v ', MINVAL( hbatv(:,:) )
+      ENDIF
+!! helsinki
+
+      ! 2. Computation of gsig and esig fields
+      ! --------------------------------------
+
+      ! 2.1 Coefficients for model level depth at w- and t-levels
+
+!!bug gm : change the def of statment function....
+      DO jk = 1, jpk
+        gsigw(jk) = -fssigw(FLOAT(jk))
+        gsigt(jk) = -fssigt(FLOAT(jk))
+      END DO
+
+      IF( nprint == 1 .AND. lwp ) WRITE(numout,*) 'gsigw 1 jpk    ', gsigw(1), gsigw(jpk)
+
+!!org DO jk = 1, jpk
+!!org    gsigw(jk) = -fssig ( FLOAT(jk)    )
+!!org    gsigt(jk) = -fssig ( FLOAT(jk)+0.5)
+!!org END DO
+
+      ! 2.2 Coefficients for vertical scale factors at w-, t- levels
+
+!!bug gm :  define it from analytical function, not like juste bellow....
+!!          or betteroffer the 2 possibilities....
+      DO jk=2,jpk
+        esigw(jk)=gsigt(jk)-gsigt(jk-1)
+      END DO
+      DO jk=1,jpkm1
+        esigt(jk)=gsigw(jk+1)-gsigw(jk)
+      END DO
+        esigw(1)=esigw(2)
+        esigt(jpk)=esigt(jpkm1)
+
+!!org DO jk = 1, jpk
+!!org    esigw(jk)=fsdsig( FLOAT(jk))
+!!org    esigt(jk)=fsdsig( FLOAT(jk)+0.5)
+!!org END DO
+
+      ! 2.3 Coefficients for vertical depth as the sum of e3w scale factors
+
+      gsi3w(1) = 0.5 * esigw(1)
+      DO jk = 2, jpk
+        gsi3w(jk) = gsi3w(jk-1)+ esigw(jk)
+      END DO
+
+!!bug gm: depuw, depvw can be suppressed (modif in ldfslp) and depw=dep3w can be set (save 3 3D arrays)
+      DO jk = 1, jpk
+!! change the solver stat....
+!!       zcoeft = ( FLOAT(jk) - 0.5 ) / FLOAT(jpkm1)
+!!       gdept (:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsigt(jk)+hift(:,:)*zcoeft)
+         gdept (:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsigt(jk)+hift(:,:)*(FLOAT(jk)-0.5)/FLOAT(jpkm1))
+!!       zcoefw = ( FLOAT(jk) - 1.0 ) / FLOAT(jpkm1) 
+!!       gdepw (:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsigw(jk)+hift(:,:)*zcoefw)
+!!       gdep3w(:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsi3w(jk)+hift(:,:)*zcoefw)
+         gdepw (:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsigw(jk)+hift(:,:)*FLOAT(jk-1)/FLOAT(jpkm1))
+         gdep3w(:,:,jk) = (scosrf(:,:)+(hbatt(:,:)-hift(:,:))*gsi3w(jk)+hift(:,:)*FLOAT(jk-1)/FLOAT(jpkm1))
+      END DO
+
+!!bug gm: e3uw, e3vw can be suppressed  (modif in dynzdf, dynzdf_iso, zdfbfr) (save 2 3D arrays)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            DO jk = 1, jpk
+              e3t(ji,jj,jk)=((hbatt(ji,jj)-hift(ji,jj))*esigt(jk) + hift(ji,jj)/FLOAT(jpkm1))
+              e3u(ji,jj,jk)=((hbatu(ji,jj)-hifu(ji,jj))*esigt(jk) + hifu(ji,jj)/FLOAT(jpkm1))
+              e3v(ji,jj,jk)=((hbatv(ji,jj)-hifv(ji,jj))*esigt(jk) + hifv(ji,jj)/FLOAT(jpkm1))
+              e3f(ji,jj,jk)=((hbatf(ji,jj)-hiff(ji,jj))*esigt(jk) + hiff(ji,jj)/FLOAT(jpkm1))
+
+              e3w (ji,jj,jk)=((hbatt(ji,jj)-hift(ji,jj))*esigw(jk) + hift(ji,jj)/FLOAT(jpkm1))
+              e3uw(ji,jj,jk)=((hbatu(ji,jj)-hifu(ji,jj))*esigw(jk) + hifu(ji,jj)/FLOAT(jpkm1))
+              e3vw(ji,jj,jk)=((hbatv(ji,jj)-hifv(ji,jj))*esigw(jk) + hifv(ji,jj)/FLOAT(jpkm1))
+            END DO
+         END DO
+      END DO
+
+! HYBRID
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            DO jk = 1, jpkm1
+               IF( scobot(ji,jj) >= fsdept(ji,jj,jk) )   mbathy(ji,jj) = MAX( 2, jk )
+               IF( scobot(ji,jj) == 0.e0             )   mbathy(ji,jj) = 0
+            END DO
+         END DO
+      END DO
+
+      IF( nprint == 1 .AND. lwp ) WRITE(numout,*) ' MIN val mbathy h90 ', MINVAL( mbathy(:,:) ),   &
+         &                                        ' MAX '               , MAXVAL( mbathy(:,:) )
+
+
+      ! ===========
+      ! Zoom domain 
+      ! ===========
+
+      IF( lzoom )   CALL zgr_bat_zoom
+
+      IF(lwp) THEN                           ! Control print
+         WRITE(numout,*) 
+         WRITE(numout,*) ' domzgr: vertical coefficients for model level'
+         WRITE(numout,9400)
+         WRITE(numout,9410) (jk,gsigt(jk),gsigw(jk),esigt(jk),esigw(jk),gsi3w(jk),jk=1,jpk)
+      ENDIF
+ 9400 FORMAT(9x,'  level    gsigt      gsigw      esigt      esigw      gsi3w')
+ 9410 FORMAT(10x,i4,5f11.4)
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' domzgr: vertical coordinates : point (1,1,k) bathy = ', bathy(1,1), hbatt(1,1)
+         WRITE(numout,*) ' ~~~~~~  --------------------'
+         WRITE(numout,9420)
+         WRITE(numout,9430) (jk,fsdept(1,1,jk),fsdepw(1,1,jk),     &
+                             fse3t (1,1,jk),fse3w (1,1,jk),jk=1,jpk)
+         DO jj = mj0(20), mj1(20)
+            DO ji = mi0(20), mi1(20)
+               WRITE(numout,*)
+               WRITE(numout,*) ' domzgr: vertical coordinates : point (20,20,k)   bathy = ', bathy(ji,jj), hbatt(ji,jj)
+               WRITE(numout,*) ' ~~~~~~  --------------------'
+               WRITE(numout,9420)
+               WRITE(numout,9430) (jk,fsdept(ji,jj,jk),fsdepw(ji,jj,jk),     &
+                    &                 fse3t (ji,jj,jk),fse3w (ji,jj,jk),jk=1,jpk)
+            END DO
+         END DO
+         DO jj = mj0(74), mj1(74)
+            DO ji = mi0(100), mi1(100)
+               WRITE(numout,*)
+               WRITE(numout,*) ' domzgr: vertical coordinates : point (100,74,k)   bathy = ', bathy(ji,jj), hbatt(ji,jj)
+               WRITE(numout,*) ' ~~~~~~  --------------------'
+               WRITE(numout,9420)
+               WRITE(numout,9430) (jk,fsdept(ji,jj,jk),fsdepw(ji,jj,jk),     &
+                    &                 fse3t (ji,jj,jk),fse3w (ji,jj,jk),jk=1,jpk)
+            END DO
+         END DO
+      ENDIF
+
+ 9420 FORMAT(9x,' level   gdept    gdepw    gde3w     e3t      e3w  ')
+ 9430 FORMAT(10x,i4,4f9.2)
+
+!!bug gm   no more necessary?  if ! defined key_helsinki
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fse3w(ji,jj,jk) <= 0. .OR. fse3t(ji,jj,jk) <= 0. ) THEN
+                  IF(lwp) THEN
+                     WRITE(numout,*)
+                     WRITE(numout,*) ' e r r o r :         e3w or e3t =< 0 '
+                     WRITE(numout,*) ' =========           --------------- '
+                     WRITE(numout,*)
+                     WRITE(numout,*) '             point (i,j,k)= ',ji,jj,jk
+                     WRITE(numout,*)
+                  ENDIF
+                  STOP 'domzgr'
+               ENDIF
+               IF( fsdepw(ji,jj,jk) < 0. .OR. fsdept(ji,jj,jk) < 0. ) THEN
+                  IF(lwp) THEN
+                     WRITE(numout,*)
+                     WRITE(numout,*) ' e r r o r :      gdepw or gdept < 0 '
+                     WRITE(numout,*) ' =========        ------------------ '
+                     WRITE(numout,*)
+                     WRITE(numout,*) '             point (i,j,k)= ', ji, jj, jk
+                     WRITE(numout,*)
+                  ENDIF
+                  STOP 'domzgr'
+               ENDIF
+            END DO
+         END DO
+      END DO
+!!bug gm    #endif
+      !
+   END SUBROUTINE zgr_sco
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                      Empty routine
+   !!----------------------------------------------------------------------
+   SUBROUTINE zgr_sco
+   END SUBROUTINE zgr_sco
+#endif
+
+
+   !!======================================================================
+END MODULE domzgr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90	(revision 4536)
@@ -0,0 +1,72 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  domzgr_substitute.h90   ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsdep. and fse.., the vert. depth and scale
+   !!      factors depending on the vertical coord. used, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!
+   !! History :
+   !!   9.0  !  05-10  (A. Beckmann, G. Madec) generalisation to all coord.
+   !!----------------------------------------------------------------------
+#if defined key_zco
+#   define  fsdept(i,j,k)  gdept_0(k)
+
+#   define  fsdepw(i,j,k)  gdepw_0(k)
+#   define  fsde3w(i,j,k)  gdepw_0(k)
+
+#   define  fse3t(i,j,k)   e3t_0(k)
+#   define  fse3u(i,j,k)   e3t_0(k)
+#   define  fse3v(i,j,k)   e3t_0(k)
+#   define  fse3f(i,j,k)   e3t_0(k)
+
+#   define  fse3w(i,j,k)   e3w_0(k)
+#   define  fse3uw(i,j,k)  e3w_0(k)
+#   define  fse3vw(i,j,k)  e3w_0(k)
+#else
+#   define  fsdept(i,j,k)  gdept(i,j,k)
+
+#   define  fsdepw(i,j,k)  gdepw(i,j,k)
+#   define  fsde3w(i,j,k)  gdep3w(i,j,k)
+ 
+#   define  fse3t(i,j,k)   e3t(i,j,k)
+#   define  fse3u(i,j,k)   e3u(i,j,k)
+#   define  fse3v(i,j,k)   e3v(i,j,k)
+#   define  fse3f(i,j,k)   e3f(i,j,k)
+
+#   define  fse3w(i,j,k)   e3w(i,j,k)
+#   define  fse3uw(i,j,k)  e3uw(i,j,k)
+#   define  fse3vw(i,j,k)  e3vw(i,j,k)
+#endif
+
+#if defined key_vvl
+#   define  fsvdept(i,j,k)  gdept_1(i,j,k)
+
+#   define  fsvdepw(i,j,k)  gdepw_1(i,j,k)
+#   define  fsvde3w(i,j,k)  gdep3w_1(i,j,k)
+
+#   define  fsve3t(i,j,k)   e3t_1(i,j,k)
+#   define  fsve3u(i,j,k)   e3u_1(i,j,k)
+#   define  fsve3v(i,j,k)   e3v_1(i,j,k)
+#   define  fsve3f(i,j,k)   e3f_1(i,j,k)
+
+#   define  fsve3w(i,j,k)   e3w_1(i,j,k)
+#   define  fsve3uw(i,j,k)  e3uw_1(i,j,k)
+#   define  fsve3vw(i,j,k)  e3vw_1(i,j,k)
+#else
+#   define  fsvdept(i,j,k)  fsdept(i,j,k)
+
+#   define  fsvdepw(i,j,k)  fsdepw(i,j,k)
+#   define  fsvde3w(i,j,k)  fsde3w(i,j,k)
+
+#   define  fsve3t(i,j,k)   fse3t(i,j,k)
+#   define  fsve3u(i,j,k)   fse3u(i,j,k)
+#   define  fsve3v(i,j,k)   fse3v(i,j,k)
+#   define  fsve3f(i,j,k)   fse3f(i,j,k)
+
+#   define  fsve3w(i,j,k)   fse3w(i,j,k)
+#   define  fsve3uw(i,j,k)  fse3uw(i,j,k)
+#   define  fsve3vw(i,j,k)  fse3vw(i,j,k)
+#endif
+
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_zps.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_zps.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DOM/domzgr_zps.h90	(revision 4536)
@@ -0,0 +1,443 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  domzgr_zps.h90  ***
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+#if ! defined key_zco
+   !!----------------------------------------------------------------------
+   !!   NOT 'key_zco' :                                    3D gdep. and e3.
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zgr_zps
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zgr_zps  ***
+      !!                     
+      !! ** Purpose :   the depth and vertical scale factor in partial step
+      !!      z-coordinate case
+      !!
+      !! ** Method  :   Partial steps : computes the 3D vertical scale factors
+      !!      of T-, U-, V-, W-, UW-, VW and F-points that are associated with
+      !!      a partial step representation of bottom topography.
+      !!
+      !!        The reference depth of model levels is defined from an analytical
+      !!      function the derivative of which gives the reference vertical
+      !!      scale factors.
+      !!        From  depth and scale factors reference, we compute there new value
+      !!      with partial steps  on 3d arrays ( i, j, k ).
+      !!
+      !!              w-level: gdepw(i,j,k)  = fsdep(k)
+      !!                       e3w(i,j,k) = dk(fsdep)(k)     = fse3(i,j,k)
+      !!              t-level: gdept(i,j,k)  = fsdep(k+0.5)
+      !!                       e3t(i,j,k) = dk(fsdep)(k+0.5) = fse3(i,j,k+0.5)
+      !!
+      !!        With the help of the bathymetric file ( bathymetry_depth_ORCA_R2.nc),
+      !!      we find the mbathy index of the depth at each grid point.
+      !!      This leads us to three cases:
+      !!
+      !!              - bathy = 0 => mbathy = 0
+      !!              - 1 < mbathy < jpkm1    
+      !!              - bathy > gdepw(jpk) => mbathy = jpkm1  
+      !!
+      !!        Then, for each case, we find the new depth at t- and w- levels
+      !!      and the new vertical scale factors at t-, u-, v-, w-, uw-, vw- 
+      !!      and f-points.
+      !! 
+      !!        This routine is given as an example, it must be modified
+      !!      following the user s desiderata. nevertheless, the output as
+      !!      well as the way to compute the model levels and scale factors
+      !!      must be respected in order to insure second order accuracy
+      !!      schemes.
+      !!
+      !!         c a u t i o n : gdept_0, gdepw_0 and e3._0 are positives
+      !!         - - - - - - -   gdept, gdepw and e3. are positives
+      !!      
+      !!  Reference :
+      !!     Pacanowsky & Gnanadesikan 1997, Mon. Wea. Rev., 126, 3248-3270.
+      !!
+      !!  History :
+      !!    8.5  !  02-09 (A. Bozec, G. Madec)  F90: Free form and module
+      !!    9.0  !  02-09 (A. de Miranda)  rigid-lid + islands
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk    ! dummy loop indices
+      INTEGER  ::   &
+         ik, it            ! temporary integers
+      
+      REAL(wp) ::   &  
+         ze3tp, ze3wp,    &  ! Last ocean level thickness at T- and W-points
+         zdepwp,          &  ! Ajusted ocean depth to avoid too small e3t
+         zdepth,          &  !    "         "
+         zmax, zmin,      &  ! Maximum and minimum depth
+         zdiff               ! temporary scalar
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zprt  !    "           "
+
+      LOGICAL ::  ll_print                          ! Allow  control print for debugging
+
+      !!---------------------------------------------------------------------
+      !! OPA8.5, LODYC-IPSL (2002)
+      !!---------------------------------------------------------------------
+      
+      ! Local variable for debugging
+      ll_print=.FALSE.
+!!!   ll_print=.TRUE.
+      
+      ! Initialization of constant
+      zmax = gdepw_0(jpk) + e3t_0(jpk)
+      zmin = gdepw_0(4)
+      
+      ! Ocean depth
+      IF(lwp .AND. ll_print) THEN 
+         WRITE(numout,*)
+         WRITE(numout,*) 'dom_zgr_zps:  bathy (in hundred of meters)'
+         CALL prihre( bathy, jpi, jpj, 1,jpi, 1, 1, jpj, 1, 1.e-2, numout )
+      ENDIF
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '    zgr_zps : z-coordinate with partial steps'
+      IF(lwp) WRITE(numout,*) '    ~~~~~~~ '
+      IF(lwp) WRITE(numout,*) '              mbathy is recomputed : bathy_level file is NOT used'
+
+
+      ! bathymetry in level (from bathy_meter)
+      ! ===================
+
+      ! initialize mbathy to the maximum ocean level available
+      mbathy(:,:) = jpkm1
+
+      ! storage of land and island's number (zera and negative values) in mbathy
+      DO jj = 1, jpj
+         DO ji= 1, jpi
+            IF( bathy(ji,jj) <= 0. )   mbathy(ji,jj) = INT( bathy(ji,jj) )
+         END DO
+      END DO
+
+      ! bounded value of bathy
+      ! minimum depth == 3 levels
+      ! maximum depth == gdepw_0(jpk)+e3t_0(jpk) 
+      ! i.e. the last ocean level thickness cannot exceed e3t_0(jpkm1)+e3t_0(jpk)
+      DO jj = 1, jpj
+         DO ji= 1, jpi
+            IF( bathy(ji,jj) <= 0. ) THEN
+               bathy(ji,jj) = 0.e0
+            ELSE
+               bathy(ji,jj) = MAX( bathy(ji,jj), zmin )
+               bathy(ji,jj) = MIN( bathy(ji,jj), zmax )
+            ENDIF
+         END DO
+      END DO
+
+      ! Compute mbathy for ocean points (i.e. the number of ocean levels)
+      ! find the number of ocean levels such that the last level thickness
+      ! is larger than the minimum of e3zps_min and e3zps_rat * e3t_0 (where
+      ! e3t_0 is the reference level thickness
+      DO jk = jpkm1, 1, -1
+         zdepth = gdepw_0(jk) + MIN( e3zps_min, e3t_0(jk)*e3zps_rat )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( 0. < bathy(ji,jj) .AND. bathy(ji,jj) <= zdepth )   mbathy(ji,jj) = jk-1
+            END DO
+         END DO
+      END DO
+
+     ! Scale factors and depth at T- and W-points
+     
+     ! intitialization to the reference z-coordinate
+     DO jk = 1, jpk
+        gdept(:,:,jk) = gdept_0(jk)
+        gdepw(:,:,jk) = gdepw_0(jk)
+        e3t  (:,:,jk) = e3t_0  (jk)
+        e3w  (:,:,jk) = e3w_0  (jk)
+     END DO
+     hdept(:,:) = gdept(:,:,2 )
+     hdepw(:,:) = gdepw(:,:,3 )     
+     
+     ! 
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           ik = mbathy(ji,jj)
+           ! ocean point only
+           IF( ik > 0 ) THEN
+              ! max ocean level case
+              IF( ik == jpkm1 ) THEN
+                 zdepwp = bathy(ji,jj)
+                 ze3tp  = bathy(ji,jj) - gdepw_0(ik)
+                 ze3wp = 0.5 * e3w_0(ik) * ( 1. + ( ze3tp/e3t_0(ik) ) )
+                 e3t(ji,jj,ik  ) = ze3tp
+                 e3t(ji,jj,ik+1) = ze3tp
+                 e3w(ji,jj,ik  ) = ze3wp
+                 e3w(ji,jj,ik+1) = ze3tp
+                 gdepw(ji,jj,ik+1) = zdepwp
+                 gdept(ji,jj,ik  ) = gdept_0(ik-1) + ze3wp
+                 gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + ze3tp
+                 ! standard case
+              ELSE
+!!alex
+                 IF( bathy(ji,jj) <= gdepw_0(ik+1) ) THEN
+                    gdepw(ji,jj,ik+1) = bathy(ji,jj)
+                 ELSE
+!!alex ctl          write(*,*) 'zps',ji,jj,'bathy', bathy(ji,jj), 'depw ',gdepw_0(ik+1)
+                    gdepw(ji,jj,ik+1) = gdepw_0(ik+1)
+                 ENDIF
+!!Alex
+!!Alex           gdepw(ji,jj,ik+1) = bathy(ji,jj)
+!!bug gm  verifier les gdepw_0
+                 gdept(ji,jj,ik  ) =  gdepw_0(ik) + ( gdepw(ji,jj,ik+1) - gdepw_0(ik) )   &
+                    &                             * ((gdept_0(      ik  ) - gdepw_0(ik) )   &
+                    &                             / ( gdepw_0(      ik+1) - gdepw_0(ik) ))
+                 e3t(ji,jj,ik) = e3t_0(ik) * ( gdepw  (ji,jj,ik+1) - gdepw_0(ik) )   & 
+                    &                      / ( gdepw_0(      ik+1) - gdepw_0(ik) ) 
+                 e3w(ji,jj,ik) = 0.5 * ( gdepw(ji,jj,ik+1) + gdepw_0(ik+1) - 2.*gdepw_0(ik) )   &
+                    &                * ( e3w_0(ik) / ( gdepw_0(ik+1) - gdepw_0(ik) ) )
+                 !       ... on ik+1
+                 e3w(ji,jj,ik+1) = e3t(ji,jj,ik)
+                 e3t(ji,jj,ik+1) = e3t(ji,jj,ik)
+                 gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + e3t(ji,jj,ik)
+              ENDIF
+           ENDIF
+        END DO
+     END DO
+
+     it = 0
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           ik = mbathy(ji,jj)
+           ! ocean point only
+           IF( ik > 0 ) THEN
+              ! bathymetry output
+              hdept(ji,jj) = gdept(ji,jj,ik  )
+              hdepw(ji,jj) = gdepw(ji,jj,ik+1)
+              e3tp (ji,jj) = e3t(ji,jj,ik  )
+              e3wp (ji,jj) = e3w(ji,jj,ik  )
+              ! test
+              zdiff= gdepw(ji,jj,ik+1) - gdept(ji,jj,ik  )
+              IF( zdiff <= 0. .AND. lwp ) THEN 
+                 it=it+1
+                 WRITE(numout,*) ' it      = ', it, ' ik      = ', ik, ' (i,j) = ', ji, jj
+                 WRITE(numout,*) ' bathy = ', bathy(ji,jj)
+                 WRITE(numout,*) ' gdept= ', gdept(ji,jj,ik), ' gdepw= ', gdepw(ji,jj,ik+1),   &
+                                 ' zdiff   = ', zdiff
+                 WRITE(numout,*) ' e3tp    = ', e3t(ji,jj,ik  ), ' e3wp    = ', e3w(ji,jj,ik  )
+              ENDIF
+           ENDIF
+        END DO
+      END DO
+
+      ! Scale factors and depth at U-, V-, UW and VW-points
+
+      ! initialisation to z-scale factors
+      DO jk = 1, jpk
+         e3u (:,:,jk)  = e3t_0(jk)
+         e3v (:,:,jk)  = e3t_0(jk)
+         e3uw(:,:,jk)  = e3w_0(jk)
+         e3vw(:,:,jk)  = e3w_0(jk)
+      END DO
+
+     ! Computed as the minimum of neighbooring scale factors
+     DO jk = 1,jpk
+        DO jj = 1, jpjm1
+           DO ji = 1, fs_jpim1   ! vector opt.
+              e3u (ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji+1,jj,jk))
+              e3v (ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji,jj+1,jk))
+              e3uw(ji,jj,jk) = MIN( e3w(ji,jj,jk), e3w(ji+1,jj,jk) )
+              e3vw(ji,jj,jk) = MIN( e3w(ji,jj,jk), e3w(ji,jj+1,jk) )
+           END DO
+        END DO
+     END DO
+     
+     ! Boundary conditions
+     CALL lbc_lnk( e3u , 'U', 1. )   ;   CALL lbc_lnk( e3uw, 'U', 1. )
+     CALL lbc_lnk( e3v , 'V', 1. )   ;   CALL lbc_lnk( e3vw, 'V', 1. )
+     
+     ! set to z-scale factor if zero (i.e. along closed boundaries)
+     DO jk = 1, jpk
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              IF( e3u (ji,jj,jk) == 0.e0 ) e3u (ji,jj,jk) = e3t_0(jk)
+              IF( e3v (ji,jj,jk) == 0.e0 ) e3v (ji,jj,jk) = e3t_0(jk)
+              IF( e3uw(ji,jj,jk) == 0.e0 ) e3uw(ji,jj,jk) = e3w_0(jk)
+              IF( e3vw(ji,jj,jk) == 0.e0 ) e3vw(ji,jj,jk) = e3w_0(jk)
+           END DO
+        END DO
+     END DO
+     
+     ! Scale factor at F-point
+     
+     ! initialisation to z-scale factors
+     DO jk = 1, jpk
+        e3f (:,:,jk) = e3t_0(jk)
+     END DO
+     
+     ! Computed as the minimum of neighbooring V-scale factors
+     DO jk = 1, jpk
+        DO jj = 1, jpjm1
+           DO ji = 1, fs_jpim1   ! vector opt.
+              e3f(ji,jj,jk) = MIN( e3v(ji,jj,jk), e3v(ji+1,jj,jk) )
+           END DO
+        END DO
+     END DO
+     ! Boundary conditions
+     CALL lbc_lnk( e3f, 'F', 1. )
+     
+     ! set to z-scale factor if zero (i.e. along closed boundaries)
+     DO jk = 1, jpk
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              IF( e3f(ji,jj,jk) == 0.e0 ) e3f(ji,jj,jk) = e3t_0(jk)
+           END DO
+        END DO
+     END DO
+!!bug ? gm:  must be a do loop with mj0,mj1
+
+     ! we duplicate factor scales for jj = 1 and jj = 2
+     e3t(:,mj0(1),:) = e3t(:,mj0(2),:) 
+     e3w(:,mj0(1),:) = e3w(:,mj0(2),:) 
+     e3u(:,mj0(1),:) = e3u(:,mj0(2),:) 
+     e3v(:,mj0(1),:) = e3v(:,mj0(2),:) 
+     e3f(:,mj0(1),:) = e3f(:,mj0(2),:) 
+
+
+     
+     ! Compute gdep3w (vertical sum of e3w)
+     
+     gdep3w   (:,:,1) = 0.5 * e3w (:,:,1)
+     DO jk = 2, jpk
+        gdep3w   (:,:,jk) = gdep3w   (:,:,jk-1) + e3w (:,:,jk) 
+     END DO
+          
+     ! Control print
+ 9600 FORMAT(9x,' level   gdept    gdepw     e3t      e3w   ')
+ 9610 FORMAT(10x,i4,4f9.2)
+      IF(lwp .AND. ll_print) THEN
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik = MAX(mbathy(ji,jj),1)
+               zprt(ji,jj) = e3t(ji,jj,ik)
+            END DO
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr e3t(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik = MAX(mbathy(ji,jj),1)
+               zprt(ji,jj) = e3w(ji,jj,ik)
+            END DO
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr e3w(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik = MAX(mbathy(ji,jj),1)
+               zprt(ji,jj) = e3u(ji,jj,ik)
+            END DO
+         END DO
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr e3u(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik = MAX(mbathy(ji,jj),1)
+               zprt(ji,jj) = e3v(ji,jj,ik)
+            END DO
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr e3v(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik = MAX(mbathy(ji,jj),1) 
+               zprt(ji,jj) = e3f(ji,jj,ik)
+            END DO
+         END DO
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr e3f(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ik =  MAX(mbathy(ji,jj),1)
+               zprt(ji,jj) = gdep3w(ji,jj,ik)
+            END DO
+         END DO
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr gdep3w(mbathy)'
+         CALL prihre(zprt,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+
+      ENDIF  
+
+
+      DO jk = 1,jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi 
+               IF( e3w(ji,jj,jk) <= 0. .or. e3t(ji,jj,jk) <= 0. ) THEN
+                  IF(lwp) THEN
+                     WRITE(numout,*) ' e r r o r :         e3w or e3t =< 0 '
+                     WRITE(numout,*) ' =========           --------------- '
+                     WRITE(numout,*)
+                  ENDIF
+                  STOP 'domzgr.psteps'
+               ENDIF
+               IF( gdepw(ji,jj,jk) < 0. .or. gdept(ji,jj,jk) < 0. ) THEN
+                  IF(lwp) THEN
+                     WRITE(numout,*) ' e r r o r :      gdepw or gdept < 0 '
+                     WRITE(numout,*) ' =========        ------------------ '
+                     WRITE(numout,*)
+                  ENDIF
+                  STOP 'domzgr.psteps'
+               ENDIF
+            END DO
+         END DO
+      END DO  
+
+   IF(lwp) THEN
+      WRITE(numout,*) ' e3t lev 21 '
+      CALL prihre(e3t(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3w lev 21  '
+      CALL prihre(e3w(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3u lev 21  '
+      CALL prihre(e3u(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3v lev 21  '
+      CALL prihre(e3v(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3f lev 21  '
+      CALL prihre(e3f(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3t lev 22 '
+      CALL prihre(e3t(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3w lev 22  '
+      CALL prihre(e3w(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3u lev 22  '
+      CALL prihre(e3u(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3v lev 22  '
+      CALL prihre(e3v(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      WRITE(numout,*) ' e3f lev 22  '
+      CALL prihre(e3f(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+   ENDIF
+
+      ! ===========
+      ! Zoom domain 
+      ! ===========
+
+      IF( lzoom )   CALL zgr_bat_zoom
+
+      ! ================
+      ! Bathymetry check
+      ! ================
+
+      CALL zgr_bat_ctl
+
+   END SUBROUTINE zgr_zps
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                      Empty routine
+   !!----------------------------------------------------------------------
+   SUBROUTINE zgr_zps
+   END SUBROUTINE zgr_zps
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasal.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasal.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasal.F90	(revision 4536)
@@ -0,0 +1,347 @@
+MODULE dtasal
+   !!======================================================================
+   !!                     ***  MODULE  dtasal  ***
+   !! Ocean data  :  read ocean salinity data from monthly atlas data
+   !!=====================================================================
+#if defined key_dtasal   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dtasal'                                          salinity data
+   !!----------------------------------------------------------------------
+   !!   dta_sal      : read ocean salinity data
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE daymod          ! calendar
+#if defined key_orca_lev10
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dta_sal   ! called by step.F90 and inidta.F90
+   
+   !! * Shared module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasal = .TRUE.    !: salinity data flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      s_dta       !: salinity data at given time-step
+
+   !! * Module variables
+   INTEGER ::   &
+      numsdt,           &  !: logical unit for data salinity
+      nsal1, nsal2         ! first and second record used
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      saldta    ! salinity data at two consecutive times
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   !!----------------------------------------------------------------------
+   !!   Default option:                                         NetCDF file
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_sal( kt )
+     !!----------------------------------------------------------------------
+     !!                   ***  ROUTINE dta_sal  ***
+     !!        
+     !! ** Purpose :   Reads monthly salinity data
+     !!             
+     !! ** Method  : - Read on unit numsdt the monthly salinity data interpo-
+     !!     lated onto the model grid.
+     !!              - At each time step, a linear interpolation is applied
+     !!     between two monthly values.
+     !!
+     !! History :
+     !!        !  91-03  ()  Original code
+     !!        !  92-07  (M. Imbard)
+     !!   9.0  !  02-06  (G. Madec)  F90: Free form and module 
+     !!----------------------------------------------------------------------
+     !! * Modules used
+     USE iom
+     
+     !! * Arguments
+     INTEGER, INTENT(in) ::   kt             ! ocean time step
+     
+     !! * Local declarations
+     
+     INTEGER ::   ji, jj, jk, jl, jkk   ! dummy loop indicies
+     INTEGER ::   &
+          imois, iman, i15, ik           ! temporary integers
+#  if defined key_tradmp
+     INTEGER ::   &
+          il0, il1, ii0, ii1, ij0, ij1   ! temporary integers         
+# endif
+     REAL(wp) ::   zxy, zl
+#if defined key_orca_lev10
+     REAL(wp), DIMENSION(jpi,jpj,jpkdta,2) :: zsal
+     INTEGER   :: ikr, ikw, ikt, jjk
+     REAL(wp)  :: zfac
+#endif
+     REAL(wp), DIMENSION(jpk,2) ::   &
+          zsaldta            ! auxiliary array for interpolation
+     !!----------------------------------------------------------------------
+     
+     ! 0. Initialization
+     ! -----------------
+     
+     iman  = INT( raamo )
+!!! better but change the results     i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+     i15   = nday / 16
+     imois = nmonth + i15 - 1
+     IF( imois == 0 ) imois = iman
+     
+     ! 1. First call kt=nit000
+     ! -----------------------
+     
+     IF( kt == nit000 ) THEN
+        
+        nsal1 = 0   ! initializations
+        IF(lwp) WRITE(numout,*) ' dta_sal : monthly salinity data in NetCDF file'
+        CALL iom_open ( 'data_1m_salinity_nomask', numsdt ) 
+        
+     ENDIF
+     
+     
+     ! 2. Read monthly file
+     ! -------------------
+     
+     IF( kt == nit000 .OR. imois /= nsal1 ) THEN
+        
+        ! 2.1 Calendar computation
+        
+        nsal1 = imois        ! first file record used 
+        nsal2 = nsal1 + 1    ! last  file record used
+        nsal1 = MOD( nsal1, iman )
+        IF( nsal1 == 0 ) nsal1 = iman
+        nsal2 = MOD( nsal2, iman )
+        IF( nsal2 == 0 ) nsal2 = iman
+        IF(lwp) WRITE(numout,*) 'first record file used nsal1 ', nsal1
+        IF(lwp) WRITE(numout,*) 'last  record file used nsal2 ', nsal2
+        
+        ! 2.3 Read monthly salinity data Levitus 
+        
+#if defined key_orca_lev10
+        if (ln_zps) stop
+        zsal(:,:,:,:) = 0.
+        CALL iom_get (numsdt,jpdom_data,'vosaline',zsal(:,:,:,1),nsal1)
+        CALL iom_get (numsdt,jpdom_data,'vosaline',zsal(:,:,:,2),nsal2)
+#else
+        CALL iom_get (numsdt,jpdom_data,'vosaline',saldta(:,:,:,1),nsal1)
+        CALL iom_get (numsdt,jpdom_data,'vosaline',saldta(:,:,:,2),nsal2)
+#endif
+        
+        IF(lwp) THEN
+           WRITE(numout,*)
+           WRITE(numout,*) ' read Levitus salinity ok'
+           WRITE(numout,*)
+        ENDIF
+        
+#if defined key_tradmp
+        IF( cp_cfg == "orca"  .AND. jp_cfg == 2 ) THEN
+           
+           !                                        ! =======================
+           !                                        !  ORCA_R2 configuration
+           !                                        ! =======================
+           ij0 = 101   ;   ij1 = 109
+           ii0 = 141   ;   ii1 = 155   
+           DO jj = mj0(ij0), mj1(ij1)                  ! Reduced salinity in the Alboran Sea
+              DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                 zsal  (ji,jj,13:13,:) = zsal  (ji,jj,13:13,:) - 0.15
+                 zsal  (ji,jj,14:15,:) = zsal  (ji,jj,14:15,:) - 0.25
+                 zsal  (ji,jj,16:17,:) = zsal  (ji,jj,16:17,:) - 0.30
+                 zsal  (ji,jj,18:25,:) = zsal  (ji,jj,18:25,:) - 0.35
+#else
+                 saldta(ji,jj,13:13,:) = saldta(ji,jj,13:13,:) - 0.15
+                 saldta(ji,jj,14:15,:) = saldta(ji,jj,14:15,:) - 0.25
+                 saldta(ji,jj,16:17,:) = saldta(ji,jj,16:17,:) - 0.30
+                 saldta(ji,jj,18:25,:) = saldta(ji,jj,18:25,:) - 0.35
+#endif
+              END DO
+           END DO
+           IF( n_cla == 1 ) THEN 
+              !                                         ! New salinity profile at Gibraltar
+              il0 = 138   ;   il1 = 138   
+              ij0 = 101   ;   ij1 = 101
+              ii0 = 139   ;   ii1 = 139   
+#if defined key_orca_lev10
+              zsal  ( mi0(ii0):mi1(ii1), mj0(ij0):mj1(ij1) , : , : ) =   &
+                   &                          zsal  ( mi0(il0):mi1(il1) , mj0(ij0):mj1(ij1) , : , : )
+#else
+              saldta( mi0(ii0):mi1(ii1), mj0(ij0):mj1(ij1) , : , : ) =   &
+                   &                          saldta( mi0(il0):mi1(il1) , mj0(ij0):mj1(ij1) , : , : )
+#endif
+              ij0 = 101   ;   ij1 = 101
+#if defined key_orca_lev10
+              zsal  ( mi0(ii0):mi1(ii1), mj0(ij0):mj1(ij1) , : , : ) =   &
+                   &                          zsal  ( mi0(il0):mi1(il1) , mj0(ij0):mj1(ij1) , : , : )
+#else
+              saldta( mi0(ii0):mi1(ii1), mj0(ij0):mj1(ij1) , : , : ) =   &
+                   &                          saldta( mi0(il0):mi1(il1) , mj0(ij0):mj1(ij1) , : , : )
+#endif
+              il0 = 138   ;   il1 = 138   
+              ij0 = 101   ;   ij1 = 102
+              ii0 = 139   ;   ii1 = 139   
+              DO jl = mi0(il0), mi1(il1)                ! New salinity profile at Gibraltar
+                 DO jj = mj0(ij0), mj1(ij1)
+                    DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                       zsal  (ji,jj,:,:) = zsal  (jl,jj,:,:)
+#else
+                       saldta(ji,jj,:,:) = saldta(jl,jj,:,:)
+#endif
+                    END DO
+                 END DO
+              END DO
+              
+              il0 = 164   ;   il1 = 164   
+              ij0 =  88   ;   ij1 =  88
+              ii0 = 161   ;   ii1 = 163   
+              DO jl = mi0(il0), mi1(il1)                ! New salinity profile at Bab el Mandeb
+                 DO jj = mj0(ij0), mj1(ij1)
+                    DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                       zsal  (ji,jj,:,:) = zsal  (jl,jj,:,:)
+#else
+                       saldta(ji,jj,:,:) = saldta(jl,jj,:,:)
+#endif
+                    END DO
+                 END DO
+                 ij0 =  87   ;   ij1 =  87
+                 DO jj = mj0(ij0), mj1(ij1)
+                    DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                       zsal  (ji,jj,:,:) = zsal  (jl,jj,:,:)
+#else
+                       saldta(ji,jj,:,:) = saldta(jl,jj,:,:)
+#endif
+                    END DO
+                 END DO
+              END DO
+              
+           ENDIF
+           
+        ENDIF
+#endif   
+        
+#if defined key_orca_lev10
+        !  interpolate from 31 to 301 level the zsal field result in saldta
+        DO jl = 1, 2
+           DO jjk = 1, 5
+              saldta(:,:,jjk,jl) = zsal(:,:,1,jl)
+           ENDDO
+           DO jk = 1, jpk - 20, 10
+              ikr = INT( jk / 10 ) + 1
+              ikw = (ikr-1) * 10 + 1
+              ikt = ikw + 5
+              DO jjk = ikt , ikt + 9
+                 zfac = ( gdept_0(jjk) - gdepw_0(ikt) ) / ( gdepw_0(ikt+10) - gdepw_0(ikt) )
+                 saldta(:,:,jjk,jl) = zsal(:,:,ikr,jl) + ( zsal(:,:,ikr+1,jl) - zsal(:,:,ikr,jl) ) * zfac
+              END DO
+           END DO
+           DO jjk = jpk-5, jpk
+              saldta(:,:,jjk,jl) = zsal(:,:,jpkdta-1,jl)
+           END DO
+           ! fill the overlap areas
+           CALL lbc_lnk (saldta(:,:,:,jl),'Z',-999.,'no0')
+        END DO
+        
+#endif
+        
+        IF( ln_sco ) THEN
+           DO jl = 1, 2
+              DO jj = 1, jpj                  ! interpolation of salinites
+                 DO ji = 1, jpi
+                    DO jk = 1, jpk
+                       zl=fsdept(ji,jj,jk)
+                       IF(zl <  gdept_0(1)) zsaldta(jk,jl) =  saldta(ji,jj,1,jl)
+                       IF(zl >  gdept_0(jpk)) zsaldta(jk,jl) =  saldta(ji,jj,jpkm1,jl)
+                       DO jkk = 1, jpkm1
+                          IF((zl-gdept_0(jkk))*(zl-gdept_0(jkk+1)).le.0.0) THEN
+                             zsaldta(jk,jl) = saldta(ji,jj,jkk,jl)                                  &
+                                  &           + (zl-gdept_0(jkk))/(gdept_0(jkk+1)-gdept_0(jkk))       &
+                                  &                              *(saldta(ji,jj,jkk+1,jl) - saldta(ji,jj,jkk,jl))
+                          ENDIF
+                       END DO
+                    END DO
+                    DO jk = 1, jpkm1
+                       saldta(ji,jj,jk,jl) = zsaldta(jk,jl)
+                    END DO
+                    saldta(ji,jj,jpk,jl) = 0.0
+                 END DO
+              END DO
+           END DO
+           
+           IF(lwp) WRITE(numout,*)
+           IF(lwp) WRITE(numout,*) ' Levitus salinity data interpolated to s-coordinate'
+           IF(lwp) WRITE(numout,*)
+           
+        ELSE
+           !                                  ! Mask
+           DO jl = 1, 2
+              saldta(:,:,:,jl) = saldta(:,:,:,jl)*tmask(:,:,:)
+              saldta(:,:,jpk,jl) = 0.
+              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 = mbathy(ji,jj) - 1
+                       IF( ik > 2 ) THEN
+                          zl = ( gdept_0(ik) - fsdept(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                          saldta(ji,jj,ik,jl) = (1.-zl) * saldta(ji,jj,ik,jl) +zl * saldta(ji,jj,ik-1,jl)
+                       ENDIF
+                    END DO
+                 END DO
+              ENDIF
+           END DO
+        ENDIF
+        
+        
+        IF(lwp) THEN
+           WRITE(numout,*)' salinity Levitus month ',nsal1,nsal2
+           WRITE(numout,*)
+           WRITE(numout,*) ' Levitus month = ',nsal1,'  level = 1'
+           CALL prihre(saldta(:,:,1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+           WRITE(numout,*) ' Levitus month = ',nsal1,'  level = ',jpk/2
+           CALL prihre(saldta(:,:,jpk/2,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+           WRITE(numout,*) ' Levitus month = ',nsal1,'  level = ',jpkm1
+           CALL prihre(saldta(:,:,jpkm1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+        ENDIF
+     ENDIF
+     
+     
+     ! 3. At every time step compute salinity data
+     ! -------------------------------------------
+     
+     zxy = FLOAT(nday + 15 - 30*i15)/30.
+     s_dta(:,:,:) = ( 1.- zxy ) * saldta(:,:,:,1) + zxy * saldta(:,:,:,2)
+     
+     ! Close the file
+     ! --------------
+     
+     IF( kt == nitend )   CALL iom_close (numsdt)
+
+   END SUBROUTINE dta_sal
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option:                                    NO salinity data
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasal = .FALSE.   !: salinity data flag
+CONTAINS
+   SUBROUTINE dta_sal( kt )        ! Empty routine
+      WRITE(*,*) 'dta_sal: You should not have seen this print! error?', kt
+   END SUBROUTINE dta_sal
+#endif
+   !!======================================================================
+END MODULE dtasal
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasss.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasss.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasss.F90	(revision 4536)
@@ -0,0 +1,128 @@
+MODULE dtasss
+   !!======================================================================
+   !!                       ***  MODULE  dtasss  ***
+   !! Data : Sea Surface Salinity (SSS)
+   !!======================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   dta_sss      : sss data
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE ocfzpt          ! ???
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Shared routine
+   PUBLIC dta_sss
+
+   !! * Shared module variables
+#if defined key_dtasss
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasss = .TRUE.   !: sss data flag
+#else
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasss = .FALSE.  !: sss data flag
+#endif
+   INTEGER ::   numsss         !: logical unit for surface salinity data
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      sss             !: surface salinity
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , IPSL-LODYC  (2005)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_dtasss
+   !!----------------------------------------------------------------------
+   !!   'key_dtasss'                                               SSS data
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_sss( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_sss  ***
+      !!                    
+      !! ** Purpose :   Read surface salinity data 
+      !!
+      !! ** Method  : - Read a specific sss.
+      !!
+      !! ** Action  : - sss 
+      !!
+      !! History :
+      !!        !  90-03  (O. Marti and Ph Dandin)  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  96-11  (E. Guilyardi)  Daily AGCM input files
+      !!        !  00-04  (M. Imbard)  NetCDF FORMAT
+      !!        !  00-10  (J.-P. Boulanger)  passage ORCA a TDH
+      !!        !  01-10  (A. Lazar)  Reynolds default
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!        !  02-11  (C. Levy)  MPP/MPI NetCDF read
+      !!        !  05-03  (M. Levy) adapt SST to SSS
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+      
+      !! * Arguments
+      INTEGER ::   kt
+
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dta_sss : yearly mean sea surface salinity data'
+
+         CALL iom_open ( 'sss.nc', numsss ) 
+         CALL iom_get ( numsss, jpdom_data, 'sss', sss, 1 )
+         CALL iom_close ( numsss )
+
+         sss(:,:) = sss(:,:)*tmask(:,:,1)
+
+         IF( lwp ) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' read  sea surface salinity ok'
+            WRITE(numout,*) ' '
+            CALL prihre(sss(:,:),jpi,jpj,1,jpi,20,1,jpj,10,1.,numout)
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE dta_sss
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                        NO SSS data
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_sss( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_sss  ***
+      !!                    
+      !! ** Purpose :   sea surface salinity data and update it
+      !!     at each time step.   ???
+      !!
+      !! ** Method  : - sss  
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean timestep
+      !!---------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dta_sss : No SSS data'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      
+   END SUBROUTINE dta_sss
+#endif
+
+   !!======================================================================
+END MODULE dtasss
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtasst.F90	(revision 4536)
@@ -0,0 +1,196 @@
+MODULE dtasst
+   !!======================================================================
+   !!                       ***  MODULE  dtasst  ***
+   !! Data : Sea Surface Temperature (SST)
+   
+   !!      BUG initialisation  nyearsst !!!!!!bug
+   
+   !!======================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   dta_sst      : Reynolds sst data
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE ocfzpt          ! ???
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Shared routine
+   PUBLIC dta_sst
+
+   !! * Shared module variables
+#if defined key_dtasst
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasst = .TRUE.   !: sst data flag
+   INTEGER ::   &
+        numsst ,      &              !: logical unit for surface temperature data
+        ndaysst                      !: new day for Reynolds sst
+   CHARACTER (len=34) :: clname      !: filename for daily SST
+#else
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtasst = .FALSE.  !: sst data flag
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      sst             !: surface temperature
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,2) ::   &  !:
+      rclice          !: climatological ice index (0/1) (2 months)
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_dtasst
+   !!----------------------------------------------------------------------
+   !!   'key_dtasst'                                               SST data
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_sst( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_sst  ***
+      !!                    
+      !! ** Purpose :   Read Reynolds weekly mean sea surface temperature 
+      !!      data and update it at each time step.
+      !!
+      !! ** Method  : - Read a specific REYNOLDS daily sst in Celcius.
+      !!              -  Compute a climatological ice cover rclice (0 or 1)
+      !!
+      !! ** Action  : - sst (Celcius)
+      !!              - rclice, ice/ocean mask (0 or 1)
+      !!
+      !! History :
+      !!        !  90-03  (O. Marti and Ph Dandin)  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  96-11  (E. Guilyardi)  Daily AGCM input files
+      !!        !  00-04  (M. Imbard)  NetCDF FORMAT
+      !!        !  00-10  (J.-P. Boulanger)  passage ORCA a TDH
+      !!        !  01-10  (A. Lazar)  Reynolds default
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!        !  02-11  (C. Levy)  MPP/MPI NetCDF read
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+      
+      !! * Arguments
+      INTEGER ::   kt
+
+      !! * Local save
+
+      !! * Local declarations
+      INTEGER ::   ji, jj
+      !!----------------------------------------------------------------------
+
+      ! -------------------- !
+      ! First call kt=nit000 !
+      ! -------------------- !
+
+      IF( kt == nit000 ) THEN
+
+         ndaysst = 0   ! initializations
+         IF(lwp) WRITE(numout,*) 'dta_sst : DAILY sea surface temperature data'
+         CALL iom_open ( 'sst_1d.nc', numsst ) 
+
+      ENDIF
+
+      ! ----------------- !
+      ! Read daily file   !
+      ! ----------------- !
+
+      ! Read daily SST 
+
+      IF( ndaysst /= nday ) THEN 
+         ndaysst = nday
+
+         CALL iom_get ( numsst, jpdom_data, 'sst', sst, nday_year )
+
+         IF ( kt == nit000 .AND. lwp ) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' read daily sea surface temperature ok'
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' Surface temp day: ', ndastp
+            CALL prihre(sst(:,:),jpi,jpj,1,jpi,20,1,jpj,10,1.,numout)
+         ENDIF
+         
+      ENDIF
+      
+      ! 2. At every time step compute temperature data
+      ! ----------------------------------------------
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ztgel = fzptn(ji,jj)
+            rclice(ji,jj,1) = tmask(ji,jj,1)
+            IF( sst(ji,jj) >= ztgel )   rclice(ji,jj,1) = 0.e0
+            rclice(ji,jj,2) = rclice(ji,jj,1)
+         END DO
+      END DO
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'Computed Ice cover rclice'
+         WRITE(numout,*)
+         WRITE(numout,*) 'Ice cover : '
+         CALL prihre( rclice(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+      ENDIF
+      
+      ! Close the file
+      ! --------------
+      
+      IF( kt == nitend )   CALL iom_close (numsst)
+      
+
+   END SUBROUTINE dta_sst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                        NO SST data
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_sst( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dta_sst  ***
+      !!                    
+      !! ** Purpose :   sea surface temperature data and update it
+      !!     at each time step.   ???
+      !!
+      !! ** Method  : - sst   = tn
+      !!              - rclice = 1. IF tn =< ztgel
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean timestep
+      
+      !! * Local declarations
+      INTEGER :: ji, jj
+      !!---------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dta_sst : No SST data'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      
+      ! 1. Update at each time step
+      ! ---------------------------
+
+      sst   (:,:)   = tn   (:,:,1)
+      rclice(:,:,1) = tmask(:,:,1)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( tn(ji,jj,1) >= fzptn(ji,jj) ) rclice(ji,jj,1) = 0.e0
+         END DO
+      END DO
+      rclice(:,:,2) = rclice(:,:,1)
+      
+   END SUBROUTINE dta_sst
+#endif
+
+   !!======================================================================
+END MODULE dtasst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtatem.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtatem.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DTA/dtatem.F90	(revision 4536)
@@ -0,0 +1,343 @@
+MODULE dtatem
+   !!======================================================================
+   !!                     ***  MODULE  dtatem  ***
+   !! Ocean data  :  read ocean temperature data from monthly atlas data
+   !!=====================================================================
+#if defined key_dtatem   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dtatem'                              3D temperature data field
+   !!----------------------------------------------------------------------
+   !!   dta_tem      : read ocean temperature data
+   !!---l-------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE daymod          ! calendar
+#if defined key_orca_lev10
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+#endif
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dta_tem   ! called by step.F90 and inidta.F90
+
+   !! * Shared module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtatem = .TRUE.   !: temperature data flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      t_dta             !: temperature data at given time-step
+
+   !! * Module variables
+   INTEGER ::   &
+      numtdt,        &  !: logical unit for data temperature
+      ntem1, ntem2  ! first and second record used
+   REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   &
+      temdta            ! temperature data at two consecutive times
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   !!----------------------------------------------------------------------
+   !!   Default case                                            NetCDF file
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dta_tem( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dta_tem  ***
+      !!                    
+      !! ** Purpose :   Reads monthly temperature data 
+      !! 
+      !! ** Method  :   Read on unit numtdt the interpolated temperature 
+      !!      onto the model grid.
+      !!      Data begin at january. 
+      !!      The value is centered at the middle of month.
+      !!      In the opa model, kt=1 agree with january 1.
+      !!      At each time step, a linear interpolation is applied between 
+      !!      two monthly values.
+      !!      Read on unit numtdt
+      !!
+      !! ** Action  :   define t_dta array at time-step kt
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  99-10  (M.A. Foujols, M. Imbard)  NetCDF FORMAT 
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jl, jk, jkk       ! dummy loop indicies
+      INTEGER ::   &
+         imois, iman, i15 , ik      ! temporary integers
+#  if defined key_tradmp
+      INTEGER ::   &
+         il0, il1, ii0, ii1, ij0, ij1   ! temporary integers
+# endif
+      REAL(wp) ::   zxy, zl
+#if defined key_orca_lev10
+      REAL(wp), DIMENSION(jpi,jpj,jpkdta,2) :: ztem
+      INTEGER   :: ikr, ikw, ikt, jjk 
+      REAL(wp)  :: zfac
+#endif
+      REAL(wp), DIMENSION(jpk,2) ::   &
+         ztemdta            ! auxiliary array for interpolation
+      !!----------------------------------------------------------------------
+      
+      ! 0. Initialization
+      ! -----------------
+      
+      iman  = INT( raamo )
+!!! better but change the results     i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+      i15   = nday / 16
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+      
+      ! 1. First call kt=nit000
+      ! -----------------------
+      
+      IF( kt == nit000 ) THEN
+         
+         ntem1= 0   ! initializations
+         IF(lwp) WRITE(numout,*) ' dta_tem : Levitus monthly fields'
+         CALL iom_open ( 'data_1m_potential_temperature_nomask', numtdt ) 
+         
+      ENDIF
+      
+      
+      ! 2. Read monthly file
+      ! -------------------
+      
+      IF( kt == nit000 .OR. imois /= ntem1 ) THEN
+         
+         ! Calendar computation
+         
+         ntem1 = imois        ! first file record used 
+         ntem2 = ntem1 + 1    ! last  file record used
+         ntem1 = MOD( ntem1, iman )
+         IF( ntem1 == 0 )   ntem1 = iman
+         ntem2 = MOD( ntem2, iman )
+         IF( ntem2 == 0 )   ntem2 = iman
+         IF(lwp) WRITE(numout,*) 'first record file used ntem1 ', ntem1
+         IF(lwp) WRITE(numout,*) 'last  record file used ntem2 ', ntem2
+         
+         ! Read monthly temperature data Levitus 
+         
+#if defined key_orca_lev10
+         if (ln_zps) stop
+         ztem(:,:,:,:) = 0.
+         CALL iom_get (numtdt,jpdom_data,'votemper',ztem(:,:,:,1),ntem1)
+         CALL iom_get (numtdt,jpdom_data,'votemper',ztem(:,:,:,2),ntem2)
+#else         
+         CALL iom_get (numtdt,jpdom_data,'votemper',temdta(:,:,:,1),ntem1)
+         CALL iom_get (numtdt,jpdom_data,'votemper',temdta(:,:,:,2),ntem2)
+#endif
+         
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' read Levitus temperature ok'
+         IF(lwp) WRITE(numout,*)
+         
+#if defined key_tradmp
+         IF( cp_cfg == "orca"  .AND. jp_cfg == 2 ) THEN
+            
+            !                                        ! =======================
+            !                                        !  ORCA_R2 configuration
+            !                                        ! ======================= 
+            
+            ij0 = 101   ;   ij1 = 109
+            ii0 = 141   ;   ii1 = 155
+            DO jj = mj0(ij0), mj1(ij1)                      ! Reduced temperature in the Alboran Sea
+               DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                  ztem(  ji,jj, 13:13 ,:) = ztem  (ji,jj, 13:13 ,:) - 0.20
+                  ztem  (ji,jj, 14:15 ,:) = ztem  (ji,jj, 14:15 ,:) - 0.35
+                  ztem  (ji,jj, 16:25 ,:) = ztem  (ji,jj, 16:25 ,:) - 0.40
+#else
+                  temdta(ji,jj, 13:13 ,:) = temdta(ji,jj, 13:13 ,:) - 0.20
+                  temdta(ji,jj, 14:15 ,:) = temdta(ji,jj, 14:15 ,:) - 0.35
+                  temdta(ji,jj, 16:25 ,:) = temdta(ji,jj, 16:25 ,:) - 0.40
+#endif
+               END DO
+            END DO
+            
+            IF( n_cla == 0 ) THEN 
+               !                                         ! Reduced temperature at Red Sea
+               ij0 =  87   ;   ij1 =  96
+               ii0 = 148   ;   ii1 = 160
+#if defined key_orca_lev10
+               ztem  ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 , : ) = 7.0 
+               ztem  ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 , : ) = 6.5 
+               ztem  ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 , : ) = 6.0
+#else
+               temdta( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ,  4:10 , : ) = 7.0 
+               temdta( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 11:13 , : ) = 6.5 
+               temdta( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 14:20 , : ) = 6.0
+#endif
+            ELSE
+               il0 = 138   ;   il1 = 138
+               ij0 = 101   ;   ij1 = 102
+               ii0 = 139   ;   ii1 = 139
+               DO jl = mi0(il0), mi1(il1)                ! New temperature profile at Gibraltar
+                  DO jj = mj0(ij0), mj1(ij1)
+                     DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                        ztem  (ji,jj,:,:) = ztem  (jl,jj,:,:)
+#else
+                        temdta(ji,jj,:,:) = temdta(jl,jj,:,:)
+#endif
+                     END DO
+                  END DO
+               END DO
+               il0 = 164   ;   il1 = 164
+               ij0 =  88   ;   ij1 =  88
+               ii0 = 161   ;   ii1 = 163
+               DO jl = mi0(il0), mi1(il1)                ! New temperature profile at Bab el Mandeb
+                  DO jj = mj0(ij0), mj1(ij1)
+                     DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                        ztem  (ji,jj,:,:) = ztem  (jl,jj,:,:)
+#else
+                        temdta(ji,jj,:,:) = temdta(jl,jj,:,:)
+#endif
+                     END DO
+                  END DO
+                  ij0 =  87   ;   ij1 =  87
+                  DO jj = mj0(ij0), mj1(ij1)
+                     DO ji = mi0(ii0), mi1(ii1)
+#if defined key_orca_lev10
+                        ztem  (ji,jj,:,:) = ztem  (jl,jj,:,:)
+#else
+                        temdta(ji,jj,:,:) = temdta(jl,jj,:,:)
+#endif
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+            
+         ENDIF
+#endif
+         
+#if defined key_orca_lev10
+         ! interpolate from 31 to 301 level the ztem field result in temdta
+         DO jl = 1, 2
+            DO jjk = 1, 5
+               temdta(:,:,jjk,jl) = ztem(:,:,1,jl)
+            END DO
+            DO jk = 1, jpk-20,10
+               ik = jk+5
+               ikr =  INT(jk/10) + 1
+               ikw =  (ikr-1) *10 + 1
+               ikt =  ikw + 5
+               DO jjk=ikt,ikt+9
+                  zfac = ( gdept_0(jjk   ) - gdepw_0(ikt) ) / ( gdepw_0(ikt+10) - gdepw_0(ikt) )
+                  temdta(:,:,jjk,jl) = ztem(:,:,ikr,jl) + ( ztem(:,:,ikr+1,jl) - ztem(:,:,ikr,jl) ) * zfac
+               END DO
+            END DO
+            DO jjk = jpk-5, jpk
+               temdta(:,:,jjk,jl) = ztem(:,:,jpkdta-1,jl)
+            END DO
+            ! fill the overlap areas
+            CALL lbc_lnk (temdta(:,:,:,jl),'Z',-999.,'no0')
+         END DO
+#endif
+         
+         IF( ln_sco ) THEN
+            DO jl = 1, 2
+               DO jj = 1, jpj                  ! interpolation of temperatures
+                  DO ji = 1, jpi
+                     DO jk = 1, jpk
+                        zl=fsdept(ji,jj,jk)
+                        IF(zl < gdept_0(1)) ztemdta(jk,jl) =  temdta(ji,jj,1,jl)
+                        IF(zl > gdept_0(jpk)) ztemdta(jk,jl) =  temdta(ji,jj,jpkm1,jl)
+                        DO jkk = 1, jpkm1
+                           IF((zl-gdept_0(jkk))*(zl-gdept_0(jkk+1)).le.0.0) THEN
+                              ztemdta(jk,jl) = temdta(ji,jj,jkk,jl)                                 &
+                                   &           + (zl-gdept_0(jkk))/(gdept_0(jkk+1)-gdept_0(jkk))      &
+                                   &                              *(temdta(ji,jj,jkk+1,jl) - temdta(ji,jj,jkk,jl))
+                           ENDIF
+                        END DO
+                     END DO
+                     DO jk = 1, jpkm1
+                        temdta(ji,jj,jk,jl) = ztemdta(jk,jl)
+                     END DO
+                     temdta(ji,jj,jpk,jl) = 0.0
+                  END DO
+               END DO
+            END DO
+            
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' Levitus temperature data interpolated to s-coordinate'
+            IF(lwp) WRITE(numout,*)
+            
+         ELSE
+            
+            !                                  ! Mask
+            DO jl = 1, 2
+               temdta(:,:,:,jl) = temdta(:,:,:,jl) * tmask(:,:,:)
+               temdta(:,:,jpk,jl) = 0.
+               IF( ln_zps ) THEN                ! z-coord. with partial steps
+                  DO jj = 1, jpj                  ! interpolation of temperature at the last level
+                     DO ji = 1, jpi
+                        ik = mbathy(ji,jj) - 1
+                        IF( ik > 2 ) THEN
+                           zl = ( gdept_0(ik) - fsdept(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                           temdta(ji,jj,ik,jl) = (1.-zl) * temdta(ji,jj,ik,jl) + zl * temdta(ji,jj,ik-1,jl)
+                        ENDIF
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            
+         ENDIF
+         
+         IF(lwp) THEN
+            WRITE(numout,*) ' temperature Levitus month ', ntem1, ntem2
+            WRITE(numout,*)
+            WRITE(numout,*) ' Levitus month = ', ntem1, '  level = 1'
+            CALL prihre( temdta(:,:,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            WRITE(numout,*) ' Levitus month = ', ntem1, '  level = ', jpk/2
+            CALL prihre( temdta(:,:,jpk/2,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            WRITE(numout,*) ' Levitus month = ',ntem1,'  level = ', jpkm1
+            CALL prihre( temdta(:,:,jpkm1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+         ENDIF
+      ENDIF
+      
+      
+      ! 2. At every time step compute temperature data
+      ! ----------------------------------------------
+      
+      zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
+      t_dta(:,:,:) = (1.-zxy) * temdta(:,:,:,1) + zxy * temdta(:,:,:,2)
+      
+      ! Close the file
+      ! --------------
+      
+      IF( kt == nitend )   CALL iom_close (numtdt)
+      
+    END SUBROUTINE dta_tem
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case                           NO 3D temperature data field
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_dtatem = .FALSE.   !: temperature data flag
+CONTAINS
+   SUBROUTINE dta_tem( kt )        ! Empty routine
+      WRITE(*,*) 'dta_tem: You should not have seen this print! error?', kt
+   END SUBROUTINE dta_tem
+#endif
+   !!======================================================================
+END MODULE dtatem
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/divcur.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/divcur.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/divcur.F90	(revision 4536)
@@ -0,0 +1,349 @@
+MODULE divcur
+   !!==============================================================================
+   !!                       ***  MODULE  divcur  ***
+   !! Ocean diagnostic variable : horizontal divergence and relative vorticity
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   div_cur    : Compute the horizontal divergence and relative
+   !!                vorticity fields
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE obc_oce         ! ocean lateral open boundary condition
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC div_cur    ! routine called by step.F90 and istate.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_noslip_accurate
+   !!----------------------------------------------------------------------
+   !!   'key_noslip_accurate'                     2nd order centered scheme
+   !!                                                4th order at the coast
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE div_cur( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur  ***
+      !!
+      !! ** Purpose :   compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method  : 
+      !!      I.  divergence :
+      !!         - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!         - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the
+      !!      above expression
+      !!         - apply lateral boundary conditions on hdivn 
+      !!      II. vorticity :
+      !!         - save the curl computed at the previous time-step
+      !!            rotb = rotn
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!         - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!         - apply lateral boundary conditions on rotn through a call
+      !!      of lbc_lnk routine.
+      !!         - Coastal boundary condition: 'key_noslip_accurate' defined,
+      !!      the no-slip boundary condition is computed using Schchepetkin
+      !!      and O'Brien (1996) scheme (i.e. 4th order at the coast).
+      !!      For example, along east coast, the one-sided finite difference
+      !!      approximation used for di[v] is:
+      !!         di[e2v vn] =  1/(e1f*e2f)
+      !!                    * ( (e2v vn)(i) + (e2v vn)(i-1) + (e2v vn)(i-2) )
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History :
+      !!   8.2  !  00-03  (G. Madec)  no slip accurate
+      !!   9.0  !  03-08  (G. Madec)  merged of cur and div, free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   ii, ij, jl     ! temporary integer
+      INTEGER ::   ijt, iju       ! temporary integer
+      REAL(wp) ::   zdiv, zdju
+      REAL(wp), DIMENSION(   jpi  ,1:jpj+2) ::   zwu   ! workspace
+      REAL(wp), DIMENSION(-1:jpi+2,  jpj  ) ::   zwv   ! workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur : horizontal velocity divergence and relative vorticity'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   NOT optimal for auto-tasking case'
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         hdivb(:,:,jk) = hdivn(:,:,jk)    ! time swap of div arrays
+         rotb (:,:,jk) = rotn (:,:,jk)    ! time swap of rot arrays
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div
+         !                                             ! --------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               hdivn(ji,jj,jk) = (  e2u(ji,jj) * un(ji,jj,jk) - e2u(ji-1,jj  ) * un(ji-1,jj  ,jk)      &
+                  &               + e1v(ji,jj) * vn(ji,jj,jk) - e1v(ji  ,jj-1) * vn(ji  ,jj-1,jk)  )   &
+                  &            / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               hdivn(ji,jj,jk) =   &
+                  (  e2u(ji,jj)*fse3u(ji,jj,jk) * un(ji,jj,jk) - e2u(ji-1,jj  )*fse3u(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)       &
+                   + e1v(ji,jj)*fse3v(ji,jj,jk) * vn(ji,jj,jk) - e1v(ji  ,jj-1)*fse3v(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  )    &
+                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO
+         END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
+         IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
+         IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
+         IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
+#endif         
+
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+         ! contravariant velocity (extended for lateral b.c.)
+         ! inside the model domain
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwu(ji,jj) = e1u(ji,jj) * un(ji,jj,jk)
+               zwv(ji,jj) = e2v(ji,jj) * vn(ji,jj,jk)
+            END DO  
+         END DO  
+ 
+         ! East-West boundary conditions
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+            zwv(  0  ,:) = zwv(jpi-2,:)
+            zwv( -1  ,:) = zwv(jpi-3,:)
+            zwv(jpi+1,:) = zwv(  3  ,:)
+            zwv(jpi+2,:) = zwv(  4  ,:)
+         ELSE
+            zwv(  0  ,:) = 0.e0
+            zwv( -1  ,:) = 0.e0
+            zwv(jpi+1,:) = 0.e0
+            zwv(jpi+2,:) = 0.e0
+         ENDIF
+
+         ! North-South boundary conditions
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            ! north fold ( Grid defined with a T-point pivot) ORCA 2 degre
+            zwu(jpi,jpj+1) = 0.e0
+            zwu(jpi,jpj+2) = 0.e0
+            DO ji = 1, jpi-1
+               iju = jpi - ji + 1
+               zwu(ji,jpj+1) = - zwu(iju,jpj-3)
+               zwu(ji,jpj+2) = - zwu(iju,jpj-4)
+            END DO
+         ELSEIF( nperio == 5 .OR. nperio == 6 ) THEN
+            ! north fold ( Grid defined with a F-point pivot) ORCA 0.5 degre\
+            zwu(jpi,jpj+1) = 0.e0
+            zwu(jpi,jpj+2) = 0.e0
+            DO ji = 1, jpi-1
+               iju = jpi - ji
+               zwu(ji,jpj  ) = - zwu(iju,jpj-1)
+               zwu(ji,jpj+1) = - zwu(iju,jpj-2)
+               zwu(ji,jpj+2) = - zwu(iju,jpj-3)
+            END DO
+            DO ji = -1, jpi+2
+               ijt = jpi - ji + 1
+               zwv(ji,jpj) = - zwv(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi+2
+               ijt = jpi - ji + 1
+               zwv(ji,jpjm1) = - zwv(ijt,jpjm1)
+            END DO
+         ELSE
+            ! closed
+            zwu(:,jpj+1) = 0.e0
+            zwu(:,jpj+2) = 0.e0
+         ENDIF
+
+         ! relative vorticity (vertical component of the velocity curl) 
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               rotn(ji,jj,jk) = (  zwv(ji+1,jj  ) - zwv(ji,jj)      &
+                                 - zwu(ji  ,jj+1) + zwu(ji,jj)  )   &
+                              * fmask(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
+            END DO
+         END DO
+
+         ! second order accurate scheme along straight coast
+         DO jl = 1, npcoa(1,jk)
+            ii = nicoa(jl,1,jk)
+            ij = njcoa(jl,1,jk)
+            rotn(ii,ij,jk) = 1. / ( e1f(ii,ij) * e2f(ii,ij) )   &
+                           * ( + 4. * zwv(ii+1,ij) - zwv(ii+2,ij) + 0.2 * zwv(ii+3,ij) )
+         END DO
+         DO jl = 1, npcoa(2,jk)
+            ii = nicoa(jl,2,jk)
+            ij = njcoa(jl,2,jk)
+            rotn(ii,ij,jk) = 1./(e1f(ii,ij)*e2f(ii,ij))   &
+               *(-4.*zwv(ii,ij)+zwv(ii-1,ij)-0.2*zwv(ii-2,ij))
+         END DO
+         DO jl = 1, npcoa(3,jk)
+            ii = nicoa(jl,3,jk)
+            ij = njcoa(jl,3,jk)
+            rotn(ii,ij,jk) = -1. / ( e1f(ii,ij)*e2f(ii,ij) )   &
+               * ( +4. * zwu(ii,ij+1) - zwu(ii,ij+2) + 0.2 * zwu(ii,ij+3) )
+         END DO
+         DO jl = 1, npcoa(4,jk)
+            ii = nicoa(jl,4,jk)
+            ij = njcoa(jl,4,jk)
+            rotn(ii,ij,jk) = -1. / ( e1f(ii,ij)*e2f(ii,ij) )   &
+               * ( -4. * zwu(ii,ij) + zwu(ii,ij-1) - 0.2 * zwu(ii,ij-2) )
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk( hdivn, 'T', 1. )     ! T-point, no sign change
+      CALL lbc_lnk( rotn , 'F', 1. )     ! F-point, no sign change
+
+   END SUBROUTINE div_cur
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                           2nd order centered schemes
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE div_cur( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE div_cur  ***
+      !!                    
+      !! ** Purpose :   compute the horizontal divergence and the relative
+      !!      vorticity at before and now time-step
+      !!
+      !! ** Method  : - Divergence:
+      !!      - save the divergence computed at the previous time-step
+      !!      (note that the Asselin filter has not been applied on hdivb)
+      !!      - compute the now divergence given by :
+      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      Note: if lk_zco=T, e3u=e3v=e3t, they are simplified in the 
+      !!      above expression
+      !!      - apply lateral boundary conditions on hdivn 
+      !!              - Relavtive Vorticity :
+      !!      - save the curl computed at the previous time-step (rotb = rotn)
+      !!      (note that the Asselin time filter has not been applied to rotb)
+      !!      - compute the now curl in tensorial formalism:
+      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
+      !!      - apply lateral boundary conditions on rotn through a call to
+      !!      routine lbc_lnk routine.
+      !!      Note: Coastal boundary condition: lateral friction set through
+      !!      the value of fmask along the coast (see dommsk.F90) and shlat
+      !!      (namelist parameter)
+      !!
+      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
+      !!              - update rotb , rotn , the before & now rel. vorticity
+      !!
+      !! History :
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!   4.0  !  91-11  (G. Madec)
+      !!   6.0  !  93-03  (M. Guyon)  symetrical conditions
+      !!   7.0  !  96-01  (G. Madec)  s-coordinates
+      !!   8.0  !  97-06  (G. Madec)  lateral boundary cond., lbc
+      !!   8.1  !  97-08  (J.M. Molines)  Open boundaries
+      !!   9.0  !  02-09  (G. Madec, E. Durand)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'div_cur : horizontal velocity divergence and'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   relative vorticity'
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         hdivb(:,:,jk) = hdivn(:,:,jk)    ! time swap of div arrays
+         rotb (:,:,jk) = rotn (:,:,jk)    ! time swap of rot arrays
+
+         !                                             ! --------
+         ! Horizontal divergence                       !   div 
+         !                                             ! --------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               hdivn(ji,jj,jk) = (  e2u(ji,jj) * un(ji,jj,jk) - e2u(ji-1,jj  ) * un(ji-1,jj  ,jk)      &
+                  &               + e1v(ji,jj) * vn(ji,jj,jk) - e1v(ji  ,jj-1) * vn(ji  ,jj-1,jk)  )   & 
+                  / ( e1t(ji,jj) * e2t(ji,jj) )
+#else
+               hdivn(ji,jj,jk) =   &
+                  (  e2u(ji,jj)*fse3u(ji,jj,jk) * un(ji,jj,jk) - e2u(ji-1,jj  )*fse3u(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)       &
+                   + e1v(ji,jj)*fse3v(ji,jj,jk) * vn(ji,jj,jk) - e1v(ji  ,jj-1)*fse3v(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  )    &
+                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+#endif
+            END DO  
+         END DO  
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
+         IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
+         IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
+         IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
+#endif         
+         !                                             ! --------
+         ! relative vorticity                          !   rot 
+         !                                             ! --------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               rotn(ji,jj,jk) = (  e2v(ji+1,jj  ) * vn(ji+1,jj  ,jk) - e2v(ji,jj) * vn(ji,jj,jk)    &
+                  &              - e1u(ji  ,jj+1) * un(ji  ,jj+1,jk) + e1u(ji,jj) * un(ji,jj,jk)  ) &
+                  &           * fmask(ji,jj,jk) / ( e1f(ji,jj) * e2f(ji,jj) )
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      
+      ! 4. Lateral boundary conditions on hdivn and rotn
+      ! ---------------------------------=======---======
+      CALL lbc_lnk( hdivn, 'T', 1. )       ! T-point, no sign change
+      CALL lbc_lnk( rotn , 'F', 1. )       ! F-point, no sign change
+
+   END SUBROUTINE div_cur
+   
+#endif
+   !!======================================================================
+END MODULE divcur
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 4536)
@@ -0,0 +1,129 @@
+MODULE dynadv
+   !!==============================================================================
+   !!                       ***  MODULE  dynadv  ***
+   !! Ocean active tracers:  advection scheme control
+   !!==============================================================================
+   !! History :  9.0  !  06-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_adv      : compute the momentum advection trend 
+   !!   dyn_adv_ctl  : control the different options of advection scheme
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+
+   USE dynadv_cen2     ! centred flux form advection      (dyn_adv_cen2 routine)
+   USE dynadv_ubs      ! UBS flux form advection          (dyn_adv_ubs  routine)
+   USE dynkeg          ! kinetic energy gradient          (dyn_keg      routine)
+   USE dynzad          ! vertical advection               (dyn_zad      routine)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_adv     ! routine called by step module
+ 
+   LOGICAL, PUBLIC ::   ln_dynadv_vec  = .TRUE.    ! vector form flag
+   LOGICAL, PUBLIC ::   ln_dynadv_cen2 = .FALSE.   ! flux form - 2nd order centered scheme flag
+   LOGICAL, PUBLIC ::   ln_dynadv_ubs  = .FALSE.   ! flux form - 3rd order UBS scheme flag
+   
+   INTEGER ::   nadv   ! choice of the formulation and scheme for the advection
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_adv( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv  ***
+      !!                
+      !! ** Purpose :   compute the ocean momentum advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
+      !!      a metric term is add to the coriolis term while in vector form 
+      !!      it is the relative vorticity which is added to coriolis term
+      !!      (see dynvor module).
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )   CALL dyn_adv_ctl          ! initialisation & control of options
+
+      SELECT CASE ( nadv )                     ! compute advection trend and add it to general trend
+      CASE ( 0 )     
+                      CALL dyn_keg     ( kt )    ! vector form : horizontal gradient of kinetic energy
+                      CALL dyn_zad     ( kt )    ! vector form : vertical advection
+      CASE ( 1 ) 
+                      CALL dyn_adv_cen2( kt )    ! 2nd order centered scheme
+      CASE ( 2 )   
+                      CALL dyn_adv_ubs ( kt )    ! 3rd order UBS      scheme
+      !
+      CASE (-1 )                                 ! esopa: test all possibility with control print
+                      CALL dyn_keg     ( kt )
+                      CALL dyn_zad     ( kt )
+                      CALL dyn_adv_cen2( kt )
+                      CALL dyn_adv_ubs ( kt )
+      END SELECT
+      !
+   END SUBROUTINE dyn_adv
+
+   
+   SUBROUTINE dyn_adv_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              momentum advection formulation & scheme and set nadv
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+
+      NAMELIST/nam_dynadv/ ln_dynadv_vec, ln_dynadv_cen2 , ln_dynadv_ubs
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_dynadv : momentum advection scheme
+      READ   ( numnam, nam_dynadv )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_adv_ctl : choice/control of the momentum advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_dynadv : chose a advection formulation & scheme for momentum'
+         WRITE(numout,*) '          Vector/flux form (T/F)             ln_dynadv_vec  = ', ln_dynadv_vec
+         WRITE(numout,*) '          2nd order centred advection scheme ln_dynadv_cen2 = ', ln_dynadv_cen2
+         WRITE(numout,*) '          3rd order UBS advection scheme     ln_dynadv_ubs  = ', ln_dynadv_ubs
+      ENDIF
+
+      ioptio = 0                      ! Parameter control
+      IF( ln_dynadv_vec  )   ioptio = ioptio + 1
+      IF( ln_dynadv_cen2 )   ioptio = ioptio + 1
+      IF( ln_dynadv_ubs  )   ioptio = ioptio + 1
+      IF( lk_esopa       )   ioptio =          1
+
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist nam_dynadv' )
+
+      !                               ! Set nadv
+      IF( ln_dynadv_vec  )   nadv =  0 
+      IF( ln_dynadv_cen2 )   nadv =  1
+      IF( ln_dynadv_ubs  )   nadv =  2
+      IF( lk_esopa       )   nadv = -1
+
+      IF(lwp) THEN                    ! Print the choice
+         WRITE(numout,*)
+         IF( nadv ==  0 )   WRITE(numout,*) '         vector form : keg + zad + vor is used'
+         IF( nadv ==  1 )   WRITE(numout,*) '         flux form   : 2nd order scheme is used'
+         IF( nadv ==  2 )   WRITE(numout,*) '         flux form   : UBS       scheme is used'
+         IF( nadv == -1 )   WRITE(numout,*) '         esopa test: use all advection formulation'
+      ENDIF
+      !
+   END SUBROUTINE dyn_adv_ctl
+
+  !!======================================================================
+END MODULE dynadv
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 4536)
@@ -0,0 +1,162 @@
+MODULE dynadv_cen2
+   !!======================================================================
+   !!                       ***  MODULE  dynadv  ***
+   !! Ocean dynamics: Update the momentum trend with the flux form advection
+   !!                 using a 2nd order centred scheme
+   !!======================================================================
+   !! History :  9.0  !  06-08  (G. Madec, S. Theetten)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_adv_cen2       : flux form momentum advection (ln_dynadv_cen2=T)
+   !!                        trends using a 2nd order centred scheme  
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE dynspg_oce     ! surface pressure gradient
+   USE in_out_manager ! I/O manager
+   USE dynspg_rl     ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_adv_cen2                        ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LODYC-IPSL  (2006)
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_adv_cen2( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_cen2  ***
+      !!
+      !! ** Purpose :   Compute the now momentum advection trend in flux form
+      !!      and the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (utrd,vtrd) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY:   zfu => ta,   & ! use ta as 3D workspace
+                       zfv => sa      ! use sa as 3D workspace
+
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      REAL(wp) ::   zua, zva, zbu, zbv      ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zfu_t, zfu_f, zfu_uw   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zfv_t, zfv_f, zfv_vw   !  "      "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zfw                    !  "      "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_adv_cen2 : 2nd order flux form momentum advection'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+
+      ! I. Horizontal advection
+      ! -----------------------
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! horizontal volume fluxes
+         zfu(:,:,jk) = 0.25 * e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = 0.25 * e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+
+         ! horizontal momentum fluxes at T- and F-point
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji+1,jj  ,jk) )
+               zfv_f(ji  ,jj  ,jk) = ( zfv(ji,jj,jk) + zfv(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji  ,jj+1,jk) )
+               zfu_f(ji  ,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) )
+               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) )
+            END DO
+         END DO
+
+         ! divergence of horizontal momentum fluxes
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               zbv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+               ! horizontal advective trends
+               zua = - (  zfu_t(ji+1,jj  ,jk) - zfu_t(ji  ,jj  ,jk)   &
+                  &     + zfv_f(ji  ,jj  ,jk) - zfv_f(ji  ,jj-1,jk)  ) / zbu
+               zva = - (  zfu_f(ji  ,jj  ,jk) - zfu_f(ji-1,jj  ,jk)   &
+                  &     + zfv_t(ji  ,jj+1,jk) - zfv_t(ji  ,jj  ,jk)  ) / zbv
+               ! add it to the general tracer trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+!!gm  momentum trend diagnostics is missing
+
+      ! II. Vertical advection
+      ! ----------------------
+
+      ! Second order centered tracer flux at w-point
+      DO jk = 1, jpkm1
+         ! Vertical volume fluxes                   
+         zfw(:,:,jk) = 0.25 * e1t(:,:) * e2t(:,:) * wn(:,:,jk)
+         ! Vertical advective fluxes                   
+         IF( jk == 1 ) THEN
+            zfu_uw(:,:,jpk) = 0.e0         ! Bottom value : flux set to zero
+            zfv_vw(:,:,jpk) = 0.e0
+            !                              ! Surface value
+            IF( lk_dynspg_rl ) THEN             ! rigid lid : flux set to zero
+               zfu_uw(:,:, 1 ) = 0.e0    
+               zfv_vw(:,:, 1 ) = 0.e0
+            ELSE                                ! free surface-constant volume
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zfu_uw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji+1,jj  ,1) ) * un(ji,jj,1)
+                     zfv_vw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji  ,jj+1,1) ) * vn(ji,jj,1)
+                  END DO
+               END DO
+            ENDIF
+         ELSE
+            !                              ! interior fluxes
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
+                  zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
+               END DO
+            END DO
+         ENDIF
+      END DO
+
+      ! momentum flux divergence at u-, v-points added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zua = - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) )    &
+                  &  / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zva = - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) )    &
+                  &  / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               ! add it to the general tracer trends
+               ua(ji,jj,jk) =  ua(ji,jj,jk) + zua
+               va(ji,jj,jk) =  va(ji,jj,jk) + zva
+            END DO
+         END DO
+      END DO
+!!gm  momentum trend diagnostics is missing
+
+   END SUBROUTINE dyn_adv_cen2
+
+   !!==============================================================================
+END MODULE dynadv_cen2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 4536)
@@ -0,0 +1,253 @@
+MODULE dynadv_ubs
+   !!======================================================================
+   !!                       ***  MODULE  dynadv_ubs  ***
+   !! Ocean dynamics: Update the momentum trend with the flux form advection
+   !!                 trend using a 3rd order upstream biased scheme
+   !!======================================================================
+   !! History :  9.0  !  06-08  (R. Benshila, L. Debreu)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_adv_ubs   : flux form momentum advection using    (ln_dynadv=T)
+   !!                   an 3rd order Upstream Biased Scheme or Quick scheme
+   !!                   combined with 2nd or 4th order finite differences 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE dynspg_oce     ! surface pressure gradient
+   USE in_out_manager ! I/O manager
+   USE dynspg_rl      ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp), PARAMETER :: gamma1 = 1._wp/4._wp  ! =1/4 quick      ; =1/3  3rd order UBS
+   REAL(wp), PARAMETER :: gamma2 = 1._wp/8._wp  ! =0   2nd order  ; =1/8  4th order centred
+
+   !! * Routine accessibility
+   PUBLIC dyn_adv_ubs                            ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LODYC-IPSL  (2006)
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_adv_ubs( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_adv_ubs  ***
+      !!
+      !! ** Purpose :   Compute the now momentum advection trend in flux form
+      !!      and the general trend of the momentum equation.
+      !!
+      !! ** Method  :   The scheme is the one implemeted in ROMS. It depends 
+      !!      on two parameter gamma1 and gamma2. The former control the 
+      !!      upstream baised part of the scheme and the later the centred 
+      !!      part:     gamma1 = 0    pure centered  (no diffusive part)
+      !!                       = 1/4  Quick scheme
+      !!                       = 1/3  3rd order Upstream biased scheme
+      !!                gamma2 = 0    2nd order finite differencing 
+      !!                       = 1/8  4th order finite differencing
+      !!      For stability reasons, the first term of the fluxes which cor-
+      !!      responds to a second order centered scheme is evaluated using  
+      !!      the now velocity (centered in time) while the second term which  
+      !!      is the diffusive part of the scheme, is evaluated using the 
+      !!      before velocity (forward in time). 
+      !!      Default value (hard coded in the begining of the module) are 
+      !!      gamma1=1/4 and gamma2=1/8.
+      !!
+      !! ** Action : - update (ua,va) with the 3D advective momentum trends
+      !!
+      !! Reference : Shchepetkin & McWilliams, 2005, Ocean Modelling. 
+      !!----------------------------------------------------------------------
+      USE oce, ONLY:   zfu => ta,   & ! use ta as 3D workspace
+                       zfv => sa      ! use sa as 3D workspace
+
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+
+      INTEGER  ::   ji, jj, jk                      ! dummy loop indices
+      REAL(wp) ::   zua, zva, zbu, zbv              ! temporary scalars
+      REAL(wp) ::   zui, zvj, zfuj, zfvi, zl_u, zl_v! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zfu_t, zfu_f     ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zfv_t, zfv_f     !    "           "
+      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zfw, zfu_uw, zfv_vw
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   zlu_uu, zlu_uv   ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   zlv_vv, zlv_vu   ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_adv_ubs : UBS flux form momentum advection'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      zfu_t(:,:,:) = 0.e0
+      zfv_t(:,:,:) = 0.e0
+      zfu_f(:,:,:) = 0.e0
+      zfv_f(:,:,:) = 0.e0
+     
+      zlu_uu(:,:,:,:) = 0.e0 
+      zlv_vv(:,:,:,:) = 0.e0 
+      zlu_uv(:,:,:,:) = 0.e0 
+      zlv_vu(:,:,:,:) = 0.e0 
+
+      
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Laplacian
+         ! ---------
+         zfu(:,:,jk) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+            
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlu_uu(ji,jj,jk,1) = ( ub (ji+1,jj,jk)-2.*ub (ji,jj,jk)+ub (ji-1,jj,jk) ) * umask(ji,jj,jk)
+               zlv_vv(ji,jj,jk,1) = ( vb (ji,jj+1,jk)-2.*vb (ji,jj,jk)+vb (ji,jj-1,jk) ) * vmask(ji,jj,jk) 
+               zlu_uv(ji,jj,jk,1) = ( ub (ji,jj+1,jk)-2.*ub (ji,jj,jk)+ub (ji,jj-1,jk) ) * umask(ji,jj,jk)
+               zlv_vu(ji,jj,jk,1) = ( vb (ji+1,jj,jk)-2.*vb (ji,jj,jk)+vb (ji-1,jj,jk) ) * vmask(ji,jj,jk)
+               
+               zlu_uu(ji,jj,jk,2) = ( zfu(ji+1,jj,jk)-2.*zfu(ji,jj,jk)+zfu(ji-1,jj,jk) ) * umask(ji,jj,jk)
+               zlv_vv(ji,jj,jk,2) = ( zfv(ji,jj+1,jk)-2.*zfv(ji,jj,jk)+zfv(ji,jj-1,jk) ) * vmask(ji,jj,jk)
+               zlu_uv(ji,jj,jk,2) = ( zfu(ji,jj+1,jk)-2.*zfu(ji,jj,jk)+zfu(ji,jj-1,jk) ) * umask(ji,jj,jk)
+               zlv_vu(ji,jj,jk,2) = ( zfv(ji+1,jj,jk)-2.*zfv(ji,jj,jk)+zfv(ji-1,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      CALL lbc_lnk( zlu_uu(:,:,:,1), 'U', -1.) 
+      CALL lbc_lnk( zlu_uu(:,:,:,2), 'U', -1.) 
+      CALL lbc_lnk( zlv_vv(:,:,:,1), 'V', -1.) 
+      CALL lbc_lnk( zlv_vv(:,:,:,2), 'V', -1.) 
+
+      CALL lbc_lnk( zlu_uv(:,:,:,1), 'U', -1.) 
+      CALL lbc_lnk( zlu_uv(:,:,:,2), 'U', -1.) 
+      CALL lbc_lnk( zlv_vu(:,:,:,1), 'V', -1.) 
+      CALL lbc_lnk( zlv_vu(:,:,:,2), 'V', -1.) 
+
+      ! I. Horizontal advection
+      ! -----------------------
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! horizontal volume fluxes
+         zfu(:,:,jk) = 0.25 * e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zfv(:,:,jk) = 0.25 * e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+
+         ! horizontal momentum fluxes at T- and F-point
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zui = ( un(ji,jj,jk) + un(ji+1,jj  ,jk) )
+               zvj = ( vn(ji,jj,jk) + vn(ji  ,jj+1,jk) )
+
+               IF (zui > 0) THEN   ;   zl_u = zlu_uu(ji  ,jj,jk,1)
+               ELSE                ;   zl_u = zlu_uu(ji+1,jj,jk,1)
+               ENDIF
+               IF (zvj > 0) THEN   ;   zl_v = zlv_vv(ji,jj  ,jk,1)
+               ELSE                ;   zl_v = zlv_vv(ji,jj+1,jk,1)
+               ENDIF
+
+               zfu_t(ji+1,jj  ,jk) = ( zfu(ji,jj,jk) + zfu(ji+1,jj  ,jk)                               &
+                  &                    - gamma2 * ( zlu_uu(ji,jj,jk,2) + zlu_uu(ji+1,jj  ,jk,2) )  )   &
+                  &                * ( zui - gamma1 * zl_u)
+               zfv_t(ji  ,jj+1,jk) = ( zfv(ji,jj,jk) + zfv(ji  ,jj+1,jk)                               &
+                  &                    - gamma2 * ( zlv_vv(ji,jj,jk,2) + zlv_vv(ji  ,jj+1,jk,2) )  )   &
+                  &                * ( zvj - gamma1 * zl_v)
+
+               zfuj = ( zfu(ji,jj,jk) + zfu(ji  ,jj+1,jk) )
+               zfvi = ( zfv(ji,jj,jk) + zfv(ji+1,jj  ,jk) )
+               IF (zfuj > 0) THEN   ;    zl_v = zlv_vu( ji  ,jj  ,jk,1)
+               ELSE                 ;    zl_v = zlv_vu( ji+1,jj,jk,1)
+               ENDIF
+               IF (zfvi > 0) THEN   ;    zl_u = zlu_uv( ji,jj  ,jk,1)
+               ELSE                 ;    zl_u = zlu_uv( ji,jj+1,jk,1)
+               ENDIF
+
+               zfv_f(ji  ,jj  ,jk) = ( zfvi - gamma2 * ( zlv_vu(ji,jj,jk,2) + zlv_vu(ji+1,jj  ,jk,2) )  )   &
+                  &                * ( un(ji,jj,jk) + un(ji  ,jj+1,jk) - gamma1 * zl_u )
+               zfu_f(ji  ,jj  ,jk) = ( zfuj - gamma2 * ( zlu_uv(ji,jj,jk,2) + zlu_uv(ji  ,jj+1,jk,2) )  )   &
+                  &                * ( vn(ji,jj,jk) + vn(ji+1,jj  ,jk) - gamma1 * zl_v )
+            END DO
+         END DO
+
+         ! divergence of horizontal momentum fluxes
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               zbv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+               ! horizontal advective trends
+               zua = - (  zfu_t(ji+1,jj  ,jk) - zfu_t(ji  ,jj  ,jk)   &
+                  &     + zfv_f(ji  ,jj  ,jk) - zfv_f(ji  ,jj-1,jk)  ) / zbu
+               zva = - (  zfu_f(ji  ,jj  ,jk) - zfu_f(ji-1,jj  ,jk)   &
+                  &     + zfv_t(ji  ,jj+1,jk) - zfv_t(ji  ,jj  ,jk)  ) / zbv
+               ! add it to the general tracer trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+!!gm  momentum trend diagnostics is missing
+
+      ! II. Vertical advection
+      ! ----------------------
+
+      ! Second order centered tracer flux at w-point
+      DO jk = 1, jpkm1
+         ! Vertical volume fluxes                   
+         zfw(:,:,jk) = 0.25 * e1t(:,:) * e2t(:,:) * wn(:,:,jk)
+         ! Vertical advective fluxes                   
+         IF( jk == 1 ) THEN
+            zfu_uw(:,:,jpk) = 0.e0         ! Bottom value : flux set to zero
+            zfv_vw(:,:,jpk) = 0.e0
+            !                              ! Surface value
+            IF( lk_dynspg_rl ) THEN             ! rigid lid : flux set to zero
+               zfu_uw(:,:, 1 ) = 0.e0    
+               zfv_vw(:,:, 1 ) = 0.e0
+            ELSE                                ! free surface-constant volume
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zfu_uw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji+1,jj  ,1) ) * un(ji,jj,1)
+                     zfv_vw(ji,jj, 1 ) = 2.e0 * ( zfw(ji,jj,1) + zfw(ji  ,jj+1,1) ) * vn(ji,jj,1)
+                  END DO
+               END DO
+            ENDIF
+         ELSE
+            !                              ! interior fluxes
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zfu_uw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji+1,jj  ,jk) ) * ( un(ji,jj,jk) + un(ji,jj,jk-1) )
+                  zfv_vw(ji,jj,jk) = ( zfw(ji,jj,jk)+ zfw(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk) + vn(ji,jj,jk-1) )
+               END DO
+            END DO
+         ENDIF
+      END DO
+
+      ! momentum flux divergence at u-, v-points added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zua = - ( zfu_uw(ji,jj,jk) - zfu_uw(ji,jj,jk+1) )    &
+                  &  / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zva = - ( zfv_vw(ji,jj,jk) - zfv_vw(ji,jj,jk+1) )    &
+                  &  / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               ! add it to the general tracer trends
+               ua(ji,jj,jk) =  ua(ji,jj,jk) + zua
+               va(ji,jj,jk) =  va(ji,jj,jk) + zva
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_adv_ubs
+
+   !!==============================================================================
+END MODULE dynadv_ubs
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4536)
@@ -0,0 +1,1020 @@
+MODULE dynhpg
+   !!======================================================================
+   !!                       ***  MODULE  dynhpg  ***
+   !! Ocean dynamics:  hydrostatic pressure gradient trend
+   !!======================================================================
+   !! History :  1.0  !  87-09  (P. Andrich, M.-A. Foujols)  hpg_zco: Original code
+   !!            5.0  !  91-11  (G. Madec)
+   !!            7.0  !  96-01  (G. Madec)  hpg_sco: Original code for s-coordinates
+   !!            8.0  !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
+   !!            8.5  !  02-07  (G. Madec)  F90: Free form and module
+   !!            8.5  !  02-08  (A. Bozec)  hpg_zps: Original code
+   !!            9.0  !  05-10  (A. Beckmann, B.W. An)  various s-coordinate options
+   !!                           Original code for hpg_ctl, hpg_hel hpg_wdj, hpg_djc, hpg_rot 
+   !!            9.0  !  05-11  (G. Madec) style & small optimisation
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_hpg      : update the momentum trend with the now horizontal
+   !!                  gradient of the hydrostatic pressure
+   !!                  default case : k-j-i loops (vector opt. available)
+   !!       hpg_ctl  : initialisation and control of options
+   !!       hpg_zco  : z-coordinate scheme
+   !!       hpg_zps  : z-coordinate plus partial steps (interpolation)
+   !!       hpg_sco  : s-coordinate (standard jacobian formulation)
+   !!       hpg_hel  : s-coordinate (helsinki modification)
+   !!       hpg_wdj  : s-coordinate (weighted density jacobian)
+   !!       hpg_djc  : s-coordinate (Density Jacobian with Cubic polynomial)
+   !!       hpg_rot  : s-coordinate (ROTated axes scheme)
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE dynhpg_jki      !
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE prtctl          ! Print control
+   USE lbclnk          ! lateral boundary condition 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_hpg    ! routine called by step module
+
+#if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp' :                                 j-k-i loop (j-slab)
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynhpg_jki = .TRUE.    !: OpenMP hpg flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynhpg     = .FALSE.   !: vector hpg flag
+#else
+   !!----------------------------------------------------------------------
+   !!   default case :                             k-j-i loop (vector opt.)
+   !!----------------------------------------------------------------------   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynhpg_jki = .FALSE.   !: OpenMP hpg flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynhpg     = .TRUE.    !: vector hpg flag
+#endif
+
+   !!* Namelist nam_dynhpg : Choice of horizontal pressure gradient computation
+   LOGICAL  ::   ln_hpg_zco = .TRUE.    ! z-coordinate - full steps
+   LOGICAL  ::   ln_hpg_zps = .FALSE.   ! z-coordinate - partial steps (interpolation)
+   LOGICAL  ::   ln_hpg_sco = .FALSE.   ! s-coordinate (standard jacobian formulation)
+   LOGICAL  ::   ln_hpg_hel = .FALSE.   ! s-coordinate (helsinki modification)
+   LOGICAL  ::   ln_hpg_wdj = .FALSE.   ! s-coordinate (weighted density jacobian)
+   LOGICAL  ::   ln_hpg_djc = .FALSE.   ! s-coordinate (Density Jacobian with Cubic polynomial)
+   LOGICAL  ::   ln_hpg_rot = .FALSE.   ! s-coordinate (ROTated axes scheme)
+   REAL(wp) ::   gamm       = 0.e0      ! weighting coefficient
+
+   INTEGER  ::   nhpg  =  0             ! = 0 to 6, type of pressure gradient scheme used
+      !                                 ! (deduced from ln_hpg_... flags)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_hpg( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_hpg  ***
+      !!
+      !! ** Method  :   Call the hydrostatic pressure gradient routine 
+      !!              using the scheme defined in the namelist
+      !!   
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D temporary workspace
+      !!----------------------------------------------------------------------
+   
+      IF( kt == nit000 )   CALL hpg_ctl      ! initialisation & control of options
+
+      IF( l_trddyn ) THEN                    ! Temporary saving of ua and va trends (l_trddyn)
+         ztrdu(:,:,:) = ua(:,:,:)  
+         ztrdv(:,:,:) = va(:,:,:) 
+      ENDIF      
+
+      SELECT CASE ( nhpg )      ! Hydrastatic pressure gradient computation
+      CASE (  0 )   ;   CALL hpg_zco    ( kt )      ! z-coordinate
+      CASE (  1 )   ;   CALL hpg_zps    ( kt )      ! z-coordinate plus partial steps (interpolation)
+      CASE (  2 )   ;   CALL hpg_sco    ( kt )      ! s-coordinate (standard jacobian formulation)
+      CASE (  3 )   ;   CALL hpg_hel    ( kt )      ! s-coordinate (helsinki modification)
+      CASE (  4 )   ;   CALL hpg_wdj    ( kt )      ! s-coordinate (weighted density jacobian)
+      CASE (  5 )   ;   CALL hpg_djc    ( kt )      ! s-coordinate (Density Jacobian with Cubic polynomial)
+      CASE (  6 )   ;   CALL hpg_rot    ( kt )      ! s-coordinate (ROTated axes scheme)
+      CASE ( 10 )   ;   CALL hpg_zco_jki( kt )      ! z-coordinate (k-j-i)
+      CASE ( 11 )   ;   CALL hpg_zps_jki( kt )      ! z-coordinate plus partial steps (interpolation) (k-j-i)
+      CASE ( 12 )   ;   CALL hpg_sco_jki( kt )      ! s-coordinate (standard jacobian formulation) (k-j-i)
+      END SELECT
+
+      IF( l_trddyn ) THEN      ! save the hydrostatic pressure gradient trends for momentum trend diagnostics
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_hpg, 'DYN', kt )
+      ENDIF          
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_hpg
+
+
+   SUBROUTINE hpg_ctl
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE hpg_ctl  ***
+      !!
+      !! ** Purpose :   initializations for the hydrostatic pressure gradient
+      !!              computation and consistency control
+      !!
+      !! ** Action  :   Read the namelist namdynhpg and check the consistency
+      !!      with the type of vertical coordinate used (zco, zps, sco)
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio = 0      ! temporary integer
+
+      NAMELIST/nam_dynhpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco, ln_hpg_hel,   &
+         &                 ln_hpg_wdj, ln_hpg_djc, ln_hpg_rot, gamm
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_dynhpg : pressure gradient calculation options
+      READ   ( numnam, nam_dynhpg )
+
+      IF(lwp) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn:hpg_ctl : hydrostatic pressure gradient control'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_dynhpg : choice of hpg scheme'
+         WRITE(numout,*) '          z-coord. - full steps                          ln_hpg_zco = ', ln_hpg_zco
+         WRITE(numout,*) '          z-coord. - partial steps (interpolation)       ln_hpg_zps = ', ln_hpg_zps
+         WRITE(numout,*) '          s-coord. (standard jacobian formulation)       ln_hpg_sco = ', ln_hpg_sco
+         WRITE(numout,*) '          s-coord. (helsinki modification)               ln_hpg_hel = ', ln_hpg_hel
+         WRITE(numout,*) '          s-coord. (weighted density jacobian)           ln_hpg_wdj = ', ln_hpg_wdj
+         WRITE(numout,*) '          s-coord. (Density Jacobian: Cubic polynomial)  ln_hpg_djc = ', ln_hpg_djc
+         WRITE(numout,*) '          s-coord. (ROTated axes scheme)                 ln_hpg_rot = ', ln_hpg_rot
+         WRITE(numout,*) '          weighting coeff. (wdj scheme)                     gamm       = ', gamm
+      ENDIF
+
+      IF( lk_vvl .AND. .NOT. ln_hpg_sco )   THEN
+         CALL ctl_stop( 'hpg_ctl : variable volume key_vvl compatible only with the standard jacobian formulation hpg_sco')
+      ENDIF
+
+      !                               ! Set nhpg from ln_hpg_... flags
+      IF( ln_hpg_zco )   nhpg = 0
+      IF( ln_hpg_zps )   nhpg = 1
+      IF( ln_hpg_sco )   nhpg = 2
+      IF( ln_hpg_hel )   nhpg = 3
+      IF( ln_hpg_wdj )   nhpg = 4
+      IF( ln_hpg_djc )   nhpg = 5
+      IF( ln_hpg_rot )   nhpg = 6
+
+      !                               ! Consitency check
+      ioptio = 0 
+      IF( ln_hpg_zco )   ioptio = ioptio + 1
+      IF( ln_hpg_zps )   ioptio = ioptio + 1
+      IF( ln_hpg_sco )   ioptio = ioptio + 1
+      IF( ln_hpg_hel )   ioptio = ioptio + 1
+      IF( ln_hpg_wdj )   ioptio = ioptio + 1
+      IF( ln_hpg_djc )   ioptio = ioptio + 1
+      IF( ln_hpg_rot )   ioptio = ioptio + 1
+      IF ( ioptio /= 1 )   CALL ctl_stop( ' NO or several hydrostatic pressure gradient options used' )
+
+      IF( lk_dynhpg_jki ) THEN
+         nhpg = nhpg + 10
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          Autotasking or OPENMP: use j-k-i loops (i.e. _jki routines)'
+      ENDIF
+      !
+   END SUBROUTINE hpg_ctl
+
+
+   SUBROUTINE hpg_zco( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_zco  ***
+      !!
+      !! ** Method  :   z-coordinate case, levels are horizontal surfaces.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level:    zhpi = grav .....
+      !!                zhpj = grav .....
+      !!      add it to the general momentum trend (ua,va).
+      !!            ua = ua - 1/e1u * zhpi
+      !!            va = va - 1/e2v * zhpj
+      !! 
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zco : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   z-coordinate case '
+      ENDIF
+      
+      ! Local constant initialization 
+      zcoef0 = - grav * 0.5
+
+      ! Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
+         END DO
+      END DO
+      !
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd(ji  ,jj,jk)+rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd(ji,jj,  jk)+rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_zco
+
+
+   SUBROUTINE hpg_zps( kt )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE hpg_zps  ***
+      !!                    
+      !! ** Method  :   z-coordinate plus partial steps case.  blahblah...
+      !! 
+      !! ** Action  : - Update (ua,va) with the now hydrastatic pressure trend
+      !!---------------------------------------------------------------------- 
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
+      INTEGER  ::   iku, ikv                         ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zcoef2, zcoef3   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_zps : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   z-coordinate with partial steps - vector optimization'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+
+      !  Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj  ,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji  ,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
+         END DO
+      END DO
+
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! partial steps correction at the last level  (new gradient with  intgrd.F)
+# if defined key_vectopt_loop
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+            ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+            zcoef2 = zcoef0 * MIN( fse3w(ji,jj,iku), fse3w(ji+1,jj  ,iku) )
+            zcoef3 = zcoef0 * MIN( fse3w(ji,jj,ikv), fse3w(ji  ,jj+1,ikv) )
+            ! on i-direction
+            IF ( iku > 2 ) THEN
+               ! subtract old value
+               ua(ji,jj,iku) = ua(ji,jj,iku) - zhpi(ji,jj,iku)
+               ! compute the new one
+               zhpi (ji,jj,iku) = zhpi(ji,jj,iku-1)   &
+                  + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) / e1u(ji,jj)
+               ! add the new one to the general momentum trend
+               ua(ji,jj,iku) = ua(ji,jj,iku) + zhpi(ji,jj,iku)
+            ENDIF
+            ! on j-direction
+            IF ( ikv > 2 ) THEN
+               ! subtract old value
+               va(ji,jj,ikv) = va(ji,jj,ikv) - zhpj(ji,jj,ikv)
+               ! compute the new one
+               zhpj (ji,jj,ikv) = zhpj(ji,jj,ikv-1)   &
+                  + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) / e2v(ji,jj)
+               ! add the new one to the general momentum trend
+               va(ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv)
+            ENDIF
+# if ! defined key_vectopt_loop
+         END DO
+# endif
+      END DO
+      !
+   END SUBROUTINE hpg_zps
+
+
+   SUBROUTINE hpg_sco( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_sco  ***
+      !!
+      !! ** Method  :   s-coordinate case. Jacobian scheme.
+      !!      The now hydrostatic pressure gradient at a given level, jk,
+      !!      is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap, znad   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_sco : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, OPA original scheme used'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      ! To use density and not density anomaly
+      IF ( lk_vvl ) THEN   ;     znad = 1.            ! Variable volume
+      ELSE                 ;     znad = 0.e0          ! Fixed volume
+      ENDIF
+
+      ! Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.   
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( fse3w(ji+1,jj  ,1) * ( znad + rhd(ji+1,jj  ,1) )   &
+               &                                  - fse3w(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) ) )
+            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( fse3w(ji  ,jj+1,1) * ( znad + rhd(ji  ,jj+1,1) )   &
+               &                                  - fse3w(ji  ,jj  ,1) * ( znad + rhd(ji  ,jj  ,1) ) )
+            ! s-coordinate pressure gradient correction
+            zuap = -zcoef0 * ( rhd   (ji+1,jj,1) + rhd   (ji,jj,1) + 2*znad )   &
+               &           * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd   (ji,jj+1,1) + rhd   (ji,jj,1) + 2*znad )   &
+               &           * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap
+         END DO  
+      END DO   
+            
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1                                  
+         DO jj = 2, jpjm1     
+            DO ji = fs_2, fs_jpim1   ! vector opt.      
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj)   & 
+                  &           * (  fse3w(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) + 2*znad )   & 
+                  &              - fse3w(ji  ,jj,jk) * ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) + 2*znad )  )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj)   &
+                  &           * (  fse3w(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) + 2*znad )   &
+                  &              - fse3w(ji,jj  ,jk) * ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) + 2*znad )  )
+               ! s-coordinate pressure gradient correction
+               zuap = -zcoef0 * ( rhd   (ji+1,jj  ,jk) + rhd   (ji,jj,jk) + 2*znad )   &
+                  &           * ( fsde3w(ji+1,jj  ,jk) - fsde3w(ji,jj,jk) ) / e1u(ji,jj)
+               zvap = -zcoef0 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji,jj,jk) + 2*znad )   &
+                  &           * ( fsde3w(ji  ,jj+1,jk) - fsde3w(ji,jj,jk) ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) + zvap
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_sco
+
+
+   SUBROUTINE hpg_hel( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_hel  ***
+      !!
+      !! ** Method  :   s-coordinate case.
+      !!      The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ 
+      !!      density gradient along the model level from the suface to that 
+      !!      level. s-coordinates (ln_sco): a corrective term is added
+      !!      to the horizontal pressure gradient :
+      !!         zhpi = grav .....  + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....  + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend (l_trddyn=T)
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_hel : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, helsinki modified scheme'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+ 
+      ! Surface value
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * ( fse3t(ji+1,jj  ,1) * rhd(ji+1,jj  ,1)  &
+               &                                  - fse3t(ji  ,jj  ,1) * rhd(ji  ,jj  ,1) )
+            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * ( fse3t(ji  ,jj+1,1) * rhd(ji  ,jj+1,1)  &
+               &                                  - fse3t(ji  ,jj  ,1) * rhd(ji  ,jj  ,1) )
+            ! s-coordinate pressure gradient correction
+            zuap = -zcoef0 * ( rhd   (ji+1,jj,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsdept(ji+1,jj,1) - fsdept(ji,jj,1) ) / e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd   (ji,jj+1,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsdept(ji,jj+1,1) - fsdept(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap
+         END DO
+      END DO
+      !
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) &
+                  &           +  zcoef0 / e1u(ji,jj) * ( fse3t(ji+1,jj,jk  ) * rhd(ji+1,jj,jk)     &
+                  &                                     -fse3t(ji  ,jj,jk  ) * rhd(ji  ,jj,jk)   ) &
+                  &           +  zcoef0 / e1u(ji,jj) * ( fse3t(ji+1,jj,jk-1) * rhd(ji+1,jj,jk-1)   &
+                  &                                     -fse3t(ji  ,jj,jk-1) * rhd(ji  ,jj,jk-1) )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) &
+                  &           +  zcoef0 / e2v(ji,jj) * ( fse3t(ji,jj+1,jk  ) * rhd(ji,jj+1,jk)   &
+                  &                                     -fse3t(ji,jj  ,jk  ) * rhd(ji,jj,  jk)   ) &
+                  &           +  zcoef0 / e2v(ji,jj) * ( fse3t(ji,jj+1,jk-1) * rhd(ji,jj+1,jk-1) &
+                  &                                     -fse3t(ji,jj  ,jk-1) * rhd(ji,jj,  jk-1) )
+               ! s-coordinate pressure gradient correction
+               zuap = - zcoef0 * ( rhd   (ji+1,jj,jk) + rhd   (ji,jj,jk) )   &
+                  &            * ( fsdept(ji+1,jj,jk) - fsdept(ji,jj,jk) ) / e1u(ji,jj)
+               zvap = - zcoef0 * ( rhd   (ji,jj+1,jk) + rhd   (ji,jj,jk) )   &
+                  &            * ( fsdept(ji,jj+1,jk) - fsdept(ji,jj,jk) ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) + zvap
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_hel
+
+
+   SUBROUTINE hpg_wdj( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_wdj  ***
+      !!
+      !! ** Method  :   Weighted Density Jacobian (wdj) scheme (song 1998)
+      !!      The weighting coefficients from the namelist parameter gamm
+      !!      (alpha=0.5-gamm ; beta=1-alpha=0.5+gamm)
+      !!
+      !! Reference : Song, Mon. Wea. Rev., 126, 3213-3230, 1998.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
+      REAL(wp) ::   zalph , zbeta        !    "         "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_wdj : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   Weighted Density Jacobian'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      zalph  = 0.5 - gamm        ! weighting coefficients (alpha=0.5-gamm)
+      zbeta  = 0.5 + gamm        !                        (beta =1-alpha=0.5+gamm)
+
+      ! Surface value (no ponderation)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj) * (  fse3w(ji+1,jj  ,1) * rhd(ji+1,jj  ,1)   &
+               &                                   - fse3w(ji  ,jj  ,1) * rhd(ji  ,jj  ,1)  )
+            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj) * (  fse3w(ji  ,jj+1,1) * rhd(ji  ,jj+1,1)   &
+               &                                   - fse3w(ji  ,jj  ,1) * rhd(ji,  jj  ,1)  )
+            ! s-coordinate pressure gradient correction
+            zuap = -zcoef0 * ( rhd   (ji+1,jj,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd   (ji,jj+1,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap
+         END DO
+      END DO
+
+      ! Interior value (2=<jk=<jpkm1) (weighted with zalph & zbeta)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj)                            &
+                  &           * (   (            fsde3w(ji+1,jj,jk  ) + fsde3w(ji,jj,jk  )        &
+                  &                            - fsde3w(ji+1,jj,jk-1) - fsde3w(ji,jj,jk-1)    )   &
+                  &               * (  zalph * ( rhd   (ji+1,jj,jk-1) - rhd   (ji,jj,jk-1) )      &
+                  &                  + zbeta * ( rhd   (ji+1,jj,jk  ) - rhd   (ji,jj,jk  ) )  )   &
+                  &             -   (            rhd   (ji+1,jj,jk  ) + rhd   (ji,jj,jk  )        &
+                  &                           - rhd   (ji+1,jj,jk-1) - rhd   (ji,jj,jk-1)     )   &
+                  &               * (  zalph * ( fsde3w(ji+1,jj,jk-1) - fsde3w(ji,jj,jk-1) )      &
+                  &                  + zbeta * ( fsde3w(ji+1,jj,jk  ) - fsde3w(ji,jj,jk  ) )  )  )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj)                            &
+                  &           * (   (           fsde3w(ji,jj+1,jk  ) + fsde3w(ji,jj,jk  )         &
+                  &                           - fsde3w(ji,jj+1,jk-1) - fsde3w(ji,jj,jk-1)     )   &
+                  &               * (  zalph * ( rhd   (ji,jj+1,jk-1) - rhd   (ji,jj,jk-1) )      &
+                  &                  + zbeta * ( rhd   (ji,jj+1,jk  ) - rhd   (ji,jj,jk  ) )  )   &
+                  &             -   (            rhd   (ji,jj+1,jk  ) + rhd   (ji,jj,jk  )        &
+                  &                            - rhd   (ji,jj+1,jk-1) - rhd   (ji,jj,jk-1)    )   &
+                  &               * (  zalph * ( fsde3w(ji,jj+1,jk-1) - fsde3w(ji,jj,jk-1) )      &
+                  &                  + zbeta * ( fsde3w(ji,jj+1,jk  ) - fsde3w(ji,jj,jk  ) )  )  )
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_wdj
+
+
+   SUBROUTINE hpg_djc( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_djc  ***
+      !!
+      !! ** Method  :   Density Jacobian with Cubic polynomial scheme
+      !! 
+      !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zcoef0, zep, cffw   ! temporary scalars
+      REAL(wp) ::   z1_10, cffu, cffx   !    "         "
+      REAL(wp) ::   z1_12, cffv, cffy   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhox, dzx, drhou, dzu, rho_i   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoy, dzy, drhov, dzv, rho_j   !  "      "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoz, dzz, drhow, dzw, rho_k   !  "      "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_djc : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, density Jacobian with cubic polynomial scheme'
+      ENDIF
+
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      z1_10  = 1.0 / 10.0
+      z1_12  = 1.0 / 12.0
+
+      !----------------------------------------------------------------------------------------
+      !  compute and store in provisional arrays elementary vertical and horizontal differences
+      !----------------------------------------------------------------------------------------
+
+!!bug gm   Not a true bug, but... dzz=e3w  for dzx, dzy verify what it is really
+
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               drhoz(ji,jj,jk) = rhd   (ji  ,jj  ,jk) - rhd   (ji,jj,jk-1)
+               dzz  (ji,jj,jk) = fsde3w(ji  ,jj  ,jk) - fsde3w(ji,jj,jk-1)
+               drhox(ji,jj,jk) = rhd   (ji+1,jj  ,jk) - rhd   (ji,jj,jk  )
+               dzx  (ji,jj,jk) = fsde3w(ji+1,jj  ,jk) - fsde3w(ji,jj,jk  )
+               drhoy(ji,jj,jk) = rhd   (ji  ,jj+1,jk) - rhd   (ji,jj,jk  )
+               dzy  (ji,jj,jk) = fsde3w(ji  ,jj+1,jk) - fsde3w(ji,jj,jk  )
+            END DO
+         END DO
+      END DO
+
+      !-------------------------------------------------------------------------
+      ! compute harmonic averages using eq. 5.18
+      !-------------------------------------------------------------------------
+      zep = 1.e-15
+
+!!bug  gm  drhoz not defined at level 1 and used (jk-1 with jk=2)
+!!bug  gm  idem for drhox, drhoy et ji=jpi and jj=jpj
+
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               cffw = 2.0 * drhoz(ji  ,jj  ,jk) * drhoz(ji,jj,jk-1)
+
+               cffu = 2.0 * drhox(ji+1,jj  ,jk) * drhox(ji,jj,jk  )
+               cffx = 2.0 * dzx  (ji+1,jj  ,jk) * dzx  (ji,jj,jk  )
+  
+               cffv = 2.0 * drhoy(ji  ,jj+1,jk) * drhoy(ji,jj,jk  )
+               cffy = 2.0 * dzy  (ji  ,jj+1,jk) * dzy  (ji,jj,jk  )
+
+               IF( cffw > zep) THEN
+                  drhow(ji,jj,jk) = 2.0 *   drhoz(ji,jj,jk) * drhoz(ji,jj,jk-1)   &
+                     &                  / ( drhoz(ji,jj,jk) + drhoz(ji,jj,jk-1) )
+               ELSE
+                  drhow(ji,jj,jk) = 0.e0
+               ENDIF
+
+               dzw(ji,jj,jk) = 2.0 *   dzz(ji,jj,jk) * dzz(ji,jj,jk-1)   &
+                  &                / ( dzz(ji,jj,jk) + dzz(ji,jj,jk-1) )
+
+               IF( cffu > zep ) THEN
+                  drhou(ji,jj,jk) = 2.0 *   drhox(ji+1,jj,jk) * drhox(ji,jj,jk)   &
+                     &                  / ( drhox(ji+1,jj,jk) + drhox(ji,jj,jk) )
+               ELSE
+                  drhou(ji,jj,jk ) = 0.e0
+               ENDIF
+
+               IF( cffx > zep ) THEN
+                  dzu(ji,jj,jk) = 2.0*dzx(ji+1,jj,jk)*dzx(ji,jj,jk)   &
+                     &            /(dzx(ji+1,jj,jk)+dzx(ji,jj,jk))
+               ELSE
+                  dzu(ji,jj,jk) = 0.e0
+               ENDIF
+
+               IF( cffv > zep ) THEN
+                  drhov(ji,jj,jk) = 2.0 *   drhoy(ji,jj+1,jk) * drhoy(ji,jj,jk)   &
+                     &                  / ( drhoy(ji,jj+1,jk) + drhoy(ji,jj,jk) )
+               ELSE
+                  drhov(ji,jj,jk) = 0.e0
+               ENDIF
+
+               IF( cffy > zep ) THEN
+                  dzv(ji,jj,jk) = 2.0 *   dzy(ji,jj+1,jk) * dzy(ji,jj,jk)   &
+                     &                / ( dzy(ji,jj+1,jk) + dzy(ji,jj,jk) )
+               ELSE
+                  dzv(ji,jj,jk) = 0.e0
+               ENDIF
+
+            END DO
+         END DO
+      END DO
+
+      !----------------------------------------------------------------------------------
+      ! apply boundary conditions at top and bottom using 5.36-5.37
+      !----------------------------------------------------------------------------------
+      drhow(:,:, 1 ) = 1.5 * ( drhoz(:,:, 2 ) - drhoz(:,:,  1  ) ) - 0.5 * drhow(:,:,  2  )
+      drhou(:,:, 1 ) = 1.5 * ( drhox(:,:, 2 ) - drhox(:,:,  1  ) ) - 0.5 * drhou(:,:,  2  )
+      drhov(:,:, 1 ) = 1.5 * ( drhoy(:,:, 2 ) - drhoy(:,:,  1  ) ) - 0.5 * drhov(:,:,  2  )
+
+      drhow(:,:,jpk) = 1.5 * ( drhoz(:,:,jpk) - drhoz(:,:,jpkm1) ) - 0.5 * drhow(:,:,jpkm1)
+      drhou(:,:,jpk) = 1.5 * ( drhox(:,:,jpk) - drhox(:,:,jpkm1) ) - 0.5 * drhou(:,:,jpkm1)
+      drhov(:,:,jpk) = 1.5 * ( drhoy(:,:,jpk) - drhoy(:,:,jpkm1) ) - 0.5 * drhov(:,:,jpkm1)
+
+
+      !--------------------------------------------------------------
+      ! Upper half of top-most grid box, compute and store
+      !-------------------------------------------------------------
+
+!!bug gm   :  e3w-de3w = 0.5*e3w  ....  and de3w(2)-de3w(1)=e3w(2) ....   to be verified
+!          true if de3w is really defined as the sum of the e3w scale factors as, it seems to me, it should be
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            rho_k(ji,jj,1) = -grav * ( fse3w(ji,jj,1) - fsde3w(ji,jj,1) )            &
+               &                   * (  rhd(ji,jj,1)                                 &
+               &                     + 0.5 * ( rhd(ji,jj,2) - rhd(ji,jj,1) )         &
+               &                           * ( fse3w (ji,jj,1) - fsde3w(ji,jj,1) )   &
+               &                           / ( fsde3w(ji,jj,2) - fsde3w(ji,jj,1) )  ) 
+         END DO
+      END DO
+
+!!bug gm    : here also, simplification is possible
+!!bug gm    : optimisation: 1/10 and 1/12 the division should be done before the loop
+
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               rho_k(ji,jj,jk) = zcoef0 * ( rhd   (ji,jj,jk) + rhd   (ji,jj,jk-1) )                                   &
+                  &                     * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) )                                   &
+                  &            - grav * z1_10 * (                                                                     &
+                  &     ( drhow (ji,jj,jk) - drhow (ji,jj,jk-1) )                                                     &
+                  &   * ( fsde3w(ji,jj,jk) - fsde3w(ji,jj,jk-1) - z1_12 * ( dzw  (ji,jj,jk) + dzw  (ji,jj,jk-1) ) )   &
+                  &   - ( dzw   (ji,jj,jk) - dzw   (ji,jj,jk-1) )                                                     &
+                  &   * ( rhd   (ji,jj,jk) - rhd   (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) )   &
+                  &                             )
+
+               rho_i(ji,jj,jk) = zcoef0 * ( rhd   (ji+1,jj,jk) + rhd   (ji,jj,jk) )                                   &
+                  &                     * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) )                                   &
+                  &            - grav* z1_10 * (                                                                      &
+                  &     ( drhou (ji+1,jj,jk) - drhou (ji,jj,jk) )                                                     &
+                  &   * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzu  (ji+1,jj,jk) + dzu  (ji,jj,jk) ) )   &
+                  &   - ( dzu   (ji+1,jj,jk) - dzu   (ji,jj,jk) )                                                     &
+                  &   * ( rhd   (ji+1,jj,jk) - rhd   (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) )   &
+                  &                            )
+
+               rho_j(ji,jj,jk) = zcoef0 * ( rhd   (ji,jj+1,jk) + rhd   (ji,jj,jk) )                                   &
+                  &                     * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) )                                   &
+                  &            - grav* z1_10 * (                                                                      &
+                  &     ( drhov (ji,jj+1,jk) - drhov (ji,jj,jk) )                                                     &
+                  &   * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) - z1_12 * ( dzv  (ji,jj+1,jk) + dzv  (ji,jj,jk) ) )   &
+                  &   - ( dzv   (ji,jj+1,jk) - dzv   (ji,jj,jk) )                                                     &
+                  &   * ( rhd   (ji,jj+1,jk) - rhd   (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) )   &
+                  &                            )
+
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk(rho_k,'W',1.)
+      CALL lbc_lnk(rho_i,'U',1.)
+      CALL lbc_lnk(rho_j,'V',1.)
+
+
+      ! ---------------
+      !  Surface value
+      ! ---------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zhpi(ji,jj,1) = ( rho_k(ji+1,jj  ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) / e1u(ji,jj)
+            zhpj(ji,jj,1) = ( rho_k(ji  ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
+         END DO
+      END DO
+
+      ! ----------------
+      !  interior value   (2=<jk=<jpkm1)
+      ! ----------------
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)                                &
+                  &           + (  ( rho_k(ji+1,jj,jk) - rho_k(ji,jj,jk  ) )    &
+                  &              - ( rho_i(ji  ,jj,jk) - rho_i(ji,jj,jk-1) )  ) / e1u(ji,jj)
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)                                &
+                  &           + (  ( rho_k(ji,jj+1,jk) - rho_k(ji,jj,jk  ) )    &
+                  &               -( rho_j(ji,jj  ,jk) - rho_j(ji,jj,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_djc
+
+
+   SUBROUTINE hpg_rot( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_rot  ***
+      !!
+      !! ** Method  :   rotated axes scheme (Thiem and Berntsen 2005)
+      !!
+      !! Reference: Thiem & Berntsen, Ocean Modelling, In press, 2005.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zforg, zcoef0, zuap, zmskd1, zmskd1m   ! temporary scalar
+      REAL(wp) ::   zfrot        , zvap, zmskd2, zmskd2m   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdistr, zsina, zcosa                ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpiorg, zhpirot, zhpitra, zhpine   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpjorg, zhpjrot, zhpjtra, zhpjne   !  "      "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:hpg_rot : hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate case, rotated axes scheme used'
+      ENDIF
+
+      ! -------------------------------
+      !  Local constant initialization
+      ! -------------------------------
+      zcoef0 = - grav * 0.5
+      zforg  = 0.95e0
+      zfrot  = 1.e0 - zforg
+
+      ! inverse of the distance between 2 diagonal T-points (defined at F-point) (here zcoef0/distance)
+      zdistr(:,:) = zcoef0 / SQRT( e1f(:,:)*e1f(:,:) + e2f(:,:)*e1f(:,:) )
+
+      ! sinus and cosinus of diagonal angle at F-point
+      zsina(:,:) = ATAN2( e2f(:,:), e1f(:,:) )
+      zcosa(:,:) = COS( zsina(:,:) )
+      zsina(:,:) = SIN( zsina(:,:) )
+
+      ! ---------------
+      !  Surface value
+      ! ---------------
+      ! compute and add to the general trend the pressure gradients along the axes
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpiorg(ji,jj,1) = zcoef0 / e1u(ji,jj) * (  fse3t(ji+1,jj,1) * rhd(ji+1,jj,1)   &
+               &                                      - fse3t(ji  ,jj,1) * rhd(ji  ,jj,1)  )
+            zhpjorg(ji,jj,1) = zcoef0 / e2v(ji,jj) * (  fse3t(ji,jj+1,1) * rhd(ji,jj+1,1)   &
+               &                                      - fse3t(ji,jj  ,1) * rhd(ji,jj  ,1)  )
+            ! s-coordinate pressure gradient correction
+            zuap = -zcoef0 * ( rhd   (ji+1,jj  ,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsdept(ji+1,jj  ,1) - fsdept(ji,jj,1) ) / e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd   (ji  ,jj+1,1) + rhd   (ji,jj,1) )   &
+               &           * ( fsdept(ji  ,jj+1,1) - fsdept(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zforg * ( zhpiorg(ji,jj,1) + zuap )
+            va(ji,jj,1) = va(ji,jj,1) + zforg * ( zhpjorg(ji,jj,1) + zvap )
+         END DO
+      END DO
+
+      ! compute the pressure gradients in the diagonal directions
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zmskd1 = tmask(ji+1,jj+1,1) * tmask(ji  ,jj,1)      ! mask in the 1st diagnonal
+            zmskd2 = tmask(ji  ,jj+1,1) * tmask(ji+1,jj,1)      ! mask in the 2nd diagnonal
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpitra(ji,jj,1) = zdistr(ji,jj) * zmskd1 * (  fse3t(ji+1,jj+1,1) * rhd(ji+1,jj+1,1)   &
+               &                                         - fse3t(ji  ,jj  ,1) * rhd(ji  ,jj  ,1)  )
+            zhpjtra(ji,jj,1) = zdistr(ji,jj) * zmskd2 * (  fse3t(ji  ,jj+1,1) * rhd(ji  ,jj+1,1)   &
+               &                                         - fse3t(ji+1,jj  ,1) * rhd(ji+1,jj  ,1)  )
+            ! s-coordinate pressure gradient correction
+            zuap = -zdistr(ji,jj) * zmskd1 * ( rhd   (ji+1,jj+1,1) + rhd   (ji  ,jj,1) )   &
+               &                           * ( fsdept(ji+1,jj+1,1) - fsdept(ji  ,jj,1) )
+            zvap = -zdistr(ji,jj) * zmskd2 * ( rhd   (ji  ,jj+1,1) + rhd   (ji+1,jj,1) )   &
+               &                           * ( fsdept(ji  ,jj+1,1) - fsdept(ji+1,jj,1) )
+            ! back rotation
+            zhpine(ji,jj,1) = zcosa(ji,jj) * ( zhpitra(ji,jj,1) + zuap )   &
+               &            - zsina(ji,jj) * ( zhpjtra(ji,jj,1) + zvap )
+            zhpjne(ji,jj,1) = zsina(ji,jj) * ( zhpitra(ji,jj,1) + zuap )   &
+               &            + zcosa(ji,jj) * ( zhpjtra(ji,jj,1) + zvap )
+         END DO
+      END DO
+
+      ! interpolate and add to the general trend the diagonal gradient
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! averaging
+            zhpirot(ji,jj,1) = 0.5 * ( zhpine(ji,jj,1) + zhpine(ji  ,jj-1,1) )
+            zhpjrot(ji,jj,1) = 0.5 * ( zhpjne(ji,jj,1) + zhpjne(ji-1,jj  ,1) )
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zfrot * zhpirot(ji,jj,1) 
+            va(ji,jj,1) = va(ji,jj,1) + zfrot * zhpjrot(ji,jj,1) 
+         END DO
+      END DO
+
+      ! -----------------
+      ! 2. interior value (2=<jk=<jpkm1)
+      ! -----------------
+      ! compute and add to the general trend the pressure gradients along the axes
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpiorg(ji,jj,jk) = zhpiorg(ji,jj,jk-1)                                                 &
+                  &              +  zcoef0 / e1u(ji,jj) * (  fse3t(ji+1,jj,jk  ) * rhd(ji+1,jj,jk  )   &
+                  &                                        - fse3t(ji  ,jj,jk  ) * rhd(ji  ,jj,jk  )   &
+                  &                                        + fse3t(ji+1,jj,jk-1) * rhd(ji+1,jj,jk-1)   &
+                  &                                        - fse3t(ji  ,jj,jk-1) * rhd(ji  ,jj,jk-1)  )
+               zhpjorg(ji,jj,jk) = zhpjorg(ji,jj,jk-1)                                                 &
+                  &              +  zcoef0 / e2v(ji,jj) * (  fse3t(ji,jj+1,jk  ) * rhd(ji,jj+1,jk  )   &
+                  &                                        - fse3t(ji,jj  ,jk  ) * rhd(ji,jj,  jk  )   &
+                  &                                        + fse3t(ji,jj+1,jk-1) * rhd(ji,jj+1,jk-1)   &
+                  &                                        - fse3t(ji,jj  ,jk-1) * rhd(ji,jj,  jk-1)  )
+               ! s-coordinate pressure gradient correction
+               zuap = - zcoef0 * ( rhd   (ji+1,jj  ,jk) + rhd   (ji,jj,jk) )   &
+                  &            * ( fsdept(ji+1,jj  ,jk) - fsdept(ji,jj,jk) ) / e1u(ji,jj)
+               zvap = - zcoef0 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji,jj,jk) )   &
+                  &            * ( fsdept(ji  ,jj+1,jk) - fsdept(ji,jj,jk) ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zforg*( zhpiorg(ji,jj,jk) + zuap )
+               va(ji,jj,jk) = va(ji,jj,jk) + zforg*( zhpjorg(ji,jj,jk) + zvap )
+            END DO
+         END DO
+      END DO
+
+      ! compute the pressure gradients in the diagonal directions
+      DO jk = 2, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zmskd1  = tmask(ji+1,jj+1,jk  ) * tmask(ji  ,jj,jk  )      ! level jk   mask in the 1st diagnonal
+               zmskd1m = tmask(ji+1,jj+1,jk-1) * tmask(ji  ,jj,jk-1)      ! level jk-1    "               "     
+               zmskd2  = tmask(ji  ,jj+1,jk  ) * tmask(ji+1,jj,jk  )      ! level jk   mask in the 2nd diagnonal
+               zmskd2m = tmask(ji  ,jj+1,jk-1) * tmask(ji+1,jj,jk-1)      ! level jk-1    "               "     
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpitra(ji,jj,jk) = zhpitra(ji,jj,jk-1)                                                       &
+                  &              + zdistr(ji,jj) * zmskd1  * ( fse3t(ji+1,jj+1,jk  ) * rhd(ji+1,jj+1,jk)     &
+                  &                                           -fse3t(ji  ,jj  ,jk  ) * rhd(ji  ,jj  ,jk) )   &
+                  &              + zdistr(ji,jj) * zmskd1m * ( fse3t(ji+1,jj+1,jk-1) * rhd(ji+1,jj+1,jk-1)   &
+                  &                                           -fse3t(ji  ,jj  ,jk-1) * rhd(ji  ,jj  ,jk-1) )
+               zhpjtra(ji,jj,jk) = zhpjtra(ji,jj,jk-1)                                                       &
+                  &              + zdistr(ji,jj) * zmskd2  * ( fse3t(ji  ,jj+1,jk  ) * rhd(ji  ,jj+1,jk)     &
+                  &                                           -fse3t(ji+1,jj  ,jk  ) * rhd(ji+1,jj,  jk) )   &
+                  &              + zdistr(ji,jj) * zmskd2m * ( fse3t(ji  ,jj+1,jk-1) * rhd(ji  ,jj+1,jk-1)   &
+                  &                                           -fse3t(ji+1,jj  ,jk-1) * rhd(ji+1,jj,  jk-1) )
+               ! s-coordinate pressure gradient correction
+               zuap = - zdistr(ji,jj) * zmskd1 * ( rhd   (ji+1,jj+1,jk) + rhd   (ji  ,jj,jk) )   &
+                  &                            * ( fsdept(ji+1,jj+1,jk) - fsdept(ji  ,jj,jk) )
+               zvap = - zdistr(ji,jj) * zmskd2 * ( rhd   (ji  ,jj+1,jk) + rhd   (ji+1,jj,jk) )   &
+                  &                            * ( fsdept(ji  ,jj+1,jk) - fsdept(ji+1,jj,jk) )
+               ! back rotation
+               zhpine(ji,jj,jk) = zcosa(ji,jj) * ( zhpitra(ji,jj,jk) + zuap )   &
+                  &             - zsina(ji,jj) * ( zhpjtra(ji,jj,jk) + zvap )
+               zhpjne(ji,jj,jk) = zsina(ji,jj) * ( zhpitra(ji,jj,jk) + zuap )   &
+                  &             + zcosa(ji,jj) * ( zhpjtra(ji,jj,jk) + zvap )
+            END DO
+         END DO
+      END DO
+
+      ! interpolate and add to the general trend
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! averaging
+               zhpirot(ji,jj,jk) = 0.5 * ( zhpine(ji,jj,jk) + zhpine(ji  ,jj-1,jk) )
+               zhpjrot(ji,jj,jk) = 0.5 * ( zhpjne(ji,jj,jk) + zhpjne(ji-1,jj  ,jk) )
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zfrot * zhpirot(ji,jj,jk) 
+               va(ji,jj,jk) = va(ji,jj,jk) + zfrot * zhpjrot(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE hpg_rot
+
+   !!======================================================================
+END MODULE dynhpg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynhpg_jki.F90	(revision 4536)
@@ -0,0 +1,308 @@
+MODULE dynhpg_jki
+   !!======================================================================
+   !!                       ***  MODULE  dynhpg_jki  ***
+   !! Ocean dynamics:  hydrostatic pressure gradient trend
+   !!======================================================================
+   !! History :  9.0  !  06-09  (G. Madec) From dynhpg module
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   hpg_sco_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (s-coordinate)
+   !!   hpg_zps_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (partial step)
+   !!   hpg_zco_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (z-coordinate)
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! lateral boundary condition
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   hpg_sco_jki   ! routine called by step.F90
+   PUBLIC   hpg_zps_jki   ! routine called by step.F90
+   PUBLIC   hpg_zco_jki   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE hpg_sco_jki( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_sco_jki  ***
+      !!        
+      !! ** Purpose :   Compute the now momentum trend due to the horizontal 
+      !!     gradient of the hydrostatic pressure. Add it to the general
+      !!     momentum trend.
+      !!
+      !! ** Method  :   The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ 
+      !!      density gradient along the model level from the suface to that
+      !!      level. s-coordinate case (ln_sco=T): a corrective term is
+      !!      added to the horizontal pressure gradient :
+      !!         zhpi = grav .....   + 1/e1u mi(rhd) di[ grav dep3w ]
+      !!         zhpj = grav .....   + 1/e2v mj(rhd) dj[ grav dep3w ]
+      !!      add it to the general momentum trend (ua,va).
+      !!         ua = ua - 1/e1u * zhpi
+      !!         va = va - 1/e2v * zhpj
+      !!      j-k-i loop (j-slab) ('key_mpp_omp')
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'hpg_sco_jki : s-coordinate hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   OpenMP / NEC autotasking case (j-k-i loop)'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      zuap   = 0.e0
+      zvap   = 0.e0
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         DO ji = 2, jpim1         !  Surface value
+            ! hydrostatic pressure gradient along s-surfaces
+            zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj)   &
+                       * ( fse3w(ji+1,jj,1) * rhd(ji+1,jj,1) - fse3w(ji,jj,1) * rhd(ji,jj,1)  )
+            zhpj(ji,jj,1) = zcoef0 / e2v(ji,jj)   &
+                       * ( fse3w(ji,jj+1,1) * rhd(ji,jj+1,1) - fse3w(ji,jj,1) * rhd(ji,jj,1)  )
+            ! s-coordinate pressure gradient correction
+            zuap = -zcoef0 * ( rhd(ji+1,jj,1) + rhd(ji,jj,1) )   &
+                 * ( fsde3w(ji+1,jj,1) - fsde3w(ji,jj,1) ) / e1u(ji,jj)
+            zvap = -zcoef0 * ( rhd(ji,jj+1,1) + rhd(ji,jj,1) )   &
+                 * ( fsde3w(ji,jj+1,1) - fsde3w(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap
+         END DO  
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
+            DO ji = 2, jpim1
+               ! hydrostatic pressure gradient along s-surfaces
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1) + zcoef0 / e1u(ji,jj)   &
+                  &           * ( fse3w(ji+1,jj,jk) * ( rhd(ji+1,jj,jk) + rhd(ji+1,jj,jk-1) )   &
+                  &              -fse3w(ji  ,jj,jk) * ( rhd(ji  ,jj,jk) + rhd(ji  ,jj,jk-1) )  )
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1) + zcoef0 / e2v(ji,jj)   &
+                  &           * ( fse3w(ji,jj+1,jk) * ( rhd(ji,jj+1,jk) + rhd(ji,jj+1,jk-1) )   &
+                  &              -fse3w(ji,jj  ,jk) * ( rhd(ji,jj,  jk) + rhd(ji,jj  ,jk-1) )  )
+               ! s-coordinate pressure gradient correction 
+               zuap = -zcoef0 * ( rhd(ji+1,jj  ,jk) + rhd(ji,jj,jk) )   &
+                    * ( fsde3w(ji+1,jj,jk) - fsde3w(ji,jj,jk) ) / e1u(ji,jj)
+               zvap = -zcoef0 * ( rhd(ji  ,jj+1,jk) + rhd(ji,jj,jk) )   &
+                    * ( fsde3w(ji,jj+1,jk) - fsde3w(ji,jj,jk) ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk) + zvap
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE hpg_sco_jki
+
+
+   SUBROUTINE hpg_zps_jki( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_zps_jki  ***
+      !!  
+      !! ** Purpose :   Compute the now momentum trend due to the hor. gradient
+      !!      of the hydrostatic pressure. Add it to the general momentum trend.
+      !!
+      !! ** Method  :   The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ
+      !!      density gradient along the model level from the suface to that 
+      !!      level:    zhpi = grav .....
+      !!                zhpj = grav .....
+      !!      add it to the general momentum trend (ua,va).
+      !!            ua = ua - 1/e1u * zhpi
+      !!            va = va - 1/e2v * zhpj
+      !!      j-k-i loop (j-slab) ('key_mpp_omp')
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   iku, ikv               ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zuap   ! temporary scalars
+      REAL(wp) ::   zcoef2, zcoef3, zvap   !    "         "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'hpg_zps_jki : z-coord. partial steps hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   OpenMP / NEC autotasking case (j-k-i loop)'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      zuap   = 0.e0
+      zvap   = 0.e0
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         DO ji = 2, jpim1         ! Surface value
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
+         END DO
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
+            DO ji = 2, jpim1
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd(ji  ,jj,jk)+rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd(ji,jj,  jk)+rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO 
+         END DO
+         !
+         ! partial steps correction at the last level  (new gradient with  intgrd.F)
+         DO ji = 2, jpim1
+            iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+            ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+            zcoef2 = zcoef0 * MIN( fse3w(ji,jj,iku), fse3w(ji+1,jj  ,iku) )
+            zcoef3 = zcoef0 * MIN( fse3w(ji,jj,ikv), fse3w(ji  ,jj+1,ikv) )
+            ! on i-direction
+            IF ( iku > 2 ) THEN
+               ! subtract old value  
+               ua(ji,jj,iku) = ua(ji,jj,iku) - zhpi(ji,jj,iku)
+               ! compute the new one   
+               zhpi (ji,jj,iku) = zhpi(ji,jj,iku-1)   &
+                  + zcoef2 * ( rhd(ji+1,jj,iku-1) - rhd(ji,jj,iku-1) + gru(ji,jj) ) / e1u(ji,jj)
+               ! add the new one to the general momentum trend
+               ua(ji,jj,iku) = ua(ji,jj,iku) + zhpi(ji,jj,iku)
+            ENDIF
+            ! on j-direction
+            IF ( ikv > 2 ) THEN
+               ! subtract old value  
+               va(ji,jj,ikv) = va(ji,jj,ikv) - zhpj(ji,jj,ikv)
+               ! compute the new one   
+               zhpj (ji,jj,ikv) = zhpj(ji,jj,ikv-1)   &
+                  + zcoef3 * ( rhd(ji,jj+1,ikv-1) - rhd(ji,jj,ikv-1) + grv(ji,jj) ) / e2v(ji,jj)
+               ! add the new one to the general momentum trend
+               va(ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv)
+            ENDIF
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE hpg_zps_jki
+
+
+   SUBROUTINE hpg_zco_jki( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE hpg_zco_jki  ***
+      !!   
+      !! ** Purpose :   Compute the now momentum trend due to the horizontal
+      !!      gradient of the hydrostatic pressure. Add it to the general
+      !!      momentum trend.
+      !!
+      !! ** Method  :   The now hydrostatic pressure gradient at a given level
+      !!      jk is computed by taking the vertical integral of the in-situ  
+      !!      density gradient along the model level from the suface to that
+      !!      level:    zhpi = grav .....
+      !!                zhpj = grav .....
+      !!      add it to the general momentum trend (ua,va).
+      !!            ua = ua - 1/e1u * zhpi
+      !!            va = va - 1/e2v * zhpj
+      !!      j-k-i loop (j-slab) ('key_mpp_omp')
+      !!
+      !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                   ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1, zuap, zvap   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'hpg_zco_jki : z-coordinate hydrostatic pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   OpenMP / NEC auto-tasking (j-k-i loop)'
+      ENDIF
+
+      ! Local constant initialization
+      zcoef0 = - grav * 0.5
+      zuap   = 0.e0
+      zvap   = 0.e0
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         DO ji = 2, jpim1         ! Surface value
+            zcoef1 = zcoef0 * fse3w(ji,jj,1)
+            ! hydrostatic pressure gradient
+            zhpi(ji,jj,1) = zcoef1 * ( rhd(ji+1,jj,1) - rhd(ji,jj,1) ) / e1u(ji,jj)
+            zhpj(ji,jj,1) = zcoef1 * ( rhd(ji,jj+1,1) - rhd(ji,jj,1) ) / e2v(ji,jj)
+            ! add to the general momentum trend
+            ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1)
+            va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
+         END DO
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
+            DO ji = 2, jpim1
+               zcoef1 = zcoef0 * fse3w(ji,jj,jk)
+               ! hydrostatic pressure gradient
+               zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji+1,jj,jk)+rhd(ji+1,jj,jk-1) )   &
+                  &                       - ( rhd(ji  ,jj,jk)+rhd(ji  ,jj,jk-1) )  ) / e1u(ji,jj)
+
+               zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)   &
+                  &           + zcoef1 * (  ( rhd(ji,jj+1,jk)+rhd(ji,jj+1,jk-1) )   &
+                  &                       - ( rhd(ji,jj,  jk)+rhd(ji,jj  ,jk-1) )  ) / e2v(ji,jj)
+               ! add to the general momentum trend
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zhpj(ji,jj,jk)
+            END DO 
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE hpg_zco_jki
+
+   !!======================================================================
+END MODULE dynhpg_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 4536)
@@ -0,0 +1,109 @@
+MODULE dynkeg
+   !!======================================================================
+   !!                       ***  MODULE  dynkeg  ***
+   !! Ocean dynamics:  kinetic energy gradient trend
+   !!======================================================================
+   !! History :  1.0  !  87-09  (P. Andrich, m.-a. Foujols)  Original code
+   !!            7.0  !  97-05  (G. Madec)  Split dynber into dynkeg and dynhpg
+   !!            9.0  !  02-07  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   dyn_keg      : update the momentum trend with the horizontal tke
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_keg    ! routine called by step module
+   
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_keg( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_keg  ***
+      !!
+      !! ** Purpose :   Compute the now momentum trend due to the horizontal
+      !!      gradient of the horizontal kinetic energy and add it to the 
+      !!      general momentum trend.
+      !!
+      !! ** Method  :   Compute the now horizontal kinetic energy 
+      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
+      !!      Take its horizontal gradient and add it to the general momentum
+      !!      trend (ua,va).
+      !!         ua = ua - 1/e1u di[ zhke ]
+      !!         va = va - 1/e2v dj[ zhke ]
+      !!
+      !! ** Action : - Update the (ua, va) with the hor. ke gradient trend
+      !!             - save this trends (l_trddyn=T) for post-processing
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdu => ta   ! use ta as 3D workspace   
+      USE oce, ONLY :   ztrdv => sa   ! use sa as 3D workspace   
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zu, zv       ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhke   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_keg : kinetic energy gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      IF( l_trddyn ) THEN           ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
+      ENDIF
+      
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         DO jj = 2, jpj         ! Horizontal kinetic energy at T-point
+            DO ji = fs_2, jpi   ! vector opt.
+               zu = 0.25 * (  un(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)   &
+                  &         + un(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)  )
+               zv = 0.25 * (  vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)   &
+                  &         + vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)  )
+               zhke(ji,jj,jk) = zv + zu
+            END DO  
+         END DO  
+         DO jj = 2, jpjm1       ! add the gradient of kinetic energy to the general momentum trends
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) = ua(ji,jj,jk) - ( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) - ( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
+            END DO 
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF( l_trddyn ) THEN      ! save the Kinetic Energy trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_keg, 'DYN', kt )
+      ENDIF
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' keg  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_keg
+
+   !!======================================================================
+END MODULE dynkeg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 4536)
@@ -0,0 +1,191 @@
+MODULE dynldf
+   !!======================================================================
+   !!                       ***  MODULE  dynldf  ***
+   !! Ocean physics:  lateral diffusivity trends 
+   !!=====================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code (new step architecture)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf     : update the dynamics trend with the lateral diffusion
+   !!   dyn_ldf_ctl : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ldfdyn_oce     ! ocean dynamics lateral physics
+   USE ldfslp         ! lateral mixing: slopes of mixing orientation
+   USE dynldf_bilapg  ! lateral mixing            (dyn_ldf_bilapg routine)
+   USE dynldf_bilap   ! lateral mixing            (dyn_ldf_bilap  routine)
+   USE dynldf_iso     ! lateral mixing            (dyn_ldf_iso    routine)
+   USE dynldf_lap     ! lateral mixing            (dyn_ldf_lap    routine)
+   USE trdmod         ! ocean dynamics and tracer trends
+   USE trdmod_oce     ! ocean variables trends
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_ldf   ! called by step module 
+
+   INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_dynldf_... namlist logicals)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynldf.F90,v 1.4 2007/06/05 11:02:08 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_ldf  ***
+      !! 
+      !! ** Purpose :   compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL dyn_ldf_ctl      ! initialisation & control of options
+
+      IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
+      ENDIF
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )    ;   CALL dyn_ldf_lap    ( kt )      ! iso-level laplacian
+      CASE ( 1 )    ;   CALL dyn_ldf_iso    ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )    ;   CALL dyn_ldf_bilap  ( kt )      ! iso-level bilaplacian
+      CASE ( 3 )    ;   CALL dyn_ldf_bilapg ( kt )      ! s-coord. horizontal bilaplacian
+      !
+      CASE ( -1 )                                       ! esopa: test all possibility with control print
+                        CALL dyn_ldf_lap    ( kt )
+                        CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf0 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+                        CALL dyn_ldf_iso    ( kt )
+                        CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf1 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+                        CALL dyn_ldf_bilap  ( kt )
+                        CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf2 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+                        CALL dyn_ldf_bilapg ( kt )
+                        CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf3 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      END SELECT
+
+      IF( l_trddyn ) THEN                        ! save the horizontal diffusive trends for further diagnostics
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_ldf, 'DYN', kt )
+      ENDIF
+      !                                          ! print sum trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_ldf
+
+
+   SUBROUTINE dyn_ldf_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_ldf_ctl  ***
+      !! 
+      !! ** Purpose :   initializations of the horizontal ocean dynamics physics
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio, ierr         ! temporary integers 
+      !!----------------------------------------------------------------------
+    
+      !                                   ! Namelist nam_dynldf: already read in ldfdyn module
+
+      IF(lwp) THEN                        ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_ldf_ctl : Choice of the lateral diffusive operator on dynamics'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_dynldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_dynldf_lap   = ', ln_dynldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_dynldf_bilap = ', ln_dynldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_dynldf_level = ', ln_dynldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_dynldf_hor   = ', ln_dynldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_dynldf_iso   = ', ln_dynldf_iso
+      ENDIF
+
+      !                                   ! control the consistency
+      ioptio = 0
+      IF( ln_dynldf_lap   )   ioptio = ioptio + 1
+      IF( ln_dynldf_bilap )   ioptio = ioptio + 1
+      IF( ioptio /= 1 ) CALL ctl_stop( '          use ONE of the 2 lap/bilap operator type on dynamics' )
+      ioptio = 0
+      IF( ln_dynldf_level )   ioptio = ioptio + 1
+      IF( ln_dynldf_hor   )   ioptio = ioptio + 1
+      IF( ln_dynldf_iso   )   ioptio = ioptio + 1
+      IF( ioptio /= 1 ) CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
+
+      !                                   ! Set nldf, the type of lateral diffusion, from ln_dynldf_... logicals
+      ierr = 0
+      IF ( ln_dynldf_lap ) THEN      ! laplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   ierr = 1      ! iso-level not allowed
+            IF ( ln_dynldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 1      ! horizontal (   rotation)
+            IF ( ln_dynldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+      ENDIF
+
+      IF( ln_dynldf_bilap ) THEN      ! bilaplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   ierr = 1      ! iso-level not allowed 
+            IF ( ln_dynldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_dynldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_dynldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_dynldf_hor   )   nldf = 3      ! horizontal (   rotation)
+            IF ( ln_dynldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+      ENDIF
+      
+      IF( lk_esopa )                 nldf = -1     ! esopa test
+
+      IF( ierr == 1 )   CALL ctl_stop( 'iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 2 )   CALL ctl_stop( 'isoneutral bilaplacian operator does not exist' )
+      IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( 'the rotation of the diffusive tensor require key_ldfslp' )
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nldf == -1 )   WRITE(numout,*) '              ESOPA test All scheme used'
+         IF( nldf ==  0 )   WRITE(numout,*) '              laplacian operator'
+         IF( nldf ==  1 )   WRITE(numout,*) '              Rotated laplacian operator'
+         IF( nldf ==  2 )   WRITE(numout,*) '              bilaplacian operator'
+         IF( nldf ==  3 )   WRITE(numout,*) '              Rotated bilaplacian'
+      ENDIF
+      !
+   END SUBROUTINE dyn_ldf_ctl
+
+   !!======================================================================
+END MODULE dynldf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 4536)
@@ -0,0 +1,238 @@
+MODULE dynldf_bilap
+   !!======================================================================
+   !!                     ***  MODULE  dynldf_bilap  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf_bilap : update the momentum trend with the lateral diffusion
+   !!                   using an iso-level bilaplacian operator
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE in_out_manager  ! I/O manager
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_bilap  ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_bilap( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_bilap  ***
+      !!
+      !! ** Purpose :   Compute the before trend of the lateral momentum
+      !!      diffusion and add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   The before horizontal momentum diffusion trend is a 
+      !!      bi-harmonic operator (bilaplacian type) which separates the
+      !!      divergent and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!      laplacian:
+      !!          zlu = 1/e1u di[ hdivb ] - 1/(e2u*e3u) dj-1[ e3f rotb ]
+      !!          zlv = 1/e2v dj[ hdivb ] + 1/(e1v*e3v) di-1[ e3f rotb ]
+      !!      third derivative:
+      !!       * multiply by the eddy viscosity coef. at u-, v-point, resp.
+      !!          zlu = ahmu * zlu
+      !!          zlv = ahmv * zlv
+      !!       * curl and divergence of the laplacian
+      !!          zuf = 1/(e1f*e2f) ( di[e2v zlv] - dj[e1u zlu] )
+      !!          zut = 1/(e1t*e2t*e3t) ( di[e2u*e3u zlu] + dj[e1v*e3v zlv] )
+      !!      bilaplacian:
+      !!              diffu = 1/e1u di[ zut ] - 1/(e2u*e3u) dj-1[ e3f zuf ]
+      !!              diffv = 1/e2v dj[ zut ] + 1/(e1v*e3v) di-1[ e3f zuf ]
+      !!      If ln_sco=F and ln_zps=F, the vertical scale factors in the
+      !!      rotational part of the diffusion are simplified
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' defined: the two components of the horizontal
+      !!                               diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level biharmonic
+      !!               mixing trend.
+      !!
+      !! History :
+      !!        !  90-09  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions (M. Guyon)
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-07  (G. Madec)  lbc calls
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zua, zva, zbt, ze2u, ze2v ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zcu, zcv                             ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zuf, zut, zlu, zlv                   ! temporary workspace
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_bilap : iso-level bilaplacian operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+!!bug gm this should be enough
+!!$      zuf(:,:,jpk) = 0.e0
+!!$      zut(:,:,jpk) = 0.e0
+!!$      zlu(:,:,jpk) = 0.e0
+!!$      zlv(:,:,jpk) = 0.e0
+      zuf(:,:,:) = 0.e0
+      zut(:,:,:) = 0.e0
+      zlu(:,:,:) = 0.e0
+      zlv(:,:,:) = 0.e0
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Laplacian
+         ! ---------
+
+         IF( ln_sco .OR. ln_zps ) THEN   ! s-coordinate or z-coordinate with partial steps
+            zuf(:,:,jk) = rotb(:,:,jk) * fse3f(:,:,jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlu(ji,jj,jk) = - ( zuf(ji,jj,jk) - zuf(ji,jj-1,jk) ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )   &
+                     &         + ( hdivb(ji+1,jj,jk) - hdivb(ji,jj,jk) ) / e1u(ji,jj)
+   
+                  zlv(ji,jj,jk) = + ( zuf(ji,jj,jk) - zuf(ji-1,jj,jk) ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )   &
+                     &         + ( hdivb(ji,jj+1,jk) - hdivb(ji,jj,jk) ) / e2v(ji,jj)
+               END DO
+            END DO
+         ELSE                            ! z-coordinate - full step
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlu(ji,jj,jk) = - ( rotb (ji  ,jj,jk) - rotb (ji,jj-1,jk) ) / e2u(ji,jj)   &
+                     &         + ( hdivb(ji+1,jj,jk) - hdivb(ji,jj  ,jk) ) / e1u(ji,jj)
+   
+                  zlv(ji,jj,jk) = + ( rotb (ji,jj  ,jk) - rotb (ji-1,jj,jk) ) / e1v(ji,jj)   &
+                     &         + ( hdivb(ji,jj+1,jk) - hdivb(ji  ,jj,jk) ) / e2v(ji,jj)
+               END DO  
+            END DO  
+         ENDIF
+      ENDDO
+
+      ! Boundary conditions on the laplacian  (zlu,zlv)
+      CALL lbc_lnk( zlu, 'U', -1. )
+      CALL lbc_lnk( zlv, 'V', -1. )
+         
+         
+      DO jk = 1, jpkm1
+   
+         ! Third derivative
+         ! ----------------
+         
+         ! Multiply by the eddy viscosity coef. (at u- and v-points)
+         zlu(:,:,jk) = zlu(:,:,jk) * fsahmu(:,:,jk)
+         zlv(:,:,jk) = zlv(:,:,jk) * fsahmv(:,:,jk)
+         
+         ! Contravariant "laplacian"
+         zcu(:,:) = e1u(:,:) * zlu(:,:,jk)
+         zcv(:,:) = e2v(:,:) * zlv(:,:,jk)
+         
+         ! Laplacian curl ( * e3f if s-coordinates or z-coordinate with partial steps)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zuf(ji,jj,jk) = fmask(ji,jj,jk) * (  zcv(ji+1,jj  ) - zcv(ji,jj)      &
+                  &                            - zcu(ji  ,jj+1) + zcu(ji,jj)  )   &
+#if defined key_zco
+                  &                         / ( e1f(ji,jj)*e2f(ji,jj) )
+#else
+                  &       * fse3f(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
+#endif
+            END DO  
+         END DO  
+
+         ! Laplacian Horizontal fluxes
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+#if defined key_zco
+               zlu(ji,jj,jk) = e2u(ji,jj) * zlu(ji,jj,jk)
+               zlv(ji,jj,jk) = e1v(ji,jj) * zlv(ji,jj,jk)
+#else
+               zlu(ji,jj,jk) = e2u(ji,jj) * fse3u(ji,jj,jk) * zlu(ji,jj,jk)
+               zlv(ji,jj,jk) = e1v(ji,jj) * fse3v(ji,jj,jk) * zlv(ji,jj,jk)
+#endif
+            END DO
+         END DO
+
+         ! Laplacian divergence
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+#if defined key_zco
+               zbt = e1t(ji,jj) * e2t(ji,jj)
+#else
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+#endif
+               zut(ji,jj,jk) = (  zlu(ji,jj,jk) - zlu(ji-1,jj  ,jk)   &
+                  &             + zlv(ji,jj,jk) - zlv(ji  ,jj-1,jk) ) / zbt
+            END DO
+         END DO
+      END DO
+
+
+      ! boundary conditions on the laplacian curl and div (zuf,zut)
+!!bug gm no need to do this 2 following lbc...
+      CALL lbc_lnk( zuf, 'F', 1. )
+      CALL lbc_lnk( zut, 'T', 1. )
+
+      DO jk = 1, jpkm1      
+   
+         ! Bilaplacian
+         ! -----------
+
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               ze2u = e2u(ji,jj)
+               ze2v = e1v(ji,jj)
+#else
+               ze2u = e2u(ji,jj) * fse3u(ji,jj,jk)
+               ze2v = e1v(ji,jj) * fse3v(ji,jj,jk)
+#endif
+               ! horizontal biharmonic diffusive trends
+               zua = - ( zuf(ji  ,jj,jk) - zuf(ji,jj-1,jk) ) / ze2u   &
+                  &  + ( zut(ji+1,jj,jk) - zut(ji,jj  ,jk) ) / e1u(ji,jj)
+
+               zva = + ( zuf(ji,jj  ,jk) - zuf(ji-1,jj,jk) ) / ze2v   &
+                  &  + ( zut(ji,jj+1,jk) - zut(ji  ,jj,jk) ) / e2v(ji,jj)
+               ! add it to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_bilap
+
+   !!======================================================================
+END MODULE dynldf_bilap
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 4536)
@@ -0,0 +1,476 @@
+MODULE dynldf_bilapg
+   !!======================================================================
+   !!                       ***  MODULE  dynldf_bilapg  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!======================================================================
+#if defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'                              Rotation of mixing tensor
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf_bilapg : update the momentum trend with the horizontal part
+   !!                    of the horizontal s-coord. bilaplacian diffusion
+   !!   ldfguv         : 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldfdyn_oce      ! ocean dynamics lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE ldfslp          ! iso-neutral slopes available
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_bilapg ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_bilapg( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_ldf_bilapg  ***
+      !!                      
+      !! ** Purpose :   Compute the before trend of the horizontal momentum
+      !!      diffusion and add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   The lateral momentum diffusive trends is provided by a 
+      !!      a 4th order operator rotated along geopotential surfaces. It is 
+      !!      computed using before fields (forward in time) and geopotential
+      !!      slopes computed in routine inildf.
+      !!         -1- compute the geopotential harmonic operator applied to
+      !!      (ub,vb) and multiply it by the eddy diffusivity coefficient
+      !!      (done by a call to ldfgpu and ldfgpv routines) The result is in
+      !!      (zwk1,zwk2) arrays. Applied the domain lateral boundary conditions
+      !!      by call to lbc_lnk.
+      !!         -2- applied to (zwk1,zwk2) the geopotential harmonic operator
+      !!      by a second call to ldfgpu and ldfgpv routines respectively. The
+      !!      result is in (zwk3,zwk4) arrays.
+      !!         -3- Add this trend to the general trend (ta,sa):
+      !!            (ua,va) = (ua,va) + (zwk3,zwk4)
+      !!      'key_trddyn' defined: the trend is saved for diagnostics.
+      !!
+      !! ** Action  : - Update (ua,va) arrays with the before geopotential
+      !!                biharmonic mixing trend.
+      !!              - save the trend in (zwk3,zwk4) ('key_trddyn')
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!----------------------------------------------------------------------
+      !! * Modules used     
+      USE oce, ONLY :    zwk3 => ta,   & ! use ta as 3D workspace   
+                         zwk4 => sa      ! use sa as 3D workspace   
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwk1, zwk2                ! work array used for rotated biharmonic
+         !                         ! operator on tracers and/or momentum
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_bilapg : horizontal biharmonic operator in s-coordinate'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
+         zwk1(:,:,:) = 0.e0   ;   zwk3(:,:,:) = 0.e0
+         zwk2(:,:,:) = 0.e0   ;   zwk4(:,:,:) = 0.e0
+      ENDIF
+
+      ! Laplacian of (ub,vb) multiplied by ahm
+      ! --------------------------------------  
+      ! rotated harmonic operator applied to (ub,vb)
+      !     and multiply by ahmu, ahmv (output in (zwk1,zwk2) )
+
+      CALL ldfguv ( ub, vb, zwk1, zwk2, 1 )
+
+
+      ! Lateral boundary conditions on (zwk1,zwk2)
+      CALL lbc_lnk( zwk1, 'U', -1. )
+      CALL lbc_lnk( zwk2, 'V', -1. )
+
+
+      ! Bilaplacian of (ub,vb)
+      ! ---------------------- 
+      ! rotated harmonic operator applied to (zwk1,zwk2) (output in (zwk3,zwk4) )
+
+      CALL ldfguv ( zwk1, zwk2, zwk3, zwk4, 2 )
+
+
+      ! Update the momentum trends			   (j-slab :   2, jpj-1)
+      ! --------------------------
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ! add the diffusive trend to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zwk3(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) + zwk4(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_bilapg
+
+
+   SUBROUTINE ldfguv( pu, pv, plu, plv, kahm )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldfguv  ***
+      !!      
+      !! ** Purpose :   Apply a geopotential harmonic operator to (pu,pv)
+      !!      (defined at u- and v-points) and multiply it by the eddy
+      !!      viscosity coefficient (if kahm=1).
+      !!
+      !! ** Method  :   The harmonic operator rotated along geopotential 
+      !!      surfaces is applied to (pu,pv) using the slopes of geopotential
+      !!      surfaces computed in inildf routine. The result is provided in
+      !!      (plu,plv) arrays. It is computed in 2 stepv:
+      !!
+      !!      First step: horizontal part of the operator. It is computed on
+      !!      ==========  pu as follows (idem on pv)
+      !!      horizontal fluxes :
+      !!         zftu = e2u*e3u/e1u di[ pu ] - e2u*uslp dk[ mi(mk(pu)) ]
+      !!         zftv = e1v*e3v/e2v dj[ pu ] - e1v*vslp dk[ mj(mk(pu)) ]
+      !!      take the horizontal divergence of the fluxes (no divided by
+      !!      the volume element :
+      !!         plu  = di-1[ zftu ] +  dj-1[ zftv ]
+      !!
+      !!      Second step: vertical part of the operator. It is computed on
+      !!      ===========  pu as follows (idem on pv)
+      !!      vertical fluxes :
+      !!         zftw = e1t*e2t/e3w * (wslpi^2+wslpj^2)  dk-1[ pu ]
+      !!              -     e2t     *       wslpi        di[ mi(mk(pu)) ]
+      !!              -     e1t     *       wslpj        dj[ mj(mk(pu)) ]
+      !!      take the vertical divergence of the fluxes add it to the hori-
+      !!      zontal component, divide the result by the volume element and
+      !!      if kahm=1, multiply by the eddy diffusivity coefficient:
+      !!         plu  = aht / (e1t*e2t*e3t) { plu + dk[ zftw ] }
+      !!      else:
+      !!         plu  =  1  / (e1t*e2t*e3t) { plu + dk[ zftw ] }
+      !!
+      !! ** Action :
+      !!        plu, plv        : partial harmonic operator applied to
+      !!                          pu and pv (all the components except
+      !!                          second order vertical derivative term)
+      !!      'key_trddyn' defined: the trend is saved for diagnostics.
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         pu, pv     ! momentum fields (before u and v for the 1st call, and
+      !             ! laplacian of these fields multiplied by ahm for the 2nd
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         plu, plv   ! partial harmonic operator applied to
+      !             ! pu and pv (all the components except
+      !             ! second order vertical derivative term)
+      INTEGER, INTENT( in ) ::   &
+         kahm       ! =1 the laplacian is multiplied by the eddy diffusivity coef.
+      !             ! =2 no multiplication
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   &
+         zabe1, zabe2, zcof1, zcof2,    &  ! temporary scalars
+         zcoef0, zcoef3, zcoef4
+      REAL(wp) ::   &
+         zbur, zbvr, zmkt, zmkf, zuav, zvav,    &
+         zuwslpi, zuwslpj, zvwslpi, zvwslpj
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ziut, zjuf , zjvt, zivf,       &  ! workspace
+         zdku, zdk1u, zdkv, zdk1v
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         zfuw, zfvw, zdiu, zdiv,        &  ! workspace
+         zdju, zdj1u, zdjv, zdj1v 
+      !!----------------------------------------------------------------------
+
+      !                               ! ********** !   ! ===============
+      DO jk = 1, jpkm1                ! First step !   ! Horizontal slab
+         !                            ! ********** !   ! ===============
+
+         ! I.1 Vertical gradient of pu and pv at level jk and jk+1
+         ! -------------------------------------------------------
+         ! surface boundary condition: zdku(jk=1)=zdku(jk=2)
+         !                             zdkv(jk=1)=zdkv(jk=2)
+
+         zdk1u(:,:) = ( pu(:,:,jk) - pu(:,:,jk+1) ) * umask(:,:,jk+1)
+         zdk1v(:,:) = ( pv(:,:,jk) - pv(:,:,jk+1) ) * vmask(:,:,jk+1)
+
+         IF( jk == 1 ) THEN
+            zdku(:,:) = zdk1u(:,:)
+            zdkv(:,:) = zdk1v(:,:)
+         ELSE
+            zdku(:,:) = ( pu(:,:,jk-1) - pu(:,:,jk) ) * umask(:,:,jk)
+            zdkv(:,:) = ( pv(:,:,jk-1) - pv(:,:,jk) ) * vmask(:,:,jk)
+         ENDIF
+
+         !                                -----f-----
+         ! I.2 Horizontal fluxes on U          |
+         ! ------------------------===     t   u   t
+         !                                     |
+         ! i-flux at t-point              -----f-----
+         DO jj = 1, jpjm1
+            DO ji = 2, jpi
+               zabe1 = e2t(ji,jj) * fse3t(ji,jj,jk) / e1t(ji,jj)
+
+               zmkt  = 1./MAX(  umask(ji-1,jj,jk  )+umask(ji,jj,jk+1)   &
+                              + umask(ji-1,jj,jk+1)+umask(ji,jj,jk  ), 1. )
+
+               zcof1 = -e2t(ji,jj) * zmkt   &
+                     * 0.5  * ( uslp(ji-1,jj,jk) + uslp(ji,jj,jk) )
+
+               ziut(ji,jj) = tmask(ji,jj,jk) *   &
+                           (  zabe1 * ( pu(ji,jj,jk) - pu(ji-1,jj,jk) )   &
+                            + zcof1 * ( zdku (ji,jj) + zdk1u(ji-1,jj)     &
+                                       +zdk1u(ji,jj) + zdku (ji-1,jj) )  )
+            END DO
+         END DO
+
+         ! j-flux at f-point
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zabe2 = e1f(ji,jj) * fse3f(ji,jj,jk) / e2f(ji,jj)
+
+               zmkf  = 1./MAX(  umask(ji,jj+1,jk  )+umask(ji,jj,jk+1)   &
+                              + umask(ji,jj+1,jk+1)+umask(ji,jj,jk  ), 1. )
+
+               zcof2 = -e1f(ji,jj) * zmkf   &
+                     * 0.5  * ( vslp(ji+1,jj,jk) + vslp(ji,jj,jk) )
+
+               zjuf(ji,jj) = fmask(ji,jj,jk) *   &
+                           (  zabe2 * ( pu(ji,jj+1,jk) - pu(ji,jj,jk) )   &
+                            + zcof2 * ( zdku (ji,jj+1) + zdk1u(ji,jj)     &
+                                       +zdk1u(ji,jj+1) + zdku (ji,jj) )  )
+            END DO
+         END DO
+
+         !                                 |   t   |
+         ! I.3 Horizontal fluxes on V      |       |
+         ! ------------------------===     f---v---f
+         !                                 |       |
+         ! i-flux at f-point               |   t   |
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zabe1 = e2f(ji,jj) * fse3f(ji,jj,jk) / e1f(ji,jj)
+
+               zmkf  = 1./MAX(  vmask(ji+1,jj,jk  )+vmask(ji,jj,jk+1)   &
+                              + vmask(ji+1,jj,jk+1)+vmask(ji,jj,jk  ), 1. )
+
+               zcof1 = -e2f(ji,jj) * zmkf   &
+                     * 0.5 * ( uslp(ji,jj+1,jk) + uslp(ji,jj,jk) )
+
+               zivf(ji,jj) = fmask(ji,jj,jk) *   &
+                           (  zabe1 * ( pu(ji+1,jj,jk) - pu(ji,jj,jk) )   &
+                            + zcof1 * ( zdku (ji,jj) + zdk1u(ji+1,jj)     &
+                                       +zdk1u(ji,jj) + zdku (ji+1,jj) )  )
+            END DO
+         END DO
+
+         ! j-flux at t-point
+         DO jj = 2, jpj
+            DO ji = 1, jpim1
+               zabe2 = e1t(ji,jj) * fse3t(ji,jj,jk) / e2t(ji,jj)
+
+               zmkt  = 1./MAX(  vmask(ji,jj-1,jk  )+vmask(ji,jj,jk+1)   &
+                              + vmask(ji,jj-1,jk+1)+vmask(ji,jj,jk  ), 1. )
+
+               zcof2 = -e1t(ji,jj) * zmkt   &
+                     * 0.5 * ( vslp(ji,jj-1,jk) + vslp(ji,jj,jk) )
+
+               zjvt(ji,jj) = tmask(ji,jj,jk) *   &
+                           (  zabe2 * ( pu(ji,jj,jk) - pu(ji,jj-1,jk) )   &
+                            + zcof2 * ( zdku (ji,jj-1) + zdk1u(ji,jj)     &
+                                       +zdk1u(ji,jj-1) + zdku (ji,jj) )  )
+            END DO
+         END DO
+
+
+         ! I.4 Second derivative (divergence) (not divided by the volume)
+         ! ---------------------
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               plu(ji,jj,jk) = ziut (ji+1,jj) - ziut (ji,jj  )   &
+                             + zjuf (ji  ,jj) - zjuf (ji,jj-1)
+               plv(ji,jj,jk) = zivf (ji,jj  ) - zivf (ji-1,jj)   &
+                             + zjvt (ji,jj+1) - zjvt (ji,jj  ) 
+            END DO
+         END DO
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      !                             ! ************ !   ! ===============
+      DO jj = 2, jpjm1              !  Second step !   ! Horizontal slab
+         !                          ! ************ !   ! ===============
+
+         ! II.1 horizontal (pu,pv) gradients
+         ! ---------------------------------
+
+         DO jk = 1, jpk
+            DO ji = 2, jpi
+               ! i-gradient of u at jj
+               zdiu (ji,jk) = tmask(ji,jj  ,jk) * ( pu(ji,jj  ,jk) - pu(ji-1,jj  ,jk) )
+               ! j-gradient of u and v at jj
+               zdju (ji,jk) = fmask(ji,jj  ,jk) * ( pu(ji,jj+1,jk) - pu(ji  ,jj  ,jk) )
+               zdjv (ji,jk) = tmask(ji,jj  ,jk) * ( pv(ji,jj  ,jk) - pv(ji  ,jj-1,jk) )
+               ! j-gradient of u and v at jj+1
+               zdj1u(ji,jk) = fmask(ji,jj-1,jk) * ( pu(ji,jj  ,jk) - pu(ji  ,jj-1,jk) )
+               zdj1v(ji,jk) = tmask(ji,jj+1,jk) * ( pv(ji,jj+1,jk) - pv(ji  ,jj  ,jk) )
+            END DO
+         END DO
+         DO jk = 1, jpk
+            DO ji = 1, jpim1
+               ! i-gradient of v at jj
+               zdiv (ji,jk) = fmask(ji,jj  ,jk) * ( pv(ji+1,jj,jk) - pv(ji  ,jj  ,jk) )
+            END DO
+         END DO
+
+
+         ! II.2 Vertical fluxes
+         ! --------------------
+
+         ! Surface and bottom vertical fluxes set to zero
+
+         zfuw(:, 1 ) = 0.e0
+         zfvw(:, 1 ) = 0.e0
+         zfuw(:,jpk) = 0.e0
+         zfvw(:,jpk) = 0.e0
+
+         ! interior (2=<jk=<jpk-1) on pu field
+
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               ! i- and j-slopes at uw-point
+               zuwslpi = 0.5 * ( wslpi(ji+1,jj,jk) + wslpi(ji,jj,jk) )
+               zuwslpj = 0.5 * ( wslpj(ji+1,jj,jk) + wslpj(ji,jj,jk) )
+               ! coef. for the vertical dirative
+               zcoef0 = e1u(ji,jj) * e2u(ji,jj) / fse3u(ji,jj,jk)   &
+                      * ( zuwslpi * zuwslpi + zuwslpj * zuwslpj )
+               ! weights for the i-k, j-k averaging at t- and f-points, resp.
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji+1,jj,jk-1)   &
+                             + tmask(ji,jj,jk  )+tmask(ji+1,jj,jk  ), 1. )
+               zmkf = 1./MAX(  fmask(ji,jj-1,jk-1)+fmask(ji,jj,jk-1)   &
+                             + fmask(ji,jj-1,jk  )+fmask(ji,jj,jk  ), 1. )
+               ! coef. for the horitontal derivative
+               zcoef3 = - e2u(ji,jj) * zmkt * zuwslpi
+               zcoef4 = - e1u(ji,jj) * zmkf * zuwslpj
+               ! vertical flux on u field
+               zfuw(ji,jk) = umask(ji,jj,jk) *   &
+                           (  zcoef0 * ( pu  (ji,jj,jk-1) - pu  (ji,jj,jk) )   &
+                            + zcoef3 * ( zdiu (ji,jk-1) + zdiu (ji+1,jk-1)     &
+                                        +zdiu (ji,jk  ) + zdiu (ji+1,jk  ) )   &
+                            + zcoef4 * ( zdj1u(ji,jk-1) + zdju (ji  ,jk-1)     &
+                                        +zdj1u(ji,jk  ) + zdju (ji  ,jk  ) ) )
+            END DO
+         END DO
+
+         ! interior (2=<jk=<jpk-1) on pv field
+
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               ! i- and j-slopes at vw-point
+               zvwslpi = 0.5 * ( wslpi(ji,jj+1,jk) + wslpi(ji,jj,jk) )
+               zvwslpj = 0.5 * ( wslpj(ji,jj+1,jk) + wslpj(ji,jj,jk) )
+               ! coef. for the vertical derivative
+               zcoef0 = e1v(ji,jj) * e2v(ji,jj) / fse3v(ji,jj,jk)   &
+                      * ( zvwslpi * zvwslpi + zvwslpj * zvwslpj )
+               ! weights for the i-k, j-k averaging at f- and t-points, resp.
+               zmkf = 1./MAX(  fmask(ji-1,jj,jk-1)+fmask(ji,jj,jk-1)   &
+                             + fmask(ji-1,jj,jk  )+fmask(ji,jj,jk  ), 1. )
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji,jj+1,jk-1)   &
+                             + tmask(ji,jj,jk  )+tmask(ji,jj+1,jk  ), 1. )
+               ! coef. for the horizontal derivatives
+               zcoef3 = - e2v(ji,jj) * zmkf * zvwslpi
+               zcoef4 = - e1v(ji,jj) * zmkt * zvwslpj
+               ! vertical flux on pv field
+               zfvw(ji,jk) = vmask(ji,jj,jk) *   &
+                           (  zcoef0 * ( pv  (ji,jj,jk-1) - pv  (ji,jj,jk) )   &
+                            + zcoef3 * ( zdiv (ji,jk-1) + zdiv (ji-1,jk-1)     &
+                                        +zdiv (ji,jk  ) + zdiv (ji-1,jk  ) )   &
+                            + zcoef4 * ( zdjv (ji,jk-1) + zdj1v(ji  ,jk-1)     &
+                                        +zdjv (ji,jk  ) + zdj1v(ji  ,jk  ) )  )
+            END DO
+         END DO
+
+
+         ! II.3 Divergence of vertical fluxes added to the horizontal divergence
+         ! ---------------------------------------------------------------------
+
+         IF( kahm == 1 ) THEN
+            ! multiply the laplacian by the eddy viscosity coefficient
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ! eddy coef. divided by the volume element
+                  zbur = fsahmu(ji,jj,jk) / ( e1u(ji,jj)*e2u(ji,jj)*fse3u(ji,jj,jk) )
+                  zbvr = fsahmv(ji,jj,jk) / ( e1v(ji,jj)*e2v(ji,jj)*fse3v(ji,jj,jk) )
+                  ! vertical divergence
+                  zuav = zfuw(ji,jk) - zfuw(ji,jk+1)
+                  zvav = zfvw(ji,jk) - zfvw(ji,jk+1)
+                  ! harmonic operator applied to (pu,pv) and multiply by ahm
+                  plu(ji,jj,jk) = ( plu(ji,jj,jk) + zuav ) * zbur
+                  plv(ji,jj,jk) = ( plv(ji,jj,jk) + zvav ) * zbvr
+               END DO
+            END DO
+         ELSEIF( kahm == 2 ) THEN
+            ! second call, no multiplication
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ! inverse of the volume element
+                  zbur = 1. / ( e1u(ji,jj)*e2u(ji,jj)*fse3u(ji,jj,jk) )
+                  zbvr = 1. / ( e1v(ji,jj)*e2v(ji,jj)*fse3v(ji,jj,jk) )
+                  ! vertical divergence
+                  zuav = zfuw(ji,jk) - zfuw(ji,jk+1)
+                  zvav = zfvw(ji,jk) - zfvw(ji,jk+1)
+                  ! harmonic operator applied to (pu,pv) 
+                  plu(ji,jj,jk) = ( plu(ji,jj,jk) + zuav ) * zbur
+                  plv(ji,jj,jk) = ( plv(ji,jj,jk) + zvav ) * zbvr
+               END DO
+            END DO
+         ELSE
+            IF(lwp)WRITE(numout,*) ' ldfguv: kahm= 1 or 2, here =', kahm
+            IF(lwp)WRITE(numout,*) '         We stop'
+            STOP 'ldfguv'
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE ldfguv
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                         NO rotation of mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_ldf_bilapg( kt )               ! Dummy routine
+      WRITE(*,*) 'dyn_ldf_bilapg: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_ldf_bilapg
+#endif
+
+   !!======================================================================
+END MODULE dynldf_bilapg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_iso.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 4536)
@@ -0,0 +1,433 @@
+MODULE dynldf_iso
+   !!======================================================================
+   !!                     ***  MODULE  dynldf_iso  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!======================================================================
+#if defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'                      slopes of the direction of mixing
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf_iso  : update the momentum trend with the horizontal part
+   !!                  of the lateral diffusion using isopycnal or horizon-
+   !!                  tal s-coordinate laplacian operator.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldfdyn_oce      ! ocean dynamics lateral physics
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE ldfslp          ! iso-neutral slopes 
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_iso           ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_iso( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_iso  ***
+      !!                       
+      !! ** Purpose :   Compute the before trend of the rotated laplacian
+      !!      operator of lateral momentum diffusion except the diagonal
+      !!      vertical term that will be computed in dynzdf module. Add it
+      !!      to the general trend of momentum equation.
+      !!
+      !! ** Method :
+      !!        The momentum lateral diffusive trend is provided by a 2nd
+      !!      order operator rotated along neutral or geopotential surfaces
+      !!      (in s-coordinates).
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!      Here, u and v components are considered as 2 independent scalar
+      !!      fields. Therefore, the property of splitting divergent and rota-
+      !!      tional part of the flow of the standard, z-coordinate laplacian
+      !!      momentum diffusion is lost.
+      !!      horizontal fluxes associated with the rotated lateral mixing:
+      !!      u-component:
+      !!         ziut = ( ahmt + ahmb0 ) e2t * e3t / e1t  di[ ub ]
+      !!               -      ahmt       e2t * mi-1(uslp) dk[ mi(mk(ub)) ]
+      !!         zjuf = ( ahmf + ahmb0 ) e1f * e3f / e2f  dj[ ub ]
+      !!               -      ahmf       e1f * mi(vslp)   dk[ mj(mk(ub)) ]
+      !!      v-component:
+      !!         zivf = ( ahmf + ahmb0 ) e2t * e3t / e1t  di[ vb ]
+      !!               -      ahmf       e2t * mj(uslp)   dk[ mi(mk(vb)) ]
+      !!         zjvt = ( ahmt + ahmb0 ) e1f * e3f / e2f  dj[ ub ]
+      !!               -      ahmt       e1f * mj-1(vslp) dk[ mj(mk(vb)) ]
+      !!      take the horizontal divergence of the fluxes:
+      !!         diffu = 1/(e1u*e2u*e3u) {  di  [ ziut ] + dj-1[ zjuf ]  }
+      !!         diffv = 1/(e1v*e2v*e3v) {  di-1[ zivf ] + dj  [ zjvt ]  }
+      !!      Add this trend to the general trend (ua,va):
+      !!         ua = ua + diffu
+      !!      CAUTION: here the isopycnal part is with a coeff. of aht. This
+      !!      should be modified for applications others than orca_r2 (!!bug)
+      !!
+      !! ** Action :
+      !!        Update (ua,va) arrays with the before geopotential biharmonic
+      !!      mixing trend.
+      !!        Update (avmu,avmv) to accompt for the diagonal vertical component
+      !!      of the rotated operator in dynzdf module
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!        !  05-11  (G. Madec)  s-coordinate: horizontal diffusion
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   &
+         zabe1, zabe2, zcof1, zcof2,   &  ! temporary scalars
+         zmskt, zmskf, zbu, zbv,       &
+         zuah, zvah
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ziut, zjuf, zjvt, zivf,        & ! temporary workspace
+         zdku, zdk1u, zdkv, zdk1v
+
+      REAL(wp) ::   &
+         zcoef0, zcoef3, zcoef4, zmkt, zmkf,   &
+         zuav, zvav, zuwslpi, zuwslpj, zvwslpi, zvwslpj
+      REAL(wp), DIMENSION(jpi,jpk) ::        &
+         zfuw, zdiu, zdju, zdj1u,            & !    "        "
+         zfvw, zdiv, zdjv, zdj1v
+
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf_iso : iso-neutral laplacian diffusive operator or '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   s-coordinate horizontal diffusive operator'
+      ENDIF
+
+!     ! s-coordinate: Iso-level diffusion on momentum but not on tracer
+      IF( ln_dynldf_hor .AND. ln_traldf_iso ) THEN
+ 
+         ! set the slopes of iso-level
+         DO jk = 1, jpk
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  uslp (ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept(ji+1,jj,jk) - fsdept(ji ,jj ,jk) ) * umask(ji,jj,jk)
+                  vslp (ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept(ji,jj+1,jk) - fsdept(ji ,jj ,jk) ) * vmask(ji,jj,jk)
+                  wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw(ji+1,jj,jk) - fsdepw(ji-1,jj,jk) ) * tmask(ji,jj,jk) * 0.5
+                  wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw(ji,jj+1,jk) - fsdepw(ji,jj-1,jk) ) * tmask(ji,jj,jk) * 0.5
+               END DO
+            END DO
+         END DO
+ 
+         ! Lateral boundary conditions on the slopes
+         CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
+         CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
+ 
+!!bug
+         if( kt == nit000 ) then
+            IF(lwp) WRITE(numout,*) ' max slop: u',SQRT( MAXVAL(uslp*uslp)), ' v ', SQRT(MAXVAL(vslp)),  &
+               &                             ' wi', sqrt(MAXVAL(wslpi)), ' wj', sqrt(MAXVAL(wslpj))
+         endif
+!!end
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! Vertical u- and v-shears at level jk and jk+1
+         ! ---------------------------------------------
+         ! surface boundary condition: zdku(jk=1)=zdku(jk=2)
+         !                             zdkv(jk=1)=zdkv(jk=2)
+
+         zdk1u(:,:) = ( ub(:,:,jk) -ub(:,:,jk+1) ) * umask(:,:,jk+1)
+         zdk1v(:,:) = ( vb(:,:,jk) -vb(:,:,jk+1) ) * vmask(:,:,jk+1)
+
+         IF( jk == 1 ) THEN
+            zdku(:,:) = zdk1u(:,:)
+            zdkv(:,:) = zdk1v(:,:)
+         ELSE
+            zdku(:,:) = ( ub(:,:,jk-1) - ub(:,:,jk) ) * umask(:,:,jk)
+            zdkv(:,:) = ( vb(:,:,jk-1) - vb(:,:,jk) ) * vmask(:,:,jk)
+         ENDIF
+
+         !                               -----f-----
+         ! Horizontal fluxes on U             |  
+         ! --------------------===        t   u   t
+         !                                    |  
+         ! i-flux at t-point             -----f-----
+
+         IF( ln_zps ) THEN      ! z-coordinate - partial steps : min(e3u)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, jpi   ! vector opt.
+                  zabe1 = (fsahmt(ji,jj,jk)+ahmb0) * e2t(ji,jj) * MIN( fse3u(ji,jj,jk), fse3u(ji-1,jj,jk) ) / e1t(ji,jj)
+
+                  zmskt = 1./MAX(  umask(ji-1,jj,jk  )+umask(ji,jj,jk+1)   &
+                     &           + umask(ji-1,jj,jk+1)+umask(ji,jj,jk  ), 1. )
+
+                  zcof1 = - aht0 * e2t(ji,jj) * zmskt * 0.5  * ( uslp(ji-1,jj,jk) + uslp(ji,jj,jk) )
+   
+                  ziut(ji,jj) = (  zabe1 * ( ub(ji,jj,jk) - ub(ji-1,jj,jk) )   &
+                     &           + zcof1 * ( zdku (ji,jj) + zdk1u(ji-1,jj)     &
+                     &                      +zdk1u(ji,jj) + zdku (ji-1,jj) )  ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         ELSE                   ! other coordinate system (zco or sco) : e3t
+            DO jj = 2, jpjm1
+               DO ji = fs_2, jpi   ! vector opt.
+                  zabe1 = (fsahmt(ji,jj,jk)+ahmb0) * e2t(ji,jj) * fse3t(ji,jj,jk) / e1t(ji,jj)
+
+                  zmskt = 1./MAX(  umask(ji-1,jj,jk  )+umask(ji,jj,jk+1)   &
+                     &           + umask(ji-1,jj,jk+1)+umask(ji,jj,jk  ), 1. )
+
+                  zcof1 = - aht0 * e2t(ji,jj) * zmskt * 0.5  * ( uslp(ji-1,jj,jk) + uslp(ji,jj,jk) )
+
+                  ziut(ji,jj) = (  zabe1 * ( ub(ji,jj,jk) - ub(ji-1,jj,jk) )   &
+                     &           + zcof1 * ( zdku (ji,jj) + zdk1u(ji-1,jj)     &
+                     &                      +zdk1u(ji,jj) + zdku (ji-1,jj) )  ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! j-flux at f-point
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zabe2 = ( fsahmf(ji,jj,jk) + ahmb0 ) * e1f(ji,jj) * fse3f(ji,jj,jk) / e2f(ji,jj)
+
+               zmskf = 1./MAX(  umask(ji,jj+1,jk  )+umask(ji,jj,jk+1)   &
+                  &           + umask(ji,jj+1,jk+1)+umask(ji,jj,jk  ), 1. )
+
+               zcof2 = - aht0 * e1f(ji,jj) * zmskf * 0.5  * ( vslp(ji+1,jj,jk) + vslp(ji,jj,jk) )
+
+               zjuf(ji,jj) = (  zabe2 * ( ub(ji,jj+1,jk) - ub(ji,jj,jk) )   &
+                  &           + zcof2 * ( zdku (ji,jj+1) + zdk1u(ji,jj)     &
+                  &                      +zdk1u(ji,jj+1) + zdku (ji,jj) )  ) * fmask(ji,jj,jk)
+            END DO
+         END DO
+
+         !                                |   t   |
+         ! Horizontal fluxes on V         |       |
+         ! --------------------===        f---v---f
+         !                                |       |
+         ! i-flux at f-point              |   t   |
+
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zabe1 = ( fsahmf(ji,jj,jk) + ahmb0 ) * e2f(ji,jj) * fse3f(ji,jj,jk) / e1f(ji,jj)
+
+               zmskf = 1./MAX(  vmask(ji+1,jj,jk  )+vmask(ji,jj,jk+1)   &
+                  &           + vmask(ji+1,jj,jk+1)+vmask(ji,jj,jk  ), 1. )
+
+               zcof1 = - aht0 * e2f(ji,jj) * zmskf * 0.5 * ( uslp(ji,jj+1,jk) + uslp(ji,jj,jk) )
+
+               zivf(ji,jj) = (  zabe1 * ( vb(ji+1,jj,jk) - vb(ji,jj,jk) )   &
+                  &           + zcof1 * ( zdkv (ji,jj) + zdk1v(ji+1,jj)     &
+                  &                      +zdk1v(ji,jj) + zdkv (ji+1,jj) )  ) * fmask(ji,jj,jk)
+            END DO
+         END DO
+
+         ! j-flux at t-point
+         IF( ln_zps ) THEN      ! z-coordinate - partial steps : min(e3u)
+            DO jj = 2, jpj
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zabe2 = (fsahmt(ji,jj,jk)+ahmb0) * e1t(ji,jj) * MIN( fse3v(ji,jj,jk), fse3v(ji,jj-1,jk) ) / e2t(ji,jj)
+
+                  zmskt = 1./MAX(  vmask(ji,jj-1,jk  )+vmask(ji,jj,jk+1)   &
+                     &           + vmask(ji,jj-1,jk+1)+vmask(ji,jj,jk  ), 1. )
+
+                  zcof2 = - aht0 * e1t(ji,jj) * zmskt * 0.5 * ( vslp(ji,jj-1,jk) + vslp(ji,jj,jk) )
+
+                  zjvt(ji,jj) = (  zabe2 * ( vb(ji,jj,jk) - vb(ji,jj-1,jk) )   &
+                     &           + zcof2 * ( zdkv (ji,jj-1) + zdk1v(ji,jj)     &
+                     &                      +zdk1v(ji,jj-1) + zdkv (ji,jj) )  ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         ELSE                   ! other coordinate system (zco or sco) : e3t
+            DO jj = 2, jpj
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zabe2 = (fsahmt(ji,jj,jk)+ahmb0) * e1t(ji,jj) * fse3t(ji,jj,jk) / e2t(ji,jj)
+
+                  zmskt = 1./MAX(  vmask(ji,jj-1,jk  )+vmask(ji,jj,jk+1)   &
+                     &           + vmask(ji,jj-1,jk+1)+vmask(ji,jj,jk  ), 1. )
+
+                  zcof2 = - aht0 * e1t(ji,jj) * zmskt * 0.5 * ( vslp(ji,jj-1,jk) + vslp(ji,jj,jk) )
+
+                  zjvt(ji,jj) = (  zabe2 * ( vb(ji,jj,jk) - vb(ji,jj-1,jk) )   &
+                     &           + zcof2 * ( zdkv (ji,jj-1) + zdk1v(ji,jj)     &
+                     &                      +zdk1v(ji,jj-1) + zdkv (ji,jj) )  ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+
+         ! Second derivative (divergence) and add to the general trend
+         ! -----------------------------------------------------------
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1          !! Question vectop possible??? !!bug
+               ! volume elements
+               zbu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               zbv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+               ! horizontal component of isopycnal momentum diffusive trends
+               zuah =( ziut (ji+1,jj) - ziut (ji,jj  ) +   &
+                  &    zjuf (ji  ,jj) - zjuf (ji,jj-1)  ) / zbu
+               zvah =( zivf (ji,jj  ) - zivf (ji-1,jj) +   &
+                  &    zjvt (ji,jj+1) - zjvt (ji,jj  )  ) / zbv
+               ! add the trends to the general trends
+               ua (ji,jj,jk) = ua (ji,jj,jk) + zuah
+               va (ji,jj,jk) = va (ji,jj,jk) + zvah
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! print sum trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' ldfh - Ua: ', mask1=umask, &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+
+ 
+         ! I. vertical trends associated with the lateral mixing
+         ! =====================================================
+         !  (excluding the vertical flux proportional to dk[t]
+
+
+         ! I.1 horizontal momentum gradient
+         ! --------------------------------
+
+         DO jk = 1, jpk
+            DO ji = 2, jpi
+               ! i-gradient of u at jj
+               zdiu (ji,jk) = tmask(ji,jj  ,jk) * ( ub(ji,jj  ,jk) - ub(ji-1,jj  ,jk) )
+               ! j-gradient of u and v at jj
+               zdju (ji,jk) = fmask(ji,jj  ,jk) * ( ub(ji,jj+1,jk) - ub(ji  ,jj  ,jk) )
+               zdjv (ji,jk) = tmask(ji,jj  ,jk) * ( vb(ji,jj  ,jk) - vb(ji  ,jj-1,jk) )
+               ! j-gradient of u and v at jj+1
+               zdj1u(ji,jk) = fmask(ji,jj-1,jk) * ( ub(ji,jj  ,jk) - ub(ji  ,jj-1,jk) )
+               zdj1v(ji,jk) = tmask(ji,jj+1,jk) * ( vb(ji,jj+1,jk) - vb(ji  ,jj  ,jk) )
+            END DO
+         END DO
+         DO jk = 1, jpk
+            DO ji = 1, jpim1
+               ! i-gradient of v at jj
+               zdiv (ji,jk) = fmask(ji,jj  ,jk) * ( vb(ji+1,jj,jk) - vb(ji  ,jj  ,jk) )
+            END DO
+         END DO
+
+
+         ! I.2 Vertical fluxes
+         ! -------------------
+
+         ! Surface and bottom vertical fluxes set to zero
+         DO ji = 1, jpi
+            zfuw(ji, 1 ) = 0.e0
+            zfvw(ji, 1 ) = 0.e0
+            zfuw(ji,jpk) = 0.e0
+            zfvw(ji,jpk) = 0.e0
+         END DO
+
+         ! interior (2=<jk=<jpk-1) on U field
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               zcoef0= 0.5 * aht0 * umask(ji,jj,jk)
+
+               zuwslpi = zcoef0 * ( wslpi(ji+1,jj,jk) + wslpi(ji,jj,jk) )
+               zuwslpj = zcoef0 * ( wslpj(ji+1,jj,jk) + wslpj(ji,jj,jk) )
+
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji+1,jj,jk-1)   &
+                             + tmask(ji,jj,jk  )+tmask(ji+1,jj,jk  ), 1. )
+               zmkf = 1./MAX(  fmask(ji,jj-1,jk-1)+fmask(ji,jj,jk-1)   &
+                             + fmask(ji,jj-1,jk  )+fmask(ji,jj,jk  ), 1. )
+
+               zcoef3 = - e2u(ji,jj) * zmkt * zuwslpi
+               zcoef4 = - e1u(ji,jj) * zmkf * zuwslpj
+               ! vertical flux on u field
+               zfuw(ji,jk) = zcoef3 * ( zdiu (ji,jk-1) + zdiu (ji+1,jk-1)     &
+                                       +zdiu (ji,jk  ) + zdiu (ji+1,jk  ) )   &
+                           + zcoef4 * ( zdj1u(ji,jk-1) + zdju (ji  ,jk-1)     &
+                                       +zdj1u(ji,jk  ) + zdju (ji  ,jk  ) )
+               ! update avmu (add isopycnal vertical coefficient to avmu)
+               ! Caution: zcoef0 include aht0, so divided by aht0 to obtain slp^2 * aht0
+               avmu(ji,jj,jk) = avmu(ji,jj,jk) + ( zuwslpi * zuwslpi + zuwslpj * zuwslpj ) / aht0
+            END DO
+         END DO
+
+         ! interior (2=<jk=<jpk-1) on V field
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               zcoef0= 0.5 * aht0 * vmask(ji,jj,jk)
+
+               zvwslpi = zcoef0 * ( wslpi(ji,jj+1,jk) + wslpi(ji,jj,jk) )
+               zvwslpj = zcoef0 * ( wslpj(ji,jj+1,jk) + wslpj(ji,jj,jk) )
+
+               zmkf = 1./MAX(  fmask(ji-1,jj,jk-1)+fmask(ji,jj,jk-1)   &
+                             + fmask(ji-1,jj,jk  )+fmask(ji,jj,jk  ), 1. )
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji,jj+1,jk-1)   &
+                             + tmask(ji,jj,jk  )+tmask(ji,jj+1,jk  ), 1. )
+
+               zcoef3 = - e2v(ji,jj) * zmkf * zvwslpi
+               zcoef4 = - e1v(ji,jj) * zmkt * zvwslpj
+               ! vertical flux on v field
+               zfvw(ji,jk) = zcoef3 * ( zdiv (ji,jk-1) + zdiv (ji-1,jk-1)     &
+                                       +zdiv (ji,jk  ) + zdiv (ji-1,jk  ) )   &
+                           + zcoef4 * ( zdjv (ji,jk-1) + zdj1v(ji  ,jk-1)     &
+                                       +zdjv (ji,jk  ) + zdj1v(ji  ,jk  ) )
+               ! update avmv (add isopycnal vertical coefficient to avmv)
+               ! Caution: zcoef0 include aht0, so divided by aht0 to obtain slp^2 * aht0
+               avmv(ji,jj,jk) = avmv(ji,jj,jk) + ( zvwslpi * zvwslpi + zvwslpj * zvwslpj ) / aht0
+            END DO
+         END DO
+
+
+         ! I.3 Divergence of vertical fluxes added to the general tracer trend
+         ! -------------------------------------------------------------------
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ! volume elements
+               zbu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               zbv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+               ! part of the k-component of isopycnal momentum diffusive trends
+               zuav = ( zfuw(ji,jk) - zfuw(ji,jk+1) ) / zbu
+               zvav = ( zfvw(ji,jk) - zfvw(ji,jk+1) ) / zbv
+               ! add the trends to the general trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zuav
+               va(ji,jj,jk) = va(ji,jj,jk) + zvav
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_iso
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                           NO rotation of mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_ldf_iso( kt )               ! Empty routine
+      WRITE(*,*) 'dyn_ldf_iso: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_ldf_iso
+#endif
+
+   !!======================================================================
+END MODULE dynldf_iso
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_lap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 4536)
@@ -0,0 +1,121 @@
+MODULE dynldf_lap
+   !!======================================================================
+   !!                       ***  MODULE  dynldf_lap  ***
+   !! Ocean dynamics:  lateral viscosity trend
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   dyn_ldf_lap  : update the momentum trend with the lateral diffusion
+   !!                  using an iso-level harmonic operator
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE trdmod          ! ocean dynamics trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE ldfslp          ! iso-neutral slopes 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_ldf_lap  ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_ldf_lap( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dyn_ldf_lap  ***
+      !!                       
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The before horizontal momentum diffusion trend is an
+      !!      harmonic operator (laplacian type) which separates the divergent
+      !!      and rotational parts of the flow.
+      !!      Its horizontal components are computed as follow:
+      !!         difu = 1/e1u di[ahmt hdivb] - 1/(e2u*e3u) dj-1[e3f ahmf rotb]
+      !!         difv = 1/e2v dj[ahmt hdivb] + 1/(e1v*e3v) di-1[e3f ahmf rotb]
+      !!      If lk_zco=T, e3f=e3u=e3v, the vertical scale factor are simplified
+      !!      in the rotational part of the diffusion.
+      !!      Add this before trend to the general trend (ua,va):
+      !!            (ua,va) = (ua,va) + (diffu,diffv)
+      !!      'key_trddyn' activated: the two components of the horizontal
+      !!                                 diffusion trend are saved.
+      !!
+      !! ** Action : - Update (ua,va) with the before iso-level harmonic 
+      !!               mixing trend.
+      !!
+      !! History :
+      !!        !  90-09 (G. Madec) Original code
+      !!        !  91-11 (G. Madec)
+      !!        !  96-01 (G. Madec) statement function for e3 and ahm
+      !!   8.5  !  02-06 (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08 (C. Talandier) New trends organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk            ! dummy loop indices
+      REAL(wp) ::   &
+         zua, zva, ze2u, ze1v             ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_ldf : iso-level harmonic (laplacien) operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+               ! horizontal diffusive trends
+               ze2u = rotb (ji,jj,jk)*fsahmf(ji,jj,jk)
+               ze1v = hdivb(ji,jj,jk)*fsahmt(ji,jj,jk)
+               zua = - ( ze2u - rotb (ji,jj-1,jk)*fsahmf(ji,jj-1,jk)                   ) / e2u(ji,jj)   &
+                     + ( hdivb(ji+1,jj,jk)*fsahmt(ji+1,jj,jk) - ze1v                   ) / e1u(ji,jj)
+
+               zva = + ( ze2u - rotb (ji-1,jj,jk)*fsahmf(ji-1,jj,jk)                   ) / e1v(ji,jj)   &
+                     + ( hdivb(ji,jj+1,jk)*fsahmt(ji,jj+1,jk) - ze1v                   ) / e2v(ji,jj)
+#else
+               ze2u = rotb (ji,jj,jk)*fsahmf(ji,jj,jk)*fse3f(ji,jj,jk)
+               ze1v = hdivb(ji,jj,jk)*fsahmt(ji,jj,jk)
+               ! horizontal diffusive trends
+               zua = - ( ze2u - rotb (ji,jj-1,jk)*fsahmf(ji,jj-1,jk)*fse3f(ji,jj-1,jk) ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )   &
+                     + ( hdivb(ji+1,jj,jk)*fsahmt(ji+1,jj,jk) - ze1v                   ) / e1u(ji,jj)
+
+               zva = + ( ze2u - rotb (ji-1,jj,jk)*fsahmf(ji-1,jj,jk)*fse3f(ji-1,jj,jk) ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )   &
+                     + ( hdivb(ji,jj+1,jk)*fsahmt(ji,jj+1,jk) - ze1v                   ) / e2v(ji,jj)
+#endif
+
+               ! add it to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_ldf_lap
+
+   !!======================================================================
+END MODULE dynldf_lap
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4536)
@@ -0,0 +1,305 @@
+MODULE dynnxt
+   !!======================================================================
+   !!                       ***  MODULE  dynnxt  ***
+   !! Ocean dynamics: time stepping
+   !!======================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   dyn_nxt      : update the horizontal velocity from the momentum trend
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE obc_oce         ! ocean open boundary conditions
+   USE obcdyn          ! open boundary condition for momentum (obc_dyn routine)
+   USE obcdyn_bt       ! 2D open boundary condition for momentum (obc_dyn_bt routine)
+   USE obcvol          ! ocean open boundary condition (obc_vol routines)
+   USE dynspg_oce      ! type of surface pressure gradient
+   USE lbclnk          ! lateral boundary condition (or mpp link)
+   USE prtctl          ! Print control
+   USE agrif_opa_update
+   USE agrif_opa_interp
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_nxt                ! routine called by step.F90
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_nxt ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_nxt  ***
+      !!                   
+      !! ** Purpose :   Compute the after horizontal velocity from the 
+      !!      momentum trend.
+      !!
+      !! ** Method  :   Apply lateral boundary conditions on the trends (ua,va) 
+      !!      through calls to routine lbc_lnk.
+      !!      After velocity is compute using a leap-frog scheme environment:
+      !!         (ua,va) = (ub,vb) + 2 rdt (ua,va)
+      !!      Note that if lk_dynspg_flt=T, the time stepping has already been
+      !!      performed in dynspg module
+      !!      Time filter applied on now horizontal velocity to avoid the
+      !!      divergence of two consecutive time-steps and swap of dynamics
+      !!      arrays to start the next time step:
+      !!         (ub,vb) = (un,vn) + atfp [ (ub,vb) + (ua,va) - 2 (un,vn) ]
+      !!         (un,vn) = (ua,va) 
+      !!
+      !! ** Action : - Update ub,vb arrays, the before horizontal velocity
+      !!             - Update un,vn arrays, the now horizontal velocity
+      !!
+      !! History :
+      !!        !  87-02  (P. Andrich, D. L Hostis)  Original code
+      !!        !  90-10  (C. Levy, G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  97-02  (G. Madec & M. Imbard)  opa, release 8.0
+      !!        !  97-04  (A. Weaver)  Euler forward step
+      !!        !  97-06  (G. Madec)  lateral boudary cond., lbc routine
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!        !  02-10  (C. Talandier, A-M. Treguier) Open boundary cond.
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   z2dt         ! temporary scalar
+      REAL(wp) ::   zsshun1, zsshvn1         ! temporary scalar
+      !! Variable volume
+      REAL(wp), DIMENSION(jpi,jpj)     ::  & ! 2D workspace
+         zsshub, zsshun, zsshua,           &
+         zsshvb, zsshvn, zsshva
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &
+         zfse3ub, zfse3un, zfse3ua, &        ! 3D workspace
+         zfse3vb, zfse3vn, zfse3va
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_nxt : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      z2dt = 2. * rdt
+      IF( neuler == 0 .AND. kt == nit000 )  z2dt = rdt
+
+      !! Explicit physics with thickness weighted updates
+      IF( lk_vvl .AND. .NOT. lk_dynspg_flt ) THEN
+
+         ! Sea surface elevation time stepping
+         ! -----------------------------------
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1,jpim1
+
+               ! Sea Surface Height at u-point before
+               zsshub(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )     &
+                  &          * ( e1t(ji  ,jj  ) * e2t(ji  ,jj  ) * sshbb(ji  ,jj  )   &
+                  &            + e1t(ji+1,jj  ) * e2t(ji+1,jj  ) * sshbb(ji+1,jj  ) )
+
+               ! Sea Surface Height at v-point before
+               zsshvb(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )     &
+                  &          * ( e1t(ji  ,jj  ) * e2t(ji  ,jj  ) * sshbb(ji  ,jj  )   &
+                  &            + e1t(ji  ,jj+1) * e2t(ji  ,jj+1) * sshbb(ji  ,jj+1) )
+
+               ! Sea Surface Height at u-point after
+               zsshua(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )     &
+                  &          * ( e1t(ji  ,jj  ) * e2t(ji  ,jj  ) * ssha(ji  ,jj  )    &
+                  &            + e1t(ji+1,jj  ) * e2t(ji+1,jj  ) * ssha(ji+1,jj  ) )
+
+               ! Sea Surface Height at v-point after
+               zsshva(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )     &
+                  &          * ( e1t(ji  ,jj  ) * e2t(ji  ,jj  ) * ssha(ji  ,jj  )    &
+                  &            + e1t(ji  ,jj+1) * e2t(ji  ,jj+1) * ssha(ji  ,jj+1) )
+
+            END DO
+         END DO
+
+         ! Boundaries conditions
+         CALL lbc_lnk( zsshua, 'U', 1. )   ;    CALL lbc_lnk( zsshva, 'V', 1. )
+         CALL lbc_lnk( zsshub, 'U', 1. )   ;    CALL lbc_lnk( zsshvb, 'V', 1. )
+
+         ! Scale factors at before and after time step
+         ! -------------------------------------------
+         CALL dom_vvl_sf( zsshub, 'U', zfse3ub ) ;    CALL dom_vvl_sf( zsshua, 'U', zfse3ua ) 
+         CALL dom_vvl_sf( zsshvb, 'V', zfse3vb ) ;    CALL dom_vvl_sf( zsshva, 'V', zfse3va ) 
+
+         ! Asselin filtered scale factor at now time step
+         ! ----------------------------------------------
+         IF( (neuler == 0 .AND. kt == nit000) .OR. lk_dynspg_ts ) THEN
+            CALL dom_vvl_sf_ini( 'U', zfse3un ) ;   CALL dom_vvl_sf_ini( 'V', zfse3vn ) 
+         ELSE
+            zsshun(:,:) = atfp * ( zsshub(:,:) + zsshua(:,:) ) + atfp1 * sshu(:,:)
+            zsshvn(:,:) = atfp * ( zsshvb(:,:) + zsshva(:,:) ) + atfp1 * sshv(:,:)
+            CALL dom_vvl_sf( zsshun, 'U', zfse3un ) ;   CALL dom_vvl_sf( zsshvn, 'V', zfse3vn ) 
+         ENDIF
+
+         ! Thickness weighting
+         ! -------------------
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * fse3u(ji,jj,jk)
+                  va(ji,jj,jk) = va(ji,jj,jk) * fse3v(ji,jj,jk)
+
+                  un(ji,jj,jk) = un(ji,jj,jk) * fse3u(ji,jj,jk)
+                  vn(ji,jj,jk) = vn(ji,jj,jk) * fse3v(ji,jj,jk)
+
+                  ub(ji,jj,jk) = ub(ji,jj,jk) * zfse3ub(ji,jj,jk)
+                  vb(ji,jj,jk) = vb(ji,jj,jk) * zfse3vb(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+      ! Lateral boundary conditions on ( ua, va )
+      CALL lbc_lnk( ua, 'U', -1. )
+      CALL lbc_lnk( va, 'V', -1. )
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Next velocity
+         ! -------------
+#if defined key_dynspg_flt
+         ! Leap-frog time stepping already done in dynspg.F routine
+#else
+         DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop
+            DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+               ! Leap-frog time stepping
+               ua(ji,jj,jk) = ( ub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) * umask(ji,jj,jk)
+               va(ji,jj,jk) = ( vb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+# if defined key_obc
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update (ua,va) along open boundaries (only in the rigid-lid case)
+      CALL obc_dyn( kt )
+
+      IF ( lk_dynspg_exp .OR. lk_dynspg_ts ) THEN
+         !Flather boundary condition :
+         !        - Update sea surface height on each open boundary
+         !                 sshn (= after ssh) for explicit case
+         !                 sshn_b (= after ssha_b) for time-splitting case
+         !        - Correct the barotropic velocities
+         CALL obc_dyn_bt( kt )
+
+         !Boundary conditions on sshn ( after ssh)
+         CALL lbc_lnk( sshn, 'T', 1. )
+
+         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
+            CALL prt_ctl(tab2d_1=sshn, clinfo1=' ssh      : ', mask1=tmask)
+         ENDIF
+
+         IF ( ln_vol_cst ) CALL obc_vol( kt )
+
+      ENDIF
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+# endif
+# if defined key_agrif
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update (ua,va) along open boundaries (only in the rigid-lid case)
+      CALL Agrif_dyn( kt )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+# endif
+#endif
+
+         ! Time filter and swap of dynamics arrays
+         ! ------------------------------------------
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            IF( (lk_vvl .AND. .NOT. lk_dynspg_flt) ) THEN      ! Varying levels
+               ! caution: don't use (:,:) for this loop
+               ! it causes optimization problems on NEC in auto-tasking
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zsshun1 = umask(ji,jj,jk) / fse3u(ji,jj,jk)
+                     zsshvn1 = vmask(ji,jj,jk) / fse3v(ji,jj,jk)
+                     ub(ji,jj,jk) = un(ji,jj,jk) * zsshun1 * umask(ji,jj,jk)
+                     vb(ji,jj,jk) = vn(ji,jj,jk) * zsshvn1 * vmask(ji,jj,jk)
+                     zsshun1 = umask(ji,jj,jk) / zfse3ua(ji,jj,jk)
+                     zsshvn1 = vmask(ji,jj,jk) / zfse3va(ji,jj,jk)
+                     un(ji,jj,jk) = ua(ji,jj,jk) * zsshun1 * umask(ji,jj,jk)
+                     vn(ji,jj,jk) = va(ji,jj,jk) * zsshvn1 * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            ELSE                                               ! Fixed levels
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ! Euler (forward) time stepping
+                     ub(ji,jj,jk) = un(ji,jj,jk)
+                     vb(ji,jj,jk) = vn(ji,jj,jk)
+                     un(ji,jj,jk) = ua(ji,jj,jk)
+                     vn(ji,jj,jk) = va(ji,jj,jk)
+                  END DO
+               END DO
+            ENDIF
+         ELSE
+            IF( (lk_vvl .AND. .NOT. lk_dynspg_flt) ) THEN      ! Varying levels
+               ! caution: don't use (:,:) for this loop
+               ! it causes optimization problems on NEC in auto-tasking
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zsshun1 = umask(ji,jj,jk) / zfse3un(ji,jj,jk)
+                     zsshvn1 = vmask(ji,jj,jk) / zfse3vn(ji,jj,jk)
+                     ub(ji,jj,jk) = ( atfp  * ( ub(ji,jj,jk) + ua(ji,jj,jk) ) &
+                       &            + atfp1 * un(ji,jj,jk) ) * zsshun1
+                     vb(ji,jj,jk) = ( atfp  * ( vb(ji,jj,jk) + va(ji,jj,jk) ) &
+                       &            + atfp1 * vn(ji,jj,jk) ) * zsshvn1
+                     zsshun1 = umask(ji,jj,jk) / zfse3ua(ji,jj,jk)
+                     zsshvn1 = vmask(ji,jj,jk) / zfse3va(ji,jj,jk)
+                     un(ji,jj,jk) = ua(ji,jj,jk) * zsshun1
+                     vn(ji,jj,jk) = va(ji,jj,jk) * zsshvn1
+                  END DO
+               END DO
+            ELSE                                               ! Fixed levels
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     ! Leap-frog time stepping
+                     ub(ji,jj,jk) = atfp  * ( ub(ji,jj,jk) + ua(ji,jj,jk) ) + atfp1 * un(ji,jj,jk)
+                     vb(ji,jj,jk) = atfp  * ( vb(ji,jj,jk) + va(ji,jj,jk) ) + atfp1 * vn(ji,jj,jk)
+                     un(ji,jj,jk) = ua(ji,jj,jk)
+                     vn(ji,jj,jk) = va(ji,jj,jk)
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=un, clinfo1=' nxt  - Un: ', mask1=umask, &
+            &         tab3d_2=vn, clinfo2=' Vn: ', mask2=vmask)
+      ENDIF
+
+#if defined key_agrif
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Dyn( kt )
+#endif      
+
+   END SUBROUTINE dyn_nxt
+
+   !!======================================================================
+END MODULE dynnxt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4536)
@@ -0,0 +1,200 @@
+MODULE dynspg
+   !!======================================================================
+   !!                       ***  MODULE  dynspg  ***
+   !! Ocean dynamics:  surface pressure gradient control
+   !!======================================================================
+   !! History :  9.0  !  05-12  (C. Talandier, G. Madec)  Original code
+   !!            9.0  !  05-12  (V. Garnier)  dyn_spg_ctl: Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_spg     : update the dynamics trend with the lateral diffusion
+   !!   dyn_spg_ctl : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE obc_oce        ! ocean open boundary conditions
+   USE dynspg_oce     ! surface pressure gradient variables
+   USE dynspg_exp     ! surface pressure gradient     (dyn_spg_exp routine)
+   USE dynspg_ts      ! surface pressure gradient     (dyn_spg_ts  routine)
+   USE dynspg_flt     ! surface pressure gradient     (dyn_spg_flt routine)
+   USE dynspg_rl      ! surface pressure gradient     (dyn_spg_rl  routine)
+   USE dynspg_exp_jki ! surface pressure gradient (dyn_spg_exp_jki routine)
+   USE dynspg_ts_jki  ! surface pressure gradient (dyn_spg_ts_jki  routine)
+   USE dynspg_flt_jki ! surface pressure gradient (dyn_spg_flt_jki routine)
+   USE trdmod         ! ocean dynamics trends
+   USE trdmod_oce     ! ocean variables trends
+   USE prtctl         ! Print control                     (prt_ctl routine)
+   USE in_out_manager ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_spg         ! routine called by step module
+
+   !! * module variables
+   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from lk_dynspg_... 
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_spg  ***
+      !!
+      !! ** Purpose :   compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in  ) ::   kt     ! ocean time-step index
+      INTEGER, INTENT( out ) ::   kindic ! solver flag
+      !!
+      REAL(wp) ::   z2dt                      ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL dyn_spg_ctl      ! initialisation & control of options
+
+      IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
+         ztrdu(:,:,:) = ua(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:)
+      ENDIF
+
+      SELECT CASE ( nspg )                       ! compute surf. pressure gradient trend and add it to the general trend
+      !                                                      ! k-j-i loops
+      CASE (  0 )   ;   CALL dyn_spg_exp    ( kt )              ! explicit
+      CASE (  1 )   ;   CALL dyn_spg_ts     ( kt )              ! time-splitting
+      CASE (  2 )   ;   CALL dyn_spg_flt    ( kt, kindic )      ! filtered
+      CASE (  3 )   ;   CALL dyn_spg_rl     ( kt, kindic )      ! rigid lid
+      !                                                      ! j-k-i loops
+      CASE ( 10 )   ;   CALL dyn_spg_exp_jki( kt )              ! explicit with j-k-i loop
+      CASE ( 11 )   ;   CALL dyn_spg_ts_jki ( kt )              ! time-splitting with j-k-i loop
+      CASE ( 12 )   ;   CALL dyn_spg_flt_jki( kt, kindic )      ! filtered with j-k-i loop
+      !
+      CASE ( -1 )                                       ! esopa: test all possibility with control print
+         ;              CALL dyn_spg_exp    ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg0 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_ts     ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg1 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_flt  ( kt, kindic )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg2 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_exp_jki( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg10- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_ts_jki ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg12- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_flt_jki( kt, kindic )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg13- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      END SELECT
+      !                    
+      IF( l_trddyn )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+         SELECT CASE ( nspg )
+         CASE ( 0, 1, 3, 10, 11 )
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CASE( 2, 12 )
+            z2dt = 2. * rdt
+            IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
+            ztrdu(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) / z2dt - ztrdu(:,:,:)
+            ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / z2dt - ztrdv(:,:,:)
+         END SELECT
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_spg, 'DYN', kt )
+      ENDIF
+      !                                          ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg  - Ua: ', mask1=umask, &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_spg
+
+
+   SUBROUTINE dyn_spg_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_spg_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between cpp options for 
+      !!      surface pressure gradient schemes
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ioptio
+      !!----------------------------------------------------------------------
+
+      ! Parameter control and print
+      ! ---------------------------
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn_spg_ctl : choice of the surface pressure gradient scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '     Explicit free surface                  lk_dynspg_exp = ', lk_dynspg_exp
+         WRITE(numout,*) '     Free surface with time splitting       lk_dynspg_ts  = ', lk_dynspg_ts
+         WRITE(numout,*) '     Filtered free surface cst volume       lk_dynspg_flt = ', lk_dynspg_flt
+         WRITE(numout,*) '     Rigid-lid case                         lk_dynspg_rl  = ', lk_dynspg_rl
+      ENDIF
+
+      ! Control of surface pressure gradient scheme options
+      ! ---------------------------------------------------
+      ioptio = 0
+      IF(lk_dynspg_exp)   ioptio = ioptio + 1
+      IF(lk_dynspg_ts )   ioptio = ioptio + 1
+      IF(lk_dynspg_flt)   ioptio = ioptio + 1
+      IF(lk_dynspg_rl )   ioptio = ioptio + 1
+
+      IF( ( ioptio > 1 .AND. .NOT. lk_esopa ) .OR. ioptio == 0 )   &
+           &   CALL ctl_stop( ' Choose only one surface pressure gradient scheme with a key cpp' )
+
+      IF( lk_esopa     )   nspg = -1
+      IF( lk_dynspg_exp)   nspg =  0
+      IF( lk_dynspg_ts )   nspg =  1
+      IF( lk_dynspg_flt)   nspg =  2
+      IF( lk_dynspg_rl )   nspg =  3
+      IF( lk_jki       )   nspg =  nspg + 10
+      IF( nspg == 13   )   nspg =  3
+
+      IF( lk_esopa     )   nspg = -1
+
+     IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nspg == -1 )   WRITE(numout,*) '     ESOPA test All scheme used except rigid-lid'
+         IF( nspg ==  0 )   WRITE(numout,*) '     explicit free surface'
+         IF( nspg ==  1 )   WRITE(numout,*) '     free surface with time splitting scheme'
+         IF( nspg ==  2 )   WRITE(numout,*) '     filtered free surface'
+         IF( nspg ==  3 )   WRITE(numout,*) '     rigid-lid'
+         IF( nspg == 10 )   WRITE(numout,*) '     explicit free surface with j-k-i loop'
+         IF( nspg == 11 )   WRITE(numout,*) '     time splitting free surface with j-k-i loop'
+         IF( nspg == 12 )   WRITE(numout,*) '     filtered free surface with j-k-i loop'
+      ENDIF
+
+      ! Control of timestep choice
+      ! --------------------------
+      IF( lk_dynspg_ts ) THEN
+         IF( MOD( rdt , rdtbt ) /= 0. )   &
+           &   CALL ctl_stop( ' The barotropic timestep must be an integer divisor of the baroclinic timestep' )
+      ENDIF
+
+#if key_obc
+      ! Conservation of ocean volume (key_dynspg_flt)
+      ! ---------------------------------------------
+      IF( lk_dynspg_flt ) ln_vol_cst = .true.
+
+      ! Application of Flather's algorithm at open boundaries
+      ! -----------------------------------------------------
+      IF( lk_dynspg_flt ) ln_obc_fla = .false.
+      IF( lk_dynspg_exp ) ln_obc_fla = .true.
+      IF( lk_dynspg_ts  ) ln_obc_fla = .true.
+#endif
+
+   END SUBROUTINE dyn_spg_ctl
+
+  !!======================================================================
+END MODULE dynspg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4536)
@@ -0,0 +1,271 @@
+MODULE dynspg_exp
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_exp  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+#if defined key_dynspg_exp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_exp'           free sfce cst vol. without filter nor ts
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_exp  : update the momentum trend with the surface 
+   !!                      pressure gradient in the free surface constant  
+   !!                      volume case with vector optimization
+   !!   exp_rst      : read/write the explicit restart fields in the ocean restart file
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition
+   USE obc_oce         ! Lateral open boundary condition
+   USE obc_par         ! open boundary condition parameters
+   USE obcdta          ! open boundary condition data     (obc_dta_bt routine)
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE iom             ! I/O library
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_exp  ! routine called by step.F90
+   PUBLIC exp_rst      ! routine called j-k-i subroutine
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynspg_exp.F90,v 1.9 2007/06/05 10:38:27 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_exp( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_exp  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!      gradient in case of explicit free surface formulation and 
+      !!      add it to the general trend of momentum equation. Compute
+      !!      the free surface.
+      !!
+      !! ** Method  :   Explicit free surface formulation. The surface pressure
+      !!      gradient is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  g/e1u di( sshn )
+      !!         spgv = 1/rau0 d/dy(ps) =  g/e2v dj( sshn )
+      !!      -1- Compute the now surface pressure gradient
+      !!      -2- Add it to the general trend
+      !!      -3- Compute the horizontal divergence of velocities
+      !!      - the now divergence is given by :
+      !!         zhdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      - integrate the horizontal divergence from the bottom 
+      !!         to the surface
+      !!      - apply lateral boundary conditions on zhdivn
+      !!      -4- Estimate the after sea surface elevation from the kinematic
+      !!         surface boundary condition:
+      !!         zssha = sshb - 2 rdt ( zhdiv + emp )
+      !!      - Time filter applied on now sea surface elevation to avoid
+      !!         the divergence of two consecutive time-steps and swap of free
+      !!         surface arrays to start the next time step:
+      !!         sshb = sshn + atfp * [ sshb + zssha - 2 sshn ]
+      !!         sshn = zssha
+      !!      - apply lateral boundary conditions on sshn
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References :
+      !!
+      !! History :
+      !!   9.0  !  05-11  (V. Garnier, G. Madec, L. Bessieres) Original code
+      !!
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in )  ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur, zssha       ! temporary scalars 
+      REAL(wp), DIMENSION(jpi,jpj)    ::  &  ! temporary arrays
+         &         zhdiv
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_exp : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   (explicit free surface)'
+
+         ! set to zero free surface specific arrays
+         spgu(:,:) = 0.e0                     ! surface pressure gradient (i-direction)
+         spgv(:,:) = 0.e0                     ! surface pressure gradient (j-direction)
+
+         CALL exp_rst( nit000, 'READ' )       ! read or initialize the following fields:
+         !                                    ! sshb, sshn
+
+      ENDIF
+
+      IF( .NOT. lk_vvl ) THEN
+
+         ! 0. Initialization
+         ! -----------------
+         ! read or estimate sea surface height and vertically integrated velocities
+         IF( lk_obc )   CALL obc_dta_bt( kt, 0 )
+         z2dt = 2. * rdt                                       ! time step: leap-frog
+         IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt       ! time step: Euler if restart from rest
+         zraur = 1.e0 / rauw
+
+         ! 1. Surface pressure gradient (now)
+         ! ----------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               spgu(ji,jj) = - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) / e1u(ji,jj)
+               spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
+            END DO
+         END DO
+
+         ! 2. Add the surface pressure trend to the general trend
+         ! ------------------------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
+                  va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
+               END DO
+            END DO
+         END DO
+     
+         ! 3. Vertical integration of horizontal divergence of velocities
+         ! --------------------------------
+         zhdiv(:,:) = 0.e0
+         DO jk = jpkm1, 1, -1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zhdiv(ji,jj) = zhdiv(ji,jj) + (  e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)      &
+                     &                           - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)      &
+                     &                           + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)      &
+                     &                           - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  )   &
+                     &                        / ( e1t(ji,jj) * e2t(ji,jj) )
+               END DO
+            END DO
+         END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of zhdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1  ) = 0.e0      ! east
+         IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1  ) = 0.e0      ! west
+         IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0      ! north
+         IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1  ) = 0.e0      ! south
+#endif
+
+         ! 4. Sea surface elevation time stepping
+         ! --------------------------------------
+         ! Euler (forward) time stepping, no time filter
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! after free surface elevation
+                  zssha = sshb(ji,jj) - rdt * ( zraur * emp(ji,jj) + zhdiv(ji,jj) ) * tmask(ji,jj,1)
+                  ! swap of arrays
+                  sshb(ji,jj) = sshn(ji,jj)
+                  sshn(ji,jj) = zssha
+               END DO
+            END DO
+         ELSE
+            ! Leap-frog time stepping and time filter
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ! after free surface elevation
+                  zssha = sshb(ji,jj) - z2dt * ( zraur * emp(ji,jj) + zhdiv(ji,jj) ) * tmask(ji,jj,1)
+                  ! time filter and array swap
+                  sshb(ji,jj) = atfp * ( sshb(ji,jj) + zssha ) + atfp1 * sshn(ji,jj)
+                  sshn(ji,jj) = zssha
+               END DO
+            END DO
+         ENDIF
+
+      ELSE !! Variable volume, ssh time-stepping already done
+
+         ! read or estimate sea surface height and vertically integrated velocities
+         IF( lk_obc )   CALL obc_dta_bt( kt, 0 )
+
+         ! Sea surface elevation swap
+         ! -----------------------------
+         !
+         sshbb(:,:) = sshb(:,:) ! Needed for the dynamics time-stepping
+         !
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            ! No time filter
+            sshb(:,:) = sshn(:,:)
+            sshn(:,:) = ssha(:,:)
+         ELSE
+            ! Time filter
+            sshb(:,:) = atfp * ( sshb(:,:) + ssha(:,:) ) + atfp1 * sshn(:,:)
+            sshn(:,:) = ssha(:,:)
+         ENDIF
+
+      ENDIF
+
+      ! Boundary conditions on sshn
+      IF( .NOT. lk_obc ) CALL lbc_lnk( sshn, 'T', 1. )
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce )   CALL exp_rst( kt, 'WRITE' )
+ 
+      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
+         CALL prt_ctl(tab2d_1=sshn, clinfo1=' ssh      : ', mask1=tmask)
+      ENDIF
+      
+   END SUBROUTINE dyn_spg_exp
+
+   SUBROUTINE exp_rst( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE exp_rst  ***
+      !!
+      !! ** Purpose : Read or write explicit arrays in restart file
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      !
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN
+         IF( iom_varid( numror, 'sshn' ) > 0 ) THEN
+            CALL iom_get( numror, jpdom_autoglo, 'sshb'  , sshb(:,:)   )
+            CALL iom_get( numror, jpdom_autoglo, 'sshn'  , sshn(:,:)   )
+            IF( neuler == 0 ) sshb(:,:) = sshn(:,:)
+         ELSE
+            IF( nn_rstssh == 1 ) THEN  
+               sshb(:,:) = 0.e0
+               sshn(:,:) = 0.e0
+            ENDIF
+         ENDIF
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+         CALL iom_rstput( kt, nitrst, numrow, 'sshb'  , sshb  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'sshn'  , sshn  (:,:) )
+      ENDIF
+      !
+   END SUBROUTINE exp_rst
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart explicit free surface 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_exp( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_exp
+   SUBROUTINE exp_rst( kt, cdrw )     ! Empty routine
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      WRITE(*,*) 'exp_rst: You should not have seen this print! error?', kt, cdrw
+   END SUBROUTINE exp_rst
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_exp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_exp_jki.F90	(revision 4536)
@@ -0,0 +1,212 @@
+MODULE dynspg_exp_jki
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_exp_jki  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+#if defined key_dynspg_exp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_exp'                              explicit free surface
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_exp_jki  : update the momentum trend with the surface 
+   !!                      pressure gradient in the free surface constant  
+   !!                      volume case with vector optimization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition
+   USE obc_oce         ! Lateral open boundary condition
+   USE obc_par         ! open boundary condition parameters
+   USE obcdta          ! open boundary condition data     (obc_dta_bt routine)
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE dynspg_exp      ! surface pressure gradient
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_exp_jki  ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_exp_jki( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_exp_jki  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!      gradient in case of explicit free surface formulation and 
+      !!      add it to the general trend of momentum equation. Compute
+      !!      the free surface.
+      !!
+      !! ** Method  :   Explicit free surface formulation. The surface pressure
+      !!      gradient is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  g/e1u di( sshn )
+      !!         spgv = 1/rau0 d/dy(ps) =  g/e2v dj( sshn )
+      !!      -1- Compute the now surface pressure gradient
+      !!      -2- Add it to the general trend
+      !!      -3- Compute the horizontal divergence of velocities
+      !!      - the now divergence is given by :
+      !!         zhdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
+      !!      - integrate the horizontal divergence from the bottom 
+      !!         to the surface
+      !!      - apply lateral boundary conditions on zhdivn
+      !!      -4- Estimate the after sea surface elevation from the kinematic
+      !!         surface boundary condition:
+      !!         zssha = sshb - 2 rdt ( zhdiv + emp )
+      !!      - Time filter applied on now sea surface elevation to avoid
+      !!         the divergence of two consecutive time-steps and swap of free
+      !!         surface arrays to start the next time step:
+      !!         sshb = sshn + atfp * [ sshb + zssha - 2 sshn ]
+      !!         sshn = zssha
+      !!      - apply lateral boundary conditions on sshn
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References :
+      !!
+      !! History :
+      !!   9.0  !  05-11  (V. Garnier, G. Madec, L. Bessieres) Original code
+      !!
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in )  ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur, zssha       ! temporary scalars 
+      REAL(wp), DIMENSION(jpi,jpj)    ::  &  ! temporary arrays
+         &         zhdiv
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_exp_jki : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   (explicit free surface, j-k-i loop)'
+
+         ! set to zero free surface specific arrays
+         spgu(:,:) = 0.e0                     ! surface pressure gradient (i-direction)
+         spgv(:,:) = 0.e0                     ! surface pressure gradient (j-direction)
+
+         CALL exp_rst( nit000, 'READ' )       ! read or initialize the following fields:
+         !                                    ! sshb, sshn
+
+      ENDIF
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      ! read or estimate sea surface height and vertically integrated velocities
+      IF( lk_obc )   CALL obc_dta_bt( kt, 0 )
+      z2dt = 2. * rdt                                       ! time step: leap-frog
+      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt       ! time step: Euler if restart from rest
+      zraur = 1.e0 / rauw
+
+!CDIR PARALLEL DO
+!$OMP PARALLEL DO
+      !                                                ! =============== !
+      DO jj = 2, jpjm1                                 !  Vertical slab  !
+         !                                             ! =============== !
+
+         ! Surface pressure gradient (now)
+         DO ji = 2, jpim1
+            spgu(ji,jj) = - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) / e1u(ji,jj)
+            spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
+         END DO
+
+         ! Add the surface pressure trend to the general trend
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
+            END DO
+         END DO
+     
+         !  Vertical integration of horizontal divergence of velocities
+         zhdiv(:,jj) = 0.e0
+         DO jk = jpkm1, 1, -1
+            DO ji = 2, jpim1
+               zhdiv(ji,jj) = zhdiv(ji,jj) + (  e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)      &
+                  &                           - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)      &
+                  &                           + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)      &
+                  &                           - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  )   &
+                  &                        / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of zhdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  ) THEN
+            IF( nje0   <= jj .AND. jj <= nje1   )   zhdiv(nie0p1:nie1p1,jj) = 0.e0      ! east
+         ENDIF
+         IF( lp_obc_west  ) THEN
+            IF( njw0   <= jj .AND. jj <= njw1   )   zhdiv(niw0  :niw1  ,jj) = 0.e0      ! west
+         ENDIF
+         IF( lp_obc_north ) THEN
+            IF( njn0p1 <= jj .AND. jj <= njn1p1 )   zhdiv(nin0  :nin1  ,jj) = 0.e0      ! north
+         ENDIF
+         IF( lp_obc_south ) THEN
+            IF( njs0   <= jj .AND. jj <= njs1   )   zhdiv(nis0  :nis1  ,jj) = 0.e0      ! south
+         ENDIF
+#endif
+
+         ! Sea surface elevation time stepping
+         IF( neuler == 0 .AND. kt == nit000 ) THEN       ! Euler (forward) time stepping, no time filter
+            DO ji = 2, jpim1
+               ! after free surface elevation
+               zssha = sshb(ji,jj) - rdt * ( zraur * emp(ji,jj) + zhdiv(ji,jj) ) * tmask(ji,jj,1)
+               ! swap of arrays
+               sshb(ji,jj) = sshn(ji,jj)
+               sshn(ji,jj) = zssha
+            END DO
+         ELSE                                            ! Leap-frog time stepping and time filter
+            DO ji = 2, jpim1
+               ! after free surface elevation
+               zssha = sshb(ji,jj) - z2dt * ( zraur * emp(ji,jj) + zhdiv(ji,jj) ) * tmask(ji,jj,1)
+               ! time filter and array swap
+               sshb(ji,jj) = atfp * ( sshb(ji,jj) + zssha ) + atfp1 * sshn(ji,jj)
+               sshn(ji,jj) = zssha
+            END DO
+         ENDIF
+         !                                             ! =============== !
+      END DO                                           !     end slab    !
+      !                                                ! =============== !
+
+      ! Boundary conditions on sshn
+      IF( .NOT. lk_obc ) CALL lbc_lnk( sshn, 'T', 1. )
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce )   CALL exp_rst( kt, 'WRITE' )
+ 
+      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
+         CALL prt_ctl(tab2d_1=sshn, clinfo1=' ssh      : ', mask1=tmask)
+      ENDIF
+      
+   END SUBROUTINE dyn_spg_exp_jki
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart explicit free surface 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_exp_jki( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_exp_jki: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_exp_jki
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_exp_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 4536)
@@ -0,0 +1,498 @@
+MODULE dynspg_flt
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_flt  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+   !! History    8.0  !  98-05  (G. Roullet)  free surface
+   !!                 !  98-10  (G. Madec, M. Imbard)  release 8.2
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!            " "  !  02-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!            9.0  !  04-08  (C. Talandier) New trends organization
+   !!            " "  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!            " "  !  06-07  (S. Masson)  distributed restart using iom
+   !!----------------------------------------------------------------------
+#if defined key_dynspg_flt   ||   defined key_esopa  
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_flt'                              filtered free surface
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_flt  : update the momentum trend with the surface pressure
+   !!                  gradient in the filtered free surface case with
+   !!                  vector optimization
+   !!   flt_rst      : read/write the time-splitting restart fields in the ocean restart file
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition
+   USE flxrnf          ! ocean runoffs
+   USE sol_oce         ! ocean elliptic solver
+   USE solver          ! solver initialization
+   USE solpcg          ! preconditionned conjugate gradient solver
+   USE solsor          ! Successive Over-relaxation solver
+   USE solfet          ! FETI solver
+   USE solsor_e        ! Successive Over-relaxation solver with MPP optimization
+   USE obc_oce         ! Lateral open boundary condition
+   USE obcdyn          ! ocean open boundary condition (obc_dyn routines)
+   USE obcvol          ! ocean open boundary condition (obc_vol routines)
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE cla_dynspg      ! cross land advection
+   USE prtctl          ! Print control
+   USE solmat          ! matrix construction for elliptic solvers
+   USE agrif_opa_interp
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE restart         ! only for lrst_oce
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_spg_flt  ! routine called by step.F90
+   PUBLIC flt_rst      ! routine called by j-k-i subroutine
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynspg_flt.F90,v 1.14 2007/06/05 10:38:27 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_flt( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_flt  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure 
+      !!      gradient in case of filtered free surface formulation  and add
+      !!      it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   Filtered free surface formulation. The surface
+      !!      pressure gradient is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  1/e1u di( sshn + rnu btda )
+      !!         spgv = 1/rau0 d/dy(ps) =  1/e2v dj( sshn + rnu btda )
+      !!      where sshn is the free surface elevation and btda is the after
+      !!      of the free surface elevation
+      !!       -1- compute the after sea surface elevation from the kinematic
+      !!      surface boundary condition:
+      !!              zssha = sshb + 2 rdt ( wn - emp )
+      !!           Time filter applied on now sea surface elevation to avoid 
+      !!      the divergence of two consecutive time-steps and swap of free
+      !!      surface arrays to start the next time step:
+      !!              sshb = sshn + atfp * [ sshb + zssha - 2 sshn ]
+      !!              sshn = zssha
+      !!       -2- evaluate the surface presure trend (including the addi-
+      !!      tional force) in three steps:
+      !!        a- compute the right hand side of the elliptic equation:
+      !!            gcb = 1/(e1t e2t) [ di(e2u spgu) + dj(e1v spgv) ]
+      !!         where (spgu,spgv) are given by:
+      !!            spgu = vertical sum[ e3u (ub+ 2 rdt ua ) ]
+      !!                 - grav 2 rdt hu /e1u di[sshn + emp]
+      !!            spgv = vertical sum[ e3v (vb+ 2 rdt va) ]
+      !!                 - grav 2 rdt hv /e2v dj[sshn + emp]
+      !!         and define the first guess from previous computation :
+      !!            zbtd = btda
+      !!            btda = 2 zbtd - btdb
+      !!            btdb = zbtd
+      !!        b- compute the relative accuracy to be reached by the
+      !!         iterative solver
+      !!        c- apply the solver by a call to sol... routine
+      !!       -3- compute and add the free surface pressure gradient inclu-
+      !!      ding the additional force used to stabilize the equation.
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Roullet and Madec 1999, JGR.
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      USE oce    , ONLY :   zub   => ta,             &  ! ta used as workspace
+                            zvb   => sa                 ! sa   "          "
+
+      INTEGER, INTENT( in )  ::   kt         ! ocean time-step index
+      INTEGER, INTENT( out ) ::   kindic     ! solver convergence flag (<0 if not converge)
+      !!                                   
+      INTEGER  ::   ji, jj, jk                          ! dummy loop indices
+      REAL(wp) ::   z2dt, z2dtg, zraur, znugdt,      &  ! temporary scalars
+         &          znurau, zgcb, zbtd,              &  !   "          "
+         &          ztdgu, ztdgv                        !   "          "
+      !! Variable volume
+      REAL(wp), DIMENSION(jpi,jpj)     ::  &
+         zsshub, zsshua, zsshvb, zsshva, zssha          ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &            ! 3D workspace
+         zfse3ub, zfse3ua, zfse3vb, zfse3va             ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_flt : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   (free surface constant volume case)'
+       
+         ! set to zero free surface specific arrays
+         spgu(:,:) = 0.e0                     ! surface pressure gradient (i-direction)
+         spgv(:,:) = 0.e0                     ! surface pressure gradient (j-direction)
+         CALL solver_init( nit000 )           ! Elliptic solver initialisation
+
+         ! read filtered free surface arrays in restart file
+         CALL flt_rst( nit000, 'READ' )       ! read or initialize the following fields:
+         !                                    ! gcx, gcxb, sshb, sshn
+      ENDIF
+
+      ! Local constant initialization
+      z2dt = 2. * rdt                                       ! time step: leap-frog
+      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt       ! time step: Euler if restart from rest
+      IF( neuler == 0 .AND. kt == nit000+1 ) CALL sol_mat(kt)
+      z2dtg  = grav * z2dt
+      zraur  = 1. / rauw
+      znugdt =  rnu * grav * z2dt
+      znurau =  znugdt * zraur
+
+      !! Explicit physics with thickness weighted updates
+      IF( lk_vvl ) THEN          ! variable volume 
+
+         DO jj = 1, jpjm1
+            DO ji = 1,jpim1
+
+               ! Sea Surface Height at u-point before
+               zsshub(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )  & 
+                  &          * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshb(ji  ,jj)       &
+                  &            + e1t(ji+1,jj) * e2t(ji+1,jj) * sshb(ji+1,jj) )
+
+               ! Sea Surface Height at v-point before
+               zsshvb(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )  &
+                  &          * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshb(ji,jj  )       &
+                  &            + e1t(ji,jj+1) * e2t(ji,jj+1) * sshb(ji,jj+1) )
+
+               ! Sea Surface Height at u-point after
+               zsshua(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )  &
+                  &          * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)       &
+                  &            + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
+
+               ! Sea Surface Height at v-point after
+               zsshva(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )  &
+                  &          * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )       &
+                  &            + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
+
+            END DO
+         END DO
+
+         ! Boundaries conditions
+         CALL lbc_lnk( zsshub, 'U', 1. )    ;    CALL lbc_lnk( zsshvb, 'V', 1. )
+         CALL lbc_lnk( zsshua, 'U', 1. )    ;    CALL lbc_lnk( zsshva, 'V', 1. )
+
+         ! Scale factors at before and after time step
+         ! -------------------------------------------
+         CALL dom_vvl_sf( zsshub, 'U', zfse3ub ) ;    CALL dom_vvl_sf( zsshua, 'U', zfse3ua )
+         CALL dom_vvl_sf( zsshvb, 'V', zfse3vb ) ;    CALL dom_vvl_sf( zsshva, 'V', zfse3va )
+
+
+         ! Thickness weighting
+         ! -------------------
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * fse3u(ji,jj,jk)
+                  va(ji,jj,jk) = va(ji,jj,jk) * fse3v(ji,jj,jk)
+
+                  zub(ji,jj,jk) = ub(ji,jj,jk) * zfse3ub(ji,jj,jk)
+                  zvb(ji,jj,jk) = vb(ji,jj,jk) * zfse3vb(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Evaluate the masked next velocity (effect of the additional force not included)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ( zub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) /zfse3ua(ji,jj,jk) * umask(ji,jj,jk)
+                  va(ji,jj,jk) = ( zvb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) /zfse3va(ji,jj,jk) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE                       ! fixed volume 
+
+         ! Surface pressure gradient (now)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               spgu(ji,jj) = - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) / e1u(ji,jj)
+               spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
+            END DO 
+         END DO 
+
+         ! Add the surface pressure trend to the general trend
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
+                  va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         ! Evaluate the masked next velocity (effect of the additional force not included)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ( ub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) * umask(ji,jj,jk)
+                  va(ji,jj,jk) = ( vb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+#if defined key_obc
+      CALL obc_dyn( kt )      ! Update velocities on each open boundary with the radiation algorithm
+      CALL obc_vol( kt )      ! Correction of the barotropic componant velocity to control the volume of the system
+#endif
+#if defined key_agrif
+      CALL Agrif_dyn( kt )    ! Update velocities on each coarse/fine interfaces 
+#endif
+#if defined key_orca_r2
+      IF( n_cla == 1 )   CALL dyn_spg_cla( kt )      ! Cross Land Advection (update (ua,va))
+#endif
+
+      ! compute the next vertically averaged velocity (effect of the additional force not included)
+      ! ---------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            spgu(ji,jj) = 0.e0
+            spgv(ji,jj) = 0.e0
+         END DO
+      END DO
+
+      ! vertical sum
+!CDIR NOLOOPCHG
+      IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
+         DO jk = 1, jpkm1
+            DO ji = 1, jpij
+               spgu(ji,1) = spgu(ji,1) + fse3u(ji,1,jk) * ua(ji,1,jk)
+               spgv(ji,1) = spgv(ji,1) + fse3v(ji,1,jk) * va(ji,1,jk)
+            END DO
+         END DO
+      ELSE                        ! No  vector opt.
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  spgu(ji,jj) = spgu(ji,jj) + fse3u(ji,jj,jk) * ua(ji,jj,jk)
+                  spgv(ji,jj) = spgv(ji,jj) + fse3v(ji,jj,jk) * va(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! transport: multiplied by the horizontal scale factor
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            spgu(ji,jj) = spgu(ji,jj) * e2u(ji,jj)
+            spgv(ji,jj) = spgv(ji,jj) * e1v(ji,jj)
+         END DO
+      END DO
+
+      ! Boundary conditions on (spgu,spgv)
+      CALL lbc_lnk( spgu, 'U', -1. )
+      CALL lbc_lnk( spgv, 'V', -1. )
+
+      IF( lk_vvl ) CALL sol_mat( kt )
+
+      ! Right hand side of the elliptic equation and first guess
+      ! -----------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! Divergence of the after vertically averaged velocity
+            zgcb =  spgu(ji,jj) - spgu(ji-1,jj)   &
+                  + spgv(ji,jj) - spgv(ji,jj-1)
+            gcb(ji,jj) = gcdprc(ji,jj) * zgcb
+            ! First guess of the after barotropic transport divergence
+            zbtd = gcx(ji,jj)
+            gcx (ji,jj) = 2. * zbtd   - gcxb(ji,jj)
+            gcxb(ji,jj) =      zbtd
+         END DO
+      END DO
+      ! applied the lateral boundary conditions
+      IF( nsolv == 4 )   CALL lbc_lnk_e( gcb, c_solver_pt, 1. )   
+
+#if defined key_agrif
+      IF( .NOT. AGRIF_ROOT() ) THEN
+         ! add contribution of gradient of after barotropic transport divergence 
+         IF( nbondi == -1 .OR. nbondi == 2 )   gcb(3     ,:) =   &
+            &    gcb(3     ,:) - znugdt * z2dt * laplacu(2     ,:) * gcdprc(3     ,:) * hu(2     ,:) * e2u(2     ,:)
+         IF( nbondi ==  1 .OR. nbondi == 2 )   gcb(nlci-2,:) =   &
+            &    gcb(nlci-2,:) + znugdt * z2dt * laplacu(nlci-2,:) * gcdprc(nlci-2,:) * hu(nlci-2,:) * e2u(nlci-2,:)
+         IF( nbondj == -1 .OR. nbondj == 2 )   gcb(:     ,3) =   &
+            &    gcb(:,3     ) - znugdt * z2dt * laplacv(:,2     ) * gcdprc(:,3     ) * hv(:,2     ) * e1v(:,2     )
+         IF( nbondj ==  1 .OR. nbondj == 2 )   gcb(:,nlcj-2) =   &
+            &    gcb(:,nlcj-2) + znugdt * z2dt * laplacv(:,nlcj-2) * gcdprc(:,nlcj-2) * hv(:,nlcj-2) * e1v(:,nlcj-2)
+      ENDIF
+#endif
+
+
+      ! Relative precision (computation on one processor)
+      ! ------------------
+      rnorme =0.
+      rnorme = SUM( gcb(1:jpi,1:jpj) * gcdmat(1:jpi,1:jpj) * gcb(1:jpi,1:jpj) * bmask(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+
+      epsr = eps * eps * rnorme
+      ncut = 0
+      ! if rnorme is 0, the solution is 0, the solver is not called
+      IF( rnorme == 0.e0 ) THEN
+         gcx(:,:) = 0.e0
+         res   = 0.e0
+         niter = 0
+         ncut  = 999
+      ENDIF
+
+      ! Evaluate the next transport divergence
+      ! --------------------------------------
+      !    Iterarive solver for the elliptic equation (except IF sol.=0)
+      !    (output in gcx with boundary conditions applied)
+      kindic = 0
+      IF( ncut == 0 ) THEN
+         IF( nsolv == 1 ) THEN         ! diagonal preconditioned conjuguate gradient
+            CALL sol_pcg( kindic )
+         ELSEIF( nsolv == 2 ) THEN     ! successive-over-relaxation
+            CALL sol_sor( kindic )
+         ELSEIF( nsolv == 3 ) THEN     ! FETI solver
+            CALL sol_fet( kindic )
+         ELSEIF( nsolv == 4 ) THEN     ! successive-over-relaxation with extra outer halo
+            CALL sol_sor_e( kindic )
+         ELSE                          ! e r r o r in nsolv namelist parameter
+            WRITE(ctmp1,*) ' ~~~~~~~~~~~                not = ', nsolv
+            CALL ctl_stop( ' dyn_spg_flt : e r r o r, nsolv = 1, 2 ,3 or 4', ctmp1 )
+         ENDIF
+      ENDIF
+
+      ! Transport divergence gradient multiplied by z2dt
+      ! --------------------------------------------====
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ! trend of Transport divergence gradient
+            ztdgu = znugdt * (gcx(ji+1,jj  ) - gcx(ji,jj) ) / e1u(ji,jj)
+            ztdgv = znugdt * (gcx(ji  ,jj+1) - gcx(ji,jj) ) / e2v(ji,jj)
+            ! multiplied by z2dt
+#if defined key_obc
+            ! caution : grad D = 0 along open boundaries
+            spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
+            spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
+#else
+            spgu(ji,jj) = z2dt * ztdgu
+            spgv(ji,jj) = z2dt * ztdgv
+#endif
+         END DO
+      END DO
+
+#if defined key_agrif      
+      IF( .NOT. Agrif_Root() ) THEN
+         ! caution : grad D (fine) = grad D (coarse) at coarse/fine interface
+         IF( nbondi == -1 .OR. nbondi == 2 ) spgu(2     ,:) = znugdt * z2dt * laplacu(2     ,:) * umask(2     ,:,1)
+         IF( nbondi ==  1 .OR. nbondi == 2 ) spgu(nlci-2,:) = znugdt * z2dt * laplacu(nlci-2,:) * umask(nlci-2,:,1)
+         IF( nbondj == -1 .OR. nbondj == 2 ) spgv(:,2     ) = znugdt * z2dt * laplacv(:,2     ) * vmask(:     ,2,1)
+         IF( nbondj ==  1 .OR. nbondj == 2 ) spgv(:,nlcj-2) = znugdt * z2dt * laplacv(:,nlcj-2) * vmask(:,nlcj-2,1)
+      ENDIF
+#endif      
+      ! 7.  Add the trends multiplied by z2dt to the after velocity
+      ! -----------------------------------------------------------
+      !     ( c a u t i o n : (ua,va) here are the after velocity not the
+      !                       trend, the leap-frog time stepping will not
+      !                       be done in dynnxt.F90 routine)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) = (ua(ji,jj,jk) + spgu(ji,jj)) * umask(ji,jj,jk)
+               va(ji,jj,jk) = (va(ji,jj,jk) + spgv(ji,jj)) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Sea surface elevation time stepping
+      ! -----------------------------------
+      IF( lk_vvl ) THEN   ! after free surface elevation
+         zssha(:,:) = ssha(:,:)
+      ELSE
+         zssha(:,:) = sshb(:,:) + z2dt * ( wn(:,:,1) - emp(:,:) * zraur ) * tmask(:,:,1)
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN      ! Euler (forward) time stepping, no time filter
+         ! swap of arrays
+         sshb(:,:) = sshn (:,:)
+         sshn(:,:) = zssha(:,:)
+      ELSE                                           ! Leap-frog time stepping and time filter
+         ! time filter and array swap
+         sshb(:,:) = atfp * ( sshb(:,:) + zssha(:,:) ) + atfp1 * sshn(:,:)
+         sshn(:,:) = zssha(:,:)
+      ENDIF
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce ) CALL flt_rst( kt, 'WRITE' )
+
+      ! print sum trends (used for debugging)
+      IF(ln_ctl)     CALL prt_ctl( tab2d_1=sshn, clinfo1=' spg  - ssh: ', mask1=tmask )
+      !
+   END SUBROUTINE dyn_spg_flt
+
+
+   SUBROUTINE flt_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE ts_rst  ***
+     !!
+     !! ** Purpose : Read or write filtered free surface arrays in restart file
+     !!----------------------------------------------------------------------
+     INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+     !!----------------------------------------------------------------------
+
+     IF( TRIM(cdrw) == 'READ' ) THEN
+        IF( iom_varid( numror, 'gcx' ) > 0 ) THEN
+! Caution : extra-hallow
+! gcx and gcxb are defined as: DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj)
+           CALL iom_get( numror, jpdom_autoglo, 'gcx' , gcx (1:jpi,1:jpj) )
+           CALL iom_get( numror, jpdom_autoglo, 'gcxb', gcxb(1:jpi,1:jpj) )
+           CALL iom_get( numror, jpdom_autoglo, 'sshb', sshb(:,:)         )
+           CALL iom_get( numror, jpdom_autoglo, 'sshn', sshn(:,:)         )
+           IF( neuler == 0 ) THEN
+              sshb(:,:) = sshn(:,:)
+              gcxb(:,:) = gcx (:,:)
+           ENDIF
+        ELSE
+           gcx (:,:) = 0.e0
+           gcxb(:,:) = 0.e0
+           IF( nn_rstssh == 1 ) THEN  
+              sshb(:,:) = 0.e0
+              sshn(:,:) = 0.e0
+           ENDIF
+        ENDIF
+     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+! Caution : extra-hallow
+! gcx and gcxb are defined as: DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj)
+        CALL iom_rstput( kt, nitrst, numrow, 'gcx' , gcx( 1:jpi,1:jpj) )
+        CALL iom_rstput( kt, nitrst, numrow, 'gcxb', gcxb(1:jpi,1:jpj) )
+        CALL iom_rstput( kt, nitrst, numrow, 'sshb', sshb(:,:)         )
+        CALL iom_rstput( kt, nitrst, numrow, 'sshn', sshn(:,:)         )
+     ENDIF
+     !
+   END SUBROUTINE flt_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart free surface cst volume
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_flt( kt, kindic )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_flt: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE dyn_spg_flt
+   SUBROUTINE flt_rst    ( kt, cdrw )         ! Empty routine
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      WRITE(*,*) 'flt_rst: You should not have seen this print! error?', kt, cdrw
+   END SUBROUTINE flt_rst
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_flt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90	(revision 4536)
@@ -0,0 +1,388 @@
+MODULE dynspg_flt_jki
+   !!======================================================================
+   !!                  ***  MODULE  dynspg_flt_jki  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+#if defined key_dynspg_flt   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_flt'                              filtered free surface
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_flt_jki : Update the momentum trend with the surface pressure
+   !!                     gradient for the free surf. constant volume case
+   !!                     with auto-tasking (j-slab) (no vectior opt.)
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constant
+   USE ocesbc          ! Ocean Surface Boundary condition
+   USE flxrnf          ! ocean runoffs
+   USE sol_oce         ! ocean elliptic solver
+   USE solpcg          ! preconditionned conjugate gradient solver
+   USE solsor          ! Successive Over-relaxation solver
+   USE solfet          ! FETI solver
+   USE solsor_e        ! Successive Over-relaxation solver with MPP optimization
+   USE solver
+   USE obc_oce         ! Lateral open boundary condition
+   USE obcdyn          ! ocean open boundary condition (obc_dyn routines)
+   USE obcvol          ! ocean open boundary condition (obc_vol routines)
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE cla_dynspg      ! cross land advection
+   USE prtctl          ! Print control
+   USE in_out_manager  ! I/O manager
+   USE solmat          ! matrix construction for elliptic solvers
+   USE agrif_opa_interp
+   USE restart         ! only for lrst_oce
+   USE iom             ! I/O library
+   USE dynspg_flt      ! surface pressure gradient
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_flt_jki        ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_flt_jki( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_flt_jki  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure 
+      !!      gradient for free surface formulation with a constant ocean
+      !!      volume case, add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   Free surface formulation. The surface pressure gradient
+      !!      is given by:
+      !!         spgu = 1/rau0 d/dx(ps) =  1/e1u di( etn + rnu btda )
+      !!         spgv = 1/rau0 d/dy(ps) =  1/e2v dj( etn + rnu btda )
+      !!      where etn is the free surface elevation and btda is the after
+      !!      of the free surface elevation
+      !!       -1- compute the after sea surface elevation from the cinematic
+      !!      surface boundary condition:
+      !!              zssha = sshb + 2 rdt ( wn - emp )
+      !!           Time filter applied on now sea surface elevation to avoid 
+      !!      the divergence of two consecutive time-steps and swap of free
+      !!      surface arrays to start the next time step:
+      !!              sshb = sshn + atfp * [ sshb + zssha - 2 sshn ]
+      !!              sshn = zssha
+      !!       -2- evaluate the surface presure trend (including the addi-
+      !!      tional force) in three steps:
+      !!        a- compute the right hand side of the elliptic equation:
+      !!            gcb = 1/(e1t e2t) [ di(e2u spgu) + dj(e1v spgv) ]
+      !!         where (spgu,spgv) are given by:
+      !!            spgu = vertical sum[ e3u (ub+ 2 rdt ua ) ]
+      !!                 - grav 2 rdt hu /e1u di[sshn + emp]
+      !!            spgv = vertical sum[ e3v (vb+ 2 rdt va) ]
+      !!                 - grav 2 rdt hv /e2v dj[sshn + emp]
+      !!         and define the first guess from previous computation :
+      !!            zbtd = btda
+      !!            btda = 2 zbtd - btdb
+      !!            btdb = zbtd
+      !!        b- compute the relative accuracy to be reached by the
+      !!         iterative solver
+      !!        c- apply the solver by a call to sol... routine
+      !!       -3- compute and add the free surface pressure gradient inclu-
+      !!      ding the additional force used to stabilize the equation.
+      !!      several slabs used ('key-autotasking')
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Roullet and Madec 1999, JGR.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      INTEGER, INTENT( out ) ::   kindic     ! solver convergence flag, <0 if the solver doesn t converge
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   &              ! temporary scalars
+         z2dt, z2dtg, zraur, znugdt, znurau,   &
+         zssha, zgcb, zbtd, ztdgu, ztdgv, zgwgt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_flt_jki : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~  (free surface constant volume, autotasking case)'
+
+         ! set to zero free surface specific arrays
+         spgu(:,:) = 0.e0                     ! surface pressure gradient (i-direction)
+         
+         spgv(:,:) = 0.e0                     ! surface pressure gradient (j-direction)
+         
+         CALL solver_init( nit000 )           ! Elliptic solver initialisation
+
+         ! read filtered free surface arrays in restart file
+         CALL flt_rst( nit000, 'READ' )       ! read or initialize the following fields:
+         !                                    ! gcx, gcxb, sshb, sshn
+      ENDIF
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      ! time step: leap-frog
+      z2dt = 2. * rdt
+      ! time step: Euler if restart from rest
+      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
+      IF( neuler == 0 .AND. kt == nit000+1 ) CALL sol_mat(kt)
+      ! coefficients
+      z2dtg  = grav * z2dt
+      zraur  = 1. / rauw
+      znugdt =  rnu * grav * z2dt
+      znurau =  znugdt * zraur
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         ! Surface pressure gradient (now)
+         DO ji = 2, jpim1
+            spgu(ji,jj) = - grav * ( sshn(ji+1,jj  ) - sshn(ji,jj) ) / e1u(ji,jj)
+            spgv(ji,jj) = - grav * ( sshn(ji  ,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
+         END DO 
+         !  Add the surface pressure trend to the general trend
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
+            END DO
+         END DO
+         ! Evaluate the masked next velocity (effect of the additional force not included)
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ( ub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) * umask(ji,jj,jk)
+               va(ji,jj,jk) = ( vb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+#if defined key_obc
+         ! Update velocities on each open boundary with the radiation algorithm
+         CALL obc_dyn( kt )
+         ! Correction of the barotropic componant velocity to control the volume of the system
+         CALL obc_vol( kt )
+#endif
+#if defined key_agrif
+      ! Update velocities on each coarse/fine interfaces
+
+      CALL Agrif_dyn( kt )
+#endif
+#if defined key_orca_r2
+      IF( n_cla == 1 )   CALL dyn_spg_cla( kt )      ! Cross Land Advection (Update (ua,va))
+#endif
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+
+         ! 2. compute the next vertically averaged velocity
+         ! ------------------------------------------------
+         !     (effect of the additional force not included)
+         ! initialize to zero
+         DO ji = 2, jpim1
+            spgu(ji,jj) = 0.e0
+            spgv(ji,jj) = 0.e0
+         END DO
+         ! vertical sum
+         DO jk = 1, jpk
+            DO ji = 2, jpim1
+               spgu(ji,jj) = spgu(ji,jj) + fse3u(ji,jj,jk) * ua(ji,jj,jk)
+               spgv(ji,jj) = spgv(ji,jj) + fse3v(ji,jj,jk) * va(ji,jj,jk)
+            END DO
+         END DO
+         ! transport: multiplied by the horizontal scale factor
+         DO ji = 2, jpim1
+            spgu(ji,jj) = spgu(ji,jj) * e2u(ji,jj)
+            spgv(ji,jj) = spgv(ji,jj) * e1v(ji,jj)
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+      
+      ! Boundary conditions on (spgu,spgv)
+      CALL lbc_lnk( spgu, 'U', -1. )
+      CALL lbc_lnk( spgv, 'V', -1. )
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      ! 3. Right hand side of the elliptic equation and first guess
+      ! -----------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            ! Divergence of the after vertically averaged velocity
+            zgcb =  spgu(ji,jj) - spgu(ji-1,jj)   &
+                  + spgv(ji,jj) - spgv(ji,jj-1)
+            gcb(ji,jj) = gcdprc(ji,jj) * zgcb
+            ! First guess of the after barotropic transport divergence
+            zbtd = gcx(ji,jj)
+            gcx (ji,jj) = 2. * zbtd   - gcxb(ji,jj)
+            gcxb(ji,jj) =      zbtd
+         END DO
+      END DO
+      ! applied the lateral boundary conditions
+      IF( nsolv == 4)   CALL lbc_lnk_e( gcb, c_solver_pt, 1. )  
+
+#if defined key_agrif
+      IF( .NOT. AGRIF_ROOT() ) THEN
+         ! add contribution of gradient of after barotropic transport divergence 
+        IF( (nbondi == -1) .OR. (nbondi == 2) ) gcb(3,:) = gcb(3,:) &
+           &            -znugdt * z2dt*laplacu(2,:)*gcdprc(3,:)*hu(2,:)*e2u(2,:)
+        IF( (nbondi ==  1) .OR. (nbondi == 2) )  gcb(nlci-2,:) = gcb(nlci-2,:) &
+           &           +znugdt * z2dt*laplacu(nlci-2,:)*gcdprc(nlci-2,:)*hu(nlci-2,:)*e2u(nlci-2,:)
+        IF( (nbondj == -1) .OR. (nbondj == 2) ) gcb(:,3) = gcb(:,3) &
+           &           -znugdt * z2dt*laplacv(:,2)*gcdprc(:,3)*hv(:,2)*e1v(:,2)
+        IF( (nbondj ==  1) .OR. (nbondj == 2) )  gcb(:,nlcj-2) = gcb(:,nlcj-2) &
+           &           +znugdt * z2dt*laplacv(:,nlcj-2)*gcdprc(:,nlcj-2)*hv(:,nlcj-2)*e1v(:,nlcj-2)
+      ENDIF
+#endif
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+      
+      ! 4. Relative precision (computation on one processor)
+      ! ---------------------
+      rnorme =0.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zgwgt  = gcdmat(ji,jj) * gcb(ji,jj)
+            rnorme = rnorme + gcb(ji,jj) * zgwgt * bmask(ji,jj)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+
+      epsr = eps * eps * rnorme
+      ncut = 0
+      ! if rnorme is 0, the solution is 0, the solver isn't called
+      IF( rnorme == 0.e0 ) THEN
+         gcx(:,:) = 0.e0
+         res   = 0.e0
+         niter = 0
+         ncut  = 999
+      ENDIF
+      
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+      
+      ! 5. Evaluate the next transport divergence
+      ! -----------------------------------------
+      !    Iterarive solver for the elliptic equation (except IF sol.=0)
+      !    (output in gcx with boundary conditions applied)
+      kindic = 0
+      IF( ncut == 0 ) THEN
+         IF( nsolv == 1 ) THEN         ! diagonal preconditioned conjuguate gradient
+            CALL sol_pcg( kindic )
+         ELSEIF( nsolv == 2 ) THEN     ! successive-over-relaxation
+            CALL sol_sor( kindic )
+         ELSEIF( nsolv == 3 ) THEN     ! FETI solver
+            CALL sol_fet( kindic )
+         ELSEIF( nsolv == 4 ) THEN     ! successive-over-relaxation with extra outer halo
+            CALL sol_sor_e( kindic )
+         ELSE                          ! e r r o r in nsolv namelist parameter
+            WRITE(ctmp1,*) ' ~~~~~~~~~~~~~~~~                not = ', nsolv
+            CALL ctl_stop( ' dyn_spg_flt_jki : e r r o r, nsolv = 1, 2, 3 or 4', ctmp1 )
+         ENDIF
+      ENDIF
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         
+         ! 6. Transport divergence gradient multiplied by z2dt
+         ! -----------------------------------------------====
+         DO ji = 2, jpim1
+            ! trend of Transport divergence gradient
+            ztdgu = znugdt * (gcx(ji+1,jj  ) - gcx(ji,jj) ) / e1u(ji,jj)
+            ztdgv = znugdt * (gcx(ji  ,jj+1) - gcx(ji,jj) ) / e2v(ji,jj)
+            ! multiplied by z2dt
+#if defined key_obc
+            ! caution : grad D = 0 along open boundaries
+            spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
+            spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
+#else
+            spgu(ji,jj) = z2dt * ztdgu
+            spgv(ji,jj) = z2dt * ztdgv
+#endif
+         END DO
+         
+#if defined key_agrif      
+      IF( .NOT. Agrif_Root() ) THEN
+         ! caution : grad D (fine) = grad D (coarse) at coarse/fine interface
+         IF( (nbondi == -1) .OR. (nbondi == 2) ) spgu(2,:) = znugdt * z2dt * laplacu(2,:) * umask(2,:,1)
+         IF( (nbondi ==  1) .OR. (nbondi == 2) ) spgu(nlci-2,:) = znugdt * z2dt * laplacu(nlci-2,:) * umask(nlci-2,:,1)
+         IF( (nbondj == -1) .OR. (nbondj == 2) ) spgv(:,2) = znugdt * z2dt * laplacv(:,2) * vmask(:,2,1)
+         IF( (nbondj ==  1) .OR. (nbondj == 2) ) spgv(:,nlcj-2) = znugdt * z2dt * laplacv(:,nlcj-2) * vmask(:,nlcj-2,1)
+      ENDIF
+#endif
+      
+         ! 7.  Add the trends multiplied by z2dt to the after velocity
+         ! -----------------------------------------------------------
+         !     ( c a u t i o n : (ua,va) here are the after velocity not the
+         !                       trend, the leap-frog time stepping will not
+         !                       be done in dynnxt.F routine)
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = (ua(ji,jj,jk) + spgu(ji,jj)) * umask(ji,jj,jk)
+               va(ji,jj,jk) = (va(ji,jj,jk) + spgv(ji,jj)) * vmask(ji,jj,jk)
+            END DO
+         END DO
+
+         ! 8. Sea surface elevation time stepping
+         ! --------------------------------------
+         IF( neuler == 0 .AND. kt == nit000 ) THEN         ! Euler (forward) time stepping, no time filter
+            DO ji = 1, jpi
+               ! after free surface elevation
+               zssha = sshb(ji,jj) + rdt * ( wn(ji,jj,1) - emp(ji,jj) * zraur ) * tmask(ji,jj,1)
+               ! swap of arrays
+               sshb(ji,jj) = sshn(ji,jj)
+               sshn(ji,jj) = zssha
+            END DO
+         ELSE                                              ! Leap-frog time stepping and time filter
+            DO ji = 1, jpi
+               ! after free surface elevation
+               zssha = sshb(ji,jj) + z2dt * ( wn(ji,jj,1) - emp(ji,jj) * zraur ) * tmask(ji,jj,1)
+               ! time filter and array swap
+               sshb(ji,jj) = atfp * ( sshb(ji,jj) + zssha ) + atfp1 * sshn(ji,jj)
+               sshn(ji,jj) = zssha
+            END DO
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      !Boundary conditions on sshn
+      CALL lbc_lnk( sshn, 'T', 1. )
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce ) CALL flt_rst( kt, 'WRITE' )
+
+      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
+         CALL prt_ctl( tab3d_1=ua  , clinfo1=' spg  - Ua : ', mask1=umask,   &
+            &          tab3d_2=va  , clinfo2='        Va : ', mask2=vmask )
+         CALL prt_ctl( tab2d_1=sshn, clinfo1=' spg  - ssh: ', mask1=tmask)
+      ENDIF
+      !
+   END SUBROUTINE dyn_spg_flt_jki
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_flt_jki( kt, kindic )      ! Empty module
+      WRITE(*,*) 'dyn_spg_flt_jki: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE dyn_spg_flt_jki
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_flt_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_oce.F90	(revision 4536)
@@ -0,0 +1,54 @@
+MODULE dynspg_oce
+   !!----------------------------------------------------------------------
+   !!                       ***  MODULE dynspg_oce  ***
+   !!       
+   !! ** Purpose :   Define in memory all the ocean space domain variables
+   !!----------------------------------------------------------------------
+   !! Modules used
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC           
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   !! Surface pressure gradient logicals
+   !! ----------------------------------
+#if   defined key_dynspg_exp   ||  defined key_esopa
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_exp = .TRUE.  !: Explicit free surface flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_exp = .FALSE. !: Explicit free surface flag
+#endif
+#if   defined key_dynspg_ts   ||  defined key_esopa
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_ts  = .TRUE.  !: Free surface with time splitting flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_ts  = .FALSE. !: Free surface with time splitting flag
+#endif
+#if   defined key_dynspg_flt  ||  defined key_esopa
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_flt = .TRUE.  !: Filtered free surface cst volume flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_flt = .FALSE. !: Filtered free surface cst volume flag
+#endif
+#if   defined key_dynspg_rl
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_rl  = .TRUE.  !: Rigid-lid flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_rl  = .FALSE. !: Rigid-lid flag
+#endif
+
+#if   defined key_dynspg_ts   ||  defined key_vvl   ||  defined key_esopa
+   !! Time splitting variables
+   !! ------------------------
+      REAL(wp), PUBLIC, DIMENSION(jpi,jpj) :: & ! variables averaged over the barotropic loop
+         sshn_b, sshb_b,               &  ! sea surface heigth (now, before)
+         un_b  , vn_b                     ! vertically integrated horizontal velocities (now)
+      REAL(wp), PUBLIC, DIMENSION(jpi,jpj) :: & ! variables of the explicit barotropic loop
+         sshn_e, ssha_e,               &  ! sea surface heigth (now,after)
+         ua_e  , va_e                     ! vertically integrated horizontal velocities (after)
+#endif
+
+   !!----------------------------------------------------------------------
+
+END MODULE dynspg_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_rl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_rl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_rl.F90	(revision 4536)
@@ -0,0 +1,557 @@
+MODULE dynspg_rl
+   !!======================================================================
+   !!                    ***  MODULE  dynspg_rl  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+   !! History :  7.0  !  96-05  (G. Madec, M. Imbard, M. Guyon)  rewitting in 1
+   !!                           routine, without pointers, and with the same matrix
+   !!                           for sor and pcg, mpp exchange, and symmetric conditions
+   !!            " "  !  96-07  (A. Weaver)  Euler forward step
+   !!            " "  !  96-11  (A. Weaver)  correction to preconditioning:
+   !!            8.0  !  98-02  (M. Guyon)  FETI method
+   !!            " "  !  97-09  (J.-M. Molines)  Open boundaries
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!                 !  02-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!            9.0  !  04-08  (C. Talandier)  New trends organization
+   !!            " "  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!            " "  !  06-07  (S. Masson)  distributed restart using iom
+   !!---------------------------------------------------------------------
+#if   defined key_dynspg_rl   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_rl'                                           rigid lid
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_rl   : update the momentum trend with the surface pressure
+   !!                  for the rigid-lid case.
+   !!   rl_rst       : read/write the rigid-lid restart fields in the ocean restart file
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE sol_oce         ! ocean elliptic solver
+   USE solver          ! solver initialization
+   USE solpcg          ! preconditionned conjugate gradient solver
+   USE solsor          ! Successive Over-relaxation solver
+   USE solfet          ! FETI solver
+   USE solsor_e        ! Successive Over-relaxation solver with MPP optimization
+   USE solisl          ! ???
+   USE obc_oce         ! Lateral open boundary condition
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_spg_rl   ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+#  include "obc_vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynspg_rl.F90,v 1.11 2007/06/05 10:38:27 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_rl( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_rl  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!      gradient for the rigid-lid case,  add it to the general trend of 
+      !!      momentum equation.
+      !!
+      !! ** Method  :   Rigid-lid appromimation: the surface pressure gradient 
+      !!      is given by:
+      !!         spgu = 1/rau0 d/dx(ps) = Mu + 1/(hu e2u) dj-1(bsfd)
+      !!         spgv = 1/rau0 d/dy(ps) = Mv - 1/(hv e1v) di-1(bsfd)
+      !!      where (Mu,Mv) is the vertically averaged momentum trend (i.e.
+      !!      the vertical ponderated sum of the general momentum trend),
+      !!      and bsfd is the barotropic streamfunction trend.
+      !!      The trend is computed as follows:
+      !!         -1- compute the vertically averaged momentum trend (Mu,Mv)
+      !!         -2- compute the barotropic streamfunction trend by solving an
+      !!      ellipic equation using a diagonal preconditioned conjugate
+      !!      gradient or a successive-over-relaxation method (depending
+      !!      on nsolv, a namelist parameter).
+      !!         -3- add to bsfd the island trends if lk_isl=T
+      !!         -4- compute the after streamfunction is for further diagnos-
+      !!      tics using a leap-frog scheme.
+      !!         -5- add the momentum trend associated with the surface pres-
+      !!      sure gradient to the general trend.
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Madec et al. 1988, ocean modelling, issue 78, 1-6.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in  ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT( out ) ::   kindic   ! solver flag (<0 when the solver does not converge)
+      INTEGER ::   ji, jj, jk    ! dummy loop indices
+      REAL(wp) ::  zbsfa, zgcx, z2dt
+# if defined key_obc
+      INTEGER ::   ip, ii, ij
+      INTEGER ::   iii, ijj, jip, jnic
+      INTEGER ::   it, itm, itm2, ib, ibm, ibm2
+      REAL(wp) ::   z2dtr
+# endif
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_rl : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+         ! set to zero rigid-lid specific arrays
+         spgu(:,:) = 0.e0                   ! surface pressure gradient (i-direction) 
+         spgv(:,:) = 0.e0                   ! surface pressure gradient (j-direction)
+
+         CALL solver_init( nit000 )         ! Elliptic solver initialisation
+
+         ! read rigid lid arrays in restart file
+         CALL rl_rst( nit000, 'READ' )      ! read or initialize the following fields:
+         !                                  ! gcx, gcxb, bsfb, bsfn, bsfd
+      ENDIF
+
+      !  Vertically averaged momentum trend
+      ! ------------------------------------
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         
+         spgu(:,jj) = 0.                          ! initialization to zero
+         spgv(:,jj) = 0.
+         DO jk = 1, jpk                           ! vertical sum
+            DO ji = 2, jpim1
+               spgu(ji,jj) = spgu(ji,jj) + ua(ji,jj,jk) * fse3u(ji,jj,jk) * umask(ji,jj,jk)
+               spgv(ji,jj) = spgv(ji,jj) + va(ji,jj,jk) * fse3v(ji,jj,jk) * vmask(ji,jj,jk)
+            END DO 
+         END DO 
+         spgu(:,jj) = spgu(:,jj) * hur(:,jj)      ! divide by the depth 
+         spgv(:,jj) = spgv(:,jj) * hvr(:,jj)
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Boundary conditions on (spgu,spgv)
+      CALL lbc_lnk( spgu, 'U', -1. )
+      CALL lbc_lnk( spgv, 'V', -1. )
+
+      !  Barotropic streamfunction trend (bsfd)
+      ! ----------------------------------
+      DO jj = 2, jpjm1                            ! Curl of the vertically averaged velocity 
+         DO ji = 2, jpim1
+            gcb(ji,jj) = -gcdprc(ji,jj)   &
+               &       *(  ( e2v(ji+1,jj  )*spgv(ji+1,jj  ) - e2v(ji,jj)*spgv(ji,jj) )   &
+               &          -( e1u(ji  ,jj+1)*spgu(ji  ,jj+1) - e1u(ji,jj)*spgu(ji,jj) )   ) 
+         END DO
+      END DO
+
+# if defined key_obc
+      DO jj = 2, jpjm1                            ! Open boundary contribution 
+         DO ji = 2, jpim1
+           gcb(ji,jj) = gcb(ji,jj) - gcdprc(ji,jj) * gcbob(ji,jj)
+         END DO
+      END DO
+# else
+      ! No open boundary contribution
+# endif
+
+      ! First guess using previous solution of the elliptic system and
+      ! not bsfd since the system is solved with 0 as coastal boundary
+      ! condition. Also include a swap array (gcx,gxcb)
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zgcx        = gcx(ji,jj)
+            gcx (ji,jj) = 2.*zgcx - gcxb(ji,jj)
+            gcxb(ji,jj) =    zgcx
+         END DO
+      END DO
+      ! applied the lateral boundary conditions
+      IF( nsolv == 4)   CALL lbc_lnk_e( gcb, c_solver_pt, 1. )   
+
+      ! Relative precision (computation on one processor)
+      rnorme = 0.e0
+      rnorme = SUM( gcb(1:nlci,1:nlcj) * gcdmat(1:nlci,1:nlcj) * gcb(1:nlci,1:nlcj) * bmask(:,:) )
+      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+
+      epsr = eps*eps*rnorme
+      ncut = 0
+      ! if rnorme is 0, the solution is 0, the solver isn't called
+      IF( rnorme == 0.e0 ) THEN
+         bsfd (:,:) = 0.e0
+         res   = 0.e0
+         niter = 0
+         ncut  = 999
+      ENDIF
+
+      kindic = 0
+      ! solve the bsf system  ===> solution in gcx array
+      IF( ncut == 0 ) THEN
+         SELECT CASE ( nsolv )
+         CASE ( 1 )                    ! diagonal preconditioned conjuguate gradient
+            CALL sol_pcg( kindic )
+         CASE( 2 )                     ! successive-over-relaxation
+            CALL sol_sor( kindic )
+         CASE( 3 )                     ! FETI solver
+            CALL sol_fet( kindic )
+         CASE( 4 )                     ! successive-over-relaxation with extra outer halo
+            CALL sol_sor_e( kindic )
+         CASE DEFAULT                  ! e r r o r in nsolv namelist parameter
+            WRITE(ctmp1,*) ' ~~~~~~~~~~                not = ', nsolv
+            CALL ctl_stop( ' dyn_spg_rl : e r r o r, nsolv = 1, 2 ,3 or 4', ctmp1 )
+         END SELECT
+      ENDIF
+
+      ! bsf trend update
+      ! ----------------
+      bsfd(1:nlci,1:nlcj) = gcx(1:nlci,1:nlcj)
+      
+      ! update bsf trend with islands trend
+      ! -----------------------------------
+      IF( lk_isl )   CALL isl_dyn_spg         ! update bsfd
+
+# if defined key_obc
+      ! Compute bsf trend for OBC points (not masked)
+
+      IF( lp_obc_east ) THEN
+      ! compute bsf trend at the boundary from bsfeob, computed in obc_spg
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dtr = 1. / rdt
+      ELSE
+         z2dtr = 1. / (2. * rdt )
+      ENDIF
+      ! (jped,jpefm1),nieob
+      DO ji = fs_nie0, fs_nie1   ! vector opt.
+         DO jj = nje0m1, nje1m1
+            bsfd(ji,jj) = ( bsfeob(jj) - bsfb(ji,jj) ) * z2dtr
+         END DO
+      END DO
+      ENDIF
+
+      IF( lp_obc_west ) THEN
+      ! compute bsf trend at the boundary from bsfwob, computed in obc_spg
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dtr = 1. / rdt
+      ELSE
+         z2dtr = 1. / ( 2. * rdt )
+      ENDIF
+      ! (jpwd,jpwfm1),niwob
+      DO ji = fs_niw0, fs_niw1   ! vector opt.
+         DO jj = njw0m1, njw1m1
+            bsfd(ji,jj) = ( bsfwob(jj) - bsfb(ji,jj) ) * z2dtr
+         END DO
+      END DO
+      ENDIF
+
+      IF( lp_obc_north ) THEN
+      ! compute bsf trend at the boundary from bsfnob, computed in obc_spg
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dtr = 1. / rdt
+      ELSE
+         z2dtr = 1. / ( 2. * rdt )
+      ENDIF
+      ! njnob,(jpnd,jpnfm1)
+      DO jj = fs_njn0, fs_njn1   ! vector opt.
+         DO ji = nin0m1, nin1m1
+            bsfd(ji,jj) = ( bsfnob(ji) - bsfb(ji,jj) ) * z2dtr
+         END DO
+      END DO
+      ENDIF
+
+      IF( lp_obc_south ) THEN
+      ! compute bsf trend at the boundary from bsfsob, computed in obc_spg
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dtr = 1. / rdt
+      ELSE
+         z2dtr = 1. / ( 2. * rdt )
+      ENDIF
+      ! njsob,(jpsd,jpsfm1)
+      DO jj = fs_njs0, fs_njs1   ! vector opt.
+         DO ji = nis0m1, nis1m1
+            bsfd(ji,jj) = ( bsfsob(ji) - bsfb(ji,jj) ) * z2dtr
+         END DO
+      END DO
+      ENDIF
+
+      ! compute bsf trend for isolated coastline points
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dtr = 1. / rdt
+      ELSE
+         z2dtr = 1. /( 2. * rdt )
+      ENDIF
+
+      IF( nbobc > 1 ) THEN
+         DO jnic = 1,nbobc - 1
+            ip = mnic(0,jnic)
+            DO jip = 1,ip
+               ii = miic(jip,0,jnic)
+               ij = mjic(jip,0,jnic)
+               IF( ii >= 1 + nimpp - 1 .AND. ii <= jpi + nimpp -1 .AND. &
+                   ij >= 1 + njmpp - 1 .AND. ij <= jpj + njmpp -1 ) THEN
+                  iii = ii - nimpp + 1
+                  ijj = ij - njmpp + 1
+                  bsfd(iii,ijj) = ( bsfic(jnic) - bsfb(iii,ijj) ) * z2dtr
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+# endif
+
+      ! 4. Barotropic stream function and array swap
+      ! --------------------------------------------
+      ! Leap-frog time scheme, time filter and array swap
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         ! Euler time stepping (first time step, starting from rest)
+         z2dt = rdt
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zbsfa       = bsfb(ji,jj) + z2dt * bsfd(ji,jj)
+               bsfb(ji,jj) = bsfn(ji,jj)
+               bsfn(ji,jj) = zbsfa 
+            END DO
+         END DO
+      ELSE
+         ! Leap-frog time stepping - Asselin filter
+         z2dt = 2.*rdt
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zbsfa       = bsfb(ji,jj) + z2dt * bsfd(ji,jj)
+               bsfb(ji,jj) = atfp * ( bsfb(ji,jj) + zbsfa ) + atfp1 * bsfn(ji,jj)
+               bsfn(ji,jj) = zbsfa
+            END DO
+         END DO
+      ENDIF
+
+# if defined key_obc
+      ib   = 1      ! space index on boundary arrays
+      ibm  = 2
+      ibm2 = 3
+      it   = 1      ! time index on boundary arrays
+      itm  = 2
+      itm2 = 3
+
+      ! Swap of boundary arrays
+      IF( lp_obc_east ) THEN
+      ! (jped,jpef),nieob
+      IF( kt < nit000+3 .AND. .NOT.ln_rstart ) THEN
+         DO jj = nje0m1, nje1
+            ! fields itm2 <== itm
+            bebnd(jj,ib  ,itm2) = bebnd(jj,ib  ,itm)
+            bebnd(jj,ibm ,itm2) = bebnd(jj,ibm ,itm)
+            bebnd(jj,ibm2,itm2) = bebnd(jj,ibm2,itm)
+            bebnd(jj,ib  ,itm ) = bebnd(jj,ib  ,it )
+         END DO
+      ELSE
+         ! fields itm <== it  plus time filter at the boundary
+         DO ji = fs_nie0, fs_nie1   ! vector opt.
+            DO jj = nje0m1, nje1
+               bebnd(jj,ib  ,itm2) = bebnd(jj,ib  ,itm)
+               bebnd(jj,ibm ,itm2) = bebnd(jj,ibm ,itm)
+               bebnd(jj,ibm2,itm2) = bebnd(jj,ibm2,itm)
+               bebnd(jj,ib  ,itm ) = atfp * ( bebnd(jj,ib,itm) + bsfn(ji,jj) ) + atfp1 * bebnd(jj,ib,it)
+               bebnd(jj,ibm ,itm ) = bebnd(jj,ibm ,it )
+               bebnd(jj,ibm2,itm ) = bebnd(jj,ibm2,it )
+            END DO
+         END DO
+      ENDIF
+      ! fields it <== now (kt+1)
+      DO ji = fs_nie0, fs_nie1   ! vector opt.
+         DO jj = nje0m1, nje1
+            bebnd(jj,ib  ,it  ) = bsfn (ji  ,jj)
+            bebnd(jj,ibm ,it  ) = bsfn (ji-1,jj)
+            bebnd(jj,ibm2,it  ) = bsfn (ji-2,jj)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mppobc( bebnd, jpjed, jpjef, jpieob, 3*3, 2, jpj )
+      ENDIF
+
+      IF( lp_obc_west ) THEN
+      ! (jpwd,jpwf),niwob
+      IF( kt < nit000+3 .AND. .NOT.ln_rstart ) THEN
+         DO jj = njw0m1, njw1
+            ! fields itm2 <== itm
+            bwbnd(jj,ib  ,itm2) = bwbnd(jj,ib  ,itm)
+            bwbnd(jj,ibm ,itm2) = bwbnd(jj,ibm ,itm)
+            bwbnd(jj,ibm2,itm2) = bwbnd(jj,ibm2,itm)
+            bwbnd(jj,ib  ,itm ) = bwbnd(jj,ib  ,it )
+         END DO
+      ELSE
+         DO ji = fs_niw0, fs_niw1   ! Vector opt.
+            DO jj = njw0m1, njw1
+               bwbnd(jj,ib  ,itm2) = bwbnd(jj,ib  ,itm)
+               bwbnd(jj,ibm ,itm2) = bwbnd(jj,ibm ,itm)
+               bwbnd(jj,ibm2,itm2) = bwbnd(jj,ibm2,itm)
+               ! fields itm <== it  plus time filter at the boundary
+               bwbnd(jj,ib  ,itm ) = atfp * ( bwbnd(jj,ib,itm) + bsfn(ji,jj) ) + atfp1 * bwbnd(jj,ib,it)
+               bwbnd(jj,ibm ,itm ) = bwbnd(jj,ibm ,it )
+               bwbnd(jj,ibm2,itm ) = bwbnd(jj,ibm2,it )
+            END DO
+         END DO
+      ENDIF
+      ! fields it <== now (kt+1)
+      DO ji = fs_niw0, fs_niw1   ! Vector opt.
+         DO jj = njw0m1, njw1
+            bwbnd(jj,ib  ,it  ) = bsfn (ji  ,jj)
+            bwbnd(jj,ibm ,it  ) = bsfn (ji+1,jj)
+            bwbnd(jj,ibm2,it  ) = bsfn (ji+2,jj)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mppobc( bwbnd, jpjwd, jpjwf, jpiwob, 3*3, 2, jpj )
+      ENDIF
+
+      IF( lp_obc_north ) THEN
+   ! njnob,(jpnd,jpnf)
+      IF( kt < nit000 + 3 .AND. .NOT.ln_rstart ) THEN
+         DO ji = nin0m1, nin1
+            ! fields itm2 <== itm
+            bnbnd(ji,ib  ,itm2) = bnbnd(ji,ib  ,itm)
+            bnbnd(ji,ibm ,itm2) = bnbnd(ji,ibm ,itm)
+            bnbnd(ji,ibm2,itm2) = bnbnd(ji,ibm2,itm)
+            bnbnd(ji,ib  ,itm ) = bnbnd(ji,ib  ,it )
+         END DO
+      ELSE
+         DO jj = fs_njn0, fs_njn1   ! Vector opt.
+            DO ji = nin0m1, nin1
+               bnbnd(ji,ib  ,itm2) = bnbnd(ji,ib  ,itm)
+               bnbnd(ji,ibm ,itm2) = bnbnd(ji,ibm ,itm)
+               bnbnd(ji,ibm2,itm2) = bnbnd(ji,ibm2,itm)
+               ! fields itm <== it  plus time filter at the boundary
+               bnbnd(jj,ib  ,itm ) = atfp * ( bnbnd(jj,ib,itm) + bsfn(ji,jj) ) + atfp1 * bnbnd(jj,ib,it)
+               bnbnd(ji,ibm ,itm ) = bnbnd(ji,ibm ,it )
+               bnbnd(ji,ibm2,itm ) = bnbnd(ji,ibm2,it )
+            END DO
+          END DO
+      ENDIF
+      ! fields it <== now (kt+1)
+      DO jj = fs_njn0, fs_njn1   ! Vector opt.
+         DO ji = nin0m1, nin1
+            bnbnd(ji,ib  ,it  ) = bsfn (ji,jj  )
+            bnbnd(ji,ibm ,it  ) = bsfn (ji,jj-1)
+            bnbnd(ji,ibm2,it  ) = bsfn (ji,jj-2)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mppobc( bnbnd, jpind, jpinf, jpjnob, 3*3, 1, jpi )
+      ENDIF
+
+      IF( lp_obc_south ) THEN
+         ! njsob,(jpsd,jpsf)
+         IF( kt < nit000+3 .AND. .NOT.ln_rstart ) THEN
+            DO ji = nis0m1, nis1
+               ! fields itm2 <== itm
+               bsbnd(ji,ib  ,itm2) = bsbnd(ji,ib  ,itm)
+               bsbnd(ji,ibm ,itm2) = bsbnd(ji,ibm ,itm)
+               bsbnd(ji,ibm2,itm2) = bsbnd(ji,ibm2,itm)
+               bsbnd(ji,ib  ,itm ) = bsbnd(ji,ib  ,it )
+            END DO
+         ELSE
+            DO jj = fs_njs0, fs_njs1   ! vector opt.
+               DO ji = nis0m1, nis1
+                  bsbnd(ji,ib  ,itm2) = bsbnd(ji,ib  ,itm)
+                  bsbnd(ji,ibm ,itm2) = bsbnd(ji,ibm ,itm)
+                  bsbnd(ji,ibm2,itm2) = bsbnd(ji,ibm2,itm)
+                  ! fields itm <== it  plus time filter at the boundary
+                  bsbnd(jj,ib  ,itm ) = atfp * ( bsbnd(jj,ib,itm) + bsfn(ji,jj) ) + atfp1 * bsbnd(jj,ib,it)
+                  bsbnd(ji,ibm ,itm ) = bsbnd(ji,ibm ,it )
+                  bsbnd(ji,ibm2,itm ) = bsbnd(ji,ibm2,it )
+               END DO
+            END DO
+         ENDIF
+         DO jj = fs_njs0, fs_njs1   ! vector opt.
+            DO ji = nis0m1, nis1 
+               ! fields it <== now (kt+1)
+               bsbnd(ji,ib  ,it  ) = bsfn (ji,jj  )
+               bsbnd(ji,ibm ,it  ) = bsfn (ji,jj+1)
+               bsbnd(ji,ibm2,it  ) = bsfn (ji,jj+2)
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc( bsbnd, jpisd, jpisf, jpjsob, 3*3, 1, jpi )
+      ENDIF
+# endif
+      
+      !  add the surface pressure trend to the general trend
+      ! -----------------------------------------------------
+      DO jj = 2, jpjm1
+         ! update the surface pressure gradient with the barotropic trend
+         DO ji = 2, jpim1
+            spgu(ji,jj) = spgu(ji,jj) + hur(ji,jj) / e2u(ji,jj) * ( bsfd(ji,jj) - bsfd(ji  ,jj-1) )
+            spgv(ji,jj) = spgv(ji,jj) - hvr(ji,jj) / e1v(ji,jj) * ( bsfd(ji,jj) - bsfd(ji-1,jj  ) )
+         END DO
+         ! add the surface pressure gradient trend to the general trend
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ua(ji,jj,jk) - spgu(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) - spgv(ji,jj)
+            END DO
+         END DO
+      END DO
+
+      ! write rigid lid arrays in restart file
+      ! --------------------------------------
+      IF( lrst_oce ) CALL rl_rst( kt, 'WRITE' )
+
+   END SUBROUTINE dyn_spg_rl
+
+
+   SUBROUTINE rl_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE rl_rst  ***
+     !!
+     !! ** Purpose : Read or write rigid-lid arrays in ocean restart file
+     !!----------------------------------------------------------------------
+     INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+     !!----------------------------------------------------------------------
+     !
+     IF( TRIM(cdrw) == 'READ' ) THEN
+        IF( iom_varid( numror, 'gcx' ) > 0 ) THEN
+     ! Caution : extra-hallow
+     ! gcx and gcxb are defined as: DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj)
+           CALL iom_get( numror, jpdom_autoglo, 'gcx' , gcx (1:jpi,1:jpj) )
+           CALL iom_get( numror, jpdom_autoglo, 'gcxb', gcxb(1:jpi,1:jpj) )
+           CALL iom_get( numror, jpdom_autoglo, 'bsfb', bsfb(:,:)         )
+           CALL iom_get( numror, jpdom_autoglo, 'bsfn', bsfn(:,:)         )
+           CALL iom_get( numror, jpdom_autoglo, 'bsfd', bsfd(:,:)         )
+           IF( neuler == 0 ) THEN
+              gcxb(:,:) = gcx (:,:)
+              bsfb(:,:) = bsfn(:,:)
+           ENDIF
+        ELSE
+           gcx (:,:) = 0.e0
+           gcxb(:,:) = 0.e0
+           bsfb(:,:) = 0.e0
+           bsfn(:,:) = 0.e0
+           bsfd(:,:) = 0.e0
+        ENDIF
+     ELSEIF(  TRIM(cdrw) == 'WRITE' ) THEN
+        ! Caution : extra-hallow, gcx and gcxb are defined as: DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj)
+        CALL iom_rstput( kt, nitrst, numrow, 'gcx' , gcx (1:jpi,1:jpj) )
+        CALL iom_rstput( kt, nitrst, numrow, 'gcxb', gcxb(1:jpi,1:jpj) )
+        CALL iom_rstput( kt, nitrst, numrow, 'bsfb', bsfb(:,:)         )
+        CALL iom_rstput( kt, nitrst, numrow, 'bsfn', bsfn(:,:)         )
+        CALL iom_rstput( kt, nitrst, numrow, 'bsfd', bsfd(:,:)         )
+     ENDIF
+     !
+   END SUBROUTINE rl_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_rl'                                        NO rigid lid
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_rl( kt, kindic )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_rl: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE dyn_spg_rl
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_rl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4536)
@@ -0,0 +1,691 @@
+MODULE dynspg_ts
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_ts  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+   !! History :   9.0  !  04-12  (L. Bessieres, G. Madec)  Original code
+   !!             " "  !  05-11  (V. Garnier, G. Madec)  optimization
+   !!             9.0  !  06-08  (S. Masson)  distributed restart using iom
+   !!---------------------------------------------------------------------
+#if defined key_dynspg_ts   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_ts'         free surface cst volume with time splitting
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_ts  : compute surface pressure gradient trend using a time-
+   !!                 splitting scheme and add to the general trend 
+   !!   ts_rst      : read/write the time-splitting restart fields in the ocean restart file
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition
+   USE obcdta          ! open boundary condition data     
+   USE obcfla          ! Flather open boundary condition  
+   USE dynvor          ! vorticity term
+   USE obc_oce         ! Lateral open boundary condition
+   USE obc_par         ! open boundary condition parameters
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE restart         ! only for lrst_oce
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dyn_spg_ts  ! routine called by step.F90
+   PUBLIC ts_rst      ! routine called by j-k-i subroutine
+
+   REAL(wp), DIMENSION(jpi,jpj) ::  ftnw, ftne,   &  ! triad of coriolis parameter
+      &                             ftsw, ftse       ! (only used with een vorticity scheme)
+
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynspg_ts.F90,v 1.16 2007/06/05 10:38:27 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_ts( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_ts  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!      gradient in case of free surface formulation with time-splitting.
+      !!      Add it to the general trend of momentum equation.
+      !!      Compute the free surface.
+      !!
+      !! ** Method  :   Free surface formulation with time-splitting
+      !!      -1- Save the vertically integrated trend. This general trend is
+      !!          held constant over the barotropic integration.
+      !!          The Coriolis force is removed from the general trend as the
+      !!          surface gradient and the Coriolis force are updated within
+      !!          the barotropic integration.
+      !!      -2- Barotropic loop : updates of sea surface height (ssha_e) and 
+      !!          barotropic transports (ua_e and va_e) through barotropic 
+      !!          momentum and continuity integration. Barotropic former 
+      !!          variables are time averaging over the full barotropic cycle
+      !!          (= 2 * baroclinic time step) and saved in zsshX_b, zuX_b 
+      !!          and zvX_b (X specifying after, now or before).
+      !!      -3- Update of sea surface height from time averaged barotropic 
+      !!          variables.
+      !!        - apply lateral boundary conditions on sshn.
+      !!      -4- The new general trend becomes :
+      !!          ua = ua - sum_k(ua)/H + ( zua_b - sum_k(ub) )/H
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References : Griffies et al., (2003): A technical guide to MOM4. NOAA/GFDL
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk, jit             ! dummy loop indices
+      INTEGER  ::  icycle                      ! temporary scalar
+      REAL(wp) ::                           &
+         zraur, zcoef, z2dt_e, z2dt_b, zfac25,   &  ! temporary scalars
+         zfact1, zspgu, zcubt, zx1, zy1,    &  !     "        "
+         zfact2, zspgv, zcvbt, zx2, zy2        !     "        "
+      REAL(wp), DIMENSION(jpi,jpj) ::       &
+         zcu, zcv, zwx, zwy, zhdiv,         &  ! temporary arrays
+         zua, zva, zub, zvb,                &  !     "        "
+         zssha_b, zua_b, zva_b,             &  !     "        "
+         zsshb_e, zub_e, zvb_e,             &  !     "        "
+         zun_e, zvn_e                          !     "        "
+      !! Variable volume
+      REAL(wp), DIMENSION(jpi,jpj)     ::   &
+         zspgu_1, zspgv_1, zsshun_e, zsshvn_e, hu_e, hv_e         ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zfse3un_e, zfse3vn_e  ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      ! Arrays initialization
+      ! ---------------------
+      zua_b(:,:) = 0.e0   ;   zub_e(:,:) = 0.e0   ;   zun_e(:,:) = 0.e0
+      zva_b(:,:) = 0.e0   ;   zvb_e(:,:) = 0.e0   ;   zvn_e(:,:) = 0.e0
+      zhdiv(:,:) = 0.e0
+
+
+      IF( kt == nit000 ) THEN
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_ts : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~   free surface with time splitting'
+         IF(lwp) WRITE(numout,*) ' Number of sub cycle in 1 time-step (2 rdt) : icycle = ', FLOOR( 2*rdt/rdtbt )
+
+         CALL ts_rst( nit000, 'READ' )   ! read or initialize the following fields:
+         !                               ! sshb, sshn, sshb_b, sshn_b, un_b, vn_b
+
+         ssha_e(:,:) = sshn(:,:)
+         ua_e(:,:)   = un_b(:,:)
+         va_e(:,:)   = vn_b(:,:)
+
+         IF( ln_dynvor_een ) THEN
+            ftne(1,:) = 0.e0   ;   ftnw(1,:) = 0.e0   ;   ftse(1,:) = 0.e0   ;   ftsw(1,:) = 0.e0
+            DO jj = 2, jpj
+               DO ji = fs_2, jpi   ! vector opt.
+                  ftne(ji,jj) = ( ff(ji-1,jj  ) + ff(ji  ,jj  ) + ff(ji  ,jj-1) ) / 3.
+                  ftnw(ji,jj) = ( ff(ji-1,jj-1) + ff(ji-1,jj  ) + ff(ji  ,jj  ) ) / 3.
+                  ftse(ji,jj) = ( ff(ji  ,jj  ) + ff(ji  ,jj-1) + ff(ji-1,jj-1) ) / 3.
+                  ftsw(ji,jj) = ( ff(ji  ,jj-1) + ff(ji-1,jj-1) + ff(ji-1,jj  ) ) / 3.
+               END DO
+            END DO
+         ENDIF
+         !
+      ENDIF
+
+      ! Substract the surface pressure gradient from the momentum
+      ! ---------------------------------------------------------
+      IF( lk_vvl ) THEN    ! Variable volume
+
+         ! 0. Local initialization
+         ! -----------------------
+         zspgu_1(:,:) = 0.e0
+         zspgv_1(:,:) = 0.e0
+
+         ! 1. Surface pressure gradient (now)
+         ! ----------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zspgu_1(ji,jj) = -grav * ( ( rhd(ji+1,jj  ,1) + 1 ) * sshn(ji+1,jj  ) &
+                  &                     - ( rhd(ji  ,jj  ,1) + 1 ) * sshn(ji  ,jj  ) ) / e1u(ji,jj)
+               zspgv_1(ji,jj) = -grav * ( ( rhd(ji  ,jj+1,1) + 1 ) * sshn(ji  ,jj+1) &
+                  &                     - ( rhd(ji  ,jj  ,1) + 1 ) * sshn(ji  ,jj  ) ) / e2v(ji,jj)
+            END DO 
+         END DO
+
+         ! 2. Substract the surface pressure trend from the general trend
+         ! ------------------------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ua(ji,jj,jk) - zspgu_1(ji,jj)
+                  va(ji,jj,jk) = va(ji,jj,jk) - zspgv_1(ji,jj)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+      ! Local constant initialization
+      ! --------------------------------
+      z2dt_b = 2.0 * rdt                                    ! baroclinic time step
+      IF ( neuler == 0 .AND. kt == nit000 ) z2dt_b = rdt
+      zfact1 = 0.5 * 0.25                                   ! coefficient for vorticity estimates
+      zfact2 = 0.5 * 0.5
+      zraur  = 1. / rauw                                    ! 1 / volumic mass of pure water
+      
+      ! -----------------------------------------------------------------------------
+      !  Phase 1 : Coupling between general trend and barotropic estimates (1st step)
+      ! -----------------------------------------------------------------------------
+
+      ! Vertically integrated quantities
+      ! --------------------------------
+      zua(:,:) = 0.e0
+      zva(:,:) = 0.e0
+      zub(:,:) = 0.e0
+      zvb(:,:) = 0.e0
+      zwx(:,:) = 0.e0
+      zwy(:,:) = 0.e0
+
+      ! vertical sum
+      IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
+         DO jk = 1, jpkm1
+            DO ji = 1, jpij
+               !                                                           ! Vertically integrated momentum trends
+               zua(ji,1) = zua(ji,1) + fse3u(ji,1,jk) * umask(ji,1,jk) * ua(ji,1,jk)
+               zva(ji,1) = zva(ji,1) + fse3v(ji,1,jk) * vmask(ji,1,jk) * va(ji,1,jk)
+               !                                                           ! Vertically integrated transports (before)
+               zub(ji,1) = zub(ji,1) + fse3u(ji,1,jk) * ub(ji,1,jk)
+               zvb(ji,1) = zvb(ji,1) + fse3v(ji,1,jk) * vb(ji,1,jk)
+               !                                                           ! Planetary vorticity transport fluxes (now)
+               zwx(ji,1) = zwx(ji,1) + e2u(ji,1) * fse3u(ji,1,jk) * un(ji,1,jk)
+               zwy(ji,1) = zwy(ji,1) + e1v(ji,1) * fse3v(ji,1,jk) * vn(ji,1,jk)
+            END DO
+         END DO
+      ELSE                             ! No  vector opt.
+         DO jk = 1, jpkm1
+            !                                                           ! Vertically integrated momentum trends
+            zua(:,:) = zua(:,:) + fse3u(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
+            zva(:,:) = zva(:,:) + fse3v(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
+            !                                                           ! Vertically integrated transports (before)
+            zub(:,:) = zub(:,:) + fse3u(:,:,jk) * ub(:,:,jk)
+            zvb(:,:) = zvb(:,:) + fse3v(:,:,jk) * vb(:,:,jk)
+            !                                                           ! Planetary vorticity (now)
+            zwx(:,:) = zwx(:,:) + e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = zwy(:,:) + e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         END DO
+      ENDIF
+
+      IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = ( zwy(ji,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
+               zy2 = ( zwy(ji,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 = ( zwx(ji-1,jj) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
+               zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               ! energy conserving formulation for planetary vorticity term
+               zcu(ji,jj) = zfact2 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 )
+               zcv(ji,jj) =-zfact2 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 )
+            END DO
+         END DO
+         !
+      ELSEIF ( ln_dynvor_ens ) THEN                    ! enstrophy conserving scheme
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = zfact1 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                              + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 =-zfact1 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                              + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               zcu(ji,jj)  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) )
+               zcv(ji,jj)  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) )
+            END DO
+         END DO
+         !
+      ELSEIF ( ln_dynvor_een ) THEN                    ! enstrophy and energy conserving scheme
+         zfac25 = 0.25
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcu(ji,jj) = + zfac25 / e1u(ji,jj)   &
+                  &       * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) + ftnw(ji+1,jj) * zwy(ji+1,jj  )   &
+                  &          + ftse(ji,jj  ) * zwy(ji  ,jj-1) + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
+               zcv(ji,jj) = - zfac25 / e2v(ji,jj)   &
+                  &       * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) + ftse(ji,jj+1) * zwx(ji  ,jj+1)   &
+                  &          + ftnw(ji,jj  ) * zwx(ji-1,jj  ) + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
+            END DO
+         END DO
+         !
+      ENDIF
+
+
+      ! Remove barotropic trend from general momentum trend
+      ! ---------------------------------------------------
+      DO jk = 1 , jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) = ua(ji,jj,jk) - zua(ji,jj) * hur(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) - zva(ji,jj) * hvr(ji,jj)
+            END DO
+         END DO
+      END DO
+
+      ! Remove coriolis term from barotropic trend
+      ! ------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zua(ji,jj) = zua(ji,jj) - zcu(ji,jj)
+            zva(ji,jj) = zva(ji,jj) - zcv(ji,jj)
+         END DO
+      END DO
+
+      ! -----------------------------------------------------------------------
+      !  Phase 2 : Integration of the barotropic equations with time splitting
+      ! -----------------------------------------------------------------------
+
+      ! Initialisations
+      !----------------
+      ! Number of iteration of the barotropic loop
+      icycle = FLOOR( z2dt_b / rdtbt )
+
+      ! variables for the barotropic equations
+      zsshb_e(:,:) = sshn_b(:,:)       ! (barotropic) sea surface height (before and now)
+      sshn_e (:,:) = sshn_b(:,:)
+      zub_e  (:,:) = un_b  (:,:)       ! barotropic transports issued from the barotropic equations (before and now)
+      zvb_e  (:,:) = vn_b  (:,:)
+      zun_e  (:,:) = un_b  (:,:)
+      zvn_e  (:,:) = vn_b  (:,:)
+      zssha_b(:,:) = sshn  (:,:)       ! time averaged variables over all sub-timesteps
+      zua_b  (:,:) = un_b  (:,:)   
+      zva_b  (:,:) = vn_b  (:,:)
+      IF( lk_vvl ) THEN
+         zsshun_e(:,:)    = sshu (:,:)     ! (barotropic) sea surface height (now) at u-point
+         zsshvn_e(:,:)    = sshv (:,:)     ! (barotropic) sea surface height (now) at v-point
+         hu_e(:,:)        = hu   (:,:)     ! (barotropic) ocean depth at u-point
+         hv_e(:,:)        = hv   (:,:)     ! (barotropic) ocean depth at v-point
+         zfse3un_e(:,:,:) = fse3u(:,:,:)   ! (barotropic) scale factors  at u-point
+         zfse3un_e(:,:,:) = fse3v(:,:,:)   ! (barotropic) scale factors  at v-point
+      ENDIF
+
+      ! set ssh corrections to 0
+      ! ssh corrections are applied to normal velocities (Flather's algorithm) and averaged over the barotropic loop
+#if defined key_obc
+      IF( lp_obc_east  )   sshfoe_b(:,:) = 0.e0
+      IF( lp_obc_west  )   sshfow_b(:,:) = 0.e0
+      IF( lp_obc_south )   sshfos_b(:,:) = 0.e0
+      IF( lp_obc_north )   sshfon_b(:,:) = 0.e0
+#endif
+
+      ! Barotropic integration over 2 baroclinic time steps
+      ! ---------------------------------------------------
+
+      !                                                    ! ==================== !
+      DO jit = 1, icycle                                   !  sub-time-step loop  !
+         !                                                 ! ==================== !
+         z2dt_e = 2. * rdtbt
+         IF ( jit == 1 )   z2dt_e = rdtbt
+
+         ! Time interpolation of open boundary condition data
+         IF( lk_obc )   CALL obc_dta_bt( kt, jit )
+
+         ! Horizontal divergence of barotropic transports
+         !--------------------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zhdiv(ji,jj) = ( e2u(ji  ,jj  ) * zun_e(ji  ,jj)              &
+                  &            -e2u(ji-1,jj  ) * zun_e(ji-1,jj)              &
+                  &            +e1v(ji  ,jj  ) * zvn_e(ji  ,jj)              &
+                  &            -e1v(ji  ,jj-1) * zvn_e(ji  ,jj-1) )          &
+                  &           / (e1t(ji,jj)*e2t(ji,jj))
+            END DO
+         END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1)   = 0.e0      ! east
+         IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1)   = 0.e0      ! west
+         IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0      ! north
+         IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1)   = 0.e0      ! south
+#endif
+
+         ! Sea surface height from the barotropic system
+         !----------------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ssha_e(ji,jj) = ( zsshb_e(ji,jj) - z2dt_e *  ( zraur * emp(ji,jj)  &
+            &            +  zhdiv(ji,jj) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+
+         ! evolution of the barotropic transport ( following the vorticity scheme used)
+         ! ----------------------------------------------------------------------------
+         zwx(:,:) = e2u(:,:) * zun_e(:,:)
+         zwy(:,:) = e1v(:,:) * zvn_e(:,:)
+
+         IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! surface pressure gradient
+                  IF( lk_vvl) THEN
+                     zspgu = -grav * ( ( rhd(ji+1,jj,1) + 1 ) * sshn_e(ji+1,jj) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hu_e(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( ( rhd(ji,jj+1,1) + 1 ) * sshn_e(ji,jj+1) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hv_e(ji,jj) / e2v(ji,jj)
+                  ELSE
+                     zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ENDIF
+                  ! energy conserving formulation for planetary vorticity term
+                  zy1 = ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
+                  zy2 = ( zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+                  zx1 = ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
+                  zx2 = ( zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+                  zcubt = zfact2 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 )
+                  zcvbt =-zfact2 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+            END DO
+            !
+         ELSEIF ( ln_dynvor_ens ) THEN                    ! enstrophy conserving scheme
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! surface pressure gradient
+                  IF( lk_vvl) THEN
+                     zspgu = -grav * ( ( rhd(ji+1,jj,1) + 1 ) * sshn_e(ji+1,jj) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hu_e(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( ( rhd(ji,jj+1,1) + 1 ) * sshn_e(ji,jj+1) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hv_e(ji,jj) / e2v(ji,jj)
+                  ELSE
+                     zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ENDIF
+                  ! enstrophy conserving formulation for planetary vorticity term
+                  zy1 = zfact1 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                                 + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+                  zx1 =-zfact1 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                                 + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+                  zcubt  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) )
+                  zcvbt  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+            END DO
+            !
+         ELSEIF ( ln_dynvor_een ) THEN                    ! energy and enstrophy conserving scheme
+            zfac25 = 0.25
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! surface pressure gradient
+                  IF( lk_vvl) THEN
+                     zspgu = -grav * ( ( rhd(ji+1,jj,1) + 1 ) * sshn_e(ji+1,jj) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hu_e(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( ( rhd(ji,jj+1,1) + 1 ) * sshn_e(ji,jj+1) &
+                        &  - ( rhd(ji,jj,1) + 1 ) * sshn_e(ji,jj) ) * hv_e(ji,jj) / e2v(ji,jj)
+                  ELSE
+                     zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                     zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ENDIF
+                  ! energy/enstrophy conserving formulation for planetary vorticity term
+                  zcubt = + zfac25 / e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) + ftnw(ji+1,jj) * zwy(ji+1,jj  )   &
+                     &                             + ftse(ji,jj  ) * zwy(ji  ,jj-1) + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
+                  zcvbt = - zfac25 / e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) + ftse(ji,jj+1) * zwx(ji  ,jj+1)   &
+                     &                             + ftnw(ji,jj  ) * zwx(ji-1,jj  ) + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+            END DO
+            ! 
+         ENDIF
+
+         ! Flather's boundary condition for the barotropic loop :
+         !         - Update sea surface height on each open boundary
+         !         - Correct the barotropic transports
+         IF( lk_obc )   CALL obc_fla_ts
+
+
+         ! ... Boundary conditions on ua_e, va_e, ssha_e
+         CALL lbc_lnk( ua_e  , 'U', -1. )
+         CALL lbc_lnk( va_e  , 'V', -1. )
+         CALL lbc_lnk( ssha_e, 'T',  1. )
+
+         ! temporal sum
+         !-------------
+         zssha_b(:,:) = zssha_b(:,:) + ssha_e(:,:)
+         zua_b  (:,:) = zua_b  (:,:) + ua_e  (:,:)
+         zva_b  (:,:) = zva_b  (:,:) + va_e  (:,:) 
+
+         ! Time filter and swap of dynamics arrays
+         ! ---------------------------------------
+         IF( neuler == 0 .AND. jit == 1 ) THEN   ! Euler (forward) time stepping
+            zsshb_e(:,:) = sshn_e(:,:)
+            zub_e  (:,:) = zun_e (:,:)
+            zvb_e  (:,:) = zvn_e (:,:)
+            sshn_e (:,:) = ssha_e(:,:)
+            zun_e  (:,:) = ua_e  (:,:)
+            zvn_e  (:,:) = va_e  (:,:)
+         ELSE                                        ! Asselin filtering
+            zsshb_e(:,:) = atfp * ( zsshb_e(:,:) + ssha_e(:,:) ) + atfp1 * sshn_e(:,:)
+            zub_e  (:,:) = atfp * ( zub_e  (:,:) + ua_e  (:,:) ) + atfp1 * zun_e  (:,:)
+            zvb_e  (:,:) = atfp * ( zvb_e  (:,:) + va_e  (:,:) ) + atfp1 * zvn_e  (:,:)
+            sshn_e (:,:) = ssha_e(:,:)
+            zun_e  (:,:) = ua_e  (:,:)
+            zvn_e  (:,:) = va_e  (:,:)
+         ENDIF
+
+         IF( lk_vvl ) THEN ! Variable volume
+
+            ! Sea surface elevation
+            ! ---------------------
+            DO jj = 1, jpjm1
+               DO ji = 1,jpim1
+
+                  ! Sea Surface Height at u-point before
+                  zsshun_e(ji,jj) = 0.5 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )   &
+                     &              * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshn_e(ji  ,jj)    &
+                     &                + e1t(ji+1,jj) * e2t(ji+1,jj) * sshn_e(ji+1,jj) )
+
+                  ! Sea Surface Height at v-point before
+                  zsshvn_e(ji,jj) = 0.5 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )   &
+                     &              * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshn_e(ji,jj  )    &
+                     &                + e1t(ji,jj+1) * e2t(ji,jj+1) * sshn_e(ji,jj+1) )
+
+               END DO
+            END DO
+
+            ! Boundaries conditions
+            CALL lbc_lnk( zsshun_e, 'U', 1. )    ;    CALL lbc_lnk( zsshvn_e, 'V', 1. )
+
+            ! Scale factors at before and after time step
+            ! -------------------------------------------
+            CALL dom_vvl_sf( zsshun_e, 'U', zfse3un_e ) ;   CALL dom_vvl_sf( zsshvn_e, 'V', zfse3vn_e )
+
+            ! Ocean depth at U- and V-points
+            hu_e(:,:) = 0.e0
+            hv_e(:,:) = 0.e0
+
+            DO jk = 1, jpk
+               hu_e(:,:) = hu_e(:,:) + zfse3un_e(:,:,jk) * umask(:,:,jk)
+               hv_e(:,:) = hv_e(:,:) + zfse3vn_e(:,:,jk) * vmask(:,:,jk)
+            END DO
+
+         ENDIF ! End variable volume case
+
+         !                                                 ! ==================== !
+      END DO                                               !        end loop      !
+      !                                                    ! ==================== !
+
+
+      ! Time average of after barotropic variables
+      zcoef =  1.e0 / (  FLOAT( icycle +1 )  )
+      zssha_b(:,:) = zcoef * zssha_b(:,:) 
+      zua_b  (:,:) = zcoef *  zua_b (:,:) 
+      zva_b  (:,:) = zcoef *  zva_b (:,:) 
+#if defined key_obc
+         IF( lp_obc_east  )   sshfoe_b(:,:) = zcoef * sshfoe_b(:,:)
+         IF( lp_obc_west  )   sshfow_b(:,:) = zcoef * sshfow_b(:,:)
+         IF( lp_obc_north )   sshfon_b(:,:) = zcoef * sshfon_b(:,:)
+         IF( lp_obc_south )   sshfos_b(:,:) = zcoef * sshfos_b(:,:)
+#endif
+     
+
+      ! ---------------------------------------------------------------------------
+      ! Phase 3 : Update sea surface height from time averaged barotropic variables
+      ! ---------------------------------------------------------------------------
+
+ 
+      ! Horizontal divergence of time averaged barotropic transports
+      !-------------------------------------------------------------
+      IF( .NOT. lk_vvl ) THEN
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zhdiv(ji,jj) = ( e2u(ji,jj) * un_b(ji,jj) - e2u(ji-1,jj  ) * un_b(ji-1,jj  )     &
+                  &            +e1v(ji,jj) * vn_b(ji,jj) - e1v(ji  ,jj-1) * vn_b(ji  ,jj-1) )   &
+                  &           / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+      ENDIF
+
+#if defined key_obc && ! defined key_vvl
+      ! open boundaries (div must be zero behind the open boundary)
+      !  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
+      IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1)   = 0.e0    ! east
+      IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1)   = 0.e0    ! west
+      IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0    ! north
+      IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1)   = 0.e0    ! south
+#endif
+
+      ! sea surface height
+      !-------------------
+      IF( lk_vvl ) THEN
+         sshbb(:,:) = sshb(:,:)
+         sshb (:,:) = sshn(:,:)
+         sshn (:,:) = ssha(:,:)
+      ELSE
+         sshb (:,:) = sshn(:,:)
+         sshn(:,:) = (  sshb_b(:,:) - z2dt_b * ( zraur * emp(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
+      ENDIF
+
+      ! ... Boundary conditions on sshn
+      IF( .NOT. lk_obc ) CALL lbc_lnk( sshn, 'T', 1. )
+
+
+      ! -----------------------------------------------------------------------------
+      ! Phase 4. Coupling between general trend and barotropic estimates - (2nd step)
+      ! -----------------------------------------------------------------------------
+
+      ! Swap on time averaged barotropic variables
+      ! ------------------------------------------
+      sshb_b(:,:) = sshn_b (:,:)
+      IF ( kt == nit000 ) zssha_b(:,:) = sshn(:,:)
+      sshn_b(:,:) = zssha_b(:,:)
+      un_b  (:,:) = zua_b  (:,:) 
+      vn_b  (:,:) = zva_b  (:,:) 
+   
+      ! add time averaged barotropic coriolis and surface pressure gradient
+      ! terms to the general momentum trend
+      ! --------------------------------------------------------------------
+      DO jk=1,jpkm1
+         ua(:,:,jk) = ua(:,:,jk) + hur(:,:) * ( zua_b(:,:) - zub(:,:) ) / z2dt_b
+         va(:,:,jk) = va(:,:,jk) + hvr(:,:) * ( zva_b(:,:) - zvb(:,:) ) / z2dt_b
+      END DO
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce )   CALL ts_rst( kt, 'WRITE' )
+
+      ! print sum trends (used for debugging)
+      IF( ln_ctl )     CALL prt_ctl( tab2d_1=sshn, clinfo1=' ssh      : ', mask1=tmask )
+      !
+   END SUBROUTINE dyn_spg_ts
+
+
+   SUBROUTINE ts_rst( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE ts_rst  ***
+      !!
+      !! ** Purpose : Read or write time-splitting arrays in restart file
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      !
+      INTEGER ::  ji, jk        ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN
+         IF( iom_varid( numror, 'sshn' ) > 0 ) THEN
+            CALL iom_get( numror, jpdom_autoglo, 'sshb'  , sshb(:,:)   )
+            CALL iom_get( numror, jpdom_autoglo, 'sshn'  , sshn(:,:)   )
+            IF( neuler == 0 ) sshb(:,:) = sshn(:,:)
+         ELSE
+            IF( nn_rstssh == 1 ) THEN  
+               sshb(:,:) = 0.e0
+               sshn(:,:) = 0.e0
+            ENDIF
+         ENDIF
+         IF( iom_varid( numror, 'sshn_b' ) > 0 ) THEN
+            CALL iom_get( numror, jpdom_autoglo, 'sshb_b', sshb_b(:,:) )   ! free surface issued
+            CALL iom_get( numror, jpdom_autoglo, 'sshn_b', sshn_b(:,:) )   ! from time-splitting loop
+            CALL iom_get( numror, jpdom_autoglo, 'un_b'  , un_b  (:,:) )   ! horizontal transports issued
+            CALL iom_get( numror, jpdom_autoglo, 'vn_b'  , vn_b  (:,:) )   ! from barotropic loop
+            IF( neuler == 0 ) sshb_b(:,:) = sshn_b(:,:)
+         ELSE
+            sshb_b(:,:) = sshb(:,:)
+            sshn_b(:,:) = sshn(:,:)
+            un_b  (:,:) = 0.e0
+            vn_b  (:,:) = 0.e0
+            ! vertical sum
+            IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
+               DO jk = 1, jpkm1
+                  DO ji = 1, jpij
+                     un_b(ji,1) = un_b(ji,1) + fse3u(ji,1,jk) * un(ji,1,jk)
+                     vn_b(ji,1) = vn_b(ji,1) + fse3v(ji,1,jk) * vn(ji,1,jk)
+                  END DO
+               END DO
+            ELSE                             ! No  vector opt.
+               DO jk = 1, jpkm1
+                  un_b(:,:) = un_b(:,:) + fse3u(:,:,jk) * un(:,:,jk)
+                  vn_b(:,:) = vn_b(:,:) + fse3v(:,:,jk) * vn(:,:,jk)
+               END DO
+            ENDIF
+         ENDIF
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+         CALL iom_rstput( kt, nitrst, numrow, 'sshb'  , sshb  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'sshn'  , sshn  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'sshb_b', sshb_b(:,:) )   ! free surface issued
+         CALL iom_rstput( kt, nitrst, numrow, 'sshn_b', sshn_b(:,:) )   ! from barotropic loop
+         CALL iom_rstput( kt, nitrst, numrow, 'un_b'  , un_b  (:,:) )   ! horizontal transports issued
+         CALL iom_rstput( kt, nitrst, numrow, 'vn_b'  , vn_b  (:,:) )   ! from barotropic loop
+      ENDIF
+      !
+   END SUBROUTINE ts_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart free surface cst volume
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_ts( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_ts: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_ts
+   SUBROUTINE ts_rst( kt, cdrw )     ! Empty routine
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      WRITE(*,*) 'ts_rst    : You should not have seen this print! error?', kt, cdrw
+   END SUBROUTINE ts_rst    
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_ts
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynspg_ts_jki.F90	(revision 4536)
@@ -0,0 +1,514 @@
+MODULE dynspg_ts_jki
+   !!======================================================================
+   !!                   ***  MODULE  dynspg_ts_jki  ***
+   !! Ocean dynamics:  surface pressure gradient trend
+   !!======================================================================
+#if defined key_dynspg_ts   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_dynspg_ts'                    free surface with time splitting
+   !!----------------------------------------------------------------------
+   !!   dyn_spg_ts  : compute surface pressure gradient trend using a time-
+   !!                 splitting scheme and add to the general trend 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition
+   USE obcdta          ! open boundary condition data     
+   USE obcfla          ! Flather open boundary condition  
+   USE dynvor          ! vorticity term
+   USE obc_oce         ! Lateral open boundary condition
+   USE obc_par         ! open boundary condition parameters
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE dynspg_ts       ! surface pressure gradient
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O library
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_ts_jki  ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LODYC-IPSL  (2005)
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_ts_jki( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine dyn_spg_ts_jki  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the surface pressure
+      !!      gradient in case of free surface formulation with time-splitting.
+      !!      Add it to the general trend of momentum equation.
+      !!      Compute the free surface.
+      !!
+      !! ** Method  :   Free surface formulation with time-splitting
+      !!      -1- Save the vertically integrated trend. This general trend is
+      !!          held constant over the barotropic integration.
+      !!          The Coriolis force is removed from the general trend as the
+      !!          surface gradient and the Coriolis force are updated within
+      !!          the barotropic integration.
+      !!      -2- Barotropic loop : updates of sea surface height (ssha_e) and 
+      !!          barotropic transports (ua_e and va_e) through barotropic 
+      !!          momentum and continuity integration. Barotropic former 
+      !!          variables are time averaging over the full barotropic cycle
+      !!          (= 2 * baroclinic time step) and saved in zsshX_b, zuX_b 
+      !!          and zvX_b (X specifying after, now or before).
+      !!      -3- Update of sea surface height from time averaged barotropic 
+      !!          variables.
+      !!        - apply lateral boundary conditions on sshn.
+      !!      -4- The new general trend becomes :
+      !!          ua = ua - sum_k(ua)/H + ( zua_b - sum_k(ub) )/H
+      !!
+      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !!
+      !! References :
+      !!   Griffies et al., (2003): A technical guide to MOM4. NOAA/GFDL
+      !!
+      !! History :
+      !!   9.0  !  04-12  (L. Bessieres, G. Madec)  Original code
+      !!        !  05-11  (V. Garnier, G. Madec)  optimization
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in )  ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk, jit             ! dummy loop indices
+      INTEGER  ::  icycle                      ! temporary scalar
+      REAL(wp) ::                           &
+         zraur, zcoef, z2dt_e, z2dt_b, zfac25,   &  ! temporary scalars
+         zfact1, zspgu, zcubt, zx1, zy1,    &  !     "        "
+         zfact2, zspgv, zcvbt, zx2, zy2        !     "        "
+      REAL(wp), DIMENSION(jpi,jpj) ::       &
+         zcu, zcv, zwx, zwy, zhdiv,         &  ! temporary arrays
+         zua, zva, zub, zvb,                &  !     "        "
+         zssha_b, zua_b, zva_b,             &  !     "        "
+         zsshb_e, zub_e, zvb_e,             &  !     "        "
+         zun_e, zvn_e                          !     "        "
+      REAL(wp), DIMENSION(jpi,jpj),SAVE ::  &
+         ztnw, ztne, ztsw, ztse
+      !!----------------------------------------------------------------------
+
+      ! Arrays initialization
+      ! ---------------------
+      zua_b(:,:) = 0.e0   ;   zub_e(:,:) = 0.e0   ;   zun_e(:,:) = 0.e0
+      zva_b(:,:) = 0.e0   ;   zvb_e(:,:) = 0.e0   ;   zvn_e(:,:) = 0.e0
+      zhdiv(:,:) = 0.e0
+
+      IF( kt == nit000 ) THEN
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_spg_ts_jki : surface pressure gradient trend'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   free surface with time splitting with j-k-i loop'
+         IF(lwp) WRITE(numout,*) ' Number of sub cycle in 1 time-step (2 rdt) : icycle = ', FLOOR( 2*rdt/rdtbt )
+
+         CALL ts_rst( nit000, 'READ' )   ! read or initialize the following fields:
+         !                               ! sshb, sshn, sshb_b, sshn_b, un_b, vn_b
+
+         ssha_e(:,:) = sshn(:,:)
+         ua_e  (:,:) = un_b(:,:)
+         va_e  (:,:) = vn_b(:,:)
+
+         IF( ln_dynvor_een ) THEN
+            ztne(1,:) = 0.e0   ;   ztnw(1,:) = 0.e0   ;   ztse(1,:) = 0.e0   ;   ztsw(1,:) = 0.e0
+            DO jj = 2, jpj
+               DO ji = 2, jpi
+                  ztne(ji,jj) = ( ff(ji-1,jj  ) + ff(ji  ,jj  ) + ff(ji  ,jj-1) ) / 3.
+                  ztnw(ji,jj) = ( ff(ji-1,jj-1) + ff(ji-1,jj  ) + ff(ji  ,jj  ) ) / 3.
+                  ztse(ji,jj) = ( ff(ji  ,jj  ) + ff(ji  ,jj-1) + ff(ji-1,jj-1) ) / 3.
+                  ztsw(ji,jj) = ( ff(ji  ,jj-1) + ff(ji-1,jj-1) + ff(ji-1,jj  ) ) / 3.
+               END DO
+            END DO
+         ENDIF
+
+      ENDIF
+    
+      ! Local constant initialization
+      ! --------------------------------
+      z2dt_b = 2.0 * rdt                                    ! baroclinic time step
+      IF ( neuler == 0 .AND. kt == nit000 ) z2dt_b = rdt
+      zfact1 = 0.5 * 0.25                                   ! coefficient for vorticity estimates
+      zfact2 = 0.5 * 0.5
+      zraur  = 1. / rauw                                    ! 1 / volumic mass of pure water
+      
+      ! -----------------------------------------------------------------------------
+      !  Phase 1 : Coupling between general trend and barotropic estimates (1st step)
+      ! -----------------------------------------------------------------------------
+
+      DO jj = 1, jpj
+
+         ! variables for the barotropic equations
+         zsshb_e(:,jj) = sshn_b(:,jj)       ! (barotropic) sea surface height (before and now)
+         sshn_e (:,jj) = sshn_b(:,jj)
+         zub_e  (:,jj) = un_b  (:,jj)       ! barotropic transports issued from the barotropic equations (before and now)
+         zvb_e  (:,jj) = vn_b  (:,jj)
+         zun_e  (:,jj) = un_b  (:,jj)
+         zvn_e  (:,jj) = vn_b  (:,jj)
+         zssha_b(:,jj) = sshn  (:,jj)        ! time averaged variables over all sub-timesteps
+         zua_b  (:,jj) = un_b  (:,jj)   
+         zva_b  (:,jj) = vn_b  (:,jj)
+
+         ! Vertically integrated quantities
+         ! --------------------------------
+         zua(:,jj) = 0.e0
+         zva(:,jj) = 0.e0
+         zub(:,jj) = 0.e0
+         zvb(:,jj) = 0.e0
+         zwx(:,jj) = 0.e0
+         zwy(:,jj) = 0.e0
+
+         ! vertical sum
+         DO jk = 1, jpkm1
+            !                                                           ! Vertically integrated momentum trends
+            zua(:,jj) = zua(:,jj) + fse3u(:,jj,jk) * umask(:,jj,jk) * ua(:,jj,jk)
+            zva(:,jj) = zva(:,jj) + fse3v(:,jj,jk) * vmask(:,jj,jk) * va(:,jj,jk)
+            !                                                           ! Vertically integrated transports (before)
+            zub(:,jj) = zub(:,jj) + fse3u(:,jj,jk) * ub(:,jj,jk)
+            zvb(:,jj) = zvb(:,jj) + fse3v(:,jj,jk) * vb(:,jj,jk)
+            !                                                           ! Planetary vorticity (now)
+            zwx(:,jj) = zwx(:,jj) + e2u(:,jj) * fse3u(:,jj,jk) * un(:,jj,jk)
+            zwy(:,jj) = zwy(:,jj) + e1v(:,jj) * fse3v(:,jj,jk) * vn(:,jj,jk)
+         END DO
+
+      END DO
+
+      DO jj = 2, jpjm1
+
+         IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
+            DO ji = 2, jpim1
+               zy1 = ( zwy(ji,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
+               zy2 = ( zwy(ji,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 = ( zwx(ji-1,jj) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
+               zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               ! energy conserving formulation for planetary vorticity term
+               zcu(ji,jj) = zfact2 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 )
+               zcv(ji,jj) =-zfact2 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 )
+            END DO
+
+         ELSEIF ( ln_dynvor_ens ) THEN                    ! enstrophy conserving scheme
+            DO ji = 2, jpim1
+               zy1 = zfact1 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                              + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 =-zfact1 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                              + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               zcu(ji,jj)  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) )
+               zcv(ji,jj)  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) )
+            END DO
+
+         ELSEIF ( ln_dynvor_een ) THEN                    ! enstrophy and energy conserving scheme
+         zfac25 = 0.25
+            DO ji = 2, jpim1
+               zcu(ji,jj) = + zfac25 / e1u(ji,jj)   &
+                  &       * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
+                  &          + ztse(ji,jj  ) * zwy(ji  ,jj-1) + ztsw(ji+1,jj) * zwy(ji+1,jj-1) )
+               zcv(ji,jj) = - zfac25 / e2v(ji,jj)   &
+                  &       * (  ztsw(ji,jj+1) * zwx(ji-1,jj+1) + ztse(ji,jj+1) * zwx(ji  ,jj+1)   &
+                  &          + ztnw(ji,jj  ) * zwx(ji-1,jj  ) + ztne(ji,jj  ) * zwx(ji  ,jj  ) )
+            END DO
+
+         ENDIF
+
+
+         ! Remove barotropic trend from general momentum trend
+         DO jk = 1 , jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ua(ji,jj,jk) - zua(ji,jj) * hur(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) - zva(ji,jj) * hvr(ji,jj)
+            END DO
+         END DO
+
+         ! Remove coriolis term from barotropic trend
+         ! ------------------------------------------
+         DO ji = 2, jpim1
+            zua(ji,jj) = zua(ji,jj) - zcu(ji,jj)
+            zva(ji,jj) = zva(ji,jj) - zcv(ji,jj)
+         END DO
+
+      END DO
+
+      ! -----------------------------------------------------------------------
+      !  Phase 2 : Integration of the barotropic equations with time splitting
+      ! -----------------------------------------------------------------------
+
+      ! Initialisations
+      !----------------
+      ! Number of iteration of the barotropic loop
+      icycle = FLOOR( z2dt_b / rdtbt )
+
+      ! set ssh corrections to 0
+      ! ssh corrections are applied to normal velocities (Flather's algorithm) and averaged over the barotropic loop
+#if defined key_obc
+      IF( lp_obc_east  )   sshfoe_b(:,:) = 0.e0
+      IF( lp_obc_west  )   sshfow_b(:,:) = 0.e0
+      IF( lp_obc_south )   sshfos_b(:,:) = 0.e0
+      IF( lp_obc_north )   sshfon_b(:,:) = 0.e0
+#endif
+
+      ! Barotropic integration over 2 baroclinic time steps
+      ! ---------------------------------------------------
+
+      !                                                    ! ==================== !
+      DO jit = 1, icycle                                   !  sub-time-step loop  !
+         !                                                 ! ==================== !
+
+         z2dt_e = 2. * rdtbt
+         IF ( jit == 1 )   z2dt_e = rdtbt
+
+         ! Time interpolation of open boundary condition data
+         IF( lk_obc )   CALL obc_dta_bt( kt, jit )
+
+         DO jj = 2, jpjm1
+
+         ! Horizontal divergence of barotropic transports
+         !--------------------------------------------------
+            DO ji = 2, jpim1
+               zhdiv(ji,jj) = ( e2u(ji  ,jj  ) * zun_e(ji  ,jj)              &
+                  &            -e2u(ji-1,jj  ) * zun_e(ji-1,jj)              &
+                  &            +e1v(ji  ,jj  ) * zvn_e(ji  ,jj)              &
+                  &            -e1v(ji  ,jj-1) * zvn_e(ji  ,jj-1) )          &
+                  &           / (e1t(ji,jj)*e2t(ji,jj))
+            END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of zhdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  ) THEN
+            IF( nje0   <= jj .AND. jj <= nje1   )   zhdiv(nie0p1:nie1p1,jj) = 0.e0      ! east
+         ENDIF
+         IF( lp_obc_west  ) THEN
+            IF( njw0   <= jj .AND. jj <= njw1   )   zhdiv(niw0  :niw1  ,jj) = 0.e0      ! west
+         ENDIF
+         IF( lp_obc_north ) THEN
+            IF( njn0p1 <= jj .AND. jj <= njn1p1 )   zhdiv(nin0  :nin1  ,jj) = 0.e0      ! north
+         ENDIF
+         IF( lp_obc_south ) THEN
+            IF( njs0   <= jj .AND. jj <= njs1   )   zhdiv(nis0  :nis1  ,jj) = 0.e0      ! south
+         ENDIF
+#endif
+
+         ! Sea surface height from the barotropic system
+         !----------------------------------------------
+            DO ji = 2, jpim1
+               ssha_e(ji,jj) = ( zsshb_e(ji,jj) - z2dt_e *  ( zraur * emp(ji,jj)  &
+                  &            +  zhdiv(ji,jj) ) ) * tmask(ji,jj,1)
+            END DO
+
+         END DO
+
+         ! evolution of the barotropic transport ( following the vorticity scheme used)
+         ! ----------------------------------------------------------------------------
+         zwx(:,:) = e2u(:,:) * zun_e(:,:)
+         zwy(:,:) = e1v(:,:) * zvn_e(:,:)
+
+         DO jj = 2, jpjm1
+
+            IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
+               DO ji = 2, jpim1
+                  ! surface pressure gradient
+                  zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                  zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ! energy conserving formulation for planetary vorticity term
+                  zy1 = ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
+                  zy2 = ( zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+                  zx1 = ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
+                  zx2 = ( zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+                  zcubt = zfact2 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 )
+                  zcvbt =-zfact2 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+
+            ELSEIF ( ln_dynvor_ens ) THEN                    ! enstrophy conserving scheme
+               DO ji = 2, jpim1
+                  ! surface pressure gradient
+                  zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                  zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ! enstrophy conserving formulation for planetary vorticity term
+                  zy1 = zfact1 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                                 + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+                  zx1 =-zfact1 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                                 + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+                  zcubt  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) )
+                  zcvbt  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+
+            ELSEIF ( ln_dynvor_een ) THEN                    ! energy and enstrophy conserving scheme
+               zfac25 = 0.25
+               DO ji = 2, jpim1
+                  ! surface pressure gradient
+                  zspgu = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) * hu(ji,jj) / e1u(ji,jj)
+                  zspgv = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) * hv(ji,jj) / e2v(ji,jj)
+                  ! energy/enstrophy conserving formulation for planetary vorticity term
+                  zcubt = + zfac25 / e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
+                     &                             + ztse(ji,jj  ) * zwy(ji  ,jj-1) + ztsw(ji+1,jj) * zwy(ji+1,jj-1) )
+                  zcvbt = - zfac25 / e2v(ji,jj) * (  ztsw(ji,jj+1) * zwx(ji-1,jj+1) + ztse(ji,jj+1) * zwx(ji  ,jj+1)   &
+                     &                             + ztnw(ji,jj  ) * zwx(ji-1,jj  ) + ztne(ji,jj  ) * zwx(ji  ,jj  ) )
+                  ! after transports
+                  ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zcubt + zspgu + zua(ji,jj) ) ) * umask(ji,jj,1)
+                  va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zcvbt + zspgv + zva(ji,jj) ) ) * vmask(ji,jj,1)
+               END DO
+            ENDIF
+
+         END DO
+
+
+         ! Flather's boundary condition for the barotropic loop :
+         !         - Update sea surface height on each open boundary
+         !         - Correct the barotropic transports
+         IF( lk_obc )   CALL obc_fla_ts
+
+         ! ... Boundary conditions on ua_e, va_e, ssha_e
+         CALL lbc_lnk( ua_e  , 'U', -1. )
+         CALL lbc_lnk( va_e  , 'V', -1. )
+         CALL lbc_lnk( ssha_e, 'T',  1. )
+
+         DO jj = 1, jpj
+
+            ! temporal sum
+            !-------------
+            zssha_b(:,jj) = zssha_b(:,jj) + ssha_e(:,jj)
+            zua_b  (:,jj) = zua_b  (:,jj) + ua_e  (:,jj)
+            zva_b  (:,jj) = zva_b  (:,jj) + va_e  (:,jj) 
+
+            ! Time filter and swap of dynamics arrays
+            ! ---------------------------------------
+            IF( neuler == 0 .AND. jit == 1 ) THEN       ! Euler (forward) time stepping
+               zsshb_e(:,jj) = sshn_e(:,jj)
+               zub_e  (:,jj) = zun_e (:,jj)
+               zvb_e  (:,jj) = zvn_e (:,jj)
+               sshn_e (:,jj) = ssha_e(:,jj)
+               zun_e  (:,jj) = ua_e  (:,jj)
+               zvn_e  (:,jj) = va_e  (:,jj)
+            ELSE                                        ! Asselin filtering
+               zsshb_e(:,jj) = atfp * ( zsshb_e(:,jj) + ssha_e(:,jj) ) + atfp1 * sshn_e (:,jj)
+               zub_e  (:,jj) = atfp * ( zub_e  (:,jj) + ua_e  (:,jj) ) + atfp1 * zun_e  (:,jj)
+               zvb_e  (:,jj) = atfp * ( zvb_e  (:,jj) + va_e  (:,jj) ) + atfp1 * zvn_e  (:,jj)
+               sshn_e (:,jj) = ssha_e(:,jj)
+               zun_e  (:,jj) = ua_e  (:,jj)
+               zvn_e  (:,jj) = va_e  (:,jj)
+            ENDIF
+
+         END DO
+
+         !                                                 ! ==================== !
+      END DO                                               !        end loop      !
+      !                                                    ! ==================== !
+
+
+      ! Time average of after barotropic variables
+      zcoef =  1.e0 / (  FLOAT( icycle +1 )  )
+      zssha_b(:,:) = zcoef * zssha_b(:,:) 
+      zua_b  (:,:) = zcoef * zua_b  (:,:) 
+      zva_b  (:,:) = zcoef * zva_b  (:,:) 
+#if defined key_obc
+         IF( lp_obc_east  )   sshfoe_b(:,:) = zcoef * sshfoe_b(:,:)
+         IF( lp_obc_west  )   sshfow_b(:,:) = zcoef * sshfow_b(:,:)
+         IF( lp_obc_north )   sshfon_b(:,:) = zcoef * sshfon_b(:,:)
+         IF( lp_obc_south )   sshfos_b(:,:) = zcoef * sshfos_b(:,:)
+#endif
+     
+
+      ! ---------------------------------------------------------------------------
+      ! Phase 3 : Update sea surface height from time averaged barotropic variables
+      ! ---------------------------------------------------------------------------
+
+      sshb(:,:) = sshn(:,:)
+ 
+      ! Horizontal divergence of time averaged barotropic transports
+      !-------------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zhdiv(ji,jj) = ( e2u(ji,jj) * un_b(ji,jj) - e2u(ji-1,jj  ) * un_b(ji-1,jj  )     &
+           &                +e1v(ji,jj) * vn_b(ji,jj) - e1v(ji  ,jj-1) * vn_b(ji  ,jj-1) )   &
+           &             / ( e1t(ji,jj) * e2t(ji,jj) )
+         END DO
+
+#if defined key_obc
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of zhdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  ) THEN
+            IF( nje0   <= jj .AND. jj <= nje1   )   zhdiv(nie0p1:nie1p1,jj) = 0.e0      ! east
+         ENDIF
+         IF( lp_obc_west  ) THEN
+            IF( njw0   <= jj .AND. jj <= njw1   )   zhdiv(niw0  :niw1  ,jj) = 0.e0      ! west
+         ENDIF
+         IF( lp_obc_north ) THEN
+            IF( njn0p1 <= jj .AND. jj <= njn1p1 )   zhdiv(nin0  :nin1  ,jj) = 0.e0      ! north
+         ENDIF
+         IF( lp_obc_south ) THEN
+            IF( njs0   <= jj .AND. jj <= njs1   )   zhdiv(nis0  :nis1  ,jj) = 0.e0      ! south
+         ENDIF
+#endif
+
+         ! sea surface height
+         !-------------------
+         DO ji = 2, jpim1
+            sshn(ji,jj) = (  sshb_b(ji,jj) - z2dt_b * ( zraur * emp(ji,jj) + zhdiv(ji,jj) )  ) * tmask(ji,jj,1)
+         END DO
+
+      END DO
+
+      ! ... Boundary conditions on sshn
+      IF( .NOT. lk_obc ) CALL lbc_lnk( sshn, 'T', 1. )
+
+
+      ! -----------------------------------------------------------------------------
+      ! Phase 4. Coupling between general trend and barotropic estimates - (2nd step)
+      ! -----------------------------------------------------------------------------
+
+      DO jj = 1, jpj
+
+         ! Swap on time averaged barotropic variables
+         ! ------------------------------------------
+         sshb_b(:,jj) = sshn_b (:,jj)
+         sshn_b(:,jj) = zssha_b(:,jj)
+         un_b  (:,jj) = zua_b  (:,jj) 
+         vn_b  (:,jj) = zva_b  (:,jj) 
+   
+         ! add time averaged barotropic coriolis and surface pressure gradient
+         ! terms to the general momentum trend
+         ! --------------------------------------------------------------------
+         DO jk = 1, jpkm1
+            ua(:,jj,jk) = ua(:,jj,jk) + hur(:,jj) * ( zua_b(:,jj) - zub(:,jj) ) / z2dt_b
+            va(:,jj,jk) = va(:,jj,jk) + hvr(:,jj) * ( zva_b(:,jj) - zvb(:,jj) ) / z2dt_b
+         END DO
+      END DO
+
+      ! write filtered free surface arrays in restart file
+      ! --------------------------------------------------
+      IF( lrst_oce )   CALL ts_rst( kt, 'WRITE' )
+
+      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
+         CALL prt_ctl(tab2d_1=sshn, clinfo1=' ssh      : ', mask1=tmask)
+      ENDIF
+      
+   END SUBROUTINE dyn_spg_ts_jki
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :   Empty module   No standart free surface cst volume
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dyn_spg_ts_jki( kt )       ! Empty routine
+      WRITE(*,*) 'dyn_spg_ts_jki: You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_ts_jki
+#endif
+   
+   !!======================================================================
+END MODULE dynspg_ts_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4536)
@@ -0,0 +1,703 @@
+MODULE dynvor
+   !!======================================================================
+   !!                       ***  MODULE  dynvor  ***
+   !! Ocean dynamics: Update the momentum trend with the relative and
+   !!                 planetary vorticity trends
+   !!======================================================================
+   !! History :  1.0  !  89-12  (P. Andrich)  vor_ens: Original code
+   !!            5.0  !  91-11  (G. Madec) vor_ene, vor_mix: Original code
+   !!            6.0  !  96-01  (G. Madec)  s-coord, suppress work arrays
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!            8.5  !  04-02  (G. Madec)  vor_een: Original code
+   !!            9.0  !  03-08  (G. Madec)  vor_ctl: Original code
+   !!            9.0  !  05-11  (G. Madec)  dyn_vor: Original code (new step architecture)
+   !!            9.0  !  06-11  (G. Madec)  flux form advection: add metric term
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_vor     : Update the momentum trend with the vorticity trend
+   !!       vor_ens : enstrophy conserving scheme       (ln_dynvor_ens=T)
+   !!       vor_ene : energy conserving scheme          (ln_dynvor_ene=T)
+   !!       vor_mix : mixed enstrophy/energy conserving (ln_dynvor_mix=T)
+   !!       vor_een : energy and enstrophy conserving   (ln_dynvor_een=T)
+   !!       vor_ctl : set and control of the different vorticity option
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE dynadv         ! momentum advection (use ln_dynadv_vec value)
+   USE trdmod         ! ocean dynamics trends 
+   USE trdmod_oce     ! ocean variables trends
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_vor   ! routine called by step.F90
+
+   !!* Namelist nam_dynvor: vorticity term
+   LOGICAL, PUBLIC ::   ln_dynvor_ene = .FALSE.   !: energy conserving scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_ens = .TRUE.    !: enstrophy conserving scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_mix = .FALSE.   !: mixed scheme
+   LOGICAL, PUBLIC ::   ln_dynvor_een = .FALSE.   !: energy and enstrophy conserving scheme
+
+   INTEGER ::   nvor = 0   ! type of vorticity trend used
+   INTEGER ::   ncor = 1   ! coriolis
+   INTEGER ::   nrvm = 2   ! =2 relative vorticity ; =3 metric term
+   INTEGER ::   ntot = 4   ! =4 total vorticity (relative + planetary) ; =5 coriolis + metric term
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_vor( kt )
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose :   compute the lateral ocean tracer physics.
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdu => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   ztrdv => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL vor_ctl          ! initialisation & control of options
+
+      !                                          ! vorticity term 
+      SELECT CASE ( nvor )                       ! compute the vorticity trend and add it to the general trend
+      !
+      CASE ( -1 )                                      ! esopa: test all possibility with control print
+         CALL vor_ene( kt, ntot, ua, va )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor0 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL vor_ens( kt, ntot, ua, va )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor1 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL vor_mix( kt )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor2 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL vor_een( kt, ntot, ua, va )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor3 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         !
+      CASE ( 0 )                                       ! energy conserving scheme
+         IF( l_trddyn )   THEN
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ene( kt, nrvm, ua, va )                ! relative vorticity or metric trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ene( kt, ncor, ua, va )                ! planetary vorticity trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+         ELSE
+            CALL vor_ene( kt, ntot, ua, va )                ! total vorticity
+         ENDIF
+         !
+      CASE ( 1 )                                       ! enstrophy conserving scheme
+         IF( l_trddyn )   THEN    
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ens( kt, nrvm, ua, va )                ! relative vorticity or metric trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ens( kt, ncor, ua, va )                ! planetary vorticity trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+         ELSE
+            CALL vor_ens( kt, ntot, ua, va )                ! total vorticity
+         ENDIF
+         !
+      CASE ( 2 )                                       ! mixed ene-ens scheme
+         IF( l_trddyn )   THEN
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ens( kt, nrvm, ua, va )                ! relative vorticity or metric trend (ens)
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_ene( kt, ncor, ua, va )                ! planetary vorticity trend (ene)
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+         ELSE
+            CALL vor_mix( kt )                               ! total vorticity (mix=ens-ene)
+         ENDIF
+         !
+      CASE ( 3 )                                       ! energy and enstrophy conserving scheme
+         IF( l_trddyn )   THEN
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_een( kt, nrvm, ua, va )                ! relative vorticity or metric trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+            CALL vor_een( kt, ncor, ua, va )                ! planetary vorticity trend
+            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+         ELSE
+            CALL vor_een( kt, ntot, ua, va )                ! total vorticity
+         ENDIF
+         !
+      END SELECT
+
+      !                       ! print sum trends (used for debugging)
+      IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' vor  - Ua: ', mask1=umask, &
+         &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+
+   END SUBROUTINE dyn_vor
+
+
+   SUBROUTINE vor_ene( kt, kvor, pua, pva )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE vor_ene  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!      and the Sadourny (1975) flux form formulation : conserves the
+      !!      horizontal kinetic energy.
+      !!      The trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)/e3f  mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)/e3f  mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)  mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)  mj(e2u un) ]
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua    ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva    ! total v-trend
+      !!
+      INTEGER  ::   ji, jj, jk         ! dummy loop indices
+      REAL(wp) ::   zx1, zy1, zfact2   ! temporary scalars
+      REAL(wp) ::   zx2, zy2           !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! temporary 2D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_ene : vorticity term: energy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact2 = 0.5 * 0.5
+
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz )
+!$OMP PARALLEL DO PRIVATE( zwx, zwy, zwz )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwz(:,:) =                  ff(:,:)      ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwz(:,:) =   rotn(:,:,jk)                ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) )    ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                                                                       &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       )
+               END DO
+            END DO
+         END SELECT
+
+         IF( ln_sco ) THEN
+            zwz(:,:) = zwz(:,:) / fse3f(:,:,jk)
+            zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         ELSE
+            zwx(:,:) = e2u(:,:) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * vn(:,:,jk)
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = zwy(ji,jj-1) + zwy(ji+1,jj-1)
+               zy2 = zwy(ji,jj  ) + zwy(ji+1,jj  )
+               zx1 = zwx(ji-1,jj) + zwx(ji-1,jj+1)
+               zx2 = zwx(ji  ,jj) + zwx(ji  ,jj+1)
+               pua(ji,jj,jk) = pua(ji,jj,jk) + zfact2 / e1u(ji,jj) * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+               pva(ji,jj,jk) = pva(ji,jj,jk) - zfact2 / e2v(ji,jj) * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 ) 
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_ene
+
+
+   SUBROUTINE vor_mix( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE vor_mix  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time)
+      !!      Mixte formulation : conserves the potential enstrophy of a hori-
+      !!      zontally non-divergent flow for (rotzu x uh), the relative vor-
+      !!      ticity term and the horizontal kinetic energy for (f x uh), the
+      !!      coriolis term. the now trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!          voru = 1/e1u  mj-1(rotn/e3f) mj-1[ mi(e1v*e3v vn) ]
+      !!              +1/e1u  mj-1[ f/e3f          mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1(rotn/e3f) mi-1[ mj(e2u*e3u un) ]
+      !!              +1/e2v  mi-1[ f/e3f          mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1(rotn) mj-1[ mi(e1v vn) ]
+      !!              +1/e1u  mj-1[ f          mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1(rotn) mi-1[ mj(e2u un) ]
+      !!              +1/e2v  mi-1[ f          mj(e2u un) ]
+      !!      Add this now trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
+      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean timestep index
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zfact1, zua, zcua, zx1, zy1   ! temporary scalars
+      REAL(wp) ::   zfact2, zva, zcva, zx2, zy2   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz, zww   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_mix : vorticity term: mixed energy/enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact1 = 0.5 * 0.25
+      zfact2 = 0.5 * 0.5
+
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz, zww )
+!$OMP PARALLEL DO PRIVATE( zwx, zwy, zwz, zww )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! Relative and planetary potential vorticity and horizontal fluxes
+         ! ----------------------------------------------------------------
+         IF( ln_sco ) THEN        
+            IF( ln_dynadv_vec ) THEN
+               zww(:,:) = rotn(:,:,jk) / fse3f(:,:,jk)
+            ELSE                       
+               DO jj = 1, jpjm1
+                  DO ji = 1, fs_jpim1   ! vector opt.
+                     zww(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                        &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                        &       * 0.5 / ( e1f(ji,jj) * e2f (ji,jj) * fse3f(ji,jj,jk) )
+                  END DO
+               END DO
+            ENDIF
+            zwz(:,:) = ff  (:,:)    / fse3f(:,:,jk)
+            zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         ELSE
+            IF( ln_dynadv_vec ) THEN
+               zww(:,:) = rotn(:,:,jk)
+            ELSE                       
+               DO jj = 1, jpjm1
+                  DO ji = 1, fs_jpim1   ! vector opt.
+                     zww(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                        &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                        &       * 0.5 / ( e1f(ji,jj) * e2f (ji,jj) )
+                  END DO
+               END DO
+            ENDIF
+            zwz(:,:) = ff (:,:)
+            zwx(:,:) = e2u(:,:) * un(:,:,jk)
+            zwy(:,:) = e1v(:,:) * vn(:,:,jk)
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zy1 = ( zwy(ji,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
+               zy2 = ( zwy(ji,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 = ( zwx(ji-1,jj) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
+               zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               ! enstrophy conserving formulation for relative vorticity term
+               zua = zfact1 * ( zww(ji  ,jj-1) + zww(ji,jj) ) * ( zy1 + zy2 )
+               zva =-zfact1 * ( zww(ji-1,jj  ) + zww(ji,jj) ) * ( zx1 + zx2 )
+               ! energy conserving formulation for planetary vorticity term
+               zcua = zfact2 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+               zcva =-zfact2 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
+               ! mixed vorticity trend added to the momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zcua + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zcva + zva
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_mix
+
+
+   SUBROUTINE vor_ens( kt, kvor, pua, pva )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_ens  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time)
+      !!      and the Sadourny (1975) flux FORM formulation : conserves the
+      !!      potential enstrophy of a horizontally non-divergent flow. the
+      !!      trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivative:
+      !!          voru = 1/e1u  mj-1[ (rotn+f)/e3f ]  mj-1[ mi(e1v*e3v vn) ]
+      !!          vorv = 1/e2v  mi-1[ (rotn+f)/e3f ]  mi-1[ mj(e2u*e3u un) ]
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          voru = 1/e1u  mj-1[ rotn+f ]  mj-1[ mi(e1v vn) ]
+      !!          vorv = 1/e2v  mi-1[ rotn+f ]  mi-1[ mj(e2u un) ]
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
+      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative 
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua    ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva    ! total v-trend
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zfact1, zuav, zvau   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_ens : vorticity term: enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! Local constant initialization
+      zfact1 = 0.5 * 0.25
+
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz )
+!$OMP PARALLEL DO PRIVATE( zwx, zwy, zwz )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwz(:,:) =                  ff(:,:)      ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwz(:,:) =   rotn(:,:,jk)                ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) )    ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                                                                       &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       )
+               END DO
+            END DO
+         END SELECT
+
+         IF( ln_sco ) THEN
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwz(ji,jj) = zwz(ji,jj) / fse3f(ji,jj,jk)
+                  zwx(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj                      ! caution: don't use (:,:) for this loop 
+               DO ji = 1, jpi                   ! it causes optimization problems on NEC in auto-tasking
+                  zwx(ji,jj) = e2u(ji,jj) * un(ji,jj,jk)
+                  zwy(ji,jj) = e1v(ji,jj) * vn(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zuav = zfact1 / e1u(ji,jj) * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
+                  &                         + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
+               zvau =-zfact1 / e2v(ji,jj) * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
+                  &                         + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
+               pua(ji,jj,jk) = pua(ji,jj,jk) + zuav * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
+               pva(ji,jj,jk) = pva(ji,jj,jk) + zvau * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_ens
+
+
+   SUBROUTINE vor_een( kt, kvor, pua, pva )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE vor_een  ***
+      !!
+      !! ** Purpose :   Compute the now total vorticity trend and add it to 
+      !!      the general trend of the momentum equation.
+      !!
+      !! ** Method  :   Trend evaluated using now fields (centered in time) 
+      !!      and the Arakawa and Lamb (19XX) flux form formulation : conserves 
+      !!      both the horizontal kinetic energy and the potential enstrophy
+      !!      when horizontal divergence is zero.
+      !!      The trend of the vorticity term is given by:
+      !!       * s-coordinate (ln_sco=T), the e3. are inside the derivatives:
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!      Add this trend to the general momentum trend (ua,va):
+      !!          (ua,va) = (ua,va) + ( voru , vorv )
+      !!
+      !! ** Action : - Update (ua,va) with the now vorticity term trend
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
+      !!               and planetary vorticity trends) ('key_trddyn')
+      !!
+      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      INTEGER , INTENT(in   )                         ::   kvor   ! =ncor (planetary) ; =ntot (total) ;
+         !                                                        ! =nrvm (relative vorticity or metric)
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua    ! total u-trend
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva    ! total v-trend
+      !!
+      INTEGER ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zfac12, zua, zva   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz            ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnw, ztne, ztsw, ztse   ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   ze3f
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn:vor_een : vorticity term: energy and enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  ze3f(ji,jj,jk) = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &             + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) ) * 0.25
+                  IF( ze3f(ji,jj,jk) /= 0.e0 )   ze3f(ji,jj,jk) = 1.e0 / ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( ze3f, 'F', 1. )
+      ENDIF
+
+      ! Local constant initialization
+      zfac12 = 1.e0 / 12.e0
+
+      
+!CDIR PARALLEL DO PRIVATE( zwx, zwy, zwz, ztnw, ztne, ztsw, ztse )
+!$OMP PARALLEL DO PRIVATE( zwx, zwy, zwz, ztnw, ztne, ztsw, ztse )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         
+         ! Potential vorticity and horizontal fluxes
+         ! -----------------------------------------
+         SELECT CASE( kvor )      ! vorticity considered
+         CASE ( 1 )   ;   zwz(:,:) = ff(:,:)      * ze3f(:,:,jk)   ! planetary vorticity (Coriolis)
+         CASE ( 2 )   ;   zwz(:,:) = rotn(:,:,jk) * ze3f(:,:,jk)   ! relative  vorticity
+         CASE ( 3 )                                                ! metric term
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &         - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &     * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         CASE ( 4 )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk) ! total (relative + planetary vorticity)
+         CASE ( 5 )                                                ! total (coriolis + metric)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwz(ji,jj) = ( ff (ji,jj)                                                                       &
+                       &       + (   ( vn(ji+1,jj  ,jk) + vn (ji,jj,jk) ) * ( e2v(ji+1,jj  ) - e2v(ji,jj) )       &
+                       &           - ( un(ji  ,jj+1,jk) + un (ji,jj,jk) ) * ( e1u(ji  ,jj+1) - e1u(ji,jj) )   )   &
+                       &       * 0.5 / ( e1f(ji,jj) * e2f(ji,jj) )                                               &
+                       &       ) * ze3f(ji,jj,jk)
+               END DO
+            END DO
+         END SELECT
+
+         zwx(:,:) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)
+         zwy(:,:) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+
+         ! Compute and add the vorticity term trend
+         ! ----------------------------------------
+         jj=2
+         ztne(1,:) = 0 ; ztnw(1,:) = 0 ; ztse(1,:) = 0 ; ztsw(1,:) = 0
+         DO ji = 2, jpi   
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+         END DO
+         DO jj = 3, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               ztne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+               ztnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+               ztse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+               ztsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zua = + zfac12 / e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
+                  &                           + ztse(ji,jj  ) * zwy(ji  ,jj-1) + ztsw(ji+1,jj) * zwy(ji+1,jj-1) )
+               zva = - zfac12 / e2v(ji,jj) * (  ztsw(ji,jj+1) * zwx(ji-1,jj+1) + ztse(ji,jj+1) * zwx(ji  ,jj+1)   &
+                  &                           + ztnw(ji,jj  ) * zwx(ji-1,jj  ) + ztne(ji,jj  ) * zwx(ji  ,jj  ) )
+               pua(ji,jj,jk) = pua(ji,jj,jk) + zua
+               pva(ji,jj,jk) = pva(ji,jj,jk) + zva
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE vor_een
+
+
+   SUBROUTINE vor_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE vor_ctl  ***
+      !!
+      !! ** Purpose :   Control the consistency between cpp options for
+      !!      tracer advection schemes
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio          ! temporary integer
+      NAMELIST/nam_dynvor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix, ln_dynvor_een
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_dynvor : Vorticity scheme options
+      READ   ( numnam, nam_dynvor )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn:vor_ctl : vorticity term : read namelist and control the consistency'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '        Namelist nam_dynvor : oice of the vorticity term scheme'
+         WRITE(numout,*) '           energy    conserving scheme                ln_dynvor_ene = ', ln_dynvor_ene
+         WRITE(numout,*) '           enstrophy conserving scheme                ln_dynvor_ens = ', ln_dynvor_ens
+         WRITE(numout,*) '           mixed enstrophy/energy conserving scheme   ln_dynvor_mix = ', ln_dynvor_mix
+         WRITE(numout,*) '           enstrophy and energy conserving scheme     ln_dynvor_een = ', ln_dynvor_een
+      ENDIF
+
+      ioptio = 0                     ! Control of vorticity scheme options
+      IF( ln_dynvor_ene )   ioptio = ioptio + 1
+      IF( ln_dynvor_ens )   ioptio = ioptio + 1
+      IF( ln_dynvor_mix )   ioptio = ioptio + 1
+      IF( ln_dynvor_een )   ioptio = ioptio + 1
+      IF( lk_esopa      )   ioptio =          1
+
+      IF( ioptio /= 1 ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
+
+      !                              ! Set nvor (type of scheme for vorticity)
+      IF( ln_dynvor_ene )   nvor =  0
+      IF( ln_dynvor_ens )   nvor =  1
+      IF( ln_dynvor_mix )   nvor =  2
+      IF( ln_dynvor_een )   nvor =  3
+      IF( lk_esopa      )   nvor = -1
+      
+      !                              ! Set ncor, nrvm, ntot (type of vorticity)
+      IF(lwp) WRITE(numout,*)
+      ncor = 1
+      IF( ln_dynadv_vec ) THEN     
+         IF(lwp) WRITE(numout,*) '         Vector form advection : vorticity = Coriolis + relative vorticity'
+         nrvm = 2
+         ntot = 4
+      ELSE                        
+         IF(lwp) WRITE(numout,*) '         Flux form advection   : vorticity = Coriolis + metric term'
+         nrvm = 3
+         ntot = 5
+      ENDIF
+      
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nvor ==  0 )   WRITE(numout,*) '         vorticity scheme : energy conserving scheme'
+         IF( nvor ==  1 )   WRITE(numout,*) '         vorticity scheme : enstrophy conserving scheme'
+         IF( nvor ==  2 )   WRITE(numout,*) '         vorticity scheme : mixed enstrophy/energy conserving scheme'
+         IF( nvor ==  3 )   WRITE(numout,*) '         vorticity scheme : energy and enstrophy conserving scheme'
+         IF( nvor == -1 )   WRITE(numout,*) '         esopa test: use all lateral physics options'
+      ENDIF
+      !
+   END SUBROUTINE vor_ctl
+
+   !!==============================================================================
+END MODULE dynvor
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 4536)
@@ -0,0 +1,220 @@
+MODULE dynzad
+   !!======================================================================
+   !!                       ***  MODULE  dynzad  ***
+   !! Ocean dynamics : vertical advection trend
+   !!======================================================================
+   !! History :  6.0  !  91-01  (G. Madec) Original code
+   !!            7.0  !  91-11  (G. Madec)
+   !!            7.5  !  96-01  (G. Madec) statement function for e3
+   !!            8.5  !  02-07  (G. Madec) j-k-i case: Original code
+   !!            8.5  !  02-07  (G. Madec) Free form, F90
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   dyn_zad       : vertical advection momentum trend
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE in_out_manager ! I/O manager
+   USE trdmod         ! ocean dynamics trends 
+   USE trdmod_oce     ! ocean variables trends
+   USE flxrnf         ! ocean runoffs
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   dyn_zad   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp'        OpenMP / NEC autotasking: j-k-i loops (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dyn_zad( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dynzad  ***
+      !!
+      !! ** Purpose :   Compute the now vertical momentum advection trend and 
+      !!      add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   Use j-slab (j-k-i loops) for OpenMP / NEC autotasking
+      !!      The now vertical advection of momentum is given by:
+      !!         w dz(u) = ua + 1/(e1u*e2u*e3u) mk+1[ mi(e1t*e2t*wn) dk(un) ]
+      !!         w dz(v) = va + 1/(e1v*e2v*e3v) mk+1[ mj(e1t*e2t*wn) dk(vn) ]
+      !!      Add this trend to the general trend (ua,va):
+      !!         (ua,va) = (ua,va) + w dz(u,v)
+      !!
+      !! ** Action  : - Update (ua,va) with the vert. momentum advection trends
+      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY:   zwuw => ta   ! use ta as 3D workspace
+      USE oce, ONLY:   zwvw => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zvn, zua, zva   ! temporary scalars
+      REAL(wp), DIMENSION(jpi)         ::   zww            ! 1D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zad : arakawa advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   Auto-tasking case, j-slab, no vector opt.'
+      ENDIF
+
+      IF( l_trddyn )   THEN         ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
+      ENDIF
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         DO jk = 2, jpkm1         ! Vertical momentum advection at uw and vw-pts
+            DO ji = 2, jpi              ! vertical fluxes 
+               zww(ji) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(ji,jj,jk)
+            END DO
+            DO ji = 2, jpim1            ! vertical momentum advection at w-point
+               zvn = 0.25 * e1t(ji,jj+1) * e2t(ji,jj+1) * wn(ji,jj+1,jk)
+               zwuw(ji,jj,jk) = ( zww(ji+1) + zww(ji) ) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
+               zwvw(ji,jj,jk) = ( zvn       + zww(ji) ) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
+            END DO  
+         END DO   
+         DO ji = 2, jpim1               ! Surface and bottom values set to zero
+            zwuw(ji,jj, 1 ) = 0.e0
+            zwvw(ji,jj, 1 ) = 0.e0
+            zwuw(ji,jj,jpk) = 0.e0
+            zwvw(ji,jj,jpk) = 0.e0
+         END DO  
+         !
+         DO jk = 1, jpkm1         ! Vertical momentum advection at u- and v-points
+            DO ji = 2, jpim1
+               !                        ! vertical momentum advective trends
+               zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               !                        ! add the trends to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO  
+         END DO  
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      !
+      IF( l_trddyn ) THEN         ! save the vertical advection trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt )
+      ENDIF
+      !                           ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_zad
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                             k-j-i loop (vector opt.)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE dyn_zad ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dynzad  ***
+      !! 
+      !! ** Purpose :   Compute the now vertical momentum advection trend and 
+      !!      add it to the general trend of momentum equation.
+      !!
+      !! ** Method  :   The now vertical advection of momentum is given by:
+      !!         w dz(u) = ua + 1/(e1u*e2u*e3u) mk+1[ mi(e1t*e2t*wn) dk(un) ]
+      !!         w dz(v) = va + 1/(e1v*e2v*e3v) mk+1[ mj(e1t*e2t*wn) dk(vn) ]
+      !!      Add this trend to the general trend (ua,va):
+      !!         (ua,va) = (ua,va) + w dz(u,v)
+      !!
+      !! ** Action  : - Update (ua,va) with the vert. momentum adv. trends
+      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+     !!----------------------------------------------------------------------
+      USE oce, ONLY:   zwuw => ta   ! use ta as 3D workspace
+      USE oce, ONLY:   zwvw => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zua, zva        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zww            ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'dyn_zad : arakawa advection scheme'
+         IF(lwp)WRITE(numout,*) '~~~~~~~   vector optimization k-j-i loop'
+      ENDIF
+
+      IF( l_trddyn )   THEN         ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
+      ENDIF
+      
+      DO jk = 2, jpkm1              ! Vertical momentum advection at level w and u- and v- vertical
+         DO jj = 2, jpj                   ! vertical fluxes 
+            DO ji = fs_2, jpi             ! vector opt.
+               zww(ji,jj) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = 2, jpjm1                 ! vertical momentum advection at w-point
+            DO ji = fs_2, fs_jpim1        ! vector opt.
+               zwuw(ji,jj,jk) = ( zww(ji+1,jj  ) + zww(ji,jj) ) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
+               zwvw(ji,jj,jk) = ( zww(ji  ,jj+1) + zww(ji,jj) ) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
+            END DO  
+         END DO   
+      END DO
+      DO jj = 2, jpjm1              ! Surface and bottom values set to zero
+         DO ji = fs_2, fs_jpim1           ! vector opt.
+            zwuw(ji,jj, 1 ) = 0.e0
+            zwvw(ji,jj, 1 ) = 0.e0
+            zwuw(ji,jj,jpk) = 0.e0
+            zwvw(ji,jj,jpk) = 0.e0
+         END DO  
+      END DO
+
+      DO jk = 1, jpkm1              ! Vertical momentum advection at u- and v-points
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1       ! vector opt.
+               !                         ! vertical momentum advective trends
+               zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               !                         ! add the trends to the general momentum trends
+               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+               va(ji,jj,jk) = va(ji,jj,jk) + zva
+            END DO  
+         END DO  
+      END DO
+
+      IF( l_trddyn ) THEN           ! save the vertical advection trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod(ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt)
+      ENDIF
+      !                             ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_zad
+#endif
+
+   !!======================================================================
+END MODULE dynzad
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 4536)
@@ -0,0 +1,147 @@
+MODULE dynzdf
+   !!==============================================================================
+   !!                 ***  MODULE  dynzdf  ***
+   !! Ocean dynamics :  vertical component of the momentum mixing trend
+   !!==============================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf      : Update the momentum trend with the vertical diffusion
+   !!       zdf_ctl  : initializations of the vertical diffusion scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+
+   USE dynzdf_exp      ! vertical diffusion: explicit (dyn_zdf_exp     routine)
+   USE dynzdf_imp      ! vertical diffusion: implicit (dyn_zdf_imp     routine)
+   USE dynzdf_imp_jki  ! vertical diffusion  implicit (dyn_zdf_imp_jki routine)
+
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE trdmod          ! ocean active dynamics and tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dyn_zdf    !  routine called by step.F90
+
+   INTEGER  ::   nzdf = 0              ! type vertical diffusion algorithm used 
+      !                                ! defined from ln_zdf...  namlist logicals)
+
+   REAL(wp) ::   r2dt                  ! time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/DYN/dynzdf.F90,v 1.3 2007/06/05 11:00:28 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE dyn_zdf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf  ***
+      !!
+      !! ** Purpose :   compute the vertical ocean dynamics physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL zdf_ctl          ! initialisation & control of options
+
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
+         ztrdu(:,:,:) = ua(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:)
+      ENDIF
+
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )   ;   CALL dyn_zdf_exp    ( kt, r2dt )      ! explicit scheme
+      CASE ( 1 )   ;   CALL dyn_zdf_imp    ( kt, r2dt )      ! implicit scheme (k-j-i loop)
+      CASE ( 2 )   ;   CALL dyn_zdf_imp_jki( kt, r2dt )      ! implicit scheme (j-k-i loop)
+      !
+      CASE ( -1 )                                      ! esopa: test all possibility with control print
+                       CALL dyn_zdf_exp    ( kt, r2dt )
+                       CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf0 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+                       CALL dyn_zdf_imp    ( kt, r2dt )
+                       CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf1 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+                       CALL dyn_zdf_imp_jki( kt, r2dt )
+                       CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf2 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      END SELECT
+
+      IF( l_trddyn )   THEN                      ! save the vertical diffusive trends for further diagnostics
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zdf, 'DYN', kt )
+      ENDIF
+      !                                          ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf  - Ua: ', mask1=umask,               &
+            &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+   END SUBROUTINE dyn_zdf
+
+
+   SUBROUTINE zdf_ctl
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdf_ctl  ***
+      !!
+      !! ** Purpose :   initializations of the vertical diffusion scheme
+      !!
+      !! ** Method  :   implicit (euler backward) scheme (default)
+      !!                explicit (time-splitting) scheme if ln_zdfexp=T
+      !!                OpenMP / NEC autotasking: use j-k-i loops
+      !!----------------------------------------------------------------------
+      USE zdftke
+      USE zdfkpp
+      !!----------------------------------------------------------------------
+
+      ! Choice from ln_zdfexp read in namelist in zdfini
+      IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
+      ELSE                   ;   nzdf = 1           ! use implicit scheme
+      ENDIF
+
+      ! Force implicit schemes
+      IF( lk_zdftke .OR. lk_zdfkpp   )   nzdf = 1   ! TKE or KPP physics
+      IF( ln_dynldf_iso              )   nzdf = 1   ! iso-neutral lateral physics
+      IF( ln_dynldf_hor .AND. ln_sco )   nzdf = 1   ! horizontal lateral physics in s-coordinate
+
+      ! OpenMP / NEC autotasking
+#if defined key_mpp_omp
+      IF( nzdf == 1 )   nzdf = 2                    ! j-k-i loop
+#endif
+
+      IF( lk_esopa )    nzdf = -1                   ! Esopa key: All schemes used
+
+      IF(lwp) THEN                                  ! Print the choice
+         WRITE(numout,*)
+         WRITE(numout,*) 'dyn:zdf_ctl : vertical dynamics physics scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         IF( nzdf == -1 )   WRITE(numout,*) '              ESOPA test All scheme used'
+         IF( nzdf ==  0 )   WRITE(numout,*) '              Explicit time-splitting scheme'
+         IF( nzdf ==  1 )   WRITE(numout,*) '              Implicit (euler backward) scheme'
+         IF( nzdf ==  2 )   WRITE(numout,*) '              Implicit (euler backward) scheme with j-k-i loops'
+      ENDIF
+      !
+   END SUBROUTINE zdf_ctl
+
+   !!==============================================================================
+END MODULE dynzdf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 4536)
@@ -0,0 +1,128 @@
+MODULE dynzdf_exp
+   !!==============================================================================
+   !!                     ***  MODULE  dynzdf_exp  ***
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !!==============================================================================
+   !! History :      !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf_exp  : update the momentum trend with the vertical diffu-
+   !!                  sion using an explicit time-stepping scheme.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE taumod          ! surface ocean stress
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_zdf_exp    ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_zdf_exp( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_exp  ***
+      !!                   
+      !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
+      !!
+      !! ** Method  :   Explicit forward time stepping with a time splitting
+      !!      technique. The vertical diffusion of momentum is given by:
+      !!         diffu = dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ub) )
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F90)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )
+      !!
+      !! ** Action : - Update (ua,va) with the vertical diffusive trend
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jl                              ! dummy loop indices
+      REAL(wp) ::   zrau0r, zlavmr, zua, zva                   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpk) ::   zwx, zwy, zwz, zww     ! temporary workspace arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_exp : vertical momentum diffusion explicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      ! Local constant initialization
+      ! -----------------------------
+      zrau0r = 1. / rau0                                   ! inverse of the reference density
+      zlavmr = 1. / float( n_zdfexp )                      ! inverse of the number of sub time step
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+
+         ! Surface boundary condition
+         DO ji = 2, jpim1
+            zwy(ji,1) = taux(ji,jj) * zrau0r
+            zww(ji,1) = tauy(ji,jj) * zrau0r
+         END DO  
+
+         ! Initialization of x, z and contingently trends array
+         DO jk = 1, jpk
+            DO ji = 2, jpim1
+               zwx(ji,jk) = ub(ji,jj,jk)
+               zwz(ji,jk) = vb(ji,jj,jk)
+            END DO  
+         END DO  
+
+         ! Time splitting loop
+         DO jl = 1, n_zdfexp
+
+            ! First vertical derivative
+            DO jk = 2, jpk
+               DO ji = 2, jpim1
+                  zwy(ji,jk) = avmu(ji,jj,jk) * ( zwx(ji,jk-1) - zwx(ji,jk) ) / fse3uw(ji,jj,jk) 
+                  zww(ji,jk) = avmv(ji,jj,jk) * ( zwz(ji,jk-1) - zwz(ji,jk) ) / fse3vw(ji,jj,jk)
+               END DO  
+            END DO  
+
+            ! Second vertical derivative and trend estimation at kt+l*rdt/n_zdfexp
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  zua = zlavmr*( zwy(ji,jk) - zwy(ji,jk+1) ) / fse3u(ji,jj,jk)
+                  zva = zlavmr*( zww(ji,jk) - zww(ji,jk+1) ) / fse3v(ji,jj,jk)
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + zua
+                  va(ji,jj,jk) = va(ji,jj,jk) + zva
+
+                  zwx(ji,jk) = zwx(ji,jk) + p2dt*zua*umask(ji,jj,jk)
+                  zwz(ji,jk) = zwz(ji,jk) + p2dt*zva*vmask(ji,jj,jk)
+               END DO  
+            END DO  
+
+         END DO  
+
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_zdf_exp
+
+   !!==============================================================================
+END MODULE dynzdf_exp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4536)
@@ -0,0 +1,279 @@
+MODULE dynzdf_imp
+   !!==============================================================================
+   !!                    ***  MODULE  dynzdf_imp  ***
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !!==============================================================================
+   !! History :      !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf_imp  : update the momentum trend with the vertical diffu-
+   !!                  sion using a implicit time-stepping.
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE taumod          ! surface ocean stress
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_zdf_imp    ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+
+   SUBROUTINE dyn_zdf_imp( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_imp  ***
+      !!                   
+      !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
+      !!      and the surface forcing, and add it to the general trend of 
+      !!      the momentum equations.
+      !!
+      !! ** Method  :   The vertical momentum mixing trend is given by :
+      !!             dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ua) )
+      !!      backward time stepping
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )
+      !!
+      !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
+      !!               mixing trend.
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      USE oce, ONLY :  zwd   => ta,   &                ! use ta as workspace
+                       zws   => sa                     ! use sa as workspace
+
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                   ! ocean time-step index
+      REAL(wp), INTENT( in ) ::  p2dt                  ! vertical profile of tracer time-step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                          ! dummy loop indices
+      REAL(wp) ::   zrau0r, z2dtf, zcoef, zzws, zrhs   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwi        ! temporary workspace arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp : vertical momentum diffusion implicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      zrau0r = 1. / rau0      ! inverse of the reference density
+
+      ! 1. Vertical diffusion on u
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! bottom boundary condition: only zws must be masked as avmu can take
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used (see zdfmix.F)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef = - p2dt / fse3u(ji,jj,jk)
+               zwi(ji,jj,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  )
+               zzws          = zcoef * avmu(ji,jj,jk+1) / fse3uw(ji,jj,jk+1)
+               zws(ji,jj,jk) = zzws * umask(ji,jj,jk+1)
+               zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1 
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0.
+            zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion starting from the first level
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and a lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (the after velocity) is in ua
+      !-----------------------------------------------------------------------
+
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+!!! change les resultats (derniers digit, pas significativement + rapide 1* de moins)
+!!!         ua(ji,jj,1) = ub(ji,jj,1)  &
+!!!                      + p2dt * ( ua(ji,jj,1) + taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 ) )
+            z2dtf = p2dt / ( fse3u(ji,jj,1)*rau0 )
+            ua(ji,jj,1) = ub(ji,jj,1)  &
+                         + p2dt *  ua(ji,jj,1) + z2dtf * taux(ji,jj)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrhs = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)   ! zrhs=right hand side
+               ua(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ua(ji,jj,jpkm1) = ua(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) =( ua(ji,jj,jk) - zws(ji,jj,jk) * ua(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Normalization to obtain the general momentum trend ua
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) - ub(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. Vertical diffusion on v
+      ! ---------------------------
+      ! Matrix and second member construction
+      ! bottom boundary condition: only zws must be masked as avmv can take
+      ! non zero value at the ocean bottom depending on the bottom friction
+      ! used (see zdfmix.F)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef = -p2dt / fse3v(ji,jj,jk)
+               zwi(ji,jj,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  )
+               zzws       = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
+               zws(ji,jj,jk) =  zzws * vmask(ji,jj,jk+1)
+               zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zzws
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0.e0
+            zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+         END DO
+      END DO
+
+      ! Matrix inversion
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular
+      !   matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (after velocity) is in 2d array va
+      !-----------------------------------------------------------------------
+
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+!!! change les resultats (derniers digit, pas significativement + rapide 1* de moins)
+!!!         va(ji,jj,1) = vb(ji,jj,1)  &
+!!!                      + p2dt * ( va(ji,jj,1) + tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 ) )
+            z2dtf = p2dt / ( fse3v(ji,jj,1)*rau0 )
+            va(ji,jj,1) = vb(ji,jj,1)  &
+                         + p2dt * va(ji,jj,1) + z2dtf * tauy(ji,jj)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrhs = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)   ! zrhs=right hand side
+               va(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! thrid recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk
+      DO jj = 2, jpjm1   
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            va(ji,jj,jpkm1) = va(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               va(ji,jj,jk) =( va(ji,jj,jk) - zws(ji,jj,jk) * va(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Normalization to obtain the general momentum trend va
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               va(ji,jj,jk) = ( va(ji,jj,jk) - vb(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_zdf_imp
+
+   !!==============================================================================
+END MODULE dynzdf_imp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90	(revision 4536)
@@ -0,0 +1,264 @@
+MODULE dynzdf_imp_jki
+   !!==============================================================================
+   !!                    ***  MODULE  dynzdf_imp_jki  ***
+   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
+   !!==============================================================================
+   !! History : 8.5  !  02-08  (G. Madec)  auto-tasking option
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf_imp_jki : update the momentum trend with the vertical
+   !!                     diffusion using an implicit time-stepping and
+   !!                     j-k-i loops.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE taumod          ! surface ocean stress
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC dyn_zdf_imp_jki     ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_zdf_imp_jki( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_zdf_imp_jki  ***
+      !!                   
+      !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
+      !!      and the surface forcing, and add it to the general trend of 
+      !!      the momentum equations.
+      !!
+      !! ** Method  :   The vertical momentum mixing trend is given by :
+      !!             dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ua) )
+      !!      backward time stepping
+      !!      Surface boundary conditions: wind stress input
+      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F)
+      !!      Add this trend to the general trend ua :
+      !!         ua = ua + dz( avmu dz(u) )
+      !!
+      !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
+      !!               mixing trend.
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in ) ::   kt                          ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                        ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                                 ! dummy loop indices
+      INTEGER ::   ikst, ikenm2, ikstp1                       ! temporary integers
+      REAL(wp) ::  zrau0r, z2dtf, zcoef, zzws                 ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpk) ::  zwx, zwy, zwz,       & ! workspace
+         &                             zwd, zws, zwi, zwt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp_jki : vertical momentum diffusion implicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   auto-task case (j-k-i loop)'
+      ENDIF
+
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      zrau0r = 1. / rau0      ! inverse of the reference density
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         ! 1. Vertical diffusion on u
+         ! ---------------------------
+
+         ! Matrix and second member construction
+         ! bottom boundary condition: only zws must be masked as avmu can take
+         ! non zero value at the ocean bottom depending on the bottom friction
+         ! used (see zdfmix.F)
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               zcoef = - p2dt / fse3u(ji,jj,jk)
+               zwi(ji,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  )
+               zzws       = zcoef * avmu(ji,jj,jk+1) / fse3uw(ji,jj,jk+1)
+               zws(ji,jk) = zzws * umask(ji,jj,jk+1)
+               zwd(ji,jk) = 1. - zwi(ji,jk) - zzws
+               zwy(ji,jk) = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)
+            END DO
+         END DO
+
+         ! Surface boudary conditions
+         DO ji = 2, jpim1
+            z2dtf = p2dt / ( fse3u(ji,jj,1)*rau0 )
+            zwi(ji,1) = 0.
+            zwd(ji,1) = 1. - zws(ji,1)
+            zwy(ji,1) = zwy(ji,1) + z2dtf * taux(ji,jj)
+         END DO
+
+         ! Matrix inversion starting from the first level
+         ikst = 1
+!!----------------------------------------------------------------------
+!!         ZDF.MATRIXSOLVER
+!!       ********************
+!!----------------------------------------------------------------------
+!! Matrix inversion
+!   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+!
+!        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+!        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+!        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+!        (        ...               )( ...  ) ( ...  )
+!        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+!
+!   m is decomposed in the product of an upper and lower triangular
+!   matrix
+!   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+!   The second member is in 2d array zwy
+!   The solution is in 2d array zwx
+!   The 2d arry zwt and zwz are work space arrays
+!
+!   N.B. the starting vertical index (ikst) is equal to 1 except for
+!   the resolution of tke matrix where surface tke value is prescribed
+!   so that ikstrt=2.
+!!----------------------------------------------------------------------
+
+         ikstp1 = ikst + 1
+         ikenm2 = jpk - 2
+         DO ji = 2, jpim1
+            zwt(ji,ikst) = zwd(ji,ikst)
+         END DO
+         DO jk = ikstp1, jpkm1
+            DO ji = 2, jpim1
+               zwt(ji,jk) = zwd(ji,jk) - zwi(ji,jk) * zws(ji,jk-1) / zwt(ji,jk-1)
+            END DO
+         END DO
+         DO ji = 2, jpim1
+            zwz(ji,ikst) = zwy(ji,ikst)
+         END DO
+         DO jk = ikstp1, jpkm1
+            DO ji = 2, jpim1
+               zwz(ji,jk) = zwy(ji,jk) - zwi(ji,jk) / zwt(ji,jk-1) * zwz(ji,jk-1)
+            END DO
+         END DO
+         DO ji = 2, jpim1
+            zwx(ji,jpkm1) = zwz(ji,jpkm1) / zwt(ji,jpkm1)
+         END DO
+         DO jk = ikenm2, ikst, -1
+            DO ji = 2, jpim1
+            zwx(ji,jk) =( zwz(ji,jk) - zws(ji,jk) * zwx(ji,jk+1) ) / zwt(ji,jk)
+            END DO
+         END DO
+      
+         ! Normalization to obtain the general momentum trend ua
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) = ( zwx(ji,jk) - ub(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+
+
+         ! 2. Vertical diffusion on v
+         ! ---------------------------
+         ! Matrix and second member construction
+         ! bottom boundary condition: only zws must be masked as avmv can take
+         ! non zero value at the ocean bottom depending on the bottom friction
+         ! used (see zdfmix.F)
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               zcoef = -p2dt/fse3v(ji,jj,jk)
+               zwi(ji,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  )
+               zzws       = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
+               zws(ji,jk) =  zzws * vmask(ji,jj,jk+1)
+               zwd(ji,jk) = 1. - zwi(ji,jk) - zzws
+               zwy(ji,jk) = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)
+            END DO
+         END DO
+
+         ! Surface boudary conditions
+         DO ji = 2, jpim1
+            z2dtf = p2dt / ( fse3v(ji,jj,1)*rau0 )
+            zwi(ji,1) = 0.e0
+            zwd(ji,1) = 1. - zws(ji,1)
+            zwy(ji,1) = zwy(ji,1) + z2dtf * tauy(ji,jj)
+         END DO
+
+         ! Matrix inversion starting from the first level
+         ikst = 1
+!!----------------------------------------------------------------------
+!!         ZDF.MATRIXSOLVER
+!!       ********************
+!!----------------------------------------------------------------------
+!! Matrix inversion
+!   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+!
+!        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+!        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+!        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+!        (        ...               )( ...  ) ( ...  )
+!        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+!
+!   m is decomposed in the product of an upper and lower triangular
+!   matrix
+!   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+!   The second member is in 2d array zwy
+!   The solution is in 2d array zwx
+!   The 2d arry zwt and zwz are work space arrays
+!
+!   N.B. the starting vertical index (ikst) is equal to 1 except for
+!   the resolution of tke matrix where surface tke value is prescribed
+!   so that ikstrt=2.
+!!----------------------------------------------------------------------
+
+         ikstp1 = ikst + 1
+         ikenm2 = jpk - 2
+         DO ji = 2, jpim1
+            zwt(ji,ikst) = zwd(ji,ikst)
+         END DO
+         DO jk = ikstp1, jpkm1
+            DO ji = 2, jpim1
+               zwt(ji,jk) = zwd(ji,jk) - zwi(ji,jk) * zws(ji,jk-1) / zwt(ji,jk-1)
+            END DO
+         END DO
+         DO ji = 2, jpim1
+            zwz(ji,ikst) = zwy(ji,ikst)
+         END DO
+         DO jk = ikstp1, jpkm1
+            DO ji = 2, jpim1
+               zwz(ji,jk) = zwy(ji,jk) - zwi(ji,jk) / zwt(ji,jk-1) * zwz(ji,jk-1)
+            END DO
+         END DO
+         DO ji = 2, jpim1
+            zwx(ji,jpkm1) = zwz(ji,jpkm1) / zwt(ji,jpkm1)
+         END DO
+         DO jk = ikenm2, ikst, -1
+            DO ji = 2, jpim1
+               zwx(ji,jk) =( zwz(ji,jk) - zws(ji,jk) * zwx(ji,jk+1) ) / zwt(ji,jk)
+            END DO
+         END DO
+      
+         ! Normalization to obtain the general momentum trend va
+         DO jk = 1, jpkm1
+            DO ji = 2, jpim1
+               va(ji,jj,jk) = ( zwx(ji,jk) - vb(ji,jj,jk) ) / p2dt
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+   END SUBROUTINE dyn_zdf_imp_jki
+
+   !!==============================================================================
+END MODULE dynzdf_imp_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/wzvmod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/wzvmod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/DYN/wzvmod.F90	(revision 4536)
@@ -0,0 +1,194 @@
+MODULE wzvmod
+   !!==============================================================================
+   !!                       ***  MODULE  wzvmod  ***
+   !! Ocean diagnostic variable : vertical velocity
+   !!==============================================================================
+   !! History :   5.0  !  90-10  (C. Levy, G. Madec)  Original code
+   !!             7.0  !  96-01  (G. Madec)  Statement function for e3
+   !!             8.5  !  02-07  (G. Madec)  Free form, F90
+   !!----------------------------------------------------------------------
+   !!   wzv        : Compute the vertical velocity
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   USE domvvl          ! Variable volume
+   USE phycst
+   USE ocesbc          ! ocean surface boundary condition
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC wzv          ! routine called by step.F90 and inidtr.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp'                                   j-k-i loop (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE wzv( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE wzv  ***
+      !!                     
+      !! ** Purpose :   Compute the now vertical velocity after the array swap
+      !!
+      !! ** Method  :   Using the incompressibility hypothesis, the vertical
+      !!     velocity is computed by integrating the horizontal divergence 
+      !!     from the bottom to the surface.
+      !!     The boundary conditions are w=0 at the bottom (no flux) and,
+      !!     in rigid-lid case, w=0 at the sea surface.
+      !!
+      !! ** action  :    wn array : the now vertical velocity
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   jj, jk      ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'wzv     : vertical velocity from continuity eq.'
+         IF(lwp) WRITE(numout,*) '~~~~~~~                     j-k-i loops'
+
+         ! bottom boundary condition: w=0 (set once for all)
+         wn(:,:,jpk) = 0.e0
+      ENDIF
+
+      !                                                ! ===============
+      DO jj = 1, jpj                                   !  Vertical slab
+         !                                             ! ===============
+         ! Computation from the bottom
+         DO jk = jpkm1, 1, -1
+            wn(:,jj,jk) = wn(:,jj,jk+1) - fse3t(:,jj,jk) * hdivn(:,jj,jk)
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=wn, clinfo1=' w**2 -   : ', mask1=wn)
+
+   END SUBROUTINE wzv
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                           k-j-i loop
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE wzv( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE wzv  ***
+      !!
+      !! ** Purpose :   Compute the now vertical velocity after the array swap
+      !!
+      !! ** Method  :   Using the incompressibility hypothesis, the vertical
+      !!      velocity is computed by integrating the horizontal divergence 
+      !!      from the bottom to the surface.
+      !!        The boundary conditions are w=0 at the bottom (no flux) and,
+      !!      in regid-lid case, w=0 at the sea surface.
+      !!
+      !! ** action  :   wn array : the now vertical velocity
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::           jk           ! dummy loop indices
+      !! Variable volume
+      INTEGER  ::   ji, jj               ! dummy loop indices
+      REAL(wp) ::   z2dt, zraur          ! temporary scalar
+      REAL(wp), DIMENSION (jpi,jpj) ::   zssha, zun, zvn, zhdiv
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'wzv     : vertical velocity from continuity eq.'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ ' 
+
+         ! bottom boundary condition: w=0 (set once for all)
+         wn(:,:,jpk) = 0.e0
+      ENDIF
+
+      IF( lk_vvl ) THEN                ! Variable volume
+         !
+         z2dt = 2. * rdt                                       ! time step: leap-frog
+         IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt       ! time step: Euler if restart from rest
+         zraur  = 1. / rauw
+
+         ! Vertically integrated quantities
+         ! --------------------------------
+         zun(:,:) = 0.e0
+         zvn(:,:) = 0.e0
+         !
+         DO jk = 1, jpkm1             ! Vertically integrated transports (now)
+            zun(:,:) = zun(:,:) + fse3u(:,:,jk) * un(:,:,jk)
+            zvn(:,:) = zvn(:,:) + fse3v(:,:,jk) * vn(:,:,jk)
+         END DO
+
+         ! Horizontal divergence of barotropic transports
+         !--------------------------------------------------
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1   ! vector opt.
+               zhdiv(ji,jj) = (  e2u(ji  ,jj  ) * zun(ji  ,jj  )     &
+                  &            - e2u(ji-1,jj  ) * zun(ji-1,jj  )     &
+                  &            + e1v(ji  ,jj  ) * zvn(ji  ,jj  )     &
+                  &            - e1v(ji  ,jj-1) * zvn(ji  ,jj-1) )   &
+                  &           / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+
+#if defined key_obc && ( key_dynspg_exp || key_dynspg_ts )
+         ! open boundaries (div must be zero behind the open boundary)
+         !  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
+         IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1)   = 0.e0    ! east
+         IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1)   = 0.e0    ! west
+         IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0.e0    ! north
+         IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1)   = 0.e0    ! south
+#endif
+
+         CALL lbc_lnk( zhdiv, 'T', 1. )
+
+         ! Sea surface elevation time stepping
+         ! -----------------------------------
+         zssha(:,:) = sshb(:,:) - z2dt * ( zraur * emp(:,:) + zhdiv(:,:) ) * tmask(:,:,1)
+
+         ! Vertical velocity computed from bottom
+         ! --------------------------------------
+         DO jk = jpkm1, 1, -1
+            wn(:,:,jk) = wn(:,:,jk+1) - fse3t(:,:,jk) * hdivn(:,:,jk) &
+              &        - ( zssha(:,:) - sshb(:,:) ) * fsve3t(:,:,jk) * mut(:,:,jk) / z2dt
+         END DO
+
+      ELSE                             ! Fixed volume 
+
+         ! Vertical velocity computed from bottom
+         ! --------------------------------------
+         DO jk = jpkm1, 1, -1
+            wn(:,:,jk) = wn(:,:,jk+1) - fse3t(:,:,jk) * hdivn(:,:,jk)
+         END DO
+      
+      ENDIF 
+
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=wn, clinfo1=' w**2 -   : ', mask1=wn)
+
+   END SUBROUTINE wzv
+#endif
+
+   !!======================================================================
+END MODULE wzvmod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo4rk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo4rk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo4rk.F90	(revision 4536)
@@ -0,0 +1,502 @@
+MODULE flo4rk
+   !!======================================================================
+   !!                    ***  MODULE  flo4rk  ***
+   !! Ocean floats :   trajectory computation using a 4th order Runge-Kutta
+   !!======================================================================
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                     float trajectories
+   !!----------------------------------------------------------------------
+   !!   flo_4rk        : Compute the geographical position of floats
+   !!   flo_interp     : interpolation
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE flo_oce         ! ocean drifting floats
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC flo_4rk      ! routine called by floats.F90
+
+   !! * Module variables
+   REAL(wp), DIMENSION (4) ::   &   ! RK4 and Lagrange interpolation
+      tcoef1 = (/  1.0  ,  0.5  ,  0.5  ,  0.0  /) ,  &  ! coeffients  for 
+      tcoef2 = (/  0.0  ,  0.5  ,  0.5  ,  1.0  /) ,  &  ! lagrangian interp.
+      scoef2 = (/  1.0  ,  2.0  ,  2.0  ,  1.0  /) ,  &  ! RK4 coefficients
+      rcoef  = (/-1./6. , 1./2. ,-1./2. , 1./6. /)       ! ???
+   REAL(wp), DIMENSION (3) ::   &
+      scoef1 = (/ .5, .5, 1. /)       ! compute position with interpolated
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flo_4rk( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE flo_4rk  ***
+      !!
+      !!  ** Purpose :   Compute the geographical position (lat,lon,depth)
+      !!       of each float at each time step.
+      !! 
+      !!  ** Method  :   The position of a float is computed with a 4th order
+      !!       Runge-Kutta scheme and and Lagrange interpolation.
+      !!         We need to know the velocity field, the old positions of the
+      !!       floats and the grid defined on the domain.
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::  jfl, jind           ! dummy loop indices
+      REAL(wp), DIMENSION ( jpnfl)  ::   &
+         zgifl, zgjfl, zgkfl,   &     ! index RK  positions
+         zufl, zvfl, zwfl             ! interpolated velocity at the
+      ! float position 
+      REAL(wp), DIMENSION ( jpnfl, 4 )  ::    &
+         zrkxfl, zrkyfl, zrkzfl       ! RK coefficients
+      !!---------------------------------------------------------------------
+    
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flo_4rk : compute Runge Kutta trajectories for floats '
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Verification of the floats positions. If one of them leave the domain
+      ! domain we replace the float near the border.
+      DO jfl = 1, jpnfl
+         ! i-direction
+         IF( tpifl(jfl) <= 1.5 ) THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the WEST border.'
+            tpifl(jfl) = tpifl(jfl) + 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at i=',tpifl(jfl)
+         ENDIF
+          
+         IF( tpifl(jfl) >= jpi-.5 ) THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the EAST border.'
+            tpifl(jfl) = tpifl(jfl) - 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at i=', tpifl(jfl)
+         ENDIF
+         ! j-direction
+         IF( tpjfl(jfl) <= 1.5 ) THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the SOUTH border.'
+            tpjfl(jfl) = tpjfl(jfl) + 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at j=', tpjfl(jfl)
+         ENDIF
+           
+         IF( tpjfl(jfl) >= jpj-.5 ) THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the NORTH border.'
+            tpjfl(jfl) = tpjfl(jfl) - 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at j=', tpjfl(jfl)
+         ENDIF
+         ! k-direction
+         IF( tpkfl(jfl) <= .5 ) THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the TOP border.'
+            tpkfl(jfl) = tpkfl(jfl) + 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at k=', tpkfl(jfl)
+         ENDIF
+         
+         IF( tpkfl(jfl) >= jpk-.5 )  THEN
+            IF(lwp)WRITE(numout,*)'!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!'
+            IF(lwp)WRITE(numout,*)'The float',jfl,'is out of the domain at the BOTTOM border.'
+            tpkfl(jfl) = tpkfl(jfl) - 1.
+            IF(lwp)WRITE(numout,*)'New initialisation for this float at k=', tpkfl(jfl)
+         ENDIF
+      END DO
+      
+      ! 4 steps of Runge-Kutta algorithme
+      ! initialisation of the positions 
+      
+      DO jfl = 1, jpnfl
+         zgifl(jfl) = tpifl(jfl)
+         zgjfl(jfl) = tpjfl(jfl)
+         zgkfl(jfl) = tpkfl(jfl)
+      END DO
+       
+      DO  jind = 1, 4
+         
+         ! for each step we compute the compute the velocity with Lagrange interpolation
+         CALL flo_interp(zgifl,zgjfl,zgkfl,zufl,zvfl,zwfl,jind)
+         
+         ! computation of Runge-Kutta factor
+         
+         DO jfl = 1, jpnfl
+            zrkxfl(jfl,jind) = rdt*zufl(jfl)
+            zrkyfl(jfl,jind) = rdt*zvfl(jfl)
+            zrkzfl(jfl,jind) = rdt*zwfl(jfl)
+         END DO
+         IF( jind /= 4 ) THEN
+            DO jfl = 1, jpnfl
+               zgifl(jfl) = (tpifl(jfl)) + scoef1(jind)*zrkxfl(jfl,jind)
+               zgjfl(jfl) = (tpjfl(jfl)) + scoef1(jind)*zrkyfl(jfl,jind)
+               zgkfl(jfl) = (tpkfl(jfl)) + scoef1(jind)*zrkzfl(jfl,jind)
+            END DO
+         ENDIF
+      END DO
+      DO jind = 1, 4
+         DO jfl = 1, jpnfl
+            tpifl(jfl) = tpifl(jfl) + scoef2(jind)*zrkxfl(jfl,jind)/6.
+            tpjfl(jfl) = tpjfl(jfl) + scoef2(jind)*zrkyfl(jfl,jind)/6.
+            tpkfl(jfl) = tpkfl(jfl) + scoef2(jind)*zrkzfl(jfl,jind)/6.
+         END DO
+      END DO
+
+   END SUBROUTINE flo_4rk
+
+
+   SUBROUTINE flo_interp( pxt , pyt , pzt ,      &
+      &                   pufl, pvfl, pwfl, kind )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE flointerp  ***
+      !!
+      !! ** Purpose :   Interpolation of the velocity on the float position
+      !! 
+      !! ** Method  :   Lagrange interpolation with the 64 neighboring
+      !!      points. This routine is call 4 time at each time step to
+      !!      compute velocity at the date and the position we need to
+      !!      integrated with RK method.
+      !!
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   &
+         kind,   &
+         jfl, jind1, jind2, jind3,   &
+         zsumu, zsumv, zsumw
+      INTEGER , DIMENSION  ( jpnfl  ) ::   &
+         iilu, ijlu, iklu,     &           ! nearest neighbour INDEX-u
+         iilv, ijlv, iklv,     &           ! nearest neighbour INDEX-v
+         iilw, ijlw, iklw                  ! nearest neighbour INDEX-w
+      INTEGER , DIMENSION  ( jpnfl, 4  ) ::   &
+         iidu, ijdu, ikdu,    &            ! 64 nearest neighbour INDEX-u
+         iidv, ijdv, ikdv,    &            ! 64 nearest neighbour INDEX-v
+         iidw, ijdw, ikdw                  ! 64 nearest neighbour INDEX-w
+      REAL(wp) , DIMENSION  ( jpnfl  ) ::   &
+         pxt , pyt , pzt,     &            ! position of the float
+         pufl, pvfl, pwfl                  ! velocity at this position
+      REAL(wp) , DIMENSION  ( jpnfl, 4, 4, 4 ) ::   &
+         ztufl, ztvfl, ztwfl               ! velocity at choosen time step
+      REAL(wp) , DIMENSION  ( jpnfl, 4 ) ::   &
+         zlagxu, zlagyu, zlagzu,   &       ! Lagrange  coefficients
+         zlagxv, zlagyv, zlagzv,   &
+         zlagxw, zlagyw, zlagzw
+      !!---------------------------------------------------------------------
+      
+      ! Interpolation of U velocity
+
+      ! nearest neightboring point for computation of u       
+      DO jfl = 1, jpnfl
+         iilu(jfl) = INT(pxt(jfl)-.5)
+         ijlu(jfl) = INT(pyt(jfl)-.5)
+         iklu(jfl) = INT(pzt(jfl))
+      END DO
+      
+      !  64 neightboring points for computation of u 
+      DO jind1 = 1, 4
+         DO jfl = 1, jpnfl
+            !  i-direction
+            IF( iilu(jfl) <= 2 ) THEN
+               iidu(jfl,jind1) = jind1
+            ELSE
+               IF( iilu(jfl) >= jpi-1 ) THEN
+                  iidu(jfl,jind1) = jpi + jind1 - 4
+               ELSE
+                  iidu(jfl,jind1) = iilu(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            !  j-direction
+            IF( ijlu(jfl) <= 2 ) THEN
+               ijdu(jfl,jind1) = jind1
+            ELSE
+               IF( ijlu(jfl) >= jpj-1 ) THEN
+                  ijdu(jfl,jind1) = jpj + jind1 - 4
+               ELSE
+                  ijdu(jfl,jind1) = ijlu(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            ! k-direction
+            IF( iklu(jfl) <= 2 ) THEN
+               ikdu(jfl,jind1) = jind1
+            ELSE
+               IF( iklu(jfl) >= jpk-1 ) THEN
+                  ikdu(jfl,jind1) = jpk + jind1 - 4
+               ELSE
+                  ikdu(jfl,jind1) = iklu(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+      
+      ! Lagrange coefficients
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            zlagxu(jfl,jind1) = 1.
+            zlagyu(jfl,jind1) = 1.
+            zlagzu(jfl,jind1) = 1.
+         END DO
+      END DO
+      
+      DO jind1 = 1, 4
+         DO jind2 = 1, 4
+            DO jfl= 1, jpnfl
+               IF( jind1 /= jind2 ) THEN
+                  zlagxu(jfl,jind1) = zlagxu(jfl,jind1) * ( pxt(jfl)-(float(iidu(jfl,jind2))+.5) )
+                  zlagyu(jfl,jind1) = zlagyu(jfl,jind1) * ( pyt(jfl)-(float(ijdu(jfl,jind2))) )
+                  zlagzu(jfl,jind1) = zlagzu(jfl,jind1) * ( pzt(jfl)-(float(ikdu(jfl,jind2))) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+      
+      ! velocity when we compute at middle time step
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1, 4
+                  ztufl(jfl,jind1,jind2,jind3) =   &
+                     &   (  tcoef1(kind) * ub(iidu(jfl,jind1),ijdu(jfl,jind2),ikdu(jfl,jind3)) +   &
+                     &      tcoef2(kind) * un(iidu(jfl,jind1),ijdu(jfl,jind2),ikdu(jfl,jind3)) )   &
+                     &      / e1u(iidu(jfl,jind1),ijdu(jfl,jind2)) 
+               END DO
+            END DO
+         END DO
+         
+         zsumu = 0.
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1, 4
+                  zsumu = zsumu + ztufl(jfl,jind1,jind2,jind3) * zlagxu(jfl,jind1) * zlagyu(jfl,jind2)   &
+                     &  * zlagzu(jfl,jind3) * rcoef(jind1)*rcoef(jind2)*rcoef(jind3) 
+               END DO
+            END DO
+         END DO
+         pufl(jfl) = zsumu
+      END DO
+      
+      ! Interpolation of V velocity 
+
+      ! nearest neightboring point for computation of v 
+      DO jfl = 1, jpnfl
+         iilv(jfl) = INT(pxt(jfl)-.5)
+         ijlv(jfl) = INT(pyt(jfl)-.5)
+         iklv(jfl) = INT(pzt(jfl))
+      END DO
+      
+      ! 64 neightboring points for computation of v 
+      DO jind1 = 1, 4
+         DO jfl = 1, jpnfl
+            ! i-direction
+            IF( iilv(jfl) <= 2 ) THEN
+               iidv(jfl,jind1) = jind1
+            ELSE
+               IF( iilv(jfl) >= jpi-1 ) THEN
+                  iidv(jfl,jind1) = jpi + jind1 - 4
+               ELSE
+                  iidv(jfl,jind1) = iilv(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            ! j-direction
+            IF( ijlv(jfl) <= 2 ) THEN
+               ijdv(jfl,jind1) = jind1
+            ELSE
+               IF( ijlv(jfl) >= jpj-1 ) THEN
+                  ijdv(jfl,jind1) = jpj + jind1 - 4
+               ELSE
+                  ijdv(jfl,jind1) = ijlv(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            ! k-direction
+            IF( iklv(jfl) <= 2 ) THEN
+               ikdv(jfl,jind1) = jind1
+            ELSE
+               IF( iklv(jfl) >= jpk-1 ) THEN
+                  ikdv(jfl,jind1) = jpk + jind1 - 4
+               ELSE
+                  ikdv(jfl,jind1) = iklv(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+      
+      ! Lagrange coefficients
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            zlagxv(jfl,jind1) = 1.
+            zlagyv(jfl,jind1) = 1.
+            zlagzv(jfl,jind1) = 1.
+         END DO
+      END DO
+      
+      DO jind1 = 1, 4
+         DO jind2 = 1, 4
+            DO jfl = 1, jpnfl
+               IF( jind1 /= jind2 ) THEN
+                  zlagxv(jfl,jind1)= zlagxv(jfl,jind1)*(pxt(jfl) - (float(iidv(jfl,jind2))) )
+                  zlagyv(jfl,jind1)= zlagyv(jfl,jind1)*(pyt(jfl) - (float(ijdv(jfl,jind2))+.5) )
+                  zlagzv(jfl,jind1)= zlagzv(jfl,jind1)*(pzt(jfl) - (float(ikdv(jfl,jind2))) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+      
+      ! velocity when we compute at middle time step
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1 ,4
+                  ztvfl(jfl,jind1,jind2,jind3)=   &
+                     &   ( tcoef1(kind) * vb(iidv(jfl,jind1),ijdv(jfl,jind2),ikdv(jfl,jind3))  +   &
+                     &     tcoef2(kind) * vn(iidv(jfl,jind1),ijdv(jfl,jind2),ikdv(jfl,jind3)) )    & 
+                     &     / e2v(iidv(jfl,jind1),ijdv(jfl,jind2))
+               END DO
+            END DO
+         END DO
+         
+         zsumv=0.
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1, 4
+                  zsumv = zsumv + ztvfl(jfl,jind1,jind2,jind3) * zlagxv(jfl,jind1) * zlagyv(jfl,jind2)   &
+                     &  * zlagzv(jfl,jind3) * rcoef(jind1)*rcoef(jind2)*rcoef(jind3)
+               END DO
+            END DO
+         END DO
+         pvfl(jfl) = zsumv
+      END DO
+      
+      ! Interpolation of W velocity
+
+      ! nearest neightboring point for computation of w 
+      DO jfl = 1, jpnfl
+         iilw(jfl) = INT(pxt(jfl))
+         ijlw(jfl) = INT(pyt(jfl))
+         iklw(jfl) = INT(pzt(jfl)+.5)
+      END DO
+      
+      ! 64 neightboring points for computation of w 
+      DO jind1 = 1, 4
+         DO jfl = 1, jpnfl
+            ! i-direction
+            IF( iilw(jfl) <= 2 ) THEN
+               iidw(jfl,jind1) = jind1
+            ELSE
+               IF( iilw(jfl) >= jpi-1 ) THEN
+                  iidw(jfl,jind1) = jpi + jind1 - 4
+               ELSE
+                  iidw(jfl,jind1) = iilw(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            ! j-direction
+            IF( ijlw(jfl) <= 2 ) THEN
+               ijdw(jfl,jind1) = jind1
+            ELSE
+               IF( ijlw(jfl) >= jpj-1 ) THEN
+                  ijdw(jfl,jind1) = jpj + jind1 - 4
+               ELSE
+                  ijdw(jfl,jind1) = ijlw(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+            ! k-direction
+            IF( iklw(jfl) <= 2 ) THEN
+               ikdw(jfl,jind1) = jind1
+            ELSE
+               IF( iklw(jfl) >= jpk-1 ) THEN
+                  ikdw(jfl,jind1) = jpk + jind1 - 4
+               ELSE
+                  ikdw(jfl,jind1) = iklw(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+      DO jind1 = 1, 4
+         DO jfl = 1, jpnfl
+            IF( iklw(jfl) <= 2 ) THEN
+               ikdw(jfl,jind1) = jind1
+            ELSE
+               IF( iklw(jfl) >= jpk-1 ) THEN
+                  ikdw(jfl,jind1) = jpk + jind1 - 4
+               ELSE
+                  ikdw(jfl,jind1) = iklw(jfl) + jind1 - 2
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+      
+      ! Lagrange coefficients  for w interpolation
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            zlagxw(jfl,jind1) = 1.
+            zlagyw(jfl,jind1) = 1.
+            zlagzw(jfl,jind1) = 1.
+         END DO
+      END DO
+       
+      DO jind1 = 1, 4
+         DO jind2 = 1, 4
+            DO jfl = 1, jpnfl
+               IF( jind1 /= jind2 ) THEN
+                  zlagxw(jfl,jind1) = zlagxw(jfl,jind1) * (pxt(jfl) - (float(iidw(jfl,jind2))) )
+                  zlagyw(jfl,jind1) = zlagyw(jfl,jind1) * (pyt(jfl) - (float(ijdw(jfl,jind2))) )
+                  zlagzw(jfl,jind1) = zlagzw(jfl,jind1) * (pzt(jfl) - (float(ikdw(jfl,jind2))-.5) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+      
+      ! velocity w  when we compute at middle time step
+      
+      DO jfl = 1, jpnfl
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1, 4
+                  ztwfl(jfl,jind1,jind2,jind3)=   &
+                     &   ( tcoef1(kind) * wb(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3))+   &
+                     &     tcoef2(kind) * wn(iidw(jfl,jind1),ijdw(jfl,jind2),ikdw(jfl,jind3)) )  &
+!!bug e3w instead of fse3 
+                     &   / e3w(ikdw(jfl,jind3))
+               END DO
+            END DO
+         END DO
+         
+         zsumw=0.
+         DO jind1 = 1, 4
+            DO jind2 = 1, 4
+               DO jind3 = 1, 4
+                  zsumw = zsumw + ztwfl(jfl,jind1,jind2,jind3) * zlagxw(jfl,jind1) * zlagyw(jfl,jind2)   &
+                     &  * zlagzw(jfl,jind3) * rcoef(jind1)*rcoef(jind2)*rcoef(jind3)
+               END DO
+            END DO
+         END DO
+         pwfl(jfl) = zsumw
+      END DO
+      
+   END SUBROUTINE flo_interp
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flo_4rk                 ! Empty routine
+   END SUBROUTINE flo_4rk
+#endif
+   
+   !!======================================================================
+END MODULE flo4rk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flo_oce.F90	(revision 4536)
@@ -0,0 +1,69 @@
+MODULE flo_oce
+   !!======================================================================
+   !!                     ***  MODULE flo_oce  ***
+   !!                
+   !! ** Purpose : - Define in memory all floats parameters and variables
+   !!
+   !! History :
+   !!   8.0  !  99-10  (CLIPPER projet)
+   !!   9.0  !  02-11  (G. Madec, A. Bozec)  F90: Free form and module
+   !!======================================================================
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                        drifting floats
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_floats = .TRUE.    !: float flag
+
+   !! float parameters
+   !! ----------------
+   INTEGER, PARAMETER ::   &
+      jpnfl     = 23 ,            &  ! total number of floats during the run
+      jpnnewflo =  0 ,            &  ! number of floats added in a new run
+      jpnrstflo = jpnfl-jpnnewflo    ! number of floats for the restart
+
+   !! float variables
+   !! ---------------
+   INTEGER, DIMENSION(jpnfl)  ::    &
+      nisobfl,    &  ! 0 for a isobar float
+      !              ! 1 for a float following the w velocity
+      ngrpfl         ! number to identify searcher group
+
+   REAL(wp), DIMENSION(jpnfl) ::    &
+      flxx,       &  ! longitude of float (decimal degree)
+      flyy,       &  ! latitude of float (decimal degree)
+      flzz,       &  ! depth of float (m, positive)
+      tpifl,      &  ! index of float position on zonal axe
+      tpjfl,      &  ! index of float position on meridien axe
+      tpkfl          ! index of float position on z axe
+   
+   REAL(wp), DIMENSION(jpi, jpj, jpk) ::    & 
+      wb             ! vertical velocity at previous time step (m s-1).
+   
+   ! floats unit
+   
+   LOGICAL  ::                & !!! * namelist namflo *
+      ln_rstflo = .FALSE. ,   &  ! T/F float restart 
+      ln_argo   = .FALSE. ,   &  ! T/F argo type floats
+      ln_flork4 = .FALSE.        ! T/F 4th order Runge-Kutta
+   INTEGER  ::               & !!! * namelist namflo *
+      nwritefl,              &  ! frequency of float output file 
+      nstockfl                  ! frequency of float restart file
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                 NO drifting floats
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_floats = .FALSE.   !: float flag
+#endif
+
+   !!======================================================================
+END MODULE flo_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floats.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floats.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floats.F90	(revision 4536)
@@ -0,0 +1,138 @@
+MODULE floats
+   !!======================================================================
+   !!                       ***  MODULE  floats  ***
+   !! Ocean floats : floats
+   !!======================================================================
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                     float trajectories
+   !!----------------------------------------------------------------------
+   !!   flo_stp   : float trajectories computation
+   !!   flo_init  : initialization of float trajectories computation
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE flo_oce         ! floats variables
+   USE lib_mpp         ! distributed memory computing
+   USE flodom          ! initialisation Module 
+   USE flowri          ! float output                     (flo_wri routine)
+   USE flo4rk          ! Trajectories, Runge Kutta scheme (flo_4rk routine)
+   USE floblk          ! Trajectories, Blanke scheme      (flo_blk routine)
+
+   IMPLICIT NONE
+   PRIVATE  
+
+   !! * Routine accessibility
+   PUBLIC flo_stp    ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flo_stp( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE flo_stp  ***
+      !!                    
+      !! ** Purpose :   Compute the geographical position (lat., long., depth)
+      !!      of each float at each time step with one of the algorithm.
+      !! 
+      !! ** Method  :   The position of a float is computed with Bruno Blanke 
+      !!        algorithm by default and with a 4th order Runge-Kutta scheme
+      !!        if ln_flork4 =T
+      !!      
+      !! History :
+      !!   8.5  !  02-06  (A. Bozec, G. Madec )  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flo_stp : call floats routine '
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+         CALL flo_init           ! read the namelist of floats             
+
+         CALL flo_dom            ! compute/read initial position of floats
+
+         ! Initialisation of wb for computation of floats trajectories at the first time step
+         wb(:,:,:) = wn(:,:,:)
+      ENDIF
+
+      IF( ln_flork4 ) THEN
+         CALL flo_4rk( kt )        ! Trajectories using a 4th order Runge Kutta scheme
+      ELSE
+         CALL flo_blk( kt )        ! Trajectories using Blanke' algorithme
+      ENDIF
+
+      IF( lk_mpp )   CALL mppsync   ! synchronization of all the processor
+
+
+      ! Writing and restart      
+      
+      ! trajectories file 
+      IF( kt == nit000 .OR. MOD( kt, nwritefl ) == 0 )   CALL flo_wri( kt )
+      ! restart file 
+      IF( kt == nitend .OR. MOD( kt, nstockfl ) == 0 )   CALL flo_wri( kt )
+
+      ! Save the old vertical velocity field
+      wb(:,:,:) = wn(:,:,:)
+
+   END SUBROUTINE flo_stp
+
+
+   SUBROUTINE flo_init
+      !!----------------------------------------------------------------
+      !!                 ***  ROUTINE flo_init  ***
+      !!                   
+      !! ** Purpose :   Read the namelist of floats
+      !!      
+      !! History :
+      !!   8.0  !         (CLIPPER)   original Code
+      !!   8.5  !  02-06  (A. Bozec)  F90, Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Local declarations
+      NAMELIST/namflo/ ln_rstflo, nwritefl, nstockfl, ln_argo, ln_flork4 
+      !!---------------------------------------------------------------------
+      ! Namelist namflo : floats
+      
+      ! default values
+      ln_rstflo  = .FALSE.
+      nwritefl  = 150
+      nstockfl  = 450
+      
+      ! lecture of namflo
+      REWIND( numnam )
+      READ  ( numnam, namflo )
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '         Namelist floats :'
+         WRITE(numout,*) '            restart                          ln_rstflo = ', ln_rstflo
+         WRITE(numout,*) '            frequency of float output file   nwritefl  = ', nwritefl
+         WRITE(numout,*) '            frequency of float restart file  nstockfl  = ', nstockfl
+         WRITE(numout,*) '            Argo type floats                 ln_argo   = ', ln_argo
+         WRITE(numout,*) '            Computation of T trajectories    ln_flork4 = ', ln_flork4
+         WRITE(numout,*) ' '
+      ENDIF
+
+   END SUBROUTINE flo_init
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flo_stp( kt )          ! Empty routine
+      WRITE(*,*) 'flo_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE flo_stp
+#endif
+
+   !!======================================================================
+ END MODULE floats
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floblk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floblk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/floblk.F90	(revision 4536)
@@ -0,0 +1,428 @@
+MODULE floblk
+   !!======================================================================
+   !!                     ***  MODULE  floblk  ***
+   !! Ocean floats :   trajectory computation
+   !!======================================================================
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                     float trajectories
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!    flotblk     : compute float trajectories with Blanke algorithme
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE flo_oce         ! ocean drifting floats
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC flo_blk      ! routine called by floats.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flo_blk( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE flo_blk  ***
+      !!           
+      !! ** Purpose :   Compute the geographical position,latitude, longitude
+      !!      and depth of each float at each time step.
+      !! 
+      !! ** Method  :   The position of a float is computed with Bruno Blanke
+      !!      algorithm. We need to know the velocity field, the old positions
+      !!      of the floats and the grid defined on the domain.
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt ! ocean time step
+
+      !! * Local declarations
+      INTEGER :: jfl              ! dummy loop arguments
+      INTEGER :: ind, ifin, iloop
+      INTEGER , DIMENSION ( jpnfl )  ::   &
+         iil, ijl, ikl,             &     ! index of nearest mesh
+         iiloc , ijloc,             &
+         iiinfl, ijinfl, ikinfl,    &     ! index of input mesh of the float.
+         iioutfl, ijoutfl, ikoutfl        ! index of output mesh of the float.
+      REAL(wp) , DIMENSION ( jpnfl )  ::    &
+         zgifl, zgjfl, zgkfl,       &     ! position of floats, index on 
+                                          ! velocity mesh.
+         ztxfl, ztyfl, ztzfl,       &     ! time for a float to quit the mesh
+                                          ! across one of the face x,y and z 
+         zttfl,                     &     ! time for a float to quit the mesh 
+         zagefl,                    &     ! time during which, trajectorie of 
+                                          ! the float has been computed
+         zagenewfl,                 &     ! new age of float after calculation 
+                                          ! of new position
+         zufl, zvfl, zwfl,          &     ! interpolated vel. at float position
+         zudfl, zvdfl, zwdfl,       &     ! velocity diff input/output of mesh
+         zgidfl, zgjdfl, zgkdfl           ! direction index of float 
+      REAL(wp)   ::       &
+         zuinfl,zvinfl,zwinfl,      &     ! transport across the input face
+         zuoutfl,zvoutfl,zwoutfl,   &     ! transport across the ouput face
+         zvol,                      &     ! volume of the mesh
+         zsurfz,                    &     ! surface of the face of the mesh 
+         zind
+      REAL(wp), DIMENSION ( 2 )  ::   &
+         zsurfx, zsurfy                   ! surface of the face of the mesh
+      !!---------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flo_blk : compute Blanke trajectories for floats '
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      ! Initialisation of parameters
+      
+      DO jfl = 1, jpnfl
+         ! ages of floats are put at zero
+         zagefl(jfl) = 0.
+         ! index on the velocity grid 
+         ! We considere k coordinate negative, with this transformation 
+         ! the computation in the 3 direction is the same. 
+         zgifl(jfl) = tpifl(jfl) - 0.5
+         zgjfl(jfl) = tpjfl(jfl) - 0.5
+         zgkfl(jfl) = MIN(-1.,-(tpkfl(jfl)))
+         ! surface drift every 10 days 
+         IF( ln_argo ) THEN
+            IF( MOD(kt,150) >= 146 .OR. MOD(kt,150) == 0 )  zgkfl(jfl) = -1.
+         ENDIF
+         ! index of T mesh
+         iil(jfl) = 1 + INT(zgifl(jfl))
+         ijl(jfl) = 1 + INT(zgjfl(jfl))
+         ikl(jfl) =     INT(zgkfl(jfl))
+      END DO
+       
+      iloop = 0
+222   DO jfl = 1, jpnfl
+# if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+         IF( (iil(jfl) >= (mig(nldi)-jpizoom+1)) .AND. (iil(jfl) <= (mig(nlei)-jpizoom+1)) .AND.   &
+             (ijl(jfl) >= (mjg(nldj)-jpjzoom+1)) .AND. (ijl(jfl) <= (mjg(nlej)-jpjzoom+1)) ) THEN
+            iiloc(jfl) = iil(jfl) - (mig(1)-jpizoom+1) + 1
+            ijloc(jfl) = ijl(jfl) - (mjg(1)-jpjzoom+1) + 1
+# else 
+            iiloc(jfl) = iil(jfl)
+            ijloc(jfl) = ijl(jfl)
+# endif
+            
+            ! compute the transport across the mesh where the float is.            
+!!bug (gm) change e3t into fse3. but never checked 
+            zsurfx(1) = e2u(iiloc(jfl)-1,ijloc(jfl)  ) * fse3u(iiloc(jfl)-1,ijloc(jfl)  ,-ikl(jfl))
+            zsurfx(2) = e2u(iiloc(jfl)  ,ijloc(jfl)  ) * fse3u(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
+            zsurfy(1) = e1v(iiloc(jfl)  ,ijloc(jfl)-1) * fse3v(iiloc(jfl)  ,ijloc(jfl)-1,-ikl(jfl))
+            zsurfy(2) = e1v(iiloc(jfl)  ,ijloc(jfl)  ) * fse3v(iiloc(jfl)  ,ijloc(jfl)  ,-ikl(jfl))
+
+            ! for a isobar float zsurfz is put to zero. The vertical velocity will be zero too.
+            zsurfz = e1t(iiloc(jfl),ijloc(jfl)) * e2t(iiloc(jfl),ijloc(jfl))
+            zvol   = zsurfz * fse3t(iiloc(jfl),ijloc(jfl),-ikl(jfl))
+
+            !
+            zuinfl =( ub(iiloc(jfl)-1,ijloc(jfl),-ikl(jfl)) + un(iiloc(jfl)-1,ijloc(jfl),-ikl(jfl)) )/2.*zsurfx(1)
+            zuoutfl=( ub(iiloc(jfl)  ,ijloc(jfl),-ikl(jfl)) + un(iiloc(jfl)  ,ijloc(jfl),-ikl(jfl)) )/2.*zsurfx(2)
+            zvinfl =( vb(iiloc(jfl),ijloc(jfl)-1,-ikl(jfl)) + vn(iiloc(jfl),ijloc(jfl)-1,-ikl(jfl)) )/2.*zsurfy(1)
+            zvoutfl=( vb(iiloc(jfl),ijloc(jfl)  ,-ikl(jfl)) + vn(iiloc(jfl),ijloc(jfl)  ,-ikl(jfl)) )/2.*zsurfy(2)
+            zwinfl =-(wb(iiloc(jfl),ijloc(jfl),-(ikl(jfl)-1))    &
+               &   +  wn(iiloc(jfl),ijloc(jfl),-(ikl(jfl)-1)) )/2. *  zsurfz*nisobfl(jfl)
+            zwoutfl=-(wb(iiloc(jfl),ijloc(jfl),- ikl(jfl)   )   &
+               &   +  wn(iiloc(jfl),ijloc(jfl),- ikl(jfl)   ) )/2. *  zsurfz*nisobfl(jfl)
+            
+            ! interpolation of velocity field on the float initial position            
+            zufl(jfl)=  zuinfl  + ( zgifl(jfl) - float(iil(jfl)-1) ) * ( zuoutfl - zuinfl)
+            zvfl(jfl)=  zvinfl  + ( zgjfl(jfl) - float(ijl(jfl)-1) ) * ( zvoutfl - zvinfl)
+            zwfl(jfl)=  zwinfl  + ( zgkfl(jfl) - float(ikl(jfl)-1) ) * ( zwoutfl - zwinfl)
+            
+            ! faces of input and output
+            ! u-direction
+            IF( zufl(jfl) < 0. ) THEN
+               iioutfl(jfl) = iil(jfl) - 1.
+               iiinfl (jfl) = iil(jfl)
+               zind   = zuinfl
+               zuinfl = zuoutfl
+               zuoutfl= zind
+            ELSE
+               iioutfl(jfl) = iil(jfl)
+               iiinfl (jfl) = iil(jfl) - 1
+            ENDIF
+            ! v-direction       
+            IF( zvfl(jfl) < 0. ) THEN
+               ijoutfl(jfl) = ijl(jfl) - 1.
+               ijinfl (jfl) = ijl(jfl)
+               zind    = zvinfl
+               zvinfl  = zvoutfl
+               zvoutfl = zind
+            ELSE
+               ijoutfl(jfl) = ijl(jfl)
+               ijinfl (jfl) = ijl(jfl) - 1.
+            ENDIF
+            ! w-direction
+            IF( zwfl(jfl) < 0. ) THEN
+               ikoutfl(jfl) = ikl(jfl) - 1.
+               ikinfl (jfl) = ikl(jfl)
+               zind    = zwinfl
+               zwinfl  = zwoutfl
+               zwoutfl = zind
+            ELSE
+               ikoutfl(jfl) = ikl(jfl)
+               ikinfl (jfl) = ikl(jfl) - 1.
+            ENDIF
+            
+            ! compute the time to go out the mesh across a face
+            ! u-direction
+            zudfl (jfl) = zuoutfl - zuinfl
+            zgidfl(jfl) = float(iioutfl(jfl) - iiinfl(jfl))
+            IF( zufl(jfl)*zuoutfl <= 0. ) THEN
+               ztxfl(jfl) = 1.E99
+            ELSE
+               IF( ABS(zudfl(jfl)) >= 1.E-5 ) THEN
+                  ztxfl(jfl)= zgidfl(jfl)/zudfl(jfl) * LOG(zuoutfl/zufl (jfl))
+               ELSE
+                  ztxfl(jfl)=(float(iioutfl(jfl))-zgifl(jfl))/zufl(jfl)
+               ENDIF
+               IF( (ABS(zgifl(jfl)-float(iiinfl (jfl))) <=  1.E-7) .OR.   &
+                   (ABS(zgifl(jfl)-float(iioutfl(jfl))) <=  1.E-7) ) THEN
+                  ztxfl(jfl)=(zgidfl(jfl))/zufl(jfl)
+               ENDIF
+            ENDIF
+            ! v-direction
+            zvdfl (jfl) = zvoutfl - zvinfl
+            zgjdfl(jfl) = float(ijoutfl(jfl)-ijinfl(jfl))
+            IF( zvfl(jfl)*zvoutfl <= 0. ) THEN
+               ztyfl(jfl) = 1.E99
+            ELSE
+               IF( ABS(zvdfl(jfl)) >= 1.E-5 ) THEN
+                  ztyfl(jfl) = zgjdfl(jfl)/zvdfl(jfl) * LOG(zvoutfl/zvfl (jfl))
+               ELSE
+                  ztyfl(jfl) = (float(ijoutfl(jfl)) - zgjfl(jfl))/zvfl(jfl)
+               ENDIF
+               IF( (ABS(zgjfl(jfl)-float(ijinfl (jfl))) <= 1.E-7) .OR.   &
+                   (ABS(zgjfl(jfl)-float(ijoutfl(jfl))) <=  1.E-7) ) THEN
+                  ztyfl(jfl) = (zgjdfl(jfl)) / zvfl(jfl)
+               ENDIF
+            ENDIF
+            ! w-direction        
+            IF( nisobfl(jfl) == 1. ) THEN 
+               zwdfl (jfl) = zwoutfl - zwinfl
+               zgkdfl(jfl) = float(ikoutfl(jfl) - ikinfl(jfl))
+               IF( zwfl(jfl)*zwoutfl <= 0. ) THEN
+                  ztzfl(jfl) = 1.E99
+               ELSE
+                  IF( ABS(zwdfl(jfl)) >= 1.E-5 ) THEN
+                     ztzfl(jfl) = zgkdfl(jfl)/zwdfl(jfl) * LOG(zwoutfl/zwfl (jfl))
+                  ELSE
+                     ztzfl(jfl) = (float(ikoutfl(jfl)) - zgkfl(jfl))/zwfl(jfl)
+                  ENDIF
+                  IF( (ABS(zgkfl(jfl)-float(ikinfl (jfl))) <=  1.E-7) .OR.   &
+                      (ABS(zgkfl(jfl)-float(ikoutfl(jfl))) <= 1.E-7) ) THEN
+                     ztzfl(jfl) = (zgkdfl(jfl)) / zwfl(jfl)
+                  ENDIF
+               ENDIF
+            ENDIF
+            
+            ! the time to go leave the mesh is the smallest time
+                   
+            IF( nisobfl(jfl) == 1. ) THEN 
+               zttfl(jfl) = MIN(ztxfl(jfl),ztyfl(jfl),ztzfl(jfl))
+            ELSE
+               zttfl(jfl) = MIN(ztxfl(jfl),ztyfl(jfl))
+            ENDIF
+            ! new age of the FLOAT
+            zagenewfl(jfl) = zagefl(jfl) + zttfl(jfl)*zvol
+            ! test to know if the "age" of the float is not bigger than the 
+            ! time step
+            IF( zagenewfl(jfl) > rdt ) THEN
+               zttfl(jfl) = (rdt-zagefl(jfl)) / zvol
+               zagenewfl(jfl) = rdt
+            ENDIF
+            
+            ! In the "minimal" direction we compute the index of new mesh
+            ! on i-direction
+            IF( ztxfl(jfl) <=  zttfl(jfl) ) THEN
+               zgifl(jfl) = float(iioutfl(jfl))
+               ind = iioutfl(jfl)
+               IF( iioutfl(jfl) >= iiinfl(jfl) ) THEN
+                  iioutfl(jfl) = iioutfl(jfl) + 1
+               ELSE
+                  iioutfl(jfl) = iioutfl(jfl) - 1
+               ENDIF
+               iiinfl(jfl) = ind
+            ELSE
+               IF( ABS(zudfl(jfl)) >= 1.E-5 ) THEN 
+                  zgifl(jfl) = zgifl(jfl) + zgidfl(jfl)*zufl(jfl)    &
+                     &       * ( EXP( zudfl(jfl)/zgidfl(jfl)*zttfl(jfl) ) - 1. ) /  zudfl(jfl)
+               ELSE
+                  zgifl(jfl) = zgifl(jfl) + zufl(jfl) * zttfl(jfl)
+               ENDIF
+            ENDIF
+            ! on j-direction
+            IF( ztyfl(jfl) <= zttfl(jfl) ) THEN
+               zgjfl(jfl) = float(ijoutfl(jfl))
+               ind = ijoutfl(jfl)
+               IF( ijoutfl(jfl) >= ijinfl(jfl) ) THEN
+                  ijoutfl(jfl) = ijoutfl(jfl) + 1
+               ELSE
+                  ijoutfl(jfl) = ijoutfl(jfl) - 1
+               ENDIF
+               ijinfl(jfl) = ind
+            ELSE
+               IF( ABS(zvdfl(jfl)) >= 1.E-5 ) THEN 
+                  zgjfl(jfl) = zgjfl(jfl)+zgjdfl(jfl)*zvfl(jfl)   &
+                     &       * ( EXP(zvdfl(jfl)/zgjdfl(jfl)*zttfl(jfl)) - 1. ) /  zvdfl(jfl)
+               ELSE
+                  zgjfl(jfl) = zgjfl(jfl)+zvfl(jfl)*zttfl(jfl)
+               ENDIF
+            ENDIF
+            ! on k-direction
+            IF( nisobfl(jfl) == 1. ) THEN
+               IF( ztzfl(jfl) <= zttfl(jfl) ) THEN
+                  zgkfl(jfl) = float(ikoutfl(jfl))
+                  ind = ikoutfl(jfl)
+                  IF( ikoutfl(jfl) >= ikinfl(jfl) ) THEN
+                     ikoutfl(jfl) = ikoutfl(jfl)+1
+                  ELSE
+                     ikoutfl(jfl) = ikoutfl(jfl)-1
+                  ENDIF
+                  ikinfl(jfl) = ind
+               ELSE
+                  IF( ABS(zwdfl(jfl)) >= 1.E-5 ) THEN 
+                     zgkfl(jfl) = zgkfl(jfl)+zgkdfl(jfl)*zwfl(jfl)    &
+                        &       * ( EXP(zwdfl(jfl)/zgkdfl(jfl)*zttfl(jfl)) - 1. ) /  zwdfl(jfl)
+                  ELSE
+                     zgkfl(jfl) = zgkfl(jfl)+zwfl(jfl)*zttfl(jfl)
+                  ENDIF
+               ENDIF
+            ENDIF
+            
+            ! coordinate of the new point on the temperature grid
+            
+            iil(jfl) = MAX(iiinfl(jfl),iioutfl(jfl))
+            ijl(jfl) = MAX(ijinfl(jfl),ijoutfl(jfl))
+            IF( nisobfl(jfl) ==  1 ) ikl(jfl) = MAX(ikinfl(jfl),ikoutfl(jfl))
+!!Alexcadm	 write(*,*)'PE ',narea,
+!!Alexcadm     .    iiinfl(jfl),iioutfl(jfl),ijinfl(jfl)
+!!Alexcadm     .		,ijoutfl(jfl),ikinfl(jfl),
+!!Alexcadm     .	  ikoutfl(jfl),ztxfl(jfl),ztyfl(jfl)
+!!Alexcadm     .		,ztzfl(jfl),zgifl(jfl),
+!!Alexcadm     .  zgjfl(jfl) 
+!!Alexcadm	IF (jfl == 910) write(*,*)'Flotteur 910',
+!!Alexcadm     .    iiinfl(jfl),iioutfl(jfl),ijinfl(jfl)
+!!Alexcadm     .		,ijoutfl(jfl),ikinfl(jfl),
+!!Alexcadm     .	  ikoutfl(jfl),ztxfl(jfl),ztyfl(jfl)
+!!Alexcadm     .		,ztzfl(jfl),zgifl(jfl),
+!!Alexcadm     .  zgjfl(jfl) 
+            ! reinitialisation of the age of FLOAT
+            zagefl(jfl) = zagenewfl(jfl)
+# if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+         ELSE
+            ! we put zgifl, zgjfl, zgkfl, zagefl
+            zgifl (jfl) = 0.
+            zgjfl (jfl) = 0.
+            zgkfl (jfl) = 0.
+            zagefl(jfl) = 0.
+            iil(jfl) = 0
+            ijl(jfl) = 0
+         ENDIF
+# endif
+      END DO
+      
+      ! synchronisation
+      IF( lk_mpp )   CALL mpp_sum( zgifl , jpnfl )   ! sums over the global domain
+      IF( lk_mpp )   CALL mpp_sum( zgjfl , jpnfl )
+      IF( lk_mpp )   CALL mpp_sum( zgkfl , jpnfl )
+      IF( lk_mpp )   CALL mpp_sum( zagefl, jpnfl )
+      IF( lk_mpp )   CALL mpp_sum( iil   , jpnfl )
+      IF( lk_mpp )   CALL mpp_sum( ijl   , jpnfl )
+      
+      ! in the case of open boundaries we need to test if the floats don't
+      ! go out of the domain. If it goes out, the float is put at the 
+      ! middle of the mesh in the domain but the trajectory isn't compute 
+      ! more time.      
+# if defined key_obc
+      DO jfl = 1, jpnfl
+         IF( lp_obc_east ) THEN
+            IF( jped <=  zgjfl(jfl) .AND. zgjfl(jfl) <= jpef .AND. nieob-1 <=  zgifl(jfl) ) THEN
+               zgifl (jfl) = INT(zgifl(jfl)) + 0.5
+               zgjfl (jfl) = INT(zgjfl(jfl)) + 0.5
+               zagefl(jfl) = rdt
+            END IF
+         END IF
+         IF( lp_obc_west ) THEN
+            IF( jpwd <= zgjfl(jfl) .AND. zgjfl(jfl) <= jpwf .AND. niwob >=  zgifl(jfl) ) THEN
+               zgifl (jfl) = INT(zgifl(jfl)) + 0.5
+               zgjfl (jfl) = INT(zgjfl(jfl)) + 0.5
+               zagefl(jfl) = rdt
+            END IF
+         END IF
+         IF( lp_obc_north ) THEN
+            IF( jpnd <=  zgifl(jfl) .AND. zgifl(jfl) <= jpnf .AND. njnob-1 >=  zgjfl(jfl) ) THEN
+               zgifl (jfl) = INT(zgifl(jfl)) + 0.5
+               zgjfl (jfl) = INT(zgjfl(jfl)) + 0.5
+               zagefl(jfl) = rdt
+            END IF
+         END IF
+         IF( lp_obc_south ) THEN
+            IF( jpsd <=  zgifl(jfl) .AND. zgifl(jfl) <= jpsf .AND.  njsob >= zgjfl(jfl) ) THEN
+               zgifl (jfl) = INT(zgifl(jfl)) + 0.5
+               zgjfl (jfl) = INT(zgjfl(jfl)) + 0.5
+               zagefl(jfl) = rdt
+            END IF
+         END IF
+      END DO
+#endif
+
+      ! Test to know if a  float hasn't integrated enought time
+      IF( ln_argo ) THEN
+         ifin = 1
+         DO jfl = 1, jpnfl
+            IF( zagefl(jfl) < rdt )   ifin = 0
+            tpifl(jfl) = zgifl(jfl) + 0.5
+            tpjfl(jfl) = zgjfl(jfl) + 0.5
+         END DO
+      ELSE
+         ifin = 1
+         DO jfl = 1, jpnfl
+            IF( zagefl(jfl) < rdt )   ifin = 0
+            tpifl(jfl) = zgifl(jfl) + 0.5
+            tpjfl(jfl) = zgjfl(jfl) + 0.5
+            IF( nisobfl(jfl) == 1 ) tpkfl(jfl) = -(zgkfl(jfl))
+         END DO
+      ENDIF
+!!Alexcadm	IF (lwp) write(numout,*) '---------'
+!!Alexcadm	IF (lwp) write(numout,*) 'before Erika:',tpifl(880),tpjfl(880),
+!!Alexcadm     .       tpkfl(880),zufl(880),zvfl(880),zwfl(880)
+!!Alexcadm	IF (lwp) write(numout,*) 'first Erika:',tpifl(900),tpjfl(900),
+!!Alexcadm     .       tpkfl(900),zufl(900),zvfl(900),zwfl(900)
+!!Alexcadm	IF (lwp) write(numout,*) 'last Erika:',tpifl(jpnfl),tpjfl(jpnfl),
+!!Alexcadm     .       tpkfl(jpnfl),zufl(jpnfl),zvfl(jpnfl),zwfl(jpnfl)
+      IF( ifin == 0 ) THEN
+         iloop = iloop + 1 
+         GO TO 222
+      ENDIF
+
+   END SUBROUTINE flo_blk
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flo_blk                  ! Empty routine
+   END SUBROUTINE flo_blk 
+#endif
+   
+   !!======================================================================
+END MODULE floblk 
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flodom.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flodom.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flodom.F90	(revision 4536)
@@ -0,0 +1,468 @@
+MODULE flodom
+   !!======================================================================
+   !!                       ***  MODULE  flodom  ***
+   !! Ocean floats :   domain
+   !!======================================================================
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                     float trajectories
+   !!----------------------------------------------------------------------
+   !!   flo_dom        : initialization of floats
+   !!   findmesh       : compute index of position 
+   !!   dstnce         : compute distance between face mesh and floats 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE flo_oce         ! ocean drifting floats
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+
+   !! * Accessibility
+   PRIVATE  dstnce
+   PUBLIC flo_dom     ! routine called by floats.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/FLO/flodom.F90,v 1.7 2007/06/29 17:01:51 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flo_dom
+      !! ---------------------------------------------------------------------
+      !!                  ***  ROUTINE flo_dom  ***
+      !!                 
+      !!  ** Purpose :   Initialisation of floats
+      !!
+      !!  ** Method  :   We put the floats  in the domain with the latitude,
+      !!       the longitude (degree) and the depth (m).
+      !!
+      !!----------------------------------------------------------------------      
+      !! * Local declarations
+      LOGICAL  :: llinmesh
+      CHARACTER (len=21) ::  clname
+      INTEGER  :: ji, jj, jk               ! DO loop index on 3 directions
+      INTEGER  :: jfl, jfl1                ! number of floats   
+      INTEGER  :: inum                     ! logical unit for file read
+      INTEGER, DIMENSION ( jpnfl    )  ::   &
+         iimfl, ijmfl, ikmfl,    &          ! index mesh of floats
+         idomfl,  ivtest, ihtest
+      REAL(wp) :: zdxab, zdyad
+      REAL(wp), DIMENSION ( jpnnewflo+1 )  :: zgifl, zgjfl,  zgkfl
+      !!---------------------------------------------------------------------
+      
+      ! Initialisation with the geographical position or restart
+      
+      IF(lwp) WRITE(numout,*) 'flo_dom : compute initial position of floats'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+      IF(lwp) WRITE(numout,*) '           jpnfl = ',jpnfl
+      
+      IF(ln_rstflo) THEN
+         IF(lwp) WRITE(numout,*) '        float restart file read'
+         
+         ! open the restart file 
+         clname='restart_float'
+         CALL ctlopn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, lwp, 1 )
+         REWIND inum
+
+         ! read of the restart file
+         READ(inum) ( tpifl  (jfl), jfl=1, jpnrstflo),   & 
+                        ( tpjfl  (jfl), jfl=1, jpnrstflo),   &
+                        ( tpkfl  (jfl), jfl=1, jpnrstflo),   &
+                        ( nisobfl(jfl), jfl=1, jpnrstflo),   &
+                        ( ngrpfl (jfl), jfl=1, jpnrstflo)    
+         CLOSE(inum)
+
+         ! if we want a  surface drift  ( like PROVOR floats )
+         IF( ln_argo ) THEN
+            DO jfl = 1, jpnrstflo
+               nisobfl(jfl) = 0
+            END DO
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)' flo_dom: END of florstlec'
+         
+         ! It is possible to add new floats.          
+         IF(lwp) WRITE(numout,*)' flo_dom:jpnfl jpnrstflo ',jpnfl,jpnrstflo
+         IF( jpnfl > jpnrstflo ) THEN
+            ! open the init file 
+            clname='init_float'
+            CALL ctlopn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+               &         1, numout, .TRUE., 1 )
+            DO jfl = jpnrstflo+1, jpnfl
+               READ(inum,*) flxx(jfl),flyy(jfl),flzz(jfl), nisobfl(jfl),ngrpfl(jfl),jfl1
+            END DO
+            CLOSE(inum)
+            IF(lwp) WRITE(numout,*)' flodom: END reading init_float file'
+            
+            ! Test to find the grid point coordonate with the geographical position            
+            DO jfl = jpnrstflo+1, jpnfl
+               ihtest(jfl) = 0
+               ivtest(jfl) = 0
+               ikmfl(jfl) = 0
+# if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+               DO ji = MAX(nldi,2), nlei
+                  DO jj = MAX(nldj,2), nlej
+# else
+               DO ji = 2, jpi
+                  DO jj = 2, jpj
+# endif                     
+                     ! For each float we find the indexes of the mesh                      
+                     CALL findmesh(glamf(ji-1,jj-1),gphif(ji-1,jj-1),   &
+                                   glamf(ji-1,jj  ),gphif(ji-1,jj  ),   &
+                                   glamf(ji  ,jj  ),gphif(ji  ,jj  ),   &
+                                   glamf(ji  ,jj-1),gphif(ji  ,jj-1),   &
+                                   flxx(jfl)       ,flyy(jfl)       ,   &
+                                   glamt(ji  ,jj  ),gphit(ji  ,jj  ), llinmesh)
+                     IF(llinmesh) THEN
+                        iimfl(jfl) = ji
+                        ijmfl(jfl) = jj
+                        ihtest(jfl) = ihtest(jfl)+1
+                        DO jk = 1, jpk-1
+                           IF( (fsdepw(ji,jj,jk) <= flzz(jfl)) .AND. (fsdepw(ji,jj,jk+1) > flzz(jfl)) ) THEN
+                              ikmfl(jfl) = jk
+                              ivtest(jfl) = ivtest(jfl) + 1
+                           ENDIF
+                        END DO
+                     ENDIF
+                  END DO
+               END DO
+               IF(lwp) WRITE(numout,*)'   flo_dom: END findmesh'
+               
+               ! If the float is in a mesh computed by an other processor we put iimfl=ijmfl=-1               
+               IF( ihtest(jfl) ==  0 ) THEN
+                  iimfl(jfl) = -1
+                  ijmfl(jfl) = -1
+               ENDIF
+            END DO
+            
+            ! A zero in the sum of the arrays "ihtest" and "ivtest"             
+# if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+            CALL mpp_sum(ihtest,jpnfl)
+            CALL mpp_sum(ivtest,jpnfl)
+# endif 
+            DO jfl = jpnrstflo+1, jpnfl
+               IF( (ihtest(jfl) > 1 ) .OR. ( ivtest(jfl) > 1) ) THEN
+                  IF(lwp) WRITE(numout,*) 'THE FLOAT',jfl,' IS NOT IN ONLY ONE MESH'
+                  STOP
+               ENDIF
+               IF( (ihtest(jfl) == 0) ) THEN
+                  IF(lwp) WRITE(numout,*)'THE FLOAT',jfl,' IS IN NO MESH'
+                  STOP
+               ENDIF
+            END DO
+            
+            ! We compute the distance between the float and the face of the mesh            
+            DO jfl = jpnrstflo+1, jpnfl               
+               ! Made only if the float is in the domain of the processor              
+               IF( (iimfl(jfl) >= 0) .AND. (ijmfl(jfl) >= 0) ) THEN
+                  
+                  ! TEST TO KNOW IF THE FLOAT IS NOT INITIALISED IN THE COAST
+                  
+                  idomfl(jfl) = 0
+                  IF( tmask(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) == 0. ) idomfl(jfl) = 1
+                                           
+                  ! Computation of the distance between the float and the faces of the mesh
+                  !            zdxab
+                  !             .
+                  !        B----.---------C
+                  !        |    .         |
+                  !        |<------>flo   |
+                  !        |        ^     |
+                  !        |        |.....|....zdyad
+                  !        |        |     |
+                  !        A--------|-----D
+                  !
+             
+                  zdxab = dstnce( flxx(jfl), flyy(jfl), glamf(iimfl(jfl)-1,ijmfl(jfl)-1), flyy(jfl) )
+                  zdyad = dstnce( flxx(jfl), flyy(jfl), flxx(jfl), gphif(iimfl(jfl)-1,ijmfl(jfl)-1) )
+                  
+                  ! Translation of this distances (in meter) in indexes
+                  
+                  zgifl(jfl-jpnrstflo)= (iimfl(jfl)-0.5) + zdxab/e1u(iimfl(jfl)-1,ijmfl(jfl)) + (mig(1)-jpizoom)
+                  zgjfl(jfl-jpnrstflo)= (ijmfl(jfl)-0.5) + zdyad/e2v(iimfl(jfl),ijmfl(jfl)-1) + (mjg(1)-jpjzoom)
+                  zgkfl(jfl-jpnrstflo) = (( fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - flzz(jfl) )* ikmfl(jfl))   &
+                     &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
+                     &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl) ) )                             &
+                     &                 + (( flzz(jfl)-fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) ) *(ikmfl(jfl)+1))   &
+                     &                 / (  fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1)                              &
+                     &                    - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) )
+               ELSE
+                  zgifl(jfl-jpnrstflo) = 0.e0
+                  zgjfl(jfl-jpnrstflo) = 0.e0
+                  zgkfl(jfl-jpnrstflo) = 0.e0
+               ENDIF
+            END DO
+            
+            ! The sum of all the arrays zgifl, zgjfl, zgkfl give 3 arrays with the positions of all the floats.
+            IF( lk_mpp )   THEN
+               CALL mpp_sum( zgjfl, jpnnewflo )   ! sums over the global domain
+               CALL mpp_sum( zgkfl, jpnnewflo )
+               IF(lwp) WRITE(numout,*) (zgifl(jfl),jfl=1,jpnnewflo)
+               IF(lwp) WRITE(numout,*) (zgjfl(jfl),jfl=1,jpnnewflo)
+               IF(lwp) WRITE(numout,*) (zgkfl(jfl),jfl=1,jpnnewflo) 
+            ENDIF
+           
+            DO jfl = jpnrstflo+1, jpnfl
+               tpifl(jfl) = zgifl(jfl-jpnrstflo)
+               tpjfl(jfl) = zgjfl(jfl-jpnrstflo)
+               tpkfl(jfl) = zgkfl(jfl-jpnrstflo)
+            END DO
+         ENDIF
+      ELSE
+         IF(lwp) WRITE(numout,*) '                     init_float read '
+         
+         ! First initialisation of floats
+         ! the initials positions of floats are written in a file
+         ! with a variable to know if it is a isobar float a number 
+         ! to identified who want the trajectories of this float and 
+         ! an index for the number of the float         
+         ! open the init file 
+         clname='init_float'
+         CALL ctlopn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .TRUE., 1 )
+         READ(inum) (flxx(jfl)   , jfl=1, jpnfl),   &
+                    (flyy(jfl)   , jfl=1, jpnfl),   &
+                    (flzz(jfl)   , jfl=1, jpnfl),   &
+                    (nisobfl(jfl), jfl=1, jpnfl),   &
+                    (ngrpfl(jfl) , jfl=1, jpnfl)
+         CLOSE(inum)
+            
+         ! Test to find the grid point coordonate with the geographical position         
+         DO jfl = 1, jpnfl
+            ihtest(jfl) = 0
+            ivtest(jfl) = 0
+            ikmfl(jfl) = 0
+# if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+            DO ji = MAX(nldi,2), nlei
+               DO jj = MAX(nldj,2), nlej
+# else
+            DO ji = 2, jpi
+               DO jj = 2, jpj
+# endif                  
+                  ! for each float we find the indexes of the mesh 
+                  
+                  CALL findmesh(glamf(ji-1,jj-1),gphif(ji-1,jj-1),   &
+                                glamf(ji-1,jj  ),gphif(ji-1,jj  ),   &
+                                glamf(ji  ,jj  ),gphif(ji  ,jj  ),   &
+                                glamf(ji  ,jj-1),gphif(ji  ,jj-1),   &
+                                flxx(jfl)       ,flyy(jfl)       ,   &
+                                glamt(ji  ,jj  ),gphit(ji  ,jj  ), llinmesh)
+                  IF(llinmesh) THEN
+                     iimfl(jfl)  = ji
+                     ijmfl(jfl)  = jj
+                     ihtest(jfl) = ihtest(jfl)+1
+                     DO jk = 1, jpk-1
+                        IF( (fsdepw(ji,jj,jk) <= flzz(jfl)) .AND. (fsdepw(ji,jj,jk+1) >  flzz(jfl)) ) THEN
+                           ikmfl(jfl)  = jk
+                           ivtest(jfl) = ivtest(jfl) + 1
+                        ENDIF
+                     END DO
+                  ENDIF
+               END DO
+            END DO
+            
+            ! If the float is in a mesh computed by an other processor we put iimfl=ijmfl=-1            
+            IF( ihtest(jfl) == 0 ) THEN
+               iimfl(jfl) = -1
+               ijmfl(jfl) = -1
+            ENDIF
+         END DO
+         
+         ! A zero in the sum of the arrays "ihtest" and "ivtest"          
+         IF( lk_mpp )   CALL mpp_sum(ihtest,jpnfl)   ! sums over the global domain
+         IF( lk_mpp )   CALL mpp_sum(ivtest,jpnfl)
+
+         DO jfl = 1, jpnfl
+            IF( (ihtest(jfl) > 1 ) .OR. ( ivtest(jfl) > 1 )) THEN
+               IF(lwp) WRITE(numout,*) 'THE FLOAT',jfl,' IS NOT IN ONLY ONE MESH'
+            ENDIF
+            IF( ihtest(jfl) == 0 ) THEN 
+               IF(lwp) WRITE(numout,*)'THE FLOAT',jfl,' IS IN NO MESH'
+            ENDIF
+         END DO
+        
+         ! We compute the distance between the float and the face of  the mesh         
+         DO jfl = 1, jpnfl
+            ! Made only if the float is in the domain of the processor
+            IF( (iimfl(jfl) >= 0 ) .AND. ( ijmfl(jfl) >= 0 ) ) THEN
+               
+               ! TEST TO KNOW IF THE FLOAT IS NOT INITIALISED IN THE COAST
+               
+               idomfl(jfl) = 0
+               IF( tmask(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)) == 0. ) idomfl(jfl)=1
+               
+               ! Computation of the distance between the float
+               ! and the faces of the mesh
+               !            zdxab
+               !             .
+               !        B----.---------C
+               !        |    .         |
+               !        |<------>flo   |
+               !        |        ^     |
+               !        |        |.....|....zdyad
+               !        |        |     |
+               !        A--------|-----D
+               
+               zdxab = dstnce(flxx(jfl),flyy(jfl),glamf(iimfl(jfl)-1,ijmfl(jfl)-1),flyy(jfl))                
+               zdyad = dstnce(flxx(jfl),flyy(jfl),flxx(jfl),gphif(iimfl(jfl)-1,ijmfl(jfl)-1))
+               
+               ! Translation of this distances (in meter) in indexes
+               
+               tpifl(jfl) = (iimfl(jfl)-0.5)+zdxab/ e1u(iimfl(jfl)-1,ijmfl(jfl))+(mig(1)-jpizoom)
+               tpjfl(jfl) = (ijmfl(jfl)-0.5)+zdyad/ e2v(iimfl(jfl),ijmfl(jfl)-1)+(mjg(1)-jpjzoom)
+               tpkfl(jfl) = (fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - flzz(jfl))*(ikmfl(jfl))                     &
+                          / (fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)))   &
+                          + (flzz(jfl) - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)))*(ikmfl(jfl)+1)                     &
+                          / (fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)+1) - fsdepw(iimfl(jfl),ijmfl(jfl),ikmfl(jfl)))
+            ELSE
+               tpifl (jfl) = 0.e0
+               tpjfl (jfl) = 0.e0
+               tpkfl (jfl) = 0.e0
+               idomfl(jfl) = 0
+            ENDIF
+         END DO
+         
+         ! The sum of all the arrays tpifl, tpjfl, tpkfl give 3 arrays with the positions of all the floats. 
+         IF( lk_mpp )   CALL mpp_sum( tpifl , jpnfl )   ! sums over the global domain
+         IF( lk_mpp )   CALL mpp_sum( tpjfl , jpnfl )
+         IF( lk_mpp )   CALL mpp_sum( tpkfl , jpnfl )
+         IF( lk_mpp )   CALL mpp_sum( idomfl, jpnfl )
+      ENDIF
+            
+      ! Print the initial positions of the floats
+      IF( .NOT. ln_rstflo ) THEN 
+         ! WARNING : initial position not in the sea         
+         DO jfl = 1, jpnfl
+            IF( idomfl(jfl) == 1 ) THEN
+               IF(lwp) WRITE(numout,*)'*****************************'
+               IF(lwp) WRITE(numout,*)'!!!!!!!  WARNING   !!!!!!!!!!'
+               IF(lwp) WRITE(numout,*)'*****************************'
+               IF(lwp) WRITE(numout,*)'The float number',jfl,'is out of the sea.'
+               IF(lwp) WRITE(numout,*)'geographical position',flxx(jfl),flyy(jfl),flzz(jfl)
+               IF(lwp) WRITE(numout,*)'index position',tpifl(jfl),tpjfl(jfl),tpkfl(jfl)
+            ENDIF
+         END DO
+      ENDIF
+
+   END SUBROUTINE flo_dom
+
+
+   SUBROUTINE findmesh( pax, pay, pbx, pby,   &
+                        pcx, pcy, pdx, pdy,   &
+                        px  ,py  ,ptx, pty, ldinmesh )
+      !! -------------------------------------------------------------
+      !!                ***  ROUTINE findmesh  ***
+      !!      
+      !! ** Purpose :   Find the index of mesh for the point spx spy
+      !!
+      !! ** Method  : 
+      !!
+      !! History :
+      !!   8.0  !  98-07 (Y.Drillet)  Original code
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp) ::   &
+         pax, pay, pbx, pby,    &     ! ???
+         pcx, pcy, pdx, pdy,    &     ! ???
+         px, py,                &     ! longitude and latitude
+         ptx, pty                     ! ???
+      LOGICAL ::  ldinmesh            ! ???
+
+      !! * local declarations
+      REAL(wp) ::   &
+         zabt, zbct, zcdt, zdat, zabpt, zbcpt, zcdpt, zdapt,  &
+         psax,psay,psbx,psby,psx,psy
+      REAL(wp) ::  fsline                ! Statement function
+
+      !! * Substitutions
+      fsline(psax, psay, psbx, psby, psx, psy) = psy  * ( psbx - psax )   &
+                                               - psx  * ( psby - psay )   &
+                                               + psax *   psby - psay * psbx
+      !!---------------------------------------------------------------------
+      
+      ! 4 semi plane defined by the 4 points and including the T point
+      zabt = fsline(pax,pay,pbx,pby,ptx,pty)
+      zbct = fsline(pbx,pby,pcx,pcy,ptx,pty)
+      zcdt = fsline(pcx,pcy,pdx,pdy,ptx,pty)
+      zdat = fsline(pdx,pdy,pax,pay,ptx,pty)
+      
+      ! 4 semi plane defined by the 4 points and including the extrememity
+      zabpt = fsline(pax,pay,pbx,pby,px,py)
+      zbcpt = fsline(pbx,pby,pcx,pcy,px,py)
+      zcdpt = fsline(pcx,pcy,pdx,pdy,px,py)
+      zdapt = fsline(pdx,pdy,pax,pay,px,py)
+       
+      ! We compare the semi plane T with the semi plane including the point
+      ! to know if it is in this  mesh.
+      ! For numerical reasons it is possible that for a point which is on
+      ! the line we don't have exactly zero with fsline function. We want 
+      ! that a point can't be in 2 mesh in the same time, so we put the 
+      ! coefficient to zero if it is smaller than 1.E-12
+      
+      IF( ABS(zabpt) <= 1.E-12 ) zabpt = 0.
+      IF( ABS(zbcpt) <= 1.E-12 ) zbcpt = 0.
+      IF( ABS(zcdpt) <= 1.E-12 ) zcdpt = 0.
+      IF( ABS(zdapt) <= 1.E-12 ) zdapt = 0.
+      IF( (zabt*zabpt >  0.) .AND. (zbct*zbcpt >= 0. ) .AND. ( zcdt*zcdpt >= 0. ) .AND. ( zdat*zdapt > 0. )   &
+         .AND. ( px <= MAX(pcx,pdx) ) .AND. ( px >= MIN(pax,pbx) )    &
+         .AND. ( py <= MAX(pby,pcy) ) .AND. ( py >= MIN(pay,pdy) ) ) THEN
+         ldinmesh=.TRUE.
+      ELSE
+         ldinmesh=.FALSE.
+      ENDIF
+
+   END SUBROUTINE findmesh
+
+
+   FUNCTION dstnce( pla1, phi1, pla2, phi2 )
+      !! -------------------------------------------------------------
+      !!                 ***  Function dstnce  ***
+      !!          
+      !! ** Purpose :   returns distance (in m) between two geographical
+      !!                points
+      !! ** Method  : 
+      !!         
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(in) ::   pla1, phi1, pla2, phi2   ! ???
+
+      !! * Local variables
+      REAL(wp) ::   dly1, dly2, dlx1, dlx2, dlx, dls, dld, dpi
+      REAL(wp) ::   dstnce
+      !!---------------------------------------------------------------------
+      
+      dpi  = 2.* ASIN(1.)
+      dls  = dpi / 180.
+      dly1 = phi1 * dls
+      dly2 = phi2 * dls
+      dlx1 = pla1 * dls
+      dlx2 = pla2 * dls
+
+      dlx = SIN(dly1) * SIN(dly2) + COS(dly1) * COS(dly2) * COS(dlx2-dlx1)
+ 
+      IF( ABS(dlx) > 1.0 ) dlx = 1.0
+
+      dld = ATAN(DSQRT( ( 1-dlx )/( 1+dlx ) )) * 222.24 / dls
+      dstnce = dld * 1000.
+
+   END FUNCTION dstnce
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flo_dom                 ! Empty routine
+   END SUBROUTINE flo_dom
+#endif
+
+   !!======================================================================
+END MODULE flodom
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flowri.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/FLO/flowri.F90	(revision 4536)
@@ -0,0 +1,321 @@
+MODULE flowri
+   !!======================================================================
+   !!                       ***  MODULE  flowri  ***
+   !! 
+   !!======================================================================
+#if   defined key_floats   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_floats'                                     float trajectories
+   !!----------------------------------------------------------------------
+   !!    flowri     : write trajectories of floats in file 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE flo_oce         ! ocean drifting floats
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE lib_mpp         ! distribued memory computing library
+   USE daymod
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+
+   !! * Accessibility
+   PRIVATE
+   PUBLIC flo_wri     ! routine called by floats.F90
+
+   !! * Module variables
+      INTEGER :: jfl              ! number of floats
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flo_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE flo_wri  ***
+      !!             
+      !! ** Purpose :   Write position of floats in "trajec_float" file
+      !!      and the temperature and salinity at this position
+      !!      
+      !! ** Method  :   The frequency is nwritefl
+      !!      
+      !!  History :
+      !!    8.0  !  99-09  (Y. Drillet)  Original code
+      !!         !  00-06  (J.-M. Molines)  Profiling floats for CLS 
+      !!    8.5  !  02-10  (A. Bozec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER  :: kt                               ! time step
+
+      !! * Local declarations
+      CHARACTER (len=21) ::  clname
+      INTEGER ::   inum            ! temporary logical unit for restart file
+      INTEGER  ::   &
+         iafl,ibfl,icfl,ia1fl,ib1fl,ic1fl,jfl,irecflo,   &
+         iafloc,ibfloc,ia1floc,ib1floc,   &
+         iafln, ibfln
+      INTEGER  ::    ic, jc , jpn
+      INTEGER, DIMENSION ( jpnij )  :: iproc
+
+      REAL(wp) :: zafl,zbfl,zcfl,zdtj
+      REAL(wp) :: zxxu, zxxu_01,zxxu_10, zxxu_11
+      REAL(wp), DIMENSION (jpk,jpnfl) :: ztemp, zsal
+      !!---------------------------------------------------------------------
+      
+      IF( kt == nit000 .OR. MOD( kt,nwritefl)== 0 ) THEN 
+
+         ! header of output floats file
+      
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'flo_wri : write in trajec_float file '
+            WRITE(numout,*) '~~~~~~~    '
+         ENDIF
+
+         ! open the file numflo 
+         clname='trajec_float'
+         CALL ctlopn( numflo, clname, 'UNKNOWN', 'UNFORMATTED', 'SEQUENTIAL',   &
+            &           1, numout, .FALSE., 1 )
+         !      REWIND numflo
+
+         IF( kt == nit000 ) THEN
+            irecflo = NINT( (nitend-nit000) / FLOAT(nwritefl) )
+            IF(lwp) WRITE(numflo)cexper,no,irecflo,jpnfl,nwritefl
+         ENDIF
+         zdtj = rdt / 86400.      !!bug   use of 86400 instead of the phycst parameter
+
+         ! translation of index position in geographical position
+
+         IF( lk_mpp ) THEN
+            DO jfl = 1, jpnfl
+               iafl  = INT ( tpifl(jfl) )
+               ibfl  = INT ( tpjfl(jfl) )
+               icfl  = INT ( tpkfl(jfl) )
+               iafln = NINT( tpifl(jfl) )
+               ibfln = NINT( tpjfl(jfl) )
+               ia1fl = iafl + 1
+               ib1fl = ibfl + 1
+               ic1fl = icfl + 1
+               zafl  = tpifl(jfl) - FLOAT( iafl )
+               zbfl  = tpjfl(jfl) - FLOAT( ibfl )
+               zcfl  = tpkfl(jfl) - FLOAT( icfl )
+               IF(   iafl >= mig(nldi)-jpizoom+1 .AND. iafl <= mig(nlei)-jpizoom+1 .AND.   &
+                  &  ibfl >= mjg(nldj)-jpjzoom+1 .AND. ibfl <= mjg(nlej)-jpjzoom+1       ) THEN
+
+                  ! local index
+
+                  iafloc  = iafl -(mig(1)-jpizoom+1) + 1
+                  ibfloc  = ibfl -(mjg(1)-jpjzoom+1) + 1
+                  ia1floc = iafloc + 1
+                  ib1floc = ibfloc + 1
+
+                  flyy(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc)   &
+                     &      +     zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) +     zafl  * zbfl * gphit(ia1floc,ib1floc)
+                  flxx(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc)   &
+                     &      +     zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) +     zafl  * zbfl * glamt(ia1floc,ib1floc)
+                  flzz(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)
+
+                  ! Change  by Alexandra Bozec et Jean-Philippe Boulanger
+                  ! We save  the instantaneous profile of T and S of the column     
+                  ! ztemp(jfl)=tn(iafloc,ibfloc,icfl)
+                  ! zsal(jfl)=sn(iafloc,ibfloc,icfl)
+                  ztemp(1:jpk,jfl) = tn(iafloc,ibfloc,1:jpk)
+                  zsal (1:jpk,jfl) = sn(iafloc,ibfloc,1:jpk)            
+               ELSE
+                  flxx(jfl) = 0.
+                  flyy(jfl) = 0.
+                  flzz(jfl) = 0.
+                  ztemp(1:jpk,jfl) = 0.
+                  zsal (1:jpk,jfl) = 0.
+               ENDIF
+            END DO
+
+            CALL mpp_sum( flxx, jpnfl )   ! sums over the global domain
+            CALL mpp_sum( flyy, jpnfl )
+            CALL mpp_sum( flzz, jpnfl )
+            ! these 2 lines have accendentaly been removed from ATL6-V8 run hence
+            ! giving 0 salinity and temperature on the float trajectory
+!bug RB
+!compilation failed in mpp
+!            CALL mpp_sum( ztemp, jpk*jpnfl )
+!            CALL mpp_sum( zsal , jpk*jpnfl )
+
+         ELSE
+            DO jfl = 1, jpnfl
+               iafl  = INT (tpifl(jfl))
+               ibfl  = INT (tpjfl(jfl))
+               icfl  = INT (tpkfl(jfl))
+               iafln = NINT(tpifl(jfl))
+               ibfln = NINT(tpjfl(jfl))
+               ia1fl = iafl+1
+               ib1fl = ibfl+1
+               ic1fl = icfl+1
+               zafl  = tpifl(jfl) - FLOAT(iafl)
+               zbfl  = tpjfl(jfl) - FLOAT(ibfl)
+               zcfl  = tpkfl(jfl) - FLOAT(icfl)
+               iafloc  = iafl
+               ibfloc  = ibfl
+               ia1floc = iafloc + 1
+               ib1floc = ibfloc + 1
+               !
+               flyy(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc)   &
+                         +     zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) +     zafl  * zbfl * gphit(ia1floc,ib1floc)
+               flxx(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc)   &
+                         +     zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) +     zafl  * zbfl * glamt(ia1floc,ib1floc)
+               flzz(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)
+               !ALEX
+               ! Astuce pour ne pas avoir des flotteurs qui se baladent sur IDL
+               zxxu_11 = glamt(iafloc ,ibfloc )
+               zxxu_10 = glamt(iafloc ,ib1floc)
+               zxxu_01 = glamt(ia1floc,ibfloc )
+               zxxu    = glamt(ia1floc,ib1floc)
+
+               IF( iafloc == 52 )  zxxu_10 = -181
+               IF( iafloc == 52 )  zxxu_11 = -181
+               flxx(jfl)=(1.-zafl)*(1.-zbfl)* zxxu_11 + (1.-zafl)*    zbfl * zxxu_10   &
+                        +    zafl *(1.-zbfl)* zxxu_01 +     zafl *    zbfl * zxxu
+               !ALEX         
+               ! Change  by Alexandra Bozec et Jean-Philippe Boulanger
+               ! We save  the instantaneous profile of T and S of the column     
+               !     ztemp(jfl)=tn(iafloc,ibfloc,icfl)
+               !     zsal(jfl)=sn(iafloc,ibfloc,icfl)
+               ztemp(1:jpk,jfl) = tn(iafloc,ibfloc,1:jpk)
+               zsal (1:jpk,jfl) = sn(iafloc,ibfloc,1:jpk)
+            END DO
+         ENDIF
+
+         !
+         WRITE(numflo) flxx,flyy,flzz,nisobfl,ngrpfl,ztemp,zsal, FLOAT(ndastp)
+      !!
+      !! case when profiles are dumped. In order to save memory, dumps are
+      !! done level by level.
+      !      IF (mod(kt,nflclean) == 0.) THEN
+      !!     IF ( nwflo == nwprofil ) THEN
+      !        DO jk = 1,jpk
+      !         DO jfl=1,jpnfl
+      !         iafl= INT(tpifl(jfl))
+      !         ibfl=INT(tpjfl(jfl))
+      !         iafln=NINT(tpifl(jfl))
+      !         ibfln=NINT(tpjfl(jfl))
+      !# if defined key_mpp_mpi   ||   defined key_mpp_shmem
+      !        IF ( (iafl >= (mig(nldi)-jpizoom+1)) .AND.
+      !     $       (iafl <= (mig(nlei)-jpizoom+1)) .AND.
+      !     $       (ibfl >= (mjg(nldj)-jpjzoom+1)) .AND.
+      !     $       (ibfl <= (mjg(nlej)-jpjzoom+1)) ) THEN
+      !!
+      !! local index
+      !!
+      !         iafloc=iafln-(mig(1)-jpizoom+1)+1
+      !         ibfloc=ibfln-(mjg(1)-jpjzoom+1)+1
+      !!         IF (jk == 1 ) THEN
+      !!      PRINT *,'<<<>>> ',jfl,narea, iafloc ,ibfloc, iafln, ibfln,adatrj
+      !!         ENDIF
+      !# else
+      !         iafloc=iafln
+      !         ibfloc=ibfln
+      !# endif
+      !         ztemp(jfl)=tn(iafloc,ibfloc,jk)
+      !         zsal(jfl)=sn(iaflo!,ibfloc,jk)
+      !# if defined key_mpp_mpi   ||   defined key_mpp_shmem
+      !        ELSE
+      !         ztemp(jfl) = 0.
+      !         zsal(jfl) = 0.
+      !        ENDIF
+      !# endif
+      !! ... next float
+      !        END DO
+      !      IF( lk_mpp )   CALL mpp_sum( ztemp, jpnfl )
+      !      IF( lk_mpp )   CALL mpp_sum( zsal , jpnfl )
+      !
+      !      IF (lwp) THEN 
+      !         WRITE(numflo) ztemp, zsal
+      !      ENDIF
+      !! ... next level jk
+      !      END DO
+      !! ... reset nwflo to 0 for ALL processors, if profile has been written
+      !!       nwflo = 0
+      !      ENDIF
+      !!
+      !      CALL flush (numflo)
+      !! ... time of dumping floats
+      !!      END IF
+      ENDIF
+      
+      IF( (MOD(kt,nstockfl) == 0) .OR. ( kt == nitend ) ) THEN 
+         ! Writing the restart file 
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'flo_wri : write in  restart_float file '
+            WRITE(numout,*) '~~~~~~~    '
+         ENDIF
+
+         ! file is opened and closed every time it is used.
+
+         clname = 'restart.float.'
+         ic = 1
+         DO jc = 1, 16
+            IF( cexper(jc:jc) /= ' ' ) ic = jc
+         END DO
+         clname = clname(1:14)//cexper(1:ic)
+         ic = 1
+         DO jc = 1, 48
+            IF( clname(jc:jc) /= ' ' ) ic = jc
+         END DO
+
+         CALL ctlopn( inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &           1, numout, .FALSE., 0 )
+         REWIND inum
+         !
+         DO jpn = 1, jpnij
+            iproc(jpn) = 0
+         END DO
+         !
+         IF(lwp) THEN
+            REWIND(inum)
+            WRITE (inum) tpifl,tpjfl,tpkfl,nisobfl,ngrpfl
+            CLOSE (inum) 
+         ENDIF
+         !
+         ! Compute the number of trajectories for each processor
+         !
+         IF( lk_mpp ) THEN
+            DO jfl = 1, jpnfl
+               IF( (INT(tpifl(jfl)) >= (mig(nldi)-jpizoom+1)) .AND.   &
+                  &(INT(tpifl(jfl)) <= (mig(nlei)-jpizoom+1)) .AND.   &
+                  &(INT(tpjfl(jfl)) >= (mjg(nldj)-jpjzoom+1)) .AND.   &
+                  &(INT(tpjfl(jfl)) <= (mjg(nlej)-jpjzoom+1)) ) THEN
+                  iproc(narea) = iproc(narea)+1
+               ENDIF
+            END DO
+            CALL mpp_sum( iproc, jpnij )
+            !
+            IF(lwp) THEN 
+               WRITE(numout,*) 'DATE',adatrj
+               DO jpn = 1, jpnij
+                  IF( iproc(jpn) /= 0 ) THEN
+                     WRITE(numout,*)'PROCESSOR',jpn-1,'compute',iproc(jpn), 'trajectories.'
+                  ENDIF
+               END DO
+            ENDIF
+         ENDIF
+      ENDIF 
+
+   END SUBROUTINE flo_wri
+
+#  else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flo_wri                 ! Empty routine
+   END SUBROUTINE flo_wri
+#endif
+   
+   !!======================================================================
+END MODULE flowri
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4536)
@@ -0,0 +1,176 @@
+MODULE in_out_manager   
+   !!======================================================================
+   !!                       ***  MODULE  in_out_manager  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the tke 
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !! History :   8.5  !  02-06  (G. Madec)  original code
+   !!             9.0  !  06-07  (S. Masson)  iom, add ctl_stop, ctl_warn
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
+   !!   ctl_warn   : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE par_kind
+   USE par_oce
+   USE lib_print         ! formated print library
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !!                   namrun namelist parameters
+   !!----------------------------------------------------------------------
+   CHARACTER (len=16) ::   cexper     = "exp0"    !: experiment name used for output filename
+   LOGICAL            ::   ln_rstart  = .FALSE.   !: start from (F) rest or (T) a restart file
+   INTEGER            ::   no         = 0         !: job number
+   INTEGER            ::   nrstdt     = 0         !: control of the time step (0, 1 or 2)
+   INTEGER            ::   nn_rstssh  = 0         !: hand made initilization of ssh or not (1/0)
+   INTEGER            ::   nit000     = 1         !: index of the first time step
+   INTEGER            ::   nitend     = 10        !: index of the last time step
+   INTEGER            ::   ndate0     = 961115    !: initial calendar date aammjj
+   INTEGER            ::   nleapy     = 0         !: Leap year calendar flag (0/1 or 30)
+   INTEGER            ::   ninist     = 0         !: initial state output flag (0/1)
+   LOGICAL            ::   ln_dimgnnn = .FALSE.   !: type of dimgout. (F): 1 file for all proc
+                                                  !:                  (T): 1 file per proc
+   !!----------------------------------------------------------------------
+   !! was in restart but moved here because of the OFF line... better solution should be found...
+   !!----------------------------------------------------------------------
+   INTEGER            ::   nitrst                 !: time step at which restart file should be written
+   !!----------------------------------------------------------------------
+   !!                    output monitoring
+   !!----------------------------------------------------------------------
+   LOGICAL            ::   ln_ctl     = .FALSE.   !: run control for debugging
+   INTEGER            ::   nstock     =   10      !: restart file frequency
+   INTEGER            ::   nprint     =    0      !: level of print (0 no print)
+   INTEGER            ::   nwrite     =   10      !: restart file frequency
+   INTEGER            ::   nictls     =    0      !: Start i indice for the SUM control
+   INTEGER            ::   nictle     =    0      !: End   i indice for the SUM control
+   INTEGER            ::   njctls     =    0      !: Start j indice for the SUM control
+   INTEGER            ::   njctle     =    0      !: End   j indice for the SUM control
+   INTEGER            ::   isplt      =    1      !: number of processors following i
+   INTEGER            ::   jsplt      =    1      !: number of processors following j
+   INTEGER            ::   ijsplt     =    1      !: nb of local domain = nb of processors
+   INTEGER            ::   nbench     =    0      !: benchmark parameter (0/1)
+   INTEGER            ::   nbit_cmp   =    0      !: bit reproducibility  (0/1)
+   !!----------------------------------------------------------------------
+   !!                        logical units
+   !!----------------------------------------------------------------------
+   INTEGER            ::   numstp                 !: logical unit for time step
+   INTEGER            ::   numout                 !: logical unit for output print
+   INTEGER            ::   numnam                 !: logical unit for namelist
+   INTEGER            ::   numnam_ice             !: logical unit for ice namelist
+   INTEGER            ::   numevo_ice             !: logical unit for ice variables (temp. evolution)
+   INTEGER            ::   numsol                 !: logical unit for solver statistics
+   INTEGER            ::   numwri                 !: logical unit for output write
+   INTEGER            ::   numisp                 !: logical unit for island statistics
+   INTEGER            ::   numgap                 !: logical unit for differences diagnostic
+   INTEGER            ::   numbol                 !: logical unit for "bol" diagnostics
+   INTEGER            ::   numptr                 !: logical unit for Poleward TRansports
+   INTEGER            ::   numflo                 !: logical unit for drifting floats
+
+   !!----------------------------------------------------------------------
+   !!                          Run control  
+   !!----------------------------------------------------------------------
+
+   INTEGER            ::   nstop = 0                !: error flag (=number of reason for a premature stop run)
+   INTEGER            ::   nwarn = 0                !: warning flag (=number of warning found during the run)
+   CHARACTER(len=200) ::   ctmp1, ctmp2, ctmp3      !: temporary character
+   CHARACTER (len=64) ::   cform_err = "(/,' ===>>> : E R R O R',     /,'         ===========',/)"       !:
+   CHARACTER (len=64) ::   cform_war = "(/,' ===>>> : W A R N I N G', /,'         ===============',/)"   !:
+   LOGICAL            ::   lwp                      !: boolean : true on the 1st processor only
+   LOGICAL            ::   lsp_area = .TRUE.        !: to make a control print over a specific area
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/in_out_manager.F90,v 1.11 2007/03/02 16:37:06 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_opa  ***
+      !!
+      !! ** Purpose : ??? blah blah....
+      !!-----------------------------------------------------------------------
+      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,"(/,' ===>>> : E R R O R',     /,'         ===========',/)") 
+         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_stop
+
+
+   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_warn  ***
+      !!
+      !! ** Purpose : ???  blah blah....
+      !!-----------------------------------------------------------------------
+      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,"(/,' ===>>> : W A R N I N G', /,'         ===============',/)") 
+         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
+
+
+   FUNCTION getunit()
+     !!-----------------------------------------------------------------------
+     !!                  ***  FUNCTION  getunit  ***
+     !!
+     !! ** Purpose : ???  blah blah....
+     !!-----------------------------------------------------------------------
+     INTEGER :: getunit
+     LOGICAL :: llopn 
+     !---------------------------------------------------------------------
+     getunit = 15   ! choose a unit that is big enough then it is
+                    !  not already used in OPA
+     llopn = .TRUE.
+     DO WHILE( (getunit < 998) .AND. llopn )
+        getunit = getunit + 1
+        INQUIRE( unit = getunit, opened = llopn )
+     END DO
+     IF( (getunit == 999) .AND. llopn ) THEN
+        CALL ctl_stop( 'getunit: All logical units until 999 are used...' )
+        getunit = -1
+     ENDIF
+
+   END FUNCTION getunit
+
+   !!=====================================================================
+END MODULE in_out_manager
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4536)
@@ -0,0 +1,779 @@
+MODULE iom
+   !!=====================================================================
+   !!                    ***  MODULE  iom ***
+   !! Input/Output manager :  Library to read input files
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis cdvar in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+   USE iom_ioipsl      ! NetCDF format with IOIPSL library
+   USE iom_nf90        ! NetCDF format with native NetCDF library
+   USE iom_rstdimg     ! restarts access direct format "dimg" style...
+
+   IMPLICIT NONE
+   PUBLIC   !   must be public to be able to access iom_def through iom
+   
+   PUBLIC iom_open, iom_close, iom_varid, iom_get, iom_gettime, iom_rstput
+
+   INTERFACE iom_get
+      MODULE PROCEDURE iom_g0d, iom_g1d, iom_g2d, iom_g3d
+   END INTERFACE
+   INTERFACE iom_rstput
+      MODULE PROCEDURE iom_rp0d, iom_rp1d, iom_rp2d, iom_rp3d
+   END INTERFACE
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom.F90,v 1.10 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file (return 0 if not found)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in   )           ::   cdname   ! File name
+      INTEGER         , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldwrt    ! open in write modeb          (default = .FALSE.)
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kdom     ! Type of domain to be written (default = jpdom_local_noovlap)
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kiolib   ! library used to open the file (default = jpnf90) 
+      LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
+
+      CHARACTER(LEN=100)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
+      CHARACTER(LEN=100)    ::   cltmpn    ! tempory name to store clname (in writting mode)
+      CHARACTER(LEN=10)     ::   clsuffix  ! ".nc" or ".dimg"
+      CHARACTER(LEN=15)     ::   clcpu     ! the cpu number (max jpmax_digits digits)
+      CHARACTER(LEN=100)    ::   clinfo    ! info character
+      LOGICAL               ::   llok      ! check the existence 
+      LOGICAL               ::   llwrt     ! local definition of ldwrt
+      LOGICAL               ::   llstop    ! local definition of ldstop
+      INTEGER               ::   iolib     ! library do we use to open the file
+      INTEGER               ::   icnt      ! counter for digits in clcpu (max = jpmax_digits)
+      INTEGER               ::   iln, ils  ! lengths of character
+      INTEGER               ::   idom      ! type of domain
+      INTEGER               ::   istop     ! 
+      INTEGER, DIMENSION(2,5) ::   idompar ! domain parameters: 
+      ! local number of points for x,y dimensions
+      ! position of first local point for x,y dimensions
+      ! position of last local point for x,y dimensions
+      ! start halo size for x,y dimensions
+      ! end halo size for x,y dimensions
+      !---------------------------------------------------------------------
+      ! Initializations and control
+      ! =============
+      clinfo = '                    iom_open ~~~  '
+      istop = nstop
+      ! if iom_open is called for the first time: initialize iom_file(:)%nfid to 0
+      ! (could be done when defining iom_file in f95 but not in f90)
+      IF( iom_init == 0 ) THEN
+         iom_file(:)%nfid = 0
+         iom_init = 1
+      ENDIF
+      ! do we read or write the file?
+      IF( PRESENT(ldwrt) ) THEN   ;   llwrt = ldwrt
+      ELSE                        ;   llwrt = .FALSE.
+      ENDIF
+      ! do we call ctl_stop if we try to open a non-existing file in read mode?
+      IF( PRESENT(ldstop) ) THEN   ;   llstop = ldstop
+      ELSE                         ;   llstop = .TRUE.
+      ENDIF
+      ! what library do we use to open the file?
+      IF( PRESENT(kiolib) ) THEN   ;   iolib = kiolib
+      ELSE                         ;   iolib = jpnf90
+      ENDIF
+      ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
+      ! =============
+      clname   = trim(cdname)
+#if defined key_agrif
+      if ( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+#endif    
+      ! which suffix should we use?
+      SELECT CASE (iolib)
+      CASE (jpioipsl ) ;   clsuffix = '.nc'
+      CASE (jpnf90   ) ;   clsuffix = '.nc'
+      CASE (jprstdimg) ;   clsuffix = '.dimg'
+      CASE DEFAULT     ;   clsuffix = ''
+         CALL ctl_stop( TRIM(clinfo), 'accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+      END SELECT
+      ! Add the suffix if needed
+      iln = LEN_TRIM(clname)
+      ils = LEN_TRIM(clsuffix)
+      IF( INDEX( TRIM(clname), TRIM(clsuffix), back = .TRUE. ) /= iln - ils + 1 ) clname = TRIM(clname)//TRIM(clsuffix)
+      cltmpn = clname   ! store this name
+      ! try to find if the file to be opened already exist
+      ! =============
+      INQUIRE( FILE = clname, EXIST = llok )
+      IF( .NOT.llok ) THEN
+         ! we try to add the cpu number to the name
+         IF( iolib == jprstdimg ) THEN   ;   WRITE(clcpu,*) narea
+         ELSE                            ;   WRITE(clcpu,*) narea-1
+         ENDIF
+         clcpu  = TRIM(ADJUSTL(clcpu))
+         iln = INDEX(clname,TRIM(clsuffix), back = .TRUE.)
+         clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
+         icnt = 0
+         INQUIRE( FILE = clname, EXIST = llok ) 
+         ! we try different formats for the cpu number by adding 0
+         DO WHILE( .NOT.llok .AND. icnt < jpmax_digits )
+            clcpu  = "0"//trim(clcpu)
+            clname = clname(1:iln-1)//'_'//TRIM(clcpu)//TRIM(clsuffix)
+            INQUIRE( FILE = clname, EXIST = llok )
+            icnt = icnt + 1
+         END DO
+      ENDIF
+      IF( llwrt ) THEN
+         ! check the domain definition
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         idom = jpdom_local_noovlap   ! default definition
+         IF( jpni*jpnj == jpnij ) THEN   ;   idom = jpdom_local_noovlap   ! default definition
+         ELSE                            ;   idom = jpdom_local_full      ! default definition
+         ENDIF
+         IF( PRESENT(kdom) )   idom = kdom
+         ! create the domain informations
+         ! =============
+         SELECT CASE (idom)
+         CASE (jpdom_local_full)
+            idompar(:,1) = (/ jpi             , jpj              /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + jpi - 1 , njmpp + jpj - 1  /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ jpi - nlei      , jpj - nlej       /)
+         CASE (jpdom_local_noextra)
+            idompar(:,1) = (/ nlci            , nlcj             /)
+            idompar(:,2) = (/ nimpp           , njmpp            /)
+            idompar(:,3) = (/ nimpp + nlci - 1, njmpp + nlcj - 1 /)
+            idompar(:,4) = (/ nldi - 1        , nldj - 1         /)
+            idompar(:,5) = (/ nlci - nlei     , nlcj - nlej      /)
+         CASE (jpdom_local_noovlap)
+            idompar(:,1) = (/ nlei  - nldi + 1, nlej  - nldj + 1 /)
+            idompar(:,2) = (/ nimpp + nldi - 1, njmpp + nldj - 1 /)
+            idompar(:,3) = (/ nimpp + nlei - 1, njmpp + nlej - 1 /)
+            idompar(:,4) = (/ 0               , 0                /)
+            idompar(:,5) = (/ 0               , 0                /)
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo), 'wrong value of kdom, only jpdom_local* cases are accepted' )
+         END SELECT
+      ENDIF
+      ! Open the NetCDF or RSTDIMG file
+      ! =============
+      ! do we have some free file identifier?
+      IF( MINVAL(iom_file(:)%nfid) /= 0 )   &
+         &   CALL ctl_stop( TRIM(clinfo), 'No more free file identifier', 'increase jpmax_files in iom_def' )
+      ! if no file was found...
+      IF( .NOT. llok ) THEN
+         IF( .NOT. llwrt ) THEN   ! we are in read mode 
+            IF( llstop ) THEN   ;   CALL ctl_stop( TRIM(clinfo), 'File '//TRIM(cltmpn)//'* not found' )
+            ELSE                ;   istop = nstop + 1   ! make sure that istop /= nstop so we don't open the file
+            ENDIF
+         ELSE                     ! we are in write mode so we 
+            clname = cltmpn       ! get back the file name without the cpu number
+         ENDIF
+      ENDIF
+      IF( istop == nstop ) THEN   ! no error within this routine
+         SELECT CASE (iolib)
+         CASE (jpioipsl )   ;   CALL iom_ioipsl_open(  clname, kiomid, llwrt, llok, idompar )
+         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
+         CASE (jprstdimg)   ;   CALL iom_rstdimg_open( clname, kiomid, llwrt, llok, idompar )
+         CASE DEFAULT
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         END SELECT
+      ENDIF
+      !
+   END SUBROUTINE iom_open
+
+
+   SUBROUTINE iom_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_close  ***
+      !!
+      !! ** Purpose : close an input file, or all files opened by iom
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in), OPTIONAL ::   kiomid   ! iom identifier of the file to be closed
+      !                                           ! No argument : all the files opened by iom are closed
+
+      INTEGER ::   jf         ! dummy loop indices
+      INTEGER ::   i_s, i_e   ! temporary integer
+      CHARACTER(LEN=100)    ::   clinfo    ! info character
+      !---------------------------------------------------------------------
+      !
+      clinfo = '                    iom_close ~~~  '
+      IF( PRESENT(kiomid) ) THEN
+         i_s = kiomid
+         i_e = kiomid
+      ELSE
+         i_s = 1
+         i_e = jpmax_files
+      ENDIF
+
+      IF( i_s > 0 ) THEN
+         DO jf = i_s, i_e
+            IF( iom_file(jf)%nfid > 0 ) THEN
+               SELECT CASE (iom_file(jf)%iolib)
+               CASE (jpioipsl )   ;   CALL iom_ioipsl_close(  jf )
+               CASE (jpnf90   )   ;   CALL iom_nf90_close(    jf )
+               CASE (jprstdimg)   ;   CALL iom_rstdimg_close( jf )
+               CASE DEFAULT
+                  CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+               END SELECT
+               iom_file(jf)%nfid       = 0   ! free the id 
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' close file: '//TRIM(iom_file(jf)%name)//' ok'
+            ELSEIF( PRESENT(kiomid) ) THEN
+               WRITE(ctmp1,*) '--->',  kiomid
+               CALL ctl_stop( TRIM(clinfo)//' Invalid file identifier', ctmp1 )
+            ENDIF
+         END DO
+      ENDIF
+      !    
+   END SUBROUTINE iom_close
+
+
+   FUNCTION iom_varid ( kiomid, cdvar, kdimsz )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file (return 0 if not found)
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      !
+      INTEGER                        ::   iom_varid, iiv, i_nvd
+      LOGICAL                        ::   ll_fnd
+      CHARACTER(LEN=100)             ::   clinfo                   ! info character
+      !!-----------------------------------------------------------------------
+      iom_varid = 0                         ! default definition
+      !
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+         IF( iom_file(kiomid)%nfid == 0 ) THEN 
+            CALL ctl_stop( trim(clinfo), 'the file is not open' )
+         ELSE
+            ll_fnd  = .FALSE.
+            iiv = 0
+            !
+            DO WHILE ( .NOT.ll_fnd .AND. iiv < iom_file(kiomid)%nvars )
+               iiv = iiv + 1
+               ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
+            END DO
+            !
+            IF( .NOT.ll_fnd ) THEN
+               iiv = iiv + 1
+               IF( iiv <= jpmax_vars ) THEN
+                  SELECT CASE (iom_file(kiomid)%iolib)
+                  CASE (jpioipsl )   ;   iom_varid = iom_ioipsl_varid( kiomid, cdvar, iiv, kdimsz )
+                  CASE (jpnf90   )   ;   iom_varid = iom_nf90_varid(   kiomid, cdvar, iiv, kdimsz )
+                  CASE (jprstdimg)   ;   iom_varid = 0   ! all variables are listed in iom_file
+                  CASE DEFAULT   
+                     CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                  END SELECT
+               ELSE
+                  CALL ctl_stop( trim(clinfo), 'Too many variables in the file '//iom_file(kiomid)%name,   &
+                        &                         'increase the parameter jpmax_vars')
+               ENDIF
+            ELSE
+               iom_varid = iiv
+               IF( PRESENT(kdimsz) ) THEN 
+                  i_nvd = iom_file(kiomid)%ndims(iiv)
+                  IF( i_nvd == size(kdimsz) ) THEN
+                     kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,iiv)
+                  ELSE
+                     WRITE(ctmp1,*) i_nvd, size(kdimsz)
+                     CALL ctl_stop( trim(clinfo), 'error in kdimsz size'//trim(ctmp1) )
+                  ENDIF
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDIF
+      !
+   END FUNCTION iom_varid
+
+
+   !!----------------------------------------------------------------------
+   !!                   INTERFACE iom_get
+   !!----------------------------------------------------------------------
+   SUBROUTINE iom_g0d( kiomid, cdvar, pvar )
+      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file
+      CHARACTER(len=*), INTENT(in   )                 ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out)                 ::   pvar      ! read field
+      !
+      INTEGER               :: idvar   ! variable id
+      !
+      IF( kiomid > 0 ) THEN
+         idvar = iom_varid( kiomid, cdvar )
+         IF( iom_file(kiomid)%nfid > 0 .AND. idvar > 0 ) THEN
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, pvar )
+            CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idvar, pvar )
+            CASE DEFAULT    
+               CALL ctl_stop( 'iom_g0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_g0d
+
+   SUBROUTINE iom_g1d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                         ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                         ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                         ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )              , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(1), OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r1d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g1d
+
+   SUBROUTINE iom_g2d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                           ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                           ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                           ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:,:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )                , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(2)  , OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r2d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g2d
+
+   SUBROUTINE iom_g3d( kiomid, kdom, cdvar, pvar, ktime, kstart, kcount )
+      INTEGER         , INTENT(in   )                             ::   kiomid    ! Identifier of the file
+      INTEGER         , INTENT(in   )                             ::   kdom      ! Type of domain to be read
+      CHARACTER(len=*), INTENT(in   )                             ::   cdvar     ! Name of the variable
+      REAL(wp)        , INTENT(  out), DIMENSION(:,:,:)           ::   pvar      ! read field
+      INTEGER         , INTENT(in   )                  , OPTIONAL ::   ktime     ! record number
+      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kstart    ! start axis position of the reading 
+      INTEGER         , INTENT(in   ), DIMENSION(3)    , OPTIONAL ::   kcount    ! number of points in each axis
+      !
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) CALL iom_get_123d( kiomid, kdom       , cdvar        , pv_r3d=pvar,   &
+              &                                                     ktime=ktime, kstart=kstart, kcount=kcount )
+      ENDIF
+   END SUBROUTINE iom_g3d
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE iom_get_123d( kiomid, kdom  , cdvar ,   &
+         &                  pv_r1d, pv_r2d, pv_r3d,   &
+         &                  ktime , kstart, kcount  )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_get_123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! Identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
+      CHARACTER(len=*)           , INTENT(in   )           ::   cdvar      ! Name of the variable
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+      INTEGER                    , INTENT(in   ), OPTIONAL ::   ktime      ! record number
+      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kstart     ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
+      !
+      INTEGER                        ::   jl          ! loop on number of dimension 
+      INTEGER                        ::   idom        ! type of domain
+      INTEGER                        ::   idvar       ! id of the variable
+      INTEGER                        ::   inbdim      ! number of dimensions of the variable
+      INTEGER                        ::   idmspc      ! number of spatial dimensions 
+      INTEGER                        ::   itime       ! record number
+      INTEGER                        ::   istop       ! temporary value of nstop
+      INTEGER                        ::   ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER                        ::   ji, jj      ! loop counters
+      INTEGER                        ::   irankpv       ! 
+      INTEGER                        ::   ind1, ind2  ! substring index
+      INTEGER, DIMENSION(jpmax_dims) ::   istart      ! starting point to read for each axis
+      INTEGER, DIMENSION(jpmax_dims) ::   icnt        ! number of value to read along each axis 
+      INTEGER, DIMENSION(jpmax_dims) ::   idimsz      ! size of the dimensions of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   ishape      ! size of the dimensions of the variable
+      REAL(wp)                       ::   zscf, zofs  ! sacle_factor and add_offset
+      INTEGER                        ::   itmp        ! temporary integer
+      CHARACTER(LEN=100)             ::   clinfo      ! info character
+      CHARACTER(LEN=100)             ::   clname      ! file name
+      CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
+      !---------------------------------------------------------------------
+      !
+      clname = iom_file(kiomid)%name   !   esier to read
+      clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
+      ! local definition of the domain ?
+      idom = kdom
+      ! check kcount and kstart optionals parameters...
+      IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
+      IF( PRESENT(kstart) .AND. (.NOT. PRESENT(kcount)) ) CALL ctl_stop(trim(clinfo), 'kstart present needs kcount present')
+      IF( PRESENT(kstart) .AND. idom /= jpdom_unknown   ) CALL ctl_stop(trim(clinfo), 'kstart present needs kdom = jpdom_unknown')
+
+      ! Search for the variable in the data base (eventually actualize data)
+      istop = nstop
+      idvar = iom_varid( kiomid, cdvar )
+      !
+      IF( idvar > 0 ) THEN
+         ! to write iom_file(kiomid)%dimsz in a shorter way !
+         idimsz(:) = iom_file(kiomid)%dimsz(:, idvar) 
+         inbdim = iom_file(kiomid)%ndims(idvar)            ! number of dimensions in the file
+         idmspc = inbdim                                   ! number of spatial dimensions in the file
+         IF( iom_file(kiomid)%luld(idvar) )   idmspc = inbdim - 1
+         IF( idmspc > 3 )   CALL ctl_stop(trim(clinfo), 'the file has more than 3 spatial dimensions this case is not coded...') 
+         !
+         ! update idom definition...
+         ! Identify the domain in case of jpdom_auto(glo/dta) definition
+         IF( idom == jpdom_autoglo .OR. idom == jpdom_autodta ) THEN            
+            IF( idom == jpdom_autoglo ) THEN   ;   idom = jpdom_global 
+            ELSE                               ;   idom = jpdom_data
+            ENDIF
+            ind1 = INDEX( clname, '_', back = .TRUE. ) + 1
+            ind2 = INDEX( clname, '.', back = .TRUE. ) - 1
+            IF( ind2 > ind1 ) THEN   ;   IF( VERIFY( clname(ind1:ind2), '0123456789' ) == 0 )   idom = jpdom_local   ;   ENDIF
+         ENDIF
+         ! Identify the domain in case of jpdom_local definition
+         IF( idom == jpdom_local ) THEN
+            IF(     idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN   ;   idom = jpdom_local_full
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN   ;   idom = jpdom_local_noextra
+            ELSEIF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN   ;   idom = jpdom_local_noovlap
+            ELSE   ;   CALL ctl_stop( trim(clinfo), 'impossible to identify the local domain' )
+            ENDIF
+         ENDIF
+         !
+         ! check the consistency between input array and data rank in the file
+         !
+         ! initializations
+         itime = 1
+         IF( PRESENT(ktime) ) itime = ktime
+
+         irankpv = 1 * COUNT( (/PRESENT(pv_r1d)/) ) + 2 * COUNT( (/PRESENT(pv_r2d)/) ) + 3 * COUNT( (/PRESENT(pv_r3d)/) )
+         WRITE(clrankpv, fmt='(i1)') irankpv
+         WRITE(cldmspc , fmt='(i1)') idmspc
+         !
+         IF(     idmspc <  irankpv ) THEN 
+            CALL ctl_stop( TRIM(clinfo), 'The file has only '//cldmspc//' spatial dimension',   &
+               &                         'it is impossible to read a '//clrankpv//'D array from this file...' )
+         ELSEIF( idmspc == irankpv ) THEN
+            IF( PRESENT(pv_r1d) .AND. idom /= jpdom_unknown )   &
+               &   CALL ctl_stop( TRIM(clinfo), 'case not coded...You must use jpdom_unknown' )
+         ELSEIF( idmspc >  irankpv ) THEN
+               IF( PRESENT(pv_r2d) .AND. itime == 1 .AND. idimsz(3) == 1 .AND. idmspc == 3 ) THEN
+                  CALL ctl_warn( trim(clinfo), '2D array but 3 spatial dimensions for the data...'              ,   &
+                        &         'As the size of the z dimension is 1 and as we try to read the first record, ',   &
+                        &         'we accept this case, even if there is a possible mix-up between z and time dimension' )   
+                  idmspc = idmspc - 1
+               ELSE
+                  CALL ctl_stop( TRIM(clinfo), 'To keep iom lisibility, when reading a '//clrankpv//'D array,'         ,   &
+                     &                         'we do not accept data with more than '//cldmspc//' spatial dimension',   &
+                     &                         'Use ncwa -a to suppress the unnecessary dimensions' )
+               ENDIF
+         ENDIF
+
+         !
+         ! definition of istart and icnt
+         !
+         icnt  (:) = 1
+         istart(:) = 1
+         istart(idmspc+1) = itime
+
+         IF(              PRESENT(kstart)       ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+         ELSE
+            IF(           idom == jpdom_unknown ) THEN                                       ; icnt(1:idmspc) = idimsz(1:idmspc)
+            ELSE 
+               IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
+                  IF(     idom == jpdom_data    ) THEN ; istart(1:2) = (/ mig(1), mjg(1) /)  ! icnt(1:2) done bellow
+                  ELSEIF( idom == jpdom_global  ) THEN ; istart(1:2) = (/ nimpp , njmpp  /)  ! icnt(1:2) done bellow
+                  ENDIF
+                  ! we do not read the overlap                     -> we start to read at nldi, nldj
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  IF( idom /= jpdom_local_noovlap )   istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  IF( jpni*jpnj == jpnij .AND. idom /= jpdom_local_noovlap ) istart(1:2) = istart(1:2) + (/ nldi - 1, nldj - 1 /)
+                  ! we do not read the overlap and the extra-halos -> from nldi to nlei and from nldj to nlej 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!                  icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  IF( jpni*jpnj == jpnij ) THEN   ;   icnt(1:2) = (/ nlei - nldi + 1, nlej - nldj + 1 /)
+                  ELSE                            ;   icnt(1:2) = (/ nlci           , nlcj            /)
+                  ENDIF
+                  IF( PRESENT(pv_r3d) ) THEN
+                     IF( idom == jpdom_data ) THEN   ; icnt(3) = jpkdta
+                     ELSE                            ; icnt(3) = jpk
+                     ENDIF
+                  ENDIF
+               ENDIF
+            ENDIF
+         ENDIF
+
+         ! check that istart and icnt can be used with this file
+         !-
+         DO jl = 1, jpmax_dims
+            itmp = istart(jl)+icnt(jl)-1
+            IF( itmp > idimsz(jl) .AND. idimsz(jl) /= 0 ) THEN
+               WRITE( ctmp1, FMT="('(istart(', i1, ') + icnt(', i1, ') - 1) = ', i5)" ) jl, jl, itmp
+               WRITE( ctmp2, FMT="(' is larger than idimsz(', i1,') = ', i5)"         ) jl, idimsz(jl)
+               CALL ctl_stop( trim(clinfo), 'start and count too big regarding to the size of the data, ', ctmp1, ctmp2 )     
+            ENDIF
+         END DO
+
+         ! check that icnt matches the input array
+         !-     
+         IF( idom == jpdom_unknown ) THEN
+            IF( irankpv == 1 )        ishape(1:1) = SHAPE(pv_r1d)
+            IF( irankpv == 2 )        ishape(1:2) = SHAPE(pv_r2d)
+            IF( irankpv == 3 )        ishape(1:3) = SHAPE(pv_r3d)
+            ctmp1 = 'd'
+         ELSE
+            IF( irankpv == 2 ) THEN
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:2) = SHAPE(pv_r2d(nldi:nlei,nldj:nlej  ))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:2)=SHAPE(pv_r2d(nldi:nlei,nldj:nlej  )) ; ctmp1='d(nldi:nlei,nldj:nlej)'
+               ELSE                          ; ishape(1:2)=SHAPE(pv_r2d(1   :nlci,1   :nlcj  )) ; ctmp1='d(1:nlci,1:nlcj)'
+               ENDIF
+            ENDIF
+            IF( irankpv == 3 ) THEN 
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!               ishape(1:3) = SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:))   ;   ctmp1 = 'd(nldi:nlei,nldj:nlej,:)'
+               IF( jpni*jpnj == jpnij ) THEN ; ishape(1:3)=SHAPE(pv_r3d(nldi:nlei,nldj:nlej,:)) ; ctmp1='d(nldi:nlei,nldj:nlej,:)'
+               ELSE                          ; ishape(1:3)=SHAPE(pv_r3d(1   :nlci,1   :nlcj,:)) ; ctmp1='d(1:nlci,1:nlcj,:)'
+               ENDIF
+            ENDIF
+         ENDIF
+         
+         DO jl = 1, irankpv
+            WRITE( ctmp2, FMT="(', ', i1,'): ', i5,' /= icnt(', i1,'):', i5)" ) jl, ishape(jl), jl, icnt(jl)
+            IF( ishape(jl) /= icnt(jl) )   CALL ctl_stop( TRIM(clinfo), 'size(pv_r'//clrankpv//TRIM(ctmp1)//TRIM(ctmp2) )
+         END DO
+
+      ENDIF
+
+      ! read the data
+      !-     
+      IF( idvar > 0 .AND. istop == nstop ) THEN   ! no additional errors until this point...
+         !
+         ! find the right index of the array to be read
+! JMM + SM: ugly patch before getting the new version of lib_mpp)
+!         IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+!         ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+!         ENDIF
+         IF( jpni*jpnj == jpnij ) THEN
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = nldi   ;   ix2 = nlei      ;   iy1 = nldj   ;   iy2 = nlej
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ELSE
+            IF( idom /= jpdom_unknown ) THEN   ;   ix1 = 1      ;   ix2 = nlci      ;   iy1 = 1      ;   iy2 = nlcj
+            ELSE                               ;   ix1 = 1      ;   ix2 = icnt(1)   ;   iy1 = 1      ;   iy2 = icnt(2)
+            ENDIF
+         ENDIF
+      
+         SELECT CASE (iom_file(kiomid)%iolib)
+         CASE (jpioipsl )   ;   CALL iom_ioipsl_get(  kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jpnf90   )   ;   CALL iom_nf90_get(    kiomid, idvar, inbdim, istart, icnt, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE (jprstdimg)   ;   CALL iom_rstdimg_get( kiomid, idom, idvar, ix1, ix2, iy1, iy2,   &
+            &                                         pv_r1d, pv_r2d, pv_r3d )
+         CASE DEFAULT    
+            CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+         END SELECT
+
+         IF( istop == nstop ) THEN   ! no additional errors until this point...
+            IF(lwp) WRITE(numout,*) '           read '//TRIM(cdvar)//' in '//TRIM(iom_file(kiomid)%name)//' ok'
+            
+            !--- overlap areas and extra hallows (mpp)
+            IF(     PRESENT(pv_r2d) .AND. idom /= jpdom_unknown ) THEN
+               CALL lbc_lnk( pv_r2d,'Z',-999.,'no0' )
+            ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
+               ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
+               IF( icnt(3) == jpk ) THEN
+                  CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
+               ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
+                  DO jj = nlcj+1, jpj   ;   pv_r3d(1:nlci, jj, :) = pv_r3d(1:nlci, nlej, :)   ;   END DO
+                  DO ji = nlci+1, jpi   ;   pv_r3d(ji    , : , :) = pv_r3d(nlei  , :   , :)   ;   END DO
+               ENDIF
+            ENDIF
+            
+            !--- Apply scale_factor and offset
+            zscf = iom_file(kiomid)%scf(idvar)      ! scale factor
+            zofs = iom_file(kiomid)%ofs(idvar)      ! offset
+            IF(     PRESENT(pv_r1d) ) THEN
+               IF( zscf /= 1. )   pv_r1d(:) = pv_r1d(:) * zscf 
+               IF( zofs /= 0. )   pv_r1d(:) = pv_r1d(:) + zofs
+            ELSEIF( PRESENT(pv_r2d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r2d(:,:) = pv_r2d(:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r2d(:,:) = pv_r2d(:,:) + zofs
+            ELSEIF( PRESENT(pv_r3d) ) THEN
+               !CDIR COLLAPSE
+               IF( zscf /= 1.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) * zscf
+               !CDIR COLLAPSE
+               IF( zofs /= 0.)   pv_r3d(:,:,:) = pv_r3d(:,:,:) + zofs
+            ENDIF
+            !
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE iom_get_123d
+
+
+   SUBROUTINE iom_gettime( kiomid, cdvar, ptime )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
+      CHARACTER(len=*)      , INTENT(in   ) ::   cdvar    ! time axis name
+      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
+      !
+      INTEGER            ::   idvar    ! id of the variable
+      CHARACTER(LEN=100) ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      !
+      IF( kiomid > 0 ) THEN
+         clinfo = 'iom_gettime, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+         idvar = iom_varid( kiomid, cdvar )
+         !
+         ptime(:) = 0. ! default definition
+         IF( idvar > 0 ) THEN
+            IF( iom_file(kiomid)%ndims(idvar) == 1 ) THEN
+               IF( iom_file(kiomid)%luld(idvar) ) THEN
+                  IF( iom_file(kiomid)%dimsz(1,idvar) == size(ptime) ) THEN
+                     SELECT CASE (iom_file(kiomid)%iolib)
+                     CASE (jpioipsl )   ;   CALL iom_ioipsl_gettime( kiomid, idvar, ptime )
+                     CASE (jpnf90   )   ;   CALL iom_nf90_gettime(   kiomid, idvar, ptime )
+                     CASE (jprstdimg)   ;   CALL ctl_stop( TRIM(clinfo)//' case IO library == jprstdimg not coded...' )
+                     CASE DEFAULT    
+                        CALL ctl_stop( TRIM(clinfo)//' accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+                     END SELECT
+                  ELSE
+                     WRITE(ctmp1,*) 'error with the size of ptime ',size(ptime),iom_file(kiomid)%dimsz(1,idvar)
+                     CALL ctl_stop( trim(clinfo), trim(ctmp1) )
+                  ENDIF
+               ELSE
+                  CALL ctl_stop( trim(clinfo), 'variable dimension is not unlimited... use iom_get' )
+               ENDIF
+            ELSE
+               CALL ctl_stop( trim(clinfo), 'the variable has more than 1 dimension' )
+            ENDIF
+         ELSE
+            CALL ctl_stop( trim(clinfo), 'variable not found in '//iom_file(kiomid)%name )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE iom_gettime
+
+
+   !!----------------------------------------------------------------------
+   !!                   INTERFACE iom_rstput
+   !!----------------------------------------------------------------------
+   SUBROUTINE iom_rp0d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in)                         ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid(kiomid, cdvar)
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r0d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp0d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp0d
+
+   SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(        jpk) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid(kiomid, cdvar)
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r1d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )    CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r1d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp1d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp1d
+
+   SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj    ) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid(kiomid, cdvar)
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r2d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r2d = pvar ) 
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp2d: accepted IO library are only jpioipsl, jpnf90 and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp2d
+
+   SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
+      INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
+      INTEGER         , INTENT(in)                         ::   kwrite   ! writing time-step
+      INTEGER         , INTENT(in)                         ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*), INTENT(in)                         ::   cdvar    ! time axis name
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvar     ! written field
+      INTEGER         , INTENT(in), OPTIONAL               ::   ktype    ! variable external type
+      INTEGER :: ivid   ! variable id
+      IF( kiomid > 0 ) THEN
+         IF( iom_file(kiomid)%nfid > 0 ) THEN
+            ivid = iom_varid(kiomid, cdvar)
+            SELECT CASE (iom_file(kiomid)%iolib)
+            CASE (jpioipsl )   ;   CALL iom_ioipsl_rstput( kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jpnf90   )   ;   CALL iom_nf90_rstput(   kt, kwrite, kiomid, cdvar, ivid, ktype, pv_r3d = pvar )
+            CASE (jprstdimg)   ;   IF( kt == kwrite )   CALL iom_rstdimg_rstput( kiomid, cdvar, ivid, pv_r3d = pvar )
+            CASE DEFAULT     
+               CALL ctl_stop( 'iom_rp3d: accepted IO library are only jpioipsl and jprstdimg' )
+            END SELECT
+         ENDIF
+      ENDIF
+   END SUBROUTINE iom_rp3d
+   !!----------------------------------------------------------------------
+
+
+   !!======================================================================
+END MODULE iom
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_def.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 4536)
@@ -0,0 +1,71 @@
+MODULE iom_def
+   !!=====================================================================
+   !!                    ***  MODULE  iom_def ***
+   !! IOM variables definitions
+   !!====================================================================
+   !! History :  9.0  ! 06 09  (S. Masson) Original code
+   !!--------------------------------------------------------------------
+   !!---------------------------------------------------------------------------------
+   !! OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_def.F90,v 1.7 2007/06/05 10:33:38 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!---------------------------------------------------------------------------------
+
+   USE par_kind
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_data          = 1   !: ( 1  :jpidta, 1  :jpjdta)
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_global        = 2   !: ( 1  :jpiglo, 1  :jpjglo)
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local         = 3   !: One of the 3 following cases
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_full    = 4   !: ( 1  :jpi   , 1  :jpi   )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_noextra = 5   !: ( 1  :nlci  , 1  :nlcj  )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_local_noovlap = 6   !: (nldi:nlei  ,nldj:nlej  )
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_unknown       = 7   !: No dimension checking
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autoglo       = 8   !: 
+   INTEGER, PARAMETER, PUBLIC ::   jpdom_autodta       = 9   !: 
+
+   INTEGER, PARAMETER, PUBLIC ::   jpioipsl    = 100      !: Use ioipsl (fliocom only) library
+   INTEGER, PARAMETER, PUBLIC ::   jpnf90      = 101      !: Use nf90 library
+   INTEGER, PARAMETER, PUBLIC ::   jprstdimg   = 102      !: Use restart dimgs (fortran direct acces) library
+#if defined key_dimgout
+   INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jprstdimg  !: restarts io library
+#else
+   INTEGER, PARAMETER, PUBLIC ::   jprstlib  = jpnf90     !: restarts io library
+#endif
+
+   INTEGER, PARAMETER, PUBLIC ::   jp_r8    = 200      !: write REAL(8)
+   INTEGER, PARAMETER, PUBLIC ::   jp_r4    = 201      !: write REAL(4)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i4    = 202      !: write INTEGER(4)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i2    = 203      !: write INTEGER(2)
+   INTEGER, PARAMETER, PUBLIC ::   jp_i1    = 204      !: write INTEGER(1)
+
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_files  = 20   !: maximum number of simultaneously opened file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 60   !: maximum number of variables in one file
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_dims   =  4   !: maximum number of dimensions for one variable
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  5   !: maximum number of digits for the cpu number in the file name
+
+!$AGRIF_DO_NOT_TREAT
+   INTEGER, PUBLIC            ::   iom_init = 0        !: used to initialize iom_file(:)%nfid to 0
+
+   TYPE, PUBLIC ::   file_descriptor
+      CHARACTER(LEN=240)                        ::   name     !: name of the file
+      INTEGER                                   ::   nfid     !: identifier of the file (0 if closed)
+      INTEGER                                   ::   iolib    !: library used to read the file (jpioipsl, jpnf90 or jprstdimg)
+      INTEGER                                   ::   nvars    !: number of identified varibles in the file
+      INTEGER                                   ::   iduld    !: id of the unlimited dimension
+      INTEGER                                   ::   irec     !: writing record position  
+      CHARACTER(LEN=32), DIMENSION(jpmax_vars)  ::   cn_var   !: names of the variables
+      INTEGER, DIMENSION(jpmax_vars)            ::   nvid     !: id of the variables
+      INTEGER, DIMENSION(jpmax_vars)            ::   ndims    !: number of dimensions of the variables
+      LOGICAL, DIMENSION(jpmax_vars)            ::   luld     !: variable using the unlimited dimension
+      INTEGER, DIMENSION(jpmax_dims,jpmax_vars) ::   dimsz    !: size of variables dimensions 
+      REAL(kind=wp), DIMENSION(jpmax_vars)      ::   scf      !: scale_factor of the variables
+      REAL(kind=wp), DIMENSION(jpmax_vars)      ::   ofs      !: add_offset of the variables
+   END TYPE file_descriptor
+   TYPE(file_descriptor), DIMENSION(jpmax_files), PUBLIC ::   iom_file !: array containing the info for all opened files
+!$AGRIF_END_DO_NOT_TREAT
+
+   !!=====================================================================
+END MODULE iom_def
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4536)
@@ -0,0 +1,422 @@
+MODULE iom_ioipsl
+   !!=====================================================================
+   !!                    ***  MODULE  iom_ioipsl ***
+   !! Input/Output manager :  Library to read input files with IOIPSL (only fliocom module)
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE iom_def         ! iom variables definitions
+   USE ioipsl          ! IOIPSL library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_ioipsl_open, iom_ioipsl_close, iom_ioipsl_varid, iom_ioipsl_get, iom_ioipsl_gettime, iom_ioipsl_rstput
+
+   INTERFACE iom_ioipsl_get
+      MODULE PROCEDURE iom_ioipsl_g0d, iom_ioipsl_g123d
+   END INTERFACE
+   INTERFACE iom_ioipsl_rstput
+      MODULE PROCEDURE iom_ioipsl_rp0123d
+   END INTERFACE
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_ioipsl.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_ioipsl_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file with IOIPSL (only fliocom module)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! ioipsl identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      INTEGER            ::   iln        ! lengths of character
+      INTEGER            ::   istop      ! temporary storage of nstop
+      INTEGER            ::   ifliodom   ! model domain identifier (see flio_dom_set)
+      INTEGER            ::   ioipslid   ! ioipsl identifier of the opened file
+      INTEGER            ::   jl         ! loop variable
+      !---------------------------------------------------------------------
+
+      clinfo = '                    iom_ioipsl_open ~~~  '
+      istop = nstop
+      !
+      IF( ldok ) THEN      ! Open existing file...
+         !                 ! =============
+         IF( ldwrt ) THEN  ! ... in write mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
+            CALL flioopfd( TRIM(cdname), ioipslid, "WRITE" )
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            CALL flioopfd( TRIM(cdname), ioipslid )
+         ENDIF
+      ELSE                 ! the file does not exist
+         !                 ! =============
+         iln = INDEX( cdname, '.nc' )
+         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+            IF( jpnij > 1 ) THEN
+               ! define the domain position regarding to the global domain (mainly useful in mpp)
+               CALL flio_dom_set( jpnij, narea-1, (/1, 2/), (/jpiglo, jpjglo/)   &
+                  &             , kdompar(:,1), kdompar(:,2), kdompar(:,3), kdompar(:,4), kdompar(:,5)   &
+                  &             , 'BOX', ifliodom )        
+               ! Note that fliocrfd may change the value of cdname (add the cpu number...)
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname(1:iln-1)//'... in WRITE mode'
+               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom )
+            ELSE              ! the file should be open for read mode so it must exist...
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname//' in WRITE mode'
+               CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid )
+            ENDIF
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! start to fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name   = TRIM(cdname)
+         iom_file(kiomid)%nfid   = ioipslid
+         iom_file(kiomid)%iolib  = jpioipsl
+         iom_file(kiomid)%nvars  = 0
+         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files
+         CALL flioinqf( ioipslid, id_uld = iom_file(kiomid)%iduld )
+         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
+      ELSE
+         kiomid = 0               ! return error flag
+      ENDIF
+      !
+   END SUBROUTINE iom_ioipsl_open
+
+
+   SUBROUTINE iom_ioipsl_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_ioipsl_close  ***
+      !!
+      !! ** Purpose : close an input file with IOIPSL (only fliocom module) 
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      !---------------------------------------------------------------------
+      !
+      CALL flioclo( iom_file(kiomid)%nfid )
+      !    
+   END SUBROUTINE iom_ioipsl_close
+
+
+   FUNCTION iom_ioipsl_varid ( kiomid, cdvar, kiv, kdimsz )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file with IOIPSL (only fliocom module)
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER              , INTENT(in   )           ::   kiv   ! 
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      !
+      INTEGER                        ::   iom_ioipsl_varid  ! iom variable Id
+      INTEGER                        ::   ioipslid          ! ioipsl file identifier
+      INTEGER                        ::   ji                ! dummy loop index
+      INTEGER                        ::   i_nvd             ! number of dimension of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   idimid            ! dimension ids of the variable
+      LOGICAL                        ::   ll_fnd            ! found test
+      CHARACTER(LEN=100)             ::   clinfo            ! info character
+      !!-----------------------------------------------------------------------
+      clinfo = 'iom_ioipsl_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
+      iom_ioipsl_varid = 0                  ! default definition
+      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
+      ioipslid = iom_file(kiomid)%nfid      ! get back ioipsl file identifier 
+      CALL flioinqv( ioipslid, cdvar, ll_fnd, nb_dims = i_nvd )   ! does the variable exist in the file
+      IF( ll_fnd ) THEN
+         IF( i_nvd <= jpmax_dims ) THEN
+            iom_ioipsl_varid = kiv
+            iom_file(kiomid)%nvars       = kiv
+            iom_file(kiomid)%nvid(kiv)   = -1   ! variable id is not available in ioipsl
+            iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
+            iom_file(kiomid)%ndims(kiv)  = i_nvd
+            CALL flioinqv( ioipslid, cdvar, ll_fnd,   &
+                  &           len_dims = iom_file(kiomid)%dimsz(1:i_nvd,kiv), &   ! dimensions size
+                  &           id_dims  = idimid(1:i_nvd) )                        ! dimensions ids
+            iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+            DO ji = 1, i_nvd                       ! find the unlimited dimension
+               IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.
+            END DO
+            !---------- Deal with scale_factor and add_offset
+            CALL flioinqa( ioipslid, cdvar, 'scale_factor', ll_fnd )
+            IF( ll_fnd) THEN
+               CALL fliogeta( ioipslid, cdvar, 'scale_factor', iom_file(kiomid)%scf(kiv) )
+            ELSE
+               iom_file(kiomid)%scf(kiv) = 1.
+            END IF
+            CALL flioinqa( ioipslid, cdvar, 'add_offset', ll_fnd )
+            IF( ll_fnd ) THEN
+               CALL fliogeta( ioipslid, cdvar, 'add_offset', iom_file(kiomid)%ofs(kiv) )
+            ELSE
+               iom_file(kiomid)%ofs(kiv) = 0.
+            END IF
+            ! return the simension size
+            IF( PRESENT(kdimsz) ) THEN 
+               IF( i_nvd == SIZE(kdimsz) ) THEN
+                  kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
+               ELSE
+                  WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
+                  CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
+               ENDIF
+            ENDIF
+         ELSE
+            CALL ctl_stop( TRIM(clinfo), 'Too many dimensions in the file '//iom_file(kiomid)%name,   &
+                  &                       'increase the parameter jpmax_vars')
+         ENDIF
+!!$                  ELSE  
+!!$                     CALL ctl_warn( trim(clinfo), 'Variable '//trim(cdvar)// &
+!!$                        &                         ' is not found in the file '//trim(iom_file(kiomid)%name) )
+      ENDIF
+      !
+   END FUNCTION iom_ioipsl_varid
+
+
+   SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_ioipsl_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with IOIPSL (only fliocom module)
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   ) ::   kiomid    ! Identifier of the file
+      INTEGER , INTENT(in   ) ::   kvid      ! variable id
+      REAL(wp), INTENT(  out) ::   pvar      ! read field
+      !
+      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), pvar )
+      ! 
+   END SUBROUTINE iom_ioipsl_g0d
+
+
+   SUBROUTINE iom_ioipsl_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                      pv_r1d, pv_r2d, pv_r3d)
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_ioipsl_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with IOIPSL (only fliocom module)
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kvid       ! Name of the variable
+      INTEGER                    , INTENT(in   )           ::   knbdim     ! number of dimensions of the variable
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+      !
+      INTEGER               ::   ioipslid   ! ioipsl file identifier
+      CHARACTER(LEN=100)    ::   clvn       ! variable name
+      !---------------------------------------------------------------------
+      clvn = TRIM(iom_file(kiomid)%cn_var(kvid))   ! get back variable name 
+      ioipslid = iom_file(kiomid)%nfid             ! get back IPIPSL file id
+      !
+      IF( PRESENT(pv_r1d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r1d(:                ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ELSEIF( PRESENT(pv_r2d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ELSEIF( PRESENT(pv_r3d) ) THEN
+         CALL fliogetv( ioipslid, clvn, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), count = kcount(1:knbdim) )
+      ENDIF
+      !
+      !
+   END SUBROUTINE iom_ioipsl_g123d
+
+
+   SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis kvid in the file with IOIPSL (only fliocom module)
+      !!--------------------------------------------------------------------
+      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
+      INTEGER               , INTENT(in   ) ::   kvid     ! variable id
+      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
+      !---------------------------------------------------------------------
+      !
+      CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), ptime(:),   &
+            &         start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /) )
+      !
+   END SUBROUTINE iom_ioipsl_gettime
+
+
+   SUBROUTINE iom_ioipsl_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
+         &                                 pv_r0d, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_ioipsl_rstput  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kt       ! ocean time-step
+      INTEGER                         , INTENT(in)           ::   kwrite   ! writing time-step
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! variable name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      INTEGER                         , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
+      REAL(wp)                        , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      INTEGER               :: idims                ! number of dimension
+      INTEGER               :: idvar                ! variable id
+      INTEGER               :: itype                ! variable type
+      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
+      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
+      CHARACTER(LEN=100)    :: clinfo               ! info character
+      INTEGER               :: ioipslid             ! ioipsl file identifier
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_ioipsl_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      ioipslid = iom_file(kiomid)%nfid
+      !
+      ! define dimension variables if it is not already done
+      ! ==========================
+      IF( iom_file(kiomid)%nvars == 0 ) THEN
+         ! define the dimension variables if it is not already done
+         CALL fliodefv( ioipslid,'nav_lon', (/1,2/), v_t=flio_r4   , axis='X',   &
+               &                  long_name="Longitude", units="degrees_east" )
+         CALL fliodefv( ioipslid,'nav_lat', (/1,2/), v_t=flio_r4   , axis='Y',   &
+               &                  long_name="Latitude", units="degrees_north" )
+         CALL fliodefv( ioipslid,'nav_lev', (/3/)  , v_t=flio_i4   , axis='Z',   &
+               &                  long_name="Model levels",units="model_levels")
+         CALL fliodefv( ioipslid,'time_counter', (/4/), v_t=flio_r4, axis='T',   &
+               &                  long_name="Time axis", units='seconds since 0001-01-01 00:00:00' )
+         ! update informations structure related the dimension variable we just added...
+         iom_file(kiomid)%nvars       = 4
+         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
+         iom_file(kiomid)%cn_var(1:3) = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
+         iom_file(kiomid)%cn_var(4)   = 'time_counter'
+         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1) = 0   
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
+      ENDIF
+
+      ! define the data if it is not already done
+      ! ===============
+      IF( kvid <= 0 ) THEN
+         ! variable definition
+         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
+         ENDIF
+         IF( PRESENT(ktype) ) THEN   ! variable external type
+            SELECT CASE (ktype)
+            CASE (jp_r8)  ;   itype = flio_r8
+            CASE (jp_r4)  ;   itype = flio_r4
+            CASE (jp_i4)  ;   itype = flio_i4
+            CASE (jp_i2)  ;   itype = flio_i2
+            CASE (jp_i1)  ;   itype = flio_i1   !   fliocom does not handle i1 type of variable
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
+            END SELECT
+         ELSE
+            itype = flio_r8
+         ENDIF
+         IF( PRESENT(pv_r0d) ) THEN   ;   CALL fliodefv (ioipslid, TRIM(cdvar)                 , v_t = itype)
+         ELSE                         ;   CALL fliodefv (ioipslid, TRIM(cdvar), idimid(1:idims), v_t = itype)
+         ENDIF
+         ! update informations structure related the new variable we want to add...
+         idvar                          = iom_file(kiomid)%nvars + 1
+         iom_file(kiomid)%nvars         = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(idvar)   = -1   ! netcdf variable id is not available in ioipsl
+         iom_file(kiomid)%scf(idvar)    = 1.
+         iom_file(kiomid)%ofs(idvar)    = 0.
+         iom_file(kiomid)%ndims(idvar)  = idims
+         IF( .NOT. PRESENT(pv_r0d) ) THEN
+            iom_file(kiomid)%luld(idvar) = .TRUE.
+            CALL flioinqf( ioipslid, ln_dim = idimsz )
+            iom_file(kiomid)%dimsz(1:idims-1,idvar) = idimsz(idimid(1:idims-1))
+         ELSE                               
+            iom_file(kiomid)%luld(idvar) = .FALSE.
+         ENDIF
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
+      ELSE
+         idvar = kvid
+      ENDIF
+
+      ! time step kwrite : write the variable
+      IF( kt == kwrite ) THEN
+         ! on what kind of domain must the data be written?
+         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
+            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
+            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
+               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
+               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
+               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+            ELSE 
+               CALL ctl_stop( 'iom_ioipsl_rp0123d: should have been an impossible case...' )
+            ENDIF
+
+            ! write dimension variables if it is not already done
+            ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
+            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
+               CALL flioputv( ioipslid, 'nav_lon'     , glamt(ix1:ix2, iy1:iy2) )
+               CALL flioputv( ioipslid, 'nav_lat'     , gphit(ix1:ix2, iy1:iy2) )
+               CALL flioputv( ioipslid, 'nav_lev'     , gdept_0 )
+               ! +++ WRONG VALUE: to be improved but not really useful...
+               CALL flioputv( ioipslid, 'time_counter', kt )
+               ! update the values of the variables dimensions size
+               CALL flioinqf( ioipslid, ln_dim = idimsz )
+               iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
+               iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
+            ENDIF
+         ENDIF
+
+         ! write the data
+         ! =============
+         IF(     PRESENT(pv_r0d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r0d                      )
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r1d(                  :) )
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r2d(ix1:ix2, iy1:iy2   ) )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   CALL flioputv( ioipslid, cdvar, pv_r3d(ix1:ix2, iy1:iy2, :) )
+         ENDIF
+         ! add 1 to the size of the temporal dimension (not really useful...)
+         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
+               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_ioipsl_rp0123d
+
+
+   !!======================================================================
+END MODULE iom_ioipsl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4536)
@@ -0,0 +1,476 @@
+MODULE iom_nf90
+   !!=====================================================================
+   !!                    ***  MODULE  iom_nf90 ***
+   !! Input/Output manager :  Library to read input files with NF90 (only fliocom module)
+   !!====================================================================
+   !! History :  9.0  ! 05 12  (J. Belier) Original code
+   !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
+   !!--------------------------------------------------------------------
+   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+   USE netcdf          ! NetCDF library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_nf90_open, iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput
+
+   INTERFACE iom_nf90_get
+      MODULE PROCEDURE iom_nf90_g0d, iom_nf90_g123d
+   END INTERFACE
+   INTERFACE iom_nf90_rstput
+      MODULE PROCEDURE iom_nf90_rp0123d
+   END INTERFACE
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_nf90.F90,v 1.8 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose : open an input file with NF90
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid    ! nf90 identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo   ! info character
+      CHARACTER(LEN=100) ::   cltmp    ! temporary character
+      INTEGER            ::   iln      ! lengths of character
+      INTEGER            ::   istop    ! temporary storage of nstop
+      INTEGER            ::   if90id   ! nf90 identifier of the opened file
+      INTEGER            ::   idmy     ! dummy variable
+      INTEGER            ::   jl       ! loop variable
+      !---------------------------------------------------------------------
+
+      clinfo = '                    iom_nf90_open ~~~  '
+      istop = nstop   ! store the actual value of nstop
+      !
+      IF( ldok ) THEN      ! Open existing file...
+         !                 ! =============
+         IF( ldwrt ) THEN  ! ... in write mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
+            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_WRITE  , if90id), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy    ), clinfo)
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_NOWRITE, if90id), clinfo)
+         ENDIF
+      ELSE                 ! the file does not exist
+         !                 ! =============
+         iln = INDEX( cdname, '.nc' )
+         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+            IF( jpnij > 1 ) THEN
+               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.nc'
+               cdname = TRIM(cltmp)
+            ENDIF
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in WRITE mode'
+            CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), NF90_NOCLOBBER, if90id ), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy          ), clinfo)
+            ! define dimensions
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1)  , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', jpk           , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 't', NF90_UNLIMITED, idmy ), clinfo)
+            ! global attributes
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1     , 2     /) ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_global'    , (/jpiglo, jpjglo/) ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_size_local'     , kdompar(:,1)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_first' , kdompar(:,2)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_position_last'  , kdompar(:,3)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_start', kdompar(:,4)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , kdompar(:,5)       ), clinfo)
+            CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              ), clinfo)
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! start to fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name   = TRIM(cdname)
+         iom_file(kiomid)%nfid   = if90id
+         iom_file(kiomid)%iolib  = jpnf90
+         iom_file(kiomid)%nvars  = 0
+         iom_file(kiomid)%irec   = -1   ! useless for NetCDF files, used to know if the file is in define mode 
+         CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
+         IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
+      ELSE
+         kiomid = 0               ! return error flag
+      ENDIF
+      !
+   END SUBROUTINE iom_nf90_open
+
+
+   SUBROUTINE iom_nf90_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_nf90_close  ***
+      !!
+      !! ** Purpose : close an input file with NF90
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      CHARACTER(LEN=100)  ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      !
+      clinfo = '      iom_nf90_close    , file: '//TRIM(iom_file(kiomid)%name)
+      CALL iom_nf90_check(NF90_CLOSE(iom_file(kiomid)%nfid), clinfo)
+      !    
+   END SUBROUTINE iom_nf90_close
+
+
+   FUNCTION iom_nf90_varid ( kiomid, cdvar, kiv, kdimsz )  
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION  iom_varid  ***
+      !!
+      !! ** Purpose : get the id of a variable in a file with NF90
+      !!-----------------------------------------------------------------------
+      INTEGER              , INTENT(in   )           ::   kiomid   ! file Identifier
+      CHARACTER(len=*)     , INTENT(in   )           ::   cdvar    ! name of the variable
+      INTEGER              , INTENT(in   )           ::   kiv   ! 
+      INTEGER, DIMENSION(:), INTENT(  out), OPTIONAL ::   kdimsz   ! size of the dimensions
+      !
+      INTEGER                        ::   iom_nf90_varid   ! iom variable Id
+      INTEGER                        ::   if90id           ! nf90 file identifier
+      INTEGER                        ::   ji               ! dummy loop index
+      INTEGER                        ::   ivarid           ! NetCDF  variable Id
+      INTEGER                        ::   i_nvd            ! number of dimension of the variable
+      INTEGER, DIMENSION(jpmax_dims) ::   idimid           ! dimension ids of the variable
+      LOGICAL                        ::   llok             ! ok  test
+      CHARACTER(LEN=100)             ::   clinfo           ! info character
+      !!-----------------------------------------------------------------------
+      clinfo = '          iom_nf90_varid, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      iom_nf90_varid = 0                    ! default definition
+      IF( PRESENT(kdimsz) ) kdimsz(:) = 0   ! default definition
+      if90id = iom_file(kiomid)%nfid        ! get back NetCDF file id
+      !
+      llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr   ! does the variable exist in the file
+      IF( llok ) THEN
+         iom_nf90_varid = kiv
+         iom_file(kiomid)%nvars       = kiv
+         iom_file(kiomid)%nvid(kiv)   = ivarid
+         iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
+         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, ndims = i_nvd), clinfo)   ! number of dimensions
+         iom_file(kiomid)%ndims(kiv)  = i_nvd
+         CALL iom_nf90_check(NF90_Inquire_Variable(if90id, ivarid, dimids = idimid(1:i_nvd)), clinfo)   ! dimensions ids
+         iom_file(kiomid)%luld(kiv) = .FALSE.   ! default value
+         DO ji = 1, i_nvd                       ! dimensions size
+            CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, idimid(ji), len = iom_file(kiomid)%dimsz(ji,kiv)), clinfo)   
+            IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.   ! unlimited dimension? 
+         END DO
+         !---------- Deal with scale_factor and add_offset
+         llok = NF90_Inquire_attribute(if90id, ivarid, 'scale_factor') == nf90_noerr
+         IF( llok) THEN
+            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'scale_factor', iom_file(kiomid)%scf(kiv)), clinfo)
+         ELSE
+            iom_file(kiomid)%scf(kiv) = 1.
+         END IF
+         llok = NF90_Inquire_attribute(if90id, ivarid, 'add_offset') == nf90_noerr
+         IF( llok ) THEN
+            CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, 'add_offset', iom_file(kiomid)%ofs(kiv)), clinfo)
+         ELSE
+            iom_file(kiomid)%ofs(kiv) = 0.
+         END IF
+         ! return the simension size
+         IF( PRESENT(kdimsz) ) THEN 
+            IF( i_nvd == SIZE(kdimsz) ) THEN
+               kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
+            ELSE
+               WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
+               CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
+            ENDIF
+         ENDIF
+!!$                  ELSE  
+!!$                     CALL ctl_warn( trim(clinfo), 'Variable '//trim(cdvar)// &
+!!$                        &                         ' is not found in the file '//trim(iom_file(kiomid)%name) )
+      ENDIF
+      !
+   END FUNCTION iom_nf90_varid
+
+
+   SUBROUTINE iom_nf90_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_nf90_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with NF90
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      INTEGER , INTENT(in   ) ::   kvid     ! variable id
+      REAL(wp), INTENT(  out) ::   pvar     ! read field
+      !
+      CHARACTER(LEN=100)      ::   clinfo   ! info character
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar), clinfo )
+      ! 
+   END SUBROUTINE iom_nf90_g0d
+
+
+   SUBROUTINE iom_nf90_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2,   &
+         &                    pv_r1d, pv_r2d, pv_r3d )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_nf90_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with NF90
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid    ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kvid      ! Name of the variable
+      INTEGER                    , INTENT(in   )           ::   knbdim    ! number of dimensions of the variable
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart    ! start position of the reading in each axis 
+      INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount    ! number of points to be read in each axis
+      INTEGER ,                    INTENT(in   )           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d    ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d    ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d    ! read field (3D case)
+      !
+      CHARACTER(LEN=100) ::   clinfo               ! info character
+      INTEGER            ::   if90id               ! nf90 identifier of the opened file
+      INTEGER            ::   ivid                 ! nf90 variable id
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_g123d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      if90id = iom_file(kiomid)%nfid         ! get back NetCDF file id
+      ivid   = iom_file(kiomid)%nvid(kvid)   ! get back NetCDF var id
+      !
+      IF(     PRESENT(pv_r1d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r1d(:                ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ELSEIF( PRESENT(pv_r2d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r2d(kx1:kx2,ky1:ky2  ), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ELSEIF( PRESENT(pv_r3d) ) THEN
+         CALL iom_nf90_check( NF90_GET_VAR(if90id, ivid, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim),   &
+            &                                                                       count = kcount(1:knbdim)), clinfo )
+      ENDIF
+      !
+   END SUBROUTINE iom_nf90_g123d
+
+
+   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_gettime  ***
+      !!
+      !! ** Purpose : read the time axis kvid in the file with NF90
+      !!--------------------------------------------------------------------
+      INTEGER               , INTENT(in   ) ::   kiomid   ! file Identifier
+      INTEGER               , INTENT(in   ) ::   kvid     ! variable id
+      REAL(wp), DIMENSION(:), INTENT(  out) ::   ptime    ! the time axis
+      !
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      !---------------------------------------------------------------------
+      clinfo = 'iom_nf90_gettime, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
+      CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), ptime(:),   &
+            &                           start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /)), clinfo)
+      !
+   END SUBROUTINE iom_nf90_gettime
+
+
+   SUBROUTINE iom_nf90_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
+         &                               pv_r0d, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_nf90_rstput  ***
+      !!
+      !! ** Purpose : read the time axis cdvar in the file 
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kt       ! ocean time-step
+      INTEGER                         , INTENT(in)           ::   kwrite   ! writing time-step
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! variable name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      INTEGER                         , INTENT(in), OPTIONAL ::   ktype    ! variable type (default R8)
+      REAL(wp)                        , INTENT(in), OPTIONAL ::   pv_r0d   ! written Od field
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      INTEGER               :: idims                ! number of dimension
+      INTEGER               :: idvar                ! variable id
+      INTEGER               :: jd                   ! dimension loop counter   
+      INTEGER               :: ix1, ix2, iy1, iy2   ! subdomain indexes   
+      INTEGER, DIMENSION(4) :: idimsz               ! dimensions size  
+      INTEGER, DIMENSION(4) :: idimid               ! dimensions id
+      CHARACTER(LEN=100)    :: clinfo               ! info character
+      CHARACTER(LEN= 12), DIMENSION(4) :: cltmp     ! temporary character
+      INTEGER               :: if90id               ! nf90 file identifier
+      INTEGER               :: idmy                 ! dummy variable
+      INTEGER               :: itype                ! variable type
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_nf90_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      if90id = iom_file(kiomid)%nfid
+      !
+      ! define dimension variables if it is not already done
+      ! ==========================
+      IF( iom_file(kiomid)%nvars == 0 ) THEN
+         ! are we in define mode?
+         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
+         ENDIF
+         ! define the dimension variables if it is not already done
+         cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'nav_lev     ', 'time_counter' /)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(1)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(1) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(2)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(2) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(3)), NF90_FLOAT , (/ 3    /), iom_file(kiomid)%nvid(3) ), clinfo)
+         CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(4)), NF90_DOUBLE, (/ 4    /), iom_file(kiomid)%nvid(4) ), clinfo)
+         ! update informations structure related the dimension variable we just added...
+         iom_file(kiomid)%nvars       = 4
+         iom_file(kiomid)%luld(1:4)   = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
+         iom_file(kiomid)%cn_var(1:4) = cltmp
+         iom_file(kiomid)%ndims(1:4)  = (/ 2, 2, 1, 1 /)  
+         ! trick: defined to 0 to say that dimension variables are defined but not yet written
+         iom_file(kiomid)%dimsz(1, 1)  = 0   
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
+      ENDIF
+      ! define the data if it is not already done
+      ! ===============
+      IF( kvid <= 0 ) THEN
+         idvar = iom_file(kiomid)%nvars + 1
+         ! are we in define mode?
+         IF( iom_file(kiomid)%irec /= -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_REDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = -1
+         ENDIF
+         ! variable definition
+         IF(     PRESENT(pv_r0d) ) THEN   ;   idims = 0
+         ELSEIF( PRESENT(pv_r1d) ) THEN   ;   idims = 2   ;   idimid(1:idims) = (/    3,4/)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ;   idims = 3   ;   idimid(1:idims) = (/1,2  ,4/)
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ;   idims = 4   ;   idimid(1:idims) = (/1,2,3,4/)
+         ENDIF
+         IF( PRESENT(ktype) ) THEN   ! variable external type
+            SELECT CASE (ktype)
+            CASE (jp_r8)  ;   itype = NF90_DOUBLE
+            CASE (jp_r4)  ;   itype = NF90_FLOAT
+            CASE (jp_i4)  ;   itype = NF90_INT
+            CASE (jp_i2)  ;   itype = NF90_SHORT
+            CASE (jp_i1)  ;   itype = NF90_BYTE
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
+            END SELECT
+         ELSE
+            itype = NF90_DOUBLE
+         ENDIF
+         IF( PRESENT(pv_r0d) ) THEN
+            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype,                    &
+                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+         ELSE
+            CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, idimid(1:idims),   &
+                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+         ENDIF
+         ! update informations structure related the new variable we want to add...
+         iom_file(kiomid)%nvars         = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%scf(idvar)    = 1.
+         iom_file(kiomid)%ofs(idvar)    = 0.
+         iom_file(kiomid)%ndims(idvar)  = idims
+         IF( .NOT. PRESENT(pv_r0d) ) THEN   ;   iom_file(kiomid)%luld(idvar) = .TRUE.
+         ELSE                               ;   iom_file(kiomid)%luld(idvar) = .FALSE.
+         ENDIF
+         DO jd = 1, idims
+            CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, idimid(jd), len = iom_file(kiomid)%dimsz(jd,idvar) ), clinfo)
+         END DO
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
+      ELSE
+         idvar = kvid
+      ENDIF
+
+      ! time step kwrite : write the variable
+      IF( kt == kwrite ) THEN
+         ! are we in write mode?
+         IF( iom_file(kiomid)%irec == -1 ) THEN   ! trick: irec used to know if the file is in define mode or not
+            CALL iom_nf90_check(NF90_ENDDEF( if90id ), clinfo)   ;   iom_file(kiomid)%irec = 0
+         ENDIF
+         ! on what kind of domain must the data be written?
+         IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
+            idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
+            IF(     idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
+               ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+            ELSEIF( idimsz(1) == nlci              .AND. idimsz(2) == nlcj              ) THEN
+               ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+            ELSEIF( idimsz(1) == jpi               .AND. idimsz(2) == jpj               ) THEN
+               ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+            ELSE 
+               CALL ctl_stop( 'iom_nf90_rp0123d: should have been an impossible case...' )
+            ENDIF
+
+            ! write dimension variables if it is not already done
+            ! =============
+            ! trick: is defined to 0 => dimension variable are defined but not yet written
+            IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lon'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo)
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lat'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo)
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_0                 ), clinfo)
+               ! +++ WRONG VALUE: to be improved but not really useful...
+               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo)   
+               ! update the values of the variables dimensions size
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
+               iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
+               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
+               iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
+            ENDIF
+         ENDIF
+
+         ! write the data
+         ! =============
+         IF(     PRESENT(pv_r0d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r0d                      ), clinfo)
+         ELSEIF( PRESENT(pv_r1d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r1d(                  :) ), clinfo)
+         ELSEIF( PRESENT(pv_r2d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2, iy1:iy2   ) ), clinfo)
+         ELSEIF( PRESENT(pv_r3d) ) THEN
+            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2, iy1:iy2, :) ), clinfo)
+         ENDIF
+         ! add 1 to the size of the temporal dimension (not really useful...)
+         IF( iom_file(kiomid)%luld(idvar) )   iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar)    &
+               &                            = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_nf90_rp0123d
+
+
+   SUBROUTINE iom_nf90_check( kstatus, cdinfo )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE iom_nf90_check  ***
+      !!
+      !! ** Purpose :   check nf90 errors
+      !!--------------------------------------------------------------------
+      INTEGER,          INTENT(in) :: kstatus
+      CHARACTER(LEN=*), INTENT(in) :: cdinfo
+      !---------------------------------------------------------------------
+      IF(kstatus /= nf90_noerr)   CALL ctl_stop( 'iom_nf90_check : '//TRIM(nf90_strerror(kstatus)), TRIM(cdinfo) )
+   END SUBROUTINE iom_nf90_check
+
+
+   !!======================================================================
+END MODULE iom_nf90
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_rstdimg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/IOM/iom_rstdimg.F90	(revision 4536)
@@ -0,0 +1,496 @@
+MODULE iom_rstdimg
+   !!=====================================================================
+   !!                    ***  MODULE  iom_rstdimg ***
+   !! Input/Output manager :  Library to read input rstdimg files
+   !!====================================================================
+   !! History :  9.0  ! 06 09  (S. Masson) Original code
+   !!--------------------------------------------------------------------
+
+   !!--------------------------------------------------------------------
+   !!   iom_open       : open a file read only
+   !!   iom_close      : close a file or all files opened by iom
+   !!   iom_get        : read a field (interfaced to several routines)
+   !!   iom_gettime    : read the time axis kvid in the file
+   !!   iom_varid      : get the id of a variable in a file
+   !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
+   !!--------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! lateal boundary condition / mpp exchanges
+   USE iom_def         ! iom variables definitions
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC iom_rstdimg_open, iom_rstdimg_close, iom_rstdimg_get, iom_rstdimg_rstput
+
+   INTERFACE iom_rstdimg_get
+      MODULE PROCEDURE iom_rstdimg_g0d, iom_rstdimg_g123d
+   END INTERFACE
+   INTERFACE iom_rstdimg_rstput
+      MODULE PROCEDURE iom_rstdimg_rp0d, iom_rstdimg_rp123d
+   END INTERFACE
+
+   INTEGER, PARAMETER ::   jpvnl          = 32   ! variable name length
+      
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_rstdimg.F90,v 1.9 2007/06/29 14:10:50 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE iom_rstdimg_open( cdname, kiomid, ldwrt, ldok, kdompar )
+      !!---------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_open  ***
+      !!
+      !! ** Purpose :  open an input file read only (return 0 if not found)
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters: 
+
+      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
+      CHARACTER(LEN=100)                      ::   cltmp                      ! temporary character
+      INTEGER                                 ::   jv                         ! loop counter
+      INTEGER                                 ::   istop                      ! temporary storage of nstop
+      INTEGER                                 ::   idrst                      ! logical unit of the restart file
+      INTEGER                                 ::   iln                        ! lengths of character
+      INTEGER                                 ::   irecl8                     ! record length
+      INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
+      INTEGER                                 ::   ivnum                      ! number of variables
+      INTEGER                                 ::   ishft                      ! counter shift
+      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
+      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
+      INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition 
+      INTEGER                                 ::   iiglo, ijglo               ! domain global size 
+      INTEGER                                 ::   jl                         ! loop variable
+      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
+      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
+      !                                                                               ! position for 1/2/3D variables
+      !---------------------------------------------------------------------
+      clinfo = '                    iom_rstdimg_open ~~~  '
+      istop = nstop      ! store the actual value of nstop
+      ios = 0            ! default definition
+      kiomid = 0         ! default definition
+      ! get a free unit
+      idrst = getunit()  ! get a free logical unit for the restart file
+!!$#if defined key_agrif 
+!!$      idrst = Agrif_Get_Unit()      
+!!$#endif 
+      ! Open the file...
+      ! =============
+      IF( ldok ) THEN      ! Open existing file...
+         ! find the record length
+         OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+            &       , RECL = 8, STATUS = 'old', ACTION = 'read', IOSTAT = ios, ERR = 987 )
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8
+         CLOSE( idrst )
+         ! Open the file with the appropriate record length and parameters
+         IF( ldwrt ) THEN  ! ... in readwrite mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READWRITE mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+               &       , RECL = irecl8, STATUS = 'old', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+         ELSE              ! ... in read mode
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
+               &       , RECL = irecl8, STATUS = 'old', ACTION = 'read'     , IOSTAT = ios, ERR = 987 )
+         ENDIF
+      ELSE                 ! the file does not exist
+         iln = INDEX( cdname, '.dimg' )
+         IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
+            irecl8= MAX( kdompar(1,1) * kdompar(2,1) * wp, ( 8*jpnij + 15 ) * 4 )
+            IF( jpnij > 1 ) THEN
+               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.dimg'
+               cdname = TRIM(cltmp)
+            ENDIF
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in READWRITE mode'
+            OPEN( idrst, FILE = TRIM(cdname), FORM = 'UNFORMATTED', ACCESS = 'DIRECT'   &
+               &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+         ELSE              ! the file should be open for read mode so it must exist...
+            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
+         ENDIF
+      ENDIF
+      ! Performs checks on the file
+      ! =============
+      IF( ldok ) THEN      ! old file
+         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
+              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+              &   ipni, ipnj, ipnij, iarea, iiglo, ijglo
+         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                       &
+            &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
+            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
+         clinfo = TRIM(clinfo)//' file '//TRIM(cdname)
+         IF( iiglo /= jpiglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in i direction' )
+         IF( ijglo /= jpjglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in j direction' )
+         IF( ldwrt ) THEN
+            IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in i direction' )
+            IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in j direction' )
+         ENDIF
+         IF( inz   /= jpk          )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in k direction' )
+         IF( ipni  /= jpni         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along I' )
+         IF( ipnj  /= jpnj         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along J' )
+         IF( ipnij /= jpnij        )   CALL ctl_stop( TRIM(clinfo), 'Total number of processors changed' )
+         IF( iarea /= narea        )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in area numbering ...' )
+      ENDIF
+      ! fill file informations
+      ! =============
+      IF( istop == nstop ) THEN   ! no error within this routine
+!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
+         kiomid = 0
+         DO jl = jpmax_files, 1, -1
+            IF( iom_file(jl)%nfid == 0 )   kiomid = jl
+         ENDDO
+         iom_file(kiomid)%name    = TRIM(cdname)
+         iom_file(kiomid)%nfid    = idrst
+         iom_file(kiomid)%iolib   = jprstdimg
+         iom_file(kiomid)%iduld   = -1
+         IF( ldok ) THEN      ! old file
+            ! read variables informations from the file header
+            IF(  TRIM(clna0d(1)) == 'no0d' )   in0d = 0
+            IF(  TRIM(clna1d(1)) == 'no1d' )   in1d = 0
+            IF(  TRIM(clna2d(1)) == 'no2d' )   in2d = 0
+            IF(  TRIM(clna3d(1)) == 'no3d' )   in3d = 0
+            ivnum = in0d + in1d + in2d + in3d
+            iom_file(kiomid)%nvars            = ivnum
+            iom_file(kiomid)%irec             = 2 + in1d + in2d + inz * in3d
+            iom_file(kiomid)%luld(   1:ivnum) = .FALSE.
+            iom_file(kiomid)%scf(    1:ivnum) = 1.
+            ! scalar variable
+            DO jv = 1, in0d
+               iom_file(kiomid)%cn_var(jv) = TRIM(clna0d(jv))
+               iom_file(kiomid)%nvid(  jv) = 1
+               iom_file(kiomid)%ndims( jv) = 0
+               iom_file(kiomid)%ofs(   jv) = zval0d(jv)   ! warning: trick... we use ofs to store the value
+            END DO
+            ! 1d variable
+            ishft = in0d
+            DO jv = 1, in1d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna1d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval1d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 1
+               iom_file(kiomid)%dimsz(1  , ishft + jv) = jpk
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+            ! 2d variable
+            ishft = in0d + in1d
+            DO jv = 1, in2d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna2d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval2d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 2
+               iom_file(kiomid)%dimsz(1:2, ishft + jv) = (/ inx, iny /)
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+            ! 3d variable
+            ishft = in0d + in1d + in2d 
+            DO jv = 1, in3d
+               iom_file(kiomid)%cn_var(    ishft + jv) = TRIM(clna3d(jv))
+               iom_file(kiomid)%nvid(      ishft + jv) = zval3d(jv)
+               iom_file(kiomid)%ndims(     ishft + jv) = 3
+               iom_file(kiomid)%dimsz(1:3, ishft + jv) = (/ inx, iny, jpk /)
+               iom_file(kiomid)%ofs(       ishft + jv) = 0.
+            END DO
+         ELSE                 ! new file
+            iom_file(kiomid)%nvars = 0
+            iom_file(kiomid)%irec  = 2
+            ! store file informations
+            WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, kdompar(:,1), jpk   ! store domain size
+         ENDIF
+      ENDIF
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo), '   error in opening file '//TRIM(cdname), ctmp1 )
+      ENDIF
+      !
+   END SUBROUTINE iom_rstdimg_open
+
+
+   SUBROUTINE iom_rstdimg_close( kiomid )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_close  ***
+      !!
+      !! ** Purpose : close an input file
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kiomid   ! iom identifier of the file to be closed
+      !
+      CHARACTER(LEN=100)                      ::   clinfo                     ! info character
+      INTEGER                                 ::   jv                         ! loop counter
+      INTEGER                                 ::   irecl8                     ! record length
+      INTEGER                                 ::   ios                        ! IO status
+      INTEGER                                 ::   irhd                       ! record of the header infos
+      INTEGER                                 ::   ivnum                      ! number of variables
+      INTEGER                                 ::   idrst                      ! file logical unit
+      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable
+      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables
+      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d    ! name of 0/1/2/3D variables
+      REAL(wp),          DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d    ! value of 0d variables or record
+      !                                                                               ! position for 1/2/3D variables
+      !---------------------------------------------------------------------
+      !
+      clinfo = '                    iom_rstdimg_close ~~~  '
+      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+      ! test if we can write in the file (test with INQUIRE gives alsways YES even with read only files...)
+      READ(  idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   
+      WRITE( idrst, REC = 1, IOSTAT = ios            ) irecl8, inx, iny, inz   
+      ! We can write in the file => we update its header before closing
+      IF( ios == 0 ) THEN
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   ! get back domain size
+         irhd = iom_file(kiomid)%irec
+         ivnum = iom_file(kiomid)%nvars
+         in0d = 0   ;   in1d = 0   ;   in2d = 0   ;   in3d = 0
+         DO jv = 1, ivnum   ! loop on each variable to get its name and value/record position
+            SELECT CASE (iom_file(kiomid)%ndims(jv))
+            CASE (0)   ! scalar variable
+               in0d = in0d + 1
+               clna0d(in0d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval0d(in0d) = iom_file(kiomid)%ofs(jv)   ! warning: trick... we use ofs to store the value
+            CASE (1)   ! 1d variable
+               in1d = in1d + 1
+               clna1d(in1d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval1d(in1d) = iom_file(kiomid)%nvid(jv)
+            CASE (2)   ! 2d variable
+               in2d = in2d + 1
+               clna2d(in2d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval2d(in2d) = iom_file(kiomid)%nvid(jv)
+            CASE (3)   ! 3d variable
+               in3d = in3d + 1
+               clna3d(in3d) = TRIM(iom_file(kiomid)%cn_var(jv))
+               zval3d(in3d) = iom_file(kiomid)%nvid(jv)
+            CASE DEFAULT   ;   CALL ctl_stop( TRIM(clinfo), 'Should not ne there...' )
+            END SELECT
+         END DO
+         ! force to have at least 1 variable in each list (not necessary (?), but safer...)
+         IF( in0d == 0 ) THEN   ;   in0d = 1   ;   clna0d(1) = 'no0d'   ;   zval0d(1) = -1.   ;   ENDIF
+         IF( in1d == 0 ) THEN   ;   in1d = 1   ;   clna1d(1) = 'no1d'   ;   zval1d(1) = -1.   ;   ENDIF
+         IF( in2d == 0 ) THEN   ;   in2d = 1   ;   clna2d(1) = 'no2d'   ;   zval2d(1) = -1.   ;   ENDIF
+         IF( in3d == 0 ) THEN   ;   in3d = 1   ;   clna3d(1) = 'no3d'   ;   zval3d(1) = -1.   ;   ENDIF
+         ! update the file header before closing it
+         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              &
+            &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
+            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              &
+            &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt
+         IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN 
+            CALL ctl_stop( TRIM(clinfo),   &
+                 &   'Last record size is too big... You could reduce the value of jpvnl' )
+         ELSE 
+            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                        &
+                 &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   &
+                 &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d)
+         ENDIF
+      ELSE
+         ios = 0   ! we cannot write in the file
+      ENDIF
+      !
+      CLOSE( idrst, IOSTAT = ios, ERR = 987 )
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo),   &
+            &   '   error when updating the header of '//TRIM(iom_file(kiomid)%name), ctmp1 )
+      ENDIF
+      !    
+   END SUBROUTINE iom_rstdimg_close
+
+
+   SUBROUTINE iom_rstdimg_g0d( kiomid, kvid, pvar )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_rstdimg_g0d  ***
+      !!
+      !! ** Purpose : read a scalar with RSTDIMG
+      !!-----------------------------------------------------------------------
+      INTEGER,  INTENT(in   ) ::   kiomid    ! Identifier of the file
+      INTEGER,  INTENT(in   ) ::   kvid      ! variable id
+      REAL(wp), INTENT(  out) ::   pvar      ! read field
+      !---------------------------------------------------------------------
+      !
+      pvar = iom_file(kiomid)%ofs(kvid)   ! warning: trick... we use ofs to store the value
+      !
+   END SUBROUTINE iom_rstdimg_g0d
+
+
+   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
+      !!
+      !! ** Purpose : write a scalar with RSTDIMG
+      !!--------------------------------------------------------------------
+      INTEGER                   , INTENT(in) ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)          , INTENT(in) ::   cdvar    ! time axis name
+      INTEGER                   , INTENT(in) ::   kvid     ! variable id
+      REAL(wp)                  , INTENT(in) ::   pv_r0d   ! written 0d field
+      !
+      CHARACTER(LEN=100) ::   clinfo     ! info character
+      INTEGER            ::   idvar      ! variable id
+      !---------------------------------------------------------------------
+      !  
+      clinfo = '                    iom_rstdimg_rp0d ~~~  '
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
+      IF( idvar <= jpmax_vars ) THEN
+         iom_file(kiomid)%nvars = idvar
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(   idvar) = 1   ! useless, Od variables a strored in record 1
+         iom_file(kiomid)%ndims(  idvar) = 0
+         iom_file(kiomid)%luld(   idvar) = .FALSE.
+         iom_file(kiomid)%scf(    idvar) = 1.
+         iom_file(kiomid)%ofs(    idvar) = pv_r0d   ! warning: trick... we use ofs to store the value
+      ELSE
+         CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
+      ENDIF
+   END SUBROUTINE iom_rstdimg_rp0d
+
+
+   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid, kx1, kx2, ky1, ky2,   &
+         &                       pv_r1d, pv_r2d, pv_r3d )
+      !!-----------------------------------------------------------------------
+      !!                  ***  ROUTINE  iom_rstdimg_g123d  ***
+      !!
+      !! ** Purpose : read a 1D/2D/3D variable with RSTDIMG
+      !!
+      !! ** Method : read ONE record at each CALL
+      !!-----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   )           ::   kiomid     ! iom identifier of the file
+      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read
+      INTEGER                    , INTENT(in   )           ::   kvid       ! variable id
+      INTEGER ,                    INTENT(inout)           ::   kx1, kx2, ky1, ky2   ! subdomain indexes
+      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case)
+      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out), OPTIONAL ::   pv_r3d     ! read field (3D case)
+
+      CHARACTER(LEN=100) ::   clinfo               ! info character
+      INTEGER            ::   ios                  ! IO status
+      INTEGER            ::   jk                   ! loop counter
+      INTEGER            ::   idrst                ! logical unit of the restart file
+      !---------------------------------------------------------------------
+      clinfo = '                    iom_rstdimg_g123d ~~~  '
+      !
+      IF( kdom == jpdom_data .OR. kdom == jpdom_global ) THEN
+         CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' )
+      ELSE
+      !
+         idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+         ! modify the subdomain indexes because we cannot directly extract the appropriate subdomaine
+         IF(     kdom == jpdom_local_full    ) THEN   ;   kx1 = 1   ;   kx2 = jpi    ;   ky1 = 1
+         ELSEIF( kdom == jpdom_local_noextra ) THEN   ;   kx1 = 1   ;   kx2 = nlci   ;   ky1 = 1
+         ENDIF
+         !
+         IF(     PRESENT(pv_r1d) ) THEN   ! read 1D variables
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r1d(:)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ! read 2D variables
+            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r2d(kx1:kx2, ky1:ky2    )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ! read 3D variables
+            DO jk = 1, iom_file(kiomid)%dimsz(3,kvid)   ! do loop on each level
+               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   pv_r3d(kx1:kx2, ky1:ky2, jk)
+            END DO
+         ENDIF
+987      CONTINUE
+         IF( ios /= 0 ) THEN
+            WRITE(ctmp1,*) '           iostat = ', ios
+            CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE iom_rstdimg_g123d
+
+
+   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, kvid, pv_r1d, pv_r2d, pv_r3d )
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  ***
+      !!
+      !! ** Purpose : write a 2D/3D variable with RSTDIMG
+      !!--------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file 
+      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! time axis name
+      INTEGER                         , INTENT(in)           ::   kvid     ! variable id
+      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field
+      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pv_r3d   ! written 3d field
+      !
+      CHARACTER(LEN=100)    ::   clinfo               ! info character
+      INTEGER               ::   irecl8               ! reacord length
+      INTEGER               ::   ios                  ! IO status
+      INTEGER               ::   idrst                ! reacord length
+      INTEGER               ::   inx, iny, inz        ! x,y,z dimension of the variable
+      INTEGER               ::   idvar                ! variable id
+      INTEGER               ::   istop                ! temporary storage of nstop
+      INTEGER               ::   irec                 ! record number
+      INTEGER               ::   ix1, ix2, iy1, iy2   ! subdomain indexes
+      INTEGER               ::   jk                   ! loop counter
+      !---------------------------------------------------------------------
+      !
+      clinfo = '          iom_rstdimg_rp123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
+      istop = nstop                   ! store the actual value of nstop
+      irec = iom_file(kiomid)%irec    ! get back the record number of the variable
+      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file
+      IF( kvid <= 0 ) THEN   !   new variable
+         idvar = iom_file(kiomid)%nvars + 1
+      ELSE                   !   the variable already exists in the file
+         idvar = kvid
+      ENDIF
+      IF( idvar > jpmax_vars )   CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' )
+      IF( .NOT. PRESENT(pv_r1d) ) THEN
+         ! find which part of data must be written
+         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz
+         IF(     inx == (nlei - nldi + 1) .AND. iny == (nlej - nldj + 1) ) THEN
+            ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej
+         ELSEIF( inx == nlci              .AND. iny == nlcj              ) THEN
+            ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj
+         ELSEIF( inx == jpi               .AND. iny == jpj               ) THEN
+            ix1 = 1      ;   ix2 = jpi    ;   iy1 = 1      ;   iy2 = jpj
+         ELSE 
+            CALL ctl_stop( clinfo, 'should have been an impossible case...' )
+         ENDIF
+      ENDIF
+      IF( istop == nstop ) THEN
+         ! write the data
+         IF(     PRESENT(pv_r1d) ) THEN   ! 1D variable
+            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r1d(:)
+         ELSEIF( PRESENT(pv_r2d) ) THEN   ! 2D variable
+            WRITE( idrst, REC = irec            , IOSTAT = ios, ERR = 987 ) pv_r2d(ix1:ix2, iy1:iy2    )
+         ELSEIF( PRESENT(pv_r3d) ) THEN   ! 3D variable
+            DO jk = 1, jpk   ! do loop on each level
+               WRITE( idrst, REC = irec + jk - 1, IOSTAT = ios, ERR = 987 ) pv_r3d(ix1:ix2, iy1:iy2, jk)
+            END DO
+         ENDIF
+         ! fill the file informations
+         iom_file(kiomid)%nvars = idvar
+         IF(     PRESENT(pv_r1d) ) THEN
+            iom_file(kiomid)%irec              = irec + 1
+            iom_file(kiomid)%ndims(     idvar) = 1
+            iom_file(kiomid)%dimsz(1  , idvar) = inz
+         ELSEIF( PRESENT(pv_r2d) ) THEN
+            iom_file(kiomid)%irec              = irec + 1
+            iom_file(kiomid)%ndims(     idvar) = 2
+            iom_file(kiomid)%dimsz(1:2, idvar) = (/ inx, iny /)
+         ELSEIF( PRESENT(pv_r3d) ) THEN
+            iom_file(kiomid)%irec              = irec + inz
+            iom_file(kiomid)%ndims(     idvar) = 3
+            iom_file(kiomid)%dimsz(1:3, idvar) = (/ inx, iny, inz /)
+         ENDIF
+         iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
+         iom_file(kiomid)%nvid(  idvar) = irec
+         iom_file(kiomid)%luld(  idvar) = .FALSE.
+         iom_file(kiomid)%scf(   idvar) = 1.
+         iom_file(kiomid)%ofs(   idvar) = 0.
+      ENDIF
+987   CONTINUE
+      IF( ios /= 0 ) THEN
+         WRITE(ctmp1,*) '           iostat = ', ios
+         CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 )
+      ELSE
+         IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
+      ENDIF
+      !     
+   END SUBROUTINE iom_rstdimg_rp123d
+
+
+   !!======================================================================
+END MODULE iom_rstdimg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 4536)
@@ -0,0 +1,317 @@
+MODULE ldfdyn
+   !!======================================================================
+   !!                       ***  MODULE  ldfdyn  ***
+   !! Ocean physics:  lateral viscosity coefficient 
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   ldf_dyn_init : initialization, namelist read, and parameters control
+   !!   ldf_dyn_c3d   : 3D eddy viscosity coefficient initialization
+   !!   ldf_dyn_c2d   : 2D eddy viscosity coefficient initialization
+   !!   ldf_dyn_c1d   : 1D eddy viscosity coefficient initialization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE ldfdyn_oce      ! ocean dynamics lateral physics
+   USE phycst          ! physical constants
+   USE ldfslp          ! ???
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC ldf_dyn_init   ! called by opa.F90
+
+  INTERFACE ldf_zpf
+     MODULE PROCEDURE ldf_zpf_1d, ldf_zpf_1d_3d, ldf_zpf_3d
+  END INTERFACE
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ldf_dyn_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_dyn_init  ***
+      !!                   
+      !! ** Purpose :   set the horizontal ocean dynamics physics
+      !!
+      !! ** Method  :  
+      !!      Eddy viscosity coefficients:
+      !!         default option   : constant coef. ahm0 (namelist)
+      !!        'key_dynldf_c1d': depth dependent coef. defined in 
+      !!                        in ldf_dyn_c1d routine
+      !!        'key_dynldf_c2d': latitude and longitude dependent coef.
+      !!                        defined in ldf_dyn_c2d routine
+      !!        'key_dynldf_c3d': latitude, longitude, depth dependent coef.
+      !!                        defined in ldf_dyn_c3d routine
+      !!      N.B. User defined include files.  By default, 3d and 2d coef.
+      !!      are set to a constant value given in the namelist and the 1d
+      !!      coefficients are initialized to a hyperbolic tangent vertical
+      !!      profile.
+      !!
+      !! Reference :
+      !!      Madec, G. and M. Imbard, 1996, A global ocean mesh to overcome
+      !!      the North Pole singularity, Climate Dynamics, 12, 381-388.
+      !!
+      !! History :
+      !!        !  07-97  (G. Madec)  from inimix.F split in 2 routines
+      !!        !  08-97  (G. Madec)  multi dimensional coefficients
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Local declarations
+      INTEGER ::   ioptio         ! ???
+      LOGICAL :: ll_print = .FALSE.    ! Logical flag for printing viscosity coef.
+
+       
+      NAMELIST/nam_dynldf/ ln_dynldf_lap  , ln_dynldf_bilap,                &
+         &                 ln_dynldf_level, ln_dynldf_hor, ln_dynldf_iso,   &
+         &                 ahm0, ahmb0
+      !!----------------------------------------------------------------------
+
+
+      ! Define the lateral physics parameters
+      ! ======================================
+    
+      ! Read Namelist nam_dynldf : Lateral physics
+      REWIND( numnam )
+      READ  ( numnam, nam_dynldf )
+
+      ! Parameter print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ldf_dyn : lateral momentum physics'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist nam_dynldf : set lateral mixing parameters'
+         WRITE(numout,*) '             laplacian operator          ln_dynldf_lap   = ', ln_dynldf_lap
+         WRITE(numout,*) '             bilaplacian operator        ln_dynldf_bilap = ', ln_dynldf_bilap
+         WRITE(numout,*) '             iso-level                   ln_dynldf_level = ', ln_dynldf_level
+         WRITE(numout,*) '             horizontal (geopotential)   ln_dynldf_hor   = ', ln_dynldf_hor
+         WRITE(numout,*) '             iso-neutral                 ln_dynldf_iso   = ', ln_dynldf_iso
+         WRITE(numout,*) '             horizontal eddy viscosity            ahm0   = ', ahm0
+         WRITE(numout,*) '             background viscosity                 ahmb0  = ', ahmb0
+      ENDIF
+
+      ! ... check of lateral diffusive operator on tracers
+      !           ==> will be done in trazdf module
+
+      ! ... Space variation of eddy coefficients
+      ioptio = 0
+#if defined key_dynldf_c3d
+      IF(lwp) WRITE(numout,*) '          momentum mixing coef. = F( latitude, longitude, depth)'
+      ioptio = ioptio+1
+#endif
+#if defined key_dynldf_c2d
+      IF(lwp) WRITE(numout,*) '          momentum mixing coef. = F( latitude, longitude)'
+      ioptio = ioptio+1
+#endif
+#if defined key_dynldf_c1d
+      IF(lwp) WRITE(numout,*) '          momentum mixing coef. = F( depth )'
+      ioptio = ioptio+1
+      IF( ln_sco ) CALL ctl_stop( '          key_dynldf_c1d cannot be used in s-coordinate (ln_sco)' )
+#endif
+      IF( ioptio == 0 ) THEN
+          IF(lwp) WRITE(numout,*) '          momentum mixing coef. = constant  (default option)'
+        ELSEIF( ioptio > 1 ) THEN
+           CALL ctl_stop( '          use only one of the following keys:',   &
+                &         ' key_dynldf_c3d, key_dynldf_c2d, key_dynldf_c1d' )
+      ENDIF
+
+
+      IF( ln_dynldf_bilap ) THEN
+         IF(lwp) WRITE(numout,*) '          biharmonic momentum diffusion'
+         IF( ahm0 > 0 .AND. .NOT. lk_esopa )   &
+              &   CALL ctl_stop( 'The horizontal viscosity coef. ahm0 must be negative' )
+      ELSE
+         IF(lwp) WRITE(numout,*) '          harmonic momentum diff. (default)'
+         IF( ahm0 < 0 .AND. .NOT. lk_esopa ) &
+              &   CALL ctl_stop( '          The horizontal viscosity coef. ahm0 must be positive' )
+      ENDIF
+
+
+      ! Lateral eddy viscosity
+      ! ======================
+
+#if defined key_dynldf_c3d
+      CALL ldf_dyn_c3d( ll_print )   ! ahm = 3D coef. = F( longitude, latitude, depth )
+#elif defined key_dynldf_c2d
+      CALL ldf_dyn_c2d( ll_print )   ! ahm = 1D coef. = F( longitude, latitude )
+#elif defined key_dynldf_c1d
+      CALL ldf_dyn_c1d( ll_print )   ! ahm = 1D coef. = F( depth )
+#else
+                                     ! Constant coefficients
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'inildf: constant eddy viscosity coef. '
+      IF(lwp) WRITE(numout,*) '~~~~~~'
+      IF(lwp) WRITE(numout,*) '        ahm1 = ahm2 = ahm0 =  ',ahm0
+#endif
+
+   END SUBROUTINE ldf_dyn_init
+
+#if defined key_dynldf_c3d
+#   include "ldfdyn_c3d.h90"
+#elif defined key_dynldf_c2d
+#   include "ldfdyn_c2d.h90"
+#elif defined key_dynldf_c1d
+#   include "ldfdyn_c1d.h90"
+#endif
+
+
+   SUBROUTINE ldf_zpf_1d( ld_print, pdam, pwam, pbot, pdep, pah )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_zpf  ***
+      !!                   
+      !! ** Purpose :   vertical adimensional profile for eddy coefficient
+      !!
+      !! ** Method  :   1D eddy viscosity coefficients ( depth )
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL , INTENT (in   ) :: ld_print   ! If true, output arrays on numout
+      REAL(wp), INTENT (in   ) ::   &
+          pdam,     &  ! depth of the inflection point
+          pwam,     &  ! width of inflection
+          pbot         ! battom value (0<pbot<= 1)
+      REAL(wp), INTENT (in   ), DIMENSION(jpk) ::   &
+          pdep         ! depth of the gridpoint (T, U, V, F)
+      REAL(wp), INTENT (inout), DIMENSION(jpk) ::   &
+          pah          ! adimensional vertical profile
+
+      !! * Local variables
+      INTEGER  ::   jk           ! dummy loop indices
+      REAL(wp) ::   zm00, zm01, zmhb, zmhs       ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )
+      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zmhs = zm00 / zm01
+      zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
+
+      DO jk = 1, jpk
+         pah(jk) = 1.e0 + zmhb * ( zm00 - TANH( ( pdam - pdep(jk) ) / pwam )  )
+      END DO
+
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm profile : '
+         WRITE(numout,*)
+         WRITE(numout,'("  jk      ahm       ","  depth t-level " )')
+         DO jk = 1, jpk
+            WRITE(numout,'(i6,2f12.4,3x,2f12.4)') jk, pah(jk), pdep(jk)
+         END DO
+      ENDIF
+
+   END SUBROUTINE ldf_zpf_1d
+
+
+   SUBROUTINE ldf_zpf_1d_3d( ld_print, pdam, pwam, pbot, pdep, pah )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_zpf  ***
+      !!
+      !! ** Purpose :   vertical adimensional profile for eddy coefficient
+      !!
+      !! ** Method  :   1D eddy viscosity coefficients ( depth )
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL , INTENT (in   ) :: ld_print   ! If true, output arrays on numout
+      REAL(wp), INTENT (in   ) ::   &
+          pdam,     &  ! depth of the inflection point
+          pwam,     &  ! width of inflection
+          pbot         ! battom value (0<pbot<= 1)
+      REAL(wp), INTENT (in   ), DIMENSION(jpk) ::   &
+          pdep         ! depth of the gridpoint (T, U, V, F)
+      REAL(wp), INTENT (inout), DIMENSION(jpi,jpj,jpk) ::   &
+          pah          ! adimensional vertical profile
+
+      !! * Local variables
+      INTEGER  ::   jk           ! dummy loop indices
+      REAL(wp) ::   zm00, zm01, zmhb, zmhs, zcf  ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )
+      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zmhs = zm00 / zm01
+      zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
+
+      DO jk = 1, jpk
+         zcf = 1.e0 + zmhb * ( zm00 - TANH( ( pdam - pdep(jk) ) / pwam )  )
+         pah(:,:,jk) = zcf
+      END DO
+
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm profile : '
+         WRITE(numout,*)
+         WRITE(numout,'("  jk      ahm       ","  depth t-level " )')
+         DO jk = 1, jpk
+            WRITE(numout,'(i6,2f12.4,3x,2f12.4)') jk, pah(1,1,jk), pdep(jk)
+         END DO
+      ENDIF
+
+   END SUBROUTINE ldf_zpf_1d_3d
+
+
+   SUBROUTINE ldf_zpf_3d( ld_print, pdam, pwam, pbot, pdep, pah )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_zpf  ***
+      !!
+      !! ** Purpose :   vertical adimensional profile for eddy coefficient
+      !!
+      !! ** Method  :   3D for partial step or s-coordinate
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL , INTENT (in   ) :: ld_print   ! If true, output arrays on numout
+      REAL(wp), INTENT (in   ) ::   &
+          pdam,     &  ! depth of the inflection point
+          pwam,     &  ! width of inflection
+          pbot         ! reduction factor (surface value / bottom value)
+      REAL(wp), INTENT (in   ), DIMENSION(jpi,jpj,jpk) ::   &
+          pdep         ! dep of the gridpoint (T, U, V, F)
+      REAL(wp), INTENT (inout), DIMENSION(jpi,jpj,jpk) ::   &
+          pah          ! adimensional vertical profile
+
+      !! * Local variables
+      INTEGER  ::   jk           ! dummy loop indices
+      REAL(wp) ::   zm00, zm01, zmhb, zmhs       ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )   
+      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zmhs = zm00 / zm01
+      zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
+
+      DO jk = 1, jpk
+         pah(:,:,jk) = 1.e0 + zmhb * ( zm00 - TANH( ( pdam - pdep(:,:,jk) ) / pwam )  )
+      END DO
+
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm profile : '
+         WRITE(numout,*)
+         WRITE(numout,'("  jk      ahm       ","  depth t-level " )')
+         DO jk = 1, jpk
+            WRITE(numout,'(i6,2f12.4,3x,2f12.4)') jk, pah(1,1,jk), pdep(1,1,jk)
+         END DO
+      ENDIF
+
+   END SUBROUTINE ldf_zpf_3d
+   !!======================================================================
+END MODULE ldfdyn
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_antarctic.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_antarctic.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_antarctic.h90	(revision 4536)
@@ -0,0 +1,43 @@
+   !!----------------------------------------------------------------------
+   !!  ldfdyn_antarctic.h90        2D (i,j) antarctic zoom viscosity coeff.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+!
+! 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
+C
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_arctic.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_arctic.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_arctic.h90	(revision 4536)
@@ -0,0 +1,43 @@
+   !!----------------------------------------------------------------------
+   !!  ldftra_arctic.h90              2D (i,j) arctic zoom viscosity coeff.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+! 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
+
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c1d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c1d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c1d.h90	(revision 4536)
@@ -0,0 +1,99 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  ldfdyn_c1d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_dyn_c1d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_dyn_c1d  ***
+      !!                   
+      !! ** Purpose :   initializations of the horizontal ocean physics
+      !!
+      !! ** Method  :   1D eddy viscosity coefficients ( depth )
+      !!      ahm3, ahm4 never used
+      !!      biharmonic or harmonic operator : ahm1=ahm2 defined at T-level
+      !!      isopycnal or geopotential harmonic operator
+      !!                                      : ahm1 defined at T-level
+      !!                                      : ahm2 defined at w-level
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * Local variables
+      REAL(wp) ::   zdam, zwam, zm00, zm01, zmhf, zmhs
+      REAL(wp) ::   zahmf, zahms
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'inildf: 1D eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~  --'
+      IF(lwp) WRITE(numout,*)
+
+      ! Set ahm1=ahm2   (always at t-level)
+      ! =============
+      ! (USER: modify ahm1 following your desiderata)
+
+      ! initialization of the profile
+      ! ahms, ahmf: surface and bottom values
+      zahms = ahm0
+      zahmf = ahm0/4.
+      ! zdam, zwam: depth of the inflection pt and width of inflection
+      zdam  = -300.
+      zwam  =  300.
+      ! computation coefficients
+      zm00 = TANH( (0-zdam)/zwam )
+      zm01 = TANH( (-fsdept(1,1,jpk)-zdam)/zwam )
+      zmhf = (zahms-zahmf)/(zm00-zm01)
+      zmhs = zahms-zmhf * zm00
+
+      ! set ahm1=ahm2 at T-level
+      DO jk = 1, jpk
+         ahm1(jk) = zmhs + zmhf * TANH( (-fsdept(1,1,jk)-zdam) / zwam )
+         ahm2(jk) = ahm1(jk)
+      END DO
+
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm profile : '
+         WRITE(numout,*)
+         WRITE(numout,9100)
+         DO jk = 1, jpk
+            WRITE(numout,9110) jk, ahm1(jk), fsdept(1,1,jk)
+         END DO
+      ENDIF
+ 9100 FORMAT('  jk      ahm       ','  depth t-level ' )
+ 9110 FORMAT(i6,2f12.4,3x,2f12.4)
+
+
+      ! Set ahm3=ahm4   (always defined at w-level)
+      ! =============
+
+      ! define ahm3 from the same vertical profile used for ahm4
+      ! (always defined at w-level)
+      ! (USER: modify ahm1 following your desiderata)
+
+      DO jk = 1, jpk
+         ahm3(jk) = zmhs + zmhf * TANH( (-fsdepw(1,1,jk)-zdam) / zwam )
+         ahm4(jk) = ahm3(jk)
+      END DO
+
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm3=ahm4 profile : '
+         WRITE(numout,*)
+         WRITE(numout,9120)
+         DO jk = 1, jpk
+            WRITE(numout,9110) jk, ahm3(jk), fsdepw(1,1,jk)
+         END DO
+      ENDIF
+ 9120 FORMAT('  jk      ahm       ','  depth w-level ' )
+
+   END SUBROUTINE ldf_dyn_c1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c2d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c2d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c2d.h90	(revision 4536)
@@ -0,0 +1,280 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldfdyn_c2d.h90  ***
+   !!----------------------------------------------------------------------
+   !!   ldf_dyn_c2d  : set the lateral viscosity coefficients
+   !!   ldf_dyn_c2d_orca : specific case for orca r2 and r4
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/LDF/ldfdyn_c2d.h90,v 1.6 2007/06/29 17:01:51 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/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 : ahm1 is defined at u-point
+      !!                             ahm2 is defined at v-point
+      !!                           : ahm3, ahm4 not used
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * Local variables
+      REAL(wp) ::   za00, zdx_max
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ldf_dyn_c2d : 2d lateral eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      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)
+
+         zdx_max = MAXVAL( e1t(:,:) )
+         IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              laplacian operator: ahm proportional to e1'
+         IF(lwp) WRITE(numout,*) '              Caution, here we assume your mesh is isotropic ...'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zdx_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0 / zdx_max
+         ahm1(:,:) = za00 * e1t(:,:)
+         ahm2(:,:) = za00 * e1f(:,:)
+
+         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 R2 and R4 configurations (overwrite the value of ahm1 ahm2)
+         ! ==============================================
+         IF( cp_cfg == "orca" .AND. ( jp_cfg == 2 .OR. jp_cfg == 4 ) )   CALL ldf_dyn_c2d_orca( 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
+
+         zdx_max = MAXVAL( e1u(:,:) )
+         IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              bi-laplacian operator: ahm proportional to e1**3 '
+         IF(lwp) WRITE(numout,*) '              Caution, here we assume your mesh is isotropic ...'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zdx_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0 / ( zdx_max * zdx_max * zdx_max )
+         ahm3(:,:) = za00 * e1u(:,:) * e1u(:,:) * e1u(:,:)
+         ahm4(:,:) = za00 * e1v(:,:) * e1v(:,:) * e1v(:,:)
+
+         ! 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...
+      !!
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ldftra_oce, ONLY : aht0
+
+      !! * Arguments
+      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
+
+      !! * Local variables
+      INTEGER ::   ji, jj, jn      ! dummy loop indices
+      INTEGER ::   inum            ! temporary logical unit
+      INTEGER ::   iim, ijm
+      INTEGER ::   ifreq, il1, il2, ij, ii
+      INTEGER, DIMENSION(jpidta,jpidta) ::   idata
+      INTEGER, DIMENSION(jpi   ,jpj   ) ::   icof
+
+      REAL(wp) ::   zahmeq, zcoft, zcoff, zmsk
+
+      CHARACTER (len=15) ::   clexp
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'inildf: 2d eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~  --'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '        orca ocean model'
+      IF(lwp) WRITE(numout,*)
+
+#if defined key_antarctic
+#     include "ldfdyn_antarctic.h90"
+#elif defined key_arctic
+#     include "ldfdyn_arctic.h90"
+#else
+      ! Read 2d integer array to specify western boundary increase in the
+      ! ===================== equatorial strip (20N-20S) defined at t-points
+
+      CALL ctlopn( inum, 'ahmcoef', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, lwp, 1 )
+      REWIND inum
+      READ(inum,9101) clexp, iim, ijm
+      READ(inum,'(/)')
+      ifreq = 40
+      il1 = 1
+      DO jn = 1, jpidta/ifreq+1
+         READ(inum,'(/)')
+         il2 = MIN( jpidta, il1+ifreq-1 )
+         READ(inum,9201) ( ii, ji = il1, il2, 5 )
+         READ(inum,'(/)')
+         DO jj = jpjdta, 1, -1
+            READ(inum,9202) ij, ( idata(ji,jj), ji = il1, il2 )
+         END DO
+         il1 = il1 + ifreq
+      END DO
+      
+      DO jj = 1, nlcj
+         DO ji = 1, nlci
+            icof(ji,jj) = idata( mig(ji), mjg(jj) )
+         END DO
+      END DO
+      DO jj = nlcj+1, jpj
+         DO ji = 1, nlci
+            icof(ji,jj) = icof(ji,nlcj)
+         END DO
+      END DO
+      DO jj = 1, jpj
+         DO ji = nlci+1, jpi
+            icof(ji,jj) = icof(nlci,jj)
+         END DO
+      END DO
+
+ 9101 FORMAT(1x,a15,2i8)
+ 9201 FORMAT(3x,13(i3,12x))
+ 9202 FORMAT(i3,41i3)
+
+
+      ! 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
+            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
+
+   END SUBROUTINE ldf_dyn_c2d_orca
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 4536)
@@ -0,0 +1,459 @@
+   !!----------------------------------------------------------------------
+   !!                        ***  ldfdyn_c3d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90,v 1.9 2007/07/04 13:02:29 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/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
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ldftra_oce, ONLY : aht0
+
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * local variables
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &
+         zr = 0.2 ,   &  ! maximum of the reduction factor at the bottom ocean
+         !               ! ( 0 < zr < 1 )
+         zh = 500.,   &  ! depth of at which start the reduction ( > dept(1) )
+         zdx_max  ,   &  ! maximum grid spacing over the global domain
+         za00, zc, zd    ! temporary scalars
+      REAL(wp), DIMENSION(jpk) ::   zcoef   ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      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)
+
+         zdx_max = MAXVAL( e1t(:,:) )
+         IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              laplacian operator: ahm proportional to e1'
+         IF(lwp) WRITE(numout,*) '              Caution, here we assume your mesh is isotropic ...'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zdx_max, ' maximum value for ahm = ', ahm0
+
+
+         za00 = ahm0 / zdx_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
+            ahm1(:,:,jk) = za00 * e1t(:,:) * ahm1(:,:,jk)
+            ahm2(:,:,jk) = za00 * e1f(:,:) * ahm2(:,:,jk)
+         END DO
+
+
+         ! Special case for ORCA R2 and R4 configurations (overwrite the value of ahm1 ahm2)
+         ! ==============================================
+         IF( cp_cfg == "orca" .AND. ( jp_cfg == 2 .OR. jp_cfg == 4 ) ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '              ORCA 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
+
+         zdx_max = MAXVAL( e1u(:,:) )
+         IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              bi-laplacian operator: ahm proportional to e1**3 '
+         IF(lwp) WRITE(numout,*) '              Caution, here we assume your mesh is isotropic ...'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zdx_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0 / ( zdx_max * zdx_max * zdx_max )
+         ahm3(:,:,1) = za00 * e1u(:,:) * e1u(:,:) * e1u(:,:)
+         ahm4(:,:,1) = za00 * e1v(:,:) * e1v(:,:) * e1v(:,:)
+
+         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
+# if defined key_zco
+            zc = gdept_0(jpkm1)
+# else
+            zc = MAXVAL( fsdept(:,:,jpkm1) )
+# endif
+            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
+
+   END SUBROUTINE ldf_dyn_c3d
+
+
+   SUBROUTINE ldf_dyn_c3d_orca( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_dyn_c3d  ***
+      !!                   
+      !! ** Purpose :   ORCA R2 an R4 only
+      !!
+      !! ** Method  :   blah blah blah ....
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ldftra_oce, ONLY : aht0
+
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * local variables
+      INTEGER ::   ji, jj, jk, jn      ! dummy loop indices
+      INTEGER ::   ii0, ii1, ij0, ij1  ! temporary integers
+      INTEGER ::   inum                ! temporary logical unit
+      INTEGER ::   iim, ijm
+      INTEGER ::   ifreq, il1, il2, ij, ii
+      INTEGER, DIMENSION(jpidta, jpjdta) ::   idata
+      INTEGER, DIMENSION(jpi   , jpj   ) ::   icof
+
+      REAL(wp) ::   &
+         zahmeq, zcoff, zcoft, zmsk,   & ! ???
+         zemax, zemin, zeref, zahmm
+      REAL(wp), DIMENSION(jpi,jpj) ::   zahm0
+      REAL(wp), DIMENSION(jpk) ::   zcoef
+
+      CHARACTER (len=15) ::   clexp
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ldfdyn_c3d_orca : 3D eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '        orca R2 or R4 ocean model'
+      IF(lwp) WRITE(numout,*) '  reduced in the surface Eq. strip '
+      IF(lwp) WRITE(numout,*)
+
+      ! Read 2d integer array to specify western boundary increase in the
+      ! ===================== equatorial strip (20N-20S) defined at t-points
+
+      CALL ctlopn( inum, 'ahmcoef', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+         &         1, numout, lwp, 1 )
+      REWIND inum
+      READ(inum,9101) clexp, iim, ijm
+      READ(inum,'(/)')
+      ifreq = 40
+      il1 = 1
+      DO jn = 1, jpidta/ifreq+1
+         READ(inum,'(/)')
+         il2 = MIN( jpidta, il1+ifreq-1 )
+         READ(inum,9201) ( ii, ji = il1, il2, 5 )
+         READ(inum,'(/)')
+         DO jj = jpjdta, 1, -1
+            READ(inum,9202) ij, ( idata(ji,jj), ji = il1, il2 )
+         END DO
+         il1 = il1 + ifreq
+      END DO
+      
+      DO jj = 1, nlcj
+         DO ji = 1, nlci
+            icof(ji,jj) = idata( mig(ji), mjg(jj) )
+         END DO
+      END DO
+      DO jj = nlcj+1, jpj
+         DO ji = 1, nlci
+            icof(ji,jj) = icof(ji,nlcj)
+         END DO
+      END DO
+      DO jj = 1, jpj
+         DO ji = nlci+1, jpi
+            icof(ji,jj) = icof(nlci,jj)
+         END DO
+      END DO
+      
+9101  FORMAT(1x,a15,2i8)
+9201  FORMAT(3x,13(i3,12x))
+9202  FORMAT(i3,41i3)
+      
+      ! 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
+
+      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
+            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
+      
+#if defined key_orca_lev10
+      DO jk = 1, 210
+         zcoef(jk) = 1.
+      END DO
+      DO jk= 211, 230
+         zcoef(jk) = 1. + 0.1 * FLOAT(jk-210)
+      END DO
+      DO jk= 231, 260
+         zcoef(jk) = 3. + 0.2 * FLOAT(jk-230)
+      END DO
+      DO jk= 261, 270
+         zcoef(jk) = 9. + 0.1 * FLOAT(jk-260)
+      END DO
+      DO jk= 271, jpk
+         zcoef(jk) = 10.
+      END DO
+      DO jk= 1, jpk
+         IF(lwp) WRITE(numout,*) 'k= ',jk, 'cof ', zcoef(jk)
+      END DO
+#else
+       DO jk = 1, 21
+         zcoef(jk) = 1.
+      END DO
+      zcoef(22) = 2.
+      zcoef(23) = 3.
+      zcoef(24) = 5.
+      zcoef(25) = 7.
+      zcoef(26) = 9.
+      DO jk = 27, jpk
+         zcoef(jk) = 10.
+      END DO
+#endif
+
+      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
+      
+      ! 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) 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 )
+         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, :)
+      
+      ! Lateral boundary conditions on ( ahm3, ahm4 )
+      !                                ==============
+      CALL lbc_lnk( ahm3, 'U', 1. )   ! U-point, unchanged sign
+      CALL lbc_lnk( ahm4, 'V', 1. )   ! V-point, unchanged sign
+
+      ! 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
+
+   END SUBROUTINE ldf_dyn_c3d_orca
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_oce.F90	(revision 4536)
@@ -0,0 +1,50 @@
+MODULE ldfdyn_oce
+   !!======================================================================
+   !!                  ***  MODULE  ldfdyn_oce  ***
+   !! Ocean physics:  lateral momentum mixing coefficient defined in memory 
+   !!======================================================================
+   !!
+   !! ** Purpose :
+   !!       - Define in memory lateral momentum mixing coefficients
+   !!
+   !! History :
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !! Lateral eddy viscosity coefficients (dynamics)
+   !!----------------------------------------------------------------------
+
+   LOGICAL  ::                      & !!! ** lateral mixing namelist (nam_dynldf) **
+      ln_dynldf_lap   = .TRUE.  ,   &  ! laplacian operator
+      ln_dynldf_bilap = .FALSE. ,   &  ! bilaplacian operator
+      ln_dynldf_level = .FALSE. ,   &  ! iso-level direction
+      ln_dynldf_hor   = .TRUE.  ,   &  ! horizontal (geopotential) direction
+      ln_dynldf_iso   = .FALSE.        ! iso-neutral direction
+
+   REAL(wp) ::                      & !!! ** lateral mixing namelist (nam_dynldf) **
+      ahm0  = 40000._wp ,   &  ! lateral eddy viscosity (m2/s)
+      ahmb0 =     0._wp        ! lateral background eddy viscosity (m2/s)
+
+#if defined key_dynldf_c3d
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &  ! ** 3D coefficients **
+#elif defined key_dynldf_c2d
+   REAL(wp), DIMENSION(jpi,jpj)     ::   &  ! ** 2D coefficients **
+#elif defined key_dynldf_c1d
+   REAL(wp), DIMENSION(jpk)         ::   &  ! ** 2D coefficients **
+#else
+   REAL(wp)                         ::   &  ! ** 0D coefficients **
+#endif
+      ahm1, ahm2, ahm3, ahm4                ! ????
+
+   !!----------------------------------------------------------------------
+END MODULE ldfdyn_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfdyn_substitute.h90	(revision 4536)
@@ -0,0 +1,36 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  ldfdyn_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsahm., the lateral eddy viscosity coeff. 
+   !!      with a constant, or 1D, or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_dynldf_c3d
+!   ' key_dynldf_c3d' :                  3D coefficient
+#    define   fsahmt(i,j,k)    ahm1(i,j,k)
+#    define   fsahmf(i,j,k)    ahm2(i,j,k)
+#    define   fsahmu(i,j,k)    ahm3(i,j,k)
+#    define   fsahmv(i,j,k)    ahm4(i,j,k)
+#elif defined key_dynldf_c2d
+!   ' key_dynldf_c2d' :                 2D coefficient
+#  define   fsahmt(i,j,k)    ahm1(i,j)
+#  define   fsahmf(i,j,k)    ahm2(i,j)
+#  define   fsahmu(i,j,k)    ahm3(i,j)
+#  define   fsahmv(i,j,k)    ahm4(i,j)
+#elif defined key_dynldf_c1d
+!   'key_dynldf_c1d' :                  1D coefficient
+#  define   fsahmt(i,j,k)    ahm1(k)
+#  define   fsahmf(i,j,k)    ahm1(k)
+#  define   fsahmu(i,j,k)    ahm1(k)
+#  define   fsahmv(i,j,k)    ahm1(k)
+#else
+!   default option :               Constant coefficient
+#  define   fsahmt(i,j,k)   ahm0
+#  define   fsahmf(i,j,k)   ahm0
+#  define   fsahmu(i,j,k)   ahm0
+#  define   fsahmv(i,j,k)   ahm0
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv.F90	(revision 4536)
@@ -0,0 +1,388 @@
+MODULE ldfeiv
+   !!======================================================================
+   !!                     ***  MODULE  ldfeiv  ***
+   !! Ocean physics:  variable eddy induced velocity coefficients
+   !!======================================================================
+#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
+   !!                  Same results but not same routine if 'key_mpp_omp'
+   !!                  is defined or not
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE phycst          ! physical constants
+   USE ldfslp          ! iso-neutral slopes
+   USE flxrnf          ! 
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   !! * Routine accessibility
+   PUBLIC ldf_eiv               ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp' :                  OpenMP /  NEC autotasking (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_eiv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_eiv  ***
+      !!
+      !! ** Purpose :   Compute the eddy induced velocity coefficient from the
+      !!      growth rate of baroclinic instability.
+      !!
+      !! ** Method :
+      !!
+      !! ** Action :   uslp(),   : i- and j-slopes of neutral surfaces
+      !!               vslp()      at u- and v-points, resp.
+      !!               wslpi(),  : i- and j-slopes of neutral surfaces
+      !!               wslpj()     at w-points. 
+      !!
+      !! History :
+      !!   8.1  !  99-03  (G. Madec, A. Jouzeau)  Original code
+      !!   8.5  !  02-06  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step inedx
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   &
+         zfw, ze3w, zn2, zf20,       &  ! temporary scalars
+         zaht, zaht_min
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zn, zah, zhw, zross            ! workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ldf_eiv : eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   NEC autotasking / OpenMP : j-slab'
+      ENDIF
+      
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         
+         ! 0. Local initialization
+         ! -----------------------
+         zn   (:,jj) = 0.e0
+         zhw  (:,jj) = 5.e0
+         zah  (:,jj) = 0.e0
+         zross(:,jj) = 0.e0
+         
+         ! 1. Compute lateral diffusive coefficient 
+         ! ----------------------------------------
+
+!CDIR NOVERRCHK 
+         DO jk = 1, jpk
+!CDIR NOVERRCHK 
+            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( rn2(ji,jj,jk), 0.e0 )
+               ze3w = fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+               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))
+               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 
+ 
+!CDIR NOVERRCHK 
+         DO ji = 2, jpim1
+            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) ) * tmask(ji,jj,1)
+            IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN   ! ORCA R02
+               ! Take the minimum between aeiw and aeiv0 for depth levels
+               ! lower than 20 (21 in w- point)
+               IF( mbathy(ji,jj) <= 21. ) aeiw(ji,jj) = MIN( aeiw(ji,jj), 1000. )
+            ENDIF
+         END DO
+
+         ! Decrease the coefficient in the tropics (20N-20S) 
+         zf20 = 2. * omega * sin( rad * 20. )
+         DO ji = 2, jpim1
+            aeiw(ji,jj) = MIN( 1., ABS( ff(ji,jj) / zf20 ) ) * aeiw(ji,jj)
+         END DO
+  
+         ! ORCA R05: Take the minimum between aeiw and aeiv0
+         IF( cp_cfg == "orca" .AND. jp_cfg == 05 ) THEN   ! ORCA R05
+            DO ji = 2, jpim1
+               aeiw(ji,jj) = MIN( aeiw(ji,jj), aeiv0 )
+            END DO
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      ! lateral boundary condition on aeiw 
+      CALL lbc_lnk( aeiw, 'W', 1. )
+
+      ! Average the diffusive coefficient at u- v- points 
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiu(ji,jj) = .5 * (aeiw(ji,jj) + aeiw(ji+1,jj  ))
+            aeiv(ji,jj) = .5 * (aeiw(ji,jj) + aeiw(ji  ,jj+1))
+         END DO 
+      END DO 
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+      ! lateral boundary condition on aeiu, aeiv 
+      CALL lbc_lnk( aeiu, 'U', 1. )
+      CALL lbc_lnk( aeiv, 'V', 1. )
+
+      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. * omega * SIN( rad * 20. )
+         zaht_min = 100.                              ! minimum value for aht
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zaht      = ( 1. -  MIN( 1., ABS( ff(ji,jj) / zf20 ) ) ) * ( aht0 - zaht_min )  &
+                  &      + aht0 * upsrnfh(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.e0 ) THEN
+         aeiu(:,:) = 0.e0
+         aeiv(:,:) = 0.e0
+         aeiw(:,:) = 0.e0
+      ENDIF
+
+   END SUBROUTINE ldf_eiv
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default key                                             k-j-i loops
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_eiv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_eiv  ***
+      !!
+      !! ** Purpose :   Compute the eddy induced velocity coefficient from the
+      !!      growth rate of baroclinic instability.
+      !!
+      !! ** Method :
+      !!
+      !! ** Action : - uslp(),  : i- and j-slopes of neutral surfaces
+      !!             - vslp()      at u- and v-points, resp.
+      !!             - wslpi(),  : i- and j-slopes of neutral surfaces
+      !!             - wslpj()     at w-points. 
+      !!
+      !! History :
+      !!   8.1  !  99-03  (G. Madec, A. Jouzeau)  Original code
+      !!   8.5  !  02-06  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step inedx
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   &
+         zfw, ze3w, zn2, zf20,       &  ! temporary scalars
+         zaht, zaht_min
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zn, zah, zhw, zross            ! workspace
+      !!----------------------------------------------------------------------
+      
+      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.e0
+      zhw  (:,:) = 5.e0
+      zah  (:,:) = 0.e0
+      zross(:,:) = 0.e0
+
+
+      ! 1. Compute lateral diffusive coefficient 
+      ! ----------------------------------------
+
+      DO jk = 1, jpk
+#  if defined key_vectopt_loop  &&  ! defined key_mpp_omp
+!CDIR NOVERRCHK 
+         DO ji = 1, jpij   ! vector opt.
+            ! 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( rn2(ji,1,jk), 0.e0 )
+            zn(ji,1) = zn(ji,1) + SQRT( zn2 ) * fse3w(ji,1,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,1,jk) * tmask(ji,1,jk)
+               zah(ji,1) = zah(ji,1) + zn2   &
+                              * ( wslpi(ji,1,jk) * wslpi(ji,1,jk)    &
+                                + wslpj(ji,1,jk) * wslpj(ji,1,jk) )   &
+                              * ze3w
+            zhw(ji,1) = zhw(ji,1) + ze3w
+         END DO
+#  else
+         DO jj = 2, jpjm1
+!CDIR NOVERRCHK 
+            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( rn2(ji,jj,jk), 0.e0 )
+               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 
+#  endif
+      END DO 
+
+      DO jj = 2, jpjm1
+!CDIR NOVERRCHK 
+         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) ) * tmask(ji,jj,1)
+            IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN   ! ORCA R02
+               ! Take the minimum between aeiw and aeiv0 for depth levels
+               ! lower than 20 (21 in w- point)
+               IF( mbathy(ji,jj) <= 21. ) aeiw(ji,jj) = MIN( aeiw(ji,jj), 1000. )
+            ENDIF
+         END DO
+      END DO
+
+      ! Decrease the coefficient in the tropics (20N-20S) 
+      zf20 = 2. * omega * sin( rad * 20. )
+      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
+
+      ! lateral boundary condition on aeiw 
+      CALL lbc_lnk( aeiw, 'W', 1. )
+
+      ! Average the diffusive coefficient at u- v- points 
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiu(ji,jj) = .5 * ( aeiw(ji,jj) + aeiw(ji+1,jj  ) )
+            aeiv(ji,jj) = .5 * ( aeiw(ji,jj) + aeiw(ji  ,jj+1) )
+         END DO 
+      END DO 
+
+      ! lateral boundary condition on aeiu, aeiv
+      CALL lbc_lnk( aeiu, 'U', 1. )
+      CALL lbc_lnk( aeiv, 'V', 1. )
+
+      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. * omega * SIN( rad * 20. )
+         zaht_min = 100.                              ! minimum value for aht
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zaht      = ( 1. -  MIN( 1., ABS( ff(ji,jj) / zf20 ) ) ) * ( aht0 - zaht_min )  &
+                  &      + aht0 * upsrnfh(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.e0 ) THEN
+         aeiu(:,:) = 0.e0
+         aeiv(:,:) = 0.e0
+         aeiw(:,:) = 0.e0
+      ENDIF
+
+   END SUBROUTINE ldf_eiv
+
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Dummy module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ldf_eiv( kt )       ! Empty routine
+      WRITE(*,*) 'ldf_eiv: You should not have seen this print! error?', kt
+   END SUBROUTINE ldf_eiv
+#endif
+
+   !!======================================================================
+END MODULE ldfeiv
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfeiv_substitute.h90	(revision 4536)
@@ -0,0 +1,39 @@
+#if defined key_traldf_eiv   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!                   ***  ldfeiv_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsaei. the eddy induced velocity coeff.
+   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#  if defined key_traldf_c3d
+!   'traldf_c3d' :                           eiv: 3D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(i,j,k)
+#    define   fsaeiv(i,j,k)   aeiv(i,j,k)
+#    define   fsaeiw(i,j,k)   aeiw(i,j,k)
+#  elif defined key_traldf_c2d
+!   'traldf_c2d' :                           eiv: 2D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(i,j)
+#    define   fsaeiv(i,j,k)   aeiv(i,j)
+#    define   fsaeiw(i,j,k)   aeiw(i,j)
+#  elif defined key_traldf_c1d
+!   'traldf_c1d' :                           eiv: 1D coefficient
+#    define   fsaeiu(i,j,k)   aeiu(k)
+#    define   fsaeiv(i,j,k)   aeiv(k)
+#    define   fsaeiw(i,j,k)   aeiw(k)
+#  else
+!   Default option :                          eiv: Constant coefficient
+#    define   fsaeiu(i,j,k)   aeiv0
+#    define   fsaeiv(i,j,k)   aeiv0
+#    define   fsaeiw(i,j,k)   aeiv0
+#  endif
+#else
+!   Default option :                         eiv: dummy variables
+#    define   fsaeiu(i,j,k)   aeiv0
+#    define   fsaeiv(i,j,k)   aeiv0
+#    define   fsaeiw(i,j,k)   aeiv0
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfslp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 4536)
@@ -0,0 +1,768 @@
+MODULE ldfslp
+   !!======================================================================
+   !!                       ***  MODULE  ldfslp  ***
+   !! Ocean physics: slopes of neutral surfaces
+   !!======================================================================
+#if   defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'                      Rotation of lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   ldf_slp      : compute the slopes of neutral surface
+   !!   ldf_slp_mxl  : compute the slopes of iso-neutral surface
+   !!   ldf_slp_init : initialization of the slopes computation
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce
+   USE ldfdyn_oce
+   USE phycst          ! physical constants
+   USE zdfmxl          ! mixed layer depth
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC ldf_slp        ! routine called by step.F90
+
+   !! * Share module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_ldfslp = .TRUE.     !: slopes flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      uslp, wslpi,         &  !: i_slope at U- and W-points
+      vslp, wslpj             !: j-slope at V- and W-points
+   
+   !! * Module variables
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      omlmask                 ! mask of the surface mixed layer at T-pt
+   REAL(wp), DIMENSION(jpi,jpj) ::   &
+      uslpml, wslpiml,     &  ! i_slope at U- and W-points just below
+   !                          ! the surface mixed layer
+      vslpml, wslpjml         ! j_slope at V- and W-points just below
+   !                          ! the surface mixed layer
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ldf_slp( kt, prd, pn2 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldf_slp  ***
+      !! 
+      !! ** Purpose :   Compute the slopes of neutral surface (slope of iso-
+      !!      pycnal surfaces referenced locally) ('key_traldfiso').
+      !!
+      !! ** Method  :   The slope in the i-direction is computed at U- and 
+      !!      W-points (uslp, wslpi) and the slope in the j-direction is 
+      !!      computed at V- and W-points (vslp, wslpj).
+      !!      They are bounded by 1/100 over the whole ocean, and within the
+      !!      surface layer they are bounded by the distance to the surface
+      !!      ( slope<= depth/l  where l is the length scale of horizontal
+      !!      diffusion (here, aht=2000m2/s ==> l=20km with a typical velocity
+      !!      of 10cm/s)
+      !!        A horizontal shapiro filter is applied to the slopes
+      !!        ln_sco=T, s-coordinate, add to the previously computed slopes
+      !!      the slope of the model level surface.
+      !!        macro-tasked on horizontal slab (jk-loop)  (2, jpk-1)
+      !!      [slopes already set to zero at level 1, and to zero or the ocean
+      !!      bottom slope (ln_sco=T) at level jpk in inildf]
+      !!
+      !! ** Action : - uslp, wslpi, and vslp, wslpj, the i- and  j-slopes 
+      !!               of now neutral surfaces at u-, w- and v- w-points, resp.
+      !!
+      !! History :
+      !!   7.0  !  94-12  (G. Madec, M. Imbard)  Original code
+      !!   8.0  !  97-06  (G. Madec)  optimization, lbc
+      !!   8.1  !  99-10  (A. Jouzeau)  NEW profile
+      !!   8.5  !  99-10  (G. Madec)  Free form, F90
+      !!   9.0  !  05-10  (A. Beckmann)  correction for s-coordinates
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce            , zgru  => ua,  &  ! use ua as workspace
+                           zgrv  => va,  &  ! use va as workspace
+                           zwy   => ta,  &  ! use ta as workspace
+                           zwz   => sa      ! use sa as workspace
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         prd,                            &  ! in situ density
+         pn2                                ! Brunt-Vaisala frequency (locally ref.)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      INTEGER  ::   ii0, ii1, ij0, ij1,  &  ! temporary integer
+         &          iku, ikv                !    "          "
+      REAL(wp) ::   &
+         zeps, zmg, zm05g,               &  ! temporary scalars
+         zcoef1, zcoef2, zcoef3,         &  !
+         zau, zbu, zav, zbv,             &
+         zai, zbi, zaj, zbj,             &
+         zcofu, zcofv, zcofw,            &
+         z1u, z1v, z1wu, z1wv,           &
+         zalpha
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zww
+      !!----------------------------------------------------------------------
+
+      
+      ! 0. Initialization (first time-step only)
+      !    --------------
+      
+      IF( kt == nit000 ) CALL ldf_slp_init
+      
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      
+      zeps  =  1.e-20
+      zmg   = -1.0 / grav
+      zm05g = -0.5 / grav
+
+      zww(:,:,:) = 0.e0
+      zwz(:,:,:) = 0.e0
+
+      ! horizontal density gradient computation
+      DO jk = 1, jpk
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zgru(ji,jj,jk) = umask(ji,jj,jk) * ( prd(ji+1,jj  ,jk) - prd(ji,jj,jk) ) 
+               zgrv(ji,jj,jk) = vmask(ji,jj,jk) * ( prd(ji  ,jj+1,jk) - prd(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      IF( ln_zps ) THEN      ! partial steps correction at the bottom ocean level (zps_hde routine)
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               ! last ocean level
+               iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj) ) - 1
+               ikv = MIN ( mbathy(ji,jj), mbathy(ji,jj+1) ) - 1
+               zgru(ji,jj,iku) = gru(ji,jj) 
+               zgrv(ji,jj,ikv) = grv(ji,jj)               
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+      ENDIF
+
+      ! Slopes of isopycnal surfaces just below the mixed layer
+      ! -------------------------------------------------------
+      
+      CALL ldf_slp_mxl( prd, pn2 )
+      
+      !-------------------synchro---------------------------------------------
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! I.  slopes at u and v point
+         ! ===========================
+         
+         
+         ! I.1. Slopes of isopycnal surfaces
+         ! ---------------------------------
+         ! uslp = d/di( prd ) / d/dz( prd )
+         ! vslp = d/dj( prd ) / d/dz( prd )
+         
+         ! Local vertical density gradient evaluated from N^2
+         ! zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwy(ji,jj,jk) = zmg * ( prd(ji,jj,jk) + 1. )                &
+                  &          * ( pn2(ji,jj,jk) + pn2(ji,jj,jk+1) )       &
+                  &          / MAX( tmask(ji,jj,jk) + tmask (ji,jj,jk+1), 1. )
+            END DO
+         END DO
+         
+         ! Slope at u and v points
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal and vertical density gradient at u- and v-points
+               zau = 1. / e1u(ji,jj) * zgru(ji,jj,jk)
+               zav = 1. / e2v(ji,jj) * zgrv(ji,jj,jk)
+               zbu = 0.5 * ( zwy(ji,jj,jk) + zwy(ji+1,jj  ,jk) )
+               zbv = 0.5 * ( zwy(ji,jj,jk) + zwy(ji  ,jj+1,jk) )
+               ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+               !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+               zbu = MIN( zbu, -100.*ABS( zau ), -7.e+3/fse3u(ji,jj,jk)*ABS( zau ) )
+               zbv = MIN( zbv, -100.*ABS( zav ), -7.e+3/fse3v(ji,jj,jk)*ABS( zav ) )
+               ! uslp and vslp output in zwz and zww, resp.
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji+1,jj,jk) )
+               zwz (ji,jj,jk) = ( zau / ( zbu - zeps ) * ( 1. - zalpha)   &
+                  &           + zalpha * uslpml(ji,jj)                    &
+                  &                    * 0.5 * ( fsdept(ji+1,jj,jk)+fsdept(ji,jj,jk)-fse3u(ji,jj,1) )   &
+                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 5. ) ) * umask(ji,jj,jk)
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji,jj+1,jk) )
+               zww (ji,jj,jk) = ( zav / ( zbv - zeps ) * ( 1. - zalpha)   &
+                  &           + zalpha * vslpml(ji,jj)                    &
+                  &                    * 0.5 * ( fsdept(ji,jj+1,jk)+fsdept(ji,jj,jk)-fse3v(ji,jj,1) )   &
+                  &                          / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 5. ) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============
+
+
+         ! lateral boundary conditions on zww and zwz
+         CALL lbc_lnk( zwz, 'U', -1. )
+         CALL lbc_lnk( zww, 'V', -1. )
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         
+         ! Shapiro filter applied in the horizontal direction
+         zcofu = 1. / 16.
+         zcofv = 1. / 16.
+         DO jj = 2, jpjm1, jpj-3   ! row jj=2 and =jpjm1 only
+            DO ji = 2, jpim1  
+               !uslop
+               uslp(ji,jj,jk) = zcofu * (       zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)      &
+                  &                       +     zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)      &
+                  &                       + 2.*(zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)      &
+                  &                       +     zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )    &
+                  &                       + 4.* zwz(ji  ,jj  ,jk)                       )
+               ! vslop
+               vslp(ji,jj,jk) = zcofv * (       zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)      &
+                  &                       +     zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)      &
+                  &                       + 2.*(zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)      &
+                  &                       +     zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )    &
+                  &                       + 4.* zww(ji,jj    ,jk)                       )
+            END DO
+         END DO
+
+         DO jj = 3, jpj-2
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! uslop
+               uslp(ji,jj,jk) = zcofu * (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)      &
+                  &                       +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)      &
+                  &                       + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)      &
+                  &                       +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )    &
+                  &                       + 4.*  zwz(ji  ,jj  ,jk)                       )
+               ! vslop
+               vslp(ji,jj,jk) = zcofv * (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)      &
+                  &                       +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)      &
+                  &                       + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)      &
+                  &                       +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )    &
+                  &                       + 4.*  zww(ji,jj    ,jk)                       )
+            END DO
+         END DO
+
+         ! decrease along coastal boundaries
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z1u  = ( umask(ji,jj+1,jk) + umask(ji,jj-1,jk) )*.5
+               z1v  = ( vmask(ji+1,jj,jk) + vmask(ji-1,jj,jk) )*.5
+               z1wu = ( umask(ji,jj,jk)   + umask(ji,jj,jk+1) )*.5
+               z1wv = ( vmask(ji,jj,jk)   + vmask(ji,jj,jk+1) )*.5
+               uslp(ji,jj,jk) = uslp(ji,jj,jk) * z1u * z1wu
+               vslp(ji,jj,jk) = vslp(ji,jj,jk) * z1v * z1wv
+            END DO
+         END DO
+
+
+         ! II. Computation of slopes at w point
+         ! ====================================
+         
+         
+         ! II.1 Slopes of isopycnal surfaces
+         ! ---------------------------------
+         ! wslpi = mij( d/di( prd ) / d/dz( prd )
+         ! wslpj = mij( d/dj( prd ) / d/dz( prd )
+         
+         
+         ! Local vertical density gradient evaluated from N^2
+         !     zwy = d/dz(prd)= - mk ( prd ) / grav * pn2 -- at w point
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwy (ji,jj,jk) = zm05g * pn2 (ji,jj,jk) *   &
+                  &                     ( prd (ji,jj,jk) + prd (ji,jj,jk-1) + 2. )
+            END DO
+         END DO
+         
+         ! Slope at w point
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal density i-gradient at w-points
+               zcoef1 = MAX( zeps, umask(ji-1,jj,jk  )+umask(ji,jj,jk  )    &
+                  &               +umask(ji-1,jj,jk-1)+umask(ji,jj,jk-1) )
+               zcoef1 = 1. / ( zcoef1 * e1t (ji,jj) )
+               zai = zcoef1 * (  zgru(ji  ,jj,jk  ) + zgru(ji  ,jj,jk-1)   &
+                  &            + zgru(ji-1,jj,jk-1) + zgru(ji-1,jj,jk  ) ) * tmask (ji,jj,jk)
+               ! horizontal density j-gradient at w-points
+               zcoef2 = MAX( zeps, vmask(ji,jj-1,jk  )+vmask(ji,jj,jk-1)   &
+                  &               +vmask(ji,jj-1,jk-1)+vmask(ji,jj,jk  ) )
+               zcoef2 = 1.0 / ( zcoef2 *  e2t (ji,jj) )
+               zaj = zcoef2 * (  zgrv(ji,jj  ,jk  ) + zgrv(ji,jj  ,jk-1)   &
+                  &            + zgrv(ji,jj-1,jk-1) + zgrv(ji,jj-1,jk  ) ) * tmask (ji,jj,jk)
+               ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
+               !                   static instability:
+               !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+               zbi = MIN( zwy (ji,jj,jk),- 100.*ABS(zai), -7.e+3/fse3w(ji,jj,jk)*ABS(zai) )
+               zbj = MIN( zwy (ji,jj,jk), -100.*ABS(zaj), -7.e+3/fse3w(ji,jj,jk)*ABS(zaj) )
+               ! wslpi and wslpj output in zwz and zww, resp.
+               zalpha = MAX( omlmask(ji,jj,jk), omlmask(ji,jj,jk-1) )
+               zcoef3 = fsdepw(ji,jj,jk) / MAX( hmlp(ji,jj), 10. )
+               zwz(ji,jj,jk) = (     zai / ( zbi - zeps)  * ( 1. - zalpha )   &
+                  &             + zcoef3 * wslpiml(ji,jj) *        zalpha   ) * tmask (ji,jj,jk)
+               zww(ji,jj,jk) = (     zaj / ( zbj - zeps)  * ( 1. - zalpha )   &
+                  &             + zcoef3 * wslpjml(ji,jj) *        zalpha   ) * tmask (ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============
+
+
+      ! lateral boundary conditions on zwz and zww
+      CALL lbc_lnk( zwz, 'T', -1. )
+      CALL lbc_lnk( zww, 'T', -1. )
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! Shapiro filter applied in the horizontal direction
+
+         DO jj = 2, jpjm1, jpj-3   ! row jj=2 and =jpjm1
+            DO ji = 2, jpim1
+               zcofw = tmask(ji,jj,jk)/16.
+               wslpi(ji,jj,jk) = (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)     &
+                  &                +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)     &
+                  &                + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)     &
+                  &                +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zwz(ji  ,jj  ,jk)                        ) * zcofw
+
+               wslpj(ji,jj,jk) = (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)     &
+                  &                +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)     &
+                  &                + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)     &
+                  &                +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zww(ji  ,jj  ,jk)                        ) * zcofw
+            END DO
+         END DO
+         
+         DO jj = 3, jpj-2
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcofw = tmask(ji,jj,jk)/16.
+               wslpi(ji,jj,jk) = (        zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk)     &
+                  &                +      zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk)     &
+                  &                + 2.*( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj  ,jk)     &
+                  &                +      zwz(ji+1,jj  ,jk) + zwz(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zwz(ji  ,jj  ,jk)                        ) * zcofw
+
+               wslpj(ji,jj,jk) = (        zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk)     &
+                  &                +      zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk)     &
+                  &                + 2.*( zww(ji  ,jj-1,jk) + zww(ji-1,jj  ,jk)     &
+                  &                +      zww(ji+1,jj  ,jk) + zww(ji  ,jj+1,jk) )   &
+                  &                + 4.*  zww(ji  ,jj  ,jk)                        ) * zcofw
+            END DO
+         END DO
+         
+         ! decrease the slope along the boundaries
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z1u = ( umask(ji,jj,jk) + umask(ji-1,jj,jk) ) *.5
+               z1v = ( vmask(ji,jj,jk) + vmask(ji,jj-1,jk) ) *.5
+               wslpi(ji,jj,jk) = wslpi(ji,jj,jk) * z1u * z1v
+               wslpj(ji,jj,jk) = wslpj(ji,jj,jk) * z1u * z1v
+            END DO
+         END DO
+         
+         
+         ! III. Specific grid points
+         ! -------------------------
+
+         IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN
+            !                                        ! =======================
+            ! Horizontal diffusion in                !  ORCA_R4 configuration 
+            ! specific area                          ! =======================
+            !
+            !                                             ! Gibraltar Strait
+            ij0 =  50   ;   ij1 =  53
+            ii0 =  69   ;   ii1 =  71   ;   uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ij0 =  51   ;   ij1 =  53
+            ii0 =  68   ;   ii1 =  71   ;   vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  69   ;   ii1 =  71   ;   wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  69   ;   ii1 =  71   ;   wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+
+            !                                             ! Mediterrannean Sea
+            ij0 =  49   ;   ij1 =  56
+            ii0 =  71   ;   ii1 =  90   ;   uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ij0 =  50   ;   ij1 =  56
+            ii0 =  70   ;   ii1 =  90   ;   vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  71   ;   ii1 =  90   ;   wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+            ii0 =  71   ;   ii1 =  90   ;   wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , jk ) = 0.e0
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   end of slab
+      !                                                ! ===============       
+
+      
+      ! III Lateral boundary conditions on all slopes (uslp , vslp, 
+      ! -------------------------------                wslpi, wslpj )
+      CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
+      CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab3d_1=uslp , clinfo1=' slp  - u : ', tab3d_2=vslp,  clinfo2=' v : ', kdim=jpk)
+         CALL prt_ctl(tab3d_1=wslpi, clinfo1=' slp  - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE ldf_slp
+
+
+   SUBROUTINE ldf_slp_mxl( prd, pn2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_slp_mxl  ***
+      !! ** Purpose :
+      !!     Compute the slopes of iso-neutral surface (slope of isopycnal
+      !!   surfaces referenced locally) just above the mixed layer.
+      !!
+      !! ** Method :
+      !!      The slope in the i-direction is computed at u- and w-points
+      !!   (uslp, wslpi) and the slope in the j-direction is computed at
+      !!   v- and w-points (vslp, wslpj).
+      !!   They are bounded by 1/100 over the whole ocean, and within the
+      !!   surface layer they are bounded by the distance to the surface
+      !!   ( slope<= depth/l  where l is the length scale of horizontal
+      !!   diffusion (here, aht=2000m2/s ==> l=20km with a typical velocity
+      !!   of 10cm/s)
+      !!
+      !! ** Action :
+      !!      Compute uslp, wslpi, and vslp, wslpj, the i- and  j-slopes
+      !!   of now neutral surfaces at u-, w- and v- w-points, resp.
+      !!
+      !! History :
+      !!   8.1  !  99-10  (A. Jouzeau)  Original code
+      !!   8.5  !  99-10  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce           , zgru  => ua,  &  ! ua, va used as workspace and set to hor. 
+                          zgrv  => va      ! density gradient in ldf_slp
+
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         prd,                           &  ! in situ density
+         pn2                              ! Brunt-Vaisala frequency (locally ref.)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   ik, ikm1               ! temporary integers
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zwy                               ! temporary workspace
+      REAL(wp) ::   &
+         zeps, zmg, zm05g,              &  ! temporary scalars
+         zcoef1, zcoef2,                &  !    "         "
+         zau, zbu, zav, zbv,            &  !    "         "
+         zai, zbi, zaj, zbj                !    "         "
+      !!----------------------------------------------------------------------
+
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+
+      zeps  =  1.e-20
+      zmg   = -1.0 / grav
+      zm05g = -0.5 / grav
+
+
+      uslpml (1,:) = 0.e0      ;      uslpml (jpi,:) = 0.e0
+      vslpml (1,:) = 0.e0      ;      vslpml (jpi,:) = 0.e0
+      wslpiml(1,:) = 0.e0      ;      wslpiml(jpi,:) = 0.e0
+      wslpjml(1,:) = 0.e0      ;      wslpjml(jpi,:) = 0.e0
+
+      ! surface mixed layer mask
+
+      ! mask for mixed layer
+      DO jk = 1, jpk
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+# endif
+               ! mixed layer interior (mask = 1) and exterior (mask = 0)
+               ik = nmln(ji,jj) - 1
+               IF( jk <= ik ) THEN
+                  omlmask(ji,jj,jk) = 1.e0
+               ELSE
+                  omlmask(ji,jj,jk) = 0.e0
+               ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+      END DO
+
+
+      ! Slopes of isopycnal surfaces just before bottom of mixed layer
+      ! --------------------------------------------------------------
+      ! uslpml = d/di( prd ) / d/dz( prd )
+      ! vslpml = d/dj( prd ) / d/dz( prd )
+
+      ! Local vertical density gradient evaluated from N^2
+      ! zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+
+      !-----------------------------------------------------------------------
+      zwy(:,jpj) = 0.e0
+      zwy(jpi,:) = 0.e0
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji+1,jj) )
+            ! if ik = jpk take jpkm1 values
+            ik = MIN( ik,jpkm1 )
+            zwy(ji,jj) = zmg * ( prd(ji,jj,ik) + 1. )   &
+               &             * ( pn2(ji,jj,ik) + pn2(ji,jj,ik+1) )   &
+               &             / MAX( tmask(ji,jj,ik) + tmask (ji,jj,ik+1), 1. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+      ! lateral boundary conditions on zwy
+      CALL lbc_lnk( zwy, 'U', -1. )
+
+      ! Slope at u points
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ! horizontal and vertical density gradient at u-points
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji+1,jj) )
+            ik = MIN( ik,jpkm1 )
+            zau = 1./ e1u(ji,jj) * zgru(ji,jj,ik)
+            zbu = 0.5*( zwy(ji,jj) + zwy(ji+1,jj) )
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+            !                         kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbu = MIN( zbu, -100.*ABS(zau), -7.e+3/fse3u(ji,jj,ik)*ABS(zau) )
+            ! uslpml
+            uslpml (ji,jj) = zau / ( zbu - zeps ) * umask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on uslpml
+      CALL lbc_lnk( uslpml, 'U', -1. )
+
+      ! Local vertical density gradient evaluated from N^2
+      !     zwy = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
+      zwy ( :, jpj) = 0.e0
+      zwy ( jpi, :) = 0.e0
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji,jj+1) )
+            ik = MIN( ik,jpkm1 )
+            zwy(ji,jj) = zmg * ( prd(ji,jj,ik) + 1. )   &
+               &             * ( pn2(ji,jj,ik) + pn2(ji,jj,ik+1) )   &
+               &             / MAX( tmask(ji,jj,ik) + tmask (ji,jj,ik+1), 1. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on zwy
+      CALL lbc_lnk( zwy, 'V', -1. )
+
+      ! Slope at v points
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ! horizontal and vertical density gradient at v-points
+            ik = MAX( 1, nmln(ji,jj) , nmln(ji,jj+1) )
+            ik = MIN( ik,jpkm1 )
+            zav = 1./ e2v(ji,jj) * zgrv(ji,jj,ik)
+            zbv = 0.5*( zwy(ji,jj) + zwy(ji,jj+1) )
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
+            !                         kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbv = MIN( zbv, -100.*ABS(zav), -7.e+3/fse3v(ji,jj,ik)*ABS( zav ) )
+            ! vslpml
+            vslpml (ji,jj) = zav / ( zbv - zeps ) * vmask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on vslpml
+      CALL lbc_lnk( vslpml, 'V', -1. )
+
+      ! wslpiml = mij( d/di( prd ) / d/dz( prd )
+      ! wslpjml = mij( d/dj( prd ) / d/dz( prd )
+
+
+      ! Local vertical density gradient evaluated from N^2
+      ! zwy = d/dz(prd)= - mk ( prd ) / grav * pn2 -- at w point
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+# endif
+            ik = nmln(ji,jj)+1
+            ik = MIN( ik,jpk )
+            ikm1 = MAX ( 1, ik-1)
+            zwy (ji,jj) = zm05g * pn2 (ji,jj,ik) *     &
+               &             ( prd (ji,jj,ik) + prd (ji,jj,ikm1) + 2. )
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Slope at w point
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ik = nmln(ji,jj)+1
+            ik = MIN( ik,jpk )
+            ikm1 = MAX ( 1, ik-1)
+            ! horizontal density i-gradient at w-points
+            zcoef1 = MAX( zeps, umask(ji-1,jj,ik  )+umask(ji,jj,ik  )   &
+               &               +umask(ji-1,jj,ikm1)+umask(ji,jj,ikm1) )
+            zcoef1 = 1. / ( zcoef1 * e1t (ji,jj) )
+            zai = zcoef1 * (  zgru(ji  ,jj,ik  ) + zgru(ji  ,jj,ikm1)   &
+               &            + zgru(ji-1,jj,ikm1) + zgru(ji-1,jj,ik  ) ) * tmask (ji,jj,ik)
+            ! horizontal density j-gradient at w-points
+            zcoef2 = MAX( zeps, vmask(ji,jj-1,ik  )+vmask(ji,jj,ikm1)    &
+               &               +vmask(ji,jj-1,ikm1)+vmask(ji,jj,ik  ) )
+            zcoef2 = 1.0 / ( zcoef2 *  e2t (ji,jj) )
+            zaj = zcoef2 * (  zgrv(ji,jj  ,ik  ) + zgrv(ji,jj  ,ikm1)   &
+               &            + zgrv(ji,jj-1,ikm1) + zgrv(ji,jj-1,ik  ) ) * tmask (ji,jj,ik)
+            ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
+            !                   static instability:
+            !                   kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
+            zbi = MIN ( zwy (ji,jj),- 100.*ABS(zai), -7.e+3/fse3w(ji,jj,ik)*ABS(zai) )
+            zbj = MIN ( zwy (ji,jj), -100.*ABS(zaj), -7.e+3/fse3w(ji,jj,ik)*ABS(zaj) )
+            ! wslpiml and wslpjml
+            wslpiml (ji,jj) = zai / ( zbi - zeps) * tmask (ji,jj,ik)
+            wslpjml (ji,jj) = zaj / ( zbj - zeps) * tmask (ji,jj,ik)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! lateral boundary conditions on wslpiml and wslpjml
+      CALL lbc_lnk( wslpiml, 'W', -1. )
+      CALL lbc_lnk( wslpjml, 'W', -1. )
+
+   END SUBROUTINE ldf_slp_mxl
+
+
+   SUBROUTINE ldf_slp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_slp_init  ***
+      !!
+      !! ** Purpose :   Initialization for the isopycnal slopes computation
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameter 
+      !!      values called by tra_dmp at the first timestep (nit000)
+      !!
+      !! History :
+      !!  8.5  ! 02-06 (G. Madec) original code
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      
+      
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ldf_slp : direction of lateral mixing'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      ! Direction of lateral diffusion (tracers and/or momentum)
+      ! ------------------------------
+      ! set the slope to zero (even in s-coordinates)
+
+      uslp (:,:,:) = 0.e0
+      vslp (:,:,:) = 0.e0
+      wslpi(:,:,:) = 0.e0
+      wslpj(:,:,:) = 0.e0
+
+      uslpml (:,:) = 0.e0
+      vslpml (:,:) = 0.e0
+      wslpiml(:,:) = 0.e0
+      wslpjml(:,:) = 0.e0
+
+      IF( (ln_traldf_hor .OR. ln_dynldf_hor) .AND. .NOT. (lk_vvl .AND. ln_rstart) ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '          Horizontal mixing in s-coordinate: slope = slope of s-surfaces'
+         ENDIF
+
+         ! geopotential diffusion in s-coordinates on tracers and/or momentum
+         ! The slopes of s-surfaces are computed once (no call to ldfslp in step)
+         ! The slopes for momentum diffusion are i- or j- averaged of those on tracers
+
+         ! set the slope of diffusion to the slope of s-surfaces
+         !      ( c a u t i o n : minus sign as fsdep has positive value )
+         DO jk = 1, jpk
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  uslp (ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept(ji+1,jj,jk) - fsdept(ji ,jj ,jk) ) * umask(ji,jj,jk)
+                  vslp (ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept(ji,jj+1,jk) - fsdept(ji ,jj ,jk) ) * vmask(ji,jj,jk)
+                  wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw(ji+1,jj,jk) - fsdepw(ji-1,jj,jk) ) * tmask(ji,jj,jk) * 0.5
+                  wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw(ji,jj+1,jk) - fsdepw(ji,jj-1,jk) ) * tmask(ji,jj,jk) * 0.5
+               END DO
+            END DO
+         END DO
+
+         ! Lateral boundary conditions on the slopes
+         CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
+         CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
+      ENDIF
+
+   END SUBROUTINE ldf_slp_init
+
+#else
+   !!------------------------------------------------------------------------
+   !!   Dummy module :                 NO Rotation of lateral mixing tensor
+   !!------------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_ldfslp = .FALSE.    !: slopes flag
+CONTAINS
+   SUBROUTINE ldf_slp( kt, prd, pn2 )        ! Dummy routine
+      INTEGER, INTENT(in) :: kt 
+      REAL,DIMENSION(:,:,:), INTENT(in) :: prd, pn2
+      WRITE(*,*) 'ldf_slp: You should not have seen this print! error?', kt, prd(1,1,1), pn2(1,1,1)
+   END SUBROUTINE ldf_slp
+#endif
+
+   !!======================================================================
+END MODULE ldfslp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 4536)
@@ -0,0 +1,165 @@
+MODULE ldftra
+   !!======================================================================
+   !!                       ***  MODULE  ldftra  ***
+   !! Ocean physics:  lateral diffusivity coefficient 
+   !!=====================================================================
+   !! History :
+   !!        !  07-97  (G. Madec)  from inimix.F split in 2 routines
+   !!        !  08-97  (G. Madec)  multi dimensional coefficients
+   !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+   !!   9.0  !  05-11  (G. Madec)  
+   !!----------------------------------------------------------------------
+   !!   ldf_tra_init : initialization, namelist read, and parameters control
+   !!   ldf_tra_c3d   : 3D eddy viscosity coefficient initialization
+   !!   ldf_tra_c2d   : 2D eddy viscosity coefficient initialization
+   !!   ldf_tra_c1d   : 1D eddy viscosity coefficient initialization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE ldfslp          ! ???
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC ldf_tra_init   ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE ldf_tra_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_tra_init  ***
+      !! 
+      !! ** Purpose :   initializations of the tracer lateral mixing coeff.
+      !!
+      !! ** Method  :   the Eddy diffusivity and eddy induced velocity ceoff.
+      !!      are defined as follows:
+      !!         default option   : constant coef. aht0, aeiv0 (namelist)
+      !!        'key_traldf_c1d': depth dependent coef. defined in 
+      !!                            in ldf_tra_c1d routine
+      !!        'key_traldf_c2d': latitude and longitude dependent coef.
+      !!                            defined in ldf_tra_c2d routine
+      !!        'key_traldf_c3d': latitude, longitude, depth dependent coef.
+      !!                            defined in ldf_tra_c3d routine
+      !!
+      !!      N.B. User defined include files.  By default, 3d and 2d coef.
+      !!      are set to a constant value given in the namelist and the 1d
+      !!      coefficients are initialized to a hyperbolic tangent vertical
+      !!      profile.
+      !!
+      !!----------------------------------------------------------------------
+      USE ioipsl
+
+      INTEGER ::   ioptio               ! ???
+      LOGICAL ::   ll_print = .FALSE.   ! =T print eddy coef. in numout
+       
+      NAMELIST/nam_traldf/ ln_traldf_lap  , ln_traldf_bilap,                &
+         &                 ln_traldf_level, ln_traldf_hor, ln_traldf_iso,   &
+         &                 aht0, ahtb0, aeiv0
+      !!----------------------------------------------------------------------
+
+      !  Define the lateral tracer physics parameters
+      ! =============================================
+    
+      ! Read Namelist nam_traldf : Lateral physics on tracers
+      REWIND( numnam )
+      READ  ( numnam, nam_traldf )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ldf_tra_init : lateral tracer physics'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+         WRITE(numout,*) '          Namelist nam_traldf : lateral mixing coefficients'
+         WRITE(numout,*) '             laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
+         WRITE(numout,*) '             bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
+         WRITE(numout,*) '             lateral eddy diffusivity             aht0   = ', aht0
+         WRITE(numout,*) '             background hor. diffusivity          ahtb0  = ', ahtb0
+         WRITE(numout,*) '             eddy induced velocity coef.          aeiv0  = ', aeiv0
+         WRITE(numout,*)
+      ENDIF
+
+      ! Parameter control
+
+      ! ... Check consistency for type and direction :
+      !           ==> will be done in traldf module
+
+      ! ... Space variation of eddy coefficients
+      ioptio = 0
+#if defined key_traldf_c3d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( latitude, longitude, depth)'
+      ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c2d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( latitude, longitude)'
+      ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c1d
+      IF(lwp) WRITE(numout,*) '          tracer mixing coef. = F( depth )'
+      ioptio = ioptio + 1
+      IF( .NOT. ln_zco ) &
+           &   CALL ctl_stop( '          key_traldf_c1d can only be used in z-coordinate - full step' )
+#endif
+      IF( ioptio == 0 ) THEN
+          IF(lwp) WRITE(numout,*) '          tracer mixing coef. = constant (default option)'
+        ELSEIF( ioptio > 1 ) THEN
+           CALL ctl_stop('          use only one of the following keys:',   &
+             &           ' key_traldf_c3d, key_traldf_c2d, key_traldf_c1d' )
+      ENDIF
+
+      IF( ln_traldf_bilap ) THEN
+         IF(lwp) WRITE(numout,*) '          biharmonic tracer diffusion'
+         IF( aht0 > 0 .AND. .NOT. lk_esopa )   &
+              &   CALL ctl_stop( '          The horizontal diffusivity coef. aht0 must be negative' )
+      ELSE
+         IF(lwp) WRITE(numout,*) '          harmonic tracer diffusion (default)'
+         IF( aht0 < 0 .AND. .NOT. lk_esopa )   &
+              &   CALL ctl_stop('          The horizontal diffusivity coef. aht0 must be positive' )
+      ENDIF
+
+
+      !  Lateral eddy diffusivity and eddy induced velocity coefficients
+      ! ================================================================
+
+#if defined key_traldf_c3d
+      CALL ldf_tra_c3d( ll_print )      ! aht = 3D coef. = F( longitude, latitude, depth )
+#elif defined key_traldf_c2d
+      CALL ldf_tra_c2d( ll_print )      ! aht = 2D coef. = F( longitude, latitude )
+#elif defined key_traldf_c1d
+      CALL ldf_tra_c1d( ll_print )      ! aht = 1D coef. = F( depth )
+#else
+                                        ! Constant coefficients
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) '          constant eddy diffusivity coef.   ahtu = ahtv = ahtw = aht0 = ', aht0
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) '          constant eddy induced velocity coef.   aeiu = aeiv = aeiw = aeiv0 = ', aeiv0
+      ENDIF
+#endif
+
+   END SUBROUTINE ldf_tra_init
+
+#if defined key_traldf_c3d
+#   include "ldftra_c3d.h90"
+#elif defined key_traldf_c2d
+#   include "ldftra_c2d.h90"
+#elif defined key_traldf_c1d
+#   include "ldftra_c1d.h90"
+#endif
+
+   !!======================================================================
+END MODULE ldftra
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c1d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c1d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c1d.h90	(revision 4536)
@@ -0,0 +1,133 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldftra_c1d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_tra_c1d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldftra_c1d  ***
+      !!              
+      !! ** Purpose :   1D eddy diffusivity coefficient
+      !!
+      !! ** Method  :   1D eddy diffusivity coefficients ( depth )
+      !!       biharmonic operator    : ahtt = defined at T-level
+      !!                                ahtu,ahtv,ahtw never used
+      !!
+      !!       harmonic operator      : ahtt never used
+      !!          -1-  iso-model level: ahtu = ahtv defined at T-level
+      !!                                ahtw never used
+      !!          -2-  isopycnal or   : ahtu = ahtv defined at T-level
+      !!               geopotential     ahtw defined at w-level
+      !!
+      !!       eddy induced velocity
+      !!         always harmonic      : aeiu = aeiv defined at T-level
+      !!				  aeiw defined at w-level
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, print arrays in numout
+
+      !! * Local variables
+      INTEGER ::   jk                  ! dummy loop indices
+      REAL(wp) ::   &
+         zkah, zahr, za00 , za01,   &  ! temporary scalars
+         zahf, zahs, zahtf, zahts
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra_c1d : 1D eddy diffusivity and eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   -- ' 
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' inildf : 1D eddy diffusivity coefficient '
+         IF(lwp) WRITE(numout,*) ' ~~~~~~   -- '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! initialization of the profile
+
+      ! ahts, ahtf: surface and bottom values
+      zahts = aht0
+      zahtf = aht0/4. 
+      ! zkah, zahr: depth of the inflection pt and width of inflection
+      zkah =  -300.
+      zahr =   300.
+      ! computation coefficients
+      za00 = TANH( ( -fsdept(1,1,1  ) - zkah ) / zahr )
+      za01 = TANH( ( -fsdept(1,1,jpk) - zkah ) / zahr )
+      zahf = ( zahts-zahtf ) / ( za00 - za01 )
+      zahs = zahts - zahf * za00
+
+      ! biharmonic operator : (T-point)
+      ! ==================== 
+
+      ! set ahtt at T-level
+      DO jk = 1, jpk
+         ahtt(jk) = zahs + zahf * TANH( (-fsdept(1,1,jk)-zkah) / zahr )
+      END DO
+
+      ! control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         aht profile at T-level : '
+         WRITE(numout,*)
+         WRITE(numout,*) ' level    aht          depth t-level '
+         DO jk = 1, jpk
+            WRITE(numout,'(i6,2f12.4)') jk, ahtt(jk), fsdept(1,1,jk)
+         END DO
+      ENDIF
+
+      ! harmonic operator : (U-, V-, W-points)
+      ! ================== 
+
+      ! set ahtu = ahtv at T-level, and ahtw at w-level
+      DO jk = 1, jpk
+         ahtu(jk) = zahs + zahf * TANH( ( -fsdept(1,1,jk) - zkah ) / zahr )
+         ahtv(jk) = ahtu(jk)
+         ahtw(jk) = zahs + zahf * TANH( ( -fsdepw(1,1,jk) - zkah ) / zahr )
+      END DO
+
+      ! control print
+      IF(lwp .AND. ld_print ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aht profile at T-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' level    aht          depth t-level '
+         DO jk = 1, jpk
+            IF(lwp) WRITE(numout,"(i6,2f12.4)") jk, ahtu(jk), fsdept(1,1,jk)
+         END DO
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aht profile at W-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '  jk      aht          depth w-level '
+         DO jk = 1, jpk
+            IF(lwp)WRITE(numout,"(i6,2f12.4)") jk, ahtw(jk), fsdepw(1,1,jk)
+         END DO
+      ENDIF
+
+# if defined key_traldf_eiv
+      ! set aeiu = aeiv and set aeiw (here same profile as on aht)
+      aeiu(:) = ahtu(:)
+      aeiv(:) = aeiu(:)
+      aeiw(:) = ahtw(:)
+      
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '         aeiv profile at T-level : '
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '  jk      aeiv           depth t-level '
+         DO jk = 1, jpk
+            IF(lwp) WRITE(numout,"(i6,2f12.4)") jk, aeiu(jk), fsdept(1,1,jk)
+         END DO
+      ENDIF
+#endif
+
+   END SUBROUTINE ldf_tra_c1d
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c2d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c2d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c2d.h90	(revision 4536)
@@ -0,0 +1,153 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldftra_c2d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, print arrays in numout
+
+      !! * Local variables
+# if defined key_traldf_eiv && defined key_orca_r4
+      INTEGER ::   ji, jj                  ! dummy loop indices
+# endif
+# if defined key_orca_r4
+      INTEGER :: i1, i2, j1, j2
+# endif
+      REAL(wp) ::   za00, zdx_max
+      
+      !!----------------------------------------------------------------------
+
+      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'
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra2d : 2D eddy diffusivity coefficient'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --'
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      zdx_max = MAXVAL( e1t(:,:) )
+      IF( lk_mpp )   CALL mpp_max( zdx_max )   ! max over the global domain
+
+      ! harmonic operator : (U-, V-, W-points)
+      ! ==================
+      IF( ln_traldf_lap ) THEN
+  
+         za00 = aht0 / zdx_max
+  
+!RB         ahtu(:,:) = za00 * e1u(:,:)               ! set ahtu = ahtv at u- and v-points,
+!RB         ahtv(:,:) = za00 * e1f(:,:)               ! and ahtw at w-point (idem T-point)
+!RB         ahtw(:,:) = za00 * e1t(:,:)               ! 
+         ahtu(:,:) = aht0                ! set ahtu = ahtv at u- and v-points,
+         ahtv(:,:) = aht0                ! and ahtw at w-point (idem T-point)
+         ahtw(:,:) = aht0                !
+
+
+
+         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. )
+
+         ! 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
+
+         za00 = aht0 / ( zdx_max * zdx_max * zdx_max )
+         ahtt(:,:) = za00 * e1t(:,:) * e1t(:,:) *e1t(:,:)      ! set ahtt at T-point 
+
+         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: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c3d.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c3d.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_c3d.h90	(revision 4536)
@@ -0,0 +1,130 @@
+   !!----------------------------------------------------------------------
+   !!                        ***  ldftra_c3d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_tra_c3d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldftra_c3d  ***
+      !!                
+      !! ** Purpose :
+      !!     initializations of non uniform horizontal eddy diffusivity coef.
+      !!
+      !! ** Method :
+      !!      3D eddy diffusivity coefficients ( longitude, latitude, depth )
+      !!
+      !!       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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Arguments
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                   ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra_c3d : 3D eddy diffusivity and eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --  '
+         IF(lwp) WRITE(numout,*)
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra_c3d : 3D eddy diffusivity coefficient'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   -- '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+
+      ! biharmonic operator   (T-point)
+      ! -------------------
+
+      ahtt(:,:,:) = aht0              ! set ahtt at T-point (here no space variation)
+
+      CALL lbc_lnk( ahtt, 'T', 1. )   ! Lateral boundary conditions on ( ahtt )
+
+      IF(lwp .AND. ld_print ) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtt at k = 1'
+         CALL prihre( ahtt(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+      ENDIF
+
+
+      ! harmonic operator   (U-, V-, W-points)
+      ! ----------------- 
+
+      ahtu(:,:,:) = aht0              ! set ahtu = ahtv at u- and v-points,
+      ahtv(:,:,:) = aht0              ! and ahtw at w-point
+      ahtw(:,:,:) = aht0              ! (here example: no space variation)
+      
+      CALL lbc_lnk( ahtu, 'U', 1. )   ! Lateral boundary conditions
+      CALL lbc_lnk( ahtv, 'V', 1. )
+      CALL lbc_lnk( ahtw, 'W', 1. )
+
+      IF(lwp .AND. ld_print ) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtu at k = 1'
+         CALL prihre( ahtu(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtv at k = 1'
+         CALL prihre( ahtv(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: ahtw at k = 1'
+         CALL prihre( ahtw(:,:,1), jpi, jpj, 1, jpi, 1,   &
+            &                                1, jpj, 1, 1.e-3, numout )
+      ENDIF
+
+# if defined key_traldf_eiv
+      aeiu(:,:,:) = aeiv0            ! set aeiu = aeiv at u- and v-points,
+      aeiv(:,:,:) = aeiv0            ! and aeiw at w-point
+      aeiw(:,:,:) = aeiv0            ! (here example: no space variation)
+
+      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
+
+      CALL lbc_lnk( aeiu, 'U', 1. )   ! Lateral boundary conditions 
+      CALL lbc_lnk( aeiv, 'V', 1. )
+      CALL lbc_lnk( aeiw, 'W', 1. )
+# endif
+
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiu at k = 1'
+         CALL prihre(aeiu(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiv at k = 1'
+         CALL prihre(aeiv(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiw at k = 1'
+         CALL prihre(aeiw(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+
+END SUBROUTINE ldf_tra_c3d
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_oce.F90	(revision 4536)
@@ -0,0 +1,81 @@
+MODULE ldftra_oce
+   !!=====================================================================
+   !!                      ***  MODULE  ldftra_oce  ***
+   !! Ocean physics :  lateral tracer mixing coefficient defined in memory 
+   !!=====================================================================
+   !!
+   !! ** Purpose : - Define in memory lateral tracer mixing coefficients
+   !!
+   !! History :
+   !!   9.0  !  02-11  (G. Madec)  Original code (from common.h)
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !!----------------------------------------------------------------------
+   !! Lateral eddy diffusivity coefficients (tracers)
+   !!----------------------------------------------------------------------
+
+   LOGICAL , PUBLIC ::              & !!: ** lateral mixing namelist (nam_traldf) **
+      ln_traldf_lap   = .TRUE.  ,   &  !: laplacian operator
+      ln_traldf_bilap = .FALSE. ,   &  !: bilaplacian operator
+      ln_traldf_level = .FALSE. ,   &  !: iso-level direction
+      ln_traldf_hor   = .FALSE. ,   &  !: horizontal (geopotential) direction
+      ln_traldf_iso   = .TRUE.         !: iso-neutral direction
+
+   REAL(wp), PUBLIC ::              & !!: ** lateral mixing namelist (namldf) **
+      aht0  = 2000._wp     ,        &  !: lateral eddy diffusivity (m2/s)
+      ahtb0 =    0._wp     ,        &  !: lateral background eddy diffusivity (m2/s)
+      aeiv0 = 2000._wp                 !: eddy induced velocity coefficient (m2/s)
+
+#if defined key_traldf_c3d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !: ** 3D coefficients **
+#elif defined key_traldf_c2d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   &  !: ** 2D coefficients **
+#elif defined key_traldf_c1d
+   REAL(wp), PUBLIC, DIMENSION(jpk)         ::   &  !: ** 1D coefficients **
+#else
+   REAL(wp), PUBLIC                         ::   &  !: ** 0D coefficients **
+#endif
+      ahtt, ahtu, ahtv, ahtw                !: T-, U-, V-, W-points coefficients
+
+
+#if defined key_traldf_eiv
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_eiv'                              eddy induced velocity
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_traldf_eiv   = .TRUE.   !: eddy induced velocity flag
+      
+# if defined key_traldf_c3d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !: ** 3D coefficients **
+# elif defined key_traldf_c2d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)     ::   &  !: ** 2D coefficients **
+# elif defined key_traldf_c1d
+   REAL(wp), PUBLIC, DIMENSION(jpk)         ::   &  !: ** 1D coefficients **
+# else
+   REAL(wp), PUBLIC                         ::   &  !: ** 0D coefficients **
+# endif
+      aeiu, aeiv, aeiw                              !: U-, V-, W-points  induced velocity coef. (m2/s)
+
+# if defined key_diaeiv
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::    &  !:
+      u_eiv, v_eiv, w_eiv     !: The three component of the eddy induced velocity (m/s)
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                           NO eddy induced velocity
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_traldf_eiv   = .FALSE.   !: eddy induced velocity flag
+   REAL(wp), PUBLIC ::   aeiu, aeiv, aeiw
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE ldftra_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/LDF/ldftra_substitute.h90	(revision 4536)
@@ -0,0 +1,36 @@
+   !!----------------------------------------------------------------------
+   !!                    *** ldftra_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsaht. the eddy diffusivity coeff.
+   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_traldf_c3d
+!   'key_traldf_c3d' :                 aht: 3D coefficient
+#       define   fsahtt(i,j,k)   ahtt(i,j,k)
+#       define   fsahtu(i,j,k)   ahtu(i,j,k)
+#       define   fsahtv(i,j,k)   ahtv(i,j,k)
+#       define   fsahtw(i,j,k)   ahtw(i,j,k)
+#elif defined key_traldf_c2d
+!   'key_traldf_c2d' :                 aht: 2D coefficient
+#       define   fsahtt(i,j,k)   ahtt(i,j)
+#       define   fsahtu(i,j,k)   ahtu(i,j)
+#       define   fsahtv(i,j,k)   ahtv(i,j)
+#       define   fsahtw(i,j,k)   ahtw(i,j)
+#elif defined key_traldf_c1d
+!   'key_traldf_c1d' :                aht: 1D coefficient
+#       define   fsahtt(i,j,k)   ahtt(k)
+#       define   fsahtu(i,j,k)   ahtu(k)
+#       define   fsahtv(i,j,k)   ahtv(k)
+#       define   fsahtw(i,j,k)   ahtw(k)
+#else
+!   Default option :             aht: Constant coefficient
+#      define   fsahtt(i,j,k)   aht0
+#      define   fsahtu(i,j,k)   aht0
+#      define   fsahtv(i,j,k)   aht0
+#      define   fsahtw(i,j,k)   aht0
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_oce.F90	(revision 4536)
@@ -0,0 +1,356 @@
+MODULE obc_oce
+   !!==============================================================================
+   !!                       ***  MODULE obc_oce   ***
+   !! Open Boundary Cond. :   define related variables
+   !!==============================================================================
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+#if defined key_obc
+   !!----------------------------------------------------------------------
+   !!   'key_obc' :                                 Open Boundary Condition
+   !!----------------------------------------------------------------------
+   !! history :
+   !!  8.0   01/91   (CLIPPER)  Original code 
+   !!  8.5   06/02   (C. Talandier)  modules
+   !!        06/04   (F. Durand) ORCA2_ZIND config
+   !!        06/04   (F. Durand) Dimensions of arrays vsdta, tsdta, ssdta,
+   !!                vndta, tndta, sndta, uwdta, twdta, swdta, uedta, tedta, sedta
+   !!                are defined to the actual dimensions of the OBs i.e. 
+   !!		     (jpisd:jpisf,jpk,jptobc) for the South OB
+   !! 		     (jpind:jpinf,jpk,jptobc) for the North OB 
+   !!		     (jpjwd:jpjwf,jpk,jptobc) for the West OB
+   !! 		     (jpjed:jpjef,jpk,jptobc) for the East OB
+   !!                 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+   USE obc_par         ! open boundary condition parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !! open boundary variables
+   !!----------------------------------------------------------------------
+   !!
+   !!General variables for open boundaries:
+   !!--------------------------------------
+   INTEGER ::              & !: * namelist ??? *
+      nbobc    = 2  ,      & !: number of open boundaries ( 1=< nbobc =< 4 ) 
+      nobc_dta = 0           !:  = 0 use the initial state as obc data
+      !                      !   = 1 read obc data in obcxxx.dta files
+
+   LOGICAL ::  ln_obc_clim = .true.  !:  obc data files are climatological
+   LOGICAL ::  ln_obc_fla  = .false. !:  Flather open boundary condition not used
+   LOGICAL ::  ln_vol_cst  = .true.  !:  Conservation of the whole volume
+
+   REAL(wp) ::             & !!: open boundary namelist (namobc)
+      rdpein =  1.  ,      &  !: damping time scale for inflow at East open boundary
+      rdpwin =  1.  ,      &  !:    "                      "   at West open boundary
+      rdpsin =  1.  ,      &  !:    "                      "   at South open boundary
+      rdpnin =  1.  ,      &  !:    "                      "   at North open boundary
+      rdpeob = 15.  ,      &  !: damping time scale for the climatology at East open boundary
+      rdpwob = 15.  ,      &  !:    "                           "       at West open boundary
+      rdpsob = 15.  ,      &  !:    "                           "       at South open boundary
+      rdpnob = 15.  ,      &  !:    "                           "       at North open boundary
+      volemp =  1.            !: = 0 the total volume will have the variability of the 
+                              !      surface Flux E-P else (volemp = 1) the volume will be constant
+                              !  = 1 the volume will be constant during all the integration.
+
+   LOGICAL ::              &  !:
+      lfbceast, lfbcwest,  &  !: logical flag for a fixed East and West open boundaries       
+      lfbcnorth, lfbcsouth    !: logical flag for a fixed North and South open boundaries       
+      !                       !  These logical flags are set to 'true' if damping time 
+      !                       !  scale are set to 0 in the namelist, for both inflow and outflow).
+
+   REAL(wp), PUBLIC ::    &  !:
+      obcsurftot       !: Total lateral surface of open boundaries
+   
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) :: &  !:
+      obctmsk,            &  !: mask array identical to tmask, execpt along OBC where it is set to 0
+      !                      !  it used to calculate the cumulate flux E-P in the obcvol.F90 routine
+      obcumask, obcvmask     !: u-, v- Force filtering mask for the open
+      !                      !  boundary condition on grad D
+
+   !!----------------
+   !! Rigid lid case:
+   !!----------------
+   INTEGER ::   nbic !: number of isolated coastlines ( 0 <= nbic <= 3 )
+         
+   INTEGER, DIMENSION(jpnic,0:4,3) ::   &  !:
+      miic, mjic     !: position of isolated coastlines points
+
+   INTEGER, DIMENSION(0:4,3) ::   &  !:
+      mnic           !: number of points on isolated coastlines
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   &  !:
+      gcbob          !: right hand side of the barotropic elliptic equation associated
+      !              !  with the OBC
+                                             
+   REAL(wp), DIMENSION(jpi,jpj,3) ::   &  !:
+      gcfobc         !: coef. associated with the contribution of isolated coastlines 
+      !              !  to the right hand side of the barotropic elliptic equation
+
+   REAL(wp), DIMENSION(3) ::   &  !:
+      gcbic          !: time variation of the barotropic stream function along the 
+      !              !  isolated coastlines 
+
+   REAL(wp), DIMENSION(1) ::   &  !:
+      bsfic0         !: barotropic stream function on isolated coastline
+         
+   REAL(wp), DIMENSION(3) ::   &  !:
+      bsfic          !: barotropic stream function on isolated coastline
+         
+   !!--------------------
+   !! East open boundary:
+   !!--------------------
+   INTEGER ::   nie0  , nie1      !: do loop index in mpp case for jpieob
+   INTEGER ::   nie0p1, nie1p1    !: do loop index in mpp case for jpieob+1
+   INTEGER ::   nie0m1, nie1m1    !: do loop index in mpp case for jpieob-1
+   INTEGER ::   nje0  , nje1      !: do loop index in mpp case for jpjed, jpjef
+   INTEGER ::   nje0p1, nje1m1    !: do loop index in mpp case for jpjedp1,jpjefm1
+   INTEGER ::   nje1m2, nje0m1    !: do loop index in mpp case for jpjefm1-1,jpjed
+
+   REAL(wp), DIMENSION(jpj) ::    &  !:
+      bsfeob              !: now barotropic stream fuction computed at the OBC. The corres-
+      !                   ! ponding bsfn will be computed by the forward time step in dynspg.
+
+   REAL(wp), DIMENSION(jpj,3,3) ::   &  !:
+      bebnd               !: east boundary barotropic streamfunction over 3 rows
+      !                   ! and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpjed:jpjef) ::   &  !:
+      bfoe,             & !: now climatology of the east boundary barotropic stream function 
+      sshfoe,           & !: now climatology of the east boundary sea surface height
+      ubtfoe,vbtfoe       !: now climatology of the east boundary barotropic transport
+     
+   REAL(wp), DIMENSION(jpj,jpk) ::   &  !:
+      ufoe, vfoe,       & !: now climatology of the east boundary velocities 
+      tfoe, sfoe,       & !: now climatology of the east boundary temperature and salinity
+      uclie               !: baroclinic componant of the zonal velocity after radiation 
+      !                   ! in the obcdyn.F90 routine
+
+   REAL(wp), DIMENSION(jpjed:jpjef,jpj) ::   &  !:
+      sshfoe_b            !: east boundary ssh correction averaged over the barotropic loop
+                          !: (if Flather's algoritm applied at open boundary)
+
+   REAL(wp), DIMENSION(jpjed:jpjef,0:jptobc+1) ::   &  !:
+      sshedta, ubtedta    !: array used for interpolating monthly data on the east boundary
+
+   REAL(wp), DIMENSION(jpjed:jpjef,jpk,jptobc) ::   &  !:
+      uedta, tedta, sedta !: array used for interpolating monthly data on the east boundary
+
+   !!-------------------------------
+   !! Arrays for radiative East OBC: 
+   !!-------------------------------
+   REAL(wp), DIMENSION(jpj,jpk,3,3) ::   &  !:
+      uebnd, vebnd                  !: baroclinic u & v component of the velocity over 3 rows 
+                                    ! and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpj,jpk,2,2) ::   &  !:
+      tebnd, sebnd                  !: East boundary temperature and salinity over 2 rows 
+                                    ! and 2 time step (now and before)
+
+   REAL(wp), DIMENSION(jpj,jpk) ::   &  !:
+      u_cxebnd, v_cxebnd            !: Zonal component of the phase speed ratio computed with 
+                                    ! radiation of u and v velocity (respectively) at the 
+                                    ! east open boundary (u_cxebnd = cx rdt )
+
+   REAL(wp), DIMENSION(jpj,jpk) ::   &  !:
+      uemsk, vemsk, temsk           !: 2D mask for the East OB
+
+   ! Note that those arrays are optimized for mpp case 
+   ! (hence the dimension jpj is the size of one processor subdomain)
+
+   !!--------------------
+   !! West open boundary
+   !!--------------------
+   INTEGER ::   niw0  , niw1       !: do loop index in mpp case for jpiwob
+   INTEGER ::   niw0p1, niw1p1     !: do loop index in mpp case for jpiwob+1
+   INTEGER ::   njw0  , njw1       !: do loop index in mpp case for jpjwd, jpjwf
+   INTEGER ::   njw0p1, njw1m1     !: do loop index in mpp case for jpjwdp1,jpjwfm1
+   INTEGER ::   njw1m2, njw0m1     !: do loop index in mpp case for jpjwfm2,jpjwd
+
+   REAL(wp), DIMENSION(jpj) ::   &  !:
+      bsfwob              !: now barotropic stream fuction computed at the OBC. The corres-
+      !                   !  ponding bsfn will be computed by the forward time step in dynspg.
+
+   REAL(wp), DIMENSION(jpj,3,3) ::   &  !:
+      bwbnd               !: West boundary barotropic streamfunction over
+      !                   !  3 rows and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpjwd:jpjwf) ::   &  !:
+      bfow,             & !: now climatology of the west boundary barotropic stream function
+      sshfow,           & !: now climatology of the west boundary sea surface height
+      ubtfow,vbtfow       !: now climatology of the west boundary barotropic transport
+
+   REAL(wp), DIMENSION(jpj,jpk) ::   &  !:
+      ufow, vfow,       & !: now climatology of the west velocities 
+      tfow, sfow,       & !: now climatology of the west temperature and salinity
+      ucliw               !: baroclinic componant of the zonal velocity after the radiation 
+      !                   !  in the obcdyn.F90 routine
+
+   REAL(wp), DIMENSION(jpjwd:jpjwf,jpj) ::   &  !:
+      sshfow_b            !: west boundary ssh correction averaged over the barotropic loop
+                          !: (if Flather's algoritm applied at open boundary)
+
+   REAL(wp), DIMENSION(jpjwd:jpjwf,0:jptobc+1) ::   &  !:
+      sshwdta, ubtwdta    !: array used for interpolating monthly data on the west boundary
+
+   REAL(wp), DIMENSION(jpjwd:jpjwf,jpk,jptobc) ::   &  !:
+      uwdta, twdta, swdta !: array used for interpolating monthly data on the west boundary
+
+   !!-------------------------------
+   !! Arrays for radiative West OBC
+   !!-------------------------------
+   REAL(wp), DIMENSION(jpj,jpk,3,3) ::   &  !:
+      uwbnd, vwbnd                  !: baroclinic u & v components of the velocity over 3 rows 
+      !                             !  and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpj,jpk,2,2) ::   &  !:
+      twbnd, swbnd                  !: west boundary temperature and salinity over 2 rows and 
+      !                             !  2 time step (now and before)
+
+   REAL(wp), DIMENSION(jpj,jpk) ::    &  !:
+      u_cxwbnd, v_cxwbnd            !: Zonal component of the phase speed ratio computed with 
+      !                             !  radiation of zonal and meridional velocity (respectively) 
+      !                             !  at the west open boundary (u_cxwbnd = cx rdt )
+
+   REAL(wp), DIMENSION(jpj,jpk) ::    &  !:
+      uwmsk, vwmsk, twmsk           !: 2D mask for the West OB
+
+   ! Note that those arrays are optimized for mpp case 
+   ! (hence the dimension jpj is the size of one processor subdomain)
+
+   !!---------------------
+   !! North open boundary
+   !!---------------------
+   INTEGER ::   nin0  , nin1       !: do loop index in mpp case for jpind, jpinf
+   INTEGER ::   nin0p1, nin1m1     !: do loop index in mpp case for jpindp1, jpinfm1
+   INTEGER ::   nin1m2, nin0m1     !: do loop index in mpp case for jpinfm1-1,jpind
+   INTEGER ::   njn0  , njn1       !: do loop index in mpp case for jpnob
+   INTEGER ::   njn0p1, njn1p1     !: do loop index in mpp case for jpnob+1
+   INTEGER ::   njn0m1, njn1m1     !: do loop index in mpp case for jpnob-1
+
+   REAL(wp), DIMENSION(jpi) ::   &  !:
+      bsfnob              !: now barotropic stream fuction computed at the OBC. The corres-
+      !                   !  ponding bsfn will be computed by the forward time step in dynspg.
+
+   REAL(wp), DIMENSION(jpi,3,3) ::   &  !:
+      bnbnd               !: north boundary barotropic streamfunction over
+      !                   !  3 rows and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpind:jpinf) ::   &  !:
+      bfon,             & !: now climatology of the north boundary barotropic stream function
+      sshfon,           & !: now climatology of the north boundary sea surface height
+      ubtfon,vbtfon       !: now climatology of the north boundary barotropic transport
+
+   REAL(wp), DIMENSION(jpi,jpk) ::   &    !:
+      ufon, vfon,       & !: now climatology of the north boundary velocities
+      tfon, sfon,       & !: now climatology of the north boundary temperature and salinity
+      vclin               !: baroclinic componant of the meridian velocity after the radiation
+      !                   !  in yhe obcdyn.F90 routine
+
+   REAL(wp), DIMENSION(jpind:jpinf,jpj) ::   &  !:
+      sshfon_b            !: north boundary ssh correction averaged over the barotropic loop
+                          !: (if Flather's algoritm applied at open boundary)
+
+   REAL(wp), DIMENSION(jpind:jpinf,0:jptobc+1) ::   &  !:
+      sshndta, vbtndta   !: array used for interpolating monthly data on the north boundary
+
+   REAL(wp), DIMENSION(jpind:jpinf,jpk,jptobc) ::   &  !:
+      vndta, tndta, sndta !: array used for interpolating monthly data on the north boundary
+
+   !!--------------------------------
+   !! Arrays for radiative North OBC
+   !!--------------------------------
+   !!   
+   REAL(wp), DIMENSION(jpi,jpk,3,3) ::   &   !:
+      unbnd, vnbnd                  !: baroclinic u & v components of the velocity over 3
+      !                             !  rows and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpi,jpk,2,2) ::   &   !:
+      tnbnd, snbnd                  !: north boundary temperature and salinity over
+      !                             !  2 rows and 2 time step (now and before)
+
+   REAL(wp), DIMENSION(jpi,jpk) ::   &     !:
+      u_cynbnd, v_cynbnd            !: Meridional component of the phase speed ratio compu-
+      !                             !  ted with radiation of zonal and meridional velocity 
+      !                             !  (respectively) at the north OB (u_cynbnd = cx rdt )
+
+   REAL(wp), DIMENSION(jpi,jpk) ::   &  !:
+      unmsk, vnmsk, tnmsk           !: 2D mask for the North OB
+
+   ! Note that those arrays are optimized for mpp case 
+   ! (hence the dimension jpj is the size of one processor subdomain)
+   
+   !!---------------------
+   !! South open boundary
+   !!---------------------
+   INTEGER ::   nis0  , nis1       !: do loop index in mpp case for jpisd, jpisf
+   INTEGER ::   nis0p1, nis1m1     !: do loop index in mpp case for jpisdp1, jpisfm1
+   INTEGER ::   nis1m2, nis0m1     !: do loop index in mpp case for jpisfm1-1,jpisd
+   INTEGER ::   njs0  , njs1       !: do loop index in mpp case for jpsob
+   INTEGER ::   njs0p1, njs1p1     !: do loop index in mpp case for jpsob+1
+
+   REAL(wp), DIMENSION(jpi) ::    &   !:
+      bsfsob              !: now barotropic stream fuction computed at the OBC.The corres-
+      !                   !  ponding bsfn will be computed by the forward time step in dynspg.
+   REAL(wp), DIMENSION(jpi,3,3) ::   &   !:
+      bsbnd               !: south boundary barotropic stream function over
+      !                   !  3 rows and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpisd:jpisf) ::    &   !:
+      bfos,             & !: now climatology of the south boundary barotropic stream function
+      sshfos,           & !: now climatology of the south boundary sea surface height
+      ubtfos,vbtfos       !: now climatology of the south boundary barotropic transport
+
+   REAL(wp), DIMENSION(jpi,jpk) ::    &   !:
+      ufos, vfos,       & !: now climatology of the south boundary velocities 
+      tfos, sfos,       & !: now climatology of the south boundary temperature and salinity
+      vclis               !: baroclinic componant of the meridian velocity after the radiation 
+      !                   !  in the obcdyn.F90 routine
+
+   REAL(wp), DIMENSION(jpisd:jpisf,jpj) ::   &  !:
+      sshfos_b            !: south boundary ssh correction averaged over the barotropic loop
+                          !: (if Flather's algoritm applied at open boundary)
+
+   REAL(wp), DIMENSION(jpisd:jpisf,0:jptobc+1) ::    &    !:
+      sshsdta, vbtsdta    !: array used for interpolating monthly data on the south boundary
+
+   REAL(wp), DIMENSION(jpisd:jpisf,jpk,jptobc) ::    &    !:
+      vsdta, tsdta, ssdta   !: array used for interpolating monthly data on the south boundary
+
+   !!--------------------------------
+   !! Arrays for radiative South OBC
+   !!--------------------------------
+   !!                        computed by the forward time step in dynspg.
+   REAL(wp), DIMENSION(jpi,jpk,3,3) ::   &   !:
+      usbnd, vsbnd                  !: baroclinic u & v components of the velocity over 3 
+      !                             !  rows and 3 time step (now, before, and before before)
+
+   REAL(wp), DIMENSION(jpi,jpk,2,2) ::   &  !:
+      tsbnd, ssbnd                  !: south boundary temperature and salinity over
+      !                             !  2 rows and 2 time step (now and before)
+
+   REAL(wp), DIMENSION(jpi,jpk) ::   &  !:
+      u_cysbnd, v_cysbnd            !: Meridional component of the phase speed ratio compu-
+      !                             !  ted with radiation of zonal and meridional velocity 
+      !                             !  (repsectively) at the south OB (u_cynbnd = cx rdt )
+
+   REAL(wp), DIMENSION(jpi,jpk) ::   &  !:
+      usmsk, vsmsk, tsmsk           !: 2D mask for the South OB
+
+   ! Note that those arrays are optimized for mpp case 
+   ! (hence the dimension jpj is the size of one processor subdomain)
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE obc_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par.F90	(revision 4536)
@@ -0,0 +1,94 @@
+MODULE obc_par
+   !!==============================================================================
+   !!                  ***  MODULE obc_par   ***
+   !! Open Boundary Cond. :   define related parameters
+   !!==============================================================================
+#if defined key_obc
+   !!----------------------------------------------------------------------
+   !!   'key_obc' :                                 Open Boundary Condition
+   !!----------------------------------------------------------------------
+   !! history :
+   !!  8.0   01/91   (CLIPPER)  Original code 
+   !!  9.0   06/02   (C. Talandier)  modules
+   !!        06/04   (F. Durand) ORCA_R2_ZIND config
+   !!        06/04   (F. Durand) jptobc is defined as a parameter, 
+   !!	     	     in order to allow time-dependent OBCs fields on input
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_obc = .TRUE.   !: Ocean Boundary Condition flag
+
+# if defined key_eel_r5
+   !!----------------------------------------------------------------------
+   !!   'key_eel_r5' :                                 EEL R5 configuration
+   !!----------------------------------------------------------------------
+#    include "obc_par_EEL_R5.h90"
+
+# else
+   !!---------------------------------------------------------------------
+   !! open boundary parameter
+   !!---------------------------------------------------------------------
+   INTEGER, PARAMETER ::     &  !: time dimension of the BCS fields on input
+      jptobc  =	      2 
+   !! * EAST open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_east = .FALSE.     !: to active or not the East open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpieob  = jpiglo-2,    &  !: i-localization of the East open boundary (must be ocean U-point)
+      jpjed   =        2,    &  !: j-starting indice of the East open boundary (must be land T-point)
+      jpjef   = jpjglo-1,    &  !: j-ending   indice of the East open boundary (must be land T-point)
+      jpjedp1 =  jpjed+1,    &  !: first ocean point         "                 "
+      jpjefm1 =  jpjef-1        !: last  ocean point         "                 "
+
+   !! * WEST open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_west = .FALSE.     !: to active or not the West open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpiwob  =	       2,    &  !: i-localization of the West open boundary (must be ocean U-point)
+      jpjwd   =	       2,    &  !: j-starting indice of the West open boundary (must be land T-point)
+      jpjwf   = jpjglo-1,    &  !: j-ending   indice of the West open boundary (must be land T-point)
+      jpjwdp1 =  jpjwd+1,    &  !: first ocean point         "                 "
+      jpjwfm1 =  jpjwf-1        !: last  ocean point         "                 "
+
+   !! * NORTH open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_north = .FALSE.    !: to active or not the North open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpjnob  = jpjglo-2,    &  !: j-localization of the North open boundary (must be ocean V-point)
+      jpind   =        2,    &  !: i-starting indice of the North open boundary (must be land T-point)
+      jpinf   = jpiglo-1,    &  !: i-ending   indice of the North open boundary (must be land T-point)
+      jpindp1 =  jpind+1,    &  !: first ocean point         "                 "
+      jpinfm1 =  jpinf-1        !: last  ocean point         "                 "
+
+   !! * SOUTH open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_south = .FALSE.    !: to active or not the South open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpjsob  =        2,    &  !: j-localization of the South open boundary (must be ocean V-point)
+      jpisd   =        2,    &  !: i-starting indice of the South open boundary (must be land T-point)
+      jpisf   = jpiglo-1,    &  !: i-ending   indice of the South open boundary (must be land T-point)
+      jpisdp1 =  jpisd+1,    &  !: first ocean point         "                 "
+      jpisfm1 =  jpisf-1        !: last  ocean point         "                 "
+   
+   INTEGER, PARAMETER ::     &  !:
+      jpnic = 2700              !: maximum number of isolated coastlines points 
+
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                         NO open boundary condition
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_obc = .FALSE.  !: Ocean Boundary Condition flag
+#endif
+
+   !!======================================================================
+END MODULE obc_par
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par_EEL_R5.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par_EEL_R5.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_par_EEL_R5.h90	(revision 4536)
@@ -0,0 +1,56 @@
+   !!----------------------------------------------------------------------
+   !!                  ***  obc_par_EEL_R5.h90  ***
+   !!----------------------------------------------------------------------
+   !! open boundary parameter : EEL5 configuration
+   !!---------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   INTEGER, PARAMETER ::     &  !: time dimension for the BCS fields on input
+      jptobc  =	      2 
+
+   !! * EAST open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_east = .TRUE.      !: to active or not the East open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpieob  = jpiglo-2,    &  !: i-localization of the East open boundary (must be ocean U-point)
+      jpjed   =        2,    &  !: j-starting indice of the East open boundary (must be land T-point)
+      jpjef   = jpjglo-1,    &  !: j-ending   indice of the East open boundary (must be land T-point)
+      jpjedp1 =  jpjed+1,    &  !: first ocean point         "                 "
+      jpjefm1 =  jpjef-1        !: last  ocean point         "                 "
+
+   !! * WEST open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_west = .TRUE.      !: to active or not the West open boundary
+   INTEGER, PARAMETER ::     &
+      jpiwob  =	       2,    &  !: i-localization of the West open boundary (must be ocean U-point)
+      jpjwd   =	       2,    &  !: j-starting indice of the West open boundary (must be land T-point)
+      jpjwf   = jpjglo-1,    &  !: j-ending   indice of the West open boundary (must be land T-point)
+      jpjwdp1 =  jpjwd+1,    &  !: first ocean point         "                 "
+      jpjwfm1 =  jpjwf-1        !: last  ocean point         "                 "
+
+   !! * NORTH open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_north = .FALSE.    !: to active or not the North open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpjnob  = jpjglo-2,    &  !: j-localization of the North open boundary (must be ocean V-point)
+      jpind   =        2,    &  !: i-starting indice of the North open boundary (must be land T-point)
+      jpinf   = jpiglo-1,    &  !: i-ending   indice of the North open boundary (must be land T-point)
+      jpindp1 =  jpind+1,    &  !: first ocean point         "                 "
+      jpinfm1 =  jpinf-1        !: last  ocean point         "                 "
+
+   !! * SOUTH open boundary
+   LOGICAL, PARAMETER ::     &  !:
+      lp_obc_south = .FALSE.    !: to active or not the South open boundary
+   INTEGER, PARAMETER ::     &  !:
+      jpjsob  =        2,    &  !: j-localization of the South open boundary (must be ocean V-point)
+      jpisd   =        2,    &  !: i-starting indice of the South open boundary (must be land T-point)
+      jpisf   = jpiglo-1,    &  !: i-ending   indice of the South open boundary (must be land T-point)
+      jpisdp1 =  jpisd+1,    &  !: first ocean point         "                 "
+      jpisfm1 =  jpisf-1        !: last  ocean point         "                 "
+   
+   INTEGER, PARAMETER ::     &  !:
+      jpnic = 2700              !: maximum number of isolated coastlines points 
+   !!---------------------------------------------------------------------------------------------
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_vectopt_loop_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_vectopt_loop_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obc_vectopt_loop_substitute.h90	(revision 4536)
@@ -0,0 +1,30 @@
+   !!----------------------------------------------------------------------
+   !!                 ***  obc_vectopt_loop_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute the inner loop starting and inding indices 
+   !!      to allow unrolling of do-loop using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_vectopt_loop && defined key_obc && ! defined key_mpp_mpi && ! defined key_mpp_shmem
+#  define fs_niw0  jpiwob 
+#  define fs_niw1  jpiwob
+#  define fs_nie0  jpieob 
+#  define fs_nie1  jpieob
+#  define fs_njn0  jpjnob
+#  define fs_njn1  jpjnob
+#  define fs_njs0  jpjsob
+#  define fs_njs1  jpjsob
+#else
+#  define fs_niw0  niw0 
+#  define fs_niw1  niw1
+#  define fs_nie0  nie0 
+#  define fs_nie1  nie1
+#  define fs_njn0  njn0
+#  define fs_njn1  njn1
+#  define fs_njs0  njs0
+#  define fs_njs1  njs1
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obccli.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obccli.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obccli.F90	(revision 4536)
@@ -0,0 +1,230 @@
+MODULE obccli
+   !!======================================================================
+   !!                       ***  MODULE  obccli  ***
+   !! Ocean dynamics:   Baroclinic velocities on each open boundary
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+   !!   9.0  !  06-04 (R.Benshila, G. Madec)  zco, zps, sco coordinate
+   !!----------------------------------------------------------------------
+#if defined key_obc && defined key_dynspg_rl
+   !!----------------------------------------------------------------------
+   !!   'key_obc' and 'key_dynspg_rl' open boundary condition and rigid-lid
+   !!----------------------------------------------------------------------
+   !!   obc_cli_dyn : baroclinic componant after the radiation phase
+   !!   obc_cli_dta : baroclinic componant for the climatological velocities
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_cli    ! routine called in obcdyn.F90 and obcdta.F90 (rigid lid case)
+
+   INTERFACE obc_cli
+     MODULE PROCEDURE obc_cli_dyn, obc_cli_dta
+   END INTERFACE
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_cli_dyn( obvel, velcli, obd, obf, obtyp, obl)
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_cli_dyn  ***
+      !!                   
+      !! ** Purpose :   Compute the baroclinic velocities at the open boundaries.
+      !!
+      !! ** Method  :
+      !!      - Compute de barotropic velocity along the considered Open Boundary 
+      !!        and substract it to the total velocity to have baroclinic velotity.
+      !!      - obtyp must be set to | 0 when traiting an East or West OB 
+      !!                             | 1 when traiting a North or South OB.
+      !!      - obl is the lenght of the OB (jpi or jpj) 
+      !!
+      !!-----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   & ! OB localization:jpieob or jpiwob for East or West 
+         obd, obf,               & !                 jpjnob or jpjsob for North or South 
+         obl,                    & ! Lenght of the Open Boundary
+         obtyp                     ! Type of Open Boundary: zonal or Meridional 
+      REAL(wp), DIMENSION(:,:), INTENT( out) ::   &
+         velcli                    ! Baroclinic velocity calculated
+      REAL(wp), DIMENSION(:,:,:), INTENT( in ) ::   &
+         obvel                     ! ua or va velocities from obcdyn.F90 routine
+
+      !! * Local declarations
+      INTEGER ::   &   
+         ji, jj, jk, jle, jol         ! loop indices  
+      REAL(wp) ::   zcbl              ! Temporary Baroclinic velocity 
+      REAL(wp), DIMENSION(obl) ::   & 
+         zvelbtpe,                  & ! Barotropic velocity 
+         zhinv                        ! Invert of the local depth 1/H
+      REAL(wp), DIMENSION(obl,jpk) ::   &
+         zmskob,                    & ! Velocity mask
+         zvel                         ! 2D Local velocity on OB
+      REAL(wp), DIMENSION(obl,jpk) ::   &
+         ze3ob                        ! Vertical scale factor
+      !!--------------------------------------------------------------------------------
+
+      ! 0. Array initialization
+      ! -----------------------
+
+      zhinv (:)   = 0.e0
+      zmskob(:,:) = 0.e0
+      zvel  (:,:) = 0.e0
+      ze3ob (:,:) = 0.e0
+
+      IF( obtyp == 0 ) THEN            ! Meridional Open Boundary ( East or West OB )
+         DO ji = obd, obf
+            zhinv (:)   = hur  (ji,:)
+            zmskob(:,:) = umask(ji,:,:)
+            zvel  (:,:) = obvel(ji,:,:)
+            ze3ob (:,:) = fse3u(ji,:,:)
+         END DO
+      ELSE                             ! Zonal Open Boundary ( North or South OB )
+         DO jj = obd, obf
+            zhinv (:)   = hvr  (:,jj)
+            zmskob(:,:) = vmask(:,jj,:)
+            zvel  (:,:) = obvel(:,jj,:)
+            ze3ob (:,:) = fse3v(:,jj,:)
+         END DO
+      END IF
+
+
+      ! 1. vertical sum
+      ! ----------------
+      zvelbtpe(1) = 0.e0
+!CDIR NOLOOPCHG
+      DO jk = 1, jpkm1
+         DO jle = 1, obl
+            zvelbtpe(jle) = zvelbtpe(jle) + zvel(jle,jk) * zmskob(jle,jk) * ze3ob(jle,jk)
+         END DO
+      END DO
+
+      ! 2. divide by the depth
+      ! -----------------------
+      zvelbtpe(:) = zvelbtpe(:) * zhinv(:) * zmskob(:,1) 
+
+      ! 3. substract zvelbtpe to the total velocity
+      !    and save the baroclinic velocity in velcli()
+      ! ------------------------------------------------
+      DO jk = 1, jpkm1
+         velcli(:,jk) = ( zvel(:,jk) - zvelbtpe(:) ) * zmskob(:,jk)
+      END DO
+
+   END SUBROUTINE obc_cli_dyn
+
+
+   SUBROUTINE obc_cli_dta( obvel, velcli, obd, obf, obtyp, obl, mpp )
+      !!--------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_cli_dta  ***
+      !!                   
+      !! ** Purpose :
+      !!      Compute the baroclinic velocities for the climatological velocities.
+      !!
+      !! ** Method  :
+      !!      - Compute de barotropic velocity along the considered Open Boundary 
+      !!        and substract it to the total velocity to have baroclinic velotity.
+      !!      - obtyp must be set to | 0 when traiting an East or West OB 
+      !!                             | 1 when traiting a North or South OB.
+      !!      - obl is the lenght of the OB (jpi or jpj) 
+      !!
+      !!--------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   & ! OB localization: jpieob or jpiwob for East or West 
+         obd, obf,               & !                  jpjnob or jpjsob for North or South 
+         obl,                    & ! Lenght of the Open Boundary
+         mpp,                    & ! MPP index
+         obtyp                     ! Type of Open Boundary: zonal or Meridional 
+      REAL(wp), INTENT( out), DIMENSION(:,:) ::   &
+         velcli                    ! Baroclinic velocity calculated
+      REAL(wp), INTENT( inout ), DIMENSION(:,:,:) ::   &
+         obvel                     ! uXdta or vXdta climatological velocities from 
+                                   ! obcdta.F90 routine
+
+      !! * Local declarations
+      INTEGER ::   &
+         ji, jj, jk, jle, jol, ij     ! loop indices  
+      REAL(wp), DIMENSION(obl) ::   & 
+         zvelbtpe,                  & ! Barotropic velocity 
+         zhinv                        ! Invert of the local depth 1/H
+      REAL(wp), DIMENSION(obl,jpk) ::   &
+         zmskob                       ! Velocity mask
+      REAL(wp), DIMENSION(obl,jpk) ::   &
+         ze3ob                        ! Vertical scale factor
+      !!--------------------------------------------------------------------------------
+
+      ! 0. Array initialization
+      ! -----------------------
+
+      zhinv (:)   = 0.e0
+      zmskob(:,:) = 0.e0
+      ze3ob (:,:) = 0.e0
+
+      IF( obtyp == 0 ) THEN            ! Meridional Open Boundary ( East or West OB )
+         DO ji = obd, obf
+            zhinv (:)   = hur  (ji,:)
+            zmskob(:,:) = umask(ji,:,:)
+            ze3ob (:,:) = fse3u(ji,:,:)
+         END DO
+      ELSE                             ! Zonal Open Boundary ( North or South OB )
+         DO jj = obd, obf
+            zhinv (:)   = hvr  (:,jj)
+            zmskob(:,:) = vmask(:,jj,:)
+            ze3ob (:,:) = fse3v(:,jj,:)
+         END DO
+      END IF
+
+      ! 1. vertical sum
+      ! ----------------
+      zvelbtpe(1) = 0.e0
+!CDIR NOLOOPCHG
+      DO jk = 1, jpkm1
+         DO jle = 1, obl
+            ij = jle -1 + mpp
+            zvelbtpe(jle) = zvelbtpe(jle) + obvel(ij,jk,1)*zmskob(jle,jk) * ze3ob(jle,jk)
+         END DO
+      END DO
+
+      ! 2. divide by the depth
+      ! -----------------------
+         zvelbtpe(:) = zvelbtpe(:) * zhinv(:) * zmskob(:,1) 
+
+      ! 3. substract zvelbtpe to the total velocity
+      !    and save the baroclinic velocity in velcli()
+      ! ------------------------------------------------
+      DO jk = 1, jpkm1
+         DO jle = 1, obl
+            ij = jle -1 + mpp
+            obvel(ij,jk,1) = obvel(ij,jk,1) - zvelbtpe(jle)*zmskob(jle,jk)
+            velcli(jle,jk) = obvel(ij,jk,1) * zmskob(jle,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_cli_dta
+
+#else
+   !!----------------------------------------------------------------------------------
+   !!   Default options :                                                  Empty module
+   !!----------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_cli_dyn       ! Empty routine
+   END SUBROUTINE obc_cli_dyn
+   SUBROUTINE obc_cli_dta       ! Empty routine
+   END SUBROUTINE obc_cli_dta
+#endif
+
+   !!==================================================================================
+END MODULE obccli
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdom.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdom.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdom.F90	(revision 4536)
@@ -0,0 +1,543 @@
+MODULE obcdom
+   !!=================================================================================
+   !!                       ***  MODULE  obcdom  ***
+   !! Space domain  :  get all the isolated coastline points needed to resolve the 
+   !!                  barotropic streamfunction elliptic equation associated with 
+   !!                  the open boundaries.
+   !!=================================================================================
+#if defined key_obc && defined key_dynspg_rl
+   !!---------------------------------------------------------------------------------
+   !!   'key_obc'           AND                                Open Boundary Condition
+   !!   'key_dynspg_rl'                                          Rigid-Lid formulation
+   !!---------------------------------------------------------------------------------
+   !!   obc_dom        : domain initialization in rid-lid formulation
+   !!---------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_dom        ! routine called by iniobc.F90
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_dom
+      !!------------------------------------------------------------------------------
+      !!                       SUBROUTINE obc_dom
+      !!                      ********************
+      !! ** Purpose :   Initialize the array used for the computation of the part of 
+      !!        the right hand side of the barotropic streamfunction elliptic equation
+      !!        associated with the open boundaries
+      !!
+      !! **  Method :
+      !!      + The (i,j) indices of ocean grid-points round isolated coastlines
+      !!        are found (isolated coastlines = coast lines separated by an
+      !!        open boundary) from icoast array read in coastlines file.
+      !!
+      !!      + read 'coastline' file  initialize icoast()
+      !!        modify icoast() depending on the number of open boundaries 
+      !!        specified through key_obc
+      !!
+      !!      + compute zwb, an ocean/land mask defined as follows:
+      !!             zwb(i,j)  =  0. over the one isolated coastline
+      !!                       = -1, -2, -3 over the orthers
+      !!      + for example, when 4 open boundaries are specified:
+      !!
+      !!                       //|           |// 
+      !!        North          //|   North   |// -1 -1   North
+      !!         West     0  0 //| - - - - - |// -1 -1    East
+      !!                       //| open bnd  |//
+      !!              ///////////|           |/////////
+      !!              ------------            ----------
+      !!                                               
+      !!             west   |                  |    east
+      !!           open bnd                       open bnd    
+      !!                    |                  |         
+      !!              ___________             _________ 
+      !!              ///////////|           |/////////
+      !!                       //|   south   |// 
+      !!        South    -3 -3 //| - - - - - |// -2 -2   South
+      !!         West    -3 -3 //| open bnd  |// -2 -2    East
+      !!                       //|           |// 
+      !!
+      !!        With the proper boundary conditions (defined by nperio)
+      !!
+      !!        C a u t i o n :  no check, the user must enter a well defined
+      !!        coastline file. Further more, he must verify that isolated
+      !!        coastlines have been well located dans that the right potential
+      !!        is affected to the right coastline in obc.F
+      !!
+      !! History :
+      !!   8.1  !  09-97  (J.M. Molines, G. Madec)  Original code
+      !!   8.2  !  06-99  (J.M. Molines) suppress zwb(,) for ATL6 (memory saving)
+      !!        !  02-02  (A.M. Treguier) icoast in 2 dimension
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj, jn, jnic, jnp, jii    ! dummy loop indices
+      INTEGER ::   inum = 11         ! temporary logical unit
+      INTEGER ::   ifreq, il1, il2, ii, ij, icheck
+      INTEGER ::   ip, ipn, ips, ipe, ipw
+      INTEGER ::   iim, ijm, iii, ijj
+      INTEGER, DIMENSION(jpidta,jpjdta) ::   icoast
+      CHARACTER (len=15) ::   clexp
+      REAL(wp) ::   zzic, zland
+      REAL(wp) ::   zwb, zwbn, zwbs, zwbe, zwbw
+      REAL(wp) ::   zglo(jpiglo,jpjglo)
+      !!---------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!---------------------------------------------------------------------
+      
+      ! 0. initialization of gcfobc to zero
+      ! -----------------------------------
+      
+      DO jn = 1, 3
+         gcfobc(:,:,jn) = 0.e0
+      END DO
+      
+      ! 1. Only 1 open boundary : gcfobc is zero, return
+      ! ------------------------------------------------
+      
+      IF( nbobc == 1 .OR. nbic == 0 ) CALL ctl_stop( ' obc_dom: No isolated coastlines gcfobc is set to zero' )
+
+      ! 2. Lecture of 'coastlines' file
+      ! -------------------------------
+      
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'obc_dom: define isolated coastlines from "coastlines" file'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+
+      ! open coastlines file'
+      CALL ctlopn( inum, 'coastlines', 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+                   1 , numout, lwp, 1 )
+
+      ! lecture of coastlines, set icoast array
+      ! Note that this is coded for jpjdta > 1000
+      REWIND(inum)
+      READ(inum,9101) clexp, iim, ijm
+      READ(inum,'(/)')
+      ifreq = 40
+      il1 = 1
+      IF( jpjglo < 1000 ) THEN
+         DO jn = 1, jpidta/ifreq+1
+            READ(inum,'(/)')
+            il2 = min0( jpidta, il1+ifreq-1 )
+            READ(inum,9201) ( ii, ji = il1, il2, 5 )
+            READ(inum,'(/)')
+            DO jj = jpjdta, 1, -1
+               READ(inum,9202) ij, ( icoast(ji,jj), ji = il1, il2 )
+            END DO
+            il1 = il1 + ifreq
+         END DO
+      ELSE
+         DO jn = 1, jpidta/ifreq+1
+            READ(inum,'(/)')
+            il2 = min0( jpidta, il1+ifreq-1 )
+            READ(inum,9221) ( ii, ji = il1, il2, 5 )
+            READ(inum,'(/)')
+            DO jj = jpjdta, 1, -1
+               READ(inum,9222) ij, ( icoast(ji,jj), ji = il1, il2 )
+            END DO
+            il1 = il1 + ifreq
+         END DO
+      END IF
+      CLOSE(inum)
+
+   ! in case of zoom, icoast must be set to 0 on the domain border
+   ! it must be the same for the bathymetry
+   IF (lzoom_w) icoast(jpiglo            ,:) = 0 
+   IF (lzoom_e) icoast(jpiglo +jpizoom -1,:) = 0 
+   IF (lzoom_s) icoast(:,jpjzoom           ) = 0 
+   IF (lzoom_n) icoast(:,jpjglo+jpjzoom -1 ) = 0 
+
+      DO jj = 1, jpjglo
+         DO ji = 1, jpiglo
+            zglo(ji,jj) = icoast( ji+jpizoom-1, jj+jpjzoom-1)
+         END DO
+      END DO
+
+ 9101 FORMAT(1x,a15,2i8)
+ 9201 FORMAT(3x,13(i3,12x))
+ 9202 FORMAT(i3,41i3)
+ 9221 FORMAT(4x,13(i3,12x))
+ 9222 FORMAT(i4,41i3)
+
+      ! check consistency between tmask and icoast
+      
+      icheck = 0
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            icheck = icheck +  INT( tmask(ji,jj,1) ) - MAX(  0, icoast( mig(ji), mjg(jj) )  )
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum(icheck)   ! sum over the global domain
+
+      IF( icheck /= 0 ) THEN
+         WRITE(ctmp1,*) 'obc_dom : tmask and isolated coastlines mask are not equal', icheck
+	 CALL ctl_stop( ctmp1 )
+      END IF
+
+      ! 3. transfer the coastline information from T- to f-points
+      !    (i.e. from icoast to zwb with  zwb=0 over the continent
+      !     and ocean, =-n over the nth isolated coastline)
+      ! -----------------------------------------------------------
+      
+      ! east open boundary
+      IF( lp_obc_east .AND. ( jpieob /= 0 ) ) THEN
+         IF(lwp) WRITE(numout,*) '         East open boundary: from coastline S.E : ', &
+                                 INT(zglo(jpieob,jpjed)),' to N.E : ',               &
+                                 INT(zglo(jpieob,jpjef))
+      END IF
+      ! west open boundary
+      IF( lp_obc_west .AND. ( jpiwob /= 0 ) ) THEN
+         IF(lwp) WRITE(numout,*) '         West open boundary: from coastline S.W : ', &
+                                 INT(zglo(jpiwob,jpjwd)),' to N.W : ',               &
+                                 INT(zglo(jpiwob,jpjwf))
+      END IF
+      ! north open boundary
+      IF( lp_obc_north .AND. ( jpjnob /= 0 ) ) THEN
+         IF(lwp) WRITE(numout,*) '         North open boundary: from coastline N.W : ', &
+                                 INT(zglo(jpind,jpjnob)),' to N.E : ',                &
+                                 INT(zglo(jpinf,jpjnob))
+      END IF
+      ! south open boundary
+      IF( lp_obc_south .AND. ( jpjsob /= 0 ) ) THEN
+         IF(lwp) WRITE(numout,*) '         South open boundary: from coastline S.W : ', &
+                                 INT(zglo(jpisd,jpjsob)),' to S.E : ',                &
+                                 INT(zglo(jpisf,jpjsob))
+      END IF
+
+      ! 4. Identify the isolated coastline grid point position
+      ! ------------------------------------------------------
+
+      ! Loop over isolated coastlines
+
+      DO jnic = 1, nbobc-1
+         ! set to zero of miic, mjic of the jnic isolated coastline
+         DO jn = 0, 4
+            DO ji = 1, jpnic
+               miic(ji,jn,jnic) = 0
+               mjic(ji,jn,jnic) = 0
+            END DO
+         END DO
+         
+         ! Coastal isolated coastline grid-points (miic,mjic)
+         ip  = 0
+         ipn = 0
+         ips = 0
+         ipe = 0
+         ipw = 0
+         
+         ! Middle lines (1=<jj=<jpjm1)
+
+         !       jj+1  --zwb--v--ZWB--v--zwb--
+         !                |       |       |
+         !          jj+1  u   T   u   T   u
+         !                |       |       |
+         !       jj    --ZWB--v--ZWB--v--ZWB--
+         !                |       |       |
+         !              jj    u   T   u   T   u
+         !                |       |       |
+         !       jj-1  --zwb--v--ZWB--v--zwb--
+         !                |       |       | 
+         !                |   ii  | ii+1  |
+         !                |       |       | 
+         !               ii-1    ii      ii+1
+         
+         DO jj = 1, jpjglo-1
+            DO ji = 1, jpiglo-1
+               ii = ji
+               zwb = MIN( 0., zglo(ji,jj), zglo(ji+1,jj), zglo(ji,jj+1), zglo(ji+1,jj+1) )
+               IF( jj == jpjglo -1 ) THEN
+                  zwbn = zwb
+               ELSE
+                  zwbn= MIN( 0., zglo(ji,jj+1), zglo(ji+1,jj+1), zglo(ji,jj+2), zglo(ji+1,jj+2) )
+               END IF
+               IF( jj == 1 ) THEN
+                  zwbs = zwb
+               ELSE
+                  zwbs= MIN( 0., zglo(ji,jj-1), zglo(ji+1,jj-1), zglo(ji,jj), zglo(ji+1,jj) )
+               END IF
+               IF( ji == jpiglo -1 ) THEN
+                  zwbe = zwb
+               ELSE
+                  zwbe= MIN( 0., zglo(ji+1,jj), zglo(ji+2,jj), zglo(ji+1,jj+1), zglo(ji+2,jj+1) )
+               END IF
+               IF( ji == 1 ) THEN
+                  zwbw = zwb
+               ELSE
+                  zwbw= MIN( 0., zglo(ji-1,jj), zglo(ji,jj), zglo(ji-1,jj+1), zglo(ji,jj+1) )
+               END IF
+               
+               ! inside coastlines indicator
+               zzic  =                zwbn                 &
+                     * zwbw                       * zwbe   &
+                                    * zwbs
+               ! inside land indicator
+               zland = MAX( 0., zglo(ji,jj+1) ) + MAX( 0., zglo(ji+1,jj+1) )   &
+                     + MAX( 0., zglo(ji,jj  ) ) + MAX( 0., zglo(ji+1,jj  ) )
+               ! if isolated coastline grid-point 
+               IF( zwb == float( -jnic ) .AND.   &
+                  ! not inside the isolated coastline
+                             zzic == 0.  .AND.   &
+                  ! not inside the land
+                             zland >= 2.         ) THEN
+                  ! coastal point of the isolated coastline jnic
+                  ip = ip + 1
+                  miic(ip,0,jnic) = ii
+                  mjic(ip,0,jnic) = jj
+                  ! which has a west ocean grid point 
+                  IF( zwbw == 0. ) THEN
+                     ipw = ipw + 1
+                     miic(ipw,4,jnic) = ii
+                     mjic(ipw,4,jnic) = jj
+                  END IF
+                  ! which has a east ocean grid point
+                  IF( zwbe == 0. ) THEN
+                     ipe = ipe + 1
+                     IF( nperio == 1 .AND. ii == jpiglo-1 ) THEN
+                        miic(ipe,3,jnic) = 2
+                     ELSE
+                        miic(ipe,3,jnic) = ii + 1
+                     END IF
+                     mjic(ipe,3,jnic) = jj
+                  END IF
+                  ! which has a south ocean grid point 
+                  IF( zwbs == 0. ) THEN
+                     ips = ips + 1
+                     miic(ips,2,jnic) = ii
+                     mjic(ips,2,jnic) = jj
+                  END IF
+                  ! which has a north ocean grid point not out of north open b.
+                  IF( zwbn == 0. ) THEN
+                     ipn = ipn + 1
+                     miic(ipn,1,jnic) = ii
+                     mjic(ipn,1,jnic) = jj + 1
+                  END IF
+               END IF
+            END DO
+         END DO
+         
+         mnic(0,jnic) = ip
+         mnic(1,jnic) = ipn
+         mnic(2,jnic) = ips
+         mnic(3,jnic) = ipe
+         mnic(4,jnic) = ipw
+         
+      END DO
+
+      ! 5. Check the number of isolated coastline
+      ! -----------------------------------------
+
+      DO jnic = 1, nbobc-1
+         IF( mnic(0,jnic) > jpnic ) THEN
+            WRITE(ctmp1,*) 'obc_dom: isolated coastline ',jnic,' has ',ip,' grid-points > ',jpnic 
+            CALL ctl_stop( ctmp1 )
+         END IF
+         IF( mnic(0,jnic) == 0 ) THEN
+            WRITE(ctmp1,*) 'obc_dom: isolated coastline ',jnic,' has 0  grid-points verify coastlines file'
+            CALL ctl_stop( ctmp1 )
+         END IF
+      END DO
+
+      ! 6. Print of isolated coastline parametres and arrays
+      ! -----------------------------------------------------
+
+      IF(lwp) WRITE(numout,*) '           '
+      IF(lwp) WRITE(numout,*) '         isolated coastlines found:', nbobc - 1
+
+      DO jnic = 1, nbobc-1
+         ip  = mnic(0,jnic)
+         ipn = mnic(1,jnic)
+         ips = mnic(2,jnic)
+         ipe = mnic(3,jnic)
+         ipw = mnic(4,jnic)
+         IF(lwp) THEN
+            WRITE(numout,9000) jnic
+            WRITE(numout,9010) ip, ipn, ips, ipe, ipw
+            WRITE(numout,9020)
+            DO jnp = 1, mnic(0,jnic)
+               WRITE(numout,9030) jnp,( miic(jnp,ji,jnic)+nimpp-1, mjic(jnp,ji,jnic)+njmpp-1, ji=0,4 )
+            END DO
+         END IF
+         
+         ! format
+
+ 9000 FORMAT(/,'          isolated coastline number= ',i2)
+ 9010 FORMAT(/,'          npic=',i4,' npn=',i4,' nps=',i4,' npe=',i4,' npw=',i4)
+ 9020 FORMAT(/,'              * ic  point *  point n  *  point s  *  point e ','*  point w  *')
+ 9030 FORMAT('         ',i4,' * (',i4,',',i4,') * (',i4,',',i4,') * (',i4,',',i4,') * (',i4,',',i4,') * (',i4,',',i4,') *')
+
+      END DO
+
+      ! 7. Construct the gcfobc array associated with each isolated coastline
+      ! ----------------------------------------------------------------------
+
+      DO jnic = 1, nbobc-1
+
+         ! north and south grid-points
+         DO jii = 1, 2
+            DO jnp = 1, mnic(jii,jnic)
+               ii = miic(jnp,jii,jnic)
+               ij = mjic(jnp,jii,jnic)
+               ! take only into account gridpoint of the model domain
+               IF( ii >= nldi+nimpp-1 .AND. ii <= nlci+nimpp-1 .AND.   &
+                   ij >= nldj+njmpp-1 .AND. ij <= nlcj+njmpp-1       ) THEN
+                  iii=ii-nimpp+1
+                  ijj=ij-njmpp+1
+                  gcfobc(iii,ijj-jii+1,jnic) = gcfobc(iii,ijj-jii+1,jnic)   &
+                                             - hur(iii,ijj) * e1u(iii,ijj) / e2u(iii,ijj)
+
+               END IF
+            END DO
+         END DO
+
+         ! east and west grid-points
+         DO jii = 3, 4
+            DO jnp = 1, mnic(jii,jnic)
+               ii = miic(jnp,jii,jnic)
+               ij = mjic(jnp,jii,jnic)
+               ! take only into account gridpoint of the model domain
+               IF( ii >= nldi+nimpp-1 .AND. ii <= nlci+nimpp-1 .AND.    &
+                   ij >= nldj+njmpp-1 .AND. ij <= nlcj+njmpp-1 ) THEN
+                  iii=ii-nimpp+1
+                  ijj=ij-njmpp+1
+                  IF( iii-jii+3 == 1 ) THEN
+                     ! cyclic east-west boundary
+                     gcfobc(jpim1    ,ijj,jnic) = gcfobc(jpim1    ,ijj,jnic)   &
+                                                - hvr(iii,ijj) * e2v(iii,ijj) / e1v(iii,ijj)
+                  ELSE
+                     ! interior points
+                     gcfobc(iii-jii+3,ijj,jnic) = gcfobc(iii-jii+3,ijj,jnic)   &
+                                                - hvr(iii,ijj) * e2v(iii,ijj) / e1v(iii,ijj)
+                  END IF
+               END IF
+            END DO
+         END DO
+
+         ! applied bmask to suppress coastal open boundary influence
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               gcfobc(ji,jj,jnic) = gcfobc(ji,jj,jnic) * bmask(ji,jj)
+            END DO
+         END DO
+         
+      END DO
+
+
+      ! 8. check the grid point which value controls the isolated coastline potential
+      !    Note: in order to activate those tests you need to make zwb a global array,
+      !    which is not done usually to spare memory.
+      !    n.b. here at least 2 open boundaries
+      ! ------------------------------------------------------------------------------
+!
+! east open boundary:
+!     IF( nieob /= 0 ) THEN
+!   east open & south open  :                              Ed === Sf
+!         IF( njsob /= 0 ) THEN
+!             IF( zwb(nieob,jped) /= zwb(jpsf,njsob) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east d # south f'
+!             END IF
+!   east open, south closed & west open :                  Ed === Wd
+!           ELSEIF( niwob /= 0 ) THEN
+!             IF( zwb(nieob,jped) /= zwb(niwob,jpwd) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east d # west d'
+!             END IF
+!   east open, south closed, west closed & north open :    Ed === Nd
+!           ELSEIF( njnob /= 0 ) THEN
+!             IF( zwb(nieob,jped) /= zwb(jpnd,njnob) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east d # north d'
+!             END IF
+!         END IF
+!   east open & north open :                               Ef === Nf
+!         IF( njnob /= 0 ) THEN
+!             IF( zwb(nieob,jpef) /= zwb(jpnf,njnob) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east f # north f'
+!             END IF
+!   east open, north closed & west open :                  Ef === Wf
+!           ELSEIF( niwob /= 0 ) THEN
+!             IF( zwb(nieob,jpef) /= zwb(niwob,jpwf) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east f # west f'
+!             END IF
+!   east open, north closed, west closed & south open :    Ef === Sd
+!           ELSEIF( njsob /= 0 ) THEN
+!             IF( zwb(nieob,jpef) /= zwb(jpsd,njnob) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : east f # south d'
+!             END IF
+!         END IF
+!
+! east closed 
+!       ELSE
+! east closed, south open
+!         IF( njsob /= 0 ) THEN
+!   east closed, south open & west open :                  Sd === Wd
+!             IF( niwob /= 0 ) THEN
+!                 IF( zwb(jpsd,njsob) /= zwb(niwob,jpwd) ) THEN
+!                     IF(lwp)WRITE(numout,*) ' E R R O R :',
+!    $                                       ' south d # west d'
+!                 END IF
+!   east closed, south open, west closed & north open :    Sd === Nd
+!               ELSEIF( njnob /= 0 ) THEN
+!                 IF( zwb(jpsd,njsob) /= zwb(jpnd,njnob) ) THEN
+!                     IF(lwp)WRITE(numout,*) ' E R R O R : ',
+!    $                                       ' south d # north d'
+!                 END IF
+!             END IF
+!   south open, east closed & north open :                 Sf === Nf
+!             IF( njnob /= 0 ) THEN
+!                 IF( zwb(jpsf,njsob) /= zwb(jpnf,njnob) ) THEN
+!                     IF(lwp)WRITE(numout,*) ' E R R O R : ',
+!    $                                       ' south f # north f'
+!                 END IF
+!   south open, east closed, north closed & west open :    Sf === Wf
+!               ELSEIF( niwob /= 0 ) THEN
+!                 IF( zwb(jpsf,njsob) /= zwb(niwob,jpwf) ) THEN
+!                     IF(lwp)WRITE(numout,*) ' E R R O R : ',
+!    $                                       ' south f # west f'
+!                 END IF
+!             END IF
+!
+! east & south closed ==> north & west open :              Nd === Wf
+!                                                              Nf === Wd
+!           ELSE
+!             IF( zwb(jpnd,njnob) /= zwb(niwob,jpwf) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : north d # west f'
+!             END IF
+!             IF( zwb(jpnf,njnob) /= zwb(niwob,jpwd) ) THEN
+!                 IF(lwp)WRITE(numout,*) ' E R R O R : north f # west d'
+!             END IF
+!         END IF
+!
+!     END IF
+!
+!
+
+   END SUBROUTINE obc_dom
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcdom  ***
+   !! Space domain :  get all the isolated coastline points needed to resolve the 
+   !!                 barotropic streamfunction elliptic equation associated with 
+   !!                 the open boundaries.
+   !!=================================================================================
+CONTAINS
+
+   SUBROUTINE obc_dom                 
+
+      ! No isolated coastline OR No Open Boundaries ==> empty routine
+
+   END SUBROUTINE obc_dom
+#endif
+
+END MODULE obcdom
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdta.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 4536)
@@ -0,0 +1,1185 @@
+MODULE obcdta
+   !!==============================================================================
+   !!                            ***  MODULE obcdta  ***
+   !! Open boundary data : read the data for the open boundaries.
+   !!==============================================================================
+   !! History :
+   !!        !  98-05 (J.M. Molines) Original code
+   !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+   !!   9.0  !  04-06 (F. Durand, A-M. Treguier) Netcdf BC files on input
+   !!------------------------------------------------------------------------------
+#if defined key_obc
+   !!------------------------------------------------------------------------------
+   !!   'key_obc'         :                                Open Boundary Conditions
+   !!------------------------------------------------------------------------------
+   !!   obc_dta           : read u, v, t, s data along each open boundary
+   !!   obc_dta_psi       : read psi data along each open boundary (rigid lid only)
+   !!------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE daymod          ! calendar
+   USE in_out_manager  ! I/O logical units
+   USE lib_mpp         ! distributed memory computing
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE iom
+#  if defined key_dynspg_rl
+   USE obccli          ! climatological obc, use only in rigid-lid case
+#  endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_dta        ! routines called by step.F90
+   PUBLIC obc_dta_bt     ! routines called by dynspg_ts.F90
+
+   !! * Shared module variables
+   INTEGER ::   &
+      nlecto,   &  ! switch for the first read
+      ntobc1,   &  ! first record used
+      ntobc2,   &  ! second record used
+      ntobc        ! number of time steps in OBC files 
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE :: tcobc      ! time_counter variable of BCs
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"                                            
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LODYC-IPSL  (2003)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/OBC/obcdta.F90,v 1.14 2007/06/29 17:01:51 opalod Exp $
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_dta( kt )
+      !!--------------------------------------------------------------------
+      !!              ***  SUBROUTINE obc_dta  ***
+      !!                   
+      !! ** Purpose :   Find the climatological boundary arrays for the specified date,
+      !!   The boundary arrays are netcdf files. Three possible cases:
+      !!   - one time frame only in the file (time dimension = 1).
+      !!     in that case the boundary data does not change in time.
+      !!   - many time frames. In that case,  if we have 12 frames
+      !!     we assume monthly fields.
+      !!     Else, we assume that time_counter is in seconds
+      !!     since the beginning of either the current year or a reference
+      !!     year given in the namelist.
+      !!     (no check is done so far but one would have to check the "unit"
+      !!     attribute of variable time_counter).
+      !!
+      !! History :
+      !!        !  98-05 (J.M. Molines) Original code
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!   9.0  !  04-06 (F. Durand, A-M. Treguier) Netcdf BC files on input
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, ii, ij   ! dummy loop indices
+      INTEGER ::   itimo, iman, imois
+      INTEGER ::   i15
+      REAL(wp) ::   zxy
+      !! * Ajouts FD
+      INTEGER ::  isrel              ! number of seconds since 1/1/1992
+      INTEGER, DIMENSION(1) ::  itobce, itobcw,  & ! number of time steps in OBC files
+                                itobcs, itobcn     !    "       "       "       "
+      INTEGER ::  istop        
+      INTEGER ::  iprint                              ! frequency for printouts.
+      INTEGER ::  idvar, id_e, id_w, id_n, id_s       ! file identifiers
+      LOGICAL :: llnot_done
+      CHARACTER(LEN=25) :: cl_vname
+      !!--------------------------------------------------------------------
+
+      IF( lk_dynspg_rl )  THEN
+         CALL obc_dta_psi (kt)     ! update bsf data at open boundaries
+         IF ( nobc_dta == 1 .AND. kt == nit000 ) CALL ctl_stop( 'obcdta : time-variable psi boundary data not allowed yet' )
+      ENDIF
+           
+      ! 1.   First call: check time frames available in files.
+      ! -------------------------------------------------------
+
+      IF ( kt == nit000 ) THEN
+      
+         nlecto = 0
+         itobce(1) = 0   ;    itobcw(1) = 0
+         itobcn(1) = 0   ;    itobcs(1) = 0
+
+         IF (lwp) WRITE(numout,*)
+         IF (lwp) WRITE(numout,*)     'obc_dta : find boundary data'
+         IF (lwp) WRITE(numout,*)     '~~~~~~~'
+             
+         IF ( nobc_dta == 0 ) THEN
+            IF(lwp) WRITE(numout,*)  '  OBC data taken from initial conditions.'
+            ntobc1 = 1
+            ntobc2 = 1
+         ELSE    
+            IF (lwp) WRITE(numout,*)  '  OBC data taken from netcdf files.'
+            IF (lwp) WRITE(numout,*)  '  climatology (T/F):',ln_obc_clim
+            ! check the number of time steps in the files.
+            cl_vname = 'time_counter'
+            IF ( lp_obc_east ) THEN
+               CALL iom_open ( 'obceast_TS.nc' , id_e )
+               idvar = iom_varid( id_e, cl_vname, kdimsz = itobce )
+            ENDIF
+            IF ( lp_obc_west ) THEN
+               CALL iom_open ( 'obcwest_TS.nc' , id_w )
+               idvar = iom_varid( id_w, cl_vname, kdimsz = itobcw )
+            ENDIF
+            IF ( lp_obc_north ) THEN
+               CALL iom_open ( 'obcnorth_TS.nc', id_n )
+               idvar = iom_varid( id_n, cl_vname, kdimsz = itobcn )
+            ENDIF
+            IF ( lp_obc_south ) THEN
+               CALL iom_open ( 'obcsouth_TS.nc', id_s )
+               idvar = iom_varid( id_s, cl_vname, kdimsz = itobcs )
+            ENDIF
+
+            ntobc = MAX(itobce(1),itobcw(1),itobcn(1),itobcs(1))
+            istop = 0
+            IF ( lp_obc_east  .AND. itobce(1) /= ntobc ) istop = 1 
+            IF ( lp_obc_west  .AND. itobcw(1) /= ntobc ) istop = 1      
+            IF ( lp_obc_north .AND. itobcn(1) /= ntobc ) istop = 1
+            IF ( lp_obc_south .AND. itobcs(1) /= ntobc ) istop = 1 
+            IF ( istop /= 0 )  THEN
+               WRITE(ctmp1,*) ' east, west, north, south: ', itobce(1), itobcw(1), itobcn(1), itobcs(1)
+               CALL ctl_stop( 'obcdta : all files must have the same number of time steps', ctmp1 )
+            ENDIF
+            IF ( ntobc == 1 ) THEN
+               IF ( lwp ) WRITE(numout,*) ' obcdta found one time step only in the OBC files'
+            ELSE
+               ALLOCATE (tcobc(ntobc))
+               llnot_done = .TRUE.
+               IF ( lp_obc_east ) THEN
+                  IF ( llnot_done ) THEN
+                     CALL iom_gettime ( id_e, TRIM(cl_vname), tcobc )
+                     llnot_done = .FALSE.
+                  ENDIF
+                  CALL iom_close (id_e)
+               ENDIF
+               IF ( lp_obc_west ) THEN
+                  IF ( llnot_done ) THEN
+                     CALL iom_gettime ( id_w, TRIM(cl_vname), tcobc )
+                     llnot_done = .FALSE.
+                 ENDIF
+                 CALL iom_close (id_w)
+               ENDIF
+               IF ( lp_obc_north ) THEN
+                  IF ( llnot_done ) THEN
+                     CALL iom_gettime ( id_n, TRIM(cl_vname), tcobc )
+                     llnot_done = .FALSE.
+                  ENDIF
+                  CALL iom_close (id_n)
+               ENDIF
+               IF ( lp_obc_south ) THEN
+                  IF ( llnot_done ) THEN
+                     CALL iom_gettime ( id_s, TRIM(cl_vname), tcobc )
+                     llnot_done = .FALSE.
+                  ENDIF
+                  CALL iom_close (id_s)
+               ENDIF
+               IF ( lwp ) WRITE(numout,*) ' obcdta found', ntobc,' time steps in the OBC files'
+               IF ( .NOT. ln_obc_clim .AND. ntobc == 12 ) THEN
+                  IF ( lwp ) WRITE(numout,*) '  WARNING: With monthly data we assume climatology'
+                  ln_obc_clim = .true.
+               ENDIF
+            ENDIF
+         ENDIF
+      
+       ! 1.1  Tangential velocities set to zero
+       ! --------------------------------------
+         IF( lp_obc_east  ) vfoe = 0.e0
+         IF( lp_obc_west  ) vfow = 0.e0
+         IF( lp_obc_south ) ufos = 0.e0
+         IF( lp_obc_north ) ufon = 0.e0
+      
+       ! 1.2  Data temperature, salinity, normal velocities set to zero
+       !                        or initial conditions if nobc_dta == 0
+       ! --------------------------------------------------------------
+
+         IF( lp_obc_east )   THEN
+            ! initialisation to zero
+            sedta(:,:,:) = 0.e0
+            tedta(:,:,:) = 0.e0
+            uedta(:,:,:) = 0.e0
+            !                                    ! ================== !
+            IF( nobc_dta == 0 )   THEN           ! initial state used
+               !                                 ! ================== !
+               !  Fills sedta, tedta, uedta (global arrays)
+               !  Remark: this works for njzoom = 1.
+               !          Should the definition of ij include njzoom?
+               DO ji = nie0, nie1
+                  DO jk = 1, jpkm1
+                     DO jj = nje0p1, nje1m1
+                        ij = jj -1 + njmpp
+                        sedta(ij,jk,1) = sn(ji,jj,jk)*tmask(ji,jj,jk)
+                        tedta(ij,jk,1) = tn(ji,jj,jk)*tmask(ji,jj,jk)
+                        uedta(ij,jk,1) = un(ji,jj,jk)*umask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_west )   THEN
+            ! initialisation to zero
+            swdta(:,:,:) = 0.e0
+            twdta(:,:,:) = 0.e0
+            uwdta(:,:,:) = 0.e0
+            !                                    ! ================== !
+            IF( nobc_dta == 0 )   THEN           ! initial state used !
+               !                                 ! ================== !
+               !  Fills swdta, twdta, uwdta (global arrays)
+               !  Remark: this works for njzoom = 1. 
+               !          Should the definition of ij include njzoom?
+               DO ji = niw0, niw1
+                  DO jk = 1, jpkm1
+                     DO jj = njw0p1, njw1m1
+                        ij = jj -1 + njmpp
+                        swdta(ij,jk,1) = sn(ji,jj,jk)*tmask(ji,jj,jk)
+                        twdta(ij,jk,1) = tn(ji,jj,jk)*tmask(ji,jj,jk)
+                        uwdta(ij,jk,1) = un(ji,jj,jk)*umask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_north)   THEN
+            ! initialisation to zero
+            sndta(:,:,:) = 0.e0
+            tndta(:,:,:) = 0.e0
+            vndta(:,:,:) = 0.e0
+            !                                    ! ================== !
+            IF( nobc_dta == 0 )   THEN           ! initial state used
+               !                                 ! ================== !
+               !  Fills sndta, tndta, vndta (global arrays)
+               !  Remark: this works for njzoom = 1. 
+               !          Should the definition of ij include njzoom?
+               DO jj = njn0, njn1
+                  DO jk = 1, jpkm1
+                     DO ji = nin0p1, nin1m1
+                        ii = ji -1 + nimpp
+                        sndta(ii,jk,1) = sn(ji,jj,jk)*tmask(ji,jj,jk)
+                        tndta(ii,jk,1) = tn(ji,jj,jk)*tmask(ji,jj,jk)
+                        vndta(ii,jk,1) = vn(ji,jj,jk)*vmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_south )   THEN
+            ! initialisation to zero
+            ssdta(:,:,:) = 0.e0
+            tsdta(:,:,:) = 0.e0
+            vsdta(:,:,:) = 0.e0
+            !                                    ! ================== !
+            IF( nobc_dta == 0 )   THEN           ! initial state used
+               !                                 ! ================== !
+               !  Fills ssdta, tsdta, vsdta (global arrays)
+               !  Remark: this works for njzoom = 1. 
+               !          Should the definition of ij include njzoom?
+               DO jj = njs0, njs1
+                  DO jk = 1, jpkm1
+                     DO ji = nis0p1, nis1m1
+                        ii = ji -1 + nimpp
+                        ssdta(ii,jk,1) = sn(ji,jj,jk)*tmask(ji,jj,jk)
+                        tsdta(ii,jk,1) = tn(ji,jj,jk)*tmask(ji,jj,jk)
+                        vsdta(ii,jk,1) = vn(ji,jj,jk)*vmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         ENDIF
+
+      ENDIF        !       end if kt == nit000
+      
+      ! 2.  Initialize the time we are at.
+      !     Does this every time the routine is called,
+      !     excepted when nobc_dta = 0
+      !---------------------------------------------------------------------
+      IF( nobc_dta == 0 )   THEN
+         itimo = 1
+         zxy   = 0
+      ELSE
+         IF( ntobc == 1 )   THEN
+            itimo = 1
+         ELSE IF( ntobc == 12 )   THEN      !   BC are monthly   
+            ! we assume we have climatology in that case
+            iman  = 12
+            i15   = nday / 16
+            imois = nmonth + i15 - 1
+            IF( imois == 0 )   imois = iman
+            itimo = imois   
+         ELSE
+            IF(lwp) WRITE(numout,*) 'data other than constant or monthly', kt
+            iman  = ntobc
+            itimo = FLOOR( kt*rdt / (tcobc(2)-tcobc(1)) )
+            isrel = kt*rdt
+         ENDIF
+      ENDIF
+      
+      ! 2.1 Read two records in the file if necessary
+      ! ---------------------------------------------
+      IF( ( nobc_dta == 1 ) .AND. ( ( kt == nit000 .AND. nlecto == 0 ) .OR. itimo  /= ntobc1 ) )   THEN
+         nlecto = 1
+      
+         ! Calendar computation
+         IF( ntobc == 1 )   THEN            !  BC are constant in time
+            ntobc1 = 1
+            ntobc2 = 1  
+         ELSE IF( ntobc == 12 )   THEN      !   BC are monthly   
+            ntobc1 = itimo         ! first file record used
+            ntobc2 = ntobc1 + 1    ! last  file record used
+            ntobc1 = MOD( ntobc1, iman )
+            IF( ntobc1 == 0 )   ntobc1 = iman
+            ntobc2 = MOD( ntobc2, iman )
+            IF( ntobc2 == 0 )   ntobc2 = iman
+            IF( lwp )   THEN
+               WRITE(numout,*) ' read monthly obc first record file used ntobc1 ', ntobc1
+               WRITE(numout,*) ' read monthly obc last  record file used ntobc2 ', ntobc2
+            ENDIF
+         ELSE
+            isrel=kt*rdt
+            ntobc1 = itimo         ! first file record used
+            ntobc2 = ntobc1 + 1    ! last  file record used
+            ntobc1 = MOD( ntobc1, iman )
+            IF( ntobc1 == 0 )   ntobc1 = iman
+            ntobc2 = MOD( ntobc2, iman )
+            IF( ntobc2 == 0 )   ntobc2 = iman
+            IF(lwp) WRITE(numout,*) ' read obc first record file used ntobc1 ', ntobc1
+            IF(lwp) WRITE(numout,*) ' read obc last  record file used ntobc2 ', ntobc2
+         ENDIF
+                               ! ======================= !
+                               !  BCs read               !
+         !                     ! ======================= !
+         IF( lp_obc_east )   THEN
+            ! ... Read datafile and set temperature, salinity and normal velocity
+            ! ... initialise the sedta, tedta, uedta arrays
+            CALL iom_open ( 'obceast_TS.nc' , id_e )
+            CALL iom_get ( id_e, jpdom_unknown, 'votemper', tedta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_e, jpdom_unknown, 'votemper', tedta(:,:,2), ktime=ntobc2 )
+            CALL iom_get ( id_e, jpdom_unknown, 'vosaline', sedta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_e, jpdom_unknown, 'vosaline', sedta(:,:,2), ktime=ntobc2 )
+            CALL iom_close (id_e)
+            !
+            CALL iom_open ( 'obceast_U.nc' , id_e )
+            CALL iom_get ( id_e, jpdom_unknown, 'vozocrtx', uedta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_e, jpdom_unknown, 'vozocrtx', uedta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_e )
+            !  Usually printout is done only once at kt = nit000,
+            !  unless nprint (namelist) > 1      
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 ) )   THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read East OBC data records ', ntobc1, ntobc2
+               iprint = (jpjef-jpjed+1)/20 +1
+               WRITE(numout,*) ' Temperature record 1 - printout every 3 level'
+               CALL prihre( tedta(:,:,1),jpjef-jpjed+1,jpk,1,jpjef-jpjed+1,iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
+               CALL prihre( sedta(:,:,1), jpjef-jpjed+1, jpk, 1, jpjef-jpjed+1, iprint, &
+                  &        jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal velocity U  record 1  - printout every 3 level'
+               CALL prihre( uedta(:,:,1), jpjef-jpjed+1, jpk, 1, jpjef-jpjed+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_west )   THEN
+            ! ... Read datafile and set temperature, salinity and normal velocity
+            ! ... initialise the swdta, twdta, uwdta arrays
+            CALL iom_open ( 'obcwest_TS.nc' , id_w )
+            CALL iom_get ( id_w, jpdom_unknown, 'votemper', twdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_w, jpdom_unknown, 'votemper', twdta(:,:,2), ktime=ntobc2 )
+            CALL iom_get ( id_w, jpdom_unknown, 'vosaline', swdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_w, jpdom_unknown, 'vosaline', swdta(:,:,2), ktime=ntobc2 )
+            CALL iom_close (id_w)
+            !
+            CALL iom_open ( 'obcwest_U.nc' , id_w )
+            CALL iom_get ( id_w, jpdom_unknown, 'vozocrtx', uwdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_w, jpdom_unknown, 'vozocrtx', uwdta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_w )
+            !
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 ) )   THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read West OBC data records ', ntobc1, ntobc2
+               iprint = (jpjwf-jpjwd+1)/20 +1
+               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
+               CALL prihre( twdta(:,:,1), jpjwf-jpjwd+1, jpk, 1, jpjwf-jpjwd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
+               CALL prihre( swdta(:,:,1), jpjwf-jpjwd+1, jpk, 1, jpjwf-jpjwd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal velocity U  record 1  - printout every 3 level'
+               CALL prihre( uwdta(:,:,1), jpjwf-jpjwd+1, jpk, 1, jpjwf-jpjwd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_north )   THEN      
+            CALL iom_open ( 'obcnorth_TS.nc', id_n )
+            CALL iom_get ( id_n, jpdom_unknown, 'votemper', tndta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_n, jpdom_unknown, 'votemper', tndta(:,:,2), ktime=ntobc2 )
+            CALL iom_get ( id_n, jpdom_unknown, 'vosaline', sndta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_n, jpdom_unknown, 'vosaline', sndta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_n )                                                           
+            !
+            CALL iom_open ( 'obcnorth_V.nc', id_n )                                          
+            CALL iom_get ( id_n, jpdom_unknown, 'vomecrty', vndta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_n, jpdom_unknown ,'vomecrty', vndta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_n )
+            !
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 ) )   THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read North OBC data records ', ntobc1, ntobc2
+               iprint = (jpinf-jpind+1)/20 +1
+               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
+               CALL prihre( tndta(:,:,1), jpinf-jpind+1, jpk, 1, jpinf-jpind+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
+               CALL prihre( sndta(:,:,1), jpinf-jpind+1, jpk, 1, jpinf-jpind+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal velocity V  record 1  - printout every 3 level'
+               CALL prihre( vndta(:,:,1), jpinf-jpind+1, jpk, 1, jpinf-jpind+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_south )   THEN      
+            CALL iom_open ( 'obcsouth_TS.nc', id_s )
+            CALL iom_get ( id_s, jpdom_unknown, 'votemper', tsdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_s, jpdom_unknown, 'votemper', tsdta(:,:,2), ktime=ntobc2 )
+            CALL iom_get ( id_s, jpdom_unknown, 'vosaline', ssdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_s, jpdom_unknown, 'vosaline', ssdta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_s )                                                           
+            !
+            CALL iom_open ( 'obcsouth_V.nc', id_s )                                          
+            CALL iom_get ( id_s, jpdom_unknown, 'vomecrty', vsdta(:,:,1), ktime=ntobc1 )
+            CALL iom_get ( id_s, jpdom_unknown ,'vomecrty', vsdta(:,:,2), ktime=ntobc2 )
+            CALL iom_close ( id_s )
+            !
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 ) )   THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read South OBC data records ', ntobc1, ntobc2
+               iprint = (jpisf-jpisd+1)/20 +1
+               WRITE(numout,*) ' Temperature  record 1 - printout every 3 level'
+               CALL prihre( tsdta(:,:,1), jpisf-jpisd+1, jpk, 1, jpisf-jpisd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Salinity  record 1 - printout every 3 level'
+               CALL prihre( ssdta(:,:,1), jpisf-jpisd+1, jpk, 1, jpisf-jpisd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal velocity V  record 1  - printout every 3 level'
+               CALL prihre( vsdta(:,:,1), jpisf-jpisd+1, jpk, 1, jpisf-jpisd+1, iprint, &
+                  &         jpk, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+      ELSE
+         
+         nlecto = 0        !      no reading of OBC barotropic data                         
+
+      ENDIF                !      end of the test on the condition to read or not the files 
+      
+      ! 3.  Call at every time step :
+      !     Linear interpolation of BCs to current time step 
+      ! ----------------------------------------------------
+
+      IF( ntobc == 1 .OR. nobc_dta == 0 )   THEN 
+         zxy = 0.
+      ELSE IF( ntobc == 12 )   THEN         
+         zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
+      ELSE
+         zxy = (tcobc(ntobc1)-FLOAT(isrel))/(tcobc(ntobc1)-tcobc(ntobc2))
+      ENDIF
+      
+      IF( lp_obc_east )   THEN
+         !  fills sfoe, tfoe, ufoe (local to each processor)
+         DO jk = 1, jpkm1
+            DO jj = nje0p1, nje1m1
+               ij = jj -1 + njmpp
+               sfoe(jj,jk) =  ( zxy * sedta(ij,jk,2) + &
+                  &           (1.-zxy) * sedta(ij,jk,1) ) * temsk(jj,jk)
+               tfoe(jj,jk) =  ( zxy * tedta(ij,jk,2) + &
+                  &           (1.-zxy) * tedta(ij,jk,1) ) * temsk(jj,jk)
+               ufoe(jj,jk) =  ( zxy * uedta(ij,jk,2) + &
+                  &           (1.-zxy) * uedta(ij,jk,1) ) * uemsk(jj,jk)
+            END DO
+         END DO
+      ENDIF
+      
+      IF( lp_obc_west )   THEN
+         !  fills sfow, tfow, ufow (local to each processor)
+         DO jk = 1, jpkm1
+            DO jj = njw0p1, njw1m1
+               ij = jj -1 + njmpp
+               sfow(jj,jk) =  ( zxy * swdta(ij,jk,2) + &
+                  &           (1.-zxy) * swdta(ij,jk,1) ) * twmsk(jj,jk)
+               tfow(jj,jk) =  ( zxy * twdta(ij,jk,2) + &
+                  &           (1.-zxy) * twdta(ij,jk,1) ) * twmsk(jj,jk)
+               ufow(jj,jk) =  ( zxy * uwdta(ij,jk,2) + &
+                  &           (1.-zxy) * uwdta(ij,jk,1) ) * uwmsk(jj,jk)
+            END DO
+         END DO
+      ENDIF
+      
+      IF( lp_obc_north )   THEN
+         !  fills sfon, tfon, vfon (local to each processor)
+         DO jk = 1, jpkm1
+            DO ji = nin0p1, nin1m1
+               ii = ji -1 + nimpp
+               sfon(ji,jk) =  ( zxy * sndta(ii,jk,2) + &
+                  &           (1.-zxy) * sndta(ii,jk,1) ) * tnmsk(ji,jk)
+               tfon(ji,jk) =  ( zxy * tndta(ii,jk,2) + &
+                  &           (1.-zxy) * tndta(ii,jk,1) ) * tnmsk(ji,jk)
+               vfon(ji,jk) =  ( zxy * vndta(ii,jk,2) + &
+                  &           (1.-zxy) * vndta(ii,jk,1) ) * vnmsk(ji,jk)
+            END DO
+         END DO
+      ENDIF
+      
+      IF( lp_obc_south )   THEN
+         !  fills sfos, tfos, vfos (local to each processor)
+         DO jk = 1, jpkm1
+           DO ji = nis0p1, nis1m1
+              ii = ji -1 + nimpp
+              sfos(ji,jk) = ( zxy * ssdta(ii,jk,2) + &
+                 &          (1.-zxy) * ssdta(ii,jk,1) ) * tsmsk(ji,jk)
+              tfos(ji,jk) = ( zxy * tsdta(ii,jk,2) + &
+                 &          (1.-zxy) * tsdta(ii,jk,1) ) * tsmsk(ji,jk)
+              vfos(ji,jk) = ( zxy * vsdta(ii,jk,2) + &
+                 &          (1.-zxy) * vsdta(ii,jk,1) ) * vsmsk(ji,jk)
+           END DO
+         END DO             
+      ENDIF
+      
+   END SUBROUTINE obc_dta
+      
+# if defined key_dynspg_rl
+   !!-----------------------------------------------------------------------------
+   !!   Rigid-lid
+   !!-----------------------------------------------------------------------------
+
+   SUBROUTINE obc_dta_psi ( kt )
+      !!-----------------------------------------------------------------------------
+      !!                       ***  SUBROUTINE obc_dta_psi  ***
+      !!
+      !! ** Purpose :
+      !!      Update the climatological streamfunction OBC at each time step.
+      !!      Depends on the user's configuration.  Here data are read only once
+      !!      at the beginning of the run.
+      !!
+      !! ** Method :
+      !!      1. initialization
+      !!         kbsfstart: number of time steps over which increase bsf
+      !!         during initialization. This is provided for a smooth start
+      !!         in cases where the transport is large (like on the Antarctic
+      !!         continent). also note that when kbfstart=1, the transport
+      !!         increases a lot in one time step and the precision usually
+      !!         required for the solver may not be enough.
+      !!      2. set the time evolution of the climatological barotropic streamfunction
+      !!         along the isolated coastlines ( gcbic(jnic) ). 
+      !!      3. set the climatological barotropic streamfunction at the boundary.
+      !!
+      !!      The last two steps are done only at first step (nit000) or if kt <= kbfstart
+      !!
+      !! History :
+      !!        ! 97-08 (G. Madec, J.M. Molines)
+      !!   8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!   9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jnic, jip         ! dummy loop indices
+      INTEGER ::   inum                      ! temporary logical unit
+      INTEGER ::   ip, ii, ij, iii, ijj
+      INTEGER ::   kbsfstart
+      REAL(wp) ::   zsver1, zsver2, zsver3, z2dtr, zcoef
+      !!----------------------------------------------------------------------------
+
+      ! 1. initialisation
+      ! -----------------
+
+      kbsfstart =  1
+      zsver1 =  bsfic0(1)
+      zsver2 =  zsver1
+      IF( kt <= kbsfstart )   THEN
+         zcoef = float(kt)/float(kbsfstart)
+      ELSE
+         zcoef = 1.
+      END IF
+      bsfic(1) = zsver1*zcoef
+      IF( lwp .AND. ( kt <= kbsfstart ) )   THEN
+         IF(lwp) WRITE(numout,*)'            '
+         IF(lwp) WRITE(numout,*)'obcdta: spinup phase in obc_dta_psi routine'
+         IF(lwp) WRITE(numout,*)'~~~~~~  it=',kt,'  OBC: spinup coef: ', &
+                                           zcoef, ' and transport: ',bsfic(1)
+      END IF
+
+      zsver2 =  bsfic(1)-bsfic(2)
+      zsver3 =  bsfic(2)
+
+      ! 2. Right hand side of the barotropic elliptic equation (isolated coastlines)
+      ! ----------------------------------------------------------------------------
+
+      IF( ( neuler == 0 ) .AND. ( kt == nit000 ) )   THEN
+         z2dtr = 1./rdt
+      ELSE
+         z2dtr = 1./2./rdt
+      END IF
+      ! ... bsfb(ii,ij) should be constant but due to the Asselin filter it
+      ! ... converges asymptotically towards bsfic(jnic)
+      ! ... However, bsfb(ii,ij) is constant along the same coastlines
+      ! ... ---> can be improved using an extra array for storing bsficb (before)
+      IF( nbobc > 1 )   THEN
+         DO jnic = 1,nbobc - 1
+            gcbic(jnic) = 0.e0
+            ip=mnic(0,jnic)
+            DO jip = 1,ip
+               ii = miic(jip,0,jnic) 
+               ij = mjic(jip,0,jnic) 
+               IF( ii >= nldi+ nimpp - 1 .AND. ii <= nlei+ nimpp - 1 .AND. &
+                   ij >= nldj+ njmpp - 1 .AND. ij <= nlej+ njmpp - 1 )   THEN
+                  iii=ii-nimpp+1
+                  ijj=ij-njmpp+1
+                  gcbic(jnic) = ( bsfic(jnic) - bsfb(iii,ijj) ) * z2dtr
+               END IF
+            END DO
+         END DO
+      END IF
+
+      IF( lk_mpp )   CALL mpp_isl( gcbic, 3 )
+
+      ! 3. Update the climatological barotropic function at the boundary 
+      ! ----------------------------------------------------------------
+
+      IF( lpeastobc )   THEN
+
+         IF( kt == nit000 .OR. kt <= kbsfstart )   THEN
+            CALL ctlopn( inum, 'obceastbsf.dta', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+               &         1, numout, lwp, 1 )
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*) (bfoe(jj),jj=jpjed, jpjef)
+            CLOSE(inum)
+         END IF
+         DO jj=jpjed, jpjefm1
+            bfoe(jj)=bfoe(jj)*zcoef
+         END DO
+
+      END IF
+
+      IF( lpwestobc)   THEN
+
+         IF( kt == nit000 .OR. kt <= kbsfstart ) then
+            CALL ctlopn( inum, 'obcwestbsf.dta', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+               &         1, numout, lwp, 1 )
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*) (bfow(jj),jj=jpjwd, jpjwf)
+            CLOSE(inum)
+         END IF
+         DO jj=jpjwd, jpjwfm1
+            bfow(jj)=bfow(jj)*zcoef
+         END DO
+
+      END IF
+
+      IF( lpsouthobc)   THEN
+
+         IF( kt == nit000 .OR. kt <= kbsfstart )   THEN
+            CALL ctlopn( inum, 'obcsouthbsf.dta', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+               &         1, numout, lwp, 1 )
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*) (bfos(jj),jj=jpisd, jpisf)
+            CLOSE(inum)
+         END IF
+         DO ji=jpisd, jpisfm1
+            bfos(ji)=bfos(ji)*zcoef
+         END DO
+
+      END IF
+
+      IF( lpnorthobc)   THEN
+         IF( kt == nit000 .OR. kt <= kbsfstart )   THEN
+            CALL ctlopn( inum, 'obcnorthbsf.dta', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+               &         1, numout, lwp, 1 )
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*)
+            READ(inum,*) (bfon(jj),jj=jpind, jpinf)
+            CLOSE(inum)
+         END IF
+         DO ji=jpind, jpinfm1
+            bfon(ji)=bfon(ji)*zcoef
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_dta_psi
+#else
+   !!-----------------------------------------------------------------------------
+   !!   Default option                    
+   !!-----------------------------------------------------------------------------
+   SUBROUTINE obc_dta_psi ( kt )       ! Empty routine
+      !! * Arguments
+      INTEGER,INTENT(in) :: kt 
+      WRITE(*,*) 'obc_dta_psi: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_dta_psi
+# endif
+
+
+#if defined key_dynspg_ts || defined key_dynspg_exp
+   SUBROUTINE obc_dta_bt( kt, kbt )
+      !!---------------------------------------------------------------------------
+      !!                      ***  SUBROUTINE obc_dta  ***
+      !!
+      !! ** Purpose :   time interpolation of barotropic data for time-splitting scheme
+      !!                Data at the boundary must be in m2/s 
+      !!
+      !! History :
+      !!   9.0  !  05-11 (V. garnier) Original code
+      !!---------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kbt         ! barotropic ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, ii, ij   ! dummy loop indices
+      INTEGER ::   id_e, id_w, id_n, id_s, fid  ! file identifiers
+      INTEGER ::   itimo, iman, imois, i15
+      INTEGER ::   itobcm, itobcp, itimom, itimop
+      REAL(wp) ::  zxy
+      INTEGER ::   isrel, ikt           ! number of seconds since 1/1/1992
+      INTEGER ::   iprint              ! frequency for printouts.
+
+      !!---------------------------------------------------------------------------
+
+      ! 1.   First call: check time frames available in files.
+      ! -------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+
+         ! 1.1  Barotropic tangential velocities set to zero
+         ! -------------------------------------------------
+         IF( lp_obc_east  ) vbtfoe(:) = 0.e0
+         IF( lp_obc_west  ) vbtfow(:) = 0.e0
+         IF( lp_obc_south ) ubtfos(:) = 0.e0
+         IF( lp_obc_north ) ubtfon(:) = 0.e0
+
+         ! 1.2  Sea surface height and normal barotropic velocities set to zero
+         !                               or initial conditions if nobc_dta == 0
+         ! --------------------------------------------------------------------
+
+          IF( lp_obc_east ) THEN
+             ! initialisation to zero
+             sshedta(:,:) = 0.e0
+             ubtedta(:,:) = 0.e0
+             !                                        ! ================== !
+             IF( nobc_dta == 0 )   THEN               ! initial state used !
+                !                                     ! ================== !
+                !  Fills sedta, tedta, uedta (global arrays)
+                !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
+                DO ji = nie0, nie1
+                   DO jj = nje0p1, nje1m1
+                      ij = jj -1 + njmpp
+                      sshedta(ij,1) = sshn(ji+1,jj) * tmask(ji+1,jj,1)
+                   END DO
+                END DO
+             ENDIF
+          ENDIF
+
+          IF( lp_obc_west) THEN
+             ! initialisation to zero
+             sshwdta(:,:) = 0.e0
+             ubtwdta(:,:) = 0.e0
+             !                                        ! ================== !
+             IF( nobc_dta == 0 )   THEN               ! initial state used !
+                !                                     ! ================== !
+                !  Fills swdta, twdta, uwdta (global arrays)
+                !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
+                DO ji = niw0, niw1
+                   DO jj = njw0p1, njw1m1
+                      ij = jj -1 + njmpp
+                      sshwdta(ij,1) = sshn(ji,jj) * tmask(ji,jj,1)
+                   END DO
+                END DO
+             ENDIF
+          ENDIF
+
+          IF( lp_obc_north) THEN
+             ! initialisation to zero
+             sshndta(:,:) = 0.e0
+             vbtndta(:,:) = 0.e0
+             !                                        ! ================== !
+             IF( nobc_dta == 0 )   THEN               ! initial state used !
+                !                                     ! ================== !
+                !  Fills sndta, tndta, vndta (global arrays)
+                !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
+                DO jj = njn0, njn1
+                   DO ji = nin0p1, nin1m1
+                      DO jk = 1, jpkm1
+                         ii = ji -1 + nimpp
+                         vbtndta(ii,1) = vbtndta(ii,1) + vndta(ii,jk,1)*fse3v(ji,jj,jk)
+                      END DO
+                      sshndta(ii,1) = sshn(ii,jj+1) * tmask(ji,jj+1,1)
+                   END DO
+                END DO
+             ENDIF
+          ENDIF
+
+          IF( lp_obc_south) THEN
+             ! initialisation to zero
+             ssdta(:,:,:) = 0.e0
+             tsdta(:,:,:) = 0.e0
+             vsdta(:,:,:) = 0.e0
+             sshsdta(:,:) = 0.e0
+             vbtsdta(:,:) = 0.e0
+             !                                        ! ================== !
+             IF( nobc_dta == 0 )   THEN               ! initial state used !
+                !                                     ! ================== !
+                !  Fills ssdta, tsdta, vsdta (global arrays)
+                !  Remark: this works for njzoom = 1. Should the definition of ij include njzoom?
+                DO jj = njs0, njs1
+                   DO ji = nis0p1, nis1m1
+                      DO jk = 1, jpkm1
+                         ii = ji -1 + nimpp
+                         vbtsdta(ii,1) = vbtsdta(ii,1) + vsdta(ii,jk,1)*fse3v(ji,jj,jk)
+                      END DO
+                      sshsdta(ii,1) = sshn(ji,jj) * tmask(ii,jj,1)
+                   END DO
+                END DO
+             ENDIF
+          ENDIF
+
+       ENDIF        !       END IF kt == nit000
+
+      !!------------------------------------------------------------------------------------
+      ! 2.      Initialize the time we are at. Does this every time the routine is called,
+      !         excepted when nobc_dta = 0
+      !
+      IF( nobc_dta == 0) THEN
+         itimo = 1
+         zxy   = 0
+      ELSE
+         IF(ntobc == 1) THEN
+            itimo = 1
+         ELSE IF (ntobc == 12) THEN      !   BC are monthly
+            ! we assume we have climatology in that case
+            iman  = 12
+            i15   = nday / 16
+            imois = nmonth + i15 - 1
+            IF( imois == 0 )   imois = iman
+            itimo = imois
+         ELSE
+            IF(lwp) WRITE(numout,*) 'data other than constant or monthly',kt
+            iman  = ntobc
+            itimo = FLOOR( kt*rdt / tcobc(1))
+            isrel=kt*rdt
+         ENDIF
+      ENDIF
+
+      ! 2. Read two records in the file if necessary
+      ! ---------------------------------------------
+
+      IF( nobc_dta == 1 .AND. nlecto == 1 ) THEN
+
+         IF( lp_obc_east ) THEN
+            ! ... Read datafile and set sea surface height and barotropic velocity
+            ! ... initialise the sshedta, ubtedta arrays
+            sshedta(:,0) = sshedta(:,1)
+            ubtedta(:,0) = ubtedta(:,1)
+            CALL iom_open ( 'obceast_TS.nc', id_e )
+            CALL iom_get ( id_e, jpdom_unknown, 'vossurfh', sshedta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_e, jpdom_unknown, 'vossurfh', sshedta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get (id_e, jpdom_unknown, 'vossurfh', sshedta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_e )
+            !
+            CALL iom_open ( 'obceast_U.nc', id_e )
+            CALL iom_get ( id_e, jpdom_unknown, 'vozoubt', ubtedta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_e, jpdom_unknown, 'vozoubt', ubtedta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get ( id_e, jpdom_unknown, 'vozoubt', ubtedta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_e )
+            ! ... Usually printout is done only once at kt = nit000, unless nprint (namelist) > 1
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read East OBC barotropic data records ', ntobc1, ntobc2
+               iprint = (jpjef-jpjed+1)/20 +1
+               WRITE(numout,*)
+               WRITE(numout,*) ' Sea surface height record 1'
+               CALL prihre( sshedta(:,1), jpjef-jpjed+1, 1, 1, jpjef-jpjed+1, iprint, 1, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal transport (m2/s) record 1',iprint
+               CALL prihre( ubtedta(:,1), jpjef-jpjed+1, 1, 1, jpjef-jpjed+1, iprint, 1, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_west ) THEN
+            ! ... Read datafile and set temperature, salinity and normal velocity
+            ! ... initialise the swdta, twdta, uwdta arrays
+            sshwdta(:,0) = sshwdta(:,1)
+            ubtwdta(:,0) = ubtwdta(:,1)
+            CALL iom_open ( 'obcwest_TS.nc', id_w )
+            CALL iom_get ( id_w, jpdom_unknown, 'vossurfh', sshwdta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_w, jpdom_unknown, 'vossurfh', sshwdta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL  ( id_w, jpdom_unknown, 'vossurfh', sshwdta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_w )
+            !
+            CALL iom_open ( 'obcwest_U.nc', id_w )
+            CALL iom_get ( id_w, jpdom_unknown, 'vozoubt', ubtwdta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_w, jpdom_unknown, 'vozoubt', ubtwdta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get ( id_w, jpdom_unknown, 'vozoubt', ubtwdta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_w )
+            ! ... Usually printout is done only once at kt = nit000, unless nprint (namelist) > 1
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read West OBC barotropic data records ', ntobc1, ntobc2
+               iprint = (jpjwf-jpjwd+1)/20 +1
+               WRITE(numout,*)
+               WRITE(numout,*) ' Sea surface height record 1  - printout surface level'
+               CALL prihre( sshwdta(:,1), jpjwf-jpjwd+1, 1, 1, jpjwf-jpjwd+1, iprint, 1, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal transport (m2/s) record 1'
+               CALL prihre( ubtwdta(:,1), jpjwf-jpjwd+1, 1, 1, jpjwf-jpjwd+1, iprint, 1, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_north) THEN
+            ! ... Read datafile and set sea surface height and barotropic velocity
+            ! ... initialise the sshndta, ubtndta arrays
+            sshndta(:,0) = sshndta(:,1)
+            vbtndta(:,0) = vbtndta(:,1)
+            CALL iom_open ( 'obcnorth_TS.nc', id_n )
+            CALL iom_get (id_n, jpdom_unknown, 'vossurfh', sshndta(:,1), ktime=ntobc1 )
+            CALL iom_get (id_n, jpdom_unknown, 'vossurfh', sshndta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get (id_n, jpdom_unknown, 'vossurfh', sshndta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_n )
+
+            CALL iom_open ( 'obcnorth_V.nc', id_n )
+            CALL iom_get (id_n, jpdom_unknown, 'vomevbt', vbtndta(:,1), ktime=ntobc1 )
+            CALL iom_get (id_n, jpdom_unknown, 'vomevbt', vbtndta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get (id_n, jpdom_unknown, 'vomevbt', vbtndta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_n )
+
+            ! ... Usually printout is done only once at kt = nit000, unless nprint (namelist) > 1
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read North OBC barotropic data records ', ntobc1, ntobc2
+               iprint = (jpinf-jpind+1)/20 +1
+               WRITE(numout,*)
+               WRITE(numout,*) ' Sea surface height record 1  - printout surface level'
+               CALL prihre( sshndta(:,1), jpinf-jpind+1, 1, 1, jpinf-jpind+1, iprint, 1, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal transport (m2/s) record 1'
+               CALL prihre( vbtndta(:,1), jpinf-jpind+1, 1, 1, jpinf-jpind+1, iprint, 1, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+         IF( lp_obc_south) THEN
+            ! ... Read datafile and set sea surface height and barotropic velocity
+            ! ... initialise the sshsdta, ubtsdta arrays
+            sshsdta(:,0) = sshsdta(:,1)
+            vbtsdta(:,0) = vbtsdta(:,1)
+            CALL iom_open ( 'obcsouth_TS.nc', id_s )
+            CALL iom_get ( id_s, jpdom_unknown, 'vossurfh', sshsdta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_s, jpdom_unknown, 'vossurfh', sshsdta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get ( id_s, jpdom_unknown, 'vossurfh', sshsdta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_s )
+
+            CALL iom_open ( 'obcsouth_V.nc', id_s )
+            CALL iom_get ( id_s, jpdom_unknown, 'vomevbt', vbtsdta(:,1), ktime=ntobc1 )
+            CALL iom_get ( id_s, jpdom_unknown, 'vomevbt', vbtsdta(:,2), ktime=ntobc2 )
+            IF( lk_dynspg_ts ) THEN
+               CALL iom_get ( id_s, jpdom_unknown, 'vomevbt', vbtsdta(:,3), ktime=ntobc2+1 )
+            ENDIF
+            CALL iom_close ( id_s )
+                
+            ! ... Usually printout is done only once at kt = nit000, unless nprint (namelist) > 1
+            IF( lwp .AND.  ( kt == nit000 .OR. nprint /= 0 )  ) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' Read South OBC barotropic data records ', ntobc1, ntobc2
+               iprint = (jpisf-jpisd+1)/20 +1
+               WRITE(numout,*)
+               WRITE(numout,*) ' Sea surface height record 1  - printout surface level'
+               CALL prihre( sshsdta(:,1), jpisf-jpisd+1, 1, 1, jpisf-jpisd+1, iprint, 1, 1, -3, 1., numout )
+               WRITE(numout,*)
+               WRITE(numout,*) ' Normal transport (m2/s) record 1'
+               CALL prihre( vbtsdta(:,1), jpisf-jpisd+1, 1, 1, jpisf-jpisd+1, iprint, 1, 1, -3, 1., numout )
+            ENDIF
+         ENDIF
+
+       ENDIF        !      end of the test on the condition to read or not the files
+
+      ! 3.  Call at every time step : Linear interpolation of BCs to current time step
+      ! ----------------------------------------------------------------------
+
+       IF( lk_dynspg_ts ) THEN
+          isrel = (kt-1)*rdt + kbt*rdtbt
+
+          IF( nobc_dta == 1 ) THEN
+             isrel = (kt-1)*rdt + kbt*rdtbt
+             itimo  = FLOOR(  kt*rdt    / (tcobc(2)-tcobc(1)) )
+             itimom = FLOOR( (kt-1)*rdt / (tcobc(2)-tcobc(1)) )
+             itimop = FLOOR( (kt+1)*rdt / (tcobc(2)-tcobc(1)) )
+             IF( itimom == itimo .AND. itimop == itimo ) THEN
+                itobcm = ntobc1
+                itobcp = ntobc2
+
+             ELSEIF ( itimom <= itimo .AND. itimop == itimo ) THEN
+                IF(  FLOOR( isrel / (tcobc(2)-tcobc(1)) ) < itimo ) THEN
+                   itobcm = ntobc1-1
+                   itobcp = ntobc2-1
+                ELSE
+                   itobcm = ntobc1
+                   itobcp = ntobc2
+                ENDIF
+
+             ELSEIF ( itimom == itimo .AND. itimop >= itimo ) THEN
+                IF(  FLOOR( isrel / (tcobc(2)-tcobc(1)) ) < itimop ) THEN
+                   itobcm = ntobc1
+                   itobcp = ntobc2
+                ELSE
+                   itobcm = ntobc1+1
+                   itobcp = ntobc2+1
+                ENDIF
+
+             ELSEIF ( itimom == itimo-1 .AND. itimop == itimo+1 ) THEN
+                IF(  FLOOR( isrel / (tcobc(2)-tcobc(1)) ) < itimo ) THEN
+                   itobcm = ntobc1-1
+                   itobcp = ntobc2-1
+                ELSEIF (  FLOOR( isrel / (tcobc(2)-tcobc(1)) ) < itimop ) THEN
+                   itobcm = ntobc1
+                   itobcp = ntobc2
+                ELSEIF (  FLOOR( isrel / (tcobc(2)-tcobc(1)) ) == itimop ) THEN
+                   itobcm = ntobc1+1
+                   itobcp = ntobc2+2
+                ELSE
+                   IF(lwp) WRITE(numout, *) 'obc_dta_bt: You should not have seen this print! error 1?'
+                ENDIF
+             ELSE
+                IF(lwp) WRITE(numout, *) 'obc_dta_bt: You should not have seen this print! error 2?'
+             ENDIF
+
+          ENDIF
+
+       ELSE IF( lk_dynspg_exp ) THEN
+          isrel=kt*rdt
+          itobcm = ntobc1
+          itobcp = ntobc2
+       ENDIF
+
+       IF( ntobc == 1 .OR. nobc_dta == 0 ) THEN
+          zxy = 0.e0
+       ELSE IF( ntobc == 12 ) THEN
+          zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
+       ELSE
+          zxy = (tcobc(itobcm)-FLOAT(isrel)) / (tcobc(itobcm)-tcobc(itobcp))
+       ENDIF
+
+       IF( lp_obc_east ) THEN           !  fills sshfoe, ubtfoe (local to each processor)
+          DO jj = nje0p1, nje1m1
+             ij = jj -1 + njmpp
+             sshfoe(jj) = ( zxy * sshedta(ij,2) + (1.-zxy) * sshedta(ij,1) ) * temsk(jj,1)
+             ubtfoe(jj) = ( zxy * ubtedta(ij,2) + (1.-zxy) * ubtedta(ij,1) ) * uemsk(jj,1)
+          END DO
+       ENDIF
+
+       IF( lp_obc_west) THEN            !  fills sshfow, ubtfow (local to each processor)
+          DO jj = njw0p1, njw1m1
+             ij = jj -1 + njmpp
+             sshfow(jj) = ( zxy * sshwdta(ij,2) + (1.-zxy) * sshwdta(ij,1) ) * twmsk(jj,1)
+             ubtfow(jj) = ( zxy * ubtwdta(ij,2) + (1.-zxy) * ubtwdta(ij,1) ) * uwmsk(jj,1)
+          END DO
+       ENDIF
+
+       IF( lp_obc_north) THEN           !  fills sshfon, vbtfon (local to each processor)
+          DO ji = nin0p1, nin1m1
+             ii = ji -1 + nimpp
+             sshfon(ji) = ( zxy * sshndta(ii,2) + (1.-zxy) * sshndta(ii,1) ) * tnmsk(ji,1)
+             vbtfon(ji) = ( zxy * vbtndta(ii,2) + (1.-zxy) * vbtndta(ii,1) ) * vnmsk(ji,1)
+          END DO
+       ENDIF
+
+       IF( lp_obc_south) THEN           !  fills sshfos, vbtfos (local to each processor)
+          DO ji = nis0p1, nis1m1
+             ii = ji -1 + nimpp
+             sshfos(ji) = ( zxy * sshsdta(ii,2) + (1.-zxy) * sshsdta(ii,1) ) * tsmsk(ji,1)
+             vbtfos(ji) = ( zxy * vbtsdta(ii,2) + (1.-zxy) * vbtsdta(ii,1) ) * vsmsk(ji,1)
+          END DO
+       ENDIF
+
+   END SUBROUTINE obc_dta_bt
+
+#else
+   !!-----------------------------------------------------------------------------
+   !!   Default option
+   !!-----------------------------------------------------------------------------
+   SUBROUTINE obc_dta_bt ( kt, kbt )       ! Empty routine
+      !! * Arguments
+      INTEGER,INTENT(in) :: kt
+      INTEGER, INTENT( in ) ::   kbt         ! barotropic ocean time-step index
+      WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kt
+      WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kbt
+   END SUBROUTINE obc_dta_bt
+#endif
+
+#else
+   !!--------------------------------------------------------------------
+   !!  default option  :  Dummy module    NO Open Boundary Conditions
+   !!--------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_dta( kt )             ! Dummy routine
+     INTEGER, INTENT (in) :: kt
+     WRITE(*,*) 'obc_dta: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_dta
+   SUBROUTINE obc_dta_bt( kt, jn)             ! Dummy routine
+     INTEGER, INTENT (in) :: kt, jn
+     WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kt
+     WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', jn
+   END SUBROUTINE obc_dta_bt
+#endif
+
+   !!=====================================================================
+END MODULE obcdta
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn.F90	(revision 4536)
@@ -0,0 +1,797 @@
+MODULE obcdyn
+#if defined key_obc
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Ocean dynamics:   Radiation of velocities on each open boundary
+   !!=================================================================================
+
+   !!---------------------------------------------------------------------------------
+   !!   obc_dyn        : call the subroutine for each open boundary
+   !!   obc_dyn_east   : radiation of the east open boundary velocities
+   !!   obc_dyn_west   : radiation of the west open boundary velocities
+   !!   obc_dyn_north  : radiation of the north open boundary velocities
+   !!   obc_dyn_south  : radiation of the south open boundary velocities
+   !!----------------------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ???
+   USE lib_mpp         ! ???
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE obccli          ! ocean open boundary conditions: climatology
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_dyn     ! routine called in dynspg_flt (free surface case)
+                      ! routine called in dynnxt.F90 (rigid lid case)
+
+   !! * Module variables
+   INTEGER ::   ji, jj, jk     ! dummy loop indices
+
+   INTEGER ::      & ! ... boundary space indices 
+      nib   = 1,   & ! nib   = boundary point
+      nibm  = 2,   & ! nibm  = 1st interior point
+      nibm2 = 3,   & ! nibm2 = 2nd interior point
+                     ! ... boundary time indices 
+      nit   = 1,   & ! nit    = now
+      nitm  = 2,   & ! nitm   = before
+      nitm2 = 3      ! nitm2  = before-before
+
+   REAL(wp) ::   rtaue  , rtauw  , rtaun  , rtaus  ,  &
+                 rtauein, rtauwin, rtaunin, rtausin
+
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_dyn ( kt )
+      !!------------------------------------------------------------------------------
+      !!                      SUBROUTINE obc_dyn
+      !!                     ********************
+      !! ** Purpose :
+      !!      Compute  dynamics (u,v) at the open boundaries.
+      !!      if defined key_dynspg_flt: 
+      !!                 this routine is called by dynspg_flt and updates
+      !!                 ua, va which are the actual velocities (not trends)
+      !!      else  (rigid lid case) , 
+      !!                 this routine is called in dynnxt.F routine and updates ua, va. 
+      !!
+      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, 
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the param_obc.h90 file).
+      !!
+      !! ** Reference : 
+      !!      Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !!
+      !! History :
+      !!        !  95-03 (J.-M. Molines) Original, SPEM
+      !!        !  97-07 (G. Madec, J.-M. Molines) addition
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+
+      IF( kt == nit000 .OR. ln_rstart) THEN
+         ! ... Boundary restoring coefficient
+         rtaue = 2. * rdt / rdpeob
+         rtauw = 2. * rdt / rdpwob
+         rtaun = 2. * rdt / rdpnob
+         rtaus = 2. * rdt / rdpsob
+         ! ... Boundary restoring coefficient for inflow ( all boundaries)
+         rtauein = 2. * rdt / rdpein 
+         rtauwin = 2. * rdt / rdpwin
+         rtaunin = 2. * rdt / rdpnin
+         rtausin = 2. * rdt / rdpsin 
+      END IF
+
+      IF( lp_obc_east  )   CALL obc_dyn_east ( kt )
+      IF( lp_obc_west  )   CALL obc_dyn_west ( kt )
+      IF( lp_obc_north )   CALL obc_dyn_north( kt )
+      IF( lp_obc_south )   CALL obc_dyn_south( kt )
+
+      IF( lk_mpp ) THEN
+         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
+            CALL lbc_lnk( ub, 'U', -1. )
+            CALL lbc_lnk( vb, 'V', -1. )
+         END IF
+         CALL lbc_lnk( ua, 'U', -1. )
+         CALL lbc_lnk( va, 'V', -1. )
+      ENDIF
+
+   END SUBROUTINE obc_dyn
+
+
+   SUBROUTINE obc_dyn_east ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_east  ***
+      !!              
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on east OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
+      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbceast is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbceast .OR. lk_dynspg_exp ) THEN
+
+         ! 1.1 U zonal velocity    
+         ! --------------------
+         DO ji = nie0, nie1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+# if defined key_dynspg_rl
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uemsk(jj,jk)) +                     &
+                                 uemsk(jj,jk)*( ufoe(jj,jk) - hur (ji,jj) / e2u (ji,jj) &
+                                 * ( bsfn(ji,jj) - bsfn(ji,jj-1) ) )
+# else
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uemsk(jj,jk)) + &
+                                 uemsk(jj,jk)*ufoe(jj,jk)
+# endif 
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = nie0+1, nie1+1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vemsk(jj,jk)) + &
+                                 vfoe(jj,jk)*vemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbceast is .FALSE.
+      ! -----------------------------------------------------
+ 
+         ! 2.1. u-component of the velocity
+         ! ---------------------------------
+         !
+         !          nibm2      nibm      nib
+         !            |   nibm  |   nib   |///
+         !            |    |    |    |    |///
+         !  jj-line --f----v----f----v----f---
+         !            |    |    |    |    |///
+         !            |         |         |///
+         !  jj-line   u    T    u    T    u///
+         !            |         |         |///
+         !            |    |    |    |    |///
+         !          jpieob-2   jpieob-1   jpieob
+         !                 |         |        
+         !              jpieob-1    jpieob    
+         !  
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... (jpjedp1, jpjefm1),jpieob
+         DO ji = nie0, nie1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  z05cx = u_cxebnd(jj,jk)
+                  z05cx = z05cx / e1t(ji,jj)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaue
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
+                  ztau = (1.-zin ) * rtauein  + zin * rtaue
+                  z05cx = z05cx * zin
+         ! ... update ua with radiative or climatological velocity
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uemsk(jj,jk) ) +          &
+                                 uemsk(jj,jk) * (  ( 1. - z05cx - ztau )         &
+                                 * uebnd(jj,jk,nib ,nitm) + 2.*z05cx               &
+                                 * uebnd(jj,jk,nibm,nit ) + ztau * ufoe (jj,jk) )  &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+# if defined key_dynspg_rl
+         ! ... ua must be a baroclinic velocity uclie() 
+         CALL obc_cli( ua, uclie, nie0, nie1, 0, jpj )  
+
+         ! ... add the correct barotropic radiative velocity (calculated from bsfn) to the 
+         !     baroclinc velocity uclie() to have the total velocity
+         DO ji = nie0, nie1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uemsk(jj,jk) ) +                     &
+                                 uemsk(jj,jk) * ( uclie(jj,jk) -  hur (ji,jj) / e2u (ji,jj) &
+                                 * ( bsfn(ji,jj) - bsfn(ji,jj-1) ) )
+               END DO
+            END DO
+         END DO
+# endif
+         ! 2.2 v-component of the velocity
+         ! -------------------------------
+         !
+         !          nibm2       nibm     nib
+         !            |   nibm  |   nib///|///
+         !            |    |    |    |////|///
+         !  jj-line --v----f----v----f----v---
+         !            |    |    |    |////|///
+         !            |    |    |    |////|///
+         !            | jpieob-1 |  jpieob /|///
+         !            |         |         |   
+         !         jpieob-1    jpieob     jpieob+1
+         !
+         ! ... radiative condition
+         ! ... (jpjedp1, jpjefm1), jpieob+1
+         DO ji = nie0+1, nie1+1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  z05cx = v_cxebnd(jj,jk) 
+                  z05cx = z05cx / e1f(ji-1,jj)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaue
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
+                  ztau = (1.-zin ) * rtauein  + zin * rtaue
+                  z05cx = z05cx * zin
+         ! ... update va with radiative or climatological velocity
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1. - vemsk(jj,jk) ) +          &
+                                 vemsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * vebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
+                                 * vebnd(jj,jk,nibm,nit ) + ztau * vfoe(jj,jk) )  &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_dyn_east
+
+
+   SUBROUTINE obc_dyn_west ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_west  ***
+      !!                  
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on west OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
+      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcwest is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcwest .OR. lk_dynspg_exp ) THEN
+
+         ! 1.1 U zonal velocity
+         ! ---------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+# if defined key_dynspg_rl
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uwmsk(jj,jk)) +                     &
+                                 uwmsk(jj,jk)*( ufow(jj,jk) - hur (ji,jj) / e2u (ji,jj) &
+                                 * ( bsfn(ji,jj) - bsfn(ji,jj-1) ) )
+# else 
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-uwmsk(jj,jk)) + &
+                                 uwmsk(jj,jk)*ufow(jj,jk)
+# endif
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vwmsk(jj,jk)) + &
+                                 vfow(jj,jk)*vwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcwest is .FALSE.
+      ! -----------------------------------------------------
+ 
+         ! 2.1. u-component of the velocity
+         ! ---------------------------------
+         !
+         !        nib       nibm     nibm2
+         !      ///|   nib   |   nibm  |
+         !      ///|    |    |    |    |
+         !      ---f----v----f----v----f-- jj-line
+         !      ///|    |    |    |    |
+         !      ///|         |         |
+         !      ///u    T    u    T    u   jj-line
+         !      ///|         |         |
+         !      ///|    |    |    |    |
+         !       jpiwob    jpiwob+1    jpiwob+2
+         !              |         |        
+         !            jpiwob+1    jpiwob+2     
+         !
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... (jpjwdp1, jpjwfm1), jpiwob
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  z05cx = u_cxwbnd(jj,jk)
+                  z05cx = z05cx / e1t(ji+1,jj)
+                  z05cx = max( z05cx, -1. )
+         ! ... z05c  > 0, inflow  zin=0, ztau=1    
+         !          =< 0, outflow zin=1, ztau=rtauw
+                  zin = sign( 1., -1. * z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin )* rtauwin + zin * rtauw
+                  z05cx = z05cx * zin
+         ! ... update un with radiative or climatological velocity
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uwmsk(jj,jk) ) +          &
+                                 uwmsk(jj,jk) * ( ( 1. + z05cx - ztau )          &
+                                 * uwbnd(jj,jk,nib ,nitm) - 2.*z05cx               &
+                                 * uwbnd(jj,jk,nibm,nit ) + ztau  * ufow (jj,jk) ) &
+                                 / (1. - z05cx)
+               END DO
+            END DO
+         END DO
+# if defined key_dynspg_rl
+         ! ... ua must be a baroclinic velocity ucliw() 
+         CALL obc_cli( ua, ucliw, niw0, niw1, 0, jpj )  
+
+         ! ... add the correct barotropic radiative velocity (calculated from bsfn)
+         !     to the baroclinc velocity ucliw() to have the total velocity
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * ( 1. - uwmsk(jj,jk) ) +                    &
+                                 uwmsk(jj,jk)*( ucliw(jj,jk) - hur (ji,jj) / e2u (ji,jj)   &
+                                 * ( bsfn(ji,jj) - bsfn(ji,jj-1) ) )
+               END DO
+            END DO
+         END DO
+# endif
+
+         ! 2.2 v-component of the velocity
+         ! -------------------------------
+         !
+         !    nib       nibm     nibm2
+         !  ///|///nib   |   nibm  |  nibm2
+         !  ///|////|    |    |    |    |    |
+         !  ---v----f----v----f----v----f----v-- jj-line
+         !  ///|////|    |    |    |    |    |
+         !  ///|////|    |    |    |    |    |
+         ! jpiwob     jpiwob+1    jpiwob+2
+         !          |         |         |   
+         !        jpiwob   jpiwob+1   jpiwob+2    
+         !
+         ! ... radiative condition plus Raymond-Kuo
+         ! ... (jpjwdp1, jpjwfm1),jpiwob
+         DO ji = niw0, niw1
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  z05cx = v_cxwbnd(jj,jk)  
+                  z05cx = z05cx / e1f(ji,jj)
+                  z05cx = max( z05cx, -1. )
+         ! ... z05cx > 0, inflow  zin=0, ztau=1    
+         !          =< 0, outflow zin=1, ztau=rtauw
+                  zin = sign( 1., -1. * z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin )*rtauwin + zin * rtauw
+                  z05cx = z05cx * zin 
+         ! ... update va with radiative or climatological velocity
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1. - vwmsk(jj,jk) ) +          &
+                                 vwmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
+                                 * vwbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
+                                 * vwbnd(jj,jk,nibm,nit ) + ztau * vfow (jj,jk) ) &
+                                 / (1. - z05cx)
+                END DO
+             END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_dyn_west
+
+   SUBROUTINE obc_dyn_north ( kt )
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_north
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on north OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
+      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcnorth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! ---------------------------------------------------------
+ 
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcnorth  .OR. lk_dynspg_exp ) THEN
+
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njn0+1, njn1+1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua(ji,jj,jk)= ua(ji,jj,jk) * (1.-unmsk(ji,jk)) + &
+                                ufon(ji,jk)*unmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njn0, njn1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+# if defined key_dynspg_rl
+                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vnmsk(ji,jk)) +                       &
+                                vnmsk(ji,jk) * ( vfon(ji,jk) + hvr (ji,jj) / e1v (ji,jj) &
+                                * ( bsfn(ji,jj) - bsfn(ji-1,jj) ) )
+# else
+                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vnmsk(ji,jk)) + &
+                                vfon(ji,jk)*vnmsk(ji,jk)
+# endif
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcnorth is .FALSE.
+      ! ------------------------------------------------------
+
+         ! 2.1. u-component of the velocity
+         ! --------------------------------
+         !
+         !            ji-row
+         !              |
+         !       nib ///u//////  jpjnob + 1
+         !         /////|//////
+         !     nib -----f-----   jpjnob
+         !              |    
+         !      nibm--  u   ---- jpjnob
+         !              |        
+         !    nibm -----f-----   jpjnob-1
+         !              |        
+         !     nibm2--  u   ---- jpjnob-1
+         !              |        
+         !   nibm2 -----f-----   jpjnob-2
+         !              |
+         !
+         ! ... radiative condition
+         ! ... jpjnob+1,(jpindp1, jpinfm1)
+         DO jj = njn0+1, njn1+1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  z05cx= u_cynbnd(ji,jk) 
+                  z05cx = z05cx / e2f(ji, jj-1)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaun
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
+                  ztau = (1.-zin ) * rtaunin  + zin * rtaun
+         ! ... for u, when inflow, ufon is prescribed
+                  z05cx = z05cx * zin
+         ! ... update un with radiative or climatological velocity
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-unmsk(ji,jk)) +             &
+                                 unmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * unbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
+                                 * unbnd(ji,jk,nibm,nit ) + ztau * ufon (ji,jk) ) &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+
+         ! 2.2 v-component of the velocity
+         ! -------------------------------
+         !
+         !                ji-row    ji-row
+         !              |         |
+         !         /////|/////////////////
+         !    nib  -----f----v----f----  jpjnob
+         !              |         |
+         !      nib  -  u -- T -- u ---- jpjnob
+         !              |         |
+         !   nibm  -----f----v----f----  jpjnob-1
+         !              |         |
+         !     nibm --  u -- T -- u ---  jpjnob-1
+         !              |         |
+         !   nibm2 -----f----v----f----  jpjnob-2
+         !              |         |
+         !
+         ! ... If rigidlid formulation:
+         ! ... radiative conditions on the baroclinic part only + relaxation toward climatology 
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... jpjnob,(jpindp1, jpinfm1)
+         DO jj = njn0, njn1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+         ! ... 2* gradj(v) (T-point i=nibm, time mean)
+                  z05cx = v_cynbnd(ji,jk)
+                  z05cx = z05cx / e2t(ji,jj)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaun
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
+                  ztau = (1.-zin ) * rtaunin + zin * rtaun
+                  z05cx = z05cx * zin
+         ! ... update va with radiative or climatological velocity
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vnmsk(ji,jk)) +             &
+                                 vnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * vnbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
+                                 * vnbnd(ji,jk,nibm,nit ) + ztau * vfon (ji,jk) ) &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+# if defined key_dynspg_rl
+         ! ... va must be a baroclinic velocity vclin() 
+         CALL obc_cli( va, vclin, njn0, njn1, 1, jpi )  
+
+         ! ... add the correct barotropic radiative velocity (calculated from bsfn)
+         !     to the baroclinc velocity vclin() to have the total velocity
+         DO jj = njn0, njn1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vnmsk(ji,jk)) +                         &
+                                 vnmsk(ji,jk) * ( vclin(ji,jk) +  hvr (ji,jj) / e1v (ji,jj) &
+                                 * ( bsfn(ji,jj) - bsfn(ji-1,jj) ) )
+               END DO
+            END DO
+         END DO
+# endif
+      END IF
+
+   END SUBROUTINE obc_dyn_north
+
+   SUBROUTINE obc_dyn_south ( kt )
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_south
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on south OBC velocities ua, va using the 
+      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
+      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!    9.0  ! 05-11  (V. Garnier) Surface pressure gradient organization
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      REAL(wp) ::   z05cx, ztau, zin
+
+      !!------------------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcsouth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! ---------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcsouth  .OR. lk_dynspg_exp ) THEN
+
+         ! 1.1 U zonal velocity
+         ! --------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ua(ji,jj,jk)= ua(ji,jj,jk) * (1.-usmsk(ji,jk)) + &
+                                usmsk(ji,jk) * ufos(ji,jk)
+               END DO
+            END DO
+         END DO
+
+         ! 1.2 V meridional velocity
+         ! -------------------------
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+# if defined key_dynspg_rl
+                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vsmsk(ji,jk)) +                      &
+                                vsmsk(ji,jk) * (vfos(ji,jk) + hvr (ji,jj) / e1v (ji,jj) &
+                                * ( bsfn(ji,jj) - bsfn(ji-1,jj) ) )
+# else 
+                  va(ji,jj,jk)= va(ji,jj,jk) * (1.-vsmsk(ji,jk)) + &
+                                vsmsk(ji,jk) * vfos(ji,jk)
+# endif
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcsouth is .FALSE.
+      ! ------------------------------------------------------
+
+         ! 2.1. u-component of the velocity
+         ! --------------------------------
+         !
+         !            ji-row
+         !              |
+         !   nibm2 -----f-----   jpjsob +2
+         !              |    
+         !    nibm2 --  u   ---- jpjsob +2 
+         !              |        
+         !    nibm -----f-----   jpjsob +1
+         !              |        
+         !    nibm  --  u   ---- jpjsob +1
+         !              |        
+         !    nib  -----f-----   jpjsob
+         !         /////|//////
+         !    nib   ////u/////   jpjsob 
+         !
+         ! ... radiative condition plus Raymond-Kuo
+         ! ... jpjsob,(jpisdp1, jpisfm1)
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  z05cx= u_cysbnd(ji,jk) 
+                  z05cx = z05cx / e2f(ji, jj)
+                  z05cx = max( z05cx, -1. )
+         ! ... z05cx > 0, inflow  zin=0, ztau=1 
+         !          =< 0, outflow zin=1, ztau=rtaus
+                  zin = sign( 1., -1. * z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin ) * rtausin + zin * rtaus
+                  z05cx = z05cx * zin 
+         ! ... update ua with radiative or climatological velocity
+                  ua(ji,jj,jk) = ua(ji,jj,jk) * (1.-usmsk(ji,jk)) +              &
+                                 usmsk(ji,jk) * (  ( 1. + z05cx - ztau )         &
+                                 * usbnd(ji,jk,nib ,nitm) - 2.*z05cx               &
+                                 * usbnd(ji,jk,nibm,nit ) + ztau * ufos (ji,jk) )  &
+                                 / (1. - z05cx)
+               END DO
+            END DO
+         END DO
+
+         ! 2.2 v-component of the velocity
+         ! -------------------------------
+         !
+         !                ji-row    ji-row
+         !              |         |
+         !  nibm2  -----f----v----f----  jpjsob+2
+         !              |         |
+         !    nibm   -  u -- T -- u ---- jpjsob+2
+         !              |         |
+         !   nibm  -----f----v----f----  jpjsob+1 
+         !              |         |
+         !   nib    --  u -- T -- u ---  jpjsob+1
+         !              |         |
+         !   nib   -----f----v----f----  jpjsob
+         !         /////////////////////
+         !
+         ! ... If rigidlid formulation:
+         ! ... radiative conditions on the baroclinic part only + relaxation toward climatology
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... jpjsob,(jpisdp1,jpisfm1)
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  z05cx = v_cysbnd(ji,jk)
+                  z05cx = z05cx / e2t(ji,jj+1)
+                  z05cx = max( z05cx, -1. )
+         ! ... z05c > 0, inflow  zin=0, ztau=1 
+         !         =< 0, outflow zin=1, ztau=rtaus
+                  zin = sign( 1., -1. * z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin )*rtausin + zin * rtaus
+                  z05cx = z05cx * zin
+         ! ... update va with radiative or climatological velocity
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vsmsk(ji,jk)) +             &
+                                 vsmsk(ji,jk) * ( ( 1. + z05cx - ztau )         &
+                                 * vsbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
+                                 * vsbnd(ji,jk,nibm,nit ) + ztau * vfos (ji,jk) ) &
+                                 / (1. - z05cx)
+               END DO
+            END DO
+         END DO
+# if defined key_dynspg_rl 
+         ! ... va must be a baroclinic velocity vclis() 
+         CALL obc_cli( va, vclis, njs0, njs1, 1, jpi )  
+
+         ! ... add the correct barotropic radiative velocity (calculated from bsfn)
+         !     to the baroclinic velocity vclis() to have the total velocity
+         DO jj = njs0, njs1
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va(ji,jj,jk) = va(ji,jj,jk) * (1.-vsmsk(ji,jk)) +                         &
+                                 vsmsk(ji,jk) * ( vclis(ji,jk) +  hvr (ji,jj) / e1v (ji,jj) &
+                                 * ( bsfn(ji,jj) - bsfn(ji-1,jj) ) )
+               END DO
+            END DO
+         END DO
+# endif
+      END IF
+
+   END SUBROUTINE obc_dyn_south
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn  ***
+   !! Ocean dynamics:   Radiation of velocities on each open boundary
+   !!=================================================================================
+CONTAINS
+
+   SUBROUTINE obc_dyn
+                              ! No open boundaries ==> empty routine
+   END SUBROUTINE obc_dyn
+#endif
+
+END MODULE obcdyn
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn_bt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn_bt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcdyn_bt.F90	(revision 4536)
@@ -0,0 +1,362 @@
+MODULE obcdyn_bt
+#if ( defined key_dynspg_ts || defined key_dynspg_exp ) & defined key_obc
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn_bt  ***
+   !! Ocean dynamics:   Radiation/prescription of sea surface heights
+   !!                   on each open boundary
+   !!=================================================================================
+
+   !!---------------------------------------------------------------------------------
+   !!   obc_dyn_bt        : call the subroutine for each open boundary
+   !!   obc_dyn_bt_east   : Flather's algorithm at the east open boundary
+   !!   obc_dyn_bt_west   : Flather's algorithm at the west open boundary
+   !!   obc_dyn_bt_north  : Flather's algorithm at the north open boundary
+   !!   obc_dyn_bt_south  : Flather's algorithm at the south open boundary
+   !!----------------------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! distributed memory computing
+   USE obccli          ! ocean open boundary conditions: climatology
+   USE in_out_manager  ! I/O manager
+   USE dynspg_oce      ! surface pressure gradient     (free surface with time-splitting)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_dyn_bt  ! routine called in dynnxt (explicit free surface case)
+
+   !!---------------------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_dyn_bt ( kt )
+      !!------------------------------------------------------------------------------
+      !!                      SUBROUTINE obc_dyn_bt
+      !!                     ***********************
+      !! ** Purpose :
+      !!      Apply Flather's algorithm at open boundaries for the explicit
+      !!      free surface case and free surface case with time-splitting
+      !!
+      !!      This routine is called in dynnxt.F routine and updates ua, va and sshn. 
+      !!
+      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, 
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the param_obc.h90 file).
+      !!
+      !! ** Reference : 
+      !!         Flather, R. A., 1976, Mem. Soc. R. Sci. Liege, Ser. 6, 10, 141-164
+      !!
+      !! History :
+      !!   9.0  !  05-12  (V. Garnier) original 
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !!----------------------------------------------------------------------
+
+      IF( lp_obc_east  )   CALL obc_dyn_bt_east 
+      IF( lp_obc_west  )   CALL obc_dyn_bt_west 
+      IF( lp_obc_north )   CALL obc_dyn_bt_north
+      IF( lp_obc_south )   CALL obc_dyn_bt_south
+
+      IF( lk_mpp ) THEN
+         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
+            CALL lbc_lnk( sshb, 'T',  1. )
+            CALL lbc_lnk( ub  , 'U', -1. )
+            CALL lbc_lnk( vb  , 'V', -1. )
+         END IF
+         CALL lbc_lnk( sshn, 'T',  1. )
+         CALL lbc_lnk( ua  , 'U', -1. )
+         CALL lbc_lnk( va  , 'V', -1. )
+      ENDIF
+
+   END SUBROUTINE obc_dyn_bt
+
+# if defined key_dynspg_exp
+   SUBROUTINE obc_dyn_bt_east 
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_bt_east  ***
+      !!              
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on east OBC velocities ua, va 
+      !!      Fix sea surface height (sshn) on east open boundary
+      !!      The logical lfbceast must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO ji = nie0, nie1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(ji,jj,jk) = ua(ji,jj,jk) + sqrt( grav*hur (ji,jj) )               &
+                  &                      * ( ( sshn(ji,jj) + sshn(ji+1,jj) ) * 0.5  &
+                  &                          - sshfoe(jj) ) * uemsk(jj,jk)
+            END DO
+         END DO
+      END DO
+      DO ji = nie0p1, nie1p1
+         DO jj = 1, jpj
+            sshn(ji,jj) = sshn(ji,jj) * (1.-temsk(jj,1)) + temsk(jj,1)*sshfoe(jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_east
+
+
+   SUBROUTINE obc_dyn_bt_west 
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_bt_west  ***
+      !!                  
+      !! ** Purpose :
+      !!      Apply Flather algorithm on west OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on west open boundary
+      !!      The logical lfbcwest must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO ji = niw0, niw1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(ji,jj,jk) = ua(ji,jj,jk) - sqrt( grav*hur (ji,jj) )               &
+                  &                      * ( ( sshn(ji,jj) + sshn(ji+1,jj) ) * 0.5  &
+                  &                          - sshfow(jj) ) * uwmsk(jj,jk)
+            END DO
+         END DO
+         DO jj = 1, jpj
+            sshn(ji,jj) = sshn(ji,jj) * (1.-twmsk(jj,1)) + twmsk(jj,1)*sshfow(jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_west
+
+   SUBROUTINE obc_dyn_bt_north 
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_dyn_bt_north  ***
+      !!
+      !! ** Purpose :
+      !!      Apply Flather algorithm on north OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on north open boundary
+      !!      The logical lfbcnorth must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO jj = njn0, njn1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,jj,jk) = va(ji,jj,jk) + sqrt( grav*hvr (ji,jj) )               &
+                  &                      * ( ( sshn(ji,jj) + sshn(ji,jj+1) ) * 0.5  &
+                  &                          - sshfon(ji) ) * vnmsk(ji,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = njn0p1, njn1p1
+         DO ji = 1, jpi
+            sshn(ji,jj)= sshn(ji,jj) * (1.-tnmsk(ji,1)) + sshfon(ji)*tnmsk(ji,1)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_north
+
+   SUBROUTINE obc_dyn_bt_south 
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_dyn_bt_south  ***
+      !!                    
+      !! ** Purpose :
+      !!      Apply Flather algorithm on south OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on south open boundary
+      !!      The logical lfbcsouth must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+
+      !!------------------------------------------------------------------------------
+
+      DO jj = njs0, njs1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,jj,jk) = va(ji,jj,jk) - sqrt( grav*hvr (ji,jj) )               &
+                  &                       * ( ( sshn(ji,jj) + sshn(ji,jj+1) ) * 0.5 &
+                  &                           - sshfos(ji) ) * vsmsk(ji,jk)
+            END DO
+         END DO
+         DO ji = 1, jpi
+            sshn(ji,jj)= sshn(ji,jj) * (1.-tsmsk(ji,1)) + tsmsk(ji,1) * sshfos(ji)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_south
+
+# elif defined key_dynspg_ts
+
+   SUBROUTINE obc_dyn_bt_east 
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_bt_east  ***
+      !!
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on east OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on east open boundary
+      !!      The logical lfbceast must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO ji = nie0, nie1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) + sshfoe_b(ji,jj) ) * uemsk(jj,jk)
+            END DO
+         END DO
+      END DO
+      DO ji = nie0p1, nie1p1
+         DO jj = 1, jpj
+            sshn(ji,jj) = sshn(ji,jj) * (1.-temsk(jj,1)) + temsk(jj,1)*sshn_b(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_east
+
+   SUBROUTINE obc_dyn_bt_west 
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_dyn_bt_west  ***
+      !!
+      !! ** Purpose :
+      !! ** Purpose :
+      !!      Apply Flather algorithm on west OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on west open boundary
+      !!      The logical lfbcwest must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO ji = niw0, niw1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) + sshfow_b(ji,jj) ) * uwmsk(jj,jk)
+            END DO
+         END DO
+         DO jj = 1, jpj
+            sshn(ji,jj) = sshn(ji,jj) * (1.-twmsk(jj,1)) + twmsk(jj,1)*sshn_b(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_west
+
+   SUBROUTINE obc_dyn_bt_north 
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_bt_north
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply Flather algorithm on north OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on north open boundary
+      !!      The logical lfbcnorth must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      DO jj = njn0, njn1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,jj,jk) = ( va(ji,jj,jk) + sshfon_b(ji,jj) ) * vnmsk(jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = njn0p1, njn1p1
+         DO ji = 1, jpi
+            sshn(ji,jj)= sshn(ji,jj) * (1.-tnmsk(ji,1)) + sshn_b(ji,jj)*tnmsk(ji,1)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_north
+
+   SUBROUTINE obc_dyn_bt_south 
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_dyn_bt_south
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply Flather algorithm on south OBC velocities ua, va
+      !!      Fix sea surface height (sshn) on south open boundary
+      !!      The logical lfbcsouth must be .TRUE.
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+
+      !!------------------------------------------------------------------------------
+
+      DO jj = njs0, njs1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va(ji,jj,jk) = ( va(ji,jj,jk) + sshfos_b(ji,jj) ) * vsmsk(jj,jk)
+            END DO
+         END DO
+         DO ji = 1, jpi
+            sshn(ji,jj)= sshn(ji,jj) * (1.-tsmsk(ji,1)) + tsmsk(ji,1) * sshn_b(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_dyn_bt_south
+
+# endif
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcdyn_bt  ***
+   !! Ocean dynamics:   Radiation of velocities on each open boundary
+   !!=================================================================================
+CONTAINS
+
+   SUBROUTINE obc_dyn_bt
+                              ! No open boundaries ==> empty routine
+   END SUBROUTINE obc_dyn_bt
+#endif
+
+END MODULE obcdyn_bt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcfla.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcfla.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcfla.F90	(revision 4536)
@@ -0,0 +1,225 @@
+MODULE obcfla
+#if defined key_obc && defined key_dynspg_ts
+   !!=================================================================================
+   !!                       ***  MODULE  obcfla  ***
+   !! Ocean dynamics:   Flather's algorithm at open boundaries for the time-splitting
+   !!=================================================================================
+
+   !!---------------------------------------------------------------------------------
+   !!   obc_fla_ts        : call the subroutine for each open boundary
+   !!   obc_fla_ts_east   : Flather on the east  open boundary velocities & ssh
+   !!   obc_fla_ts_west   : Flather on the west  open boundary velocities & ssh
+   !!   obc_fla_ts_north  : Flather on the north open boundary velocities & ssh
+   !!   obc_fla_ts_south  : Flather on the south open boundary velocities & ssh
+   !!----------------------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE obcdta          ! ocean open boundary conditions: climatology
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_fla_ts  ! routine called in dynspg_ts (free surface time splitting case)
+
+   !!---------------------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005)
+   !! $Header$
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_fla_ts
+      !!------------------------------------------------------------------------------
+      !!                      SUBROUTINE obc_fla_ts
+      !!                     **********************
+      !! ** Purpose :
+      !!      Apply Flather's algorithm at open boundaries for the time-splitting
+      !!      free surface case (barotropic variables)
+      !!
+      !!      This routine is called in dynspg_ts.F90 routine 
+      !!
+      !!      The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the obc_par.F90 file).
+      !!
+      !! ** Reference :
+      !!         Flather, R. A., 1976, Mem. Soc. R. Sci. Liege, Ser. 6, 10, 141-164
+      !!
+      !! History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+
+      IF( lp_obc_east  )   CALL obc_fla_ts_east 
+      IF( lp_obc_west  )   CALL obc_fla_ts_west 
+      IF( lp_obc_north )   CALL obc_fla_ts_north
+      IF( lp_obc_south )   CALL obc_fla_ts_south
+
+   END SUBROUTINE obc_fla_ts
+
+
+   SUBROUTINE obc_fla_ts_east
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_fla_ts_east  ***
+      !!
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on east OBC velocities ua, va
+      !!      Fix sea surface height (sshn_e) on east open boundary
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      DO ji = nie0, nie1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua_e(ji,jj) = (  ubtfoe(jj) + sqrt( grav*hu(ji,jj) )           &
+                  &            * ( ( sshn_e(ji,jj) + sshn_e(ji+1,jj) ) * 0.5  &
+                  &            - sshfoe(jj) )  ) * uemsk(jj,jk)
+            END DO
+         END DO
+      END DO
+      DO ji = nie0p1, nie1p1
+         DO jj = 1, jpj
+            sshfoe_b(ji,jj) = sshfoe_b(ji,jj) + sqrt( grav*hur(ji,jj) )     &
+               &             * ( ( sshn_e(ji,jj) + sshn_e(ji+1,jj) ) * 0.5  &
+               &                 - sshfoe(jj) ) * uemsk(jj,1)
+            ssha_e(ji,jj) = ssha_e(ji,jj) * ( 1. - temsk(jj,1) ) &
+               &            + temsk(jj,1) * sshfoe(jj)
+            va_e(ji,jj) = vbtfoe(jj) * uemsk(jj,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_fla_ts_east
+
+
+   SUBROUTINE obc_fla_ts_west
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_fla_ts_west  ***
+      !! 
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on west OBC velocities ua, va
+      !!      Fix sea surface height (sshn_e) on west open boundary
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      DO ji = niw0, niw1
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               ua_e(ji,jj) = ( ubtfow(jj) - sqrt( grav * hu(ji,jj) )          &
+                  &            * ( ( sshn_e(ji,jj) + sshn_e(ji+1,jj) ) * 0.5  &
+                  &                - sshfow(jj) ) ) * uwmsk(jj,jk)
+               va_e(ji,jj) = vbtfow(jj) * uwmsk(jj,jk)
+            END DO
+         END DO
+         DO jj = 1, jpj
+            sshfow_b(ji,jj) = sshfow_b(ji,jj) - sqrt( grav * hur(ji,jj) )     &
+                              * ( ( sshn_e(ji,jj) + sshn_e(ji+1,jj) ) * 0.5   &
+                                 - sshfow(jj) ) * uwmsk(jj,1)
+            ssha_e(ji,jj) = ssha_e(ji,jj) * ( 1. - twmsk(jj,1) ) &
+               &            + twmsk(jj,1)*sshfow(jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_fla_ts_west
+
+   SUBROUTINE obc_fla_ts_north
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_fla_ts_north
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on north OBC velocities ua, va
+      !!      Fix sea surface height (sshn_e) on north open boundary
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+      !!------------------------------------------------------------------------------
+
+      DO jj = njn0, njn1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va_e(ji,jj) = ( vbtfon(ji) + sqrt( grav * hv(ji,jj) )           &
+                  &            * ( ( sshn_e(ji,jj) + sshn_e(ji,jj+1) ) * 0.5   &
+                  &                - sshfon(ji) ) ) * vnmsk(ji,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = njn0p1, njn1p1
+         DO ji = 1, jpi
+            sshfon_b(ji,jj) = sshfon_b(ji,jj) + sqrt( grav * hvr(ji,jj) )  &
+               &              * ( ( sshn_e(ji,jj) + sshn_e(ji,jj+1) ) * 0.5    &
+               &                  - sshfon(ji) ) * vnmsk(ji,1)
+            ssha_e(ji,jj) = ssha_e(ji,jj) * ( 1. - tnmsk(ji,1) ) &
+               &            + sshfon(ji) * tnmsk(ji,1)
+            ua_e(ji,jj) = ubtfon(ji) * vnmsk(ji,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_fla_ts_north
+
+   SUBROUTINE obc_fla_ts_south
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_fla_ts_south
+      !!                    *************************
+      !! ** Purpose :
+      !!      Apply Flather's algorithm on south OBC velocities ua, va
+      !!      Fix sea surface height (sshn_e) on south open boundary
+      !!
+      !!  History :
+      !!   9.0  !  05-12  (V. Garnier) original
+      !!------------------------------------------------------------------------------
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk ! dummy loop indices
+
+      !!------------------------------------------------------------------------------
+
+      DO jj = njs0, njs1
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+               va_e(ji,jj) = ( vbtfos(ji) - sqrt( grav * hv(ji,jj) )            &
+                  &            * ( ( sshn_e(ji,jj) + sshn_e(ji,jj+1) ) * 0.5    &
+                  &                - sshfos(ji) ) ) * vsmsk(ji,jk)
+               ua_e(ji,jj) = ubtfos(ji) * vsmsk(ji,jk)
+            END DO
+         END DO
+         DO ji = 1, jpi
+            sshfos_b(ji,jj) = sshfos_b(ji,jj) - sqrt( grav * hvr(ji,jj) )      &
+               &              * ( ( sshn_e(ji,jj) + sshn_e(ji,jj+1) ) * 0.5    &
+               &                  - sshfos(ji) ) * vsmsk(ji,1)
+            ssha_e(ji,jj) = ssha_e(ji,jj) * (1. - tsmsk(ji,1) ) &
+               &            + tsmsk(ji,1) * sshfos(ji)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_fla_ts_south
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcfla  ***
+   !! Ocean dynamics:   Flather's algorithm at open boundaries for the time-splitting
+   !!=================================================================================
+CONTAINS
+
+   SUBROUTINE obc_fla_ts
+      WRITE(*,*) 'obc_fla_ts: You should not have seen this print! error?'
+   END SUBROUTINE obc_fla_ts
+#endif
+
+END MODULE obcfla
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcini.F90	(revision 4536)
@@ -0,0 +1,845 @@
+ MODULE obcini
+   !!=================================================================================
+   !!                       ***  MODULE  obcini  ***
+   !! OBC initial state :  Open boundary initial state
+   !!=================================================================================
+#if defined key_obc
+   !!---------------------------------------------------------------------------------
+   !!   'key_obc'                                             Open Boundary Conditions
+   !!---------------------------------------------------------------------------------
+   !!   obc_init       : initialization for the open boundary condition
+   !!---------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! for mpp_sum
+   USE in_out_manager  ! I/O units
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC obc_init        ! routine called by opa.F90
+
+   !! * Substitutions
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE obc_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE obc_init  ***
+      !!         
+      !! ** Purpose :   Initialization of the dynamics and tracer fields at 
+      !!      the open boundaries.
+      !!
+      !! ** Method  :   initialization of open boundary variables
+      !!      (u, v, bsf) over 3 time step and 3 rows
+      !!      (t, s)      over 2 time step and 2 rows
+      !!      if ln_rstart = .FALSE. : no restart, fields set to zero
+      !!      if ln_rstart = .TRUE.  : restart, fields are read in a file 
+      !!      if rdpxxx = 0 then lfbc is set true for this boundary.
+      !!
+      !! ** Input   :   restart.obc file, restart file for open boundaries 
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!        !  97-11  (J.M. Molines)
+      !!   8.5  !  02-11  (C. Talandier, A-M. Treguier) Free surface, F90
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE obcrst,   ONLY :   obc_rst_lec   ! Make obc_rst_lec routine available
+      USE obcdom,   ONLY :   obc_dom       ! Make obc_dom routine available
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, istop , inumfbc
+      INTEGER, DIMENSION(4) ::   icorner
+      REAL(wp) ::   zbsic1, zbsic2, zbsic3
+      REAL(wp), DIMENSION(2) ::   ztestmask
+
+      NAMELIST/namobc/ rdpein, rdpwin, rdpnin, rdpsin,   &
+         &             rdpeob, rdpwob, rdpnob, rdpsob,   &
+         &             zbsic1, zbsic2, zbsic3,           &
+         &             nbic, volemp, nobc_dta,           &
+         &             ln_obc_clim, ln_vol_cst, ln_obc_fla
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'obc_init : initialization of open boundaries'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+
+
+      ! 0. read namelist parameters
+      ! ---------------------------
+      ! default values already set except:
+      zbsic1 = 0.e0
+      zbsic2 = 0.e0
+      zbsic3 = 0.e0
+
+      ! Namelist namobc : open boundaries
+      REWIND( numnam )
+      READ  ( numnam, namobc )
+
+      bsfic0(1) = zbsic1
+      bsfic (2) = zbsic2
+      bsfic (3) = zbsic3
+
+      ! By security we set rdpxin and rdpxob respectively
+      ! to 1. and 15. if the corresponding OBC is not activated
+      IF( .NOT.lp_obc_east ) THEN
+         rdpein = 1.
+         rdpeob = 15.
+      END IF
+      IF( .NOT.lp_obc_west ) THEN
+         rdpwin = 1.
+         rdpwob = 15.
+      END IF
+      IF( .NOT.lp_obc_north ) THEN
+         rdpnin = 1.
+         rdpnob = 15.
+      END IF
+      IF( .NOT.lp_obc_south ) THEN
+         rdpsin = 1.
+         rdpsob = 15.
+      END IF
+
+      ! number of open boudaries and open boundary indicators
+      nbobc = 0
+      IF( lp_obc_east  )   nbobc = nbobc + 1
+      IF( lp_obc_west  )   nbobc = nbobc + 1
+      IF( lp_obc_north )   nbobc = nbobc + 1
+      IF( lp_obc_south )   nbobc = nbobc + 1
+
+      IF(lwp) WRITE(numout,*) '         Number of open boundaries    nbobc = ',nbobc
+      IF(lwp) WRITE(numout,*)
+      IF( nbobc /= 0 .AND. jperio /= 0 ) &
+           &   CALL ctl_stop( ' Cyclic or symmetric, and open boundary condition are not compatible' )
+
+      ! control prints
+      IF(lwp) WRITE(numout,*) '         namobc'
+      IF(lwp) WRITE(numout,*) ' '
+      IF(lwp) WRITE(numout,*) '         data in file (=1) or     nobc_dta = ', nobc_dta
+      IF(lwp) WRITE(numout,*) '         initial state used (=0)             '
+      IF(lwp) WRITE(numout,*) '         climatology (true) or not:', ln_obc_clim
+      IF(lwp) WRITE(numout,*) ' '
+      IF(lwp) WRITE(numout,*) '                                 WARNING                                                  '
+      IF(lwp) WRITE(numout,*) '         Flather"s algorithm is applied with explicit free surface scheme                 '
+      IF(lwp) WRITE(numout,*) '         or with free surface time-splitting scheme                                       '
+      IF(lwp) WRITE(numout,*) '         Nor radiation neither relaxation is allowed with explicit free surface scheme:   '
+      IF(lwp) WRITE(numout,*) '         Radiation and/or relaxation is allowed with free surface time-splitting scheme '
+      IF(lwp) WRITE(numout,*) '         depending of the choice of rdpXin = rdpXob  = 0. for open boundaries             '
+      IF(lwp) WRITE(numout,*) ' '
+      IF(lwp) WRITE(numout,*) '         For the rigid-lid case or the filtered free surface case,                        '
+      IF(lwp) WRITE(numout,*) '         radiation, relaxation or presciption of data can be applied                      '
+      IF( lwp.AND.lp_obc_east ) THEN
+         WRITE(numout,*) '         East open boundary :'
+         WRITE(numout,*) '              i index                    jpieob = ', jpieob
+         WRITE(numout,*) '              damping time scale (days)  rdpeob = ', rdpeob
+         WRITE(numout,*) '              damping time scale (days)  rdpein = ', rdpein
+      ENDIF
+
+      IF( lwp.AND.lp_obc_west ) THEN
+         WRITE(numout,*) '         West open boundary :'
+         WRITE(numout,*) '              i index                    jpiwob = ', jpiwob
+         WRITE(numout,*) '              damping time scale (days)  rdpwob = ', rdpwob
+         WRITE(numout,*) '              damping time scale (days)  rdpwin = ', rdpwin
+      ENDIF
+
+      IF( lwp.AND.lp_obc_north ) THEN
+         WRITE(numout,*) '         North open boundary :'
+         WRITE(numout,*) '               j index                    jpjnob = ', jpjnob
+         WRITE(numout,*) '               damping time scale (days)  rdpnob = ', rdpnob
+         WRITE(numout,*) '               damping time scale (days)  rdpnin = ', rdpnin
+      ENDIF
+
+      IF( lwp.AND.lp_obc_south ) THEN
+         WRITE(numout,*) '         South open boundary :'
+         WRITE(numout,*) '               j index                    jpjsob = ', jpjsob
+         WRITE(numout,*) '               damping time scale (days)  rdpsob = ', rdpsob
+         WRITE(numout,*) '               damping time scale (days)  rdpsin = ', rdpsin
+         WRITE(numout,*) ' '
+      ENDIF
+
+      ! 1. Initialisation of constants 
+      ! ------------------------------
+
+      ! ... convert rdp$ob in seconds
+      rdpein = rdpein * rday
+      rdpwin = rdpwin * rday
+      rdpnin = rdpnin * rday
+      rdpsin = rdpsin * rday
+      rdpeob = rdpeob * rday
+      rdpwob = rdpwob * rday
+      rdpnob = rdpnob * rday
+      rdpsob = rdpsob * rday
+      lfbceast  = .FALSE.
+      lfbcwest  = .FALSE.
+      lfbcnorth = .FALSE.
+      lfbcsouth = .FALSE.
+      inumfbc = 0
+      ! ... look for Fixed Boundaries (rdp = 0 )
+      ! ... When specified, lbcxxx flags are set to TRUE and rdpxxx are set to
+      ! ...  a small arbitrary value, (to avoid division by zero further on). 
+      ! ...  rdpxxx is not used anymore.
+      IF( lp_obc_east )  THEN
+         IF( (rdpein+rdpeob) == 0 )  THEN
+            lfbceast = .TRUE.
+            rdpein = 1e-3
+            rdpeob = 1e-3
+            inumfbc = inumfbc+1
+         ELSEIF ( (rdpein*rdpeob) == 0 )  THEN
+            CALL ctl_stop( 'obc_init : rdpein & rdpeob must be both zero or non zero' )
+         END IF
+      END IF
+      IF( lp_obc_west )  THEN
+         IF( (rdpwin + rdpwob) == 0 )  THEN
+            lfbcwest = .TRUE.
+            rdpwin = 1e-3
+            rdpwob = 1e-3
+            inumfbc = inumfbc+1
+         ELSEIF ( (rdpwin*rdpwob) == 0 )  THEN
+            CALL ctl_stop( 'obc_init : rdpwin & rdpwob must be both zero or non zero' )
+         END IF
+      END IF
+      IF( lp_obc_north )  THEN
+         IF( (rdpnin + rdpnob) == 0 )  THEN
+            lfbcnorth = .TRUE.
+            rdpnin = 1e-3
+            rdpnob = 1e-3
+            inumfbc = inumfbc+1
+         ELSEIF ( (rdpnin*rdpnob) == 0 )  THEN
+            CALL ctl_stop( 'obc_init : rdpnin & rdpnob must be both zero or non zero' )
+         END IF
+      END IF
+      IF( lp_obc_south )  THEN
+         IF( (rdpsin + rdpsob) == 0 )  THEN
+            lfbcsouth = .TRUE.
+            rdpsin = 1e-3
+            rdpsob = 1e-3
+            inumfbc = inumfbc+1
+         ELSEIF ( (rdpsin*rdpsob) == 0 )  THEN
+            CALL ctl_stop( 'obc_init : rdpsin & rdpsob must be both zero or non zero' )
+         END IF
+      END IF
+
+      ! 2.  Clever mpp indices for loops on the open boundaries. 
+      !     The loops will be performed only on the processors 
+      !     that contain a given open boundary.
+      ! --------------------------------------------------------
+
+      IF( lp_obc_east ) THEN
+         ! ...   mpp initialization
+         nie0   = max( 1, min(jpieob   - nimpp+1, jpi     ) )
+         nie1   = max( 0, min(jpieob   - nimpp+1, jpi - 1 ) )
+         nie0p1 = max( 1, min(jpieob+1 - nimpp+1, jpi     ) )
+         nie1p1 = max( 0, min(jpieob+1 - nimpp+1, jpi - 1 ) )
+         nie0m1 = max( 1, min(jpieob-1 - nimpp+1, jpi     ) )
+         nie1m1 = max( 0, min(jpieob-1 - nimpp+1, jpi - 1 ) )
+         nje0   = max( 2, min(jpjed    - njmpp+1, jpj     ) )
+         nje1   = max( 0, min(jpjef    - njmpp+1, jpj - 1 ) )
+         nje0p1 = max( 1, min(jpjedp1  - njmpp+1, jpj     ) )
+         nje0m1 = max( 1, min(jpjed    - njmpp+1, jpj     ) )
+         nje1m1 = max( 0, min(jpjefm1  - njmpp+1, jpj - 1 ) )
+         nje1m2 = max( 0, min(jpjefm1-1- njmpp+1, jpj - 1 ) )
+         IF(lwp) THEN
+            IF( lfbceast ) THEN
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Specified East Open Boundary'
+            ELSE
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Radiative East Open Boundary'
+            END IF
+         END IF
+      END IF
+
+      IF( lp_obc_west ) THEN
+         ! ...   mpp initialization
+         niw0   = max( 1, min(jpiwob   - nimpp+1, jpi     ) )
+         niw1   = max( 0, min(jpiwob   - nimpp+1, jpi - 1 ) )
+         niw0p1 = max( 1, min(jpiwob+1 - nimpp+1, jpi     ) )
+         niw1p1 = max( 0, min(jpiwob+1 - nimpp+1, jpi - 1 ) )
+         njw0   = max( 2, min(jpjwd    - njmpp+1, jpj     ) )
+         njw1   = max( 0, min(jpjwf    - njmpp+1, jpj - 1 ) )
+         njw0p1 = max( 1, min(jpjwdp1  - njmpp+1, jpj     ) )
+         njw0m1 = max( 1, min(jpjwd    - njmpp+1, jpj     ) )
+         njw1m1 = max( 0, min(jpjwfm1  - njmpp+1, jpj - 1 ) )
+         njw1m2 = max( 0, min(jpjwfm1-1- njmpp+1, jpj - 1 ) )
+         IF(lwp) THEN
+            IF( lfbcwest ) THEN
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Specified West Open Boundary'
+            ELSE
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Radiative West Open Boundary'
+            END IF
+         END IF
+      END IF
+ 
+      IF( lp_obc_north ) THEN
+         ! ...   mpp initialization
+         nin0   = max( 2, min(jpind    - nimpp+1, jpi     ) )
+         nin1   = max( 0, min(jpinf    - nimpp+1, jpi - 1 ) )
+         nin0p1 = max( 1, min(jpindp1  - nimpp+1, jpi     ) )
+         nin0m1 = max( 1, min(jpind    - nimpp+1, jpi     ) )
+         nin1m1 = max( 0, min(jpinfm1  - nimpp+1, jpi - 1 ) )
+         nin1m2 = max( 0, min(jpinfm1-1- nimpp+1, jpi - 1 ) )
+         njn0   = max( 1, min(jpjnob   - njmpp+1, jpj     ) )
+         njn1   = max( 0, min(jpjnob   - njmpp+1, jpj - 1 ) )
+         njn0p1 = max( 1, min(jpjnob+1 - njmpp+1, jpj     ) )
+         njn1p1 = max( 0, min(jpjnob+1 - njmpp+1, jpj - 1 ) )
+         njn0m1 = max( 1, min(jpjnob-1 - njmpp+1, jpj     ) )
+         njn1m1 = max( 0, min(jpjnob-1 - njmpp+1, jpj - 1 ) )
+         IF(lwp) THEN
+            IF( lfbcnorth ) THEN
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Specified North Open Boundary'
+            ELSE
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Radiative North Open Boundary'
+            END IF
+         END IF
+      END IF
+
+      IF( lp_obc_south ) THEN
+         ! ...   mpp initialization
+         nis0   = max( 2, min(jpisd    - nimpp+1, jpi     ) )
+         nis1   = max( 0, min(jpisf    - nimpp+1, jpi - 1 ) )
+         nis0p1 = max( 1, min(jpisdp1  - nimpp+1, jpi     ) )
+         nis0m1 = max( 1, min(jpisd    - nimpp+1, jpi     ) )
+         nis1m1 = max( 0, min(jpisfm1  - nimpp+1, jpi - 1 ) )
+         nis1m2 = max( 0, min(jpisfm1-1- nimpp+1, jpi - 1 ) )
+         njs0   = max( 1, min(jpjsob   - njmpp+1, jpj     ) )
+         njs1   = max( 0, min(jpjsob   - njmpp+1, jpj - 1 ) )
+         njs0p1 = max( 1, min(jpjsob+1 - njmpp+1, jpj     ) )
+         njs1p1 = max( 0, min(jpjsob+1 - njmpp+1, jpj - 1 ) )
+         IF(lwp) THEN
+            IF( lfbcsouth ) THEN
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Specified South Open Boundary'
+            ELSE
+               WRITE(numout,*)'     '
+               WRITE(numout,*)'         Radiative South Open Boundary'
+            END IF
+         END IF
+      END IF
+
+      ! 3. mask correction for OBCs
+      ! ---------------------------
+
+      IF( lp_obc_east ) THEN
+         !... (jpjed,jpjefm1),jpieob
+         DO jj = nje0, nje1m1
+# if defined key_dynspg_rl
+            DO ji = nie0, nie1
+# else
+            DO ji = nie0p1, nie1p1
+# endif
+               bmask(ji,jj) = 0.e0
+            END DO
+         END DO
+
+         ! ... initilization to zero
+         uemsk(:,:) = 0.e0
+         vemsk(:,:) = 0.e0
+         temsk(:,:) = 0.e0
+
+         ! ... set 2D mask on East OBC,  Vopt
+         DO ji = fs_nie0, fs_nie1
+            DO jj = nje0, nje1
+               uemsk(jj,:) = umask(ji,  jj,:)
+               vemsk(jj,:) = vmask(ji+1,jj,:)
+               temsk(jj,:) = tmask(ji+1,jj,:)
+            END DO
+         END DO
+
+      END IF
+
+      IF( lp_obc_west ) THEN
+         ! ... (jpjwd,jpjwfm1),jpiwob
+         DO jj = njw0, njw1m1
+            DO ji = niw0, niw1
+               bmask(ji,jj) = 0.e0
+            END DO
+         END DO
+
+         ! ... initilization to zero
+         uwmsk(:,:) = 0.e0
+         vwmsk(:,:) = 0.e0
+         twmsk(:,:) = 0.e0
+
+         ! ... set 2D mask on West OBC,  Vopt
+         DO ji = fs_niw0, fs_niw1
+            DO jj = njw0, njw1
+               uwmsk(jj,:) = umask(ji,jj,:)
+               vwmsk(jj,:) = vmask(ji,jj,:)
+               twmsk(jj,:) = tmask(ji,jj,:)
+            END DO
+         END DO
+
+      END IF
+
+      IF( lp_obc_north ) THEN
+         ! ... jpjnob,(jpind,jpisfm1)
+# if defined key_dynspg_rl
+         DO jj = njn0, njn1
+# else
+         DO jj = njn0p1, njn1p1
+# endif
+            DO ji = nin0, nin1m1
+               bmask(ji,jj) = 0.e0
+            END DO
+         END DO
+
+         ! ... initilization to zero
+         unmsk(:,:) = 0.e0
+         vnmsk(:,:) = 0.e0
+         tnmsk(:,:) = 0.e0
+
+         ! ... set 2D mask on North OBC,  Vopt
+         DO jj = fs_njn0, fs_njn1
+            DO ji = nin0, nin1
+               unmsk(ji,:) = umask(ji,jj+1,:)
+               vnmsk(ji,:) = vmask(ji,jj  ,:)
+               tnmsk(ji,:) = tmask(ji,jj+1,:)
+            END DO
+         END DO
+
+      END IF
+
+      IF( lp_obc_south ) THEN 
+         ! ... jpjsob,(jpisd,jpisfm1)
+         DO jj = njs0, njs1
+            DO ji = nis0, nis1m1
+               bmask(ji,jj) = 0.e0
+            END DO
+         END DO
+
+         ! ... initilization to zero
+         usmsk(:,:) = 0.e0
+         vsmsk(:,:) = 0.e0
+         tsmsk(:,:) = 0.e0
+
+         ! ... set 2D mask on South OBC,  Vopt
+         DO jj = njs0, njs1
+            DO ji = nis0, nis1
+               usmsk(ji,:) = umask(ji,jj,:)
+               vsmsk(ji,:) = vmask(ji,jj,:)
+               tsmsk(ji,:) = tmask(ji,jj,:)
+            END DO
+         END DO
+
+      END IF
+
+# if defined key_dynspg_flt
+
+      ! ... Initialize obcumask and obcvmask for the Force filtering 
+      !     boundary condition in dynspg_flt
+      obcumask(:,:) = umask(:,:,1)
+      obcvmask(:,:) = vmask(:,:,1)
+
+      ! ... Initialize obctmsk on overlap region and obcs. This mask
+      !     is used in obcvol.F90 to calculate cumulate flux E-P. 
+      !     - no flux E-P on obcs and overlap region (jpereci = jprecj = 1)
+      obctmsk(:,:) = tmask(:,:,1)     
+      obctmsk(1  ,:) = 0.e0           
+      obctmsk(jpi,:) = 0.e0           
+      obctmsk(:  ,1) = 0.e0           
+      obctmsk(:,jpj) = 0.e0           
+
+      IF( lp_obc_east ) THEN
+         ! ... East obc Force filtering mask for the grad D
+         DO ji = nie0, nie1
+            DO jj = nje0p1, nje1m1
+               obcumask(ji  ,jj)=0.e0
+               obcvmask(ji+1,jj)=0.e0
+            END DO
+         END DO
+
+         ! ... set to 0 on East OBC
+         DO jj = nje0p1, nje1m1
+            DO ji = nie0p1, nie1p1
+               obctmsk(ji,jj) = 0.e0
+            END DO
+         END DO
+      END IF
+
+      IF( lp_obc_west ) THEN
+         ! ... West obc Force filtering mask for the grad D
+         DO ji = niw0, niw1
+            DO jj = njw0p1, njw1m1
+               obcumask(ji,jj)=0.e0
+               obcvmask(ji,jj)=0.e0
+            END DO
+         END DO
+
+         ! ... set to 0 on West OBC
+         DO jj = njw0p1, njw1m1
+            DO ji = niw0, niw1
+               obctmsk(ji,jj) = 0.e0
+            END DO
+         END DO
+      END IF
+
+      IF( lp_obc_north ) THEN
+         ! ... North obc Force filtering mask for the grad D
+         DO jj = njn0, njn1
+            DO ji = nin0p1, nin1m1
+               obcvmask(ji,jj  )=0.e0
+               obcumask(ji,jj+1)=0.e0
+            END DO
+         END DO
+
+         ! ... set to 0 on North OBC
+         DO jj = njn0p1, njn1p1
+            DO ji = nin0p1, nin1m1
+               obctmsk(ji,jj) = 0.e0
+            END DO
+         END DO
+      END IF
+
+      IF( lp_obc_south ) THEN
+         ! ... South obc Force filtering mask for the grad D
+         DO jj = njs0, njs1 
+            DO ji = nis0p1, nis1m1
+               obcumask(ji,jj)=0.e0
+               obcvmask(ji,jj)=0.e0
+            END DO
+         END DO
+
+         ! ... set to 0 on South OBC
+         DO jj = njs0, njs1
+            DO ji = nis0p1, nis1m1
+               obctmsk(ji,jj) = 0.e0
+            END DO
+         END DO
+      END IF
+
+# endif
+
+# if ! defined key_dynspg_rl
+
+      IF ( ln_vol_cst ) THEN
+
+         ! 3.1 Total lateral surface for each open boundary
+         ! ------------------------------------------------
+
+         ! ... West open boundary surface
+         IF( lp_obc_west ) THEN
+            DO ji = niw0, niw1
+               DO jj = 1, jpj 
+                  obcsurftot = obcsurftot+hu(ji,jj)*e2u(ji,jj)*uwmsk(jj,1)
+               END DO
+            END DO
+         END IF
+
+         ! ... East open boundary surface
+         IF( lp_obc_east ) THEN
+            DO ji = nie0, nie1
+               DO jj = 1, jpj 
+                  obcsurftot = obcsurftot+hu(ji,jj)*e2u(ji,jj)*uemsk(jj,1)
+               END DO
+            END DO
+         END IF
+
+         ! ... North open boundary vertical surface
+         IF( lp_obc_north ) THEN
+            DO jj = njn0, njn1
+               DO ji = 1, jpi
+                  obcsurftot = obcsurftot+hv(ji,jj)*e1v(ji,jj)*vnmsk(ji,1)
+               END DO
+            END DO
+         END IF
+
+         ! ... South open boundary vertical surface
+         IF( lp_obc_south ) THEN
+            DO jj = njs0, njs1
+               DO ji = 1, jpi
+                  obcsurftot = obcsurftot+hv(ji,jj)*e1v(ji,jj)*vsmsk(ji,1)
+               END DO
+            END DO
+         END IF
+         IF( lk_mpp )   CALL mpp_sum( obcsurftot )   ! sum over the global domain
+      ENDIF
+# endif
+
+      ! 5. Control print on mask 
+      !    The extremities of the open boundaries must be in land
+      !    or else correspond to an "ocean corner" between two open boundaries. 
+      !    corner 1 is southwest, 2 is south east, 3 is northeast, 4 is northwest. 
+      ! --------------------------------------------------------------------------
+
+      icorner(:)=0
+
+      ! ... control of the west boundary
+      IF( lp_obc_west ) THEN
+         IF( jpiwob < 2 .OR.  jpiwob >= jpiglo-2 ) THEN
+            WRITE(ctmp1,*) ' jpiwob exceed ', jpiglo-2, 'or less than 2'
+            CALL ctl_stop( ctmp1 )
+         END IF
+         ztestmask(:)=0.
+         DO ji=niw0,niw1
+            IF( (njw0 + njmpp - 1) == jpjwd ) ztestmask(1)=ztestmask(1)+ tmask(ji,njw0,1)
+            IF( (njw1 + njmpp - 1) == jpjwf ) ztestmask(2)=ztestmask(2)+ tmask(ji,njw1,1)
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
+
+         IF( ztestmask(1) /= 0. ) icorner(1)=icorner(1)+1
+         IF( ztestmask(2) /= 0. ) icorner(4)=icorner(4)+1
+      END IF
+
+      ! ... control of the east boundary
+      IF( lp_obc_east ) THEN
+         IF( jpieob < 4 .OR.  jpieob >= jpiglo ) THEN
+            WRITE(ctmp1,*) ' jpieob exceed ', jpiglo, ' or less than 4'
+            CALL ctl_stop( ctmp1 )
+         END IF
+         ztestmask(:)=0.
+         DO ji=nie0p1,nie1p1
+            IF( (nje0 + njmpp - 1) == jpjed ) ztestmask(1)=ztestmask(1)+ tmask(ji,nje0,1)
+            IF( (nje1 + njmpp - 1) == jpjef ) ztestmask(2)=ztestmask(2)+ tmask(ji,nje1,1)
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
+
+        IF( ztestmask(1) /= 0. ) icorner(2)=icorner(2)+1
+        IF( ztestmask(2) /= 0. ) icorner(3)=icorner(3)+1
+      END IF
+
+      ! ... control of the north boundary
+      IF( lp_obc_north ) THEN
+         IF( jpjnob < 4 .OR.  jpjnob >= jpjglo ) THEN
+            WRITE(ctmp1,*) 'jpjnob exceed ', jpjglo, ' or less than 4'
+            CALL ctl_stop( ctmp1 )
+         END IF
+         ztestmask(:)=0.
+         DO jj=njn0p1,njn1p1
+            IF( (nin0 + nimpp - 1) == jpind ) ztestmask(1)=ztestmask(1)+ tmask(nin0,jj,1)
+            IF( (nin1 + nimpp - 1) == jpinf ) ztestmask(2)=ztestmask(2)+ tmask(nin1,jj,1)
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
+
+         IF( ztestmask(1) /= 0. ) icorner(4)=icorner(4)+1
+         IF( ztestmask(2) /= 0. ) icorner(3)=icorner(3)+1
+      END IF
+
+      ! ... control of the south boundary
+      IF( lp_obc_south ) THEN
+         IF( jpjsob < 2 .OR.  jpjsob >= jpjglo-2 ) THEN
+            WRITE(ctmp1,*) ' jpjsob exceed ', jpjglo-2, ' or less than 2'
+            CALL ctl_stop( ctmp1 )
+         END IF
+         ztestmask(:)=0.
+         DO jj=njs0,njs1
+            IF( (nis0 + nimpp - 1) == jpisd ) ztestmask(1)=ztestmask(1)+ tmask(nis0,jj,1)
+            IF( (nis1 + nimpp - 1) == jpisf ) ztestmask(2)=ztestmask(2)+ tmask(nis1,jj,1)
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztestmask, 2 )   ! sum over the global domain
+
+         IF( ztestmask(1) /= 0. ) icorner(1)=icorner(1)+1
+         IF( ztestmask(2) /= 0. ) icorner(2)=icorner(2)+1
+      END IF
+
+      IF( icorner(1) == 2 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' South West ocean corner, two open boudaries'
+         IF(lwp) WRITE(numout,*) ' ========== '
+         IF(lwp) WRITE(numout,*)
+         IF( jpisd /= jpiwob.OR.jpjsob /= jpjwd ) &
+              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
+
+      ELSE IF( icorner(1) == 1 ) THEN
+         CALL ctl_stop( ' Open boundaries do not fit at SW corner, we stop' )
+      END IF 
+
+      IF( icorner(2) == 2 ) THEN
+          IF(lwp) WRITE(numout,*)
+          IF(lwp) WRITE(numout,*) ' South East ocean corner, two open boudaries'
+          IF(lwp) WRITE(numout,*) ' ========== '
+          IF(lwp) WRITE(numout,*)
+          IF( jpisf /= jpieob+1.OR.jpjsob /= jpjed ) &
+               &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
+      ELSE IF( icorner(2) == 1 ) THEN
+         CALL ctl_stop( ' Open boundaries do not fit at SE corner, we stop' )
+      END IF 
+
+      IF( icorner(3) == 2 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' North East ocean corner, two open boudaries'
+         IF(lwp) WRITE(numout,*) ' ========== '
+         IF(lwp) WRITE(numout,*)
+         IF( jpinf /= jpieob+1 .OR. jpjnob+1 /= jpjef ) &
+              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
+       ELSE IF( icorner(3) == 1 ) THEN
+          CALL ctl_stop( ' Open boundaries do not fit at NE corner, we stop' )
+       END IF 
+
+      IF( icorner(4) == 2 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' North West ocean corner, two open boudaries'
+         IF(lwp) WRITE(numout,*) ' ========== '
+         IF(lwp) WRITE(numout,*)
+         IF( jpind /= jpiwob.OR.jpjnob+1 /= jpjwf ) &
+              &   CALL ctl_stop( ' Open boundaries do not fit, we stop' )
+       ELSE IF( icorner(4) == 1 ) THEN
+          CALL ctl_stop( ' Open boundaries do not fit at NW corner, we stop' )
+       END IF 
+
+      ! 6. Initialization of open boundary variables (u, v, bsf, t, s)
+      ! --------------------------------------------------------------
+      !   only if at least one boundary is  radiative 
+
+      ! ... Restart from restart.obc
+      IF ( inumfbc < nbobc .AND.  ln_rstart ) THEN
+         CALL obc_rst_lec
+      ELSE
+
+          ! ... Initialization to zero of radiation arrays.
+          !     Those have dimensions of local subdomains
+
+          bebnd(:,:,:)   = 0.e0   ;   bnbnd(:,:,:)   = 0.e0
+          uebnd(:,:,:,:) = 0.e0   ;   unbnd(:,:,:,:) = 0.e0
+          vebnd(:,:,:,:) = 0.e0   ;   vnbnd(:,:,:,:) = 0.e0
+          tebnd(:,:,:,:) = 0.e0   ;   tnbnd(:,:,:,:) = 0.e0 
+          sebnd(:,:,:,:) = 0.e0   ;   snbnd(:,:,:,:) = 0.e0
+
+          bwbnd(:,:,:)   = 0.e0   ;   bsbnd(:,:,:)   = 0.e0
+          uwbnd(:,:,:,:) = 0.e0   ;   usbnd(:,:,:,:) = 0.e0
+          vwbnd(:,:,:,:) = 0.e0   ;   vsbnd(:,:,:,:) = 0.e0
+          twbnd(:,:,:,:) = 0.e0   ;   tsbnd(:,:,:,:) = 0.e0 
+          swbnd(:,:,:,:) = 0.e0   ;   ssbnd(:,:,:,:) = 0.e0
+
+      END IF
+
+# if defined key_dynspg_rl
+      ! 7. Isolated coastline arrays initialization (rigid lid case only)
+      ! -----------------------------------------------------------------
+      CALL obc_dom
+# endif
+
+      ! 8. Control print
+      ! ... control of the east boundary
+      IF( lp_obc_east ) THEN
+         istop = 0
+         IF( jpieob < 4 .OR.  jpieob >= jpiglo ) THEN
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*) '            jpieob exceed ', jpim1, ' or less than 4'
+            istop = istop + 1
+         END IF
+
+         IF( lk_mpp ) THEN
+            ! ... 
+            IF( nimpp > jpieob-5) THEN
+               IF(lwp) WRITE(numout,cform_err)
+               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the East OBC'
+               IF(lwp) WRITE(numout,*) '        nimpp must be < jpieob-5'
+               istop = istop + 1
+            ENDIF
+         ELSE
+
+            ! ... stop if  e r r o r (s)   detected
+            IF( istop /= 0 ) THEN
+               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
+               CALL ctl_stop( ctmp1 )
+            ENDIF
+         ENDIF
+      ENDIF
+
+      ! ... control of the west boundary
+      IF( lp_obc_west ) THEN
+         istop = 0
+         IF( jpiwob < 2 .OR.  jpiwob >= jpiglo ) THEN
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*) '            jpiwob exceed ', jpim1, ' or less than 2'
+            istop = istop + 1
+         END IF
+
+         IF( lk_mpp ) THEN
+            IF( (nimpp < jpiwob+5) .AND. (nimpp > 1) ) THEN
+               IF(lwp) WRITE(numout,cform_err)
+               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the West OBC'
+               IF(lwp) WRITE(numout,*) '        nimpp must be > jpiwob-5 or =1'
+               istop = istop + 1
+            ENDIF
+         ELSE
+   
+            ! ... stop if  e r r o r (s)   detected
+            IF( istop /= 0 ) THEN
+               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
+               CALL ctl_stop( ctmp1 )
+            ENDIF
+         ENDIF
+      ENDIF
+
+      ! control of the north boundary
+      IF( lp_obc_north ) THEN
+         istop = 0
+         IF( jpjnob < 4 .OR.  jpjnob >= jpjglo ) THEN
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*) '          jpjnob exceed ', jpjm1,' or less than 4'
+            istop = istop + 1
+         END IF
+
+         IF( lk_mpp ) THEN
+            IF( njmpp > jpjnob-5) THEN
+               IF(lwp) WRITE(numout,cform_err)
+               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the North OBC'
+               IF(lwp) WRITE(numout,*) '        njmpp must be < jpjnob-5'
+               istop = istop + 1
+            ENDIF
+         ELSE
+   
+            ! ... stop if  e r r o r (s)   detected
+            IF( istop /= 0 ) THEN
+                WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
+               CALL ctl_stop( ctmp1 )
+           ENDIF
+         ENDIF
+      ENDIF
+
+      ! control of the south boundary
+      IF( lp_obc_south ) THEN
+         istop = 0
+         IF( jpjsob < 2 .OR. jpjsob >= jpjglo ) THEN
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*) '          jpjsob exceed ', jpjm1,' or less than 2'
+            istop = istop + 1
+         END IF
+
+         IF( lk_mpp ) THEN
+            IF( (njmpp < jpjsob+5) .AND. (njmpp > 1) ) THEN
+               IF(lwp) WRITE(numout,cform_err)
+               IF(lwp) WRITE(numout,*) '        A sub-domain is too close to the South OBC'
+               IF(lwp) WRITE(numout,*) '        njmpp must be > jpjsob+5 or =1'
+               istop = istop + 1
+            ENDIF
+         ELSE
+   
+            ! ... stop if  e r r o r (s)   detected
+            IF( istop /= 0 ) THEN
+               WRITE(ctmp1,*) istop,' obcini : E R R O R (S) detected : stop'
+               CALL ctl_stop( ctmp1 )
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE obc_init
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Dummy module                                                NO open boundaries
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_init      ! Dummy routine
+   END SUBROUTINE obc_init
+#endif
+
+   !!=================================================================================
+END MODULE obcini
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrad.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrad.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrad.F90	(revision 4536)
@@ -0,0 +1,1235 @@
+MODULE obcrad 
+   !!=================================================================================
+   !!                       ***  MODULE  obcrad  ***
+   !! Ocean dynamic :   Phase velocities for each open boundary
+   !!=================================================================================
+#if defined key_obc
+   !!---------------------------------------------------------------------------------
+   !!   obc_rad        : call the subroutine for each open boundary
+   !!   obc_rad_east   : compute the east phase velocities
+   !!   obc_rad_west   : compute the west phase velocities
+   !!   obc_rad_north  : compute the north phase velocities
+   !!   obc_rad_south  : compute the south phase velocities
+   !!---------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! for mppobc
+   USE in_out_manager  ! I/O units
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_rad        ! routine called by step.F90
+
+   !! * Module variables
+   INTEGER ::   ji, jj, jk     ! dummy loop indices
+
+   INTEGER ::      & ! ... boundary space indices 
+      nib   = 1,   & ! nib   = boundary point
+      nibm  = 2,   & ! nibm  = 1st interior point
+      nibm2 = 3,   & ! nibm2 = 2nd interior point
+                     ! ... boundary time indices 
+      nit   = 1,   & ! nit    = now
+      nitm  = 2,   & ! nitm   = before
+      nitm2 = 3      ! nitm2  = before-before
+
+   !! * Substitutions
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_rad ( kt )
+      !!------------------------------------------------------------------------------
+      !!                     SUBROUTINE obc_rad
+      !!                    ********************
+      !! ** Purpose :
+      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+      !!      boundaries and calculate those phase speeds if the open boundaries are 
+      !!      not fixed. In case of fixed open boundaries does nothing.
+      !!
+      !!     The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
+      !!     and/or lp_obc_south allow the user to determine which boundary is an
+      !!     open one (must be done in the param_obc.h90 file).
+      !! 
+      !! ** Reference : 
+      !!     Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !!
+      !!  History :
+      !!    8.5  !  02-10  (C. Talandier, A-M. Treguier) Free surface, F90 from the 
+      !!                                                 J. Molines and G. Madec version
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+      !!----------------------------------------------------------------------
+
+      IF( lp_obc_east  .AND. .NOT.lfbceast  )   CALL obc_rad_east ( kt )   ! East open boundary
+
+      IF( lp_obc_west  .AND. .NOT.lfbcwest  )   CALL obc_rad_west ( kt )   ! West open boundary
+
+      IF( lp_obc_north .AND. .NOT.lfbcnorth )   CALL obc_rad_north( kt )   ! North open boundary
+
+      IF( lp_obc_south .AND. .NOT.lfbcsouth )   CALL obc_rad_south( kt )   ! South open boundary
+
+   END SUBROUTINE obc_rad
+
+
+   SUBROUTINE obc_rad_east ( kt )
+      !!------------------------------------------------------------------------------
+      !!                     ***  SUBROUTINE obc_rad_east  ***
+      !!                   
+      !! ** Purpose :
+      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+      !!      east boundary and calculate those phase speeds if this OBC is not fixed.
+      !!      In case of fixed OBC, this subrountine is not called.
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER  ::   ij
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      REAL(wp) ::   zucb, zucbm, zucbm2
+      !!------------------------------------------------------------------------------
+
+      ! 1. Swap arrays before calculating radiative velocities
+      ! ------------------------------------------------------
+
+      ! 1.1  zonal velocity 
+      ! -------------------
+
+      IF( kt > nit000 ) THEN 
+
+         ! ... advance in time (time filter, array swap) 
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               uebnd(jj,jk,nib  ,nitm2) = uebnd(jj,jk,nib  ,nitm)*uemsk(jj,jk)
+               uebnd(jj,jk,nibm ,nitm2) = uebnd(jj,jk,nibm ,nitm)*uemsk(jj,jk)
+               uebnd(jj,jk,nibm2,nitm2) = uebnd(jj,jk,nibm2,nitm)*uemsk(jj,jk)
+            END DO
+         END DO
+         ! ... fields nitm <== nit  plus time filter at the boundary 
+         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  uebnd(jj,jk,nib  ,nitm) = uebnd(jj,jk,nib,  nit)*uemsk(jj,jk)
+                  uebnd(jj,jk,nibm ,nitm) = uebnd(jj,jk,nibm ,nit)*uemsk(jj,jk)
+                  uebnd(jj,jk,nibm2,nitm) = uebnd(jj,jk,nibm2,nit)*uemsk(jj,jk)
+         ! ... fields nit <== now (kt+1) 
+         ! ... Total or baroclinic velocity at b, bm and bm2
+# if defined key_dynspg_rl
+                  zucb   = uclie(jj,jk)
+# else
+                  zucb   = un(ji,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zucbm  = un(ji-1,jj,jk) + hur(ji-1,jj) / e2u(ji-1,jj) &
+                           * ( bsfn(ji-1,jj) - bsfn(ji-1,jj-1) )
+# else
+                  zucbm  = un(ji-1,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zucbm2 = un(ji-2,jj,jk) + hur(ji-2,jj) / e2u(ji-2,jj) &
+                           * ( bsfn(ji-2,jj) - bsfn(ji-2,jj-1) )
+# else
+                  zucbm2 = un(ji-2,jj,jk)
+# endif
+                  uebnd(jj,jk,nib  ,nit) = zucb   *uemsk(jj,jk)
+                  uebnd(jj,jk,nibm ,nit) = zucbm  *uemsk(jj,jk) 
+                  uebnd(jj,jk,nibm2,nit) = zucbm2 *uemsk(jj,jk) 
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(uebnd,jpjed,jpjef,jpieob,jpk*3*3,2,jpj)
+
+         ! ... extremeties nie0, nie1
+         ij = jpjed +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               uebnd(ij,jk,nibm,nitm) = uebnd(ij+1 ,jk,nibm,nitm)
+            END DO
+         END IF
+         ij = jpjef +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               uebnd(ij,jk,nibm,nitm) = uebnd(ij-1 ,jk,nibm,nitm)
+            END DO
+         END IF
+
+         ! 1.2 tangential velocity
+         ! -----------------------
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+         ! ... fields nitm2 <== nitm
+               vebnd(jj,jk,nib  ,nitm2) = vebnd(jj,jk,nib  ,nitm)*vemsk(jj,jk)
+               vebnd(jj,jk,nibm ,nitm2) = vebnd(jj,jk,nibm ,nitm)*vemsk(jj,jk)
+               vebnd(jj,jk,nibm2,nitm2) = vebnd(jj,jk,nibm2,nitm)*vemsk(jj,jk)
+            END DO
+         END DO
+
+         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  vebnd(jj,jk,nib  ,nitm) = vebnd(jj,jk,nib,  nit)*vemsk(jj,jk)
+                  vebnd(jj,jk,nibm ,nitm) = vebnd(jj,jk,nibm ,nit)*vemsk(jj,jk)
+                  vebnd(jj,jk,nibm2,nitm) = vebnd(jj,jk,nibm2,nit)*vemsk(jj,jk)
+         ! ... fields nit <== now (kt+1)
+                  vebnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vemsk(jj,jk)
+                  vebnd(jj,jk,nibm ,nit) = vn(ji-1,jj,jk)*vemsk(jj,jk)
+                  vebnd(jj,jk,nibm2,nit) = vn(ji-2,jj,jk)*vemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(vebnd,jpjed,jpjef,jpieob+1,jpk*3*3,2,jpj)
+
+         !... extremeties nie0, nie1
+         ij = jpjed +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               vebnd(ij,jk,nibm,nitm) = vebnd(ij+1 ,jk,nibm,nitm)
+            END DO 
+         END IF 
+         ij = jpjef +1 - njmpp 
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+            DO jk = 1,jpkm1 
+               vebnd(ij,jk,nibm,nitm) = vebnd(ij-1 ,jk,nibm,nitm)
+            END DO 
+         END IF 
+
+         ! 1.3 Temperature and salinity
+         ! ----------------------------
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+         ! ... fields nitm <== nit  plus time filter at the boundary
+               tebnd(jj,jk,nib,nitm) = tebnd(jj,jk,nib,nit)*temsk(jj,jk)
+               sebnd(jj,jk,nib,nitm) = sebnd(jj,jk,nib,nit)*temsk(jj,jk)
+            END DO
+         END DO
+
+         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  tebnd(jj,jk,nibm,nitm) = tebnd(jj,jk,nibm,nit)*temsk(jj,jk)
+                  sebnd(jj,jk,nibm,nitm) = sebnd(jj,jk,nibm,nit)*temsk(jj,jk)
+         ! ... fields nit <== now (kt+1)
+                  tebnd(jj,jk,nib  ,nit) = tn(ji  ,jj,jk)*temsk(jj,jk)
+                  tebnd(jj,jk,nibm ,nit) = tn(ji-1,jj,jk)*temsk(jj,jk)
+                  sebnd(jj,jk,nib  ,nit) = sn(ji  ,jj,jk)*temsk(jj,jk)
+                  sebnd(jj,jk,nibm ,nit) = sn(ji-1,jj,jk)*temsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(tebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj)
+         IF( lk_mpp )   CALL mppobc(sebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj)
+
+         ! ... extremeties nie0, nie1
+         ij = jpjed +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               tebnd(ij,jk,nibm,nitm) = tebnd(ij+1 ,jk,nibm,nitm)
+               sebnd(ij,jk,nibm,nitm) = sebnd(ij+1 ,jk,nibm,nitm)
+            END DO
+         END IF
+         ij = jpjef +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               tebnd(ij,jk,nibm,nitm) = tebnd(ij-1 ,jk,nibm,nitm)
+               sebnd(ij,jk,nibm,nitm) = sebnd(ij-1 ,jk,nibm,nitm)
+            END DO
+         END IF
+
+      END IF     ! End of array swap
+
+      ! 2 - Calculation of radiation velocities
+      ! ---------------------------------------
+
+      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+
+         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxebnd
+         ! ---------------------------------------------------------------------
+         !
+         !          nibm2      nibm      nib
+         !            |  nibm   |   nib   |///
+         !            |    |    |    |    |///
+         !  jj-line --f----v----f----v----f---
+         !            |    |    |    |    |///
+         !            |         |         |///
+         !  jj-line   u    T    u    T    u///
+         !            |         |         |///
+         !            |    |    |    |    |///
+         !          jpieob-2   jpieob-1   jpieob
+         !                 |         |        
+         !              jpieob-1    jpieob      
+         !
+         ! ... (jpjedp1, jpjefm1),jpieob
+         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... 2* gradi(u) (T-point i=nibm, time mean)
+                  z2dx = ( uebnd(jj,jk,nibm ,nit) + uebnd(jj,jk,nibm ,nitm2) &
+                           - 2.*uebnd(jj,jk,nibm2,nitm) ) / e1t(ji-1,jj)
+         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
+                  z2dy = ( uebnd(jj+1,jk,nibm,nitm) - uebnd(jj-1,jk,nibm,nitm) ) / e2u(ji-1,jj)
+         ! ... square of the norm of grad(u)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = uebnd(jj,jk,nibm,nitm2) - uebnd(jj,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by 1)               
+                  IF( z4nor2 == 0. ) THEN
+                     z4nor2=.00001
+                  END IF
+                  z05cx = zdt * z2dx / z4nor2
+                  u_cxebnd(jj,jk) = z05cx*uemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxebnd
+         ! -----------------------------------------------------------------------
+         !
+         !          nibm2      nibm      nib
+         !            |   nibm  |   nib///|///
+         !            |    |    |    |////|///
+         !  jj-line --v----f----v----f----v---
+         !            |    |    |    |////|///
+         !            |    |    |    |////|///
+         !            | jpieob-1| jpieob /|///
+         !            |         |         |   
+         !         jpieob-1    jpieob     jpieob+1
+         !
+         ! ... (jpjedp1, jpjefm1), jpieob+1
+         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
+                  z2dx = ( vebnd(jj,jk,nibm ,nit) + vebnd(jj,jk,nibm ,nitm2) &
+                          - 2.*vebnd(jj,jk,nibm2,nitm) ) / e1f(ji-2,jj)
+         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
+                  z2dy = ( vebnd(jj+1,jk,nibm,nitm) -  vebnd(jj-1,jk,nibm,nitm) ) / e2v(ji-1,jj)
+         ! ... square of the norm of grad(v)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = vebnd(jj,jk,nibm,nitm2) - vebnd(jj,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
+         !     velocity ratio no divided by e1f for the tracer radiation
+                  IF( z4nor2 == 0. ) THEN
+                     z4nor2=.000001
+                  END IF
+                  z05cx = zdt * z2dx / z4nor2
+                  v_cxebnd(jj,jk) = z05cx*vemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(v_cxebnd,jpjed,jpjef,jpieob+1,jpk,2,jpj)
+
+         ! ... extremeties nie0, nie1
+         ij = jpjed +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               v_cxebnd(ij,jk) = v_cxebnd(ij+1 ,jk)
+            END DO
+         END IF
+         ij = jpjef +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               v_cxebnd(ij,jk) = v_cxebnd(ij-1 ,jk)
+            END DO
+         END IF
+
+      END IF
+
+   END SUBROUTINE obc_rad_east
+
+
+   SUBROUTINE obc_rad_west ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_rad_west  ***
+      !!                    
+      !! ** Purpose :
+      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+      !!      west boundary and calculate those phase speeds if this OBC is not fixed.
+      !!      In case of fixed OBC, this subrountine is not called.
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER ::   ij
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      REAL(wp) ::   zucb, zucbm, zucbm2
+      !!------------------------------------------------------------------------------
+
+      ! 1. Swap arrays before calculating radiative velocities
+      ! ------------------------------------------------------
+
+      ! 1.1  zonal velocity 
+      ! -------------------
+
+      IF( kt > nit000 ) THEN
+
+         ! ... advance in time (time filter, array swap) 
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj 
+               uwbnd(jj,jk,nib  ,nitm2) = uwbnd(jj,jk,nib  ,nitm)*uwmsk(jj,jk)
+               uwbnd(jj,jk,nibm ,nitm2) = uwbnd(jj,jk,nibm ,nitm)*uwmsk(jj,jk)
+               uwbnd(jj,jk,nibm2,nitm2) = uwbnd(jj,jk,nibm2,nitm)*uwmsk(jj,jk)
+            END DO
+         END DO
+
+         ! ... fields nitm <== nit  plus time filter at the boundary 
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  uwbnd(jj,jk,nib  ,nitm) = uwbnd(jj,jk,nib  ,nit)*uwmsk(jj,jk)
+                  uwbnd(jj,jk,nibm ,nitm) = uwbnd(jj,jk,nibm ,nit)*uwmsk(jj,jk)
+                  uwbnd(jj,jk,nibm2,nitm) = uwbnd(jj,jk,nibm2,nit)*uwmsk(jj,jk)
+         ! ... total or baroclinic velocity at b, bm and bm2
+# if defined key_dynspg_rl
+                  zucb   = ucliw(jj,jk) 
+# else
+                  zucb   = un (ji,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zucbm  = un (ji+1,jj,jk) + hur (ji+1,jj) / e2u (ji+1,jj) &
+                           * ( bsfn(ji+1,jj) - bsfn(ji+1,jj-1) )
+# else
+                  zucbm  = un (ji+1,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zucbm2 = un (ji+2,jj,jk) + hur (ji+2,jj) / e2u (ji+2,jj) &
+                           * ( bsfn(ji+2,jj) - bsfn(ji+2,jj-1) )
+# else
+                  zucbm2 = un (ji+2,jj,jk)
+# endif
+
+         ! ... fields nit <== now (kt+1) 
+                  uwbnd(jj,jk,nib  ,nit) = zucb  *uwmsk(jj,jk)
+                  uwbnd(jj,jk,nibm ,nit) = zucbm *uwmsk(jj,jk)
+                  uwbnd(jj,jk,nibm2,nit) = zucbm2*uwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(uwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj)
+
+         ! ... extremeties niw0, niw1
+         ij = jpjwd +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij+1 ,jk,nibm,nitm)
+            END DO
+         END IF
+         ij = jpjwf +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               uwbnd(ij,jk,nibm,nitm) = uwbnd(ij-1 ,jk,nibm,nitm)
+            END DO
+         END IF
+
+         ! 1.2 tangential velocity
+         ! -----------------------
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj 
+         ! ... fields nitm2 <== nitm
+                  vwbnd(jj,jk,nib  ,nitm2) = vwbnd(jj,jk,nib  ,nitm)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm ,nitm2) = vwbnd(jj,jk,nibm ,nitm)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm2,nitm2) = vwbnd(jj,jk,nibm2,nitm)*vwmsk(jj,jk)
+            END DO
+         END DO
+
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  vwbnd(jj,jk,nib  ,nitm) = vwbnd(jj,jk,nib,  nit)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm ,nitm) = vwbnd(jj,jk,nibm ,nit)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm2,nitm) = vwbnd(jj,jk,nibm2,nit)*vwmsk(jj,jk)
+         ! ... fields nit <== now (kt+1)
+                  vwbnd(jj,jk,nib  ,nit) = vn(ji  ,jj,jk)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm ,nit) = vn(ji+1,jj,jk)*vwmsk(jj,jk)
+                  vwbnd(jj,jk,nibm2,nit) = vn(ji+2,jj,jk)*vwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(vwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj)
+
+         ! ... extremeties niw0, niw1 
+         ij = jpjwd +1 - njmpp 
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+            DO jk = 1,jpkm1 
+               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij+1 ,jk,nibm,nitm)
+            END DO 
+         END IF
+         ij = jpjwf +1 - njmpp 
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN 
+            DO jk = 1,jpkm1 
+               vwbnd(ij,jk,nibm,nitm) = vwbnd(ij-1 ,jk,nibm,nitm)
+            END DO 
+         END IF 
+ 
+         ! 1.3 Temperature and salinity
+         ! ----------------------------
+ 
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+         ! ... fields nitm <== nit  plus time filter at the boundary
+               twbnd(jj,jk,nib,nitm) = twbnd(jj,jk,nib,nit)*twmsk(jj,jk)
+               swbnd(jj,jk,nib,nitm) = swbnd(jj,jk,nib,nit)*twmsk(jj,jk)
+            END DO
+         END DO
+ 
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  twbnd(jj,jk,nibm ,nitm) = twbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
+                  swbnd(jj,jk,nibm ,nitm) = swbnd(jj,jk,nibm ,nit)*twmsk(jj,jk)
+         ! ... fields nit <== now (kt+1)
+                  twbnd(jj,jk,nib  ,nit) = tn(ji   ,jj,jk)*twmsk(jj,jk)
+                  twbnd(jj,jk,nibm ,nit) = tn(ji+1 ,jj,jk)*twmsk(jj,jk)
+                  swbnd(jj,jk,nib  ,nit) = sn(ji   ,jj,jk)*twmsk(jj,jk)
+                  swbnd(jj,jk,nibm ,nit) = sn(ji+1 ,jj,jk)*twmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(twbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj)
+         IF( lk_mpp )   CALL mppobc(swbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj)
+
+         ! ... extremeties niw0, niw1
+         ij = jpjwd +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               twbnd(ij,jk,nibm,nitm) = twbnd(ij+1 ,jk,nibm,nitm)
+               swbnd(ij,jk,nibm,nitm) = swbnd(ij+1 ,jk,nibm,nitm)
+            END DO
+         END IF
+         ij = jpjwf +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               twbnd(ij,jk,nibm,nitm) = twbnd(ij-1 ,jk,nibm,nitm)
+               swbnd(ij,jk,nibm,nitm) = swbnd(ij-1 ,jk,nibm,nitm)
+            END DO
+         END IF
+ 
+      END IF     ! End of array swap
+
+      ! 2 - Calculation of radiation velocities
+      ! ---------------------------------------
+   
+      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+  
+         ! 2.1  Calculate the normal velocity U based on phase velocity u_cxwbnd
+         ! ----------------------------------------------------------------------
+         !
+         !          nib       nibm      nibm2
+         !        ///|   nib   |   nibm  |
+         !        ///|    |    |    |    |
+         !        ---f----v----f----v----f-- jj-line
+         !        ///|    |    |    |    |
+         !        ///|         |         |
+         !        ///u    T    u    T    u   jj-line
+         !        ///|         |         |
+         !        ///|    |    |    |    |
+         !         jpiwob    jpiwob+1    jpiwob+2
+         !                |         |        
+         !              jpiwob+1    jpiwob+2     
+         !
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... (jpjwdp1, jpjwfm1), jpiwob
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... 2* gradi(u) (T-point i=nibm, time mean)
+                  z2dx = ( - uwbnd(jj,jk,nibm ,nit) -  uwbnd(jj,jk,nibm ,nitm2) &
+                           + 2.*uwbnd(jj,jk,nibm2,nitm) ) / e1t(ji+2,jj)
+         ! ... 2* gradj(u) (u-point i=nibm, time nitm)
+                  z2dy = ( uwbnd(jj+1,jk,nibm,nitm) - uwbnd(jj-1,jk,nibm,nitm) ) / e2u(ji+1,jj)
+         ! ... square of the norm of grad(u)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = uwbnd(jj,jk,nibm,nitm2) - uwbnd(jj,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by -1)
+                  IF( z4nor2 == 0. ) THEN
+                     z4nor2=0.00001
+                  END IF
+                  z05cx = zdt * z2dx / z4nor2
+                  u_cxwbnd(jj,jk)=z05cx*uwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! 2.2  Calculate the tangential velocity based on phase velocity v_cxwbnd
+         ! -----------------------------------------------------------------------
+         !
+         !      nib       nibm     nibm2
+         !    ///|///nib   |   nibm  |  nibm2
+         !    ///|////|    |    |    |    |    |
+         !    ---v----f----v----f----v----f----v-- jj-line
+         !    ///|////|    |    |    |    |    |
+         !    ///|////|    |    |    |    |    |
+         !   jpiwob     jpiwob+1    jpiwob+2
+         !            |         |         |   
+         !          jpiwob   jpiwob+1   jpiwob+2    
+         !
+         ! ... radiative condition plus Raymond-Kuo
+         ! ... (jpjwdp1, jpjwfm1),jpiwob
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... 2* i-gradient of v (f-point i=nibm, time mean)
+                  z2dx = ( - vwbnd(jj,jk,nibm ,nit) - vwbnd(jj,jk,nibm ,nitm2) &
+                           + 2.*vwbnd(jj,jk,nibm2,nitm) ) / e1f(ji+1,jj)
+         ! ... 2* j-gradient of v (v-point i=nibm, time nitm)
+                  z2dy = ( vwbnd(jj+1,jk,nibm,nitm) - vwbnd(jj-1,jk,nibm,nitm) ) / e2v(ji+1,jj)
+         ! ... square of the norm of grad(v)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = vwbnd(jj,jk,nibm,nitm2) - vwbnd(jj,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
+         !     velocity ratio no divided by e1f for the tracer radiation
+                  IF( z4nor2 == 0) THEN
+                     z4nor2=0.000001
+                  endif
+                  z05cx = zdt * z2dx / z4nor2
+                  v_cxwbnd(jj,jk) = z05cx*vwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(v_cxwbnd,jpjwd,jpjwf,jpiwob,jpk,2,jpj)
+
+         ! ... extremeties niw0, niw1
+         ij = jpjwd +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               v_cxwbnd(ij,jk) = v_cxwbnd(ij+1 ,jk)
+            END DO
+         END IF
+         ij = jpjwf +1 - njmpp
+         IF( ij >= 2 .AND. ij < jpjm1 ) THEN
+            DO jk = 1,jpkm1
+               v_cxwbnd(ij,jk) = v_cxwbnd(ij-1 ,jk)
+            END DO
+         END IF
+
+      END IF
+
+   END SUBROUTINE obc_rad_west
+
+
+   SUBROUTINE obc_rad_north ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_rad_north  ***
+      !!           
+      !! ** Purpose :
+      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+      !!      north boundary and calculate those phase speeds if this OBC is not fixed.
+      !!      In case of fixed OBC, this subrountine is not called.
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER  ::   ii
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      REAL(wp) ::   zvcb, zvcbm, zvcbm2
+      !!------------------------------------------------------------------------------
+
+      ! 1. Swap arrays before calculating radiative velocities
+      ! ------------------------------------------------------
+
+      ! 1.1  zonal velocity 
+      ! -------------------
+
+      IF( kt > nit000 ) THEN 
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm2 <== nitm
+               unbnd(ji,jk,nib  ,nitm2) = unbnd(ji,jk,nib  ,nitm)*unmsk(ji,jk)
+               unbnd(ji,jk,nibm ,nitm2) = unbnd(ji,jk,nibm ,nitm)*unmsk(ji,jk)
+               unbnd(ji,jk,nibm2,nitm2) = unbnd(ji,jk,nibm2,nitm)*unmsk(ji,jk)
+            END DO
+         END DO
+
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  unbnd(ji,jk,nib  ,nitm) = unbnd(ji,jk,nib,  nit)*unmsk(ji,jk)
+                  unbnd(ji,jk,nibm ,nitm) = unbnd(ji,jk,nibm ,nit)*unmsk(ji,jk)
+                  unbnd(ji,jk,nibm2,nitm) = unbnd(ji,jk,nibm2,nit)*unmsk(ji,jk)
+         ! ... fields nit <== now (kt+1)
+                  unbnd(ji,jk,nib  ,nit) = un(ji,jj,  jk)*unmsk(ji,jk)
+                  unbnd(ji,jk,nibm ,nit) = un(ji,jj-1,jk)*unmsk(ji,jk)
+                  unbnd(ji,jk,nibm2,nit) = un(ji,jj-2,jk)*unmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(unbnd,jpind,jpinf,jpjnob+1,jpk*3*3,1,jpi)
+
+         ! ... extremeties njn0,njn1 
+         ii = jpind + 1 - nimpp 
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN 
+            DO jk = 1, jpkm1
+                unbnd(ii,jk,nibm,nitm) = unbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF 
+         ii = jpinf + 1 - nimpp 
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               unbnd(ii,jk,nibm,nitm) = unbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+ 
+         ! 1.2. normal velocity 
+         ! --------------------
+
+         ! ... advance in time (time filter, array swap) 
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm2 <== nitm 
+               vnbnd(ji,jk,nib  ,nitm2) = vnbnd(ji,jk,nib  ,nitm)*vnmsk(ji,jk)
+               vnbnd(ji,jk,nibm ,nitm2) = vnbnd(ji,jk,nibm ,nitm)*vnmsk(ji,jk)
+               vnbnd(ji,jk,nibm2,nitm2) = vnbnd(ji,jk,nibm2,nitm)*vnmsk(ji,jk)
+            END DO
+         END DO
+
+         DO jj = fs_njn0, fs_njn1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  vnbnd(ji,jk,nib  ,nitm) = vnbnd(ji,jk,nib,  nit)*vnmsk(ji,jk)
+                  vnbnd(ji,jk,nibm ,nitm) = vnbnd(ji,jk,nibm ,nit)*vnmsk(ji,jk)
+                  vnbnd(ji,jk,nibm2,nitm) = vnbnd(ji,jk,nibm2,nit)*vnmsk(ji,jk)
+         ! ... fields nit <== now (kt+1)
+         ! ... total or baroclinic velocity at b, bm and bm2
+# if defined key_dynspg_rl
+                  zvcb   = vclin(ji,jk)
+# else
+                  zvcb   = vn (ji,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zvcbm  = vn (ji,jj-1,jk) - hvr (ji,jj-1) / e1v (ji,jj-1) &
+                           * ( bsfn(ji,jj-1) - bsfn(ji-1,jj-1) )
+# else
+                  zvcbm  = vn (ji,jj-1,jk)
+# endif
+# if defined key_dynspg_rl
+                  zvcbm2 = vn (ji,jj-2,jk) - hvr (ji,jj-2) / e1v (ji,jj-2) &
+                           * ( bsfn(ji,jj-2) - bsfn(ji-1,jj-2) )
+# else
+                  zvcbm2 = vn (ji,jj-2,jk)
+# endif
+         ! ... fields nit <== now (kt+1) 
+                  vnbnd(ji,jk,nib  ,nit) = zvcb  *vnmsk(ji,jk)
+                  vnbnd(ji,jk,nibm ,nit) = zvcbm *vnmsk(ji,jk)
+                  vnbnd(ji,jk,nibm2,nit) = zvcbm2*vnmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(vnbnd,jpind,jpinf,jpjnob,jpk*3*3,1,jpi)
+
+         ! ... extremeties njn0,njn1
+         ii = jpind + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF
+         ii = jpinf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               vnbnd(ii,jk,nibm,nitm) = vnbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+
+         ! 1.3 Temperature and salinity
+         ! ----------------------------
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm <== nit  plus time filter at the boundary
+               tnbnd(ji,jk,nib ,nitm) = tnbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
+               snbnd(ji,jk,nib ,nitm) = snbnd(ji,jk,nib,nit)*tnmsk(ji,jk)
+            END DO
+         END DO
+
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  tnbnd(ji,jk,nibm ,nitm) = tnbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
+                  snbnd(ji,jk,nibm ,nitm) = snbnd(ji,jk,nibm ,nit)*tnmsk(ji,jk)
+         ! ... fields nit <== now (kt+1)
+                  tnbnd(ji,jk,nib  ,nit) = tn(ji,jj,  jk)*tnmsk(ji,jk)
+                  tnbnd(ji,jk,nibm ,nit) = tn(ji,jj-1,jk)*tnmsk(ji,jk)
+                  snbnd(ji,jk,nib  ,nit) = sn(ji,jj,  jk)*tnmsk(ji,jk)
+                  snbnd(ji,jk,nibm ,nit) = sn(ji,jj-1,jk)*tnmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(tnbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi)
+         IF( lk_mpp )   CALL mppobc(snbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi)
+
+         ! ... extremeties  njn0,njn1
+         ii = jpind + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii+1,jk,nibm,nitm)
+               snbnd(ii,jk,nibm,nitm) = snbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF
+         ii = jpinf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               tnbnd(ii,jk,nibm,nitm) = tnbnd(ii-1,jk,nibm,nitm)
+               snbnd(ii,jk,nibm,nitm) = snbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+
+      END IF     ! End of array swap
+
+      ! 2 - Calculation of radiation velocities
+      ! ---------------------------------------
+
+      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+
+         ! 2.1  Calculate the normal velocity based on phase velocity u_cynbnd
+         ! -------------------------------------------------------------------
+         !
+         !           ji-row
+         !             |
+         !     nib -///u//////  jpjnob + 1
+         !        /////|//////
+         !   nib  -----f-----   jpjnob
+         !             |    
+         !     nibm--  u   ---- jpjnob
+         !             |        
+         !  nibm  -----f-----   jpjnob-1
+         !             |        
+         !    nibm2--  u   ---- jpjnob-1
+         !             |        
+         !  nibm2 -----f-----   jpjnob-2
+         !             |
+         ! ... radiative condition
+         ! ... jpjnob+1,(jpindp1, jpinfm1)
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
+                  z2dx = ( unbnd(ji,jk,nibm ,nit) + unbnd(ji,jk,nibm ,nitm2) &
+                        - 2.*unbnd(ji,jk,nibm2,nitm)) / e2f(ji,jj-2)
+         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
+                  z2dy = ( unbnd(ji+1,jk,nibm,nitm) - unbnd(ji-1,jk,nibm,nitm) ) / e1u(ji,jj-1)
+         ! ... square of the norm of grad(v)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = unbnd(ji,jk,nibm,nitm2) - unbnd(ji,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by 1) and save the unbounded phase
+         !     velocity ratio no divided by e1f for the tracer radiation
+                  IF( z4nor2 == 0.) THEN
+                     z4nor2=.000001
+                  END IF
+                  z05cx = zdt * z2dx / z4nor2
+                  u_cynbnd(ji,jk) = z05cx *unmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(u_cynbnd,jpind,jpinf,jpjnob+1,jpk,1,jpi)
+
+         ! ... extremeties  njn0,njn1
+         ii = jpind + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               u_cynbnd(ii,jk) = u_cynbnd(ii+1,jk)
+            END DO
+         END IF
+         ii = jpinf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               u_cynbnd(ii,jk) = u_cynbnd(ii-1,jk)
+            END DO
+         END IF
+
+         ! 2.2 Calculate the normal velocity based on phase velocity v_cynbnd 
+         ! ------------------------------------------------------------------
+         !
+         !                ji-row  ji-row
+         !                     |
+         !        /////|/////////////////
+         !   nib  -----f----v----f----  jpjnob
+         !             |         |
+         !     nib  -  u -- T -- u ---- jpjnob
+         !             |         |
+         !  nibm  -----f----v----f----  jpjnob-1
+         !             |         |
+         !    nibm --  u -- T -- u ---  jpjnob-1
+         !             |         |
+         !  nibm2 -----f----v----f----  jpjnob-2
+         !             |         |
+         ! ... If rigidlid formulation:
+         ! ... radiative conditions on the baroclinic part only + relaxation toward climatology
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology 
+         ! ... jpjnob,(jpindp1, jpinfm1)
+         DO jj = fs_njn0, fs_njn1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         ! ... 2* gradj(v) (T-point i=nibm, time mean)
+                  ii = ji -1 + nimpp
+                  z2dx = ( vnbnd(ji,jk,nibm ,nit) + vnbnd(ji,jk,nibm ,nitm2) &
+                          - 2.*vnbnd(ji,jk,nibm2,nitm)) / e2t(ji,jj-1)
+         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
+                  z2dy = ( vnbnd(ji+1,jk,nibm,nitm) - vnbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj-1)
+         ! ... square of the norm of grad(u)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = vnbnd(ji,jk,nibm,nitm2) - vnbnd(ji,jk,nibm,nit)
+         ! ... j-phase speed ratio (bounded by 1)
+                  IF( z4nor2 == 0. ) THEN
+                     z4nor2=.00001
+                  END IF
+                  z05cx = zdt * z2dx / z4nor2
+                  v_cynbnd(ji,jk)=z05cx *vnmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_rad_north
+
+
+   SUBROUTINE obc_rad_south ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_rad_south  ***
+      !!           
+      !! ** Purpose :
+      !!      Perform swap of arrays to calculate radiative phase speeds at the open 
+      !!      south boundary and calculate those phase speeds if this OBC is not fixed.
+      !!      In case of fixed OBC, this subrountine is not called.
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) Free surface, F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER ::   ii
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      REAL(wp) ::   zvcb, zvcbm, zvcbm2
+      !!------------------------------------------------------------------------------
+
+      ! 1. Swap arrays before calculating radiative velocities
+      ! ------------------------------------------------------
+
+      ! 1.1  zonal velocity 
+      ! --------------------
+  
+      IF( kt > nit000) THEN 
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm2 <== nitm
+                  usbnd(ji,jk,nib  ,nitm2) = usbnd(ji,jk,nib  ,nitm)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm ,nitm2) = usbnd(ji,jk,nibm ,nitm)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm2,nitm2) = usbnd(ji,jk,nibm2,nitm)*usmsk(ji,jk)
+            END DO
+         END DO
+ 
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  usbnd(ji,jk,nib  ,nitm) = usbnd(ji,jk,nib,  nit)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm ,nitm) = usbnd(ji,jk,nibm ,nit)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm2,nitm) = usbnd(ji,jk,nibm2,nit)*usmsk(ji,jk)
+         ! ... fields nit <== now (kt+1)
+                  usbnd(ji,jk,nib  ,nit) = un(ji,jj  ,jk)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm ,nit) = un(ji,jj+1,jk)*usmsk(ji,jk)
+                  usbnd(ji,jk,nibm2,nit) = un(ji,jj+2,jk)*usmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(usbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi)
+
+         ! ... extremeties njs0,njs1
+         ii = jpisd + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               usbnd(ii,jk,nibm,nitm) = usbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF
+         ii = jpisf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               usbnd(ii,jk,nibm,nitm) = usbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+ 
+         ! 1.2 normal velocity
+         ! -------------------
+ 
+         !.. advance in time (time filter, array swap) 
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm2 <== nitm 
+               vsbnd(ji,jk,nib  ,nitm2) = vsbnd(ji,jk,nib  ,nitm)*vsmsk(ji,jk)
+               vsbnd(ji,jk,nibm ,nitm2) = vsbnd(ji,jk,nibm ,nitm)*vsmsk(ji,jk)
+            END DO
+         END DO
+
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  vsbnd(ji,jk,nib  ,nitm) = vsbnd(ji,jk,nib,  nit)*vsmsk(ji,jk)
+                  vsbnd(ji,jk,nibm ,nitm) = vsbnd(ji,jk,nibm ,nit)*vsmsk(ji,jk)
+                  vsbnd(ji,jk,nibm2,nitm) = vsbnd(ji,jk,nibm2,nit)*vsmsk(ji,jk)
+         ! ... total or baroclinic velocity at b, bm and bm2
+# if defined key_dynspg_rl
+                  zvcb   = vclis(ji,jk)
+# else
+                  zvcb   = vn (ji,jj,jk)
+# endif
+# if defined key_dynspg_rl
+                  zvcbm  = vn (ji,jj+1,jk) - hvr (ji,jj+1) / e1v (ji,jj+1) & 
+                           * ( bsfn(ji,jj+1) - bsfn(ji-1,jj+1) )
+# else
+                  zvcbm  = vn (ji,jj+1,jk)
+# endif
+# if defined key_dynspg_rl  
+                  zvcbm2 = vn (ji,jj+2,jk) - hvr (ji,jj+2) / e1v (ji,jj+2) &
+                           * ( bsfn(ji,jj+2) - bsfn(ji-1,jj+2) )
+# else
+                  zvcbm2 = vn (ji,jj+2,jk)
+# endif
+         ! ... fields nit <== now (kt+1) 
+                  vsbnd(ji,jk,nib  ,nit) = zvcb   *vsmsk(ji,jk)
+                  vsbnd(ji,jk,nibm ,nit) = zvcbm  *vsmsk(ji,jk)
+                  vsbnd(ji,jk,nibm2,nit) = zvcbm2 *vsmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(vsbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi)
+
+         ! ... extremeties njs0,njs1
+         ii = jpisd + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF
+         ii = jpisf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               vsbnd(ii,jk,nibm,nitm) = vsbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+
+         ! 1.3 Temperature and salinity
+         ! ----------------------------
+
+         ! ... advance in time (time filter, array swap)
+         DO jk = 1, jpkm1
+            DO ji = 1, jpi
+         ! ... fields nitm <== nit  plus time filter at the boundary
+               tsbnd(ji,jk,nib,nitm) = tsbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
+               ssbnd(ji,jk,nib,nitm) = ssbnd(ji,jk,nib,nit)*tsmsk(ji,jk)
+            END DO
+         END DO
+
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  tsbnd(ji,jk,nibm ,nitm) = tsbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
+                  ssbnd(ji,jk,nibm ,nitm) = ssbnd(ji,jk,nibm ,nit)*tsmsk(ji,jk)
+         ! ... fields nit <== now (kt+1)
+                  tsbnd(ji,jk,nib  ,nit) = tn(ji,jj   ,jk)*tsmsk(ji,jk)
+                  tsbnd(ji,jk,nibm ,nit) = tn(ji,jj+1 ,jk)*tsmsk(ji,jk)
+                  ssbnd(ji,jk,nib  ,nit) = sn(ji,jj   ,jk)*tsmsk(ji,jk)
+                  ssbnd(ji,jk,nibm ,nit) = sn(ji,jj+1 ,jk)*tsmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(tsbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi)
+         IF( lk_mpp )   CALL mppobc(ssbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi)
+
+         ! ... extremeties  njs0,njs1
+         ii = jpisd + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii+1,jk,nibm,nitm)
+               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii+1,jk,nibm,nitm)
+            END DO
+         END IF
+         ii = jpisf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               tsbnd(ii,jk,nibm,nitm) = tsbnd(ii-1,jk,nibm,nitm)
+               ssbnd(ii,jk,nibm,nitm) = ssbnd(ii-1,jk,nibm,nitm)
+            END DO
+         END IF
+
+      END IF     ! End of array swap
+
+      ! 2 - Calculation of radiation velocities
+      ! ---------------------------------------
+
+      IF( kt >= nit000 +3 .OR. ln_rstart ) THEN
+
+         ! 2.1  Calculate the normal velocity based on phase velocity u_cysbnd
+         ! -------------------------------------------------------------------
+         !
+         !          ji-row
+         !            |
+         ! nibm2 -----f-----   jpjsob +2
+         !            |    
+         !  nibm2 --  u  ----- jpjsob +2 
+         !            |        
+         !  nibm -----f-----   jpjsob +1
+         !            |        
+         !  nibm  --  u  ----- jpjsob +1
+         !            |        
+         !  nib  -----f-----   jpjsob
+         !       /////|//////
+         !  nib   ////u/////   jpjsob 
+         !
+         ! ... radiative condition plus Raymond-Kuo
+         ! ... jpjsob,(jpisdp1, jpisfm1)
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         ! ... 2* j-gradient of u (f-point i=nibm, time mean)
+                  z2dx = (- usbnd(ji,jk,nibm ,nit) - usbnd(ji,jk,nibm ,nitm2) &
+                          + 2.*usbnd(ji,jk,nibm2,nitm) ) / e2f(ji,jj+1)
+         ! ... 2* i-gradient of u (u-point i=nibm, time nitm)
+                  z2dy = ( usbnd(ji+1,jk,nibm,nitm) - usbnd(ji-1,jk,nibm,nitm) ) / e1u(ji, jj+1)
+         ! ... square of the norm of grad(v)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+                  IF( z4nor2 == 0.) THEN
+                     z4nor2 = 0.000001
+                  END IF
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = usbnd(ji,jk,nibm,nitm2) - usbnd(ji,jk,nibm,nit)
+         ! ... i-phase speed ratio (bounded by -1) and save the unbounded phase
+         !     velocity ratio no divided by e1f for the tracer radiation
+                  z05cx = zdt * z2dx / z4nor2
+                  u_cysbnd(ji,jk) = z05cx*usmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mppobc(u_cysbnd,jpisd,jpisf,jpjsob,jpk,1,jpi)
+
+         ! ... extremeties  njs0,njs1
+         ii = jpisd + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               u_cysbnd(ii,jk) = u_cysbnd(ii+1,jk)
+            END DO
+         END IF
+         ii = jpisf + 1 - nimpp
+         IF( ii >= 2 .AND. ii < jpim1 ) THEN
+            DO jk = 1, jpkm1
+               u_cysbnd(ii,jk) = u_cysbnd(ii-1,jk)
+            END DO
+         END IF
+
+         ! 2.2 Calculate the normal velocity based on phase velocity v_cysbnd 
+         ! -------------------------------------------------------------------
+         !
+         !               ji-row  ji-row
+         !            |         |
+         ! nibm2 -----f----v----f----  jpjsob+2
+         !            |         |
+         !  nibm   -  u -- T -- u ---- jpjsob+2
+         !            |         |
+         ! nibm  -----f----v----f----  jpjsob+1 
+         !            |         |
+         ! nib    --  u -- T -- u ---  jpjsob+1
+         !            |         |
+         ! nib   -----f----v----f----  jpjsob
+         !       /////////////////////
+         !
+         ! ... If rigidlid formulation:
+         ! ... radiative conditions on the baroclinic part only + relaxation toward climatology 
+         ! ... If free surface formulation:
+         ! ... radiative conditions on the total part + relaxation toward climatology
+         ! ... jpjsob,(jpisdp1,jpisfm1)
+         DO jj = fs_njs0, fs_njs1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         ! ... 2* gradj(v) (T-point i=nibm, time mean)
+                  z2dx = ( - vsbnd(ji,jk,nibm ,nit) - vsbnd(ji,jk,nibm ,nitm2) &
+                           + 2.*vsbnd(ji,jk,nibm2,nitm) ) / e2t(ji,jj+1)
+         ! ... 2* gradi(v) (v-point i=nibm, time nitm)
+                  z2dy = ( vsbnd(ji+1,jk,nibm,nitm) - vsbnd(ji-1,jk,nibm,nitm) ) / e1v(ji,jj+1)
+         ! ... square of the norm of grad(u)
+                  z4nor2 = z2dx * z2dx + z2dy * z2dy
+                  IF( z4nor2 == 0.) THEN
+                     z4nor2 = 0.000001
+                  END IF
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+                  zdt = vsbnd(ji,jk,nibm,nitm2) - vsbnd(ji,jk,nibm,nit)
+         ! ... j-phase speed ratio (bounded by -1)
+                  z05cx = zdt * z2dx / z4nor2
+                  v_cysbnd(ji,jk)=z05cx*vsmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+ 
+   END SUBROUTINE obc_rad_south
+
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcrad  ***
+   !! Ocean dynamic :   Phase velocities for each open boundary
+   !!=================================================================================
+CONTAINS
+   SUBROUTINE obc_rad( kt )            ! No open boundaries ==> empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'obc_rad: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_rad
+#endif
+
+END MODULE obcrad
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcrst.F90	(revision 4536)
@@ -0,0 +1,671 @@
+MODULE obcrst
+#if defined key_obc
+   !!=================================================================================
+   !!                       ***  MODULE  obcrst  ***
+   !! Ocean dynamic :  Input/Output files for restart on OBC
+   !!=================================================================================
+
+   !!---------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE daymod          ! calendar
+   USE lib_mpp         ! for mppobc
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_rst_lec        ! routine called by iniobc.F90
+   PUBLIC obc_rst_wri        ! routine called by step.F90
+
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/OBC/obcrst.F90,v 1.8 2007/06/29 17:01:51 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_rst_wri ( kt )
+      !!--------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_rst_wri  ***
+      !!                
+      !! ** Purpose :   Write open boundary restart fields in restart.obc.output file 
+      !!
+      !! ** Method  :   restart.obc.output file: Direct access non formatted file.
+      !!      Each nstock time step , save fields which are necessary for restart.
+      !!      - This routine is called if at least the key_obc is defined. It is called
+      !!        at the same time step than rstwri.
+      !!      - First record holds OBC parameters nbobc,jpieob,jpiwob,jpjnob,jpjsob and 
+      !!        the OBC layout jpjed, jpjef ... for checking purposes.
+      !!      - Following records hold the boundary arrays, in the order east west north
+      !!        south, if they exist.
+      !!      - The writing is realised by vertical slab across the boundary, for bsf, u,
+      !!        v, t, and s boundary arrays. Each record hold a vertical slab.
+      !!      - For mpp, this allows each processor to write only the correct informations
+      !!        it hold. If a processor has no valid informations on boundary, it just 
+      !!        skip the writing part (automatically).
+      !!      - Special care is taken for dumping the starting point of a boundary (jpjed,
+      !!        jpjwd, jpind, jpisd) because of the general definition of nje0 njw0,nin0,
+      !!        nis0. This is done to avoid records to be written by 2 adjacent processors.
+      !!
+      !!  History :
+      !!         ! 97-11 (J.M. Molines) Original code
+      !!         ! 98-11 (J.M. Molines) Bug fix for adjacent processors
+      !!   8.5   ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!         ! 03-06 (J.M. Molines) Bug fix for adjacent processors
+      !!   9.0   ! 04-02 (G. Madec)  suppression of numwob, use inum
+      !!-----------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk
+      INTEGER ::   inum               ! temporary logical unit
+      INTEGER ::   ibloc, nreclo, jrec, jt, jb 
+      INTEGER ::   jfoe, jfow, ifon, ifos
+      INTEGER ::   ino0, it0
+      !!-----------------------------------------------------------------------------
+
+      ! 1. Output of restart fields (inum)
+      ! ------------------------------------
+ 
+      IF( ( mod(kt,nstock) == 0 ) .OR. ( kt == nitend ) ) THEN
+
+         ! 1.0 Initializations
+         ! -------------------
+         IF(lwp) THEN
+              WRITE(numout,*) ' '
+              WRITE(numout,*) 'obcrst: OBC output for restart with obc_rst_wri routine'
+              WRITE(numout,*) '~~~~~~'
+              WRITE(numout,*) '        output done in restart.obc.output file at it= ', kt, ' date= ', ndastp
+         END IF
+
+         ino0 = no
+         it0  = kt
+         ibloc  = 4096*4
+         nreclo = ibloc*( ( ( 26 *jpk + 9 )*jpbyt -1)/ibloc + 1)
+         IF(lwp) WRITE(numout,*) '             '
+         IF(lwp) WRITE(numout,*) '        OBC restart file opened with nreclo = ',nreclo
+
+         ! 1.1 Open file
+         ! -------------
+
+         CALL ctlopn( inum, 'restart.obc.output', 'UNKNOWN', 'UNFORMATTED', 'DIRECT',   &
+            &         nreclo, numout, lwp, 1 )
+ 
+         ! 1.2 Write header
+         ! ----------------
+         WRITE (inum,REC=1) ino0,it0,nbobc,jpieob,jpiwob,jpjnob,jpjsob,     &
+                              jpjed,jpjef,jpjwd,jpjwf,jpind,jpinf,jpisd,jpisf
+
+         ! 1.3 Write east boundary array if any.
+         ! -------------------------------------
+         IF( lp_obc_east ) THEN
+            IF( lfbceast ) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) '        No restart file for the fixed east OBC'
+               END IF
+            ELSE
+               IF( jpieob /= 0 ) THEN
+                  IF( nje0+njmpp-1  == jpjed .AND. nie1 >= nie0 ) THEN
+            ! ... dump of jpjed if it is on this proc.
+                     jrec = 2
+                     jfoe = jpjed - njmpp + 1
+                     PRINT *,'Narea =',narea,' write jrec =2 east'
+                     WRITE(inum,REC=jrec)                                    &
+# if defined key_dynspg_rl
+                           ((  bebnd(jfoe,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                           ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                           ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                  ENDIF
+                  DO ji = nie0, nie1
+                     DO jj = nje0, nje1
+            ! ... only interested processors go through the following lines
+            !           jfoe = jj + njmpp -1
+                        jfoe = jj 
+                        jrec = 2 + jj + njmpp -1 -jpjed
+                        WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                              ((  bebnd(jfoe,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                              ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                              ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                     END DO
+                  END DO
+               END IF
+            END IF
+         END IF
+ 
+         ! 1.4 Write west boundary arrays if any
+         ! -------------------------------------
+         IF( lp_obc_west ) THEN
+            IF( lfbcwest ) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) '        No restart file for the fixed west OBC'
+               END IF
+            ELSE
+               IF( jpiwob /= 0 ) THEN
+                  IF( njw0+njmpp+1 == jpjwd .AND. niw1 >= niw0 ) THEN
+            ! ... dump of jpjwd if it is on this proc.
+                     jrec = 3 + jpjef - jpjed
+            !        jfow = jpjwd
+                     jfow = jpjwd -njmpp + 1
+                     PRINT *,'Narea =',narea,' write jrec =',jrec,' west'
+                     WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                           ((  bwbnd(jfow,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                           ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                           ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                  END IF
+                  DO ji = niw0, niw1
+                     DO jj = njw0, njw1
+            ! ... only interested processors go through the following lines
+            !           jfow = jj + njmpp -1
+                        jfow = jj 
+                        jrec = 3 + jpjef -jpjed + jj + njmpp -1 -jpjwd
+                        WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                              ((  bwbnd(jfow,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                              ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                              ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                     END DO
+                  END DO
+               END IF
+            END IF
+         END IF
+ 
+         ! 1.5 Write north boundary arrays if any
+         ! --------------------------------------
+         IF( lp_obc_north ) THEN
+            IF( lfbcnorth ) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) '        No restart file for the fixed north OBC'
+               END IF
+            ELSE
+               IF( jpjnob /= 0) THEN
+                  IF( nin0+nimpp-1 == jpind .AND. njn1 >= njn0 ) THEN
+            ! ... dump of jpind if it is on this proc.
+                     jrec = 4 + jpjef -jpjed + jpjwf -jpjwd
+            !        ifon = jpind
+                     ifon = jpind -nimpp +1
+                     WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                           ((  bnbnd(ifon,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                           ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                           ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                  END IF
+                  DO jj = njn0, njn1
+                     DO ji = nin0, nin1
+            ! ... only interested processors go through the following lines
+            !           ifon = ji + nimpp -1
+                        ifon = ji 
+                        jrec = 4 + jpjef -jpjed + jpjwf -jpjwd +ji + nimpp -1  -jpind
+                        WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                              ((  bnbnd(ifon,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                              ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                              ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                     END DO
+                  END DO
+               END IF
+            END IF
+         END IF
+ 
+         ! 1.6 Write south boundary arrays if any
+         ! --------------------------------------
+         IF( lp_obc_south ) THEN
+            IF( lfbcsouth ) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) '        No restart file for the fixed south OBC'
+                  WRITE(numout,*) ' '
+               END IF
+            ELSE
+               IF( jpjsob /= 0 ) THEN
+                  IF( nis0+nimpp-1 == jpisd .AND. njs1 >= njs0 ) THEN
+            ! ... dump of jpisd if it is on this proc.
+                     jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind
+            !        ifos = jpisd
+                     ifos = jpisd -nimpp + 1
+                     WRITE (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                           ((  bsbnd(ifos,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                           ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                           ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                           ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                  END IF
+                  DO jj = njs0, njs1
+                     DO ji = nis0, nis1
+            ! ... only interested processors go through the following lines
+            !           ifos = ji + nimpp -1
+                        ifos = ji 
+                        jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind + &
+                              ji + nimpp -1 -jpisd
+                        WRITE (inum,REC=jrec) &
+# if defined key_dynspg_rl
+                              ((  bsbnd(ifos,   jb,jt),          jb=1,3),jt=1,3), &
+# endif 
+                              ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                              ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                              ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+                     END DO
+                  END DO
+               END IF
+            END IF
+         END IF
+      END IF
+      CLOSE(inum)
+
+   END SUBROUTINE obc_rst_wri
+
+
+   SUBROUTINE obc_rst_lec
+      !!----------------------------------------------------------------------------
+      !!                   ***  SUBROUTINE obc_rst_lec  ***
+      !!                   
+      !! ** Purpose :   Read files for restart at open boundaries
+      !!
+      !! ** Method  :   Read the previous boundary arrays on unit inum
+      !!      The first record indicates previous characterics
+      !!
+      !! History :
+      !!        ! 97-11 (J.M. Molines) Original code
+      !!   8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!----------------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   inum = 11            ! temporary logical unit
+      INTEGER ::   ji,jj,jk,ios
+      INTEGER ::   ino0,it0,nbobc0,jpieob0,jpiwob0,jpjnob0,jpjsob0
+      INTEGER ::   ino1,it1,nbobc1,jpieob1,jpiwob1,jpjnob1,jpjsob1
+      INTEGER ::   ied0,ief0,iwd0,iwf0,ind0,inf0,isd0,isf0
+      INTEGER ::   ied1,ief1,iwd1,iwf1,ind1,inf1,isd1,isf1
+      INTEGER ::   ibloc, nreclo, jrec, jt, jb
+      INTEGER ::   jfoe, jfow, ifon, ifos
+      !!-----------------------------------------------------------------------------
+
+      ! 0. Initialisations
+      ! ------------------
+ 
+      ino0    = no
+      it0     = nit000
+      nbobc0  = nbobc
+      jpieob0 = jpieob
+      jpiwob0 = jpiwob
+      jpjnob0 = jpjnob
+      jpjsob0 = jpjsob
+ 
+      ied0   = jpjed
+      ief0   = jpjef
+      iwd0   = jpjwd
+      iwf0   = jpjwf
+      ind0   = jpind
+      inf0   = jpinf
+      isd0   = jpisd
+      isf0   = jpisf
+ 
+      ibloc  = 4096*4
+      nreclo = ibloc *( ( ( 26 *jpk + 9 )*jpbyt -1)/ibloc + 1)
+ 
+      IF(lwp) THEN
+         WRITE(numout,*) 'obcrst: beginning of restart with obc_rst_lec routine'
+         WRITE(numout,*) '~~~~~~'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '        The present run :'
+         WRITE(numout,*) '        number job is  : ',no 
+         WRITE(numout,*) '        with the time nit000 : ',nit000
+         WRITE(numout,*) '        OBC restart file opened with nreclo = ',nreclo 
+      END IF
+ 
+      ! 0.1 Open files
+      ! ---------------
+      CALL ctlopn( inum, 'restart.obc.output', 'UNKNOWN', 'UNFORMATTED', 'DIRECT',   &
+         &         nreclo, numout, lwp, 1 )
+
+      ! 1. Read
+      ! -------
+ 
+      ! 1.1 First record
+      ! -----------------
+      READ(inum,REC=1) ino1,it1,nbobc1,jpieob1,jpiwob1,jpjnob1,     &
+                         jpjsob1,ied1,ief1,iwd1,iwf1,ind1,inf1,isd1,isf1
+ 
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '        READ inum with number job : ',ino1,' with the time it: ',it1
+         WRITE(numout,*) ' '
+      END IF
+ 
+      ! 1.2 Control of date
+      ! --------------------
+      IF( ( it0-it1 ) /= 1 .AND. abs(nrstdt) == 1 ) THEN
+          CALL ctl_stop( '        ===>>>> : problem with nit000 for the restart',   &
+               &         '        ==============',   &
+               &         '        we stop in obc_rst_lec routine. Verify the file or rerun with the value',   &
+               &         '        0 for the control of time parameter nrstdt' )
+             
+      END IF
+ 
+      ! 1.3 Control of number of open boundaries
+      ! ----------------------------------------
+      IF( nbobc1 /= nbobc0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '        ===> W A R N I N G: The number of OBC have changed:'
+            WRITE(numout,*) '        Last run : ',nbobc0,' obcs'
+            WRITE(numout,*) '        This run : ',nbobc1,' obcs'
+         END IF
+      END IF
+ 
+      ! 1.4 Control of which boundary is open
+      ! -------------------------------------
+      IF( lp_obc_east .AND. ( jpieob1 /= 0 ) ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '         '
+            WRITE(numout,*) '        East open boundary'
+            IF( jpieob0 /= jpieob1 ) CALL ctl_stop( '         ==>>>> : Problem in obc_rst_lec, jpieob have changed' )
+         END IF
+      END IF
+ 
+      IF( lp_obc_west .AND. ( jpiwob1 /= 0 ) ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '         '
+            WRITE(numout,*) '        West open boundary'
+            IF( jpiwob0 /= jpiwob1 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpiwob has changed' )
+         END IF
+      END IF
+ 
+      IF( lp_obc_north .AND. ( jpjnob1 /= 0 ) ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '         '
+            WRITE(numout,*) '        North open boundary'
+            IF( jpjnob0 /= jpjnob1 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjnob has changed' )
+         END IF
+      END IF
+ 
+      IF( lp_obc_south .AND. ( jpjsob1 /= 0 ) ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) '         '
+            WRITE(numout,*) '        South open boundary'
+            IF( jpjsob0 /= jpjsob1) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjsob has changed' )
+         END IF
+      END IF
+ 
+ 
+      ! 1.5 Control of the limit of the boundaries
+      ! ------------------------------------------
+      IF( lp_obc_east .AND. ( jpieob1 /= 0 ) ) THEN
+         IF( ied1 /= ied0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjed has changed' )
+         IF( ief1 /= ief0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjef has changed' )
+      END IF
+
+      IF( lp_obc_west .AND. ( jpiwob1 /= 0 ) ) THEN
+         IF( iwd1 /= iwd0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjwd has changed' )
+         IF( iwf1 /= iwf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpjwf has changed' )
+      END IF
+ 
+      IF( lp_obc_north .AND. ( jpjnob1 /= 0 ) ) THEN
+         IF( ind1 /= ind0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpind has changed' )
+         IF( inf1 /= inf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpinf has changed' )
+      END IF
+ 
+      IF( lp_obc_south .AND. ( jpjsob1 /= 0 ) ) THEN
+         IF( isd1 /= isd0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpisd has changed' )
+         IF( isf1 /= isf0 ) CALL ctl_stop( '        ==>>>> : Problem in obc_rst_lec, jpisf has changed' )
+      END IF
+ 
+ 
+      ! 2. Now read the boundary arrays
+      ! -------------------------------
+ 
+      ! 2.1 Read east boundary array if any.
+      ! ------------------------------------
+      IF( lp_obc_east ) THEN
+         IF( jpieob1 /= 0) THEN
+            IF( nje0+njmpp-1 == jpjed .AND. nie1 >= nie0 ) THEN
+      ! ... read of jpjed if it is on this proc.
+               jrec = 2
+      !        jfoe = jpjed
+               jfoe = jpjed -njmpp + 1
+               READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                    ((  bebnd(jfoe,   jb,jt),          jb=1,3),jt=1,3), &
+# endif 
+                    ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                    ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+            END IF
+            DO ji = nie0, nie1
+               DO jj = nje0, nje1
+      ! ... only interested processors go through the following lines
+      !           jfoe = jj + njmpp -1
+                  jfoe = jj 
+                  jrec = 2 + jj + njmpp -1 -jpjed
+                  READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                       ((  bebnd(jfoe,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                       ((( uebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( vebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( tebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                       ((( sebnd(jfoe,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+               END DO
+            END DO
+
+         ELSE
+
+            !  lp_obc_east was not TRUE previously
+         END IF
+
+      END IF
+ 
+      ! 2.2 Read west boundary arrays if any.
+      ! -------------------------------------
+      IF( lp_obc_west ) THEN
+         IF( jpiwob1 /= 0) THEN
+            IF( njw0+njmpp-1 == jpjwd .AND. niw1 >= niw0 ) THEN
+      ! ... read of jpjwd if it is on this proc.
+               jrec = 3 + jpjef - jpjed
+      !        jfow = jpjwd
+               jfow = jpjwd -njmpp + 1
+               READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                    ((  bwbnd(jfow,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                    ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                    ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+            END IF
+            DO ji = niw0, niw1
+               DO jj = njw0, njw1
+      ! ... only interested processors go through the following lines
+      !           jfow = jj + njmpp -1
+                  jfow = jj 
+                  jrec = 3 + jpjef -jpjed + jj + njmpp -1 -jpjwd
+                  READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                       ((  bwbnd(jfow,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                       ((( uwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( vwbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( twbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                       ((( swbnd(jfow,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+               END DO
+            END DO
+
+         ELSE
+
+            !  lp_obc_west was not TRUE previously
+         END IF
+
+      END IF
+ 
+      ! 2.3 Read north boundary arrays if any.
+      ! --------------------------------------
+      IF( lp_obc_north ) THEN
+         IF( jpjnob1 /= 0) THEN
+            IF( nin0+nimpp-1 == jpind .AND. njn1 >= njn0 ) THEN
+      ! ... read of jpind if it is on this proc.
+               jrec = 4 + jpjef -jpjed + jpjwf -jpjwd
+      !        ifon = jpind
+               ifon = jpind -nimpp +1
+               READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                    ((  bnbnd(ifon,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                    ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), & 
+                    ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+            END IF
+            DO jj = njn0, njn1
+               DO ji = nin0, nin1
+      ! ... only interested processors go through the following lines
+      !           ifon = ji + nimpp -1
+                  ifon = ji 
+                  jrec = 4 + jpjef -jpjed + jpjwf -jpjwd +ji + nimpp -1  -jpind
+                  READ (inum,REC=jrec)                                   & 
+# if defined key_dynspg_rl
+                       ((  bnbnd(ifon,   jb,jt),          jb=1,3),jt=1,3), &
+# endif  
+                       ((( unbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( vnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( tnbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                       ((( snbnd(ifon,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+               END DO
+            END DO
+
+         ELSE
+
+           !  lp_obc_north was not TRUE previously
+         END IF
+
+      END IF
+ 
+      ! 2.4 Read south boundary arrays if any.
+      ! -------------------------------------
+      IF( lp_obc_south ) THEN
+         IF( jpjsob1 /= 0) THEN
+            IF( nis0+nimpp-1 == jpisd .AND. njs1 >= njs0 ) THEN
+      ! ... read of jpisd if it is on this proc.
+               jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind
+      !        ifos = jpisd
+               ifos = jpisd -nimpp + 1
+               READ (inum,REC=jrec)                                   &
+# if defined key_dynspg_rl
+                    ((  bsbnd(ifos,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                    ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                    ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                    ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+            END IF
+            DO jj = njs0, njs1
+               DO ji = nis0, nis1
+      ! ... only interested processors go through the following lines
+      !           ifos = ji + nimpp -1
+                  ifos = ji 
+                  jrec = 5 + jpjef -jpjed + jpjwf -jpjwd +jpinf -jpind +  &
+                        ji + nimpp -1 -jpisd
+                  READ (inum,REC=jrec)                                   & 
+# if defined key_dynspg_rl
+                       ((  bsbnd(ifos,   jb,jt),          jb=1,3),jt=1,3), &
+# endif
+                       ((( usbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( vsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,3),jt=1,3), &
+                       ((( tsbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2), &
+                       ((( ssbnd(ifos,jk,jb,jt),jk=1,jpk),jb=1,2),jt=1,2)
+               END DO
+            END DO
+         ELSE
+            !  lp_obc_south was not TRUE previously
+         END IF
+
+      END IF
+      CLOSE(inum)
+
+      IF( lk_mpp ) THEN
+         IF( lp_obc_east ) THEN
+# if defined key_dynspg_rl
+            CALL mppobc(bebnd,jpjed,jpjef,jpieob,3*3,2,jpj)
+# endif
+            CALL mppobc(uebnd,jpjed,jpjef,jpieob,jpk*3*3,2,jpj)
+            CALL mppobc(vebnd,jpjed,jpjef,jpieob+1,jpk*3*3,2,jpj)
+            CALL mppobc(tebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj)
+            CALL mppobc(sebnd,jpjed,jpjef,jpieob+1,jpk*2*2,2,jpj)
+         ENDIF
+         IF( lp_obc_west ) THEN
+# if defined key_dynspg_rl
+            CALL mppobc(bwbnd,jpjwd,jpjwf,jpiwob,3*3,2,jpj)
+# endif
+            CALL mppobc(uwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj)
+            CALL mppobc(vwbnd,jpjwd,jpjwf,jpiwob,jpk*3*3,2,jpj)
+            CALL mppobc(twbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj)
+            CALL mppobc(swbnd,jpjwd,jpjwf,jpiwob,jpk*2*2,2,jpj)
+         ENDIF
+         IF( lp_obc_north ) THEN 
+# if defined key_dynspg_rl
+            CALL mppobc(bnbnd,jpind,jpinf,jpjnob  ,3*3    ,1,jpi)
+# endif
+            CALL mppobc(unbnd,jpind,jpinf,jpjnob+1,jpk*3*3,1,jpi)
+            CALL mppobc(vnbnd,jpind,jpinf,jpjnob  ,jpk*3*3,1,jpi)
+            CALL mppobc(tnbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi)
+            CALL mppobc(snbnd,jpind,jpinf,jpjnob+1,jpk*2*2,1,jpi)
+         ENDIF
+         IF( lp_obc_south ) THEN
+# if defined key_dynspg_rl
+            CALL mppobc(bsbnd,jpisd,jpisf,jpjsob,    3*3,1,jpi)
+# endif
+            CALL mppobc(usbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi)
+            CALL mppobc(vsbnd,jpisd,jpisf,jpjsob,jpk*3*3,1,jpi)
+            CALL mppobc(tsbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi)
+            CALL mppobc(ssbnd,jpisd,jpisf,jpjsob,jpk*2*2,1,jpi)
+         ENDIF
+      ENDIF
+ 
+   END SUBROUTINE obc_rst_lec
+#else
+   !!=================================================================================
+   !!                       ***  MODULE  obcrst  ***
+   !! Ocean dynamic :  Input/Output files for restart on OBC
+   !!=================================================================================
+CONTAINS
+   SUBROUTINE obc_rst_wri( kt )           !  No Open boundary ==> empty routine
+      INTEGER,INTENT(in) :: kt
+      WRITE(*,*) 'obc_rst_wri: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_rst_wri
+   SUBROUTINE obc_rst_lec                 !  No Open boundary ==> empty routine
+   END SUBROUTINE obc_rst_lec
+#endif
+
+   !!=================================================================================
+END MODULE obcrst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcspg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcspg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcspg.F90	(revision 4536)
@@ -0,0 +1,609 @@
+MODULE obcspg 
+   !!======================================================================
+   !!                       ***  MODULE  obcspg  ***
+   !! Open Boundaries  :   Radiation of barotropic stream function on each
+   !!                      open boundary
+   !!======================================================================
+#if   defined key_obc   &&   defined key_dynspg_rl
+   !!----------------------------------------------------------------------
+   !!   'key_obc'    and                            Open Boundary Condition
+   !!   'key_dynspg_rl'                                 Rigid-Lid
+   !!----------------------------------------------------------------------
+   !!   obc_spg       : call the subroutine for each open boundary
+   !!   obc_spg_east  : radiation of the east open boundary streamfunction
+   !!   obc_spg_west  : radiation of the west open boundary streamfunction
+   !!   obc_spg_north : radiation of the north open boundary streamfunction
+   !!   obc_spg_south : radiation of the south open boundary streamfunction
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! for mppobc
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_spg     ! routine called in step.F90 (rigid lid case)
+
+   !! * Module variables
+   INTEGER ::   ji, jj, jk, jnic   ! dummy loop indices
+
+   INTEGER ::      & ! ... boundary space indices 
+      nib   = 1,   & ! nib   = boundary point
+      nibm  = 2,   & ! nibm  = 1st interior point
+      nibm2 = 3,   & ! nibm2 = 2nd interior point
+      !              ! ... boundary time indices 
+      nit   = 1,   & ! nit    = now
+      nitm  = 2,   & ! nitm   = before
+      nitm2 = 3      ! nitm2  = before-before
+
+   REAL(wp) ::   rtaue  , rtauw  , rtaun  , rtaus  ,   &  !
+                 rtauein, rtauwin, rtaunin, rtausin       !
+
+   !! * Substitutions
+#  include "obc_vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_spg ( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE obc_spg  ***
+      !!
+      !! **  Purpose :
+      !!       Compute now barotropic stream function at the open boundaries.
+      !!       (lp_obc_east, and/or lp_obc_west, and/or lp_obc_north, and/or lp_obc_south).
+      !!       Deduce the correct bsf trend on the open boundaries and isolated 
+      !!       coastlines previous to the call to the barotropic solver.
+      !!
+      !! ** Method :
+      !!      In case of open boundaries, there can be a net barotropic flow
+      !!      through the boundaries, hence the potential on the coastlines
+      !!      on each side of the OBC is different.
+      !!      This routine:
+      !!           1. compute the contribution of the isolated coastlines to the
+      !!              rhs of the barotropic equation
+      !!           2. compute the contribution of the OBC to the rhs of the
+      !!              barotropic equation using a radiation equation as explained
+      !!              in the OBC routine.
+      !!
+      !! Reference : 
+      !!   Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !! History :
+      !!        ! 95-03 (J.-M. Molines) Original, SPEM
+      !!        ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!   8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .OR. ln_rstart ) THEN      ! Initialization
+         ! ... Boundary restoring coefficient
+         rtaue = 2. * rdt / rdpeob
+         rtauw = 2. * rdt / rdpwob
+         rtaun = 2. * rdt / rdpnob
+         rtaus = 2. * rdt / rdpsob
+         ! ... Boundary restoring coefficient for inflow ( all boundaries)
+         rtauein = 2. * rdt / rdpein 
+         rtauwin = 2. * rdt / rdpwin
+         rtaunin = 2. * rdt / rdpnin
+         rtausin = 2. * rdt / rdpsin 
+      ENDIF
+
+      ! right hand side of the barotropic elliptic equation
+      ! ---------------------------------------------------
+
+      ! Isolated coastline contribution to the RHS of the barotropic Eq.
+      gcbob(:,:) = 0.e0
+      DO jnic = 1, nbobc-1
+         gcbob(:,:) = gcbob(:,:) + gcfobc(:,:,jnic) * gcbic(jnic)
+      END DO
+
+      IF( lp_obc_east  )   CALL obc_spg_east ( kt )    ! East open boundary
+
+      IF( lp_obc_west  )   CALL obc_spg_west ( kt )    ! West open boundary
+
+      IF( lp_obc_north )   CALL obc_spg_north( kt )    ! North open boundary
+
+      IF( lp_obc_south )   CALL obc_spg_south( kt )    ! South open boundary
+
+      IF( lk_mpp )   CALL lbc_lnk( gcbob, 'G', 1. )
+ 
+   END SUBROUTINE obc_spg
+
+
+   SUBROUTINE obc_spg_east ( kt )
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_spg_east  ***
+      !!                 
+      !! ** Purpose :   Apply the radiation algorithm on east OBC stream function.
+      !!      If lfbceast=T , there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER ::   ij
+      REAL(wp) ::   z2dtr, ztau, zin
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbceast is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000 + 3 .AND. .NOT.ln_rstart) .OR. lfbceast ) THEN
+
+         ! 1.1 Fixed barotropic stream function
+         ! ------------------------------------
+         DO jj = nje0m1, nje1 
+            ij = jj -1 + njmpp
+            bsfeob(jj)=bfoe(ij)
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbceast is .FALSE.
+      ! -----------------------------------------------------
+
+         ! 2.1. Barotropic stream function radiation
+         ! ----------------------------------------
+         !
+         !          nibm2      nibm      nib
+         !            |   nibm  |   nib   |///
+         !            |    |    |    |    |///
+         !  jj-line --f----v----f----v----f---
+         !            |         |         |///
+         !            |    |    |    |    |///
+         !         jpieob-2   jpieob-1    jpieob
+         !                 |         |        
+         !              jpieob-1    jpieob      
+         !
+         ! ... radiative conditions plus restoring term toward climatology
+         ! ... Initialize bsfeob to clim in any case, at the first step
+         !     to ensure proper values at the ends of the open line.
+         ! ... Take care that the j indices starts at nje0 (jpjed) and finish 
+         !     at nje1 (jpjef) to be sure that jpjefm1 and jpjef are set OK.
+         DO ji = fs_nie0-1, fs_nie1-1 ! Vector opt.
+            DO jj = nje0p1, nje1m2 
+               ij = jj -1 + njmpp
+         ! ... 2* gradi(bsf) (v-point i=nibm, time mean)
+               z2dx = ( bebnd(jj,nibm ,nit) + bebnd(jj,nibm ,nitm2) - 2.*bebnd(jj,nibm2,nitm) ) &
+                      / e1v(ji,jj)
+         ! ... 2* gradj(bsf) (f-point i=nibm, time nitm)
+               z2dy = ( bebnd(jj+1,nibm,nitm) - bebnd(jj-1,nibm,nitm) ) / e2f(ji,jj)
+         ! ... square of the norm of grad(bsf)
+               z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+               zdt = bebnd(jj,nibm,nitm2) - bebnd(jj,nibm,nit)
+         ! ... i-phase speed ratio (bounded by 1) and MASKED!
+               IF( z4nor2 == 0 ) THEN
+                  IF(lwp) WRITE(numout,*)' PB dans obc_spg_east au pt ',jj,' : z4nor=0'
+                  z4nor2 = 0.001
+               ENDIF
+               z05cx = zdt * z2dx / z4nor2 * bmask(ji,jj)
+               z05cx = z05cx / e1v(ji+1,jj)
+               z05cx = min( z05cx, 1. )
+         ! ... z05cx < 0, inflow  zin=0, ztau=1  
+         !          => 0, outflow zin=1, ztau=rtaue
+               zin = sign( 1., z05cx )
+               zin = 0.5*( zin + abs(zin) )
+         ! ... Modification JM:  We maintain a restoring term toward
+         !                   bsfb even in case of inflow 
+         ! But restoring is stronger when in flow (10 days) (ztau in set in obcspg.F)
+               ztau = (1.-zin ) * rtauein + zin * rtaue
+               z05cx = z05cx * zin
+         ! ... update bsfn with radiative or climatological bsf (not mask!)
+               bsfeob(jj) = ( ( 1. - z05cx - ztau ) * bebnd(jj,nib ,nitm) + 2.*z05cx  &
+                               * bebnd(jj,nibm,nit) + ztau * bfoe (ij) )              &
+                            / (1. + z05cx)
+            END DO
+         END DO
+
+      ENDIF
+      IF( lk_mpp )   CALL mppobc(bsfeob,jpjed,jpjef,jpieob-1,1,2,jpj)
+
+
+      ! 3. right hand side of the barotropic elliptic equation
+      ! ------------------------------------------------------
+ 
+      IF( ( neuler == 0 ) .AND. ( kt == nit000 ) ) THEN
+         z2dtr = 1.0 / rdt
+      ELSE
+         z2dtr = 0.5 / rdt
+      ENDIF
+      DO ji = fs_nie0-1, fs_nie1-1 ! Vector opt.
+         DO jj = nje0m1, nje1 
+            gcbob(ji,jj) = gcbob(ji,jj) - hvr(ji+1,jj) * e2v(ji+1,jj) / e1v(ji+1,jj) &
+                           * ( bsfeob(jj) - bsfb(ji+1,jj) ) * z2dtr * bmask(ji,jj) 
+         END DO
+      END DO
+
+   END SUBROUTINE obc_spg_east
+
+   SUBROUTINE obc_spg_west ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_spg_west  ***
+      !!                    
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on west OBC stream function.
+      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER ::   ij
+
+      REAL(wp) ::   z2dtr, ztau, zin
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+
+      !!------------------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcwest is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000 + 3 .AND. .NOT.ln_rstart ) .OR. lfbcwest ) THEN
+
+         ! 1.1 Fixed barotropic stream function
+         ! ------------------------------------
+         DO jj = njw0m1, njw1
+            ij = jj -1 + njmpp
+            bsfwob(jj)=bfow(ij)
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcwest is .FALSE.
+      ! -----------------------------------------------------
+
+         ! 2.1. Barotropic stream function radiation
+         ! ----------------------------------------
+         !
+         !         nib       nibm     nibm2
+         !       ///|   nib   |   nibm  |
+         !       ///|    |    |    |    |
+         !       ---f----v----f----v----f-- jj-line
+         !       ///|         |         |
+         !       ///|    |    |    |    |
+         !        jpiwob    jpiwob+1    jpiwob+2
+         !               |         |        
+         !             jpiwob+1    jpiwob+2     
+         !
+         ! ... radiative conditions plus restoring term toward climatology
+         ! ... Initialize bsfwob to clim in any case, at the first step
+         !     to ensure proper values at the ends of the open line.
+         ! ... Take care that the j indices starts at njw0 (jpjwd) and finish
+         ! ... at njw1 (jpjwf) to be sure that jpjwfm1 and jpjwf are set OK.
+         DO ji = fs_niw0+1, fs_niw1+1 ! Vector opt.
+            DO jj = njw0p1, njw1m2
+               ij = jj -1 + njmpp
+         ! ... 2* gradi(bsf) (v-point i=nibm, time mean)
+               z2dx = ( -  bwbnd(jj,nibm ,nit ) - bwbnd(jj,nibm ,nitm2) + 2.*bwbnd(jj,nibm2,nitm ) ) &
+                      / e1v(ji+1,jj)
+         ! ... 2* gradj(bsf) (f-point i=nibm, time nitm)
+               z2dy = ( bwbnd(jj+1,nibm,nitm) - bwbnd(jj-1,nibm,nitm) ) / e2f(ji,jj)
+         ! ... square of the norm of grad(bsf)
+               z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+               zdt = bwbnd(jj,nibm,nitm2) - bwbnd(jj,nibm,nit)
+         ! ... i-phase speed ratio (bounded by 1) and MASKED!
+               IF( z4nor2 == 0 ) THEN
+                  IF(lwp) WRITE(numout,*)' PB dans obc_spg_west au pt ',jj,' : z4nor =0'
+                  z4nor2=0.0001
+               ENDIF
+               z05cx = zdt * z2dx / z4nor2 * bmask(ji,jj)
+               z05cx = z05cx / e1v(ji,jj)
+               z05cx = max( z05cx, -1. )
+         ! ... z05cx => 0, inflow  zin=0, ztau=1  
+         !           <  0, outflow zin=1, ztau=rtauw
+               zin = sign( 1., -1. * z05cx )
+               zin = 0.5*( zin + abs(zin) )
+               ztau = (1.-zin )*rtauwin + zin * rtauw
+               z05cx = z05cx * zin
+         !  ... update bsfn with radiative or climatological bsf (not mask!)
+               bsfwob(jj) = ( ( 1. + z05cx - ztau ) * bwbnd(jj,nib ,nitm) - 2.*z05cx &
+                               * bwbnd(jj,nibm,nit) + ztau * bfow (ij) )             &
+                            / (1. - z05cx)
+            END DO
+         END DO
+
+      ENDIF
+      IF( lk_mpp )   CALL mppobc(bsfwob,jpjwd,jpjwf,jpiwob+1,1,2,jpj) 
+
+
+      ! 3. right hand side of the barotropic elliptic equation
+      ! -------------------------------------------------------
+
+      IF( ( neuler == 0 ) .AND. ( kt == nit000 ) ) THEN
+         z2dtr = 1.0 / rdt
+      ELSE
+         z2dtr = 0.5 / rdt
+      ENDIF
+      DO ji = fs_niw0+1, fs_niw1+1 ! Vector opt.
+         DO jj = njw0m1, njw1
+            gcbob(ji,jj) = gcbob(ji,jj) - hvr(ji,jj) * e2v(ji,jj) / e1v(ji,jj)     &
+                           * ( bsfwob(jj) - bsfb(ji-1,jj) ) * z2dtr * bmask(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_spg_west
+
+   SUBROUTINE obc_spg_north ( kt )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_spg_north  ***
+      !! 
+      !! ** Purpose :   Apply the radiation algorithm on north OBC stream function.
+      !!      If lfbcnorth=T, there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declarations
+      INTEGER ::   ii
+      REAL(wp) ::   z2dtr, ztau, zin
+      REAL(wp) ::   z05cx, zdt, z4nor2, z2dx, z2dy
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcnorth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000 + 3 .AND. .NOT.ln_rstart ) .OR. lfbcnorth ) THEN
+
+         ! 1.1 Fixed barotropic stream function
+         ! ------------------------------------
+         DO ji = nin0m1, nin1
+            ii = ji -1 + nimpp
+            bsfnob(ji)=bfon(ii)
+         END DO
+
+      ELSE      
+
+      ! 2. Beyond the fourth time step if lfbcnorth is .FALSE.
+      ! -----------------------------------------------------
+
+         ! 2.1. Barotropic stream function radiation
+         ! -----------------------------------------
+         !
+         !           ji-row
+         !             |
+         !        ////////////
+         !        ////////////
+         !   nib  -----f------  jpjnob
+         !             |    
+         !      nib--  u   ---- jpjnob
+         !             |        
+         !  nibm  -----f-----   jpjnob-1
+         !             |        
+         !     nibm--  u   ---- jpjnob-1
+         !             |        
+         !  nibm2 -----f-----   jpjnob-2
+         !             |
+         !
+         ! ... radiative conditions plus restoring term toward climatology
+         ! ... z05cx is always the cross boundary phase velocity
+         ! ... Initialize bsfnob to clim in any case, at the first step
+         !     to ensure proper values at the ends of the open line.
+         ! ... Take care that the i indices starts at nin0 (jpind) and finish
+         ! ... at nin1 (jpinf) to be sure that jpinfm1 and jpinf are set OK.
+         DO jj = fs_njn0-1, fs_njn1-1 ! Vector opt.
+            DO ji = nin0p1, nin1m2
+               ii = ji -1 + nimpp
+         ! ... 2* gradj(bsf) (u-point i=nibm, time mean)
+               z2dx = ( bnbnd(ji,nibm ,nit) + bnbnd(ji,nibm ,nitm2) - 2.*bnbnd(ji,nibm2,nitm) ) &
+                      / e2u(ji,jj)
+         ! ... 2* gradi(bsf) (f-point i=nibm, time nitm)
+               z2dy = ( bnbnd(ji+1,nibm,nitm) - bnbnd(ji-1,nibm,nitm) ) / e1f(ji,jj)
+         ! ... square of the norm of grad(bsf)
+               z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+               zdt = bnbnd(ji,nibm,nitm2) - bnbnd(ji,nibm,nit)
+         ! ... j-phase speed ratio (bounded by 1) and MASKED!
+               IF( z4nor2 == 0 ) THEN
+                  IF(lwp) WRITE(numout,*)' PB dans obc_spg_north au pt',ji,' : z4nor =0'
+               ENDIF
+               z05cx = zdt * z2dx / z4nor2 * bmask(ji,jj)
+               z05cx = z05cx / e2u(ji,jj+1)
+               z05cx = min( z05cx, 1. )
+         ! ... z05cx < 0, inflow  zin=0, ztau=1 
+         !          => 0, outflow zin=1, ztau=rtaun
+               zin = sign( 1., z05cx )
+               zin = 0.5*( zin + abs(zin) )
+               ztau = (1.-zin ) * rtaunin + zin * rtaun
+               z05cx = z05cx * zin
+         ! ... update bsfn with radiative or climatological bsf (not mask!)
+               bsfnob(ji) = ( ( 1. - z05cx - ztau ) * bnbnd(ji,nib ,nitm) + 2.*z05cx  &
+                               * bnbnd(ji,nibm,nit) + ztau * bfon (ii) )              &
+                            / (1. + z05cx)
+            END DO
+         END DO
+
+      ENDIF
+      IF( lk_mpp )   CALL mppobc(bsfnob,jpind,jpinf,jpjnob-1,1,1,jpi)
+
+
+      ! 3. right hand side of the barotropic elliptic equation
+      !-------------------------------------------------------
+
+      IF( ( neuler == 0 ) .AND. ( kt == nit000 ) ) THEN
+         z2dtr = 1.0 / rdt
+      ELSE
+         z2dtr = 0.5 / rdt
+      ENDIF
+      DO jj = fs_njn0-1, fs_njn1-1 ! Vector opt.
+         DO ji = nin0m1, nin1
+            gcbob(ji,jj) = gcbob(ji,jj) - hur(ji,jj+1) *  e1u(ji,jj+1) / e2u(ji,jj+1) &
+                           * ( bsfnob(ji) - bsfb(ji,jj+1) ) * z2dtr * bmask(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_spg_north
+
+
+   SUBROUTINE obc_spg_south ( kt )
+      !!------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE obc_spg_south  ***
+      !!                
+      !! ** Purpose :   Apply the radiation algorithm on south OBC stream function.
+      !!      If lfbcsouth=T, there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in) ::   kt  ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ii             ! temporary integers
+      REAL(wp) ::   &
+         z2dtr, ztau, zin   ,   &  ! temporary scalars
+         z05cx, zdt , z4nor2,   &  !    "         "
+         z2dx , z2dy               !    "         "
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcsouth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+      
+      IF( ( kt < nit000 + 3 .AND. .NOT.ln_rstart ) .OR. lfbcsouth ) THEN
+
+         ! 1.1 Fixed barotropic stream function
+         ! ------------------------------------
+         DO ji = nis0m1, nis1 
+            ii = ji -1 + nimpp 
+            bsfsob(ji)=bfos(ii)
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcsouth is .FALSE.
+      ! -----------------------------------------------------
+
+         ! 2.1. Barotropic stream function radiation
+         ! -----------------------------------------
+         !
+         !           ji-row
+         !             |
+         ! nibm2  -----f------  jpjsob + 2
+         !             |    
+         !   nibm  --  u  ----- jpjsob + 2
+         !             |        
+         !  nibm  -----f-----   jpjsob + 1
+         !             |        
+         !    nib  --  u  ----- jpjsob + 1
+         !             |        
+         !    nib -----f-----   jpjsob
+         !        ///////////     
+         !        ///////////
+         !
+         ! ... radiative conditions plus restoring term toward climatology
+         ! ... z05cx is always the cross boundary phase velocity
+         ! ... Initialize bsfsob to clim in any case, at the first step
+         !     to ensure proper values at the ends of the open line.
+         ! ... Take care that the i indices starts at nis0 (jpisd) and finish
+         ! ... at nis1 (jpisf) to be sure that jpisfm1 and jpisf are set OK.
+         DO jj = fs_njs0+1, fs_njs1+1 ! Vector opt.
+            DO ji = nis0p1, nis1m2
+               ii = ji -1 + nimpp
+         ! ... 2* gradj(bsf) (u-point i=nibm, time mean)
+               z2dx = ( - bsbnd(ji,nibm ,nit) - bsbnd(ji,nibm ,nitm2) + 2.*bsbnd(ji,nibm2,nitm) ) &
+                      / e2u(ji,jj+1)
+         ! ... 2* gradi(bsf) (f-point i=nibm, time nitm)
+               z2dy = ( bsbnd(ji+1,nibm,nitm) - bsbnd(ji-1,nibm,nitm) ) / e1f(ji,jj)
+         ! ... square of the norm of grad(bsf)
+               z4nor2 = z2dx * z2dx + z2dy * z2dy
+         ! ... minus time derivative (leap-frog) at nibm, without / 2 dt
+               zdt = bsbnd(ji,nibm,nitm2) - bsbnd(ji,nibm,nit)
+         ! ... j-phase speed ratio (bounded by -1) and MASKED!
+               IF( z4nor2 == 0 ) THEN
+                  IF(lwp) WRITE(numout,*)' PB dans obc_spg_south au pt ',ji,' : z4nor =0'
+               ENDIF
+               z05cx = zdt * z2dx / z4nor2 * bmask(ji,jj)
+               z05cx = z05cx / e2u(ji,jj)
+               z05cx = max( z05cx, -1. )
+         ! ... z05cx => 0, inflow  zin=0, ztau=1
+         !           <  0, outflow zin=1, ztau=rtaus
+               zin = sign( 1., -1. * z05cx )
+               zin = 0.5*( zin + abs(zin) )
+               ztau = (1.-zin ) *rtausin  + zin * rtaus
+               z05cx = z05cx * zin
+         ! ... update bsfn with radiative or climatological bsf (not mask!)
+               bsfsob(ji) = ( ( 1. + z05cx - ztau ) * bsbnd(ji,nib ,nitm) - 2.*z05cx  & 
+                               * bsbnd(ji,nibm,nit) + ztau * bfos (ii) )              &
+                            / (1. - z05cx)
+            END DO
+         END DO
+
+      ENDIF
+      IF( lk_mpp )   CALL mppobc(bsfsob,jpisd,jpisf,jpjsob+1,1,1,jpi)
+
+ 
+      ! 3. right hand side of the barotropic elliptic equation
+      ! -------------------------------------------------------
+
+      IF( ( neuler == 0 ) .AND. ( kt == nit000 ) ) THEN
+         z2dtr = 1.0 / rdt
+      ELSE
+         z2dtr = 0.5 / rdt
+      ENDIF
+      DO jj = fs_njs0+1, fs_njs1+1 ! Vector opt.
+         DO ji = nis0m1, nis1 
+            gcbob(ji,jj) = gcbob(ji,jj) - hur(ji,jj) * e1u(ji,jj) / e2u(ji,jj) &
+                           * ( bsfsob(ji) - bsfb(ji,jj-1) ) * z2dtr * bmask(ji,jj)
+         END DO
+      END DO
+
+   END SUBROUTINE obc_spg_south
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_spg( kt )        ! Empty routine
+      INTEGER, INTENT( in ) :: kt
+      WRITE(*,*) 'obc_spg: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_spg
+#endif
+
+   !!======================================================================
+END MODULE obcspg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obctra.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obctra.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obctra.F90	(revision 4536)
@@ -0,0 +1,523 @@
+MODULE obctra
+   !!=================================================================================
+   !!                       ***  MODULE  obctra  ***
+   !! Ocean tracers:   Radiation of tracers on each open boundary
+   !!=================================================================================
+#if defined key_obc
+   !!---------------------------------------------------------------------------------
+   !!   'key_obc'      :                                      Open Boundary Conditions
+   !!---------------------------------------------------------------------------------
+   !!   obc_tra        : call the subroutine for each open boundary
+   !!   obc_tra_east   : radiation of the east open boundary tracers
+   !!   obc_tra_west   : radiation of the west open boundary tracers
+   !!   obc_tra_north  : radiation of the north open boundary tracers
+   !!   obc_tra_south  : radiation of the south open boundary tracers
+   !!----------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! ???
+   USE lbclnk          ! ???
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_tra     ! routine called in tranxt.F90 
+
+   !! * Module variables
+   INTEGER ::      & ! ... boundary space indices 
+      nib   = 1,   & ! nib   = boundary point
+      nibm  = 2,   & ! nibm  = 1st interior point
+      nibm2 = 3,   & ! nibm2 = 2nd interior point
+                     ! ... boundary time indices 
+      nit   = 1,   & ! nit    = now
+      nitm  = 2,   & ! nitm   = before
+      nitm2 = 3      ! nitm2  = before-before
+
+   REAL(wp) ::     &
+      rtaue  , rtauw  , rtaun  , rtaus  ,  &  ! Boundary restoring coefficient
+      rtauein, rtauwin, rtaunin, rtausin      ! Boundary restoring coefficient for inflow 
+
+   !! * Substitutions
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_tra( kt )
+      !!-------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra  ***
+      !!                    
+      !! ** Purpose :   Compute tracer fields (t,s) along the open boundaries.
+      !!      This routine is called by the tranxt.F routine and updates ta,sa
+      !!      which are the actual temperature and salinity fields.
+      !!        The logical variable lp_obc_east, and/or lp_obc_west, and/or lp_obc_north,
+      !!      and/or lp_obc_south allow the user to determine which boundary is an
+      !!      open one (must be done in the param_obc.h90 file).
+      !!
+      !! Reference : 
+      !!   Marchesiello P., 1995, these de l'universite J. Fourier, Grenoble, France.
+      !!
+      !!  History :
+      !!        !  95-03 (J.-M. Molines) Original, SPEM
+      !!        !  97-07 (G. Madec, J.-M. Molines) addition
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+      !!----------------------------------------------------------------------
+
+      ! 0. Local constant initialization
+
+      IF( kt == nit000 .OR. ln_rstart) THEN
+         ! ... Boundary restoring coefficient
+         rtaue = 2. * rdt / rdpeob
+         rtauw = 2. * rdt / rdpwob
+         rtaun = 2. * rdt / rdpnob
+         rtaus = 2. * rdt / rdpsob
+         ! ... Boundary restoring coefficient for inflow ( all boundaries)
+         rtauein = 2. * rdt / rdpein 
+         rtauwin = 2. * rdt / rdpwin
+         rtaunin = 2. * rdt / rdpnin
+         rtausin = 2. * rdt / rdpsin 
+      END IF
+
+      IF( lp_obc_east  )   CALL obc_tra_east ( kt )    ! East open boundary
+
+      IF( lp_obc_west  )   CALL obc_tra_west ( kt )    ! West open boundary
+
+      IF( lp_obc_north )   CALL obc_tra_north( kt )    ! North open boundary
+
+      IF( lp_obc_south )   CALL obc_tra_south( kt )    ! South open boundary
+
+      IF( lk_mpp ) THEN                  !!bug ???
+         IF( kt >= nit000+3 .AND. ln_rstart ) THEN
+            CALL lbc_lnk( tb, 'T', 1. )
+            CALL lbc_lnk( sb, 'T', 1. )
+         END IF
+         CALL lbc_lnk( ta, 'T', 1. )
+         CALL lbc_lnk( sa, 'T', 1. )
+      ENDIF
+
+   END SUBROUTINE obc_tra
+
+
+   SUBROUTINE obc_tra_east ( kt )
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_tra_east  ***
+      !!                  
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on east OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_east subroutine in obcrad.F90 module
+      !!      If the logical lfbceast is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbceast is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbceast ) THEN
+         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - temsk(jj,jk)) + &
+                                 tfoe(jj,jk)*temsk(jj,jk)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - temsk(jj,jk)) + &
+                                 sfoe(jj,jk)*temsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbceast is .FALSE.
+      ! -----------------------------------------------------
+
+         ! Temperature and salinity radiation
+         ! ----------------------------------
+         !
+         !            nibm2      nibm      nib
+         !              |   nibm  |   nib///|///
+         !              |    |    |    |////|///
+         !  jj   line --v----f----v----f----v---
+         !              |    |    |    |////|///
+         !                   |         |///   //
+         !  jj   line   T    u    T    u/// T //
+         !                   |         |///   //
+         !              |    |    |    |////|///
+         !  jj-1 line --v----f----v----f----v---
+         !              |    |    |    |////|///
+         !                jpieob-1    jpieob / ///
+         !              |         |         |
+         !           jpieob-1    jpieob     jpieob+1
+         !
+         ! ... radiative conditions + relaxation toward a climatology
+         !     the phase velocity is taken as the phase velocity of the tangen-
+         !     tial velocity (here vn), which have been saved in (u_cxebnd,v_cxebnd)
+         ! ... (jpjedp1, jpjefm1), jpieob+1
+         DO ji = fs_nie0+1, fs_nie1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... i-phase speed ratio (from averaged of v_cxebnd)
+                  z05cx = ( 0.5 * ( v_cxebnd(jj,jk) + v_cxebnd(jj-1,jk) ) ) / e1t(ji-1,jj)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaue
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtauein is used for relaxation coefficient else rtaue
+                  ztau = (1.-zin ) * rtauein  + zin * rtaue
+                  z05cx = z05cx * zin
+         ! ... update ( ta, sa ) with radiative or climatological (t, s)
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - temsk(jj,jk)) +           & 
+                                 temsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * tebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
+                                 * tebnd(jj,jk,nibm,nit ) + ztau * tfoe (jj,jk) ) &
+                                 / (1. + z05cx)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - temsk(jj,jk)) +           & 
+                                 temsk(jj,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * sebnd(jj,jk,nib ,nitm) + 2.*z05cx              &
+                                 * sebnd(jj,jk,nibm,nit ) + ztau * sfoe (jj,jk) ) &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_tra_east
+
+
+   SUBROUTINE obc_tra_west ( kt )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra_west  ***
+      !!           
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on west OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_west subroutine in obcrad.F90 module
+      !!      If the logical lfbcwest is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcwest is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcwest ) THEN
+
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - twmsk(jj,jk)) + &
+                                 tfow(jj,jk)*twmsk(jj,jk)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - twmsk(jj,jk)) + &
+                                 sfow(jj,jk)*twmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcwest is .FALSE.
+      ! -----------------------------------------------------
+          
+         ! Temperature and salinity radiation
+         ! ----------------------------------
+         !
+         !          nib       nibm     nibm2
+         !     nib///|   nibm  |  nibm2  |
+         !   ///|////|    |    |    |    |   
+         !   ---v----f----v----f----v----f-- jj   line
+         !   ///|////|    |    |    |    |   
+         !   //   ///|         |         |   
+         !   // T ///u    T    u    T    u   jj   line
+         !   //   ///|         |         |   
+         !   ///|////|    |    |    |    |   
+         !   ---v----f----v----f----v----f-- jj-1 line
+         !   ///|////|    |    |    |    |   
+         !         jpiwob    jpiwob+1    jpiwob+2
+         !      |         |         |        
+         !    jpiwob    jpiwob+1   jpiwob+2
+         !
+         ! ... radiative conditions + relaxation toward a climatology
+         ! ... the phase velocity is taken as the phase velocity of the tangen-
+         ! ... tial velocity (here vn), which have been saved in (v_cxwbnd)
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+         ! ... i-phase speed ratio (from averaged of v_cxwbnd)
+                  z05cx = (  0.5 * ( v_cxwbnd(jj,jk) + v_cxwbnd(jj-1,jk) ) ) / e1t(ji+1,jj)
+                  z05cx = max( z05cx, -1. )
+         ! ... z05cx > 0, inflow  zin=0, ztau=1    
+         !           < 0, outflow zin=1, ztau=rtauw
+                  zin = sign( 1., -1.* z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin )*rtauwin + zin * rtauw
+                  z05cx = z05cx * zin
+         ! ... update (ta,sa) with radiative or climatological (t, s)
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1. - twmsk(jj,jk)) +           &
+                                 twmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
+                                 * twbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
+                                 * twbnd(jj,jk,nibm,nit ) + ztau * tfow (jj,jk) ) &
+                                 / (1. - z05cx)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1. - twmsk(jj,jk)) +           &
+                                 twmsk(jj,jk) * ( ( 1. + z05cx - ztau )         &
+                                 * swbnd(jj,jk,nib ,nitm) - 2.*z05cx              &
+                                 * swbnd(jj,jk,nibm,nit ) + ztau * sfow (jj,jk) ) &
+                                 / (1. - z05cx)
+               END DO
+            END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_tra_west
+
+
+   SUBROUTINE obc_tra_north ( kt )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE obc_tra_north  ***
+      !!
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on north OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_north subroutine in obcrad.F90 module
+      !!      If the logical lfbcnorth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M. Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcnorth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcnorth ) THEN
+
+         DO jj = fs_njn0+1, fs_njn1+1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta(ji,jj,jk)= ta(ji,jj,jk) * (1.-tnmsk(ji,jk)) + &
+                                tnmsk(ji,jk) * tfon(ji,jk)
+                  sa(ji,jj,jk)= sa(ji,jj,jk) * (1.-tnmsk(ji,jk)) + &
+                                tnmsk(ji,jk) * sfon(ji,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcnorth is .FALSE.
+      ! -------------------------------------------------------
+          
+         ! Temperature and salinity radiation
+         ! ----------------------------------
+         !
+         !           ji-1   ji   ji   ji +1
+         !             |
+         !    nib //// u // T // u // T //   jpjnob + 1
+         !        /////|//////////////////
+         !    nib  ----f----v----f----v---   jpjnob
+         !             |         |       
+         !      nibm-- u -- T -- u -- T --   jpjnob
+         !             |         |            
+         !   nibm  ----f----v----f----v---  jpjnob-1
+         !             |         |      
+         !     nibm2-- u -- T -- T -- T --  jpjnob-1
+         !             |         |    
+         !   nibm2 ----f----v----f----v---  jpjnob-2
+         !             |         |
+         !
+         ! ... radiative conditions + relaxation toward a climatology
+         ! ... the phase velocity is taken as the normal phase velocity of the tangen-
+         ! ... tial velocity (here un), which has been saved in (u_cynbnd)
+         ! ... jpjnob+1,(jpindp1, jpinfm1)
+         DO jj = fs_njn0+1, fs_njn1+1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         ! ... j-phase speed ratio (from averaged of vtnbnd)
+         !        (bounded by 1)
+                  z05cx = ( 0.5 * ( u_cynbnd(ji,jk) + u_cynbnd(ji-1,jk) ) ) / e2t(ji,jj-1)
+                  z05cx = min( z05cx, 1. )
+         ! ... z05cx=< 0, inflow  zin=0, ztau=1    
+         !           > 0, outflow zin=1, ztau=rtaun
+                  zin = sign( 1., z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+         ! ... for inflow rtaunin is used for relaxation coefficient else rtaun
+                  ztau = (1.-zin ) * rtaunin + zin * rtaun
+                  z05cx = z05cx * zin
+         ! ... update (ta,sa) with radiative or climatological (t, s)
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1.-tnmsk(ji,jk)) +             &
+                                 tnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * tnbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
+                                 * tnbnd(ji,jk,nibm,nit ) + ztau * tfon (ji,jk) ) &
+                                 / (1. + z05cx)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1.-tnmsk(ji,jk)) +             &
+                                 tnmsk(ji,jk) * ( ( 1. - z05cx - ztau )         &
+                                 * snbnd(ji,jk,nib ,nitm) + 2.*z05cx              &
+                                 * snbnd(ji,jk,nibm,nit ) + ztau * sfon (ji,jk) ) &
+                                 / (1. + z05cx)
+               END DO
+            END DO
+         END DO
+
+      END IF
+
+   END SUBROUTINE obc_tra_north
+
+
+   SUBROUTINE obc_tra_south ( kt )
+      !!------------------------------------------------------------------------------
+      !!                ***  SUBROUTINE obc_tra_south  ***
+      !!     
+      !! ** Purpose :
+      !!      Apply the radiation algorithm on south OBC tracers ta, sa using the 
+      !!      phase velocities calculated in obc_rad_south subroutine in obcrad.F90 module
+      !!      If the logical lfbcsouth is .TRUE., there is no radiation but only fixed OBC
+      !!
+      !!  History :
+      !!         ! 95-03 (J.-M. Molines) Original from SPEM
+      !!         ! 97-07 (G. Madec, J.-M. Molines) additions
+      !!         ! 97-12 (M. Imbard) Mpp adaptation
+      !!         ! 00-06 (J.-M. Molines) 
+      !!    8.5  ! 02-10 (C. Talandier, A-M Treguier) F90
+      !!------------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt
+
+      !! * Local declaration
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   z05cx, ztau, zin
+      !!------------------------------------------------------------------------------
+
+      ! 1. First three time steps and more if lfbcsouth is .TRUE.
+      !    In that case open boundary conditions are FIXED.
+      ! --------------------------------------------------------
+
+      IF( ( kt < nit000+3 .AND. .NOT.ln_rstart ) .OR. lfbcsouth ) THEN
+
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  ta(ji,jj,jk)= ta(ji,jj,jk) * (1.-tsmsk(ji,jk)) + &
+                                tsmsk(ji,jk) * tfos(ji,jk)
+                  sa(ji,jj,jk)= sa(ji,jj,jk) * (1.-tsmsk(ji,jk)) + &
+                                tsmsk(ji,jk) * sfos(ji,jk)
+               END DO
+            END DO
+         END DO
+
+      ELSE
+
+      ! 2. Beyond the fourth time step if lfbcsouth is .FALSE.
+      ! -------------------------------------------------------
+          
+         ! Temperature and salinity radiation
+         ! ----------------------------------
+         !
+         !           ji-1   ji   ji   ji +1
+         !             |         |
+         !   nibm2 ----f----v----f----v---   jpjsob+2
+         !             |         |       
+         !   nibm2 --  u -- T -- u -- T --   jpjsob+2
+         !             |         |            
+         !   nibm  ----f----v----f----v---   jpjsob+1
+         !             |         |      
+         !    nibm --  u -- T -- T -- T --   jpjsob+1
+         !             |         |    
+         !   nib  -----f----v----f----v---   jpjsob
+         !       //////|/////////|//////// 
+         !    nib //// u // T // u // T //   jpjsob 
+         !
+         !... radiative conditions + relaxation toward a climatology
+         !... the phase velocity is taken as the phase velocity of the tangen-
+         !... tial velocity (here un), which has been saved in (u_cysbnd)
+         !... jpjsob,(jpisdp1, jpisfm1)
+         DO jj = fs_njs0, fs_njs1  ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+         !... j-phase speed ratio (from averaged of u_cysbnd)
+         !       (bounded by 1)
+                  z05cx = ( 0.5 * ( u_cysbnd(ji,jk) + u_cysbnd(ji-1,jk) ) ) / e2t(ji,jj+1)
+                  z05cx = max( z05cx, -1. )
+         !... z05cx > 0, inflow  zin=0, ztau=1
+         !          < 0, outflow zin=1, ztau=rtaus
+                  zin = sign( 1., -1.* z05cx )
+                  zin = 0.5*( zin + abs(zin) )
+                  ztau = (1.-zin ) + zin * rtaus
+                  z05cx = z05cx * zin
+         !... update (ta,sa) with radiative or climatological (t, s)
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * (1.-tsmsk(ji,jk)) +             &
+                                 tsmsk(ji,jk) * ( ( 1. + z05cx - ztau )         &
+                                 * tsbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
+                                 * tsbnd(ji,jk,nibm,nit ) + ztau * tfos (ji,jk) ) &
+                                 / (1. - z05cx)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * (1.-tsmsk(ji,jk)) +             &
+                                 tsmsk(ji,jk) * (  ( 1. + z05cx - ztau )        &
+                                 * ssbnd(ji,jk,nib ,nitm) - 2.*z05cx              &
+                                 * ssbnd(ji,jk,nibm,nit ) + ztau * sfos (ji,jk) ) &
+                                 / (1. - z05cx)
+               END DO
+            END DO
+         END DO
+
+      END IF   
+
+   END SUBROUTINE obc_tra_south
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_tra      ! Empty routine
+   END SUBROUTINE obc_tra
+#endif
+
+   !!=================================================================================
+END MODULE obctra
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcvol.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcvol.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/OBC/obcvol.F90	(revision 4536)
@@ -0,0 +1,288 @@
+MODULE obcvol
+   !!=================================================================================
+   !!                       ***  MODULE  obcvol  ***
+   !! Ocean dynamic :  Volume constraint when OBC and Free surface are used
+   !!=================================================================================
+#if   defined key_obc   &&   ! defined key_dynspg_rl
+   !!---------------------------------------------------------------------------------
+   !!   'key_obc'               and                           open boundary conditions
+   !!   'key_dynspg_flt'                                  constant volume free surface
+   !!---------------------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lib_mpp         ! for mppsum
+   USE in_out_manager  ! I/O manager
+   USE ocesbc          ! ocean surface boundary conditions
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC obc_vol        ! routine called by dynspg_flt
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "obc_vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE obc_vol ( kt )
+      !!------------------------------------------------------------------------------
+      !!                      ***  ROUTINE obcvol  ***
+      !!
+      !! ** Purpose : 
+      !!      This routine is called in dynspg_flt to control 
+      !!      the volume of the system. A correction velocity is calculated
+      !!      to correct the total transport through the OBC. 
+      !!      The total depth used is constant (H0) to be consistent with the 
+      !!      linear free surface coded in OPA 8.2
+      !!
+      !! ** Method :  
+      !!      The correction velocity (zubtpecor here) is defined calculating
+      !!      the total transport through all open boundaries (trans_obc) minus
+      !!      the cumulate E-P flux (zCflxemp) divided by the total lateral 
+      !!      surface (obcsurftot) of these OBC. 
+      !!
+      !!      zubtpecor = [trans_obc - zCflxemp ]*(1./obcsurftot)
+      !!
+      !!      with zCflxemp => sum of (Evaporation minus Precipitation)
+      !!                       over all the domain in m3/s at each time step.
+      !!
+      !!      zCflxemp < 0 when precipitation dominate
+      !!      zCflxemp > 0 when evaporation dominate
+      !!
+      !!      There are 2 options (user's desiderata): 
+      !!
+      !!         1/ The volume changes according to E-P, this is the default
+      !!            option. In this case the cumulate E-P flux are setting to
+      !!            zero (zCflxemp=0) to calculate the correction velocity. So
+      !!            it will only balance the flux through open boundaries.
+      !!            (set volemp to 0 in tne namelist for this option)
+      !!
+      !!         2/ The volume is constant even with E-P flux. In this case
+      !!            the correction velocity must balance both the flux 
+      !!            through open boundaries and the ones through the free
+      !!            surface. 
+      !!            (set volemp to 1 in tne namelist for this option)
+      !!
+      !! History :
+      !!   8.5  !  02-10 (C. Talandier, A-M. Treguier) Original code
+      !!----------------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk
+      REAL(wp) ::   zubtpecor
+      REAL(wp) ::   zCflxemp
+      REAL(wp) ::   ztransw, ztranse, ztransn, ztranss, ztranst
+      !!-----------------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN 
+         IF(lwp) WRITE(numout,*)'        '
+         IF(lwp) WRITE(numout,*)'obc_vol : Correction of velocities along OBC'
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+         IF(lwp) WRITE(numout,*)'        '
+      END IF 
+
+      ! 1. Calculate the cumulate surface Flux zCflxemp (m3/s) over all the domain.
+      ! ---------------------------------------------------------------------------
+ 
+      zCflxemp = 0.e0
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zCflxemp = zCflxemp + ( (emp(ji,jj)*obctmsk(ji,jj) )/rauw)*e1v(ji,jj)*e2u(ji,jj)
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zCflxemp )   ! sum over the global domain
+
+      ! 2. Barotropic velocity for each open boundary
+      ! ---------------------------------------------
+
+      zubtpecor = 0.e0
+
+      ! ... West open boundary
+      IF( lp_obc_west ) THEN                      ! ... Total transport through the West OBC
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  zubtpecor = zubtpecor + ua(ji,jj,jk)*e2u(ji,jj)*fse3u(ji,jj,jk) * uwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+      END IF 
+
+      ! ... East open boundary
+      IF( lp_obc_east ) THEN                      ! ... Total transport through the East OBC
+         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  zubtpecor = zubtpecor - ua(ji,jj,jk)*e2u(ji,jj)*fse3u(ji,jj,jk) * uemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+      END IF 
+
+      ! ... North open boundary
+      IF( lp_obc_north ) THEN                     ! ... Total transport through the North OBC
+         DO jj = fs_njn0, fs_njn1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zubtpecor = zubtpecor - va(ji,jj,jk)*e1v(ji,jj)*fse3v(ji,jj,jk) * vnmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+      END IF 
+
+      ! ... South open boundary
+      IF( lp_obc_south ) THEN                     ! ... Total transport through the South OBC
+         DO jj = fs_njs0, fs_njs1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zubtpecor = zubtpecor + va(ji,jj,jk)*e1v(ji,jj)*fse3v(ji,jj,jk) * vsmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+      END IF 
+
+      IF( lk_mpp )   CALL mpp_sum( zubtpecor )   ! sum over the global domain
+
+
+      ! 3. The normal velocity correction
+      ! ---------------------------------
+
+      zubtpecor = (zubtpecor - zCflxemp*volemp)*(1./obcsurftot)
+
+      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+         IF(lwp) WRITE(numout,*)'        '
+         IF(lwp) WRITE(numout,*)'obc_vol : time step :', kt
+         IF(lwp) WRITE(numout,*)'~~~~~~~ '
+         IF(lwp) WRITE(numout,*)'        '
+         IF(lwp) WRITE(numout,*)'          cumulate flux EMP :', zCflxemp,' (m3/s)'
+         IF(lwp) WRITE(numout,*)'          total lateral surface of OBC :',obcsurftot,'(m2)'
+         IF(lwp) WRITE(numout,*)'          correction velocity zubtpecor :',zubtpecor,'(m/s)'
+         IF(lwp) WRITE(numout,*)'        '
+      END IF 
+
+      ! 4. Correction of the total velocity on each open 
+      !    boundary torespect the mass flux conservation
+      ! -------------------------------------------------
+
+      ztransw = 0.e0
+      ztranse = 0.e0
+      ztransn = 0.e0
+      ztranss = 0.e0
+      ztranst = 0.e0
+
+      IF( lp_obc_west ) THEN
+
+         ! ... correction of the west velocity
+         DO ji = fs_niw0, fs_niw1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua(ji,jj,jk) = ua(ji,jj,jk) - zubtpecor*uwmsk(jj,jk)
+                  ztransw= ztransw + ua(ji,jj,jk)*fse3u(ji,jj,jk)*e2u(ji,jj)*uwmsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+         IF( lk_mpp )   CALL mpp_sum( ztransw )   ! sum over the global domain
+
+         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+            IF(lwp) WRITE(numout,*)'          West OB transport ztransw :', ztransw,'(m3/s)'
+         END IF 
+
+      END IF 
+
+      IF( lp_obc_east ) THEN
+
+         ! ... correction of the east velocity
+         DO ji = fs_nie0, fs_nie1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + zubtpecor*uemsk(jj,jk)
+                  ztranse= ztranse + ua(ji,jj,jk)*fse3u(ji,jj,jk)*e2u(ji,jj)*uemsk(jj,jk)
+               END DO
+            END DO
+         END DO
+
+         IF( lk_mpp )   CALL mpp_sum( ztranse )   ! sum over the global domain
+
+         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+            IF(lwp) WRITE(numout,*)'          East OB transport ztranse :', ztranse,'(m3/s)'
+         END IF 
+
+      END IF 
+
+      IF( lp_obc_north ) THEN
+
+         ! ... correction of the north velocity
+         DO jj = fs_njn0, fs_njn1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji =  1, jpi
+                  va(ji,jj,jk) = va(ji,jj,jk) + zubtpecor*vnmsk(ji,jk)
+                  ztransn= ztransn + va(ji,jj,jk)*fse3v(ji,jj,jk)*e1v(ji,jj)*vnmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztransn )   ! sum over the global domain
+
+         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+            IF(lwp) WRITE(numout,*)'          North OB transport ztransn :', ztransn,'(m3/s)'
+         END IF 
+
+      END IF 
+
+      IF( lp_obc_south ) THEN
+
+         ! ... correction of the south velocity
+         DO jj = fs_njs0, fs_njs1 ! Vector opt.
+            DO jk = 1, jpkm1
+               DO ji =  1, jpi
+                  va(ji,jj,jk) = va(ji,jj,jk) - zubtpecor*vsmsk(ji,jk)
+                  ztranss= ztranss + va(ji,jj,jk)*fse3v(ji,jj,jk)*e1v(ji,jj)*vsmsk(ji,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztranss )   ! sum over the global domain
+
+         IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+            IF(lwp) WRITE(numout,*)'          South OB transport ztranss :', ztranss,'(m3/s)'
+         END IF 
+
+      END IF 
+
+      ! 5. Check the cumulate transport through OBC
+      !    once barotropic velocities corrected
+      ! -------------------------------------------
+
+      ztranst = ztransw - ztranse + ztranss - ztransn
+
+      IF( lwp .AND. MOD( kt, nwrite ) == 0) THEN
+         IF(lwp) WRITE(numout,*)'        '
+         IF(lwp) WRITE(numout,*)'          Cumulate transport ztranst =', ztranst,'(m3/s)'
+         IF(lwp) WRITE(numout,*)'        '
+      END IF 
+
+   END SUBROUTINE obc_vol
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!  Default option :                                                   Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE obc_vol        ! Empty routine
+   END SUBROUTINE obc_vol
+#endif
+
+   !!=================================================================================
+END MODULE obcvol
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/albedo.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/albedo.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/albedo.F90	(revision 4536)
@@ -0,0 +1,278 @@
+MODULE albedo
+   !!======================================================================
+   !!                       ***  MODULE  albedo  ***
+   !! Ocean forcing:  bulk thermohaline forcing of the ocean (or ice)
+   !!=====================================================================
+   !!----------------------------------------------------------------------
+   !!   flx_blk_albedo : albedo for ocean and ice (clear and overcast skies)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE cpl_oce         ! ???
+   USE phycst          ! physical constants
+   USE daymod
+   USE blk_oce         ! bulk variables
+   USE flx_oce         ! forcings variables
+   USE ocfzpt          ! ???
+   USE in_out_manager
+   USE lbclnk
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC flx_blk_albedo ! routine called by limflx.F90 in coupled
+                         ! and in flxblk.F90 in forced
+   !! * Module variables
+   INTEGER  ::             &  !: nameos : ocean physical parameters
+      albd_init = 0           !: control flag for initialization
+
+   REAL(wp)  ::            &  ! constant values
+      zzero   = 0.e0    ,  &
+      zone    = 1.0
+
+   !! * constants for albedo computation (flx_blk_albedo)
+   REAL(wp) ::   &
+      c1     = 0.05  ,     &   ! constants values
+      c2     = 0.10  ,     &
+      albice = 0.50  ,     &   !  albedo of melting ice in the arctic and antarctic (Shine & Hendersson-Sellers)
+      cgren  = 0.06  ,     &   !  correction of the snow or ice albedo to take into account
+                               !  effects of cloudiness (Grenfell & Perovich, 1984)
+      alphd  = 0.80  ,     &   !  coefficients for linear interpolation used to compute
+      alphdi = 0.72  ,     &   !  albedo between two extremes values (Pyane, 1972)
+      alphc  = 0.65  ,     &
+      zmue   = 0.40            !  cosine of local solar altitude
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'                                         LIM ice model
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE flx_blk_albedo( palb , palcn , palbp , palcnp )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE flx_blk_albedo  ***
+      !!          
+      !! ** Purpose :   Computation of the albedo of the snow/ice system 
+      !!      as well as the ocean one
+      !!       
+      !! ** Method  : - Computation of the albedo of snow or ice (choose the 
+      !!      rignt one by a large number of tests
+      !!              - Computation of the albedo of the ocean
+      !!
+      !! References :
+      !!      Shine and Hendersson-Sellers 1985, JGR, 90(D1), 2243-2250.
+      !!
+      !! History :
+      !!  8.0   !  01-04  (LIM 1.0)
+      !!  8.5   !  03-07  (C. Ethe, G. Madec)  Optimization (old name:shine)
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ice                   ! ???
+
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::  &
+         palb         ,     &    !  albedo of ice under overcast sky
+         palcn        ,     &    !  albedo of ocean under overcast sky
+         palbp        ,     &    !  albedo of ice under clear sky 
+         palcnp                  !  albedo of ocean under clear sky
+
+      !! * Local variables
+      INTEGER ::    &
+         ji, jj                   ! dummy loop indices
+      REAL(wp) ::   & 
+         zmue14         ,     &   !  zmue**1.4
+         zalbpsnm       ,     &   !  albedo of ice under clear sky when snow is melting
+         zalbpsnf       ,     &   !  albedo of ice under clear sky when snow is freezing
+         zalbpsn        ,     &   !  albedo of snow/ice system when ice is coverd by snow
+         zalbpic        ,     &   !  albedo of snow/ice system when ice is free of snow
+         zithsn         ,     &   !  = 1 for hsn >= 0 ( ice is cov. by snow ) ; = 0 otherwise (ice is free of snow)
+         zitmlsn        ,     &   !  = 1 freezinz snow (sist >=rt0_snow) ; = 0 melting snow (sist<rt0_snow)
+         zihsc1         ,     &   !  = 1 hsn <= c1 ; = 0 hsn > c1
+         zihsc2                   !  = 1 hsn >= c2 ; = 0 hsn < c2
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zalbfz         ,     &   !  ( = alphdi for freezing ice ; = albice for melting ice )
+         zficeth                  !  function of ice thickness
+      LOGICAL , DIMENSION(jpi,jpj) ::  &
+         llmask
+      !!---------------------------------------------------------------------
+      
+      ! initialization 
+      IF( albd_init == 0 )   CALL albedo_init
+
+      !-------------------------                                                             
+      !  Computation of  zficeth
+      !-------------------------- 
+      
+      llmask = (hsnif == 0.e0) .AND. ( sist >= rt0_ice )
+      WHERE ( llmask )   !  ice free of snow and melts
+         zalbfz = albice
+      ELSEWHERE                   
+         zalbfz = alphdi
+      END WHERE
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( hicif(ji,jj) > 1.5 ) THEN
+               zficeth(ji,jj) = zalbfz(ji,jj)
+            ELSEIF( hicif(ji,jj) > 1.0  .AND. hicif(ji,jj) <= 1.5 ) THEN
+               zficeth(ji,jj) = 0.472 + 2.0 * ( zalbfz(ji,jj) - 0.472 ) * ( hicif(ji,jj) - 1.0 )
+            ELSEIF( hicif(ji,jj) > 0.05 .AND. hicif(ji,jj) <= 1.0 ) THEN
+               zficeth(ji,jj) = 0.2467 + 0.7049 * hicif(ji,jj)                                &
+                  &                    - 0.8608 * hicif(ji,jj) * hicif(ji,jj)                 &
+                  &                    + 0.3812 * hicif(ji,jj) * hicif(ji,jj) * hicif (ji,jj)
+            ELSE
+               zficeth(ji,jj) = 0.1 + 3.6 * hicif(ji,jj) 
+            ENDIF
+         END DO
+      END DO
+      
+      !----------------------------------------------- 
+      !    Computation of the snow/ice albedo system 
+      !-------------------------- ---------------------
+      
+      !    Albedo of snow-ice for clear sky.
+      !-----------------------------------------------    
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            !  Case of ice covered by snow.             
+            
+            !  melting snow        
+            zihsc1       = 1.0 - MAX ( zzero , SIGN ( zone , - ( hsnif(ji,jj) - c1 ) ) )
+            zalbpsnm     = ( 1.0 - zihsc1 ) * ( zficeth(ji,jj) + hsnif(ji,jj) * ( alphd - zficeth(ji,jj) ) / c1 ) &
+               &                 + zihsc1   * alphd  
+            !  freezing snow                
+            zihsc2       = MAX ( zzero , SIGN ( zone , hsnif(ji,jj) - c2 ) )
+            zalbpsnf     = ( 1.0 - zihsc2 ) * ( albice + hsnif(ji,jj) * ( alphc - albice ) / c2 )                 &
+               &                 + zihsc2   * alphc 
+            
+            zitmlsn      =  MAX ( zzero , SIGN ( zone , sist(ji,jj) - rt0_snow ) )   
+            zalbpsn      =  zitmlsn * zalbpsnf + ( 1.0 - zitmlsn ) * zalbpsnm 
+            
+            !  Case of ice free of snow.
+            zalbpic      = zficeth(ji,jj) 
+            
+            ! albedo of the system   
+            zithsn       = 1.0 - MAX ( zzero , SIGN ( zone , - hsnif(ji,jj) ) )
+            palbp(ji,jj) =  zithsn * zalbpsn + ( 1.0 - zithsn ) *  zalbpic
+         END DO
+      END DO
+      
+      !    Albedo of snow-ice for overcast sky.
+      !----------------------------------------------  
+      palb(:,:)   = palbp(:,:) + cgren                                           
+      
+      !--------------------------------------------
+      !    Computation of the albedo of the ocean 
+      !-------------------------- -----------------                                                          
+      
+      !  Parameterization of Briegled and Ramanathan, 1982 
+      zmue14      = zmue**1.4                                       
+      palcnp(:,:) = 0.05 / ( 1.1 * zmue14 + 0.15 )                
+      
+      !  Parameterization of Kondratyev, 1969 and Payne, 1972
+      palcn(:,:)  = 0.06                                                 
+      
+   END SUBROUTINE flx_blk_albedo
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                   NO sea-ice model
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE flx_blk_albedo( palb , palcn , palbp , palcnp )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE flx_blk_albedo  ***
+      !! 
+      !! ** Purpose :   Computation of the albedo of the snow/ice system
+      !!      as well as the ocean one
+      !!
+      !! ** Method  :   Computation of the albedo of snow or ice (choose the
+      !!      wright one by a large number of tests Computation of the albedo
+      !!      of the ocean
+      !!
+      !! History :
+      !!  8.0   !  01-04  (LIM 1.0)
+      !!  8.5   !  03-07  (C. Ethe, G. Madec)  Optimization (old name:shine)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::  &
+         palb         ,     &    !  albedo of ice under overcast sky
+         palcn        ,     &    !  albedo of ocean under overcast sky
+         palbp        ,     &    !  albedo of ice under clear sky
+         palcnp                  !  albedo of ocean under clear sky
+
+      REAL(wp) ::   &
+         zmue14                 !  zmue**1.4
+      !!----------------------------------------------------------------------
+
+      !--------------------------------------------
+      !    Computation of the albedo of the ocean
+      !-------------------------- -----------------
+
+      !  Parameterization of Briegled and Ramanathan, 1982
+      zmue14      = zmue**1.4
+      palcnp(:,:) = 0.05 / ( 1.1 * zmue14 + 0.15 )
+
+      !  Parameterization of Kondratyev, 1969 and Payne, 1972
+      palcn(:,:)  = 0.06
+
+      palb (:,:)  = palcn(:,:)
+      palbp(:,:)  = palcnp(:,:)
+
+   END SUBROUTINE flx_blk_albedo
+
+#endif
+
+   SUBROUTINE albedo_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE albedo_init  ***
+      !!
+      !! ** Purpose :   initializations for the albedo parameters
+      !!
+      !! ** Method  :   Read the namelist namalb
+      !!
+      !! ** Action  :  
+      !!
+      !!
+      !! History :
+      !!   9.0  !  04-11  (C. Talandier)  Original code
+      !!----------------------------------------------------------------------
+      NAMELIST/namalb/ cgren, albice, alphd, alphdi, alphc
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0, LODYC-IPSL (2004)
+      !!----------------------------------------------------------------------
+
+      ! set the initialization flag to 1
+      albd_init = 1           ! indicate that the initialization has been done
+
+      ! Read Namelist namalb : albedo parameters
+      REWIND( numnam )
+      READ  ( numnam, namalb )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'albedo_init : albedo '
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namalb : set albedo parameters'
+         WRITE(numout,*)
+         WRITE(numout,*) '             correction of the snow or ice albedo to take into account cgren = ', cgren
+         WRITE(numout,*) '             albedo of melting ice in the arctic and antarctic        albice = ', albice
+         WRITE(numout,*) '             coefficients for linear                                   alphd = ', alphd
+         WRITE(numout,*) '             interpolation used to compute albedo                     alphdi = ', alphdi
+         WRITE(numout,*) '             between two extremes values (Pyane, 1972)                 alphc = ', alphc
+         WRITE(numout,*)
+      ENDIF
+
+   END SUBROUTINE albedo_init
+   !!======================================================================
+END MODULE albedo
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/blk_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/blk_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/blk_oce.F90	(revision 4536)
@@ -0,0 +1,48 @@
+MODULE blk_oce
+   !!======================================================================
+   !!                 ***  MODULE  blk_oce  ***
+   !! Bulk   :  bulk parameter and  variables defined in memory 
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+   !!----------------------------------------------------------------------
+   !! ' key_flx_bulk_monthly or defined key_flx_bulk_daily             bulk
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+   
+   !!----------------------------------------------------------------------
+   !! bulk common variables
+   !!----------------------------------------------------------------------
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      watm     ,      &  !: precipitation
+      tatm     ,      &  !: atmospheric temperature
+      hatm     ,      &  !: relative humidity
+      vatm     ,      &  !: wind speed
+      catm               !: percent of cloud cover
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)    ::   &  !:
+      gsst               !: SST mean on nfbulk ocean time step
+
+   REAL(wp) ::        &
+      yearday  ,      &  !: number of days per year
+      rdtbs2             !: bulk time step divide by 2
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+#endif
+   
+   INTEGER ::         & !!: namdom : space/time domain (namlist)
+      nfbulk =  5        !: bulk computation frequency 
+   !!----------------------------------------------------------------------
+END MODULE blk_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/bulk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/bulk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/bulk.F90	(revision 4536)
@@ -0,0 +1,123 @@
+MODULE bulk
+   !!======================================================================
+   !!                           ***  bulk  ***
+   !!======================================================================
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+   !!----------------------------------------------------------------------
+   !!   'key_flx_bulk_monthly'                        monthly bulk formulea
+   !!   'key_flx_bulk_daily'                          daily bulk formulea
+   !!----------------------------------------------------------------------
+   !!   bulk          : computation of fluxes using bulk formulation
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE ice_oce         ! bulk variable  
+   USE ocfzpt          ! ocean freezing point
+   USE flxblk          ! bulk formulae
+   USE blk_oce         ! bulk variable 
+   USE flx_oce
+   USE taumod
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC blk        ! called by flx.F90   
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE blk( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE blk  ***
+      !!        
+      !! ** Purpose :   provide the heat fluxes on ice and ocean 
+      !!                using bulk formulation
+      !!
+      !! History :
+      !!   9.0  !  03-11  (C. Ethe and G. Madec)  F90: Free form and MODULE 
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations    
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsst 
+# if ! defined key_ice_lim
+      INTEGER  ::   ji, jj         ! dummy loop indices  
+      REAL(wp) ::   ztgel, zicopa
+# endif
+      !!---------------------------------------------------------------------
+
+     ! Initialisation
+     IF( kt == nit000) THEN
+      ! computation of rdtbs2
+        IF( nacc == 1 ) THEN
+           rdtbs2 = nfbulk * rdtmin * 0.5
+        ELSE
+           rdtbs2 = nfbulk * rdt * 0.5
+        ENDIF
+        IF ( .NOT.ln_rstart ) THEN
+           gsst(:,:) =  ( nfbulk - 1 ) * ( tn(:,:,1) + rt0 )
+        ENDIF
+     ENDIF
+
+# if ! defined key_ice_lim
+      ! opa model ice freeze()      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ztgel  = fzptn(ji,jj)
+            zicopa = tmask(ji,jj,1)
+            IF( tn(ji,jj,1) >= ztgel ) zicopa = 0.
+            freeze(ji,jj) = zicopa
+         END DO
+      END DO
+# endif
+
+      gsst(:,:) = gsst(:,:) + tn(:,:,1) + rt0  
+
+      !  Computation of the fluxes       
+      IF( MOD( kt - 1 , nfbulk ) == 0 ) THEN
+
+         zsst(:,:) = gsst(:,:) / REAL( nfbulk ) * tmask(:,:,1)
+         CALL flx_blk( zsst )    
+     
+         gsst(:,:) = 0.    
+
+# if ! defined key_ice_lim
+         IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+            CALL prt_ctl_info(' Forcings ')
+            CALL prt_ctl(tab2d_1=qsr_oce , clinfo1=' qsr_oce   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=qsr_ice , clinfo1=' qsr_ice   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=qnsr_oce, clinfo1=' qnsr_oce  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=qnsr_ice, clinfo1=' qnsr_ice  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=evap    , clinfo1=' evap      : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tprecip , clinfo1=' precip    : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=sprecip , clinfo1=' Snow      : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=taux    , clinfo1=' u-stress  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tauy    , clinfo1=' v-stress  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=zsst    , clinfo1=' sst       : ', mask1=tmask, ovlap=1)
+         ENDIF
+# endif   
+      ENDIF
+ 
+   END SUBROUTINE blk
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                     NO bulk formulea
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE blk( kt )          ! Dummy routine
+      WRITE(*,*) 'blk: You should not see this print! error? ', kt
+   END SUBROUTINE blk
+#endif
+ 
+   !!======================================================================
+END MODULE bulk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4536)
@@ -0,0 +1,1171 @@
+MODULE cpl_oasis3
+   !!======================================================================
+   !!                    ***  MODULE cpl_oasis  ***
+   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3 V. prism_2_4
+   !!               special case: NEMO OPA/LIM coupled to ECHAM5
+   !!=====================================================================
+   !! History :   
+   !!   9.0  !  04-06  (R. Redler, NEC CCRLE, Germany) Original code
+   !!   " "  !  04-11  (R. Redler, N. Keenlyside) revision
+   !!   " "  !  04-11  (V. Gayler, MPI M&D) Grid writing
+   !!   " "  !  05-08  (R. Redler, W. Park) frld initialization, paral(2) revision
+   !!   " "  !  05-09  (R. Redler) extended to allow for communication over root only
+   !!   " "  !  06-01  (W. Park) modification of physical part
+   !!   " "  !  06-02  (R. Redler, W. Park) buffer array fix for root exchange
+   !!----------------------------------------------------------------------
+#if defined key_oasis3
+   !!----------------------------------------------------------------------
+   !!   'key_oasis3'                    coupled Ocean/Atmosphere via OASIS3
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   cpl_prism_init     : initialization of coupled mode communication
+   !!   cpl_prism_define   : definition of grid and fields
+   !!   cpl_prism_send     : send out fields in coupled mode
+   !!   cpl_prism_recv     : receive fields in coupled mode
+   !!   cpl_prism_finalize : finalize the coupled mode communication
+   !!----------------------------------------------------------------------
+   !! * Modules used
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+!   Following lines must be enabled if coupling with OASIS
+!
+!   USE mod_prism_proto              ! OASIS3 prism module
+!   USE mod_prism_def_partition_proto! OASIS3 prism module for partitioning
+!   USE mod_prism_grids_writing      ! OASIS3 prism module for writing grid files
+!   USE mod_prism_put_proto          ! OASIS3 prism module for sending
+!   USE mod_prism_get_proto          ! OASIS3 prism module for receiving
+!   USE mod_prism_grids_writing      ! OASIS3 prism module for writing grids
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+#if defined key_mpp_mpi
+   USE lib_mpp, only : mppsize, mpprank ! message passing
+   USE lib_mpp, only : mppsend          ! message passing
+   USE lib_mpp, only : mpprecv          ! message passing
+#endif
+   USE daymod                       ! date and time info
+   USE dom_oce                      ! ocean space and time domain
+   USE in_out_manager               ! I/O manager
+   USE par_oce                      !
+   USE phycst, only : rt0           ! freezing point of sea water
+
+   USE oce, only: tn, un, vn
+   USE ice, only: frld, hicif, hsnif
+   USE flx_oce, only : alb_ice ,  & ! albedo of ice
+                       tn_ice       ! ice surface temperature
+
+   IMPLICIT NONE
+!
+! Exchange parameters for coupling ORCA-LIM with ECHAM5
+!
+#if defined key_cpl_ocevel
+   INTEGER, PARAMETER         :: nsend =  6
+#else
+   INTEGER, PARAMETER         :: nsend =  4
+#endif
+
+#if defined key_cpl_discharge
+   INTEGER, PARAMETER         :: nrecv = 20
+#else
+   INTEGER, PARAMETER         :: nrecv = 17
+#endif
+
+   INTEGER, DIMENSION(nsend)  :: send_id
+   INTEGER, DIMENSION(nrecv)  :: recv_id
+
+   CHARACTER(len=32)          :: cpl_send (nsend)
+   CHARACTER(len=32)          :: cpl_recv (nrecv)
+
+   PRIVATE
+
+   INTEGER                    :: localRank      ! local MPI rank
+   INTEGER                    :: comp_id        ! id returned by prism_init_comp
+
+   INTEGER                    :: range(5)
+
+   INTEGER, PARAMETER         :: localRoot  = 0
+   INTEGER                    :: localSize      ! local MPI size
+   INTEGER                    :: localComm      ! local MPI size
+   LOGICAL                    :: commRank       ! true for ranks doing OASIS communication
+
+   LOGICAL, SAVE              :: prism_was_initialized
+   LOGICAL, SAVE              :: prism_was_terminated
+   INTEGER, SAVE              :: write_grid
+
+   INTEGER                    :: ierror         ! return error code
+
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE :: exfld  ! Temporary buffer for receiving
+
+#ifdef key_cpl_rootexchg
+   LOGICAL                               :: rootexchg =.true.     ! logical switch 
+#else
+   LOGICAL                               :: rootexchg =.false.    ! logical switch
+#endif
+
+   REAL(wp), DIMENSION(:),   ALLOCATABLE :: buffer ! Temporary buffer for exchange
+   INTEGER, DIMENSION(:,:),  ALLOCATABLE :: ranges ! Temporary buffer for exchange
+
+   !! Routine accessibility
+   PUBLIC cpl_prism_init
+   PUBLIC cpl_prism_define
+   PUBLIC cpl_prism_send
+   PUBLIC cpl_prism_recv
+   PUBLIC cpl_prism_finalize
+
+   PUBLIC send_id, recv_id
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE cpl_prism_init( localCommunicator )
+
+      IMPLICIT NONE
+
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE cpl_prism_init  ***
+      !!
+      !! ** Purpose :   Initialize coupled mode communication for ocean
+      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
+      !!
+      !! ** Method  :   OASIS3 MPI communication 
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT(OUT)       :: localCommunicator
+      !!
+      !! * Local declarations
+      !!
+      CHARACTER(len=4)           :: comp_name      ! name of this PRISM component
+      !!
+      !!--------------------------------------------------------------------
+      !!
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_prism_init : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+     
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily
+      IF(lwp)WRITE(numout,cform_err)
+      IF(lwp)WRITE(numout,*) ' key_coupled and key_flx_bulk_* key_flx_forced_daily are incompatible'
+      nstop = nstop + 1
+#endif
+
+      comp_name = 'opa9'
+
+      !------------------------------------------------------------------
+      ! 1st Initialize the PRISM system for the application
+      !------------------------------------------------------------------
+
+      CALL prism_init_comp_proto ( comp_id, comp_name, ierror )
+      IF ( ierror /= PRISM_Ok ) &
+         CALL prism_abort_proto (comp_id, 'cpl_prism_init', 'Failure in prism_init_comp_proto')
+      prism_was_initialized = .true.
+
+      !------------------------------------------------------------------
+      ! 3rd Get an MPI communicator for OPA local communication
+      !------------------------------------------------------------------
+
+      CALL prism_get_localcomm_proto ( localComm, ierror )
+      IF ( ierror /= PRISM_Ok ) &
+         CALL prism_abort_proto (comp_id, 'cpl_prism_init','Failure in prism_get_localcomm_proto' )
+
+      localCommunicator = localComm
+
+   END SUBROUTINE cpl_prism_init
+
+
+   SUBROUTINE cpl_prism_define ()
+
+      IMPLICIT NONE
+
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE cpl_prism_define  ***
+      !!
+      !! ** Purpose :   Define grid and field information for ocean
+      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
+      !!
+      !! ** Method  :   OASIS3 MPI communication 
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      !!
+      !! * Local declarations
+      !!
+      INTEGER                    :: grid_id(2)     ! id returned by prism_def_grid
+      INTEGER                    :: part_id
+
+      INTEGER                    :: paral(5)       ! OASIS3 box partition
+
+      INTEGER                    :: shape(2,3)     ! shape of arrays passed to PSMILe
+      INTEGER                    :: nodim(2)
+      INTEGER                    :: data_type      ! data type of transients
+
+      INTEGER                    :: ji, jj         ! local loop indicees
+      INTEGER                    :: nx, ny, nc     ! local variables
+      INTEGER                    :: im1, ip1
+      INTEGER                    :: jm1, jp1
+      INTEGER                    :: i_grid         ! loop index
+      INTEGER                    :: info
+      INTEGER                    :: maxlen
+      INTEGER                    :: mask(jpi,jpj)
+      REAL(kind=wp)              :: area(jpi,jpj)
+
+      CHARACTER(len=4)           :: point_name     ! name of the grid points
+
+      REAL(kind=wp)              :: rclam(jpi,jpj,4)
+      REAL(kind=wp)              :: rcphi(jpi,jpj,4)
+
+      REAL(kind=wp)              :: glam_b(jpi,jpj) ! buffer for orca2 grid correction
+      REAL(kind=wp)              :: gphi_b(jpi,jpj) ! buffer for orca2 grid correction
+      !!
+      !!--------------------------------------------------------------------
+     
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_prism_define : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+     
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily
+      IF(lwp)WRITE(numout,cform_err)
+      IF(lwp)WRITE(numout,*) ' key_coupled and key_flx_bulk_... are incompatible'
+      nstop = nstop + 1
+#endif
+
+      ! -----------------------------------------------------------------
+      ! ... Some initialisation
+      ! -----------------------------------------------------------------
+
+      send_id = 0
+      recv_id = 0
+
+#if defined key_mpp_mpi
+
+      ! -----------------------------------------------------------------
+      ! ... Some MPI stuff relevant for optional exchange via root only
+      ! -----------------------------------------------------------------
+
+      commRank = .false.
+
+      localRank = mpprank ! from lib_mpp
+      localSize = mppsize ! from lib_mpp
+
+      IF ( rootexchg ) THEN
+         IF ( localRank == localRoot ) commRank = .true.
+      ELSE
+         commRank = .true.
+      ENDIF
+
+      IF ( rootexchg .and. localRank == localRoot ) THEN
+         ALLOCATE(ranges(5,0:localSize-1), stat = ierror)
+         IF (ierror > 0) THEN
+            CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in allocating Integer')
+            RETURN
+         ENDIF
+      ENDIF
+
+#else
+      !
+      ! For non-parallel configurations the one and only process ("localRoot")
+      ! takes part in the communication
+      ! 
+      localRank = localRoot
+      commRank = .true.
+
+#endif
+
+      ! -----------------------------------------------------------------
+      ! ... If necessary the root process writes the global grid info
+      ! -----------------------------------------------------------------
+
+      IF ( localRank == localRoot ) THEN
+
+         WRITE(numout,*)'Opening file SSTOCEAN, unit= 199'
+
+         OPEN (199,STATUS='NEW',FILE="sstocean",FORM='UNFORMATTED',err=310)
+
+         ! In case the sstocean of OASIS3 from a previous run exists
+         ! the programs jumps to the end of the if-block
+!    
+!*    2.0    Write exchange fields to OASIS data file.
+!            -----------------------------------------
+
+         WHERE (tmask(:,:,1) > 0.5 )
+            mask(:,:) = 0
+         ELSE WHERE
+            mask(:,:) = 1
+         END WHERE
+
+! Initialise ice mask at the very first start only
+         frld = 1.
+
+         WRITE(199) 'SSTOCEAN'
+         WRITE(199) (tn(:,:,1)*mask(:,:))+rt0
+
+         WRITE(199) 'SICOCEAN'
+         WRITE(199) (1.-frld(:,:))*mask(:,:)
+
+#if defined key_cpl_albedo
+         tn_ice  = 271.285
+	 alb_ice =   0.75
+
+         WRITE(199) 'STIOCEAN'
+         WRITE(199) tn_ice(:,:)
+
+         WRITE(199) 'SAIOCEAN'
+         WRITE(199) alb_ice(:,:)
+#else
+         hicit = 0.
+         hsnit = 0.
+         WRITE(199) 'SITOCEAN'
+         WRITE(199) hicif(:,:)*mask(:,:)
+
+         WRITE(199) 'SNTOCEAN'
+         WRITE(199) hsnif(:,:)*mask(:,:)
+#endif
+
+#if defined key_cpl_ocevel
+         un(:,:,1) = 0.
+         vn(:,:,1) = 0.
+
+         WHERE (umask(:,:,1) > 0.5 )
+            mask(:,:) = 0
+         ELSE WHERE
+            mask(:,:) = 1
+         END WHERE
+
+         WRITE(199) 'SUNOCEAN'
+         WRITE(199) un(:,:,1)*mask(:,:)
+
+         WHERE (vmask(:,:,1) > 0.5 )
+            mask(:,:) = 0
+         ELSE WHERE
+            mask(:,:) = 1
+         END WHERE
+
+         WRITE(199) 'SVNOCEAN'
+         WRITE(199) vn(:,:,1)*mask(:,:)
+#endif
+
+         WRITE(numout,*)
+         WRITE(numout,*)' sstocean written'
+         WRITE(numout,*)' ***************'
+
+         CLOSE(199)
+
+ 310     CONTINUE
+
+         CALL prism_start_grids_writing ( write_grid )
+
+      ENDIF  ! localRank == localRoot
+
+      IF ( localRank == localRoot .and. write_grid == 1 ) THEN
+
+         !------------------------------------------------------------------
+         ! 1st write global grid information (ORCA tripolar) characteristics
+         !     for surface coupling into a OASIS3 specific grid file. For
+         !     surface coupling it is sufficient to specify only one vertical
+         !     z-level.
+         !------------------------------------------------------------------
+         !
+         ! ... Treat corners in the horizontal plane
+         !
+         nx = jpi
+         ny = jpj
+         nc = 4
+
+         DO i_grid = 1, 3
+
+            IF ( i_grid == 1 ) THEN
+
+               ! --------------------------------------------------------
+               ! ... Write the grid info for T points
+               ! --------------------------------------------------------
+
+               point_name = 'opat'
+
+               glam_b = glamt
+               gphi_b = gphit
+
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+
+                     im1 = ji-1
+                     jm1 = jj-1
+                     IF (ji == 1) im1 = jpi-2
+                     IF (jj == 1) jm1 = jj
+
+                     rclam(ji,jj,1) = glamf(ji,jj)
+                     rclam(ji,jj,2) = glamf(im1,jj)
+                     rclam(ji,jj,3) = glamf(im1,jm1)
+                     rclam(ji,jj,4) = glamf(ji,jm1)
+
+                     rcphi(ji,jj,1) = gphif(ji,jj)
+                     rcphi(ji,jj,2) = gphif(im1,jj)
+                     rcphi(ji,jj,3) = gphif(im1,jm1)
+                     rcphi(ji,jj,4) = gphif(ji,jm1)
+
+                  END DO
+               END DO
+
+               ! Correction of one (land) grid cell of the orca2 grid.
+               ! It was causing problems with the SCRIP interpolation.
+
+               IF (jpiglo == 182 .AND. jpjglo == 149) THEN
+                  rclam(145,106,2) = -1.0
+                  rcphi(145,106,2) = 41.0
+               ENDIF
+
+               WHERE (tmask(:,:,1) > 0.5 )
+                  mask(:,:) = 0
+               ELSE WHERE
+                  mask(:,:) = 1
+               END WHERE
+
+               area = e1t * e2t
+
+            ELSE IF ( i_grid == 2 ) THEN
+
+               ! --------------------------------------------------------
+               ! ... Write the grid info for u points
+               ! --------------------------------------------------------
+
+               point_name = 'opau'
+
+               glam_b = glamu
+               gphi_b = gphiu
+
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+
+                     ip1 = ji+1
+                     jm1 = jj-1
+
+                     IF (ji == jpiglo) ip1 = 3
+                     IF (jj == 1) jm1 = jj
+
+                     rclam(ji,jj,1) = glamv(ip1,jj)
+                     rclam(ji,jj,2) = glamv(ji,jj)
+                     rclam(ji,jj,3) = glamv(ji,jm1)
+                     rclam(ji,jj,4) = glamv(ip1,jm1)
+
+                     rcphi(ji,jj,1) = gphiv(ip1,jj)
+                     rcphi(ji,jj,2) = gphiv(ji,jj)
+                     rcphi(ji,jj,3) = gphiv(ji,jm1)
+                     rcphi(ji,jj,4) = gphiv(ip1,jm1)
+
+                  END DO
+               END DO
+
+               ! Correction of three (land) grid cell of the orca2 grid.
+               ! It was causing problems with the SCRIP interpolation.
+
+               IF (jpiglo == 182 .AND. jpjglo == 149) THEN
+                  glam_b(144,106)   = -1.0
+                  gphi_b(144,106)   = 40.5
+                  rclam (144,106,2) = -1.5  
+                  rcphi (144,106,2) = 41.0
+
+                  glam_b(144,107)   = -1.0
+                  gphi_b(144,107)   = 41.5
+                  rclam (144,107,2) = -1.5  
+                  rcphi (144,107,2) = 42.0
+                  rclam (144,107,3) = -1.5  
+                  rcphi (144,107,3) = 41.0
+
+                  glam_b(144,108)   = -1.0
+                  gphi_b(144,108)   = 42.5
+                  rclam (144,108,2) = -1.5  
+                  rcphi (144,108,2) = 43.0
+                  rclam (144,108,3) = -1.5  
+                  rcphi (144,108,3) = 42.0
+               ENDIF
+
+               WHERE (umask(:,:,1) > 0.5 )
+                  mask(:,:) = 0
+               ELSE WHERE
+                  mask(:,:) = 1
+               END WHERE
+
+               area = e1u * e2u
+
+            ELSE IF ( i_grid == 3 ) THEN
+
+               ! --------------------------------------------------------
+               ! ... Write the grid info for v points
+               ! --------------------------------------------------------
+
+               point_name = 'opav'
+
+               glam_b = glamv
+               gphi_b = gphiv
+
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+
+                     im1 = ji-1
+                     jp1 = jj+1
+                     IF (ji == 1) im1 = jpiglo-2
+                     IF (jj == jpjglo) jp1 = jj
+
+                     rclam(ji,jj,1) = glamu(ji,jp1)
+                     rclam(ji,jj,2) = glamu(im1,jp1)
+                     rclam(ji,jj,3) = glamu(im1,jj)
+                     rclam(ji,jj,4) = glamu(ji,jj)
+
+                     rcphi(ji,jj,1) = gphiu(ji,jp1)
+                     rcphi(ji,jj,2) = gphiu(im1,jp1)
+                     rcphi(ji,jj,3) = gphiu(im1,jj)
+                     rcphi(ji,jj,4) = gphiu(ji,jj)
+
+                  END DO
+               END DO
+
+               ! Correction of one (land) grid cell of the orca2 grid.
+               ! It was causing problems with the SCRIP interpolation.
+
+               IF (jpiglo == 182 .AND. jpjglo == 149) THEN
+                  rclam(145,105,2) = -1.0  
+                  rcphi(145,105,2) = 40.5
+               ENDIF
+
+               WHERE (vmask(:,:,1) > 0.5 )
+                  mask(:,:) = 0
+               ELSE WHERE
+                  mask(:,:) = 1
+               END WHERE
+
+               area = e1v * e2v
+
+            ENDIF ! i_grid
+
+            WHERE (glam_b(:,:) < 0.)
+               glam_b(:,:) = glam_b(:,:) + 360.
+            END WHERE
+            WHERE (glam_b(:,:) > 360.)
+               glam_b(:,:) = glam_b(:,:) - 360.
+            END WHERE
+
+            WHERE (rclam(:,:,:) < 0.)
+               rclam(:,:,:) = rclam(:,:,:) + 360.
+            END WHERE
+            WHERE (rclam(:,:,:) > 360.)
+               rclam(:,:,:) = rclam(:,:,:) - 360.
+            END WHERE
+
+            mask(:,jpjglo)=1
+
+            CALL prism_write_grid   ( point_name, nx, ny, glam_b, gphi_b ) 
+            CALL prism_write_corner ( point_name, nx, ny, nc, rclam, rcphi )
+            CALL prism_write_mask   ( point_name, nx, ny, mask )
+            CALL prism_write_area   ( point_name, nx, ny, area )
+
+         END DO ! i_grid
+
+         CALL prism_terminate_grids_writing ()
+
+      ENDIF ! localRank == localRoot .and. write_grid == 1
+
+      ! -----------------------------------------------------------------
+      ! ... Define the partition 
+      ! -----------------------------------------------------------------
+
+      IF ( rootexchg ) THEN
+
+         paral(1) = 2              ! box partitioning
+         paral(2) = 0              ! NEMO lower left corner global offset    
+         paral(3) = jpiglo         ! local extent in i 
+         paral(4) = jpjglo         ! local extent in j
+         paral(5) = jpiglo         ! global extent in x
+
+         range(1) = nimpp-1+nldi   ! global start in i
+         range(2) = nlei-nldi+1    ! local size in i of valid region
+         range(3) = njmpp-1+nldj   ! global start in j
+         range(4) = nlej-nldj+1    ! local size in j of valid region
+         range(5) = range(2) &
+                  * range(4)       ! local horizontal size
+
+         IF(ln_ctl) THEN
+         write(numout,*) ' rootexchg: range(1:5)', range
+         ENDIF
+
+         !
+         ! Collect ranges from all NEMO procs on the local root process
+         !
+         CALL mpi_gather(range,  5, MPI_INTEGER, &
+                         ranges, 5, MPI_INTEGER, localRoot, localComm, ierror)
+
+         IF ( localRank == localRoot ) THEN
+
+            maxlen = maxval(ranges(5,:))
+            
+            ALLOCATE(buffer(1:maxlen), stat = ierror)
+            IF (ierror > 0) THEN
+               CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in allocating buffer')
+               RETURN
+            ENDIF
+
+          ENDIF
+
+      ELSE
+
+         paral(1) = 2                  ! box partitioning
+!2dtest         paral(2) = jpiglo           &
+!2dtest                  * (nldj-1+njmpp-1) &
+!2dtest                  + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset    
+         paral(2) = jpiglo &
+                  * (nldj-1+njmpp-1)   ! NEMO lower left corner global offset    
+         paral(3) = nlei-nldi+1        ! local extent in i 
+         paral(4) = nlej-nldj+1        ! local extent in j
+         paral(5) = jpiglo             ! global extent in x
+
+         IF(ln_ctl) THEN
+            print*, ' multiexchg: paral (1:5)', paral
+            print*, ' multiexchg: jpi, jpj =', jpi, jpj
+            print*, ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
+            print*, ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
+         ENDIF
+
+         IF ( paral(3) /= nlei-nldi+1 ) THEN
+              print*, 'WARNING!!! in cpl_oasis3 - cpl_prism_define'
+              print*, 'cpl_prism_define: local extend in i is ', paral(3), ' should equal ', nlei-nldi+1
+         ENDIF
+         IF ( paral(4) /= nlej-nldj+1 ) THEN
+              print*, 'WARNING!!! in cpl_oasis3 - cpl_prism_define'
+              print*, 'cpl_prism_define: local extend in j is ', paral(4), ' should equal ', nlej-nldj+1
+         ENDIF
+
+      ENDIF
+
+      IF ( commRank ) &
+      CALL prism_def_partition_proto ( part_id, paral, ierror )
+
+      grid_id(1)= part_id
+
+      !------------------------------------------------------------------
+      ! 3rd Declare the transient variables
+      !------------------------------------------------------------------
+      !
+      ! ... Define symbolic names for the transient fields send by the ocean
+      !     These must be identical to the names specified in the SMIOC file.
+      !
+      cpl_send( 1)='SSTOCEAN' ! sea surface temperature              -> sst_io
+      cpl_send( 2)='SICOCEAN' ! sea ice area fraction                -> 1.-frld
+#if defined key_cpl_albedo
+      cpl_send( 3)='STIOCEAN' ! surface temperature over sea ice     -> tn_ice
+      cpl_send( 4)='SAIOCEAN' ! albedo over sea ice                  -> alb_ice
+#else
+      cpl_send( 3)='SITOCEAN' ! sea ice thickness                    -> hicif (only 1 layer available!)
+      cpl_send( 4)='SNTOCEAN' ! surface snow thickness over sea ice  -> hsnif
+#endif
+#if defined key_cpl_ocevel
+      cpl_send( 5)='SUNOCEAN' ! U-velocity                           -> un
+      cpl_send( 6)='SVNOCEAN' ! V-velocity                           -> vn
+#endif
+      !
+      ! ...  Define symbolic names for transient fields received by the ocean.
+      !      These must be identical to the names specified in the SMIOC file.
+      !
+      ! ...  a) U-Grid fields
+      !
+      cpl_recv( 1)='TXWOCEWU' ! weighted surface downward eastward stress
+      cpl_recv( 2)='TYWOCEWU' ! weighted surface downward northward stress
+      cpl_recv( 3)='TXIOCEWU' ! weighted surface downward eastward stress over ice
+      cpl_recv( 4)='TYIOCEWU' ! weighted surface downward northward stress over ice
+      !
+      ! ...  a) V-Grid fields
+      !
+      cpl_recv( 5)='TXWOCEWV' ! weighted surface downward eastward stress
+      cpl_recv( 6)='TYWOCEWV' ! weighted surface downward northward stress
+      cpl_recv( 7)='TXIOCEWV' ! weighted surface downward eastward stress over ice
+      cpl_recv( 8)='TYIOCEWV' ! weighted surface downward northward stress over ice
+      !
+      ! ...  a) T-Grid fields
+      !
+      cpl_recv( 9)='FRWOCEPE' ! P-E over water                               -> zpew
+      cpl_recv(10)='FRIOCEPE' ! P-E over ice                                 -> zpei
+      cpl_recv(11)='FRROCESN' ! surface downward snow fall                   -> zpsol
+      cpl_recv(12)='FRIOCEEV' ! surface upward snow flux where sea ice       -> zevice
+
+      cpl_recv(13)='QSWOCESR' ! surface net downward shortwave flux          -> qsr_oce
+      cpl_recv(14)='QSWOCENS' ! surface downward non-solar heat flux in air  -> qnsr_oce
+      cpl_recv(15)='QSIOCESR' ! solar heat flux on sea ice                   -> qsr_ice
+      cpl_recv(16)='QSIOCENS' ! non-solar heat flux on sea ice               -> qnsr_ice
+      cpl_recv(17)='QSIOCEDQ' ! non-solar heat flux derivative               -> dqns_ice
+
+#ifdef key_cpl_discharge
+      cpl_recv(18)='FRWOCEIS' ! ice discharge into ocean                     -> calving
+      cpl_recv(19)='FRWOCERD' ! river discharge into ocean                   -> zrunriv
+      cpl_recv(20)='FRWOCECD' ! continental discharge into ocean             -> zruncot
+#endif
+      !
+      ! data_type has to be PRISM_REAL as PRISM_DOUBLE is not supported.
+      ! For exchange of double precision fields the OASIS3 has to be compiled
+      ! with use_realtype_single. (see OASIS3 User Guide prism_2-4, 5th Ed.,
+      ! p. 13 and p. 53 for further explanation.)
+      !
+      data_type = PRISM_REAL
+
+      nodim(1) = 3 ! check
+      nodim(2) = 0
+
+      !
+      ! ... Define the shape for the area that excludes the halo
+      !     For serial configuration (key_mpp_mpi not being active)
+      !     nl* is set to the global values 1 and jp*glo.
+      !
+      IF ( rootexchg ) THEN
+         shape(1,1) = 1
+         shape(2,1) = jpiglo
+         shape(1,2) = 1
+         shape(2,2) = jpjglo
+         shape(1,3) = 1
+         shape(2,3) = 1
+       ELSE
+         shape(1,1) = 1
+         shape(2,1) = nlei-nldi+1 ! jpi
+         shape(1,2) = 1
+         shape(2,2) = nlej-nldj+1 ! jpj
+         shape(1,3) = 1
+         shape(2,3) = 1
+      ENDIF
+      !
+      ! -----------------------------------------------------------------
+      ! ... Allocate memory for data exchange
+      ! -----------------------------------------------------------------
+      !
+      ALLOCATE(exfld(shape(1,1):shape(2,1),shape(1,2):shape(2,2)), stat = ierror)
+      IF (ierror > 0) THEN
+         CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in allocating exfld')
+         RETURN
+      ENDIF
+      !
+      ! ... Announce send variables, all on T points. 
+      !
+      info = PRISM_Out
+      !
+
+      IF ( commRank ) THEN
+
+         DO ji = 1, nsend
+            !        if ( ji == 2 ) ; then ; nodim(2) = 2 ; else ; nodim(2) = 0 ; endif
+            CALL prism_def_var_proto (send_id(ji), cpl_send(ji), grid_id(1), &
+                 nodim, info, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Ok ) THEN
+               PRINT *, 'Failed to define transient ', ji, TRIM(cpl_send(ji))
+               CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         nodim(1) = 3 ! check
+         nodim(2) = 0
+         !
+         ! ... Announce recv variables. 
+         !
+         info = PRISM_In
+         !
+         ! ... a) on U points
+         !
+         DO ji = 1, 4
+            CALL prism_def_var_proto (recv_id(ji), cpl_recv(ji), grid_id(1), &
+                 nodim, info, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Ok ) THEN
+               PRINT *, 'Failed to define transient ', ji, TRIM(cpl_recv(ji))
+               CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         ! ... b) on V points
+         !
+         DO ji = 5, 8
+            CALL prism_def_var_proto (recv_id(ji), cpl_recv(ji), grid_id(1), &
+                 nodim, info, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Ok ) THEN
+               PRINT *, 'Failed to define transient ', TRIM(cpl_recv(ji))
+               CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         ! ... c) on T points
+         !
+         DO ji = 9, nrecv
+            CALL prism_def_var_proto (recv_id(ji), cpl_recv(ji), grid_id(1), &
+                 nodim, info, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Ok ) THEN
+               PRINT *, 'Failed to define transient ', TRIM(cpl_recv(ji))
+               CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in prism_def_var')
+            ENDIF
+         ENDDO
+
+      ENDIF ! commRank
+
+      !------------------------------------------------------------------
+      ! 4th End of definition phase
+      !------------------------------------------------------------------
+
+      IF ( commRank ) THEN
+         CALL prism_enddef_proto(ierror)
+         IF ( ierror /= PRISM_Ok ) &
+              CALL prism_abort_proto ( comp_id, 'cpl_prism_define', 'Failure in prism_enddef')
+      ENDIF
+
+   END SUBROUTINE cpl_prism_define
+
+
+
+   SUBROUTINE cpl_prism_send( var_id, date, data_array, info )
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_send  ***
+      !!
+      !! ** Purpose : - At each coupling time-step,this routine sends fields
+      !!      like sst or ice cover to the coupler or remote application.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT( IN )  :: var_id    ! variable Id
+      INTEGER, INTENT( OUT ) :: info      ! OASIS3 info argument
+      INTEGER, INTENT( IN )  :: date      ! ocean time-step in seconds
+      REAL(wp)               :: data_array(:,:)
+      !!
+      !! * Local declarations
+      !!
+#if defined key_mpp_mpi
+      REAL(wp)               :: global_array(jpiglo,jpjglo)
+      !
+!mpi  INTEGER                :: status(MPI_STATUS_SIZE)
+!mpi  INTEGER                :: type       ! MPI data type
+      INTEGER                :: request    ! MPI isend request
+      INTEGER                :: ji, jj, jn ! local loop indicees
+#else
+      INTEGER                :: ji
+#endif
+      !!
+      !!--------------------------------------------------------------------
+      !!
+
+#if defined key_mpp_mpi
+
+      request = 0
+
+      IF ( rootexchg ) THEN
+         !
+!mpi     IF ( wp == 4 ) type = MPI_REAL
+!mpi     IF ( wp == 8 ) type = MPI_DOUBLE_PRECISION
+         !
+         ! collect data on the local root process
+         !
+
+         if ( var_id == 1 .and. localRank == localRoot .and. ln_ctl )  then
+             do ji = 0, localSize-1
+                WRITE(numout,*) ' rootexchg: ranges for rank ', ji, ' are ', ranges(:,ji) 
+             enddo
+         endif
+
+         IF ( localRank /= localRoot ) THEN
+
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  exfld(ji-nldi+1,jj-nldj+1)=data_array(ji,jj)
+               ENDDO
+            ENDDO
+
+!mpi        CALL mpi_send(exfld, range(5), type, localRoot, localRank, localComm, ierror)
+            CALL mppsend (localRank, exfld, range(5), localRoot, request)  
+
+            if ( var_id == 1 .and. ln_ctl )  then
+               WRITE(numout,*) ' rootexchg: This is process       ', localRank
+               WRITE(numout,*) ' rootexchg: We have a range of    ', range 
+!               WRITE(numout,*) ' rootexchg: We got SST to process ', data_array 
+            endif
+
+         ENDIF
+
+         IF ( localRank == localRoot ) THEN
+
+            DO jj = ranges(3,localRoot), ranges(3,localRoot)+ranges(4,localRoot)-1
+               DO ji = ranges(1,localRoot), ranges(1,localRoot)+ranges(2,localRoot)-1
+                  global_array(ji,jj) = data_array(ji,jj) ! workaround
+               ENDDO
+            ENDDO
+
+            DO jn = 1, localSize-1
+
+!mpi           CALL mpi_recv(buffer, ranges(5,jn), type, localRoot, jn, localComm, status, ierror)
+               CALL mpprecv(jn, buffer, ranges(5,jn))
+
+               if ( var_id == 1 .and. ln_ctl )  then
+                   WRITE(numout,*) ' rootexchg: Handling data from process ', jn
+!                   WRITE(numout,*) ' rootexchg: We got SST to process      ', buffer
+               endif
+
+
+               DO jj = ranges(3,jn), ranges(3,jn)+ranges(4,jn)-1
+                  DO ji = ranges(1,jn), ranges(1,jn)+ranges(2,jn)-1
+                     global_array(ji,jj) = buffer((jj-ranges(3,jn))*ranges(2,jn) + ji-ranges(1,jn)+1)
+                  ENDDO
+               ENDDO
+
+            ENDDO
+
+            CALL prism_put_proto ( var_id, date, global_array, info )
+
+         ENDIF
+
+      ELSE
+
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               exfld(ji-nldi+1,jj-nldj+1)=data_array(ji,jj)
+            ENDDO
+         ENDDO
+
+         CALL prism_put_proto ( var_id, date, exfld, info )
+
+      ENDIF
+
+#else
+
+      !
+      ! send local data from every process to OASIS3
+      !
+      IF ( commRank ) &
+      CALL prism_put_proto ( var_id, date, data_array, info )
+
+#endif
+
+      IF ( commRank ) THEN
+
+         IF (ln_ctl .and. lwp) THEN        
+
+            IF ( info == PRISM_Sent     .OR. &
+                 info == PRISM_ToRest   .OR. &
+                 info == PRISM_SentOut  .OR. &
+                 info == PRISM_ToRestOut       ) THEN
+               WRITE(numout,*) '****************'
+               DO ji = 1, nsend
+                  IF (var_id == send_id(ji) ) THEN
+                     WRITE(numout,*) 'prism_put_proto: Outgoing ', cpl_send(ji)
+                     EXIT
+                  ENDIF
+               ENDDO
+               WRITE(numout,*) 'prism_put_proto: var_id ', var_id
+               WRITE(numout,*) 'prism_put_proto:   date ', date
+               WRITE(numout,*) 'prism_put_proto:   info ', info
+               WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+               WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+               WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+               WRITE(numout,*) '****************'
+            ENDIF
+
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE cpl_prism_send
+
+
+
+   SUBROUTINE cpl_prism_recv( var_id, date, data_array, info )
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_recv  ***
+      !!
+      !! ** Purpose : - At each coupling time-step,this routine receives fields
+      !!      like stresses and fluxes from the coupler or remote application.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT( IN )  :: var_id    ! variable Id
+      INTEGER, INTENT( OUT ) :: info      ! variable Id
+      INTEGER, INTENT( IN )  :: date      ! ocean time-step in seconds
+      REAL(wp),INTENT( OUT ) :: data_array(:,:)
+      !!
+      !! * Local declarations
+      !!
+#if defined key_mpp_mpi
+      REAL(wp)               :: global_array(jpiglo,jpjglo)
+      !
+!      LOGICAL                :: action = .false.
+      LOGICAL                :: action
+!mpi  INTEGER                :: status(MPI_STATUS_SIZE)
+!mpi  INTEGER                :: type       ! MPI data type
+      INTEGER                :: request    ! MPI isend request
+      INTEGER                :: ji, jj, jn ! local loop indices
+#else
+      INTEGER                :: ji
+#endif
+      !!
+      !!--------------------------------------------------------------------
+      !!
+#ifdef key_mpp_mpi
+      action = .false.
+      request = 0
+
+      IF ( rootexchg ) THEN
+         !
+         ! receive data from OASIS3 on local root
+         !
+         IF ( commRank ) &
+              CALL prism_get_proto ( var_id, date, global_array, info )
+
+         CALL MPI_BCAST ( info, 1, MPI_INTEGER, localRoot, localComm, ierror )
+
+      ELSE
+         !
+         ! receive local data from OASIS3 on every process
+         !
+         CALL prism_get_proto ( var_id, date, exfld, info )
+
+      ENDIF
+
+      IF ( info == PRISM_Recvd        .OR. &
+           info == PRISM_FromRest     .OR. &
+           info == PRISM_RecvOut      .OR. &
+           info == PRISM_FromRestOut ) action = .true.
+
+      IF (ln_ctl .and. lwp) THEN        
+         WRITE(numout,*) "info", info, var_id
+         WRITE(numout,*) "date", date, var_id
+         WRITE(numout,*) "action", action, var_id
+      ENDIF
+
+      IF ( rootexchg .and. action ) THEN
+         !
+!mpi     IF ( wp == 4 ) type = MPI_REAL
+!mpi     IF ( wp == 8 ) type = MPI_DOUBLE_PRECISION
+         !
+         ! distribute data to processes
+         !
+         IF ( localRank == localRoot ) THEN
+
+            DO jj = ranges(3,localRoot), ranges(3,localRoot)+ranges(4,localRoot)-1
+               DO ji = ranges(1,localRoot), ranges(1,localRoot)+ranges(2,localRoot)-1
+                  exfld(ji-ranges(1,localRoot)+1,jj-ranges(3,localRoot)+1) = global_array(ji,jj)
+               ENDDO
+            ENDDO
+
+            DO jn = 1, localSize-1
+
+               DO jj = ranges(3,jn), ranges(3,jn)+ranges(4,jn)-1
+                  DO ji = ranges(1,jn), ranges(1,jn)+ranges(2,jn)-1
+                     buffer((jj-ranges(3,jn))*ranges(2,jn) + ji-ranges(1,jn)+1) = global_array(ji,jj)
+                  ENDDO
+               ENDDO
+
+!mpi           CALL mpi_send(buffer, ranges(5,jn), type, jn, jn, localComm, ierror)
+               CALL mppsend (jn, buffer, ranges(5,jn), jn, request)  
+
+            ENDDO
+
+         ENDIF
+
+         IF ( localRank /= localRoot ) THEN
+!mpi         CALL mpi_recv(exfld, range(5), type, localRoot, localRank, localComm, status, ierror)
+             CALL mpprecv(localRank, exfld, range(5))
+         ENDIF
+
+      ENDIF
+
+      IF ( action ) THEN
+
+         data_array = 0.0
+
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               data_array(ji,jj)=exfld(ji-nldi+1,jj-nldj+1)
+            ENDDO
+         ENDDO
+
+         IF (ln_ctl .and. lwp) THEN        
+            WRITE(numout,*) '****************'
+            DO ji = 1, nrecv
+               IF (var_id == recv_id(ji) ) THEN
+                  WRITE(numout,*) 'prism_get_proto: Incoming ', cpl_recv(ji)
+                  EXIT
+               ENDIF
+            ENDDO
+            WRITE(numout,*) 'prism_get_proto: var_id ', var_id
+            WRITE(numout,*) 'prism_get_proto:   date ', date
+            WRITE(numout,*) 'prism_get_proto:   info ', info
+            WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+            WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+            WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+            WRITE(numout,*) '****************'
+         ENDIF
+
+      ENDIF
+#else
+      CALL prism_get_proto ( var_id, date, exfld, info)
+      
+      IF (info == PRISM_Recvd        .OR. &
+          info == PRISM_FromRest     .OR. &
+          info == PRISM_RecvOut      .OR. &
+          info == PRISM_FromRestOut )      THEN
+             data_array = exfld
+
+         IF (ln_ctl .and. lwp ) THEN        
+            WRITE(numout,*) '****************'
+            DO ji = 1, nrecv
+               IF (var_id == recv_id(ji) ) THEN
+                  WRITE(numout,*) 'prism_get_proto: Incoming ', cpl_recv(ji)
+                  EXIT
+               ENDIF
+            ENDDO
+            WRITE(numout,*) 'prism_get_proto: var_id ', var_id
+            WRITE(numout,*) 'prism_get_proto:   date ', date
+            WRITE(numout,*) 'prism_get_proto:   info ', info
+            WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+            WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+            WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+            WRITE(numout,*) '****************'
+         ENDIF
+
+       ENDIF
+#endif
+
+   END SUBROUTINE cpl_prism_recv
+
+
+
+   SUBROUTINE cpl_prism_finalize
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_finalize  ***
+      !!
+      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
+      !!      called explicitly before cpl_prism_init it will also close
+      !!      MPI communication.
+      !!----------------------------------------------------------------------
+
+      DEALLOCATE(exfld)
+
+      if ( prism_was_initialized ) then
+
+         if ( prism_was_terminated ) then
+            print *, 'prism has already been terminated.'
+         else
+            call prism_terminate_proto ( ierror )
+            prism_was_terminated = .true.
+         endif
+
+      else
+
+         print *, 'Initialize prism before terminating it.'
+
+      endif
+
+
+   END SUBROUTINE cpl_prism_finalize
+
+#endif
+
+END MODULE cpl_oasis3
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis4.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis4.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/cpl_oasis4.F90	(revision 4536)
@@ -0,0 +1,1215 @@
+MODULE cpl_oasis4
+   !!======================================================================
+   !!                    ***  MODULE cpl_oasis4  ***
+   !! Coupled O/A : coupled ocean-atmosphere case using OASIS4
+   !!               special case: OPA/LIM coupled to ECHAM5
+   !!=====================================================================
+   !! History :   
+   !!   9.0  !  04-06  (R. Redler, NEC CCRLE, Germany) Original code
+   !!   " "  !  04-11  (R. Redler, N. Keenlyside) revision
+   !!   " "  !  04-11  (V. Gayler, MPI M&D) Grid writing
+   !!   " "  !  05-08  (R. Redler, W. Park) frld initialization, paral(2) revision
+   !!   " "  !  05-09  (R. Redler) extended to allow for communication over root only
+   !!   " "  !  05-09  (R. Redler) extended to allow for communication over root only
+   !!   " "  !  05-12  (R. Hill, Met. Office) Tweaks and hacks to get NEMO/O4 working
+   !!   " "  !  06-02  (R. Redler, W. Park) Bug fixes and updates according to the OASIS3 interface
+   !!   " "  !  06-02  (R. Redler) app/grid/grid_name from namelist
+   !!----------------------------------------------------------------------
+#if defined key_oasis4
+   !!----------------------------------------------------------------------
+   !!   'key_oasis4'                    coupled Ocean/Atmosphere via OASIS4
+   !!----------------------------------------------------------------------
+   !!   cpl_prism_init     : initialization of coupled mode communication
+   !!   cpl_prism_define   : definition of grid and fields
+   !!   cpl_prism_send     : send out fields in coupled mode
+   !!   cpl_prism_recv     : receive fields in coupled mode
+   !!   cpl_prism_finalize : finalize the coupled mode communication
+   !!----------------------------------------------------------------------
+   !! * Modules used
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+!   Following line must be enabled if coupling with OASIS
+!   USE prism                        ! prism module
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+#if defined key_mpp_mpi
+   USE lib_mpp, only : mppsize, mpprank   ! message passing
+   USE lib_mpp, only : mppsend            ! message passing
+   USE lib_mpp, only : mpprecv            ! message passing
+#endif
+   USE daymod                       ! date and time info
+   USE dom_oce                      ! ocean space and time domain
+   USE in_out_manager               ! I/O manager
+   USE par_oce                      !
+   USE phycst, only : rt0           ! freezing point of sea water
+   USE oasis4_date                  ! OASIS4 date declarations in
+                                    ! PRISM compatible format
+   IMPLICIT NONE
+!
+! Exchange parameters for coupling ORCA-LIM with ECHAM5
+!
+#if defined key_cpl_ocevel
+   INTEGER, PARAMETER         :: nsend =  6
+#else
+   INTEGER, PARAMETER         :: nsend =  4
+#endif
+
+#if defined key_cpl_discharge
+   INTEGER, PARAMETER         :: nrecv = 20
+#else
+   INTEGER, PARAMETER         :: nrecv = 17
+#endif
+
+   INTEGER, DIMENSION(nsend)  :: send_id
+   INTEGER, DIMENSION(nrecv)  :: recv_id
+
+   CHARACTER(len=32)          :: cpl_send (nsend)
+   CHARACTER(len=32)          :: cpl_recv (nrecv)
+
+   CHARACTER(len=16)          :: app_name       ! application name for OASIS use
+   CHARACTER(len=16)          :: comp_name      ! name of this PRISM component
+   CHARACTER(len=16)          :: grid_name      ! name of the grid
+   CHARACTER(len=1)           :: c_mpi_send
+
+! The following now come in via new module oasis4_date
+!   TYPE(PRISM_Time_struct), PUBLIC    :: dates          ! date info for send operation
+!   TYPE(PRISM_Time_struct), PUBLIC    :: dates_bound(2) ! date info for send operation
+!   TYPE(PRISM_Time_struct), PUBLIC    :: dater          ! date info for receive operation
+!   TYPE(PRISM_Time_struct), PUBLIC    :: dater_bound(2) ! date info for receive operation
+!   TYPE(PRISM_Time_struct), PUBLIC    :: tmpdate
+
+   PRIVATE
+
+   INTEGER, PARAMETER         :: localRoot  = 0
+
+   INTEGER                    :: localRank      ! local MPI rank
+   INTEGER                    :: localSize      ! local MPI size
+   INTEGER                    :: localComm      ! local MPI size
+   LOGICAL                    :: commRank       ! true for ranks doing OASIS communication
+   INTEGER                    :: comp_id        ! id returned by prism_init_comp
+
+   INTEGER                    :: range(5)
+
+   LOGICAL, SAVE              :: prism_was_initialized
+   LOGICAL, SAVE              :: prism_was_terminated
+   INTEGER, SAVE              :: write_grid
+
+   INTEGER                    :: ierror         ! return error code
+
+#ifdef key_cpl_rootexchg
+   LOGICAL                               :: rootexchg =.true.     ! logical switch 
+#else
+   LOGICAL                               :: rootexchg =.false.    ! logical switch
+#endif
+
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE :: exfld  ! Temporary buffer for exchange
+   REAL(wp), DIMENSION(:),   ALLOCATABLE :: buffer ! Temporary buffer for exchange
+   INTEGER, DIMENSION(:,:),  ALLOCATABLE :: ranges ! Temporary buffer for exchange
+
+   DOUBLE PRECISION           :: date_incr
+
+   !! Routine accessibility
+   PUBLIC cpl_prism_init
+   PUBLIC cpl_prism_define
+   PUBLIC cpl_prism_send
+   PUBLIC cpl_prism_recv
+   PUBLIC cpl_prism_finalize
+
+   PUBLIC send_id, recv_id
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE cpl_prism_init( localCommunicator )
+
+      IMPLICIT NONE
+
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE cpl_prism_init  ***
+      !!
+      !! ** Purpose :   Initialize coupled mode communication for ocean
+      !!    exchange between AGCM, OGCM and COUPLER. (OASIS4 software)
+      !!
+      !! ** Method  :   OASIS4 MPI communication 
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT(OUT)       :: localCommunicator
+      !!
+      !! * Local declarations
+      !!
+
+      NAMELIST/nam_mpp/ app_name, comp_name, c_mpi_send, grid_name
+
+      !!
+      !!--------------------------------------------------------------------
+      !!
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_prism_init : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+     
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily
+
+#if !defined key_oasis4
+! The following is not necessarily a valid peice of checking
+
+      IF(lwp) WRITE(numout,cform_err)
+      IF(lwp) WRITE(numout,*) ' key_coupled and key_flx_bulk_* key_flx_forced_daily are incompatible'
+      nstop = nstop + 1
+
+#endif
+
+#endif
+
+      REWIND( numnam )
+      READ  ( numnam, nam_mpp )
+      REWIND( numnam )
+
+      !------------------------------------------------------------------
+      ! 1st Initialize the PRISM system for the application
+      !------------------------------------------------------------------
+
+      CALL prism_initialized (prism_was_initialized, ierror)
+      IF ( ierror /= PRISM_Success ) &
+         CALL prism_abort( comp_id, 'OPA9.0', 'cpl_prism_init: Failure in prism_initialized' )
+
+      IF ( .NOT. prism_was_initialized ) THEN
+         CALL prism_init( app_name, ierror )
+         IF ( ierror /= PRISM_Success ) &
+            CALL prism_abort(comp_id, 'OPA9.0', 'cpl_prism_init: Failure in prism_init')
+         prism_was_initialized = .true.
+      ELSE
+         call prism_abort(comp_id, 'OPA9.0', 'cpl_prism_init: Do not initialize prism twice!')
+      ENDIF
+      !
+      ! Obtain the actual dates and date bounds
+      !
+      ! date is determined by adding days since beginning of
+      !   the run to the corresponding initial date. Note that
+      !   OPA internal info about the start date of the experiment
+      !   is bypassed. Instead we rely sololy on the info provided
+      !   by the SCC.xml file. 
+      !
+      dates   = PRISM_Jobstart_date
+
+      WRITE(6,*) "PRISM JOB START DATE IS", dates
+
+      !
+      ! upper bound is determined by adding half a time step
+      !
+      tmpdate = dates
+      date_incr = rdttra(1)/2.0
+      CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+      dates_bound(2) = tmpdate
+      !
+      ! lower bound is determined by half distance to date from previous run
+      !
+      tmpdate   = dates
+      date_incr = ( adatrj - adatrj0 ) * 43200.0
+      CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+      dates_bound(1) = tmpdate
+
+      dater = dates
+      dater_bound(1) = dates_bound(1) 
+      dater_bound(2) = dates_bound(2) 
+
+      WRITE(6,*) "DATE send and rec BOUNDS",dater_bound
+      WRITE(6,*) "OTHER BITS FOR DATE",rdttra(1)
+      WRITE(6,*) "adatrj/0",adatrj,adatrj0,date_incr
+
+      !------------------------------------------------------------------
+      ! 2nd Initialize the PRISM system for the component
+      !------------------------------------------------------------------
+
+      CALL prism_init_comp ( comp_id, comp_name, ierror )
+      IF ( ierror /= PRISM_Success ) &
+         CALL prism_abort (comp_id, 'OPA9.0', 'cpl_prism_init: Failure in prism_init_comp')
+
+      WRITE(6,*) "COMPLETED INIT_COMP",comp_name,comp_id
+
+      !------------------------------------------------------------------
+      ! 3rd Get an MPI communicator for OPA local communication
+      !------------------------------------------------------------------
+
+      CALL prism_get_localcomm ( comp_id, localComm, ierror )
+      IF ( ierror /= PRISM_Success ) &
+         CALL prism_abort (comp_id, 'OPA9.0', 'cpl_prism_init: Failure in prism_get_localcomm' )
+
+      localCommunicator = localComm
+
+       WRITE(6,*) "COMPLETED GET_LOCALCOMM",comp_name,comp_id
+
+
+   END SUBROUTINE cpl_prism_init
+
+
+   SUBROUTINE cpl_prism_define ()
+
+      IMPLICIT NONE
+
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE cpl_prism_define  ***
+      !!
+      !! ** Purpose :   Define grid and field information for ocean
+      !!    exchange between AGCM, OGCM and COUPLER. (OASIS4 software)
+      !!
+      !! ** Method  :   OASIS4 MPI communication 
+      !!--------------------------------------------------------------------
+      !! * Arguments
+      !!
+      !! * Local declarations
+
+      INTEGER                    :: grid_id(2)     ! id returned by prism_def_grid
+
+      INTEGER                    :: upoint_id(2), &
+                                    vpoint_id(2), &
+                                    tpoint_id(2), &
+                                    fpoint_id(2)   ! ids returned by prism_set_points
+
+      INTEGER                    :: umask_id(2), &
+                                    vmask_id(2), &
+                                    tmask_id(2), &
+                                    fmask_id(2)    ! ids returned by prism_set_mask
+
+      INTEGER                    :: grid_type      ! PRISM grid type
+
+      INTEGER                    :: shape(2,3)     ! shape of arrays passed to PSMILe
+      INTEGER                    :: nodim(2)
+      INTEGER                    :: data_type      ! data type of transients
+
+      INTEGER                    :: nbr_corners
+
+      LOGICAL                    :: new_points
+      LOGICAL                    :: new_mask
+      LOGICAL                    :: mask(jpi,jpj,jpk)
+
+      INTEGER                    :: ji, jj, jk     ! local loop indicees
+
+      CHARACTER(len=32)          :: cpl_send (nsend)
+      CHARACTER(len=32)          :: cpl_recv (nrecv)
+
+      CHARACTER(len=32)          :: grid_name      ! name of the grid
+      CHARACTER(len=32)          :: point_name     ! name of the grid points
+
+      REAL(kind=wp), ALLOCATABLE :: rclon(:,:,:)
+      REAL(kind=wp), ALLOCATABLE :: rclat(:,:,:)
+      REAL(kind=wp), ALLOCATABLE :: rcz  (:,:)
+
+      !!--------------------------------------------------------------------
+     
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_prism_define : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+     
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily
+
+#if !defined key_oasis4
+! The problem with the following is that it ASSUMES we're only ever coupling to an atmosphere
+! which is not necessarily the case. Prevent this test temporarily for NEMOGAM development.
+
+      IF(lwp) WRITE(numout,cform_err)
+      IF(lwp) WRITE(numout,*) ' key_coupled and key_flx_bulk_... are incompatible'
+      nstop = nstop + 1
+
+#endif
+
+#endif
+
+      ! -----------------------------------------------------------------
+      ! ... Some initialisation
+      ! -----------------------------------------------------------------
+
+      send_id = 0
+      recv_id = 0
+
+#if defined key_mpp_mpi
+
+      ! -----------------------------------------------------------------
+      ! ... Some MPI stuff relevant for optional exchange via root only
+      ! -----------------------------------------------------------------
+
+      commRank = .false.
+
+      localRank = mpprank ! from lib_mpp
+      localSize = mppsize ! from lib_mpp
+
+      IF(lwp) WRITE(numout,*) "CALLING DEFINE"
+
+      IF ( rootexchg ) THEN
+         IF ( localRank == localRoot ) commRank = .true.
+      ELSE
+         commRank = .true.
+      ENDIF
+
+#else
+      !
+      ! For non-parallel configurations the one and only process ("localRoot")
+      ! takes part in the communication
+      ! 
+      localRank = localRoot
+      commRank = .true.
+
+#endif
+
+      ! -----------------------------------------------------------------
+      ! ... Allocate memory for data exchange
+      ! -----------------------------------------------------------------
+
+
+      IF(lwp) WRITE(numout,*) "Abbout to allocate exfld",jpi,jpj
+
+      ALLOCATE(exfld(1:jpi,1:jpj), stat = ierror)
+      IF (ierror > 0) THEN
+         CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in allocating Reals')
+         RETURN
+      ENDIF
+
+      IF ( rootexchg .and. localRank == localRoot ) THEN
+         ALLOCATE(ranges(5,0:localSize-1), stat = ierror)
+         IF (ierror > 0) THEN
+            CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in allocating Integer')
+            RETURN
+         ENDIF
+      ENDIF
+
+      !------------------------------------------------------------------
+      ! 1st Declare the local grid (ORCA tripolar) characteristics for
+      !     surface coupling. The halo regions must be excluded. For
+      !     surface coupling it is sufficient to specify only one
+      !     vertical z-level.
+      !------------------------------------------------------------------
+
+      grid_type = PRISM_irrlonlat_regvrt
+
+      IF(lwp) WRITE(numout,*) "Set grid type"
+
+
+      ! -----------------------------------------------------------------
+      ! ... Define the shape of the valid region without the halo.
+      !     For serial configuration (key_mpp_mpi not being active)
+      !     nl* is set to the global values 1 and jp*glo.
+      ! -----------------------------------------------------------------
+
+      IF ( rootexchg ) THEN
+         shape(1,1) = 1+jpreci
+         shape(2,1) = jpiglo-jpreci
+         shape(1,2) = 1+jpreci
+         shape(2,2) = jpjglo-jpreci
+         shape(1,3) = 1
+         shape(2,3) = 1
+      ELSE
+         shape(1,1) = 1+jpreci
+         shape(2,1) = jpi-jpreci
+         shape(1,2) = 1+jpreci
+         shape(2,2) = jpj-jpreci
+         shape(1,3) = 1
+         shape(2,3) = 1
+      ENDIF
+
+      IF(lwp) WRITE(numout,*) "commrank is", commRank
+
+      IF ( commRank ) THEN
+
+         IF(lwp) WRITE(numout,*) "CALLING DEF_GRID"
+
+         IF(lwp) WRITE(numout,*) "grid name",grid_name
+         IF(lwp) WRITE(numout,*) " shape",shape
+         IF(lwp) WRITE(numout,*) "grid type",grid_type
+
+         CALL prism_def_grid ( grid_id(1), grid_name, comp_id, shape, &
+              grid_type, ierror )
+         IF ( ierror /= PRISM_Success ) THEN
+            PRINT *, 'OPA cpl_prism_define: Failure in prism_def_grid'
+            CALL prism_abort (comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_def_grid')
+         ENDIF
+
+         !------------------------------------------------------------------
+         ! 2nd Declare the geometic information for this grid.
+         !------------------------------------------------------------------
+
+         ! -----------------------------------------------------------------
+         ! ... Redefine shape which may now include the halo region as well.
+         ! -----------------------------------------------------------------
+
+         shape(1,1) = 1
+         shape(2,1) = jpi
+         shape(1,2) = 1
+         shape(2,2) = jpj
+         shape(1,3) = 1
+         shape(2,3) = 1
+
+         IF(lwp) WRITE(numout,*) "redefined shape",shape
+
+         ! -----------------------------------------------------------------
+         ! ... Define the elements, i.e. specify the corner points for each
+         !     volume element. In case OPA runs on level coordinates (regular
+         !     in the vertical) we only need to give the 4 horizontal corners
+         !     for a volume element plus the vertical position of the upper
+         !     and lower face. Nevertheless the volume element has 8 corners.
+         ! -----------------------------------------------------------------
+
+         !
+         ! ... Treat corners in the horizontal plane
+         !
+         ALLOCATE(rclon(shape(1,1):shape(2,1),shape(1,2):shape(2,2),4), &
+              STAT=ierror)
+         IF ( ierror /= 0 ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: error in allocate for rclon')
+
+         ALLOCATE(rclat(shape(1,1):shape(2,1),shape(1,2):shape(2,2),4), &
+              STAT=ierror)
+         IF ( ierror /= 0 ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: error in allocate for rclon')
+
+         nbr_corners = 8
+         !
+         ! ... Set right longitudes and upper latitudes
+         !
+         DO jj = shape(1,2), shape(2,2)
+            DO ji = shape(1,1), shape(2,1)
+               rclon(ji,jj,1) = glamu(ji,jj)
+               rclon(ji,jj,2) = glamu(ji,jj)
+               rclat(ji,jj,2) = gphiv(ji,jj)
+               rclat(ji,jj,3) = gphiv(ji,jj)
+            ENDDO
+         ENDDO
+         !
+         ! ... Set the lower latitudes
+         !
+         DO jj = shape(1,2)+1, shape(2,2)
+            DO ji = shape(1,1), shape(2,1)
+               rclat(ji,jj-1,1) = rclat(ji,jj,2)
+               rclat(ji,jj-1,4) = rclat(ji,jj,3)
+            ENDDO
+         ENDDO
+         !
+         ! ... Set the left longitudes
+         !
+         DO jj = shape(1,2), shape(2,2)
+            DO ji = shape(1,1)+1, shape(2,1)
+               rclon(ji-1,jj,3) = rclon(ji,jj,2)
+               rclon(ji-1,jj,4) = rclon(ji,jj,1)
+            ENDDO
+         ENDDO
+         !
+         ! ... Set the lowermost latitudes 
+         !
+         DO jj = shape(1,2), shape(1,2)
+            DO ji = shape(1,1), shape(2,1)
+               rclat(ji,jj,1) = 2.0*gphit(ji,jj)-rclat(ji,jj,2)
+               rclat(ji,jj,4) = 2.0*gphit(ji,jj)-rclat(ji,jj,4)
+            ENDDO
+         ENDDO
+         !
+         ! ... Set the rightmost latitudes 
+         !
+         DO jj = shape(1,2), shape(2,2)
+            DO ji = shape(1,2), shape(1,2)
+               rclon(ji,jj,3) = 2.0*glamt(ji,jj)-rclon(ji,jj,2)
+               rclon(ji,jj,4) = 2.0*glamt(ji,jj)-rclon(ji,jj,1)
+
+               WRITE(76,*) "rclon", ji, jj, rclon(ji,jj,1), &
+                                            rclon(ji,jj,2), &
+                                            rclon(ji,jj,3), &
+                                            rclon(ji,jj,4)
+
+               WRITE(76,*) "rclat", ji, jj, rclat(ji,jj,1), &
+                                            rclat(ji,jj,2), &
+                                            rclat(ji,jj,3), &
+                                            rclat(ji,jj,4)
+
+            ENDDO
+         ENDDO
+
+         !
+         ! ... Treat corners along the vertical axis
+         !
+         ALLOCATE(rcz(shape(1,3):shape(2,3),2), STAT=ierror)
+         IF ( ierror /= 0 ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: error in allocate for rcz')
+
+         DO jk = shape(1,3), shape(2,3)
+            rcz(jk,1) = gdepw(jk)
+            rcz(jk,2) = gdepw(jk+1)
+         ENDDO
+
+         IF(lwp) WRITE(numout,*) "ABOUT TO CALL SET CORNERS",shape 
+
+         CALL prism_set_corners ( grid_id(1), nbr_corners, shape, rclon, rclat, &
+              rcz, ierror)
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_corners')
+
+         DEALLOCATE(rclon, rclat, rcz)
+
+         ! -----------------------------------------------------------------
+         ! ... Define the gridpoints  
+         ! -----------------------------------------------------------------
+
+         new_points = .TRUE.
+
+         IF(lwp) WRITE(numout,*) "CALLING SET_POINTS"
+
+         !
+         ! ... the u-points
+         !
+         point_name = 'u-points'
+         CALL prism_set_points ( upoint_id(1), point_name, grid_id(1), shape,      &
+              glamu, gphiu, gdept(shape(1,3):shape(2,3)), new_points, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_points upoint_id')
+         !
+         ! ... the v-points
+         !
+
+         IF(lwp) WRITE(numout,*) "CALLING SET_POINTS done u doing v"
+
+         point_name = 'v-points'
+         CALL prism_set_points ( vpoint_id(1), point_name, grid_id(1), shape,      &
+              glamv, gphiv, gdept(shape(1,3):shape(2,3)), new_points, ierror )      
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_points vpoint_id')
+         !
+         ! ... the t-points
+         !
+         ! WRITE(76,*) 'CALLING T POINTS', shape
+         ! WRITE(77,*) 'glamt', glamt
+         ! WRITE(78,*) 'gphit', gphit
+         !
+         point_name = 't-points'
+         CALL prism_set_points ( tpoint_id(1), point_name, grid_id(1), shape,   &
+              glamt, gphit, gdept(shape(1,3):shape(2,3)), new_points, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_points tpoint_id')
+         !
+         ! ... the f-points
+         !
+         point_name = 'f-points'
+         CALL prism_set_points ( fpoint_id(1), point_name, grid_id(1), shape,   &
+              glamf, gphif, gdept(shape(1,3):shape(2,3)), new_points, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_points fpoint_id')
+
+
+         IF(lwp) WRITE(numout,*) "CALLING SET_POINTS done f"
+
+         ! -----------------------------------------------------------------
+         ! ... Convert OPA masks to logicals and define the masks
+         ! -----------------------------------------------------------------
+
+         new_mask = .true.
+
+         mask = (umask == 1)
+         CALL prism_set_mask (umask_id(1), grid_id(1), shape, &
+                 mask(shape(1,1):shape(2,1),                  &
+                      shape(1,2):shape(2,2),                  &
+                      shape(1,3):shape(2,3)),                 &
+              new_mask, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_mask umask_id')
+
+         mask = (vmask == 1)
+         CALL prism_set_mask (vmask_id(1), grid_id(1), shape, &
+                 mask(shape(1,1):shape(2,1),                  &
+                      shape(1,2):shape(2,2),                  &
+                      shape(1,3):shape(2,3)),                 &
+              new_mask, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_mask umask_id')
+
+         mask = (tmask == 1)
+         CALL prism_set_mask (tmask_id(1), grid_id(1), shape, &
+                 mask(shape(1,1):shape(2,1),                  &
+                      shape(1,2):shape(2,2),                  &
+                      shape(1,3):shape(2,3)),                 &
+              new_mask, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_mask umask_id')
+
+         mask = (fmask == 1)
+         CALL prism_set_mask (fmask_id(1), grid_id(1), shape, &
+                 mask(shape(1,1):shape(2,1),                  &
+                      shape(1,2):shape(2,2),                  &
+                      shape(1,3):shape(2,3)),                 &
+              new_mask, ierror )
+         IF ( ierror /= PRISM_Success ) &
+              CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_set_mask umask_id')
+
+         IF(lwp) WRITE(numout,*) "DONE ALL THE SET MASKS"
+
+         ! -----------------------------------------------------------------
+         ! ... Define the angles
+         !   This is needed if zonal tau is not oriented E-W and meridional
+         !   tau is not oriented along N-S but rather along local coordinate
+         !   axis. Please check!!!!
+         ! -----------------------------------------------------------------
+
+!rr      cal prism_set_angles ( ..., ierror ) ! not yet supported by OASIS4
+
+         ! -----------------------------------------------------------------
+         ! ... Define the partition 
+         ! -----------------------------------------------------------------
+         
+         IF ( rootexchg ) THEN
+
+            range(1) = nimpp-1+nldi   ! global start in i
+            range(2) = nlei-nldi+1    ! local size in i of valid region
+            range(3) = njmpp-1+nldj   ! global start in j
+            range(4) = nlej-nldj+1    ! local size in j of valid region
+            range(5) = range(2) &
+                     * range(4)       ! local horizontal size
+            !
+            ! Collect ranges from all NEMO procs on the local root process
+            !
+            CALL mpi_gather(range,  5, MPI_INTEGER, &
+                            ranges, 5, MPI_INTEGER, localRoot, localComm, ierror)
+
+            IF ( localRank == localRoot ) THEN
+
+               maxlen = maxval(ranges(5,:))
+
+               ALLOCATE(buffer(1:maxlen), stat = ierror)
+               IF (ierror > 0) THEN
+                  CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in allocating buffer')
+                  RETURN
+               ENDIF
+
+            ENDIF
+
+         ENDIF
+
+         ! -----------------------------------------------------------------
+         ! ... Define the scalefactors 
+         ! -----------------------------------------------------------------
+
+!rr      WRITE(numout,*) "CALLING SCALEFACTOR"
+!rr      call prism_set_scalefactor ( grid_id(1), shape, e1t, e2t, e3t, ierror )  ! not yet supported by OASIS4
+!rr      WRITE(numout,*) "ABOUT TO DEFINE THE TRANSIENTS"
+
+         !------------------------------------------------------------------
+         ! 3rd Declare the transient variables
+         !------------------------------------------------------------------
+         !
+         ! ... Define symbolic names for the transient fields send by the ocean
+         !     These must be identical to the names specified in the SMIOC file.
+         !
+         cpl_send( 1)='SOSSTSST' ! sea surface temperature              -> sst_io
+         cpl_send( 2)='SITOCEAN' ! sea ice thickness                    -> hicif (only 1 layer available!)
+#if defined key_cpl_albedo
+         cpl_send( 3)='STIOCEAN' ! surface temperature over sea ice     -> tn_ice
+         cpl_send( 4)='SAIOCEAN' ! albedo over sea ice                  -> alb_ice
+#else
+         cpl_send( 3)='SITOCEAN' ! sea ice thickness                    -> hicif (only 1 layer available!)
+         cpl_send( 4)='SNTOCEAN' ! surface snow thickness over sea ice  -> hsnif
+#endif
+#if defined key_cpl_ocevel
+         cpl_send( 5)='SUNOCEAN' ! U-velocity                           -> un
+         cpl_send( 6)='SVNOCEAN' ! V-velocity                           -> vn
+#endif
+         !
+         ! ...  Define symbolic names for transient fields received by the ocean.
+         !      These must be identical to the names specified in the SMIOC file.
+         !
+         ! ...  a) U-Grid fields
+         !
+         cpl_recv( 1)='TXWOCEWU' ! weighted surface downward eastward stress
+         cpl_recv( 2)='TYWOCEWU' ! weighted surface downward northward stress
+         cpl_recv( 3)='TXIOCEWU' ! weighted surface downward eastward stress over ice
+         cpl_recv( 4)='TYIOCEWU' ! weighted surface downward northward stress over ice
+         !
+         ! ...  a) V-Grid fields
+         !
+         cpl_recv( 5)='TXWOCEWV' ! weighted surface downward eastward stress
+         cpl_recv( 6)='TYWOCEWV' ! weighted surface downward northward stress
+         cpl_recv( 7)='TXIOCEWV' ! weighted surface downward eastward stress over ice
+         cpl_recv( 8)='TYIOCEWV' ! weighted surface downward northward stress over ice
+         !
+         ! ...  a) T-Grid fields
+         !
+         cpl_recv( 9)='FRWOCEPE' ! P-E over water                               -> zpew
+         cpl_recv(10)='FRIOCEPE' ! P-E over ice                                 -> zpei
+         cpl_recv(11)='FRROCESN' ! surface downward snow fall                   -> zpsol
+         cpl_recv(12)='FRIOCEEV' ! surface upward snow flux where sea ice       -> zevice
+
+         cpl_recv(13)='QSWOCESR' ! surface net downward shortwave flux          -> qsr_oce
+         cpl_recv(14)='QSWOCENS' ! surface downward non-solar heat flux in air  -> qnsr_oce
+         cpl_recv(15)='QSIOCESR' ! solar heat flux on sea ice                   -> qsr_ice
+         cpl_recv(16)='QSIOCENS' ! non-solar heat flux on sea ice               -> qnsr_ice
+         cpl_recv(17)='QSIOCEDQ' ! non-solar heat flux derivative               -> dqns_ice
+
+#ifdef key_cpl_discharge
+         cpl_recv(18)='FRWOCEIS' ! ice discharge into ocean                     -> calving
+         cpl_recv(19)='FRWOCERD' ! river discharge into ocean                   -> zrunriv
+         cpl_recv(20)='FRWOCECD' ! continental discharge into ocean             -> zruncot
+#endif
+         IF ( wp == 4 ) data_type = PRISM_REAL
+         IF ( wp == 8 ) data_type = PRISM_DOUBLE_PRECISION
+
+         nodim(1) = 3 ! check
+         nodim(2) = 0
+         !
+         ! ... Announce send variables, all on T points. 
+         !
+         DO ji = 1, nsend
+            ! if ( ji == 2 ) ; then ; nodim(2) = 2 ; else ; nodim(2) = 0 ; endif
+            CALL prism_def_var (send_id(ji), cpl_send(ji), grid_id(1), &
+                 tpoint_id(1), tmask_id(1), nodim, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Success ) THEN
+               PRINT *, 'Failed to define transient ', ji, TRIM(cpl_send(ji))
+               CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         nodim(1) = 3 ! check
+         nodim(2) = 0
+         !
+         ! ... Announce recv variables. 
+         !
+         ! ... a) on U points
+         !
+         DO ji = 1, 4
+            CALL prism_def_var (recv_id(ji), cpl_recv(ji), grid_id(1), &
+                 upoint_id(1), umask_id(1), nodim, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Success ) THEN
+               PRINT *, 'Failed to define transient ', ji, TRIM(cpl_recv(ji))
+               CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         ! ... b) on V points
+         !
+         DO ji = 5, 8 
+            CALL prism_def_var (recv_id(ji), cpl_recv(ji), grid_id(1), &
+                 vpoint_id(1), vmask_id(1), nodim, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Success ) THEN
+               PRINT *, 'Failed to define transient ', TRIM(cpl_recv(ji))
+               CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_def_var')
+            ENDIF
+         ENDDO
+         !
+         ! ... c) on T points
+         !
+         DO ji = 9, nrecv
+            CALL prism_def_var (recv_id(ji), "SORUNOFF", grid_id(1), &
+                 tpoint_id(1), tmask_id(1), nodim, shape, data_type, ierror)
+            IF ( ierror /= PRISM_Success ) THEN
+               PRINT *, 'Failed to define transient ', TRIM(cpl_recv(ji))
+               CALL prism_abort ( comp_id, 'OPA9.0', 'OPA cpl_prism_define: Failure in prism_def_var')
+            ENDIF
+         ENDDO
+
+      ENDIF ! commRank
+
+      !------------------------------------------------------------------
+      ! 4th End of definition phase
+      !------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*) "ABOUT TO CALL PRISM_ENDDEF" 
+
+      CALL prism_enddef(ierror)
+
+      IF(lwp) WRITE(numout,*) "DONE ENDDEF",ierror
+
+      IF ( ierror /= PRISM_Success ) &
+         CALL prism_abort ( comp_id, 'OPA9.0', 'cpl_prism_define: Failure in prism_enddef')
+        
+      IF(lwp) WRITE(numout,*) "ALL DONE, EXITING PRISM SET UP PHASE"
+ 
+   END SUBROUTINE cpl_prism_define
+
+
+
+   SUBROUTINE cpl_prism_send( var_id, date, data_array, info )
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_send  ***
+      !!
+      !! ** Purpose : - At each coupling time-step,this routine sends fields
+      !!      like sst or ice cover to the coupler or remote application.
+      !!
+      !! ** Method  : OASIS4
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT( IN )  :: var_id    ! variable Id
+      INTEGER, INTENT( OUT ) :: info      ! variable Id
+      INTEGER, INTENT( IN )  :: date      ! ocean time-step in seconds
+      REAL(wp)               :: data_array(:,:)
+      !!
+      !! * Local declarations
+      !!
+#if defined key_mpp_mpi
+      REAL(wp)               :: global_array(jpiglo,jpjglo)
+      !
+!mpi  INTEGER                :: status(MPI_STATUS_SIZE)
+!mpi  INTEGER                :: type       ! MPI data type
+      INTEGER                :: request    ! MPI isend request
+      INTEGER                :: ji, jj, jn ! local loop indicees
+#else
+      INTEGER                :: ji
+#endif
+      !!
+      INTEGER, SAVE          :: ncount = 0
+      !!
+      !!--------------------------------------------------------------------
+      !!
+      ncount = ncount + 1
+
+#if defined key_mpp_mpi
+
+      request = 0
+
+      IF ( rootexchg ) THEN
+         !
+!mpi     IF ( wp == 4 ) type = MPI_REAL
+!mpi     IF ( wp == 8 ) type = MPI_DOUBLE_PRECISION
+         !
+         ! collect data on the local root process
+         !
+         IF ( localRank /= localRoot ) THEN
+
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  exfld(ji-nldi+1,jj-nldj+1)=data_array(ji,jj)
+               ENDDO
+            ENDDO
+
+!mpi        CALL mpi_send(exfld, range(5), type, localRoot, localRank, localComm, ierror)
+            CALL mppsend (localRank, exfld, range(5), localRoot, request)
+         ENDIF
+
+         IF ( localRank == localRoot ) THEN
+
+            DO jj = ranges(3,localRoot), ranges(3,localRoot)+ranges(4,localRoot)-1
+               DO ji = ranges(1,localRoot), ranges(1,localRoot)+ranges(2,localRoot)-1
+                  global_array(ji,jj) = data_array(ji,jj) ! workaround
+               ENDDO
+            ENDDO
+
+            DO jn = 1, localSize-1
+
+!mpi           CALL mpi_recv(buffer, ranges(5,jn), type, localRoot, jn, localComm, status, ierror)
+               CALL mpprecv(jn, buffer, ranges(5,jn))
+
+               DO jj = ranges(3,jn), ranges(3,jn)+ranges(4,jn)-1
+                  DO ji = ranges(1,jn), ranges(1,jn)+ranges(2,jn)-1
+                     global_array(ji,jj) = buffer( (jj-ranges(3,jn))*ranges(2,jn) + ji-ranges(1,jn)+1 )
+                  ENDDO
+               ENDDO
+
+            ENDDO
+
+         ENDIF
+         !
+         ! send data from local root to OASIS4
+         !
+         CALL prism_put ( var_id, dates, dates_bound, global_array, info, ierror )      
+
+      ELSE
+         !
+         ! send local data from every process to OASIS4
+         !
+         CALL prism_put ( var_id, dates, dates_bound, data_array, info, ierror )      
+
+      ENDIF !rootexchg
+
+#else
+
+      !
+      ! send local data from every process to OASIS4
+      !
+      IF ( commRank ) &
+      CALL prism_put ( var_id, dates, dates_bound, data_array, info, ierror )      
+
+#endif
+
+      IF ( commRank ) THEN
+
+         IF (l_ctl) THEN
+
+            IF ( info==PRISM_Cpl ) THEN
+               WRITE(numout,*) '****************'
+               DO ji = 1, nsend
+                  IF (var_id == send_id(ji) ) THEN
+                     WRITE(numout,*) 'prism_put_proto: Outgoing ', cpl_send(ji)
+                     EXIT
+                  ENDIF
+               ENDDO
+               WRITE(numout,*) 'prism_put: var_id       ', var_id
+               WRITE(numout,*) 'prism_put:   date       ', date
+               WRITE(numout,*) 'prism_put:   info       ', info
+               WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+               WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+               WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+               WRITE(numout,*) '****************'
+            ENDIF
+
+         ENDIF
+
+         IF ( ncount == nrecv ) THEN
+            !
+            !  3. Update dates and dates_bound for next step. We assume that cpl_prism_send
+            !  is called for all send fields at each time step. Therefore we update
+            !  the date argument to prism_put only every nsend call to cpl_prism_send.
+            !
+            dates_bound(1) = dates_bound(2)
+
+            tmpdate    = dates_bound(2)
+            date_incr  = rdCplttra(1)/2.0
+
+            CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+            dates = tmpdate
+            CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+            dates_bound(2) = tmpdate
+
+            ncount = 0
+
+         ENDIF
+
+      ENDIF ! commRank
+
+   END SUBROUTINE cpl_prism_send
+
+
+
+   SUBROUTINE cpl_prism_recv(  var_id, date, data_array, info )
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_recv  ***
+      !!
+      !! ** Purpose : - At each coupling time-step,this routine receives fields
+      !!      like stresses and fluxes from the coupler or remote application.
+      !!
+      !! ** Method  : OASIS4
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      !!
+      INTEGER, INTENT( IN )  :: var_id    ! variable Id
+      INTEGER, INTENT( OUT ) :: info      ! variable Id
+      INTEGER, INTENT( IN )  :: date      ! ocean time-step in seconds
+      REAL(wp),INTENT( OUT ) :: data_array(:,:)
+      !!
+      !! * Local declarations
+      !!
+#if defined key_mpp_mpi
+      REAL(wp)               :: global_array(jpiglo,jpjglo)
+      !
+      LOGICAL                :: action = .false.
+!mpi  INTEGER                :: status(MPI_STATUS_SIZE)
+!mpi  INTEGER                :: type       ! MPI data type
+      INTEGER                :: request    ! MPI isend request
+      INTEGER                :: ji, jj, jn ! local loop indicees
+#else
+      INTEGER                :: ji
+#endif
+
+      INTEGER, SAVE          :: ncount = 0
+      !!
+      !!--------------------------------------------------------------------
+      !!
+      ncount  = ncount + 1
+
+#ifdef key_mpp_mpi
+
+      request = 0
+
+      IF ( rootexchg ) THEN
+         !
+         ! receive data from OASIS4 on local root
+         !
+         IF ( commRank ) &
+         CALL prism_get (var_id, dater, dater_bound, global_array, info, ierror)
+         CALL MPI_BCAST ( info, 1, MPI_INTEGER, localRoot, localComm, ierror )
+
+      ELSE
+         !
+         ! receive local data from OASIS4 on every process
+         !
+         CALL prism_get (var_id, dater, dater_bound, exfld, info, ierror)
+
+      ENDIF
+
+      action = (info==PRISM_CplIO)
+
+      IF ( rootexchg .and. action ) THEN
+         !
+!mpi     IF ( wp == 4 ) type = MPI_REAL
+!mpi     IF ( wp == 8 ) type = MPI_DOUBLE_PRECISION
+         !
+         ! distribute data to processes
+         !
+         IF ( localRank == localRoot ) THEN
+
+            DO jj = ranges(3,localRoot), ranges(3,localRoot)+ranges(4,localRoot)-1
+               DO ji = ranges(1,localRoot), ranges(1,localRoot)+ranges(2,localRoot)-1
+                  exfld(ji,jj) = global_array(ji,jj)
+               ENDDO
+            ENDDO
+
+            DO jn = 1, localSize-1
+
+               DO jj = ranges(3,jn), ranges(3,jn)+ranges(4,jn)-1
+                  DO ji = ranges(1,jn), ranges(1,jn)+ranges(2,jn)-1
+                     buffer( (jj-ranges(3,jn))*ranges(2,jn) + ji-ranges(1,jn)+1 ) = global_array(ji,jj)
+                  ENDDO
+               ENDDO
+
+!mpi           CALL mpi_send(buffer, ranges(5,jn), type, jn, jn, localComm, ierror)
+               CALL mppsend (jn, buffer, ranges(5,jn), jn, request)  
+
+            ENDDO
+
+         ENDIF
+
+         IF ( localRank /= localRoot ) &
+!mpi         CALL mpi_recv(exfld, range(5), type, localRoot, localRank, localComm, status, ierror)
+             CALL mpprecv(localRank, exfld, range(5))
+      ENDIF
+
+      IF ( action ) THEN
+
+         data_array = 0.0
+
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               data_array(ji,jj)=exfld(ji-nldi+1,jj-nldj+1)
+            ENDDO
+         ENDDO
+
+         IF (l_ctl) THEN        
+            WRITE(numout,*) '****************'
+            DO ji = 1, nrecv
+               IF (var_id == recv_id(ji) ) THEN
+                  WRITE(numout,*) 'prism_get: Incoming ', cpl_recv(ji)
+                  EXIT
+               ENDIF
+            ENDDO
+            WRITE(numout,*) 'prism_get: var_id       ', var_id
+            WRITE(numout,*) 'prism_get:   date       ', date
+            WRITE(numout,*) 'prism_get:   info       ', info
+            WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+            WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+            WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+            WRITE(numout,*) '****************'
+         ENDIF
+
+      ENDIF
+#else
+
+      CALL prism_get (var_id, dater, dater_bound, exfld, info, ierror)
+
+      IF ( info==PRISM_CplIO ) THEN
+               data_array=exfld
+
+         IF (l_ctl) THEN        
+            WRITE(numout,*) '****************'
+            DO ji = 1, nrecv
+               IF (var_id == recv_id(ji) ) THEN
+                  WRITE(numout,*) 'prism_get: Incoming ', cpl_recv(ji)
+                  EXIT
+               ENDIF
+            ENDDO
+            WRITE(numout,*) 'prism_get: var_id       ', var_id
+            WRITE(numout,*) 'prism_get:   date       ', date
+            WRITE(numout,*) 'prism_get:   info       ', info
+            WRITE(numout,*) '     - Minimum value is ', MINVAL(data_array)
+            WRITE(numout,*) '     - Maximum value is ', MAXVAL(data_array)
+            WRITE(numout,*) '     -     Sum value is ', SUM(data_array)
+            WRITE(numout,*) '****************'
+         ENDIF
+
+      ENDIF
+
+#endif
+
+      IF ( ncount == nrecv ) THEN
+         !
+         !  3. Update dater and dater_bound for next step. We assume that cpl_prism_recv
+         !  is called for all recv fields at each time step. Therefore we update
+         !  the date argument to prism_get only every nrecv call to cpl_prism_recv.
+         !
+         dater_bound(1) = dater_bound(2)
+
+         tmpdate    = dater_bound(2)
+         date_incr  = rdttra(1)/2.0
+
+         CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+         dater = tmpdate
+         CALL PRISM_calc_newdate ( tmpdate, date_incr, ierror )
+         dater_bound(2) = tmpdate
+
+         ncount = 0
+
+      ENDIF
+
+   END SUBROUTINE cpl_prism_recv
+
+
+
+   SUBROUTINE cpl_prism_finalize
+
+      IMPLICIT NONE
+
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE cpl_prism_finalize  ***
+      !!
+      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
+      !!      called explicitly before cpl_prism_init it will also close
+      !!      MPI communication.
+      !!
+      !! ** Method  : OASIS4
+      !!----------------------------------------------------------------------
+
+      DEALLOCATE(exfld)
+
+      if ( prism_was_initialized ) then
+
+         call prism_terminated ( prism_was_terminated, ierror )
+         
+         if ( prism_was_terminated ) then
+            print *, 'prism has already been terminated.'
+         else
+            call prism_terminate ( ierror )
+            prism_was_terminated = .true.
+         endif
+
+      else
+
+         print *, 'Initialize prism before terminating it.'
+
+      endif
+
+
+   END SUBROUTINE cpl_prism_finalize
+
+#else
+
+   !!----------------------------------------------------------------------
+   !!   Default case           Dummy module         forced Ocean/Atmosphere
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE cpl_prism_init             ! Dummy routine
+   END SUBROUTINE cpl_prism_init
+   SUBROUTINE cpl_prism_define           ! Dummy routine
+   END SUBROUTINE cpl_prism_define
+   SUBROUTINE cpl_prism_send             ! Dummy routine
+   END SUBROUTINE cpl_prism_send
+   SUBROUTINE cpl_prism_recv             ! Dummy routine
+   END SUBROUTINE cpl_prism_recv
+   SUBROUTINE cpl_prism_finalize         ! Dummy routine
+   END SUBROUTINE cpl_prism_finalize
+
+#endif
+
+END MODULE cpl_oasis4
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90	(revision 4536)
@@ -0,0 +1,193 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flx_bulk_daily  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   bulk          : reading 
+   !!----------------------------------------------------------------------
+   !! * Modules used     C A U T I O N  already defined in flxmod.F90
+
+   !! * Module variables
+   
+   INTEGER ::          &
+      ji, jj,          &  ! loop indices
+      numfl1, numfl2,  &  ! logical units for surface fluxes data
+      numfl3, numfl4,  &  ! 
+      nflx1 , nflx2 ,  &  !  first and second record used
+      ndayflx
+
+   REAL(wp), DIMENSION(jpi,jpj,2,3) ::   &
+      flxdta              ! 2 consecutive set of CLIO/CMAP monthly fluxes
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE flx  ***
+      !!        
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater)
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method :
+      !!       ORCA FORCED VERSION WITH :
+      !!       Daily climatological NCEP temperature
+      !!       Daily climatological ERS-NCEP winds
+      !!       monthly climatological humidity and clouds
+      !!       monthly climatological CMAP precipitation
+      !!       Read several AGCM daily and monthly fluxes file
+      !!             temperature at 2m   tatm   (K)
+      !!             relative humidite   hatm   (%)
+      !!             wind speed          vatm   (m/s)
+      !!             monthly precip      watm   (kg/m2/day)  from Xie/Arkin
+      !!             clouds              catm   (%)
+      !!
+      !! caution : now, in the opa global model, the net upward water flux is
+      !! -------   with mm/day unit.
+      !!
+      !! History :
+      !!        !  91-03  (O. Marti and Ph Dandin)  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  96-11  (E. Guilyardi)  Daily AGCM input files
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with io-ipsl
+      !!        !  00-05  (K. Rodgers) Daily Netcdf
+      !!   8.5  !  02-09  (C. Ethe and G. Madec)  F90: Free form and MODULE 
+      !!----------------------------------------------------------------------
+      !! * modules used
+      USE iom             ! I/O library
+      USE blk_oce         ! bulk variable
+      USE bulk            ! bulk module
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt ! ocean time step
+
+      !! * Local declarations      
+      INTEGER  ::   iman,imois,i15
+      REAL(wp) ::   zxy
+      !!---------------------------------------------------------------------
+
+
+      ! Initialization
+      ! --------------
+
+      i15 = INT(2*FLOAT(nday)/(FLOAT(nobis(nmonth))+0.5))
+      iman  = INT( raamo )
+      imois = nmonth + i15 - 1
+      IF (imois == 0) imois = iman
+
+
+      ! 1. first call kt = nit000
+      ! -----------------------
+      
+      IF( kt == nit000 ) THEN
+         ! initializations
+         nflx1 = 0
+         ndayflx = 0
+         IF(lwp) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' **** Routine flx_bulk_daily.h90'
+            WRITE(numout,*) ' '
+         ENDIF         
+         ! open files
+         IF(lwp) WRITE(numout,*) ' **** global NCEP flx  daily fields '
+         CALL iom_open ( 'tair_1d.nc', numfl1 )
+         IF(lwp) WRITE(numout,*) ' **** global CLIO flx  monthly fields '
+         CALL iom_open ( 'hum_cloud_1m.nc', numfl2 )
+         IF(lwp) WRITE(numout,*) ' **** global XIE  flx  monthly fields '
+         CALL iom_open ( 'rain_1m.nc', numfl3 )
+         IF(lwp) WRITE(numout,*) ' **** global ERS-NCEP  wind daily  fields '
+         CALL iom_open ( 'wspd_1d.nc', numfl4 )
+      ENDIF
+
+
+      ! 2. Read daily DATA Temperature from NCEP
+      ! ---------------------------------------
+      
+      IF( ndayflx /= nday ) THEN 
+         
+         ndayflx = nday
+         
+         ! read T 2m (Caution in K)
+         CALL iom_get ( numfl1, jpdom_data, 'air', tatm, nday_year )
+         
+         IF(lwp) WRITE (numout,*)' Lecture daily flx record OK :',nday_year
+         IF(lwp) WRITE (numout,*)' '
+         
+         ! conversion of temperature Kelvin --> Celsius  [rt0=273.15]
+         tatm(:,:) = ( tatm(:,:) - rt0 ) 
+         
+         ! read wind speed
+         CALL iom_get ( numfl4, jpdom_data, 'wspd', vatm, nday_year )
+         
+         IF(lwp) WRITE (numout,*)' Lecture daily wind speed flx :',nday_year
+         IF(lwp) WRITE (numout,*)' '
+         
+      ENDIF
+
+      
+      !  3. Read monthly data from CLIO and From Xie
+      !  -------------------------------------------
+      
+      IF( kt == nit000 .OR. imois /= nflx1 ) THEN
+         
+         ! calendar computation
+         
+         ! nflx1 number of the first file record used in the simulation
+         ! flx2 number of the last  file record
+         
+         nflx1 = imois
+         nflx2 = nflx1+1
+         nflx1 = MOD(nflx1,iman)
+         IF ( nflx1 == 0 ) nflx1 = iman
+         nflx2 = MOD(nflx2,iman)
+         IF ( nflx2 == 0 ) nflx2 = iman
+         IF(lwp)WRITE(numout,*) 'first record file used nflx1 ',nflx1
+         IF(lwp)WRITE(numout,*) 'last  record file used nflx2 ',nflx2
+
+         ! Read monthly fluxes data Esbensen Kushnir 
+
+         ! humidity
+         CALL iom_get ( numfl2, jpdom_data, 'socliohu', flxdta(:,:,1,1), nflx1 )
+         CALL iom_get ( numfl2, jpdom_data, 'socliohu', flxdta(:,:,2,1), nflx2 )
+
+         ! clouds
+         CALL iom_get ( numfl2, jpdom_data, 'socliocl', flxdta(:,:,1,2), nflx1 )
+         CALL iom_get ( numfl2, jpdom_data, 'socliocl', flxdta(:,:,2,2), nflx2 )
+
+         ! Read monthly precipitations ds flxdta(:,:,1 ou 2,4) 
+
+         CALL iom_get ( numfl3, jpdom_data, 'rain', flxdta(:,:,1,3), nflx1 )
+         CALL iom_get ( numfl3, jpdom_data, 'rain', flxdta(:,:,2,3), nflx2 )
+                  
+      ENDIF
+
+
+      ! 3. at every time step linear interpolation of precipitation fluxes
+      ! -----------------------------------------------------------
+      
+      zxy = FLOAT(nday) / FLOAT(nobis(nflx1)) + 0.5 - i15
+
+      hatm(:,:) = ( (1.-zxy) * flxdta(:,:,1,1) + zxy  * flxdta(:,:,2,1) ) 
+      catm(:,:) = ( (1.-zxy )* flxdta(:,:,1,2) + zxy  * flxdta(:,:,2,2) )  
+      watm(:,:) = ( (1.-zxy) * flxdta(:,:,1,3) + zxy  * flxdta(:,:,2,3) ) 
+
+      ! 4. Closing all files
+      ! --------------------
+
+      IF( kt == nitend ) THEN
+         CALL iom_close (numfl1)
+         CALL iom_close (numfl2)
+         CALL iom_close (numfl3)
+         CALL iom_close (numfl4)
+      ENDIF
+
+      CALL blk(kt)
+      
+      CALL FLUSH(numout)
+      
+   END SUBROUTINE flx
+   
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90	(revision 4536)
@@ -0,0 +1,236 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flx_blulk_monthly.h90  ***
+   !!----------------------------------------------------------------------
+   !!   flx     : update surface thermohaline fluxes using bulk formulae
+   !!             and fields read in a NetCDF file
+   !!----------------------------------------------------------------------
+   !! * Modules used     C A U T I O N  already defined in flxmod.F90
+
+   !! * Module variables
+   
+   INTEGER ::          &
+      ji, jj,          &  ! loop indices
+      numflx,          &  ! logical unit for surface fluxes data
+      nflx1 , nflx2,   &  !  first and second record used
+      nflx11, nflx12      ! ???
+
+   INTEGER, PARAMETER :: jpf    =  7                   
+   REAL(wp), DIMENSION(jpi,jpj,2,jpf) ::   &
+      flxdta              ! 2 consecutive set of CLIO monthly fluxes
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE flx  ***
+      !!                   
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater) 
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method  :   Read monthly climatological fluxes in a NetCDF file
+      !!          the net downward radiative flux qsr      1 (watt/m2)
+      !!          the net downward heat flux      q        2 (watt/m2)
+      !!          the net upward water            emp      3 (mm/month)
+      !!              (evaporation - precipitation)
+      !!          the climatological ice cover    rclice   4 (0 or 1)
+      !!
+      !!     Qsr and q is obtained from Esbensen-Kushnir data (opal file) with
+      !!   some corrections :
+      !!          - Data are extended over the polar area and for the net heat
+      !!            flux, values are put at 200 w/m2 on the ice regions
+      !!          - Red sea and Mediterranean values are imposed.
+      !! 
+      !!     emp is the Oberhuber climatology with a function of Levitus 
+      !!   salinity
+      !! 
+      !!     rclice is an handmade climalological ice cover on the polar 
+      !!   regions.
+      !! 
+      !!     runoff is an handmade climalological runoff.
+      !!
+      !! caution : now, in the opa global model, the net upward water flux is
+      !! -------   with mm/day unit.
+      !!
+      !! History :
+      !!        !  91-03  (O. Marti and Ph Dandin)  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  96-11  (E. Guilyardi)  Daily AGCM input files
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with io-ipsl
+      !!        !  00-10  (J.-P. Boulanger)  adjusted for reading any
+      !!                         daily wind stress data including a climatology
+      !!        !  01-09  (A. Lazar and C. Levy)  Daily NetCDF by default
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * modules used
+      USE iom
+      USE blk_oce         ! bulk variable
+      USE bulk            ! bulk module
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER ::   jm            ! dummy loop indices
+      INTEGER ::   &
+         imois, imois2,       &  ! temporary integers
+         i15  , iman             !    "          "
+      REAL(wp) ::   &
+         zxy   , zdtt  ,      &  !    "         "
+         zttbt , zttat ,      &  !    "         "
+         zdtts6                  !    "         "
+      !!---------------------------------------------------------------------
+
+      ! Initialization
+      ! --------------
+
+      i15 = INT( 2 * FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+      iman  = INT( raamo )
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+      imois2 = nmonth
+
+      ! 1. first call kt=nit000
+      ! -----------------------
+
+      IF( kt == nit000 ) THEN
+         ! initializations
+         nflx1  = 0
+         nflx11 = 0
+         ! open the file
+         IF(lwp) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' **** Routine flx_bulk_monthly.h90'
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' global CLIO flx monthly fields'
+         ENDIF
+         CALL iom_open ( 'flx.nc', numflx )
+        
+         ! temperature, spline initialization, we read the first record
+         CALL iom_get ( numflx, jpdom_data, 'socliot1', flxdta(:,:,1,5), 1 )
+
+      ENDIF
+
+
+      ! Read monthly file
+      ! ----------------
+
+      IF( kt == nit000 .OR. imois /= nflx1 ) THEN
+
+         ! Calendar computation
+
+         ! nflx1 number of the first file record used in the simulation
+         ! nflx2 number of the last  file record
+
+         nflx1 = imois
+         nflx2 = nflx1+1
+         nflx1 = MOD( nflx1, iman )
+         nflx2 = MOD( nflx2, iman )
+         IF( nflx1 == 0 )   nflx1 = iman
+         IF( nflx2 == 0 )   nflx2 = iman
+         IF(lwp) WRITE(numout,*) 'first record file used nflx1 ',nflx1
+         IF(lwp) WRITE(numout,*) 'last  record file used nflx2 ',nflx2
+         
+         ! Read monthly fluxes data
+
+         ! humidity
+         CALL iom_get ( numflx, jpdom_data, 'socliohu', flxdta(:,:,1,1), nflx1 )
+         CALL iom_get ( numflx, jpdom_data, 'socliohu', flxdta(:,:,2,1), nflx2 )
+         ! 10m wind module
+         CALL iom_get ( numflx, jpdom_data, 'socliowi', flxdta(:,:,1,2), nflx1 )
+         CALL iom_get ( numflx, jpdom_data, 'socliowi', flxdta(:,:,2,2), nflx2 )
+         ! cloud cover
+         CALL iom_get ( numflx, jpdom_data, 'socliocl', flxdta(:,:,1,3), nflx1 )
+         CALL iom_get ( numflx, jpdom_data, 'socliocl', flxdta(:,:,2,3), nflx2 )
+         ! precipitations
+         CALL iom_get ( numflx, jpdom_data, 'socliopl', flxdta(:,:,1,4), nflx1 )
+         CALL iom_get ( numflx, jpdom_data, 'socliopl', flxdta(:,:,2,4), nflx2 )
+         
+         IF(lwp .AND. nitend-nit000 <= 100 ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' read clio flx ok'
+            WRITE(numout,*)
+            DO jm = 1, 4
+               WRITE(numout,*)
+               WRITE(numout,*) 'Clio mounth: ',nflx1,'  field: ',jm,' multiply by ',0.1
+               CALL prihre( flxdta(:,:,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout )
+            END DO
+         ENDIF
+
+      ENDIF
+
+      IF( kt == nit000 .OR. imois2 /= nflx11 ) THEN
+
+         ! calendar computation
+         
+         ! nflx1 number of the first file record used in the simulation
+         ! nflx2 number of the last  file record
+         
+         nflx11 = imois2
+         nflx12 = nflx11 + 1
+         nflx11 = MOD( nflx11, iman )
+         nflx12 = MOD( nflx12, iman )
+         IF( nflx11 == 0 )   nflx11 = iman
+         IF( nflx12 == 0 )   nflx12 = iman
+         IF(lwp) WRITE(numout,*) 'first record file used nflx11 ',nflx11
+         IF(lwp) WRITE(numout,*) 'last  record file used nflx12 ',nflx12
+         
+         ! Read monthly fluxes data Esbensen Kushnir 
+         
+         ! air temperature
+         ! Utilisation d'un spline, on lit le champ a mois=nflx1 et nflx2
+         CALL iom_get (numflx,jpdom_data,'socliot1',flxdta(:,:,1,6),nflx11)
+         CALL iom_get (numflx,jpdom_data,'socliot1',flxdta(:,:,2,6),nflx12)
+         ! air temperature derivative (to reconstruct a daily field)
+         CALL iom_get (numflx,jpdom_data,'socliot2',flxdta(:,:,1,7),nflx11)
+         CALL iom_get (numflx,jpdom_data,'socliot2',flxdta(:,:,2,7),nflx12)
+          
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' read CLIO flx ok'
+            WRITE(numout,*)
+            DO jm = 6, jpf
+               WRITE(numout,*) 'jpf =  ', jpf !C a u t i o n : information need for SX5NEC compilo bug
+               WRITE(numout,*) 'Clio mounth: ',nflx11,'  field: ',jm,' multiply by ',0.1
+               CALL prihre(flxdta(:,:,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
+               WRITE(numout,*)
+            END DO
+         ENDIF
+
+      ENDIF
+
+
+      ! 3. at every time step interpolation of fluxes
+      ! ---------------------------------------------
+
+      zxy = FLOAT( nday ) / FLOAT( nobis(nflx1) ) + 0.5 - i15
+
+      zdtt = raajj / raamo
+      zttbt = (REAL(nday) - 1.)/(nobis(nmonth) - 1.)
+
+      zttat = 1. - zttbt
+      zdtts6 = zdtt/6.
+
+      hatm(:,:) = ( (1.-zxy) * flxdta(:,:,1,1) + zxy * flxdta(:,:,2,1) )
+      vatm(:,:) = ( (1.-zxy) * flxdta(:,:,1,2) + zxy * flxdta(:,:,2,2) )
+      catm(:,:) = ( (1.-zxy )* flxdta(:,:,1,3) + zxy * flxdta(:,:,2,3) )
+      watm(:,:) = ( (1.-zxy) * flxdta(:,:,1,4) + zxy * flxdta(:,:,2,4) )
+      tatm(:,:) = ( flxdta(:,:,2,6) - flxdta(:,:,1,6) )/zdtt   &
+                - ((3. * zttat * zttat - 1.) * flxdta(:,:,1,7)   &
+                - ( 3. * zttbt * zttbt - 1.) * flxdta(:,:,2,7) ) * zdtts6   &
+                + flxdta(:,:,1,5)
+ 
+      CALL blk( kt )                ! bulk formulea fluxes 
+
+      ! ------------------- !
+      ! Last call kt=nitend !
+      ! ------------------- !
+
+      ! Closing of the numflx file (required in mpp)
+      IF( kt == nitend ) CALL iom_close (numflx)
+
+   END SUBROUTINE flx
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_core.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_core.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_core.h90	(revision 4536)
@@ -0,0 +1,1117 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flx_core.h90  ***
+   !!----------------------------------------------------------------------
+   !!   flx     : update surface thermohaline fluxes from the NCAR data set
+   !!             read in a NetCDF file
+   !!----------------------------------------------------------------------
+   !! * Modules used     C A U T I O N  already defined in flxmod.F90
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+      gsss,            &  !: SSS mean on nfbulk ocean time step
+      gu  , gv ,       &  !: (un,vn)(jk=1) mean over nfbulk ocean time step
+      !                   ! these variables are used for output in diawri
+      qlw_oce  ,       &  !: long wave flx over ocean
+      qla_oce  ,       &  !: latent heat flx over ocean
+      qsb_oce  ,       &  !: sensible heat flx over ocean
+      qlw_ice  ,       &  !: long wave flx over ice
+      qsb_ice             !: sensible heat flx over ice
+
+   !! * Module variables
+   INTEGER, PARAMETER ::   jpfile  = 8  ! maximum number of files to read 
+   CHARACTER (LEN=32), DIMENSION (jpfile) ::  clvarname  
+   CHARACTER (LEN=50), DIMENSION (jpfile) ::  clname 
+
+   INTEGER   ::      isnap
+   INTEGER, DIMENSION(jpfile) ::   &
+      numflxall,           &  ! logical units for surface fluxes data
+      nrecflx  , nrecflx2     ! first and second record to be read in flux file
+   REAL(wp), DIMENSION(jpfile) ::   &
+      freqh                 ! Frequency for each forcing file (hours)
+      !                     ! a negative value of -12 corresponds to monthly
+   REAL(wp), DIMENSION(jpi,jpj,jpfile,2) ::   &
+      flxdta                !:  set of NCAR 6hourly/daily/monthly fluxes
+   LOGICAL  :: &
+        &   ln_2m   = .FALSE.     !: logical flag for height of air temp. and hum.
+   REAL(wp) :: alpha_precip=1.    !: multiplication factor for precipitation
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   9.0  !  04-08  (U. Schweckendiek)  Original code
+   !!        !  05-04  (L. Brodeau, A.M. Treguier)  severals modifications:
+   !!        !         - new bulk routine for efficiency
+   !!        !         - WINDS ARE NOW ASSUMED TO BE AT T POINTS in input files
+   !!        !         - file names and file characteristics in namelist 
+   !!        !         - Implement reading of 6-hourly fields   
+   !!        !  06-02  (S. Masson, G. Madec)  IOM read + NEMO "style"
+   !!        !  12-06  (L. Brodeau) handle both 2m and 10m input fields
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/SBC/flx_core.h90,v 1.5 2007/06/05 10:41:37 opalod Exp $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE flx  ***
+      !!                   
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater)
+      !!                and momentum fluxes (tau) 
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method  :   Read NCAR data in a NetCDF file
+      !!               (file names and frequency of inputs specified in namelist)
+      !!          precipitation:  total (rain+snow)
+      !!          precipitation:  snow only 
+      !!          u10,v10 -> scalar wind at 10m in m/s -  ON 'T' GRID POINTS!!!
+      !!          solar radiation (short wave)  in W/m2
+      !!          thermal radiation (long wave) in W/m2
+      !!          specific humidity             in %
+      !!          temperature at 10m            in degrees K
+      !!
+      !!  ** Action  :   
+      !!          call flx_blk_albedo to compute ocean and ice albedo
+      !!          Calculates forcing fluxes to input into ice model 
+      !          or to be used directly for the ocean in ocesbc. 
+      !!
+      !!  ** Outputs 
+      !!          COMMENTS TO BE ADDED -units to be verified!
+      !!          taux    : zonal      wind stress on "u" points  (N/m2)
+      !!          tauy    : meridional wind stress on "v" points  (N/m2)
+      !!          qsr_oce : Solar flux over the ocean (W/m2)
+      !!          qnsr_oce: longwave flux over the ocean (W/m2)
+      !!          qsr_ice : solar flux over the ice (W/m2)
+      !!          qnsr_ice: longwave flux over the ice (W/m2)
+      !!          qla_ice : latent flux over sea-ice (W/m2)
+      !!          dqns_ice: total heat fluxes sensitivity over ice (dQ/dT)
+      !!          dqla_ice: latent heat flux sensitivity over ice (dQla/dT)
+      !!          fr1_i0
+      !!          fr2_i0
+      !!          tprecip
+      !!          sprecip
+      !!          evap
+      !!          
+      !! caution : now, in the opa global model, the net upward water flux is
+      !! -------   with mm/day unit,i.e. Kg/m2/s.
+      !!---------------------------------------------------------------------
+      !! * modules used
+      USE iom
+      USE restart         
+      USE par_oce
+      USE flx_oce
+      USE blk_oce         ! bulk variable
+      USE taumod
+      USE bulk
+      USE phycst
+      USE lbclnk
+      USE dtatem          ! FOR Ce = F(SST(levitus)):
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER , PARAMETER :: jpmaxtime = 366*4   ! maximum time steps in file will be for a 6 hourly field
+                                                 ! and a leap year (necessary variable for flinopen??)
+      INTEGER ::  irectot, irecflx
+      INTEGER ::  ihour                ! current hour of the day at which we read the forcings
+      INTEGER ::   &
+         imois, imois2,             &  ! temporary integers
+         i15  , iman  , inum ,      &  !    "          "
+         ifpr , jfpr  ,             &  ! frequency of index for print in prihre
+         jj   , ji                     !  Loop indices 
+      REAL(wp) ::   &
+         zadatrjb,                  &  ! date (noninteger day) at which we read the forcings
+         zxy    ,                   &  ! scalar for temporal interpolation
+         zcof , zzu , zzv              ! scalar 
+      REAL(wp), DIMENSION(jpi,jpj, jpfile) ::   &
+         flxnow             ! input flux values at current time step 
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         dqlw_ice ,      &  ! long wave heat flx sensitivity over ice
+         dqsb_ice ,      &  ! sensible heat flx sensitivity over ice
+         alb_oce_os,     &  ! albedo of the ocean under overcast sky
+         alb_ice_os,     &  ! albedo of the ice under overcast sky
+         alb_ice_cs,     &  ! albedo of ice under clear sky
+         alb_oce_cs,     &  ! albedo of the ocean under clear sky
+         zsst,           &  ! nfbulk : mean SST
+         zsss,           &  ! nfbulk : mean tn_ice(:,:,1)
+         zut,            &  ! nfbulk : mean U at T-point
+         zvt,            &  ! nfbulk : mean V at T-point
+         dUnormt,        &  ! scalar wind (norm) on T points
+         tauxt, tauyt,   &  ! wind stress computed at T-point
+         qsatw,          &  ! specific humidity at zSST
+         qsat,           &  ! specific humidity at zsss 
+         Ch,             &  ! coefficient for sensible heat flux
+         Ce,             &  ! coefficient for latent heat flux
+         Cd,             &  ! coefficient for wind stress
+         zt_zu,          &  !: air temperature at wind speed height
+         zq_zu              !: air spec. hum.  at wind speed height
+      REAL(wp), PARAMETER ::   &
+         rhoa  = 1.22,    &  ! air density
+         cp    = 1000.5,  &  ! specific heat of air
+         Lv    = 2.5e6,   &  ! latent heat of vaporization
+         Ls    = 2.839e6, &  ! latent heat of sublimation
+         Stef  = 5.67e-8, &  ! Stefan Boltzmann constant
+         Cice = 1.63e-3      ! transfert coefficient over ice
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         catm1               ! 
+
+      NAMELIST /namcore/  clname, clvarname, freqh, ln_2m, alpha_precip
+      !!---------------------------------------------------------------------
+
+      !! =============================================== !!
+      !!   PART A:   READING FLUX FILES WHEN NECESSARY   !!
+      !! =============================================== !!
+
+      !--- calculation for monthly data 
+      ! i15 = 0 if first half of current month
+      ! i15 = 1 if second half of current month
+      i15 = INT( 2 * FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+      iman  = 12
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+      imois2 = nmonth
+
+      !--- calculation for 6-hourly data 
+      !    we need the fraction of day, measured in hours at the date of forcings. 
+      !    This is the time step before the date we are calculating, zadatrj 
+      !    "adatrj" (real time in days (noninteger))
+      zadatrjb = adatrj - rdt / rday
+      ihour = INT( ( zadatrjb - INT(zadatrjb) ) * 24 )
+
+      !                                         ! ------------------------ !
+      IF( kt == nit000 ) THEN                   !   first call kt=nit000   !
+         !                                      ! ------------------------ !
+         CALL core_rst ( kt, 'READ' )
+
+         !--- Initializes default values of file names, frequency of forcings 
+         !    and variable to be read in the files, before reading namelist 
+         clname(1) = 'precip.nc'   ; freqh(1) = -12 ; clvarname(1) = 'precip'     ! monthly
+         clname(2) = 'u10.nc'      ; freqh(2) =   6 ; clvarname(2) = 'u10'        ! 6 hourly          
+         clname(3) = 'v10.nc'      ; freqh(3) =   6 ; clvarname(3) = 'v10'        ! 6 hourly    
+         clname(4) = 'q10.nc'      ; freqh(4) =   6 ; clvarname(4) = 'q10'        ! 6 hourly   
+         clname(5) = 'radsw.nc'    ; freqh(5) =  24 ; clvarname(5) = 'radsw'      ! daily 
+         clname(6) = 'radlw.nc'    ; freqh(6) =  24 ; clvarname(6) = 'radlw'      ! daily 
+         clname(7) = 't10.nc'      ; freqh(7) =   6 ; clvarname(7) = 't10'        ! 6 hourly 
+         clname(8) = 'snow.nc'     ; freqh(8) = -12 ; clvarname(8) = 'snow'       ! monthly
+
+         !--- Read Namelist namcore : OMIP/CORE 
+         REWIND ( numnam )
+         READ   ( numnam, namcore )
+
+         ! in case of ln_2m, air temp. and humidity are given at 2 m, thus file name and variable name are changed
+         IF ( ln_2m ) THEN
+           clname(4) = 'q2.nc'      ; clvarname(4) = 'q2'     
+           clname(7) = 't2.nc'      ; clvarname(7) = 't2'    
+           ! but if for some reason, clname and varname were also in the name list, we screw them up !
+           ! re-read the namelist, to restore clname, varname to their namelist value 
+           REWIND ( numnam )
+           READ   ( numnam, namcore )
+         ENDIF
+
+         IF(lwp) THEN
+            WRITE(numout,*)' '
+            WRITE(numout,*)' flx_core : global CORE fields in NetCDF format'
+            WRITE(numout,*)' ~~~~~~~~~~ '
+            WRITE(numout,*) '           ln_2m        = ', ln_2m
+            WRITE(numout,*) '           alpha_precip = ', alpha_precip
+            WRITE(numout,*) '           list of files and frequency (hour), or monthly (-12) '
+            DO ji = 1, jpfile
+                WRITE(numout,*) trim(clname(ji)), ' frequency:', freqh(ji)
+            END DO
+         ENDIF
+
+         !--- Initialization to zero
+         qsr_oce (:,:) = 0.e0
+         qsb_oce (:,:) = 0.e0
+         qla_oce (:,:) = 0.e0
+         qlw_oce (:,:) = 0.e0
+         qnsr_oce(:,:) = 0.e0
+         qsr_ice (:,:) = 0.e0
+         qnsr_ice(:,:) = 0.e0
+         qla_ice (:,:) = 0.e0
+         qlw_ice (:,:) = 0.e0
+         qsb_ice (:,:) = 0.e0
+
+         dqns_ice(:,:) = 0.e0
+         dqla_ice(:,:) = 0.e0
+         tprecip (:,:) = 0.e0
+         sprecip (:,:) = 0.e0
+         evap    (:,:) = 0.e0
+
+         flxnow  (:,:,:) = 1.e-15         !RB
+         flxdta  (:,:,:,:) = 1.e-15       !RB
+
+         nrecflx (:)    = 0      ! switch for reading flux data for each file
+         nrecflx2(:)    = 0      ! switch for reading flux data for each file
+
+         !--- Open the files of the list
+         DO ji = 1, jpfile
+            CALL iom_open( clname(ji), numflxall(ji) )
+         END DO
+
+      ENDIF
+
+      !                                         ! ------------------------ !
+      !                                         !  Read files if required  !
+      !                                         ! ------------------------ !
+
+      !--- read data if necessary checks each file in turn 
+
+      DO ji = 1, jpfile
+
+         IF (  freqh(ji) > 0 .AND.  freqh(ji) <  24 ) THEN          !--- Case of 6-hourly flux data  
+            !--- calculate current snapshot from hour of day 
+            isnap = ihour / INT( freqh(ji) ) + 1
+            !--- reading is necessary when nrecflx(ji) differs from isnap 
+            IF( nrecflx(ji) /= isnap ) THEN   
+               nrecflx(ji) = isnap
+               irecflx = (nday_year-1)*24 / freqh(ji) + isnap
+               irectot = 365*24 / freqh(ji)        !  this variable is not used by iom_get
+               IF(lwp) WRITE (numout,*)' CORE flux 6-h record :',irecflx, ' var:',trim(clvarname(ji))
+               CALL iom_get( numflxall(ji), jpdom_data, clvarname(ji), flxdta(:,:,ji,1), irecflx )
+            ENDIF
+
+         ELSE IF ( freqh(ji) ==  24 ) THEN                             !--- Case of daily flux data  
+
+            !--- reading is necessary when nrecflx(ji) differs from nday
+            IF( nrecflx(ji) /= nday ) THEN   
+               nrecflx(ji) = nday          !! remember present read day
+               irecflx     = nday_year     !! 
+               irectot = 365        !  this variable is not used by iom_get
+               IF(lwp) WRITE (numout,*)'DAILY CORE flux record :',irecflx, ' var:',trim(clvarname(ji))
+               CALL iom_get( numflxall(ji), jpdom_data, clvarname(ji), flxdta(:,:,ji,1), irecflx )
+            ENDIF
+
+         ELSE IF ( freqh(ji) == -12 ) THEN                            !--- Case monthly data from CORE
+            ! we read two months all the time although we 
+            ! could only read one and swap the arrays 
+            IF( kt == nit000 .OR. imois /= nrecflx(ji) ) THEN
+               ! calendar computation
+               ! nrecflx number of the first file record used in the simulation
+               ! nrecflx2 number of the last  file record
+               nrecflx(ji) = imois
+               nrecflx2(ji) = nrecflx(ji)+1
+               nrecflx(ji) = MOD( nrecflx(ji), iman )
+               IF( nrecflx(ji) == 0 )   nrecflx(ji) = iman
+               nrecflx2(ji) = MOD( nrecflx2(ji), iman )
+               IF ( nrecflx2(ji) == 0 ) nrecflx2(ji) = iman
+               irectot = 12        !  this variable is not used by iom_get
+               IF(lwp) WRITE(numout,*) 'MONTHLY CORE flux record 1:', nrecflx(ji),   &
+                  &                    ' rec 2:', nrecflx2(ji), ' var:', trim(clvarname(ji))
+               CALL iom_get( numflxall(ji), jpdom_data, clvarname(ji), flxdta(:,:,ji,1), nrecflx (ji) )
+               CALL iom_get( numflxall(ji), jpdom_data, clvarname(ji), flxdta(:,:,ji,2), nrecflx2(ji) )
+            ENDIF
+         ENDIF
+      END DO    !   end of loop over forcing files to verify if reading is necessary 
+
+      !--- Printout if required      
+      !  IF( MOD( kt - 1 , nfbulk ) == 0 ) THEN
+      !            printout at the initial time step only (unless you want to debug!!)
+      IF( kt == nit000 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' read daily and monthly CORE fluxes: ok'
+            WRITE(numout,*)
+            ifpr = INT(jpi/8)      ;      jfpr = INT(jpj/10)
+            DO ji = 1, jpfile 
+               WRITE(numout,*) trim(clvarname(ji)),' day: ',ndastp
+               CALL prihre(flxdta(1,1,ji,1),jpi,jpj,1,jpi,ifpr,1,jpj,jfpr,0.,numout)
+               WRITE(numout,*)
+            END DO
+         ENDIF
+      ENDIF
+
+      !                                         ! ------------------------ !
+      !                                         !   Interpolates in time   !
+      !                                         ! ------------------------ !
+      ! N.B. For now, only monthly values are interpolated, and they 
+      !      are interpolated to the current day, not to the time step.
+      !
+      DO ji = 1, jpfile       
+         IF( freqh(ji) == -12 ) THEN
+            zxy = REAL(nday) / REAL( nobis(imois) ) + 0.5 - i15         !!! <== Caution nobis hard coded !!!
+            flxnow(:,:,ji) = ( ( 1. - zxy) * flxdta(:,:,ji,1) + zxy * flxdta(:,:,ji,2) )
+         ELSE
+            flxnow(:,:,ji) = flxdta(:,:,ji,1)
+         ENDIF
+      END DO
+      ! JMM : add vatm needed in tracer routines  ==> wind module ???
+      vatm(:,:) = SQRT( flxnow(:,:,2) * flxnow(:,:,2) + flxnow(:,:,3) * flxnow(:,:,3) )
+
+
+      !! =============================================== !!
+      !!   PART B:   CORE BULK CALCULATION               !!
+      !! =============================================== !!
+
+      !  for other forcing cases this is done in modules bulk.F90 and flxblk
+
+      !                                         ! ------------------------ !
+      !                                         !   Bulk initialisation    !
+      !                                         ! ------------------------ !
+
+      ! code part from bulk.F90 :
+
+      IF( kt == nit000) THEN
+         !--- computation of rdtbs2     ===>  !gm  is it really usefull ????
+         IF( nacc == 1 ) THEN
+            rdtbs2 = nfbulk * rdtmin * 0.5
+         ELSE
+           rdtbs2 = nfbulk * rdt * 0.5
+         ENDIF
+         IF( .NOT.ln_rstart ) THEN
+            zcof =  REAL( nfbulk - 1, wp )
+            gsst(:,:) =  zcof * ( tn(:,:,1)  + rt0 )
+            gsss(:,:) =  zcof * tn_ice(:,:)
+            gu  (:,:) =  zcof * un(:,:,1)
+            gv  (:,:) =  zcof * vn(:,:,1)
+         ENDIF
+      ENDIF
+
+      ! ----------------------------------------------------------------------------- !
+      !      0   Mean SST, ice temperature and ocean currents over nfbulk pdt         !
+      ! ----------------------------------------------------------------------------- !
+      !
+      gsst(:,:) = gsst(:,:) + (tn(:,:,1) + rt0 )  
+      gsss(:,:) = gsss(:,:) + tn_ice(:,:)
+      gu  (:,:) = gu  (:,:) + un    (:,:,1)
+      gv  (:,:) = gv  (:,:) + vn    (:,:,1)
+
+      IF( MOD( kt - 1 , nfbulk ) == 0 ) THEN
+         !
+!        zsst(:,:) = gsst(:,:) / REAL( nfbulk, wp ) * tmask(:,:,1) ! mean sst in K
+!        zsss(:,:) = gsss(:,:) / REAL( nfbulk ) * tmask(:,:,1) ! mean tn_ice in K
+
+!        where ( zsst(:,:) .eq. 0.e0 ) zsst(:,:) = rt0     !lb vilain !!???
+!        where ( zsss(:,:) .eq. 0.e0 ) zsss(:,:) = rt0     !lb    //
+
+!!gm  better coded:
+         ! Caution set to rt0 over land, not 0 Kelvin (otherwise floating point exception in bulk computation) 
+         zcof =  1. / REAL( nfbulk, wp )
+         zsst(:,:) = gsst(:,:) * zcof * tmask(:,:,1) + rt0 * (1.- tmask(:,:,1))    ! mean sst in K
+         zsss(:,:) = gsss(:,:) * zcof * tmask(:,:,1) + rt0 * (1.- tmask(:,:,1))   ! mean tn_ice in K
+!!gm
+
+         zut(:,:) = 0.e0      !!gm not necessary but at least first and last column
+         zvt(:,:) = 0.e0
+         !            lb
+         ! Interpolation of surface current at T-point, zut and zvt :
+!        DO ji=2, jpi
+!           zut(ji,:) = 0.5*(gu(ji-1,:) + gu(ji,:)) / REAL( nfbulk )
+!        END DO
+!        !
+!        DO jj=2, jpj
+!           zvt(:,jj) = 0.5*(gv(:,jj-1) + gv(:,jj)) / REAL( nfbulk )
+!        END DO
+!!gm better coded
+         zcof =  0.5 / REAL( nfbulk, wp )
+         DO jj = 2, jpjm1
+            DO ji = 1, jpi
+               zut(ji,jj) = ( gu(ji-1,jj  ) + gu(ji,jj) ) * zcof
+               zvt(ji,jj) = ( gv(ji  ,jj-1) + gv(ji,jj) ) * zcof
+            END DO
+         END DO
+!!gm
+
+         CALL lbc_lnk( zut(:,:), 'T', -1. )         
+         CALL lbc_lnk( zvt(:,:), 'T', -1. )         
+
+         ! ----------------------------------------------------------------------------- !
+         !      I   Radiative FLUXES                                                     !
+         ! ----------------------------------------------------------------------------- !
+
+         !--- Ocean & Ice Albedo
+         alb_oce_os(:,:) = 0.   ;   alb_oce_cs(:,:) = 0.   !gm is it necessary ???
+         alb_ice_os(:,:) = 0.   ;   alb_ice_cs(:,:) = 0.
+         CALL flx_blk_albedo( alb_ice_os, alb_oce_os, alb_ice_cs, alb_oce_cs )
+
+         !--- Radiative fluxes over ocean
+         qsr_oce(:,:) = ( 1. - 0.066 ) * flxnow(:,:,5)                                 ! Solar Radiation
+         qlw_oce(:,:) = flxnow(:,:,6) - Stef*zsst(:,:)*zsst(:,:)*zsst(:,:)*zsst(:,:)   ! Long Waves (Infra-red)
+
+         !--- Radiative fluxes over ice
+         qsr_ice(:,:) = ( 1. - alb_ice_cs(:,:) ) * flxnow(:,:,5)                                  ! Solar Radiation
+         qlw_ice(:,:) = 0.95 * ( flxnow(:,:,6) - Stef*zsss(:,:)*zsss(:,:)*zsss(:,:)*zsss(:,:) )   ! Long Waves (Infra-red)
+         !-------------------------------------------------------------------------------!
+
+         ! ----------------------------------------------------------------------------- !
+         !     II    Turbulent FLUXES                                                    !
+         ! ----------------------------------------------------------------------------- !
+         !
+         ! scalar wind ( = | U10m - SSU | )
+         ! It is important to take into account the sea surface courant
+         !                lb
+         ! Now, wind components are provided on T-points within the netcdf input file.
+         ! Thus, the wind module is computded at T-points taking into account the sea
+
+         !--- Module of relative wind
+!        dUnormt(:,:) = sqrt( (flxnow(:,:,2) - zut(:,:))*(flxnow(:,:,2) - zut(:,:))  &
+!             &             + (flxnow(:,:,3) - zvt(:,:))*(flxnow(:,:,3) - zvt(:,:)) )
+!!gm  more efficient coding:
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zzu = flxnow(ji,jj,2) - zut(ji,jj)
+               zzv = flxnow(ji,jj,3) - zvt(ji,jj)
+               dUnormt(ji,jj) = SQRT( zzu*zzu + zzv*zzv )
+            END DO 
+         END DO 
+!!gm
+         !--- specific humidity at temp SST
+         qsatw(:,:) = 0.98*640380*exp(-5107.4/zsst(:,:))/rhoa
+         !
+         !--- specific humidity at temp tn_ice
+         qsat(:,:)  = 11637800*exp(-5897.8/zsss(:,:))/rhoa
+         !
+
+         ! CORE iterartive algo for computation of Cd, Ch, Ce at T-point :
+         ! ===============================================================
+         IF( ln_2m ) THEN
+            IF( kt == nit000 .AND. lwp )   THEN
+               WRITE(numout,*) 
+               WRITE(numout,*) '           Calling TURB_CORE_2Z for bulk transfert coefficients'
+            ENDIF
+            !! If air temp. and spec. hum. are given at different height (2m) than wind (10m) :
+            CALL TURB_CORE_2Z(2.,10.,zsst(:,:), flxnow(:,:,7), qsatw(:,:), flxnow(:,:,4), &
+               &              dUnormt(:,:), Cd(:,:), Ch(:,:), Ce(:,:), zt_zu(:,:), zq_zu(:,:))
+         ELSE
+            IF( kt == nit000 .AND. lwp )    THEN
+               WRITE(numout,*) 
+               WRITE(numout,*) '           Calling TURB_CORE_1Z for bulk transfert coefficients'
+            ENDIF
+            !! If air temp. and spec. hum. are given at same height than wind (10m) :
+            CALL TURB_CORE_1Z(10., zsst(:,:), flxnow(:,:,7), qsatw(:,:), flxnow(:,:,4),  &
+               &              dUnormt(:,:), Cd(:,:), Ch(:,:), Ce(:,:) )
+         ENDIF
+
+         !   II.1) Momentum over ocean and ice
+         !   ---------------------------------
+         ! Tau_x at T-point
+         tauxt(:,:) = rhoa*dUnormt(:,:)*( (1. - freeze(:,:))*Cd(:,:)*(flxnow(:,:,2) - zut(:,:))    &
+              &                          + freeze(:,:)*Cice*flxnow(:,:,2) ) !lb correct pour glace
+         ! Tau_y at T-point
+         tauyt(:,:) = rhoa*dUnormt(:,:)*( (1. - freeze(:,:))*Cd(:,:)*(flxnow(:,:,3) - zvt(:,:))    &
+              &                          + freeze(:,:)*Cice*flxnow(:,:,3) )
+         !
+         CALL lbc_lnk( tauxt(:,:), 'T', -1. )       !!gm seems not decessary at this point....
+         CALL lbc_lnk( tauyt(:,:), 'T', -1. )
+
+         !
+         !Tau_x at U-point
+         DO ji = 1, jpim1
+            taux(ji,:) = 0.5*(tauxt(ji,:) + tauxt(ji+1,:))
+         END DO
+         !
+         ! Tau_y at V-point
+         DO jj = 1, jpjm1
+            tauy(:,jj) = 0.5*(tauyt(:,jj) + tauyt(:,jj+1))
+         END DO
+
+         !
+         !   II.2) Turbulent fluxes over ocean
+         !   ---------------------------------
+         !
+         IF( ln_2m ) THEN
+            !!
+            !! Values of temp. and hum. adjusted to 10m must be used instead of 2m values
+            !! Sensible Heat :    ! right sign for ocean
+            qsb_oce(:,:) = rhoa*cp*Ch(:,:)*(zt_zu(:,:) - zsst(:,:))*dUnormt(:,:)
+            !!
+            !! Latent Heat :      ! wrong sign for ocean
+            evap(:,:)    = rhoa*Ce(:,:)*(qsatw(:,:) - zq_zu(:,:))*dUnormt(:,:)
+            !!
+         ELSE
+            !!
+            !! Sensible Heat :    ! right sign for ocean
+            qsb_oce(:,:) = rhoa*cp*Ch(:,:)*(flxnow(:,:,7) - zsst(:,:))*dUnormt(:,:)
+            !!
+            !! Latent Heat :      ! wrong sign for ocean
+            evap(:,:)    = rhoa*Ce(:,:)*(qsatw(:,:) - flxnow(:,:,4))*dUnormt(:,:)
+            !!
+         END IF
+         !!
+         qla_oce(:,:) =  -Lv * evap(:,:) ! right sign for ocean
+         
+         ! 
+         !   II.3) Turbulent fluxes over ice
+         !   -------------------------------
+         ! 
+         ! Sensible Heat :
+         qsb_ice(:,:) = rhoa*cp*Cice*( flxnow(:,:,7) - zsss(:,:) )*dUnormt(:,:) !lb     use
+         !                                                                    !lb   dUnormt???
+         ! Latent Heat :                                                      !lb or rather Unormt?
+         qla_ice(:,:) = Ls*rhoa*Cice*( flxnow(:,:,4) - qsat(:,:) )*dUnormt(:,:)
+         !
+         !-------------------------------------------------------------------------------------
+
+
+         ! ----------------------------------------------------------------------------- !
+         !     III    Total FLUXES                                                       !
+         ! ----------------------------------------------------------------------------- !
+         !
+         !   III.1) Downward Non Solar flux over ocean
+         !   -----------------------------------------
+         qnsr_oce(:,:) = qlw_oce(:,:) + qsb_oce(:,:) + qla_oce(:,:)
+         !
+         !   III.1) Downward Non Solar flux over ice
+         !   ---------------------------------------
+         qnsr_ice(:,:) = qlw_ice(:,:) + qsb_ice(:,:) + qla_ice(:,:) 
+         !
+         !-------------------------------------------------------------------------------!
+
+         ! 6. TOTAL NON SOLAR SENSITIVITY 
+
+         dqlw_ice(:,:)= 4.0*0.95*Stef*zsss(:,:)*zsss(:,:)*zsss(:,:)
+
+         ! d qla_ice/ d zsss
+         dqla_ice(:,:) = -Ls*Cice*0.98*11637800/(rhoa*rhoa) &
+              * (-5897.8)/(zsss(:,:)*zsss(:,:)) &
+              * exp(-5897.8/zsss(:,:)) * dUnormt(:,:)
+
+         ! d qsb_ice/ d zsss
+         dqsb_ice(:,:) = rhoa * cp * Cice * dUnormt(:,:)
+
+         dqns_ice(:,:) = - ( dqlw_ice(:,:) + dqsb_ice(:,:) + dqla_ice(:,:) )
+
+         !--------------------------------------------------------------------
+         ! FRACTION of net shortwave radiation which is not absorbed in the
+         ! thin surface layer and penetrates inside the ice cover
+         ! ( Maykut and Untersteiner, 1971 ; Elbert and Curry, 1993 )
+
+         catm1(:,:) = 1.0  - 0.3  ! flxnow(:,:,8)
+         fr1_i0(:,:) = & 
+              (0.18 * catm1(:,:) + 0.35 * flxnow(:,:,8))
+         fr2_i0(:,:) = &
+              (0.82 * catm1(:,:) + 0.65 * flxnow(:,:,8))
+
+
+         !  Total  PRECIPITATION (kg/m2/s)
+         tprecip(:,:) = alpha_precip*flxnow(:,:,1) 
+         ! rename precipitation for freshwater budget calculations:
+!         watm(:,:) =  flxnow(:,:,1)*1000
+         watm(:,:) =  flxnow(:,:,1)*rday
+         !
+
+         !  SNOW PRECIPITATION  (kg/m2/s)
+         sprecip(:,:) =  alpha_precip*flxnow(:,:,8) 
+
+         !---------------------------------------------------------------------
+
+         CALL lbc_lnk( taux (:,:)    , 'U', -1. )
+         CALL lbc_lnk( tauy (:,:)    , 'V', -1. )
+         CALL lbc_lnk( qsr_oce (:,:) , 'T', 1. )
+         CALL lbc_lnk( qnsr_oce(:,:) , 'T', 1. )
+         CALL lbc_lnk( qsr_ice (:,:) , 'T', 1. )
+         CALL lbc_lnk( qnsr_ice(:,:) , 'T', 1. )
+         CALL lbc_lnk( qla_ice (:,:) , 'T', 1. )
+         CALL lbc_lnk( dqns_ice(:,:) , 'T', 1. )
+         CALL lbc_lnk( dqla_ice(:,:) , 'T', 1. )
+         CALL lbc_lnk( fr1_i0  (:,:) , 'T', 1. )
+         CALL lbc_lnk( fr2_i0  (:,:) , 'T', 1. )
+         CALL lbc_lnk( tprecip (:,:) , 'T', 1. )
+         CALL lbc_lnk( sprecip (:,:) , 'T', 1. )
+         CALL lbc_lnk( evap    (:,:) , 'T', 1. )
+         !!
+         !!
+         !!   NEVER mask the windstress!!
+         qsr_oce (:,:) = qsr_oce (:,:)*tmask(:,:,1)
+         qnsr_oce(:,:) = qnsr_oce(:,:)*tmask(:,:,1)
+         qsr_ice (:,:) = qsr_ice (:,:)*tmask(:,:,1)
+         qnsr_ice(:,:) = qnsr_ice(:,:)*tmask(:,:,1)
+         qla_ice (:,:) = qla_ice (:,:)*tmask(:,:,1)
+         dqns_ice(:,:) = dqns_ice(:,:)*tmask(:,:,1)
+         dqla_ice(:,:) = dqla_ice(:,:)*tmask(:,:,1)
+         fr1_i0  (:,:) = fr1_i0  (:,:)*tmask(:,:,1)
+         fr2_i0  (:,:) = fr2_i0  (:,:)*tmask(:,:,1)
+         tprecip (:,:) = tprecip (:,:)*tmask(:,:,1)
+         sprecip (:,:) = sprecip (:,:)*tmask(:,:,1)
+         evap    (:,:) = evap    (:,:)*tmask(:,:,1)
+         gsst(:,:) = 0.e0
+         gsss(:,:) = 0.e0
+         gu  (:,:) = 0.e0
+         gv  (:,:) = 0.e0
+
+         !   Degugging print (A.M. Treguier)       
+         !      write (55) taux, tauy, qnsr_oce, qsb_ice, qnsr_ice, qla_ice, dqns_ice &
+         !  &     , dqla_ice, fr1_i0, fr2_i0, qlw_oce, qla_oce, qsb_oce, evap
+         !      write(numout,*) 'written 14 arrays on unit fort.55'
+
+
+      ENDIF
+
+      ! ------------------- !
+      ! Last call kt=nitend !
+      ! ------------------- !
+
+      ! Closing of the numflx file (required in mpp)
+
+      IF( kt == nitend ) THEN
+         DO ji=1, jpfile 
+            CALL iom_close(numflxall(ji))
+         END DO
+      ENDIF
+      IF ( lrst_oce ) CALL core_rst( kt, 'WRITE' )
+
+   END SUBROUTINE flx
+
+   SUBROUTINE TURB_CORE_1Z(zu, sst, T_a, q_sat, q_a,   &
+      &                        dU, Cd, Ch, Ce   )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE  turb_core  ***
+      !!
+      !! ** Purpose :   Computes turbulent transfert coefficients of surface
+      !!                fluxes according to Large & Yeager (2004)
+      !!
+      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
+      !!      Momentum, Latent and sensible heat exchange coefficients
+      !!      Caution: this procedure should only be used in cases when air
+      !!      temperature (T_air), air specific humidity (q_air) and wind (dU)
+      !!      are provided at the same height 'zzu'!
+      !!
+      !! References :
+      !!      Large & Yeager, 2004 : ???
+      !! History :
+      !!        !  XX-XX  (???     )  Original code
+      !!   9.0  !  05-08  (L. Brodeau) Rewriting and optimization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+
+      REAL(wp), INTENT(in) :: zu                 ! altitude of wind measurement       [m]
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj) ::  &
+         sst,       &       ! sea surface temperature         [Kelvin]
+         T_a,       &       ! potential air temperature       [Kelvin]
+         q_sat,     &       ! sea surface specific humidity   [kg/kg]
+         q_a,       &       ! specific air humidity           [kg/kg]
+         dU                 ! wind module |U(zu)-U(0)|        [m/s]
+      REAL(wp), intent(out), DIMENSION(jpi,jpj)  :: &
+         Cd,    &                ! transfert coefficient for momentum       (tau)
+         Ch,    &                ! transfert coefficient for temperature (Q_sens)
+         Ce                      ! transfert coefficient for evaporation  (Q_lat)
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(jpi,jpj)  ::   &
+         dU10,        &       ! dU                                   [m/s]
+         dT,          &       ! air/sea temperature differeence      [K]
+         dq,          &       ! air/sea humidity difference          [K]
+         Cd_n10,      &       ! 10m neutral drag coefficient
+         Ce_n10,      &       ! 10m neutral latent coefficient
+         Ch_n10,      &       ! 10m neutral sensible coefficient
+         sqrt_Cd_n10, &       ! root square of Cd_n10
+         sqrt_Cd,     &       ! root square of Cd
+         T_vpot,      &       ! virtual potential temperature        [K]
+         T_star,      &       ! turbulent scale of tem. fluct.
+         q_star,      &       ! turbulent humidity of temp. fluct.
+         U_star,      &       ! turb. scale of velocity fluct.
+         L,           &       ! Monin-Obukov length                  [m]
+         zeta,        &       ! stability parameter at height zu
+         U_n10,       &       ! neutral wind velocity at 10m         [m]   
+         xlogt, xct, zpsi_h, zpsi_m
+      !!
+      INTEGER :: j_itt
+      INTEGER, PARAMETER :: nb_itt = 3
+      INTEGER, DIMENSION(jpi,jpj)  ::   &
+         stab         ! 1st guess stability test integer
+
+      REAL(wp), PARAMETER ::                        &
+         grav   = 9.8,          &  ! gravity                       
+         kappa  = 0.4              ! von Karman s constant
+
+      !! * Start
+      !! Air/sea differences
+      dU10 = max(0.5, dU)     ! we don't want to fall under 0.5 m/s
+      dT = T_a - sst          ! assuming that T_a is allready the potential temp. at zzu
+      dq = q_a - q_sat
+      !!    
+      !! Virtual potential temperature
+      T_vpot = T_a*(1. + 0.608*q_a)
+      !!
+      !! Neutral Drag Coefficient
+      stab    = 0.5 + sign(0.5,dT)    ! stable : stab = 1 ; unstable : stab = 0 
+      Cd_n10  = 1E-3 * ( 2.7/dU10 + 0.142 + dU10/13.09 )    !   L & Y eq. (6a)
+      sqrt_Cd_n10 = sqrt(Cd_n10)
+      Ce_n10  = 1E-3 * ( 34.6 * sqrt_Cd_n10 )               !   L & Y eq. (6b)
+      Ch_n10  = 1E-3*sqrt_Cd_n10*(18*stab + 32.7*(1-stab)) !   L & Y eq. (6c), (6d)
+      !!
+      !! Initializing transfert coefficients with their first guess neutral equivalents :
+      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
+
+      !! * Now starting iteration loop
+      DO j_itt=1, nb_itt
+         !! Turbulent scales :
+         U_star  = sqrt_Cd*dU10                !   L & Y eq. (7a)
+         T_star  = Ch/sqrt_Cd*dT               !   L & Y eq. (7b)
+         q_star  = Ce/sqrt_Cd*dq               !   L & Y eq. (7c)
+
+         !! Estimate the Monin-Obukov length :
+         L  = (U_star**2)/( kappa*grav*(T_star/T_vpot + q_star/(q_a + 1./0.608)) )
+
+         !! Stability parameters :
+         zeta = zu/L ;  zeta   = sign( min(abs(zeta),10.0), zeta )
+         zpsi_h = psi_h(zeta)
+         zpsi_m = psi_m(zeta)
+
+         !! Shifting the wind speed to 10m and neutral stability :
+         U_n10 = dU10*1./(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) !  L & Y eq. (9a)
+
+         !! Updating the neutral 10m transfer coefficients :
+         Cd_n10  = 1E-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)              !  L & Y eq. (6a)
+         sqrt_Cd_n10 = sqrt(Cd_n10)
+         Ce_n10  = 1E-3 * (34.6 * sqrt_Cd_n10)                           !  L & Y eq. (6b)
+         stab    = 0.5 + sign(0.5,zeta)
+         Ch_n10  = 1E-3*sqrt_Cd_n10*(18.*stab + 32.7*(1-stab))           !  L & Y eq. (6c), (6d)
+
+         !! Shifting the neutral  10m transfer coefficients to ( zu , zeta ) :
+         !!
+         xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10) - zpsi_m)
+         Cd  = Cd_n10/(xct*xct) ;  sqrt_Cd = sqrt(Cd)
+         !!
+         xlogt = log(zu/10.) - zpsi_h
+         !!
+         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
+         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
+         !!
+         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
+         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
+         !!
+      END DO
+      !!
+    END SUBROUTINE TURB_CORE_1Z
+
+
+    SUBROUTINE TURB_CORE_2Z(zt, zu, sst, T_zt, q_sat, q_zt, dU, Cd, Ch, Ce, T_zu, q_zu)
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE  turb_core  ***
+      !!
+      !! ** Purpose :   Computes turbulent transfert coefficients of surface 
+      !!                fluxes according to Large & Yeager (2004).
+      !!
+      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
+      !!      Momentum, Latent and sensible heat exchange coefficients
+      !!      Caution: this procedure should only be used in cases when air
+      !!      temperature (T_air) and air specific humidity (q_air) are at 2m
+      !!      whereas wind (dU) is at 10m.
+      !!
+      !! References :
+      !!      Large & Yeager, 2004 : ???
+      !! History :
+      !!   9.0  !  06-12  (L. Brodeau) Original code for 2Z
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(in)   :: &
+         zt,      &     ! height for T_zt and q_zt                   [m]
+         zu             ! height for dU                              [m]
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj) ::  &
+         sst,      &     ! sea surface temperature              [Kelvin]
+         T_zt,     &     ! potential air temperature            [Kelvin]
+         q_sat,    &     ! sea surface specific humidity         [kg/kg]
+         q_zt,     &     ! specific air humidity                 [kg/kg]
+         dU              ! relative wind module |U(zu)-U(0)|       [m/s]
+      REAL(wp), INTENT(out), DIMENSION(jpi,jpj)  ::  &
+         Cd,       &     ! transfer coefficient for momentum         (tau)
+         Ch,       &     ! transfer coefficient for sensible heat (Q_sens)
+         Ce,       &     ! transfert coefficient for evaporation   (Q_lat)
+         T_zu,     &     ! air temp. shifted at zu                     [K]
+         q_zu            ! spec. hum.  shifted at zu               [kg/kg]
+
+      !! * Local declarations
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         dU10,        &     ! dU                                [m/s]
+         dT,          &     ! air/sea temperature differeence   [K]
+         dq,          &     ! air/sea humidity difference       [K]
+         Cd_n10,      &     ! 10m neutral drag coefficient
+         Ce_n10,      &     ! 10m neutral latent coefficient
+         Ch_n10,      &     ! 10m neutral sensible coefficient
+         sqrt_Cd_n10, &     ! root square of Cd_n10
+         sqrt_Cd,     &     ! root square of Cd
+         T_vpot_u,    &     ! virtual potential temperature        [K]
+         T_star,      &     ! turbulent scale of tem. fluct.
+         q_star,      &     ! turbulent humidity of temp. fluct.
+         U_star,      &     ! turb. scale of velocity fluct.
+         L,           &     ! Monin-Obukov length                  [m]
+         zeta_u,      &     ! stability parameter at height zu
+         zeta_t,      &     ! stability parameter at height zt
+         U_n10,       &     ! neutral wind velocity at 10m        [m]
+         xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m
+
+      INTEGER :: j_itt
+      INTEGER, PARAMETER :: nb_itt = 3   ! number of itterations
+      INTEGER, DIMENSION(jpi,jpj) :: &
+           &     stab                ! 1st stability test integer
+      REAL(wp), PARAMETER ::                        &
+         grav   = 9.8,      &  ! gravity                       
+         kappa  = 0.4          ! von Karman's constant
+
+      !!  * Start
+
+      !! Initial air/sea differences
+      dU10 = max(0.5, dU)      !  we don't want to fall under 0.5 m/s
+      dT = T_zt - sst 
+      dq = q_zt - q_sat
+
+      !! Neutral Drag Coefficient :
+      stab = 0.5 + sign(0.5,dT)                 ! stab = 1  if dT > 0  -> STABLE
+      Cd_n10  = 1E-3*( 2.7/dU10 + 0.142 + dU10/13.09 ) 
+      sqrt_Cd_n10 = sqrt(Cd_n10)
+      Ce_n10  = 1E-3*( 34.6 * sqrt_Cd_n10 )
+      Ch_n10  = 1E-3*sqrt_Cd_n10*(18*stab + 32.7*(1 - stab))
+
+      !! Initializing transf. coeff. with their first guess neutral equivalents :
+      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
+
+      !! Initializing z_u values with z_t values :
+      T_zu = T_zt ;  q_zu = q_zt
+
+      !!  * Now starting iteration loop
+      DO j_itt=1, nb_itt
+         dT = T_zu - sst ;  dq = q_zu - q_sat ! Updating air/sea differences
+         T_vpot_u = T_zu*(1. + 0.608*q_zu)    ! Updating virtual potential temperature at zu
+         U_star = sqrt_Cd*dU10                ! Updating turbulent scales :   (L & Y eq. (7))
+         T_star  = Ch/sqrt_Cd*dT              !
+         q_star  = Ce/sqrt_Cd*dq              !
+         !!
+         L = (U_star*U_star) &                ! Estimate the Monin-Obukov length at height zu
+              & / (kappa*grav/T_vpot_u*(T_star*(1.+0.608*q_zu) + 0.608*T_zu*q_star))
+         !! Stability parameters :
+         zeta_u  = zu/L  ;  zeta_u = sign( min(abs(zeta_u),10.0), zeta_u )
+         zeta_t  = zt/L  ;  zeta_t = sign( min(abs(zeta_t),10.0), zeta_t )
+         zpsi_hu = psi_h(zeta_u)
+         zpsi_ht = psi_h(zeta_t)
+         zpsi_m  = psi_m(zeta_u)
+         !!
+         !! Shifting the wind speed to 10m and neutral stability : (L & Y eq.(9a))
+!        U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - psi_m(zeta_u)))
+         U_n10 = dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m))
+         !!
+         !! Shifting temperature and humidity at zu :          (L & Y eq. (9b-9c))
+!        T_zu = T_zt - T_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
+         T_zu = T_zt - T_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
+!        q_zu = q_zt - q_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
+         q_zu = q_zt - q_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
+         !!
+         !! q_zu cannot have a negative value : forcing 0
+         stab = 0.5 + sign(0.5,q_zu) ;  q_zu = stab*q_zu
+         !!
+         !! Updating the neutral 10m transfer coefficients :
+         Cd_n10  = 1E-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)    ! L & Y eq. (6a)
+         sqrt_Cd_n10 = sqrt(Cd_n10)
+         Ce_n10  = 1E-3 * (34.6 * sqrt_Cd_n10)                 ! L & Y eq. (6b)
+         stab    = 0.5 + sign(0.5,zeta_u)
+         Ch_n10  = 1E-3*sqrt_Cd_n10*(18.*stab + 32.7*(1-stab)) ! L & Y eq. (6c-6d)
+         !!
+         !!
+         !! Shifting the neutral 10m transfer coefficients to (zu,zeta_u) :
+!        xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - psi_m(zeta_u))
+         xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)
+         Cd = Cd_n10/(xct*xct) ; sqrt_Cd = sqrt(Cd)
+         !!
+!        xlogt = log(zu/10.) - psi_h(zeta_u)
+         xlogt = log(zu/10.) - zpsi_hu
+         !!
+         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
+         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
+         !!
+         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
+         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
+         !!
+         !!
+      END DO
+      !!
+    END SUBROUTINE TURB_CORE_2Z
+
+    FUNCTION psi_m(zta)   !! Psis, L & Y eq. (8c), (8d), (8e)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: zta
+
+      REAL(wp), PARAMETER :: pi = 3.14159
+      REAL(wp), DIMENSION(jpi,jpj)             :: psi_m
+      REAL(wp), DIMENSION(jpi,jpj)             :: X2, X, stabit
+      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.0) ;  X  = sqrt(X2)
+      stabit    = 0.5 + sign(0.5,zta)
+      psi_m = -5.*zta*stabit  &                                                  ! Stable
+           & + (1. - stabit)*(2*log((1. + X)/2) + log((1. + X2)/2) - 2*atan(X) + pi/2)  ! Unstable 
+    END FUNCTION psi_m
+
+    FUNCTION psi_h(zta)    !! Psis, L & Y eq. (8c), (8d), (8e)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: zta
+
+      REAL(wp), DIMENSION(jpi,jpj)             :: psi_h
+      REAL(wp), DIMENSION(jpi,jpj)             :: X2, X, stabit
+      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.) ;  X  = sqrt(X2)
+      stabit    = 0.5 + sign(0.5,zta)
+      psi_h = -5.*zta*stabit  &                                       ! Stable
+           & + (1. - stabit)*(2.*log( (1. + X2)/2. ))                 ! Unstable
+    END FUNCTION psi_h
+
+
+  SUBROUTINE flx_blk_albedo( palb , palcn , palbp , palcnp )
+    !!----------------------------------------------------------------------
+    !!               ***  ROUTINE flx_blk_albedo  ***
+    !!
+    !! ** Purpose :   Computation of the albedo of the snow/ice system
+    !!      as well as the ocean one
+    !!
+    !! ** Method  : - Computation of the albedo of snow or ice (choose the
+    !!      right one by a large number of tests
+    !!              - Computation of the albedo of the ocean
+    !!
+    !! References :
+    !!      Shine and Hendersson-Sellers 1985, JGR, 90(D1), 2243-2250.
+    !!
+    !! History :
+    !!  8.0   !  01-04  (LIM 1.0)
+    !!  8.5   !  03-07  (C. Ethe, G. Madec)  Optimization (old name:shine)
+    !!----------------------------------------------------------------------
+    !! * Modules used
+    USE ice                   ! ???
+
+    !! * Arguments
+    REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::  &
+         palb         , & !  albedo of ice under overcast sky
+         palcn        , & !  albedo of ocean under overcast sky
+         palbp        , & !  albedo of ice under clear sky
+         palcnp                  !  albedo of ocean under clear sky
+
+    !! * Local variables
+    INTEGER ::    &
+         ji, jj                   ! dummy loop indices
+    REAL(wp) ::   &
+         c1     = 0.05  , & ! constants values
+         c2     = 0.1   , &
+         albice = 0.50  , & !  albedo of melting ice in the arctic and antarctic (Shine & Hendersson-Sellers)
+         cgren  = 0.06  , & !  correction of the snow or ice albedo to take into account
+         !  effects of cloudiness (Grenfell & Perovich, 1984)
+         alphd  = 0.80  , & !  coefficients for linear interpolation used to compute
+         alphdi = 0.72  , & !  albedo between two extremes values (Pyane, 1972)
+         alphc  = 0.65  , &
+         zmue   = 0.4   , &     !  cosine of local solar altitude
+         zzero   = 0.0     ,  &
+         zone    = 1.0
+
+    REAL(wp) ::   &
+         zmue14         , & !  zmue**1.4
+         zalbpsnm       , & !  albedo of ice under clear sky when snow is melting
+         zalbpsnf       , & !  albedo of ice under clear sky when snow is freezing
+         zalbpsn        , & !  albedo of snow/ice system when ice is coverd by snow
+         zalbpic        , & !  albedo of snow/ice system when ice is free of snow
+         zithsn         , & !  = 1 for hsn >= 0 ( ice is cov. by snow ) ; = 0 otherwise (ice is free of snow)
+         zitmlsn        , & !  = 1 freezinz snow (sist >=rt0_snow) ; = 0 melting snow (sist<rt0_snow)
+         zihsc1         , & !  = 1 hsn <= c1 ; = 0 hsn > c1
+         zihsc2                   !  = 1 hsn >= c2 ; = 0 hsn < c2
+    REAL(wp), DIMENSION(jpi,jpj) ::  &
+         zalbfz         , & !  ( = alphdi for freezing ice ; = albice for melting ice )
+         zficeth                  !  function of ice thickness
+    LOGICAL , DIMENSION(jpi,jpj) ::  &
+         llmask
+    !!    to be included for without seaice
+    !!      REAL(wp), DIMENSION(jpi,jpj) ::   &  !:
+    !!      sist   ,   &  !: Sea-Ice Surface Temperature (Kelvin )
+    !!      hsnif  ,   &  !: Snow thickness
+    !!      hicif       !: Ice thickness
+    
+    !!---------------------------------------------------------------------
+
+    !-------------------------
+    !  Computation of  zficeth
+    !--------------------------
+
+    llmask = (hsnif == 0.0) .AND. ( sist >= rt0_ice )
+    WHERE ( llmask )   !  ice free of snow and melts
+       zalbfz = albice
+    ELSEWHERE
+       zalbfz = alphdi
+    END WHERE
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          IF( hicif(ji,jj) > 1.5 ) THEN
+             zficeth(ji,jj) = zalbfz(ji,jj)
+          ELSEIF( hicif(ji,jj) > 1.0  .AND. hicif(ji,jj) <= 1.5 ) THEN
+             zficeth(ji,jj) = 0.472 + 2.0 * ( zalbfz(ji,jj) - 0.472 ) * ( hicif(ji,jj) - 1.0 )
+          ELSEIF( hicif(ji,jj) > 0.05 .AND. hicif(ji,jj) <= 1.0 ) THEN
+             zficeth(ji,jj) = 0.2467 + 0.7049 * hicif(ji,jj)                                &
+                  &                    - 0.8608 * hicif(ji,jj) * hicif(ji,jj)                 &
+                  &                    + 0.3812 * hicif(ji,jj) * hicif(ji,jj) * hicif (ji,jj)
+          ELSE
+             zficeth(ji,jj) = 0.1 + 3.6 * hicif(ji,jj)
+          ENDIF
+       END DO
+    END DO
+
+    !-----------------------------------------------
+    !    Computation of the snow/ice albedo system
+    !-------------------------- ---------------------
+
+    !    Albedo of snow-ice for clear sky.
+    !-----------------------------------------------
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           !  Case of ice covered by snow.
+           !  melting snow
+           zihsc1       = 1.0 - MAX ( zzero , SIGN ( zone , - ( hsnif(ji,jj) - c1 ) ) )
+           zalbpsnm     = ( 1.0 - zihsc1 ) & 
+                * ( zficeth(ji,jj) + hsnif(ji,jj) * ( alphd - zficeth(ji,jj) ) / c1 ) &
+                &                 + zihsc1   * alphd
+          !  freezing snow
+           zihsc2       = MAX ( zzero , SIGN ( zone , hsnif(ji,jj) - c2 ) )
+           zalbpsnf     = ( 1.0 - zihsc2 ) * & 
+                ( albice + hsnif(ji,jj) * ( alphc - albice ) / c2 ) &
+                &                 + zihsc2   * alphc
+
+           zitmlsn      =  MAX ( zzero , SIGN ( zone , sist(ji,jj) - rt0_snow ) )
+           zalbpsn      =  zitmlsn * zalbpsnf + ( 1.0 - zitmlsn ) * zalbpsnm
+
+           !  Case of ice free of snow.
+           zalbpic      = zficeth(ji,jj)
+
+           ! albedo of the system
+           zithsn       = 1.0 - MAX ( zzero , SIGN ( zone , - hsnif(ji,jj) ) )
+           palbp(ji,jj) =  zithsn * zalbpsn + ( 1.0 - zithsn ) *  zalbpic
+        END DO
+     END DO
+
+     !    Albedo of snow-ice for overcast sky.
+     !----------------------------------------------
+     palb(:,:)   = palbp(:,:) + cgren
+
+     !--------------------------------------------
+     !    Computation of the albedo of the ocean
+     !-------------------------- -----------------
+
+
+     !  Parameterization of Briegled and Ramanathan, 1982
+     zmue14      = zmue**1.4
+     palcnp(:,:) = 0.05 / ( 1.1 * zmue14 + 0.15 )
+
+     !  Parameterization of Kondratyev, 1969 and Payne, 1972
+     palcn(:,:)  = 0.06
+
+   END SUBROUTINE flx_blk_albedo
+
+   SUBROUTINE core_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE ts_rst  ***
+     !!
+     !! ** Purpose : Read or write CORE specific variables ( gsss, gu, gv )
+     !!
+     !! ** Method  :
+     !!
+     !!----------------------------------------------------------------------
+     USE iom          ! move to top of flxmod to avoid duplication
+     USE restart      ! move to top of flxmod to avoid duplication
+     !
+     INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+     !
+     !!----------------------------------------------------------------------
+     !
+     IF( TRIM(cdrw) == 'READ' ) THEN
+        IF( ln_rstart ) THEN
+              CALL iom_get( numror, jpdom_autoglo, 'gsss', gsss )
+              CALL iom_get( numror, jpdom_autoglo, 'gu', gu )
+              CALL iom_get( numror, jpdom_autoglo, 'gv', gv )
+        ENDIF ! gsss, gu, gv are initialized in the routine ( may be changed )
+     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+        CALL iom_rstput( kt, nitrst, numrow, 'gsss', gsss )
+        CALL iom_rstput( kt, nitrst, numrow, 'gu', gu )
+        CALL iom_rstput( kt, nitrst, numrow, 'gv', gv )
+     ENDIF
+     !
+   END SUBROUTINE core_rst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_forced_daily.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_forced_daily.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_forced_daily.h90	(revision 4536)
@@ -0,0 +1,123 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flx_forced_daily  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   flx          : define the thermohaline fluxes for the ocean
+   !!                  in forced mode using flux formulation (not bulk)
+   !!                  (read in NetCDF file)
+   !!----------------------------------------------------------------------
+   !! * Modules used     C A U T I O N  already defined in flxmod.F90
+
+   !! * Module variables
+   INTEGER ::          &
+      numflx,          &  ! logical unit for surface fluxes data
+      ndayflx             ! new day for ecmwf flx forcing
+   REAL(wp), DIMENSION(jpi,jpj,3) ::   &
+      flxdta              ! 3 consecutive daily fluxes
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE flx  ***
+      !!                   
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater) 
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method  :   READ daily flux file in NetCDF files
+      !!      the net downward radiative flux qsr      1 (watt/m2)
+      !!      the net downward heat flux      q        2 (watt/m2)
+      !!      the net upward water            emp      3 (kg/m2/s)
+      !!      (evaporation - precipitation)
+      !!
+      !! History :
+      !!        !  90-03  (O. Marti and P. Dandin)  Original code
+      !!        !  92-07  (M. Imbard)
+      !!        !  96-11  (E. Guilyardi)  Daily AGCM input files
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with io-ipsl
+      !!        !  00-10  (J.-P. Boulanger)  adjusted for reading any
+      !!                         daily wind stress data including a climatology
+      !!        !  01-09  (A. Lazar and C. Levy)  config with no ice model
+      !!   8.5  !  03-07  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+      USE flx_oce
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt ! ocean time step
+
+      !!---------------------------------------------------------------------
+
+
+      ! First call kt=nit000
+      ! --------------------
+
+      IF( kt == nit000 ) THEN
+         
+         ndayflx = 0   ! Initialization
+         ! open the file
+         IF(lwp) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' **** Routine flx_forced_daily.h90'
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' daily fluxes Q, Qsr, EmP'
+         ENDIF
+         CALL iom_open ( 'flx_1d.nc', numflx )
+
+      ENDIF
+
+      ! Read daily fluxes in flxdta(1,1,jm) 
+      !     1. Qtot    (w/m2)
+      !     2. Qsr     (w/m2)
+      !     3. emp     (kg/m2/s)
+      
+      IF( ndayflx /= nday ) THEN 
+         
+         ndayflx = nday
+                  
+         ! read Qtot
+         CALL iom_get ( numflx, jpdom_data, 'sohefldo', flxdta(:,:,1), nday_year )
+         ! read qsr
+         CALL iom_get ( numflx, jpdom_data, 'soshfldo', flxdta(:,:,2), nday_year )
+         ! read emp
+         CALL iom_get ( numflx, jpdom_data, 'sowaflup', flxdta(:,:,3), nday_year )
+
+         IF(lwp) WRITE (numout,*)'Lecture flx record :',nday
+
+         IF( nit000 == 1 ) THEN 
+            IF( kt == nit000 ) THEN
+               IF(lwp) THEN
+                  WRITE(numout,*)
+                  WRITE(numout,*) ' read daily fluxes ok'
+                  WRITE(numout,*)
+                  WRITE(numout,*) ' Q * .1, day: ',ndastp
+                  CALL prihre( flxdta(:,:,1),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout )
+                  WRITE(numout,*)
+                  WRITE(numout,*) ' QSR * .1, day: ',ndastp
+                  CALL prihre( flxdta(:,:,2),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout )
+                  WRITE(numout,*)
+                  WRITE(numout,*) ' E-P *86400, day: ',ndastp
+                  CALL prihre( flxdta(:,:,3),jpi,jpj,1,jpi,20,1,jpj,10,86400.,numout )
+                  WRITE(numout,*) ' '
+               ENDIF
+            ENDIF
+         ENDIF
+      ENDIF
+
+      p_qt (:,:) = flxdta(:,:,1)
+      p_qsr(:,:) = flxdta(:,:,2)
+      p_emp(:,:) = flxdta(:,:,3)
+  
+      ! Closing all files
+      ! -----------------
+ 
+      IF( kt == nitend ) CALL iom_close ( numflx )
+ 
+   END SUBROUTINE flx
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oasis_ice.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oasis_ice.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oasis_ice.h90	(revision 4536)
@@ -0,0 +1,371 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  flx_oasis_ice.h90  ***
+   !!----------------------------------------------------------------------
+   !!   flx          : define the thermohaline fluxes for the ocean in
+   !!                  coupled ocean/atmosphere case with sea-ice
+   !!----------------------------------------------------------------------
+
+    REAL(wp) :: zcatm1  (1:jpi,1:jpj)  ! cloud fraction
+
+    REAL(wp) :: qsr_oce_recv   (1:jpi,1:jpj)
+    REAL(wp) :: qsr_ice_recv   (1:jpi,1:jpj)
+    REAL(wp) :: qnsr_oce_recv   (1:jpi,1:jpj)
+    REAL(wp) :: qnsr_ice_recv   (1:jpi,1:jpj)
+    REAL(wp) :: dqns_ice_recv   (1:jpi,1:jpj)
+    REAL(wp) :: tprecip_recv   (1:jpi,1:jpj)    
+    REAL(wp) :: sprecip_recv   (1:jpi,1:jpj)
+    REAL(wp) :: fr1_i0_recv   (1:jpi,1:jpj)    
+    REAL(wp) :: fr2_i0_recv   (1:jpi,1:jpj)    
+    REAL(wp) :: rrunoff_recv   (1:jpi,1:jpj)
+    REAL(wp) :: calving_recv   (1:jpi,1:jpj)
+#if defined key_cpl_ocevel
+    REAL(wp) :: un_weighted (1:jpi,1:jpj)
+    REAL(wp) :: vn_weighted (1:jpi,1:jpj)
+    REAL(wp) :: un_send (1:jpi,1:jpj)
+    REAL(wp) :: vn_send (1:jpi,1:jpj)
+#endif
+    REAL(wp) :: zrunriv (1:jpi,1:jpj)  ! river discharge into ocean
+    REAL(wp) :: zruncot (1:jpi,1:jpj)  ! continental discharge into ocean
+
+    REAL(wp) :: zpew    (1:jpi,1:jpj)  ! P-E over water
+    REAL(wp) :: zpei    (1:jpi,1:jpj)  ! P-E over ice
+    REAL(wp) :: zpsol   (1:jpi,1:jpj)  ! surface downward snow fall
+    REAL(wp) :: zevice  (1:jpi,1:jpj)  ! surface upward snow flux where sea ice
+
+   !! * Modules used     C A U T I O N  already defined in flxmod.F90
+   !!
+   !! * Module variables
+   LOGICAL :: lfirstf=.TRUE.
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+  SUBROUTINE flx( kt )
+    !!---------------------------------------------------------------------
+    !!                    ***  ROUTINE flx  ***
+    !!                   
+    !! ** Purpose :   exchange the thermohaline fields (heat and freshwater) 
+    !!                with the atmosphere at each ocean time step.
+    !!
+    !! ** Method  :   Receive and send fluxes from/to a coupled atmospheric model 
+    !!
+    !! References : The OASIS User Guide, Version 3.0
+    !!
+    !! History :
+    !!   9.0  !  04-11  (R. Redler)  Original code
+    !!        !  05-05  (W. Park, N. Keenlyside) Separation of recv and pass variables (ref.icestp.F90)
+    !!        !  05-09  (W. Park, N. Keenlyside) Implementation of ocean velocity
+    !!        !  06-06  (E. Maisonnave, W. Park) Oasis mask adaptation
+    !!----------------------------------------------------------------------
+    !! * Modules used
+     USE in_out_manager, only: numout ! I/O manager
+     
+    !! * Arguments
+    INTEGER, INTENT( in  ) ::   kt    ! ocean time step
+
+    !! * Local declarations
+    INTEGER :: ji, jj
+
+#if defined key_cpl_ocevel
+    INTEGER :: ikchoix=-1
+#endif
+
+    INTEGER  :: var_id
+    INTEGER  :: info, date, n
+
+    REAL(wp) :: zfacflx
+    REAL(wp) :: zfacwat
+    !
+    !!---------------------------------------------------------------------
+    !
+    ! Initialization
+    ! --------------
+    !
+    ! caution, I presume that you have good UNIT system from coupler to OPA
+    ! that is :
+    ! watt/m2 for znsolc and zqsrc
+    ! kg/m2/s for evaporation, precipitation and runoff
+    zfacflx = 1.e0
+    zfacwat = 1.e3  ! convert [m/s] to [kg/m**2/s]
+    !
+    date = ( kt - nit000 ) * rdttra(1)
+    !
+    ! 1. Send coupling fields
+    !------------------------
+    !
+    var_id = send_id(1)
+    CALL cpl_prism_send ( var_id, date, tn(:,:,1)+rt0, info )      
+    var_id = send_id(2)
+    CALL cpl_prism_send ( var_id, date, 1.0-frld, info )      
+
+#if defined key_cpl_albedo
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+         if (((tn_ice(ji,jj).lt.50).or.(tn_ice(ji,jj).gt.400)) .and. frld(ji,jj).lt.1.) then
+         WRITE(numout,*) ' tn_ice, ERROR ',ji,jj, ' = ', tn_ice(ji,jj), &
+          ' qnsr_ice_recv=', qnsr_ice_recv(ji,jj), ' dqns_ice_recv=', dqns_ice_recv(ji,jj)
+          endif
+       ENDDO
+    ENDDO
+    var_id = send_id(3)
+    CALL cpl_prism_send ( var_id, date, tn_ice, info )      
+
+    var_id = send_id(4)
+    CALL cpl_prism_send ( var_id, date, alb_ice, info )
+#else
+    var_id = send_id(3)
+    CALL cpl_prism_send ( var_id, date, hicif, info )      
+
+    var_id = send_id(4)
+    CALL cpl_prism_send ( var_id, date, hsnif, info )      
+#endif
+
+#if defined key_cpl_ocevel
+    un_weighted = un(:,:,1) * frld + u_ice * ( 1. - frld )
+    vn_weighted = vn(:,:,1) * frld + v_ice * ( 1. - frld )
+    CALL repere ( un_weighted, vn_weighted, un_send, vn_send, ikchoix )
+
+    var_id = send_id(5)
+    CALL cpl_prism_send ( var_id, date, un_send, info )
+
+    var_id = send_id(6)
+    CALL cpl_prism_send ( var_id, date, vn_send, info )
+#endif
+    !
+    ! 2. Receive and build flux fields
+    !---------------------------------
+    !
+    ! I.) Precipitation/Evaporation
+    ! -----------------------------
+    !
+    ! ... a) P-E over water
+    !
+    var_id = recv_id(9)
+    CALL cpl_prism_recv ( var_id, date, zpew,  info )
+    !
+    ! ... b) P-E over ice
+    !
+    var_id = recv_id(10)
+    CALL cpl_prism_recv ( var_id, date, zpei, info )
+    !
+    ! ... c) Snow fall over water and ice
+    !
+    var_id = recv_id(11)
+    CALL cpl_prism_recv ( var_id, date, zpsol, info  )
+    !
+    ! ... d) Evaporation over ice (sublimination)
+    !
+    var_id = recv_id(12)
+    CALL cpl_prism_recv ( var_id, date, zevice, info )
+    !
+    ! calculate water flux (PE over water and ice)  (positive upward)
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          tprecip_recv(ji,jj) = ( zpew(ji,jj) + zpei(ji,jj) ) * tmask(ji,jj,1) * zfacwat
+       ENDDO
+    ENDDO
+    IF (ln_ctl) THEN
+      WRITE(numout,*) ' flx:tprecip_recv    - Minimum value is ', MINVAL(tprecip_recv)
+      WRITE(numout,*) ' flx:tprecip_recv    - Maximum value is ', MAXVAL(tprecip_recv)
+      WRITE(numout,*) ' flx:tprecip_recv    -     Sum value is ', SUM(tprecip_recv)
+    ENDIF
+
+    IF ( SUM(zpew*e1t*e2t) /= SUM(zpew*e1t*e2t*tmask(:,:,1)) ) THEN
+       WRITE(numout,*) ' flx: Forcing values outside Orca mask'
+       WRITE(numout,*) ' flx: Losses in water conservation'
+       WRITE(numout,*) ' flx:   Masked ', SUM(zpew*e1t*e2t*tmask(:,:,1))
+       WRITE(numout,*) ' flx: Unmasked ', SUM(zpew*e1t*e2t)
+       WRITE(numout,*) ' flx: Simulation STOP'
+       CALL FLUSH(numout)
+       STOP
+    END IF
+
+    !
+    ! calculate solid precipitation  (positive upward)
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          sprecip_recv(ji,jj) = ( zpsol(ji,jj) + zevice(ji,jj) ) * tmask(ji,jj,1) * zfacwat
+       ENDDO
+    ENDDO
+    !
+    !
+    ! II.) Solar fluxes
+    ! ------------------
+    !
+    ! ... a) surface net downward shortwave flux
+    !
+    var_id = recv_id(13)
+    CALL cpl_prism_recv ( var_id, date, qsr_oce_recv, info )
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          qsr_oce_recv(ji,jj) =  qsr_oce_recv(ji,jj) * tmask(ji,jj,1) * zfacflx
+       ENDDO
+    ENDDO
+    !
+    ! ... b) surface downward non-solar heat flux in air
+    !
+    var_id = recv_id(14)
+    CALL cpl_prism_recv ( var_id, date, qnsr_oce_recv, info)
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          qnsr_oce_recv(ji,jj) = qnsr_oce_recv(ji,jj) * tmask(ji,jj,1) * zfacflx
+       ENDDO
+    ENDDO
+    !
+    ! ... c) solar heat flux on sea ice
+    !
+    var_id = recv_id(15)
+    CALL cpl_prism_recv ( var_id, date, qsr_ice_recv, info )
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          qsr_ice_recv(ji,jj) = qsr_ice_recv(ji,jj) * tmask(ji,jj,1) * zfacflx
+       ENDDO
+    ENDDO
+    !
+    ! ... d) non-solar heat flux on sea ice
+    !
+    var_id = recv_id(16)
+    CALL cpl_prism_recv ( var_id, date, qnsr_ice_recv, info)
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          qnsr_ice_recv(ji,jj) = qnsr_ice_recv(ji,jj) * tmask(ji,jj,1) * zfacflx
+       ENDDO
+    ENDDO
+    !
+    ! ... e) non solar heat flux derivative over ice
+    !
+    var_id = recv_id(17)
+    CALL cpl_prism_recv ( var_id, date, dqns_ice_recv, info)
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          dqns_ice_recv(ji,jj) =  dqns_ice_recv(ji,jj) * tmask(ji,jj,1) * zfacflx
+       ENDDO
+    ENDDO
+    !
+    ! Since cloud cover catm not transmitted from atmosphere, init =0. 
+    !
+    catm(:, :) = 0.
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          zcatm1(ji,jj) = 1.0    - catm  (ji,jj)  !  fractional cloud cover
+       END DO
+    END DO
+
+    !  fraction of net shortwave radiation which is not absorbed in the 
+    !  thin surface layer and penetrates inside the ice cover 
+    !  ( Maykut and Untersteiner, 1971 ; Elbert anbd Curry, 1993 )
+    !------------------------------------------------------------------
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          fr1_i0_recv(ji,jj) = 0.18  * zcatm1(ji,jj) + 0.35 * catm(ji,jj) 
+          fr2_i0_recv(ji,jj) = 0.82  * zcatm1(ji,jj) + 0.65 * catm(ji,jj)
+       END DO
+    END DO
+    !
+#if defined key_cpl_discharge
+    ! III.) Runoff
+    ! -----------
+    !
+    ! ... a) ice discharge into ocean
+    !
+    var_id = recv_id(18)
+    CALL cpl_prism_recv ( var_id, date, calving_recv, info )
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          calving_recv(ji,jj) = calving_recv(ji,jj) * tmask(ji,jj,1) * zfacwat
+       ENDDO
+    ENDDO
+    !
+    ! ... b) river discharge into ocean
+    !
+    var_id = recv_id(19)
+    CALL cpl_prism_recv ( var_id, date, zrunriv, info )
+    !
+    ! ... c) continental discharge into ocean
+    !
+    var_id = recv_id(20)
+    CALL cpl_prism_recv ( var_id, date, zruncot, info)
+
+    DO jj = 1, jpj
+       DO ji = 1, jpi
+          rrunoff_recv(ji,jj) = ( zrunriv(ji,jj) + zruncot (ji,jj) ) * tmask(ji,jj,1) * zfacwat
+       ENDDO
+    ENDDO
+    !
+#else
+    calving_recv = 0.
+    rrunoff_recv = 0.
+#endif
+
+    ! Oasis mask shift and update lateral boundary conditions (E. Maisonnave)
+    ! not tested when mpp is used, W. Park
+!WSPTEST
+    qsr_oce_recv(jpi-1,:) = qsr_oce_recv(1,:)
+    qsr_ice_recv(jpi-1,:) = qsr_ice_recv(1,:)
+    qnsr_oce_recv(jpi-1,:) = qnsr_oce_recv(1,:)
+    qnsr_ice_recv(jpi-1,:) = qnsr_ice_recv(1,:)
+    dqns_ice_recv(jpi-1,:) = dqns_ice_recv(1,:)
+    tprecip_recv(jpi-1,:) = tprecip_recv(1,:)
+    sprecip_recv(jpi-1,:) = sprecip_recv(1,:)
+    fr1_i0_recv(jpi-1,:) = fr1_i0_recv(1,:)
+    fr2_i0_recv(jpi-1,:) = fr2_i0_recv(1,:)
+    rrunoff_recv(jpi-1,:) = rrunoff_recv(1,:)
+    calving_recv(jpi-1,:) = calving_recv(1,:)
+
+    qsr_oce = qsr_oce_recv
+    qsr_ice = qsr_ice_recv
+    qnsr_oce = qnsr_oce_recv
+    qnsr_ice = qnsr_ice_recv
+    dqns_ice = dqns_ice_recv
+    tprecip = tprecip_recv 
+    sprecip = sprecip_recv 
+    fr1_i0 = fr1_i0_recv  
+    fr2_i0 = fr2_i0_recv  
+!WSP    rrunoff = rrunoff_recv 
+!WSP    calving = calving_recv
+    rrunoff = 0.  !WSP runoff and calving included in tprecip
+    calving = 0.  !WSP
+ 
+    IF(ln_ctl) THEN
+    write(numout,*) 'flx:qsr_oce     - Minimum value is ', minval(qsr_oce)
+    write(numout,*) 'flx:qsr_oce     - Maximum value is ', maxval(qsr_oce)
+    write(numout,*) 'flx:qsr_oce     -     Sum value is ', SUM(qsr_oce)
+
+    write(numout,*) 'flx:tprecip     - Minimum value is ', minval(tprecip)
+    write(numout,*) 'flx:tprecip     - Maximum value is ', maxval(tprecip)
+    write(numout,*) 'flx:tprecip     -     Sum value is ', SUM(tprecip)
+    ENDIF
+
+    CALL lbc_lnk( qsr_oce , 'T', 1. )
+    CALL lbc_lnk( qsr_ice , 'T', 1. )
+    CALL lbc_lnk( qnsr_oce, 'T', 1. )
+    CALL lbc_lnk( qnsr_ice, 'T', 1. )
+    CALL lbc_lnk( tprecip , 'T', 1. )
+    CALL lbc_lnk( sprecip , 'T', 1. )
+    CALL lbc_lnk( rrunoff , 'T', 1. )
+    CALL lbc_lnk( dqns_ice, 'T', 1. )
+    CALL lbc_lnk( calving , 'T', 1. )
+    CALL lbc_lnk( fr1_i0  , 'T', 1. )
+    CALL lbc_lnk( fr2_i0  , 'T', 1. )
+
+    IF(ln_ctl) THEN
+    write(numout,*) 'flx(af lbc_lnk):qsr_oce     - Minimum value is ', minval(qsr_oce)
+    write(numout,*) 'flx(af lbc_lnk):qsr_oce     - Maximum value is ', maxval(qsr_oce)
+    write(numout,*) 'flx(af lbc_lnk):qsr_oce     -     Sum value is ', SUM(qsr_oce)
+
+    write(numout,*) 'flx(af lbc_lnk):tprecip     - Minimum value is ', minval(tprecip)
+    write(numout,*) 'flx(af lbc_lnk):tprecip     - Maximum value is ', maxval(tprecip)
+    write(numout,*) 'flx(af lbc_lnk):tprecip     -     Sum value is ', SUM(tprecip)
+    ENDIF
+
+END SUBROUTINE flx
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flx_oce.F90	(revision 4536)
@@ -0,0 +1,62 @@
+MODULE flx_oce
+   !!======================================================================
+   !!                 ***  MODULE  flx_oce  ***
+   !!        parameter and  variables defined in memory in forced mode
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-11  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+
+   !!----------------------------------------------------------------------
+   !! fluxes common variables
+   !!----------------------------------------------------------------------
+#if defined key_flx_forced_daily
+   !!----------------------------------------------------------------------
+   !! 'key_flx_forced_daily'
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      p_qt ,        &   !: total heat flux ( solar + non solar)
+      p_qsr,        &   !: solar heat flux
+      p_emp             !: evaporation minus precipitation            
+
+#elif defined key_ice_lim || defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)    ::   &  !:
+      qsr_ice  ,      &  !: solar flux over ice
+      qsr_oce  ,      &  !: solar flux over ocean
+      qnsr_oce ,      &  !: total non solar heat flux (Longwave downward radiation) over ocean 
+      qnsr_ice ,      &  !: total non solar heat flux (Longwave downward radiation) over ice
+      tprecip  ,      &  !: total precipitation ( or liquid precip minus evaporation in coupled mode)
+      sprecip  ,      &  !: solid (snow) precipitation
+      dqns_ice ,      &  !: total non solar sensibility over ice (LW+SEN+LA)
+      tn_ice   ,      &  !: ice surface temperature
+      evap     ,      &  !: evaporation over ocean
+      fr1_i0   ,      &  !: 1st part of the fraction of sol. rad.  which penetrate inside the ice cover
+      fr2_i0   ,      &  !: 2nd part of the fraction of sol. rad.  which penetrate inside the ice cover 
+#if ! defined key_coupled
+      qla_ice  ,      &  !: latent flux over ice  
+      dqla_ice           !: latent sensibility over ice
+#else
+      rrunoff  ,      &  !: runoff
+      calving  ,      &  !: calving
+      alb_ice            !: albedo of ice      
+#endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE flx_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxblk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxblk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxblk.F90	(revision 4536)
@@ -0,0 +1,741 @@
+MODULE flxblk
+   !!======================================================================
+   !!                       ***  MODULE  flxblk  ***
+   !! Ocean forcing:  bulk thermohaline forcing of the ocean (or ice)
+   !!=====================================================================
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+   !!----------------------------------------------------------------------
+   !!   'key_flx_bulk_monthly'   or                            MONTHLY bulk
+   !!   'key_flx_bulk_daily'                                     DAILY bulk
+   !!----------------------------------------------------------------------
+   !!   flx_blk        : thermohaline fluxes from bulk
+   !!   flx_blk_declin : solar declinaison
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE cpl_oce         ! ???
+   USE phycst          ! physical constants
+   USE daymod
+   USE blk_oce         ! bulk variables
+   USE flx_oce         ! forcings variables
+   USE ocfzpt          ! ???
+   USE in_out_manager
+   USE lbclnk
+   USE albedo
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC flx_blk        ! routine called by flx.F90 
+
+   !! * Module variables
+   INTEGER, PARAMETER  ::   &
+      jpintsr = 24          ! number of time step between sunrise and sunset
+      !                     ! uses for heat flux computation
+   LOGICAL ::   &
+      lbulk_init = .TRUE.   ! flag, bulk initialization done or not)
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   &
+      stauc            ,  &   ! cloud optical depth 
+      sbudyko   
+
+   !! * constants for bulk computation (flx_blk)
+   REAL(wp), DIMENSION(19)  ::  &
+      budyko                  ! BUDYKO's coefficient
+   ! BUDYKO's coefficient (cloudiness effect on LW radiation):
+   DATA budyko / 1.00, 0.98, 0.95, 0.92, 0.89, 0.86, 0.83, 0.80, 0.78, 0.75,  &
+      &          0.72, 0.69, 0.67, 0.64, 0.61, 0.58, 0.56, 0.53, 0.50 /
+   REAL(wp), DIMENSION(20)  :: &
+      tauco                  ! cloud optical depth coefficient
+   ! Cloud optical depth coefficient
+   DATA tauco / 6.6, 6.6, 7.0, 7.2, 7.1, 6.8, 6.5, 6.6, 7.1, 7.6,   &
+      &         6.6, 6.1, 5.6, 5.5, 5.8, 5.8, 5.6, 5.6, 5.6, 5.6 /
+   REAL(wp)  ::            &  ! constant values
+      zeps    = 1.e-20  ,  &
+      zeps0   = 1.e-13  ,  &
+      zeps1   = 1.e-06  ,  &
+      zzero   = 0.e0    ,  &
+      zone    = 1.0
+
+   !! * constants for solar declinaison computation (flx_blk_declin)
+   REAL(wp) ::                &
+      a0  =  0.39507671   ,   &  ! coefficients
+      a1  = 22.85684301   ,   &
+      a2  = -0.38637317   ,   &
+      a3  =  0.15096535   ,   &
+      a4  = -0.00961411   ,   &
+      b1  = -4.29692073   ,   &
+      b2  =  0.05702074   ,   &
+      b3  = -0.09028607   ,   &
+      b4  =  0.00592797
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx_blk( psst )
+      !!---------------------------------------------------------------------------
+      !!                     ***  ROUTINE flx_blk  ***
+      !!                 
+      !!  ** Purpose :   Computation of the heat fluxes at ocean and snow/ice
+      !!       surface the solar heat at ocean and snow/ice surfaces and the 
+      !!       sensitivity of total heat fluxes to the SST variations
+      !!         
+      !!  ** Method  :   The flux of heat at the ice and ocean surfaces are derived
+      !!       from semi-empirical ( or bulk ) formulae which relate the flux to 
+      !!       the properties of the surface and of the lower atmosphere. Here, we
+      !!       follow the work of Oberhuber, 1988   
+      !!
+      !!  ** Action  :   call flx_blk_albedo to compute ocean and ice albedo 
+      !!          computation of snow precipitation
+      !!          computation of solar flux at the ocean and ice surfaces
+      !!          computation of the long-wave radiation for the ocean and sea/ice
+      !!          computation of turbulent heat fluxes over water and ice
+      !!          computation of evaporation over water
+      !!          computation of total heat fluxes sensitivity over ice (dQ/dT)
+      !!          computation of latent heat flux sensitivity over ice (dQla/dT)
+      !!
+      !! History :
+      !!   8.0  !  97-06  (Louvain-La-Neuve)  Original code
+      !!   8.5  !  02-09  (C. Ethe , G. Madec )  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) ::   &
+         &                          psst      ! Sea Surface Temperature 
+
+      !! * Local variables
+      INTEGER  ::             &
+         ji, jj, jt        ,  &  ! dummy loop indices
+         indaet            ,  &  !  = -1, 0, 1 for odd, normal and leap years resp.
+         iday              ,  &  ! integer part of day
+         indxb             ,  &  ! index for budyko coefficient
+         indxc                   ! index for cloud depth coefficient
+
+      REAL(wp)  ::            & 
+         zalat , zclat     ,  &  ! latitude in degrees 
+         zmt1, zmt2, zmt3  ,  &  ! tempory air temperatures variables
+         ztatm3, ztatm4    ,  &  ! power 3 and 4 of air temperature
+         z4tatm3           ,  &  ! 4 * ztatm3
+         zcmue             ,  &  ! cosine of local solar altitude
+         zcmue2            ,  &  ! root of zcmue1 
+         zscmue            ,  &  ! square-root of zcmue1 
+         zpcmue            ,  &  ! zcmue1**1.4
+         zdecl             ,  &  ! solar declination
+         zsdecl , zcdecl   ,  &  ! sine and cosine of solar declination 
+         zalbo             ,  &  ! albedo of sea-water
+         zalbi             ,  &  ! albedo of ice
+         ztamr             ,  &  ! air temperature minus triple point of water (rtt)
+         ztaevbk           ,  &  ! part of net longwave radiation
+         zevi , zevo       ,  &  ! vapour pressure of ice and ocean 
+         zind1,zind2,zind3 ,  &  ! switch for testing the values of air temperature
+         zinda             ,  &  ! switch for testing the values of sea ice cover
+         zpis2             ,  &  ! pi / 2
+         z2pi                    ! 2 * pi 
+
+      REAL(wp)  ::            & 
+         zxday             ,  &  ! day of year
+         zdist             ,  &  ! distance between the sun and the earth during the year
+         zdaycor           ,  &  ! corr. factor to take into account the variation of 
+         !                       ! zday when calc. the solar rad.    
+         zesi, zeso        ,  &  ! vapour pressure of ice and ocean at saturation
+         zesi2             ,  &  ! root of zesi 
+         zqsato            ,  &  ! humidity close to the ocean surface (at saturation)   
+         zqsati            ,  &  ! humidity close to the ice surface (at saturation) 
+         zqsati2           ,  &  ! root of  zqsati 
+         zdesidt           ,  &  ! derivative of zesi, function of ice temperature
+         zdteta            ,  &  ! diff. betw. sst and air temperature
+         zdeltaq           ,  &  ! diff. betw. spec. hum. and hum. close to the surface
+         ztvmoy, zobouks   ,  &  ! tempory scalars
+         zpsims, zpsihs, zpsils, zobouku, zxins, zpsimu ,  & 
+         zpsihu, zpsilu, zstab,zpsim, zpsih, zpsil      ,  & 
+         zvatmg, zcmn, zchn, zcln, zcmcmn, zdenum       ,  & 
+         zdtetar, ztvmoyr, zlxins, zcmn2, zchcm, zclcm , zcoef
+
+      REAL(wp)  ::            & 
+         zrhova            ,  &  ! air density per wind speed
+         zcsho , zcleo     ,  &  ! transfer coefficient over ocean
+         zcshi , zclei     ,  &  ! transfer coefficient over ice-free
+         zrhovacleo        ,  &  ! air density per wind speed per transfer coef.
+         zrhovacsho, zrhovaclei, zrhovacshi, & 
+         ztice3            ,  &  ! power 3 of ice temperature
+         zticemb, zticemb2 ,  &  ! tempory air temperatures variables
+         zdqlw_ice         ,  &  ! sensitivity of long-wave flux over ice
+         zdqsb_ice         ,  &  ! sensitivity of sensible heat flux over ice
+         zdqla_ice         ,  &  ! sensitivity of latent heat flux over ice
+         zdl, zdr                ! fractionnal part of latitude
+      REAL(wp), DIMENSION(jpi,jpj) :: & 
+         zpatm            ,  &   ! atmospheric pressure
+         zqatm            ,  &   ! specific humidity
+         zes              ,  &   ! vapour pressure at saturation
+         zev, zevsqr      ,  &   ! vapour pressure and his square-root
+         zrhoa            ,  &   ! air density
+         ztatm            ,  &   ! air temperature in Kelvins
+         zfrld            ,  &   ! fraction of sea ice cover 
+         zcatm1           ,  &   ! fraction of cloud
+         zcldeff                 ! correction factor to account cloud effect
+      REAL(wp), DIMENSION(jpi,jpj) ::   & 
+         zalbocsd         ,  &   ! albedo of ocean
+         zalboos          ,  &   ! albedo of ocean under overcast sky
+         zalbics          ,  &   ! albedo of ice under clear sky
+         zalbios          ,  &   ! albedo of ice under overcast sky
+         zalbomu          ,  &   ! albedo of ocean when zcmue is 0.4
+         zqsro            ,  &   ! solar radiation over ocean
+         zqsrics          ,  &   ! solar radiation over ice under clear sky
+         zqsrios          ,  &   ! solar radiation over ice under overcast sky
+         zcldcor          ,  &   ! cloud correction
+         zlsrise, zlsset  ,  &   ! sunrise and sunset
+         zlmunoon         ,  &   ! local noon solar altitude
+         zdlha            ,  &   ! length of the ninstr segments of the solar day
+         zps              ,  &   ! sine of latitude per sine of solar decli.
+         zpc                     ! cosine of latitude per cosine of solar decli. 
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   & 
+         zqlw_oce         ,  &   ! long-wave heat flux over ocean
+         zqlw_ice         ,  &   ! long-wave heat flux over ice
+         zqla_oce         ,  &   ! latent heat flux over ocean
+         zqla_ice         ,  &   ! latent heat flux over ice
+         zqsb_oce         ,  &   ! sensible heat flux over ocean
+         zqsb_ice                ! sensible heat flux over ice
+ 
+      REAL(wp), DIMENSION(jpi,jpj,jpintsr) ::    &
+         zlha             ,  &   ! local hour angle
+         zalbocs          ,  &   ! tempory var. of ocean albedo under clear sky
+         zsqsro           ,  &   ! tempory var. of solar rad. over ocean 
+         zsqsrics         ,  &   ! temp. var. of solar rad. over ice under clear sky
+         zsqsrios                ! temp. var. of solar rad. over ice under overcast sky
+      !!---------------------------------------------------------------------
+
+      !---------------------
+      !   Initilization    !
+      !---------------------
+#if ! defined key_ice_lim
+      tn_ice(:,:) = psst(:,:)
+#endif
+
+      !  Determine cloud optical depths as a function of latitude (Chou et al., 1981).
+      !  and the correction factor for taking into account  the effect of clouds 
+      !------------------------------------------------------
+      IF( lbulk_init ) THEN
+         DO jj = 1, jpj  
+            DO ji = 1 , jpi
+               zalat          = ( 90.e0 - ABS( gphit(ji,jj) ) ) /  5.e0
+               zclat          = ( 95.e0 -      gphit(ji,jj)   ) / 10.e0
+               indxb          = 1 + INT( zalat ) 
+               !  correction factor to account for the effect of clouds 
+               sbudyko(ji,jj) = budyko(indxb)  
+               indxc          = 1 + INT( zclat )  
+               zdl            = zclat - INT( zclat ) 
+               zdr            = 1.0 - zdl
+               stauc(ji,jj)   = zdr * tauco( indxc ) + zdl * tauco( indxc + 1 ) 
+            END DO
+         END DO
+         IF( nleapy == 1 ) THEN
+            yearday = 366.e0
+         ELSE IF( nleapy == 0 ) THEN
+            yearday = 365.e0
+         ELSEIF( nleapy == 30) THEN
+            yearday = 360.e0
+         ENDIF
+         lbulk_init = .FALSE.
+      ENDIF
+
+      zqlw_oce(:,:) = 0.e0
+      zqla_oce(:,:) = 0.e0
+      zqsb_oce(:,:) = 0.e0
+      zqlw_ice(:,:) = 0.e0
+      zqla_ice(:,:) = 0.e0
+      zqsb_ice(:,:) = 0.e0
+
+      zpis2       = rpi / 2.
+      z2pi        = 2. * rpi
+
+ !CDIR NOVERRCHK
+      DO jj = 1, jpj
+ !CDIR NOVERRCHK
+         DO ji = 1, jpi
+
+            ztatm (ji,jj) = 273.15 + tatm  (ji,jj)  !  air temperature in Kelvins 
+            zcatm1(ji,jj) = 1.0    - catm  (ji,jj)  !  fractional cloud cover
+            zfrld (ji,jj) = 1.0    - freeze(ji,jj)  !  fractional sea ice cover
+            zpatm(ji,jj)  = 101000.               !  pressure 
+      
+            !  Computation of air density, obtained from the equation of state for dry air. 
+            zrhoa(ji,jj) = zpatm(ji,jj) / ( 287.04 * ztatm(ji,jj) )
+      
+            !  zes : Saturation water vapour
+            ztamr = ztatm(ji,jj) - rtt
+            zmt1  = SIGN( 17.269, ztamr )
+            zmt2  = SIGN( 21.875, ztamr )
+            zmt3  = SIGN( 28.200, -ztamr )
+            zes(ji,jj) = 611.0 * EXP (  ABS( ztamr ) * MIN ( zmt1, zmt2 )   &
+               &                      / ( ztatm(ji,jj) - 35.86  + MAX( zzero, zmt3 ) ) )
+
+            !  zev : vapour pressure  (hatm is relative humidity)  
+            zev(ji,jj)   = hatm(ji,jj) * zes(ji,jj) 
+            !  square-root of vapour pressure
+!CDIR NOVERRCHK
+            zevsqr(ji,jj) = SQRT( zev(ji,jj) * 0.01 )
+            !  zqapb  : specific humidity 
+            zqatm(ji,jj) = 0.622 * zev(ji,jj) / ( zpatm(ji,jj) - 0.378 * zev(ji,jj) )
+
+
+            !----------------------------------------------------
+            !   Computation of snow precipitation (Ledley, 1985) |
+            !----------------------------------------------------
+
+            zmt1  =   253.0 - ztatm(ji,jj)
+            zmt2  = ( 272.0 - ztatm(ji,jj) ) / 38.0 
+            zmt3  = ( 281.0 - ztatm(ji,jj) ) / 18.0
+            zind1 = MAX( zzero, SIGN( zone, zmt1 ) )
+            zind2 = MAX( zzero, SIGN( zone, zmt2 ) )
+            zind3 = MAX( zzero, SIGN( zone, zmt3 ) )
+            ! total precipitation
+            tprecip(ji,jj) = watm(ji,jj)
+            ! solid  (snow) precipitation
+            sprecip(ji,jj) = tprecip(ji,jj) *       &
+               &             (           zind1      &
+               &               + ( 1.0 - zind1 ) * ( zind2 * ( 0.5 + zmt2 ) + ( 1.0 - zind2 ) *  zind3 * zmt3 ) ) 
+         END DO
+      END DO
+
+      !----------------------------------------------------------
+      !   Computation of albedo (need to calculates heat fluxes)|
+      !-----------------------------------------------------------
+      
+      CALL flx_blk_albedo( zalbios, zalboos, zalbics, zalbomu )
+
+      !-------------------------------------
+      !   Computation of solar irradiance. |
+      !----------------------------------------
+      indaet   = 1  
+      !  compution of the day of the year at which the fluxes have to be calculate 
+      !--The date corresponds to the middle of the time step.
+      zxday=nday_year + rdtbs2/rday
+
+      iday   = INT( zxday )
+
+      IF(ln_ctl) CALL prt_ctl_info('declin : iday ', ivar1=iday, clinfo2=' nfbulk= ', ivar2=nfbulk)
+
+      !   computation of the solar declination, his sine and his cosine
+      CALL flx_blk_declin( indaet, iday, zdecl )
+      
+      zdecl    = zdecl * rad
+      zsdecl   = SIN( zdecl )
+      zcdecl   = COS( zdecl )
+      
+      !  correction factor added for computation of shortwave flux to take into account the variation of
+      !  the distance between the sun and the earth during the year (Oberhuber 1988)
+      zdist    = zxday * z2pi / yearday
+      zdaycor  = 1.0 + 0.0013 * SIN( zdist ) + 0.0342 * COS( zdist )
+
+!CDIR NOVERRCHK
+      DO jj = 1, jpj
+!CDIR NOVERRCHK
+         DO ji = 1, jpi
+            !  product of sine of latitude and sine of solar declination
+            zps     (ji,jj) = SIN( gphit(ji,jj) * rad ) * zsdecl
+            !  product of cosine of latitude and cosine of solar declination
+            zpc     (ji,jj) = COS( gphit(ji,jj) * rad ) * zcdecl
+            !  computation of the both local time of sunrise and sunset
+            zlsrise (ji,jj) = ACOS( - SIGN( zone, zps(ji,jj) ) * MIN( zone, SIGN( zone, zps(ji,jj) )  &
+               &                     * ( zps(ji,jj) / zpc(ji,jj) ) ) ) 
+            zlsset  (ji,jj) = - zlsrise(ji,jj)
+            !  dividing the solar day into jpintsr segments of length zdlha
+            zdlha   (ji,jj) = ( zlsrise(ji,jj) - zlsset(ji,jj) ) / REAL( jpintsr )
+            !  computation of the local noon solar altitude
+            zlmunoon(ji,jj) = ASIN ( ( zps(ji,jj) + zpc(ji,jj) ) ) / rad
+            
+            !  cloud correction taken from Reed (1977) (imposed lower than 1)
+            zcldcor (ji,jj) = MIN( zone, ( 1.e0 - 0.62 * catm(ji,jj) + 0.0019 * zlmunoon(ji,jj) ) )
+         END DO
+      END DO
+
+         !  Computation of solar heat flux at each time of the day between sunrise and sunset. 
+         !  We do this to a better optimisation of the code 
+         !------------------------------------------------------       
+
+!CDIR NOVERRCHK   
+      DO jt = 1, jpintsr   
+         zcoef = FLOAT( jt ) - 0.5
+!CDIR NOVERRCHK     
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               !  local hour angle
+               zlha (ji,jj,jt) = COS ( zlsrise(ji,jj) - zcoef * zdlha(ji,jj) )
+
+               ! cosine of local solar altitude
+               zcmue              = MAX ( zzero ,   zps(ji,jj) + zpc(ji,jj) * zlha (ji,jj,jt)  )
+               zcmue2             = 1368.0 * zcmue * zcmue
+               zscmue             = SQRT ( zcmue )
+               zpcmue             = zcmue**1.4
+               ! computation of sea-water albedo (Payne, 1972)
+               zalbocs(ji,jj,jt)  = 0.05 / ( 1.1 * zpcmue + 0.15 )
+               zalbo              = zcatm1(ji,jj) * zalbocs(ji,jj,jt) + catm(ji,jj) * zalboos(ji,jj)
+               ! solar heat flux absorbed at ocean surfaces (Zillman, 1972)
+               zevo               = zev(ji,jj) * 1.0e-05
+               zsqsro(ji,jj,jt)   =  ( 1.0 - zalbo ) * zdlha(ji,jj) * zcmue2                &
+                                   / ( ( zcmue + 2.7 ) * zevo + 1.085 * zcmue +  0.10 )
+               !  solar heat flux absorbed at sea/ice surfaces 
+               !  Formulation of Shine and Crane, 1984 adapted for high albedo surfaces 
+
+               !  For clear sky        
+               zevi               = zevo
+               zalbi              = zalbics(ji,jj)
+               zsqsrics(ji,jj,jt) =  ( 1.0 - zalbi ) * zdlha(ji,jj) * zcmue2                &
+                  &                / ( ( 1.0 + zcmue ) * zevi + 1.2 * zcmue + 0.0455 )
+
+               ! For overcast sky
+               zalbi              = zalbios(ji,jj)
+               zsqsrios(ji,jj,jt) = zdlha(ji,jj) *                                                           &
+                  &                 ( ( 53.5 + 1274.5 * zcmue      ) *  zscmue * ( 1.0 - 0.996  * zalbi ) )  &
+                  &                 / (  1.0 + 0.139  * stauc(ji,jj) *           ( 1.0 - 0.9435 * zalbi ) )
+            END DO
+         END DO
+      END DO
+
+
+      !  Computation of daily (between sunrise and sunset) solar heat flux absorbed 
+      !  at the ocean and snow/ice surfaces.
+      !--------------------------------------------------------------------
+
+      zalbocsd(:,:) = 0.e0
+      zqsro   (:,:) = 0.e0
+      zqsrics (:,:) = 0.e0
+      zqsrios (:,:) = 0.e0
+
+      DO jt = 1, jpintsr 
+#   if defined key_vectopt_loop && ! defined key_mpp_omp
+         DO ji = 1, jpij  
+            zalbocsd(ji,1) = zalbocsd(ji,1) + zdlha   (ji,1) * zalbocs(ji,1,jt)   &
+               &                                             / MAX( 2.0 * zlsrise(ji,1) , zeps0 )
+            zqsro   (ji,1) = zqsro   (ji,1) + zsqsro  (ji,1,jt)
+            zqsrics (ji,1) = zqsrics (ji,1) + zsqsrics(ji,1,jt)
+            zqsrios (ji,1) = zqsrios (ji,1) + zsqsrios(ji,1,jt)
+         END DO
+#  else
+         DO jj = 1, jpj
+            DO ji = 1, jpi  
+               zalbocsd(ji,jj) = zalbocsd(ji,jj) + zdlha(ji,jj) * zalbocs(ji,jj,jt)   &
+                  &                                              / MAX( 2.0 * zlsrise(ji,jj) , zeps0 )
+               zqsro  (ji,jj)  = zqsro   (ji,jj) + zsqsro  (ji,jj,jt)
+               zqsrics(ji,jj)  = zqsrics (ji,jj) + zsqsrics(ji,jj,jt)
+               zqsrios(ji,jj)  = zqsrios (ji,jj) + zsqsrios(ji,jj,jt)
+            END DO
+         END DO
+#  endif
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi 
+
+            !------------------------------------------- 
+            !  Computation of shortwave radiation.
+            !-------------------------------------------
+
+            ! the solar heat flux absorbed at ocean and snow/ice surfaces
+            !------------------------------------------------------------
+
+            ! For ocean
+            qsr_oce(ji,jj) = srgamma * zcldcor(ji,jj) * zqsro(ji,jj) / z2pi
+            zinda          = SIGN( zone , -( -0.5 - zfrld(ji,jj) ) )
+            zinda          = 1.0 - MAX( zzero , zinda )
+            qsr_oce(ji,jj) = ( 1.- zinda ) * qsr_oce(ji,jj)
+
+            ! For snow/ice 
+            qsr_ice(ji,jj) = ( zcatm1(ji,jj) * zqsrics(ji,jj) + catm(ji,jj) * zqsrios(ji,jj) ) / z2pi
+
+
+            ! Taking into account the ellipsity of the earth orbit
+            !-----------------------------------------------------
+
+            qsr_ice(ji,jj) = qsr_ice(ji,jj) * zdaycor
+            qsr_oce(ji,jj) = qsr_oce(ji,jj) * zdaycor
+
+            !  fraction of net shortwave radiation which is not absorbed in the 
+            !  thin surface layer and penetrates inside the ice cover 
+            !  ( Maykut and Untersteiner, 1971 ; Elbert anbd Curry, 1993 )
+            !------------------------------------------------------------------
+
+            fr1_i0(ji,jj) = 0.18  * zcatm1(ji,jj) + 0.35 * catm(ji,jj) 
+            fr2_i0(ji,jj) = 0.82  * zcatm1(ji,jj) + 0.65 * catm(ji,jj)
+
+            !---------------------------------------------------------------------------
+            !   Computation of long-wave radiation  ( Berliand 1952 ; all latitudes )
+            !---------------------------------------------------------------------------
+
+            ! tempory variables
+            ztatm3         = ztatm(ji,jj) * ztatm(ji,jj) * ztatm(ji,jj)
+            ztatm4         = ztatm3 * ztatm(ji,jj)
+            z4tatm3        = 4. * ztatm3
+            zcldeff(ji,jj) = 1.0 - sbudyko(ji,jj) * catm(ji,jj) * catm(ji,jj)    
+            ztaevbk        = ztatm4 * zcldeff(ji,jj) * ( 0.39 - 0.05 * zevsqr(ji,jj) ) 
+
+            !  Long-Wave for Ice
+            !----------------------
+            zqlw_ice(ji,jj) = - emic * stefan * ( ztaevbk + z4tatm3 * ( tn_ice(ji,jj) - ztatm(ji,jj) ) ) 
+
+            !  Long-Wave for Ocean
+            !-----------------------
+            zqlw_oce(ji,jj) = - emic * stefan * ( ztaevbk + z4tatm3 * ( psst  (ji,jj) - ztatm(ji,jj) ) ) 
+
+         END DO
+      END DO
+
+      !----------------------------------------
+      !  Computation of turbulent heat fluxes  ( Latent and sensible ) 
+      !----------------------------------------        
+      !CDIR NOVERRCHK
+      DO jj = 2 , jpjm1
+!ib   DO jj = 1 , jpj
+         !CDIR NOVERRCHK
+         DO  ji = 1, jpi
+
+            !  Turbulent heat fluxes over water
+            !----------------------------------
+
+            ! zeso     : vapour pressure at saturation of ocean
+            ! zqsato   : humidity close to the ocean surface (at saturation)
+            zeso          =  611.0 * EXP ( 17.2693884 * ( psst(ji,jj) - rtt ) * tmask(ji,jj,1) / ( psst(ji,jj) - 35.86 ) )
+            zqsato        = ( 0.622 * zeso ) / ( zpatm(ji,jj) - 0.378 * zeso )
+
+            !  Drag coefficients from Large and Pond (1981,1982)
+            !---------------------------------------------------
+    
+            !  Stability parameters
+            zdteta         = psst(ji,jj) - ztatm(ji,jj)
+            zdeltaq        = zqatm(ji,jj) - zqsato
+            ztvmoy         = ztatm(ji,jj) * ( 1. + 2.2e-3 * ztatm(ji,jj) * zqatm(ji,jj) )
+            zdenum         = MAX( vatm(ji,jj) * vatm(ji,jj) * ztvmoy, zeps )
+!i
+!i          if( zdenum == 0.e0 ) then
+!i               write(numout,*) 'flxblk  zdenum=0 ', ji,jj
+!i               zdenum = zeps
+!i          endif
+!i
+            zdtetar        = zdteta / zdenum
+            ztvmoyr        = ztvmoy * ztvmoy * zdeltaq / zdenum
+            
+            ! For stable atmospheric conditions
+            zobouks        = -70.0 * 10. * ( zdtetar + 3.2e-3 * ztvmoyr )
+            zobouks        = MAX( zzero , zobouks )
+            zpsims         = -7.0 * zobouks
+            zpsihs         =  zpsims
+            zpsils         =  zpsims
+
+            !  For unstable atmospheric conditions
+            zobouku        = -100.0 * 10.0 * ( zdtetar + 2.2e-3 * ztvmoyr )
+            zobouku        = MIN( zzero , zobouku )
+            zxins          = ( 1. - 16. * zobouku )**0.25
+            zlxins         = LOG( ( 1. + zxins * zxins ) / 2. )
+            zpsimu         = 2. * LOG( ( 1 + zxins ) / 2. )  + zlxins - 2. * ATAN( zxins ) + zpis2
+            zpsihu         = 2. * zlxins
+            zpsilu         = zpsihu
+
+            ! computation of intermediate values
+            zstab          = MAX( zzero , SIGN( zone , zdteta ) )
+            zpsim          = zstab * zpsimu + (1.0 - zstab ) * zpsims
+            zpsih          = zstab * zpsihu + (1.0 - zstab ) * zpsihs
+            zpsil          = zpsih
+            
+            zvatmg         = MAX( 0.032 * 1.5e-3 * vatm(ji,jj) * vatm(ji,jj) / grav, zeps )
+!i
+!!          if( zvatmg == 0.e0 ) then
+!!               write(numout,*) 'flxblk  zvatmg=0 ', ji,jj
+!!               zvatmg = zeps
+!!          endif
+!i
+
+            zcmn           = vkarmn / LOG ( 10. / zvatmg )
+            zcmn2          = zcmn * zcmn
+            zchn           = 0.0327 * zcmn
+            zcln           = 0.0346 * zcmn
+            zcmcmn         = 1 / ( 1 - zcmn * zpsim / vkarmn )
+            zchcm          = zcmcmn / ( 1 - zchn * zpsih / ( vkarmn * zcmn ) )
+            zclcm          = zchcm
+
+
+            !  Transfer cofficient zcsho and zcleo over ocean according to Large and Pond (1981,1982)
+            !-------------------------------------------------------------- 
+            zcsho          = zchn * zchcm
+            zcleo          = zcln * zclcm 
+
+
+            !   Computation of sensible and latent fluxes over Ocean 
+            !----------------------------------------------------------------
+
+            !  computation of intermediate values
+            zrhova         = zrhoa(ji,jj) * vatm(ji,jj)
+            zrhovacsho     = zrhova * zcsho
+            zrhovacleo     = zrhova * zcleo
+
+            ! sensible heat flux
+            zqsb_oce(ji,jj) = zrhovacsho * 1004.0  * ( psst(ji,jj) - ztatm(ji,jj) )  
+         
+            !  latent heat flux 
+            zqla_oce(ji,jj) = MAX(0.e0, zrhovacleo * 2.5e+06 * ( zqsato      - zqatm(ji,jj) ) )
+               
+            !  Calculate evaporation over water. (kg/m2/s)
+            !-------------------------------------------------
+            evap(ji,jj)    = zqla_oce(ji,jj) / cevap
+               
+               
+            !  Turbulent heat fluxes over snow/ice.
+            !--------------------------------------------------
+            
+            !  zesi     : vapour pressure at saturation of ice
+            !  zqsati   : humidity close to the ice surface (at saturation)
+            zesi           =  611.0 * EXP ( 21.8745587 * tmask(ji,jj,1)   &   ! tmask needed to avoid overflow in the exponential
+               &                                       * ( tn_ice(ji,jj) - rtt ) / ( tn_ice(ji,jj) - 7.66 ) )
+            zqsati         = ( 0.622 * zesi ) / ( zpatm(ji,jj) - 0.378 * zesi )
+               
+            !  computation of intermediate values
+            zticemb        = ( tn_ice(ji,jj) - 7.66 )
+            zticemb2       = zticemb * zticemb  
+            ztice3         = tn_ice(ji,jj) * tn_ice(ji,jj) * tn_ice(ji,jj)
+            zqsati2        = zqsati * zqsati
+            zesi2          = zesi * zesi
+            zdesidt        = zesi * ( 9.5 * LOG( 10.0 ) * ( rtt - 7.66 )  / zticemb2 )
+               
+            !  Transfer cofficient zcshi and zclei over ice. Assumed to be constant Parkinson 1979 ; Maykut 1982
+            !--------------------------------------------------------------------
+            zcshi          = 1.75e-03
+            zclei          = zcshi
+               
+            !  Computation of sensible and latent fluxes over ice
+            !----------------------------------------------------------------
+               
+            !  computation of intermediate values
+            zrhova          = zrhoa(ji,jj) * vatm(ji,jj)
+            zrhovacshi      = zrhova * zcshi * 2.834e+06
+            zrhovaclei      = zrhova * zclei * 1004.0
+            
+            !  sensible heat flux
+            zqsb_ice(ji,jj) = zrhovaclei * ( tn_ice(ji,jj) - ztatm(ji,jj) )
+            
+            !  latent heat flux 
+            zqla_ice(ji,jj) = zrhovacshi * ( zqsati        - zqatm(ji,jj) )
+            qla_ice (ji,jj) = MAX(0.e0, zqla_ice(ji,jj) )
+              
+            !  Computation of sensitivity of non solar fluxes (dQ/dT)
+            !---------------------------------------------------------------
+               
+            !  computation of long-wave, sensible and latent flux sensitivity
+            zdqlw_ice       = 4.0 * emic * stefan * ztice3
+            zdqsb_ice       = zrhovaclei
+            zdqla_ice       = zrhovacshi * ( zdesidt * ( zqsati2 / zesi2 ) * ( zpatm(ji,jj) / 0.622 ) )         
+            
+            !  total non solar sensitivity
+            dqns_ice(ji,jj) = -( zdqlw_ice + zdqsb_ice + zdqla_ice ) 
+            
+            ! latent flux sensitivity
+            dqla_ice(ji,jj) = zdqla_ice
+            
+         END DO
+      END DO
+
+      ! total non solar heat flux over ice
+      qnsr_ice(:,:) = zqlw_ice(:,:) - zqsb_ice(:,:) - zqla_ice(:,:)
+      ! total non solar heat flux over water 
+      qnsr_oce(:,:) = zqlw_oce(:,:) - zqsb_oce(:,:) - zqla_oce(:,:)
+
+      ! solid precipitations ( kg/m2/day -> kg/m2/s)
+      tprecip(:,:) = tprecip  (:,:) / rday 
+      ! snow  precipitations ( kg/m2/day -> kg/m2/s)
+      sprecip(:,:) = sprecip  (:,:) / rday  
+!i
+      CALL lbc_lnk( qsr_oce (:,:) , 'T', 1. )
+      CALL lbc_lnk( qnsr_oce(:,:) , 'T', 1. )
+      CALL lbc_lnk( qsr_ice (:,:) , 'T', 1. )
+      CALL lbc_lnk( qnsr_ice(:,:) , 'T', 1. )
+      CALL lbc_lnk( qla_ice (:,:) , 'T', 1. )
+      CALL lbc_lnk( dqns_ice(:,:) , 'T', 1. )
+      CALL lbc_lnk( dqla_ice(:,:) , 'T', 1. )
+      CALL lbc_lnk( fr1_i0  (:,:) , 'T', 1. )
+      CALL lbc_lnk( fr2_i0  (:,:) , 'T', 1. )
+      CALL lbc_lnk( tprecip (:,:) , 'T', 1. )
+      CALL lbc_lnk( sprecip (:,:) , 'T', 1. )
+      CALL lbc_lnk( evap    (:,:) , 'T', 1. )
+!i
+!i
+      qsr_oce (:,:) = qsr_oce (:,:)*tmask(:,:,1)
+      qnsr_oce(:,:) = qnsr_oce(:,:)*tmask(:,:,1)
+      qsr_ice (:,:) = qsr_ice (:,:)*tmask(:,:,1)
+      qnsr_ice(:,:) = qnsr_ice(:,:)*tmask(:,:,1)
+      qla_ice (:,:) = qla_ice (:,:)*tmask(:,:,1)
+      dqns_ice(:,:) = dqns_ice(:,:)*tmask(:,:,1)
+      dqla_ice(:,:) = dqla_ice(:,:)*tmask(:,:,1)
+      fr1_i0  (:,:) = fr1_i0  (:,:)*tmask(:,:,1)
+      fr2_i0  (:,:) = fr2_i0  (:,:)*tmask(:,:,1)
+      tprecip (:,:) = tprecip (:,:)*tmask(:,:,1)
+      sprecip (:,:) = sprecip (:,:)*tmask(:,:,1)
+      evap    (:,:) = evap    (:,:)*tmask(:,:,1)
+!i
+
+   END SUBROUTINE flx_blk
+
+
+   SUBROUTINE flx_blk_declin( ky, kday, pdecl )
+      !!---------------------------------------------------------------------------
+      !!               ***  ROUTINE flx_blk_declin  ***
+      !!          
+      !! ** Purpose :   Computation of the solar declination for the day
+      !!	        kday ( in decimal degrees ).
+      !!       
+      !! ** Method  :
+      !!
+      !! History :
+      !!         original    : 01-04 (LIM)
+      !!         addition    : 02-08 (C. Ethe, G. Madec)
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ky  ,        &  ! = -1, 0, 1 for odd, normal and leap years resp.
+         kday            ! day of the year ( kday = 1 on january 1)
+      REAL(wp), INTENT(out) ::  &
+         pdecl            ! solar declination
+
+      !! * Local variables
+      REAL(wp) ::                & 
+         zday                ,   &  ! corresponding day of type year (cf. ky)
+         zp1, zp2, zp3, zp4         ! temporary scalars
+      !!---------------------------------------------------------------------
+      
+      zday = FLOAT( kday ) 
+      
+      IF( ky == 1 )  THEN 
+         zday = zday - 0.5
+      ELSEIF( ky == 3 )  THEN
+         zday = zday - 1.
+      ELSE 
+         zday = REAL( kday )
+      ENDIF
+      
+      zp1 = rpi * ( 2.0 * zday - 367.0 ) / yearday
+      zp2 = 2. * zp1
+      zp3 = 3. * zp1
+      zp4 = 4. * zp1
+      
+      pdecl  = a0                                                                      &
+         &   + a1 * COS( zp1 ) + a2 * COS( zp2 ) + a3 * COS( zp3 ) + a4 * COS( zp4 )   &
+         &   + b1 * SIN( zp1 ) + b2 * SIN( zp2 ) + b3 * SIN( zp3 ) + b4 * SIN( zp4 )
+      
+   END SUBROUTINE flx_blk_declin
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :           Empty module                     NO bulk
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE flx_blk            ! Empty routine
+   END SUBROUTINE flx_blk
+#endif
+
+   !!======================================================================
+END MODULE flxblk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxfwb.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxfwb.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxfwb.F90	(revision 4536)
@@ -0,0 +1,326 @@
+MODULE flxfwb
+   !!======================================================================
+   !!                       ***  MODULE  flxfwb  ***
+   !! Ocean fluxes   : domain averaged freshwater budget
+   !!======================================================================
+#if ! defined key_dynspg_rl
+   !!----------------------------------------------------------------------
+   !!   NOT 'key_dynspg_rl'                        Free surface formulation
+   !!----------------------------------------------------------------------
+   !!   flx_fwb      : freshwater budget for global ocean configurations
+   !!                  in free surface and forced mode
+   !!   flx_fwb_init : freshwater budget for global ocean configurations
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE cpl_oce         ! coupled atmosphere/ocean
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE flxrnf          ! ocean runoffs
+   USE ocesbc          ! ocean surface boudaries conditions
+   USE blk_oce
+   USE flxblk          ! bulk formulea
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC flx_fwb      ! routine called by step
+   PUBLIC flx_fwb_init ! routine called by opa
+
+   !! * Share module variables
+   LOGICAL, PUBLIC ::    & !!: * namelist *
+      ln_fwb = .TRUE.       !: Flag to activate the fwb computation
+   REAL(wp), PUBLIC ::   &  !:
+      a_fwb_b  ,         &  !: annual domain averaged freshwater budget
+      a_fwb                 !: for 2 year before (_b) and before year.
+
+   !! * Module variables
+   REAL(wp) ::   &
+      a_emp   ,  & ! domain averaged evaporation minus precipitation
+      a_precip,  & ! domain averaged precipitation
+      a_rnf   ,  & ! domain averaged runoff
+      a_sshb  ,  & ! domain averaged sea surface heigh at nit000
+      a_sshend,  & ! domain averaged sea surface heigh at nitend
+      a_sal000,  & ! domain averaged ocean salinity at nit000 (before time step)
+      a_salend,  & ! domain averaged ocean salinity at nitend (now time step)
+      a_aminus,  & ! 
+      a_aplus
+      REAL(wp), DIMENSION(jpi,jpj) ::  &
+         e1e2_i    ! area of the interior domain (e1t*e2t*tmask_i)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE flx_fwb( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_fwb  ***
+      !!
+      !! ** Purpose :
+      !!
+      !! ** Method  :
+      !!	
+      !! History :
+      !!   8.2  !  01-02  (E. Durand)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      CHARACTER (len=32) ::   &
+         clname = 'EMPav.dat'
+      INTEGER  ::   ji, jj, jk        ! dummy loop indices
+      INTEGER  ::   inum              ! temporary logical unit
+      INTEGER  ::   ikty              ! 
+      REAL(wp) ::   &
+         zarea, zvol, zwei,       &  ! temporary scalars
+         zsm0, zempnew                !    "         "
+      !!----------------------------------------------------------------------
+
+      ! Mean global salinity
+      zsm0 = 34.72654
+
+      ! To compute emp mean value mean emp
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'flx_fwb : FreshWater Budget correction'
+            WRITE(numout,*) '~~~~~~~'
+         ENDIF
+
+         a_emp    = 0.e0
+         a_precip = 0.e0
+         a_rnf    = 0.e0
+         a_sshb   = 0.e0   ! averaged sea surface heigh at nit000 
+         a_sal000 = 0.e0   ! averaged ocean salinity at nit000
+         a_aminus = 0.e0
+         a_aplus  = 0.e0
+         
+         e1e2_i(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+         a_sshb = SUM( e1e2_i(:,:) * sshn(:,:) )
+         IF( lk_mpp )   CALL  mpp_sum( a_sshb   )   ! sum over all the global domain
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwei  = e1e2_i(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  a_sal000 = a_sal000 + ( sb(ji,jj,jk) - zsm0 ) * zwei
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL  mpp_sum( a_sal000 )   ! sum over the global domain
+
+      ENDIF
+      
+      ! cumulate surface freshwater budget at each time-step
+      ! --------------------------------------====----------
+      a_emp    = SUM( e1e2_i(:,:) * emp   (:,:) )
+      IF( lk_mpp )   CALL  mpp_sum( a_emp    )   ! sum over the global domain
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
+      a_precip = SUM( e1e2_i(:,:) * watm  (:,:) )
+      IF( lk_mpp )   CALL  mpp_sum( a_precip )   ! sum over the global domain
+#endif
+      a_rnf    = SUM( e1e2_i(:,:) * runoff(:,:) )
+      IF( lk_mpp )   CALL  mpp_sum( a_rnf    )   ! sum over the global domain
+
+      IF( aminus /= 0.e0 ) a_aminus = a_aminus + ( MIN( aplus, aminus ) / aminus )
+      IF( aplus  /= 0.e0 ) a_aplus  = a_aplus  + ( MIN( aplus, aminus ) / aplus  )
+
+
+      ! Update empold if new year start
+      ikty = 365 * 86400 / rdttra(1)    !!bug  use of 365 days leap year or 360d year !!!!!!!
+      IF( MOD( kt, ikty ) == 0 ) THEN
+         zarea    = SUM( e1e2_i(:,:)            )
+         IF( lk_mpp )   CALL  mpp_sum( zarea    )   ! sum over the global domain
+         a_fwb_b = a_fwb
+         a_fwb   = SUM( e1e2_i(:,:) * sshn(:,:) )
+         IF( lk_mpp )   CALL  mpp_sum( a_fwb    )   ! sum over the global domain
+
+         a_fwb   = a_fwb * 1.e+3 / ( zarea * 86400. * 365. )    ! convert in Kg/m3/s = mm/s
+         !                                                      !!bug 365d year 
+         empold =  a_fwb                 ! current year freshwater budget correction
+         !                               ! estimate from the previous year budget
+      ENDIF
+
+
+      IF( kt == nitend ) THEN
+         zvol  = 0.e0
+         zempnew = 0.e0
+         ! Mean sea level at nitend
+         a_sshend = SUM( e1e2_i(:,:) * sshn(:,:) )
+         zarea    = SUM( e1e2_i(:,:)             )
+         
+         a_salend = 0.e0
+         DO jk = 1, jpkm1   
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwei  = e1e2_i(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  a_salend = a_salend + ( sn(ji,jj,jk) - zsm0 ) * zwei
+                  zvol  = zvol  + zwei
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp ) THEN
+            CALL  mpp_sum( zarea    )   ! sums over all the global domain
+            CALL  mpp_sum( zvol     )        
+            CALL  mpp_sum( a_sshend )        
+            CALL  mpp_sum( a_salend )        
+         ENDIF
+
+         a_aminus = a_aminus / ( nitend - nit000 + 1 )
+         a_aplus  = a_aplus  / ( nitend - nit000 + 1 )
+
+         ! Conversion in m3
+         a_emp    = a_emp    * rdttra(1) * 1.e-3 
+         a_precip = a_precip * rdttra(1) * 1.e-3 / rday
+         a_rnf    = a_rnf    * rdttra(1) * 1.e-3
+         
+      ENDIF
+
+
+      ! Ecriture des diagnostiques 
+      ! --------------------------
+
+      IF( kt == nitend ) THEN
+
+         CALL ctlopn( inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &           1, numout, .FALSE., 0 )
+         WRITE(inum, "(24X,I8,2ES24.16)" ) nyear, a_fwb_b, a_fwb
+         WRITE(inum,*)
+         WRITE(inum,*)    'Net freshwater budget '
+         WRITE(inum,9010) '  emp    = ', a_emp   , ' m3 =', a_emp   /((nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,9010) '  precip = ', a_precip, ' m3 =', a_precip/((nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,9010) '  a_rnf  = ', a_rnf   , ' m3 =', a_rnf   /((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_sshend         ,' m3 '
+         WRITE(inum,9010) '  diff      = ',(a_sshend-a_sshb),' m3 =', (a_sshend-a_sshb)/((nitend-nit000+1)*rdt) * 1.e-6,' Sv'
+         WRITE(inum,9020) '  mean sea level elevation    =', a_sshend/zarea,' m'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Anomaly of salinity content : '
+         WRITE(inum,9010) '  at nit000 = ', a_sal000           ,' psu.m3 '
+         WRITE(inum,9010) '  at nitend = ', a_salend           ,' psu.m3 '
+         WRITE(inum,9010) '  diff      = ', a_salend - a_sal000,' psu.m3'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Mean salinity : '
+         WRITE(inum,9020) '  at nit000 = ',  a_sal000/zvol+zsm0     ,' psu '
+         WRITE(inum,9020) '  at nitend = ',  a_salend/zvol+zsm0     ,' psu '
+         WRITE(inum,9020) '  diff      = ', (a_salend-a_sal000)/zvol,' psu'
+         WRITE(inum,9020) '  S-SLevitus= ',  a_salend          /zvol,' psu'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Coeff : '
+         WRITE(inum,9030) '  Alpha+   =  ', a_aplus
+         WRITE(inum,9030) '  Alpha-   =  ', a_aminus
+         WRITE(inum,*)
+      ENDIF
+
+ 9006 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,F8.2,A)
+
+   END SUBROUTINE flx_fwb
+
+
+   SUBROUTINE flx_fwb_init
+      !!---------------------------------------------------------------------
+      !!                ***  ROUTINE flx_fwb_init  ***
+      !!
+      !! ** Purpose :
+      !!
+      !! ** Method  :
+      !!  
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  Original code
+      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      CHARACTER (len=32) ::   &
+         clname = 'EMPave_old.dat'
+      INTEGER ::   inum, iyear
+
+      NAMELIST/namfwb/ ln_fwb 
+      !!----------------------------------------------------------------------
+         
+      ! Read Namelist namfwb : freshWater Budget correction
+      ! --------------------
+      REWIND( numnam )
+      READ  ( numnam, namfwb )            
+      
+      ! Parameter control and print
+      ! ---------------------------
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'flx_fwb_init : FreshWater Budget correction'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '               Namelist namfwb : set fwb parameters'
+         WRITE(numout,*) '                  use or not fwb correction      ln_fwb   = ', ln_fwb
+      ENDIF
+      ! Option consistency
+#if defined key_dynspg_rl
+      IF(lwp) WRITE '               Rigid-lid option, fwb correction is useless, but valid'
+#endif
+      IF( lk_cpl ) THEN
+         IF(lwp) WRITE(numout,*) '               Coupled option, fwb correction is a flux correction ! '
+         IF(lwp) WRITE(numout,*) '               ln_fwb = .FALSE. is recommanded'
+      ENDIF
+
+      IF( nbit_cmp == 1 .AND. ln_fwb ) THEN
+         CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require ln_fwb = .false.' )
+      END IF
+
+      !                                        ! ==============================
+      IF( ln_fwb ) THEN                        !  Freshwater budget correction 
+         !                                     ! ==============================
+         ! Read the corrective factor on precipitations (empold)
+         CALL ctlopn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+            &           1, numout, .FALSE., 1 )
+         READ ( inum, "(24X,I8,2ES24.16)" ) iyear, a_fwb_b, a_fwb
+         CLOSE( inum )
+         empold = a_fwb                  ! current year freshwater budget correction
+         !                               ! estimate from the previous year budget
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*)'flx_fwb_init : year = ',iyear  , ' freshwater budget correction = ', empold
+         IF(lwp)WRITE(numout,*)'               year = ',iyear-1, ' freshwater budget read       = ', a_fwb
+         IF(lwp)WRITE(numout,*)'               year = ',iyear-2, ' freshwater budget read       = ', a_fwb_b
+         !                                    ! ==============================
+      ELSE                                    !      NO  budget correction 
+         !                                    ! ==============================
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'               NO freshwater budget correction'
+         empold = 0.e0
+      ENDIF
+
+   END SUBROUTINE flx_fwb_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case :                       
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC ::   ln_fwb = .FALSE.   !: no fwb forced
+CONTAINS
+   SUBROUTINE flx_fwb( kt )                ! dummy routine
+      WRITE(*,*) 'flx_fwb: You should not have seen this print! error?', kt
+   END SUBROUTINE flx_fwb
+   SUBROUTINE flx_fwb_init
+   END SUBROUTINE flx_fwb_init
+#endif
+   !!======================================================================
+END MODULE flxfwb
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxmod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxmod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxmod.F90	(revision 4536)
@@ -0,0 +1,192 @@
+MODULE flxmod
+   !!======================================================================
+   !!                       ***  MODULE  flxmod  ***
+   !! Ocean forcing:  thermohaline forcing of the ocean
+   !!=====================================================================
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE daymod          ! calendar
+   USE ocfzpt          ! ocean freezing point
+
+#if defined key_oasis3 || defined key_oasis4
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling (to ECHAM5)
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (to ECHAM5)
+#endif
+   USE flx_oce, only : dqns_ice , & ! : derivative of non solar heat flux on sea ice
+                       qsr_oce  , & ! : solar flux over ocean
+                       qnsr_oce , & ! : total non solar heat flux (longwave downward radiation) over ocean
+                       qsr_ice  , & ! : solar flux over ice
+                       qnsr_ice , & ! : total non solar heat flux (Longwave downward radiation) over ice
+                       tn_ice   , & ! : ice surface temperature
+                       alb_ice  , & ! : albedo of ice
+                       sprecip  , & ! : solid (snow) precipitation over water (!) what about ice?
+                       tprecip  , & ! : total precipitation ( or liquid precip minus evaporation in coupled mode)
+                       calving  , & ! : calving
+                       rrunoff  , & ! : monthly runoff (kg/m2/s)
+                       fr1_i0   , & ! : 1st part of the fraction of sol.rad. which penetrate inside the ice cover
+                       fr2_i0       ! : 2nd part of the fraction of sol.rad. which penetrate inside the ice cover
+
+   USE ice, only    : hicif ,     & ! : ice thickness
+                      frld  ,     & ! : leads fraction = 1-a/totalarea
+                      hsnif  ,    & ! : snow thickness
+                      u_ice , v_ice ! : ice velocity
+
+   USE ice_oce, only : sst_io      ! : sea surface temperature
+
+#if defined key_cpl_ocevel
+   USE geo2ocean, only : repere, repcmo
+#endif
+#endif
+   IMPLICIT NONE
+   PRIVATE
+
+#if defined key_flx_core
+   LOGICAL, PUBLIC ::   lk_core = .TRUE.   !: CORE surface fluxes flag
+#else
+   LOGICAL, PUBLIC ::   lk_core = .FALSE.  !: CORE surface fluxes flag
+#endif
+
+#if defined key_oasis3 || defined key_oasis4
+   REAL(wp), DIMENSION(jpi,jpj) :: catm
+#endif
+   !! * Routine accessibility
+   PUBLIC flx       ! routine called by step.F90
+   PUBLIC flx_init  ! routine called by opa.F90
+
+   !! * local declarations
+   REAL(wp), PUBLIC ::            & !!! surface fluxes namelist (namflx)
+      q0    = 0.e0,               &  ! net heat flux
+      qsr0  = 0.e0,               &  ! solar heat flux
+      emp0  = 0.e0,               &  ! net freshwater flux
+      dqdt0 = -40.,               &  ! coefficient for SST damping (W/m2/K)
+      deds0 = 27.7                   ! coefficient for SSS damping (mm/day)
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+#if defined key_flx_bulk_monthly
+   !!----------------------------------------------------------------------
+   !!   'key_flx_bulk_monthly'   and                           MONTHLY bulk
+   !!   Default option                                         Net CDF file
+   !!----------------------------------------------------------------------
+#  include "flx_bulk_monthly.h90"
+
+#elif defined key_flx_bulk_daily
+   !!----------------------------------------------------------------------
+   !!   'key_flx_bulk_daily'                                     DAILY bulk
+   !!                                                          Net CDF file
+   !!----------------------------------------------------------------------
+#  include "flx_bulk_daily.h90"
+
+#elif defined key_flx_core
+   !!----------------------------------------------------------------------
+   !!   'key_flx_core'   and                     NCAR data (Large & Yeager)
+   !!                                                          Net CDF file
+   !!----------------------------------------------------------------------
+#  include "flx_core.h90"
+
+#elif defined key_flx_forced_daily
+   !!----------------------------------------------------------------------
+   !!   'key_flx_forced_daily'                                 DAILY fluxes
+   !!                                                          Net CDF file
+   !!----------------------------------------------------------------------
+#  include "flx_forced_daily.h90"
+
+#elif defined key_oasis3  ||  defined key_oasis4
+   !!----------------------------------------------------------------------
+   !!   'key_oasis3'  or 'key_oasis4' and           Coupled Ocan/Atmosphere
+   !!   'key_ice_lim'                               with  LIM sea-ice model
+   !!----------------------------------------------------------------------
+#  include "flx_oasis_ice.h90"
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                   Analytical forcing
+   !!----------------------------------------------------------------------
+   !!   flx          : define the thermohaline fluxes for the ocean
+   !!----------------------------------------------------------------------
+   !! * Module used
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx ( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE flx  ***
+      !!              
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater)
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method  :   Constant surface fluxes (read in namelist (namflx))
+      !!
+      !! ** Action  : - q, qt, qsr, emp, emps, qrp, erp
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 )  THEN
+         IF(lwp) WRITE(numout,*)' '
+         IF(lwp) WRITE(numout,*)'flx     : Analytical/Constant surface fluxes'
+         IF(lwp) WRITE(numout,*)'~~~~~~~ '
+         IF(lwp) WRITE(numout,*)'          See the routine oce_sbc'     
+         IF(lwp) WRITE(numout,*)' '
+      ENDIF
+
+   END SUBROUTINE flx
+
+#endif
+
+
+   SUBROUTINE flx_init
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE flx  ***
+      !!              
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater)
+      !!      to the ocean at each time step.
+      !!
+      !! ** Method  :   Constant surface fluxes (read in namelist (namflx))
+      !!
+      !! ** Action  : - q, qt, qsr, emp, emps, qrp, erp
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      NAMELIST/namflx/ q0, qsr0, emp0, dqdt0, deds0
+      !!---------------------------------------------------------------------
+
+      ! Read Namelist namflx : surface thermohaline fluxes
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namflx )
+
+      IF(lwp) THEN
+         WRITE(numout,*)' '
+         WRITE(numout,*)'flx_init : thermohaline forcing '
+         WRITE(numout,*)'~~~~~~~~ '
+         WRITE(numout,*)'           net heat flux                  q0   = ', q0  , ' W/m2'
+         WRITE(numout,*)'           solar heat flux                qsr0 = ', qsr0, ' W/m2'
+         WRITE(numout,*)'           net heat flux                  emp0 = ', emp0, ' W/m2'
+         WRITE(numout,*)'           coefficient for SST damping   dqdt0 = ', dqdt0,' W/m2/K'
+         WRITE(numout,*)'           coefficient for SSS damping   deds0 = ', deds0,' mm/day'
+      ENDIF
+
+   END SUBROUTINE flx_init
+
+END MODULE flxmod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf.F90	(revision 4536)
@@ -0,0 +1,322 @@
+MODULE flxrnf
+   !!======================================================================
+   !!                       ***  MODULE  flxrnf  ***
+   !! Ocean forcing:  runoff
+   !!=====================================================================
+#if defined key_orca_r05
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r05'                               ORCA R05 configuration
+   !!----------------------------------------------------------------------
+#  include "flxrnf_ORCA_R05.h90"
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                     Standard runoffs
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   flx_rnf      : monthly runoff read in a NetCDF file
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE iom             ! I/O module
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC flx_rnf          ! routine call in step module
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      runoff,           &  !: monthly runoff (kg/m2/s)
+      upsadv,           &  !: mixed adv scheme in straits vicinity (hori.)
+      upsrnfh              !: mixed adv scheme in runoffs vicinity (hori.)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      upsrnfz              !: mixed adv scheme in runoffs vicinity (vert.)
+   INTEGER, PUBLIC ::   &  !:
+      nrunoff =  0         !: runoff option (namelist)
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &  !:
+      rnfdta               !: monthly runoff data array (kg/m2/s)
+   INTEGER  ::          &  !:
+      numrnf,           &  !: logical unit for runoff data
+      nrnf1, nrnf2         !: first and second record used
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx_rnf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_rnf  ***
+      !!       
+      !! ** Purpose :   Introduce a climatological run off forcing
+      !!
+      !! ** Method :
+      !!      Initialze each mouth of river with a monthly climatology 
+      !!      provided from different data.
+      !!     C a u t i o n : upward water flux, runoff is negative
+      !!                     set at the last loop of the routine
+      !!
+      !! ** Action :
+      !!
+      !! References : 
+      !!       J. D. Milliman and R. H. Meade, 1983 : world-wide delivery
+      !!          of river sediment to the oceans, journal of geology vol 91
+      !!          pp 1-21.
+      !!       G. L. Russell and J. R. Miller, 1990 : global river runoff
+      !!          calculated from a global atmospheric general circulation
+      !!          model, journal of hydrology, 117(1990), pp 241-254.
+      !!       F. Van Der Leeden, Troise F. L., Todd D. K. : the water
+      !!          encyclopedia, second edition, lewis publishers.
+      !!       J. W. Weatherly, J. E. Walsh : The effects of precipitation
+      !!          and river runoff in a coupled ice-ocean model of Arctic
+      !!          Climate dynamics 1996 12:785,798
+      !!       Jacobs et al. 1992. J. Glaciol. 38 (130) 375-387.
+      !!
+      !! History :
+      !!        !  94-10  (G.Madec, M. Pontaud, M. Imbard)  Original code
+      !!        !  97-03  (G.Madec)  time dependent version
+      !!        !  98-06  (J.M. Molines)  exact computation of zxy 
+      !!                         for months that are not 30 days
+      !!        !  98-07  (M. Imbard)  ORCA and mpp option
+      !!        !  99-08  (J.P. Boulanger H.L.Ayina)  New rivers and 
+      !!                         values given in m3/s 
+      !!        !  00-04  (G. Madec, K. Roberts) add antarctica ice discharge.
+      !!        !  00-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt       ! ocean time step
+
+      !! * Local declarations
+# if ! defined key_coupled
+      INTEGER  ::   ji, jj                 ! dummy loop indices
+      INTEGER ::   &
+         i15 , imois , iman,            &  ! temporary integers
+         idbd, idmeom                      !    "          "
+      REAL(wp) ::   zxy
+# endif
+      INTEGER  ::   ii0, ii1, ij0, ij1     !    "          "
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+
+         SELECT CASE ( nrunoff )
+
+         CASE ( 0 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : No runoff in this simulation (nrunoff=0)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+            
+         CASE ( 1 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : monthly runoff (nrunoff=1)'
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+         CASE ( 2 )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flx_rnf : monthly runoff with upsteam advection'
+            IF(lwp) WRITE(numout,*) '~~~~~~~   in the vicinity of river mouths (nrunoff=2)'
+
+         CASE DEFAULT
+            WRITE(ctmp1,*) ' Error nrunoff = ', nrunoff, ' /= 0, 1 or 2'
+            CALL ctl_stop( ctmp1 )
+
+         END SELECT
+
+         ! Set runoffs and upstream coeff to zero
+         upsadv (:,:) = 0.e0
+
+      ENDIF
+
+
+      ! 1. Initialization
+      ! -----------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2 ) THEN
+# if ! defined key_coupled
+
+         ! year, month, day
+         iman  = INT( raamo )
+!!! better but change the results      i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+         i15   = nday / 16
+         imois = nmonth + i15 - 1
+         IF( imois == 0 ) imois = iman
+         ! Number of days in the month
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+# endif
+         
+         ! Open file
+
+         IF( kt == nit000 ) THEN
+
+            nrnf1 = 0   ! initialization
+            IF (lwp) WRITE(numout,*) 'flx_rnf : Monthly runoff'
+            CALL iom_open ( 'runoff_1m_nomask.nc', numrnf )
+            
+         ENDIF
+         
+# if ! defined key_coupled
+
+         ! 2. Read monthly file of runoff
+         ! ------------------------------
+
+         IF( kt == nit000 .OR. imois /= nrnf1 ) THEN
+
+            ! Calendar computation for interpolation
+            !     nrnf1 number of the first array record used in the simulation
+            !     nrnf2 number of the last  array record
+
+            nrnf1 = imois
+            nrnf2 = nrnf1 + 1
+            nrnf1 = MOD( nrnf1, iman )
+            IF( nrnf1 == 0 ) nrnf1 = iman
+            nrnf2 = MOD( nrnf2, iman )
+            IF( nrnf2 == 0 ) nrnf2 = iman
+            
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) ' runoff monthly field'
+               WRITE(numout,*) ' --------------------'
+               WRITE(numout,*) ' NetCDF format'
+               WRITE(numout,*)
+               WRITE(numout,*) 'first array record used nrnf1 ', nrnf1
+               WRITE(numout,*) 'last  array record used nrnf2 ', nrnf2
+               WRITE(numout,*)
+            ENDIF
+            
+            ! Read monthly runoff data in kg/m2/s
+
+            CALL iom_get ( numrnf, jpdom_data, 'sorunoff', rnfdta(:,:,1), nrnf1 )
+            CALL iom_get ( numrnf, jpdom_data, 'sorunoff', rnfdta(:,:,2), nrnf2 )
+
+         ENDIF
+
+         ! Linear interpolation and conversion in upward water flux
+         ! C a u t i o n : runoff is negative and in kg/m2/s 
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         runoff(:,:) = -( ( 1.e0 - zxy ) * rnfdta(:,:,1) + zxy * rnfdta(:,:,2) )
+
+         ! Runoff reduction only associated to the ORCA2_LIM configuration
+         ! when reading the NetCDF file runoff_1m_nomask.nc
+         IF( cp_cfg == 'orca' .AND. jp_cfg == 2 )   THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( gphit(ji,jj) > 40 .AND. gphit(ji,jj) < 65 )   runoff(ji,jj) = 0.85 * runoff(ji,jj)
+               END DO
+            END DO
+         ENDIF
+         
+# endif
+
+      ENDIF
+
+
+      ! 3. Mixed advection scheme 
+      ! -------------------------
+
+      IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+         ! Upstream and centered scheme in the vicinity of river mouths
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+
+         CALL iom_get ( numrnf, jpdom_data, 'socoefr', upsrnfh )
+         
+         upsrnfz(:)   = 0.e0
+         upsrnfz(1)   = 1.0
+         upsrnfz(2)   = 1.0
+         upsrnfz(3)   = 0.5
+         upsrnfz(4)   = 0.25
+         upsrnfz(5)   = 0.125
+         
+         IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN
+            ! ORCA_R2 configuration : upstream scheme in the Sound Strait
+            ij0 = 116   ;   ij1 = 116
+            ii0 = 144   ;   ii1 = 144   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+            ii0 = 145   ;   ii1 = 147   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+            ii0 = 148   ;   ii1 = 148   ;   upsrnfh( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+         ENDIF
+
+      ENDIF
+
+      ! Upstream and centered scheme in the vicinity of some straits
+
+      IF( kt == nit000 ) THEN 
+
+         IF( cp_cfg == "orca" ) THEN
+
+            SELECT CASE ( jp_cfg )
+            !                                        ! =======================
+            CASE ( 4 )                               !  ORCA_R4 configuration 
+               !                                     ! =======================
+
+               !                                          ! Gibraltar Strait
+               ii0 =  70   ;   ii1 =  71
+               ij0 =  52   ;   ij1 =  53   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+         
+               !                                     ! =======================
+            CASE ( 2 )                               !  ORCA_R2 configuration 
+               !                                     ! =======================
+
+               !                                          ! Gibraltar Strait
+               ij0 = 102   ;   ij1 = 102
+               ii0 = 138   ;   ii1 = 138   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.20
+               ii0 = 139   ;   ii1 = 139   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+               ii0 = 140   ;   ii1 = 140   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+               ij0 = 101   ;   ij1 = 102
+               ii0 = 141   ;   ii1 = 141   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+
+               !                                          ! Bab el Mandeb Strait
+               ij0 =  87   ;   ij1 =  88
+               ii0 = 164   ;   ii1 = 164   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.10
+               ij0 =  88   ;   ij1 =  88
+               ii0 = 163   ;   ii1 = 163   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+               ii0 = 162   ;   ii1 = 162   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+               ii0 = 160   ;   ii1 = 161   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+               ij0 =  89   ;   ij1 =  89
+               ii0 = 158   ;   ii1 = 160   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+               ij0 =  90   ;   ij1 =  90
+               ii0 = 160   ;   ii1 = 160   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.25
+
+               !                                          ! Sound Strait
+               ij0 = 116   ;   ij1 = 116
+               ii0 = 145   ;   ii1 = 147   ;   upsadv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.50
+         
+            END SELECT 
+
+         ENDIF
+
+      ENDIF
+     
+      ! 4. Closing all files
+      ! --------------------
+
+      IF( kt == nitend .AND. nrunoff >= 1 )   CALL iom_close( numrnf )
+
+   END SUBROUTINE flx_rnf
+
+#endif
+   !!======================================================================
+END MODULE flxrnf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R05.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R05.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R05.h90	(revision 4536)
@@ -0,0 +1,1537 @@
+   !!----------------------------------------------------------------------
+   !!                  *** flxrnf_ORCA_R05.h90  ***
+   !!----------------------------------------------------------------------
+   !!   flx_rnf      : update ocean runoffs for ORCA_R05 configuration
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC flx_rnf         ! routine call by step.F90
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      runoff,            &  !: monthly runoff (kg/m2/s)
+      upsadv,            &  !: mixed adv scheme in straits vicinity (hori.)
+      upsrnfh               !: mixed adv scheme in runoffs vicinity (hori.)
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &  !:
+      upsrnfz               !: mixed adv scheme in runoffs vicinity (vert.)
+   INTEGER , PUBLIC ::   &  !:
+      nrunoff =  0          !: runoff option (namelist)
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &  !:
+      rnfdta                !: monthly runoff data array (kg/m2/s)
+   INTEGER    ::         &  !:
+      nrnf1, nrnf2          !: first and second record used
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE flx_rnf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE flx_rnf  ***
+      !!       
+      !! ** Purpose :   Introduce a climatological run off forcing
+      !!
+      !! ** Method  :   ORCA R05 configuration
+      !!      Initialze each mouth of river with a monthly climatology 
+      !!      provided from different data.
+      !!     C a u t i o n : upward water flux, runoff is negative
+      !!                     set at the last loop of the routine
+      !!
+      !! ** Action :
+      !!
+      !! References : 
+      !!       J. D. Milliman and R. H. Meade, 1983 : world-wide delivery
+      !!          of river sediment to the oceans, journal of geology vol 91
+      !!          pp 1-21.
+      !!       G. L. Russell and J. R. Miller, 1990 : global river runoff
+      !!          calculated from a global atmospheric general circulation
+      !!          model, journal of hydrology, 117(1990), pp 241-254.
+      !!       F. Van Der Leeden, Troise F. L., Todd D. K. : the water
+      !!          encyclopedia, second edition, lewis publishers.
+      !!       J. W. Weatherly, J. E. Walsh : The effects of precipitation
+      !!          and river runoff in a coupled ice-ocean model of Arctic
+      !!          Climate dynamics 1996 12:785,798
+      !!       Jacobs et al. 1992. J. Glaciol. 38 (130) 375-387.
+      !!
+      !! History :
+      !!        !  94-10  (G.Madec, M. Pontaud, M. Imbard)  Original code
+      !!        !  97-03  (G.Madec)  time dependent version
+      !!        !  98-06  (J.M. Molines)  exact computation of zxy 
+      !!                         for months that are not 30 days
+      !!        !  98-07  (M. Imbard)  ORCA and mpp option
+      !!        !  99-08  (J.P. Boulanger H.L.Ayina)  New rivers and 
+      !!                         values given in m3/s 
+      !!        !  00-04  (G. Madec, K. Roberts) add antarctica ice discharge.
+      !!        !  00-11  (R. Hordoir, E. Durand)  NetCDF FORMAT
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt ! ocean time step
+
+#if defined key_coupled
+      runoff(:,:) = 0.0e0
+#else
+      !!----------------------------------------------------------------------
+      !!  ORCA_R05
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER, PARAMETER ::   &
+         jpmois=12,   &  ! number of month in the year !
+         jpriv=200,   &  ! maximum number of rivers
+         jpcoef=20       ! maximum number of gridpoints for mouth rivers
+
+      INTEGER  ::   ji, jj, jl, jm, jn, jr, jc
+      INTEGER  ::   i15, imois, iman
+      INTEGER  ::   inbp, idbd, idmeom
+      INTEGER  ::   iirnf(jpcoef,jpriv),ijrnf(jpcoef,jpriv)
+      INTEGER  ::   inb(jpriv)
+
+      REAL(wp) ::   zconv, zxy
+      REAL(wp) ::   zrup1,zrup2,zrup3
+      REAL(wp) ::   zrnfm(jpmois, jpriv)
+      REAL(wp) ::   zcoefr(jpi, jpj, 5)
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+      ! ====
+      ! DATA
+      ! ====
+
+      ! I NORTH AMERICA
+      ! ---------------
+
+      ! 1-Saint Lawrence (Canada) 49N30 67W00               R2
+      ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+      ! --> 13975.249m3/s
+      DATA inb(1)/3/
+      DATA (iirnf(jc,1),jc=1,jpcoef)/ 444, 444, 444, 17*0 /
+      DATA (ijrnf(jc,1),jc=1,jpcoef)/ 367, 368, 369, 17*0 /
+      DATA (zrnfm(jm,1),jm=1,jpmois)/   &
+          11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+          14211.,  13119.,  13367.,  13644.,  13463.,  12594./
+      ! 2-Hudson River (USA) 41N00 77W00                    R1
+      ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+      ! --> 407.416687m3/s
+      DATA inb(2)/1/
+      DATA (iirnf(jc,2),jc=1,jpcoef)/ 426, 19*0 /
+      DATA (ijrnf(jc,2),jc=1,jpcoef)/ 336, 19*0 /
+      DATA (zrnfm(jm,2),jm=1,jpmois)/   &
+          364.,    404.,    648.,    873.,    593.,    301.,   &
+          205.,    171.,    205.,    290.,    379.,    456./
+      ! 3-Missisipi and Atchafalaya (USA) 29N 90W           R1 
+      ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+      ! --> 17599.334m3/s
+      DATA inb(3)/2/
+      DATA (iirnf(jc,3),jc=1,jpcoef)/ 397, 398, 18*0 /
+      DATA (ijrnf(jc,3),jc=1,jpcoef)/ 312, 313, 18*0 /
+      DATA (zrnfm(jm,3),jm=1,jpmois)/   &
+          19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+          14181.,  10676.,   9578.,  10167.,  11699.,  17472./
+      ! 4-Brazos (USA) 29N58 95W53                          R1
+      ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+      ! --> 199.666656m3/s
+      DATA inb(4)/1/
+      DATA (iirnf(jc,4),jc=1,jpcoef)/ 386, 19*0 /
+      DATA (ijrnf(jc,4),jc=1,jpcoef)/ 311, 19*0 /
+      DATA (zrnfm(jm,4),jm=1,jpmois)/   &
+          165.,    224.,    200.,    266.,    457.,    327.,   &
+          143.,     69.,    102.,    132.,    160.,    151./
+      ! 5-Colorado (Mexico) 31N54 114W57                    R5
+      ! Old=20 km3/year=634m3/s
+      ! --> 634.m3/s
+      DATA inb(5)/2/
+      DATA (iirnf(jc,5),jc=1,jpcoef)/ 347, 348, 18*0 /
+      DATA (ijrnf(jc,5),jc=1,jpcoef)/ 316, 316, 18*0 /
+      DATA (zrnfm(jm,5),jm=1,jpmois)/12*634./ 
+      ! 6-Columbia (USA) 45N60 121W17                       R1
+      ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+      ! --> 5368.41602m3/s
+      DATA inb(6)/2/
+      DATA (iirnf(jc,6),jc=1,jpcoef)/ 326, 326, 18*0 /
+      DATA (ijrnf(jc,6),jc=1,jpcoef)/ 360, 361, 18*0 /
+      DATA (zrnfm(jm,6),jm=1,jpmois)/   &
+          4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+          6350.,    4112.,    3273.,    3251.,    3548.,    4106./ 
+      ! 7-Fraser (USA)                                      R5
+      ! Old=112 km3/year=3550m3/s;not found in UNESCO
+      ! --> 3549.99976m3/s
+      DATA inb(7)/2/
+      DATA (iirnf(jc,7),jc=1,jpcoef)/ 317, 317, 18*0 /
+      DATA (ijrnf(jc,7),jc=1,jpcoef)/ 378, 379, 18*0 /
+      DATA (zrnfm(jm,7),jm=1,jpmois)/12*3550./ 
+      ! 8-Yukon (USA) 63N00 165W00                          R3
+      ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+      ! --> 6017.24951m3/s
+      DATA inb(8)/2/
+      DATA (iirnf(jc,8),jc=1,jpcoef)/ 244, 244, 18*0 /
+      DATA (ijrnf(jc,8),jc=1,jpcoef)/ 413, 414, 18*0 /
+      DATA (zrnfm(jm,8),jm=1,jpmois)/   &
+           1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+          10680.,   11271.,    8658.,    5453.,    2649.,    1917./ 
+      ! 9-Copper (USA) 61N47 144W45                         R2
+      ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+      ! --> 1236.25m3/s
+      DATA inb(9)/1/
+      DATA (iirnf(jc,9),jc=1,jpcoef)/ 274, 19*0 /
+      DATA (ijrnf(jc,9),jc=1,jpcoef)/ 409, 19*0 /
+      DATA (zrnfm(jm,9),jm=1,jpmois)/   &
+           219.,    195.,    181.,    214.,    904.,   2532.,   &
+          4026.,   3627.,   1632.,    697.,    354.,    254./ 
+      ! 10-Susitna (USA)                                    R5
+      ! Old=40 km3/year=1268m3/s
+      ! --> 1268.m3/s
+      DATA inb(10)/2/
+      DATA (iirnf(jc,10),jc=1,jpcoef)/ 263, 264, 18*0 /
+      DATA (ijrnf(jc,10),jc=1,jpcoef)/ 405, 405, 18*0 /
+      DATA (zrnfm(jm,10),jm=1,jpmois)/12*1268./ 
+      ! 11-McKenzie (Canada) 70N00 135W00                   R3
+      ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+      ! ratio=1.16
+      ! --> 9606.66797m3/s
+      DATA inb(11)/3/
+      DATA (iirnf(jc,11),jc=1,jpcoef)/ 272, 272, 272, 17*0 /
+      DATA (ijrnf(jc,11),jc=1,jpcoef)/ 451, 452, 453, 17*0 /
+      DATA (zrnfm(jm,11),jm=1,jpmois)/   &
+           3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+          18954.,   15487.,   11284.,   10169.,    5901.,    3905./
+      ! 12-Kuksokwim (USA) 60N00 ~162W30                    R4
+      ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+      ! --> 1111.99988m3/s
+      DATA inb(12)/2/
+      DATA (iirnf(jc,12),jc=1,jpcoef)/ 244, 244, 18*0 /
+      DATA (ijrnf(jc,12),jc=1,jpcoef)/ 413, 414, 18*0 /
+      DATA (zrnfm(jm,12),jm=1,jpmois)/   &
+          335.,     308.,     295.,     407.,    2415.,    2027.,   &
+          1917.,   2049.,    1585.,    1072.,     545.,     389./     
+
+      DATA inb(13)/0/
+      DATA inb(14)/0/
+      DATA inb(15)/0/
+
+      ! Total run-offs(I)=60974.2539m3/s
+
+      ! II SOUTH AMERICA
+      ! -----------------
+      ! 16-Chira (Peru) 4s54 81w08                          R2
+      ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+      ! --> 158.000015m3/s
+      DATA inb(16)/1/
+      DATA (iirnf(jc,16),jc=1,jpcoef)/ 414, 19*0 /
+      DATA (ijrnf(jc,16),jc=1,jpcoef)/ 244, 19*0 /
+      DATA (zrnfm(jm,16),jm=1,jpmois)/   &
+          70.,     105.,     564.,     582.,     230.,      94.,   &
+          87.,      47.,      35.,      32.,      29.,      21./
+      ! 17-Magdalena (Colombia) 11N06 74W51                 R2
+      ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+      ! ratio=1.08
+      ! --> 7451.58301m3/s
+      DATA inb(17)/2/
+      DATA (iirnf(jc,17),jc=1,jpcoef)/ 424, 424, 18*0 /
+      DATA (ijrnf(jc,17),jc=1,jpcoef)/ 270, 271, 18*0 /
+      DATA (zrnfm(jm,17),jm=1,jpmois)/   &
+          6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+          8509.,    7428.,    7631.,    9296.,   10588.,    9949./
+      ! 18-Orinoco (Venezuela) 8N37 62W15!                  R1
+      ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+      ! HLA=26371m3/s
+      ! Data from HLA: 8.1N - 63.3W   1925/89
+      ! --> 26371.416
+      DATA inb(18)/5/
+      DATA (iirnf(jc,18),jc=1,jpcoef)/ 451, 451, 452, 452, 452, 15*0 /
+      DATA (ijrnf(jc,18),jc=1,jpcoef)/ 271, 272, 271, 272, 272, 15*0 /
+      DATA (zrnfm(jm,18),jm=1,jpmois)/   &
+          10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+          43938.,   59957.,   57435.,   39951.,   27410.,   16567./ 
+      ! 19-Amazon (Brazil) 0S05 50W00                       R1
+      ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+      ! HLA=184806m3/s
+      ! UNESCO data are at Obidos which is far inland and therefore does not
+      ! fully represent the actual discharge
+      ! Data from HLA: 1.5N - 55.3W   1970/96
+      ! --> 184845.484m3/s
+      DATA inb(19)/14/
+      DATA (iirnf(jc,19),jc=1,jpcoef)/ 475, 476, 476, 476, 476,  &
+                                       477, 477, 477, 477, 477,  &
+                                       478, 478, 478, 478, 6*0 /
+      DATA (ijrnf(jc,19),jc=1,jpcoef)/ 254, 251, 252, 253, 254,  &
+                                       250, 251, 252, 253, 254,  &
+                                       250, 251, 252, 253, 6*0 /
+      DATA (zrnfm(jm,19),jm=1,jpmois)/   &
+          152233., 176415., 199941., 225565., 244016., 244861.,   &
+          230711., 203128., 164531., 128486., 118214., 130045. /
+      ! 20-Sao Francisco (Brazil) 10S30 36W24               R1
+      ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+      ! --> 2645.3335m3/s
+      DATA inb(20)/1/
+      DATA (iirnf(jc,20),jc=1,jpcoef)/ 498, 19*0 /
+      DATA (ijrnf(jc,20),jc=1,jpcoef)/ 223, 19*0 /
+      DATA (zrnfm(jm,20),jm=1,jpmois)/   &
+          3244.,   4116.,   5139.,   4330.,   2323.,   1800.,     &
+          1587.,   1511.,   1593.,   1740.,   2190.,   2171. /
+      ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18            R1 
+      ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+      ! --> 22203.168m3/s 
+      DATA inb(21)/5/
+      DATA (iirnf(jc,21),jc=1,jpcoef)/ 462, 462, 462, 462, 463, 15*0 /
+      DATA (ijrnf(jc,21),jc=1,jpcoef)/ 172, 173, 174, 175, 175, 15*0 /
+      DATA (zrnfm(jm,21),jm=1,jpmois)/   &
+          24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+          22647.,   20403.,   19627.,   21400.,   21126.,   21923./
+      ! 22-Negro (Argentina)  41S02  62W47                  R2
+      ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+      ! --> 907.666687m3/s
+      DATA inb(22)/2/
+      DATA (iirnf(jc,22),jc=1,jpcoef)/ 446, 447, 18*0 /
+      DATA (ijrnf(jc,22),jc=1,jpcoef)/ 160, 160, 18*0 /
+      DATA (zrnfm(jm,22),jm=1,jpmois)/   &
+          882.,     587.,     519.,     482.,     623.,     984.,   &
+          1120.,   1294.,    1092.,    1166.,    1105.,    1038./
+      ! 23- Tocantins :  ~48W00 ~0.5S                       R4
+      ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+      ! --> 12173.082m3/s
+      DATA inb(23)/4/
+      DATA (iirnf(jc,23),jc=1,jpcoef)/ 479, 480, 481, 482, 16*0 /
+      DATA (ijrnf(jc,23),jc=1,jpcoef)/ 249, 249, 249, 249, 16*0 /
+      DATA (zrnfm(jm,23),jm=1,jpmois)/   &
+          15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+          4440.,   3082.,   2728.,   3417.,   5511.,  10705. /
+
+      DATA inb(24)/0/
+      DATA inb(25)/0/
+
+      ! Total run-offs(II)=256755.75
+      ! Total run-offs(I+II)=317730
+
+      ! III EUROPE
+      ! ----------
+      ! 26-Rhone (France) 43N20 4E50                        R1 
+      ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+      ! --> 1217.16663m3/s
+      DATA inb(26)/1/
+      DATA (iirnf(jc,26),jc=1,jpcoef)/ 584, 19*0 /
+      DATA (ijrnf(jc,26),jc=1,jpcoef)/ 347, 19*0 /
+      DATA (zrnfm(jm,26),jm=1,jpmois)/   &
+          1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+           937.,     796.,     794.,     962.,    1161.,    1233./
+      ! 27-Po (Italy) 11N10 1W09                            R1 
+      ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+      ! --> 1550.08337m3/s
+      DATA inb(27)/1/
+      DATA (iirnf(jc,27),jc=1,jpcoef)/ 599, 19*0 /
+      DATA (ijrnf(jc,27),jc=1,jpcoef)/ 355, 19*0 /
+      DATA (zrnfm(jm,27),jm=1,jpmois)/   &
+          1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+          1040.,    1007.,    1615.,    1907.,    1772.,    1228./
+      ! 28-Danube (Roumania) 45N20 29E40                    R1 
+      ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+      ! --> 7011.8335m3/s
+      DATA inb(28)/2/
+      DATA (iirnf(jc,28),jc=1,jpcoef)/ 632, 632, 18*0 /
+      DATA (ijrnf(jc,28),jc=1,jpcoef)/ 356, 357, 18*0 /
+      DATA (zrnfm(jm,28),jm=1,jpmois)/   &
+          6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+          7586.,    6001.,    5210.,    4989.,    4921.,    6093./
+
+      DATA inb(29)/0/
+      DATA inb(30)/0/
+
+      ! Total run-offs(III)=9779.08301m3/s
+      ! Total run-offs(I+II+III)=327509.094m3/s
+      
+      ! IV EURASIAN ARCTIC
+      ! ------------------
+      ! 31-Iana (Russia)                                    R1
+      ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+      ! --> 0m3/s
+      DATA inb(31)/0/
+      DATA (iirnf(jc,31),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,31),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,31),jm=1,jpmois)/   &
+             2.,       1.,       0.,       0.,     917.,    3514.,   &
+          2968.,    2329.,    1322.,     178.,      36.,       8./ 
+      ! 32-Ob (Russia) 66N45 69E30                          R1 
+      ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+      ! --> 12861.5m3/s
+      DATA inb(32)/8/
+      DATA (iirnf(jc,32),jc=1,jpcoef)/ 635, 635, 636, 636, 636,637, 637,637,12*0 /
+      DATA (ijrnf(jc,32),jc=1,jpcoef)/ 508, 509, 509, 508, 507,509, 508,507,12*0 /
+     DATA (zrnfm(jm,32),jm=1,jpmois)/12*0./
+!CT bug     DATA (zrnfm(jm,32),jm=1,jpmois)/   &
+!CT bug          4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+!CT bug         30773.,   22785.,   14701.,    9705.,    6078.,    5879./
+      ! 33-Yenesei (Russia) 71N50 82E40                     R1 
+      ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+      ! --> 17461.666m3/s
+      DATA inb(33)/9/
+      DATA (iirnf(jc,33),jc=1,jpcoef)/ 114,115,115,116, 117,117,117,118,118,11*0 /
+      DATA (ijrnf(jc,33),jc=1,jpcoef)/ 504,504,503,503, 501,502,503,502,501,11*0 /
+      DATA (zrnfm(jm,33),jm=1,jpmois)/   &
+           6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+          25325.,   15940.,   16050.,   12678.,    6741.,    6008./
+      ! 34-Severnaya Dvina(Russia)64N32 40E30               R5 
+      ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+      ! --> 3359.00024m3/s
+      DATA inb(34)/2/
+      DATA (iirnf(jc,34),jc=1,jpcoef)/ 620, 620, 18*0 /
+      DATA (ijrnf(jc,34),jc=1,jpcoef)/ 448, 449, 18*0 /
+      DATA (zrnfm(jm,34),jm=1,jpmois)/12*3359./
+      ! 35-Lena (Russia) 72N25 126E40                       R1 
+      ! --> 16192.333m3/s
+      DATA inb(35)/9/
+      DATA (iirnf(jc,35),jc=1,jpcoef)/ 142,143,148,148,149,149,150,150,150,11*0 /
+      DATA (ijrnf(jc,35),jc=1,jpcoef)/ 458,458,456,448,449,448,451,450,449,11*0 /
+      DATA (zrnfm(jm,35),jm=1,jpmois)/   &
+           2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+          40810.,   28310.,   25995.,   13299.,    3673.,    3077./
+      ! 36-Kolyma (Russia) 69N30 161E00                     R1
+      ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+      ! --> 2138.66675m3/s
+      DATA inb(36)/2/
+      DATA (iirnf(jc,36),jc=1,jpcoef)/ 184, 185, 18*0 /
+      DATA (ijrnf(jc,36),jc=1,jpcoef)/ 429, 429, 18*0 /
+      DATA (zrnfm(jm,36),jm=1,jpmois)/   &
+           131.,      92.,      76.,      65.,    2576.,    9143.,   &
+          4670.,    3727.,    3226.,    1119.,     630.,     209./
+      ! 37-Indigirka (russia) 70N48 148E54                  R1 
+      ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+      ! --> 1622.00012m3/s
+      DATA inb(37)/1/
+      DATA (iirnf(jc,37),jc=1,jpcoef)/ 172, 19*0 /
+      DATA (ijrnf(jc,37),jc=1,jpcoef)/ 438, 19*0 /
+      DATA (zrnfm(jm,37),jm=1,jpmois)/   &
+            32.,      17.,      11.,       7.,     354.,    5629.,   &
+          5210.,    4617.,    2823.,     559.,     142.,      63./
+
+      DATA inb(38)/0/
+      DATA inb(39)/0/
+      DATA inb(40)/0/
+
+      ! Total run-offs(IV)=40773.6641m3/s
+      ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+      ! V ASIA
+      ! ------
+      ! 41-Amur (Russia) 52N56 141E10                       R2
+      ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+      ! --> 10299.332m3/s
+      DATA inb(41)/2/
+      DATA (iirnf(jc,41),jc=1,jpcoef)/ 141, 141, 18*0 /
+      DATA (ijrnf(jc,41),jc=1,jpcoef)/ 381, 382, 18*0 /
+      DATA (zrnfm(jm,41),jm=1,jpmois)/   &
+           2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+          16100.,   20801.,   21548.,   15658.,    5188.,    2506./
+      ! 42-Liaohe (China) 40N40 122E09                      R5
+      ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+      ! --> 189.999985m3/s
+      DATA inb(42)/1/
+      DATA (iirnf(jc,42),jc=1,jpcoef)/ 100, 19*0 /
+      DATA (ijrnf(jc,42),jc=1,jpcoef)/ 342, 19*0 /
+      DATA (zrnfm(jm,42),jm=1,jpmois)/12*190./
+      ! 43-Daling (China) 40N56 121E43                      R5
+      ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+      ! --> 31.9999962m3/s
+      DATA inb(43)/2/
+      DATA (iirnf(jc,43),jc=1,jpcoef)/  99, 100, 18*0 /
+      DATA (ijrnf(jc,43),jc=1,jpcoef)/ 342, 342, 18*0 /
+      DATA (zrnfm(jm,43),jm=1,jpmois)/12*32./
+      ! 44-Haiho (China) 6N17   1E23
+      ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+      ! --> 63.9999924m3/s
+      DATA inb(44)/1/
+      DATA (iirnf(jc,44),jc=1,jpcoef)/ 121, 19*0 /
+      DATA (ijrnf(jc,44),jc=1,jpcoef)/ 348, 19*0 /
+      DATA (zrnfm(jm,44),jm=1,jpmois)/12*64./
+      ! 45-Yellow/Huangho (China) 37N32 118E19              R2 
+      ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+      ! --> 1552.5m3/s
+      DATA inb(45)/3/
+      DATA (iirnf(jc,45),jc=1,jpcoef)/  92,  92,  92, 17*0 /
+      DATA (ijrnf(jc,45),jc=1,jpcoef)/ 336, 337, 338, 17*0 /
+      DATA (zrnfm(jm,45),jm=1,jpmois)/   &
+           697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+          1964.,    3270.,    3668.,    2133.,     978.,     871./
+      ! 46-Yangtze (China) 31N48 121E10=Changjiang          R2
+      ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+      ! --> 28519.584m3/s
+      DATA inb(46)/2/
+      DATA (iirnf(jc,46),jc=1,jpcoef)/ 100, 100, 18*0 /
+      DATA (ijrnf(jc,46),jc=1,jpcoef)/ 316, 317, 18*0 /
+      DATA (zrnfm(jm,46),jm=1,jpmois)/   &
+          10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+          53891.,   42070.,   37627.,   30762.,   22046.,   12777./
+      ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang      R2 
+      ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+      ! --> 9570.75m3/s
+      DATA inb(47)/2/
+      DATA (iirnf(jc,47),jc=1,jpcoef)/  72,  73, 18*0 /
+      DATA (ijrnf(jc,47),jc=1,jpcoef)/ 294, 294, 18*0 /
+      DATA (zrnfm(jm,47),jm=1,jpmois)/   &
+           2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+          19213.,   17558.,   12312.,    7255.,    5864.,    6154./
+      ! 48-Red/Hungho (Vietnam) 20N17 106E34                R5 
+      ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+      ! --> 3897.m3/s
+      DATA inb(48)/3/
+      DATA (iirnf(jc,48),jc=1,jpcoef)/  68,  68,  68, 17*0 /
+      DATA (ijrnf(jc,48),jc=1,jpcoef)/ 288, 289, 290, 17*0 /
+      DATA (zrnfm(jm,48),jm=1,jpmois)/12*3897./
+      ! 49-Mekong (Vietnam) 10N33 105E24                    R5
+      ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+      ! --> 14893.0029m3/s
+      DATA inb(49)/3/
+      DATA (iirnf(jc,49),jc=1,jpcoef)/  69,  69,  70, 17*0 /
+      DATA (ijrnf(jc,49),jc=1,jpcoef)/ 269, 270, 270, 17*0 /
+      DATA (zrnfm(jm,49),jm=1,jpmois)/12*14893./
+
+      DATA inb(50)/0/
+      DATA inb(51)/0/
+      DATA inb(52)/0/
+
+      ! 53-Damodar (India)                                  R2
+      ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+      ! --> 432.916656m3/s
+      DATA inb(53)/1/
+      DATA (iirnf(jc,53),jc=1,jpcoef)/  30, 19*0 /
+      DATA (ijrnf(jc,53),jc=1,jpcoef)/ 294, 19*0 /
+      DATA (zrnfm(jm,53),jm=1,jpmois)/   &
+           51.,      37.,      42.,      49.,      85.,     296.,   &
+          896.,    1390.,    1591.,     542.,     172.,      44./   
+
+      DATA inb(54)/0/
+      DATA inb(55)/0/
+      DATA inb(56)/0/
+      DATA inb(57)/0/
+      DATA inb(58)/0/
+      DATA inb(59)/0/
+      DATA inb(60)/0/
+
+      ! Total run-offs (V)=128642.922m3/s
+      ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+
+      ! VI AFRICA
+      ! ----------
+      ! 61-Nile (Egypt) 30N10  31E06                        R1
+      ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+      ! --> 1251.33337m3/s
+      DATA inb(61)/3/
+      DATA (iirnf(jc,61),jc=1,jpcoef)/ 636, 636, 637, 17*0 /
+      DATA (ijrnf(jc,61),jc=1,jpcoef)/ 317, 318, 318, 17*0 /
+      DATA (zrnfm(jm,61),jm=1,jpmois)/   &
+          1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+          1742.,    1559.,    1191.,    1103.,    1075.,    1124./   
+      ! 62-Niger (Nigeria) 5N33   6E33                      R1
+      ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+      ! Data from HLA: 4.5N -  6  E   1950/87
+      ! --> 5545.08301m3/s
+      DATA inb(62)/3/
+      DATA (iirnf(jc,62),jc=1,jpcoef)/ 591, 592, 593, 17*0 /
+      DATA (ijrnf(jc,62),jc=1,jpcoef)/ 258, 258, 258, 17*0 /
+      DATA (zrnfm(jm,62),jm=1,jpmois)/   &
+          2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+          5272.,    9629.,   14951.,   16227.,    6842.,    2741./   
+      ! 63-Zaire/Congo (Congo) 6S04  12E24                  R1      
+      ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+      ! =39720m3/s
+      ! Data from HLA: 6S - 12  E   1902/96
+      ! --> 39719.5m3/s
+      DATA inb(63)/4/
+      DATA (iirnf(jc,63),jc=1,jpcoef)/ 599, 599, 600, 600, 16*0 /
+      DATA (ijrnf(jc,63),jc=1,jpcoef)/ 237, 238, 236, 237, 16*0 /
+      DATA (zrnfm(jm,63),jm=1,jpmois)/   &
+          47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+          30966.,   30774.,   35981.,   42825.,   51455.,   55314./  
+      ! 64-Orange (Sth Africa) 28S41 16E28                  R5
+      ! Old=11 km3/year=349m3/s
+      ! --> 349.000031m3/s
+      DATA inb(64)/2/
+      DATA (iirnf(jc,64),jc=1,jpcoef)/ 609, 609, 18*0 /
+      DATA (ijrnf(jc,64),jc=1,jpcoef)/ 188, 189, 18*0 /
+      DATA (zrnfm(jm,64),jm=1,jpmois)/12*349./
+      ! 65-Zambesi (Mozambique) 18S55 36E04                 R5
+      ! Old=223 km3/year=7066m3/s
+      ! --> 7066.00049m3/s
+      DATA inb(65)/3/
+      DATA (iirnf(jc,65),jc=1,jpcoef)/ 646, 646, 646, 17*0 /
+      DATA (ijrnf(jc,65),jc=1,jpcoef)/ 207, 208, 209, 17*0 /
+      DATA (zrnfm(jm,65),jm=1,jpmois)/12*7066./
+      ! 66-Limpopo (mozambique) 25S15 33E30                 R5
+      ! Old=5 km3/year=158m3/s
+      ! --> 158.m3/s
+      DATA inb(66)/2/
+      DATA (iirnf(jc,66),jc=1,jpcoef)/ 642, 642, 18*0 /
+      DATA (ijrnf(jc,66),jc=1,jpcoef)/ 196, 197, 18*0 /
+      DATA (zrnfm(jm,66),jm=1,jpmois)/12*158./
+      ! 67-Rufiji (tanzania) 8S00 39E20                     R5
+      ! Old=9 km3/year=285m3/s
+      ! --> 285.m3/s
+      DATA inb(67)/1/
+      DATA (iirnf(jc,67),jc=1,jpcoef)/ 655, 19*0 /
+      DATA (ijrnf(jc,67),jc=1,jpcoef)/ 235, 19*0 /
+      DATA (zrnfm(jm,67),jm=1,jpmois)/12*285./
+      ! Other rivers from the Gulf of Guinea
+      ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)         R1
+      ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+      ! --> 924.25m3/s
+      DATA inb(68)/1/
+      DATA (iirnf(jc,68),jc=1,jpcoef)/ 599, 19*0 /
+      DATA (ijrnf(jc,68),jc=1,jpcoef)/ 240, 19*0 /
+      DATA (zrnfm(jm,68),jm=1,jpmois)/   &
+          1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+           480.,     378.,     327.,     400.,    1018.,    1281./
+      ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)              R1
+      ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+      ! --> 264.166687m3/s
+      DATA inb(69)/1/
+      DATA (iirnf(jc,69),jc=1,jpcoef)/ 595, 19*0 /
+      DATA (ijrnf(jc,69),jc=1,jpcoef)/ 244, 19*0 /
+      DATA (zrnfm(jm,69),jm=1,jpmois)/   &
+          126.,      99.,     143.,     253.,     316.,     300.,   &
+          156.,      93.,     231.,     557.,     592.,     304./
+      ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)                R1
+      ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+      ! --> 4511.83301m3/s
+      DATA inb(70)/2/
+      DATA (iirnf(jc,70),jc=1,jpcoef)/ 593, 593, 18*0 /
+      DATA (ijrnf(jc,70),jc=1,jpcoef)/ 247, 248, 18*0 /
+      DATA (zrnfm(jm,70),jm=1,jpmois)/   &
+          4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+          2616.,    1961.,    2119.,    4304.,    7870.,    6810./
+      ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)        R1
+      ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+      ! --> 1982.58337m3/s
+      DATA inb(71)/2/
+      DATA (iirnf(jc,71),jc=1,jpcoef)/ 595, 595, 18*0 /
+      DATA (ijrnf(jc,71),jc=1,jpcoef)/ 255, 256, 18*0 /
+      DATA (zrnfm(jm,71),jm=1,jpmois)/   &
+           813.,     578.,     517.,     633.,     909.,    1278.,   &
+          1928.,    2653.,    4361.,    5470.,    3307.,    1344./
+      ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)         R1
+      ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+      ! --> 431.166656m3/s      
+      DATA inb(72)/1/
+      DATA (iirnf(jc,72),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,72),jc=1,jpcoef)/ 257, 19*0 /
+      DATA (zrnfm(jm,72),jm=1,jpmois)/   &
+          232.,     128.,     150.,     266.,     402.,     459.,   &
+          353.,     306.,     604.,     930.,     878.,     466./
+      ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)          R1
+      ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+      ! --> 329.75m3/s
+      DATA inb(73)/1/
+      DATA (iirnf(jc,73),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,73),jc=1,jpcoef)/ 254, 19*0 /
+      DATA (zrnfm(jm,73),jm=1,jpmois)/   &
+          452.,     455.,     492.,     466.,     482.,     251.,   &
+          151.,     108.,      87.,     133.,     395.,     485./
+      ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)           R1
+      ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+      ! --> 306.583374m3/s
+      DATA inb(74)/1/
+      DATA (iirnf(jc,74),jc=1,jpcoef)/ 594, 19*0 /
+      DATA (ijrnf(jc,74),jc=1,jpcoef)/ 257, 19*0 /
+      DATA (zrnfm(jm,74),jm=1,jpmois)/   &
+           88.,      63.,      68.,      95.,     139.,     222.,   &
+          395.,     633.,     825.,     675.,     328.,     148./
+      ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)            R1
+      ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+      ! --> 112.666664m3/s
+      DATA inb(75)/1/
+      DATA (iirnf(jc,75),jc=1,jpcoef)/ 583, 19*0 /
+      DATA (ijrnf(jc,75),jc=1,jpcoef)/ 262, 19*0 /
+      DATA (zrnfm(jm,75),jm=1,jpmois)/   &
+           0.,       0.,       0.,       0.,       1.,      18.,   &
+          96.,     324.,     531.,     319.,      58.,       5./
+      ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27)     R1
+      ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+      ! --> 96.4999924m3/s
+      DATA inb(76)/2/
+      DATA (iirnf(jc,76),jc=1,jpcoef)/ 578, 579, 18*0 /
+      DATA (ijrnf(jc,76),jc=1,jpcoef)/ 262, 262, 18*0 /
+      DATA (zrnfm(jm,76),jm=1,jpmois)/   &
+            2.,       1.,       1.,       4.,       8.,      44.,   &
+          168.,     274.,     386.,     215.,      47.,       8./
+      ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)          R1
+      ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+      ! --> 194.25m3/s
+      DATA inb(77)/1/
+      DATA (iirnf(jc,77),jc=1,jpcoef)/ 569, 19*0 /
+      DATA (ijrnf(jc,77),jc=1,jpcoef)/ 260, 19*0 /
+      DATA (zrnfm(jm,77),jm=1,jpmois)/   &
+           14.,       7.,       9.,      17.,      29.,      90.,   &
+          145.,     349.,     740.,     688.,     198.,      45./
+      ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)      R1
+      ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+      ! --> 449.333344m3/s
+      DATA inb(78)/1/
+      DATA (iirnf(jc,78),jc=1,jpcoef)/ 564, 19*0 /
+      DATA (ijrnf(jc,78),jc=1,jpcoef)/ 260, 19*0 /
+      DATA (zrnfm(jm,78),jm=1,jpmois)/   &
+          144.,     116.,     119.,     143.,     156.,     334.,   &
+          419.,     692.,    1277.,    1190.,     553.,     249./
+      
+      DATA inb(79)/0/
+      DATA inb(80)/0/
+      DATA inb(81)/0/
+      DATA inb(82)/0/
+      DATA inb(83)/0/
+      DATA inb(84)/0/
+      DATA inb(85)/0/
+      DATA inb(86)/0/
+      DATA inb(87)/0/
+      DATA inb(88)/0/
+      DATA inb(89)/0/
+      DATA inb(90)/0/
+
+      ! Total run-offs (VI)=63977.m3/s
+      ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+
+      ! VII OCEANIA
+      ! ------------
+      ! 91-Murray (Austrlia) 35S34 138E54                   R5
+      ! Old=22 km3/year=697m3/s
+      ! --> 696.999939m3/s
+      DATA inb(91)/3/
+      DATA (iirnf(jc,91),jc=1,jpcoef)/ 129, 130, 130, 17*0 /
+      DATA (ijrnf(jc,91),jc=1,jpcoef)/ 177, 176, 177, 17*0 /
+      DATA (zrnfm(jm,91),jm=1,jpmois)/12*697./
+      ! 92-Haast (N. Zeland) 43S50 169E02                   R5
+      ! Old=6 km3/year=190m3/s
+      ! --> 189.999985m3/s
+      DATA inb(92)/1/
+      DATA (iirnf(jc,92),jc=1,jpcoef)/ 194, 19*0 /
+      DATA (ijrnf(jc,92),jc=1,jpcoef)/ 153, 19*0 /
+      DATA (zrnfm(jm,92),jm=1,jpmois)/12*190./
+      ! 93-Fly (N. Guinea) 8S30 143E05                      R5
+      ! Old=77 km3/year=2440m3/s
+      ! --> 2440.m3/s
+      DATA inb(93)/1/
+      DATA (iirnf(jc,93),jc=1,jpcoef)/ 143, 19*0 /
+      DATA (ijrnf(jc,93),jc=1,jpcoef)/ 233, 19*0 /
+      DATA (zrnfm(jm,93),jm=1,jpmois)/12*2440./
+      ! 94-Purari (N. Guinea) 7S25 145E05                   R4
+      ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+      ! --> 2727.33325m3/s
+      DATA inb(94)/1/
+      DATA (iirnf(jc,94),jc=1,jpcoef)/ 146, 19*0 /
+      DATA (ijrnf(jc,94),jc=1,jpcoef)/ 234, 19*0 /
+      DATA (zrnfm(jm,94),jm=1,jpmois)/   &
+          1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+          2867.,    3477.,    2195.,    2967.,    2674.,    2627./
+      ! 95-Choshui ch''i (taiwan) 24N03 120E23              R2
+      ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+      ! --> 0.m3/s
+      DATA inb(95)/0/
+      DATA (iirnf(jc,95),jc=1,jpcoef)/  20*0 /
+      DATA (ijrnf(jc,95),jc=1,jpcoef)/  20*0 /
+      DATA (zrnfm(jm,95),jm=1,jpmois)/   &
+           65.,      63.,      83.,     100.,     177.,     535.,   &
+          332.,     313.,     236.,     193.,     101.,      84./
+      ! 96-Kaoping (Taiwan)                                 R5  
+      ! Old=9 km3/year=285m3/s
+      ! --> 0.m3/s
+      DATA inb(96)/0/
+      DATA (iirnf(jc,96),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,96),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,96),jm=1,jpmois)/12*285./
+      ! 97-Tsengwen (Taiwan)                                R5
+      ! Old=2 km3/year=63m3/s
+      ! --> 0.m3/s
+      DATA inb(97)/0/
+      DATA (iirnf(jc,97),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,97),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,97),jm=1,jpmois)/12*63./
+      ! 98-Hualien (Taiwan)                                 R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(98)/0/
+      DATA (iirnf(jc,98),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,98),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,98),jm=1,jpmois)/12*127./
+      ! 99-Peinan (Taiwan) 22N46 121E10                     R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 127.000008m3/s
+      DATA inb(99)/1/
+      DATA (iirnf(jc,99),jc=1,jpcoef)/  98, 19*0 /
+      DATA (ijrnf(jc,99),jc=1,jpcoef)/ 288, 19*0 /
+      DATA (zrnfm(jm,99),jm=1,jpmois)/12*127./
+      ! 100-Hsiukuluan (Taiwan)                             R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(100)/0/
+      DATA (iirnf(jc,100),jc=1,jpcoef)/ 20*0 /
+      DATA (ijrnf(jc,100),jc=1,jpcoef)/ 20*0 /
+      DATA (zrnfm(jm,100),jm=1,jpmois)/12*127./
+
+
+
+
+
+
+
+       ! I ASIA
+       ! ------
+
+       ! 1-Indus (Pakistan)
+       ! --> 3949m3/s
+       DATA inb(101)/4/
+       DATA (iirnf(jc,101),jc=1,jpcoef)/ 711, 711, 712, 713, 16*0 /
+       DATA (ijrnf(jc,101),jc=1,jpcoef)/ 297, 298, 297, 297, 16*0 /
+       DATA (zrnfm(jm,101),jm=1,jpmois)/  &
+     &      1691.,    2121.,    2083.,    2940.,    3738.,    4198.,  &
+     &      5334.,    8247.,    7833.,    4908.,    2681.,    1614./
+       ! 2-Sabarmati+Mahi+Narmada (India)
+       ! --> 3383m3/s
+       DATA inb(102)/1/
+!CT bug point terre       DATA (iirnf(jc,102),jc=1,jpcoef)/ 720, 19*0 /
+!CT bug point terre       DATA (ijrnf(jc,102),jc=1,jpcoef)/ 292, 19*0 /
+       DATA (iirnf(jc,102),jc=1,jpcoef)/ 719, 19*0 /
+       DATA (ijrnf(jc,102),jc=1,jpcoef)/ 291, 19*0 /
+       DATA (zrnfm(jm,102),jm=1,jpmois)/  &
+     &      1343.,     110.,       0.,       0.,      13.,    3051.,  &
+     &      9453.,   11655.,    7619.,    3547.,    2081.,    1727./
+       ! 3-
+       ! --> 182m3/s
+       DATA inb(103)/1/
+!CT bug point terre       DATA (iirnf(jc,103),jc=1,jpcoef)/ 721, 19*0 /
+!CT bug point terre       DATA (ijrnf(jc,103),jc=1,jpcoef)/ 286, 19*0 /
+       DATA (iirnf(jc,103),jc=1,jpcoef)/ 720, 19*0 /
+       DATA (ijrnf(jc,103),jc=1,jpcoef)/ 286, 19*0 /
+       DATA (zrnfm(jm,103),jm=1,jpmois)/  &
+     &      0.,       0.,       0.,       0.,     225.,     669.,  &
+     &      526.,     327.,     187.,     100.,      62.,      92./
+       ! 4-Mandovi + Zuari + Kalinadi
+       ! --> 347m3/s
+       DATA inb(104)/1/
+       DATA (iirnf(jc,104),jc=1,jpcoef)/ 2, 19*0 /
+       DATA (ijrnf(jc,104),jc=1,jpcoef)/ 282, 19*0 /
+       DATA (zrnfm(jm,104),jm=1,jpmois)/  &
+     &      7.,       0.,       0.,       0.,     428.,    1339.,  &
+     &      966.,     601.,     350.,     190.,     117.,     166./
+       ! 5-                    R2
+       ! --> 190m3/s
+       DATA inb(105)/1/
+       DATA (iirnf(jc,105),jc=1,jpcoef)/ 4, 19*0 /
+       DATA (ijrnf(jc,105),jc=1,jpcoef)/ 279, 19*0 /
+       DATA (zrnfm(jm,105),jm=1,jpmois)/  &
+     &      0.,       0.,       0.,       0.,     363.,     710.,   &
+     &      484.,     315.,     172.,      95.,      59.,      87./
+       ! 6-
+       ! --> 1101m3/s
+       DATA inb(106)/1/
+       DATA (iirnf(jc,106),jc=1,jpcoef)/ 4, 19*0 /
+       DATA (ijrnf(jc,106),jc=1,jpcoef)/ 277, 19*0 /
+       DATA (zrnfm(jm,106),jm=1,jpmois)/   &
+     &      79.,       0.,       0.,       0.,    1457.,    3639.,   &
+     &      3084.,    2031.,    1282.,     696.,     414.,     535. /
+       ! 7-
+       ! --> 948m3/s
+       DATA inb(107)/1/
+       DATA (iirnf(jc,107),jc=1,jpcoef)/ 5, 19*0 /
+       DATA (ijrnf(jc,107),jc=1,jpcoef)/ 275, 19*0 /
+       DATA (zrnfm(jm,107),jm=1,jpmois)/  &
+     &      72.,       0.,       0.,       0.,    1151.,    3038.,     & 
+     &      2583.,    1603.,    1216.,     749.,     426.,     539./
+
+       ! 8-
+       ! --> 551m3/s
+       DATA inb(108)/1/
+       DATA (iirnf(jc,108),jc=1,jpcoef)/ 7, 19*0 /
+       DATA (ijrnf(jc,108),jc=1,jpcoef)/ 271, 19*0 /
+       DATA (zrnfm(jm,108),jm=1,jpmois)/  &
+     &      45.,       0.,       2.,       7.,     680.,    1621.,  &
+     &      1234.,     744.,     784.,     696.,     359.,     442. /
+       ! 9-
+       ! --> 103m3/s
+       DATA inb(109)/1/
+       DATA (iirnf(jc,109),jc=1,jpcoef)/ 8, 19*0 /
+       DATA (ijrnf(jc,109),jc=1,jpcoef)/ 269, 19*0 /
+       DATA (zrnfm(jm,109),jm=1,jpmois)/  &
+     &      11.,       0.,       0.,       0.,     160.,     250.,   &
+     &      200.,     145.,     168.,     146.,      74.,      89. /
+       ! 10-
+       ! --> 99m3/s
+       DATA inb(110)/1/
+       DATA (iirnf(jc,110),jc=1,jpcoef)/12, 19*0 /
+       DATA (ijrnf(jc,110),jc=1,jpcoef)/267, 19*0 /
+       DATA (zrnfm(jm,110),jm=1,jpmois)/  &
+     &      50.,       1.,       1.,       0.,      25.,      69.,  &
+     &      51.,      32.,     176.,     329.,     233.,     222./
+       ! 11- Kaveri (India)
+       ! --> 173m3/s
+       DATA inb(111)/1/
+       DATA (iirnf(jc,111),jc=1,jpcoef)/16, 19*0 /
+       DATA (ijrnf(jc,111),jc=1,jpcoef)/271, 19*0 /
+       DATA (zrnfm(jm,111),jm=1,jpmois)/  &
+     &       97.,       2.,       1.,       2.,      19.,      67.,   &
+     &      108.,     134.,     218.,     515.,     498.,     416. /
+       ! 12-
+       ! --> 116m3/s
+       DATA inb(112)/1/
+       DATA (iirnf(jc,112),jc=1,jpcoef)/16, 19*0 /
+       DATA (ijrnf(jc,112),jc=1,jpcoef)/279, 19*0 /
+       DATA (zrnfm(jm,112),jm=1,jpmois)/  &
+     &       43.,       0.,       0.,       0.,       0.,       0.,   &
+     &        0.,       0.,      99.,     568.,     343.,     342. /
+       ! 13- Krishna
+       ! --> 2864m3/s
+       DATA inb(113)/1/
+       DATA (iirnf(jc,113),jc=1,jpcoef)/ 16, 19*0 /
+       DATA (ijrnf(jc,113),jc=1,jpcoef)/ 281, 19*0 /
+       DATA (zrnfm(jm,113),jm=1,jpmois)/   &
+     &       1368.,     174.,       0.,       0.,     166.,    2362.,  &
+     &       9501.,    8639.,    6053.,    3173.,    1763.,    1175. /
+       ! 14- (SriLanka)
+       ! --> 371m3/s
+       DATA inb(114)/1/
+       DATA (iirnf(jc,114),jc=1,jpcoef)/ 16, 19*0 /
+       DATA (ijrnf(jc,114),jc=1,jpcoef)/ 261, 19*0 /
+       DATA (zrnfm(jm,114),jm=1,jpmois)/  &
+     &      171.,     144.,     292.,     469.,     414.,     309.,  &
+     &      269.,     244.,     526.,     560.,     476.,     588.  /
+       ! 15- (SriLanka)
+       ! --> 305m3/s
+       DATA inb(115)/1/
+       DATA (iirnf(jc,115),jc=1,jpcoef)/18, 19*0 /
+       DATA (ijrnf(jc,115),jc=1,jpcoef)/262, 19*0 /
+       DATA (zrnfm(jm,115),jm=1,jpmois)/  &
+     &      116.,     111.,     225.,     379.,     366.,     300.,  &
+     &      256.,     239.,     385.,     437.,     388.,     467. /
+       ! 16- (SriLanka)
+       ! --> 722m3/s
+       DATA inb(116)/1/
+       DATA (iirnf(jc,116),jc=1,jpcoef)/20, 19*0 /
+       DATA (ijrnf(jc,116),jc=1,jpcoef)/265, 19*0 /
+       DATA (zrnfm(jm,116),jm=1,jpmois)/  &
+     &      711.,     347.,     477.,     556.,     430.,     302.,  &
+     &      228.,     200.,     629.,    1156.,    1579.,    2055.   /
+       ! 17- (SriLanka)
+       ! --> 188m3/s
+       DATA inb(117)/1/
+       DATA (iirnf(jc,117),jc=1,jpcoef)/19, 19*0 /
+       DATA (ijrnf(jc,117),jc=1,jpcoef)/267, 19*0 /
+       DATA (zrnfm(jm,117),jm=1,jpmois)/  &
+     &      189.,      50.,      27.,      17.,      10.,       6.,  &
+     &       4.,       2.,       1.,     236.,     829.,     894. /
+       ! 18- Godavari (India) 17N00  81E45
+       ! --> 2709m3/s
+       DATA inb(118)/1/
+       DATA (iirnf(jc,118),jc=1,jpcoef)/ 19, 19*0 /
+       DATA (ijrnf(jc,118),jc=1,jpcoef)/283, 19*0 /
+       DATA (zrnfm(jm,118),jm=1,jpmois)/  &
+     &      1151.,      57.,       0.,       0.,      38.,    1490.,  &
+     &      6714.,    9065.,    7208.,    3294.,    1874.,    1629. /
+       ! 19-
+       ! --> 116m3/s
+       DATA inb(119)/1/
+       DATA (iirnf(jc,119),jc=1,jpcoef)/23, 19*0 /
+       DATA (ijrnf(jc,119),jc=1,jpcoef)/286, 19*0 /
+       DATA (zrnfm(jm,119),jm=1,jpmois)/  &
+     &         17.,       0.,       0.,       0.,       0.,     103.,  &
+     &        259.,     341.,     330.,     155.,      87.,     110. /
+       ! 20- Mahanadi (India)
+       ! --> 2390m3/s
+       DATA inb(120)/1/
+       DATA (iirnf(jc,120),jc=1,jpcoef)/28, 19*0 /
+       DATA (ijrnf(jc,120),jc=1,jpcoef)/290, 19*0 /
+       DATA (zrnfm(jm,120),jm=1,jpmois)/  &
+     &       809.,       5.,       0.,       0.,      60.,    1401.,  &
+     &      6652.,    8828.,    5410.,    2561.,    1503.,    1452. /
+       ! 21-
+       ! --> 247m3/s
+       DATA inb(121)/1/
+       DATA (iirnf(jc,121),jc=1,jpcoef)/30, 19*0 /
+       DATA (ijrnf(jc,121),jc=1,jpcoef)/294, 19*0 /
+       DATA (zrnfm(jm,121),jm=1,jpmois)/  &
+     &         15.,       0.,       0.,       0.,      73.,     367.,   &
+     &        744.,     722.,     491.,     227.,     137.,     188. /
+       ! 22-
+       ! --> 167m3/s
+       DATA inb(122)/1/
+       DATA (iirnf(jc,122),jc=1,jpcoef)/31, 19*0 /
+       DATA (ijrnf(jc,122),jc=1,jpcoef)/294, 19*0 /
+       DATA (zrnfm(jm,122),jm=1,jpmois)/  &
+     &         16.,       0.,       0.,       0.,      95.,     337.,  &
+     &        488.,     453.,     285.,     143.,      84.,     109. /
+       ! 23-
+       ! --> 206m3/s
+       DATA inb(123)/1/
+       DATA (iirnf(jc,123),jc=1,jpcoef)/32, 19*0 /
+       DATA (ijrnf(jc,123),jc=1,jpcoef)/294, 19*0 /
+       DATA (zrnfm(jm,123),jm=1,jpmois)/  &
+     &         12.,       0.,       0.,       0.,      35.,     400.,  &
+     &        652.,     616.,     347.,     172.,     105.,     144. /
+       ! 24- Ganga + Brahmaputra (Bangladesh) 22N00  91E00
+       ! --> 42436m3/s
+       DATA inb(124)/9/
+       DATA (iirnf(jc,124),jc=1,jpcoef)/ 37, 38, 39, 32, 33, 34, 35  &
+     &      , 36, 37, 11*0 /
+       DATA (ijrnf(jc,124),jc=1,jpcoef)/ 295,295,295,294,294,294,294  &
+     &      , 294, 294, 11*0 /
+       DATA (zrnfm(jm,124),jm=1,jpmois)/  &
+     &        14293.,   4223.,   3004.,  11743.,  32210.,  56899.,  &
+     &        82263.,  95069.,  77997.,  44194.,  23724.,  17272. /
+
+       DATA inb(125)/0/
+      DATA inb(126)/0/
+
+       ! 27- Kuladan
+       ! --> 1541m3/s
+       DATA inb(127)/1/
+       DATA (iirnf(jc,127),jc=1,jpcoef)/42, 19*0 /
+       DATA (ijrnf(jc,127),jc=1,jpcoef)/290, 19*0 /
+       DATA (zrnfm(jm,127),jm=1,jpmois)/  &
+     &        140.,       0.,       0.,      27.,    2280.,    4133.,  &
+     &       4306.,    3049.,    1993.,    1115.,     646.,     812. /
+       ! 28-
+       ! --> 618m3/s
+       DATA inb(128)/1/
+       DATA (iirnf(jc,128),jc=1,jpcoef)/44, 19*0 /
+       DATA (ijrnf(jc,128),jc=1,jpcoef)/287, 19*0 /
+       DATA (zrnfm(jm,128),jm=1,jpmois)/  &
+     &        0.,       0.,       0.,      73.,    1139.,    1755.,  &
+     &      1725.,    1139.,     677.,     362.,     221.,     326. /
+       ! 29-
+       ! --> 158m3/s
+       DATA inb(129)/1/
+       DATA (iirnf(jc,129),jc=1,jpcoef)/44, 19*0 /
+       DATA (ijrnf(jc,129),jc=1,jpcoef)/284, 19*0 /
+       DATA (zrnfm(jm,129),jm=1,jpmois)/  &
+     &        0.,       0.,       0.,       0.,     248.,     419.,  &
+     &      445.,     334.,     201.,     103.,      63.,      93. /
+       ! 30-
+       ! --> 136m3/s
+       DATA inb(130)/1/
+       DATA (iirnf(jc,130),jc=1,jpcoef)/32, 19*0 /
+       DATA (ijrnf(jc,130),jc=1,jpcoef)/277, 19*0 /
+       DATA (zrnfm(jm,130),jm=1,jpmois)/  &
+     &         0.,       0.,       0.,       0.,     223.,     261.,  &
+     &       269.,     315.,     223.,     147.,      86.,     116. /
+       ! 31-
+       ! --> 142m3/s
+       DATA inb(131)/1/
+       DATA (iirnf(jc,131),jc=1,jpcoef)/42, 19*0 /
+       DATA (ijrnf(jc,131),jc=1,jpcoef)/275, 19*0 /
+       DATA (zrnfm(jm,131),jm=1,jpmois)/  &
+     &         0.,       0.,       0.,       0.,     241.,     260.,  &
+     &       270.,     325.,     231.,     158.,      96.,     126.  /
+       ! 32- Irrawady (Myanmar) 15N50  95E06
+       ! --> 16751m3/s
+       DATA inb(132)/3/
+       DATA (iirnf(jc,132),jc=1,jpcoef)/  45,  46, 47, 17*0 /
+       DATA (ijrnf(jc,132),jc=1,jpcoef)/ 282, 281, 282, 17*0 /
+       DATA (zrnfm(jm,132),jm=1,jpmois)/  &
+     &       7174.,     2281.,     80.,    687.,    8133.,   23980.,  &
+     &       38452.,   41442.,  34497.,  23150.,   12529.,    8629. /
+
+       DATA inb(133)/0/
+       DATA inb(134)/0/
+       DATA inb(135)/0/
+       DATA inb(136)/0/
+
+       ! 37- Tenasserim (Myanmar)
+       ! --> 1369m3/s
+       DATA inb(137)/1/
+       DATA (iirnf(jc,137),jc=1,jpcoef)/51, 19*0 /
+       DATA (ijrnf(jc,137),jc=1,jpcoef)/279, 19*0 /
+       DATA (zrnfm(jm,137),jm=1,jpmois)/  &
+     &        65.,       0.,       0.,     540.,    2127.,    3260.,  &
+     &      3540.,    2966.,    1747.,     900.,     544.,     741. /
+       ! 38-
+       ! --> 413m3/s
+       DATA inb(138)/1/
+       DATA (iirnf(jc,138),jc=1,jpcoef)/52, 19*0 /
+       DATA (ijrnf(jc,138),jc=1,jpcoef)/277, 19*0 /
+       DATA (zrnfm(jm,138),jm=1,jpmois)/  &
+     &          0.,       0.,       0.,     202.,     773.,    1000.,  &
+     &       1032.,     831.,     492.,     248.,     153.,     226. /
+       ! 39-
+       ! --> 810m3/s
+       DATA inb(139)/1/
+       DATA (iirnf(jc,139),jc=1,jpcoef)/52, 19*0 /
+       DATA (ijrnf(jc,139),jc=1,jpcoef)/275, 19*0 /
+       DATA (zrnfm(jm,139),jm=1,jpmois)/  &
+     &         59.,       0.,       0.,      22.,    1104.,    1857.,  &
+     &       2069.,    1858.,    1252.,     637.,     373.,     493. /
+       ! 40-
+       ! --> 896m3/s
+       DATA inb(140)/1/
+       DATA (iirnf(jc,140),jc=1,jpcoef)/52, 19*0 /
+       DATA (ijrnf(jc,140),jc=1,jpcoef)/273, 19*0 /
+       DATA (zrnfm(jm,140),jm=1,jpmois)/  &
+     &         94.,       0.,       0.,     196.,    1145.,    1716.,  &
+     &       1936.,    1899.,    1519.,    1000.,     562.,     688. /
+       ! 41-
+       ! --> 559m3/s
+       DATA inb(141)/1/
+       DATA (iirnf(jc,141),jc=1,jpcoef)/52, 19*0 /
+       DATA (ijrnf(jc,141),jc=1,jpcoef)/271, 19*0 /
+       DATA (zrnfm(jm,141),jm=1,jpmois)/  &
+     &       38.,       0.,       0.,     227.,     805.,    1051.,  &
+     &      1105.,    1236.,     941.,     575.,     321.,     416. /
+       ! 42-
+       ! --> 1070m3/s
+       DATA inb(142)/1/
+       DATA (iirnf(jc,142),jc=1,jpcoef)/53, 19*0 /
+       DATA (ijrnf(jc,142),jc=1,jpcoef)/265, 19*0 /
+       DATA (zrnfm(jm,142),jm=1,jpmois)/  &
+     &       356.,      18.,      14.,     160.,     745.,    1123.,  &
+     &      1347.,    1732.,    2076.,    2057.,    1574.,    1639. /
+       ! 43-
+       ! --> 513m3/s
+       DATA inb(143)/1/
+       DATA (iirnf(jc,143),jc=1,jpcoef)/54, 19*0 /
+       DATA (ijrnf(jc,143),jc=1,jpcoef)/263, 19*0 /
+       DATA (zrnfm(jm,143),jm=1,jpmois)/  &
+     &       231.,      12.,     121.,     236.,     216.,     239.,  &
+     &       351.,     517.,    1008.,    1324.,     975.,     929.  /
+       ! 44-
+       ! --> 881m3/s
+       DATA inb(144)/1/
+       DATA (iirnf(jc,144),jc=1,jpcoef)/56, 19*0 /
+       DATA (ijrnf(jc,144),jc=1,jpcoef)/259, 19*0 /
+       DATA (zrnfm(jm,144),jm=1,jpmois)/  &
+     &      558.,     632.,     980.,     902.,     575.,     421.,  &
+     &      432.,     731.,    1276.,    1405.,    1188.,    1480. /
+       ! 45-
+       ! --> 905m3/s
+       DATA inb(145)/1/
+       DATA (iirnf(jc,145),jc=1,jpcoef)/52, 19*0 /
+       DATA (ijrnf(jc,145),jc=1,jpcoef)/259, 19*0 /
+       DATA (zrnfm(jm,145),jm=1,jpmois)/  &
+     &      604.,     552.,     781.,     853.,     627.,     488.,  &
+     &      503.,     781.,    1245.,    1356.,    1331.,    1747. /
+       ! 46-
+       ! --> 136m3/s
+       DATA inb(146)/1/
+       DATA (iirnf(jc,146),jc=1,jpcoef)/50, 19*0 /
+       DATA (ijrnf(jc,146),jc=1,jpcoef)/261, 19*0 /
+       DATA (zrnfm(jm,146),jm=1,jpmois)/  &
+     &      103.,     111.,     126.,     112.,      66.,      40.,  &
+     &       35.,      51.,     126.,     227.,     279.,     362.  /
+       ! 47-
+       ! --> 222m3/s
+       DATA inb(147)/1/
+       DATA (iirnf(jc,147),jc=1,jpcoef)/47, 19*0 /
+       DATA (ijrnf(jc,147),jc=1,jpcoef)/258, 19*0 /
+       DATA (zrnfm(jm,147),jm=1,jpmois)/  &
+     &      176.,     160.,     209.,     197.,     130.,      99.,  &
+     &       90.,     151.,     240.,     342.,     373.,     502./
+       ! 48-
+       ! --> 326m3/s
+       DATA inb(148)/1/
+       DATA (iirnf(jc,148),jc=1,jpcoef)/49, 19*0 /
+       DATA (ijrnf(jc,148),jc=1,jpcoef)/257, 19*0 /
+       DATA (zrnfm(jm,148),jm=1,jpmois)/  &
+     &       226.,     278.,     363.,     301.,     181.,     130.,  &
+     &       131.,     194.,     407.,     505.,     519.,     689. /
+       ! 49-
+       ! --> 203m3/s
+       DATA inb(149)/1/
+       DATA (iirnf(jc,149),jc=1,jpcoef)/50, 19*0 /
+       DATA (ijrnf(jc,149),jc=1,jpcoef)/256, 19*0 /
+       DATA (zrnfm(jm,149),jm=1,jpmois)/  &
+     &      120.,     218.,     233.,     189.,     134.,     128.,  &
+     &      115.,     178.,     244.,     272.,     247.,     360. /
+       ! 50-
+       ! --> 153m3/s
+       DATA inb(150)/1/
+       DATA (iirnf(jc,150),jc=1,jpcoef)/50, 19*0 /
+       DATA (ijrnf(jc,150),jc=1,jpcoef)/255, 19*0 /
+       DATA (zrnfm(jm,150),jm=1,jpmois)/  &
+     &         97.,     108.,     191.,     141.,      97.,      82.,  &
+     &        107.,     118.,     188.,     230.,     208.,     278. /
+       ! 51-
+       ! --> 196m3/s
+       DATA inb(151)/1/
+       DATA (iirnf(jc,151),jc=1,jpcoef)/53, 19*0 /
+       DATA (ijrnf(jc,151),jc=1,jpcoef)/253, 19*0 /
+       DATA (zrnfm(jm,151),jm=1,jpmois)/  &
+     &        74.,     125.,     165.,     123.,     117.,     121.,  &
+     &       160.,     196.,     272.,     322.,     296.,     389. /
+       ! 52-
+       ! --> 166m3/s
+       DATA inb(152)/1/
+       DATA (iirnf(jc,152),jc=1,jpcoef)/53, 19*0 /
+       DATA (ijrnf(jc,152),jc=1,jpcoef)/252, 19*0 /
+       DATA (zrnfm(jm,152),jm=1,jpmois)/  &
+     &      136.,     140.,     192.,     169.,     108.,      80.,  &
+     &      75.,     145.,     200.,     219.,     221.,     307. /
+       ! 53-Tigris+Euphrates (Irak) 31N00  47E25
+       ! --> 4762m3/s
+       DATA inb(153)/3/
+       DATA (iirnf(jc,153),jc=1,jpcoef)/ 673, 673, 674, 17*0 /
+       DATA (ijrnf(jc,153),jc=1,jpcoef)/ 312, 313, 313, 17*0 /
+       DATA (zrnfm(jm,153),jm=1,jpmois)/  &
+     &       6056.,    7229.,    8377.,    8505.,    7966.,    6217.,  &
+     &       3396.,    1898.,    1147.,     869.,    1714.,    3779. /
+
+       DATA (inb(jr),jr=154,200)/47*0/
+
+
+      !  Total run-offs(VII)=6181.33301m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+      !                                      = 1.588668056E-6 kg/m2/s
+      !                                      = 17883.5586 km3/Year
+      !                                      = 0.567083955 Sverdrup
+
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca05'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+ !!! better but change the results      i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+         i15 = nday / 16
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         END IF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                     DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                           &          + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                           &          +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! ji,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr)), mi1(iirnf(jl,jr))
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     DO jj = mj0(ijrnf(jl,jr)), mj1(ijrnf(jl,jr))
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) - 1), mi1(iirnf(jl,jr) - 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr)    ), mi1(iirnf(jl,jr)    )
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr)    ), mi1(iirnf(jl,jr)    )
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) + 1), mi1(iirnf(jl,jr) + 1)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     DO jj = mj0(ijrnf(jl,jr)    ), mj1(ijrnf(jl,jr)    )
+                        DO ji = mi0(iirnf(jl,jr) + 2), mi1(iirnf(jl,jr) + 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     DO jj = mj0(ijrnf(jl,jr)    ), mj1(ijrnf(jl,jr)    )
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     DO jj = mj0(ijrnf(jl,jr) - 2), mj1(ijrnf(jl,jr) - 2)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     DO jj = mj0(ijrnf(jl,jr) + 2), mj1(ijrnf(jl,jr) + 2)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     DO jj = mj0(ijrnf(jl,jr) - 1), mj1(ijrnf(jl,jr) - 1)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     DO jj = mj0(ijrnf(jl,jr) + 1), mj1(ijrnf(jl,jr) + 1)
+                        DO ji = mi0(iirnf(jl,jr) - 2), mi1(iirnf(jl,jr) - 2)
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = zrup1
+            upsrnfz(2)   = zrup1
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+         ENDIF
+      ENDIF
+    
+#endif
+
+   END SUBROUTINE flx_rnf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R2.h90	(revision 4536)
@@ -0,0 +1,1319 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flxrnf_ORCA_R2.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                  OLD ORCA R2 runoff specification
+   !!                      kept here for memory
+   !!                         ( 20/04/2000 )
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER :: kt
+      INTEGER, PARAMETER ::   &
+         jpmois =  12,        &  ! number of months
+         jpriv  = 120,        &  ! maximum number of river
+         jpcoef = 300            ! maximum of river mouth grid-points
+      INTEGER ::   &
+         ji, jj, jl, jm,      &  ! dummy loop indices
+         jn, jr, jc              !    "         "
+      INTEGER ::   &
+         i15, imois, iman,    &  ! temporary integers
+         inbp, idbd, idmeom,  &  !    "          "
+         iipt0, iipt1, ijpt0, &  !    "          "
+         ijpt1, ii, ij           !    "          "
+      INTEGER, DIMENSION(jpriv) ::   &
+         inb                     ! ???
+      INTEGER, DIMENSION(jpcoef,jpriv) ::   &
+         iirnf, ijrnf            ! ???
+
+      REAL(wp) ::   &
+         zconv, zxy,          &  ! temporary scalars
+         zrup1, zrup2, zrup3     !    "         "
+      REAL(wp), DIMENSION(jpmois,jpriv) ::   &
+         zrnfm                   ! ???
+      REAL(wp), DIMENSION(jpi, jpj, 5) ::   &
+         zcoefr                  ! ???
+
+      ! ====
+      ! DATA
+      ! ====
+
+      ! I NORTH AMERICA
+      ! ---------------
+
+      ! 1-Saint Lawrence (Canada) 49N30 67W00               R2
+      ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+      ! --> 13975.249m3/s
+      DATA inb(1)/2/
+      DATA (iirnf(jc,1),jc=1,jpcoef)/ 110, 110, 298*0 /
+      DATA (ijrnf(jc,1),jc=1,jpcoef)/ 110, 111, 298*0 /
+      DATA (zrnfm(jm,1),jm=1,jpmois)/   &
+          11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+          14211.,  13119.,  13367.,  13644.,  13463.,  12594./
+      ! 2-Hudson River (USA) 41N00 77W00                    R1
+      ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+      ! --> 407.416687m3/s
+      DATA inb(2)/1/
+      DATA (iirnf(jc,2),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (ijrnf(jc,2),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,2),jm=1,jpmois)/   &
+          364.,    404.,    648.,    873.,    593.,    301.,   &
+          205.,    171.,    205.,    290.,    379.,    456./
+      ! 3-Missisipi and Atchafalaya (USA) 29N 90W           R1 
+      ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+      ! --> 17599.334m3/s
+      DATA inb(3)/2/
+      DATA (iirnf(jc,3),jc=1,jpcoef)/  97, 98, 298*0 /
+      DATA (ijrnf(jc,3),jc=1,jpcoef)/  97, 97, 298*0 /
+      DATA (zrnfm(jm,3),jm=1,jpmois)/   &
+          19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+          14181.,  10676.,   9578.,  10167.,  11699.,  17472./
+      ! 4-Brazos (USA) 29N58 95W53                          R1
+      ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+      ! --> 199.666656m3/s
+      DATA inb(4)/1/
+      DATA (iirnf(jc,4),jc=1,jpcoef)/  95, 299*0 /
+      DATA (ijrnf(jc,4),jc=1,jpcoef)/  97, 299*0 /
+      DATA (zrnfm(jm,4),jm=1,jpmois)/   &
+          165.,    224.,    200.,    266.,    457.,    327.,   &
+          143.,     69.,    102.,    132.,    160.,    151./
+      ! 5-Colorado (Mexico) 31N54 114W57                    R5
+      ! Old=20 km3/year=634m3/s
+      ! --> 634.m3/s
+      DATA inb(5)/1/
+      DATA (iirnf(jc,5),jc=1,jpcoef)/  88, 299*0 /
+      DATA (ijrnf(jc,5),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,5),jm=1,jpmois)/12*634./ 
+      ! 6-Columbia (USA) 45N60 121W17                       R1
+      ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+      ! --> 5368.41602m3/s
+      DATA inb(6)/1/
+      DATA (iirnf(jc,6),jc=1,jpcoef)/  79, 299*0 /
+      DATA (ijrnf(jc,6),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (zrnfm(jm,6),jm=1,jpmois)/   &
+          4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+          6350.,    4112.,    3273.,    3251.,    3548.,    4106./ 
+      ! 7-Fraser (USA)                                      R5
+      ! Old=112 km3/year=3550m3/s;not found in UNESCO
+      ! --> 3549.99976m3/s
+      DATA inb(7)/1/
+      DATA (iirnf(jc,7),jc=1,jpcoef)/  77, 299*0 /
+      DATA (ijrnf(jc,7),jc=1,jpcoef)/ 112, 299*0 /
+      DATA (zrnfm(jm,7),jm=1,jpmois)/12*3550./ 
+      ! 8-Yukon (USA) 63N00 165W00                          R3
+      ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+      ! --> 6017.24951m3/s
+      DATA inb(8)/1/
+      DATA (iirnf(jc,8),jc=1,jpcoef)/  58, 299*0 /
+      DATA (ijrnf(jc,8),jc=1,jpcoef)/ 122, 299*0 /
+      DATA (zrnfm(jm,8),jm=1,jpmois)/   &
+           1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+          10680.,   11271.,    8658.,    5453.,    2649.,    1917./ 
+     ! 9-Copper (USA) 61N47 144W45                          R2
+     ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+     ! --> 1236.25m3/s
+      DATA inb(9)/1/
+      DATA (iirnf(jc,9),jc=1,jpcoef)/  67, 299*0 /
+      DATA (ijrnf(jc,9),jc=1,jpcoef)/ 119, 299*0 /
+      DATA (zrnfm(jm,9),jm=1,jpmois)/   &
+           219.,    195.,    181.,    214.,    904.,   2532.,   &
+          4026.,   3627.,   1632.,    697.,    354.,    254./ 
+      ! 10-Susitna (USA)                                    R5
+      ! Old=40 km3/year=1268m3/s
+      ! --> 1268.m3/s
+      DATA inb(10)/1/
+      DATA (iirnf(jc,10),jc=1,jpcoef)/  65, 299*0 /
+      DATA (ijrnf(jc,10),jc=1,jpcoef)/ 118, 299*0 /
+      DATA (zrnfm(jm,10),jm=1,jpmois)/12*1268./ 
+      ! 11-McKenzie (Canada) 70N00 135W00                   R3
+      ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+      ! ratio=1.16
+      ! --> 9606.66797m3/s
+      DATA inb(11)/1/
+      DATA (iirnf(jc,11),jc=1,jpcoef)/  69, 299*0 /
+      DATA (ijrnf(jc,11),jc=1,jpcoef)/ 131, 299*0 /
+      DATA (zrnfm(jm,11),jm=1,jpmois)/   &
+           3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+          18954.,   15487.,   11284.,   10169.,    5901.,    3905./
+      ! 12-Kuksokwim (USA) 60N00 ~162W30                    R4
+      ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+      ! --> 1111.99988m3/s
+      DATA inb(12)/1/
+      DATA (iirnf(jc,12),jc=1,jpcoef)/  60, 299*0 /
+      DATA (ijrnf(jc,12),jc=1,jpcoef)/ 118, 299*0 /
+      DATA (zrnfm(jm,12),jm=1,jpmois)/   &
+          335.,     308.,     295.,     407.,    2415.,    2027.,   &
+          1917.,   2049.,    1585.,    1072.,     545.,     389./     
+
+      DATA inb(13)/0/
+      DATA inb(14)/0/
+      DATA inb(15)/0/
+
+      ! Total run-offs(I)=60974.2539m3/s
+
+      ! II SOUTH AMERICA
+      ! -----------------
+      ! 16-Chira (Peru) 4s54 81w08                          R2
+      ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+      ! --> 158.000015m3/s
+      DATA inb(16)/1/
+      DATA (iirnf(jc,16),jc=1,jpcoef)/ 101, 299*0 /
+      DATA (ijrnf(jc,16),jc=1,jpcoef)/  66, 299*0 /
+      DATA (zrnfm(jm,16),jm=1,jpmois)/   &
+          70.,     105.,     564.,     582.,     230.,      94.,   &
+          87.,      47.,      35.,      32.,      29.,      21./
+      ! 17-Magdalena (Colombia) 11N06 74W51                 R2
+      ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+      ! ratio=1.08
+      ! --> 7451.58301m3/s
+      DATA inb(17)/1/
+      DATA (iirnf(jc,17),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (ijrnf(jc,17),jc=1,jpcoef)/  86, 299*0 /
+      DATA (zrnfm(jm,17),jm=1,jpmois)/   &
+          6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+          8509.,    7428.,    7631.,    9296.,   10588.,    9949./
+      ! 18-Orinoco (Venezuela) 8N37 62W15!                  R1
+      ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+      ! HLA=26371m3/s
+      ! Data from HLA: 8.1N - 63.3W   1925/89
+      ! --> 26371.416
+      DATA inb(18)/1/
+      DATA (iirnf(jc,18),jc=1,jpcoef)/ 112, 299*0 /
+      DATA (ijrnf(jc,18),jc=1,jpcoef)/  86, 299*0 /
+      DATA (zrnfm(jm,18),jm=1,jpmois)/   &
+          10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+          43938.,   59957.,   57435.,   39951.,   27410.,   16567./ 
+      ! 19-Amazon (Brazil) 0S05 50W00                       R1
+      ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+      ! HLA=184806m3/s
+      ! UNESCO data are at Obidos which is far inland and therefore does not
+      ! fully represent the actual discharge
+      ! Data from HLA: 1.5N - 55.3W   1970/96
+      ! --> 184845.484m3/s
+      DATA inb(19)/2/
+      DATA (iirnf(jc,19),jc=1,jpcoef)/ 117, 117, 298*0 /
+      DATA (ijrnf(jc,19),jc=1,jpcoef)/  75,  76, 298*0 /
+      DATA (zrnfm(jm,19),jm=1,jpmois)/   &
+          152233., 176415., 199941., 225565., 244016., 244861.,   &
+          230711., 203128., 164531., 128486., 118214., 130045. /
+      ! 20-Sao Francisco (Brazil) 10S30 36W24               R1
+      ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+      ! --> 2645.3335m3/s
+      DATA inb(20)/1/
+      DATA (iirnf(jc,20),jc=1,jpcoef)/ 123, 299*0 /
+      DATA (ijrnf(jc,20),jc=1,jpcoef)/  59, 299*0 /
+      DATA (zrnfm(jm,20),jm=1,jpmois)/   &
+          3244.,   4116.,   5139.,   4330.,   2323.,   1800.,   &
+          1587.,   1511.,   1593.,   1740.,   2190.,   2171. /
+      ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18            R1 
+      ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+      ! --> 22203.168m3/s 
+      DATA inb(21)/2/
+      DATA (iirnf(jc,21),jc=1,jpcoef)/ 114, 114, 298*0 /
+      DATA (ijrnf(jc,21),jc=1,jpcoef)/  46,  47, 298*0 /
+      DATA (zrnfm(jm,21),jm=1,jpmois)/   &
+          24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+          22647.,   20403.,   19627.,   21400.,   21126.,   21923./
+      ! 22-Negro (Argentina)  41S02  62W47                  R2
+      ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+      ! --> 907.666687m3/s
+      DATA inb(22)/1/
+      DATA (iirnf(jc,22),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (ijrnf(jc,22),jc=1,jpcoef)/  43, 299*0 /
+      DATA (zrnfm(jm,22),jm=1,jpmois)/   &
+          882.,     587.,     519.,     482.,     623.,     984.,   &
+          1120.,   1294.,    1092.,    1166.,    1105.,    1038./
+     ! 23- Tocantins :  ~48W00 ~0.5S                        R4
+     ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+     ! --> 12173.082m3/s
+      DATA inb(23)/1/
+      DATA (iirnf(jc,23),jc=1,jpcoef)/118, 299*0 /
+      DATA (ijrnf(jc,23),jc=1,jpcoef)/ 73, 299*0 /
+      DATA (zrnfm(jm,23),jm=1,jpmois)/   &
+          15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+          4440.,   3082.,   2728.,   3417.,   5511.,  10705. /
+
+      DATA inb(24)/0/
+      DATA inb(25)/0/
+
+      ! Total run-offs(II)=256755.75
+      ! Total run-offs(I+II)=317730
+
+      ! III EUROPE
+      ! ----------
+      ! 26-Rhone (France) 43N20 4E50                        R1 
+      ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+      ! --> 1217.16663m3/s
+      DATA inb(26)/1/
+      DATA (iirnf(jc,26),jc=1,jpcoef)/ 150, 299*0 /
+      DATA (ijrnf(jc,26),jc=1,jpcoef)/ 108, 299*0 /
+      DATA (zrnfm(jm,26),jm=1,jpmois)/   &
+          1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+           937.,     796.,     794.,     962.,    1161.,    1233./
+      ! 27-Po (Italy) 11N10 1W09                            R1 
+      ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+      ! --> 1550.08337m3/s
+      DATA inb(27)/1/
+      DATA (iirnf(jc,27),jc=1,jpcoef)/ 159, 299*0 /
+      DATA (ijrnf(jc,27),jc=1,jpcoef)/ 110, 299*0 /
+      DATA (zrnfm(jm,27),jm=1,jpmois)/   &
+          1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+          1040.,    1007.,    1615.,    1907.,    1772.,    1228./
+      ! 28-Danube (Roumania) 45N20 29E40                    R1 
+      ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+      ! --> 7011.8335m3/s
+      DATA inb(28)/1/
+      DATA (iirnf(jc,28),jc=1,jpcoef)/ 171, 299*0 /
+      DATA (ijrnf(jc,28),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (zrnfm(jm,28),jm=1,jpmois)/   &
+          6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+          7586.,    6001.,    5210.,    4989.,    4921.,    6093./
+
+      DATA inb(29)/0/
+      DATA inb(30)/0/
+
+      ! Total run-offs(III)=9779.08301m3/s
+      ! Total run-offs(I+II+III)=327509.094m3/s
+
+      ! IV EURASIAN ARCTIC
+      ! ------------------
+      ! 31-Iana (Russia)                                    R1
+      ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+      ! --> 0m3/s
+      DATA inb(31)/0/
+      DATA (iirnf(jc,31),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,31),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,31),jm=1,jpmois)/   &
+             2.,       1.,       0.,       0.,     917.,    3514.,   &
+          2968.,    2329.,    1322.,     178.,      36.,       8./ 
+      ! 32-Ob (Russia) 66N45 69E30                          R1 
+      ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+      ! --> 12861.5m3/s
+      DATA inb(32)/2/
+      DATA (iirnf(jc,32),jc=1,jpcoef)/ 153, 153, 298*0 /
+      DATA (ijrnf(jc,32),jc=1,jpcoef)/ 146, 147, 298*0 /
+      DATA (zrnfm(jm,32),jm=1,jpmois)/   &
+           4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+          30773.,   22785.,   14701.,    9705.,    6078.,    5879./
+      ! 33-Yenesei (Russia) 71N50 82E40                     R1 
+      ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+      ! --> 17461.666m3/s
+      DATA inb(33)/1/
+      DATA (iirnf(jc,33),jc=1,jpcoef)/  32, 299*0 /
+      DATA (ijrnf(jc,33),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (zrnfm(jm,33),jm=1,jpmois)/   &
+           6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+          25325.,   15940.,   16050.,   12678.,    6741.,    6008./
+     ! 34-Severnaya Dvina(Russia)64N32 40E30                R5 
+     ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+     ! --> 3359.00024m3/s
+      DATA inb(34)/1/
+      DATA (iirnf(jc,34),jc=1,jpcoef)/ 153, 299*0 /
+      DATA (ijrnf(jc,34),jc=1,jpcoef)/ 133, 299*0 /
+      DATA (zrnfm(jm,34),jm=1,jpmois)/12*3359./
+      ! 35-Lena (Russia) 72N25 126E40                       R1 
+      ! --> 16192.333m3/s
+      DATA inb(35)/1/
+      DATA (iirnf(jc,35),jc=1,jpcoef)/  36, 299*0 /
+      DATA (ijrnf(jc,35),jc=1,jpcoef)/ 137, 299*0 /
+      DATA (zrnfm(jm,35),jm=1,jpmois)/   &
+           2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+          40810.,   28310.,   25995.,   13299.,    3673.,    3077./
+      ! 36-Kolyma (Russia) 69N30 161E00                     R1
+      ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+      ! --> 2138.66675m3/s
+      DATA inb(36)/1/
+      DATA (iirnf(jc,36),jc=1,jpcoef)/  46, 299*0 /
+      DATA (ijrnf(jc,36),jc=1,jpcoef)/ 128, 299*0 /
+      DATA (zrnfm(jm,36),jm=1,jpmois)/   &
+           131.,      92.,      76.,      65.,    2576.,    9143.,   &
+          4670.,    3727.,    3226.,    1119.,     630.,     209./
+     ! 37-Indigirka (russia) 70N48 148E54                   R1 
+     ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+     ! --> 1622.00012m3/s
+      DATA inb(37)/1/
+      DATA (iirnf(jc,37),jc=1,jpcoef)/  42, 299*0 /
+      DATA (ijrnf(jc,37),jc=1,jpcoef)/ 131, 299*0 /
+      DATA (zrnfm(jm,37),jm=1,jpmois)/   &
+            32.,      17.,      11.,       7.,     354.,    5629.,   &
+          5210.,    4617.,    2823.,     559.,     142.,      63./
+
+      DATA inb(38)/0/
+      DATA inb(39)/0/
+      DATA inb(40)/0/
+
+      ! Total run-offs(IV)=40773.6641m3/s
+      ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+      ! V ASIA
+      ! ------
+      ! 41-Amur (Russia) 52N56 141E10                       R2
+      ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+      ! --> 10299.332m3/s
+      DATA inb(41)/1/
+      DATA (iirnf(jc,41),jc=1,jpcoef)/  33, 299*0 /
+      DATA (ijrnf(jc,41),jc=1,jpcoef)/ 116, 299*0 /
+      DATA (zrnfm(jm,41),jm=1,jpmois)/   &
+           2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+          16100.,   20801.,   21548.,   15658.,    5188.,    2506./
+      ! 42-Liaohe (China) 40N40 122E09                      R5
+      ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+      ! --> 189.999985m3/s
+      DATA inb(42)/1/
+      DATA (iirnf(jc,42),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,42),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,42),jm=1,jpmois)/12*190./
+      ! 43-Daling (China) 40N56 121E43                      R5
+      ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+      ! --> 31.9999962m3/s
+      DATA inb(43)/1/
+      DATA (iirnf(jc,43),jc=1,jpcoef)/  24, 299*0 /
+      DATA (ijrnf(jc,43),jc=1,jpcoef)/ 104, 299*0 /
+      DATA (zrnfm(jm,43),jm=1,jpmois)/12*32./
+      ! 44-Haiho (China) 6N17   1E23
+      ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+      ! --> 63.9999924m3/s
+      DATA inb(44)/1/
+      DATA (iirnf(jc,44),jc=1,jpcoef)/  28, 299*0 /
+      DATA (ijrnf(jc,44),jc=1,jpcoef)/ 106, 299*0 /
+      DATA (zrnfm(jm,44),jm=1,jpmois)/12*64./
+      ! 45-Yellow/Huangho (China) 37N32 118E19              R2 
+      ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+      ! --> 1552.5m3/s
+      DATA inb(45)/1/
+      DATA (iirnf(jc,45),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,45),jc=1,jpcoef)/ 103, 299*0 /
+      DATA (zrnfm(jm,45),jm=1,jpmois)/   &
+           697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+          1964.,    3270.,    3668.,    2133.,     978.,     871./
+      ! 46-Yangtze (China) 31N48 121E10=Changjiang          R2
+      ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+      ! --> 28519.584m3/s
+      DATA inb(46)/1/
+      DATA (iirnf(jc,46),jc=1,jpcoef)/  23, 299*0 /
+      DATA (ijrnf(jc,46),jc=1,jpcoef)/  98, 299*0 /
+      DATA (zrnfm(jm,46),jm=1,jpmois)/   &
+          10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+          53891.,   42070.,   37627.,   30762.,   22046.,   12777./
+      ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang      R2 
+      ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+      ! --> 9570.75m3/s
+      DATA inb(47)/1/
+      DATA (iirnf(jc,47),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,47),jc=1,jpcoef)/  95, 299*0 /
+      DATA (zrnfm(jm,47),jm=1,jpmois)/   &
+           2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+          19213.,   17558.,   12312.,    7255.,    5864.,    6154./
+      ! 48-Red/Hungho (Vietnam) 20N17 106E34                R5 
+      ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+      ! --> 3897.m3/s
+      DATA inb(48)/1/
+      DATA (iirnf(jc,48),jc=1,jpcoef)/  16, 299*0 /
+      DATA (ijrnf(jc,48),jc=1,jpcoef)/  91, 299*0 /
+      DATA (zrnfm(jm,48),jm=1,jpmois)/12*3897./
+      ! 49-Mekong (Vietnam) 10N33 105E24                    R5
+      ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+      ! --> 14893.0029m3/s
+      DATA inb(49)/2/
+      DATA (iirnf(jc,49),jc=1,jpcoef)/  16,  16, 298*0 /
+      DATA (ijrnf(jc,49),jc=1,jpcoef)/  86,  87, 298*0 /
+      DATA (zrnfm(jm,49),jm=1,jpmois)/12*14893./
+      ! 50-Irrawady (Burma) 15N50  95E06                    R5
+      ! Old=428 km3/year=13563m3/s; not in UNESCO data base
+      ! --> 13563.m3/s
+      DATA inb(50)/1/
+      DATA (iirnf(jc,50),jc=1,jpcoef)/  10, 299*0 /
+      DATA (ijrnf(jc,50),jc=1,jpcoef)/  90, 299*0 /
+      DATA (zrnfm(jm,50),jm=1,jpmois)/12*13563./
+      ! 51-Ganges+Brahmaputra (Beng.) 22N00  91E00          R1
+      ! Old=971 km3/year=30769m3/s; UNESCO(69-70+73-75, p367)=31760m3/s
+      ! --> 32147.498m3/s
+      DATA inb(51)/2/
+      DATA (iirnf(jc,51),jc=1,jpcoef)/   7,  8, 298*0 /
+      DATA (ijrnf(jc,51),jc=1,jpcoef)/  93, 93, 298*0 /
+      DATA (zrnfm(jm,51),jm=1,jpmois)/   &
+           6623.,    6315.,    6432.,    9410.,   17263.,   38302.,   &
+          64688.,   80338.,   84802.,   43387.,   17888.,   10322./
+      ! 52-Mehandi (India)                                  R5
+      ! Old=67 km3/year=2123m3/s; not in UNESCO data base
+      ! --> 0m3/s
+      DATA inb(52)/0/
+      DATA (iirnf(jc,52),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,52),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,52),jm=1,jpmois)/12*2123./
+      ! 53-Damodar (India)                                  R2
+      ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+      ! --> 432.916656m3/s
+      DATA inb(53)/1/
+      DATA (iirnf(jc,53),jc=1,jpcoef)/   6, 299*0 /
+      DATA (ijrnf(jc,53),jc=1,jpcoef)/  93, 299*0 /
+      DATA (zrnfm(jm,53),jm=1,jpmois)/   &
+           51.,      37.,      42.,      49.,      85.,     296.,   &
+          896.,    1390.,    1591.,     542.,     172.,      44./   
+      ! 54-Godavari (India) 17N00  81E45                    R2
+      ! Old=84 km3/year=2662m3/s; UNESCO(p379)=1916m3/s; ratio=1.39
+      ! --> 3670.5m3/s
+      DATA inb(54)/1/
+      DATA (iirnf(jc,54),jc=1,jpcoef)/   3, 299*0 /
+      DATA (ijrnf(jc,54),jc=1,jpcoef)/  90, 299*0 /
+      DATA (zrnfm(jm,54),jm=1,jpmois)/   &
+           988.,     737.,     280.,     219.,     196.,    1691.,   &
+          8063.,   14571.,   11428.,    3953.,    1221.,     699./   
+     ! 55-Indus (Pakistan) 24N20  67E47                     R2
+     ! Old=238 km3/year=7542m3/s; UNESCO (76-79, p428)=2396m3/s; ratio=3.15
+     ! --> 7562.m3/s
+      DATA inb(55)/2/
+      DATA (iirnf(jc,55),jc=1,jpcoef)/ 176, 176, 298*0 /
+      DATA (ijrnf(jc,55),jc=1,jpcoef)/  93,  94, 298*0 /
+      DATA (zrnfm(jm,55),jm=1,jpmois)/   &
+            988.,     737.,    1904.,    1968.,    3625.,    6143.,   &
+          15969.,    36656.,  17173.,    3215.,    1251.,    1115./   
+      ! 56-Tigris and Euphrates (Iraq) 31N00  47E25         R1
+      ! Old=46 km3/year=1458m3/s; UNESCO(76-79, p428)=2396m3/s
+      ! --> 2248.8335m3/s
+      DATA inb(56)/1/
+      DATA (iirnf(jc,56),jc=1,jpcoef)/ 172, 299*0 /
+      DATA (ijrnf(jc,56),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,56),jm=1,jpmois)/   &
+          1872.,    2127.,    2962.,    4944.,    5036.,    3078.,   &
+          1362.,     900.,     786.,     993.,    1184.,    1742./   
+
+      DATA inb(57)/0/
+      DATA inb(58)/0/
+      DATA inb(59)/0/
+      DATA inb(60)/0/
+
+      ! Total run-offs (V)=128642.922m3/s
+      ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+      
+      ! VI AFRICA
+      ! ----------
+      ! 61-Nile (Egypt) 30N10  31E06                        R1
+      ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+      ! --> 1251.33337m3/s
+      DATA inb(61)/1/
+      DATA (iirnf(jc,61),jc=1,jpcoef)/ 176, 299*0 /
+      DATA (ijrnf(jc,61),jc=1,jpcoef)/  97, 299*0 /
+      DATA (zrnfm(jm,61),jm=1,jpmois)/   &
+          1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+          1742.,    1559.,    1191.,    1103.,    1075.,    1124./   
+      ! 62-Niger (Nigeria) 5N33   6E33                      R1
+      ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+      ! Data from HLA: 4.5N -  6  E   1950/87
+      ! --> 5545.08301m3/s
+      DATA inb(62)/1/
+      DATA (iirnf(jc,62),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,62),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,62),jm=1,jpmois)/   &
+          2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+          5272.,    9629.,   14951.,   16227.,    6842.,    2741./   
+      ! 63-Zaire/Congo (Congo) 6S04  12E24                  R1      
+      ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+      ! =39720m3/s
+      ! Data from HLA: 6S - 12  E   1902/96
+      ! --> 39719.5m3/s
+      DATA inb(63)/2/
+      DATA (iirnf(jc,63),jc=1,jpcoef)/ 148, 148, 298*0 /
+      DATA (ijrnf(jc,63),jc=1,jpcoef)/  63,  64, 298*0 /
+      DATA (zrnfm(jm,63),jm=1,jpmois)/   &
+          47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+          30966.,   30774.,   35981.,   42825.,   51455.,   55314./  
+      ! 64-Orange (Sth Africa) 28S41 16E28                  R5
+      ! Old=11 km3/year=349m3/s
+      ! --> 349.000031m3/s
+      DATA inb(64)/1/
+      DATA (iirnf(jc,64),jc=1,jpcoef)/ 150, 299*0 /
+      DATA (ijrnf(jc,64),jc=1,jpcoef)/  51, 299*0 /
+      DATA (zrnfm(jm,64),jm=1,jpmois)/12*349./
+      ! 65-Zambesi (Mozambique) 18S55 36E04                 R5
+      ! Old=223 km3/year=7066m3/s
+      ! --> 7066.00049m3/s
+      DATA inb(65)/1/
+      DATA (iirnf(jc,65),jc=1,jpcoef)/ 160, 299*0 /
+      DATA (ijrnf(jc,65),jc=1,jpcoef)/  56, 299*0 /
+      DATA (zrnfm(jm,65),jm=1,jpmois)/12*7066./
+      ! 66-Limpopo (mozambique) 25S15 33E30                 R5
+      ! Old=5 km3/year=158m3/s
+      ! --> 158.m3/s
+      DATA inb(66)/1/
+      DATA (iirnf(jc,66),jc=1,jpcoef)/ 159, 299*0 /
+      DATA (ijrnf(jc,66),jc=1,jpcoef)/  52, 299*0 /
+      DATA (zrnfm(jm,66),jm=1,jpmois)/12*158./
+      ! 67-Rufiji (tanzania) 8S00 39E20                     R5
+      ! Old=9 km3/year=285m3/s
+      ! --> 285.m3/s
+      DATA inb(67)/1/
+      DATA (iirnf(jc,67),jc=1,jpcoef)/ 162, 299*0 /
+      DATA (ijrnf(jc,67),jc=1,jpcoef)/  62, 299*0 /
+      DATA (zrnfm(jm,67),jm=1,jpmois)/12*285./
+      ! Other rivers from the Gulf of Guinea
+      ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)         R1
+      ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+      ! --> 924.25m3/s
+      DATA inb(68)/1/
+      DATA (iirnf(jc,68),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (ijrnf(jc,68),jc=1,jpcoef)/  67, 299*0 /
+      DATA (zrnfm(jm,68),jm=1,jpmois)/   &
+          1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+           480.,     378.,     327.,     400.,    1018.,    1281./
+      ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)              R1
+      ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+      ! --> 264.166687m3/s
+      DATA inb(69)/1/
+      DATA (iirnf(jc,69),jc=1,jpcoef)/ 147, 299*0 /
+      DATA (ijrnf(jc,69),jc=1,jpcoef)/  68, 299*0 /
+      DATA (zrnfm(jm,69),jm=1,jpmois)/   &
+          126.,      99.,     143.,     253.,     316.,     300.,   &
+          156.,      93.,     231.,     557.,     592.,     304./
+      ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)                R1
+      ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+      ! --> 4511.83301m3/s
+      DATA inb(70)/1/
+      DATA (iirnf(jc,70),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,70),jc=1,jpcoef)/  72, 299*0 /
+      DATA (zrnfm(jm,70),jm=1,jpmois)/   &
+          4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+          2616.,    1961.,    2119.,    4304.,    7870.,    6810./
+      ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)        R1
+      ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+      ! --> 1982.58337m3/s
+      DATA inb(71)/1/
+      DATA (iirnf(jc,71),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,71),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,71),jm=1,jpmois)/   &
+           813.,     578.,     517.,     633.,     909.,    1278.,   &
+          1928.,    2653.,    4361.,    5470.,    3307.,    1344./
+      ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)         R1
+      ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+      ! --> 431.166656m3/s      
+      DATA inb(72)/1/
+      DATA (iirnf(jc,72),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,72),jc=1,jpcoef)/  80, 299*0 /
+      DATA (zrnfm(jm,72),jm=1,jpmois)/   &
+          232.,     128.,     150.,     266.,     402.,     459.,   &
+          353.,     306.,     604.,     930.,     878.,     466./
+      ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)          R1
+      ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+      ! --> 329.75m3/s
+      DATA inb(73)/1/
+      DATA (iirnf(jc,73),jc=1,jpcoef)/ 146, 299*0 /
+      DATA (ijrnf(jc,73),jc=1,jpcoef)/  79, 299*0 /
+      DATA (zrnfm(jm,73),jm=1,jpmois)/   &
+          452.,     455.,     492.,     466.,     482.,     251.,   &
+          151.,     108.,      87.,     133.,     395.,     485./
+      ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)           R1
+      ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+      ! --> 306.583374m3/s
+      DATA inb(74)/1/
+      DATA (iirnf(jc,74),jc=1,jpcoef)/ 145, 299*0 /
+      DATA (ijrnf(jc,74),jc=1,jpcoef)/  81, 299*0 /
+      DATA (zrnfm(jm,74),jm=1,jpmois)/   &
+           88.,      63.,      68.,      95.,     139.,     222.,   &
+          395.,     633.,     825.,     675.,     328.,     148./
+      ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)            R1
+      ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+      ! --> 112.666664m3/s
+      DATA inb(75)/1/
+      DATA (iirnf(jc,75),jc=1,jpcoef)/ 144, 299*0 /
+      DATA (ijrnf(jc,75),jc=1,jpcoef)/  83, 299*0 /
+      DATA (zrnfm(jm,75),jm=1,jpmois)/   &
+           0.,       0.,       0.,       0.,       1.,      18.,   &
+          96.,     324.,     531.,     319.,      58.,       5./
+      ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27)     R1
+      ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+      ! --> 96.4999924m3/s
+      DATA inb(76)/1/
+      DATA (iirnf(jc,76),jc=1,jpcoef)/ 143, 299*0 /
+      DATA (ijrnf(jc,76),jc=1,jpcoef)/  83, 299*0 /
+      DATA (zrnfm(jm,76),jm=1,jpmois)/   &
+            2.,       1.,       1.,       4.,       8.,      44.,   &
+          168.,     274.,     386.,     215.,      47.,       8./
+      ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)          R1
+      ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+      ! --> 194.25m3/s
+      DATA inb(77)/1/
+      DATA (iirnf(jc,77),jc=1,jpcoef)/ 140, 299*0 /
+      DATA (ijrnf(jc,77),jc=1,jpcoef)/  82, 299*0 /
+      DATA (zrnfm(jm,77),jm=1,jpmois)/   &
+           14.,       7.,       9.,      17.,      29.,      90.,   &
+          145.,     349.,     740.,     688.,     198.,      45./
+      ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)      R1
+      ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+      ! --> 449.333344m3/s
+      DATA inb(78)/1/
+      DATA (iirnf(jc,78),jc=1,jpcoef)/ 139, 299*0 /
+      DATA (ijrnf(jc,78),jc=1,jpcoef)/  82, 299*0 /
+      DATA (zrnfm(jm,78),jm=1,jpmois)/   &
+          144.,     116.,     119.,     143.,     156.,     334.,   &
+          419.,     692.,    1277.,    1190.,     553.,     249./
+
+      DATA inb(79)/0/
+      DATA inb(80)/0/
+      DATA inb(82)/0/
+      DATA inb(83)/0/
+      DATA inb(84)/0/
+      DATA inb(85)/0/
+      DATA inb(86)/0/
+      DATA inb(87)/0/
+      DATA inb(88)/0/
+      DATA inb(89)/0/
+      DATA inb(90)/0/
+
+      ! Total run-offs (VI)=63977.m3/s
+      ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+      
+      ! VII OCEANIA
+      ! ------------
+      ! 91-Murray (Austrlia) 35S34 138E54                   R5
+      ! Old=22 km3/year=697m3/s
+      ! --> 696.999939m3/s
+      DATA inb(91)/1/
+      DATA (iirnf(jc,91),jc=1,jpcoef)/  30, 299*0 /
+      DATA (ijrnf(jc,91),jc=1,jpcoef)/  47, 299*0 /
+      DATA (zrnfm(jm,91),jm=1,jpmois)/12*697./
+      ! 92-Haast (N. Zeland) 43S50 169E02                   R5
+      ! Old=6 km3/year=190m3/s
+      ! --> 189.999985m3/s
+      DATA inb(92)/1/
+      DATA (iirnf(jc,92),jc=1,jpcoef)/  48, 299*0 /
+      DATA (ijrnf(jc,92),jc=1,jpcoef)/  41, 299*0 /
+      DATA (zrnfm(jm,92),jm=1,jpmois)/12*190./
+      ! 93-Fly (N. Guinea) 8S30 143E05                      R5
+      ! Old=77 km3/year=2440m3/s
+      ! --> 2440.m3/s
+      DATA inb(93)/1/
+      DATA (iirnf(jc,93),jc=1,jpcoef)/  34, 299*0 /
+      DATA (ijrnf(jc,93),jc=1,jpcoef)/  62, 299*0 /
+      DATA (zrnfm(jm,93),jm=1,jpmois)/12*2440./
+      ! 94-Purari (N. Guinea) 7S25 145E05                   R4
+      ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+      ! --> 2727.33325m3/s
+      DATA inb(94)/1/
+      DATA (iirnf(jc,94),jc=1,jpcoef)/  36, 299*0 /
+      DATA (ijrnf(jc,94),jc=1,jpcoef)/  64, 299*0 /
+      DATA (zrnfm(jm,94),jm=1,jpmois)/   &
+          1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+          2867.,    3477.,    2195.,    2967.,    2674.,    2627./
+      ! 95-Choshui ch''i (taiwan) 24N03 120E23              R2
+      ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+      ! --> 0.m3/s
+      DATA inb(95)/0/
+      DATA (iirnf(jc,95),jc=1,jpcoef)/  22, 299*0 /
+      DATA (ijrnf(jc,95),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,95),jm=1,jpmois)/   &
+           65.,      63.,      83.,     100.,     177.,     535.,   &
+          332.,     313.,     236.,     193.,     101.,      84./
+      ! 96-Kaoping (Taiwan)                                 R5  
+      ! Old=9 km3/year=285m3/s
+      ! --> 0.m3/s
+      DATA inb(96)/0/
+      DATA (iirnf(jc,96),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,96),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,96),jm=1,jpmois)/12*285./
+      ! 97-Tsengwen (Taiwan)                                R5
+      ! Old=2 km3/year=63m3/s
+      ! --> 0.m3/s
+      DATA inb(97)/0/
+      DATA (iirnf(jc,97),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,97),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,97),jm=1,jpmois)/12*63./
+      ! 98-Hualien (Taiwan)                                 R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(98)/0/
+      DATA (iirnf(jc,98),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,98),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,98),jm=1,jpmois)/12*127./
+      ! 99-Peinan (Taiwan) 22N46 121E10                     R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 127.000008m3/s
+      DATA inb(99)/1/
+      DATA (iirnf(jc,99),jc=1,jpcoef)/  23, 299*0 /
+      DATA (ijrnf(jc,99),jc=1,jpcoef)/  94, 299*0 /
+      DATA (zrnfm(jm,99),jm=1,jpmois)/12*127./
+      ! 100-Hsiukuluan (Taiwan)                             R5
+      ! Old=4 km3/year=127m3/s
+      ! --> 0.m3/s
+      DATA inb(100)/0/
+      DATA (iirnf(jc,100),jc=1,jpcoef)/ 300*0 /
+      DATA (ijrnf(jc,100),jc=1,jpcoef)/ 300*0 /
+      DATA (zrnfm(jm,100),jm=1,jpmois)/12*127./
+
+      DATA inb(101)/0/
+      DATA inb(102)/0/
+
+      !  Total run-offs(VII)=6181.33301m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+      !                                      = 1.588668056E-6 kg/m2/s
+      !                                      = 17883.5586 km3/Year
+      !                                      = 0.567083955 Sverdrup
+
+      ! VIII ANTARCTICA
+      ! ---------------
+      ! 103 -Antarcti! ice discharge (2 613 Gt/year) (jacobs et al 1992)
+      ! Data from Jacobs et al 92: =2613 km3/year=82857.686454 m3/s
+      ! --> 82858 m3/s
+      DATA inb(103)/295/
+      DATA (iirnf(jc,103),jc=1,jpcoef)/   &
+            1,    2,    3,    3,    4,    4,    5,    6,    7,    8,   &
+            9,    9,   10,   11,   12,   13,   14,   14,   15,   16,   &
+           17,   18,   19,   20,   21,   22,   23,   24,   25,   26,   &
+           27,   28,   29,   30,   31,   32,   32,   33,   34,   35,   &
+           35,   36,   36,   37,   38,   39,   40,   40,   41,   42,   &
+           42,   43,   43,   44,   44,   44,   44,   44,   44,   44,   &
+           45,   45,   45,   45,   46,   46,   46,   46,   46,   47,   &
+           47,   47,   47,   47,   48,   48,   48,   48,   48,   49,   &
+           50,   51,   51,   52,   53,   54,   55,   56,   57,   58,   &
+           59,   60,   61,   62,   62,   63,   63,   64,   65,   66,   &
+           66,   67,   67,   68,   69,   69,   70,   71,   71,   72,   &
+           73,   73,   74,   75,   76,   76,   77,   78,   78,   79,   &
+           80,   81,   82,   83,   83,   84,   85,   86,   87,   88,   &
+           88,   89,   89,   90,   91,   92,   93,   94,   95,   96,   &
+           97,   98,   99,  100,  101,  102,  102,  103,  104,  104,   &
+          104,  104,  104,  105,  105,  106,  106,  107,  107,  107,   &
+          108,  108,  109,  109,  110,  110,  111,  111,  112,  112,   &
+          112,  112,  112,  112,  112,  112,  112,  112,  112,  112,   &
+          112,  112,  112,  112,  112,  113,  113,  113,  113,  113,   &
+          114,  114,  114,  114,  115,  115,  115,  115,  115,  116,   &
+          116,  117,  117,  118,  118,  119,  119,  120,  121,  122,   &
+          123,  124,  124,  125,  125,  126,  126,  127,  128,  128,   &
+          129,  130,  130,  131,  132,  132,  133,  133,  133,  133,   &
+          133,  134,  135,  135,  136,  136,  136,  137,  137,  138,   &
+          139,  140,  141,  142,  142,  143,  144,  145,  146,  147,   &
+          148,  149,  150,  151,  152,  153,  154,  155,  156,  156,   &
+          157,  158,  159,  160,  161,  161,  162,  163,  163,  164,   &
+          165,  165,  166,  166,  167,  168,  169,  170,  171,  171,   &
+          172,  173,  173,  174,  175,  176,  177,  177,  178,  178,   &
+          179,  180,  180,  181,  181,    0,    0,    0,    0,    0    &
+                                      /
+      DATA (ijrnf(jc,103),jc=1,jpcoef)/   &
+           19,   20,   20,   21,   21,   22,   22,   22,   22,   22,   &
+           22,   23,   23,   23,   23,   23,   22,   23,   22,   22,   &
+           22,   22,   22,   22,   22,   22,   22,   22,   22,   22,   &
+           22,   22,   22,   22,   22,   21,   22,   21,   21,   20,   &
+           21,   19,   20,   19,   19,   19,   18,   19,   18,   17,   &
+           18,   16,   17,    3,    4,    5,    6,    7,    8,   16,   &
+            3,    8,    9,   16,    3,    9,   10,   15,   16,    3,   &
+           10,   11,   14,   15,    3,   11,   12,   13,   14,    3,   &
+            3,    2,    3,    2,    2,    2,    2,    2,    2,    2,   &
+            2,    2,    2,    2,    3,    3,    4,    4,    4,    4,   &
+            5,    5,    6,    6,    6,    7,    7,    7,    8,    8,   &
+            8,    9,    9,    9,    9,   10,   10,   10,   11,   11,   &
+           11,   11,   11,   10,   11,   10,   10,   10,   10,   10,   &
+           11,   11,   12,   12,   12,   12,   12,   12,   12,   12,   &
+           12,   12,   12,   12,   12,   12,   13,   13,   13,   14,   &
+           15,   16,   17,   17,   18,   18,   19,   19,   20,   21,   &
+           21,   22,   22,   23,   23,   24,   24,   25,    8,    9,   &
+           10,   11,   12,   13,   14,   15,   16,   17,   18,   19,   &
+           20,   21,   22,   25,   26,    7,    8,   22,   23,   26,   &
+            7,   23,   24,   26,    6,    7,   24,   25,   26,    5,   &
+            6,    4,    5,    3,    4,    2,    3,    2,    2,    2,   &
+            2,    2,    3,    3,    4,    4,    5,    5,    5,    6,   &
+            6,    6,    7,    7,    7,    8,    8,    9,   10,   11,   &
+           12,   12,   12,   13,   13,   14,   15,   15,   16,   16,   &
+           16,   16,   16,   16,   17,   17,   17,   17,   17,   17,   &
+           17,   17,   17,   17,   17,   17,   17,   17,   17,   18,   &
+           18,   18,   18,   18,   18,   19,   19,   19,   20,   20,   &
+           20,   21,   21,   22,   22,   22,   22,   22,   21,   22,   &
+           21,   20,   21,   20,   20,   20,   19,   20,   18,   19,   &
+           18,   18,   19,   19,   20,    0,    0,    0,    0,    0    &
+                                      /
+      DATA (zrnfm(jm,103),jm=1,jpmois)/12*82858./
+
+      !  Total run-offs(VIII)=82858 m3/s
+      !  Total run-offs(I+II+III+IV+V+VI+VII+VIII)= 649941. m3/s
+      !                                           = 0.649940955 Sverdrup
+
+
+      DATA (inb(jr),jr=104,jpriv)/17*0/
+
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca2'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+         
+         i15 = nday / 16
+         
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  ii = iirnf(jl,jr) - nimpp + 1 - jpizoom + 1
+                  ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom + 1
+                  iipt0 = MAX( 1, MIN( ii, jpi   ) )
+                  iipt1 = MAX( 0, MIN( ii, jpi-1 ) )
+                  ijpt0 = MAX( 1, MIN( ij, jpj   ) )
+                  ijpt1 = MAX( 0, MIN( ij, jpj-1 ) )
+                  DO jj = ijpt0, ijpt1
+                     DO ji = iipt0, iipt1
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                                      + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                                      +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! --> zrup1 (originally, = 1 = all upstream).
+                     ! ji,jj
+                     ii = iirnf(jl,jr) - nimpp + 1 - jpizoom - 1
+                     ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom - 1
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     iipt0 = MAX( 1, MIN( ii+1, jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1, jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     ijpt0 = MAX( 1, MIN( ij, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     iipt0 = MAX( 1, MIN( ii-1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     iipt0 = MAX( 1, MIN( ii+1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     iipt0 = MAX( 1, MIN( ii+2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     iipt0 = MAX( 1, MIN( ii-2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = 1.0
+            upsrnfz(2)   = 1.0
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+
+            ! Reduces the sea surface restoring term to Levitus98
+            ! in the Sound Strait
+            DO jj = mj0(116), mj1(116)
+               DO ji = mi0(144), mi1(144)
+                  upsrnfh(ji,jj) = 0.25
+               END DO
+               DO ji = mi0(145), mi1(147)
+                  upsrnfh(ji,jj) = 0.5
+               END DO
+               DO ji = mi0(148), mi1(148)
+                  upsrnfh(ji,jj) = 0.25
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+      
+      ! Upstream and centered scheme in the vicinity of some straits
+
+      IF( kt == nit000 ) THEN
+
+         ! ORCA_R2 configuration :
+         ! Gibraltar Strait
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(138), mi1(138)
+               upsadv(ji,jj) = 0.2
+            END DO
+         END DO
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(139), mi1(139)
+               upsadv(ji,jj) = 0.4
+            END DO
+         END DO
+         DO jj = mj0(102), mj1(102)
+            DO ji = mi0(140), mi1(140)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         DO jj = mj0(101), mj1(102)
+            DO ji = mi0(141), mi1(141)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         ! Bab el Mandeb Strait
+         DO jj = mj0(87), mj1(88)
+            DO ji = mi0(164), mi1(164)
+               upsadv(ji,jj) = 0.1
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(163), mi1(163)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(162), mi1(162)
+               upsadv(ji,jj) = 0.4
+            END DO
+         END DO
+         DO jj = mj0(88), mj1(88)
+            DO ji = mi0(160), mi1(161)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+         DO jj = mj0(89), mj1(89)
+            DO ji = mi0(158), mi1(160)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         DO jj = mj0(90), mj1(90)
+            DO ji = mi0(160), mi1(160)
+               upsadv(ji,jj) = 0.25
+            END DO
+         END DO
+         ! Sound Strait
+         DO jj = mj0(116), mj1(116)
+            DO ji = mi0(145), mi1(147)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+
+      ENDIF
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R4.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R4.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/flxrnf_ORCA_R4.h90	(revision 4536)
@@ -0,0 +1,1339 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  flxrnf_ORCA_R4.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                  OLD ORCA R4 runoff specification
+   !!                      kept here for memory
+   !!                         ( 20/04/2000 )
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: kt
+      INTEGER  :: jpmois
+      INTEGER  ::   &
+         jpriv,    & ! jpriv : maximum river number
+         jpcoef      ! jpcoef: maximum point number
+      INTEGER, PARAMETER ::   jpmois=12, jpriv=120, jpcoef=150
+
+      INTEGER  ::   ji, jj, jl, jm, jn, jr, jc
+      INTEGER  ::   i15, imois, iman
+      INTEGER  ::   inbp, idbd, idmeom
+      INTEGER  ::   iipt0, iipt1, ijpt0, ijpt1, ii, ij
+      INTEGER  ::   iirnf(jpcoef,jpriv),ijrnf(jpcoef,jpriv)
+      INTEGER  ::   inb(jpriv)
+
+      REAL(wp) ::   zconv, zxy
+      REAL(wp) ::   zrup1,zrup2,zrup3
+      REAL(wp) ::   zrnfm(jpmois, jpriv)
+      REAL(wp) ::   zcoefr(jpi, jpj, 5)
+      CHARACTER (len=20) ::   criver(jpriv)
+
+      REAL(wp) ::   zbilan , zero
+
+      COMMON/zzzrnf/ zrnfm, iirnf, ijrnf, inb
+
+      ! ====
+      ! DATA
+      ! ====
+
+      zero = 0.0e0
+      IF( kt == nit000 ) THEN 
+          criver = "                    "
+          inb = 0
+          iirnf = 0
+          ijrnf = 0
+          zrnfm  = zero
+          runoff = zero
+         
+          ! I NORTH AMERICA
+          ! ---------------
+          
+          ! 1-Saint Lawrence (Canada) 49N30 67W00           R2
+          ! Old=447 km3/year=14165m3/s; CLIPPER=12430m3/s; ratio=1.14
+          ! --> 13975.249m3/s
+          criver(1) = "Saint Lawrence      "
+          inb(1) = 1
+          iirnf(1:1,1) = 57
+          ijrnf(1:1,1) = 55
+          zrnfm(1:jpmois,1) = (/   &
+              11718.,  11971.,  12466.,  14980.,  19257.,  16913.,   &
+              14211.,  13119.,  13367.,  13644.,  13463.,  12594./)
+          ! 2-Hudson River (USA) 41N00 77W00                R1
+          ! Old=12 km3/year=380m3/s; UNESCO(64-83,p255)=408m3/s
+          ! --> 407.416687m3/s
+          criver(2) = "Hudson River        "
+          inb(2) = 1
+          iirnf(1:1,2) = 54
+          ijrnf(1:1,2) = 53
+          zrnfm(1:jpmois,2) = (/   &
+              364.,    404.,    648.,    873.,    593.,    301.,   &
+              205.,    171.,    205.,    290.,    379.,    456./)
+          ! 3-Missisipi and Atchafalaya (USA) 29N 90W       R1 
+          ! Old=580 km3/year=18380m3/s; CLIPPER=17599m3/s
+          ! --> 17599.334m3/s
+          criver(3) = "Missisipi           "
+          inb(3) = 1
+          iirnf(1:1,3) = 50
+          ijrnf(1:1,3) = 49
+          zrnfm(1:jpmois,3) = (/   &
+              19260.,  20813.,  23026.,  28160.,  26510.,  19650.,   &
+              14181.,  10676.,   9578.,  10167.,  11699.,  17472./)
+          ! 4-Brazos (USA) 29N58 95W53                      R1
+          ! Old=7 km3/year=222m3/s; UNESCO(65-84, p298)=200m3/s
+          ! --> 199.666656m3/s
+          criver(4) = "Brazos              "
+          inb(4) = 1
+          iirnf(1:1,4) = 48
+          ijrnf(1:1,4) = 49
+          zrnfm(1:jpmois,4) = (/   &
+              165.,    224.,    200.,    266.,    457.,    327.,   &
+              143.,     69.,    102.,    132.,    160.,    151. /)
+          ! 5-Colorado (Mexico) 31N54 114W57                R5
+          ! Old=20 km3/year=634m3/s
+          ! --> 634.m3/s
+          criver(5) = "Colorado            "
+          inb(5) = 1
+          iirnf(1:1,5) = 43
+          ijrnf(1:1,5) = 50
+          zrnfm(1:jpmois,5) = 634. 
+          ! 6-Columbia (USA) 45N60 121W17                   R1
+          ! Old=251 km3/year=7954m3/s; UNESCO(65-84, p312)=5368m3/s
+          ! --> 5368.41602m3/s
+          criver(6) = "Columbia            "
+          inb(6) = 1
+          iirnf(1:1,6) = 40
+          ijrnf(1:1,6) = 56
+          zrnfm(1:jpmois,6) = (/   &
+              4752.,    5077.,    5633.,    6075.,    8422.,    9822.,   &
+              6350.,    4112.,    3273.,    3251.,    3548.,    4106. /)
+          ! 7-Fraser (USA) 47N 124W                         R5
+          ! Old=112 km3/year=3550m3/s;not found in UNESCO
+          ! --> 3549.99976m3/s
+          criver(7) = "Fraser              "
+          inb(7) = 1
+          iirnf(1:1,7) = 40
+          ijrnf(1:1,7) = 57
+          zrnfm(1:jpmois,7) = 3550. 
+          ! 8-Yukon (USA) 63N00 165W00                      R3
+          ! Old=195 km3/year=6179m3/s; UNESCO(65-77+80-84, p321)=4245; ratio=1.46
+          ! --> 6017.24951m3/s
+          criver(8) = "Yukon               "
+          inb(8) = 1
+          iirnf(1:1,8) = 30
+          ijrnf(1:1,8) = 62
+          zrnfm(1:jpmois,8) = (/   &
+              1459.,    1213.,    1065.,    1100.,    9067.,   17675.,   &
+              10680.,   11271.,    8658.,    5453.,    2649.,    1917./)
+          ! 9-Copper (USA) 61N47 144W45                     R2
+          ! Old=39 km3/year=1236m3/s; UNESCO(65-84, p317)=1052m3/s; ratio=1.18
+          ! --> 1236.25m3/s
+          criver(9) = "Copper              "
+          inb(9) = 1
+          iirnf(1:1,9) = 35
+          ijrnf(1:1,9) = 60
+          zrnfm(1:jpmois,9) = (/   &
+              219.,    195.,    181.,    214.,    904.,   2532.,   &
+              4026.,   3627.,   1632.,    697.,    354.,    254. /) 
+          ! 10-Susitna (USA)   62N 150E                     R5
+          ! Old=40 km3/year=1268m3/s
+          ! --> 1268.m3/s
+          criver(10) = "Susitna             "
+          inb(10) = 1
+          iirnf(1:1,10) = 34
+          ijrnf(1:1,10) = 60
+          zrnfm(1:jpmois,10) = 1268. 
+          ! 11-McKenzie (Canada) 70N00 135W00               R3
+          ! Old=306 km3/year=9697m3/s; UNESCO(67+72+7479+82-84, p168)=8343m3/s;
+          ! ratio=1.16
+          ! --> 9606.66797m3/s
+          criver(11) = "McKenzie            "
+          inb(11) = 1
+          iirnf(1:1,11) = 35
+          ijrnf(1:1,11) = 66
+          zrnfm(1:jpmois,11) = (/   &
+              3644.,    3400.,    3258.,    3546.,   14188.,   21544.,   &
+              18954.,   15487.,   11284.,   10169.,    5901.,    3905./)
+          ! 12-Kuksokwim (USA) 60N00 ~162W30                R4
+          ! UNESCO(65-84, p318)=1112m3/s (61N87 158E10, Crooked Creek, inland)
+          ! --> 1111.99988m3/s
+          criver(12) = "Kuksokwim           "
+          inb(12) = 1
+          iirnf(1:1,12) = 30
+          ijrnf(1:1,12) = 60
+          zrnfm(1:jpmois,12) = (/   &
+              335.,     308.,     295.,     407.,    2415.,    2027.,   &
+              1917.,   2049.,    1585.,    1072.,     545.,     389./)
+          ! 13-Nelson
+          criver(13) = "Nelson              "
+          inb(13) = 1
+          iirnf(1:1,13) = 51
+          ijrnf(1:1,13) = 65
+          zrnfm(1:jpmois,13) = 0.
+
+          ! Total run-offs(I)=60974.2539m3/s
+
+          ! II SOUTH AMERICA
+          ! -----------------
+          ! 16-Chira (Peru) 4s54 81w08                      R2
+          ! Old=5 km3/year=158m3/s; UNESCO (65-68, p357)=80.9; ratio=1.95
+          ! --> 158.000015m3/s
+          criver(16) = "Chira               "
+          inb(16) = 1
+          iirnf(1:1,16) = 51
+          ijrnf(1:1,16) = 34
+          zrnfm(1:jpmois,16) = (/   &
+              70.,     105.,     564.,     582.,     230.,      94.,   &
+              87.,      47.,      35.,      32.,      29.,      21./)
+          ! 17-Magdalena (Colombia) 11N06 74W51             R2
+          ! Old=237 km3/year=7510m3/s; UNESCO(71-73+76-79, p348)=6973m3/s;
+          ! ratio=1.08
+          ! --> 7451.58301m3/s
+          criver(17) = "Magdelena           "
+          inb(17) = 1
+          iirnf(1:1,17) = 53
+          ijrnf(1:1,17) = 45
+          zrnfm(1:jpmois,17) = (/   &
+              6598.,    4441.,    4087.,    5445.,    7380.,    8067.,   &
+              8509.,    7428.,    7631.,    9296.,   10588.,    9949./)
+          ! 18-Orinoco (Venezuela) 8N37 62W15!              R1
+          ! Old=1100 km3/year=34857m3/s; UNESCO(73-75, p364)=28736m3/s;
+          ! HLA=26371m3/s
+          ! Data from HLA: 8.1N - 63.3W   1925/89
+          ! --> 26371.416
+          criver(18) = "Orinico             "
+          inb(18) = 1
+          iirnf(1:1,18) = 57
+          ijrnf(1:1,18) = 44
+          zrnfm(1:jpmois,18) = (/   &
+              10670.,    7513.,    6344.,    6887.,   13086.,   26699.,   &
+              43938.,   59957.,   57435.,   39951.,   27410.,   16567./)
+          ! 19-Amazon (Brazil) 0S05 50W00                   R1
+          ! Old=6300 km3/year=199634m3/s; CLIPPER=166192m3/s~UNESCO;
+          ! HLA=184806m3/s
+          ! UNESCO data are at Obidos which is far inland and therefore does not
+          ! fully represent the actual discharge
+          ! Data from HLA: 1.5N - 55.3W   1970/96
+          ! --> 184845.484m3/s
+          criver(19) = "Amazon              "
+          inb(19) = 3
+          iirnf(1:3,19) = (/ 60, 60, 60 /)
+          ijrnf(1:3,19) = (/ 39, 40, 41 /)
+          zrnfm(1:jpmois,19) = (/   &
+              152233., 176415., 199941., 225565., 244016., 244861.,   &
+              230711., 203128., 164531., 128486., 118214., 130045. /)
+          ! 20-Sao Francisco (Brazil) 10S30 36W24           R1
+          ! Old=97 km3/year=3074m3/s; UNESCO(77-79, p338)=2645m3/s
+          ! --> 2645.3335m3/s
+          criver(20) = "San Fransisco       "
+          inb(20) = 1
+          iirnf(1:1,20) = 63
+          ijrnf(1:1,20) = 31
+          zrnfm(1:jpmois,20) = (/   &
+              3244.,   4116.,   5139.,   4330.,   2323.,   1800.,     &
+              1587.,   1511.,   1593.,   1740.,   2190.,   2171. /)
+          ! 21-Parana+Uruguay(Arg./Uru.) 34S12 58W18        R1 
+          ! Old=470 km3/year=14893m3/s; UNESCO(p323/324)=22263m3/s
+          ! --> 22203.168m3/s 
+          criver(21) = "Parana              "
+          inb(21) = 1
+          iirnf(1:1,21) = 58
+          ijrnf(1:1,21) = 24
+          zrnfm(1:jpmois,21) = (/   &
+              24803.,   26836.,   24585.,   21358.,   20041.,   21689.,   &
+              22647.,   20403.,   19627.,   21400.,   21126.,   21923./)
+          ! 22-Negro (Argentina)  41S02  62W47              R2
+          ! Old=30 km3/year=951m3/s; UNESCO(65-79,p330)=765m3/s; ratio=1.24
+          ! --> 907.666687m3/s
+          criver(22) = "Rio Negro           "
+          inb(22) = 1
+          iirnf(1:1,22) = 56
+          ijrnf(1:1,22) = 22
+          zrnfm(1:jpmois,22) = (/   &
+              882.,     587.,     519.,     482.,     623.,     984.,   &
+              1120.,   1294.,    1092.,    1166.,    1105.,    1038./)
+          ! 23- Tocantins :  ~48W00 ~0.5S                   R4
+          ! UNESCO(76-77+80-81, p335)=12167m3/s (station far inland!)
+          ! --> 12173.082m3/s
+          criver(23) = "Tocantins           "
+          inb(23) = 1
+          iirnf(1:1,23) = 60
+          ijrnf(1:1,23) = 38
+          zrnfm(1:jpmois,23) = (/   &
+              15507.,  24855.,  27854.,  24257.,  15860.,   7861.,   &
+              4440.,   3082.,   2728.,   3417.,   5511.,  10705. /)
+
+          ! Total run-offs(II)=256755.75
+          ! Total run-offs(I+II)=317730
+
+          ! III EUROPE
+          ! ----------
+          ! 26-Rhone (France) 43N20 4E50                    R1 
+          ! Old=49 km3/year=1553m3/s; UNESCO(65-83, p512)=1229
+          ! --> 1217.16663m3/s
+          criver(26) = "Rhone               "
+          inb(26) = 1
+          iirnf(1:1,26) = 76
+          ijrnf(1:1,26) = 55
+          zrnfm(1:jpmois,26) = (/   &
+              1385.,    1848.,    1568.,    1311.,    1420.,    1191.,   &
+              937.,     796.,     794.,     962.,    1161.,    1233./)
+          ! 27-Po (Italy) 41N10 11E09                       R1 
+          ! Old=46 km3/year=1458m3/s; UNESCO(65-84, p527)=1550m3/s
+          ! --> 1550.08337m3/s
+          criver(27) = "Po                  "
+          inb(27) = 1
+          iirnf(1:1,27) = 79
+          ijrnf(1:1,27) = 54
+          zrnfm(1:jpmois,27) = (/   &
+              1304.,    1605.,    1856.,    1549.,    1958.,    1760.,   &
+              1040.,    1007.,    1615.,    1907.,    1772.,    1228./)
+          ! 28-Danube (Roumania) 45N20 29E40                R1 
+          ! Old=206 km3/year=6527m3/s; UNESCO(65-84, p544)=7011m3/s
+          ! --> 7011.8335m3/s
+          criver(28) = "Danube              "
+          inb(28) = 1
+          iirnf(1:1,28) = 87
+          ijrnf(1:1,28) = 53
+          zrnfm(1:jpmois,28) = (/   &
+              6625.,    7352.,    7986.,    9279.,    9482.,    8618.,   &
+              7586.,    6001.,    5210.,    4989.,    4921.,    6093./)
+
+          ! 29-Volga
+          criver(29) = "Volga               "
+          inb(29) = 1
+          iirnf(1:1,29) = 4
+          ijrnf(1:1,29) = 56
+          zrnfm(1:jpmois,29) = 0.
+          ! 30-Dniepr
+          criver(30) = "Dniepr+Don          "
+          inb(30)= 2
+          iirnf(1:2,30) = (/ 89, 90 /)
+          ijrnf(1:2,30) = (/ 56, 56 /)
+
+          ! Total run-offs(III)=9779.08301m3/s
+          ! Total run-offs(I+II+III)=327509.094m3/s
+
+          ! IV EURASIAN ARCTIC
+          ! ------------------
+          ! 31-Iana (Russia)      126E40 72N25              R1
+          ! Old=29 km3/year=919m3/s; UNESCO(65-72+74+76-84, p463)=936m3/s
+          ! --> 0m3/s
+          criver(31) = "Iana                "
+          inb(31) = 1
+          iirnf(1:1,31) = 20
+          ijrnf(1:1,31) = 68
+          zrnfm(1:jpmois,31) = (/   &
+              2.,       1.,       0.,       0.,     917.,    3514.,   &
+              2968.,    2329.,    1322.,   178.,      36.,       8./)
+          ! 32-Ob (Russia) 66N45 69E30                      R1 
+          ! Old=385 km3/year=12200m3/s; UNESCO(65-84, p478)=12862m3/s
+          ! --> 12861.5m3/s
+          criver(32) = "Ob                  "
+          inb(32) = 1
+          iirnf(1:1,32) = 78
+          ijrnf(1:1,32) = 72
+          zrnfm(1:jpmois,32) = (/   &
+              4977.,    4150.,    3611.,    3590.,   14723.,   33366.,   &
+              30773.,   22785.,   14701.,    9705.,    6078.,    5879./)
+          ! 33-Yenesei (Russia) 71N50 82E40                 R1 
+          ! Old=560 km3/year=17745m3/s; UNESCO(65-84, p472)=17462m3/s
+          ! --> 17461.666m3/s
+          criver(33) = "Yenesei             "
+          inb(33) = 1
+          iirnf(1:1,33) = 77
+          ijrnf(1:1,33) = 75
+          zrnfm(1:jpmois,33) = (/   &
+              6659.,    7007.,    6895.,    7089.,   24183.,   74965.,   &
+              25325.,   15940.,   16050.,   12678.,    6741.,    6008./)
+          ! 34-Severnaya Dvina(Russia)64N32 40E30           R5 
+          ! Old=106 km3/year=3359m3/s; not in UNESCO data base
+          ! --> 3359.00024m3/s
+          criver(34) = "Severnaya Dvina     "
+          inb(34) = 1
+          iirnf(1:1,34) = 78
+          ijrnf(1:1,34) = 68
+          zrnfm(1:jpmois,34) = 3359.
+          ! 35-Lena (Russia) 72N25 126E40                   R1 
+          ! --> 16192.333m3/s
+          criver(35) = "Lena                "
+          inb(35) = 1
+          iirnf(1:1,35) = 20
+          ijrnf(1:1,35) = 68
+          zrnfm(1:jpmois,35) = (/   &
+              2663.,    2095.,    1629.,    1324.,    7203.,   64230.,   &
+              40810.,   28310.,   25995.,   13299.,    3673.,    3077./)
+          ! 36-Kolyma (Russia) 69N30 161E00                 R1
+          ! Old=71 km3/year=2250m3/s; UNESCO(65-84)=2138m3/s
+          ! --> 2138.66675m3/s
+          criver(36) = "Kolyma              "
+          inb(36) = 1
+          iirnf(1:1,36) = 24
+          ijrnf(1:1,36) = 65
+          zrnfm(1:jpmois,36) = (/   &
+              131.,      92.,      76.,      65.,    2576.,    9143.,   &
+              4670.,    3727.,    3226.,    1119.,     630.,     209./)
+          ! 37-Indigirka (russia) 70N48 148E54              R1 
+          ! Old=55 km3/year=1743m3/s; UNESCO(65-68+70+72-84)=1622.
+          ! --> 1622.00012m3/s
+          criver(37) = "Indigirka           "
+          inb(37) = 1
+          iirnf(1:1,37) = 23
+          ijrnf(1:1,37) = 66
+          zrnfm(1:jpmois,37) = (/   &
+              32.,      17.,      11.,       7.,     354.,    5629.,   &
+              5210.,    4617.,    2823.,     559.,     142.,      63./)
+          ! 38-Khatanga
+          criver(38) = "Khatanga             "
+          inb(38) = 1
+          iirnf(1:1,38) = 20
+          ijrnf(1:1,38) = 72
+          zrnfm(1:jpmois,38) = 0.
+
+          ! Total run-offs(IV)=40773.6641m3/s
+          ! Total run-offs(I+II+III+IV)=368282.75m3/s
+
+          ! V ASIA
+          ! ------
+          ! 41-Amur (Russia) 52N56 141E10                   R2
+          ! Old=325 km3/year=10299m3/s; UNESCO(65-84, p451)=8792m3/s; ratio=1.17
+          ! --> 10299.332m3/s
+          criver(41) = "Amur                "
+          inb(41) = 1
+          iirnf(1:1,41) = 18
+          ijrnf(1:1,41) = 59
+          zrnfm(1:jpmois,41) = (/   &
+              2108.,    1543.,    1252.,    4088.,   15464.,   17336.,   &
+              16100.,   20801.,   21548.,   15658.,    5188.,    2506./)
+          ! 42-Liaohe (China) 40N40 122E09                  R5
+          ! Old=6 km3/year=190m3/s; not found in UNESCO data base
+          ! --> 189.999985m3/s
+          criver(42) = "Liaohe              "
+          inb(42) = 1
+          iirnf(1:1,42) = 15
+          ijrnf(1:1,42) = 54
+          zrnfm(1:jpmois,42) = 190.
+          ! 43-Daling (China) 40N56 121E43                  R5
+          ! Old=1 km3/year=32m3/s; not found in UNESCO data base
+          ! --> 31.9999962m3/s
+          criver(43) = "Daling              "
+          inb(43) = 1
+          iirnf(1:1,43) = 15
+          ijrnf(1:1,43) = 54
+          zrnfm(1:jpmois,43) = 32.
+          ! 44-Haiho (China) 6N17   1E23
+          ! Old=2 km3/year=64m3/s; not found in UNESCO data base
+          ! --> 63.9999924m3/s
+          criver(44) = "Haiho               "
+          inb(44) = 0
+          iirnf(1:1,44) = 0
+          ijrnf(1:1,44) = 0
+          zrnfm(1:jpmois,44) = 64.
+          ! 45-Yellow/Huangho (China) 37N32 118E19          R2 
+          ! Old=49 km3/year=1553m3/s; UNESCO(p371)=1210m3/s; ratio=1.28
+          ! --> 1552.5m3/s
+          criver(45) = "Yellow/Huangho      "
+          inb(45) = 1
+          iirnf(1:1,45) = 13
+          ijrnf(1:1,45) = 51
+          zrnfm(1:jpmois,45) = (/   &
+              697.,     674.,    1282.,    1206.,    1109.,     778.,   &
+              1964.,    3270.,    3668.,    2133.,     978.,     871./)
+          ! 46-Yangtze (China) 31N48 121E10=Changjiang      R2
+          ! Old=900 km3/year=28520m3/s; UNESCO(p372)=25032m3/s; ratio=1.14
+          ! --> 28519.584m3/s
+          criver(46) = "Yangtze             "
+          inb(46) = 1
+          iirnf(1:1,46) = 13
+          ijrnf(1:1,46) = 50
+          zrnfm(1:jpmois,46) = (/   &
+              10994.,   10548.,   13254.,   24097.,   36972.,   47197.,   &
+              53891.,   42070.,   37627.,   30762.,   22046.,   12777./)
+          ! 47-Pearl/Zhujiang (China) 23N36 106E34=Xijiang  R2 
+          ! Old=302 km3/year=9570m3/s; UNESCO(76,82, p373)=6987m3/s; ratio=1.37
+          ! --> 9570.75m3/s
+          criver(47) = "Pearl Zhujiang       "
+          inb(47) = 1
+          iirnf(1:1,47) = 12
+          ijrnf(1:1,47) = 48
+          zrnfm(1:jpmois,47) = (/   &
+              2357.,    2415.,    2634.,    6446.,   14246.,   18395.,   &
+              19213.,   17558.,   12312.,    7255.,    5864.,    6154./)
+          ! 48-Red/Hungho (Vietnam) 20N17 106E34            R5 
+          ! Old=123 km3/year=3897m3/s; not in UNESCO data base
+          ! --> 3897.m3/s
+          criver(48) = "Red Hungho          "
+          inb(48) = 1
+          iirnf(1:1,48) = 10
+          ijrnf(1:1,48) = 47
+          zrnfm(1:jpmois,48) = 3897.
+          ! 49-Mekong (Vietnam) 10N33 105E24                R5
+          ! Old=470 km3/year=14893m3/s; not in UNESCO data base
+          ! --> 14893.0029m3/s
+          criver(49) = "Mekong              "
+          inb(49) = 1
+          iirnf(1:1,49) =  8
+          ijrnf(1:1,49) = 44
+          zrnfm(1:jpmois,49) = 14893.
+          ! 50-Irrawady (Burma) 15N50  95E06                R5
+          ! Old=428 km3/year=13563m3/s; not in UNESCO data base
+          ! --> 13563.m3/s
+          criver(50) = "Irrawady            "
+          inb(50) = 1
+          iirnf(1:1,50) =  6
+          ijrnf(1:1,50) = 46
+          zrnfm(1:jpmois,50) = 13563.
+          ! 51-Ganges+Brahmaputra (Beng.) 22N00  91E00      R1
+          ! Old=971 km3/year=30769m3/s; UNESCO(69-70+73-75, p367)=31760m3/s
+          ! --> 32147.498m3/s
+          criver(51) = "Ganges              "
+          inb(51) = 2
+          iirnf(1:2,51) = (/  4,  5 /)
+          ijrnf(1:2,51) = (/ 47, 47 /)
+          zrnfm(1:jpmois,51) = (/   &
+              6623.,    6315.,    6432.,    9410.,   17263.,   38302.,   &
+              64688.,   80338.,   84802.,   43387.,   17888.,   10322./)
+          ! 52-Mehandi (India)                              R5
+          ! Old=67 km3/year=2123m3/s; not in UNESCO data base
+          ! --> 0m3/s
+          criver(52) = "Mehandi             "
+          inb(52) = 0
+          iirnf(1:1,52) = 0
+          ijrnf(1:1,52) = 0
+          zrnfm(1:jpmois,52) = 2123.
+          ! 53-Damodar (India)                              R2
+          ! Old=10 km3/year=320m3/s; UNESCO(p386)=173m3/s; ratio=1.85
+          ! --> 432.916656m3/s
+          criver(53) = "Damodar             "
+          inb(53) = 0
+          iirnf(1:1,53) = 0
+          ijrnf(1:1,53) = 0
+          zrnfm(1:jpmois,53) = (/   &
+              51.,      37.,      42.,      49.,      85.,     296.,   &
+              896.,    1390.,    1591.,     542.,     172.,      44./)  
+          ! 54-Godavari (India) 17N00  81E45                R2
+          ! Old=84 km3/year=2662m3/s; UNESCO(p379)=1916m3/s; ratio=1.39
+          ! --> 3670.5m3/s
+          criver(54) = "Godaravi            "
+          inb(54) = 1
+          iirnf(1:1,54) =  3
+          ijrnf(1:1,54) = 46
+          zrnfm(1:jpmois,54) = (/   &
+              988.,     737.,     280.,     219.,     196.,    1691.,   &
+              8063.,   14571.,   11428.,    3953.,    1221.,     699./)
+          ! 55-Indus (Pakistan) 24N20  67E47                R2
+          ! Old=238 km3/year=7542m3/s; UNESCO (76-79, p428)=2396m3/s; ratio=3.15
+          ! --> 7562.m3/s
+          criver(55) = "Indus               "
+          inb(55) = 1
+          iirnf(1:1,55) = 89
+          ijrnf(1:1,55) = 47
+          zrnfm(1:jpmois,55) = (/   &
+              988.,     737.,    1904.,    1968.,    3625.,    6143.,   &
+              15969.,    36656.,  17173.,    3215.,    1251.,    1115./)
+          ! 56-Tigris and Euphrates (Iraq) 31N00  47E25     R1
+          ! Old=46 km3/year=1458m3/s; UNESCO(76-79, p428)=2396m3/s
+          ! --> 2248.8335m3/s
+          criver(56) = "Tigris              "
+          inb(56) = 1
+          iirnf(1:1,56) = 88
+          ijrnf(1:1,56) = 47
+          zrnfm(1:jpmois,56) = (/   &
+              1872.,    2127.,    2962.,    4944.,    5036.,    3078.,   &
+              1362.,     900.,     786.,     993.,    1184.,    1742./)
+
+          ! Total run-offs (V)=128642.922m3/s
+          ! Total run-offs (I+II+III+IV+V)=496925.688m3/s
+
+          ! VI AFRICA
+          ! ----------
+          ! 61-Nile (Egypt) 30N10  31E06                    R1
+          ! Old=30 km3/year=951m3/s; UNESCO(73-84)=1251m3/s
+          ! --> 1251.33337m3/s
+          criver(61) = "Nile                "
+          inb(61) = 1
+          iirnf(1:1,61) = 90
+          ijrnf(1:1,61) = 50
+          zrnfm(1:jpmois,61) = (/   &
+              1239.,    1035.,    1126.,    1110.,    1170.,    1542.,   &
+              1742.,    1559.,    1191.,    1103.,    1075.,    1124./)
+          ! 62-Niger (Nigeria) 5N33   6E33                  R1
+          ! Old=192 km3/year=6084m3/s; HLA=5545m3/s;
+          ! Data from HLA: 4.5N -  6  E   1950/87
+          ! --> 5545.08301m3/s
+          criver(62) = "Niger               "
+          inb(62) = 1
+          iirnf(1:1,62) = 74
+          ijrnf(1:1,62) = 41
+          zrnfm(1:jpmois,62) = (/   &
+              2029.,    1804.,    1573.,    1418.,    1494.,    2561.,   &
+              5272.,    9629.,   14951.,   16227.,    6842.,    2741./)
+          ! 63-Zaire/Congo (Congo) 6S04  12E24              R1      
+          ! Old=1250 km3/year=39610m3/s; UNESCO(65-83, p149)=41941m3/s; HLA
+          ! =39720m3/s
+          ! Data from HLA: 6S - 12  E   1902/96
+          ! --> 39719.5m3/s
+          criver(63) = "Zaire Congo         "
+          inb(63) = 1
+          iirnf(1:1,63) = 75
+          ijrnf(1:1,63) = 33
+          zrnfm(1:jpmois,63) = (/   &
+              47200.,   37692.,   34374.,   36603.,   37862.,   35588.,   &
+              30966.,   30774.,   35981.,   42825.,   51455.,   55314./)
+          ! 64-Orange (Sth Africa) 28S41 16E28              R5
+          ! Old=11 km3/year=349m3/s
+          ! --> 349.000031m3/s
+          criver(64) = "Orange              "
+          inb(64) = 1
+          iirnf(1:1,64) = 76
+          ijrnf(1:1,64) = 26
+          zrnfm(1:jpmois,64) = 349.
+          ! 65-Zambesi (Mozambique) 18S55 36E04             R5
+          ! Old=223 km3/year=7066m3/s
+          ! --> 7066.00049m3/s
+          criver(65) = "Zambesi             "
+          inb(65) = 1
+          iirnf(1:1,65) = 81
+          ijrnf(1:1,65) = 29
+          zrnfm(1:jpmois,65) = 7066.
+          ! 66-Limpopo (mozambique) 25S15 33E30             R5
+          ! Old=5 km3/year=158m3/s
+          ! --> 158.m3/s
+          criver(66) = "Limpopo             "
+          inb(66) = 1
+          iirnf(1:1,66) = 81
+          ijrnf(1:1,66) = 28
+          zrnfm(1:jpmois,66) = 158.
+          ! 67-Rufiji (tanzania) 8S00 39E20                 R5
+          ! Old=9 km3/year=285m3/s
+          ! --> 285.m3/s
+          criver(67) = "Rufiji             "
+          inb(67) = 1
+          iirnf(1:1,67) = 82
+          ijrnf(1:1,67) = 33
+          zrnfm(1:jpmois,67) = 285.
+          ! Other rivers from the Gulf of Guinea
+          ! 68-Kouilou (Congo)  4.5S-11.5E (UNESCO=p51)     R1
+          ! Data from HLA:  4S - 11  E   1953/86 = 919m3/s
+          ! --> 924.25m3/s
+          criver(68) = "Kouilou            "
+          inb(68) = 1
+          iirnf(1:1,68) = 75
+          ijrnf(1:1,68) = 33
+          zrnfm(1:jpmois,68) = (/   &
+              1115.,    1166.,    1285.,    1462.,    1454.,     725.,   &
+              480.,     378.,     327.,     400.,    1018.,    1281./)
+          ! 69-Nyanga (Gabon)  3S-10E (UNESCO=p66)          R1
+          ! Data from HLA: 2.8N - 10  E   1952/82 = 264m3/s
+          ! --> 264.166687m3/s
+          criver(69) = "Nyanga              "
+          inb(69) = 1
+          iirnf(1:1,69) = 74
+          ijrnf(1:1,69) = 36
+          zrnfm(1:jpmois,69) = (/   &
+              126.,      99.,     143.,     253.,     316.,     300.,   &
+              156.,      93.,     231.,     557.,     592.,     304./)
+          ! 70-Ogoue (Gabon) 1S-9E (UNESCO, p69)            R1
+          ! Data from HLA: .75S -  9  E   1930/90 = 4512m3/s
+          ! --> 4511.83301m3/s
+          criver(70) = "Ogoue               "
+          inb(70) = 1
+          iirnf(1:1,70) = 74
+          ijrnf(1:1,70) = 37
+          zrnfm(1:jpmois,70) = (/   &
+              4514.,    3988.,    4622.,    5403.,    5790.,    4145.,   &
+              2616.,    1961.,    2119.,    4304.,    7870.,    6810./)
+          ! 71-Sanaga (Cameroun) 3.5N-9.5E (UNESCO, p31)    R1
+          ! Data from HLA: 3.9N -  9.6E   1944/80 = 1983m3/s
+          ! --> 1982.58337m3/s
+          criver(71) = "Sanaga              "
+          inb(71) = 1
+          iirnf(1:1,71) = 74
+          ijrnf(1:1,71) = 41
+          zrnfm(1:jpmois,71) = (/   &
+              813.,     578.,     517.,     633.,     909.,    1278.,   &
+              1928.,    2653.,    4361.,    5470.,    3307.,    1344./)
+          ! 72-Nyong (Cameroun) 3.1N-9.5E (UNESCO, p36)     R1
+          ! Data from HLA: 3.5N -  9.8E   1951/84 = 432m3/s
+          ! --> 431.166656m3/s      
+          criver(72) = "Nyong               "
+          inb(72) = 1
+          iirnf(1:1,72) = 74
+          ijrnf(1:1,72) = 41
+          zrnfm(1:jpmois,72) = (/   &
+              232.,     128.,     150.,     266.,     402.,     459.,   &
+              353.,     306.,     604.,     930.,     878.,     466./)
+          ! 73-Ntem (Cameroun) 2.5N-9.5E (UNESCO, p36)      R1
+          ! Data from HLA: 3N -  9.8E   1951/87 = 330m3/s      
+          ! --> 329.75m3/s
+          criver(73) = "Ntem                "
+          inb(73) = 1
+          iirnf(1:1,73) = 74
+          ijrnf(1:1,73) = 41
+          zrnfm(1:jpmois,73) = (/   &
+              452.,     455.,     492.,     466.,     482.,     251.,   &
+              151.,     108.,      87.,     133.,     395.,     485./)
+          ! 74-Wouri (Cameroun) 4N-9.5E (UNESCO, p34)       R1
+          ! Data from HLA: 4N -  9.5E   1951/84  = 307m3/s
+          ! --> 306.583374m3/s
+          criver(74) = "Wouri               "
+          inb(74) = 1
+          iirnf(1:1,74) = 74
+          ijrnf(1:1,74) = 41
+          zrnfm(1:jpmois,74) = (/   &
+              88.,      63.,      68.,      95.,     139.,     222.,   &
+              395.,     633.,     825.,     675.,     328.,     148./)
+          ! 75-Oueme (Benin) 6.5N-2.5E (UNESCO, p27)        R1
+          ! Data from HLA:  6.2N -  2.5E   1951/84 =113m3/s
+          ! --> 112.666664m3/s
+          criver(75) = "Oueme               "
+          inb(75) = 1
+          iirnf(1:1,75) = 73
+          ijrnf(1:1,75) = 42
+          zrnfm(1:jpmois,75) = (/   &
+              0.,       0.,       0.,       0.,       1.,      18.,   &
+              96.,     324.,     531.,     319.,      58.,       5./)
+          ! 76-Mono(Tepetou,Benin/Togo) 6.25N-1.8E (U, p27) R1
+          ! Data from HLA: 6.2N -  1  E   1951/85  = 96m3/s       
+          ! --> 96.4999924m3/s
+          criver(76) = "Mono                "
+          inb(76) = 1
+          iirnf(1:1,76) = 72
+          ijrnf(1:1,76) = 42
+          zrnfm(1:jpmois,76) = (/   &
+              2.,       1.,       1.,       4.,       8.,      44.,   &
+              168.,     274.,     386.,     215.,      47.,       8./)
+          ! 77-Comoe (Ivory Coast) 5N-4W (UNESCO, p56)      R1
+          ! Data from HLA: 5.1N -  4  W   1955/86 = 194m3/s       
+          ! --> 194.25m3/s
+          criver(77) = "Comoe               "
+          inb(77) = 1
+          iirnf(1:1,77) = 71
+          ijrnf(1:1,77) = 41
+          zrnfm(1:jpmois,77) = (/   &
+              14.,       7.,       9.,      17.,      29.,      90.,   &
+              145.,     349.,     740.,     688.,     198.,      45./)
+          ! 78-Sassandra (Ivory Coast) 5N-6W (UNESCO, p58)  R1
+          ! Data from HLA: 5N -  6  W   1953/86 = 449m3/s
+          ! --> 449.333344m3/s
+          criver(78) = "Sassandra           "
+          inb(78) = 1
+          iirnf(1:1,78) = 71
+          ijrnf(1:1,78) = 41
+          zrnfm(1:jpmois,78) = (/   &
+              144.,     116.,     119.,     143.,     156.,     334.,   &
+              419.,     692.,    1277.,    1190.,     553.,     249./)
+          ! 79-Jubba (Somali Coast)
+          criver(79) = "Jubba               "
+          inb(79) = 1
+          iirnf(1:1,79) = 84
+          ijrnf(1:1,79) = 39
+          zrnfm(1:jpmois,79) = 0.
+          ! 80-Senaga
+          criver(80) = "Senegal             "
+          inb(79) = 1
+          iirnf(1:1,80) = 66
+          ijrnf(1:1,80) = 47
+          zrnfm(1:jpmois,79) = 0.
+      
+          ! Total run-offs (VI)=63977.m3/s
+          ! Total run-offs (I+II+III+IV+V+VI)=560902.688m3/s
+          
+          ! VII OCEANIA
+          ! ------------
+          ! 91-Murray (Australia) 35S34 138E54              R5
+          ! Old=22 km3/year=697m3/s
+          ! --> 696.999939m3/s
+          criver(91) = "Murray              "
+          inb(91) = 1
+          iirnf(1:1,91) = 16
+          ijrnf(1:1,91) = 24
+          zrnfm(1:jpmois,91) = 697.
+          ! 92-Haast (N. Zeland) 43S50 169E02               R5
+          ! Old=6 km3/year=190m3/s
+          ! --> 189.999985m3/s
+          criver(92) = "Haast               "
+          inb(92) = 1
+          iirnf(1:1,92) = 24
+          ijrnf(1:1,92) = 22
+          zrnfm(1:jpmois,92) = 190.
+          ! 93-Fly (N. Guinea) 8S30 143E05                  R5
+          ! Old=77 km3/year=2440m3/s
+          ! --> 2440.m3/s
+          criver(93) = "Fly                 "
+          inb(93) = 1
+          iirnf(1:1,93) = 19
+          ijrnf(1:1,93) = 31
+          zrnfm(1:jpmois,93) = 2440.
+          ! 94-Purari (N. Guinea) 7S25 145E05               R4
+          ! Old=77 km3/year=2440m3/s; UNESCO(77+83,p595)=2727m3/s
+          ! --> 2727.33325m3/s
+          criver(94) = "Purari              "
+          inb(94) = 1
+          iirnf(1:1,94) = 19
+          ijrnf(1:1,94) = 33
+          zrnfm(1:jpmois,94) = (/   &
+              1972.,    3067.,    2332.,    2981.,    2693.,    2876.,   &
+              2867.,    3477.,    2195.,    2967.,    2674.,    2627./)
+          ! 95-Choshui ch''i (taiwan) 24N03 120E23          R2
+          ! Old=6 km3/year=190m3/s; UNESCO(65-68, p374)=120m3/s; ratio=1.58 
+          ! --> 0.m3/s
+          criver(95) = "Choshui             "
+          inb(95) = 1
+          iirnf(1:1,95) = 12
+          ijrnf(1:1,95) = 48
+          zrnfm(1:jpmois,95) = (/   &
+              65.,      63.,      83.,     100.,     177.,     535.,   &
+              332.,     313.,     236.,     193.,     101.,      84./)
+          ! 96-Kaoping (Taiwan)                             R5  
+          ! Old=9 km3/year=285m3/s
+          ! --> 0.m3/s
+          criver(96) = "Kaoping             "
+          inb(96) = 0
+          iirnf(1:1,96) = 0
+          ijrnf(1:1,96) = 0
+          zrnfm(1:jpmois,96) = 285.
+          ! 97-Tsengwen (Taiwan)                            R5
+          ! Old=2 km3/year=63m3/s
+          ! --> 0.m3/s
+          criver(97) = "Tsengwen            "
+          inb(97) = 0
+          iirnf(1:1,97) = 0
+          ijrnf(1:1,97) = 0
+          zrnfm(1:jpmois,97) = 63.
+          ! 98-Hualien (Taiwan)                             R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 0.m3/s
+          criver(98) = "Hualien             "
+          inb(98) = 0
+          iirnf(1:1,98) = 0
+          ijrnf(1:1,98) = 0
+          zrnfm(1:jpmois,98) = 127.
+          ! 99-Peinan (Taiwan) 22N46 121E10                 R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 127.000008m3/s
+          criver(99) = "Peinan              "
+          inb(99) = 1
+          iirnf(1:1,99) = 12
+          ijrnf(1:1,99) = 48
+          zrnfm(1:jpmois,99) = 127.
+          ! 100-Hsiukuluan (Taiwan)                         R5
+          ! Old=4 km3/year=127m3/s
+          ! --> 0.m3/s
+          criver(100) = "Hsiukuluan          "
+          inb(100) = 0
+          iirnf(1:1,100) = 0
+          ijrnf(1:1,100) = 0
+          zrnfm(1:jpmois,100) = 127.
+
+          !  Total run-offs(VII)=6181.33301m3/s
+          
+
+          ! VIII ANTARCTICA
+          ! ---------------
+          ! 103 -Antarctic ice discharge (2 613 Gt/year) (jacobs et al 1992)
+          ! Data from Jacobs et al 92: =2613 km3/year=82857.686454 m3/s
+          ! --> 82858 m3/s
+          criver(103) = "Antarctica         "
+          inb(103) = 108
+          iirnf(1:108,103) = (/   &
+               2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,   &
+              21,22,23,24,25,25,24,24,24,25,26,27,28,29,30,31,32,33,34,   &
+              35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,51,53,   &
+              53,53,53,54,54,54,56,57,57,57,57,57,57,57,57,57,57,58,59,   &
+              60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,   &
+              79,80,81,82,83,84,85,86,87,88,89,90,91 /)
+          ijrnf(1:108,103) = (/   &
+              12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,   &
+              10,10, 9, 9, 8, 7, 6, 5, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,   &
+               3, 4, 5, 6, 6, 6, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,   &
+               8, 9,10,10,11,12,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 2,   &
+               2, 2, 2, 2, 3, 4, 4, 5, 7, 8, 9, 9, 9, 9, 9, 9,10,10,10,   &
+              10,10,10,10,11,12,12,12,12,11,11,10,10 /)
+          zrnfm(1:jpmois,100) = 82858.0
+                   
+
+          !  Total run-offs(I+II+III+IV+V+VI+VII)= 567084. m3/s
+          !                                      = 1.588668056E-6 kg/m2/s
+          !                                      = 17883.5586 km3/Year
+          !                                      = 0.567083955 Sverdrup
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'flxrnf : runoff + orca4'
+         IF(lwp) WRITE(numout,*) '~~~~~~'
+         IF(lwp) WRITE(numout,*) '   nrunoff = ', nrunoff
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! 0. initialization and  indexes  modification for zoom version
+      ! --------------------------------------------------------------
+      
+      
+      ! conversion factor m3/s --> kg/m2/s *e1t*e2t
+
+      zconv = rauw
+
+      IF( kt == nit000 ) THEN 
+         ! Set runoffs and upstream coeff to zero
+         runoff (:,:) = 0.e0                                                                                  
+         upsrnfh(:,:) = 0.e0
+         upsrnfz(:)   = 0.e0
+         upsadv (:,:) = 0.e0
+         zcoefr(:,:,:) = 0.e0
+
+         IF( nrunoff == 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' NO RUNOFF in this simulation '
+            IF(lwp) WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      IF( kt == nit000 ) THEN
+         IF( nrunoff >= 1 ) THEN 
+            zbilan = 0.0 
+!OCL SCALAR
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0 ) THEN
+                  ii = mj0(iirnf(1,jr))
+                  ij = mi0(ijrnf(1,jr))
+                  ii = MAX( 2, MIN( ii, jpi-1 ) )
+                  ij = MAX( 2, MIN( ij, jpj-1 ) )
+!OCL SCALAR
+                  IF( tmask(ii,ij,1) <= 0.5 ) THEN 
+                     IF(lwp) WRITE(numout,*) 'Erreur riviere masquee   ', ii, ij, jr, criver(jr)
+                  ENDIF
+                  IF( tmask(ii-1,ij,1)*tmask(ii+1,ij,1)   &
+                     *tmask(ii,ij-1,1)*tmask(ii,ij+1,1) /= 0. )THEN 
+                     IF(lwp) WRITE(numout,*) 'Erreur riviere non cotiere ',ii, ij, jr, criver(jr)
+                  ENDIF
+                  DO nrnf1 = 1, jpmois
+                     zbilan = zbilan + zrnfm(nrnf1,jr) * tmask(ii,ij,1)
+                  END DO
+               ENDIF
+            END DO
+            IF(lwp) WRITE(numout,*) 'zrnfm (runoff) ', zero, zconv, rauw, SUM(zrnfm)
+            IF(lwp) THEN 
+               WRITE(numout,'("Total runoff : ",1E30.15)' ) zbilan
+               WRITE(numout,*) 'Run-off : POSITION and value '
+               WRITE(numout,*) 'ji jj glamt gphit annual mask 12-month '
+!OCL SCALAR
+               DO jr = 1, jpriv-1
+                  inbp = inb(jr)
+                  IF(inbp /= 0) THEN
+!OCL SCALAR
+                     DO jl = 1, inbp
+                        ii = mj0(iirnf(jl,jr))
+                        ij = mi0(ijrnf(jl,jr))
+                        WRITE(numout,'(2I3,1X,1A20,2X,2I4,2F7.1,1I3,1PE10.1,1I2,12E9.1)')   &
+                           jr, jl, criver(jr),   &
+                           ii, ij, glamt(ii,ij), gphit(ii,ij), inbp,   &
+                           SUM(zrnfm(1:jpmois,jr))/float(inbp),   &
+                           NINT(tmask(ii,ij,1)),   &
+                           zrnfm(1:jpmois,jr)/float(inbp)
+                     END DO
+                  ENDIF
+               END DO
+            ENDIF
+            IF(lwp) WRITE(numout,*) ' zrnfm (runoff) ', zero, zconv, rauw, SUM(zrnfm)
+         ENDIF
+      ENDIF
+
+      ! 1. initialization of the runoff array
+      ! -------------------------------------
+
+      IF( nrunoff == 1 .OR. nrunoff == 2) THEN
+
+         iman  = jpmois
+         
+         i15 = nday/16
+         
+         imois = nmonth + i15 - 1
+         IF( imois == 0) imois = iman
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            ! Number of Day Between Data
+            idbd = nbiss(imois)
+         ELSEIF( nleapy > 1 ) THEN
+            idbd = nleapy
+         ELSE
+            idbd = nobis(imois)
+         ENDIF
+         ! Number of days between imois, 15 and the end of month
+         idmeom = idbd - 15
+         
+         ! 1.1 Calendar computation
+         
+         ! nrnf1 number of the first array record used in the simulation
+         ! nrnf2 number of the last  array record
+         
+         nrnf1 = imois
+         nrnf2 = nrnf1 + 1
+         nrnf1 = MOD( nrnf1, iman )
+         IF( nrnf1 == 0 ) nrnf1 = iman
+         nrnf2 = MOD( nrnf2, iman )
+         IF( nrnf2 == 0 ) nrnf2 = iman
+         
+         IF( kt == nit000 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'flxrnf routine'
+            IF(lwp) WRITE(numout,*) 'first array record used nrnf1 ',nrnf1
+            IF(lwp) WRITE(numout,*) 'last  array record used nrnf2 ',nrnf2
+            IF(lwp) WRITE(numout,*) 'total zrnfm ', SUM(zrnfm)
+            IF(lwp) WRITE(numout,*) 'total surface ', SUM(e1t*e2t*tmask(:,:,1))
+         ENDIF
+
+         zxy = FLOAT( nday + idmeom - idbd * i15 ) / idbd
+
+!OCL SCALAR
+         DO jr = 1, jpriv-1
+            inbp = inb(jr)
+!OCL SCALAR
+            IF( inbp /= 0 ) THEN
+               DO jl = 1, inbp
+                  ii = iirnf(jl,jr) - nimpp + 1 - jpizoom + 1
+                  ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom + 1
+                  iipt0 = MAX( 1, MIN( ii, jpi   ) )
+                  iipt1 = MAX( 0, MIN( ii, jpi-1 ) )
+                  ijpt0 = MAX( 1, MIN( ij, jpj   ) )
+                  ijpt1 = MAX( 0, MIN( ij, jpj-1 ) )
+                  DO jj = ijpt0, ijpt1
+                     DO ji = iipt0, iipt1
+                        runoff(ji,jj) = runoff(ji,jj)   & 
+                                      + ( (1.-zxy) * zrnfm(nrnf1,jr)   &
+                                      +       zxy  * zrnfm(nrnf2,jr)  ) / FLOAT(inbp)      
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+
+
+         ! 2. conversion in mm/day
+         ! -----------------------
+         !     C a u t i o n : upward water flux, runoff is negative
+
+         runoff(:,:) = -zconv * runoff(:,:) / ( e1t(:,:) * e2t(:,:) )
+         
+
+         ! 3. advectve coefficient
+         ! -----------------------
+
+         !  Creates the array coef that contains the coefficient to affect to
+         !  the upstream scheme. advection scheme will be:
+         !  coefr * upstream + (1- coefr) centered
+         !  coefr must be between 0 and 1.
+         !  3 values are used: maximum = zrup1, between zrup2, small zrup3.
+         ! 
+         IF( nrunoff == 2 .AND. kt == nit000 ) THEN
+
+            zrup1 = 0.5
+            zrup2 = 0.25
+            zrup3 = 0.125
+            DO jr = 1, jpriv-1
+               inbp = inb(jr)
+               IF( inbp /= 0) THEN
+                  DO jl = 1, inbp
+                     ! --> zrup1 (originally, = 1 = all upstream).
+                     ! ji,jj
+                     ii = iirnf(jl,jr) - nimpp + 1 - jpizoom - 1
+                     ij = ijrnf(jl,jr) - njmpp + 1 - jpjzoom - 1
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = zrup1
+                           END DO
+                           zcoefr(ji,jj,4) = zrup2
+                           zcoefr(ji,jj,5) = zrup3
+                        END DO
+                     END DO
+                     ! --> zrup2 (originally = 0.5)
+                     ! ji,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj-1
+                     iipt0 = MAX( 1, MIN( ii+1, jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1, jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj
+                     ijpt0 = MAX( 1, MIN( ij, jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij, jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji+1,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj+1
+                     iipt0 = MAX( 1, MIN( ii-1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! ji-1,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup2, zcoefr(ji,jj,jn) )
+                           END DO
+                           zcoefr(ji,jj,4) = MAX( zrup3, zcoefr(ji,jj,4) )
+                        END DO
+                     END DO
+                     ! --> zrup3 (originally = 0.25)
+                     ! ji-1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-1,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj-2
+                     iipt0 = MAX( 1, MIN( ii,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj-2
+                     iipt0 = MAX( 1, MIN( ii+1,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+1,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+1,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-2
+                     iipt0 = MAX( 1, MIN( ii+2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii+2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3  
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji+2,jj
+                     ijpt0 = MAX( 1, MIN( ij,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj
+                     iipt0 = MAX( 1, MIN( ii-2,jpi  ) )
+                     iipt1 = MAX( 0, MIN( ii-2,jpi-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3        
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-2
+                     ijpt0 = MAX( 1, MIN( ij-2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+2
+                     ijpt0 = MAX( 1, MIN( ij+2,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+2,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj-1
+                     ijpt0 = MAX( 1, MIN( ij-1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij-1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                     ! ji-2,jj+1
+                     ijpt0 = MAX( 1, MIN( ij+1,jpj  ) )
+                     ijpt1 = MAX( 0, MIN( ij+1,jpj-1) )
+                     DO jj = ijpt0, ijpt1
+                        DO ji = iipt0, iipt1
+                           DO jn = 1, 3 
+                              zcoefr(ji,jj,jn) = MAX( zrup3, zcoefr(ji,jj,jn) )
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            END DO
+            upsrnfh(:,:) = zcoefr(:,:,1)
+            upsrnfz(:)   = 0.e0
+            upsrnfz(1)   = 1.0
+            upsrnfz(2)   = 1.0
+            upsrnfz(3)   = zrup1
+            upsrnfz(4)   = zrup2
+            upsrnfz(5)   = zrup3
+         ENDIF
+      ENDIF
+      
+      ! Upstream and centered scheme in the vicinity of some straits
+      
+      IF( kt == nit000 ) THEN
+
+         ! ORCA_R4 configuration :
+         ! Gibraltar Strait
+         DO jj = mj0(52), mj1(53)
+            DO ji = mi0(70), mi1(71)
+               upsadv(ji,jj) = 0.5
+            END DO
+         END DO
+
+      ENDIF
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/oasis4_date.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/oasis4_date.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/oasis4_date.F90	(revision 4536)
@@ -0,0 +1,33 @@
+MODULE oasis4_date
+   !!---------------------------------------------------------------------
+   !!                     ***  oasis_date.h90  ***  
+   !!   Date and related information required to couple NEMO via OASIS4
+   !!   Made separate from cpl_oasis4 module to allow wider use.
+   !!=====================================================================
+   !! History :   
+   !!   9.0  !  05-12  (R. Hill, Met. Office) Original code
+   !!----------------------------------------------------------------------
+#if defined key_oasis4
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+!   Following line must be enabled if coupling with OASIS
+!   USE PRISM
+!##################### WARNING coupled mode ###############################
+!##################### WARNING coupled mode ###############################
+
+   IMPLICIT NONE
+
+   INTEGER :: date_err, date_info
+   !!---------------------------------------------------------------------
+   TYPE(PRISM_Time_struct), PUBLIC    :: dates          ! date info for send operation
+   TYPE(PRISM_Time_struct), PUBLIC    :: dates_bound(2) ! date info for send operation
+   TYPE(PRISM_Time_struct), PUBLIC    :: dater          ! date info for receive operation
+   TYPE(PRISM_Time_struct), PUBLIC    :: dater_bound(2) ! date info for receive operation
+   TYPE(PRISM_Time_struct), PUBLIC    :: tmpdate
+#endif
+END MODULE oasis4_date
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/ocesbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/ocesbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/ocesbc.F90	(revision 4536)
@@ -0,0 +1,897 @@
+MODULE ocesbc
+   !!======================================================================
+   !!                     ***  MODULE  ocesbc  ***
+   !!                     Ocean surface boundary conditions
+   !!======================================================================
+   !! History :   -   !  00-10  (O. Marti)  Original code
+   !!            1.0  !  02-12  (G. Madec)  F90: Free form and module
+   !!            2.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!            2.4  !  08-01  (G. Madec)  suppress dmp (internal damping contribution)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   oce_sbc     : ???
+   !!   oce_sbc_dmp : ???
+   !!----------------------------------------------------------------------
+   USE oce            ! dynamics and tracers variables
+   USE dom_oce        ! ocean space domain variables
+   USE cpl_oce        ! coupled ocean-atmosphere variables
+   USE ice_oce        ! sea-ice variable
+   USE blk_oce        ! bulk variables
+   USE flx_oce        ! sea-ice/ocean forcings variables
+   USE phycst         ! Define parameters for the routines
+   USE taumod         ! surface stress forcing
+   USE flxmod         ! thermohaline fluxes
+   USE flxrnf         ! runoffs forcing
+   USE dtatem         ! ocean temperature data
+   USE dtasal         ! ocean salinity data
+   USE ocfzpt         ! surface ocean freezing point
+   USE lbclnk         ! ocean lateral boundary condition
+   USE lib_mpp        ! distribued memory computing library
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC oce_sbc    ! routine called by step
+
+   !! * Shared module variables
+   REAL(wp), PUBLIC ::   &  !:
+      aplus, aminus,     &  !:
+      empold = 0.e0         !: current year freshwater budget correction
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      qt  ,         &  !: total surface heat flux (w/m2)
+      qsr ,         &  !: solar radiation (w/m2)
+      qla ,         &  !: Latent heat flux (W/m2)
+      qlw ,         &  !: Long Wave Heat Flux (W/m2)
+      qsb ,         &  !: Sensible Heat Flux (W/m2)
+      emp ,         &  !: evaporation minus precipitation (kg/m2/s = mm/s)
+      emps,         &  !: evaporation - precipitation (free surface)
+      qrp ,         &  !: heat flux damping (w/m2)
+      erp              !: evaporation damping (kg/m2/s = mm/s)
+
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim' :                                   LIM sea-ice model
+   !!----------------------------------------------------------------------
+# if defined key_coupled
+      !!----------------------------------------------------------------------
+      !!   'key_coupled' :                            Coupled Ocean/Atmosphere
+      !!----------------------------------------------------------------------
+
+   SUBROUTINE oce_sbc( kt )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE oce_sbc  ***
+      !!                    
+      !! ** Purpose :   Ocean surface boundaries conditions with 
+      !!        Louvain la Neuve Sea Ice Model in coupled mode
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   ztx, ztaux, zty, ztauy
+      REAL(wp) ::   ztdta, ztgel, zqrp
+      !!----------------------------------------------------------------------
+
+      ! 1. initialization to zero at kt = nit000
+      ! ---------------------------------------
+
+      IF( kt == nit000 ) THEN     
+         qsr   (:,:) = 0.e0
+         freeze(:,:) = 0.e0
+         qt    (:,:) = 0.e0
+         qrp   (:,:) = 0.e0
+         emp   (:,:) = 0.e0
+         emps  (:,:) = 0.e0
+         erp   (:,:) = 0.e0
+      ENDIF
+
+      IF( MOD( kt-1, nfice ) == 0 ) THEN 
+
+         CALL oce_sbc_dmp   ! Computation of internal and evaporation damping terms       
+
+         ! Surface heat flux (W/m2)
+         ! -----------------------
+
+         ! restoring heat flux
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztgel = fzptn(ji,jj)
+#if defined key_dtasst
+               ztdta = MAX( sst(ji,jj),    ztgel )
+#else
+               ztdta = MAX( t_dta(ji,jj,1), ztgel )
+#endif
+               zqrp = dqdt0 * ( tb(ji,jj,1) - ztdta )
+
+               qrp(ji,jj) = (1.0-freeze(ji,jj) ) * zqrp
+            END DO
+         END DO
+
+         ! non solar heat flux + solar flux + restoring
+         qt (:,:) = fnsolar(:,:) + fsolar(:,:) + qrp(:,:)
+
+         ! solar flux
+         qsr(:,:) = fsolar(:,:)
+
+#if ! defined key_dynspg_rl  
+         ! total concentration/dilution effect (use on SSS)
+         emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:)
+
+         ! total volume flux (use on sea-surface height)
+         emp (:,:) = fmass(:,:)  + runoff(:,:) + erp(:,:)
+#else
+         ! Rigid-lid (emp=emps=E-P-R+Erp) 
+         ! freshwater flux
+         emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:)
+         emp (:,:) = emps(:,:)
+#endif
+
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vertor opt.
+               ztx   = 0.5 * ( freeze(ji+1,jj) + freeze(ji+1,jj+1) )
+               ztaux = 0.5 * ( ftaux (ji+1,jj) + ftaux (ji+1,jj+1) )
+               taux(ji,jj) = (1.0-ztx) * taux(ji,jj) + ztx * ztaux
+
+               zty   = 0.5 * ( freeze(ji,jj+1) + freeze(ji+1,jj+1) )
+               ztauy = 0.5 * ( ftauy (ji,jj+1) + ftauy (ji+1,jj+1) )
+               tauy(ji,jj) = (1.0-zty) * tauy(ji,jj) + zty * ztauy
+            END DO
+         END DO
+         CALL lbc_lnk( taux, 'U', -1. )
+         CALL lbc_lnk( tauy, 'V', -1. )    
+
+         ! Re-initialization of fluxes
+         sst_io(:,:) = 0.e0
+         sss_io(:,:) = 0.e0
+         u_io  (:,:) = 0.e0
+         v_io  (:,:) = 0.e0
+         gtaux (:,:) = 0.e0
+         gtauy (:,:) = 0.e0
+
+      ENDIF
+
+   END SUBROUTINE oce_sbc
+
+# elif defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+      !!----------------------------------------------------------------------
+      !!   'key_ice_lim'                              with  LIM sea-ice model
+      !!----------------------------------------------------------------------
+
+   SUBROUTINE oce_sbc( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE oce_sbc  ***
+      !!                    
+      !! ** Purpose : - Ocean surface boundary conditions with LIM sea-ice
+      !!        model in forced mode using bulk formulea
+      !!
+      !! History :
+      !!   1.0  !  99-11  (M. Imbard)  Original code
+      !!        !  01-03  (D. Ludicone, E. Durand, G. Madec) free surf.
+      !!   2.0  !  02-09  (G. Madec, C. Ethe)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   ztx, ztaux, zty, ztauy
+      !!----------------------------------------------------------------------
+
+      ! 1. initialization to zero at kt = nit000
+      ! ---------------------------------------
+
+      IF( kt == nit000 ) THEN     
+         qsr    (:,:) = 0.e0
+         qt     (:,:) = 0.e0
+         qla    (:,:) = 0.e0
+         qlw    (:,:) = 0.e0
+         qsb    (:,:) = 0.e0
+         qrp    (:,:) = 0.e0
+         emp    (:,:) = 0.e0
+         emps   (:,:) = 0.e0
+         erp    (:,:) = 0.e0
+      ENDIF
+#if defined key_flx_core
+      qla(:,:) = (1 - freeze(:,:))*qla_oce + freeze(:,:)*qla_ice(:,:)
+      qsb(:,:) = (1 - freeze(:,:))*qsb_oce + freeze(:,:)*qsb_ice(:,:)
+      qlw(:,:) = (1 - freeze(:,:))*qlw_oce + freeze(:,:)*qlw_ice(:,:)
+#endif
+      IF( MOD( kt-1, nfice ) == 0 ) THEN
+
+         CALL oce_sbc_dmp       ! Computation of internal and evaporation damping terms       
+
+         ! Surface Ocean fluxes
+         ! ====================
+
+         ! Surface heat flux (W/m2)
+         ! -----------------
+
+         qt  (:,:) = fnsolar(:,:) + fsolar(:,:)     ! non solar heat flux + solar flux
+         qsr (:,:) = fsolar(:,:)                     ! solar flux
+
+#if ! defined key_dynspg_rl     
+         ! total concentration/dilution effect (use on SSS)
+         emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:) + empold
+
+         ! total volume flux (use on sea-surface height)
+         emp (:,:) = fmass(:,:)              + runoff(:,:) + erp(:,:) + empold      
+#else
+         ! Rigid-lid (emp=emps=E-P-R+Erp)
+         emps(:,:) = fmass(:,:) + fsalt(:,:) + runoff(:,:) + erp(:,:)     ! freshwater flux
+         emp (:,:) = emps(:,:)
+
+#endif
+
+         ! Surface stress
+         ! --------------
+
+         ! update the stress beloww sea-ice area
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vertor opt.
+               ztx         = MAX( freezn(ji,jj), freezn(ji,jj+1) )   ! ice/ocean indicator at U- and V-points
+               zty         = MAX( freezn(ji,jj), freezn(ji+1,jj) )
+               ztaux       = 0.5 *( ftaux(ji+1,jj) + ftaux(ji+1,jj+1) ) ! ice-ocean stress at U- and V-points
+               ztauy       = 0.5 *( ftauy(ji,jj+1) + ftauy(ji+1,jj+1) )
+               taux(ji,jj) = (1.-ztx) * taux(ji,jj) + ztx * ztaux    ! stress at the ocean surface
+               tauy(ji,jj) = (1.-zty) * tauy(ji,jj) + zty * ztauy
+            END DO
+         END DO
+
+         ! boundary condition on the stress (taux,tauy)
+         CALL lbc_lnk( taux, 'U', -1. )
+         CALL lbc_lnk( tauy, 'V', -1. )
+
+         ! Re-initialization of fluxes
+         sst_io(:,:) = 0.e0
+         sss_io(:,:) = 0.e0
+         u_io  (:,:) = 0.e0
+         v_io  (:,:) = 0.e0
+
+      ENDIF
+
+   END SUBROUTINE oce_sbc
+
+# else
+      !!----------------------------------------------------------------------
+      !!   Error option               LIM sea-ice model requires bulk formulea
+      !!----------------------------------------------------------------------
+      This line forced a compilation error
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                 NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+# if defined key_coupled
+      !!----------------------------------------------------------------------
+      !!   'key_coupled' :                            Coupled Ocean/Atmosphere
+      !!----------------------------------------------------------------------
+
+   SUBROUTINE oce_sbc( kt )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE oce_sbc  ***
+      !!                    
+      !! ** Purpose :   Ocean surface boundaries conditions in 
+      !!                coupled ocean/atmosphere case without sea-ice
+      !!
+      !! History :
+      !!   1.0  !  00-10  (O. Marti)  Original code
+      !!   2.0  !  02-12  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE cpl_oce       ! coupled ocean-atmosphere variables
+
+      !! * Arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jf         ! dummy loop indices
+      REAL(wp) ::   ztgel,          &  ! temporary scalars
+         zice, zhemis, zqrp, zqri,  &  !    "         "
+         zq, zqi, zerp, ze, zei, zro   !    "         "
+      !!----------------------------------------------------------------------
+
+      ! Compute fluxes
+      ! --------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+            ztgel = fzptn(ji,jj)   ! local freezing temperature
+
+            ! opa model ice freeze()
+
+            zice = tmask(ji,jj,1)
+            IF( tn(ji,jj,1) >=  ztgel ) zice = 0.
+            freeze(ji,jj) = zice
+
+            ! hemisphere indicator (=1 north, =-1 south)
+
+            zhemis = float(isign(1, mjg(jj)-(jpjglo/2+1)))
+
+            ! a) net downward radiative flux qsr()
+            ! - AGCM qsrc if no ice
+            ! - zero under ice (zice=1)
+
+            qsr(ji,jj) = (1.-zice)*qsrc(ji,jj)*tmask(ji,jj,1)
+
+            ! b) heat flux damping term qrp()
+            ! - no damping if no  ice      (zice=0) 
+            ! - gamma*min(0,t-tgel) if ice (zice=1)
+
+            zqrp = 0.
+            zqri = dqdt0*MIN( 0., tb(ji,jj,1)-ztgel )
+            qrp(ji,jj) = ( ( 1. - zice ) * zqrp + zice * zqri ) * tmask(ji,jj,1)
+
+
+            ! c) net downward heat flux q() = q0 + qrp()
+            ! for q0
+            ! - AGCM qc if no  ice (zice=0)
+            ! - -2 watt/m2 (arctic) or -4 watt/m2 (antarctic) if ice (zice=1)
+            zq  = qc(ji,jj)
+            zqi = -3. + zhemis
+            qt(ji,jj) = ( (1.-zice) * zq + zice * zqi ) * tmask(ji,jj,1) + qrp(ji,jj)
+
+            ! d) water flux damping term erp()
+            ! - no damping
+            zerp = 0.
+            erp(ji,jj) = zerp
+
+            ! e) net upward water flux e() = eo + runoff() + erp()
+            ! for e0
+            ! - AGCM if no ice (zice=0)
+            ! - 1.mm/day if climatological and opa ice (zice=1)
+            ze  = ec(ji,jj)
+            zei = 1./rday
+            zro = runoff(ji,jj)
+            emp(ji,jj) = ( ( 1. - zice ) *  ze + zice * zei + zro ) * tmask(ji,jj,1) + erp(ji,jj)
+
+            ! f) net upward water flux for the salinity surface 
+            !    boundary condition
+            emps(:,:) = emp(:,:)
+
+         END DO
+      END DO
+
+   END SUBROUTINE oce_sbc
+# elif defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily || defined key_flx_core
+      !!-------------------------------------------------------------------------
+      !!   'key_flx_bulk_monthly' or 'key_flx_bulk_daily' or  core   bulk formulea
+      !!   'key_flx_forced_daily'                                or no bulk case 
+      !!-------------------------------------------------------------------------
+
+   SUBROUTINE oce_sbc( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE oce_sbc  ***
+      !!                    
+      !! ** Purpose :   Ocean surface boundary conditions in forced mode
+      !!      using either flux or bulk formulation.
+      !!
+      !! History :
+      !!   1.0  !  99-11  (M. Imbard)  Original code
+      !!        !  01-03  (D. Ludicone, E. Durand, G. Madec) free surf.
+      !!   2.0  !  02-09  (G. Madec, C. Ethe)  F90: Free form and module
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE daymod                 ! calendar
+#if ! defined key_dtasst
+      USE dtasst, ONLY : rclice  ! sea surface temperature data
+#endif
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+      USE blk_oce                ! bulk variables
+#endif
+#if defined key_flx_forced_daily
+      USE flx_oce                ! sea-ice/ocean forcings variables
+#endif
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * local declarations
+      INTEGER ::   ji, jj        ! dummy loop arguments
+      INTEGER ::   i15, ifreq             !      
+      REAL(wp) ::  zxy
+      REAL(wp) ::  zsice, zqri, zqrp, ztdta, zqrj
+      REAL(wp) ::  zq, zqi, zhemis
+      REAL(wp), DIMENSION(jpi,jpj) :: zeri, zerps, ziclim
+      REAL(wp), DIMENSION(jpi,jpj) :: zqt, zqsr, zemp  
+      !!----------------------------------------------------------------------
+ 
+
+#if defined key_flx_core
+      CALL ctl_stop( 'flxcore and no ice model not tested yet' )
+#endif
+
+      ! 1. initialization to zero at kt = nit000
+      ! ---------------------------------------
+
+      IF( kt == nit000 ) THEN     
+         qsr    (:,:) = 0.e0
+         freeze (:,:) = 0.e0
+         qt     (:,:) = 0.e0
+         qla    (:,:) = 0.e0
+         qlw    (:,:) = 0.e0
+         qsb    (:,:) = 0.e0
+         qrp    (:,:) = 0.e0
+         emp    (:,:) = 0.e0
+         emps   (:,:) = 0.e0
+         erp    (:,:) = 0.e0
+      ENDIF
+
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+      ifreq      = nfbulk
+      zqt (:,:)  = qsr_oce(:,:) + qnsr_oce(:,:)
+      zqsr(:,:)  = qsr_oce(:,:)
+      zemp(:,:)  = evap(:,:) - tprecip(:,:)
+#endif 
+
+#if defined key_flx_forced_daily
+      ifreq      = 1
+      zqt (:,:)  = p_qt (:,:)
+      zqsr(:,:)  = p_qsr(:,:)
+      zemp(:,:)  = p_emp(:,:)
+#endif 
+#if defined key_flx_core
+      qla(:,:) = (1 - freeze(:,:))*qla_oce + freeze(:,:)*qla_ice(:,:)
+      qsb(:,:) = (1 - freeze(:,:))*qsb_oce + freeze(:,:)*qsb_ice(:,:)
+      qlw(:,:) = (1 - freeze(:,:))*qlw_oce + freeze(:,:)*qlw_ice(:,:)
+#endif 
+      IF( MOD( kt-1, ifreq) == 0 ) THEN
+         ! Computation of internal and evaporation damping terms       
+         CALL oce_sbc_dmp
+
+         zsice = - 0.04 / 0.8    ! ratio of isohaline compressibility over isotherme compressibility 
+                                 ! ( d rho / dt ) / ( d rho / ds )      ( s = 34, t = -1.8 )
+         ! Flux computation
+         DO jj = 1, jpj
+            DO ji = 1, jpi      
+               ! climatological ice 
+               ziclim(ji,jj) = FLOAT( NINT( rclice(ji,jj,1) ) )
+
+               ! avoid surfreezing point            
+               tn(ji,jj,1) = MAX( tn(ji,jj,1), fzptn(ji,jj) )
+
+               ! hemisphere indicator (=1 north, =-1 south)           
+               zhemis = FLOAT( isign(1, mjg(jj) - (jpjdta/2+1) ) )
+
+               ! restoring temperature (ztdta >= to local freezing temperature)            
+#if defined key_dtasst
+               ztdta = MAX( sst(ji,jj),    fzptn(ji,jj) )
+#else
+               ztdta = MAX( t_dta(ji,jj,1), fzptn(ji,jj) )
+#endif
+
+               ! a) net downward radiative flux qsr()           
+               qsr(ji,jj) = (1.-ziclim(ji,jj)) * zqsr(ji,jj) * tmask(ji,jj,1)
+
+               ! b) heat flux damping term qrp()
+               ! - gamma*(t-tlevitus) if no  climatological ice (ziclim=0)
+               ! - gamma*(t-(tgel-1.))  if climatological ice and no opa ice   (ziclim=1 zicopa=0)
+               ! - gamma*min(0,t-tgel) if climatological and opa ice (ziclim=1 zicopa=1)
+
+               zqri = dqdt0 * ( tb(ji,jj,1) - ( fzptn(ji,jj) - 1.) )
+               zqrj = dqdt0 * MIN( 0., tb(ji,jj,1) - fzptn(ji,jj) )
+
+               qrp(ji,jj) =  ( ziclim(ji,jj) * ( (1 - freeze(ji,jj)) * zqri    &
+                 &                                  + freeze(ji,jj)  * zqrj ) ) * tmask(ji,jj,1)
+
+#if ! defined key_flx_bulk_monthly && ! defined key_flx_bulk_daily && ! defined key_flx_core
+               zqrp = dqdt0 * ( tb(ji,jj,1) - ztdta )
+               qrp(ji,jj) = qrp(ji,jj) + (1. - ziclim(ji,jj)) * zqrp
+# endif
+
+               ! c) net downward heat flux q() = q0 + qrp()
+               ! for q0
+               ! - ECMWF fluxes if no climatological ice      (ziclim=0)
+               ! - qrp if climatological ice and no opa ice   (ziclim=1 zicopa=0)
+               ! - -2 watt/m2 (arctic) or -4 watt/m2 (antarctic) if climatological and opa ice 
+               !                                              (ziclim=1 zicopa=1)
+               zq  = zqt(ji,jj)
+               zqi = -3. + zhemis
+               qt (ji,jj) = ( (1.-ziclim(ji,jj)) * zq   &
+                  +ziclim(ji,jj)  * freeze(ji,jj) * zqi )   &
+                  * tmask(ji,jj,1)   &
+                  + qrp(ji,jj)
+
+            END DO
+         END DO
+
+#if ! defined key_dynspg_rl 
+         ! Free-surface
+
+         ! Water flux for zero buoyancy flux if no opa ice and ice clim
+         zeri(:,:) = -zsice * qrp(:,:) * ro0cpr * rauw / 34.0
+         zerps(:,:) = ziclim(:,:) * ( (1-freeze(:,:)) * zeri(:,:) )
+
+         ! Contribution to sea level:
+         ! net upward water flux emp() = e-p + runoff() + erp() + empold
+         emp (:,:) = zemp(:,:)     &   ! e-p data
+            &      + runoff(:,:)   &   ! runoff data
+            &      + erp(:,:)      &   ! restoring term to SSS data
+            &      + empold            ! domain averaged annual mean correction
+
+         ! Contribution to salinity:
+         ! net upward water flux emps() = e-p + runoff() + erp() + zerps + empold
+         emps(:,:) = zemp(:,:)     &
+            &      + runoff(:,:)   &
+            &      + erp(:,:)      &
+            &      + zerps(:,:)    &
+            &      + empold 
+#else
+         ! Rigid-lid (emp=emps=E-P-R+Erp)
+         ! freshwater flux
+         zeri(:,:)  = -zsice * qrp(:,:) * ro0cpr * rauw / 34.0
+         zerps(:,:) = ziclim(:,:) * ( (1-freeze(:,:)) * zeri(:,:) )
+         emps (:,:) = zemp(:,:)     &
+            &       + runoff(:,:)   &
+            &       + erp(:,:)      &
+            &       + zerps(:,:)
+         emp (:,:) = emps(:,:)
+#endif  
+
+         ! Boundary condition on emp for free surface option
+         ! -------------------------------------------------
+         CALL lbc_lnk( emp, 'T', 1. )
+
+      ENDIF
+
+   END SUBROUTINE oce_sbc
+
+# else
+      !!----------------------------------------------------------------------
+      !!   Default option :                                 Analytical forcing
+      !!----------------------------------------------------------------------
+
+   SUBROUTINE oce_sbc( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE oce_sbc  ***
+      !!              
+      !! ** Purpose :   provide the thermohaline fluxes (heat and freshwater)
+      !!                to the ocean at each time step.
+      !!
+      !! ** Method  :   Constant surface fluxes (read in namelist (namflx))
+      !!
+      !! ** Action  : - qt, qsr, emp, emps, qrp, erp
+      !!
+      !! History :
+      !!        !  91-03  ()  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-05  (A. Koch-Larrouy) Add Gyre configuration 
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE flxrnf                       ! ocean runoffs
+      USE daymod, ONLY : nyear         ! calendar
+      USE dtasss                       ! sea surface salinity data
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * local declarations
+      REAL(wp) ::                   & !!! surface fluxes namelist (namflx)
+         q0   = 0.e0,               &  ! net heat flux
+         qsr0 = 0.e0,               &  ! solar heat flux
+         emp0 = 0.e0                   ! net freshwater flux
+      REAL(wp) ::   zsrp,           &
+         zemp_S, zemp_N, zemp_sais, &
+         zTstar, zcos_sais1, zconv, &
+         zcos_sais2
+      REAL(wp) ::           &
+         zsumemp,           &          ! tampon used for the emp sum
+         zsurf,             &          ! tampon used for the domain sum
+         ztime,             &          ! time in hour
+         ztimemax1, ztimemin1, &       ! 21th june,   and 21th december if date0 = 1st january
+         ztimemax2, ztimemin2          ! 21th august, and 21th february if date0 = 1st january
+      REAL(wp), DIMENSION(jpi,jpj) :: t_star
+      INTEGER  ::   ji, jj             ! dummy loop indices
+
+      INTEGER  ::           &
+         zyear0,            &          ! initial year
+         zmonth0,           &          ! initial month
+         zday0,             &          ! initial day
+         zday_year0                    ! initial day since january 1st
+
+      NAMELIST/namflx/ q0, qsr0, emp0
+      !!---------------------------------------------------------------------
+
+      !same temperature, E-P as in HAZELEGER 2000
+
+      IF( cp_cfg == 'gyre' ) THEN
+
+          zyear0  = ndate0 / 10000                              ! initial year
+          zmonth0 = ( ndate0 - zyear0 * 10000 ) / 100           ! initial month
+          zday0   = ndate0 - zyear0 * 10000 - zmonth0 * 100     ! initial day betwen 1 and 30
+          zday_year0= (zmonth0-1)*30.+zday0                     ! initial day betwen 1 and 360
+
+          ! current day (in hours) since january the 1st of the current year
+          ztime = FLOAT( kt ) * rdt / (rmmss * rhhmm)  &    !  total incrementation (in hours)
+             &     - (nyear  - 1) * rjjhh * raajj           !  minus years since beginning of experiment (in hours)
+
+          ! 21th june at 24h  in hours
+          ztimemax1 = ((5.*30.)+21.)* 24.
+          ! 21th december in hours
+          ! rjjhh * raajj / 4 = 1 seasonal cycle in hours
+          ztimemin1 = ztimemax1 + rjjhh * raajj / 2         
+          ! 21th july at 24h in hours
+          ztimemax2 = ((6.*30.)+21.)* 24.
+          ! 21th january day in hours
+          ! rjjhh * raajj / 4 = 1 seasonal cycle in hours
+          ztimemin2 = ztimemax2 - rjjhh * raajj / 2         
+
+          ! amplitudes
+          zemp_S   = 0.7       ! intensity of COS in the South
+          zemp_N   = 0.8       ! intensity of COS in the North
+          zemp_sais= 0.1
+          zTstar   = 28.3      ! intemsity from 28.3 a -5 deg
+
+          ! 1/2 period between 21th June and 21th December
+          zcos_sais1 = COS( (ztime - ztimemax1) / (ztimemin1 - ztimemax1) * rpi )    
+
+          ! 1/2 period between 21th July and 21th January
+          zcos_sais2 = COS( (ztime - ztimemax2) / (ztimemax2 - ztimemin2) * rpi )
+
+          zconv = 3.16e-5      ! convert 1m/yr->3.16e-5mm/s
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                ! domain from 15 deg to 50 deg between 27 and 28  degC at 15N, -3 
+                ! and 13 degC at 50N 53.5 + or - 11 = 1/4 period :
+                ! 64.5 in summer, 42.5 in winter
+                t_star (ji,jj) = zTstar * ( 1 + 1. / 50. * zcos_sais2 )   &                  
+                   &             * COS( rpi * (gphit(ji,jj) - 5.)        &                  
+                   &                        / (53.5 * ( 1 + 11 / 53.5 * zcos_sais2 ) * 2.) ) 
+                qt  (ji,jj) = dqdt0 * ( tb(ji,jj,1) - t_star(ji,jj) )
+                IF( gphit(ji,jj) >= 14.845 .AND. 37.2 >= gphit(ji,jj)) THEN
+                   ! zero at 37.8 deg, max at 24.6 deg
+                   emp  (ji,jj) =   zemp_S * zconv   &
+                      &         * SIN( rpi / 2 * (gphit(ji,jj) - 37.2) / (24.6 - 37.2) )  & 
+                      &         * ( 1 - zemp_sais / zemp_S * zcos_sais1)
+                   emps (ji,jj) = emp  (ji,jj)
+                ELSE
+                   ! zero at 37.8 deg, max at 46.8 deg
+                   emp (ji,jj) =  - zemp_N * zconv   &
+                      &         * SIN( rpi / 2 * (gphit(ji,jj) - 37.2) / (46.8 - 37.2) )  & 
+                      &         * ( 1 - zemp_sais / zemp_N * zcos_sais1 )
+                   emps (ji,jj) = emp  (ji,jj)
+                ENDIF
+                ! 23.5 deg : tropics
+                qsr (ji,jj) =  230 * COS( 3.1415 * ( gphit(ji,jj) - 23.5 * zcos_sais1 ) / ( 0.9 * 180 ) )   
+             END DO
+          END DO
+
+          ! Compute the emp flux such as its integration on the whole domain at each time is zero
+          IF( nbench /= 1 .AND. nbit_cmp /= 1 ) THEN
+             zsumemp = 0.e0   ;   zsurf = 0.e0
+             DO jj = 1, jpj
+                DO ji = 1, jpi
+                   zsumemp = zsumemp + emp(ji,jj) * tmask(ji,jj,1) * tmask_i(ji,jj)
+                   zsurf =  zsurf + tmask(ji,jj,1) * tmask_i(ji,jj)
+                END DO
+             END DO
+
+             IF( lk_mpp )   CALL mpp_sum( zsumemp  )       ! sum over the global domain
+             IF( lk_mpp )   CALL mpp_sum( zsurf    )       ! sum over the global domain
+
+             ! Default GYRE configuration
+             zsumemp = zsumemp / zsurf
+          ELSE
+             ! Benchmark GYRE configuration (to allow the bit to bit comparison between Mpp/Mono case)
+             zsumemp = 0.e0   ;    zsurf = 0.e0
+          ENDIF
+
+          IF( lk_dtasss ) THEN           ! Sea surface salinity damping
+             ! deds0 from (mm/day) => (mm/s)
+             zsrp = deds0 / rday 
+             erp(:,:) = zsrp * ( sss(:,:) - sb(:,:,1) ) / ( sn(:,:,1) + 1.e-20 )
+          ELSE                           ! NO Sea surface salinity damping 
+             zsrp = 0.e0
+             erp(:,:) = 0.e0
+          ENDIF
+
+          ! freshwater fluxes terms
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                emp(ji, jj) =  emp(ji,jj) - zsumemp * tmask(ji,jj,1)
+                emps(ji, jj)=  emp(ji,jj) + erp(ji,jj)
+             END DO
+          END DO
+
+         IF( kt == nit000 .AND. lwp ) THEN
+            WRITE(numout,*)' ocesbc  : analytical formulation for gyre'
+            WRITE(numout,*)' ~~~~~~~ '
+            WRITE(numout,*)'           nyear      = ', nyear
+            WRITE(numout,*)'           ztime      = ',ztime
+            WRITE(numout,*)'           ztimemax1  = ',ztimemax1
+            WRITE(numout,*)'           ztimemin1  = ',ztimemin1
+            WRITE(numout,*)'           ztimemax2  = ',ztimemax2
+            WRITE(numout,*)'           ztimemin2  = ',ztimemin2
+            WRITE(numout,*)'           zyear0     = ', zyear0
+            WRITE(numout,*)'           zmonth0    = ', zmonth0
+            WRITE(numout,*)'           zday0      = ', zday0
+            WRITE(numout,*)'           zday_year0 = ',zday_year0
+            WRITE(numout,*)'           raajj      = ', raajj
+            WRITE(numout,*)'           zemp_S     = ',zemp_S 
+            WRITE(numout,*)'           zemp_N     = ',zemp_N 
+            WRITE(numout,*)'           zemp_sais  = ',zemp_sais
+            WRITE(numout,*)'           zTstar     = ',zTstar 
+            WRITE(numout,*)'           zsumemp    = ',zsumemp
+            WRITE(numout,*)'           zsurf      = ',zsurf 
+            WRITE(numout,*)'           dqdt0      = ',dqdt0
+            WRITE(numout,*)'           deds0      = ',deds0
+            WRITE(numout,*)'           zconv      = ',zconv 
+         ENDIF
+
+      ELSE
+
+         ! Constant surface fluxes
+
+         IF( kt == nit000 ) THEN
+            IF(lwp) THEN
+               WRITE(numout,*)' '
+               WRITE(numout,*)' ocesbc  : Constant surface fluxes read in namelist'
+               WRITE(numout,*)' ~~~~~~~ '
+               WRITE(numout,*)'           Namelist namflx: set the constant flux values'
+               WRITE(numout,*)'              net heat flux          q0   = ', q0  , ' W/m2'
+               WRITE(numout,*)'              solar heat flux        qsr0 = ', qsr0, ' W/m2'
+               WRITE(numout,*)'              net heat flux          emp0 = ', emp0, ' W/m2'
+            ENDIF
+
+            qt    (:,:) = q0
+            qsr   (:,:) = qsr0
+            emp   (:,:) = emp0
+            emps  (:,:) = emp0
+            qrp   (:,:) = 0.e0
+            erp   (:,:) = 0.e0
+
+            runoff(:,:) = 0.e0
+         ENDIF
+
+      ENDIF
+
+   END SUBROUTINE oce_sbc
+
+# endif
+#endif
+
+#if defined key_dtasal
+   !!----------------------------------------------------------------------
+   !!   'key_dtasal'                                          salinity data
+   !!----------------------------------------------------------------------
+   SUBROUTINE oce_sbc_dmp
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE oce_sbc_dmp  ***
+      !!                    
+      !! ** Purpose : Computation of internal and evaporation damping terms 
+      !!        for ocean surface boundary conditions 
+      !!
+      !! History :
+      !!   9.0  !  04-01  (G. Madec, C. Ethe)  Original code
+      !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj                   ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj)  :: zsss, zfreeze
+      REAL(wp) ::   zerp, zsrp
+      CHARACTER (len=71) :: charout
+#if ! defined key_dynspg_rl
+      REAL(wp) ::   zwei
+      REAL(wp) ::   zerpplus(jpi,jpj), zerpminus(jpi,jpj)
+      REAL(wp) ::   zplus, zminus, zadefi
+#endif
+      !!----------------------------------------------------------------------
+
+#if defined key_ice_lim
+      ! sea ice indicator (1 or 0)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            freezn(ji,jj) = MAX(0., SIGN(1., freeze(ji,jj)-rsmall) )
+         END DO
+      END DO
+      zsss   (:,:) = sss_io(:,:)
+      zfreeze(:,:) = freezn(:,:)
+#else
+      zsss   (:,:) = sb    (:,:,1)
+      zfreeze(:,:) = freeze(:,:)
+#endif
+
+      ! Initialisation
+      ! --------------
+      ! Restoring coefficients on SST and SSS   
+      zsrp = dqdt0 * ro0cpr * rauw   ! (Kg/m2/s) 
+
+#if ! defined key_dynspg_rl 
+      ! Free-surface
+         
+      !   evaporation damping term ( Surface restoring )
+      zerpplus (:,:) = 0.e0
+      zerpminus(:,:) = 0.e0
+      zplus  =  15. / rday
+      zminus = -15. / rday
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zerp = ( 1. - 2.*upsrnfh(ji,jj) ) * zsrp   &
+               & * ( zsss(ji,jj) - s_dta(ji,jj,1) )     &
+               & / ( zsss(ji,jj) + 1.e-20        )
+            
+            zerp = MIN( zerp, zplus  )
+            zerp = MAX( zerp, zminus )
+            erp(ji,jj) = zerp
+            zerpplus (ji,jj) = MAX( erp(ji,jj), 0.e0 )
+            zerpminus(ji,jj) = MIN( erp(ji,jj), 0.e0 )
+         END DO
+      END DO
+
+      aplus  = 0.e0
+      aminus = 0.e0
+
+      IF( nbit_cmp == 1) THEN
+
+         IF(ln_ctl)   THEN
+            WRITE(charout,FMT="('oce_sbc_dmp : a+ = ',D23.16, ' a- = ',D23.16)") aplus, aminus
+            CALL prt_ctl_info(charout)
+         ENDIF
+         erp(:,:) = 0.e0
+
+      ELSE
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwei   = e1t(ji,jj) * e2t(ji,jj) * tmask_i(ji,jj)
+               aplus  = aplus  + zerpplus (ji,jj) * zwei
+               aminus = aminus - zerpminus(ji,jj) * zwei
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( aplus  )   ! sums over the global domain
+         IF( lk_mpp )   CALL mpp_sum( aminus )
+
+         IF(ln_ctl)   THEN
+            WRITE(charout,FMT="('oce_sbc_dmp : a+ = ',D23.16, ' a- = ',D23.16)") aplus, aminus
+            CALL prt_ctl_info(charout)
+         ENDIF
+
+         zadefi = MIN( aplus, aminus )
+         IF( zadefi == 0.e0 ) THEN 
+            erp(:,:) = 0.e0
+         ELSE
+            erp(:,:) = zadefi * ( zerpplus(:,:) / aplus + zerpminus(:,:) / aminus )
+         ENDIF
+
+      END IF
+#else
+      ! Rigid-lid (emp=emps=E-P-R+Erp)
+
+      erp(:,:) = ( 1. - zfreeze(:,:) ) * zsrp    &   ! surface restoring term
+         &     * ( zsss(:,:) - s_dta(:,:,1) )     &
+         &     / ( zsss(:,:) + 1.e-20      )
+#endif
+
+   END SUBROUTINE oce_sbc_dmp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy routine                                      NO salinity data
+   !!----------------------------------------------------------------------
+   SUBROUTINE oce_sbc_dmp         ! Dummy routine
+      WRITE(*,*) 'oce_sbc_dmp: you should not have seen that print! error?'
+   END SUBROUTINE oce_sbc_dmp
+#endif
+
+   !!======================================================================
+END MODULE ocesbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_daily.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_daily.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_daily.h90	(revision 4536)
@@ -0,0 +1,107 @@
+   !!----------------------------------------------------------------------
+   !!                   ***  tau_forced_daily.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tau     :   update the surface stress - daily fields in NetCDF file
+   !!----------------------------------------------------------------------
+   !! * local modules variables
+   INTEGER ::   &
+      numtau,         &  ! logical unit for the i-component of the wind data
+      numtav,         &  ! logical unit for the j-component of the wind data
+      ndaytau            ! new day for ers/ncep tau forcing
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tau( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE tau  ***
+      !!     
+      !! ** Purpose :   provide to the ocean the stress at each time step
+      !!
+      !! ** Method  :   Read the daily surface stress components in NetCDF 
+      !!      file. They are given in the (i,j) referential 
+      !!        The i-component is given at U-point (INTERP package)
+      !!        The j-component is given at V-point (INTERP package)
+      !!
+      !!    CAUTION: never mask the surface stress field !
+      !!
+      !! ** Action  :   update at each time-step the two components of the 
+      !!      surface stress in both (i,j) and geographical referencial
+      !!
+      !! History :
+      !!   4.0  !  91-03  (G. Madec)  Original code
+      !!   6.0  !  92-07  (M. Imbard)
+      !!   8.1  !  00-08  (D. Ludicone) adapted to ERS-NCEP
+      !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+      !!        !  03-07  (C. Ethe, G. Madec)  daily generic forcing
+      !!----------------------------------------------------------------------
+      USE iom       ! NetCDF library
+
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+     
+      !!---------------------------------------------------------------------
+
+      ! -------------------- !
+      ! First call kt=nit000 !
+      ! -------------------- !
+
+      IF( kt == nit000 ) THEN
+         
+         ndaytau = 0   ! initialization
+         IF(lwp) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' tau    : DAILY wind stress in NetCDF files'
+         ENDIF
+         ! open the files
+         CALL iom_open ( 'taux_1d.nc', numtau )
+         CALL iom_open ( 'tauy_1d.nc', numtav )
+         
+      ENDIF
+
+      ! ----------------- !
+      ! Read daily file   !
+      ! ----------------- !
+
+      IF ( ndaytau /= nday ) THEN
+            
+         ndaytau = nday
+            
+         ! Read daily wind stress data
+
+         CALL iom_get ( numtau, jpdom_data, 'taux', taux, nday_year )
+         CALL iom_get ( numtav, jpdom_data, 'tauy', tauy, nday_year )
+            
+         IF (lwp .AND. nitend-nit000 <= 100 ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' read daily wind stress ok'
+            WRITE(numout,*)
+            WRITE(numout,*) ' day: ', ndastp , '  taux: 1 multiply by ', 1.
+            CALL prihre( taux, jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+            WRITE(numout,*)
+            WRITE(numout,*) ' day: ', ndastp , '  tauy: 1 multiply by ', 1.
+            CALL prihre( tauy, jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+            WRITE(numout,*) ' ' 
+         ENDIF
+            
+         CALL FLUSH(numout)
+
+      ENDIF
+         
+      ! ------------------- !
+      ! Last call kt=nitend !
+      ! ------------------- !
+
+      ! Closing of the 2 files
+      IF( kt == nitend ) THEN
+          CALL iom_close( numtau )
+          CALL iom_close( numtav )
+      ENDIF
+         
+   END SUBROUTINE tau
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90	(revision 4536)
@@ -0,0 +1,148 @@
+   !!----------------------------------------------------------------------
+   !!                ***  tau_forced_monthly.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tau     : update the surface wind stress - monthly fields in NetCDF
+   !!             file.
+   !!----------------------------------------------------------------------
+   !! * local modules variables
+   INTEGER ::   &
+      numtau,   &   ! logical unit for the i-component of the wind data
+      numtav,   &   ! logical unit for the j-component of the wind data
+      ntau1, ntau2  ! index of the first and second record used
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   &
+      taux_dta,    &  ! i- and j-components of the surface stress (Pascal)
+      tauy_dta        ! at 2 consecutive months in the (i,j) referential
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tau( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE tau  ***
+      !!              
+      !! ** Purpose :   provide to the ocean the stress at each time step
+      !!
+      !! ** Method  : - Read the 2 monthly surface stress components in NetCDF 
+      !!      file at 2 consecutive time-steps
+      !!        They are given in the (i,j) referential 
+      !!        The i-component is given at U-point (INTERP package)
+      !!        The j-component is given at V-point (INTERP package)
+      !!              - a linear time-interpolation is performed to provide the
+      !!      stress at the kt time-step.
+      !!
+      !!    CAUTION: never mask the surface stress field !
+      !!
+      !! ** Action :
+      !!        update at each time-step the two components of the surface
+      !!      stress in both (i,j) and geographical referencial
+      !!
+      !! History :
+      !!   4.0  !  91-03  (G. Madec)  Original code
+      !!   6.0  !  92-07  (M. Imbard)
+      !!   8.1  !  00-08  (D. Ludicone) adapted to ERS-NCEP
+      !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+      !!        !                     daily/monthly, forced/coupled form
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom      
+      !! * Arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER :: imois, iman, i15
+      REAL(wp) :: zxy          ! coefficient of the linear time interpolation
+      !!---------------------------------------------------------------------
+
+      ! -------------- !
+      ! Initialization !
+      ! -------------- !
+      
+      ! iman=number of dates in data file (12 for a year of monthly values)
+      iman  = INT( raamo )
+      i15 = INT( 2*FLOAT( nday ) / ( FLOAT( nobis(nmonth) ) + 0.5 ) )
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+
+      ! -------------------- !
+      ! First call kt=nit000 !
+      ! -------------------- !
+
+      IF( kt == nit000 ) THEN
+         
+         ntau1 = 0   ! initialization
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' tau    : MONTHLY climatological wind stress (NetCDF files)'
+         ENDIF
+         CALL iom_open ( 'taux_1m.nc', numtau )
+         CALL iom_open ( 'tauy_1m.nc', numtav )
+         
+      ENDIF
+      
+      ! ----------------- !
+      ! Read monthly file !
+      ! ----------------- !
+
+      IF( kt == nit000 .OR. imois /= ntau1 ) THEN
+
+         ! Calendar computation
+         ntau1 = imois          ! index of the first record
+         ntau2 = ntau1 + 1      ! index of the last  record
+         ntau1 = MOD( ntau1, iman )
+         IF( ntau1 == 0 ) ntau1 = iman
+         ntau2 = MOD( ntau2, iman )
+         IF( ntau2 == 0 ) ntau2 = iman
+         IF(lwp) WRITE(numout,*) 'first month used ntau1 = ', ntau1
+         IF(lwp) WRITE(numout,*) 'last  month used ntau2 = ', ntau2
+
+         ! Read the corresponding 2 monthly stress data
+         ! ntau1
+         CALL iom_get ( numtau, jpdom_data, 'sozotaux', taux_dta(:,:,1), ntau1 )
+         CALL iom_get ( numtav, jpdom_data, 'sometauy', tauy_dta(:,:,1), ntau1 )
+
+         CALL iom_get ( numtau, jpdom_data, 'sozotaux', taux_dta(:,:,2), ntau2 )
+         CALL iom_get ( numtav, jpdom_data, 'sometauy', tauy_dta(:,:,2), ntau2 )
+         
+         IF(lwp .AND. nitend-nit000 <= 100 ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' monthly stress read'
+            WRITE(numout,*)
+            WRITE(numout,*) ' month: ', ntau1, '  taux: 1 multiply by ', 1.
+            CALL prihre( taux_dta(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+            WRITE(numout,*)
+            WRITE(numout,*) ' month: ', ntau2, '  tauy: 2 multiply by ', 1.
+            CALL prihre( tauy_dta(:,:,2), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+         ENDIF
+
+         CALL FLUSH(numout)
+
+      ENDIF
+
+      ! ------------------------------- !
+      ! linear time interpolation at kt !
+      ! ------------------------------- !
+
+      ! zxy : coefficient for linear interpolation in time
+
+      zxy = FLOAT( nday ) / FLOAT( nobis(ntau1) ) + 0.5 - i15
+
+      taux(:,:) = (1.-zxy) * taux_dta(:,:,1) + zxy * taux_dta(:,:,2)
+      tauy(:,:) = (1.-zxy) * tauy_dta(:,:,1) + zxy * tauy_dta(:,:,2)
+
+      ! ------------------- !
+      ! Last call kt=nitend !
+      ! ------------------- !
+
+      ! Closing of the 2 files (required in mpp)
+      IF( kt == nitend ) THEN
+          CALL iom_close(numtau)
+          CALL iom_close(numtav)
+      ENDIF
+
+   END SUBROUTINE tau
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_oasis_ice.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_oasis_ice.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/tau_oasis_ice.h90	(revision 4536)
@@ -0,0 +1,120 @@
+   !!----------------------------------------------------------------------
+   !!                   ***  tau_oasis_ice.h90  ***
+   !!----------------------------------------------------------------------
+
+   REAL(wp)  :: ztaueuw (1:jpi,1:jpj)  ! eastward wind stress over water 
+   REAL(wp)  :: ztaunuw (1:jpi,1:jpj)  ! northward wind stress over water 
+   REAL(wp)  :: ztaueui (1:jpi,1:jpj)  ! eastward wind stress over ice
+   REAL(wp)  :: ztaunui (1:jpi,1:jpj)  ! northward wind stress over ice 
+   REAL(wp)  :: ztaueu  (1:jpi,1:jpj)  ! eastward wind stress combined
+   REAL(wp)  :: ztaunu  (1:jpi,1:jpj)  ! northward wind stress combined 
+   REAL(wp)  :: ztauevw (1:jpi,1:jpj)
+   REAL(wp)  :: ztaunvw (1:jpi,1:jpj)
+   REAL(wp)  :: ztauevi (1:jpi,1:jpj)
+   REAL(wp)  :: ztaunvi (1:jpi,1:jpj)
+   REAL(wp)  :: ztauev  (1:jpi,1:jpj)
+   REAL(wp)  :: ztaunv  (1:jpi,1:jpj)
+   REAL(wp)  :: ztauzv  (1:jpi,1:jpj)
+
+   !!----------------------------------------------------------------------
+   !!   tau     :   update the surface stress - coupled case with LIM
+   !!               sea-ice model
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/SBC/tau_oasis_ice.h90,v 1.2 2007/06/29 14:23:07 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tau( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE tau  ***
+      !!  
+      !! ** Purpose :   provide to the ocean the stress at each time step
+      !!
+      !! ** Method  :   Coupled case with LIM sea-ice model
+      !!      Read wind stress from a coupled Atmospheric model
+      !!      - horizontal interpolation is done in OASIS
+      !!        They are given in the 3D referential 
+      !!      (3 components at both U- and V-points)
+      !!
+      !!    CAUTION: never mask the surface stress field !
+      !!
+      !! ** Action  :   update at each time-step the two components of the 
+      !!                surface stress in both (i,j) and geographical ref.
+      !!
+      !! References : The OASIS User Guide, Version 3.0
+      !!
+      !! History :
+      !!   9.0  !  04-10  (R. Redler)  original Code for OASIS3
+      !!   9.0  !  05-12  (W. Park, N. Keenlyside)  Removal of z-components
+      !!----------------------------------------------------------------------
+      !! * Modules used
+     USE in_out_manager, only:numout             ! I/O manager
+      !! * Arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER :: ji,jj
+      INTEGER :: var_id
+
+      INTEGER  :: info
+
+      INTEGER  :: dater
+
+      LOGICAL, SAVE :: lfirstt=.true.
+
+      !!---------------------------------------------------------------------
+      
+      ! 0. Initialization
+      !------------------
+      !
+      dater = ( kt - nit000 ) * rdttra(1)
+      !
+      ! 1. Receive wind stress fields and rotate them onto OPA grid
+      !------------------------------------------------------------
+      !
+      var_id = recv_id(1)
+      CALL cpl_prism_recv ( var_id, dater, ztaueuw, info )
+
+      var_id = recv_id(2)
+      CALL cpl_prism_recv ( var_id, dater, ztaunuw, info )
+
+      var_id = recv_id(3)
+      CALL cpl_prism_recv ( var_id, dater, ztaueui, info )
+
+      var_id = recv_id(4)
+      CALL cpl_prism_recv ( var_id, dater, ztaunui, info )
+
+      var_id = recv_id(5)
+      CALL cpl_prism_recv ( var_id, dater, ztauevw, info )
+
+      var_id = recv_id(6)
+      CALL cpl_prism_recv ( var_id, dater, ztaunvw, info )
+
+      var_id = recv_id(7)
+      CALL cpl_prism_recv ( var_id, dater, ztauevi, info )
+
+      var_id = recv_id(8)
+      CALL cpl_prism_recv ( var_id, dater, ztaunvi, info )
+
+      !
+      ! ... add field over water and ice 
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+              ztaueu(ji,jj) = ztaueuw(ji,jj) * frld(ji,jj) + ztaueui(ji,jj) * ( 1.0 - frld(ji,jj) )
+              ztaunu(ji,jj) = ztaunuw(ji,jj) * frld(ji,jj) + ztaunui(ji,jj) * ( 1.0 - frld(ji,jj) )
+              ztauev(ji,jj) = ztauevw(ji,jj) * frld(ji,jj) + ztauevi(ji,jj) * ( 1.0 - frld(ji,jj) )
+              ztaunv(ji,jj) = ztaunvw(ji,jj) * frld(ji,jj) + ztaunvi(ji,jj) * ( 1.0 - frld(ji,jj) )
+         ENDDO
+      ENDDO
+      !
+      ! ... rotate vector components
+      !
+      CALL repcmo ( ztaueu, ztaunu, ztauev, ztaunv, taux, tauy )
+
+      !
+   END SUBROUTINE tau
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/taumod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/taumod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SBC/taumod.F90	(revision 4536)
@@ -0,0 +1,207 @@
+MODULE taumod
+   !!======================================================================
+   !!                       ***  MODULE  taumod  ***
+   !! Ocean forcing : stress at the the ocean surface
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   tau          : define the surface stress for the ocean
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE lbclnk          ! 
+
+#if defined key_oasis3 || defined key_oasis4
+   USE geo2ocean, only : repcmo
+   USE ice, only       : frld       ! : leads fraction = 1-a/totalarea
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling (to ECHAM5)
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (to ECHAM5)
+#endif
+#endif
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tau                ! routine called by step.F90
+
+   !! * Share modules variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &
+      taux, tauy             !: surface stress components in (i,j) referential
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+#if defined key_tau_monthly
+   ! Monthly climatology in (i,j) referential  (i-comp. at U-pt and j-comp. at V-pt)
+   !!----------------------------------------------------------------------
+   !!   'key_tau_monthly'                        MONTHLY climatology stress
+   !!   default case                                   NetCDF files
+   !!----------------------------------------------------------------------
+#   include "tau_forced_monthly.h90"
+
+# elif defined key_tau_daily
+   !!----------------------------------------------------------------------
+   !!   'key_tau_daily'                                 DAILY stress
+   !!                                                   NetCDF files
+   !!----------------------------------------------------------------------
+   ! Daily climatology/interannual in (i,j) referential  (i-comp. at U-pt and j-comp. at V-pt)
+#   include "tau_forced_daily.h90"
+
+#elif defined key_oasis3  ||  defined key_oasis4
+   ! Coupled case : stress at the coupling frequency
+   !!----------------------------------------------------------------------
+   !!   'key_oasis3' or 'key_oasis4' and           Coupled Ocean/Atmosphere
+   !!   'key_ice_lim'                                   LIM sea-ice
+   !!----------------------------------------------------------------------
+   ! New way: 3D referential link to the earth (avoid north pole pb)
+   ! (3 component stress defined at U- and V-points)
+#  include "tau_oasis_ice.h90"
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                     constant forcing
+   !!----------------------------------------------------------------------
+   !! * local modules variables
+   INTEGER  ::       & !!! * Namelist numtau *
+      ntau000 = 1       ! nb of time-step during which the surface stress
+      !                 ! increase from 0 to its nominal value (taudta) (>0)
+   REAL(wp) ::       & !!! * Namelist numtau *
+      tau0x = 0.e0 , &  ! constant wind stress value in i-direction
+      tau0y = 0.e0      ! constant wind stress value in j-direction
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tau( kt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE tau  ***
+      !! 
+      !! ** Purpose :   provide the ocean surface stress at each time step
+      !!
+      !! ** Method  :   Constant surface stress increasing from 0 to taudta 
+      !!      value during the first ntau000 time-step (namelist)
+      !!        CAUTION: never mask the surface stress field !
+      !!
+      !! ** Action  : - update taux , tauy the stress in (i,j) ref.
+      !!
+      !! History :
+      !!   4.0  !  91-03  (G. Madec)  Original code
+      !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  ) ::   kt    ! ocean time step
+      REAL(wp) ::   ztau, ztau_sais, &  ! wind intensity and of the seasonal cycle
+         ztime,                      &  ! time in hour
+         ztimemax, ztimemin,         &  ! 21th June, and 21th decem. if date0 = 1st january
+         ztaun                          ! intensity 
+      INTEGER  ::   ji, jj              ! dummy loop indices
+
+      INTEGER  ::           &
+         zyear0,            &           ! initial year
+         zmonth0,           &           ! initial month
+         zday0,             &           ! initial day
+         zday_year0                    ! initial day since january 1st
+        
+
+      !! * Local declarations
+      REAL(wp) ::   zfacto              ! 
+
+      NAMELIST/namtau/ ntau000, tau0x, tau0y
+      !!---------------------------------------------------------------------
+
+      IF( cp_cfg == 'gyre' ) THEN
+
+         zyear0  = ndate0 / 10000                             ! initial year
+         zmonth0 = ( ndate0 - zyear0 * 10000 ) / 100          ! initial month
+         zday0   = ndate0 - zyear0 * 10000 - zmonth0 * 100    ! initial day betwen 1 and 30
+
+         zday_year0 = (zmonth0-1)*30.+zday0                   ! initial day betwen 1 and 360
+
+         ! current day (in hours) since january the 1st of the current year
+          ztime = FLOAT( kt ) * rdt / (rmmss * rhhmm)  &    !  total incrementation (in hours)
+             &     - (nyear  - 1) * rjjhh * raajj           !  minus years since beginning of experiment (in hours)
+
+
+        ! 21th june at 24h in hours
+         ztimemax = ((5.*30.)+21.)* 24.
+         ! 21th december day in hours
+         ! rjjhh * raajj / 4 = 1 seasonal cycle in hours
+         ztimemin = ztimemax + rjjhh * raajj / 2  
+
+         ! mean intensity at 0.105/srqt(2) because projected with 45deg angle
+         ztau = 0.105 / SQRT(2.)            
+         ! seasonal oscillation intensity
+         ztau_sais = 0.015                  
+         ztaun = ztau - ztau_sais * COS( (ztime - ztimemax) / (ztimemin - ztimemax) * rpi )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+              ! domain from 15deg to 50deg and 1/2 period along 14deg 
+              ! so 5/4 of half period with seasonal cycle
+              taux (ji,jj) = - ztaun * SIN( rpi * (gphiu(ji,jj) - 15.) / (29.-15.) )
+              tauy (ji,jj) =   ztaun * SIN( rpi * (gphiv(ji,jj) - 15.) / (29.-15.) )
+            END DO
+         END DO
+   
+         IF( kt == nit000 .AND. lwp ) THEN
+            WRITE(numout,*)' tau    : analytical formulation for gyre'
+            WRITE(numout,*)' ~~~~~~~ '
+            WRITE(numout,*)'          nyear      = ', nyear
+            WRITE(numout,*)'          nmonth     = ', nmonth
+            WRITE(numout,*)'          nday       = ', nday
+            WRITE(numout,*)'          nday_year  = ',nday_year
+            WRITE(numout,*)'          ndastp     = ',ndastp
+            WRITE(numout,*)'          adatrj     = ',adatrj
+            WRITE(numout,*)'          ztime      = ',ztime
+            WRITE(numout,*)'          ztimemax   = ',ztimemax
+            WRITE(numout,*)'          ztimemin   = ',ztimemin
+            WRITE(numout,*)'          zyear0     = ', zyear0
+            WRITE(numout,*)'          zmonth0    = ', zmonth0
+            WRITE(numout,*)'          zday0      = ', zday0
+            WRITE(numout,*)'          zday_year0 = ',zday_year0
+            WRITE(numout,*)'          raajj      = ', raajj
+            WRITE(numout,*)'          ztau       = ', ztau
+            WRITE(numout,*)'          ztau_sais  = ', ztau_sais
+            WRITE(numout,*)'          ztaun      = ', ztaun
+         ENDIF
+   
+      ELSE
+
+         IF( kt == nit000 ) THEN
+   
+            ! Read Namelist namtau : surface wind stress
+            ! --------------------
+            REWIND ( numnam )
+            READ   ( numnam, namtau )
+   
+            IF(lwp) WRITE(numout,*)' '
+            IF(lwp) WRITE(numout,*)' tau     : Constant surface wind stress read in namelist'
+            IF(lwp) WRITE(numout,*)' ~~~~~~~ '
+            IF(lwp) WRITE(numout,*)'           Namelist namtau: set the constant stress values'
+            IF(lwp) WRITE(numout,*)'              spin up of the stress  ntau000 = ', ntau000, ' time-steps'
+            IF(lwp) WRITE(numout,*)'              constant i-stress      tau0x   = ', tau0x  , ' N/m2'
+            IF(lwp) WRITE(numout,*)'              constant j-stress      tau0y   = ', tau0y  , ' N/m2'
+   
+            ntau000 = MAX( ntau000, 1 )   ! must be >= 1
+   
+         ENDIF
+   
+         ! Increase the surface stress to its nominal value in ntau000 time-step
+         
+         IF( kt <= ntau000 ) THEN
+            zfacto = 0.5 * (  1. - COS( rpi * FLOAT( kt ) / FLOAT( ntau000 ) )  )
+            taux (:,:) = zfacto * tau0x
+            tauy (:,:) = zfacto * tau0y
+         ENDIF
+
+      ENDIF
+      
+   END SUBROUTINE tau
+#endif
+   !!======================================================================
+END MODULE taumod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/sol_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/sol_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/sol_oce.F90	(revision 4536)
@@ -0,0 +1,117 @@
+MODULE sol_oce
+   !!======================================================================
+   !!                    ***  MODULE  sol_oce  ***
+   !! Ocean solver :  solver variables defined in memory 
+   !!=====================================================================
+   !!
+   !! ** Purpose :   Define in memory solver variables
+   !!
+   !! History :
+   !!   9.0  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !!-----------------------------------
+   !! elliptic solver: SOR, PCG or FETI
+   !! ----------------------------------
+   INTEGER , PUBLIC ::      & !!: namsol   elliptic solver / island / free surface
+      nsolv    =    1 ,     &  !: = 1/2/3/4 type of elliptic solver
+      nsol_arp =    0 ,     &  !: = 0/1 absolute/relative precision convergence test
+      nmin     =  300 ,     &  !: minimum of iterations for the SOR solver
+      nmax     =  800 ,     &  !: maximum of iterations for the SOR solver
+      nmod     =   10 ,     &  !: frequency of test for the SOR solver
+      nmisl    = 4000          !: maximum pcg iterations for island
+     
+   REAL(wp), PUBLIC ::      & !!: namsol   elliptic solver / island / free surface
+      eps    =  1.e-6_wp ,  &  !: absolute precision of the solver
+      resmax = 1.e-14_wp ,  &  !: absolute precision for the SOR solver
+      sor    =   1.92_wp ,  &  !: optimal coefficient for the SOR solver
+      epsisl = 1.e-10_wp ,  &  !: absolute precision on stream function solver
+      rnu    =    1.0_wp       !: strength of the additional force used in free surface
+
+   CHARACTER(len=1), PUBLIC ::   &  !:
+      c_solver_pt = 'T'        !: nature of grid-points T (S) for free surface case
+      !                        !                        F (G) for rigid-lid case
+
+   INTEGER , PUBLIC ::   &  !:
+      ncut,         &  !: indicator of solver convergence
+      niter            !: number of iteration done by the solver
+
+   REAL(wp), PUBLIC ::   &  !:
+      epsr,         &  !: relative precision for SOR & PCG solvers
+      epsilo,       &  !: precision for the FETI solver
+      rnorme, res,  &  !: intermediate modulus, solver residu
+      alph,         &  !: coefficient  =(gcr,gcr)/(gcx,gccd)
+      beta,         &  !: coefficient  =(rn+1,rn+1)/(rn,rn)
+      radd,         &  !: coefficient  =(gccd,gcdes)
+      rr               !: coefficient  =(rn,rn)
+
+   REAL(wp), PUBLIC, DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj,4) ::   &  !:
+      gcp              !: barotropic matrix extra-diagonal elements
+
+   REAL(wp), PUBLIC, DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj) ::   &  !:
+      gcx, gcxb,    &  !: now, before solution of the elliptic equation
+      gcdprc,       &  !: inverse diagonal preconditioning matrix
+      gcdmat,       &  !: diagonal preconditioning matrix
+      gcb,          &  !: second member of the barotropic linear system
+      gcr,          &  !: residu =b-a.x
+      gcdes,        &  !: vector descente
+      gccd             !: vector such that ca.gccd=a.d (ca-1=gcdprc)
+
+#if defined key_agrif
+      REAL(wp), DIMENSION(jpi,jpj) :: laplacu, laplacv
+#endif
+
+#if defined key_feti
+   !!----------------------------------------------------------------------
+   !!   'key_feti' :                                            FETI solver
+   !!----------------------------------------------------------------------
+   !!      noeuds           : total number of nodes for a subdomnain
+   !!      ninterf          : neighbour subdomain number
+   !!      nni              : interface point number
+   !!      ndvois()         : neighbour subdomain list
+   !!      maplistin()      : node pointer at each interface
+   !!      malistin()       : concatened list of interface nodes
+
+   INTEGER, PUBLIC :: nim,nxm,   &
+       malxm,malim,malxmax,malimax,   &
+       nifmat,njfmat,nelem,npe,matopo,   &
+       noeuds,nmorse,maan,   &
+       ninterf,ninterfc,nni,nnic,nnih,nnitot,ndir,   &
+       mandvois,mandvoisc,   &
+       maplistin,maplistih,malistin,   &
+       malisdir,npblo,mablo,ndlblo,ndkerep,   &
+       malisblo,mansp,ndimax,   &
+       miax,may,maz,mapoids,   &
+       nmaxd,mjj0,nitmax,ntest,   &
+       mabitw,mautilu,malambda,mag,mamg,mapg,mawj,madwj,madwwj,   &
+       magh,maw,madw,   &
+       mautil,mav,madia,mabufin,mabufout,mawork,maae,magamm,   &
+       maxnul,maynul,numit0ete,nitmaxete,maeteg,maeteag,   &
+       maeted,maetead,maeteadd,maetegamm,maetev,maetew,   &
+       madwork
+
+   INTEGER, PUBLIC :: mfet(jpi*jpj+2*jpi+2*jpj+51)
+
+   REAL(wp), PUBLIC ::   &  !:
+      wfeti(jpj*jpi*jpi+13*jpi*jpj+19*(jpi+jpj)   &
+       +4*jpnij+33   &
+       +2*(jpi+jpj)*(jpnij-jpni)*jpi   &
+       +2*(jpi+jpj)*(jpnij-jpnj+jperio)*jpj   &
+       +3*(jpnij-jpni)*jpi   &
+       +3*(jpnij-jpnj+jperio)*jpj) 
+
+   REAL(wp), PUBLIC ::   res2, rcompt
+
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE sol_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solfet.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solfet.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solfet.F90	(revision 4536)
@@ -0,0 +1,161 @@
+MODULE solfet
+   !!======================================================================
+   !!                     ***  MODULE  solfet
+   !! Ocean solver :  Finite Elements Tearing & Interconnecting solver
+   !!=====================================================================
+#if defined key_feti
+   !!----------------------------------------------------------------------
+   !!   'key_feti' :                                            FETI solver
+   !!----------------------------------------------------------------------
+   !!   sol_fet     : FETI solver
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE sol_oce         ! ocean solver 
+   USE lib_mpp         ! distribued memory computing
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_fet              ! ???
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE sol_fet( kindic )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_fet  ***
+      !!
+      !! ** Purpose :
+      !!     Solve the ellipic equation for the barotropic stream function
+      !!     system (default option) or the transport divergence system
+      !!     (lk_dynspg_flt=T) using a Finite Elements Tearing and 
+      !!      Interconnecting (FETI) approach.
+      !!     In the former case, the barotropic stream function trend has a
+      !!     zero boundary condition along all coastlines (i.e. continent
+      !!     as well as islands) while in the latter the boundary condition
+      !!     specification is not required.
+      !!
+      !! ** Method :
+      !!      Resolution of the elliptic equation by a Dual formulation of
+      !!      the Schur Complement Method or Finite Elements Tearing & 
+      !!      Interconnecting (FETI) approach
+      !!
+      !! ** Action :
+      !!
+      !! ** References :
+      !!      Guyon, M, Roux, F-X, Chartier, M and Fraunie, P, 1994 :
+      !!      A domain decomposition solver to compute the barotropic 
+      !!      component of an OGCM in the parallel processing field.
+      !!      Ocean Modelling, issue 105, december 94.
+      !!
+      !! History :
+      !!        !  97-02  (M. Guyon)  original code 
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj                    ! dummy loop indices
+      INTEGER ::   iit0, inn, iju 
+      REAL(wp) ::   zgcad, zgwgt
+
+
+      ! Norme(gcr)   = (gcb, gcb)
+      ! gcdes = gsr
+      
+      ! bmask field is filtering the differents contribution on the 
+      ! non-overlapping interface
+      
+      gcb(:,:) = bmask(:,:) * gcb(:,:)
+      
+      ! Mpp: sum over all the global domain
+      
+      ! copy the right hand member
+      
+      CALL feti_vmov(noeuds,gcb(1,1),wfeti(may))
+      
+      ! conservation of descent direction if ntest = 0
+      
+      IF(ntest /= 0) mjj0=0
+      iit0 = mjj0
+      !                      --->
+      !    resolution of the Grad(PS) equation by a Dual formulation of the
+      !    Schur Complement Method or Finite Elements Tearing & Interconnecting
+      !    (FETI) approach
+      !    interface problem (Lagrange  multiplier) : PCPG algorithm
+      !    local problem (trend of the 2D potential field) : LU factorization
+      !    preconditioner : lumped
+      !    optimisation : Krylov initialisation + Krylov correction
+
+      CALL feti_dualschur(noeuds,nifmat+1,njfmat+1,wfeti(maan),   &
+          npblo,wfeti(mablo),ninterf,   &
+          ninterfc,nni,nnic,mfet(mandvois),mfet(mandvoisc),   &
+          mfet(maplistin),mfet(malistin),   &
+          wfeti(mapoids),wfeti(miax),   &
+          wfeti(maz),wfeti(may),   &
+          wfeti(mabitw),wfeti(mautilu),   &
+          wfeti(malambda),wfeti(mag),   &
+          wfeti(mapg),wfeti(mamg),nitmax,nmaxd,mjj0,   &
+          wfeti(mawj),   &
+          wfeti(madwj),wfeti(madwwj),wfeti(magamm),   &
+          wfeti(mawork),   &
+          wfeti(mabufin),wfeti(mabufout),narea,epsilo,   &
+          ndlblo,mfet(malisblo),ndkerep,   &
+          wfeti(maxnul),wfeti(maynul),numit0ete,nitmaxete,   &
+          wfeti(maeteg),wfeti(maeteag),wfeti(maeted),   &
+          wfeti(maetead),wfeti(maeteadd),wfeti(maetegamm),   &
+          wfeti(mansp),   &
+          wfeti(maetev),wfeti(maetew),nnih,mfet(maplistih),   &
+          wfeti(magh),   &
+          wfeti(maw),wfeti(madw),   &
+          res,kindic,inn)
+
+      ! number of iteration of the pcg to solve the interface pb
+
+      inn =  mjj0 - iit0
+
+      ! test of convergence
+      IF( res < epsilo .OR. inn == nmax ) THEN
+          niter = inn
+          ncut  = 999
+      ENDIF
+
+      ! indicator of non-convergence or explosion
+      IF( inn == nmax .OR. rr > 1.e+20 ) kindic = -2
+      IF( ncut == 999 ) GOTO 999
+
+999   CONTINUE
+
+      !  2. Output in gcx
+      !  -----------------
+      
+      CALL feti_vmov( noeuds, wfeti(miax), gcx )
+
+      CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! lateral boundary condition
+
+   END SUBROUTINE sol_fet
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE sol_fet( kindic )        ! Empty routine
+      INTEGER, INTENT( inout ) ::   kindic  ! solver problem 
+      kindic = -100
+   END SUBROUTINE sol_fet
+#endif
+
+   !!=====================================================================
+END MODULE solfet
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solisl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solisl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solisl.F90	(revision 4536)
@@ -0,0 +1,1268 @@
+MODULE solisl
+   !!==============================================================================
+   !!                       ***  MODULE  solisl  ***
+   !! Ocean island : specific treatment of island in rigid-lid case
+   !!==============================================================================
+#if defined key_islands
+   !!----------------------------------------------------------------------
+   !!   'key_islands' :                           islands in rigid-lid case
+   !!----------------------------------------------------------------------
+   !!   isl_dom     : locate islands in the domain
+   !!   isl_pri     : control print of island gridpoint position
+   !!   isl_pth     : Compute coeff. associated with path round each island
+   !!   isl_mat     : Compute the matrix associated with islands
+   !!   isl_bsf     : Compute the barotropic streamfunction of each island
+   !!   isl_dyn_spg : Update the barotropic streamfunction trend with the
+   !!                 Island contribution (call by dyn_spg)
+   !!   isl_stp_ctl : print island information (call by stp_ctl)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE in_out_manager  ! I/O manager
+   USE sol_oce         ! ocean solver 
+   USE obc_oce         ! ocean open boundary condition
+   USE lib_mpp         ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC isl_dom        ! routine called by solver_init
+   PUBLIC isl_mat        ! routine called by solver_init
+   PUBLIC isl_bsf        ! routine called by solver_init
+   PUBLIC isl_dyn_spg    ! routine called by dyn_spg
+   PUBLIC isl_stp_ctl    ! routine called by stp_ctl
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_isl = .TRUE.    !: 'key_islands' flag
+
+   !! * module variable
+   INTEGER :: numisl           ! logical unit for island file only used
+   !                           ! here during the initialization phase
+   INTEGER ::   &
+      nimlu, njmlu, nkmlu,  &  ! i-j-k-dimensions read
+      nlmlu, nmmlu, nnmlu      ! read islands number
+   INTEGER, DIMENSION(jpnisl,0:4,jpisl) ::   &
+      miisl, mjisl             ! position of island grid-points
+   INTEGER, DIMENSION(0:4,jpisl) ::   &
+      mnisl                    ! number of grid-points for each island
+ 
+   REAL(wp) ::    &
+      replu                    ! read absolute precision
+   REAL(wp), DIMENSION(jpisl,jpisl) ::   &
+      aisl, aislm1             ! island matrix and its inverse
+   REAL(wp), DIMENSION(jpi,jpj,jpisl) ::   &
+      bsfisl                   ! barotropic streamfunction of island
+   REAL(wp), DIMENSION(jpi,jpj,2,jpisl) ::   &
+      acisl1, acisl2           ! coef. to compute circulations round islands
+   REAL(wp), DIMENSION(jpisl) ::   &
+      bisl,                 &  ! second member of island linear system
+      visl                     ! trend of island stream function
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/SOL/solisl.F90,v 1.8 2007/06/05 10:40:06 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE isl_dom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE isl_dom  ***
+      !!                    
+      !! ** Purpose :   Locate island grid-points from mbathy array
+      !!
+      !! ** Method  :   The coordinates of ocean grid-points round an island 
+      !!      are found from mbathy array read or computed in dommba.
+      !!      we first compute zwb, an ocean/land mask defined as follows:
+      !!              zwb(i,j)  =  0. over the main land and the ocean
+      !!                        = -n  over the nth island
+      !!      With the proper boundary conditions (defined by nperio)
+      !!        Note: IF i,j are the coordinates of an ocean grid-point west
+      !!      or east of a island, the corresponding coordinates miisl(ip,4,n)
+      !!      or mjisl(ip,2,n) are those of the western or southern side of
+      !!      the island (i.e. i+1 ou j+1, respectively)
+      !!
+      !! ** Action  :   compute mnisl, miisl, mjisl arrays defined as:
+      !!      mnisl(i,n) : nb of grid-points along (i=0), north (i=1), north
+      !!      (i=1), south (i=2), east (i=3), or west (i=4) of the nth island
+      !!      miisl(ip,i,n), mjisl(ip,i,n) : (i,j) index of ipth u- or v-point
+      !!      along (i=0), north (i=1),south (i=2), east (i=3), or west (i=4)
+      !!      of the nth island
+      !!
+      !! History :
+      !!    4.0  !  88-03  (G. Madec)  Original code
+      !!    6.0  !  96-01  (G. Madec)  Suppress common workspace, use of bmask
+      !!    8.5  !  96-01  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj, jn, jnil   ! dummy loop indices
+      INTEGER ::   ind, inilt, ip, ipn, ips, ipe, ipw, ii, ij, iju
+      INTEGER ::   iista, iiend, ijsta, ijend, ijstm1, ijenm1
+      INTEGER ::   isrchne
+      INTEGER, DIMENSION(jpj) ::   indil
+      INTEGER, DIMENSION(jpi,jpj) ::   idil
+
+      REAL(wp) znil
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwb
+      !!----------------------------------------------------------------------
+
+
+      ! 0. Islands index computed from mbathy
+      ! -------------------------------------
+      ! zwb=0 over the continent and ocean, =-n over the nth island
+      
+      ! Computation
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            zwb(ji,jj) = MIN( 0 , mbathy(ji,jj  ), mbathy(ji+1,jj  ),   &
+                                  mbathy(ji,jj+1), mbathy(ji+1,jj+1)  )
+         END DO
+      END DO
+      
+      ! Lateral boundary conditions on zwb
+
+      !  mono- or macro-tasking environnement:
+      IF( nperio == 2 ) THEN
+         zwb(:, 1 ) = zwb(:, 2 )
+      ELSEIF( nperio == 3 .OR. nperio == 4) THEN
+! om 
+!$$$          DO ji = 1, jpim1
+! On ne peut pas partir de ji=1, car alors jiu=jpi, et cette valeur
+! n'est pas encore initialiee. 
+! Le cas ji=1 est de toute facon traite a partir de la ligne 135
+         DO ji = 2, jpim1
+            iju = jpi-ji+1
+            zwb(ji,jpj  ) = zwb(iju,jpj-3)
+            zwb(ji,jpjm1) = zwb(iju,jpj-2)
+         END DO
+      ELSEIF( nperio == 5 .OR. nperio == 6) THEN
+         DO ji = 1, jpim1
+            iju = jpi-ji
+            zwb(ji,jpj  ) = zwb(iju,jpj-2)
+         END DO
+         DO ji = jpi/2+1, jpi-1
+            iju = jpi-ji
+            zwb(ji,jpjm1) = zwb(iju,jpjm1)
+         END DO
+      ELSE
+         zwb(:,jpj) = 0.e0
+      ENDIF
+
+      IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+         zwb( 1 ,:) = zwb(jpim1,:)
+         zwb(jpi,:) = zwb(  2  ,:)
+      ELSE
+         zwb( 1 ,:) = 0.e0
+         zwb(jpi,:) = 0.e0
+      ENDIF
+      IF( lk_mpp )   CALL lbc_lnk( zwb, 'G', 1. )
+
+
+      ! 1. Initialization for the search of island grid-points
+      ! ------------------------------------------------------
+
+      IF( lk_mpp ) THEN
+
+         ! Mpp : The overlap region are not taken into account
+         ! (islands bondaries are searched over subdomain only)
+         iista =  1   + jpreci
+         iiend = nlci - jpreci
+         ijsta =  1   + jprecj
+         ijend = nlcj - jprecj
+         ijstm1=  1   + jprecj
+         ijenm1= nlcj - jprecj
+         IF( nbondi == -1 .OR. nbondi == 2 ) THEN
+            iista  = 1
+         ENDIF
+         IF( nbondi ==  1 .OR. nbondi == 2 ) THEN
+            iiend  = nlci
+         ENDIF
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN
+            ijsta  = 1
+            ijstm1 = 2
+         ENDIF
+         IF( nbondj ==  1 .OR. nbondj == 2 ) THEN
+            ijend  = nlcj
+            ijenm1 = nlcj-1
+         ENDIF
+         IF( npolj == 3 .OR. npolj == 4 ) THEN
+            ijend  = nlcj-2
+            ijenm1 = nlcj-2
+         ENDIF 
+      ELSE
+         ! mono- or macro-tasking environnement: full domain scan
+         iista  = 1
+         iiend  = jpi
+         ijsta  = 1
+         ijstm1 = 2
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            ijend  = jpj-2
+            ijenm1 = jpj-2
+         ELSEIF( nperio == 5 .OR. nperio == 6 ) THEN
+            ijend  = jpj-1
+            ijenm1 = jpj-1
+         ELSE
+            ijend  = jpj
+            ijenm1 = jpj-1
+         ENDIF
+      ENDIF
+
+
+      ! 2. Loop over island
+      ! -------------------
+
+      DO jnil = 1, jpisl
+
+         ! 2.1 Initialization to zero of miisl, mjisl of the jnil island
+
+         miisl(:,:,jnil) = 0
+         mjisl(:,:,jnil) = 0
+         
+         ! 2.2 Search grid-points of island jnil
+ 
+         indil(:)   = 0
+         idil (:,:) = 0
+         
+         znil = - FLOAT( jnil )
+         DO jj = ijsta, ijend
+            indil(jj) = 0
+            ind = 0
+            DO ji = iista, iiend
+               IF( zwb(ji,jj) == znil ) THEN
+                  ind = ind + 1
+                  idil(ind,jj) = ji
+                  indil(jj) = indil(jj) + 1
+               ENDIF
+            END DO
+         END DO
+         
+         ! 2.3 Check the number of island
+         
+         inilt = 0
+         DO jj = ijsta, ijend
+            inilt = inilt + indil(jj)
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( inilt )   ! sum over the global domain
+
+         IF( inilt == 0 ) THEN
+            WRITE(ctmp1,*) ' isldom: there is not island number: ', jnil,' while jpisl= ', jpisl
+            CALL ctl_stop( ctmp1, ' change par_oce' )
+
+         ENDIF
+         
+         ! 2.4 Coastal island grid-points (miisl,mjisl)
+         
+         ip  = 0
+         ipn = 0
+         ips = 0
+         ipe = 0
+         ipw = 0
+
+         ! South line (ij=1)
+         ij = 1
+         DO jn = 1, indil(ij)
+            ii = idil(jn,ij)
+            IF( (ij+njmpp-1) == 1 .AND. ii > jpreci .AND. ii < (nlci-jpreci+1) ) THEN
+               IF(  zwb(ii-1,ij) * zwb(ii+1,ij) * zwb(ii,ij+1)  == 0. ) THEN
+                  ip = ip + 1
+                  miisl(ip,0,jnil) = ii
+                  mjisl(ip,0,jnil) = ij
+                  IF( zwb(ii-1,ij) == 0. ) THEN
+                     ipw = ipw + 1
+                     miisl(ipw,4,jnil) = ii
+                     mjisl(ipw,4,jnil) = ij
+                  ENDIF
+                  IF( zwb(ii+1,ij) == 0. ) THEN
+                     ipe = ipe+1
+                     IF( (nperio == 1 .OR. nperio == 4.OR. nperio == 6)  &
+                        .AND. ii == (nlci-jpreci) ) THEN
+                        miisl(ipe,3,jnil) = 1+jpreci
+                     ELSE
+                        miisl(ipe,3,jnil) = ii + 1
+                     ENDIF
+                     mjisl(ipe,3,jnil) = ij
+                  ENDIF
+                  IF( zwb(ii,ij+1) == 0. ) THEN
+                     ipn = ipn+1
+                     miisl(ipn,1,jnil) = ii
+                     mjisl(ipn,1,jnil) = ij + 1
+                  ENDIF
+               ENDIF
+            ENDIF
+         END DO
+         
+         ! Middle lines (2=<jj=<jpjm1 or jpj-2 if north fold b.c.)
+         DO jj = ijstm1, ijenm1
+            DO jn = 1, indil(jj)
+               ii = idil(jn,jj)
+               IF( ii > jpreci .AND. ii < (nlci-jpreci+1) ) THEN
+                  IF( (zwb(ii-1, jj )*zwb(ii+1, jj )*   &
+                       zwb( ii ,jj-1)*zwb( ii ,jj+1)) == 0. ) THEN
+                     ip = ip + 1
+                     miisl(ip,0,jnil) = ii
+                     mjisl(ip,0,jnil) = jj
+                     IF( zwb(ii-1,jj) == 0. ) THEN
+                        ipw = ipw + 1
+                        miisl(ipw,4,jnil) = ii
+                        mjisl(ipw,4,jnil) = jj
+                     ENDIF
+                     IF( zwb(ii+1,jj) == 0. ) THEN
+                        ipe = ipe + 1
+                        IF((nperio == 1.OR.nperio == 4.OR.nperio == 6)   &
+                           .AND.ii == (nlci-jpreci) ) THEN
+                           miisl(ipe,3,jnil) = 1 + jpreci
+                        ELSE
+                           miisl(ipe,3,jnil) = ii + 1
+                        ENDIF
+                        mjisl(ipe,3,jnil) = jj
+                     ENDIF
+                     IF( zwb(ii,jj-1) == 0. ) THEN
+                        ips = ips + 1
+                        miisl(ips,2,jnil) = ii
+                        mjisl(ips,2,jnil) = jj
+                     ENDIF
+                     IF( zwb(ii,jj+1) == 0. ) THEN
+                        ipn = ipn + 1
+                        miisl(ipn,1,jnil) = ii
+                        mjisl(ipn,1,jnil) = jj + 1
+                     ENDIF
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+         
+         ! North line (jj=jpj) only if not north fold b.c.
+         IF( nperio /= 3 .AND. nperio /= 4 .AND. nperio /= 5 .AND. nperio /= 6 ) THEN
+            ij = jpj
+            DO jn = 1, indil(ij)
+               ii = idil(jn,ij)
+               IF( (ij+njmpp-1) == jpjglo .AND. ii > jpreci .AND. ii < (nlci-jpreci+1) ) THEN
+                  IF( (zwb(ii-1, ij )*zwb(ii+1, ij )* zwb( ii ,ij-1) ) == 0. ) THEN
+                     ip = ip+1
+                     miisl(ip,0,jnil) = ii
+                     mjisl(ip,0,jnil) = ij
+                     IF( zwb(ii-1,ij) == 0. ) THEN
+                        ipw = ipw+1
+                        miisl(ipw,4,jnil) = ii
+                        mjisl(ipw,4,jnil) = ij
+                     ENDIF
+                     IF( zwb(ii+1,ij) == 0. ) THEN
+                        ipe = ipe+1
+                        IF( (nperio == 1) .AND. ii == (nlci-jpreci) ) THEN
+                           miisl(ipe,3,jnil) = 1+jpreci
+                        ELSE
+                           miisl(ipe,3,jnil) = ii+1
+                        ENDIF
+                        mjisl(ipe,3,jnil) = ij
+                     ENDIF
+                     IF( zwb(ii,ij-1) == 0. ) THEN
+                        ips = ips+1
+                        miisl(ips,2,jnil) = ii
+                        mjisl(ips,2,jnil) = ij
+                     ENDIF
+                  ENDIF
+               ENDIF
+            END DO
+         ENDIF
+         
+         mnisl(0,jnil) = ip
+         mnisl(1,jnil) = ipn
+         mnisl(2,jnil) = ips
+         mnisl(3,jnil) = ipe
+         mnisl(4,jnil) = ipw
+         
+         ! Take account of redundant points
+         
+         IF( lk_mpp )   CALL mpp_sum( ip )   ! sum over the global domain
+         
+         IF( ip > jpnisl ) THEN
+            WRITE(ctmp1,*) ' isldom: the island ',jnil,' has ',   &
+                 mnisl(0,jnil),' grid-points, while jpnisl= ', jpnisl,ip
+            CALL ctl_stop( ctmp1, ' change par_oce.h' )
+         ENDIF
+         
+         ! 2.5 Set to zero the grid-points of the jnil island in x
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zwb(ji,jj)+FLOAT(jnil) == 0. ) zwb(ji,jj) = 0. 
+            END DO
+         END DO
+         
+      END DO
+      
+
+      ! 3. Check the number of island
+      ! -----------------------------
+
+      inilt = isrchne( jpij, zwb(1,1), 1, 0. )
+      IF( lk_mpp )   CALL mpp_min( inilt )   ! min over the global domain
+
+      IF( inilt /= jpij+1 ) THEN
+            WRITE(ctmp1,*) ' isldom: there is at least one more ',   &
+                  'island in the domain and jpisl=', jpisl
+            CALL ctl_stop( ctmp1, ' change par_oce.h' )
+      ENDIF
+
+
+      ! 4. Print of island parametres and arrays
+      ! ----------------------------------------
+
+      CALL isl_pri
+
+
+      ! 5. Array for computation of circulation arround islands
+      ! -------------------------------------------------------
+
+      CALL isl_pth
+
+   END SUBROUTINE isl_dom
+
+
+   SUBROUTINE isl_pri
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE isl_pri  ***
+      !!              
+      !! ** Purpose :   Print islands variables and islands arrays
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   1.0  !  88-03  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jni, jnp      ! dummy loop variables
+      INTEGER ::   &
+         ip, ipn, ips, ipe, ipw      ! temporary integers
+      !!----------------------------------------------------------------------
+      
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '*** islpri number of islands : jpisl =',jpisl
+      ENDIF
+
+      DO jni = 1, jpisl
+         ip  = mnisl(0,jni)
+         ipn = mnisl(1,jni)
+         ips = mnisl(2,jni)
+         ipe = mnisl(3,jni)
+         ipw = mnisl(4,jni)
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( ip  )   ! sums over the global domain
+            CALL mpp_sum( ipn )
+            CALL mpp_sum( ips )
+            CALL mpp_sum( ipe )
+            CALL mpp_sum( ipw )
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,9000) jni
+            WRITE(numout,9010) ip, ipn, ips, ipe, ipw
+            WRITE(numout,9020)
+            DO jnp = 1, mnisl(0,jni)
+               WRITE(numout,9030) jnp, ( miisl(jnp,ji,jni)+nimpp-1,   &
+                                         mjisl(jnp,ji,jni)+njmpp-1, ji = 0, 4 )
+            END DO
+         ENDIF
+      END DO
+
+      ! FORMAT   !!cr => no more format
+ 9000 FORMAT(/, /, 'island number= ', i2 )
+ 9010 FORMAT(/, 'npil=',i4,' npn=',i3,' nps=',i3,' npe=',i3,' npw=',i3 )
+ 9020 FORMAT(/,'     * isl point *  point n  *  point s  *  point e ', '*  point w  *')
+ 9030 FORMAT(i4,' * (',i3,',',i3,') * (',i3,',',i3,') * (',i3,',',i3,   &
+          ') * (',i3,',',i3,') * (',i3,',',i3,') *' )
+
+   END SUBROUTINE isl_pri
+
+
+   SUBROUTINE isl_pth
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE isl_pth  ***
+      !!             
+      !! ** Purpose :   intialize arrays for the computation of streamfunction
+      !!      around islands
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action  : - acisl1(i,j,ii,n): coefficient n-s (ii=1) and e-w (ii=2)
+      !!                for the calculation of mu and mv around the island n      
+      !!              - acisl2(i,j,ii,n): coefficient n-s (ii=1) and e-w (ii=2)
+      !!                for the calculation of bsfd around the island n
+      !!
+      !! History :
+      !!   1.0  !  88-03  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   jni, jii, jnp    ! dummy loop indices
+      INTEGER ::   ii, ij           ! temporary integers
+      !!----------------------------------------------------------------------
+      
+      ! 1. Initialisation
+      ! -----------------
+      acisl1(:,:,:,:) = 0.e0
+      acisl2(:,:,:,:) = 0.e0
+      bsfisl(:,:,:)   = 0.e0
+
+      ! 2. Coefficient arrays
+      ! ---------------------
+      DO jni = 1, jpisl
+         DO jii = 1, 4
+            DO jnp = 1,mnisl(jii,jni)
+               ii = miisl(jnp,jii,jni)
+               ij = mjisl(jnp,jii,jni)
+               IF( jii <= 2 ) THEN
+                  ! north and south points
+                  acisl1(ii,ij,1,jni) = float( 2*jii-3) * e1u(ii,ij)
+                  acisl2(ii,ij,1,jni) = float( 2*jii-3) * e1u(ii,ij) * hur(ii,ij) / e2u(ii,ij)
+               ELSE
+                  ! east and west points
+                  acisl1(ii,ij,2,jni) = float(-2*jii+7) * e2v(ii,ij)
+                  acisl2(ii,ij,2,jni) = float(-2*jii+7) * e2v(ii,ij) * hvr(ii,ij) / e1v(ii,ij)
+               ENDIF
+            END DO
+         END DO
+      END DO
+      
+   END SUBROUTINE isl_pth
+
+   !!----------------------------------------------------------------------
+   !!   Default option :                                        NetCDF file
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE isl_mat
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE isl_mat  ***
+      !!                
+      !! ** Purpose :   Compute and invert the island matrix 
+      !!
+      !! ** Method  :   aisl(jni,jnj) matrix constituted by bsfisl circulation
+      !!
+      !! ** Action  : - aisl     : island matrix
+      !!              - aislm1   : invert of the island matrix
+      !!      file
+      !!              - islands  : contain bsfisl, aisl and aislm1
+      !!
+      !! History :
+      !!   1.0  !  88-10  (G. Madec)  Original code
+      !!   7.0  !  96-01  (G. Madec)  suppression of common work arrays
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+      USE iom
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jni, jnj, jl   ! dummy loop indices
+      INTEGER ::   ios          ! temporary integers
+      INTEGER  ::   &
+         inum                 ! temporary logical unit
+      REAL(wp), DIMENSION(jpi,jpj,2) ::   zwx
+      REAL(wp), DIMENSION(jpisl*jpisl) ::   ztab
+      !!----------------------------------------------------------------------
+
+
+      ! I. Island matrix lecture in numisl (if it exists)
+      ! ==================================
+
+      ! Lecture
+      CALL iom_open ( 'islands', inum )
+      ios = iom_varid( inum, 'aisl' )
+      IF( ios > 0 ) THEN
+
+         CALL iom_get( inum, jpdom_unknown, 'aisl'  , aisl )     
+         CALL iom_get( inum, jpdom_unknown, 'aislm1', aislm1 )      
+         CALL iom_close( inum )
+         ! Control print
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*)' islmat: lecture aisl/aislm1 in numisl done'
+            WRITE(numout,*)' ~~~~~~'
+            WRITE(numout,*)
+            WRITE(numout,*) '        island matrix : '
+            WRITE(numout,*)
+            
+            DO jnj = 1, jpisl
+               WRITE(numout,'(8e12.4)') ( aisl(jni,jnj), jni = 1, jpisl )
+            END DO
+            
+            WRITE(numout,*)
+            WRITE(numout,*) '       inverse of the island matrix'
+            WRITE(numout,*)
+            
+            DO jnj = 1, jpisl
+               WRITE(numout,'(12e11.3)') ( aislm1(jni,jnj), jni=1,jpisl )
+            END DO
+         ENDIF
+ 
+         CALL restclo(numisl)
+                 
+      ELSE
+ 
+         CALL iom_close( inum )
+
+      ! II. Island matrix computation
+      ! =============================
+
+      DO jnj = 1, jpisl
+
+         ! Circulation of bsf(jnj) around island jni
+         
+         DO jj = 2, jpj
+               zwx(:,jj,1) = -( bsfisl(:,jj,jnj) - bsfisl(:,jj-1,jnj) )
+         END DO
+         zwx(:,1,1) = 0.e0
+         
+         DO jj = 1, jpj
+            DO ji = 2, jpi
+               zwx(ji,jj,2) = ( bsfisl(ji,jj,jnj) - bsfisl(ji-1,jj,jnj) )
+            END DO
+         END DO
+         zwx(1,:,2) = 0.e0
+         
+         ! Island matrix
+         
+         DO jni = 1, jpisl
+            aisl(jni,jnj) = 0.e0
+            DO jl = 1, 2
+               DO jj=1,jpj
+                  DO ji=1,jpi
+                     aisl(jni,jnj) = aisl(jni,jnj) + acisl2(ji,jj,jl,jni)*zwx(ji,jj,jl)
+                  END DO
+               END DO
+            END DO
+         END DO
+         
+      END DO
+      IF( lk_mpp ) THEN
+         DO jnj = 1, jpisl
+            DO jni = 1, jpisl
+               ztab(jni+(jnj-1)*jpisl) = aisl(jni,jnj)
+            END DO
+         END DO
+         CALL mpp_sum( ztab, jpisl*jpisl )   ! sum over the global domain
+      ENDIF
+
+      ! 1.3 Control print
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'islmat : island matrix'
+         WRITE(numout,*) '~~~~~~'
+         WRITE(numout,*)
+         
+         DO jnj = 1, jpisl
+            WRITE(numout,'(8e12.4)') ( aisl(jni,jnj), jni = 1, jpisl )
+         END DO
+      ENDIF
+      
+
+      ! 2. Invertion of the island matrix
+      ! ---------------------------------
+      
+      ! 2.1 Call of an imsl routine for the matrix invertion
+
+      CALL linrg( jpisl, aisl, jpisl, aislm1, jpisl )
+
+      ! 2.2 Control print
+      
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'islmat : inverse of the island matrix'
+         WRITE(numout,*) '~~~~~~'
+         WRITE(numout,*)
+         
+         DO jnj = 1, jpisl
+            WRITE(numout, '(12e11.3)')  '        ', ( aislm1(jni,jnj), jni=1, jpisl )
+         END DO
+      ENDIF
+      
+
+      ! 3. Output of aisl and aislm1 in numisl
+      ! --------------------------------------
+
+      CALL restput( numisl, 'aisl'  , jpisl, jpisl, 1, 0, aisl   )
+      CALL restput( numisl, 'aislm1', jpisl, jpisl, 1, 0, aislm1 )
+      CALL restclo( numisl )
+
+      ENDIF
+
+   END SUBROUTINE isl_mat
+
+
+   SUBROUTINE isl_bsf
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE isl_bsf  ***
+      !!          
+      !! ** Purpose :
+      !!         Compute the barotropic stream function associated with each
+      !!      island using FETI or preconditioned conjugate gradient method
+      !!      or read them in numisl.
+      !!
+      !! ** Method :
+      !!
+      !! ** input/output file :
+      !!            numisl            : barotropic stream function associated
+      !!                          with each island of the domain
+      !!
+      !! ** Action :
+      !!       bsfisl, the streamfunction which takes the value 1 over island ni,
+      !!    and 0 over the others islands
+      !!       file 'numisl' barotropic stream function associated
+      !!                              with each island of the domain
+      !!
+      !! History :
+      !!        !  87-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-03  (G. Madec)  release 7.1
+      !!        !  93-04  (M. Guyon)  loops and suppress pointers
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  99-11  (M. Imbard)  NetCDF FORMAT with IOIPSL
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+      USE iom
+      USE solpcg
+      USE solfet
+      USE solsor
+
+      !! * Local declarations
+      LOGICAL  ::   llog, llbon
+      CHARACTER (len=10) ::  clisl
+      CHARACTER (len=32) ::  clname = 'islands'
+      INTEGER  ::   &
+         inum                 ! temporary logical unit
+      INTEGER  ::   ji, jj, jni, jii, jnp  ! dummy loop indices
+      INTEGER  ::   iimlu, ijmlu, inmlu, iju
+      INTEGER  ::   ii, ij, icile, icut, inmax, indic
+      INTEGER  ::   itime
+      REAL(wp) ::   zepsr, zeplu, zgwgt
+      REAL(wp) ::   zep(jpisl), zdept(1), zprec(4)
+      REAL(wp) ::   zdate0, zdt
+      REAL(wp) ::   t2p1(jpi,1,1)
+      INTEGER  ::   iloc
+      !!----------------------------------------------------------------------
+
+
+      ! 0. Initializations
+      ! ==================
+
+      icile         = 0      ! set to zero the convergence indicator
+      bsfisl(:,:,:) = 0.e0   ! set to zero of bsfisl
+
+
+      ! I. Lecture of bsfisl in numisl (if it exists)
+      ! =============================================
+
+      icut  = 0
+      iimlu = 0
+      ijmlu = 0
+      inmlu = 0
+      zeplu = 0.
+      
+      clname = 'islands'
+      
+      INQUIRE( FILE=clname, EXIST=llbon )
+! islands FILE does not EXIST : icut=999
+      IF( llbon ) THEN 
+
+         ! island FILE is present 
+
+         CALL iom_open (clname, inum )
+         CALL iom_get( inum, jpdom_unknown, 'PRECISION', zprec )     
+
+         iimlu = NINT( zprec(1) )
+         ijmlu = NINT( zprec(2) )
+         inmlu = NINT( zprec(3) )
+         zeplu = zprec(4)
+         ! the read domain does not correspond to the model one : icut=999
+         IF( iimlu /= jpi .OR. ijmlu /= jpj .OR. inmlu /= jpisl ) THEN
+            icut = 999
+         ELSE 
+            DO jni = 1, jpisl
+               IF( jni < 10 ) THEN
+                  WRITE(clisl,'("island",I1)') jni
+               ELSEIF( jni < 100 ) THEN
+                  WRITE(clisl,'("island",I2)') jni
+               ELSE 
+                  WRITE(clisl,'("island",I3)') jni
+               ENDIF
+               CALL iom_get( inum, jpdom_autoglo, clisl, bsfisl(:,:,jni))     
+            END DO
+         ENDIF
+      ELSE 
+         ! islands FILE does not EXIST : icut=999 
+         icut = 999
+      ENDIF
+  
+      CALL iom_close( inum )
+    
+      ! the read precision is not the required one : icut=888
+      IF( zeplu > epsisl ) THEN 
+         icut = 888
+      ENDIF
+
+      ! Control print
+      IF( icut == 999 ) THEN
+          IF(lwp) THEN
+              WRITE(numout,*)
+              WRITE(numout,*) 'islbsf : lecture bsfisl in numisl failed'
+              WRITE(numout,*) '~~~~~~'
+              WRITE(numout,*) '         icut= ', icut
+              WRITE(numout,*) '         imlu= ', iimlu, ' jmlu= ', ijmlu,   &
+                                      ' nilu= ', inmlu, ' epsisl lu= ', zeplu
+              WRITE(numout,*) '         the bsfisl are computed from zero'
+          ENDIF
+        ELSEIF( icut == 888 ) THEN
+          IF(lwp) THEN
+              WRITE(numout,*)
+              WRITE(numout,*) 'islbsf : lecture bsfisl in numisl done'
+              WRITE(numout,*) '~~~~~~'
+              WRITE(numout,*) '         the required accuracy is not reached'
+              WRITE(numout,*) '         epsisl lu= ', zeplu,' epsisl required ', epsisl
+              WRITE(numout,*) '         the bsfisl are computed from the read values'
+          ENDIF
+        ELSE
+          IF(lwp) THEN
+              WRITE(numout,*)
+              WRITE(numout,*) 'islbsf : lecture bsfisl in numisl done'
+              WRITE(numout,*) '~~~~~~'
+          ENDIF
+          RETURN
+      ENDIF
+      
+      
+      ! II. Compute the bsfisl (if icut=888 or 999)
+      ! ============================================
+
+      ! save nmax
+      inmax = nmax
+
+      ! set the number of iteration of island computation
+      nmax = nmisl
+
+      ! Loop over islands
+      ! -----------------
+      
+      DO jni = 1, jpisl
+
+
+         ! 1. Initalizations of island computation
+         ! ---------------------------------------
+         
+         ! Set the pcg solution gcb to zero
+         gcb(:,:) = 0.e0
+
+         ! Set first guess gcx either to zero or to the read bsfisl
+         IF( icut == 999 ) THEN
+            gcx(:,:) = 0.e0
+         ELSEIF( icut == 888 ) THEN
+            IF(lwp) WRITE(numout,*) ' islbsf: bsfisl read are used as first guess'
+            ! c a u t i o n: bsfisl masked because it contains 1 along island seaside
+            gcx(:,:) = bsfisl(:,:,jni) * bmask(:,:)
+         ENDIF
+         
+         ! Right hand side of the streamfunction equation
+         
+         IF( lk_mpp ) THEN
+
+            ! north fold treatment
+            IF( npolj == 3 .OR. npolj == 5)   iloc=jpiglo-(nimpp-1+nimppt(nono+1)-1)
+            IF( npolj == 4 .OR. npolj == 6)   iloc=jpiglo-2*(nimpp-1)
+            t2p1(:,1,1) = 0.e0
+            ! north and south grid-points
+            DO jii = 1, 2
+               DO jnp = 1, mnisl(jii,jni)
+                  ii = miisl(jnp,jii,jni)
+                  ij = mjisl(jnp,jii,jni)
+                  IF( ( npolj == 3 .OR. npolj == 4 ) .AND.   &
+                     ( ij == nlcj-1 .AND. jii == 1) ) THEN 
+                     iju=iloc-ii+1
+                     t2p1(iju,1,1) =  t2p1(iju,1,1) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                  ELSEIF( ( npolj == 5 .OR. npolj == 6 ) .AND.   &
+                     ( ij == nlcj-1 .AND. jii == 1) ) THEN 
+                     iju=iloc-ii
+                     gcb(ii,ij) =  gcb(ii,ij) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                     t2p1(iju,1,1) =  t2p1(iju,1,1) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                  ELSE  
+                     gcb(ii,ij-jii+1) =  gcb(ii,ij-jii+1) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                  ENDIF
+               END DO
+            END DO
+         
+            ! east and west grid-points
+         
+            DO jii = 3, 4
+               DO jnp = 1, mnisl(jii,jni)
+                  ii = miisl(jnp,jii,jni)
+                  ij = mjisl(jnp,jii,jni)
+                  gcb(ii-jii+3,ij) = gcb(ii-jii+3,ij) + hvr(ii,ij) * e2v(ii,ij) / e1v(ii,ij)
+               END DO
+            END DO
+
+            IF( lk_mpp )   CALL mpplnks( gcb )   !!bug ? should use an lbclnk ? is it possible?
+
+         ELSE
+
+            ! north and south grid-points
+            DO jii = 1, 2
+               DO jnp = 1, mnisl(jii,jni)
+                  ii = miisl(jnp,jii,jni)
+                  ij = mjisl(jnp,jii,jni)
+                  IF( ( nperio == 3 .OR. nperio == 4 ) .AND.   &
+                     ( ij == jpj-1 .AND. jii == 1) ) THEN 
+                     gcb(jpi-ii+1,ij-1) = gcb(jpi-ii+1,ij-1) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                  ELSEIF( ( nperio == 5 .OR. nperio == 6 ) .AND.   &
+                     ( ij == jpj-1 .AND. jii == 1) ) THEN 
+                     gcb(ii,ij) =  gcb(ii,ij) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij)
+                     gcb(jpi-ii,ij) = gcb(jpi-ii,ij) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij) 
+                  ELSE  
+                     gcb(ii,ij-jii+1) =  gcb(ii,ij-jii+1) + hur(ii,ij) * e1u(ii,ij) / e2u(ii,ij)
+                  ENDIF
+               END DO
+            END DO
+
+            ! east and west grid-points
+            DO jii = 3, 4
+               DO jnp = 1, mnisl(jii,jni)
+                  ii = miisl(jnp,jii,jni)
+                  ij = mjisl(jnp,jii,jni)
+                  IF( bmask(ii-jii+3,ij) /= 0. ) THEN
+                     gcb(ii-jii+3,ij) = gcb(ii-jii+3,ij) + hvr(ii,ij) * e2v(ii,ij) / e1v(ii,ij)
+                  ELSE
+                     ! east-west cyclic boundary conditions
+                     IF( ii-jii+3 == 1 ) THEN
+                        gcb(jpim1,ij) = gcb(jpim1,ij) + hvr(ii,ij) * e2v(ii,ij) / e1v(ii,ij)
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+
+         ! Preconditioned right hand side and absolute precision
+
+         IF( nsolv == 3 ) THEN 
+            ! FETI method
+            ncut    = 0
+            rnorme  = 0.e0
+            gcb(:,:) = bmask(:,:) * gcb(:,:)
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  rnorme = rnorme + gcb(ji,jj) * gcb(ji,jj)
+               END DO
+            END DO
+            
+            IF( lk_mpp )   CALL mpp_sum( rnorme )
+
+            IF(lwp) WRITE(numout,*) 'rnorme ', rnorme
+            epsr  = epsisl * epsisl * rnorme
+            indic = 0
+         ELSE 
+            ncut   = 0
+            rnorme = 0.e0
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  gcb  (ji,jj) = gcdprc(ji,jj) * gcb(ji,jj)
+                  zgwgt  = gcdmat(ji,jj) * gcb(ji,jj)
+                  rnorme = rnorme + gcb(ji,jj) * zgwgt
+               END DO
+            END DO
+            IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+
+            IF(lwp) WRITE(numout,*) 'rnorme ', rnorme
+            epsr = epsisl * epsisl * rnorme
+            indic = 0
+         ENDIF
+
+
+         ! 3. PCG solver for gcp.gcx=gcb in monotask
+         ! -------------------------------------------
+
+         IF( nsolv == 3 ) THEN 
+            epsilo = epsisl       ! precision to compute Islands matrix A
+            CALL sol_fet( indic )  ! FETI method
+            epsilo = eps          ! precision to compute grad PS
+         ELSE 
+            CALL sol_pcg( indic )  ! pcg method
+         ENDIF
+
+
+         ! 4. Save the solution in bsfisl
+         ! ------------------------------
+
+         bsfisl(:,:,jni) = gcx(:,:)
+
+
+         ! 5. Boundary conditions
+         ! ----------------------
+
+         ! set to 1. coastal gridpoints of the island
+         DO jnp = 1, mnisl(0,jni)
+            ii = miisl(jnp,0,jni)
+            ij = mjisl(jnp,0,jni)
+            bsfisl(ii,ij,jni) = 1.
+         END DO
+
+         ! cyclic boundary conditions
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+            bsfisl( 1 ,:,jni) = bsfisl(jpim1,:,jni)
+            bsfisl(jpi,:,jni) = bsfisl(  2  ,:,jni)
+         ENDIF
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            DO ji = 1, jpim1
+               iju = jpi-ji+1
+               bsfisl(ji,jpj-1,jni) = bsfisl(iju,jpj-2,jni)
+               bsfisl(ji, jpj ,jni) = bsfisl(iju,jpj-3,jni)
+            END DO
+         ENDIF
+         IF( nperio == 5 .OR. nperio == 6 ) THEN
+            DO ji = 1, jpi-1
+               iju=jpi-ji
+               bsfisl(ji,jpj,jni) = bsfisl(iju,jpj-2,jni)
+            END DO
+            DO ji = jpi/2+1, jpi-1
+               iju=jpi-ji
+               bsfisl (ji,jpjm1,jni) = bsfisl(iju,jpjm1,jni)
+            END DO
+         ENDIF
+         IF( lk_mpp )   CALL lbc_lnk( bsfisl(:,:,jni), 'G', 1. )   ! link at G-point
+
+
+         ! 6. Control print
+         ! ----------------
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' islbsf: island number: ', jni
+         IF(lwp) WRITE (numout,9290) niter, res, SQRT(epsr)/epsisl
+         zep(jni) =  MAX(epsisl, res/(SQRT(epsr)/epsisl))
+         IF( indic <  0 ) THEN
+            icile = icile-1
+            IF(lwp) WRITE(numout,*) '  pcg do not converge for island: ', jni
+            IF(lwp) WRITE(numout,*) '      Precision reached: ',zep(jni)
+         ENDIF
+
+9290     FORMAT('        niter :',i4,' , res :',e20.10,' , gcb :',e20.10)
+
+         !                                          !====================
+      END DO                                        !  End Loop islands
+      !                                             !====================
+
+      ! 7. Reset PCG
+      ! ------------
+
+      ! reset the number of iteration for pcg
+      nmax = inmax
+
+      ! reset to zero pcg arrays
+      gcx  (:,:) = 0.e0
+      gcxb (:,:) = 0.e0
+      gcb  (:,:) = 0.e0
+      gcr  (:,:) = 0.e0
+      gcdes(:,:) = 0.e0
+      gccd (:,:) = 0.e0
+
+
+      ! III. Output of bsfisl in numisl
+      ! ===============================
+
+      CALL ymds2ju( 0, 1, 1, 0.e0, zdate0 )
+      zprec(1) = FLOAT(jpi)
+      zprec(2) = FLOAT(jpj)
+      zprec(3) = FLOAT(jpisl)
+      IF(lwp) WRITE(numout,*) clname
+      zdept(1)   = 0.
+      itime = 0
+      CALL restini( 'NONE', jpi, jpj, glamt, gphit, 1, zdept,  &
+         &          clname, itime, zdate0, rdt, numisl, domain_id=nidom )
+      IF( icile == 0 .AND. icut /= 0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*)' islbsf: write bsfisl in numisl ', numisl
+            WRITE(numout,*)' -------------------------------------'
+         ENDIF
+         zprec(4) = epsisl
+         CALL restput(numisl,'PRECISION',1,1,4,0,zprec)
+         DO jni = 1, jpisl
+            IF(jni < 10) THEN
+               WRITE(clisl,'("island",I1)') jni
+            ELSE IF(jni < 100) THEN
+               WRITE(clisl,'("island",I2)') jni
+            ELSE 
+               WRITE(clisl,'("island",I3)') jni
+            ENDIF
+            CALL restput( numisl, clisl, jpi, jpj, 1, 0, bsfisl(:,:,jni) )
+         END DO
+      ENDIF
+
+      IF( icile < 0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' islbsf: number of island without convergence : ',ABS(icile)
+            WRITE(numout,*) ' ---------------------------------------------'
+         ENDIF
+         zepsr = epsisl
+         DO jni = 1, jpisl
+            IF(lwp) WRITE(numout,*) '    isl ',jni,' precision reached ', zep(jni)
+            zepsr = MAX( zep(jni), zepsr )
+         END DO
+         IF( zepsr == 0. ) zepsr = epsisl
+         IF(lwp) THEN
+            WRITE(numout,*) ' save value of precision reached: ',zepsr
+            WRITE(numout,*)
+            WRITE(numout,*)' islbsf: save bsfisl in numisl ',numisl
+            WRITE(numout,*)' -------------------------------------'
+         ENDIF
+
+         zprec(4) = zepsr
+         CALL restput( numisl, 'PRECISION', 1, 1, 1, 0, zprec )
+         DO jni = 1, jpisl
+            IF( jni < 10 ) THEN
+               WRITE(clisl,'("island",I1)') jni
+            ELSE IF( jni < 100 ) THEN
+               WRITE(clisl,'("island",I2)') jni
+            ELSE 
+               WRITE(clisl,'("island",I3)') jni
+            ENDIF
+            CALL restput( numisl, clisl, jpi, jpj, 1, 0, bsfisl(:,:,jni) )
+         END DO
+         CALL restclo(numisl)
+         CALL ctl_stop( ' ' )
+      ENDIF
+
+   END SUBROUTINE isl_bsf
+
+
+   SUBROUTINE isl_dyn_spg
+      !!----------------------------------------------------------------------
+      !!                  ***  routine isl_dyn_spg  ***
+      !!
+      !! ** Purpose :   Compute and add the island contribution to the 
+      !!      barotropic stream function trend.
+      !!
+      !!
+      !! ** Method  :   Rigid-lid appromimation: ...????
+      !!
+      !! ** Action : - Update bsfd with the island contribution
+      !!
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  isolate island computation
+      !!---------------------------------------------------------------------
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jni, jnj    ! dummy loop indices
+      !!----------------------------------------------------------------------
+      
+
+      ! compute the island potential
+      ! ----------------------------
+      DO jni = 1, jpisl                      ! second member
+         bisl(jni) =  0.e0
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               bisl(jni) =  bisl(jni) + acisl1(ji,jj,1,jni) *  spgu(ji,jj)                  &
+                  &                   + acisl1(ji,jj,2,jni) *  spgv(ji,jj)                  &
+                  &                   + acisl2(ji,jj,1,jni) * ( gcx(ji,jj)-gcx(ji,jj-1) )   &
+                  &                   - acisl2(ji,jj,2,jni) * ( gcx(ji,jj)-gcx(ji-1,jj) )
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( bisl, jpisl )   ! sum over the global domain
+
+      DO jni = 1, jpisl                     ! Island stream function trend
+         visl(jni) = 0.e0
+         DO jnj = 1, jpisl
+            visl(jni) = visl(jni) + aislm1(jni,jnj) * bisl(jnj)
+         END DO
+      END DO
+
+      ! update the bsf trend ( caution : bsfd is not zero along island coastlines, dont mask it ! )
+      ! --------------------
+      DO jj = 1, jpj
+         DO jni = 1, jpisl
+            DO ji = 1, jpi
+               bsfd(ji,jj) = bsfd(ji,jj) + visl(jni) * bsfisl(ji,jj,jni)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE isl_dyn_spg
+
+
+   SUBROUTINE isl_stp_ctl( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE isl_stp_ctl  ***
+      !!                     
+      !! ** Purpose :   ???
+      !!
+      !! ** Method  : - print island potential
+      !!
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  isolated from stp_ctl
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in   ) ::   kt        ! ocean time-step index
+      INTEGER, INTENT(inout) ::   kindic    ! indicator of solver convergence
+
+      !! * local declarations
+      INTEGER  ::   jni                     ! dummy loop indice
+      REAL(wp) ::   zfact                   ! temporary scalar
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'isl_stp_ctl : time-stepping control'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! Island trends
+      DO jni = 1, jpisl
+         zfact = 0.
+         IF( miisl(1,0,jni) /= 0 .AND. mjisl(1,0,jni) /= 0 ) THEN
+            zfact = 1.e-6 * bsfn(miisl(1,0,jni),mjisl(1,0,jni))
+         ENDIF
+         IF( lk_mpp )   CALL mpp_isl( zfact )
+
+         IF(lwp) WRITE(numisp,9300) kt, jni, zfact, visl(jni)
+         IF( MOD( kt, nwrite ) == 0 .OR. kindic < 0     &
+            .OR. ( kt == nit000 .AND. kindic > 0 )      &
+            .OR.   kt == nitend                         ) THEN
+            IF( jni == 1 .AND. lwp ) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) 'isl_stp_ctl : island bsf'
+               WRITE(numout,*) '~~~~~~~~~~~'
+            ENDIF
+            IF(lwp) WRITE(numout,9300) kt, jni, zfact, visl(jni)
+         ENDIF
+      END DO
+9300  FORMAT(' it : ',i8,' island  :',i4,'   BSF (Sverdrup) : ',f7.2, '   visl : ',e15.6)
+
+   END SUBROUTINE isl_stp_ctl
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_isl = .FALSE.    !: 'key_islands' flag
+CONTAINS
+   SUBROUTINE isl_dom                        ! Empty routine
+   END SUBROUTINE isl_dom
+   SUBROUTINE isl_bsf                        ! Empty routine
+   END SUBROUTINE isl_bsf
+   SUBROUTINE isl_mat                        ! Empty routine
+   END SUBROUTINE isl_mat
+   SUBROUTINE isl_dyn_spg                    ! Empty routine
+   END SUBROUTINE isl_dyn_spg
+   SUBROUTINE isl_stp_ctl( kt, kindic )      ! Empty routine
+      WRITE(*,*) 'isl_stp_ctl: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE isl_stp_ctl
+#endif
+
+   !!======================================================================
+END MODULE solisl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solmat.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solmat.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solmat.F90	(revision 4536)
@@ -0,0 +1,991 @@
+MODULE solmat
+   !!======================================================================
+   !!                       ***  MODULE  solmat  ***
+   !! solver       : construction of the matrix 
+   !!======================================================================
+   !! History :   1.0  !  88-04  (G. Madec)  Original code
+   !!                  !  93-03  (M. Guyon)  symetrical conditions
+   !!                  !  93-06  (M. Guyon)  suppress pointers
+   !!                  !  96-05  (G. Madec)  merge sor and pcg formulations
+   !!                  !  96-11  (A. Weaver)  correction to preconditioning
+   !!                  !  98-02  (M. Guyon)  FETI method
+   !!             8.5  !  02-08  (G. Madec)  F90: Free form
+   !!                  !  02-11  (C. Talandier, A-M. Treguier) Free surface & Open boundaries
+   !!             9.0  !  05-09  (R. Benshila)  add sol_exd for extra outer halo
+   !!             9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!             9.0  !  06-07  (S. Masson)  distributed restart using iom
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   sol_mat       : Construction of the matrix of used by the elliptic solvers
+   !!   fetsch        :
+   !!   fetmat        :
+   !!   fetstr        :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE sol_oce         ! ocean solver
+   USE phycst          ! physical constants
+   USE obc_oce         ! ocean open boundary conditions
+   USE lbclnk          ! lateral boudary conditions
+   USE lib_mpp         ! distributed memory computing
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_mat     ! routine called by inisol.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE sol_mat( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_mat  ***
+      !!
+      !! ** Purpose :   Construction of the matrix of used by the elliptic 
+      !!      solvers (either sor, pcg or feti methods).
+      !!
+      !! ** Method  :   The matrix depends on the type of free surface:
+      !!       * lk_dynspg_rl=T: rigid lid formulation
+      !!      The matrix is built for the barotropic stream function system.
+      !!      a diagonal preconditioning matrix is also defined.
+      !!       * lk_dynspg_flt=T: free surface formulation
+      !!      The matrix is built for the divergence of the transport system
+      !!      a diagonal preconditioning matrix is also defined.
+      !!        Note that for feti solver (nsolv=3) a specific initialization 
+      !!      is required (call to fetstr.F) for memory allocation and inter-
+      !!      face definition.
+      !! 
+      !! ** Action  : - gcp    : extra-diagonal elements of the matrix
+      !!              - gcdmat : preconditioning matrix (diagonal elements)
+      !!              - gcdprc : inverse of the preconditioning matrix
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in) :: kt
+
+      !! * Local declarations
+      INTEGER ::   ji, jj                    ! dummy loop indices
+      INTEGER ::   ii, ij, iiend, ijend      ! temporary integers
+      REAL(wp) ::   zcoefs, zcoefw, zcoefe, zcoefn  ! temporary scalars
+      REAL(wp) ::   z2dt, zcoef
+      !!----------------------------------------------------------------------
+
+      ! FETI method ( nsolv = 3)
+      ! memory allocation and interface definition for the solver
+
+      IF( nsolv == 3 )   CALL fetstr
+
+      
+      ! 1. Construction of the matrix
+      ! -----------------------------
+      
+      ! initialize to zero
+      zcoef = 0.e0
+      gcp(:,:,1) = 0.e0
+      gcp(:,:,2) = 0.e0
+      gcp(:,:,3) = 0.e0
+      gcp(:,:,4) = 0.e0
+      
+      gcdprc(:,:) = 0.e0
+      gcdmat(:,:) = 0.e0
+      
+      IF( neuler == 0 .AND. kt == nit000 ) THEN
+         z2dt = rdt
+      ELSE
+         z2dt = 2. * rdt
+      ENDIF
+
+#if defined key_dynspg_flt && ! defined key_obc
+!!cr      IF( lk_dynspg_flt .AND. .NOT.lk_obc ) THEN   !bug missing lk_dynspg_flt_atsk
+
+      ! defined the coefficients for free surface elliptic system
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zcoef = z2dt * z2dt * grav * rnu * bmask(ji,jj)
+            zcoefs = -zcoef * hv(ji  ,jj-1) * e1v(ji  ,jj-1) / e2v(ji  ,jj-1)    ! south coefficient
+            zcoefw = -zcoef * hu(ji-1,jj  ) * e2u(ji-1,jj  ) / e1u(ji-1,jj  )    ! west coefficient
+            zcoefe = -zcoef * hu(ji  ,jj  ) * e2u(ji  ,jj  ) / e1u(ji  ,jj  )    ! east coefficient
+            zcoefn = -zcoef * hv(ji  ,jj  ) * e1v(ji  ,jj  ) / e2v(ji  ,jj  )    ! north coefficient
+            gcp(ji,jj,1) = zcoefs
+            gcp(ji,jj,2) = zcoefw
+            gcp(ji,jj,3) = zcoefe
+            gcp(ji,jj,4) = zcoefn
+            gcdmat(ji,jj) = e1t(ji,jj) * e2t(ji,jj) * bmask(ji,jj)    &          ! diagonal coefficient
+               &          - zcoefs -zcoefw -zcoefe -zcoefn
+         END DO
+      END DO
+      
+#  elif defined key_dynspg_flt && defined key_obc
+!!cr      ELSEIF( lk_dynspg_flt .AND. lk_obc ) THEN     !bug missing lk_dynspg_flt_atsk 
+
+      !   defined gcdmat in the case of open boundaries
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zcoef = z2dt * z2dt * grav * rnu * bmask(ji,jj)
+            !  south coefficient
+            IF( lp_obc_south .AND. ( jj == njs0p1 ) ) THEN
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)*(1.-vsmsk(ji,1))
+            ELSE
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)
+            END IF
+            gcp(ji,jj,1) = zcoefs
+
+            !  west coefficient
+            IF( lp_obc_west  .AND. ( ji == niw0p1 ) ) THEN
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)*(1.-uwmsk(jj,1))
+            ELSE
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)
+            END IF
+            gcp(ji,jj,2) = zcoefw
+
+            !   east coefficient
+            IF( lp_obc_east  .AND. ( ji == nie0 ) ) THEN
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)*(1.-uemsk(jj,1))
+            ELSE
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)
+            END IF
+            gcp(ji,jj,3) = zcoefe
+
+            !   north coefficient
+            IF( lp_obc_north .AND. ( jj == njn0 ) ) THEN
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)*(1.-vnmsk(ji,1))
+            ELSE
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)
+            END IF
+            gcp(ji,jj,4) = zcoefn
+
+            ! diagonal coefficient
+            gcdmat(ji,jj) = e1t(ji,jj)*e2t(ji,jj)*bmask(ji,jj) &
+                            - zcoefs -zcoefw -zcoefe -zcoefn
+         END DO
+      END DO
+
+#  else
+!!cr      ELSE
+
+      !   defined the coefficients for bsf elliptic system
+      
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zcoefs = -hur(ji  ,jj  ) * e1u(ji  ,jj  ) / e2u(ji  ,jj  ) * bmask(ji,jj)   ! south coefficient
+            zcoefw = -hvr(ji  ,jj  ) * e2v(ji  ,jj  ) / e1v(ji  ,jj  ) * bmask(ji,jj)   ! west coefficient
+            zcoefe = -hvr(ji+1,jj  ) * e2v(ji+1,jj  ) / e1v(ji+1,jj  ) * bmask(ji,jj)   ! east coefficient
+            zcoefn = -hur(ji  ,jj+1) * e1u(ji  ,jj+1) / e2u(ji  ,jj+1) * bmask(ji,jj)   ! north coefficient
+            gcp(ji,jj,1) = zcoefs
+            gcp(ji,jj,2) = zcoefw
+            gcp(ji,jj,3) = zcoefe
+            gcp(ji,jj,4) = zcoefn
+            gcdmat(ji,jj) = -zcoefs -zcoefw -zcoefe -zcoefn                             ! diagonal coefficient
+         END DO
+      END DO
+      
+!!cr  ENDIF
+#endif
+#if defined key_agrif
+       IF (.NOT.AGRIF_ROOT()) THEN
+       
+       IF ( (nbondi == -1)  .OR. (nbondi == 2) ) bmask(2,:)=0.
+       IF ( (nbondi ==  1)  .OR. (nbondi == 2) ) bmask(nlci-1,:)=0.
+       IF ( (nbondj == -1)  .OR. (nbondj == 2) ) bmask(:,2)=0.
+       IF ( (nbondj ==  1)  .OR. (nbondj == 2) ) bmask(:,nlcj-1)=0.
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zcoef = z2dt * z2dt * grav * rnu * bmask(ji,jj)
+            !  south coefficient
+            IF( ((nbondj == -1)  .OR. (nbondj == 2)) .AND. ( jj == 3 ) ) THEN
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)*(1.-vmask(ji,jj-1,1))
+            ELSE
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)
+            END IF
+            gcp(ji,jj,1) = zcoefs
+
+            !  west coefficient
+	    IF( ( (nbondi == -1)  .OR. (nbondi == 2) ) .AND. ( ji == 3 )  ) THEN
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)*(1.-umask(ji-1,jj,1))
+            ELSE
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)
+            END IF
+            gcp(ji,jj,2) = zcoefw
+
+            !   east coefficient
+            IF( ((nbondi == 1)  .OR. (nbondi == 2)) .AND. ( ji == nlci-2 ) ) THEN
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)*(1.-umask(ji,jj,1))
+            ELSE
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)
+            END IF
+            gcp(ji,jj,3) = zcoefe
+
+            !   north coefficient
+            IF( ((nbondj == 1)  .OR. (nbondj == 2)) .AND. ( jj == nlcj-2 ) ) THEN
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)*(1.-vmask(ji,jj,1))
+            ELSE
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)
+            END IF
+            gcp(ji,jj,4) = zcoefn
+
+            ! diagonal coefficient
+            gcdmat(ji,jj) = e1t(ji,jj)*e2t(ji,jj)*bmask(ji,jj) &
+                            - zcoefs -zcoefw -zcoefe -zcoefn
+         END DO
+      END DO
+      
+       ENDIF
+#endif
+
+      ! 2. Boundary conditions 
+      ! ----------------------
+      
+      ! Cyclic east-west boundary conditions
+      !     ji=2 is the column east of ji=jpim1 and reciprocally,
+      !     ji=jpim1 is the column west of ji=2
+      !     all the coef are already set to zero as bmask is initialized to
+      !     zero for ji=1 and ji=jpj in dommsk.
+      
+      ! Symetrical conditions
+      ! free surface: no specific action
+      ! bsf system: n-s gradient of bsf = 0 along j=2 (perhaps a bug !!!!!!)
+      ! the diagonal coefficient of the southern grid points must be modify to
+      ! account for the existence of the south symmetric bassin.
+      
+!!cr      IF( .NOT.lk_dynspg_flt ) THEN   !bug missing lk_dynspg_flt_atsk
+#if ! defined key_dynspg_flt
+      IF( nperio == 2 ) THEN
+         DO ji = 1, jpi
+            IF( bmask(ji,2) /= 0.e0 ) THEN
+               zcoefs = - hur(ji,2)*e1u(ji,2)/e2u(ji,2)
+               gcdmat(ji,2) = gcdmat(ji,2) - zcoefs
+            ENDIF
+         END DO
+      ENDIF
+!!cr      ENDIF
+#endif
+      
+      ! North fold boundary condition
+      !     all the coef are already set to zero as bmask is initialized to
+      !     zero on duplicated lignes and portion of lignes
+      
+      ! 3. Preconditioned matrix
+      ! ------------------------
+      
+      IF( nsolv /= 3 ) THEN
+         
+         ! SOR and PCG solvers
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( bmask(ji,jj) /= 0.e0 )   gcdprc(ji,jj) = 1.e0 / gcdmat(ji,jj)
+            END DO
+         END DO
+         
+         gcp(:,:,1) = gcp(:,:,1) * gcdprc(:,:)
+         gcp(:,:,2) = gcp(:,:,2) * gcdprc(:,:)
+         gcp(:,:,3) = gcp(:,:,3) * gcdprc(:,:)
+         gcp(:,:,4) = gcp(:,:,4) * gcdprc(:,:)
+         IF( ( nsolv == 2 ) .OR. ( nsolv == 4 ) )  gccd(:,:) = sor * gcp(:,:,2)
+
+         IF( nsolv == 4 ) THEN
+            CALL lbc_lnk_e( gcp   (:,:,1), c_solver_pt, 1. )   ! lateral boundary conditions
+            CALL lbc_lnk_e( gcp   (:,:,2), c_solver_pt, 1. )   ! lateral boundary conditions
+            CALL lbc_lnk_e( gcp   (:,:,3), c_solver_pt, 1. )   ! lateral boundary conditions
+            CALL lbc_lnk_e( gcp   (:,:,4), c_solver_pt, 1. )   ! lateral boundary conditions
+            CALL lbc_lnk_e( gcdprc(:,:)  , c_solver_pt, 1. )   ! lateral boundary conditions
+            CALL lbc_lnk_e( gcdmat(:,:)  , c_solver_pt, 1. )   ! lateral boundary conditions         
+            IF( npolj /= 0 ) CALL sol_exd( gcp , c_solver_pt ) ! switch northernelements
+         END IF
+
+      ELSE
+         
+         ! FETI method
+         ! if feti solver : gcdprc is a mask for the non-overlapping
+         !   data structuring
+         
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( bmask(ji,jj) /= 0.e0 ) THEN
+                  gcdprc(ji,jj) = 1.e0
+               ELSE
+                  gcdprc(ji,jj) = 0.e0
+               ENDIF
+            END DO
+         END DO
+         
+         ! so "common" line & "common" column have to be !=0 except on global
+         !   domain boundaries
+         ! pbs with nbondi if nperio != 2 ?
+         !   ii = nldi-1
+         ! pb with nldi value if jperio==1 : nbondi modifyed at the end
+         !   of inimpp.F => pb
+         ! pb with periodicity conditions : iiend, ijend
+         
+         ijend = nlej
+         iiend = nlei
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 )   iiend = nlci - jpreci
+         ii = jpreci
+         
+         ! case number 1
+         
+         IF( nbondi /= -1 .AND. nbondi /= 2 ) THEN
+            DO jj = 1, ijend
+               IF( fmask(ii,jj,1) == 1. ) gcdprc(ii,jj) = 1.
+            END DO
+         ENDIF
+         
+         ! case number 2
+         
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+            DO jj = 1, ijend
+               IF( fmask(ii,jj,1) == 1. ) gcdprc(ii,jj) = 1.
+            END DO
+         ENDIF
+         
+         !      ij = nldj-1
+         ! pb with nldi value if jperio==1 : nbondi modifyed at the end
+         !   of inimpp.F => pb, here homogeneisation...
+         
+         ij = jprecj
+         IF( nbondj /= -1 .AND. nbondj /= 2 ) THEN
+            DO ji = 1, iiend
+               IF( fmask(ji,ij,1) == 1. ) gcdprc(ji,ij) = 1.
+            END DO
+         ENDIF
+      ENDIF
+      
+      
+      ! 4. Initialization the arrays used in pcg
+      ! ----------------------------------------
+      gcb  (:,:) = 0.e0
+      gcr  (:,:) = 0.e0
+      gcdes(:,:) = 0.e0
+      gccd (:,:) = 0.e0
+      
+      ! FETI method
+      IF( nsolv == 3 ) THEN
+         CALL fetmat       ! Matrix treatment : Neumann condition, inverse computation
+         CALL fetsch       ! data framework for the Schur Dual solver
+      ENDIF
+      
+   END SUBROUTINE sol_mat
+
+
+   SUBROUTINE sol_exd( pt3d, cd_type )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine sol_exd  ***
+      !!                  
+      !! ** Purpose :   Reorder gcb coefficient on the extra outer  halo 
+      !!                at north fold in case of T or F pivot
+      !!
+      !! ** Method  :   Perform a circular permutation of the coefficients on 
+      !!                the total area strictly above the pivot point,
+      !!                and on the semi-row of the pivot point   
+      !!                
+      !! History :
+      !!   9.0  !  05-09  (R. Benshila)  original routine
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of pt2d array grid-points
+         !             !  = T , U , V , F , W 
+         !             !  = S : T-point, north fold treatment
+         !             !  = G : F-point, north fold treatment
+         !             !  = I : sea-ice velocity at F-point with index shift
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj,4), INTENT( inout ) ::   &
+         pt3d          ! 2D array on which the boundary condition is applied
+
+      !! * Local variables
+      INTEGER  ::   ji, jk      ! dummy loop indices
+      INTEGER  ::   iloc                ! temporary integers
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj,4) ::   &
+         ztab          ! 2D array on which the boundary condition is applied
+      !!----------------------------------------------------------------------
+
+      ztab = pt3d
+
+      ! north fold treatment
+      ! -----------------------
+  
+      SELECT CASE ( npolj )
+         
+         CASE ( 3 , 4 )   !  T pivot
+         iloc = jpiglo/2 +1 
+            
+            SELECT CASE ( cd_type )
+  
+            CASE ( 'T', 'S', 'U', 'W' )
+               DO jk =1, 4
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     pt3d(ji,nlcj:nlcj+jpr2dj,jk) = ztab(ji,nlcj:nlcj+jpr2dj,jk+3-2*MOD(jk+3,4))           
+                  ENDDO
+               ENDDO
+
+              DO jk =1, 4
+                  DO ji = nlci+jpr2di, 1-jpr2di,  -1
+                     IF( ( ji .LT. mi0(iloc) .AND. mi0(iloc) /= 1 ) &
+                       & .OR. ( mi0(iloc) == jpi+1 ) ) EXIT
+                     pt3d(ji,nlcj-1,jk) = ztab(ji,nlcj-1,jk+3-2*MOD(jk+3,4))
+                  ENDDO
+               ENDDO
+
+            CASE ( 'F' ,'G' , 'I', 'V' )
+               DO jk =1, 4
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     pt3d(ji,nlcj-1:nlcj+jpr2dj,jk) = ztab(ji,nlcj-1:nlcj+jpr2dj,jk+3-2*MOD(jk+3,4))           
+                  ENDDO
+               ENDDO
+
+            END SELECT   ! cd_type
+  
+         CASE ( 5 , 6 )                 ! F pivot
+          iloc=jpiglo/2
+
+            SELECT CASE (cd_type )
+
+            CASE ( 'T'  ,'S', 'U', 'W')
+               DO jk =1, 4
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     pt3d(ji,nlcj:nlcj+jpr2dj,jk) = ztab(ji,nlcj:nlcj+jpr2dj,jk+3-2*MOD(jk+3,4))           
+                  ENDDO
+               ENDDO
+
+            CASE ( 'F' ,'G' , 'I', 'V' )
+               DO jk =1, 4
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     pt3d(ji,nlcj:nlcj+jpr2dj,jk) = ztab(ji,nlcj:nlcj+jpr2dj,jk+3-2*MOD(jk+3,4))           
+                  ENDDO
+               ENDDO
+               DO jk =1, 4
+                  DO ji = nlci+jpr2di, 1-jpr2di,  -1
+                    IF ( ( ji .LT. mi0(iloc) .AND. mi0(iloc) /= 1 ) &
+                       & .OR. ( mi0(iloc) == jpi+1 ) ) EXIT
+                    pt3d(ji,nlcj-1,jk) = ztab(ji,nlcj-1,jk+3-2*MOD(jk+3,4))
+                  ENDDO
+               ENDDO
+
+            END SELECT   ! cd_type
+
+         END SELECT   ! npolj
+  
+   END SUBROUTINE sol_exd
+
+#if defined key_feti
+
+   SUBROUTINE fetstr
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE fetstr  ***
+      !!               
+      !! ** Purpose :   Construction of the matrix of the barotropic stream 
+      !!      function system.
+      !!      Finite Elements Tearing & Interconnecting (FETI) approach
+      !!      Memory allocation and interface definition for the solver
+      !!
+      !! ** Method :
+      !!
+      !! References :
+      !!      Guyon, M, Roux, F-X, Chartier, M and Fraunie, P, 1994 :
+      !!      A domain decomposition solver to compute the barotropic 
+      !!      component of an OGCM in the parallel processing field.
+      !!      Ocean Modelling, issue 105, december 94.
+      !!
+      !! History :
+      !!        !  98-02 (M. Guyon)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE lib_feti            ! feti librairy
+      !! * Local declarations
+      INTEGER ::   iiend, ijend, iperio   ! temporary integers
+      !!---------------------------------------------------------------------
+      
+      
+      ! Preconditioning technics of the Dual Schur Operator
+      ! <= definition of the Coarse Grid solver
+      ! <= dimension of the nullspace of the local operators
+      ! <= Neumann boundaries conditions
+      
+      ! 0. Initializations
+      ! ------------------
+      
+      ndkerep = 1
+
+      ! initialization of the superstructures management
+
+      malxm = 1
+      malim = 1
+
+      ! memory space for the pcpg associated with the FETI dual formulation
+      ! ndkerep is associated to the list of rigid modes, 
+      ! ndkerep == 1 because the Dual Operator
+      ! is a first order operator due to SPG elliptic Operator is a
+      ! second order operator
+
+      nim = 50
+      nim = nim + ndkerep
+      nim = nim + 2*jpi + 2*jpj
+      nim = nim + jpi*jpj
+
+      nxm = 33
+      nxm = nxm + 4*jpnij
+      nxm = nxm + 19*(jpi+jpj)
+      nxm = nxm + 13*jpi*jpj
+      nxm = nxm + jpi*jpi*jpj
+
+      ! krylov space memory
+
+      iperio = 0
+      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6) iperio = 1
+      nxm = nxm + 3*(jpnij-jpni)*jpi
+      nxm = nxm + 3*(jpnij-jpnj+iperio)*jpj
+      nxm = nxm + 2*(jpi+jpj)*(jpnij-jpni)*jpi
+      nxm = nxm + 2*(jpi+jpj)*(jpnij-jpnj+iperio)*jpj
+
+      ! Resolution with the Schur dual Method ( frontal and local solver by
+      ! blocks
+      ! Case with a local symetrical matrix
+      ! The local matrix is stored in a multi-column form
+      ! The total number of nodes for this subdomain is named "noeuds"
+
+      noeuds = jpi*jpj
+      nifmat = jpi-1
+      njfmat = jpj-1
+      nelem = nifmat*njfmat
+      npe = 4
+      nmorse = 5*noeuds
+      
+      ! 1. mesh building
+      ! ----------------
+      
+      ! definition of specific information for a subdomain
+      !  narea           : subdomain number = processor number +1 
+      !  ninterf         : neighbour subdomain number
+      !  nni             : interface point number
+      !  ndvois array    : neighbour subdomain list 
+      !  maplistin array : node pointer at each interface
+      !  maplistin array : concatened list of interface nodes
+      
+      !  messag coding is necessary by interface type for avoid collision
+      !  if nperio == 1 
+      
+      !  lint  array     : indoor interface list / type
+      !  lext  array     : outdoor interface list / type
+      
+      !  domain with jpniXjpnj subdomains
+      
+      CALL feti_inisub(nifmat,njfmat,nbondi,nbondj,nperio,   &
+          nbsw,nbnw,nbse,nbne,ninterf,ninterfc,nni,nnic)
+
+      CALL feti_creadr(malim,malimax,nim,3*ninterf ,mandvois ,'ndvois' )
+      CALL feti_creadr(malim,malimax,nim,3*ninterfc,mandvoisc,'ndvoisc')
+      CALL feti_creadr(malim,malimax,nim,ninterfc+1,maplistin,'plistin')
+      CALL feti_creadr(malim,malimax,nim,nnic      ,malistin ,'listin' )
+
+      ! pb with periodicity conditions : iiend, ijend
+
+      ijend = nlej
+      iiend = nlei
+      IF (jperio == 1) iiend = nlci - jpreci
+
+      CALL feti_subound(nifmat,njfmat,nldi,iiend,nldj,ijend,   &
+          narea,nbondi,nbondj,nperio,   &
+          ninterf,ninterfc,   &
+          nowe,noea,noso,nono,   &
+          nbsw,nbnw,nbse,nbne,   &
+          npsw,npnw,npse,npne,   &
+          mfet(mandvois),mfet(mandvoisc),   &
+          mfet(maplistin),nnic,mfet(malistin) )
+
+   END SUBROUTINE fetstr
+
+
+   SUBROUTINE fetmat
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE fetmat  ***
+      !!            
+      !! ** Purpose :   Construction of the matrix of the barotropic stream 
+      !!      function system.
+      !!      Finite Elements Tearing & Interconnecting (FETI) approach
+      !!      Matrix treatment : Neumann condition, inverse computation
+      !!
+      !! ** Method :
+      !!
+      !! References :
+      !!      Guyon, M, Roux, F-X, Chartier, M and Fraunie, P, 1994 :
+      !!      A domain decomposition solver to compute the barotropic 
+      !!      component of an OGCM in the parallel processing field.
+      !!      Ocean Modelling, issue 105, december 94.
+      !!
+      !! History :
+      !!        !  98-02 (M. Guyon)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE lib_feti            ! feti librairy
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jl
+      INTEGER ::   iimask(jpi,jpj)
+      INTEGER ::   iiend, ijend
+      REAL(wp) ::   zres, zres2, zdemi
+      !!---------------------------------------------------------------------
+
+      ! Matrix computation
+      ! ------------------
+
+      CALL feti_creadr(malxm,malxmax,nxm,nmorse,maan,'matrice a')
+
+      nnitot = nni
+
+      CALL mpp_sum( nnitot, 1, numit0ete )
+      CALL feti_creadr(malxm,malxmax,nxm,npe*npe,maae,'ae')
+
+      ! initialisation of the local barotropic matrix
+      ! local boundary conditions on the halo
+
+      CALL lbc_lnk( gcp(:,:,1), 'F', 1)
+      CALL lbc_lnk( gcp(:,:,2), 'F', 1) 
+      CALL lbc_lnk( gcp(:,:,3), 'F', 1) 
+      CALL lbc_lnk( gcp(:,:,4), 'F', 1) 
+      CALL lbc_lnk( gcdmat    , 'T', 1)
+
+      ! Neumann conditions
+      ! initialisation of the integer Neumann Mask
+
+      CALL feti_iclr(jpi*jpj,iimask)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            iimask(ji,jj) = INT( gcdprc(ji,jj) )
+         END DO
+      END DO
+
+      ! regularization of the local matrix
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            gcdmat(ji,jj) = gcdmat(ji,jj) * gcdprc(ji,jj) + 1. - gcdprc(ji,jj)
+         END DO
+      END DO
+
+      DO jk = 1, 4
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               gcp(ji,jj,jk) = gcp(ji,jj,jk) * gcdprc(ji,jj)
+            END DO
+         END DO
+      END DO
+      
+      ! implementation of the west, east, north & south Neumann conditions
+
+      zdemi  = 0.5
+
+      ! pb with periodicity conditions : iiend, ijend
+
+      ijend = nlej
+      iiend = nlei
+      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) iiend = nlci - jpreci
+
+      IF( nbondi == 2 .AND. (nperio /= 1 .OR. nperio /= 4 .OR. nperio == 6) ) THEN
+
+         ! with the periodicity : no east/west interface if nbondi = 2
+         ! and nperio != 1
+
+      ELSE 
+         ! west
+         IF( nbondi /= -1 ) THEN 
+            DO jj = 1, jpj
+               IF( iimask(1,jj) /= 0 ) THEN
+                  gcp(1,jj,2) = 0.e0
+                  gcp(1,jj,1) = zdemi * gcp(1,jj,1)
+                  gcp(1,jj,4) = zdemi * gcp(1,jj,4)
+               ENDIF
+            END DO
+            DO jj = 1, jpj
+               IF( iimask(1,jj) /= 0 ) THEN
+                  gcdmat(1,jj) = - ( gcp(1,jj,1) + gcp(1,jj,2) + gcp(1,jj,3) + gcp(1,jj,4) )
+               ENDIF
+            END DO
+         ENDIF
+         ! east
+         IF( nbondi /= 1 ) THEN 
+            DO jj = 1, jpj
+               IF( iimask(iiend,jj) /= 0 ) THEN
+                  gcp(iiend,jj,3) = 0.e0
+                  gcp(iiend,jj,1) = zdemi * gcp(iiend,jj,1)
+                  gcp(iiend,jj,4) = zdemi * gcp(iiend,jj,4)
+               ENDIF
+            END DO
+            DO jj = 1, jpj
+               IF( iimask(iiend,jj) /= 0 ) THEN
+                  gcdmat(iiend,jj) = - ( gcp(iiend,jj,1) + gcp(iiend,jj,2)   &
+                                       + gcp(iiend,jj,3) + gcp(iiend,jj,4) )
+               ENDIF
+            END DO
+         ENDIF
+      ENDIF
+
+      ! south
+      IF( nbondj /= -1 .AND. nbondj /= 2 ) THEN 
+         DO ji = 1, jpi
+            IF( iimask(ji,1) /= 0 ) THEN
+               gcp(ji,1,1) = 0.e0
+               gcp(ji,1,2) = zdemi * gcp(ji,1,2)
+               gcp(ji,1,3) = zdemi * gcp(ji,1,3)
+            ENDIF
+         END DO
+         DO ji = 1, jpi
+            IF( iimask(ji,1) /= 0 ) THEN
+               gcdmat(ji,1) = - ( gcp(ji,1,1) + gcp(ji,1,2) + gcp(ji,1,3) + gcp(ji,1,4) )
+            ENDIF
+         END DO
+      ENDIF
+      
+      ! north
+      IF( nbondj /= 1 .AND. nbondj /= 2 ) THEN 
+         DO ji = 1, jpi
+            IF( iimask(ji,ijend) /= 0 ) THEN
+               gcp(ji,ijend,4) = 0.e0
+               gcp(ji,ijend,2) = zdemi * gcp(ji,ijend,2) 
+               gcp(ji,ijend,3) = zdemi * gcp(ji,ijend,3)
+            ENDIF
+         END DO
+         DO ji = 1, jpi
+            IF( iimask(ji,ijend) /= 0 ) THEN
+               gcdmat(ji,ijend) = - ( gcp(ji,ijend,1) + gcp(ji,ijend,2)   &
+                                    + gcp(ji,ijend,3) + gcp(ji,ijend,4) )
+            ENDIF
+         END DO
+      ENDIF
+
+      ! matrix terms are  saved in FETI solver arrays
+      CALL feti_vmov(noeuds,gcp(1,1,1),wfeti(maan))
+      CALL feti_vmov(noeuds,gcp(1,1,2),wfeti(maan+noeuds))
+      CALL feti_vmov(noeuds,gcdmat,wfeti(maan+2*noeuds))
+      CALL feti_vmov(noeuds,gcp(1,1,3),wfeti(maan+3*noeuds))
+      CALL feti_vmov(noeuds,gcp(1,1,4),wfeti(maan+4*noeuds))
+
+      ! construction of Dirichlet liberty degrees array
+      CALL feti_subdir(nifmat,njfmat,noeuds,ndir,iimask)
+      CALL feti_creadr(malim,malimax,nim,ndir,malisdir,'lisdir')
+      CALL feti_listdir(jpi,jpj,iimask,ndir,mfet(malisdir))
+
+      ! stop onto  matrix term for Dirichlet conditions
+      CALL feti_blomat(nifmat+1,njfmat+1,wfeti(maan),ndir,mfet(malisdir))
+
+      ! reservation of factorized diagonal blocs and temporary array for
+      ! factorization
+      npblo = (njfmat+1) * (nifmat+1) * (nifmat+1)
+      ndimax = nifmat+1
+
+      CALL feti_creadr(malxm,malxmax,nxm,npblo,mablo,'blo')
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,madia,'dia')
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,mav,'v')
+      CALL feti_creadr(malxm,malxmax,nxm,ndimax*ndimax,mautil,'util')
+
+      ! stoping the rigid modes
+
+      ! the number of rigid modes =< Max [dim(Ker(Ep))]
+      !                                p=1,Np
+
+      CALL feti_creadr(malim,malimax,nim,ndkerep,malisblo,'lisblo')
+
+      ! Matrix factorization
+
+      CALL feti_front(noeuds,nifmat+1,njfmat+1,wfeti(maan),npblo,   &
+          wfeti(mablo),wfeti(madia),   &
+          wfeti(mautil),wfeti(mav),ndlblo,mfet(malisblo),ndkerep)
+      CALL feti_prext(noeuds,wfeti(madia))
+
+      ! virtual dealloc => we have to see for a light f90 version
+      ! the super structure is removed to clean the coarse grid
+      ! solver structure
+
+      malxm = madia
+      CALL feti_vclr(noeuds,wfeti(madia))
+      CALL feti_vclr(noeuds,wfeti(mav))
+      CALL feti_vclr(ndimax*ndimax,wfeti(mautil))
+
+      ! ndlblo is the dimension of the local nullspace .=<. the size of the 
+      ! memory of the superstructure associated to the nullspace : ndkerep
+      ! ndkerep is introduced to avoid messages "out of bounds" when memory
+      ! is checked
+
+      ! copy matrix for Dirichlet condition
+
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,miax,'x')
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,may,'y')
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,maz,'z')
+
+      ! stoping the rigid modes
+
+      ! ndlblo is the dimension of the local nullspace .=<. the size of the 
+      ! memory of the superstructure associated to the nullspace : ndkerep
+      ! ndkerep is introduced to avoid messages "out of bounds" when memory
+      ! is checked
+
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep*noeuds,mansp,'nsp')
+      CALL feti_blomat1(nifmat+1,njfmat+1,wfeti(maan),ndlblo,   &
+          mfet(malisblo),wfeti(mansp))      
+
+      ! computation of operator kernel
+
+      CALL feti_nullsp(noeuds,nifmat+1,njfmat+1,npblo,wfeti(mablo),   &
+          wfeti(maan),ndlblo,mfet(malisblo),wfeti(mansp),   &
+          wfeti(maz))
+
+      ! test of the factorisation onto each sub domain
+
+      CALL feti_init(noeuds,wfeti(may))
+      CALL feti_blodir(noeuds,wfeti(may),ndir,mfet(malisdir))
+      CALL feti_blodir(noeuds,wfeti(may),ndlblo,mfet(malisblo))
+      CALL feti_vclr(noeuds,wfeti(miax))
+      CALL feti_resloc(noeuds,nifmat+1,njfmat+1,wfeti(maan),npblo,   &
+          wfeti(mablo),wfeti(may),wfeti(miax),wfeti(maz)) 
+      CALL feti_proax(noeuds,nifmat+1,njfmat+1,wfeti(maan),wfeti(miax),   &
+          wfeti(maz))
+      CALL feti_blodir(noeuds,wfeti(maz),ndlblo,mfet(malisblo))
+      CALL feti_vsub(noeuds,wfeti(may),wfeti(maz),wfeti(maz))
+
+      zres2 = 0.e0
+      DO jl = 1, noeuds
+         zres2 = zres2 + wfeti(may+jl-1) * wfeti(may+jl-1)
+      END DO
+      CALL mpp_sum(zres2,1,zres)
+
+      res2 = 0.e0
+      DO jl = 1, noeuds
+         res2 = res2 + wfeti(maz+jl-1) * wfeti(maz+jl-1)
+      END DO 
+      res2 = res2 / zres2
+      CALL mpp_sum(res2,1,zres)
+
+      res2 = SQRT(res2)
+      IF(lwp) WRITE(numout,*) 'global residu : sqrt((Ax-b,Ax-b)/(b.b)) =', res2
+
+      IF( res2 > (eps/100.) ) THEN 
+         IF(lwp) WRITE (numout,*) 'eps is :',eps
+         IF(lwp) WRITE (numout,*) 'factorized matrix precision :',res2
+         STOP 
+      ENDIF
+
+   END SUBROUTINE fetmat
+
+
+   SUBROUTINE fetsch
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE fetsch  ***
+      !!        
+      !! ** Purpose :
+      !!     Construction of the matrix of the barotropic stream function
+      !!     system.
+      !!     Finite Elements Tearing & Interconnecting (FETI) approach
+      !!     Data framework for the Schur Dual solve
+      !!
+      !! ** Method :
+      !!
+      !! References :
+      !!      Guyon, M, Roux, F-X, Chartier, M and Fraunie, P, 1994 :
+      !!      A domain decomposition solver to compute the barotropic 
+      !!      component of an OGCM in the parallel processing field.
+      !!      Ocean Modelling, issue 105, december 94.
+      !!
+      !! History :
+      !!        !  98-02 (M. Guyon)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE lib_feti            ! feti librairy
+      !! * Local declarations
+      !!---------------------------------------------------------------------
+
+      !  computing weights for the conform construction
+
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,mapoids ,'poids' )
+      CALL feti_creadr(malxm,malxmax,nxm,nnic  ,mabufin ,'bufin' )
+      CALL feti_creadr(malxm,malxmax,nxm,nnic  ,mabufout,'bufout')
+
+!!    CALL feti_poids(ninterfc,mfet(mandvoisc),mfet(maplistin),nnic,   &
+!!        mfet(malistin),narea,noeuds,wfeti(mapoids),wfeti(mabufin),   &
+!!        wfeti(mabufout) )
+      CALL feti_poids(ninterfc,                                nnic,   &
+          mfet(malistin),      noeuds,wfeti(mapoids)                )
+
+
+      ! Schur dual arrays
+ 
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,mabitw,'bitw') 
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,mautilu,'utilu') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,malambda,'lambda') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,mag,'g') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,mapg,'pg') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,mamg,'mg') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,maw,'w') 
+      CALL feti_creadr(malxm,malxmax,nxm,nni,madw,'dw')
+
+      !  coarse grid solver dimension and arrays
+
+      nitmaxete = ndlblo
+      CALL  mpp_sum(nitmaxete,1,numit0ete)
+
+      nitmaxete = nitmaxete + 1
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep,maxnul,'xnul')
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep,maynul,'ynul')
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep,maeteg,'eteg')
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep,maeteag,'eteag')
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep*nitmaxete,maeted,'eted')
+      CALL feti_creadr(malxm,malxmax,nxm,ndkerep*nitmaxete,maetead,'etead')
+      CALL feti_creadr(malxm,malxmax,nxm,nitmaxete,maeteadd,'eteadd')
+      CALL feti_creadr(malxm,malxmax,nxm,nitmaxete,maetegamm,'etegamm')
+      CALL feti_creadr(malxm,malxmax,nxm,nni,maetew,'etew') 
+      CALL feti_creadr(malxm,malxmax,nxm,noeuds,maetev,'etev') 
+
+      ! construction of semi interface arrays
+
+      CALL feti_creadr(malim,malimax,nim,ninterf+1,maplistih,'plistih')
+!!    CALL feti_halfint(ninterf,mfet(mandvois),mfet(maplistin),nni,   &
+!!        mfet(maplistih),nnih,narea)
+      CALL feti_halfint(ninterf,mfet(mandvois),mfet(maplistin),       & 
+          mfet(maplistih),nnih      )
+
+      CALL feti_creadr(malxm,malxmax,nxm,nnih,magh,'gh') 
+
+      ! Schur Dual Method
+
+      nmaxd = nnitot / 2
+
+      !  computation of the remain array for descent directions
+
+      nmaxd = min0(nmaxd,(nxm-nitmaxete-malxm)/(2*nnih+3))
+      CALL mpp_min(nmaxd,1,numit0ete)
+
+      nitmax = nnitot/2
+      epsilo = eps
+      ntest = 0
+
+      ! Krylov space construction
+
+      CALL feti_creadr(malxm,malxmax,nxm,nnih*nmaxd,mawj,'wj') 
+      CALL feti_creadr(malxm,malxmax,nxm,nnih*nmaxd,madwj,'dwj') 
+      CALL feti_creadr(malxm,malxmax,nxm,nmaxd,madwwj,'dwwj') 
+      CALL feti_creadr(malxm,malxmax,nxm,nmaxd,magamm,'gamm') 
+      CALL feti_creadr(malxm,malxmax,nxm,max0(nmaxd,nitmaxete),mawork,'work')
+      mjj0 = 0 
+      numit0ete = 0 
+
+   END SUBROUTINE fetsch
+
+#else
+   SUBROUTINE fetstr                 ! Empty routine
+   END SUBROUTINE fetstr
+   SUBROUTINE fetmat                 ! Empty routine
+   END SUBROUTINE fetmat
+   SUBROUTINE fetsch                 ! Empty routine
+   END SUBROUTINE fetsch
+#endif
+
+   !!======================================================================
+END MODULE solmat
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solpcg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solpcg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solpcg.F90	(revision 4536)
@@ -0,0 +1,192 @@
+MODULE solpcg
+   !!======================================================================
+   !!                     ***  MODULE  solfet
+   !! Ocean solver :  preconditionned conjugate gradient solver
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   sol_pcg    : preconditionned conjugate gradient solver
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE sol_oce         ! ocean solver variables
+   USE lib_mpp         ! distributed memory computing
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_pcg              ! ???
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE sol_pcg( kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_pcg  ***
+      !!                    
+      !! ** Purpose :   Solve the ellipic equation for the barotropic stream 
+      !!      function system (lk_dynspg_rl=T) or the transport divergence 
+      !!      system (lk_dynspg_flt=T) using a diagonal preconditionned
+      !!      conjugate gradient method.
+      !!      In the former case, the barotropic stream function trend has a
+      !!      zero boundary condition along all coastlines (i.e. continent
+      !!      as well as islands) while in the latter the boundary condition
+      !!      specification is not required.
+      !!
+      !! ** Method  :   Diagonal preconditionned conjugate gradient method.
+      !!      the algorithm is multitasked. (case of 5 points matrix)
+      !!      define              pa  = q^-1 * a
+      !!                        pgcb  = q^-1 * gcb
+      !!                 < . ; . >_q  = ( . )^t q ( . )
+      !!      where q is the preconditioning matrix = diagonal matrix of the
+      !!                                              diagonal elements of a
+      !!      Initialization:
+      !!         x(o) = gcx
+      !!         r(o) = d(o) = pgcb - pa.x(o)
+      !!         rr(o)= < r(o) , r(o) >_q
+      !!      Iteration n   :
+      !!         z(n)   = pa.d(n)
+      !!         alp(n) = rr(n) / < z(n) , d(n) >_q
+      !!         x(n+1) = x(n) + alp(n) d(n)
+      !!         r(n+1) = r(n) - alp(n) z(n)
+      !!         rr(n+1)= < r(n+1) , r(n+1) >_q
+      !!         bet(n) = rr(n+1) / rr(n)
+      !!         r(n+1) = r(n+1) + bet(n+1) d(n)
+      !!      Convergence test :
+      !!         rr(n+1) / < gcb , gcb >_q   =< epsr
+      !!
+      !! ** Action : - niter  : solver number of iteration done
+      !!             - res    : solver residu reached
+      !!             - gcx()  : solution of the elliptic system
+      !!
+      !! References :
+      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-04  (M. Guyon)  loops and suppress pointers
+      !!        !  95-09  (M. Imbard, J. Escobar)  mpp exchange 
+      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solpcg
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jn                ! dummy loop indices
+      REAL(wp) ::   zgcad                    ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      !                                                !================
+      DO jn = 1, nmax                                  ! Iterative loop
+         !                                             !================
+
+         IF( jn == 1 ) THEN           ! Initialization of the algorithm
+
+            CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! lateral boundary condition
+
+            ! gcr   = gcb-a.gcx
+            ! gcdes = gsr
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zgcad = bmask(ji,jj) * ( gcb(ji,jj  ) -                gcx(ji  ,jj  )   &
+                     &                                  - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
+                     &                                  - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
+                     &                                  - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
+                     &                                  - gcp(ji,jj,4) * gcx(ji  ,jj+1)   )
+                  gcr  (ji,jj) = zgcad
+                  gcdes(ji,jj) = zgcad
+               END DO
+            END DO
+            
+            rnorme = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
+            IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+            rr = rnorme
+
+         ENDIF
+        
+         !                             ! Algorithm
+        
+         CALL lbc_lnk( gcdes, c_solver_pt, 1. )   ! lateral boundary condition
+        
+         ! ... gccd = matrix . gcdes
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               gccd(ji,jj) = bmask(ji,jj)*( gcdes(ji,jj)   &
+                  &        +gcp(ji,jj,1)*gcdes(ji,jj-1)+gcp(ji,jj,2)*gcdes(ji-1,jj)   &
+                  &        +gcp(ji,jj,4)*gcdes(ji,jj+1)+gcp(ji,jj,3)*gcdes(ji+1,jj)   )
+            END DO
+         END DO
+ 
+         ! alph = (gcr,gcr)/(gcdes,gccd)
+         radd = SUM(  gcdes(:,:) * gcdmat(:,:) * gccd(:,:)  )
+         IF( lk_mpp )   CALL mpp_sum( radd )   ! sum over the global domain
+         alph = rr / radd
+         
+         ! gcx = gcx + alph * gcdes
+         ! gcr = gcr - alph * gccd
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               gcx(ji,jj) = bmask(ji,jj) * ( gcx(ji,jj) + alph * gcdes(ji,jj) )
+               gcr(ji,jj) = bmask(ji,jj) * ( gcr(ji,jj) - alph * gccd (ji,jj) )
+            END DO
+         END DO
+        
+         ! rnorme = (gcr,gcr)
+         rnorme = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
+         IF( lk_mpp )   CALL  mpp_sum( rnorme )   ! sum over the global domain
+        
+         ! test of convergence
+         IF( rnorme < epsr .OR. jn == nmax ) THEN
+            res = SQRT( rnorme )
+            niter = jn
+            ncut = 999
+         ENDIF
+        
+         ! beta = (rk+1,rk+1)/(rk,rk)
+         beta = rnorme / rr
+         rr   = rnorme
+
+         ! indicator of non-convergence or explosion
+         IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
+         IF( ncut == 999 ) GOTO 999
+
+         ! gcdes = gcr + beta * gcdes
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               gcdes(ji,jj) = bmask(ji,jj)*( gcr(ji,jj) + beta * gcdes(ji,jj) )
+            END DO
+         END DO
+        
+         !                                             !================
+      END DO                                           !    End Loop
+      !                                                !================
+     
+999   CONTINUE
+     
+     
+      ! Output in gcx with lateral b.c. applied
+      ! ---------------------------------------
+     
+      CALL lbc_lnk( gcx, c_solver_pt, 1. )
+     
+   END SUBROUTINE sol_pcg
+
+   !!=====================================================================
+END MODULE solpcg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor.F90	(revision 4536)
@@ -0,0 +1,171 @@
+MODULE solsor
+   !!======================================================================
+   !!                     ***  MODULE  solsor  ***
+   !! Ocean solver :  Successive Over-Relaxation solver
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   sol_sor     : Red-Black Successive Over-Relaxation solver
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE sol_oce         ! solver variables
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_sor              ! ???
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+      
+   SUBROUTINE sol_sor( kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_sor  ***
+      !!                 
+      !! ** Purpose :   Solve the ellipic equation for the barotropic stream 
+      !!      function system (lk_dynspg_rl=T) or the transport divergence 
+      !!      system (lk_dynspg_flt=T) using a red-black successive-over-
+      !!      relaxation method.
+      !!       In the former case, the barotropic stream function trend has a
+      !!     zero boundary condition along all coastlines (i.e. continent
+      !!     as well as islands) while in the latter the boundary condition
+      !!     specification is not required.
+      !!
+      !! ** Method  :   Successive-over-relaxation method using the red-black 
+      !!      technique. The former technique used was not compatible with 
+      !!      the north-fold boundary condition used in orca configurations.
+      !!
+      !! References :
+      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!   7.1  !  93-04  (G. Madec)  time filter
+      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!   9.0  !  03-04  (C. Deltel, G. Madec)  Red-Black SOR in free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solsor
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jn               ! dummy loop indices
+      INTEGER  ::   ishift
+      REAL(wp) ::   ztmp, zres, zres2
+
+      INTEGER  ::   ijmppodd, ijmppeven
+      !!----------------------------------------------------------------------
+      
+      ijmppeven = MOD(nimpp+njmpp  ,2)
+      ijmppodd  = MOD(nimpp+njmpp+1,2)
+      !                                                       ! ==============
+      DO jn = 1, nmax                                         ! Iterative loop 
+         !                                                    ! ==============
+
+         CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! applied the lateral boundary conditions
+         
+         ! Residus
+         ! -------
+
+         ! Guess black update
+         DO jj = 2, jpjm1
+            ishift = MOD( jj-ijmppodd, 2 )
+            DO ji = 2+ishift, jpim1, 2
+               ztmp =                  gcb(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx(ji  ,jj+1)
+               ! Estimate of the residual
+               zres = ztmp - gcx(ji,jj)
+               gcr(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx(ji,jj) = sor * ztmp + (1-sor) * gcx(ji,jj)
+            END DO
+         END DO
+
+         CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! applied the lateral boubary conditions
+
+         ! Guess red update
+         DO jj = 2, jpjm1
+            ishift = MOD( jj-ijmppeven, 2 )
+            DO ji = 2+ishift, jpim1, 2
+               ztmp =                  gcb(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx(ji  ,jj+1) 
+               ! Estimate of the residual
+               zres = ztmp - gcx(ji,jj)
+               gcr(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx(ji,jj) = sor * ztmp + (1-sor) * gcx(ji,jj)
+            END DO
+         END DO
+
+         ! test of convergence
+         IF ( jn > nmin .AND. MOD( jn-nmin, nmod ) == 0 ) then
+
+            SELECT CASE ( nsol_arp )
+            CASE ( 0 )                 ! absolute precision (maximum value of the residual)
+               zres2 = MAXVAL( gcr(2:jpim1,2:jpjm1) )
+               IF( lk_mpp )   CALL mpp_max( zres2 )   ! max over the global domain
+               ! test of convergence
+               IF( zres2 < resmax .OR. jn == nmax ) THEN
+                  res = SQRT( zres2 )
+                  niter = jn
+                  ncut = 999
+               ENDIF
+            CASE ( 1 )                 ! relative precision
+               rnorme = SUM( gcr(2:jpim1,2:jpjm1) )
+               IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+               ! test of convergence
+               IF( rnorme < epsr .OR. jn == nmax ) THEN
+                  res = SQRT( rnorme )
+                  niter = jn
+                  ncut = 999
+               ENDIF
+            END SELECT
+         
+         !****
+         !     IF(lwp)WRITE(numsol,9300) jn, res, sqrt( epsr ) / eps
+9300     FORMAT('          niter :',i4,' res :',e20.10,' b :',e20.10)
+         !****
+         
+         ENDIF
+         ! indicator of non-convergence or explosion
+         IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
+         IF( ncut == 999 ) GOTO 999
+         
+         !                                                 ! =====================
+      END DO                                               ! END of iterative loop
+      !                                                    ! =====================
+      
+999   CONTINUE
+      
+      
+      !  Output in gcx
+      !  -------------
+
+      CALL lbc_lnk( gcx, c_solver_pt, 1. )    ! boundary conditions
+
+      
+   END SUBROUTINE sol_sor
+
+   !!=====================================================================
+END MODULE solsor
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor_e.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor_e.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solsor_e.F90	(revision 4536)
@@ -0,0 +1,186 @@
+MODULE solsor_e
+   !!======================================================================
+   !!                     ***  MODULE  solsor  ***
+   !! Ocean solver :  Successive Over-Relaxation solver
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   sol_sor     : Red-Black Successive Over-Relaxation solver
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE sol_oce         ! solver variables
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC sol_sor_e              ! ???
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+      
+   SUBROUTINE sol_sor_e( kindic )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sol_sor  ***
+      !!                 
+      !! ** Purpose :   Solve the ellipic equation for the barotropic stream 
+      !!      function system (lk_dynspg_rl=T) or the transport divergence 
+      !!      system (lk_dynspg_flt=T) using a red-black successive-over-
+      !!      relaxation method.
+      !!       In the former case, the barotropic stream function trend has a
+      !!     zero boundary condition along all coastlines (i.e. continent
+      !!     as well as islands) while in the latter the boundary condition
+      !!     specification is not required.
+      !!       This routine provides a MPI optimization to the existing solsor
+      !!     by reducing the number of call to lbc.
+      !! 
+      !! ** Method  :   Successive-over-relaxation method using the red-black 
+      !!      technique. The former technique used was not compatible with 
+      !!      the north-fold boundary condition used in orca configurations.
+      !!      Compared to the classical sol_sor, this routine provides a 
+      !!      mpp optimization by reducing the number of calls to lnc_lnk
+      !!      The solution is computed on a larger area and the boudary
+      !!      conditions only when the inside domain is reached.
+      !! 
+      !! References :
+      !!      Madec et al. 1988, Ocean Modelling, issue 78, 1-6.
+      !!      Beare and Stevens 1997 Ann. Geophysicae 15, 1369-1377
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!   7.1  !  93-04  (G. Madec)  time filter
+      !!        !  96-05  (G. Madec)  merge sor and pcg formulations
+      !!        !  96-11  (A. Weaver)  correction to preconditioning
+      !!   9.0  !  03-04  (C. Deltel, G. Madec)  Red-Black SOR in free form
+      !!   9.0  !  05-09  (R. Benshila, G. Madec)  MPI optimization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( inout ) ::   kindic   ! solver indicator, < 0 if the conver-
+      !                                      ! gence is not reached: the model is
+      !                                      ! stopped in step
+      !                                      ! set to zero before the call of solsor
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jn               ! dummy loop indices
+      INTEGER  ::   ishift, icount
+      REAL(wp) ::   ztmp, zres, zres2
+
+      INTEGER  ::   ijmppodd, ijmppeven
+      INTEGER  ::   ijpr2d
+      !!----------------------------------------------------------------------
+      
+      ijmppeven = MOD(nimpp+njmpp+jpr2di+jpr2dj,2)
+      ijmppodd  = MOD(nimpp+njmpp+jpr2di+jpr2dj+1,2)
+      ijpr2d = MAX(jpr2di,jpr2dj)
+      icount = 0
+      !                                                       ! ==============
+      DO jn = 1, nmax                                         ! Iterative loop 
+         !                                                    ! ==============
+
+         ! applied the lateral boundary conditions
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx, c_solver_pt, 1. )   
+        
+         ! Residus
+         ! -------
+
+         ! Guess black update
+         DO jj = 2-jpr2dj, nlcj-1+jpr2dj
+            ishift = MOD( jj-ijmppodd-jpr2dj, 2 )
+            DO ji = 2-jpr2di+ishift, nlci-1+jpr2di, 2
+               ztmp =                  gcb(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx(ji  ,jj+1)
+               ! Estimate of the residual
+               zres = ztmp - gcx(ji,jj)
+               gcr(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx(ji,jj) = sor * ztmp + (1-sor) * gcx(ji,jj)
+            END DO
+         END DO
+         icount = icount + 1 
+ 
+         ! applied the lateral boundary conditions
+         IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx, c_solver_pt, 1. )  
+
+         ! Guess red update
+         DO jj = 2-jpr2dj, nlcj-1+jpr2dj
+            ishift = MOD( jj-ijmppeven-jpr2dj, 2 )
+            DO ji = 2-jpr2di+ishift, nlci-1+jpr2di, 2
+               ztmp =                  gcb(ji  ,jj  )   &
+                  &   - gcp(ji,jj,1) * gcx(ji  ,jj-1)   &
+                  &   - gcp(ji,jj,2) * gcx(ji-1,jj  )   &
+                  &   - gcp(ji,jj,3) * gcx(ji+1,jj  )   &
+                  &   - gcp(ji,jj,4) * gcx(ji  ,jj+1) 
+               ! Estimate of the residual
+               zres = ztmp - gcx(ji,jj)
+               gcr(ji,jj) = zres * gcdmat(ji,jj) * zres
+               ! Guess update
+               gcx(ji,jj) = sor * ztmp + (1-sor) * gcx(ji,jj)
+            END DO
+         END DO
+         icount = icount + 1
+
+         ! test of convergence
+         IF ( jn > nmin .AND. MOD( jn-nmin, nmod ) == 0 ) then
+
+            SELECT CASE ( nsol_arp )
+            CASE ( 0 )                 ! absolute precision (maximum value of the residual)
+               zres2 = MAXVAL( gcr(2:nlci-1,2:nlcj-1) )
+               IF( lk_mpp )   CALL mpp_max( zres2 )   ! max over the global domain
+               ! test of convergence
+               IF( zres2 < resmax .OR. jn == nmax ) THEN
+                  res = SQRT( zres2 )
+                  niter = jn
+                  ncut = 999
+               ENDIF
+            CASE ( 1 )                 ! relative precision
+               rnorme = SUM( gcr(2:nlci-1,2:nlcj-1) )
+               IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+               ! test of convergence
+               IF( rnorme < epsr .OR. jn == nmax ) THEN
+                  res = SQRT( rnorme )
+                  niter = jn
+                  ncut = 999
+               ENDIF
+            END SELECT
+         
+         !****
+         !     IF(lwp)WRITE(numsol,9300) jn, res, sqrt( epsr ) / eps
+9300     FORMAT('          niter :',i4,' res :',e20.10,' b :',e20.10)
+         !****
+         
+         ENDIF
+         ! indicator of non-convergence or explosion
+         IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2
+         IF( ncut == 999 ) GOTO 999
+         
+         !                                                 ! =====================
+      END DO                                               ! END of iterative loop
+      !                                                    ! =====================
+      
+999   CONTINUE
+      
+      
+      !  Output in gcx
+      !  -------------
+
+      CALL lbc_lnk_e( gcx, c_solver_pt, 1. )    ! boundary conditions
+
+      
+   END SUBROUTINE sol_sor_e
+
+   !!=====================================================================
+END MODULE solsor_e
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solver.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solver.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/SOL/solver.F90	(revision 4536)
@@ -0,0 +1,248 @@
+MODULE solver
+   !!======================================================================
+   !!                     ***  MODULE  solver  ***
+   !! Ocean solver :  initialization of ocean solver
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   solver_init: solver initialization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE sol_oce         ! solver variables
+   USE solmat          ! ???
+   USE solisl          ! ???
+   USE obc_oce         ! Lateral open boundary condition
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+
+   IMPLICIT NONE
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE solver_init( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE solver_init  ***
+      !!                   
+      !! ** Purpose :   Initialization for the solver of the elliptic equation:
+      !!       * default option: barotropic stream function system
+      !!         and islands initialization (if lk_isl=T)
+      !!       * lk_dynspg_flt = T : transport divergence system. No specific
+      !!         treatment of islands.
+      !!      
+      !! ** Method :
+      !!       - Compute the local depth of the water column at u- and v-point
+      !!      (lk_dynspg_flt = T) or its inverse (lk_dynspg_rl = T).
+      !!      The local depth of the water column is computed by summing 
+      !!      the vertical scale factors. For its inverse, the thickness of
+      !!      the first model level is imposed as lower bound. The inverse of
+      !!      this depth is THEN taken and masked, so that the inverse of the
+      !!      local depth is zero when the local depth is zero.
+      !!       - Construct the matrix of the elliptic system by a call to
+      !!      solmat.F routine.
+      !!       - island (if lk_isl=T)
+      !!            isl_dom: find islands from the bathymetry file
+      !!            isl_bsf: compute the island barotropic stream function
+      !!            isl_mat: compute the inverse island matrix
+      !!            set mbathy to the number of non-zero w-levels of a water
+      !!            column (the minimum value of mbathy is 2):
+      !!                  mbathy = min( mbathy, 1 ) + 1
+      !!
+      !! ** Action : - hur, hvr : masked inverse of the local depth at
+      !!                                u- and v-point. (lk_dynspg_rl = T)
+      !!             - hu, hv   : masked local depth at u- and v- points
+      !!                                (lk_dynspg_flt = T)
+      !!             - c_solver_pt : nature of the gridpoint at which the
+      !!                                solver is applied
+      !! References :
+      !!      Jensen, 1986: adv. phys. oceanogr. num. mod.,ed. o brien,87-110.
+      !!      Madec & Marti, 1990: internal rep. LODYC, 90/03., 29pp.
+      !!
+      !! History :
+      !!        !  90-10  (G. Madec)  Original code           
+      !!        !  93-02  (O. Marti)                         
+      !!        !  97-02  (G. Madec)  local depth inverse computation
+      !!        !  98-10  (G. Roullet, G. Madec)  free surface 
+      !!   9.0  !  03-07  (G. Madec)  free form, F90
+      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in) :: kt
+
+      !! * Local declarations
+      INTEGER :: ji, jj   ! dummy loop indices
+      CHARACTER(len=80) :: clname
+
+      NAMELIST/namsol/ nsolv, nsol_arp, nmin, nmax, nmod, eps, resmax, sor, epsisl, nmisl, rnu
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'solver_init : solver to compute the surface pressure gradient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+      ! open elliptic solver statistics file
+      clname = 'solver.stat'
+      CALL ctlopn( numsol, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+                   1, numout, lwp, 1 )
+
+
+      ! 0. Define the solver parameters
+      !    ----------------------------
+      ! Namelist namsol : elliptic solver / islands / free surface
+      REWIND( numnam )
+      READ  ( numnam, namsol )
+
+#if defined key_feti
+      ! FETI algorithm, we force nsolv at 3
+      nsolv = 3
+#endif
+
+      ! 0. Parameter control and print
+      !    ---------------------------
+
+      ! Control print
+      IF(lwp) WRITE(numout,*) '          Namelist namsol : set solver parameters'
+
+      IF(lwp) THEN
+         WRITE(numout,*) '             type of elliptic solver            nsolv    = ', nsolv
+         WRITE(numout,*) '             absolute/relative (0/1) precision  nsol_arp = ', nsol_arp
+         WRITE(numout,*) '             minimum iterations for solver      nmin     = ', nmin
+         WRITE(numout,*) '             maximum iterations for solver      nmax     = ', nmax
+         WRITE(numout,*) '             frequency for test                 nmod     = ', nmod
+         WRITE(numout,*) '             absolute precision of solver       eps      = ', eps
+         WRITE(numout,*) '             absolute precision for SOR solver  resmax   = ', resmax
+         WRITE(numout,*) '             optimal coefficient of sor         sor      = ', sor
+         IF(lk_isl) WRITE(numout,*) '             absolute precision stream fct    epsisl   = ', epsisl
+         IF(lk_isl) WRITE(numout,*) '             maximum pcg iterations island    nmisl    = ', nmisl
+         WRITE(numout,*) '             free surface parameter         rnu    = ', rnu
+         WRITE(numout,*)
+      ENDIF
+
+      IF( lk_dynspg_flt ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          free surface formulation'
+         IF( lk_isl ) CALL ctl_stop( ' key_islands inconsistent with key_dynspg_flt' )
+    
+      ELSEIF( lk_dynspg_rl ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '          Rigid lid formulation'
+      ELSE
+         CALL ctl_stop( '          Choose only one surface pressure gradient calculation: filtered or rigid-lid',   &
+              &         '          Should not call this routine if dynspg_exp or dynspg_ts has been chosen' )
+      ENDIF
+      IF( lk_dynspg_flt .AND. lk_dynspg_rl ) &
+         CALL ctl_stop( '          Chose between free surface or rigid-lid, not both' )
+
+      SELECT CASE ( nsolv )
+
+      CASE ( 1 )                ! preconditioned conjugate gradient solver
+         IF(lwp) WRITE(numout,*) '          a preconditioned conjugate gradient solver is used'
+         IF( jpr2di /= 0 .AND. jpr2dj /= 0 ) &
+            CALL ctl_stop( ' jpr2di and jpr2dj should be equal to zero' )
+
+      CASE ( 2 )                ! successive-over-relaxation solver
+         IF(lwp) WRITE(numout,*) '          a successive-over-relaxation solver is used'
+         IF( jpr2di /= 0 .AND. jpr2dj /= 0 ) &
+             CALL ctl_stop( ' jpr2di and jpr2dj should be equal to zero' )
+
+      CASE ( 3 )                ! FETI solver
+         IF(lwp) WRITE(numout,*) '          the FETI solver is used'
+         IF( jpr2di /= 0 .AND. jpr2dj /= 0 ) &
+              CALL ctl_stop( ' jpr2di and jpr2dj should be equal to zero' )
+           
+         IF( .NOT.lk_mpp ) THEN
+            CALL ctl_stop( ' The FETI algorithm is used only with the key_mpp_... option' )
+         ELSE
+            IF( jpnij == 1 ) THEN
+               CALL ctl_stop( ' The FETI algorithm needs more than one processor' )
+            ENDIF
+         ENDIF
+         
+      CASE ( 4 )                ! successive-over-relaxation solver with extra outer halo
+         IF(lwp) WRITE(numout,*) '          a successive-over-relaxation solver with extra outer halo is used'
+         IF(lwp) WRITE(numout,*) '          with jpr2di =', jpr2di, ' and  jpr2dj =', jpr2dj
+         IF( .NOT. lk_mpp .AND. jpr2di /= 0 .AND. jpr2dj /= 0 ) THEN
+             CALL ctl_stop( ' jpr2di and jpr2dj are not equal to zero',   &
+             &              ' In this case this algorithm should be used only with the key_mpp_... option' )
+         ELSE
+            IF( ( ( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) .OR. ( jpni /= 1 ) ) &
+              &  .AND. ( jpr2di /= jpr2dj ) ) CALL ctl_stop( '          jpr2di should be equal to jpr2dj' )
+         ENDIF
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nsolv = ', nsolv
+         CALL ctl_stop( ctmp1 )
+         
+      END SELECT
+
+      IF( nbit_cmp == 1 .AND. nsolv /= 2 ) THEN
+         CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require the SOR solver: nsolv = 2' )
+      END IF
+
+      ! Grid-point at which the solver is applied
+      ! -----------------------------------------
+
+      IF( lk_dynspg_rl ) THEN       ! rigid-lid
+         IF( lk_mpp ) THEN
+            c_solver_pt = 'G'   ! G= F with special staff ??? which one?
+         ELSE
+            c_solver_pt = 'F'
+         ENDIF
+      ELSE                          ! free surface T-point
+         IF( lk_mpp ) THEN
+            c_solver_pt = 'S'   ! S=T with special staff ??? which one?
+         ELSE
+            c_solver_pt = 'T'
+         ENDIF
+      ENDIF
+
+
+      ! Construction of the elliptic system matrix
+      ! ------------------------------------------
+
+      CALL sol_mat( kt )
+
+
+      IF( lk_isl ) THEN
+      
+         ! Islands in the domain
+         ! ---------------------
+
+         IF ( jpisl == 0 ) THEN
+             WRITE(ctmp1,*) ' bad islands parameter jpisl =', jpisl
+             CALL ctl_stop( ctmp1 )
+         ENDIF
+
+         ! open Island streamfunction statistic file
+         CALL ctlopn( numisp, 'islands.stat', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1     , numout        , lwp      , 1                         )
+   
+         CALL isl_dom       ! Island identification
+
+         CALL isl_bsf       ! Island barotropic stream function
+
+         CALL isl_mat       ! Comput and invert the island matrix
+
+         ! mbathy set to the number of w-level (minimum value 2)
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               mbathy(ji,jj) = MAX( 1, mbathy(ji,jj) ) + 1
+            END DO
+         END DO
+
+      ENDIF
+
+   END SUBROUTINE solver_init
+
+   !!======================================================================
+END MODULE solver
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 4536)
@@ -0,0 +1,196 @@
+MODULE traadv
+   !!==============================================================================
+   !!                       ***  MODULE  traadv  ***
+   !! Ocean active tracers:  advection trend 
+   !!==============================================================================
+   !! History :  1.0  !  2005-11  (G. Madec)  Original code
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   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 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 trabbl          ! tracers: bottom boundary layer
+   USE ldftra_oce      ! lateral diffusion coefficient on tracers
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv    ! routine called by step module
+ 
+   !!* Namelist nam_traadv
+   LOGICAL, PUBLIC ::   ln_traadv_cen2   = .TRUE.       ! 2nd order centered scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_tvd    = .FALSE.      ! TVD scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl  = .FALSE.      ! MUSCL scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl2 = .FALSE.      ! MUSCL2 scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_ubs    = .FALSE.      ! UBS scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_qck    = .FALSE.      ! QUICKEST scheme flag
+
+   INTEGER ::   nadv   ! choice of the type of advection scheme
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRA/traadv.F90,v 1.7 2007/06/05 11:00:53 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/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), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn   ! effective transports
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_adv_ctl          ! initialisation & control of options
+
+
+      !                                              ! effective transport
+      DO jk = 1, jpkm1 
+#if defined key_trabbl_adv
+         !                                                ! eulerian + bbl transport
+         zun(:,:,jk) = e2u(:,:) * fse3u(:,:,jk) * ( un(:,:,jk) - u_bbl(:,:,jk) )
+         zvn(:,:,jk) = e1v(:,:) * fse3v(:,:,jk) * ( vn(:,:,jk) - v_bbl(:,:,jk) )
+         zwn(:,:,jk) = e1t(:,:) * e2t(:,:)      * ( wn(:,:,jk) + w_bbl(:,:,jk) )
+#else
+         !                                                ! eulerian transport only
+         zun(:,:,jk) = e2u(:,:) * fse3u(:,:,jk) *   un(:,:,jk) 
+         zvn(:,:,jk) = e1v(:,:) * fse3v(:,:,jk) *   vn(:,:,jk)
+         zwn(:,:,jk) = e1t(:,:) * e2t(:,:)      *   wn(:,:,jk)
+#endif
+      END DO
+      zwn(:,:,jpk) = 0.e0                                 ! no transport trough the bottom
+
+      !                                                   ! add the eiv transport (if necessary)
+      IF( lk_traldf_eiv )   CALL tra_adv_eiv( kt, zun, zvn, zwn ) 
+
+
+      SELECT CASE ( nadv )                           ! compute advection trend and add it to general trend
+      !
+      CASE ( 1 )   ;   CALL tra_adv_cen2    ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! 2nd order centered
+                       CALL tra_adv_cen2    ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )    ! on T & S
+      !
+      CASE ( 2 )   ;   CALL tra_adv_tvd     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! TVD      scheme
+                       CALL tra_adv_tvd     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )    ! on T & S
+      !
+      CASE ( 3 )   ;   CALL tra_adv_muscl   ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb    , ta )    ! MUSCL    scheme
+                       CALL tra_adv_muscl   ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb    , sa )    ! on T & S
+      !
+      CASE ( 4 )   ;   CALL tra_adv_muscl2  ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! MUSCL2   scheme
+                       CALL tra_adv_muscl2  ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )    ! on T & S
+      !
+      CASE ( 5 )   ;   CALL tra_adv_ubs     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! UBS      scheme
+                       CALL tra_adv_ubs     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )    ! on T & S
+      !
+      CASE ( 6 )   ;   CALL tra_adv_qck     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! QUICKEST scheme
+                       CALL tra_adv_qck     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )    ! on T & S
+      !
+      CASE (-1 )                                     ! NEMO debug : test all the schemes at once
+                       CALL tra_adv_cen2    ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! 2nd order centered
+                       CALL tra_adv_cen2    ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa ) 
+                       CALL tra_adv_tvd     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! TVD      scheme
+                       CALL tra_adv_tvd     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )  
+                       CALL tra_adv_muscl   ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb    , ta )    ! MUSCL    scheme
+                       CALL tra_adv_muscl   ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb    , sa ) 
+                       CALL tra_adv_muscl2  ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! MUSCL2   scheme
+                       CALL tra_adv_muscl2  ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )
+                       CALL tra_adv_ubs     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! UBS      scheme
+                       CALL tra_adv_ubs     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )
+                       CALL tra_adv_qck     ( kt, 'TRA', jp_tem, zun, zvn, zwn, tb, tn, ta )    ! QUICKEST scheme
+                       CALL tra_adv_qck     ( kt, 'TRA', jp_sal, zun, zvn, zwn, sb, sn, sa )
+      END SELECT
+      !
+   END SUBROUTINE tra_adv
+
+
+   SUBROUTINE tra_adv_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              tracer advection schemes and set nadv
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+      !!
+      NAMELIST/nam_traadv/ ln_traadv_cen2 , ln_traadv_tvd,    &
+         &                 ln_traadv_muscl, ln_traadv_muscl2, &
+         &                 ln_traadv_ubs  , ln_traadv_qck
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_traadv : tracer advection scheme
+      READ   ( numnam, nam_traadv )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_ctl : choice/control of the tracer advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_traadv : 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
+    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( lk_esopa         )   ioptio =          1
+
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist nam_traadv' )
+
+      IF( n_cla == 1 .AND. .NOT. ln_traadv_cen2 )   &
+         &                CALL ctl_stop( 'cross-land advection only with 2nd order advection scheme' )
+
+      !                               ! 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( 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,*) '         PPM       scheme is used'
+         IF( nadv ==  7 )   WRITE(numout,*) '         QUICKEST  scheme is used'
+         IF( nadv == -1 )   WRITE(numout,*) '         NEMO debug: test all advection scheme at once'
+      ENDIF
+      !
+   END SUBROUTINE tra_adv_ctl
+
+  !!======================================================================
+END MODULE traadv
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_cen2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 4536)
@@ -0,0 +1,203 @@
+MODULE traadv_cen2
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_cen2  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  8.2  !  2001-08  (G. Madec, E. Durand)  trahad+trazad = traadv 
+   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
+   !!   NEMO     1.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!             -   !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!             -   !  2006-04  (R. Benshila, G. Madec) Step reorganization
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_cen2 : update the tracer trend with the horizontal and vertical
+   !!                  advection trends using a 2nd order centered scheme
+   !!----------------------------------------------------------------------
+   USE oce, ONLY: tn   ! now ocean temperature
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE flxrnf          !
+   USE ocfzpt          !
+   USE lib_mpp
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE diaptr          ! poleward transport diagnostics
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_cen2   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_cen2( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                       ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_cen2  ***
+      !!                 
+      !! ** Purpose :   Compute the now trend due to the advection of a tracer
+      !!      and add it to the corresponding general trend of tracer equations.
+      !!
+      !! ** Method  :   The advection is evaluated by a second order centered
+      !!      scheme using now fields (leap-frog scheme). In specific areas
+      !!      (vicinity of major river mouths, some straits, or where tn is
+      !!      approaching the freezing point) it is mixed with an upstream
+      !!      scheme for stability reasons.
+      !!         Part 0 : compute the upstream / centered flag
+      !!                  (3D array, zind, defined at T-point (0<zind<1))
+      !!         Part I : advective fluxes
+      !!       * centered flux:   zcenu = pun  mi(ptn)         (idem for v and w)
+      !!       * upstream flux:   zupsu = pun  (ptb(i) or ptb(i-1) ) [un>0 or <0]
+      !!       * mixed upstream / centered flux:
+      !!               zcofi = max(zind(i+1), zind(i))
+      !!               zwx = zcofi * zupsu + (1-zcofi) * zcenu
+      !!         Part III : advective trend
+      !!       * horizontal advective trend (divergence of the fluxes)
+      !!         added to the general trend of tracer (pta):
+      !!               pta = pta - 1/(e1t*e2t*e3t) { di-1[zwx] + dj-1[zwy] + dk[zwz] }
+      !!       * trend diagnostic (lk_trdtra=T): the advective fluxes are
+      !!      where the 3 part of advective trend are recomputed as U.grad[T]
+      !!      and then used in on-line diagnostics.
+      !!
+      !!         NB: The surface boundary condition is no flux for both
+      !!      rigid-lid (lk_dynspg_frd = T) and non-linear free-surface
+      !!      but a flux (pwn(1) * ptn(1)) cross the surface in linear
+      !!      free-surface case (lk_dynspg_fsc = T)
+      !!
+      !! ** Action :  - update pta with the 2nd order centered advective trends
+      !!              - trend diagnostics (lk_trdtra=T)
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk                                    ! dummy loop indices
+      REAL(wp) ::   zbtr                                          ! temporary scalars
+      REAL(wp) ::   zcofi, zcenut, zupsut, zfp_ui, zfm_ui         !    "         "
+      REAL(wp) ::   zcofj, zcenvt, zupsvt, zfp_vj, zfm_vj         !    "         "
+      REAL(wp) ::   zcofk, zcent , zupst , zfp_w , zfm_w          !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, zwy, zwz, zind   ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_cen2 : 2nd order centered advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      ! Upstream / centered scheme indicator
+      ! ------------------------------------
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zind(ji,jj,jk) =  MAX ( upsrnfh(ji,jj) * upsrnfz(jk),     &  ! changing advection scheme near runoff
+                  &                    upsadv(ji,jj)                     &  ! in the vicinity of some straits
+#if defined key_ice_lim
+                  &                  , tmask(ji,jj,jk)                   &  ! half upstream tracer fluxes
+                  &                  * MAX( 0., SIGN( 1., fzptn(ji,jj)   &  ! if tn < ("freezing"+0.1 )
+                  &                                +0.1-tn(ji,jj,jk) ) ) &
+#endif
+                  &                  )
+            END DO
+         END DO
+      END DO
+
+      ! I. Advective fluxes
+      ! -------------------
+      DO jk = 1, jpkm1                                 ! Horizontal advective fluxes
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! upstream indicator
+               zcofi = MAX( zind(ji+1,jj,jk), zind(ji,jj,jk) )
+               zcofj = MAX( zind(ji,jj+1,jk), zind(ji,jj,jk) )
+               ! 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) )
+               zupsut = zfp_ui * ptb(ji,jj,jk) + zfm_ui * ptb(ji+1,jj  ,jk)
+               zupsvt = zfp_vj * ptb(ji,jj,jk) + zfm_vj * ptb(ji  ,jj+1,jk)
+               ! centered scheme
+               zcenut = pun(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji+1,jj  ,jk) )
+               zcenvt = pvn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji  ,jj+1,jk) )
+               ! mixed centered / upstream scheme
+               zwx(ji,jj,jk) = 0.5 * ( zcofi * zupsut + (1.-zcofi) * zcenut )
+               zwy(ji,jj,jk) = 0.5 * ( zcofj * zupsvt + (1.-zcofj) * zcenvt )
+            END DO
+         END DO
+      END DO
+      !                                                ! Vertical advective fluxes
+      zwz(:,:,jpk) = 0.e0                                   ! Bottom  value : flux set to zero
+      !                                                     ! Surface value : 
+      IF( lk_dynspg_rl .OR. lk_vvl ) THEN   ;   zwz(:,:, 1 ) = 0.e0                      ! rigid lid or non-linear fs
+      ELSE                                  ;   zwz(:,:, 1 ) = pwn(:,:,1) * ptn(:,:,1)   ! linear free surface 
+      ENDIF
+      !
+      DO jk = 2, jpkm1                                      ! interior values
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! upstream indicator
+               zcofk = MAX( zind(ji,jj,jk-1), zind(ji,jj,jk) )
+               ! upstream scheme
+               zfp_w = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
+               zfm_w = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
+               zupst = zfp_w * ptb(ji,jj,jk) + zfm_w * ptb(ji,jj,jk-1)
+               ! centered scheme
+               zcent = pwn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji,jj,jk-1) )
+               ! mixed centered / upstream scheme
+               zwz(ji,jj,jk) = 0.5 * ( zcofk * zupst + (1.-zcofk) * zcent )
+            END DO
+         END DO
+      END DO
+
+      ! II. Divergence of advective fluxes
+      ! ----------------------------------
+      DO jk = 1, jpkm1                   
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ! advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - 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)  )
+            END DO
+         END DO
+      END DO
+
+
+      ! III. Diagnostics and control print
+      ! ----------------------------------
+      IF( l_trdtra ) THEN                            ! trend diagnostics
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, zwx, pun, ptn )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, zwy, pvn, ptn )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_zad, cdtype, zwz, pwn, ptn )
+      ENDIF
+      !                                              ! "Poleward" heat and salt transport 
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_adv(:) = ptr_vj( zwy(:,:,:) )
+         IF( ktra == jp_sal)   pst_adv(:) = ptr_vj( zwy(:,:,:) )
+      ENDIF
+      !                                              ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' cen2 - adv: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_cen2
+
+   !!======================================================================
+END MODULE traadv_cen2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_eiv.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_eiv.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_eiv.F90	(revision 4536)
@@ -0,0 +1,226 @@
+MODULE traadv_eiv
+   !!======================================================================
+   !!                    ***  MODULE  traadv_eiv  ***
+   !! Ocean active tracers:  advection trend - eddy induced velocity
+   !!======================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code, from traldf and zdf _iso
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+#if defined key_traldf_eiv   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_eiv'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_iso : update the tracer trend with the horizontal component
+   !!                 of iso neutral laplacian operator or horizontal 
+   !!                 laplacian operator in s-coordinate
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfslp          ! iso-neutral slopes
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_eiv   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "ldfeiv_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_eiv( kt, pun, pvn, pwn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_eiv  ***
+      !! 
+      !! ** Purpose :   Compute the eddy induced transport and add it to the
+      !!              effective transport
+      !!
+      !! ** Method  :   The eddy induced transport is computed from the slope
+      !!      of iso-neutral surfaces computed in routine ldf_slp as follows:
+      !!         zu_eiv =   dk[ aeiu e2u mi(wslpi) ]
+      !!         zv_eiv =   dk[ aeiv e1v mj(wslpj) ]
+      !!         zw_eiv = - { di[ aeiu e2u mi(wslpi) ] + dj[ aeiv e1v mj(wslpj) ] }
+      !!      add the eiv component to the model velocity:
+      !!         p.n = p.n + z._eiv
+      !! CAUTION : the horizontal transports not updated along jpi column and jpj row
+      !!           the vertical   transports not updated along 1 & jpi columns and 1 & jpj rows
+      !!
+      !! ** Action  : - add to p.n the eiv component
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun   ! in : 3 ocean transport components 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvn   ! out: 3 ocean transport components
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwn   !      increased by the eiv
+      !!
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp) ::   zuwk, zuwk1, zuwi, zuwi1   ! temporary scalar
+      REAL(wp) ::   zvwk, zvwk1, zvwj, zvwj1   !    "         "
+      REAL(wp) ::   zu_eiv, zv_eiv, zw_eiv     !    "         "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_eiv : eddy induced advection :'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   add to velocity fields the eiv component'
+# if defined key_diaeiv
+         u_eiv(:,:,:) = 0.e0
+         v_eiv(:,:,:) = 0.e0
+         w_eiv(:,:,:) = 0.e0
+# endif
+      ENDIF
+      !                                             ! =================
+      DO jk = 1, jpkm1                              !  Horizontal slab
+         !                                          ! =================
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zuwk = ( wslpi(ji,jj,jk  ) + wslpi(ji+1,jj,jk  ) ) * fsaeiu(ji,jj,jk  ) * umask(ji,jj,jk  )
+               zuwk1= ( wslpi(ji,jj,jk+1) + wslpi(ji+1,jj,jk+1) ) * fsaeiu(ji,jj,jk+1) * umask(ji,jj,jk+1)
+               zvwk = ( wslpj(ji,jj,jk  ) + wslpj(ji,jj+1,jk  ) ) * fsaeiv(ji,jj,jk  ) * vmask(ji,jj,jk  )
+               zvwk1= ( wslpj(ji,jj,jk+1) + wslpj(ji,jj+1,jk+1) ) * fsaeiv(ji,jj,jk+1) * vmask(ji,jj,jk+1)
+
+               zu_eiv = 0.5 * umask(ji,jj,jk) * ( zuwk - zuwk1 )
+               zv_eiv = 0.5 * vmask(ji,jj,jk) * ( zvwk - zvwk1 )
+   
+               pun(ji,jj,jk) = pun(ji,jj,jk) + e2u(ji,jj) * zu_eiv
+               pvn(ji,jj,jk) = pvn(ji,jj,jk) + e1v(ji,jj) * zv_eiv
+# if defined key_diaeiv
+               u_eiv(ji,jj,jk) = zu_eiv / fse3u(ji,jj,jk)
+               v_eiv(ji,jj,jk) = zv_eiv / fse3v(ji,jj,jk)
+# endif
+            END DO
+         END DO
+         IF( jk >=2 ) THEN                             ! jk=1 zw_eiv=0, not computed
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+# if defined key_traldf_c2d || defined key_traldf_c3d
+                  zuwi  = ( wslpi(ji,jj,jk)+wslpi(ji-1,jj,jk) ) * fsaeiu(ji-1,jj,jk) * e2u(ji-1,jj) * umask(ji-1,jj,jk)
+                  zuwi1 = ( wslpi(ji,jj,jk)+wslpi(ji+1,jj,jk) ) * fsaeiu(ji  ,jj,jk) * e2u(ji  ,jj) * umask(ji  ,jj,jk)
+                  zvwj  = ( wslpj(ji,jj,jk)+wslpj(ji,jj-1,jk) ) * fsaeiv(ji,jj-1,jk) * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
+                  zvwj1 = ( wslpj(ji,jj,jk)+wslpj(ji,jj+1,jk) ) * fsaeiv(ji,jj  ,jk) * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
+  
+                  zw_eiv = - 0.5 * tmask(ji,jj,jk) * ( zuwi1 - zuwi + zvwj1 - zvwj ) / ( e1t(ji,jj)*e2t(ji,jj) )
+# else
+                  zuwi  = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) ) * e2u(ji-1,jj) * umask(ji-1,jj,jk)
+                  zuwi1 = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) ) * e2u(ji  ,jj) * umask(ji  ,jj,jk)
+                  zvwj  = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) ) * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
+                  zvwj1 = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) ) * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
+
+                  zw_eiv = - 0.5 * tmask(ji,jj,jk) * fsaeiw(ji,jj,jk) * ( zuwi1 - zuwi + zvwj1 - zvwj )
+# endif
+                  pwn(ji,jj,jk) = pwn(ji,jj,jk) + zw_eiv
+
+# if defined key_diaeiv
+                  w_eiv(ji,jj,jk) = zw_eiv / ( e1t(ji,jj)*e2t(ji,jj) )
+# endif
+               END DO
+            END DO
+         ENDIF
+         !                                          ! =================
+      END DO                                        !    End of slab  
+      !                                             ! =================
+   END SUBROUTINE tra_adv_eiv
+
+
+!!gm   test tra_adv_eiv better (faster) coded?  to be verified
+
+   SUBROUTINE tra_adv_eiv2( kt, pun, pvn, pwn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_eiv  ***
+      !! 
+      !! ** Purpose :   Compute the eddy induced transport and add it to the
+      !!              effective transport
+      !!
+      !! ** Method  :   The eddy induced transport is computed from the slope
+      !!              of iso-neutral surfaces (see ldfslp.F90) as follows:
+      !!                   zu_eiv =   dk[ aeiu e2u mi(wslpi) ]
+      !!                   zv_eiv =   dk[ aeiv e1v mj(wslpj) ]
+      !!                   zw_eiv = - { di[ aeiu e2u mi(wslpi) ] + dj[ aeiv e1v mj(wslpj) ] }
+      !!              add the eiv component to the model velocity:
+      !!                   p.n = p.n + z._eiv
+      !! CAUTION : the horizontal transports not updated along jpi column and jpj row
+      !!           the vertical   transports not updated along 1 & jpi columns and 1 & jpj rows
+      !!
+      !! ** Action  : - add to p.n the eiv transport component
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun   ! in : 3 ocean transport components 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvn   ! out: 3 ocean transport components
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwn   !      increased by the eiv
+      !!
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp) ::   zuwslpi, zvwslpj           ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsfu, zsfv   ! eiv stream-function in u and v directions
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_eiv : eddy induced advection :'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   add to velocity fields the eiv component'
+      ENDIF
+
+      ! eiv stream-function in u- and v-directions
+      ! NB: UW-point mask at level k is umask(:,:,k) idem form VW-point mask
+      zsfu(:,:, 1 ) = 0.e0   ;   zsfv(:,:, 1 ) = 0.e0      ! surface value set to zero
+      zsfu(:,:,jpk) = 0.e0   ;   zsfv(:,:,jpk) = 0.e0      ! bottom  value set to zero
+      DO jk = 2, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zuwslpi = 0.5 * ( wslpi(ji+1,jj,jk) + wslpi(ji,jj,jk) )
+               zvwslpj = 0.5 * ( wslpj(ji,jj+1,jk) + wslpj(ji,jj,jk) ) 
+               zsfu(ji,jj,jk) = zuwslpi * e2u(ji,jj) * fsaeiu(ji,jj,jk) * umask(ji,jj,jk)
+               zsfv(ji,jj,jk) = zvwslpj * e1v(ji,jj) * fsaeiv(ji,jj,jk) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+# if defined key_diaeiv
+      ! save eiv stream function in the output
+!!gm  to be done, u_sfeiv and v_sfeiv not defined    ==> new IOM....
+!!gm  and zsfu, zfv notdefined for jpi column and jpj row
+!     u_sfeiv(:,:,:) = zsfu(:,:,:)
+!     v_sfeiv(:,:,:) = zsfu(:,:,:)
+# endif
+
+      ! increase the transport with the eiv transport
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               pun(ji,jj,jk) = pun(ji,jj,jk) + ( zsfu(ji,jj,jk) - zsfu(ji,jj,jk+1) )
+               pvn(ji,jj,jk) = pvn(ji,jj,jk) + ( zsfv(ji,jj,jk) - zsfv(ji,jj,jk+1) )
+            END DO
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               pwn(ji,jj,jk) = pwn(ji,jj,jk) - (  zsfu(ji,jj,jk) - zsfu(ji-1,jj  ,jk)                        &
+                  &                             + zsfv(ji,jj,jk) - zsfv(ji  ,jj-1,jk)  ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_adv_eiv2
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             No rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_adv_eiv( kt, pun, pvn, pwn )              ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   pun, pvn, pwn
+      WRITE(*,*) 'tra_adv_eiv: You should not have seen this print! error?', kt, pun(1,1,1), pvn(1,1,1), pwn(1,1,1)
+   END SUBROUTINE tra_adv_eiv
+#endif
+
+   !!==============================================================================
+END MODULE traadv_eiv
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 4536)
@@ -0,0 +1,255 @@
+MODULE traadv_muscl
+   !!======================================================================
+   !!                       ***  MODULE  traadv_muscl  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!======================================================================
+   !! History :  OPA  !  2006-00  (A.Estublier)  for passive tracers
+   !!            8.2  !  2001-08  (E.Durand, G.Madec)  adapted for T & S
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_muscl : update the tracer trend with the horizontal
+   !!                   and vertical advection trends using MUSCL scheme
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE trabbl          ! tracers: bottom boundary layer
+   USE lib_mpp         ! distribued memory computing
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_muscl   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_muscl( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                        ptb     , pta )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE tra_adv_muscl  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to total advection of T and 
+      !!      S using a MUSCL scheme (Monotone Upstream-centered Scheme for
+      !!      Conservation Laws) and add it to the general tracer trend.
+      !!
+      !! ** Method  : MUSCL scheme plus centered scheme at ocean boundaries
+      !!
+      !! ** Action  : - update (pta,sa) with the now advective tracer trends
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
+      !!
+      !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zu, z0u, zzwx
+      REAL(wp) ::   zv, z0v, zzwy 
+      REAL(wp) ::   zw, z0w 
+      REAL(wp) ::   zbtr, z2, zdt, zalpha 
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zwx, zwy, zslpx, zslpy   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv : MUSCL advection scheme'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.      ! euler     time-stepping
+      ELSE                                        ;    z2 = 2.      ! leap-frog time-stepping
+      ENDIF
+
+      ! I. Horizontal advective fluxes
+      ! ------------------------------
+      !                                             !-- first guess of the slopes
+      zwx(:,:,jpk) = 0.e0   ;   zwy(:,:,jpk) = 0.e0        ! bottom values
+      DO jk = 1, jpkm1                                     ! interior values
+         DO jj = 1, jpjm1      
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zwx(ji,jj,jk) = umask(ji,jj,jk) * ( ptb(ji+1,jj,jk) - ptb(ji,jj,jk) )
+               zwy(ji,jj,jk) = vmask(ji,jj,jk) * ( ptb(ji,jj+1,jk) - ptb(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+!!gm optimisation (lbc to be suppressed)
+      CALL lbc_lnk( zwx, 'U', -1. )                        ! lateral boundary conditions on zwx, zwy   (changed sign)
+      CALL lbc_lnk( zwy, 'V', -1. )
+!!gm
+
+      !                                             !-- Slopes of tracer
+      zslpx(:,:,jpk) = 0.e0   ;   zslpy(:,:,jpk) = 0.e0    ! bottom values
+      DO jk = 1, jpkm1                                     ! interior values
+         DO jj = 2, jpjm1
+            DO ji = fs_2, jpim1   ! vector opt.
+               zslpx(ji,jj,jk) =                    ( zwx(ji,jj,jk) + zwx(ji-1,jj  ,jk) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji-1,jj  ,jk) ) )
+               zslpy(ji,jj,jk) =                    ( zwy(ji,jj,jk) + zwy(ji  ,jj-1,jk) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwy(ji,jj,jk) * zwy(ji  ,jj-1,jk) ) )
+            END DO
+         END DO
+      END DO
+!!gm  :merge the 2 loop (above & below)
+      DO jk = 1, jpkm1                                     ! Slopes limitation
+         DO jj = 2, jpjm1
+            DO ji = fs_2, jpim1   ! vector opt.
+               zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN(    ABS( zslpx(ji  ,jj,jk) ),   &
+                  &                                                 2.*ABS( zwx  (ji-1,jj,jk) ),   &
+                  &                                                 2.*ABS( zwx  (ji  ,jj,jk) ) )
+               zslpy(ji,jj,jk) = SIGN( 1., zslpy(ji,jj,jk) ) * MIN(    ABS( zslpy(ji,jj  ,jk) ),   &
+                  &                                                 2.*ABS( zwy  (ji,jj-1,jk) ),   &
+                  &                                                 2.*ABS( zwy  (ji,jj  ,jk) ) )
+            END DO
+         END DO
+      END DO        
+!!gm optimisation:  call lbclnk just 1 time here on zslpx & zslpy
+!!    CALL lbc_lnk( zslpx, 'U', -1. )                      ! lateral boundary conditions on zwx, zwy   (changed sign)
+!!    CALL lbc_lnk( zslpy, 'V', -1. )
+!!
+!! and loop below from 1 to jpjm1 and to jpim1
+!!gm
+
+      !                                             !-- MUSCL horizontal advective fluxes
+      DO jk = 1, jpkm1                                     ! interior values
+         zdt  = z2 * rdttra(jk)
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z0u = SIGN( 0.5, pun(ji,jj,jk) )            
+               zalpha = 0.5 - z0u
+               zu  = z0u - 0.5 * pun(ji,jj,jk) * zdt / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zzwx = ptb(ji+1,jj,jk) + zu * zslpx(ji+1,jj,jk)
+               zzwy = ptb(ji  ,jj,jk) + zu * zslpx(ji  ,jj,jk)
+               zwx(ji,jj,jk) = pun(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
+               !
+               z0v = SIGN( 0.5, pvn(ji,jj,jk) )            
+               zalpha = 0.5 - z0v
+               zv  = z0v - 0.5 * pvn(ji,jj,jk) * zdt / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               zzwx = ptb(ji,jj+1,jk) + zv * zslpy(ji,jj+1,jk)
+               zzwy = ptb(ji,jj  ,jk) + zv * zslpy(ji,jj  ,jk)
+               zwy(ji,jj,jk) = pvn(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
+            END DO
+         END DO
+      END DO
+!!gm optimisation (lbc to be suppressed)
+      !                                                    ! lateral boundary conditions on zwx, zwy   (changed sign)
+      CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )
+!!gm
+
+      !                                             !-- MUSCL advective trend
+      ! Tracer flux divergence at t-point added to the general trend
+      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) )
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                  &                                   + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  ) ) 
+            END DO
+        END DO
+      END DO        
+
+      IF( l_trdtra ) THEN                           !-- trend diagnostics
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, zwx, pun, ptb )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, zwy, pvn, ptb )
+      ENDIF
+      !                                             !-- "Poleward" heat or salt transports
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_adv(:) = ptr_vj( zwy(:,:,:) )
+         IF( ktra == jp_sal)   pst_adv(:) = ptr_vj( zwy(:,:,:) )
+      ENDIF
+      !                                             !-- control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' muscl - had: ', mask1=tmask, clinfo3=cdtype )
+
+
+      ! II. Vertical advective fluxes
+      ! -----------------------------
+      
+      !                                             !-- first guess of the slopes
+      zwx (:,:, 1 ) = 0.e0    ;    zwx (:,:,jpk) = 0.e0    ! surface & bottom boundary conditions
+      DO jk = 2, jpkm1                                     ! interior values
+         zwx(:,:,jk) = tmask(:,:,jk) * ( ptb(:,:,jk-1) - ptb(:,:,jk) )
+      END DO
+
+      !                                             !-- Slopes of tracer
+      zslpx(:,:,1) = 0.e0                                  ! surface values
+      DO jk = 2, jpkm1                                     ! interior value
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zslpx(ji,jj,jk) =                    ( zwx(ji,jj,jk) + zwx(ji,jj,jk+1) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji,jj,jk+1) ) )
+            END DO
+         END DO
+      END DO
+!!gm : merge the above and below loops
+      !                                             !-- Slopes limitation
+      DO jk = 2, jpkm1                                     ! interior values
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN(    ABS( zslpx(ji,jj,jk  ) ),   &
+                  &                                                 2.*ABS( zwx  (ji,jj,jk+1) ),   &
+                  &                                                 2.*ABS( zwx  (ji,jj,jk  ) )  )
+            END DO
+         END DO
+      END DO
+
+      !                                             !-- vertical advective flux
+      !                                                    ! surface values  (bottom already set to zero)
+      IF( lk_dynspg_rl .OR. lk_vvl) THEN    ;   zwx(:,:, 1 ) = 0.e0                      ! rigid lid or variable volume
+      ELSE                                  ;   zwx(:,:, 1 ) = pwn(:,:,1) * ptb(:,:,1)   ! linear free surface
+      ENDIF
+      DO jk = 1, jpkm1                                     ! interior values
+         zdt  = z2 * rdttra(jk)
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z0w = SIGN( 0.5, pwn(ji,jj,jk+1) )
+               zalpha = 0.5 + z0w
+               zw  = z0w - 0.5 * pwn(ji,jj,jk+1) * zdt / (e1t(ji,jj) * e2t(ji,jj) * fse3w(ji,jj,jk+1) )
+               zzwx = ptb(ji,jj,jk+1) + zw * zslpx(ji,jj,jk+1)
+               zzwy = ptb(ji,jj,jk  ) + zw * zslpx(ji,jj,jk  )
+               zwx(ji,jj,jk+1) = pwn(ji,jj,jk+1) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
+            END DO
+         END DO
+      END DO
+
+      !                                             !-- vertical advective trend
+      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) )
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) =  pta(ji,jj,jk) - zbtr * ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) )
+            END DO
+         END DO
+      END DO
+
+      !                                             !-- trend diagnostic
+      IF( l_trdtra )   CALL trd_tra_adv( kt, ktra, jpt_trd_zad, cdtype, zwx, pwn, ptb )
+      !                                             !-- control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' muscl - zad: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_muscl
+
+   !!======================================================================
+END MODULE traadv_muscl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 4536)
@@ -0,0 +1,301 @@
+MODULE traadv_muscl2
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_muscl2  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  1.0  !  2002-06  (G. Madec) from traadv_muscl
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_muscl2 : update the tracer trend with the horizontal
+   !!                    and vertical advection trends using MUSCL2 scheme
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE trabbl          ! tracers: bottom boundary layer
+   USE lib_mpp
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_adv_muscl2        ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_muscl2( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                         ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_adv_muscl2  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to total advection of T and 
+      !!      S using a MUSCL scheme (Monotone Upstream-centered Scheme for
+      !!      Conservation Laws) and add it to the general tracer trend.
+      !!
+      !! ** Method  : MUSCL scheme plus centered scheme at ocean boundaries
+      !!
+      !! ** Action  : - update (ta,sa) with the now advective tracer trends
+      !!              - save trends (lk_trdtra=T)
+      !!
+      !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer fields
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptn             ! now    tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zu, zv, zw
+      REAL(wp) ::   zbtr, zstep, z2 
+      REAL(wp) ::   z0u, z0v, z0w
+      REAL(wp) ::   zzwx, zzwy, zalpha
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zwx, zwy, zslpx, zslpy   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_muscl2 : MUSCL2 advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   z2 = 1.
+      ELSE                                        ;   z2 = 2.
+      ENDIF
+
+      ! I. Horizontal advective fluxes
+      ! ------------------------------
+
+      ! first guess of the slopes
+      DO jk = 1, jpkm1                                       ! interior values
+
+         DO jj = 1, jpjm1      
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zwx(ji,jj,jk) = umask(ji,jj,jk) * ( ptb(ji+1,jj,jk) - ptb(ji,jj,jk) )
+               zwy(ji,jj,jk) = vmask(ji,jj,jk) * ( ptb(ji,jj+1,jk) - ptb(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      zwx(:,:,jpk) = 0.e0    ;    zwy(:,:,jpk) = 0.e0        ! bottom values
+
+!!gm  this lbc_lnk can be omitted
+      ! lateral boundary conditions on zwx, zwy   (changed sign)
+      CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )
+
+      ! Slopes
+      DO jk = 1, jpkm1                                       ! interior values
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               zslpx(ji,jj,jk) =                    ( zwx(ji,jj,jk) + zwx(ji-1,jj  ,jk) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji-1,jj  ,jk) ) )
+               zslpy(ji,jj,jk) =                    ( zwy(ji,jj,jk) + zwy(ji  ,jj-1,jk) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwy(ji,jj,jk) * zwy(ji  ,jj-1,jk) ) )
+            END DO
+         END DO
+      END DO
+      zslpx(:,:,jpk) = 0.e0    ;    zslpy(:,:,jpk) = 0.e0      ! bottom values
+
+      DO jk = 1, jpkm1                                       ! Slopes limitation
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN(    ABS( zslpx(ji  ,jj,jk) ),   &
+                  &                                                 2.*ABS( zwx  (ji-1,jj,jk) ),   &
+                  &                                                 2.*ABS( zwx  (ji  ,jj,jk) ) )
+               zslpy(ji,jj,jk) = SIGN( 1., zslpy(ji,jj,jk) ) * MIN(    ABS( zslpy(ji,jj  ,jk) ),   &
+                  &                                                 2.*ABS( zwy  (ji,jj-1,jk) ),   &
+                  &                                                 2.*ABS( zwy  (ji,jj  ,jk) ) )
+            END DO
+         END DO
+      END DO        
+
+      ! Advection terms
+      DO jk = 1, jpkm1                                        ! interior values
+         zstep  = z2 * rdttra(jk)
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z0u  = SIGN( 0.5, pun(ji,jj,jk) )            
+               zalpha = 0.5 - z0u
+               zu   = z0u - 0.5 * pun(ji,jj,jk) * zstep / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
+               zzwx = ptb(ji+1,jj,jk) + zu * zslpx(ji+1,jj,jk)
+               zzwy = ptb(ji  ,jj,jk) + zu * zslpx(ji  ,jj,jk)
+               zwx(ji,jj,jk) = pun(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
+               !
+               z0v = SIGN( 0.5, pvn(ji,jj,jk) )            
+               zalpha = 0.5 - z0v
+               zv   = z0v - 0.5 * pvn(ji,jj,jk) * zstep / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
+               zzwx = ptb(ji,jj+1,jk) + zv * zslpy(ji,jj+1,jk)
+               zzwy = ptb(ji,jj  ,jk) + zv * zslpy(ji,jj  ,jk)
+               zwy(ji,jj,jk) = pvn(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
+            END DO
+         END DO
+      END DO
+
+      !!!!  centered scheme at lateral b.C. if off-shore velocity
+!!gm bug  :   seems to access jpj+1... jpi+1....
+!!gm bug2 :   centered...  use tn, not ptb !
+      DO jk = 1, jpkm1
+        DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               IF( umask(ji,jj,jk) == 0. ) THEN
+                  IF( pun(ji+1,jj,jk) > 0. .AND. ji /= jpi ) THEN
+                     zwx(ji+1,jj,jk) = pun(ji+1,jj,jk) * ( ptn(ji+1,jj,jk) + ptn(ji+2,jj,jk) ) * 0.5
+                  ENDIF
+                  IF( pun(ji-1,jj,jk) < 0. ) THEN
+                     zwx(ji-1,jj,jk) = pun(ji-1,jj,jk) * ( ptn(ji-1,jj,jk) + ptn(ji  ,jj,jk) ) * 0.5
+                  ENDIF
+               ENDIF
+               IF( vmask(ji,jj,jk) == 0. ) THEN
+                  IF( pvn(ji,jj+1,jk) > 0. .AND. jj /= jpj ) THEN
+                     zwy(ji,jj+1,jk) = pvn(ji,jj+1,jk) * ( ptn(ji,jj+1,jk) + ptn(ji,jj+2,jk) ) * 0.5
+                  ENDIF
+                  IF( pvn(ji,jj-1,jk) < 0. ) THEN
+                     zwy(ji,jj-1,jk) = pvn(ji,jj-1,jk) * ( ptn(ji,jj-1,jk) + ptn(ji  ,jj,jk) ) * 0.5
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary conditions on zwx, zwy   (changed sign)
+      CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )
+
+      ! Compute & add the horizontal advective trend
+
+      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) )
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                  &                                   + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  ) ) 
+            END DO
+        END DO
+      END DO        
+
+      ! Save the horizontal advective trends for diagnostic
+      IF( l_trdtra ) THEN
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, zwx, pun, ptb )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, zwy, pvn, ptb )
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' muscl2 - had: ', mask1=tmask, clinfo3=cdtype )
+
+      ! "Poleward" heat and salt transports
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( lk_zco ) THEN
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                    zwy(ji,jj,jk) = zwy(ji,jj,jk) * fse3v(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         IF( ktra == jp_tem)   pht_adv(:) = ptr_vj( zwy(:,:,:) )
+         IF( ktra == jp_sal)   pst_adv(:) = ptr_vj( zwy(:,:,:) )
+      ENDIF
+
+      ! II. Vertical advective fluxes
+      ! -----------------------------
+      
+      ! First guess of the slope
+      ! interior values
+      DO jk = 2, jpkm1
+         zwx(:,:,jk) = tmask(:,:,jk) * ( ptb(:,:,jk-1) - ptb(:,:,jk) )
+      END DO
+      ! surface & bottom boundary conditions
+      zwx (:,:, 1 ) = 0.e0    ;    zwx (:,:,jpk) = 0.e0
+
+      ! Slopes
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zslpx(ji,jj,jk) =                    ( zwx(ji,jj,jk) + zwx(ji,jj,jk+1) )   &
+                  &            * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji,jj,jk+1) ) )
+            END DO
+         END DO
+      END DO
+
+      ! Slopes limitation
+      DO jk = 2, jpkm1        ! interior values
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN(    ABS( zslpx(ji,jj,jk  ) ),   &
+                  &                                                 2.*ABS( zwx  (ji,jj,jk+1) ),   &
+                  &                                                 2.*ABS( zwx  (ji,jj,jk  ) ) )
+            END DO
+         END DO
+      END DO
+      zslpx(:,:,1) = 0.e0      ! surface values
+
+      ! vertical advective flux
+      DO jk = 1, jpkm1        ! interior values
+         zstep  = z2 * rdttra(jk)
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               z0w = SIGN( 0.5, pwn(ji,jj,jk+1) )
+               zalpha = 0.5 + z0w
+               zw  = z0w - 0.5 * pwn(ji,jj,jk+1)*zstep / ( e1t(ji,jj) *e2t(ji,jj) * fse3w(ji,jj,jk+1) )
+               zzwx = ptb(ji,jj,jk+1) + zw * zslpx(ji,jj,jk+1)
+               zzwy = ptb(ji,jj,jk  ) + zw * zslpx(ji,jj,jk  )
+               zwx(ji,jj,jk+1) = pwn(ji,jj,jk+1) * ( zalpha * zzwx + (1.-zalpha)*zzwy )
+            END DO
+         END DO
+      END DO
+      DO jk = 2, jpkm1        ! centered near the bottom
+        DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               IF( tmask(ji,jj,jk+1) == 0. ) THEN
+                  IF( pwn(ji,jj,jk) > 0. ) THEN
+                     zwx(ji,jj,jk) = pwn(ji,jj,jk) * ( ptn(ji,jj,jk-1) + ptn(ji,jj,jk) ) * 0.5
+                  ENDIF
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      zwx(:,:,jpk) = 0.e0                                       ! bottom value
+      !                                                         ! surface values
+      IF( lk_dynspg_rl .OR. lk_vvl) THEN    ;   zwx(:,:, 1 ) = 0.e0                      ! rigid lid or variable volume
+      ELSE                                  ;   zwx(:,:, 1 ) = pwn(:,:,1) * ptb(:,:,1)   ! linear free surface
+      ENDIF 
+
+
+      ! Compute & add the vertical advective trend
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1      
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1. / fse3t(ji,jj,jk)
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) =  pta(ji,jj,jk) - zbtr * ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) )
+            END DO
+         END DO
+      END DO
+
+      ! Save the vertical advective trends for diagnostic
+      IF( l_trdtra )   CALL trd_tra_adv( kt, ktra, jpt_trd_zad, cdtype, zwx, pwn, ptb )
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' muscl2 - zad: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_muscl2
+
+   !!======================================================================
+END MODULE traadv_muscl2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_qck.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 4536)
@@ -0,0 +1,468 @@
+MODULE traadv_qck
+   !!======================================================================
+   !!                       ***  MODULE  traadv_qck  ***
+   !! Ocean tracers:  horizontal & vertical advective trend using QUICKEST scheme
+   !!======================================================================
+   !! History :  1.0  !  06-09  (G. Reffray)  Original code
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_qck : update the tracer trend with the horizontal advection
+   !!                 trends using a 3rd order finite difference scheme        ?????
+   !!                 The vertical advection scheme is the 2nd centered scheme ?????
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE flxrnf          !
+   USE ocfzpt          !
+   USE lib_mpp
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE diaptr          ! poleward transport diagnostics
+   USE dynspg_oce      ! 
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_adv_qck    ! routine called by traadv.F90
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   sl
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_qck( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                      ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_qck  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method :   The advection is evaluated by a third order scheme
+      !!               For a positive velocity u :
+      !!
+      !!                  i-1    i      i+1   i+2
+      !!
+      !!               |--FU--|--FC--|--FD--|------|
+      !!                           u(i)>0
+      !!
+      !!               For a negative velocity u :
+      !!
+      !!               |------|--FD--|--FC--|--FU--|
+      !!                           u(i)<0
+      !!
+      !!                FU is the second upwind point
+      !!                FD is the first douwning point
+      !!                FC is the central point (or the first upwind point)
+      !!
+      !!      Flux(i) = u(i) * {0.5(FC+FD)  -0.5C(i)(FD-FC)  -((1-C(i)Â?)/6)(FU+FD-2FC)}
+      !!                with C(i)=|u(i)|dx(i)/dt (Courant number)
+      !!
+      !!         dt = 2*rdtra and the scalar values are tb and sb
+      !!
+      !!       On the vertical, the simple centered scheme used tn and sn
+      !!
+      !!               The fluxes are bounded by the ULTIMATE limiter
+      !!               to guarantee the monotonicity of the solution and to
+      !!            prevent the appearance of spurious numerical oscillations
+      !!
+      !! ** Action : - update (ta,sa) with the now advective tracer trends
+      !!             - save the trends in (ttrdh,strdh) ('key_trdtra')
+      !!
+      !! References : Leonard (1979, 1991)
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk        ! dummy loop indices
+      REAL(wp) ::   zdt, z2, zcoef1   ! temporary scalars
+      REAL(wp) ::   zbtr              ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_qck : 3st order quickest advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.      ! euler     time-stepping
+      ELSE                                        ;    z2 = 2.      ! leap-frog time-stepping
+      ENDIF
+
+
+      ! I. Slope estimation at the T-point for the limiter ULTIMATE
+      ! SL = Sum(1/C_out) with C_out : Courant number for the outflows
+      !---------------------------------------------------------------
+
+!!gm : optimisation: sl compute twice (for t & s, and even more for trc)
+!!gm   note that sl is in permanent memory be used as workspace in the vertical part !
+      sl(:,:,:) = 100.
+
+      DO jk = 1, jpkm1
+         zdt  = z2 * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = 2, fs_jpim1   ! vector opt.
+               zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) *fse3t(ji,jj,jk) )
+               zcoef1 = 1.e-12
+               IF( pun(ji-1,jj  ,jk  ) < 0.e0 )   zcoef1 = zcoef1 + ABS( pun(ji-1,jj  ,jk  ) ) * zdt * zbtr
+               IF( pun(ji  ,jj  ,jk  ) > 0.e0 )   zcoef1 = zcoef1 + ABS( pun(ji  ,jj  ,jk  ) ) * zdt * zbtr
+               IF( pvn(ji  ,jj-1,jk  ) < 0.e0 )   zcoef1 = zcoef1 + ABS( pvn(ji  ,jj-1,jk  ) ) * zdt * zbtr
+               IF( pvn(ji  ,jj  ,jk  ) > 0.e0 )   zcoef1 = zcoef1 + ABS( pvn(ji  ,jj  ,jk  ) ) * zdt * zbtr
+               IF( pwn(ji  ,jj  ,jk+1) < 0.e0 )   zcoef1 = zcoef1 + ABS( pwn(ji  ,jj  ,jk+1) ) * zdt * zbtr
+               IF( pwn(ji  ,jj  ,jk  ) > 0.e0 )   zcoef1 = zcoef1 + ABS( pwn(ji  ,jj  ,jk  ) ) * zdt * zbtr
+               sl(ji,jj,jk) = 1. / zcoef1
+               sl(ji,jj,jk) = MIN( 100., sl(ji,jj,jk) )
+               sl(ji,jj,jk) = MAX( 1.  , sl(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( sl(:,:,:), 'T', 1. )      ! Lateral boundary conditions on the limiter slope
+
+
+      ! II. The horizontal fluxes are computed with the QUICKEST + ULTIMATE scheme
+      !---------------------------------------------------------------------------
+
+      CALL tra_adv_qck_hor( kt, cdtype, ktra, pun, pvn, ptb, pta, z2 )
+
+      !                                       ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' qck - had: ', mask1=tmask, clinfo3=cdtype )
+
+
+      ! III. The vertical fluxes are computed with the 2nd order centered scheme
+      !-------------------------------------------------------------------------
+
+      CALL tra_adv_qck_ver( pwn, ptn , pta )
+
+      !                                       ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' qck - zad: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_qck
+
+
+   SUBROUTINE tra_adv_qck_hor ( kt, cdtype, ktra, pun, pvn, ptb, pta, pz2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_qck_hor  ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt          ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype      ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra        ! tracer index
+      REAL(wp)        , INTENT(in   )                         ::   pz2         ! =1 or 2 (euler or leap-frog)
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn    ! horizontal effective velocity
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb         ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta         ! tracer trend
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zdt                                     ! temporary scalars
+      REAL(wp) ::   zbtr, zc, zdir, zfu, zfc, zfd           ! temporary scalars
+      REAL(wp) ::   zcoef1, zcoef2, zcoef3, zfho, zmsk, zdx
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask, zlap, zdwst, zlim 
+      !!----------------------------------------------------------------------
+
+      !----------------------------------------------------------------------
+      ! 0. Initialization (should ot be needed on the whole array ???)
+      !----------------------------------------------------------------------
+      zmask(:,:,:)= 0.e0                                                
+      zlap (:,:,:)= 0.e0                                                  
+      zdwst(:,:,:)= 0.e0                                                  
+      zlim (:,:,:)= 0.e0     
+                                            
+      !----------------------------------------------------------------------
+      ! I. Part 1 : x-direction
+      !----------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+
+         ! Laplacian of tracers (at before time step)
+         ! ------------------------------------------
+         !--- First derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zmask(ji,jj,jk) = e2u(ji,jj) * fse3u(ji,jj,jk) * umask(ji,jj,jk)                    &
+                  &                         * ( ptb(ji+1,jj  ,jk) - ptb(ji,jj,jk) ) / e1u(ji,jj)
+            END DO
+         END DO
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlap(ji,jj,jk) = e1t(ji,jj) * (  zmask(ji,jj,jk) - zmask(ji-1,jj,jk)  )   &
+                  &                        / ( e2t(ji,jj) * fse3t(ji,jj,jk) )
+            END DO
+         END DO
+         !--- Function lim=FU+SL*(FC-FU) used by the limiter
+         !--- Computation of the ustream and downstream lim at the T-points
+!!gm bug : fs_2  instead of 2 ...
+!!gm  a lot of optimisation to be done in this routine....
+         DO jj = 2, jpjm1
+            DO ji = 2, fs_jpim1   ! vector opt.
+               ! Upstream in the x-direction for the tracer
+               zmask(ji,jj,jk) = ptb(ji-1,jj,jk) + sl(ji,jj,jk) *( ptb(ji,jj,jk) - ptb(ji-1,jj,jk) )
+               ! Downstream in the x-direction for the tracer
+               zdwst(ji,jj,jk) = ptb(ji+1,jj,jk) + sl(ji,jj,jk) * ( ptb(ji,jj,jk) - ptb(ji+1,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      !--- Lateral boundary conditions on the laplacian and lim functions (unchanged sgn)
+      CALL lbc_lnk( zlap (:,:,:), 'T', 1. ) 
+      CALL lbc_lnk( zmask(:,:,:), 'T', 1. )   ;   CALL lbc_lnk(  zdwst(:,:,:), 'T', 1. )
+            
+      ! --- lim at the U-points in function of the direction of the flow
+      ! ----------------------------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zdir = 0.5 + SIGN( 0.5, pun(ji,jj,jk) )     ! if pun>0 : diru = 1 otherwise diru = 0
+               zlim(ji,jj,jk) = zdir * zmask(ji,jj,jk) + (1-zdir) * zdwst(ji+1,jj,jk)
+               ! Mask at the T-points in the x-direction (mask=0 or mask=1)
+               zmask(ji,jj,jk) = tmask(ji-1,jj,jk) + tmask(ji,jj,jk) + tmask(ji+1,jj,jk) - 2
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk(  zmask(:,:,:), 'T', 1. )       !--- Lateral boundary conditions for the mask
+
+
+      ! Horizontal advective fluxes
+      ! ---------------------------
+      DO jk = 1, jpkm1
+         zdt  = pz2 * rdttra(jk)
+         !--- tracer flux at u and v-points
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt. 
+               zdir = 0.5 + SIGN( 0.5, pun(ji,jj,jk) )                     ! if pun>0 : diru = 1 otherwise diru = 0
+               zdx  = ( zdir * e1t(ji,jj) + (1-zdir)* e1t(ji+1,jj) ) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               zc   = ABS( pun(ji,jj,jk) ) * zdt / zdx                     ! (0<cx<1 : Courant number on x-direction)
+
+               zfu  = zlim(ji,jj,jk)                                       ! FU + sl(FC-FU) in the x-direction for T
+               zfc  = zdir * ptb(ji  ,jj,jk) + (1-zdir) * ptb(ji+1,jj,jk)  ! FC in the x-direction for T
+               zfd  = zdir * ptb(ji+1,jj,jk) + (1-zdir) * ptb(ji  ,jj,jk)  ! FD in the x-direction for T
+
+               !--- QUICKEST scheme
+               ! Temperature on the x-direction
+               zcoef1 = 0.5      * ( zfc + zfd )
+               zcoef2 = 0.5 * zc * ( zfd - zfc )
+               zcoef3 = ( (1.-(zc*zc)) / 6. ) * ( zdir * zlap(ji,jj,jk) + (1-zdir) * zlap(ji+1,jj,jk) )
+               zfho = zcoef1 - zcoef2 - zcoef3
+               zfho = bound( zfu, zfd, zfc, zfho )
+               !--- If the second ustream point is a land point
+               !--- the flux is computed by the 1st order UPWIND scheme
+               zmsk = zdir * zmask(ji,jj,jk) + (1-zdir) * zmask(ji+1,jj,jk)
+               zfho = zmsk * zfho            + (1-zmsk) * zfc
+               zdwst(ji,jj,jk) = pun(ji,jj,jk) * zfho
+            END DO
+         END DO
+
+         !--- Tracer flux divergence at t-point added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               !--- horizontal advective trends
+               zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               !--- add it to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - zbtr * ( zdwst(ji,jj,jk) - zdwst(ji-1,jj  ,jk) )
+            END DO
+         END DO
+      END DO
+
+      !                                            !-- trend diagnostic
+      IF( l_trdtra )   CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, zdwst, pun, ptb )
+
+
+      !----------------------------------------------------------------------
+      ! I. Part 2 : y-direction
+      !----------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+
+         ! Laplacian of tracers (at before time step)
+         ! ------------------------------------------
+         !--- First derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zmask(ji,jj,jk) = e1v(ji,jj) * fse3v(ji,jj,jk)   &
+                  &            * ( ptb(ji  ,jj+1,jk) - ptb(ji,jj,jk) ) / e2v(ji,jj) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !--- Second derivative (divergence)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlap(ji,jj,jk) = e2t(ji,jj) * (  zmask(ji,jj,jk) - zmask(ji,jj-1,jk)  )   &
+                  &                        / ( e1t(ji,jj) * fse3t(ji,jj,jk) )
+            END DO
+         END DO
+         !--- Function lim=FU+SL*(FC-FU) used by the limiter
+         !--- Computation of the ustream and downstream lim at the T-points
+         DO jj = 2, jpjm1
+            DO ji = 2, fs_jpim1   ! vector opt.
+               ! Upstream in the y-direction for the tracer
+               zmask(ji,jj,jk) = ptb(ji,jj-1,jk) + sl(ji,jj,jk) *( ptb(ji,jj,jk) - ptb(ji,jj-1,jk) )
+               ! Downstream in the y-direction for the tracer
+               zdwst(ji,jj,jk) = ptb(ji,jj+1,jk) + sl(ji,jj,jk) *( ptb(ji,jj,jk) - ptb(ji,jj+1,jk) )
+            ENDDO
+         ENDDO
+      END DO
+      !--- Lateral boundary conditions on the laplacian and lim function (unchanged sgn)
+      CALL lbc_lnk( zlap (:,:,:), 'T', 1. )
+      CALL lbc_lnk( zmask(:,:,:), 'T', 1. )   ;   CALL lbc_lnk( zdwst(:,:,:), 'T', 1. )
+
+      DO jk = 1, jpkm1
+      
+         ! --- lim at the V-points in function of the direction of the flow
+         ! ----------------------------------------------------------------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zdir = 0.5 + SIGN( 0.5, pvn(ji,jj,jk) )      ! if pvn>0 : dirv = 1 otherwise dirv = 0
+               zlim(ji,jj,jk) = zdir * zmask(ji,jj,jk) + (1-zdir) * zdwst(ji,jj+1,jk)
+               ! Mask at the T-points in the y-direction (mask=0 or mask=1)
+               zmask(ji,jj,jk) = tmask(ji,jj-1,jk) + tmask(ji,jj,jk) + tmask(ji,jj+1,jk) - 2.
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk(  zmask(:,:,:), 'T', 1. )      !--- Lateral boundary conditions for the mask
+
+      ! Horizontal advective fluxes
+      ! ---------------------------
+                                  
+      DO jk = 1, jpkm1           
+         zdt  = pz2 * rdttra(jk)
+         !--- tracer flux at u and v-points
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zdir = 0.5 + SIGN( 0.5, pvn(ji,jj,jk) )                     ! if pvn>0 : dirv = 1 otherwise dirv = 0
+               zdx  = ( zdir * e2t(ji,jj) + (1-zdir)* e2t(ji,jj+1) ) * e1v(ji,jj) * fse3v(ji,jj,jk)
+               zc   = ABS( pvn(ji,jj,jk) ) * zdt / zdx                     ! (0<cy<1 : Courant number on y-direction)
+
+               zfu  = zlim(ji,jj,jk)                                       ! FU + sl(FC-FU) in the y-direction for T
+               zfc  = zdir * ptb(ji,jj  ,jk) + (1-zdir) * ptb(ji,jj+1,jk)  ! FC in the y-direction for T
+               zfd  = zdir * ptb(ji,jj+1,jk) + (1-zdir) * ptb(ji,jj  ,jk)  ! FD in the y-direction for T
+
+               !--- QUICKEST scheme
+               ! Temperature on the y-direction
+               zcoef1 = 0.5      * ( zfc + zfd )
+               zcoef2 = 0.5 * zc * ( zfd - zfc )
+               zcoef3 = ( (1.-(zc*zc)) / 6. ) * ( zdir * zlap(ji,jj,jk) + (1-zdir) * zlap(ji,jj+1,jk) )
+               zfho = zcoef1 - zcoef2 - zcoef3
+               zfho = bound( zfu, zfd, zfc, zfho )
+               !--- If the second ustream point is a land point
+               !--- the flux is computed by the 1st order UPWIND scheme
+               zmsk = zdir * zmask(ji,jj,jk) + (1-zdir) * zmask(ji,jj+1,jk)
+               zfho = zmsk * zfho            + (1-zmsk) * zfc
+               zdwst(ji,jj,jk) = pvn(ji,jj,jk) * zfho
+            END DO
+         END DO
+
+         !--- Tracer flux divergence at t-point added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - zbtr * (  zdwst(ji,jj,jk) - zdwst(ji,jj-1,jk) )
+            END DO
+         END DO
+      END DO 
+
+      !                                           !-- trend diagnostic
+      IF( l_trdtra )   CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, zdwst, pvn, ptb )
+      !                                           ! "Poleward" heat or salt transport 
+      IF( ln_diaptr .AND. cdtype == 'TRA' .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_adv(:) = ptr_vj( zdwst(:,:,:) )
+         IF( ktra == jp_sal)   pst_adv(:) = ptr_vj( zdwst(:,:,:) )
+      ENDIF
+      !
+   END SUBROUTINE tra_adv_qck_hor
+
+
+   SUBROUTINE tra_adv_qck_ver( pwn, ptn , pta )      
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_qck_ver  ***
+      !!
+      !! ** Purpose :   
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pwn   ! vertical transport
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptn   ! now tracer
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta   ! tracer trend
+      !!
+      INTEGER  ::   ji, jj , jk                  ! dummy loop indices
+      REAL(wp) ::   zbtr, zdir, zfc, zfd   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      ! Vertical advection
+      ! ------------------
+
+      ! 1. Vertical advective fluxes
+      ! ----------------------------
+
+      sl(:,:,jpk) = 0.e0                          ! bottom value 
+
+      !                                           ! Surface value
+      IF( lk_dynspg_rl .OR. lk_vvl ) THEN   ;   sl(:,:, 1 ) = 0.e0                      ! rigid lid or non-linear fs
+      ELSE                                  ;   sl(:,:, 1 ) = pwn(:,:,1) * ptn(:,:,1)   ! linear free surface
+      ENDIF
+
+!!gm  bug: code au true 2nd order scheme
+!!gm  : sl used as work array: not good idea for optimisation (sl compute once for all tracers...)
+
+      ! Second order centered tracer flux at w-point
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zdir = 0.5 + SIGN( 0.5, pwn(ji,jj,jk) )                        ! if pwn>0 : dirw = 1 otherwise dirw = 0
+               zfc = zdir * ptn(ji,jj,jk  ) * fse3t(ji,jj,jk-1) + (1-zdir) * ptn(ji,jj,jk-1) * fse3t(ji,jj,jk  )   ! FC 
+               zfd = zdir * ptn(ji,jj,jk-1) * fse3t(ji,jj,jk  ) + (1-zdir) * ptn(ji,jj,jk  ) * fse3t(ji,jj,jk-1)   ! FD
+               !--- Second order centered scheme
+               sl(ji,jj,jk) = pwn(ji,jj,jk) * ( zfc + zfd ) / ( fse3t(ji,jj,jk-1) + fse3t(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! 2. Tracer flux divergence at t-point added to the general trend
+      ! ---------------------------------------------------------------
+      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) )
+               ! vertical advective trends added to the general tracer trends
+               pta(ji,jj,jk) =  pta(ji,jj,jk) - zbtr * ( sl(ji,jj,jk) - sl(ji,jj,jk+1) )
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_adv_qck_ver
+
+
+   FUNCTION bound( pfu, pfd, pfc, pfho )   RESULT( pbound )
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION bound  ***
+      !!
+      !! ** Purpose :   ???
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in) ::  pfu, pfd, pfc, pfho
+      REAL(wp)             ::  pbound
+      !!
+      REAL(wp) ::  zfref1, zfref2
+      !!----------------------------------------------------------------------
+      zfref1 = pfu
+      zfref2 = MAX(  MIN( pfc , pfd ), MIN( MAX( pfc , pfd ), zfref1 )  )
+      pbound = MAX(  MIN( pfho, pfc ), MIN( MAX( pfho, pfc ), zfref2 )  )
+      !
+   END FUNCTION
+
+   !!======================================================================
+END MODULE traadv_qck
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_tvd.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 4536)
@@ -0,0 +1,362 @@
+MODULE traadv_tvd
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_tvd  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  7.0  !  1995-12  (L. Mortier)  Original code
+   !!            8.0  !  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
+   !!             -   !  2008-04  (S. Cravatte) add the i-, j- & k- trends computation
+   !!             -   !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_tvd  : update the tracer trend with the horizontal and
+   !!                  vertical advection trends using a TVD scheme
+   !!   nonosc       : compute monotonic tracer fluxes by a nonoscillatory algorithm
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE trabbl          ! Advective term of BBL
+   USE lib_mpp         !
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_tvd    ! routine called by traadv.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_tvd( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                      ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  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 in (ztrdt,ztrds) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   z2dtt, zbtr, z2, zzti    ! temporary scalar
+      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !    "         "
+      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !    "         "
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zti, ztu, ztv, ztw   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      zti(:,:,:) = 0.e0 
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_tvd : TVD advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.      ! euler   time-stepping
+      ELSE                                        ;    z2 = 2.      ! leap-frog time-stepping
+      ENDIF
+
+      ! 1. Bottom value : flux set to zero
+      ! ---------------
+      ztu(:,:,jpk) = 0.e0   ;   ztv(:,:,jpk) = 0.e0
+      ztw(:,:,jpk) = 0.e0   ;   zti(:,:,jpk) = 0.e0
+
+
+      ! 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.
+               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) )
+               ztu(ji,jj,jk) = 0.5 * ( zfp_ui * ptb(ji,jj,jk) + zfm_ui * ptb(ji+1,jj  ,jk) )
+               ztv(ji,jj,jk) = 0.5 * ( zfp_vj * ptb(ji,jj,jk) + zfm_vj * ptb(ji  ,jj+1,jk) )
+            END DO
+         END DO
+      END DO
+      !
+      ! upstream tracer flux in the k direction
+      !                                                                           ! Surface value
+      IF( lk_dynspg_rl .OR. lk_vvl ) THEN   ;   ztw(:,:,1) = 0.e0                      ! rigid lid or non-linear fs
+      ELSE                                  ;   ztw(:,:,1) = pwn(:,:,1) * ptb(:,:,1)   ! free surface
+      ENDIF
+      !
+      DO jk = 2, jpkm1                                                            ! Interior value
+         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) )
+               ztw(ji,jj,jk) = 0.5 * ( zfp_wk * ptb(ji,jj,jk) + zfm_wk * ptb(ji,jj,jk-1) )
+            END DO
+         END DO
+      END DO
+      !
+      ! upstream advective trend
+      DO jk = 1, jpkm1
+         z2dtt = z2 * rdttra(jk)
+         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 intermediate advective trends
+               zzti = - ( ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk  )            &
+                  &     + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  )            &
+                  &     + ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1) ) * zbtr
+               ! update and guess with monotonic sheme
+               pta(ji,jj,jk) =   pta(ji,jj,jk) +         zzti
+               zti(ji,jj,jk) = ( ptb(ji,jj,jk) + z2dtt * zzti ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      CALL lbc_lnk( zti, 'T', 1. )      ! Lateral boundary conditions on zti   (unchanged sign)
+
+
+      !                                 ! trend diagnostics (contribution of upstream fluxes)
+      IF( l_trdtra ) THEN
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, ztu, pun, ptn )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, ztv, pvn, ptn )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_zad, cdtype, ztw, pwn, ptn )
+      ENDIF
+      !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_adv(:) = ptr_vj( ztv(:,:,:) ) 
+         IF( ktra == jp_sal)   pst_adv(:) = ptr_vj( ztv(:,:,:) )
+      ENDIF
+
+
+      ! 3. antidiffusive flux : high order minus low order
+      ! --------------------------------------------------
+      !                                 ! anti-diffusive flux on i and j
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztu(ji,jj,jk) = 0.5 * pun(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji+1,jj,jk) ) - ztu(ji,jj,jk)
+               ztv(ji,jj,jk) = 0.5 * pvn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji,jj+1,jk) ) - ztv(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !                                 ! antidiffusive flux on k
+      ztw(:,:,1) = 0.e0                      ! Surface value
+      !
+      DO jk = 2, jpkm1                       ! Interior value
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztw(ji,jj,jk) = 0.5 * pwn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji,jj,jk-1) ) - ztw(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      CALL lbc_lnk( ztu, 'U', -1. )     ! Lateral bondary conditions on upstream fluxes
+      CALL lbc_lnk( ztv, 'V', -1. )
+      CALL lbc_lnk( ztw, 'W',  1. )
+
+      !                                 ! monotonicity algorithm
+      CALL nonosc( ptb, ztu, ztv, ztw, zti, z2 )
+
+
+      ! 4. final trend with anti-diffusive 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) )
+               ! anti-diffusive trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - ( ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk  )             &
+                  &                            + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  )             &
+                  &                            + ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1)  ) * zbtr
+            END DO
+         END DO
+      END DO
+
+      IF( l_trdtra ) THEN               ! trend diagnostic (contribution of anti-diffusive fluxes)
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, ztu, pun, ptn, cnbpas='bis' )   ! <<< Add to iad trend
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, ztv, pvn, ptn, cnbpas='bis' )   ! <<< Add to jad trend
+         CALL trd_tra_adv( kt, ktra, jpt_trd_zad, cdtype, ztw, pwn, ptn, cnbpas='bis' )   ! <<< Add to zad trend
+      ENDIF
+      !                                 ! "Poleward" heat and salt transports (contribution of anti-diffusive fluxes)
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_adv(:) = pht_adv(:) + ptr_vj( ztv(:,:,:) )
+         IF( ktra == jp_sal)   pst_adv(:) = pst_adv(:) + ptr_vj( ztv(:,:,:) )
+      ENDIF
+      !                                 ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' tvd - adv: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_tvd
+
+
+   SUBROUTINE nonosc( pbef, paa, pbb, pcc, paft, prdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  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), INTENT(in   ) ::   prdt                               ! ???
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   pbef, paft       ! before & after field
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   paa, pbb, pcc    ! monotonic flux in the 3 directions
+      !!
+      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      INTEGER ::   ikm1
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zbetup, zbetdo
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt
+      !!----------------------------------------------------------------------
+
+      zbig = 1.e+40
+      zrtrn = 1.e-15
+      zbetup(:,:,:) = 0.e0   ;   zbetdo(:,:,:) = 0.e0  
+
+!!gm   optimisation :  add the optimal version I wrote 1 year ago
+      ! Search local extrema
+      ! --------------------
+      ! large negative value (-zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search maximum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetup(ji,jj,jk) = MAX(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji-1,jj  ,jk  ), pbef(ji+1,jj  ,jk  ),   &
+                  &                     paft(ji-1,jj  ,jk  ), paft(ji+1,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj-1,jk  ), pbef(ji  ,jj+1,jk  ),   &
+                  &                     paft(ji  ,jj-1,jk  ), paft(ji  ,jj+1,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+      ! large positive value (+zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search minimum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetdo(ji,jj,jk) = MIN(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji-1,jj  ,jk  ), pbef(ji+1,jj  ,jk  ),   &
+                  &                     paft(ji-1,jj  ,jk  ), paft(ji+1,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj-1,jk  ), pbef(ji  ,jj+1,jk  ),   &
+                  &                     paft(ji  ,jj-1,jk  ), paft(ji  ,jj+1,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+
+      ! restore masked values to zero
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:)
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:)
+ 
+
+      ! 2. Positive and negative part of fluxes and beta terms
+      ! ------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         z2dtt = prdt * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! positive & negative 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  ) )
+               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) = ( zbetup(ji,jj,jk) - paft(ji,jj,jk) ) / (zpos+zrtrn) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zbetdo(ji,jj,jk) ) / (zneg+zrtrn) * zbt
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on zbetup & zbetdo   (unchanged sign)
+      CALL lbc_lnk( zbetup, 'T', 1. )
+      CALL lbc_lnk( zbetdo, 'T', 1. )
+
+
+      ! 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.
+               za = MIN( 1.e0, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
+               zb = MIN( 1.e0, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
+               zc = 0.5 * ( 1.e0 + SIGN( 1.e0, paa(ji,jj,jk) ) )
+               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zc * za + ( 1.e0 - zc) * zb )
+
+               za = MIN( 1.e0, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
+               zb = MIN( 1.e0, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
+               zc = 0.5 * ( 1.e0 + SIGN( 1.e0, pbb(ji,jj,jk) ) )
+               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zc * za + ( 1.e0 - zc) * zb )
+            END DO
+         END DO
+      END DO
+
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji,jj,jk-1) )
+               zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji,jj,jk-1) )
+               zc = 0.5 * ( 1.e0 + SIGN( 1.e0, pcc(ji,jj,jk) ) )
+               pcc(ji,jj,jk) = pcc(ji,jj,jk) * ( zc * za + ( 1.e0 - zc) * zb )
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on paa, pbb, pcc
+      CALL lbc_lnk( paa, 'U', -1. )      ! changed sign
+      CALL lbc_lnk( pbb, 'V', -1. )      ! changed sign
+      CALL lbc_lnk( pcc, 'W',  1. )      ! NO changed sign
+      !
+   END SUBROUTINE nonosc
+
+   !!======================================================================
+END MODULE traadv_tvd
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 4536)
@@ -0,0 +1,391 @@
+MODULE traadv_ubs
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_ubs  ***
+   !! Ocean tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  1.0  !  2006-08  (L. Debreu, R. Benshila)  Original code
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_ubs : update the tracer trend with the horizontal
+   !!                 advection trends using a third order biaised scheme  
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod
+   USE trdmod_oce
+   USE lib_mpp
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+   USE in_out_manager  ! I/O manager
+   USE diaptr          ! poleward transport diagnostics
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE prtctl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_ubs   ! routine called by traadv module
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA & TRP 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_ubs( kt, cdtype, ktra, pun, pvn, pwn,   &
+      &                                      ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ubs  ***
+      !!                 
+      !! ** Purpose :   Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method  :   The upstream biased third (UBS) is order scheme based 
+      !!      on an upstream-biased parabolic interpolation (Shchepetkin and McWilliams 2005)
+      !!      It is only used in the horizontal direction.
+      !!      For example the i-component of the advective fluxes are given by :
+      !!                !  e1u e3u un ( mi(Tn) - zltu(i  ) )   if un(i) >= 0
+      !!          zwx = !  or 
+      !!                !  e1u e3u un ( mi(Tn) - zltu(i+1) )   if un(i) < 0
+      !!      where zltu is the second derivative of the before temperature field:
+      !!          zltu = 1/e3t di[ e2u e3u / e1u di[Tb] ]
+      !!      This results in a dissipatively dominant (i.e. hyper-diffusive) 
+      !!      truncation error. The overall performance of the advection scheme 
+      !!      is similar to that reported in (Farrow and Stevens, 1995). 
+      !!      For stability reasons, the first term of the fluxes which corresponds
+      !!      to a second order centered scheme is evaluated using the now velocity 
+      !!      (centered in time) while the second term which is the diffusive part 
+      !!      of the scheme, is evaluated using the before velocity (forward in time). 
+      !!      Note that UBS is not positive. Do not use it on passive tracers.
+      !!      On the vertical, the advection is evaluated using a TVD scheme, as
+      !!      the UBS have been found to be too diffusive.
+      !!
+      !! ** Action : - update (ta,sa) with the now advective tracer trends
+      !!
+      !! Reference : Shchepetkin, A. F., J. C. McWilliams, 2005, Ocean Modelling, 9, 347-404. 
+      !!             Farrow, D.E., Stevens, D.P., 1995, J. Phys. Ocean. 25, 1731-1741. 
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk                     ! dummy loop indices
+      REAL(wp) ::   zbtr, zcoef, z_hdivn           ! temporary scalars
+      REAL(wp) ::   zeeu, zfp_ui, zfm_ui, zcenut   !    "         "
+      REAL(wp) ::   zeev, zfp_vj, zfm_vj, zcenvt   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, ztu, zltu   ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwy, ztv, zltv   !    "              "
+      !!----------------------------------------------------------------------
+
+!!gm  this can be optimized: we don't need zero everywhere
+      zltu(:,:,:) = 0.e0
+      zltv(:,:,:) = 0.e0
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_ubs :  horizontal UBS advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      !  Laplacian
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1                               ! First derivative (gradient)
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zeeu = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+               zeev = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+               ztu(ji,jj,jk) = zeeu * ( ptb(ji+1,jj  ,jk) - ptb(ji,jj,jk) )
+               ztv(ji,jj,jk) = zeev * ( ptb(ji  ,jj+1,jk) - ptb(ji,jj,jk) )
+            END DO
+         END DO
+         DO jj = 2, jpjm1                               ! Second derivative (divergence)
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef = 1. / ( 6. * fse3t(ji,jj,jk) )
+               zltu(ji,jj,jk) = (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)  ) * zcoef
+               zltv(ji,jj,jk) = (  ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  ) * zcoef
+            END DO
+         END DO
+      END DO
+
+      ! Lateral boundary conditions on the laplacian (zlt,zls)   (unchanged sgn)
+      CALL lbc_lnk( zltu, 'T', 1. )   ;    CALL lbc_lnk( zltv, 'T', 1. )
+
+
+      !  Horizontal advective fluxes
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! upstream transport
+               zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )      ! = 2.pun  if pun>0,  =0      if pun<0
+               zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )      ! = 0      if pun>0,  = 2.pun if pun<0
+               zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )      ! idem on pvn
+               zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )      !
+               ! centered scheme
+               zcenut = pun(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji+1,jj  ,jk) )
+               zcenvt = pvn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji  ,jj+1,jk) )
+               ! UBS scheme
+               zwx(ji,jj,jk) = 0.5 * (  zcenut - zfp_ui * zltu(ji,jj,jk) -zfm_ui * zltu(ji+1,jj,jk)  )
+               zwy(ji,jj,jk) = 0.5 * (  zcenvt - zfp_vj * zltv(ji,jj,jk) -zfm_vj * zltv(ji,jj+1,jk)  )
+            END DO
+         END DO
+      END DO
+
+      zltu(:,:,:) = pta(:,:,:)      ! store pta trends
+
+      ! Horizontal advective trends
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ! horizontal advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
+                  &                                    + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
+            END DO
+         END DO
+      END DO
+
+      zltu(:,:,:) = pta(:,:,:) - zltu(:,:,:)    ! store the Horizontal advective trend (used in tra_adv_ztvd subroutine)
+
+ 
+      IF( l_trdtra ) THEN                       ! trend diagnostics (from advective fluxes)
+         CALL trd_tra_adv( kt, ktra, jpt_trd_xad, cdtype, zwx, pun, ptn )
+         CALL trd_tra_adv( kt, ktra, jpt_trd_yad, cdtype, zwy, pvn, ptn )
+      ENDIF
+      !                                         ! "Poleward" heat or salt transports
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem )   pht_adv(:) = ptr_vj( zwy(:,:,:) )
+         IF( ktra == jp_sal )   pst_adv(:) = ptr_vj( zwy(:,:,:) )
+      ENDIF
+      !                                         ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' ubs - had: ', mask1=tmask, clinfo3=cdtype )
+
+
+      ! II. Vertical advection
+      ! ----------------------
+      IF( l_trdtra )   zltv(:,:,:) = pta(:,:,:)          ! store pta if trend diag.
+    
+      ! TVD scheme the vertical direction  
+      CALL tra_adv_ztvd( kt, pwn, zltu, ptb, ptn, pta )
+
+      IF( l_trdtra )   THEN                     ! vertical advective trend diagnostics
+         DO jk = 1, jpkm1                       ! (compute -w.dk[ptn]= -dk[w.ptn] + ptn.dk[w])
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr = 1.e0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn = (  pwn(ji,jj,jk) - pwn(ji,jj,jk+1)  ) * zbtr
+                  zltv(ji,jj,jk) = pta(ji,jj,jk) - zltv(ji,jj,jk+1)  +  ptn(ji,jj,jk) * z_hdivn 
+               END DO
+            END DO
+         END DO
+         CALL trd_tra( kt, ktra, jpt_trd_zad, cdtype, ptrd3d=zltv )
+      ENDIF
+      !                                         ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' ubs - zad: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_adv_ubs
+
+
+   SUBROUTINE tra_adv_ztvd( kt, pwn, phtrd, ptb, ptn, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ztvd  ***
+      !! 
+      !! **  Purpose :   Compute the vertical advective trend of a tracer
+      !!               and add it to its general trend 
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!
+      !! ** Action : - update pta with the vertical advective trend
+      !!             - trend diagnostic (lk_trdtra=T)
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt         ! ocean time-step
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pwn        ! verical effective velocity
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   phtrd      ! lateral advective trends on T & S 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   ptb, ptn   ! before and now tracer fields
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta        ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      REAL(wp) ::   z2dtt, zbtr, z2         ! temporary scalar  
+      REAL(wp) ::   ztak, zfp_wk, zfm_wk    !    "         "
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zti, ztw   ! temporary 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_ztvd : vertical TVD advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.
+      ELSE                                        ;    z2 = 2.
+      ENDIF
+
+
+      !  upstream advection with initial mass fluxes & intermediate update
+      ztw(:,:,jpk) = 0.e0                                   ! Bottom  value : flux set to zero
+      zti(:,:,jpk) = 0.e0
+      !                                                     ! Surface value : 
+      IF( lk_dynspg_rl .OR. lk_vvl ) THEN   ;   ztw(:,:, 1 ) = 0.e0                      ! rigid lid or non-linear fs
+      ELSE                                  ;   ztw(:,:, 1 ) = pwn(:,:,1) * ptb(:,:,1)   ! linear free surface 
+      ENDIF
+      !
+      DO jk = 2, jpkm1                                      ! interior values
+         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) )
+               ztw(ji,jj,jk) = 0.5 * (  zfp_wk * ptb(ji,jj,jk) + zfm_wk * ptb(ji,jj,jk-1)  )
+            END DO
+         END DO
+      END DO
+
+      ! update and guess with monotonic sheme
+      DO jk = 1, jpkm1
+         z2dtt = z2 * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1./ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ztak = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr
+               pta(ji,jj,jk) =   pta(ji,jj,jk) +           ztak
+               zti(ji,jj,jk) = ( ptb(ji,jj,jk) + z2dtt * ( ztak + phtrd(ji,jj,jk) ) ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      CALL lbc_lnk( zti, 'T', 1. )      ! Lateral boundary conditions on zti, zsi   (unchanged sign)
+
+
+      !  antidiffusive flux : high order minus low order
+      ztw(:,:,1) = 0.e0       ! Surface value
+      DO jk = 2, jpkm1        ! Interior value
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztw(ji,jj,jk) = 0.5 * pwn(ji,jj,jk) * ( ptn(ji,jj,jk) + ptn(ji,jj,jk-1) ) - ztw(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      CALL nonosc_z( ptb, ztw, zti, z2 )      !  monotonicity algorithm
+
+
+      !  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) )
+               ! k- vertical advective trends added to the general tracer trends
+               pta(ji,jj,jk) = pta(ji,jj,jk) - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_adv_ztvd
+
+
+   SUBROUTINE nonosc_z( pbef, pcc, paft, prdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc_z  ***
+      !!     
+      !! **  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), INTENT(in   )                          ::   prdt   ! ???
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   pbef   ! before field
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   paft   ! after field
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   pcc    ! monotonic flux in the k direction
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      INTEGER  ::   ikm1
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zbetup, zbetdo
+      !!----------------------------------------------------------------------
+
+      zbig = 1.e+40
+      zrtrn = 1.e-15
+      zbetup(:,:,:) = 0.e0   ;   zbetdo(:,:,:) = 0.e0
+
+      ! Search local extrema
+      ! --------------------
+      ! large negative value (-zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search maximum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetup(ji,jj,jk) = MAX(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+      ! large positive value (+zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search minimum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetdo(ji,jj,jk) = MIN(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+
+      ! restore masked values to zero
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:)
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:)
+ 
+
+      ! 2. Positive and negative part of fluxes and beta terms
+      ! ------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         z2dtt = prdt * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! positive & negative part of the flux
+               zpos = MAX( 0., pcc(ji  ,jj  ,jk+1) ) - MIN( 0., pcc(ji  ,jj  ,jk  ) )
+               zneg = 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) = ( zbetup(ji,jj,jk) - paft(ji,jj,jk) ) / (zpos+zrtrn) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zbetdo(ji,jj,jk) ) / (zneg+zrtrn) * zbt
+            END DO
+         END DO
+      END DO
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji,jj,jk-1) )
+               zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji,jj,jk-1) )
+               zc = 0.5 * ( 1.e0 + SIGN( 1.e0, pcc(ji,jj,jk) ) )
+               pcc(ji,jj,jk) = pcc(ji,jj,jk) * ( zc * za + ( 1.e0 - zc) * zb )
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE nonosc_z
+
+   !!======================================================================
+END MODULE traadv_ubs
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 4536)
@@ -0,0 +1,197 @@
+MODULE trabbc
+   !!==============================================================================
+   !!                       ***  MODULE  trabbc  ***
+   !! Ocean active tracers:  bottom boundary condition
+   !!==============================================================================
+   !! History :  8.1  ! 99-10 (G. Madec)  original code
+   !!            8.5  ! 02-08 (G. Madec)  free form + modules
+   !!            8.5  ! 02-11 (A. Bozec)  tra_bbc_init: original code
+   !!----------------------------------------------------------------------
+#if   defined key_trabbc   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trabbc'                                  geothermal heat flux
+   !!----------------------------------------------------------------------
+   !!   tra_bbc      : update the tracer trend at ocean bottom 
+   !!   tra_bbc_init : initialization of geothermal heat flux trend
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE trdmod          ! ocean trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_bbc          ! routine called by step.F90
+
+   !! to be transfert in the namelist ???!   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbc = .TRUE.   !: bbc flag
+
+   !!* Namelist nambbc: bottom boundary condition
+   INTEGER  ::   ngeo_flux       = 1            ! Geothermal flux (0:no flux, 1:constant flux, 2:read in file )
+   REAL(wp) ::   ngeo_flux_const = 86.4e-3      ! Constant value of geothermal heat flux
+
+   INTEGER , DIMENSION(jpi,jpj) ::   nbotlevt   ! ocean bottom level index at T-pt
+   REAL(wp), DIMENSION(jpi,jpj) ::   qgh_trd0   ! geothermal heating trend
+ 
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_bbc( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbc  ***
+      !!
+      !! ** Purpose :   Compute the bottom boundary contition on temperature 
+      !!      associated with geothermal heating and add it to the general
+      !!      trend of temperature equations.
+      !!
+      !! ** Method  :   The geothermal heat flux set to its constant value of 
+      !!       86.4 mW/m2 (Stein and Stein 1992, Huang 1999).
+      !!       The temperature trend associated to this heat flux through the
+      !!       ocean bottom can be computed once and is added to the temperature
+      !!       trend juste above the bottom at each time step:
+      !!            ta = ta + Qsf / (rau0 rcp e3T) for k= mbathy -1
+      !!       Where Qsf is the geothermal heat flux.
+      !!
+      !! ** Action  : - update the temperature trends (ta) with the trend of
+      !!                the ocean bottom boundary condition
+      !!
+      !! References : Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   zqgh_trd  ! geothermal heat flux trend
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt   ! 3D workspace   
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_bbc_init      ! Initialization
+
+      IF( l_trdtra )   ztrdt(:,:,:) = ta(:,:,:)         ! Save ta and sa trends
+
+      ! Add the geothermal heat flux trend on temperature
+
+      SELECT CASE ( ngeo_flux )
+      !
+      CASE ( 1:2 )                !  geothermal heat flux
+#if defined key_vectopt_loop
+         DO jj = 1, 1                   ! vector opt.
+            DO ji = jpi+2, jpij-jpi-1   ! forced loop collapse
+#else
+         DO jj = 2, jpjm1               ! standard loop
+            DO ji = 2, jpim1
+#endif
+               zqgh_trd = ro0cpr * qgh_trd0(ji,jj) / fse3t(ji,jj,nbotlevt(ji,jj))
+               ta(ji,jj,nbotlevt(ji,jj)) = ta(ji,jj,nbotlevt(ji,jj)) + zqgh_trd
+            END DO
+         END DO
+      END SELECT
+
+      IF( l_trdtra ) THEN        ! Save the geothermal heat flux trend for diagnostics
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         CALL trd_tra( kt, jp_tem, jpt_trd_ldf, 'TRA', ptrd3d=ztrdt)
+      ENDIF
+      !
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=ta, clinfo1=' bbc  - Ta: ', mask1=tmask, clinfo3='tra-ta')
+      !
+   END SUBROUTINE tra_bbc
+
+
+   SUBROUTINE tra_bbc_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbc_init  ***
+      !!
+      !! ** Purpose :   Compute once for all the trend associated with geo-
+      !!      thermal heating that will be applied at each time step at the
+      !!      bottom ocean level
+      !!
+      !! ** Method  :   Read the nambbc namelist and check the parameters.
+      !!      called at the first time step (nit000)
+      !!
+      !! ** Input   : - Namlist nambbc
+      !!              - NetCDF file  : geothermal_heating.nc ( if necessary )
+      !!
+      !! ** Action  : - read/fix the geothermal heat qgh_trd0
+      !!              - compute the bottom ocean level nbotlevt
+      !!----------------------------------------------------------------------
+      USE iom
+      !!
+      INTEGER  ::   ji, jj              ! dummy loop indices
+      INTEGER  ::   inum                ! temporary logical unit
+
+      NAMELIST/nambbc/ngeo_flux, ngeo_flux_const 
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )              ! Read Namelist nambbc : bottom momentum boundary condition
+      READ   ( numnam, nambbc )
+
+      !                              ! Control print
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'tra_bbc : tempearture Bottom Boundary Condition (bbc)'
+      IF(lwp) WRITE(numout,*) '~~~~~~~   Geothermal heatflux'
+      IF(lwp) WRITE(numout,*) '          Namelist nambbc : set bbc parameters'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '             Geothermal flux           ngeo_flux       = ', ngeo_flux
+      IF(lwp) WRITE(numout,*) '             Constant geothermal flux  ngeo_flux_const = ', ngeo_flux_const
+      IF(lwp) WRITE(numout,*)
+
+      !                              ! level of the ocean bottom at T-point
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            nbotlevt(ji,jj) = MAX( mbathy(ji,jj)-1, 1 )
+         END DO
+      END DO
+
+      SELECT CASE ( ngeo_flux )      ! initialization of geothermal heat flux
+      !
+      CASE ( 0 )                ! no geothermal heat flux
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '             *** no geothermal heat flux'
+         !
+      CASE ( 1 )                ! constant flux
+         IF(lwp) WRITE(numout,*) '             *** constant heat flux  =   ', ngeo_flux_const
+         qgh_trd0(:,:) = ngeo_flux_const
+         !
+      CASE ( 2 )                ! variable geothermal heat flux
+         ! read the geothermal fluxes in mW/m2
+         !
+         IF(lwp) WRITE(numout,*) '             *** variable geothermal heat flux'
+         CALL iom_open ( 'geothermal_heating.nc', inum )
+         CALL iom_get ( inum, jpdom_data, 'heatflow', qgh_trd0 )
+         CALL iom_close (inum)
+         !
+         qgh_trd0(:,:) = qgh_trd0(:,:) * 1.e-3 ! conversion in W/m2
+         !
+      CASE DEFAULT
+         WRITE(ctmp1,*) '     bad flag value for ngeo_flux = ', ngeo_flux
+         CALL ctl_stop( ctmp1 )
+         !
+      END SELECT
+
+
+   END SUBROUTINE tra_bbc_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbc = .FALSE.  !: bbc flag
+CONTAINS
+   SUBROUTINE tra_bbc( kt )           ! Empty routine
+      WRITE(*,*) 'tra_bbc: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbc
+#endif
+
+   !!======================================================================
+END MODULE trabbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4536)
@@ -0,0 +1,497 @@
+MODULE trabbl
+   !!==============================================================================
+   !!                       ***  MODULE  trabbl  ***
+   !! Ocean physics :  advective and/or diffusive bottom boundary layer scheme
+   !!==============================================================================
+   !! History :  8.0  !  96-06  (L. Mortier)  Original code
+   !!            8.0  !  97-11  (G. Madec)  Optimization
+   !!            8.5  !  02-08  (G. Madec)  free form + modules
+   !!----------------------------------------------------------------------
+#if   defined key_trabbl_dif   ||   defined key_trabbl_adv   || defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trabbl_dif'   or            diffusive bottom boundary layer
+   !!   'key_trabbl_adv'                 advective bottom boundary layer
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_bbl_dif  : update the active tracer trends due to the bottom
+   !!                  boundary layer (diffusive only)
+   !!   tra_bbl_adv  : update the active tracer trends due to the bottom
+   !!                  boundary layer (advective and/or diffusive)
+   !!   tra_bbl_init : initialization, namlist read, parameters control
+   !!----------------------------------------------------------------------
+   USE oce                ! ocean dynamics and active tracers
+   USE dom_oce            ! ocean space and time domain
+   USE trdmod             ! ocean active tracers trends
+   USE trdmod_oce         ! ocean variables trends
+   USE in_out_manager     ! I/O manager
+   USE lbclnk             ! ocean lateral boundary conditions
+   USE prtctl             ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_bbl_dif    ! routine called by step.F90
+   PUBLIC tra_bbl_adv    ! routine called by step.F90
+
+   !!* Namelist nambbl: bottom boundary layer
+   REAL(wp), PUBLIC ::   atrbbl = 1.e+3   !: lateral coeff. for bottom boundary layer scheme (m2/s)
+
+# if defined key_trabbl_dif
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_dif = .TRUE.          !: diffusive bottom boundary layer flag
+# else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_dif = .FALSE.         !: diffusive bottom boundary layer flag
+# endif
+
+# if defined key_trabbl_adv
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .TRUE.   !: advective bottom boundary layer flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   u_bbl      !: 3 components of the velocity
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   v_bbl      !: associated with advective BBL
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   w_bbl      !: (only affect tracer)
+# else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .FALSE.  !: advective bottom boundary layer flag
+# endif
+
+   INTEGER, DIMENSION(jpi,jpj) ::   mbkt          ! vertical index of the bottom ocean T-level
+   INTEGER, DIMENSION(jpi,jpj) ::   mbku, mbkv    ! vertical index of the bottom ocean U/V-level
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_bbl_dif( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_bbl_dif  ***
+      !!
+      !! ** Purpose :   Compute the before tracer (t & s) trend associated 
+      !!      with the bottom boundary layer and add it to the general trend 
+      !!      of tracer equations. The bottom boundary layer is supposed to be
+      !!      a purely diffusive bottom boundary layer.
+      !!
+      !! ** Method  :   When the product grad( rho) * grad(h) < 0 (where grad 
+      !!      is an along bottom slope gradient) an additional lateral diffu-
+      !!      sive trend along the bottom slope is added to the general tracer
+      !!      trend, otherwise nothing is done.
+      !!      Second order operator (laplacian type) with variable coefficient
+      !!      computed as follow for temperature (idem on s): 
+      !!         difft = 1/(e1t*e2t*e3t) { di-1[ ahbt e2u*e3u/e1u di[ztb] ]
+      !!                                 + dj-1[ ahbt e1v*e3v/e2v dj[ztb] ] }
+      !!      where ztb is a 2D array: the bottom ocean temperature and ahtb
+      !!      is a time and space varying diffusive coefficient defined by:
+      !!         ahbt = zahbp    if grad(rho).grad(h) < 0
+      !!              = 0.       otherwise.
+      !!      Note that grad(.) is the along bottom slope gradient. grad(rho)
+      !!      is evaluated using the local density (i.e. referenced at the
+      !!      local depth). Typical value of ahbt is 2000 m2/s (equivalent to
+      !!      a downslope velocity of 20 cm/s if the condition for slope
+      !!      convection is satified)
+      !!      Add this before trend to the general trend (ta,sa) of the 
+      !!      botton ocean tracer point:
+      !!         ta = ta + difft
+      !!
+      !! ** Action  : - update (ta,sa) at the bottom level with the bottom
+      !!                boundary layer trend
+      !!              - save the trends in ztrdt/ztrds ('key_trdtra')
+      !!
+      !! References : Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      USE eosbn2                      ! equation of state
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step
+      !!
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      INTEGER  ::   ik
+      INTEGER  ::   ii0, ii1, ij0, ij1       ! temporary integers
+      INTEGER  ::   iku1, iku2, ikv1,ikv2   ! temporary intergers
+      REAL(wp) ::   ze3u, ze3v              ! temporary scalars
+      INTEGER  ::   iku, ikv
+      REAL(wp) ::   zsign, zt, zs, zh, zalbet   ! temporary scalars
+      REAL(wp) ::   zgdrho, zbtr, zta, zsa
+      REAL(wp), DIMENSION(jpi,jpj) ::   zki, zkj, zkw, zkx, zky, zkz   ! 2D workspace arrays
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnb, zsnb, zdep
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztbb, zsbb, zahu, zahv
+      REAL(wp) ::    fsalbt, pft, pfs, pfh   ! statement function
+      !!----------------------------------------------------------------------
+      ! ratio alpha/beta
+      ! ================
+      !  fsalbt: ratio of thermal over saline expension coefficients
+      !       pft :  potential temperature in degrees celcius
+      !       pfs :  salinity anomaly (s-35) in psu
+      !       pfh :  depth in meters
+
+      fsalbt( pft, pfs, pfh ) =                                              &
+         ( ( ( -0.255019e-07 * pft + 0.298357e-05 ) * pft                    &
+                                   - 0.203814e-03 ) * pft                    &
+                                   + 0.170907e-01 ) * pft                    &
+                                   + 0.665157e-01                            &
+         +(-0.678662e-05 * pfs - 0.846960e-04 * pft + 0.378110e-02 ) * pfs   &
+         +  ( ( - 0.302285e-13 * pfh                                         &
+                - 0.251520e-11 * pfs                                         &
+                + 0.512857e-12 * pft * pft          ) * pfh                  &
+                                     - 0.164759e-06   * pfs                  &
+             +(   0.791325e-08 * pft - 0.933746e-06 ) * pft                  &
+                                     + 0.380374e-04 ) * pfh   
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_bbl_init
+
+      IF( l_trdtra )   THEN         ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
+      ENDIF
+
+      ! 0. 2D fields of bottom temperature and salinity, and bottom slope
+      ! -----------------------------------------------------------------
+      ! mbathy= number of w-level, minimum value=1 (cf dommsk.F)
+#  if defined key_vectopt_loop
+      DO jj = 1, 1         ! vector opt.
+         DO ji = 1, jpij   ! forced the loop collapse
+#  else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#  endif
+            ik = mbkt(ji,jj)                              ! index of the bottom ocean T-level
+            ztnb(ji,jj) = tn(ji,jj,ik) * tmask(ji,jj,1)   ! masked now T and S at ocean bottom 
+            zsnb(ji,jj) = sn(ji,jj,ik) * tmask(ji,jj,1)
+            ztbb(ji,jj) = tb(ji,jj,ik) * tmask(ji,jj,1)   ! masked before T and S at ocean bottom 
+            zsbb(ji,jj) = sb(ji,jj,ik) * tmask(ji,jj,1)
+            zdep(ji,jj) = fsdept(ji,jj,ik)                ! depth of the ocean bottom T-level
+         END DO
+      END DO
+
+      IF( ln_zps ) THEN      ! partial steps correction 
+# if defined key_vectopt_loop
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               iku1 = MAX( mbathy(ji+1,jj  )-1, 1 )
+               iku2 = MAX( mbathy(ji  ,jj  )-1, 1 )
+               ikv1 = MAX( mbathy(ji  ,jj+1)-1, 1 )
+               ikv2 = MAX( mbathy(ji  ,jj  )-1, 1 )
+               ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+               ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+               zahu(ji,jj) = atrbbl * e2u(ji,jj) * ze3u / e1u(ji,jj) * umask(ji,jj,1)
+               zahv(ji,jj) = atrbbl * e1v(ji,jj) * ze3v / e2v(ji,jj) * vmask(ji,jj,1)
+            END DO
+         END DO
+      ELSE                    ! z-coordinate - full steps or s-coordinate
+#   if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#   else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#   endif
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               zahu(ji,jj) = atrbbl * e2u(ji,jj) * fse3u(ji,jj,iku) / e1u(ji,jj) * umask(ji,jj,1)
+               zahv(ji,jj) = atrbbl * e1v(ji,jj) * fse3v(ji,jj,ikv) / e2v(ji,jj) * vmask(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+
+      ! 1. Criteria of additional bottom diffusivity: grad(rho).grad(h)<0
+      ! --------------------------------------------
+      ! Sign of the local density gradient along the i- and j-slopes
+      ! multiplied by the slope of the ocean bottom
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )                 ! Jackett and McDougall (1994) formulation
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+            zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+            ! masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh )*umask(ji,jj,1)
+            ! local density gradient along i-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
+                   -          ( zsnb(ji+1,jj) - zsnb(ji,jj) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+         END DO
+      END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+            zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+            ! masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh )*vmask(ji,jj,1)
+            ! local density gradient along j-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
+               &   -          ( zsnb(ji,jj+1) - zsnb(ji,jj) )
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = sign( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+         END DO
+      END DO
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+                               ! 
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! local 'density/temperature' gradient along i-bathymetric slope
+            zgdrho =  ztnb(ji+1,jj) - ztnb(ji,jj) 
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+         END DO
+      END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! local density gradient along j-bathymetric slope
+            zgdrho =  ztnb(ji,jj+1) - ztnb(ji,jj) 
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = sign( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+         END DO
+      END DO
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif      
+            ! local density gradient along i-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji+1,jj) - zsnb(ji,jj) )   &
+               &     -  ralpha*( ztnb(ji+1,jj) - ztnb(ji,jj) ) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+         END DO
+      END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif     
+            ! local density gradient along j-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji,jj+1) - zsnb(ji,jj) )   &
+               &     -  ralpha*( ztnb(ji,jj+1) - ztnb(ji,jj) ) )   
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+         END DO
+      END DO
+      
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop(ctmp1)
+
+      END SELECT
+
+      ! 2. Additional second order diffusive trends
+      ! -------------------------------------------
+
+      ! first derivative (gradient)
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1             ! vector opt.
+         DO ji = 1, jpij-jpi   ! forced the loop collapse
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            zkx(ji,jj) = zki(ji,jj) * ( ztbb(ji+1,jj) - ztbb(ji,jj) )
+            zkz(ji,jj) = zki(ji,jj) * ( zsbb(ji+1,jj) - zsbb(ji,jj) )
+
+            zky(ji,jj) = zkj(ji,jj) * ( ztbb(ji,jj+1) - ztbb(ji,jj) )
+            zkw(ji,jj) = zkj(ji,jj) * ( zsbb(ji,jj+1) - zsbb(ji,jj) )
+         END DO
+      END DO
+
+      IF( cp_cfg == "orca" ) THEN
+         !
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            ! Gibraltar enhancement of BBL
+            ij0 = 102   ;   ij1 = 102
+            ii0 = 139   ;   ii1 = 140  
+            zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            !
+            ! Red Sea enhancement of BBL
+            ij0 =  88   ;   ij1 =  88
+            ii0 = 161   ;   ii1 = 162
+            zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            !
+            !                                        ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            ! Gibraltar enhancement of BBL
+            ij0 =  52   ;   ij1 =  52
+            ii0 =  70   ;   ii1 =  71  
+            zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+            !
+         END SELECT
+      !
+      ENDIF
+
+
+      ! second derivative (divergence) and add to the general tracer trend
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      DO jj = 1, 1                   ! vector opt.
+         DO ji = jpi+2, jpij-jpi-1   ! forced the loop collapse
+#  else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+#  endif
+            ik = max( mbathy(ji,jj)-1, 1 )
+            zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,ik) )
+            zta = (  zkx(ji,jj) - zkx(ji-1,jj  )    &
+               &   + zky(ji,jj) - zky(ji  ,jj-1)  ) * zbtr
+            zsa = (  zkz(ji,jj) - zkz(ji-1,jj  )    &
+               &   + zkw(ji,jj) - zkw(ji  ,jj-1)  ) * zbtr
+            ta(ji,jj,ik) = ta(ji,jj,ik) + zta
+            sa(ji,jj,ik) = sa(ji,jj,ik) + zsa
+         END DO
+      END DO
+
+      IF( l_trdtra ) THEN      ! save the BBL lateral diffusion trends for diagnostic
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_tra( kt, jp_tem, jpt_trd_bbl, 'TRA', ptrd3d=ztrdt)
+         CALL trd_tra( kt, jp_sal, jpt_trd_bbl, 'TRA', ptrd3d=ztrds)
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
+   END SUBROUTINE tra_bbl_dif
+
+# if defined key_trabbl_adv
+   !!----------------------------------------------------------------------
+   !!   'key_trabbl_adv'                    advective bottom boundary layer
+   !!----------------------------------------------------------------------
+#  include "trabbl_adv.h90"
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                 NO advective bottom boundary layer
+   !!----------------------------------------------------------------------
+   SUBROUTINE tra_bbl_adv( kt )              ! Empty routine
+      INTEGER :: kt
+      WRITE(*,*) 'tra_bbl_adv: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbl_adv
+# endif
+
+   SUBROUTINE tra_bbl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbl_init  ***
+      !!
+      !! ** Purpose :   Initialization for the bottom boundary layer scheme.
+      !!
+      !! ** Method  :   Read the nambbl namelist and check the parameters
+      !!      called by tra_bbl at the first timestep (nit000)
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj      ! dummy loop indices
+      REAL(wp),  DIMENSION(jpi,jpj) :: zmbk  
+
+      NAMELIST/nambbl/ atrbbl
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )              ! Read Namelist nambbl : bottom boundary layer scheme
+      READ   ( numnam, nambbl )
+
+      IF(lwp) THEN                   ! Parameter control and print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_bbl_init : '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         IF (lk_trabbl_dif )   WRITE(numout,*) '               * Diffusive Bottom Boundary Layer'
+         IF( lk_trabbl_adv )   WRITE(numout,*) '               * Advective Bottom Boundary Layer'
+         WRITE(numout,*) '       Namelist nambbl : set bbl parameters'
+         WRITE(numout,*) '          bottom boundary layer coef.    atrbbl = ', atrbbl
+      ENDIF
+ 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            mbkt(ji,jj) = MAX( mbathy(ji,jj) - 1, 1 )   ! vertical index of the bottom ocean T-level
+         END DO
+      END DO
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            mbku(ji,jj) = MAX( MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) ) - 1, 1 )
+            mbkv(ji,jj) = MAX( MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) ) - 1, 1 )
+         END DO
+      END DO
+
+      zmbk(:,:) = FLOAT( mbku (:,:) )   
+      CALL lbc_lnk(zmbk,'U',1.)
+      mbku(:,:) = MAX( INT( zmbk(:,:) ), 1 ) 
+
+      zmbk(:,:) = FLOAT( mbkv (:,:) )   
+      CALL lbc_lnk(zmbk,'V',1.)
+      mbkv(:,:) = MAX( INT( zmbk(:,:) ), 1 ) 
+
+# if defined key_trabbl_adv
+      w_bbl(:,:,:) = 0.e0          ! initialisation of w_bbl to zero
+# endif
+      !
+   END SUBROUTINE tra_bbl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      No bottom boundary layer scheme
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_dif = .FALSE.   !: diff bbl flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .FALSE.   !: adv  bbl flag
+CONTAINS
+   SUBROUTINE tra_bbl_dif( kt )              ! Empty routine
+      WRITE(*,*) 'tra_bbl_dif: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbl_dif
+   SUBROUTINE tra_bbl_adv( kt )              ! Empty routine
+      WRITE(*,*) 'tra_bbl_adv: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_bbl_adv
+#endif
+
+   !!======================================================================
+END MODULE trabbl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl_adv.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl_adv.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trabbl_adv.h90	(revision 4536)
@@ -0,0 +1,430 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  trabbl_adv.h90  ***
+   !!----------------------------------------------------------------------
+   !! History :  8.5  !  02-12  (A. de Miranda, G. Madec)  Original Code 
+   !!            9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines )
+   !!----------------------------------------------------------------------     
+
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE tra_bbl_adv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_bbl_adv  ***
+      !!                   
+      !! ** Purpose :   Compute the before tracer (t & s) trend associated 
+      !!     with the bottom boundary layer and add it to the general trend
+      !!     of tracer equations. The bottom boundary layer is supposed to be 
+      !!     both an advective and diffusive bottom boundary layer.
+      !!
+      !! ** Method  :   Computes the bottom boundary horizontal and vertical 
+      !!      advection terms. Add it to the general trend : ta =ta + adv_bbl.
+      !!        When the product grad( rho) * grad(h) < 0 (where grad is a
+      !!      along bottom slope gradient) an additional lateral 2nd order
+      !!      diffusion along the bottom slope is added to the general
+      !!      tracer trend, otherwise the additional trend is set to 0.
+      !!      Second order operator (laplacian type) with variable coefficient
+      !!      computed as follow for temperature (idem on s):
+      !!         difft = 1/(e1t*e2t*e3t) { di-1[ ahbt e2u*e3u/e1u di[ztb] ]
+      !!                                 + dj-1[ ahbt e1v*e3v/e2v dj[ztb] ] }
+      !!      where ztb is a 2D array: the bottom ocean te;perature and ahtb
+      !!      is a time and space varying diffusive coefficient defined by:
+      !!         ahbt = zahbp    if grad(rho).grad(h) < 0
+      !!              = 0.       otherwise.
+      !!      Note that grad(.) is the along bottom slope gradient. grad(rho)
+      !!      is evaluated using the local density (i.e. referenced at the
+      !!      local depth). Typical value of ahbt is 2000 m2/s (equivalent to
+      !!      a downslope velocity of 20 cm/s if the condition for slope
+      !!      convection is satified)
+      !!        Add this before trend to the general trend (ta,sa) of the
+      !!      botton ocean tracer point:
+      !!              ta = ta + difft
+      !!
+      !! ** Action  : - update (ta,sa) at the bottom level with the bottom
+      !!                boundary layer trend
+      !!
+      !! References : Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!----------------------------------------------------------------------     
+      USE eosbn2                      ! equation of state
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step 
+      !!
+      INTEGER  ::   ji, jj, jk        ! dummy loop indices
+      INTEGER  ::   ik                ! temporary integers
+      INTEGER  ::   iku, iku1, iku2   !    "          "
+      INTEGER  ::   ikv, ikv1, ikv2   !    "          "
+      REAL(wp) ::   zsign, zh, zalbet     ! temporary scalars
+      REAL(wp) ::   zgdrho, zbtr          !    "         " 
+      REAL(wp) ::   zbt, zsigna           !    "         "
+      REAL(wp) ::   zfui, ze3u, zt, zta   !    "         "
+      REAL(wp) ::   zfvj, ze3v, zs, zsa   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zalphax, zwu, zunb   ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zalphay, zwv, zvnb   !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx, zwy, zww, zwz   !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztbb, zsbb           !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztnb, zsnb, zdep     !    "             "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhdivn               ! temporary 3D workspace
+      REAL(wp) ::   fsalbt, pft, pfs, pfh   ! statement function
+      !!----------------------------------------------------------------------
+      ! ratio alpha/beta
+      ! ================
+      !  fsalbt: ratio of thermal over saline expension coefficients
+      !       pft :  potential temperature in degrees celcius
+      !       pfs :  salinity anomaly (s-35) in psu
+      !       pfh :  depth in meters
+
+      fsalbt( pft, pfs, pfh ) =                                              &
+         ( ( ( -0.255019e-07 * pft + 0.298357e-05 ) * pft                    &
+                                   - 0.203814e-03 ) * pft                    &
+                                   + 0.170907e-01 ) * pft                    &
+                                   + 0.665157e-01                            &
+         +(-0.678662e-05 * pfs - 0.846960e-04 * pft + 0.378110e-02 ) * pfs   &
+         +  ( ( - 0.302285e-13 * pfh                                         &
+                - 0.251520e-11 * pfs                                         &
+                + 0.512857e-12 * pft * pft          ) * pfh                  &
+                                     - 0.164759e-06   * pfs                  &
+             +(   0.791325e-08 * pft - 0.933746e-06 ) * pft                  &
+                                     + 0.380374e-04 ) * pfh
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_bbl_init    ! initialization at first time-step
+
+      ! 1. 2D fields of bottom temperature and salinity, and bottom slope
+      ! -----------------------------------------------------------------
+      ! mbathy= number of w-level, minimum value=1 (cf dommsk.F)
+
+#if defined key_vectopt_loop 
+      DO jj = 1, 1
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#endif
+            ik = mbkt(ji,jj)                               ! index of the bottom ocean T-level
+            ztnb(ji,jj) = tn(ji,jj,ik)
+            zsnb(ji,jj) = sn(ji,jj,ik)
+            ztbb(ji,jj) = tb(ji,jj,ik)
+            zsbb(ji,jj) = sb(ji,jj,ik) 
+            zdep(ji,jj) = fsdept(ji,jj,ik)                 ! depth of the ocean bottom T-level
+
+            zunb(ji,jj) = un(ji,jj,mbku(ji,jj)) 
+            zvnb(ji,jj) = vn(ji,jj,mbkv(ji,jj)) 
+         END DO
+      END DO
+
+
+      ! 2. Criteria of additional bottom diffusivity: grad(rho).grad(h)<0
+      ! --------------------------------------------
+      ! Sign of the local density gradient along the i- and j-slopes
+      ! multiplied by the slope of the ocean bottom
+
+      SELECT CASE ( neos )
+      !
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+      !
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            !   ... temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+            zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+            !   ... masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh ) * umask(ji,jj,1)
+            !   ... local density gradient along i-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
+               &       -      ( zsnb(ji+1,jj) - zsnb(ji,jj) )
+            zgdrho = zgdrho * umask(ji,jj,1)
+            !   ... sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zalphax(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
+         END DO
+      END DO
+      !
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            !   ... temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+            zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+            !   ... masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh ) * vmask(ji,jj,1)
+            !   ... local density gradient along j-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
+               &       -      ( zsnb(ji,jj+1) - zsnb(ji,jj) )
+            zgdrho = zgdrho*vmask(ji,jj,1)
+            !   ... sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+      !
+      CASE ( 1 )               ! Linear formulation function of temperature only
+      !
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            ! local 'density/temperature' gradient along i-bathymetric slope
+            zgdrho =  ( ztnb(ji+1,jj) - ztnb(ji,jj) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho    * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zalphax(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
+
+            ! local density gradient along j-bathymetric slope
+            zgdrho =  ( ztnb(ji,jj+1) - ztnb(ji,jj) )
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+      !
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+      !
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.            
+            ! local density gradient along i-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji+1,jj) - zsnb(ji,jj) )   &
+               &     -  ralpha*( ztnb(ji+1,jj) - ztnb(ji,jj) ) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho    * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zalphax(ji,jj) = ( 0.5 + zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
+
+            ! local density gradient along j-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji,jj+1) - zsnb(ji,jj) )   &
+                   -    ralpha*( ztnb(ji,jj+1) - ztnb(ji,jj) ) )   
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, - zgdrho    * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj) = ( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+      !
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+         !
+      END SELECT
+
+      ! lateral boundary conditions on zalphax and zalphay   (unchanged sign)
+       CALL lbc_lnk( zalphax, 'U', 1. )   ;   CALL lbc_lnk( zalphay, 'V', 1. )
+
+
+      ! 3. Velocities that are exchanged between ajacent bottom boxes.
+      !---------------------------------------------------------------
+
+      ! ... is equal to zero but where bbl will work.
+      u_bbl(:,:,:) = 0.e0   ;   v_bbl(:,:,:) = 0.e0
+
+      IF( ln_zps ) THEN     ! partial steps correction   
+      
+# if defined key_vectopt_loop
+         DO jj = 1, 1
+            DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else   
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               iku  = mbku(ji  ,jj  )
+               ikv  = mbkv(ji  ,jj  )  
+               iku1 = mbkt(ji+1,jj  )
+               iku2 = mbkt(ji  ,jj  )
+               ikv1 = mbkt(ji  ,jj+1)
+               ikv2 = mbkt(ji  ,jj  )
+               ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+               ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+               
+               IF( MAX(iku,ikv) >  1 ) THEN
+                  u_bbl(ji,jj,iku) = zalphax(ji,jj) * un(ji,jj,iku) * ze3u / fse3u(ji,jj,iku)
+                  v_bbl(ji,jj,ikv) = zalphay(ji,jj) * vn(ji,jj,ikv) * ze3v / fse3v(ji,jj,ikv)       
+               ENDIF
+            END DO
+         END DO
+
+         ! lateral boundary conditions on u_bbl and v_bbl   (changed sign)
+         CALL lbc_lnk( u_bbl, 'U', -1. )   ;   CALL lbc_lnk( v_bbl, 'V', -1. )
+       
+      ELSE       ! if not partial step loop over the whole domain no lbc call
+
+#if defined key_vectopt_loop
+         DO jj = 1, 1
+            DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+#endif   
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               IF( MAX(iku,ikv) >  1 ) THEN
+                  u_bbl(ji,jj,iku) = zalphax(ji,jj) * un(ji,jj,iku) 
+                  v_bbl(ji,jj,ikv) = zalphay(ji,jj) * vn(ji,jj,ikv)       
+               ENDIF
+            END DO
+         END DO
+       
+      ENDIF
+	  
+
+      ! 5. Along sigma advective trend
+      ! -------------------------------
+      ! ... Second order centered tracer flux at u and v-points
+
+# if defined key_vectopt_loop
+      DO jj = 1, 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            iku = mbku(ji,jj)
+            ikv = mbkv(ji,jj)
+            zfui = e2u(ji,jj) * fse3u(ji,jj,iku) * u_bbl(ji,jj,iku)
+            zfvj = e1v(ji,jj) * fse3v(ji,jj,ikv) * v_bbl(ji,jj,ikv)
+            ! centered scheme
+!           zwx(ji,jj) = 0.5* zfui * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+!           zwy(ji,jj) = 0.5* zfvj * ( ztnb(ji,jj) + ztnb(ji,jj+1) )
+!           zww(ji,jj) = 0.5* zfui * ( zsnb(ji,jj) + zsnb(ji+1,jj) )
+!           zwz(ji,jj) = 0.5* zfvj * ( zsnb(ji,jj) + zsnb(ji,jj+1) )
+            ! upstream scheme
+            zwx(ji,jj) = ( ( zfui + ABS( zfui ) ) * ztbb(ji  ,jj  )   &
+               &          +( zfui - ABS( zfui ) ) * ztbb(ji+1,jj  ) ) * 0.5
+            zwy(ji,jj) = ( ( zfvj + ABS( zfvj ) ) * ztbb(ji  ,jj  )   &
+               &          +( zfvj - ABS( zfvj ) ) * ztbb(ji  ,jj+1) ) * 0.5
+            zww(ji,jj) = ( ( zfui + ABS( zfui ) ) * zsbb(ji  ,jj  )   &
+               &          +( zfui - ABS( zfui ) ) * zsbb(ji+1,jj  ) ) * 0.5
+            zwz(ji,jj) = ( ( zfvj + ABS( zfvj ) ) * zsbb(ji  ,jj  )   &
+               &          +( zfvj - ABS( zfvj ) ) * zsbb(ji  ,jj+1) ) * 0.5
+         END DO
+      END DO
+# if defined key_vectopt_loop
+      DO jj = 1, 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ik = mbkt(ji,jj)
+            zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,ik) )
+            ! horizontal advective trends
+            zta = - zbtr * (  zwx(ji,jj) - zwx(ji-1,jj  )   &
+               &            + zwy(ji,jj) - zwy(ji  ,jj-1)  )
+            zsa = - zbtr * (  zww(ji,jj) - zww(ji-1,jj  )   &
+               &            + zwz(ji,jj) - zwz(ji  ,jj-1)  )
+
+            ! add it to the general tracer trends
+            ta(ji,jj,ik) = ta(ji,jj,ik) + zta
+            sa(ji,jj,ik) = sa(ji,jj,ik) + zsa
+         END DO
+      END DO
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+
+      ! 6. Vertical advection velocities
+      ! --------------------------------
+      ! ... computes divergence perturbation (velocties to be removed from upper t boxes :
+      DO jk= 1, jpkm1
+         DO jj=1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zwu(ji,jj) = -e2u(ji,jj) * u_bbl(ji,jj,jk) * fse3u(ji,jj,jk)
+               zwv(ji,jj) = -e1v(ji,jj) * v_bbl(ji,jj,jk) * fse3v(ji,jj,jk)
+            END DO
+         END DO
+
+      ! ... horizontal divergence
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zhdivn(ji,jj,jk) = (  zwu(ji,jj) - zwu(ji-1,jj  )   &
+                                   + zwv(ji,jj) - zwv(ji  ,jj-1)  ) / zbt
+            END DO
+         END DO
+      END DO
+
+
+      ! ... horizontal bottom divergence
+
+      IF( ln_zps ) THEN
+	  
+# if defined key_vectopt_loop 
+         DO jj = 1, 1
+            DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               iku  = mbku(ji  ,jj  )
+               ikv  = mbkv(ji  ,jj  )  
+               iku1 = mbkt(ji+1,jj  )
+               iku2 = mbkt(ji  ,jj  )
+               ikv1 = mbkt(ji  ,jj+1)
+               ikv2 = mbkt(ji  ,jj  )
+               ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+               ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+	       
+               zwu(ji,jj) = zalphax(ji,jj) * e2u(ji,jj) * ze3u  
+               zwv(ji,jj) = zalphay(ji,jj) * e1v(ji,jj) * ze3v
+            END DO
+         END DO  
+	
+      ELSE
+
+# if defined key_vectopt_loop
+         DO jj = 1, 1
+            DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               zwu(ji,jj) = zalphax(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,iku) 
+               zwv(ji,jj) = zalphay(ji,jj) * e1v(ji,jj) * fse3v(ji,jj,ikv) 
+            END DO
+         END DO
+
+      ENDIF
+ 
+
+# if defined key_vectopt_loop
+      DO jj = 1, 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+# endif
+            ik = mbkt(ji,jj)
+            zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,ik)
+            zhdivn(ji,jj,ik) =   &
+               &   (  zwu(ji  ,jj  ) * ( zunb(ji  ,jj  ) - un(ji  ,jj  ,ik) )   &
+               &    - zwu(ji-1,jj  ) * ( zunb(ji-1,jj  ) - un(ji-1,jj  ,ik) )   &
+               &    + zwv(ji  ,jj  ) * ( zvnb(ji  ,jj  ) - vn(ji  ,jj  ,ik) )   &
+               &    - zwv(ji  ,jj-1) * ( zvnb(ji  ,jj-1) - vn(ji  ,jj-1,ik) )   &
+               &   ) / zbt
+
+         END DO
+      END DO
+
+      ! 7. compute additional vertical velocity to be used in t boxes
+      ! -------------------------------------------------------------
+      ! ... Computation from the bottom
+      ! Note that w_bbl(:,:,jpk) has been set to 0 in tra_bbl_init
+      DO jk = jpkm1, 1, -1
+         DO jj= 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               w_bbl(ji,jj,jk) = w_bbl(ji,jj,jk+1) - fse3t(ji,jj,jk)*zhdivn(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Boundary condition on w_bbl   (unchanged sign)
+      CALL lbc_lnk( w_bbl, 'W', 1. )
+      !
+   END SUBROUTINE tra_bbl_adv
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4536)
@@ -0,0 +1,755 @@
+MODULE tradmp
+   !!======================================================================
+   !!                       ***  MODULE  tradmp  ***
+   !! Ocean physics: internal restoring trend on active tracers (T and S)
+   !!======================================================================
+   !! History :  5.0  !  91-03  (O. Marti, G. Madec)  Original code
+   !!                 !  92-06  (M. Imbard)  doctor norme
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!                 !  97-05  (G. Madec)  macro-tasked on jk-slab
+   !!                 !  98-07  (M. Imbard, G. Madec) ORCA version
+   !!            7.0  !  01-02  (M. Imbard)  cofdis, Original code
+   !!            8.1  !  01-02  (G. Madec, E. Durand)  cleaning
+   !!   NEMO     1.0  !  02-08  (G. Madec, E. Durand)  free form + modules
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+#if   defined key_tradmp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   key_tradmp                                         internal damping
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_dmp      : update the tracer trend with the internal damping
+   !!   tra_dmp_init : initialization, namlist read, parameters control
+   !!   dtacof_zoom  : restoring coefficient for zoom domain
+   !!   dtacof       : restoring coefficient for global domain
+   !!   cofdis       : compute the distance to the coastline
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! Define parameters for the routines
+   USE dtatem          ! temperature data
+   USE dtasal          ! salinity data
+   USE zdfmxl          ! mixed layer depth
+   USE lib_mpp         ! distribued memory computing
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_dmp      ! routine called by step.F90
+
+#if ! defined key_agrif
+   LOGICAL, PUBLIC, PARAMETER ::   lk_tradmp = .TRUE.     !: internal damping flag
+#else
+   LOGICAL, PUBLIC            ::   lk_tradmp = .TRUE.     !: internal damping flag
+#endif
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   resto    !: restoring coeff. on T and S (s-1)
+   
+   !!* newtonian damping namelist (mandmp) 
+   INTEGER  ::   ndmp   =   -1    ! = 0/-1/'latitude' for damping over T and S
+   INTEGER  ::   ndmpf  =    2    ! = 1 create a damping.coeff NetCDF file 
+   INTEGER  ::   nmldmp =    0    ! = 0/1/2 flag for damping in the mixed layer
+   REAL(wp) ::   sdmp   =   50.   ! surface time scale for internal damping (days)
+   REAL(wp) ::   bdmp   =  360.   ! bottom time scale for internal damping (days)
+   REAL(wp) ::   hdmp   =  800.   ! depth of transition between sdmp and bdmp (meters)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_dmp( kt, cdtype, ktra, ptb, pta )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_dmp  ***
+      !!                  
+      !! ** Purpose :   Compute the tracer trend due to a newtonian damping
+      !!      of the tracer field towards given data field and add it to the
+      !!      general tracer trends.
+      !!
+      !! ** Method  :   Newtonian damping towards t_dta and s_dta computed 
+      !!      and add to the general tracer trends:
+      !!                     pta = pta + resto * (t_dta - ptb)
+      !!         The trend is computed either throughout the water column
+      !!      (nlmdmp=0) or in area of weak vertical mixing (nlmdmp=1) or
+      !!      below the well mixed layer (nlmdmp=2)
+      !!
+      !! ** Action  : - update the tracer trends (pta) with the newtonian 
+      !!                damping trends.
+      !!              - save the trends in (ttrd) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype   ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra     ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb      ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta      ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zta          ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt   ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. ktra == jp_tem )   CALL tra_dmp_init      ! Initialization
+
+      IF( l_trdtra )   ztrdt(:,:,:) = pta(:,:,:)                      ! Save pta trend
+
+
+      SELECT CASE ( nmldmp )                                          ! compute the newtonian damping trends
+      !
+      CASE( 0 )                ! newtonian damping throughout the water column
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  pta(ji,jj,jk) = pta(ji,jj,jk) + resto(ji,jj,jk) * ( t_dta(ji,jj,jk) - ptb(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( avt(ji,jj,jk) - 5.e-4 < 0. ) THEN   ;   zta = 1.e0
+                  ELSE                                    ;   zta = 0.e0
+                  ENDIF
+                  pta(ji,jj,jk) = pta(ji,jj,jk) + zta * resto(ji,jj,jk) * ( t_dta(ji,jj,jk) - ptb(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+         !
+      CASE ( 2 )                ! no damping in the mixed layer 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN   ;   zta = 1.e0
+                  ELSE                                          ;   zta = 0.e0
+                  ENDIF
+                  pta(ji,jj,jk) = pta(ji,jj,jk) + zta * resto(ji,jj,jk) * ( t_dta(ji,jj,jk) - ptb(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+
+      IF( l_trdtra )   THEN          ! save the damping tracer trends for diagnostic
+         ztrdt(:,:,:) = pta(:,:,:) - ztrdt(:,:,:)
+         CALL trd_tra( kt, ktra, jpt_trd_dmp, 'TRA', ptrd3d=ztrdt)
+      ENDIF
+      !                              ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' cen2 - dmp: ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_dmp
+
+
+   SUBROUTINE tra_dmp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_dmp_init  ***
+      !! 
+      !! ** Purpose :   Initialization for the newtonian damping 
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameters
+      !!      called by tra_dmp at the first timestep (nit000)
+      !!----------------------------------------------------------------------
+      NAMELIST/namtdp/ ndmp, ndmpf, nmldmp, sdmp, bdmp, hdmp
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )                  ! Read Namelist namtdp : temperature and salinity damping term
+      READ   ( numnam, namtdp )
+      IF( lzoom )   nmldmp = 0           ! restoring to climatology at closed north or south boundaries
+
+      IF(lwp) THEN                       ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_dmp : T and S newtonian damping'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '       Namelist namtdp : set damping parameter'
+         WRITE(numout,*) '          T and S damping option         ndmp   = ', ndmp
+         WRITE(numout,*) '          create a damping.coeff file    ndmpf  = ', ndmpf
+         WRITE(numout,*) '          mixed layer damping option     nmldmp = ', nmldmp, '(zoom: forced to 0)'
+         WRITE(numout,*) '          surface time scale (days)      sdmp   = ', sdmp
+         WRITE(numout,*) '          bottom time scale (days)       bdmp   = ', bdmp
+         WRITE(numout,*) '          depth of transition (meters)   hdmp   = ', hdmp
+      ENDIF
+
+      SELECT CASE ( ndmp )
+      CASE (  -1  )   ;   IF(lwp) WRITE(numout,*) '          tracer damping in the Med & Red seas only'
+      CASE ( 1:90 )   ;   IF(lwp) WRITE(numout,*) '          tracer damping poleward of', ndmp, ' degrees'
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for ndmp = ', ndmp
+         CALL ctl_stop(ctmp1)
+      END SELECT
+
+      SELECT CASE ( nmldmp )
+      CASE ( 0 )   ;   IF(lwp) WRITE(numout,*) '          tracer damping throughout the water column'
+      CASE ( 1 )   ;   IF(lwp) WRITE(numout,*) '          no tracer damping in the turbocline (avt > 5 cm2/s)'
+      CASE ( 2 )   ;   IF(lwp) WRITE(numout,*) '          no tracer damping in the mixed layer'
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nmldmp = ', nmldmp
+         CALL ctl_stop(ctmp1)
+      END SELECT
+
+      IF( .NOT.lk_dtasal .OR. .NOT.lk_dtatem )   &
+         &   CALL ctl_stop( 'no temperature and/or salinity data define key_dtatem and key_dtasal' )
+
+      !                          ! Damping coefficients initialization
+      IF( lzoom ) THEN   ;   CALL dtacof_zoom
+      ELSE               ;   CALL dtacof
+      ENDIF
+      !
+   END SUBROUTINE tra_dmp_init
+
+
+   SUBROUTINE dtacof_zoom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dtacof_zoom  ***
+      !!
+      !! ** Purpose :   Compute the damping coefficient for zoom domain
+      !!
+      !! ** Method  : - set along closed boundary due to zoom a damping over
+      !!      6 points with a max time scale of 5 days.
+      !!              - ORCA arctic/antarctic zoom: set the damping along
+      !!      south/north boundary over a latitude strip.
+      !!
+      !! ** Action  : - resto, the damping coeff. for T and S
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
+      REAL(wp) ::   zlat, zlat0, zlat1, zlat2   ! temporary scalar
+      REAL(wp), DIMENSION(6)  ::   zfact        ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      zfact(1) =  1.
+      zfact(2) =  1. 
+      zfact(3) = 11./12.
+      zfact(4) =  8./12.
+      zfact(5) =  4./12.
+      zfact(6) =  1./12.
+      zfact(:) = zfact(:) / ( 5. * rday )    ! 5 days max restoring time scale
+
+      resto(:,:,:) = 0.e0
+
+      ! damping along the forced closed boundary over 6 grid-points
+      DO jn = 1, 6
+         IF( lzoom_w )   resto( mi0(jn+jpizoom):mi1(jn+jpizoom), : , : )                    = zfact(jn)   ! west  closed
+         IF( lzoom_s )   resto( : , mj0(jn+jpjzoom):mj1(jn+jpjzoom), : )                    = zfact(jn)   ! south closed 
+         IF( lzoom_e )   resto( mi0(jpiglo+jpizoom-1-jn):mi1(jpiglo+jpizoom-1-jn) , : , : ) = zfact(jn)   ! east  closed 
+         IF( lzoom_n )   resto( : , mj0(jpjglo+jpjzoom-1-jn):mj1(jpjglo+jpjzoom-1-jn) , : ) = zfact(jn)   ! north closed
+      END DO
+
+
+      IF( lzoom_arct .AND. lzoom_anta ) THEN
+         !
+         ! ====================================================
+         !  ORCA configuration : arctic zoom or antarctic zoom
+         ! ====================================================
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp .AND. lzoom_arct ) WRITE(numout,*) '              dtacof_zoom : ORCA    Arctic zoom'
+         IF(lwp .AND. lzoom_arct ) WRITE(numout,*) '              dtacof_zoom : ORCA Antarctic zoom'
+         IF(lwp) WRITE(numout,*)
+
+         ! ... Initialization : 
+         !     zlat0 : latitude strip where resto decreases
+         !     zlat1 : resto = 1 before zlat1
+         !     zlat2 : resto decreases from 1 to 0 between zlat1 and zlat2
+         resto(:,:,:) = 0.e0
+         zlat0 = 10.
+         zlat1 = 30.
+         zlat2 = zlat1 + zlat0
+
+         ! ... Compute arrays resto ; value for internal damping : 5 days
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zlat = ABS( gphit(ji,jj) )
+                  IF ( zlat1 <= zlat .AND. zlat <= zlat2 ) THEN
+                     resto(ji,jj,jk) = 0.5 * ( 1./(5.*rday) ) *   &
+                        ( 1. - cos(rpi*(zlat2-zlat)/zlat0) ) 
+                  ELSE IF ( zlat < zlat1 ) THEN
+                     resto(ji,jj,jk) = 1./(5.*rday)
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+
+      ! ... Mask resto array
+      resto(:,:,:) = resto(:,:,:) * tmask(:,:,:)
+      !
+   END SUBROUTINE dtacof_zoom
+
+
+   SUBROUTINE dtacof
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dtacof  ***
+      !!
+      !! ** Purpose :   Compute the damping coefficient
+      !!
+      !! ** Method  :   Arrays defining the damping are computed for each grid
+      !!      point for temperature and salinity (resto)
+      !!      Damping depends on distance to coast, depth and latitude
+      !!
+      !! ** Action  : - resto, the damping coeff. for T and S
+      !!----------------------------------------------------------------------
+      USE iom
+      USE ioipsl
+      !!
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   itime
+      INTEGER ::   ii0, ii1, ij0, ij1  !    "          "
+      INTEGER ::   idmp         ! logical unit for file restoring damping term
+      INTEGER ::   icot         ! logical unit for file distance to the coast
+      CHARACTER (len=32) :: clname3
+      REAL(wp) ::   zdate0, zinfl, zlon         ! temporary scalars
+      REAL(wp) ::   zlat, zlat0, zlat1, zlat2   !    "         "
+      REAL(wp) ::   zsdmp, zbdmp                !    "         "
+      REAL(wp), DIMENSION(jpk)         ::   zhfac
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zmrs
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdct
+      !!----------------------------------------------------------------------
+
+      ! ====================================
+      !  ORCA configuration : global domain
+      ! ====================================
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '              dtacof : Global domain of ORCA'
+      IF(lwp) WRITE(numout,*) '              ------------------------------'
+
+      ! ... Initialization : 
+      !   zdct()      : distant to the coastline
+      !   resto()     : array of restoring coeff. on T and S
+
+      resto(:,:,:) = 0.e0
+
+      IF ( ndmp > 0 ) THEN
+
+         !    ------------------------------------
+         !     Damping poleward of 'ndmp' degrees
+         !    ------------------------------------
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '              Damping poleward of ', ndmp,' deg.'
+         IF(lwp) WRITE(numout,*)
+
+         ! ... Distance to coast (zdct)
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' dtacof : distance to coast file'
+         CALL iom_open ( 'dist.coast.nc', icot )
+         IF( icot > 0 ) THEN
+            CALL iom_get ( icot, jpdom_data, 'Tcoast', zdct )
+            CALL iom_close (icot)
+         ELSE
+            !   ... Compute and save the distance-to-coast array (output in zdct)
+            CALL cofdis( zdct )
+         ENDIF
+
+         ! ... Compute arrays resto 
+         !      zinfl : distance of influence for damping term
+         !      zlat0 : latitude strip where resto decreases
+         !      zlat1 : resto = 0 between -zlat1 and zlat1
+         !      zlat2 : resto increases from 0 to 1 between |zlat1| and |zlat2|
+         !          and resto = 1 between |zlat2| and 90 deg.
+         zinfl = 1000.e3
+         zlat0 = 10
+         zlat1 = ndmp
+         zlat2 = zlat1 + zlat0
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zlat = ABS( gphit(ji,jj) )
+               IF ( zlat1 <= zlat .AND. zlat <= zlat2 ) THEN
+                  resto(ji,jj,1) = 0.5 * ( 1. - cos(rpi*(zlat-zlat1)/zlat0 ) )
+               ELSEIF ( zlat > zlat2 ) THEN
+                  resto(ji,jj,1) = 1.
+               ENDIF
+            END DO
+         END DO
+
+         !   ... North Indian ocean (20N/30N x 45E/100E) : resto=0
+         IF ( ndmp == 20 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zlat = gphit(ji,jj)
+                  zlon = MOD( glamt(ji,jj), 360. )
+                  IF ( zlat1 < zlat .AND. zlat < zlat2 .AND.   &
+                     45.  < zlon .AND. zlon < 100. ) THEN
+                     resto(ji,jj,1) = 0.
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+
+         zsdmp = 1./(sdmp * rday)
+         zbdmp = 1./(bdmp * rday)
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zdct(ji,jj,jk) = MIN( zinfl, zdct(ji,jj,jk) )
+                  !   ... Decrease the value in the vicinity of the coast
+                  resto(ji,jj,jk) = resto(ji,jj,1) * 0.5 * ( 1. - COS( rpi*zdct(ji,jj,jk)/zinfl) )
+                  !   ... Vertical variation from zsdmp (sea surface) to zbdmp (bottom)
+                  resto(ji,jj,jk) = resto(ji,jj,jk)      * ( zbdmp + (zsdmp-zbdmp)*EXP(-fsdept(ji,jj,jk)/hdmp) )
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+
+
+      IF( cp_cfg == "orca" .AND. ( ndmp > 0 .OR. ndmp == -1 ) ) THEN
+
+         !                                         ! =========================
+         !                                         !  Med and Red Sea damping
+         !                                         ! =========================
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) '              ORCA configuration: Damping in Med and Red Seas'
+
+
+         zmrs(:,:) = 0.e0                             ! damping term on the Med or Red Sea
+
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration 
+            !                                        ! =======================
+            ! Mediterranean Sea
+            ij0 =  50   ;   ij1 =  56
+            ii0 =  81   ;   ii1 =  91   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 =  50   ;   ij1 =  55
+            ii0 =  75   ;   ii1 =  80   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 =  52   ;   ij1 =  53
+            ii0 =  70   ;   ii1 =  74   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Smooth transition from 0 at surface to 1./rday at the 18th level in Med and Red Sea
+            DO jk = 1, 17
+               zhfac (jk) = 0.5*( 1.- COS( rpi*(jk-1)/16. ) ) / rday
+            END DO
+            DO jk = 18, jpkm1
+               zhfac (jk) = 1./rday
+            END DO
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration 
+            !                                        ! =======================
+            ! Mediterranean Sea
+            ij0 =  96   ;   ij1 = 110
+            ii0 = 157   ;   ii1 = 181   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 = 100   ;   ij1 = 110
+            ii0 = 144   ;   ii1 = 156   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 = 100   ;   ij1 = 103
+            ii0 = 139   ;   ii1 = 143   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Gibraltar Strait
+            ij0 = 101   ;   ij1 = 102
+            ii0 = 139   ;   ii1 = 141   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.e0
+            ii0 = 142   ;   ii1 = 142   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ii0 = 143   ;   ii1 = 143   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40e0
+            ii0 = 144   ;   ii1 = 144   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.75e0
+            ! Red Sea
+            ij0 =  87   ;   ij1 =  96
+            ii0 = 147   ;   ii1 = 163   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Bab el Mandeb Strait
+            ij0 =  91   ;   ij1 =  91
+            ii0 = 153   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.80e0
+            ij0 =  90   ;   ij1 =  90
+            ii0 = 153   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40e0
+            ij0 =  89   ;   ij1 =  89
+            ii0 = 158   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ij0 =  88   ;   ij1 =  88
+            ii0 = 160   ;   ii1 = 163   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.e0
+            ! Smooth transition from 0 at surface to 1./rday at the 18th level in Med and Red Sea
+            DO jk = 1, 17
+               zhfac (jk) = 0.5*( 1.- COS( rpi*(jk-1)/16. ) ) / rday
+            END DO
+            DO jk = 18, jpkm1
+               zhfac (jk) = 1./rday
+            END DO
+            !                                        ! =======================
+         CASE ( 05 )                                 !  ORCA_R05 configuration
+            !                                        ! =======================
+            ! Mediterranean Sea
+            ii0 = 568   ;   ii1 = 574 
+            ij0 = 324   ;   ij1 = 333   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ii0 = 575   ;   ii1 = 658
+            ij0 = 314   ;   ij1 = 366   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Black Sea (remaining part
+            ii0 = 641   ;   ii1 = 651
+            ij0 = 367   ;   ij1 = 372   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Gibraltar Strait
+            ij0 = 324   ;   ij1 = 333
+            ii0 = 565   ;   ii1 = 565   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ii0 = 566   ;   ii1 = 566   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+            ii0 = 567   ;   ii1 = 567   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.75
+            ! Red Sea
+            ii0 = 641   ;   ii1 = 665
+            ij0 = 270   ;   ij1 = 310   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Bab el Mandeb Strait
+            ii0 = 666   ;   ii1 = 675
+            ij0 = 270   ;   ij1 = 290   
+            DO ji = mi0(ii0), mi1(ii1)
+               zmrs( ji , mj0(ij0):mj1(ij1) ) = 0.1 * ABS( FLOAT(ji - mi1(ii1)) )
+            END DO 
+            zsdmp = 1./(sdmp * rday)
+            zbdmp = 1./(bdmp * rday)
+            DO jk = 1, jpk
+               zhfac (jk) = ( zbdmp + (zsdmp-zbdmp) * EXP(-fsdept(1,1,jk)/hdmp) )
+            END DO
+            !                                       ! ========================
+         CASE ( 025 )                               !  ORCA_R025 configuration 
+            !                                       ! ========================
+            CALL ctl_stop( ' Not yet implemented in ORCA_R025' )
+            !
+         END SELECT
+
+         DO jk = 1, jpkm1
+            resto(:,:,jk) = zmrs(:,:) * zhfac(jk) + ( 1. - zmrs(:,:) ) * resto(:,:,jk)
+         END DO
+
+         ! Mask resto array and set to 0 first and last levels
+         resto(:,:, : ) = resto(:,:,:) * tmask(:,:,:)
+         resto(:,:, 1 ) = 0.e0
+         resto(:,:,jpk) = 0.e0
+
+      ELSE
+         !    ------------
+         !     No damping
+         !    ------------
+         CALL ctl_stop( 'Choose a correct value of ndmp or DO NOT defined key_tradmp' )
+      ENDIF
+
+      !    ----------------------------
+      !     Create Print damping array
+      !    ----------------------------
+
+      ! ndmpf   : = 1 create a damping.coeff NetCDF file
+
+      IF( ndmpf == 1 ) THEN
+         IF(lwp) WRITE(numout,*) '              create damping.coeff.nc file'
+         itime   = 0
+         clname3 = 'damping.coeff'
+         CALL ymds2ju( 0     , 1      , 1      , 0.e0 , zdate0 )
+         CALL restini( 'NONE', jpi    , jpj    , glamt, gphit,    &
+            &          jpk   , gdept_0, clname3, itime, zdate0,   &
+            &          rdt   , idmp, domain_id=nidom )
+         CALL restput( idmp, 'Resto', jpi, jpj, jpk,   &
+            &          0   , resto  )
+         CALL restclo( idmp )
+      ENDIF
+      !
+   END SUBROUTINE dtacof
+
+
+   SUBROUTINE cofdis( pdct )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE cofdis  ***
+      !!
+      !! ** Purpose :   Compute the distance between ocean T-points and the
+      !!      ocean model coastlines. Save the distance in a NetCDF file.
+      !!
+      !! ** Method  :   For each model level, the distance-to-coast is 
+      !!      computed as follows : 
+      !!       - The coastline is defined as the serie of U-,V-,F-points
+      !!      that are at the ocean-land bound.
+      !!       - For each ocean T-point, the distance-to-coast is then 
+      !!      computed as the smallest distance (on the sphere) between the 
+      !!      T-point and all the coastline points.
+      !!       - For land T-points, the distance-to-coast is set to zero.
+      !!      C A U T I O N : Computation not yet implemented in mpp case.
+      !!
+      !! ** Action  : - pdct, distance to the coastline (argument)
+      !!              - NetCDF file 'dist.coast.nc' 
+      !!----------------------------------------------------------------------
+      USE ioipsl      ! IOipsl librairy
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   pdct   ! distance to the coastline
+      !!
+      INTEGER ::   ji, jj, jk, jl      ! dummy loop indices
+      INTEGER ::   iju, ijt            ! temporary integers
+      INTEGER ::   icoast, itime
+      INTEGER ::   icot         ! logical unit for file distance to the coast
+      LOGICAL, DIMENSION(jpi,jpj) ::   llcotu, llcotv, llcotf   ! ???
+      CHARACTER (len=32) ::   clname
+      REAL(wp) ::   zdate0
+      REAL(wp), DIMENSION(jpi,jpj)   ::   zxt, zyt, zzt, zmask   ! cartesian coordinates for T-points
+      REAL(wp), DIMENSION(3*jpi*jpj) ::   zxc, zyc, zzc, zdis    ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialization
+      ! -----------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cofdis : compute the distance to coastline'
+      IF(lwp) WRITE(numout,*) '~~~~~~'
+      IF(lwp) WRITE(numout,*)
+      IF( lk_mpp ) &
+           & CALL ctl_stop('         Computation not yet implemented with key_mpp_...', &
+           &               '         Rerun the code on another computer or ', &
+           &               '         create the "dist.coast.nc" file using IDL' )
+
+      pdct(:,:,:) = 0.e0
+      zxt(:,:) = cos( rad * gphit(:,:) ) * cos( rad * glamt(:,:) )
+      zyt(:,:) = cos( rad * gphit(:,:) ) * sin( rad * glamt(:,:) )
+      zzt(:,:) = sin( rad * gphit(:,:) )
+
+
+      ! 1. Loop on vertical levels
+      ! --------------------------
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Define the coastline points (U, V and F)
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zmask(ji,jj) =  ( tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) &
+                   &           + tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk) )
+               llcotu(ji,jj) = ( tmask(ji,jj,  jk) + tmask(ji+1,jj  ,jk) == 1. ) 
+               llcotv(ji,jj) = ( tmask(ji,jj  ,jk) + tmask(ji  ,jj+1,jk) == 1. ) 
+               llcotf(ji,jj) = ( zmask(ji,jj) > 0. ) .AND. ( zmask(ji,jj) < 4. )
+            END DO
+         END DO
+
+         ! Lateral boundaries conditions
+         llcotu(:, 1 ) = umask(:,  2  ,jk) == 1
+         llcotu(:,jpj) = umask(:,jpjm1,jk) == 1
+         llcotv(:, 1 ) = vmask(:,  2  ,jk) == 1
+         llcotv(:,jpj) = vmask(:,jpjm1,jk) == 1
+         llcotf(:, 1 ) = fmask(:,  2  ,jk) == 1
+         llcotf(:,jpj) = fmask(:,jpjm1,jk) == 1
+
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+            llcotu( 1 ,:) = llcotu(jpim1,:)
+            llcotu(jpi,:) = llcotu(  2  ,:)
+            llcotv( 1 ,:) = llcotv(jpim1,:)
+            llcotv(jpi,:) = llcotv(  2  ,:)
+            llcotf( 1 ,:) = llcotf(jpim1,:)
+            llcotf(jpi,:) = llcotf(  2  ,:)
+         ELSE
+            llcotu( 1 ,:) = umask(  2  ,:,jk) == 1
+            llcotu(jpi,:) = umask(jpim1,:,jk) == 1
+            llcotv( 1 ,:) = vmask(  2  ,:,jk) == 1
+            llcotv(jpi,:) = vmask(jpim1,:,jk) == 1
+            llcotf( 1 ,:) = fmask(  2  ,:,jk) == 1
+            llcotf(jpi,:) = fmask(jpim1,:,jk) == 1
+         ENDIF
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            DO ji = 1, jpim1
+               iju = jpi - ji + 1
+               llcotu(ji,jpj  ) = llcotu(iju,jpj-2)
+               llcotf(ji,jpjm1) = llcotf(iju,jpj-2)
+               llcotf(ji,jpj  ) = llcotf(iju,jpj-3)
+            END DO
+            DO ji = jpi/2, jpim1
+               iju = jpi - ji + 1
+               llcotu(ji,jpjm1) = llcotu(iju,jpjm1)
+            END DO
+            DO ji = 2, jpi
+               ijt = jpi - ji + 2
+               llcotv(ji,jpjm1) = llcotv(ijt,jpj-2)
+               llcotv(ji,jpj  ) = llcotv(ijt,jpj-3)
+            END DO
+         ENDIF
+         IF( nperio == 5 .OR. nperio == 6 ) THEN
+            DO ji = 1, jpim1
+               iju = jpi - ji
+               llcotu(ji,jpj  ) = llcotu(iju,jpjm1)
+               llcotf(ji,jpj  ) = llcotf(iju,jpj-2)
+            END DO
+            DO ji = jpi/2, jpim1
+               iju = jpi - ji
+               llcotf(ji,jpjm1) = llcotf(iju,jpjm1)
+            END DO
+            DO ji = 1, jpi
+               ijt = jpi - ji + 1
+               llcotv(ji,jpj  ) = llcotv(ijt,jpjm1)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi - ji + 1
+               llcotv(ji,jpjm1) = llcotv(ijt,jpjm1)
+            END DO
+         ENDIF
+
+         ! Compute cartesian coordinates of coastline points
+         ! and the number of coastline points
+
+         icoast = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( llcotf(ji,jj) ) THEN
+                  icoast = icoast + 1
+                  zxc(icoast) = COS( rad*gphif(ji,jj) ) * COS( rad*glamf(ji,jj) )
+                  zyc(icoast) = COS( rad*gphif(ji,jj) ) * SIN( rad*glamf(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphif(ji,jj) )
+               ENDIF
+               IF( llcotu(ji,jj) ) THEN
+                  icoast = icoast+1
+                  zxc(icoast) = COS( rad*gphiu(ji,jj) ) * COS( rad*glamu(ji,jj) )
+                  zyc(icoast) = COS( rad*gphiu(ji,jj) ) * SIN( rad*glamu(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphiu(ji,jj) )
+               ENDIF
+               IF( llcotv(ji,jj) ) THEN
+                  icoast = icoast+1
+                  zxc(icoast) = COS( rad*gphiv(ji,jj) ) * COS( rad*glamv(ji,jj) )
+                  zyc(icoast) = COS( rad*gphiv(ji,jj) ) * SIN( rad*glamv(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphiv(ji,jj) )
+               ENDIF
+            END DO
+         END DO
+
+         ! Distance for the T-points
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tmask(ji,jj,jk) == 0. ) THEN
+                  pdct(ji,jj,jk) = 0.
+               ELSE
+                  DO jl = 1, icoast
+                     zdis(jl) = ( zxt(ji,jj) - zxc(jl) )**2   &
+                        &     + ( zyt(ji,jj) - zyc(jl) )**2   &
+                        &     + ( zzt(ji,jj) - zzc(jl) )**2
+                  END DO
+                  pdct(ji,jj,jk) = ra * SQRT( MINVAL( zdis(1:icoast) ) )
+               ENDIF
+            END DO
+         END DO
+         !                                                ! ===============
+      END DO                                              !   End of slab
+      !                                                   ! ===============
+
+
+      ! 2. Create the  distance to the coast file in NetCDF format
+      ! ----------------------------------------------------------    
+      clname = 'dist.coast'
+      itime = 0
+      CALL ymds2ju( 0     , 1      , 1     , 0.e0 , zdate0 )
+      CALL restini( 'NONE', jpi    , jpj   , glamt, gphit ,   &
+         &          jpk   , gdept_0, clname, itime, zdate0,   &
+         &          rdt   , icot                         )
+      CALL restput( icot, 'Tcoast', jpi, jpj, jpk, 0, pdct )
+      CALL restclo( icot )
+
+   END SUBROUTINE cofdis
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO internal damping
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_tradmp = .FALSE.    !: internal damping flag
+CONTAINS
+   SUBROUTINE tra_dmp( kt, cdtype, ktra, ptb, pta )
+!  SUBROUTINE tra_dmp( kt )        ! Empty routine
+!    INTEGER         , INTENT(in   )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3) ::   cdtype   ! =TRA or TRC (tracer indicator)
+!     INTEGER         , INTENT(in   )                         ::   ktra     ! tracer index
+      REAL, DIMENSION(:,:,:) ::   ptb, pta
+
+      WRITE(*,*) 'tra_dmp: You should not have seen this print! error?', kt, ktra,cdtype, ptb(1,1,1), pta(1,1,1)
+   END SUBROUTINE tra_dmp
+#endif
+
+   !!======================================================================
+END MODULE tradmp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 4536)
@@ -0,0 +1,326 @@
+MODULE traldf
+   !!======================================================================
+   !!                       ***  MODULE  traldf  ***
+   !! Ocean Active tracers : lateral diffusive trends 
+   !!=====================================================================
+   !! History :  9.0  ! 05-11 (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf     : update the tracer trend with the lateral diffusion
+   !!       ldf_ctl : initialization, namelist read, and parameters control
+   !!       ldf_ano : compute lateral diffusion for constant T-S profiles
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE ldfslp          ! ???
+   USE traldf_bilapg   ! lateral mixing            (tra_ldf_bilapg routine)
+   USE traldf_bilap    ! lateral mixing             (tra_ldf_bilap routine)
+   USE traldf_iso      ! lateral mixing               (tra_ldf_iso routine)
+   USE traldf_lap      ! lateral mixing               (tra_ldf_lap routine)
+   USE trdmod          ! ocean active tracers trends
+   USE trdmod_oce      ! ocean variables trends
+   USE prtctl          ! Print control
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_ldf    ! called by step.F90 
+
+   INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_traldf_... namlist logicals)
+#if defined key_traldf_ano
+   REAL, DIMENSION(jpi,jpj,jpk) ::   t0_ldf, s0_ldf   ! lateral diffusion trends of T & S
+      !                                               ! for a constant vertical profile
+#endif
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_ldf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf  ***
+      !! 
+      !! ** Purpose :   compute the lateral ocean tracer physics.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt, ztrds   ! 3D temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL ldf_ctl          ! initialisation & control of options
+
+      IF( l_trdtra )   THEN                      ! temporary save of ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
+      ENDIF
+
+      SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      CASE ( 0 )   ;   CALL tra_ldf_lap   ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! iso-level laplacian
+                       CALL tra_ldf_lap   ( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! iso-level laplacian
+      CASE ( 1 )   ;   CALL tra_ldf_iso   ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! rotated laplacian except dk2
+      CASE ( 2 )   ;   CALL tra_ldf_bilap ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! rotated laplacian except dk2
+                       CALL tra_ldf_bilap ( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! iso-level laplacian
+      CASE ( 3 )   ;   CALL tra_ldf_bilapg( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! s-coord. horizontal bilaplacian
+                       CALL tra_ldf_bilapg( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! s-coord. horizontal bilaplacian
+         !
+      CASE ( -1 )                                     ! esopa: test all possibility with control print
+                       CALL tra_ldf_lap   ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! iso-level laplacian
+                       CALL tra_ldf_lap   ( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! iso-level laplacian
+                       CALL tra_ldf_iso   ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! rotated laplacian except dk2
+                       CALL tra_ldf_iso   ( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! rotated laplacian except dk2
+                       CALL tra_ldf_bilap ( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! iso-level bilaplacian
+                       CALL tra_ldf_bilap ( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! iso-level laplacian
+                       CALL tra_ldf_bilapg( kt, 'TRA', jp_tem, gtu, gtv, tb, ta )      ! s-coord. horizontal bilaplacian
+                       CALL tra_ldf_bilapg( kt, 'TRA', jp_sal, gsu, gsv, sb, sa )      ! s-coord. horizontal bilaplacian
+      END SELECT
+
+#if defined key_traldf_ano
+      ta(:,:,:) = ta(:,:,:) - t0_ldf(:,:,:)      ! anomaly: substract the reference diffusivity
+      sa(:,:,:) = sa(:,:,:) - s0_ldf(:,:,:)
+#endif
+      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_tra( kt, jp_tem, jpt_trd_ldf, 'TRA', ptrd3d=ztrdt)
+         CALL trd_tra( kt, jp_sal, jpt_trd_ldf, 'TRA', ptrd3d=ztrds)
+      ENDIF
+      !                                          ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf  - Ta: ', mask1=tmask,               &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
+   END SUBROUTINE tra_ldf
+
+
+   SUBROUTINE ldf_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_ctl  ***
+      !! 
+      !! ** Purpose :   Choice of the operator for the lateral tracer diffusion
+      !!
+      !! ** Method  :   set nldf from the nam_traldf logicals
+      !!      nldf == -1   ESOPA test: ALL operators are used
+      !!      nldf ==  0   laplacian operator
+      !!      nldf ==  1   Rotated laplacian operator
+      !!      nldf ==  2   bilaplacian operator
+      !!      nldf ==  3   Rotated bilaplacian
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio, ierr         ! temporary integers 
+!      
+!     NAMELIST/nam_traldf/ ln_traldf_lap  , ln_traldf_bilap,                &
+!        &                 ln_traldf_level, ln_traldf_hor, ln_traldf_iso,   &
+!        &                 aht0, ahtb0, aeiv0
+      !!----------------------------------------------------------------------
+
+      !  Define the lateral mixing oparator for tracers
+      ! ===============================================
+    
+      ! Namelist nam_traldf already read in ldftra module
+!     ! Read Namelist nam_traldf : Lateral physics on tracers
+!     REWIND( numnam )
+!     READ  ( numnam, nam_traldf )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:ldf_ctl : lateral tracer diffusive operator'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist nam_traldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_traldf_level = ', ln_traldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_traldf_hor   = ', ln_traldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_traldf_iso   = ', ln_traldf_iso
+      ENDIF
+
+      !                               ! control the input
+      ioptio = 0
+      IF( ln_traldf_lap   )   ioptio = ioptio + 1
+      IF( ln_traldf_bilap )   ioptio = ioptio + 1
+      IF( ioptio >  1 )   CALL ctl_stop( '          use ONE or NONE of the 2 lap/bilap operator type on tracer' )
+      IF( ioptio == 0 )   nldf = -2   ! No lateral diffusion
+      ioptio = 0
+      IF( ln_traldf_level )   ioptio = ioptio + 1
+      IF( ln_traldf_hor   )   ioptio = ioptio + 1
+      IF( ln_traldf_iso   )   ioptio = ioptio + 1
+      IF( ioptio /= 1 )   CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
+
+      ! defined the type of lateral diffusion from ln_traldf_... logicals
+      ierr = 0
+      IF( ln_traldf_lap ) THEN       ! laplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed
+            IF ( ln_traldf_hor   )   nldf = 0      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 0      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 1      ! horizontal (   rotation)
+            IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
+         ENDIF
+      ENDIF
+
+      IF( ln_traldf_bilap ) THEN      ! bilaplacian operator
+         IF ( ln_zco ) THEN                ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_zps ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed 
+            IF ( ln_traldf_hor   )   nldf = 2      ! horizontal (no rotation)
+            IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+         IF ( ln_sco ) THEN             ! z-coordinate
+            IF ( ln_traldf_level )   nldf = 2      ! iso-level  (no rotation)
+            IF ( ln_traldf_hor   )   nldf = 3      ! horizontal (   rotation)
+            IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
+         ENDIF
+      ENDIF
+
+      IF( ierr == 1 )   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 2 )   CALL ctl_stop( ' isoneutral bilaplacian operator does not exist' )
+      IF( lk_traldf_eiv .AND. .NOT.ln_traldf_iso )   &
+           CALL ctl_stop( '          eddy induced velocity on tracers',   &
+           &              ' the eddy induced velocity on tracers requires isopycnal laplacian diffusion' )
+      IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( '          the rotation of the diffusive tensor require key_ldfslp' )
+      ENDIF
+
+      IF( lk_esopa ) THEN
+         IF(lwp) WRITE(numout,*) '          esopa control: use all lateral physics options'
+         nldf = -1
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF( nldf == -2 )   WRITE(numout,*) '          NO lateral diffusion'
+         IF( nldf == -1 )   WRITE(numout,*) '          ESOPA test All scheme used'
+         IF( nldf ==  0 )   WRITE(numout,*) '          laplacian operator'
+         IF( nldf ==  1 )   WRITE(numout,*) '          Rotated laplacian operator'
+         IF( nldf ==  2 )   WRITE(numout,*) '          bilaplacian operator'
+         IF( nldf ==  3 )   WRITE(numout,*) '          Rotated bilaplacian'
+      ENDIF
+
+      ! Reference T & S diffusivity (if necessary)
+      ! ===========================
+      CALL ldf_ano
+      !
+   END SUBROUTINE ldf_ctl
+
+#if defined key_traldf_ano
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_ano'               T & S lateral diffusion on anomalies
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_ano
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_ano  ***
+      !!
+      !! ** Purpose :   initializations of 
+      !!----------------------------------------------------------------------
+      USE zdf_oce         ! vertical mixing
+      USE trazdf          ! vertical mixing: double diffusion
+      USE zdfddm          ! vertical mixing: double diffusion
+      !!
+      INTEGER  ::   jk              ! Dummy loop indice
+      LOGICAL  ::   llsave          !
+      REAL(wp) ::   zt0, zs0, z12   ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zt_ref, ztb, zavt   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zs_ref, zsb         ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:ldf_ano : lateral diffusion acting on anomalies'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      ! defined the T & S reference profiles
+      ! ------------------------------------
+      zt0 =10.e0                               ! homogeneous ocean
+      zs0 =35.e0
+      zt_ref(:,:,:) = 10.0 * tmask(:,:,:)
+      zs_ref(:,:,:) = 35.0 * tmask(:,:,:)
+      IF(lwp) WRITE(numout,*) '              homogeneous ocean T = ', zt0, ' S = ',zs0
+
+      !                                        ! T & S profile (to be coded +namelist parameter
+
+      ! prepare the ldf computation
+      ! ---------------------------
+      llsave = l_trdtra
+      l_trdtra = .false.      ! desactivate trend computation
+      t0_ldf(:,:,:) = 0.e0
+      s0_ldf(:,:,:) = 0.e0
+      ztb   (:,:,:) = tb (:,:,:)
+      zsb   (:,:,:) = sb (:,:,:)
+      ua    (:,:,:) = ta (:,:,:)
+      va    (:,:,:) = sa (:,:,:)
+      zavt  (:,:,:) = avt(:,:,:)
+      IF( lk_zdfddm ) THEN CALL ctl_stop( ' key_traldf_ano with key_zdfddm not implemented' )
+      ! set tb, sb to reference values and avr to zero
+      tb (:,:,:) = zt_ref(:,:,:)
+      sb (:,:,:) = zs_ref(:,:,:)
+      ta (:,:,:) = 0.e0
+      sa (:,:,:) = 0.e0
+      avt(:,:,:) = 0.e0
+
+      ! Compute the ldf trends
+      ! ----------------------
+      CALL tra_ldf( nit000+1 )      ! horizontal components (+1: no more init)
+      CALL tra_zdf( nit000   )      ! vertical component (if necessary nit000 to performed the init)
+
+      ! finalise the computation and recover all arrays
+      ! -----------------------------------------------
+      l_trdtra = llsave
+      z12 = 2.e0
+      IF( neuler == 1)   z12 = 1.e0
+      IF( ln_zdfexp ) THEN      ! ta,sa are the trends
+         t0_ldf(:,:,:) = ta(:,:,:)
+         s0_ldf(:,:,:) = sa(:,:,:)
+      ELSE
+         DO jk = 1, jpkm1
+            t0_ldf(:,:,jk) = ( ta(:,:,jk) - tb(:,:,jk) ) / ( z12 *rdttra(jk) )
+            s0_ldf(:,:,jk) = ( sa(:,:,jk) - tb(:,:,jk) ) / ( z12 *rdttra(jk) )
+         END DO
+      ENDIF
+      tb    (:,:,:) = ztb (:,:,:)
+      sb    (:,:,:) = zsb (:,:,:)
+      ta    (:,:,:) = ua  (:,:,:)
+      sa    (:,:,:) = va  (:,:,:)
+      avt   (:,:,:) = zavt(:,:,:)
+      !
+   END SUBROUTINE ldf_ano
+
+#else
+   !!----------------------------------------------------------------------
+   !!   default option :   Dummy code   NO T & S background profiles
+   !!----------------------------------------------------------------------
+   SUBROUTINE ldf_ano
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:ldf_ano : lateral diffusion acting on the full fields'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+   END SUBROUTINE ldf_ano
+#endif
+
+   !!======================================================================
+END MODULE traldf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilap.F90	(revision 4536)
@@ -0,0 +1,179 @@
+MODULE traldf_bilap
+   !!==============================================================================
+   !!                   ***  MODULE  traldf_bilap  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+   !! History :  OPA  !  91-11  (G. Madec)  Original code
+   !!                 !  93-03  (M. Guyon)  symetrical conditions
+   !!                 !  95-11  (G. Madec)  suppress volumetric scale factors
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!                 !  96-01  (M. Imbard)  mpp exchange
+   !!                 !  97-07  (G. Madec)  optimization, and ahtt
+   !!            NEMO !  02-08  (G. Madec)  F90: Free form and module
+   !!            1.0  !  04-08  (C. Talandier) New trends organization
+   !!                 !  05-11  (G. Madec)  zps or sco as default option
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_bilap : update the tracer trend with the horizontal diffusion
+   !!                   using a iso-level biharmonic operator
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_ldf_bilap   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "ldfeiv_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE tra_ldf_bilap( kt, cdtype, ktra, pgtu, pgtv,   &
+      &                                        ptb , pta   )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_bilap  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   4th order diffusive operator along model level surfaces 
+      !!      evaluated using before fields (forward time scheme). The hor.
+      !!      diffusive trends of temperature (idem for salinity) is given by:
+      !!      Laplacian of tb:
+      !!         zlt   = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(tb) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(tb) ]  }
+      !!      Multiply by the eddy diffusivity coef. and insure lateral bc:
+      !!        zlt   = ahtt * zlt
+      !!        call to lbc_lnk
+      !!      Bilaplacian (laplacian of zlt):
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(zlt) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(zlt) ]  }
+      !!      Note: if key_zco defined, e3t=e3u=e3v, they are simplified.
+      !!
+      !!      Add this trend to the general trend (ta,sa):
+      !!         (ta,sa) = (ta,sa) + ( difft , diffs )
+      !!
+      !! ** Action : - Update (ta,sa) arrays with the before iso-level
+      !!               biharmonic mixing trend.
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj)     ::   pgtu, pgtv      ! tracer gradient at pstep levels
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER ::   ji, jj, jk             ! dummy loop indices
+      INTEGER ::   iku, ikv               ! temporary integers
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zeeu, zeev, zbtr, zlt   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztu, ztv          ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_bilap : iso-level biharmonic operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! 0. Initialization of metric arrays (for z- or s-coordinates)
+         ! ----------------------------------
+
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+               zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+               zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+            END DO
+         END DO
+
+
+         ! 1. Laplacian
+         ! ------------
+
+         ! First derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztu(ji,jj,jk) = zeeu(ji,jj) * ( ptb(ji+1,jj  ,jk) - ptb(ji,jj,jk) )
+               ztv(ji,jj,jk) = zeev(ji,jj) * ( ptb(ji  ,jj+1,jk) - ptb(ji,jj,jk) )
+            END DO
+         END DO
+         IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  ! last level
+                  iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  IF( iku == jk )   ztu(ji,jj,jk) = zeeu(ji,jj) * pgtu(ji,jj)
+                  IF( ikv == jk )   ztv(ji,jj,jk) = zeev(ji,jj) * pgtv(ji,jj)
+               END DO
+            END DO
+         ENDIF
+
+         ! Second derivative (divergence) multiply by the eddy diffusivity coefficient
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zlt(ji,jj) = fsahtt(ji,jj,jk) * zbtr(ji,jj)   &
+                  &                          * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+            END DO
+         END DO
+
+!!gm   k-loop must be cut here and a 3D lbclnk used
+
+         ! Lateral boundary conditions on the laplacian (zlt)   (unchanged sgn)
+         CALL lbc_lnk( zlt, 'T', 1. ) 
+
+         ! 2. Bilaplacian
+         ! --------------
+
+         DO jj = 1, jpjm1                              ! third derivative (gradient)
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztu(ji,jj,jk) = zeeu(ji,jj) * ( zlt(ji+1,jj  ) - zlt(ji,jj) )
+               ztv(ji,jj,jk) = zeev(ji,jj) * ( zlt(ji  ,jj+1) - zlt(ji,jj) )
+            END DO
+         END DO
+
+         DO jj = 2, jpjm1                              ! 4th derivative (divergence) and add to the general tracer trend
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               pta(ji,jj,jk) = pta(ji,jj,jk) + zbtr(ji,jj)   &
+                  &                          * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           ! Horizontal slab
+      !                                                ! ===============
+
+
+      !                              ! "Poleward" lateral diffusive heat or salt transport 
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_ldf(:) = ptr_vj( ztv(:,:,:) )
+         IF( ktra == jp_sal)   pst_ldf(:) = ptr_vj( ztv(:,:,:) )
+      ENDIF
+
+      !                              ! control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' ldf - bilap : ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_ldf_bilap
+
+   !!==============================================================================
+END MODULE traldf_bilap
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90	(revision 4536)
@@ -0,0 +1,337 @@
+MODULE traldf_bilapg
+   !!==============================================================================
+   !!                       ***  MODULE  traldf_bilapg  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+   !! History :  8.0  !  97-07  (G. Madec)  Original code
+   !!            NEMO !  02-08  (G. Madec)  F90: Free form and module
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+#if defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_bilapg : update the tracer trend with the horizontal diffusion
+   !!                    using an horizontal biharmonic operator in s-coordinate 
+   !!   ldfght         :  ???
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain variables
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE ldfslp          ! iso-neutral slopes available
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+   USE diaptr          ! poleward transport diagnostics 
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_ldf_bilapg    ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "ldfeiv_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE tra_ldf_bilapg( kt, cdtype, ktra, pgtu, pgtv,   &
+      &                                         ptb , pta   )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tra_ldf_bilapg  ***
+      !!                    
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The lateral diffusive trends is provided by a 4th order
+      !!      operator rotated along geopotential surfaces. It is computed
+      !!      using before fields (forward in time) and geopotential slopes
+      !!      computed in routine inildf.
+      !!         -1- compute the geopotential harmonic operator applied to
+      !!      (tb,sb) and multiply it by the eddy diffusivity coefficient
+      !!      (done by a call to ldfght routine, result in wk1 array).
+      !!      Applied the domain lateral boundary conditions by call to lbc_lnk
+      !!         -2- compute the geopotential harmonic operator applied to
+      !!      wk1 by a second call to ldfght routine (result in wk2)
+      !!      arrays).
+      !!         -3- Add this trend to the general trend pta:
+      !!            pta = pta + wk2
+      !!
+      !! ** Action : - Update pta arrays with the before geopotential 
+      !!               biharmonic mixing trend.
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj)     ::   pgtu, pgtv      ! tracer gradient at pstep levels
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   wk1, wk2                ! workspace arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_bilapg : horizontal biharmonic operator in s-coordinate'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Laplacian of ptb * aht
+
+      CALL ldfght ( kt, cdtype, ktra, ptb, wk1, 1 )      ! rotated laplacian applied to ptb and * aht (output in wk1 )
+
+      CALL lbc_lnk( wk1, 'T', 1. )                       ! Lateral boundary conditions on wk1   (unchanged sign)
+
+      ! Bilaplacian of ptb
+
+      CALL ldfght ( kt, cdtype, ktra, wk1, wk2,  2 )     ! rotated laplacian applied to wk1 (output in wk2 )
+
+
+      ! Update the tracer trends
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1 
+            DO ji = 2, jpim1
+               pta(ji,jj,jk) = pta(ji,jj,jk) + wk2(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_ldf_bilapg
+
+
+   SUBROUTINE ldfght ( kt, cdtype, ktra, pt, plt, kaht )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldfght  ***
+      !!          
+      !! ** Purpose :   Apply a geopotential harmonic operator to p and 
+      !!      multiply it by the eddy diffusivity coefficient (if kaht=1).
+      !!      Routine only used in s-coordinates (l_sco=T) with bilaplacian
+      !!      operator (ln_traldf_bilap=T) acting along geopotential surfaces
+      !!      (ln_traldf_hor).
+      !!
+      !! ** Method  :   The harmonic operator rotated along geopotential 
+      !!      surfaces is applied to pt using the slopes of geopotential
+      !!      surfaces computed in inildf routine. The result is provided in
+      !!      plt arrays. It is computed in 2 steps:
+      !!
+      !!      First step: horizontal part of the operator. It is computed on
+      !!      ==========  pt as follows
+      !!      horizontal fluxes :
+      !!         zftu = e2u*e3u/e1u di[ pt ] - e2u*uslp dk[ mi(mk(pt)) ]
+      !!         zftv = e1v*e3v/e2v dj[ pt ] - e1v*vslp dk[ mj(mk(pt)) ]
+      !!      take the horizontal divergence of the fluxes (no divided by
+      !!      the volume element :
+      !!         plt  = di-1[ zftu ] +  dj-1[ zftv ]
+      !!
+      !!      Second step: vertical part of the operator. It is computed on
+      !!      ===========  pt as follows 
+      !!      vertical fluxes :
+      !!         zftw = e1t*e2t/e3w * (wslpi^2+wslpj^2)  dk-1[ pt ]
+      !!              -     e2t     *       wslpi        di[ mi(mk(pt)) ]
+      !!              -     e1t     *       wslpj        dj[ mj(mk(pt)) ]
+      !!      take the vertical divergence of the fluxes add it to the hori-
+      !!      zontal component, divide the result by the volume element and
+      !!      if kaht=1, multiply by the eddy diffusivity coefficient:
+      !!         plt  = aht / (e1t*e2t*e3t) { plt + dk[ zftw ] }
+      !!      else:
+      !!         plt  =  1  / (e1t*e2t*e3t) { plt + dk[ zftw ] }
+      !!
+      !! * Action :
+      !!      'key_trdtra' defined: the trend is saved for diagnostics.
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3), INTENT(in )                         ::   cdtype   ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in )                         ::   ktra     ! tracer index
+      REAL(wp)        , INTENT(in ), DIMENSION(jpi,jpj,jpk) ::   pt       ! before tracer field           (1st call)
+      !                                                                   ! laplacian of the tracer field (2nd call)
+      REAL(wp)        , INTENT(out), DIMENSION(jpi,jpj,jpk) ::   plt      ! harmonic operator applied to pt
+      INTEGER         , INTENT(in )                         ::   kaht     ! =1 multiply plt by aht
+      !                                                                   ! =2 no multiplication
+      !!
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      REAL(wp) ::   zabe1, zabe2, zmku, zmkv   ! temporary scalars
+      REAL(wp) ::   zbtr, ztah, ztav
+      REAL(wp) ::   zcof0, zcof1, zcof2
+      REAL(wp) ::   zcof3, zcof4
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zftu, zdkt, zdk1t         ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpk)     ::   zftw, zdit, zdjt, zdj1t   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zftv                      ! workspace (only v components for ptr)
+      !!----------------------------------------------------------------------
+
+      !                               ! ********** !   ! ===============
+      DO jk = 1, jpkm1                ! First step !   ! Horizontal slab
+         !                            ! ********** !   ! ===============
+
+         ! I.1 Vertical gradient of pt at level jk and jk+1
+         ! ------------------------------------------------
+         !     surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+         zdk1t(:,:) = ( pt(:,:,jk) - pt(:,:,jk+1) ) * tmask(:,:,jk+1)
+
+         IF( jk == 1 ) THEN
+            zdkt(:,:) = zdk1t(:,:)
+         ELSE
+            zdkt(:,:) = ( pt(:,:,jk-1) - pt(:,:,jk) ) * tmask(:,:,jk)
+         ENDIF
+
+
+         ! I.2 Horizontal fluxes
+         ! ---------------------
+
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zabe1 = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+               zabe2 = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+               zmku=1./MAX( tmask(ji+1,jj,jk  )+tmask(ji,jj,jk+1)   &
+                           +tmask(ji+1,jj,jk+1)+tmask(ji,jj,jk  ),1. )
+               zmkv=1./MAX( tmask(ji,jj+1,jk  )+tmask(ji,jj,jk+1)   &
+                           +tmask(ji,jj+1,jk+1)+tmask(ji,jj,jk  ),1. )
+
+               zcof1= -e2u(ji,jj) * uslp(ji,jj,jk) * zmku
+               zcof2= -e1v(ji,jj) * vslp(ji,jj,jk) * zmkv
+
+               zftu(ji,jj)= umask(ji,jj,jk) *   &
+                  (  zabe1 *( pt(ji+1,jj,jk) - pt(ji,jj,jk) )   &
+                   + zcof1 *( zdkt (ji+1,jj) + zdk1t(ji,jj)     &
+                             +zdk1t(ji+1,jj) + zdkt (ji,jj) )  )
+
+               zftv(ji,jj,jk)= vmask(ji,jj,jk) *   &
+                  (  zabe2 *( pt(ji,jj+1,jk) - pt(ji,jj,jk) )   &
+                   + zcof2 *( zdkt (ji,jj+1) + zdk1t(ji,jj)     &
+                             +zdk1t(ji,jj+1) + zdkt (ji,jj) )  )
+            END DO
+         END DO
+
+
+         ! I.3 Second derivative (divergence) (not divided by the volume)
+         ! ---------------------
+
+         DO jj = 2 , jpjm1
+            DO ji = 2 , jpim1
+               ztah = zftu(ji,jj) - zftu(ji-1,jj) + zftv(ji,jj,jk) - zftv(ji,jj-1,jk)
+               plt(ji,jj,jk) = ztah
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+ 
+      ! "Poleward" diffusive heat or salt transport
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( kaht == 2 ) .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_ldf(:) = ptr_vj( zftv(:,:,:) )
+         IF( ktra == jp_sal)   pst_ldf(:) = ptr_vj( zftv(:,:,:) )
+      ENDIF
+
+      !                             ! ************ !   ! ===============
+      DO jj = 2, jpjm1              !  Second step !   ! Horizontal slab
+         !                          ! ************ !   ! ===============
+
+         ! II.1 horizontal tracer gradient
+         ! -------------------------------
+
+         DO jk = 1, jpk
+            DO ji = 1, jpim1
+               zdit (ji,jk) = ( pt(ji+1,jj  ,jk) - pt(ji,jj  ,jk) ) * umask(ji,jj  ,jk)
+               zdjt (ji,jk) = ( pt(ji  ,jj+1,jk) - pt(ji,jj  ,jk) ) * vmask(ji,jj  ,jk)
+               zdj1t(ji,jk) = ( pt(ji  ,jj  ,jk) - pt(ji,jj-1,jk) ) * vmask(ji,jj-1,jk)
+            END DO
+         END DO
+
+
+         ! II.2 Vertical fluxes
+         ! --------------------
+
+         ! Surface and bottom vertical fluxes set to zero
+         zftw(:, 1 ) = 0.e0
+         zftw(:,jpk) = 0.e0
+
+         ! interior (2=<jk=<jpk-1)
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               zcof0 = e1t(ji,jj) * e2t(ji,jj) / fse3w(ji,jj,jk)   &
+                     * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)        &
+                        + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+
+               zmku =1./MAX(  umask(ji  ,jj,jk-1)+umask(ji-1,jj,jk)   &
+                             +umask(ji-1,jj,jk-1)+umask(ji  ,jj,jk), 1. )
+
+               zmkv =1./MAX(  vmask(ji,jj  ,jk-1)+vmask(ji,jj-1,jk)   &
+                             +vmask(ji,jj-1,jk-1)+vmask(ji,jj  ,jk), 1. )
+
+               zcof3 = - e2t(ji,jj) * wslpi (ji,jj,jk) * zmku
+               zcof4 = - e1t(ji,jj) * wslpj (ji,jj,jk) * zmkv
+
+               zftw(ji,jk) = tmask(ji,jj,jk) *   &
+                  (  zcof0 * ( pt  (ji,jj,jk-1) - pt  (ji,jj,jk) )   &
+                   + zcof3 * ( zdit (ji  ,jk-1) + zdit (ji-1,jk)     &
+                              +zdit (ji-1,jk-1) + zdit (ji  ,jk) )   &
+                   + zcof4 * ( zdjt (ji  ,jk-1) + zdj1t(ji  ,jk)     &
+                              +zdj1t(ji  ,jk-1) + zdjt (ji  ,jk) )  )
+            END DO
+         END DO
+
+
+         ! II.3 Divergence of vertical fluxes added to the horizontal divergence
+         ! ---------------------------------------------------------------------
+
+         IF( kaht == 1 ) THEN
+            ! multiply the laplacian by the eddy diffusivity coefficient
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ! eddy coef. divided by the volume element
+                  zbtr = fsahtt(ji,jj,jk) / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ! vertical divergence
+                  ztav = zftw(ji,jk) - zftw(ji,jk+1)
+                  ! harmonic operator applied to (pt,ps) and multiply by aht
+                  plt(ji,jj,jk) = ( plt(ji,jj,jk) + ztav ) * zbtr
+               END DO
+            END DO
+         ELSEIF( kaht == 2 ) THEN
+            ! second call, no multiplication
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ! inverse of the volume element
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ! vertical divergence
+                  ztav = zftw(ji,jk) - zftw(ji,jk+1)
+                  ! harmonic operator applied to (pt,ps) 
+                  plt(ji,jj,jk) = ( plt(ji,jj,jk) + ztav ) * zbtr
+               END DO
+            END DO
+         ELSE
+            IF(lwp) WRITE(numout,*) ' ldfght: kaht= 1 or 2, here =', kaht
+            IF(lwp) WRITE(numout,*) '         We stop'
+            STOP 'ldfght'
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+   END SUBROUTINE ldfght
+
+#else  
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             NO rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_ldf_bilapg( kt )               ! Dummy routine
+      WRITE(*,*) 'tra_ldf_bilapg: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_ldf_bilapg
+#endif
+
+   !!==============================================================================
+END MODULE traldf_bilapg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_iso.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 4536)
@@ -0,0 +1,273 @@
+MODULE traldf_iso
+   !!======================================================================
+   !!                   ***  MODULE  traldf_iso  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!======================================================================
+   !! History :  OPA  !  1994-08  (G. Madec, M. Imbard)
+   !!                 !  1997-05  (G. Madec)  split into traldf and trazdf
+   !!            NEMO !  2002-08  (G. Madec)  Free form, F90
+   !!            1.0  !  2005-11  (G. Madec)  merge traldf and trazdf :-)
+   !!            2.4  !  2008-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+#if   defined key_ldfslp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_ldfslp'               slope of the lateral diffusive direction
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_iso  : update the tracer trend with the horizontal 
+   !!                  component of a iso-neutral laplacian operator
+   !!                  and with the vertical part of
+   !!                  the isopycnal or geopotential s-coord. operator 
+   !!                  vector optimization, use k-j-i loops.
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE ldfslp          ! iso-neutral slopes
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_ldf_iso   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_ldf_iso( kt, cdtype, ktra, pgtu, pgtv,   &
+      &                                      ptb , pta   )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_iso  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer (t & s) diffusive 
+      !!      trend for a laplacian tensor (ezxcept the dz[ dz[.] ] term) and 
+      !!      add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The horizontal component of the lateral diffusive trends 
+      !!      is provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      1st part :  masked horizontal derivative of T & S ( di[ t ] )
+      !!      ========    with partial cell update if ln_zps=T.
+      !!
+      !!      2nd part :  horizontal fluxes of the lateral mixing operator
+      !!      ========    
+      !!         zftu = (aht+ahtb0) e2u*e3u/e1u di[ tb ]
+      !!               - aht       e2u*uslp    dk[ mi(mk(tb)) ]
+      !!         zftv = (aht+ahtb0) e1v*e3v/e2v dj[ tb ]
+      !!               - aht       e2u*vslp    dk[ mj(mk(tb)) ]
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ zftu ] +  dj-1[ zftv ]  }
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !!      3rd part: vertical trends of the lateral mixing operator
+      !!      ========  (excluding the vertical flux proportional to dk[t] )
+      !!      vertical fluxes associated with the rotated lateral mixing:
+      !!         zftw =-aht {  e2t*wslpi di[ mi(mk(tb)) ]
+      !!                     + e1t*wslpj dj[ mj(mk(tb)) ]  }
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) dk[ zftw ]
+      !!      Add this trend to the general trend (ta,sa):
+      !!         ta = ta + difft
+      !!
+      !! ** Action :   Update (ta,sa) arrays with the before rotated diffusion
+      !!            trend (except the dk[ dk[.] ] term)
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj)     ::   pgtu, pgtv      ! tracer gradient at pstep levels
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iku, ikv     ! temporary integer
+      REAL(wp) ::   zmsku, zabe1, zcof1, zcoef3   ! temporary scalars
+      REAL(wp) ::   zmskv, zabe2, zcof2, zcoef4   !    "         "
+      REAL(wp) ::   zcoef0, zbtr                       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdkt , zdk1t, zftu   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdit, zdjt, ztfw, zftv     ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_iso : rotated laplacian diffusion operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   I - masked horizontal derivative of T & S
+      !!----------------------------------------------------------------------
+!!bug ajout.... why?   ( 1,jpj,:) and (jpi,1,:) should be sufficient....
+      zdit (1,:,:) = 0.e0     ;     zdit (jpi,:,:) = 0.e0
+      zdjt (1,:,:) = 0.e0     ;     zdjt (jpi,:,:) = 0.e0
+!!end
+
+      ! Horizontal temperature and salinity gradient 
+      DO jk = 1, jpkm1
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zdit(ji,jj,jk) = ( ptb(ji+1,jj  ,jk) - ptb(ji,jj,jk) ) * umask(ji,jj,jk)
+               zdjt(ji,jj,jk) = ( ptb(ji  ,jj+1,jk) - ptb(ji,jj,jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( ln_zps ) THEN      ! partial steps correction at the last level 
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! last level
+               iku = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+               ikv = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+               zdit(ji,jj,iku) = pgtu(ji,jj) 
+               zdjt(ji,jj,ikv) = pgtv(ji,jj) 
+            END DO
+         END DO
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   II - horizontal trend of T & S (full)
+      !!----------------------------------------------------------------------
+      
+!CDIR PARALLEL DO PRIVATE( zdk1t, zftu ) 
+!$OMP PARALLEL DO PRIVATE( zdk1t, zftu )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! 1. Vertical tracer gradient at level jk and jk+1
+         ! ------------------------------------------------
+         ! surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+         zdk1t(:,:) = ( ptb(:,:,jk) - ptb(:,:,jk+1) ) * tmask(:,:,jk+1)
+
+         IF( jk == 1 ) THEN
+            zdkt(:,:) = zdk1t(:,:)
+         ELSE
+            zdkt(:,:) = ( ptb(:,:,jk-1) - ptb(:,:,jk) ) * tmask(:,:,jk)
+         ENDIF
+
+
+         ! 2. Horizontal fluxes
+         ! --------------------
+
+         DO jj = 1 , jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zabe1 = ( fsahtu(ji,jj,jk) + ahtb0 ) * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+               zabe2 = ( fsahtv(ji,jj,jk) + ahtb0 ) * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+               zmsku = 1. / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
+                  &             + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+               zmskv = 1. / MAX(  tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
+                  &             + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+               zcof1 = -fsahtu(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku
+               zcof2 = -fsahtv(ji,jj,jk) * e1v(ji,jj) * vslp(ji,jj,jk) * zmskv
+
+               zftu(ji,jj   ) = (  zabe1 * zdit(ji,jj,jk)   &
+                  &              + zcof1 * (  zdkt (ji+1,jj) + zdk1t(ji,jj)      &
+                  &                         + zdk1t(ji+1,jj) + zdkt (ji,jj)  )  ) * umask(ji,jj,jk)
+               zftv(ji,jj,jk) = (  zabe2 * zdjt(ji,jj,jk)   &
+                  &              + zcof2 * (  zdkt (ji,jj+1) + zdk1t(ji,jj)      &
+                  &                         + zdk1t(ji,jj+1) + zdkt (ji,jj)  )  ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+
+
+         ! II.4 Second derivative (divergence) and add to the general trend
+         ! ----------------------------------------------------------------
+         DO jj = 2 , jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr= 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               pta(ji,jj,jk) = pta(ji,jj,jk)   &
+                  &          + zbtr * ( zftu(ji,jj   ) - zftu(ji-1,jj   ) + zftv(ji,jj,jk) - zftv(ji,jj-1,jk)  )
+            END DO
+         END DO
+         !                                          ! ===============
+      END DO                                        !   End of slab  
+      !                                             ! ===============
+
+      ! "Poleward" diffusive heat or salt transports
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_ldf(:) = ptr_vj( zftv(:,:,:) )
+         IF( ktra == jp_sal)   pst_ldf(:) = ptr_vj( zftv(:,:,:) )
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !!   III - vertical trend of T & S (extra diagonal terms only)
+      !!----------------------------------------------------------------------
+
+      ! Local constant initialization
+      ! -----------------------------
+      ztfw(1,:,:) = 0.e0     ;     ztfw(jpi,:,:) = 0.e0
+
+
+      ! Vertical fluxes
+      ! ---------------
+
+      ! Surface and bottom vertical fluxes set to zero
+      ztfw(:,:, 1 ) = 0.e0      ;      ztfw(:,:,jpk) = 0.e0
+
+      ! interior (2=<jk=<jpk-1)
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zcoef0 = - fsahtw(ji,jj,jk) * tmask(ji,jj,jk)
+
+               zmsku = 1./MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)      &
+                  &            + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk), 1.  )
+
+               zmskv = 1./MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)      &
+                  &            + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk), 1.  )
+
+               zcoef3 = zcoef0 * e2t(ji,jj) * zmsku * wslpi (ji,jj,jk)
+               zcoef4 = zcoef0 * e1t(ji,jj) * zmskv * wslpj (ji,jj,jk)
+
+               ztfw(ji,jj,jk) = zcoef3 * (   zdit(ji  ,jj  ,jk-1) + zdit(ji-1,jj  ,jk)      &
+                  &                        + zdit(ji-1,jj  ,jk-1) + zdit(ji  ,jj  ,jk)  )   &
+                  &           + zcoef4 * (   zdjt(ji  ,jj  ,jk-1) + zdjt(ji  ,jj-1,jk)      &
+                  &                        + zdjt(ji  ,jj-1,jk-1) + zdjt(ji  ,jj  ,jk)  )
+            END DO
+         END DO
+      END DO
+
+
+      ! I.5 Divergence of vertical fluxes added to the general tracer trend
+      ! -------------------------------------------------------------------
+
+      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) )
+               pta(ji,jj,jk) = pta(ji,jj,jk) + (  ztfw(ji,jj,jk) - ztfw(ji,jj,jk+1)  ) * zbtr
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_ldf_iso
+
+#else
+   !!----------------------------------------------------------------------
+   !!   default option :   Dummy code   NO rotation of the diffusive tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE tra_ldf_iso( kt )               ! Empty routine
+      WRITE(*,*) 'tra_ldf_iso: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_ldf_iso
+#endif
+
+   !!==============================================================================
+END MODULE traldf_iso
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_lap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_lap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traldf_lap.F90	(revision 4536)
@@ -0,0 +1,147 @@
+MODULE traldf_lap
+   !!==============================================================================
+   !!                       ***  MODULE  traldf_lap  ***
+   !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+   !! History :  OPA  !  87-06  (P. Andrich, D. L Hostis)  Original code
+   !!                 !  91-11  (G. Madec)
+   !!                 !  95-11  (G. Madec)  suppress volumetric scale factors
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!            NEMO !  02-06  (G. Madec)  F90: Free form and module
+   !!            1.0  !  04-08  (C. Talandier) New trends organization
+   !!                 !  05-11  (G. Madec)  add zps case
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_ldf_lap  : update the tracer trend with the horizontal diffusion
+   !!                 using a iso-level harmonic (laplacien) operator.
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE in_out_manager  ! I/O manager
+   USE diaptr          ! poleward transport diagnostics
+   USE prtctl          ! Print control
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_ldf_lap  ! routine called by step.F90
+
+      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   e1ur, e2vr, btr2   ! scale factor coefficients
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE tra_ldf_lap( kt, cdtype, ktra, pgtu, pgtv,   &
+      &                                      ptb , pta   )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_ldf_lap  ***
+      !!                   
+      !! ** Purpose :   Compute the before horizontal tracer  diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   Second order diffusive operator evaluated using before
+      !!      fields (forward time scheme). The horizontal diffusive trends of 
+      !!      temperature (idem for salinity) is given by:
+      !!          difft = 1/(e1t*e2t*e3t) {  di-1[ aht e2u*e3u/e1u di(ptb) ]
+      !!                                   + dj-1[ aht e1v*e3v/e2v dj(ptb) ] }
+      !!     Note: key_zco defined, the e3t=e3u=e3v, the trend becomes:  
+      !!          difft = 1/(e1t*e2t) {  di-1[ aht e2u/e1u di(ptb) ]
+      !!                               + dj-1[ aht e1v/e2v dj(ptb) ] }
+      !!      Add this trend to the general tracer trend (pta):
+      !!          pta   = pta + difft
+      !!
+      !! ** Action  : - Update pta with the before iso-level harmonic mixing trend.
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                         ::   kt              ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                         ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER         , INTENT(in   )                         ::   ktra            ! tracer index
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj)     ::   pgtu, pgtv      ! tracer gradient at pstep levels
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb             ! before tracer field
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta             ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk     ! dummy loop indices
+      INTEGER  ::   iku, ikv       ! temporary integers
+      REAL(wp) ::   zabe1, zabe2   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztu, ztv   ! 3D workspace
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_ldf_lap : iso-level laplacian diffusion'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         e1ur(:,:) = e2u(:,:) / e1u(:,:)
+         e2vr(:,:) = e1v(:,:) / e2v(:,:)
+         btr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF
+
+      
+      !                                                  ! =============
+      DO jk = 1, jpkm1                                   ! Vertical slab
+         !                                               ! =============
+         ! 1. First derivative (gradient)
+         ! -------------------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * e1ur(ji,jj) * fse3u(ji,jj,jk)
+               zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * e2vr(ji,jj) * fse3v(ji,jj,jk)
+               ztu(ji,jj,jk) = zabe1 * ( ptb(ji+1,jj  ,jk) - ptb(ji,jj,jk) )
+               ztv(ji,jj,jk) = zabe2 * ( ptb(ji  ,jj+1,jk) - ptb(ji,jj,jk) )
+            END DO  
+         END DO  
+         IF( ln_zps ) THEN      ! set gradient at partial step level
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! last level
+                  iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  IF( iku == jk ) THEN
+                     zabe1 = fsahtu(ji,jj,iku) * umask(ji,jj,iku) * e1ur(ji,jj) * fse3u(ji,jj,iku)
+                     ztu(ji,jj,jk) = zabe1 * pgtu(ji,jj)
+                  ENDIF
+                  IF( ikv == jk ) THEN
+                     zabe2 = fsahtv(ji,jj,ikv) * vmask(ji,jj,ikv) * e2vr(ji,jj) * fse3v(ji,jj,ikv)
+                     ztv(ji,jj,jk) = zabe2 * pgtv(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+         ENDIF
+         
+         
+         ! 2. Second derivative (divergence) added to the general tracer trends
+         ! --------------------
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               pta(ji,jj,jk) = pta(ji,jj,jk) + btr2(ji,jj) / fse3t(ji,jj,jk)       &
+                  &                          * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)   &
+                  &                             + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+            END DO  
+         END DO  
+         !                                               ! =============
+      END DO                                             !  End of slab  
+      !                                                  ! =============
+
+
+      ! "Poleward" lateral diffusive heat or salt transport 
+      IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( ktra == jp_tem)   pht_ldf(:) = ptr_vj( ztv(:,:,:) )
+         IF( ktra == jp_sal)   pst_ldf(:) = ptr_vj( ztv(:,:,:) )
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pta, clinfo1=' ldf - lap : ', mask1=tmask, clinfo3=cdtype )
+      !
+   END SUBROUTINE tra_ldf_lap
+
+   !!==============================================================================
+END MODULE traldf_lap
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 4536)
@@ -0,0 +1,257 @@
+MODULE tranpc
+   !!==============================================================================
+   !!                       ***  MODULE  tranpc  ***
+   !! Ocean active tracers:  non penetrative convection scheme
+   !!==============================================================================
+   !! History :  1.0  !  90-09  (G. Madec)  Original code
+   !!                 !  91-11  (G. Madec)
+   !!                 !  92-06  (M. Imbard)  periodic conditions on t and s
+   !!                 !  93-03  (M. Guyon)  symetrical conditions 
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!                                       suppression of common work arrays
+   !!            8.5  !  02-06  (G. Madec)  free form F90
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_npc      : apply the non penetrative convection scheme
+   !!   tra_npc_init : initialization and control of the scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracer trends
+   USE trdmod_oce      ! ocean variables trends
+   USE eosbn2          ! equation of state (eos routine) 
+   USE lbclnk          ! lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_npc    ! routine called by step.F90
+
+   !!* Namelist namnpc: non penetrative convection algorithm
+   INTEGER ::   nnpc1 =   1   ! nnpc1   non penetrative convective scheme frequency
+   INTEGER ::   nnpc2 =  15   ! nnpc2   non penetrative convective scheme print frequency
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_npc( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tranpc  ***
+      !!
+      !! ** Purpose :   Non penetrative convective adjustment scheme. solve 
+      !!      the static instability of the water column (now, after the swap) 
+      !!      while conserving heat and salt contents.
+      !!
+      !! ** Method  :   The algorithm used converges in a maximium of jpk 
+      !!      iterations. instabilities are treated when the vertical density
+      !!      gradient is less than 1.e-5.
+      !!      l_trdtra=T: the trend associated with this algorithm is saved.
+      !!
+      !! ** Action  : - (tn,sn) after the application od the npc scheme
+      !!              - save the associated trends (ttrd,strd) ('key_trdtra')
+      !!
+      !! References : Madec, et al., 1991, JPO, 21, 9, 1349-1371.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :    ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :    ztrds => va   ! use va as 3D workspace   
+      !! 
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   inpcc        ! number of statically instable water column
+      INTEGER  ::   inpci        ! number of iteration for npc scheme
+      INTEGER  ::   jiter, jkdown, jkp        ! ???
+      INTEGER  ::   ikbot, ik, ikup, ikdown   ! ???
+      REAL(wp) ::   ze3tot, zta, zsa, zraua, ze3dwn
+      REAL(wp), DIMENSION(jpi,jpk)     ::   zwx, zwy, zwz   ! 2D arrays
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zrhop           ! 3D arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL tra_npc_init   ! Initialisation
+
+      IF( MOD( kt, nnpc1 ) == 0 ) THEN
+
+         inpcc = 0
+         inpci = 0
+
+         CALL eos( tn, sn, rhd, zrhop )         ! Potential density
+
+
+         IF( l_trdtra )   THEN                  ! Save tn and sn trends
+            ztrdt(:,:,:) = tn(:,:,:) 
+            ztrds(:,:,:) = sn(:,:,:) 
+         ENDIF
+
+         !                                                ! ===============
+         DO jj = 1, jpj                                   !  Vertical slab
+            !                                             ! ===============
+            !  Static instability pointer 
+            ! ----------------------------
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zwx(ji,jk) = ( zrhop(ji,jj,jk) - zrhop(ji,jj,jk+1) ) * tmask(ji,jj,jk+1)
+               END DO
+            END DO
+
+            ! 1.1 do not consider the boundary points
+
+            ! even if east-west cyclic b. c. do not considere ji=1 or jpi
+            DO jk = 1, jpkm1
+               zwx( 1 ,jk) = 0.e0
+               zwx(jpi,jk) = 0.e0
+            END DO
+            ! even if south-symmetric b. c. used, do not considere jj=1
+            IF( jj == 1 )   zwx(:,:) = 0.e0
+
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zwx(ji,jk) = 1.
+                  IF( zwx(ji,jk) < 1.e-5 ) zwx(ji,jk) = 0.e0
+               END DO
+            END DO
+
+            zwy(:,1) = 0.e0
+            DO ji = 1, jpi
+               DO jk = 1, jpkm1
+                  zwy(ji,1) = zwy(ji,1) + zwx(ji,jk)
+               END DO
+            END DO
+
+            zwz(1,1) = 0.e0
+            DO ji = 1, jpi
+               zwz(1,1) = zwz(1,1) + zwy(ji,1)
+            END DO
+
+            inpcc = inpcc + NINT( zwz(1,1) )
+
+
+            ! 2. Vertical mixing for each instable portion of the density profil
+            ! ------------------------------------------------------------------
+
+            IF( zwz(1,1) /= 0.e0 ) THEN         ! -->> the density profil is statically instable :
+               DO ji = 1, jpi
+                  IF( zwy(ji,1) /= 0.e0 ) THEN
+                     !
+                     ikbot = mbathy(ji,jj)      ! ikbot: ocean bottom level
+                     !
+                     DO jiter = 1, jpk          ! vertical iteration
+                        !
+                        ! search of ikup : the first static instability from the sea surface
+                        !
+                        ik = 0
+220                     CONTINUE
+                        ik = ik + 1
+                        IF( ik >= ikbot-1 ) GO TO 200
+                        zwx(ji,ik) = zrhop(ji,jj,ik) - zrhop(ji,jj,ik+1)
+                        IF( zwx(ji,ik) <= 0.e0 ) GO TO 220
+                        ikup = ik
+                        ! the density profil is instable below ikup
+                        ! ikdown : bottom of the instable portion of the density profil
+                        ! search of ikdown and vertical mixing from ikup to ikdown
+                        !
+                        ze3tot= fse3t(ji,jj,ikup)
+                        zta   = tn   (ji,jj,ikup)
+                        zsa   = sn   (ji,jj,ikup)
+                        zraua = zrhop(ji,jj,ikup)
+                        !
+                        DO jkdown = ikup+1, ikbot-1
+                           IF( zraua <= zrhop(ji,jj,jkdown) ) THEN
+                              ikdown = jkdown
+                              GO TO 240
+                           ENDIF
+                           ze3dwn =  fse3t(ji,jj,jkdown)
+                           ze3tot =  ze3tot + ze3dwn
+                           zta   = ( zta*(ze3tot-ze3dwn) + tn(ji,jj,jkdown)*ze3dwn )/ze3tot
+                           zsa   = ( zsa*(ze3tot-ze3dwn) + sn(ji,jj,jkdown)*ze3dwn )/ze3tot
+                           zraua = ( zraua*(ze3tot-ze3dwn) + zrhop(ji,jj,jkdown)*ze3dwn )/ze3tot
+                           inpci = inpci+1
+                        END DO
+                        ikdown = ikbot-1
+240                     CONTINUE
+                        !
+                        DO jkp = ikup, ikdown-1
+                           tn(ji,jj,jkp) = zta
+                           sn(ji,jj,jkp) = zsa
+                           zrhop(ji,jj,jkp) = zraua
+                        END DO
+                        IF (ikdown == ikbot-1 .AND. zraua >= zrhop(ji,jj,ikdown) ) THEN
+                           tn(ji,jj,ikdown) = zta
+                           sn(ji,jj,ikdown) = zsa
+                           zrhop(ji,jj,ikdown) = zraua
+                        ENDIF
+                     END DO
+                  ENDIF
+200               CONTINUE
+               END DO
+               ! <<-- no more static instability on slab jj
+            ENDIF
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+         ! 
+         IF( l_trdtra )   THEN         ! save the Non penetrative mixing trends for diagnostic
+            ztrdt(:,:,:) = tn(:,:,:) - ztrdt(:,:,:)
+            ztrds(:,:,:) = sn(:,:,:) - ztrds(:,:,:)
+            CALL trd_tra( kt, jp_tem, jpt_trd_ldf, 'TRA', ptrd3d=ztrdt)
+            CALL trd_tra( kt, jp_sal, jpt_trd_ldf, 'TRA', ptrd3d=ztrds)
+         ENDIF
+
+      
+         ! Lateral boundary conditions on ( tn, sn )   ( Unchanged sign)
+         ! ------------------------------============
+         CALL lbc_lnk( tn, 'T', 1. )
+         CALL lbc_lnk( sn, 'T', 1. )
+      
+
+         !  2. non penetrative convective scheme statistics
+         !  -----------------------------------------------
+         IF( nnpc2 /= 0 .AND. MOD( kt, nnpc2 ) == 0 ) THEN
+            IF(lwp) WRITE(numout,*)' kt=',kt, ' number of statically instable',   &
+               &                   ' water column : ',inpcc, ' number of iteration : ',inpci
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE tra_npc
+
+
+   SUBROUTINE tra_npc_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_npc_init  ***
+      !!                   
+      !! ** Purpose :   initializations of the non-penetrative adjustment scheme
+      !!----------------------------------------------------------------------
+      NAMELIST/namnpc/ nnpc1, nnpc2
+      !
+      REWIND( numnam )           ! Namelist namzdf : vertical diffusion
+      READ  ( numnam, namnpc )
+      !
+      IF(lwp) THEN               ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_npc_init : Non Penetrative Convection (npc) scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '       Namelist namnpc : set npc scheme parameters'
+         WRITE(numout,*) '          npc scheme frequency           nnpc1  = ', nnpc1
+         WRITE(numout,*) '          npc scheme print frequency     nnpc2  = ', nnpc2
+      ENDIF
+      !
+      IF ( nnpc1 == 0 ) THEN      ! Parameter controls
+          IF(lwp) WRITE(numout,cform_war)
+          IF(lwp) WRITE(numout,*) '             nnpc1 = ', nnpc1, ' is forced to 1'
+          nnpc1 = 1
+          nwarn = nwarn + 1
+      ENDIF
+      !
+   END SUBROUTINE tra_npc_init
+
+   !!======================================================================
+END MODULE tranpc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 4536)
@@ -0,0 +1,297 @@
+MODULE tranxt
+   !!======================================================================
+   !!                       ***  MODULE  tranxt  ***
+   !! Ocean active tracers:  time stepping on temperature and salinity
+   !!======================================================================
+   !! History :  7.0  !  91-11  (G. Madec)  Original code
+   !!                 !  93-03  (M. Guyon)  symetrical conditions
+   !!                 !  96-02  (G. Madec & M. Imbard)  opa release 8.0
+   !!            8.0  !  96-04  (A. Weaver)  Euler forward step
+   !!            8.2  !  99-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!                 !  02-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!                 !  05-04  (C. Deltel) Add Asselin trend in the ML budget
+   !!            9.0  !  06-02  (L. Debreu, C. Mazauric) Agrif implementation
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_nxt     : time stepping on temperature and salinity
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ???
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE obctra          ! open boundary condition (obc_tra routine)
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE prtctl          ! Print control
+   USE agrif_opa_update
+   USE agrif_opa_interp
+
+   USE ocesbc          ! ocean surface boundary condition
+   USE domvvl          ! variable volume
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE phycst
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC   tra_nxt   ! routine called by step.F90
+
+   REAL(wp) ::   vemp ! total amount of volume added or removed by E-P forcing
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_nxt( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tranxt  ***
+      !!
+      !! ** Purpose :   Compute the temperature and salinity fields at the 
+      !!      next time-step from their temporal trends and swap the fields.
+      !! 
+      !! ** Method  :   Apply lateral boundary conditions on (ua,va) through 
+      !!      call to lbc_lnk routine
+      !!      After t and s are compute using a leap-frog scheme environment:
+      !!         ta = tb + 2 rdttra(k) * ta
+      !!         sa = sb + 2 rdttra(k) * sa
+      !!      Compute and save in (ta,sa) an average over three time levels
+      !!      (before,now and after) of temperature and salinity which is
+      !!      used to compute rhd in eos routine and thus the hydrostatic 
+      !!      pressure gradient (ln_dynhpg_imp = T)
+      !!      Apply an Asselin time filter on now tracers (tn,sn) to avoid
+      !!      the divergence of two consecutive time-steps and swap tracer
+      !!      arrays to prepare the next time_step:
+      !!         (zt,zs) = (ta+2tn+tb,sa+2sn+sb)/4       (ln_dynhpg_imp = T)
+      !!         (zt,zs) = (0,0)                            (default option)
+      !!         (tb,sb) = (tn,vn) + atfp [ (tb,sb) + (ta,sa) - 2 (tn,sn) ]
+      !!         (tn,sn) = (ta,sa) 
+      !!         (ta,sa) = (zt,zs)  (NB: reset to 0 after use in eos.F)
+      !!
+      !! ** Action  : - update (tb,sb) and (tn,sn) 
+      !!              - (ta,sa) time averaged (t,s)      (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :    ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :    ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk    ! dummy loop indices
+      REAL(wp) ::   zt, zs, zssh1 ! temporary scalars
+      REAL(wp) ::   zfact         ! temporary scalar
+      !! Variable volume
+      REAL(wp), DIMENSION(jpi,jpj) ::   zssh                         ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zfse3tb, zfse3tn, zfse3ta  ! 3D workspace
+
+      !!----------------------------------------------------------------------
+
+      !! Explicit physics with thickness weighted updates
+      IF( lk_vvl .AND. ln_zdfexp ) THEN
+
+         ! Scale factors at before and after time step
+         ! -------------------------------------------
+         CALL dom_vvl_sf( sshb, 'T', zfse3tb ) ;    CALL dom_vvl_sf( ssha, 'T', zfse3ta )
+
+         ! Asselin filtered scale factor at now time step
+         ! ----------------------------------------------
+         IF( (neuler == 0 .AND. kt == nit000) .OR. lk_dynspg_ts ) THEN
+            CALL dom_vvl_sf_ini( 'T', zfse3tn ) 
+         ELSE
+            zssh(:,:) = atfp * ( sshb(:,:) + ssha(:,:) ) + atfp1 * sshn(:,:)
+            CALL dom_vvl_sf( zssh, 'T', zfse3tn ) 
+         ENDIF
+
+         ! Thickness weighting
+         ! -------------------
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ta(ji,jj,jk) = ta(ji,jj,jk) * fse3t(ji,jj,jk)
+                  sa(ji,jj,jk) = sa(ji,jj,jk) * fse3t(ji,jj,jk)
+
+                  tn(ji,jj,jk) = tn(ji,jj,jk) * fse3t(ji,jj,jk)
+                  sn(ji,jj,jk) = sn(ji,jj,jk) * fse3t(ji,jj,jk)
+
+                  tb(ji,jj,jk) = tb(ji,jj,jk) * zfse3tb(ji,jj,jk)
+                  sb(ji,jj,jk) = sb(ji,jj,jk) * zfse3tb(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,jpk) = 0.e0
+         ztrds(:,:,jpk) = 0.e0
+      ENDIF
+
+      ! 0. Lateral boundary conditions on ( ta, sa )   (T-point, unchanged sign)
+      ! ---------------------------------============
+      CALL lbc_lnk( ta, 'T', 1. )   
+      CALL lbc_lnk( sa, 'T', 1. )
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         ! 1. Leap-frog scheme (only in explicit case, otherwise the 
+         ! -------------------  time stepping is already done in trazdf)
+         IF( ln_zdfexp ) THEN
+            zfact = 2. * rdttra(jk)
+            IF( neuler == 0 .AND. kt == nit000 )   zfact = rdttra(jk)
+            ta(:,:,jk) = ( tb(:,:,jk) + zfact * ta(:,:,jk) ) * tmask(:,:,jk)
+            sa(:,:,jk) = ( sb(:,:,jk) + zfact * sa(:,:,jk) ) * tmask(:,:,jk)
+            IF(l_trdtra)   CALL ctl_stop( 'tranxt: Asselin ML trend not yet accounted for.' )
+         ENDIF
+
+#if defined key_obc
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update tracers on open boundaries.
+      CALL obc_tra( kt )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+#endif
+#if defined key_agrif
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update tracers on open boundaries.
+      CALL Agrif_tra( kt )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+#endif
+         ! 2. Time filter and swap of arrays
+         ! ---------------------------------
+
+         IF( ln_dynhpg_imp ) THEN                       ! semi-implicite hpg
+            IF( neuler == 0 .AND. kt == nit000 ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zt = ( ta(ji,jj,jk) + 2. * tn(ji,jj,jk) + tb(ji,jj,jk) ) * 0.25
+                     zs = ( sa(ji,jj,jk) + 2. * sn(ji,jj,jk) + sb(ji,jj,jk) ) * 0.25
+                     tb(ji,jj,jk) = tn(ji,jj,jk)
+                     sb(ji,jj,jk) = sn(ji,jj,jk)
+                     tn(ji,jj,jk) = ta(ji,jj,jk)
+                     sn(ji,jj,jk) = sa(ji,jj,jk)
+                     ta(ji,jj,jk) = zt
+                     sa(ji,jj,jk) = zs
+                  END DO
+               END DO
+               IF( l_trdtra ) THEN
+                  ztrdt(:,:,jk) = 0.e0
+                  ztrds(:,:,jk) = 0.e0
+               END IF
+            ELSE
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zt = ( ta(ji,jj,jk) + 2. * tn(ji,jj,jk) + tb(ji,jj,jk) ) * 0.25
+                     zs = ( sa(ji,jj,jk) + 2. * sn(ji,jj,jk) + sb(ji,jj,jk) ) * 0.25
+                     tb(ji,jj,jk) = atfp  * ( tb(ji,jj,jk) + ta(ji,jj,jk) ) + atfp1 * tn(ji,jj,jk)
+                     sb(ji,jj,jk) = atfp  * ( sb(ji,jj,jk) + sa(ji,jj,jk) ) + atfp1 * sn(ji,jj,jk)
+                     IF( l_trdtra ) THEN ! ChD ceci est a optimiser, mais ca marche
+                        ztrdt(ji,jj,jk) = tb(ji,jj,jk) - tn(ji,jj,jk)
+                        ztrds(ji,jj,jk) = sb(ji,jj,jk) - sn(ji,jj,jk)
+                     END IF
+                     tn(ji,jj,jk) = ta(ji,jj,jk)
+                     sn(ji,jj,jk) = sa(ji,jj,jk)
+                     ta(ji,jj,jk) = zt
+                     sa(ji,jj,jk) = zs
+                  END DO
+               END DO
+            ENDIF
+         ELSE                                          ! Default case
+            IF( neuler == 0 .AND. kt == nit000 ) THEN
+               IF( (lk_vvl .AND. ln_zdfexp) ) THEN                      ! Varying levels
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        zssh1 = tmask(ji,jj,jk) / fse3t(ji,jj,jk)
+                        tb(ji,jj,jk) = tn(ji,jj,jk) * zssh1 * tmask(ji,jj,jk)
+                        sb(ji,jj,jk) = sn(ji,jj,jk) * zssh1 * tmask(ji,jj,jk)
+                        zssh1 = tmask(ji,jj,jk) / zfse3ta(ji,jj,jk)
+                        tn(ji,jj,jk) = ta(ji,jj,jk) * zssh1 * tmask(ji,jj,jk)
+                        sn(ji,jj,jk) = sa(ji,jj,jk) * zssh1 * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               ELSE                                                     ! Fixed levels
+                 DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        tb(ji,jj,jk) = tn(ji,jj,jk)
+                        sb(ji,jj,jk) = sn(ji,jj,jk)
+                        tn(ji,jj,jk) = ta(ji,jj,jk)
+                        sn(ji,jj,jk) = sa(ji,jj,jk)
+                     END DO
+                  END DO
+               ENDIF
+               IF( l_trdtra ) THEN
+                  ztrdt(:,:,jk) = 0.e0
+                  ztrds(:,:,jk) = 0.e0
+               END IF
+            ELSE
+               IF( l_trdtra ) THEN
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        ztrdt(ji,jj,jk) = atfp * ( tb(ji,jj,jk) - 2*tn(ji,jj,jk) + ta(ji,jj,jk) )
+                        ztrds(ji,jj,jk) = atfp * ( sb(ji,jj,jk) - 2*sn(ji,jj,jk) + sa(ji,jj,jk) )
+                     END DO
+                  END DO
+               END IF
+               IF( (lk_vvl .AND. ln_zdfexp) ) THEN                      ! Varying levels
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        zssh1 = tmask(ji,jj,jk) / zfse3tn(ji,jj,jk)
+                        tb(ji,jj,jk) = ( atfp  * ( tb(ji,jj,jk) + ta(ji,jj,jk) ) &
+                          &            + atfp1 * tn(ji,jj,jk) ) * zssh1
+                        sb(ji,jj,jk) = ( atfp  * ( sb(ji,jj,jk) + sa(ji,jj,jk) ) &
+                          &            + atfp1 * sn(ji,jj,jk) ) * zssh1
+                        zssh1 = tmask(ji,jj,1) / zfse3ta(ji,jj,jk)
+                        tn(ji,jj,jk) = ta(ji,jj,jk) * zssh1
+                        sn(ji,jj,jk) = sa(ji,jj,jk) * zssh1
+                     END DO
+                  END DO
+               ELSE                                                     ! Fixed levels or first varying level
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        tb(ji,jj,jk) = atfp  * ( tb(ji,jj,jk) + ta(ji,jj,jk) ) + atfp1 * tn(ji,jj,jk)
+                        sb(ji,jj,jk) = atfp  * ( sb(ji,jj,jk) + sa(ji,jj,jk) ) + atfp1 * sn(ji,jj,jk)
+                        tn(ji,jj,jk) = ta(ji,jj,jk)
+                        sn(ji,jj,jk) = sa(ji,jj,jk)
+                     END DO
+                  END DO
+               ENDIF
+            ENDIF
+         ENDIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF( l_trdtra )   THEN                      ! trend associated with the Asselin filter
+         ztrdt(:,:,:) = ztrdt(:,:,:) / ( 2.*rdt )
+         ztrds(:,:,:) = ztrds(:,:,:) / ( 2.*rdt )         
+         CALL trd_tra( kt, jp_tem, jpt_trd_atf, 'TRA', ptrd3d=ztrdt)
+         CALL trd_tra( kt, jp_sal, jpt_trd_atf, 'TRA', ptrd3d=ztrds)
+      ENDIF
+
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tn, clinfo1=' nxt  - Tn: ', mask1=tmask,   &
+         &                       tab3d_2=sn, clinfo2=       ' Sn: ', mask2=tmask )
+#if defined key_agrif
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Tra( kt )
+#endif      
+      !
+   END SUBROUTINE tra_nxt
+
+   !!======================================================================
+END MODULE tranxt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4536)
@@ -0,0 +1,279 @@
+MODULE traqsr
+   !!======================================================================
+   !!                       ***  MODULE  traqsr  ***
+   !! Ocean physics: solar radiation penetration in the top ocean levels
+   !!======================================================================
+   !! History :  OPA  !  90-10  (B. Blanke)  Original code
+   !!            7.0  !  91-11  (G. Madec)
+   !!                 !  96-01  (G. Madec)  s-coordinates
+   !!  NEMO      1.0  !  02-06  (G. Madec)  F90: Free form and module
+   !!             -   !  05-11  (G. Madec) zco, zps, sco coordinate
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_qsr      : trend due to the solar radiation penetration
+   !!   tra_qsr_init : solar radiation penetration initialization
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE trc_oce         ! share SMS/Ocean variables
+   USE ocesbc          ! thermohaline fluxes
+   USE phycst          ! physical constants
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_qsr      ! routine called by step.F90 (ln_traqsr=T)
+   PUBLIC   tra_qsr_init ! routine called by opa.F90
+
+   !!* Namelist namqsr: penetrative solar radiation
+   LOGICAL , PUBLIC ::   ln_traqsr = .TRUE.   !: qsr flag (Default=T)
+   REAL(wp), PUBLIC ::   rabs = 0.58_wp       ! fraction associated with xsi1
+   REAL(wp), PUBLIC ::   xsi1 = 0.35_wp       ! first depth of extinction 
+   REAL(wp), PUBLIC ::   xsi2 = 23.0_wp       ! second depth of extinction (default values: water type Ib)
+   LOGICAL , PUBLIC ::   ln_qsr_sms = .false. ! flag to use or not the biological fluxes for light 
+   
+   INTEGER ::   nksr   ! number of levels
+   REAL(wp), DIMENSION(jpk) ::   gdsr   ! profile of the solar flux penetration
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_qsr( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr  ***
+      !!
+      !! ** Purpose :   Compute the temperature trend due to the solar radiation
+      !!      penetration and add it to the general temperature trend.
+      !!
+      !! ** Method  : The profile of the solar radiation within the ocean is
+      !!      defined through two penetration length scale (xsr1,xsr2) and a 
+      !!      ratio (rabs) as :
+      !!         I(k) = Qsr*( rabs*EXP(z(k)/xsr1) + (1.-rabs)*EXP(z(k)/xsr2) )
+      !!         The temperature trend associated with the solar radiation
+      !!      penetration is given by :
+      !!            zta = 1/e3t dk[ I ] / (rau0*Cp)
+      !!         At the bottom, boudary condition for the radiation is no flux :
+      !!      all heat which has not been absorbed in the above levels is put
+      !!      in the last ocean level.
+      !!         In z-coordinate case, the computation is only done down to the
+      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients 
+      !!      used for the computation are calculated one for once as they
+      !!      depends on k only.
+      !!
+      !! ** Action  : - update ta with the penetrative solar radiation trend
+      !!              - save the trend in ttrd ('key_trdtra')
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indexes
+      REAL(wp) ::   zc0 , zta         ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_qsr : penetration of the surface solar radiation'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+         CALL tra_qsr_init
+      ENDIF
+
+      IF( l_trdtra ) ztrdt(:,:,:) = ta(:,:,:)      ! Save ta and sa trends
+
+      ! ---------------------------------------------- !
+      !  Biological fluxes  : all vertical coordinate  !
+      ! ---------------------------------------------- !
+      IF( lk_qsr_sms .AND. ln_qsr_sms ) THEN      
+         !                                                   ! ===============
+         DO jk = 1, jpkm1                                    ! Horizontal slab
+            !                                                ! ===============
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zc0 = ro0cpr  / fse3t(ji,jj,jk)         ! compute the qsr trend
+                  zta = zc0 * ( etot3(ji,jj,jk  ) * tmask(ji,jj,jk)     &
+                     &        - etot3(ji,jj,jk+1) * tmask(ji,jj,jk+1) )
+                  ta(ji,jj,jk) = ta(ji,jj,jk) + zta       ! add qsr trend to the temperature trend
+               END DO
+            END DO
+            !                                                ! ===============
+         END DO                                              !   End of slab
+         !                                                   ! ===============
+
+      ! ---------------------------------------------- !
+      !  Ocean alone :
+      ! ---------------------------------------------- !
+      ELSE
+         !                                                ! =================== !
+         IF( ln_sco ) THEN                                !    s-coordinate     !
+            !                                             ! =================== !
+            DO jk = 1, jpkm1
+               ta(:,:,jk) = ta(:,:,jk) + etot3(:,:,jk) * qsr(:,:)
+            END DO
+         ENDIF
+         !                                                ! =================== !
+         IF( ln_zps ) THEN                                !    partial steps    !
+            !                                             ! =================== !
+            DO jk = 1, nksr
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ! qsr trend from gdsr
+                     zc0 = qsr(ji,jj) / fse3t(ji,jj,jk)
+                     zta = zc0 * ( gdsr(jk) * tmask(ji,jj,jk) - gdsr(jk+1) * tmask(ji,jj,jk+1) )
+                     ! add qsr trend to the temperature trend
+                     ta(ji,jj,jk) = ta(ji,jj,jk) + zta
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         !                                                ! =================== !
+         IF( ln_zco ) THEN                                !     z-coordinate    !
+            !                                             ! =================== !
+            DO jk = 1, nksr
+               zc0 = 1. / e3t_0(jk)
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ! qsr trend
+                     zta = qsr(ji,jj) * zc0 * ( gdsr(jk)*tmask(ji,jj,jk) - gdsr(jk+1)*tmask(ji,jj,jk+1) )
+                     ! add qsr trend to the temperature trend
+                     ta(ji,jj,jk) = ta(ji,jj,jk) + zta      
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         !
+      ENDIF
+
+      IF( l_trdtra )   THEN                      ! qsr tracer trend saved for diagnostics
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         CALL trd_tra( kt, jp_tem, jpt_trd_qsr, 'TRA', ptrd3d=ztrdt)
+      ENDIF
+      !                       ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' qsr  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
+      !
+   END SUBROUTINE tra_qsr
+
+
+   SUBROUTINE tra_qsr_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_qsr_init  ***
+      !!
+      !! ** Purpose :   Initialization for the penetrative solar radiation
+      !!
+      !! ** Method  :   The profile of solar radiation within the ocean is set
+      !!      from two length scale of penetration (xsr1,xsr2) and a ratio
+      !!      (rabs). These parameters are read in the namqsr namelist. The
+      !!      default values correspond to clear water (type I in Jerlov' 
+      !!      (1968) classification.
+      !!         called by tra_qsr at the first timestep (nit000)
+      !!
+      !! ** Action  : - initialize xsr1, xsr2 and rabs
+      !!
+      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop index
+      INTEGER  ::   indic        ! temporary integer
+      REAL(wp) ::   zc0 , zc1 , zc2    ! temporary scalars
+      REAL(wp) ::   zcst, zdp1, zdp2   !    "         "
+
+      NAMELIST/namqsr/ ln_traqsr, rabs, xsi1, xsi2, ln_qsr_sms
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )           ! Read Namelist namqsr : ratio and length of penetration
+      READ   ( numnam, namqsr )
+
+      IF( ln_traqsr  ) THEN       ! Parameter control and print
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'tra_qsr_init : penetration of the surface solar radiation'
+            WRITE(numout,*) '~~~~~~~~~~~~'
+            WRITE(numout,*) '    Namelist namqsr : set the parameter of penetration'
+            WRITE(numout,*) '        fraction associated with xsi     rabs        = ',rabs
+            WRITE(numout,*) '        first depth of extinction        xsi1        = ',xsi1
+            WRITE(numout,*) '        second depth of extinction       xsi2        = ',xsi2
+            IF( lk_qsr_sms ) THEN
+               WRITE(numout,*) '     Biological fluxes for light(Y/N) ln_qsr_sms  = ',ln_qsr_sms
+            ENDIF
+         ENDIF
+      ELSE
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'tra_qsr_init : NO solar flux penetration'
+            WRITE(numout,*) '~~~~~~~~~~~~'
+         ENDIF
+      ENDIF
+
+      IF( rabs > 1.e0 .OR. rabs < 0.e0 .OR. xsi1 < 0.e0 .OR. xsi2 < 0.e0 ) &
+         CALL ctl_stop( '             0<rabs<1, 0<xsi1, or 0<xsi2 not satisfied' )
+
+      !                           ! Initialization of gdsr
+      IF( ln_zco .OR. ln_zps ) THEN
+         !
+         ! z-coordinate with or without partial step : same w-level everywhere inside the ocean
+         gdsr(:) = 0.e0
+         DO jk = 1, jpk
+            zdp1 = -gdepw_0(jk)
+            gdsr(jk) = ro0cpr * (  rabs  * EXP( zdp1/xsi1 ) + (1.-rabs) * EXP( zdp1/xsi2 )  )
+            IF ( gdsr(jk) <= 1.e-10 ) EXIT
+         END DO
+         indic = 0
+         DO jk = 1, jpk
+            IF( gdsr(jk) <= 1.e-15 .AND. indic == 0 ) THEN
+               gdsr(jk) = 0.e0
+               nksr = jk
+               indic = 1
+            ENDIF
+         END DO
+         nksr = MIN( nksr, jpkm1 )
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '        - z-coordinate, level max of computation =', nksr
+            WRITE(numout,*) '             profile of coef. of penetration:'
+            WRITE(numout,"('              ',7e11.2)") ( gdsr(jk), jk = 1, nksr )
+            WRITE(numout,*)
+         ENDIF
+         ! Initialisation of Biological fluxes for light here because
+         ! the optical biological model is call after the dynamical one
+         IF( lk_qsr_sms .AND. ln_qsr_sms ) THEN
+            DO jk = 1, jpkm1
+               zcst = gdsr(jk) / ro0cpr
+               etot3(:,:,jk) = qsr(:,:) * zcst * tmask(:,:,jk) 
+            END DO
+         ENDIF
+         !
+      ENDIF
+
+      ! Initialisation of etot3 (s-coordinate)
+      ! -----------------------
+      IF( ln_sco ) THEN
+         etot3(:,:,jpk) = 0.e0
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zdp1 = -fsdepw(ji,jj,jk  )
+                  zdp2 = -fsdepw(ji,jj,jk+1)
+                  zc0  = ro0cpr / fse3t(ji,jj,jk)
+                  zc1  =   (  rabs * EXP(zdp1/xsi1) + (1.-rabs) * EXP(zdp1/xsi2)  )
+                  zc2  = - (  rabs * EXP(zdp2/xsi1) + (1.-rabs) * EXP(zdp2/xsi2)  )
+                  etot3(ji,jj,jk)  = zc0 * (  zc1 * tmask(ji,jj,jk) + zc2 * tmask(ji,jj,jk+1)  )
+               END DO
+            END DO
+         END DO 
+      ENDIF
+      !
+   END SUBROUTINE tra_qsr_init
+
+   !!======================================================================
+END MODULE traqsr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 4536)
@@ -0,0 +1,158 @@
+MODULE trasbc
+   !!======================================================================
+   !!                       ***  MODULE  trasbc  ***
+   !! Ocean active tracers:  surface boundary condition
+   !!======================================================================
+   !! History :  OPA  !  98-10  (G. Madec, G. Roullet, M. Imbard)  Original code
+   !!            8.2  !  01-02  (D. Ludicone)  sea ice and free surface
+   !!   NEMO     1.0  !  02-06  (G. Madec)  F90: Free form and module
+   !!            2.4  !  08-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_sbc      : update the tracer trend at ocean surface
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space domain variables
+   USE ocesbc          ! surface thermohaline fluxes
+   USE phycst          ! physical constant
+   USE traqsr          ! solar radiation penetration
+   USE trdmod          ! ocean trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_sbc    ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_sbc ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_sbc  ***
+      !!                   
+      !! ** Purpose :   Compute the tracer surface boundary condition trend of
+      !!      (flux through the interface, concentration/dilution effect)
+      !!      and add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      Following Roullet and Madec (2000), the air-sea flux can be divided 
+      !!      into three effects: (1) Fext, external forcing; 
+      !!      (2) Fwi, concentration/dilution effect due to water exchanged 
+      !!         at the surface by evaporation, precipitations and runoff (E-P-R); 
+      !!      (3) Fwe, tracer carried with the water that is exchanged. 
+      !!
+      !!      Fext, flux through the air-sea interface for temperature and salt: 
+      !!            - temperature : heat flux q (w/m2). If penetrative solar
+      !!         radiation q is only the non solar part of the heat flux, the
+      !!         solar part is added in traqsr.F routine.
+      !!            ta = ta + q /(rau0 rcp e3t)  for k=1
+      !!            - salinity    : no salt flux
+      !!
+      !!      The formulation for Fwb and Fwi vary according to the free 
+      !!      surface formulation (linear or variable volume). 
+      !!      * Linear free surface
+      !!            The surface freshwater flux modifies the ocean volume
+      !!         and thus the concentration of a tracer and the temperature.
+      !!         First order of the effect of surface freshwater exchange 
+      !!         for salinity, it can be neglected on temperature (especially
+      !!         as the temperature of precipitations and runoffs is usually
+      !!         unknown).
+      !!            - temperature : we assume that the temperature of both
+      !!         precipitations and runoffs is equal to the SST, thus there
+      !!         is no additional flux since in this case, the concentration
+      !!         dilution effect is balanced by the net heat flux associated
+      !!         to the freshwater exchange (Fwe+Fwi=0):
+      !!            (Tp P - Te E) + SST (P-E) = 0 when Tp=Te=SST
+      !!            - salinity    : evaporation, precipitation and runoff
+      !!         water has a zero salinity (Fwe=0), thus only Fwi remains:
+      !!            sa = sa + emp * sn / e3t   for k=1
+      !!         where emp, the surface freshwater budget (evaporation minus
+      !!         precipitation minus runoff) given in kg/m2/s is divided
+      !!         by 1000 kg/m3 (density of plain water) to obtain m/s.    
+      !!         Note: even though Fwe does not appear explicitly for 
+      !!         temperature in this routine, the heat carried by the water
+      !!         exchanged through the surface is part of the total heat flux
+      !!         forcing and must be taken into account in the global heat
+      !!         balance).
+      !!      * nonlinear free surface (variable volume, lk_vvl)
+      !!         contrary to the linear free surface case, Fwi is properly 
+      !!         taken into account by using the true layer thicknesses to       
+      !!         calculate tracer content and advection. There is no need to 
+      !!         deal with it in this routine.
+      !!           - temperature: Fwe=SST (P-E+R) is added to Fext.
+      !!           - salinity:  Fwe = 0, there is no surface flux of salt.
+      !!
+      !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
+      !!                with the tracer surface boundary condition 
+      !!              - save the trend it in ttrd ('key_trdtra')
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      REAL(wp) ::   zta, zsa, zsrau, zse3t   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt, ztrds   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_sbc : TRAcer Surface Boundary Condition'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      zsrau = 1. / rauw             ! initialization
+#if defined key_zco
+      zse3t = 1. / e3t_0(1)
+#endif
+
+      IF( l_trdtra ) THEN           ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
+      ENDIF
+
+      IF( .NOT.ln_traqsr )   qsr(:,:) = 0.e0   ! no solar radiation penetration
+
+      ! Concentration dillution effect on (t,s)
+      DO jj = 2, jpj
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+            zse3t = 1. / fse3t(ji,jj,1)
+#endif
+            IF( lk_vvl) THEN
+               zta = ro0cpr * ( qt(ji,jj) - qsr(ji,jj) ) * zse3t &   ! temperature : heat flux
+                &    - emp(ji,jj) * zsrau * tn(ji,jj,1)  * zse3t     ! & cooling/heating effet of EMP flux
+               zsa = 0.e0                                            ! No salinity concent./dilut. effect
+            ELSE
+               zta = ro0cpr * ( qt(ji,jj) - qsr(ji,jj) ) * zse3t     ! temperature : heat flux
+               zsa = emps(ji,jj) * zsrau * sn(ji,jj,1)   * zse3t     ! salinity :  concent./dilut. effect
+            ENDIF
+            ta(ji,jj,1) = ta(ji,jj,1) + zta                          ! add the trend to the general tracer trend
+            sa(ji,jj,1) = sa(ji,jj,1) + zsa
+         END DO
+      END DO
+
+      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_tra( kt, jp_tem, jpt_trd_qns, 'TRA', ptrd3d=ztrdt)
+         CALL trd_tra( kt, jp_sal, jpt_trd_qns, 'TRA', ptrd3d=ztrds)
+      ENDIF
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' sbc  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
+   END SUBROUTINE tra_sbc
+
+   !!======================================================================
+END MODULE trasbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 4536)
@@ -0,0 +1,173 @@
+MODULE trazdf
+   !!==============================================================================
+   !!                 ***  MODULE  trazdf  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend
+   !!==============================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_zdf      : Update the tracer trend with the vertical diffusion
+   !!       zdf_ctl  : ???
+   !!----------------------------------------------------------------------
+   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          ! vertical mixing: double diffusion
+
+   USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
+   USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
+
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   USE phycst
+   USE dynspg_oce
+   USE ocesbc          ! ocean surface boundary condition
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_zdf   !  routine called by step.F90
+
+   INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
+      !                                ! defined from ln_zdf...  namlist logicals)
+
+   REAL(wp), DIMENSION(jpk) ::   r2dt  ! vertical profile time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE tra_zdf( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf  ***
+      !!
+      !! ** Purpose :   compute the vertical ocean tracer physics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      INTEGER  ::   jk                   ! Dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt, ztrds   ! 3D workspace
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL zdf_ctl          ! initialisation & control of options
+
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
+         r2dt(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
+         r2dt(:) = 2. * rdttra(:)                      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      IF( l_trdtra )   THEN                      ! temporary save of ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:)
+      ENDIF
+
+      IF( lk_vvl )   CALL dom_vvl_ssh( kt )      ! compute ssha field
+
+      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
+      CASE ( -1 )                                       ! esopa: test all possibility with control print
+         CALL tra_zdf_exp    ( kt, r2dt,   avt       , tb, ta )   ! temperature
+         CALL tra_zdf_exp    ( kt, r2dt, fsavs(:,:,:), tb, ta )   ! salinity
+         CALL prt_ctl( tab3d_1=ta, clinfo1=' zdf0 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_zdf_imp( kt, r2dt, 'TRA' )                      ! T & S zdf trends
+
+      CASE ( 0 )                                       ! explicit scheme
+         CALL tra_zdf_exp    ( kt, r2dt,   avt       , tb, ta )   ! temperature
+         CALL tra_zdf_exp    ( kt, r2dt, fsavs(:,:,:), tb, ta )   ! salinity
+         IF( l_trdtra )   THEN                                    ! zdf trends diagnostics
+            ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+            ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+            CALL trd_tra( kt, jp_tem, jpt_trd_ldf, 'TRA', ptrd3d=ztrdt)
+            CALL trd_tra( kt, jp_sal, jpt_trd_ldf, 'TRA', ptrd3d=ztrds)
+         ENDIF
+
+      CASE ( 1 )                                       ! implicit scheme
+         CALL tra_zdf_imp( kt, r2dt, 'TRA' )                      ! T & S zdf trends
+         IF( l_trdtra )   THEN                                    ! zdf trends diagnostics
+            DO jk = 1, jpkm1
+               ztrdt(:,:,jk) = ( ( ta(:,:,jk) - tb(:,:,jk) ) / r2dt(jk) ) - ztrdt(:,:,jk)
+               ztrds(:,:,jk) = ( ( sa(:,:,jk) - sb(:,:,jk) ) / r2dt(jk) ) - ztrds(:,:,jk)
+            END DO
+            CALL trd_tra( kt, jp_tem, jpt_trd_zdf, 'TRA', ptrd3d=ztrdt)
+            CALL trd_tra( kt, jp_sal, jpt_trd_zdf, 'TRA', ptrd3d=ztrds)
+         ENDIF
+
+      END SELECT
+
+      !                                                ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' zdf  - Ta: ', mask1=tmask,               &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
+   END SUBROUTINE tra_zdf
+
+
+   SUBROUTINE zdf_ctl
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdf_ctl  ***
+      !!
+      !! ** Purpose :   Choose the vertical mixing scheme
+      !!
+      !! ** Method  :   Set nzdf from ln_zdfexp and 'key_mpp_omp'.
+      !!      nzdf = 0   explicit (time-splitting) scheme (ln_zdfexp=T)
+      !!           = 1   implicit (euler backward) scheme (ln_zdfexp=F)
+      !!           = 2   implicit (euler backward) scheme with j-k-i loops
+      !!                 (ln_zdfexp=T and 'key_mpp_omp')
+      !!      NB: rotation of lateral mixing operator or TKE or KPP scheme,
+      !!      the implicit scheme is required.
+      !!----------------------------------------------------------------------
+      USE zdftke
+      USE zdfkpp
+      !!----------------------------------------------------------------------
+
+      !  Define the vertical tracer physics scheme
+      ! ==========================================
+
+      ! Choice from ln_zdfexp already read in namelist in zdfini module
+      IF( ln_zdfexp ) THEN   ;   nzdf = 0              ! use explicit scheme
+      ELSE                   ;   nzdf = 1              ! use implicit scheme
+      ENDIF
+
+      ! Force implicit schemes
+      IF( lk_zdftke .OR. lk_zdfkpp   )   nzdf = 1      ! TKE or KPP physics
+      IF( ln_traldf_iso              )   nzdf = 1      ! iso-neutral lateral physics
+      IF( ln_traldf_hor .AND. ln_sco )   nzdf = 1      ! horizontal lateral physics in s-coordinate
+
+      IF( ln_zdfexp .AND. nzdf == 1 )   THEN
+         CALL ctl_stop( 'tra_zdf : If using the rotation of lateral mixing operator or TKE ', &
+            &           '          or KPP scheme, the implicit scheme is required, set ln_zdfexp = .false.' )
+      ENDIF
+
+      ! Test: esopa
+      IF( lk_esopa )    nzdf = -1                      ! All schemes used
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra:zdf_ctl : vertical tracer physics scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         IF( nzdf == -1 )   WRITE(numout,*) '              ESOPA test All scheme used'
+         IF( nzdf ==  0 )   WRITE(numout,*) '              Explicit time-splitting scheme'
+         IF( nzdf ==  1 )   WRITE(numout,*) '              Implicit (euler backward) scheme'
+      ENDIF
+
+   END SUBROUTINE zdf_ctl
+
+   !!==============================================================================
+END MODULE trazdf
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_exp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_exp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_exp.F90	(revision 4536)
@@ -0,0 +1,129 @@
+MODULE trazdf_exp
+   !!==============================================================================
+   !!                    ***  MODULE  trazdf_exp  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend using
+   !!                        an explicit time-stepping (time spllitting scheme)
+   !!==============================================================================
+   !! History :  6.0  !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11  (G. Madec)
+   !!                 !  1992-06  (M. Imbard)  correction on tracer trend loops
+   !!                 !  1996-01  (G. Madec)  statement function for e3
+   !!                 !  1997-05  (G. Madec)  vertical component of isopycnal
+   !!                 !  1997-07  (G. Madec)  geopotential diffusion in s-coord
+   !!                 !  2000-08  (G. Madec)  double diffusive mixing
+   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
+   !!             -   !  2004-08  (C. Talandier) New trends organisation
+   !!            2.0  !  2005-11  (G. Madec)  New organisation
+   !!            2.4  !  2008-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_zdf_exp  : update the tracer trend with the vertical diffusion
+   !!                  using an explicit time stepping
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain 
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_zdf_exp          ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_zdf_exp( kt, p2dt, pavt, ptb , pta   )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_exp  ***
+      !!                   
+      !! ** Purpose :   Compute the trend due to the vertical tracer mixing 
+      !!      using an explicit time stepping and add it to the general trend 
+      !!      of the tracer equations.
+      !!
+      !! ** Method  :   The vertical diffusion of tracers (t & s) is given by:
+      !!         difft = dz( avt dz(tb) ) = 1/e3t dk+1( avt/e3w dk(tb) )
+      !!      It is evaluated with an Euler scheme, using a time splitting
+      !!      technique.
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend ta,sa :
+      !!          ta = ta + dz( avt dz(t) )
+      !!         (sa = sa + dz( avs dz(t) ) if lk_zdfddm= T)
+      !!
+      !! ** Action : - Update (ta,sa) with the before vertical diffusion trend
+      !!
+      !!---------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt     ! ocean time-step index
+      REAL(wp), INTENT(in   ), DIMENSION(jpk)         ::   p2dt   ! vertical profile of tracer time-step
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pavt   ! eddy diffusivity coef.
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb    ! before tracer field
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta    ! tracer trend 
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      REAL(wp) ::   zlavmr, zave3r, ze3tr, zta   !    "         " 
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, zwy
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_zdf_exp : explicit vertical mixing (j-k-i loops)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      zlavmr = 1. / FLOAT( n_zdfexp )
+
+      ! 1. Initializations
+      ! ------------------
+      zwy(:,:, 1 ) = 0.e0          ! surface : zero diffusive flux
+      zwy(:,:,jpk) = 0.e0          ! bottom  : zero diffusive flux
+      zwx(:,:,:) = ptb(:,:,:)      ! interior: start from before tracer
+
+
+      ! 2. Time splitting loop
+      ! ----------------------
+
+      DO jl = 1, n_zdfexp
+         !
+         ! first vertical derivative
+         DO jk = 2, jpk
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1      ! vector opt.
+                  zave3r = 1.e0 / fse3w(ji,jj,jk) 
+                  zwy(ji,jj,jk) =  pavt(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) * zave3r
+               END DO
+            END DO
+         END DO
+
+         ! trend estimation at kt+l*2*rdt/n_zdfexp
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1      ! vector opt.
+                  ze3tr = zlavmr / fse3t(ji,jj,jk)
+                  ! 2nd vertical derivative
+                  zta = ( zwy(ji,jj,jk) - zwy(ji,jj,jk+1) ) * ze3tr
+                  ! update the tracer trends
+                  pta(ji,jj,jk) = pta(ji,jj,jk) + zta
+                  ! update tracer fields at kt+l*2*rdt/n_zdfexp
+                  zwx(ji,jj,jk) = zwx(ji,jj,jk) + p2dt(jk) * zta * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !
+      END DO 
+      !
+   END SUBROUTINE tra_zdf_exp
+
+   !!==============================================================================
+END MODULE trazdf_exp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_imp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 4536)
@@ -0,0 +1,359 @@
+MODULE trazdf_imp
+   !!==============================================================================
+   !!                 ***  MODULE  trazdf_imp  ***
+   !! Ocean active tracers:  vertical component of the tracer mixing trend
+   !!==============================================================================
+   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
+   !!            7.0  !  1991-11 (G. Madec)
+   !!             -   !  1992-06 (M. Imbard) correction on tracer trend loops
+   !!            8.0  !  1996-01 (G. Madec) statement function for e3
+   !!             -   !  1997-05 (G. Madec) vertical component of isopycnal
+   !!             -   !  1997-07 (G. Madec) geopotential diffusion in s-coord
+   !!             -   !  2000-08 (G. Madec) double diffusive mixing
+   !!   NEMO     1.0  !  2002-08 (G. Madec)  F90: Free form and module
+   !!            2.0  !  2006-11 (G. Madec)  New step reorganisation
+   !!            2.4  !  2008-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_zdf_imp : Update the tracer trend with the diagonal vertical  
+   !!                 part of the mixing tensor.
+   !!                 Vector optimization, use k-j-i loops.
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfslp          ! lateral physics: slope of diffusion
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
+   USE zdfddm          ! ocean vertical physics: double diffusion
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE domvvl          ! variable volume
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC tra_zdf_imp   !  routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!----------------------------------------------------------------------
+CONTAINS
+   
+   SUBROUTINE tra_zdf_imp( kt, p2dt, cdtype )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_imp  ***
+      !!
+      !! ** Purpose :   Compute the trend due to the vertical tracer diffusion
+      !!     including the vertical component of lateral mixing (only for 2nd
+      !!     order operator, for fourth order it is already computed and add
+      !!     to the general trend in traldf.F) and add it to the general trend
+      !!     of the tracer equations.
+      !!
+      !! ** Method  :   The vertical component of the lateral diffusive trends
+      !!      is provided by a 2nd order operator rotated along neutral or geo-
+      !!      potential surfaces to which an eddy induced advection can be 
+      !!      added. It is computed using before fields (forward in time) and 
+      !!      isopycnal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers (t & s) is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=ta).
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend ta,sa :
+      !!         ta = ta + dz( avt dz(t) )
+      !!         (sa = sa + dz( avs dz(t) ) if lk_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in zdfmxl.F90).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_zdfddm=T )
+      !!
+      !! ** Action  : - Update (ta,sa) with before vertical diffusion trend
+      !!
+      !!---------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                 ::   kt       ! ocean time-step index
+      CHARACTER(len=3), INTENT(in   )                 ::   cdtype   ! =TRA or TRC (tracer indicator)
+      REAL(wp)        , INTENT(in   ), DIMENSION(jpk) ::   p2dt     ! vertical profile of tracer time-step
+      !!
+      INTEGER  ::   ji, jj, jk                     ! dummy loop indices
+      REAL(wp) ::   znvvl                    ! temporary scalars
+      REAL(wp) ::   ze3tn, ze3ta, zvsfvvl   ! variable vertical scale factors
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwd, zws, zwi, zav   ! workspace arrays
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'tra_zdf_imp : implicit vertical mixing (k-j-i loops)'
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~ '
+         IF( cdtype /= 'TRA' ) THEN
+            IF(lwp)WRITE(numout,*) 'CAUTION TRC casei still not coded '
+         ENDIF
+      ENDIF
+
+      ! I. Local initialization
+      ! -----------------------
+      zwd  (1,:, : ) = 0.e0     ;     zwd  (jpi,:,:) = 0.e0
+      zws  (1,:, : ) = 0.e0     ;     zws  (jpi,:,:) = 0.e0
+      zwi  (1,:, : ) = 0.e0     ;     zwi  (jpi,:,:) = 0.e0
+      zav  (1,:, : ) = 0.e0     ;     zav  (jpi,:,:) = 0.e0
+      zav  (:,:,jpk) = 0.e0     ;     zav  ( : ,:,1) = 0.e0
+
+      ! I.1 Variable volume : to take into account vertical variable vertical scale factors
+      ! -------------------
+      IF( lk_vvl ) THEN   ;    znvvl = 1.
+      ELSE                ;    znvvl = 0.e0
+      ENDIF
+
+      ! II. Vertical trend associated with the vertical physics
+      ! =======================================================
+      !     (including the vertical flux proportional to dk[t] associated
+      !      with the lateral mixing, through the avt update)
+      !     dk[ avt dk[ (t,s) ] ] diffusive trends
+
+
+      ! II.0 Matrix construction
+      ! ------------------------
+
+      ! vertical mixing coef. put in zav
+      IF( ln_traldf_iso ) THEN      ! zav = avt + lateral mixing contribution
+#if defined key_ldfslp
+         DO jk = 2, jpkm1 
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zav(ji,jj,jk) = avt(ji,jj,jk) + fsahtw(ji,jj,jk) * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)   &
+                     &                                                + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+               END DO
+            END DO
+         END DO
+#endif
+      ELSE
+         zav(:,:,:) = avt(:,:,:)   ! zav = avt
+      ENDIF
+
+      ! Diagonal, inferior, superior  (including the bottom boundary condition via avt masked)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zvsfvvl = fsve3t(ji,jj,jk) * ( 1 + ssha(ji,jj) * mut(ji,jj,jk) )
+               ze3ta = ( 1. - znvvl ) + znvvl*zvsfvvl                                ! after scale factor at T-point
+               ze3tn = ( 1. - znvvl )*fse3t(ji,jj,jk) + znvvl                        ! now   scale factor at T-point
+               zwi(ji,jj,jk) = - p2dt(jk) * zav(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+               zws(ji,jj,jk) = - p2dt(jk) * zav(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+               zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Surface boudary conditions
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zvsfvvl = fsve3t(ji,jj,1) * ( 1 + ssha(ji,jj) * mut(ji,jj,1) )
+            ze3ta = ( 1. - znvvl ) + znvvl*zvsfvvl                                   ! after scale factor at T-point
+            zwi(ji,jj,1) = 0.e0
+            zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+         END DO
+      END DO
+
+
+      ! II.1. Vertical diffusion on t
+      ! ---------------------------
+      CALL zdf_imp( p2dt, zwd, zws, zwi, tb, ta )
+
+
+      ! II.2 Vertical diffusion on salinity
+      ! -----------------------------------
+
+!!gm    question: why surface value of zav is zero????  to be checked
+      IF( lk_zdfddm ) THEN
+         ! vertical mixing coef. on salintity including isopycnal slope (if necessary) put in zav
+         IF( ln_traldf_iso ) THEN      ! zav = avt + lateral mixing contribution
+#if defined key_ldfslp
+            DO jk = 2, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     zav(ji,jj,jk) = zav(ji,jj,jk) - avt(ji,jj,jk) + fsavs(ji,jj,jk)  
+                  END DO
+               END DO
+            END DO
+#endif
+         ELSE                             ! zav = avs
+            zav(:,:,:) = avs(:,:,:) 
+         ENDIF
+
+         ! Rebuild the Matrix as avt /= avs
+
+         ! Diagonal, inferior, superior  (including the bottom boundary condition via avs masked)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zvsfvvl = fsve3t(ji,jj,jk) * ( 1 + ssha(ji,jj) * mut(ji,jj,jk) )
+                  ze3ta = ( 1. - znvvl ) + znvvl*zvsfvvl                              ! after scale factor at T-point
+                  ze3tn = ( 1. - znvvl )*fse3t(ji,jj,jk) + znvvl                      ! now   scale factor at T-point
+                  zwi(ji,jj,jk) = - p2dt(jk) * zav(ji,jj,jk  ) / ( ze3tn * fse3w(ji,jj,jk  ) )
+                  zws(ji,jj,jk) = - p2dt(jk) * zav(ji,jj,jk+1) / ( ze3tn * fse3w(ji,jj,jk+1) )
+                  zwd(ji,jj,jk) = ze3ta - zwi(ji,jj,jk) - zws(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Surface boudary conditions
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zvsfvvl = fsve3t(ji,jj,1) * ( 1 + ssha(ji,jj) * mut(ji,jj,1) )
+               ze3ta = ( 1. - znvvl ) + znvvl*zvsfvvl                                  ! after scale factor at T-point
+               zwi(ji,jj,1) = 0.e0
+               zwd(ji,jj,1) = ze3ta - zws(ji,jj,1)
+            END DO
+         END DO
+         !
+      ENDIF
+
+      CALL zdf_imp( p2dt, zwd, zws, zwi, tb, ta )
+      !
+   END SUBROUTINE tra_zdf_imp
+
+
+   SUBROUTINE zdf_imp( p2dt, pwd, pws, pwi, ptb, pta )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_zdf_imp  ***
+      !!
+      !! ** Purpose :   Compute the trend due to the vertical tracer diffusion
+      !!     including the vertical component of lateral mixing (only for 2nd
+      !!     order operator, for fourth order it is already computed and add
+      !!     to the general trend in traldf.F) and add it to the general trend
+      !!     of the tracer equations.
+      !!
+      !! ** Method  :   The vertical component of the lateral diffusive trends
+      !!      is provided by a 2nd order operator rotated along neutral or geo-
+      !!      potential surfaces to which an eddy induced advection can be 
+      !!      added. It is computed using before fields (forward in time) and 
+      !!      isopycnal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers (t & s) is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=ta).
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend ta,sa :
+      !!         ta = ta + dz( avt dz(t) )
+      !!         (sa = sa + dz( avs dz(t) ) if lk_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in zdfmxl.F90).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_zdfddm=T )
+      !!
+      !! ** Action  : - Update (ta,sa) with before vertical diffusion trend
+      !!
+      !!---------------------------------------------------------------------
+      REAL(wp), INTENT(in   ), DIMENSION(jpk)         ::   p2dt     ! vertical profile of tracer time-step
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pwd      ! matrix: diagnal terms
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pws      ! matrix: upper   terms
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   pwi      ! matrix: lower   terms
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   ptb      ! before tracer field
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pta      ! in : tracer trend
+      !                                                                     ! out: after tracer
+      !!
+      INTEGER  ::   ji, jj, jk                     ! dummy loop indices
+      REAL(wp) ::   zrhs, znvvl              ! temporary scalars
+      REAL(wp) ::   ze3tb, ze3tn, zvsfvvl   ! variable vertical scale factors
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwt    ! workspace arrays
+      !!---------------------------------------------------------------------
+
+      ! Variable volume : to take into account vertical variable vertical scale factors
+      IF( lk_vvl ) THEN   ;    znvvl = 1.
+      ELSE                ;    znvvl = 0.e0
+      ENDIF
+
+      !! Matrix inversion from the first level
+      !!----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular matrix
+      !   The 3 diagonal terms are the input 3d arrays: zwd, zws, zwi
+      !   The second member and solution are put in pta array
+      !   The zwt array is a work space array
+
+      ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zwt(ji,jj,1) = pwd(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,jk) = pwd(ji,jj,jk) - pwi(ji,jj,jk) * pws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            zvsfvvl = fsve3t(ji,jj,1) * ( 1 + sshb(ji,jj) * mut(ji,jj,1) )
+            ze3tb = ( 1. - znvvl ) + znvvl*zvsfvvl
+            ze3tn = ( 1. - znvvl ) + znvvl*fse3t (ji,jj,1)
+            pta(ji,jj,1) = ze3tb * ptb(ji,jj,1) + p2dt(1) * ze3tn * pta(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zvsfvvl = fsve3t(ji,jj,jk) * ( 1 + sshb(ji,jj) * mut(ji,jj,jk) )
+               ze3tb = ( 1. - znvvl ) + znvvl*zvsfvvl
+               ze3tn = ( 1. - znvvl ) + znvvl*fse3t (ji,jj,jk)
+               zrhs = ze3tb * tb(ji,jj,jk) + p2dt(jk) * ze3tn * ta(ji,jj,jk)   ! zrhs=right hand side 
+               pta(ji,jj,jk) = zrhs - pwi(ji,jj,jk) / zwt(ji,jj,jk-1) *pta(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+      ! Save the masked temperature after in ta
+      ! (c a u t i o n:  temperature not its trend, Leap-frog scheme done it will not be done in tranxt)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            pta(ji,jj,jpkm1) = pta(ji,jj,jpkm1) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               pta(ji,jj,jk) = ( pta(ji,jj,jk) - pws(ji,jj,jk) * ta(ji,jj,jk+1) )   &
+                  &          / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE zdf_imp
+
+   !!==============================================================================
+END MODULE trazdf_imp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/zpshde.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 4536)
@@ -0,0 +1,241 @@
+MODULE zpshde
+   !!==============================================================================
+   !!                       ***  MODULE zpshde   ***
+   !! z-coordinate - partial step : Horizontal Derivative
+   !!==============================================================================
+   
+   !!----------------------------------------------------------------------
+   !!   zps_hde      :  Horizontal DErivative of T, S and rd at the last
+   !!                   ocean level (Z-coord. with Partial Steps)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space domain variables
+   USE oce             ! ocean dynamics and tracers variables
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE eosbn2          ! ocean equation of state
+   USE lbclnk          ! lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zps_hde          ! routine called by step.F90
+
+   !! * module variables
+   INTEGER, DIMENSION(jpi,jpj) ::   &
+      mbatu, mbatv      ! bottom ocean level index at U- and V-points
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zps_hde ( kt, ptem, psal, prd ,   &
+                            pgtu, pgsu, pgru,   &
+                            pgtv, pgsv, pgrv  )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde  ***
+      !!                    
+      !! ** Purpose :   Compute the horizontal derivative of T, S and rd
+      !!      at u- and v-points with a linear interpolation for z-coordinate
+      !!      with partial steps.
+      !!
+      !! ** Method  :   In z-coord with partial steps, scale factors on last 
+      !!      levels are different for each grid point, so that T, S and rd 
+      !!      points are not at the same depth as in z-coord. To have horizontal
+      !!      gradients again, we interpolate T and S at the good depth : 
+      !!      Linear interpolation of T, S   
+      !!         Computation of di(tb) and dj(tb) by vertical interpolation:
+      !!          di(t) = t~ - t(i,j,k) or t(i+1,j,k) - t~
+      !!          dj(t) = t~ - t(i,j,k) or t(i,j+1,k) - t~
+      !!         This formulation computes the two cases:
+      !!                 CASE 1                   CASE 2  
+      !!         k-1  ___ ___________   k-1   ___ ___________
+      !!                    Ti  T~                  T~  Ti+1
+      !!                  _____                        _____
+      !!         k        |   |Ti+1     k           Ti |   |
+      !!                  |   |____                ____|   |
+      !!              ___ |   |   |           ___  |   |   |
+      !!                  
+      !!      case 1->   e3w(i+1) >= e3w(i) ( and e3w(j+1) >= e3w(j) ) then
+      !!          t~ = t(i+1,j  ,k) + (e3w(i+1) - e3w(i)) * dk(Ti+1)/e3w(i+1)
+      !!        ( t~ = t(i  ,j+1,k) + (e3w(j+1) - e3w(j)) * dk(Tj+1)/e3w(j+1)  )
+      !!          or
+      !!      case 2->   e3w(i+1) <= e3w(i) ( and e3w(j+1) <= e3w(j) ) then
+      !!          t~ = t(i,j,k) + (e3w(i) - e3w(i+1)) * dk(Ti)/e3w(i )
+      !!        ( t~ = t(i,j,k) + (e3w(j) - e3w(j+1)) * dk(Tj)/e3w(j ) )
+      !!          Idem for di(s) and dj(s)          
+      !!
+      !!      For rho, we call eos_insitu_2d which will compute rd~(t~,s~) at 
+      !!      the good depth zh from interpolated T and S for the different
+      !!      formulation of the equation of state (eos).
+      !!      Gradient formulation for rho :
+      !!          di(rho) = rd~ - rd(i,j,k) or rd (i+1,j,k) - rd~
+      !!
+      !! ** Action  : - pgtu, pgsu, pgru: horizontal gradient of T, S
+      !!                and rd at U-points 
+      !!              - pgtv, pgsv, pgrv: horizontal gradient of T, S
+      !!                and rd at V-points 
+      !!
+      !! History :
+      !!   8.5  !  02-04  (A. Bozec)  Original code
+      !!   8.5  !  02-08  (G. Madec E. Durand)  Optimization and Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem, psal, prd            ! 3D T, S and rd fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         pgtu, pgsu, pgru,       &  ! horizontal grad. of T, S and rd at u- 
+         pgtv, pgsv, pgrv           ! and v-points of the partial step level
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,       &  ! Dummy loop indices
+                   iku,ikv          ! partial step level at u- and v-points
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zti, ztj, zsi, zsj,     &  ! interpolated value of T, S 
+         zri, zrj,               &  ! and rd
+         zhgi, zhgj                 ! depth of interpolation for eos2d
+      REAL(wp) ::   &
+         ze3wu, ze3wv,           &  ! temporary scalars
+         zmaxu1, zmaxu2,         &  !    "         "
+         zmaxv1, zmaxv2             !    "         "
+
+      ! Initialization (first time-step only): compute mbatu and mbatv
+      IF( kt == nit000 ) THEN
+         mbatu(:,:) = 0
+         mbatv(:,:) = 0
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               mbatu(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1, 2 )
+               mbatv(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1, 2 )
+            END DO
+         END DO
+         zti(:,:) = FLOAT( mbatu(:,:) )
+         ztj(:,:) = FLOAT( mbatv(:,:) )
+         ! lateral boundary conditions: T-point, sign unchanged
+         CALL lbc_lnk( zti , 'U', 1. )
+         CALL lbc_lnk( ztj , 'V', 1. )
+         mbatu(:,:) = MAX( INT( zti(:,:) ), 2 )
+         mbatv(:,:) = MAX( INT( ztj(:,:) ), 2 )
+      ENDIF
+      
+
+      ! Interpolation of T and S at the last ocean level
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            ! last level
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+            zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+            zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+            zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+            ! i- direction
+
+            IF( ze3wu >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji+1,jj,iku) + zmaxu1 * ( ptem(ji+1,jj,iku-1) - ptem(ji+1,jj,iku) )
+               zsi(ji,jj) = psal(ji+1,jj,iku) + zmaxu1 * ( psal(ji+1,jj,iku-1) - psal(ji+1,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji,jj,iku)
+               ! gradient of T and S
+               pgtu(ji,jj) = umask(ji,jj,1) * ( zti(ji,jj) - ptem(ji,jj,iku) )
+               pgsu(ji,jj) = umask(ji,jj,1) * ( zsi(ji,jj) - psal(ji,jj,iku) )
+
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               zti(ji,jj) = ptem(ji,jj,iku) + zmaxu2 * ( ptem(ji,jj,iku-1) - ptem(ji,jj,iku) )
+               zsi(ji,jj) = psal(ji,jj,iku) + zmaxu2 * ( psal(ji,jj,iku-1) - psal(ji,jj,iku) )
+               ! depth of the partial step level
+               zhgi(ji,jj) = fsdept(ji+1,jj,iku)
+               ! gradient of T and S 
+               pgtu(ji,jj) = umask(ji,jj,1) * ( ptem(ji+1,jj,iku) - zti (ji,jj) )
+               pgsu(ji,jj) = umask(ji,jj,1) * ( psal(ji+1,jj,iku) - zsi (ji,jj) )
+            ENDIF
+
+            ! j- direction
+
+            IF( ze3wv >= 0. ) THEN      ! case 1
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj+1,ikv) + zmaxv1 * ( ptem(ji,jj+1,ikv-1) - ptem(ji,jj+1,ikv) )
+               zsj(ji,jj) = psal(ji,jj+1,ikv) + zmaxv1 * ( psal(ji,jj+1,ikv-1) - psal(ji,jj+1,ikv) )
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj,ikv) 
+               ! gradient of T and S
+               pgtv(ji,jj) = vmask(ji,jj,1) * ( ztj(ji,jj) - ptem(ji,jj,ikv) )
+               pgsv(ji,jj) = vmask(ji,jj,1) * ( zsj(ji,jj) - psal(ji,jj,ikv) )
+
+            ELSE                        ! case 2
+               ! interpolated values of T and S
+               ztj(ji,jj) = ptem(ji,jj,ikv) + zmaxv2 * ( ptem(ji,jj,ikv-1) - ptem(ji,jj,ikv) )
+               zsj(ji,jj) = psal(ji,jj,ikv) + zmaxv2 * ( psal(ji,jj,ikv-1) - psal(ji,jj,ikv) ) 
+               ! depth of the partial step level
+               zhgj(ji,jj) = fsdept(ji,jj+1,ikv) 
+               ! gradient of T and S
+               pgtv(ji,jj) = vmask(ji,jj,1) * ( ptem(ji,jj+1,ikv) - ztj(ji,jj) )
+               pgsv(ji,jj) = vmask(ji,jj,1) * ( psal(ji,jj+1,ikv) - zsj(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Compute interpolated rd from zti, zsi, ztj, zsj for the 2 cases at the depth of the partial
+      ! step and store it in  zri, zrj for each  case
+      CALL eos( zti, zsi, zhgi, zri )
+      CALL eos( ztj, zsj, zhgj, zrj )
+
+
+      ! Gradient of density at the last level 
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+# endif
+            iku = mbatu(ji,jj)
+            ikv = mbatv(ji,jj)
+            ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+            ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+            IF( ze3wu >= 0. ) THEN    ! i-direction: case 1
+               pgru(ji,jj) = umask(ji,jj,1) * ( zri(ji,jj) - prd(ji,jj,iku) )
+            ELSE                      ! i-direction: case 2
+               pgru(ji,jj) = umask(ji,jj,1) * ( prd(ji+1,jj,iku) - zri(ji,jj) )
+            ENDIF
+            IF( ze3wv >= 0. ) THEN    ! j-direction: case 1
+               pgrv(ji,jj) = vmask(ji,jj,1) * ( zrj(ji,jj) - prd(ji,jj,ikv) )  
+            ELSE                      ! j-direction: case 2
+               pgrv(ji,jj) = vmask(ji,jj,1) * ( prd(ji,jj+1,ikv) - zrj(ji,jj) )
+            ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+# endif
+      END DO
+
+      ! Lateral boundary conditions on each gradient
+      CALL lbc_lnk( pgtu , 'U', -1. )   ;   CALL lbc_lnk( pgtv , 'V', -1. )
+      CALL lbc_lnk( pgsu , 'U', -1. )   ;   CALL lbc_lnk( pgsv , 'V', -1. )
+      CALL lbc_lnk( pgru , 'U', -1. )   ;   CALL lbc_lnk( pgrv , 'V', -1. )
+
+   END SUBROUTINE zps_hde
+
+   !!======================================================================
+END MODULE zpshde
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 4536)
@@ -0,0 +1,761 @@
+MODULE trdicp
+   !!======================================================================
+   !!                       ***  MODULE  trdicp  ***
+   !! Ocean diagnostics:  ocean tracers and dynamic trends
+   !!=====================================================================
+   !! History :  OPA  !  1991-12  (G. Madec)
+   !!            4.0  !  1992-06  (M. Imbard) add time step frequency
+   !!            8.0  !  1996-01  (G. Madec)  terrain following coordinates
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
+   !!            1.0  !  2004-08  (C. Talandier) New trends organization
+   !!            2.4  !  2008-01  (G. Madec)  merge TRC-TRA
+   !!----------------------------------------------------------------------
+#if  defined key_trdtra   ||   defined key_trddyn   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trdtra'  or                  active tracers trends diagnostics
+   !!   'key_trddyn'                            momentum trends diagnostics
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   trd_icp          : compute the basin averaged properties for tra/dyn 
+   !!   trd_dwr          : print dynmaic trends in ocean.output file
+   !!   trd_twr          : print tracers trends in ocean.output file
+   !!   trd_icp_init     : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE trdmod_oce      ! ocean variables trends
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distibuted memory computing library
+   USE eosbn2          ! equation of state
+   USE phycst          ! physical constants
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE trd_icp
+      MODULE PROCEDURE trd_2d, trd_3d, trd_u2d, trd_u3d
+   END INTERFACE
+
+   PUBLIC   trd_icp       ! called by trdmod.F90
+   PUBLIC   trd_dwr       ! called by step.F90
+   PUBLIC   trd_twr       ! called by step.F90
+   PUBLIC   trd_icp_init  ! called by opa.F90
+
+   !! Variables used for diagnostics
+   REAL(wp) ::   tvolt        !: volume of the whole ocean computed at t-points
+   REAL(wp) ::   tvolu        !: volume of the whole ocean computed at u-points
+   REAL(wp) ::   tvolv        !: volume of the whole ocean computed at v-points
+
+   !! Active Tracer trend diagnostics variables
+   REAL(wp), DIMENSION(jpt_trd,2) ::   tsmo         !: tracers trends average 
+   REAL(wp), DIMENSION(jpt_trd,2) ::   ts2          !: tracers square trends average 
+
+   !! Momentum trends diagnostics variables
+   REAL(wp), DIMENSION(jptot_dyn) ::   umo, vmo         !: momentum trends average 
+   REAL(wp), DIMENSION(jptot_dyn) ::   hke              !: momentum square trends average 
+   REAL(wp) ::   rpktrd   !: potential to kinetic energy conversion
+   REAL(wp) ::   peke     !: conversion potential energy - kinetic energy trend
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trd_2d( ptrd, ktra, ktrd , ctype, clpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_2d  ***
+      !! 
+      !! ** Purpose : verify the basin averaged properties of tracers and/or
+      !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   ptrd      ! tracer or u trend
+      INTEGER                     , INTENT(in   )           ::   ktra      ! tracer index
+      INTEGER                     , INTENT(in   )           ::   ktrd      ! tracer trend index
+      CHARACTER(len=3)            , INTENT(in   )           ::   ctype     ! tracer type (='TRA' or 'TRC')
+      CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   clpas     ! number of passage
+      !!
+      CHARACTER(len=3) ::   cpas   ! number of passage
+      REAL(wp)         ::   zsum   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      cpas = 'fst'                             ! Control of optional arguments
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      ! 1. Mask volumic trends
+      ptrd(:,:) = e1t(:,:) * e2t(:,:) * fse3t(:,:,1) * ptrd(:,:) * tmask_i(:,:)
+      
+      ! 2. Basin averaged tracer trends
+      SELECT CASE( ctype )
+      CASE( 'TRA' )              ! Tracers
+         zsum = SUM( ptrd(:,:) )
+         IF( cpas == 'fst' ) THEN   ;   tsmo(ktrd,ktra) =                   zsum
+         ELSE                       ;   tsmo(ktrd,ktra) = tsmo(ktrd,ktra) + zsum
+         ENDIF
+      CASE( 'TRC' )              ! Passive tracers
+         !      ....  to be done
+      END SELECT
+      
+      ! 3. Basin averaged tracer square trends (i.e. trd * now tracer field)
+      SELECT CASE( ctype )
+      CASE( 'TRA' )              ! Tracers
+         IF( ktra == jp_tem )   zsum = SUM(  ptrd(:,:) * tn(:,:,1) )
+         IF( ktra == jp_sal )   zsum = SUM(  ptrd(:,:) * sn(:,:,1) )
+         IF( cpas == 'fst' ) THEN   ;   ts2(ktrd,ktra) =                  zsum
+         ELSE                       ;   ts2(ktrd,ktra) = ts2(ktrd,ktra) + zsum
+         ENDIF
+      CASE( 'TRC' )              ! Passive tracers
+         !      ....  to be done
+      END SELECT
+      !
+   END SUBROUTINE trd_2d
+
+
+   SUBROUTINE trd_3d( ptrd, ktra, ktrd , ctype, clpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_3d  ***
+      !! 
+      !! ** Purpose : verify the basin averaged properties of tracers and/or
+      !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   ptrd      ! tracer or u trend
+      INTEGER                         , INTENT(in   )           ::   ktra      ! tracer index
+      INTEGER                         , INTENT(in   )           ::   ktrd      ! tracer trend index
+      CHARACTER(len=3)                , INTENT(in   )           ::   ctype     ! tracer type (='TRA' or 'TRC')
+      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   clpas     ! number of passage
+      !!
+      INTEGER          ::   jk     ! dummy loop indices
+      CHARACTER(len=3) ::   cpas   ! number of passage
+      REAL(wp)         ::   zsum   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsurf          ! 2D workspace array
+      !!----------------------------------------------------------------------
+
+      cpas = 'fst'                             ! Control of optional arguments
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      ! 1. Mask volumic trends
+      zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+      DO jk = 1, jpk
+         ptrd(:,:,jk) = zsurf(:,:) * fse3t(:,:,jk) * ptrd(:,:,jk) * tmask(:,:,jk)
+      END DO
+
+      ! 2. Basin averaged tracer trends
+      SELECT CASE( ctype )
+      CASE( 'TRA' )              ! Tracers
+         zsum = SUM( ptrd(:,:,:) )
+         IF( cpas == 'fst' ) THEN   ;   tsmo(ktrd,ktra) =                   zsum
+         ELSE                       ;   tsmo(ktrd,ktra) = tsmo(ktrd,ktra) + zsum
+         ENDIF
+      CASE( 'TRC' )              ! Passive tracers
+         !      ....  to be done
+      END SELECT
+
+      ! 3. Basin averaged tracer square trends (i.e. trd * now tracer field)
+      SELECT CASE( ctype )
+      CASE( 'TRA' )              ! Tracers
+         IF( ktra == jp_tem )   zsum = SUM(  ptrd(:,:,:) * tn(:,:,:) )
+         IF( ktra == jp_sal )   zsum = SUM(  ptrd(:,:,:) * sn(:,:,:) )
+         IF( cpas == 'fst' ) THEN   ;   ts2(ktrd,ktra) =                  zsum
+         ELSE                       ;   ts2(ktrd,ktra) = ts2(ktrd,ktra) + zsum
+         ENDIF
+      CASE( 'TRC' )              ! Passive tracers
+         !      ....  to be done
+      END SELECT
+      !
+   END SUBROUTINE trd_3d
+
+
+   SUBROUTINE trd_u2d( ptrdu, ptrdv, ktrd , ctype, clpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_2d  ***
+      !! 
+      !! ** Purpose : verify the basin averaged properties of tracers and/or
+      !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   ptrdu, ptrdv   ! U and V momentum trends 
+      INTEGER                     , INTENT(in   )           ::   ktrd           ! tracer trend index
+      CHARACTER(len=3)            , INTENT(in   )           ::   ctype          ! momentum ('DYN')
+      CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   clpas          ! number of passage
+      !!
+      INTEGER          ::   ji, jj        ! loop indices
+      CHARACTER(len=3) ::   cpas          ! number of passage
+      REAL(wp)         ::   zmsku, zbtu   ! temporary scalars
+      REAL(wp)         ::   zmskv, zbtv   !    "         "
+      !!----------------------------------------------------------------------
+
+      cpas = 'fst'                           ! Control of optional arguments
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
+
+      ! 1. Mask trends
+      ! --------------
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            zmsku = tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,1)
+            zmskv = tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,1)
+            ptrdu(ji,jj) = ptrdu(ji,jj) * zmsku
+            ptrdv(ji,jj) = ptrdv(ji,jj) * zmskv
+         END DO
+      END DO
+      ptrdu(jpi, : ) = 0.e0      ;      ptrdv(jpi, : ) = 0.e0
+      ptrdu( : ,jpj) = 0.e0      ;      ptrdv( : ,jpj) = 0.e0
+      
+      ! 2. Basin averaged tracer/momentum trends
+      ! ----------------------------------------
+      umo(ktrd) = 0.e0
+      vmo(ktrd) = 0.e0
+      !
+      SELECT CASE( ktrd )
+      !
+      CASE( jpdyn_trd_swf )         ! surface forcing
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               umo(ktrd) = umo(ktrd) + ptrdu(ji,jj) * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1)
+               vmo(ktrd) = vmo(ktrd) + ptrdv(ji,jj) * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1)
+            END DO
+         END DO
+            !
+         CASE( jpdyn_trd_bfr )         ! bottom friction fluxes
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  umo(ktrd) = umo(ktrd) + ptrdu(ji,jj)
+                  vmo(ktrd) = vmo(ktrd) + ptrdv(ji,jj)
+               END DO
+            END DO
+            !
+      END SELECT
+      !   
+      ! 3. Basin averaged tracer/momentum square trends
+      ! ----------------------------------------------
+      ! c a u t i o n: field now
+      
+         hke(ktrd) = 0.e0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zbtu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1)
+               zbtv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1)
+               hke(ktrd) = hke(ktrd) + un(ji,jj,1) * ptrdu(ji,jj) * zbtu   &
+               &                     + vn(ji,jj,1) * ptrdv(ji,jj) * zbtv
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE trd_u2d
+
+
+   SUBROUTINE trd_u3d( ptrdu, ptrdv, ktrd, ctype, clpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_3d  ***
+      !! 
+      !! ** Purpose : verify the basin averaged properties of tracers and/or
+      !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   ptrdu, ptrdv   ! U and V momentum trends
+      INTEGER,                          INTENT(in   )           ::   ktrd           ! momentum trend index
+      CHARACTER(len=3),                 INTENT(in   )           ::   ctype          ! momentum (='DYN')
+      CHARACTER(len=3),                 INTENT(in   ), OPTIONAL ::   clpas          ! number of passage
+      !!
+      INTEGER ::   ji, jj, jk
+      CHARACTER(len=3) ::   cpas               ! number of passage
+      REAL(wp) ::   zbtu, zbtv, zmsku, zmskv   ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      cpas = 'fst'                            ! Control of optional arguments
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum        
+
+         ! 1. Mask the trends
+         ! ------------------
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zmsku = tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
+                  zmskv = tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
+                  ptrdu(ji,jj,jk) = ptrdu(ji,jj,jk) * zmsku
+                  ptrdv(ji,jj,jk) = ptrdv(ji,jj,jk) * zmskv
+               END DO
+            END DO
+         END DO
+         ptrdu(jpi, : ,:) = 0.e0      ;      ptrdv(jpi, : ,:) = 0.e0
+         ptrdu( : ,jpj,:) = 0.e0      ;      ptrdv( : ,jpj,:) = 0.e0
+         !
+
+      ! 2. Basin averaged tracer/momentum trends
+      ! ----------------------------------------
+      
+         umo(ktrd) = 0.e0
+         vmo(ktrd) = 0.e0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zbtu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+                  zbtv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+                  umo(ktrd) = umo(ktrd) + ptrdu(ji,jj,jk) * zbtu
+                  vmo(ktrd) = vmo(ktrd) + ptrdv(ji,jj,jk) * zbtv
+               END DO
+            END DO
+         END DO
+         !
+
+      ! 3. Basin averaged tracer/momentum square trends
+      ! -----------------------------------------------
+      ! c a u t i o n: field now
+      
+         hke(ktrd) = 0.e0
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zbtu = e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+                  zbtv = e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+                  hke(ktrd) = hke(ktrd) + un(ji,jj,jk) * ptrdu(ji,jj,jk) * zbtu   &
+                  &                     + vn(ji,jj,jk) * ptrdv(ji,jj,jk) * zbtv
+               END DO
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE trd_u3d
+
+
+   SUBROUTINE trd_icp_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_icp_init  ***
+      !! 
+      !! ** Purpose :   Read the namtrd namelist
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jk
+#if  defined key_trddyn
+      INTEGER  ::   ji, jj
+      REAL(wp) ::   zmsku, zmskv
+#endif
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsurf          ! 2D workspace array
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trd_icp_init : integral constraints properties trends'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Total volume at t-points:
+      tvolt = 0.e0
+      zsurf(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+      DO jk = 1, jpkm1
+            tvolt = tvolt + SUM( tmask(:,:,jk) * zsurf(:,:) * fse3t(:,:,jk) )
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
+
+      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
+
+#if  defined key_trddyn
+      ! Initialization of potential to kinetic energy conversion
+      rpktrd = 0.e0
+
+      ! Total volume at u-, v- points:
+      tvolu = 0.e0
+      tvolv = 0.e0
+
+      DO jk = 1, jpk
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zmsku = tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
+               zmskv = tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
+               tvolu = tvolu + zmsku * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk)
+               tvolv = tvolv + zmskv * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolu )   ! sums over the global domain
+      IF( lk_mpp )   CALL mpp_sum( tvolv )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '                total ocean volume at U-point   tvolu = ',tvolu
+         WRITE(numout,*) '                total ocean volume at V-point   tvolv = ',tvolv
+      ENDIF
+#endif
+      !
+   END SUBROUTINE trd_icp_init
+
+
+   SUBROUTINE trd_dwr( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_dwr  ***
+      !! 
+      !! ** Purpose :  write dynamic trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt                                  ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zcof, zbe1ru, zbe2rv, zbtr, ztz, zth   !    "      scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zsurf          ! 2D workspace array
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zkepe, zkx, zky, zkz   ! temporary arrays
+      !!----------------------------------------------------------------------
+
+      ! I. Momentum trends
+      ! -------------------
+
+      IF( MOD(kt,ntrd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Conversion potential energy - kinetic energy
+         ! --------------------------------------------------
+         ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
+
+         zkx(:,:,:)   = 0.e0
+         zky(:,:,:)   = 0.e0
+         zkz(:,:,:)   = 0.e0
+         zkepe(:,:,:) = 0.e0
+   
+         CALL eos( tn, sn, rhd, rhop )       ! now potential and in situ densities
+
+         ! Density flux at w-point
+         zsurf(:,:) = 0.5 * e1t(:,:) * e2t(:,:) * tmask_i(:,:) /rau0
+!!gm better use bn2....
+         zkz(:,:,1) = 0.e0
+         DO jk = 2, jpk
+            zkz(:,:,jk) = zsurf(:,:) * wn(:,:,jk) * ( rhop(:,:,jk) + rhop(:,:,jk-1) )
+         END DO
+         
+         ! Density flux at u and v-points
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zcof   = 0.5 / rau0
+                  zbe1ru = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk)
+                  zbe2rv = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk)
+                  zkx(ji,jj,jk) = zbe1ru * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
+                  zky(ji,jj,jk) = zbe2rv * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
+               END DO
+            END DO
+         END DO
+         
+         ! Density flux divergence at t-point
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ztz = - zbtr * (    zkz(ji,jj,jk) - zkz(ji,jj,jk+1) )
+                  zth = - zbtr * (  ( zkx(ji,jj,jk) - zkx(ji-1,jj,jk) )   &
+                    &             + ( zky(ji,jj,jk) - zky(ji,jj-1,jk) )  )
+                  zkepe(ji,jj,jk) = (zth + ztz) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         zkepe( : , : ,jpk) = 0.e0
+         zkepe( : ,jpj, : ) = 0.e0
+         zkepe(jpi, : , : ) = 0.e0
+
+         ! I.2 Basin averaged kinetic energy trend
+         ! ----------------------------------------
+         peke = 0.e0
+         DO jk = 1,jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  peke = peke + zkepe(ji,jj,jk) * grav * fsdept(ji,jj,jk)   &
+                     &                     * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! I.3 Sums over the global domain
+         ! ---------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( peke )
+            CALL mpp_sum( umo , jptot_dyn )
+            CALL mpp_sum( vmo , jptot_dyn )
+            CALL mpp_sum( hke , jptot_dyn )
+         ENDIF
+
+         ! I.2 Print dynamic trends in the ocean.output file
+         ! --------------------------------------------------
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9500) kt
+            WRITE (numout,9501) umo(jpicpd_hpg) / tvolu, vmo(jpicpd_hpg) / tvolv
+            WRITE (numout,9502) umo(jpicpd_keg) / tvolu, vmo(jpicpd_keg) / tvolv
+            WRITE (numout,9503) umo(jpicpd_rvo) / tvolu, vmo(jpicpd_rvo) / tvolv
+            WRITE (numout,9504) umo(jpicpd_pvo) / tvolu, vmo(jpicpd_pvo) / tvolv
+            WRITE (numout,9505) umo(jpicpd_ldf) / tvolu, vmo(jpicpd_ldf) / tvolv
+            WRITE (numout,9506) umo(jpicpd_zad) / tvolu, vmo(jpicpd_zad) / tvolv
+            WRITE (numout,9507) umo(jpicpd_zdf) / tvolu, vmo(jpicpd_zdf) / tvolv
+            WRITE (numout,9508) umo(jpicpd_spg) / tvolu, vmo(jpicpd_spg) / tvolv
+            WRITE (numout,9509) umo(jpicpd_swf) / tvolu, vmo(jpicpd_swf) / tvolv
+            WRITE (numout,9510) umo(jpicpd_dat) / tvolu, vmo(jpicpd_dat) / tvolv
+            WRITE (numout,9511) umo(jpicpd_bfr) / tvolu, vmo(jpicpd_bfr) / tvolv
+            WRITE (numout,9512)
+            WRITE (numout,9513)                                                 &
+            &     (  umo(jpicpd_hpg) + umo(jpicpd_keg) + umo(jpicpd_rvo) + umo(jpicpd_pvo) + umo(jpicpd_ldf)   &
+            &      + umo(jpicpd_zad) + umo(jpicpd_zdf) + umo(jpicpd_spg) + umo(jpicpd_dat) + umo(jpicpd_swf)   &
+            &      + umo(jpicpd_bfr) ) / tvolu,   &
+            &     (  vmo(jpicpd_hpg) + vmo(jpicpd_keg) + vmo(jpicpd_rvo) + vmo(jpicpd_pvo) + vmo(jpicpd_ldf)   &
+            &      + vmo(jpicpd_zad) + vmo(jpicpd_zdf) + vmo(jpicpd_spg) + vmo(jpicpd_dat) + vmo(jpicpd_swf)   &
+            &      + vmo(jpicpd_bfr) ) / tvolv
+         ENDIF
+
+ 9500    FORMAT(' momentum trend at it= ', i6, ' :', /' ==============================')
+ 9501    FORMAT(' pressure gradient          u= ', e20.13, '    v= ', e20.13)
+ 9502    FORMAT(' ke gradient                u= ', e20.13, '    v= ', e20.13)
+ 9503    FORMAT(' relative vorticity term    u= ', e20.13, '    v= ', e20.13)
+ 9504    FORMAT(' coriolis term              u= ', e20.13, '    v= ', e20.13)
+ 9505    FORMAT(' horizontal diffusion       u= ', e20.13, '    v= ', e20.13)
+ 9506    FORMAT(' vertical advection         u= ', e20.13, '    v= ', e20.13)
+ 9507    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
+ 9508    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
+ 9509    FORMAT(' surface wind forcing       u= ', e20.13, '    v= ', e20.13)
+ 9510    FORMAT(' dampimg term               u= ', e20.13, '    v= ', e20.13)
+ 9511    FORMAT(' bottom flux                u= ', e20.13, '    v= ', e20.13)
+ 9512    FORMAT(' -----------------------------------------------------------------------------')
+ 9513    FORMAT(' total trend                u= ', e20.13, '    v= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9520) kt
+            WRITE (numout,9521) hke(jpicpd_hpg) / tvolt
+            WRITE (numout,9522) hke(jpicpd_keg) / tvolt
+            WRITE (numout,9523) hke(jpicpd_rvo) / tvolt
+            WRITE (numout,9524) hke(jpicpd_pvo) / tvolt
+            WRITE (numout,9525) hke(jpicpd_ldf) / tvolt
+            WRITE (numout,9526) hke(jpicpd_zad) / tvolt
+            WRITE (numout,9527) hke(jpicpd_zdf) / tvolt
+            WRITE (numout,9528) hke(jpicpd_spg) / tvolt
+            WRITE (numout,9529) hke(jpicpd_swf) / tvolt
+            WRITE (numout,9530) hke(jpicpd_dat) / tvolt
+            WRITE (numout,9531)
+            WRITE (numout,9532)   &
+            &     (  hke(jpicpd_hpg) + hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_pvo) + hke(jpicpd_ldf)   &
+            &      + hke(jpicpd_zad) + hke(jpicpd_zdf) + hke(jpicpd_spg) + hke(jpicpd_dat) + hke(jpicpd_swf) ) / tvolt
+         ENDIF
+
+ 9520    FORMAT(' kinetic energy trend at it= ', i6, ' :', /' ====================================')
+ 9521    FORMAT(' pressure gradient         u2= ', e20.13)
+ 9522    FORMAT(' ke gradient               u2= ', e20.13)
+ 9523    FORMAT(' relative vorticity term   u2= ', e20.13)
+ 9524    FORMAT(' coriolis term             u2= ', e20.13)
+ 9525    FORMAT(' horizontal diffusion      u2= ', e20.13)
+ 9526    FORMAT(' vertical advection        u2= ', e20.13)
+ 9527    FORMAT(' vertical diffusion        u2= ', e20.13)
+ 9528    FORMAT(' surface pressure gradient u2= ', e20.13)
+ 9529    FORMAT(' surface wind forcing      u2= ', e20.13)
+ 9530    FORMAT(' dampimg term              u2= ', e20.13)
+ 9531    FORMAT(' --------------------------------------------------')
+ 9532    FORMAT(' total trend               u2= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9540) kt
+            WRITE (numout,9541) ( hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_zad) ) / tvolt
+            WRITE (numout,9542) ( hke(jpicpd_keg) + hke(jpicpd_zad) ) / tvolt
+            WRITE (numout,9543) ( hke(jpicpd_pvo) ) / tvolt
+            WRITE (numout,9544) ( hke(jpicpd_rvo) ) / tvolt
+            WRITE (numout,9545) ( hke(jpicpd_spg) ) / tvolt
+            WRITE (numout,9546) ( hke(jpicpd_ldf) ) / tvolt
+            WRITE (numout,9547) ( hke(jpicpd_zdf) ) / tvolt
+            WRITE (numout,9548) ( hke(jpicpd_hpg) ) / tvolt, rpktrd / tvolt
+            WRITE (numout,*)
+            WRITE (numout,*)
+         ENDIF
+
+ 9540    FORMAT(' energetic consistency at it= ', i6, ' :', /' =========================================')
+ 9541    FORMAT(' 0 = non linear term(true if key_vorenergy or key_combined): ', e20.13)
+ 9542    FORMAT(' 0 = ke gradient + vertical advection                      : ', e20.13)
+ 9543    FORMAT(' 0 = coriolis term  (true if key_vorenergy or key_combined): ', e20.13)
+ 9544    FORMAT(' 0 = uh.( rot(u) x uh ) (true if enstrophy conser.)        : ', e20.13)
+ 9545    FORMAT(' 0 = surface pressure gradient                             : ', e20.13)
+ 9546    FORMAT(' 0 > horizontal diffusion                                  : ', e20.13)
+ 9547    FORMAT(' 0 > vertical diffusion                                    : ', e20.13)
+ 9548    FORMAT(' pressure gradient u2 = - 1/rau0 u.dz(rhop)                : ', e20.13, '  u.dz(rhop) =', e20.13)
+         !
+         ! Save potential to kinetic energy conversion for next time step
+         rpktrd = peke
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_dwr
+
+
+   SUBROUTINE trd_twr( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_twr  ***
+      !! 
+      !! ** Purpose :  write active tracers trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+      ! I. Tracers trends
+      ! -----------------
+
+      IF( MOD(kt,ntrd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Sums over the global domain
+         ! -------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( tsmo, jpt_trd )   
+            CALL mpp_sum( ts2 , jpt_trd )
+         ENDIF
+
+         ! I.2 Print tracers trends in the ocean.output file
+         ! --------------------------------------------------
+         
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9400) kt
+            WRITE (numout,9401) ( tsmo(jpt_trd_xad,jp_tem) + tsmo(jpt_trd_yad,jp_tem)  ) / tvolt,   &
+               &                ( tsmo(jpt_trd_xad,jp_sal) + tsmo(jpt_trd_yad,jp_sal)  ) / tvolt
+            WRITE (numout,9402)   tsmo(jpt_trd_zad,jp_tem) / tvolt,   tsmo(jpt_trd_zad,jp_sal) / tvolt
+            WRITE (numout,9403)   tsmo(jpt_trd_ldf,jp_tem) / tvolt,   tsmo(jpt_trd_ldf,jp_sal) / tvolt
+            WRITE (numout,9404)   tsmo(jpt_trd_zdf,jp_tem) / tvolt,   tsmo(jpt_trd_zdf,jp_sal) / tvolt
+            WRITE (numout,9405)   tsmo(jpt_trd_npc,jp_tem) / tvolt,   tsmo(jpt_trd_npc,jp_sal) / tvolt
+            WRITE (numout,9406)   tsmo(jpt_trd_dmp,jp_tem) / tvolt,   tsmo(jpt_trd_dmp,jp_sal) / tvolt
+            WRITE (numout,9407)   tsmo(jpt_trd_qsr,jp_tem) / tvolt
+            WRITE (numout,9408)   tsmo(jpt_trd_qns,jp_tem) / tvolt,   tsmo(jpt_trd_qns,jp_sal) / tvolt
+            WRITE (numout,9409) 
+            WRITE (numout,9410) (  tsmo(jpt_trd_xad,jp_tem) + tsmo(jpt_trd_yad,jp_tem) + tsmo(jpt_trd_zad,jp_tem)     &
+               &                 + tsmo(jpt_trd_ldf,jp_tem) + tsmo(jpt_trd_zdf,jp_tem) + tsmo(jpt_trd_npc,jp_tem)     &
+               &                 + tsmo(jpt_trd_dmp,jp_tem) + tsmo(jpt_trd_qsr,jp_tem) + tsmo(jpt_trd_qns,jp_tem) )   &
+               &                / tvolt,   &
+               &                (  tsmo(jpt_trd_xad,jp_sal) + tsmo(jpt_trd_yad,jp_sal) + tsmo(jpt_trd_zad,jp_sal)     &
+               &                 + tsmo(jpt_trd_ldf,jp_sal) + tsmo(jpt_trd_zdf,jp_sal) + tsmo(jpt_trd_npc,jp_sal)     &
+               &                 + tsmo(jpt_trd_dmp,jp_sal)                           + tsmo(jpt_trd_qns,jp_sal) )   &
+               &                / tvolt
+
+
+9400     FORMAT(' tracer trend at it= ',i6,' :     temperature              salinity', /,   &
+                ' ============================')
+9401     FORMAT(' horizontal advection        ',e20.13,'     ',e20.13)
+9402     FORMAT(' vertical advection          ',e20.13,'     ',e20.13)
+9403     FORMAT(' horizontal diffusion        ',e20.13,'     ',e20.13)
+9404     FORMAT(' vertical diffusion          ',e20.13,'     ',e20.13)
+9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
+9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
+9407     FORMAT(' penetrative qsr             ',e20.13)
+9408     FORMAT(' non solar radiation         ',e20.13,'     ',e20.13)
+9409     FORMAT(' -------------------------------------------------------------------------')
+9410     FORMAT(' total trend                 ',e20.13,'     ',e20.13)
+
+
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9420) kt
+            WRITE (numout,9421) ( ts2(jpt_trd_xad,jp_tem) + ts2(jpt_trd_yad,jp_tem) ) / tvolt,   &
+               &                ( ts2(jpt_trd_xad,jp_sal) + ts2(jpt_trd_yad,jp_sal) ) / tvolt
+            WRITE (numout,9422)   ts2(jpt_trd_zad,jp_tem) / tvolt, ts2(jpt_trd_zad,jp_sal) / tvolt
+            WRITE (numout,9423)   ts2(jpt_trd_ldf,jp_tem) / tvolt, ts2(jpt_trd_ldf,jp_sal) / tvolt
+            WRITE (numout,9424)   ts2(jpt_trd_zdf,jp_tem) / tvolt, ts2(jpt_trd_zdf,jp_sal) / tvolt
+            WRITE (numout,9425)   ts2(jpt_trd_npc,jp_tem) / tvolt, ts2(jpt_trd_npc,jp_sal) / tvolt
+            WRITE (numout,9426)   ts2(jpt_trd_dmp,jp_tem) / tvolt, ts2(jpt_trd_dmp,jp_sal) / tvolt
+            WRITE (numout,9427)   ts2(jpt_trd_qsr,jp_tem) / tvolt
+            WRITE (numout,9428)   ts2(jpt_trd_qns,jp_tem) / tvolt, ts2(jpt_trd_qns,jp_sal) / tvolt
+            WRITE (numout,9429)
+            WRITE (numout,9430) (  ts2(jpt_trd_xad,jp_tem) + ts2(jpt_trd_yad,jp_tem) + ts2(jpt_trd_zad,jp_tem)     &
+               &                 + ts2(jpt_trd_ldf,jp_tem) + ts2(jpt_trd_zdf,jp_tem) + ts2(jpt_trd_npc,jp_tem)     &
+               &                 + ts2(jpt_trd_dmp,jp_tem) + ts2(jpt_trd_qsr,jp_tem) + ts2(jpt_trd_qns,jp_tem) )   &
+               &                / tvolt,   &
+               &                (  ts2(jpt_trd_xad,jp_sal) + ts2(jpt_trd_yad,jp_sal) + ts2(jpt_trd_zad,jp_sal)     &
+               &                 + ts2(jpt_trd_ldf,jp_sal) + ts2(jpt_trd_zdf,jp_sal) + ts2(jpt_trd_npc,jp_sal)     &
+               &                 + ts2(jpt_trd_dmp,jp_sal)                          + ts2(jpt_trd_qns,jp_sal) )   &
+               &                / tvolt
+
+9420     FORMAT(' tracer**2 trend at it= ',i6,' :     temperature              salinity', /,   &
+                ' ============================')
+9421     FORMAT(' horizontal advection      * t   ', e20.13, '     ', e20.13)
+9422     FORMAT(' vertical advection        * t   ', e20.13, '     ', e20.13)
+9423     FORMAT(' horizontal diffusion      * t   ', e20.13, '     ', e20.13)
+9424     FORMAT(' vertical diffusion        * t   ', e20.13, '     ', e20.13)
+9425     FORMAT(' static instability mixing * t   ', e20.13, '     ', e20.13)
+9426     FORMAT(' damping term              * t   ', e20.13, '     ', e20.13)
+9427     FORMAT(' penetrative qsr           * t   ', e20.13)
+9428     FORMAT(' non solar radiation       * t   ', e20.13, '     ', e20.13)
+9429     FORMAT(' -----------------------------------------------------------------------------')
+9430     FORMAT(' total trend                *t = ', e20.13, '  *s = ', e20.13)
+
+
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9440) kt
+            WRITE (numout,9441) ( tsmo(jpt_trd_xad,jp_tem)+tsmo(jpt_trd_yad,jp_tem)+tsmo(jpt_trd_zad,jp_tem) )/tvolt,  &
+            &                   ( tsmo(jpt_trd_xad,jp_sal)+tsmo(jpt_trd_yad,jp_sal)+tsmo(jpt_trd_zad,jp_sal) )/tvolt
+            WRITE (numout,9442)   tsmo(jpt_trd_zl1,jp_tem)/tvolt,  tsmo(jpt_trd_zl1,jp_sal)/tvolt
+            WRITE (numout,9443)   tsmo(jpt_trd_ldf,jp_tem)/tvolt,  tsmo(jpt_trd_ldf,jp_sal)/tvolt
+            WRITE (numout,9444)   tsmo(jpt_trd_zdf,jp_tem)/tvolt,  tsmo(jpt_trd_zdf,jp_sal)/tvolt
+            WRITE (numout,9445)   tsmo(jpt_trd_npc,jp_tem)/tvolt,  tsmo(jpt_trd_npc,jp_sal)/tvolt
+            WRITE (numout,9446) ( ts2(jpt_trd_xad,jp_tem)+ts2(jpt_trd_yad,jp_tem)+ts2(jpt_trd_zad,jp_tem) )/tvolt,    &
+            &                   ( ts2(jpt_trd_xad,jp_sal)+ts2(jpt_trd_yad,jp_sal)+ts2(jpt_trd_zad,jp_sal) )/tvolt
+            WRITE (numout,9447)   ts2(jpt_trd_ldf,jp_tem)/tvolt,   ts2(jpt_trd_ldf,jp_sal)/tvolt
+            WRITE (numout,9448)   ts2(jpt_trd_zdf,jp_tem)/tvolt,   ts2(jpt_trd_zdf,jp_sal)/tvolt
+            WRITE (numout,9449)   ts2(jpt_trd_npc,jp_tem)/tvolt,   ts2(jpt_trd_npc,jp_sal)/tvolt
+         ENDIF
+
+9440     FORMAT(' tracer consistency at it= ',i6, ' :         temperature','                salinity',   &
+                /, ' ==================================')
+9441     FORMAT(' 0 = horizontal+vertical advection +    ',e20.13,'       ',e20.13)
+9442     FORMAT('     1st lev vertical advection         ',e20.13,'       ',e20.13)
+9443     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
+9444     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
+9445     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
+9446     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
+9447     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
+9448     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
+9449     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_twr
+
+#   else
+   !!----------------------------------------------------------------------
+   !!   Default case :                                         Empty module
+   !!----------------------------------------------------------------------
+   INTERFACE trd_icp
+      MODULE PROCEDURE trd_2d, trd_3d
+   END INTERFACE
+
+CONTAINS
+   SUBROUTINE trd_2d( ptrd2dx, ptrd2dy, ktrd , ctype, clpas )       ! Empty routine
+      REAL, DIMENSION(:,:) ::   ptrd2dx, ptrd2dy
+      INTEGER                     , INTENT(in   ) ::   ktrd         ! tracer trend index
+      CHARACTER(len=3)            , INTENT(in   ) ::   ctype        ! momentum ('DYN') or tracers ('TRA') trends
+      CHARACTER(len=3), INTENT(in), OPTIONAL ::   clpas             ! number of passage
+      WRITE(*,*) 'trd_2d: You should not have seen this print! error ?', &
+          &       ptrd2dx(1,1), ptrd2dy(1,1), ktrd, ctype, clpas
+   END SUBROUTINE trd_2d
+   SUBROUTINE trd_3d( ptrd3dx, ptrd3dy, ktrd , ctype, clpas )       ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   ptrd3dx, ptrd3dy
+      INTEGER                     , INTENT(in   ) ::   ktrd         ! tracer trend index
+      CHARACTER(len=3)            , INTENT(in   ) ::   ctype        ! momentum ('DYN') or tracers ('TRA') trends
+      CHARACTER(len=3), INTENT(in), OPTIONAL ::   clpas             ! number of passage
+      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', &
+          &       ptrd3dx(1,1,1), ptrd3dy(1,1,1), ktrd, ctype, clpas
+   END SUBROUTINE trd_3d
+   SUBROUTINE trd_icp_init               ! Empty routine
+   END SUBROUTINE trd_icp_init
+   SUBROUTINE trd_dwr( kt )          ! Empty routine
+      WRITE(*,*) 'trd_dwr: You should not have seen this print! error ?', kt
+   END SUBROUTINE trd_dwr
+   SUBROUTINE trd_twr( kt )          ! Empty routine
+      WRITE(*,*) 'trd_twr: You should not have seen this print! error ?', kt
+   END SUBROUTINE trd_twr
+#endif
+
+   !!======================================================================
+END MODULE trdicp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdicp_oce.F90	(revision 4536)
@@ -0,0 +1,39 @@
+MODULE trdicp_oce
+   !!======================================================================
+   !!                   ***  MODULE trdicp_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   'key_trdtra'   or                         tracer trends diagnostics
+   !!   'key_trddyn'                            momentum trends diagnostics
+   !!----------------------------------------------------------------------
+   USE par_oce                 ! ocean parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !! Momentum trends diagnostics parameters
+   !!---------------------------------------------------------------------
+   INTEGER, PARAMETER ::   &  !: => dynamic trends indexes <=
+        jpicpd_hpg =  1,   &  !: hydrostatic pressure gradient 
+        jpicpd_keg =  2,   &  !: kinetic energy gradient
+        jpicpd_rvo =  3,   &  !: relative vorticity
+        jpicpd_pvo =  4,   &  !: planetary vorticity
+        jpicpd_ldf =  5,   &  !: lateral diffusion
+        jpicpd_zad =  6,   &  !: vertical advection
+        jpicpd_zdf =  7,   &  !: vertical diffusion
+        jpicpd_spg =  8,   &  !: surface pressure gradient
+        jpicpd_dat =  9,   &  !: damping term
+        jpicpd_swf = 10,   &  !: surface wind forcing
+        jpicpd_bfr = 11       !: bottom friction 
+
+   INTEGER, PARAMETER ::   &  !: => Total dynamic trends indexes <=
+        jptot_dyn = 11        !: change it when adding/removing one indice above
+   
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trdicp_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 4536)
@@ -0,0 +1,960 @@
+MODULE trdmld
+   !!======================================================================
+   !!                       ***  MODULE  trdmld  ***
+   !! Ocean diagnostics:  mixed layer T-S trends 
+   !!=====================================================================
+   !! History :       !  95-04  (J. Vialard)    Original code
+   !!                 !  97-02  (E. Guilyardi)  Adaptation global + base cmo
+   !!                 !  99-09  (E. Guilyardi)  Re-writing + netCDF output
+   !!            8.5  !  02-06  (G. Madec)      F90: Free form and module
+   !!            9.0  !  04-08  (C. Talandier)  New trends organization
+   !!                 !  05-05  (C. Deltel)     Diagnose trends of time averaged ML T & S
+   !!----------------------------------------------------------------------
+#if   defined key_trdmld   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trdmld'                          mixed layer trend diagnostics
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   trd_mld          : T and S cumulated trends averaged over the mixed layer
+   !!   trd_mld_zint     : T and S trends vertical integration
+   !!   trd_mld_init     : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE trdmod_oce      ! ocean variables trends
+   USE ldftra_oce      ! ocean active tracers lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! Define parameters for the routines
+   USE daymod          ! calendar
+   USE dianam          ! build the name of file (routine)
+   USE ldfslp          ! iso-neutral slopes 
+   USE zdfmxl          ! mixed layer depth
+   USE zdfddm          ! ocean vertical physics: double diffusion
+   USE ioipsl          ! NetCDF library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE diadimg         ! dimg direct access file format output
+   USE trdmld_rst      ! restart for diagnosing the ML trends
+   USE prtctl          ! Print control
+   USE restart         ! for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_mld        ! routine called by step.F90
+   PUBLIC   trd_mld_init   ! routine called by opa.F90
+   PUBLIC   trd_mld_zint   ! routine called by tracers routines
+
+   CHARACTER (LEN=40) ::  clhstnam         ! name of the trends NetCDF file
+   INTEGER ::   nh_t, nmoymltrd
+   INTEGER ::   nidtrd, ndextrd1(jpi*jpj)
+   INTEGER ::   ndimtrd1                        
+   INTEGER ::   ionce, icount                   
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mld_zint  ***
+      !! 
+      !! ** Purpose :   Compute the vertical average of the 3D fields given as arguments 
+      !!                to the subroutine. This vertical average is performed from ocean
+      !!                surface down to a chosen control surface.
+      !!
+      !! ** Method/usage :
+      !!      The control surface can be either a mixed layer depth (time varying)
+      !!      or a fixed surface (jk level or bowl). 
+      !!      Choose control surface with nctls in namelist NAMTRD :
+      !!        nctls = 0  : use mixed layer with density criterion 
+      !!        nctls = 1  : read index from file 'ctlsurf_idx'
+      !!        nctls > 1  : use fixed level surface jk = nctls
+      !!      Note: in the remainder of the routine, the volume between the 
+      !!            surface and the control surface is called "mixed-layer"
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   ktrd                             ! ocean trend index
+      CHARACTER(len=2), INTENT( in ) :: ctype                     ! surface/bottom (2D arrays) or
+      !                                                           ! interior (3D arrays) physics
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  pttrdmld ! temperature trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  pstrdmld ! salinity trend 
+      INTEGER ::   ji, jj, jk, isum
+      REAL(wp), DIMENSION(jpi,jpj) ::  zvlmsk
+      !!----------------------------------------------------------------------
+
+      ! I. Definition of control surface and associated fields
+      ! ------------------------------------------------------
+      !            ==> only once per time step <== 
+
+      IF( icount == 1 ) THEN        
+         !
+         tmltrd(:,:,:) = 0.e0    ;    smltrd(:,:,:) = 0.e0    ! <<< reset trend arrays to zero
+         
+         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
+         IF( nctls == 0 ) THEN       ! * control surface = mixed-layer with density criterion 
+            nmld(:,:) = nmln(:,:)    ! array nmln computed in zdfmxl.F90
+         ELSE IF( nctls == 1 ) THEN  ! * control surface = read index from file 
+            nmld(:,:) = nbol(:,:)
+         ELSE IF( nctls >= 2 ) THEN  ! * control surface = model level
+            nctls = MIN( nctls, jpktrd - 1 )
+            nmld(:,:) = nctls + 1
+         ENDIF
+
+         ! ... Compute ndextrd1 and ndimtrd1 only once
+         IF( ionce == 1 ) THEN
+            !
+            ! Check of validity : nmld(ji,jj) <= jpktrd
+            isum        = 0
+            zvlmsk(:,:) = 0.e0
+
+            IF( jpktrd < jpk ) THEN 
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( nmld(ji,jj) <= jpktrd ) THEN
+                        zvlmsk(ji,jj) = tmask(ji,jj,1)
+                     ELSE
+                        isum = isum + 1
+                        zvlmsk(ji,jj) = 0.
+                     ENDIF
+                  END DO
+               END DO
+            ENDIF
+
+            ! Index of ocean points (2D only)
+            IF( isum > 0 ) THEN
+               WRITE(numout,*)' Number of invalid points nmld > jpktrd', isum 
+               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )    ! surface
+            ELSE 
+               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )    ! surface
+            ENDIF                                
+
+            ionce = 0                ! no more pass here
+            !
+         END IF
+         
+         ! ... Weights for vertical averaging
+         wkx(:,:,:) = 0.e0
+         DO jk = 1, jpktrd             ! initialize wkx with vertical scale factor in mixed-layer
+            DO jj = 1,jpj
+               DO ji = 1,jpi
+                  IF( jk - nmld(ji,jj) < 0.e0 )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         
+         rmld(:,:) = 0.e0                ! compute mixed-layer depth : rmld
+         DO jk = 1, jpktrd
+            rmld(:,:) = rmld(:,:) + wkx(:,:,jk)
+         END DO
+         
+         DO jk = 1, jpktrd             ! compute integration weights
+            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1., rmld(:,:) )
+         END DO
+
+         icount = 0                    ! <<< flag = off : control surface & integr. weights
+         !                             !     computed only once per time step
+      END IF
+
+      ! II. Vertical integration of trends in the mixed-layer
+      ! -----------------------------------------------------
+
+      SELECT CASE (ctype)
+      CASE ( '3D' )   ! mean T/S trends in the mixed-layer
+         DO jk = 1, jpktrd
+            tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,jk) * wkx(:,:,jk)   ! temperature
+            smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,jk) * wkx(:,:,jk)   ! salinity
+         END DO
+      CASE ( '2D' )   ! forcing at upper boundary of the mixed-layer
+         tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,1) * wkx(:,:,1)        ! non penetrative
+         smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,1) * wkx(:,:,1)            
+      END SELECT
+      !
+   END SUBROUTINE trd_mld_zint
+    
+
+   SUBROUTINE trd_mld( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mld  ***
+      !! 
+      !! ** Purpose :  Compute and cumulate the mixed layer trends over an analysis
+      !!               period, and write NetCDF (or dimg) outputs.
+      !!
+      !! ** Method/usage :
+      !!          The stored trends can be chosen twofold (according to the ln_trdmld_instant 
+      !!          logical namelist variable) :
+      !!          1) to explain the difference between initial and final 
+      !!             mixed-layer T & S (where initial and final relate to the
+      !!             current analysis window, defined by ntrd in the namelist)
+      !!          2) to explain the difference between the current and previous 
+      !!             TIME-AVERAGED mixed-layer T & S (where time-averaging is
+      !!             performed over each analysis window).
+      !!
+      !! ** Consistency check : 
+      !!        If the control surface is fixed ( nctls > 1 ), the residual term (dh/dt
+      !!        entrainment) should be zero, at machine accuracy. Note that in the case
+      !!        of time-averaged mixed-layer fields, this residual WILL NOT BE ZERO
+      !!        over the first two analysis windows (except if restart).
+      !!        N.B. For ORCA2_LIM, use e.g. ntrd=5, ucf=1., nctls=8
+      !!             for checking residuals.
+      !!             On a NEC-SX5 computer, this typically leads to:
+      !!                   O(1.e-20) temp. residuals (tml_res) when ln_trdmld_instant=.false.
+      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmld_instant=.true.
+      !!
+      !! ** Action :
+      !!       At each time step, mixed-layer averaged trends are stored in the 
+      !!       tmltrd(:,:,jpmld_xxx) array (see trdmld_oce.F90 for definitions of jpmld_xxx).
+      !!       This array is known when trd_mld is called, at the end of the stp subroutine, 
+      !!       except for the purely vertical K_z diffusion term, which is embedded in the
+      !!       lateral diffusion trend.
+      !!
+      !!       In I), this K_z term is diagnosed and stored, thus its contribution is removed
+      !!       from the lateral diffusion trend.
+      !!       In II), the instantaneous mixed-layer T & S are computed, and misc. cumulative
+      !!       arrays are updated.
+      !!       In III), called only once per analysis window, we compute the total trends,
+      !!       along with the residuals and the Asselin correction terms.
+      !!       In IV), the appropriate trends are written in the trends NetCDF file.
+      !!
+      !! References :
+      !!       - Vialard & al.
+      !!       - See NEMO documentation (in preparation)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER :: ji, jj, jk, jl, ik, it
+      LOGICAL :: lldebug = .TRUE.
+      REAL(wp) :: zavt, zfn, zfn2
+      REAL(wp) ,DIMENSION(jpi,jpj) ::     &
+           ztmltot,  zsmltot,             & ! dT/dt over the anlysis window (including Asselin)
+           ztmlres,  zsmlres,             & ! residual = dh/dt entrainment term
+           ztmlatf,  zsmlatf,             & ! needed for storage only
+           ztmltot2, ztmlres2, ztmltrdm2, & ! \  working arrays to diagnose the trends
+           zsmltot2, zsmlres2, zsmltrdm2, & !  > associated with the time meaned ML T & S
+           ztmlatf2, zsmlatf2               ! /
+      REAL(wp), DIMENSION(jpi,jpj,jpltrd) ::  &
+           ztmltrd2, zsmltrd2               ! only needed for mean diagnostics
+#if defined key_dimgout
+      INTEGER ::  iyear,imon,iday
+      CHARACTER(LEN=80) :: cltext, clmode
+#endif
+      !!----------------------------------------------------------------------
+      
+
+      ! ======================================================================
+      ! I. Diagnose the purely vertical (K_z) diffusion trend
+      ! ======================================================================
+
+      ! ... These terms can be estimated by flux computation at the lower boundary of the ML 
+      !     (we compute (-1/h) * K_z * d_z( T ) and (-1/h) * K_z * d_z( S ))
+      IF( ln_traldf_iso ) THEN
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               ik = nmld(ji,jj)
+               zavt = avt(ji,jj,ik)
+               tmltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+                  &                      * ( tn(ji,jj,ik-1) - tn(ji,jj,ik) )         &
+                  &                      / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
+               zavt = fsavs(ji,jj,ik)
+               smltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+                  &                      * ( sn(ji,jj,ik-1) - sn(ji,jj,ik) )         &
+                  &                      / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+
+         ! ... Remove this K_z trend from the iso-neutral diffusion term (if any)
+         tmltrd(:,:,jpmld_ldf) = tmltrd(:,:,jpmld_ldf) - tmltrd(:,:,jpmld_zdf)
+         smltrd(:,:,jpmld_ldf) = smltrd(:,:,jpmld_ldf) - smltrd(:,:,jpmld_zdf)
+      END IF
+
+      ! ... Lateral boundary conditions
+      DO jl = 1, jpltrd
+         CALL lbc_lnk( tmltrd(:,:,jl), 'T', 1. )
+         CALL lbc_lnk( smltrd(:,:,jl), 'T', 1. )
+      END DO
+
+      ! ======================================================================
+      ! II. Cumulate the trends over the analysis window
+      ! ======================================================================
+
+      ztmltrd2(:,:,:) = 0.e0   ;    zsmltrd2(:,:,:) = 0.e0  ! <<< reset arrays to zero
+      ztmltot2(:,:)   = 0.e0   ;    zsmltot2(:,:)   = 0.e0
+      ztmlres2(:,:)   = 0.e0   ;    zsmlres2(:,:)   = 0.e0
+      ztmlatf2(:,:)   = 0.e0   ;    zsmlatf2(:,:)   = 0.e0
+
+      ! II.1 Set before values of vertically average T and S 
+      ! ----------------------------------------------------
+      IF( kt > nit000 ) THEN
+         !   ... temperature ...                    ... salinity ...
+         tmlb   (:,:) = tml   (:,:)           ; smlb   (:,:) = sml   (:,:)
+         tmlatfn(:,:) = tmltrd(:,:,jpmld_atf) ; smlatfn(:,:) = smltrd(:,:,jpmld_atf)
+      END IF
+
+      ! II.2 Vertically averaged T and S
+      ! --------------------------------
+      tml(:,:) = 0.e0   ;   sml(:,:) = 0.e0
+      DO jk = 1, jpktrd - 1
+         tml(:,:) = tml(:,:) + wkx(:,:,jk) * tn(:,:,jk)
+         sml(:,:) = sml(:,:) + wkx(:,:,jk) * sn(:,:,jk) 
+      END DO
+
+      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window    
+      ! ------------------------------------------------------------------------
+      IF( kt == 2 ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
+         !
+         !   ... temperature ...                ... salinity ...
+         tmlbb  (:,:) = tmlb   (:,:)   ;   smlbb  (:,:) = smlb   (:,:)
+         tmlbn  (:,:) = tml    (:,:)   ;   smlbn  (:,:) = sml    (:,:)
+         tmlatfb(:,:) = tmlatfn(:,:)   ;   smlatfb(:,:) = smlatfn(:,:)
+         
+         tmltrd_csum_ub (:,:,:) = 0.e0  ;   smltrd_csum_ub (:,:,:) = 0.e0
+         tmltrd_atf_sumb(:,:)   = 0.e0  ;   smltrd_atf_sumb(:,:)   = 0.e0
+
+         rmldbn(:,:) = rmld(:,:)
+
+         IF( ln_ctl ) THEN
+            WRITE(numout,*) '             we reach kt == nit000 + 1 = ', nit000+1
+            CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+         END IF
+         !
+      END IF
+
+      IF( ( ln_rstart ) .AND. ( kt == nit000 ) .AND. ( ln_ctl ) ) THEN
+         IF( ln_trdmld_instant ) THEN
+            WRITE(numout,*) '             restart from kt == nit000 = ', nit000
+            CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+         ELSE
+            WRITE(numout,*) '             restart from kt == nit000 = ', nit000
+            CALL prt_ctl(tab2d_1=tmlbn          , clinfo1=' tmlbn           -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=rmldbn         , clinfo1=' rmldbn          -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tml_sumb       , clinfo1=' tml_sumb        -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub  -  : ', mask1=tmask, ovlap=1, kdim=1)
+         END IF
+      END IF
+
+      ! II.4 Cumulated trends over the analysis period
+      ! ----------------------------------------------
+      !
+      !         [  1rst analysis window ] [     2nd analysis window     ]                       
+      !
+      !     o---[--o-----o-----o-----o--]-[--o-----o-----o-----o-----o--]---o-----o--> time steps
+      !                            ntrd                             2*ntrd       etc.
+      !     1      2     3     4    =5 e.g.                          =10
+      !
+      IF( ( kt >= 2 ).OR.( ln_rstart ) ) THEN
+         !
+         nmoymltrd = nmoymltrd + 1
+         
+         ! ... Cumulate over BOTH physical contributions AND over time steps
+         DO jl = 1, jpltrd
+            tmltrdm(:,:) = tmltrdm(:,:) + tmltrd(:,:,jl)
+            smltrdm(:,:) = smltrdm(:,:) + smltrd(:,:,jl)
+         END DO
+
+         ! ... Special handling of the Asselin trend 
+         tmlatfm(:,:) = tmlatfm(:,:) + tmlatfn(:,:)
+         smlatfm(:,:) = smlatfm(:,:) + smlatfn(:,:)
+
+         ! ... Trends associated with the time mean of the ML T/S
+         tmltrd_sum    (:,:,:) = tmltrd_sum    (:,:,:) + tmltrd    (:,:,:) ! tem
+         tmltrd_csum_ln(:,:,:) = tmltrd_csum_ln(:,:,:) + tmltrd_sum(:,:,:)
+         tml_sum       (:,:)   = tml_sum       (:,:)   + tml       (:,:)
+         smltrd_sum    (:,:,:) = smltrd_sum    (:,:,:) + smltrd    (:,:,:) ! sal
+         smltrd_csum_ln(:,:,:) = smltrd_csum_ln(:,:,:) + smltrd_sum(:,:,:)
+         sml_sum       (:,:)   = sml_sum       (:,:)   + sml       (:,:)
+         rmld_sum      (:,:)   = rmld_sum      (:,:)   + rmld      (:,:)   ! rmld
+         !
+      END IF
+
+      ! ======================================================================
+      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
+      ! ======================================================================
+
+      ! Convert to appropriate physical units
+      ! N.B. It may be useful to check IOIPSL time averaging with :
+      !      tmltrd (:,:,:) = 1. ; smltrd (:,:,:) = 1.
+      tmltrd(:,:,:) = tmltrd(:,:,:) * ucf   ! (actually needed for 1:jpltrd-1, but trdmld(:,:,jpltrd)
+      smltrd(:,:,:) = smltrd(:,:,:) * ucf   !  is no longer used, and is reset to 0. at next time step)
+      
+      MODULO_NTRD : IF( MOD( kt, ntrd ) == 0 ) THEN        ! nitend MUST be multiple of ntrd
+         !
+         ztmltot (:,:) = 0.e0   ;   zsmltot (:,:) = 0.e0   ! reset arrays to zero
+         ztmlres (:,:) = 0.e0   ;   zsmlres (:,:) = 0.e0
+         ztmltot2(:,:) = 0.e0   ;   zsmltot2(:,:) = 0.e0
+         ztmlres2(:,:) = 0.e0   ;   zsmlres2(:,:) = 0.e0
+      
+         zfn  = float(nmoymltrd)    ;    zfn2 = zfn * zfn
+         
+         ! III.1 Prepare fields for output ("instantaneous" diagnostics) 
+         ! -------------------------------------------------------------
+         
+         !-- Compute total trends
+         ztmltot(:,:) = ( tml(:,:) - tmlbn(:,:) + tmlb(:,:) - tmlbb(:,:) ) / ( 2.*rdt )
+         zsmltot(:,:) = ( sml(:,:) - smlbn(:,:) + smlb(:,:) - smlbb(:,:) ) / ( 2.*rdt )
+         
+         !-- Compute residuals
+         ztmlres(:,:) = ztmltot(:,:) - ( tmltrdm(:,:) - tmlatfn(:,:) + tmlatfb(:,:) )
+         zsmlres(:,:) = zsmltot(:,:) - ( smltrdm(:,:) - smlatfn(:,:) + smlatfb(:,:) )
+      
+         !-- Diagnose Asselin trend over the analysis window 
+         ztmlatf(:,:) = tmlatfm(:,:) - tmlatfn(:,:) + tmlatfb(:,:)
+         zsmlatf(:,:) = smlatfm(:,:) - smlatfn(:,:) + smlatfb(:,:)
+         
+         !-- Lateral boundary conditions
+         !         ... temperature ...                    ... salinity ...
+         CALL lbc_lnk( ztmltot , 'T', 1. )  ;   CALL lbc_lnk( zsmltot , 'T', 1. )
+         CALL lbc_lnk( ztmlres , 'T', 1. )  ;   CALL lbc_lnk( zsmlres , 'T', 1. )
+         CALL lbc_lnk( ztmlatf , 'T', 1. )  ;   CALL lbc_lnk( zsmlatf , 'T', 1. )
+
+#if defined key_diainstant
+         CALL ctl_stop( 'tml_trd : key_diainstant was never checked within trdmld. Comment this to proceed.')
+#endif
+         ! III.2 Prepare fields for output ("mean" diagnostics) 
+         ! ----------------------------------------------------
+         
+         !-- Update the ML depth time sum (to build the Leap-Frog time mean)
+         rmld_sum(:,:) = rmldbn(:,:) + 2 * ( rmld_sum(:,:) - rmld(:,:) ) + rmld(:,:)
+
+         !-- Compute temperature total trends
+         tml_sum (:,:) = tmlbn(:,:) + 2 * ( tml_sum(:,:) - tml(:,:) ) + tml(:,:)
+         ztmltot2(:,:) = ( tml_sum(:,:) - tml_sumb(:,:) ) /  ( 2.*rdt )    ! now in degC/s
+         
+         !-- Compute salinity total trends
+         sml_sum (:,:) = smlbn(:,:) + 2 * ( sml_sum(:,:) - sml(:,:) ) + sml(:,:)
+         zsmltot2(:,:) = ( sml_sum(:,:) - sml_sumb(:,:) ) /  ( 2.*rdt )    ! now in psu/s
+         
+         !-- Compute temperature residuals
+         DO jl = 1, jpltrd
+            ztmltrd2(:,:,jl) = tmltrd_csum_ub(:,:,jl) + tmltrd_csum_ln(:,:,jl)
+         END DO
+
+         ztmltrdm2(:,:) = 0.e0
+         DO jl = 1, jpltrd
+            ztmltrdm2(:,:) = ztmltrdm2(:,:) + ztmltrd2(:,:,jl)
+         END DO
+
+         ztmlres2(:,:) =  ztmltot2(:,:)  -       &
+              ( ztmltrdm2(:,:) - tmltrd_sum(:,:,jpmld_atf) + tmltrd_atf_sumb(:,:) )
+         
+         !-- Compute salinity residuals
+         DO jl = 1, jpltrd
+            zsmltrd2(:,:,jl) = smltrd_csum_ub(:,:,jl) + smltrd_csum_ln(:,:,jl)
+         END DO
+
+         zsmltrdm2(:,:) = 0.
+         DO jl = 1, jpltrd
+            zsmltrdm2(:,:) = zsmltrdm2(:,:) + zsmltrd2(:,:,jl)
+         END DO
+
+         zsmlres2(:,:) =  zsmltot2(:,:)  -       &
+              ( zsmltrdm2(:,:) - smltrd_sum(:,:,jpmld_atf) + smltrd_atf_sumb(:,:) )
+         
+         !-- Diagnose Asselin trend over the analysis window
+         ztmlatf2(:,:) = ztmltrd2(:,:,jpmld_atf) - tmltrd_sum(:,:,jpmld_atf) + tmltrd_atf_sumb(:,:)
+         zsmlatf2(:,:) = zsmltrd2(:,:,jpmld_atf) - smltrd_sum(:,:,jpmld_atf) + smltrd_atf_sumb(:,:)
+
+         !-- Lateral boundary conditions
+         !         ... temperature ...                    ... salinity ...
+         CALL lbc_lnk( ztmltot2, 'T', 1. )  ;   CALL lbc_lnk( zsmltot2, 'T', 1. )
+         CALL lbc_lnk( ztmlres2, 'T', 1. )  ;   CALL lbc_lnk( zsmlres2, 'T', 1. )
+         DO jl = 1, jpltrd
+            CALL lbc_lnk( ztmltrd2(:,:,jl), 'T', 1. ) ! \  these will be output
+            CALL lbc_lnk( zsmltrd2(:,:,jl), 'T', 1. ) ! /  in the NetCDF trends file
+         END DO
+         
+         ! III.3 Time evolution array swap
+         ! -------------------------------
+         
+         ! For T/S instantaneous diagnostics 
+         !   ... temperature ...               ... salinity ...
+         tmlbb  (:,:) = tmlb   (:,:)  ;   smlbb  (:,:) = smlb   (:,:)
+         tmlbn  (:,:) = tml    (:,:)  ;   smlbn  (:,:) = sml    (:,:)
+         tmlatfb(:,:) = tmlatfn(:,:)  ;   smlatfb(:,:) = smlatfn(:,:)
+
+         ! For T mean diagnostics 
+         tmltrd_csum_ub (:,:,:) = zfn * tmltrd_sum(:,:,:) - tmltrd_csum_ln(:,:,:)
+         tml_sumb       (:,:)   = tml_sum(:,:)
+         tmltrd_atf_sumb(:,:)   = tmltrd_sum(:,:,jpmld_atf)
+         
+         ! For S mean diagnostics 
+         smltrd_csum_ub (:,:,:) = zfn * smltrd_sum(:,:,:) - smltrd_csum_ln(:,:,:)
+         sml_sumb       (:,:)   = sml_sum(:,:)
+         smltrd_atf_sumb(:,:)   = smltrd_sum(:,:,jpmld_atf)
+         
+         ! ML depth
+         rmldbn         (:,:)   = rmld    (:,:)
+         
+         IF( ln_ctl ) THEN
+            IF( ln_trdmld_instant ) THEN
+               CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+            ELSE
+               CALL prt_ctl(tab2d_1=tmlbn          , clinfo1=' tmlbn           -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=rmldbn         , clinfo1=' rmldbn          -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tml_sumb       , clinfo1=' tml_sumb        -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub  -  : ', mask1=tmask, ovlap=1, kdim=1)
+            END IF
+         END IF
+
+         ! III.4 Convert to appropriate physical units
+         ! -------------------------------------------
+
+         !    ... temperature ...                         ... salinity ...
+         ztmltot (:,:)   = ztmltot(:,:)   * ucf/zfn  ; zsmltot (:,:)   = zsmltot(:,:)   * ucf/zfn
+         ztmlres (:,:)   = ztmlres(:,:)   * ucf/zfn  ; zsmlres (:,:)   = zsmlres(:,:)   * ucf/zfn
+         ztmlatf (:,:)   = ztmlatf(:,:)   * ucf/zfn  ; zsmlatf (:,:)   = zsmlatf(:,:)   * ucf/zfn
+
+         tml_sum (:,:)   = tml_sum (:,:)  /  (2*zfn) ; sml_sum (:,:)   = sml_sum (:,:)  /  (2*zfn)
+         ztmltot2(:,:)   = ztmltot2(:,:)  * ucf/zfn2 ; zsmltot2(:,:)   = zsmltot2(:,:)  * ucf/zfn2
+         ztmltrd2(:,:,:) = ztmltrd2(:,:,:)* ucf/zfn2 ; zsmltrd2(:,:,:) = zsmltrd2(:,:,:)* ucf/zfn2
+         ztmlatf2(:,:)   = ztmlatf2(:,:)  * ucf/zfn2 ; zsmlatf2(:,:)   = zsmlatf2(:,:)  * ucf/zfn2
+         ztmlres2(:,:)   = ztmlres2(:,:)  * ucf/zfn2 ; zsmlres2(:,:)   = zsmlres2(:,:)  * ucf/zfn2
+
+         rmld_sum(:,:)   = rmld_sum(:,:)  /  (2*zfn)  ! similar to tml_sum and sml_sum
+
+         ! * Debugging information *
+         IF( lldebug ) THEN
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) 'trd_mld : write trends in the Mixed Layer for debugging process:'
+            WRITE(numout,*) '~~~~~~~  '
+            WRITE(numout,*) '          TRA kt = ', kt, 'nmoymltrd = ', nmoymltrd
+            WRITE(numout,*)
+            WRITE(numout,*) '          >>>>>>>>>>>>>>>>>>  TRA TEMPERATURE <<<<<<<<<<<<<<<<<<'
+            WRITE(numout,*) '          TRA ztmlres    : ', SUM(ztmlres(:,:))
+            WRITE(numout,*) '          TRA ztmltot    : ', SUM(ztmltot(:,:))
+            WRITE(numout,*) '          TRA tmltrdm    : ', SUM(tmltrdm(:,:))
+            WRITE(numout,*) '          TRA tmlatfb    : ', SUM(tmlatfb(:,:))
+            WRITE(numout,*) '          TRA tmlatfn    : ', SUM(tmlatfn(:,:))
+            DO jl = 1, jpltrd
+               WRITE(numout,*) '          * TRA TREND INDEX jpmld_xxx = jl = ', jl, &
+                    & ' tmltrd : ', SUM(tmltrd(:,:,jl))
+            END DO
+            WRITE(numout,*) '          TRA ztmlres (jpi/2,jpj/2) : ', ztmlres (jpi/2,jpj/2)
+            WRITE(numout,*) '          TRA ztmlres2(jpi/2,jpj/2) : ', ztmlres2(jpi/2,jpj/2)
+            WRITE(numout,*)
+            WRITE(numout,*) '          >>>>>>>>>>>>>>>>>>  TRA SALINITY <<<<<<<<<<<<<<<<<<'
+            WRITE(numout,*) '          TRA zsmlres    : ', SUM(zsmlres(:,:))
+            WRITE(numout,*) '          TRA zsmltot    : ', SUM(zsmltot(:,:))
+            WRITE(numout,*) '          TRA smltrdm    : ', SUM(smltrdm(:,:))
+            WRITE(numout,*) '          TRA smlatfb    : ', SUM(smlatfb(:,:))
+            WRITE(numout,*) '          TRA smlatfn    : ', SUM(smlatfn(:,:))
+            DO jl = 1, jpltrd
+               WRITE(numout,*) '          * TRA TREND INDEX jpmld_xxx = jl = ', jl, &
+                    & ' smltrd : ', SUM(smltrd(:,:,jl))
+            END DO
+            WRITE(numout,*) '          TRA zsmlres (jpi/2,jpj/2) : ', zsmlres (jpi/2,jpj/2)
+            WRITE(numout,*) '          TRA zsmlres2(jpi/2,jpj/2) : ', zsmlres2(jpi/2,jpj/2)
+            !
+         END IF
+         !
+      END IF MODULO_NTRD
+
+      ! ======================================================================
+      ! IV. Write trends in the NetCDF file
+      ! ======================================================================
+
+      ! IV.1 Code for dimg mpp output
+      ! -----------------------------
+
+#if defined key_dimgout
+
+      IF( MOD( kt, ntrd ) == 0 ) THEN
+         iyear =  ndastp/10000
+         imon  = (ndastp-iyear*10000)/100
+         iday  =  ndastp - imon*100 - iyear*10000
+         WRITE(clname,9000) TRIM(cexper),'MLDiags',iyear,imon,iday
+         WRITE(clmode,'(f5.1,a)') ntrd*rdt/86400.,' days average'
+         cltext = TRIM(cexper)//' mld diags'//TRIM(clmode)
+         CALL dia_wri_dimg (clname, cltext, smltrd, jpltrd, '2')
+      END IF
+
+9000  FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
+
+#else
+      
+      ! IV.2 Code for IOIPSL/NetCDF output
+      ! ----------------------------------
+
+      IF( lwp .AND. MOD( kt , ntrd ) == 0 ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trd_mld : write trends in the NetCDF file :'
+         WRITE(numout,*) '~~~~~~~  '
+         WRITE(numout,*) '          ', TRIM(clhstnam), ' at kt = ', kt
+         WRITE(numout,*) '          N.B. nmoymltrd = ', nmoymltrd
+         WRITE(numout,*) ' '
+      END IF
+         
+      it = kt - nit000 + 1
+
+      !-- Write the trends for T/S instantaneous diagnostics 
+      IF( ln_trdmld_instant ) THEN           
+
+         CALL histwrite( nidtrd, "mxl_depth", it, rmld(:,:), ndimtrd1, ndextrd1 )
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "tml"     , it, tml    (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_tot" , it, ztmltot(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_res" , it, ztmlres(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("tml"//ctrd(jl,2)),            &
+                 &          it, tmltrd (:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("tml"//ctrd(jpmld_atf,2)),        &
+              &          it, ztmlatf(:,:), ndimtrd1, ndextrd1 )
+         
+         !.................................. ( ML salinity ) .....................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "sml"     , it, sml    (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_tot" , it, zsmltot(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_res" , it, zsmlres(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("sml"//ctrd(jl,2)),            &
+                 &          it, smltrd(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("sml"//ctrd(jpmld_atf,2)),        &
+              &          it, zsmlatf(:,:), ndimtrd1, ndextrd1 )
+         
+         IF( kt == nitend )   CALL histclo( nidtrd )
+
+      !-- Write the trends for T/S mean diagnostics 
+      ELSE
+         
+         CALL histwrite( nidtrd, "mxl_depth", it, rmld_sum(:,:), ndimtrd1, ndextrd1 ) 
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "tml"     , it, tml_sum (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_tot" , it, ztmltot2(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_res" , it, ztmlres2(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("tml"//ctrd(jl,2)),            &
+                 &          it, ztmltrd2(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("tml"//ctrd(jpmld_atf,2)),        &
+              &          it, ztmlatf2(:,:), ndimtrd1, ndextrd1 )
+         
+         !.................................. ( ML salinity ) .....................................
+                     
+         !-- Output the fields
+         CALL histwrite( nidtrd, "sml"     , it, sml_sum (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_tot" , it, zsmltot2(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_res" , it, zsmlres2(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("sml"//ctrd(jl,2)),            &
+                 &          it, zsmltrd2(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("sml"//ctrd(jpmld_atf,2)),        &
+              &          it, zsmlatf2(:,:), ndimtrd1, ndextrd1 )
+         
+         IF( kt == nitend )   CALL histclo( nidtrd )
+
+      END IF
+      
+      ! Compute the control surface (for next time step) : flag = on
+      icount = 1
+      !
+#endif
+
+      IF( MOD( kt , ntrd ) == 0 ) THEN
+         !
+         ! III.5 Reset cumulative arrays to zero
+         ! -------------------------------------
+         nmoymltrd = 0
+         
+         !   ... temperature ...               ... salinity ...
+         tmltrdm        (:,:)   = 0.e0   ;   smltrdm        (:,:)   = 0.e0
+         tmlatfm        (:,:)   = 0.e0   ;   smlatfm        (:,:)   = 0.e0
+         tml_sum        (:,:)   = 0.e0   ;   sml_sum        (:,:)   = 0.e0
+         tmltrd_csum_ln (:,:,:) = 0.e0   ;   smltrd_csum_ln (:,:,:) = 0.e0
+         tmltrd_sum     (:,:,:) = 0.e0   ;   smltrd_sum     (:,:,:) = 0.e0
+
+         rmld_sum       (:,:)   = 0.e0
+         !
+      END IF
+
+      ! ======================================================================
+      ! V. Write restart file
+      ! ======================================================================
+
+      IF( lrst_oce )   CALL trd_mld_rst_write( kt ) 
+
+   END SUBROUTINE trd_mld
+
+
+   SUBROUTINE trd_mld_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mld_init  ***
+      !! 
+      !! ** Purpose :   computation of vertically integrated T and S budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER :: ilseq, jl
+
+      REAL(wp) ::   zjulian, zsto, zout
+
+      CHARACTER (LEN=21) ::    &
+         clold ='OLD'        , & ! open specifier (direct access files)
+         clunf ='UNFORMATTED', & ! open specifier (direct access files)
+         clseq ='SEQUENTIAL'     ! open specifier (direct access files)
+      CHARACTER (LEN=40) ::   clop
+      CHARACTER (LEN=12) ::   clmxl, cltu, clsu
+
+      !!----------------------------------------------------------------------
+
+      ! ======================================================================
+      ! I. initialization
+      ! ======================================================================
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mld_init : Mixed-layer trends'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~'
+         WRITE(numout,*) '                namelist namtrd read in trd_mod_init                        '
+         WRITE(numout,*)
+      END IF
+
+      ! I.1 Check consistency of user defined preferences
+      ! -------------------------------------------------
+
+      IF( ( lk_trdmld ) .AND. ( MOD( nitend, ntrd ) /= 0 ) ) THEN
+         WRITE(numout,cform_err)
+         WRITE(numout,*) '                Your nitend parameter, nitend = ', nitend
+         WRITE(numout,*) '                is no multiple of the trends diagnostics frequency        '
+         WRITE(numout,*) '                          you defined, ntrd   = ', ntrd
+         WRITE(numout,*) '                This will not allow you to restart from this simulation.  '
+         WRITE(numout,*) '                You should reconsider this choice.                        ' 
+         WRITE(numout,*) 
+         WRITE(numout,*) '                N.B. the nitend parameter is also constrained to be a     '
+         WRITE(numout,*) '                multiple of the sea-ice frequency parameter (typically 5) '
+         nstop = nstop + 1
+      END IF
+
+      IF( ( lk_trdmld ) .AND. ( n_cla == 1 ) ) THEN
+         WRITE(numout,cform_war)
+         WRITE(numout,*) '                You set n_cla = 1. Note that the Mixed-Layer diagnostics  '
+         WRITE(numout,*) '                are not exact along the corresponding straits.            '
+         nwarn = nwarn + 1
+      END IF
+
+      ! I.2 Initialize arrays to zero or read a restart file
+      ! ----------------------------------------------------
+
+      nmoymltrd = 0
+
+      !     ... temperature ...                  ... salinity ...
+      tml            (:,:)   = 0.e0    ;    sml            (:,:)   = 0.e0     ! inst.
+      tmltrdm        (:,:)   = 0.e0    ;    smltrdm        (:,:)   = 0.e0
+      tmlatfm        (:,:)   = 0.e0    ;    smlatfm        (:,:)   = 0.e0
+      tml_sum        (:,:)   = 0.e0    ;    sml_sum        (:,:)   = 0.e0     ! mean
+      tmltrd_sum     (:,:,:) = 0.e0    ;    smltrd_sum     (:,:,:) = 0.e0
+      tmltrd_csum_ln (:,:,:) = 0.e0    ;    smltrd_csum_ln (:,:,:) = 0.e0
+
+      rmld           (:,:)   = 0.e0            
+      rmld_sum       (:,:)   = 0.e0
+
+      IF( ln_rstart .AND. ln_trdmld_restart ) THEN
+         CALL trd_mld_rst_read
+      ELSE
+         !     ... temperature ...                  ... salinity ...
+         tmlb           (:,:)   = 0.e0    ;    smlb           (:,:)   = 0.e0  ! inst.
+         tmlbb          (:,:)   = 0.e0    ;    smlbb          (:,:)   = 0.e0  
+         tmlbn          (:,:)   = 0.e0    ;    smlbn          (:,:)   = 0.e0  
+         tml_sumb       (:,:)   = 0.e0    ;    sml_sumb       (:,:)   = 0.e0  ! mean
+         tmltrd_csum_ub (:,:,:) = 0.e0    ;    smltrd_csum_ub (:,:,:) = 0.e0
+         tmltrd_atf_sumb(:,:)   = 0.e0    ;    smltrd_atf_sumb(:,:)   = 0.e0  
+      END IF
+
+      ilseq  = 1   ;   icount = 1   ;   ionce  = 1                            ! open specifier
+
+      ! I.3 Read control surface from file ctlsurf_idx
+      ! ----------------------------------------------
+ 
+      IF( nctls == 1 ) THEN
+         clname = 'ctlsurf_idx'
+         CALL ctlopn( numbol, clname, clold, clunf, clseq, ilseq, numout, lwp, 1 )
+         REWIND( numbol )
+         READ  ( numbol ) nbol
+      END IF
+
+      ! ======================================================================
+      ! II. netCDF output initialization
+      ! ======================================================================
+
+#if defined key_dimgout 
+      ???
+#else
+      ! clmxl = legend root for netCDF output
+      IF( nctls == 0 ) THEN      ! control surface = mixed-layer with density criterion
+         clmxl = 'Mixed Layer '  !                   (array nmln computed in zdfmxl.F90)
+      ELSE IF( nctls == 1 ) THEN ! control surface = read index from file 
+         clmxl = '      Bowl '
+      ELSE IF( nctls >= 2 ) THEN ! control surface = model level
+         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nctls
+      END IF
+
+      ! II.1 Define frequency of output and means
+      ! -----------------------------------------
+#  if defined key_diainstant
+      IF( .NOT. ln_trdmld_instant ) THEN
+         CALL ctl_stop( 'trd_mld : this was never checked. Comment this line to proceed...' )
+      END IF
+      zsto = ntrd * rdt
+      clop ="inst(only(x))"
+#  else
+      IF( ln_trdmld_instant ) THEN
+         zsto = rdt                 ! inst. diags : we use IOIPSL time averaging
+      ELSE
+         zsto = ntrd * rdt          ! mean  diags : we DO NOT use any IOIPSL time averaging
+      END IF
+      clop ="ave(only(x))"
+#  endif
+      zout = ntrd * rdt
+
+      IF(lwp) WRITE (numout,*) '                netCDF initialization'
+
+      ! II.2 Compute julian date from starting date of the run
+      ! ------------------------------------------------------
+      CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+      IF(lwp) WRITE(numout,*)' '  
+      IF(lwp) WRITE(numout,*)'                Date 0 used :',nit000,    &
+         &                   ' YEAR ', nyear,' MONTH '      , nmonth,   &
+         &                   ' DAY ' , nday, 'Julian day : ', zjulian
+
+
+      ! II.3 Define the T grid trend file (nidtrd)
+      ! ------------------------------------------
+      !-- Define long and short names for the NetCDF output variables
+      !       ==> choose them according to trdmld_oce.F90 <==
+
+      ctrd(jpmld_xad,1) = " Zonal advection"                  ;   ctrd(jpmld_xad,2) = "_xad"
+      ctrd(jpmld_yad,1) = " Meridional advection"             ;   ctrd(jpmld_yad,2) = "_yad"
+      ctrd(jpmld_zad,1) = " Vertical advection"               ;   ctrd(jpmld_zad,2) = "_zad"
+      ctrd(jpmld_ldf,1) = " Lateral diffusion"                ;   ctrd(jpmld_ldf,2) = "_ldf"
+      ctrd(jpmld_for,1) = " Forcing"                          ;   ctrd(jpmld_for,2) = "_for"
+      ctrd(jpmld_zdf,1) = " Vertical diff. (Kz)"              ;   ctrd(jpmld_zdf,2) = "_zdf"
+      ctrd(jpmld_bbc,1) = " Geothermal flux"                  ;   ctrd(jpmld_bbc,2) = "_bbc"
+      ctrd(jpmld_bbl,1) = " Adv/diff. Bottom boundary layer"  ;   ctrd(jpmld_bbl,2) = "_bbl"
+      ctrd(jpmld_dmp,1) = " Tracer damping"                   ;   ctrd(jpmld_dmp,2) = "_dmp"
+      ctrd(jpmld_npc,1) = " Non penetrative convec. adjust."  ;   ctrd(jpmld_npc,2) = "_npc"
+      ctrd(jpmld_atf,1) = " Asselin time filter"              ;   ctrd(jpmld_atf,2) = "_atf"
+                                                                  
+      !-- Create a NetCDF file and enter the define mode 
+      CALL dia_nam( clhstnam, ntrd, 'trends' )
+      IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
+      CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
+      &             1, jpi, 1, jpj, 0, zjulian, rdt, nh_t, nidtrd, domain_id=nidom )
+
+      !-- Define the ML depth variable
+      CALL histdef(nidtrd, "mxl_depth", clmxl//"  Mixed Layer Depth"              , "m",         &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+
+      !-- Define physical units
+      IF( ucf == 1. ) THEN
+         cltu = "degC/s"     ;   clsu = "p.s.u./s"
+      ELSEIF ( ucf == 3600.*24.) THEN
+         cltu = "degC/day"   ;   clsu = "p.s.u./day"
+      ELSE
+         cltu = "unknown?"   ;   clsu = "unknown?"
+      END IF
+
+      !-- Define miscellaneous T and S mixed-layer variables 
+
+      IF( jpltrd /= jpmld_atf ) CALL ctl_stop( 'Error : jpltrd /= jpmld_atf' ) ! see below
+
+      !................................. ( ML temperature ) ...................................
+
+      CALL histdef(nidtrd, "tml"      , clmxl//" T Mixed Layer Temperature"       ,  "C",        &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
+      CALL histdef(nidtrd, "tml_tot",   clmxl//" T Total trend"                   , cltu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )              
+      CALL histdef(nidtrd, "tml_res",   clmxl//" T dh/dt Entrainment (Resid.)"    , cltu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
+      
+      DO jl = 1, jpltrd - 1      ! <== only true if jpltrd == jpmld_atf
+         CALL histdef(nidtrd, trim("tml"//ctrd(jl,2)), clmxl//" T"//ctrd(jl,1), cltu,            & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+      END DO                                                                 ! if zsto=rdt above
+      
+      CALL histdef(nidtrd, trim("tml"//ctrd(jpmld_atf,2)), clmxl//" T"//ctrd(jpmld_atf,1), cltu, & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+      
+      !.................................. ( ML salinity ) .....................................
+     
+      CALL histdef(nidtrd, "sml"      , clmxl//" S Mixed Layer Salinity"          , "p.s.u.",       &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
+      CALL histdef(nidtrd, "sml_tot",   clmxl//" S Total trend"                   , clsu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )              
+      CALL histdef(nidtrd, "sml_res",   clmxl//" S dh/dt Entrainment (Resid.)"    , clsu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
+      
+      DO jl = 1, jpltrd - 1      ! <== only true if jpltrd == jpmld_atf
+         CALL histdef(nidtrd, trim("sml"//ctrd(jl,2)), clmxl//" S"//ctrd(jl,1), clsu,            & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+      END DO                                                                 ! if zsto=rdt above
+      
+      CALL histdef(nidtrd, trim("sml"//ctrd(jpmld_atf,2)), clmxl//" S"//ctrd(jpmld_atf,1), clsu, & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+
+      !-- Leave IOIPSL/NetCDF define mode
+      CALL histend( nidtrd )
+
+#endif        /* key_dimgout */
+   END SUBROUTINE trd_mld_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trd_mld( kt )             ! Empty routine
+      INTEGER, INTENT( in) ::   kt
+      WRITE(*,*) 'trd_mld: You should not have seen this print! error?', kt
+   END SUBROUTINE trd_mld
+   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
+      REAL, DIMENSION(:,:,:), INTENT( in ) ::   &
+         pttrdmld, pstrdmld                   ! Temperature and Salinity trends
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      CHARACTER(len=2), INTENT( in ) ::   &  
+         ctype                                ! surface/bottom (2D arrays) or
+         !                                    ! interior (3D arrays) physics
+      WRITE(*,*) 'trd_mld_zint: You should not have seen this print! error?', pttrdmld(1,1,1)
+      WRITE(*,*) '  "      "  : You should not have seen this print! error?', pstrdmld(1,1,1)
+      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ctype
+      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ktrd
+   END SUBROUTINE trd_mld_zint
+   SUBROUTINE trd_mld_init              ! Empty routine
+      WRITE(*,*) 'trd_mld_init: You should not have seen this print! error?'
+   END SUBROUTINE trd_mld_init
+#endif
+
+   !!======================================================================
+END MODULE trdmld
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 4536)
@@ -0,0 +1,89 @@
+MODULE trdmld_oce
+   !!======================================================================
+   !!                   ***  MODULE trdmld_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+   !! History :  9.0  !  04-08  (C. Talandier)  New trends organization
+   !!----------------------------------------------------------------------
+   USE par_oce         ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+#if defined key_trdmld
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .TRUE.    !: ML trend flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .FALSE.   !: ML trend flag
+#endif
+   !!* mixed layer trends indices
+   INTEGER, PARAMETER, PUBLIC ::   jpltrd = 11    !: number of mixed-layer trends arrays
+   INTEGER, PUBLIC   & 
+#if !defined key_agrif
+      , PARAMETER  &
+#endif
+::   jpktrd = jpk   !: max level for mixed-layer trends diag.
+   !
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_xad =  1   !:  zonal      
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_yad =  2   !:  meridonal   > advection
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_zad =  3   !:  vertical   
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_ldf =  4   !:  lateral diffusion (geopot. or iso-neutral)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_for =  5   !:  forcing 
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_zdf =  6   !:  vertical diffusion (TKE)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_bbc =  7   !:  geothermal flux
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_bbl =  8   !:  bottom boundary layer (advective/diffusive)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_dmp =  9   !:  internal restoring trend
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_npc = 10   !:  non penetrative convective adjustment
+!! INTEGER, PUBLIC, PARAMETER ::   jpmld_xxx = xx   !:  add here any additional trend (add change jpltrd)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_atf = 11   !:  asselin trend (**MUST BE THE LAST ONE**)
+
+#if   defined  key_trdmld   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trdmld'                         mixed layer trends diagnostics
+   !!----------------------------------------------------------------------
+
+   !! Arrays used for diagnosing mixed-layer trends 
+   !!---------------------------------------------------------------------
+   CHARACTER(LEN=80) , PUBLIC :: clname, ctrd(jpltrd+1,2)
+
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj)     ::   nmld   !: mixed layer depth indexes 
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj)     ::   nbol   !: mixed-layer depth indexes when read from file
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   wkx    !:
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+      rmld   ,                      & !: mld depth (m) corresponding to nmld
+      tml    , sml  ,               & !: \ "now" mixed layer temperature/salinity
+      tmlb   , smlb ,               & !: /  and associated "before" fields
+      tmlbb  , smlbb,               & !: \  idem, but valid at the 1rst time step of the
+      tmlbn  , smlbn,               & !: /  current analysis window
+      tmltrdm, smltrdm,             & !: total cumulative trends over the analysis window
+      tml_sum,                      & !: mixed layer T, summed over the current analysis period
+      tml_sumb,                     & !: idem, but from the previous analysis period
+      tmltrd_atf_sumb,              & !: Asselin trends, summed over the previous analysis period
+      sml_sum,                      & !: 
+      sml_sumb,                     & !:    ( idem for salinity )
+      smltrd_atf_sumb,              & !: 
+      rmld_sum, rmldbn                !: needed to compute the leap-frog time mean of the ML depth
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+      tmlatfb, tmlatfn ,            & !: "before" Asselin contribution at begining of the averaging
+      smlatfb, smlatfn,             & !: period (i.e. last contrib. from previous such period) and 
+                                      !: "now" Asselin contribution to the ML temp. & salinity trends
+      tmlatfm, smlatfm                !: accumulator for Asselin trends (needed for storage only)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpltrd) ::  &
+      tmltrd,                       & !: \ physical contributions to the total trend (for T/S),
+      smltrd,                       & !: / cumulated over the current analysis window
+      tmltrd_sum,                   & !: sum of these trends over the analysis period
+      tmltrd_csum_ln,               & !: now cumulated sum of the trends over the "lower triangle"
+      tmltrd_csum_ub,               & !: before (prev. analysis period) cumulated sum over the upper triangle
+      smltrd_sum,                   & !: 
+      smltrd_csum_ln,               & !:    ( idem for salinity )
+      smltrd_csum_ub                  !: 
+#endif
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trdmld_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_rst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 4536)
@@ -0,0 +1,193 @@
+MODULE trdmld_rst
+   !!=================================================================================
+   !!                       ***  MODULE  trdmld_rst  ***
+   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+   !!=================================================================================
+   !! History :  9.0  ! 05-05 (C. Deltel) Original code
+   !!---------------------------------------------------------------------------------
+#if defined key_trdmld
+   !!---------------------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod_oce      ! ocean variables for trend diagnostics (i.e. icp/mixed-layer/vorticity)
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE iom             ! I/O module
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+  
+   PUBLIC   trd_mld_rst_read    ! routine called by trd_mld_init
+   PUBLIC   trd_mld_rst_write   ! routine called by step.F90
+  
+   CHARACTER (len=48) ::   crestart = 'initial.nc'   ! restart file name
+   INTEGER ::   nummldw                              ! logical unit for mld restart
+
+   !!---------------------------------------------------------------------------------
+   !! OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRD/trdmld_rst.F90,v 1.7 2007/06/05 10:40:59 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!---------------------------------------------------------------------------------
+  
+CONTAINS
+  
+   SUBROUTINE trd_mld_rst_write( kt )
+      !!--------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trd_mld_rst_wri  ***
+      !!                
+      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
+      !!--------------------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      CHARACTER (len=35) :: charout
+      INTEGER ::   jk                 ! loop indice
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      !!--------------------------------------------------------------------------------
+
+      IF( kt == nitrst-1 ) THEN
+         IF( nitrst > 1.0e9 ) THEN   
+            WRITE(clkt,*) nitrst
+         ELSE
+            WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_mld"
+         IF(lwp) WRITE(numout,*) '             open ocean restart_mld NetCDF file: '//clname
+         CALL iom_open( clname, nummldw, ldwrt = .TRUE., kiolib = jprstlib )
+      ENDIF
+
+      IF( kt == nitrst .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trdmld_rst: output for ML diags. restart, with trd_mld_rst_write routine'
+         WRITE(numout,*) '~~~~~~~~~~'
+         WRITE(numout,*)
+      ENDIF
+
+      IF( ln_trdmld_instant ) THEN 
+         !-- Temperature
+         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbb'           , tmlbb           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbn'           , tmlbn           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'tmlatfb'         , tmlatfb         )
+
+         !-- Salinity
+         CALL iom_rstput( kt, nitrst, nummldw, 'smlbb'           , smlbb           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'smlbn'           , smlbn           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'smlatfb'         , smlatfb         )
+      ELSE
+         CALL iom_rstput( kt, nitrst, nummldw, 'rmldbn'          , rmldbn          )
+
+         !-- Temperature
+         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbn'           , tmlbn           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'tml_sumb'        , tml_sumb        )
+         DO jk = 1, jpltrd
+            IF( jk < 10 )   THEN
+               WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
+            ELSE
+               WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
+            ENDIF
+            CALL iom_rstput( kt, nitrst, nummldw, charout,  tmltrd_csum_ub(:,:,jk) )
+         ENDDO
+         CALL iom_rstput( kt, nitrst, nummldw, 'tmltrd_atf_sumb' , tmltrd_atf_sumb )
+
+         !-- Salinity
+         CALL iom_rstput( kt, nitrst, nummldw, 'smlbn'           , smlbn           )
+         CALL iom_rstput( kt, nitrst, nummldw, 'sml_sumb'        , sml_sumb        )
+         DO jk = 1, jpltrd
+            IF( jk < 10 )   THEN
+               WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
+            ELSE
+               WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
+            ENDIF
+            CALL iom_rstput( kt, nitrst, nummldw, charout , smltrd_csum_ub(:,:,jk) )
+         ENDDO
+         CALL iom_rstput( kt, nitrst, nummldw, 'smltrd_atf_sumb' , smltrd_atf_sumb )
+      ENDIF
+      !
+      IF( kt == nitrst ) THEN
+         CALL iom_close( nummldw )     ! close the restart file (only at last time step)
+         lrst_oce = .FALSE.
+      ENDIF
+      ! 
+      !    
+   END SUBROUTINE trd_mld_rst_write
+
+
+   SUBROUTINE trd_mld_rst_read
+    !!----------------------------------------------------------------------------
+    !!                   ***  SUBROUTINE trd_mld_rst_lec  ***
+    !!                   
+    !! ** Purpose :   Read file for mixed-layer diagnostics restart.
+    !!----------------------------------------------------------------------------
+    INTEGER  ::  inum       ! temporary logical unit
+    !
+    CHARACTER (len=35) :: charout
+    INTEGER ::   jk         ! loop indice
+    !!-----------------------------------------------------------------------------
+
+    IF(lwp)  THEN
+       WRITE(numout,*)
+       WRITE(numout,*) ' trd_mld_rst_read : read the NetCDF MLD restart file'
+       WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+    ENDIF
+
+    CALL iom_open( 'restart_mld', inum, kiolib = jprstlib ) 
+
+    IF( ln_trdmld_instant ) THEN 
+       !-- Temperature
+       CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
+       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
+       CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
+
+       !-- Salinity
+       CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
+       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
+       CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
+    ELSE
+       CALL iom_get( inum, jpdom_autoglo, 'rmldbn'          , rmldbn         ) ! needed for rmld_sum
+
+       !-- Temperature
+       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
+       CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
+       DO jk = 1, jpltrd
+          IF( jk < 10 )   THEN
+             WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
+          ELSE
+             WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
+          ENDIF
+          CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
+       ENDDO
+       CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
+
+       !-- Salinity
+       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
+       CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
+       DO jk = 1, jpltrd
+          IF( jk < 10 )   THEN
+             WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
+          ELSE
+             WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
+          ENDIF
+          CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
+       ENDDO
+       CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
+
+       CALL iom_close( inum )
+    ENDIF
+
+  END SUBROUTINE trd_mld_rst_read
+  
+#else
+  !!=================================================================================
+  !!                       ***  MODULE  trdmld_rst  ***
+  !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+  !!=================================================================================
+CONTAINS
+  SUBROUTINE trd_mld_rst_write( kt )           !  No ML diags ==> empty routine
+    WRITE(*,*) 'trd_mld_rst_wri: You should not have seen this print! error?', kt
+  END SUBROUTINE trd_mld_rst_write
+  SUBROUTINE trd_mld_rst_read                  !  No ML Diags ==> empty routine
+  END SUBROUTINE trd_mld_rst_read
+#endif
+
+  !!=================================================================================
+END MODULE trdmld_rst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 4536)
@@ -0,0 +1,436 @@
+MODULE trdmod
+   !!======================================================================
+   !!                       ***  MODULE  trdmod  ***
+   !! Ocean diagnostics:  ocean tracers and dynamic trends
+   !!=====================================================================
+   !! History :  9.0  !  04-08  (C. Talandier) Original code
+   !!                 !  05-04  (C. Deltel)    Add Asselin trend in the ML budget
+   !!----------------------------------------------------------------------
+#if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   trd_tra          : active tracer trend manager
+   !!   trd_tra_adv      : pre-treatment of the tracer advection trends
+   !!   trd_mod          : momentum trend manager
+   !!   trd_mod_init     : Initialization step
+   !!----------------------------------------------------------------------
+   USE phycst                  ! physical constants
+   USE oce                     ! ocean dynamics and tracers variables
+   USE dom_oce                 ! ocean space and time domain variables
+   USE zdf_oce                 ! ocean vertical physics variables
+   USE trdmod_oce              ! ocean variables trends
+   USE ldftra_oce              ! ocean active tracers lateral physics
+   USE trdvor                  ! ocean vorticity trends 
+   USE trdicp                  ! ocean bassin integral constraints properties
+   USE trdmld                  ! ocean active mixed layer tracers trends 
+   USE in_out_manager          ! I/O manager
+   USE taumod                  ! surface ocean stress
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp) ::   r2dt          ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
+
+   PUBLIC trd_tra              ! called by all traXXX.F90 modules
+   PUBLIC trd_tra_adv          ! called by all traadv_XXX.F90 modules
+   PUBLIC trd_mod              ! called by all dynXXX.F90 modules
+   PUBLIC trd_mod_init         ! called by opa.F90 module
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trd_tra( kt, ktra, ktrd, ctype, ptrd2d, ptrd3d, cnbpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod  ***
+      !! 
+      !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or 
+      !!              integral constraints
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                                   ::   kt      ! time step
+      INTEGER         , INTENT(in   )                                   ::   ktra    ! tracer index
+      INTEGER         , INTENT(in   )                                   ::   ktrd    ! tracer trend index
+      CHARACTER(len=3), INTENT(in   )                                   ::   ctype   ! tracers type 'TRA' or 'TRC'
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj)    , OPTIONAL ::   ptrd2d  ! Temperature or U trend 
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk), OPTIONAL ::   ptrd3d  ! Temperature or U trend 
+      CHARACTER(len=3), INTENT(in   )                        , OPTIONAL ::   cnbpas  ! number of passage
+      !!
+      CHARACTER(len=3) ::   ccpas                                  ! number of passage
+!     REAL(wp), DIMENSION(jpi,jpj) ::   z2dx, z2dy                 ! workspace arrays
+      !!----------------------------------------------------------------------
+
+      ccpas = 'fst'                            ! Control of optional arguments
+      IF( PRESENT(cnbpas) )  ccpas = cnbpas
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! I. Integral Constraints Properties for momentum and/or tracers trends
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( ( mod(kt,ntrd) == 0 .OR. kt == nit000 .OR. kt == nitend) )   THEN
+         !
+         IF( lk_trdtra .AND. ctype == 'TRA' )   THEN       ! active tracer trends
+            IF( PRESENT(ptrd2d) ) THEN   ;   CALL trd_icp( ptrd2d, ktra, ktrd, ctype, clpas=ccpas )
+            ELSE                         ;   CALL trd_icp( ptrd3d, ktra, ktrd, ctype, clpas=ccpas )
+            ENDIF
+         ENDIF
+!           SELECT CASE ( ktrd )
+!           CASE ( jptra_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_ldf, ctype )   ! lateral diff
+!           CASE ( jptra_trd_zdf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zdf, ctype )   ! vertical diff (Kz)
+!           CASE ( jptra_trd_bbc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbc, ctype )   ! bottom boundary cond
+!           CASE ( jptra_trd_bbl )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbl, ctype )   ! bottom boundary layer
+!           CASE ( jptra_trd_npc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_npc, ctype )   ! static instability mixing
+!           CASE ( jptra_trd_dmp )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_dmp, ctype )   ! damping
+!           CASE ( jptra_trd_qsr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_qsr, ctype )   ! penetrative solar radiat.
+!           CASE ( jptra_trd_nsr )   
+!              z2dx(:,:) = ptrdx(:,:,1)   ;   z2dy(:,:) = ptrdy(:,:,1)
+!              CALL trd_icp( z2dx, z2dy, jpicpt_nsr, ctype )                               ! non solar radiation
+!           CASE ( jptra_trd_xad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_xad, ctype )   ! x- horiz adv
+!           CASE ( jptra_trd_yad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_yad, ctype )   ! y- horiz adv
+!           CASE ( jptra_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype, clpas=ccpas )    ! z- adv 
+!              CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype, clpas=ccpas )   
+!              ! compute the surface flux condition wn(:,:,1)*tn(:,:,1)
+!              z2dx(:,:) = wn(:,:,1)*tn(:,:,1)/fse3t(:,:,1)
+!              z2dy(:,:) = wn(:,:,1)*sn(:,:,1)/fse3t(:,:,1)
+!              CALL trd_icp( z2dx , z2dy , jpicpt_zl1, ctype )                             ! 1st z- vertical adv 
+!           END SELECT
+!        END IF
+         !
+      END IF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! III. Mixed layer trends for active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_trdmld .AND. ctype == 'TRA' )   THEN
+         
+         !-----------------------------------------------------------------------------------------------
+         ! W.A.R.N.I.N.G :
+         ! jptra_trd_ldf : called by traldf.F90
+         !                 at this stage we store:
+         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
+         !                  - and the iso-neutral diffusion if activated 
+         ! jptra_trd_zdf : called by trazdf.F90
+         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the 
+         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mld)
+         !-----------------------------------------------------------------------------------------------
+
+!        SELECT CASE ( ktrd )
+!        CASE ( jpt_trd_zdf )
+!           IF( ln_traldf_iso )   THEN
+!              CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! vertical diffusion (K_z)
+!           ELSE
+!              CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zdf, '3D' )   ! vertical diffusion (K_z)
+!           ENDIF
+!        CASE ( jpt_trd_nsr )
+!           ptrdx(:,:,2:jpk) = 0.e0   ;   ptrdy(:,:,2:jpk) = 0.e0
+!           CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '2D' )                             ! air-sea : non solar flux
+!        CASE ( jpt_trd_bbc )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbc, '3D' )   ! bbc (geothermal flux)
+!        CASE DEFAULT
+!                                     CALL trd_mld_zint( ptrdx, ptrdy, ktra     , '3D' )   ! other 3D trends
+!        END SELECT
+
+      ENDIF
+
+   END SUBROUTINE trd_tra
+
+
+   SUBROUTINE trd_tra_adv( kt, ktra, ktrd, ctype, pf, pun, ptn, cnbpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod  ***
+      !! 
+      !! ** Purpose :   transformed the i-, j- or k-advective flux into thes
+      !!              i-, j- or k-advective trends, resp.
+      !! ** Method  :   i-advective trends = -un. di-1[T] = -( di-1[fi] - tn di-1[un] )
+      !!                k-advective trends = -un. di-1[T] = -( dj-1[fi] - tn dj-1[un] )
+      !!                k-advective trends = -un. di+1[T] = -( dk+1[fi] - tn dk+1[un] )
+      !!   NB: for TVD advection scheme, this routine is called twice (for upstream
+      !!       advective fluxes and anti-diffusive fluxes, resp.), but the
+      !!       divergence is only removed once, at the first call.
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in)                                   ::   kt      ! time step
+      INTEGER         , INTENT(in)                                   ::   ktra    ! tracer index
+      INTEGER         , INTENT(in)                                   ::   ktrd    ! tracer trend index
+      CHARACTER(len=3), INTENT(in)                                   ::   ctype   ! tracers type 'TRA' or 'TRC'
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk)           ::   pf      ! advective flux in one direction
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk)           ::   pun     ! now velocity  in one direction
+      REAL(wp)        , INTENT(in), DIMENSION(jpi,jpj,jpk)           ::   ptn     ! now or before tracer 
+      CHARACTER(len=3), INTENT(in)                        , OPTIONAL ::   cnbpas  ! number of passage
+      !!
+      INTEGER                          ::   ji, jj, jk   ! dummy loop indices
+      INTEGER                          ::   ii, ij, ik   ! index shift function of the direction
+      CHARACTER(len=3)                 ::   ccpas        ! number of passage
+      REAL(wp)                         ::   zbtr         ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt        ! 3D workspace 
+      !!----------------------------------------------------------------------
+
+      ccpas = 'fst'                            ! Control of optional arguments
+      IF( PRESENT(cnbpas) )  ccpas = cnbpas
+
+
+      SELECT CASE( ktrd )            ! shift depending on the direction
+      CASE( jpt_trd_xad )   ;   ii = 1   ; ij = 0   ;   ik = 0      ! i-advective trend
+      CASE( jpt_trd_yad )   ;   ii = 0   ; ij = 1   ;   ik = 0      ! j-advective trend
+      CASE( jpt_trd_zad )   ;   ii = 0   ; ij = 0   ;   ik =-1      ! k-advective trend
+      END SELECT
+
+      !                              ! set to zero uncomputed values
+      ztrdt(jpi,:,:) = 0.e0   ;   ztrdt(1,:,:) = 0.e0
+      ztrdt(:,jpj,:) = 0.e0   ;   ztrdt(:,1,:) = 0.e0
+      ztrdt(:,:,jpk) = 0.e0
+      !
+      !
+      IF( ccpas == 'fst' ) THEN      ! first treatment : remove the divergence
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr    = 1.e0/ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztrdt(ji,jj,jk) = - zbtr * (      pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                    &
+                     &                          - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )
+               END DO
+            END DO
+         END DO
+         !
+      ELSE                           ! second call : just compute the trend   (TVD scheme)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr    = 1.e0/ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztrdt(ji,jj,jk) = - zbtr * (      pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)     )
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+      !                              ! trend diagnostics
+      CALL trd_tra( kt, ktra, ktrd, ctype, ptrd3d=ztrdt, cnbpas=ccpas )
+      !
+   END SUBROUTINE trd_tra_adv
+
+
+   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt, cnbpas )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod  ***
+      !! 
+      !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or 
+      !!              integral constraints
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in   )                                   ::   kt      ! time step
+      INTEGER         , INTENT(in   )                                   ::   ktrd    ! tracer trend index
+      CHARACTER(len=3), INTENT(in   )                                   ::   ctype   ! momentum trends type ='DYN'
+      CHARACTER(len=3), INTENT(in   )                        , OPTIONAL ::   cnbpas  ! number of passage
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk)           ::   ptrdx   ! Temperature or U trend 
+      REAL(wp)        , INTENT(inout), DIMENSION(jpi,jpj,jpk)           ::   ptrdy   ! Salinity    or V trend
+      !!
+      INTEGER ::   ji, ikbu, ikbum1
+      INTEGER ::   jj, ikbv, ikbvm1
+      CHARACTER(len=3) ::   ccpas                                  ! number of passage
+      REAL(wp) ::   zua, zva                                       ! scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztswu, ztswv               ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztbfu, ztbfv               ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   z2dx, z2dy                 ! workspace arrays
+      !!----------------------------------------------------------------------
+
+      z2dx(:,:)   = 0.e0   ;   z2dy(:,:)   = 0.e0                  ! initialization of workspace arrays
+
+      ccpas = 'fst'                            ! Control of optional arguments
+      IF( PRESENT(cnbpas) )  ccpas = cnbpas
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (start with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! I. Integral Constraints Properties for momentum and/or tracers trends
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( ( mod(kt,ntrd) == 0 .OR. kt == nit000 .OR. kt == nitend) )   THEN
+         !
+         IF( lk_trddyn .AND. ctype == 'DYN' )   THEN       ! momentum trends 
+            !
+            SELECT CASE ( ktrd )
+            CASE ( jpdyn_trd_hpg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_hpg, ctype )   ! hydrost. pressure grad
+            CASE ( jpdyn_trd_keg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_keg, ctype )   ! KE gradient 
+            CASE ( jpdyn_trd_rvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_rvo, ctype )   ! relative vorticity 
+            CASE ( jpdyn_trd_pvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_pvo, ctype )   ! planetary vorticity
+            CASE ( jpdyn_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_ldf, ctype )   ! lateral diffusion 
+            CASE ( jpdyn_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_zad, ctype )   ! vertical advection 
+            CASE ( jpdyn_trd_spg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_spg, ctype )   ! surface pressure grad.
+            CASE ( jpdyn_trd_dat )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_dat, ctype )   ! damping term
+            CASE ( jpdyn_trd_zdf )                                                         ! vertical diffusion 
+               ! subtract surface forcing/bottom friction trends 
+               ! from vertical diffusive momentum trends
+               ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+               ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0  
+               DO jj = 2, jpjm1   
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ! save the surface forcing momentum fluxes
+                     ztswu(ji,jj) = taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
+                     ztswv(ji,jj) = tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
+                     ! save bottom friction momentum fluxes
+                     ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+                     ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+                     ikbum1 = MAX( ikbu-1, 1 )
+                     ikbvm1 = MAX( ikbv-1, 1 )
+                     zua = ua(ji,jj,ikbum1) * r2dt + ub(ji,jj,ikbum1)
+                     zva = va(ji,jj,ikbvm1) * r2dt + vb(ji,jj,ikbvm1)
+                     ztbfu(ji,jj) = - avmu(ji,jj,ikbu) * zua / ( fse3u(ji,jj,ikbum1)*fse3uw(ji,jj,ikbu) )
+                     ztbfv(ji,jj) = - avmv(ji,jj,ikbv) * zva / ( fse3v(ji,jj,ikbvm1)*fse3vw(ji,jj,ikbv) )
+                     !
+                     ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
+                     ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
+                     ptrdx(ji,jj,ikbum1) = ptrdx(ji,jj,ikbum1) - ztbfu(ji,jj)
+                     ptrdy(ji,jj,ikbvm1) = ptrdy(ji,jj,ikbvm1) - ztbfv(ji,jj)
+                  END DO
+               END DO
+               !
+               CALL trd_icp( ptrdx, ptrdy, jpicpd_zdf, ctype )   
+               CALL trd_icp( ztswu, ztswv, jpicpd_swf, ctype )                               ! wind stress forcing term
+               CALL trd_icp( ztbfu, ztbfv, jpicpd_bfr, ctype )                               ! bottom friction term
+            END SELECT
+            !
+         END IF
+         !
+      END IF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! II. Vorticity trends
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_trdvor .AND. ctype == 'DYN' )   THEN
+         !
+         SELECT CASE ( ktrd ) 
+         CASE ( jpdyn_trd_hpg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_prg )   ! Hydrostatique Pressure Gradient 
+         CASE ( jpdyn_trd_keg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_keg )   ! KE Gradient 
+         CASE ( jpdyn_trd_rvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_rvo )   ! Relative Vorticity 
+         CASE ( jpdyn_trd_pvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_pvo )   ! Planetary Vorticity Term 
+         CASE ( jpdyn_trd_ldf )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_ldf )   ! Horizontal Diffusion 
+         CASE ( jpdyn_trd_zad )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zad )   ! Vertical Advection 
+         CASE ( jpdyn_trd_spg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_spg )   ! Surface Pressure Grad. 
+         CASE ( jpdyn_trd_dat )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bev )   ! Beta V  
+         CASE ( jpdyn_trd_zdf )                                                      ! Vertical Diffusion 
+            ! subtract surface forcing/bottom friction trends 
+            ! from vertical diffusive momentum trends
+            ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+            ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0  
+            DO jj = 2, jpjm1   
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! save the surface forcing momentum fluxes
+                  ztswu(ji,jj) = taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
+                  ztswv(ji,jj) = tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
+                  ! save bottom friction momentum fluxes
+                  ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+                  ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+                  ikbum1 = MAX( ikbu-1, 1 )
+                  ikbvm1 = MAX( ikbv-1, 1 )
+                  zua = ua(ji,jj,ikbum1) * r2dt + ub(ji,jj,ikbum1)
+                  zva = va(ji,jj,ikbvm1) * r2dt + vb(ji,jj,ikbvm1)
+                  ztbfu(ji,jj) = - avmu(ji,jj,ikbu) * zua / ( fse3u(ji,jj,ikbum1)*fse3uw(ji,jj,ikbu) )
+                  ztbfv(ji,jj) = - avmv(ji,jj,ikbv) * zva / ( fse3v(ji,jj,ikbvm1)*fse3vw(ji,jj,ikbv) )
+                  !
+                  ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
+                  ptrdx(ji,jj,ikbum1) = ptrdx(ji,jj,ikbum1) - ztbfu(ji,jj)
+                  ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
+                  ptrdy(ji,jj,ikbvm1) = ptrdy(ji,jj,ikbvm1) - ztbfv(ji,jj)
+               END DO
+            END DO
+            !
+            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zdf )   
+            CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                               ! Wind stress forcing term
+            CALL trd_vor_zint( ztbfu, ztbfv, jpvor_bfr )                               ! Bottom friction term
+         END SELECT
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_mod
+
+#   else
+   !!----------------------------------------------------------------------
+   !!   Default case :                                         Empty module
+   !!----------------------------------------------------------------------
+   USE trdmod_oce      ! ocean variables trends
+   USE trdvor          ! ocean vorticity trends 
+   USE trdicp          ! ocean bassin integral constraints properties
+   USE trdmld          ! ocean active mixed layer tracers trends 
+
+CONTAINS
+
+   SUBROUTINE trd_tra( kt, ktra, ktrd, ctype, ptrd2d, ptrd3d, cnbpas )
+      INTEGER ::   kt, ktra, ktrd
+      CHARACTER(len=3) ::   ctype   ! tracers type 'TRA' or 'TRC'
+      REAL, DIMENSION(:,:)  , OPTIONAL ::   ptrd2d  ! Temperature or U trend 
+      REAL, DIMENSION(:,:,:), OPTIONAL ::   ptrd3d  ! Temperature or U trend 
+      CHARACTER(len=3)      , OPTIONAL ::   cnbpas  ! number of passage
+      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', kt, ktra, ktrd, ctype,   &
+         &                                                               ptrd2d(1,1), ptrd3d(1,1,1), cnbpas
+   END SUBROUTINE trd_tra
+
+   SUBROUTINE trd_tra_adv( kt, ktra, ktrd, ctype, pf, pun, ptn, cnbpas )
+      INTEGER ::   kt, ktra, ktrd  
+      CHARACTER(len=3) ::   ctype
+      REAL, DIMENSION(:,:,:) ::   pf, pun, ptn
+      CHARACTER(len=3), OPTIONAL ::   cnbpas
+      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', kt, ktra, ktrd, ctype, pf(1,1,1),   &
+         &                                                               pun(1,1,1), ptn(1,1,1), cnbpas
+   END SUBROUTINE trd_tra_adv
+
+   SUBROUTINE trd_mod(ptrd3dx, ptrd3dy, ktrd , ctype, kt, cnbpas)   ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   ptrd3dx, ptrd3dy    
+      INTEGER ::   ktrd, kt
+      CHARACTER(len=3), INTENT( in ) ::  ctype                     ! momentum or tracers trends type
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::   cnbpas         ! number of passage
+      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd3dx(1,1,1)
+      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ptrd3dy(1,1,1)
+      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ktrd
+      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ctype
+      WRITE(*,*) ' "   ": You should not have seen this print! error ?', kt
+      WRITE(*,*) ' "   ": You should not have seen this print! error ?', cnbpas
+   END SUBROUTINE trd_mod
+#   endif
+
+   SUBROUTINE trd_mod_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod_init  ***
+      !! 
+      !! ** Purpose :   Initialization of activated trends
+      !!----------------------------------------------------------------------
+      USE in_out_manager          ! I/O manager
+
+      NAMELIST/namtrd/ ntrd, nctls, ln_trdmld_restart, ucf, ln_trdmld_instant
+      !!----------------------------------------------------------------------
+
+      IF( l_trdtra .OR. l_trddyn )   THEN
+         REWIND( numnam )
+         READ  ( numnam, namtrd )      ! namelist namtrd : trends diagnostic
+
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' trd_mod_init : Momentum/Tracers trends'
+            WRITE(numout,*) ' ~~~~~~~~~~~~~'
+            WRITE(numout,*) '       Namelist namtrd : set trends parameters'
+            WRITE(numout,*) '           * frequency of trends diagnostics   ntrd               = ', ntrd
+            WRITE(numout,*) '           * control surface type              nctls              = ', nctls
+            WRITE(numout,*) '           * restart for ML diagnostics        ln_trdmld_restart  = ', ln_trdmld_restart
+            WRITE(numout,*) '           * instantaneous or mean ML T/S      ln_trdmld_instant  = ', ln_trdmld_instant
+            WRITE(numout,*) '           * unit conversion factor            ucf                = ', ucf
+        ENDIF
+      ENDIF
+      !
+      IF( lk_trddyn .OR. lk_trdtra )    CALL trd_icp_init       ! integral constraints trends
+      IF( lk_trdmld                )    CALL trd_mld_init       ! mixed-layer trends (active  tracers)  
+      IF( lk_trdvor                )    CALL trd_vor_init       ! vorticity trends        
+      !
+   END SUBROUTINE trd_mod_init
+
+   !!======================================================================
+END MODULE trdmod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 4536)
@@ -0,0 +1,85 @@
+MODULE trdmod_oce
+   !!======================================================================
+   !!                   ***  MODULE trdmod_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+   !! History :  9.0  !  04-08  (C. Talandier) Original code
+   !!----------------------------------------------------------------------
+   USE trdicp_oce              ! ocean momentum/tracers bassin properties trends variables
+   USE trdmld_oce              ! ocean active mixed layer tracers trends variables
+   USE trdvor_oce              ! ocean vorticity trends variables
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!* Namelist namtrd:  diagnostics on dynamics/tracer trends
+   INTEGER , PUBLIC ::    ntrd  = 10                    !: time step frequency dynamics and tracers trends
+   INTEGER , PUBLIC ::    nctls =  0                    !: control surface type for trends vertical integration
+   REAL(wp), PUBLIC ::    ucf   = 1.                    !: unit conversion factor (for netCDF trends outputs)
+                                                        !: =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
+   LOGICAL , PUBLIC ::    ln_trdmld_instant = .FALSE.   !: flag to diagnose inst./mean ML T/S trends
+   LOGICAL , PUBLIC ::    ln_trdmld_restart = .FALSE.   !: flag to restart mixed-layer diagnostics
+
+   !!* Control parameters
+# if defined key_trdtra   ||   defined key_trdmld
+   LOGICAL , PUBLIC ::   l_trdtra = .TRUE.              !: tracers  trend flag
+# else
+   LOGICAL , PUBLIC ::   l_trdtra = .FALSE.             !: tracers  trend flag
+# endif
+# if defined key_trddyn   ||   defined key_trdvor
+   LOGICAL , PUBLIC ::   l_trddyn = .TRUE.              !: momentum trend flag
+# else
+   LOGICAL , PUBLIC ::   l_trddyn = .FALSE.             !: momentum trend flag
+# endif
+#if  defined key_trdtra   &&   defined key_trddyn    ||   defined key_esopa
+   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
+   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
+#elif  defined key_trdtra
+   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
+   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
+#elif  defined key_trddyn
+   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
+   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
+#else
+   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
+   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
+#endif
+
+
+   !!* Active tracers trends indexes
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd = 13        !: change it when adding/removing one indice above
+
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_xad =  1   !: x- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_yad =  2   !: y- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_zad =  3   !: z- vertical   advection
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_ldf =  4   !: lateral       diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_zdf =  5   !: vertical diffusion (Kz)
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_bbc =  6   !: Bottom Boundary Condition (geoth. flux) 
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_bbl =  7   !: Bottom Boundary Layer (diffusive/convective)
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_npc =  8   !: static instability mixing
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_dmp =  9   !: damping
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_qsr = 10   !: penetrative solar radiation
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_qns = 11   !: non solar heat flux
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_atf = 12   !: Asselin correction
+   INTEGER, PUBLIC, PARAMETER ::   jpt_trd_zl1 = 13   !: first level vertical flux (lk_vvl=F)
+
+   
+   !!* Momentum trends indexes
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_hpg =  1   !: hydrostatic pressure gradient 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_keg =  2   !: kinetic energy gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_rvo =  3   !: relative vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_pvo =  4   !: planetary vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_ldf =  5   !: lateral diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zad =  6   !: vertical advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zdf =  7   !: vertical diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_spg =  8   !: surface pressure gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_dat =  9   !: damping term
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_swf = 10   !: surface wind forcing
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_bfr = 11   !: bottom friction 
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trdmod_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 4536)
@@ -0,0 +1,634 @@
+MODULE trdvor
+   !!======================================================================
+   !!                       ***  MODULE  trdvor  ***
+   !! Ocean diagnostics:  momentum trends
+   !!=====================================================================
+   !! History :  9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
+   !!                 !  04-08  (C. Talandier) New trends organization
+   !!----------------------------------------------------------------------
+#if defined key_trdvor   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trdvor'   : momentum trend diagnostics
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   trd_vor      : momentum trends averaged over the depth
+   !!   trd_vor_zint : vorticity vertical integration
+   !!   trd_vor_init : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE trdmod_oce      ! ocean variables trends
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! Define parameters for the routines
+   USE ldfdyn_oce      ! ocean active tracers: lateral physics
+   USE daymod          ! calandar
+   USE dianam          ! build the name of file (routine)
+   USE zdfmxl          ! mixed layer depth
+   USE ioipsl          ! NetCDF library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE trd_vor_zint
+      MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
+   END INTERFACE
+
+   PUBLIC   trd_vor        ! routine called by step.F90
+   PUBLIC   trd_vor_zint   ! routine called by dynamics routines
+   PUBLIC   trd_vor_init   ! routine called by opa.F90
+
+   INTEGER ::                &
+      nh_t, nmoydpvor  ,     &
+      nidvor, nhoridvor,     &
+      ndexvor1(jpi*jpj),     &
+      ndimvor1, icount,      &
+      idebug                    ! (0/1) set it to 1 in case of problem to have more print
+
+   REAL(wp), DIMENSION(jpi,jpj) ::  &
+     vor_avr    ,     &  ! average
+     vor_avrb   ,     &  ! before vorticity (kt-1)
+     vor_avrbb  ,     &  ! vorticity at begining of the nwrite-1 timestep averaging period
+     vor_avrbn  ,     &  ! after vorticity at time step after the
+     rotot      ,     &  ! begining of the NWRITE-1 timesteps
+     vor_avrtot ,     &
+     vor_avrres
+
+   REAL(wp), DIMENSION(jpi,jpj,jpltot_vor)::   vortrd  !: curl of trends
+         
+   CHARACTER(len=12) ::   cvort
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldfdyn_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+  
+CONTAINS
+
+   SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
+      !!----------------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor_zint  ***
+      !!
+      !! ** Purpose :   computation of vertically integrated vorticity budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!
+      !! ** Method/usage :
+      !!      integration done over nwrite-1 time steps
+      !!
+      !!
+      !! ** Action :
+      !!            /comvor/   :
+      !!                         vor_avr          average
+      !!                         vor_avrb         vorticity at kt-1
+      !!                         vor_avrbb        vorticity at begining of the NWRITE-1
+      !!                                          time steps averaging period
+      !!                         vor_avrbn         vorticity at time step after the
+      !!                                          begining of the NWRITE-1 time
+      !!                                          steps averaging period
+      !!
+      !!                 trends :
+      !!
+      !!                  vortrd (,, 1) = Pressure Gradient Trend
+      !!                  vortrd (,, 2) = KE Gradient Trend
+      !!                  vortrd (,, 3) = Relative Vorticity Trend
+      !!                  vortrd (,, 4) = Coriolis Term Trend
+      !!                  vortrd (,, 5) = Horizontal Diffusion Trend
+      !!                  vortrd (,, 6) = Vertical Advection Trend
+      !!                  vortrd (,, 7) = Vertical Diffusion Trend
+      !!                  vortrd (,, 8) = Surface Pressure Grad. Trend
+      !!                  vortrd (,, 9) = Beta V
+      !!                  vortrd (,,10) = forcing term
+      !!		  vortrd (,,11) = bottom friction term
+      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
+      !!                  vor_avrtot(,) : first membre of vrticity equation
+      !!                  vor_avrres(,) : residual = dh/dt entrainment
+      !!
+      !!      trends output in netCDF format using ioipsl
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         putrdvor,                         &  ! u vorticity trend 
+         pvtrdvor                             ! v vorticity trend
+      !!
+      INTEGER ::   ji, jj
+      INTEGER ::   ikbu, ikbum1, ikbv, ikbvm1
+      REAL(wp), DIMENSION(jpi,jpj) ::   zudpvor, zvdpvor   ! total cmulative trends
+      !!----------------------------------------------------------------------
+
+      ! Initialization
+      zudpvor(:,:) = 0.e0
+      zvdpvor(:,:) = 0.e0
+
+      CALL lbc_lnk( putrdvor,  'U' , -1. )
+      CALL lbc_lnk( pvtrdvor,  'V' , -1. )
+
+      !  =====================================
+      !  I vertical integration of 2D trends
+      !  =====================================
+
+      SELECT CASE (ktrd) 
+
+      CASE (jpvor_bfr)        ! bottom friction
+
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1 
+               ikbu   = min( mbathy(ji+1,jj), mbathy(ji,jj) )
+               ikbum1 = max( ikbu-1, 1 )
+               ikbv   = min( mbathy(ji,jj+1), mbathy(ji,jj) )
+               ikbvm1 = max( ikbv-1, 1 )
+            
+               zudpvor(ji,jj) = putrdvor(ji,jj) * fse3u(ji,jj,ikbum1) * e1u(ji,jj) * umask(ji,jj,ikbum1)
+               zvdpvor(ji,jj) = pvtrdvor(ji,jj) * fse3v(ji,jj,ikbvm1) * e2v(ji,jj) * vmask(ji,jj,ikbvm1)
+            END DO
+         END DO
+
+      CASE (jpvor_swf)        ! wind stress
+
+         zudpvor(:,:) = putrdvor(:,:) * fse3u(:,:,1) * e1u(:,:) * umask(:,:,1)
+         zvdpvor(:,:) = pvtrdvor(:,:) * fse3v(:,:,1) * e2v(:,:) * vmask(:,:,1)
+
+      END SELECT
+
+      ! Average except for Beta.V
+      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
+      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
+   
+      ! Curl
+      DO ji=1,jpim1
+         DO jj=1,jpjm1
+            vortrd(ji,jj,ktrd) = ( zvdpvor(ji+1,jj) - zvdpvor(ji,jj)        &
+                 &                - ( zudpvor(ji,jj+1) - zudpvor(ji,jj) ) ) &
+                 &               / ( e1f(ji,jj) * e2f(ji,jj) )
+         END DO
+      END DO
+
+      ! Surface mask
+      vortrd(:,:,ktrd) = vortrd(:,:,ktrd) * fmask(:,:,1)
+
+      IF( idebug /= 0 ) THEN
+         IF(lwp) WRITE(numout,*) ' debuging trd_vor_zint: I done'
+         CALL FLUSH(numout)
+      ENDIF
+      !
+   END SUBROUTINE trd_vor_zint_2d
+
+
+   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
+      !!----------------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor_zint  ***
+      !!
+      !! ** Purpose :   computation of vertically integrated vorticity budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!
+      !! ** Method/usage :
+      !!      integration done over nwrite-1 time steps
+      !!
+      !!
+      !! ** Action :
+      !!            /comvor/   :
+      !!                         vor_avr          average
+      !!                         vor_avrb         vorticity at kt-1
+      !!                         vor_avrbb        vorticity at begining of the NWRITE-1
+      !!                                          time steps averaging period
+      !!                         vor_avrbn         vorticity at time step after the
+      !!                                          begining of the NWRITE-1 time
+      !!                                          steps averaging period
+      !!
+      !!                 trends :
+      !!
+      !!                  vortrd (,,1) = Pressure Gradient Trend
+      !!                  vortrd (,,2) = KE Gradient Trend
+      !!                  vortrd (,,3) = Relative Vorticity Trend
+      !!                  vortrd (,,4) = Coriolis Term Trend
+      !!                  vortrd (,,5) = Horizontal Diffusion Trend
+      !!                  vortrd (,,6) = Vertical Advection Trend
+      !!                  vortrd (,,7) = Vertical Diffusion Trend
+      !!                  vortrd (,,8) = Surface Pressure Grad. Trend
+      !!                  vortrd (,,9) = Beta V
+      !!                  vortrd (,,10) = forcing term
+      !!		  vortrd (,,11) = bottom friction term
+      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
+      !!                  vor_avrtot(,) : first membre of vrticity equation
+      !!                  vor_avrres(,) : residual = dh/dt entrainment
+      !!
+      !!      trends output in netCDF format using ioipsl
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         putrdvor,                         &  ! u vorticity trend 
+         pvtrdvor                             ! v vorticity trend
+      !!
+      INTEGER ::   ji, jj, jk
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zubet,                         &  ! u Beta.V case
+         zvbet,                         &  ! v Beta.V case
+         zudpvor,                       &  ! total cmulative trends
+         zvdpvor                           !   "      "        "
+      !!----------------------------------------------------------------------
+     
+      ! Initialization
+      zubet(:,:) = 0.e0
+      zvbet(:,:) = 0.e0
+      zudpvor(:,:) = 0.e0
+      zvdpvor(:,:) = 0.e0
+
+      !  =====================================
+      !  I vertical integration of 3D trends
+      !  =====================================
+
+      CALL lbc_lnk( putrdvor, 'U' , -1. )
+      CALL lbc_lnk( pvtrdvor, 'V' , -1. )
+
+      ! putrdvor and pvtrdvor terms
+      DO jk = 1,jpk
+        zudpvor(:,:) = zudpvor(:,:) + putrdvor(:,:,jk) * fse3u(:,:,jk) * e1u(:,:) * umask(:,:,jk)
+        zvdpvor(:,:) = zvdpvor(:,:) + pvtrdvor(:,:,jk) * fse3v(:,:,jk) * e2v(:,:) * vmask(:,:,jk)
+      END DO
+
+      ! Save Beta.V term to avoid average before Curl
+      ! Beta.V : intergration, no average
+      IF( ktrd == jpvor_bev ) THEN 
+         zubet(:,:) = zudpvor(:,:)
+         zvbet(:,:) = zvdpvor(:,:)
+      ENDIF
+
+      ! Average except for Beta.V
+      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
+      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
+   
+      ! Curl
+      DO ji=1,jpim1
+         DO jj=1,jpjm1
+            vortrd(ji,jj,ktrd) = (  zvdpvor(ji+1,jj) - zvdpvor(ji,jj) -   &
+                 &                ( zudpvor(ji,jj+1) - zudpvor(ji,jj) ) ) &
+                 &               / ( e1f(ji,jj) * e2f(ji,jj) )
+         END DO
+      END DO
+
+      ! Surface mask
+      vortrd(:,:,ktrd) = vortrd(:,:,ktrd) * fmask(:,:,1)
+
+      ! Special treatement for the Beta.V term
+      ! Compute the Curl of the Beta.V term which is not averaged
+      IF( ktrd == jpvor_bev ) THEN
+         DO ji=1,jpim1
+            DO jj=1,jpjm1
+               vortrd(ji,jj,jpvor_bev) = (  zvbet(ji+1,jj) - zvbet(ji,jj) -   &
+                    &                    ( zubet(ji,jj+1) - zubet(ji,jj) ) ) &
+                    &                   / ( e1f(ji,jj) * e2f(ji,jj) )
+            END DO
+         END DO
+
+         ! Average on the Curl
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * hur(:,:)
+
+         ! Surface mask
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * fmask(:,:,1)
+      ENDIF
+   
+      IF( idebug /= 0 ) THEN
+         IF(lwp) WRITE(numout,*) ' debuging trd_vor_zint: I done'
+         CALL FLUSH(numout)
+      ENDIF
+      !
+   END SUBROUTINE trd_vor_zint_3d
+
+
+   SUBROUTINE trd_vor( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor  ***
+      !! 
+      !! ** Purpose :  computation of cumulated trends over analysis period
+      !!               and make outputs (NetCDF or DIMG format)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk, jl, it
+      REAL(wp) ::   zmean
+      REAL(wp), DIMENSION(jpi,jpj) ::   zun, zvn
+      !!----------------------------------------------------------------------
+
+      !  =================
+      !  I. Initialization
+      !  =================
+     
+     
+      ! I.1 set before values of vertically average u and v
+      ! ---------------------------------------------------
+
+      IF( kt > nit000 ) THEN
+         vor_avrb(:,:) = vor_avr(:,:)
+      ENDIF
+
+       IF( idebug /= 0 ) THEN
+          WRITE(numout,*) ' debuging trd_vor: I.1 done '
+          CALL FLUSH(numout)
+      ENDIF
+
+      ! I.2 vertically integrated vorticity
+      !  ----------------------------------
+
+      vor_avr(:,:) = 0.
+      zun(:,:)=0
+      zvn(:,:)=0
+      vor_avrtot(:,:)=0
+      vor_avrres(:,:)=0
+      
+      ! Vertically averaged velocity
+      DO jk = 1, jpk - 1
+         zun(:,:)=zun(:,:) + e1u(:,:)*un(:,:,jk)*fse3u(:,:,jk)
+         zvn(:,:)=zvn(:,:) + e2v(:,:)*vn(:,:,jk)*fse3v(:,:,jk)
+      END DO
+ 
+      zun(:,:)=zun(:,:)*hur(:,:)
+      zvn(:,:)=zvn(:,:)*hvr(:,:)
+
+      ! Curl
+      DO ji=1,jpim1
+         DO jj=1,jpjm1
+            vor_avr(ji,jj) = ((zvn(ji+1,jj)-zvn(ji,jj))-   &
+                              (zun(ji,jj+1)-zun(ji,jj)))   &
+                             /( e1f(ji,jj) * e2f(ji,jj) )
+            vor_avr(ji,jj) = vor_avr(ji,jj)*fmask(ji,jj,1)
+         END DO
+      END DO
+      
+      IF(idebug /= 0) THEN
+         WRITE(numout,*) ' debuging trd_vor: I.2 done'
+         CALL FLUSH(numout)
+      ENDIF
+
+      !  =================================
+      !   II. Cumulated trends
+      !  =================================
+
+      ! II.1 set `before' mixed layer values for kt = nit000+1
+      ! ------------------------------------------------------
+      IF( kt == nit000+1 ) THEN
+         vor_avrbb(:,:) = vor_avrb(:,:)
+         vor_avrbn(:,:) = vor_avr (:,:)
+      ENDIF
+
+      IF( idebug /= 0 ) THEN
+         WRITE(numout,*) ' debuging trd_vor: I1.1 done'
+         CALL FLUSH(numout)
+      ENDIF
+
+      ! II.2 cumulated trends over analysis period (kt=2 to nwrite)
+      ! ----------------------
+      ! trends cumulated over nwrite-2 time steps
+
+      IF( kt >= nit000+2 ) THEN
+         nmoydpvor = nmoydpvor + 1
+         DO jl = 1, jpltot_vor
+            IF( jl /= 9 ) THEN
+               rotot(:,:) = rotot(:,:) + vortrd(:,:,jl)
+            ENDIF
+         END DO
+      ENDIF
+
+      IF( idebug /= 0 ) THEN
+         WRITE(numout,*) ' debuging trd_vor: II.2 done'
+         CALL FLUSH(numout)
+      ENDIF
+
+      !  =============================================
+      !   III. Output in netCDF + residual computation
+      !  =============================================
+
+      IF( MOD( kt - nit000+1, ntrd ) == 0 ) THEN
+
+         ! III.1 compute total trend
+         ! ------------------------
+         zmean = float(nmoydpvor)
+
+         vor_avrtot(:,:) = ( vor_avr(:,:) - vor_avrbn(:,:) + vor_avrb(:,:) - &
+                             vor_avrbb(:,:) ) /  (zmean * 2. * rdt)
+
+         IF( idebug /= 0 ) THEN
+             WRITE(numout,*) ' zmean = ',zmean
+             WRITE(numout,*) ' debuging trd_vor: III.1 done'
+             CALL FLUSH(numout)
+         ENDIF
+
+         ! III.2 compute residual
+         ! ---------------------
+         vor_avrres(:,:) = vor_avrtot(:,:) - rotot(:,:) / zmean
+
+         ! Boundary conditions
+         CALL lbc_lnk( vor_avrtot, 'F', 1. )
+         CALL lbc_lnk( vor_avrres, 'F', 1. )
+
+         IF( idebug /= 0 ) THEN
+            WRITE(numout,*) ' debuging trd_vor: III.2 done'
+            CALL FLUSH(numout)
+         ENDIF
+
+         ! III.3 time evolution array swap
+         ! ------------------------------
+         vor_avrbb(:,:) = vor_avrb(:,:)
+         vor_avrbn(:,:) = vor_avr(:,:)
+
+         IF( idebug /= 0 ) THEN
+            WRITE(numout,*) ' debuging trd_vor: III.3 done'
+            CALL FLUSH(numout)
+         ENDIF
+
+         nmoydpvor=0
+
+      ENDIF
+
+      ! III.4 write trends to output
+      ! ---------------------------
+
+      IF( kt >=  nit000+1 ) THEN
+
+         ! define time axis
+         it= kt-nit000+1
+         IF( lwp .AND. MOD( kt, ntrd ) == 0 ) THEN
+            WRITE(numout,*) ''
+            WRITE(numout,*) 'trd_vor : write trends in the NetCDF file at kt = ', kt
+            WRITE(numout,*) '~~~~~~~  '
+         ENDIF
+ 
+         CALL histwrite( nidvor,"sovortPh",it,vortrd(:,:,jpvor_prg),ndimvor1,ndexvor1)  ! grad Ph
+         CALL histwrite( nidvor,"sovortEk",it,vortrd(:,:,jpvor_keg),ndimvor1,ndexvor1)  ! Energy
+         CALL histwrite( nidvor,"sovozeta",it,vortrd(:,:,jpvor_rvo),ndimvor1,ndexvor1)  ! rel vorticity
+         CALL histwrite( nidvor,"sovortif",it,vortrd(:,:,jpvor_pvo),ndimvor1,ndexvor1)  ! coriolis
+         CALL histwrite( nidvor,"sovodifl",it,vortrd(:,:,jpvor_ldf),ndimvor1,ndexvor1)  ! lat diff
+         CALL histwrite( nidvor,"sovoadvv",it,vortrd(:,:,jpvor_zad),ndimvor1,ndexvor1)  ! vert adv
+         CALL histwrite( nidvor,"sovodifv",it,vortrd(:,:,jpvor_zdf),ndimvor1,ndexvor1)  ! vert diff
+         CALL histwrite( nidvor,"sovortPs",it,vortrd(:,:,jpvor_spg),ndimvor1,ndexvor1)  ! grad Ps
+         CALL histwrite( nidvor,"sovortbv",it,vortrd(:,:,jpvor_bev),ndimvor1,ndexvor1)  ! beta.V
+         CALL histwrite( nidvor,"sovowind",it,vortrd(:,:,jpvor_swf),ndimvor1,ndexvor1) ! wind stress
+         CALL histwrite( nidvor,"sovobfri",it,vortrd(:,:,jpvor_bfr),ndimvor1,ndexvor1) ! bottom friction
+         CALL histwrite( nidvor,"1st_mbre",it,vor_avrtot    ,ndimvor1,ndexvor1) ! First membre
+         CALL histwrite( nidvor,"sovorgap",it,vor_avrres    ,ndimvor1,ndexvor1) ! gap between 1st and 2 nd mbre
+         !
+         IF( idebug /= 0 ) THEN
+            WRITE(numout,*) ' debuging trd_vor: III.4 done'
+            CALL FLUSH(numout)
+         ENDIF
+         !
+      ENDIF
+      !
+      IF( MOD( kt - nit000+1, ntrd ) == 0 ) rotot(:,:)=0
+      !
+      IF( kt == nitend )   CALL histclo( nidvor )
+      !
+   END SUBROUTINE trd_vor
+
+
+   SUBROUTINE trd_vor_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor_init  ***
+      !! 
+      !! ** Purpose :   computation of vertically integrated T and S budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zjulian, zsto, zout
+      CHARACTER (len=40) ::   clhstnam
+      CHARACTER (len=40) ::   clop
+      !!----------------------------------------------------------------------
+
+      !  ===================
+      !   I. initialization
+      !  ===================
+
+      cvort='averaged-vor'
+
+      ! Open specifier
+      idebug = 0      ! set it to 1 in case of problem to have more Print
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' trd_vor_init: vorticity trends'
+         WRITE(numout,*) ' ~~~~~~~~~~~~'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) '               ##########################################################################'
+         WRITE(numout,*) '                CAUTION: The interpretation of the vorticity trends is'
+         WRITE(numout,*) '                not obvious, please contact Anne-Marie TREGUIER at: treguier@ifremer.fr '
+         WRITE(numout,*) '               ##########################################################################'
+         WRITE(numout,*) ' '
+      ENDIF
+
+      ! cumulated trends array init
+      nmoydpvor = 0
+      rotot(:,:)=0
+      vor_avrtot(:,:)=0
+      vor_avrres(:,:)=0
+
+      IF( idebug /= 0 ) THEN
+         WRITE(numout,*) ' debuging trd_vor_init: I. done'
+         CALL FLUSH(numout)
+      ENDIF
+
+      !  =================================
+      !   II. netCDF output initialization
+      !  =================================
+
+      !-----------------------------------------
+      ! II.1 Define frequency of output and means
+      ! -----------------------------------------
+#if defined key_diainstant
+      zsto = nwrite*rdt
+      clop ="inst(x)"
+#else
+      zsto = rdt
+      clop ="ave(x)"
+#endif
+      zout = ntrd*rdt
+
+      IF(lwp) WRITE(numout,*) '               netCDF initialization'
+
+      ! II.2 Compute julian date from starting date of the run
+      ! ------------------------
+      CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+      IF(lwp) WRITE(numout,*)' '  
+      IF(lwp) WRITE(numout,*)'               Date 0 used :',nit000,    &
+         &                   ' YEAR ', nyear,' MONTH '      , nmonth,   &
+         &                   ' DAY ' , nday, 'Julian day : ', zjulian
+
+      ! II.3 Define the T grid trend file (nidvor)
+      ! ---------------------------------
+      CALL dia_nam( clhstnam, ntrd, 'vort' )                  ! filename
+      IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
+      CALL histbeg( clhstnam, jpi, glamf, jpj, gphif,1, jpi,   &  ! Horizontal grid : glamt and gphit
+         &          1, jpj, 0, zjulian, rdt, nh_t, nidvor, domain_id=nidom )
+      CALL wheneq( jpi*jpj, fmask, 1, 1., ndexvor1, ndimvor1 )    ! surface
+
+      ! Declare output fields as netCDF variables
+      CALL histdef( nidvor, "sovortPh", cvort//"grad Ph" , "s-2",        & ! grad Ph
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovortEk", cvort//"Energy", "s-2",          & ! Energy
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovozeta", cvort//"rel vorticity", "s-2",   & ! rel vorticity
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovortif", cvort//"coriolis", "s-2",        & ! coriolis
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovodifl", cvort//"lat diff ", "s-2",       & ! lat diff
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovoadvv", cvort//"vert adv", "s-2",        & ! vert adv
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovodifv", cvort//"vert diff" , "s-2",      & ! vert diff
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovortPs", cvort//"grad Ps", "s-2",         & ! grad Ps
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovortbv", cvort//"Beta V", "s-2",          & ! beta.V
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovowind", cvort//"wind stress", "s-2",     & ! wind stress
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovobfri", cvort//"bottom friction", "s-2", & ! bottom friction
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "1st_mbre", cvort//"1st mbre", "s-2",        & ! First membre
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histdef( nidvor, "sovorgap", cvort//"gap", "s-2",             & ! gap between 1st and 2 nd mbre
+         &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
+      CALL histend( nidvor )
+
+      IF( idebug /= 0 ) THEN
+         WRITE(numout,*) ' debuging trd_vor_init: II. done'
+         CALL FLUSH(numout)
+      ENDIF
+      !
+   END SUBROUTINE trd_vor_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+   INTERFACE trd_vor_zint
+      MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
+   END INTERFACE
+CONTAINS
+   SUBROUTINE trd_vor( kt )        ! Empty routine
+      WRITE(*,*) 'trd_vor: You should not have seen this print! error?', kt
+   END SUBROUTINE trd_vor
+   SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
+      REAL, DIMENSION(:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      WRITE(*,*) 'trd_vor_zint_2d: You should not have seen this print! error?', putrdvor(1,1)
+      WRITE(*,*) '  "      "     : You should not have seen this print! error?', pvtrdvor(1,1)
+      WRITE(*,*) '  "      "     : You should not have seen this print! error?', ktrd
+   END SUBROUTINE trd_vor_zint_2d
+   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
+      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      WRITE(*,*) 'trd_vor_zint_3d: You should not have seen this print! error?', putrdvor(1,1,1)
+      WRITE(*,*) '  "      "     : You should not have seen this print! error?', pvtrdvor(1,1,1)
+      WRITE(*,*) '  "      "     : You should not have seen this print! error?', ktrd
+   END SUBROUTINE trd_vor_zint_3d
+   SUBROUTINE trd_vor_init              ! Empty routine
+      WRITE(*,*) 'trd_vor_init: You should not have seen this print! error?'
+   END SUBROUTINE trd_vor_init
+#endif
+   !!======================================================================
+END MODULE trdvor
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 4536)
@@ -0,0 +1,40 @@
+MODULE trdvor_oce
+   !!======================================================================
+   !!                   ***  MODULE trdvor_oce  ***
+   !! Ocean trends :   set vorticity trend variables
+   !!======================================================================
+   !! History :  9.0  ! ???
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+#if defined key_trdvor
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .TRUE.     !: momentum trend flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .FALSE.    !: momentum trend flag
+#endif
+   !!* vorticity trends index
+   INTEGER, PUBLIC, PARAMETER ::   jpltot_vor = 11  !: Number of vorticity trend terms
+   !
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_prg =  1   !: Pressure Gradient Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_keg =  2   !: KE Gradient Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_rvo =  3   !: Relative Vorticity Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_pvo =  4   !: Planetary Vorticity Term Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_ldf =  5   !: Horizontal Diffusion Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_zad =  6   !: Vertical Advection Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_zdf =  7   !: Vertical Diffusion Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_spg =  8   !: Surface Pressure Grad. Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_bev =  9   !: Beta V
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_swf = 10   !: wind stress forcing term
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_bfr = 11   !: bottom friction term
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trdvor_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trends_manager.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trends_manager.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/TRD/trends_manager.F90	(revision 4536)
@@ -0,0 +1,14 @@
+MODULE trends_manager
+   !!======================================================================
+   !!                       ***  MODULE  trends_manager  ***
+   !! Ocean diagnostics:  ocean tracers and dynamic trends
+   !!=====================================================================
+   !! History :  9.0  !  04-08  (C. Talandier) Original code
+   !!                 !  05-04  (C. Deltel)    Add Asselin trend in the ML budget
+   !!----------------------------------------------------------------------
+#if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
+
+#endif
+
+   !!======================================================================
+END MODULE trends_manager
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf.matrixsolver.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf.matrixsolver.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf.matrixsolver.h90	(revision 4536)
@@ -0,0 +1,57 @@
+!! 
+!!         ZDF.MATRIXSOLVER
+!!       ********************
+!! 
+!! Matrix inversion
+!!----------------------------------------------------------------------
+!   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+!
+!        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+!        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+!        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+!        (        ...               )( ...  ) ( ...  )
+!        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+!
+!   m is decomposed in the product of an upper and lower triangular
+!   matrix
+!   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+!   The second member is in 2d array zwy
+!   The solution is in 2d array zwx
+!   The 2d arry zwt and zwz are work space arrays
+!
+!   N.B. the starting vertical index (ikst) is equal to 1 except for
+!   the resolution of tke matrix where surface tke value is prescribed
+!   so that ikstrt=2.
+!!----------------------------------------------------------------------
+!!  OPA 9.0 , LOCEAN-IPSL (2005) 
+!! $Header$ 
+!! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+!!----------------------------------------------------------------------
+
+      ikstp1 = ikst + 1
+      ikenm2 = jpk - 2
+      DO ji = 2, jpim1
+         zwt(ji,ikst) = zwd(ji,ikst)
+      END DO
+      DO jk = ikstp1, jpkm1
+         DO ji = 2, jpim1
+            zwt(ji,jk) = zwd(ji,jk) - zwi(ji,jk) * zws(ji,jk-1) / zwt(ji,jk-1)
+         END DO
+      END DO
+      DO ji = 2, jpim1
+         zwz(ji,ikst) = zwy(ji,ikst)
+      END DO
+      DO jk = ikstp1, jpkm1
+         DO ji = 2, jpim1
+            zwz(ji,jk) = zwy(ji,jk) - zwi(ji,jk) / zwt(ji,jk-1) * zwz(ji,jk-1)
+         END DO
+      END DO
+      DO ji = 2, jpim1
+         zwx(ji,jpkm1) = zwz(ji,jpkm1) / zwt(ji,jpkm1)
+      END DO
+      DO jk = ikenm2, ikst, -1
+         DO ji = 2, jpim1
+            zwx(ji,jk) =( zwz(ji,jk) - zws(ji,jk) * zwx(ji,jk+1) ) / zwt(ji,jk)
+         END DO
+      END DO
+      
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 4536)
@@ -0,0 +1,52 @@
+MODULE zdf_oce
+   !!======================================================================
+   !!              ***  MODULE  zdf_oce  ***
+   !! Ocean physics : define vertical mixing variables
+   !!=====================================================================
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   zdf_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! mesh and scale factors
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Share Module variables
+   LOGICAL, PARAMETER, PUBLIC ::    &   !:
+#if defined key_zdfcst   ||   defined key_esopa
+      lk_zdfcst        = .TRUE.         !: constant vertical mixing flag
+#else
+      lk_zdfcst        = .FALSE.        !: constant vertical mixing flag
+#endif
+   LOGICAL, PUBLIC ::                & !!! namzdf: vertical diffusion
+      ln_zdfexp        = .FALSE. ,   &  !: explicit vertical diffusion scheme flag
+      ln_zdfevd        = .TRUE.  ,   &  !: convection: enhanced vertical diffusion flag
+      ln_zdfnpc        = .FALSE.        !: convection: non-penetrative convection flag
+
+   INTEGER, PUBLIC ::    & !!: namzdf:  vertical diffusion
+      n_zdfexp = 3    ,  &  !: number of sub-time step (explicit time stepping)
+      n_evdm   = 1          !: =0/1 flag to apply enhanced avm or not
+ 
+   REAL(wp), PUBLIC ::   & !!: namzdf   vertical diffusion
+      avm0  = 1.e-4_wp,  &  !: vertical eddy viscosity (m2/s)
+      avt0  = 1.e-5_wp,  &  !: vertical eddy diffusivity (m2/s)
+      avevd = 1._wp         !: vertical eddy coeff. for enhanced vert. diff. (m2/s)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      avmu,              &  !: vertical viscosity coeff. at uw-, vw-points
+      avmv,              &  !: vertical viscosity coeff. at uw-, vw-points
+      avt ,              &  !: vertical diffusivity coeff. at w-point
+      avt_evd,           &  !: convection: enhanced vertical diffusivity coeff. at w-point
+      avmu_evd              !: convection: enhanced vertical viscosity   coeff. at w-point
+ 
+   REAL(wp), PUBLIC, DIMENSION(jpk) ::   &   !:
+      avmb, avtb            !: background profile of avm and avt
+ 
+   !!======================================================================
+END MODULE zdf_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfbfr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 4536)
@@ -0,0 +1,236 @@
+MODULE zdfbfr
+   !!======================================================================
+   !!                       ***  MODULE  zdfbfr  ***
+   !! Ocean physics: Bottom friction
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   zdf_bfr      : update momentum Kz at the ocean bottom due to the
+   !!                  type of bottom friction chosen
+   !!   zdf_bfr_init : read in namelist and control the bottom friction
+   !!                  parameters.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_bfr    ! called by step.F90
+
+   !! * Module variables
+   INTEGER ::             & !!! ** bottom friction namelist (nambfr) **
+      nbotfr = 0             ! = 0/1/2/3 type of bottom friction 
+   REAL(wp) ::            & !!! ** bottom friction namelist (nambfr) **
+      bfri1 = 4.0e-4_wp,  &  ! bottom drag coefficient (linear case) 
+      bfri2 = 1.0e-3_wp,  &  ! bottom drag coefficient (non linear case)
+      bfeb2 = 2.5e-3_wp      ! background bottom turbulent kinetic energy  (m2/s2)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_bfr( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_bfr  ***
+      !!                 
+      !! ** Purpose :   Applied the bottom friction through a specification of 
+      !!      Kz at the ocean bottom.
+      !!
+      !! ** Method  :   Update the value of avmu and avmv at the ocean bottom 
+      !!       level following the chosen friction type (no-slip, free-slip, 
+      !!       linear, or quadratic)
+      !!
+      !! History :
+      !!   8.0  !  97-06  (G. Madec, A.-M. Treguier)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   &
+         ji, jj,                   &  ! dummy loop indexes
+         ikbu, ikbv,               &  ! temporary integers
+         ikbum1, ikbvm1               !
+      REAL(wp) ::   &
+         zvu, zuv, zecu, zecv         ! temporary scalars
+      !!----------------------------------------------------------------------
+
+
+      IF( kt == nit000 )   CALL zdf_bfr_init
+
+
+      ! Compute avmu, avmv at the ocean bottom
+      ! --------------------------------------
+
+      SELECT CASE (nbotfr)
+
+      CASE( 0 )                 ! no-slip boundary condition
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+# endif
+               ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+               ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+               ikbum1 = MAX( ikbu-1, 1 )
+               ikbvm1 = MAX( ikbv-1, 1 )
+               avmu(ji,jj,ikbu) = 2. * avmu(ji,jj,ikbum1)
+               avmv(ji,jj,ikbv) = 2. * avmv(ji,jj,ikbvm1)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+
+      CASE( 1 )                 ! linear botton friction
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+# endif
+               ikbu = MIN( mbathy(ji+1,jj), mbathy(ji,jj) )
+               ikbv = MIN( mbathy(ji,jj+1), mbathy(ji,jj) )
+               avmu(ji,jj,ikbu) = bfri1 * fse3uw(ji,jj,ikbu)
+               avmv(ji,jj,ikbv) = bfri1 * fse3vw(ji,jj,ikbv)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+
+      CASE( 2 )                 ! quadratic botton friction
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+!CDIR NOVERRCHK
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+!CDIR NOVERRCHK
+         DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+            DO ji = 2, jpim1
+# endif
+               ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+               ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+               ikbum1 = MAX( ikbu-1, 1 )
+               ikbvm1 = MAX( ikbv-1, 1 )
+               
+               zvu  = 0.25 * (  vn(ji,jj  ,ikbum1) + vn(ji+1,jj  ,ikbum1)     &
+                              + vn(ji,jj-1,ikbum1) + vn(ji+1,jj-1,ikbum1)  )
+               
+               zuv  = 0.25 * (  un(ji,jj  ,ikbvm1) + un(ji-1,jj  ,ikbvm1)     &
+                              + un(ji,jj+1,ikbvm1) + un(ji-1,jj+1,ikbvm1)  )
+               
+               zecu = SQRT(  un(ji,jj,ikbum1) * un(ji,jj,ikbum1) + zvu*zvu + bfeb2  )
+               zecv = SQRT(  vn(ji,jj,ikbvm1) * vn(ji,jj,ikbvm1) + zuv*zuv + bfeb2  )
+               
+               avmu(ji,jj,ikbu) = bfri2 * zecu * fse3uw(ji,jj,ikbu)
+               avmv(ji,jj,ikbv) = bfri2 * zecv * fse3vw(ji,jj,ikbv)
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+
+      CASE( 3 )                 ! free-slip boundary condition
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+# endif
+               ikbu = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+               ikbv = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+               avmu(ji,jj,ikbu) = 0.e0
+               avmv(ji,jj,ikbv) = 0.e0
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+
+      END SELECT
+
+      ! Lateral boundary condition on (avmu,avmv)   (unchanged sign)
+      ! ------------------------------===========
+      CALL lbc_lnk( avmu, 'U', 1. )
+      CALL lbc_lnk( avmv, 'V', 1. )
+
+      IF(ln_ctl)  THEN
+         CALL prt_ctl(tab3d_1=avmu, clinfo1=' bfr  - u: ', mask1=umask, &
+            &         tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask,ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE zdf_bfr
+
+
+   SUBROUTINE zdf_bfr_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_bfr_init  ***
+      !!                    
+      !! ** Purpose :   Initialization of the bottom friction
+      !!
+      !! ** Method  :   Read the nammbf namelist and check their consistency
+      !!      called at the first timestep (nit000)
+      !!
+      !! History :
+      !!   9.0  !  02-06  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      NAMELIST/nambfr/ nbotfr, bfri1, bfri2, bfeb2
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nambfr : bottom momentum boundary condition
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, nambfr )
+
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'zdf_bfr : momentum bottom friction'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      IF(lwp) WRITE(numout,*) '          Namelist nambfr : set bottom friction parameters'
+
+      SELECT CASE (nbotfr)
+
+      CASE( 0 )
+         IF(lwp) WRITE(numout,*) '            no-slip '
+
+      CASE( 1 )
+         IF(lwp) WRITE(numout,*) '            linear botton friction'
+         IF(lwp) WRITE(numout,*) '            friction coef.   bfri1  = ', bfri1
+
+      CASE( 2 )
+         IF(lwp) WRITE(numout,*) '            quadratic botton friction'
+         IF(lwp) WRITE(numout,*) '            friction coef.   bfri2  = ', bfri2
+         IF(lwp) WRITE(numout,*) '            background tke   bfeb2  = ', bfeb2
+
+      CASE( 3 )
+         IF(lwp) WRITE(numout,*) '            free-slip '
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '         bad flag value for nbotfr = ', nbotfr
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE zdf_bfr_init
+
+   !!======================================================================
+END MODULE zdfbfr
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 4536)
@@ -0,0 +1,260 @@
+MODULE zdfddm
+   !!======================================================================
+   !!                       ***  MODULE  zdfddm  ***
+   !! Ocean physics : double diffusion mixing parameterization
+   !!======================================================================
+#if defined key_zdfddm   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdfddm' :                                     double diffusion
+   !!----------------------------------------------------------------------
+   !!   zdf_ddm       : compute the Ks for salinity
+   !!   zdf_ddm_init  : read namelist and control the parameters
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_ddm     ! called by step.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfddm = .TRUE.    !: double diffusive mixing flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &   !:
+      avs ,               &  !: salinity vertical diffusivity coeff. at w-point
+      rrau                   !: heat/salt buoyancy flux ratio
+
+   !! * Module variables
+   REAL(wp) ::            & !!! * double diffusive mixing namelist *
+      avts  = 1.e-4_wp ,  &  ! maximum value of avs for salt fingering
+      hsbfr = 1.6_wp         ! heat/salt buoyancy flux ratio
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_ddm( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_ddm  ***
+      !!                    
+      !! ** Purpose :   Add to the vertical eddy diffusivity coefficient the 
+      !!      effect of salt fingering and diffusive convection. 
+      !!
+      !! ** Method  :   Diapycnal mixing is increased in case of double
+      !!      diffusive mixing (i.e. salt fingering and diffusive layering)
+      !!      following Merryfield et al. (1999). The rate of double diffusive 
+      !!      mixing depend on the buoyancy ratio: Rrau=alpha/beta dk[T]/dk[S]
+      !!      which is computed in rn2.F
+      !!         * salt fingering (Schmitt 1981):
+      !!      for Rrau > 1 and rn2 > 0 : zavfs = avts / ( 1 + (Rrau/hsbfr)^6 )
+      !!      for Rrau > 1 and rn2 > 0 : zavfs = O
+      !!      otherwise                : zavft = 0.7 zavs / Rrau
+      !!         * diffusive layering (Federov 1988):
+      !!      for 0< Rrau < 1 and rn2 > 0 : zavdt = 1.3635e-6  
+      !!                                 * exp( 4.6 exp(-0.54 (1/Rrau-1) ) )
+      !!      otherwise                   : zavdt = 0 
+      !!      for .5 < Rrau < 1 and rn2 > 0 : zavds = zavdt (1.885 Rrau -0.85)
+      !!      for  0 < Rrau <.5 and rn2 > 0 : zavds = zavdt 0.15 Rrau      
+      !!      otherwise                     : zavds = 0 
+      !!         * update the eddy diffusivity:
+      !!      avt = avt + zavft + zavdt
+      !!      avs = avs + zavfs + zavds
+      !!      avmu, avmv are required to remain at least above avt and avs.
+      !!      
+      !! ** Action  :   avt, avs : update vertical eddy diffusivity coef.
+      !!                           for temperature and salinity
+      !!
+      !! References :
+      !!      Merryfield et al., JPO, 29, 1124-1142, 1999.
+      !! History :
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step indexocean time step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj , jk              ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zmsks, zmskf,                    & ! temporary workspace 
+         zmskd1, zmskd2, zmskd3             !    "           "
+      REAL(wp) ::   &
+         zinr, zrr,                       & ! temporary scalars
+         zavft, zavfs,                    & !    "         "
+         zavdt, zavds                       !    "         "
+      !!----------------------------------------------------------------------
+
+
+      IF ( kt == nit000 )   CALL zdf_ddm_init          ! Initialization (first time-step only)
+
+
+      ! Compute avs
+      ! -----------
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Define the mask 
+         ! ---------------
+         ! only retains positive value of rrau
+         rrau(:,:,jk) = MAX( 1.e-20, rrau(:,:,jk) )
+
+         ! indicators:
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ! stability indicator: msks=1 if rn2>0; 0 elsewhere
+               IF( rn2(ji,jj,jk) + 1.e-12  <= 0. ) THEN
+                  zmsks(ji,jj) = 0.e0
+               ELSE
+                  zmsks(ji,jj) = 1.e0
+               ENDIF
+               ! salt fingering indicator: msksf=1 if rrau>1; 0 elsewhere            
+               IF( rrau(ji,jj,jk) <= 1. ) THEN
+                  zmskf(ji,jj) = 0.e0
+               ELSE
+                  zmskf(ji,jj) = 1.e0
+               ENDIF
+               ! diffusive layering indicators: 
+               !   mskdl1=1 if 0<rrau<1; 0 elsewhere
+               IF( rrau(ji,jj,jk) >= 1. ) THEN
+                  zmskd1(ji,jj) = 0.e0
+               ELSE
+                  zmskd1(ji,jj) = 1.e0
+               ENDIF
+               !   mskdl2=1 if 0<rrau<0.5; 0 elsewhere
+               IF( rrau(ji,jj,jk) >= 0.5 ) THEN
+                  zmskd2(ji,jj) = 0.e0
+               ELSE
+                  zmskd2(ji,jj) = 1.e0
+               ENDIF
+               !   mskdl3=1 if 0.5<rrau<1; 0 elsewhere
+               IF( rrau(ji,jj,jk) <= 0.5 .OR. rrau(ji,jj,jk) >= 1. ) THEN
+                  zmskd3(ji,jj) = 0.e0
+               ELSE
+                  zmskd3(ji,jj) = 1.e0
+               ENDIF
+            END DO
+         END DO
+         ! mask zmsk in order to have avt and avs masked
+         zmsks(:,:) = zmsks(:,:) * tmask(:,:,jk)
+
+
+         ! Update avt and avs
+         ! ------------------
+         ! Constant eddy coefficient: reset to the background value
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               zinr = 1./rrau(ji,jj,jk)
+               ! salt fingering
+               zrr = rrau(ji,jj,jk)/hsbfr
+               zrr = zrr * zrr
+               zavfs = avts / ( 1 + zrr*zrr*zrr ) * zmsks(ji,jj) *zmskf(ji,jj)
+               zavft = 0.7 * zavfs / rrau(ji,jj,jk)
+               ! diffusive layering
+               zavdt = 1.3635e-6 * EXP(4.6*EXP(-0.54*(zinr-1.) ) )   &
+                                 * zmsks(ji,jj) * zmskd1(ji,jj)
+               zavds = zavdt * zmsks(ji,jj)   &
+                     * ( (1.85 * rrau(ji,jj,jk) - 0.85 ) * zmskd3(ji,jj)   &
+                         + zavdt * 0.15 * rrau(ji,jj,jk) * zmskd2(ji,jj)  )
+               ! add to the eddy viscosity coef. previously computed
+               avs (ji,jj,jk) = avt(ji,jj,jk) + zavfs + zavds
+               avt (ji,jj,jk) = avt(ji,jj,jk) + zavft + zavdt
+            END DO
+         END DO
+
+
+         ! Increase avmu, avmv if necessary
+         ! --------------------------------
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk),    &
+                                     avt(ji,jj,jk), avt(ji+1,jj,jk),   &
+                                     avs(ji,jj,jk), avs(ji+1,jj,jk) )   &
+                              * umask(ji,jj,jk)
+               avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk),    &
+                                     avt(ji,jj,jk), avt(ji,jj+1,jk),   &
+                                     avs(ji,jj,jk), avs(ji,jj+1,jk) )   &
+                              * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                                ! ===============
+      END DO                                              !   End of slab
+      !                                                   ! ===============
+      
+      ! Lateral boundary conditions on ( avt, avs, avmu, avmv )   (unchanged sign)
+      ! -------------------------------========================
+      CALL lbc_lnk( avt , 'W', 1. )
+      CALL lbc_lnk( avs , 'W', 1. )
+      CALL lbc_lnk( avmu, 'U', 1. ) 
+      CALL lbc_lnk( avmv, 'V', 1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab3d_1=avt , clinfo1=' ddm  - t: ', tab3d_2=avs , clinfo2=' s: ', ovlap=1, kdim=jpk)
+         CALL prt_ctl(tab3d_1=avmu, clinfo1=' ddm  - u: ', mask1=umask, &
+            &         tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk)
+      ENDIF
+      
+   END SUBROUTINE zdf_ddm
+   
+   
+   SUBROUTINE zdf_ddm_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_ddm_init  ***
+      !!
+      !! ** Purpose :   Initialization of double diffusion mixing scheme
+      !!
+      !! ** Method  :   Read the nammbf namelist and check the parameter values
+      !!      called by zdf_ddm at the first timestep (nit000)
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      NAMELIST/namddm/ avts, hsbfr
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namddm : double diffusion mixing scheme
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namddm )
+
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_ddm : double diffusive mixing'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist namddm : set dd mixing parameter'
+         WRITE(numout,*) '             maximum avs for dd mixing      avts   = ', avts
+         WRITE(numout,*) '             heat/salt buoyancy flux ratio  hsbfr  = ', hsbfr
+         WRITE(numout,*)
+      ENDIF
+
+   END SUBROUTINE zdf_ddm_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :          Dummy module          No double diffusion
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfddm = .FALSE.   !: double diffusion flag
+CONTAINS
+   SUBROUTINE zdf_ddm( kt )           ! Dummy routine
+      WRITE(*,*) 'zdf_ddm: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_ddm
+#endif
+
+   !!======================================================================
+END MODULE zdfddm
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90	(revision 4536)
@@ -0,0 +1,18 @@
+   !!----------------------------------------------------------------------
+   !!                    *** zdfddm_substitute.h90  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsaht. the eddy diffusivity coeff.
+   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_zdfddm
+!   'key_zdfddm' :                      avs: 3D array defined in zdfddm module
+#   define   fsavs(i,j,k)   avs(i,j,k)
+#else
+!   Defautl option :                     avs = avt
+#   define   fsavs(i,j,k)   avt(i,j,k)
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfevd.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 4536)
@@ -0,0 +1,167 @@
+MODULE zdfevd
+   !!======================================================================
+   !!                       ***  MODULE  zdfevd  ***
+   !! Ocean physics: parameterization of convection through an enhancement
+   !!                of vertical eddy mixing coefficient
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   zdf_evd      : update momentum and tracer Kz at the location of
+   !!                  statically unstable portion of the water column
+   !!                  (called if ln_zdfevd=T)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics variables
+   USE zdfkpp          ! KPP vertical mixing
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_evd      ! called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_evd( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_evd  ***
+      !!                   
+      !! ** Purpose :   Local increased the vertical eddy viscosity and diffu-
+      !!      sivity coefficients when a static instability is encountered.
+      !!
+      !! ** Method  :   avt, and the 4 neighbouring avmu, avmv coefficients
+      !!      are set to avevd (namelist parameter) if the water column is 
+      !!      statically unstable (i.e. if rn2 < -1.e-12 )
+      !!
+      !! ** Action  :   Update avt, avmu, avmv in statically instable cases
+      !!                and avt_evd which is avt due to convection
+      !! References :
+      !!      Lazar, A., these de l'universite Paris VI, France, 1997
+      !! History :
+      !!   7.0  !  97-06  (G. Madec, A. Lazar)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  05-06  (C. Ethe) KPP parameterization
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step indexocean time step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'zdf_evd : Enhanced Vertical Diffusion (evd)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      ! Initialisation of avt_evd (vertical diffusion due to convection) to avt and avmu_evd to avmu
+      avt_evd  (:,:,:) = avt(:,:,:) 
+      avmu_evd (:,:,:) = avmu(:,:,:) 
+
+      SELECT CASE ( n_evdm )
+ 
+      CASE ( 1 )           ! enhance vertical eddy viscosity and diffusivity (if rn2<-1.e-12)
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+#   if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+!!!         WHERE( rn2(:,:,jk) <= -1.e-12 ) avt(:,:,jk) = tmask(:,:,jk) * avevd   ! agissant sur T SEUL!
+            jj = 1                     ! big loop forced
+            DO ji = jpi+2, jpij   
+#   if defined key_zdfkpp
+!! no implicit mixing in the boundary layer with KPP
+               IF( ( rn2(ji,jj,jk) <= -1.e-12 ) .AND. ( fsdepw(ji,jj,jk) > hkpp(ji,jj) ) ) THEN
+#   else
+               IF( rn2(ji,jj,jk) <= -1.e-12 ) THEN
+#   endif
+                  avt (ji  ,jj  ,jk) = avevd * tmask(ji  ,jj  ,jk)
+                  avmu(ji  ,jj  ,jk) = avevd * umask(ji  ,jj  ,jk)
+                  avmu(ji-1,jj  ,jk) = avevd * umask(ji-1,jj  ,jk)
+                  avmv(ji  ,jj  ,jk) = avevd * vmask(ji  ,jj  ,jk)
+                  avmv(ji  ,jj-1,jk) = avevd * vmask(ji  ,jj-1,jk)
+               ENDIF
+            END DO
+#   else
+            DO jj = 2, jpj             ! no vector opt.
+               DO ji = 2, jpi
+#   if defined key_zdfkpp
+!! no implicit mixing in the boundary layer with KPP
+               IF( ( rn2(ji,jj,jk) <= -1.e-12 ) .AND. ( fsdepw(ji,jj,jk) > hkpp(ji,jj) ) ) THEN
+#   else
+               IF( rn2(ji,jj,jk) <= -1.e-12 ) THEN
+#   endif
+                     avt (ji  ,jj  ,jk) = avevd * tmask(ji  ,jj  ,jk)
+                     avmu(ji  ,jj  ,jk) = avevd * umask(ji  ,jj  ,jk)
+                     avmu(ji-1,jj  ,jk) = avevd * umask(ji-1,jj  ,jk)
+                     avmv(ji  ,jj  ,jk) = avevd * vmask(ji  ,jj  ,jk)
+                     avmv(ji  ,jj-1,jk) = avevd * vmask(ji  ,jj-1,jk)
+                  ENDIF
+               END DO
+            END DO
+#   endif
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+         ! Lateral boundary conditions on ( avt, avmu, avmv )   (unchanged sign)
+         ! -------------------------------===================
+         CALL lbc_lnk( avt , 'W', 1. )
+         CALL lbc_lnk( avmu, 'U', 1. )
+         CALL lbc_lnk( avmv, 'V', 1. )
+
+      CASE DEFAULT         ! enhance vertical eddy diffusivity only (if rn2<-1.e-12) 
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+!!!         WHERE( rn2(:,:,jk) <= -1.e-12 ) avt(:,:,jk) = tmask(:,:,jk) * avevd   ! agissant sur T SEUL! 
+#   if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+            jj = 1                     ! big loop forced
+            DO ji = 1, jpij   
+#   if defined key_zdfkpp
+!! no implicit mixing in the boundary layer with KPP
+               IF( ( rn2(ji,jj,jk) <= -1.e-12 ) .AND. ( fsdepw(ji,jj,jk) > hkpp(ji,jj) ) ) &              
+                  avt(ji,jj,jk) = avevd * tmask(ji,jj,jk)
+#   else
+               IF( rn2(ji,jj,jk) <= -1.e-12 )   avt(ji,jj,jk) = avevd * tmask(ji,jj,jk)
+#   endif
+            END DO
+#   else
+            DO jj = 1, jpj             ! loop over the whole domain (no lbc_lnk call)
+               DO ji = 1, jpi
+#   if defined key_zdfkpp
+!! no implicit mixing in the boundary layer with KPP
+               IF( ( rn2(ji,jj,jk) <= -1.e-12 ) .AND. ( fsdepw(ji,jj,jk) > hkpp(ji,jj) ) ) &          
+                  avt(ji,jj,jk) = avevd * tmask(ji,jj,jk)
+#   else
+                  IF( rn2(ji,jj,jk) <= -1.e-12 )   avt(ji,jj,jk) = avevd * tmask(ji,jj,jk)
+#   endif
+               END DO
+            END DO
+#   endif
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+      END SELECT 
+
+      ! update of avt_evd and avmu_evd
+      avt_evd  (:,:,:) = avt (:,:,:)  - avt_evd  (:,:,:) 
+      avmu_evd (:,:,:) = avmu(:,:,:)  - avmu_evd (:,:,:) 
+
+   END SUBROUTINE zdf_evd
+
+   !!======================================================================
+END MODULE zdfevd
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4536)
@@ -0,0 +1,141 @@
+MODULE zdfini
+   !!======================================================================
+   !!              ***  MODULE  zdfini  ***
+   !! Ocean physics : define vertical mixing variables
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   zdf_init    : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! mesh and scale factors
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics lateral physics
+   USE zdf_oce         ! TKE vertical mixing          
+   USE lib_mpp         ! distribued memory computing
+   USE zdftke          ! TKE vertical mixing  
+   USE zdfkpp          ! KPP vertical mixing          
+   USE zdfddm          ! double diffusion mixing      
+   USE zdfevd          ! enhanced vertical diffusion  
+   USE zdfric          ! Richardson vertical mixing   
+   USE tranpc          ! convection: non penetrative adjustment
+   USE ldfslp          ! iso-neutral slopes
+
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC zdf_init          ! routine called by opa.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE zdf_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_init  ***
+      !! 
+      !! ** Purpose :   initializations of the vertical ocean physics
+      !!
+      !! ** Method  :   Read namelist namzdf, control logicals 
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code from inimix
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!   9.0  !  05-06  (C. Ethe) KPP parameterization
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ioptio       ! temporary scalar
+
+      !! * Namelist
+      NAMELIST/namzdf/ ln_zdfexp, n_zdfexp, ln_zdfevd, ln_zdfnpc,   &
+         &             avm0     , avt0    , avevd    , n_evdm
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0, LODYC-IPSL (2003)
+      !!----------------------------------------------------------------------
+
+      ! Read namzdf namelist : vertical mixing parameters
+      ! --------------------
+      REWIND( numnam )
+      READ  ( numnam, namzdf )
+
+      ! Parameter print
+      ! ---------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_init: vertical physics'
+         WRITE(numout,*) '~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
+         WRITE(numout,*) '      time splitting / backward scheme    ln_zdfexp = ', ln_zdfexp
+         WRITE(numout,*) '      number of time step                  n_zdfexp = ', n_zdfexp
+         WRITE(numout,*) '      enhanced vertical diffusion         ln_zdfevd = ', ln_zdfevd
+         WRITE(numout,*) '      non-penetrative convection          ln_zdfnpc = ', ln_zdfnpc
+         WRITE(numout,*) '      vertical eddy viscosity             avm0      = ', avm0
+         WRITE(numout,*) '      vertical eddy diffusivity           avt0      = ', avt0
+         WRITE(numout,*) '      vertical coefficient for evd        avevd     = ', avevd
+         WRITE(numout,*) '         applied on momentum (=1/0)       n_evdm    = ', n_evdm
+      ENDIF
+
+      ! Parameter & logicals controls
+      ! -----------------------------
+      ! ... check of vertical mixing scheme on tracers
+      !           ==> will be done in trazdf module
+
+      ! ... check of mixing coefficient
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          vertical mixing option :'
+      ioptio = 0
+      IF( lk_zdfcst ) THEN
+         IF(lwp) WRITE(numout,*) '             constant eddy diffusion coefficients'
+         ioptio = ioptio+1
+      ENDIF
+      IF( lk_zdfric ) THEN
+         IF(lwp) WRITE(numout,*) '             Richardson dependent eddy coefficients'
+         ioptio = ioptio+1
+      ENDIF
+      IF( lk_zdftke ) THEN
+         IF(lwp) WRITE(numout,*) '             TKE dependent eddy coefficients'
+         ioptio = ioptio+1
+      ENDIF
+      IF( lk_zdfkpp ) THEN
+         IF(lwp) WRITE(numout,*) '             KPP dependent eddy coefficients'
+         ioptio = ioptio+1
+      ENDIF
+      IF( ioptio == 0 .OR. ioptio > 1 .AND. .NOT. lk_esopa ) &
+         CALL ctl_stop( ' one and only one vertical diffusion option has to be defined ' )
+
+      ! ... Convection
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          convection :'
+      ioptio = 0
+      IF( ln_zdfnpc ) THEN
+         IF(lwp) WRITE(numout,*) '             use non penetrative convective scheme'
+         ioptio = ioptio+1
+      ENDIF
+      IF( ln_zdfevd ) THEN
+         IF(lwp) WRITE(numout,*) '             use enhanced vertical dif. scheme'
+         ioptio = ioptio+1
+      ENDIF
+      IF( lk_zdftke ) THEN
+         IF(lwp) WRITE(numout,*) '             use the 1.5 turbulent closure'
+      ENDIF
+      IF( lk_zdfkpp ) THEN
+         IF(lwp) WRITE(numout,*) '             use the KPP closure scheme'
+         IF(lk_mpp) THEN
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*) '             The KPP scheme is not ready to run in MPI'
+         ENDIF
+      ENDIF
+      IF ( ioptio > 1 .AND. .NOT. lk_esopa ) &
+           CALL ctl_stop( ' chose between ln_zdfnpc', '           and ln_zdfevd' )
+      IF( ioptio == 0 .AND. .NOT.( lk_zdftke .OR. lk_zdfkpp ) ) &
+         CALL ctl_stop( ' except for TKE sor KPP physics, a convection scheme is', &
+         &              ' required: ln_zdfevd or ln_zdfnpc logicals' )
+
+   END SUBROUTINE zdf_init
+
+   !!======================================================================
+END MODULE zdfini
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 4536)
@@ -0,0 +1,1591 @@
+MODULE zdfkpp
+   !!======================================================================
+   !!                       ***  MODULE  zdfkpp  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the KPP 
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !! History :  8.1  ! 00-03 (W.G. Large, J. Chanut) Original code
+   !!            8.1  ! 02-06 (J.M. Molines) for real case CLIPPER  
+   !!            8.2  ! 03-10 (Chanut J.) re-writting
+   !!            9.0  ! 05-01 (C. Ethe) Free form, F90
+   !!----------------------------------------------------------------------
+#if defined key_zdfkpp   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdfkpp'                                             KPP scheme
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   zdf_kpp      : update momentum and tracer Kz from a kpp scheme
+   !!   zdf_kpp_init : initialization, namelist read, and parameters control
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE taumod          ! surface stress
+   USE eosbn2          ! equation of state
+   USE ocesbc          ! thermohaline fluxes
+   USE zdfddm          ! double diffusion mixing
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_kpp   ! routine called by step.F90
+   PUBLIC   tra_kpp   ! routine called by step.F90
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfkpp = .TRUE.    !: KPP vertical mixing flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   ghats   !: non-local scalar mixing term (gamma/<ws>o)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   & 
+      wt0                   ,  &  !: surface temperature flux for non local flux
+      ws0                   ,  &  !: surface salinity flux for non local flux
+      hkpp                        !: boundary layer depht
+
+   INTEGER ::                  & !!! ** kpp namelist (namkpp) **
+      nave  =  1            ,  &  ! = 0/1 flag for horizontal average on avt, avmu, avmv
+      navb  =  0                  ! = 0/1 flag for constant or profile background avt
+
+   REAL(wp) ::                 & !!! ** Interior Mixing 
+      difmiw  = 1.2e-04_wp  ,  &  ! constant internal wave viscosity (m2/s)
+      difsiw  = 1.2e-05_wp  ,  &  ! constant internal wave diffusivity (m2/s)
+      Riinfty = 0.8_wp      ,  &  ! local Richardson Number limit for shear instability
+      difri   = 5.e-03_wp   ,  &  ! maximum shear mixing at Rig = 0    (m2/s)
+      bvsqcon = -1.e-09_wp  ,  &  ! Brunt-Vaisala squared (1/s**2) for maximum convection
+      difcon  = 1._wp             ! maximum mixing in interior convection (m2/s)
+#if defined key_zdfddm
+   REAL(wp) ::                 & !!! ** Double diffusion Mixing
+      difssf  = 1.e-03_wp   ,  &  ! maximum salt fingering mixing 
+      Rrho0   = 1.9_wp      ,  &  ! limit for salt  fingering mixing 
+      difsdc  = 1.5e-06_wp       ! maximum diffusive convection mixing
+#endif
+   LOGICAL  ::                 &
+      ln_kpprimix  = .TRUE.       ! Shear instability mixing 
+
+   REAL(wp) ::                 & !!! ** General constants  **
+      epsln   = 1.0e-20_wp   , &  ! a small positive number    
+      pthird  = 1._wp/3._wp  , &  ! 1/3
+      pfourth = 1._wp/4._wp       ! 1/4
+
+   REAL(wp) ::                 & !!! ** Boundary Layer Turbulence Parameters  **
+      vonk     = 0.4_wp     ,  &  ! von Karman's constant
+      epsilon  = 0.1_wp     ,  &  ! nondimensional extent of the surface layer
+      rconc1   = 5.0_wp     ,  &  ! standard flux profile function parmaeters
+      rconc2   = 16.0_wp    ,  &  !         "        "
+      rconcm   = 8.38_wp    ,  &  ! momentum flux profile fit
+      rconam   = 1.26_wp    ,  &  !         "       "
+      rzetam   = -.20_wp    ,  &  !         "       "       
+      rconcs   = 98.96_wp   ,  &  !  scalar  flux profile fit
+      rconas   = -28.86_wp  ,  &  !         "       "
+      rzetas   = -1.0_wp          !         "       "  
+   REAL(wp) ::                 & !!! ** Boundary Layer Depth Diagnostic  **
+      Ricr     = 0.3_wp     ,  &  ! critical bulk Richardson Number
+      rcekman  = 0.7_wp     ,  &  ! coefficient for ekman depth  
+      rcmonob  = 1.0_wp     ,  &  ! coefficient for Monin-Obukhov depth 
+      rconcv   = 1.7_wp     ,  &  ! ratio of interior buoyancy frequency to buoyancy frequency at entrainment depth
+      hbf      = 1.0_wp     ,  &  ! fraction of bound. layer depth to which absorbed solar 
+      !                           ! rad. and contributes to surf. buo. forcing
+      Vtc                         ! function of rconcv,rconcs,epsilon,vonk,Ricr
+   REAL(wp) ::                 & !!! ** Nonlocal Boundary Layer Mixing **
+      rcstar   = 5.0_wp     ,  &  ! coefficient for convective nonlocal transport
+      rcs      = 1.0e-3_wp  ,  &  ! conversion: mm/s ==> m/s   
+      rcg                         ! non-dimensional coefficient for nonlocal transport
+
+#if ! defined key_kppcustom
+   REAL(wp), DIMENSION(jpk,jpk) ::   & 
+      del                         ! array for reference mean values of vertical integration 
+#endif
+
+#if defined key_kpplktb
+   INTEGER, PARAMETER ::       & !!! ** Parameters for lookup table for turbulent velocity scales ** 
+      nilktb   = 892        ,  &  ! number of values for zehat in KPP lookup table
+      njlktb   = 482        ,  &  ! number of values for ustar in KPP lookup table
+      nilktbm1 = nilktb - 1 ,  &  !
+      njlktbm1 = njlktb - 1       !
+
+   REAL(wp), DIMENSION(nilktb,njlktb) ::  &
+      wmlktb                ,  &  ! lookup table for the turbulent vertical velocity scale for momentum
+      wslktb                       ! lookup table for the turbulent vertical velocity scale for tracers
+
+   REAL(wp) ::                 &
+      dehatmin = -4.e-7_wp  ,  &  ! minimum limit for zhat in lookup table (m3/s3) 
+      dehatmax = 0._wp      ,  &  ! maximum limit for zhat in lookup table (m3/s3)
+      ustmin   = 0._wp      ,  &  ! minimum limit for ustar in lookup table (m/s)
+      ustmax   = 0.04_wp    ,  &  ! maximum limit for ustar in lookup table (m/s)    
+      dezehat               ,  &  ! delta zhat in lookup table
+      deustar                     ! delta ustar in lookup table
+#endif
+   REAL(wp), DIMENSION(jpk) :: &  !!! attenuation coef  
+      ratt        
+   !! already defines in module traqsr, but only if the solar radiation penetration is considered
+   REAL(wp) ::                 & !!! * penetrative solar radiation coefficient *
+      rabs = 0.58_wp        ,  &  ! fraction associated with xsi1
+      xsi1 = 0.35_wp        ,  &  ! first depth of extinction 
+      xsi2 = 23.0_wp              ! second depth of extinction 
+      !                           ! (default values: water type Ib) 
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      etmean                ,  &  ! coefficient used for horizontal smoothing
+      eumean                ,  &  ! at t-, u- and v-points
+      evmean  
+ 
+#if defined key_cfg_1d
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &
+      rig                   ,  &  ! gradient Richardson number
+      rib                   ,  &  ! bulk Richardson number
+      buof                  ,  &  ! buoyancy forcing
+      mols                        ! moning-Obukhov length scale 
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &
+      ekdp                        ! Ekman depth
+#endif
+
+   INTEGER  ::  &                 !
+      jip = 62 , jjp = 111
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL   (2005)
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_kpp ( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_kpp  ***
+      !!
+      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients and non local mixing using K-profile parameterization
+      !!
+      !! ** Method :   The boundary layer depth hkpp is diagnosed at tracer points
+      !!      from profiles of buoyancy, and shear, and the surface forcing.
+      !!      Above hbl (sigma=-z/hbl <1) the mixing coefficients are computed from 
+      !!
+      !!                      Kx =  hkpp  Wx(sigma) G(sigma)  
+      !!
+      !!             and the non local term ghat = Cs / Ws(sigma) / hkpp
+      !!      Below hkpp  the coefficients are the sum of mixing due to internal waves
+      !!      shear instability and double diffusion.
+      !!
+      !!      -1- Compute the now interior vertical mixing coefficients at all depths. 
+      !!      -2- Diagnose the boundary layer depth. 
+      !!      -3- Compute the now boundary layer vertical mixing coefficients. 
+      !!      -4- Compute the now vertical eddy vicosity and diffusivity.
+      !!      -5- Smoothing
+      !!
+      !!        N.B. The computation is done from jk=2 to jpkm1 
+      !!             Surface value of avt avmu avmv are set once a time to zero
+      !!             in routine zdf_kpp_init.
+      !!
+      !! ** Action  :   update the non-local terms ghats
+      !!                update avt, avmu, avmv (before vertical eddy coef.)
+      !!
+      !! References : Large W.G., Mc Williams J.C. and Doney S.C.              
+      !!         Reviews of Geophysics, 32, 4, November 1994
+      !!         Comments in the code refer to this paper, particularly 
+      !!         the equation number. (LMD94, here after)
+      !!----------------------------------------------------------------------
+#if defined  key_zdfddm
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta,      &  ! temp. array for diffusivities use sa as workspace
+         &          zdiffus => sa          ! temp. array for diffusivities use sa as workspace
+#else
+      USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
+         &          zdiffut => ta          ! temp. array for diffusivities use sa as workspace
+#endif
+      !!
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!
+      INTEGER ::   ji, jj, jk              ! dummy loop indices
+      INTEGER ::   ikbot, jkmax, jkm1, jkp2   !
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   & !!! Surface buoyancy forcing, friction velocity
+         zBo, zBosol, zustar              !
+                      !
+      REAL(wp) ::                       &  !
+         ztx, zty, ztau, zflageos,      &  !
+         zstabl, zbuofdep,zucube,       &  !
+         zrhos, zalbet, zbeta,          &  !
+         zthermal, zhalin, zatt1           !
+     
+      REAL(wp) ::                       & !!! Bulk richardson number
+         zref, zt, zs, zh,              &  !
+         zu, zv, zrh,                   &  !
+         zrib, zrinum,                  &  !
+         zdVsq, zVtsq                      !
+      
+      REAL(wp) ::                       & !!! Velocity scales
+         zehat, zeta, zhrib, zsig,      &  !
+         zscale, zwst, zws, zwm
+
+#if defined key_kpplktb
+      INTEGER ::                        & !!! Lookup table or Analytical functions 
+         il, jl                            !
+      REAL(wp) ::                       &  !
+         ud, zfrac, ufrac,              &  !
+         zwam, zwbm, zwas, zwbs            !
+#else
+     REAL(wp) ::                        &  !
+        zwsun, zwmun,                   & 
+        zcons, zconm, zwcons, zwconm      !
+#endif
+ 
+     REAL(wp) ::                       & !!! In situ density
+         zsr, zbw, ze,                  &  !
+         zb, zd, zc, zaw, za,           &  !
+         zb1, za1, zkw, zk0,            &  !
+         zcomp , zrhd, zrhdr,zbvzed       !
+
+#if ! defined key_kppcustom     
+     !! * local declarations
+      INTEGER ::                        &
+         jm                                ! dummy loop indices
+      REAL(wp) ::                       & !!! Compression terms
+         zr1, zr2, zr3, zr4,            &  !
+         zrhop                             !
+#endif
+ 
+      REAL(wp) ::                       &  !
+         zflag, ztemp, zrn2,            &  !
+         zdep21, zdep32, zdep43
+
+      REAL(wp) ::                       & !!! Interior richardson mixing
+         zdku2, zdkv2, ze3sqr,          &  !
+         zsh2, zri, zfri                   !
+
+      REAL(wp), DIMENSION(jpi,0:2) ::  &  !!! Moning-Obukov limitation
+         zmoek
+      REAL(wp), DIMENSION(jpi)     ::  &
+         zmoa, zekman                
+      REAL(wp)                     ::  &
+         zmob, zek
+
+      REAL(wp), DIMENSION(jpi,4) ::     &  !!! The pipe 
+         zdepw, zdift, zvisc
+      REAL(wp), DIMENSION(jpi,3) ::     & 
+         zdept
+      REAL(wp), DIMENSION(jpi,2) ::     &  
+         zriblk
+      REAL(wp), DIMENSION(jpi,jpk) ::   &  !
+         zmask                          
+      REAL(wp), DIMENSION(jpi) ::       &  ! 
+         zhmax, zria, zhbl 
+      REAL(wp) ::                       &  !
+         zflagri, zflagek,              &  !
+         zflagmo, zflagh, zflagkb          !
+      REAL(wp), DIMENSION(jpi)     ::   & !!! Shape function (G)
+         za2m, za3m, zkmpm,             &
+         za2t, za3t, zkmpt
+      REAL(wp) ::                       &  !
+         zdelta, zdelta2,               &  !
+         zdzup, zdzdn, zdzh,            &  !
+         zvath, zgat1, zdat1,           &  !
+         zkm1m, zkm1t
+      REAL(wp), DIMENSION(jpi,jpk) ::   & !!! Boundary layer diffusivities/viscosities
+         zblcm, zblct                          
+#if defined key_zdfddm
+      REAL(wp) ::                       & !!! double diffusion mixing
+         zrrau, zds,                    &
+         zavdds, zavddt,zinr 
+      REAL(wp), DIMENSION(jpi,4) ::     &  
+        zdifs
+      REAL(wp), DIMENSION(jpi)     ::   &
+         za2s, za3s, zkmps
+      REAL(wp) ::                       & 
+         zkm1s
+      REAL(wp), DIMENSION(jpi,jpk) ::   & 
+         zblcs                     
+#endif
+      !!--------------------------------------------------------------------
+
+
+      ! Initialization (first time-step only)
+      ! --------------
+      IF( kt == nit000  )   CALL zdf_kpp_init
+     
+      zviscos(:,:,:) = 0.
+      zblcm  (:,:  ) = 0. 
+      zdiffut(:,:,:) = 0.
+      zblct  (:,:  ) = 0. 
+#if defined key_zdfddm
+      zdiffus(:,:,:) = 0.
+      zblcs  (:,:  ) = 0. 
+#endif
+      ghats(:,:,:) = 0.
+     
+      zBo   (:,:) = 0.
+      zBosol(:,:) = 0.
+      zustar(:,:) = 0.
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! I. Interior diffusivity and viscosity at w points ( T interfaces)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1 
+               ! Mixing due to internal waves breaking
+               ! -------------------------------------
+               avmu(ji,jj,jk)  = difmiw 
+               avt (ji,jj,jk)  = difsiw             
+               ! Mixing due to vertical shear instability
+               ! -------------------------------------               
+               IF( ln_kpprimix ) THEN          
+                  ! Compute the gradient Richardson  number at interfaces (zri):
+                  ! LMD94, eq. 27 (is vertical smoothing needed : Rig=N^2 / (dz(u))^2 + (dz(v))^2
+                  zdku2 =   ( un(ji - 1,jj,jk - 1) - un(ji - 1,jj,jk) ) &
+                     &    * ( un(ji - 1,jj,jk - 1) - un(ji - 1,jj,jk) ) &
+                     &    + ( un(ji    ,jj,jk - 1) - un(ji    ,jj,jk) ) &
+                     &    * ( un(ji    ,jj,jk - 1) - un(ji    ,jj,jk) )  
+                  
+                  zdkv2 =   ( vn(ji,jj - 1,jk - 1) - vn(ji,jj - 1,jk) ) &
+                     &    * ( vn(ji,jj - 1,jk - 1) - vn(ji,jj - 1,jk) ) &
+                     &    + ( vn(ji,    jj,jk - 1) - vn(ji,    jj,jk) ) &
+                     &    * ( vn(ji,    jj,jk - 1) - vn(ji,    jj,jk) )  
+
+                  ze3sqr = 1. / ( fse3w(ji,jj,jk) * fse3w(ji,jj,jk) )
+                  ! Square of vertical shear  at interfaces
+                  zsh2   = 0.5 * 0.5 * ( zdku2 + zdkv2 ) * ze3sqr
+                  zri    = MAX( rn2(ji,jj,jk), 0. ) / ( zsh2 + epsln ) 
+#if defined key_cfg_1d
+                  ! save the gradient richardson number
+                  rig(ji,jj,jk) = zri * tmask(ji,jj,jk)
+#endif                  
+                  ! Evaluate f of Ri (zri) for shear instability store in zfri
+                  ! LMD94, eq. 28a,b,c, figure 3 ; Rem: p1 is 3, hard coded
+                  zfri  = MAX( zri , 0. )
+                  zfri  = MIN( zfri / Riinfty , 1.0 )
+                  zfri  = ( 1.0 - zfri * zfri )
+                  zfri  = zfri * zfri  * zfri
+                  ! add shear contribution to mixing coef. 
+                  avmu(ji,jj,jk) =  avmu(ji,jj,jk) + difri * zfri   
+                  avt (ji,jj,jk) =  avt (ji,jj,jk) + difri * zfri    
+               ENDIF
+#if defined key_zdfddm 
+               avs (ji,jj,jk) =  avt (ji,jj,jk)              
+               !  Double diffusion mixing ; NOT IN ROUTINE ZDFDDM.F90
+               ! ------------------------------------------------------------------
+               ! only retains positive value of rrau
+               zrrau = MAX( rrau(ji,jj,jk), epsln )
+               zds   = sn(ji,jj,jk-1) - sn(ji,jj,jk)
+               IF( zrrau > 1. .AND. zds > 0.) THEN
+                  !
+                  ! Salt fingering case.
+                  !---------------------
+                  ! Compute interior diffusivity for double diffusive mixing of
+                  ! salinity. Upper bound "zrrau" by "Rrho0"; (Rrho0=1.9, difcoefnuf=0.001).
+                  ! After that set interior diffusivity for double diffusive mixing
+                  ! of temperature
+                  zavdds = MIN( zrrau, Rrho0 )
+                  zavdds = ( zavdds - 1.0 ) / ( Rrho0 - 1.0 )
+                  zavdds = 1.0 - zavdds * zavdds 
+                  zavdds = zavdds * zavdds * zavdds 
+                  zavdds = difssf * zavdds 
+                  zavddt = 0.7 * zavdds
+               ELSEIF( zrrau < 1. .AND. zrrau > 0. .AND. zds < 0.) THEN
+                  !
+                  ! Diffusive convection case.
+                  !---------------------------
+                  ! Compute interior diffusivity for double diffusive mixing of
+                  ! temperature (Marmorino and Caldwell, 1976); 
+                  ! Compute interior diffusivity for double diffusive mixing of salinity 
+                  zinr   = 1. / zrrau
+                  zavddt = 0.909 * EXP( 4.6 * EXP( -0.54* ( zinr - 1. ) ) ) 
+                  zavddt = difsdc * zavddt
+                  IF( zrrau < 0.5) THEN
+                     zavdds = zavddt * 0.15 * zrrau
+                  ELSE
+                     zavdds = zavddt * (1.85 * zrrau - 0.85 ) 
+                  ENDIF
+               ELSE
+                  zavddt = 0.
+                  zavdds = 0.
+               ENDIF 
+               ! Add double diffusion contribution to temperature and salinity  mixing coefficients.
+               avt (ji,jj,jk) =  avt (ji,jj,jk) +  zavddt 
+               avs (ji,jj,jk) =  avs (ji,jj,jk) +  zavdds         
+#endif                      
+            END DO
+         END DO
+      END DO
+
+
+      ! Radiative (zBosol) and non radiative (zBo) surface buoyancy
+      !JMM at the time zdfkpp is called, q still holds the sum q + qsr
+      !---------------------------------------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1     
+            IF( neos < 1) THEN   
+               zt     = tn(ji,jj,1)
+               zs     = sn(ji,jj,1) - 35.0
+               zh     = fsdept(ji,jj,1)
+               !  potential volumic mass
+               zrhos  = rhop(ji,jj,1)
+               zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
+                  &                               - 0.203814e-03 ) * zt   &
+                  &                               + 0.170907e-01 ) * zt   &
+                  &   + 0.665157e-01                                      &
+                  &   +     ( - 0.678662e-05 * zs                         &
+                  &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
+                  &   +   ( ( - 0.302285e-13 * zh                         &
+                  &           - 0.251520e-11 * zs                         &
+                  &           + 0.512857e-12 * zt * zt           ) * zh   &
+                  &           - 0.164759e-06 * zs                         &
+                  &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
+                  &                               + 0.380374e-04 ) * zh
+
+               zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
+                  &                            - 0.301985e-05 ) * zt      &
+                  &   + 0.785567e-03                                      &
+                  &   + (     0.515032e-08 * zs                           &
+                  &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
+                  &   +(  (   0.121551e-17 * zh                           &
+                  &         - 0.602281e-15 * zs                           &
+                  &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
+                  &                             + 0.408195e-10   * zs     &
+                  &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
+                  &                             - 0.121555e-07 ) * zh
+
+               zthermal = zbeta * zalbet / ( rcp * zrhos + epsln )
+               zhalin   = zbeta * sn(ji,jj,1) * rcs
+            ELSE
+               zrhos    = rhop(ji,jj,1) + rau0 * ( 1. - tmask(ji,jj,1) )
+               zthermal = ralpha / ( rcp * zrhos + epsln )
+               zhalin   = rbeta * sn(ji,jj,1) * rcs
+            ENDIF
+            ! Radiative surface buoyancy force
+            zBosol(ji,jj) = grav * zthermal * qsr(ji,jj)
+            ! Non radiative surface buoyancy force
+            zBo   (ji,jj) = grav * zthermal * ( qt(ji,jj) - qsr(ji,jj) ) -  grav * zhalin * emp(ji,jj)
+            ! Surface Temperature flux for non-local term
+            wt0(ji,jj) = - qt(ji,jj) * ro0cpr * tmask(ji,jj,1)
+            ! Surface salinity flux for non-local term
+            ws0(ji,jj) = - ( emp(ji,jj) * sn(ji,jj,1) * rcs ) * tmask(ji,jj,1)
+         ENDDO
+      ENDDO
+
+      zflageos = 0.5 + SIGN( 0.5, neos - 1. ) 
+      !  Compute surface buoyancy forcing, Monin Obukhov and Ekman depths  
+      !------------------------------------------------------------------    
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            !  Reference surface density = density at first T point level   
+            zrhos         = rhop(ji,jj,1) + zflageos * rau0 * ( 1. - tmask(ji,jj,1) )  
+            ! Friction velocity (zustar), at T-point : LMD94 eq. 2
+            ztx           = 0.5 * ( taux(ji,jj) + taux(ji - 1, jj    ) )
+            zty           = 0.5 * ( tauy(ji,jj) + tauy(ji    , jj - 1) )
+            ztau          = SQRT( ztx * ztx + zty * zty )
+            zustar(ji,jj) = SQRT( ztau / ( zrhos +  epsln ) )
+         ENDDO
+      ENDDO
+
+!CDIR NOVERRCHK  
+      !                                               ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! ===============
+         
+         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+         ! II Compute Boundary layer mixing coef. and diagnose the new boundary layer depth
+         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+         
+         ! Initialization
+         jkmax       = 0
+         zdept (:,:) = 0.
+         zdepw (:,:) = 0.
+         zriblk(:,:) = 0.
+         zmoek (:,:) = 0.
+         zvisc (:,:) = 0.
+         zdift (:,:) = 0.
+#if defined key_zdfddm
+         zdifs (:,:) = 0.
+#endif
+         zmask (:,:) = 0.
+         DO ji = fs_2, fs_jpim1
+            zria(ji ) = 0.
+            ! Maximum boundary layer depth
+            ikbot     = mbathy(ji,jj) - 1 ! ikbot is the last T point in the water
+            zhmax(ji) = fsdept(ji,jj,ikbot) - 0.001      
+            ! Compute Monin obukhov length scale at the surface and Ekman depth:
+            zbuofdep   = zBo(ji,jj) + zBosol(ji,jj) * ratt(1)
+            zekman(ji) = rcekman * zustar(ji,jj) / ( ABS( ff(ji,jj) ) + epsln )
+            zucube     = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj) 
+            zmoa(ji)   = zucube / ( vonk * ( zbuofdep + epsln ) )   
+#if defined key_cfg_1d
+            ! store the surface buoyancy forcing
+            zstabl        = 0.5 + SIGN( 0.5, zbuofdep )
+            buof(ji,jj,1) = zbuofdep * tmask(ji,jj,1)
+            ! store the moning-oboukov length scale at surface
+            zmob          = zstabl * zmoa(ji) + ( 1.0 - zstabl ) * fsdept(ji,jj,1)
+            mols(ji,jj,1) = MIN( zmob , zhmax(ji) ) * tmask(ji,jj,1)
+            ! store Ekman depth
+            zek           = zstabl * zekman(ji) + ( 1.0 - zstabl ) * fsdept(ji,jj,1)  
+            ekdp(ji,jj )  = MIN( zek , zhmax(ji) ) * tmask(ji,jj,1)  
+#endif 
+         END DO     
+         ! Compute the pipe
+         ! ---------------------
+         DO jk = 2, jpkm1
+            DO ji = fs_2, fs_jpim1
+               ! Compute bfsfc = Bo + radiative contribution down to hbf*depht
+               zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * ratt(jk)
+               ! Flag (zstabl  = 1) if positive forcing
+               zstabl   =  0.5 + SIGN(  0.5, zbuofdep)
+
+               !   Compute bulk richardson number zrib at depht 
+               !-------------------------------------------------------
+               !                           [Br - B(d)] * d         zrinum
+               !             Rib(z) = ----------------------- = -------------
+               !                       |Vr - V(d)|^2 + Vt(d)^2   zdVsq + zVtsq
+               !
+               ! First compute zt,zs,zu,zv = means in the surface layer < epsilon*depht  
+               ! Else surface values are taken at the first T level.
+               ! For stability, resolved vertical shear is computed with "before velocities".
+               zref = epsilon * fsdept(ji,jj,jk)
+#if defined key_kppcustom
+               ! zref = gdept(1)
+               zref = fsdept(ji,jj,1)
+               zt   = tn(ji,jj,1)
+               zs   = sn(ji,jj,1)
+               zrh  = rhop(ji,jj,1)
+               zu   = ( ub(ji,jj,1) + ub(ji - 1,jj    ,1) ) / MAX( 1. , umask(ji,jj,1) + umask(ji - 1,jj   ,1) )
+               zv   = ( vb(ji,jj,1) + vb(ji    ,jj - 1,1) ) / MAX( 1. , vmask(ji,jj,1) + vmask(ji   ,jj - 1,1) )
+#else
+               zt   = 0.
+               zs   = 0.
+               zu   = 0.
+               zv   = 0.
+               zrh  = 0.
+               ! vertically integration over the upper epsilon*gdept(jk) ; del () array is computed once in zdf_kpp_init
+               DO jm = 1, jpkm1
+                  zt   = zt  + del(jk,jm) * tn(ji,jj,jm)
+                  zs   = zs  + del(jk,jm) * sn(ji,jj,jm)
+                  zu   = zu  + 0.5 * del(jk,jm) &
+                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
+                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
+                  zv   = zv  + 0.5 * del(jk,jm) &
+                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
+                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
+                  zrh  = zrh + del(jk,jm) * rhop(ji,jj,jm)
+               END DO
+#endif
+               zsr = SQRT( ABS( sn(ji,jj,jk) ) )
+               ! depth
+               zh = fsdept(ji,jj,jk)
+               ! compute compression terms on density
+               ze  = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+               zbw = (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+               zb  = zbw + ze * zs
+               
+               zd  = -2.042967e-2
+               zc  =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+               zaw = ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+               za  = ( zd*zsr + zc ) *zs + zaw
+               
+               zb1 =   (-0.1909078*zt+7.390729 ) *zt-55.87545
+               za1 = ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+               zkw = ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+               zk0 = ( zb1*zsr + za1 )*zs + zkw
+               zcomp =   1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )
+               
+#if defined key_kppcustom
+               ! potential density of water(zrh = zt,zs at level jk):
+               zrhdr = zrh / zcomp
+#else
+               ! potential density of water(ztref,zsref at level jk):
+               ! compute volumic mass pure water at atm pressure
+               IF ( neos < 1 ) THEN
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     &       -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     &   -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4              
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1                 
+                  zrhdr = zrhop / zcomp
+               ELSE
+                  zrhdr = zrh / zcomp
+               ENDIF
+#endif
+               
+               ! potential density of ambiant water at level jk :
+               zrhd   = ( rhd(ji,jj,jk) * rau0 + rau0 )  
+               
+               ! And now the Rib number numerator .
+               zrinum = grav * ( zrhd - zrhdr ) / rau0
+               zrinum = zrinum * ( fsdept(ji,jj,jk) - zref ) * tmask(ji,jj,jk)
+           
+               ! Resolved shear contribution to Rib at depth T-point (zdVsq)
+               ztx    =   ( ub( ji , jj ,jk)   +  ub(ji - 1, jj ,jk) ) &
+                  &     / MAX( 1. , umask( ji , jj ,jk) + umask(ji - 1, jj ,jk) )   
+               zty    =   ( vb( ji , jj ,jk)   +  vb(ji  ,jj - 1,jk) ) &
+                  &     / MAX( 1., vmask( ji , jj ,jk) + vmask(ji  ,jj - 1,jk) ) 
+               
+               zdVsq  = ( zu - ztx ) * ( zu - ztx ) + ( zv - zty ) * ( zv - zty )
+               
+               ! Scalar turbulent velocity scale zws for hbl=gdept
+               zscale = zstabl + ( 1.0 - zstabl ) * epsilon
+               zehat  = vonk * zscale * fsdept(ji,jj,jk) * zbuofdep
+               zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)              
+               zeta   = zehat / ( zucube + epsln )
+               
+               IF( zehat > 0. ) THEN
+                  ! Stable case
+                  zws  = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
+               ELSE
+                  ! Unstable case
+#if defined key_kpplktb
+                  ! use lookup table
+                  zd     = zehat - dehatmin
+                  il     = INT( zd / dezehat )
+                  il     = MIN( il, nilktbm1 )
+                  il     = MAX( il, 1 )
+                  
+                  ud     = zustar(ji,jj) - ustmin
+                  jl     = INT( ud / deustar )
+                  jl     = MIN( jl, njlktbm1 )
+                  jl     = MAX( jl, 1 )
+                  
+                  zfrac  = zd / dezehat - FLOAT( il )  
+                  ufrac  = ud / deustar - FLOAT( jl )
+                  zwas   = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
+                  zwbs   = ( 1. - zfrac ) * wslktb(il,jl  ) + zfrac * wslktb(il+1,jl  )
+                  !
+                  zws    = ( 1. - ufrac ) * zwbs + ufrac * zwas
+#else
+                  ! use analytical functions:
+                  zcons  = 0.5 + SIGN( 0.5 , ( rzetas - zeta ) )
+                  zwcons = vonk * zustar(ji,jj) * ( ( ABS( rconas - rconcs * zeta ) )**pthird ) 
+                  zwsun  = vonk * zustar(ji,jj) * SQRT( ABS ( 1.0 - rconc2 * zeta ) )
+                  !
+                  zws    = zcons * zwcons +  ( 1.0 - zcons) * zwsun
+#endif
+               ENDIF
+               
+               ! Turbulent shear contribution to Rib (zVtsq) bv frequency at levels  ( ie T-point jk)
+               zrn2   = 0.5 * ( rn2(ji,jj,jk) + rn2(ji,jj,jk+1) )   
+               zbvzed = SQRT( ABS( zrn2 ) ) 
+               zVtsq  = fsdept(ji,jj,jk) * zws * zbvzed  * Vtc
+               
+               ! Finally, the bulk Richardson number at depth fsdept(i,j,k) 
+               zrib  = zrinum   / ( zdVsq + zVtsq + epsln )
+ 
+               ! Find subscripts around the boundary layer depth, build the pipe
+               ! ----------------------------------------------------------------
+
+               ! Flag (zflagri = 1) if zrib < Ricr  
+               zflagri = 0.5 + SIGN( 0.5, ( Ricr - zrib ) )
+               !  Flag (zflagh  = 1) if still within overall boundary layer
+               zflagh  = 0.5 + SIGN( 0.5, ( fsdept(ji,jj,1) - zdept(ji,2) ) )
+               
+               ! Ekman layer depth
+               zek     = zstabl * zekman(ji) + ( 1.0 - zstabl ) * zhmax(ji)
+               zflag   = 0.5 + SIGN( 0.5, ( zek - fsdept(ji,jj,jk-1) ) )
+               zek     = zflag * zek + ( 1.0 - zflag ) * zhmax(ji)
+               zflagek = 0.5 + SIGN( 0.5, ( zek - fsdept(ji,jj,jk) ) )
+               ! Flag (zflagmo = 1) if still within stable Monin-Obukhov and in water
+               zmob    = zucube / ( vonk * ( zbuofdep + epsln ) )  
+               ztemp   = zstabl * zmob + ( 1.0 - zstabl) * zhmax(ji)
+               ztemp   = MIN( ztemp , zhmax(ji) ) 
+               zflagmo = 0.5 + SIGN( 0.5, ( ztemp - fsdept(ji,jj,jk) ) )             
+
+               ! No limitation by Monin Obukhov or Ekman depths:
+!               zflagek = 1.0
+!               zflagmo = 0.5 + SIGN( 0.5, ( zhmax(ji) - fsdept(ji,jj,jk) ) )
+
+               ! Load  pipe via zflagkb  for later calculations
+               ! Flag (zflagkb = 1) if zflagh = 1 and (zflagri = 0 or zflagek = 0 or zflagmo = 0)
+               zflagkb = zflagh * ( 1.0 - ( zflagri * zflagek * zflagmo ) )
+
+               zmask(ji,jk) = zflagh
+               jkp2         = MIN( jk+2 , ikbot )
+               jkm1         = MAX( jk-1 , 2 )
+               jkmax        = MAX( jkmax, jk * INT( REAL( zflagh+epsln ) ) ) 
+
+               zdept(ji,1)  = zdept(ji,1) + zflagkb * fsdept(ji,jj,jk-1) 
+               zdept(ji,2)  = zdept(ji,2) + zflagkb * fsdept(ji,jj,jk  ) 
+               zdept(ji,3)  = zdept(ji,3) + zflagkb * fsdept(ji,jj,jk+1) 
+
+               zdepw(ji,1)  = zdepw(ji,1) + zflagkb * fsdepw(ji,jj,jk-1) 
+               zdepw(ji,2)  = zdepw(ji,2) + zflagkb * fsdepw(ji,jj,jk  ) 
+               zdepw(ji,3)  = zdepw(ji,3) + zflagkb * fsdepw(ji,jj,jk+1)
+               zdepw(ji,4)  = zdepw(ji,4) + zflagkb * fsdepw(ji,jj,jkp2)  
+
+               zriblk(ji,1) = zriblk(ji,1) + zflagkb * zria(ji)
+               zriblk(ji,2) = zriblk(ji,2) + zflagkb * zrib
+
+               zmoek (ji,0) = zmoek (ji,0) + zflagkb * zek
+               zmoek (ji,1) = zmoek (ji,1) + zflagkb * zmoa(ji)
+               zmoek (ji,2) = zmoek (ji,2) + zflagkb * ztemp  
+               ! Save Monin Obukhov depth
+               zmoa  (ji)   = zmob
+           
+               zvisc(ji,1) = zvisc(ji,1) + zflagkb * avmu(ji,jj,jkm1)
+               zvisc(ji,2) = zvisc(ji,2) + zflagkb * avmu(ji,jj,jk  )
+               zvisc(ji,3) = zvisc(ji,3) + zflagkb * avmu(ji,jj,jk+1)
+               zvisc(ji,4) = zvisc(ji,4) + zflagkb * avmu(ji,jj,jkp2)
+               
+               zdift(ji,1) = zdift(ji,1) + zflagkb * avt (ji,jj,jkm1)
+               zdift(ji,2) = zdift(ji,2) + zflagkb * avt (ji,jj,jk  )
+               zdift(ji,3) = zdift(ji,3) + zflagkb * avt (ji,jj,jk+1)
+               zdift(ji,4) = zdift(ji,4) + zflagkb * avt (ji,jj,jkp2)
+
+#if defined key_zdfddm
+               zdifs(ji,1) = zdifs(ji,1) + zflagkb * avs (ji,jj,jkm1)
+               zdifs(ji,2) = zdifs(ji,2) + zflagkb * avs (ji,jj,jk  )
+               zdifs(ji,3) = zdifs(ji,3) + zflagkb * avs (ji,jj,jk+1)
+               zdifs(ji,4) = zdifs(ji,4) + zflagkb * avs (ji,jj,jkp2)
+#endif               
+               ! Save the Richardson number 
+               zria  (ji)   = zrib  
+#if defined key_cfg_1d
+               ! store buoyancy length scale
+               buof(ji,jj,jk) = zbuofdep * tmask(ji,jj,jk) 
+               ! store Monin Obukhov
+               zmob           = zstabl * zmob + ( 1.0 - zstabl) * fsdept(ji,jj,1)
+               mols(ji,jj,jk) = MIN( zmob , zhmax(ji) ) * tmask(ji,jj,jk) 
+               ! Bulk Richardson number
+               rib(ji,jj,jk)  = zrib * tmask(ji,jj,jk)             
+#endif               
+            END DO
+         END DO
+         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+         ! III PROCESS THE PIPE
+         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+         
+         DO ji = fs_2, fs_jpim1 
+            
+            ! Find the boundary layer depth zhbl
+            ! ----------------------------------------
+            
+            ! Interpolate monin Obukhov and critical Ri mumber depths   
+            ztemp = zdept(ji,2) - zdept(ji,1)
+            zflag = ( Ricr - zriblk(ji,1) ) / ( zriblk(ji,2) - zriblk(ji,1)  + epsln )
+            zhrib = zdept(ji,1) + zflag * ztemp      
+
+            IF( zriblk(ji,2) < Ricr ) zhrib = zhmax(ji) 
+         
+            IF( zmoek(ji,2) < zdept(ji,2) ) THEN
+               IF ( zmoek(ji,1) < 0. ) THEN
+                  zmob = zdept(ji,2) - epsln
+               ELSE
+                  zmob = ztemp + zmoek(ji,1) - zmoek(ji,2)
+                  zmob = ( zmoek(ji,1) * zdept(ji,2) - zmoek(ji,2) * zdept(ji,1) ) / zmob
+                  zmob = MAX( zmob , zdept(ji,1) + epsln )                
+               ENDIF
+            ELSE           
+               zmob = zhmax(ji) 
+            ENDIF
+            ztemp   = MIN( zmob , zmoek(ji,0) )
+                         
+            ! Finally, the boundary layer depth, zhbl 
+            zhbl(ji) = MAX( fsdept(ji,jj,1) + epsln, MIN( zhrib , ztemp ) )
+            
+            ! Save hkpp for further diagnostics (optional)
+            hkpp(ji,jj) = zhbl(ji) * tmask(ji,jj,1) 
+          
+            ! Correct mask if zhbl < fsdepw(ji,jj,2) for no viscosity/diffusivity enhancement at fsdepw(ji,jj,2)
+            !     zflag = 1 if zhbl(ji) > fsdepw(ji,jj,2)
+            IF( zhbl(ji) < fsdepw(ji,jj,2) ) zmask(ji,2) = 0.
+          
+            
+            !  Velocity scales at depth zhbl
+            ! -----------------------------------
+            
+            !  Compute bouyancy forcing down to zhbl
+            ztemp    = -hbf * zhbl(ji)
+            zatt1    = 1.0 - ( rabs * EXP( ztemp / xsi1 ) + ( 1.0 - rabs ) * EXP( ztemp / xsi2 ) )
+            zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * zatt1
+            zstabl   = 0.5 + SIGN( 0.5 , zbuofdep ) 
+
+            zbuofdep = zbuofdep + zstabl * epsln
+
+            zscale = zstabl + ( 1.0 - zstabl ) * epsilon          
+            zehat  = vonk * zscale * zhbl(ji) * zbuofdep
+            zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)              
+            zeta   = zehat / ( zucube + epsln )
+            
+            IF( zehat > 0. ) THEN
+               ! Stable case
+               zws  = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
+               zwm  = zws
+            ELSE
+               ! Unstable case
+#if defined key_kpplktb
+               ! use lookup table
+               zd     = zehat - dehatmin
+               il     = INT( zd / dezehat )
+               il     = MIN( il, nilktbm1 )
+               il     = MAX( il, 1 )
+               
+               ud     = zustar(ji,jj) - ustmin
+               jl     = INT( ud / deustar )
+               jl     = MIN( jl, njlktbm1 )
+               jl     = MAX( jl, 1 )
+               
+               zfrac  = zd / dezehat - FLOAT( il )  
+               ufrac  = ud / deustar - FLOAT( jl )
+               zwas   = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
+               zwbs   = ( 1. - zfrac ) * wslktb(il,jl  ) + zfrac * wslktb(il+1,jl  )
+               zwam   = ( 1. - zfrac ) * wmlktb(il,jl+1) + zfrac * wmlktb(il+1,jl+1)
+               zwbm   = ( 1. - zfrac ) * wmlktb(il,jl  ) + zfrac * wmlktb(il+1,jl  )
+               !
+               zws    = ( 1. - ufrac ) * zwbs + ufrac * zwas
+               zwm    = ( 1. - ufrac ) * zwbm + ufrac * zwam
+#else
+               ! use analytical functions
+               zconm  = 0.5 + SIGN( 0.5, ( rzetam - zeta) )
+               zcons  = 0.5 + SIGN( 0.5, ( rzetas - zeta) )
+               
+               ! Momentum : zeta < rzetam (zconm = 1)
+               ! Scalars  : zeta < rzetas (zcons = 1) 
+               zwconm = zustar(ji,jj) * vonk * ( ( ABS( rconam - rconcm * zeta) )**pthird )
+               zwcons = zustar(ji,jj) * vonk * ( ( ABS( rconas - rconcs * zeta) )**pthird )
+               
+               ! Momentum : rzetam <= zeta < 0 (zconm = 0)
+               ! Scalars  : rzetas <= zeta < 0 (zcons = 0)	
+               zwmun  = SQRT( ABS( 1.0 - rconc2 * zeta ) )
+               zwsun  = vonk * zustar(ji,jj) * zwmun
+               zwmun  = vonk * zustar(ji,jj) * SQRT(zwmun)
+               !
+               zwm    = zconm * zwconm + ( 1.0 - zconm ) * zwmun
+               zws    = zcons * zwcons + ( 1.0 - zcons ) * zwsun
+               
+#endif
+            ENDIF
+            
+            
+            ! Viscosity, diffusivity values and derivatives at h
+            ! --------------------------------------------------------
+            
+            ! check between at which interfaces is located zhbl(ji)
+            ! ztemp = 1, zdepw(ji,2) < zhbl <  zdepw(ji,3)
+            ! ztemp = 0, zdepw(ji,1) < zhbl <  zdepw(ji,2)
+            ztemp  =  0.5 + SIGN( 0.5, ( zhbl(ji) - zdepw(ji,2) ) )  
+            zdep21 =   zdepw(ji,2) - zdepw(ji,1) + epsln
+            zdep32 =   zdepw(ji,3) - zdepw(ji,2) + epsln
+            zdep43 =   zdepw(ji,4) - zdepw(ji,3) + epsln  
+            
+            ! Compute R as in LMD94, eq D5b
+            zdelta =  ( zhbl(ji) - zdepw(ji,2) ) *         ztemp   / zdep32   &
+               &    + ( zhbl(ji) - zdepw(ji,1) ) * ( 1.0 - ztemp ) / zdep21 
+            
+            ! Compute the vertical derivative of viscosities (zdzh) at z=zhbl(ji)
+            zdzup  =  ( zvisc(ji,2) - zvisc(ji,3) ) *         ztemp   / zdep32 &
+               &    + ( zvisc(ji,1) - zvisc(ji,2) ) * ( 1.0 - ztemp ) / zdep21
+            
+            zdzdn  =  ( zvisc(ji,3) - zvisc(ji,4) ) *         ztemp   / zdep43 &
+               &    + ( zvisc(ji,2) - zvisc(ji,3) ) * ( 1.0 - ztemp ) / zdep32
+            
+            ! LMD94, eq D5b :          
+            zdzh   = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
+            zdzh   = MAX( zdzh , 0. )
+            
+            ! Compute viscosities (zvath) at z=zhbl(ji), LMD94 eq D5a
+            zvath  =          ztemp   * ( zvisc(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
+               &    + ( 1.0 - ztemp ) * ( zvisc(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
+            
+            ! Compute G (zgat1) and its derivative (zdat1) at z=hbl(ji), LMD94 eq 18
+            
+            ! Vertical derivative of velocity scale divided by velocity scale squared at z=hbl(ji) 
+            ! (non zero only in stable conditions)
+            zflag  =  -zstabl * rconc1 * zbuofdep / ( zucube * zustar(ji,jj) + epsln )
+            
+            ! G at its derivative at z=hbl:
+            zgat1  = zvath  / ( zhbl(ji) * ( zwm + epsln )  )
+            zdat1  = -zdzh  / ( zwm + epsln ) -  zflag * zvath / zhbl(ji)
+            
+            ! G coefficients, LMD94 eq 17
+            za2m(ji) = -2.0 + 3.0 * zgat1 - zdat1
+            za3m(ji) =  1.0 - 2.0 * zgat1 + zdat1
+
+            
+            ! Compute the vertical derivative of temperature diffusivities (zdzh) at z=zhbl(ji)
+            zdzup  =  ( zdift(ji,2) - zdift(ji,3) ) *         ztemp   / zdep32 &
+               &    + ( zdift(ji,1) - zdift(ji,2) ) * ( 1.0 - ztemp ) / zdep21
+            
+            zdzdn  =  ( zdift(ji,3) - zdift(ji,4) ) *         ztemp   / zdep43 &
+               &    + ( zdift(ji,2) - zdift(ji,3) ) * ( 1.0 - ztemp ) / zdep32
+            
+            ! LMD94, eq D5b :          
+            zdzh   = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
+            zdzh   = MAX( zdzh , 0. )
+            
+            
+            ! Compute diffusivities (zvath) at z=zhbl(ji), LMD94 eq D5a
+            zvath  =          ztemp   * ( zdift(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
+               &    + ( 1.0 - ztemp ) * ( zdift(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
+                        
+            ! G at its derivative at z=hbl:
+            zgat1  = zvath  / ( zhbl(ji) * ( zws + epsln )  )
+            zdat1  = -zdzh  / ( zws + epsln ) -  zflag * zvath / zhbl(ji)
+            
+            ! G coefficients, LMD94 eq 17
+            za2t(ji) = -2.0 + 3.0 * zgat1 - zdat1
+            za3t(ji) =  1.0 - 2.0 * zgat1 + zdat1
+
+#if defined key_zdfddm
+            ! Compute the vertical derivative of salinities diffusivities (zdzh) at z=zhbl(ji)
+            zdzup  =  ( zdifs(ji,2) - zdifs(ji,3) ) *         ztemp   / zdep32 &
+               &    + ( zdifs(ji,1) - zdifs(ji,2) ) * ( 1.0 - ztemp ) / zdep21
+            
+            zdzdn  =  ( zdifs(ji,3) - zdifs(ji,4) ) *         ztemp   / zdep43 &
+               &    + ( zdifs(ji,2) - zdifs(ji,3) ) * ( 1.0 - ztemp ) / zdep32
+            
+            ! LMD94, eq D5b :          
+            zdzh   = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
+            zdzh   = MAX( zdzh , 0. )           
+            
+            ! Compute diffusivities (zvath) at z=zhbl(ji), LMD94 eq D5a
+            zvath  =          ztemp   * ( zdifs(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
+               &    + ( 1.0 - ztemp ) * ( zdifs(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
+                        
+            ! G at its derivative at z=hbl:
+            zgat1  = zvath  / ( zhbl(ji) * ( zws + epsln )  )
+            zdat1  = -zdzh  / ( zws + epsln ) -  zflag * zvath / zhbl(ji)
+            
+            ! G coefficients, LMD94 eq 17
+            za2s(ji) = -2.0 + 3.0 * zgat1 - zdat1
+            za3s(ji) =  1.0 - 2.0 * zgat1 + zdat1
+#endif
+
+            !-------------------turn off interior matching here------
+            !          za2(ji,1) = -2.0
+            !          za3(ji,1) =  1.0
+            !          za2(ji,2) = -2.0
+            !          za3(ji,2) =  1.0
+            !--------------------------------------------------------
+            
+            !  Compute Enhanced Mixing Coefficients (LMD94,eq D6)
+            ! ---------------------------------------------------------------
+            
+            ! Delta 
+            zdelta  = ( zhbl(ji)  - zdept(ji,1) ) / ( zdept(ji,2) - zdept(ji,1) + epsln )
+            zdelta2 = zdelta * zdelta
+            
+            !  Mixing coefficients at first level above h (zdept(ji,1)) 
+            ! and at first interface in the pipe (zdepw(ji,2))
+            
+            ! At first T level above h (zdept(ji,1)) (always in the boundary layer)
+            zsig    = zdept(ji,1) / zhbl(ji)
+            ztemp   = zstabl * zsig  + ( 1.0 - zstabl ) * MIN( zsig , epsilon )
+            zehat   = vonk * ztemp * zhbl(ji) * zbuofdep
+            zeta    = zehat / ( zucube + epsln)
+            zwst    = vonk * zustar(ji,jj) / ( ABS( 1.0 + rconc1 * zeta ) + epsln)
+            zwm     = zstabl * zwst + ( 1.0 - zstabl ) * zwm
+            zws     = zstabl * zwst + ( 1.0 - zstabl ) * zws
+
+            zkm1m  = zhbl(ji) * zwm * zsig * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
+            zkm1t  = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
+#if defined key_zdfddm
+            zkm1s  = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
+#endif                        
+            ! At first W level in the pipe (zdepw(ji,2)) (not always in the boundary layer ):
+            zsig    = MIN( zdepw(ji,2) / zhbl(ji) , 1.0 )
+            ztemp   = zstabl * zsig + ( 1.0 - zstabl ) * MIN( zsig , epsilon )
+            zehat   = vonk * ztemp * zhbl(ji) * zbuofdep
+            zeta    = zehat / ( zucube + epsln )
+            zwst    = vonk * zustar(ji,jj) / ( ABS( 1.0 + rconc1 * zeta ) + epsln)
+            zws     = zstabl * zws + ( 1.0 - zstabl ) * zws
+            zwm     = zstabl * zws + ( 1.0 - zstabl ) * zwm
+
+            zkmpm(ji) = zhbl(ji) * zwm * zsig * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
+            zkmpt(ji) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
+#if defined key_zdfddm
+            zkmps(ji) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
+#endif  
+      
+            ! check if this point is in the boundary layer,else take interior viscosity/diffusivity:
+            zflag       = 0.5 + SIGN( 0.5, ( zhbl(ji) - zdepw(ji,2) ) )
+            zkmpm(ji) = zkmpm(ji) * zflag + ( 1.0 - zflag ) * zvisc(ji,2)
+            zkmpt(ji) = zkmpt(ji) * zflag + ( 1.0 - zflag ) * zdift(ji,2)
+#if defined key_zdfddm
+            zkmps(ji) = zkmps(ji) * zflag + ( 1.0 - zflag ) * zdifs(ji,2)
+#endif
+
+            ! Enhanced viscosity/diffusivity at zdepw(ji,2)
+            ztemp     = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1m + zdelta2 * zkmpm(ji)
+            zkmpm(ji) = ( 1.0 - zdelta ) * zvisc(ji,2) + zdelta * ztemp
+            ztemp     = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1t + zdelta2 * zkmpt(ji)
+            zkmpt(ji) = ( 1.0 - zdelta ) * zdift(ji,2) + zdelta * ztemp
+#if defined key_zdfddm
+            ztemp     = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1s + zdelta2 * zkmps(ji)
+            zkmps(ji) = ( 1.0 - zdelta ) * zdifs(ji,2) + zdelta * ztemp
+#endif            
+
+         END DO
+         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+         ! IV. Compute vertical eddy viscosity and diffusivity coefficients
+         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+         
+         DO jk  = 2, jkmax
+            
+            ! Compute turbulent velocity scales on the interfaces
+            ! --------------------------------------------------------
+            DO  ji = fs_2, fs_jpim1
+               zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * zatt1
+               zstabl   = 0.5 + SIGN( 0.5 , zbuofdep ) 
+               zbuofdep = zbuofdep + zstabl * epsln          
+               zsig    = fsdepw(ji,jj,jk) / zhbl(ji)
+               ztemp   = zstabl * zsig + ( 1. - zstabl ) * MIN( zsig , epsilon )
+               zehat   = vonk * ztemp * zhbl(ji) * zbuofdep
+               zucube  = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)
+               zeta    = zehat / ( zucube + epsln )
+
+               IF( zehat > 0. ) THEN
+                  ! Stable case
+                  zws  = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
+                  zwm  = zws
+               ELSE
+                  ! Unstable case
+#if defined key_kpplktb
+                  ! use lookup table
+                  zd     = zehat - dehatmin
+                  il     = INT( zd / dezehat )
+                  il     = MIN( il, nilktbm1 )
+                  il     = MAX( il, 1 )
+                  
+                  ud     = zustar(ji,jj) - ustmin
+                  jl     = INT( ud / deustar )
+                  jl     = MIN( jl, njlktbm1 )
+                  jl     = MAX( jl, 1 )
+                  
+                  zfrac  = zd / dezehat - FLOAT( il )  
+                  ufrac  = ud / deustar - FLOAT( jl )
+                  zwas   = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
+                  zwbs   = ( 1. - zfrac ) * wslktb(il,jl  ) + zfrac * wslktb(il+1,jl  )
+                  zwam   = ( 1. - zfrac ) * wmlktb(il,jl+1) + zfrac * wmlktb(il+1,jl+1)
+                  zwbm   = ( 1. - zfrac ) * wmlktb(il,jl  ) + zfrac * wmlktb(il+1,jl  )
+                  !
+                  zws    = ( 1. - ufrac ) * zwbs + ufrac * zwas
+                  zwm    = ( 1. - ufrac ) * zwbm + ufrac * zwam
+#else
+                  ! use analytical functions
+                  zconm  = 0.5 + SIGN( 0.5, ( rzetam - zeta) )
+                  zcons  = 0.5 + SIGN( 0.5, ( rzetas - zeta) )
+                  
+                  ! Momentum : zeta < rzetam (zconm = 1)
+                  ! Scalars  : zeta < rzetas (zcons = 1) 
+                  zwconm = zustar(ji,jj) * vonk * ( ( ABS( rconam - rconcm * zeta) )**pthird )
+                  zwcons = zustar(ji,jj) * vonk * ( ( ABS( rconas - rconcs * zeta) )**pthird )
+                  
+                  ! Momentum : rzetam <= zeta < 0 (zconm = 0)
+                  ! Scalars  : rzetas <= zeta < 0 (zcons = 0)	
+                  zwmun  = SQRT( ABS( 1.0 - rconc2 * zeta ) )
+                  zwsun  = vonk * zustar(ji,jj) * zwmun
+                  zwmun  = vonk * zustar(ji,jj) * SQRT(zwmun)
+                  !
+                  zwm    = zconm * zwconm + ( 1.0 - zconm ) * zwmun
+                  zws    = zcons * zwcons + ( 1.0 - zcons ) * zwsun
+                  
+#endif
+               ENDIF
+               
+               zblcm(ji,jk) = zhbl(ji) * zwm * zsig  * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
+               zblct(ji,jk) = zhbl(ji) * zws * zsig  * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
+#if defined key_zdfddm
+               zblcs(ji,jk) = zhbl(ji) * zws * zsig  * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
+#endif              
+               !  Compute Nonlocal transport term = ghats * <ws>o
+               ! ----------------------------------------------------
+               ghats(ji,jj,jk-1) = ( 1. - zstabl ) * rcg / ( zws * zhbl(ji) + epsln ) * tmask(ji,jj,jk)
+
+            END DO
+         END DO     
+         !  Combine interior and boundary layer coefficients and nonlocal term
+         ! -----------------------------------------------------------------------
+         DO jk = 2, jpkm1   
+            DO ji = fs_2, fs_jpim1
+               zflag = zmask(ji,jk) * zmask(ji,jk+1)
+               zviscos(ji,jj,jk) = ( 1.0 - zmask(ji,jk) )         * avmu (ji,jj,jk) & ! interior viscosities
+                  &              +                        zflag   * zblcm(ji,jk    ) & ! boundary layer viscosities
+                  &              + zmask(ji,jk) * ( 1.0 - zflag ) * zkmpm(ji       )   ! viscosity enhancement at W_level near zhbl
+               
+               zviscos(ji,jj,jk) = zviscos(ji,jj,jk) * tmask(ji,jj,jk)   
+
+            
+               zdiffut(ji,jj,jk) = ( 1.0 - zmask(ji,jk) )          * avt (ji,jj,jk) & ! interior diffusivities 
+                  &              +                        zflag   * zblct(ji,jk   ) & ! boundary layer diffusivities
+                  &              + zmask(ji,jk) * ( 1.0 - zflag ) * zkmpt(ji      )   ! diffusivity enhancement at W_level near zhbl
+                       
+               zdiffut(ji,jj,jk) = zdiffut(ji,jj,jk) * tmask(ji,jj,jk) 
+#if defined key_zdfddm
+               zdiffus(ji,jj,jk) = ( 1.0 - zmask(ji,jk) )          * avs (ji,jj,jk) & ! interior diffusivities 
+                  &              +                        zflag   * zblcs(ji,jk   ) & ! boundary layer diffusivities
+                  &              + zmask(ji,jk) * ( 1.0 - zflag ) * zkmps(ji      )   ! diffusivity enhancement at W_level near zhbl
+                       
+               zdiffus(ji,jj,jk) = zdiffus(ji,jj,jk) * tmask(ji,jj,jk) 
+#endif               
+               ! Non local flux in the boundary layer only
+               ghats(ji,jj,jk-1) = zmask(ji,jk) * ghats(ji,jj,jk-1)
+
+            ENDDO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Lateral boundary conditions on zvicos and zdiffus  (sign unchanged)
+      CALL lbc_lnk( zviscos(:,:,:), 'U', 1. )  ; CALL lbc_lnk( zdiffut(:,:,:), 'W', 1. )  
+#if defined key_zdfddm  
+      CALL lbc_lnk( zdiffus(:,:,:), 'W', 1. ) 
+#endif
+
+      SELECT CASE ( nave )
+         !
+         CASE ( 0 )             ! no viscosity and diffusivity smoothing
+
+            DO jk = 2, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     avmu(ji,jj,jk) = ( zviscos(ji,jj,jk) + zviscos(ji+1,jj,jk) ) &
+                        &  / MAX( 1., tmask(ji,jj,jk) + tmask (ji + 1,jj,jk) ) * umask(ji,jj,jk)
+                     
+                     avmv(ji,jj,jk) = ( zviscos(ji,jj,jk) + zviscos(ji,jj+1,jk) ) &
+                        &  / MAX( 1., tmask(ji,jj,jk) + tmask (ji,jj+1,jk) ) * vmask(ji,jj,jk)
+                     
+                     avt (ji,jj,jk) =  zdiffut(ji,jj,jk) * tmask(ji,jj,jk)  
+#if defined key_zdfddm     
+                     avs (ji,jj,jk) =  zdiffus(ji,jj,jk) * tmask(ji,jj,jk)  
+#endif
+                  END DO
+               END DO
+            END DO
+            
+         CASE ( 1 )                ! viscosity and diffusivity smoothing
+            !                      
+            !           ( 1/2  1  1/2 )              ( 1/2  1/2 )             ( 1/2  1  1/2 )
+            ! avt = 1/8 ( 1    2  1   )   avmu = 1/4 ( 1    1   )   avmv= 1/4 ( 1/2  1  1/2 )
+            !           ( 1/2  1  1/2 )              ( 1/2  1/2 )
+  
+            DO jk = 2, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+
+                     avmu(ji,jj,jk) = (      zviscos(ji  ,jj  ,jk) + zviscos(ji+1,jj  ,jk)   &
+                        &              +.5*( zviscos(ji  ,jj-1,jk) + zviscos(ji+1,jj-1,jk)   &
+                        &                   +zviscos(ji  ,jj+1,jk) + zviscos(ji+1,jj+1,jk) ) ) * eumean(ji,jj,jk)
+                     
+                     avmv(ji,jj,jk) = (      zviscos(ji  ,jj  ,jk) + zviscos(ji  ,jj+1,jk)   &
+                        &              +.5*( zviscos(ji-1,jj  ,jk) + zviscos(ji-1,jj+1,jk)   &
+                        &                   +zviscos(ji+1,jj  ,jk) + zviscos(ji+1,jj+1,jk) ) ) * evmean(ji,jj,jk)
+ 
+                     avt (ji,jj,jk) = ( .5*( zdiffut(ji-1,jj+1,jk) + zdiffut(ji-1,jj-1,jk)    &
+                        &                   +zdiffut(ji+1,jj+1,jk) + zdiffut(ji+1,jj-1,jk) )  &
+                        &              +1.*( zdiffut(ji-1,jj  ,jk) + zdiffut(ji  ,jj+1,jk)    &
+                        &                   +zdiffut(ji  ,jj-1,jk) + zdiffut(ji+1,jj  ,jk) )  &
+                        &              +2.*  zdiffut(ji  ,jj  ,jk)                          ) * etmean(ji,jj,jk)
+#if defined key_zdfddm   
+                     avs (ji,jj,jk) = ( .5*( zdiffus(ji-1,jj+1,jk) + zdiffus(ji-1,jj-1,jk)    &
+                        &                   +zdiffus(ji+1,jj+1,jk) + zdiffus(ji+1,jj-1,jk) )  &
+                        &              +1.*( zdiffus(ji-1,jj  ,jk) + zdiffus(ji  ,jj+1,jk)    &
+                        &                   +zdiffus(ji  ,jj-1,jk) + zdiffus(ji+1,jj  ,jk) )  &
+                        &              +2.*  zdiffus(ji  ,jj  ,jk)                          ) * etmean(ji,jj,jk)  
+#endif                
+                  END DO
+               END DO
+            END DO
+         
+         END SELECT
+
+         DO jk = 2, jpkm1                       ! vertical slab
+            !
+            !  Minimum value on the eddy diffusivity
+            ! ----------------------------------------
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avt(ji,jj,jk) = MAX( avt(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
+#if defined key_zdfddm  
+                  avs(ji,jj,jk) = MAX( avs(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
+#endif
+               END DO
+            END DO
+
+            !
+            ! Minimum value on the eddy viscosity
+            ! ----------------------------------------
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), avmb(jk) ) * umask(ji,jj,jk)
+                  avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), avmb(jk) ) * vmask(ji,jj,jk)
+               END DO
+            END DO
+            !
+         END DO
+
+         ! Lateral boundary conditions on avt  (sign unchanged)
+         CALL lbc_lnk( hkpp(:,:), 'T', 1. )
+
+         ! Lateral boundary conditions on avt  (sign unchanged)
+         CALL lbc_lnk( avt(:,:,:), 'W', 1. )
+#if defined key_zdfddm  
+         CALL lbc_lnk( avs(:,:,:), 'W', 1. )  
+#endif
+         ! Lateral boundary conditions (avmu,avmv) (U- and V- points, sign unchanged)
+         CALL lbc_lnk( avmu(:,:,:), 'U', 1. )   ;    CALL lbc_lnk( avmv(:,:,:), 'V', 1. )  
+ 
+         IF(ln_ctl) THEN
+#if defined key_zdfddm
+            CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp - t: ', tab3d_2=avs , clinfo2=' s: ', ovlap=1, kdim=jpk)
+#else
+            CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp - t: ', ovlap=1, kdim=jpk)
+#endif
+            CALL prt_ctl(tab3d_1=avmu, clinfo1=' kpp - u: ', mask1=umask,  &
+               &         tab3d_2=avmv, clinfo2=      ' v: ', mask2=vmask, ovlap=1, kdim=jpk)
+         ENDIF
+
+   END SUBROUTINE zdf_kpp
+
+
+   SUBROUTINE tra_kpp
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_kpp  ***
+      !!
+      !! ** Purpose :   compute and add to the tracer trend the non-local
+      !!      tracer flux
+      !!
+      !! ** Method  :   ???
+      !!
+      !! history :
+      !!     9.0  ! 05-11 (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce, ONLY :    ztrdt => ua,       & ! use ua as 3D workspace
+                         ztrds => va          ! use va as 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_kpp : KPP non-local tracer fluxes'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   '
+      ENDIF
+
+
+      ! Save ta and sa trends
+      IF( l_trdtra )   THEN
+         ztrdt(:,:,:) = ta(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:)
+      ENDIF
+
+      ! add non-local temperature and salinity flux ( in convective case only)
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ta(ji,jj,jk) =  ta(ji,jj,jk)                           &
+                  &         - ( ghats(ji,jj,jk  ) * avt(ji,jj,jk  )   &
+                  &           - ghats(ji,jj,jk+1) * avt(ji,jj,jk+1) ) * wt0(ji,jj) / fse3t(ji,jj,jk)
+               sa(ji,jj,jk) = sa(ji,jj,jk)                              &
+                  &         - ( ghats(ji,jj,jk  ) * fsavs(ji,jj,jk  )   &
+                  &           - ghats(ji,jj,jk+1) * fsavs(ji,jj,jk+1) ) * ws0(ji,jj) / fse3t(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! save the non-local tracer flux trends for diagnostic
+      IF( l_trdtra )   THEN
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+!!bug gm jpttdzdf ==> jpttkpp
+         CALL trd_mod(ztrdt, ztrds, jpt_trd_zdf, 'TRA', kt)
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' kpp  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      ENDIF
+
+   END SUBROUTINE tra_kpp
+
+
+   SUBROUTINE zdf_kpp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_kpp_init  ***
+      !!                     
+      !! ** Purpose :   Initialization of the vertical eddy diffivity and 
+      !!      viscosity when using a kpp turbulent closure scheme
+      !!
+      !! ** Method  :   Read the namkpp namelist and check the parameters
+      !!      called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namlist namkpp
+      !!
+      !!
+      !! history :
+      !!     8.1  ! 00-02 (J. Chanut) KPP Mixing
+      !!     9.0  ! 05-01 (C. Ethe) F90 : free form
+      !!----------------------------------------------------------------------
+      !! * local declarations
+
+      INTEGER    ::   &
+         ji, jj, jk             ! dummy loop indices
+      
+#if ! defined key_kppcustom
+      INTEGER    ::   &
+         jm                       ! dummy loop indices     
+      REAL(wp)   ::              & !!! tempory scalars
+         zref, zdist
+#endif
+
+#if defined key_kpplktb
+      REAL(wp)   ::              & !!! tempory scalars
+         zustar,    &
+         zucube, zustvk,         & 
+         zeta, zehat
+#endif
+      REAL(wp)   ::             & !!! tempory scalars
+         zhbf
+      LOGICAL ::                &
+         ll_kppcustom,          &  ! 1st ocean level taken as surface layer
+         ll_kpplktb                ! Lookup table for turbul. velocity scales 
+
+      NAMELIST/namkpp/ ln_kpprimix, difmiw, difsiw, Riinfty, difri, bvsqcon, difcon, nave, navb
+
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namtke : Turbulente Kinetic Energy
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namkpp )
+
+      ! Parameter control and print
+      ! ---------------------------
+      REWIND( numnam )
+      READ  ( numnam, namkpp )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_kpp_init : kpp turbulent closure scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namkpp : set tke mixing parameters'
+         WRITE(numout,*) '     Shear instability mixing                 ln_kpprimix  = ', ln_kpprimix
+         WRITE(numout,*) '     max. internal wave viscosity                   difmiw = ', difmiw
+         WRITE(numout,*) '     max. internal wave diffusivity                 difsiw = ', difsiw
+         WRITE(numout,*) '     Richardson Number limit for shear instability Riinfty = ', Riinfty
+         WRITE(numout,*) '     max. shear mixing at Rig = 0                  difri   = ', difri
+         WRITE(numout,*) '     Brunt-Vaisala squared for max. convection     bvsqcon = ', bvsqcon
+         WRITE(numout,*) '     max. mix. in interior convec.                 difcon  = ', difcon
+         WRITE(numout,*) '     horizontal average flag                        nave   = ', nave
+         WRITE(numout,*) '     constant background or profile                 navb   = ', navb
+      ENDIF
+
+      ll_kppcustom = .FALSE.
+      ll_kpplktb   = .FALSE.
+
+#if defined key_kppcustom
+      ll_kppcustom = .TRUE.
+#endif
+#if defined key_kpplktb
+      ll_kpplktb   = .TRUE.
+#endif
+      IF(lwp) THEN
+         WRITE(numout,*) '     Lookup table for turbul. velocity scales ll_kpplktb   = ', ll_kpplktb
+         WRITE(numout,*) '     1st ocean level taken as surface layer   ll_kppcustom = ', ll_kppcustom
+         WRITE(numout,*) ' '
+      ENDIF
+      
+      IF( lk_zdfddm) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '    Double diffusion mixing on temperature and salinity '
+            WRITE(numout,*) '    CAUTION : done in routine zdfkpp, not in routine zdfddm '
+            WRITE(numout,*) ' '
+         ENDIF
+      ENDIF
+      
+         
+
+      !set constants not in namelist
+      !-----------------------------
+      Vtc  = rconcv * SQRT( 0.2 / ( rconcs * epsilon ) ) / ( vonk * vonk * Ricr )
+      rcg  = rcstar * vonk * ( rconcs * vonk * epsilon )**pthird
+
+      IF(lwp) THEN
+         WRITE(numout,*) '     Constant value for unreso. turbul. velocity shear Vtc = ', Vtc
+         WRITE(numout,*) '     Non-dimensional coef. for nonlocal transport      rcg = ', rcg
+         WRITE(numout,*) ' '
+       ENDIF
+
+      ! ratt is the attenuation coefficient for solar flux
+      ! Should be different is s_coordinate
+      DO jk = 1, jpk
+         zhbf     = - fsdept(1,1,jk) * hbf
+         ratt(jk) = 1.0 - ( rabs * EXP( zhbf / xsi1 ) + ( 1.0 - rabs ) * EXP( zhbf / xsi2 ) )        
+      ENDDO
+
+      ! Horizontal average : initialization of weighting arrays 
+      ! -------------------
+      
+      SELECT CASE ( nave )
+
+      CASE ( 0 )                ! no horizontal average
+         IF(lwp) WRITE(numout,*) '          no horizontal average on avt, avmu, avmv'
+         IF(lwp) WRITE(numout,*) '          only in very high horizontal resolution !'
+         ! weighting mean arrays etmean, eumean and evmean
+         !           ( 1  1 )                                          ( 1 )
+         ! avt = 1/4 ( 1  1 )     avmu = 1/2 ( 1  1 )       avmv=  1/2 ( 1 )
+         !                          
+         etmean(:,:,:) = 0.e0
+         eumean(:,:,:) = 0.e0
+         evmean(:,:,:) = 0.e0
+         
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1   ! vector opt.
+                  etmean(ji,jj,jk) = tmask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
+                  &            + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+                  
+                  eumean(ji,jj,jk) = umask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  tmask(ji,jj,jk) + tmask(ji+1,jj  ,jk)  )
+
+                  evmean(ji,jj,jk) = vmask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  tmask(ji,jj,jk) + tmask(ji  ,jj+1,jk)  )
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )                ! horizontal average 
+         IF(lwp) WRITE(numout,*) '          horizontal average on avt, avmu, avmv'
+         ! weighting mean arrays etmean, eumean and evmean
+         !           ( 1/2  1  1/2 )              ( 1/2  1/2 )             ( 1/2  1  1/2 )
+         ! avt = 1/8 ( 1    2  1   )   avmu = 1/4 ( 1    1   )   avmv= 1/4 ( 1/2  1  1/2 )
+         !           ( 1/2  1  1/2 )              ( 1/2  1/2 )
+         etmean(:,:,:) = 0.e0
+         eumean(:,:,:) = 0.e0
+         evmean(:,:,:) = 0.e0
+         
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  etmean(ji,jj,jk) = tmask(ji, jj,jk)                           &
+                     & / MAX( 1., 2.* tmask(ji,jj,jk)                           &
+                     &      +.5 * ( tmask(ji-1,jj+1,jk) + tmask(ji-1,jj-1,jk)   &
+                     &             +tmask(ji+1,jj+1,jk) + tmask(ji+1,jj-1,jk) ) &
+                     &      +1. * ( tmask(ji-1,jj  ,jk) + tmask(ji  ,jj+1,jk)   &
+                     &             +tmask(ji  ,jj-1,jk) + tmask(ji+1,jj  ,jk) ) )
+                  
+                  eumean(ji,jj,jk) = umask(ji,jj,jk)                        &
+                     &  / MAX( 1.,   tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk)   &
+                     &       +.5 * ( tmask(ji,jj-1,jk) + tmask(ji+1,jj-1,jk)   &
+                     &              +tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) )  )
+                  
+                  evmean(ji,jj,jk) = vmask(ji,jj,jk)                        &
+                     &  / MAX( 1.,   tmask(ji  ,jj,jk) + tmask(ji  ,jj+1,jk)   &
+                     &       +.5 * ( tmask(ji-1,jj,jk) + tmask(ji-1,jj+1,jk)   &
+                     &              +tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk) )  )
+               END DO
+            END DO
+         END DO
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nave = ', nave
+         CALL ctl_opa( ctmp1 )
+
+      END SELECT
+
+
+ 
+      ! Background eddy viscosity and diffusivity profil
+      ! ------------------------------------------------
+      IF( navb == 0 ) THEN
+         !   Define avmb, avtb from namelist parameter
+         avmb(:) = avm0
+         avtb(:) = avt0
+      ELSE
+         !   Background profile of avt (fit a theoretical/observational profile (Krauss 1990) 
+         avmb(:) = avm0
+         avtb(:) = 1.e-5 + 2.8e-8 * gdepw(:)   ! m2/s
+      ENDIF
+
+      !   Increase the background in the surface layers
+!!      avmb(1) = 1. * avmb(1)      ;      avtb(1) = 1. * avtb(1)
+!!      avmb(2) = 1. * avmb(2)      ;      avtb(2) = 1. * avtb(2)
+!!      avmb(3) = 1. * avmb(3)      ;      avtb(3) = 1. * avtb(3)
+!!      avmb(4) = 1. * avmb(4)      ;      avtb(4) = 1. * avtb(4)
+
+
+      ! Initialization of vertical eddy coef. to the background value
+      ! -------------------------------------------------------------
+      DO jk = 1, jpk
+         avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
+         avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
+         avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
+      END DO
+
+      ! zero the surface flux for non local term and kpp mixed layer depth
+      ! ------------------------------------------------------------------
+      ghats(:,:,:) = 0.
+      wt0  (:,:  ) = 0.
+      ws0  (:,:  ) = 0.
+      hkpp (:,:  ) = 0. ! just a diagnostic (not essential)
+
+#if ! defined key_kppcustom
+      ! compute arrays (del, wz) for reference mean values 
+      ! (increase speed for vectorization key_kppcustom not defined)
+      del(1:jpk, 1:jpk) = 0.
+      DO jk = 1, jpk
+         zref = epsilon * fsdept(1,1,jk)    
+         DO jm = 1 , jpk
+            zdist = zref - fsdepw(1,1,jm)   
+            IF( zdist > 0.  ) THEN
+               del(jk,jm) = MIN( zdist, fse3t(1,1,jm) ) / zref   
+            ELSE
+               del(jk,jm) = 0.
+            ENDIF
+         ENDDO
+      ENDDO
+#endif
+
+#if defined key_kpplktb
+      ! build lookup table for turbulent velocity scales
+      dezehat = ( dehatmax - dehatmin ) / nilktbm1
+      deustar = ( ustmax   - ustmin   ) / njlktbm1
+ 
+      DO jj = 1, njlktb
+         zustar = ( jj - 1) * deustar + ustmin
+         zustvk = vonk * zustar 
+         zucube = zustar * zustar * zustar 
+         DO ji = 1 , nilktb
+            zehat = ( ji - 1 ) * dezehat + dehatmin
+            zeta   = zehat / ( zucube + epsln )
+            IF( zehat >= 0 ) THEN             ! Stable case
+               wmlktb(ji,jj) = zustvk / ABS( 1.0 + rconc1 * zeta + epsln )                        
+               wslktb(ji,jj) = wmlktb(ji,jj)
+            ELSE                                ! Unstable case 
+               IF( zeta > rzetam ) THEN
+                  wmlktb(ji,jj) = zustvk * ABS( 1.0    - rconc2 * zeta )**pfourth
+               ELSE
+                  wmlktb(ji,jj) = zustvk * ABS( rconam - rconcm * zeta )**pthird
+               ENDIF
+               
+               IF( zeta > rzetas ) THEN
+                  wslktb(ji,jj) = zustvk * SQRT( ABS( 1.0 - rconc2 * zeta ) )
+               ELSE
+                  wslktb(ji,jj) = zustvk * ABS( rconas - rconcs * zeta )**pthird
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+#endif
+   END SUBROUTINE zdf_kpp_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        NO KPP scheme
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfkpp = .FALSE.   !: KPP flag
+CONTAINS
+   SUBROUTINE zdf_kpp( kt )          ! Empty routine
+      WRITE(*,*) 'zdf_kpp: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_kpp
+   SUBROUTINE tra_kpp( kt )          ! Empty routine
+      WRITE(*,*) 'tra_kpp: You should not have seen this print! error?', kt
+   END SUBROUTINE tra_kpp
+#endif
+
+   !!======================================================================
+END MODULE zdfkpp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfmxl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 4536)
@@ -0,0 +1,242 @@
+MODULE zdfmxl
+   !!======================================================================
+   !!                       ***  MODULE  zdfmxl  ***
+   !! Ocean physics: mixed layer depth 
+   !!======================================================================
+   !! History :
+   !!   9.0  !  03-08  (G. Madec)  OpenMP/autotasking optimization
+   !!----------------------------------------------------------------------
+   !!   zdf_mxl      : Compute the turbocline and mixed layer depths.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_mxl           ! called by step.F90
+
+   !! * Shared module variables
+   INTEGER, PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      nmln                  !: number of level in the mixed layer
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &   !:
+      hmld ,             &  !: mixing layer depth (turbocline) (m)
+      hmlp ,             &  !: mixed layer depth  (rho=rho0+zdcrit) (m)
+      hmlpt                 !: mixed layer depth at t-points (m)
+
+   !! * module variables
+   REAL(wp) ::   &
+      avt_c = 5.e-4_wp,  &  ! Kz criterion for the turbocline depth
+      rho_c = 0.01_wp       ! density criterion for mixed layer depth
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_mpp_omp
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_omp'                                   j-k-i loop (j-slab)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zdf_mxl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zdfmxl  ***
+      !!                   
+      !! ** Purpose :   Compute the turbocline depth and the mixed layer depth
+      !!      with a density criteria.
+      !!
+      !! ** Method  :   The turbocline depth is the depth at which the vertical 
+      !!      eddy diffusivity coefficient (resulting from the vertical physics
+      !!      alone, not the isopycnal part, see trazdf.F) fall below a given
+      !!      value defined locally (avt_c here taken equal to 5 cm/s2)
+      !!
+      !! ** Action  :
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   ik             ! temporary integer
+      INTEGER, DIMENSION(jpi,jpj) ::   &
+         imld                     ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'zdf_mxl : mixed layer depth, j-k-i loops'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+      !                                                ! ===============
+      DO jj = 1, jpj                                   !  Vertical slab
+         !                                             ! ===============
+
+         ! 1. Turbocline depth
+         ! -------------------
+         ! last w-level at which avt<avt_c (starting from the bottom jk=jpk)
+         ! (since avt(.,.,jpk)=0, we have jpk=< imld =< 2 )
+         DO jk = jpk, 2, -1
+            DO ji = 1, jpi
+               IF( avt(ji,jj,jk) < avt_c ) imld(ji,jj) = jk 
+            END DO
+         END DO
+
+         ! Turbocline depth and sub-turbocline temperature
+         DO ji = 1, jpi
+            ik = imld(ji,jj)
+            hmld (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+         END DO
+
+!!gm idea
+!!   
+!!gm     DO jk = jpk, 2, -1
+!!gm        DO ji = 1, jpi
+!!gm           IF( avt(ji,jj,jk) < avt_c ) hmld(ji,jj) = fsdepw(ji,jj,jk) * tmask(ji,jj,1)
+!!gm        END DO
+!!gm     END DO
+!!gm
+
+         ! 2. Mixed layer depth
+         ! --------------------
+         ! Initialization to the number of w ocean point mbathy
+         nmln(:,jj) = mbathy(:,jj)
+
+         ! Last w-level at which rhop>=rho surf+rho_c (starting from jpk-1)
+         ! (rhop defined at t-point, thus jk-1 for w-level just above)
+         DO jk = jpkm1, 2, -1
+            DO ji = 1, jpi
+               IF( rhop(ji,jj,jk) > rhop(ji,jj,1) + rho_c )   nmln(ji,jj) = jk
+            END DO
+         END DO
+
+         ! Mixed layer depth
+         DO ji = 1, jpi
+            ik = nmln(ji,jj)
+            hmlp (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+            hmlpt(ji,jj) = fsdept(ji,jj,ik-1)
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmld, clinfo2=' hmld : ', ovlap=1 )
+
+   END SUBROUTINE zdf_mxl
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                         k-j-i loop
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE zdf_mxl( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdfmxl  ***
+      !!                   
+      !! ** Purpose :   Compute the turbocline depth and the mixed layer depth
+      !!      with density criteria.
+      !!
+      !! ** Method  :   The turbocline depth is the depth at which the vertical
+      !!      eddy diffusivity coefficient (resulting from the vertical physics
+      !!      alone, not the isopycnal part, see trazdf.F) fall below a given
+      !!      value defined locally (avt_c here taken equal to 5 cm/s2)
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        !  94-11  (M. Imbard)  Original code
+      !!   8.0  !  96-01  (E. Guilyardi)  sub mixed layer temp.
+      !!   8.1  !  97-07  (G. Madec)  optimization
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk     ! dummy loop indices
+      INTEGER ::   ik             ! temporary integer
+      INTEGER, DIMENSION(jpi,jpj) ::   &
+         imld                     ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'zdf_mxl : mixed layer depth'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+
+      ! 1. Turbocline depth
+      ! -------------------
+      ! last w-level at which avt<avt_c (starting from the bottom jk=jpk)
+      ! (since avt(.,.,jpk)=0, we have jpk=< imld =< 2 )
+      DO jk = jpk, 2, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( avt(ji,jj,jk) < avt_c ) imld(ji,jj) = jk 
+            END DO
+         END DO
+      END DO
+
+      ! Turbocline depth and sub-turbocline temperature
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ik = imld(ji,jj)
+            hmld (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+         END DO
+      END DO
+
+!!gm idea
+!!   
+!!gm  DO jk = jpk, 2, -1
+!!gm     DO jj = 1, jpj
+!!gm        DO ji = 1, jpi
+!!gm           IF( avt(ji,jj,jk) < avt_c ) hmld(ji,jj) = fsdepw(ji,jj,jk) * tmask(ji,jj,1)
+!!gm        END DO
+!!gm     END DO
+!!gm  END DO
+!!gm
+
+      ! 2. Mixed layer depth
+      ! --------------------
+      ! Initialization to the number of w ocean point mbathy
+      nmln(:,:) = mbathy(:,:)
+
+      ! Last w-level at which rhop>=rho surf+rho_c (starting from jpk-1)
+      ! (rhop defined at t-point, thus jk-1 for w-level just above)
+      DO jk = jpkm1, 2, -1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( rhop(ji,jj,jk) > rhop(ji,jj,1) + rho_c )   nmln(ji,jj) = jk
+            END DO
+         END DO
+      END DO
+
+      ! Mixed layer depth
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ik = nmln(ji,jj)
+            hmlp (ji,jj) = fsdepw(ji,jj,ik) * tmask(ji,jj,1)
+            hmlpt(ji,jj) = fsdept(ji,jj,ik-1)
+         END DO
+      END DO
+
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmld, clinfo2=' hmld : ', ovlap=1 )
+
+   END SUBROUTINE zdf_mxl
+#endif
+
+   !!======================================================================
+END MODULE zdfmxl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 4536)
@@ -0,0 +1,264 @@
+MODULE zdfric
+   !!======================================================================
+   !!                       ***  MODULE  zdfric  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the local
+   !!                 Richardson number dependent formulation
+   !!======================================================================
+#if defined key_zdfric   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdfric'                                             Kz = f(Ri)
+   !!----------------------------------------------------------------------
+   !!   zdf_ric      : update momentum and tracer Kz from the Richardson
+   !!                  number computation
+   !!   zdf_ric_init : initialization, namelist read, & parameters control
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics
+!  USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_ric   ! called by step.F90
+
+   !! * Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfric = .TRUE.    !: Richardson vertical mixing flag
+
+   !! * Module variables
+   INTEGER ::               & !!! namric   richardson number dependent Kz
+      nric  = 2                ! coefficient of the parameterization
+   REAL(wp) ::              & !!! namric   richardson number dependent Kz
+      avmri = 100.e-4_wp ,  &  ! maximum value of the vertical eddy viscosity
+      alp   =   5._wp          ! coefficient of the parameterization
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      tmric                    ! coef. for the horizontal mean at t-point
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zdf_ric( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdfric  ***
+      !!                    
+      !! ** Purpose :   Compute the before eddy viscosity and diffusivity as
+      !!      a function of the local richardson number.
+      !!
+      !! ** Method  :   Local richardson number dependent formulation of the 
+      !!      vertical eddy viscosity and diffusivity coefficients. the eddy
+      !!      coefficients are given by:
+      !!              avm = avm0 + avmb
+      !!              avt = avm0 / (1 + alp*ri)
+      !!      with    ri  = N^2 / dz(u)**2
+      !!                  = e3w**2 * rn2/[ mi( dk(ub) )+mj( dk(vb) ) ]
+      !!              avm0= avmri / (1 + alp*ri)**nric
+      !!      Where ri is the before local Richardson number, avmri the maximum
+      !!      value reaches by the vertical eddy coefficients, avmb and avtb
+      !!      the background (or minimum) values of these coefficients for
+      !!      momemtum and tracers, and alp, nric are adjustable parameters.
+      !!      typical values used are : avm0=1.e-2 m2/s, avmb=1.e-6 m2/s
+      !!      avtb=1.e-7 m2/s, alp=5. and nric=2.
+      !!      this formulation needs ri>=0 : ri is set to zero if dz(rau)<0.
+      !!      a numerical threshold is impose on the vertical shear (1.e-20)
+      !!        N.B. the mask are required for implicit scheme, and surface
+      !!      and bottom value already set in inimix.F
+      !!
+      !! References :
+      !!      pacanowski & philander 1981, j. phys. oceanogr., 1441-1451.
+      !! History :
+      !!        !  87-09  (P. Andrich)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  96-01  (G. Madec)  complet rewriting of multitasking
+      !!                                  suppression of common work arrays
+      !!        !  97-06 (G. Madec)  complete rewriting of zdfmix
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step indexocean time step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   &
+         zcoef, zdku, zdkv, zri, z05alp     ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx ! temporary workspace
+
+      IF( kt == nit000  ) CALL zdf_ric_init            ! Initialization (first time-step only)
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Richardson number (put in zwx(ji,jj))
+         ! -----------------
+         ! minimum value set to zero
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zcoef = 0.5 / fse3w(ji,jj,jk)
+               ! shear of horizontal velocity
+               zdku = zcoef * (  ub(ji-1,jj,jk-1) + ub(ji,jj,jk-1)   &
+                                -ub(ji-1,jj,jk  ) - ub(ji,jj,jk  )  )
+               zdkv = zcoef * (  vb(ji,jj-1,jk-1) + vb(ji,jj,jk-1)   &
+                                -vb(ji,jj-1,jk  ) - vb(ji,jj,jk  )  )
+               ! richardson number (minimum value set to zero)
+               zri = rn2(ji,jj,jk) / ( zdku*zdku + zdkv*zdkv + 1.e-20 )
+               zwx(ji,jj) = MAX( zri, 0.e0 )
+            END DO
+         END DO
+
+         ! Boundary condition on zwx   (sign unchanged)
+         CALL lbc_lnk( zwx, 'W', 1. )
+
+
+         ! Vertical eddy viscosity and diffusivity coefficients
+         ! -------------------------------------------------------
+         ! Eddy viscosity coefficients
+         z05alp = 0.5 * alp
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               avmu(ji,jj,jk) = umask(ji,jj,jk)   &
+                              * avmri / ( 1. + z05alp*( zwx(ji+1,jj)+zwx(ji,jj) ) )**nric
+               avmv(ji,jj,jk) = vmask(ji,jj,jk)   &
+                              * avmri / ( 1. + z05alp*( zwx(ji,jj+1)+zwx(ji,jj) ) )**nric
+            END DO
+         END DO
+
+         ! Eddy diffusivity coefficients
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               avt(ji,jj,jk) = tmric(ji,jj,jk) / ( 1. + alp * zwx(ji,jj) )   &
+                             * (  avmu(ji,jj,jk) + avmu(ji-1, jj ,jk)        &
+                                + avmv(ji,jj,jk) + avmv( ji ,jj-1,jk)  )     &
+                             + avtb(jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+
+         ! Add the background coefficient on eddy viscosity
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               avmu(ji,jj,jk) = avmu(ji,jj,jk) + avmb(jk) * umask(ji,jj,jk)
+               avmv(ji,jj,jk) = avmv(ji,jj,jk) + avmb(jk) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Boundary conditions on (avt,avmu,avmv)   (unchanged sign)
+      ! -----------------------===============
+      CALL lbc_lnk( avt , 'W', 1. )
+      CALL lbc_lnk( avmu, 'U', 1. )
+      CALL lbc_lnk( avmv, 'V', 1. )
+
+   END SUBROUTINE zdf_ric
+
+
+   SUBROUTINE zdf_ric_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdfbfr_init  ***
+      !!                    
+      !! ** Purpose :   Initialization of the vertical eddy diffusivity and
+      !!      viscosity coef. for the Richardson number dependent formulation.
+      !!
+      !! ** Method  :   Read the namric namelist and check the parameter values
+      !!
+      !! ** input   :   Namelist namric
+      !!
+      !! ** Action  :   increase by 1 the nstop flag is setting problem encounter
+      !!
+      !! history :
+      !!  8.5  !  02-06  (G. Madec)  original code
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER :: ji, jj, jk        ! dummy loop indices
+
+      NAMELIST/namric/ avmri, alp, nric
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namric : richardson number dependent Kz
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namric )
+
+
+      ! Parameter control and print
+      ! ---------------------------
+      ! Control print
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'zdf_ric : Ri depend vertical mixing scheme'
+      IF(lwp) WRITE(numout,*) '======='
+      IF(lwp) WRITE(numout,*) '          Namelist namric : set Kz(Ri) parameters'
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '             maximum vertical viscosity     avmri  = ', avmri
+         WRITE(numout,*) '             coefficient                    alp    = ', alp
+         WRITE(numout,*) '             coefficient                    nric   = ', nric
+         WRITE(numout,*)
+      ENDIF
+
+
+      ! Work arrays for Ri number formulation
+      ! -------------------------------------
+
+      ! background eddy viscosity and diffusivity profiles
+      avmb(:) = avm0
+      avtb(:) = avt0
+
+      ! background profile of avm (fit the theoretical/observational
+      !     profile shown by Krauss (1990) and avt
+!!!   avtb(:) = 1.e-5 + 2.8e-8 * gdepw(:) ! m2/s
+
+      ! Increase the background in the surface layers
+      avmb(1) = 10.  * avmb(1)      ;      avtb(1) = 10.  * avtb(1)
+      avmb(2) = 10.  * avmb(2)      ;      avtb(2) = 10.  * avtb(2)
+      avmb(3) =  5.  * avmb(3)      ;      avtb(3) =  5.  * avtb(3)
+      avmb(4) =  2.5 * avmb(4)      ;      avtb(4) =  2.5 * avtb(4)
+
+      ! weighting mean array tmric for 4 T-points which accounts for coastal boundary conditions.
+      DO jk = 1, jpk
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               tmric(ji,jj,jk) =  tmask(ji,jj,jk)                                  &
+                               / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
+                                         + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+            END DO
+         END DO
+      END DO
+
+      tmric(:,1,:) = 0.e0
+
+      ! Initialization of vertical eddy coef. to the background value
+      DO jk = 1, jpk
+         avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
+         avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
+         avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
+      END DO
+
+   END SUBROUTINE zdf_ric_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :              NO Richardson dependent vertical mixing
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfric = .FALSE.   !: Richardson mixing flag
+CONTAINS
+   SUBROUTINE zdf_ric( kt )        ! Dummy routine
+      WRITE(*,*) 'zdf_ric: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_ric
+#endif
+
+   !!======================================================================
+END MODULE zdfric
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 4536)
@@ -0,0 +1,834 @@
+MODULE zdftke
+   !!======================================================================
+   !!                       ***  MODULE  zdftke  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the tke 
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !! History :   6.0  !  91-03  (b. blanke)  Original code
+   !!             7.0  !  91-11  (G. Madec)   bug fix
+   !!             7.1  !  92-10  (G. Madec)   new mixing length and eav
+   !!             7.2  !  93-03  (M. Guyon)   symetrical conditions
+   !!             7.3  !  94-08  (G. Madec, M. Imbard)   npdl flag
+   !!             7.5  !  96-01  (G. Madec)   s-coordinates
+   !!             8.0  !  97-07  (G. Madec)   lbc
+   !!             8.1  !  99-01  (E. Stretta) new option for the mixing length
+   !!             8.5  !  02-06  (G. Madec) add zdf_tke_init routine
+   !!             8.5  !  02-08  (G. Madec)  ri_c and Free form, F90
+   !!             9.0  !  04-10  (C. Ethe )  1D configuration
+   !!             9.0  !  02-08  (G. Madec)  autotasking optimization
+   !!             9.0  !  06-07  (S. Masson)  distributed restart using iom
+   !!----------------------------------------------------------------------
+#if defined key_zdftke   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdftke'                                   TKE vertical physics
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   zdf_tke      : update momentum and tracer Kz from a tke scheme
+   !!   zdf_tke_init : initialization, namelist read, and parameters control
+   !!   tke_rst      : read/write tke restart in ocean restart file
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE taumod          ! surface stress
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_tke        ! routine called in step module
+   PUBLIC   zdf_tke_init   ! routine also called in zdftke_jki module
+   PUBLIC   tke_rst        ! routine also called in zdftke_jki module
+
+   LOGICAL , PUBLIC, PARAMETER              ::   lk_zdftke = .TRUE.  !: TKE vertical mixing flag
+   REAL(wp), PUBLIC                         ::   eboost              !: multiplicative coeff of the shear product.
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   en                  !: now turbulent kinetic energy
+# if defined key_vectopt_memory
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   etmean              !: coefficient used for horizontal smoothing
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   eumean, evmean      !: at t-, u- and v-points
+# endif
+
+   !! * Namelist (namtke)
+   LOGICAL , PUBLIC ::   ln_rstke = .FALSE.         !: =T restart with tke from a run without tke with 
+     !                                              !  a none zero initial value for en
+   INTEGER , PUBLIC ::   nitke = 50 ,            &  !: number of restart iterative loops
+      &                  nmxl  =  2 ,            &  !: = 0/1/2/3 flag for the type of mixing length used
+      &                  npdl  =  1 ,            &  !: = 0/1/2 flag on prandtl number on vert. eddy coeff.
+      &                  nave  =  1 ,            &  !: = 0/1 flag for horizontal average on avt, avmu, avmv
+      &                  navb  =  0                 !: = 0/1 flag for constant or profile background avt
+   REAL(wp), PUBLIC ::   ediff = 0.1_wp       ,  &  !: coeff. for vertical eddy coef.; avt=ediff*mxl*sqrt(e)
+      &                  ediss = 0.7_wp       ,  &  !: coef. of the Kolmogoroff dissipation 
+      &                  ebb   = 3.75_wp      ,  &  !: coef. of the surface input of tke
+      &                  efave = 1._wp        ,  &  !: coef. for the tke vert. diff. coeff.; avtke=efave*avm
+      &                  emin  = 0.7071e-6_wp ,  &  !: minimum value of tke (m2/s2)
+      &                  emin0 = 1.e-4_wp     ,  &  !: surface minimum value of tke (m2/s2)
+      &                  ri_c  = 2._wp / 9._wp      !: critic Richardson number
+
+# if defined key_cfg_1d
+   !                                                                   ! 1D cfg only
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   e_dis, e_mix,      &  ! dissipation and mixing turbulent lengh scales
+      &                                          e_pdl, e_ric          ! prandl and local Richardson numbers
+#endif
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/ZDF/zdftke.F90,v 1.16 2007/06/05 10:39:27 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_tke( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_tke  ***
+      !!
+      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients using a 1.5 turbulent closure scheme.
+      !!
+      !! ** Method  :   The time evolution of the turbulent kinetic energy 
+      !!      (tke) is computed from a prognostic equation :
+      !!         d(en)/dt = eboost eav (d(u)/dz)**2       ! shear production
+      !!                  + d( efave eav d(en)/dz )/dz    ! diffusion of tke
+      !!                  + grav/rau0 pdl eav d(rau)/dz   ! stratif. destruc.
+      !!                  - ediss / emxl en**(2/3)        ! dissipation
+      !!      with the boundary conditions:
+      !!         surface: en = max( emin0,ebb sqrt(taux^2 + tauy^2) )
+      !!         bottom : en = emin
+      !!      -1- The dissipation and mixing turbulent lengh scales are computed
+      !!      from the usual diagnostic buoyancy length scale:  
+      !!         mxl= 1/(sqrt(en)/N)  WHERE N is the brunt-vaisala frequency
+      !!      Four cases : 
+      !!         nmxl=0 : mxl bounded by the distance to surface and bottom.
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=1 : mxl bounded by the vertical scale factor.
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=2 : mxl bounded such that the vertical derivative of mxl 
+      !!                  is less than 1 (|d/dz(xml)|<1). 
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=3 : lup = mxl bounded using |d/dz(xml)|<1 from the surface 
+      !!                        to the bottom
+      !!                  ldown = mxl bounded using |d/dz(xml)|<1 from the bottom 
+      !!                        to the surface
+      !!                  zmxld = sqrt (lup*ldown) ; zmxlm = min(lup,ldown)
+      !!      -2- Compute the now Turbulent kinetic energy. The time differencing
+      !!      is implicit for vertical diffusion term, linearized for kolmo-
+      !!      goroff dissipation term, and explicit forward for both buoyancy
+      !!      and dynamic production terms. Thus a tridiagonal linear system is
+      !!      solved.
+      !!         Note that - the shear production is multiplied by eboost in order
+      !!      to set the critic richardson number to ri_c (namelist parameter)
+      !!                   - the destruction by stratification term is multiplied
+      !!      by the Prandtl number (defined by an empirical funtion of the local 
+      !!      Richardson number) if npdl=1 (namelist parameter)
+      !!      coefficient (zesh2):
+      !!      -3- Compute the now vertical eddy vicosity and diffusivity
+      !!      coefficients from en (before the time stepping) and zmxlm:
+      !!              avm = max( avtb, ediff*zmxlm*en^1/2 )
+      !!              avt = max( avmb, pdl*avm )  (pdl=1 if npdl=0)
+      !!              eav = max( avmb, avm )
+      !!      avt and avm are horizontally averaged to avoid numerical insta-
+      !!      bilities.
+      !!        N.B. The computation is done from jk=2 to jpkm1 except for
+      !!      en. Surface value of avt avmu avmv are set once a time to
+      !!      their background value in routine zdf_tke_init.
+      !!
+      !! ** Action  :   compute en (now turbulent kinetic energy)
+      !!                update avt, avmu, avmv (before vertical eddy coef.)
+      !!
+      !! References : Gaspar et al., jgr, 95, 1990,
+      !!              Blanke and Delecluse, jpo, 1991
+      !!----------------------------------------------------------------------
+      USE oce     , zwd   => ua,  &  ! use ua as workspace
+         &          zmxlm => ta,  &  ! use ta as workspace
+         &          zmxld => sa      ! use sa as workspace
+      !
+      INTEGER, INTENT(in) ::   kt ! ocean time step
+      !
+      INTEGER  ::   ji, jj, jk                  ! dummy loop arguments
+      REAL(wp) ::   zmlmin, zbbrau,          &  ! temporary scalars
+         &          zfact1, zfact2, zfact3,  &  !
+         &          zrn2, zesurf,            &  !
+         &          ztx2, zty2, zav,         &  !
+         &          zcoef, zcof, zsh2,       &  !
+         &          zdku, zdkv, zpdl, zri,   &  !
+         &          zsqen, zesh2,            &  !
+         &          zemxl, zemlm, zemlp
+      !!--------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL zdf_tke_init      ! Initialization (first time-step only)
+
+      !                                            ! Local constant initialization
+      zmlmin = 1.e-8
+      zbbrau =  .5 * ebb / rau0
+      zfact1 = -.5 * rdt * efave
+      zfact2 = 1.5 * rdt * ediss
+      zfact3 = 0.5 * rdt * ediss
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! I.  Mixing length
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! Buoyancy length scale: l=sqrt(2*e/n**2)
+      ! ---------------------
+      zmxlm(:,:, 1 ) = zmlmin   ! surface set to the minimum value
+      zmxlm(:,:,jpk) = zmlmin   ! bottom  set to the minimum value
+!CDIR NOVERRCHK
+      DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrn2 = MAX( rn2(ji,jj,jk), rsmall )
+               zmxlm(ji,jj,jk) = MAX( SQRT( 2. * en(ji,jj,jk) / zrn2 ), zmlmin  )
+            END DO
+         END DO
+      END DO
+
+      ! Physical limits for the mixing length
+      ! -------------------------------------
+      zmxld(:,:, 1 ) = zmlmin   ! surface set to the minimum value
+      zmxld(:,:,jpk) = zmlmin   ! bottom  set to the minimum value
+
+      SELECT CASE ( nmxl )
+
+      CASE ( 0 )           ! bounded by the distance to surface and bottom
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zemxl = MIN( fsdepw(ji,jj,jk), zmxlm(ji,jj,jk),   &
+                  &            fsdepw(ji,jj,mbathy(ji,jj)) - fsdepw(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )           ! bounded by the vertical scale factor
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zemxl = MIN( fse3w(ji,jj,jk), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+         END DO
+
+      CASE ( 2 )           ! |dk[xml]| bounded by e3t :
+         DO jk = 2, jpkm1         ! from the surface to the bottom :
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+         DO jk = jpkm1, 2, -1     ! from the bottom to the surface :
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zemxl = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+         END DO
+
+      CASE ( 3 )           ! lup and ldown, |dk[xml]| bounded by e3t :
+         DO jk = 2, jpkm1         ! from the surface to the bottom : lup
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+         DO jk = jpkm1, 2, -1     ! from the bottom to the surface : ldown
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+         END DO
+!CDIR NOVERRCHK
+         DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+            DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zemlm = MIN ( zmxld(ji,jj,jk),  zmxlm(ji,jj,jk) )
+                  zemlp = SQRT( zmxld(ji,jj,jk) * zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemlm
+                  zmxld(ji,jj,jk) = zemlp
+               END DO
+            END DO
+         END DO
+
+      END SELECT
+
+# if defined key_cfg_1d
+      ! save mixing and dissipation turbulent length scales
+      e_dis(:,:,:) = zmxld(:,:,:)
+      e_mix(:,:,:) = zmxlm(:,:,:)
+# endif
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! II  Tubulent kinetic energy time stepping
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! 1. Vertical eddy viscosity on tke (put in zmxlm) and first estimate of avt
+      ! ---------------------------------------------------------------------
+!CDIR NOVERRCHK
+      DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zsqen = SQRT( en(ji,jj,jk) )
+               zav   = ediff * zmxlm(ji,jj,jk) * zsqen
+               avt  (ji,jj,jk) = MAX( zav, avtb(jk) ) * tmask(ji,jj,jk)
+               zmxlm(ji,jj,jk) = MAX( zav, avmb(jk) ) * tmask(ji,jj,jk)
+               zmxld(ji,jj,jk) = zsqen / zmxld(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! 2. Surface boundary condition on tke and its eddy viscosity (zmxlm)
+      ! -------------------------------------------------
+      ! en(1)   = ebb sqrt(taux^2+tauy^2) / rau0  (min value emin0)
+      ! zmxlm(1) = avmb(1) and zmxlm(jpk) = 0.
+!CDIR NOVERRCHK
+      DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ztx2 = taux(ji-1,jj  ) + taux(ji,jj)
+            zty2 = tauy(ji  ,jj-1) + tauy(ji,jj)
+            zesurf = zbbrau * SQRT( ztx2 * ztx2 + zty2 * zty2 )
+            en (ji,jj,1) = MAX( zesurf, emin0 ) * tmask(ji,jj,1)
+            zmxlm(ji,jj,1  ) = avmb(1) * tmask(ji,jj,1)
+            zmxlm(ji,jj,jpk) = 0.e0
+         END DO
+      END DO
+
+      ! 3. Now Turbulent kinetic energy (output in en)
+      ! -------------------------------
+      ! Resolution of a tridiagonal linear system by a "methode de chasse"
+      ! computation from level 2 to jpkm1  (e(1) already computed and
+      ! e(jpk)=0 ). 
+
+      SELECT CASE ( npdl )
+
+      CASE ( 0 )           ! No Prandtl number
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! zesh2 = eboost * (du/dz)^2 - N^2
+                  zcoef = 0.5 / fse3w(ji,jj,jk)
+                  ! shear
+                  zdku = zcoef * (   ub(ji-1, jj ,jk-1) + ub(ji,jj,jk-1)   &
+                  &                - ub(ji-1, jj ,jk  ) - ub(ji,jj,jk  )  )
+                  zdkv = zcoef * (   vb( ji ,jj-1,jk-1) + vb(ji,jj,jk-1)   &
+                  &                - vb( ji ,jj-1,jk  ) - vb(ji,jj,jk  )  )
+                  ! coefficient (zesh2)
+                  zesh2 =  eboost * ( zdku*zdku + zdkv*zdkv ) - rn2(ji,jj,jk)
+
+                  ! Matrix
+                  zcof = zfact1 * tmask(ji,jj,jk)
+                  ! lower diagonal
+                  avmv(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk  ) + zmxlm(ji,jj,jk-1) )   &
+                  &                    / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  ! upper diagonal
+                  avmu(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk+1) + zmxlm(ji,jj,jk  ) )   &
+                  &                    / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  ! diagonal
+                  zwd(ji,jj,jk) = 1. - avmv(ji,jj,jk) - avmu(ji,jj,jk) + zfact2 * zmxld(ji,jj,jk)
+                  ! right hand side in en 
+                  en(ji,jj,jk) = en(ji,jj,jk) + zfact3 * zmxld(ji,jj,jk) * en   (ji,jj,jk)   &
+                  &                           +   rdt  * zmxlm(ji,jj,jk) * zesh2
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )           ! Prandtl number
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! zesh2 =  eboost * (du/dz)^2 - pdl * N^2
+                  zcoef = 0.5 / fse3w(ji,jj,jk)
+                  ! shear
+                  zdku = zcoef * (   ub(ji-1,jj  ,jk-1) + ub(ji,jj,jk-1) &
+                  &                - ub(ji-1,jj  ,jk  ) - ub(ji,jj,jk  )   )
+                  zdkv = zcoef * (   vb(ji  ,jj-1,jk-1) + vb(ji,jj,jk-1) &
+                  &                - vb(ji  ,jj-1,jk  ) - vb(ji,jj,jk  )   )
+                  ! square of vertical shear
+                  zsh2 = zdku * zdku + zdkv * zdkv
+                  ! local Richardson number
+                  zri  = MAX( rn2(ji,jj,jk), 0. ) / ( zsh2 + 1.e-20 )
+# if defined key_cfg_1d
+                  ! save masked local Richardson number in zmxlm array
+                  e_ric(ji,jj,jk) = zri * tmask(ji,jj,jk)
+# endif
+                  ! Prandtl number
+                  zpdl = 1.0
+                  IF( zri >= 0.2 ) zpdl = 0.2 / zri
+                  zpdl = MAX( 0.1, zpdl )
+                  ! coefficient (esh2)
+                  zesh2 = eboost * zsh2 - zpdl * rn2(ji,jj,jk)
+
+                  ! Matrix
+                  zcof = zfact1 * tmask(ji,jj,jk)
+                  ! lower diagonal
+                  avmv(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk  ) + zmxlm(ji,jj,jk-1) )   &
+                  &                     / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  ! upper diagonal
+                  avmu(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk+1) + zmxlm(ji,jj,jk  ) )   &
+                  &                     / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  ! diagonal
+                  zwd(ji,jj,jk) = 1. - avmv(ji,jj,jk) - avmu(ji,jj,jk) + zfact2 * zmxld(ji,jj,jk)
+                  ! right hand side in en 
+                  en(ji,jj,jk) = en(ji,jj,jk) + zfact3 * zmxld(ji,jj,jk) * en   (ji,jj,jk)   &
+                  &                           +   rdt  * zmxlm(ji,jj,jk) * zesh2
+                  ! save masked Prandlt number in zmxlm array
+                  zmxld(ji,jj,jk) = zpdl * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      END SELECT
+
+# if defined key_cfg_1d
+      !  save masked Prandlt number
+      e_pdl(:,:,2:jpkm1) = zmxld(:,:,2:jpkm1)
+      e_pdl(:,:,      1) = e_pdl(:,:,      2)
+      e_pdl(:,:,    jpk) = e_pdl(:,:,  jpkm1)      
+# endif
+
+      ! 4. Matrix inversion from level 2 (tke prescribed at level 1)
+      !!--------------------------------
+      ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1
+      DO jk = 3, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1    ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - avmv(ji,jj,jk) * avmu(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! Second recurrence : Lk = RHSk - Lk / Dk-1 * Lk-1
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1    ! vector opt.
+            avmv(ji,jj,2) = en(ji,jj,2) - avmv(ji,jj,2) * en(ji,jj,1)    ! Surface boudary conditions on tke
+         END DO
+      END DO
+      DO jk = 3, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1    ! vector opt.
+               avmv(ji,jj,jk) = en(ji,jj,jk) - avmv(ji,jj,jk) / zwd(ji,jj,jk-1) *avmv(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! thrid recurrence : Ek = ( Lk - Uk * Ek+1 ) / Dk
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1    ! vector opt.
+            en(ji,jj,jpkm1) = avmv(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 2, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1    ! vector opt.
+               en(ji,jj,jk) = ( avmv(ji,jj,jk) - avmu(ji,jj,jk) * en(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Save the result in en and set minimum value of tke : emin
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               en(ji,jj,jk) = MAX( en(ji,jj,jk), emin ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Lateral boundary conditions on ( avt, en )   (sign unchanged)
+      CALL lbc_lnk( en , 'W', 1. )   ;   CALL lbc_lnk( avt, 'W', 1. )
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! III.  Before vertical eddy vicosity and diffusivity coefficients
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      SELECT CASE ( nave )
+         
+      CASE ( 0 )                ! no horizontal average
+
+         ! Vertical eddy viscosity
+
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = ( avt  (ji,jj,jk) + avt  (ji+1,jj  ,jk) ) * umask(ji,jj,jk)   &
+                  &     / MAX( 1.,   tmask(ji,jj,jk) + tmask(ji+1,jj  ,jk) )
+                  avmv(ji,jj,jk) = ( avt  (ji,jj,jk) + avt  (ji  ,jj+1,jk) ) * vmask(ji,jj,jk)   &
+                  &     / MAX( 1.,   tmask(ji,jj,jk) + tmask(ji  ,jj+1,jk) )
+               END DO
+            END DO
+         END DO
+
+         ! Lateral boundary conditions (avmu,avmv) (U- and V- points, sign unchanged)
+         CALL lbc_lnk( avmu, 'U', 1. )   ;    CALL lbc_lnk( avmv, 'V', 1. )
+         
+      CASE ( 1 )                ! horizontal average
+
+         !                                                ( 1/2  1/2 )
+         ! Eddy viscosity: horizontal average: avmu = 1/4 ( 1    1   )
+         !                      ( 1/2  1 1/2 )            ( 1/2  1/2 )
+         !           avmv = 1/4 ( 1/2  1 1/2 )      
+         
+!! caution vectopt_memory change the solution (last digit of the solver stat)
+#  if defined key_vectopt_memory
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = (      avt(ji,jj  ,jk) + avt(ji+1,jj  ,jk)   &
+                  &                 +.5*( avt(ji,jj-1,jk) + avt(ji+1,jj-1,jk)   &
+                  &                      +avt(ji,jj+1,jk) + avt(ji+1,jj+1,jk) ) ) * eumean(ji,jj,jk)
+
+                  avmv(ji,jj,jk) = (      avt(ji  ,jj,jk) + avt(ji  ,jj+1,jk)   &
+                  &                 +.5*( avt(ji-1,jj,jk) + avt(ji-1,jj+1,jk)   &
+                  &                      +avt(ji+1,jj,jk) + avt(ji+1,jj+1,jk) ) ) * evmean(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+#  else
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = (   avt  (ji,jj  ,jk) + avt  (ji+1,jj  ,jk)   &
+                  &              +.5*( avt  (ji,jj-1,jk) + avt  (ji+1,jj-1,jk)   &
+                  &                   +avt  (ji,jj+1,jk) + avt  (ji+1,jj+1,jk) ) ) * umask(ji,jj,jk)  &
+                  &       / MAX( 1.,   tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk)   &
+                  &              +.5*( tmask(ji,jj-1,jk) + tmask(ji+1,jj-1,jk)   &
+                  &                   +tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) )  )
+
+                  avmv(ji,jj,jk) = (   avt  (ji  ,jj,jk) + avt  (ji  ,jj+1,jk)   &
+                  &              +.5*( avt  (ji-1,jj,jk) + avt  (ji-1,jj+1,jk)   &
+                  &                   +avt  (ji+1,jj,jk) + avt  (ji+1,jj+1,jk) ) ) * vmask(ji,jj,jk)  &
+                  &      /  MAX( 1.,   tmask(ji  ,jj,jk) + tmask(ji  ,jj+1,jk)   &
+                  &              +.5*( tmask(ji-1,jj,jk) + tmask(ji-1,jj+1,jk)   &
+                  &                   +tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk) )  )
+               END DO
+            END DO
+         END DO
+#  endif
+
+         ! Lateral boundary conditions (avmu,avmv) (sign unchanged)
+         CALL lbc_lnk( avmu, 'U', 1. )   ;    CALL lbc_lnk( avmv, 'V', 1. )
+
+         ! Vertical eddy diffusivity
+         ! ------------------------------
+         !                                (1 2 1)
+         ! horizontal average  avt = 1/16 (2 4 2)
+         !                                (1 2 1)
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+#  if defined key_vectopt_memory
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avt(ji,jj,jk) = ( avmu(ji,jj,jk) + avmu(ji-1,jj  ,jk)    &
+                  &               + avmv(ji,jj,jk) + avmv(ji  ,jj-1,jk)  ) * etmean(ji,jj,jk)
+               END DO
+            END DO
+#  else
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avt(ji,jj,jk) = ( avmu (ji,jj,jk) + avmu (ji-1,jj  ,jk)   &
+                  &               + avmv (ji,jj,jk) + avmv (ji  ,jj-1,jk)  ) * tmask(ji,jj,jk)   &
+                  &     / MAX( 1.,  umask(ji,jj,jk) + umask(ji-1,jj  ,jk)   &
+                  &               + vmask(ji,jj,jk) + vmask(ji  ,jj-1,jk)  )
+               END DO
+            END DO
+#  endif
+         END DO
+
+      END SELECT
+
+      ! multiplied by the Prandtl number (npdl>1)
+      ! ----------------------------------------
+      IF( npdl == 1 ) THEN
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zpdl = zmxld(ji,jj,jk)
+                  avt(ji,jj,jk) = MAX( zpdl * avt(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! Minimum value on the eddy viscosity
+      ! ----------------------------------------
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), avmb(jk) ) * umask(ji,jj,jk)
+               avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), avmb(jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Lateral boundary conditions on avt  (sign unchanged)
+      ! ------------------------------=====
+      CALL lbc_lnk( avt, 'W', 1. )
+
+      ! write en in restart file
+      ! ------------------------
+      IF( lrst_oce )   CALL tke_rst( kt, 'WRITE' )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab3d_1=en  , clinfo1=' tke  - e: ', tab3d_2=avt , clinfo2=' t: ', ovlap=1, kdim=jpk)
+         CALL prt_ctl(tab3d_1=avmu, clinfo1=' tke  - u: ', mask1=umask, &
+            &         tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE zdf_tke
+
+
+   SUBROUTINE zdf_tke_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_tke_init  ***
+      !!                     
+      !! ** Purpose :   Initialization of the vertical eddy diffivity and 
+      !!      viscosity when using a tke turbulent closure scheme
+      !!
+      !! ** Method  :   Read the namtke namelist and check the parameters
+      !!      called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namlist namtke
+      !!
+      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
+      !!
+      !!----------------------------------------------------------------------
+      USE dynzdf_exp
+      USE trazdf_exp
+      !
+# if defined key_vectopt_memory
+      ! caution vectopt_memory change the solution (last digit of the solver stat)
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+# else
+      INTEGER ::           jk   ! dummy loop indices
+# endif
+
+      NAMELIST/namtke/ ln_rstke, ediff, ediss, ebb, efave, emin, emin0,   &
+         &             ri_c, nitke, nmxl, npdl, nave, navb
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namtke : Turbulente Kinetic Energy
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namtke )
+
+      ! Compute boost associated with the Richardson critic
+      !     (control values: ri_c = 0.3   ==> eboost=1.25 for npdl=1 or 2)
+      !     (                ri_c = 0.222 ==> eboost=1.                  )
+      eboost = ri_c * ( 2. + ediss / ediff ) / 2.
+
+
+      ! Parameter control and print
+      ! ---------------------------
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_tke_init : tke turbulent closure scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namtke : set tke mixing parameters'
+         WRITE(numout,*) '             restart with tke from no tke ln_rstke = ', ln_rstke
+         WRITE(numout,*) '             coef. to compute avt           ediff  = ', ediff
+         WRITE(numout,*) '             Kolmogoroff dissipation coef.  ediss  = ', ediss
+         WRITE(numout,*) '             tke surface input coef.        ebb    = ', ebb
+         WRITE(numout,*) '             tke diffusion coef.            efave  = ', efave
+         WRITE(numout,*) '             minimum value of tke           emin   = ', emin
+         WRITE(numout,*) '             surface minimum value of tke   emin0  = ', emin0
+         WRITE(numout,*) '             number of restart iter loops   nitke  = ', nitke
+         WRITE(numout,*) '             mixing length type             nmxl   = ', nmxl
+         WRITE(numout,*) '             prandl number flag             npdl   = ', npdl
+         WRITE(numout,*) '             horizontal average flag        nave   = ', nave
+         WRITE(numout,*) '             critic Richardson nb           ri_c   = ', ri_c
+         WRITE(numout,*) '                and its associated coeff.   eboost = ', eboost
+         WRITE(numout,*) '             constant background or profile navb   = ', navb
+         WRITE(numout,*)
+      ENDIF
+
+      ! Check nmxl and npdl values
+      IF( nmxl < 0 .OR. nmxl > 3 ) CALL ctl_stop( '          bad flag: nmxl is < 0 or > 3 ' )
+      IF( npdl < 0 .OR. npdl > 1 ) CALL ctl_stop( '          bad flag: npdl is < 0 or > 1 ' )
+
+      ! Horizontal average : initialization of weighting arrays 
+      ! -------------------
+      
+      SELECT CASE ( nave )
+
+      CASE ( 0 )                ! no horizontal average
+         IF(lwp) WRITE(numout,*) '          no horizontal average on avt, avmu, avmv'
+         IF(lwp) WRITE(numout,*) '          only in very high horizontal resolution !'
+# if defined key_vectopt_memory
+         ! caution vectopt_memory change the solution (last digit of the solver stat)
+         ! weighting mean arrays etmean, eumean and evmean
+         !           ( 1  1 )                                          ( 1 )
+         ! avt = 1/4 ( 1  1 )     avmu = 1/2 ( 1  1 )       avmv=  1/2 ( 1 )
+         !                          
+         etmean(:,:,:) = 0.e0
+         eumean(:,:,:) = 0.e0
+         evmean(:,:,:) = 0.e0
+         
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  etmean(ji,jj,jk) = tmask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
+                  &            + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+                  
+                  eumean(ji,jj,jk) = umask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  tmask(ji,jj,jk) + tmask(ji+1,jj  ,jk)  )
+
+                  evmean(ji,jj,jk) = vmask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  tmask(ji,jj,jk) + tmask(ji  ,jj+1,jk)  )
+               END DO
+            END DO
+         END DO
+# endif
+
+      CASE ( 1 )                ! horizontal average 
+         IF(lwp) WRITE(numout,*) '          horizontal average on avt, avmu, avmv'
+# if defined key_vectopt_memory
+         ! caution vectopt_memory change the solution (last digit of the solver stat)
+         ! weighting mean arrays etmean, eumean and evmean
+         !           ( 1  1 )              ( 1/2  1/2 )             ( 1/2  1  1/2 )
+         ! avt = 1/4 ( 1  1 )   avmu = 1/4 ( 1    1   )   avmv= 1/4 ( 1/2  1  1/2 )
+         !                                 ( 1/2  1/2 )
+         etmean(:,:,:) = 0.e0
+         eumean(:,:,:) = 0.e0
+         evmean(:,:,:) = 0.e0
+         
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  etmean(ji,jj,jk) = tmask(ji,jj,jk)                     &
+                  &  / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
+                  &            + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+                  
+                  eumean(ji,jj,jk) = umask(ji,jj,jk)                        &
+                  &  / MAX( 1.,   tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk)   &
+                  &       +.5 * ( tmask(ji,jj-1,jk) + tmask(ji+1,jj-1,jk)   &
+                  &              +tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) )  )
+
+                  evmean(ji,jj,jk) = vmask(ji,jj,jk)                        &
+                  &  / MAX( 1.,   tmask(ji  ,jj,jk) + tmask(ji  ,jj+1,jk)   &
+                  &       +.5 * ( tmask(ji-1,jj,jk) + tmask(ji-1,jj+1,jk)   &
+                  &              +tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk) )  )
+               END DO
+            END DO
+         END DO
+# endif
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nave = ', nave
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+
+      ! Background eddy viscosity and diffusivity profil
+      ! ------------------------------------------------
+      IF( navb == 0 ) THEN
+         !   Define avmb, avtb from namelist parameter
+         avmb(:) = avm0
+         avtb(:) = avt0
+      ELSE
+         !   Background profile of avt (fit a theoretical/observational profile (Krauss 1990) 
+         avmb(:) = avm0
+!!bug  this is not valide neither in scoord
+         IF(ln_sco .AND. lwp) WRITE(numout,cform_war)
+         IF(ln_sco .AND. lwp) WRITE(numout,*) '          avtb profile nort valid in sco'
+
+         avtb(:) = avt0 + ( 3.0e-4 - 2 * avt0 ) * 1.0e-4 * gdepw_0(:)   ! m2/s
+      ENDIF
+
+      !   Increase the background in the surface layers
+      avmb(1) = 10.  * avmb(1)      ;      avtb(1) = 10.  * avtb(1)
+      avmb(2) = 10.  * avmb(2)      ;      avtb(2) = 10.  * avtb(2)
+      avmb(3) =  5.  * avmb(3)      ;      avtb(3) =  5.  * avtb(3)
+      avmb(4) =  2.5 * avmb(4)      ;      avtb(4) =  2.5 * avtb(4)
+
+
+      ! Initialization of vertical eddy coef. to the background value
+      ! -------------------------------------------------------------
+      DO jk = 1, jpk
+         avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
+         avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
+         avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
+      END DO
+
+
+      ! read or initialize turbulent kinetic energy ( en )
+      ! -------------------------------------------------
+      CALL tke_rst( nit000, 'READ' )
+      !
+   END SUBROUTINE zdf_tke_init
+
+
+   SUBROUTINE tke_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE ts_rst  ***
+     !!                     
+     !! ** Purpose : Read or write filtered free surface arrays in restart file
+     !!
+     !! ** Method  : 
+     !!
+     !!----------------------------------------------------------------------
+     INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+     CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+     !
+     INTEGER ::   jit   ! dummy loop indices
+     !!----------------------------------------------------------------------
+     !
+     IF( TRIM(cdrw) == 'READ' ) THEN
+        IF( ln_rstart ) THEN
+           IF( iom_varid( numror, 'en' ) > 0 .AND. .NOT.(ln_rstke) ) THEN 
+              CALL iom_get( numror, jpdom_autoglo, 'en', en )
+           ELSE
+              IF(lwp .AND. iom_varid(numror,'en') > 0 ) WRITE(numout,*) ' ===>>>> : previous run without tke scheme'
+              IF(lwp .AND. ln_rstke ) WRITE(numout,*) ' ===>>>> : We do not use en from the restart file'
+              IF(lwp) WRITE(numout,*) ' ===>>>> : en set by iterative loop'
+              IF(lwp) WRITE(numout,*) ' =======             ========='
+              en (:,:,:) = emin * tmask(:,:,:)
+              DO jit = 2, nitke+1
+                 CALL zdf_tke( jit )
+              END DO
+           ENDIF
+        ELSE
+           en(:,:,:) = emin * tmask(:,:,:)      ! no restart: en set to emin
+        ENDIF
+     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+        CALL iom_rstput( kt, nitrst, numrow, 'en', en )
+     ENDIF
+     !
+   END SUBROUTINE tke_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        NO TKE scheme
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftke = .FALSE.   !: TKE flag
+CONTAINS
+   SUBROUTINE zdf_tke( kt )          ! Empty routine
+      WRITE(*,*) 'zdf_tke: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_tke
+#endif
+
+   !!======================================================================
+END MODULE zdftke
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke_jki.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke_jki.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ZDF/zdftke_jki.F90	(revision 4536)
@@ -0,0 +1,545 @@
+MODULE zdftke_jki
+   !!======================================================================
+   !!                       ***  MODULE  zdftke_jki  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the tke
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !! History :
+   !!   9.0  !  02-08  (G. Madec)  autotasking optimization
+   !!----------------------------------------------------------------------
+#if defined key_zdftke   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdftke'                                             TKE scheme
+   !!----------------------------------------------------------------------
+   !!   zdf_tke_jki  : update momentum and tracer Kz from a tke scheme
+   !!                  j-k-i loops for NEC autotasking or OpenMP 
+   !!                  (used if 'key_mpp_omp' activated)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics
+   USE zdftke          ! ???
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE phycst          ! physical constants
+   USE taumod          ! surface stress
+   USE prtctl          ! Print control
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zdf_tke_jki   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zdf_tke_jki( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_tke  ***
+      !!                     
+      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients using a 1.5 turbulent closure scheme.
+      !!
+      !! ** Method  :   The time evolution of the turbulent kinetic energy 
+      !!      (tke) is computed from a prognostic equation :
+      !!         d(en)/dt = eboost eav (d(u)/dz)**2       ! shear production
+      !!                  + d( efave eav d(en)/dz )/dz    ! diffusion of tke
+      !!                  + g/rau0 pdl eav d(rau)/dz      ! stratif. destruc.
+      !!                  - ediss / emxl en**(2/3)        ! dissipation
+      !!      with the boundary conditions:
+      !!         surface: en = max( emin0,ebb sqrt(taux^2 + tauy^2) )
+      !!         bottom : en = emin
+      !!      -1- The dissipation and mixing turbulent lengh scales are computed
+      !!      from the usual diagnostic buoyancy length scale:  
+      !!         mxl= 1/(sqrt(en)/N)  WHERE N is the brunt-vaisala frequency
+      !!      Four cases : 
+      !!         nmxl=0 : mxl bounded by the distance to surface and bottom.
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=1 : mxl bounded by the vertical scale factor.
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=2 : mxl bounded such that the vertical derivative of mxl 
+      !!                  is less than 1 (|d/dz(xml)|<1). 
+      !!                  zmxld = zmxlm = mxl
+      !!         nmxl=3 : lup = mxl bounded using |d/dz(xml)|<1 from the surface 
+      !!                        to the bottom
+      !!                  ldown = mxl bounded using |d/dz(xml)|<1 from the bottom 
+      !!                        to the surface
+      !!                  zmxld = sqrt (lup*ldown) ; zmxlm = min(lup,ldown)
+      !!      -2- Compute the now Turbulent kinetic energy. The time differencing
+      !!      is implicit for vertical diffusion term, linearized for kolmo-
+      !!      goroff dissipation term, and explicit forward for both buoyancy
+      !!      and dynamic production terms. Thus a tridiagonal linear system is
+      !!      solved.
+      !!         Note that - the shear production is multiplied by eboost in order
+      !!      to set the critic richardson number to ri_c (namelist parameter)
+      !!                   - the destruction by stratification term is multiplied
+      !!      by the Prandtl number (defined by an empirical funtion of the local 
+      !!      Richardson number) if npdl=1 (namelist parameter)
+      !!      coefficient (zesh2):
+      !!      -3- Compute the now vertical eddy vicosity and diffusivity
+      !!      coefficients from en (before the time stepping) and zmxlm:
+      !!              avm = max( avtb, ediff*zmxlm*en^1/2 )
+      !!              avt = max( avmb, pdl*avm )  (pdl=1 if npdl=0)
+      !!              eav = max( avmb, avm )
+      !!      avt and avm are horizontally averaged to avoid numerical insta-
+      !!      bilities.
+      !!        N.B. The computation is done from jk=2 to jpkm1 except for
+      !!      en. Surface value of avt avmu avmv are set once a time to
+      !!      their background value in routine zdftke_init.
+      !!
+      !! ** Action :   compute en (now turbulent kinetic energy)
+      !!               update avt, avmu, avmv (before vertical eddy coeff.)
+      !!
+      !! References :
+      !!      Gaspar et al., jgr, 95, 1990,
+      !!      Blanke and Delecluse, jpo, 1991
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce       , zwd   => ua,  &  ! use ua as workspace
+                      zmxlm => ta,  &  ! use ta as workspace
+                      zmxld => sa      ! use sa as workspace
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jk          ! dummy loop arguments
+      REAL(wp) ::                   &
+         zmlmin, zbbrau,            &  ! temporary scalars
+         zfact1, zfact2, zfact3,    &  !
+         zrn2, zesurf,              &  !
+         ztx2, zty2, zav,           &  !
+         zcoef, zcof, zsh2,         &  !
+         zdku, zdkv, zpdl, zri,     &  !
+         zsqen, zesh2,              &  !
+         zemxl, zemlm, zemlp
+      !!--------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!--------------------------------------------------------------------
+
+
+      ! 0. Initialization
+      !    --------------
+      IF( kt == nit000  )   CALL zdf_tke_init
+
+      ! Local constant 
+      zmlmin = 1.e-8
+      zbbrau =  .5 * ebb / rau0
+      zfact1 = -.5 * rdt * efave
+      zfact2 = 1.5 * rdt * ediss
+      zfact3 = 0.5 * rdt * ediss
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! I.  Mixing length
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      !                                                ! ===============
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         !                                             ! =============== 
+         ! Buoyancy length scale: l=sqrt(2*e/n**2)
+         ! ---------------------
+         zmxlm(:,jj, 1 ) = zmlmin   ! surface set to the minimum value
+         zmxlm(:,jj,jpk) = zmlmin   ! bottom  set to the minimum value
+!CDIR NOVERRCHK
+         DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+            DO ji = 2, jpim1
+               zrn2 = MAX( rn2(ji,jj,jk), rsmall )
+               zmxlm(ji,jj,jk) = MAX( SQRT( 2. * en(ji,jj,jk) / zrn2 ), zmlmin  )
+            END DO
+         END DO
+
+
+         ! Physical limits for the mixing length
+         ! -------------------------------------
+         zmxld(:,jj, 1 ) = zmlmin   ! surface set to the minimum value
+         zmxld(:,jj,jpk) = zmlmin   ! bottom  set to the minimum value
+
+         SELECT CASE ( nmxl )
+
+         CASE ( 0 )           ! bounded by the distance to surface and bottom
+
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zemxl = MIN( fsdepw(ji,jj,jk), zmxlm(ji,jj,jk),   &
+                  &            fsdepw(ji,jj,mbathy(ji,jj)) - fsdepw(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+
+         CASE ( 1 )           ! bounded by the vertical scale factor
+
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zemxl = MIN( fse3w(ji,jj,jk), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+
+         CASE ( 2 )           ! |dk[xml]| bounded by e3t :
+
+            DO jk = 2, jpk           ! from the surface to the bottom :
+               DO ji = 2, jpim1
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+            DO jk = jpkm1, 2, -1     ! from the bottom to the surface :
+               DO ji = 2, jpim1
+                  zemxl = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemxl
+                  zmxld(ji,jj,jk) = zemxl
+               END DO
+            END DO
+
+         CASE ( 3 )           ! lup and ldown, |dk[xml]| bounded by e3t :
+
+            DO jk = 2, jpk           ! from the surface to the bottom : lup
+               DO ji = 2, jpim1
+                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+            DO jk = jpkm1, 1, -1     ! from the bottom to the surface : ldown
+               DO ji = 2, jpim1
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+               END DO
+            END DO
+!CDIR NOVERRCHK
+            DO jk = 1, jpk
+!CDIR NOVERRCHK
+               DO ji = 2, jpim1
+                  zemlm = MIN ( zmxld(ji,jj,jk),  zmxlm(ji,jj,jk) )
+                  zemlp = SQRT( zmxld(ji,jj,jk) * zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = zemlm
+                  zmxld(ji,jj,jk) = zemlp
+               END DO
+            END DO
+
+         END SELECT
+
+
+         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+         ! II  Tubulent kinetic energy time stepping
+         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+         ! 1. Vertical eddy viscosity on tke (put in zmxlm) and first estimate of avt
+         ! ---------------------------------------------------------------------
+!CDIR NOVERRCHK
+         DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+            DO ji = 2, jpim1
+               zsqen = SQRT( en(ji,jj,jk) )
+               zav   = ediff * zmxlm(ji,jj,jk) * zsqen
+               avt  (ji,jj,jk) = MAX( zav, avtb(jk) ) * tmask(ji,jj,jk)
+               zmxlm(ji,jj,jk) = MAX( zav, avmb(jk) ) * tmask(ji,jj,jk)
+               zmxld(ji,jj,jk) = zsqen / zmxld(ji,jj,jk)
+            END DO
+         END DO
+
+
+         ! 2. Surface boundary condition on tke and its eddy viscosity (zmxlm)
+         ! -------------------------------------------------
+         ! en(1)   = ebb sqrt(taux^2+tauy^2) / rau0  (min value emin0)
+         ! zmxlm(1) = avmb(1) and zmxlm(jpk) = 0.
+!CDIR NOVERRCHK
+         DO ji = 2, jpim1
+            ztx2 = taux(ji-1,jj  ) + taux(ji,jj)
+            zty2 = tauy(ji  ,jj-1) + tauy(ji,jj)
+            zesurf = zbbrau * SQRT( ztx2 * ztx2 + zty2 * zty2 )
+            en (ji,jj,1) = MAX( zesurf, emin0 ) * tmask(ji,jj,1)
+            zmxlm(ji,jj,1  ) = avmb(1) * tmask(ji,jj,1)
+            zmxlm(ji,jj,jpk) = 0.e0
+         END DO
+
+
+         ! 3. Now Turbulent kinetic energy (output in en)
+         ! -------------------------------
+         ! Resolution of a tridiagonal linear system by a "methode de chasse"
+         ! computation from level 2 to jpkm1  (e(1) already computed and
+         ! e(jpk)=0 ). 
+
+         SELECT CASE ( npdl )
+
+         CASE ( 0 )           ! No Prandtl number
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  ! zesh2 = eboost * (du/dz)^2 - N^2
+                  zcoef = 0.5 / fse3w(ji,jj,jk)
+                  ! shear
+                  zdku = zcoef * (   ub(ji-1, jj ,jk-1) + ub(ji,jj,jk-1)   &
+                  &                - ub(ji-1, jj ,jk  ) - ub(ji,jj,jk  )  )
+                  zdkv = zcoef * (   vb( ji ,jj-1,jk-1) + vb(ji,jj,jk-1)   &
+                  &                - vb( ji ,jj-1,jk  ) - vb(ji,jj,jk  )  )
+                  ! coefficient (zesh2)
+                  zesh2 =  eboost * ( zdku*zdku + zdkv*zdkv ) - rn2(ji,jj,jk)
+
+                  ! Matrix
+                  zcof = zfact1 * tmask(ji,jj,jk)
+                  ! lower diagonal
+                  avmv(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk  ) + zmxlm(ji,jj,jk-1) )   &
+                  &                    / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  ! upper diagonal
+                  avmu(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk+1) + zmxlm(ji,jj,jk  ) )   &
+                  &                    / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  ! diagonal
+                  zwd(ji,jj,jk) = 1. - avmv(ji,jj,jk) - avmu(ji,jj,jk) + zfact2 * zmxld(ji,jj,jk)
+                  ! right hand side in en 
+                  en(ji,jj,jk) = en(ji,jj,jk) + zfact3 * zmxld(ji,jj,jk) * en   (ji,jj,jk)   &
+                  &                           +   rdt  * zmxlm(ji,jj,jk) * zesh2
+               END DO
+            END DO
+
+         CASE ( 1 )           ! Prandtl number
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  ! zesh2 =  eboost * (du/dz)^2 - pdl * N^2
+                  zcoef = 0.5 / fse3w(ji,jj,jk)
+                  ! shear
+                  zdku = zcoef * (   ub(ji-1,jj  ,jk-1) + ub(ji,jj,jk-1) &
+                  &                - ub(ji-1,jj  ,jk  ) - ub(ji,jj,jk  )   )
+                  zdkv = zcoef * (   vb(ji  ,jj-1,jk-1) + vb(ji,jj,jk-1) &
+                  &                - vb(ji  ,jj-1,jk  ) - vb(ji,jj,jk  )   )
+                  ! square of vertical shear
+                  zsh2 = zdku * zdku + zdkv * zdkv
+                  ! Prandtl number
+                  zri  = MAX( rn2(ji,jj,jk), 0. ) / ( zsh2 + 1.e-20 )
+                  zpdl = 1.0
+                  IF( zri >= 0.2 ) zpdl = 0.2 / zri
+                  zpdl = MAX( 0.1, zpdl )
+                  ! coefficient (esh2)
+                  zesh2 = eboost * zsh2 - zpdl * rn2(ji,jj,jk)
+
+                  ! Matrix
+                  zcof = zfact1 * tmask(ji,jj,jk)
+                  ! lower diagonal
+                  avmv(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk  ) + zmxlm(ji,jj,jk-1) )   &
+                  &                     / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
+                  ! upper diagonal
+                  avmu(ji,jj,jk) = zcof * ( zmxlm(ji,jj,jk+1) + zmxlm(ji,jj,jk  ) )   &
+                  &                     / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk) )
+                  ! diagonal
+                  zwd(ji,jj,jk) = 1. - avmv(ji,jj,jk) - avmu(ji,jj,jk) + zfact2 * zmxld(ji,jj,jk)
+                  ! right hand side in en 
+                  en(ji,jj,jk) = en(ji,jj,jk) + zfact3 * zmxld(ji,jj,jk) * en   (ji,jj,jk)   &
+                  &                           +   rdt  * zmxlm(ji,jj,jk) * zesh2
+                  ! save masked Prandlt number in zmxlm array
+                  zmxld(ji,jj,jk) = zpdl * tmask(ji,jj,jk)
+               END DO
+            END DO
+
+         END SELECT
+
+
+         ! 4. Matrix inversion from level 2 (tke prescribed at level 1)
+         !---------------------------------
+
+         ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1
+         DO jk = 3, jpkm1
+            DO ji = 2, jpim1
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - avmv(ji,jj,jk) * avmu(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+
+         ! Second recurrence : Lk = RHSk - Lk / Dk-1 * Lk-1
+         DO ji = 2, jpim1
+            avmv(ji,jj,2) = en(ji,jj,2) - avmv(ji,jj,2) * en(ji,jj,1)    ! Surface boudary conditions on tke
+         END DO
+         DO jk = 3, jpkm1
+            DO ji = 2, jpim1
+               avmv(ji,jj,jk) = en(ji,jj,jk) - avmv(ji,jj,jk) / zwd(ji,jj,jk-1) *avmv(ji,jj,jk-1)
+            END DO
+         END DO
+
+         ! thrid recurrence : Ek = ( Lk - Uk * Ek+1 ) / Dk
+         DO ji = 2, jpim1
+            en(ji,jj,jpkm1) = avmv(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+         DO jk = jpk-2, 2, -1
+            DO ji = 2, jpim1
+               en(ji,jj,jk) = ( avmv(ji,jj,jk) - avmu(ji,jj,jk) * en(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+
+         ! Save the result in en and set minimum value of tke : emin
+         DO jk = 2, jpkm1
+            DO ji = 2, jpim1
+               en(ji,jj,jk) = MAX( en(ji,jj,jk), emin ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Lateral boundary conditions on ( avt, en )  (sign unchanged)
+      ! --------------------------------=========
+      CALL lbc_lnk( avt, 'W', 1. )   ;   CALL lbc_lnk( en , 'W', 1. )
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! III.  Before vertical eddy vicosity and diffusivity coefficients
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! =============== 
+         SELECT CASE ( nave )
+            
+         CASE ( 0 )                ! no horizontal average
+
+            ! Vertical eddy viscosity
+
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = ( avt  (ji,jj,jk) + avt  (ji+1,jj  ,jk) ) * umask(ji,jj,jk)   &
+                  &     / MAX( 1.,   tmask(ji,jj,jk) + tmask(ji+1,jj  ,jk) )
+                  avmv(ji,jj,jk) = ( avt  (ji,jj,jk) + avt  (ji  ,jj+1,jk) ) * vmask(ji,jj,jk)   &
+                  &     / MAX( 1.,   tmask(ji,jj,jk) + tmask(ji  ,jj+1,jk) )
+               END DO
+            END DO
+
+            
+         CASE ( 1 )                ! horizontal average
+
+            !                                                ( 1/2  1/2 )
+            ! Eddy viscosity: horizontal average: avmu = 1/4 ( 1    1   )
+            !                      ( 1/2  1 1/2 )            ( 1/2  1/2 )
+            !           avmv = 1/4 ( 1/2  1 1/2 )      
+            
+!! caution vectopt_memory change the solution (last digit of the solver stat)
+#  if defined key_vectopt_memory
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = (      avt(ji,jj  ,jk) + avt(ji+1,jj  ,jk)   &
+                  &                 +.5*( avt(ji,jj-1,jk) + avt(ji+1,jj-1,jk)   &
+                  &                      +avt(ji,jj+1,jk) + avt(ji+1,jj+1,jk) ) ) * eumean(ji,jj,jk)
+
+                  avmv(ji,jj,jk) = (      avt(ji  ,jj,jk) + avt(ji  ,jj+1,jk)   &
+                  &                 +.5*( avt(ji-1,jj,jk) + avt(ji-1,jj+1,jk)   &
+                  &                      +avt(ji+1,jj,jk) + avt(ji+1,jj+1,jk) ) ) * evmean(ji,jj,jk)
+               END DO
+            END DO
+#  else
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmu(ji,jj,jk) = (   avt  (ji,jj  ,jk) + avt  (ji+1,jj  ,jk)   &
+                  &              +.5*( avt  (ji,jj-1,jk) + avt  (ji+1,jj-1,jk)   &
+                  &                   +avt  (ji,jj+1,jk) + avt  (ji+1,jj+1,jk) ) ) * umask(ji,jj,jk)  &
+                  &       / MAX( 1.,   tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk)   &
+                  &              +.5*( tmask(ji,jj-1,jk) + tmask(ji+1,jj-1,jk)   &
+                  &                   +tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) )  )
+
+                  avmv(ji,jj,jk) = (   avt  (ji  ,jj,jk) + avt  (ji  ,jj+1,jk)   &
+                  &              +.5*( avt  (ji-1,jj,jk) + avt  (ji-1,jj+1,jk)   &
+                  &                   +avt  (ji+1,jj,jk) + avt  (ji+1,jj+1,jk) ) ) * vmask(ji,jj,jk)  &
+                  &      /  MAX( 1.,   tmask(ji  ,jj,jk) + tmask(ji  ,jj+1,jk)   &
+                  &              +.5*( tmask(ji-1,jj,jk) + tmask(ji-1,jj+1,jk)   &
+                  &                   +tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk) )  )
+               END DO
+            END DO
+#  endif
+         END SELECT
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Lateral boundary conditions (avmu,avmv)  (sign unchanged)
+      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )
+
+      !                                                ! ===============
+      DO jk = 2, jpkm1                                 ! Horizontal slab
+         !                                             ! =============== 
+         SELECT CASE ( nave )
+            
+         CASE ( 1 )                ! horizontal average
+
+            ! Vertical eddy diffusivity
+            ! ------------------------------
+            !                                (1 2 1)
+            ! horizontal average  avt = 1/16 (2 4 2)
+            !                                (1 2 1)
+!! caution vectopt_memory change the solution (last digit of the solver stat)
+#  if defined key_vectopt_memory
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avt(ji,jj,jk) = ( avmu(ji,jj,jk) + avmu(ji-1,jj  ,jk)    &
+                  &               + avmv(ji,jj,jk) + avmv(ji  ,jj-1,jk)  ) * etmean(ji,jj,jk)
+               END DO
+            END DO
+#  else
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avt(ji,jj,jk) = ( avmu (ji,jj,jk) + avmu (ji-1,jj  ,jk)   &
+                  &               + avmv (ji,jj,jk) + avmv (ji  ,jj-1,jk)  ) * tmask(ji,jj,jk)   &
+                  &     / MAX( 1.,  umask(ji,jj,jk) + umask(ji-1,jj  ,jk)   &
+                  &               + vmask(ji,jj,jk) + vmask(ji  ,jj-1,jk)  )
+               END DO
+            END DO
+#  endif
+         END SELECT
+
+
+         ! multiplied by the Prandtl number (npdl>1)
+         ! ----------------------------------------
+         IF( npdl == 1 ) THEN
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zpdl = zmxld(ji,jj,jk)
+                  avt(ji,jj,jk) = MAX( zpdl * avt(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         ENDIF
+
+         ! Minimum value on the eddy viscosity
+         ! ----------------------------------------
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), avmb(jk) ) * umask(ji,jj,jk)
+               avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), avmb(jk) ) * vmask(ji,jj,jk)
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+
+      ! Lateral boundary conditions on avt   (W-point (=T), sign unchanged)
+      ! ------------------------------=====
+      CALL lbc_lnk( avt, 'W', 1. )
+
+      ! write en in restart file
+      ! ------------------------
+      IF( lrst_oce )   CALL tke_rst( kt, 'WRITE' )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab3d_1=en  , clinfo1=' tke  - e: ', tab3d_2=avt , clinfo2=' t: ', ovlap=1, kdim=jpk)
+         CALL prt_ctl(tab3d_1=avmu, clinfo1=' tke  - u: ', mask1=umask, &
+            &         tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask,ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE zdf_tke_jki
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        NO TKE scheme
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE zdf_tke_jki( kt )          ! Empty routine
+      WRITE(*,*) 'zdf_tke_jki: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_tke_jki
+#endif
+
+   !!======================================================================
+END MODULE zdftke_jki
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_interp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_interp.F90	(revision 4536)
@@ -0,0 +1,15 @@
+MODULE agrif_opa_interp
+   !!======================================================================
+   !!                       ***  MODULE agrif_opa_interp  ***
+   !!  Dummy module
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                     NO agrif use
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+END MODULE agrif_opa_interp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_sponge.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_sponge.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_sponge.F90	(revision 4536)
@@ -0,0 +1,15 @@
+MODULE agrif_opa_sponge
+   !!======================================================================
+   !!                       ***  MODULE agrif_opa_sponge  ***
+   !!  Dummy module
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                     NO agrif use
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+END MODULE agrif_opa_sponge
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_update.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/agrif_opa_update.F90	(revision 4536)
@@ -0,0 +1,15 @@
+MODULE agrif_opa_update
+   !!======================================================================
+   !!                       ***  MODULE agrif_opa_update  ***
+   !!  Dummy module
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                     NO agrif use
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+END MODULE agrif_opa_update
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla.F90	(revision 4536)
@@ -0,0 +1,781 @@
+MODULE cla
+   !!==============================================================================
+   !!                         ***  MODULE  cla  ***
+   !! Cross Land Advection : parameterize ocean exchanges through straits by a
+   !!                        specified advection across land.
+   !!==============================================================================
+#if defined key_orca_r2
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r2'   :                             ORCA R2 configuration
+   !!----------------------------------------------------------------------
+   !!   tra_cla           : update the tracer trend with the horizontal 
+   !!                       and vertical advection trends at straits
+   !!   tra_bab_el_mandeb : 
+   !!   tra_gibraltar     :
+   !!   tra_hormuz        :
+   !!   tra_cla_init      :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE ocesbc          ! ocean surface boundary condition (fluxes)
+   USE lib_mpp         ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC tra_cla        ! routine called by step.F90
+
+   !! * Modules variables   
+   REAL(wp) :: zempmed, zempred
+
+   REAL(wp) :: zisw_rs, zurw_rs, zbrw_rs          ! Imposed transport Red Sea 
+   REAL(wp) :: zisw_ms, zmrw_ms, zurw_ms, zbrw_ms ! Imposed transport Med Sea 
+   REAL(wp) :: zisw_pg, zbrw_pg                   ! Imposed transport Persic Gulf 
+
+   REAL(wp), DIMENSION(jpk) ::   &
+      zu1_rs_i, zu2_rs_i, zu3_rs_i,              &  ! Red Sea velocities
+      zu1_ms_i, zu2_ms_i, zu3_ms_i,              &  ! Mediterranean Sea velocities
+      zu_pg                                         ! Persic Gulf velocities
+   REAL(wp), DIMENSION (jpk) :: zthor, zshor        ! Temperature, salinity Hormuz 
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_cla( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tra_cla  ***
+      !!                   
+      !! ** Purpose :   Update the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations
+      !!      at some straits ( Bab el Mandeb, Gibraltar, Hormuz ).
+      !!
+      !! ** Method  :   ...
+      !!         Add this trend now to the general trend of tracer (ta,sa):
+      !!            (ta,sa) = (ta,sa) + ( zta , zsa )
+      !!
+      !! ** Action  :   update (ta,sa) with the now advective tracer trends
+      !!
+      !! History :
+      !!        !         (A. Bozec)  original code  
+      !!   8.5  !  02-11  (A. Bozec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      !!----------------------------------------------------------------------
+ 
+      ! cross land advection for straits
+
+      ! Initialization
+      IF( kt == nit000 )   CALL tra_cla_init
+
+
+      ! Bab el Mandeb strait horizontal advection
+
+      CALL tra_bab_el_mandeb 
+
+      ! Gibraltar strait horizontal advection
+
+      CALL tra_gibraltar
+
+      ! Hormuz Strait ( persian Gulf) horizontal advection
+
+      CALL tra_hormuz 
+
+   END SUBROUTINE tra_cla
+
+
+   SUBROUTINE tra_bab_el_mandeb
+      !!---------------------------------------------------------------------
+      !!             ***  ROUTINE tra_bab_el_mandeb  ***
+      !!
+      !! ** Purpose :   Update the horizontal advective trend of tracers
+      !!      correction in Bab el Mandeb strait and
+      !!      add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!     We impose transport at Bab el Mandeb and knowing T and S in
+      !!     surface and depth at each side of the  strait, we deduce T and S
+      !!     of the deep outflow of the Red Sea in the Indian ocean . 
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!    
+      !!     The horizontal advection is evaluated by a second order cen-
+      !!     tered scheme using now fields (leap-frog scheme). In specific
+      !!     areas (vicinity of major river mouths, some straits, or tn
+      !!     approaching the freezing point) it is mixed with an upstream 
+      !!     scheme for stability reasons. 
+      !!
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history :
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zt, zs
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs, zu2_rs, zu3_rs
+      !!---------------------------------------------------------------------
+
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt  = 0.e0       ! East  Bab el Mandeb surface north point (T)
+      zsums  = 0.e0       ! East  Bab el Mandeb surface north point (S)
+      zsumt1 = 0.e0       ! East  Bab el Mandeb depth   south point (T)
+      zsums1 = 0.e0       ! East  Bab el Mandeb depth   south point (S)
+      zsumt2 = 0.e0       ! West  Bab el Mandeb surface             (T)
+      zsums2 = 0.e0       ! West  Bab el Mandeb surface             (S)
+      zsumt3 = 0.e0       ! West  Bab el Mandeb depth               (T)
+      zsums3 = 0.e0       ! West  Bab el Mandeb depth               (S)
+      zsumt4 = 0.e0       ! East  Bab el Mandeb depth   north point (T) 
+      zsums4 = 0.e0       ! East  Bab el Mandeb depth   north point (S) 
+      
+      ! EMP of the Red Sea 
+      ! ------------------
+
+      zempred = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred = zempred + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+      ! convert in m3
+      zempred = zempred * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_rs(:) = zu1_rs_i(:)
+      zu2_rs(:) = zu2_rs_i(:)
+      zu3_rs(:) = zu3_rs_i(:)
+
+      ! velocity profile at 161,88 East Bab el Mandeb North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1, 8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs(jk) = zu1_rs(jk) - ( zempred / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )     
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 161, 88 West Bab el Mandeb 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs(jk) = zu3_rs(jk) + ( zempred / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! east Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 19
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt  = zsumt  + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)  
+               zsums  = zsums  + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb surface vertical sum of transport* S,T
+      DO jk =  1, 10
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt2 = zsumt2 + tn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+               zsums2 = zsums2 + sn(ji,jj,jk) * e1v(ji-1,jj) * fse3v(ji-1,jj,jk) * zu3_rs(jk)
+            END DO
+         END DO
+      END DO
+
+      ! west Bab el Mandeb deeper
+      DO jj = mj0(89), mj1(89) 
+         DO ji = mi0(160), mi1(160) 
+            zsumt3 = tn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+            zsums3 = sn(ji,jj,16) * e1v(ji,jj-1) * fse3v(ji,jj-1,16) * zu3_rs(16)
+         END DO
+      END DO
+
+      ! east  Bab el Mandeb deeper  
+      DO jk =  20, 21
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zsumt4 =  zsumt4 + tn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk)
+               zsums4 =  zsums4 + sn(ji,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zu1_rs(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! Total transport  
+      zsumt1 = -( zsumt3 + zsumt2 + zsumt + zsumt4 )
+      zsums1 = -( zsums3 + zsums2 + zsums + zsums4 )
+
+      ! Temperature and Salinity at East Bab el Mandeb, Level 21
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zt = zsumt1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+            zs = zsums1 / ( zu2_rs(21) * e2u(ji,jj-1) * fse3u(ji,jj-1,21) )
+         END DO
+      END DO
+      
+      ! New Temperature and Salinity at East Bab el Mandeb
+      ! --------------------------------------------------
+
+      ! north point 	
+      DO jk = 1, jpk
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu1_rs(jk) * tn(ji,jj,jk)
+               sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu1_rs(jk) * sn(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! south point
+      jk =  21
+      DO jj = mj0(87), mj1(87) 
+         DO ji = mi0(161), mi1(161) 
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+            ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu2_rs(jk) * zt
+            sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu2_rs(jk) * zs
+         END DO
+      END DO
+
+
+      ! New Temperature and Salinity at West Bab el Mandeb 
+      ! --------------------------------------------------
+
+      ! surface	
+      DO jk = 1, 10
+         DO jj = mj0(89), mj1(89) 
+            DO ji = mi0(160), mi1(160) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+               ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu3_rs(jk) * tn(ji+1,jj-1,jk)
+               sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu3_rs(jk) * sn(ji+1,jj-1,jk)
+            END DO
+         END DO
+      END DO
+      ! deeper
+      jk =  16
+      DO jj = mj0(89), mj1(89) 
+         DO ji = mi0(160), mi1(160) 
+            zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+            zsu = e1v(ji,jj-1) * fse3v(ji,jj-1,jk)
+            ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu3_rs(jk) * tn(ji,jj,jk)
+            sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu3_rs(jk) * sn(ji,jj,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE tra_bab_el_mandeb
+
+
+   SUBROUTINE tra_gibraltar
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_gibraltar  ***
+      !!
+      !! ** Purpose :
+      !!        Update the horizontal advective trend of tracers (t & s)
+      !!        correction in Gibraltar  and
+      !!        add it to the general trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      We impose transport at Gibraltar and knowing T and S in
+      !!      surface and deeper at each side of the strait, we deduce T and S
+      !!      of the outflow of the Mediterranean Sea in the Atlantic ocean .
+      !!                                
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!         C A U T I O N : the trend saved is the centered trend only.
+      !!      It doesn't take into account the upstream part of the scheme.
+      !!
+      !! ** history :
+      !!           !  02-06  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk               ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zsumt, zsumt1, zsumt2, zsumt3, zsumt4
+      REAL(wp) :: zsums, zsums1, zsums2, zsums3, zsums4
+      REAL(wp) :: zt, zs
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms, zu2_ms, zu3_ms
+      !!---------------------------------------------------------------------
+      
+      ! Initialization of vertical sum for T and S transport
+      ! ----------------------------------------------------
+
+      zsumt  = 0.e0        ! West Gib. surface south point ( T )
+      zsums  = 0.e0        ! West Gib. surface south point ( S )
+      zsumt1 = 0.e0        ! East Gib. surface north point ( T )
+      zsums1 = 0.e0        ! East Gib. surface north point ( S )
+      zsumt2 = 0.e0        ! East Gib. depth   north point ( T )
+      zsums2 = 0.e0        ! East Gib. depth   north point ( S )
+      zsumt3 = 0.e0        ! West Gib. depth   south point ( T ) 
+      zsums3 = 0.e0        ! West Gib. depth   south point ( S ) 
+      zsumt4 = 0.e0        ! West Gib. depth   north point ( T ) 
+      zsums4 = 0.e0        ! West Gib. depth   north point ( S ) 
+      
+      ! EMP of Mediterranean Sea 
+      ! ------------------------
+ 
+      zempmed = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(96),mj1(110)
+         DO ji = mi0(141),mi1(181)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed = zempmed + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+
+      ! minus 2 points in Red Sea and 3 in Atlantic ocean
+      DO jj = mj0(96),mj1(96)
+         DO ji = mi0(148),mi1(148)
+            zempmed = zempmed  -  emp(ji  ,jj) * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj)   &
+                               -  emp(ji+1,jj) * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+
+      ! convert in m3
+      zempmed = zempmed * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_ms(:) = zu1_ms_i(:)
+      zu2_ms(:) = zu2_ms_i(:)
+      zu3_ms(:) = zu3_ms_i(:)
+
+      ! velocity profile at 139,101  South point + emp on surface 
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms(jk) = zu1_ms(jk) + ( zempmed / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! profile at East Gibraltar    
+      ! velocity profile at 141,102  + emp on surface 
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms(jk) = zu3_ms(jk) +  ( zempmed / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+     
+      ! Balance of temperature and salinity
+      ! -----------------------------------
+
+      ! west gibraltar surface vertical sum of transport* S,T
+      DO  jk =  1, 14 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt  = zsumt + tn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)  
+               zsums  = zsums + sn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar surface  vertical sum of transport* S,T
+      DO  jk =  1, 14 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt1 = zsumt1 + tn(ji, jj,jk) * e2u(ji+1, jj+1) * fse3u(ji+1, jj+1,jk) * zu3_ms(jk)
+               zsums1 = zsums1 + sn(ji, jj,jk) * e2u(ji+1, jj+1) * fse3u(ji+1, jj+1,jk) * zu3_ms(jk)
+            END DO
+         END DO
+      END DO
+
+      ! east Gibraltar deeper  vertical sum of transport* S,T
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(141), mi1(141) 
+            zsumt2 = tn(ji, jj,21) * e2u(ji-1, jj) * fse3u(ji-1, jj,21) * zu3_ms(21)
+            zsums2 = sn(ji, jj,21) * e2u(ji-1, jj) * fse3u(ji-1, jj,21) * zu3_ms(21)
+         END DO
+      END DO
+      
+      ! west Gibraltar deeper vertical sum of transport* S,T
+      DO  jk =  21, 22 
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zsumt3 = zsumt3 + tn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)
+               zsums3 = zsums3 + sn(ji, jj,jk) * e2u(ji, jj) * fse3u(ji, jj,jk) * zu1_ms(jk)
+            END DO
+         END DO
+      END DO
+
+      ! Total transport = 0.
+      zsumt4 = zsumt2 + zsumt1 - zsumt - zsumt3
+      zsums4 = zsums2 + zsums1 - zsums - zsums3
+
+      ! Temperature and Salinity at West gibraltar , Level 22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zt = zsumt4 / ( zu2_ms(22) * e2u(ji-1, jj) * fse3u(ji-1, jj, 22) )
+            zs = zsums4 / ( zu2_ms(22) * e2u(ji-1, jj) * fse3u(ji-1, jj, 22) )
+         END DO
+      END DO
+      
+      ! New Temperature and Salinity trend at West Gibraltar
+      ! ----------------------------------------------------
+
+      ! south point 	
+      DO jk = 1, 22
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               ta(ji, jj,jk) = ta(ji, jj,jk) - ( 1. / zvt ) * zsu * zu1_ms(jk) * tn(ji, jj,jk)
+               sa(ji, jj,jk) = sa(ji, jj,jk) - ( 1. / zvt ) * zsu * zu1_ms(jk) * sn(ji, jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! north point 
+      DO jk = 15, 20
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               ta(ji, jj,jk) = ta(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_ms(jk) * tn(ji, jj-1,jk)
+               sa(ji, jj,jk) = sa(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_ms(jk) * sn(ji, jj-1,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Gibraltar outflow, north point deeper
+      jk =  22
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(139), mi1(139) 
+            zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+            zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+            ta(ji, jj,jk) = ta(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_ms(jk) * zt
+            sa(ji, jj,jk) = sa(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_ms(jk) * zs
+         END DO
+      END DO
+
+
+      ! New Temperature and Salinity at East Gibraltar 
+      ! ----------------------------------------------
+
+      ! surface	
+      DO jk = 1, 14
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(141), mi1(141) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               ta(ji, jj,jk) = ta(ji, jj,jk) + ( 1. / zvt ) * zsu * zu3_ms(jk) * tn(ji-2, jj-1,jk)
+               sa(ji, jj,jk) = sa(ji, jj,jk) + ( 1. / zvt ) * zsu * zu3_ms(jk) * sn(ji-2, jj-1,jk)
+            END DO
+         END DO
+      END DO
+      ! deeper
+      jk =  21
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(141), mi1(141) 
+            zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+            zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+            ta(ji, jj,jk) = ta(ji, jj,jk) + ( 1. / zvt ) * zsu * zu3_ms(jk) * tn(ji, jj,jk)
+            sa(ji, jj,jk) = sa(ji, jj,jk) + ( 1. / zvt ) * zsu * zu3_ms(jk) * sn(ji, jj,jk)
+         END DO
+      END DO
+
+   END SUBROUTINE tra_gibraltar
+
+
+   SUBROUTINE tra_hormuz
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_hormuz  ***
+      !!
+      !! ** Purpose :   Update the horizontal advective trend of tracers
+      !!        correction in Hormuz.
+      !!
+      !! ** Method :   We impose transport at Hormuz .
+      !!                                
+      !! ** history :
+      !!           !  02-11  (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk              ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      !!---------------------------------------------------------------------
+      
+      ! New trend at Hormuz strait
+      ! --------------------------
+      DO jk = 1, 8   
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu_pg(jk) * tn(ji,jj,jk) 
+               sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu_pg(jk) * sn(ji,jj,jk) 
+            END DO
+         END DO
+      END DO
+      DO jk = 16, 18
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               ta(ji,jj,jk) = ta(ji,jj,jk) + ( 1. / zvt ) * zsu * zu_pg(jk) * zthor(jk)
+               sa(ji,jj,jk) = sa(ji,jj,jk) + ( 1. / zvt ) * zsu * zu_pg(jk) * zshor(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE tra_hormuz
+
+
+   SUBROUTINE tra_cla_init
+      !!---------------------------------------------------------------------
+      !!               ***  ROUTINE tra_cla_init  ***
+      !!
+      !! ** Purpose :   Initialization of variables
+      !!
+      !! ** history :
+      !!      9.0  !  02-11  (A. Bozec) Original code
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk              ! dummy loop indices
+      !!---------------------------------------------------------------------
+
+      ! Control print
+      ! -------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'tra_cla_init : cross land advection on tracer '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+
+      ! Initialization at Bab el Mandeb
+      ! -------------------------------
+
+      ! imposed transport
+      zisw_rs = 0.4e6        ! inflow surface water
+      zurw_rs = 0.2e6        ! upper recirculation water
+!!Alex      zbrw_rs = 1.2e6        ! bottom  recirculation water
+      zbrw_rs = 0.5e6        ! bottom  recirculation water
+
+      ! initialization of the velocity at Bab el Mandeb
+      zu1_rs_i(:) = 0.e0      ! velocity profile at 161,88 South point
+      zu2_rs_i(:) = 0.e0      ! velocity profile at 161,87 North point
+      zu3_rs_i(:) = 0.e0      ! velocity profile at 160,88 East  point
+
+      ! velocity profile at 161,88 East Bab el Mandeb North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1, 8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs_i(jk) = -( zisw_rs / 8. ) / ( e2u(ji,jj) * fse3u(ji,jj,jk) )     
+            END DO
+         END DO
+      END DO
+
+      ! recirculation water 
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zu1_rs_i(20) = -(           zurw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,20) )
+            zu1_rs_i(21) = -( zbrw_rs - zurw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,21) )
+         END DO
+      END DO
+      
+      ! velocity profile at 161,87 East Bab el Mandeb South point
+      DO jj = mj0(87), mj1(87) 
+         DO ji = mi0(160), mi1(160) 
+            zu2_rs_i(21) =  ( zbrw_rs + zisw_rs ) / ( e2u(ji,jj) * fse3u(ji,jj,21) )
+         END DO
+      END DO
+
+      ! velocity profile at 161, 88 West Bab el Mandeb 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs_i(jk) =  ( zisw_rs / 10. ) / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! deeper
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zu3_rs_i(16)  = - zisw_rs /( e1v(ji,jj) * fse3v(ji,jj,16) )
+         END DO
+      END DO
+
+
+      ! Initialization at Gibraltar
+      ! ---------------------------
+
+      ! imposed transport
+      zisw_ms = 0.8e6         ! atlantic-mediterranean  water
+      zmrw_ms = 0.7e6         ! middle recirculation water
+      zurw_ms = 2.5e6         ! upper  recirculation water 
+      zbrw_ms = 3.5e6         ! bottom recirculation water 
+
+      ! initialization of the velocity
+      zu1_ms_i(:) = 0.e0       ! velocity profile at 139,101 South point
+      zu2_ms_i(:) = 0.e0       ! velocity profile at 139,102 North point
+      zu3_ms_i(:) = 0.e0       ! velocity profile at 141,102 East  point
+
+      ! velocity profile at 139,101  South point
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_i(jk) = ( zisw_ms / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk)) 
+            END DO
+         END DO
+      END DO
+
+      ! middle recirculation ( uncounting in the balance )
+      DO jk = 15, 20                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_i(jk) = ( zmrw_ms / 6. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu1_ms_i(21) =  (           zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,21) )
+            zu1_ms_i(22) =  ( zbrw_ms - zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,22) )
+         END DO
+      END DO
+
+      ! velocity profile at 139,102  North point
+      ! middle recirculation ( uncounting in the balance )
+      DO jk = 15, 20                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu2_ms_i(jk) = -( zmrw_ms / 6. ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,jk) ) 
+            END DO
+         END DO
+      END DO 
+
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu2_ms_i(22) = -( zisw_ms + zbrw_ms ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,22) )
+         END DO
+      END DO 
+
+      ! profile at East Gibraltar   
+      ! velocity profile at 141,102 
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms_i(jk) =  ( zisw_ms / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! deeper 
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu3_ms_i(21) = -zisw_ms / ( e2u(ji, jj) * fse3u(ji, jj,21) )
+         END DO
+      END DO
+
+
+      ! Initialization at Hormuz
+      ! ------------------------
+
+      ! imposed transport
+      zisw_pg = 4. * 0.25e6      ! surface and bottom  water
+
+      ! initialization of the velocity
+      zu_pg(:) = 0.e0       ! velocity profile at 139,101 South point
+
+      ! Velocity profile 
+      DO jk = 1, 8 
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zu_pg(jk) = -( zisw_pg / 8. ) /  ( e2u(ji-1,jj) * fse3u(ji-1,jj,jk) )
+            END DO
+         END DO
+      END DO
+     DO jk = 16, 18
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zu_pg(jk) =  ( zisw_pg / 3. )  / ( e2u(ji-1,jj) * fse3u(ji-1,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! Temperature and Salinity at Hormuz
+      zthor(:) = 0.e0
+      zshor(:) = 0.e0
+
+      zthor(16) = 18.4
+      zshor(16) = 36.27
+      !
+      zthor(17) = 17.8
+      zshor(17) = 36.4
+      !
+      zthor(18) = 16.
+      zshor(18) = 36.27
+ 
+   END SUBROUTINE tra_cla_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                              NO cross land advection
+   !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+CONTAINS
+   SUBROUTINE tra_cla( kt ) 
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step indice
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_cla : No use of cross land advection'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+   END SUBROUTINE tra_cla
+#endif
+
+   !!======================================================================
+END MODULE cla
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_div.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_div.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_div.F90	(revision 4536)
@@ -0,0 +1,541 @@
+MODULE cla_div
+   !!==============================================================================
+   !!                    ***  MODULE  cla_div  ***
+   !! Ocean diagnostic variable : specific update of the horizontal divergence
+   !!                             CAUTION: Specific to ORCA_R2
+   !!==============================================================================
+#if defined key_orca_r2
+   !!----------------------------------------------------------------------
+   !!   'key_orca_r2'                                 global ocean model R2
+   !!----------------------------------------------------------------------
+   !!   div_cla      : 
+   !!   div_bab_el_mandeb
+   !!   div_gibraltar
+   !!   div_hormuz
+   !!   div_cla_init :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE ocesbc          ! ocean surface boundary condition (fluxes)
+   USE lib_mpp         ! distributed memory computing library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   REAL(wp) :: zempmed, zempred       ! EMP of Mediterranean and Red Sea 
+
+   REAL(wp) :: zisw_rs, zbrw_rs, zurw_rs          ! imposed transport at Red Sea
+   REAL(wp) :: zisw_ms, zbrw_ms, zurw_ms, zmrw_ms ! imposed transport at Mediterranean Sea
+   REAL(wp) :: zisw_pg, zbrw_pg                   ! imposed transport at Persic Gulf
+
+   REAL(wp), DIMENSION (jpk) ::   &
+      zu1_rs_i, zu2_rs_i, zu3_rs_i,                   & ! Red Sea velocities
+      zu1_ms_i, zu2_ms_i, zu3_ms_i,                   & ! Mediterranean Sea velocities
+      zu_pg                                             ! Persic Gulf velocities
+   
+   !! * Routine accessibility
+   PUBLIC div_cla     ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE div_cla ( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE div_cla  ***
+      !!
+      !! ** Purpose :   update the horizontal divergence of the velocity field
+      !!      for at some straits ( Gibraltar, Bab el Mandeb and Hormuz ).
+      !!
+      !! ** Method  :   With imposed transport at each strait, we compute 
+      !!      corresponding velocities and update horizontal divergence.
+      !!        Apply lateral boundary conditions on hdivn through a call
+      !!      to routine lbc_lnk.
+      !!
+      !! ** Action  :   update hdivn array : the now horizontal divergence
+      !!
+      !! History :
+      !!   8.5  !  02-11 (A. Bozec)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!----------------------------------------------------------------------
+
+      ! Correction of the Divergence at some straits
+            
+      IF( kt == nit000 )     CALL div_cla_init    ! Initialization
+
+      CALL div_bab_el_mandeb                        ! New divergence at Bab el Mandeb 
+
+      CALL div_gibraltar                            ! New divergence at Gibraltar
+
+      CALL div_hormuz                               ! Hormuz Strait ( persian Gulf)
+
+      ! Lateral boundary conditions on hdivn
+      CALL lbc_lnk( hdivn, 'T', 1. )
+
+   END SUBROUTINE div_cla
+
+   SUBROUTINE div_bab_el_mandeb
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE div_bab_el_mandeb  ***
+      !!       
+      !! ** Purpose :   Update  the now horizontal divergence of the velocity 
+      !!     field in Bab el Mandeb ( Red Sea strait ).
+      !!
+      !! ** Method  :   Set the velocity field at each side of the strait :
+      !!                                          |
+      !!            |/ \|            N          |\ /|
+      !!            |_|_|______      |          |___|______
+      !!        88  |   |<-       W - - E    88 |   |<-
+      !!        87  |___|______      |       87 |___|->____
+      !!             160 161         S           160 161 
+      !!       horizontal view                horizontal view
+      !!          surface                        depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History :
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-11  (A. Bozec) F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt, zwei   ! temporary scalar
+      REAL(wp), DIMENSION (jpk) ::  zu1_rs, zu2_rs, zu3_rs
+      !!---------------------------------------------------------------------
+      
+      ! EMP on the Red Sea 
+      ! ------------------
+
+      zempred = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(87), mj1(96)
+         DO ji = mi0(148), mi1(160) 
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred = zempred + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+
+      ! convert in m3
+      zempred = zempred * 1.e-3         
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_rs(:) = zu1_rs_i(:)
+      zu2_rs(:) = zu2_rs_i(:)
+      zu3_rs(:) = zu3_rs_i(:)
+
+      ! velocity profile at 161,88 North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs(jk) = zu1_rs(jk) - ( zempred / 8. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! velocity profile at 160,88 North  point
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs(jk) = zu3_rs(jk) + ( zempred / 10. ) / ( e1v(ji, jj) * fse3v(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+       
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the new divergence at 161,88 
+      DO jk = 1, 21
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn(ji, jj  ,jk) = hdivn(ji, jj  ,jk) - ( 1. / zvt ) * zsu * zu1_rs(jk)
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 161,87 
+      DO jk = 1, 21
+         DO jj = mj0(87), mj1(87) 
+            DO ji = mi0(161), mi1(161) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn(ji, jj,jk) = hdivn(ji, jj,jk) - ( 1. / zvt ) * zsu * zu2_rs(jk)
+            END DO
+         END DO
+      END DO
+
+      ! compute the divergence at 160,89 
+      DO jk = 1, 18
+         DO jj = mj0(89), mj1(89) 
+            DO ji = mi0(160), mi1(160) 
+               zvt = e1t(ji, jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e1v(ji, jj-1) * fse3v(ji, jj-1,jk)
+               hdivn(ji, jj,jk) = hdivn(ji, jj,jk) - ( 1. / zvt ) * zsu * zu3_rs(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_bab_el_mandeb
+
+   SUBROUTINE div_gibraltar
+      !! -------------------------------------------------------------------
+      !!                 ***  ROUTINE div_gibraltar  ***
+      !!        
+      !! ** Purpose :   update the now horizontal divergence of the velocity 
+      !!     field in Gibraltar.
+      !!
+      !! ** Method :
+      !!          ________________      N        ________________
+      !! 102           |    |->         |           <-|    |<-
+      !! 101      ___->|____|_____   W - - E     ___->|____|_____
+      !!           139   140  141       |         139   140  141
+      !!          horizontal view       S        horizontal view
+      !!            surface                          depth
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History :
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt
+      REAL(wp) :: zwei
+      REAL(wp), DIMENSION (jpk) ::  zu1_ms, zu2_ms, zu3_ms
+      !!---------------------------------------------------------------------
+      
+      ! EMP on the Mediterranean Sea 
+      ! ----------------------------
+
+      zempmed = 0.e0
+      zwei = 0.e0
+      DO jj = mj0(96), mj1(110)
+         DO ji = mi0(141),mi1(181)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed = zempmed + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+      ! minus 2 points in Red Sea and 3 in Atlantic 
+      DO jj = mj0(96), mj1(96)
+         DO ji = mi0(148),mi1(148)
+            zempmed = zempmed -  emp(ji  , jj) * tmask(ji  , jj,1) * e1t(ji  , jj) * e2t(ji  , jj)   &
+                              -  emp(ji+1, jj) * tmask(ji+1, jj,1) * e1t(ji+1, jj) * e2t(ji+1, jj)   
+         END DO
+      END DO
+
+      ! convert in m3
+      zempmed = zempmed * 1.e-3
+
+      ! Velocity profile at each point
+      ! ------------------------------
+
+      zu1_ms(:) = zu1_ms_i(:)
+      zu2_ms(:) = zu2_ms_i(:)
+      zu3_ms(:) = zu3_ms_i(:)
+
+      ! velocity profile at 139,101 South point 
+      ! we imposed zisw + EMP above the Mediterranean Sea 
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms(jk) =  zu1_ms(jk) + ( zempmed / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+      
+      ! velocity profile at 141,102  East point
+      ! flux in surface inflow of the Atlantic ocean + EMP   
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms(jk) = zu3_ms(jk) +  ( zempmed / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+     
+      ! Divergence at each point of the straits
+      ! ---------------------------------------
+
+      ! compute the new divergence at 139,101 South point  
+      DO jk = 1, jpk
+         DO jj = mj0(101), mj1(101) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               hdivn(ji, jj,jk) = hdivn(ji, jj,jk) + ( 1. / zvt ) * zsu * zu1_ms(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! compute the new divergence at 139,102 deep North point
+      DO jk = 1, jpk
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(139), mi1(139) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji, jj) * fse3u(ji, jj,jk)
+               hdivn(ji, jj,jk) = hdivn(ji, jj,jk) + ( 1. / zvt ) * zsu * zu2_ms(jk) 
+            END DO
+         END DO
+      END DO
+
+      ! compute the divergence at 141,102 East point
+      DO jk = 1, jpk
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(141), mi1(141) 
+               zvt = e1t(ji, jj) * e2t(ji, jj) * fse3t(ji, jj,jk)
+               zsu = e2u(ji-1, jj) * fse3u(ji-1, jj,jk)
+               hdivn(ji, jj,jk) = hdivn(ji, jj,jk) - ( 1. / zvt ) * zsu * zu3_ms(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_gibraltar
+
+   SUBROUTINE div_hormuz
+      !! -------------------------------------------------------------------
+      !!                   ***  ROUTINE div_hormuz  ***
+      !!              
+      !! ** Purpose :   update the now horizontal divergence of the velocity 
+      !!     field in Hormuz ( Persic Gulf strait ) .
+      !!
+      !! ** Method :
+      !!      The now divergence is given by :
+      !!         hdivn = 1/(e1t*e2t) [ di(e2u  un) + dj(e1v  vn) ]
+      !!
+      !! ** History :
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      REAL(wp) :: zsu, zvt     ! temporary scalars
+      !!---------------------------------------------------------------------
+
+      ! New divergence at Hormuz 
+      ! ------------------------
+      DO jk = 1, jpk
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zvt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               zsu = e2u(ji-1,jj) * fse3u(ji-1,jj,jk)
+               hdivn(ji,jj,jk) = hdivn(ji,jj,jk) - ( 1. / zvt ) * zsu * zu_pg(jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_hormuz
+
+
+   SUBROUTINE div_cla_init
+      !! -------------------------------------------------------------------
+      !!                   ***  ROUTINE div_cla_init  ***
+      !!           
+      !! ** Purpose :   Initialization of variables at all straits  
+      !!
+      !! ** History :
+      !!           !         (A. Bozec) Original code 
+      !!      8.5  !  02-10  (A. Bozec) F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER  :: ji, jj, jk   ! dummy loop indices
+      !!---------------------------------------------------------------------
+
+      ! Control print
+      ! -------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'divmod_cross_land : cross land advection on divergence '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*) ' '
+
+      ! Initialization at Bab el Mandeb
+      ! -------------------------------
+
+      ! imposed transport
+      zisw_rs = 0.4e6             ! inflow surface water
+      zurw_rs = 0.2e6             ! upper recirculation water
+!Alex      zbrw = 1.2e6        ! bottom  recirculation water
+      zbrw_rs = 0.5e6             ! bottom  recirculation water
+
+      ! initialization of the velocity
+      zu1_rs_i(:) = 0.e0          ! velocity profile at 161,88 South point
+      zu2_rs_i(:) = 0.e0          ! velocity profile at 161,87 North point
+      zu3_rs_i(:) = 0.e0          ! velocity profile at 160,88 East  point
+
+      ! velocity profile at 161,88 North point 
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  8                                      
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu1_rs_i(jk) = -( zisw_rs / 8. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! recirculation water 
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zu1_rs_i(20) =            - zurw_rs   / ( e2u(ji, jj) * fse3u(ji, jj,20) )
+            zu1_rs_i(21) = -( zbrw_rs - zurw_rs ) / ( e2u(ji, jj) * fse3u(ji, jj,21) )
+         END DO
+      END DO
+      
+      ! velocity profile at 161,87 South point
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zu2_rs_i(21) =  ( zbrw_rs + zisw_rs ) / ( e2u(ji, jj-1 ) * fse3u(ji, jj-1,21) )
+         END DO
+      END DO
+
+      ! velocity profile at 160,88 North  point
+      ! we imposed zisw_rs + EMP above the Red Sea 
+      DO jk = 1,  10                                     
+         DO jj = mj0(88), mj1(88) 
+            DO ji = mi0(160), mi1(160) 
+               zu3_rs_i(jk) = ( zisw_rs / 10. ) / ( e1v(ji, jj) * fse3v(ji, jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      ! deeper
+      DO jj = mj0(88), mj1(88) 
+         DO ji = mi0(160), mi1(160) 
+            zu3_rs_i(16)  = - zisw_rs / ( e1v(ji, jj) * fse3v(ji, jj,16) )
+         END DO
+      END DO
+      
+
+      ! Initialization at Gibraltar
+      ! ---------------------------
+
+      ! imposed transport
+      zisw_ms = 0.8e6             ! inflow surface  water
+      zmrw_ms = 0.7e6             ! middle recirculation water
+      zurw_ms = 2.5e6             ! upper  recirculation water
+      zbrw_ms = 3.5e6             ! bottom recirculation water
+
+      ! initialization of the velocity
+      zu1_ms_i(:) = 0.e0          ! velocity profile at 139,101 South point
+      zu2_ms_i(:) = 0.e0          ! velocity profile at 139,102 North point
+      zu3_ms_i(:) = 0.e0          ! velocity profile at 141,102 East  point
+
+      ! velocity profile at 139,101 South point 
+      DO jk = 1, 14                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_i(jk) =  ( zisw_ms / 14. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! recirculation water 
+      DO jk = 15, 20                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu1_ms_i(jk) =  ( zmrw_ms / 6. ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu1_ms_i(21) =  (           zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,21) )
+            zu1_ms_i(22) =  ( zbrw_ms - zurw_ms ) / ( e2u(ji-1, jj-1) * fse3u(ji-1, jj-1,22) )
+         END DO
+      END DO
+      
+      ! velocity profile at 139,102 North point
+      DO jk = 15, 20                      
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu2_ms_i(jk) = -( zmrw_ms / 6. ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! outflow of Mediterranean sea + recirculation
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu2_ms_i(22) = -( zisw_ms + zbrw_ms ) / ( e2u(ji-1, jj) * fse3u(ji-1, jj,22) )
+         END DO
+      END DO
+      
+      ! velocity profile at 141,102  East point
+      ! flux in surface inflow of the Atlantic ocean    
+      DO  jk = 1, 14                     
+         DO jj = mj0(102), mj1(102) 
+            DO ji = mi0(140), mi1(140) 
+               zu3_ms_i(jk) =  ( zisw_ms / 14. ) / ( e2u(ji, jj) * fse3u(ji, jj,jk) ) 
+            END DO
+         END DO
+      END DO
+
+      ! deeper 
+      DO jj = mj0(102), mj1(102) 
+         DO ji = mi0(140), mi1(140) 
+            zu3_ms_i(21) = - zisw_ms / ( e2u(ji, jj) * fse3u(ji, jj,21) )
+         END DO
+      END DO
+
+      ! Initialization at Hormuz
+      ! ------------------------
+
+      ! imposed transport
+      zisw_pg = 4. * 0.25e6       ! inflow surface  water
+      zbrw_pg = 4. * 0.25e6       ! bottom recirculation water
+
+      ! initialization of the velocity
+      zu_pg(:) = 0.e0           ! velocity profile at 172,94 
+
+      ! velocity profile 
+      DO jk = 1, 8 
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zu_pg(jk) = -( zisw_pg / 8. ) / ( e2u(ji-1,jj) * fse3u(ji-1,jj, jk) )
+            END DO
+         END DO
+      END DO
+
+      DO jk = 16, 18
+         DO jj = mj0(94), mj1(94) 
+            DO ji = mi0(172), mi1(172) 
+               zu_pg(jk) =  ( zbrw_pg / 3. ) / ( e2u(ji-1,jj) * fse3u(ji-1,jj, jk) )
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE div_cla_init
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                            Dummy module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE div_cla( kt )
+      WRITE(*,*) 'div_cla: You should have not see this print! error?', kt
+   END SUBROUTINE div_cla
+#endif
+   
+   !!======================================================================
+END MODULE cla_div
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_dynspg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_dynspg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cla_dynspg.F90	(revision 4536)
@@ -0,0 +1,243 @@
+MODULE cla_dynspg
+   !!======================================================================
+   !!                       ***  cla_dynspg  ***
+   !!======================================================================
+   !!   dyn_spg      : update the momentum trend with the surface pressure
+   !!                  gradient in the free surface constant volume case
+   !!                  with vector optimization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE zdf_oce         ! ocean vertical physics
+   USE obc_oce         ! Lateral open boundary condition
+   USE sol_oce         ! solver variables
+   USE phycst          ! physical constants
+   USE ocesbc          ! ocean surface boundary condition (fluxes)
+   USE flxrnf          ! ocean runoffs
+   USE solpcg          ! preconditionned conjugate gradient solver
+   USE solsor          ! Successive Over-relaxation solver
+   USE solfet          ! FETI solver
+   USE obcdyn          ! ocean open boundary condition (obc_dyn routines)
+   USE obcvol          ! ocean open boundary condition (obc_vol routines)
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distribued memory computing
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC dyn_spg_cla   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dyn_spg_cla( kt ) 
+      !!----------------------------------------------------------------------
+      !!              ***  routine dyn_spg_cross_land  ***
+      !!
+      !! ** Purpose :
+      !!
+      !! ** Method :
+      !!
+      !! ** Action :
+      !!
+      !! History :
+      !!        !         (A. Bozec)  Original code
+      !!   8.5  !  02-11  (A. Bozec)  F90: Free form and module
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      INTEGER  ::   ii0, ii1, ij0, ij1        ! temporary integer
+      REAL(wp) ::    &    
+         zempmed, zempred,   &                ! EMP on Med Sea ans Red Sea
+         zwei,   &                            !              
+         zisw_rs, zurw_rs, zbrw_rs,      &    ! imposed transport Red sea
+         zisw_ms, zurw_ms, zbrw_ms, zmrw_ms   ! imposed transport Med Sea
+      !!----------------------------------------------------------------------
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb...)
+         
+      ! Control print
+      ! -------------
+      IF( kt == nit000 ) THEN 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dynspg_cross_land : cross land advection on surface '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~   pressure '
+         IF(lwp) WRITE(numout,*) ' '
+      ENDIF
+
+      ! EMP on Mediterranean Sea and Red Sea 
+      ! ------------------------------------
+      ! compute the emp in Mediterranean Sea
+      zempmed = 0.e0
+      zwei = 0.e0
+      ij0 =  96   ;   ij1 = 110
+      ii0 = 141   ;   ii1 = 181
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            zwei    = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempmed = zempmed + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempmed )      ! sum with other processors value
+
+      ! minus 2 points in Red Sea and 3 in Atlantic 
+      ij0 =  96   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 148
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            zempmed = zempmed - emp(ji  ,jj) * tmask(ji  ,jj,1) * e1t(ji  ,jj) * e2t(ji  ,jj)   &
+               &              - emp(ji+1,jj) * tmask(ji+1,jj,1) * e1t(ji+1,jj) * e2t(ji+1,jj)   
+         END DO
+      END DO
+      ! we convert in m3
+      zempmed = zempmed * 1.e-3
+
+      ! compute the emp in Red Sea   
+      zempred = 0.e0
+      zwei = 0.e0
+      ij0 =  87   ;   ij1 =  96
+      ii0 = 148   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            zwei      = tmask(ji,jj,1) * e1t(ji,jj) * e2t(ji,jj)
+            zempred   = zempred + emp(ji,jj) * zwei
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( zempred )      ! sum with other processors value
+
+      ! we convert in m3
+      zempred = zempred * 1.e-3
+
+      ! New Transport at Bab el Mandeb and Gibraltar
+      ! --------------------------------------------
+
+      ! imposed transport at Bab el Mandeb
+      zisw_rs = 0.4e6        ! inflow surface water
+      zurw_rs = 0.2e6        ! upper recirculation water
+!!Alex      zbrw_rs = 1.2e6        ! bottom  recirculation water
+      zbrw_rs = 0.5e6        ! bottom  recirculation water
+
+      ! imposed transport at Gibraltar
+      zisw_ms  = 0.8e6          ! atlantic-mediterranean  water
+      zmrw_ms  = 0.7e6          ! middle recirculation water
+      zurw_ms  = 2.5e6          ! upper  recirculation water 
+      zbrw_ms  = 3.5e6          ! bottom recirculation water 
+
+      ! Different velocities for straits ( Gibraltar, Bab el Mandeb )
+      ! -------------------------------------------------------------
+
+      ! Bab el Mandeb
+      ! -------------
+      ! 160,88 north point Bab el Mandeb
+      ij0 =  88   ;   ij1 =  88
+      ii0 = 160   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj  ,: ) = 0.e0  !  North East Bab el Mandeb 
+         END DO
+      END DO
+      !                              ! surface
+      DO jk = 1,  8                                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0),mi1(ii1)
+               ua(ji, jj,jk) = -( ( zisw_rs + zempred ) / 8. ) / ( e2u(ji, jj) * fse3t(ji, jj,jk) )     
+            END DO
+         END DO
+      END DO
+      !                              ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji, jj,21) = - zbrw_rs / ( e2u(ji, jj) * fse3t(ji, jj,21) )
+         END DO
+      END DO
+
+      ! 160,87 south point Bab el Mandeb
+      ij0 =  87   ;   ij1 =  87
+      ii0 = 160   ;   ii1 = 160
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj  ,: ) = 0.e0  !  South East Bab el Mandeb 
+         END DO
+      END DO
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji, jj,21) =  ( zisw_rs + zbrw_rs ) / ( e2u(ji,jj )*fse3t(ji, jj,21) )      
+         END DO
+      END DO
+
+      ! Gibraltar
+      ! ---------
+
+      ! initialisation of velocity at concerned points 
+      ! 139, 101 south point in Gibraltar 
+      ij0 = 101   ;   ij1 = 101
+      ii0 = 139   ;   ii1 = 139
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj  ,: ) = 0.e0  !  South West Gibraltar
+            ua(ji,jj+1,: ) = 0.e0  !  North West Gibraltar
+         END DO
+      END DO
+      !                            ! surface
+      DO jk = 1, 14                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0),mi1(ii1)
+               ua(ji,jj,jk) =  ( ( zisw_ms + zempmed ) / 14. ) / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+      !                            ! middle circulation
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0),mi1(ii1)
+               ua(ji,jj,jk) =  ( zmrw_ms / 6. ) / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+      !                            ! deeper 
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj,21) =             zurw_ms   / ( e2u(ji,jj) * fse3t(ji,jj,21) )
+            ua(ji,jj,22) = ( zbrw_ms - zurw_ms ) / ( e2u(ji,jj) * fse3t(ji,jj,22) )
+         END DO
+      END DO
+
+      ! 139,102 north point in Gibraltar
+      ij0 = 102   ;   ij1 = 102
+      ii0 = 139   ;   ii1 = 139
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj  ,: ) = 0.e0  !  North West Gibraltar
+         END DO
+      END DO
+      DO jk = 15, 20                      
+         DO jj = mj0(ij0), mj1(ij1)
+            DO ji = mi0(ii0),mi1(ii1)
+               ua(ji,jj,jk) = -( zmrw_ms / 6. ) / ( e2u(ji,jj) * fse3t(ji,jj,jk) ) 
+            END DO
+         END DO
+      END DO
+      !                            ! deeper
+      DO jj = mj0(ij0), mj1(ij1)
+         DO ji = mi0(ii0),mi1(ii1)
+            ua(ji,jj,22) = -( zisw_ms + zbrw_ms ) / ( e2u(ji,jj) * fse3t(ji,jj,22) )
+         END DO
+      END DO
+
+   END SUBROUTINE dyn_spg_cla
+
+   !!======================================================================
+END MODULE cla_dynspg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl.F90	(revision 4536)
@@ -0,0 +1,763 @@
+MODULE cpl
+   !!======================================================================
+   !!                       ***  MODULE cpl  ***
+   !! Coupled O/A : coupled ocean-atmosphere case using OASIS
+   !!=====================================================================
+#if defined key_coupled
+   !!----------------------------------------------------------------------
+   !!   'key_coupled'                              coupled Ocean/Atmosphere
+   !!----------------------------------------------------------------------
+   !!   cpl_init     : initialization of coupled mode communication
+   !!   cpl_read     : read the coupled namelist
+   !!   cpl_stp      : exchange fields in coupled mode
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O manager
+   USE cpl_oce         ! coupled exchange variables (???)
+   USE flx_oce         ! in case of ice 
+   USE ocfzpt          ! ocean freezing point
+   USE daymod          ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! Routine accessibility
+   PUBLIC cpl_init     ! routine called in opa module
+   PUBLIC cpl_stp      ! routine called in step module
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE cpl_init( kastp, kexch, kstep )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE cpl_init  ***
+      !!
+      !! ** Purpose :   Initialize coupled mode communication for ocean
+      !!    exchange process identifiers and timestep information
+      !!    between AGCM, OGCM and COUPLER. (OASIS software)
+      !!
+      !! ** Method  :  3 types :
+      !!      a) Use named pipes(FIFO) to exchange process identifiers
+      !!          between the 3 programs
+      !!      b) USE a messag passing method with PVM language (CLIM)
+      !!      c) USE SVIPC method
+      !!
+      !! ** Input   :   npiat     : agcm process identifier
+      !!                npicp     : coupler process identifier
+      !!                npioc     : ogcm process identifier
+      !!
+      !! Reference  :   see Epicoa 0803 (1992)
+      !!
+      !! History :
+      !!        !  92-09  (L. Terray)  Original code
+      !!        !  96-07  (L. Terray)  OASIS version 2
+      !!        !  96-11  (E. Guilyardi)  run-off + Taux,Tauy x2
+      !!        !  98-04  (M.A Foujols, S. Valcke, M. Imbard)  OASIS2.2
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(in ) ::   &
+         kastp,      &  ! total number of timesteps in oceanic model
+         kexch,      &  ! frequency of exchange for the fluxes (in time steps)
+         kstep          ! timestep value (in seconds)
+
+      !! * Local declarations
+      INTEGER,DIMENSION(3)  :: iparal
+      INTEGER               :: ifcpl, idt, info, imxtag, istep
+
+      CHARACTER (len=9) ::   clpoolnam 
+      INTEGER           :: ipoolhandle, ipoolsize, jf
+      CHARACTER (len=3) ::   cljobnam      ! experiment name
+      INTEGER           :: ierror
+!      INTEGER,DIMENSION(4) ::  imess
+      INTEGER,DIMENSION(4) ::  imesso
+      !!----------------------------------------------------------------------
+     
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_init : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+     
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_forced_daily
+      CALL ctl_stop( 'key_coupled and key_flx_bulk_... are incompatible' )
+#endif
+ 
+      CALL cpl_read           ! read the coupled mode information in namelist
+
+      CALL flush(numout)
+
+      ! I- PIPE
+      ! --------
+      ! W A R N I N G : PIPE technique is temporary diseable (nov. 2000)
+
+      IF( cchan == 'PIPE' ) THEN 
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'Making pipes for fields to receive from CPL'
+         IF(lwp) WRITE(numout,*)
+         CALL flush(numout)
+         ierror = 0
+
+         ! loop to define pipes (CPL=atmos to ocean)
+
+         DO jf = 1, nflxc2o  
+            ! CALL PIPE_Model_Define( numout, cpl_readflx(jf), jpread, info )
+            IF( info /= 0 ) ierror = ierror + 1
+         END DO
+         DO jf = 1, ntauc2o
+            ! CALL PIPE_Model_Define( numout, cpl_readtau(jf), jpread, info )
+            IF( info /= 0 ) ierror = ierror + 1
+         END DO
+         
+         IF(lwp) WRITE(numout,*) ' '
+         IF(lwp) WRITE(numout,*) 'Making pipes for fields to send to CPL'
+         IF(lwp) WRITE(numout,*) ' '
+         
+         ! loop to define pipes (ocean to atmos=CPL)
+
+         DO jf = 1, nfldo2c
+            ! CALL PIPE_Model_Define( numout, cpl_writ(jf), jpwrit, info )
+            IF( info /= 0 ) ierror = ierror + 1
+         END DO
+
+         IF( ierror /= 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'cpl_init: end of job due to error in pipes definitions'
+            CALL abort('')
+         END IF
+         
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'All pipes have been made'
+         
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'Communication test between OCE and CPL'
+         CALL flush(numout)
+         
+         ! CALL PIPE_Model_Stepi(numout, imess, nmodcpl, imesso, ierror)
+         
+         IF( ierror /= 0 ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'cpl_init: end of job due to error in exchange first informations with Oasis'
+            CALL abort('')
+         END IF
+         
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'Communication test between OCE and CPL is OK'
+         IF(lwp) WRITE(numout,*) ' total simulation time in oasis = ',imesso(1)
+         IF(lwp) WRITE(numout,*) ' total number of iterations is  = ',imesso(2)
+         IF(lwp) WRITE(numout,*) ' value of oasis timestep  is    = ',imesso(3)
+         IF(lwp) WRITE(numout,*) ' process id for oasis  is       = ',imesso(4)
+         CALL flush(numout)
+         
+         ! II SVIPC
+         ! ---------
+         ! W A R N I N G : SVIPC technique is temporary diseable (nov. 2000)
+         
+         
+      ELSE IF( cchan == 'SIPC' ) THEN
+
+         ! debug for more information
+
+         ! CALL SVIPC_debug(1)
+
+         ! Define the experiment name :
+
+          cljobnam = 'IPC'      ! as $JOBNAM in namcouple
+
+          ! Attach to shared memory pool used to exchange initial infos 
+
+          info = 0
+          ! CALL SIPC_Init_Model (cljobnam, cplmodnam, 1, info)
+          IF( info /= 0 ) THEN 
+             IF(lwp) WRITE(numout,*)
+             IF(lwp) WRITE(numout,*)'WARNING: Problem with attachement to',info 
+             IF(lwp) WRITE(numout,*)'         initial memory pool(s) in ocean'
+             IF(lwp) WRITE(numout,*)
+             CALL abort('STOP in ocean')
+          ENDIF
+
+          ! Attach to pools used to exchange fields from ocean to coupler
+
+          DO jf = 1, nfldo2c
+             ! Pool name:
+             clpoolnam = 'P'//cpl_writ(jf)
+             ! CALL SIPC_Attach(clpoolnam, ipoolhandle)
+             ! Resulting pool handle:
+             mpoolwrit(jf) = ipoolhandle  
+          END DO
+
+          ! Attach to pools used to exchange fields from coupler to ocean
+          
+          DO jf = 1, nflxc2o
+             ! Pool name:
+             clpoolnam = 'P'//cpl_readflx(jf)
+             ! CALL SIPC_Attach(clpoolnam, ipoolhandle)
+             ! Resulting pool handle:
+             mpoolread(jf) = ipoolhandle  
+          END DO  
+
+          DO jf = 1, ntauc2o
+             ! Pool name:
+             clpoolnam = 'P'//cpl_readtau(jf)
+             ! CALL SIPC_Attach(clpoolnam, ipoolhandle)
+             ! Resulting pool handle:
+             mpoolread(jf+nflxc2o) = ipoolhandle  
+          END DO 
+
+          ! Exchange of initial infos
+
+          ! Write data array isend to pool READ by Oasis
+
+          info = 0
+          ipoolsize = 4*jpbyteint
+          ! CALL SVIPC_write(mpoolinitr, imess, ipoolsize, info)
+
+          ! Find error if any
+
+          IF( info < 0 ) THEN
+             IF(lwp) WRITE(numout,*)
+             IF(lwp) WRITE(numout,*) 'Problem in ocean in writing initial' 
+             IF(lwp) WRITE(numout,*) 'infos to the shared memory segment(s)'
+             IF(lwp) WRITE(numout,*)
+          ELSE
+             IF(lwp) WRITE(numout,*)
+             IF(lwp) WRITE(numout,*) 'Initial infos written in ocean'            
+             IF(lwp) WRITE(numout,*) 'to the shared memory segment(s)'
+             IF(lwp) WRITE(numout,*)
+          ENDIF
+
+          ! Read data array irecv from pool written by Oasis
+
+          info = 0
+          ipoolsize = 4 * jpbyteint
+          CALL svipc_read(mpoolinitw, imesso, ipoolsize, info)
+
+          ! Find error if any
+
+          IF( info < 0 ) THEN
+             IF(lwp) WRITE(numout,*) '   '
+             IF(lwp) WRITE(numout,*) 'Problem in ocean in reading initial' 
+             IF(lwp) WRITE(numout,*) 'infos from the shared memory segment(s)'
+             IF(lwp) WRITE(numout,*) '   '
+          ELSE
+             IF(lwp) WRITE(numout,*) '   '
+             IF(lwp) WRITE(numout,*) 'Initial infos read by ocean'                
+             IF(lwp) WRITE(numout,*) 'from the shared memory segment(s)'
+             IF(lwp) WRITE(numout,*) '   '
+             IF(lwp) WRITE(numout,*) ' ntime, niter, nstep, Oasis pid:'
+             IF(lwp) WRITE(numout,*) imesso(1), imesso(2), imesso(3), imesso(4) 
+          ENDIF
+
+          ! Detach from shared memory segment(s)
+
+          info = 0
+          ! CALL SVIPC_close(mpoolinitw, 0, info)
+          
+          ! Find error if any
+
+          IF( info < 0 ) THEN
+             IF(lwp) WRITE(numout,*) 'Problem in detaching from shared memory segment(s)'
+             IF(lwp) WRITE(numout,*) 'used by ocean to read initial infos' 
+          ENDIF
+
+          ! III CLIM
+          ! --------
+
+      ELSE IF( cchan == 'CLIM' ) THEN
+
+         ! Define the number of processors involved in the coupling for
+         ! Oasis (=1) and each model (as last two INTEGER on $CHATYPE line
+         ! in the namcouple); they will be stored in a COMMON in mpiclim.h
+         ! (used for CLIM/MPI2 only)
+         mpi_nproc(0)=1
+         mpi_nproc(1)=1
+         mpi_nproc(2)=1 
+
+         ! Define the number of processors used by each model as in
+         ! $CHATYPE line of namcouple (used for CLIM/MPI2 only)
+         mpi_totproc(1)=1
+         mpi_totproc(2)=1
+         
+         ! Define names of each model as in $NBMODEL line of namcouple
+         ! (used for CLIM/MPI2 only)
+         cmpi_modnam(1)='lmdz.x'
+         cmpi_modnam(2)=cplmodnam
+         !  
+         ! 1.1-Define the experiment name :
+         
+         cljobnam = 'CLI'      ! as $JOBNAM in namcouple
+         
+         OPEN ( UNIT = 7, FILE = 'trace', STATUS = 'unknown', FORM = 'formatted')
+         CALL clim_init ( cljobnam, cplmodnam, 3, 7,   &
+                          kastp, kexch, kstep,   &
+                          5, 3600, 3600, info )
+
+         IF( info /= clim_ok ) THEN
+            IF(lwp) WRITE( numout, *) 'cpl_init : pb init clim, error code is = ', info
+            CALL abort( 'STOP in cpl_init' )
+         ELSE
+            IF(lwp) WRITE(numout,*) 'cpl_init : init clim ok '
+         ENDIF
+         
+         iparal ( clim_strategy ) = clim_serial
+         iparal ( clim_length   ) = jpiglo*jpjglo
+         iparal ( clim_offset   ) = 0
+         
+         ! loop to define messages (CPL=atmos to ocean)
+         DO jf = 1, nflxc2o
+            CALL CLIM_Define ( cpl_readflx(jf), clim_in, clim_double, iparal, info )  
+         END DO
+         DO jf = 1, ntauc2o
+            CALL CLIM_Define ( cpl_readtau(jf), clim_in, clim_double, iparal, info )  
+         END DO
+         
+         ! loop to define messages (ocean to CPL=atmos)
+         DO jf = 1, nfldo2c
+            CALL CLIM_Define ( cpl_writ(jf), clim_out, clim_double, iparal, info )   
+         END DO
+         
+         IF(lwp) WRITE(numout,*) 'cpl_init : clim_define ok '
+         
+         CALL CLIM_Start( imxtag, info )
+         
+         IF( info /= clim_ok ) THEN
+            IF(lwp) WRITE(numout,*) 'cpl_init : pb start clim, error code is = ', info
+            CALL abort( 'stop in cpl_init' )
+         ELSE
+            IF(lwp) WRITE(numout,*) 'cpl_init : start clim ok '
+         ENDIF
+         
+         CALL CLIM_Stepi ( cploasis, istep, ifcpl, idt, info )
+
+         IF( info /= clim_ok ) THEN
+            IF(lwp) WRITE(numout,*) ' warning : problem in getting step info from oasis '
+            IF(lwp) WRITE(numout,*) ' =======   error code number = ', info
+         ELSE
+            IF(lwp) WRITE(numout,*) ' got step information from oasis '
+         ENDIF
+         IF(lwp) WRITE(numout,*) ' number of tstep in oasis ', istep
+         IF(lwp) WRITE(numout,*) ' exchange frequency in oasis ', ifcpl
+         IF(lwp) WRITE(numout,*) ' length of tstep in oasis ', idt
+      ENDIF
+
+   END SUBROUTINE cpl_init
+
+
+   SUBROUTINE cpl_read
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE cpl_read  ***
+      !!                    
+      !! ** Purpose :   Read and print options for the coupled run (namelist)
+      !!
+      !! ** Method  :   ???
+      !!
+      !! History :
+      !!   8.5  !  02-12  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER :: jf
+
+      NAMELIST/namcpl/ nexco, cchan, nmodcpl, cplmodnam, cploasis   &
+          , nfldo2c, nflxc2o, ntauc2o, cpl_f_readflx, cpl_f_readtau   &
+          , cpl_f_writ, cpl_readflx, cpl_readtau, cpl_writ
+      !!----------------------------------------------------------------------
+      
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' cpl_read : read the coupled parameters in namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~'
+      IF(lwp) WRITE(numout,*)
+
+      ! Default values
+      
+      nexco = 24
+      cchan='PIPE'              ! echange TYPE
+      nmodcpl = 2
+      cplmodnam = 'opa.xx'      ! model name : as $NBMODEL in namcouple
+      cploasis = 'Oasis'        ! coupler name : as in coupler
+
+      ! -Define symbolic name for fields exchanged from ocean to coupler,
+      ! must be the same as (1) of the field  definition in namcouple:
+      nfldo2c=2
+      cpl_writ(1)='SOSSTSST'
+      cpl_writ(2)='SOICECOV'
+
+      ! -Define files name for fields exchanged from ocean to coupler,
+      ! must be the same as (6) of the field  definition in namcouple:
+      nflxc2o=6
+      cpl_readflx(1)='SONSFLDO' ! non solar heat flux (positif vers l'ocean)
+      cpl_readflx(2)='SOSHFLDO' ! solar flux
+      cpl_readflx(3)='SOTOPRSU' ! precip
+      cpl_readflx(4)='SOTFSHSU' ! evaporation
+      cpl_readflx(5)='SORUNCOA' ! coastal run-off
+      cpl_readflx(6)='SORIVFLU' ! river run-off
+      ntauc2o=2
+      cpl_readtau(1)='SOZOTAUX' ! first zonal wind stress
+      cpl_readtau(2)='SOZOTAU2' ! second zonal wind stress
+      cpl_readtau(3)='SOMETAUY' ! first meridien wind stress
+      cpl_readtau(4)='SOMETAU2' ! second meridien wind stress
+
+      ! -Define files name for fields exchanged from ocean to coupler,
+      ! must be the same as (6) of the field  definition in namcouple:
+      cpl_f_writ(1)='ocesst'
+      cpl_f_writ(2)='oceice'
+
+      ! -Define files name for fields exchanged from coupler to ocean
+      ! must be the same as (7) of the field  definition in namcouple:
+      cpl_f_readflx(1)='oceflx'
+      cpl_f_readflx(2)='oceflx'
+      cpl_f_readflx(3)='oceflx'
+      cpl_f_readflx(4)='oceflx'
+      cpl_f_readflx(5)='oceflx'
+      cpl_f_readflx(6)='oceflx'
+      cpl_f_readtau(1)='ocetau'
+      cpl_f_readtau(2)='ocetau'
+      cpl_f_readtau(3)='ocetau'
+      cpl_f_readtau(4)='ocetau'
+
+      ! Namelist namcpl : coupling mode and frequency
+      REWIND( numnam )
+      READ  ( numnam, namcpl )
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'namcpl'
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Coupling exchange frequency    nexco  = ',nexco
+         WRITE(numout,*) ' Coupling exchange technique    cchan  = ',cchan
+         WRITE(numout,*) ' Mode Coupling technique      nmodcpl  = ',nmodcpl
+         WRITE(numout,*) ' Define the model name      cplmodnam  = ',cplmodnam
+         WRITE(numout,*) ' Define the coupler name      cploasis = ',cploasis
+         WRITE(numout,*) ' Fields number ocean to coupler nfldo2c= ',nfldo2c
+         WRITE(numout,*) ' Flux fields coupler to ocean nflxc2o  = ',nflxc2o
+         WRITE(numout,*) ' Stress fields coupler to ocean ntauc2o= ',ntauc2o
+         IF ( cchan == 'PIPE' .OR.  cchan == 'pipe' ) THEN
+            cchan='PIPE'
+            WRITE(numout,*)'(communication between models made by pipes)'
+         ELSEIF( cchan == 'CLIM' .OR. cchan == 'clim' ) THEN
+            cchan='CLIM'
+            WRITE(numout,*)'(communication between models made by CLIM-PVM)'
+         ELSEIF( cchan == 'SIPC' .OR. cchan == 'sipc' ) THEN
+            cchan='SIPC'
+            WRITE(numout,*)'(communication between models made by the',  &
+               'Share Memory Segment and Semaphore)'
+         ELSE
+            WRITE(numout,*) 'technic not yet implemented ',cchan
+            STOP 'in cpl_read'
+         ENDIF
+         DO jf = 1, nflxc2o
+            WRITE(numout,*) 'file to receive field number = ',jf,'  ',cpl_f_readflx(jf) 
+         END DO
+         DO jf = 1, ntauc2o
+            WRITE(numout,*) 'file to receive field number = ',jf,'  ',cpl_f_readtau(jf) 
+         END DO
+         DO jf = 1, nfldo2c
+            WRITE(numout,*) 'file to send field number = ',jf,'  ',cpl_f_writ(jf)
+         END DO
+         WRITE(numout,*) ' fields received from coupler'
+         DO jf = 1, nflxc2o
+            WRITE(numout,*) 'symbolic name for field number = ',jf,'  ',cpl_readflx(jf) 
+         END DO
+         DO jf = 1, ntauc2o
+            WRITE(numout,*) 'symbolic name for field number = ',jf,'  ',cpl_readtau(jf) 
+         END DO
+         WRITE(numout,*) ' fields send to coupler'
+         DO jf = 1, nfldo2c
+            WRITE(numout,*) 'symbolic name for field number = ',jf,'  ',cpl_writ(jf)
+         END DO
+      ENDIF
+
+   END SUBROUTINE cpl_read
+
+
+   SUBROUTINE cpl_stp( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE cpl_stp  ***
+      !!                      *****************
+      !!                      * OASIS routine *
+      !!                      *****************
+      !! ** Purpose : - At each coupling time-step,this routine sends fields
+      !!      like sst or ice cover to the coupler.
+      !!              - At each time-step computes time average values 
+      !!              - Specific treatment for the last time-step
+      !!
+      !! ** Method  :   3 types available:
+      !!      a) Use named pipes(FIFO) to exchange process identifiers
+      !!         between the 3 programs
+      !!      b) USE a messag passing method with PVM language (CLIM)
+      !!      c) USE SVIPC method
+      !!
+      !! History :
+      !!        !  92-09 (L. Terray)  Original code
+      !!        !  96-07 (L. Terray)  OASIS version 2
+      !!        !  96-11 (E. Guilyardi)  run-off + Taux,Tauy x2
+      !!        !  98-04 (M.A Foujols, S. Valcke, M. Imbard)  OASIS2.2
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * modules used
+      USE ioipsl
+      USE phycst          ! physical constants
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jn, jf           ! dummy loop indexes
+      INTEGER :: icstep, info, ierror, isize
+      INTEGER :: iflmax, iunmax
+      INTEGER :: ifile(jpmaxfld), ifield(jpmaxfld)
+      CHARACTER (len=8) ::  clfile(jpmaxfld) 
+      LOGICAL :: llfind
+      REAL(wp), DIMENSION(jpiglo,jpjglo) ::    &
+         zstoc, zieoc, zalboc, zticoc
+      
+      ! netcdf outputs
+       
+      CHARACTER (len=80) ::  clcplsnam
+      INTEGER, SAVE ::  nhoridcs, nidcs, ndexcs(1)
+      LOGICAL, SAVE :: lfirsts = .TRUE.
+      REAL(wp) ::    zjulian
+      
+      ! Additions for SVIPC
+      
+      INTEGER  :: index
+!      INTEGER, DIMENSION(3) :: infos
+      CHARACTER (len=3) ::  clmodinf       ! Header or not
+!      CHARACTER (len=3) ::  cljobnam      ! experiment name
+      !!----------------------------------------------------------------------
+
+      ! coupled mode Ocean/Atmosphere
+
+      ! 0. Initialization
+      ! -----------------
+
+      isize = jpiglo * jpjglo
+
+      ! First time step: ocean sst and ice sea-ice extend set to zero
+      IF( kt == nit000 ) THEN
+         sstoc(:,:) = 0.e0
+         sieoc(:,:) = 0.e0
+         alboc(:,:) = 0.e0
+         ticoc(:,:) = 0.e0
+
+         ! initialisation for netcdf outputs
+         ! 
+         ndexcs(:) = 0
+         clcplsnam = "cpl_oce_sst"
+
+         ! Compute julian date from starting date of the run
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
+         CALL histbeg(clcplsnam, jpiglo, glamt, jpjglo, gphit,   &
+            1, jpiglo, 1, jpjglo, 0,   &
+            zjulian, rdt, nhoridcs, nidcs, domain_id=nidom)
+         ! no vertical axis
+         DO jf = 1, nfldo2c
+            CALL histdef(nidcs, cpl_writ(jf),cpl_writ(jf),"-",jpi,    &
+               jpj, nhoridcs, 1, 1, 1, -99, 32, "inst", rdt, rdt)
+         END DO
+         CALL histend(nidcs)
+      ENDIF
+
+      ! 1. Cumulated sst and sea-ice extend
+      !------------------------------------
+
+      sstoc(:,:) = sstoc(:,:) + ( 1.0 - freeze(:,:) ) * ( tn(:,:,1) + rt0 )
+      sieoc(:,:) = sieoc(:,:) + freeze(:,:)
+
+#if defined key_ice_lim
+      alboc(:,:) = alboc(:,:) + freeze(:,:) * alb_ice(:,:)
+      ticoc(:,:) = ticoc(:,:) + freeze(:,:) * tn_ice(:,:) 
+#else
+      alboc(:,:) = alboc(:,:) + freeze(:,:) * 0.8
+      ticoc(:,:) = ticoc(:,:) + freeze(:,:) * ( -10.e0 + rt0 )
+#endif
+
+
+      ! 2. Send coupling fields to OASIS
+      !---------------------------------
+
+      IF( MOD( kt, nexco ) == 0 ) THEN
+
+         ! 2.1 Average : mean coupling fields
+         zstoc (:,:) = 0.e0
+         zieoc (:,:) = 0.e0
+         zalboc(:,:) = 0.e0
+         zticoc(:,:) = 0.e0
+         DO jj = 1, nlcj
+            DO ji = 1, nlci
+               zstoc (mig(ji),mjg(jj)) = sstoc(ji,jj) / FLOAT( nexco )
+               zieoc (mig(ji),mjg(jj)) = sieoc(ji,jj) / FLOAT( nexco )
+               zalboc(mig(ji),mjg(jj)) = alboc(ji,jj) / FLOAT( nexco )
+               zticoc(mig(ji),mjg(jj)) = ticoc(ji,jj) / FLOAT( nexco )
+            END DO
+         END DO
+         icstep = kt - nit000 + 1
+
+         WRITE(numout,*)
+         WRITE(numout,*) 'STEP: Send fields to CPL with kt= ', kt
+         WRITE(numout,*)
+
+         ! outputs
+
+         CALL histwrite( nidcs, cpl_writ(1), kt, zstoc , jpi*jpj, ndexcs )
+         CALL histwrite( nidcs, cpl_writ(2), kt, zieoc , jpi*jpj, ndexcs )
+         CALL histwrite( nidcs, cpl_writ(3), kt, zalboc, jpi*jpj, ndexcs )
+         CALL histwrite( nidcs, cpl_writ(4), kt, zticoc, jpi*jpj, ndexcs )
+         CALL histsync ( nidcs )
+
+         ! 2.2 Last time step (clim or pipe) or pipe mode
+         ! 
+         IF( kt == nitend .OR. cchan == 'PIPE' ) THEN 
+
+            ! finalize outputs
+
+            CALL histclo( nidcs )
+
+            ! WRITE fields for coupler with pipe technique or for last time step
+
+            ! initialisation
+
+            iflmax =  1
+            iunmax = 99
+            
+            clfile(iflmax) = cpl_f_writ(iflmax)     ! keeps first file name
+            ifile(iflmax) = iunmax                  ! keeps first file unit
+            iunmax = iunmax - 1                     ! decrements file unit maximum
+            ifield(1) = ifile(iflmax)               ! keeps file unit for field
+
+            ! different files names counter
+            DO jf = 2, nfldo2c
+               llfind = .FALSE.
+               DO jn = 1, iflmax
+                  IF( .NOT. llfind ) THEN
+                     IF( cpl_f_writ(jf) == clfile(jn) ) THEN
+                        ifield(jf) = ifile(jn)      ! keep file unit for field
+                        llfind = .TRUE.
+                     ENDIF
+                  END IF
+               END DO
+               IF( .NOT. llfind) THEN
+                  iflmax = iflmax + 1               ! increment the number of different files
+                  clfile(iflmax) = cpl_f_writ(jf)   ! keep file name
+                  ifile (iflmax) = iunmax           ! keep file unit for file
+                  ifield(jf) = ifile(iflmax)        ! keep file unit for field
+                  iunmax = iunmax-1                 ! decrement unit maximum number from 99 to 98...
+               ENDIF
+            END DO
+            !          
+            DO jn = 1, iflmax 
+               OPEN (ifile(jn), FILE=clfile(jn), FORM='UNFORMATTED')
+            END DO
+            !              
+            DO jf = 1, nfldo2c
+               IF( jf == 1 ) CALL locwrite(cpl_writ(jf),zstoc , isize, ifield(jf), ierror, numout) 
+               IF( jf == 2 ) CALL locwrite(cpl_writ(jf),zieoc , isize, ifield(jf), ierror, numout) 
+               IF( jf == 3 ) CALL locwrite(cpl_writ(jf),zalboc, isize, ifield(jf), ierror, numout) 
+               IF( jf == 4 ) CALL locwrite(cpl_writ(jf),zticoc, isize, ifield(jf), ierror, numout) 
+            END DO
+
+            ! simulate a FLUSH
+
+            DO jn = 1, iflmax 
+               CLOSE( ifile(jn) )
+            END DO
+
+            ! Clim mode
+            IF( cchan == 'CLIM' ) THEN  ! inform PVM daemon, I have finished
+               CALL CLIM_Quit( CLIM_ContPvm, info )
+               IF( info /= CLIM_Ok ) THEN
+                  WRITE (6, *) 'An error occured while leaving CLIM. Error = ',info
+               ENDIF
+            ENDIF
+
+         ENDIF
+
+         ! IF last we have finished if not pass info to the atmosphere
+
+         IF ( kt /= nitend ) THEN
+
+            ! 2.3 normal exchange
+
+            ! PIPE mode      
+            IF( cchan == 'PIPE' ) THEN 
+
+               ! Send message to pipes for CPL=atmosphere
+
+               ! DO jf = 1, nfldo2c
+               !    CALL PIPE_Model_Send(cpl_writ(jf), icstep, numout)
+               ! END DO 
+
+               ! SIPC mode
+            ELSE IF( cchan == 'SIPC' ) THEN
+
+               ! Define IF a header must be encapsulated within the field brick :
+               clmodinf = 'NOT'  ! as $MODINFO in namcouple  
+
+               ! IF clmodinf = 'YES', define encapsulated infos to be exchanged
+               !    infos(1) = initial date
+               !    infos(2) = timestep
+               !    infos(3) = actual time
+               !
+               ! Writing of output field SST SOSSTSST
+               !
+               ! Index of SST in total number of fields jpfldo2a: 
+               index = 1
+               !
+               ! CALL SIPC_Write_Model(index, isize, clmodinf, cljobnam, infos, zstoc)
+               !
+               ! Writing of output field Sea-Ice SOICECOV 
+               !
+               ! Index of sea-ice in total number of fields jpfldo2a: 
+               index = 2
+               !
+               ! CALL SIPC_Write_Model(index, isize, clmodinf, cljobnam, infos, zieoc)
+   
+               ! CLIM mode
+            ELSE IF( cchan == 'CLIM' ) THEN
+   
+               DO jn = 1, nfldo2c
+   
+                  IF (jn == 1) CALL CLIM_Export(cpl_writ(jn), icstep, zstoc , info)
+                  IF (jn == 2) CALL CLIM_Export(cpl_writ(jn), icstep, zieoc , info)
+                  IF (jn == 3) CALL CLIM_Export(cpl_writ(jn), icstep, zalboc, info)
+                  IF (jn == 4) CALL CLIM_Export(cpl_writ(jn), icstep, zticoc, info)
+
+                  IF (info /= CLIM_Ok) THEN
+                     WRITE (numout,*) 'STEP : Pb giving', cpl_writ(jn), ':', jn
+                     WRITE (numout,*) ' at timestep = ', icstep, 'kt = ', kt
+                     WRITE (numout,*) 'Clim error code is = ',info
+                     WRITE (numout,*) 'STOP in stpcpl '
+                     CALL abort(' stpcpl ')
+                  ENDIF
+               END DO
+            ENDIF
+
+            ! reset cumulative sst and sea-ice extend to zero
+            sstoc(:,:) = 0.e0
+            sieoc(:,:) = 0.e0
+            alboc(:,:) = 0.e0
+            ticoc(:,:) = 0.e0
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE cpl_stp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case           Dummy module         forced Ocean/Atmosphere
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE cpl_init            ! Dummy routine
+      WRITE(*,*) 'cpl_init: You should have not see this print! error?'
+   END SUBROUTINE cpl_init
+   SUBROUTINE cpl_stp( kt )       ! Dummy routine
+      WRITE(*,*) 'cpl_stp: You should have not see this print! error?', kt
+   END SUBROUTINE cpl_stp
+#endif
+
+   !!======================================================================
+END MODULE cpl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/cpl_oce.F90	(revision 4536)
@@ -0,0 +1,283 @@
+MODULE cpl_oce
+   !!======================================================================
+   !!                   ***  MODULE  cpl_oce  ***
+   !! Ocean coupling:  ocean-atmosphere-sea ice coupled exchanges 
+   !!=====================================================================
+#if defined key_coupled
+   !!----------------------------------------------------------------------
+   !!   'key_coupled'                              Coupled Ocean/Atmosphere
+   !!----------------------------------------------------------------------
+   !! ** Purpose :   Atmosphere/Ice/Ocean Coupling
+   !!      GASTON TEAM (CERFACS, Meteo-France, LMD, LSCE, IPSL, LODYC)
+   !!
+   !! history :
+   !!  8.0   ! 08-98  (M.A. Foujols, M. Imbard)  Original code
+   !!  8.5   ! 06/02  (G. Madec)  modules
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+
+   IMPLICIT NONE
+
+   !! ---------------------------------------------------------------------
+   !! Ocean/Ice/Atmosphere Coupling
+   !! -----------------------------
+   LOGICAL, PUBLIC, PARAMETER :: lk_cpl = .TRUE.   !: coupled flag
+
+   INTEGER, PARAMETER ::   &  !:  
+      jpmaxfld = 40           !: Number of maximum fields exchange betwwen
+      !                       ! the ocean and the coupler
+
+   !!---------------------------------------------------------------------
+   !! SIPC Method   (L. Terray, S. Valcke, CERFACS)
+   !! -----------
+
+   INTEGER, PARAMETER ::   &  !:
+      jpbyteint = 4,       &  !: number of bytes per integer
+      jpbyterea = 8,       &  !: number of bytes per real
+      jpbytecha = 1           !: number of bytes per character  
+
+   INTEGER, PARAMETER ::   &  !:
+      jptest = 100            !: The models will test during 2*jptest 
+      !                       ! seconds if the file DUMMY_SIPC has been
+      !                       ! created by OASIS, signaling that the
+      !                       ! SHM pools are opened. After, it aborts.
+
+   !!---------------------------------------------------------------------
+   !! PIPE Method   (L. Terray, CERFACS)
+   !! -----------
+
+   INTEGER, PARAMETER ::   &  !:
+      jpread = 0,          &  !: 
+      jpwrit = 1              !: 
+
+   !!---------------------------------------------------------------------
+   !! Messag Passing Method (CLIM)
+   !! ----------------------------
+!!!INCLUDE '../../CPL/include/clim.h90'
+!!
+!! -- clim.h   18-08-95   Version 2.0   Author: Laurent Terray
+!!    ******
+!!             26-10-99   Version 2.4   Jean Latour (F.S.E.) MPI-2 support
+!!
+!!   clim.h90  13-08-04  Change to F90 C. Levy
+!!@
+!!@  Contents : variables related to the CLIM library
+!!@  --------
+!!@ For complete definition, see the CLIM manual
+!!@
+      INTEGER (kind=4)	CLIM_MaxMod,    CLIM_MaxPort,  CLIM_MaxSegments, &
+               CLIM_MaxTag, &
+               CLIM_MaxLink, &
+               CLIM_ParSize, & 
+               CLIM_Clength, &
+               CLIM_MaxCodes
+!!
+      INTEGER (kind=4) CLIM_Void
+!!
+      INTEGER (kind=4) CLIM_In,	CLIM_Out,	CLIM_InOut
+!!
+      INTEGER (kind=4) CLIM_Strategy,  CLIM_Segments,  &
+               CLIM_Serial,    CLIM_Length,    CLIM_Orange, &
+               CLIM_Apple,     CLIM_Offset, &
+               CLIM_Box,	CLIM_SizeX,	CLIM_SizeY, &
+               CLIM_LdX
+!!
+      INTEGER  (kind=4)CLIM_Integer,	CLIM_Real,	CLIM_Double
+!!
+      INTEGER  (kind=4)CLIM_StopPvm,   CLIM_ContPvm
+!!
+      INTEGER (kind=4)	CLIM_Ok
+      INTEGER (kind=4) CLIM_FastExit, 	CLIM_BadName, 	CLIM_BadPort, &
+               CLIM_BadType, 	CLIM_DoubleDef, CLIM_NotStep, &
+               CLIM_IncStep, 	CLIM_IncSize, 	CLIM_NotClim, &
+               CLIM_TimeOut, &
+               CLIM_Pvm, 	CLIM_FirstCall, CLIM_PbRoute, &
+               CLIM_Group, 	CLIM_BadTaskId, CLIM_NoTask, &
+               CLIM_InitBuff, 	CLIM_Pack, 	CLIM_Unpack, &
+               CLIM_Down, 	CLIM_PvmExit
+!!
+      INTEGER (kind=4) CLIM_jpmax, 	CLIM_jpmx8, 	CLIM_Mpi
+!!
+!!-----Parameter sizes
+!!
+      PARAMETER ( CLIM_Void    = 0  )
+      PARAMETER ( CLIM_MaxMod  = 8 )
+      PARAMETER ( CLIM_MaxPort = 50 )
+      PARAMETER ( CLIM_MaxSegments = 50 )
+      PARAMETER ( CLIM_MaxLink = CLIM_MaxMod * CLIM_MaxPort )
+      PARAMETER ( CLIM_ParSize = 2*CLIM_MaxSegments+2 )
+      PARAMETER ( CLIM_MaxTag  = 16777215 )
+      PARAMETER ( CLIM_Clength = 32 )
+!!
+!!-----Dimension of buffer for packing / unpacking messages with MPI
+!!     (must be equal to jpmax of Oasis)
+!!
+      PARAMETER ( CLIM_jpmax = 400000 )
+      PARAMETER ( CLIM_jpmx8 = CLIM_jpmax*8 )
+!!
+!!-----Ports status
+!!
+      PARAMETER ( CLIM_In      = 1 )
+      PARAMETER ( CLIM_Out     = 0 )
+      PARAMETER ( CLIM_InOut   = 2 )
+!!
+!!-----Parallel distribution
+!!
+      PARAMETER ( CLIM_Strategy = 1 )
+      PARAMETER ( CLIM_Segments = 2 )
+      PARAMETER ( CLIM_Serial   = 0 )
+      PARAMETER ( CLIM_Apple    = 1 )
+      PARAMETER ( CLIM_Box      = 2 )
+      PARAMETER ( CLIM_Orange   = 3 )
+      PARAMETER ( CLIM_Offset   = 2 )
+      PARAMETER ( CLIM_Length   = 3 )
+      PARAMETER ( CLIM_SizeX    = 3 )
+      PARAMETER ( CLIM_SizeY    = 4 )
+      PARAMETER ( CLIM_LdX      = 5 )
+!!
+!!-----Datatypes
+!!
+      PARAMETER ( CLIM_Integer = 1 )
+      PARAMETER ( CLIM_Real    = 4 ) 
+      PARAMETER ( CLIM_Double  = 8 )
+!!
+!!-----Quit parameters
+!!
+      PARAMETER ( CLIM_ContPvm = 0 )
+      PARAMETER ( CLIM_StopPvm = 1 )
+!!
+!!-----Error Codes
+!!
+      PARAMETER ( CLIM_MaxCodes  = -22 )
+!!
+      PARAMETER ( CLIM_Ok	 = 0 )
+      PARAMETER ( CLIM_FastExit  = -1 )
+      PARAMETER ( CLIM_BadName   = -2 )
+      PARAMETER ( CLIM_BadPort   = -3 )
+      PARAMETER ( CLIM_BadType   = -4 )
+      PARAMETER ( CLIM_DoubleDef = -5 )
+      PARAMETER ( CLIM_NotStep   = -6 )
+      PARAMETER ( CLIM_IncStep   = -7 )
+      PARAMETER ( CLIM_IncSize   = -8 )
+      PARAMETER ( CLIM_NotClim   = -9 )
+      PARAMETER ( CLIM_TimeOut   = -10 )
+      PARAMETER ( CLIM_Pvm       = -11 )
+      PARAMETER ( CLIM_FirstCall = -12 )
+      PARAMETER ( CLIM_PbRoute   = -13 )
+      PARAMETER	( CLIM_Group     = -14 )
+      PARAMETER ( CLIM_BadTaskId = -15 )
+      PARAMETER ( CLIM_NoTask    = -16 )
+      PARAMETER ( CLIM_InitBuff  = -17 )
+      PARAMETER ( CLIM_Pack      = -18 )
+      PARAMETER ( CLIM_Unpack    = -19 )
+      PARAMETER ( CLIM_Down      = -20 )
+      PARAMETER ( CLIM_PvmExit   = -21 )
+      PARAMETER ( CLIM_Mpi       = -22 )
+
+!!
+!     --- end of clim.h90
+!!!END-----------------------------------------------------------------
+
+!!!INCLUDE '../../CPL/include/mpiclim.h90'
+!!
+!! -- mpiclim.h  26-10-99   Version 2.4   Author: Jean Latour (F.S.E.)
+!!    *********
+!!    mpiclim.h90 13-08-04 change to F90 C. Levy
+!!@
+!!@  Contents : variables related to MPI-2 message passing
+!!@  --------
+!!@
+!!@ -- mpi_totproc: number of processors on which to launch each model
+!!@
+!!@ -- mpi_nproc: number of processors involved in the coupling for
+!!@               each model
+!!@ -- cmpi_modnam: models name
+!!     -----------------------------------------------------------------
+!!
+      INTEGER (kind=4) mpi_totproc(1:CLIM_MaxMod-1),mpi_nproc(0:CLIM_MaxMod-1)
+!!
+      CHARACTER (len=6) cmpi_modnam(1:CLIM_MaxMod-1)
+!!
+      common/CLIM_mpiclim/mpi_totproc, mpi_nproc, cmpi_modnam 
+!!
+!!!END-----------------------------------------------------------------
+
+
+   !!----------------------------------------------------------------------
+   !!  Atmosphere/Ice/Ocean Coupling
+   !!---------------------------------
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   &   !: data from an atmospheric model
+      qc  ,       &  !: total surf. total heat flux (wm-2)
+      ec  ,       &  !: surface water flux (kg m-2s-1)
+      qsrc           !: solar radiation (w m-2)
+
+#  if defined key_ice_lim
+   REAL(wp), DIMENSION(jpi,jpj) ::   &  !:
+      watm        ,    &  !:
+      tatm        ,    &  !:
+      hatm        ,    &  !:
+      vatm        ,    &  !:
+      catm                !:
+#  endif
+
+   !! Coupling
+
+   INTEGER ::          &  !:
+      npioc       ,    &  !: process-id of ocean PROGRAM
+      nexco       ,    &  !: exchange frequency for fluxes
+      nmodcpl     ,    &  !: coupling mode
+      nflxc2o     ,    &  !: fluxes field number coupler to ocean
+      ntauc2o     ,    &  !: stress field number coupler to ocean
+      nfldo2c             !: surface field number ocean to coupler
+
+   CHARACTER(len=4) ::   cchan       !: type of message passing (pipe or clim) 
+   CHARACTER(len=6) ::   cplmodnam   !: model name
+   CHARACTER(len=5) ::   cploasis    !: coupler name
+
+   CHARACTER(len=8), DIMENSION(jpmaxfld) ::   &  !:
+      cpl_f_readflx,   &  !: coupler to ocean file name for flx.coupled
+      cpl_f_readtau,   &  !: coupler to ocean file name for tau.coupled
+      cpl_f_writ   ,   &  !: ocean to coupler file name for cpl_stp
+      cpl_readflx  ,   &  !: coupler to ocean field name for flx.coupled
+      cpl_readtau  ,   &  !: coupler to ocean field name for tau.coupled
+      cpl_writ            !: ocean to coupler field name for cpl_stp
+
+  REAL(wp), DIMENSION(jpi,jpj) ::   &  !:
+      sstoc,     &  !: work array to average sst
+      sieoc,     &  !: work array to average Ice index
+      alboc,     &  !: work array to average Ice Albedo
+      ticoc         !: work array to average Ice temperature
+
+
+   !! -- inc_sipc.h   97-08-11   Version 2.0   Author: S&A
+   !!    **********
+   !! variables describing pools formed of shared memory segments 
+
+   INTEGER ::   &  !:
+      mpoolinitr,  &  !: handles associated to model pools for passing
+      mpoolinitw      !: initial info (r=read, w=write)
+
+   INTEGER, DIMENSION(jpmaxfld) ::   &  !:
+      mpoolwrit,   &  !: handles associated to pools used to pass fields
+      !               !  exchanged from model to coupler 
+      !               !  (see libsipc/SIPC_Write_Model.f)
+      mpoolread       !: handles associated to pools used to pass fields
+      !               !  exchanged from model to coupler
+      !               !  (see libsipc/SIPC_Read_Model.f)
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case                                Forced Ocean/Atmosphere
+   !!----------------------------------------------------------------------
+   !!   Empty module
+   LOGICAL, PUBLIC, PARAMETER :: lk_cpl = .FALSE.   !: coupled flag
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE cpl_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ctlopn.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ctlopn.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ctlopn.F90	(revision 4536)
@@ -0,0 +1,171 @@
+   SUBROUTINE ctlopn ( knum, cdfile, cdstat, cdform, cdacce,   &
+                       klengh, kout, ldwp, krequ )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctlopn  ***
+      !!
+      !! ** Purpose :   Open file and check if required file is available.
+      !!
+      !! ** Method  :   Fortan open
+      !!
+      !! History :
+      !!        !  95-12  (G. Madec)  Original code
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+#if defined key_agrif
+      USE Agrif_Util
+#endif
+      USE in_out_manager
+      IMPLICIT NONE
+
+      INTEGER, INTENT( out ) ::   &
+         knum      ! logical unit to open
+      INTEGER, INTENT( in ) ::   &
+         krequ,    & ! =1 file required (stop if not exist)
+         !           ! =0 file not required (create the file if does not exist)
+         kout,     & ! number of logical units for write
+         klengh      ! record length
+      CHARACTER (len=* ), INTENT( in ) ::   &
+         cdacce,   & ! access specifier
+         cdform,   & ! formatting specifier
+         cdstat      ! disposition specifier
+#if !defined key_agrif
+      CHARACTER (len=* ), INTENT( in ) ::   &
+         cdfile      ! file name to open
+#else
+      CHARACTER (len=* ), INTENT( inout ) ::   &
+         cdfile      ! file name to open
+#endif
+
+      INTEGER ::   iost
+      LOGICAL ::  ldwp   ! boolean term for print
+
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+#if defined key_agrif
+      if ( .NOT. Agrif_Root() ) then
+         cdfile= TRIM(Agrif_CFixed())//'_'//TRIM(cdfile)
+      endif
+        knum=Agrif_Get_Unit()
+#else
+        knum=getunit()
+#endif
+
+      ! 1. Required file
+      ! ----------------
+
+      IF( krequ == 1 ) THEN
+
+         iost=0
+         IF( cdacce(1:6) == 'DIRECT' )  THEN
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
+         ELSE
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, ERR=100, IOSTAT=iost)
+         ENDIF
+         IF( iost == 0 ) THEN
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' 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: ', cdfile
+               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 'ctlopn bad opening'
+         ENDIF
+         
+         
+         ! 2. Not required, file create if not exist
+         ! -----------------------------------------
+         
+      ELSEIF( krequ == 0 ) THEN
+
+         iost = 0
+         IF( cdacce(1:6) == 'DIRECT' ) THEN
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, RECL=klengh, ERR=200, IOSTAT=iost )
+         ELSE
+            OPEN( UNIT=knum, FILE=cdfile, FORM=cdform, ACCESS=cdacce,   &
+               STATUS=cdstat, ERR=200, IOSTAT=iost )
+         ENDIF
+         IF(iost == 0) THEN
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' open ok'
+               WRITE(kout,*) '     unit   = ', knum
+               WRITE(kout,*) '     status = ', cdstat
+               WRITE(kout,*) '     form   = ', cdform
+               WRITE(kout,*) '     access = ', cdacce
+               WRITE(kout,*)
+            ENDIF
+         ENDIF
+200      CONTINUE
+         IF( iost /= 0 ) THEN
+            iost = 0
+            IF(ldwp) THEN
+               WRITE(kout,*)
+               WRITE(kout,*) '     ===>>>> : file ', cdfile,   &
+                  ' does not exist: it is created'
+               WRITE(kout,*) ' =======   ===  '
+            ENDIF
+            IF( cdacce(1:6) == 'DIRECT' ) THEN
+               OPEN( UNIT=knum, FILE=cdfile, FORM=cdform,   &
+                  ACCESS=cdacce, STATUS=cdstat,   &
+                  RECL=klengh, ERR=210, IOSTAT=iost )
+            ELSE
+               OPEN( UNIT=knum, FILE=cdfile, FORM=cdform,   &
+                  ACCESS=cdacce, STATUS=cdstat, ERR=210,   &
+                  IOSTAT=iost )
+            ENDIF
+            IF(ldwp) THEN
+               WRITE(kout,*) '     file   : ', cdfile,' open ok'
+               WRITE(kout,*) '     unit   = ', knum
+               WRITE(kout,*) '     status = ', cdstat
+               WRITE(kout,*) '     form   = ', cdform
+               WRITE(kout,*) '     access = ', cdacce
+               WRITE(kout,*)
+            ENDIF
+210         CONTINUE
+            IF( iost /= 0 ) THEN
+               IF(ldwp) THEN
+                  WRITE(kout,*) ' logical unit ',knum,' iostat = ', iost
+                  WRITE(kout,*) ' we stop. verify the file ', cdfile
+                  WRITE(kout,*)
+               ENDIF
+               STOP '001'
+            ENDIF
+         ENDIF
+         
+      ELSE
+         
+         IF(ldwp) THEN
+            WRITE(kout,*)
+            WRITE(kout,*) ' ctlopn : invalid option, krequ = ', krequ
+            WRITE(kout,*) ' ~~~~~~   call for file ', cdfile
+            WRITE(kout,*)
+         ENDIF
+
+
+         STOP 'ctlopn invalid option'
+      ENDIF
+      
+   END SUBROUTINE ctlopn
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/daymod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/daymod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/daymod.F90	(revision 4536)
@@ -0,0 +1,165 @@
+MODULE daymod
+   !!======================================================================
+   !!                       ***  MODULE  daymod  ***
+   !! Ocean        :  calendar 
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   day        : calendar
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC day        ! called by step.F90
+
+   !! * Shared module variables
+   INTEGER , PUBLIC ::   &  !:
+      nyear     ,   &  !: current year
+      nmonth    ,   &  !: current month
+      nday      ,   &  !: current day of the month
+      nday_year ,   &  !: curent day counted from jan 1st of the current year
+      ndastp           !: time step date in year/month/day aammjj
+   REAL(wp), PUBLIC ::   &  !:
+       adatrj   ,   &  !: number of elapsed days since the begining of the run
+       adatrj0         !: value of adatrj at nit000-1 (before the present run).
+       !               !  it is the accumulated duration of previous runs
+       !               !  that may have been run with different time steps.
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE day( kt )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE day  ***
+      !! 
+      !! ** Purpose :   Compute the date with a day iteration IF necessary.
+      !!
+      !! ** Method  : - ???
+      !!
+      !! ** Action  : - nyear     : current year
+      !!              - nmonth    : current month of the year nyear
+      !!              - nday      : current day of the month nmonth
+      !!              - nday_year : current day of the year nyear
+      !!              - ndastp    : =nyear*10000+nmonth*100+nday
+      !!              - adatrj    : date in days since the beginning of the run
+      !!
+      !! History :
+      !!        !  94-09  (M. Pontaud M. Imbard)  Original code
+      !!        !  97-03  (O. Marti)
+      !!        !  97-05  (G. Madec) 
+      !!        !  97-08  (M. Imbard)
+      !!   9.0  !  03-09  (G. Madec)  F90 + nyear, nmonth, nday
+      !!        !  04-01  (A.M. Treguier) new calculation based on adatrj
+      !!----------------------------------------------------------------------      
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step indices
+
+      !! * Local declarations
+      INTEGER  ::   js                   ! dummy loop indice
+      INTEGER  ::   iend, iday0, iday1   ! temporary integers
+      REAL(wp) :: zadatrjn, zadatrjb     ! adatrj at timestep kt-1 and kt-2 
+      CHARACTER (len=25) :: charout
+      !!----------------------------------------------------------------------
+
+      ! 0.  initialization of adatrj0 and nday, nmonth,nyear, nday_year.
+      !     ndastp has been initialized in domain.F90 or restart.F90
+      !-----------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+
+         IF( .NOT.ln_rstart )   adatrj0 = 0.e0      ! adatrj0 initialized in rst_read when restart 
+
+         adatrj  = adatrj0
+         nyear   =   ndastp / 10000
+         nmonth  = ( ndastp - (nyear * 10000) ) / 100
+         nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
+
+         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
+         nday_year =  nday
+         !                               ! accumulates days of previous months of this year
+         DO js = 1, nmonth-1
+            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+               nday_year = nday_year + nbiss(js)
+            ELSE
+               nday_year = nday_year + nobis(js)
+            ENDIF
+         END DO
+
+      ENDIF
+
+      ! I.  calculates adatrj, zadatrjn, zadatrjb.
+      ! ------------------------------------------------------------------
+
+      adatrj    = adatrj0 + ( kt - nit000 + 1 ) * rdttra(1) / rday
+      zadatrjn  = adatrj0 + ( kt - nit000     ) * rdttra(1) / rday
+      zadatrjb  = adatrj0 + ( kt - nit000 - 1 ) * rdttra(1) / rday
+
+
+      ! II.  increment the date.  The date corresponds to 'now' variables (kt-1),
+      !      which is the time step of forcing fields. 
+      !      Do not do this at nit000  unless nrstdt= 2
+      !      In that case ndastp (read in restart) was for step nit000-2
+      ! -------------------------------------------------------------------
+
+      iday0 = INT( zadatrjb )
+      iday1 = INT( zadatrjn )
+
+      IF( iday1 - iday0 >= 1 .AND. ( kt /= nit000 .OR. nrstdt == 2 ) ) THEN
+
+         ! increase calendar
+         nyear  =   ndastp / 10000
+         nmonth = ( ndastp - (nyear * 10000) ) / 100
+         nday   =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
+         nday = nday + 1
+         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+            iend = nbiss(nmonth)
+         ELSEIF( nleapy > 1 ) THEN 
+            iend = nleapy
+         ELSE 
+            iend = nobis(nmonth)
+         ENDIF
+         IF( nday == iend + 1 ) THEN
+            nday  = 1
+            nmonth = nmonth + 1
+            IF( nmonth == 13 ) THEN
+               nmonth  = 1
+               nyear = nyear + 1
+            ENDIF
+         ENDIF
+         ndastp = nyear * 10000 + nmonth * 100 + nday
+
+         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
+         nday_year =  nday
+         !                                ! accumulates days of previous months of this year
+         DO js = 1, nmonth-1
+            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
+               nday_year = nday_year + nbiss(js)
+            ELSE
+               nday_year = nday_year + nobis(js)
+            ENDIF
+         END DO
+
+         IF(lwp) WRITE(numout,*)' ==============>> time-step =', kt, ' New day, DATE= ',   &
+            &                   nyear, '/', nmonth, '/', nday, 'nday_year:', nday_year
+      ENDIF
+
+      IF(ln_ctl) THEN
+         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
+         CALL prt_ctl_info(charout, itime=kt)
+      ENDIF
+
+   END SUBROUTINE day
+
+   !!======================================================================
+END MODULE daymod
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/eosbn2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/eosbn2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/eosbn2.F90	(revision 4536)
@@ -0,0 +1,843 @@
+MODULE eosbn2
+   !!==============================================================================
+   !!                       ***  MODULE  eosbn2  ***
+   !! Ocean diagnostic variable : equation of state - in situ and potential density
+   !!                                               - Brunt-Vaisala frequency 
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   eos            : generic interface of the equation of state
+   !!   eos_insitu     : Compute the in situ density
+   !!   eos_insitu_pot : Compute the insitu and surface referenced potential
+   !!                    volumic mass
+   !!   eos_insitu_2d  : Compute the in situ density for 2d fields
+   !!   eos_bn2        : Compute the Brunt-Vaisala frequency
+   !!   eos_init       : set eos parameters (namelist)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE zdfddm          ! vertical physics: double diffusion
+   USE prtctl          ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Interface 
+   INTERFACE eos
+      MODULE PROCEDURE eos_insitu, eos_insitu_pot, eos_insitu_2d
+   END INTERFACE 
+   INTERFACE bn2
+      MODULE PROCEDURE eos_bn2
+   END INTERFACE 
+
+   !! * Routine accessibility
+   PUBLIC eos        ! called by step.F90, inidtr.F90, tranpc.F90 and intgrd.F90
+   PUBLIC bn2        ! called by step.F90
+   PUBLIC eos_init   ! called by step.F90
+
+   !! * Share module variables
+   INTEGER , PUBLIC ::   &  !: nameos : ocean physical parameters
+      neos      = 0,     &  !: = 0/1/2 type of eq. of state and Brunt-Vaisala frequ.
+      neos_init = 0         !: control flag for initialization
+
+   REAL(wp), PUBLIC ::   &  !: nameos : ocean physical parameters
+      ralpha = 2.0e-4,   &  !: thermal expension coeff. (linear equation of state)
+      rbeta  = 7.7e-4       !: saline  expension coeff. (linear equation of state)
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE eos_insitu ( ptem, psal, prd )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE eos_insitu  ***
+      !! 
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) from 
+      !!       potential temperature and salinity using an equation of state
+      !!       defined through the namelist parameter neos.
+      !!
+      !! ** Method  :   3 cases:
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - ralpha * t
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rbeta * s - ralpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Action  :   compute prd , the in situ density (no units)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!
+      !! History :
+      !!        !  89-03 (o. Marti)  Original code
+      !!        ! 94-08 (G. Madec)
+      !!        !  96-01 (G. Madec) statement function for e3
+      !!        !  97-07 (G. Madec) introduction of neos, OPA8.1
+      !!        !  97-07 (G. Madec) density instead of volumic mass
+      !!        !  99-02 (G. Madec, N. Grima) semi-implicit pressure gradient
+      !!        !  01-09 (M. Ben Jelloul) bugfix   
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                 &  ! potential temperature
+         psal                     ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         prd                      ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   &          
+         zt , zs , zh , zsr,   &  ! temporary scalars
+         zr1, zr2, zr3, zr4,   &  !    "         " 
+         zrhop, ze, zbw, zb,   &  !    "         "
+         zd , zc , zaw, za ,   &  !    "         "
+         zb1, za1, zkw, zk0       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zws                      ! temporary workspace
+      !!----------------------------------------------------------------------
+
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  ! depth
+                  zh = fsdept(ji,jj,jk)
+                  ! square root salinity
+                  zsr= zws(ji,jj,jk)
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! masked in situ density anomaly
+                  prd(ji,jj,jk) = (  zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
+                     - rau0 ) / rau0 * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd(ji,jj,jk) = ( 0.0285 - ralpha * zt ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd(ji,jj,jk) = (   rbeta  * zs - ralpha * zt ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=prd, clinfo1=' eos  : ', ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE eos_insitu
+
+
+   SUBROUTINE eos_insitu_pot ( ptem, psal, prd, prhop)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_pot  ***
+      !!           
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) and the
+      !!      potential volumic mass (Kg/m3) from potential temperature and
+      !!      salinity fields using an equation of state defined through the 
+      !!     namelist parameter neos.
+      !!
+      !! ** Method  :
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!              rhop(t,s)  = rho(t,s,0)
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - ralpha * t
+      !!              rhop(t,s)  = rho(t,s)
+      !!
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0 
+      !!                       = rbeta * s - ralpha * tn - 1.
+      !!              rhop(t,s)  = rho(t,s)
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd  , the in situ density (no units)
+      !!              - prhop, the potential volumic mass (Kg/m3)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!      Brown, J. A. and K. A. Campana. Mon. Weather Rev., 1978
+      !!
+      !! History :
+      !!   4.0  !  89-03  (O. Marti)
+      !!        !  94-08  (G. Madec)
+      !!        !  96-01  (G. Madec) statement function for e3
+      !!        !  97-07  (G. Madec) introduction of neos, OPA8.1
+      !!        !  97-07  (G. Madec) density instead of volumic mass
+      !!        !  99-02  (G. Madec, N. Grima) semi-implicit pressure gradient
+      !!        !  01-09  (M. Ben Jelloul) bugfix   
+      !!   9.0  !  03-08  (G. Madec)  F90, free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,   &  ! potential temperature
+         psal       ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         prd,    &  ! potential density (surface referenced)
+         prhop      ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER  ::  ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zws
+      !!----------------------------------------------------------------------
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         zws(:,:,:) = SQRT( ABS( psal(:,:,:) ) )
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  ! depth
+                  zh = fsdept(ji,jj,jk)
+                  ! square root salinity
+!!Edmee           zsr= SQRT( ABS( zs ) )
+                  zsr= zws(ji,jj,jk)
+                  ! compute volumic mass pure water at atm pressure
+                  zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                     -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+                  ! seawater volumic mass atm pressure
+                  zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt   &
+                     -4.0899e-3 ) *zt+0.824493
+                  zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+                  zr4= 4.8314e-4
+
+                  ! potential volumic mass (reference to the surface)
+                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+                  ! save potential volumic mass
+                  prhop(ji,jj,jk) = zrhop * tmask(ji,jj,jk)
+
+                  ! add the compression terms
+                  ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+                  zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+                  zb = zbw + ze * zs
+
+                  zd = -2.042967e-2
+                  zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+                  zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
+                  za = ( zd*zsr + zc ) *zs + zaw
+
+                  zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+                  za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+                  zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
+                  zk0= ( zb1*zsr + za1 )*zs + zkw
+
+                  ! masked in situ density anomaly
+                  prd(ji,jj,jk) = (  zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
+                     - rau0 ) / rau0 * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd  (ji,jj,jk) = ( 0.0285 - ralpha * zt )        * tmask(ji,jj,jk)
+                  prhop(ji,jj,jk) = ( rau0 * prd(ji,jj,jk) + rau0 ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt = ptem(ji,jj,jk)
+                  zs = psal(ji,jj,jk)
+                  !   ... density and potential volumic mass
+                  prd  (ji,jj,jk) = ( rbeta  * zs - ralpha * zt ) * tmask(ji,jj,jk)
+                  prhop(ji,jj,jk) = ( rau0 * prd(ji,jj,jk) + rau0 )    * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=prd, clinfo1=' eos-p: ', tab3d_2=prhop, clinfo2=' pot : ', ovlap=1, kdim=jpk)
+      ENDIF
+
+   END SUBROUTINE eos_insitu_pot
+
+   SUBROUTINE eos_insitu_2d ( ptem, psal, pdep, prd )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_insitu_2d  ***
+      !!
+      !! ** Purpose :   Compute the in situ density (ratio rho/rau0) from 
+      !!      potential temperature and salinity using an equation of state
+      !!      defined through the namelist parameter neos. * 2D field case
+      !!
+      !! ** Method :
+      !!      neos = 0 : Jackett and McDougall (1994) equation of state.
+      !!         the in situ density is computed directly as a function of
+      !!         potential temperature relative to the surface (the opa t
+      !!         variable), salt and pressure (assuming no pressure variation
+      !!         along geopotential surfaces, i.e. the pressure p in decibars
+      !!         is approximated by the depth in meters.
+      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
+      !!         with pressure                      p        decibars
+      !!              potential temperature         t        deg celsius
+      !!              salinity                      s        psu
+      !!              reference volumic mass        rau0     kg/m**3
+      !!              in situ volumic mass          rho      kg/m**3
+      !!              in situ density anomalie      prd      no units
+      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
+      !!          t = 40 deg celcius, s=40 psu
+      !!      neos = 1 : linear equation of state function of temperature only
+      !!              prd(t) = 0.0285 - ralpha * t
+      !!      neos = 2 : linear equation of state function of temperature and
+      !!               salinity
+      !!              prd(t,s) = rbeta * s - ralpha * tn - 1.
+      !!      Note that no boundary condition problem occurs in this routine
+      !!      as (ptem,psal) are defined over the whole domain.
+      !!
+      !! ** Action  : - prd , the in situ density (no units)
+      !!
+      !! References :
+      !!      Jackett, D.R., and T.J. McDougall. J. Atmos. Ocean. Tech., 1994
+      !!
+      !! History :
+      !!   8.5  !  02-11  (G. Madec, A. Bozec)  partial step
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::   &
+         ptem,                           &  ! potential temperature
+         psal,                           &  ! salinity
+         pdep                               ! depth
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( out ) ::   &
+         prd                                ! potential density (surface referenced)
+
+      !! * Local declarations
+      INTEGER ::  ji, jj                    ! dummy loop indices
+      REAL(wp) ::   &             ! temporary scalars
+         zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw,   &
+         zb, zd, zc, zaw, za, zb1, za1, zkw, zk0,               &
+         zmask
+      REAL(wp), DIMENSION(jpi,jpj) :: zws
+      !!----------------------------------------------------------------------
+
+
+      ! initialization (in not already done)
+      IF( neos_init == 0 ) CALL eos_init
+
+      prd(:,:) = 0.e0
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpjm1
+!CDIR NOVERRCHK
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               zws(ji,jj) = SQRT( ABS( psal(ji,jj) ) )
+            END DO
+         END DO
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+
+               zmask = tmask(ji,jj,1)      ! land/sea bottom mask = surf. mask
+
+               zt = ptem (ji,jj)            ! interpolated T
+               zs = psal (ji,jj)            ! interpolated S
+               zsr= zws(ji,jj)            ! square root of interpolated S
+               zh = pdep(ji,jj)            ! depth at the partial step level
+
+               ! compute volumic mass pure water at atm pressure
+               zr1 = ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt   &
+                         -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
+               ! seawater volumic mass atm pressure
+               zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 )*zt+7.6438e-5 ) *zt   &
+                         -4.0899e-3 ) *zt+0.824493
+               zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
+               zr4= 4.8314e-4
+
+               ! potential volumic mass (reference to the surface)
+               zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
+
+               ! add the compression terms
+               ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
+               zbw= (  1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
+               zb = zbw + ze * zs
+
+               zd = -2.042967e-2
+               zc =   (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
+               zaw= ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt -4.721788
+               za = ( zd*zsr + zc ) *zs + zaw
+
+               zb1=   (-0.1909078*zt+7.390729 ) *zt-55.87545
+               za1= ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
+               zkw= ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt   &
+                         +2098.925 ) *zt+190925.6
+               zk0= ( zb1*zsr + za1 )*zs + zkw
+
+               ! masked in situ density anomaly
+               prd(ji,jj) = ( zrhop / (  1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )  ) - rau0 )   &
+                          / rau0 * zmask
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               prd(ji,jj) = ( 0.0285 - ralpha * ptem(ji,jj) ) * tmask(ji,jj,1)
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jj = 1, jpjm1                                 ! Horizontal slab
+            !                                             ! ===============
+#if defined key_mpp_omp
+            DO ji = 1, jpim1
+#else
+            DO ji = 1, fs_jpim1   ! vector opt.
+#endif
+               prd(ji,jj) = ( rbeta * psal(ji,jj) - ralpha * ptem(ji,jj) ) * tmask(ji,jj,1) 
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   CALL prt_ctl(tab2d_1=prd, clinfo1=' eos2d: ')
+
+   END SUBROUTINE eos_insitu_2d
+
+
+   SUBROUTINE eos_bn2( ptem, psal, pn2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE eos_bn2  ***
+      !!
+      !! ** Purpose :   Compute the local Brunt-Vaisala frequency at the time-
+      !!      step of the input arguments
+      !!      
+      !! ** Method :
+      !!       * neos = 0  : UNESCO sea water properties
+      !!         The brunt-vaisala frequency is computed using the polynomial
+      !!      polynomial expression of McDougall (1987):
+      !!            N^2 = grav * beta * ( alpha/beta*dk[ t ] - dk[ s ] )/e3w
+      !!      If lk_zdfddm=T, the heat/salt buoyancy flux ratio Rrau is
+      !!      computed and used in zdfddm module :
+      !!              Rrau = alpha/beta * ( dk[ t ] / dk[ s ] )
+      !!       * neos = 1  : linear equation of state (temperature only)
+      !!            N^2 = grav * ralpha * dk[ t ]/e3w
+      !!       * neos = 2  : linear equation of state (temperature & salinity)
+      !!            N^2 = grav * (ralpha * dk[ t ] - rbeta * dk[ s ] ) / e3w
+      !!      The use of potential density to compute N^2 introduces e r r o r
+      !!      in the sign of N^2 at great depths. We recommand the use of 
+      !!      neos = 0, except for academical studies.
+      !!        Macro-tasked on horizontal slab (jk-loop)
+      !!      N.B. N^2 is set to zero at the first level (JK=1) in inidtr
+      !!      and is never used at this level.
+      !!
+      !! ** Action  : - pn2 : the brunt-vaisala frequency
+      !!
+      !! References :
+      !!      McDougall, T. J., J. Phys. Oceanogr., 17, 1950-1964, 1987.
+      !!
+      !! History :
+      !!   6.0  !  94-07  (G. Madec, M. Imbard)  Original code
+      !!   8.0  !  97-07  (G. Madec) introduction of statement functions
+      !!   8.5  !  02-07  (G. Madec) Free form, F90
+      !!   8.5  !  02-08  (G. Madec) introduction of arguments
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
+         ptem,                           &  ! potential temperature
+         psal                               ! salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         pn2                               ! Brunt-Vaisala frequency
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   &
+         zgde3w, zt, zs, zh,  &  ! temporary scalars 
+         zalbet, zbeta           !    "         "
+#if defined key_zdfddm
+      REAL(wp) ::   zds          ! temporary scalars
+#endif
+      !!----------------------------------------------------------------------
+      !!  OPA8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      ! pn2 : first and last levels
+      ! ---------------------------
+      ! bn^2=0. at jk=1 and jpk set in inidtr.F : no computation
+
+
+      ! pn2 : interior points only (2=< jk =< jpkm1 )
+      ! -------------------------- 
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk)
+                  zt = 0.5 * ( ptem(ji,jj,jk) + ptem(ji,jj,jk-1) )          ! potential temperature at w-point
+                  zs = 0.5 * ( psal(ji,jj,jk) + psal(ji,jj,jk-1) ) - 35.0   ! salinity anomaly (s-35) at w-point
+                  zh = fsdepw(ji,jj,jk)                                     ! depth in meters  at w-point
+
+                  zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
+                     &                               - 0.203814e-03 ) * zt   &
+                     &                               + 0.170907e-01 ) * zt   &
+                     &   + 0.665157e-01                                      &
+                     &   +     ( - 0.678662e-05 * zs                         &
+                     &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
+                     &   +   ( ( - 0.302285e-13 * zh                         &
+                     &           - 0.251520e-11 * zs                         &
+                     &           + 0.512857e-12 * zt * zt           ) * zh   &
+                     &           - 0.164759e-06 * zs                         &
+                     &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
+                     &                               + 0.380374e-04 ) * zh
+
+                  zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
+                     &                            - 0.301985e-05 ) * zt      &
+                     &   + 0.785567e-03                                      &
+                     &   + (     0.515032e-08 * zs                           &
+                     &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
+                     &   +(  (   0.121551e-17 * zh                           &
+                     &         - 0.602281e-15 * zs                           &
+                     &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
+                     &                             + 0.408195e-10   * zs     &
+                     &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
+                     &                             - 0.121555e-07 ) * zh
+
+                  pn2(ji,jj,jk) = zgde3w * zbeta * tmask(ji,jj,jk)           &   ! N^2 
+                     &          * ( zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )   &
+                     &                     - ( psal(ji,jj,jk-1) - psal(ji,jj,jk) ) )
+#if defined key_zdfddm
+                  !                                                         !!bug **** caution a traiter zds=dk[S]= 0 !!!!
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )                    ! Rrau = (alpha / beta) (dk[t] / dk[s])
+                  IF ( ABS( zds) <= 1.e-20 ) zds = 1.e-20
+                  rrau(ji,jj,jk) = zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  pn2(ji,jj,jk) = zgde3w * ralpha * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         !                                                ! ===============
+         DO jk = 2, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zgde3w = grav / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  pn2(ji,jj,jk) = zgde3w * (  ralpha * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) )   &
+                     &                      - rbeta  * ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )  )
+               END DO
+            END DO
+#if defined key_zdfddm
+            !                                                ! Rrau = (alpha / beta) (dk[t] / dk[s])
+            zalbet = ralpha / rbeta
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zds = ( psal(ji,jj,jk-1) - psal(ji,jj,jk) )
+                  IF ( ABS( zds ) <= 1.e-20 ) zds = 1.e-20
+                  rrau(ji,jj,jk) = zalbet * ( ptem(ji,jj,jk-1) - ptem(ji,jj,jk) ) / zds
+               END DO
+            END DO
+#endif
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      IF(ln_ctl)   THEN
+         CALL prt_ctl(tab3d_1=pn2, clinfo1=' bn2  : ', ovlap=1, kdim=jpk)
+#if defined key_zdfddm
+         CALL prt_ctl(tab3d_1=rrau, clinfo1=' rrau : ', ovlap=1, kdim=jpk)
+#endif
+      ENDIF
+
+   END SUBROUTINE eos_bn2
+
+
+   SUBROUTINE eos_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_init  ***
+      !!
+      !! ** Purpose :   initializations for the equation of state
+      !!
+      !! ** Method  :   Read the namelist nameos
+      !!
+      !! ** Action  :   blahblah....
+      !!
+      !! History :
+      !!   8.5  !  02-10  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      NAMELIST/nameos/ neos, ralpha, rbeta
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      ! set the initialization flag to 1
+      neos_init = 1           ! indicate that the initialization has been done
+
+      ! namelist nameos : ocean physical parameters
+
+      ! Read Namelist nameos : equation of state
+      REWIND( numnam )
+      READ  ( numnam, nameos )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'eos_init : equation of state'
+         WRITE(numout,*) '~~~~~~~~'
+         WRITE(numout,*) '          Namelist nameos : set eos parameters'
+         WRITE(numout,*)
+         WRITE(numout,*) '             flag for eq. of state and N^2  neos   = ', neos
+         WRITE(numout,*) '             thermal exp. coef. (linear)    ralpha = ', ralpha
+         WRITE(numout,*) '             saline  exp. coef. (linear)    rbeta  = ', rbeta
+         WRITE(numout,*)
+      ENDIF
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+         IF(lwp) WRITE(numout,*) '          use of Jackett & McDougall (1994) equation of state and'
+         IF(lwp) WRITE(numout,*) '                 McDougall (1987) Brunt-Vaisala frequency'
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T) = rau0 * ( 1.0285 - ralpha * T )'
+         IF( lk_zdfddm ) CALL ctl_stop( '          double diffusive mixing parameterization requires',   &
+              &                         ' that T and S are used as state variables' )
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T,S) = rau0 * ( rbeta * S - ralpha * T )'
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE eos_init
+
+   !!======================================================================
+END MODULE eosbn2  
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/geo2ocean.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/geo2ocean.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/geo2ocean.F90	(revision 4536)
@@ -0,0 +1,449 @@
+MODULE geo2ocean
+   !!======================================================================
+   !!                     ***  MODULE  geo2ocean  ***
+   !! Ocean mesh    :  ???
+   !!=====================================================================
+
+   !!----------------------------------------------------------------------
+   !!   repcmo      : 
+   !!   angle       :
+   !!   geo2oce     :
+   !!   repere      :   old routine suppress it ???
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! mesh and scale factors
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+
+   !! * Accessibility
+   PRIVATE
+   PUBLIC rot_rep, repcmo, repere, geo2oce   ! only rot_rep should be used
+                                             ! repcmo and repere are keep only for compatibility.
+                                             ! they are only a useless overlay of rot_rep
+
+   !! * Module variables
+   REAL(wp), DIMENSION(jpi,jpj) ::   &
+      gsint, gcost,   &  ! cos/sin between model grid lines and NP direction at T point
+      gsinu, gcosu,   &  ! cos/sin between model grid lines and NP direction at U point
+      gsinv, gcosv,   &  ! cos/sin between model grid lines and NP direction at V point
+      gsinf, gcosf       ! cos/sin between model grid lines and NP direction at F point
+
+   LOGICAL ::   lmust_init = .TRUE.        !: used to initialize the cos/sin variables (se above)
+
+  !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/geo2ocean.F90,v 1.7 2007/06/29 14:23:06 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE repcmo ( pxu1, pyu1, pxv1, pyv1,   &
+                       px2 , py2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE repcmo  ***
+      !!
+      !! ** Purpose :   Change vector componantes from a geographic grid to a
+      !!      stretched coordinates grid.
+      !!
+      !! ** Method  :   Initialization of arrays at the first call.
+      !!
+      !! ** Action  : - px2 : first componante (defined at u point)
+      !!              - py2 : second componante (defined at v point)
+      !!
+      !! History :
+      !!   7.0  !  07-96  (O. Marti)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments 
+      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) ::   & 
+         pxu1, pyu1,     & ! geographic vector componantes at u-point
+         pxv1, pyv1        ! geographic vector componantes at v-point
+      REAL(wp), INTENT( out ), DIMENSION(jpi,jpj) ::   & 
+         px2,            & ! i-componante (defined at u-point)
+         py2               ! j-componante (defined at v-point)
+      !!----------------------------------------------------------------------
+      
+      ! Change from geographic to stretched coordinate
+      ! ----------------------------------------------
+      
+      CALL rot_rep( pxu1, pyu1, 'U', 'en->i',px2 )
+      CALL rot_rep( pxv1, pyv1, 'V', 'en->j',py2 )
+      
+   END SUBROUTINE repcmo
+
+
+   SUBROUTINE rot_rep ( pxin, pyin, cd_type, cdtodo, prot )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE rot_rep  ***
+      !!
+      !! ** Purpose :   Rotate the Repere: Change vector componantes between
+      !!                geographic grid <--> stretched coordinates grid.
+      !!
+      !! History :
+      !!   9.2  !  07-04  (S. Masson)  
+      !!                  (O. Marti ) Original code (repere and repcmo)
+      !!----------------------------------------------------------------------
+      !! * Arguments 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( IN ) ::   pxin, pyin   ! vector componantes
+      CHARACTER(len=1),             INTENT( IN ) ::   cd_type      ! define the nature of pt2d array grid-points
+      CHARACTER(len=5),             INTENT( IN ) ::   cdtodo       ! specify the work to do:
+      !!                                                           ! 'en->i' east-north componantes to model i componante
+      !!                                                           ! 'en->j' east-north componantes to model j componante
+      !!                                                           ! 'ij->e' model i-j componantes to east componante
+      !!                                                           ! 'ij->n' model i-j componantes to east componante
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::   prot      
+
+      !!----------------------------------------------------------------------
+
+      ! Initialization of gsin* and gcos* at first call
+      ! -----------------------------------------------
+
+      IF( lmust_init ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' rot_rep : geographic <--> stretched'
+         IF(lwp) WRITE(numout,*) ' ~~~~~    coordinate transformation'
+
+         CALL angle       ! initialization of the transformation
+         lmust_init = .FALSE.
+
+      ENDIF
+      
+      SELECT CASE (cdtodo)
+      CASE ('en->i')      ! 'en->i' est-north componantes to model i componante
+         SELECT CASE (cd_type)
+         CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) + pyin(:,:) * gsint(:,:)
+         CASE ('U')   ;   prot(:,:) = pxin(:,:) * gcosu(:,:) + pyin(:,:) * gsinu(:,:)
+         CASE ('V')   ;   prot(:,:) = pxin(:,:) * gcosv(:,:) + pyin(:,:) * gsinv(:,:)
+         CASE ('F')   ;   prot(:,:) = pxin(:,:) * gcosf(:,:) + pyin(:,:) * gsinf(:,:)
+         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
+         END SELECT
+      CASE ('en->j')      ! 'en->j' est-north componantes to model j componante
+         SELECT CASE (cd_type)
+         CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) - pxin(:,:) * gsint(:,:)
+         CASE ('U')   ;   prot(:,:) = pyin(:,:) * gcosu(:,:) - pxin(:,:) * gsinu(:,:)
+         CASE ('V')   ;   prot(:,:) = pyin(:,:) * gcosv(:,:) - pxin(:,:) * gsinv(:,:)   
+         CASE ('F')   ;   prot(:,:) = pyin(:,:) * gcosf(:,:) - pxin(:,:) * gsinf(:,:)   
+         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
+         END SELECT
+      CASE ('ij->e')      ! 'ij->e' model i-j componantes to est componante
+         SELECT CASE (cd_type)
+         CASE ('T')   ;   prot(:,:) = pxin(:,:) * gcost(:,:) - pyin(:,:) * gsint(:,:)
+         CASE ('U')   ;   prot(:,:) = pxin(:,:) * gcosu(:,:) - pyin(:,:) * gsinu(:,:)
+         CASE ('V')   ;   prot(:,:) = pxin(:,:) * gcosv(:,:) - pyin(:,:) * gsinv(:,:)
+         CASE ('F')   ;   prot(:,:) = pxin(:,:) * gcosf(:,:) - pyin(:,:) * gsinf(:,:)
+         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
+         END SELECT
+      CASE ('ij->n')      ! 'ij->n' model i-j componantes to est componante
+         SELECT CASE (cd_type)
+         CASE ('T')   ;   prot(:,:) = pyin(:,:) * gcost(:,:) + pxin(:,:) * gsint(:,:)
+         CASE ('U')   ;   prot(:,:) = pyin(:,:) * gcosu(:,:) + pxin(:,:) * gsinu(:,:)
+         CASE ('V')   ;   prot(:,:) = pyin(:,:) * gcosv(:,:) + pxin(:,:) * gsinv(:,:)
+         CASE ('F')   ;   prot(:,:) = pyin(:,:) * gcosf(:,:) + pxin(:,:) * gsinf(:,:)
+         CASE DEFAULT   ;   CALL ctl_stop( 'Only T, U, V and F grid points are coded' )
+         END SELECT
+      CASE DEFAULT   ;   CALL ctl_stop( 'rot_rep: Syntax Error in the definition of cdtodo' )
+      END SELECT
+      
+   END SUBROUTINE rot_rep
+
+
+   SUBROUTINE angle
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE angle  ***
+      !! 
+      !! ** Purpose :   Compute angles between model grid lines and the North direction
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action  :   Compute (gsint, gcost, gsinu, gcosu, gsinv, gcosv, gsinf, gcosf) arrays:
+      !!      sinus and cosinus of the angle between the north-south axe and the 
+      !!      j-direction at t, u, v and f-points
+      !!
+      !! History :
+      !!   7.0  !  96-07  (O. Marti )  Original code
+      !!   8.0  !  98-06  (G. Madec )
+      !!   8.5  !  98-06  (G. Madec )  Free form, F90 + opt.
+      !!   9.2  !  07-04  (S. Masson)  Add T, F points and bugfix in cos lateral boundary
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER ::   ji, jj      ! dummy loop indices
+
+      REAL(wp) ::   &
+         zlam, zphi,            &  ! temporary scalars
+         zlan, zphh,            &  !    "         "
+         zxnpt, zynpt, znnpt,   &  ! x,y components and norm of the vector: T point to North Pole
+         zxnpu, zynpu, znnpu,   &  ! x,y components and norm of the vector: U point to North Pole
+         zxnpv, zynpv, znnpv,   &  ! x,y components and norm of the vector: V point to North Pole
+         zxnpf, zynpf, znnpf,   &  ! x,y components and norm of the vector: F point to North Pole
+         zxvvt, zyvvt, znvvt,   &  ! x,y components and norm of the vector: between V points below and above a T point
+         zxffu, zyffu, znffu,   &  ! x,y components and norm of the vector: between F points below and above a U point
+         zxffv, zyffv, znffv,   &  ! x,y components and norm of the vector: between F points left  and right a V point
+         zxuuf, zyuuf, znuuf       ! x,y components and norm of the vector: between U points below and above a F point
+      !!----------------------------------------------------------------------
+
+      ! ============================= !
+      ! Compute the cosinus and sinus !
+      ! ============================= !
+      ! (computation done on the north stereographic polar plane)
+
+      DO jj = 2, jpjm1
+!CDIR NOVERRCHK
+         DO ji = fs_2, jpi   ! vector opt.
+
+            ! north pole direction & modulous (at t-point)
+            zlam = glamt(ji,jj)
+            zphi = gphit(ji,jj)
+            zxnpt = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            zynpt = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            znnpt = zxnpt*zxnpt + zynpt*zynpt
+
+            ! north pole direction & modulous (at u-point)
+            zlam = glamu(ji,jj)
+            zphi = gphiu(ji,jj)
+            zxnpu = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            zynpu = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            znnpu = zxnpu*zxnpu + zynpu*zynpu
+
+            ! north pole direction & modulous (at v-point)
+            zlam = glamv(ji,jj)
+            zphi = gphiv(ji,jj)
+            zxnpv = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            zynpv = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            znnpv = zxnpv*zxnpv + zynpv*zynpv
+
+            ! north pole direction & modulous (at f-point)
+            zlam = glamf(ji,jj)
+            zphi = gphif(ji,jj)
+            zxnpf = 0. - 2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            zynpf = 0. - 2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )
+            znnpf = zxnpf*zxnpf + zynpf*zynpf
+
+            ! j-direction: v-point segment direction (around t-point)
+            zlam = glamv(ji,jj  )
+            zphi = gphiv(ji,jj  )
+            zlan = glamv(ji,jj-1)
+            zphh = gphiv(ji,jj-1)
+            zxvvt =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            zyvvt =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            znvvt = SQRT( znnpt * ( zxvvt*zxvvt + zyvvt*zyvvt )  )
+            znvvt = MAX( znvvt, 1.e-14 )
+
+            ! j-direction: f-point segment direction (around u-point)
+            zlam = glamf(ji,jj  )
+            zphi = gphif(ji,jj  )
+            zlan = glamf(ji,jj-1)
+            zphh = gphif(ji,jj-1)
+            zxffu =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            zyffu =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            znffu = SQRT( znnpu * ( zxffu*zxffu + zyffu*zyffu )  )
+            znffu = MAX( znffu, 1.e-14 )
+
+            ! i-direction: f-point segment direction (around v-point)
+            zlam = glamf(ji  ,jj)
+            zphi = gphif(ji  ,jj)
+            zlan = glamf(ji-1,jj)
+            zphh = gphif(ji-1,jj)
+            zxffv =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            zyffv =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            znffv = SQRT( znnpv * ( zxffv*zxffv + zyffv*zyffv )  )
+            znffv = MAX( znffv, 1.e-14 )
+
+            ! j-direction: u-point segment direction (around f-point)
+            zlam = glamu(ji,jj+1)
+            zphi = gphiu(ji,jj+1)
+            zlan = glamu(ji,jj  )
+            zphh = gphiu(ji,jj  )
+            zxuuf =  2. * COS( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * COS( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            zyuuf =  2. * SIN( rad*zlam ) * TAN( rpi/4. - rad*zphi/2. )   &
+               &  -  2. * SIN( rad*zlan ) * TAN( rpi/4. - rad*zphh/2. )
+            znuuf = SQRT( znnpf * ( zxuuf*zxuuf + zyuuf*zyuuf )  )
+            znuuf = MAX( znuuf, 1.e-14 )
+
+            ! cosinus and sinus using scalar and vectorial products
+            gsint(ji,jj) = ( zxnpt*zyvvt - zynpt*zxvvt ) / znvvt
+            gcost(ji,jj) = ( zxnpt*zxvvt + zynpt*zyvvt ) / znvvt
+
+            gsinu(ji,jj) = ( zxnpu*zyffu - zynpu*zxffu ) / znffu
+            gcosu(ji,jj) = ( zxnpu*zxffu + zynpu*zyffu ) / znffu
+
+            gsinf(ji,jj) = ( zxnpf*zyuuf - zynpf*zxuuf ) / znuuf
+            gcosf(ji,jj) = ( zxnpf*zxuuf + zynpf*zyuuf ) / znuuf
+
+            ! (caution, rotation of 90 degres)
+            gsinv(ji,jj) = ( zxnpv*zxffv + zynpv*zyffv ) / znffv
+            gcosv(ji,jj) =-( zxnpv*zyffv - zynpv*zxffv ) / znffv
+
+         END DO
+      END DO
+
+      ! =============== !
+      ! Geographic mesh !
+      ! =============== !
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, jpi   ! vector opt.
+            IF( MOD( ABS( glamv(ji,jj) - glamv(ji,jj-1) ), 360. ) < 1.e-8 ) THEN
+               gsint(ji,jj) = 0.
+               gcost(ji,jj) = 1.
+            ENDIF
+            IF( MOD( ABS( glamf(ji,jj) - glamf(ji,jj-1) ), 360. ) < 1.e-8 ) THEN
+               gsinu(ji,jj) = 0.
+               gcosu(ji,jj) = 1.
+            ENDIF
+            IF(      ABS( gphif(ji,jj) - gphif(ji-1,jj) )         < 1.e-8 ) THEN
+               gsinv(ji,jj) = 0.
+               gcosv(ji,jj) = 1.
+            ENDIF
+            IF( MOD( ABS( glamu(ji,jj) - glamu(ji,jj+1) ), 360. ) < 1.e-8 ) THEN
+               gsinf(ji,jj) = 0.
+               gcosf(ji,jj) = 1.
+            ENDIF
+         END DO
+      END DO
+
+      ! =========================== !
+      ! Lateral boundary conditions !
+      ! =========================== !
+
+      ! lateral boundary cond.: T-, U-, V-, F-pts, sgn
+      CALL lbc_lnk ( gcost, 'T', 1. )   ;   CALL lbc_lnk( gsint, 'T', -1. )
+      CALL lbc_lnk ( gcosu, 'U', 1. )   ;   CALL lbc_lnk( gsinu, 'U', -1. )
+      CALL lbc_lnk ( gcosv, 'V', 1. )   ;   CALL lbc_lnk( gsinv, 'V', -1. )
+      CALL lbc_lnk ( gcosf, 'F', 1. )   ;   CALL lbc_lnk( gsinf, 'F', -1. )
+
+   END SUBROUTINE angle
+
+
+   SUBROUTINE geo2oce ( pxx , pyy , pzz, cgrid,     &
+                        plon, plat, pte, ptn  , ptv )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE geo2oce  ***
+      !!      
+      !! ** Purpose :
+      !!
+      !! ** Method  :   Change wind stress from geocentric to east/north
+      !!
+      !! History :
+      !!        !         (O. Marti)  Original code
+      !!        !  91-03  (G. Madec)
+      !!        !  92-07  (M. Imbard)
+      !!        !  99-11  (M. Imbard) NetCDF format with IOIPSL
+      !!        !  00-08  (D. Ludicone) Reduced section at Bab el Mandeb
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) ::   &
+         pxx, pyy, pzz
+      CHARACTER (len=1), INTENT( in) ::   &
+         cgrid
+      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj) ::   &
+         plon, plat
+      REAL(wp), INTENT(out), DIMENSION(jpi,jpj) ::    &
+         pte, ptn, ptv
+      REAL(wp), PARAMETER :: rpi = 3.141592653E0
+      REAL(wp), PARAMETER :: rad = rpi / 180.e0
+
+      !! * Local variables
+      INTEGER ::   ig     !
+
+      !! * Local save
+      REAL(wp), SAVE, DIMENSION(jpi,jpj,4) ::   &
+         zsinlon, zcoslon,   &
+         zsinlat, zcoslat
+      LOGICAL, SAVE, DIMENSION (4) ::   &
+         linit = .FALSE.
+      !!----------------------------------------------------------------------
+
+      SELECT CASE( cgrid)
+
+         CASE ( 't' ) ;; ig = 1
+         CASE ( 'u' ) ;; ig = 2
+         CASE ( 'v' ) ;; ig = 3
+         CASE ( 'f' ) ;; ig = 4
+
+         CASE default
+            WRITE(ctmp1,*) 'geo2oce : bad grid argument : ', cgrid
+            CALL ctl_stop( ctmp1 )
+       END SELECT
+      
+      IF( .NOT. linit(ig) ) THEN 
+         zsinlon (:,:,ig) = SIN (rad * plon)
+         zcoslon (:,:,ig) = COS (rad * plon)
+         zsinlat (:,:,ig) = SIN (rad * plat)
+         zcoslat (:,:,ig) = COS (rad * plat)
+         linit (ig) = .TRUE.
+      ENDIF
+      
+      pte = - zsinlon (:,:,ig) * pxx + zcoslon (:,:,ig) * pyy
+      ptn = - zcoslon (:,:,ig) * zsinlat (:,:,ig) * pxx    &
+            - zsinlon (:,:,ig) * zsinlat (:,:,ig) * pyy    &
+            + zcoslat (:,:,ig) * pzz
+      ptv =   zcoslon (:,:,ig) * zcoslat (:,:,ig) * pxx    &
+            + zsinlon (:,:,ig) * zcoslat (:,:,ig) * pyy    &
+            + zsinlat (:,:,ig) * pzz
+
+   END SUBROUTINE geo2oce
+
+
+   SUBROUTINE repere ( px1, py1, px2, py2, kchoix, cd_type )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE repere  ***
+      !!        
+      !! ** Purpose :   Change vector componantes between a geopgraphic grid 
+      !!      and a stretched coordinates grid.
+      !!
+      !! ** Method  :   
+      !!
+      !! ** Action  :
+      !!
+      !! History :
+      !!        !  89-03  (O. Marti)  original code
+      !!        !  92-02  (M. Imbard)
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  98-05  (B. Blanke)
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT( IN   ), DIMENSION(jpi,jpj) ::   &
+         px1, py1          ! two horizontal components to be rotated
+      REAL(wp), INTENT( OUT  ), DIMENSION(jpi,jpj) ::   &
+         px2, py2          ! the two horizontal components in the model repere
+      INTEGER, INTENT( IN ) ::   &
+         kchoix   ! type of transformation
+                  ! = 1 change from geographic to model grid.
+                  ! =-1 change from model to geographic grid
+      CHARACTER(len=1), INTENT( IN ), OPTIONAL ::   cd_type      ! define the nature of pt2d array grid-points
+      !
+      CHARACTER(len=1) ::   cl_type      ! define the nature of pt2d array grid-points (T point by default)
+      !!----------------------------------------------------------------------
+
+      cl_type = 'T'
+      IF( PRESENT(cd_type) )   cl_type = cd_type
+         !
+      SELECT CASE (kchoix)
+      CASE ( 1)      ! change from geographic to model grid.
+         CALL rot_rep( px1, py1, cl_type, 'en->i', px2 )
+         CALL rot_rep( px1, py1, cl_type, 'en->j', py2 )
+      CASE (-1)      ! change from model to geographic grid
+         CALL rot_rep( px1, py1, cl_type, 'ij->e', px2 )
+         CALL rot_rep( px1, py1, cl_type, 'ij->n', py2 )
+      CASE DEFAULT   ;   CALL ctl_stop( 'repere: Syntax Error in the definition of kchoix (1 OR -1' )
+      END SELECT
+      
+   END SUBROUTINE repere
+
+  !!======================================================================
+END MODULE geo2ocean
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ice_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ice_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ice_oce.F90	(revision 4536)
@@ -0,0 +1,66 @@
+MODULE ice_oce
+   !!======================================================================
+   !!                 ***  MODULE  ice_oce  ***
+   !! Ocean - ice  :  ice variables defined in memory 
+   !!======================================================================
+   !! History :
+   !!   8.5  !  02-11  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_ice_lim
+   !!----------------------------------------------------------------------
+   !!   'key_ice_lim'   :                                     LIM ice model
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE par_oce         ! ocean parameters
+   USE blk_oce         ! bulk parameters
+
+   IMPLICIT NONE
+   PRIVATE
+ 
+   !! Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_ice_lim = .TRUE.    !: LIM ice model
+
+   !!----------------------------------------------------------------------
+   !! ice-ocean common variables
+   !!----------------------------------------------------------------------
+# if defined key_coupled
+   REAL(wp), PUBLIC, DIMENSION(jpiglo,jpjglo) ::   &  !: cumulated fields
+      fqsr_oce ,      &   !: Net short wave heat flux on free ocean 
+      fqsr_ice ,      &   !: Net short wave het flux on sea ice 
+      fqnsr_oce,      &   !: Net longwave heat flux on free ocean
+      fqnsr_ice,      &   !: Net longwave heat flux on sea ice
+      fdqns_ice,      &   !: Derivative of non solar heat flux on sea ice
+      ftprecip ,      &   !: Water flux (liquid precipitation - evaporation) 
+      fsprecip ,      &   !: Solid (snow) precipitation
+      frunoff  ,      &   !: runoff
+      fcalving            !: Iceberg calving 
+# endif
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !: field exchanges with ice model to ocean
+      sst_io, sss_io , &  !: sea surface temperature (C) and salinity (PSU)
+      u_io  , v_io   , &  !: velocity at ice surface (m/s)
+      fsolar, fnsolar, &  !: solar and non-solar heat fluxes (W/m2)
+      fsalt , fmass  , &  !: salt and freshwater fluxes
+      ftaux , ftauy  , &  !: wind stresses
+      gtaux , gtauy       !: wind stresses
+   
+   REAL(wp), PUBLIC ::   &  !:
+      rdt_ice,           &  !: ice time step
+      dtsd2                 !: ice time step divide by 2
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                 NO LIM sea-ice model
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_ice_lim = .FALSE.  !: No LIM ice model
+#endif
+
+   INTEGER, PUBLIC ::   &  !: namdom : space/time domain (namlist)
+      nfice =  5           !: coupling frequency OPA ICELLN  nfice 
+
+   !!----------------------------------------------------------------------
+END MODULE ice_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/initrc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/initrc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/initrc.F90	(revision 4536)
@@ -0,0 +1,22 @@
+MODULE initrc
+   !!======================================================================
+   !!                       ***  MODULE initrc  ***
+   !!  Dummy module
+   !! Initialization for the tracer model
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Default key                                     No passive tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ini_trc        ! Empty routine
+      WRITE(*,*) 'ini_trc: You should not have seen this print! error?'
+   END SUBROUTINE ini_trc
+
+   !!======================================================================
+END MODULE initrc
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/istate.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/istate.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/istate.F90	(revision 4536)
@@ -0,0 +1,591 @@
+MODULE istate
+   !!======================================================================
+   !!                     ***  MODULE  istate  ***
+   !! Ocean state   :  initial state setting
+   !!=====================================================================
+   !! History :   4.0  !  89-12  (P. Andrich)  Original code
+   !!             5.0  !  91-11  (G. Madec)  rewritting
+   !!             6.0  !  96-01  (G. Madec)  terrain following coordinates
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_eel
+   !!             8.0  !  01-09  (M. Levy, M. Ben Jelloul)  istate_uvg
+   !!             9.0  !  03-08  (G. Madec)  F90: Free form, modules
+   !!             9.0  !  03-09  (G. Madec, C. Talandier)  add EEL R5
+   !!             9.0  !  04-05  (A. Koch-Larrouy)  istate_gyre 
+   !!             9.0  !  06-07  (S. Masson)  distributed restart using iom
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   istate_init   : initial state setting
+   !!   istate_tem    : analytical profile for initial Temperature
+   !!   istate_sal    : analytical profile for initial Salinity
+   !!   istate_eel    : initial state setting of EEL R5 configuration
+   !!   istate_gyre   : initial state setting of GYRE configuration
+   !!   istate_uvg    : initial velocity in geostropic balance
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers 
+   USE dom_oce         ! ocean space and time domain 
+   USE daymod          ! 
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE phycst          ! physical constants
+   USE wzvmod          ! verctical velocity               (wzv     routine)
+   USE dtatem          ! temperature data                 (dta_tem routine)
+   USE dtasal          ! salinity data                    (dta_sal routine)
+   USE restart         ! ocean restart                   (rst_read routine)
+   USE solisl          ! ???
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE ini1d           ! re-initialization of u-v mask for the 1D configuration
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE domvvl          ! varying vertical mesh
+   USE dynspg_oce      ! pressure gradient schemes
+   USE dynspg_flt      ! pressure gradient schemes
+   USE dynspg_exp      ! pressure gradient schemes
+   USE dynspg_ts       ! pressure gradient schemes
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   istate_init   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/istate.F90,v 1.20 2007/06/06 20:25:36 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE istate_init
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_init  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracer fields.
+      !!----------------------------------------------------------------------
+      USE eosbn2          ! eq. of state, Brunt Vaisala frequency (eos     routine)
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_ini : Initialization of the dynamics and tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      rhd  (:,:,:) = 0.e0
+      rhop (:,:,:) = 0.e0
+      rn2  (:,:,:) = 0.e0 
+
+      IF( ln_rstart ) THEN                    ! Restart from a file
+         !                                    ! -------------------
+         neuler = 1                              ! Set time-step indicator at nit000 (leap-frog)
+         CALL rst_read                           ! Read the restart file
+      ELSE
+         !                                    ! Start from rest
+         !                                    ! ---------------
+         neuler = 0                              ! Set time-step indicator at nit000 (euler forward)
+         adatrj = 0._wp
+         numror = 0                              ! define numror = 0 -> no restart file to read
+         !                                       ! Initialization of ocean to zero
+         !     before fields       !       now fields          
+             ub   (:,:,:) = 0.e0   ;   un   (:,:,:) = 0.e0   ; sshb(:,:) = 0.e0
+             vb   (:,:,:) = 0.e0   ;   vn   (:,:,:) = 0.e0   ; sshn(:,:) = 0.e0
+             rotb (:,:,:) = 0.e0   ;   rotn (:,:,:) = 0.e0
+             hdivb(:,:,:) = 0.e0   ;   hdivn(:,:,:) = 0.e0
+         !
+         IF( cp_cfg == 'eel' ) THEN
+            CALL istate_eel                      ! EEL   configuration : start from pre-defined
+            !                                    !                       velocity and thermohaline fields
+         ELSEIF( cp_cfg == 'gyre' ) THEN         
+            CALL istate_gyre                     ! GYRE  configuration : start from pre-defined temperature
+            !                                    !                       and salinity fields 
+         ELSE
+            !                                    ! Other configurations: Initial temperature and salinity fields
+#if defined key_dtatem
+            CALL dta_tem( nit000 )                  ! read 3D temperature data
+            tb(:,:,:) = t_dta(:,:,:)                ! use temperature data read
+            tn(:,:,:) = t_dta(:,:,:)
+#else
+            IF(lwp) WRITE(numout,*)                 ! analytical temperature profile
+            IF(lwp) WRITE(numout,*)'             Temperature initialization using an analytic profile'
+            CALL istate_tem
+#endif
+#if defined key_dtasal
+            CALL dta_sal( nit000 )                  ! read 3D salinity data
+            sb(:,:,:) = s_dta(:,:,:)                ! use salinity data read
+            sn(:,:,:) = s_dta(:,:,:)
+#else
+            ! No salinity data
+            IF(lwp)WRITE(numout,*)                  ! analytical salinity profile
+            IF(lwp)WRITE(numout,*)'             Salinity initialisation using a constant value'
+            CALL istate_sal
+#endif
+         ENDIF
+
+         CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
+         
+         IF( ln_zps .AND. .NOT. lk_cfg_1d )   &
+            &             CALL zps_hde( nit000, tb, sb, rhd,  &  ! Partial steps: before Horizontal DErivative
+            &                                  gtu, gsu, gru, &  ! of t, s, rd at the bottom ocean level
+            &                                  gtv, gsv, grv )
+         
+      ENDIF
+
+      IF( lk_vvl ) THEN
+         ! read free surface arrays in restart file
+         IF( ln_rstart ) THEN
+            IF( lk_dynspg_flt )   CALL flt_rst( nit000, 'READ' )      ! read or initialize the following fields
+            !                                                         ! gcx, gcxb, sshb, sshn
+            IF( lk_dynspg_ts  )   CALL ts_rst ( nit000, 'READ' )      ! read or initialize the following fields
+            !                                                         ! sshb, sshn, sshb_b, sshn_b, un_b, vn_b
+            IF( lk_dynspg_exp )   CALL exp_rst( nit000, 'READ' )      ! read or initialize the following fields
+            !                                                         ! sshb, sshn
+         ENDIF
+         !
+         IF( .NOT. lk_dynspg_flt ) sshbb(:,:) = sshb(:,:)
+         !
+         CALL dom_vvl               ! ssh init and vertical grid update
+
+         CALL eos_init              ! usefull to get the equation state type neos parameter
+
+         CALL bn2( tb, sb, rn2 )    ! before Brunt Vaissala frequency
+
+         IF( .NOT. ln_rstart ) CALL wzv( nit000 ) 
+
+      ENDIF
+
+      !                                       ! Vertical velocity
+      !                                       ! -----------------
+
+      IF( .NOT. lk_vvl )    CALL wzv( nit000 )                         ! from horizontal divergence
+      !
+   END SUBROUTINE istate_init
+
+
+   SUBROUTINE istate_tem
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE istate_tem  ***
+      !!   
+      !! ** Purpose :   Intialization of the temperature field with an 
+      !!      analytical profile or a file (i.e. in EEL configuration)
+      !!
+      !! ** Method  :   Use Philander analytic profile of temperature
+      !!
+      !! References :  Philander ???
+      !!----------------------------------------------------------------------
+      INTEGER :: ji, jj, jk
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_tem : initial temperature profile'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               tn(ji,jj,jk) = (  ( ( 7.5 - 0.*ABS(gphit(ji,jj))/30. )   &
+                  &               *( 1.-TANH((fsdept(ji,jj,jk)-80.)/30.) )   &
+                  &            + 10.*(5000.-fsdept(ji,jj,jk))/5000.)  ) * tmask(ji,jj,jk)
+               tb(ji,jj,jk) = tn(ji,jj,jk)
+          END DO
+        END DO
+      END DO
+
+      IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
+         &                 1     , jpi   , 5     , 1     , jpk   ,   &
+         &                 1     , 1.    , numout                  )
+      !
+   END SUBROUTINE istate_tem
+
+
+   SUBROUTINE istate_sal
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE istate_sal  ***
+      !!
+      !! ** Purpose :   Intialize the salinity field with an analytic profile
+      !!
+      !! ** Method  :   Use to a constant value 35.5
+      !!              
+      !! ** Action  :   Initialize sn and sb
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zsal = 35.50_wp
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'istate_sal : initial salinity : ', zsal
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      sn(:,:,:) = zsal * tmask(:,:,:)
+      sb(:,:,:) = sn(:,:,:)
+      
+   END SUBROUTINE istate_sal
+
+
+   SUBROUTINE istate_eel
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_eel  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers for EEL R5
+      !!      configuration (channel with or without a topographic bump)
+      !!
+      !! ** Method  : - set temprature field
+      !!              - set salinity field
+      !!              - set velocity field including horizontal divergence
+      !!                and relative vorticity fields
+      !!----------------------------------------------------------------------
+      USE eosbn2     ! eq. of state, Brunt Vaisala frequency (eos     routine)
+      USE divcur     ! hor. divergence & rel. vorticity      (div_cur routine)
+      USE iom
+ 
+      INTEGER  ::   inum              ! temporary logical unit
+      INTEGER  ::   ji, jj, jk        ! dummy loop indices
+      INTEGER  ::   ijloc
+      REAL(wp) ::   zh1, zh2, zslope, zcst, zfcor   ! temporary scalars
+      REAL(wp) ::   zt1  = 15._wp,               &  ! surface temperature value (EEL R5)
+         &          zt2  =  5._wp,               &  ! bottom  temperature value (EEL R5)
+         &          zsal = 35.0_wp,              &  ! constant salinity (EEL R2, R5 and R6)
+         &          zueel = 0.1_wp                  ! constant uniform zonal velocity (EEL R5)
+# if ! defined key_dynspg_rl
+      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zssh  ! initial ssh over the global domain
+# endif
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( jp_cfg ) 
+         !                                              ! ====================
+         CASE ( 5 )                                     ! EEL R5 configuration
+            !                                           ! ====================
+
+            ! set temperature field with a linear profile
+            ! -------------------------------------------
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: linear temperature profile'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+            zh1 = gdept_0(  1  )
+            zh2 = gdept_0(jpkm1)
+
+            zslope = ( zt1 - zt2 ) / ( zh1 - zh2 )
+            zcst   = ( zt1 * ( zh1 - zh2) - ( zt1 - zt2 ) * zh1 ) / ( zh1 - zh2 )
+
+            DO jk = 1, jpk
+               tn(:,:,jk) = ( zt2 + zt1 * exp( - fsdept(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
+               tb(:,:,jk) = tn(:,:,jk)
+            END DO
+
+            IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
+               &                 1     , jpi   , 5     , 1     , jpk   ,   &
+               &                 1     , 1.    , numout                  )
+
+            ! set salinity field to a constant value
+            ! --------------------------------------
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+            sn(:,:,:) = zsal * tmask(:,:,:)
+            sb(:,:,:) = sn(:,:,:)
+      
+
+# if ! defined key_dynspg_rl
+            ! set the dynamics: U,V, hdiv, rot (and ssh if necessary)
+            ! ----------------
+            ! Start EEL5 configuration with barotropic geostrophic velocities 
+            ! according the sshb and sshn SSH imposed.
+            ! we assume a uniform grid (hence the use of e1t(1,1) for delta_y)
+            ! we use the Coriolis frequency at mid-channel.   
+    
+            ub(:,:,:) = zueel * umask(:,:,:)
+            un(:,:,:) = ub(:,:,:)
+            ijloc = mj0(INT(jpjglo-1)/2)
+            zfcor = ff(1,ijloc)
+
+            DO jj = 1, jpjglo
+               zssh(:,jj) = - (FLOAT(jj)- FLOAT(jpjglo-1)/2.)*zueel*e1t(1,1)*zfcor/grav 
+            END DO
+
+            IF(lwp) THEN
+               WRITE(numout,*) ' Uniform zonal velocity for EEL R5:',zueel
+               WRITE(numout,*) ' Geostrophic SSH profile as a function of y:'
+               WRITE(numout,'(12(1x,f6.2))') zssh(1,:)
+            ENDIF
+
+            DO jj = 1, nlcj
+               DO ji = 1, nlci
+                  sshb(ji,jj) = zssh( mig(ji) , mjg(jj) ) * tmask(ji,jj,1)
+               END DO
+            END DO
+            sshb(nlci+1:jpi,      :   ) = 0.e0      ! set to zero extra mpp columns
+            sshb(      :   ,nlcj+1:jpj) = 0.e0      ! set to zero extra mpp rows
+
+            sshn(:,:) = sshb(:,:)                   ! set now ssh to the before value
+
+            IF( nn_rstssh /= 0 ) THEN  
+               nn_rstssh = 0                           ! hand-made initilization of ssh 
+               CALL ctl_warn( 'istate_eel: force nn_rstssh = 0' )
+            ENDIF
+
+            ! horizontal divergence and relative vorticity (curl)
+            CALL div_cur( nit000 )
+
+            ! N.B. the vertical velocity will be computed from the horizontal divergence field
+            ! in istate by a call to wzv routine
+# endif
+
+
+            !                                     ! ==========================
+         CASE ( 2 , 6 )                           ! EEL R2 or R6 configuration
+            !                                     ! ==========================
+ 
+            ! set temperature field with a NetCDF file
+            ! ----------------------------------------
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R2 or R6: read initial temperature in a NetCDF file'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+            CALL iom_open ( 'eel.initemp', inum )
+            CALL iom_get ( inum, jpdom_data, 'initemp', tb ) ! read before temprature (tb)
+            CALL iom_close( inum )
+     
+            tn(:,:,:) = tb(:,:,:)                            ! set nox temperature to tb
+
+            IF(lwp) CALL prizre( tn    , jpi   , jpj   , jpk   , jpj/2 ,   &
+               &                 1     , jpi   , 5     , 1     , jpk   ,   &
+               &                 1     , 1.    , numout                  )
+
+
+            ! set salinity field to a constant value
+            ! --------------------------------------
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+ 
+            sn(:,:,:) = zsal * tmask(:,:,:)
+            sb(:,:,:) = sn(:,:,:)
+
+
+            IF( lk_isl ) THEN
+               ! Horizontal velocity : start from geostrophy (EEL config)
+               CALL eos( tn, sn, rhd )     ! now in situ density
+               CALL istate_uvg             ! compute geostrophic velocity
+
+               ! N.B. the vertical velocity will be computed from the horizontal divergence field
+               ! in istate by a call to wzv routine
+            ENDIF
+            !                                    ! ===========================
+         CASE DEFAULT                            ! NONE existing configuration
+            !                                    ! ===========================
+            WRITE(ctmp1,*) 'EEL with a ', jp_cfg,' km resolution is not coded'
+            CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+   END SUBROUTINE istate_eel
+
+
+   SUBROUTINE istate_gyre
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE istate_gyre  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers for GYRE
+      !!      configuration (double gyre with rotated domain)
+      !!
+      !! ** Method  : - set temprature field
+      !!              - set salinity field
+      !!----------------------------------------------------------------------
+      INTEGER :: ji, jj, jk  ! dummy loop indices
+      INTEGER            ::   inum          ! temporary logical unit
+      INTEGER, PARAMETER ::   ntsinit = 0   ! (0/1) (analytical/input data files) T&S initialization
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( ntsinit)
+
+      CASE ( 0 )                  ! analytical T/S profil deduced from LEVITUS
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'istate_gyre : initial analytical T and S profil deduced from LEVITUS '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  tn(ji,jj,jk) = (  16. - 12. * TANH( (fsdept(ji,jj,jk) - 400) / 700 )         )   &
+                       &           * (-TANH( (500-fsdept(ji,jj,jk)) / 150 ) + 1) / 2               &
+                       &       + (      15. * ( 1. - TANH( (fsdept(ji,jj,jk)-50.) / 1500.) )       &
+                       &                - 1.4 * TANH((fsdept(ji,jj,jk)-100.) / 100.)               &    
+                       &                + 7.  * (1500. - fsdept(ji,jj,jk)) / 1500.             )   & 
+                       &           * (-TANH( (fsdept(ji,jj,jk) - 500) / 150) + 1) / 2
+                  tn(ji,jj,jk) = tn(ji,jj,jk) * tmask(ji,jj,jk)
+                  tb(ji,jj,jk) = tn(ji,jj,jk)
+
+                  sn(ji,jj,jk) =  (  36.25 - 1.13 * TANH( (fsdept(ji,jj,jk) - 305) / 460 )  )  &
+                     &              * (-TANH((500 - fsdept(ji,jj,jk)) / 150) + 1) / 2          &
+                     &          + (  35.55 + 1.25 * (5000. - fsdept(ji,jj,jk)) / 5000.         &
+                     &                - 1.62 * TANH( (fsdept(ji,jj,jk) - 60.  ) / 650. )       &
+                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 35.  ) / 100. )       &
+                     &                + 0.2  * TANH( (fsdept(ji,jj,jk) - 1000.) / 5000.)    )  &
+                     &              * (-TANH((fsdept(ji,jj,jk) - 500) / 150) + 1) / 2 
+                  sn(ji,jj,jk) = sn(ji,jj,jk) * tmask(ji,jj,jk)
+                  sb(ji,jj,jk) = sn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )                  ! T/S data fields read in dta_tem.nc/data_sal.nc files
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'istate_gyre : initial T and S read from dta_tem.nc/data_sal.nc files'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         IF(lwp) WRITE(numout,*) '              NetCDF FORMAT'
+
+         ! Read temperature field
+         ! ----------------------
+         CALL iom_open ( 'data_tem', inum )
+         CALL iom_get ( inum, jpdom_data, 'votemper', tn ) 
+         CALL iom_close( inum )
+
+         tn(:,:,:) = tn(:,:,:) * tmask(:,:,:) 
+         tb(:,:,:) = tn(:,:,:)
+
+         ! Read salinity field
+         ! -------------------
+         CALL iom_open ( 'data_sal', inum )
+         CALL iom_get ( inum, jpdom_data, 'vosaline', sn ) 
+         CALL iom_close( inum )
+
+         sn(:,:,:)  = sn(:,:,:) * tmask(:,:,:) 
+         sb(:,:,:)  = sn(:,:,:)
+
+      END SELECT
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '              Initial temperature and salinity profiles:'
+         WRITE(numout, "(9x,' level   gdept_0   temperature   salinity   ')" )
+         WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_0(jk), tn(2,2,jk), sn(2,2,jk), jk = 1, jpk )
+      ENDIF
+
+   END SUBROUTINE istate_gyre
+
+
+   SUBROUTINE istate_uvg
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE istate_uvg  ***
+      !!
+      !! ** Purpose :   Compute the geostrophic velocities from (tn,sn) fields
+      !!
+      !! ** Method  :   Using the hydrostatic hypothesis the now hydrostatic 
+      !!      pressure is computed by integrating the in-situ density from the
+      !!      surface to the bottom.
+      !!                 p=integral [ rau*g dz ]
+      !!----------------------------------------------------------------------
+      USE dynspg          ! surface pressure gradient             (dyn_spg routine)
+      USE divcur          ! hor. divergence & rel. vorticity      (div_cur routine)
+      USE lbclnk          ! ocean lateral boundary condition (or mpp link)
+
+      INTEGER ::   ji, jj, jk        ! dummy loop indices
+      INTEGER ::   indic             ! ???
+      REAL(wp) ::   zmsv, zphv, zmsu, zphu, zalfg     ! temporary scalars
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zprn     ! workspace
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*) 
+      IF(lwp) WRITE(numout,*) 'istate_uvg : Start from Geostrophy'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      ! Compute the now hydrostatic pressure
+      ! ------------------------------------
+
+      zalfg = 0.5 * grav * rau0
+      
+      zprn(:,:,1) = zalfg * fse3w(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
+
+      DO jk = 2, jpkm1                                              ! Vertical integration from the surface
+         zprn(:,:,jk) = zprn(:,:,jk-1)   &
+            &         + zalfg * fse3w(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
+      END DO  
+
+      ! Compute geostrophic balance
+      ! ---------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vertor opt.
+               zmsv = 1. / MAX(  umask(ji-1,jj+1,jk) + umask(ji  ,jj+1,jk)   &
+                               + umask(ji-1,jj  ,jk) + umask(ji  ,jj  ,jk) , 1.  )
+               zphv = ( zprn(ji  ,jj+1,jk) - zprn(ji-1,jj+1,jk) ) * umask(ji-1,jj+1,jk) / e1u(ji-1,jj+1)   &
+                    + ( zprn(ji+1,jj+1,jk) - zprn(ji  ,jj+1,jk) ) * umask(ji  ,jj+1,jk) / e1u(ji  ,jj+1)   &
+                    + ( zprn(ji  ,jj  ,jk) - zprn(ji-1,jj  ,jk) ) * umask(ji-1,jj  ,jk) / e1u(ji-1,jj  )   &
+                    + ( zprn(ji+1,jj  ,jk) - zprn(ji  ,jj  ,jk) ) * umask(ji  ,jj  ,jk) / e1u(ji  ,jj  )
+               zphv = 1. / rau0 * zphv * zmsv * vmask(ji,jj,jk)
+
+               zmsu = 1. / MAX(  vmask(ji+1,jj  ,jk) + vmask(ji  ,jj  ,jk)   &
+                               + vmask(ji+1,jj-1,jk) + vmask(ji  ,jj-1,jk) , 1.  )
+               zphu = ( zprn(ji+1,jj+1,jk) - zprn(ji+1,jj  ,jk) ) * vmask(ji+1,jj  ,jk) / e2v(ji+1,jj  )   &
+                    + ( zprn(ji  ,jj+1,jk) - zprn(ji  ,jj  ,jk) ) * vmask(ji  ,jj  ,jk) / e2v(ji  ,jj  )   &
+                    + ( zprn(ji+1,jj  ,jk) - zprn(ji+1,jj-1,jk) ) * vmask(ji+1,jj-1,jk) / e2v(ji+1,jj-1)   &
+                    + ( zprn(ji  ,jj  ,jk) - zprn(ji  ,jj-1,jk) ) * vmask(ji  ,jj-1,jk) / e2v(ji  ,jj-1)
+               zphu = 1. / rau0 * zphu * zmsu * umask(ji,jj,jk)
+
+               ! Compute the geostrophic velocities
+               un(ji,jj,jk) = -2. * zphu / ( ff(ji,jj) + ff(ji  ,jj-1) )
+               vn(ji,jj,jk) =  2. * zphv / ( ff(ji,jj) + ff(ji-1,jj  ) )
+            END DO
+         END DO
+      END DO
+
+      IF(lwp) WRITE(numout,*) '         we force to zero bottom velocity'
+
+      ! Susbtract the bottom velocity (level jpk-1 for flat bottom case)
+      ! to have a zero bottom velocity
+
+      DO jk = 1, jpkm1
+         un(:,:,jk) = ( un(:,:,jk) - un(:,:,jpkm1) ) * umask(:,:,jk)
+         vn(:,:,jk) = ( vn(:,:,jk) - vn(:,:,jpkm1) ) * vmask(:,:,jk)
+      END DO
+
+      CALL lbc_lnk( un, 'U', -1. )
+      CALL lbc_lnk( vn, 'V', -1. )
+      
+      ub(:,:,:) = un(:,:,:)
+      vb(:,:,:) = vn(:,:,:)
+      
+      ! WARNING !!!!!
+      ! after initializing u and v, we need to calculate the initial streamfunction bsf.
+      ! Otherwise, only the trend will be computed and the model will blow up (inconsistency).
+      ! to do that, we call dyn_spg with a special trick:
+      ! we fill ua and va with the velocities divided by dt, and the streamfunction will be brought to the
+      ! right value assuming the velocities have been set up in one time step.
+      ! we then set bsfd to zero (first guess for next step is d(psi)/dt = 0.)
+      !  sets up s false trend to calculate the barotropic streamfunction.
+
+      ua(:,:,:) = ub(:,:,:) / rdt
+      va(:,:,:) = vb(:,:,:) / rdt
+
+      ! calls dyn_spg. we assume euler time step, starting from rest.
+      indic = 0
+      CALL dyn_spg( nit000, indic )       ! surface pressure gradient
+
+      ! the new velocity is ua*rdt
+
+      CALL lbc_lnk( ua, 'U', -1. )
+      CALL lbc_lnk( va, 'V', -1. )
+
+      ub(:,:,:) = ua(:,:,:) * rdt
+      vb(:,:,:) = va(:,:,:) * rdt
+      ua(:,:,:) = 0.e0
+      va(:,:,:) = 0.e0
+      un(:,:,:) = ub(:,:,:)
+      vn(:,:,:) = vb(:,:,:)
+       
+#if defined key_dynspg_rl
+      IF( lk_isl )   bsfb(:,:) = bsfn(:,:)          ! Put bsfb to zero
+#endif
+
+      ! Compute the divergence and curl
+
+      CALL div_cur( nit000 )            ! now horizontal divergence and curl
+
+      hdivb(:,:,:) = hdivn(:,:,:)       ! set the before to the now value
+      rotb (:,:,:) = rotn (:,:,:)       ! set the before to the now value
+      !
+   END SUBROUTINE istate_uvg
+
+   !!=====================================================================
+END MODULE istate
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lbclnk.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lbclnk.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lbclnk.F90	(revision 4536)
@@ -0,0 +1,714 @@
+MODULE lbclnk
+   !!======================================================================
+   !!                       ***  MODULE  lbclnk  ***
+   !! Ocean        : lateral boundary conditions
+   !!=====================================================================
+#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR      MPI massively parallel processing library
+   !!   'key_mpp_shmem'         SHMEM massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk      : generic interface for mpp_lnk_3d and mpp_lnk_2d
+   !!                  routines defined in lib_mpp
+   !!   lbc_lnk_e    : generic interface for mpp_lnk_2d_e
+   !!                   routinee defined in lib_mpp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE lib_mpp          ! distributed memory computing library
+
+   INTERFACE lbc_lnk
+      MODULE PROCEDURE mpp_lnk_3d_gather, mpp_lnk_3d, mpp_lnk_2d
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e
+      MODULE PROCEDURE mpp_lnk_2d_e
+   END INTERFACE
+
+   PUBLIC lbc_lnk       ! ocean lateral boundary conditions
+   PUBLIC lbc_lnk_e
+   !!----------------------------------------------------------------------
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                              shared memory computing
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk      : generic interface for lbc_lnk_3d and lbc_lnk_2d
+   !!   lbc_lnk_3d   : set the lateral boundary condition on a 3D variable
+   !!                  on OPA ocean mesh
+   !!   lbc_lnk_2d   : set the lateral boundary condition on a 2D variable
+   !!                  on OPA ocean mesh
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers   
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE lbc_lnk
+      MODULE PROCEDURE lbc_lnk_3d_gather, lbc_lnk_3d, lbc_lnk_2d
+   END INTERFACE
+
+   INTERFACE lbc_lnk_e
+      MODULE PROCEDURE lbc_lnk_2d
+   END INTERFACE
+
+   PUBLIC lbc_lnk       ! ocean/ice  lateral boundary conditions
+   PUBLIC  lbc_lnk_e 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnk_3d_gather  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type1, cd_type2       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d1, pt3d2          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+
+      
+      !! * Local declarations
+      INTEGER  ::   ji, jk
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+      
+      !                                                      ! ===============
+      DO jk = 1, jpk                                         ! Horizontal slab
+         !                                                   ! ===============
+
+         !                                     ! East-West boundaries
+         !                                     ! ====================
+         SELECT CASE ( nperio )
+
+         CASE ( 1 , 4 , 6 )                    ! * cyclic east-west
+            pt3d1( 1 ,:,jk) = pt3d1(jpim1,:,jk)          ! all points
+            pt3d1(jpi,:,jk) = pt3d1(  2  ,:,jk)
+            pt3d2( 1 ,:,jk) = pt3d2(jpim1,:,jk)          
+            pt3d2(jpi,:,jk) = pt3d2(  2  ,:,jk)
+
+         CASE DEFAULT                          ! * closed
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d1( 1 ,:,jk) = 0.e0
+               pt3d1(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d1(jpi,:,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d2( 1 ,:,jk) = 0.e0
+               pt3d2(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d2(jpi,:,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+
+         CASE ( 2 )                            ! *  south symmetric
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d1(:, 1 ,jk) = pt3d1(:,3,jk)
+               pt3d1(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d1(:, 1 ,jk) = psgn * pt3d1(:,2,jk)
+               pt3d1(:,jpj,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d2(:, 1 ,jk) = pt3d2(:,3,jk)
+               pt3d2(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d2(:, 1 ,jk) = psgn * pt3d2(:,2,jk)
+               pt3d2(:,jpj,jk) = 0.e0
+            END SELECT
+
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+
+            pt3d1( 1 ,jpj,jk) = 0.e0
+            pt3d1(jpi,jpj,jk) = 0.e0
+            pt3d2( 1 ,jpj,jk) = 0.e0
+            pt3d2(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d1(ji,jpjm1,jk) = psgn * pt3d1(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d1(ji,jpjm1,jk) = psgn * pt3d1(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d1(ji,  1  ,jk) = 0.e0
+                     pt3d1(ji,jpj-1,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d1(ji,jpj-1,jk) = psgn * pt3d1(iju,jpj-2,jk)
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d2(ji,jpjm1,jk) = psgn * pt3d2(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d2(ji,jpjm1,jk) = psgn * pt3d2(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d2(ji,  1  ,jk) = 0.e0
+                     pt3d2(ji,jpj-1,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d2(ji,jpj-1,jk) = psgn * pt3d2(iju,jpj-2,jk)
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+
+            pt3d1( 1 ,jpj,jk) = 0.e0
+            pt3d1(jpi,jpj,jk) = 0.e0
+            pt3d2( 1 ,jpj,jk) = 0.e0
+            pt3d2(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d1(ji, 1 ,jk) = 0.e0
+                  pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji, 1 ,jk) = 0.e0
+                     pt3d1(ji,jpj,jk) = psgn * pt3d1(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d1(ji, 1 ,jk) = 0.e0
+                     pt3d1(ji,jpj,jk) = psgn * pt3d1(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d1(ji,jpjm1,jk) = psgn * pt3d1(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji,jpj  ,jk) = psgn * pt3d1(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d1(ji,jpjm1,jk) = psgn * pt3d1(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d2(ji, 1 ,jk) = 0.e0
+                  pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji, 1 ,jk) = 0.e0
+                     pt3d2(ji,jpj,jk) = psgn * pt3d2(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d2(ji, 1 ,jk) = 0.e0
+                     pt3d2(ji,jpj,jk) = psgn * pt3d2(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d2(ji,jpjm1,jk) = psgn * pt3d2(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji,jpj  ,jk) = psgn * pt3d2(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d2(ji,jpjm1,jk) = psgn * pt3d2(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+
+         CASE DEFAULT                          ! *  closed
+
+            SELECT CASE ( cd_type1 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d1(:, 1 ,jk) = 0.e0
+               pt3d1(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d1(:,jpj,jk) = 0.e0
+            END SELECT
+            SELECT CASE ( cd_type2 )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d2(:, 1 ,jk) = 0.e0
+               pt3d2(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d2(:,jpj,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+         !                                                   ! ===============
+      END DO                                                 !   End of slab
+      !                                                      ! ===============
+
+   END SUBROUTINE lbc_lnk_3d_gather
+
+
+   SUBROUTINE lbc_lnk_3d( pt3d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE lbc_lnk_3d  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is changed if north fold boundary
+         !             !   = 1 , no sign change
+         !             !   = 0 , no sign change and > 0 required (use the inner
+         !             !         row/column if closed boundary)
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+
+      !! * Local declarations
+      INTEGER  ::   ji, jk
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+      !!----------------------------------------------------------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE
+      
+      !                                                      ! ===============
+      DO jk = 1, jpk                                         ! Horizontal slab
+         !                                                   ! ===============
+
+         !                                     ! East-West boundaries
+         !                                     ! ====================
+         SELECT CASE ( nperio )
+
+         CASE ( 1 , 4 , 6 )                    ! * cyclic east-west
+            pt3d( 1 ,:,jk) = pt3d(jpim1,:,jk)          ! all points
+            pt3d(jpi,:,jk) = pt3d(  2  ,:,jk)
+
+         CASE DEFAULT                          ! * closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d( 1 ,:,jk) = 0.e0
+               pt3d(jpi,:,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d(jpi,:,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+
+         !                                     ! North-South boundaries
+         !                                     ! ======================
+         SELECT CASE ( nperio )
+
+         CASE ( 2 )                            ! *  south symmetric
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
+               pt3d(:, 1 ,jk) = pt3d(:,3,jk)
+               pt3d(:,jpj,jk) = 0.e0
+            CASE ( 'V' , 'F' )                         ! V-, F-points
+               pt3d(:, 1 ,jk) = psgn * pt3d(:,2,jk)
+               pt3d(:,jpj,jk) = 0.e0
+            END SELECT
+
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+
+            pt3d( 1 ,jpj,jk) = 0.e0
+            pt3d(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpi
+                  ijt = jpi-ji+2
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-2,jk)
+               END DO
+               DO ji = jpi/2+1, jpi
+                  ijt = jpi-ji+2
+                  pt3d(ji,jpjm1,jk) = psgn * pt3d(ijt,jpjm1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpi-1
+                  iju = jpi-ji+1
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(iju,jpj-2,jk)
+               END DO
+               DO ji = jpi/2, jpi-1
+                  iju = jpi-ji+1
+                  pt3d(ji,jpjm1,jk) = psgn * pt3d(iju,jpjm1,jk)
+               END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 2, jpi
+                     ijt = jpi-ji+2
+                     pt3d(ji,  1  ,jk) = 0.e0
+                     pt3d(ji,jpj-1,jk) = psgn * pt3d(ijt,jpj-2,jk)
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(ijt,jpj-3,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji+1
+                     pt3d(ji,jpj-1,jk) = psgn * pt3d(iju,jpj-2,jk)
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(iju,jpj-3,jk)
+                  END DO
+            END SELECT
+
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+
+            pt3d( 1 ,jpj,jk) = 0.e0
+            pt3d(jpi,jpj,jk) = 0.e0
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpi
+                  ijt = jpi-ji+1
+                  pt3d(ji, 1 ,jk) = 0.e0
+                  pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-1,jk)
+               END DO
+            CASE ( 'U' )                               ! U-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji, 1 ,jk) = 0.e0
+                     pt3d(ji,jpj,jk) = psgn * pt3d(iju,jpj-1,jk)
+                  END DO
+            CASE ( 'V' )                               ! V-point
+                  DO ji = 1, jpi
+                     ijt = jpi-ji+1
+                     pt3d(ji, 1 ,jk) = 0.e0
+                     pt3d(ji,jpj,jk) = psgn * pt3d(ijt,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi
+                     ijt = jpi-ji+1
+                     pt3d(ji,jpjm1,jk) = psgn * pt3d(ijt,jpjm1,jk)
+                  END DO
+            CASE ( 'F' )                               ! F-point
+                  DO ji = 1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji,jpj  ,jk) = psgn * pt3d(iju,jpj-2,jk)
+                  END DO
+                  DO ji = jpi/2+1, jpi-1
+                     iju = jpi-ji
+                     pt3d(ji,jpjm1,jk) = psgn * pt3d(iju,jpjm1,jk)
+                  END DO
+            END SELECT
+
+         CASE DEFAULT                          ! *  closed
+
+            SELECT CASE ( cd_type )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               pt3d(:, 1 ,jk) = 0.e0
+               pt3d(:,jpj,jk) = 0.e0
+            CASE ( 'F' )                               ! F-point
+               pt3d(:,jpj,jk) = 0.e0
+            END SELECT
+
+         END SELECT
+         !                                                   ! ===============
+      END DO                                                 !   End of slab
+      !                                                      ! ===============
+   ENDIF
+   END SUBROUTINE lbc_lnk_3d
+
+
+   SUBROUTINE lbc_lnk_2d( pt2d, cd_type, psgn, cd_mpp )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE lbc_lnk_2d  ***
+      !!
+      !! ** Purpose :   set lateral boundary conditions (non mpp case)
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!        !  97-06  (G. Madec)  Original code
+      !!        !  01-05  (E. Durand)  correction
+      !!   8.5  !  02-09  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-point
+         !             !   = T , U , V , F or W  gridpoints
+         !             !   = I sea-ice U-V gridpoint (= F ocean grid point with indice shift)
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   =-1 , the sign is modified following the type of b.c. used
+         !             !   = 1 , no sign change
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only (here do nothing)
+
+      !! * Local declarations
+      INTEGER  ::   ji
+      INTEGER  ::   ijt, iju
+      !!----------------------------------------------------------------------
+      !!  OPA 8.5, LODYC-IPSL (2002)
+      !!----------------------------------------------------------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+      ELSE      
+      
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      SELECT CASE ( nperio )
+
+      CASE ( 1 , 4 , 6 )                       ! * cyclic east-west
+         pt2d( 1 ,:) = pt2d(jpim1,:)
+         pt2d(jpi,:) = pt2d(  2  ,:)
+
+      CASE DEFAULT                             ! * closed 
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'V' , 'W' )                ! T-, U-, V-, W-points
+            pt2d( 1 ,:) = 0.e0
+            pt2d(jpi,:) = 0.e0
+         CASE ( 'F' )                                  ! F-point, ice U-V point
+            pt2d(jpi,:) = 0.e0 
+         CASE ( 'I' )                                  ! F-point, ice U-V point
+            pt2d( 1 ,:) = 0.e0 
+            pt2d(jpi,:) = 0.e0 
+         END SELECT
+
+      END SELECT
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( nperio )
+
+      CASE ( 2 )                               ! * South symmetric
+
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'W' )                      ! T-, U-, W-points
+            pt2d(:, 1 ) = pt2d(:,3)
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'V' , 'F' , 'I' )                      ! V-, F-points, ice U-V point
+            pt2d(:, 1 ) = psgn * pt2d(:,2)
+            pt2d(:,jpj) = 0.e0
+         END SELECT
+
+      CASE ( 3 , 4 )                           ! * North fold  T-point pivot
+
+         pt2d( 1 , 1 ) = 0.e0        !!!!!  bug gm ??? !Edmee
+         pt2d( 1 ,jpj) = 0.e0
+         pt2d(jpi,jpj) = 0.e0
+
+         SELECT CASE ( cd_type )
+
+         CASE ( 'T' , 'W' )                            ! T-, W-point
+            DO ji = 2, jpi
+               ijt = jpi-ji+2
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi-ji+2
+               pt2d(ji,jpjm1) = psgn * pt2d(ijt,jpjm1)
+            END DO
+
+         CASE ( 'U' )                                  ! U-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-2)
+            END DO
+            DO ji = jpi/2, jpi-1
+               iju = jpi-ji+1
+               pt2d(ji,jpjm1) = psgn * pt2d(iju,jpjm1)
+            END DO
+
+         CASE ( 'V' )                                  ! V-point
+            DO ji = 2, jpi
+               ijt = jpi-ji+2
+               pt2d(ji, 1   ) = 0.e0
+               pt2d(ji,jpj-1) = psgn * pt2d(ijt,jpj-2)
+               pt2d(ji,jpj  ) = psgn * pt2d(ijt,jpj-3)
+            END DO
+
+         CASE ( 'F' )                                  ! F-point
+            DO ji = 1, jpi-1
+               iju = jpi - ji + 1
+               pt2d(ji,jpj-1) = psgn * pt2d(iju,jpj-2)
+               pt2d(ji,jpj  ) = psgn * pt2d(iju,jpj-3)
+            END DO
+
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d(:, 1 ) = 0.e0
+            pt2d(2,jpj) = psgn * pt2d(3,jpj-1)
+            DO ji = 3, jpi
+               iju = jpi - ji + 3
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-1)
+            END DO
+
+         END SELECT
+
+      CASE ( 5 , 6 )                           ! * North fold  F-point pivot
+
+         pt2d( 1 , 1 ) = 0.e0           !!bug  ???
+         pt2d( 1 ,jpj) = 0.e0
+         pt2d(jpi,jpj) = 0.e0
+
+         SELECT CASE ( cd_type )
+
+         CASE ( 'T' , 'W' )                            ! T-, W-point
+            DO ji = 1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-1)
+            END DO
+
+         CASE ( 'U' )                                  ! U-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(iju,jpj-1)
+            END DO
+
+         CASE ( 'V' )                                  ! V-point
+            DO ji = 1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji, 1 ) = 0.e0
+               pt2d(ji,jpj) = psgn * pt2d(ijt,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi-ji+1
+               pt2d(ji,jpjm1) = psgn * pt2d(ijt,jpjm1)
+            END DO
+
+         CASE ( 'F' )                                  ! F-point
+            DO ji = 1, jpi-1
+               iju = jpi-ji
+               pt2d(ji,jpj  ) = psgn * pt2d(iju,jpj-2)
+            END DO
+            DO ji = jpi/2+1, jpi-1
+               iju = jpi-ji
+               pt2d(ji,jpjm1) = psgn * pt2d(iju,jpjm1)
+            END DO
+
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d( : , 1 ) = 0.e0
+            pt2d( 2 ,jpj) = 0.e0
+            DO ji = 2 , jpim1
+               ijt = jpi - ji + 2
+               pt2d(ji,jpj)= 0.5 * ( pt2d(ji,jpjm1) + psgn * pt2d(ijt,jpjm1) )
+            END DO
+
+         END SELECT
+
+      CASE DEFAULT                             ! * closed
+
+         SELECT CASE ( cd_type )
+         CASE ( 'T' , 'U' , 'V' , 'W' )                ! T-, U-, V-, W-points
+            pt2d(:, 1 ) = 0.e0
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'F' )                                  ! F-point
+            pt2d(:,jpj) = 0.e0
+         CASE ( 'I' )                                  ! ice U-V point
+            pt2d(:, 1 ) = 0.e0
+            pt2d(:,jpj) = 0.e0
+         END SELECT
+
+      END SELECT
+
+      ENDIF
+      
+   END SUBROUTINE lbc_lnk_2d
+
+#endif
+
+   !!======================================================================
+END MODULE lbclnk
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_cray.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_cray.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_cray.f90	(revision 4536)
@@ -0,0 +1,61 @@
+!  Cray subroutines or functions used by OPA model and possibly 
+!  not found on other platforms.
+!
+!  check their existence
+!  
+!  sdot
+!  wheneq
+!  saxpy
+!  isrchne
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+!---------------------------------------------------------
+     FUNCTION sdot( I, X, J, Y, K )
+        DIMENSION X(1), Y(1)
+        SDOT = 0.
+        DO N = 1, I
+        SDOT = SDOT + X(1+(N-1)*J) * Y(1+(N-1)*K)
+        END DO
+     END FUNCTION sdot
+!---------------------------------------------------------
+     SUBROUTINE wheneq ( i, x, j, t, ind, nn )
+        IMPLICIT NONE
+
+        INTEGER , INTENT (  in ) :: i, j
+        INTEGER , INTENT ( out ) :: nn
+        REAL    , INTENT (  in ), DIMENSION (1+(i-1)*j) :: x
+        REAL    , INTENT (  in ) :: t
+        INTEGER , INTENT ( out ), DIMENSION (1+(i-1)*j) :: ind
+        INTEGER :: n, k
+        nn = 0
+        DO n = 1, i
+          k = 1 + (n-1) * j
+          IF ( x ( k) == t ) THEN 
+              nn = nn + 1
+              ind (nn) = k
+          ENDIF
+        END DO 
+
+     END SUBROUTINE wheneq
+!---------------------------------------------------------
+     SUBROUTINE saxpy( I, A, X, J, Y, K )
+        DIMENSION X(1),Y(1)
+        DO N = 1, I
+           Y(1+(N-1)*K)=A*X(1+(N-1)*J)+Y(1+(N-1)*K)
+        END DO
+     END SUBROUTINE saxpy
+!---------------------------------------------------------
+     FUNCTION isrchne( K, X, I, B )
+        DIMENSION X(1)
+        DO N = 1, K
+           IF( X(1+(N-1)*I) /= B ) THEN
+              ISRCHNE = N
+              RETURN
+           ELSE
+              ISRCHNE = N + 1
+           ENDIF
+        END DO
+     END FUNCTION isrchne
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_feti.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_feti.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_feti.F90	(revision 4536)
@@ -0,0 +1,2318 @@
+MODULE lib_feti
+   !!==============================================================================
+   !!                       ***  MODULE lib_feti   ***
+   !! Ocean solver : FETI library
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_feti
+   !!  feti_creadr
+   !!  feti_prext
+   !!  feti_init
+   !!  feti_iclr
+   !!  feti_vclr
+   !!  feti_vmov
+   !!  feti_vneg    (used in lib_feti)
+   !!  feti_vsub
+   !!  feti_vadd    (used in lib_feti)
+   !!  feti_ldlt    (used in lib_feti)
+   !!  feti_desremo (used in lib_feti)
+   !!  feti_mxv     (used in lib_feti)
+   !!  feti_mxvadd  (used in lib_feti)
+   !!  feti_saut    (used in lib_feti)
+   !!  feti_moyen   (used in lib_feti)
+   !!  feti_assemb  (used in lib_feti)
+   !!  feti_poids
+   !!  feti_probit  (used in lib_feti)
+   !!  feti_inisub
+   !!  feti_subound
+   !!  feti_subdir
+   !!  feti_listdir
+   !!  feti_blodir
+   !!  feti_numblo
+   !!  feti_blomat
+   !!  feti_blomat1
+   !!  feti_nullsp
+   !!  feti_project (used in lib_feti)
+   !!  feti_etesolv (used in lib_feti)
+   !!  feti_osaxpy  (used in lib_feti) 
+   !!  feti_proe    (used in lib_feti)
+   !!  feti_proet   (used in lib_feti)
+   !!  feti_consrhs (used in lib_feti)
+   !!  feti_dualschur
+   !!  feti_extend  (used in lib_feti)
+   !!  feti_restri  (used in lib_feti)
+   !!  feti_halfint
+   !!  feti_front
+   !!  feti_calinv  (used in lib_feti)
+   !!  feti_nbdia   (used in lib_feti)
+   !!  feti_liblod  (used in lib_feti)
+   !!  feti_liblos  (used in lib_feti)
+   !!  feti_resloc
+   !!  feti_pblos   (used in lib_feti)
+   !!  feti_pbloi   (used in lib_feti) 
+   !!  feti_proax
+   !!
+   !!  EXTERNAL used (BLAS): sgemv, strsv, saxpy, irecv
+   !!
+   !! References :
+   !!      Guyon, M, Roux, F-X, Chartier, M and Fraunie, P, 1994 :
+   !!      A domain decomposition solver to compute the barotropic 
+   !!      component of an OGCM in the parallel processing field.
+   !!      Ocean Modelling, issue 105, december 94.
+   !!
+   !! Modifications :
+   !!      original :  98-02 (M. Guyon)
+   !!------------------------------------------------------------------------
+   !! * Modules used
+   USE lib_mpp                 ! distribued memory computing
+
+CONTAINS
+
+      subroutine feti_creadr(ial,ialmax,lmax,ltab,iatab,chtab)
+!  ial = derniere adresse libre dans le super-tableau de longueur lmax .
+!  ltab = taille de la structure de donnee tab , d'adresse iatab .
+      implicit none
+      external mynode
+
+      integer ial,ialmax,lmax,ltab,iatab
+      integer iialmax,iibidon,mynode
+      character(len=12) chtab
+
+      iatab=ial
+      ial=iatab+ltab
+      ialmax=max0(ial,ialmax)
+      if(ial > lmax) then 
+          write(0,*)'  creation de la structure de donnee ',chtab
+          write(0,*)'  depassement taille super-tableau :'
+          write(0,*)'  taille maximale , taille demandee :',lmax,ial
+          stop
+      endif
+
+!... test de la memoire
+
+      iialmax=-ialmax
+      call mpp_min(iialmax,1,iibidon)
+      iialmax=-iialmax
+!     if(mynode() == 0)then
+!         write(0,*)'  creation de la structure de donnee ',chtab
+!         write(0,*)'taille max vaut : ',iialmax
+!     endif
+
+      end subroutine feti_creadr
+!***********************************************************************
+      subroutine feti_prext(n,x)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n)
+      REAL(kind=8)   xmin,xmax
+      integer i
+
+      xmin=x(1)
+      xmax=x(1)
+      do i=2,n
+        xmin=min(xmin,x(i))
+        xmax=max(xmax,x(i))
+      end do
+!     write(0,100)xmin,xmax
+ 100  format(8d10.3)
+
+      end subroutine feti_prext
+!*********************************************************************
+      subroutine feti_init(noeuds,x)
+      implicit none
+      integer noeuds
+      REAL(kind=8)  x(noeuds)
+      integer ji
+
+      do ji=1,noeuds
+        x(ji)=1.
+      end do
+
+      end subroutine feti_init
+!***********************************************************************
+      subroutine feti_iclr(n,x)
+      implicit none
+      integer n
+      integer x(n)
+      integer i
+
+      do i=1,n
+        x(i)=0
+      end do
+
+      end subroutine feti_iclr
+!***********************************************************************
+      subroutine feti_vclr(n,x)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n)
+      integer i
+
+      do i=1,n
+        x(i)=0.e0
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_vmov(n,x,y)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n),y(n)
+      integer i
+      do i=1,n
+        y(i)=x(i)
+      end do
+      return
+      end
+!***********************************************************************
+      subroutine feti_vneg(n,x,y)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n),y(n)
+      integer i
+
+      do i=1,n
+        y(i)=-x(i)
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_vsub(n,x,y,z)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n),y(n),z(n)
+      integer i
+      do i=1,n
+        z(i)=x(i)-y(i)
+      end do
+      return
+      end
+!***********************************************************************
+      subroutine feti_vadd(n,x,y,z)
+      implicit none
+      integer n
+      REAL(kind=8)  x(n),y(n),z(n)
+      integer i
+
+      do i=1,n
+        z(i)=y(i)+x(i)
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_ldlt(n,a,d,v,ndlblo,lisblo,nmdlblo,j0)
+
+!...ndlblo nombre de liberte bloques = nombre de pivots nuls = dim(Ker(Ep))
+
+!...nmdlblo = Max (ndlblo(Ep)) <= superstructure management in f77 context
+!            p=1,Np
+
+      implicit none
+      integer n,ndlblo,nmdlblo
+      integer j0
+      REAL(kind=8)  a(n,n),v(n),d(n)
+      integer lisblo(nmdlblo)
+      integer i,j,k
+      REAL(kind=8)  piv,epsilo
+
+!  pivot de reference .
+      piv=a(1,1)
+!  epsilon .
+      epsilo=1.e-10
+!  factorisation de Crout d'une matrice pleine .
+      do j = 1 , n
+!  calcul du produit de la ligne numero j par la diagonale .
+        do k = 1 , j - 1
+          v(k) = a(j,k) * a(k,k)
+        end do
+!  calcul des termes de la partie inferieure de la colonne .
+        call sgemv('N',n-j+1,j-1,-1.e0,a(j,1),n,v,1,1.e0,a(j,j),1)
+!  detection des pivots nuls .
+        if(a(j,j) < (piv*epsilo)) then
+            ndlblo=ndlblo+1
+            lisblo(ndlblo)=j0+j
+            do i=1,j-1
+              a(i,j)=0.e0
+            end do
+            do i=j+1,n
+              a(j,i)=0.e0
+            end do
+            a(j,j)=0.e0
+            d(j)=0.e0
+        else
+            piv=a(j,j)
+            d(j)=1.e0/a(j,j)
+            do i = j+1 , n
+              a(i,j) = a(i,j) * d(j)
+            end do
+        endif
+      end do
+!  recopie de la partie triangulaire superieure .
+      do i = 1, n
+        do j = i+1, n
+          a(i,j)=a(j,i)
+        end do
+      end do
+      do i=1,n
+        a(i,i)=d(i)
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_desremo(n,j0,a,y,x) 
+      implicit none
+      integer n,i,j,j0
+      REAL(kind=8)  a(n,n),x(n),y(n)
+
+!  descente remontee du systeme .
+!  initialisation du vecteur resultat .
+      do i=1,n
+        x(i)=y(i)
+      end do
+!  descente du systeme L x = x , L est a diagonale unitaire .
+      call strsv('L','N','U',n-j0,a(j0+1,j0+1),n,x(j0+1),1)
+!  division par la diagonale .
+      do j=j0+1,n
+        x(j)=x(j)*a(j,j)
+      end do          
+!  remontee du systeme U x = x , U est a diagonale unitaire . 
+      call strsv('U','N','U',n-j0,a(j0+1,j0+1),n,x(j0+1),1)
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_mxv(n,m,a,x,y) 
+!  calcul du produit matrice-vecteur :  y = A x
+      implicit none
+      integer n,m
+      REAL(kind=8)  a(n,m),x(m),y(n)
+      REAL(kind=8)  alpha,beta
+!  initialisation du vecteur y .
+      alpha=1.e0
+      beta=0.e0
+      call sgemv('N',n,m,alpha,a,n,x,1,beta,y,1)
+      return
+      end
+!**********************************************************************c
+      subroutine feti_mxvadd(n,m,a,x,y) 
+!  calcul du produit matrice-vecteur :  y = y + A x
+      implicit none
+      integer n,m
+      REAL(kind=8)  a(n,m),x(m),y(n)
+      REAL(kind=8)  alpha,beta
+!  initialisation du vecteur y .
+
+      alpha=1.e0
+      beta=1.e0
+      if((n > 0).and.(m > 0))then
+          call sgemv('N',n,m,alpha,a,n,x,1,beta,y,1)
+      endif
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_saut(numnes,listnes,    &
+          plistin,numins,listin,              &
+                numnos,v,w,bufin,bufout)
+!!        narea,numnos,v,w,bufin,bufout)
+
+!  computation of the jump of a field on the interfaces, in the case 
+!  where subdomain number i is allocated to processor number i-1 .
+
+!     INPUTS : numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               lint    =  list of inner interfaces
+!               lext    =  list of extern interfaces
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               narea     =  subdomain number
+!               numnos  =  number of nodes in the subdomain
+!               v       =  local field
+
+!     OUTPUTS : w  =  jump of v
+
+!     WORKSPACE : bufin   =  contributions of local field on interface
+!                 bufout  =  contributions of outer fields on interface
+!                 work
+      implicit none 
+!      external irecv
+!!    integer irecv, work(100)
+!!    integer numnes,numins,numnos,narea
+      integer numnes,numins,numnos
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  v(numnos),w(numins)
+      REAL(kind=8)  bufin(numins),bufout(numins)
+      integer i,j,l
+      integer mesg
+
+      mesg=128
+!  receiving the values of the outer fields on the interface
+!     do i=1,numnes
+!       l=(plistin(i+1)-plistin(i))*8
+!       work(i)=irecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+!     end do
+!  gathering the values of the local field on the interface
+      do i=1,numnes
+        do j=plistin(i)+1,plistin(i+1)
+          bufin(j)=v(listin(j))
+        end do
+      end do
+!  sending the values of the local field on the interface
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))*8
+!       call mppsend(mesg+narea-1,bufin(plistin(i)+1),l,listnes(i)-1,0)
+        call mppsend(mesg+listnes(i,3)-1,bufin(plistin(i)+1),l,   &
+            listnes(i,1)-1,0)
+      end do
+!  computing the jump on each interface 
+      do i=1,numnes
+!       call msgwait(work(i))
+        l=(plistin(i+1)-plistin(i))*8
+!       call mpprecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+        call mpprecv(mesg+listnes(i,2)-1,bufout(plistin(i)+1),l)
+      end do
+      do j=1,numins
+        w(j)=bufin(j)-bufout(j)
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_moyen(numnes,listnes,   &
+          plistin,numins,listin,              &
+          narea,numnos,weight,v,w,bufin,bufout)
+
+!  averaging a field on the interfaces, in the case where subdomain
+!  number i is allocated to processor number i-1 .
+
+!     INPUTS : numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               lint    =  list of inner interfaces
+!               lext    =  list of extern interfaces
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               narea    =  subdomain number
+!               numnos  =  number of nodes in the subdomain
+!               weight  =  weighting vector
+!               v       =  local field
+
+!     OUTPUTS :      w  =  averaged field
+
+!     WORKSPACE : bufin   =  contributions of local field on interface
+!                 bufout  =  contributions of outer fields on interface
+!                 work
+      implicit none 
+!     external irecv
+!!    integer irecv, work(100)
+      integer numnes,numins,numnos,narea
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  weight(numnos),v(numnos),w(numnos)
+      REAL(kind=8)  bufin(numins),bufout(numins)
+      integer i,j,l,n
+      integer mesg
+
+      mesg=128*2
+!  initialization
+      call feti_vmov(numnos,v,w)
+!  receiving the values of the outer fields on the interface
+!     do i=1,numnes
+!       l=(plistin(i+1)-plistin(i))*8
+!       work(i)=irecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+!     end do
+!  gathering the values of the local field on the interface
+      do i=1,numnes
+        do j=plistin(i)+1,plistin(i+1)
+          bufin(j)=v(listin(j))
+        end do
+      end do
+!  sending the values of the local field on the interface
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))*8
+!       call mppsend(mesg+narea-1,bufin(plistin(i)+1),l,listnes(i)-1,0)
+        call mppsend(mesg+listnes(i,3)-1,bufin(plistin(i)+1),l,   &
+            listnes(i,1)-1,0)
+      end do
+!  computing the jump on each interface 
+      do i=1,numnes
+!       call msgwait(work(i))
+        l=(plistin(i+1)-plistin(i))*8
+!       call mpprecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+        call mpprecv(mesg+listnes(i,2)-1,bufout(plistin(i)+1),l)
+      end do
+      do j=1,numins
+        n=listin(j)
+        w(n)=w(n)+bufout(j)
+      end do
+      do n=1,numnos
+        w(n)=w(n)*weight(n)
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_assemb(numnes,listnes,   &
+          plistin,numins,listin,               &
+          narea,numnos,v,w,bufin,bufout)
+
+!  assembling a field on the interfaces, in the case where subdomain
+!  number i is allocated to processor number i-1 .
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               lint    =  list of inner interfaces
+!               lext    =  list of extern interfaces
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               narea     =  subdomain number
+!               numnos  =  number of nodes in the subdomain
+!               v       =  unassembled field
+
+!     OUTPUTS :      w  =  assembled field
+
+!     WORKSPACE : bufin   =  contributions of local field on interface
+!                 bufout  =  contributions of outer fields on interface
+!                 work
+      implicit none 
+!      external irecv
+!!    integer irecv, work(100)
+      integer numnes,numins,numnos,narea
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  v(numnos),w(numnos)
+      REAL(kind=8)  bufin(numins),bufout(numins)
+      integer i,j,l,n
+      integer mesg
+
+      mesg=128*3
+!  initialization
+      call feti_vmov(numnos,v,w)
+!  receiving the values of the outer fields on the interface
+!     do i=1,numnes
+!       l=(plistin(i+1)-plistin(i))*8
+!       work(i)=irecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+!     end do
+!  gathering the values of the local field on the interface
+      do i=1,numnes
+        do j=plistin(i)+1,plistin(i+1)
+          bufin(j)=v(listin(j))
+        end do
+      end do
+!  sending the values of the local field on the interface
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))*8
+!       write(90,*)'envoie a ',listnes(i),'de ',l,'octets'
+!       write(90,*)'tag est : ',listnes(i,3)
+!       call mppsend(mesg+narea-1,bufin(plistin(i)+1),l,listnes(i)-1,0)
+        call mppsend(mesg+listnes(i,3)-1,bufin(plistin(i)+1),l,   &
+            listnes(i,1)-1,0)
+      end do
+!  computing the jump on each interface 
+      do i=1,numnes
+!       call msgwait(work(i))
+        l=(plistin(i+1)-plistin(i))*8
+!       write(90,*)'recoie de ',listnes(i),'de ',l,'octets'
+!       write(90,*)'recois avec tag :',listnes(i,2)
+!       call mpprecv(mesg+listnes(i)-1,bufout(plistin(i)+1),l)
+        call mpprecv(mesg+listnes(i,2)-1,bufout(plistin(i)+1),l)
+      end do
+      do j=1,numins
+        n=listin(j)
+        w(n)=w(n)+bufout(j)
+      end do
+
+      return
+      end
+!**********************************************************************c
+!!    subroutine feti_poids(numnes,listnes,plistin,numins,listin,   &
+!!        narea,numnos,w,bufin,bufout)
+      subroutine feti_poids(numnes,                numins,listin,   &
+                numnos,w             )
+
+!  computation of the subdomain weighting vector, in the case where 
+!  subdomain number i is allocated to processor number i-1 .
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               narea     =  subdomain number
+!               numnos  =  number of nodes in the subdomain
+
+!     OUTPUTS :      w  =  weighting vector
+
+!     WORKSPACE : bufin   =  contributions of local field on interface
+!                 bufout  =  contributions of outer fields on interface
+!                 work
+      implicit none 
+!!    integer numnes,numins,numnos,narea
+      integer numnes,numins,numnos
+!!    integer listnes(numnes), plistin(numnes+1), listin(numins)
+      integer                                     listin(numins)
+      REAL(kind=8)  w(numnos)
+!!    REAL(kind=8)  bufin(numins),bufout(numins)
+      integer j,n
+
+!  initialization
+      do n=1,numnos
+        w(n)=1.e0
+      end do
+!  computing the weight on each interface 
+      do j=1,numins
+        n=listin(j)
+        w(n)=w(n)+1.e0
+      end do
+      do n=1,numnos
+        w(n)=1.e0/w(n)
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_probit(numnes,listnes,plistin,numins,listin,   &
+          numnos,w,bitw)
+
+!  computing the local right-hand-side associated with a field
+!  on the interface .
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               numnos  =  number of nodes in the subdomain
+!               w       =  interface field
+
+!     OUTPUTS :      bitw  =  local right-hand side
+
+      implicit none 
+      integer numnes,numins,numnos
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  w(numins)
+      REAL(kind=8)  bitw(numnos)
+      integer i,j,n
+
+!  initialization
+      do n=1,numnos
+        bitw(n)=0.e0
+      end do
+!  assembling the values on the interfaces 
+      do i=1,numnes
+        do j=plistin(i)+1,plistin(i+1)
+          n=listin(j)
+          bitw(n)=bitw(n)+w(j)
+        end do
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_inisub(ni,nj,ibondi,ibondj,iperio,   &
+          ibsw,ibnw,ibse,ibne,                             &
+          ninterf,ninterfc,nni,nnic)
+      implicit none
+      integer ni,nj,ibondi,ibondj,iperio
+      integer ibsw,ibnw,ibse,ibne
+      integer ibsw2,ibnw2,ibse2,ibne2
+      integer ninterf,ninterfc,nni,nnic
+!     integer i,j
+
+!  determination de la position du sous-domaine dans la grille
+!  cela depnd de ibondi et ibondj
+
+!  nombre de sous-domaines voisins et de la longueur du tableau des
+!  noeuds voisins
+
+!  initialisation
+
+      ninterf=0
+      nni=0
+
+!...first, the "segment-points"
+
+      if((ibondi == 2).AND.(iperio /= 1))then
+
+!  la periodicite : pas d'interface east / west si nbondi = 2
+!  ET nperio != 1
+
+!      elseif(iperio == 1) then
+
+!...ca doit marcher!?
+
+      else
+
+!  west
+
+          if(ibondi /= -1)then
+              ninterf=ninterf+1
+              nni=nni+nj+1
+          endif
+
+!  east
+
+          if(ibondi /= 1)then
+              ninterf=ninterf+1
+              nni=nni+nj+1
+          endif
+
+      endif
+
+!  south
+
+      if(ibondj /= -1.AND.ibondj /= 2)then
+          ninterf=ninterf+1
+          nni=nni+ni+1
+      endif
+
+!  north
+
+      if(ibondj /= 1.AND.ibondj /= 2)then
+          ninterf=ninterf+1
+          nni=nni+ni+1
+      endif
+
+      nnic=nni
+      ninterfc=ninterf
+
+
+!...second, the "corner-points"
+
+!...determination of the neighboorings, they depends on iperio
+!   boundary condition => local description : ipXX becomes ipXX2...
+
+      ibnw2 = ibnw
+      ibne2 = ibne
+      ibsw2 = ibsw
+      ibse2 = ibse
+
+!...iperio boundary condition effect
+
+      if(iperio == 1) then
+
+!...general case : Earth == infinite tube
+
+          ibnw2 = 1
+          ibne2 = 1
+          ibsw2 = 1
+          ibse2 = 1
+
+!...real boundary condition
+
+          if(ibondj == -1.OR.ibondj == 2) then
+              ibsw2 = 0
+              ibse2 = 0
+          endif
+
+          if(ibondj == 1.OR.ibondj == 2) then
+              ibnw2 = 0
+              ibne2 = 0
+          endif
+
+      endif
+
+!  la periodicite : pas de coin si nbondi = 2
+!  ET nperio != 1
+
+!  north-west
+
+      if(ibnw == 1)then
+          ninterfc=ninterfc+1
+          nnic=nnic+1
+      endif
+
+!  north-east
+
+      if(ibne == 1)then
+          ninterfc=ninterfc+1
+          nnic=nnic+1
+      endif
+
+!  south-west
+
+      if(ibsw == 1)then
+          ninterfc=ninterfc+1
+          nnic=nnic+1
+      endif
+
+!  south-east
+
+      if(ibse == 1)then
+          ninterfc=ninterfc+1
+          nnic=nnic+1
+      endif
+
+!       write(0,*)'  nbre de voisins =',ninterf
+!       write(0,*)'  longueur des interfaces =',nni
+!       write(0,*)'  longueur des interfaces =',nnic
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_subound(ni,nj,ildi,ilei,ildj,ilej,   &
+          imoi,ibondi,ibondj,iperio,   &
+          ninterf,ninterfc,   &
+          iowe,ioea,ioso,iono,   &
+          ibsw,ibnw,ibse,ibne,   &
+          ipsw,ipnw,ipse,ipne,   &
+          nsdvois,nsdvoisc,   &
+          plistin,nni,listin)
+
+      implicit none
+      integer ni,nj,ildi,ilei,ildj,ilej
+      integer imoi,ibondi,ibondj,iperio
+      integer iowe,ioea,ioso,iono
+      integer ibsw,ibnw,ibse,ibne
+      integer ipsw,ipnw,ipse,ipne
+      integer ninterf,ninterfc,nni
+      integer nsdvois(ninterf,3),nsdvoisc(ninterfc,3)
+      integer plistin(ninterfc+1),listin(nni)
+      integer     nint,nni0,ii,jj
+!     integer i,j,nint,nni0,ii,jj
+
+      external mynode
+      integer  mynode
+
+!  determination de la position du sous-domaine dans la grille
+!  cela depnd de ibondi et ibondj
+
+! liste des sous-domaines voisins et des noeuds interface
+
+! be carefull!!! in the FETI algorithm, area number is considered
+! instead of process number
+
+!  initialisation
+
+      nint=0
+      nni0=0
+      plistin(1)=0
+
+!...first, the "segment-points"
+
+      if((ibondi == 2).AND.(iperio /= 1))then
+
+!  la periodicite : pas d'interface east / west si nbondi = 2
+!  ET nperio != 1
+
+      elseif(iperio == 1) then
+
+!  west
+
+          nint=nint+1
+          nsdvoisc(nint,1)=imoi
+          do jj=1,nj+1
+            listin(nni0+jj)=(jj-1)*(ni+1)+1
+          end do
+          nni0=nni0+nj+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=1
+          nsdvoisc(nint,3)=2
+
+!  east
+
+          nint=nint+1
+          nsdvoisc(nint,1)=imoi
+          do jj=1,nj+1
+            listin(nni0+jj)=(jj-1)*(ni+1)+ilei
+          end do
+          nni0=nni0+nj+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=2
+          nsdvoisc(nint,3)=1
+
+      else
+
+!  west
+
+          if(ibondi /= -1)then
+              nint=nint+1
+              nsdvoisc(nint,1)=(iowe+1)
+              do jj=1,nj+1
+                listin(nni0+jj)=(jj-1)*(ni+1)+1
+              end do
+              nni0=nni0+nj+1
+              plistin(nint+1)=nni0
+              nsdvoisc(nint,2)=1
+              nsdvoisc(nint,3)=2
+          endif
+
+!  east
+
+          if(ibondi /= 1)then
+              nint=nint+1
+              nsdvoisc(nint,1)=(ioea+1)
+              do jj=1,nj+1
+                listin(nni0+jj)=(jj-1)*(ni+1)+ilei
+              end do
+              nni0=nni0+nj+1
+              plistin(nint+1)=nni0
+              nsdvoisc(nint,2)=2
+              nsdvoisc(nint,3)=1
+          endif
+
+      endif
+
+!  south
+
+      if(ibondj /= -1.AND.ibondj /= 2)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(ioso+1)
+          do ii=1,ni+1
+            listin(nni0+ii)=ii
+          end do
+          nni0=nni0+ni+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=3
+          nsdvoisc(nint,3)=4
+      endif
+
+!  north
+
+      if(ibondj /= 1.AND.ibondj /= 2)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(iono+1)
+          do ii=1,ni+1
+            listin(nni0+ii)=(ilej-1)*(ni+1)+ii
+          end do
+          nni0=nni0+ni+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=4
+          nsdvoisc(nint,3)=3
+      endif
+
+!...second, the "corner-points"
+
+!...determination of the neighboorings, they depends on iperio 
+!   boundary condition => local description : inimpp or inimpp2...
+
+!  la periodicite : pas de coin si nbondi = 2
+!  ET nperio != 1
+
+!!!!!!!!!verifier la definition des voisins-coin
+
+!  north-west
+
+      if(ibnw == 1)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(ipnw+1)
+          listin(nni0+1)=(ilej-1)*(ni+1)+1
+          nni0=nni0+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=5
+          nsdvoisc(nint,3)=8
+      endif
+
+!  north-east
+
+      if(ibne == 1)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(ipne+1)
+          listin(nni0+1)=(ilej-1)*(ni+1)+ilei
+          nni0=nni0+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=6
+          nsdvoisc(nint,3)=7
+      endif
+
+!  south-west
+
+      if(ibsw == 1)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(ipsw+1)
+          listin(nni0+1)=1
+          nni0=nni0+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=7
+          nsdvoisc(nint,3)=6
+      endif
+
+!  south-east
+
+      if(ibse == 1)then
+          nint=nint+1
+          nsdvoisc(nint,1)=(ipse+1)
+          listin(nni0+1)=ilei
+          nni0=nni0+1
+          plistin(nint+1)=nni0
+          nsdvoisc(nint,2)=8
+          nsdvoisc(nint,3)=5
+      endif
+
+!...je compte les coins
+
+      do ii=1,ninterf
+        nsdvois(ii,1) = nsdvoisc(ii,1)
+        nsdvois(ii,2) = nsdvoisc(ii,2)
+        nsdvois(ii,3) = nsdvoisc(ii,3)
+      enddo
+
+
+!  impressions
+
+!     write(*,*)'  sous-domaine :',imoi
+!     write(*,*)'  nombre de sous-domaines voisins :',ninterfc
+!      do ii=1,ninterfc
+!      write(*,*)'  sous-domaine voisin :',nsdvoisc(ii,1)
+!     write(*,*)'  nombre de noeuds interface :',   &
+!         plistin(ii+1)-plistin(ii)
+!     write(*,*)'  noeuds interface :',(listin(jj),jj=plistin(ii)+1,   &
+!         plistin(ii+1))
+!     end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_subdir(ni,nj,noeuds,ndir,mgcnum)
+      implicit none 
+      integer ni,nj,noeuds,ndir
+      integer mgcnum(ni+1,nj+1)
+      integer i,j
+!     integer i,j,k
+
+!  determination de la position du sous-domaine dans la grille
+!  narea = (j-1)*iglo + i , avec 1<=i<=iglo et 1<=j<=jglo 
+
+
+
+! 1. NUMBER THE GRID-POINTS USING BMASK
+! -------------------------------------
+
+
+      ndir=0
+      do j=1,nj+1
+        do i=1,ni+1
+          ndir=ndir+1-mgcnum(i,j)
+!      do k=1,noeuds
+!        ndir=ndir+1-mgcnum(k,1)
+        enddo
+      enddo
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_listdir(ni,nj,logdir,ndir,lisdir)
+      implicit none 
+      integer ni,nj,ndir
+      integer logdir(ni,nj),lisdir(ndir)
+      integer i0,ji,jj
+
+!  creation de la liste des degres de liberte bloques
+      i0=0
+      do ji=1,ni
+        do jj=1,nj
+          if(logdir(ji,jj) == 0) then
+              i0=i0+1
+              lisdir(i0)=ji+(jj-1)*ni
+          endif
+        end do
+      end do
+      if(i0 /= ndir) then
+!      write(*,*)'  nombre de ddl bloques/prevus :',i0,ndir
+!      write(*,*)'liste des ddl Dirichlet :',(lisdir(ji),ji=1,ndir)
+          stop
+      endif
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_blodir(n,x,ndlblo,list)
+      implicit none
+      integer n,ndlblo
+      integer list(ndlblo)
+      REAL(kind=8)  x(n)
+      integer i
+
+!  remise a zero des ddl bloques
+      do i=1,ndlblo
+        x(list(i))=0.e0
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_numblo(ndlblo,lisblo)
+      implicit none
+      external mynode
+!!    integer mynode,indlblog,iibidon
+      integer mynode
+      integer ndlblo
+      integer lisblo(ndlblo)
+!!    integer n
+
+!      indlblog=-ndlblo
+!      call mpp_min(indlblog,1,iibidon)
+!      indlblog=-indlblog
+!      if(mynode() == 0)THEN
+!      write(0,*)'  nombre de degres de liberte flottants :',ndlblo
+!      write(0,*)'  liste :',(lisblo(n),n=1,ndlblo)
+!      endif
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_blomat(ni,nj,a,ndlblo,lisblo)
+      implicit none
+      integer ni,nj
+      REAL(kind=8)  a(ni,nj,5)
+      integer ndlblo
+      integer lisblo(ndlblo)
+!!    integer i,j,k,l,n
+      integer i,j,k,n
+
+      do n=1,ndlblo
+!  degre de liberte bloque : lisblo(n) = (j-1)*ni + i
+        i=mod(lisblo(n)-1,ni)+1
+        j=((lisblo(n)-1)/ni)+1
+!  annulation des coefficients sur la ligne
+        do k=1,5
+          a(i,j,k)=0.e0
+        end do
+        a(i,j,3)=1.e0
+!  annulation des coefficients dans les colonnes correspondantes
+        if(i > 1) then
+            a(i-1,j,4)=0.e0
+        endif
+        if(i < ni) then
+            a(i+1,j,2)=0.e0
+        endif
+        if(j > 1) then
+            a(i,j-1,5)=0.e0
+        endif
+        if(j < nj) then
+            a(i,j+1,1)=0.e0
+        endif
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_blomat1(ni,nj,a,ndlblo,lisblo,nsp)
+      implicit none
+      integer ni,nj,ndlblo
+      REAL(kind=8)  a(ni,nj,5),nsp(ni,nj,ndlblo)
+      integer lisblo(ndlblo)
+!!    integer i,j,k,l,n
+      integer i,j,n
+
+      do n=1,ndlblo
+!  degre de liberte bloque : lisblo(n) = (j-1)*ni + i
+        i=mod(lisblo(n)-1,ni)+1
+        j=((lisblo(n)-1)/ni)+1
+!  annulation des coefficients dans les colonnes correspondantes
+        if(i > 1) then
+            nsp(i-1,j,n)=-a(i-1,j,4)
+        endif
+        if(i < ni) then
+            nsp(i+1,j,n)=-a(i+1,j,2)
+        endif
+        if(j > 1) then
+            nsp(i,j-1,n)=-a(i,j-1,5)
+        endif
+        if(j < nj) then
+            nsp(i,j+1,n)=-a(i,j+1,1)
+        endif
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_nullsp(noeuds,ni,nj,lpblo,blo,a,ndlblo,lisblo,nsp,z)
+!  calcul du noyau de la matrice
+      implicit none
+      integer noeuds,ni,nj,lpblo,ndlblo
+      REAL(kind=8)  a(ni,nj,5)
+      integer lisblo(ndlblo)
+      REAL(kind=8)  blo(lpblo),nsp(noeuds,ndlblo),z(noeuds)
+      external sdot
+      REAL(kind=8)  sdot,res
+      integer j,i
+
+!  calcul de [Aii]-1 * Aib
+      do j=1,ndlblo
+        call feti_resloc(noeuds,ni,nj,a,lpblo,blo,nsp(1,j),nsp(1,j),z)
+      end do
+!  remise a identite du bloc diagonal correspondant aux modes bloques
+      do i=1,ndlblo
+        do j=1,ndlblo
+          nsp(lisblo(i),j)=0.e0
+        end do
+        nsp(lisblo(i),i)=1.e0
+      end do
+!  verifications
+      do j=1,ndlblo
+        call feti_proax(noeuds,ni,nj,a,nsp(1,j),z)
+        res=sqrt(sdot(noeuds,z,1,z,1)/   &
+            sdot(noeuds,nsp(1,j),1,nsp(1,j),1))
+!       write(0,*)'  residu de la colonne ',j,' du noyau :',res
+!       write(0,*)'  vecteur colonne :'
+!       call prvec(noeuds,nsp(1,j))
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_project(gint,pgint,nspdim,x,b,nmspdim,numit0   &
+          ,nitmax,gvec,agvec,d,ad,add,gamm,numnes,listnes,plistin,numins   &
+          ,listin,narea,numnos,nsp,v,w,bufin,bufout,work)
+
+      implicit none 
+
+      integer nitmax, nspdim
+      REAL(kind=8)  x(nspdim), b(nspdim)
+
+!...the Krylov optimisation used in PCG associated to the Coarse Solver
+!   involve to keep di & adi vectors in etesolve procedure
+!   the nmspdim parameter is introduced to avoid message "out of bound"
+!   arrising qhen the memory is checked!
+
+!   nmspdim  =   Max (nspdim(Ep)) <= memory management (f77 context)
+!               p=1,Np
+
+!      REAL(kind=8)  gvec(nspdim), agvec(nspdim),
+!     &       d(nspdim,0:nitmax-1), ad(nspdim,0:nitmax-1), 
+!     &       add(0:nitmax-1), gamm(0:nitmax-1)
+
+      integer nmspdim
+      REAL(kind=8)  gvec(nspdim), agvec(nspdim),   &
+          d(nmspdim,0:nitmax-1), ad(nmspdim,0:nitmax-1),    &
+          add(0:nitmax-1), gamm(0:nitmax-1)
+
+      integer numnes,numins,narea,  numnos, numit0
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  nsp(numnos,nspdim), v(numnos),    &
+          w(numins), gint(numins), pgint(numins) 
+      REAL(kind=8)  bufin(numins), bufout(numins)
+      REAL(kind=8)  work(0:nitmax-1)
+
+
+      call feti_proet(numnes,listnes,plistin,numins,listin,numnos,   &
+          gint,nspdim,nsp,b,v)
+      call feti_etesolv(nspdim,x,b,nmspdim,numit0,nitmax,gvec,agvec,d,ad   &
+          ,add,gamm,numnes,listnes,plistin,numins,listin,narea,numnos   &
+          ,nsp,v,w,bufin,bufout,work)
+      call feti_proe(numnes,listnes,plistin,numins,listin,narea,numnos,   &
+          nspdim,nsp,x,v,w,bufin,bufout)
+      call feti_vsub(numins,gint,w,pgint)
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_etesolv(nspdim,x,b,nmspdim,numit0,nitmax,gvec    &
+          ,agvec,d,ad,add,gamm,numnes,listnes,plistin,numins,listin    &
+          ,narea,numnos,nsp,v,w,bufin,bufout,work)
+
+!     INPUTS :   nspdim  =   dimension of null space : LOCAL
+!                x       =   initial solution
+!                b       =   right hand side
+!               nmspdim  =   Max (nspdim(Ep)) <= memory management
+!                            p=1,Np
+!               numit0   =   number of previous direction vectors, at most
+!                            nitmax
+!               nitmax   =   number of maximum direction vectors for 
+!                            reconjugation  
+!               gvec     =   gradient vector
+!               agvec    =   A * g
+!               d        =   direction vector
+!               ad       =   A * d
+!               add      =   dot products (Ad,d)
+!               gamm     =   GAMMA coefficients
+!               numnes   =   number of neighbouring subdomains
+!               listnes  =   list of neighbouring subdomains
+!               plistin  =   pointer of sublists of interface nodes
+!               numins   =   number of interface nodes
+!               listin   =   list of interface nodes
+!               narea    =   subdomain number
+!               numnos   =   number of nodes in the subdomain
+
+!     WORKSPACE : bufin  =  contributions of local fields on interface
+!                 bufout =  contributions of outer fields on interface
+!                 work   =  workspace for mpp_sum calls
+
+      implicit none 
+
+      integer nitmax, nspdim
+      REAL(kind=8)  x(nspdim), b(nspdim)
+
+!...the Krylov optimisation involve to keep di & adi vectors
+!   the nmspdim parameter is introduce to avoid message "out of bound"
+!   arrising qhen the memory is checked!
+
+!      REAL(kind=8)  gvec(nspdim), agvec(nspdim),
+!     &       d(nspdim,0:nitmax-1), ad(nspdim,0:nitmax-1), 
+!     &       rho, temp1(2), temp2(2), add(0:nitmax-1),
+!     &       gamm(0:nitmax-1), facg0, facgn, facst, eps
+
+      integer nmspdim
+      REAL(kind=8)  gvec(nmspdim), agvec(nmspdim),    &
+          d(nspdim,0:nitmax-1), ad(nspdim,0:nitmax-1),     &
+          rho, temp1(2), temp2(2), add(0:nitmax-1),    &
+          gamm(0:nitmax-1), facg0, facgn, facst, eps
+
+      integer numnes,numins,narea,  numnos
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  nsp(numnos,nspdim), v(numnos), w(numins)
+      REAL(kind=8)  bufin(numins), bufout(numins)
+      REAL(kind=8)  work(0:nitmax-1)
+
+      integer i, j, n, numit0, nn, n1, numit1
+
+      external sdot
+      REAL(kind=8)  sdot
+
+!    initialisation 
+
+      do 1 i=1,nspdim
+        x(i) = 0.e0
+        gvec(i) = -b(i)
+ 1    continue
+      facg0 = sdot( nspdim, gvec, 1, gvec , 1)
+      call mpp_sum(facg0,1,work)
+
+      if( facg0  ==  0.e0 ) return
+
+      eps=1.e-24
+      facst=facg0*eps
+
+!    initial projection 
+
+      if(numit0 > 0) then
+          do 91 j = 0 , numit0
+            gamm(j) = - sdot(nspdim,gvec,1,d(1,j),1) / add(j)
+ 91       continue
+          call mpp_sum(gamm,numit0+1,work)
+          call feti_mxvadd( nspdim, numit0+1, d, gamm, x )
+          call feti_mxvadd( nspdim, numit0+1, ad, gamm, gvec )
+
+!  test residual after initial projection
+
+          facgn = sdot( nspdim, gvec, 1, gvec, 1 )
+          call mpp_sum(facgn,1,work)
+          if( facgn <= facst ) then
+!             write(0,*) 'residual after initial projection for feti_etesolv='   &
+!                 ,facgn/facg0
+              return
+          endif
+
+      endif
+
+!     compute (Et E) * gvec
+
+      call feti_proe(numnes,listnes,plistin,numins,listin,narea,numnos,   &
+          nspdim,nsp,gvec,v,w,bufin,bufout)
+      call feti_proet(numnes,listnes,plistin,numins,listin,numnos,w,   &
+          nspdim,nsp,agvec,v)
+
+!   conjugate d .
+
+      if(numit0 > 0) then
+          numit1=min0(numit0+1,nitmax-1)
+          do 94 i=0,numit0
+            gamm(i) = -sdot(nspdim,gvec,1,ad(1,i),1)/ add(i)
+ 94       continue
+          call mpp_sum(gamm,numit0+1,work)
+
+          call feti_osaxpy( nspdim,gamm(numit0),d(1,numit0),   &
+              gvec,d(1,numit1))
+          call feti_osaxpy( nspdim,gamm(numit0),ad(1,numit0),   &
+              agvec,ad(1,numit1))
+
+          call feti_mxvadd( nspdim, numit1-1, d, gamm, d(1,numit1) )
+          call feti_mxvadd( nspdim, numit1-1, ad, gamm, ad(1,numit1) )
+      else
+          numit1=0
+
+          do 20 i = 1, nspdim
+            d(i,numit1) = gvec(i)
+ 20       continue
+
+          do 30 i = 1, nspdim
+            ad(i,numit1) = agvec(i)
+ 30       continue
+      endif
+
+!     computing rho
+
+      do 50 nn = numit1, nitmax
+        n=min0(nn,nitmax-1)
+        temp1(1) = sdot( nspdim, gvec, 1, d(1,n), 1 )
+        temp1(2) = sdot( nspdim, ad(1,n), 1, d(1,n), 1 )
+        call mpp_sum(temp1,2,temp2)
+        add(n) = temp1(2)
+        rho = - temp1(1) / add(n)
+
+        call feti_osaxpy( nspdim, rho, d(1,n), x, x )
+        call feti_osaxpy( nspdim, rho, ad(1,n), gvec, gvec )
+
+!        test residual . 
+
+        facgn = sdot( nspdim, gvec, 1, gvec, 1 )
+        call mpp_sum(facgn,1,work)
+!        write(0,*) 'iteration =', nn+1, 'residual = ', facgn/facg0
+        if( facgn <= facst ) then
+            goto 999
+        endif
+
+!   reconjugation of gvec
+
+        do 60 i=0,n
+          gamm(i) = -sdot(nspdim,gvec,1,ad(1,i),1)/ add(i)
+ 60     continue
+        call mpp_sum(gamm,n+1,work)
+        n1=min0(nn+1,nitmax-1)
+
+        call feti_osaxpy( nspdim,gamm(n),d(1,n),gvec,d(1,n1))
+
+        call feti_mxvadd( nspdim, n1-1, d, gamm, d(1,n1) )
+
+!     compute (Et E) * d
+
+        call feti_proe(numnes,listnes,plistin,numins,listin,narea,   &
+            numnos,nspdim,nsp,d(1,n1),v,w,bufin,bufout)
+        call feti_proet(numnes,listnes,plistin,numins,listin,numnos,w,   &
+            nspdim,nsp,ad(1,n1),v)
+
+ 50   continue
+
+      if(narea == 1) then
+          write(0,*) 'No convergence for ete in ',nitmax,' iterations'
+          stop
+      endif
+
+
+ 999  continue
+      numit0=min0(n,nitmax-1)
+!     write(0,*) 'number of iterations for ete :', nn+1, ' ,  residual =', facgn
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_osaxpy( n, a, x, y, z )
+
+      implicit none
+
+      integer n
+      REAL(kind=8)  a, x(n), y(n), z(n)
+
+      integer i
+
+      do 10 i = 1, n
+        z(i) = y(i) + a * x(i)
+ 10   continue
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_proe(numnes,listnes,plistin,numins,listin,narea,   &
+          numnos,nspdim,nsp,alpha,v,w,bufin,   &
+          bufout)
+
+!  jump of a velocity field on the interfaces, in the case where 
+!  subdomain number i is allocated to processor number i-1 .
+!  the velocity field is Nsp * alpha, where Nsp is the nullspace .
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               narea     =  subdomain number
+!               numnos  =  number of nodes in the subdomain
+!               nspdim  =  dimension of the null space
+!               nsp     =  null space
+!               alpha   =  components of the velocity field in the null
+!                          space
+!               v       =  corresponding velocity field
+
+!     OUTPUTS :      w  =  jump on the interface
+
+!     WORKSPACE : bufin   =  contributions of local field on interface
+!                 bufout  =  contributions of outer fields on interface
+!                 work
+      implicit none 
+      integer numnes,numins,numnos,narea,nspdim
+      integer listnes(numnes,3), plistin(numnes+1), listin(numins)
+      REAL(kind=8)  v(numnos),w(numins)
+      REAL(kind=8)  bufin(numins),bufout(numins)
+      REAL(kind=8)  alpha(nspdim), nsp(numnos,nspdim)
+      integer i
+
+!  computing the values of the local velocity field 
+      do i=1,numnos
+        v(i)=0.e0
+      end do
+      call feti_mxvadd( numnos, nspdim, nsp, alpha, v )
+!  computing the jump on the interface
+      call feti_saut(numnes,listnes,plistin,numins,listin,   &
+                numnos,v,w,bufin,bufout)
+!!        narea,numnos,v,w,bufin,bufout)
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_proet(numnes,listnes,plistin,numins,listin,   &
+          numnos,w,nspdim,nsp,alpha,v)
+
+!  projection in the null space of the right-hand-side associated with
+!  a Lagrange multiplier w .
+
+!     INPUTS :      numins  =  number of interface nodes
+!               listin  =  list of interface nodes
+!               numnos  =  number of nodes in the subdomain
+!               w       =  Lagrange multiplier
+!               nspdim  =  dimension of the null space
+!               nsp     =  null space
+
+!     OUTPUTS :      v     =  local right-hand-side
+!               alpha =  projection of v in the null space
+
+      implicit none 
+      external sdot
+      REAL(kind=8)  sdot
+      integer numins,numnos,nspdim,numnes
+      integer listnes(numnes,3),plistin(numnes+1),listin(numins)
+      REAL(kind=8)  v(numnos),w(numins)
+      REAL(kind=8)  alpha(nspdim), nsp(numnos,nspdim)
+      integer i
+
+!  assembling the values of the Lagrange multiplier on the interface
+      call feti_probit(numnes,listnes,plistin,numins,listin,numnos,w,v)
+!  computing the projection of v in the null space .
+      do 1 i=1,nspdim
+        alpha(i)=sdot(numnos,v,1,nsp(1,i),1)
+ 1    continue
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_consrhs( vdim,nspdim,rhs,nsp,cb )
+
+
+      implicit none
+
+      external sdot
+      REAL(kind=8)  sdot
+      integer vdim, nspdim
+
+      REAL(kind=8)   rhs(vdim), nsp(vdim,nspdim), cb(nspdim)
+
+
+      integer i
+
+!  compute the right hand side for constraint 
+
+      do i=1,nspdim
+        cb(i)=-sdot(vdim,rhs,1,nsp(1,i),1)
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_dualschur(noeuds,ni,nj,a,lpblo,blo,   &
+          ninterf,ninterfc,nni,nnic,   &
+          ndvois,ndvoisc,plistin,listin,   &
+          poids,u,v,f,bitw,utilu,   &
+          lambda,g,pg,mg,nitmax,nmaxd,j0,wj,dwj,dwwj,   &
+          gamm,work,bufin,bufout,narea,epsilo,ndlblo,   &
+          lisblo,ndkerep,   &
+          xnul,ynul,numit0ete,nitmaxete,eteg,   &
+          eteag,eted,etead,eteadd,etegamm,nsp,etev,   &
+          etew,nnih,plistih,gh,w,dw,   &
+          residu,indic,jn)
+      implicit none
+!  nombre de ddl par noeuds, nombre de noeuds interne et interface
+      integer noeuds,ni,nj,nni,nnic
+!      integer jpj,jpi
+!  numero du sous-domaine = numero de processeur + 1 
+      integer narea
+!  tableaux descripteurs de la matrice locale
+      REAL(kind=8)  a(ni,nj,5)
+!  tableaux descripteurs de l'inverse de la matrice du probleme local
+      integer lpblo
+      REAL(kind=8)  blo(lpblo)
+!  tableaux descripteurs de l'interface
+      integer ninterf,ninterfc
+      integer ndvois(ninterf,3),ndvoisc(ninterfc,3)
+      integer plistin(ninterfc+1),listin(nnic)
+!  tableaux descripteurs de l'interface ajoutes pour nperio == 1
+      REAL(kind=8)  poids(noeuds)
+!  utilitaires pour les assemblages aux interfaces
+      REAL(kind=8)  bufin(nnic),bufout(nnic)
+!  vecteurs locaux
+      REAL(kind=8)  u(noeuds),v(noeuds),f(noeuds)
+      REAL(kind=8)  bitw(noeuds),utilu(noeuds)
+!  vecteurs inconnues aux interfaces
+!  mg est le gradient preconditionne : M = sum(Bi Ai Bit)
+      REAL(kind=8)  lambda(nni),g(nni),pg(nni),mg(nni)
+!  tableaux servant a gerer le stockage de la moitie des coefficients
+!  des tableaux des directions de descente sur chaque interface
+      integer nnih
+      integer plistih(ninterf+1)
+      REAL(kind=8)  gh(nnih)
+!  tableaux des directions de descente
+!  on appelle D la matrice condensee a l'interface : sum(Bi [Ai]-1 Bit)
+!  j0 est le nombre de vecteurs D orthogonaux deja stockes
+!  j0 est egal au plus a nmaxd-1
+!  lorsque le nomtre total d'iterations atteint nmaxd, seule la derniere
+!  direction calculee est stockee dans la colonne numero nmaxd
+      integer nitmax,nmaxd,j0
+      REAL(kind=8)  wj(nnih,nmaxd),dwj(nnih,nmaxd),dwwj(nmaxd)
+      REAL(kind=8)  w(nni),dw(nni)
+!  utilitaires pour les calculs de produits scalaires globaux
+      REAL(kind=8)  work(nmaxd),gamm(nmaxd)
+!  tableaux descripteurs du noyau de la matrice locale et tableaux 
+!  servant a la projection sur le noyau
+
+!...ndlblo is the dimension of the local nullspace .=<. the size of the
+!   memory of the superstructure associated to the nullspace : ndkerep
+!   indeed ndkerep = Max ndlblo = Max dim(Ker(Ep))
+!                                p=1,Np
+!   ndkerep is introduced to avoid messages "out of bounds" when memory
+!   is checked
+
+      integer ndkerep
+      integer ndlblo,numit0ete,nitmaxete
+      integer lisblo(ndlblo)
+      REAL(kind=8)  xnul(ndlblo),ynul(ndlblo),eteg(ndlblo),eteag(ndlblo)
+
+!...the Krylov optimisation used in PCG associated to the Coarse Solver
+!   involve to keep di & adi vectors in etesolve procedure
+!   the ndkerep parameter is introduced to avoid message "out of bound"
+!   arrising when the memory is checked!
+
+!   ndkerep  =   Max (ndlblo(Ep)) <= memory management (f77 context)
+!               p=1,Np
+
+!      REAL(kind=8)  eted(ndlblo,nitmaxete),etead(ndlblo,nitmaxete)
+
+      REAL(kind=8)  eted(ndkerep,nitmaxete),etead(ndkerep,nitmaxete)
+      REAL(kind=8)  eteadd(nitmaxete),etegamm(nitmaxete)
+      REAL(kind=8)  etev(noeuds),etew(nni),nsp(noeuds,ndlblo)
+!  indicateur de convergence
+
+      integer indic
+      REAL(kind=8)  residu
+      integer jn
+!  utilitaires
+!!    integer j,k,j1,ji,jj,jk
+      integer j,k,j1
+      REAL(kind=8)  scal(2),ff,roj,epsilo,epsilo2
+!  fonctions externes
+      external sdot
+      REAL(kind=8)  sdot
+!  booleen pour caracterisation
+!  numerique si llconv=1
+      integer llconv
+
+      llconv=0
+
+!...critere d'arret epsilo2 = epsilo **2 => evite sqrt
+
+      epsilo2 = epsilo * epsilo
+
+!  calcul du carre scalaire du second membre global
+
+      call feti_assemb(ninterfc,ndvoisc,plistin,nnic,listin,narea,noeuds   &
+          ,f,utilu,bufin,bufout)
+      ff=sdot(noeuds,utilu,1,utilu,1)
+      call mpp_sum(ff,1,work)
+!     write(90,*)'valeur du carre du second membre ds le Schur Dual :',ff
+
+!  calcul du second membre contraint 
+
+      call feti_consrhs(noeuds,ndlblo,f,nsp,ynul)
+
+!  calcul de lambda0 satisfaisant la contrainte
+ 
+!     call feti_vclr(nni,lambda)
+      call feti_etesolv(ndlblo,xnul,ynul,ndkerep,numit0ete,nitmaxete   &
+          ,eteg,eteag,eted,etead,eteadd,etegamm,ninterf,ndvois,plistin   &
+          ,nni,listin,narea,noeuds,nsp,etev,etew,bufin,bufout,work)
+
+      call feti_proe(ninterf,ndvois,plistin,nni,listin,narea,noeuds,   &
+          ndlblo,nsp,xnul,etev,lambda,bufin,bufout)
+
+!  calcul du nouveau second membre
+
+      call feti_probit(ninterf,ndvois,plistin,nni,listin,noeuds,lambda,bitw)
+
+      call feti_vadd(noeuds,bitw,f,bitw)
+
+
+!  calcul du champ local initial u0
+!     call feti_blodir(noeuds,bitw,ndlblo,lisblo)
+      call feti_resloc(noeuds,ni,nj,a,lpblo,blo,bitw,u,utilu)
+
+!  calcul du gradient initial g0 = feti_saut(u0)
+!!    call feti_saut(ninterf,ndvois,plistin,nni,listin,narea,noeuds,u,g   &
+      call feti_saut(ninterf,ndvois,plistin,nni,listin,      noeuds,u,g   &
+          ,bufin,bufout)
+
+!  reinitialisation de lambdaj0 par reconjugaison
+
+      call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea,g, gh)
+      do k=1,j0
+        gamm(k)=sdot(nnih,gh,1,wj(1,k),1)
+      end do
+      if(j0 >= 1) call mpp_sum(gamm,j0,work)
+      do k=1,j0
+        gamm(k)=-gamm(k)/dwwj(k)
+      end do
+      call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea, lambda,gh)
+      call feti_mxvadd(nnih,j0,wj,gamm,gh)
+      call feti_extend(ninterf,ndvois,plistin,nni,plistih,nnih,narea,gh, lambda)
+!  calcul du second membre associe a lambdaj0
+      if(j0 > 0) then
+          call feti_probit(ninterf,ndvois,plistin,nni,listin,noeuds, lambda,bitw)
+          call feti_vadd(noeuds,bitw,f,bitw)
+!  calcul du champ local associe uj0
+!         call feti_blodir(noeuds,bitw,ndlblo,lisblo)
+          call feti_resloc(noeuds,ni,nj,a,lpblo,blo,bitw,u,utilu)
+!  calcul du gradient initial gj0= feti_saut(uj0)
+!!        call feti_saut(ninterf,ndvois,plistin,nni,listin,narea,noeuds   &
+          call feti_saut(ninterf,ndvois,plistin,nni,listin,      noeuds   &
+              ,u,g,bufin,bufout)
+      endif
+!  calcul du gradient projete 
+!     call feti_vmov(nni,g,pg)
+      call feti_project(g,pg,ndlblo,xnul,ynul,ndkerep,numit0ete   &
+          ,nitmaxete,eteg,eteag,eted,etead,eteadd,etegamm,ninterf,ndvois   &
+          ,plistin,nni,listin,narea,noeuds,nsp,etev,etew,bufin,bufout,work)
+!  calcul du gradient preconditionne 
+!     call feti_vmov(nni,pg,mg)
+
+      call feti_probit(ninterf,ndvois,plistin,nni,listin,noeuds, pg,bitw)
+
+      call feti_proax(noeuds,ni,nj,a,bitw,v) 
+!!    call feti_saut(ninterf,ndvois,plistin,nni,listin,narea,noeuds,v, mg,bufin,bufout)
+      call feti_saut(ninterf,ndvois,plistin,nni,listin,      noeuds,v, mg,bufin,bufout)
+!  verification du residu initial 
+      residu=sdot(nni,mg,1,mg,1)
+      call mpp_sum(residu,1,work)
+      residu = (4. * residu) / ff
+      if(residu <= epsilo2)then
+!         residu=10.*sqrt(residu/ff)
+!         if(residu < epsilo)then
+          if(llconv == 1)then
+              if(narea == 1)then
+                  write(0,*)'  residu carre approche initial :',residu
+              endif
+          endif
+!  calcul du champ global moyenne aux interfaces et du residu global 
+          call feti_vsub(noeuds,u,etev,utilu)
+          call feti_moyen(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+              noeuds,poids,utilu,utilu,bufin,bufout)
+          call feti_vmov(noeuds,utilu,u)
+          call feti_proax(noeuds,ni,nj,a,utilu,v) 
+          call feti_vsub(noeuds,v,f,v)
+          call feti_assemb(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+              noeuds,v,utilu,bufin,bufout)
+          residu=sdot(noeuds,utilu,1,utilu,1)
+          call mpp_sum(residu,1,work)
+          residu=sqrt(residu/ff)
+!         residu=residu/ff
+          if(llconv == 1)then
+              if(narea == 1)then
+                  write(0,*)'  residu exact initial :',residu
+              endif
+          endif
+
+ 101      format(10d9.2)
+
+          return
+
+      endif
+
+
+!  calcul de la premiere direction de descente
+!  calcul du gradient preconditionne projete 
+      call feti_project(mg,mg,ndlblo,xnul,ynul,ndkerep,numit0ete   &
+          ,nitmaxete,eteg,eteag,eted,etead,eteadd,etegamm,ninterf,ndvois   &
+          ,plistin,nni,listin,narea,noeuds,nsp,etev,etew,bufin,bufout ,work)
+      call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea,   &
+          mg,wj(1,j0+1))
+      do k=1,j0
+        gamm(k)=sdot(nnih,wj(1,j0+1),1,dwj(1,k),1)
+      end do
+      if(j0 >= 1) call mpp_sum(gamm,j0,work)
+      do k=1,j0
+        gamm(k)=-gamm(k)/dwwj(k)
+      end do
+      call feti_mxvadd(nnih,j0,wj,gamm,wj(1,j0+1))
+
+!  iterations de gradient conjugue a l'interface
+
+
+!debug
+      do j=j0+1,j0+nitmax
+
+        if(llconv == 1.and.narea == 1) write(0,*)'etape numero',j-j0
+!  j1 est le numero de colonne de la derniere direction de descente
+!  j1 = j, numero d'iteration total, tant que j < nmaxd
+!  au-dela, j1 = nmaxd
+        j1=min0(j,nmaxd)
+!  calcul de Dwi , D = sum ( Bi [Ai]-1 tBi )
+        call feti_extend(ninterf,ndvois,plistin,nni,plistih,nnih,narea, wj(1,j1),w)
+        call feti_probit(ninterf,ndvois,plistin,nni,listin,noeuds, w,bitw)
+!       call feti_blodir(noeuds,bitw,ndlblo,lisblo)
+        call feti_resloc(noeuds,ni,nj,a,lpblo,blo,bitw,v,utilu)
+!!      call feti_saut(ninterf,ndvois,plistin,nni,listin,narea,noeuds,v   &
+        call feti_saut(ninterf,ndvois,plistin,nni,listin,      noeuds,v   &
+            ,dw,bufin,bufout)
+        call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea, dw,dwj(1,j1))
+!  calcul du coefficient de descente
+        call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea, g,gh)
+        scal(1)=sdot(nnih,gh,1,wj(1,j1),1)
+        scal(2)=sdot(nnih,dwj(1,j1),1,wj(1,j1),1)
+        call mpp_sum(scal,2,work)
+        roj=-scal(1)/scal(2)
+        dwwj(j1)=scal(2)
+!  remise a jour de lambda, g et u
+        call saxpy(nni,roj,w,1,lambda,1)
+        call saxpy(nni,roj,dw,1,g,1)
+        call saxpy(noeuds,roj,v,1,u,1)
+!  calcul du gradient projete 
+!       call feti_vmov(nni,g,pg)
+        call feti_project(g,pg,ndlblo,xnul,ynul,ndkerep,numit0ete   &
+            ,nitmaxete,eteg,eteag,eted,etead,eteadd,etegamm,ninterf   &
+            ,ndvois,plistin,nni,listin,narea,noeuds,nsp,etev,etew,bufin   &
+            ,bufout,work)
+!  calcul du gradient preconditionne Mg , M = sum ( Bi Ai tBi )
+!       call feti_vmov(nni,pg,mg)
+        call feti_probit(ninterf,ndvois,plistin,nni,listin,noeuds, pg,bitw)
+        call feti_proax(noeuds,ni,nj,a,bitw,v) 
+!!      call feti_saut(ninterf,ndvois,plistin,nni,listin,narea,noeuds,v   &
+        call feti_saut(ninterf,ndvois,plistin,nni,listin,      noeuds,v   &
+            ,mg,bufin,bufout)
+!  verification du residu global approche
+        residu=sdot(nni,mg,1,mg,1)
+        call mpp_sum(residu,1,work)
+!       residu=10.*sqrt(residu/ff)
+        residu = (4. * residu) / ff
+        if(llconv == 1.and.narea == 1)then
+            write(0,*)'  residu carre global approche apres ',   &
+                j-j0,' iterations :',residu
+        endif
+
+!       if(residu <  epsilo) then
+        if(residu <= epsilo2)then
+            if(llconv == 1.and.narea == 1)then
+                write(0,*)'residu carre global approche apres ',   &
+                    j-j0,' iterations :',residu
+            endif
+!  calcul du champ global moyenne aux interfaces et du residu global 
+            call feti_vsub(noeuds,u,etev,utilu)
+            call feti_moyen(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+                noeuds,poids,utilu,utilu,bufin,bufout)
+            call feti_vmov(noeuds,utilu,u)
+            call feti_proax(noeuds,ni,nj,a,utilu,v) 
+            call feti_vsub(noeuds,v,f,v)
+            call feti_assemb(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+                noeuds,v,utilu,bufin,bufout)
+            residu=sdot(noeuds,utilu,1,utilu,1)
+            call mpp_sum(residu,1,work)
+!           residu=residu/ff
+            residu=sqrt(residu/ff)
+            if(llconv == 1.and.narea == 1)then
+                write(0,*)'  residu global exact apres ',   &
+                    j-j0,' iterations :',residu
+            endif
+
+            jn = j - j0
+            j0=min0(j,nmaxd-1)
+            if(llconv == 1.and.narea == 1)then
+                write(0,*)'  nombre de directions orthogonales conservees :',j0
+            endif
+
+
+            return
+        endif
+!##################################################################
+!  calcul du champ global moyenne aux interfaces et du residu global 
+        call feti_vsub(noeuds,u,etev,utilu)
+        call feti_moyen(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+            noeuds,poids,utilu,utilu,bufin,bufout)
+        call feti_proax(noeuds,ni,nj,a,utilu,v) 
+        call feti_vsub(noeuds,v,f,v)
+        call feti_assemb(ninterfc,ndvoisc,plistin,nnic,listin,narea,   &
+            noeuds,v,utilu,bufin,bufout)
+        residu=sdot(noeuds,utilu,1,utilu,1)
+        call mpp_sum(residu,1,work)
+!       residu=sqrt(residu/ff)
+        residu=residu/ff
+        if(llconv == 1.and.narea == 1)then
+            write(0,*)'  residu carre global exact apres ',   &
+                j-j0,' iterations :',residu
+        endif
+
+!#####################################################################
+!  calcul de la nouvelle direction de descente par reconjugaison
+!  calcul du gradient preconditionne projete 
+        call feti_project(mg,mg,ndlblo,xnul,ynul,ndkerep,numit0ete   &
+            ,nitmaxete,eteg,eteag,eted,etead,eteadd,etegamm,ninterf   &
+            ,ndvois,plistin,nni,listin,narea,noeuds,nsp,etev,etew,bufin   &
+            ,bufout,work)
+        call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea, mg,gh)
+        do k=1,j1
+          gamm(k)=sdot(nnih,gh,1,dwj(1,k),1)
+        end do
+        call mpp_sum(gamm,j1,work)
+        do k=1,j1
+          gamm(k)=-gamm(k)/dwwj(k)
+        end do
+        call feti_mxvadd(nnih,j1,wj,gamm,gh)
+        j1=min0(j1+1,nmaxd)
+
+!%%%%%%%%%%stabilisation numerique %%%%%%%%%%%%%%%%%%%%%%%%%
+        call feti_extend(ninterf,ndvois,plistin,nni,plistih,nnih,narea, gh,w)
+        call feti_project(w,w,ndlblo,xnul,ynul,ndkerep,numit0ete   &
+            ,nitmaxete,eteg,eteag,eted,etead,eteadd,etegamm,ninterf   &
+            ,ndvois,plistin,nni,listin,narea,noeuds,nsp,etev,etew,bufin   &
+            ,bufout,work)
+        call feti_restri(ninterf,ndvois,plistin,nni,plistih,nnih,narea, w,gh)
+!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+        call feti_vmov(nnih,gh,wj(1,j1))
+
+      end do
+
+      residu = sqrt(residu)
+      if(narea == 1) then
+          write(0,*)'  residu global approche apres ',nitmax,   &
+              '  iterations :',residu
+      endif
+      indic=-2
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_extend(numnes,listnes,   &
+          plistin,numins,plistih,   &
+          numinh,narea,wh,w)
+
+!  reassembling an half interface field 
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               lint    =  list of inner interfaces
+!               lext    =  list of extern ibnterfaces
+!               plistin =  pointer of sublists of interface nodes
+!               plistih =  pointer of half-sublists of interface nodes
+!               numins  =  number of interface nodes
+!               numinh  =  half number of interface nodes
+!               narea    =  subdomain number
+!               wh      =  half interface vector 
+
+!     OUTPUTS :      w  =  complete interface vector
+
+!     WORKSPACE : work
+      implicit none 
+!      external irecv
+!!    integer irecv, work(100)
+      integer numnes,numins,numinh,narea
+      integer listnes(numnes,3), plistin(numnes+1), plistih(numnes+1)
+      REAL(kind=8)  wh(numinh),w(numins)
+      integer i,l,lin,lout
+      integer mesg
+
+      mesg=128*10
+!  if subdomains i < j are neighbours, subdomain i manage the first
+!  half of the interface, and subdomain j the remaining part
+
+!  receiving the values of the outer fields on the interface
+!  sending the values of the inner field on the interface
+
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))
+!        if(narea < listnes(i)) then
+        if(listnes(i,3) < listnes(i,2))then
+            lout=(l-(l/2))
+            lin=(l/2)
+!           work(i)=irecv(mesg+listnes(i)-1,w(plistin(i)+(l/2)+1), lout*8)
+!           call mppsend(mesg+narea-1,wh(plistih(i)+1),lin*8,listnes(i) -1,0)
+            call mppsend(mesg+listnes(i,3)-1,wh(plistih(i)+1),lin*8, listnes(i,1)-1,0)
+            call feti_vmov(lin,wh(plistih(i)+1),w(plistin(i)+1))
+        else
+            lout=(l/2)
+            lin=(l-(l/2))
+!           work(i)=irecv(mesg+listnes(i)-1,w(plistin(i)+1),lout*8)
+!           call mppsend(mesg+narea-1,wh(plistih(i)+1),lin*8,listnes(i)-1,0)
+            call mppsend(mesg+listnes(i,3)-1,wh(plistih(i)+1),lin*8, listnes(i,1)-1,0)
+            call feti_vmov(lin,wh(plistih(i)+1),w(plistin(i)+(l/2)+1))
+        endif
+      enddo
+!  waiting for the completion on each interface 
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))
+!       if(narea < listnes(i)) then
+        if(listnes(i,3) < listnes(i,2))then
+            lout=(l-(l/2))
+!           call mpprecv(mesg+listnes(i)-1,w(plistin(i)+(l/2)+1), lout*8)
+            call mpprecv(mesg+listnes(i,2)-1,w(plistin(i)+(l/2)+1), lout*8)
+            call feti_vneg(lout,w(plistin(i)+(l/2)+1),   &
+                w(plistin(i)+(l/2)+1))
+        else
+            lout=(l/2)
+!           call mpprecv(mesg+listnes(i)-1,w(plistin(i)+1),lout*8)
+            call mpprecv(mesg+listnes(i,2)-1,w(plistin(i)+1),lout*8)
+            call feti_vneg(lout,w(plistin(i)+1),w(plistin(i)+1))
+        endif
+      end do
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_restri(numnes,listnes,plistin,numins,plistih,   &
+          numinh,narea,w,wh)
+
+!  restriction of an interface field to one half on each interface
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               plistin =  pointer of sublists of interface nodes
+!               plistih =  pointer of half-sublists of interface nodes
+!               numins  =  number of interface nodes
+!               numinh  =  half number of interface nodes
+!               narea    =  subdomain number
+!               w       =  complete interface vector 
+
+!     OUTPUTS :      wh  =  half interface vector
+
+!     WORKSPACE : work
+      implicit none 
+      integer numnes,numins,numinh,narea
+      integer listnes(numnes,3), plistin(numnes+1), plistih(numnes+1)
+      REAL(kind=8)  wh(numinh),w(numins)
+      integer i,l,lin
+
+!  if subdomains i < j are neighbours, subdomain i manage the first
+!  half of the interface, and subdomain j the remaining part
+
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))
+!       if(narea < listnes(i)) then
+        if(listnes(i,3) < listnes(i,2))then
+            lin=(l/2)
+            call feti_vmov(lin,w(plistin(i)+1),wh(plistih(i)+1))
+        else
+            lin=(l-(l/2))
+            call feti_vmov(lin,w(plistin(i)+(l/2)+1),wh(plistih(i)+1))
+        endif
+      end do
+
+      return
+      end
+!**********************************************************************c
+!!    subroutine feti_halfint(numnes,listnes,plistin,numins,plistih   &
+!!        ,numinh,narea)
+      subroutine feti_halfint(numnes,listnes,plistin,       plistih   &
+          ,numinh      )
+
+!  construction of the pointer of the restriction of an interface 
+!  field to one half on each interface
+
+!     INPUTS :      numnes  =  number of neighbouring subdomains
+!               listnes =  list of neighbouring subdomains
+!               plistin =  pointer of sublists of interface nodes
+!               numins  =  number of interface nodes
+!               narea    =  subdomain number
+
+!     OUTPUTS :      numinh  =  half number of interface nodes
+!               plistih =  pointer of half-sublists of interface nodes
+
+!     WORKSPACE : work
+      implicit none 
+!!    integer numnes,numins,numinh,narea
+      integer numnes,       numinh
+      integer listnes(numnes,3), plistin(numnes+1), plistih(numnes+1)
+      integer i,l
+
+!  if subdomains i < j are neighbours, subdomain i manage the first
+!  half of the interface, and subdomain j the remaining part
+
+      plistih(1)=0
+      numinh=0
+      do i=1,numnes
+        l=(plistin(i+1)-plistin(i))
+!        if(narea < listnes(i,1)) then
+        if(listnes(i,3) < listnes(i,2)) then
+!          write(*,*)'je gere interface avec : ',listnes(i,1)
+            plistih(i+1)=plistih(i)+(l/2)
+        else
+!          write(*,*)'il gere interface avec : ',listnes(i,1)
+            plistih(i+1)=plistih(i)+(l-(l/2))
+        endif
+      end do
+      numinh=plistih(numnes+1)
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_front(n,ni,nj,a,lcmat,cmat,d,v,w,ndlblo,lisblo   &
+          ,nmdlblo)
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension a(n,5)
+!  routine de calcul de la decomposition frontale par blocs de
+!  la matrice pentadiagonale a .
+!  cmat contient les termes des blocs diagonaux factorises .
+      dimension cmat(lcmat),d(n)
+
+!...ndlblo nombre de liberte bloques = nombre de pivots nuls = dim(Ker(Ep))
+
+!...nmdlblo = Max (ndlblo(Ep)) <= superstructure management in f77 context
+!            p=1,Np
+
+      integer ndlblo,nmdlblo
+      integer lisblo(nmdlblo)
+
+!  d ne contient pas, en sortie, l'inverse de la diagonale de Crout .
+!  v est un tableau servant a stocker la partie triangulaire inferieure
+!  stricte d'un bloc diagonal , et w un tableau servant a stocker un
+!  bloc sur-diagonal plein .
+!  de dimension egale a la largeur maximale d'un front .
+      dimension v(ni,ni),w(ni)
+!!!
+      ndimd=ni
+      lbd=ndimd*ndimd
+
+!      lecture du tout premier bloc diagonal
+
+      nb=1
+!  adresse du bloc diagonal courant
+      iac=1
+      call feti_liblod(n,ni,a,ndimd,nb,cmat(iac))
+!  inversion du premier bloc diagonal .
+!     write(*,*)'  inversion du premier bloc diagonal '
+      j0=0
+      call feti_ldlt(ndimd,cmat(iac),d(1),w,ndlblo,lisblo,nmdlblo,j0)
+      call feti_calinv(ndimd,cmat(iac),v)
+
+!  contraction puis inversion des blocs diagonaux de la la matrice
+!  front par front .
+
+      do 2 nb=2,nj
+!       write(*,*)'  front numero ',nb
+!  adresse du bloc diagonal precedent
+        iap=iac
+        iac=(nb-1)*lbd+1
+
+!      lecture du bloc sur-diagonal precedent: passage bande-vecteur
+
+        call feti_liblos(n,a,ndimd,nb-1,w)
+
+!  elimination du bloc extra-diagonal .
+
+!   lecture du bloc diagonal courant: passage bande-plein
+
+        call feti_liblod(n,ni,a,ndimd,nb,cmat(iac))
+
+!  calcul du nouveau bloc diagonal courant .
+
+!       write(*,*)'  calcul du nouveau bloc diagonal courant '
+        call feti_nbdia(ndimd,w,cmat(iap),cmat(iac))
+
+!  inversion du nouveau bloc diagonal courant .
+
+!       write(*,*)'  factorisation du nouveau bloc diagonal courant '
+        j0=(nb-1)*ndimd
+        call feti_ldlt(ndimd,cmat(iac),d((nb-1)*ndimd+1),w,ndlblo,   &
+            lisblo,nmdlblo,j0)
+        call feti_calinv(ndimd,cmat(iac),v)
+
+ 2    continue
+
+      return
+      end
+!**********************************************************************c
+      subroutine feti_calinv(dim,a,b)
+!  calcul de la partie triangulaire inferieure du bloc :
+!  b = [a]-1 puis recopie dans a complet .
+      implicit none
+      integer dim
+      REAL(kind=8)  a(dim,dim),b(dim,dim)
+      integer i,j
+
+      call feti_vclr(dim*dim,b)
+      do j=1,dim
+        b(j,j)=1.e0
+        call feti_desremo(dim,j-1,a,b(1,j),b(1,j))
+      end do
+      do j=1,dim
+        do i=j,dim
+          a(i,j)=b(i,j)
+          a(j,i)=b(i,j)
+        end do
+      end do
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_nbdia(n,d,w,v)
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension d(n),v(n,n),w(n,n)
+
+      do 1 j=1,n
+        do 2 i=1,n
+          v(i,j)=v(i,j)-d(i)*w(i,j)*d(j)
+ 2      continue
+ 1    continue
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_liblod(n,ni,a,ndimd,nb,db)
+
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension db(ndimd,ndimd)
+!  tableaux descripteurs de la structure morse de la matrice .
+      dimension a(n,5)
+
+      call feti_vclr(ndimd*ndimd,db)
+!       do i=1,ndimd*ndimd
+!         db(i,1)=0.e0
+!8     continue
+      n0=(nb-1)*ndimd
+!  lecture de la diagonale db(i,i) .
+      do 3 i=1,ndimd
+        db(i,i)=a(n0+i,3)
+ 3    continue
+!  lecture de la premiere sur-diagonale db(i,i+1) .
+      do 4 i=1,ndimd-1
+        db(i,i+1)=a(n0+i,4)
+ 4    continue
+!  lecture de la premiere sous-diagonale db(i,i-1) .
+      do 2 i=2,ndimd
+        db(i,i-1)=a(n0+i,2)
+ 2    continue
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_liblos(n,a,ndimd,nb,v)
+
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension v(ndimd)
+!  tableaux descripteurs de la structure morse de la matrice .
+      dimension a(n,5)
+
+      n0=(nb-1)*ndimd
+!  lecture de la deuxieme sur-diagonale v(i) .
+      do 5 i=1,ndimd
+        v(i)=a(n0+i,5)
+ 5    continue
+
+      return
+      end
+!***********************************************************************
+      subroutine feti_resloc(n,ni,nj,a,lcmat,cmat,y,x,z)
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension a(n,5)
+!  routine de resolution utilisant la decomposition frontale par blocs
+!  de la matrice heptadiagonale a .
+!  cmat contient les termes des blocs diagonaux factorises .
+      dimension cmat(lcmat)
+!  d contient l'inverse de la diagonale de Crout .
+      dimension y(n),x(n),z(n)
+!
+      call feti_vmov(n,y,z)
+      ndimd=ni
+      lbd=ndimd*ndimd
+!  descente du systeme .
+      do nb=1,nj-1
+!  calcul du second membre condense : z(i+1)=y(i+1)- FD-1 z(i) .
+        iacmat=(nb-1)*lbd+1
+        n0=(nb-1)*ndimd
+        call feti_mxv(ndimd,ndimd,cmat(iacmat),z(n0+1),x(n0+1))
+        call feti_pbloi(n,ni,nj,a,x,z,nb)
+      end do
+!  inversion du dernier bloc diagonal .
+      iacmat=(nj-1)*lbd+1
+      n0=(nj-1)*ndimd
+      call feti_mxv(ndimd,ndimd,cmat(iacmat),z(n0+1),x(n0+1))
+!  remontee du systeme par bloc .
+      do nb=nj-1,1,-1
+!  calcul du second membre condense : z(i)=z(i)- E x(i+1) .
+        call feti_pblos(n,ni,nj,a,x,z,nb)
+!  calcul de la solution pour le bloc diagonal courant .
+        iacmat=(nb-1)*lbd+1
+        n0=(nb-1)*ndimd
+        call feti_mxv(ndimd,ndimd,cmat(iacmat),z(n0+1),x(n0+1))
+      end do
+
+      end
+!***********************************************************************
+      subroutine feti_pblos(n,ni,nj,a,x,y,nb)
+!  calcul du produit matrice-vecteur morse : y = y - A x .
+!  produit par le bloc superieur numero nb .
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension a(n,5)
+      dimension x(n),y(n)
+
+      n0=(nb-1)*ni
+!  produit par la deuxieme sur-diagonale a(i,i+ni) .
+      do i=n0+1,n0+ni
+        y(i)=y(i)-x(i+ni)*a(i,5)
+      end do
+
+      end subroutine feti_pblos
+!***********************************************************************
+      subroutine feti_pbloi(n,ni,nj,a,x,y,nb)
+!  calcul du produit matrice-vecteur morse : y = y - A x .
+!  produit par le bloc inferieur numero nb .
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension a(n,5)
+      dimension x(n),y(n)
+
+      n0=nb*ni
+!  produit par la deuxieme sous-diagonale a(i,i-ni) .
+      do i=n0+1,n0+ni
+        y(i)=y(i)-x(i-ni)*a(i,1)
+      end do
+
+      end subroutine feti_pbloi
+!***********************************************************************
+      subroutine feti_proax(n,ni,nj,a,x,y)
+!  calcul du produit matrice-vecteur morse par la matrice heptadiagonale
+!  a stockee par bandes .
+      implicit REAL(kind=8) (a-h,o-z)
+      dimension a(n,5)
+      dimension x(n),y(n)
+
+!  produit par la diagonale .
+      do i=1,n
+        y(i)=x(i)*a(i,3)
+      end do
+!  produit par la premiere sur-diagonale a(i,i+1) .
+      do i=1,n-1
+        y(i)=y(i)+x(i+1)*a(i,4)
+      end do
+!  produit par la deuxieme sur-diagonale a(i,i+ni) .
+      do i=1,n-ni
+        y(i)=y(i)+x(i+ni)*a(i,5)
+      end do
+! produit par la premiere sous-diagonale a(i,i-1)
+      do i=2,n
+          y(i)=y(i)+x(i-1)*a(i,2)
+      end do
+! produit par la deuxieme sous-diagonale a(i,i-ni)
+      do i=1+ni,n
+          y(i)=y(i)+x(i-ni)*a(i,1)
+      end do
+
+      end subroutine feti_proax
+
+#else
+   !! no use of FETI librairy
+#endif
+
+   !!======================================================================
+END MODULE lib_feti
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_isml.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_isml.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_isml.f90	(revision 4536)
@@ -0,0 +1,675 @@
+!
+! subroutines for PCG or SOR solvers
+! (used if the ISML library is not available)
+!
+! linrg
+!   gauss
+!   vmov
+!   desremopt
+!   dtrsv
+!   dger
+!   xerbla
+!   lsame
+! folr (empty)
+!
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+!---------------------------------------------------------
+   SUBROUTINE linrg(kn,pa,klda,painv,kldainv)
+
+      !! compute inverse matrix
+
+      IMPLICIT NONE 
+      INTEGER kn,klda,kldainv
+      REAL (kind=8) ::   pa(kn,kn),painv(kn,kn)
+      REAL (kind=8) ::   zb(kn,kn)
+      REAL (kind=8) ::   zv(kn)
+      INTEGER iplin(kn)
+      INTEGER ji
+
+      IF( kn /= klda .OR. kn /= kldainv ) THEN 
+          write(0,*)'change your parameters'
+          STOP 
+      ENDIF 
+
+      CALL vmov( kn*kn, pa, painv )
+
+      CALL gauss( kn, painv, iplin, zv )
+
+      zb(:,:) = 0.e0   
+      DO ji = 1, kn
+        zb(ji,ji) = 1.e0
+        CALL desremopt( kn, painv, iplin, zb(1,ji), zb(1,ji), zv )
+      END DO 
+      CALL vmov( kn*kn, zb, painv )
+
+   END SUBROUTINE linrg
+!---------------------------------------------------------
+   SUBROUTINE gauss(kn,pa,kplin,pv)
+
+      IMPLICIT NONE 
+      INTEGER kn
+      INTEGER ji,jj,jk
+      INTEGER ik,ipp
+      REAL (kind=8) ::   pa(kn,kn),pv(kn)
+!!    REAL (kind=8) ::   zpivmax,zalpha
+      REAL (kind=8) ::   zalpha
+      INTEGER kplin(kn)
+      INTEGER isamax
+      EXTERNAL isamax
+
+!  factorisation de Gauss de la matrice a avec pivot partiel . 
+!  initialisation des pointeurs .
+      DO ji=1,kn
+        kplin(ji)=ji
+      END DO 
+      DO jk=1,kn-1
+!  recherche du pivot maximal .
+!!      ik=jk
+!!      zpivmax=dabs(pa(jk,jk))
+!!        DO ji=jk,kn
+!!          IF(dabs(pa(ji,jk)) > zpivmax) THEN 
+!!            zpivmax=dabs(pa(ji,jk))
+!!            ik=ji
+!!          ENDIF 
+!!        END DO 
+        ik=isamax( kn-jk+1, pa(jk,jk) )+jk-1
+!  permutation de la ligne jk et de la ligne ik .
+        IF(jk == 58) THEN
+            PRINT *,'matrix ',(pa(jk,ji),ji=1,kn)
+            PRINT *,' pivot ',ik,kplin(ik),kplin(jk)
+        ENDIF 
+        ipp=kplin(ik)
+        kplin(ik)=kplin(jk)
+        kplin(jk)=ipp
+        DO jj=1,kn
+          pv(jj)=pa(ik,jj)
+          pa(ik,jj)=pa(jk,jj)
+          pa(jk,jj)=pv(jj)
+        END DO 
+        IF(jk == 58) THEN
+            PRINT *,'matrix ',(pa(jk,ji),ji=1,kn)
+            PRINT *,' pivot ',ik,kplin(ik),kplin(jk)
+        ENDIF 
+!  calcul des coefficients de la colonne k ligne a ligne .
+        DO ji=jk+1,kn
+          IF(pa(jk,jk) == 0) THEN 
+              PRINT *,'probleme diagonale nulle',jk,pa(jk,jk)
+              pa(ji,jk)=pa(ji,jk)/1.E-20
+          ENDIF 
+          IF(pa(jk,jk) /= 0) pa(ji,jk)=pa(ji,jk)/pa(jk,jk)
+        END DO 
+!!        DO ji=jk+1,kn
+!!          DO jj=jk+1,kn
+!!            pa(ji,jj)=pa(ji,jj)-pa(ji,jk)*pa(jk,jj)
+!!          END DO 
+!!        END DO 
+        zalpha=-1.
+        CALL dger(kn-jk,kn-jk,zalpha,pa(jk+1,jk),1,pa(jk,jk+1),kn,   &
+            pa(jk+1,jk+1),kn)
+      END DO 
+
+   END SUBROUTINE gauss
+!---------------------------------------------------------
+   FUNCTION isamax( I, X )
+      DIMENSION X(I)
+      ISAMAX = 0
+      XMIN = -huge(1.)
+      DO N = 1, I
+         IF(ABS(X(N)) > XMIN ) THEN
+            XMIN = X(N)
+            ISAMAX = N
+         ENDIF
+      END DO
+   END FUNCTION isamax
+!---------------------------------------------------------
+   SUBROUTINE vmov(kn,px,py)
+
+      IMPLICIT NONE 
+      INTEGER kn
+      REAL (kind=8) ::   px(kn),py(kn)
+      INTEGER ji
+
+      DO ji=1,kn
+         py(ji)=px(ji)
+      END DO 
+
+   END SUBROUTINE vmov
+!---------------------------------------------------------
+   subroutine desremopt(n,a,plin,y,x,v)
+      implicit none
+      integer n,i,  j0
+!!    integer n,i,j,j0
+      real (kind=8) ::   a(n,n),x(n),y(n),v(n)
+      integer plin(n)
+!  descente remontee du systeme .
+!  initialisation du vecteur resultat .
+!  prise en compte de la permutation des lignes .
+      do i=1,n
+        v(i)=y(plin(i))
+      end do
+      do i=1,n
+        if(v(i) /= 0.) then
+          j0=i-1
+          goto 1
+        endif
+      end do
+1     continue
+!  descente du systeme L v = v , L est a diagonale unitaire .
+!!      do j=j0+1,n
+!!        do i=j+1,n
+!!          v(i)=v(i)-a(i,j)*v(j)
+!!        end do
+!!      end do
+      call dtrsv('L','N','U',n-j0,a(j0+1,j0+1),n,v(j0+1),1)
+!  remontee du systeme U v = v . 
+!!      do j=n,1,-1
+!!        v(j)=v(j)/a(j,j)
+!!        do i=1,j-1
+!!          v(i)=v(i)-a(i,j)*v(j)
+!!        end do
+!!      end do          
+      call dtrsv('U','N','N',n,a,n,v,1)
+!  prise en compte de la permutation des colonnes .
+      do i=1,n
+        x(i)=v(i)
+      end do
+
+   end SUBROUTINE desremopt
+!---------------------------------------------------------
+   SUBROUTINE DTRSV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
+!!    .. Scalar Arguments ..
+      INTEGER            INCX, LDA, N
+      CHARACTER (len=1) ::   DIAG, TRANS, UPLO
+!!    .. Array Arguments ..
+!     DOUBLE PRECISION   A( LDA, * ), X( * )
+      REAL (kind=8) ::     A( LDA, * ), X( * )
+!!    ..
+
+!! Purpose
+!! =======
+
+!! DTRSV  solves one of the systems of equations
+
+!!    A*x = b,   or   A'*x = b,
+
+!! where b and x are n element vectors and A is an n by n unit, or
+!! non-unit, upper or lower triangular matrix.
+
+!! No test for singularity or near-singularity is included in this
+!! routine. Such tests must be performed before calling this routine.
+
+!! Parameters
+!! ==========
+
+!! UPLO   - CHARACTER*1.
+!!          On entry, UPLO specifies whether the matrix is an upper or
+!!          lower triangular matrix as follows:
+
+!!             UPLO = 'U' or 'u'   A is an upper triangular matrix.
+
+!!             UPLO = 'L' or 'l'   A is a lower triangular matrix.
+
+!!          Unchanged on exit.
+
+!! TRANS  - CHARACTER*1.
+!!          On entry, TRANS specifies the equations to be solved as
+!!          follows:
+
+!!             TRANS = 'N' or 'n'   A*x = b.
+
+!!             TRANS = 'T' or 't'   A'*x = b.
+
+!!             TRANS = 'C' or 'c'   A'*x = b.
+
+!!          Unchanged on exit.
+
+!! DIAG   - CHARACTER*1.
+!!          On entry, DIAG specifies whether or not A is unit
+!!          triangular as follows:
+
+!!             DIAG = 'U' or 'u'   A is assumed to be unit triangular.
+
+!!             DIAG = 'N' or 'n'   A is not assumed to be unit
+!!                                 triangular.
+
+!!          Unchanged on exit.
+
+!! N      - INTEGER.
+!!          On entry, N specifies the order of the matrix A.
+!!          N must be at least zero.
+!!          Unchanged on exit.
+
+!! A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
+!!          Before entry with  UPLO = 'U' or 'u', the leading n by n
+!!          upper triangular part of the array A must contain the upper
+!!          triangular matrix and the strictly lower triangular part of
+!!          A is not referenced.
+!!          Before entry with UPLO = 'L' or 'l', the leading n by n
+!!          lower triangular part of the array A must contain the lower
+!!          triangular matrix and the strictly upper triangular part of
+!!          A is not referenced.
+!!          Note that when  DIAG = 'U' or 'u', the diagonal elements of
+!!          A are not referenced either, but are assumed to be unity.
+!!          Unchanged on exit.
+
+!! LDA    - INTEGER.
+!!          On entry, LDA specifies the first dimension of A as declared
+!!          in the calling (sub) program. LDA must be at least
+!!          max( 1, n ).
+!!          Unchanged on exit.
+
+!! X      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( n - 1 )*abs( INCX ) ).
+!!          Before entry, the incremented array X must contain the n
+!!          element right-hand side vector b. On exit, X is overwritten
+!!          with the solution vector x.
+
+!! INCX   - INTEGER.
+!!          On entry, INCX specifies the increment for the elements of
+!!          X. INCX must not be zero.
+!!          Unchanged on exit.
+
+
+!! Level 2 Blas routine.
+
+!! -- Written on 22-October-1986.
+!!    Jack Dongarra, Argonne National Lab.
+!!    Jeremy Du Croz, Nag Central Office.
+!!    Sven Hammarling, Nag Central Office.
+!!    Richard Hanson, Sandia National Labs.
+
+
+!!    .. Parameters ..
+!     DOUBLE PRECISION   ZERO
+!     PARAMETER        ( ZERO = 0.0D+0 )
+      REAL (kind=8) ::                 ZERO
+      PARAMETER        ( ZERO = 0.0 )
+!!    .. Local Scalars ..
+!     DOUBLE PRECISION   TEMP
+      REAL (kind=8) ::                 TEMP
+      INTEGER            I, INFO, IX, J, JX, KX
+      LOGICAL            NOUNIT
+!!    .. External Functions ..
+      LOGICAL            LSAME
+      EXTERNAL           LSAME
+!!    .. External Subroutines ..
+      EXTERNAL           XERBLA
+!!    .. Intrinsic Functions ..
+      INTRINSIC          MAX
+!!    ..
+!!    .. Executable Statements ..
+
+!!    Test the input parameters.
+
+      INFO = 0
+      IF     ( .NOT.LSAME( UPLO , 'U' ).AND.   &
+               .NOT.LSAME( UPLO , 'L' )      )THEN
+         INFO = 1
+      ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.   &
+               .NOT.LSAME( TRANS, 'T' ).AND.   &
+               .NOT.LSAME( TRANS, 'C' )      )THEN
+         INFO = 2
+      ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.   &
+               .NOT.LSAME( DIAG , 'N' )      )THEN
+         INFO = 3
+      ELSE IF( N < 0 )THEN
+         INFO = 4
+      ELSE IF( LDA < MAX( 1, N ) )THEN
+         INFO = 6
+      ELSE IF( INCX == 0 )THEN
+         INFO = 8
+      END IF
+      IF( INFO /= 0 )THEN
+         CALL XERBLA( 'DTRSV ', INFO )
+         RETURN
+      END IF
+
+!!    Quick return if possible.
+
+      IF( N == 0 )   RETURN
+
+      NOUNIT = LSAME( DIAG, 'N' )
+
+!!    Set up the start point in X if the increment is not unity. This
+!!    will be  ( N - 1 )*INCX  too small for descending loops.
+
+      IF( INCX <= 0 )THEN
+         KX = 1 - ( N - 1 )*INCX
+      ELSE IF( INCX /= 1 )THEN
+         KX = 1
+      END IF
+
+!!    Start the operations. In this version the elements of A are
+!!    accessed sequentially with one pass through A.
+
+      IF( LSAME( TRANS, 'N' ) )THEN
+
+!!       Form  x := inv( A )*x.
+
+         IF( LSAME( UPLO, 'U' ) )THEN
+            IF( INCX == 1 )THEN
+               DO 20, J = N, 1, -1
+                  IF( X( J ) /= ZERO )THEN
+                     IF( NOUNIT )   X( J ) = X( J )/A( J, J )
+                     TEMP = X( J )
+                     DO 10, I = J - 1, 1, -1
+                        X( I ) = X( I ) - TEMP*A( I, J )
+   10                CONTINUE
+                  END IF
+   20          CONTINUE
+            ELSE
+               JX = KX + ( N - 1 )*INCX
+               DO 40, J = N, 1, -1
+                  IF( X( JX ) /= ZERO )THEN
+                     IF( NOUNIT )  X( JX ) = X( JX )/A( J, J )
+                     TEMP = X( JX )
+                     IX   = JX
+                     DO 30, I = J - 1, 1, -1
+                        IX      = IX      - INCX
+                        X( IX ) = X( IX ) - TEMP*A( I, J )
+   30                CONTINUE
+                  END IF
+                  JX = JX - INCX
+   40          CONTINUE
+            END IF
+         ELSE
+            IF( INCX == 1 )THEN
+               DO 60, J = 1, N
+                  IF( X( J ) /= ZERO )THEN
+                     IF( NOUNIT )   X( J ) = X( J )/A( J, J )
+                     TEMP = X( J )
+                     DO 50, I = J + 1, N
+                        X( I ) = X( I ) - TEMP*A( I, J )
+   50                CONTINUE
+                  END IF
+   60          CONTINUE
+            ELSE
+               JX = KX
+               DO 80, J = 1, N
+                  IF( X( JX ) /= ZERO )THEN
+                     IF( NOUNIT )   X( JX ) = X( JX )/A( J, J )
+                     TEMP = X( JX )
+                     IX   = JX
+                     DO 70, I = J + 1, N
+                        IX      = IX      + INCX
+                        X( IX ) = X( IX ) - TEMP*A( I, J )
+   70                CONTINUE
+                  END IF
+                  JX = JX + INCX
+   80          CONTINUE
+            END IF
+         END IF
+      ELSE
+
+!!       Form  x := inv( A' )*x.
+
+         IF( LSAME( UPLO, 'U' ) )THEN
+            IF( INCX == 1 )THEN
+               DO 100, J = 1, N
+                  TEMP = X( J )
+                  DO 90, I = 1, J - 1
+                     TEMP = TEMP - A( I, J )*X( I )
+   90             CONTINUE
+                  IF( NOUNIT )   TEMP = TEMP/A( J, J )
+                  X( J ) = TEMP
+  100          CONTINUE
+            ELSE
+               JX = KX
+               DO 120, J = 1, N
+                  TEMP = X( JX )
+                  IX   = KX
+                  DO 110, I = 1, J - 1
+                     TEMP = TEMP - A( I, J )*X( IX )
+                     IX   = IX   + INCX
+  110             CONTINUE
+                  IF( NOUNIT )   TEMP = TEMP/A( J, J )
+                  X( JX ) = TEMP
+                  JX      = JX   + INCX
+  120          CONTINUE
+            END IF
+         ELSE
+            IF( INCX == 1 )THEN
+               DO 140, J = N, 1, -1
+                  TEMP = X( J )
+                  DO 130, I = N, J + 1, -1
+                     TEMP = TEMP - A( I, J )*X( I )
+  130             CONTINUE
+                  IF( NOUNIT )    TEMP = TEMP/A( J, J )
+                  X( J ) = TEMP
+  140          CONTINUE
+            ELSE
+               KX = KX + ( N - 1 )*INCX
+               JX = KX
+               DO 160, J = N, 1, -1
+                  TEMP = X( JX )
+                  IX   = KX
+                  DO 150, I = N, J + 1, -1
+                     TEMP = TEMP - A( I, J )*X( IX )
+                     IX   = IX   - INCX
+  150             CONTINUE
+                  IF( NOUNIT )    TEMP = TEMP/A( J, J )
+                  X( JX ) = TEMP
+                  JX      = JX   - INCX
+  160          CONTINUE
+            END IF
+         END IF
+      END IF
+
+   END SUBROUTINE DTRSV
+!---------------------------------------------------------
+   SUBROUTINE DGER  ( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )
+!!    .. Scalar Arguments ..
+!     DOUBLE PRECISION   ALPHA
+      REAL (kind=8) ::                 ALPHA
+      INTEGER            INCX, INCY, LDA, M, N
+!!    .. Array Arguments ..
+!     DOUBLE PRECISION   A( LDA, * ), X( * ), Y( * )
+      REAL (kind=8) ::   A( LDA, * ), X( * ), Y( * )
+!!    ..
+
+!! Purpose
+!! =======
+
+!! DGER   performs the rank 1 operation
+
+!!    A := alpha*x*y' + A,
+
+!! where alpha is a scalar, x is an m element vector, y is an n element
+!! vector and A is an m by n matrix.
+
+!! Parameters
+!! ==========
+
+!! M      - INTEGER.
+!!          On entry, M specifies the number of rows of the matrix A.
+!!          M must be at least zero.
+!!          Unchanged on exit.
+
+!! N      - INTEGER.
+!!          On entry, N specifies the number of columns of the matrix A.
+!!          N must be at least zero.
+!!          Unchanged on exit.
+
+!! ALPHA  - DOUBLE PRECISION.
+!!          On entry, ALPHA specifies the scalar alpha.
+!!          Unchanged on exit.
+
+!! X      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( m - 1 )*abs( INCX ) ).
+!!          Before entry, the incremented array X must contain the m
+!!          element vector x.
+!!          Unchanged on exit.
+
+!! INCX   - INTEGER.
+!!          On entry, INCX specifies the increment for the elements of
+!!          X. INCX must not be zero.
+!!          Unchanged on exit.
+
+!! Y      - DOUBLE PRECISION array of dimension at least
+!!          ( 1 + ( n - 1 )*abs( INCY ) ).
+!!          Before entry, the incremented array Y must contain the n
+!!          element vector y.
+!!          Unchanged on exit.
+
+!! INCY   - INTEGER.
+!!          On entry, INCY specifies the increment for the elements of
+!!          Y. INCY must not be zero.
+!!          Unchanged on exit.
+
+!! A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
+!!          Before entry, the leading m by n part of the array A must
+!!          contain the matrix of coefficients. On exit, A is
+!!          overwritten by the updated matrix.
+
+!! LDA    - INTEGER.
+!!          On entry, LDA specifies the first dimension of A as declared
+!!          in the calling (sub) program. LDA must be at least
+!!          max( 1, m ).
+!!          Unchanged on exit.
+
+
+!! Level 2 Blas routine.
+
+!! -- Written on 22-October-1986.
+!!    Jack Dongarra, Argonne National Lab.
+!!    Jeremy Du Croz, Nag Central Office.
+!!    Sven Hammarling, Nag Central Office.
+!!    Richard Hanson, Sandia National Labs.
+
+
+!!    .. Parameters ..
+!     DOUBLE PRECISION   ZERO
+!     PARAMETER        ( ZERO = 0.0D+0 )
+      REAL (kind=8) ::                 ZERO
+      PARAMETER        ( ZERO = 0.0 )
+!!    .. Local Scalars ..
+!     DOUBLE PRECISION   TEMP
+      REAL (kind=8) ::                 TEMP
+      INTEGER            I, INFO, IX, J, JY, KX
+!!    .. External Subroutines ..
+      EXTERNAL           XERBLA
+!!    .. Intrinsic Functions ..
+      INTRINSIC          MAX
+!!    ..
+!!    .. Executable Statements ..
+
+!!    Test the input parameters.
+
+      INFO = 0
+      IF     ( M < 0 )THEN
+         INFO = 1
+      ELSE IF( N < 0 )THEN
+         INFO = 2
+      ELSE IF( INCX == 0 )THEN
+         INFO = 5
+      ELSE IF( INCY == 0 )THEN
+         INFO = 7
+      ELSE IF( LDA < MAX( 1, M ) )THEN
+         INFO = 9
+      END IF
+      IF( INFO /= 0 )THEN
+         CALL XERBLA( 'DGER  ', INFO )
+         RETURN
+      END IF
+
+!!    Quick return if possible.
+
+      IF( ( M == 0 ).OR.( N == 0 ).OR.( ALPHA == ZERO ) )   &
+         RETURN
+
+!!    Start the operations. In this version the elements of A are
+!!    accessed sequentially with one pass through A.
+
+      IF( INCY > 0 )THEN
+         JY = 1
+      ELSE
+         JY = 1 - ( N - 1 )*INCY
+      END IF
+      IF( INCX == 1 )THEN
+         DO 20, J = 1, N
+            IF( Y( JY ) /= ZERO )THEN
+               TEMP = ALPHA*Y( JY )
+               DO 10, I = 1, M
+                  A( I, J ) = A( I, J ) + X( I )*TEMP
+   10          CONTINUE
+            END IF
+            JY = JY + INCY
+   20    CONTINUE
+      ELSE
+         IF( INCX > 0 )THEN
+            KX = 1
+         ELSE
+            KX = 1 - ( M - 1 )*INCX
+         END IF
+         DO 40, J = 1, N
+            IF( Y( JY ) /= ZERO )THEN
+               TEMP = ALPHA*Y( JY )
+               IX   = KX
+               DO 30, I = 1, M
+                  A( I, J ) = A( I, J ) + X( IX )*TEMP
+                  IX        = IX        + INCX
+   30          CONTINUE
+            END IF
+            JY = JY + INCY
+   40    CONTINUE
+      END IF
+
+   END SUBROUTINE DGER
+!---------------------------------------------------------
+   SUBROUTINE XERBLA ( SRNAME, INFO )
+!!    ..    Scalar Arguments ..
+      INTEGER            INFO
+      CHARACTER (len=6) ::    SRNAME
+!!    ..
+
+!! Purpose
+!! =======
+
+!! XERBLA  is an error handler for the Level 2 BLAS routines.
+
+!! It is called by the Level 2 BLAS routines if an input parameter is
+!! invalid.
+
+!! Installers should consider modifying the STOP statement in order to
+!! call system-specific exception-handling facilities.
+
+!! Parameters
+!! ==========
+
+!! SRNAME - CHARACTER*6.
+!!          On entry, SRNAME specifies the name of the routine which
+!!          called XERBLA.
+
+!! INFO   - INTEGER.
+!!          On entry, INFO specifies the position of the invalid
+!!          parameter in the parameter-list of the calling routine.
+
+
+!! Auxiliary routine for Level 2 Blas.
+
+!! Written on 20-July-1986.
+
+!!    .. Executable Statements ..
+
+      WRITE (*,99999) SRNAME, INFO
+
+      STOP
+
+99999 FORMAT ( ' ** On entry to ', A6, ' parameter number ', I2,   &
+               ' had an illegal value' )
+
+   END SUBROUTINE XERBLA
+!-----------------------------------------------------------
+   FUNCTION lsame( c1, c2 )
+      logical lsame
+      CHARACTER (len=*), INTENT(in) ::   c1, c2
+      IF( c1 == c2 ) THEN
+          lsame=.TRUE.
+      ELSE
+          lsame=.FALSE.
+      ENDIF
+   END FUNCTION lsame
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_mpp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_mpp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_mpp.F90	(revision 4536)
@@ -0,0 +1,5416 @@
+MODULE lib_mpp
+   !!======================================================================
+   !!                       ***  MODULE  lib_mpp  ***
+   !! Ocean numerics:  massively parallel processing librairy
+   !!=====================================================================
+#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'     OR      MPI massively parallel processing library
+   !!   'key_mpp_shmem'         SHMEM massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!   mynode
+   !!   mpparent
+   !!   mppshmem
+   !!   mpp_lnk     : generic interface (defined in lbclnk) for :
+   !!                 mpp_lnk_2d, mpp_lnk_3d
+   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
+   !!   mpp_lnk_e   : interface defined in lbclnk
+   !!   mpplnks
+   !!   mpprecv
+   !!   mppsend
+   !!   mppscatter
+   !!   mppgather
+   !!   mpp_isl    : generic inteface  for :
+   !!                mppisl_int , mppisl_a_int , mppisl_real, mppisl_a_real
+   !!   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
+   !!   mppobc     : variant of mpp_lnk for open boundaries
+   !!   mpp_ini_north
+   !!   mpp_lbc_north
+   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo (nsolv=4)
+   !!----------------------------------------------------------------------
+   !! History :
+   !!        !  94 (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!        !  97  (A.M. Treguier)  SHMEM additions
+   !!        !  98  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!   9.0  !  03  (J.-M. Molines, G. Madec)  F90, free form
+   !!        !  04  (R. Bourdalle Badie)  isend option in mpi
+   !!        !  05  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!        !  05  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/lib_mpp.F90,v 1.21 2007/06/05 10:28:55 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce                    ! ocean space and time domain 
+   USE in_out_manager             ! I/O manager
+
+   IMPLICIT NONE
+
+   PRIVATE
+   PUBLIC  mynode, mpparent, mpp_isl, mpp_min, mpp_max, mpp_sum,  mpp_lbc_north
+   PUBLIC  mpp_lbc_north_e, mpp_minloc, mpp_maxloc, mpp_lnk_3d, mpp_lnk_2d, mpp_lnk_3d_gather, mpp_lnk_2d_e, mpplnks
+   PUBLIC  mpprecv, mppsend, mppscatter, mppgather, mppobc, mpp_ini_north, mppstop, mppsync
+#if defined key_oasis3 || defined key_oasis4
+   PUBLIC  mppsize, mpprank
+#endif
+
+   !! * 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_isl
+      MODULE PROCEDURE mppisl_a_int, mppisl_int, mppisl_a_real, mppisl_real
+   END INTERFACE
+   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
+   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
+
+
+   !! * Share module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.       !: mpp flag
+
+   !! The processor number is a required power of two : 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,...
+   INTEGER, PARAMETER ::   &
+      nprocmax = 2**10     ! maximun dimension
+
+#if defined key_mpp_mpi
+   !! ========================= !!
+   !!  MPI  variable definition !!
+   !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
+#  include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
+
+   INTEGER ::   &
+      mppsize,  &  ! number of process
+      mpprank,  &  ! process number  [ 0 - size-1 ]
+      mpi_comm_opa ! opa local communicator
+
+   ! variables used in case of north fold condition in mpp_mpi with jpni > 1
+   INTEGER ::      &       !
+      ngrp_world,  &       ! group ID for the world processors
+      ngrp_north,  &       ! group ID for the northern processors (to be fold)
+      ncomm_north, &       ! communicator made by the processors belonging to ngrp_north
+      ndim_rank_north, &   ! number of 'sea' processor in the northern line (can be /= jpni !)
+      njmppmax             ! value of njmpp for the processors of the northern line
+   INTEGER ::      &       !
+      north_root           ! number (in the comm_opa) of proc 0 in the northern comm
+   INTEGER, DIMENSION(:), ALLOCATABLE ::   &
+      nrank_north          ! dimension ndim_rank_north, number of the procs belonging to ncomm_north
+   CHARACTER (len=1) ::  &
+      c_mpi_send = 'S'     ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
+   LOGICAL  ::           &
+      l_isend = .FALSE.    ! isend use indicator (T if c_mpi_send='I')
+
+
+#elif defined key_mpp_shmem
+   !! ========================= !!
+   !! SHMEM variable definition !!
+   !! ========================= !!
+#  include  <fpvm3.h>
+#  include <mpp/shmem.fh>
+
+   CHARACTER (len=80), PARAMETER ::   simfile    = 'pvm3_ndim'   ! file name
+   CHARACTER (len=47), PARAMETER ::   executable = 'opa'         ! executable name
+   CHARACTER, PARAMETER ::            opaall     = ""            ! group name (old def opaall*(*))
+
+   INTEGER, PARAMETER ::   & !! SHMEM control print
+      mynode_print   = 0,  &  ! flag for print, mynode   routine
+      mpprecv_print  = 0,  &  ! flag for print, mpprecv  routine
+      mppsend_print  = 0,  &  ! flag for print, mppsend  routine
+      mppsync_print  = 0,  &  ! flag for print, mppsync  routine
+      mppsum_print   = 0,  &  ! flag for print, mpp_sum  routine
+      mppisl_print   = 0,  &  ! flag for print, mpp_isl  routine
+      mppmin_print   = 0,  &  ! flag for print, mpp_min  routine
+      mppmax_print   = 0,  &  ! flag for print, mpp_max  routine
+      mpparent_print = 0      ! flag for print, mpparent routine
+
+   INTEGER, PARAMETER ::   & !! Variable definition
+      jpvmint = 21            ! ???
+
+   INTEGER, PARAMETER ::   & !! Maximum  dimension of array to sum on the processors
+      jpmsec   = 50000,    &  ! ???
+      jpmpplat =    30,    &  ! ???
+      jpmppsum = MAX( jpisl*jpisl, jpmpplat*jpk, jpmsec )   ! ???
+
+   INTEGER ::   &
+      npvm_ipas ,  &  ! pvm initialization flag
+      npvm_mytid,  &  ! pvm tid
+      npvm_me   ,  &  ! node number [ 0 - nproc-1 ]
+      npvm_nproc,  &  ! real number of nodes
+      npvm_inum       ! ???
+   INTEGER, DIMENSION(0:nprocmax-1) ::   &
+      npvm_tids       ! tids array [ 0 - nproc-1 ]
+
+   INTEGER ::   &
+      nt3d_ipas ,  &  ! pvm initialization flag
+      nt3d_mytid,  &  ! pvm tid
+      nt3d_me   ,  &  ! node number [ 0 - nproc-1 ]
+      nt3d_nproc      ! real number of nodes
+   INTEGER, DIMENSION(0:nprocmax-1) ::   &
+      nt3d_tids       ! tids array [ 0 - nproc-1 ]
+
+   !! real sum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nrs1sync_shmem,   &  ! 
+       nrs2sync_shmem
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wrs1wrk_shmem,    &  !
+       wrs2wrk_shmem        !
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wrstab_shmem         !
+
+   !! minimum and maximum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       ni1sync_shmem,    &  ! 
+       ni2sync_shmem        ! 
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wi1wrk_shmem,     &  !
+       wi2wrk_shmem
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wintab_shmem,     &  ! 
+       wi1tab_shmem,     &  ! 
+       wi2tab_shmem         ! 
+       
+       !! value not equal zero for barotropic stream function around islands
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       ni11sync_shmem,   &  !
+       ni12sync_shmem,   &  !
+       ni21sync_shmem,   &  !
+       ni22sync_shmem       !
+   REAL(wp), DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       wi11wrk_shmem,    &  ! 
+       wi12wrk_shmem,    &  !
+       wi21wrk_shmem,    &  !
+       wi22wrk_shmem        !
+   REAL(wp), DIMENSION(jpmppsum) ::   &
+       wiltab_shmem ,    &  !
+       wi11tab_shmem,    &  !
+       wi12tab_shmem,    &  ! 
+       wi21tab_shmem,    &  ! 
+       wi22tab_shmem
+
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       ni11wrk_shmem,    &  !
+       ni12wrk_shmem,    &  !
+       ni21wrk_shmem,    &  !
+       ni22wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       niitab_shmem ,    &  !
+       ni11tab_shmem,    &  !
+       ni12tab_shmem        !
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nis1sync_shmem,   &  !
+       nis2sync_shmem       !
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       nis1wrk_shmem,    &  ! 
+       nis2wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       nistab_shmem
+
+   !! integer sum reduction
+   INTEGER, DIMENSION(SHMEM_REDUCE_SYNC_SIZE) ::   &
+       nil1sync_shmem,   &  !
+       nil2sync_shmem       !
+   INTEGER, DIMENSION( MAX( SHMEM_REDUCE_MIN_WRKDATA_SIZE, jpmppsum/2+1 ) ) ::   &
+       nil1wrk_shmem,    &  !
+       nil2wrk_shmem        !
+   INTEGER, DIMENSION(jpmppsum) ::   &
+       niltab_shmem
+#endif
+
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   &
+       t4ns, t4sn  ! 3d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2,2) ::   &
+       t4ew, t4we  ! 3d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2,2) ::   &
+       t4p1, t4p2  ! 3d message passing arrays north fold
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2) ::   &
+       t3ns, t3sn  ! 3d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,jpk,2) ::   &
+       t3ew, t3we  ! 3d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,jpk,2) ::   &
+       t3p1, t3p2  ! 3d message passing arrays north fold
+   REAL(wp), DIMENSION(jpi,jprecj,2) ::   &
+       t2ns, t2sn  ! 2d message passing arrays north-south & south-north
+   REAL(wp), DIMENSION(jpj,jpreci,2) ::   &
+       t2ew, t2we  ! 2d message passing arrays east-west & west-east
+   REAL(wp), DIMENSION(jpi,jprecj,2) ::   &
+       t2p1, t2p2  ! 2d message passing arrays north fold
+   REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,jprecj+jpr2dj,2) ::   &
+       tr2ns, tr2sn  ! 2d message passing arrays north-south & south-north including extra outer halo
+   REAL(wp), DIMENSION(1-jpr2dj:jpj+jpr2dj,jpreci+jpr2di,2) ::   &
+       tr2ew, tr2we  ! 2d message passing arrays east-west & west-east including extra outer halo
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/lib_mpp.F90,v 1.21 2007/06/05 10:28:55 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!---------------------------------------------------------------------
+
+CONTAINS
+
+   FUNCTION mynode(localComm)
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mynode  ***
+      !!                    
+      !! ** Purpose :   Find processor unit
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER ::   mynode, ierr, code
+      LOGICAL ::   mpi_was_called
+      INTEGER,OPTIONAL ::   localComm
+      NAMELIST/nam_mpp/ c_mpi_send
+      !!----------------------------------------------------------------------
+
+      WRITE(numout,*)
+      WRITE(numout,*) 'mynode : mpi initialisation'
+      WRITE(numout,*) '~~~~~~ '
+      WRITE(numout,*)
+
+      ! Namelist namrun : parameters of the run
+      REWIND( numnam )
+      READ  ( numnam, nam_mpp )
+
+      WRITE(numout,*) '        Namelist nam_mpp'
+      WRITE(numout,*) '           mpi send type            c_mpi_send = ', c_mpi_send
+
+#if defined key_agrif
+      IF( Agrif_Root() ) THEN
+#endif
+!!bug RB : should be clean to use Agrif in coupled mode
+#if ! defined key_agrif
+         CALL mpi_initialized ( mpi_was_called, code )
+         IF( code /= MPI_SUCCESS ) THEN
+            CALL ctl_stop( ' lib_mpp: Error in routine mpi_initialized' )
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+
+         IF( PRESENT(localComm) .and. mpi_was_called ) THEN
+            mpi_comm_opa = localComm
+            SELECT CASE ( c_mpi_send )
+            CASE ( 'S' )                ! Standard mpi send (blocking)
+               WRITE(numout,*) '           Standard blocking mpi send (send)'
+            CASE ( 'B' )                ! Buffer mpi send (blocking)
+               WRITE(numout,*) '           Buffer blocking mpi send (bsend)'
+               CALL mpi_init_opa( ierr )
+            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+               WRITE(numout,*) '           Immediate non-blocking send (isend)'
+               l_isend = .TRUE.
+            CASE DEFAULT
+               WRITE(numout,cform_err)
+               WRITE(numout,*) '           bad value for c_mpi_send = ', c_mpi_send
+               nstop = nstop + 1
+            END SELECT
+         ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+            WRITE(numout,*) ' lib_mpp: You cannot provide a local communicator '
+            WRITE(numout,*) '          without calling MPI_Init before ! '
+         ELSE
+#endif
+            SELECT CASE ( c_mpi_send )
+            CASE ( 'S' )                ! Standard mpi send (blocking)
+               WRITE(numout,*) '           Standard blocking mpi send (send)'
+               CALL mpi_init( ierr )
+            CASE ( 'B' )                ! Buffer mpi send (blocking)
+               WRITE(numout,*) '           Buffer blocking mpi send (bsend)'
+               CALL mpi_init_opa( ierr )
+            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+               WRITE(numout,*) '           Immediate non-blocking send (isend)'
+               l_isend = .TRUE.
+               CALL mpi_init( ierr )
+            CASE DEFAULT
+               WRITE(ctmp1,*) '           bad value for c_mpi_send = ', c_mpi_send
+               CALL ctl_stop( ctmp1 )
+            END SELECT
+
+#if ! defined key_agrif
+            CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
+            IF( code /= MPI_SUCCESS ) THEN
+               CALL ctl_stop( ' lib_mpp: Error in routine mpi_comm_dup' )
+               CALL mpi_abort( mpi_comm_world, code, ierr )
+            ENDIF
+            !
+         ENDIF
+#endif
+#if defined key_agrif
+      ELSE
+         SELECT CASE ( c_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(numout,*) '           Standard blocking mpi send (send)'
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(numout,*) '           Buffer blocking mpi send (bsend)'
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(numout,*) '           Immediate non-blocking send (isend)'
+            l_isend = .TRUE.
+         CASE DEFAULT
+            WRITE(numout,cform_err)
+            WRITE(numout,*) '           bad value for c_mpi_send = ', c_mpi_send
+            nstop = nstop + 1
+         END SELECT
+      ENDIF
+
+      mpi_comm_opa = mpi_comm_world
+#endif
+        CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
+        CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
+      mynode = mpprank
+#else
+      !! * Local variables   (SHMEM version)
+      INTEGER ::   mynode
+      INTEGER ::   &
+           imypid, imyhost, ji, info, iparent_tid
+      !!----------------------------------------------------------------------
+
+      IF( npvm_ipas /= nprocmax ) THEN
+         !         ---   first passage in mynode
+         !         -------------
+         !         enroll in pvm
+         !         -------------
+         CALL pvmfmytid( npvm_mytid )
+         IF( mynode_print /= 0 ) THEN
+            WRITE(numout,*) 'mynode, npvm_ipas =', npvm_ipas, ' nprocmax=', nprocmax
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid, ' after pvmfmytid'
+         ENDIF
+
+         !         ---------------------------------------------------------------
+         !         find out IF i am parent or child spawned processes have parents
+         !         ---------------------------------------------------------------
+         CALL mpparent( iparent_tid )
+         IF( mynode_print /= 0 ) THEN
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+               &            ' after mpparent, npvm_tids(0) = ',   &
+               &            npvm_tids(0), ' iparent_tid=', iparent_tid
+         ENDIF
+         IF( iparent_tid < 0 )  THEN
+            WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+               &            ' after mpparent, npvm_tids(0) = ',   &
+               &            npvm_tids(0), ' iparent_tid=', iparent_tid
+            npvm_tids(0) = npvm_mytid
+            npvm_me = 0
+            IF( jpnij > nprocmax ) THEN
+               WRITE(ctmp1,*) 'npvm_mytid=', npvm_mytid, ' too great'
+               CALL ctl_stop( ctmp1 )
+
+            ELSE
+               npvm_nproc = jpnij
+            ENDIF
+
+            ! -------------------------
+            ! start up copies of myself
+            ! -------------------------
+            IF( npvm_nproc > 1 ) THEN
+               DO ji = 1, npvm_nproc-1
+                  npvm_tids(ji) = nt3d_tids(ji)
+               END DO
+               info=npvm_nproc-1
+  
+               IF( mynode_print /= 0 ) THEN
+                  WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                     &            ' maitre=',executable,' info=', info   &
+                     &            ,' npvm_nproc=',npvm_nproc
+                  WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                     &            ' npvm_tids ',(npvm_tids(ji),ji=0,npvm_nproc-1)
+               ENDIF
+
+               ! ---------------------------
+               ! multicast tids array to children
+               ! ---------------------------
+               CALL pvmfinitsend( pvmdefault, info )
+               CALL pvmfpack ( jpvmint, npvm_nproc, 1         , 1, info )
+               CALL pvmfpack ( jpvmint, npvm_tids , npvm_nproc, 1, info )
+               CALL pvmfmcast( npvm_nproc-1, npvm_tids(1), 10, info )
+            ENDIF
+         ELSE
+
+            ! ---------------------------------
+            ! receive the tids array and set me
+            ! ---------------------------------
+            IF( mynode_print /= 0 )   WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid, ' pvmfrecv'
+            CALL pvmfrecv( iparent_tid, 10, info )
+            IF( mynode_print /= 0 )   WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid, " fin pvmfrecv"
+            CALL pvmfunpack( jpvmint, npvm_nproc, 1         , 1, info )
+            CALL pvmfunpack( jpvmint, npvm_tids , npvm_nproc, 1, info )
+            IF( mynode_print /= 0 ) THEN
+               WRITE(numout,*) 'mynode, npvm_mytid=',npvm_mytid,   &
+                  &            ' esclave=', executable,' info=', info,' npvm_nproc=',npvm_nproc
+               WRITE(numout,*) 'mynode, npvm_mytid=', npvm_mytid,   &
+                  &            'npvm_tids', ( npvm_tids(ji), ji = 0, npvm_nproc-1 )
+            ENDIF
+            DO ji = 0, npvm_nproc-1
+               IF( npvm_mytid == npvm_tids(ji) ) npvm_me = ji
+            END DO
+         ENDIF
+
+         ! ------------------------------------------------------------
+         ! all nproc tasks are equal now
+         ! and can address each other by tids(0) thru tids(nproc-1)
+         ! for each process me => process number [0-(nproc-1)]
+         ! ------------------------------------------------------------
+         CALL pvmfjoingroup ( "bidon", info )
+         CALL pvmfbarrier   ( "bidon", npvm_nproc, info )
+         DO ji = 0, npvm_nproc-1
+            IF( ji == npvm_me ) THEN
+               CALL pvmfjoingroup ( opaall, npvm_inum )
+               IF( npvm_inum /= npvm_me )   WRITE(numout,*) 'mynode not arrived in the good order for opaall'
+            ENDIF
+            CALL pvmfbarrier( "bidon", npvm_nproc, info )
+         END DO
+         CALL pvmfbarrier( opaall, npvm_nproc, info )
+  
+      ELSE
+         ! ---   other passage in mynode
+      ENDIF
+ 
+      npvm_ipas = nprocmax
+      mynode    = npvm_me
+      imypid    = npvm_mytid
+      imyhost   = npvm_tids(0)
+      IF( mynode_print /= 0 ) THEN
+         WRITE(numout,*)'mynode: npvm_mytid=', npvm_mytid, ' npvm_me=', npvm_me,   &
+            &           ' npvm_nproc=', npvm_nproc , ' npvm_ipas=', npvm_ipas
+      ENDIF
+#endif
+   END FUNCTION mynode
+
+
+   SUBROUTINE mpparent( kparent_tid )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpparent  ***
+      !!
+      !! ** Purpose :   use an pvmfparent routine for T3E (key_mpp_shmem)
+      !!              or  only return -1 (key_mpp_mpi)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(inout) ::   kparent_tid      ! ???
+  
+#if defined key_mpp_mpi
+      ! MPI version : retour -1
+
+      kparent_tid = -1
+
+#else
+      !! * Local variables   (SHMEN onto T3E version)
+      INTEGER ::   &
+           it3d_my_pe, LEADZ, ji, info
+  
+      CALL pvmfmytid( nt3d_mytid )
+      CALL pvmfgetpe( nt3d_mytid, it3d_my_pe )
+      IF( mpparent_print /= 0 ) THEN
+         WRITE(numout,*) 'mpparent: nt3d_mytid= ', nt3d_mytid ,' it3d_my_pe=',it3d_my_pe
+      ENDIF
+      IF( it3d_my_pe == 0 ) THEN
+         !-----------------------------------------------------------------!
+         !     process = 0 => receive other tids                           !
+         !-----------------------------------------------------------------!
+         kparent_tid = -1
+         IF(mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=',nt3d_mytid ,' kparent_tid=',kparent_tid
+         ENDIF
+         !          --- END receive dimension ---
+         IF( jpnij > nprocmax ) THEN
+            WRITE(ctmp1,*) 'mytid=',nt3d_mytid,' too great'
+            CALL ctl_stop( ctmp1 )
+         ELSE
+            nt3d_nproc =  jpnij
+         ENDIF
+         IF( mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' nt3d_nproc=', nt3d_nproc
+         ENDIF
+         !-------- receive tids from others process --------
+         DO ji = 1, nt3d_nproc-1
+            CALL pvmfrecv( ji , 100, info )
+            CALL pvmfunpack( jpvmint, nt3d_tids(ji), 1, 1, info )
+            IF( mpparent_print /= 0 ) THEN
+               WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' receive=', nt3d_tids(ji), ' from = ', ji
+            ENDIF
+         END DO
+         nt3d_tids(0) = nt3d_mytid
+         IF( mpparent_print /= 0 ) THEN
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' nt3d_tids(ji) =', (nt3d_tids(ji),   &
+                 ji = 0, nt3d_nproc-1 )
+            WRITE(numout,*) 'mpparent, nt3d_mytid=', nt3d_mytid , ' kparent_tid=', kparent_tid
+         ENDIF
+
+      ELSE
+         !!----------------------------------------------------------------!
+         !     process <> 0 => send  other tids                            !
+         !!----------------------------------------------------------------!
+         kparent_tid = 0
+         CALL pvmfinitsend( pvmdataraw, info )
+         CALL pvmfpack( jpvmint, nt3d_mytid, 1, 1, info )
+         CALL pvmfsend( kparent_tid, 100, info )
+      ENDIF
+#endif
+
+   END SUBROUTINE mpparent
+
+#if defined key_mpp_shmem
+
+   SUBROUTINE mppshmem
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppshmem  ***
+      !!
+      !! ** Purpose :   SHMEM ROUTINE
+      !!
+      !!----------------------------------------------------------------------
+      nrs1sync_shmem = SHMEM_SYNC_VALUE
+      nrs2sync_shmem = SHMEM_SYNC_VALUE
+      nis1sync_shmem = SHMEM_SYNC_VALUE
+      nis2sync_shmem = SHMEM_SYNC_VALUE
+      nil1sync_shmem = SHMEM_SYNC_VALUE
+      nil2sync_shmem = SHMEM_SYNC_VALUE
+      ni11sync_shmem = SHMEM_SYNC_VALUE
+      ni12sync_shmem = SHMEM_SYNC_VALUE
+      ni21sync_shmem = SHMEM_SYNC_VALUE
+      ni22sync_shmem = SHMEM_SYNC_VALUE
+      CALL barrier()
+  
+   END SUBROUTINE mppshmem
+
+#endif
+
+   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of ptab array grid-points
+         !             ! = T , U , V , F , W points
+         !             ! = S : T-point, north fold treatment ???
+         !             ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptab          ! 3D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only 
+
+      !! * Local variables
+      INTEGER ::   ji, jj, jk, jl                        ! dummy loop indices
+      INTEGER ::   imigr, iihom, ijhom, iloc, ijt, iju   ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+
+      IF( PRESENT( cd_mpp ) ) THEN
+         DO jj = nlcj+1, jpj   ! only fill extra allows last line
+            ptab(1:nlci, jj, :) = ptab(1:nlci, nlej, :)
+         END DO
+         DO ji = nlci+1, jpi   ! only fill extra allows last column
+            ptab(ji    , : , :) = ptab(nlei  , :   , :)
+         END DO
+      ELSE      
+
+         !                                        ! East-West boundaries
+         !                                        ! ====================
+         IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+            &   (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            ptab( 1 ,:,:) = ptab(jpim1,:,:)
+            ptab(jpi,:,:) = ptab(  2  ,:,:)
+
+         ELSE                           ! closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T', 'U', 'V', 'W' )
+               ptab(     1       :jpreci,:,:) = 0.e0
+               ptab(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+            CASE ( 'F' )
+               ptab(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+            END SELECT 
+         ENDIF
+
+         !                                        ! North-South boundaries
+         !                                        ! ======================
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab(:,     1       :jprecj,:) = 0.e0
+            ptab(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+         CASE ( 'F' )
+            ptab(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+         END SELECT
+     
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all exept 2 
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            t3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj * jpk
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+         CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+
+      imigr = jpreci * jpj * jpk
+
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+         CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+         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, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci-jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = t3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = t3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            t3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi * jpk
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t3sn(1,1,1,2), t3sn(1,1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t3ns(1,1,1,2), t3ns(1,1,1,1), imigr, noso )
+         CALL shmem_put( t3sn(1,1,1,2), t3sn(1,1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t3ns(1,1,1,2), t3ns(1,1,1,1), imigr, noso )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+  
+      imigr=jprecj*jpi*jpk
+
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t3ns(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t3sn(1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t3ns(1,1,1,2), imigr )
+         CALL mpprecv( 4, t3sn(1,1,1,2), imigr )
+         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, t3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t3sn(1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj-jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = t3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = t3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = t3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+
+      IF (PRESENT(cd_mpp)) THEN
+         ! No north fold treatment (it is assumed to be already OK)
+     
+      ELSE      
+
+      ! 4.1 treatment without exchange (jpni odd)
+      !     T-point pivot  
+
+      SELECT CASE ( jpni )
+
+      CASE ( 1 )  ! only one proc along I, no mpp exchange
+
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )    ! T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+
+            SELECT CASE ( cd_type )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-2,jk)
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+          END SELECT
+       
+         CASE ( 5 , 6 ) ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE ( cd_type )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj  ,jk) = psgn * ptab(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj,jk) = psgn * ptab(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab(ji,nlcj-1,jk) = psgn * ptab(iju,nlcj-1,jk)
+                  END DO
+               END DO
+            END SELECT  ! cd_type
+
+         END SELECT     !  npolj
+  
+      CASE DEFAULT ! more than 1 proc along I
+         IF ( npolj /= 0 ) CALL mpp_lbc_north (ptab, cd_type, psgn)  ! only for northern procs.
+
+      END SELECT ! jpni 
+
+      ENDIF
+      
+
+      ! 5. East and west directions exchange
+      ! ------------------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               t3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+               t3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+            END DO
+
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! SHMEM version
+
+         imigr = jpreci * jpj * jpk
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+            CALL shmem_put( t3we(1,1,1,2), t3we(1,1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t3ew(1,1,1,2), t3ew(1,1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+         !! MPI version
+
+         imigr=jpreci*jpj*jpk
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t3we(1,1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t3ew(1,1,1,2), imigr )
+            CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+            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, t3ew(1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t3we(1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+
+         iihom = nlci-jpreci
+
+         SELECT CASE ( nbondi)
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+            END DO
+         CASE ( 0 ) 
+            DO jl = 1, jpreci
+               ptab(jl      ,:,:) = t3we(:,jl,:,2)
+               ptab(iihom+jl,:,:) = t3ew(:,jl,:,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               ptab(jl      ,:,:) = t3we(:,jl,:,2)
+            END DO
+         END SELECT
+
+      END SELECT    ! npolj 
+
+   END SUBROUTINE mpp_lnk_3d
+
+
+   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of pt2d array grid-points
+         !             !  = T , U , V , F , W 
+         !             !  = S : T-point, north fold treatment
+         !             !  = G : F-point, north fold treatment
+         !             !  = I : sea-ice velocity at F-point with index shift
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::    &
+         cd_mpp        ! fill the overlap area only 
+
+      !! * Local variables
+      INTEGER  ::   ji, jj, jl      ! dummy loop indices
+      INTEGER  ::   &
+         imigr, iihom, ijhom,    &  ! temporary integers
+         iloc, ijt, iju             !    "          "
+      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER  ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      IF (PRESENT(cd_mpp)) THEN
+         DO jj = nlcj+1, jpj   ! only fill extra allows last line
+            pt2d(1:nlci, jj) = pt2d(1:nlci, nlej)
+         END DO
+         DO ji = nlci+1, jpi   ! only fill extra allows last column
+            pt2d(ji    , : ) = pt2d(nlei  , :   )
+         END DO     
+      ELSE      
+
+         !                                        ! East-West boundaries
+         !                                        ! ====================
+         IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            pt2d( 1 ,:) = pt2d(jpim1,:)
+            pt2d(jpi,:) = pt2d(  2  ,:)
+
+         ELSE                           ! ... closed
+            SELECT CASE ( cd_type )
+            CASE ( 'T', 'U', 'V', 'W' , 'I' )
+               pt2d(     1       :jpreci,:) = 0.e0
+               pt2d(nlci-jpreci+1:jpi   ,:) = 0.e0
+            CASE ( 'F' )
+               pt2d(nlci-jpreci+1:jpi   ,:) = 0.e0
+            END SELECT
+         ENDIF
+
+         !                                        ! North-South boundaries
+         !                                        ! ======================
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' , 'I' )
+            pt2d(:,     1       :jprecj) = 0.e0
+            pt2d(:,nlcj-jprecj+1:jpj   ) = 0.e0
+         CASE ( 'F' )
+            pt2d(:,nlcj-jprecj+1:jpj   ) = 0.e0
+         END SELECT
+
+      ENDIF
+
+
+      ! 2. East and west directions
+      ! ---------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all except 2
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            t2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+         CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = jpreci * jpj
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t2ew(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t2ew(1,1,2), imigr )
+         CALL mpprecv( 2, t2we(1,1,2), imigr )
+         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, t2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t2we(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci - jpreci
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            pt2d(iihom+jl,:) = t2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = t2we(:,jl,2)
+            pt2d(iihom+jl,:) = t2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = t2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            t2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr, noso )
+         CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr, noso )
+      END SELECT 
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = jprecj * jpi
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t2ns(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t2sn(1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t2ns(1,1,2), imigr )
+         CALL mpprecv( 4, t2sn(1,1,2), imigr )
+         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, t2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t2sn(1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+  
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj - jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = t2sn(:,jl,2)
+            pt2d(:,ijhom+jl) = t2ns(:,jl,2)
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = t2sn(:,jl,2)
+         END DO
+      END SELECT 
+  
+
+      ! 4. north fold treatment
+      ! -----------------------
+  
+      IF (PRESENT(cd_mpp)) THEN
+         ! No north fold treatment (it is assumed to be already OK)
+     
+      ELSE      
+
+      ! 4.1 treatment without exchange (jpni odd)
+      
+      SELECT CASE ( jpni )
+  
+      CASE ( 1 ) ! only one proc along I, no mpp exchange
+  
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )   !  T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+  
+            SELECT CASE ( cd_type )
+  
+            CASE ( 'T' , 'S', 'W' )
+               DO ji = 2, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj) = psgn * pt2d(ijt,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'U' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-2)
+               END DO
+               DO ji = nlci/2, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'V' )
+               DO ji = 2, nlci
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-2)
+                  pt2d(ji,nlcj  ) = psgn * pt2d(ijt,nlcj-3)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-2)
+                  pt2d(ji,nlcj  ) = psgn * pt2d(iju,nlcj-3)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d(2,nlcj) = psgn * pt2d(3,nlcj-1)
+               DO ji = 3, nlci
+                  iju = iloc - ji + 3
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            END SELECT
+  
+         CASE ( 5 , 6 )                 ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE (cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO ji = 1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'U' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-1)
+               END DO
+
+            CASE ( 'V' )
+               DO ji = 1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj  ) = psgn * pt2d(ijt,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO ji = 1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj) = psgn * pt2d(iju,nlcj-2)
+               END DO
+               DO ji = nlci/2+1, nlci-1
+                  iju=iloc-ji
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d( 2 ,nlcj) = 0.e0
+               DO ji = 2 , nlci-1
+                  ijt = iloc - ji + 2
+                  pt2d(ji,nlcj)= 0.5 * ( pt2d(ji,nlcj-1) + psgn * pt2d(ijt,nlcj-1) )
+               END DO
+  
+            END SELECT   ! cd_type
+  
+         END SELECT   ! npolj
+
+      CASE DEFAULT   ! more than 1 proc along I
+         IF( npolj /= 0 )   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! only for northern procs.
+
+      END SELECT   ! jpni
+
+      ENDIF
+
+      ! 5. East and west directions
+      ! ---------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               DO jj = 1, jpj
+                  t2ew(jj,jl,1) = pt2d(jpreci+jl,jj)
+                  t2we(jj,jl,1) = pt2d(iihom +jl,jj)
+               END DO
+            END DO
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! * SHMEM version
+
+         imigr=jpreci*jpj
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+            CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+  
+#elif defined key_mpp_mpi
+         !! * MPI version
+  
+         imigr=jpreci*jpj
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t2ew(1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t2ew(1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t2we(1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t2ew(1,1,2), imigr )
+            CALL mpprecv( 2, t2we(1,1,2), imigr )
+            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, t2ew(1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t2we(1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT 
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+  
+         iihom = nlci - jpreci
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               pt2d(iihom+jl,:) = t2ew(:,jl,2)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jpreci
+               pt2d(jl      ,:) = t2we(:,jl,2)
+               pt2d(iihom+jl,:) = t2ew(:,jl,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               pt2d(jl,:) = t2we(:,jl,2)
+            END DO
+         END SELECT 
+  
+      END SELECT   ! npolj
+  
+   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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type1, cd_type2       ! define the nature of ptab array grid-points
+         !                        ! = T , U , V , F , W points
+         !                        ! = S : T-point, north fold treatment ???
+         !                        ! = G : F-point, north fold treatment ???
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         ptab1, ptab2             ! 3D array on which the boundary condition is applied
+
+      !! * Local variables
+      INTEGER ::   ji, jk, jl   ! dummy loop indices
+      INTEGER ::   imigr, iihom, ijhom, iloc, ijt, iju   ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+         &   (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
+         SELECT CASE ( cd_type1 )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab1(     1       :jpreci,:,:) = 0.e0
+            ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         CASE ( 'F' )
+            ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         END SELECT 
+         SELECT CASE ( cd_type2 )
+         CASE ( 'T', 'U', 'V', 'W' )
+            ptab2(     1       :jpreci,:,:) = 0.e0
+            ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         CASE ( 'F' )
+            ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+         END SELECT 
+      ENDIF
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( cd_type1 )
+      CASE ( 'T', 'U', 'V', 'W' )
+         ptab1(:,     1       :jprecj,:) = 0.e0
+         ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      CASE ( 'F' )
+         ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      END SELECT
+
+      SELECT CASE ( cd_type2 )
+      CASE ( 'T', 'U', 'V', 'W' )
+         ptab2(:,     1       :jprecj,:) = 0.e0
+         ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      CASE ( 'F' )
+         ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+      END SELECT
+
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all exept 2 
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            t4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+            t4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+            t4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+            t4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jpreci * jpj * jpk *2
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+         CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+
+      imigr = jpreci * jpj * jpk *2
+
+      SELECT CASE ( nbondi ) 
+      CASE ( -1 )
+         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+         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, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci-jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+            ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+            ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            t4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
+            t4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
+            t4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
+            t4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = jprecj * jpi * jpk * 2
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( t4sn(1,1,1,1,2), t4sn(1,1,1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( t4ns(1,1,1,1,2), t4ns(1,1,1,1,1), imigr, noso )
+         CALL shmem_put( t4sn(1,1,1,1,2), t4sn(1,1,1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( t4ns(1,1,1,1,2), t4ns(1,1,1,1;,1), imigr, noso )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+  
+      imigr=jprecj * jpi * jpk * 2
+
+      SELECT CASE ( nbondj )     
+      CASE ( -1 )
+         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, t4sn(1,1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, t4ns(1,1,1,1,2), imigr )
+         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr )
+         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, t4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, t4sn(1,1,1,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj-jprecj
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
+            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 0 ) 
+         DO jl = 1, jprecj
+            ptab1(:,jl      ,:) = t4sn(:,jl,:,1,2)
+            ptab1(:,ijhom+jl,:) = t4ns(:,jl,:,1,2)
+            ptab2(:,jl      ,:) = t4sn(:,jl,:,2,2)
+            ptab2(:,ijhom+jl,:) = t4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab1(:,jl,:) = t4sn(:,jl,:,1,2)
+            ptab2(:,jl,:) = t4sn(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+
+      ! 4.1 treatment without exchange (jpni odd)
+      !     T-point pivot  
+
+      SELECT CASE ( jpni )
+
+      CASE ( 1 )  ! only one proc along I, no mpp exchange
+
+      SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )    ! T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+
+            SELECT CASE ( cd_type1 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+            END SELECT
+            
+            SELECT CASE ( cd_type2 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+          
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 2, nlci
+                     ijt=iloc-ji+2
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(ijt,nlcj-3,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(iju,nlcj-3,jk)
+                  END DO
+               END DO
+  
+          END SELECT
+       
+         CASE ( 5 , 6 ) ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE ( cd_type1 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj  ,jk) = psgn * ptab1(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj,jk) = psgn * ptab1(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab1(ji,nlcj-1,jk) = psgn * ptab1(iju,nlcj-1,jk)
+                  END DO
+               END DO
+            END SELECT  ! cd_type1
+
+            SELECT CASE ( cd_type2 )
+
+            CASE ( 'T' , 'S', 'W' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'U' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'V' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj  ,jk) = psgn * ptab2(ijt,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci
+                     ijt=iloc-ji+1
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(ijt,nlcj-1,jk)
+                  END DO
+               END DO
+
+            CASE ( 'F', 'G' )
+               DO jk = 1, jpk
+                  DO ji = 1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj,jk) = psgn * ptab2(iju,nlcj-2,jk)
+                  END DO
+                  DO ji = nlci/2+1, nlci-1
+                     iju=iloc-ji
+                     ptab2(ji,nlcj-1,jk) = psgn * ptab2(iju,nlcj-1,jk)
+                  END DO
+               END DO
+
+            END SELECT  ! cd_type2
+
+         END SELECT     !  npolj
+  
+      CASE DEFAULT ! more than 1 proc along I
+         IF ( npolj /= 0 ) THEN
+            CALL mpp_lbc_north (ptab1, cd_type1, psgn)  ! only for northern procs.
+            CALL mpp_lbc_north (ptab2, cd_type2, psgn)  ! only for northern procs.
+         ENDIF
+
+      END SELECT ! jpni 
+
+
+      ! 5. East and west directions exchange
+      ! ------------------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               t4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+               t4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+               t4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+               t4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+            END DO
+
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! SHMEM version
+
+         imigr = jpreci * jpj * jpk * 2
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+            CALL shmem_put( t4we(1,1,1,1,2), t4we(1,1,1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( t4ew(1,1,1,1,2), t4ew(1,1,1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+         !! MPI version
+
+         imigr = jpreci * jpj * jpk * 2
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, t4we(1,1,1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, t4ew(1,1,1,1,2), imigr )
+            CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+            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, t4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, t4we(1,1,1,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+
+         iihom = nlci-jpreci
+
+         SELECT CASE ( nbondi)
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+               ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+            END DO
+         CASE ( 0 ) 
+            DO jl = 1, jpreci
+               ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+               ptab1(iihom+jl,:,:) = t4ew(:,jl,:,1,2)
+               ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+               ptab2(iihom+jl,:,:) = t4ew(:,jl,:,2,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               ptab1(jl      ,:,:) = t4we(:,jl,:,1,2)
+               ptab2(jl      ,:,:) = t4we(:,jl,:,2,2)
+            END DO
+         END SELECT
+
+      END SELECT    ! npolj 
+
+   END SUBROUTINE mpp_lnk_3d_gather
+
+
+   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  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
+      !!                    jpr2di : number of rows for extra outer halo
+      !!                    jpr2dj : 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
+      !!   
+      !! History :
+      !!       
+      !!   9.0  !  05-09  (R. Benshila, G. Madec)  original code
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1) , INTENT( in ) ::   &
+         cd_type       ! define the nature of pt2d array grid-points
+         !             !  = T , U , V , F , W 
+         !             !  = S : T-point, north fold treatment
+         !             !  = G : F-point, north fold treatment
+         !             !  = I : sea-ice velocity at F-point with index shift
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+
+      !! * Local variables
+      INTEGER  ::   ji, jl      ! dummy loop indices
+      INTEGER  ::   &
+         imigr, iihom, ijhom,    &  ! temporary integers
+         iloc, ijt, iju             !    "          "
+      INTEGER  ::   &
+         ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for isend
+      INTEGER  ::   ml_stat(MPI_STATUS_SIZE)     ! for isend
+     !!---------------------------------------------------------------------
+
+      ! take into account outer extra 2D overlap area
+      ipreci = jpreci + jpr2di
+      iprecj = jprecj + jpr2dj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+
+      !                                        ! East-West boundaries
+      !                                        ! ====================
+      IF( nbondi == 2 .AND.   &      ! Cyclic east-west
+         &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpr2di:     1    ,:) = pt2d(jpim1-jpr2di:  jpim1 ,:)
+         pt2d(   jpi  :jpi+jpr2di,:) = pt2d(     2      :2+jpr2di,:)
+
+      ELSE                           ! ... closed
+         SELECT CASE ( cd_type )
+         CASE ( 'T', 'U', 'V', 'W' , 'I' )
+            pt2d(  1-jpr2di   :jpreci    ,:) = 0.e0
+            pt2d(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0
+         CASE ( 'F' )
+            pt2d(nlci-jpreci+1:jpi+jpr2di,:) = 0.e0
+         END SELECT
+      ENDIF
+
+      !                                        ! North-South boundaries
+      !                                        ! ======================
+      SELECT CASE ( cd_type )
+      CASE ( 'T', 'U', 'V', 'W' , 'I' )
+         pt2d(:,  1-jpr2dj   :  jprecj  ) = 0.e0
+         pt2d(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0
+      CASE ( 'F' )
+         pt2d(:,nlcj-jprecj+1:jpj+jpr2dj) = 0.e0
+      END SELECT
+
+
+      ! 2. East and west directions
+      ! ---------------------------
+
+      ! 2.1 Read Dirichlet lateral conditions
+
+      SELECT CASE ( nbondi )
+      CASE ( -1, 0, 1 )    ! all except 2
+         iihom = nlci-nreci-jpr2di
+         DO jl = 1, ipreci
+            tr2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            tr2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+
+      ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = ipreci * ( jpj + 2*jpr2dj)
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+      CASE ( 0 )
+         CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+         CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+      CASE ( 1 )
+         CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+      END SELECT
+
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = ipreci * ( jpj + 2*jpr2dj)
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+         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, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+
+#endif
+
+      ! 2.3 Write Dirichlet lateral conditions
+
+      iihom = nlci - jpreci
+
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+            pt2d( iihom+jl,:) = tr2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+
+      ! 3.1 Read Dirichlet lateral conditions
+
+      IF( nbondj /= 2 ) THEN
+         ijhom = nlcj-nrecj-jpr2dj
+         DO jl = 1, iprecj
+            tr2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            tr2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+
+      ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      imigr = iprecj * ( jpi + 2*jpr2di )
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL shmem_put( tr2sn(1-jpr2di,1,2), tr2sn(1,1,1), imigr, nono )
+      CASE ( 0 )
+         CALL shmem_put( tr2ns(1-jpr2di,1,2), tr2ns(1,1,1), imigr, noso )
+         CALL shmem_put( tr2sn(1-jpr2di,1,2), tr2sn(1,1,1), imigr, nono )
+      CASE ( 1 )
+         CALL shmem_put( tr2ns(1-jpr2di,1,2), tr2ns(1,1,1), imigr, noso )
+      END SELECT 
+      CALL barrier()
+      CALL shmem_udcflush()
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+
+      imigr = iprecj * ( jpi + 2*jpr2di )
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, tr2sn(1-jpr2di,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, tr2ns(1-jpr2di,1,2), imigr )
+         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr )
+         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, tr2ns(1-jpr2di,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, tr2sn(1-jpr2di,1,2), imigr )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+  
+#endif
+
+      ! 3.3 Write Dirichlet lateral conditions
+
+      ijhom = nlcj - jprecj  
+
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = tr2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
+            pt2d(:,ijhom+jl ) = tr2ns(:,jl,2)
+         END DO
+      CASE ( 1 ) 
+         DO jl = 1, iprecj
+            pt2d(:,jl-jpr2dj) = tr2sn(:,jl,2)
+         END DO
+      END SELECT 
+  
+
+      ! 4. north fold treatment
+      ! -----------------------
+  
+      ! 4.1 treatment without exchange (jpni odd)
+      
+      SELECT CASE ( jpni )
+  
+      CASE ( 1 ) ! only one proc along I, no mpp exchange
+  
+         SELECT CASE ( npolj )
+  
+         CASE ( 3 , 4 )   !  T pivot
+            iloc = jpiglo - 2 * ( nimpp - 1 )
+  
+            SELECT CASE ( cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO jl = 0, iprecj-1
+                  DO ji = 2-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+2
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2+1, nlci+jpr2di
+                  ijt=iloc-ji+2
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+ 
+            CASE ( 'U' )
+               DO jl =0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1-jpr2di
+                     iju=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2, nlci-1+jpr2di
+                  iju=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'V' )
+               DO jl = -1, iprecj-1
+                  DO ji = 2-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+2
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-3-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO jl = -1, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-3-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               DO jl = 0, iprecj-1
+                  pt2d(2,nlcj+jl) = psgn * pt2d(3,nlcj-1-jl)
+                  DO ji = 3, nlci+jpr2di
+                     iju = iloc - ji + 3
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-1-jl)
+                  END DO
+               END DO
+  
+            END SELECT
+  
+         CASE ( 5 , 6 )                 ! F pivot
+            iloc=jpiglo-2*(nimpp-1)
+  
+            SELECT CASE (cd_type )
+  
+            CASE ( 'T', 'S', 'W' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-1-jl)
+                  END DO
+               END DO
+  
+            CASE ( 'U' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-1-jl)
+                  END DO
+               END DO
+ 
+            CASE ( 'V' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci+jpr2di
+                     ijt=iloc-ji+1
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(ijt,nlcj-2-jl)
+                  END DO
+               END DO 
+               DO ji = nlci/2+1, nlci+jpr2di
+                  ijt=iloc-ji+1
+                  pt2d(ji,nlcj-1) = psgn * pt2d(ijt,nlcj-1)
+               END DO
+  
+            CASE ( 'F', 'G' )
+               DO jl = 0, iprecj-1
+                  DO ji = 1-jpr2di, nlci-1+jpr2di
+                     iju=iloc-ji
+                     pt2d(ji,nlcj+jl) = psgn * pt2d(iju,nlcj-2-jl)
+                  END DO
+               END DO
+               DO ji = nlci/2+1, nlci-1+jpr2di
+                  iju=iloc-ji
+                  pt2d(ji,nlcj-1) = psgn * pt2d(iju,nlcj-1)
+               END DO
+  
+            CASE ( 'I' )                                  ! ice U-V point
+               pt2d( 2 ,nlcj) = 0.e0
+               DO jl = 0, iprecj-1
+                  DO ji = 2 , nlci-1+jpr2di
+                     ijt = iloc - ji + 2
+                     pt2d(ji,nlcj+jl)= 0.5 * ( pt2d(ji,nlcj-1-jl) + psgn * pt2d(ijt,nlcj-1-jl) )
+                  END DO
+               END DO
+  
+            END SELECT   ! cd_type
+  
+         END SELECT   ! npolj
+
+      CASE DEFAULT   ! more than 1 proc along I
+         IF( npolj /= 0 )   CALL mpp_lbc_north_e( pt2d, cd_type, psgn )   ! only for northern procs
+         
+      END SELECT   ! jpni
+
+
+      ! 5. East and west directions
+      ! ---------------------------
+
+      SELECT CASE ( npolj )
+
+      CASE ( 3, 4, 5, 6 )
+
+         ! 5.1 Read Dirichlet lateral conditions
+
+         SELECT CASE ( nbondi )
+         CASE ( -1, 0, 1 )
+            iihom = nlci-nreci-jpr2di
+            DO jl = 1, ipreci
+               tr2ew(:,jl,1) = pt2d(jpreci+jl,:)
+               tr2we(:,jl,1) = pt2d(iihom +jl,:)
+            END DO
+         END SELECT
+
+         ! 5.2 Migrations
+
+#if defined key_mpp_shmem
+         !! * SHMEM version
+
+         imigr = ipreci * ( jpj + 2*jpr2dj )
+
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+         CASE ( 0 )
+            CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+            CALL shmem_put( tr2we(1-jpr2dj,1,2), tr2we(1,1,1), imigr, noea )
+         CASE ( 1 )
+            CALL shmem_put( tr2ew(1-jpr2dj,1,2), tr2ew(1,1,1), imigr, nowe )
+         END SELECT
+
+         CALL barrier()
+         CALL shmem_udcflush()
+  
+#elif defined key_mpp_mpi
+         !! * MPI version
+  
+         imigr=ipreci* ( jpj + 2*jpr2dj )
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, tr2we(1-jpr2dj,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, tr2ew(1-jpr2dj,1,2), imigr )
+            CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+            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, tr2ew(1-jpr2dj,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, tr2we(1-jpr2dj,1,2), imigr )
+            IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         END SELECT 
+#endif
+
+         ! 5.3 Write Dirichlet lateral conditions
+  
+         iihom = nlci - jpreci
+  
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, ipreci
+               pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, ipreci
+               pt2d(jl- jpr2di,:) = tr2we(:,jl,2)
+               pt2d(iihom+jl,:) = tr2ew(:,jl,2)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, ipreci
+               pt2d(jl-jpr2di,:) = tr2we(:,jl,2)
+            END DO
+         END SELECT 
+  
+      END SELECT   ! npolj
+  
+   END SUBROUTINE mpp_lnk_2d_e
+
+
+   SUBROUTINE mpplnks( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpplnks  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for add 2d array local boundary
+      !!
+      !! ** 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
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   &
+         ptab                     ! 2D array
+  
+      !! * Local variables
+      INTEGER ::   ji, jl         ! dummy loop indices
+      INTEGER ::   &
+         imigr, iihom, ijhom      ! temporary integers
+      INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+      !!----------------------------------------------------------------------
+
+
+      ! 1. north fold treatment
+      ! -----------------------
+
+      ! 1.1 treatment without exchange (jpni odd)
+  
+      SELECT CASE ( npolj )
+      CASE ( 4 )
+         DO ji = 1, nlci
+            ptab(ji,nlcj-2) = ptab(ji,nlcj-2) + t2p1(ji,1,1)
+         END DO
+      CASE ( 6 )
+         DO ji = 1, nlci
+            ptab(ji,nlcj-1) = ptab(ji,nlcj-1) + t2p1(ji,1,1)
+         END DO
+
+      ! 1.2 treatment with exchange (jpni greater than 1)
+      ! 
+      CASE ( 3 )
+#if defined key_mpp_shmem
+  
+         !! * SHMEN version
+  
+         imigr=jprecj*jpi
+  
+         CALL shmem_put(t2p1(1,1,2),t2p1(1,1,1),imigr,nono)
+         CALL barrier()
+         CALL shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+       !! * MPI version
+
+       imigr=jprecj*jpi
+
+       CALL mppsend(3,t2p1(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2p1(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+#endif      
+
+       ! Write north fold conditions
+
+       DO ji = 1, nlci
+          ptab(ji,nlcj-2) = ptab(ji,nlcj-2)+t2p1(ji,1,2)
+       END DO
+
+    CASE ( 5 )
+
+#if defined key_mpp_shmem
+
+       !! * SHMEN version
+
+       imigr=jprecj*jpi
+
+       CALL shmem_put(t2p1(1,1,2),t2p1(1,1,1),imigr,nono)
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+       !! * Local variables   (MPI version)
+
+       imigr=jprecj*jpi
+
+       CALL mppsend(3,t2p1(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2p1(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+#endif      
+
+       ! Write north fold conditions
+
+       DO ji = 1, nlci
+          ptab(ji,nlcj-1) = ptab(ji,nlcj-1)+t2p1(ji,1,2)
+       END DO
+
+    END SELECT
+
+
+    ! 2. East and west directions
+    ! ---------------------------
+
+    ! 2.1 Read Dirichlet lateral conditions
+
+    iihom = nlci-jpreci
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1, 0, 1 )  ! all except 2
+       DO jl = 1, jpreci
+             t2ew(:,jl,1) = ptab(  jl    ,:)
+             t2we(:,jl,1) = ptab(iihom+jl,:)
+       END DO
+    END SELECT
+
+    ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+
+    !! * SHMEN version
+
+    imigr=jpreci*jpj
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       CALL shmem_put(t2we(1,1,2),t2we(1,1,1),imigr,noea)
+
+    CASE ( 0 )
+       CALL shmem_put(t2ew(1,1,2),t2ew(1,1,1),imigr,nowe)
+       CALL shmem_put(t2we(1,1,2),t2we(1,1,1),imigr,noea)
+
+    CASE ( 1 )
+       CALL shmem_put(t2ew(1,1,2),t2ew(1,1,1),imigr,nowe)
+
+    END SELECT
+    CALL  barrier()
+    CALL  shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+    !! * Local variables   (MPI version)
+
+    imigr=jpreci*jpj
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req1)
+       CALL mpprecv(1,t2ew(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+    CASE ( 0 )
+       CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+       CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req2)
+       CALL mpprecv(1,t2ew(1,1,2),imigr)
+       CALL mpprecv(2,t2we(1,1,2),imigr)
+       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,t2ew(1,1,1),imigr,nowe, ml_req1)
+       CALL mpprecv(2,t2we(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+    END SELECT
+
+#endif
+
+    ! 2.3 Write Dirichlet lateral conditions
+
+       iihom = nlci-nreci
+
+    SELECT CASE ( nbondi )
+
+    CASE ( -1 )
+       DO jl = 1, jpreci
+             ptab(iihom +jl,:) = ptab(iihom +jl,:)+t2ew(:,jl,2)
+       END DO
+
+    CASE ( 0 )
+       DO jl = 1, jpreci
+             ptab(jpreci+jl,:) = ptab(jpreci+jl,:)+t2we(:,jl,2)
+             ptab(iihom +jl,:) = ptab(iihom +jl,:)+t2ew(:,jl,2)
+       END DO
+
+    CASE ( 1 )
+       DO jl = 1, jpreci
+             ptab(jpreci+jl,:) = ptab(jpreci+jl,:)+t2we(:,jl,2)
+       END DO
+    END SELECT
+
+
+    ! 3. North and south directions
+    ! -----------------------------
+
+    ! 3.1 Read Dirichlet lateral conditions
+
+    ijhom = nlcj-jprecj
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1, 0, 1 )
+       DO jl = 1, jprecj
+             t2sn(:,jl,1) = ptab(:,ijhom+jl)
+             t2ns(:,jl,1) = ptab(:,   jl   )
+       END DO
+
+    END SELECT 
+
+    ! 3.2 Migrations
+
+#if defined key_mpp_shmem
+
+    !! * SHMEN version
+
+    imigr=jprecj*jpi
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       CALL shmem_put(t2sn(1,1,2),t2sn(1,1,1),imigr,nono)
+
+    CASE ( 0 )
+       CALL shmem_put(t2ns(1,1,2),t2ns(1,1,1),imigr,noso)
+       CALL shmem_put(t2sn(1,1,2),t2sn(1,1,1),imigr,nono)
+
+    CASE ( 1 )
+       CALL shmem_put(t2ns(1,1,2),t2ns(1,1,1),imigr,noso)
+
+    END SELECT
+    CALL  barrier()
+    CALL  shmem_udcflush()
+
+#  elif defined key_mpp_mpi
+    !! * Local variables   (MPI version)
+
+    imigr=jprecj*jpi
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req1)
+       CALL mpprecv(3,t2ns(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+
+    CASE ( 0 )
+       CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+       CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req2)
+       CALL mpprecv(3,t2ns(1,1,2),imigr)
+       CALL mpprecv(4,t2sn(1,1,2),imigr)
+       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,t2ns(1,1,1),imigr,noso, ml_req1)
+       CALL mpprecv(4,t2sn(1,1,2),imigr)
+       IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+    END SELECT
+
+#endif
+
+    ! 3.3 Write Dirichlet lateral conditions
+
+       ijhom = nlcj-nrecj
+
+    SELECT CASE ( nbondj )
+
+    CASE ( -1 )
+       DO jl = 1, jprecj
+             ptab(:,ijhom +jl) = ptab(:,ijhom +jl)+t2ns(:,jl,2)
+       END DO
+
+    CASE ( 0 )
+       DO jl = 1, jprecj
+             ptab(:,jprecj+jl) = ptab(:,jprecj+jl)+t2sn(:,jl,2)
+             ptab(:,ijhom +jl) = ptab(:,ijhom +jl)+t2ns(:,jl,2)
+       END DO
+
+    CASE ( 1 ) 
+       DO jl = 1, jprecj
+             ptab(:,jprecj+jl) = ptab(:,jprecj+jl)+t2sn(:,jl,2)
+       END DO
+
+    END SELECT
+
+  END SUBROUTINE mpplnks
+
+
+   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req)
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsend  ***
+      !!                   
+      !! ** Purpose :   Send messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(inout) ::   pmess(*)       ! array of real
+      INTEGER , INTENT( in  ) ::   kbytes,     &  ! size of the array pmess
+         &                         kdest ,     &  ! receive process number
+         &                         ktyp,       &  ! Tag of the message
+         &                         md_req         ! Argument for isend
+      !!----------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version  :    routine not used
+
+#elif defined key_mpp_mpi
+      !! * MPI version
+      INTEGER ::   iflag
+
+      SELECT CASE ( c_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
+#endif
+
+   END SUBROUTINE mppsend
+
+
+   SUBROUTINE mpprecv( ktyp, pmess, kbytes )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpprecv  ***
+      !!
+      !! ** Purpose :   Receive messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT(inout) ::   pmess(*)       ! array of real
+      INTEGER , INTENT( in  ) ::   kbytes,     &  ! suze of the array pmess
+         &                         ktyp           ! Tag of the recevied message
+      !!----------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version  :    routine not used
+
+#  elif defined key_mpp_mpi
+      !! * MPI version
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+
+      CALL mpi_recv( pmess, kbytes, mpi_double_precision, mpi_any_source, ktyp,   &
+         &                          mpi_comm_opa, istatus, iflag )
+#endif
+
+   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.
+      !!
+      !! ** Method  :
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      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
+      !!---------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      CALL barrier()
+      CALL shmem_put( pio(1,1,npvm_me+1), ptab, jpi*jpj, kp )
+      CALL barrier()
+
+#elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER :: itaille,ierror
+  
+      itaille=jpi*jpj
+      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille,   &
+         &                            mpi_double_precision, kp , mpi_comm_opa, ierror ) 
+#endif
+
+   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.
+      !!
+      !! ** Method :
+      !!
+      !!----------------------------------------------------------------------
+      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
+      !!---------------------------------------------------------------------
+#if defined key_mpp_shmem
+      !! * SHMEM version
+
+      CALL barrier()
+      CALL shmem_get( ptab, pio(1,1,npvm_me+1), jpi*jpj, kp )
+      CALL barrier()
+
+#  elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      INTEGER :: itaille, ierror
+  
+      itaille=jpi*jpj
+
+      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille,   &
+         &                            mpi_double_precision, kp, mpi_comm_opa, ierror )
+#endif
+
+   END SUBROUTINE mppscatter
+
+
+   SUBROUTINE mppisl_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_a_int  ***
+      !!                   
+      !! ** Purpose :   Massively parallel processors
+      !!                Find the  non zero value
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  )                  ::   kdim       ! ???
+      INTEGER, INTENT(inout), DIMENSION(kdim) ::   ktab       ! ???
+  
+#if defined key_mpp_shmem
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppisl_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+
+      DO ji = 1, kdim
+         niitab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni11wrk_shmem,ni11sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni21wrk_shmem,ni21sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,kdim,0   &
+              ,0,N$PES,ni22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      DO ji = 1, kdim
+         IF( ni11tab_shmem(ji) /= 0. ) THEN
+            ktab(ji) = ni11tab_shmem(ji)
+         ELSE
+            ktab(ji) = ni12tab_shmem(ji)
+         ENDIF
+      END DO
+  
+#  elif defined key_mpp_mpi
+      !! * Local variables   (MPI version)
+      LOGICAL  :: lcommute
+      INTEGER, DIMENSION(kdim) ::   iwork
+      INTEGER  :: mpi_isl,ierror
+  
+      lcommute = .TRUE.
+      CALL mpi_op_create( lc_isl, lcommute, mpi_isl, ierror )
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer   &
+           , mpi_isl, mpi_comm_opa, ierror )
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppisl_a_int
+
+
+   SUBROUTINE mppisl_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_int  ***
+      !!                   
+      !! ** Purpose :   Massively parallel processors
+      !!                Find the non zero value
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( inout ) ::   ktab        ! 
+
+#if defined key_mpp_shmem
+      !! * Local variables   (SHMEM version)
+      INTEGER, SAVE :: ibool=0
+
+      niitab_shmem(1) = ktab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni11wrk_shmem,ni11sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_int8_min_to_all (ni11tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni21wrk_shmem,ni21sync_shmem)
+         CALL shmem_int8_max_to_all (ni12tab_shmem,niitab_shmem,1,0   &
+              ,0,N$PES,ni22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      IF( ni11tab_shmem(1) /= 0. ) THEN
+         ktab = ni11tab_shmem(1)
+      ELSE
+         ktab = ni12tab_shmem(1)
+      ENDIF
+  
+#  elif defined key_mpp_mpi
+  
+      !! * Local variables   (MPI version)
+      LOGICAL :: lcommute
+      INTEGER :: mpi_isl,ierror
+      INTEGER ::   iwork
+  
+      lcommute = .TRUE.
+      CALL mpi_op_create(lc_isl,lcommute,mpi_isl,ierror)
+      CALL mpi_allreduce(ktab, iwork, 1,mpi_integer   &
+           ,mpi_isl,mpi_comm_opa,ierror)
+      ktab = iwork
+#endif
+
+   END SUBROUTINE mppisl_int
+
+
+   SUBROUTINE mppmax_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_a_int  ***
+      !! 
+      !! ** Purpose :   Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
+  
+#if defined key_mpp_shmem
+      !! * Local declarations    (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppmax_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+  
+      DO ji = 1, kdim
+         niltab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_max_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_max_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      DO ji = 1, kdim
+         ktab(ji) = niltab_shmem(ji)
+      END DO
+  
+#  elif defined key_mpp_mpi
+  
+      !! * Local variables   (MPI version)
+      INTEGER :: ierror
+      INTEGER, DIMENSION(kdim) ::   iwork
+  
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer,   &
+           &                mpi_max, mpi_comm_opa, ierror )
+  
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppmax_a_int
+
+
+   SUBROUTINE mppmax_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_int  ***
+      !!
+      !! ** Purpose :
+      !!     Massively parallel processors
+      !!     Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(inout) ::   ktab      ! ???
+  
+      !! * Local declarations
+
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      niltab_shmem(1) = ktab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_max_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_max_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      ktab = niltab_shmem(1)
+  
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      INTEGER ::  ierror, iwork
+  
+      CALL mpi_allreduce(ktab,iwork, 1,mpi_integer   &
+           &              ,mpi_max,mpi_comm_opa,ierror)
+  
+      ktab = iwork
+#endif
+
+   END SUBROUTINE mppmax_int
+
+
+   SUBROUTINE mppmin_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_a_int  ***
+      !! 
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
+  
+#if defined key_mpp_shmem
+      !! * Local declarations    (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppmin_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+  
+      DO ji = 1, kdim
+         niltab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem,kdim,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      DO ji = 1, kdim
+         ktab(ji) = niltab_shmem(ji)
+      END DO
+  
+#  elif defined key_mpp_mpi
+  
+      !! * Local variables   (MPI version)
+      INTEGER :: ierror
+      INTEGER, DIMENSION(kdim) ::   iwork
+  
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer,   &
+           &                mpi_min, mpi_comm_opa, ierror )
+  
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppmin_a_int
+
+
+   SUBROUTINE mppmin_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_int  ***
+      !!
+      !! ** Purpose :
+      !!     Massively parallel processors
+      !!     Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT(inout) ::   ktab      ! ???
+  
+      !! * Local declarations
+
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+  
+      niltab_shmem(1) = ktab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil1wrk_shmem,nil1sync_shmem )
+      ELSE
+         CALL shmem_int8_min_to_all (niltab_shmem,niltab_shmem, 1,0,0   &
+              ,N$PES,nil2wrk_shmem,nil2sync_shmem )
+      ENDIF
+      CALL  barrier()
+      ibool=ibool+1
+      ibool=MOD( ibool,2)
+      ktab = niltab_shmem(1)
+  
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      INTEGER ::  ierror, iwork
+  
+      CALL mpi_allreduce(ktab,iwork, 1,mpi_integer   &
+           &              ,mpi_min,mpi_comm_opa,ierror)
+  
+      ktab = iwork
+#endif
+
+   END SUBROUTINE mppmin_int
+
+
+   SUBROUTINE mppsum_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_int  ***
+      !!                    
+      !! ** Purpose :   Massively parallel processors
+      !!                Global integer sum
+      !!
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in  )                   ::   kdim      ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
+  
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER :: ji
+      INTEGER, SAVE :: ibool=0
+
+      IF( kdim > jpmppsum ) CALL ctl_stop( 'mppsum_a_int routine : kdim is too big', &
+           &                               'change jpmppsum dimension in mpp.h' )
+
+      DO ji = 1, kdim
+         nistab_shmem(ji) = ktab(ji)
+      END DO
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem,kdim,0,0,   &
+              N$PES,nis1wrk_shmem,nis1sync_shmem)
+      ELSE
+         CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem,kdim,0,0,   &
+              N$PES,nis2wrk_shmem,nis2sync_shmem)
+      ENDIF
+      CALL  barrier()
+      ibool = ibool + 1
+      ibool = MOD( ibool, 2 )
+      DO ji = 1, kdim
+         ktab(ji) = nistab_shmem(ji)
+      END DO
+  
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      INTEGER :: ierror
+      INTEGER, DIMENSION (kdim) ::  iwork
+  
+      CALL mpi_allreduce(ktab, iwork,kdim,mpi_integer   &
+           ,mpi_sum,mpi_comm_opa,ierror)
+  
+      ktab(:) = iwork(:)
+#endif
+
+   END SUBROUTINE mppsum_a_int
+
+
+  SUBROUTINE mppsum_int( ktab )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppsum_int  ***
+    !!                  
+    !! ** Purpose :   Global integer sum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER, INTENT(inout) ::   ktab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    nistab_shmem(1) = ktab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem, 1,0,0,   &
+            N$PES,nis1wrk_shmem,nis1sync_shmem)
+    ELSE
+       CALL shmem_int8_sum_to_all(nistab_shmem,nistab_shmem, 1,0,0,   &
+            N$PES,nis2wrk_shmem,nis2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ktab = nistab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror, iwork
+
+    CALL mpi_allreduce(ktab,iwork, 1,mpi_integer   &
+         ,mpi_sum,mpi_comm_opa,ierror)
+
+    ktab = iwork
+
+#endif
+
+  END SUBROUTINE mppsum_int
+
+
+  SUBROUTINE mppisl_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppisl_a_real  ***
+    !!         
+    !! ** Purpose :   Massively parallel processors
+    !!           Find the non zero island barotropic stream function value
+    !!
+    !!   Modifications:
+    !!        !  93-09 (M. Imbard)
+    !!        !  96-05 (j. Escobar)
+    !!        !  98-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI 
+    !!----------------------------------------------------------------------
+    INTEGER , INTENT( in  )                  ::   kdim      ! ???
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab      ! ???
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppisl_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wiltab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi11wrk_shmem,ni11sync_shmem)
+       CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi12wrk_shmem,ni12sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi21wrk_shmem,ni21sync_shmem)
+       CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem,kdim,0   &
+            ,0,N$PES,wi22wrk_shmem,ni22sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       IF(wi1tab_shmem(ji) /= 0. ) THEN
+          ptab(ji) = wi1tab_shmem(ji)
+       ELSE
+          ptab(ji) = wi2tab_shmem(ji)
+       ENDIF
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    LOGICAL ::   lcommute = .TRUE.
+    INTEGER ::   mpi_isl, ierror
+    REAL(wp), DIMENSION(kdim) ::  zwork
+
+    CALL mpi_op_create(lc_isl,lcommute,mpi_isl,ierror)
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_isl,mpi_comm_opa,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppisl_a_real
+
+
+   SUBROUTINE mppisl_real( ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppisl_real  ***
+      !!                  
+      !! ** Purpose :   Massively parallel processors
+      !!       Find the  non zero island barotropic stream function value
+      !!
+      !!     Modifications:
+      !!        !  93-09 (M. Imbard)
+      !!        !  96-05 (j. Escobar)
+      !!        !  98-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI 
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   ptab
+
+#if defined key_mpp_shmem
+
+      !! * Local variables   (SHMEM version)
+      INTEGER, SAVE :: ibool=0
+
+      wiltab_shmem(1) = ptab
+      CALL  barrier()
+      IF(ibool == 0 ) THEN 
+         CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi11wrk_shmem,ni11sync_shmem)
+         CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi12wrk_shmem,ni12sync_shmem)
+      ELSE
+         CALL shmem_real8_min_to_all (wi1tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi21wrk_shmem,ni21sync_shmem)
+         CALL shmem_real8_max_to_all (wi2tab_shmem,wiltab_shmem, 1,0   &
+            ,0,N$PES,wi22wrk_shmem,ni22sync_shmem)
+      ENDIF
+      CALL barrier()
+      ibool = ibool + 1
+      ibool = MOD( ibool, 2 )
+      IF( wi1tab_shmem(1) /= 0. ) THEN
+         ptab = wi1tab_shmem(1)
+      ELSE
+         ptab = wi2tab_shmem(1)
+      ENDIF
+
+#  elif defined key_mpp_mpi
+
+      !! * Local variables   (MPI version)
+      LOGICAL  ::   lcommute = .TRUE.
+      INTEGER  ::   mpi_isl, ierror
+      REAL(wp) ::   zwork
+
+      CALL mpi_op_create( lc_isl, lcommute, mpi_isl, ierror )
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision,   &
+         &                                mpi_isl  , mpi_comm_opa, ierror )
+      ptab = zwork
+
+#endif
+
+   END SUBROUTINE mppisl_real
+
+
+  FUNCTION lc_isl( py, px, kdim, kdtatyp )
+    INTEGER :: kdim
+    REAL(wp), DIMENSION(kdim) ::  px, py
+    INTEGER :: kdtatyp, ji
+    INTEGER :: lc_isl
+    DO ji = 1, kdim
+       IF( py(ji) /= 0. )   px(ji) = py(ji)
+    END DO
+    lc_isl=0
+
+  END FUNCTION lc_isl
+
+
+  SUBROUTINE mppmax_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppmax_a_real  ***
+    !!                  
+    !! ** Purpose :   Maximum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in  )                  ::   kdim
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppmax_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wintab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wintab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+    REAL(wp), DIMENSION(kdim) ::  zwork
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_max,mpi_comm_opa,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppmax_a_real
+
+
+  SUBROUTINE mppmax_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppmax_real  ***
+    !!                    
+    !! ** Purpose :   Maximum
+    !!
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    REAL(wp), INTENT(inout) ::   ptab      ! ???
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wintab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_max_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ptab = wintab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce( ptab, zwork  , 1             , mpi_double_precision,   &
+       &                      mpi_max, mpi_comm_opa, ierror     )
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppmax_real
+
+
+  SUBROUTINE mppmin_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                 ***  routine mppmin_a_real  ***
+    !!                  
+    !! ** Purpose :   Minimum
+    !!
+    !!-----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in  )                  ::   kdim
+    REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mpprmin routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wintab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem,kdim,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wintab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+    REAL(wp), DIMENSION(kdim) ::   zwork
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         ,mpi_min,mpi_comm_opa,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppmin_a_real
+
+
+  SUBROUTINE mppmin_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppmin_real  ***
+    !! 
+    !! ** Purpose :   minimum in Massively Parallel Processing
+    !!                REAL scalar case
+    !!
+    !!-----------------------------------------------------------------------
+    !! * Arguments
+    REAL(wp), INTENT( inout ) ::   ptab        ! 
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wintab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi1wrk_shmem,ni1sync_shmem)
+    ELSE
+       CALL shmem_real8_min_to_all (wintab_shmem,wintab_shmem, 1,0   &
+            ,0,N$PES,wi2wrk_shmem,ni2sync_shmem)
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    ptab = wintab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce( ptab, zwork, 1,mpi_double_precision   &
+         &               ,mpi_min,mpi_comm_opa,ierror)
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppmin_real
+
+
+  SUBROUTINE mppsum_a_real( ptab, kdim )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsum_a_real  ***
+    !! 
+    !! ** Purpose :   global sum in Massively Parallel Processing
+    !!                REAL ARRAY argument case
+    !!
+    !!-----------------------------------------------------------------------
+    INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
+    REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER :: ji
+    INTEGER, SAVE :: ibool=0
+
+    IF( kdim > jpmppsum ) CALL ctl_stop( 'mppsum_a_real routine : kdim is too big', &
+         &                               'change jpmppsum dimension in mpp.h' )
+
+    DO ji = 1, kdim
+       wrstab_shmem(ji) = ptab(ji)
+    END DO
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem,kdim,0   &
+            ,0,N$PES,wrs1wrk_shmem,nrs1sync_shmem )
+    ELSE
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem,kdim,0   &
+            ,0,N$PES,wrs2wrk_shmem,nrs2sync_shmem )
+    ENDIF
+    CALL  barrier()
+    ibool=ibool+1
+    ibool=MOD( ibool,2)
+    DO ji = 1, kdim
+       ptab(ji) = wrstab_shmem(ji)
+    END DO
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER                   ::   ierror    ! temporary integer
+    REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace 
+
+    CALL mpi_allreduce(ptab, zwork,kdim,mpi_double_precision   &
+         &              ,mpi_sum,mpi_comm_opa,ierror)
+    ptab(:) = zwork(:)
+
+#endif
+
+  END SUBROUTINE mppsum_a_real
+
+
+  SUBROUTINE mppsum_real( ptab )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsum_real  ***
+    !!              
+    !! ** Purpose :   global sum in Massively Parallel Processing
+    !!                SCALAR argument case
+    !!
+    !!-----------------------------------------------------------------------
+    REAL(wp), INTENT(inout) ::   ptab        ! input scalar
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    INTEGER, SAVE :: ibool=0
+
+    wrstab_shmem(1) = ptab
+    CALL  barrier()
+    IF(ibool == 0 ) THEN 
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem, 1,0   &
+            ,0,N$PES,wrs1wrk_shmem,nrs1sync_shmem )
+    ELSE
+       CALL shmem_real8_sum_to_all (wrstab_shmem,wrstab_shmem, 1,0   &
+            ,0,N$PES,wrs2wrk_shmem,nrs2sync_shmem )
+    ENDIF
+    CALL  barrier()
+    ibool = ibool + 1
+    ibool = MOD( ibool, 2 )
+    ptab = wrstab_shmem(1)
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER  ::   ierror
+    REAL(wp) ::   zwork
+
+    CALL mpi_allreduce(ptab, zwork, 1,mpi_double_precision   &
+         &              ,mpi_sum,mpi_comm_opa,ierror)
+    ptab = zwork
+
+#endif
+
+  END SUBROUTINE mppsum_real
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmin = global minimum
+    !!                O : ki,kj = global position of minimum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_minloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmin    ! Global minimum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj   ! index of minimum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmin   ! local minimum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (2)  :: ilocs
+    INTEGER :: ierror
+
+
+    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 )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmin = global minimum
+    !!                O : ki,kj = global position of minimum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_minloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmin    ! Global minimum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj,kk ! index of minimum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmin   ! local minimum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (3)  :: ilocs
+    INTEGER :: ierror
+
+
+    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. )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmax = global maximum
+    !!                O : ki,kj = global position of maximum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_maxloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmax    ! Global maximum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj   ! index of maximum in global frame
+
+    !! * Local variables
+    REAL(wp) :: zmax   ! local maximum
+    REAL(wp) ,DIMENSION(2,1) :: zain, zaout
+    INTEGER, DIMENSION (2)  :: 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
+
+    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 )
+#endif
+
+  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
+    !!
+    !! ** Arguments : I : ptab =local 2D array
+    !!                O : pmax = global maximum
+    !!                O : ki,kj = global position of maximum
+    !!
+    !! ** Author : J.M. Molines 10/10/2004
+    !!--------------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_maxloc not yet available in SHMEM' )
+# elif key_mpp_mpi
+    !! * Arguments
+    REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT (in)  :: ptab ,& ! Local 2D array
+         &                                         pmask   ! Local mask
+    REAL(wp)                     , INTENT (out) :: pmax    ! Global maximum of ptab
+    INTEGER                      , INTENT (out) :: ki,kj,kk   ! index of maximum in global frame
+
+    !! * Local variables
+    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. )
+#endif
+
+  END SUBROUTINE mpp_maxloc3d
+
+  SUBROUTINE mppsync()
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppsync  ***
+    !!                   
+    !! ** Purpose :   Massively parallel processors, synchroneous
+    !!
+    !!-----------------------------------------------------------------------
+
+#if defined key_mpp_shmem
+
+    !! * Local variables   (SHMEM version)
+    CALL barrier()
+
+#  elif defined key_mpp_mpi
+
+    !! * Local variables   (MPI version)
+    INTEGER :: ierror
+
+    CALL mpi_barrier(mpi_comm_opa,ierror)
+
+#endif
+
+  END SUBROUTINE mppsync
+
+
+  SUBROUTINE mppstop
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppstop  ***
+    !!                   
+    !! ** purpose :   Stop massilively parallel processors method
+    !!
+    !!----------------------------------------------------------------------
+    !! * Local declarations
+    INTEGER ::   info
+    !!----------------------------------------------------------------------
+
+    ! 1. Mpp synchroneus
+    ! ------------------
+
+    CALL mppsync
+#if defined key_mpp_mpi
+    CALL mpi_finalize( info )
+#endif
+
+  END SUBROUTINE mppstop
+
+
+  SUBROUTINE mppobc( ptab, kd1, kd2, kl, kk, ktype, kij )
+    !!----------------------------------------------------------------------
+    !!                  ***  routine mppobc  ***
+    !! 
+    !! ** Purpose :   Message passing manadgement for open boundary
+    !!     conditions 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
+    !!
+    !! History :
+    !!        !  98-07 (J.M. Molines) Open boundary conditions
+    !!----------------------------------------------------------------------
+    !! * Arguments
+    INTEGER , INTENT( in ) ::   &
+         kd1, kd2,   &  ! starting and ending indices
+         kl ,        &  ! index of open boundary
+         kk,         &  ! vertical dimension
+         ktype,      &  ! define north/south or east/west cdt
+         !              !  = 1  north/south  ;  = 2  east/west
+         kij            ! horizontal dimension
+    REAL(wp), DIMENSION(kij,kk), INTENT( inout )  ::   &
+         ptab           ! variable array
+
+    !! * Local variables
+    INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+    INTEGER  ::   &
+         iipt0, iipt1, ilpt1,     &  ! temporary integers
+         ijpt0, ijpt1,            &  !    "          "
+         imigr, iihom, ijhom         !    "          "
+    INTEGER ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+    INTEGER ::   ml_stat(MPI_STATUS_SIZE)     ! for key_mpi_isend
+    REAL(wp), DIMENSION(jpi,jpj) ::   &
+         ztab                        ! temporary workspace
+    !!----------------------------------------------------------------------
+
+
+    ! boundary condition initialization
+    ! ---------------------------------
+
+    ztab(:,:) = 0.e0
+
+    IF( ktype==1 ) THEN                                  ! north/south boundaries
+       iipt0 = MAX( 1, MIN(kd1 - nimpp+1, nlci     ) )
+       iipt1 = MAX( 0, MIN(kd2 - nimpp+1, nlci - 1 ) )
+       ilpt1 = MAX( 1, MIN(kd2 - nimpp+1, nlci     ) )
+       ijpt0 = MAX( 1, MIN(kl  - njmpp+1, nlcj     ) )
+       ijpt1 = MAX( 0, MIN(kl  - njmpp+1, nlcj - 1 ) )
+    ELSEIF( ktype==2 ) THEN                              ! east/west boundaries
+       iipt0 = MAX( 1, MIN(kl  - nimpp+1, nlci     ) )
+       iipt1 = MAX( 0, MIN(kl  - nimpp+1, nlci - 1 ) )
+       ijpt0 = MAX( 1, MIN(kd1 - njmpp+1, nlcj     ) )
+       ijpt1 = MAX( 0, MIN(kd2 - njmpp+1, nlcj - 1 ) )
+       ilpt1 = MAX( 1, MIN(kd2 - njmpp+1, nlcj     ) )
+    ELSE
+       CALL ctl_stop( 'mppobc: bad ktype' )
+    ENDIF
+
+    DO jk = 1, kk
+       IF( ktype==1 ) THEN                               ! north/south boundaries
+          DO jj = ijpt0, ijpt1
+             DO ji = iipt0, iipt1
+                ztab(ji,jj) = ptab(ji,jk)
+             END DO
+          END DO
+       ELSEIF( ktype==2 ) THEN                           ! east/west boundaries
+          DO jj = ijpt0, ijpt1
+             DO ji = iipt0, iipt1
+                ztab(ji,jj) = ptab(jj,jk)
+             END DO
+          END DO
+       ENDIF
+
+
+       ! 1. East and west directions
+       ! ---------------------------
+
+       ! 1.1 Read Dirichlet lateral conditions
+
+       IF( nbondi /= 2 ) THEN
+          iihom = nlci-nreci
+
+          DO jl = 1, jpreci
+             t2ew(:,jl,1) = ztab(jpreci+jl,:)
+             t2we(:,jl,1) = ztab(iihom +jl,:)
+          END DO
+       ENDIF
+
+       ! 1.2 Migrations
+
+#if defined key_mpp_shmem
+       !! *  (SHMEM version)
+       imigr=jpreci*jpj*jpbyt
+
+       IF( nbondi == -1 ) THEN
+          CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr/jpbyt, noea )
+       ELSEIF( nbondi == 0 ) THEN
+          CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr/jpbyt, nowe )
+          CALL shmem_put( t2we(1,1,2), t2we(1,1,1), imigr/jpbyt, noea )
+       ELSEIF( nbondi == 1 ) THEN
+          CALL shmem_put( t2ew(1,1,2), t2ew(1,1,1), imigr/jpbyt, nowe )
+       ENDIF
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif key_mpp_mpi
+       !! * (MPI version)
+
+       imigr=jpreci*jpj
+
+       IF( nbondi == -1 ) THEN
+          CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req1)
+          CALL mpprecv(1,t2ew(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ELSEIF( nbondi == 0 ) THEN
+          CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+          CALL mppsend(2,t2we(1,1,1),imigr,noea, ml_req2)
+          CALL mpprecv(1,t2ew(1,1,2),imigr)
+          CALL mpprecv(2,t2we(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+       ELSEIF( nbondi == 1 ) THEN
+          CALL mppsend(1,t2ew(1,1,1),imigr,nowe, ml_req1)
+          CALL mpprecv(2,t2we(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ENDIF
+#endif
+
+
+       ! 1.3 Write Dirichlet lateral conditions
+
+       iihom = nlci-jpreci
+       IF( nbondi == 0 .OR. nbondi == 1 ) THEN
+          DO jl = 1, jpreci
+             ztab(jl,:) = t2we(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( nbondi == -1 .OR. nbondi == 0 ) THEN
+          DO jl = 1, jpreci
+             ztab(iihom+jl,:) = t2ew(:,jl,2)
+          END DO
+       ENDIF
+
+
+       ! 2. North and south directions
+       ! -----------------------------
+
+       ! 2.1 Read Dirichlet lateral conditions
+
+       IF( nbondj /= 2 ) THEN
+          ijhom = nlcj-nrecj
+          DO jl = 1, jprecj
+             t2sn(:,jl,1) = ztab(:,ijhom +jl)
+             t2ns(:,jl,1) = ztab(:,jprecj+jl)
+          END DO
+       ENDIF
+
+       ! 2.2 Migrations
+
+#if defined key_mpp_shmem
+       !! * SHMEM version
+
+       imigr=jprecj*jpi*jpbyt
+
+       IF( nbondj == -1 ) THEN
+          CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr/jpbyt, nono )
+       ELSEIF( nbondj == 0 ) THEN
+          CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr/jpbyt, noso )
+          CALL shmem_put( t2sn(1,1,2), t2sn(1,1,1), imigr/jpbyt, nono )
+       ELSEIF( nbondj == 1 ) THEN
+          CALL shmem_put( t2ns(1,1,2), t2ns(1,1,1), imigr/jpbyt, noso )
+       ENDIF
+       CALL barrier()
+       CALL shmem_udcflush()
+
+#  elif key_mpp_mpi
+       !! * Local variables   (MPI version)
+
+       imigr=jprecj*jpi
+
+       IF( nbondj == -1 ) THEN
+          CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req1)
+          CALL mpprecv(3,t2ns(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ELSEIF( nbondj == 0 ) THEN
+          CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+          CALL mppsend(4,t2sn(1,1,1),imigr,nono, ml_req2)
+          CALL mpprecv(3,t2ns(1,1,2),imigr)
+          CALL mpprecv(4,t2sn(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+       ELSEIF( nbondj == 1 ) THEN
+          CALL mppsend(3,t2ns(1,1,1),imigr,noso, ml_req1)
+          CALL mpprecv(4,t2sn(1,1,2),imigr)
+          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+       ENDIF
+
+#endif
+
+       ! 2.3 Write Dirichlet lateral conditions
+
+       ijhom = nlcj - jprecj
+       IF( nbondj == 0 .OR. nbondj == 1 ) THEN
+          DO jl = 1, jprecj
+             ztab(:,jl) = t2sn(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( nbondj == 0 .OR. nbondj == -1 ) THEN
+          DO jl = 1, jprecj
+             ztab(:,ijhom+jl) = t2ns(:,jl,2)
+          END DO
+       ENDIF
+
+       IF( ktype==1 .AND. kd1 <= jpi+nimpp-1 .AND. nimpp <= kd2 ) THEN
+          ! north/south boundaries
+          DO jj = ijpt0,ijpt1
+             DO ji = iipt0,ilpt1
+                ptab(ji,jk) = ztab(ji,jj)  
+             END DO
+          END DO
+       ELSEIF( ktype==2 .AND. kd1 <= jpj+njmpp-1 .AND. njmpp <= kd2 ) THEN
+          ! east/west boundaries
+          DO jj = ijpt0,ilpt1
+             DO ji = iipt0,iipt1
+                ptab(jj,jk) = ztab(ji,jj) 
+             END DO
+          END DO
+       ENDIF
+
+    END DO
+
+  END SUBROUTINE mppobc
+
+
+  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.
+    !!
+    !! History :
+    !!        !  03-09 (J.M. Molines, MPI only )
+    !!----------------------------------------------------------------------
+#ifdef key_mpp_shmem
+    CALL ctl_stop( ' mpp_ini_north not available in SHMEM' )
+# elif key_mpp_mpi
+    INTEGER :: ierr
+    INTEGER :: jproc
+    INTEGER :: ii,ji
+    !!----------------------------------------------------------------------
+
+    njmppmax=MAXVAL(njmppt)
+
+    ! Look for how many procs on the northern boundary
+    !
+    ndim_rank_north=0
+    DO jproc=1,jpnij
+       IF ( njmppt(jproc) == njmppmax ) THEN
+          ndim_rank_north = ndim_rank_north + 1
+       END IF
+    END DO
+
+
+    ! Allocate the right size to 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)
+
+
+    ! find proc number in the world of proc 0 in the north
+    CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_north,1,0,ngrp_world,north_root,ierr)
+#endif
+
+  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 :
+      !!      Gather the 4 northern lines of the global domain on 1 processor and 
+      !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+      !!      back to the processors.
+      !!
+      !! History :
+      !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+      !!                                  from lbc routine
+      !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt3d grid-points
+         !             !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
+         pt3d          ! 3D array on which the boundary condition is applied
+      REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+         !             !   = -1. , the sign is changed if north fold boundary
+         !             !   =  1. , the sign is kept  if north fold boundary
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jk, jr, jproc
+      INTEGER :: ierr
+      INTEGER :: ildi,ilei,iilb
+      INTEGER :: ijpj,ijpjm1,ij,ijt,iju
+      INTEGER :: itaille
+      REAL(wp), DIMENSION(jpiglo,4,jpk) :: ztab
+      REAL(wp), DIMENSION(jpi,4,jpk,jpni) :: znorthgloio
+      REAL(wp), DIMENSION(jpi,4,jpk) :: znorthloc
+      !!----------------------------------------------------------------------
+
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+
+    ! put in znorthloc the last 4 jlines of pt3d
+    DO jk = 1, jpk 
+       DO jj = nlcj - ijpj +1, nlcj
+          ij = jj - nlcj + ijpj
+          znorthloc(:,ij,jk) = pt3d(:,jj,jk)
+       END DO
+    END DO
+
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:,:) = 0_wp
+
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*jpk*ijpj
+       CALL MPI_GATHER(znorthloc,itaille,MPI_DOUBLE_PRECISION,znorthgloio,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc = nrank_north(jr) + 1
+          ildi  = nldit (jproc)
+          ilei  = nleit (jproc)
+          iilb  = nimppt(jproc)
+          DO jk = 1, jpk 
+             DO jj = 1, 4
+                DO ji = ildi, ilei
+                   ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                END DO
+             END DO
+          END DO
+       END DO
+
+
+       ! Horizontal slab
+       ! ===============
+
+       DO jk = 1, jpk 
+
+
+          ! 2. North-Fold boundary conditions
+          ! ----------------------------------
+
+          SELECT CASE ( npolj )
+
+          CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+             ztab( 1    ,ijpj,jk) = 0.e0
+             ztab(jpiglo,ijpj,jk) = 0.e0
+
+             SELECT CASE ( cd_type )
+
+             CASE ( 'T' , 'S' , 'W' )                   ! T-, W-point
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(ijt,ijpjm1,jk)
+                END DO
+
+             CASE ( 'U' )                               ! U-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(iju,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(iju,ijpjm1,jk)
+                END DO
+
+             CASE ( 'V' )                               ! V-point
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj-1,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(ijt,ijpj-3,jk)
+                END DO
+
+             CASE ( 'F' , 'G' )                         ! F-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj-1,jk) = psgn * ztab(iju,ijpj-2,jk)
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(iju,ijpj-3,jk)
+                END DO
+
+             END SELECT
+
+          CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+             ztab( 1    ,ijpj,jk) = 0.e0
+             ztab(jpiglo,ijpj,jk) = 0.e0
+
+             SELECT CASE ( cd_type )
+
+             CASE ( 'T' , 'S' , 'W' )                   ! T-, W-point
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-1,jk)
+                END DO
+
+             CASE ( 'U' )                               ! U-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj,jk) = psgn * ztab(iju,ijpj-1,jk)
+                END DO
+
+             CASE ( 'V' )                               ! V-point
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj,jk) = psgn * ztab(ijt,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(ijt,ijpjm1,jk)
+                END DO
+
+             CASE ( 'F' , 'G' )                         ! F-point
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj  ,jk) = psgn * ztab(iju,ijpj-2,jk)
+                END DO
+                DO ji = jpiglo/2+1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpjm1,jk) = psgn * ztab(iju,ijpjm1,jk)
+                END DO
+
+             END SELECT
+
+          CASE DEFAULT                           ! *  closed
+
+             SELECT CASE ( cd_type) 
+
+             CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+                ztab(:, 1  ,jk) = 0.e0
+                ztab(:,ijpj,jk) = 0.e0
+
+             CASE ( 'F' )                               ! F-point
+                ztab(:,ijpj,jk) = 0.e0
+
+             END SELECT
+
+          END SELECT
+
+          !     End of slab
+          !     ===========
+
+       END DO
+
+       !! Scatter back to pt3d
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jk=  1, jpk
+             DO jj=1,ijpj
+                DO ji=ildi,ilei
+                   znorthgloio(ji,jj,jk,jr)=ztab(ji+iilb-1,jj,jk)
+                END DO
+             END DO
+          END DO
+       END DO
+
+    ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+    not done yet in shmem : compiler error
+#elif key_mpp_mpi
+    IF ( npolj /= 0 ) THEN
+       itaille=jpi*jpk*ijpj
+       CALL MPI_SCATTER(znorthgloio,itaille,MPI_DOUBLE_PRECISION,znorthloc,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+    ENDIF
+#endif
+
+    ! put in the last ijpj jlines of pt3d znorthloc
+    DO jk = 1 , jpk 
+       DO jj = nlcj - ijpj + 1 , nlcj
+          ij = jj - nlcj + ijpj
+          pt3d(:,jj,jk)= znorthloc(:,ij,jk)
+       END DO
+    END DO
+
+  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 :
+    !!      Gather the 4 northern lines of the global domain on 1 processor and 
+    !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+    !!      back to the processors.
+    !!
+    !! History :
+    !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+    !!                                  from lbc routine
+    !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+    !!----------------------------------------------------------------------
+
+    !! * Arguments
+    CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-points
+    !             !   = T ,  U , V , F or W  gridpoints
+    REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+    REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+    !             !   = -1. , the sign is changed if north fold boundary
+    !             !   =  1. , the sign is kept  if north fold boundary
+
+
+    !! * Local declarations
+
+    INTEGER :: ji, jj,  jr, jproc
+    INTEGER :: ierr
+    INTEGER :: ildi,ilei,iilb
+    INTEGER :: ijpj,ijpjm1,ij,ijt,iju
+    INTEGER :: itaille
+
+    REAL(wp), DIMENSION(jpiglo,4) :: ztab
+    REAL(wp), DIMENSION(jpi,4,jpni) :: znorthgloio
+    REAL(wp), DIMENSION(jpi,4) :: znorthloc
+    !!----------------------------------------------------------------------
+    !!  OPA 8.5, LODYC-IPSL (2002)
+    !!----------------------------------------------------------------------
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+
+
+    ! put in znorthloc the last 4 jlines of pt2d
+    DO jj = nlcj - ijpj +1, nlcj
+       ij = jj - nlcj + ijpj
+       znorthloc(:,ij)=pt2d(:,jj)
+    END DO
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:) = 0_wp
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*ijpj
+       CALL MPI_GATHER(znorthloc,itaille,MPI_DOUBLE_PRECISION,znorthgloio,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jj=1,4
+             DO ji=ildi,ilei
+                ztab(ji+iilb-1,jj)=znorthgloio(ji,jj,jr)
+             END DO
+          END DO
+       END DO
+
+
+       ! 2. North-Fold boundary conditions
+       ! ----------------------------------
+
+       SELECT CASE ( npolj )
+
+       CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+          ztab( 1    ,ijpj) = 0.e0
+          ztab(jpiglo,ijpj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' , 'S' )                         ! T-, W-point
+             DO ji = 2, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-2)
+             END DO
+             DO ji = jpiglo/2, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO ji = 2, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpj-1) = psgn * ztab(ijt,ijpj-2)
+                ztab(ji,ijpj  ) = psgn * ztab(ijt,ijpj-3)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpj-1) = psgn * ztab(iju,ijpj-2)
+                ztab(ji,ijpj  ) = psgn * ztab(iju,ijpj-3)
+             END DO
+
+          CASE ( 'I' )                                     ! ice U-V point
+             ztab(2,ijpj) = psgn * ztab(3,ijpj-1)
+             DO ji = 3, jpiglo
+                iju = jpiglo - ji + 3
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-1)
+             END DO
+
+          END SELECT
+
+       CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+          ztab( 1 ,ijpj) = 0.e0
+          ztab(jpiglo,ijpj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' ,'S' )                          ! T-, W-point
+             DO ji = 1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpj) = psgn * ztab(iju,ijpj-1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO ji = 1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpj) = psgn * ztab(ijt,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO ji = 1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpj  ) = psgn * ztab(iju,ijpj-2)
+             END DO
+             DO ji = jpiglo/2+1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+             CASE ( 'I' )                                  ! ice U-V point
+                ztab( 2 ,ijpj) = 0.e0
+                DO ji = 2 , jpiglo-1
+                   ijt = jpiglo - ji + 2
+                   ztab(ji,ijpj)= 0.5 * ( ztab(ji,ijpj-1) + psgn * ztab(ijt,ijpj-1) )
+                END DO
+
+          END SELECT
+
+       CASE DEFAULT                           ! *  closed : the code probably never go through
+
+            SELECT CASE ( cd_type) 
+  
+            CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+               ztab(:, 1 ) = 0.e0
+               ztab(:,ijpj) = 0.e0
+
+            CASE ( 'F' )                                   ! F-point
+               ztab(:,ijpj) = 0.e0
+
+            CASE ( 'I' )                                   ! ice U-V point
+               ztab(:, 1 ) = 0.e0
+               ztab(:,ijpj) = 0.e0
+
+            END SELECT
+
+         END SELECT
+
+         !     End of slab
+         !     ===========
+
+         !! Scatter back to pt2d
+         DO jr = 1, ndim_rank_north
+            jproc=nrank_north(jr)+1
+            ildi=nldit (jproc)
+            ilei=nleit (jproc)
+            iilb=nimppt(jproc)
+            DO jj=1,ijpj
+               DO ji=ildi,ilei
+                  znorthgloio(ji,jj,jr)=ztab(ji+iilb-1,jj)
+               END DO
+            END DO
+         END DO
+
+      ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+      not done yet in shmem : compiler error
+#elif key_mpp_mpi
+      IF ( npolj /= 0 ) THEN
+         itaille=jpi*ijpj
+         CALL MPI_SCATTER(znorthgloio,itaille,MPI_DOUBLE_PRECISION,znorthloc,itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+      ENDIF
+#endif
+
+      ! put in the last ijpj jlines of pt2d znorthloc
+      DO jj = nlcj - ijpj + 1 , nlcj
+         ij = jj - nlcj + ijpj
+         pt2d(:,jj)= znorthloc(:,ij)
+      END DO
+
+   END SUBROUTINE mpp_lbc_north_2d
+
+
+   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 (for 2d array with outer extra halo)
+    !!
+    !! ** Method :
+    !!      Gather the 4+2*jpr2dj northern lines of the global domain on 1 processor and 
+    !!      apply lbc north-fold on this sub array. Then scatter the fold array 
+    !!      back to the processors.
+    !!
+    !! History :
+    !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north
+    !!                                  from lbc routine
+    !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk
+    !!   9.0  !  05-09  (R. Benshila )   adapt mpp_lbc_north_2d 
+    !!----------------------------------------------------------------------
+
+    !! * Arguments
+    CHARACTER(len=1), INTENT( in ) ::   &
+         cd_type       ! nature of pt2d grid-points
+    !             !   = T ,  U , V , F or W  gridpoints
+    REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT( inout ) ::   &
+         pt2d          ! 2D array on which the boundary condition is applied
+    REAL(wp), INTENT( in ) ::   &
+         psgn          ! control of the sign change
+    !             !   = -1. , the sign is changed if north fold boundary
+    !             !   =  1. , the sign is kept  if north fold boundary
+
+
+    !! * Local declarations
+
+    INTEGER :: ji, jj,  jr, jproc, jl
+    INTEGER :: ierr
+    INTEGER :: ildi,ilei,iilb
+    INTEGER :: ijpj,ijpjm1,ij,ijt,iju, iprecj
+    INTEGER :: itaille
+
+    REAL(wp), DIMENSION(jpiglo,1-jpr2dj:4+jpr2dj) :: ztab
+    REAL(wp), DIMENSION(jpi,1-jpr2dj:4+jpr2dj,jpni) :: znorthgloio
+    REAL(wp), DIMENSION(jpi,1-jpr2dj:4+jpr2dj) :: znorthloc
+
+    ! If we get in this routine it s because : North fold condition and mpp with more
+    !   than one proc across i : we deal only with the North condition
+
+    ! 0. Sign setting
+    ! ---------------
+
+    ijpj=4
+    ijpjm1=3
+    iprecj = jpr2dj+jprecj
+
+    ! put in znorthloc the last 4 jlines of pt2d
+    DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
+       ij = jj - nlcj + ijpj
+       znorthloc(:,ij)=pt2d(1:jpi,jj)
+    END DO
+
+    IF (npolj /= 0 ) THEN
+       ! Build in proc 0 of ncomm_north the znorthgloio
+       znorthgloio(:,:,:) = 0_wp
+#ifdef key_mpp_shmem
+       not done : compiler error
+#elif defined key_mpp_mpi
+       itaille=jpi*(ijpj+2*jpr2dj)
+       CALL MPI_GATHER(znorthloc(1,1-jpr2dj),itaille,MPI_DOUBLE_PRECISION, &
+                     & znorthgloio(1,1-jpr2dj,1),itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+#endif
+    ENDIF
+
+    IF (narea == north_root+1 ) THEN
+       ! recover the global north array
+       ztab(:,:) = 0_wp
+
+       DO jr = 1, ndim_rank_north
+          jproc=nrank_north(jr)+1
+          ildi=nldit (jproc)
+          ilei=nleit (jproc)
+          iilb=nimppt(jproc)
+          DO jj=1-jpr2dj,ijpj+jpr2dj
+             DO ji=ildi,ilei
+                ztab(ji+iilb-1,jj)=znorthgloio(ji,jj,jr)
+             END DO
+          END DO
+       END DO
+
+
+       ! 2. North-Fold boundary conditions
+       ! ----------------------------------
+
+       SELECT CASE ( npolj )
+
+       CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+
+          ztab( 1    ,ijpj:ijpj+jpr2dj) = 0.e0
+          ztab(jpiglo,ijpj:ijpj+jpr2dj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' , 'S' )                         ! T-, W-point
+             DO jl =0, iprecj-1
+                DO ji = 2, jpiglo
+                   ijt = jpiglo-ji+2
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+2
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO jl =0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2, jpiglo-1
+                iju = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+            DO jl =-1, iprecj-1
+               DO ji = 2, jpiglo
+                  ijt = jpiglo-ji+2
+                  ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-3-jl)
+               END DO
+            END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+            DO jl =-1, iprecj-1
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-3-jl)
+               END DO
+             END DO
+
+          CASE ( 'I' )                                     ! ice U-V point
+             DO jl =0, iprecj-1
+                ztab(2,ijpj+jl) = psgn * ztab(3,ijpj-1+jl)
+                DO ji = 3, jpiglo
+                   iju = jpiglo - ji + 3
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-1-jl)
+                END DO
+             END DO
+
+          END SELECT
+
+       CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+
+          ztab( 1 ,ijpj:ijpj+jpr2dj) = 0.e0
+          ztab(jpiglo,ijpj:ijpj+jpr2dj) = 0.e0
+
+          SELECT CASE ( cd_type )
+
+          CASE ( 'T' , 'W' ,'S' )                          ! T-, W-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-1-jl)
+                END DO
+             END DO
+
+          CASE ( 'U' )                                     ! U-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-1-jl)
+                END DO
+             END DO
+
+          CASE ( 'V' )                                     ! V-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo
+                   ijt = jpiglo-ji+1
+                   ztab(ji,ijpj+jl) = psgn * ztab(ijt,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo
+                ijt = jpiglo-ji+1
+                ztab(ji,ijpjm1) = psgn * ztab(ijt,ijpjm1)
+             END DO
+
+          CASE ( 'F' , 'G' )                               ! F-point
+             DO jl = 0, iprecj-1
+                DO ji = 1, jpiglo-1
+                   iju = jpiglo-ji
+                   ztab(ji,ijpj+jl) = psgn * ztab(iju,ijpj-2-jl)
+                END DO
+             END DO
+             DO ji = jpiglo/2+1, jpiglo-1
+                iju = jpiglo-ji
+                ztab(ji,ijpjm1) = psgn * ztab(iju,ijpjm1)
+             END DO
+
+             CASE ( 'I' )                                  ! ice U-V point
+                ztab( 2 ,ijpj:ijpj+jpr2dj) = 0.e0
+                DO jl = 0, jpr2dj
+                   DO ji = 2 , jpiglo-1
+                      ijt = jpiglo - ji + 2
+                      ztab(ji,ijpj+jl)= 0.5 * ( ztab(ji,ijpj-1-jl) + psgn * ztab(ijt,ijpj-1-jl) )
+                   END DO
+                END DO
+
+          END SELECT
+
+       CASE DEFAULT                           ! *  closed : the code probably never go through
+
+            SELECT CASE ( cd_type) 
+  
+            CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+               ztab(:, 1:1-jpr2dj     ) = 0.e0
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            CASE ( 'F' )                                   ! F-point
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            CASE ( 'I' )                                   ! ice U-V point
+               ztab(:, 1:1-jpr2dj     ) = 0.e0
+               ztab(:,ijpj:ijpj+jpr2dj) = 0.e0
+
+            END SELECT
+
+         END SELECT
+
+         !     End of slab
+         !     ===========
+
+         !! Scatter back to pt2d
+         DO jr = 1, ndim_rank_north
+            jproc=nrank_north(jr)+1
+            ildi=nldit (jproc)
+            ilei=nleit (jproc)
+            iilb=nimppt(jproc)
+            DO jj=1-jpr2dj,ijpj+jpr2dj
+               DO ji=ildi,ilei
+                  znorthgloio(ji,jj,jr)=ztab(ji+iilb-1,jj)
+               END DO
+            END DO
+         END DO
+
+      ENDIF      ! only done on proc 0 of ncomm_north
+
+#ifdef key_mpp_shmem
+      not done yet in shmem : compiler error
+#elif key_mpp_mpi
+      IF ( npolj /= 0 ) THEN
+         itaille=jpi*(ijpj+2*jpr2dj)
+         CALL MPI_SCATTER(znorthgloio(1,1-jpr2dj,1),itaille,MPI_DOUBLE_PRECISION, &
+                        & znorthloc(1,1-jpr2dj),itaille,MPI_DOUBLE_PRECISION,0,ncomm_north,ierr)
+      ENDIF
+#endif
+
+      ! put in the last ijpj jlines of pt2d znorthloc
+      DO jj = nlcj - ijpj  -jpr2dj + 1 , nlcj +jpr2dj
+         ij = jj - nlcj + ijpj 
+         pt2d(1:jpi,jj)= znorthloc(:,ij)
+      END DO
+
+   END SUBROUTINE mpp_lbc_north_e
+
+
+   !!!!!
+
+
+   !! 
+   !!    This is valid on IBM machine ONLY. 
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -*- Mode: F90 -*- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   !! mpi_init_opa.f90 : Redefinition du point d'entree MPI_INIT de la bibliotheque
+   !!                MPI afin de faire, en plus de l'initialisation de
+   !!                l'environnement MPI, l'allocation d'une zone tampon
+   !!                qui sera ulterieurement utilisee automatiquement lors
+   !!                de tous les envois de messages par MPI_BSEND
+   !!
+   !! Auteur : CNRS/IDRIS
+   !! Date   : Tue Nov 13 12:02:14 2001
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+   SUBROUTINE mpi_init_opa(code)
+      IMPLICIT NONE
+
+!$AGRIF_DO_NOT_TREAT
+#     include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
+
+      INTEGER                                 :: code,rang,ierr
+      LOGICAL                                 :: mpi_was_called
+ 
+      ! La valeur suivante doit etre au moins egale a la taille
+      ! du plus grand message qui sera transfere dans le programme
+      ! (de toute facon, il y aura un message d'erreur si cette
+      ! valeur s'avere trop petite)
+      INTEGER                                 :: taille_tampon
+      CHARACTER(len=9)                        :: taille_tampon_alphanum
+      REAL(kind=8), ALLOCATABLE, DIMENSION(:) :: tampon
+ 
+      ! Le point d'entree dans la bibliotheque MPI elle-meme
+      CALL mpi_initialized(mpi_was_called, code)
+      IF ( code /= MPI_SUCCESS ) THEN
+        CALL ctl_stop( ' 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
+            CALL ctl_stop( ' lib_mpp: Error in routine mpi_comm_dup' )
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF
+      ! La definition de la zone tampon pour les futurs envois
+      ! par MPI_BSEND (on alloue une fois pour toute cette zone
+      ! tampon, qui sera automatiquement utilisee lors de chaque
+      ! appel  a MPI_BSEND).
+      ! La desallocation sera implicite quand on sortira de
+      ! l'environnement MPI.
+
+      ! Recuperation de la valeur de la variable d'environnement
+      ! BUFFER_LENGTH
+      ! qui, si elle est definie, doit contenir une valeur superieure
+      ! a  la taille en octets du plus gros message
+      CALL getenv('BUFFER_LENGTH',taille_tampon_alphanum)
+  
+      ! Si la variable BUFFER_LENGTH n'est pas positionnee, on lui met par
+      ! defaut la plus grande valeur de la variable MP_EAGER_LIMIT, soit
+      ! 65 536 octets
+      IF (taille_tampon_alphanum == ' ') THEN
+         taille_tampon = 65536
+      ELSE
+         READ(taille_tampon_alphanum,'(i9)') taille_tampon
+      END IF
+
+      ! On est limite en mode d'adressage 32 bits a  1750 Mo pour la zone
+      ! "data" soit 7 segments, c.-a -d. 1750/8 = 210 Mo
+      IF (taille_tampon > 210000000) THEN
+         CALL ctl_stop( ' lib_mpp: Attention la valeur BUFFER_LENGTH doit etre <= 210000000' )
+         CALL mpi_abort(MPI_COMM_WORLD,2,code)
+      END IF
+
+      CALL mpi_comm_rank(MPI_COMM_OPA,rang,code)
+      IF (rang == 0 ) PRINT *,'Taille du buffer alloue : ',taille_tampon
+
+      ! Allocation du tampon et attachement
+      ALLOCATE(tampon(taille_tampon))
+      CALL mpi_buffer_attach(tampon,taille_tampon,code)
+
+   END SUBROUTINE mpi_init_opa
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case:            Dummy module        share memory computing
+   !!----------------------------------------------------------------------
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i
+   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_isl
+      MODULE PROCEDURE mppisl_a_int, mppisl_int, mppisl_a_real, mppisl_real
+   END INTERFACE
+   INTERFACE mppobc
+      MODULE PROCEDURE mppobc_1d, mppobc_2d, mppobc_3d, mppobc_4d
+   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
+
+CONTAINS
+
+   FUNCTION mynode(localComm) RESULT (function_value)
+      INTEGER, OPTIONAL :: localComm
+      function_value = 0
+   END FUNCTION mynode
+
+   SUBROUTINE mppsync                       ! Dummy routine
+   END SUBROUTINE mppsync
+
+   SUBROUTINE mpp_sum_as( parr, kdim )      ! Dummy routine
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mpp_sum_as
+
+   SUBROUTINE mpp_sum_a2s( parr, kdim )      ! Dummy routine
+      REAL   , DIMENSION(:,:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1)
+   END SUBROUTINE mpp_sum_a2s
+
+   SUBROUTINE mpp_sum_ai( karr, kdim )      ! Dummy routine
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mpp_sum_ai
+
+   SUBROUTINE mpp_sum_s( psca )            ! Dummy routine
+      REAL                  :: psca
+      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca
+   END SUBROUTINE mpp_sum_s
+
+   SUBROUTINE mpp_sum_i( kint )            ! Dummy routine
+      integer               :: kint
+      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint
+   END SUBROUTINE mpp_sum_i
+
+   SUBROUTINE mppmax_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppmax_a_real
+
+   SUBROUTINE mppmax_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmin_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppmin_a_real
+
+   SUBROUTINE mppmin_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppmin_real
+
+   SUBROUTINE mppmax_a_int( karr, kdim )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmax_a_int: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mppmax_a_int
+
+   SUBROUTINE mppmax_int( kint )
+      INTEGER               :: kint
+      WRITE(*,*) 'mppmax_int: You should not have seen this print! error?', kint
+   END SUBROUTINE mppmax_int
+
+   SUBROUTINE mppmin_a_int( karr, kdim )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mppmin_a_int
+
+   SUBROUTINE mppmin_int( kint )
+      INTEGER               :: kint
+      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint
+   END SUBROUTINE mppmin_int
+
+   SUBROUTINE mppobc_1d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_1d
+
+   SUBROUTINE mppobc_2d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_2d
+
+   SUBROUTINE mppobc_3d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_3d
+
+   SUBROUTINE mppobc_4d( parr, kd1, kd2, kl, kk, ktype, kij )
+    INTEGER  ::   kd1, kd2, kl , kk, ktype, kij
+    REAL, DIMENSION(:,:,:,:) ::   parr           ! variable array
+      WRITE(*,*) 'mppobc: You should not have seen this print! error?',   &
+         &        parr(1,1,1,1), kd1, kd2, kl, kk, ktype, kij
+   END SUBROUTINE mppobc_4d
+
+
+   SUBROUTINE mpplnks( parr )            ! Dummy routine
+      REAL, DIMENSION(:,:) :: parr
+      WRITE(*,*) 'mpplnks: You should not have seen this print! error?', parr(1,1)
+   END SUBROUTINE mpplnks
+
+   SUBROUTINE mppisl_a_int( karr, kdim )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppisl_a_int: You should not have seen this print! error?', kdim, karr(1)
+   END SUBROUTINE mppisl_a_int
+
+   SUBROUTINE mppisl_int( kint )
+      INTEGER               :: kint
+      WRITE(*,*) 'mppisl_int: You should not have seen this print! error?', kint
+   END SUBROUTINE mppisl_int
+
+   SUBROUTINE mppisl_a_real( parr, kdim )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      WRITE(*,*) 'mppisl_a_real: You should not have seen this print! error?', kdim, parr(1)
+   END SUBROUTINE mppisl_a_real
+
+   SUBROUTINE mppisl_real( psca )
+      REAL                  :: psca
+      WRITE(*,*) 'mppisl_real: You should not have seen this print! error?', psca
+   END SUBROUTINE mppisl_real
+
+   SUBROUTINE mpp_minloc2d ( ptab, pmask, pmin, ki, kj )
+      REAL                   :: pmin
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mppisl_real: You should not have seen this print! error?', pmin, ki, kj
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmin, ki, kj, kk
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmax, ki, kj
+      WRITE(*,*) '   "      ":             "                 "            ', 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(*,*) 'mppisl_real: You should not have seen this print! error?', pmax, ki, kj, kk
+      WRITE(*,*) '   "      ":             "                 "            ', ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_maxloc3d
+
+   SUBROUTINE mppstop
+      WRITE(*,*) 'mppstop: You should not have seen this print! error?'
+   END SUBROUTINE mppstop
+
+#endif
+   !!----------------------------------------------------------------------
+END MODULE lib_mpp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_print.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_print.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/lib_print.f90	(revision 4536)
@@ -0,0 +1,265 @@
+MODULE lib_print
+   !!======================================================================
+   !!                    ***  MODULE  lib_print  ***
+   !! print librairy :  formated real and integer array print
+   !!=====================================================================
+      
+   !!----------------------------------------------------------------------
+   !!   prihin       : print an integer 2D horizontal field
+   !!   prihre       : print an real 2D horizontal field
+   !!   prizre       : print an real 2D vertical field
+   !!----------------------------------------------------------------------
+   !! * Mules used
+   USE par_kind      ! kind parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC prihin, prihre, prizre
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE prihin( ktab, ki   , kj   , kideb, kifin ,   &
+                      kind, kjdeb, kjfin, kjnd , kscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                   ***  SUBROUTINE  prihre  ***
+      !!  
+      !! ** purpose :   Print an integer field
+      !!
+      !! ** method :   format of print is selected with the dummy argument kscale
+      !!
+      !! History :
+      !!        !  90-04 (0. Marti)  Original code
+      !!        !  92-02 (M. Imbard)
+      !!        !  03-07 (G. Madec)  F90, free form
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj,                 &  ! array dimensions
+         kideb, kifin, kind,     &  ! first and last index, increment for i 
+         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
+         kscale,                 &  ! kscale=0 or > 5  print ktab with format i8
+      !                             !         kscale=1 print ktab with format i1
+      !                             !         kscale=2 print ktab with format i2
+      !                             !         kscale=3 print ktab with format i3
+      !                             !         kscale=4 print ktab with format i4
+      !                             !         kscale=5 print ktab with format i5
+         kumout                     ! unit in which print
+      INTEGER, DIMENSION(ki,kj), INTENT( in ) ::   &
+         ktab                       ! integer 2D array to be print
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jn       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+      INTEGER ::   iind, ijnd       ! temporary integers
+
+      isca = 10
+      IF( kscale == 0 )   isca = 10
+      IF( kscale == 1 )   isca = 100
+      IF( kscale == 2 )   isca = 60
+      IF( kscale == 3 )   isca = 40
+      IF( kscale == 4 )   isca = 30
+      IF( kscale == 5 )   isca = 20
+
+      iind = MAX( 1, kind )
+      ijnd = MAX( 1, kjnd )
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
+
+        IF( il1 > kifin ) RETURN
+        WRITE(kumout,'(/)')
+        il2 = il1+iind*(isca-1)
+        IF( il2 > kifin )   il2 = kifin
+
+        IF( kscale == 1 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)') il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,100i1)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 2 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,60i2)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 3 ) THEN
+            WRITE(kumout,'(4x,i14," to ",1i4," each ",1i4,/)')il1, il2, iind
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,40i3)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 4 ) THEN
+            WRITE(kumout,'(4x,30i4,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,30i4)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSEIF( kscale == 5 ) THEN
+            WRITE(kumout,'(4x,20i5,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,20i5)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ELSE
+            WRITE(kumout,'(4x,10i8,/)') ( ji, ji = il1, il2, iind )
+            DO jj = kjfin, kjdeb, -ijnd
+              WRITE (kumout,'(1x,i3,10i8)') jj, ( ktab(ji,jj), ji = il1, il2, iind )
+            END DO  
+        ENDIF
+
+        il1 = il1 + iind * isca
+      END DO  
+
+   END SUBROUTINE prihin
+
+
+   SUBROUTINE prihre( ptab, ki   , kj   , kideb, kifin ,   &
+                      kind, kjdeb, kjfin, kjnd , pscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE prihre  ***
+      !!      
+      !! ** purpose :   Print a real field with the format 10e12.4 or 20f6.2
+      !!
+      !! ** method  :   the print format is selected with the pscale argument
+      !!
+      !! History :
+      !!   1.0  !  86-01  (P. Andrich)  Original code
+      !!        !  89-11  (C. Levy)
+      !!        !  92-02  (M. Imbard)
+      !!        !  92-06  (M. Imbard)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj,                 &  ! array dimensions
+         kideb, kifin, kind,     &  ! first and last index, increment for i
+         kjdeb, kjfin, kjnd,     &  ! first and last index, increment for j
+         kumout                     ! unit in which print
+      REAL(wp), INTENT( in ) ::   &
+         pscale                     ! = 0  print        ptab with e13.5 format
+         !                          ! else print pscale*ptab with f6.2 format
+      REAL(wp), DIMENSION(ki,kj), INTENT( in ) ::   &
+         ptab                       ! integer 2D array to be print
+
+      !! * Local variables
+      INTEGER ::   ji, jj, jn       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+
+      isca = 10
+      IF( pscale /= 0. )   isca=20
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(kind*isca) + 1
+
+        IF( il1 > kifin )   RETURN
+
+        WRITE(kumout,9100)
+
+        il2 = il1+kind*(isca-1)
+        IF(il2 > kifin) il2 = kifin
+        IF( pscale == 0.) THEN
+            WRITE(kumout,9101) ( ji, ji = il1, il2, kind )
+            DO jj = kjfin, kjdeb, -kjnd
+              WRITE(kumout,9102) jj, ( ptab(ji,jj), ji = il1, il2, kind )
+            END DO  
+        ELSE
+            WRITE(kumout,9103) ( ji, ji = il1, il2, kind )
+            DO jj = kjfin, kjdeb, -kjnd
+              WRITE(kumout,9104) jj, ( pscale*ptab(ji,jj), ji = il1, il2, kind )
+            END DO  
+        ENDIF
+        il1 = il1+kind*isca
+
+      END DO  
+
+      ! formats
+ 9100 FORMAT(/)
+ 9101 FORMAT(10i12, /)
+ 9102 FORMAT(1x, i3, 10(1pe12.4))
+ 9103 FORMAT(3x, 20i6, /)
+ 9104 FORMAT(1x, i3, 1x, 20f6.2)
+
+   END SUBROUTINE prihre
+
+
+   SUBROUTINE prizre( ptab , ki   , kj   , kk   , kjcut ,   &
+                      kideb, kifin, kid  , kkdeb, kkfin ,   &
+                      kkd  , pscale, kumout )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE prizre  ***
+      !!
+      !! ** purpose :   Print a vertical slab from a tridimentional real field
+      !!
+      !!   METHOD :
+      !! ** method  :   the print format is selected with the argument pscale
+      !!
+      !! History :
+      !!      original : 86-01 (o. Marti)
+      !!      addition : 92-02 (M. Imbard)
+      !!      addition : 92-06 (M. Imbard)
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   &
+         ki, kj, kk,             &  ! array dimensions
+         kjcut,                  &  ! index j for the vertical slab
+         kideb, kifin, kid,      &  ! first and last index, increment for i
+         kkdeb, kkfin, kkd,      &  ! first and last index, increment for k
+         kumout                     ! unit in which print
+      REAL(wp), INTENT( in ) ::   &
+         pscale                     ! = 0  print        ptab with e12.4 format
+         !                          ! else print pscale*ptab with f6.2 format
+      REAL(wp), DIMENSION(ki,kj,kk), INTENT( in ) ::   &
+         ptab                       ! integer 3D array to be print
+
+      !! * Local variables
+      INTEGER ::   ji, jn, jk       ! dummy loop indices
+      INTEGER ::   isca, il1, il2   ! temporary integers
+      INTEGER ::   iind, iknd       !    "          "
+
+
+      iind = kid
+      iknd = kkd
+      isca = 10
+      IF( pscale /= 0.) isca = 20
+
+      IF (iind == 0) iind = 1
+      IF (iknd == 0) iknd = 1
+
+      il1 = kideb
+
+      DO jn = 1, (kifin-kideb+1)/(iind*isca) + 1
+
+        IF(il1 > kifin) RETURN
+        WRITE(kumout,9100)
+        il2 = il1+iind*(isca-1)
+        IF(il2 > kifin) il2 = kifin
+
+        IF( pscale == 0.) THEN
+            WRITE(kumout,9101) ( ji, ji = il1, il2, iind )
+            DO jk = kkdeb, kkfin, iknd
+              WRITE (kumout,9102) jk, ( ptab(ji,kjcut,jk), ji = il1, il2, iind )
+            END DO  
+        ELSE
+            WRITE (kumout,9103) ( ji, ji = il1, il2, iind )
+            DO jk = kkdeb, kkfin, iknd
+              WRITE(kumout,9104)jk, ( pscale*ptab(ji,kjcut,jk), ji = il1, il2, iind )
+            END DO  
+        ENDIF
+
+        il1 = il1+iind*isca
+      END DO      
+
+ 9100 FORMAT(/)
+ 9101 FORMAT(10i12, /)
+ 9102 FORMAT(1x, i3, 10(1pe12.4))
+ 9103 FORMAT(3x, 20i6, /)
+ 9104 FORMAT(1x, i3, 1x, 20f6.1)
+
+      END SUBROUTINE prizre
+
+   !!======================================================================
+END MODULE lib_print
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/model.f90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/model.f90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/model.f90	(revision 4536)
@@ -0,0 +1,21 @@
+PROGRAM model
+   !!----------------------------------------------------------------------
+   !!                     ***  PROGRAM model  ***
+   !!
+   !! ** Purpose :   encapsulate the opa model so that opa can also be 
+   !!      called together with the adjoint and linear tangent models
+   !!
+   !! History :
+   !!   8.0  !  01-02  (M. Imbard, A. Weaver)  Original code
+   !!   9.0  !  03-10  (G. Madec) F90
+   !!----------------------------------------------------------------------
+   USE opa                  ! OPA system     (opa_model routine)
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+ 
+   CALL opa_model           ! OPA system
+ 
+END PROGRAM model
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/module_example
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/module_example	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/module_example	(revision 4536)
@@ -0,0 +1,211 @@
+MODULE exampl
+   !!======================================================================
+   !!                       ***  MODULE  example  ***
+   !! Ocean physics:  brief description of the purpose of the module
+   !!                 (please no more than 2 lines)
+   !!=====================================================================
+#if defined key_example
+   !!----------------------------------------------------------------------
+   !!   'key_example'  :                brief description of the key option
+   !!----------------------------------------------------------------------
+   !!   exa_mpl      : liste of module subroutine (caution, never use the
+   !!   exa_mpl_init : name of the module for a routine)
+   !!   exa_mpl_stp  : Please try to use 3 letter block for routine names
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE module_name1            ! brief description of the used module
+   USE module_name2            ! ....
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! *  Routine accessibility
+   PUBLIC exa_mpl    ! routine called in xxx.F90 module
+
+   !! * Share Module variables
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+      var1    ,   &  !: var1 description (CAUTION always use !: to describe a 
+      !              !  PUBLIC variable simplify the search of where it is declared
+      var2           !: var2 description
+
+   !! * Module variables
+   INTEGER ::                 & !!! ** toto namelist (namtoto) **
+      nflag  =  1                ! default value of nflag 
+   REAL(wp) ::                & !!! ** toto namlist (namtoto) **
+      var3  = 2._wp / 9._wp      ! default value of var3
+   REAL(wp) ::   &  
+      var4          ! var4 description (local permanent variable)
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+      tab1          ! coefficient used for horizontal smoothing
+
+   !! * Substitutions
+#  include "exampl_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! or LIM 2.0 , UCL-LOCEAN-IPSL (2005)
+   !! or  TOP 1.0 , LOCEAN-IPSL (2005)
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+# if defined key_autotasking
+   !!----------------------------------------------------------------------
+   !!   'key_autotasking'                              autotasking (j-slab)
+   !!----------------------------------------------------------------------
+#  include "exampl_autotsk.h90"
+
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                           vector opt. (k-j-i loop)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE exa_mpl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE exa_mpl  ***
+      !!
+      !! ** Purpose :   Brief description of the routine
+      !!
+      !! ** Method  :   description of the methodoloy used to achieve the
+      !!      objectives of the routine. Be as clear as possible!
+      !!
+      !! ** Action  : - first action (share memory array/varible modified
+      !!                in this routine
+      !!              - second action .....
+      !!              - .....
+      !!
+      !! References :
+      !!   Give references if exist otherwise suppress these lines
+      !!
+      !! History :
+      !!   9.0  !  03-08  (Autor Names)  Original code
+      !!        !  02-08  (Author names)  brief description of modifications
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE toto_module                ! description od the module
+
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   &  
+         kt                          ! describe it!!!
+
+      !! * local declarations
+      INTEGER ::   ji, jj, jk        ! dummy loop arguments
+      INTEGER ::   &
+         itoto, itata,            &  ! temporary integers
+         ititi                       ! please do not forget the DOCTOR rule:
+         !                           ! local integer: name start with i
+      REAL(wp) ::   &
+         zmlmin, zbbrau,          &  ! temporary scalars
+         zfact1, zfact2, zfact3,  &  !    "         "
+         zbn2, zesurf,            &  ! local scalar: name start with z
+         zemxl                       !
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         ztoto                       ! temporary workspace
+      !!--------------------------------------------------------------------
+
+
+
+      IF( kt == nit000  )   CALL exa_mpl_init    ! Initialization (first time-step only)
+
+      ! Local constant initialization
+      zmlmin = 1.e-8
+      zbbrau =  .5 * ebb / rau0
+      zfact1 = -.5 * rdt * efave
+      zfact2 = 1.5 * rdt * ediss
+      zfact3 = 0.5 * rdt * ediss
+
+
+      SELECT CASE ( npdl )
+
+      CASE ( 0 )           ! describe case 1
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmv(ji,jj,jk) = ....
+               END DO
+            END DO
+         END DO
+
+      CASE ( 1 )           ! describe case 2
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  avmv(ji,jj,jk) = ...
+               END DO
+            END DO
+         END DO
+
+      END SELECT
+
+      ! Lateral boundary conditions (avmu)   (unchanged sign)
+      CALL mpplnk2( avmu, 'U', 1. )
+
+   END SUBROUTINE exa_mpl
+
+# endif
+
+   SUBROUTINE exa_mpl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE exa_mpl_init  ***
+      !!                   
+      !! ** Purpose :   initialization of ....
+      !!
+      !! ** Method  :   blah blah blah ...
+      !!
+      !! ** input   :   Namlist namexa
+      !!
+      !! ** Action  :   ...  
+      !!
+      !! history :
+      !!   9.0  !  03-08  (Autor Names)  Original code
+      !!----------------------------------------------------------------------
+      !! * local declarations
+      INTEGER ::   ji, jj, jk, jit   ! dummy loop indices
+
+      NAMELIST/namexa/ exa_v1, exa_v2, nexa_0  
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist namexa : example parameters
+      REWIND ( numnam )
+      READ   ( numnam, namexa )
+
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'exa_mpl_init : example '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namexa : set example parameters'
+         WRITE(numout,*) '             brief desciption               exa_v1  = ', exa_v1
+         WRITE(numout,*) '             brief desciption               exa_v1  = ', exa_v1
+         WRITE(numout,*) '             brief desciption               nexa_0  = ', nexa_0
+      ENDIF
+
+      ! Parameter control
+#if defined key_toto
+      IF(lwp) WRITE(numout,cform_err)
+      IF(lwp) WRITE(numout,*) '          this part and key_toto are incompatible'
+      nstop = nstop + 1
+#endif
+
+      ! Check nexa_0 values
+      IF( nexa_0 < 0 ) THEN
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag: nmxl is < 0 or > 3 '
+         nstop = nstop + 1
+      ENDIF
+
+   END SUBROUTINE exa_mpl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE exa_mpl              ! Empty routine
+   END SUBROUTINE exa_mpl
+#endif
+
+   !!======================================================================
+END MODULE exampl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini.F90	(revision 4536)
@@ -0,0 +1,554 @@
+MODULE mppini
+   !!==============================================================================
+   !!                       ***  MODULE mppini   ***
+   !! Ocean initialization : distributed memory computing initialization
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   mpp_init       : Lay out the global domain over processors
+   !!   mpp_init2      : Lay out the global domain over processors 
+   !!                    with land processor elimination
+   !!   mpp_init_ioispl: IOIPSL initialization in mpp
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE dom_oce         ! ocean space and time domain 
+   USE in_out_manager  ! I/O Manager
+   USE sol_oce         ! ocean elliptic solver
+   USE lib_mpp         ! distribued memory computing library
+   USE ioipsl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC mpp_init       ! called by opa.F90
+   PUBLIC mpp_init2      ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if ! defined key_mpp_mpi   &&   ! defined key_mpp_shmem
+   !!----------------------------------------------------------------------
+   !!   Default option :                            shared memory computing
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE mpp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init  ***
+      !!
+      !! ** Purpose :   Lay out the global domain over processors.
+      !!
+      !! ** Method  :   Shared memory computing, set the local processor
+      !!      variables to the value of the global domain
+      !!
+      !! History :
+      !!   9.0  !  04-01  (G. Madec, J.M. Molines)  F90 : free form, north fold jpni >1
+      !!----------------------------------------------------------------------
+
+      ! No mpp computation
+      nimpp  = 1
+      njmpp  = 1
+      nlci   = jpi
+      nlcj   = jpj
+      nldi   = 1
+      nldj   = 1
+      nlei   = jpi
+      nlej   = jpj
+      nperio = jperio
+      nbondi = 2
+      nbondj = 2
+      nidom  = FLIO_DOM_NONE
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'mpp_init(2) : NO massively parallel processing'
+         WRITE(numout,*) '~~~~~~~~~~~: '
+         WRITE(numout,*) '         nperio = ', nperio
+         WRITE(numout,*) '         npolj  = ', npolj
+         WRITE(numout,*) '         nimpp  = ', nimpp
+         WRITE(numout,*) '         njmpp  = ', njmpp
+      ENDIF
+
+      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 ) &
+          CALL ctl_stop( 'equality  jpni = jpnj = jpnij = 1 is not satisfied',   &
+          &              'the domain is lay out for distributed memory computing! ' )
+
+   END SUBROUTINE mpp_init
+
+
+   SUBROUTINE mpp_init2 
+      CALL mpp_init                             ! same routine as mpp_init
+   END SUBROUTINE mpp_init2
+
+#else
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'          OR         MPI massively parallel processing
+   !!   'key_mpp_shmem'                 SHMEM massively parallel processing
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE mpp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init  ***
+      !!                    
+      !! ** Purpose :   Lay out the global domain over processors.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!      Periodic condition is a function of the local domain position
+      !!      (global boundary or neighbouring domain) and of the global
+      !!      periodic
+      !!      Type :         jperio global periodic condition
+      !!                     nperio local  periodic condition
+      !!
+      !! ** Action  : - set domain parameters
+      !!                    nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlci      : first dimension
+      !!                    nlcj      : second dimension
+      !!                    nbondi    : mark for "east-west local boundary"
+      !!                    nbondj    : mark for "north-south local boundary"
+      !!                    nproc     : number for local processor
+      !!                    noea      : number for local neighboring processor
+      !!                    nowe      : number for local neighboring processor
+      !!                    noso      : number for local neighboring processor
+      !!                    nono      : number for local neighboring processor
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      CHARACTER (len=32) ::   clname
+      INTEGER ::   ji, jj, jn               ! dummy loop indices
+      INTEGER ::   &
+         ii, ij, ifreq, il1, il2,        &  ! temporary integers
+         iresti, irestj, ijm1, imil,     &  !    "          "
+         inum                               ! temporary logical unit
+
+      INTEGER, DIMENSION(jpni,jpnj) ::   &
+         iimppt, ijmppt, ilcit, ilcjt       ! temporary workspace
+      REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      !!----------------------------------------------------------------------
+
+#if defined key_mpp_shmem
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing PVM T3E + SHMEM'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+
+      CALL mppshmem                           ! Initialisation of shmem array
+
+#endif
+#if defined key_mpp_mpi
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing MPI'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+#endif
+
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+      !  Computation of local domain sizes ilcit() ilcjt()
+      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array (cf. par_oce.F90).
+      
+      nreci  = 2 * jpreci
+      nrecj  = 2 * jprecj
+      iresti = MOD( jpiglo - nreci , jpni )
+      irestj = MOD( jpjglo - nrecj , jpnj )
+
+      IF(  iresti == 0 )   iresti = jpni
+      DO jj = 1, jpnj
+         DO ji = 1, iresti
+            ilcit(ji,jj) = jpi
+         END DO
+         DO ji = iresti+1, jpni
+            ilcit(ji,jj) = jpi -1
+         END DO
+      END DO
+      
+      IF( irestj == 0 )   irestj = jpnj
+      DO ji = 1, jpni
+         DO jj = 1, irestj
+            ilcjt(ji,jj) = jpj
+         END DO
+         DO jj = irestj+1, jpnj
+            ilcjt(ji,jj) = jpj -1
+         END DO
+      END DO
+      
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           defines mpp subdomains'
+         WRITE(numout,*) '           ----------------------'
+         WRITE(numout,*) '           iresti=',iresti,' irestj=',irestj
+         WRITE(numout,*) '           jpni  =',jpni  ,' jpnj  =',jpnj
+         ifreq = 4
+         il1   = 1
+         DO jn = 1, (jpni-1)/ifreq+1
+            il2 = MIN( jpni, il1+ifreq-1 )
+            WRITE(numout,*)
+            WRITE(numout,9200) ('***',ji = il1,il2-1)
+            DO jj = jpnj, 1, -1
+               WRITE(numout,9203) ('   ',ji = il1,il2-1)
+               WRITE(numout,9202) jj, ( ilcit(ji,jj),ilcjt(ji,jj),ji = il1,il2 )
+               WRITE(numout,9203) ('   ',ji = il1,il2-1)
+               WRITE(numout,9200) ('***',ji = il1,il2-1)
+            END DO
+            WRITE(numout,9201) (ji,ji = il1,il2)
+            il1 = il1+ifreq
+         END DO
+ 9200    FORMAT('     ***',20('*************',a3))
+ 9203    FORMAT('     *     ',20('         *   ',a3))
+ 9201    FORMAT('        ',20('   ',i3,'          '))
+ 9202    FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+      ENDIF
+
+      zidom = nreci
+      DO ji = 1, jpni
+         zidom = zidom + ilcit(ji,1) - nreci
+      END DO
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilcit(i,1) = ', zidom, ' jpiglo = ', jpiglo
+      
+      zjdom = nrecj
+      DO jj = 1, jpnj
+         zjdom = zjdom + ilcjt(1,jj) - nrecj
+      END DO
+      IF(lwp) WRITE(numout,*)' sum ilcit(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      IF(lwp) WRITE(numout,*)
+      
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+      
+      iimppt(:,:) = 1
+      ijmppt(:,:) = 1
+      
+      IF( jpni > 1 ) THEN
+         DO jj = 1, jpnj
+            DO ji = 2, jpni
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilcit(ji-1,jj) - nreci
+            END DO
+         END DO
+      ENDIF
+
+      IF( jpnj > 1 ) THEN
+         DO jj = 2, jpnj
+            DO ji = 1, jpni
+               ijmppt(ji,jj) = ijmppt(ji,jj-1)+ilcjt(ji,jj-1)-nrecj
+            END DO
+         END DO
+      ENDIF
+      
+      ! 3. Subdomain description
+      ! ------------------------
+
+      DO jn = 1, jpnij
+         ii = 1 + MOD( jn-1, jpni )
+         ij = 1 + (jn-1) / jpni
+         nimppt(jn) = iimppt(ii,ij)
+         njmppt(jn) = ijmppt(ii,ij)
+         nlcit (jn) = ilcit (ii,ij)     
+         nlci       = nlcit (jn)     
+         nlcjt (jn) = ilcjt (ii,ij)     
+         nlcj       = nlcjt (jn)
+         nbondj = -1                                   ! general case
+         IF( jn   >  jpni          )   nbondj = 0      ! first row of processor
+         IF( jn   >  (jpnj-1)*jpni )   nbondj = 1      ! last  row of processor
+         IF( jpnj == 1             )   nbondj = 2      ! one processor only in j-direction
+         ibonjt(jn) = nbondj
+         
+         nbondi = 0                                    ! 
+         IF( MOD( jn, jpni ) == 1 )   nbondi = -1      !
+         IF( MOD( jn, jpni ) == 0 )   nbondi =  1      !
+         IF( jpni            == 1 )   nbondi =  2      ! one processor only in i-direction
+         ibonit(jn) = nbondi
+         
+         nldi =  1   + jpreci
+         nlei = nlci - jpreci
+         IF( nbondi == -1 .OR. nbondi == 2 )   nldi = 1
+         IF( nbondi ==  1 .OR. nbondi == 2 )   nlei = nlci
+         nldj =  1   + jprecj
+         nlej = nlcj - jprecj
+         IF( nbondj == -1 .OR. nbondj == 2 )   nldj = 1
+         IF( nbondj ==  1 .OR. nbondj == 2 )   nlej = nlcj
+         nldit(jn) = nldi
+         nleit(jn) = nlei
+         nldjt(jn) = nldj
+         nlejt(jn) = nlej
+      END DO
+      
+
+      ! 4. From global to local
+      ! -----------------------
+
+      nperio = 0
+      IF( jperio == 2 .AND. nbondj == -1 )   nperio = 2
+
+
+      ! 5. Subdomain neighbours
+      ! ----------------------
+
+      nproc = narea - 1
+      noso  = nproc - jpni
+      nowe  = nproc - 1
+      noea  = nproc + 1
+      nono  = nproc + jpni
+      ! great neighbours
+      npnw = nono - 1
+      npne = nono + 1
+      npsw = noso - 1
+      npse = noso + 1
+      nbsw = 1
+      nbnw = 1
+      IF( MOD( nproc, jpni ) == 0 ) THEN
+         nbsw = 0
+         nbnw = 0
+      ENDIF
+      nbse = 1
+      nbne = 1
+      IF( MOD( nproc, jpni ) == jpni-1 ) THEN
+         nbse = 0
+         nbne = 0
+      ENDIF
+      IF(nproc < jpni) THEN
+         nbsw = 0
+         nbse = 0
+      ENDIF
+      IF( nproc >= (jpnj-1)*jpni ) THEN
+         nbnw = 0
+         nbne = 0
+      ENDIF
+      nlcj = nlcjt(narea)  
+      nlci = nlcit(narea)  
+      nldi = nldit(narea)
+      nlei = nleit(narea)
+      nldj = nldjt(narea)
+      nlej = nlejt(narea)
+      nbondi = ibonit(narea)
+      nbondj = ibonjt(narea)
+      nimpp  = nimppt(narea)  
+      njmpp  = njmppt(narea)  
+
+     ! Save processor layout in layout.dat file 
+       IF (lwp) THEN
+        clname = 'layout.dat'
+        CALL ctlopn( inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+           &         1, numout, .FALSE., 1 )
+        WRITE(inum,'(a)') '   jpnij     jpi     jpj     jpk  jpiglo  jpjglo'
+        WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
+        WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
+
+        DO  jn = 1, jpnij
+         WRITE(inum,'(9i5)') jn, nlcit(jn), nlcjt(jn), &
+                                      nldit(jn), nldjt(jn), &
+                                      nleit(jn), nlejt(jn), &
+                                      nimppt(jn), njmppt(jn)
+        END DO
+        CLOSE(inum)   
+      END IF
+
+
+      ! w a r n i n g  narea (zone) /= nproc (processors)!
+
+      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+         IF( jpni == 1 )THEN
+            nbondi = 2
+            nperio = 1
+         ELSE
+            nbondi = 0
+         ENDIF
+         IF( MOD( narea, jpni ) == 0 ) THEN
+            noea = nproc-(jpni-1)
+            npne = npne-jpni
+            npse = npse-jpni
+         ENDIF
+         IF( MOD( narea, jpni ) == 1 ) THEN
+            nowe = nproc+(jpni-1)
+            npnw = npnw+jpni
+            npsw = npsw+jpni
+         ENDIF
+         nbsw = 1
+         nbnw = 1
+         nbse = 1
+         nbne = 1
+         IF( nproc < jpni ) THEN
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         IF( nproc >= (jpnj-1)*jpni ) THEN
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+      npolj = 0
+      IF( jperio == 3 .OR. jperio == 4 ) THEN
+         ijm1 = jpni*(jpnj-1)
+         imil = ijm1+(jpni+1)/2
+         IF( narea > ijm1 ) npolj = 3
+         IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 4
+         IF( npolj == 3 ) nono = jpni*jpnj-narea+ijm1
+      ENDIF
+      IF( jperio == 5 .OR. jperio == 6 ) THEN
+          ijm1 = jpni*(jpnj-1)
+          imil = ijm1+(jpni+1)/2
+          IF( narea > ijm1) npolj = 5
+          IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 6
+          IF( npolj == 5 ) nono = jpni*jpnj-narea+ijm1
+      ENDIF
+
+      ! FETI method
+
+      IF( nperio == 1 .AND. nsolv == 3 ) THEN 
+         
+         ! general case : Earth == infinite tube
+         
+         nbnw = 1
+         npnw = narea
+         nbne = 1
+         npne = narea
+         nbsw = 1
+         npsw = (narea-2)
+         nbse = 1
+         npse = (narea-2)
+         
+         ! REAL boundary condition
+         
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+         
+         IF( nbondj == 1  .OR. nbondj == 2 ) THEN 
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+
+      ! Periodicity : no corner if nbondi = 2 and nperio != 1
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' nproc  = ', nproc
+         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
+         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
+         WRITE(numout,*) ' nbondi = ', nbondi
+         WRITE(numout,*) ' nbondj = ', nbondj
+         WRITE(numout,*) ' npolj  = ', npolj
+         WRITE(numout,*) ' nperio = ', nperio
+         WRITE(numout,*) ' nlci   = ', nlci
+         WRITE(numout,*) ' nlcj   = ', nlcj
+         WRITE(numout,*) ' nimpp  = ', nimpp
+         WRITE(numout,*) ' njmpp  = ', njmpp
+         WRITE(numout,*) ' nbse   = ', nbse  , ' npse   = ', npse
+         WRITE(numout,*) ' nbsw   = ', nbsw  , ' npsw   = ', npsw
+         WRITE(numout,*) ' nbne   = ', nbne  , ' npne   = ', npne
+         WRITE(numout,*) ' nbnw   = ', nbnw  , ' npnw   = ', npnw
+      ENDIF
+
+      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init: error on cyclicity' )
+
+      ! Prepare mpp north fold
+
+      IF (jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
+         CALL mpp_ini_north
+      END IF
+
+      ! Prepare NetCDF output file (if necessary)
+      CALL mpp_init_ioipsl
+
+   END SUBROUTINE mpp_init
+
+#  include "mppini_2.h90"
+
+# if defined key_dimgout
+   !!----------------------------------------------------------------------
+   !!   'key_dimgout'                  NO use of NetCDF files
+   !!----------------------------------------------------------------------
+   SUBROUTINE mpp_init_ioipsl       ! Dummy routine
+   END SUBROUTINE mpp_init_ioipsl  
+# else
+   SUBROUTINE mpp_init_ioipsl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init_ioipsl  ***
+      !!
+      !! ** Purpose :   
+      !!
+      !! ** Method  :   
+      !!
+      !! History :
+      !!   9.0  !  04-03  (G. Madec)  MPP-IOIPSL 
+      !!----------------------------------------------------------------------
+      !! Local declarations
+
+      INTEGER, DIMENSION(2) ::   &
+         iglo, iloc, iabsf, iabsl, ihals, ihale, idid
+      INTEGER ::   &
+         inbondi, inbondj
+      !!----------------------------------------------------------------------
+
+      ! The domain is splitted only horizontally along i- or/and j- direction
+      ! So we need at the most only 1D arrays with 2 elements
+      iglo(1) = jpiglo
+      iglo(2) = jpjglo
+      iloc(1) = nlci
+      iloc(2) = nlcj
+      iabsf(1) = nimppt(narea)
+      iabsf(2) = njmppt(narea)
+      iabsl(:) = iabsf(:) + iloc(:) - 1
+      ihals(1) = jpreci
+      ihals(2) = jprecj
+      ihale(1) = jpreci
+      ihale(2) = jprecj
+      idid(1) = 1
+      idid(2) = 2
+
+      inbondj = -1                                   ! general case
+      IF( narea   >  jpni          )   inbondj = 0      ! first row of processor
+      IF( narea   >  (jpnj-1)*jpni )   inbondj = 1      ! last  row of processor
+      IF( jpnj    == 1             )   inbondj = 2      ! one processor only in j-direction
+      IF( inbondj == -1 .OR. inbondj == 2 )   ihals(2) = 0
+      IF( inbondj ==  1 .OR. inbondj == 2 )   ihale(2) = 0
+         
+      inbondi = 0                                    ! 
+      IF( MOD( narea, jpni ) == 1 )   inbondi = -1      !
+      IF( MOD( narea, jpni ) == 0 )   inbondi =  1      !
+      IF( jpni               == 1 )   inbondi =  2      ! one processor only in i-direction
+      IF( inbondi == -1 .OR. inbondi == 2 )   ihals(1) = 0
+      IF( inbondi ==  1 .OR. inbondi == 2 )   ihale(1) = 0
+
+
+      IF(lwp) THEN
+          WRITE(numout,*)
+          WRITE(numout,*) 'mpp_init_ioipsl :   iloc  = ', iloc (1), iloc (2)
+          WRITE(numout,*) '~~~~~~~~~~~~~~~     iabsf = ', iabsf(1), iabsf(2)
+          WRITE(numout,*) '                    ihals = ', ihals(1), ihals(2)
+          WRITE(numout,*) '                    ihale = ', ihale(1), ihale(2)
+      ENDIF
+
+      CALL flio_dom_set ( jpnij, nproc, idid, iglo, iloc, iabsf, iabsl, ihals, ihale, 'BOX', nidom)
+
+   END SUBROUTINE mpp_init_ioipsl  
+
+# endif
+#endif
+
+   !!======================================================================
+END MODULE mppini
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini_2.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini_2.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/mppini_2.h90	(revision 4536)
@@ -0,0 +1,576 @@
+   SUBROUTINE mpp_init2
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init2  ***
+      !!
+      !! * Purpose :   Lay out the global domain over processors.
+      !!     FOR USING THIS VERSION, A PREPROCESSING TRAITMENT IS RECOMMENDED
+      !!     FOR DEFINING BETTER CUTTING OUT.
+      !!       This routine is used with a the bathymetry file.
+      !!       In this version, the land processors are avoided and the adress
+      !!     processor (nproc, narea,noea, ...) are calculated again.
+      !!     The jpnij parameter can be lesser than jpni x jpnj
+      !!     and this jpnij parameter must be calculated before with an
+      !!     algoritmic preprocessing program.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!      Periodic condition is a function of the local domain position
+      !!      (global boundary or neighbouring domain) and of the global
+      !!      periodic
+      !!      Type :         jperio global periodic condition
+      !!                     nperio local  periodic condition
+      !!
+      !! ** Action :        nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlci      : first dimension
+      !!                    nlcj      : second dimension
+      !!                    nproc     : number for local processor
+      !!                    noea      : number for local neighboring processor
+      !!                    nowe      : number for local neighboring processor
+      !!                    noso      : number for local neighboring processor
+      !!                    nono      : number for local neighboring processor
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   9.0  !  04-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+   
+      !! Local variables
+      CHARACTER (len=32) :: clname
+      INTEGER :: ji, jj, jn, jproc, jarea     ! dummy loop indices
+      INTEGER ::  inum                        ! temporary logical unit
+      INTEGER ::   &
+         ii, ij, ifreq, il1, il2,          &  ! temporary integers
+         icont, ili, ilj,                  &  !    "          "
+         isurf, ijm1, imil,                &  !    "          "
+         iino, ijno, iiso, ijso,           &  !    "          " 
+         iiea, ijea, iiwe, ijwe,           &  !    "          "
+         iinw, ijnw, iine, ijne,           &  !    "          "
+         iisw, ijsw, iise, ijse,           &  !    "          "
+         iresti, irestj, iproc                !    "          "
+      INTEGER, DIMENSION(jpnij) ::   &
+         iin, ijn          
+      INTEGER, DIMENSION(jpni,jpnj) ::   &
+         iimppt, ijmppt, ilci  , ilcj  ,   &  ! temporary workspace
+         ipproc, ibondj, ibondi, ipolj ,   &  !    "           "
+         ilei  , ilej  , ildi  , ildj  ,   &  !    "           "
+         ioea  , iowe  , ioso  , iono  ,   &  !    "           "
+         ione  , ionw  , iose  , iosw  ,   &  !    "           "
+         ibne  , ibnw  , ibse  , ibsw         !    "           "
+      INTEGER,  DIMENSION(jpiglo,jpjglo) ::   &
+         imask                                ! temporary global workspace
+      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   &
+         zdta                   ! temporary data workspace
+      REAL(wp) ::   zidom , zjdom          ! temporary scalars
+
+      ! read namelist for ln_zco
+      NAMELIST/nam_zgr/ ln_zco, ln_zps, ln_sco
+
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/mppini_2.h90,v 1.17 2007/06/29 17:00:01 opalod Exp $ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+      ! Read Namelist nam_zgr : vertical coordinate'
+      ! ---------------------
+      REWIND ( numnam )
+      READ   ( numnam, nam_zgr )
+
+
+#if defined key_mpp_shmem
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'mpp_init : Message Passing PVM T3E + SHMEM'
+      IF(lwp)WRITE(numout,*) '~~~~~~~~'
+      IF(lwp)WRITE(numout,*) ' '
+
+      CALL mppshmem     ! Initialisation of shmem array
+
+#endif
+#if defined key_mpp_mpi
+      IF(lwp)WRITE(numout,*)
+      IF(lwp)WRITE(numout,*) 'mpp_init : Message Passing MPI'
+      IF(lwp)WRITE(numout,*) '~~~~~~~~'
+      IF(lwp)WRITE(numout,*) ' '
+#endif
+
+      IF( jpni*jpnj < jpnij ) CALL ctl_stop( ' jpnij > jpni x jpnj impossible' )
+
+      ! 0. initialisation
+      ! -----------------
+
+      ! open the file
+      ! Remember that at this level in the code, mpp is not yet initialized, so
+      ! the file must be open with jpdom_unknown, and kstart amd kcount forced 
+      IF ( ln_zco ) THEN 
+         CALL iom_open ( 'bathy_level.nc', inum )   ! Level bathymetry
+         CALL iom_get ( inum, jpdom_unknown, 'Bathy_level', zdta, kstart=(/jpizoom,jpjzoom/), kcount=(/jpiglo,jpjglo/) )
+      ELSE
+         CALL iom_open ( 'bathy_meter.nc', inum )   ! Meter bathy in case of partial steps
+         CALL iom_get ( inum, jpdom_unknown, 'Bathymetry' , zdta, kstart=(/jpizoom,jpjzoom/), kcount=(/jpiglo,jpjglo/) )
+      ENDIF
+      CALL iom_close (inum)
+
+      ! land/sea mask over the global/zoom domain
+
+      imask(:,:)=1
+      WHERE ( zdta(:,:) <= 0. ) imask = 0
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+
+      !  Computation of local domain sizes ilci() ilcj()
+      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array.
+
+      nreci=2*jpreci
+      nrecj=2*jprecj
+      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
+      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
+
+      ilci(1:iresti      ,:) = jpi
+      ilci(iresti+1:jpni ,:) = jpi-1
+
+      ilcj(:,      1:irestj) = jpj
+      ilcj(:, irestj+1:jpnj) = jpj-1
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~  ----------------------'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'iresti=',iresti,' irestj=',irestj
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'jpni=',jpni,' jpnj=',jpnj
+
+      zidom = nreci + sum(ilci(:,1) - nreci ) 
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilci(i,1)=',zidom,' jpiglo=',jpiglo
+
+      zjdom = nrecj + sum(ilcj(1,:) - nrecj ) 
+      IF(lwp) WRITE(numout,*) ' sum ilcj(1,j)=',zjdom,' jpjglo=',jpjglo
+      IF(lwp) WRITE(numout,*)
+
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+
+      iimppt(:,:) = 1
+      ijmppt(:,:) = 1
+      ipproc(:,:) = -1
+
+      IF( jpni > 1 )THEN
+         DO jj = 1, jpnj
+            DO ji = 2, jpni
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
+            END DO
+         END DO
+      ENDIF
+
+      IF( jpnj > 1 )THEN
+         DO jj = 2, jpnj
+            DO ji = 1, jpni
+               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
+            END DO
+         END DO
+      ENDIF
+
+
+      ! 3. Subdomain description in the Regular Case
+      ! --------------------------------------------
+
+      nperio = 0
+      icont = -1
+      DO jarea = 1, jpni*jpnj
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         ili = ilci(ii,ij)
+         ilj = ilcj(ii,ij)
+
+         ibondj(ii,ij) = -1
+         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
+         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
+         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
+
+         ibondi(ii,ij) = 0
+         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
+         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
+         IF( jpni            == 1 )   ibondi(ii,ij) =  2
+
+         ! 2.4 Subdomain neighbors
+
+         iproc = jarea - 1
+         ioso(ii,ij) = iproc - jpni
+         iowe(ii,ij) = iproc - 1
+         ioea(ii,ij) = iproc + 1
+         iono(ii,ij) = iproc + jpni
+         ildi(ii,ij) = 1 + jpreci
+         ilei(ii,ij) = ili -jpreci
+         ionw(ii,ij) = iono(ii,ij) - 1
+         ione(ii,ij) = iono(ii,ij) + 1
+         iosw(ii,ij) = ioso(ii,ij) - 1
+         iose(ii,ij) = ioso(ii,ij) + 1
+         ibsw(ii,ij) = 1
+         ibnw(ii,ij) = 1
+         IF( MOD(iproc,jpni) == 0 ) THEN
+            ibsw(ii,ij) = 0
+            ibnw(ii,ij) = 0
+         ENDIF
+         ibse(ii,ij) = 1
+         ibne(ii,ij) = 1
+         IF( MOD(iproc,jpni) == jpni-1 ) THEN
+            ibse(ii,ij) = 0
+            ibne(ii,ij) = 0
+         ENDIF
+         IF( iproc < jpni ) THEN
+            ibsw(ii,ij) = 0
+            ibse(ii,ij) = 0
+         ENDIF
+         IF( iproc >= (jpnj-1)*jpni ) THEN
+            ibnw(ii,ij) = 0
+            ibne(ii,ij) = 0
+         ENDIF
+         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) = 1
+         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
+         ildj(ii,ij) =  1  + jprecj
+         ilej(ii,ij) = ilj - jprecj
+         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) = 1
+         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
+
+         ! warning ii*ij (zone) /= nproc (processors)!
+
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+            IF( jpni == 1 )THEN
+               ibondi(ii,ij) = 2
+               nperio = 1
+            ELSE
+               ibondi(ii,ij) = 0
+            ENDIF
+            IF( MOD(jarea,jpni) == 0 ) THEN
+               ioea(ii,ij) = iproc - (jpni-1)
+               ione(ii,ij) = ione(ii,ij) - jpni
+               iose(ii,ij) = iose(ii,ij) - jpni
+            ENDIF
+            IF( MOD(jarea,jpni) == 1 ) THEN
+               iowe(ii,ij) = iproc + jpni - 1
+               ionw(ii,ij) = ionw(ii,ij) + jpni
+               iosw(ii,ij) = iosw(ii,ij) + jpni 
+            ENDIF
+            ibsw(ii,ij) = 1
+            ibnw(ii,ij) = 1
+            ibse(ii,ij) = 1
+            ibne(ii,ij) = 1
+            IF( iproc < jpni ) THEN
+               ibsw(ii,ij) = 0
+               ibse(ii,ij) = 0
+            ENDIF
+            IF( iproc >= (jpnj-1)*jpni ) THEN
+               ibnw(ii,ij) = 0
+               ibne(ii,ij) = 0
+            ENDIF
+         ENDIF
+         ipolj(ii,ij) = 0
+         IF( jperio == 3 .OR. jperio == 4 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
+            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1
+         ENDIF
+         IF( jperio == 5 .OR. jperio == 6 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1) ipolj(ii,ij) = 5
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
+            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1
+         ENDIF
+
+         isurf = 0
+         DO jj = 1+jprecj, ilj-jprecj
+            DO  ji = 1+jpreci, ili-jpreci
+               IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1) isurf = isurf+1
+            END DO
+         END DO
+         IF(isurf /= 0) THEN
+            icont = icont + 1
+            ipproc(ii,ij) = icont
+            iin(icont+1) = ii
+            ijn(icont+1) = ij
+         ENDIF
+      END DO
+
+      ! Control
+      IF(icont+1 /= jpnij) THEN
+         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
+         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
+         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
+         CALL ctl_stop( ' Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
+      ENDIF
+
+      ! 4. Subdomain print
+      ! ------------------
+
+      IF(lwp) THEN
+         ifreq = 4
+         il1 = 1
+         DO jn = 1,(jpni-1)/ifreq+1
+            il2 = MIN(jpni,il1+ifreq-1)
+            WRITE(numout,*)
+            WRITE(numout,9400) ('***',ji=il1,il2-1)
+            DO jj = jpnj, 1, -1
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
+               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9400) ('***',ji=il1,il2-1)
+            END DO
+            WRITE(numout,9401) (ji,ji=il1,il2)
+            il1 = il1+ifreq
+         END DO
+ 9400     FORMAT('     ***',20('*************',a3))
+ 9403     FORMAT('     *     ',20('         *   ',a3))
+ 9401     FORMAT('        ',20('   ',i3,'          '))
+ 9402     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+ 9404     FORMAT('     *  ',20('      ',i3,'   *   '))
+      ENDIF
+
+
+      ! 5. neighbour treatment
+      ! ----------------------
+
+      DO jarea = 1, jpni*jpnj
+         iproc = jarea-1
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         IF( ipproc(ii,ij) == -1 .AND. iono(ii,ij) >= 0   &
+            .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
+            iino = 1 + MOD(iono(ii,ij),jpni)
+            ijno = 1 +    (iono(ii,ij))/jpni
+            IF( ibondj(iino,ijno) == 1 ) ibondj(iino,ijno)=2
+            IF( ibondj(iino,ijno) == 0 ) ibondj(iino,ijno) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ioso(ii,ij) >= 0   &
+            .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiso = 1 + MOD(ioso(ii,ij),jpni)
+            ijso = 1 +    (ioso(ii,ij))/jpni
+            IF( ibondj(iiso,ijso) == -1 ) ibondj(iiso,ijso) = 2
+            IF( ibondj(iiso,ijso) ==  0 ) ibondj(iiso,ijso) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ioea(ii,ij) >= 0   &
+            .AND. ioea(ii,ij) <= jpni*jpnj-1) THEN
+            iiea = 1 + MOD(ioea(ii,ij),jpni)
+            ijea = 1 +    (ioea(ii,ij))/jpni
+            IF( ibondi(iiea,ijea) == 1 ) ibondi(iiea,ijea) = 2
+            IF( ibondi(iiea,ijea) == 0 ) ibondi(iiea,ijea) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. iowe(ii,ij) >= 0   &
+            .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
+            iiwe = 1 + MOD(iowe(ii,ij),jpni)
+            ijwe = 1 +    (iowe(ii,ij))/jpni
+            IF( ibondi(iiwe,ijwe) == -1 ) ibondi(iiwe,ijwe) = 2
+            IF( ibondi(iiwe,ijwe) ==  0 ) ibondi(iiwe,ijwe) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibne(ii,ij) == 1 ) THEN
+            iine = 1 + MOD(ione(ii,ij),jpni)
+            ijne = 1 +    (ione(ii,ij))/jpni
+            IF( ibsw(iine,ijne) == 1 ) ibsw(iine,ijne) = 0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibsw(ii,ij) == 1 ) THEN
+            iisw = 1 + MOD(iosw(ii,ij),jpni)
+            ijsw = 1 +    (iosw(ii,ij))/jpni
+            IF( ibne(iisw,ijsw) == 1 ) ibne(iisw,ijsw) = 0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibnw(ii,ij) == 1 ) THEN
+            iinw = 1 + MOD(ionw(ii,ij),jpni)
+            ijnw = 1 +    (ionw(ii,ij))/jpni
+            IF( ibse(iinw,ijnw) == 1 ) ibse(iinw,ijnw)=0
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. ibse(ii,ij) == 1 ) THEN
+            iise = 1 + MOD(iose(ii,ij),jpni)
+            ijse = 1 +    (iose(ii,ij))/jpni
+            IF( ibnw(iise,ijse) == 1 ) ibnw(iise,ijse) = 0
+         ENDIF
+      END DO
+
+
+      ! 6. Change processor name
+      ! ------------------------
+
+      nproc = narea-1
+      ii = iin(narea)
+      ij = ijn(narea)
+      IF( ioso(ii,ij) >= 0 .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiso = 1 + MOD(ioso(ii,ij),jpni)
+         ijso = 1 +    (ioso(ii,ij))/jpni
+         noso = ipproc(iiso,ijso)
+      ENDIF
+      IF( iowe(ii,ij) >= 0 .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiwe = 1 + MOD(iowe(ii,ij),jpni)
+         ijwe = 1 +    (iowe(ii,ij))/jpni
+         nowe = ipproc(iiwe,ijwe)
+      ENDIF
+      IF( ioea(ii,ij) >= 0 .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iiea = 1 + MOD(ioea(ii,ij),jpni)
+         ijea = 1 +    (ioea(ii,ij))/jpni
+         noea = ipproc(iiea,ijea)
+      ENDIF
+      IF( iono(ii,ij) >= 0 .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iino = 1 + MOD(iono(ii,ij),jpni)
+         ijno = 1 +    (iono(ii,ij))/jpni
+         nono = ipproc(iino,ijno)
+      ENDIF
+      IF( iose(ii,ij) >= 0 .AND. iose(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iise = 1 + MOD(iose(ii,ij),jpni)
+         ijse = 1 +    (iose(ii,ij))/jpni
+         npse = ipproc(iise,ijse)
+      ENDIF
+      IF( iosw(ii,ij) >= 0 .AND. iosw(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iisw = 1 + MOD(iosw(ii,ij),jpni)
+         ijsw = 1 +    (iosw(ii,ij))/jpni
+         npsw = ipproc(iisw,ijsw)
+      ENDIF
+      IF( ione(ii,ij) >= 0 .AND. ione(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iine = 1 + MOD(ione(ii,ij),jpni)
+         ijne = 1 +    (ione(ii,ij))/jpni
+         npne = ipproc(iine,ijne)
+      ENDIF
+      IF( ionw(ii,ij) >= 0 .AND. ionw(ii,ij) <= (jpni*jpnj-1) ) THEN 
+         iinw = 1 + MOD(ionw(ii,ij),jpni)
+         ijnw = 1 +    (ionw(ii,ij))/jpni
+         npnw = ipproc(iinw,ijnw)
+      ENDIF
+      nbnw = ibnw(ii,ij)
+      nbne = ibne(ii,ij)
+      nbsw = ibsw(ii,ij)
+      nbse = ibse(ii,ij)
+      nlcj = ilcj(ii,ij)  
+      nlci = ilci(ii,ij)  
+      nldi = ildi(ii,ij)
+      nlei = ilei(ii,ij)
+      nldj = ildj(ii,ij)
+      nlej = ilej(ii,ij)
+      nbondi = ibondi(ii,ij)
+      nbondj = ibondj(ii,ij)
+      nimpp = iimppt(ii,ij)  
+      njmpp = ijmppt(ii,ij)  
+      DO jproc = 1, jpnij
+         ii = iin(jproc)
+         ij = ijn(jproc)
+         nimppt(jproc) = iimppt(ii,ij)  
+         njmppt(jproc) = ijmppt(ii,ij)  
+         nlcjt(jproc) = ilcj(ii,ij)
+         nlcit(jproc) = ilci(ii,ij)
+         nldit(jproc) = ildi(ii,ij)
+         nleit(jproc) = ilei(ii,ij)
+         nldjt(jproc) = ildj(ii,ij)
+         nlejt(jproc) = ilej(ii,ij)
+      END DO
+
+      ! Save processor layout in ascii file
+      IF (lwp) THEN
+         clname = 'layout.dat'
+         CALL ctlopn( inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .FALSE., 1 )
+         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
+         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
+
+        DO  jproc = 1, jpnij
+         WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
+                                      nldit(jproc), nldjt(jproc), &
+                                      nleit(jproc), nlejt(jproc), &
+                                      nimppt(jproc), njmppt(jproc)
+        END DO
+        CLOSE(inum)   
+      END IF
+
+
+      ! FETI method
+
+      IF( nperio == 1 .AND. nsolv == 3 ) THEN 
+
+         ! general CASE : Earth == infinite tube
+
+         nbnw = 1
+         npnw = narea
+         nbne = 1
+         npne = narea
+         nbsw = 1
+         npsw = (narea-2)
+         nbse = 1
+         npse = (narea-2)
+
+         ! REAL boundary condition
+
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+
+         IF( nbondj == -1 .OR. nbondj == 2 ) THEN 
+            nbsw = 0
+            nbse = 0
+         ENDIF
+
+         IF( nbondj ==  1 .OR. nbondj == 2 ) THEN 
+            nbnw = 0
+            nbne = 0
+         ENDIF
+      ENDIF
+
+      IF( nperio == 1 .AND.jpni /= 1 ) CALL ctl_stop( ' mpp_init2:  error on cyclicity' )
+
+      ! Prepare mpp north fold
+
+      IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
+         CALL mpp_ini_north
+         IF(lwp) WRITE(numout,*) ' mpp_init2 : North fold boundary prepared for jpni >1'
+      ENDIF
+
+      ! Defined npolj, either 0, 3 , 4 , 5 , 6
+      ! In this case the important thing is that npolj /= 0
+      ! Because if we go through these line it is because jpni >1 and thus
+      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
+
+      npolj = 0
+      ij = ijn(narea)
+
+      IF( jperio == 3 .OR. jperio == 4 ) THEN
+         IF( ij == jpnj ) npolj = 3
+      ENDIF
+
+      IF( jperio == 5 .OR. jperio == 6 ) THEN
+         IF( ij == jpnj ) npolj = 5
+      ENDIF
+
+      ! Prepare NetCDF output file (if necessary)
+      CALL mpp_init_ioipsl
+
+      ! Periodicity : no corner if nbondi = 2 and nperio != 1
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' nproc=  ',nproc
+         WRITE(numout,*) ' nowe=   ',nowe
+         WRITE(numout,*) ' noea=   ',noea
+         WRITE(numout,*) ' nono=   ',nono
+         WRITE(numout,*) ' noso=   ',noso
+         WRITE(numout,*) ' nbondi= ',nbondi
+         WRITE(numout,*) ' nbondj= ',nbondj
+         WRITE(numout,*) ' npolj=  ',npolj
+         WRITE(numout,*) ' nperio= ',nperio
+         WRITE(numout,*) ' nlci=   ',nlci
+         WRITE(numout,*) ' nlcj=   ',nlcj
+         WRITE(numout,*) ' nimpp=  ',nimpp
+         WRITE(numout,*) ' njmpp=  ',njmpp
+         WRITE(numout,*) ' nbse=   ',nbse,' npse= ',npse
+         WRITE(numout,*) ' nbsw=   ',nbsw,' npsw= ',npsw
+         WRITE(numout,*) ' nbne=   ',nbne,' npne= ',npne
+         WRITE(numout,*) ' nbnw=   ',nbnw,' npnw= ',npnw
+      ENDIF
+
+   END SUBROUTINE mpp_init2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/oce.F90	(revision 4536)
@@ -0,0 +1,68 @@
+MODULE oce
+   !!======================================================================
+   !!                      ***  MODULE  oce  ***
+   !! Ocean        :  dynamics and active tracers defined in memory 
+   !!======================================================================
+   !! History :   1.0  !  02-11  (G. Madec)  F90: Free form and module
+   !!             2.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+
+   !! Physics and algorithm flags
+   !! ---------------------------
+   LOGICAL, PUBLIC ::   ln_dynhpg_imp   = .FALSE.  !: semi-implicite hpg flag
+   INTEGER, PUBLIC ::   nn_dynhpg_rst   = 0        !: add dynhpg implicit variables in restart ot not
+
+   !! dynamics and tracer fields              ! before ! now    ! after  !   the after trends becomes the fields
+   !! --------------------------              ! fields ! fields ! trends !   only in dyn(tra)_zdf and dyn(tra)_nxt
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   ub    ,  un    ,  ua    !: i-horizontal velocity (m/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   vb    ,  vn    ,  va    !: j-horizontal velocity (m/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::            wn             !: vertical velocity (m/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   rotb  ,  rotn           !: relative vorticity (1/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   hdivb ,  hdivn          !: horizontal divergence (1/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   tb    ,  tn    ,  ta    !: potential temperature (celcius)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   sb    ,  sn    ,  sa    !: salinity (psu)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   rhd                     !: in situ density anomalie rhd=(rho-rau0)/rau0
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   rhop                    !: potential volumic mass (kg/m3)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   rn2                     !: brunt-vaisala frequency (1/s2)
+
+      !! advection scheme choice
+      !! -----------------------
+!!gm  only for trcadv...   be be suppressed
+      CHARACTER(len=3), PUBLIC  ::   l_adv   !: 'ce2' centre scheme used
+         !                                   !: 'tvd' TVD scheme used
+         !                                   !: 'mus' MUSCL scheme used
+         !                                   !: 'mu2' MUSCL2 scheme used
+
+   !! surface pressure gradient
+   !! -------------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   spgu, spgv                  !: horizontal surface pressure gradient
+
+   !! interpolated gradient (only used in zps case)
+   !! ---------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   gtu, gsu, gru               !: t-, s- and rd horizontal gradient at u- and 
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   gtv, gsv, grv               !: v-points at bottom ocean level 
+
+   !! free surface
+   !! ------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sshb , sshn                 !: before, now sea surface height (meters)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sshu , sshv                 !: sea surface height at u- and v- point
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   sshbb, ssha                 !: before before sea surface height at t-point
+
+#if defined key_dynspg_rl   ||   defined key_esopa
+   !! rigid-lid formulation
+   !! ---------------------
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   bsfb, bsfn                 !: before, now barotropic streamfunction [m3/s]
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   bsfd                       !: now barotropic streamfunction trend   [m3/s2]
+#endif
+
+   !!----------------------------------------------------------------------
+END MODULE oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ocfzpt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ocfzpt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/ocfzpt.F90	(revision 4536)
@@ -0,0 +1,72 @@
+MODULE ocfzpt
+   !!======================================================================
+   !!                       ***  MODULE  ocfzpt  ***
+   !! Ocean active tracers:  freezing point computation and freezing area
+   !!======================================================================
+   
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC oc_fz_pt        ! called by opa.F90 and step.F90
+
+   !! * Shared module variables   
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   &  !:
+      freeze, freezn,  &  !: after and now ice mask (0 or 1)
+      fzptb, fzptn        !: before and now freezing point
+   !!----------------------------------------------------------------------
+   !! OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE oc_fz_pt
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE oc_fz_pt  ***
+      !!
+      !! ** Purpose : - Calculate ocean surface freezing temperature
+      !!              - Calculate related boolean for now ice distribution 
+      !!
+      !! ** Method  :   Caution, freezing point only for jackett & McDougall eos
+      !!
+      !! ** Action  : - fzptn  : now freezing temperature at ocean surface
+      !!              - fzptb  : before freezing temperature at ocean surface
+      !!              - freezn : boolean indicating freezing conditions at the 
+      !!                ocean surface at time step "now"
+      !!
+      !! History :
+      !!        !  94-08  (M.-A. Filiberti)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::  ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------      
+
+!CDIR NOVERRCHK
+      DO jj = 1, jpj
+!CDIR NOVERRCHK
+         DO ji = 1, jpi
+            fzptb(ji,jj) = fzptn(ji,jj)        ! swap freezing point array
+
+            !                                  ! ocean local surface freezing temperature
+            !                                  ! sn >= 0 : this is verified in stpctl at each time step
+            fzptn (ji,jj) = ( -0.0575 + 1.710523e-3 * SQRT( sn(ji,jj,1) )   &
+                                      - 2.154996e-4 *       sn(ji,jj,1)   ) * sn(ji,jj,1)   !!   &
+            !!                        - 7.53e-4 * pressure
+
+            !                                  ! Define boolean related to freezing conditions
+            freezn(ji,jj) = tmask(ji,jj,1) * MAX( 0., SIGN( 1., fzptn(ji,jj) - tn(ji,jj,1) )  )
+         END DO
+      END DO
+
+   END SUBROUTINE oc_fz_pt
+
+   !!======================================================================
+END MODULE ocfzpt
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/opa.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/opa.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/opa.F90	(revision 4536)
@@ -0,0 +1,485 @@
+MODULE opa
+   !!==============================================================================
+   !!                       ***  MODULE opa   ***
+   !! Ocean system   : OPA ocean dynamics (including on-line tracers and sea-ice)
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   opa_model      : solve ocean dynamics, tracer and/or sea-ice
+   !!   opa_init       : initialization of the opa model
+   !!   opa_flg        : initialisation of algorithm flag 
+   !!   opa_closefile  : close remaining files
+   !!----------------------------------------------------------------------
+   !! History :
+   !!   4.0  !  90-10  (C. Levy, G. Madec)  Original code
+   !!   7.0  !  91-11  (M. Imbard, C. Levy, G. Madec)
+   !!   7.1  !  93-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 
+   !!        !  92-06  (L.Terray) coupling implementation
+   !!        !  93-11  (M.A. Filiberti) IGLOO sea-ice 
+   !!   8.0  !  96-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  !  97-06  (M. Imbard, G. Madec)
+   !!   8.2  !  99-11  (M. Imbard, H. Goosse)  LIM sea-ice model 
+   !!        !  99-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP 
+   !!        !  00-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
+   !!   9.0  !  02-08  (G. Madec)  F90: Free form and modules
+   !!    "   !  04-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
+   !!    "   !  04-08  (C. Talandier) New trends organization
+   !!    "   !  05-06  (C. Ethe) Add the 1D configuration possibility
+   !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!    "   !  06-03  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!    "   !  06-04  (G. Madec, R. Benshila)  Step reorganization
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE cpl_oce         ! ocean-atmosphere-sea ice coupled exchanges
+   USE dom_oce         ! ocean space domain variables
+   USE oce             ! dynamics and tracers variables
+   USE trdmod_oce      ! ocean variables trends
+   USE daymod          ! calendar
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing
+
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+   USE obc_par         ! open boundary cond. parameters
+   USE obcini          ! open boundary cond. initialization (obc_ini routine)
+   USE istate          ! initial state setting          (istate_init routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+
+   ! ocean physics
+   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
+   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini
+
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE iceini          ! initialization of sea-ice         (ice_init routine)
+   USE cpl             ! coupled ocean/atmos.              (cpl_init routine)
+   USE ocfzpt          ! ocean freezing point              (oc_fz_pt routine)
+   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+   USE flxfwb          ! freshwater budget correction  (flx_fwb_init routine)
+   USE flxmod          ! thermohaline forcing of the ocean (flx_init routine)
+
+   USE diaptr          ! poleward transports           (dia_ptr_init routine)
+
+   USE step            ! OPA time-stepping                  (stp     routine)
+#if defined key_oasis3
+   USE cpl_oasis3      ! OASIS3 coupling (to ECHAM5)
+#elif defined key_oasis4
+   USE cpl_oasis4      ! OASIS4 coupling (to ECHAM5)
+#endif
+   USE dynspg_oce      ! Control choice of surface pressure gradient schemes
+   USE prtctl          ! Print control                 (prt_ctl_init routine)
+   USE ini1d           ! re-initialization of u-v mask for the 1D configuration
+   USE dyncor1d        ! Coriolis factor at T-point
+   USE step1d          ! Time stepping loop for the 1D configuration
+
+   USE initrc          ! Initialization of the passive tracers
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Module variables
+   CHARACTER (len=64) ::        &
+      cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !! * Routine accessibility
+   PUBLIC opa_model      ! called by model.F90
+   PUBLIC opa_init
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/opa.F90,v 1.38 2007/06/05 10:32:02 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE opa_model
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   opa solves the primitive equations on an orthogonal 
+      !!      curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!
+      !! References :
+      !!      Madec, Delecluse,Imbard, and Levy, 1997: reference manual.
+      !!              internal report, IPSL.
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp       ! time step index
+      !!----------------------------------------------------------------------
+
+#if defined key_agrif
+      CALL Agrif_Init_Grids()
+#endif
+      
+      CALL opa_init  ! Initializations
+
+      ! 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( lk_cfg_1d ) THEN 
+         istp = nit000
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL Agrif_Step(stp_1d)
+#else
+            CALL stp_1d( istp )
+#endif
+            istp = istp + 1
+
+            IF( lk_mpp )   CALL mpp_max(nstop)
+ 
+         END DO
+      ELSE
+         istp = nit000
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL Agrif_Step(stp)
+#else
+            CALL stp( istp )
+#endif
+            istp = istp + 1
+
+            IF( lk_mpp )   CALL mpp_max(nstop)
+            
+         END DO
+      ENDIF
+      !                                     ! ========= !
+      !                                     !  Job end  !
+      !                                     ! ========= !
+
+      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
+
+      CALL opa_closefile
+#if defined key_oasis3 || defined key_oasis4
+      call cpl_prism_finalize
+#else
+      IF( lk_mpp )   CALL mppstop                          ! Close all files (mpp)
+#endif
+
+   END SUBROUTINE opa_model
+
+
+   SUBROUTINE opa_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_init  ***
+      !!
+      !! ** Purpose :   initialization of the opa model
+      !!
+      !!----------------------------------------------------------------------
+#if defined key_coupled
+      INTEGER ::   itro, istp0        ! ???
+#endif
+#if defined key_oasis3 || defined key_oasis4
+      INTEGER :: localComm
+#endif
+      CHARACTER (len=20) ::   namelistname
+      CHARACTER (len=28) ::   file_out
+      NAMELIST/namctl/ ln_ctl, nprint, nictls, nictle,   &
+         &             isplt , jsplt , njctls, njctle, nbench, nbit_cmp
+      !!----------------------------------------------------------------------
+
+      ! Initializations
+      ! ===============
+
+      file_out = 'ocean.output'
+      
+      ! open listing and namelist units
+      CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+         &         'SEQUENTIAL', 1, 6, .FALSE., 1 )
+
+      WRITE(numout,*)
+      WRITE(numout,*) '                 L O D Y C - I P S L'
+      WRITE(numout,*) '                     O P A model'
+      WRITE(numout,*) '            Ocean General Circulation Model'
+      WRITE(numout,*) '               version OPA 9.0  (2005) '
+      WRITE(numout,*)
+      WRITE(numout,*)
+
+      namelistname = 'namelist'
+      CALL ctlopn( numnam, namelistname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &         1, numout, .FALSE., 1 )
+
+      ! Namelist namctl : Control prints & Benchmark
+      REWIND( numnam )
+      READ  ( numnam, namctl )
+
+#if defined key_oasis3 || defined key_oasis4
+      call cpl_prism_init(localComm)
+      ! Nodes selection
+      narea = mynode(localComm)
+#else
+      ! Nodes selection
+      narea = mynode()
+#endif
+      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      ! open additionnal listing
+      IF( ln_ctl )   THEN
+         IF( narea-1 > 0 )   THEN
+            WRITE(file_out,FMT="('ocean.output_',I4.4)") narea-1
+            CALL ctlopn( numout, file_out, 'UNKNOWN', 'FORMATTED',   &
+               &         'SEQUENTIAL', 1, numout, .FALSE., 1 )
+            lwp = .TRUE.
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) '                 L O D Y C - I P S L'
+            WRITE(numout,*) '                     O P A model'
+            WRITE(numout,*) '            Ocean General Circulation Model'
+            WRITE(numout,*) '               version OPA 9.0  (2005) '
+            WRITE(numout,*) '                   MPI Ocean output '
+            WRITE(numout,*)
+            WRITE(numout,*)
+         ENDIF
+      ENDIF
+
+      !                                     ! ============================== !
+      !                                     !  Model general initialization  !
+      !                                     ! ============================== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      CALL opa_flg                          ! Control prints & Benchmark
+
+                                            ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                          ! standard cutting out
+      ELSE
+         CALL mpp_init2                         ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+
+      IF( ln_ctl )      CALL prt_ctl_init   ! Print control
+
+      IF( lk_cfg_1d )   CALL fcorio_1d      ! redefine Coriolis at T-point
+
+      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
+
+      CALL day( nit000 )                    ! Calendar
+
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+
+      CALL oc_fz_pt                         ! Surface freezing point
+
+#if defined key_ice_lim
+      CALL ice_init                         ! Sea ice model
+#endif
+
+      !                                     ! Ocean physics
+
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
+
+
+#if defined key_passivetrc
+      CALL ini_trc                           ! Passive tracers
+#endif
+
+#if defined key_coupled && ! defined key_oasis3 && ! defined key_oasis4
+      itro  = nitend - nit000 + 1           ! Coupled
+      istp0 = NINT( rdt )
+      CALL cpl_init( itro, nexco, istp0 )   ! Signal processing and process id exchange
+#endif
+
+#if defined key_oasis3 || defined key_oasis4
+      CALL cpl_prism_define
+#endif
+
+      CALL flx_init                         ! Thermohaline forcing initialization
+
+      CALL flx_fwb_init                     ! FreshWater Budget correction
+
+      CALL dia_ptr_init                     ! Poleward TRansports initialization
+
+      !                                     ! =============== !
+      !                                     !  time stepping  !
+      !                                     ! =============== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( lk_cfg_1d  )  THEN 
+         CALL init_1d
+      ENDIF
+
+   END SUBROUTINE opa_init
+
+
+   SUBROUTINE opa_flg
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa  ***
+      !!
+      !! ** Purpose :   Initialize logical flags that control the choice of
+      !!      some algorithm or control print
+      !!
+      !! ** Method  :    Read in namilist namflg logical flags
+      !!
+      !! History :
+      !!   9.0  !  03-11  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+      NAMELIST/namflg/ ln_dynhpg_imp, nn_dynhpg_rst
+      !!----------------------------------------------------------------------
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '          Namelist namctl'
+         WRITE(numout,*) '             run control (for debugging)     ln_ctl    = ', ln_ctl
+         WRITE(numout,*) '             level of print                  nprint    = ', nprint
+         WRITE(numout,*) '             Start i indice for SUM control  nictls    = ', nictls
+         WRITE(numout,*) '             End i indice for SUM control    nictle    = ', nictle
+         WRITE(numout,*) '             Start j indice for SUM control  njctls    = ', njctls
+         WRITE(numout,*) '             End j indice for SUM control    njctle    = ', njctle
+         WRITE(numout,*) '             number of proc. following i     isplt     = ', isplt
+         WRITE(numout,*) '             number of proc. following j     jsplt     = ', jsplt
+         WRITE(numout,*) '             benchmark parameter (0/1)       nbench    = ', nbench
+         WRITE(numout,*) '             bit comparison mode (0/1)       nbit_cmp  = ', nbit_cmp
+      ENDIF
+
+      ! ... Control the sub-domain area indices for the control prints
+      IF( ln_ctl )   THEN
+         IF( lk_mpp )   THEN
+            ! the domain is forced to the real splitted domain in MPI
+            isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj
+         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
+
+            ! compute the total number of processors ijsplt
+            ijsplt = isplt*jsplt
+         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
+
+         ! Control the indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN
+            ! the print control is done over the default area
+            lsp_area = .FALSE.
+         ELSE
+            ! the print control is 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          ! IF( nictls+nictle+njctls+njctle == 0 )
+       ENDIF            ! IF(ln_ctl)
+
+      IF( nbench == 1 )   THEN
+         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: key_gyre must &
+               &                      be used or set nbench = 0' )
+         END SELECT
+      ENDIF
+
+      IF( nbit_cmp == 1 )   THEN
+         CALL ctl_warn( '          Bit comparison enabled. Single and multiple processor results must bit compare', &
+              &         '          WARNING: RESULTS ARE NOT PHYSICAL.' )
+      ENDIF
+
+
+      ! Read Namelist namflg : algorithm FLaG
+      ! --------------------
+      REWIND ( numnam )
+      READ   ( numnam, namflg )
+
+      ! Parameter control and print
+      ! ---------------------------
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'opa_flg : Hydrostatic pressure gradient algorithm'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '          Namelist namflg : set algorithm flags'
+         WRITE(numout,*) '             centered (F) or semi-implicit (T)   ln_dynhpg_imp = ', ln_dynhpg_imp
+         WRITE(numout,*) '             hydrostatic pressure gradient'
+         WRITE(numout,*) '             add dynhpg implicit variable        nn_dynhpg_rst = ', nn_dynhpg_rst
+         WRITE(numout,*) '             in restart ot not nn_dynhpg_rst'
+      ENDIF
+      IF( .NOT. ln_dynhpg_imp )   nn_dynhpg_rst = 0      ! force no adding dynhpg implicit variables in restart
+
+   END SUBROUTINE opa_flg
+
+
+   SUBROUTINE opa_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!
+      !! ** Method  :
+      !!
+      !! History :
+      !!   9.0  !  05-01  (O. Le Galloudec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE dtatem        ! temperature data
+      USE dtasal        ! salinity data
+      USE dtasst        ! sea surface temperature data
+      !!----------------------------------------------------------------------
+
+      IF ( lk_mpp ) CALL mppsync
+
+      ! 1. Unit close
+      ! -------------
+
+      CLOSE( numnam )           ! namelist
+      CLOSE( numout )           ! standard model output file
+
+      IF(lwp) CLOSE( numstp )   ! time-step file
+      IF(lwp) CLOSE( numsol )
+
+   END SUBROUTINE opa_closefile
+
+   !!======================================================================
+END MODULE opa
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r2.F90	(revision 4536)
@@ -0,0 +1,131 @@
+MODULE par_eel_r2
+   !!======================================================================
+   !!                        ***  par_eel_r2  ***
+   !! Ocean Domain parameter : 2 km resolution cyclic Channel (EEL_R2 configuration)
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_EEL_R2.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Header: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_eel_r2
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r2'   :                            EEL configuration : R2
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution      !!! *  GYRE R2  *
+   CHARACTER (len=16) ::   cp_cfg = "eel"    !: name of the configuration 
+   INTEGER            ::   jp_cfg = 2        !: resolution of the configuration [km]
+
+   ! input data size                        !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  =  83                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  = 242                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  30                !: number of levels      ( >= jpk    ) 
+   
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :            1D configuration of GYRE_R2
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                   !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   16                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   11                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :               Full global domain of GYRE_R2
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta              !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta              !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                 !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                 !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   1                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = jpiglo              !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 3   !: type of horizontal mesh
+   !                                       ! = 3 beta-plane with regular grid-spacing
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  =    0.0_wp     !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  =   35.0_wp     !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = 2000.0_wp     !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = 2000.0_wp     !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -2033.194295283385_wp  !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =  155.8325369664153_wp  !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =  146.3615918601890_wp  !:
+   REAL(wp), PARAMETER ::   ppkth =  17.28520372419791_wp  !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     5.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_eel_r2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r5.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r5.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r5.F90	(revision 4536)
@@ -0,0 +1,131 @@
+MODULE par_eel_r5
+   !!======================================================================
+   !!                        ***  par_eel_r5  ***
+   !! Ocean Domain parameter : 5 km resolution cyclic Channel (EEL_R5 configuration)
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_EEL_R5.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Header: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_eel_r5
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r5'   :                            EEL configuration : R5
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution      !!! *  GYRE R5  *
+   CHARACTER (len=16) ::   cp_cfg = "eel"    !: name of the configuration 
+   INTEGER            ::   jp_cfg = 5        !: resolution of the configuration [km]
+
+   ! input data size                        !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  =  66                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  =  66                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  31                !: number of levels      ( >= jpk    ) 
+   
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :            1D configuration of GYRE_R5
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                   !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   16                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   11                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :               Full global domain of GYRE_R5
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta              !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta              !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                 !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                 !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   1                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = jpiglo              !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 3   !: type of horizontal mesh
+   !                                       ! = 3 beta-plane with regular grid-spacing
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  =    0.0_wp       !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  = 43.436430714_wp !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                   !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used     !: zonal      grid-spacing [degrees]
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used     !: meridional grid-spacing [degrees]
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = 8000.0_wp       !: zonal      grid-spacing [meters]
+   REAL(wp) ,PARAMETER ::   ppe2_m   = 8000.0_wp       !: meridional grid-spacing [meters]
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -4762.96143546300_wp  !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   255.58049070440_wp  !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =   245.58132232490_wp  !:
+   REAL(wp), PARAMETER ::   ppkth =    21.43336197938_wp  !: (non dimensional): gives the approximate
+   !                                                      !: layer number above which  stretching will
+   !                                                      !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     3.00000000000_wp  !: (non dimensional): stretching factor
+   !                                                      !: for the grid. The highest zacr, the smallest
+   !                                                      !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_eel_r5
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r6.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r6.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_eel_r6.F90	(revision 4536)
@@ -0,0 +1,131 @@
+MODULE par_eel_r6
+   !!======================================================================
+   !!                        ***  par_eel_r6  ***
+   !! Ocean Domain parameter : 6 km resolution cyclic Channel (EEL_R6 configuration)
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_EEL_R6.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Header: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_eel_r6
+   !!---------------------------------------------------------------------
+   !!   'key_eel_r6'   :                            EEL configuration : R6
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution      !!! *  GYRE R6  *
+   CHARACTER (len=16) ::   cp_cfg = "eel"    !: name of the configuration 
+   INTEGER            ::   jp_cfg = 6        !: resolution of the configuration [km]
+
+   ! input data size                        !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  =  29                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  =  83                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  30                !: number of levels      ( >= jpk    ) 
+   
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :            1D configuration of GYRE_R6
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                   !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   16                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   11                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :               Full global domain of GYRE_R6
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta              !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta              !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                 !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                 !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   1                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = jpiglo              !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 3   !: type of horizontal mesh
+   !                                       ! = 3 beta-plane with regular grid-spacing
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  =    0.0_wp     !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  =   35.0_wp     !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = 6000.0_wp     !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = 6000.0_wp     !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -2033.194295283385_wp  !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =  155.8325369664153_wp  !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =  146.3615918601890_wp  !:
+   REAL(wp), PARAMETER ::   ppkth =  17.28520372419791_wp  !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     5.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_eel_r6
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_gyre.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_gyre.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_gyre.F90	(revision 4536)
@@ -0,0 +1,133 @@
+MODULE par_gyre
+   !!======================================================================
+   !!                        ***  par_gyre  ***
+   !! Ocean Domain parameter : rotated square bassin on a beta-plane at 1/jp_cfg 
+   !!    degree resolution (GYRE configuration) and a 1D configuration case
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_GYRE.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Header: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_gyre
+   !!----------------------------------------------------------------------
+   !!   'key_gyre'   :                                   GYRE configuration
+   !!----------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                 !!! *  GYRE  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "gyre"   !: name of the configuration 
+   INTEGER, PARAMETER            ::   jp_cfg = 1        !: resolution of the configuration (degrees)
+   !                                                    !  control the size of GYRE configurations
+
+   ! input data size                                   !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  = 30 * jp_cfg + 2    !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  = 20 * jp_cfg + 2    !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  = 31                 !: number of levels      ( >= jpk    ) 
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :             1D configuration of MY_CFG
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                   !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   16                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   11                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :                  Full global domain of GYRE
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta             !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta             !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   1                !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 5   !: type of horizontal mesh
+   !                                       !  = 5  beta-plane with regular grid-spacing and rotated domain
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  =    0.0_wp     !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  =   29.0_wp     !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = pp_not_used   !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = pp_not_used   !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -2033.194295283385_wp     !: GYRE coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   155.8325369664153_wp    !:
+   REAL(wp), PARAMETER ::   ppa1  =   146.3615918601890_wp    !:
+   REAL(wp), PARAMETER ::   ppkth =    17.28520372419791_wp   !: (non dimensional): gives the approximate
+   !                                                          !: layer number above which  stretching will
+   !                                                          !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     5.00000000000_wp      !: (non dimensional): stretching factor
+   !                                                          !: for the grid. The highest zacr, the smallest
+   !                                                          !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: vertical thickness of the top layer   [meters]
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: maximum depth of the ocean gdepw(jpk) [meters]
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_gyre
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_kind.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_kind.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_kind.F90	(revision 4536)
@@ -0,0 +1,38 @@
+MODULE par_kind
+   !!======================================================================
+   !!                   ***  MODULE par_kind  ***
+   !! Ocean :  define the kind of real for the whole model
+   !!======================================================================
+   !! History :   8.5   2002/06  (G. Madec)  Original code
+   !!             9.0   2007/11  (G. Madec)  Coding style
+   !!----------------------------------------------------------------------
+   !! NEMO 2.4, LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER, PUBLIC, PARAMETER ::   jpbyt   = 8        !: real size for mpp communications
+   INTEGER, PUBLIC, PARAMETER ::   jpbytda = 4        !: real size in input data files 4 or 8
+   INTEGER, PUBLIC, PARAMETER ::   jpbi3e  = 4        !: real size for T3E
+
+   ! Number model from which the SELECTED_*_KIND are requested:
+   !             4 byte REAL       8 byte REAL
+   ! CRAY:           -            precision = 13
+   !                              exponent = 2465
+   ! IEEE:      precision = 6     precision = 15
+   !            exponent = 37     exponent = 307
+
+   !                                       !: Floating point section
+   INTEGER, PUBLIC, PARAMETER ::   sp = SELECTED_REAL_KIND( 6, 37)    !: single precision (real 4)
+   INTEGER, PUBLIC, PARAMETER ::   dp = SELECTED_REAL_KIND(12,307)    !: double precision (real 8)
+   INTEGER, PUBLIC, PARAMETER ::   wp = dp                            !: working precision
+
+   !                                       !: Integer section
+   INTEGER, PUBLIC, PARAMETER ::   i4 = SELECTED_INT_KIND( 9)         !: single precision (integer 4)
+   INTEGER, PUBLIC, PARAMETER ::   i8 = SELECTED_INT_KIND(14)         !: double precision (integer 8)
+
+!!----------------------------------------------------------------------
+END MODULE par_kind
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_my_cfg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_my_cfg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_my_cfg.F90	(revision 4536)
@@ -0,0 +1,137 @@
+MODULE par_my_cfg
+   !!======================================================================
+   !!                        ***  par_my_cfg  ***
+   !! Ocean Domain parameter : user defined configuration (MY_CFG configuration)
+   !!    including  a 1D configuration.
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2007) 
+   !! $Id: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_my_cfg
+   !!---------------------------------------------------------------------
+   !!   'key_my_cfg'   :                       user configuration : MY_CFG
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                        AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                   no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                  !!! *  MY_CFG  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "my_cfg"  !: name of the configuration 
+   INTEGER, PARAMETER            ::   jp_cfg = 1         !: resolution of the configuration (degrees)
+
+   ! input data size                          !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  =  10                 !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  =  12                 !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  31                 !: number of levels      ( >= jpk    ) 
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :             1D configuration of MY_CFG
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                   !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =    5                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =    6                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+   
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :                Full global domain of MY_CFG
+   !------------!!--------------------------------------------------------
+   ! global domain size                                 !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta              !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta              !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta              !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                 !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                 !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                 !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   0                 !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   0                 !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 0   !: type of horizontal mesh
+   !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc file
+   !                                       !  = 1 geographical mesh on the sphere with regular grid-spacing
+   !                                       !  = 2 f-plane with regular grid-spacing
+   !                                       !  = 3 beta-plane with regular grid-spacing
+   !                                       !  = 4 Mercator grid with T/U point at the equator
+   !                                       !  = 5  beta-plane with regular grid-spacing and rotated domain
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  =    0.0_wp     !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  =  -35.0_wp     !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg =    1.0_wp     !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg =    0.5_wp     !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = 5000.0_wp     !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = 5000.0_wp     !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -4762.96143546300_wp   !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   255.58049070440_wp   !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =   245.58132232490_wp   !:
+   REAL(wp), PARAMETER ::   ppkth =    21.43336197938_wp   !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     3.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = 10._wp        !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = 5000._wp      !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_my_cfg
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_oce.F90	(revision 4536)
@@ -0,0 +1,109 @@
+MODULE par_oce
+   !!======================================================================
+   !!                        ***  par_oce  ***
+   !! Ocean :   set the ocean parameters
+   !!======================================================================
+   !! History :    -   !  1991     (Imbard, Levy, Madec)  Original code
+   !!             1.0  !  2004-01  (G. Madec, J.-M. Molines)  Free form and module
+   !!             2.4  !  2007-11  (G. Madec)  Suppress .h90 + style with AGRIF
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_kind        ! kind parameters
+   USE par_orca_r4     ! ORCA R4   configuration
+   USE par_orca_r2     ! ORCA R2   configuration (including 1D or arctic/antarctic zoom)
+   USE par_orca_r05    ! ORCA R05  configuration (including 1D or arctic/antarctic zoom)
+   USE par_orca_r025   ! ORCA R025 configuration (including 1D or arctic/antarctic zoom)
+   USE par_gyre        ! GYRE      configuration
+   USE par_eel_r2      ! GYRE R2   configuration
+   USE par_eel_r5      ! GYRE R5   configuration
+   USE par_eel_r6      ! GYRE R6   configuration
+   USE par_my_cfg      ! MY_CFG    user defined configuration (including 1D)
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!---------------------------------------------------------------------
+   !! Extra halos for mpp computing 
+   !!---------------------------------------------------------------------
+   INTEGER, PUBLIC, PARAMETER ::   jpr2di = 0   !: number of columns for extra outer halo (solsor only)
+   INTEGER, PUBLIC, PARAMETER ::   jpr2dj = 0   !: number of rows    for extra outer halo (solsor only)
+   INTEGER, PUBLIC, PARAMETER ::   jpreci = 1   !: number of columns for overlap 
+   INTEGER, PUBLIC, PARAMETER ::   jprecj = 1   !: number of rows    for overlap 
+
+#if defined key_agrif
+   !!---------------------------------------------------------------------
+   !!   'key_agrif'   :                                              AGRIF
+   !!---------------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+#if defined key_mpp_dyndist 
+   INTEGER, PUBLIC ::   jpni, jpnj, jpnij                      !: domain decomposition (AGRIF case)
+#endif
+   INTEGER, PUBLIC ::   jpi, jpj, jpim1, jpjm1, jpkm1, jpij    !: local domain size    (AGRIF case)
+
+   !! AGRIF ghost cells
+   INTEGER, PUBLIC, PARAMETER :: nbghostcells = 1                           !: ???
+   INTEGER, PUBLIC            :: nbcellsx = jpiglo - 2 - 2 * nbghostcells   !: ???
+   INTEGER, PUBLIC            :: nbcellsy = jpjglo - 2 - 2 * nbghostcells   !: ???
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default       :                         no AGRIF: model parameters
+   !!---------------------------------------------------------------------
+
+   ! Domain decomposition (NO massively parallel computer: jpni=jpnj=1 so jpi=jpiglo and jpj=jpjglo)
+   INTEGER, PUBLIC, PARAMETER ::   jpni   = 1   !: number of processors following i 
+   INTEGER, PUBLIC, PARAMETER ::   jpnj   = 1   !: number of processors following j
+   INTEGER, PUBLIC, PARAMETER ::   jpnij  = 1   !: nb of local domain = nb of processors ( <= jpni x jpnj )
+
+   !! Domain Matrix size on each processor
+   !!   data           domain   (jpidta,jpjdta)   defined in par_"config name" modules
+   !!   global or zoom domain   (jpiglo,jpjglo)   defined in par_"config name" modules
+   !!   local          domain   ( jpi  , jpj  )   defined below (= size of the domain on each processor)
+   INTEGER, PARAMETER ::   jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   !: first  dimension
+   INTEGER, PARAMETER ::   jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   !: second dimension
+   INTEGER, PARAMETER ::   jpim1 = jpi - 1                                          !: inner domain indices
+   INTEGER, PARAMETER ::   jpjm1 = jpj - 1                                          !: inner domain indices
+   INTEGER, PARAMETER ::   jpkm1 = jpk - 1                                          !: inner domain indices
+   INTEGER, PARAMETER ::   jpij  = jpi * jpj                                        !:  jpi x jpj
+#endif
+
+
+   !!---------------------------------------------------------------------
+   !! Optimization/control flags
+   !!---------------------------------------------------------------------
+#if defined key_esopa
+   LOGICAL, PUBLIC, PARAMETER ::   lk_esopa     = .TRUE.   !: flag to activate the all options
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_esopa     = .FALSE.  !: flag to activate the all options
+#endif
+#if defined key_vectopt_memory
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_mem  = .TRUE.   !: vector optimization flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_mem  = .FALSE.  !: vector optimization flag
+#endif
+#if defined key_vectopt_loop
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .TRUE.   !: vector optimization flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .FALSE.  !: vector optimization flag
+#endif
+#if defined key_mpp_omp
+   LOGICAL, PUBLIC, PARAMETER ::   lk_jki = .TRUE.   !: j-k-i loop flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_jki = .FALSE.  !: k-j-i loop flag
+#endif
+
+   !!---------------------------------------------------------------------
+   !! Temperature/salinity indices
+   !!---------------------------------------------------------------------
+
+   INTEGER, PARAMETER ::   jp_tem = 1   !: index of temperature in the tsb, tsns &, tsa arrays
+   INTEGER, PARAMETER ::   jp_sal = 2   !: index of salinity    in the tsb, tsns &, tsa arrays
+
+
+   !!======================================================================
+END MODULE par_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r025.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r025.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r025.F90	(revision 4536)
@@ -0,0 +1,136 @@
+MODULE par_orca_r025
+   !!======================================================================
+   !!                        ***  par_ORCA_R025  ***
+   !! Ocean Domain parameter : 0.25 degrees ORCA global ocean (0RCA_R025 configuration)
+   !!    including a 1D configuration case.
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_ORCA_R025.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_orca_r025
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r025'   :                       global ocean : ORCA R025
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                 !!! *  ORCA R025  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "orca"   !: name of the configuration 
+   INTEGER           , PARAMETER ::   jp_cfg = 025      !: resolution of the configuration (degrees)
+
+   ! input data size                                   !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  = 1442               !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  = 1021               !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =   46               !: number of levels      ( >= jpk    ) 
+   
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :          1D configuration of ORCA R025
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                  !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                  !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   61               !: left bottom (i,j) indices of the zoom in data domain indices
+   INTEGER, PARAMETER ::   jpjzoom =  110               !: here : (jpizoom,jpjzoom) = (61,110)  for (??W,??N)
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =  18                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 800                !: maximum number of points per island
+   
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :             Full global domain of ORCA R025
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta            !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta            !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta            !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1               !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1               !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =    4              !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =  150              !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 3000              !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 0   !: type of horizontal mesh
+   !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc file
+   !                                       !  = 1 geographical mesh on the sphere with regular grid-spacing
+   !                                       !  = 2 f-plane with regular grid-spacing
+   !                                       !  = 3 beta-plane with regular grid-spacing
+   !                                       !  = 4 Mercator grid with T/U point at the equator
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator be a T point.
+   REAL(wp) ,PARAMETER ::   ppglam0  = pp_not_used   !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  = pp_not_used   !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = pp_not_used   !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = pp_not_used   !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = pp_to_be_computed      !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  = pp_to_be_computed      !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  = pp_to_be_computed      !:
+   REAL(wp), PARAMETER ::   ppkth =    23.563_wp           !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     9.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin =    6._wp             !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = 5750._wp             !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_orca_r025
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r05.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r05.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r05.F90	(revision 4536)
@@ -0,0 +1,165 @@
+MODULE par_ORCA_R05
+   !!======================================================================
+   !!                        ***  par_ORCA_R05  ***
+   !! Ocean Domain parameter : 0.5 degrees orca global ocean (0RCA_R05 configuration)
+   !!    including antarctic, arctic or 1D configurations cases.
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_ORCA_R05.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_orca_r05
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r05'   :                         global ocean : ORCA R05
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                 !!! *  ORCA R05  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "orca"   !: name of the configuration 
+   INTEGER           , PARAMETER ::   jp_cfg = 05       !: resolution of the configuration (degrees)
+
+   ! input data size                                   !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  = 722                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  = 511                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  31                !: number of levels      ( >= jpk    ) 
+   
+
+#  if defined key_antarctic
+   !------------!!--------------------------------------------------------
+   !            !!   'key_antarctic'   :         antartic zoom of ORCA R05
+   !------------!!--------------------------------------------------------
+   ! zoom domain size                                  !!! *  antarctic zoom  * 
+   INTEGER, PARAMETER ::   jpiglo  = jpidta             !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 187                !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! zoom starting position
+   INTEGER, PARAMETER ::   jpizoom =   1                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   1                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   1                !: maximum number of points per island
+
+#  elif defined key_arctic
+   !------------!!--------------------------------------------------------
+   !            !!   'key_arctic' :                 artic zoom of ORCA R05
+   !------------!!--------------------------------------------------------
+   ! zoom domain size                                  !!! *  arctic zoom  *
+   INTEGER, PARAMETER ::   jpiglo  = 562                !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta - 301 + 1   !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! zoom starting position 
+   INTEGER, PARAMETER ::   jpizoom =  81                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom = 301                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   5                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   1                !: maximum number of points per island
+
+#  elif defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :           1D configuration of ORCA R05
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                  !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                  !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   61               !: left bottom (i,j) indices of the zoom in data domain indices
+   INTEGER, PARAMETER ::   jpjzoom =  110               !: here : (jpizoom,jpjzoom) = (61,110)  for (??W,??S)
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   1                !: maximum number of points per island
+   
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :              Full global domain of ORCA R05
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta            !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta            !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta            !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1               !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1               !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =    6              !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   79              !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 2000              !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   !!  Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   !!  Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 0   !: type of horizontal mesh
+   !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc file
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T-point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator is a T-point.
+   REAL(wp) ,PARAMETER ::   ppglam0  = pp_not_used   !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  = pp_not_used   !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = pp_not_used   !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = pp_not_used   !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -4762.96143546300_wp   !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   255.58049070440_wp   !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =   245.58132232490_wp   !:
+   REAL(wp), PARAMETER ::   ppkth =    21.43336197938_wp   !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     3.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_ORCA_R05
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r2.F90	(revision 4536)
@@ -0,0 +1,165 @@
+MODULE par_orca_r2
+   !!======================================================================
+   !!                        ***  par_orca_r2  ***
+   !! Ocean Domain parameter : 2 degrees orca global ocean (0RCA_R2 configuration)
+   !!    including antarctic, arctic or 1D configuration cases.
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_ORCA_R2.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_orca_r2
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r2'   :                           global ocean : ORCA R2
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                        AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                   no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                 !!! *  ORCA R2  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "orca"   !: name of the configuration 
+   INTEGER           , PARAMETER ::   jp_cfg = 2        !: resolution of the configuration (degrees)
+
+   ! input data size                                   !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  = 182                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  = 149                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  = 31                 !: number of levels      ( >= jpk    ) 
+   
+
+#  if defined key_antarctic
+   !------------!!--------------------------------------------------------
+   !            !!   'key_antarctic'   :          antartic zoom of ORCA R2
+   !------------!!--------------------------------------------------------
+   ! zoom domain size                                  !!! *  antarctic zoom  * 
+   INTEGER, PARAMETER ::   jpiglo  = jpidta             !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 50                 !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! zoom starting position
+   INTEGER, PARAMETER ::   jpizoom =   1                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   1                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   3                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 400                !: maximum number of points per island
+
+#  elif defined key_arctic
+   !------------!!--------------------------------------------------------
+   !            !!   'key_arctic' :                  artic zoom of ORCA R2
+   !------------!!--------------------------------------------------------
+   ! zoom domain size                                  !!! *  arctic zoom  *
+   INTEGER, PARAMETER ::   jpiglo  = 142                !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta - 97 + 1    !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! zoom starting position 
+   INTEGER, PARAMETER ::   jpizoom =  21                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =  97                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   3                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   7                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 400                !: maximum number of points per island
+
+#  elif defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :            1D configuration of ORCA R2
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                  !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                  !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   61               !: left bottom (i,j) indices of the zoom in data domain indices
+   INTEGER, PARAMETER ::   jpjzoom =  110               !: here : (jpizoom,jpjzoom) = (61,110)  for (160W,50N)
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =  18                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 800                !: maximum number of points per island
+   
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :               Full global domain of ORCA R2
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta             !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta             !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   4                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =  18                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 800                !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 0   !: type of horizontal mesh
+   !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc file
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T-point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator is a T-point.
+   REAL(wp) ,PARAMETER ::   ppglam0  = pp_not_used   !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  = pp_not_used   !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = pp_not_used   !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = pp_not_used   !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -4762.96143546300_wp   !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   255.58049070440_wp   !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =   245.58132232490_wp   !:
+   REAL(wp), PARAMETER ::   ppkth =    21.43336197938_wp   !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     3.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_orca_r2
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r4.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r4.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/par_orca_r4.F90	(revision 4536)
@@ -0,0 +1,132 @@
+MODULE par_orca_r4
+   !!======================================================================
+   !!                        ***  par_ORCA_R4  ***
+   !! Ocean Domain parameter : 4 degrees orca global ocean (0RCA_R4 configuration)
+   !!    including a 1D configuration case.
+   !!    NB: with AGRIF, values are not set as parameters
+   !!======================================================================
+   !! History :   9.0  !  2007-11  (G. Madec)  Original code from par_ORCA_R4.h90
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_orca_r4
+   !!---------------------------------------------------------------------
+   !!   'key_orca_r4'   :                           global ocean : ORCA R4
+   !!---------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_agrif
+   !------!!--------------------------------------------------------------
+   !      !!   'key_agrif'   :                                       AGRIF 
+   !------!!--------------------------------------------------------------
+
+   ! Configuration, and domain size are not assigned to a parameter value
+   !    as they are different in mother and children models
+   INTEGER ::   cp_cfg, jp_cfg                          !: configuration id       (AGRIF case)
+   INTEGER ::   jpidta, jpjdta, jpkdta                  !: input data size        (AGRIF case)
+   INTEGER ::   jpiglo, jpjglo, jpk, jpizoom, jpjzoom   !: domain size and zoom   (AGRIF case)
+   INTEGER ::   jperio, jpisl, jpnisl                   !: domain characteristics (AGRIF case)
+
+# else
+   !------!!--------------------------------------------------------------
+   !      !!   Default       :                  no AGRIF: model parameters
+   !------!!--------------------------------------------------------------
+
+   ! Configuration name and resolution                 !!! *  ORCA R4  *
+   CHARACTER (len=16), PARAMETER ::   cp_cfg = "orca"   !: name of the configuration 
+   INTEGER, PARAMETER            ::   jp_cfg = 4        !: resolution of the configuration (degrees)
+
+   ! input data size                                   !!! *  size of all input files  *
+   INTEGER, PARAMETER ::   jpidta  =  92                !: 1st lateral dimension ( >= jpiglo )
+   INTEGER, PARAMETER ::   jpjdta  =  76                !: 2nd    "       "      ( >= jpjglo )
+   INTEGER, PARAMETER ::   jpkdta  =  31                !: number of levels      ( >= jpk    ) 
+
+#  if defined key_cfg_1d
+   !------------!!--------------------------------------------------------
+   !            !!   'key_cfg_1d' :            1D configuration of ORCA R4
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  1D configuration  *
+   INTEGER, PARAMETER ::   jpiglo  = 3                  !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = 3                  !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   61               !: left bottom (i,j) indices of the zoom in data domain indices
+   INTEGER, PARAMETER ::   jpjzoom =   30               !: here : (jpizoom,jpjzoom) = (61,30)  for (??W,??N)
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   0                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =   1                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  =   1                !: maximum number of points per island
+
+#  else
+   !------------!!--------------------------------------------------------
+   !            !!   Default :               Full global domain of ORCA R4
+   !------------!!--------------------------------------------------------
+   ! global domain size                                !!! *  global domain  *
+   INTEGER, PARAMETER ::   jpiglo  = jpidta             !: 1st dimension of global domain --> i
+   INTEGER, PARAMETER ::   jpjglo  = jpjdta             !: 2nd    "                  "    --> j
+   INTEGER, PARAMETER ::   jpk     = jpkdta             !: number of vertical levels
+   ! starting position of the zoom 
+   INTEGER, PARAMETER ::   jpizoom =   1                !: left bottom (i,j) indices of the zoom
+   INTEGER, PARAMETER ::   jpjzoom =   1                !: in data domain indices
+   ! Domain characteristics
+   INTEGER, PARAMETER ::   jperio  =   4                !: lateral cond. type (between 0 and 6)
+   INTEGER, PARAMETER ::   jpisl   =  11                !: number of islands
+   INTEGER, PARAMETER ::   jpnisl  = 400                !: maximum number of points per island
+#  endif
+
+# endif
+
+   !!---------------------------------------------------------------------
+   !! grid parameters for domhgr and domzgr
+   !!---------------------------------------------------------------------
+   ! Values set to pp_not_used indicates that this parameter is not used in THIS config.
+   ! Values set to pp_to_be_computed  indicates that variables will be computed in domzgr
+   REAL(wp), PARAMETER ::   pp_not_used       = 999999_wp   !: default value for "not used"
+   REAL(wp), PARAMETER ::   pp_to_be_computed = 0._wp       !: default value for "to be computed"
+
+   ! horizontal mesh (domhgr)
+   !    Coefficients associated with the horizontal coordinate system (jphgr_msh /= 0 )
+   INTEGER, PARAMETER ::   jphgr_msh = 0   !: type of horizontal mesh
+   !                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc file
+
+   !   ppglam0 , ppgphi0: coordinates of the lower leftmost T-point of the grid.
+   !   The mercator grid starts only approximately at gphi0 because
+   !   of the constraint that the equator is a T-point.
+   REAL(wp) ,PARAMETER ::   ppglam0  = pp_not_used   !: longitude of first raw and column T-point (jphgr_msh=1)
+   REAL(wp) ,PARAMETER ::   ppgphi0  = pp_not_used   !: latitude  of first raw and column T-point (jphgr_msh=1)
+   !                                                 !  latitude  of the Coriolis/Beta parameter  (jphgr_msh=2 or 3)
+   REAL(wp) ,PARAMETER ::   ppe1_deg = pp_not_used   !: zonal      grid-spacing (degrees)
+   REAL(wp) ,PARAMETER ::   ppe2_deg = pp_not_used   !: meridional grid-spacing (degrees)
+   !
+   REAL(wp) ,PARAMETER ::   ppe1_m   = pp_not_used   !: zonal      grid-spacing (meters )
+   REAL(wp) ,PARAMETER ::   ppe2_m   = pp_not_used   !: meridional grid-spacing (meters )
+
+   ! Vertical mesh (domzgr)
+   !    parameter used in the analytical function defining the repartition of the level and their thickness
+   REAL(wp), PARAMETER ::   ppsur = -4762.96143546300_wp   !: ORCA r4, r2 and r05 coefficients
+   REAL(wp), PARAMETER ::   ppa0  =   255.58049070440_wp   !: (default coefficients)
+   REAL(wp), PARAMETER ::   ppa1  =   245.58132232490_wp   !:
+   REAL(wp), PARAMETER ::   ppkth =    21.43336197938_wp   !: (non dimensional): gives the approximate
+   !                                                       !: layer number above which  stretching will
+   !                                                       !: be maximum. Usually of order jpk/2.
+   REAL(wp), PARAMETER ::   ppacr =     3.00000000000_wp   !: (non dimensional): stretching factor
+   !                                                       !: for the grid. The highest zacr, the smallest
+   !                                                       !: the stretching.
+   !  If both ppa0 ppa1 and ppsur are specified to 0, then
+   !  they are computed from ppdzmin, pphmax, ppkth, ppacr in dom_zgr
+   REAL(wp), PARAMETER ::   ppdzmin = pp_not_used   !: (meters) vertical thickness of the top layer
+   REAL(wp), PARAMETER ::   pphmax  = pp_not_used   !: (meters) Maximum depth of the ocean gdepw(jpk)
+
+#else
+   !!---------------------------------------------------------------------
+   !!   default option  :                                     Empty module
+   !!---------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE par_orca_r4
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/phycst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/phycst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/phycst.F90	(revision 4536)
@@ -0,0 +1,196 @@
+MODULE phycst
+   !!======================================================================
+   !!                    ***  MODULE  phycst  ***
+   !!     Definition of of both ocean and ice parameters used in the code
+   !!=====================================================================
+   !! * Modules used
+   USE par_oce          ! ocean parameters
+   USE in_out_manager   ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC phy_cst          ! routine called by inipar.F90
+
+   !! * Shared module variables
+   INTEGER, PUBLIC, DIMENSION(12) ::   &  !:
+      nbiss = (/ 31, 29, 31, 30, 31, 30,      &  !: number of days per month
+         &       31, 31, 30, 31, 30, 31 /) ,  &  !  (leap-year)
+      nobis = (/ 31, 28, 31, 30, 31, 30,      &  !: number of days per month
+         &       31, 31, 30, 31, 30, 31 /)       !  (365 days a year)
+   
+   REAL(wp), PUBLIC ::                        &  !:
+      rpi = 3.141592653589793_wp           ,  &  !: pi
+      rad = 3.141592653589793_wp / 180._wp ,  &  !: conversion from degre into radian
+      rsmall = 0.5 * EPSILON( 1. )               !: smallest real computer value
+   
+   REAL(wp), PUBLIC ::          & !:
+      rday = 24.*60.*60.  ,     & !: day (s)
+      rsiyea              ,     & !: sideral year (s)
+      rsiday              ,     & !: sideral day (s)
+      raajj = 365._wp     ,     & !: number of days in one year
+      raamo =  12._wp     ,     & !: number of months in one year
+      rjjhh =  24._wp     ,     & !: number of hours in one day
+      rhhmm =  60._wp     ,     & !: number of minutes in one hour
+      rmmss =  60._wp     ,     & !: number of seconds in one minute
+      raass               ,     & !: number of seconds in one year
+      rmoss               ,     & !: number of seconds in one month
+      rjjss               ,     & !: number of seconds in one day
+!!!   omega = 7.292115083046061e-5_wp ,  &  !: change the last digit!
+      omega               ,    &  !: earth rotation parameter
+      ra    = 6371229._wp ,    &  !: earth radius (meter)
+      grav  = 9.80665_wp          !: gravity (m/s2)
+   
+   REAL(wp), PUBLIC ::         &  !:
+      rtt      = 273.16_wp  ,  &  !: triple point of temperature (Kelvin)
+      rt0      = 273.15_wp  ,  &  !: freezing point of water (Kelvin)
+      rt0_snow = 273.15_wp  ,  &  !: melting point of snow  (Kelvin)
+      rt0_ice  = 273.05_wp  ,  &  !: melting point of ice   (Kelvin)
+      rau0     = 1020._wp   ,  &  !: volumic mass of reference (kg/m3)
+      rauw     = 1000._wp   ,  &  !: density of pure water (kg/m3)
+      rcp      =    4.e+3_wp,  &  !: ocean specific heat
+      ro0cpr                      !: = 1. / ( rau0 * rcp )
+
+   REAL(wp), PUBLIC ::            &  !:
+      rcdsn   =   0.22_wp     ,   &  !: conductivity of the snow
+      rcdic   =   2.034396_wp ,   &  !: conductivity of the ice
+      rcpsn   =   6.9069e+5_wp,   &  !: density times specific heat for snow
+      rcpic   =   1.8837e+6_wp,   &  !: volumetric latent heat fusion of sea ice
+      xlsn    = 110.121e+6_wp ,   &  !: volumetric latent heat fusion of snow
+      xlic    = 300.33e+6_wp  ,   &  !: volumetric latent heat fusion of ice
+      xsn     =   2.8e+6      ,   &  !: latent heat of sublimation of snow
+      rhoic   = 900._wp       ,   &  !: density of sea ice (kg/m3)
+      rhosn   = 330._wp       ,   &  !: density of snow (kg/m3)
+      emic    =   0.97_wp     ,   &  !: emissivity of snow or ice
+      sice    =   6.0_wp      ,   &  !: salinity of ice (psu)
+      soce    =  34.7_wp      ,   &  !: salinity of sea (psu)
+      cevap   =   2.5e+6_wp   ,   &  !: latent heat of evaporation (water)
+      srgamma =   0.9_wp      ,   &  !: correction factor for solar radiation (Oberhuber, 1974)
+      vkarmn  =   0.4_wp      ,   &  !: von Karman constant
+      stefan  =   5.67e-8_wp         !: Stefan-Boltzmann constant 
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+   
+CONTAINS
+   
+   SUBROUTINE phy_cst
+      !!----------------------------------------------------------------------
+      !!                       ***  ROUTINE phy_cst  ***
+      !!
+      !! ** Purpose :   Print model parameters and set and print the constants
+      !!
+      !! ** Method  :   no
+      !!
+      !! History :
+      !!        !  90-10  (C. Levy - G. Madec)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  91-12  (M. Imbard)
+      !!   8.5  !  02-08  (G. Madec, C. Ethe)  F90, add ice constants 
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      CHARACTER (len=64) ::   cform = "(A9, 3(A13, I7) )" 
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' phy_cst : initialization of ocean parameters and constants'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+
+      ! Ocean Parameters
+      ! ----------------
+      IF(lwp) THEN
+         WRITE(numout,*) '       parameter file'
+         WRITE(numout,*)
+         WRITE(numout,*) '          dimension of model'
+         WRITE(numout,*) '              Local domain      Global domain       Data domain '
+         WRITE(numout,cform) '         ','   jpi     : ', jpi, '   jpiglo  : ', jpiglo, '   jpidta  : ', jpidta
+         WRITE(numout,cform) '         ','   jpj     : ', jpj, '   jpjglo  : ', jpjglo, '   jpjdta  : ', jpjdta
+         WRITE(numout,cform) '         ','   jpk     : ', jpk, '   jpk     : ', jpk   , '   jpkdta  : ', jpkdta
+         WRITE(numout,*)      '        ','   jpij    : ', jpij
+         WRITE(numout,*)
+         WRITE(numout,*) '          mpp local domain info (mpp)'
+         WRITE(numout,*) '             jpni    : ', jpni, '   jpreci  : ', jpreci
+         WRITE(numout,*) '             jpnj    : ', jpnj, '   jprecj  : ', jprecj
+         WRITE(numout,*) '             jpnij   : ', jpnij
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          lateral domain boundary condition type : jperio  = ', jperio
+         WRITE(numout,*) '          domain island (use in rigid-lid case)  : jpisl   = ', jpisl 
+         WRITE(numout,*) '                                                   jpnisl  = ', jpnisl
+      ENDIF
+
+      ! Define constants
+      ! ----------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '       constants'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          mathematical constant                 rpi = ', rpi
+
+      rsiyea = 365.25 * rday * 2. * rpi / 6.283076
+      rsiday = rday / ( 1. + rday / rsiyea )
+      omega  = 2. * rpi / rsiday 
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          day                                rday   = ', rday,   ' s'
+      IF(lwp) WRITE(numout,*) '          sideral year                       rsiyea = ', rsiyea, ' s'
+      IF(lwp) WRITE(numout,*) '          sideral day                        rsiday = ', rsiday, ' s'
+      IF(lwp) WRITE(numout,*) '          omega                              omega  = ', omega,  ' s-1'
+
+      rjjss = rjjhh * rhhmm * rmmss
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          nb of months per year               raamo = ', raamo, ' months'
+      IF(lwp) WRITE(numout,*) '          nb of hours per day                 rjjhh = ', rjjhh, ' hours'
+      IF(lwp) WRITE(numout,*) '          nb of minutes per hour              rhhmm = ', rhhmm, ' mn'
+      IF(lwp) WRITE(numout,*) '          nb of seconds per minute            rmmss = ', rmmss, ' s'
+      IF(lwp) WRITE(numout,*) '          nb of seconds per day               rjjss = ', rjjss, ' s'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          earth radius                         ra   = ', ra, ' m'
+      IF(lwp) WRITE(numout,*) '          gravity                              grav = ', grav , ' m/s^2'
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          triple point of temperature      rtt      = ', rtt     , ' K'
+      IF(lwp) WRITE(numout,*) '          freezing point of water          rt0      = ', rt0     , ' K'
+      IF(lwp) WRITE(numout,*) '          melting point of snow            rt0_snow = ', rt0_snow, ' K'
+      IF(lwp) WRITE(numout,*) '          melting point of ice             rt0_ice  = ', rt0_ice , ' K'
+
+      ro0cpr = 1. / ( rau0 * rcp )
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          volumic mass of pure water         rauw   = ', rauw, ' kg/m^3'
+      IF(lwp) WRITE(numout,*) '          volumic mass of reference          rau0   = ', rau0, ' kg/m^3'
+      IF(lwp) WRITE(numout,*) '          ocean specific heat                rcp    = ', rcp
+      IF(lwp) WRITE(numout,*) '                       1. / ( rau0 * rcp ) = ro0cpr = ', ro0cpr
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '          thermal conductivity of the snow          = ', rcdsn   , ' J/s/m/K'
+         WRITE(numout,*) '          thermal conductivity of the ice           = ', rcdic   , ' J/s/m/K'
+         WRITE(numout,*) '          density times specific heat for snow      = ', rcpsn   , ' J/m^3/K' 
+         WRITE(numout,*) '          density times specific heat for ice       = ', rcpic   , ' J/m^3/K'
+         WRITE(numout,*) '          volumetric latent heat fusion of sea ice  = ', xlic    , ' J/m' 
+         WRITE(numout,*) '          volumetric latent heat fusion of snow     = ', xlsn    , ' J/m' 
+         WRITE(numout,*) '          latent heat of sublimation of snow        = ', xsn     , ' J/kg' 
+         WRITE(numout,*) '          density of sea ice                        = ', rhoic   , ' kg/m^3'
+         WRITE(numout,*) '          density of snow                           = ', rhosn   , ' kg/m^3'
+         WRITE(numout,*) '          emissivity of snow or ice                 = ', emic  
+         WRITE(numout,*) '          salinity of ice                           = ', sice    , ' psu'
+         WRITE(numout,*) '          salinity of sea                           = ', soce    , ' psu'
+         WRITE(numout,*) '          latent heat of evaporation (water)        = ', cevap   , ' J/m^3' 
+         WRITE(numout,*) '          correction factor for solar radiation     = ', srgamma 
+         WRITE(numout,*) '          von Karman constant                       = ', vkarmn 
+         WRITE(numout,*) '          Stefan-Boltzmann constant                 = ', stefan  , ' J/s/m^2/K^4'
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          conversion: degre ==> radian          rad = ', rad
+
+         WRITE(numout,*)
+         WRITE(numout,*) '          smallest real computer value       rsmall = ', rsmall
+      ENDIF
+
+   END SUBROUTINE phy_cst
+
+   !!======================================================================
+END MODULE phycst
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/prtctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/prtctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/prtctl.F90	(revision 4536)
@@ -0,0 +1,567 @@
+MODULE prtctl
+   !!======================================================================
+   !!                       ***  MODULE prtctl   ***
+   !! Ocean system   : print all SUM trends for each processor domain
+   !!======================================================================
+   !! History :  2.0  !  05-07  (C. Talandier) original code
+   !!----------------------------------------------------------------------
+   USE dom_oce          ! ocean space and time domain variables
+   USE in_out_manager   ! I/O manager
+   USE lib_mpp          ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER, DIMENSION(:), ALLOCATABLE :: numid
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nlditl , nldjtl ,   &  !: first, last indoor index for each i-domain
+      nleitl , nlejtl ,   &  !: first, last indoor index for each j-domain
+      nimpptl, njmpptl,   &  !: i-, j-indexes for each processor
+      nlcitl , nlcjtl ,   &  !: dimensions of every subdomain
+      ibonitl, ibonjtl
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE ::   t_ctll , s_ctll ,   &  !: previous trend values
+      u_ctll , v_ctll
+
+   INTEGER ::   ktime        !: time step
+
+   PUBLIC prt_ctl         ! called by all subroutines
+   PUBLIC prt_ctl_info    ! called by all subroutines
+   PUBLIC prt_ctl_init    ! called by opa.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 2.4 , LOCEAN-IPSL (2008)
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+   SUBROUTINE prt_ctl (tab2d_1, tab3d_1, mask1, clinfo1, tab2d_2, tab3d_2, mask2, clinfo2, ovlap, kdim, clinfo3)
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl  ***
+      !!
+      !! ** Purpose : - print sum control of 2D or 3D arrays over the same area 
+      !!                in mono and mpp case. This way can be usefull when
+      !!                debugging a new parametrization in mono or mpp. 
+      !!
+      !! ** Method  : 2 possibilities exist when setting the ln_ctl parameter to
+      !!                .true. in the ocean namelist:
+      !!              - to debug a MPI run .vs. a mono-processor one; 
+      !!                the control print will be done over each sub-domain.
+      !!                The nictl[se] and njctl[se] parameters in the namelist must 
+      !!                be set to zero and [ij]splt to the corresponding splitted
+      !!                domain in MPI along respectively i-, j- directions.
+      !!              - to debug a mono-processor run over the whole domain/a specific area; 
+      !!                in the first case the nictl[se] and njctl[se] parameters must be set
+      !!                to zero else to the indices of the area to be controled. In both cases
+      !!                isplt and jsplt must be set to 1.
+      !!              - All arguments of the above calling sequence are optional so their
+      !!                name must be explicitly typed if used. For instance if the 3D
+      !!                array tn(:,:,:) must be passed through the prt_ctl subroutine, 
+      !!                it must looks like: CALL prt_ctl(tab3d_1=tn).
+      !!
+      !!                    tab2d_1 : first 2D array
+      !!                    tab3d_1 : first 3D array
+      !!                    mask1   : mask (3D) to apply to the tab[23]d_1 array
+      !!                    clinfo1 : information about the tab[23]d_1 array
+      !!                    tab2d_2 : second 2D array
+      !!                    tab3d_2 : second 3D array
+      !!                    mask2   : mask (3D) to apply to the tab[23]d_2 array
+      !!                    clinfo2 : information about the tab[23]d_2 array
+      !!                    ovlap   : overlap value
+      !!                    kdim    : k- direction for 3D arrays 
+      !!                    clinfo3 : additional information 
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:)  , INTENT(in), OPTIONAL :: tab2d_1
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: tab3d_1
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: mask1
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo1
+      REAL(wp), DIMENSION(:,:)  , INTENT(in), OPTIONAL :: tab2d_2
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: tab3d_2
+      REAL(wp), DIMENSION(:,:,:), INTENT(in), OPTIONAL :: mask2
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo2
+      INTEGER                   , INTENT(in), OPTIONAL :: ovlap
+      INTEGER                   , INTENT(in), OPTIONAL :: kdim
+      CHARACTER (len=*)         , INTENT(in), OPTIONAL :: clinfo3
+      !!
+      CHARACTER (len=15) :: cl2
+      INTEGER  ::   overlap, jn, sind, eind, kdir,j_id
+      REAL(wp) ::   zsum1, zsum2, zvctl1, zvctl2
+      REAL(wp), DIMENSION(jpi,jpj) :: ztab2d_1, ztab2d_2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zmask1, zmask2, ztab3d_1, ztab3d_2
+      !!----------------------------------------------------------------------
+
+      ! Arrays, scalars initialization 
+      overlap   = 0
+      kdir      = jpkm1
+      cl2       = ''
+      zsum1     = 0.e0
+      zsum2     = 0.e0
+      zvctl1    = 0.e0
+      zvctl2    = 0.e0
+      ztab2d_1(:,:)   = 0.e0
+      ztab2d_2(:,:)   = 0.e0
+      ztab3d_1(:,:,:) = 0.e0
+      ztab3d_2(:,:,:) = 0.e0
+      zmask1  (:,:,:) = 1.e0
+      zmask2  (:,:,:) = 1.e0
+
+      ! Control of optional arguments
+      IF( PRESENT(clinfo2) )  cl2            = clinfo2
+      IF( PRESENT(ovlap)   )  overlap        = ovlap
+      IF( PRESENT(kdim)    )  kdir           = kdim
+      IF( PRESENT(tab2d_1) )  ztab2d_1(:,:)  = tab2d_1(:,:)
+      IF( PRESENT(tab2d_2) )  ztab2d_2(:,:)  = tab2d_2(:,:)
+      IF( PRESENT(tab3d_1) )  ztab3d_1(:,:,:)= tab3d_1(:,:,:)
+      IF( PRESENT(tab3d_2) )  ztab3d_2(:,:,:)= tab3d_2(:,:,:)
+      IF( PRESENT(mask1)   )  zmask1  (:,:,:)= mask1  (:,:,:)
+      IF( PRESENT(mask2)   )  zmask2  (:,:,:)= mask2  (:,:,:)
+
+      IF( lk_mpp )   THEN      ! processor number
+         sind = narea
+         eind = narea
+      ELSE                     ! processors total number
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. the total number of processors ijsplt
+      DO jn = sind, eind
+         ! Set logical unit
+         j_id = numid(jn - narea + 1)
+         ! Set indices for the SUM control
+         IF( .NOT. lsp_area ) THEN
+            IF (lk_mpp )   THEN
+               nictls = MAX( 1, nlditl(jn) - overlap )
+               nictle = nleitl(jn) + overlap * MIN( 1, nlcitl(jn) - nleitl(jn)) 
+               njctls = MAX( 1, nldjtl(jn) - overlap )
+               njctle = nlejtl(jn) + overlap * MIN( 1, nlcjtl(jn) - nlejtl(jn))
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(jn) == -1 .OR. ibonitl(jn) == 2 ) nictls = MAX(2, nictls)
+               IF( ibonjtl(jn) == -1 .OR. ibonjtl(jn) == 2 ) njctls = MAX(2, njctls)
+               IF( ibonitl(jn) ==  1 .OR. ibonitl(jn) == 2 ) nictle = MIN(nictle, nleitl(jn) - 1)
+               IF( ibonjtl(jn) ==  1 .OR. ibonjtl(jn) == 2 ) njctle = MIN(njctle, nlejtl(jn) - 1)
+            ELSE
+               nictls = MAX( 1, nimpptl(jn) + nlditl(jn) - 1 - overlap )
+               nictle = nimpptl(jn) + nleitl(jn) - 1 + overlap * MIN( 1, nlcitl(jn) - nleitl(jn) ) 
+               njctls = MAX( 1, njmpptl(jn) + nldjtl(jn) - 1 - overlap )
+               njctle = njmpptl(jn) + nlejtl(jn) - 1 + overlap * MIN( 1, nlcjtl(jn) - nlejtl(jn) ) 
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(jn) == -1 .OR. ibonitl(jn) == 2 ) nictls = MAX(2, nictls)
+               IF( ibonjtl(jn) == -1 .OR. ibonjtl(jn) == 2 ) njctls = MAX(2, njctls)
+               IF( ibonitl(jn) ==  1 .OR. ibonitl(jn) == 2 ) nictle = MIN(nictle, nimpptl(jn) + nleitl(jn) - 2)
+               IF( ibonjtl(jn) ==  1 .OR. ibonjtl(jn) == 2 ) njctle = MIN(njctle, njmpptl(jn) + nlejtl(jn) - 2)
+            ENDIF
+         ENDIF
+
+         IF ( clinfo3 == 'tra' )  THEN
+             zvctl1 = t_ctll(jn)
+             zvctl2 = s_ctll(jn)
+         ELSEIF ( clinfo3 == 'dyn' )   THEN
+             zvctl1 = u_ctll(jn)
+             zvctl2 = v_ctll(jn)
+         ENDIF
+
+         ! Compute the sum control
+         ! 2D arrays
+         IF( PRESENT(tab2d_1) )   THEN
+            zsum1 = SUM( ztab2d_1(nictls:nictle,njctls:njctle)*zmask1(nictls:nictle,njctls:njctle,1) )
+            zsum2 = SUM( ztab2d_2(nictls:nictle,njctls:njctle)*zmask2(nictls:nictle,njctls:njctle,1) )
+         ENDIF
+
+         ! 3D arrays
+         IF( PRESENT(tab3d_1) )   THEN
+            zsum1 = SUM( ztab3d_1(nictls:nictle,njctls:njctle,1:kdir)*zmask1(nictls:nictle,njctls:njctle,1:kdir) )
+            zsum2 = SUM( ztab3d_2(nictls:nictle,njctls:njctle,1:kdir)*zmask2(nictls:nictle,njctls:njctle,1:kdir) )
+         ENDIF
+
+         ! Print the result
+         IF( PRESENT(clinfo3) )   THEN
+            WRITE(j_id,FMT='(a,D23.16,3x,a,D23.16)')clinfo1, zsum1-zvctl1, cl2, zsum2-zvctl2
+            SELECT CASE( clinfo3 )
+            CASE ( 'tra-ta' ) 
+               t_ctll(jn) = zsum1
+            CASE ( 'tra' ) 
+                t_ctll(jn) = zsum1
+                s_ctll(jn) = zsum2
+            CASE ( 'dyn' ) 
+                u_ctll(jn) = zsum1
+                v_ctll(jn) = zsum2 
+            END SELECT
+         ELSEIF ( PRESENT(clinfo2) .OR. PRESENT(tab2d_2) .OR. PRESENT(tab3d_2) )   THEN
+            WRITE(j_id,FMT='(a,D23.16,3x,a,D23.16)')clinfo1, zsum1, cl2, zsum2
+         ELSE
+            WRITE(j_id,FMT='(a,D23.16)')clinfo1, zsum1
+         ENDIF
+
+      ENDDO
+
+   END SUBROUTINE prt_ctl
+
+
+   SUBROUTINE prt_ctl_info (clinfo1, ivar1, clinfo2, ivar2, itime)
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_info  ***
+      !!
+      !! ** Purpose : - print information without any computation
+      !!
+      !! ** Action  : - input arguments
+      !!                    clinfo1 : information about the ivar1
+      !!                    ivar1   : value to print
+      !!                    clinfo2 : information about the ivar2
+      !!                    ivar2   : value to print
+      !!
+      !! History :
+      !!   9.0  !  05-07  (C. Talandier) original code
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      CHARACTER (len=*), INTENT(in) ::   clinfo1
+      INTEGER          , INTENT(in), OPTIONAL ::   ivar1
+      CHARACTER (len=*), INTENT(in), OPTIONAL ::   clinfo2
+      INTEGER          , INTENT(in), OPTIONAL ::   ivar2
+      INTEGER          , INTENT(in), OPTIONAL ::   itime
+
+      !! * Local declarations
+      INTEGER :: jn, sind, eind, iltime, j_id
+      !!----------------------------------------------------------------------
+
+      IF( lk_mpp )   THEN
+         ! processor number
+         sind = narea
+         eind = narea
+      ELSE
+         ! total number of processors
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Set to zero arrays at each new time step
+      IF( PRESENT(itime) )   THEN
+         iltime = itime
+         IF( iltime > ktime )   THEN
+            t_ctll(:) = 0.e0   ;   s_ctll(:) = 0.e0
+            u_ctll(:) = 0.e0   ;   v_ctll(:) = 0.e0
+            ktime = iltime
+         ENDIF
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. number of processors ijsplt
+      DO jn = sind, eind
+         
+         ! Set logical unit
+         j_id = numid(jn - narea + 1)
+
+         IF( PRESENT(ivar1) .AND. PRESENT(clinfo2) .AND. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, clinfo2, ivar2
+         ELSEIF ( PRESENT(ivar1) .AND. PRESENT(clinfo2) .AND. .NOT. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, clinfo2
+         ELSEIF ( PRESENT(ivar1) .AND. .NOT. PRESENT(clinfo2) .AND. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1, ivar2
+         ELSEIF ( PRESENT(ivar1) .AND. .NOT. PRESENT(clinfo2) .AND. .NOT. PRESENT(ivar2) )   THEN
+            WRITE(j_id,*)clinfo1, ivar1
+         ELSE
+            WRITE(j_id,*)clinfo1
+         ENDIF
+
+      ENDDO
+
+
+      END SUBROUTINE prt_ctl_info
+
+   SUBROUTINE prt_ctl_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_init  ***
+      !!
+      !! ** Purpose :   open ASCII files & compute indices
+      !!
+      !! History :
+      !!   9.0  !  05-07  (C. Talandier) original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   jn, sind, eind, j_id
+      CHARACTER (len=28) :: clfile_out
+      CHARACTER (len=23) :: clb_name
+      CHARACTER (len=19) :: cl_run
+      !!----------------------------------------------------------------------
+
+      ! Allocate arrays
+      ALLOCATE(nlditl (ijsplt))
+      ALLOCATE(nldjtl (ijsplt))
+      ALLOCATE(nleitl (ijsplt))
+      ALLOCATE(nlejtl (ijsplt))
+      ALLOCATE(nimpptl(ijsplt))
+      ALLOCATE(njmpptl(ijsplt))
+      ALLOCATE(nlcitl (ijsplt))
+      ALLOCATE(nlcjtl (ijsplt))
+      ALLOCATE(t_ctll (ijsplt))
+      ALLOCATE(s_ctll (ijsplt))
+      ALLOCATE(u_ctll (ijsplt))
+      ALLOCATE(v_ctll (ijsplt))
+      ALLOCATE(ibonitl(ijsplt))
+      ALLOCATE(ibonjtl(ijsplt))
+
+      ! Initialization 
+      t_ctll(:)=0.e0
+      s_ctll(:)=0.e0
+      u_ctll(:)=0.e0
+      v_ctll(:)=0.e0
+      ktime = 1
+
+      IF( lk_mpp ) THEN
+         sind = narea
+         eind = narea
+         clb_name = "('mpp.output_',I4.4)"
+         cl_run = 'MULTI processor run'
+         ! use indices for each area computed by mpp_init subroutine
+         nlditl(:) = nldit(:) 
+         nleitl(:) = nleit(:) 
+         nldjtl(:) = nldjt(:) 
+         nlejtl(:) = nlejt(:) 
+         !
+         nimpptl(:) = nimppt(:)
+         njmpptl(:) = njmppt(:)
+         !
+         nlcitl(:) = nlcit(:)
+         nlcjtl(:) = nlcjt(:)
+         !
+         ibonitl(:) = ibonit(:)
+         ibonjtl(:) = ibonjt(:)
+      ELSE
+         sind = 1
+         eind = ijsplt
+         clb_name = "('mono.output_',I4.4)"
+         cl_run = 'MONO processor run '
+         ! compute indices for each area as done in mpp_init subroutine
+         CALL sub_dom
+      ENDIF
+
+      ALLOCATE(numid(eind-sind+1))
+
+      DO jn = sind, eind
+         WRITE(clfile_out,FMT=clb_name) jn-1
+         CALL ctlopn( numid(jn -narea + 1), clfile_out, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .FALSE., 1 )
+         j_id = numid(jn -narea + 1)
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                 L O D Y C - I P S L'
+         WRITE(j_id,*) '                     O P A model'
+         WRITE(j_id,*) '            Ocean General Circulation Model'
+         WRITE(j_id,*) '               version OPA 9.0  (2005) '
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                   PROC number: ', jn
+         WRITE(j_id,*)
+         WRITE(j_id,FMT="(19x,a20)")cl_run
+
+         ! Print the SUM control indices
+         IF( .NOT. lsp_area )   THEN
+            nictls = nimpptl(jn) + nlditl(jn) - 1
+            nictle = nimpptl(jn) + nleitl(jn) - 1
+            njctls = njmpptl(jn) + nldjtl(jn) - 1
+            njctle = njmpptl(jn) + nlejtl(jn) - 1
+         ENDIF
+         WRITE(j_id,*) 
+         WRITE(j_id,*) 'prt_ctl :  Sum control indices'
+         WRITE(j_id,*) '~~~~~~~'
+         WRITE(j_id,*)
+         WRITE(j_id,9000)'                                nlej   = ', nlejtl(jn), '              '
+         WRITE(j_id,9000)'                  ------------- njctle = ', njctle, ' -------------'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9002)'           nictls = ', nictls,  '                           nictle = ', nictle
+         WRITE(j_id,9002)'           nldi   = ', nlditl(jn),  '                           nlei   = ', nleitl(jn)
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9004)'  njmpp  = ',njmpptl(jn),'   ------------- njctls = ', njctls, ' -------------'
+         WRITE(j_id,9003)'           nimpp  = ', nimpptl(jn), '        nldj   = ', nldjtl(jn), '              '
+         WRITE(j_id,*)
+         WRITE(j_id,*)
+
+9000     FORMAT(a41,i4.4,a14)
+9001     FORMAT(a59)
+9002     FORMAT(a20,i4.4,a36,i3.3)
+9003     FORMAT(a20,i4.4,a17,i4.4)
+9004     FORMAT(a11,i4.4,a26,i4.4,a14)
+      ENDDO
+
+   END SUBROUTINE prt_ctl_init
+
+
+   SUBROUTINE sub_dom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sub_dom  ***
+      !!                    
+      !! ** Purpose :   Lay out the global domain over processors. 
+      !!                CAUTION: 
+      !!                This part has been extracted from the mpp_init
+      !!                subroutine and names of variables/arrays have been 
+      !!                slightly changed to avoid confusion but the computation
+      !!                is exactly the same. Any modification about indices of
+      !!                each sub-domain in the mppini.F90 module should be reported 
+      !!                here.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!                Periodic condition is a function of the local domain position
+      !!                (global boundary or neighbouring domain) and of the global
+      !!                periodic
+      !!                Type :         jperio global periodic condition
+      !!                               nperio local  periodic condition
+      !!
+      !! ** Action  : - set domain parameters
+      !!                    nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlcil      : first dimension
+      !!                    nlcjl      : second dimension
+      !!                    nbondil    : mark for "east-west local boundary"
+      !!                    nbondjl    : mark for "north-south local boundary"
+      !!
+      !! History :
+      !!        !  94-11  (M. Guyon)  Original code
+      !!        !  95-04  (J. Escobar, M. Imbard)
+      !!        !  98-02  (M. Guyon)  FETI method
+      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+      !!   8.5  !  02-08  (G. Madec)  F90 : free form
+      !!----------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji, jj, jn               ! dummy loop indices
+      INTEGER ::   &
+         ii, ij,                         &  ! temporary integers
+         irestil, irestjl,               &  !    "          "
+         ijpi  , ijpj, nlcil,            &  ! temporary logical unit
+         nlcjl , nbondil, nbondjl,       &
+         nrecil, nrecjl, nldil, nleil, nldjl, nlejl
+
+      INTEGER, DIMENSION(:,:), ALLOCATABLE ::   &
+         iimpptl, ijmpptl, ilcitl, ilcjtl       ! temporary workspace
+      REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      !  1. Dimension arrays for subdomains
+      ! -----------------------------------
+      !  Computation of local domain sizes ilcitl() ilcjtl()
+      !  These dimensions depend on global sizes isplt,jsplt and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array (cf. par_oce.F90).
+
+      ijpi = ( jpiglo-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
+      ijpj = ( jpjglo-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj
+
+      ALLOCATE(ilcitl (isplt,jsplt))
+      ALLOCATE(ilcjtl (isplt,jsplt))
+
+      nrecil  = 2 * jpreci
+      nrecjl  = 2 * jprecj
+      irestil = MOD( jpiglo - nrecil , isplt )
+      irestjl = MOD( jpjglo - nrecjl , jsplt )
+
+      IF(  irestil == 0 )   irestil = isplt
+      DO jj = 1, jsplt
+         DO ji = 1, irestil
+            ilcitl(ji,jj) = ijpi
+         END DO
+         DO ji = irestil+1, isplt
+            ilcitl(ji,jj) = ijpi -1
+         END DO
+      END DO
+      
+      IF( irestjl == 0 )   irestjl = jsplt
+      DO ji = 1, isplt
+         DO jj = 1, irestjl
+            ilcjtl(ji,jj) = ijpj
+         END DO
+         DO jj = irestjl+1, jsplt
+            ilcjtl(ji,jj) = ijpj -1
+         END DO
+      END DO
+      
+      zidom = nrecil
+      DO ji = 1, isplt
+         zidom = zidom + ilcitl(ji,1) - nrecil
+      END DO
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)' sum ilcitl(i,1) = ', zidom, ' jpiglo = ', jpiglo
+      
+      zjdom = nrecjl
+      DO jj = 1, jsplt
+         zjdom = zjdom + ilcjtl(1,jj) - nrecjl
+      END DO
+      IF(lwp) WRITE(numout,*)' sum ilcitl(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      IF(lwp) WRITE(numout,*)
+      
+
+      !  2. Index arrays for subdomains
+      ! -------------------------------
+
+      ALLOCATE(iimpptl(isplt,jsplt))
+      ALLOCATE(ijmpptl(isplt,jsplt))
+      
+      iimpptl(:,:) = 1
+      ijmpptl(:,:) = 1
+      
+      IF( isplt > 1 ) THEN
+         DO jj = 1, jsplt
+            DO ji = 2, isplt
+               iimpptl(ji,jj) = iimpptl(ji-1,jj) + ilcitl(ji-1,jj) - nrecil
+            END DO
+         END DO
+      ENDIF
+
+      IF( jsplt > 1 ) THEN
+         DO jj = 2, jsplt
+            DO ji = 1, isplt
+               ijmpptl(ji,jj) = ijmpptl(ji,jj-1)+ilcjtl(ji,jj-1)-nrecjl
+            END DO
+         END DO
+      ENDIF
+      
+      ! 3. Subdomain description
+      ! ------------------------
+
+      DO jn = 1, ijsplt
+         ii = 1 + MOD( jn-1, isplt )
+         ij = 1 + (jn-1) / isplt
+         nimpptl(jn) = iimpptl(ii,ij)
+         njmpptl(jn) = ijmpptl(ii,ij)
+         nlcitl (jn) = ilcitl (ii,ij)     
+         nlcil       = nlcitl (jn)     
+         nlcjtl (jn) = ilcjtl (ii,ij)     
+         nlcjl       = nlcjtl (jn)
+         nbondjl = -1                                    ! general case
+         IF( jn   >  isplt          )   nbondjl = 0      ! first row of processor
+         IF( jn   >  (jsplt-1)*isplt )  nbondjl = 1     ! last  row of processor
+         IF( jsplt == 1             )   nbondjl = 2      ! one processor only in j-direction
+         ibonjtl(jn) = nbondjl
+         
+         nbondil = 0                                     ! 
+         IF( MOD( jn, isplt ) == 1 )   nbondil = -1      !
+         IF( MOD( jn, isplt ) == 0 )   nbondil =  1      !
+         IF( isplt            == 1 )   nbondil =  2      ! one processor only in i-direction
+         ibonitl(jn) = nbondil
+         
+         nldil =  1   + jpreci
+         nleil = nlcil - jpreci
+         IF( nbondil == -1 .OR. nbondil == 2 )   nldil = 1
+         IF( nbondil ==  1 .OR. nbondil == 2 )   nleil = nlcil
+         nldjl =  1   + jprecj
+         nlejl = nlcjl - jprecj
+         IF( nbondjl == -1 .OR. nbondjl == 2 )   nldjl = 1
+         IF( nbondjl ==  1 .OR. nbondjl == 2 )   nlejl = nlcjl
+         nlditl(jn) = nldil
+         nleitl(jn) = nleil
+         nldjtl(jn) = nldjl
+         nlejtl(jn) = nlejl
+      END DO
+
+      DEALLOCATE(iimpptl)
+      DEALLOCATE(ijmpptl)
+      DEALLOCATE(ilcitl)
+      DEALLOCATE(ilcjtl)
+
+   END SUBROUTINE sub_dom
+
+END MODULE prtctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/restart.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/restart.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/restart.F90	(revision 4536)
@@ -0,0 +1,385 @@
+MODULE restart
+   !!======================================================================
+   !!                     ***  MODULE  restart  ***
+   !! Ocean restart :  write the ocean restart file
+   !!======================================================================
+   !! History :        !  99-11  (M. Imbard)  Original code
+   !!             8.5  !  02-08  (G. Madec)  F90: Free form
+   !!             9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!             9.0  !  06-07  (S. Masson)  use IOM for restart
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   rst_opn    : open the ocean restart file
+   !!   rst_write  : write the ocean restart file
+   !!   rst_read   : read the ocean restart file
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE oce             ! ocean dynamics and tracers 
+   USE phycst          ! physical constants
+   USE daymod          ! calendar
+   USE ice_oce         ! ice variables
+   USE blk_oce         ! bulk variables
+   USE cpl_oce, ONLY : lk_cpl              !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE ini1d           ! re-initialization of u-v mask for the 1D configuration
+   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
+   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   rst_opn    ! routine called by step module
+   PUBLIC   rst_write  ! routine called by step module
+   PUBLIC   rst_read   ! routine called by opa  module
+
+   LOGICAL, PUBLIC ::   lrst_oce                  !: logical to control the oce restart write 
+   INTEGER, PUBLIC ::   numror, numrow            !: logical unit for cean restart (read and write)
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/restart.F90,v 1.27 2007/06/05 10:35:19 opalod Exp $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE rst_opn( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rst_opn  ***
+      !!                     
+      !! ** Purpose : + initialization (should be read in the namelist) of nitrst 
+      !!              + open the restart when we are one time step before nitrst
+      !!                   - restart header is defined when kt = nitrst-1
+      !!                   - restart data  are written when kt = nitrst
+      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !!
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN   ! default initialization, to do: should be read in the namelist...
+         nitrst = nitend        ! to do: should be read in the namelist in a cleaver way...
+         lrst_oce = .FALSE.
+      ENDIF
+
+      IF    ( kt == nitrst-1 .AND. lrst_oce         ) THEN
+         CALL ctl_stop( 'rst_opn: we cannot create an ocean restart at every time step',    &
+            &           'if the run has more than one time step!!!' )
+         numrow = 0
+      ELSEIF( kt == nitrst-1 .OR.  nitend == nit000 ) THEN   ! beware if model runs only one time step
+         ! beware of the format used to write kt (default is i8.8, that should be large enough)
+         IF( nitrst > 1.0e9 ) THEN   
+            WRITE(clkt,*) nitrst
+         ELSE
+            WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart"
+         IF(lwp) THEN
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jpnf90 )
+               WRITE(numout,*) '             open ocean restart.output NetCDF file: '//clname
+            CASE ( jprstdimg )
+               WRITE(numout,*) '             open ocean restart.output binary file: '//clname
+            END SELECT
+            IF( kt == nitrst-1 ) THEN
+               WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
+            ELSE
+               WRITE(numout,*) '             kt = ', kt,' date= ', ndastp
+            ENDIF
+         ENDIF
+
+         CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib )
+         lrst_oce = .TRUE.
+      ENDIF
+      !
+   END SUBROUTINE rst_opn
+
+
+   SUBROUTINE rst_write( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rstwrite  ***
+      !!                     
+      !! ** Purpose :   Write restart fields in the format corresponding to jprstlib
+      !!
+      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
+      !!      file, save fields which are necessary for restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step
+      !!----------------------------------------------------------------------
+
+      ! calendar control
+      CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp) )   ! time-step 
+      CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp) )   ! date
+      CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
+      !                                                                     ! the begining of the run [s]
+      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rdt               )   ! dynamics time step
+      CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1)         )   ! surface tracer time step
+
+      ! prognostic variables
+      CALL iom_rstput( kt, nitrst, numrow, 'ub'     , ub      )   
+      CALL iom_rstput( kt, nitrst, numrow, 'vb'     , vb      )
+      CALL iom_rstput( kt, nitrst, numrow, 'tb'     , tb      )
+      CALL iom_rstput( kt, nitrst, numrow, 'sb'     , sb      )
+      CALL iom_rstput( kt, nitrst, numrow, 'rotb'   , rotb    )
+      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb   )
+      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un      )
+      CALL iom_rstput( kt, nitrst, numrow, 'vn'     , vn      )
+      IF( lk_vvl ) CALL iom_rstput( kt, nitrst, numrow, 'wn'     , wn      )
+      CALL iom_rstput( kt, nitrst, numrow, 'tn'     , tn      )
+      CALL iom_rstput( kt, nitrst, numrow, 'sn'     , sn      )
+      CALL iom_rstput( kt, nitrst, numrow, 'rotn'   , rotn    )
+      CALL iom_rstput( kt, nitrst, numrow, 'hdivn'  , hdivn   )
+
+#if defined key_ice_lim        
+      CALL iom_rstput( kt, nitrst, numrow, 'nfice'  , REAL( nfice, wp) )   !  ice computation frequency
+      CALL iom_rstput( kt, nitrst, numrow, 'sst_io' , sst_io  )
+      CALL iom_rstput( kt, nitrst, numrow, 'sss_io' , sss_io  )
+      CALL iom_rstput( kt, nitrst, numrow, 'u_io'   , u_io    )
+      CALL iom_rstput( kt, nitrst, numrow, 'v_io'   , v_io    )
+# if defined key_coupled
+      CALL iom_rstput( kt, nitrst, numrow, 'alb_ice', alb_ice )
+# endif
+#endif
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core 
+      CALL iom_rstput( kt, nitrst, numrow, 'nfbulk' , REAL( nfbulk, wp) )   !  bulk computation frequency
+      CALL iom_rstput( kt, nitrst, numrow, 'gsst'   , gsst    )
+#endif
+
+      IF( nn_dynhpg_rst == 1 .OR. lk_vvl ) THEN
+         CALL iom_rstput( kt, nitrst, numrow, 'rhd' , rhd  )
+         CALL iom_rstput( kt, nitrst, numrow, 'rhop', rhop )
+         IF( ln_zps ) THEN
+            CALL iom_rstput( kt, nitrst, numrow, 'gtu' , gtu )
+            CALL iom_rstput( kt, nitrst, numrow, 'gsu' , gsu )
+            CALL iom_rstput( kt, nitrst, numrow, 'gru' , gru )
+            CALL iom_rstput( kt, nitrst, numrow, 'gtv' , gtv )
+            CALL iom_rstput( kt, nitrst, numrow, 'gsv' , gsv )
+            CALL iom_rstput( kt, nitrst, numrow, 'grv' , grv )
+         ENDIF
+      ENDIF
+
+      IF( kt == nitrst ) THEN
+         CALL iom_close( numrow )     ! close the restart file (only at last time step)
+         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
+      ENDIF
+      !
+   END SUBROUTINE rst_write
+
+
+   SUBROUTINE rst_read
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read  ***
+      !! 
+      !! ** Purpose :   Read files for restart (format fixed by jprstlib )
+      !! 
+      !! ** Method  :   Read the previous fields on the NetCDF/binary file 
+      !!      the first record indicates previous characterics
+      !!      after control with the present run, we read :
+      !!      - prognostic variables on the second record
+      !!      - elliptic solver arrays 
+      !!      - barotropic stream function arrays ("key_dynspg_rl" defined)
+      !!        or free surface arrays 
+      !!      - tke arrays (lk_zdftke=T)
+      !!      for this last three records,  the previous characteristics 
+      !!      could be different with those used in the present run. 
+      !!
+      !!   According to namelist parameter nrstdt,
+      !!       nrstdt = 0  no control on the date (nit000 is  arbitrary).
+      !!       nrstdt = 1  we verify that nit000 is equal to the last
+      !!                   time step of previous run + 1.
+      !!       In both those options, the  exact duration of the experiment
+      !!       since the beginning (cumulated duration of all previous restart runs)
+      !!       is not stored in the restart and is assumed to be (nit000-1)*rdt.
+      !!       This is valid is the time step has remained constant.
+      !!
+      !!       nrstdt = 2  the duration of the experiment in days (adatrj)
+      !!                    has been stored in the restart file.
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zcoef, zkt, zrdt, zrdttra1, zndastp, znfice, znfbulk
+#if defined key_ice_lim
+      INTEGER  ::   ji, jj
+#endif
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN                                             ! Contol prints
+         WRITE(numout,*)
+         SELECT CASE ( jprstlib )
+         CASE ( jpnf90 )
+            WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
+         CASE ( jprstdimg )
+            WRITE(numout,*) 'rst_read : read oce binary restart file'
+         END SELECT
+         WRITE(numout,*) '~~~~~~~~'
+
+         WRITE(numout,*) ' *** Info on the present job : '
+         WRITE(numout,*) '   time-step           : ', nit000
+         WRITE(numout,*) '   date ndastp         : ', ndastp
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** restart option'
+         SELECT CASE ( nrstdt )
+         CASE ( 0 ) 
+            WRITE(numout,*) ' nrstdt = 0 no control of nit000'
+         CASE ( 1 ) 
+            WRITE(numout,*) ' nrstdt = 1 we control the date of nit000'
+         CASE ( 2 )
+            WRITE(numout,*) ' nrstdt = 2 the date adatrj is read in restart file'
+         CASE DEFAULT
+            WRITE(numout,*) '  ===>>>> nrstdt not equal 0, 1 or 2 : no control of the date'
+            WRITE(numout,*) '  =======                  ========='
+         END SELECT
+         WRITE(numout,*)
+      ENDIF
+
+      CALL iom_open( 'restart', numror, kiolib = jprstlib )
+
+      ! Calendar informations
+      CALL iom_get( numror, 'kt'     , zkt      )   ! time-step 
+      CALL iom_get( numror, 'ndastp' , zndastp  )   ! date
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** Info on the restart file read : '
+         WRITE(numout,*) '   time-step           : ', NINT( zkt )
+         WRITE(numout,*) '   date ndastp         : ', NINT( zndastp )
+         WRITE(numout,*)
+      ENDIF
+      ! Control of date
+      IF( nit000 - NINT( zkt )  /= 1 .AND. nrstdt /= 0 ) &
+           & CALL ctl_stop( ' ===>>>> : problem with nit000 for the restart', &
+           & ' verify the restart file or rerun with nrstdt = 0 (namelist)' )
+      ! re-initialisation of  adatrj0
+      adatrj0 = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+      IF ( nrstdt == 2 ) THEN
+         ! by default ndatsp has been set to ndate0 in dom_nam
+         ! ndate0 has been read in the namelist (standard OPA 8)
+         ! here when nrstdt=2 we keep the  final date of previous run
+         ndastp = NINT( zndastp )
+         CALL iom_get( numror, 'adatrj', adatrj )   ! number of elapsed days since the begining of last run
+      ENDIF
+      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
+      IF( iom_varid( numror, 'rdt' ) > 0 )   THEN
+         CALL iom_get( numror, 'rdt', zrdt )
+         IF( zrdt /= rdt )   neuler = 0
+      ENDIF
+      IF( iom_varid( numror, 'rdttra1' ) > 0 )   THEN
+         CALL iom_get( numror, 'rdttra1', zrdttra1 )
+         IF( zrdttra1 /= rdttra(1) )   neuler = 0
+      ENDIF
+      !
+      !                                                       ! Read prognostic variables
+      CALL iom_get( numror, jpdom_autoglo, 'ub'   , ub    )        ! before i-component velocity
+      CALL iom_get( numror, jpdom_autoglo, 'vb'   , vb    )        ! before j-component velocity
+      CALL iom_get( numror, jpdom_autoglo, 'tb'   , tb    )        ! before temperature
+      CALL iom_get( numror, jpdom_autoglo, 'sb'   , sb    )        ! before salinity
+      CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb  )        ! before curl
+      CALL iom_get( numror, jpdom_autoglo, 'hdivb', hdivb )        ! before horizontal divergence
+      CALL iom_get( numror, jpdom_autoglo, 'un'   , un    )        ! now    i-component velocity
+      CALL iom_get( numror, jpdom_autoglo, 'vn'   , vn    )        ! now    j-component velocity
+      IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'wn'   , wn    )        ! now    k-component velocity
+      CALL iom_get( numror, jpdom_autoglo, 'tn'   , tn    )        ! now    temperature
+      CALL iom_get( numror, jpdom_autoglo, 'sn'   , sn    )        ! now    salinity
+      CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn  )        ! now    curl
+      CALL iom_get( numror, jpdom_autoglo, 'hdivn', hdivn )        ! now    horizontal divergence
+
+
+      IF( neuler == 0 ) THEN                                  ! Euler restart (neuler=0)
+         tb   (:,:,:) = tn   (:,:,:)                             ! all before fields set to now field values
+         sb   (:,:,:) = sn   (:,:,:)
+         ub   (:,:,:) = un   (:,:,:)
+         vb   (:,:,:) = vn   (:,:,:)
+         rotb (:,:,:) = rotn (:,:,:)
+         hdivb(:,:,:) = hdivn(:,:,:)
+      ENDIF
+
+      !!sm: TO BE MOVED IN NEW SURFACE MODULE...
+
+#if defined key_ice_lim
+      ! Louvain La Neuve Sea Ice Model
+      IF( iom_varid( numror, 'nfice' ) > 0 ) then 
+         CALL iom_get( numror             , 'nfice'  , znfice  )   ! ice computation frequency
+         CALL iom_get( numror, jpdom_autoglo, 'sst_io' , sst_io  )
+         CALL iom_get( numror, jpdom_autoglo, 'sss_io' , sss_io  )
+         CALL iom_get( numror, jpdom_autoglo, 'u_io'   , u_io    )
+         CALL iom_get( numror, jpdom_autoglo, 'v_io'   , v_io    )
+# if defined key_coupled
+         CALL iom_get( numror, jpdom_autoglo, 'alb_ice', alb_ice )
+# endif
+         IF( znfice /= REAL( nfice, wp ) ) THEN      ! if nfice changed between 2 runs
+            zcoef = REAL( nfice-1, wp ) / znfice
+            sst_io(:,:) = zcoef * sst_io(:,:)
+            sss_io(:,:) = zcoef * sss_io(:,:)
+            u_io  (:,:) = zcoef * u_io  (:,:)
+            v_io  (:,:) = zcoef * v_io  (:,:)
+         ENDIF
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'rst_read :  LLN sea Ice Model => Ice initialization'
+         IF(lwp) WRITE(numout,*)
+         zcoef = REAL( nfice-1, wp )
+         sst_io(:,:) = zcoef *( tn(:,:,1) + rt0 )          !!bug a explanation is needed here!
+         sss_io(:,:) = zcoef *  sn(:,:,1)
+         zcoef = 0.5 * REAL( nfice-1, wp )
+         DO jj = 2, jpj
+            DO ji = fs_2, jpi   ! vector opt.
+               u_io(ji,jj) = zcoef * ( un(ji-1,jj  ,1) + un(ji-1,jj-1,1) )
+               v_io(ji,jj) = zcoef * ( vn(ji  ,jj-1,1) + vn(ji-1,jj-1,1) )
+            END DO
+         END DO
+# if defined key_coupled
+         alb_ice(:,:) = 0.8 * tmask(:,:,1)
+# endif
+      ENDIF
+#endif
+#if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core 
+      ! Louvain La Neuve Sea Ice Model
+      IF( iom_varid( numror, 'nfbulk' ) > 0 ) THEN 
+         CALL iom_get( numror             , 'nfbulk', znfbulk )   ! bulk computation frequency
+         CALL iom_get( numror, jpdom_autoglo, 'gsst'  , gsst    )
+         IF( znfbulk /= REAL(nfbulk, wp) ) THEN      ! if you change nfbulk between 2 runs
+            zcoef = REAL( nfbulk-1, wp ) / znfbulk
+            gsst(:,:) = zcoef * gsst(:,:)
+         ENDIF
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'rst_read :  LLN sea Ice Model => Ice initialization'
+         IF(lwp) WRITE(numout,*)
+         gsst(:,:) = REAL( nfbulk - 1, wp )*( tn(:,:,1) + rt0 )
+      ENDIF
+#endif
+
+      !!sm: end of TO BE MOVED IN NEW SURFACE MODULE...
+
+      IF( iom_varid( numror, 'rhd' ) > 0 ) THEN
+         CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd  )
+         CALL iom_get( numror, jpdom_autoglo, 'rhop', rhop )
+      ELSE
+         CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
+      ENDIF
+      IF( ln_zps .AND. .NOT. lk_cfg_1d ) THEN
+         IF( iom_varid( numror, 'gtu' ) > 0 ) THEN
+            CALL iom_get( numror, jpdom_autoglo, 'gtu' , gtu )
+            CALL iom_get( numror, jpdom_autoglo, 'gsu' , gsu )
+            CALL iom_get( numror, jpdom_autoglo, 'gru' , gru )
+            CALL iom_get( numror, jpdom_autoglo, 'gtv' , gtv )
+            CALL iom_get( numror, jpdom_autoglo, 'gsv' , gsv )
+            CALL iom_get( numror, jpdom_autoglo, 'grv' , grv )
+         ELSE
+            CALL zps_hde( nit000, tb , sb , rhd,   &  ! Partial steps: before Horizontal DErivative
+               &                  gtu, gsu, gru,   &  ! of t, s, rd at the bottom ocean level
+               &                  gtv, gsv, grv )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE rst_read
+
+
+   !!=====================================================================
+END MODULE restart
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/sms.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/sms.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/sms.F90	(revision 4536)
@@ -0,0 +1,16 @@
+MODULE sms
+   !!======================================================================
+   !!                       ***  MODULE sms  ***
+   !!  Dummy module
+   !!  Declaration : passive tracers declaration
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                     NO passive tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+END MODULE sms
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/step.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/step.F90	(revision 4536)
@@ -0,0 +1,457 @@
+MODULE step
+   !!======================================================================
+   !!                       ***  MODULE step  ***
+   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
+   !!======================================================================
+   !! History :        !  1991-03  ()  Original code
+   !!                  !  1991-11  (G. Madec)
+   !!                  !  1992-06  (M. Imbard)  add a first output record
+   !!                  !  1996-04  (G. Madec)  introduction of dynspg
+   !!                  !  1996-04  (M.A. Foujols)  introduction of passive tracer
+   !!             8.0  !  1997-06  (G. Madec)  new architecture of call
+   !!             8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+   !!             8.2  !  1999-02  (G. Madec, N. Grima)  hpg implicit
+   !!             8.2  !  2000-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+   !!   NEMO      1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
+   !!              -   !  2004-08  (C. Talandier) New trends organization
+   !!              -   !  2005-01  (C. Ethe) Add the KPP closure scheme
+   !!              -   !  2005-11  (V. Garnier) Surface pressure gradient organization
+   !!              -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
+   !!             2.0  !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!              -   !  2006-07  (S. Masson)  restart using iom
+   !!             2.4  !  2008-01  (G. Madec) Merge TRA-TRC
+   !!----------------------------------------------------------------------
+   !!   stp            : OPA system time-stepping
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE zdf_oce         ! ocean vertical physics variables
+   USE ldftra_oce      ! ocean tracer   - trends
+   USE ldfdyn_oce      ! ocean dynamics - trends
+   USE cpl_oce         ! coupled ocean-atmosphere variables
+   USE in_out_manager  ! I/O manager
+   USE iom
+   USE lbclnk
+
+   USE daymod          ! calendar                         (day     routine)
+
+   USE dtatem          ! ocean temperature data           (dta_tem routine)
+   USE dtasal          ! ocean salinity    data           (dta_sal routine)
+   USE dtasst          ! ocean sea surface temperature    (dta_sst routine)
+   USE dtasss          ! ocean sea surface salinity       (dta_sss routine)
+   USE taumod          ! surface stress                   (tau     routine)
+   USE flxmod          ! thermohaline fluxes              (flx     routine)
+   USE ocesbc          ! thermohaline fluxes              (oce_sbc routine)
+   USE flxrnf          ! runoffs                          (flx_rnf routine)
+   USE flxfwb          ! freshwater budget correction     (flx_fwb routine)
+   USE closea          ! closed sea freshwater budget     (flx_clo routine)
+   USE ocfzpt          ! surface ocean freezing point    (oc_fz_pt routine)
+
+   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
+
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+   USE trabbc          ! bottom boundary condition        (tra_bbc routine)
+   USE trabbl          ! bottom boundary layer            (tra_bbl routine)
+   USE tradmp          ! internal damping                 (tra_dmp routine)
+   USE traadv          ! advection scheme control     (tra_adv_ctl routine)
+   USE traldf          ! lateral mixing                   (tra_ldf routine)
+   USE cla             ! cross land advection             (tra_cla routine)
+   !   zdfkpp          ! KPP non-local tracer fluxes      (tra_kpp routine)
+   USE trazdf          ! vertical mixing                  (tra_zdf routine)
+   USE tranxt          ! time-stepping                    (tra_nxt routine)
+   USE tranpc          ! non-penetrative convection       (tra_npc routine)
+
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
+
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg_oce      ! surface pressure gradient        (dyn_spg routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
+   USE dynnxt          ! time-stepping                    (dyn_nxt routine)
+
+   USE obc_par         ! open boundary condition variables
+   USE obcdta          ! open boundary condition data     (obc_dta routine)
+   USE obcrst          ! open boundary cond. restart      (obc_rst routine)
+   USE obcrad          ! open boundary cond. radiation    (obc_rad routine)
+   USE obcspg          ! open boundary cond  spg          (obc_spg routine)
+
+   USE divcur          ! hor. divergence and curl      (div & cur routines)
+   USE cla_div         ! cross land: hor. divergence      (div_cla routine)
+   USE wzvmod          ! vertical velocity                (wzv     routine)
+
+   USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
+   USE ldfeiv          ! eddy induced velocity coef.      (ldf_eiv routine)
+
+   USE zdfbfr          ! bottom friction                  (zdf_bfr routine)
+   USE zdftke          ! TKE vertical mixing              (zdf_tke routine)
+   USE zdftke_jki      ! TKE vertical mixing              (zdf_tke routine)
+   USE zdfkpp          ! KPP vertical mixing              (zdf_kpp routine)
+   USE zdfddm          ! double diffusion mixing          (zdf_ddm routine)
+   USE zdfevd          ! enhanced vertical diffusion      (zdf_evd routine)
+   USE zdfric          ! Richardson vertical mixing       (zdf_ric routine)
+   USE zdfmxl          ! Mixed-layer depth                (zdf_mxl routine)
+
+   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
+   USE ice_oce         ! sea-ice variable
+   USE icestp          ! sea-ice time-stepping             (ice_stp routine)
+
+   USE diawri          ! Standard run outputs             (dia_wri routine)
+   USE trdicp          ! Ocean momentum/tracers trends    (trd_wri routine)
+   USE trdmld          ! mixed-layer trends               (trd_mld routine)
+   USE trdmld_rst      ! restart for mixed-layer trends
+   USE trdmod_oce      ! ocean momentum/tracers trends
+   USE trdvor          ! vorticity budget                 (trd_vor routine)
+   USE diagap          ! hor. mean model-data gap         (dia_gap routine)
+   USE diahdy          ! dynamic height                   (dia_hdy routine)
+   USE diaptr          ! poleward transports              (dia_ptr routine)
+   USE diahth          ! thermocline depth                (dia_hth routine)
+   USE diafwb          ! freshwater budget                (dia_fwb routine)
+   USE diaspr          ! suface pressure (rigid-lid)      (dia_spr routine)
+   USE flo_oce         ! floats variables
+   USE floats          ! floats computation               (flo_stp routine)
+
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE cpl             ! exchanges in coupled mode        (cpl_stp routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
+   USE domvvl          ! variable volume                  (dom_vvl routine)
+
+#if defined key_agrif
+   USE agrif_opa_sponge ! Momemtum and tracers sponges
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC stp            ! called by opa.F90
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+#if defined key_agrif
+   SUBROUTINE stp( )
+#else
+   SUBROUTINE stp( kstp )
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp  ***
+      !!                      
+      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
+      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
+      !!              - Tme stepping  of TRC (passive tracer eqs.)
+      !! 
+      !! ** Method  : -1- Update forcings and data  
+      !!              -2- Update ocean physics 
+      !!              -3- Compute the t and s trends 
+      !!              -4- Update t and s 
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
+      !!              -8- Outputs and diagnostics
+      !!----------------------------------------------------------------------
+      !! * Arguments
+#if defined key_agrif   
+      INTEGER               :: kstp   ! ocean time-step index
+#else
+      INTEGER, INTENT( in ) :: kstp   ! ocean time-step index
+#endif      
+
+      !! * local declarations
+      INTEGER ::   indic    ! error indicator if < 0
+      !! ---------------------------------------------------------------------
+
+#if defined key_agrif
+      kstp = nit000 + Agrif_Nb_Step()
+!      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+!      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
+#endif   
+      indic = 1                    ! reset to no error condition
+
+      adatrj = adatrj + rdt/86400._wp
+
+      CALL day( kstp )             ! Calendar
+
+      CALL rst_opn( kstp )         ! Open the restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update data, open boundaries and Forcings
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_dtatem  )   CALL dta_tem( kstp )         ! update 3D temperature data
+
+      IF( lk_dtasal  )   CALL dta_sal( kstp )         ! Salinity data
+
+      IF( lk_dtasst  )   CALL dta_sst( kstp )         ! Sea Surface Temperature data
+
+      IF( lk_dtasss  )   CALL dta_sss( kstp )         ! Sea Surface Salinity data
+
+      IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
+
+      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
+
+      IF( .NOT. lk_core )    CALL tau( kstp )         ! wind stress
+
+                         CALL flx_rnf( kstp )         ! runoff data
+
+                         CALL flx( kstp )             ! heat and freshwater fluxes
+
+      IF( lk_ice_lim )   CALL ice_stp( kstp )         ! sea-ice model (Update stress & fluxes)
+
+                         CALL oce_sbc( kstp )         ! ocean surface boudaries
+
+      IF( ln_fwb     )   CALL flx_fwb( kstp )         ! freshwater budget
+
+      IF( nclosea == 1 ) CALL flx_clo( kstp )         ! closed sea in the domain (update freshwater fluxes)
+
+      IF( kstp == nit000 ) THEN 
+         IF( ninist == 1 ) THEN                       ! Output the initial state and forcings
+            CALL dia_wri_state( 'output.init' )
+         ENDIF
+      ENDIF
+
+      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
+         CALL prt_ctl(tab2d_1=emp    , clinfo1=' emp  -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=emps   , clinfo1=' emps -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=qt     , clinfo1=' qt   -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=qsr    , clinfo1=' qsr  -   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab2d_1=runoff , clinfo1=' runoff   : ', mask1=tmask, ovlap=1)
+         CALL prt_ctl(tab3d_1=tmask  , clinfo1=' tmask    : ', mask1=tmask, ovlap=1, kdim=jpk)
+         CALL prt_ctl(tab3d_1=tn     , clinfo1=' sst  -   : ', mask1=tmask, ovlap=1, kdim=1)
+         CALL prt_ctl(tab3d_1=sn     , clinfo1=' sss  -   : ', mask1=tmask, ovlap=1, kdim=1)
+         CALL prt_ctl(tab2d_1=taux   , clinfo1=' tau  - x : ', mask1=umask, &
+            &         tab2d_2=tauy   , clinfo2='      - y : ', mask2=vmask,ovlap=1)
+      ENDIF
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !-----------------------------------------------------------------------
+      !  VERTICAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                       CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
+      
+      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
+      IF( lk_zdfric )   CALL zdf_ric( kstp )                       ! Richardson number dependent Kz
+#if defined key_mpp_omp
+      IF( lk_zdftke )   CALL zdf_tke_jki( kstp )                   ! TKE closure scheme for Kz - j-k-i loops
+#else
+      IF( lk_zdftke )   CALL zdf_tke( kstp )                       ! TKE closure scheme for Kz
+#endif
+      IF( lk_zdfkpp )   CALL zdf_kpp( kstp )                       ! KPP closure scheme for Kz
+
+      IF( lk_zdfcst )   THEN                                       ! Constant Kz (reset avt, avm[uv] to the background value)
+         avt (:,:,:) = avt0 * tmask(:,:,:)
+         avmu(:,:,:) = avm0 * umask(:,:,:)
+         avmv(:,:,:) = avm0 * vmask(:,:,:)
+      ENDIF
+
+      IF( cp_cfg == "orca" ) THEN                           ! ORCA: Reduce vertical mixing in some specific areas
+         SELECT CASE ( jp_cfg )
+            CASE ( 05 )                         ! ORCA R2 configuration
+               avt  (:,:,2) = avt  (:,:,2) + 1.e-3 * upsrnfh(:,:)   ! increase diffusivity of rivers mouths
+            CASE ( 025 )                         ! ORCA R025 configuration
+               avt  (:,:,2) = avt  (:,:,2) + 2.e-3 * upsrnfh(:,:)   ! increase diffusivity of rivers mouths
+         END SELECT
+      ENDIF
+
+      IF( ln_zdfevd )   CALL zdf_evd( kstp )                 ! enhanced vertical eddy diffusivity
+
+      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp)   &
+         &              CALL zdf_ddm( kstp )                 ! double diffusive mixing
+
+                        CALL zdf_bfr( kstp )                 ! bottom friction
+
+                        CALL zdf_mxl( kstp )                 ! mixed layer depth
+
+
+      !-----------------------------------------------------------------------
+      !  LATERAL PHYSICS
+      !-----------------------------------------------------------------------
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      IF( lk_ldfslp     )   CALL ldf_slp( kstp, rhd, rn2 )       ! before slope of the lateral mixing
+
+#if defined key_traldf_c2d
+      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )                 ! eddy induced velocity coefficient
+#endif
+
+
+#if defined key_passivetrc
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                             CALL trc_stp( kstp, indic )            ! time-stepping
+
+#endif
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                             ta(:,:,:) = 0.e0               ! set tracer trends to zero
+                             sa(:,:,:) = 0.e0
+
+                             CALL tra_sbc    ( kstp )       ! surface boundary condition
+
+      IF( ln_traqsr      )   CALL tra_qsr    ( kstp )       ! penetrative solar radiation qsr
+
+      IF( lk_trabbc      )   CALL tra_bbc    ( kstp )       ! bottom heat flux
+
+      IF( lk_trabbl_dif  )   CALL tra_bbl_dif( kstp )       ! diffusive bottom boundary layer scheme
+      IF( lk_trabbl_adv  )   CALL tra_bbl_adv( kstp )       ! advective (and/or diffusive) bottom boundary layer scheme
+
+      IF( lk_tradmp      )   THEN                           ! internal damping trends
+                             CALL tra_dmp    ( kstp, 'TRA', jp_tem, tb, ta )      ! temperature
+                             CALL tra_dmp    ( kstp, 'TRA', jp_sal, sb, sa )      ! salinity
+      ENDIF
+
+                             CALL tra_adv    ( kstp )       ! horizontal & vertical advection
+
+      IF( n_cla == 1     )   CALL tra_cla    ( kstp )       ! Cross Land Advection (Update Hor. advection)
+
+      IF( lk_zdfkpp )        CALL tra_kpp    ( kstp )       ! KPP non-local tracer fluxes
+
+                             CALL tra_ldf    ( kstp )       ! lateral mixing
+#if defined key_agrif
+      IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_tra( kstp )  ! tracers sponge
+#endif
+                             CALL tra_zdf    ( kstp )       ! vertical mixing
+
+                             CALL tra_nxt( kstp )           ! tracer fields at next time step
+
+      IF( ln_zdfnpc      )   CALL tra_npc( kstp )           ! update the new (t,s) fields by non
+      !                                                     ! penetrative convective adjustment
+
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg
+                               CALL eos( ta, sa, rhd, rhop )          ! Time-filtered in situ density used in dynhpg module
+         IF( ln_zps    )       CALL zps_hde( kstp, ta, sa, rhd,   &   ! Partial steps: time filtered hor. gradient
+            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv, gsv, grv )
+      ELSE                                                  ! centered hpg (default case)
+                               CALL eos( tb, sb, rhd, rhop )          ! now (swap=before) in situ density for dynhpg module
+         IF( ln_zps    )       CALL zps_hde( kstp, tb, sb, rhd,   &   ! Partial steps: now horizontal gradient
+            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                     gtv, gsv, grv )
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ta, sa arrays are used as workspace in this section 
+      !-----------------------------------------------------------------------
+
+
+                               ua(:,:,:) = 0.e0               ! set dynamics trends to zero
+                               va(:,:,:) = 0.e0
+
+                               CALL dyn_adv( kstp )           ! advection (vector or flux form)
+
+                               CALL dyn_vor( kstp )           ! vorticity term including Coriolis
+
+                               CALL dyn_ldf( kstp )           ! lateral mixing
+#if defined key_agrif
+      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn( kstp )  ! momemtum sponge
+#endif
+                               CALL dyn_hpg( kstp )           ! horizontal gradient of Hydrostatic pressure
+
+                               CALL dyn_zdf( kstp )           ! vertical diffusion
+
+      IF( lk_dynspg_rl ) THEN
+         IF( lk_obc    )       CALL obc_spg( kstp )           ! surface pressure gradient at open boundaries
+      ENDIF
+                       indic=0
+!i bug lbc sur emp
+      CALL lbc_lnk( emp, 'T', 1. )
+!i
+                               CALL dyn_spg( kstp, indic )    ! surface pressure gradient
+
+                               CALL dyn_nxt( kstp )           ! lateral velocity at next time step
+
+      IF( lk_vvl )             CALL dom_vvl                   ! vertical mesh at next time step
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Computation of diagnostic variables
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+                       CALL oc_fz_pt                        ! ocean surface freezing temperature
+
+                       CALL div_cur( kstp )                 ! Horizontal divergence & Relative vorticity
+
+      IF( n_cla == 1 ) CALL div_cla( kstp )                 ! Cross Land Advection (Update Hor. divergence)
+
+                       CALL wzv( kstp )                     ! Vertical velocity
+
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control, and restarts
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+      !                                                     ! Time loop: control and print
+                                 CALL stp_ctl( kstp, indic )
+      IF( indic < 0          )   CALL ctl_stop( 'step: indic < 0' )
+
+      IF( kstp == nit000     )   CALL iom_close( numror )             ! close input  ocean restart file
+      IF( lrst_oce           )   CALL rst_write  ( kstp )             ! write output ocean restart file
+      IF( lk_obc             )   CALL obc_rst_wri( kstp )             ! write open boundary restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
+      !-----------------------------------------------------------------------
+
+      IF ( nstop == 0 ) THEN                                ! Diagnostics
+         IF( lk_floats  )   CALL flo_stp( kstp )                 ! drifting Floats
+         IF( lk_trddyn  )   CALL trd_dwr( kstp )                 ! trends: dynamics 
+         IF( lk_trdtra  )   CALL trd_twr( kstp )                 ! trends: active tracers
+         IF( lk_trdmld  )   CALL trd_mld( kstp )                 ! trends: Mixed-layer 
+         IF( lk_trdvor  )   CALL trd_vor( kstp )                 ! trends: vorticity budget
+         IF( lk_diaspr  )   CALL dia_spr( kstp )                 ! Surface pressure diagnostics
+         IF( lk_diahth  )   CALL dia_hth( kstp )                 ! Thermocline depth (20 degres isotherm depth)
+         IF( lk_diagap  )   CALL dia_gap( kstp )                 ! basin averaged diagnostics
+         IF( lk_diahdy  )   CALL dia_hdy( kstp )                 ! dynamical heigh diagnostics
+         IF( lk_diafwb  )   CALL dia_fwb( kstp )                 ! Fresh water budget diagnostics
+         IF( ln_diaptr  )   CALL dia_ptr( kstp )                 ! Poleward TRansports diagnostics
+
+         !                                                 ! Outputs
+                            CALL dia_wri    ( kstp, indic )      ! ocean model: outputs
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Coupled mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( lk_cpl    )   CALL cpl_stp( kstp )                 ! coupled mode : field exchanges
+      !
+   END SUBROUTINE stp
+
+   !!======================================================================
+END MODULE step
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/stpctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/stpctl.F90	(revision 4536)
@@ -0,0 +1,194 @@
+MODULE stpctl
+   !!==============================================================================
+   !!                       ***  MODULE  stpctl  ***
+   !! Ocean run control :  gross check of the ocean time stepping
+   !!==============================================================================
+
+   !!----------------------------------------------------------------------
+   !!   stp_ctl      : Control the run
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables 
+   USE sol_oce         ! ocean space and time domain variables 
+   USE in_out_manager  ! I/O manager
+   USE solisl          ! ???
+   USE diawri          ! ocean output file 
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! distributed memory computing
+   USE dynspg_oce      ! pressure gradient schemes 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC stp_ctl           ! routine called by step.F90
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE stp_ctl( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE stp_ctl  ***
+      !!                     
+      !! ** Purpose :   Control the run
+      !!
+      !! ** Method  : - Save the time step in numstp
+      !!              - Print it each 50 time steps
+      !!              - Print solver statistics in numsol 
+      !!              - Stop the run IF problem for the solver ( indec < 0 )
+      !!
+      !! History :
+      !!        !  91-03  ()
+      !!        !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)
+      !!        !  97-06  (A.M. Treguier)
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
+
+      !! * local declarations
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      INTEGER  ::   ii, ij, ik              ! temporary integers
+      REAL(wp) ::   zumax, zsmin            ! temporary scalars
+      INTEGER, DIMENSION(3) ::   ilocu      ! 
+      INTEGER, DIMENSION(2) ::   ilocs      ! 
+      CHARACTER(len=80) :: clname
+      !!----------------------------------------------------------------------
+      !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+      !! $Header$ 
+      !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'stp_ctl : time-stepping control'
+         WRITE(numout,*) '~~~~~~~'
+         ! open time.step file
+         clname = 'time.step'
+         CALL ctlopn( numstp, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+      ENDIF
+
+      ! save the current time step in numstp
+      ! ------------------------------------
+      IF(lwp) WRITE(numstp,9100) kt
+      IF(lwp) REWIND(numstp)
+9100  FORMAT(1x, i8)
+
+
+      ! elliptic solver statistics (if required)
+      ! --------------------------
+      IF( lk_dynspg_flt .OR. lk_dynspg_rl ) THEN
+      ! Solver
+      IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps
+
+      ! Islands (if exist)
+      IF( lk_isl )   CALL isl_stp_ctl( kt, kindic )
+
+
+      ! Output in numwso and numwvo IF kindic<0
+      ! ---------------------------------------
+      !    (i.e. problem for the solver)
+      IF( kindic < 0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
+            WRITE(numout,*) ' ====== '
+            WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
+            WRITE(numout,*)
+            WRITE(numout,*) ' stpctl: output of last fields in numwso'
+            WRITE(numout,*) '                                  numwvo'
+            WRITE(numout,*) ' ======  *******************************'
+         ENDIF
+         CALL dia_wri( kt, kindic )
+      ENDIF
+      ENDIF
+
+9200  FORMAT(' it :', i8, ' niter :', i4, ' res :',e20.10,' b :',e20.10)
+
+      ! Test maximum of velocity (zonal only)
+      ! ------------------------
+      !! zumax = MAXVAL( ABS( un(:,:,:) ) )   ! slower than the following loop on NEC SX5
+      zumax = 0.e0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
+          END DO 
+        END DO 
+      END DO        
+      IF( lk_mpp )   CALL mpp_max( zumax )   ! max over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 ) THEN
+         IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
+      ENDIF
+      IF( zumax > 20.) THEN
+         IF( lk_mpp ) THEN
+            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
+         ELSE
+            ilocu = MAXLOC( ABS( un(:,:,:) ) )
+            ii = ilocu(1) + nimpp - 1
+            ij = ilocu(2) + njmpp - 1
+            ik = ilocu(3)
+         ENDIF
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
+            WRITE(numout,*) ' ====== '
+            WRITE(numout,9400) kt, zumax, ii, ij, ik
+            WRITE(numout,*)
+            WRITE(numout,*) '          output of last fields in numwso'
+         ENDIF
+         kindic  = -3
+
+         CALL dia_wri( kt, kindic )
+      ENDIF
+9400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i4)
+
+
+      ! Test minimum of salinity
+      ! ------------------------
+      !! zsmin = MINVAL( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )    
+      !                slower than the following loop on NEC SX5
+      zsmin = 100.e0
+      DO jj = 2, jpjm1
+         DO ji = 1, jpi
+            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,sn(ji,jj,1))
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_min( zsmin )   ! min over the global domain
+
+      IF( MOD( kt, nwrite ) == 1 ) THEN
+         IF(lwp) WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
+      ENDIF
+      IF( zsmin < 0.) THEN 
+         IF (lk_mpp) THEN
+            CALL mpp_minloc ( sn(:,:,1),tmask(:,:,1), zsmin, ii,ij )
+         ELSE
+            ilocs = MINLOC( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )
+            ii = ilocs(1) + nimpp - 1
+            ij = ilocs(2) + njmpp - 1
+         END IF
+
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
+            WRITE(numout,*) '======= '
+            WRITE(numout,9500) kt, zsmin, ii, ij
+            WRITE(numout,*)
+            WRITE(numout,*) '          output of last fields in numwso'
+         ENDIF
+         IF( kindic < 0 ) THEN
+            IF(lwp) WRITE(numout,*) ' stpctl diabort done. We wont do it again '
+         ELSE 
+            kindic  = -3
+            CALL dia_wri(kt,kindic)
+         ENDIF
+      ENDIF
+9500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i4)
+
+   END SUBROUTINE stp_ctl
+
+   !!======================================================================
+END MODULE stpctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trc_oce.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trc_oce.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trc_oce.F90	(revision 4536)
@@ -0,0 +1,29 @@
+MODULE trc_oce
+   !!======================================================================
+   !!                      ***  MODULE  trc_oce  ***
+   !! Ocean passive tracer  :  share SMS/Ocean variables
+   !!======================================================================
+   !! History :
+   !!   9.0  !  04-03  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+#if defined key_passivetrc && defined key_trc_pisces
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   USE sms , ONLY :  &
+      etot3    =>   etot3   !!:  Biological fluxes for light
+   !! Shared module variables
+   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_sms = .TRUE. 
+#else
+   !!----------------------------------------------------------------------
+   !! Default option                         No Biological fluxes for light          
+   !!----------------------------------------------------------------------
+   USE par_oce
+   LOGICAL, PUBLIC, PARAMETER ::   lk_qsr_sms = .FALSE. 
+   REAL(wp), PUBLIC , DIMENSION (jpi,jpj,jpk) :: &
+      etot3
+#endif
+
+END MODULE trc_oce
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trcstp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trcstp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/trcstp.F90	(revision 4536)
@@ -0,0 +1,23 @@
+MODULE trcstp
+   !!======================================================================
+   !!                       ***  MODULE trcstp  ***
+   !!  Dummy module
+   !! Time-stepping    : time loop of opa for passive tracer
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Default key                                     No passive tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_stp( kt )        ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_stp
+
+   !!======================================================================
+END MODULE trcstp
Index: /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/vectopt_loop_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/vectopt_loop_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/OPA_SRC/vectopt_loop_substitute.h90	(revision 4536)
@@ -0,0 +1,18 @@
+   !!----------------------------------------------------------------------
+   !!                   ***  vectopt_loop_substitute  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute the inner loop starting and inding indices 
+   !!      to allow unrolling of do-loop using CPP macro.
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+#if defined key_vectopt_loop
+#  define fs_2     1
+#  define fs_jpim1 jpi
+#else
+#  define fs_2     2
+#  define fs_jpim1 jpim1
+#endif
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/par_cfc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 4536)
@@ -0,0 +1,49 @@
+MODULE par_cfc
+   !!======================================================================
+   !!                        ***  par_cfc  ***
+   !! TOP :   set the CFC parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_lobster, ONLY : jp_lobster   !: number of tracers in LOBSTER
+   USE par_pisces , ONLY : jp_pisces    !: number of tracers in PISCES
+
+   IMPLICIT NONE
+   PUBLIC
+
+   INTEGER, PUBLIC, PARAMETER ::   jp_lp      = jp_lobster + jp_pisces   !: cumulative number of passive tracers
+   
+#if defined key_cfc
+   !!---------------------------------------------------------------------
+   !!   'key_cfc'   :                                          CFC tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_cfc     = .TRUE.      !: CFC flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc     =  2          !: number of passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_2d  =  1          !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_3d  =  1          !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_trd =  0          !: number of sms trends for CFC
+   
+   ! assign an index in trc arrays for each CFC prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jp11       = jp_lp + 1   !: CFC-11 
+   INTEGER, PUBLIC, PARAMETER ::   jp12       = jp_lp + 2   !: CFC-12   
+#else
+   !!---------------------------------------------------------------------
+   !!   Default     :                                       No CFC tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_cfc     = .FALSE.     !: CFC flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc     =  0          !: No CFC tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_2d  =  0          !: No CFC additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_3d  =  0          !: No CFC additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc_trd =  0          !: number of sms trends for CFC
+#endif
+
+   ! Starting/ending CFC do-loop indices (N.B. no CFC : jp_cfc0 > jp_cfc1 the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc0    = jp_lp + 1       !: First index of CFC tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_cfc1    = jp_lp + jp_cfc  !: Last  index of CFC tracers
+
+   !!======================================================================
+END MODULE par_cfc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trccfc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trccfc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trccfc.F90	(revision 4536)
@@ -0,0 +1,238 @@
+MODULE trccfc
+   !!======================================================================
+   !!                      ***  MODULE trccfc  ***
+   !! TOP : CFC main model
+   !!======================================================================
+   !! History :    -   !  1999-10  (JC. Dutay)  original code
+   !!             1.0  !  2004-03 (C. Ethe) free form + modularity
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  reorganisation
+   !!----------------------------------------------------------------------
+#if defined key_cfc
+   !!----------------------------------------------------------------------
+   !!   'key_cfc'                                               CFC tracers
+   !!----------------------------------------------------------------------
+   !!   trc_cfc     :  compute and add CFC suface forcing to CFC trends
+   !!   trc_cfc_cst :  sets constants for CFC surface forcing computation
+   !!----------------------------------------------------------------------
+   USE daymod       ! calendar
+   USE oce_trc      ! Ocean variables
+   USE par_trc      ! TOP parameters
+   USE trc          ! TOP variables
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_cfc       ! called in ???    
+
+   INTEGER , PUBLIC, PARAMETER ::   jpyear = 100   ! temporal parameter 
+   INTEGER , PUBLIC, PARAMETER ::   jphem  =   2   ! parameter for the 2 hemispheres
+   INTEGER , PUBLIC    ::   ndate_beg      ! initial calendar date (aammjj) for CFC
+   INTEGER , PUBLIC    ::   nyear_res      ! restoring time constant (year)
+   INTEGER , PUBLIC    ::   nyear_beg      ! initial year (aa) 
+   
+   REAL(wp), PUBLIC, DIMENSION(jpyear,jphem, jp_cfc0:jp_cfc1) ::   p_cfc   ! partial hemispheric pressure for CFC          
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj)                       ::   xphem    ! spatial interpolation factor for patm
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj      ,jp_cfc0:jp_cfc1) ::   qtr      ! input function
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj      ,jp_cfc0:jp_cfc1) ::   qint     ! flux function
+
+   REAL(wp), DIMENSION(jp_cfc) ::   soa1, soa2, soa3, soa4   ! coefficient for solubility of CFC [mol/l/atm]
+   REAL(wp), DIMENSION(jp_cfc) ::   sob1, sob2, sob3         !    "               "
+   REAL(wp), DIMENSION(jp_cfc) ::   sca1, sca2, sca3, sca4   ! coefficients for schmidt number in degre Celcius
+      
+   !                          ! coefficients for conversion
+   REAL(wp) ::   xconv1 = 1.0          ! conversion from to 
+   REAL(wp) ::   xconv2 = 0.01/3600.   ! conversion from cm/h to m/s: 
+   REAL(wp) ::   xconv3 = 1.0e+3       ! conversion from mol/l/atm to mol/m3/atm
+   REAL(wp) ::   xconv4 = 1.0e-12      ! conversion from mol/m3/atm to mol/m3/pptv 
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_cfc( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_cfc  ***
+      !!
+      !! ** Purpose :   Compute the surface boundary contition on CFC 11 
+      !!             passive tracer associated with air-mer fluxes and add it 
+      !!             to the general trend of tracers equations.
+      !!
+      !! ** Method  : - get the atmospheric partial pressure - given in pico -
+      !!              - computation of solubility ( in 1.e-12 mol/l then in 1.e-9 mol/m3)
+      !!              - computation of transfert speed ( given in cm/hour ----> cm/s )
+      !!              - the input function is given by : 
+      !!                speed * ( concentration at equilibrium - concentration at surface )
+      !!              - the input function is in pico-mol/m3/s and the
+      !!                CFC concentration in pico-mol/m3
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER ::   ji, jj, jn, jm
+      INTEGER ::   iyear_beg, iyear_end
+      INTEGER ::   im1, im2
+
+      REAL(wp) ::   ztap, zdtap        
+      REAL(wp) ::   zt1, zt2, zt3, zv2
+      REAL(wp) ::   zsol      ! solubility
+      REAL(wp) ::   zsch      ! schmidt number 
+      REAL(wp) ::   zpp_cfc   ! atmospheric partial pressure of CFC
+      REAL(wp) ::   zca_cfc   ! concentration at equilibrium
+      REAL(wp) ::   zak_cfc   ! transfert coefficients
+      
+      REAL(wp), DIMENSION(jphem,jp_cfc)   ::   zpatm       ! atmospheric function
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 )   CALL trc_cfc_cst
+
+      ! Temporal interpolation
+      ! ----------------------
+      iyear_beg = nyear + ( nyear_res - 1900 - nyear_beg  )
+      IF ( nmonth <= 6 ) THEN
+         iyear_beg = iyear_beg - 2 + nyear_beg
+         im1       =  6 - nmonth + 1
+         im2       =  6 + nmonth - 1
+      ELSE
+         iyear_beg = iyear_beg - 1 + nyear_beg
+         im1       = 12 - nmonth + 7
+         im2       =      nmonth - 7
+      ENDIF
+      iyear_end = iyear_beg + 1
+
+
+      !                                                         !------------!
+      DO jn = jp_cfc0, jp_cfc1                                  !  CFC loop  !
+         !                                                      !------------!
+         ! time interpolation at time kt
+         DO jm = 1, jphem
+            zpatm(jm,jn) = (  p_cfc(iyear_beg, jm, jn) * FLOAT (im1)  &
+               &           +  p_cfc(iyear_end, jm, jn) * FLOAT (im2) ) / 12.
+         END DO
+         
+         !                                                         !------------!
+         DO jj = 1, jpj                                            !  i-j loop  !
+            DO ji = 1, jpi                                         !------------!
+ 
+               ! space interpolation
+               zpp_cfc  =       xphem(ji,jj)   * zpatm(1,jn)   &
+                  &     + ( 1.- xphem(ji,jj) ) * zpatm(2,jn)
+
+               ! Computation of concentration at equilibrium : in picomol/l
+               ! coefficient for solubility for CFC-11/12 in  mol/l/atm
+               IF( tmask(ji,jj,1) .GE. 0.5 ) THEN
+                  ztap  = ( tn(ji,jj,1) + 273.16 ) * 0.01
+                  zdtap = ( sob3(jn) * ztap + sob2(jn) ) * ztap + sob1(jn) 
+                  zsol  =  EXP( soa1(jn) + soa2(jn) / ztap + soa3(jn) * LOG( ztap )   &
+                     &                   + soa4(jn) * ztap * ztap + sn(ji,jj,1) * zdtap ) 
+               ELSE
+                  zsol  = 0.e0
+               ENDIF
+               ! conversion from mol/l/atm to mol/m3/atm and from mol/m3/atm to mol/m3/pptv    
+               zsol = xconv4 * xconv3 * zsol * tmask(ji,jj,1)  
+               ! concentration at equilibrium
+               zca_cfc = xconv1 * zpp_cfc * zsol * tmask(ji,jj,1)             
+  
+               ! Computation of speed transfert
+               !    Schmidt number
+               zt1  = tn(ji,jj,1)
+               zt2  = zt1 * zt1 
+               zt3  = zt1 * zt2
+               zsch = sca1(jn) + sca2(jn) * zt1 + sca3(jn) * zt2 + sca4(jn) * zt3
+               !    speed transfert : formulae of wanninkhof 1992
+               zv2     = vatm(ji,jj) * vatm(ji,jj)
+               zsch    = zsch / 660.
+               zak_cfc = ( 0.39 * xconv2 * zv2 / SQRT(zsch) ) * tmask(ji,jj,1)
+
+               ! Input function  : speed *( conc. at equil - concen at surface )
+               ! trn in pico-mol/l idem qtr; ak in en m/s
+               qtr(ji,jj,jn) = -zak_cfc * ( trb(ji,jj,1,jn) - zca_cfc )   &
+#if defined key_off_degrad
+                  &                     * facvol(ji,jj,1)                           &
+#endif
+                  &                     * tmask(ji,jj,1) * ( 1. - freeze(ji,jj) )
+
+               ! Add the surface flux to the trend
+               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + qtr(ji,jj,jn) / fse3t(ji,jj,1) 
+
+               ! cumulation of surface flux at each time step
+               qint(ji,jj,jn) = qint (ji,jj,jn) + qtr(ji,jj,jn) * rdt
+               !                                               !----------------!
+            END DO                                             !  end i-j loop  !
+         END DO                                                !----------------!
+         !                                                  !----------------!
+      END DO                                                !  end CFC loop  !
+      !                                                     !----------------!
+   END SUBROUTINE trc_cfc
+
+
+   SUBROUTINE trc_cfc_cst
+      !!---------------------------------------------------------------------
+      !!                     ***  trc_cfc_cst  ***  
+      !!
+      !! ** Purpose : sets constants for CFC model
+      !!---------------------------------------------------------------------
+      INTEGER ::   jn
+      !!---------------------------------------------------------------------
+
+      DO jn = jp_cfc0, jp_cfc1
+         IF ( jn == jp11 ) THEN
+            ! coefficient for solubility of CFC11 in  mol/l/atm
+            soa1(jn) = -229.9261 
+            soa2(jn) =  319.6552
+            soa3(jn) =  119.4471
+            soa4(jn) =   -1.39165
+            sob1(jn) =   -0.142382
+            sob2(jn) =    0.091459
+            sob3(jn) =   -0.0157274
+            
+            ! coefficients for schmidt number in degre Celcius
+            sca1(jn) = 3501.8
+            sca2(jn) = -210.31
+            sca3(jn) =    6.1851
+            sca4(jn) =   -0.07513
+
+         ELSE IF( jn == jp12 ) THEN
+
+            ! coefficient for solubility of CFC12 in  mol/l/atm
+            soa1(jn) = -218.0971
+            soa2(jn) =  298.9702
+            soa3(jn) =  113.8049
+            soa4(jn) =   -1.39165
+            sob1(jn) =   -0.143566
+            sob2(jn) =    0.091015
+            sob3(jn) =   -0.0153924
+                        
+            ! coefficients for schmidt number in degre Celcius
+            sca1(jn) =  3845.4 
+            sca2(jn) =  -228.95
+            sca3(jn) =     6.1908 
+            sca4(jn) =    -0.067430
+         ENDIF
+
+         WRITE(numout,*) 'coefficient for solubility of tracer',ctrcnm(jn)
+         WRITE(numout,*) soa1(jn), soa2(jn),soa3(jn), soa4(jn), &
+            &           sob1(jn), sob2(jn),sob3(jn)
+         WRITE(numout,*) 
+         WRITE(numout,*) 'coefficient for schmidt of tracer',ctrcnm(jn)
+         WRITE(numout,*) sca1(jn), sca2(jn),sca3(jn), sca4(jn)
+      END DO
+      !
+   END SUBROUTINE trc_cfc_cst
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No CFC tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_cfc( kt )       ! Empty routine
+      WRITE(*,*) 'trc_cfc: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_cfc
+#endif
+
+   !!======================================================================
+END MODULE trccfc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcctl.cfc.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcctl.cfc.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcctl.cfc.h90	(revision 4536)
@@ -0,0 +1,82 @@
+   !!======================================================================
+   !!                         ***  trcctl.cfc.h90  ***
+   !! TOP :   Control of CFC chemical model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2005-10 (C. Ethe) assign a parameter to name individual tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+
+      IF(lwp) THEN
+          WRITE(numout,*) ' CFC Model '
+          WRITE(numout,*) ' '
+      ENDIF
+
+      ! Check number of tracers
+      ! -----------------------   
+      IF( jp_cfc > 2) THEN 
+          IF(lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : w a r n i n g '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_cfc to 1 or 2 in par_CFC module '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+
+      ! Check tracer names
+      ! ------------------
+      IF( jp_cfc == 1 ) THEN
+         IF ( jp11 == 1 ) THEN
+            IF ( ctrcnm(jp11) /= 'CFC11') THEN
+               ctrcnm(jp11) = 'CFC11'
+               ctrcnl(jp11) = 'Chlorofuorocarbone 11 concentration'
+            ENDIF
+         ENDIF
+         IF( jp12 == 1 ) THEN
+            IF ( ctrcnm(jp12) /= 'CFC12') THEN
+               ctrcnm(jp12) = 'CFC12'
+               ctrcnl(jp12) = 'Chlorofuorocarbone 12 concentration'
+            ENDIF
+         ENDIF
+      ENDIF
+
+      IF( jp_cfc == 2 ) THEN
+         IF ( ctrcnm(jp11) /= 'CFC11' .OR. ctrcnm(jp12) /= 'CFC12' ) THEN 
+            ctrcnm(jp11) = 'CFC11'
+            ctrcnl(jp11) = 'Chlorofuorocarbone 11 concentration'
+            ctrcnm(jp12) = 'CFC12'
+            ctrcnl(jp12) = 'Chlorofuorocarbone 12 concentration' 
+         ENDIF
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE (numout,*) ' ===>>>> : w a r n i n g '
+         WRITE (numout,*) ' =======   ============= '
+         WRITE (numout,*) ' we force tracer names'
+         DO jn = jp_cfc0, jp_cfc1
+            WRITE(numout,*) ' tracer nb: ',jn,' name = ',ctrcnm(jn), ctrcnl(jn)
+         END DO
+         WRITE(numout,*) ' '
+      ENDIF 
+
+
+      ! Check tracer units
+      ! ------------------
+      DO jn = jp_cfc0, jp_cfc1
+        IF( ctrcun(jn) /= 'mole/m3' ) THEN
+            ctrcun(jn) = 'mole/m3'
+            IF(lwp) THEN
+               WRITE (numout,*) ' ===>>>> : w a r n i n g '
+               WRITE (numout,*) ' =======   ============= '
+               WRITE (numout,*) ' we force tracer unit'
+               WRITE(numout,*) ' tracer  ',ctrcnm(jn), 'UNIT= ',ctrcun(jn)
+               WRITE(numout,*) ' '
+            ENDIF 
+         ENDIF 
+      END DO              
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcini_cfc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcini_cfc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trcini_cfc.F90	(revision 4536)
@@ -0,0 +1,148 @@
+MODULE trcini_cfc
+   !!======================================================================
+   !!                         ***  MODULE trcini_cfc  ***
+   !! TOP :   initialisation of the CFC tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcini.cfc.h90
+   !!----------------------------------------------------------------------
+#if defined key_cfc
+   !!----------------------------------------------------------------------
+   !!   'key_cfc'                                               CFC tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_cfc      : CFC model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trccfc          ! CFC sms trends
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_cfc   ! called by trcini.F90 module
+
+   CHARACTER (len=34) ::   clname = 'cfc1112.atm'   ! ???
+
+   INTEGER  ::   inum                   ! unit number
+   REAL(wp) ::   ylats = -10.           ! 10 degrees south
+   REAL(wp) ::   ylatn =  10.           ! 10 degrees north
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_cfc
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_cfc  ***  
+      !!
+      !! ** Purpose :   initialization for cfc model
+      !!
+      !! ** Method  : - Read the namcfc namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jn, jl, jm
+      REAL(wp) ::   zyy  ,  zyd
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_cfc: initialisation of CFC chemical model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
+
+      ! Initialization of boundaries conditions
+      ! --------------------------------------- 
+      qtr   (:,:,:) = 0.e0
+      xphem (:,:)   = 0.e0
+      DO jn = jp_cfc0, jp_cfc1
+         DO jm = 1, jphem
+            DO jl = 1, jpyear
+               p_cfc(jl,jm,jn) = 0.0
+            END DO
+         END DO
+      END DO
+      
+      
+      ! Initialization of qint in case of  no restart 
+      !----------------------------------------------
+      IF( .NOT. lrsttr ) THEN    
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'Initialization de qint ; No restart : qint equal zero '
+         ENDIF
+         DO jn = jp_cfc0, jp_cfc1
+            qint(:,:,jn) = 0.e0
+         END DO
+      ENDIF
+
+
+      !   READ CFC partial pressure atmospheric value :
+      !     p11(year,nt) = PCFC11  in northern (1) and southern (2) hemisphere 
+      !     p12(year,nt) = PCFC12  in northern (1) and southern (2) hemisphere 
+      !--------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*) 'read of formatted file cfc1112atm'
+      
+      CALL ctlopn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .FALSE., 1 )
+      REWIND(inum)
+      
+      DO jm = 1, 6        ! Skip over 1st six descriptor lines
+         READ(inum,'(1x)')
+      END DO
+   
+      DO jn = 31, 98      !   Read file
+         READ(inum,*) zyy, p_cfc(jn,1,jp11), p_cfc(jn,1,jp12), &
+            &              p_cfc(jn,2,jp11), p_cfc(jn,2,jp12)
+         WRITE(numout,'(f7.2, 4f8.2)' ) &
+            &         zyy, p_cfc(jn,1,jp11), p_cfc(jn,1,jp12), &
+            &              p_cfc(jn,2,jp11), p_cfc(jn,2,jp12)
+      END DO
+
+      p_cfc(32,1:2,jp11) = 5.e-4      ! modify the values of the first years
+      p_cfc(33,1:2,jp11) = 8.e-4
+      p_cfc(34,1:2,jp11) = 1.e-6
+      p_cfc(35,1:2,jp11) = 2.e-3
+      p_cfc(36,1:2,jp11) = 4.e-3
+      p_cfc(37,1:2,jp11) = 6.e-3
+      p_cfc(38,1:2,jp11) = 8.e-3
+      p_cfc(39,1:2,jp11) = 1.e-2
+      
+      IF(lwp) THEN        ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Year   p11HN    p11HS    p12HN    p12HS '
+         DO jn = 30, 100
+            WRITE(numout, '( 1I4, 4F9.2)')   &
+               &         jn, p_cfc(jn,1,jp11), p_cfc(jn,2,jp11), &
+               &             p_cfc(jn,1,jp12), p_cfc(jn,2,jp12)
+         END DO
+      ENDIF
+
+
+      ! Interpolation factor of atmospheric partial pressure
+      ! Linear interpolation between 2 hemispheric function of latitud between ylats and ylatn
+      !---------------------------------------------------------------------------------------
+      zyd = ylatn - ylats      
+      DO jj = 1 , jpj
+         DO ji = 1 , jpi
+            IF(     gphit(ji,jj) >= ylatn ) THEN   ;   xphem(ji,jj) = 1.e0
+            ELSEIF( gphit(ji,jj) <= ylats ) THEN   ;   xphem(ji,jj) = 0.e0
+            ELSE                                   ;   xphem(ji,jj) = ( gphit(ji,jj) - ylats) / zyd
+            ENDIF
+         END DO
+      END DO
+      !
+   END SUBROUTINE trc_ini_cfc
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No CFC tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_cfc             ! Empty routine
+   END SUBROUTINE trc_ini_cfc
+#endif
+
+   !!======================================================================
+END MODULE trcini_cfc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trclsm_cfc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trclsm_cfc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/CFC/trclsm_cfc.F90	(revision 4536)
@@ -0,0 +1,81 @@
+MODULE trclsm_cfc
+   !!======================================================================
+   !!                         ***  MODULE trclsm_cfc  ***
+   !! TOP :   initialisation of some run parameters for CFC chemical model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trclsm.cfc.h90
+   !!----------------------------------------------------------------------
+#if defined key_cfc
+   !!----------------------------------------------------------------------
+   !!   'key_cfc'                                               CFC tracers
+   !!----------------------------------------------------------------------
+   !! trc_lsm_cfc      : CFC model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms             ! sms trends
+   USE trccfc          ! CFC specific variable
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_lsm_cfc   ! called by trclsm.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lsm_cfc
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_lsm_cfc  ***
+      !!                 
+      !! ** Purpose :   Definition some run parameter for CFC model
+      !!
+      !! ** Method  :   Read the namcfc namelist and check the parameter 
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namcfc
+      !!----------------------------------------------------------------------
+      CHARACTER (len=32) ::   clname = 'namelist.trc.sms'
+      INTEGER ::   numnat
+      !!
+      NAMELIST/namdates/ ndate_beg, nyear_res
+      !!-------------------------------------------------------------------
+
+      ndate_beg = 300101            ! default namelist value
+      nyear_res = 1950
+
+      !                             ! Open namelist file
+      CALL ctlopn( numnat, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .FALSE., 1 )
+         
+      READ( numnat , namdates )     ! read namelist
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trc_lsm: Read namdates, namelist for CFC chemical model'
+         WRITE(numout,*) ' ~~~~~~~'
+         WRITE(numout,*) '    initial calendar date (aammjj) for CFC  ndate_beg = ', ndate_beg
+         WRITE(numout,*) '    restoring time constant (year)          nyear_res = ', nyear_res
+      ENDIF
+      nyear_beg = ndate_beg / 10000
+      IF(lwp) WRITE(numout,*) '    initial year (aa)                       nyear_beg = ', nyear_beg
+      !
+   END SUBROUTINE trc_lsm_cfc
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                                No CFC
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lsm_cfc                      ! Empty routine
+   END  SUBROUTINE  trc_lsm_cfc
+#endif  
+
+   !!======================================================================
+END MODULE trclsm_cfc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_interp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_interp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_interp.F90	(revision 4536)
@@ -0,0 +1,16 @@
+MODULE agrif_top_interp
+   !!======================================================================
+   !!                   ***  MODULE agrif_top_interp  ***
+   !! TOP :   Dummy module when AGRIF is not used
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                               NO AGRIF
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+   !!======================================================================
+END MODULE agrif_top_interp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_update.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_update.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/DUMMY/agrif_top_update.F90	(revision 4536)
@@ -0,0 +1,16 @@
+MODULE agrif_top_update
+   !!======================================================================
+   !!                   ***  MODULE agrif_top_update  ***
+   !! TOP :   Dummy module when AGRIF is not used
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                               NO AGRIF
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+   !!======================================================================
+END MODULE agrif_top_update
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/par_lobster.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/par_lobster.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/par_lobster.F90	(revision 4536)
@@ -0,0 +1,54 @@
+MODULE par_lobster
+   !!======================================================================
+   !!                        ***  par_lobster  ***
+   !! TOP :   set the LOBSTER parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   IMPLICIT NONE
+   PUBLIC
+
+#if defined key_lobster
+   !!---------------------------------------------------------------------
+   !!   'key_lobster'   :                                LOBSTER bio-model
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_lobster     = .TRUE.    !: LOBSTER flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster     =  6        !: number of LOBSTER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_2d  = 19        !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_3d  =  3        !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_trd = 15        !: number of sms trends for LOBSTER
+
+   ! assign an index in trc arrays for each LOBSTER prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpdet          =  1        !: detritus                    [mmoleN/m3]
+   INTEGER, PUBLIC, PARAMETER ::   jpzoo          =  2        !: zooplancton concentration   [mmoleN/m3]
+   INTEGER, PUBLIC, PARAMETER ::   jpphy          =  3        !: phytoplancton concentration [mmoleN/m3]
+   INTEGER, PUBLIC, PARAMETER ::   jpno3          =  4        !: nitrate concentration       [mmoleN/m3]
+   INTEGER, PUBLIC, PARAMETER ::   jpnh4          =  5        !: ammonium concentration      [mmoleN/m3]
+   INTEGER, PUBLIC, PARAMETER ::   jpdom          =  6        !: dissolved organic matter    [mmoleN/m3]
+
+   ! productive layer depth
+   INTEGER, PUBLIC, PARAMETER ::   jpkb           = 12        !: first vertical layers where biology is active
+   INTEGER, PUBLIC, PARAMETER ::   jpkbm1         = jpkb - 1  !: first vertical layers where biology is active
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                                           No LOBSTER model
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_lobster     = .FALSE.   !: LOBSTER flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster     =  0        !: No LOBSTER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_2d  =  0        !: No LOBSTER additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_3d  =  0        !: No LOBSTER additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_lobster_trd =  0        !: number of sms trends for LOBSTER
+#endif
+
+   ! Starting/ending LOBSTER do-loop indices (N.B. no LOBSTER : jpl_lob < jpf_lob the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_lob0 =          1       !: First index of LOBSTER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_lob1 = jp_lobster       !: Last  index of LOBSTER tracers
+
+   !!======================================================================
+END MODULE par_lobster
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/sms_lobster1.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/sms_lobster1.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/sms_lobster1.h90	(revision 4536)
@@ -0,0 +1,117 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  sms_lobster1.h90  ***  
+   !! TOP :   LOBSTER 1 Source Minus Sink valiables
+   !!----------------------------------------------------------------------
+   !! History :    -   !  1999-09 (M. Levy)  original code
+   !!              -   !  2000-12 (O. Aumont, E. Kestenare) add sediment 
+   !!             1.0  !  2005-10 (C. Ethe) F90
+   !!             1.0  !  2005-03  (A-S Kremeur) add fphylab, fzoolab, fdetlab, fdbod
+   !!              -   !  2005-06  (A-S Kremeur) add sedpocb, sedpocn, sedpoca
+   !!             2.0  !  2007-04  (C. Deltel, G. Madec) Free form and modules
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   !!  biological parameters
+   !! ----------------------
+   REAL(wp) ::   apmin    !: minimum phytoplancton concentration              (NAMELIST)
+   REAL(wp) ::   azmin    !: minimum zooplancton concentration                (NAMELIST)
+   REAL(wp) ::   anmin    !: minimum nutrients concentration                  (NAMELIST)
+   REAL(wp) ::   admin    !: minimum detritus concentration                   (NAMELIST)
+   REAL(wp) ::   redf     !: redfield ratio c:n                               (NAMELIST)
+   REAL(wp) ::   reddom   !: redfield ratio c:n for DOM                       
+   REAL(wp) ::   slopet   !: van t hoff coefficient                           (NAMELIST)
+   REAL(wp) ::   toptp    !: optimal photosynthesis temperature               (NAMELIST) 
+   REAL(wp) ::   aknut    !: half-saturation nutrient                         (NAMELIST)
+   REAL(wp) ::   psinut   !: inhibition of nitrate uptake by ammonium         (NAMELIST)
+   REAL(wp) ::   akno3    !: half-saturation for nitrate                      (NAMELIST)
+   REAL(wp) ::   aknh4    !: half-saturation for ammonium                     (NAMELIST)
+   REAL(wp) ::   rcchl    !: ???                                              
+   REAL(wp) ::   rgamma   !: phytoplankton exudation fraction                 (NAMELIST)
+   REAL(wp) ::   toptgz   !: optimal temperature for zooplankton growth       (NAMELIST)
+   REAL(wp) ::   tmaxgz   !: maximal temperature for zooplankton growth       (NAMELIST) 
+   REAL(wp) ::   rgz      !: widtht of zooplankton temperature FUNCTION       (NAMELIST)
+   REAL(wp) ::   rppz     !: zooplankton nominal preference for phytoplancton food (NAMELIST)
+   REAL(wp) ::   taus     !: maximum specific zooplankton grazing rate        (NAMELIST)
+   REAL(wp) ::   aks      !: half saturation constant for total zooplankton grazing (NAMELIST)
+   REAL(wp) ::   filmax   !: maximum mass clearance rate for zooplankton      (NAMELIST)
+   REAL(wp) ::   rpnaz    !: non-assimilated phytoplankton by zooplancton     (NAMELIST)
+   REAL(wp) ::   rdnaz    !: non-assimilated detritus by zooplankton          (NAMELIST) 
+   REAL(wp) ::   eggzoo   !: minimum for zooplankton concentration            (NAMELIST)
+   REAL(wp) ::   tauzn    !: zooplancton specific excretion rate              (NAMELIST)
+   REAL(wp) ::   tmmaxp   !: maximal phytoplancton mortality rate             (NAMELIST)
+   REAL(wp) ::   tmminp   !: minimal phytoplancton mortality rate             (NAMELIST)
+   REAL(wp) ::   tmmaxz   !: maximal zooplankton mortality rate               (NAMELIST)
+   REAL(wp) ::   tmminz   !: minimal zooplankton mortality rate               (NAMELIST)
+   REAL(wp) ::   anumin   !: nutrient threshold for phytoplankton mortality   (NAMELIST)
+   REAL(wp) ::   afdmin   !: food threshold for zooplankton mortality         (NAMELIST)
+   REAL(wp) ::   taudn    !: detrital breakdown rate                          (NAMELIST)
+   REAL(wp) ::   vsed     !: sedimentation speed                              (NAMELIST)
+   REAL(wp) ::   tmumax   !: maximal phytoplankton growth rate                (NAMELIST)
+   REAL(wp) ::   aki      !: light photosynthesis half saturation constant    (NAMELIST)
+   REAL(wp) ::   tmaxr    !: maximum coefficient for passive tracer damping   (NAMELIST)
+   REAL(wp) ::   tminr    !: minimum coefficient for passive tracer damping   (NAMELIST)
+   REAL(wp) ::   fdoml    !: fraction of exsudation that goes to nh4 (should be labile dom)
+   REAL(wp) ::   taunn    !: nitrification rate
+   REAL(wp) ::   taudomn  !: slow remineralization rate of semi-labile dom to nh4
+   REAL(wp) ::   xhr      !: coeff for Martin's remineralistion profile
+   REAL(wp) ::   fphylab  !: NH4 fraction of phytoplankton excretion
+   REAL(wp) ::   fzoolab  !: NH4 fraction of zooplankton excretion
+   REAL(wp) ::   fdetlab  !: NH4 fraction of detritus dissolution
+   REAL(wp) ::   fdbod    !: zooplankton mortality fraction that goes to detritus
+
+   REAL(wp), DIMENSION(jpk,jp_lobster) ::   remdmp   !: depth dependant damping coefficient of passive tracers 
+   
+
+# if defined key_trc_diabio
+
+   !! Biological trends 
+   !! -----------------
+   CHARACTER(len=8),  DIMENSION(jpdiabio) ::   ctrbio   !: biological trends name      (NAMELIST)
+   CHARACTER(len=20), DIMENSION(jpdiabio) ::   ctrbiu   !: biological trends unit      (NAMELIST)
+   CHARACTER(len=80), DIMENSION(jpdiabio) ::   ctrbil   !: biological trends long name (NAMELIST)
+   REAL(wp), DIMENSION(jpi,jpj,jpk,jpdiabio) :: trbio   !: biological trends
+
+   !! Netcdf output parameters
+   !! ------------------------
+   INTEGER ::   nwritebio   !: time step frequency for biological outputs (NAMELIST)
+   INTEGER ::   nitb        !:         id.         for additional array output file
+   INTEGER ::   ndepitb     !:         id.         for depth mesh
+   INTEGER ::   nhoritb     !:         id.         for horizontal mesh
+
+# endif 
+
+   !! Optical parameters                                
+   !! ------------------                                
+   REAL(wp) ::   xkr0       !: water coefficient absorption in red      (NAMELIST)
+   REAL(wp) ::   xkg0       !: water coefficient absorption in green    (NAMELIST)
+   REAL(wp) ::   xkrp       !: pigment coefficient absorption in red    (NAMELIST)
+   REAL(wp) ::   xkgp       !: pigment coefficient absorption in green  (NAMELIST)
+   REAL(wp) ::   xlr        !: exposant for pigment absorption in red   (NAMELIST)
+   REAL(wp) ::   xlg        !: exposant for pigment absorption in green (NAMELIST)
+   REAL(wp) ::   rpig       !: chla/chla+phea ratio                     (NAMELIST)
+                                                        
+   INTEGER , DIMENSION(jpi,jpj)     ::   neln    !: number of levels in the euphotic layer
+   REAL(wp), DIMENSION(jpi,jpj)     ::   xze     !: euphotic layer depth
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   xpar    !: par (photosynthetic available radiation)
+
+   !! Sediment parameters                               
+   !! -------------------                               
+   REAL(wp) ::   sedlam       !: time coefficient of POC remineralization in sediments
+   REAL(wp) ::   sedlostpoc   !: ???
+   REAL(wp) ::   areacot      !: ???
+                                                        
+   REAL(wp), DIMENSION(jpi,jpj)     ::   dminl   !: fraction of sinking POC released in sediments
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   dmin3   !: fraction of sinking POC released at each level
+                                                        
+   REAL(wp), DIMENSION(jpi,jpj) ::   sedpocb     !: mass of POC in sediments
+   REAL(wp), DIMENSION(jpi,jpj) ::   sedpocn     !: mass of POC in sediments
+   REAL(wp), DIMENSION(jpi,jpj) ::   sedpoca     !: mass of POC in sediments
+                                                        
+   REAL(wp), DIMENSION(jpi,jpj) ::   fbod        !: rapid sinking particles
+   REAL(wp), DIMENSION(jpi,jpj) ::   cmask       !: ???
+
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcbio.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcbio.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcbio.F90	(revision 4536)
@@ -0,0 +1,393 @@
+MODULE trcbio
+   !!======================================================================
+   !!                         ***  MODULE trcbio  ***
+   !! TOP :   LOBSTER
+   !!======================================================================
+   !! History :    -   !  1999-07  (M. Levy) Original code
+   !!              -   !  2000-12  (E. Kestenare) assign a parameter to name individual tracers
+   !!              -   !  2001-03  (M. Levy)  LNO3 + dia2d 
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_bio        :  
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE lbclnk          ! 
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_bio    ! called in ???
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_bio( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_bio  ***
+      !!
+      !! ** Purpose :   compute the now trend due to biogeochemical processes
+      !!              and add it to the general trend of passive tracers equations
+      !!
+      !! ** Method  :   each now biological flux is calculated in function of now
+      !!              concentrations of tracers.
+      !!              depending on the tracer, these fluxes are sources or sinks.
+      !!              the total of the sources and sinks for each tracer
+      !!              is added to the general trend.
+      !!        
+      !!                      tra = tra + zf...tra - zftra...
+      !!                                     |         |
+      !!                                     |         |
+      !!                                  source      sink
+      !!        
+      !!              IF 'key_trc_diabio' defined , the biogeochemical trends
+      !!              for passive tracers are saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zdet, zzoo, zphy, zno3, znh4, zdom      ! now concentrations
+      REAL(wp) ::   zlno3, zlnh4, zle, zlt                  ! limitation terms for phyto
+      REAL(wp) ::   zno3phy, znh4phy, zphynh4, zphydom
+      REAL(wp) ::   zphydet, zphyzoo, zdetzoo
+      REAL(wp) ::   zzoonh4, zzoodom, zzoodet, zdetnh4, zdetdom
+      REAL(wp) ::   znh4no3, zdomnh4, zppz, zpdz, zpppz, zppdz, zfood
+      REAL(wp) ::   zfilpz, zfildz, zphya, zzooa, zno3a
+      REAL(wp) ::   znh4a, zdeta, zdoma, zzoobod, zboddet, zdomaju
+#if defined key_trc_diaadd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
+#endif
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_bio: LOBSTER bio-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      ENDIF
+
+#if defined key_trc_diaadd
+      ! convert fluxes in per day
+      ze3t(:,:,:) = 0.e0
+      DO jk = 1, jpkbm1
+         ze3t(:,:,jk) = fse3t(:,:,jk) * 86400.
+      END DO 
+#endif
+
+      fbod(:,:) = 0.e0
+#if defined key_trc_diaadd
+      DO ji = 1, jpdia2d
+         trc2d(:,:,ji) = 0.e0
+      END DO 
+#endif
+
+
+      !                                      ! -------------------------- !
+      DO jk = 1, jpkbm1                      !  Upper ocean (bio-layers)  !
+         !                                   ! -------------------------- !
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1           !!gm  use of fs_2 fs_jpm1  required here
+
+               ! trophic variables( det, zoo, phy, no3, nh4, dom)
+               ! ------------------------------------------------
+
+               ! negative trophic variables DO not contribute to the fluxes
+               zdet = MAX( 0.e0, trn(ji,jj,jk,jpdet) )
+               zzoo = MAX( 0.e0, trn(ji,jj,jk,jpzoo) )
+               zphy = MAX( 0.e0, trn(ji,jj,jk,jpphy) )
+               zno3 = MAX( 0.e0, trn(ji,jj,jk,jpno3) )
+               znh4 = MAX( 0.e0, trn(ji,jj,jk,jpnh4) )
+               zdom = MAX( 0.e0, trn(ji,jj,jk,jpdom) )
+
+               ! Limitations
+               zlt   = 1.
+               zle   = 1. - EXP( -xpar(ji,jj,jk) / aki / zlt )
+               ! psinut,akno3,aknh4 added by asklod AS Kremeur 2005-03
+               zlno3 = zno3 * EXP( -psinut * znh4 ) / ( akno3 + zno3 )
+               zlnh4 = znh4 / (znh4+aknh4) 
+
+
+               ! sinks and sources
+               !    phytoplankton production and exsudation
+               zno3phy = tmumax * zle * zlt * zlno3 * zphy
+               znh4phy = tmumax * zle * zlt * zlnh4 * zphy
+
+               !    fphylab added by asklod AS Kremeur 2005-03
+               zphydom = rgamma * (1 - fphylab) * (zno3phy + znh4phy)
+               zphynh4 = rgamma * fphylab * (zno3phy + znh4phy)
+
+               ! zooplankton production
+               !    preferences
+               zppz = rppz
+               zpdz = 1. - rppz
+               zpppz = ( zppz * zphy ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
+               zppdz = ( zpdz * zdet ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
+               zfood = zpppz * zphy + zppdz * zdet
+               !    filtration
+               zfilpz = taus * zpppz / (aks + zfood)
+               zfildz = taus * zppdz / (aks + zfood)
+               !    grazing
+               zphyzoo = zfilpz * zphy * zzoo
+               zdetzoo = zfildz * zdet * zzoo
+
+               ! fecal pellets production
+               zzoodet = rpnaz * zphyzoo + rdnaz * zdetzoo
+ 
+               ! zooplankton liquide excretion
+               zzoonh4 = tauzn * fzoolab * zzoo 
+               zzoodom = tauzn * (1 - fzoolab) * zzoo
+
+               ! mortality
+               !    phytoplankton mortality 
+               zphydet = tmminp * zphy
+
+               !    zooplankton mortality
+               !    closure : flux fbod is redistributed below level jpkbio
+               zzoobod = tmminz * zzoo * zzoo
+               fbod(ji,jj) = fbod(ji,jj) + (1-fdbod) * zzoobod * fse3t(ji,jj,jk)
+               zboddet = fdbod * zzoobod
+
+               ! detritus and dom breakdown
+               zdetnh4 = taudn * fdetlab * zdet
+               zdetdom = taudn * (1 - fdetlab) * zdet 
+
+               zdomnh4 = taudomn * zdom
+
+               ! flux added to express how the excess of nitrogen from
+               ! PHY, ZOO and DET to DOM goes directly to NH4 (flux of ajustment)
+               zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
+
+               ! Nitrification
+               znh4no3 = taunn * znh4
+
+               ! determination of trends
+               !    total trend for each biological tracer
+               zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
+               zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
+               zno3a = - zno3phy + znh4no3
+               znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
+               zdeta =   zphydet + zzoodet - zdetzoo - zdetnh4 - zdetdom + zboddet
+               zdoma =   zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
+   
+#if defined key_trc_diabio
+               trbio(ji,jj,jk, 1) = zno3phy
+               trbio(ji,jj,jk, 2) = znh4phy
+               trbio(ji,jj,jk, 3) = zphynh4
+               trbio(ji,jj,jk, 4) = zphydom
+               trbio(ji,jj,jk, 5) = zphyzoo
+               trbio(ji,jj,jk, 6) = zphydet
+               trbio(ji,jj,jk, 7) = zdetzoo
+               trbio(ji,jj,jk, 9) = zzoodet
+               trbio(ji,jj,jk,10) = zzoobod
+               trbio(ji,jj,jk,11) = zzoonh4
+               trbio(ji,jj,jk,12) = zzoodom
+               trbio(ji,jj,jk,13) = znh4no3
+               trbio(ji,jj,jk,14) = zdomnh4
+               trbio(ji,jj,jk,15) = zdetnh4
+#endif
+#if defined key_trc_diaadd
+               trc2d(ji,jj, 1) = trc2d(ji,jj, 1) + zno3phy * ze3t(ji,jj,jk) 
+               trc2d(ji,jj, 2) = trc2d(ji,jj, 2) + znh4phy * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 3) = trc2d(ji,jj, 3) + zphydom * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 4) = trc2d(ji,jj, 4) + zphynh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 5) = trc2d(ji,jj, 5) + zphyzoo * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 6) = trc2d(ji,jj, 6) + zphydet * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 7) = trc2d(ji,jj, 7) + zdetzoo * ze3t(ji,jj,jk)
+! trend number 8 is in trcsed.F            
+               trc2d(ji,jj, 9) = trc2d(ji,jj, 9) + zzoodet * ze3t(ji,jj,jk)
+               trc2d(ji,jj,10) = trc2d(ji,jj,10) + zzoobod * ze3t(ji,jj,jk)
+               trc2d(ji,jj,11) = trc2d(ji,jj,11) + zzoonh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,12) = trc2d(ji,jj,12) + zzoodom * ze3t(ji,jj,jk)
+               trc2d(ji,jj,13) = trc2d(ji,jj,13) + znh4no3 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,14) = trc2d(ji,jj,14) + zdomnh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,15) = trc2d(ji,jj,15) + zdetnh4 * ze3t(ji,jj,jk)
+             
+               trc2d(ji,jj,16) = trc2d(ji,jj,16) + (  zno3phy + znh4phy - zphynh4   &
+                  &                                 - zphydom - zphyzoo - zphydet ) * ze3t(ji,jj,jk)
+               trc2d(ji,jj,17) = trc2d(ji,jj,17) + (  zphyzoo + zdetzoo - zzoodet   &
+                  &                                 - zzoobod - zzoonh4 - zzoodom ) * ze3t(ji,jj,jk)
+               trc2d(ji,jj,18) = trc2d(ji,jj,18) + zdetdom * ze3t(ji,jj,jk)
+! trend number 19 is in trcexp.F
+               trc3d(ji,jj,jk,1) = zno3phy * 86400     
+               trc3d(ji,jj,jk,2) = znh4phy * 86400     
+               trc3d(ji,jj,jk,3) = znh4no3 * 86400     
+#endif
+
+               ! tracer flux at totox-point added to the general trend
+               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + zdeta
+               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) + zzooa
+               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zphya
+               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zno3a
+               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + znh4a
+               tra(ji,jj,jk,jpdom) = tra(ji,jj,jk,jpdom) + zdoma
+
+            END DO
+         END DO
+      END DO
+
+!!gm do loop until jpkm1 only!
+      !                                      ! -------------------------- !
+      DO jk = jpkb, jpk                      !  Upper ocean (bio-layers)  !
+         !                                   ! -------------------------- !
+
+         DO jj = 2, jpjm1
+            DO ji = 2,jpim1             !!gm use of fs_2 & fs_jpim1 required
+ 
+               ! remineralisation of all quantities towards nitrate 
+
+               !    trophic variables( det, zoo, phy, no3, nh4, dom)
+               !       negative trophic variables DO not contribute to the fluxes
+               zdet = MAX( 0.e0, trn(ji,jj,jk,jpdet) )
+               zzoo = MAX( 0.e0, trn(ji,jj,jk,jpzoo) )
+               zphy = MAX( 0.e0, trn(ji,jj,jk,jpphy) )
+               zno3 = MAX( 0.e0, trn(ji,jj,jk,jpno3) )
+               znh4 = MAX( 0.e0, trn(ji,jj,jk,jpnh4) )
+               zdom = MAX( 0.e0, trn(ji,jj,jk,jpdom) )
+
+               !    Limitations
+               zlt   = 0.e0
+               zle   = 0.e0
+               zlno3 = 0.e0
+               zlnh4 = 0.e0
+
+               !    sinks and sources
+               !       phytoplankton production and exsudation
+               zno3phy = 0.e0
+               znh4phy = 0.e0
+               zphydom = 0.e0
+               zphynh4 = 0.e0
+
+               !    zooplankton production
+               zphyzoo = 0.e0      ! grazing
+               zdetzoo = 0.e0
+
+               zzoodet = 0.e0      ! fecal pellets production
+
+               zzoonh4 = tauzn * fzoolab * zzoo         ! zooplankton liquide excretion
+               zzoodom = tauzn * (1 - fzoolab) * zzoo
+
+               !    mortality
+               zphydet = tmminp * zphy      ! phytoplankton mortality 
+
+               zzoobod = 0.e0               ! zooplankton mortality
+               zboddet = 0.e0               ! closure : flux fbod is redistributed below level jpkbio
+
+               !    detritus and dom breakdown
+               zdetnh4 = taudn * fdetlab * zdet
+               zdetdom = taudn * (1 - fdetlab) * zdet 
+
+               zdomnh4 = taudomn * zdom
+               zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
+
+               !    Nitrification
+               znh4no3 = taunn * znh4
+
+
+               ! determination of trends
+               !     total trend for each biological tracer
+               zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
+               zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
+               zno3a = - zno3phy + znh4no3
+               znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
+               zdeta = zphydet + zzoodet  - zdetzoo - zdetnh4 - zdetdom + zboddet
+               zdoma = zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
+
+#if defined key_trc_diabio
+               trbio(ji,jj,jk, 1) = zno3phy
+               trbio(ji,jj,jk, 2) = znh4phy
+               trbio(ji,jj,jk, 3) = zphynh4
+               trbio(ji,jj,jk, 4) = zphydom
+               trbio(ji,jj,jk, 5) = zphyzoo
+               trbio(ji,jj,jk, 6) = zphydet
+               trbio(ji,jj,jk, 7) = zdetzoo
+               trbio(ji,jj,jk, 9) = zzoodet
+               trbio(ji,jj,jk,10) = zzoobod
+               trbio(ji,jj,jk,11) = zzoonh4
+               trbio(ji,jj,jk,12) = zzoodom
+               trbio(ji,jj,jk,13) = znh4no3
+               trbio(ji,jj,jk,14) = zdomnh4
+               trbio(ji,jj,jk,15) = zdetnh4
+#endif
+#if defined key_trc_diaadd
+               trc2d(ji,jj, 1) = trc2d(ji,jj, 1) + zno3phy * ze3t(ji,jj,jk)          
+               trc2d(ji,jj, 2) = trc2d(ji,jj, 2) + znh4phy * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 3) = trc2d(ji,jj, 3) + zphydom * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 4) = trc2d(ji,jj, 4) + zphynh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 5) = trc2d(ji,jj, 5) + zphyzoo * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 6) = trc2d(ji,jj, 6) + zphydet * ze3t(ji,jj,jk)
+               trc2d(ji,jj, 7) = trc2d(ji,jj, 7) + zdetzoo * ze3t(ji,jj,jk)
+               ! trend number 8 is in trcsed.F            
+               trc2d(ji,jj, 9) = trc2d(ji,jj, 9) + zzoodet * ze3t(ji,jj,jk)
+               trc2d(ji,jj,10) = trc2d(ji,jj,10) + zzoobod * ze3t(ji,jj,jk)
+               trc2d(ji,jj,11) = trc2d(ji,jj,11) + zzoonh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,12) = trc2d(ji,jj,12) + zzoodom * ze3t(ji,jj,jk)
+               trc2d(ji,jj,13) = trc2d(ji,jj,13) + znh4no3 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,14) = trc2d(ji,jj,14) + zdomnh4 * ze3t(ji,jj,jk)
+               trc2d(ji,jj,15) = trc2d(ji,jj,15) + zdetnh4 * ze3t(ji,jj,jk)
+             
+               trc2d(ji,jj,16) = trc2d(ji,jj,16) + (  zno3phy + znh4phy - zphynh4   &
+                  &                                 - zphydom - zphyzoo - zphydet  ) * ze3t(ji,jj,jk)
+               trc2d(ji,jj,17) = trc2d(ji,jj,17) + (  zphyzoo + zdetzoo - zzoodet   &
+                  &                                 - zzoobod - zzoonh4 - zzoodom  ) * ze3t(ji,jj,jk)
+               trc2d(ji,jj,18) = trc2d(ji,jj,18) + zdetdom * ze3t(ji,jj,jk)
+
+               trc3d(ji,jj,jk,1) =  zno3phy * 86400     
+               trc3d(ji,jj,jk,2) =  znh4phy * 86400     
+               trc3d(ji,jj,jk,3) =  znh4no3 * 86400     
+#endif
+
+               ! tracer flux at totox-point added to the general trend
+               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + zdeta
+               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) + zzooa
+               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zphya
+               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zno3a
+               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + znh4a
+               tra(ji,jj,jk,jpdom) = tra(ji,jj,jk,jpdom) + zdoma
+               !
+            END DO
+         END DO
+      END DO
+
+#if defined key_trc_diaadd
+      ! Lateral boundary conditions on trc2d and trc3d
+      DO ji = 1, jpdia2d
+          CALL lbc_lnk( trc2d(:,:,ji),'T', 1. )
+      END DO 
+      DO ji = 1, jpdia3d
+          CALL lbc_lnk( trc3d(:,:,1,ji),'T', 1. )
+      END DO 
+#endif
+
+#if defined key_trc_diabio
+      ! Lateral boundary conditions on trcbio
+      DO ji = 1, jpdiabio
+          CALL lbc_lnk( trbio(:,:,1,ji),'T', 1. )
+      END DO 
+#endif
+      !
+   END SUBROUTINE trc_bio
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_bio( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_bio: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bio
+#endif 
+
+   !!======================================================================
+END MODULE  trcbio
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcctl.lobster1.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcctl.lobster1.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcctl.lobster1.h90	(revision 4536)
@@ -0,0 +1,75 @@
+   !!======================================================================
+   !!                         ***  trcctl.lobster1.h90  ***
+   !! TOP :   Control of LOBSTER 1 biological model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2000-12 (E. Kestenare) assign a parameter to name individual tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' use LOBSTER1 biological model '
+
+      ! Check number of tracers
+      ! -----------------------
+      IF (jp_lobster /= 6) THEN 
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : w a r n i n g '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_lobster to 6 in '           &
+              &   ,'parameter.passivetrc.lobster1.h '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+
+      ! Check tracer names
+      ! ------------------
+      IF(   ctrcnm(jpdet) /= 'DET' .OR. ctrcnm(jpzoo) /= 'ZOO' .OR.   &
+         &  ctrcnm(jpphy) /= 'PHY' .OR. ctrcnm(jpno3) /= 'NO3' .OR.   &
+         &  ctrcnm(jpnh4) /= 'NH4' .OR. ctrcnm(jpdom) /= 'DOM' .OR.   & 
+         &  ctrcnl(jpdet) /= 'Detritus'                        .OR.   &
+         &  ctrcnl(jpzoo) /= 'Zooplankton concentration'       .OR.   &
+         &  ctrcnl(jpphy) /= 'Phytoplankton concentration'     .OR.   &
+         &  ctrcnl(jpno3) /= 'Nitrate concentration'           .OR.   &
+         &  ctrcnl(jpnh4) /= 'Ammonium concentration'          .OR.   &
+         &  ctrcnl(jpdom) /= 'Dissolved organic matter' ) THEN 
+         ctrcnm(jpdet)='DET'
+         ctrcnl(jpdet)='Detritus'
+         ctrcnm(jpzoo)='ZOO'
+         ctrcnl(jpzoo)='Zooplankton concentration'
+         ctrcnm(jpphy)='PHY'
+         ctrcnl(jpphy)='Phytoplankton concentration'
+         ctrcnm(jpno3)='NO3'
+         ctrcnl(jpno3)='Nitrate concentration'
+         ctrcnm(jpnh4)='NH4'
+         ctrcnl(jpnh4)='Ammonium concentration'
+         ctrcnm(jpdom)='DOM'
+         ctrcnl(jpdom)='Dissolved organic matter'          
+         IF(lwp) THEN
+            WRITE (numout,*) ' ===>>>> : w a r n i n g '
+            WRITE (numout,*) ' =======   ============= '
+            WRITE (numout,*) ' we force tracer names'
+            DO jn = jp_lob0, jp_lob1
+               WRITE(numout,*) ' tracer nb: ',jn,' name = ',ctrcnm(jn), ctrcnl(jn)
+            END DO
+            WRITE(numout,*) ' '
+         ENDIF 
+      ENDIF 
+
+      ! Check tracer units
+      DO jn = jp_lob0, jp_lob1
+         IF( ctrcun(jn) /= 'mmole-N/m3') THEN
+            ctrcun(jn)='mmole-N/m3'
+            IF(lwp) THEN
+               WRITE (numout,*) ' ===>>>> : w a r n i n g '
+               WRITE (numout,*) ' =======   ============= '
+               WRITE (numout,*) ' we force tracer unit'
+               WRITE(numout,*) ' tracer  ',ctrcnm(jn), 'UNIT= ',ctrcun(jn)
+            ENDIF 
+         ENDIF 
+      END DO              
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcexp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcexp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcexp.F90	(revision 4536)
@@ -0,0 +1,180 @@
+MODULE trcexp
+   !!======================================================================
+   !!                         ***  MODULE p4sed  ***
+   !! TOP :   PISCES Compute loss of organic matter in the sediments
+   !!======================================================================
+   !! History :    -   !  1999    (O. Aumont, C. Le Quere)  original code
+   !!              -   !  2001-05 (O. Aumont, E. Kestenare) add sediment computations
+   !!             1.0  !  2005-06 (A.-S. Kremeur) new temporal integration for sedpoc
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_exp        :  Compute loss of organic matter in the sediments
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE lbclnk
+   USE trc
+   USE trctrp_lec
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_exp    ! called in p4zprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_exp( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_exp  ***
+      !!
+      !! ** Purpose :   MODELS EXPORT OF BIOGENIC MATTER (POC ''SOFT
+      !!              TISSUE'') AND ITS DISTRIBUTION IN WATER COLUMN
+      !!
+      !! ** Method  : - IN THE SURFACE LAYER POC IS PRODUCED ACCORDING TO
+      !!              NURTRIENTS AVAILABLE AND GROWTH CONDITIONS. NUTRIENT UPTAKE
+      !!              KINETICS FOLLOW MICHAELIS-MENTON FORMULATION. 
+      !!              THE TOTAL PARTICLE AMOUNT PRODUCED, IS DISTRIBUTED IN THE WATER
+      !!              COLUMN BELOW THE SURFACE LAYER.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zgeolpoc, zfact
+      INTEGER , DIMENSION(jpi,jpj) ::   ikbot
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwork
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_exp: LOBSTER export'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      ENDIF
+
+! VERTICAL DISTRIBUTION OF NEWLY PRODUCED BIOGENIC
+! POC IN THE WATER COLUMN
+! (PARTS OF NEWLY FORMED MATTER REMAINING IN THE DIFFERENT
+! LAYERS IS DETERMINED BY DMIN3 DEFINED IN common.passivetrc.*.h
+! ----------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3)   &
+     &                             + (1./fse3t(ji,jj,jk)) * dmin3(ji,jj,jk) * fbod(ji,jj)
+            END DO
+         END DO
+      END DO
+
+!     Find the last level of the water column
+!     Compute fluxes due to sinking particles (slow)
+   
+      ikbot(:,:) = jpk
+      zwork(:,:) = 0.e0
+
+!!gm ikbot already exist in opa...
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF( tmask(ji,jj,jk) == 1 .AND.  tmask(ji,jj,jk+1) == 0 ) THEN
+                  ikbot(ji,jj) = jk
+                  zwork(ji,jj) = vsed * trn(ji,jj,jk,jpdet)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      zgeolpoc = 0.e0         !     Initialization
+
+      ! Release of nutrients from the "simple" sediment
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            tra(ji,jj,ikbot(ji,jj),jpno3) = tra(ji,jj,ikbot(ji,jj),jpno3)   &
+               &                          + sedlam * sedpocn(ji,jj) / fse3t(ji,jj,ikbot(ji,jj))
+
+            !     Deposition of organic matter in the sediment
+            zgeolpoc = zgeolpoc + sedlostpoc * sedpocn(ji,jj) * e1t(ji,jj) * e2t(ji,jj)
+
+!!gm factorisationof rdt just bellow...
+            sedpoca(ji,jj) = zwork(ji,jj) * rdt + dminl(ji,jj) * fbod(ji,jj) * rdt   &
+               &           - sedlam * sedpocn(ji,jj) * rdt - sedlostpoc * sedpocn(ji,jj) * rdt
+
+         END DO
+      END DO
+
+      DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            tra(ji,jj,1,jpno3) = tra(ji,jj,1,jpno3) + zgeolpoc * cmask(ji,jj) / areacot / fse3t(ji,jj,1)
+         END DO
+      END DO
+
+      CALL lbc_lnk( sedpocn, 'T', 1. )
+ 
+      ! Oa & Ek: diagnostics depending on jpdia2d !          left as example
+# if defined key_trc_diaadd
+      trc2d(:,:,19) = sedpocn(:,:)
+# endif
+
+      ! Leap-frog scheme (only in explicit case, otherwise the 
+      ! ----------------  time stepping is already done in trczdf)
+      IF( l_trczdf_exp .AND. (ln_trcadv_cen2 .OR. ln_trcadv_tvd) ) THEN
+         zfact = 2. * rdttra(jk) * FLOAT( ndttrc ) 
+         IF( neuler == 0 .AND. kt == nittrc000 )   zfact = rdttra(jk) * FLOAT(ndttrc) 
+         sedpoca(:,:) =  sedpocb(:,:) + zfact * sedpoca(:,:) 
+      ENDIF
+
+      
+      ! Time filter and swap of arrays
+      ! ------------------------------
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd  ) THEN         ! centred or tvd scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  sedpocb(ji,jj) = sedpocn(ji,jj)
+                  sedpocn(ji,jj) = sedpoca(ji,jj)
+                  sedpoca(ji,jj) = 0.e0
+               END DO
+            END DO
+         ELSE
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  sedpocb(ji,jj) = atfp  * ( sedpocb(ji,jj) + sedpoca(ji,jj) )    &
+                     &           + atfp1 *   sedpocn(ji,jj)
+                  sedpocn(ji,jj) = sedpoca(ji,jj)
+                  sedpoca(ji,jj) = 0.e0
+               END DO
+            END DO
+         ENDIF
+      ELSE                                                   !  case of smolar scheme or muscl
+         sedpocb(:,:) = sedpoca(:,:)
+         sedpocn(:,:) = sedpoca(:,:)
+         sedpoca(:,:) = 0.e0
+      ENDIF
+      !
+   END SUBROUTINE trc_exp
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_exp( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_exp
+#endif 
+
+   !!======================================================================
+END MODULE  trcexp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcini_lobster.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcini_lobster.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcini_lobster.F90	(revision 4536)
@@ -0,0 +1,157 @@
+MODULE trcini_lobster
+   !!======================================================================
+   !!                         ***  MODULE trcini_lobster  ***
+   !! TOP :   initialisation of the LOBSTER biological model
+   !!======================================================================
+   !! History :    -   !  1999-09  (M. Levy) Original code
+   !!              -   !  2000-12  (0. Aumont, E. Kestenare) add sediment 
+   !!             1.0  !  2004-03  (C. Ethe) Modularity
+   !!              -   !  2005-03  (O. Aumont, A. El Moussaoui) F90
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcini.lobster1.h90
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !! trc_ini_lobster  : LOBSTER model initialisation
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE trccfc          ! CFC sms trends
+   USE sms             ! Source Minus Sink variables
+   USE oce_trc         ! ocean variables
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_lobster   ! called by trcini.F90 module
+
+#  include "domzgr_substitute.h90"
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_lobster
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE trc_ini_lobster  ***
+      !! ** purpose :   specific initialisation for LOBSTER bio-model
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jn
+      REAL(wp) ::   ztest, zfluo, zfluu
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zrro
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdm0
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_lobster :   LOBSTER biochemical model initialisation'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
+
+
+      ! initialization of fields for optical model
+      ! --------------------------------------------
+      xze (:,:)   = 5.e0
+      xpar(:,:,:) = 0.e0
+
+      ! initialization for passive tracer remineralisation-damping  array
+      ! -----------------------------------------------------------------
+
+      DO jn = jp_lob0, jp_lob1
+         remdmp(:,jn) = tminr
+      END DO
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' trcini: compute remineralisation-damping  '
+         WRITE(numout,*) '         arrays for tracers'
+      ENDIF
+
+      ! initialization of biological variables
+      ! ------------------------------------------
+
+      ! Calculate vertical distribution of newly formed biogenic poc
+      ! in the water column in the case of max. possible bottom depth
+      ! ------------------------------------------------------------
+
+      zdm0   = 0.e0
+      zrro = 1.e0
+      DO jk = jpkb,jpkm1
+         DO jj =1, jpj
+            DO ji =1, jpi
+               zfluo = ( fsdepw(ji,jj,jk  ) / fsdepw(ji,jj,jpkb) )**xhr 
+               zfluu = ( fsdepw(ji,jj,jk+1) / fsdepw(ji,jj,jpkb) )**xhr
+               IF( zfluo.GT.1. )   zfluo = 1.e0
+               zdm0(ji,jj,jk) = zfluo - zfluu
+               IF( jk <= jpkb-1 )   zdm0(ji,jj,jk) = 0.e0
+               zrro(ji,jj) = zrro(ji,jj) - zdm0(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      zdm0(:,:,jpk) = zrro(:,:)
+
+      ! Calculate vertical distribution of newly formed biogenic poc
+      ! in the water column with realistic topography (first "dry" layer
+      ! contains total fraction, which has passed to the upper layers)
+      ! ----------------------------------------------------------------------
+      dminl = 0.
+      dmin3 = zdm0
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tmask(ji,jj,jk) == 0. ) THEN
+                  dminl(ji,jj) = dminl(ji,jj) + dmin3(ji,jj,jk)
+                  dmin3(ji,jj,jk) = 0.e0
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( tmask(ji,jj,1) == 0 )   dmin3(ji,jj,1) = 0.e0
+         END DO
+      END DO
+
+      ! Coastal mask 
+      ! ------------   
+      cmask = 0.e0
+      DO ji = 2, jpi-1
+         DO jj = 2, jpj-1
+            if (tmask(ji,jj,1) == 1) then
+               ztest=tmask(ji+1,jj,1)*tmask(ji-1,jj,1)*tmask(ji,jj+1,1)*tmask(ji,jj-1,1)
+               IF (ztest == 0) cmask(ji,jj) = 1.
+            endif
+         END DO
+      END DO
+
+      cmask( 1 ,:) = cmask(jpi-1,:)
+      cmask(jpi,:) = cmask( 2   ,:)
+
+      !!gm BUG !!!!!   not valid in mpp and also not valid for north fold   !!!!!
+
+      ! Coastal surface
+      ! ---------------
+      areacot = 0.e0
+      DO ji = 2, jpi-1
+         DO jj = 2, jpj-1
+            areacot = areacot + e1t(ji,jj) * e2t(ji,jj) * cmask(ji,jj)
+         END DO
+      END DO
+      !
+   END SUBROUTINE trc_ini_lobster
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                   No LOBSTER bio-model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_lobster             ! Empty routine
+   END SUBROUTINE trc_ini_lobster
+#endif
+
+   !!======================================================================
+END MODULE trcini_lobster
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trclsm_lobster.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trclsm_lobster.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trclsm_lobster.F90	(revision 4536)
@@ -0,0 +1,231 @@
+MODULE trclsm_lobster
+   !!======================================================================
+   !!                      ***  MODULE trclsm_lobster  ***
+   !! TOP :   initialisation of some run parameters for LOBSTER bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trclsm.lobster1.h90
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'   :                                 LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !! trc_lsm_lobster      : LOBSTER model namelist read
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms             ! sms trends
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_lsm_lobster   ! called by trclsm.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lsm_lobster
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_lsm_lobster  ***  
+      !!
+      !! ** Purpose :   read LOBSTER namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!----------------------------------------------------------------------
+      CHARACTER (len=32) :: clname
+      !!
+      NAMELIST/natbio/ apmin, azmin, anmin, admin,                       &
+         &   redf, reddom, slopet, toptp, psinut, akno3, aknh4, rcchl,   &
+         &   rgamma, toptgz, tmaxgz, rgz,                                &
+         &   rppz, taus, aks, filmax, rpnaz, rdnaz, eggzoo, tauzn,       &
+         &   tmmaxp, tmminp, tmmaxz, tmminz, anumin, afdmin, taudn,      &
+         &   vsed, tmumax, aki, tmaxr, tminr, taunn, taudomn, xhr,       &
+         &   sedlam, sedlostpoc,                                         &
+         &   fphylab, fzoolab, fdetlab, fdbod
+      NAMELIST/natopt/ xkg0, xkr0, xkgp, xkrp, xlg, xlr, rpig
+#if defined key_trc_diabio
+      INTEGER :: ji
+      NAMELIST/natdbi/ctrbio,ctrbil,ctrbiu,nwritebio
+#endif
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_lsm_lobster : read LOBSTER namelists'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
+
+      !                               ! Open the namelist file
+      !                               ! ----------------------
+      clname ='namelist.trc.sms'
+      CALL ctlopn( numnat, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .FALSE., 1 )
+
+      !                               ! natbio : biological parameters
+      !                               ! ------------------------------
+      apmin = 0.                           ! default values
+      azmin = 0.
+      anmin = 0.
+      admin = 0.
+      redf  = 0.
+      reddom = 0.
+      slopet = 0.
+      toptp = 0.
+      psinut = 0.
+      akno3  = 0.
+      aknh4 = 0.
+      rcchl = 0.
+      rgamma= 0.
+      toptgz= 0.
+      tmaxgz= 0.
+      rgz   = 0.
+      rppz  = 0.
+      taus  = 0.
+      aks   = 0.
+      filmax= 0.
+      rpnaz = 0.
+      rdnaz = 0.
+      eggzoo= 0.
+      tauzn = 0.
+      tmmaxp= 0.
+      tmminp= 0.
+      tmmaxz= 0.
+      tmminz= 0.
+      anumin= 0.
+      afdmin= 0.
+      taudn = 0.
+      vsed  = 0.
+      tmumax= 0.
+      aki   = 0.
+      tmaxr   = 1./(     4.*rday)*0.
+      tminr   = 1./(24.*30.*rday)*0.
+      xhr=0.
+      sedlam=0.
+      sedlostpoc=0.
+      taudomn = 0.
+      taunn = 0.
+      fphylab = 0.
+      fzoolab = 0.
+      fdetlab = 0.
+      fdbod = 0.
+
+      REWIND( numnat )                     ! read natbio
+      READ  ( numnat, natbio )
+
+      IF(lwp) THEN
+          WRITE(numout,*) ' Namelist natbio'
+          WRITE(numout,*) '    minimum phytoplancton concentration                  apmin     =', apmin
+          WRITE(numout,*) '    minimum zooplancton   concentration                  azmin     =', azmin
+          WRITE(numout,*) '    minimum nutrients     concentration                  anmin     =', anmin
+          WRITE(numout,*) '    minimum detritus      concentration                  admin     =', admin
+          WRITE(numout,*) '    redfield ratio  c:n                                  redf      =', redf
+          WRITE(numout,*) '    van t hoff coefficient                               slopet    =', slopet
+          WRITE(numout,*) '    optimal photosynthesis temperature                   toptp     =', toptp
+          WRITE(numout,*) '    inhibition of no3 uptake by nh4                      psinut    =', psinut
+          WRITE(numout,*) '    half-saturation nutrient for no3 uptake              akno3     =', akno3
+          WRITE(numout,*) '    half-saturation nutrient for nh4 uptake              aknh4     =', aknh4
+          WRITE(numout,*) '    carbone/chlorophyl ratio                             rcchl     =', rcchl
+          WRITE(numout,*) '    phytoplankton exudation fraction                     rgamma    =', rgamma
+          WRITE(numout,*) '    optimal temperature for zoo growth                   toptgz    =', toptgz
+          WRITE(numout,*) '    maximal temperature for zoo growth                   tmaxgz    =', tmaxgz
+          WRITE(numout,*) '    widtht of zoo temperature FUNCTION                   rgz       =', rgz
+          WRITE(numout,*) '    zoo preference for phyto                             rppz      =', rppz
+          WRITE(numout,*) '    maximal zoo grazing rate                             taus      =', 86400 * taus, ' d'
+          WRITE(numout,*) '    half saturation constant for zoo food                aks       =', aks
+          WRITE(numout,*) '    maximal mass clearance rate for zoo                  filmax    =', filmax
+          WRITE(numout,*) '    non-assimilated phyto by zoo                         rpnaz     =', rpnaz
+          WRITE(numout,*) '    non-assimilated detritus by zoo                      rdnaz     =', rdnaz
+          WRITE(numout,*) '    minimum  for zoo concentration                       eggzoo    =', eggzoo
+          WRITE(numout,*) '    zoo specific excretion rate                          tauzn     =', 86400 * tauzn
+          WRITE(numout,*) '    maximal phyto mortality rate                         tmmaxp    =', 86400 * tmmaxp
+          WRITE(numout,*) '    minimal phyto mortality rate                         tmminp    =', 86400 * tmminp
+          WRITE(numout,*) '    maximal zoo mortality rate                           tmmaxz    =', 86400 * tmmaxz
+          WRITE(numout,*) '    minimal zoo mortality rate                           tmminz    =', 86400 * tmminz
+          WRITE(numout,*) '    nutrient threshold for phyto mort                    anumin    =', anumin
+          WRITE(numout,*) '    food threshold for zoo mort                          afdmin    =', afdmin
+          WRITE(numout,*) '    detrital breakdown rate                              taudn     =', 86400 * taudn , ' d'
+          WRITE(numout,*) '    detritus sedimentation speed                         vsed      =', 86400 * vsed  , ' d'
+          WRITE(numout,*) '    phyto max growth rate                                tmumax    =', 86400 * tmumax, ' d'
+          WRITE(numout,*) '    light hlaf saturation constant                       aki       =', aki
+          WRITE(numout,*) '    maximum damping for d z or p                         tmaxr     =', tmaxr
+          WRITE(numout,*) '    damping-remineralisation rate                        tminr     =', tminr
+          WRITE(numout,*) '    nitrification rate                                   taunn     =', taunn
+          WRITE(numout,*) '    dom remineralisation rate                            taudomn   =', taudomn
+          WRITE(numout,*) '    coeff for martin''s remineralistion                  xhr       =', xhr
+          WRITE(numout,*) '    time coeff of POC in sediments                       sedlam    =', sedlam
+          WRITE(numout,*) '    Sediment geol loss for POC                           sedlostpoc=', sedlostpoc
+          WRITE(numout,*) '    NH4 fraction of phytoplankton exsudation             fphylab   =', fphylab
+          WRITE(numout,*) '    NH4 fraction of zooplankton excretion                fzoolab   =', fzoolab
+          WRITE(numout,*) '    NH4 fraction of detritus dissolution                 fdetlab   =', fdetlab
+          WRITE(numout,*) '    Zooplankton mortality fraction that goes to detritus fdbod     =', fdbod
+      ENDIF
+
+      !                               ! natopt : optical parameters
+      !                               ! ---------------------------
+      xkg0  = 0.                           ! default values
+      xkr0  = 0.
+      xkgp  = 0.
+      xkrp  = 0.
+      xlg   = 0.
+      xlr   = 0.
+      rpig  = 0.
+
+      REWIND( numnat )                     ! read natopt
+      READ  ( numnat, natopt )       
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist natopt'
+         WRITE(numout,*) '    green   water absorption coeff                       xkg0  = ', xkg0
+         WRITE(numout,*) '    red water absorption coeff                           xkr0  = ', xkr0
+         WRITE(numout,*) '    pigment red absorption coeff                         xkrp  = ', xkrp
+         WRITE(numout,*) '    pigment green absorption coeff                       xkgp  = ', xkgp
+         WRITE(numout,*) '    green chl exposant                                   xlg   = ', xlg
+         WRITE(numout,*) '    red   chl exposant                                   xlr   = ', xlr
+         WRITE(numout,*) '    chla/chla+phea ratio                                 rpig  = ', rpig
+      ENDIF
+
+#if defined key_trc_diabio
+
+      !                               ! natdbi : bio diagnostics
+      !                               ! ------------------------
+      nwritebio = 10                     ! default values
+      DO ji = 1, jpdiabio
+         IF(     ji <  10 ) THEN   ;   WRITE (ctrbio(ji),'("BIO_",I1)') ji      ! short name
+         ELSEIF (ji < 100 ) THEN   ;   WRITE (ctrbio(ji),'("BIO_",I2)') ji   
+         ELSE                      ;   WRITE (ctrbio(ji),'("BIO_",I3)') ji
+         ENDIF
+         WRITE(ctrbil(ji),'("BIOLOGICAL TREND NUMBER ",I2)') ji                 ! long name
+         ctrbiu(ji) = 'mmoleN/m3/s '                                            ! units
+      END DO
+
+      REWIND( numnat )                     ! read natdbi
+      READ  ( numnat, natdbi )  
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist natdbi'
+         WRITE(numout,*) '    frequency of outputs for biological outputs  nwritebio = ', nwritebio
+         DO ji = 1, jpdiabio
+            WRITE(numout,*) '     name of biological trend No :',ji,' : ',ctrbio(ji), ctrbil(ji), ' in ', ctrbiu(ji)
+         END DO
+      END IF
+#endif
+      !
+   END SUBROUTINE trc_lsm_lobster
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                            No LOBSTER
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lsm_lobster                      ! Empty routine
+   END  SUBROUTINE  trc_lsm_lobster
+#endif  
+
+   !!======================================================================
+END MODULE trclsm_lobster
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcopt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcopt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcopt.F90	(revision 4536)
@@ -0,0 +1,145 @@
+MODULE trcopt
+   !!======================================================================
+   !!                         ***  MODULE trcopt  ***
+   !! TOP :   LOBSTER Compute the light availability in the water column
+   !!======================================================================
+   !! History :    -   !  1995-05  (M. Levy) Original code
+   !!              -   !  1999-09  (J.-M. Andre, M. Levy) 
+   !!              -   !  1999-11  (C. Menkes, M.-A. Foujols) itabe initial
+   !!              -   !  2000-02  (M.A. Foujols) change x**y par exp(y*log(x))
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_opt        :   Compute the light availability in the water column
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_opt   ! called in trcprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_opt( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_opt  ***
+      !!
+      !! ** Purpose :   computes the light propagation in the water column
+      !!              and the euphotic layer depth
+      !!
+      !! ** Method  :   local par is computed in w layers using light propagation
+      !!              mean par in t layers are computed by integration
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! index of the time stepping
+      INTEGER  ::   ji, jj, jk
+      INTEGER , DIMENSION(jpi,jpj)     ::   itabe           ! euphotic layer last k index
+      INTEGER , DIMENSION(jpi,jpj,jpk) ::   imaske          ! euphotic layer mask
+      REAL(wp) ::   zpig                                    ! total pigment
+      REAL(wp) ::   zkr                                     ! total absorption coefficient in red
+      REAL(wp) ::   zkg                                     ! total absorption coefficient in green
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar100         ! irradiance at euphotic layer depth
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar0m          ! irradiance just below the surface
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zparr, zparg    ! red and green compound of par
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_opt: LOBSTER optic-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      ENDIF
+
+      ! determination of surface irradiance
+      ! -----------------------------------
+      zpar0m (:,:)   = qsr   (:,:) * 0.43
+      zpar100(:,:)   = zpar0m(:,:) * 0.01
+      xpar   (:,:,1) = zpar0m(:,:)
+      zparr  (:,:,1) = 0.5 * zpar0m(:,:)
+      zparg  (:,:,1) = 0.5 * zpar0m(:,:)
+
+
+      ! determination of xpar
+      ! ---------------------
+
+      DO jk = 2, jpk                     ! determination of local par in w levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zpig = MAX( TINY(0.), trn(ji,jj,jk-1,jpphy) ) * 12 * redf / rcchl / rpig
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * fse3t(ji,jj,jk-1) )
+               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * fse3t(ji,jj,jk-1) )
+            END DO
+        END DO
+      END DO
+
+      DO jk = 1, jpkm1                   ! mean par in t levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zpig = MAX( TINY(0.), trn(ji,jj,jk,jpphy) ) * 12 * redf / rcchl / rpig
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk)    = zparr(ji,jj,jk) / zkr / fse3t(ji,jj,jk) * ( 1 - EXP( -zkr*fse3t(ji,jj,jk) ) )
+               zparg(ji,jj,jk)    = zparg(ji,jj,jk) / zkg / fse3t(ji,jj,jk) * ( 1 - EXP( -zkg*fse3t(ji,jj,jk) ) )
+               xpar (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
+            END DO
+         END DO
+      END DO
+
+      ! determination of euphotic layer depth (xze)
+      ! -------------------------------------
+
+      DO jk = 1, jpk                   ! imaske equal 1 in the euphotic layer, and 0 without
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               IF( xpar(ji,jj,jk) >= zpar100(ji,jj) ) THEN
+                  imaske(ji,jj,jk) = 1
+               ELSE
+                  imaske(ji,jj,jk) = 0
+               ENDIF
+            END DO
+         END DO
+      END DO
+      !                                ! sum of imaske Cover the vertical with a minimim value of 1 
+      itabe(:,:) = 1                   !   surface value setto 1 <=> set a ninimum value to 1
+      DO jk = 2, jpk
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               itabe(ji,jj) = itabe(ji,jj) + imaske(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      DO jj = 1, jpj                  ! converte the number of level into depth
+         DO ji = 1,jpi
+            xze(ji,jj) = fsdepw(ji,jj,itabe(ji,jj)+1)
+         END DO
+      END DO
+      !
+   END SUBROUTINE trc_opt
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_opt( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_opt: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_opt
+#endif 
+
+   !!======================================================================
+END MODULE  trcopt
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcsed.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcsed.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/LOBSTER/trcsed.F90	(revision 4536)
@@ -0,0 +1,120 @@
+MODULE trcsed
+   !!======================================================================
+   !!                         ***  MODULE p4sed  ***
+   !! TOP :   PISCES Compute loss of organic matter in the sediments
+   !!======================================================================
+   !! History :    -   !  1995-06 (M. Levy)  original code
+   !!              -   !  2000-12 (E. Kestenare)  clean up
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90 + simplifications
+   !!----------------------------------------------------------------------
+#if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_sed        :  Compute loss of organic matter in the sediments
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE lbclnk
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sed    ! called in ???
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sed( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sed  ***
+      !!
+      !! ** Purpose :   compute the now trend due to the vertical sedimentation of
+      !!              detritus and add it to the general trend of detritus equations
+      !!
+      !! ** Method  :   this ROUTINE compute not exactly the advection but the
+      !!              transport term, i.e.  dz(wt) and dz(ws)., dz(wtr)
+      !!              using an upstream scheme
+      !!              the now vertical advection of tracers is given by:
+      !!                      dz(trn wn) = 1/bt dk+1( e1t e2t vsed (trn) )
+      !!              add this trend now to the general trend of tracer (ta,sa,tra):
+      !!                             tra = tra + dz(trn wn)
+      !!        
+      !!              IF 'key_trc_diabio' is defined, the now vertical advection
+      !!              trend of passive tracers is saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ztra
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwork
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_sed: LOBSTER sedimentation'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+      ENDIF
+
+      ! sedimentation of detritus  : upstream scheme
+      ! --------------------------------------------
+
+      ! for detritus sedimentation only - jpdet
+
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      zwork(:,:,jpk) = 0.e0      ! bottom value  set to zero
+
+      ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
+
+      DO jk = 2, jpkm1
+         zwork(:,:,jk) = -vsed * trn(:,:,jk-1,jpdet)
+      END DO
+
+      ! tracer flux divergence at t-point added to the general trend
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               ztra  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + ztra
+# if defined key_trc_diabio
+               trbio(ji,jj,jk,8) = ztra
+# endif
+# if defined key_trc_diaadd
+!!gm  bug introduced: no more mask below jpkb ! 
+               trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+# endif
+            END DO
+         END DO
+      END DO
+
+#if defined key_trc_diabio
+      CALL lbc_lnk( trbio(:,:,1,8), 'T', 1. )    ! Lateral boundary conditions on trcbio
+#endif
+#if defined key_trc_diaadd
+      CALL lbc_lnk( trc2d(:,:,8), 'T', 1. )      ! Lateral boundary conditions on trc2d
+#endif
+      !
+   END SUBROUTINE trc_sed
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_sed( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sed: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sed
+#endif 
+
+   !!======================================================================
+END MODULE  trcsed
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/par_my_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/par_my_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/par_my_trc.F90	(revision 4536)
@@ -0,0 +1,52 @@
+MODULE par_my_trc
+   !!======================================================================
+   !!                        ***  par_my_trc  ***
+   !! TOP :   set the MY_TRC parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_lobster, ONLY : jp_lobster   !: number of tracers in LOBSTER
+   USE par_pisces , ONLY : jp_pisces    !: number of tracers in PISCES
+   USE par_cfc    , ONLY : jp_cfc       !: number of tracers in CFC
+
+   IMPLICIT NONE
+   PUBLIC
+
+   INTEGER, PUBLIC, PARAMETER ::   jp_lpc  = jp_lobster + jp_pisces + jp_cfc   !: cumulative number of TRC
+
+#if defined key_trc_my_trc
+   !!---------------------------------------------------------------------
+   !!   'key_trc_my_trc'                     user defined tracers (MY_TRC)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_my_trc     = .TRUE.   !: PTS flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc     =  3       !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_2d  =  1       !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_3d  =  1       !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_trd =  0       !: number of sms trends for MY_TRC
+
+   ! assign an index in trc arrays for each PTS prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jp_myt1 = jp_lpc + 1     !: 1st MY_TRC tracer
+   INTEGER, PUBLIC, PARAMETER ::   jp_myt2 = jp_lpc + 1     !: 2nd MY_TRC tracer
+   INTEGER, PUBLIC, PARAMETER ::   jp_myt3 = jp_lpc + 1     !: 3rd MY_TRC tracer
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                           No user defined tracers (MY_TRC)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_my_trc     = .FALSE.  !: MY_TRC flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc     =  0       !: No MY_TRC tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_2d  =  0       !: No MY_TRC additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_3d  =  0       !: No MY_TRC additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_my_trc_trd =  0       !: number of sms trends for MY_TRC
+#endif
+
+   ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_myt0 = jp_lpc + 1           !: First index of CFC passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_myt1 = jp_lpc + jp_my_trc   !: Last  index of CFC passive tracers
+
+   !!======================================================================
+END MODULE par_my_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trcini_my_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trcini_my_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trcini_my_trc.F90	(revision 4536)
@@ -0,0 +1,55 @@
+MODULE trcini_my_trc
+   !!======================================================================
+   !!                         ***  MODULE trcini_my_trc  ***
+   !! TOP :   initialisation of the MY_TRC tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!----------------------------------------------------------------------
+#if defined key_MY_TRC
+   !!----------------------------------------------------------------------
+   !!   'key_MY_TRC'                                               CFC tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_my_trc   : MY_TRC model initialisation
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_my_trc   ! called by trcini.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcini_cfc.F90 766 2007-12-14 08:59:00Z gm $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_my_trc
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_my_trc  ***  
+      !!
+      !! ** Purpose :   initialization for MY_TRC model
+      !!
+      !! ** Method  : - Read the namcfc namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_my_trc: initialisation of MY_TRC model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      !
+   END SUBROUTINE trc_ini_my_trc
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MY_TRC model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_my_trc             ! Empty routine
+   END SUBROUTINE trc_ini_my_trc
+#endif
+
+   !!======================================================================
+END MODULE trcini_my_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trclsm_my_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trclsm_my_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/MY_TRC/trclsm_my_trc.F90	(revision 4536)
@@ -0,0 +1,59 @@
+MODULE trclsm_my_trc
+   !!======================================================================
+   !!                      ***  MODULE trclsm_my_trc  ***
+   !! TOP :   initialisation of some run parameters for LOBSTER bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!----------------------------------------------------------------------
+#if defined key_my_trc
+   !!----------------------------------------------------------------------
+   !!   'key_my_trc'   :                                       MY_TRC model
+   !!----------------------------------------------------------------------
+   !! trc_lsm_my_trc      : MY_TRC model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms             ! sms trends
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_lsm_my_trc   ! called by trclsm.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lsm_my_trc
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_lsm_my_trc  ***  
+      !!
+      !! ** Purpose :   read MY_TRC namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_lsm_my_trc : read MY_TRC namelists'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
+      !
+   END SUBROUTINE trc_lsm_my_trc
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                             No MY_TRC
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lsm_my_trc                      ! Empty routine
+   END  SUBROUTINE  trc_lsm_my_trc
+#endif  
+
+   !!======================================================================
+END MODULE trclsm_my_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zbio.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zbio.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zbio.F90	(revision 4536)
@@ -0,0 +1,192 @@
+MODULE p4zbio
+   !!======================================================================
+   !!                         ***  MODULE p4zbio  ***
+   !! TOP :   PISCES bio-model
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_bio        :   computes the interactions between the different
+   !!                      compartments of PISCES
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE p4zsink         ! 
+   USE p4zsink_kriest  ! 
+   USE p4zopt          ! 
+   USE p4zlim          ! 
+   USE p4zprod         !
+   USE p4znano         !
+   USE p4zdiat         ! 
+   USE p4zmicro        ! 
+   USE p4zmeso         ! 
+   USE p4zrem          ! 
+   USE prtctl_trc
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_bio    ! called in p4zprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_bio ( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_bio  ***
+      !!
+      !! ** Purpose :   Ecosystem model in the whole ocean: computes the
+      !!              different interactions between the different compartments
+      !!              of PISCES
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      INTEGER  ::   ji, jj, jk, jn
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+      !     ASSIGN THE SHEAR RATE THAT IS USED FOR AGGREGATION
+      !     OF PHYTOPLANKTON AND DETRITUS
+
+      xdiss(:,:,:) = 0.01
+
+!!gm the use of nmld should be better here?
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fsdepw(ji,jj,jk+1) .le. hmld(ji,jj) )   xdiss(ji,jj,jk) = 1.e0
+            END DO 
+         END DO
+      END DO
+
+
+      ! computation of the vertical flux of particulate organic matter
+      ! --------------------------------------------------------------
+
+      IF( lk_kriest )   THEN   ;   CALL p4z_sink_kriest      ! Sink due to vertical flux of POM
+      ELSE                     ;   CALL p4z_sink             ! 
+      ENDIF
+
+
+      ! compute the PAR in the water column
+      ! -----------------------------------
+
+      CALL p4z_opt       ! Optical 
+
+
+
+      ! compute the co-limitations by the various nutrients
+      ! ----------------------------------------------------
+
+      CALL p4z_lim
+
+
+      ! compute phytoplankton growth rate over the global ocean. 
+      ! -------------------------------------------------------
+      ! (Growth rates for each element is computed (C, Si, Fe, Chl))
+
+      CALL p4z_prod ( kt )
+
+
+
+      ! phytoplankton mortality (Mortality losses for each elements are computed (C, Fe, Si, Chl) )
+      ! -----------------------
+
+      CALL p4z_nano       ! nanophytoplankton
+      
+
+      CALL p4z_diat       ! diatoms
+
+
+      ! zooplankton sources/sinks routines (each elements are computed (C, Fe, Si, Chl) )
+      ! ----------------------------------
+
+      CALL p4z_micro      ! microzooplankton
+
+      
+      CALL p4z_meso       ! mesozooplankton
+
+
+      ! computation of remineralization terms of organic matter + scavenging of Fe
+      ! --------------------------------------------------------------------------
+      
+      CALL p4z_rem        ! remineralization
+
+
+      ! Loop to test if tracers concentrations fall below 0.
+      ! ----------------------------------------------------
+
+      xnegtr(:,:,:) = 1.e0
+      DO jn = jp_pcs0, jp_pcs1
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( ( trn(ji,jj,jk,jn) + tra(ji,jj,jk,jn) ) < 0.e0 )   &
+             &      xnegtr(ji,jj,jk) = 0.e0
+               END DO
+            END DO
+         END DO
+      END DO
+      !                                ! where at least 1 tracer concentration becomes negative
+      !                                ! all tracer tendancy are set to zero (i.e. trn = trb)
+      DO jn = jp_pcs0, jp_pcs1
+         trn(:,:,:,jn) = trn(:,:,:,jn) + xnegtr(:,:,:) * tra(:,:,:,jn)
+      END DO
+
+
+      tra(:,:,:,:) = 0.0
+
+#if defined key_kriest
+        DO jk = 1,jpkm1
+           DO jj = 1,jpj
+              DO ji = 1,jpi
+                 trn(ji,jj,jk,jpnum) = MAX( trn(ji,jj,jk,jpnum),  &
+     &                                      trn(ji,jj,jk,jppoc) / xkr_massp / xnumm(jk) )
+
+                 trn(ji,jj,jk,jpnum) = MIN( trn(ji,jj,jk,jpnum),  &
+     &                                      trn(ji,jj,jk,jppoc) / xkr_massp / 1.1 )
+
+          END DO
+        END DO
+      END DO
+#endif
+
+
+# if defined key_trc_dia3d && defined key_kriest
+!!gm potential bug  hard coded index on trc3d
+     trc3d(:,:,:,11) = tra(:,:,:,jpcal) * xnegtr(:,:,:) * 1.e3 * rfact2r
+# endif
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('bio ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_bio
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_bio                         ! Empty routine
+   END SUBROUTINE p4z_bio
+#endif 
+
+   !!======================================================================
+END MODULE  p4zbio
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zche.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zche.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zche.F90	(revision 4536)
@@ -0,0 +1,369 @@
+MODULE p4zche
+   !!======================================================================
+   !!                         ***  MODULE p4zche  ***
+   !! TOP :   PISCES Sea water chemistry computed following OCMIP protocol
+   !!======================================================================
+   !! History :    -   !  1988     (E. Maier-Reimer)  Original code
+   !!              -   !  1998     (O. Aumont)  addition
+   !!              -   !  1999     (C. Le Quere)  modification
+   !!             1.0  !  2004     (O. Aumont)  modification
+   !!              -   !  2006     (R. Gangsto)  modification
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_che        :  Sea water chemistry computed following OCMIP protocol
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         !
+   USE sms             ! 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_che    ! called in p4zprg.F90
+
+   !! * Module variables
+
+   REAL(wp) :: &
+      salchl = 1./1.80655 ! conversion factor for salinity --> chlorinity (Wooster et al. 1969)
+
+   REAL(wp) :: &            ! coeff. for apparent solubility equilibrium 
+      akcc1 = -171.9065 , &    ! Millero et al. 1995 from Mucci 1983
+      akcc2 = -0.077993 , &  
+      akcc3 = 2839.319  , &  
+      akcc4 = 71.595    , &  
+      akcc5 = -0.77712  , &  
+      akcc6 = 0.0028426 , &  
+      akcc7 = 178.34    , &  
+      akcc8 = -0.07711  , &  
+      akcc9 = 0.0041249
+
+
+   REAL(wp) :: &             ! universal gas constants
+      rgas = 83.143, &
+      oxyco = 1./22.4144
+
+   REAL(wp) :: &             ! borat constants
+      bor1 = 0.00023, &
+      bor2 = 1./10.82
+
+   REAL(wp) :: &              !
+      ca0 = -162.8301  , &
+      ca1 = 218.2968   , &
+      ca2 = 90.9241    , &
+      ca3 = -1.47696   , &
+      ca4 = 0.025695   , &
+      ca5 = -0.025225  , &
+      ca6 = 0.0049867
+
+   REAL(wp) :: &              ! coeff. for 1. dissoc. of carbonic acid (Edmond and Gieskes, 1970)   
+      c10 = -3670.7   , &
+      c11 = 62.008    , &
+      c12 = -9.7944   , &
+      c13 = 0.0118    , &
+      c14 = -0.000116
+
+   REAL(wp) :: &              ! coeff. for 2. dissoc. of carbonic acid (Millero, 1995)   
+      c20 = -1394.7   , &
+      c21 = -4.777    , &
+      c22 = 0.0184    , &
+      c23 = -0.000118
+
+   REAL(wp) :: &             ! constants for calculate concentrations 
+      st1  = 0.14     , &    ! for sulfate (Morris & Riley 1966)
+      st2  = 1./96.062, &
+      ks0  = 141.328  , &
+      ks1  = -4276.1  , &
+      ks2  = -23.093  , &
+      ks3  = -13856.  , &
+      ks4  = 324.57   , &
+      ks5  = -47.986  , &
+      ks6  = 35474.   , &
+      ks7  = -771.54  , &
+      ks8  = 114.723  , &
+      ks9  = -2698.   , &
+      ks10 = 1776.    , &
+      ks11 = 1.       , &
+      ks12 = -0.001005 
+
+   REAL(wp) :: &             ! constants for calculate concentrations 
+      ft1  = 0.000067   , &  ! fluorides (Dickson & Riley 1979 )
+      ft2  = 1./18.9984 , &
+      kf0  = -12.641    , &
+      kf1  = 1590.2     , &
+      kf2  = 1.525      , &
+      kf3  = 1.0        , &
+      kf4  =-0.001005
+
+
+   REAL(wp) :: &              ! coeff. for 1. dissoc. of boric acid (Dickson and Goyet, 1994)
+      cb0  = -8966.90, &
+      cb1  = -2890.53, &
+      cb2  = -77.942 , &
+      cb3  = 1.728   , &
+      cb4  = -0.0996 , &
+      cb5  = 148.0248, &
+      cb6  = 137.1942, &
+      cb7  = 1.62142 , &
+      cb8  = -24.4344, &
+      cb9  = -25.085 , &
+      cb10 = -0.2474 , &
+      cb11 = 0.053105
+
+   REAL(wp) :: &             ! coeff. for dissoc. of water (Dickson and Riley, 1979 )
+      cw0 = -13847.26  , &
+      cw1 = 148.9652   , &
+      cw2 = -23.6521   , &
+      cw3 = 118.67     , &
+      cw4 = -5.977     , &
+      cw5 = 1.0495     , &
+      cw6 = -0.01615
+ 
+   REAL(wp) :: &             ! coeff. for dissoc. of phosphate (Millero (1974)
+      cp10 = 115.54    , &
+      cp11 = -4576.752 , &
+      cp12 = -18.453   , &
+      cp13 = -106.736  , &
+      cp14 = 0.69171   , &
+      cp15 = -0.65643  , &
+      cp16 = -0.01844  , &
+      cp20 = 172.1033  , &
+      cp21 = -8814.715 , &
+      cp22 = -27.927   , &
+      cp23 = -160.340  , &
+      cp24 = 1.3566    , &
+      cp25 = 0.37335   , &
+      cp26 = -0.05778  , &
+      cp30 = -18.126   , &
+      cp31 = -3070.75  , &
+      cp32 = 17.27039  , &
+      cp33 = 2.81197   , &
+      cp34 = -44.99486 , &
+      cp35 = -0.09984
+
+   REAL(wp) :: &             ! coeff. for dissoc. of silicates (Millero (1974)  
+      cs10 = 117.385   , &  
+      cs11 = -8904.2   , & 
+      cs12 = -19.334   , & 
+      cs13 = -458.79   , & 
+      cs14 = 3.5913    , & 
+      cs15 = 188.74    , & 
+      cs16 = -1.5998   , & 
+      cs17 = -12.1652  , & 
+      cs18 = 0.07871   , & 
+      cs19 = 0.        , & 
+      cs20 = 1.        , & 
+      cs21 = -0.001005
+
+   REAL(wp) :: &              ! volumetric solubility constants for o2 in ml/l (Weiss, 1974)
+      ox0 = -58.3877   , &
+      ox1 = 85.8079    , &
+      ox2 = 23.8439    , &
+      ox3 = -0.034892  , &
+      ox4 = 0.015568   , &
+      ox5 = -0.0019387 
+
+   REAL(wp), DIMENSION(5)  :: &  ! coeff. for seawater pressure correction 
+      devk1, devk2, devk3,    &  ! (millero 95)
+      devk4, devk5
+
+   DATA devk1 / -25.5    , -15.82    , -29.48  , -25.60     , -48.76    /   
+   DATA devk2 / 0.1271   , -0.0219   , 0.1622  , 0.2324     , 0.5304    /   
+   DATA devk3 / 0.       , 0.        , 2.608E-3,  -3.6246E-3, 0.        /   
+   DATA devk4 / -3.08E-3 , 1.13E-3   , -2.84E-3, -5.13E-3   , -11.76E-3 /   
+   DATA devk5 / 0.0877E-3, -0.1475E-3,  0.     , 0.0794E-3  , 0.3692E-3 /
+
+   !!* Substitution
+#include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_che
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_che  ***
+      !!
+      !! ** Purpose :   Sea water chemistry computed following OCMIP protocol
+      !!
+      !! ** Method  : - ...
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ztkel, zsal , zqtt  , zbuf1 , zbuf2
+      REAL(wp) ::   zpres, ztc  , zcl   , zcpexp, zoxy  , zcpexp2
+      REAL(wp) ::   zsqrt, ztr  , zlogt , zcek1
+      REAL(wp) ::   zlqtt, zqtt2, zsal15, zis   , zis2 , zisqrt
+      REAL(wp) ::   zckb , zck1 , zck2  , zckw  , zak1 , zak2  , zakb , zaksp0, zakw
+      REAL(wp) ::   zst  , zft  , zcks  , zckf  , zaksp1
+      !!---------------------------------------------------------------------
+
+      ! CHEMICAL CONSTANTS - SURFACE LAYER
+      ! ----------------------------------
+!CDIR NOVERRCHK
+      DO jj = 1, jpj
+!CDIR NOVERRCHK
+         DO ji = 1, jpi
+
+            !                             ! SET ABSOLUTE TEMPERATURE
+            ztkel = tn(ji,jj,1) + 273.16
+            zqtt  = ztkel * 0.01
+            zqtt2 = zqtt * zqtt
+            zsal  = sn(ji,jj,1) + (1.- tmask(ji,jj,1) ) * 35.
+            zlqtt = LOG( zqtt )
+
+            !                             ! LN(K0) OF SOLUBILITY OF CO2 (EQ. 12, WEISS, 1980)
+            !                             !     AND FOR THE ATMOSPHERE FOR NON IDEAL GAS
+            zcek1 = ca0 + ca1 / zqtt + ca2 * zlqtt + ca3 * zqtt2 + zsal*( ca4 + ca5 * zqtt + ca6 * zqtt2 )
+
+            !                             ! LN(K0) OF SOLUBILITY OF O2 and N2 (EQ. 4, WEISS, 1970)
+            zoxy  = ox0 + ox1 / zqtt + ox2 * zlqtt + zsal * ( ox3 + ox4 * zqtt + ox5 * zqtt2 )
+
+            !                             ! SET SOLUBILITIES OF O2 AND CO2
+            chemc(ji,jj,1) = EXP( zcek1 ) * 1.e-6 * rhop(ji,jj,1) / 1000.
+            chemc(ji,jj,2) = EXP( zoxy  ) * oxyco
+
+         END DO
+      END DO
+
+      ! CHEMICAL CONSTANTS - DEEP OCEAN
+      ! -------------------------------
+!CDIR NOVERRCHK
+      DO jk = 1, jpk
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+               ! SET PRESSION
+               zpres   = 1.025e-1 * fsdept(ji,jj,jk)
+
+               ! SET ABSOLUTE TEMPERATURE
+               ztkel   = tn(ji,jj,jk) + 273.16
+               zqtt    = ztkel * 0.01
+               zsal    = sn(ji,jj,jk) + ( 1.-tmask(ji,jj,jk) ) * 35.
+               zsqrt  = SQRT( zsal )
+               zsal15  = zsqrt * zsal
+               zlogt  = LOG( ztkel )
+               ztr    = 1. / ztkel
+               zis    = 19.924 * zsal / ( 1000.- 1.005 * zsal )
+               zis2   = zis * zis
+               zisqrt = SQRT( zis )
+               ztc     = tn(ji,jj,jk) + ( 1.- tmask(ji,jj,jk) ) * 20.
+
+               ! CHLORINITY (WOOSTER ET AL., 1969)
+               zcl     = zsal * salchl
+
+               ! TOTAL SULFATE CONCENTR. [MOLES/kg soln]
+               zst     = st1 * zcl * st2
+
+               ! TOTAL FLUORIDE CONCENTR. [MOLES/kg soln]
+               zft     = ft1 * zcl * ft2
+
+               ! DISSOCIATION CONSTANT FOR SULFATES on free H scale (Dickson 1990)
+               zcks    = EXP(  ks1 * ztr + ks0 + ks2 * zlogt                           &
+                  &                     + ( ks3 * ztr + ks4 + ks5 * zlogt ) * zisqrt   &
+                  &                     + ( ks6 * ztr + ks7 + ks8 * zlogt ) * zis      &
+                  &                     + ks9 * ztr * zis * zisqrt + ks10 * ztr *zis2 + LOG( ks11 + ks12 *zsal )  )
+
+               ! DISSOCIATION CONSTANT FOR FLUORIDES on free H scale (Dickson and Riley 79)
+               zckf    = EXP(  kf1 * ztr + kf0 + kf2 * zisqrt + LOG( kf3 + kf4 * zsal )  )
+
+               ! DISSOCIATION CONSTANT FOR CARBONATE AND BORATE
+               zckb    = ( cb0 + cb1 * zsqrt + cb2  * zsal + cb3 * zsal15 + cb4 * zsal * zsal ) * ztr   &
+                  &    + ( cb5 + cb6 * zsqrt + cb7  * zsal )                                            &
+                  &    + ( cb8 + cb9 * zsqrt + cb10 * zsal ) * zlogt + cb11 * zsqrt * ztkel             &
+                  &    + LOG(  ( 1.+ zst / zcks + zft / zckf ) / ( 1.+ zst / zcks )  )
+!!gm zsal**2 to be replaced by a *...
+               zck1    = c10 * ztr + c11 + c12 * zlogt + c13 * zsal + c14 * zsal**2
+               zck2    = c20 * ztr + c21 + c22 * zsal   + c23 * zsal**2
+
+               ! PKW (H2O) (DICKSON AND RILEY, 1979)
+               zckw    = cw0 * ztr + cw1 + cw2 * zlogt + ( cw3 * ztr + cw4 + cw5 * zlogt ) * zsqrt + cw6 * zsal
+
+
+               ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE IN SEAWATER
+               !       (S=27-43, T=2-25 DEG C) at pres =0 (atmos. pressure) (MUCCI 1983)
+               zaksp0  = akcc1 + akcc2 * ztkel + akcc3 * ztr + akcc4 * LOG10( ztkel )   &
+                  &   + ( akcc5 + akcc6 * ztkel + akcc7 * ztr ) * zsqrt + akcc8 * zsal + akcc9 * zsal15
+
+               ! K1, K2 OF CARBONIC ACID, KB OF BORIC ACID, KW (H2O) (LIT.?)
+               zak1    = 10**(zck1)
+               zak2    = 10**(zck2)
+               zakb    = EXP( zckb  )
+               zakw    = EXP( zckw )
+               zaksp1  = 10**(zaksp0)
+
+               ! FORMULA FOR CPEXP AFTER EDMOND & GIESKES (1970)
+               !        (REFERENCE TO CULBERSON & PYTKOQICZ (1968) AS MADE
+               !        IN BROECKER ET AL. (1982) IS INCORRECT; HERE RGAS IS
+               !        TAKEN TENFOLD TO CORRECT FOR THE NOTATION OF pres  IN
+               !        DBAR INSTEAD OF BAR AND THE EXPRESSION FOR CPEXP IS
+               !        MULTIPLIED BY LN(10.) TO ALLOW USE OF EXP-FUNCTION
+               !        WITH BASIS E IN THE FORMULA FOR AKSPP (CF. EDMOND
+               !        & GIESKES (1970), P. 1285-1286 (THE SMALL
+               !        FORMULA ON P. 1286 IS RIGHT AND CONSISTENT WITH THE
+               !        SIGN IN PARTIAL MOLAR VOLUME CHANGE AS SHOWN ON P. 1285))
+               zcpexp  = zpres /(rgas*ztkel)
+               zcpexp2 = zpres * zpres/(rgas*ztkel)
+
+               ! KB OF BORIC ACID, K1,K2 OF CARBONIC ACID PRESSURE
+               !        CORRECTION AFTER CULBERSON AND PYTKOWICZ (1968)
+               !        (CF. BROECKER ET AL., 1982)
+
+               zbuf1  = -(devk1(1)+devk2(1)*ztc+devk3(1)*ztc*ztc)
+               zbuf2  = 0.5*(devk4(1)+devk5(1)*ztc)
+               ak13(ji,jj,jk) = zak1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+               zbuf1  =     - ( devk1(2) + devk2(2) * ztc + devk3(2) * ztc * ztc )
+               zbuf2  = 0.5 * ( devk4(2) + devk5(2) * ztc )
+               ak23(ji,jj,jk) = zak2 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+               zbuf1  =     - ( devk1(3) + devk2(3) * ztc + devk3(3) * ztc * ztc )
+               zbuf2  = 0.5 * ( devk4(3) + devk5(3) * ztc )
+               akb3(ji,jj,jk) = zakb * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+               zbuf1  =     - ( devk1(4) + devk2(4) * ztc + devk3(4) * ztc * ztc )
+               zbuf2  = 0.5 * ( devk4(4) + devk5(4) * ztc )
+               akw3(ji,jj,jk) = zakw * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+
+               ! APPARENT SOLUBILITY PRODUCT K'SP OF CALCITE 
+               !        AS FUNCTION OF PRESSURE FOLLOWING MILLERO
+               !        (P. 1285) AND BERNER (1976)
+               zbuf1  =     - ( devk1(5) + devk2(5) * ztc + devk3(5) * ztc * ztc )
+               zbuf2  = 0.5 * ( devk4(5) + devk5(5) * ztc )
+               aksp(ji,jj,jk) = zaksp1 * EXP( zbuf1 * zcpexp + zbuf2 * zcpexp2 )
+
+
+               ! TOTAL BORATE CONCENTR. [MOLES/L]
+               borat(ji,jj,jk) = bor1 * zcl * bor2
+
+               ! Iron and SIO3 saturation concentration from ...
+               sio3eq(ji,jj,jk) = EXP(  LOG( 10.) * ( 6.44 - 968. / ztkel )  ) * 1.e-6
+               fekeq (ji,jj,jk) = 10**( 17.27 - 1565.7 / ( 273.15 + ztc ) )
+
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE p4z_che
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_che( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_che: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_che
+#endif 
+
+   !!======================================================================
+END MODULE  p4zche
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zday.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zday.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zday.F90	(revision 4536)
@@ -0,0 +1,92 @@
+MODULE p4zday
+   !!======================================================================
+   !!                         ***  MODULE p4zday  ***
+   !! TOP :   PISCES compute the day length depending on latitude and the day
+   !!======================================================================
+   !! History :    -   !  1993     (E. Maier-Reimer) Original code GBC 1993
+   !!              -   !  1999     (C. Le Quere)
+   !!             1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_day       :   compute the day length depending on latitude and the day
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_day    ! called in p4zprod.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_day
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_day  ***
+      !!
+      !! ** Purpose :   compute the day length depending on latitude and the day
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj
+      INTEGER  ::   iyy
+      REAL(wp) ::   zrum, zdelta, zcodel, zphi, zargu
+      !!---------------------------------------------------------------------
+
+      ! Get year
+      ! --------
+
+      iyy = ndastp / 10000
+
+      IF(lwp) write(numout,*)
+      IF(lwp) write(numout,*) 'p4zday : - Julian day ', nday_year
+      IF(lwp) write(numout,*) '~~~~~~'
+
+
+      IF( nleapy == 1 .AND. MOD( iyy, 4 ) == 0 ) THEN
+         zrum = FLOAT( nday_year - 80 ) / 366.
+      ELSE
+         zrum = FLOAT( nday_year - 80 ) / 365.
+      ENDIF
+
+      zdelta = SIN( zrum * rpi * 2. ) * sin( rpi * 23.5 / 180. )
+      zcodel = ASIN( zdelta )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zphi = gphit(ji,jj) * rpi / 180.
+            zargu = TAN( zcodel ) * TAN( zphi )
+            strn(ji,jj) = 0.e0
+            zargu = MIN(  1., zargu )
+            zargu = MAX( -1., zargu )
+            strn(ji,jj) = 24.- 2.* ACOS( zargu ) * 180./ rpi / 15.
+            strn(ji,jj) = MAX( strn(ji,jj), 0.e0 )
+         END DO
+      END DO
+      !
+   END SUBROUTINE p4z_day
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_day                    ! Empty routine
+   END SUBROUTINE p4z_day
+#endif 
+
+   !!======================================================================
+END MODULE  p4zday
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zdiat.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zdiat.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zdiat.F90	(revision 4536)
@@ -0,0 +1,129 @@
+MODULE p4zdiat
+   !!======================================================================
+   !!                         ***  MODULE p4zdiat  ***
+   !! TOP :   PISCES Compute the mortality terms for diatoms
+   !!======================================================================
+   !! History :   1.0  !  2002     (O. Aumont)  Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_diat       :   Compute the mortality terms for diatoms
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_diat    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_diat
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_diat  ***
+      !!
+      !! ** Purpose :   Compute the mortality terms for diatoms
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::  ji, jj, jk
+      REAL(wp) ::  zfactfe,zfactsi,zfactch, zstep, zcompadi
+      REAL(wp) ::  zrespp2, ztortp2, zmortp2
+      CHARACTER (len=25) :: charout
+ 
+      !!---------------------------------------------------------------------
+
+        zstep = rfact2 / rjjss      ! Time step duration for biology
+
+
+!    Aggregation term for diatoms is increased in case of nutrient
+!    stress as observed in reality. The stressed cells become more
+!    sticky and coagulate to sink quickly out of the euphotic zone
+!     ------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zcompadi = MAX( ( trn(ji,jj,jk,jpdia) - 1e-8), 0. )
+
+!    Aggregation term for diatoms is increased in case of nutrient
+!    stress as observed in reality. The stressed cells become more
+!    sticky and coagulate to sink quickly out of the euphotic zone
+!     ------------------------------------------------------------
+
+               zrespp2  = 1.e6 * zstep * (  wchl + wchld * ( 1.- xlimdia(ji,jj,jk) )  )    &
+# if defined key_off_degrad
+                  &       * facvol(ji,jj,jk)       &
+# endif
+                  &       * xdiss(ji,jj,jk) * zcompadi * trn(ji,jj,jk,jpdia)
+                                                                               
+
+!     Phytoplankton mortality. 
+!     ------------------------
+               ztortp2  = mprat2 * zstep * trn(ji,jj,jk,jpdia)     &
+# if defined key_off_degrad
+                  &        * facvol(ji,jj,jk)       &
+# endif
+                  &      / ( xkmort + trn(ji,jj,jk,jpdia) ) * zcompadi
+
+                zmortp2 = zrespp2 + ztortp2
+
+!   Update the arrays tra which contains the biological sources and sinks
+!   ---------------------------------------------------------------------
+               zfactch = trn(ji,jj,jk,jpdch) / ( trn(ji,jj,jk,jpdia) + rtrn )
+               zfactfe = trn(ji,jj,jk,jpdfe) / ( trn(ji,jj,jk,jpdia) + rtrn )
+               zfactsi = trn(ji,jj,jk,jpbsi) / ( trn(ji,jj,jk,jpdia) + rtrn )
+
+               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zmortp2 
+               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zmortp2 * zfactch
+               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zmortp2 * zfactfe
+               tra(ji,jj,jk,jpbsi) = tra(ji,jj,jk,jpbsi) - zmortp2 * zfactsi
+               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) + zmortp2 * zfactsi
+#if defined key_kriest
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortp2  
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + ztortp2 * xkr_ndiat + zrespp2 * xkr_naggr
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zmortp2 * zfactfe
+#else
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zrespp2 + 0.5 * ztortp2
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + 0.5 * ztortp2
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + 0.5 * ztortp2 * zfactfe
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + ( zrespp2 + 0.5 * ztortp2 ) * zfactfe
+#endif
+            END DO
+         END DO
+      END DO
+      !
+        IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('diat')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+             
+   END SUBROUTINE p4z_diat
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_diat                    ! Empty routine
+   END SUBROUTINE p4z_diat
+#endif 
+
+   !!======================================================================
+END MODULE  p4zdiat
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zflx.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zflx.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zflx.F90	(revision 4536)
@@ -0,0 +1,218 @@
+MODULE p4zflx
+   !!======================================================================
+   !!                         ***  MODULE p4zflx  ***
+   !! TOP :   PISCES CALCULATES GAS EXCHANGE AND CHEMISTRY AT SEA SURFACE
+   !!======================================================================
+   !! History :    -   !  1988-07  (E. MAIER-REIMER) Original code
+   !!              -   !  1998     (O. Aumont) additions
+   !!              -   !  1999     (C. Le Quere) modifications
+   !!             1.0  !  2004     (O. Aumont) modifications
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_flx       :   CALCULATES GAS EXCHANGE AND CHEMISTRY AT SEA SURFACE
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_flx    ! called in p4zprg.F90
+
+   REAL(wp) :: &  ! pre-industrial atmospheric [co2] (ppm) 	
+     atcox = 0.20946
+
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_flx ( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_flx  ***
+      !!
+      !! ** Purpose :   CALCULATES GAS EXCHANGE AND CHEMISTRY AT SEA SURFACE
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      INTEGER  ::   ji, jj, jrorr, nspyr
+      REAL(wp) ::   zttc, zws
+      REAL(wp) ::   zfld, zflu, zoxy16, zflu16, zfact
+      REAL(wp) ::   zph, zah2, zbot, zdic, zalk, zschmitto2, zalka, zschmittco2
+      REAL(wp), DIMENSION(jpi,jpj) ::   zkgco2, zkgo2, zh2co3, zqcumtemp 
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+      ! -----------------------------------------------------
+      !     ASSIGNATION TO EXPONENTS IN THE LISS AND MERLIVAT
+      !     FORMULATION OF THE GAS EXCHANGE RATE
+      ! -----------------------------------------------------
+
+      nspyr = INT( raass / rdt )
+
+      ! SURFACE CHEMISTRY (PCO2 AND [H+] IN
+      !     SURFACE LAYER); THE RESULT OF THIS CALCULATION
+      !     IS USED TO COMPUTE AIR-SEA FLUX OF CO2
+
+      DO jrorr = 1, 10
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+               ! DUMMY VARIABLES FOR DIC, H+, AND BORATE
+               zbot  = borat(ji,jj,1)
+               zfact = rhop(ji,jj,1) / 1000. + rtrn
+               zdic  = trn(ji,jj,1,jpdic) / zfact
+               zph   = MAX( hi(ji,jj,1), 1.e-10 ) / zfact
+               zalka = trn(ji,jj,1,jptal) / zfact
+
+               ! CALCULATE [ALK]([CO3--], [HCO3-])
+               zalk  = zalka - (  akw3(ji,jj,1) / zph - zph + zbot / ( 1.+ zph / akb3(ji,jj,1) )  )
+
+               ! CALCULATE [H+] AND [H2CO3]
+               zah2   = SQRT(  (zdic-zalk)**2 + 4.* ( zalk * ak23(ji,jj,1)   &
+                  &                                        / ak13(ji,jj,1) ) * ( 2.* zdic - zalk )  )
+               zah2   = 0.5 * ak13(ji,jj,1) / zalk * ( ( zdic - zalk ) + zah2 )
+               zh2co3(ji,jj) = ( 2.* zdic - zalk ) / ( 2.+ ak13(ji,jj,1) / zah2 ) * zfact
+               hi(ji,jj,1)   = zah2 * zfact
+            END DO
+         END DO
+      END DO
+
+
+      ! --------------
+      ! COMPUTE FLUXES
+      ! --------------
+
+      ! FIRST COMPUTE GAS EXCHANGE COEFFICIENTS
+      ! -------------------------------------------
+
+!CDIR NOVERRCHK
+      DO jj = 1, jpj
+!CDIR NOVERRCHK
+         DO ji = 1, jpi
+
+            zttc = MIN( 35., tn(ji,jj,1) )
+!!gm  optimisation & more precise computation with factorisation of the polynome
+            zschmittco2 = 2073.1 - 125.62 * zttc + 3.6276 * zttc**2 - 0.043126 * zttc**3
+            zws         = vatm(ji,jj)
+
+            ! COMPUTE GAS EXCHANGE FOR CO2
+            zkgco2(ji,jj) = (  0.3 * zws * zws    &
+               &             + 2.5 * ( 0.5246 + zttc * ( 0.016256 + zttc * 0.00049946 ) )  )   &
+               &          * SQRT( 660./ zschmittco2 )
+
+            ! CONVERT TO m/s, and apply sea-ice cover
+            zkgco2(ji,jj) = zkgco2(ji,jj) / ( 100. * 3600. )      &
+# if defined key_off_degrad
+               &         * facvol(ji,jj,1)      &
+# endif
+               &         * ( 1.- freeze(ji,jj) ) * tmask(ji,jj,1)
+
+         END DO
+      END DO
+
+      ! COMPUTE GAS EXCHANGE COEFFICIENT FO O2 FROM Waninkhof EQUATIONS
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+          zws  = vatm(ji,jj)
+          zttc = MIN( 35., tn(ji,jj,1) )
+!!gm  optimisation & more precise computation with factorisation of the polynome
+          zschmitto2   = 1953.4 - 128.0 * zttc + 3.9918 * zttc**2 - 0.050091 * zttc**3
+
+          zkgo2(ji,jj) = (  0.3 * zws * zws   &
+             &            + 2.5 * ( 0.5246 + zttc * ( 0.016256 + zttc * 0.00049946 ) )  )   &
+             &         * SQRT( 660./ zschmitto2 )
+
+          ! CONVERT TO m/s AND APPLY SEA ICE COVER
+          zkgo2(ji,jj) = zkgo2(ji,jj) / ( 100.*3600.)        &
+# if defined key_off_degrad
+             &        * facvol(ji,jj,1)       &
+# endif
+             &        * ( 1.- freeze(ji,jj) ) *tmask(ji,jj,1)
+
+         END DO
+      END DO
+
+      zqcumtemp(:,:) = 0.
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+            ! Compute CO2 flux for the sea and air
+            zfld = atcco2 * tmask(ji,jj,1) * chemc(ji,jj,1) * zkgco2(ji,jj)
+            zflu = zh2co3(ji,jj) * tmask(ji,jj,1) * zkgco2(ji,jj)
+            tra(ji,jj,1,jpdic) = tra(ji,jj,1,jpdic) + ( zfld - zflu ) / fse3t(ji,jj,1)
+
+            zqcumtemp(ji,jj) = ( zfld - zflu ) * rfact &
+               &             * e1t(ji,jj) * e2t(ji,jj) * tmask(ji,jj,1) * 1000.
+            ! Compute O2 flux 
+            zoxy16 = trn(ji,jj,1,jpoxy)
+            zflu16 = ( atcox * chemc(ji,jj,2) - zoxy16 ) * zkgo2(ji,jj)
+            tra(ji,jj,1,jpoxy) = tra(ji,jj,1,jpoxy) + zflu16 / fse3t(ji,jj,1)
+
+# if defined key_trc_diaadd
+            ! Save diagnostics
+            trc2d(ji,jj,1) = ( zfld - zflu ) * 1000.
+            trc2d(ji,jj,2) = zflu16 * 1000.
+            trc2d(ji,jj,3) = zkgco2(ji,jj)
+            trc2d(ji,jj,4) = atcco2 - zh2co3(ji,jj) / ( chemc(ji,jj,1) + rtrn )
+# endif
+         END DO
+      END DO
+      !
+
+      DO jj = 1, jpj
+        DO ji = 1, jpi
+           qcumul(1) = qcumul(1) + zqcumtemp(ji,jj) * tmask_i(ji,jj)
+        END DO
+      END DO
+
+      IF( MOD( kt, nspyr ) == 0 ) THEN
+        WRITE(numout,*) ' Atmospheric pCO2    :'
+        WRITE(numout,*) '-------------------- : ',kt,'  ',atcco2
+        WRITE(numout,*) '(ppm)'
+        WRITE(numout,*) 'Total Flux of Carbon :'
+        WRITE(numout,*) '-------------------- : ',qcumul(1)*12./1E15
+        WRITE(numout,*) '(GtC/an)'
+        qcumul(1) = 0.
+      ENDIF
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('flx ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+
+   END SUBROUTINE p4z_flx
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_flx( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_flx: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_flx
+#endif 
+
+   !!======================================================================
+END MODULE  p4zflx
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zint.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zint.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zint.F90	(revision 4536)
@@ -0,0 +1,108 @@
+MODULE p4zint
+   !!======================================================================
+   !!                         ***  MODULE p4zint  ***
+   !! TOP :   PISCES interpolation and computation of various accessory fields
+   !!======================================================================
+   !! 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
+   !!----------------------------------------------------------------------
+   !!   p4z_int        :  interpolation and computation of various accessory fields
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_int    ! called in p4zprg.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_int( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_int  ***
+      !!
+      !! ** Purpose :   interpolation and computation of various accessory fields
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      INTEGER  ::   ji, jj
+      INTEGER  ::   iman, ivit1t, ivit2t
+      REAL(wp) ::   zpdtan, zman, zpdtmo, zdemi
+      REAL(wp) ::   zt, zdum
+      !!---------------------------------------------------------------------
+
+      zpdtan = raass / rdt
+      zman   = 12.
+      iman   = 12
+      zpdtmo = zpdtan / zman
+      zdemi  = zpdtmo / 2.
+      zt     = ( float ( kt) + zdemi) / zpdtmo
+      
+      !  recherche de l indice des enregistrements
+      !  du modele dynamique encadrant le pas de temps kt.
+      !  --------------------------------------------------
+
+      xtvit = zt - FLOAT( INT( zt ) )
+      ivit1t = INT( zt )
+      ivit2t = ivit1t + 1
+      ivit1t = MOD ( ivit1t, iman )
+      IF( ivit1t == 0 )   ivit1t = iman
+      ivit2t = MOD ( ivit2t, iman )
+      IF( ivit2t == 0 )   ivit2t = iman
+
+      ! Interpolation of dust deposition
+      ! --------------------------------
+
+      dust(:,:) = ( 1.- xtvit ) * dustmo(:,:,ivit1t) + xtvit * dustmo(:,:,ivit2t)
+
+      ! Computation of phyto and zoo metabolic rate
+      ! -------------------------------------------
+
+      Tgfunc (:,:,:) = EXP( 0.063913 * tn(:,:,:) )
+      Tgfunc2(:,:,:) = EXP( 0.07608  * tn(:,:,:) )
+
+      ! Computation of the silicon dependant half saturation
+      ! constant for silica uptake
+      ! ---------------------------------------------------
+
+      DO ji = 1, jpi
+         DO jj = 1, jpj
+            zdum = trn(ji,jj,1,jpsil) * trn(ji,jj,1,jpsil)
+            xksimax(ji,jj) = MAX( xksimax(ji,jj), ( 1.+ 7.* zdum / ( xksi2 * xksi2 * 25. + zdum ) ) * 1e-6 )
+         END DO
+      END DO
+
+      IF( nday_year == 365 ) THEN
+         xksi    = xksimax
+         xksimax = 0.e0
+      ENDIF
+      !
+   END SUBROUTINE p4z_int
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_int( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_int: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_int
+#endif 
+
+   !!======================================================================
+END MODULE  p4zint
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlim.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlim.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlim.F90	(revision 4536)
@@ -0,0 +1,162 @@
+MODULE p4zlim
+   !!======================================================================
+   !!                         ***  MODULE p4zlim  ***
+   !! TOP :   PISCES 
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_lim        :  
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_lim    ! called in p4zprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_lim
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_lim  ***
+      !!
+      !! ** Purpose :   Compute the co-limitations by the various nutrients
+      !!              for the various phytoplankton species
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zlim1, zlim2, zlim3, zlim4, zno3, zferlim
+      REAL(wp) ::   zconctemp, zconctemp2, zconctempn, zconctempn2
+      REAL(wp) ::   ztemp, zdenom
+      !!---------------------------------------------------------------------
+
+!  Tuning of the iron concentration to a minimum
+!  level that is set to the detection limit
+!  -------------------------------------
+
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zno3   = trn(ji,jj,jk,jpno3) * 1.e6
+               zferlim = MAX( 1.5e-11*(zno3/40)**2, 3e-12 )
+               zferlim = MIN( zferlim, 1.5e-11 )
+               trn(ji,jj,jk,jpfer) = MAX( trn(ji,jj,jk,jpfer), zferlim )
+            END DO
+         END DO
+      END DO
+
+!  Computation of a variable Ks for iron on diatoms
+!  taking into account that increasing biomass is
+!  made of generally bigger cells
+!  ------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zconctemp   = MAX( 0.e0 , trn(ji,jj,jk,jpdia)-5e-7 )
+               zconctemp2  = trn(ji,jj,jk,jpdia) - zconctemp
+               zconctempn  = MAX( 0.e0 , trn(ji,jj,jk,jpphy)-1e-6 )
+               zconctempn2 = trn(ji,jj,jk,jpphy) - zconctempn
+               concdfe(ji,jj,jk) = ( zconctemp2 * conc3 + 0.4e-9 * zconctemp)   &
+                  &              / ( trn(ji,jj,jk,jpdia) + rtrn )
+               concdfe(ji,jj,jk) = MAX( conc3, concdfe(ji,jj,jk) )
+               concnfe(ji,jj,jk) = ( zconctempn2 * conc2 + 0.08e-9 * zconctempn)   &
+                  &              / ( trn(ji,jj,jk,jpphy) + rtrn )
+               concnfe(ji,jj,jk) = MAX( conc2, concnfe(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+    
+!      Michaelis-Menten Limitation term for nutrients
+!      Small flagellates
+!      -----------------------------------------------
+              zdenom = 1. / &
+                  & ( conc0 * concnnh4 + concnnh4 * trn(ji,jj,jk,jpno3) + conc0 * trn(ji,jj,jk,jpnh4) )
+               xnanono3(ji,jj,jk) = trn(ji,jj,jk,jpno3) * concnnh4 * zdenom
+               xnanonh4(ji,jj,jk) = trn(ji,jj,jk,jpnh4) * conc0    * zdenom
+
+               zlim1 = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
+               zlim2 = trn(ji,jj,jk,jppo4) / ( trn(ji,jj,jk,jppo4) + concnnh4          ) 
+               zlim3 = trn(ji,jj,jk,jpfer) / ( trn(ji,jj,jk,jpfer) + concnfe(ji,jj,jk) )
+               xlimphy(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+               zlim1 = trn(ji,jj,jk,jpnh4) / ( concnnh4 + trn(ji,jj,jk,jpnh4) )
+               zlim3 = trn(ji,jj,jk,jpfer) / ( conc2    + trn(ji,jj,jk,jpfer) )
+               zlim4 = trn(ji,jj,jk,jpdoc) / ( xkdoc2   + trn(ji,jj,jk,jpdoc) )
+               xlimbac(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 ) * zlim4
+
+            END DO
+         END DO
+      END DO
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!   Michaelis-Menten Limitation term for nutrients Diatoms
+!   ----------------------------------------------
+              zdenom = 1. / &
+                  & ( conc1 * concdnh4 + concdnh4 * trn(ji,jj,jk,jpno3) + conc1 * trn(ji,jj,jk,jpnh4) )
+
+               xdiatno3(ji,jj,jk) = trn(ji,jj,jk,jpno3) * concdnh4 * zdenom
+               xdiatnh4(ji,jj,jk) = trn(ji,jj,jk,jpnh4) * conc1    * zdenom 
+
+               zlim1 = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
+               zlim2 = trn(ji,jj,jk,jppo4) / ( trn(ji,jj,jk,jppo4) + concdnh4          )
+               zlim3 = trn(ji,jj,jk,jpsil) / ( trn(ji,jj,jk,jpsil) + xksi   (ji,jj)    )
+               zlim4 = trn(ji,jj,jk,jpfer) / ( trn(ji,jj,jk,jpfer) + concdfe(ji,jj,jk) )
+               xlimdia(ji,jj,jk) = MIN( zlim1, zlim2, zlim3, zlim4 )
+
+            END DO
+         END DO
+      END DO
+
+
+      ! Compute the fraction of nanophytoplankton that is made of calcifiers
+      ! --------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztemp = MAX( 0., tn(ji,jj,jk) )
+               xfracal(ji,jj,jk) = caco3r * xlimphy(ji,jj,jk)   &
+                  &                       * MAX( 0.0001, ztemp / ( 2.+ ztemp ) )   &
+                  &                       * MAX( 1., trn(ji,jj,jk,jpphy) * 1.e6 / 2. )
+               xfracal(ji,jj,jk) = MIN( 0.8 , xfracal(ji,jj,jk) )
+               xfracal(ji,jj,jk) = MAX( 0.01, xfracal(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE p4z_lim
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_lim                   ! Empty routine
+   END SUBROUTINE p4z_lim
+#endif 
+
+   !!======================================================================
+END MODULE  p4zlim
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlys.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlys.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zlys.F90	(revision 4536)
@@ -0,0 +1,168 @@
+MODULE p4zlys
+   !!======================================================================
+   !!                         ***  MODULE p4zlys  ***
+   !! TOP :   PISCES 
+   !!======================================================================
+   !! History :    -   !  1988-07  (E. MAIER-REIMER) Original code
+   !!              -   !  1998     (O. Aumont) additions
+   !!              -   !  1999     (C. Le Quere) modifications
+   !!             1.0  !  2004     (O. Aumont) modifications
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_lys        :  
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_lys    ! called in p4zprg.F90
+
+   !! * Module variables
+
+   REAL(wp) :: &
+      calcon = 1.03E-2        ! mean calcite concentration [Ca2+] in sea water [mole/kg solution]
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_lys
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_lys  ***
+      !!
+      !! ** Purpose :   CALCULATES DEGREE OF CACO3 SATURATION IN THE WATER
+      !!              COLUMN, DISSOLUTION/PRECIPITATION OF CACO3 AND LOSS
+      !!              OF CACO3 TO THE CACO3 SEDIMENT POOL.
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jn
+      REAL(wp) ::   zbot, zalk, zdic, zph, zremco3, zah2
+      REAL(wp) ::   zdispot, zfact, zalka
+      REAL(wp) ::   zomegaca, zexcess, zexcess0
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zco3
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+
+      !     -------------------------------------------
+      !     COMPUTE [CO3--] and [H+] CONCENTRATIONS
+      !     -------------------------------------------
+      
+      DO jn = 1, 5                               !  BEGIN OF ITERATION
+         !
+!CDIR NOVERRCHK
+         DO jk = 1, jpkm1
+!CDIR NOVERRCHK
+            DO jj = 1, jpj
+!CDIR NOVERRCHK
+               DO ji = 1, jpi
+
+                  ! SET DUMMY VARIABLE FOR TOTAL BORATE
+                  zbot  = borat(ji,jj,jk)
+                  zfact = rhop (ji,jj,jk) / 1000. + rtrn
+
+                  ! SET DUMMY VARIABLE FOR [H+]
+                  zph   = hi(ji,jj,jk) * tmask(ji,jj,jk) / zfact + ( 1.-tmask(ji,jj,jk) ) * 1.e-9
+
+                  ! SET DUMMY VARIABLE FOR [SUM(CO2)]GIVEN 
+                  zdic  = trn(ji,jj,jk,jpdic) / zfact
+                  zalka = trn(ji,jj,jk,jptal) / zfact
+
+                  ! CALCULATE [ALK]([CO3--], [HCO3-])
+                  zalk  = zalka - (  akw3(ji,jj,jk) / zph - zph   &
+                     &             + zbot / (1.+ zph / akb3(ji,jj,jk) )  )
+
+                  ! CALCULATE [H+] and [CO3--]
+                  zah2 = SQRT( (zdic-zalk)*(zdic-zalk)+   &
+                     &     4.*(zalk*ak23(ji,jj,jk)/ak13(ji,jj,jk))   &
+                     &     *(2*zdic-zalk))
+
+                  zah2=0.5*ak13(ji,jj,jk)/zalk*((zdic-zalk)+zah2)
+                  zco3(ji,jj,jk) = zalk/(2.+zah2/ak23(ji,jj,jk))*zfact
+
+                  hi(ji,jj,jk)  = zah2*zfact
+
+               END DO
+            END DO
+         END DO
+         !
+      END DO 
+
+      !     ---------------------------------------------------------
+      !        CALCULATE DEGREE OF CACO3 SATURATION AND CORRESPONDING
+      !        DISSOLOUTION AND PRECIPITATION OF CACO3 (BE AWARE OF
+      !        MGCO3)
+      !     ---------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               ! DEVIATION OF [CO3--] FROM SATURATION VALUE
+               zomegaca = ( calcon * zco3(ji,jj,jk) ) / aksp(ji,jj,jk)
+
+               ! SET DEGREE OF UNDER-/SUPERSATURATION
+               zexcess0 = MAX( 0., ( 1.- zomegaca ) )
+               zexcess  = zexcess0**nca
+
+               ! AMOUNT CACO3 (12C) THAT RE-ENTERS SOLUTION
+               !       (ACCORDING TO THIS FORMULATION ALSO SOME PARTICULATE
+               !       CACO3 GETS DISSOLVED EVEN IN THE CASE OF OVERSATURATION)
+# if defined key_off_degrad
+              zdispot = kdca * zexcess * trn(ji,jj,jk,jpcal) * facvol(ji,jj,jk)
+# else
+              zdispot = kdca * zexcess * trn(ji,jj,jk,jpcal)
+# endif
+
+              !  CHANGE OF [CO3--] , [ALK], PARTICULATE [CACO3],
+              !       AND [SUM(CO2)] DUE TO CACO3 DISSOLUTION/PRECIPITATION
+              zremco3 = zdispot / rmoss
+              zco3(ji,jj,jk) = zco3(ji,jj,jk) + zremco3 * rfact
+              tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + 2.*zremco3
+              tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) -    zremco3
+              tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) +    zremco3
+
+            END DO
+         END DO
+      END DO
+
+# if defined key_trc_dia3d
+         trc3d(:,:,:,1) = hi(:,:,:)
+         trc3d(:,:,:,2) = zco3(:,:,:)
+         trc3d(:,:,:,3) = aksp(:,:,:) / calcon
+# endif
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('lys ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_lys
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_lys( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_lys: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_lys
+#endif 
+
+   !!======================================================================
+END MODULE  p4zlys
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmeso.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmeso.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmeso.F90	(revision 4536)
@@ -0,0 +1,280 @@
+MODULE p4zmeso
+   !!======================================================================
+   !!                         ***  MODULE p4zmeso  ***
+   !! TOP :   PISCES Compute the sources/sinks for mesozooplankton
+   !!======================================================================
+   !! History :   1.0  !  2002     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_meso       :   Compute the sources/sinks for mesozooplankton
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_meso    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_meso
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_meso  ***
+      !!
+      !! ** Purpose :   Compute the sources/sinks for mesozooplankton
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk
+      REAL(wp) :: zcompadi, zcompaph, zcompapoc, zcompaz
+      REAL(wp) :: zfact, zstep, zcompam, zdenom, zgraze2
+      REAL(wp) :: zgrarem2, zgrafer2, zgrapoc2, zprcaca, zmortz2
+#if defined key_kriest
+      REAL znumpoc
+#endif
+      REAL(wp),DIMENSION(jpi,jpj,jpk) :: zrespz2,ztortz2,zgrazd,zgrazz,zgrazpof
+      REAL(wp),DIMENSION(jpi,jpj,jpk) :: zgrazn,zgrazpoc,zgraznf,zgrazf
+      REAL(wp),DIMENSION(jpi,jpj,jpk) :: zgrazfff,zgrazffe
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      zstep = rfact2 / rjjss      ! Time step duration for biology
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zcompam = MAX( ( trn(ji,jj,jk,jpmes) - 1.e-9 ), 0.e0 )
+# if defined key_off_degrad
+               zfact   = zstep * tgfunc(ji,jj,jk) * zcompam * facvol(ji,jj,jk)
+# else
+               zfact   = zstep * tgfunc(ji,jj,jk) * zcompam
+# endif
+
+!     Respiration rates of both zooplankton
+!     -------------------------------------
+               zrespz2(ji,jj,jk)  = resrat2 * zfact * ( 1. + 3. * nitrfac(ji,jj,jk) )        &
+                  &       * trn(ji,jj,jk,jpmes) / ( xkmort + trn(ji,jj,jk,jpmes) )
+
+!     Zooplankton mortality. A square function has been selected with
+!     no real reason except that it seems to be more stable and may
+!     mimic predation.
+!     ---------------------------------------------------------------
+               ztortz2(ji,jj,jk) = mzrat2 * 1.e6 * zfact * trn(ji,jj,jk,jpmes)
+               !
+            END DO
+         END DO
+      END DO
+
+
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               zcompadi  = MAX( ( trn(ji,jj,jk,jpdia) - 1.e-8 ), 0.e0 )
+               zcompaz   = MAX( ( trn(ji,jj,jk,jpzoo) - 1.e-8 ), 0.e0 )
+               zcompaph  = MAX( ( trn(ji,jj,jk,jpphy) - 2.e-7 ), 0.e0 )
+               zcompapoc = MAX( ( trn(ji,jj,jk,jppoc) - 1.e-8 ), 0.e0 )
+
+!     Microzooplankton grazing
+!     ------------------------
+               zdenom = 1. / (  xkgraz2 + xprefc   * trn(ji,jj,jk,jpdia)   &
+                  &                     + xprefz   * trn(ji,jj,jk,jpzoo)   &
+                  &                     + xprefp   * trn(ji,jj,jk,jpphy)   &
+                  &                     + xprefpoc * trn(ji,jj,jk,jppoc)  )
+
+               zgraze2 = grazrat2 * zstep * Tgfunc2(ji,jj,jk) * zdenom    &
+# if defined key_off_degrad
+                  &     * facvol(ji,jj,jk)          &
+# endif
+                  &     * trn(ji,jj,jk,jpmes)
+
+               zgrazd(ji,jj,jk)   = zgraze2 * xprefc   * zcompadi
+               zgrazz(ji,jj,jk)   = zgraze2 * xprefz   * zcompaz
+               zgrazn(ji,jj,jk)   = zgraze2 * xprefp   * zcompaph
+               zgrazpoc(ji,jj,jk) = zgraze2 * xprefpoc * zcompapoc
+
+               zgraznf(ji,jj,jk)  = zgrazn(ji,jj,jk)   * trn(ji,jj,jk,jpnfe) &
+                  &                                     / (trn(ji,jj,jk,jpphy) + rtrn)
+               zgrazf(ji,jj,jk)   = zgrazd(ji,jj,jk)   * trn(ji,jj,jk,jpdfe) &
+                  &                                    / (trn(ji,jj,jk,jpdia) + rtrn)
+               zgrazpof(ji,jj,jk) = zgrazpoc(ji,jj,jk) * trn(ji,jj,jk,jpsfe) &
+                  &                                   / (trn(ji,jj,jk,jppoc) + rtrn)
+            END DO
+         END DO
+      END DO
+      
+      
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               
+!    Mesozooplankton flux feeding on GOC
+!    ----------------------------------
+# if ! defined key_kriest
+               zgrazffe(ji,jj,jk) = 5.e3 * zstep * wsbio4(ji,jj,jk)          &
+#  if defined key_off_degrad
+                  &     * facvol(ji,jj,jk)          &
+#  endif
+                  &     * tgfunc2(ji,jj,jk) * trn(ji,jj,jk,jpgoc) * trn(ji,jj,jk,jpmes)
+
+               zgrazfff(ji,jj,jk) = zgrazffe(ji,jj,jk)       &
+                  &     * trn(ji,jj,jk,jpbfe) / (trn(ji,jj,jk,jpgoc) + rtrn)
+# else
+! KRIEST3
+               zgrazffe(ji,jj,jk) = 0.5 * 1.3e-2 / 5.5e-7 * 0.3 * zstep * wsbio3(ji,jj,jk)     &
+                  &     * tgfunc(ji,jj,jk) * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpmes)    &
+#  if defined key_off_degrad
+                  &     * facvol(ji,jj,jk)          &
+#  endif
+                  &     /  (trn(ji,jj,jk,jppoc) * 1.e7 + 0.1)
+
+!!C        zgrazffe(ji,jj,jk) = 5.e3 * zstep * wsbio3(ji,jj,jk)
+!!C     &     * tgfunc2(ji,jj,jk) * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpmes)
+!!C#    if defined key_off_degrad
+!!C     &     * facvol(ji,jj,jk)
+!!C#    endif
+
+               zgrazfff(ji,jj,jk) = zgrazffe(ji,jj,jk)      &
+                  &     * trn(ji,jj,jk,jpsfe) / (trn(ji,jj,jk,jppoc) + rtrn)
+# endif
+            END DO
+         END DO
+      END DO
+      
+
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+
+!    Mesozooplankton efficiency
+!    --------------------------
+               zgrarem2 = ( zgrazd(ji,jj,jk) + zgrazz(ji,jj,jk) + zgrazn(ji,jj,jk) &
+                  &            + zgrazpoc(ji,jj,jk) + zgrazffe(ji,jj,jk) )   &
+                  &     * ( 1. - epsher2 - unass2 )
+#if ! defined key_kriest
+               zgrafer2 = (zgrazf(ji,jj,jk) + zgraznf(ji,jj,jk) + zgrazz(ji,jj,jk) &
+                  &     * ferat3 + zgrazpof(ji,jj,jk) + zgrazfff (ji,jj,jk))*(1.-epsher2-unass2) &
+                  &       + epsher2 * ( &
+                  &      zgrazd(ji,jj,jk)   * MAX((trn(ji,jj,jk,jpdfe) / (trn(ji,jj,jk,jpdia) + rtrn)-ferat3),0.) &
+                  &    + zgrazn(ji,jj,jk)   * MAX((trn(ji,jj,jk,jpnfe) / (trn(ji,jj,jk,jpphy) + rtrn)-ferat3),0.) &
+                  &    + zgrazpoc(ji,jj,jk) * MAX((trn(ji,jj,jk,jpsfe) / (trn(ji,jj,jk,jppoc) + rtrn)-ferat3),0.) &
+                  &    + zgrazffe(ji,jj,jk) * MAX((trn(ji,jj,jk,jpbfe) / (trn(ji,jj,jk,jpgoc) + rtrn)-ferat3),0.)  )
+#else
+               zgrafer2 = (zgrazf(ji,jj,jk) + zgraznf(ji,jj,jk) + zgrazz(ji,jj,jk) &
+                  &       * ferat3 + zgrazpof(ji,jj,jk) + zgrazfff(ji,jj,jk) )*(1.-epsher2-unass2) &
+                  &       + epsher2 * ( &
+                  &      zgrazd(ji,jj,jk)   * MAX((trn(ji,jj,jk,jpdfe) / (trn(ji,jj,jk,jpdia) + rtrn)-ferat3),0.) &
+                  &    + zgrazn(ji,jj,jk)   * MAX((trn(ji,jj,jk,jpnfe) / (trn(ji,jj,jk,jpphy) + rtrn)-ferat3),0.) &
+                  &    + zgrazpoc(ji,jj,jk) * MAX((trn(ji,jj,jk,jpsfe) / (trn(ji,jj,jk,jppoc) + rtrn)-ferat3),0.) &
+                  &    + zgrazffe(ji,jj,jk) * MAX((trn(ji,jj,jk,jpsfe) / (trn(ji,jj,jk,jppoc) + rtrn)-ferat3),0.)  )
+
+#endif
+               zgrapoc2 = (zgrazd(ji,jj,jk) + zgrazz(ji,jj,jk)  + zgrazn(ji,jj,jk) &
+                  &          + zgrazpoc(ji,jj,jk) + zgrazffe(ji,jj,jk)) * unass2
+
+               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarem2 * sigma2
+               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgrarem2 * sigma2
+               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgrarem2 * (1.-sigma2)
+               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarem2 * sigma2
+               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgrafer2
+               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarem2 * sigma2
+               
+#if defined key_kriest
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zgrapoc2
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + zgrapoc2 * xkr_nmeso
+#else
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zgrapoc2
+#endif
+            END DO
+         END DO
+      END DO
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !
+               !   Update the arrays TRA which contain the biological sources and sinks
+               !   --------------------------------------------------------------------
+               zmortz2 = ztortz2(ji,jj,jk) + zrespz2(ji,jj,jk)
+               tra(ji,jj,jk,jpmes) = tra(ji,jj,jk,jpmes) - zmortz2  &
+                  &    + epsher2 * ( zgrazd(ji,jj,jk) + zgrazz(ji,jj,jk) + zgrazn(ji,jj,jk) &
+                  &                 + zgrazpoc(ji,jj,jk) + zgrazffe(ji,jj,jk) )
+               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazd(ji,jj,jk)
+               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) - zgrazz(ji,jj,jk)
+               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgrazn(ji,jj,jk)
+               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgrazn(ji,jj,jk) * trn(ji,jj,jk,jpnch)  &
+                  &                 / ( trn(ji,jj,jk,jpphy) + rtrn )
+               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazd(ji,jj,jk) * trn(ji,jj,jk,jpdch) &
+                  &                / ( trn(ji,jj,jk,jpdia) + rtrn )
+               tra(ji,jj,jk,jpbsi) = tra(ji,jj,jk,jpbsi) - zgrazd(ji,jj,jk) * trn(ji,jj,jk,jpbsi) &
+                  &                / ( trn(ji,jj,jk,jpdia) + rtrn )
+               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) +  zgrazd(ji,jj,jk) * trn(ji,jj,jk,jpbsi) &
+                  &                / ( trn(ji,jj,jk,jpdia) + rtrn )
+               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) -  zgraznf(ji,jj,jk)
+               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) -  zgrazf(ji,jj,jk)
+
+               zprcaca = xfracal(ji,jj,jk) * part * unass2 * zgrazn(ji,jj,jk)
+
+               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
+               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca
+               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
+#if defined key_kriest
+               znumpoc = trn(ji,jj,jk,jpnum) / ( trn(ji,jj,jk,jppoc) + rtrn )
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortz2  &
+                  &                 - zgrazpoc(ji,jj,jk) - zgrazffe(ji,jj,jk)    
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) - zgrazpoc(ji,jj,jk) * znumpoc &
+                  &                  + zmortz2  * xkr_nmeso &
+                  &                  - zgrazffe(ji,jj,jk)   * znumpoc * wsbio4(ji,jj,jk) &
+                  &                  / ( wsbio3(ji,jj,jk) + rtrn )
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ferat3 * zmortz2 &
+               &                    + unass2 * ( ferat3 * zgrazz(ji,jj,jk) + zgraznf(ji,jj,jk) &
+               &                    + zgrazf(ji,jj,jk) + zgrazpof(ji,jj,jk) + zgrazfff(ji,jj,jk) ) &
+               &                    - zgrazfff(ji,jj,jk) - zgrazpof(ji,jj,jk)
+#else
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zgrazpoc(ji,jj,jk)
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zmortz2 - zgrazffe(ji,jj,jk)
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zgrazpof(ji,jj,jk)
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + ferat3 * zmortz2 &
+               &                     + unass2 * ( ferat3 * zgrazz(ji,jj,jk) + zgraznf(ji,jj,jk) &
+               &                     + zgrazf(ji,jj,jk) + zgrazpof(ji,jj,jk) + zgrazfff(ji,jj,jk) ) &
+               &                     - zgrazfff(ji,jj,jk)
+#endif
+
+            END DO
+         END DO
+      END DO
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('meso')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_meso
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_meso                    ! Empty routine
+   END SUBROUTINE p4z_meso
+#endif 
+
+   !!======================================================================
+END MODULE  p4zmeso
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmicro.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmicro.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zmicro.F90	(revision 4536)
@@ -0,0 +1,211 @@
+MODULE p4zmicro
+   !!======================================================================
+   !!                         ***  MODULE p4zmicro  ***
+   !! TOP :   PISCES Compute the sources/sinks for microzooplankton
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_micro       :   Compute the sources/sinks for microzooplankton
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_micro    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_micro
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_micro  ***
+      !!
+      !! ** Purpose :   Compute the sources/sinks for microzooplankton
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk
+      REAL(wp) :: zcompadi, zcompadi2, zcompaz , zcompaph, zcompapoc
+      REAL(wp) :: zgraze  , zdenom  , zdenom2
+      REAL(wp) :: zfact   , zstep   , zinano , zidiat, zipoc
+      REAL(wp) :: zgrarem, zgrafer, zgrapoc, zprcaca, zmortz
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zrespz,ztortz
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazp, zgrazm, zgrazsd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazmf, zgrazsf, zgrazpf
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+        zstep = rfact2 / rjjss      ! Time step duration for biology
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zcompaz = MAX( ( trn(ji,jj,jk,jpzoo) - 1.e-9 ), 0.e0 )
+# if defined key_off_degrad
+               zfact   = zstep * tgfunc(ji,jj,jk) * zcompaz *facvol(ji,jj,jk)
+# else
+               zfact   = zstep * tgfunc(ji,jj,jk) * zcompaz
+# endif
+
+!     Respiration rates of both zooplankton
+!     -------------------------------------
+
+               zrespz(ji,jj,jk) = resrat * zfact  * ( 1.+ 3.* nitrfac(ji,jj,jk) )     &
+                  &            * trn(ji,jj,jk,jpzoo) / ( xkmort + trn(ji,jj,jk,jpzoo) )
+
+!     Zooplankton mortality. A square function has been selected with
+!     no real reason except that it seems to be more stable and may
+!     mimic predation.
+!     ---------------------------------------------------------------
+               ztortz(ji,jj,jk) = mzrat * 1.e6 * zfact * trn(ji,jj,jk,jpzoo)
+
+            END DO
+         END DO
+      END DO
+
+
+ 
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               zcompadi  = MAX( ( trn(ji,jj,jk,jpdia) - 1.e-8 ), 0.e0 )
+               zcompadi2 = MIN( zcompadi, 5.e-7 )
+               zcompaph  = MAX( ( trn(ji,jj,jk,jpphy) - 2.e-7 ), 0.e0 )
+               zcompapoc = MAX( ( trn(ji,jj,jk,jppoc) - 1.e-8 ), 0.e0 )
+               
+               !     Microzooplankton grazing
+               !     ------------------------
+               zdenom2 = 1./ ( zprefp * zcompaph + zprefc * zcompapoc + zprefd * zcompadi2 + rtrn )
+
+               zgraze = grazrat * zstep * tgfunc(ji,jj,jk)     &
+# if defined key_off_degrad
+                  &      * facvol(ji,jj,jk)         &
+# endif
+                  &      * trn(ji,jj,jk,jpzoo)
+
+               zinano = zprefp * zcompaph  * zdenom2
+               zipoc  = zprefc * zcompapoc * zdenom2
+               zidiat = zprefd * zcompadi2 * zdenom2
+
+               zdenom = 1./ ( xkgraz + zinano * zcompaph + zipoc * zcompapoc + zidiat * zcompadi2 )
+
+               zgrazp(ji,jj,jk)  = zgraze * zinano * zcompaph * zdenom
+               zgrazm(ji,jj,jk)  = zgraze * zipoc  * zcompapoc * zdenom
+               zgrazsd(ji,jj,jk) = zgraze * zidiat * zcompadi2 * zdenom
+
+               zgrazpf (ji,jj,jk) = zgrazp(ji,jj,jk)  * trn(ji,jj,jk,jpnfe) / (trn(ji,jj,jk,jpphy) + rtrn)
+               zgrazmf(ji,jj,jk)  = zgrazm(ji,jj,jk)  * trn(ji,jj,jk,jpsfe) / (trn(ji,jj,jk,jppoc) + rtrn)
+               zgrazsf(ji,jj,jk)  = zgrazsd(ji,jj,jk) * trn(ji,jj,jk,jpdfe) / (trn(ji,jj,jk,jpdia) + rtrn)
+
+            END DO
+         END DO
+      END DO
+      
+
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+!    Various remineralization and excretion terms
+!    --------------------------------------------
+
+               zgrarem = (  zgrazp(ji,jj,jk) + zgrazm(ji,jj,jk)  + zgrazsd(ji,jj,jk)  ) &
+                  &          * ( 1.- epsher - unass )
+               zgrafer = (  zgrazpf(ji,jj,jk) + zgrazsf(ji,jj,jk)  + zgrazmf(ji,jj,jk)  ) &
+                  &        * ( 1.- epsher - unass ) + epsher *  &
+                  &  ( zgrazm(ji,jj,jk)  * MAX((trn(ji,jj,jk,jpsfe) /(trn(ji,jj,jk,jppoc)+ rtrn)-ferat3),0.e0) &
+                  &   + zgrazp(ji,jj,jk)  * MAX((trn(ji,jj,jk,jpnfe)/(trn(ji,jj,jk,jpphy)+ rtrn)-ferat3),0.e0) &
+                  &   + zgrazsd(ji,jj,jk) * MAX((trn(ji,jj,jk,jpdfe)/(trn(ji,jj,jk,jpdia)+ rtrn)-ferat3),0.e0 )  )
+               zgrapoc = (  zgrazp(ji,jj,jk) + zgrazm(ji,jj,jk) + zgrazsd(ji,jj,jk)  ) * unass
+
+               !  Update of the TRA arrays
+               !  ------------------------
+
+               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarem * sigma1
+               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgrarem * sigma1
+               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgrarem * (1.-sigma1)
+               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarem * sigma1
+               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgrafer
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zgrapoc
+               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarem * sigma1
+#if defined key_kriest
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + zgrapoc * xkr_ndiat
+#endif
+            END DO
+         END DO
+      END DO
+
+!
+!   Update the arrays TRA which contain the biological sources and sinks
+!   --------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zmortz = ztortz(ji,jj,jk) + zrespz(ji,jj,jk)
+               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) - zmortz  &
+               &     + epsher * ( zgrazp(ji,jj,jk) + zgrazm(ji,jj,jk) + zgrazsd(ji,jj,jk))
+               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgrazp(ji,jj,jk)
+               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazsd(ji,jj,jk)
+               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgrazp(ji,jj,jk)  &
+               &                   * trn(ji,jj,jk,jpnch)/(trn(ji,jj,jk,jpphy)+rtrn)
+               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazsd(ji,jj,jk) &
+               &                   * trn(ji,jj,jk,jpdch)/(trn(ji,jj,jk,jpdia)+rtrn)
+               tra(ji,jj,jk,jpbsi) = tra(ji,jj,jk,jpbsi) - zgrazsd(ji,jj,jk) &
+               &                   * trn(ji,jj,jk,jpbsi)/(trn(ji,jj,jk,jpdia)+rtrn)
+               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) + zgrazsd(ji,jj,jk) &
+               &                   * trn(ji,jj,jk,jpbsi)/(trn(ji,jj,jk,jpdia)+rtrn)
+               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zgrazpf(ji,jj,jk)
+               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zgrazsf(ji,jj,jk)
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortz - zgrazm(ji,jj,jk)
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ferat3 * zmortz   &
+               &                    + unass * ( zgrazpf(ji,jj,jk) + zgrazsf (ji,jj,jk)) &
+               &                   - (1.-unass) * zgrazmf(ji,jj,jk)
+               zprcaca = xfracal(ji,jj,jk) * part * unass * zgrazp(ji,jj,jk)
+               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
+               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal)- 2. * zprcaca
+               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
+#if defined key_kriest
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + ( zmortz - zgrazm(ji,jj,jk) ) * xkr_ndiat
+#endif
+            END DO
+         END DO
+      END DO
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('micro')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_micro
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_micro                    ! Empty routine
+   END SUBROUTINE p4z_micro
+#endif 
+
+   !!======================================================================
+END MODULE  p4zmicro
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4znano.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4znano.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4znano.F90	(revision 4536)
@@ -0,0 +1,127 @@
+MODULE p4znano
+   !!======================================================================
+   !!                         ***  MODULE p4znano  ***
+   !! TOP :   PISCES Compute the mortality terms for nanophytoplankton
+   !!======================================================================
+   !! History :   1.0  !  2002     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_nano       :   Compute the mortality terms for nanophytoplankton
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_nano    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_nano
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_nano  ***
+      !!
+      !! ** Purpose :   Compute the mortality terms for nanophytoplankton
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk
+      REAL(wp) :: zstep, zcompaph
+      REAL(wp) :: zfactfe,zfactch,zprcaca,zfracal
+      REAL(wp) :: ztortp,zrespp,zmortp
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+
+      zstep = rfact2 / rjjss      ! Time step duration for biology
+
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zcompaph = MAX( ( trn(ji,jj,jk,jpphy) - 1e-8 ), 0.e0 )
+
+!     Squared mortality of Phyto similar to a sedimentation term during
+!     blooms (Doney et al. 1996)
+!     -----------------------------------------------------------------
+               zrespp = wchl * 1.e6 * zstep * xdiss(ji,jj,jk)   &
+# if defined key_off_degrad
+                  &        * facvol(ji,jj,jk)     &
+# endif
+                  &        * zcompaph * trn(ji,jj,jk,jpphy)
+
+!     Phytoplankton mortality. This mortality loss is slightly
+!     increased when nutrients are limiting phytoplankton growth
+!     as observed for instance in case of iron limitation.
+!     ----------------------------------------------------------
+               ztortp = mprat * zstep * trn(ji,jj,jk,jpphy)          &
+# if defined key_off_degrad
+                  &          * facvol(ji,jj,jk)     &
+# endif
+                  &   / ( xkmort + trn(ji,jj,jk,jpphy) ) * zcompaph
+
+                                                                               
+               zmortp = zrespp + ztortp
+
+               !   Update the arrays TRA which contains the biological sources and sinks
+               
+               zfactfe = trn(ji,jj,jk,jpnfe)/(trn(ji,jj,jk,jpphy)+rtrn)
+               zfactch = trn(ji,jj,jk,jpnch)/(trn(ji,jj,jk,jpphy)+rtrn)
+               
+               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zmortp
+               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zmortp * zfactch
+               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zmortp * zfactfe
+               zprcaca = xfracal(ji,jj,jk) * zmortp
+               zfracal = 0.5 * xfracal(ji,jj,jk)
+               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
+               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca
+               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
+#if defined key_kriest
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortp
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + ztortp * xkr_nnano + zrespp * xkr_ndiat
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zmortp * zfactfe
+#else
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zfracal * zmortp
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + ( 1. - zfracal ) * zmortp
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ( 1. - zfracal ) * zmortp * zfactfe
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zfracal * zmortp * zfactfe
+#endif
+            END DO
+         END DO
+      END DO
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('nano')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_nano
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_nano                    ! Empty routine
+   END SUBROUTINE p4z_nano
+#endif 
+
+   !!======================================================================
+END MODULE  p4znano
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zopt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zopt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zopt.F90	(revision 4536)
@@ -0,0 +1,256 @@
+MODULE p4zopt
+   !!======================================================================
+   !!                         ***  MODULE p4zopt  ***
+   !! TOP :   PISCES Compute the light availability in the water column
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_opt        :   Compute the light availability in the water column
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_opt   ! called in p4zprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_opt
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_opt  ***
+      !!
+      !! ** Purpose :   Compute the light availability in the water column
+      !!              depending on the depth and the chlorophyll concentration
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      INTEGER  ::   irgb
+      REAL(wp) ::   zchl, zparlux
+      REAL(wp) ::   zrlight , zblight , zglight
+      REAL(wp) ::   zrlight1, zblight1, zglight1
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdepmoy, zetmp
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zekg, zekr, zekb
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze1 , ze2 , ze3
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3lum, ze4lum
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze5lum, ze6lum
+      !!---------------------------------------------------------------------
+
+!     Initialisation of variables used to compute PAR
+!     -----------------------------------------------
+      ze1 (:,:,:) = 0.e0
+      ze2 (:,:,:) = 0.e0
+      ze3 (:,:,:) = 0.e0
+      etot(:,:,:) = 0.e0
+        
+      zparlux = 0.43 / 3.
+
+!    IF activated, computation of the qsr for the dynamics
+!    -----------------------------------------------------
+      IF( ln_qsr_sms ) THEN
+         ze3lum(:,:,:) = 0.e0
+         ze4lum(:,:,:) = 0.e0
+         ze5lum(:,:,:) = 0.e0
+         ze6lum(:,:,:) = 0.e0
+      ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!     Separation in three light bands: red, green, blue
+!     -------------------------------------------------
+               zchl = ( trn(ji,jj,jk,jpnch) + trn(ji,jj,jk,jpdch) + rtrn ) * 1.e6
+               zchl = MAX( 0.03, zchl )
+               zchl = MIN( 10. , zchl )
+                                                                                
+               irgb = INT( 41 + 20.* LOG10( zchl ) + rtrn )
+                                                                                
+               zekb(ji,jj,jk) = xkrgb(1,irgb)
+               zekg(ji,jj,jk) = xkrgb(2,irgb)
+               zekr(ji,jj,jk) = xkrgb(3,irgb)
+
+            END DO
+         END DO
+      END DO
+
+!CDIR NOVERRCHK
+      DO jj = 1,jpj
+!CDIR NOVERRCHK
+         DO ji = 1,jpi
+
+!     Separation in three light bands: red, green, blue
+!     -------------------------------------------------
+
+            zblight = 0.5 * zekb(ji,jj,1) * fse3t(ji,jj,1)
+            zglight = 0.5 * zekg(ji,jj,1) * fse3t(ji,jj,1)
+            zrlight = 0.5 * zekr(ji,jj,1) * fse3t(ji,jj,1)
+
+            ze1(ji,jj,1) = zparlux * qsr(ji,jj) * EXP(-zblight)
+            ze2(ji,jj,1) = zparlux * qsr(ji,jj) * EXP(-zglight)
+            ze3(ji,jj,1) = zparlux * qsr(ji,jj) * EXP(-zrlight)
+
+         END DO
+      END DO
+
+!CDIR NOVERRCHK
+      DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+          DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+!     Separation in three light bands: red, green, blue
+!     -------------------------------------------------
+
+               zblight = 0.5 * ( zekb(ji,jj,jk-1) * fse3t(ji,jj,jk-1)   &
+                  &            + zekb(ji,jj,jk  ) * fse3t(ji,jj,jk  ) )
+               zglight = 0.5 * ( zekg(ji,jj,jk-1) * fse3t(ji,jj,jk-1)   &
+                  &            + zekg(ji,jj,jk  ) * fse3t(ji,jj,jk  ) )
+               zrlight = 0.5 * ( zekr(ji,jj,jk-1) * fse3t(ji,jj,jk-1)   &
+                  &            + zekr(ji,jj,jk  ) * fse3t(ji,jj,jk  ) )
+
+               ze1(ji,jj,jk) = ze1(ji,jj,jk-1) * EXP(-zblight)
+               ze2(ji,jj,jk) = ze2(ji,jj,jk-1) * EXP(-zglight)
+               ze3(ji,jj,jk) = ze3(ji,jj,jk-1) * EXP(-zrlight)
+
+            END DO
+         END DO
+      END DO
+
+      etot(:,:,:) = ze1(:,:,:) + ze2(:,:,:) + ze3(:,:,:)
+      enano(:,:,:) = 2.1 * ze1(:,:,:) + 0.42 * ze2(:,:,:) + 0.4 * ze3(:,:,:)
+      ediat(:,:,:) = 1.6 * ze1(:,:,:) + 0.69 * ze2(:,:,:) + 0.7 * ze3(:,:,:)
+
+
+      IF( ln_qsr_sms ) THEN
+
+!   In the following, the vertical attenuation of qsr for the dynamics is computed
+!   ------------------------------------------------------------------------------
+
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+!     Separation in three light bands: red, green, blue
+!     -------------------------------------------------
+
+               zblight = 0.5 * zekb(ji,jj,1) * fse3t(ji,jj,1)
+               zglight = 0.5 * zekg(ji,jj,1) * fse3t(ji,jj,1)
+               zrlight = 0.5 * zekr(ji,jj,1) * fse3t(ji,jj,1)
+
+               ze3lum(ji,jj,1) = zparlux * qsr(ji,jj)
+               ze4lum(ji,jj,1) = zparlux * qsr(ji,jj)
+               ze5lum(ji,jj,1) = zparlux * qsr(ji,jj)
+               ze6lum(ji,jj,1) = (1.-3. * zparlux) * qsr(ji,jj)
+
+            END DO
+         END DO
+
+!CDIR NOVERRCHK
+         DO jk = 2, jpkm1
+!CDIR NOVERRCHK
+            DO jj = 1, jpj
+!CDIR NOVERRCHK
+               DO ji = 1, jpi
+
+!     Separation in three light bands: red, green, blue
+!     -------------------------------------------------
+
+                  zblight = zekb(ji,jj,jk-1) * fse3t(ji,jj,jk-1)
+                  zglight = zekg(ji,jj,jk-1) * fse3t(ji,jj,jk-1)
+                  zrlight = zekr(ji,jj,jk-1) * fse3t(ji,jj,jk-1)
+
+                  ze3lum(ji,jj,jk) = ze3lum(ji,jj,jk-1) * EXP( -zblight )
+                  ze4lum(ji,jj,jk) = ze4lum(ji,jj,jk-1) * EXP( -zglight )
+                  ze5lum(ji,jj,jk) = ze5lum(ji,jj,jk-1) * EXP( -zrlight )
+                  ze6lum(ji,jj,jk) = ze6lum(ji,jj,jk-1) * EXP( -fse3t(ji,jj,jk-1) / xsi1 )
+
+               END DO
+            END DO
+         END DO
+
+         etot3(:,:,:) = ze3lum(:,:,:) + ze4lum(:,:,:) + ze5lum(:,:,:) + ze6lum(:,:,:)
+
+      ENDIF
+
+!     Computation of the euphotic depth
+!     ---------------------------------
+    
+      heup(:,:) = 300.e0
+
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( etot(ji,jj,jk) >= 0.0043 * qsr(ji,jj) )   heup(ji,jj) = fsdepw(ji,jj,jk+1)
+            END DO
+         END DO
+      END DO
+
+      heup(:,:) = MIN( 300., heup(:,:) )
+
+!    Computation of the mean light over the mixed layer depth
+!    --------------------------------------------------------
+
+      zdepmoy(:,:)   = 0.e0
+      zetmp  (:,:)   = 0.e0
+      emoy   (:,:,:) = 0.e0
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+                  zetmp  (ji,jj) = zetmp  (ji,jj) + etot(ji,jj,jk) * fse3t(ji,jj,jk)
+                  zdepmoy(ji,jj) = zdepmoy(ji,jj) +                  fse3t(ji,jj,jk)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      emoy(:,:,:) = etot(:,:,:)
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+                  emoy(ji,jj,jk) = zetmp(ji,jj) / ( zdepmoy(ji,jj) + rtrn )
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+
+# if defined key_trc_diaadd
+      trc2d(:,:,11) = heup(:,:)
+# endif
+      !
+   END SUBROUTINE p4z_opt
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_opt                   ! Empty routine
+   END SUBROUTINE p4z_opt
+#endif 
+
+   !!======================================================================
+END MODULE  p4zopt
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprg.F90	(revision 4536)
@@ -0,0 +1,113 @@
+MODULE p4zprg
+   !!======================================================================
+   !!                         ***  MODULE p4zprg  ***
+   !! 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
+   !!----------------------------------------------------------------------
+   !!   p4z_prg        :  Time loop of passive tracers sms
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE lbclnk
+   USE lib_mpp
+   
+   USE p4zint          ! 
+   USE p4zche          ! 
+   USE p4zbio          ! 
+   USE p4zsed          ! 
+   USE p4zlys          ! 
+   USE p4zflx          ! 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_prg    ! called in trcsms.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_prg( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_prg  ***
+      !!
+      !! ** 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 ::   jnt, jn
+      INTEGER ::   iyy, imm, idd
+
+
+      !!---------------------------------------------------------------------
+
+
+      iyy = ndastp/10000
+      imm = (ndastp - iyy*10000)/100
+      idd = (ndastp - iyy*10000 - imm*100)
+
+      IF( ndayflxtr /= idd) THEN      ! New days
+         !
+         ndayflxtr = idd
+
+         CALL p4z_che          ! computation of chemical constants
+
+         CALL p4z_int( kt )    ! computation of various rates for biogeochemistry
+         !
+      ENDIF
+
+
+      DO jnt = 1, nrdttrc             ! ???
+         !
+         CALL p4z_bio ( kt )         ! Compute soft tissue production (POC)
+
+
+         CALL p4z_sed          ! compute soft tissue remineralisation
+
+         !
+         trb(:,:,:,:) = trn(:,:,:,:)
+         !
+      END DO
+
+      CALL p4z_lys             ! Compute CaCO3 saturation
+
+      CALL p4z_flx( kt )             ! Compute surface fluxes
+
+
+      DO jn = jp_pcs0, jp_pcs1
+        CALL lbc_lnk( trn(:,:,:,jn), 'T', 1. )
+        CALL lbc_lnk( trb(:,:,:,jn), 'T', 1. )
+        CALL lbc_lnk( tra(:,:,:,jn), 'T', 1. )
+      END DO
+      !
+   END SUBROUTINE p4z_prg
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_prg( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_prg: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_prg
+#endif 
+
+   !!======================================================================
+END MODULE  p4zprg
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprod.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprod.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zprod.F90	(revision 4536)
@@ -0,0 +1,351 @@
+MODULE p4zprod
+   !!======================================================================
+   !!                         ***  MODULE p4zprod  ***
+   !! TOP :   PISCES 
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_prod       :  
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE p4zday          !
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_prod    ! called in p4zbio.F90
+
+   
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_prod( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_prod  ***
+      !!
+      !! ** Purpose :   Compute the phytoplankton production depending on
+      !!              light, temperature and nutrient availability
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      INTEGER  ::   ji, jj, jk, nspyr
+      REAL(wp) ::   zsilfac, zfact, zrfact2
+      REAL(wp) ::   zprdiachl, zprbiochl, zsilim, ztn, zadap, zadap2
+      REAL(wp) ::   zlim, zsilfac2, zsiborn, zprod, zetot2, zmax, zproreg, zproreg2
+      REAL(wp) ::   zmxltst, zmxlday, zlim1, zexcret, zexcret2
+      REAL(wp) ::   zpislopen  , zpislope2n
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zmixnano   , zmixdiat
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zpislopead , zpislopead2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zprdia     , zprbio, zysopt
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zprorca    , zprorca2, zprorca4
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zprorca5   , zprorca6, zprorca7
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zpronew    , zpronew2
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      zprorca (:,:,:) = 0.0
+      zprorca2(:,:,:) = 0.0
+      zprorca4(:,:,:) = 0.0
+      zprorca5(:,:,:) = 0.0
+      zprorca6(:,:,:) = 0.0
+      zprorca7(:,:,:) = 0.0
+      zpronew (:,:,:) = 0.0
+      zpronew2(:,:,:) = 0.0
+      zprdia  (:,:,:) = 0.0
+      zprbio  (:,:,:) = 0.0
+      zysopt  (:,:,:) = 0.0
+
+      nspyr  = INT( raass / rdt )
+
+      zexcret  = 1. - excret
+      zexcret2 = 1. - excret2
+
+!     Computation of the optimal production
+!     -------------------------------------
+
+# if defined key_off_degrad
+      prmax(:,:,:) = 0.6 / rjjss * tgfunc(:,:,:) * facvol(:,:,:)
+# else
+      prmax(:,:,:) = 0.6 / rjjss * tgfunc(:,:,:)
+# endif
+
+      CALL p4z_day       ! Computation of the day length
+
+!CDIR NOVERRCHK
+      DO jk = 1, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+!      Computation of the P-I slope for nanos and diatoms
+!      --------------------------------------------------
+                IF( etot(ji,jj,jk) > 1.E-3 ) THEN
+                   ztn    = MAX( 0., tn(ji,jj,jk) - 15. )
+                   zadap  = 0.+ 1.* ztn / ( 2.+ ztn )
+                   zadap2 = 0.e0
+
+                   zfact  = EXP( -0.21 * emoy(ji,jj,jk) )
+
+                   zpislopead (ji,jj,jk) = pislope  * ( 1.+ zadap  * zfact )
+                   zpislopead2(ji,jj,jk) = pislope2 * ( 1.+ zadap2 * zfact )
+
+                   zpislopen = zpislopead(ji,jj,jk) * trn(ji,jj,jk,jpnch)               &
+                     &         / ( trn(ji,jj,jk,jpphy) * 12.                   + rtrn )   &
+                     &         / ( prmax(ji,jj,jk) * rjjss * xlimphy(ji,jj,jk) + rtrn )
+
+                   zpislope2n = zpislopead2(ji,jj,jk) * trn(ji,jj,jk,jpdch)              &
+                     &          / ( trn(ji,jj,jk,jpdia) * 12.                   + rtrn )   &
+                     &          / ( prmax(ji,jj,jk) * rjjss * xlimdia(ji,jj,jk) + rtrn )
+
+!     Computation of production function
+!     ----------------------------------
+
+                   zprbio(ji,jj,jk) = prmax(ji,jj,jk) * &
+                     &                (  1.- EXP( -zpislopen * enano(ji,jj,jk) )  )
+                   zprdia(ji,jj,jk) = prmax(ji,jj,jk) * &
+                     &                (  1.- EXP( -zpislope2n * ediat(ji,jj,jk) )  )
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+                IF( etot(ji,jj,jk) > 1.E-3 ) THEN
+!    Si/C of diatoms
+!    ------------------------
+!    Si/C increases with iron stress and silicate availability
+!    Si/C is arbitrariliy increased for very high Si concentrations
+!    to mimic the very high ratios observed in the Southern Ocean (silpot2)
+
+                  zlim1  = trn(ji,jj,jk,jpsil) / ( trn(ji,jj,jk,jpsil) + xksi1 )
+                  zlim   = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
+
+                  zsilim = MIN( zprdia(ji,jj,jk)    / ( rtrn + prmax(ji,jj,jk) ),                    &
+                  &          trn(ji,jj,jk,jpfer) / ( concdfe(ji,jj,jk) + trn(ji,jj,jk,jpfer) ),   &
+                  &          trn(ji,jj,jk,jppo4) / ( concdnh4 + trn(ji,jj,jk,jppo4) ),            &
+                  &          zlim )
+                  zsilfac = 5.4 * EXP( -4.23 * zsilim ) * MAX( 0.e0, MIN( 1., 2.2 * ( zlim1 - 0.5 ) )  ) + 1.e0
+                  zsiborn = MAX( 0.e0, ( trn(ji,jj,jk,jpsil) - 15.e-6 ) )
+                  zsilfac2 = 1.+ 3.* zsiborn / ( zsiborn + xksi2 )
+                  zsilfac = MIN( 6.4,zsilfac * zsilfac2)
+                  zysopt(ji,jj,jk) = grosip * zlim1 * zsilfac
+
+              ENDIF
+            END DO
+         END DO
+      END DO
+
+!    Computation of the limitation term due to
+!    A mixed layer deeper than the euphotic depth
+!    --------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zmxltst = MAX( 0.e0, hmld(ji,jj) - heup(ji,jj) )
+            zmxlday = zmxltst**2 / rjjss
+            zmixnano(ji,jj) = 1.- zmxlday / ( 1.+ zmxlday )
+            zmixdiat(ji,jj) = 1.- zmxlday / ( 3.+ zmxlday )
+         END DO
+      END DO
+                                                                                
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fsdepw(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
+
+!     Mixed-layer effect on production
+!     --------------------------------
+                  zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * zmixnano(ji,jj)
+                  zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * zmixdiat(ji,jj)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+!      Computation of the maximum light intensity
+!      ------------------------------------------
+            IF( strn(ji,jj) < 1.e0 )   strn(ji,jj) = 24.
+         END DO
+      END DO
+
+!CDIR NOVERRCHK
+      DO jk = 1, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+
+               IF( etot(ji,jj,jk) > 1.E-3 ) THEN
+!     Computation of the various production terms for nanophyto.
+!     ----------------------------------------------------------
+                  zetot2 = enano(ji,jj,jk) * 24. / ( strn(ji,jj) + rtrn )
+                  zmax = MAX( 0.1, xlimphy(ji,jj,jk) )
+                  zpislopen = zpislopead(ji,jj,jk)          &
+                  &         * trn(ji,jj,jk,jpnch) / ( rtrn + trn(ji,jj,jk,jpphy) * 12.)         &
+                  &         / ( prmax(ji,jj,jk) * rjjss * zmax + rtrn )
+
+                  zprbiochl = prmax(ji,jj,jk) * (  1.- EXP( -zpislopen * zetot2 )  )
+
+                  zprorca(ji,jj,jk) = zprbio(ji,jj,jk)  * xlimphy(ji,jj,jk) * trn(ji,jj,jk,jpphy) * rfact2
+
+                  zpronew(ji,jj,jk) = zprorca(ji,jj,jk) * xnanono3(ji,jj,jk)    &
+                  &             / ( xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk) + rtrn )
+                  zprod = rjjss * zprorca(ji,jj,jk) * zprbiochl * trn(ji,jj,jk,jpphy) *zmax
+
+                  zprorca5(ji,jj,jk) = (fecnm)**2 * zprod / chlcnm            &
+                  &              / (  zpislopead(ji,jj,jk) * zetot2 * trn(ji,jj,jk,jpnfe) + rtrn  )
+
+                  zprorca6(ji,jj,jk) = chlcnm * 144. * zprod                  &
+                  &              / (  zpislopead(ji,jj,jk) * zetot2 * trn(ji,jj,jk,jpnch) + rtrn  )
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+!CDIR NOVERRCHK
+      DO jk = 1, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               IF( etot(ji,jj,jk) > 1.E-3 ) THEN
+!       Computation of the various production terms for diatoms
+!       -------------------------------------------------------
+                  zetot2 = ediat(ji,jj,jk) * 24. / ( strn(ji,jj) + rtrn )
+                  zmax = MAX( 0.1, xlimdia(ji,jj,jk) )
+                  zpislope2n = zpislopead2(ji,jj,jk) * trn(ji,jj,jk,jpdch)        &
+                  &           / ( rtrn + trn(ji,jj,jk,jpdia) * 12.)        &
+                  &           / ( prmax(ji,jj,jk) * rjjss * zmax + rtrn )
+
+                  zprdiachl = prmax(ji,jj,jk) * (  1.- EXP( -zetot2 * zpislope2n )  )
+
+                  zprorca2(ji,jj,jk) = zprdia(ji,jj,jk) * xlimdia(ji,jj,jk) * trn(ji,jj,jk,jpdia) * rfact2
+
+                  zpronew2(ji,jj,jk) = zprorca2(ji,jj,jk) * xdiatno3(ji,jj,jk)     &
+                  &              / ( xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk) + rtrn )
+
+                  zprod = rjjss * zprorca2(ji,jj,jk) * zprdiachl * trn(ji,jj,jk,jpdia) * zmax
+
+                  zprorca4(ji,jj,jk) = (fecdm)**2 * zprod / chlcdm                   &
+                  &              / ( zpislopead2(ji,jj,jk) * zetot2 * trn(ji,jj,jk,jpdfe) + rtrn )
+
+                  zprorca7(ji,jj,jk) = chlcdm * 144. * zprod       &
+                  &              / ( zpislopead2(ji,jj,jk) * zetot2 * trn(ji,jj,jk,jpdch) + rtrn )
+
+               ENDIF
+            END DO
+         END DO
+      END DO
+      !
+
+!
+!   Update the arrays TRA which contain the biological sources and sinks
+!   --------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+           DO ji =1 ,jpi
+              zproreg  = zprorca(ji,jj,jk) - zpronew(ji,jj,jk)
+              zproreg2 = zprorca2(ji,jj,jk) - zpronew2(ji,jj,jk)
+              tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) - zprorca(ji,jj,jk) - zprorca2(ji,jj,jk)
+              tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - zpronew(ji,jj,jk) - zpronew2(ji,jj,jk)
+              tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) - zproreg - zproreg2
+              tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zprorca(ji,jj,jk) * zexcret
+              tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) + zprorca6(ji,jj,jk) * zexcret
+              tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) + zprorca5(ji,jj,jk) * zexcret
+              tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) + zprorca2(ji,jj,jk) * zexcret2
+              tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) + zprorca7(ji,jj,jk) * zexcret2
+              tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) + zprorca4(ji,jj,jk) * zexcret2
+              tra(ji,jj,jk,jpbsi) = tra(ji,jj,jk,jpbsi) + zprorca2(ji,jj,jk) * zysopt(ji,jj,jk) * zexcret2
+              tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + &
+              &                     excret2 * zprorca2(ji,jj,jk) + excret * zprorca(ji,jj,jk)
+              tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + o2ut * ( zproreg + zproreg2) &
+              &                    + ( o2ut + o2nit ) * ( zpronew(ji,jj,jk) + zpronew2(ji,jj,jk) )
+              tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) &
+              &                     - zexcret * zprorca5(ji,jj,jk) - zexcret2 * zprorca4(ji,jj,jk)
+              tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) &
+              &                     - zexcret2 * zprorca2(ji,jj,jk) * zysopt(ji,jj,jk)
+              tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprorca(ji,jj,jk) - zprorca2(ji,jj,jk)
+              tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) &
+              &                    + rno3 * ( zpronew(ji,jj,jk) + zpronew2(ji,jj,jk) )
+          END DO
+        END DO
+     END DO
+
+
+     DO jk = 1, jpkm1
+        DO jj = 1, jpj
+          DO ji = 1, jpi
+             qcumul(2) = qcumul(2) + ( zprorca(ji,jj,jk) + zprorca2(ji,jj,jk) )  &
+             &                       * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) * tmask_i(ji,jj)
+          END DO
+        END DO
+      END DO
+
+      IF( MOD( kt, nspyr ) == 0 ) THEN
+        WRITE(numout,*) 'Total PP :'
+        WRITE(numout,*) '-------------------- : ',qcumul(2)*12./1E12
+        WRITE(numout,*) '(GtC/an)'
+        qcumul(2) = 0.
+      ENDIF
+
+#if defined key_trc_dia3d
+      zrfact2 = 1.e3 * rfact2r
+!   Supplementary diagnostics
+!   -------------------------
+      trc3d(:,:,:,4)  = etot(:,:,:)
+      trc3d(:,:,:,5)  = zprorca(:,:,:)  * zrfact2
+      trc3d(:,:,:,6)  = zprorca2(:,:,:) * zrfact2
+      trc3d(:,:,:,7)  = zpronew(:,:,:)  * zrfact2
+      trc3d(:,:,:,8)  = zpronew2(:,:,:) * zrfact2
+      trc3d(:,:,:,9)  = zprorca2(:,:,:) * zysopt(:,:,:) * zrfact2
+      trc3d(:,:,:,10) = zprorca4(:,:,:) * zrfact2
+#if ! defined key_kriest
+      trc3d(:,:,:,11) = zprorca5(:,:,:) * zrfact2
+#endif
+#endif
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('prod')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_prod
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_prod                    ! Empty routine
+   END SUBROUTINE p4z_prod
+#endif 
+
+   !!======================================================================
+END MODULE  p4zprod
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zrem.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zrem.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zrem.F90	(revision 4536)
@@ -0,0 +1,389 @@
+MODULE p4zrem
+   !!======================================================================
+   !!                         ***  MODULE p4zrem  ***
+   !! TOP :   PISCES Compute remineralization/scavenging of organic compounds
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_top'       and                                      TOP models
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_rem       :   Compute remineralization/scavenging of organic compounds
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc         ! 
+   USE sms             ! 
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_rem    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_rem
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_rem  ***
+      !!
+      !! ** Purpose :   Compute remineralization/scavenging of organic compounds
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zremip, zremik , zlam1b
+      REAL(wp) ::   zkeq  , zfeequi, zsiremin
+      REAL(wp) ::   zsatur, zsatur2, znusil
+      REAL(wp) ::   zbactfer, zorem, zorem2, zofer, zofer2
+      REAL(wp) ::   zosil, zdenom, zdenom1, zdenom2, zscave, zaggdfe
+      REAL(wp) ::   zlamfac, zstep, zonitr
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztempbac
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdepbac, zfesatur, zolimi
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+       zstep = rfact2 / rjjss      ! Time step duration for the biology
+
+
+!      Computation of the mean phytoplankton concentration as
+!      a crude estimate of the bacterial biomass
+!      --------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( fsdept(ji,jj,jk) < 120. ) THEN
+                  zdepbac(ji,jj,jk) = MIN( 0.7 * ( trn(ji,jj,jk,jpzoo) + 2.* trn(ji,jj,jk,jpmes) ), 4.e-6 )
+                  ztempbac(ji,jj)   = zdepbac(ji,jj,jk)
+               ELSE
+                  zdepbac(ji,jj,jk) = MIN( 1., 120./ fsdept(ji,jj,jk) ) * ztempbac(ji,jj)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!    DENITRIFICATION FACTOR COMPUTED FROM O2 LEVELS
+!    ----------------------------------------------
+
+               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trn(ji,jj,jk,jpoxy) )    &
+                  &                                / ( oxymin + trn(ji,jj,jk,jpoxy) )  )
+            END DO
+         END DO
+      END DO
+
+      nitrfac(:,:,:) = MIN( 1., nitrfac(:,:,:) )
+
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!     DOC ammonification. Depends on depth, phytoplankton biomass
+!     and a limitation term which is supposed to be a parameterization
+!     of the bacterial activity. 
+!     ----------------------------------------------------------------
+               zremik = xremik * zstep / 1.e-6 * xlimbac(ji,jj,jk)         &
+# if defined key_off_degrad
+                  &            * facvol(ji,jj,jk)              &
+# endif
+                  &            * zdepbac(ji,jj,jk)
+               zremik = MAX( zremik, 5.5e-4 * zstep )
+
+!     Ammonification in oxic waters with oxygen consumption
+!     -----------------------------------------------------
+               zolimi(ji,jj,jk) = MIN(  ( trn(ji,jj,jk,jpoxy) - rtrn ) / o2ut,  &
+                  &                    zremik * ( 1.- nitrfac(ji,jj,jk) ) * trn(ji,jj,jk,jpdoc)  ) 
+
+!     Ammonification in suboxic waters with denitrification
+!     -------------------------------------------------------
+               denitr(ji,jj,jk) = MIN(  ( trn(ji,jj,jk,jpno3) - rtrn ) / rdenit,   &
+                  &                     zremik * nitrfac(ji,jj,jk) * trn(ji,jj,jk,jpdoc)  )
+            END DO
+         END DO
+      END DO
+
+      zolimi (:,:,:) = MAX( 0.e0, zolimi (:,:,:) )
+      denitr (:,:,:) = MAX( 0.e0, denitr (:,:,:) )
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!    NH4 nitrification to NO3. Ceased for oxygen concentrations
+!    below 2 umol/L. Inhibited at strong light 
+!    ----------------------------------------------------------
+               zonitr  = nitrif * zstep * trn(ji,jj,jk,jpnh4) / ( 1.+ emoy(ji,jj,jk) )     &
+# if defined key_off_degrad
+                  &      * facvol(ji,jj,jk)              &
+# endif
+                  &      * ( 1.- nitrfac(ji,jj,jk) )
+
+!
+!   Update of the tracers trends
+!   ----------------------------
+
+              tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) - zonitr
+              tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zonitr
+              tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2nit * zonitr
+              tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - rno3  * zonitr
+
+            END DO
+         END DO
+      END DO
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem1')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!    Bacterial uptake of iron. No iron is available in DOC. So
+!    Bacteries are obliged to take up iron from the water. Some
+!    studies (especially at Papa) have shown this uptake to be
+!    significant
+!    ----------------------------------------------------------
+               zbactfer = 15.e-6 * rfact2 * 4.* 0.4 * prmax(ji,jj,jk)           &
+                  &               * ( xlimphy(ji,jj,jk) * zdepbac(ji,jj,jk))**2           &
+                  &                  / ( xkgraz2 + zdepbac(ji,jj,jk) )                    &
+                  &                  * ( 0.5 + SIGN( 0.5, trn(ji,jj,jk,jpfer) -2.e-11 )  )
+
+               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zbactfer
+#if defined key_kriest
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zbactfer
+#else
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zbactfer
+#endif
+
+            END DO
+         END DO
+      END DO
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem2')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!    POC disaggregation by turbulence and bacterial activity. 
+!    -------------------------------------------------------------
+               zremip = xremip * zstep * tgfunc(ji,jj,jk)   &
+# if defined key_off_degrad
+                  &            * facvol(ji,jj,jk)              &
+# endif
+                  &            * ( 1.- 0.5 * nitrfac(ji,jj,jk) )
+
+!    POC disaggregation rate is reduced in anoxic zone as shown by
+!    sediment traps data. In oxic area, the exponent of the martin s
+!    law is around -0.87. In anoxic zone, it is around -0.35. This
+!    means a disaggregation constant about 0.5 the value in oxic zones
+!    -----------------------------------------------------------------
+               zorem  = zremip * trn(ji,jj,jk,jppoc)
+               zofer  = zremip * trn(ji,jj,jk,jpsfe)
+#if ! defined key_kriest
+               zorem2 = zremip * trn(ji,jj,jk,jpgoc)
+               zofer2 = zremip * trn(ji,jj,jk,jpbfe)
+#else
+               zorem2 = zremip * trn(ji,jj,jk,jpnum)
+#endif
+
+!  Update the appropriate tracers trends
+!  -------------------------------------
+
+               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zorem
+               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zofer
+#if defined key_kriest
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zorem
+               tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) - zorem2
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zofer
+#else
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zorem2 - zorem
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) - zorem2
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zofer2 - zofer
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) - zofer2
+#endif
+
+            END DO
+         END DO
+      END DO
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem3')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+!     Remineralization rate of BSi depedant on T and saturation
+!     ---------------------------------------------------------
+               zsatur  = ( sio3eq(ji,jj,jk) - trn(ji,jj,jk,jpsil) ) / ( sio3eq(ji,jj,jk) + rtrn )
+               zsatur  = MAX( rtrn, zsatur )
+               zsatur2 = zsatur * ( 1. + tn(ji,jj,jk) / 400.)**4
+               znusil  = 0.225  * ( 1. + tn(ji,jj,jk) / 15.) * zsatur + 0.775 * zsatur2**9
+#    if defined key_off_degrad
+               zsiremin = xsirem * zstep * znusil * facvol(ji,jj,jk)
+# else
+               zsiremin = xsirem * zstep * znusil
+#    endif
+               zosil = zsiremin * trn(ji,jj,jk,jpdsi)
+
+               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zosil
+               tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) + zosil
+
+               !
+            END DO
+         END DO
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem4')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+      zfesatur(:,:,:) = 0.6e-9
+!CDIR NOVERRCHK
+      DO jk = 1, jpkm1
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+!
+!      Compute de different ratios for scavenging of iron
+!      --------------------------------------------------
+
+#if  defined key_kriest
+               zdenom1 = trn(ji,jj,jk,jppoc) / &
+           &           ( trn(ji,jj,jk,jppoc) + trn(ji,jj,jk,jpdsi) + trn(ji,jj,jk,jpcal) + rtrn )
+#else
+                zdenom = 1. / ( trn(ji,jj,jk,jppoc) + trn(ji,jj,jk,jpgoc)  &
+           &            + trn(ji,jj,jk,jpdsi) + trn(ji,jj,jk,jpcal) + rtrn )
+
+                zdenom1 = trn(ji,jj,jk,jppoc) * zdenom
+                zdenom2 = trn(ji,jj,jk,jpgoc) * zdenom
+#endif
+
+
+!     scavenging rate of iron. this scavenging rate depends on the
+!     load in particles on which they are adsorbed. The
+!     parameterization has been taken from studies on Th
+!     ------------------------------------------------------------
+               zkeq = fekeq(ji,jj,jk)
+               zfeequi = ( -( 1. + zfesatur(ji,jj,jk) * zkeq - zkeq * trn(ji,jj,jk,jpfer) )               &
+                  &        + SQRT( ( 1. + zfesatur(ji,jj,jk) * zkeq - zkeq * trn(ji,jj,jk,jpfer) )**2       &
+                  &               + 4. * trn(ji,jj,jk,jpfer) * zkeq) ) / ( 2. * zkeq )
+#if ! defined key_kriest
+               zlam1b = 3.e-5 + xlam1 * (  trn(ji,jj,jk,jppoc) + trn(ji,jj,jk,jpgoc)   &
+                  &                      + trn(ji,jj,jk,jpcal) + trn(ji,jj,jk,jpdsi)  ) * 1.e6
+#else
+               zlam1b = 3.e-5 + xlam1 * (  trn(ji,jj,jk,jppoc)                   &
+                  &                      + trn(ji,jj,jk,jpcal) + trn(ji,jj,jk,jpdsi)  ) * 1.e6
+#endif
+# if defined key_off_degrad
+               zscave = zfeequi * zlam1b * zstep  * facvol(ji,jj,jk)
+# else
+               zscave = zfeequi * zlam1b * zstep
+# endif
+
+!  Increased scavenging for very high iron concentrations
+!  found near the coasts due to increased lithogenic particles
+!  and let s say it unknown processes (precipitation, ...)
+!  -----------------------------------------------------------
+               zlamfac = MAX( 0.e0, ( gphit(ji,jj) + 55.) / 30. )
+               zlamfac = MIN( 1.  , zlamfac )
+#if ! defined key_kriest
+               zlam1b = (  80.* ( trn(ji,jj,jk,jpdoc) + 35.e-6 )                           &
+                  &     + 698.*   trn(ji,jj,jk,jppoc) + 1.05e4 * trn(ji,jj,jk,jpgoc)  )                    &
+                  &   * xdiss(ji,jj,jk) + 1E-4 * (1.-zlamfac)                &
+                  &   + xlam1 * MAX( 0.e0, ( trn(ji,jj,jk,jpfer) * 1.e9 - 1.)  )
+#else
+               zlam1b = (  80.* (trn(ji,jj,jk,jpdoc) + 35E-6)           &
+                  &     + 698.*  trn(ji,jj,jk,jppoc)  )                    &
+                  &   * xdiss(ji,jj,jk) + 1E-4 * (1.-zlamfac)           &
+                  &   + xlam1 * MAX( 0.e0, ( trn(ji,jj,jk,jpfer) * 1.e9 - 1.)  )
+#endif
+
+# if defined key_off_degrad
+               zaggdfe = zlam1b * zstep * 0.5 * ( trn(ji,jj,jk,jpfer) - zfeequi ) * facvol(ji,jj,jk)
+# else
+               zaggdfe = zlam1b * zstep * 0.5 * ( trn(ji,jj,jk,jpfer) - zfeequi )
+# endif
+
+               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zscave - zaggdfe
+
+#if defined key_kriest
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zscave * zdenom1
+#else
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zscave * zdenom1
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zscave * zdenom2
+#endif
+
+            END DO
+         END DO
+      END DO
+      !
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem5')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+!     Update the arrays TRA which contain the biological sources and sinks
+!     --------------------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         tra(:,:,jk,jppo4) = tra(:,:,jk,jppo4) + zolimi(:,:,jk) + denitr(:,:,jk)
+         tra(:,:,jk,jpnh4) = tra(:,:,jk,jpnh4) + zolimi(:,:,jk) + denitr(:,:,jk)
+         tra(:,:,jk,jpno3) = tra(:,:,jk,jpno3) - denitr(:,:,jk) * rdenit
+         tra(:,:,jk,jpdoc) = tra(:,:,jk,jpdoc) - zolimi(:,:,jk) - denitr(:,:,jk)
+         tra(:,:,jk,jpoxy) = tra(:,:,jk,jpoxy) - zolimi(:,:,jk) * o2ut
+         tra(:,:,jk,jpdic) = tra(:,:,jk,jpdic) + zolimi(:,:,jk) + denitr(:,:,jk)
+         tra(:,:,jk,jptal) = tra(:,:,jk,jptal) + denitr(:,:,jk) * rno3 * rdenit
+     END DO
+
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rem6')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_rem
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_rem                    ! Empty routine
+   END SUBROUTINE p4z_rem
+#endif 
+
+   !!======================================================================
+END MODULE p4zrem
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsed.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsed.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsed.F90	(revision 4536)
@@ -0,0 +1,312 @@
+MODULE p4zsed
+   !!======================================================================
+   !!                         ***  MODULE p4sed  ***
+   !! TOP :   PISCES Compute loss of organic matter in the sediments
+   !!======================================================================
+   !! 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
+   !!----------------------------------------------------------------------
+   !!   p4z_sed        :  Compute loss of organic matter in the sediments
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE lib_mpp
+   USE prtctl_trc
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_sed    ! called in p4zprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_sed
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_sed  ***
+      !!
+      !! ** Purpose :   Compute loss of organic matter in the sediments. This
+      !!              is by no way a sediment model. The loss is simply 
+      !!              computed to balance the inout from rivers and dust
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      INTEGER  ::   ikt
+      REAL(wp) ::   zsumsedsi, zsumsedpo4, zsumsedcal
+      REAL(wp) ::   zconctmp , zdenitot  , znitrpottot
+      REAL(wp) ::   zlim, zconctmp2, zstep, zfact
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zsidep
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znitrpot, zirondep
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+
+      zstep = rfact2 / rjjss      ! Time step duration for the biology
+
+      zirondep(:,:,:) = 0.e0          ! Initialisation of variables used to compute deposition
+      zsidep  (:,:)   = 0.e0
+
+      ! Iron and Si deposition at the surface
+      ! -------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zirondep(ji,jj,1) = ( 0.014 * dust(ji,jj) / ( 55.85 * rmoss ) + 3.e-10 / raass )   &
+               &             * rfact2 / fse3t(ji,jj,1)
+            zsidep  (ji,jj)   = 8.8 * 0.075 * dust(ji,jj) * rfact2 / ( fse3t(ji,jj,1) * 28.1 * rmoss )
+         END DO
+      END DO
+
+      ! Iron solubilization of particles in the water column
+      ! ----------------------------------------------------
+
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zirondep(ji,jj,jk) = dust(ji,jj) / ( 10. * 55.85 * rmoss ) * rfact2 * 0.0001
+            END DO
+         END DO
+      END DO
+
+      ! Add the external input of nutrients, carbon and alkalinity
+      ! ----------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            trn(ji,jj,1,jppo4) = trn(ji,jj,1,jppo4) +   rivinp(ji,jj)                   * rfact2
+            trn(ji,jj,1,jpno3) = trn(ji,jj,1,jpno3) + ( rivinp(ji,jj) + nitdep(ji,jj) ) * rfact2
+            trn(ji,jj,1,jpfer) = trn(ji,jj,1,jpfer) +   rivinp(ji,jj) * 3.e-5           * rfact2
+            trn(ji,jj,1,jpsil) = trn(ji,jj,1,jpsil) +   zsidep (ji,jj) + cotdep(ji,jj)   * rfact2 / 6.
+            trn(ji,jj,1,jpdic) = trn(ji,jj,1,jpdic) +   rivinp(ji,jj) * 2.631           * rfact2
+            trn(ji,jj,1,jptal) = trn(ji,jj,1,jptal) + ( cotdep(ji,jj) - rno3*(rivinp(ji,jj)   &
+               &                                                      + nitdep(ji,jj) ) ) * rfact2
+         END DO
+      END DO
+
+
+      ! Add the external input of iron which is 3D distributed
+      ! (dust, river and sediment mobilization)
+      ! ------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               trn(ji,jj,jk,jpfer) = trn(ji,jj,jk,jpfer)   &
+                  &                + zirondep(ji,jj,jk) + ironsed(ji,jj,jk) * rfact2
+            END DO
+         END DO
+      END DO
+
+      ! Initialisation of variables used to compute Sinking Speed
+      ! ---------------------------------------------------------
+
+      zsumsedsi  = 0.e0
+      zsumsedpo4 = 0.e0
+      zsumsedcal = 0.e0
+
+      ! Loss of biogenic silicon, Caco3 organic carbon in the sediments. 
+      ! First, the total loss is computed.
+      ! The factor for calcite comes from the alkalinity effect
+      ! -------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj)-1, 1 )
+            zfact = e1t(ji,jj) * e2t(ji,jj) / rjjss * tmask_i(ji,jj)
+# if ! defined key_kriest
+            zsumsedsi  = zsumsedsi  + zfact *  trn(ji,jj,ikt,jpdsi) * wsbio4(ji,jj,ikt) 
+# else
+            zsumsedsi  = zsumsedsi  + zfact *  trn(ji,jj,ikt,jpdsi) * wscal (ji,jj,ikt)
+# endif
+            zsumsedcal = zsumsedcal + zfact *  trn(ji,jj,ikt,jpcal) * wscal (ji,jj,ikt) * 2.e0
+# if  defined key_kriest
+            zsumsedpo4 = zsumsedpo4 + zfact *  trn(ji,jj,ikt,jppoc) * wsbio3(ji,jj,ikt)
+# else
+            zsumsedpo4 = zsumsedpo4 + zfact *( trn(ji,jj,ikt,jpgoc) * wsbio4(ji,jj,ikt)   &
+               &                             + trn(ji,jj,ikt,jppoc) * wsbio3(ji,jj,ikt) )
+# endif
+         END DO
+      END DO
+
+      IF( lk_mpp ) THEN
+         CALL mpp_sum( zsumsedsi  )   ! sums over the global domain
+         CALL mpp_sum( zsumsedcal )   ! sums over the global domain
+         CALL mpp_sum( zsumsedpo4 )   ! sums over the global domain
+      ENDIF
+
+      ! Then this loss is scaled at each bottom grid cell for
+      ! equilibrating the total budget of silica in the ocean.
+      ! Thus, the amount of silica lost in the sediments equal
+      ! the supply at the surface (dust+rivers)
+      ! ------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj) - 1, 1 )
+            zconctmp = trn(ji,jj,ikt,jpdsi) * zstep / fse3t(ji,jj,ikt)   &
+# if ! defined key_kriest
+     &               * wsbio4(ji,jj,ikt) 
+# else
+     &               * wscal (ji,jj,ikt)
+# endif
+            trn(ji,jj,ikt,jpdsi) = trn(ji,jj,ikt,jpdsi) - zconctmp
+            trn(ji,jj,ikt,jpsil) = trn(ji,jj,ikt,jpsil) + zconctmp   &
+               &                 * ( 1.- ( sumdepsi + rivalkinput / raass / 6. ) / zsumsedsi )
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj) - 1, 1 )
+            zconctmp = trn(ji,jj,ikt,jpcal) * wscal(ji,jj,ikt) * zstep / fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jpcal) = trn(ji,jj,ikt,jpcal) - zconctmp
+            trn(ji,jj,ikt,jptal) = trn(ji,jj,ikt,jptal) + zconctmp   &
+               &                 * ( 1.- ( rivalkinput / raass ) / zsumsedcal ) * 2.e0
+            trn(ji,jj,ikt,jpdic) = trn(ji,jj,ikt,jpdic) + zconctmp   &
+               &                 * ( 1.- ( rivalkinput / raass ) / zsumsedcal )
+         END DO
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            ikt = MAX( mbathy(ji,jj) - 1, 1 )
+# if ! defined key_kriest
+            zconctmp  = trn(ji,jj,ikt,jpgoc)
+            zconctmp2 = trn(ji,jj,ikt,jppoc)
+            trn(ji,jj,ikt,jpgoc) = trn(ji,jj,ikt,jpgoc) - zconctmp  * wsbio4(ji,jj,ikt)   * zstep / fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jppoc) = trn(ji,jj,ikt,jppoc) - zconctmp2 * wsbio3(ji,jj,ikt)   * zstep / fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jpdoc) = trn(ji,jj,ikt,jpdoc)    &
+               &      + ( zconctmp  * wsbio4(ji,jj,ikt) + zconctmp2 * wsbio3(ji,jj,ikt) ) * zstep / fse3t(ji,jj,ikt)   &
+               &                                        * ( 1.- rivpo4input / (raass * zsumsedpo4 ) )
+            trn(ji,jj,ikt,jpbfe) = trn(ji,jj,ikt,jpbfe) - trn(ji,jj,ikt,jpbfe) * wsbio4(ji,jj,ikt) * zstep   &
+               &          /fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jpsfe) = trn(ji,jj,ikt,jpsfe) - trn(ji,jj,ikt,jpsfe) * wsbio3(ji,jj,ikt) * zstep   &
+               &          /fse3t(ji,jj,ikt)
+# else
+            zconctmp  = trn(ji,jj,ikt,jpnum)
+            zconctmp2 = trn(ji,jj,ikt,jppoc)
+            trn(ji,jj,ikt,jpnum) = trn(ji,jj,ikt,jpnum)   &
+               &          - zconctmp * wsbio4(ji,jj,ikt) * zstep / fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jppoc) = trn(ji,jj,ikt,jppoc)   &
+               &          - zconctmp2 * wsbio3(ji,jj,ikt) * zstep / fse3t(ji,jj,ikt)
+            trn(ji,jj,ikt,jpdoc) = trn(ji,jj,ikt,jpdoc)    &
+               &          + ( zconctmp2 * wsbio3(ji,jj,ikt) )   &
+               &          * zstep / fse3t(ji,jj,ikt) * ( 1.- rivpo4input / ( raass * zsumsedpo4 ) )
+            trn(ji,jj,ikt,jpsfe) = trn(ji,jj,ikt,jpsfe)   &
+               &                 - trn(ji,jj,ikt,jpsfe) * wsbio3(ji,jj,ikt) * zstep / fse3t(ji,jj,ikt)
+# endif
+         END DO
+      END DO
+
+      ! Nitrogen fixation (simple parameterization). The total gain
+      ! from nitrogen fixation is scaled to balance the loss by 
+      ! denitrification
+      ! -------------------------------------------------------------
+
+!!gm optimisation : use fs do loop index... or 1 to jpi/j
+      zdenitot = 0.e0
+      DO jk = 1, jpkm1
+         DO jj= 2, jpjm1
+            DO ji = 2, jpim1
+               zdenitot = zdenitot + denitr(ji,jj,jk) * rdenit * e1t(ji,jj) * e2t(ji,jj)   &
+                  &    *fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj) * xnegtr(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      IF( lk_mpp )   CALL mpp_sum( zdenitot )      ! sum over the global domain
+
+      ! Potential nitrogen fication dependant on temperature and iron
+      ! -------------------------------------------------------------
+
+!CDIR NOVERRCHK
+      DO jk = 1, jpk
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               zlim = ( 1.- xnanono3(ji,jj,jk) - xnanonh4(ji,jj,jk) )
+               IF( zlim <= 0.2 )   zlim = 0.01
+               znitrpot(ji,jj,jk) = MAX( 0.e0, ( 0.6 * tgfunc(ji,jj,jk) - 2.15 ) / rjjss )   &
+# if defined key_off_degrad
+                  &               * facvol(ji,jj,jk)   &
+# endif
+                  &               * zlim * rfact2 * trn(ji,jj,jk,jpfer)   &
+                  &               / ( conc3 + trn(ji,jj,jk,jpfer) ) * ( 1.- EXP( -etot(ji,jj,jk) / 50.) )
+            END DO
+         END DO 
+      END DO
+
+      znitrpottot = 0.e0
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               znitrpottot = znitrpottot + znitrpot(ji,jj,jk) * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)   &
+                  &                                           * tmask(ji,jj,jk) * tmask_i(ji,jj) 
+            END DO
+         END DO
+      END DO
+
+      IF( lk_mpp )   CALL mpp_sum( znitrpottot )  ! sum over the global domain
+
+      ! Nitrogen change due to nitrogen fixation
+      ! ----------------------------------------
+
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+# if ! defined key_cfg_1d && ( defined key_orca_r4 || defined key_orca_r2 || defined key_orca_r05 || defined key_orca_r025 )
+!!               zfact = znitrpot(ji,jj,jk) * zdenitot / znitrpottot
+               zfact = znitrpot(ji,jj,jk) * 1.e-7
+# else
+               zfact = znitrpot(ji,jj,jk) * 1.e-7
+# endif
+               trn(ji,jj,jk,jpnh4) = trn(ji,jj,jk,jpnh4) + zfact
+               trn(ji,jj,jk,jpoxy) = trn(ji,jj,jk,jpoxy) + zfact   * o2nit
+               trn(ji,jj,jk,jppo4) = trn(ji,jj,jk,jppo4) + 30./ 46.* zfact
+            END DO
+         END DO
+      END DO
+
+# if defined key_trc_diaadd
+      DO jj = 1,jpj
+         DO ji = 1,jpi
+            trc2d(ji,jj,13) = znitrpot(ji,jj,1) * 1.e-7 * fse3t(ji,jj,1) * 1.e+3 / rfact2
+            trc2d(ji,jj,12) = zirondep(ji,jj,1) * 1.e+3 * rfact2r * fse3t(ji,jj,1)
+         END DO
+      END DO
+# endif
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sed ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_sed
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_sed                         ! Empty routine
+   END SUBROUTINE p4z_sed
+#endif 
+
+   !!======================================================================
+END MODULE  p4zsed
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink.F90	(revision 4536)
@@ -0,0 +1,217 @@
+MODULE p4zsink
+   !!======================================================================
+   !!                         ***  MODULE p4zsink  ***
+   !! TOP :   PISCES Compute vertical flux of particulate matter due to gravitational sinking
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces  && ! defined key_kriest
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'        and                            PISCES bio-model
+   !!   NOT 'key_kriest'                                   No Kriest option
+   !!----------------------------------------------------------------------
+   !!   p4z_sink       :  Compute vertical flux of particulate matter due to gravitational sinking
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE p4zsink2        !
+   USE prtctl_trc
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_sink    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_sink
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_sink  ***
+      !!
+      !! ** Purpose :   Compute vertical flux of particulate matter due to 
+      !!              gravitational sinking
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
+      INTEGER  ::   iksed
+      REAL(wp) ::   zagg1, zagg2, zagg3, zagg4
+      REAL(wp) ::   zagg , zaggfe, zaggdoc, zaggdoc2
+      REAL(wp) ::   zfact, zstep, zwsmax
+#if defined key_trc_dia3d
+      REAL(wp) ::   zrfact2
+#endif
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsinking, zsinking2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsinkfer, zsinkfer2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsinkcal, zsinksil
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+       zstep = rfact2 / rjjss      ! Timestep duration for biology
+
+
+!    Sinking speeds of detritus is increased with depth as shown
+!    by data and from the coagulation theory
+!    -----------------------------------------------------------
+
+      iksed = 10
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji=1,jpi
+               zfact = MAX( 0., fsdepw(ji,jj,jk+1)-hmld(ji,jj) ) / 4000.
+               wsbio4(ji,jj,jk) = wsbio2 + ( 200.- wsbio2 ) * zfact
+            END DO
+         END DO
+      END DO
+
+!      LIMIT THE VALUES OF THE SINKING SPEEDS 
+!      TO AVOID NUMERICAL INSTABILITIES
+
+      wsbio3(:,:,:) = wsbio
+
+      DO jk = 1,jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zwsmax = 0.8 * fse3t(ji,jj,jk) / zstep
+               wsbio4(ji,jj,jk) = MIN( wsbio4(ji,jj,jk), zwsmax )
+               wsbio3(ji,jj,jk) = MIN( wsbio3(ji,jj,jk), zwsmax )
+            END DO
+         END DO
+      END DO
+
+      wscal(:,:,:) = wsbio4(:,:,:)
+
+
+!   INITIALIZE TO ZERO ALL THE SINKING ARRAYS
+!   -----------------------------------------
+
+      zsinking (:,:,:) = 0.e0
+      zsinking2(:,:,:) = 0.e0
+      zsinkcal (:,:,:) = 0.e0
+      zsinkfer (:,:,:) = 0.e0
+      zsinksil (:,:,:) = 0.e0
+      zsinkfer2(:,:,:) = 0.e0
+
+!   Compute the sedimentation term using p4zsink2 for all
+!   the sinking particles
+!   -----------------------------------------------------
+
+      CALL p4z_sink2( wsbio3, zsinking , jppoc )
+      CALL p4z_sink2( wsbio3, zsinkfer , jpsfe )
+      CALL p4z_sink2( wsbio4, zsinking2, jpgoc )
+      CALL p4z_sink2( wsbio4, zsinkfer2, jpbfe )
+      CALL p4z_sink2( wsbio4, zsinksil , jpdsi )
+      CALL p4z_sink2( wscal , zsinkcal , jpcal )
+
+!  Exchange between organic matter compartments due to
+!  coagulation/disaggregation
+!  ---------------------------------------------------
+
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+
+               zfact = zstep * xdiss(ji,jj,jk)
+
+!    Part I : Coagulation dependent on turbulence
+!    ----------------------------------------------
+
+# if defined key_off_degrad
+               zagg1 = 940.* zfact * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jppoc) * facvol(ji,jj,jk)
+# else
+               zagg1 = 940.* zfact * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jppoc)
+# endif
+
+# if defined key_off_degrad
+               zagg2 = 1.054e4 * zfact * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpgoc) * facvol(ji,jj,jk)
+# else
+               zagg2 = 1.054e4 * zfact * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpgoc)
+# endif
+
+!    Aggregation of small into large particles
+!    Part II : Differential settling
+!    ----------------------------------------------
+
+# if defined key_off_degrad
+               zagg3 = 0.66 * zstep * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpgoc) * facvol(ji,jj,jk)
+# else
+               zagg3 = 0.66 * zstep * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jpgoc)
+# endif
+
+# if defined key_off_degrad
+!!gm  zagg4 set to zero ????
+               zagg4 = 0.e0 * zstep * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jppoc) * facvol(ji,jj,jk)
+# else
+!!gm  zagg4 set to zero ????
+               zagg4 = 0.e0 * zstep * trn(ji,jj,jk,jppoc) * trn(ji,jj,jk,jppoc)
+# endif
+
+               zagg   = zagg1 + zagg2 + zagg3 + zagg4
+               zaggfe = zagg * trn(ji,jj,jk,jpsfe) / ( trn(ji,jj,jk,jppoc) + rtrn )
+
+!     Aggregation of DOC to small particles
+!     --------------------------------------
+
+               zaggdoc = ( 80.* trn(ji,jj,jk,jpdoc) + 698. * trn(ji,jj,jk,jppoc) )       &
+# if defined key_off_degrad
+                  &      * facvol(ji,jj,jk)                           &
+# endif
+                  &      * zfact * trn(ji,jj,jk,jpdoc)
+
+               zaggdoc2 = 1.05e4 * zfact * trn(ji,jj,jk,jpgoc)   &
+# if defined key_off_degrad
+                  &        * facvol(ji,jj,jk)                            &
+# endif      
+                  &        * trn(ji,jj,jk,jpdoc)
+
+               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zagg + zaggdoc
+               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zagg + zaggdoc2
+               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zaggfe
+               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zaggfe
+               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zaggdoc - zaggdoc2
+
+            END DO
+         END DO
+      END DO
+
+# if defined key_trc_dia3d
+      zrfact2 = 1.e3 * rfact2r
+      trc2d(:,:, 5) = zsinking (:,:,iksed+1) * zrfact2
+      trc2d(:,:, 6) = zsinking2(:,:,iksed+1) * zrfact2
+      trc2d(:,:, 7) = zsinkfer (:,:,iksed+1) * zrfact2
+      trc2d(:,:, 8) = zsinkfer2(:,:,iksed+1) * zrfact2
+      trc2d(:,:, 9) = zsinksil (:,:,iksed+1) * zrfact2
+      trc2d(:,:,10) = zsinkcal (:,:,iksed+1) * zrfact2
+# endif
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sink')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+
+   END SUBROUTINE p4z_sink
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_sink                    ! Empty routine
+   END SUBROUTINE p4z_sink
+#endif 
+
+   !!======================================================================
+END MODULE  p4zsink
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink2.F90	(revision 4536)
@@ -0,0 +1,167 @@
+MODULE p4zsink2
+   !!======================================================================
+   !!                         ***  MODULE p4zsink2  ***
+   !! TOP :   PISCES Compute vertical flux of particulate matter due to gravitational sinking
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4z_sink2       :  Compute vertical flux of particulate matter due to gravitational sinking
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_sink2    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_sink2( wstmp, sinktemp, jn )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_sink2  ***
+      !!
+      !! ** Purpose :   Compute the sedimentation terms for the various sinking
+      !!     particles. The scheme used to compute the trends is based
+      !!     on MUSCL.
+      !!
+      !! ** Method  : - this ROUTINE compute not exactly the advection but the
+      !!      transport term, i.e.  div(u*tra).
+      !!---------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   jn         ! tracer index index      
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj,jpk) ::   wstmp      ! ???
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   sinktemp   ! ???
+      !!
+      INTEGER  ::   ji, jj, jk, jnt
+      REAL(wp) ::   zigma,zew,zstep,zign
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztraz, zakz
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zkz  , zwstmp2
+      !!---------------------------------------------------------------------
+
+      zstep  = rfact2 / 2.
+
+      ztraz(:,:,:) = 0.e0
+      zkz  (:,:,:) = 0.e0
+      zakz (:,:,:) = 0.e0
+
+      DO jk = 1, jpkm1
+# if defined key_off_degrad
+         zwstmp2(:,:,jk+1)=-wstmp(:,:,jk)/rjjss*tmask(:,:,jk+1)*facvol(:,:,jk)
+# else
+         zwstmp2(:,:,jk+1)=-wstmp(:,:,jk)/rjjss*tmask(:,:,jk+1)
+
+# endif
+      END DO
+ 
+      zwstmp2(:,:,1) = 0.e0
+!
+! Vertical advective flux
+!-------------------------------
+
+      DO jnt = 1, 2
+
+! ... first guess of the slopes interior values
+
+         DO jk = 2, jpkm1
+            ztraz(:,:,jk) = (trn(:,:,jk-1,jn) - trn(:,:,jk,jn)) *tmask(:,:,jk)
+         END DO
+
+         ztraz(:,:,1  ) = 0.0
+         ztraz(:,:,jpk) = 0.0
+!
+! slopes
+         DO jk=2,jpkm1
+            DO jj = 1,jpj
+               DO ji = 1, jpi
+                  zign = 0.25 + SIGN( 0.25,ztraz(ji,jj,jk)*ztraz(ji,jj,jk+1) )
+                  zakz(ji,jj,jk) = (ztraz(ji,jj,jk) + ztraz(ji,jj,jk+1) ) * zign
+               END DO
+            END DO
+         END DO
+         !
+         ! Slopes limitation
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zakz(ji,jj,jk) = SIGN(1.,zakz(ji,jj,jk)) *        &
+                     &             MIN(ABS(zakz(ji,jj,jk)),         &
+                     &             2.*ABS(ztraz(ji,jj,jk+1)),       &
+                     &             2.*ABS(ztraz(ji,jj,jk)))
+               END DO
+            END DO
+         END DO
+         
+         ! vertical advective flux
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj      
+               DO ji = 1, jpi    
+                  zigma = zwstmp2(ji,jj,jk+1)*zstep/fse3w(ji,jj,jk+1)
+                  zew   = zwstmp2(ji,jj,jk+1)
+                  sinktemp(ji,jj,jk+1) = -zew*(trn(ji,jj,jk,jn)                &
+                     &                 -0.5*(1+zigma)*zakz(ji,jj,jk))*zstep
+               END DO
+            END DO
+         END DO
+         !
+         ! Boundary conditions
+         sinktemp(:,:,1  ) = 0.e0
+         sinktemp(:,:,jpk) = 0.e0
+         
+         DO jk=1,jpkm1
+            DO jj = 1,jpj
+               DO ji = 1, jpi
+                  trn(ji,jj,jk,jn) = trn(ji,jj,jk,jn)               &
+                     &        + (sinktemp(ji,jj,jk)-sinktemp(ji,jj,jk+1))     &
+                     &        /fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+      ENDDO
+
+      DO jk=1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1, jpi
+               ! 
+               trb(ji,jj,jk,jn) = trb(ji,jj,jk,jn)      &
+               &        + 2.*(sinktemp(ji,jj,jk)-sinktemp(ji,jj,jk+1)) &
+               &        /fse3t(ji,jj,jk)
+!
+          ENDDO
+        ENDDO
+      ENDDO
+!
+        trn(:,:,:,jn)   = trb(:,:,:,jn)
+        sinktemp(:,:,:) = 2. * sinktemp(:,:,:)
+
+      !
+   END SUBROUTINE p4z_sink2
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_sink2( wstmp, sinktemp, jn )         ! Empty routine
+      INTEGER, INTENT( in ) ::   jn
+      REAL   , INTENT( in ) ::   wstmp,sinktemp    
+      WRITE(*,*) 'p4z_sink2: You should not have seen this print! error?', jn, wstmp, sinktemp
+   END SUBROUTINE p4z_sink2
+#endif 
+
+   !!======================================================================
+END MODULE  p4zsink2
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink_kriest.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink_kriest.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/p4zsink_kriest.F90	(revision 4536)
@@ -0,0 +1,274 @@
+MODULE p4zsink_kriest
+   !!======================================================================
+   !!                   ***  MODULE p4zsink_kriest  ***
+   !! TOP :   PISCES Compute vertical flux of particulate matter due to gravitational sinking
+   !!         Kriest parameterization
+   !!======================================================================
+   !! History :   1.0  !  2004     (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces  &&  defined key_kriest
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'    and                                PISCES bio-model
+   !!   'key_kriest'                                          kriest option
+   !!----------------------------------------------------------------------
+   !!   p4z_sink_kriest :  Compute vertical flux of particulate matter due 
+   !!                      to gravitational sinking (Kriest parameterization)
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trp_trc
+   USE sms
+   USE p4zsink2
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_sink_kriest    ! called in p4zbio.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_sink_kriest
+      !!---------------------------------------------------------------------
+      !!                ***  ROUTINE p4z_sink_kriest  ***
+      !!
+      !! ** Purpose :   Compute vertical flux of particulate matter due to 
+      !!              gravitational sinking - Kriest parameterization
+      !!
+      !! ** Method  : - ???
+      !!---------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk
+      INTEGER  :: iksed
+      REAL(wp) :: zagg1, zagg2, zagg3, zagg4, zagg5, zaggsi, zaggsh
+      REAL(wp) :: zagg , zaggdoc, znumdoc
+      REAL(wp) :: znum , zeps, zfm, zgm, zsm
+      REAL(wp) :: zdiv , zdiv1, zdiv2, zdiv3, zdiv4, zdiv5
+      REAL(wp) :: zval1, zval2, zval3, zval4
+      REAL(wp) :: zstep
+#if defined key_trc_dia3d
+      REAL(wp) ::   zrfact2
+#endif
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znum3d
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   sinking, sinking2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   sinkfer
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   sinkcal, sinksil
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+       zstep=rfact2/rjjss      ! Time step duration for biology
+
+
+!     Initialisation of variables used to compute Sinking Speed
+!     ---------------------------------------------------------
+
+       znum3d(:,:,:) = 0.e0
+       iksed = 10
+       zval1 = 1. + xkr_zeta
+       zval2 = 1. + xkr_zeta + xkr_eta
+       zval3 = 1. + xkr_eta
+
+!     Computation of the vertical sinking speed : Kriest et Evans, 2000
+!     -----------------------------------------------------------------
+    
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tmask(ji,jj,jk) /= 0.e0 ) THEN
+                  znum = trn(ji,jj,jk,jppoc) / ( trn(ji,jj,jk,jpnum) + rtrn ) / xkr_massp
+! -------------- To avoid sinking speed over 50 m/day -------
+                  znum  = MIN( xnumm(jk), znum )
+                  znum  = MAX( 1.1      , znum )
+                  znum3d(ji,jj,jk) = znum
+!------------------------------------------------------------
+                  zeps  = ( zval1 * znum - 1. )/ ( znum - 1. )
+                  zfm   = xkr_frac**( 1. - zeps )
+                  zgm   = xkr_frac**( zval1 - zeps )
+                  zdiv  = MAX( 1.e-4, ABS( zeps - zval2 ) ) * SIGN( 1., ( zeps - zval2 ) )
+                  zdiv1 = zeps - zval3
+!!gmoptimisation possible below
+                  wsbio3(ji,jj,jk) = xkr_wsbio_min * ( zeps - zval1 ) / zdiv    &
+     &                             - xkr_wsbio_max *   zgm * xkr_eta  / zdiv
+                  wsbio4(ji,jj,jk) = xkr_wsbio_min *   ( zeps-1. )    / zdiv1   &
+     &                             - xkr_wsbio_max *   zfm * xkr_eta  / zdiv1
+                  IF( znum == 1.1)   wsbio3(ji,jj,jk) = wsbio4(ji,jj,jk)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      wscal(:,:,:) = MAX( wsbio3(:,:,:), 50. )
+
+
+!   INITIALIZE TO ZERO ALL THE SINKING ARRAYS
+!   -----------------------------------------
+
+      sinking (:,:,:) = 0.e0
+      sinking2(:,:,:) = 0.e0
+      sinkcal (:,:,:) = 0.e0
+      sinkfer (:,:,:) = 0.e0
+      sinksil (:,:,:) = 0.e0
+
+!   Compute the sedimentation term using p4zsink2 for all
+!   the sinking particles
+!   -----------------------------------------------------
+
+      CALL p4z_sink2( wsbio3, sinking , jppoc )
+      CALL p4z_sink2( wsbio4, sinking2, jpnum )
+      CALL p4z_sink2( wsbio3, sinkfer , jpsfe )
+      CALL p4z_sink2( wscal , sinksil , jpdsi )
+      CALL p4z_sink2( wscal , sinkcal , jpcal )
+
+!  Exchange between organic matter compartments due to
+!  coagulation/disaggregation
+!  ---------------------------------------------------
+
+      zval1 = 1. + xkr_zeta
+      zval2 = 1. + xkr_eta
+      zval3 = 3. + xkr_eta
+      zval4 = 4. + xkr_eta
+
+      DO jk = 1,jpkm1
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               IF( tmask(ji,jj,jk) /= 0.e0 ) THEN
+
+                  znum = trn(ji,jj,jk,jppoc)/(trn(ji,jj,jk,jpnum)+rtrn) / xkr_massp
+! -------------- To avoid sinking speed over 50 m/day -------
+                  znum  = min(xnumm(jk),znum)
+                  znum  = MAX( 1.1,znum)
+!------------------------------------------------------------
+                  zeps  = ( zval1 * znum - 1.) / ( znum - 1.)
+                  zdiv  = MAX( 1.e-4, ABS( zeps - zval3) ) * SIGN( 1., zeps - zval3 )
+                  zdiv1 = MAX( 1.e-4, ABS( zeps - 4.   ) ) * SIGN( 1., zeps - 4.    )
+                  zdiv2 = zeps - 2.
+                  zdiv3 = zeps - 3.
+                  zdiv4 = zeps - zval2
+                  zdiv5 = 2.* zeps - zval4
+                  zfm   = xkr_frac**( 1.- zeps )
+                  zsm   = xkr_frac**xkr_eta
+
+!    Part I : Coagulation dependant on turbulence
+!    ----------------------------------------------
+
+                  zagg1 = ( 0.163 * trn(ji,jj,jk,jpnum)**2               &
+                     &            * 2.*( (zfm-1.)*(zfm*xkr_mass_max**3-xkr_mass_min**3)    &
+                     &            * (zeps-1)/zdiv1 + 3.*(zfm*xkr_mass_max-xkr_mass_min)    &
+                     &            * (zfm*xkr_mass_max**2-xkr_mass_min**2)                  &
+                     &            * (zeps-1.)**2/(zdiv2*zdiv3))            &
+# if defined key_off_degrad
+                     &                 *facvol(ji,jj,jk)       &
+# endif
+                     &    )
+
+                  zagg2 = (  2*0.163*trn(ji,jj,jk,jpnum)**2*zfm*                       &
+                     &                   ((xkr_mass_max**3+3.*(xkr_mass_max**2          &
+                     &                    *xkr_mass_min*(zeps-1.)/zdiv2                 &
+                     &                    +xkr_mass_max*xkr_mass_min**2*(zeps-1.)/zdiv3)    &
+                     &                    +xkr_mass_min**3*(zeps-1)/zdiv1)                  &
+                     &                    -zfm*xkr_mass_max**3*(1.+3.*((zeps-1.)/           &
+                     &                    (zeps-2.)+(zeps-1.)/zdiv3)+(zeps-1.)/zdiv1))      &
+#    if defined key_off_degrad
+                     &                 *facvol(ji,jj,jk)             &
+#    endif
+                     &    )
+
+                  zagg3 = (  0.163*trn(ji,jj,jk,jpnum)**2*zfm**2*8. * xkr_mass_max**3   &
+#    if defined key_off_degrad
+                     &                 *facvol(ji,jj,jk)             &
+#    endif
+                     &    )
+
+                  zaggsh = ( zagg1 + zagg2 + zagg3 ) * rfact2 * xdiss(ji,jj,jk) / 1000.
+
+!    Aggregation of small into large particles
+!    Part II : Differential settling
+!    ----------------------------------------------
+
+                  zagg4 = (  2.*3.141*0.125*trn(ji,jj,jk,jpnum)**2*                       &
+                     &                 xkr_wsbio_min*(zeps-1.)**2                         &
+                     &                 *(xkr_mass_min**2*((1.-zsm*zfm)/(zdiv3*zdiv4)      &
+                     &                 -(1.-zfm)/(zdiv*(zeps-1.)))-                       &
+                     &                 ((zfm*zfm*xkr_mass_max**2*zsm-xkr_mass_min**2)     &
+                     &                 *xkr_eta)/(zdiv*zdiv3*zdiv5) )                     &
+# if defined key_off_degrad
+                     &                 *facvol(ji,jj,jk)        &
+# endif
+                     &    )
+
+                  zagg5 = (  2.*3.141*0.125*trn(ji,jj,jk,jpnum)**2                         &
+                     &                 *(zeps-1.)*zfm*xkr_wsbio_min                        &
+                     &                 *(zsm*(xkr_mass_min**2-zfm*xkr_mass_max**2)         &
+                     &                 /zdiv3-(xkr_mass_min**2-zfm*zsm*xkr_mass_max**2)    &
+                     &                 /zdiv)                   &
+# if defined key_off_degrad
+                     &                 *facvol(ji,jj,jk)        &
+# endif
+                     &    )
+
+                  zaggsi = ( zagg4 + zagg5 ) * zstep / 10.
+
+                  zagg = 0.5 * xkr_stick * ( zaggsh + zaggsi )
+
+!     Aggregation of DOC to small particles
+!     --------------------------------------
+
+                  zaggdoc = ( 0.4 * trn(ji,jj,jk,jpdoc)               &
+                     &        + 1018.  * trn(ji,jj,jk,jppoc)  ) * zstep    &
+# if defined key_off_degrad
+                     &        * facvol(ji,jj,jk)                              &
+# endif
+                     &        * xdiss(ji,jj,jk) * trn(ji,jj,jk,jpdoc)
+                      
+                  znumdoc = trn(ji,jj,jk,jpnum) / ( trn(ji,jj,jk,jppoc) + rtrn )
+                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zaggdoc
+                  tra(ji,jj,jk,jpnum) = tra(ji,jj,jk,jpnum) + zaggdoc * znumdoc - zagg
+                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zaggdoc
+
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+#    if defined key_trc_dia3d
+      zrfact2 = 1.e3 * rfact2r
+      trc2d(:,:, 5)   = sinking (:,:,iksed+1) * zrfact2
+      trc2d(:,:, 6)   = sinking2(:,:,iksed+1) * zrfact2
+      trc2d(:,:, 7)   = sinkfer (:,:,iksed+1) * zrfact2
+      trc2d(:,:, 9)   = sinksil (:,:,iksed+1) * zrfact2
+      trc2d(:,:,10)   = sinkcal (:,:,iksed+1) * zrfact2
+      trc3d(:,:,:,12) = sinking (:,:,:)       * zrfact2
+      trc3d(:,:,:,13) = sinking2(:,:,:)       * zrfact2
+      trc3d(:,:,:,14) = sinksil (:,:,:)       * zrfact2
+      trc3d(:,:,:,15) = sinkcal (:,:,:)       * zrfact2
+      trc3d(:,:,:,16) = znum3d  (:,:,:)
+      trc3d(:,:,:,17) = wsbio3  (:,:,:)
+      trc3d(:,:,:,18) = wsbio4  (:,:,:)
+#    endif
+      !
+       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sink')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+       ENDIF
+   END SUBROUTINE p4z_sink_kriest
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_sink_kriest                    ! Empty routine
+   END SUBROUTINE p4z_sink_kriest
+#endif 
+
+   !!======================================================================
+END MODULE  p4zsink_kriest
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/par_pisces.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/par_pisces.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/par_pisces.F90	(revision 4536)
@@ -0,0 +1,113 @@
+MODULE par_pisces
+   !!======================================================================
+   !!                        ***  par_pisces  ***
+   !! TOP :   set the PISCES parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_lobster, ONLY : jp_lobster   !: number of tracers in LOBSTER
+
+   IMPLICIT NONE
+   PUBLIC
+
+   INTEGER, PUBLIC, PARAMETER ::   jp_l  = jp_lobster      !: cumulative number of already defined TRC
+
+#if defined key_pisces  &&  defined key_kriest
+   !!---------------------------------------------------------------------
+   !!   'key_pisces' & 'key_kriest'                 PISCES bio-model + ???
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_pisces     = .TRUE.  !: PISCES flag 
+   LOGICAL, PUBLIC, PARAMETER ::   lk_kriest     = .TRUE.  !: Kriest flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces     =  23     !: number of passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_2d  =  13     !: additional 2d output ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_3d  =  18     !: additional 3d output ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_trd =   1     !: number of sms trends for PISCES
+
+   ! assign an index in trc arrays for each LOBSTER prognostic variables
+   !    WARNING: be carefull about the order when reading the restart
+        !   !!gm  this warning should be obsolet with IOM
+   INTEGER, PUBLIC, PARAMETER ::   jpdic = jp_l +  1    !: dissolved inoganic carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jptal = jp_l +  2    !: total alkalinity 
+   INTEGER, PUBLIC, PARAMETER ::   jpoxy = jp_l +  3    !: oxygen carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpcal = jp_l +  4    !: calcite  concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jppo4 = jp_l +  5    !: phosphate concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jppoc = jp_l +  6    !: small particulate organic phosphate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsil = jp_l +  7    !: silicate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphy = jp_l +  8    !: phytoplancton concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpzoo = jp_l +  9    !: zooplancton concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdoc = jp_l + 10    !: dissolved organic carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpdia = jp_l + 11    !: Diatoms Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpmes = jp_l + 12    !: Mesozooplankton Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpbsi = jp_l + 13    !: (big) Silicate Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpfer = jp_l + 14    !: Iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnum = jp_l + 15    !: Big iron particles Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsfe = jp_l + 16    !: number of particulate organic phosphate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdfe = jp_l + 17    !: Diatoms iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdsi = jp_l + 18    !: Diatoms Silicate Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnfe = jp_l + 19    !: Nano iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnch = jp_l + 20    !: Nano Chlorophyll Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdch = jp_l + 21    !: Diatoms Chlorophyll Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpno3 = jp_l + 22    !: Nitrates Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnh4 = jp_l + 23    !: Ammonium Concentration
+
+#elif defined key_pisces
+   !!---------------------------------------------------------------------
+   !!   'key_pisces'   :                         standard PISCES bio-model
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_pisces     = .TRUE.  !: PISCES flag 
+   LOGICAL, PUBLIC, PARAMETER ::   lk_kriest     = .FALSE. !: Kriest flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces     = 24      !: number of PISCES passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_2d  = 13      !: additional 2d output ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_3d  = 11      !: additional 3d output ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_trd =  1      !: number of sms trends for PISCES
+
+   ! assign an index in trc arrays for each LOBSTER prognostic variables
+   !    WARNING: be carefull about the order when reading the restart
+        !   !!gm  this warning should be obsolet with IOM
+   INTEGER, PUBLIC, PARAMETER ::   jpdic = jp_l +  1    !: dissolved inoganic carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jptal = jp_l +  2    !: total alkalinity 
+   INTEGER, PUBLIC, PARAMETER ::   jpoxy = jp_l +  3    !: oxygen carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpcal = jp_l +  4    !: calcite  concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jppo4 = jp_l +  5    !: phosphate concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jppoc = jp_l +  6    !: small particulate organic phosphate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsil = jp_l +  7    !: silicate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphy = jp_l +  8    !: phytoplancton concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpzoo = jp_l +  9    !: zooplancton concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdoc = jp_l + 10    !: dissolved organic carbon concentration 
+   INTEGER, PUBLIC, PARAMETER ::   jpdia = jp_l + 11    !: Diatoms Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpmes = jp_l + 12    !: Mesozooplankton Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpbsi = jp_l + 13    !: (big) Silicate Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpfer = jp_l + 14    !: Iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpbfe = jp_l + 15    !: Big iron particles Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpgoc = jp_l + 16    !: big particulate organic phosphate concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsfe = jp_l + 17    !: Small iron particles Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdfe = jp_l + 18    !: Diatoms iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdsi = jp_l + 19    !: Diatoms Silicate Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnfe = jp_l + 20    !: Nano iron Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnch = jp_l + 21    !: Nano Chlorophyll Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdch = jp_l + 22    !: Diatoms Chlorophyll Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpno3 = jp_l + 23    !: Nitrates Concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpnh4 = jp_l + 24    !: Ammonium Concentration
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                                   No CFC geochemical model
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_pisces     = .FALSE.  !: CFC flag 
+   LOGICAL, PUBLIC, PARAMETER ::   lk_kriest     = .FALSE.  !: Kriest flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces     =  0       !: No CFC tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_2d  =  0       !: No CFC additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_3d  =  0       !: No CFC additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_pisces_trd =  0       !: number of sms trends for PISCES
+#endif
+
+   ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_pcs0 = jp_l + 1           !: First index of CFC passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_pcs1 = jp_l + jp_pisces   !: Last  index of CFC passive tracers
+
+   !!======================================================================
+END MODULE par_pisces
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/sms_pisces.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/sms_pisces.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/sms_pisces.h90	(revision 4536)
@@ -0,0 +1,114 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  sms_pisces.h90  ***  
+   !! TOP :   PISCES Source Minus Sink valiables
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2000-02 (O. Aumont) original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! Variable for chemistry of the CO2 cycle
+   !! ---------------------------------------------------------------------
+   REAL(wp) ::   atcco2
+   !
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   akb3, ak13, ak23, aksp, akw3             !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   hi, borat                                !: ???
+   REAL, DIMENSION(2) :: qcumul
+
+   !!----------------------------------------------------------------------
+   !!  Variable for chemistry of the CO2 cycle
+   !! ---------------------------------------------------------------------
+   !
+   REAL(wp), DIMENSION(jpi,jpj,2) ::   chemc   !: ???
+
+   !!----------------------------------------------------------------------
+   !!  Variable for chemistry of Fe and SIO3
+   !! ---------------------------------------------------------------------
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   sio3eq   !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   fekeq    !: ???
+
+   !!----------------------------------------------------------------------
+   !!  Time variables
+   !! ---------------------------------------------------------------------
+   INTEGER  ::   iabsyr, nrdttrc, ndayflxtr       !: ???
+   REAL(wp) ::   tspyr, absyr, xtvit              !: ???
+   REAL(wp) ::   rfact, rfactr, rfact2, rfact2r   !: ???
+
+
+   !!----------------------------------------------------------------------
+   !!  Gas exchange
+   !! ---------------------------------------------------------------------
+   REAL(wp), DIMENSION(jpi,jpj) ::   strn         !: ???
+   
+   !!---------------------------------------
+   !!  Biological parameters 
+   !! --------------------------------------
+   INTEGER ::   jkopt    !: ???
+   !
+   REAL(wp) ::   caco3r, kdca, nca, part, rno3, o2ut, po4r               !: ???
+   REAL(wp) ::   sco2, dispo0, conc0,sumdepsi,rivalkinput,sedfeinput     !: ???
+   REAL(wp) ::   rivpo4input,nitdepinput,oxymin,spocri           !: ???
+   REAL(wp) ::   nitrif,rdenit,o2nit,concnnh4,concdnh4                   !: ???
+   REAL(wp) ::   pislope,excret,wsbio,resrat,mprat,wchl,wchld            !: ???
+   REAL(wp) ::   mzrat,grazrat,xprefc,xprefp,unass,xkgraz,xkmort         !: ???
+   REAL(wp) ::   xksi1,xksi2,sicmax,xremik,xremip,xkdoc1                 !: ???
+   REAL(wp) ::   xkdoc2,grosip,resrat2,excret2,mprat2,mzrat2,xprefz      !: ???
+   REAL(wp) ::   xkgraz2,grazrat2,xlam1,conc1,conc2,conc3                !: ???
+   REAL(wp) ::   unass2,xprefpoc,epsher,epsher2,pislope2,mpratm          !: ???
+   REAL(wp) ::   sigma1, sigma2, zprefc, zprefp, zprefd, wchl2, ferat3   !: ???
+   REAL(wp) ::   xsirem, fecnm, fecdm, chlcnm, chlcdm                    !: ???
+
+   !!---------------------------------------------
+   !!  Biological fluxes for light
+   !!---------------------------------------------
+   REAL(wp), DIMENSION(3,61)        ::   xkrgb                 !: ???
+   REAL(wp), DIMENSION(jpi,jpj)     ::   heup                  !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   etot, etot3, emoy     !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   enano, ediat
+
+!!----------------------------------------------------------
+!!  Biological fluxes for primary production
+!!----------------------------------------------------------
+   REAL(wp), DIMENSION(jpi,jpj) ::   xksimax, xksi
+   !
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   prmax, tgfunc, tgfunc2                       !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   xnanono3, xdiatno3, xnanonh4, xdiatnh4       !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   xlimphy, xlimdia, concdfe, concnfe, xnegtr   !: ???
+
+   !!---------------------------------------------
+   !!  SMS for the organic matter
+   !!---------------------------------------------
+   REAL(wp) ::   wsbio2
+   !
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   xdiss, xfracal, nitrfac, xlimbac                  !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   wsbio4, wsbio3, wscal                             !: ???
+
+   !!---------------------------------------------------------
+   !! External sources of nutrients in ocean
+   !!---------------------------------------------------------
+   LOGICAL ::   bdustfer, briver, bndepo, bsedinput   !: ???
+   !
+   REAL(wp) ::   areacot                              !: ???
+   !
+   REAL(wp), DIMENSION(jpi,jpj)     ::   dust, cotdep, nitdep, rivinp   !: ???
+   REAL(wp), DIMENSION(jpi,jpj,12)  ::   dustmo                         !: ???
+   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   denitr, ironsed         !: ???
+
+#if defined key_kriest
+   !!---------------------------------------------------------
+   !!  Kriest parameter for aggregation
+   !!---------------------------------------------------------
+   REAL(wp) ::   xkr_eta, xkr_zeta, xkr_sfact, xkr_stick            !: ???
+   REAL(wp) ::   xkr_mass_min, xkr_mass_max, xkr_massp, xkr_frac    !: ???
+   REAL(wp) ::   xkr_dnano, xkr_ddiat, xkr_dmeso, xkr_daggr         !: ???
+   REAL(wp) ::   xkr_nnano, xkr_ndiat, xkr_nmeso, xkr_naggr         !: ???
+   REAL(wp) ::   xkr_wsbio_min, xkr_wsbio_max
+   !  
+   REAL(wp), DIMENSION(jpk) ::   xnumm      !: ???
+#endif
+
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcctl.pisces.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcctl.pisces.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcctl.pisces.h90	(revision 4536)
@@ -0,0 +1,33 @@
+   !!======================================================================
+   !!                         ***  trcctl.cfc.h90  ***
+   !! TOP :   Control of CFC chemical model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2005-10 (C. Ethe) assign a parameter to name individual tracers
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' use PISCES biological model '
+
+   ! Check number of tracers
+   ! -----------------------
+#if  defined key_kriest
+      IF( jp_pisces /= 23) THEN 
+#else
+      IF( jp_pisces /= 24) THEN
+#endif
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : w a r n i n g '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                               &
+              &   ' STOP, change jp_pisces',               & 
+              &   ' in parameter.passivetrc.pisces.h '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+      
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcini_pisces.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcini_pisces.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trcini_pisces.F90	(revision 4536)
@@ -0,0 +1,331 @@
+MODULE trcini_pisces
+   !!======================================================================
+   !!                         ***  MODULE trcini_pisces  ***
+   !! TOP :   initialisation of the PISCES biochemical model
+   !!======================================================================
+   !! History :    -   !  1988-07  (E. Maier-Reiner) Original code
+   !!              -   !  1999-10  (O. Aumont, C. Le Quere)
+   !!              -   !  2002     (O. Aumont)  PISCES
+   !!             1.0  !  2005-03  (O. Aumont, A. El Moussaoui) F90
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec) from trcini.pisces.h90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !! trc_ini_pisces   : PISCES biochemical model initialisation
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE trccfc          ! CFC sms trends
+   USE sms             ! Source Minus Sink variables
+   USE oce_trc         ! ocean variables
+   USE trp_trc         !
+   USE p4zche 
+   USE lbclnk
+
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_pisces   ! called by trcini.F90 module
+
+
+#  include "domzgr_substitute.h90"
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_pisces
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_ini_pisces ***
+      !!
+      !! ** Purpose :   Initialisation of the PISCES biochemical model
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jk, jm
+      INTEGER ::   ichl, iband
+      INTEGER , PARAMETER ::   jpmois = 12, jpan = 1 
+
+      REAL(wp) ::   zcoef
+      REAL(wp) ::   ztoto, expide, denitide,zmaskt
+      REAL(wp) , DIMENSION (jpi,jpj)     ::   riverdoc, river, ndepo
+      REAL(wp) , DIMENSION (jpi,jpj,jpk) ::   cmask
+
+      INTEGER :: numriv, numdust, numbath, numdep
+      INTEGER :: numlight 
+
+#if defined key_kriest
+      INTEGER  ::   jn, kiter
+      REAL(wp) ::   znum, zdiv
+      REAL(wp) ::   zws, zwr, zwl,wmax, xnummax
+      REAL(wp) ::   zmin, zmax, zl, zr, xacc
+#endif
+      !!----------------------------------------------------------------------
+
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_pisces :   PISCES biochemical model initialisation'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+
+      !                                            ! Time-step
+      rfact   = rdttra(1) * float(ndttrc)          ! ---------
+      rfactr  = 1. / rfact
+      rfact2  = rfact / float(nrdttrc)
+      rfact2r = 1. / rfact2
+
+      IF(lwp) WRITE(numout,*) '    Tracer  time step    rfact  = ', rfact, ' rdt = ', rdt
+      IF(lwp) write(numout,*) '    Biology time step    rfact2 = ', rfact2
+
+
+      !                                            ! Dust input from the atmosphere
+      IF( bdustfer ) THEN                          ! ------------------------------
+         IF(lwp) WRITE(numout,*) '    Initialize dust input from atmosphere '
+         CALL iom_open ( 'dust.orca.nc', numdust )
+         DO jm = 1, jpmois
+            CALL iom_get( numdust, jpdom_data, 'dust', dustmo(:,:,jm), jm )
+         END DO
+         CALL iom_close( numdust )
+      ELSE
+         dustmo(:,:,:) = 0.e0
+      ENDIF
+
+
+      !                                            ! Nutrient input from rivers
+      IF( briver ) THEN                            ! --------------------------
+         IF(lwp) WRITE(numout,*) '    Initialize the nutrient input by rivers from river.orca.nc file'
+         CALL iom_open ( 'river.orca.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'riverdic', river   (:,:), jpan )
+         CALL iom_get  ( numriv, jpdom_data, 'riverdoc', riverdoc(:,:), jpan )
+         CALL iom_close( numriv )
+      ELSE
+         river   (:,:) = 0.e0
+         riverdoc(:,:) = 0.e0
+      endif
+
+      !                                            ! Nutrient input from dust
+      IF( bndepo ) THEN                            ! ------------------------
+         IF(lwp) WRITE(numout,*) '    Initialize the nutrient input by dust from ndeposition.orca.nc'
+         CALL iom_open ( 'ndeposition.orca.nc', numdep )
+         CALL iom_get  ( numdep, jpdom_data, 'ndep', ndepo(:,:), jpan )
+         CALL iom_close( numdep )
+      ELSE
+         ndepo(:,:) = 0.e0
+      ENDIF
+
+      !                                            ! Coastal and island masks
+      IF( bsedinput ) THEN                         ! ------------------------
+         IF(lwp) WRITE(numout,*) '    Computation of an island mask to enhance coastal supply of iron '
+         IF(lwp) WRITE(numout,*) '       from bathy.orca.nc file '
+         CALL iom_open ( 'bathy.orca.nc', numbath )
+         CALL iom_get  ( numbath, jpdom_data, 'bathy', cmask(:,:,:), jpan )
+         CALL iom_close( numbath )
+         !
+         DO jk = 1, 5
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  IF( tmask(ji,jj,jk) /= 0. ) THEN
+                     zmaskt = tmask(ji+1,jj,jk) * tmask(ji-1,jj,jk) * tmask(ji,jj+1,jk)    &
+                        &                       * tmask(ji,jj-1,jk) * tmask(ji,jj,jk+1)
+                     IF( zmaskt == 0. )   cmask(ji,jj,jk ) = 0.1
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  expide   = MIN( 8.,( fsdept(ji,jj,jk) / 500. )**(-1.5) )
+                  denitide = -0.9543 + 0.7662 * LOG( expide ) - 0.235 * LOG( expide )**2
+                  cmask(ji,jj,jk) = cmask(ji,jj,jk) * MIN( 1., EXP( denitide ) / 0.5 )
+               END DO
+            END DO
+         END DO    
+      ELSE
+         cmask(:,:,:) = 0.e0
+      ENDIF
+
+      CALL lbc_lnk( cmask , 'T', 1. )      ! Lateral boundary conditions on cmask   (sign unchanged)
+
+
+      !                                            ! total atmospheric supply of Si
+      !                                            ! ------------------------------
+      sumdepsi = 0.e0
+      DO jm = 1, jpmois
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               sumdepsi = sumdepsi + dustmo(ji,jj,jm) / (12.*rmoss) * 8.8        &
+                  &     * 0.075/28.1 * e1t(ji,jj) * e2t(ji,jj) * tmask(ji,jj,1) * tmask_i(ji,jj)
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( sumdepsi )  ! sum over the global domain
+
+      !                                            ! N/P and Si releases due to coastal rivers
+      !                                            ! -----------------------------------------
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zcoef = raass * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1)
+            cotdep(ji,jj) =  river(ji,jj)                  *1E9 / ( 12. * zcoef + rtrn ) * tmask(ji,jj,1)
+            rivinp(ji,jj) = (river(ji,jj)+riverdoc(ji,jj)) *1E9 / ( 31.6* zcoef + rtrn ) * tmask(ji,jj,1)
+            nitdep(ji,jj) = 7.6 * ndepo(ji,jj)                  / ( 14E6*raass*fse3t(ji,jj,1) + rtrn ) * tmask(ji,jj,1)
+         END DO
+      END DO
+      ! Lateral boundary conditions on ( cotdep, rivinp, nitdep )   (sign unchanged)
+      CALL lbc_lnk( cotdep , 'T', 1. )  ;  CALL lbc_lnk( rivinp , 'T', 1. )  ;  CALL lbc_lnk( nitdep , 'T', 1. )
+
+      rivpo4input=0.e0
+      rivalkinput=0.e0
+      nitdepinput=0.e0
+      DO jj = 2 , jpjm1
+         DO ji = 2, jpim1
+            zcoef = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,1) * tmask(ji,jj,1) * tmask_i(ji,jj) * raass
+            rivpo4input = rivpo4input + rivinp(ji,jj) * zcoef
+            rivalkinput = rivalkinput + cotdep(ji,jj) * zcoef
+            nitdepinput = nitdepinput + nitdep(ji,jj) * zcoef
+         END DO
+      END DO
+      IF( lk_mpp ) THEN
+         CALL mpp_sum( rivpo4input )  ! sum over the global domain
+         CALL mpp_sum( rivalkinput )  ! sum over the global domain
+         CALL mpp_sum( nitdepinput )  ! sum over the global domain
+      ENDIF
+
+
+      !                                            !    Coastal supply of iron
+      !                                            ! -------------------------
+      DO jk = 1, jpkm1
+         ironsed(:,:,jk) = sedfeinput * cmask(:,:,jk) / ( fse3t(:,:,jk) * rjjss )
+      END DO
+      CALL lbc_lnk( ironsed , 'T', 1. )      ! Lateral boundary conditions on ( ironsed )   (sign unchanged)
+
+
+
+#if defined key_kriest
+      !!---------------------------------------------------------------------
+      !!    'key_kriest'                                                  ???
+      !!---------------------------------------------------------------------
+      !  COMPUTATION OF THE VERTICAL PROFILE OF MAXIMUM SINKING SPEED
+      !  Search of the maximum number of particles in aggregates for each k-level.  
+      !  Bissection Method
+      !--------------------------------------------------------------------
+      WRITE(numout,*)
+      WRITE(numout,*)'    kriest : Compute maximum number of particles in aggregates'
+            
+      xacc     =  0.001
+      kiter    = 50
+      zmin     =  1.10
+      zmax     = xkr_mass_max / xkr_mass_min
+      xkr_frac = zmax
+
+      DO jk =1,jpk
+         zl = zmin
+         zr = zmax
+         wmax = 0.5 * fse3t(1,1,jk) * rjjss / rfact2
+         zdiv = xkr_zeta + xkr_eta - xkr_eta * zl
+         znum = zl - 1.
+         zwl =  xkr_wsbio_min * xkr_zeta / zdiv &
+            & - ( xkr_wsbio_max * xkr_eta * znum * &
+            &     xkr_frac**( -xkr_zeta / znum ) / zdiv ) &
+            & - wmax
+  
+         zdiv = xkr_zeta + xkr_eta - xkr_eta * zr
+         znum = zr - 1.
+         zwr =  xkr_wsbio_min * xkr_zeta / zdiv &
+            & - ( xkr_wsbio_max * xkr_eta * znum * &
+            &     xkr_frac**( -xkr_zeta / znum ) / zdiv ) &
+            & - wmax
+
+iflag:  DO jn = 1, kiter               
+           IF( zwl == 0.e0 ) THEN
+              xnummax = zl
+           ELSE IF ( zwr == 0.e0 ) THEN
+              xnummax = zr
+           ELSE
+              xnummax = ( zr + zl ) / 2.
+              zdiv = xkr_zeta + xkr_eta - xkr_eta * xnummax
+              znum = xnummax - 1.
+              zws =  xkr_wsbio_min * xkr_zeta / zdiv &
+                 & - ( xkr_wsbio_max * xkr_eta * znum * &
+                 &     xkr_frac**( -xkr_zeta / znum ) / zdiv ) &
+                 & - wmax
+              IF( zws * zwl < 0. ) THEN
+                 zr = xnummax
+              ELSE
+                 zl = xnummax
+              ENDIF
+              zdiv = xkr_zeta + xkr_eta - xkr_eta * zl
+              znum = zl - 1.
+              zwl =  xkr_wsbio_min * xkr_zeta / zdiv &
+                 & - ( xkr_wsbio_max * xkr_eta * znum * &
+                 &     xkr_frac**( -xkr_zeta / znum ) / zdiv ) &
+                 & - wmax
+              
+              zdiv = xkr_zeta + xkr_eta - xkr_eta * zr
+              znum = zr - 1.
+              zwr =  xkr_wsbio_min * xkr_zeta / zdiv &
+                 & - ( xkr_wsbio_max * xkr_eta * znum * &
+                 &     xkr_frac**( -xkr_zeta / znum ) / zdiv ) &
+                 & - wmax
+
+              IF ( ABS ( zws )  <= xacc ) EXIT iflag
+
+           ENDIF
+                    
+        END DO iflag
+               
+        xnumm(jk) = xnummax
+        WRITE(numout,*) '       jk = ', jk, ' wmax = ', wmax,' xnum max = ', xnumm(jk)
+        
+     END DO
+
+#endif
+
+      !----------------------------------------------------------------------
+      ! Initialize biological variables 
+      !----------------------------------------------------------------------
+      ! Set biological ratios
+      ! ---------------------
+      rno3   = (16.+2.) / 122.
+      po4r   =   1.e0   / 122.
+      o2nit  =  32.     / 122.
+      rdenit =  97.6    /  16.
+      o2ut   = 140.     / 122.
+
+      !  FROM THE NEW BIOOPTIC MODEL PROPOSED JM ANDRE, WE READ HERE
+      !  A PRECOMPUTED ARRAY CORRESPONDING TO THE ATTENUATION COEFFICIENT
+
+      CALL ctlopn( numlight, 'kRGB61.txt', 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .TRUE., 1 )
+      DO ichl = 1,61
+         READ(numlight,*) ztoto, ( xkrgb(iband,ichl), iband = 1,3 )
+      END DO
+      CLOSE(numlight)
+
+
+      CALL p4z_che        ! initialize the chemical constants
+
+
+      ndayflxtr = 0      !  Initialize a counter for the computation of chemistry
+
+
+      IF(lwp) WRITE(numout,*) ' Initialisation of PISCES done'
+      !
+   END SUBROUTINE trc_ini_pisces
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                            No PISCES biochemical model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_pisces             ! Empty routine
+   END SUBROUTINE trc_ini_pisces
+#endif
+
+   !!======================================================================
+END MODULE trcini_pisces
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trclsm_pisces.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trclsm_pisces.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/PISCES/trclsm_pisces.F90	(revision 4536)
@@ -0,0 +1,232 @@
+MODULE trclsm_pisces
+   !!======================================================================
+   !!                      ***  MODULE trclsm_lobster  ***
+   !! TOP :   initialisation of some run parameters for PISCES bio-model
+   !!======================================================================
+   !! History :    -   !  1999-10 (M.A. Foujols, M. Levy) original code
+   !!              -   !  2000-01 (L. Bopp) hamocc3, p3zd
+   !!             1.0  !  2003-08 (C. Ethe)  module F90
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec) from trclsm.pisces.h90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'   :                                   PISCES bio-model
+   !!----------------------------------------------------------------------
+   !! trc_lsm_pisces       : PISCES model namelist read
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms             ! sms trends
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_lsm_pisces   ! called by trclsm.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lsm_pisces
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_lsm_pisces  ***  
+      !!
+      !! ** Purpose :   read PISCES namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natext, natbio, natsms
+      !!                       natkriest ("key_kriest")
+      !!----------------------------------------------------------------------
+      CHARACTER (len=32) ::   clname
+      !!
+      NAMELIST/natext/ atcco2
+      NAMELIST/natbio/ caco3r, kdca, nca, part,                               &
+         &             dispo0,conc0,oxymin,grosip, nrdttrc,                   &
+         &             pislope, excret,wsbio,wchl,wchld,resrat,mprat,mzrat,   &
+         &             grazrat,xprefc,xprefp,unass,xkgraz,xkmort,xksi1,       &
+         &             xksi2,xremip,xremik,xsirem,xkdoc1,xkdoc2,              &
+         &             excret2,resrat2,mprat2,mpratm,mzrat2,grazrat2,         &
+         &             xprefz, xprefpoc, unass2, xkgraz2, xlam1,              &
+         &             ferat3,conc1,conc2,conc3,concnnh4,concdnh4,            &
+         &             nitrif,epsher,epsher2,pislope2,wsbio2,sigma1,          &
+         &             sigma2, zprefc, zprefp, zprefd,fecnm,fecdm,            &
+         &             chlcnm,chlcdm, sedfeinput
+      NAMELIST/natsms/bdustfer, briver, bndepo, bsedinput
+#if defined key_kriest
+      NAMELIST/natkriest/ xkr_eta  , xkr_zeta , xkr_sfact, xkr_mass_min, xkr_mass_max,   &
+         &                xkr_dnano, xkr_ddiat, xkr_dmeso, xkr_daggr   , xkr_stick
+#endif
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_lsm_pisces : read PISCES namelists'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+
+      !                               ! Open the namelist file
+      !                               ! ----------------------
+      clname ='namelist.trc.sms'
+      CALL ctlopn( numnat, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &           1, numout, .FALSE., 1 )
+
+      !                               ! natext : Atmospheric parameters
+      !                               ! -------------------- ----------
+      REWIND( numnat )                     ! read natext
+      READ  ( numnat, natext )
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : natext'
+         WRITE(numout,*) '    atmospheric pCO2                         atcco2 = ',atcco2
+      ENDIF
+
+
+      !                               ! natbio : biological parameters
+      !                               ! ------------------------------
+      REWIND( numnat )                     ! read natbio
+      READ  ( numnat, natbio )
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) ' Namelist : natbio'
+         WRITE(numout,*) '    mean rainratio                            caco3r    =', caco3r
+         WRITE(numout,*) '    diss. rate constant calcite (per month)   kdca      =', kdca
+         WRITE(numout,*) '    order of reaction for calcite dissolution nca       =', nca
+         WRITE(numout,*) '    part of calcite not dissolved in guts     part      =', part
+         WRITE(numout,*) '    mean Si/C ratio                           grosip    =', grosip
+         WRITE(numout,*) '    Calcite dissolution half saturation       dispo0    =', dispo0
+         WRITE(numout,*) '    Phosphate half saturation                 conc0     =', conc0
+         WRITE(numout,*) '    frequence pour la biologie                nrdttrc   =', nrdttrc
+         WRITE(numout,*) '    P-I slope                                 pislope   =', pislope
+         WRITE(numout,*) '    excretion ratio of phytoplankton          excret    =', excret
+         WRITE(numout,*) '    POC sinking speed                         wsbio     =', wsbio
+         WRITE(numout,*) '    quadratic mortality of phytoplankton      wchl      =', wchl
+         WRITE(numout,*) '    maximum quadratic mortality of diatoms    wchld     =', wchld
+         WRITE(numout,*) '    exsudation rate of zooplankton            resrat    =', resrat
+         WRITE(numout,*) '    phytoplankton mortality rate              mprat     =', mprat
+         WRITE(numout,*) '    zooplankton mortality rate                mzrat     =', mzrat
+         WRITE(numout,*) '    zoo preference for phyto                  xprefc    =', xprefc
+         WRITE(numout,*) '    zoo preference for POC                    xprefp    =', xprefp
+         WRITE(numout,*) '    maximal zoo grazing rate                  grazrat   =', grazrat
+         WRITE(numout,*) '    non assimilated fraction of phyto by zoo  unass     =', unass
+         WRITE(numout,*) '    half sturation constant for grazing       xkgraz    =', xkgraz
+         WRITE(numout,*) '    half saturation constant for mortality    xkmort    =', xkmort
+         WRITE(numout,*) '    half saturation constant for Si uptake    xksi1     =', xksi1
+         WRITE(numout,*) '    half saturation constant for Si/C         xksi2     =', xksi2
+         WRITE(numout,*) '    remineralisation rate of POC              xremip    =', xremip
+         WRITE(numout,*) '    remineralization rate of DOC              xremik    =', xremik
+         WRITE(numout,*) '    remineralization rate of Si               xsirem    =', xsirem 
+         WRITE(numout,*) '    1st half-sat. of DOC remineralization     xkdoc1    =', xkdoc1
+         WRITE(numout,*) '    2nd half-sat. of DOC remineralization     xkdoc2    =', xkdoc2
+         WRITE(numout,*) '    excretion ratio of diatoms                excret2   =', excret2
+         WRITE(numout,*) '    exsudation rate of mesozooplankton        resrat2   =', resrat2
+         WRITE(numout,*) '    Diatoms mortality rate                    mprat2    =', mprat2
+         WRITE(numout,*) '    Phytoplankton minimum mortality rate      mpratm    =', mpratm
+         WRITE(numout,*) '    mesozooplankton mortality rate            mzrat2    =', mzrat2
+         WRITE(numout,*) '    zoo preference for zoo                    xprefz    =', xprefz
+         WRITE(numout,*) '    zoo preference for poc                    xprefpoc  =', xprefpoc
+         WRITE(numout,*) '    maximal mesozoo grazing rate              grazrat2  =', grazrat2
+         WRITE(numout,*) '    non assimilated fraction of P by mesozoo  unass2    =', unass2
+         WRITE(numout,*) '    Efficicency of Mesozoo growth             epsher2   =', epsher2 
+         WRITE(numout,*) '    Efficiency of microzoo growth             epsher    =', epsher
+         WRITE(numout,*) '    half sturation constant for grazing 2     xkgraz2   =', xkgraz2
+         WRITE(numout,*) '    Maximum aggregation rate for diatoms      wchld     =', wchld
+         WRITE(numout,*) '    scavenging rate of Iron                   xlam1     =', xlam1
+         WRITE(numout,*) '    Fe/C in zooplankton                       ferat3    =', ferat3
+         WRITE(numout,*) '    Phosphate half saturation for diatoms     conc1     =', conc1
+         WRITE(numout,*) '    Iron half saturation for phyto            conc2     =', conc2
+         WRITE(numout,*) '    Iron half saturation for diatoms          conc3     =', conc3
+         WRITE(numout,*) '    NH4 half saturation for phyto             concnnh4  =', concnnh4
+         WRITE(numout,*) '    NH4 half saturation for diatoms           concdnh4  =', concdnh4
+         WRITE(numout,*) '    NH4 nitrification rate                    nitrif    =', nitrif
+         WRITE(numout,*) '    P-I slope  for diatoms                    pislope2  =', pislope2
+         WRITE(numout,*) '    Big particles sinking speed               wsbio2    =', wsbio2
+         WRITE(numout,*) '    Fraction of microzoo excretion as DOM     sigma1    =', sigma1
+         WRITE(numout,*) '    Fraction of mesozoo excretion as DOM      sigma2    =', sigma2
+         WRITE(numout,*) '    Microzoo preference for POM               zprefc    =', zprefc
+         WRITE(numout,*) '    Microzoo preference for Nanophyto         zprefp    =', zprefp
+         WRITE(numout,*) '    Microzoo preference for Diatoms           zprefd    =', zprefd
+         WRITE(numout,*) '    Minimum Chl/C in nanophytoplankton        chlcnm    =', chlcnm
+         WRITE(numout,*) '    Minimum Chl/C in diatoms                  chlcdm    =', chlcdm
+         WRITE(numout,*) '    Maximum Fe/C in nanophytoplankton         fecnm     =', fecnm
+         WRITE(numout,*) '    Minimum Fe/C in diatoms                   fecdm     =', fecdm
+         WRITE(numout,*) '    Coastal release of Iron                   sedfeinput=', sedfeinput
+      ENDIF
+
+      !                               ! natsms : SMS parameters
+      !                               ! -----------------------
+      REWIND( numnat )                     ! read natsms
+      READ  ( numnat, natsms )
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' Namelist : natsms'
+         WRITE(numout,*) '    Dust input from the atmosphere           bdustfer  = ', bdustfer
+         WRITE(numout,*) '    River input of nutrients                 briver    = ', briver
+         WRITE(numout,*) '    Atmospheric deposition of N              bndepo    = ', bndepo
+         WRITE(numout,*) '    Fe input from sediments                  bsedinput = ', bsedinput
+      ENDIF
+
+#if defined key_kriest
+
+      !                               ! natkriest : kriest parameters
+      !                               ! -----------------------------
+      REWIND( numnat )                     ! read natkriest
+      READ  ( numnat, natkriest )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : natkriest'
+         WRITE(numout,*) '    Sinking  exponent                        xkr_eta      = ', xkr_eta 
+         WRITE(numout,*) '    N content exponent                       xkr_zeta     = ', xkr_zeta
+         WRITE(numout,*) '    Sinking factor                           xkr_sfact    = ', xkr_sfact
+         WRITE(numout,*) '    Stickiness                               xkr_stick    = ', xkr_stick
+         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,*) '    Size of particles in nano pool           xkr_dnano    = ', xkr_dnano
+         WRITE(numout,*) '    Size of particles in diatoms pool        xkr_ddiat    = ', xkr_ddiat
+         WRITE(numout,*) '    Size of particles in mesozoo pool        xkr_dmeso    = ', xkr_dmeso
+         WRITE(numout,*) '    Size of particles in aggregates pool     xkr_daggr    = ', xkr_daggr
+     ENDIF
+
+
+     ! Computation of some variables
+     xkr_massp = 5.7E-6 * 7.6 * xkr_mass_min**xkr_zeta
+     
+     ! max and min vertical particle speed
+     xkr_wsbio_min = xkr_sfact * xkr_mass_min**xkr_eta
+     xkr_wsbio_max = xkr_sfact * xkr_mass_max**xkr_eta
+     WRITE(numout,*) ' max and min vertical particle speed ', xkr_wsbio_min, xkr_wsbio_max
+     
+     !
+     !    effect of the sizes of the different living pools on particle numbers
+     !    nano = 2um-20um -> mean size=6.32 um -> ws=2.596 -> xnum=xnnano=2.337
+     !    diat and microzoo = 10um-200um -> 44.7 -> 8.732 -> xnum=xndiat=3.718
+     !    mesozoo = 200um-2mm -> 632.45 -> 45.14 -> xnum=xnmeso=7.147
+     !    aggregates = 200um-10mm -> 1414 -> 74.34 -> xnum=xnaggr=9.877
+     !    doc aggregates = 1um
+     ! ----------------------------------------------------------
+
+     xkr_nnano = 1. / ( xkr_massp * xkr_dnano )
+     xkr_ndiat = 1. / ( xkr_massp * xkr_ddiat )
+     xkr_nmeso = 1. / ( xkr_massp * xkr_dmeso )
+     xkr_naggr = 1. / ( xkr_massp * xkr_daggr )
+    
+#endif
+      !
+   END SUBROUTINE trc_lsm_pisces
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                   No PISCES bio-model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lsm_pisces                      ! Empty routine
+   END  SUBROUTINE  trc_lsm_pisces
+#endif  
+
+   !!======================================================================
+END MODULE trclsm_pisces
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_cen2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_cen2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_cen2.F90	(revision 4536)
@@ -0,0 +1,346 @@
+MODULE trcadv_cen2
+   !!======================================================================
+   !!                       ***  MODULE  trcadv_cen2  ***
+   !! Ocean passive tracers:  horizontal & vertical advective tracer trend
+   !!======================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_adv_cen2 : update the tracer trend with the horizontal
+   !!                  and vertical advection trends using a 2nd order 
+   !!                  centered finite difference scheme
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE trcbbl              ! advective passive tracers in the BBL
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_adv_cen2    ! routine called by trcstp.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   !!----------------------------------------------------------------------
+   !!   Default option :             2nd order centered scheme (k-j-i loop)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE trc_adv_cen2( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_adv_cen2  ***
+      !!                 
+      !! ** Purpose :   Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method  :   The advection is evaluated by a second order centered
+      !!      scheme using now fields (leap-frog scheme). In specific areas
+      !!      (vicinity of major river mouths, some straits, or where tn is
+      !!      is approaching the freezing point) it is mixed with an upstream
+      !!      scheme for stability reasons.
+      !!        Part 0 : compute the upstream / centered flag
+      !!                 (3D array, zind, defined at T-point (0<zind<1))
+      !!        Part I : horizontal advection
+      !!      * centered flux:
+      !!         * s-coordinate (ln_sco=T) or
+      !!         * z-coordinate with partial steps (ln_zps=T),
+      !!        the vertical scale factors e3. are inside the derivatives:
+      !!               zcenu = e2u*e3u  un  mi(tn)
+      !!               zcenv = e1v*e3v  vn  mj(tn)
+      !!         * z-coordinate (default key), e3t=e3u=e3v:
+      !!               zcenu = e2u  un  mi(tn)
+      !!               zcenv = e1v  vn  mj(tn)
+      !!      * horizontal advective trend (divergence of the fluxes)
+      !!         * s-coordinate (ln_sco=T) or
+      !!         * z-coordinate with partial steps (ln_zps=T)
+      !!               ztra = 1/(e1t*e2t*e3t) { di-1[zwx] + dj-1[zwy] }
+      !!         * z-coordinate (default key), e3t=e3u=e3v:
+      !!               ztra = 1/(e1t*e2t) { di-1[zwx] + dj-1[zwy] }
+      !!      * Add this trend now to the general trend of tracer tra:
+      !!              tra = tra + ztra
+      !!      * trend diagnostic ('key_trc_diatrd'): the trend is saved
+      !!      for diagnostics. The trends saved is expressed as
+      !!      Uh.gradh(T)
+      !!
+      !!         Part II : vertical advection
+      !!      For any tracer  the advective trend is computed as follows :
+      !!            ztra = 1/e3t dk+1[ zwz ]
+      !!      where the vertical advective flux, zwz, is given by :
+      !!            zwz = zcofk * zupst + (1-zcofk) * zcent
+      !!      with 
+      !!        zupsv = upstream flux = wn * (trb(k) or trb(k-1) ) [wn>0 or <0]
+      !!        zcenu = centered flux = wn * mk(trn)
+      !!         The surface boundary condition is : 
+      !!      rigid-lid (default option) : zero advective flux
+      !!      free-surf ("key_fresurf_cstvol") : wn(:,:,1) * trn(:,:,1)
+      !!         Add this trend now to the general trend of tracer tra :
+      !!            tra = tra + ztra
+      !!         Trend diagnostic ('key_trc_diatrd'): the trend is saved for
+      !!      diagnostics. The trends saved is expressed as :
+      !!             save trend =  w.gradz(T) = ztra - trn divn.
+      !!
+      !! ** Action : - update tra with the now advective tracer trends
+      !!             - save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   8.2  !  01-08  (M-A Filiberti, and M.Levy)  trahad+trazad = traadv 
+      !!   8.5  !  02-06  (G. Madec, C. Ethe)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc            , zwx => ua,  &  ! use ua as workspace
+         &                     zwy => va      ! use va as workspace
+#if defined key_trcbbl_adv
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &  ! temporary arrays
+         &         zun, zvn, zwn
+#else
+      USE oce_trc            , zun => un,  &  ! When no bbl, zun == un
+         &                     zvn => vn,  &  ! When no bbl, zvn == vn
+         &                     zwn => wn      ! When no bbl, zwn == wn
+#endif
+
+ 
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+ 
+      !! * Local save
+      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
+         zbtr2
+ 
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk, jn             ! dummy loop indices
+      REAL(wp) ::                           &
+         zbtr, ztra, zfui, zfvj,            &  ! temporary scalars
+         zhw, ze3tr, zcofi, zcofj,          &  !    "         "
+         zupsut, zupsvt,                    &  !    "         "
+         zfp_ui, zfp_vj, zfm_ui, zfm_vj,    &  !    "         "
+         zcofk, zupst, zcent,               &  !    "         "
+         zfp_w, zfm_w,                      &  !    "         "
+         zcenut, zcenvt                        ! 
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zind                              ! temporary workspace arrays
+#if defined key_trc_diatrd
+      REAL(wp) ::                           &
+         ztai, ztaj,                        &  ! temporary scalars
+         zfui1, zfvj1                          !    "         "
+#endif
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_adv_cen2 : 2nd order centered advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   Vector optimization case'
+         IF(lwp) WRITE(numout,*)
+   
+         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF
+
+#if defined key_trcbbl_adv
+
+      ! Advective bottom boundary layer 
+      ! -------------------------------
+      zun(:,:,:) = un(:,:,:) - u_trc_bbl(:,:,:)
+      zvn(:,:,:) = vn(:,:,:) - v_trc_bbl(:,:,:)
+      zwn(:,:,:) = wn(:,:,:) + w_trc_bbl(:,:,:)
+#endif
+
+
+      ! Upstream / centered scheme indicator
+      ! ------------------------------------
+ 
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zind(ji,jj,jk) =  MAX ( upsrnfh(ji,jj) * upsrnfz(jk),     &  ! changing advection scheme near runoff
+                  &                    upsadv(ji,jj)                     &  ! in the vicinity of some straits
+#if defined key_ice_lim
+                  &                  , tmask(ji,jj,jk)                   &  ! half upstream tracer fluxes
+                  &                  * MAX( 0., SIGN( 1., fzptn(ji,jj)   &  ! if tn < ("freezing"+0.1 )
+                  &                                +0.1-tn(ji,jj,jk) ) ) &
+#endif
+                  &                  )
+            END DO
+         END DO
+      END DO
+
+
+      DO jn = 1, jptra
+         ! I. Horizontal advective fluxes
+         ! ------------------------------
+         
+         ! Second order centered tracer flux at u and v-points
+         
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+               ! upstream indicator
+                  zcofi = MAX( zind(ji+1,jj,jk), zind(ji,jj,jk) )
+                  zcofj = MAX( zind(ji,jj+1,jk), zind(ji,jj,jk) )
+                  ! volume fluxes * 1/2
+#if ! defined key_zco
+                  zfui = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                  zfvj = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+#else
+                  zfui = 0.5 * e2u(ji,jj) * zun(ji,jj,jk)
+                  zfvj = 0.5 * e1v(ji,jj) * zvn(ji,jj,jk)
+#endif
+               ! upstream scheme
+                  zfp_ui = zfui + ABS( zfui )
+                  zfp_vj = zfvj + ABS( zfvj )
+                  zfm_ui = zfui - ABS( zfui )
+                  zfm_vj = zfvj - ABS( zfvj )
+                  zupsut = zfp_ui * trb(ji,jj,jk,jn) + zfm_ui * trb(ji+1,jj  ,jk,jn)
+                  zupsvt = zfp_vj * trb(ji,jj,jk,jn) + zfm_vj * trb(ji  ,jj+1,jk,jn)
+                  ! centered scheme
+                  zcenut = zfui * ( trn(ji,jj,jk,jn) + trn(ji+1,jj  ,jk,jn) )
+                  zcenvt = zfvj * ( trn(ji,jj,jk,jn) + trn(ji  ,jj+1,jk,jn) )
+                  ! mixed centered / upstream scheme
+                  zwx(ji,jj,jk) = zcofi * zupsut + (1.-zcofi) * zcenut
+                  zwy(ji,jj,jk) = zcofj * zupsvt + (1.-zcofj) * zcenvt                
+               END DO
+            END DO
+
+
+            ! 2. Tracer flux divergence at t-point added to the general trend
+            ! -------------------------
+
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+                  zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+#else
+                  zbtr = zbtr2(ji,jj) 
+#endif
+                  ! horizontal advective trends
+                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
+                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
+
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+
+#if defined key_trc_diatrd 
+                  ! recompute the trends in i- and j-direction as Uh gradh(T)
+#if ! defined key_zco
+                  zfui = 0.5 * e2u(ji  ,jj) * fse3u(ji,  jj,jk) * zun(ji,  jj,jk)
+                  zfui1= 0.5 * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zun(ji-1,jj,jk)
+                  zfvj = 0.5 * e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * zvn(ji,jj  ,jk)
+                  zfvj1= 0.5 * e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * zvn(ji,jj-1,jk)
+# else
+                  zfui = 0.5 * e2u(ji  ,jj) * zun(ji,  jj,jk)
+                  zfui1= 0.5 * e2u(ji-1,jj) * zun(ji-1,jj,jk)
+                  zfvj = 0.5 * e1v(ji,jj  ) * zvn(ji,jj  ,jk)
+                  zfvj1= 0.5 * e1v(ji,jj-1) * zvn(ji,jj-1,jk)
+# endif
+                  ztai = - zbtr * ( zfui  * ( trn(ji+1,jj  ,jk,jn) - trn(ji,  jj,jk,jn) )   &
+                     &                + zfui1 * ( trn(ji,  jj,  jk,jn) - trn(ji-1,jj,jk,jn) ) )
+                  ztaj = - zbtr * ( zfvj  * ( trn(ji  ,jj+1,jk,jn) - trn(ji,jj  ,jk,jn) )    &
+                     &                + zfvj1 * ( trn(ji  ,jj  ,jk,jn) - trn(ji,jj-1,jk,jn) ) )
+                  ! save i- and j- advective trends computed as Uh gradh(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = ztai
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = ztaj
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+      ENDDO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('centered2 - had')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+      
+      ! II. Vertical advection
+      ! ----------------------
+      DO jn = 1, jptra
+
+         ! Bottom value : flux set to zero
+         zwx(:,:,jpk) = 0.e0 
+
+         ! Surface value
+         IF ( lk_dynspg_rl ) THEN       ! rigid lid : flux set to zero
+            zwx(:,:, 1 ) = 0.e0  
+         ELSE                           ! free surface-constant volume
+            zwx(:,:, 1 ) = zwn(:,:,1) * trn(:,:,1,jn)
+         ENDIF
+
+         ! 1. Vertical advective fluxes
+         ! ----------------------------
+
+         ! Second order centered tracer flux at w-point
+
+         DO jk = 2, jpk
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! upstream indicator
+                  zcofk = MAX( zind(ji,jj,jk-1), zind(ji,jj,jk) )
+                  ! velocity * 1/2
+                  zhw = 0.5 * zwn(ji,jj,jk)
+                  ! upstream scheme
+                  zfp_w = zhw + ABS( zhw )
+                  zfm_w = zhw - ABS( zhw )
+                  zupst = zfp_w * trb(ji,jj,jk,jn) + zfm_w * trb(ji,jj,jk-1,jn)
+                  ! centered scheme
+                  zcent = zhw * ( trn(ji,jj,jk,jn) + trn(ji,jj,jk-1,jn) )
+                  ! centered scheme
+                  zwx(ji,jj,jk) = zcofk * zupst + (1.-zcofk) * zcent
+               END DO
+            END DO
+         END DO
+
+
+         ! 2. Tracer flux divergence at t-point added to the general trend
+         ! -------------------------
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3tr = 1. / fse3t(ji,jj,jk)
+                  ! vertical advective trends
+                  ztra = - ze3tr * ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) =  tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd 
+                  ! save the vertical advective trends computed as w gradz(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = ztra - trn(ji,jj,jk,jn) * hdivn(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('centered - zad')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_adv_cen2
+#else
+
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_adv_cen2( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_adv_cen2: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_adv_cen2
+#endif
+   !!======================================================================
+END MODULE trcadv_cen2
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl.F90	(revision 4536)
@@ -0,0 +1,356 @@
+MODULE trcadv_muscl
+   !!==============================================================================
+   !!                       ***  MODULE  trcadv_muscl  ***
+   !! Ocean passive tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_adv_muscl : update the tracer trend with the horizontal
+   !!                   and vertical advection trends using MUSCL scheme
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and active tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE trcbbl          ! advective passive tracers in the BBL
+   USE lib_mpp
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_adv_muscl  ! routine called by trcstp.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcadv_muscl.F90,v 1.13 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_adv_muscl( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE trc_adv_muscl  ***
+      !!          
+      !! ** Purpose :   Compute the now trend due to total advection of any pas-
+      !!      sive tracer using a MUSCL scheme (Monotone Upstream-centered Scheme
+      !!      for Conservation Laws) and add it to the general tracer trend.
+      !!
+      !! ** Method  :
+      !!
+      !! ** Action  : - update tra with the now advective tracer trends
+      !!              - save trends in trtrd ('key_trc_diatrd')
+      !!
+      !! References :                
+      !!      Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!	IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
+      !!
+      !! History :
+      !!        !  06-00  (A.Estublier)  for passive tracers
+      !!   9.0  !  03-04  (C. Ethe, G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * modules used
+#if defined key_trcbbl_adv
+      USE oce_trc            , zun => ua,  &  ! use ua as workspace
+         &                     zvn => va      ! use va as workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwn
+#else
+      USE oce_trc            , zun => un,  &  ! When no bbl, zun == un
+                               zvn => vn,  &  !              zvn == vn
+                               zwn => wn      !              zwn == wn
+#endif
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn            ! dummy loop indices
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &
+         zt1, zt2, ztp1, ztp2
+
+      REAL(wp) ::   zu, zv, zw, zeu, zev, zew, zbtr, ztra
+      REAL(wp) ::   z0u, z0v, z0w
+      REAL(wp) ::   zzt1, zzt2, zalpha, z2dtt
+#if defined key_trc_diatrd
+      REAL(wp) ::   ztai, ztaj
+      REAL(wp) ::   zfui, zfvj
+#endif
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+
+      IF( kt == nittrc000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_adv : MUSCL advection scheme'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+
+ 
+
+#if defined key_trcbbl_adv
+      ! Advective bottom boundary layer
+      ! -------------------------------
+      zun(:,:,:) = un (:,:,:) - u_trc_bbl(:,:,:)
+      zvn(:,:,:) = vn (:,:,:) - v_trc_bbl(:,:,:)
+      zwn(:,:,:) = wn (:,:,:) + w_trc_bbl(:,:,:)
+#endif
+
+ 
+
+      DO jn = 1, jptra
+#if defined key_trc_diatrd
+        DO jk = 1,jpk
+           DO jj = 1,jpj
+              DO ji = 1,jpi
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = 0.
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = 0.
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = 0.
+              END DO
+            END DO
+          END DO
+#endif
+         ! I. Horizontal advective fluxes
+         ! ------------------------------
+
+         ! first guess of the slopes
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1      
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zt1(ji,jj,jk) = umask(ji,jj,jk) * ( trb(ji+1,jj,jk,jn) - trb(ji,jj,jk,jn) )
+                  zt2(ji,jj,jk) = vmask(ji,jj,jk) * ( trb(ji,jj+1,jk,jn) - trb(ji,jj,jk,jn) )
+               END DO
+            END DO
+         END DO
+         ! bottom values
+         zt1(:,:,jpk) = 0.e0
+         zt2(:,:,jpk) = 0.e0
+
+         ! lateral boundary conditions on zt1, zt2
+         CALL lbc_lnk( zt1, 'U', -1. )   
+         CALL lbc_lnk( zt2, 'V', -1. ) 
+
+
+         ! Slopes
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpj
+               DO ji = fs_2, jpi   ! vector opt.
+                  ztp1(ji,jj,jk) =                    ( zt1(ji,jj,jk) + zt1(ji-1,jj  ,jk) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt1(ji,jj,jk) * zt1(ji-1,jj  ,jk) ) )
+                  ztp2(ji,jj,jk) =                    ( zt2(ji,jj,jk) + zt2(ji  ,jj-1,jk) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt2(ji,jj,jk) * zt2(ji  ,jj-1,jk) ) )
+               END DO
+            END DO
+         END DO
+         ! bottom values
+         ztp1(:,:,jpk) = 0.e0
+         ztp2(:,:,jpk) = 0.e0
+
+         ! Slopes limitation
+         DO jk = 1, jpkm1
+            DO jj = 2, jpj
+               DO ji = fs_2, jpi   ! vector opt.
+                  ztp1(ji,jj,jk) = SIGN( 1., ztp1(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp1(ji  ,jj,jk) ),   &
+                     &                  2.*ABS( zt1 (ji-1,jj,jk) ),   &
+                     &                  2.*ABS( zt1 (ji  ,jj,jk) ) )
+
+                  ztp2(ji,jj,jk) = SIGN( 1., ztp2(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp2(ji,jj  ,jk) ),   &
+                     &                  2.*ABS( zt2 (ji,jj-1,jk) ),   &
+                     &                  2.*ABS( zt2 (ji,jj  ,jk) ) )
+
+               END DO
+            END DO
+         END DO
+
+         ! Advection terms
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! volume fluxes
+#if ! defined key_zco
+                  zeu = e2u(ji,jj) * fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                  zev = e1v(ji,jj) * fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+#else
+                  zeu = e2u(ji,jj) * zun(ji,jj,jk)
+                  zev = e1v(ji,jj) * zvn(ji,jj,jk)
+#endif
+                  ! MUSCL fluxes
+                  z2dtt = rdttra(jk) * FLOAT(ndttrc)
+                  z0u = SIGN( 0.5, zun(ji,jj,jk) )            
+                  zalpha = 0.5 - z0u
+                  zu  = z0u - 0.5 * zun(ji,jj,jk) * z2dtt / e1u(ji,jj)
+                  zzt1 = trb(ji+1,jj,jk,jn) + zu*ztp1(ji+1,jj,jk)
+                  zzt2 = trb(ji  ,jj,jk,jn) + zu*ztp1(ji  ,jj,jk)
+                  zt1(ji,jj,jk) = zeu * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
+                  z0v = SIGN( 0.5, zvn(ji,jj,jk) )            
+                  zalpha = 0.5 - z0v
+                  zv  = z0v - 0.5 * zvn(ji,jj,jk) * z2dtt / e2v(ji,jj)
+                  zzt1 = trb(ji,jj+1,jk,jn) + zv*ztp2(ji,jj+1,jk)
+                  zzt2 = trb(ji,jj  ,jk,jn) + zv*ztp2(ji,jj  ,jk)
+                  zt2(ji,jj,jk) = zev * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
+               END DO
+            END DO
+         END DO
+
+         ! lateral boundary conditions on zt1, zt2 (changed sign)
+         CALL lbc_lnk( zt1, 'U', -1. ) 
+         CALL lbc_lnk( zt2, 'V', -1. ) 
+
+         ! Compute and add the horizontal advective trend
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+#else
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj) )
+#endif
+                  ! horizontal advective trends
+                  ztra = - zbtr * ( zt1(ji,jj,jk) - zt1(ji-1,jj  ,jk  )   &
+                     &            + zt2(ji,jj,jk) - zt2(ji  ,jj-1,jk  ) )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  ! recompute the trends in i- and j-direction as Uh gradh(T)
+#if ! defined key_zco
+                  zfui =  e2u(ji  ,jj) * fse3u(ji,  jj,jk) * un(ji,  jj,jk)   &
+                     & -  e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * un(ji-1,jj,jk)
+                  zfvj =  e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * vn(ji,jj  ,jk)   &
+                     & -  e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * vn(ji,jj-1,jk)
+#   else
+                  zfui = e2u(ji  ,jj) * un(ji,  jj,jk)   &
+                     & - e2u(ji-1,jj) * un(ji-1,jj,jk)
+                  zfvj = e1v(ji,jj  ) * vn(ji,jj  ,jk)   &
+                     & - e1v(ji,jj-1) * vn(ji,jj-1,jk)
+#   endif
+                  ztai =-zbtr * (  zt1(ji,jj,jk) - zt1(ji-1,jj  ,jk) - trn(ji,jj,jk,jn) * zfui  )
+                  ztaj =-zbtr * (  zt2(ji,jj,jk) - zt2(ji  ,jj-1,jk) - trn(ji,jj,jk,jn) * zfvj  )
+                  ! save i- and j- advective trends computed as Uh gradh(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = ztai
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = ztaj
+#endif
+               END DO
+            END DO
+         END DO
+      ENDDO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('muscl - had')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+         ! II. Vertical advective fluxes
+         ! -----------------------------
+
+      DO jn = 1, jptra
+         ! First guess of the slope
+         ! interior values
+         DO jk = 2, jpkm1
+            zt1(:,:,jk) = tmask(:,:,jk) * ( trb(:,:,jk-1,jn) - trb(:,:,jk,jn) )
+         END DO
+         ! surface and bottom boundary conditions
+         zt1 (:,:, 1 ) = 0.e0 
+         zt1 (:,:,jpk) = 0.e0
+         ! Slopes
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztp1(ji,jj,jk) =                    ( zt1(ji,jj,jk) + zt1(ji,jj,jk+1) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt1(ji,jj,jk) * zt1(ji,jj,jk+1) ) )
+               END DO
+            END DO
+         END DO
+
+         ! Slopes limitation
+         ! interior values
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztp1(ji,jj,jk) = SIGN( 1., ztp1(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp1(ji,jj,jk  ) ),   &
+                     &                  2.*ABS( zt1 (ji,jj,jk+1) ),   &
+                     &                  2.*ABS( zt1 (ji,jj,jk  ) ) )
+               END DO
+            END DO
+         END DO
+         ! surface values
+         ztp1(:,:,1) = 0. 
+         ! vertical advective flux
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  z2dtt = rdttra(jk) * FLOAT(ndttrc)
+                  zew = zwn(ji,jj,jk+1)
+                  z0w = SIGN( 0.5, zwn(ji,jj,jk+1) )
+                  zalpha = 0.5 + z0w
+                  zw  = z0w - 0.5 * zwn(ji,jj,jk+1)*z2dtt / fse3w(ji,jj,jk+1)
+                  zzt1 = trb(ji,jj,jk+1,jn) + zw*ztp1(ji,jj,jk+1)
+                  zzt2 = trb(ji,jj,jk  ,jn) + zw*ztp1(ji,jj,jk  )
+                  zt1(ji,jj,jk+1) = zew * ( zalpha * zzt1 + (1.-zalpha)*zzt2 )
+               END DO
+            END DO
+         END DO
+         ! surface values
+         IF( lk_dynspg_rl ) THEN        ! rigid lid : flux set to zero
+            zt1(:,:, 1 ) = 0.e0
+         ELSE                           ! free surface
+            zt1(:,:, 1 ) = zwn(:,:,1) * trb(:,:,1,jn)
+         ENDIF
+
+         ! bottom values
+         zt1(:,:,jpk) = 0.e0
+
+         ! Compute & add the vertical advective trend
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr = 1. / fse3t(ji,jj,jk)
+                  ! horizontal advective trends
+                  ztra = - zbtr * ( zt1(ji,jj,jk) - zt1(ji,jj,jk+1) )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) =  tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  ! save the vertical advective trends computed as w gradz(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = ztra - trn(ji,jj,jk,jn) * hdivn(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('muscl - zad')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+END SUBROUTINE trc_adv_muscl
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_adv_muscl( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_adv_muscl: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_adv_muscl
+#endif
+
+   !!======================================================================
+END MODULE trcadv_muscl
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl2.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl2.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_muscl2.F90	(revision 4536)
@@ -0,0 +1,411 @@
+MODULE trcadv_muscl2
+   !!==============================================================================
+   !!                       ***  MODULE  trcadv_muscl2  ***
+   !! Ocean passive tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   tra_adv_muscl2 : update the tracer trend with the horizontal
+   !!                    and vertical advection trends using MUSCL2 scheme
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and active tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE trcbbl          ! advective passive tracers in the BBL
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_adv_muscl2        ! routine called by trcstp.F90
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpk) ::   &
+      rdttrc                     ! vertical profile of tracer time-step
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_adv_muscl2( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_adv_muscl2  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to total advection of passi-
+      !!      ve tracer using a MUSCL scheme (Monotone Upstream-
+      !!      Centered Scheme for Conservation Laws) and add it to the general
+      !!      tracer trend.
+      !!
+      !! ** Method : MUSCL scheme plus centered scheme at ocean boundaries
+      !!
+      !! ** Action : - update tra with the now advective tracer trends
+      !!             - save trends in trtrd ('key_trc_diatrd')
+      !!
+      !! References :                
+      !!      Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!	IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
+      !!
+      !! History :
+      !!        !  06-00  (A.Estublier)  for passive tracers
+      !!   9.0  !  03-04  (C. Ethe, G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * modules used
+#if defined key_trcbbl_adv
+      USE oce_trc            , zun => ua,  &  ! use ua as workspace
+         &                     zvn => va      ! use va as workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwn
+#else
+      USE oce_trc            , zun => un,  &  ! When no bbl, zun == un
+                               zvn => vn,  &  !              zvn == vn
+                               zwn => wn      !              zwn == wn
+#endif
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn               ! dummy loop indices
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &
+         zt1, zt2, ztp1, ztp2
+      REAL(wp) ::   zu, zv, zw, zeu, zev, zew, zbtr, ztra
+      REAL(wp) ::   z0u, z0v, z0w
+      REAL(wp) ::   zzt1, zzt2, zalpha
+
+#if defined key_trc_diatrd
+      REAL(wp) ::   ztai, ztaj
+      REAL(wp) ::   zfui, zfvj
+#endif
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_adv_muscl2 : MUSCL2 advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)
+      ENDIF
+      
+#if defined key_trcbbl_adv        
+      ! Advective bottom boundary layer
+      ! -------------------------------
+      zun(:,:,:) = un (:,:,:) - u_trc_bbl(:,:,:)
+      zvn(:,:,:) = vn (:,:,:) - v_trc_bbl(:,:,:)
+      zwn(:,:,:) = wn (:,:,:) + w_trc_bbl( :,:,:)
+#endif
+
+
+      DO jn = 1, jptra
+
+         ! I. Horizontal advective fluxes
+         ! ------------------------------
+
+         ! first guess of the slopes
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1      
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zt1(ji,jj,jk) = umask(ji,jj,jk) * ( trb(ji+1,jj,jk,jn) - trb(ji,jj,jk,jn) )
+                  zt2(ji,jj,jk) = vmask(ji,jj,jk) * ( trb(ji,jj+1,jk,jn) - trb(ji,jj,jk,jn) )
+               END DO
+            END DO
+         END DO
+         ! bottom values
+         zt1(:,:,jpk) = 0.e0
+         zt2(:,:,jpk) = 0.e0
+
+         ! lateral boundary conditions on zt1, zt2  (changed sign)
+         CALL lbc_lnk( zt1, 'U', -1. )
+         CALL lbc_lnk( zt2, 'V', -1. )
+
+         ! Slopes
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpj
+               DO ji = fs_2, jpi   ! vector opt.
+                  ztp1(ji,jj,jk) =                    ( zt1(ji,jj,jk) + zt1(ji-1,jj  ,jk) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt1(ji,jj,jk) * zt1(ji-1,jj  ,jk) ) )
+                  ztp2(ji,jj,jk) =                    ( zt2(ji,jj,jk) + zt2(ji  ,jj-1,jk) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt2(ji,jj,jk) * zt2(ji  ,jj-1,jk) ) )
+               END DO
+            END DO
+         END DO
+         ! bottom values
+         ztp1(:,:,jpk) = 0.e0 
+         ztp2(:,:,jpk) = 0.e0
+
+         ! Slopes limitation
+         DO jk = 1, jpkm1
+            DO jj = 2, jpj
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztp1(ji,jj,jk) = SIGN( 1., ztp1(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp1(ji  ,jj,jk) ),   &
+                     &                  2.*ABS( zt1 (ji-1,jj,jk) ),   &
+                     &                  2.*ABS( zt1 (ji  ,jj,jk) ) )
+
+                  ztp2(ji,jj,jk) = SIGN( 1., ztp2(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp2(ji,jj  ,jk) ),   &
+                     &                  2.*ABS( zt2 (ji,jj-1,jk) ),   &
+                     &                  2.*ABS( zt2 (ji,jj  ,jk) ) )
+               END DO
+            END DO
+         END DO
+
+         ! Advection terms
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! volume fluxes
+#if ! defined key_zco
+                  zeu = e2u(ji,jj) * fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                  zev = e1v(ji,jj) * fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+#else
+                  zeu = e2u(ji,jj) * zun(ji,jj,jk)
+                  zev = e1v(ji,jj) * zvn(ji,jj,jk)
+#endif
+                  ! MUSCL fluxes
+                  z0u = SIGN( 0.5, zun(ji,jj,jk) )            
+                  zalpha = 0.5 - z0u
+                  zu  = z0u - 0.5 * zun(ji,jj,jk) * rdttrc(jk) / e1u(ji,jj)
+                  zzt1 = trb(ji+1,jj,jk,jn) + zu*ztp1(ji+1,jj,jk)
+                  zzt2 = trb(ji  ,jj,jk,jn) + zu*ztp1(ji  ,jj,jk)
+                  zt1(ji,jj,jk) = zeu * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
+
+                  z0v = SIGN( 0.5, zvn(ji,jj,jk) )            
+                  zalpha = 0.5 - z0v
+                  zv  = z0v - 0.5 * zvn(ji,jj,jk) * rdttrc(jk) / e2v(ji,jj)
+                  zzt1 = trb(ji,jj+1,jk,jn) + zv*ztp2(ji,jj+1,jk)
+                  zzt2 = trb(ji,jj  ,jk,jn) + zv*ztp2(ji,jj  ,jk)
+                  zt2(ji,jj,jk) = zev * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
+
+               END DO
+            END DO
+         END DO
+
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+                  zev = e1v(ji,jj) * fse3v(ji,jj,jk)
+                  IF( umask(ji,jj,jk) == 0. ) THEN
+                     IF( zun(ji+1,jj,jk) > 0. .AND. ji /= jpi ) THEN
+                        zt1(ji+1,jj,jk) = e2u(ji+1,jj)* fse3u(ji+1,jj,jk)   &
+                           &            * zun(ji+1,jj,jk) * ( trb(ji+1,jj,jk,jn) + trb(ji+2,jj,jk,jn) ) * 0.5
+                     ENDIF
+                     IF( zun(ji-1,jj,jk) < 0. ) THEN
+                        zt1(ji-1,jj,jk) = e2u(ji-1,jj)* fse3u(ji-1,jj,jk)   &
+                           &            * zun(ji-1,jj,jk) * ( trb(ji-1,jj,jk,jn) + trb(ji  ,jj,jk,jn) ) * 0.5
+                     ENDIF
+                  ENDIF
+                  IF( vmask(ji,jj,jk) == 0. ) THEN
+                     IF( zvn(ji,jj+1,jk) > 0. .AND. jj /= jpj ) THEN
+                        zt2(ji,jj+1,jk) = e1v(ji,jj+1) * fse3v(ji,jj+1,jk)   &
+                           &            * zvn(ji,jj+1,jk) * ( trb(ji,jj+1,jk,jn) + trb(ji,jj+2,jk,jn) ) * 0.5
+                     ENDIF
+                     IF( zvn(ji,jj-1,jk) < 0. ) THEN
+                        zt2(ji,jj-1,jk) = e1v(ji,jj-1)* fse3v(ji,jj-1,jk)   &
+                           &            * zvn(ji,jj-1,jk) * ( trb(ji,jj-1,jk,jn) + trb(ji  ,jj,jk,jn) ) * 0.5
+                     ENDIF
+                  ENDIF
+
+#else
+                  IF( umask(ji,jj,jk) == 0. ) THEN
+                     IF( zun(ji+1,jj,jk) > 0. .AND. ji /= jpi ) THEN
+                        zt1(ji+1,jj,jk) = e2u(ji+1,jj) * zun(ji+1,jj,jk) * ( trb(ji+1,jj,jk,jn) + trb(ji+2,jj,jk,jn) ) * 0.5
+                     ENDIF
+                     IF( zun(ji-1,jj,jk) < 0. ) THEN
+                        zt1(ji-1,jj,jk) = e2u(ji-1,jj) * zun(ji-1,jj,jk) * ( trb(ji-1,jj,jk,jn) + trb(ji  ,jj,jk,jn) ) * 0.5
+                     ENDIF
+                  ENDIF
+                  IF( vmask(ji,jj,jk) == 0. ) THEN
+                     IF( zvn(ji,jj+1,jk) > 0. .AND. jj /= jpj ) THEN
+                        zt2(ji,jj+1,jk) = e1v(ji,jj+1) * zvn(ji,jj+1,jk) * ( trb(ji,jj+1,jk,jn) + trb(ji,jj+2,jk,jn) ) * 0.5
+                     ENDIF
+                     IF( zvn(ji,jj-1,jk) < 0. ) THEN
+                        zt2(ji,jj-1,jk) = e1v(ji,jj-1) * zvn(ji,jj-1,jk) * ( trb(ji,jj-1,jk,jn) + trb(ji  ,jj,jk,jn) ) * 0.5
+                     ENDIF
+                  ENDIF
+#endif
+               END DO
+            END DO
+         END DO
+
+         ! lateral boundary conditions on zt1, zt2   (changed sign)
+         CALL lbc_lnk( zt1, 'U', -1. )
+         CALL lbc_lnk( zt2, 'V', -1. )
+
+         ! Compute and add the horizontal advective trend
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+#else
+                  zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj) )
+#endif
+                  ! horizontal advective trends
+                  ztra = - zbtr * ( zt1(ji,jj,jk) - zt1(ji-1,jj  ,jk  )   &
+                     &            + zt2(ji,jj,jk) - zt2(ji  ,jj-1,jk  ) )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  ! recompute the trends in i- and j-direction as Uh gradh(T)
+#if ! defined key_zco
+                  zfui =  e2u(ji  ,jj) * fse3u(ji,  jj,jk) * un(ji,  jj,jk)   &
+                     & -  e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * un(ji-1,jj,jk)
+                  zfvj =  e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * vn(ji,jj  ,jk)   &
+                     & -  e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * vn(ji,jj-1,jk)
+#   else
+                  zfui = e2u(ji  ,jj) * un(ji,  jj,jk)   &
+                     & - e2u(ji-1,jj) * un(ji-1,jj,jk)
+                  zfvj = e1v(ji,jj  ) * vn(ji,jj  ,jk)   &
+                     & - e1v(ji,jj-1) * vn(ji,jj-1,jk)
+#   endif
+                  ztai =-zbtr * (  zt1(ji,jj,jk) - zt1(ji-1,jj  ,jk) - trn(ji,jj,jk,jn) * zfui  )
+                  ztaj =-zbtr * (  zt2(ji,jj,jk) - zt2(ji  ,jj-1,jk) - trn(ji,jj,jk,jn) * zfvj  )
+                  ! save i- and j- advective trends computed as Uh gradh(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = ztai
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = ztaj
+
+#endif
+               END DO
+            END DO
+         END DO
+      ENDDO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('muscl2 - had')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+      ! II. Vertical advective fluxes
+      ! -----------------------------
+
+      DO jn = 1, jptra
+
+         ! First guess of the slope
+         ! interior values
+         DO jk = 2, jpkm1
+            zt1(:,:,jk) = tmask(:,:,jk) * ( trb(:,:,jk-1,jn) - trb(:,:,jk,jn) )
+         END DO
+         ! surface and bottom boundary conditions
+         zt1 (:,:, 1 ) = 0.e0 
+         zt1 (:,:,jpk) = 0.e0
+
+         ! Slopes
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztp1(ji,jj,jk) =                    ( zt1(ji,jj,jk) + zt1(ji,jj,jk+1) )   &
+                     &           * ( 0.25 + SIGN( 0.25, zt1(ji,jj,jk) * zt1(ji,jj,jk+1) ) )
+               END DO
+            END DO
+         END DO
+
+         ! Slopes limitation
+         ! interior values
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztp1(ji,jj,jk) = SIGN( 1., ztp1(ji,jj,jk) )   &
+                     &           * MIN(    ABS( ztp1(ji,jj,jk  ) ),   &
+                     &                  2.*ABS( zt1 (ji,jj,jk+1) ),   &
+                     &                  2.*ABS( zt1 (ji,jj,jk  ) ) )
+               END DO
+            END DO
+         END DO
+
+         ! surface values
+         ztp1(:,:,1) = 0. 
+
+         ! vertical advective flux
+         ! interior values
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zew = zwn(ji,jj,jk+1)
+                  z0w = SIGN( 0.5, zwn(ji,jj,jk+1) )
+                  zalpha = 0.5 + z0w
+                  zw  = z0w - 0.5 * zwn(ji,jj,jk+1)* rdttrc(jk)/ fse3w(ji,jj,jk+1)
+                  zzt1 = trb(ji,jj,jk+1,jn) + zw*ztp1(ji,jj,jk+1)
+                  zzt2 = trb(ji,jj,jk  ,jn) + zw*ztp1(ji,jj,jk  )
+                  zt1(ji,jj,jk+1) = zew * ( zalpha * zzt1 + (1.-zalpha)*zzt2 )
+               END DO
+            END DO
+         END DO
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF( tmask(ji,jj,jk+1) == 0. ) THEN
+                     IF( zwn(ji,jj,jk) > 0. ) THEN
+                        zt1(ji,jj,jk) = zwn(ji,jj,jk) * ( trb(ji,jj,jk-1,jn) + trb(ji,jj,jk,jn) ) * 0.5
+                     ENDIF
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         ! surface values
+         IF( lk_dynspg_rl ) THEN        ! rigid lid : flux set to zero
+            zt1(:,:, 1 ) = 0.e0
+         ELSE                           ! free surface
+            zt1(:,:, 1 ) = zwn(:,:,1) * trb(:,:,1,jn)
+         ENDIF
+
+         ! bottom values
+         zt1(:,:,jpk) = 0.e0
+
+         ! Compute & add the vertical advective trend
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr = 1. / fse3t(ji,jj,jk)
+                  ! horizontal advective trends
+                  ztra = - zbtr * ( zt1(ji,jj,jk) - zt1(ji,jj,jk+1) )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) =  tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  ! save the vertical advective trends computed as w gradz(T)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = ztra - trn(ji,jj,jk,jn) * hdivn(ji,jj,jk)
+#endif
+               END DO
+            END DO
+         END DO
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('muscl2 - zad')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_adv_muscl2
+
+#else
+
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_adv_muscl2( kt ) 
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_adv_muscl2: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_adv_muscl2
+#endif
+
+   !!======================================================================
+END MODULE trcadv_muscl2
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_smolar.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_smolar.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_smolar.F90	(revision 4536)
@@ -0,0 +1,531 @@
+MODULE trcadv_smolar
+   !!==============================================================================
+   !!                       ***  MODULE  trcadv_smolar  ***
+   !! Ocean passive tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_adv_smolar : update the passive tracer trend with the horizontal
+   !!                  and vertical advection trends using a Smolarkiewicz 
+   !!                  FCT scheme
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE lbclnk              ! ocean lateral boundary conditions (or mpp link)
+   USE trcbbl              ! advective passive tracers in the BBL
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_adv_smolar    ! routine called by trcstp.F90
+
+   REAL(wp), DIMENSION(jpk) ::   rdttrc       ! vertical profile of tracer time-step
+ 
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_adv_smolar( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_adv_smolar  ***
+      !!
+      !! ** Purpose :   Compute the now trend due to total advection of passi-
+      !!      ve tracer using a Smolarkiewicz FCT (Flux Corrected Transport ) 
+      !!      scheme and add it to the general tracer trend.
+      !!
+      !! ** Method : Computation of not exactly the advection but the
+      !!             transport term, i.e.  div(u*tra). 
+      !!             Computes the now horizontal and vertical advection with
+      !!             the complete 3d method.
+      !! 
+      !!       note: - sc is an empirical factor to be used with care
+      !!             - this advection scheme needs an euler-forward time scheme
+      !!
+      !! ** Action : - update tra with the now advective tracer trends
+      !!             - save trends in trtrd ('key_trc_diatrd')
+      !!
+      !! References :                
+      !!     Piotr K. Smolarkiewicz, 1983,
+      !!       "A simple positive definit advection
+      !!        scheme with small IMPLICIT diffusion"
+      !!        Monthly Weather Review, pp 479-486
+      !!
+      !! History :
+      !!         !  87-06 (pa-dl) Original
+      !!         !  91-11 (G. Madec)
+      !!         !  94-08 (A. Czaja)
+      !!         !  95-09 (M. Levy) passive tracers
+      !!         !  98-03 (M.A. Foujols) lateral boundary conditions
+      !!         !  99-02 (M.A. Foujols) lbc in conjonction with ORCA
+      !!         !  00-05 (MA Foujols) add lbc for tracer trends
+      !!         !  00-10 (MA Foujols and E.Kestenare) INCLUDE instead of routine
+      !!         !  01-05 (E.Kestenare) fix bug in trtrd indexes
+      !!         !  02-05 (M-A Filiberti, and M.Levy) correction in trtrd computation
+      !!   9.0   !  03-04  (C. Ethe)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * modules used
+#if defined key_trcbbl_adv
+      USE oce_trc            , zun => ua,  &  ! use ua as workspace
+         &                     zvn => va      ! use va as workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwn
+#else
+      USE oce_trc            , zun => un,  &  ! When no bbl, zun == un
+                               zvn => vn,  &  !              zvn == vn
+                               zwn => wn      !              zwn == wn
+#endif
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !! * Local declarations
+      INTEGER :: ji, jj, jk,jt, jn            ! dummy loop indices
+
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &      
+         zti, ztj,              &
+         zaa, zbb, zcc,         &
+         zx , zy , zz ,         &
+         zkx, zky, zkz,         &
+         zbuf
+
+#if defined key_trc_diatrd
+      REAL(wp) :: zgm, zgz
+#endif
+
+      REAL(wp) :: zbtr, ztra
+      REAL(wp) :: zfp_ui, zfp_vj, zfm_ui, zfm_vj, zfp_w, zfm_w
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+
+      IF( kt == nittrc000  .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_adv_smolar : SMOLARKIEWICZ advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         rdttrc(:) = rdttra(:) * FLOAT(ndttrc)
+      ENDIF
+
+
+#if defined key_trcbbl_adv        
+      ! Advective bottom boundary layer
+      ! -------------------------------
+      zun(:,:,:) = un (:,:,:) - u_trc_bbl(:,:,:)
+      zvn(:,:,:) = vn (:,:,:) - v_trc_bbl(:,:,:)
+      zwn(:,:,:) = wn (:,:,:) + w_trc_bbl( :,:,:)
+#endif
+
+      ! tracer loop parallelized (macrotasking)
+      ! =======================================
+      
+      DO jn = 1, jptra
+         
+         ! 1. tracer flux in the 3 directions
+         ! ----------------------------------
+         
+         ! 1.1 mass flux at u v and t-points and initialization
+
+        DO jk = 1,jpk
+
+           DO jj = 1,jpj
+              DO ji = 1,jpi
+                 zaa(ji,jj,jk) = e2u(ji,jj)*fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                 zbb(ji,jj,jk) = e1v(ji,jj)*fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+                 zcc(ji,jj,jk) = e1t(ji,jj)*e2t(ji,jj)      * zwn(ji,jj,jk)
+                 zbuf(ji,jj,jk) = 0.
+                 ztj(ji,jj,jk) = 0.
+                 zx(ji,jj,jk) = 0.
+                 zy(ji,jj,jk) = 0.
+                 zz(ji,jj,jk) = 0.
+                 zti(ji,jj,jk) = trn(ji,jj,jk,jn)
+#if defined key_trc_diatrd
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = 0.
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = 0.
+                 IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = 0.
+#endif
+              END DO
+           END DO
+           
+           ! 1.2 calcul of intermediate field with an upstream advection scheme
+           !     and mass fluxes calculated above
+           
+           ! calcul of tracer flux in the i and j direction
+           
+           DO jj=1,jpj
+              zkx(  1,jj,jk)=0.
+              zkx(jpi,jj,jk)=0.
+           END DO
+           
+           DO ji=1,jpi
+              zky(ji,  1,jk)=0.
+              zky(ji,jpj,jk)=0.
+           END DO
+           
+           DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+                 zfp_ui = 0.5 * ( zaa(ji,jj,jk) + ABS( zaa(ji,jj,jk) ) )
+                 zfp_vj = 0.5 * ( zbb(ji,jj,jk) + ABS( zbb(ji,jj,jk) ) )
+                 zfm_ui = 0.5 * ( zaa(ji,jj,jk) - ABS( zaa(ji,jj,jk) ) )
+                 zfm_vj = 0.5 * ( zbb(ji,jj,jk) - ABS( zbb(ji,jj,jk) ) )            
+                 zkx(ji,jj,jk) = zfp_ui * zti(ji,jj,jk) + zfm_ui * zti(ji+1,jj  ,jk) 
+                 zky(ji,jj,jk) = zfp_vj * zti(ji,jj,jk) + zfm_vj * zti(ji    ,jj+1,jk)             
+              END DO
+           END DO
+
+        END DO
+
+         ! II. Vertical advection
+         ! ----------------------
+
+         ! Surface value
+         IF( lk_dynspg_rl ) THEN        ! rigid lid : flux set to zero
+            zkz(:,:, 1 ) = 0.e0  
+         ELSE                           ! free surface
+            zkz(:,:, 1 ) = zwn(:,:,1) * trn(:,:,1,jn) * tmask(ji,jj,1)
+         ENDIF
+
+        DO jk = 2,jpk
+          DO jj = 1,jpj
+            DO ji = 1,jpi
+               zfp_w = 0.5 * ( zcc(ji,jj,jk) + ABS( zcc(ji,jj,jk) ) )
+               zfm_w = 0.5 * ( zcc(ji,jj,jk) - ABS( zcc(ji,jj,jk) ) )        
+               zkz(ji,jj,jk) = zfp_w * zti(ji,jj,jk) + zfm_w * zti(ji,jj,jk-1)     
+            END DO
+          END DO
+        END DO
+
+! ... Lateral boundary conditions on zk[xy]
+      CALL lbc_lnk( zkx, 'U', -1. )
+      CALL lbc_lnk( zky, 'V', -1. )
+
+
+! 2. calcul of after field using an upstream advection scheme
+! -----------------------------------------------------------
+
+        DO jk = 1,jpkm1
+          DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+              zbtr = 1./(e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk))
+              ztj(ji,jj,jk) = -zbtr*    &
+     &            ( zkx(ji,jj,jk) - zkx(ji - 1,jj,jk)  &
+     &            + zky(ji,jj,jk) - zky(ji,jj - 1,jk)  &
+     &            + zkz(ji,jj,jk) - zkz(ji,jj,jk + 1) )
+#if defined key_trc_diatrd
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) -  &
+     &                       zbtr*( zkx(ji,jj,jk) - zkx(ji - 1,jj,jk) )
+
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) -  &
+     &            zbtr*( zky(ji,jj,jk) - zky(ji,jj - 1,jk) )
+
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3) -  &
+     &            zbtr*( zkz(ji,jj,jk) - zkz(ji,jj,jk + 1) )
+#endif
+            END DO
+          END DO
+        END DO
+
+! 2.1 start of antidiffusive correction loop
+
+        DO jt = 1,ncortrc
+
+! 2.2 calcul of intermediary field zti
+
+          DO jk = 1,jpkm1
+            DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+                zti(ji,jj,jk) = zti(ji,jj,jk)+rdttrc(jk)*ztj(ji,jj,jk)
+                zbuf(ji,jj,jk) = zbuf(ji,jj,jk) + ztj(ji,jj,jk)
+              END DO
+            END DO
+          END DO
+
+! ... Lateral boundary conditions on zti
+      CALL lbc_lnk( zti, 'T', 1. )
+
+
+! 2.3 calcul of the antidiffusive flux
+
+          DO jk = 1,jpkm1
+            DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+                zx(ji,jj,jk) = ( abs(zaa(ji,jj,jk)) - rdttrc(jk)       &
+     &              *zaa(ji,jj,jk)**2/                          &
+     &              (e1u(ji,jj)*e2u(ji,jj)*fse3u(ji,jj,jk) ) )  &
+     &              *(zti(ji + 1,jj,jk) - zti( ji ,jj,jk))      &
+     &              /(zti( ji ,jj,jk) + zti(ji + 1,jj,jk) + rtrn)    &
+     &              * rsc
+
+                zy(ji,jj,jk) = ( abs(zbb(ji,jj,jk)) - rdttrc(jk)       &
+     &              *zbb(ji,jj,jk)**2/                          &
+     &              (e1v(ji,jj)*e2v(ji,jj)*fse3v(ji,jj,jk) ) )  &
+     &              *(zti(ji,jj + 1,jk) - zti(ji, jj ,jk))      &
+     &              /(zti(ji, jj ,jk) + zti(ji,jj + 1,jk) + rtrn)    &
+     &              * rsc
+              END DO
+            END DO
+          END DO
+
+          DO jk = 2,jpkm1
+            DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+                zz(ji,jj,jk) = ( abs(zcc(ji,jj,jk)) - rdttrc(jk)*zcc(ji,jj,jk)**2  &  
+     &              /( e1t(ji,jj)*e2t(ji,jj)*fse3w(ji,jj,jk) ) ) &
+     &               *( zti(ji,jj,jk) - zti(ji,jj,jk - 1) )/  &
+     &                ( zti(ji,jj,jk) + zti(ji,jj,jk - 1) + rtrn )* rsc*( -1.)
+              END DO
+            END DO
+          END DO
+
+! 2.4 cross terms
+
+          IF (crosster) THEN
+              DO jk = 2,jpkm1
+                DO jj = 2,jpjm1
+                  DO ji = 2,jpim1
+                    zx(ji,jj,jk) = zx(ji,jj,jk) &
+     &                  - 0.5*rdttrc(jk)*rsc*zaa(ji,jj,jk)*0.25* &
+     &                  (    (zbb(ji  ,jj - 1,jk  ) + zbb(ji + 1,jj - 1 &
+     &                  ,jk  ) + zbb(ji + 1,jj  ,jk  ) + zbb(ji  ,jj  &
+     &                  ,jk))* (zti(ji  ,jj + 1,jk  ) + zti(ji + 1,jj + &
+     &                  1,jk  ) - zti(ji + 1,jj - 1,jk  ) - zti(ji  ,jj &
+     &                  - 1,jk  ))/ (zti(ji  ,jj + 1,jk  ) + zti(ji + 1 &
+     &                  ,jj + 1,jk  ) + zti(ji + 1,jj - 1,jk  ) + zti(ji &
+     &                  ,jj - 1,jk  ) + rtrn) + (zcc(ji  ,jj  ,jk  ) + &
+     &                  zcc(ji + 1,jj  ,jk  ) + zcc(ji  ,jj  ,jk + 1) + &
+     &                  zcc(ji + 1,jj  ,jk + 1))* (zti(ji  ,jj  ,jk - 1) &
+     &                  + zti(ji + 1,jj  ,jk - 1) - zti(ji  ,jj  ,jk + 1 &
+     &                  )- zti(ji + 1,jj  ,jk + 1))/ (zti(ji  ,jj  ,jk - &
+     &                  1) + zti(ji + 1,jj  ,jk - 1) + zti(ji  ,jj  ,jk &
+     &                  +1) + zti(ji + 1,jj  ,jk + 1) + rtrn))/(e1u(ji &
+     &                  ,jj)*e2u(ji,jj)*fse3u(ji,jj,jk))*vmask(ji  ,jj - &
+     &                  1,jk  )*vmask(ji + 1,jj - 1,jk  )*vmask(ji + 1 &
+     &                  ,jj,jk)*vmask(ji  ,jj  ,jk  )*tmask(ji  ,jj  ,jk &
+     &                  )*tmask(ji + 1,jj  ,jk  )*tmask(ji  ,jj  ,jk + 1 &
+     &                  )*tmask(ji + 1,jj  ,jk + 1)
+
+                    zy(ji,jj,jk) = zy(ji,jj,jk)    &   
+     &                  - 0.5*rdttrc(jk)*rsc*zbb(ji,jj,jk)*0.25*    &   
+     &                  (    (zaa(ji - 1,jj  ,jk  ) + zaa(ji - 1,jj + 1    &   
+     &                  ,jk  ) + zaa(ji  ,jj  ,jk  ) + zaa(ji  ,jj + 1    &   
+     &                  ,jk))* (zti(ji + 1,jj + 1,jk  ) + zti(ji + 1,jj    &   
+     &                  ,jk  ) - zti(ji - 1,jj + 1,jk  ) - zti(ji - 1,jj    &   
+     &                  ,jk  ))/ (zti(ji + 1,jj + 1,jk  ) + zti(ji + 1    &   
+     &                  ,jj  ,jk  ) + zti(ji - 1,jj + 1,jk  ) + zti(ji    &   
+     &                  - 1,jj  ,jk  ) + rtrn) + (zcc(ji  ,jj  ,jk  )    &   
+     &                  + zcc(ji  ,jj  ,jk + 1) + zcc(ji  ,jj + 1,jk  )    &   
+     &                  + zcc(ji  ,jj + 1,jk + 1))* (zti(ji  ,jj  ,jk -    &   
+     &                  1) + zti(ji  ,jj + 1,jk - 1) - zti(ji  ,jj  ,jk    &   
+     &                  +1) - zti(ji  ,jj + 1,jk + 1))/ (zti(ji  ,jj    &   
+     &                  ,jk- 1) + zti(ji  ,jj + 1,jk - 1) + zti(ji  ,jj    &   
+     &                  ,jk+ 1) + zti(ji  ,jj + 1,jk + 1) + rtrn))    &   
+     &                  /(e1v(ji,jj)*e2v(ji,jj)*fse3v(ji,jj,jk))    &   
+     &                  *umask(ji - 1,jj,jk  )*umask(ji - 1,jj + 1,jk  )    &   
+     &                  *umask(ji  ,jj,jk  )*umask(ji  ,jj + 1,jk  )    &   
+     &                  *tmask(ji  ,jj,jk)*tmask(ji  ,jj  ,jk + 1)    &   
+     &                  *tmask(ji  ,jj + 1,jk)*tmask(ji  ,jj + 1,jk + 1)      
+
+                    zz(ji,jj,jk) = zz(ji,jj,jk)    &   
+     &                  - 0.5*rdttrc(jk)*rsc*zcc(ji,jj,jk)*0.25*    &   
+     &                  (    (zaa(ji - 1,jj  ,jk  ) + zaa(ji  ,jj  ,jk    &   
+     &                  ) + zaa(ji  ,jj  ,jk - 1) + zaa(ji - 1,jj  ,jk -    &   
+     &                  1))*(zti(ji + 1,jj  ,jk - 1) + zti(ji + 1,jj    &   
+     &                  ,jk  ) - zti(ji - 1,jj  ,jk  ) - zti(ji - 1,jj    &   
+     &                  ,jk - 1))/(zti(ji + 1,jj  ,jk - 1) + zti(ji + 1    &   
+     &                  ,jj,jk  ) + zti(ji - 1,jj  ,jk  ) + zti(ji - 1    &   
+     &                  ,jj,jk - 1) + rtrn) + (zbb(ji  ,jj - 1,jk  )    &   
+     &                  + zbb(ji  ,jj  ,jk  ) + zbb(ji  ,jj  ,jk - 1)    &   
+     &                  + zbb(ji  ,jj - 1,jk - 1))*(zti(ji  ,jj + 1,jk -    &   
+     &                  1) + zti(ji  ,jj + 1,jk  ) - zti(ji  ,jj - 1,jk    &   
+     &                  ) - zti(ji  ,jj - 1,jk - 1))/(zti(ji  ,jj + 1,jk    &   
+     &                  - 1) + zti(ji  ,jj + 1,jk  ) + zti(ji  ,jj - 1    &   
+     &                  ,jk  ) + zti(ji  ,jj - 1,jk - 1) + rtrn))    &   
+     &                  /(e1t(ji,jj)*e2t(ji,jj)*fse3w(ji,jj,jk))    &   
+     &                  *umask(ji - 1,jj,jk  )*umask(ji  ,jj  ,jk  )    &   
+     &                  *umask(ji  ,jj,jk- 1)*umask(ji - 1,jj  ,jk - 1)    &   
+     &                  *vmask(ji  ,jj- 1,jk)*vmask(ji  ,jj  ,jk  )    &   
+     &                  *vmask(ji  ,jj  ,jk-1)*vmask(ji  ,jj - 1,jk - 1)       
+                  END DO
+                END DO
+              END DO
+
+              DO jj = 2,jpjm1
+                DO ji = 2,jpim1
+                  zx(ji,jj,1) = zx(ji,jj,1)    &   
+     &                - 0.5*rdttrc(jk)*rsc*zaa(ji,jj,1)*0.25*    &   
+     &                ( (zbb(ji  ,jj - 1,1  ) + zbb(ji + 1,jj - 1,1  )    &   
+     &                + zbb(ji + 1,jj  ,1  ) + zbb(ji  ,jj  ,1  ))    &   
+     &                *(zti(ji  ,jj + 1,1  ) + zti(ji + 1,jj + 1,1  )    &   
+     &                - zti(ji + 1,jj - 1,1  ) - zti(ji  ,jj - 1,1  ))    &   
+     &                /(zti(ji  ,jj + 1,1  ) + zti(ji + 1,jj + 1,1  )    &   
+     &                + zti(ji + 1,jj - 1,1  ) + zti(ji  ,jj - 1,1  ) +    &   
+     &                rtrn))/(e1u(ji,jj)*e2u(ji,jj)*fse3u(ji,jj,1))    &   
+     &                *vmask(ji  ,jj - 1,1  )*vmask(ji + 1,jj - 1,1  )    &   
+     &                *vmask(ji + 1,jj  ,1  )*vmask(ji  ,jj  ,1  )    
+
+                 zy(ji,jj,1) = zy(ji,jj,1)    &   
+     &                - 0.5*rdttrc(jk)*rsc*zbb(ji,jj,1)*0.25*    &   
+     &                ( (zaa(ji-1  ,jj ,1  ) + zaa(ji - 1,jj + 1,1  )    &   
+     &                + zaa(ji ,jj  ,1  ) + zaa(ji  ,jj + 1  ,1  ))    &   
+     &                *(zti(ji + 1,jj + 1,1  ) + zti(ji + 1,jj ,1  )    &   
+     &                - zti(ji - 1,jj + 1,1  ) - zti(ji - 1,jj ,1  ))    &   
+     &                /(zti(ji + 1,jj + 1,1  ) + zti(ji + 1,jj ,1  )    &   
+     &                + zti(ji - 1,jj + 1,1  ) + zti(ji - 1,jj ,1  ) +    &   
+     &                rtrn))/(e1v(ji,jj)*e2v(ji,jj)*fse3v(ji,jj,1))    &   
+     &                *umask(ji - 1,jj,1  )*umask(ji - 1,jj + 1,1  )    &   
+     &                *umask(ji    ,jj,1  )*umask(ji  ,jj + 1 ,1  )    
+
+                END DO
+              END DO
+          ENDIF
+
+          ! ... Lateral boundary conditions on z[xyz]
+          CALL lbc_lnk( zx, 'U', -1. )
+          CALL lbc_lnk( zy, 'V', -1. )
+          CALL lbc_lnk( zz, 'W',  1. )
+
+! 2.4 reinitialization
+
+          DO jk = 1,jpk
+            DO jj = 1,jpj
+              DO ji = 1,jpi
+                zaa(ji,jj,jk) = zx(ji,jj,jk)
+                zbb(ji,jj,jk) = zy(ji,jj,jk)
+                zcc(ji,jj,jk) = zz(ji,jj,jk)
+              END DO
+            END DO
+          END DO
+
+! 2.5 calcul of the final field:
+!    advection by antidiffusive mass fluxes and an upstream scheme
+
+          DO jk = 1,jpk
+             DO jj = 2,jpjm1
+                DO ji = 2,jpim1
+                   zfp_ui = 0.5 * ( zaa(ji,jj,jk) + ABS( zaa(ji,jj,jk) ) )
+                   zfp_vj = 0.5 * ( zbb(ji,jj,jk) + ABS( zbb(ji,jj,jk) ) )
+                   zfm_ui = 0.5 * ( zaa(ji,jj,jk) - ABS( zaa(ji,jj,jk) ) )
+                   zfm_vj = 0.5 * ( zbb(ji,jj,jk) - ABS( zbb(ji,jj,jk) ) )            
+                   zkx(ji,jj,jk) = zfp_ui * zti(ji,jj,jk) + zfm_ui * zti(ji+1,jj  ,jk) 
+                   zky(ji,jj,jk) = zfp_vj * zti(ji,jj,jk) + zfm_vj * zti(ji    ,jj+1,jk)             
+                END DO
+             END DO
+          END DO
+
+          DO jk = 2,jpk
+             DO jj = 1,jpj
+                DO ji = 1,jpi
+                   zfp_w = 0.5 * ( zcc(ji,jj,jk) + ABS( zcc(ji,jj,jk) ) )
+                   zfm_w = 0.5 * ( zcc(ji,jj,jk) - ABS( zcc(ji,jj,jk) ) )       
+                   zkz(ji,jj,jk) = zfp_w * zti(ji,jj,jk) + zfm_w * zti(ji,jj,jk-1)     
+                END DO
+             END DO
+          END DO
+
+
+! ... Lateral boundary conditions on zk[xy]
+      CALL lbc_lnk( zkx, 'U', -1. )
+      CALL lbc_lnk( zky, 'V', -1. )
+
+
+! 2.6. calcul of after field using an upstream advection scheme
+
+          DO jk = 1,jpkm1
+            DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+                zbtr = 1./(e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk))
+                ztj(ji,jj,jk) = -zbtr*     &  
+     &              ( zkx(ji,jj,jk) - zkx(ji - 1,jj,jk)    &  
+     &              + zky(ji,jj,jk) - zky(ji,jj - 1,jk)    &  
+     &              + zkz(ji,jj,jk) - zkz(ji,jj,jk + 1) )
+#if defined key_trc_diatrd
+                IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) -    &  
+     &              zbtr*( zkx(ji,jj,jk) - zkx(ji - 1,jj,jk) )   
+
+                IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) -    &  
+     &              zbtr*( zky(ji,jj,jk) - zky(ji,jj - 1,jk) )
+
+                IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3) -    &  
+     &              zbtr*( zkz(ji,jj,jk) - zkz(ji,jj,jk + 1) )
+#endif
+              END DO
+            END DO
+          END DO
+
+! 2.6 END of antidiffusive correction loop
+
+        END DO
+
+! 3. trend due to horizontal and vertical advection of tracer jn
+! --------------------------------------------------------------
+
+        DO jk = 1,jpk
+          DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+              ztra = ( zbuf(ji,jj,jk) + ztj(ji,jj,jk) ) * tmask(ji,jj,jk)
+              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+            END DO
+          END DO
+        END DO
+
+! 4.0 convert the transport trend into advection trend
+! ----------------------------------------------------
+
+#if defined key_trc_diatrd
+        DO jk = 1,jpk
+          DO jj = 2,jpjm1
+            DO  ji = 2,jpim1
+              zbtr = 1./(e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk))
+              zgm = zbtr * trn(ji,jj,jk,jn) *     &  
+     &            ( zun(ji  ,jj,jk) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk)    &  
+     &            -zun(ji-1,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk))
+
+              zgz = zbtr * trn(ji,jj,jk,jn) *     &  
+     &            ( zvn(ji,jj  ,jk) * e1v(ji,jj  ) * fse3v(ji,jj  ,jk)    &  
+     &            -zvn(ji,jj-1,jk) * e1v(ji,jj-1) * fse3v(ji,jj-1,jk))
+
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) + zgm
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) + zgz
+              IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3)    &  
+     &            - trn(ji,jj,jk,jn) * hdivn(ji,jj,jk)
+            END DO
+          END DO
+        END DO
+
+        ! Lateral boundary conditions on trtrd:
+
+        IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),1), 'T', 1. )
+        IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),2), 'T', 1. )
+        IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),3), 'T', 1. )
+#endif
+
+ 
+        ! END of tracer loop
+        ! ==================
+     ENDDO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('smolar - adv')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+     
+  END SUBROUTINE trc_adv_smolar
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_adv_smolar( kt ) 
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_adv_smolar: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_adv_smolar
+#endif
+
+   !!======================================================================
+END MODULE trcadv_smolar
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_tvd.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_tvd.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcadv_tvd.F90	(revision 4536)
@@ -0,0 +1,499 @@
+MODULE trcadv_tvd
+   !!==============================================================================
+   !!                       ***  MODULE  trcadv_tvd  ***
+   !! Ocean passive tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_adv_tvd  : update the passive tracer trend with the horizontal
+   !!                  and vertical advection trends using a TVD scheme
+   !!   nonosc       : compute monotonic tracer fluxes by a nonoscillatory
+   !!                  algorithm 
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE lbclnk              ! ocean lateral boundary conditions (or mpp link)
+   USE trcbbl              ! advective passive tracers in the BBL
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_adv_tvd    ! routine called by trcstp.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_adv_tvd( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_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 tra with the now advective tracer trends
+      !!             - save the trends in trtrd ('key_trc_diatrd)
+      !!
+      !! History :
+      !!        !  95-12  (L. Mortier)  Original code
+      !!        !  00-01  (H. Loukos)  adapted to ORCA 
+      !!        !  00-10  (MA Foujols E.Kestenare)  include file not routine
+      !!        !  00-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
+      !!        !  01-07  (E. Durand G. Madec)  adaptation to ORCA config
+      !!   9.0  !  02-06  (C. Ethe, G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Modules used
+#if defined key_trcbbl_adv
+      USE oce_trc            , zun => ua,  &  ! use ua as workspace
+         &                     zvn => va      ! use va as workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwn
+#else
+      USE oce_trc            , zun => un,  &  ! When no bbl, zun == un
+                               zvn => vn,  &  !             zvn == vn
+                               zwn => wn      !             zwn == wn
+#endif
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk,jn           ! dummy loop indices
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zti, ztu, ztv, ztw                ! temporary workspace
+
+      REAL(wp) ::   &
+         z2dtt, zbtr, zeu, zev, zew, z2, &  ! temporary scalar
+         zfp_ui, zfp_vj, zfp_wk,         &  !    "         "
+         zfm_ui, zfm_vj, zfm_wk             !    "         "
+
+#if defined key_trc_diatrd
+       REAL(wp) :: &
+          zgm, zgz
+#endif
+
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      zti(:,:,:) = 0.e0
+
+      IF( kt == nittrc000  .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_adv_tvd : TVD advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+         z2=1.
+      ELSE
+         z2=2.
+      ENDIF
+
+#if defined key_trcbbl_adv
+      ! Advective Bottom boundary layer: add the velocity
+      ! -------------------------------------------------
+      zun(:,:,:) = un (:,:,:) - u_trc_bbl(:,:,:)
+      zvn(:,:,:) = vn (:,:,:) - v_trc_bbl(:,:,:)
+      zwn(:,:,:) = wn (:,:,:) + w_trc_bbl(:,:,:)
+#endif
+
+      DO jn = 1, jptra
+
+         ! 1. Bottom value : flux set to zero
+         ! ---------------
+         ztu(:,:,jpk) = 0.e0
+         ztv(:,:,jpk) = 0.e0
+         ztw(:,:,jpk) = 0.e0
+         zti(:,:,jpk) = 0.e0
+
+
+         ! 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.
+                  zeu = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                  zev = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+                  ! upstream scheme
+                  zfp_ui = zeu + ABS( zeu )
+                  zfm_ui = zeu - ABS( zeu )
+                  zfp_vj = zev + ABS( zev )
+                  zfm_vj = zev - ABS( zev )
+                  ztu(ji,jj,jk) = zfp_ui * trb(ji,jj,jk,jn) + zfm_ui * trb(ji+1,jj  ,jk,jn)
+                  ztv(ji,jj,jk) = zfp_vj * trb(ji,jj,jk,jn) + zfm_vj * trb(ji  ,jj+1,jk,jn)
+               END DO
+            END DO
+         END DO
+
+         ! upstream tracer flux in the k direction
+         ! Surface value
+         IF( lk_dynspg_rl ) THEN   ! rigid lid : flux set to zero
+            ztw(:,:,1) = 0.e0
+         ELSE                      ! free surface 
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zew = e1t(ji,jj) * e2t(ji,jj) * zwn(ji,jj,1)
+                  ztw(ji,jj,1) = zew * trb(ji,jj,1,jn)
+               END DO
+            END DO
+         ENDIF
+
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zew = 0.5 * e1t(ji,jj) * e2t(ji,jj) * zwn(ji,jj,jk)
+                  zfp_wk = zew + ABS( zew )
+                  zfm_wk = zew - ABS( zew )
+                  ztw(ji,jj,jk) = zfp_wk * trb(ji,jj,jk,jn) + zfm_wk * trb(ji,jj,jk-1,jn)
+               END DO
+            END DO
+         END DO
+
+         ! total advective trend
+         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) )
+                  zti(ji,jj,jk) = - ( ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk  )   &
+                     &              + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  )   &
+                     &              + ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1) ) * zbtr
+
+#if defined key_trc_diatrd
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) -  &
+                        &                          zbtr * ( ztu(ji,jj,jk) - ztu(ji-1,jj,jk) )                     
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) -  &
+                        &                          zbtr * ( ztv(ji,jj,jk) - ztv(ji,jj-1,jk) )                     
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3) -  &
+                        &                          zbtr * ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) )
+#endif
+               END DO
+            END DO
+         END DO
+
+
+         ! update and guess with monotonic sheme
+         DO jk = 1, jpkm1
+            z2dtt = z2 * rdttra(jk) * FLOAT(ndttrc)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  tra(ji,jj,jk,jn) =  tra(ji,jj,jk,jn) + zti(ji,jj,jk)
+                  zti (ji,jj,jk) = ( trb(ji,jj,jk,jn) + z2dtt * zti(ji,jj,jk) ) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Lateral boundary conditions on zti, zsi   (unchanged sign)
+         CALL lbc_lnk( zti, 'T', 1. )
+
+         ! 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.
+                  zeu = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * zun(ji,jj,jk)
+                  zev = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * zvn(ji,jj,jk)
+                  ztu(ji,jj,jk) = zeu * ( trn(ji,jj,jk,jn) + trn(ji+1,jj,jk,jn) ) - ztu(ji,jj,jk)
+                  ztv(ji,jj,jk) = zev * ( trn(ji,jj,jk,jn) + trn(ji,jj+1,jk,jn) ) - ztv(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! antidiffusive flux on k
+         ! Surface value
+         ztw(:,:,1) = 0.
+
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zew = 0.5 * e1t(ji,jj) * e2t(ji,jj) * zwn(ji,jj,jk)
+                  ztw(ji,jj,jk) = zew * ( trn(ji,jj,jk,jn) + trn(ji,jj,jk-1,jn) ) - ztw(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Lateral bondary conditions
+         CALL lbc_lnk( ztu, 'U', -1. )
+         CALL lbc_lnk( ztv, 'V', -1. )
+         CALL lbc_lnk( ztw, 'W',  1. )
+
+         ! 4. monotonicity algorithm
+         ! -------------------------
+         CALL nonosc( trb(:,:,:,jn), ztu, ztv, ztw, zti, z2 )
+
+
+         ! 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) )
+#if defined key_trc_diatrd
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) -  &
+                        &                          zbtr * ( ztu(ji,jj,jk) - ztu(ji-1,jj,jk) )                     
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) -  &
+                        &                          zbtr * ( ztv(ji,jj,jk) - ztv(ji,jj-1,jk) )                     
+                  IF ( luttrd(jn) ) &
+                     trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3) -  &
+                        &                          zbtr * ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) )
+#endif
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn)   &
+                     &         - ( ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk  )   &
+                     &           + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  )   &
+                     &           + ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1) ) * zbtr
+               END DO
+            END DO
+         END DO
+         ! 6.0 convert the transport trend into advection trend
+         ! ----------------------------------------------------
+         
+#if defined key_trc_diatrd
+         DO jk = 1,jpk
+            DO jj = 2,jpjm1
+               DO  ji = 2,jpim1
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zgm = zbtr * trn(ji,jj,jk,jn) *     &
+                     &         (  zun(ji  ,jj,jk) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk)    &
+                     &          - zun(ji-1,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) )
+                  
+                  zgz = zbtr * trn(ji,jj,jk,jn) *     &
+                     &         (  zvn(ji,jj  ,jk) * e1v(ji,jj  ) * fse3v(ji,jj  ,jk)    &
+                     &          - zvn(ji,jj-1,jk) * e1v(ji,jj-1) * fse3v(ji,jj-1,jk) )
+                  
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),1) = trtrd(ji,jj,jk,ikeep(jn),1) + zgm
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),2) = trtrd(ji,jj,jk,ikeep(jn),2) + zgz
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = trtrd(ji,jj,jk,ikeep(jn),3)    &
+                     &            - trn(ji,jj,jk,jn) * hdivn(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         
+         ! Lateral boundary conditions on trtrd:
+         
+         IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),1), 'T', 1. )
+         IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),2), 'T', 1. )
+         IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),3), 'T', 1. )
+#endif
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('tvd - adv')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_adv_tvd
+
+
+   SUBROUTINE nonosc( pbef, paa, pbb, pcc, paft, prdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  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
+      !!
+      !! History :
+      !!        !  97-04  (L. Mortier) Original code
+      !!        !  00-02  (H. Loukos)  rewritting for opa8
+      !!        !  00-10  (M.A Foujols, E. Kestenare)  lateral b.c.
+      !!        !  01-07  (E. Durand G. Madec)  adapted for T & S
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), INTENT( in ) ::   &
+         prdt                               ! ???
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT( inout ) ::   &
+         pbef,                            & ! before field
+         paft,                            & ! after field
+         paa,                             & ! monotonic flux in the i direction
+         pbb,                             & ! monotonic flux in the j direction
+         pcc                                ! monotonic flux in the k direction
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      INTEGER ::   ikm1
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zbetup, zbetdo
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt
+      !!----------------------------------------------------------------------
+
+      zbig = 1.e+40
+      zrtrn = 1.e-15
+      zbetup(:,:,:) = 0.e0   ;   zbetdo(:,:,:) = 0.e0
+
+      ! Search local extrema
+      ! --------------------
+      ! large negative value (-zbig) inside land
+      ! large negative value (-zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search maximum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetup(ji,jj,jk) = MAX(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji-1,jj  ,jk  ), pbef(ji+1,jj  ,jk  ),   &
+                  &                     paft(ji-1,jj  ,jk  ), paft(ji+1,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj-1,jk  ), pbef(ji  ,jj+1,jk  ),   &
+                  &                     paft(ji  ,jj-1,jk  ), paft(ji  ,jj+1,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+      ! large positive value (+zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search minimum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetdo(ji,jj,jk) = MIN(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji-1,jj  ,jk  ), pbef(ji+1,jj  ,jk  ),   &
+                  &                     paft(ji-1,jj  ,jk  ), paft(ji+1,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj-1,jk  ), pbef(ji  ,jj+1,jk  ),   &
+                  &                     paft(ji  ,jj-1,jk  ), paft(ji  ,jj+1,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+
+      ! restore masked values to zero
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:)
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:)
+ 
+
+      ! 2. Positive and negative part of fluxes and beta terms
+      ! ------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         z2dtt = prdt * rdttra(jk) * FLOAT(ndttrc)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! positive & negative 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  ) )
+               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) = ( zbetup(ji,jj,jk) - paft(ji,jj,jk) ) / (zpos+zrtrn) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zbetdo(ji,jj,jk) ) / (zneg+zrtrn) * zbt
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on zbetup & zbetdo   (unchanged sign)
+      CALL lbc_lnk( zbetup, 'T', 1. )
+      CALL lbc_lnk( zbetdo, 'T', 1. )
+
+
+      ! 3. monotonic flux in the i direction, i.e. paa
+      ! ----------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zc = paa(ji,jj,jk)
+               IF( zc >= 0. ) THEN
+                  za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
+                  paa(ji,jj,jk) = za * zc
+               ELSE
+                  zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
+                  paa(ji,jj,jk) = zb * zc
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on paa   (changed sign)
+      CALL lbc_lnk( paa, 'U', -1. )
+
+
+      ! 4. monotonic flux in the j direction, i.e. pbb
+      ! ----------------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zc = pbb(ji,jj,jk)
+               IF( zc >= 0. ) THEN
+                  za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
+                  pbb(ji,jj,jk) = za * zc
+               ELSE
+                  zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
+                  pbb(ji,jj,jk) = zb * zc
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on pbb   (changed sign)
+      CALL lbc_lnk( pbb, 'V', -1. )
+
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zc = pcc(ji,jj,jk)
+               IF( zc >= 0. ) THEN
+                  za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji,jj,jk-1) )
+                  pcc(ji,jj,jk) = za * zc
+               ELSE
+                  zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji,jj,jk-1) )
+                  pcc(ji,jj,jk) = zb * zc
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! lateral boundary condition on pcc   (unchanged sign)
+      CALL lbc_lnk( pcc, 'W', 1. )
+
+   END SUBROUTINE nonosc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_adv_tvd( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_adv_tvd: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_adv_tvd
+#endif
+
+   !!======================================================================
+END MODULE trcadv_tvd
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbc.F90	(revision 4536)
@@ -0,0 +1,237 @@
+MODULE trcbbc
+   !!======================================================================
+   !!                       ***  MODULE  trcbbc  ***
+   !! Ocean passive tracers:  bottom boundary condition
+   !!======================================================================
+#if  defined key_top  &&  defined key_trcbbc
+   !!----------------------------------------------------------------------
+   !!   'key_top' and 'key_trcbbc'       TOP model and geothermal heat flux
+   !!----------------------------------------------------------------------
+   !!   trc_bbc      : update the tracer trend at ocean bottom 
+   !!   trc_bbc_init : initialization of geothermal heat flux trend
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE prtctl_trc          ! Print control for debbuging
+ 
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_bbc          ! routine called by trcstp.F90
+
+   !! to be transfert in the namelist ???!   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trcbbc = .TRUE.   !: bbc flag
+
+   !! * Module variables
+   INTEGER ::                       & !!! ** bbc namelist (nambbc) **
+      ngeo_trc_flux = 1                    ! Geothermal flux (0:no flux, 1:constant flux,
+      !                                !                  2:read in file )
+   REAL(wp) ::                      & !!! ** bbc namlist **
+      ngeo_trc_flux_const = 86.4e-3        ! Constant value of geothermal heat flux
+
+   INTEGER, DIMENSION(jpi,jpj) ::   &
+      nbotlevt                         ! ocean bottom level index at T-pt
+   REAL(wp), DIMENSION(jpi,jpj) ::  &
+      qgh_trd                          ! geothermal heating trend
+ 
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!  TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_bbc( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_bbc  ***
+      !!
+      !! ** Purpose :   Compute the bottom boundary contition on passive tracer 
+      !!      associated with geothermal heating and add it to the general
+      !!      trend of tracers equations.
+      !!
+      !! ** Method  :   The geothermal heat flux set to its constant value of 
+      !!       86.4 mW/m2 (Stein and Stein 1992, Huang 1999).
+      !!       The temperature trend associated to this heat flux through the
+      !!       ocean bottom can be computed once and is added to the temperature
+      !!       trend juste above the bottom at each time step:
+      !!            tra = tra + Qsf / (rau0 rcp e3T) for k= mbathy -1
+      !!       Where Qsf is the geothermal heat flux.
+      !!
+      !! ** Action  : - update the temperature trends tra with the trend of
+      !!                the ocean bottom boundary condition
+      !!
+      !! References :
+      !!      Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
+      !!
+      !! History :
+      !!   8.1  !  99-10  (G. Madec)  original code
+      !!   8.5  !  02-08  (G. Madec)  free form + modules
+      !!   9.0  !  04-03  (C. Ethe)  adpated for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+
+      !! * Local declarations
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      INTEGER ::   ji, jn                  ! dummy loop indices
+#else
+      INTEGER ::   ji, jj, jn              ! dummy loop indices
+#endif
+      REAL(wp) ::   ztra                ! temporary scalar
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialization
+      IF( kt == nittrc000 )   CALL trc_bbc_init
+
+      ! 1. Add the geothermal heat flux trend on temperature
+
+      SELECT CASE ( ngeo_trc_flux )
+
+      CASE ( 1:2 )                !  geothermal heat flux
+
+         DO jn = 1, jptra
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+            DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+               tra(ji,1,nbotlevt(ji,1),jn) = tra(ji,1,nbotlevt(ji,1),jn) + qgh_trd(ji,1)
+            END DO
+#else
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  tra(ji,jj,nbotlevt(ji,jj),jn) = tra(ji,jj,nbotlevt(ji,jj),jn) + qgh_trd(ji,jj)
+               END DO
+            END DO
+#endif
+         END DO
+
+         IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+            WRITE(charout, FMT="('bbc')")
+            CALL prt_ctl_trc_info(charout)
+            CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+         ENDIF
+      END SELECT
+
+   END SUBROUTINE trc_bbc
+
+
+   SUBROUTINE trc_bbc_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_bbc_init  ***
+      !!
+      !! ** Purpose :   Compute once for all the trend associated with geo-
+      !!      thermal heating that will be applied at each time step at the
+      !!      bottom ocean level
+      !!
+      !! ** Method  :   Read the namtrabbc namelist and check the parameters.
+      !!      called at the first time step (nittrc000)
+      !!
+      !! ** Input   : - Namlist namtrcbbc
+      !!              - NetCDF file  : passivetrc_geothermal_heating.nc 
+      !!                               ( if necessary )
+      !!
+      !! ** Action  : - compute the heat geothermal trend qgh_trd
+      !!              - compute the bottom ocean level nbotlevt
+      !!
+      !! history :
+      !!  8.5  ! 02-11 (A. Bozec) original code
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+
+      !! * local declarations
+      CHARACTER (len=32) ::   clname
+      INTEGER  ::   ji, jj              ! dummy loop indices
+      INTEGER  ::   inum = 11           ! temporary logical unit
+
+      NAMELIST/namtrcbbc/ngeo_trc_flux, ngeo_trc_flux_const 
+      !!----------------------------------------------------------------------
+
+      ! Read Namelist nambbc : bottom momentum boundary condition
+      REWIND ( numnamtra )
+      READ   ( numnamtra, namtrcbbc )
+
+      ! Control print
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_bbc : Passive tracers Bottom Boundary Condition (bbc)'
+      IF(lwp) WRITE(numout,*) '~~~~~~~   Geothermal heatflux'
+      IF(lwp) WRITE(numout,*) '          Namelist namtrcbbc : set bbc parameters'
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '             Geothermal flux           ngeo_trc_flux       = ', ngeo_trc_flux
+      IF(lwp) WRITE(numout,*) '             Constant geothermal flux  ngeo_trc_flux_const = ', ngeo_trc_flux_const
+      IF(lwp) WRITE(numout,*)
+
+      ! level of the ocean bottom at T-point
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            nbotlevt(ji,jj) = MAX( mbathy(ji,jj)-1, 1 )
+         END DO
+      END DO
+
+      ! initialization of geothermal heat flux
+
+      SELECT CASE ( ngeo_trc_flux )
+
+      CASE ( 0 )                ! no geothermal heat flux
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '             *** no geothermal heat flux'
+
+      CASE ( 1 )                ! constant flux
+         IF(lwp) WRITE(numout,*) '             *** constant heat flux  =   ', ngeo_trc_flux_const
+         qgh_trd(:,:) = ngeo_trc_flux_const
+
+      CASE ( 2 )                ! variable geothermal heat flux
+         ! read the geothermal fluxes in mW/m2
+         CALL iom_open ( 'geothermal_heating_trc.nc', inum )
+         CALL iom_get ( inum, jpdom_data, 'heatflow', qgh_trd )
+         CALL iom_close (inum)
+
+         qgh_trd(:,:) = qgh_trd(:,:) * 1.e-3 ! conversion in W/m2
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '     bad flag value for ngeo_flux = ', ngeo_flux
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+
+      ! geothermal heat flux trend
+
+      SELECT CASE ( ngeo_trc_flux )
+
+      CASE ( 1:2 )                !  geothermal heat flux
+
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+            qgh_trd(ji,1) = ro0cpr * qgh_trd(ji,1) / fse3t(ji,1,nbotlevt(ji,1) )
+         END DO
+#else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               qgh_trd(ji,jj) = ro0cpr * qgh_trd(ji,jj) / fse3t(ji,jj,nbotlevt(ji,jj))
+            END DO
+         END DO
+#endif
+
+      END SELECT
+
+   END SUBROUTINE trc_bbc_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trcbbc = .FALSE.  !: bbc flag
+CONTAINS
+   SUBROUTINE trc_bbc( kt )           ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_bbc: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bbc
+#endif
+
+   !!======================================================================
+END MODULE trcbbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 4536)
@@ -0,0 +1,555 @@
+MODULE trcbbl
+   !!==============================================================================
+   !!                       ***  MODULE  trcbbl  ***
+   !! Ocean passive tracers physics :  advective and/or diffusive bottom boundary 
+   !!                                  layer scheme
+   !!==============================================================================
+#if  defined key_top && ( defined key_trcbbl_dif   ||   defined key_trcbbl_adv ) && ! defined key_cfg_1d
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   'key_top'         and                                    TOP models
+   !!   'key_trcbbl_dif'   or               diffusive bottom boundary layer
+   !!   'key_trcbbl_adv'                    advective bottom boundary layer
+   !!----------------------------------------------------------------------
+   !!   trc_bbl_dif  : update the passive tracer trends due to the bottom
+   !!                  boundary layer (diffusive only)
+   !!   trc_bbl_adv  : update the passive tracer trends due to the bottom
+   !!                  boundary layer (advective and/or diffusive)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE trctrp_lec      ! passive tracers transport
+   USE prtctl_trc          ! Print control for debbuging
+   USE eosbn2
+   USE lbclnk
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_bbl_dif    ! routine called by step.F90
+   PUBLIC trc_bbl_adv    ! routine called by step.F90
+
+   !! * Shared module variables
+# if defined key_trcbbl_dif
+   LOGICAL, PUBLIC, PARAMETER ::    &  !:
+      lk_trcbbl_dif = .TRUE.   !: advective bottom boundary layer flag
+
+# else
+   LOGICAL, PUBLIC, PARAMETER ::    &  !:
+      lk_trcbbl_dif = .FALSE.  !: advective bottom boundary layer flag
+# endif
+
+# if defined key_trcbbl_adv
+   LOGICAL, PUBLIC, PARAMETER ::    &  !:
+      lk_trcbbl_adv = .TRUE.   !: advective bottom boundary layer flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
+       u_trc_bbl, v_trc_bbl, &  !: velocity involved in exhanges in the advective BBL
+       w_trc_bbl                !: vertical increment of velocity due to advective BBL
+       !                        !  only affect tracer vertical advection
+# else
+   LOGICAL, PUBLIC, PARAMETER ::    &  !:
+      lk_trcbbl_adv = .FALSE.  !: advective bottom boundary layer flag
+# endif
+
+   !! * Module variables
+   INTEGER, DIMENSION(jpi,jpj) ::   &  !:
+      mbkt, mbku, mbkv                 ! ???
+
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_bbl_dif( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_bbl_dif  ***
+      !!
+      !! ** Purpose :   Compute the before tracer trend associated 
+      !!      with the bottom boundary layer and add it to the general trend 
+      !!      of tracer equations. The bottom boundary layer is supposed to be
+      !!      a purely diffusive bottom boundary layer.
+      !!
+      !! ** Method  :   When the product grad( rho) * grad(h) < 0 (where grad 
+      !!      is an along bottom slope gradient) an additional lateral diffu-
+      !!      sive trend along the bottom slope is added to the general tracer
+      !!      trend, otherwise nothing is done.
+      !!      Second order operator (laplacian type) with variable coefficient
+      !!      computed as follow for temperature (idem on s): 
+      !!         difft = 1/(e1t*e2t*e3t) { di-1[ ahbt e2u*e3u/e1u di[ztb] ]
+      !!                                 + dj-1[ ahbt e1v*e3v/e2v dj[ztb] ] }
+      !!      where ztb is a 2D array: the bottom ocean temperature and ahtb
+      !!      is a time and space varying diffusive coefficient defined by:
+      !!         ahbt = zahbp    if grad(rho).grad(h) < 0
+      !!              = 0.       otherwise.
+      !!      Note that grad(.) is the along bottom slope gradient. grad(rho)
+      !!      is evaluated using the local density (i.e. referenced at the
+      !!      local depth). Typical value of ahbt is 2000 m2/s (equivalent to
+      !!      a downslope velocity of 20 cm/s if the condition for slope
+      !!      convection is satified)
+      !!      Add this before trend to the general trend tra of the 
+      !!      botton ocean tracer point:
+      !!         tra = tra + difft
+      !!
+      !! ** Action  : - update tra at the bottom level with the bottom
+      !!                boundary layer trend
+      !!
+      !! References :
+      !!     Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!
+      !! History :
+      !!   8.0  !  96-06  (L. Mortier)  Original code
+      !!   8.0  !  97-11  (G. Madec)  Optimization
+      !!   8.5  !  02-08  (G. Madec)  free form + modules
+      !!   9.0  !  04-03  (C. Ethe)   Adaptation for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments 
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,jn                ! dummy loop indices
+      INTEGER ::   ik
+      INTEGER ::   ii0, ii1, ij0, ij1       ! temporary integers
+      INTEGER  ::   iku1, iku2, ikv1,ikv2   ! temporary intergers
+      REAL(wp) ::   ze3u, ze3v              ! temporary scalars
+      INTEGER ::   iku, ikv
+      REAL(wp) ::   &
+         zsign, zt, zs, zh, zalbet,      &  ! temporary scalars
+         zgdrho, zbtr, ztra
+      REAL(wp), DIMENSION(jpi,jpj) ::    &
+        zki, zkj, zkx, zky,    &  ! temporary workspace arrays
+        ztnb, zsnb, zdep,                &
+        ztrb, zahu, zahv
+      CHARACTER (len=22) :: charout
+      REAL(wp) ::   &
+         fsalbt, pft, pfs, pfh              ! statement function
+      !!----------------------------------------------------------------------
+      ! ratio alpha/beta
+      ! ================
+      !  fsalbt: ratio of thermal over saline expension coefficients
+      !       pft :  potential temperature in degrees celcius
+      !       pfs :  salinity anomaly (s-35) in psu
+      !       pfh :  depth in meters
+
+      fsalbt( pft, pfs, pfh ) =                                              &
+         ( ( ( -0.255019e-07 * pft + 0.298357e-05 ) * pft                    &
+                                   - 0.203814e-03 ) * pft                    &
+                                   + 0.170907e-01 ) * pft                    &
+                                   + 0.665157e-01                            &
+         +(-0.678662e-05 * pfs - 0.846960e-04 * pft + 0.378110e-02 ) * pfs   &
+         +  ( ( - 0.302285e-13 * pfh                                         &
+                - 0.251520e-11 * pfs                                         &
+                + 0.512857e-12 * pft * pft          ) * pfh                  &
+                                     - 0.164759e-06   * pfs                  &
+             +(   0.791325e-08 * pft - 0.933746e-06 ) * pft                  &
+                                     + 0.380374e-04 ) * pfh   
+      !!----------------------------------------------------------------------
+
+
+      IF( kt == nittrc000 )   CALL trc_bbl_init
+
+
+      ! 0. 2D fields of bottom temperature and salinity, and bottom slope
+      ! -----------------------------------------------------------------
+      ! mbathy= number of w-level, minimum value=1 (cf dommsk.F)
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#  else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#  endif
+            ik = mbkt(ji,jj)                              ! index of the bottom ocean T-level
+            ztnb(ji,jj) = tn(ji,jj,ik) * tmask(ji,jj,1)   ! masked now T and S at ocean bottom 
+            zsnb(ji,jj) = sn(ji,jj,ik) * tmask(ji,jj,1)
+            zdep(ji,jj) = fsdept(ji,jj,ik)                ! depth of the ocean bottom T-level
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#  endif
+      END DO
+
+      IF( ln_zps ) THEN      ! partial steps correction
+
+#   if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#   else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#   endif
+               iku1 = MAX( mbathy(ji+1,jj  )-1, 1 )
+               iku2 = MAX( mbathy(ji  ,jj  )-1, 1 )
+               ikv1 = MAX( mbathy(ji  ,jj+1)-1, 1 )
+               ikv2 = MAX( mbathy(ji  ,jj  )-1, 1 )
+               ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+               ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+               zahu(ji,jj) = atrcbbl * e2u(ji,jj) * ze3u / e1u(ji,jj) * umask(ji,jj,1)
+               zahv(ji,jj) = atrcbbl * e1v(ji,jj) * ze3v / e2v(ji,jj) * vmask(ji,jj,1)
+#   if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#   endif
+         END DO
+      ELSE                  ! z-coordinate - full steps or s-coordinate
+#   if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#   else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#   endif
+               iku = mbku(ji,jj)
+               ikv = mbkv(ji,jj)
+               zahu(ji,jj) = atrcbbl * e2u(ji,jj) * fse3u(ji,jj,iku) / e1u(ji,jj) * umask(ji,jj,1)
+               zahv(ji,jj) = atrcbbl * e1v(ji,jj) * fse3v(ji,jj,ikv) / e2v(ji,jj) * vmask(ji,jj,1)
+#   if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#   endif
+         END DO
+     ENDIF
+
+!!
+!!     OFFLINE VERSION OF DIFFUSIVE BBL
+!!
+#if defined key_off_tra
+
+      ! 2. Additional second order diffusive trends
+      ! -------------------------------------------
+
+      DO jn = 1, jptra
+         ! first derivative (gradient)
+         
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#  else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+#  endif
+               ik = mbkt(ji,jj) 
+               ztrb(ji,jj) = trb(ji,jj,ik,jn) * tmask(ji,jj,1)
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#  endif
+         END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#  endif
+               zkx(ji,jj) = bblx(ji,jj) * zahu(ji,jj) * ( ztrb(ji+1,jj) - ztrb(ji,jj) )
+               zky(ji,jj) = bbly(ji,jj) * zahv(ji,jj) * ( ztrb(ji,jj+1) - ztrb(ji,jj) )
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#  endif
+         END DO
+!!
+!!  ONLINE VERSION OF DIFFUSIVE BBL
+!!
+#else
+      ! 1. Criteria of additional bottom diffusivity: grad(rho).grad(h)<0
+      ! --------------------------------------------
+      ! Sign of the local density gradient along the i- and j-slopes
+      ! multiplied by the slope of the ocean bottom
+	SELECT CASE ( neos )
+
+      	CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+            zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+            ! masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh )*umask(ji,jj,1)
+            ! local density gradient along i-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
+                   -          ( zsnb(ji+1,jj) - zsnb(ji,jj) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#  endif
+      END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+            zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+            ! masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh )*vmask(ji,jj,1)
+            ! local density gradient along j-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
+                   -          ( zsnb(ji,jj+1) - zsnb(ji,jj) )
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#  endif
+      END DO
+
+	CASE ( 1 )               ! Linear formulation function of temperature only
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! local density gradient along i-bathymetric slope
+            zgdrho =  ( ztnb(ji+1,jj) - ztnb(ji,jj) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#  endif
+      END DO
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+#  endif
+            ! local density gradient along j-bathymetric slope
+            zgdrho =  ( ztnb(ji,jj+1) - ztnb(ji,jj) )
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#  endif
+      END DO
+
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+            ! local density gradient along i-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji+1,jj) - zsnb(ji,jj) )   &
+                     -  ralpha*( ztnb(ji+1,jj) - ztnb(ji,jj) ) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+ 	    zki(ji,jj) = ( 0.5 - zsign ) * zahu(ji,jj)
+        END DO
+      END DO
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+            ! local density gradient along j-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji,jj+1) - zsnb(ji,jj) )   &
+                     -  ralpha*( ztnb(ji,jj+1) - ztnb(ji,jj) ) )
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = sign( 0.5, -zgdrho * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zkj(ji,jj) = ( 0.5 - zsign ) * zahv(ji,jj)
+         END DO
+      END DO
+
+
+      CASE DEFAULT
+
+         WRITE(ctmp1,*) '          bad flag value for neos = ', neos
+         CALL ctl_stop( ctmp1 )
+
+      END SELECT
+      
+      ! 2. Additional second order diffusive trends
+      ! -------------------------------------------
+
+      DO jn = 1, jptra
+         ! first derivative (gradient)
+
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#  else
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+#  endif
+               ik = mbkt(ji,jj)
+               ztrb(ji,jj) = trb(ji,jj,ik,jn) * tmask(ji,jj,1)
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#  endif
+         END DO
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#  else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+#  endif
+               zkx(ji,jj) = zki(ji,jj) * ( ztrb(ji+1,jj) - ztrb(ji,jj) )
+               zky(ji,jj) = zkj(ji,jj) * ( ztrb(ji,jj+1) - ztrb(ji,jj) )
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#  endif
+         END DO
+#endif
+
+         IF( cp_cfg == "orca" ) THEN
+            
+            SELECT CASE ( jp_cfg )
+               !                                           ! =======================
+            CASE ( 2 )                                  !  ORCA_R2 configuration
+               !                                        ! =======================
+               ! Gibraltar enhancement of BBL
+               ij0 = 102   ;   ij1 = 102
+               ii0 = 139   ;   ii1 = 140  
+               zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               
+               ! Red Sea enhancement of BBL
+               ij0 =  88   ;   ij1 =  88
+               ii0 = 161   ;   ii1 = 162
+               zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               
+               !                                        ! =======================
+            CASE ( 4 )                                  !  ORCA_R4 configuration
+               !                                        ! =======================
+               ! Gibraltar enhancement of BBL
+               ij0 =  52   ;   ij1 =  52
+               ii0 =  70   ;   ii1 =  71  
+               zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
+               
+            END SELECT
+            
+         ENDIF
+         
+         ! second derivative (divergence) and add to the general tracer trend
+#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+#  else
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+#  endif
+               ik = MAX( mbathy(ji,jj)-1, 1 )
+               zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,ik) )
+               ztra = (  zkx(ji,jj) - zkx(ji-1,jj  )    &
+                  &    + zky(ji,jj) - zky(ji  ,jj-1)  ) * zbtr
+               tra(ji,jj,ik,jn) = tra(ji,jj,ik,jn) + ztra
+#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+#  endif
+         END DO
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('bbl - dif')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_bbl_dif
+
+# if defined key_trcbbl_adv
+   !!----------------------------------------------------------------------
+   !!   'key_trcbbl_adv'                    advective bottom boundary layer
+   !!----------------------------------------------------------------------
+#  include "trcbbl_adv.h90"
+# else
+   !!----------------------------------------------------------------------
+   !!   Default option :                 NO advective bottom boundary layer
+   !!----------------------------------------------------------------------
+   SUBROUTINE trc_bbl_adv (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_bbl_adv: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bbl_adv
+# endif
+
+   SUBROUTINE trc_bbl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_bbl_init  ***
+      !!
+      !! ** Purpose :   Initialization for the bottom boundary layer scheme.
+      !!
+      !!
+      !! History :
+      !!    8.5  !  02-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj      ! dummy loop indices
+
+      REAL(wp),  DIMENSION(jpi,jpj) :: zmbk  
+
+      !!----------------------------------------------------------------------
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            mbkt(ji,jj) = MAX( mbathy(ji,jj) - 1, 1 )   ! vertical index of the bottom ocean T-level
+         END DO
+      END DO
+      
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            mbku(ji,jj) = MAX( MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) ) - 1, 1 )
+            mbkv(ji,jj) = MAX( MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) ) - 1, 1 )
+         END DO
+      END DO
+
+      zmbk(:,:) = FLOAT( mbku (:,:) )   
+      CALL lbc_lnk(zmbk,'U',1.)
+      mbku (:,:) = MAX( INT( zmbk(:,:) ), 1 ) 
+	
+      zmbk(:,:) = FLOAT( mbkv (:,:) )   
+      CALL lbc_lnk(zmbk,'V',1.)
+      mbkv (:,:) = MAX( INT( zmbk(:,:) ), 1 ) 
+
+# if defined key_trcbbl_adv
+      w_trc_bbl(:,:,:) = 0.e0    ! initialisation of w_trc_bbl to zero
+# endif
+
+   END SUBROUTINE trc_bbl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      No bottom boundary layer scheme
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trcbbl_dif = .FALSE.   !: diff bbl flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trcbbl_adv = .FALSE.   !: adv  bbl flag
+CONTAINS
+   SUBROUTINE trc_bbl_dif (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_bbl_dif: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bbl_dif
+   SUBROUTINE trc_bbl_adv (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_bbl_adv: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bbl_adv
+#endif
+
+   !!======================================================================
+END MODULE trcbbl
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl_adv.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl_adv.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcbbl_adv.h90	(revision 4536)
@@ -0,0 +1,490 @@
+   !!----------------------------------------------------------------------
+   !!                     ***  trcbbl_adv.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE trc_bbl_adv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_bbl_adv  ***
+      !!                   
+      !! ** Purpose :   Compute the before tracer trend associated 
+      !!     with the bottom boundary layer and add it to the general trend
+      !!     of tracer equations. The bottom boundary layer is supposed to be 
+      !!     both an advective and diffusive bottom boundary layer.
+      !!
+      !! ** Method  :   Computes the bottom boundary horizontal and vertical 
+      !!      advection terms. Add it to the general trend : tra =tra + adv_bbl.
+      !!        When the product grad( rho) * grad(h) < 0 (where grad is a
+      !!      along bottom slope gradient) an additional lateral 2nd order
+      !!      diffusion along the bottom slope is added to the general
+      !!      tracer trend, otherwise the additional trend is set to 0.
+      !!      Second order operator (laplacian type) with variable coefficient
+      !!      computed as follow for temperature (idem on s):
+      !!         difft = 1/(e1t*e2t*e3t) { di-1[ ahbt e2u*e3u/e1u di[ztb] ]
+      !!                                 + dj-1[ ahbt e1v*e3v/e2v dj[ztb] ] }
+      !!      where ztb is a 2D array: the bottom ocean te;perature and ahtb
+      !!      is a time and space varying diffusive coefficient defined by:
+      !!         ahbt = zahbp    if grad(rho).grad(h) < 0
+      !!              = 0.       otherwise.
+      !!      Note that grad(.) is the along bottom slope gradient. grad(rho)
+      !!      is evaluated using the local density (i.e. referenced at the
+      !!      local depth). Typical value of ahbt is 2000 m2/s (equivalent to
+      !!      a downslope velocity of 20 cm/s if the condition for slope
+      !!      convection is satified)
+      !!        Add this before trend to the general trend tra of the
+      !!      botton ocean tracer point:
+      !!              tra = tra + difft
+      !!
+      !! ** Action  : - update tra at the bottom level with the bottom
+      !!                boundary layer trend
+      !!
+      !! References :
+      !!     Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!
+      !! History :
+      !!   8.5  !  02-12  (A. de Miranda, G. Madec)  Original Code 
+      !!   9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines )
+      !!   9.0  !  04-03  (C. Ethe) Adaptation for Passive tracers 
+      !!----------------------------------------------------------------------     
+      !gh
+      
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt        ! ocean time-step 
+      
+      !! * Local declarations
+      INTEGER :: ji, jj, jk, jn            ! dummy loop indices
+      INTEGER :: ik, iku, ikv              ! temporary integers
+
+      REAL(wp) ::   &
+         zsign, zt, zs, zh, zalbet,     &  ! temporary scalars
+         zgdrho, zbtr, ztra                !    "         " 
+      REAL(wp), DIMENSION(jpi,jpj) ::   &  
+      	 ztnb, zsnb, zdep, ztrb  	   ! temporary workspace arrays 
+      REAL(wp), DIMENSION(jpi,jpj) ::   &  ! temporary workspace arrays
+         zalphax, zwu, zunb,            &  !    "                  "
+         zalphay, zwv, zvnb,            &  !    "                  "
+         zwx, zwy, zww, zwz,            &  !    "                  "
+         zti, zsi ,ztmin,ztmax, zsmin,zsmax!    "                  "
+	                           !    "                  "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zhdivn                            ! temporary workspace arrays
+      REAL(wp) ::   &
+         zfui, zfvj, zbt,  zsigna,  	&  ! temporary scalars
+	 iku1,iku2,ikv1,ikv2,  		&  ! temporary scalars
+	 ze3u,ze3v,  			&  ! temporary scalars
+	 z2,z2dtt           			! temporary scalars
+      REAL(wp) ::   &
+         fsalbt, pft, pfs, pfh             ! statement function
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+      ! ratio alpha/beta
+      ! ================
+      !  fsalbt: ratio of thermal over saline expension coefficients
+      !       pft :  potential temperature in degrees celcius
+      !       pfs :  salinity anomaly (s-35) in psu
+      !       pfh :  depth in meters
+
+      fsalbt( pft, pfs, pfh ) =                                              &
+         ( ( ( -0.255019e-07 * pft + 0.298357e-05 ) * pft                    &
+                                   - 0.203814e-03 ) * pft                    &
+                                   + 0.170907e-01 ) * pft                    &
+                                   + 0.665157e-01                            &
+         +(-0.678662e-05 * pfs - 0.846960e-04 * pft + 0.378110e-02 ) * pfs   &
+         +  ( ( - 0.302285e-13 * pfh                                         &
+                - 0.251520e-11 * pfs                                         &
+                + 0.512857e-12 * pft * pft          ) * pfh                  &
+                                     - 0.164759e-06   * pfs                  &
+             +(   0.791325e-08 * pft - 0.933746e-06 ) * pft                  &
+                                     + 0.380374e-04 ) * pfh
+      !!----------------------------------------------------------------------
+
+	IF( kt == nit000 )   CALL trc_bbl_init    ! initialization at first time-step
+	
+      ! 1. 2D fields of bottom temperature and salinity, and bottom slope
+      ! -----------------------------------------------------------------
+      ! mbathy= number of w-level, minimum value=1 (cf dommsk.F)
+
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#endif
+            ik = mbkt(ji,jj)                    ! index of the bottom ocean T-level
+            ztnb(ji,jj) = tn(ji,jj,ik)   	! masked now T at the ocean bottom 
+            zsnb(ji,jj) = sn(ji,jj,ik)  	! masked now S at the ocean bottom
+            zdep(ji,jj) = fsdept(ji,jj,ik)                 ! depth of the ocean bottom T-level
+!gh
+            zunb(ji,jj) = un(ji,jj,mbku(ji,jj)) 
+            zvnb(ji,jj) = vn(ji,jj,mbkv(ji,jj)) 
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#endif
+      END DO
+
+      ! 2. Criteria of additional bottom diffusivity: grad(rho).grad(h)<0
+      ! --------------------------------------------
+      ! Sign of the local density gradient along the i- and j-slopes
+      ! multiplied by the slope of the ocean bottom
+
+      SELECT CASE ( neos )
+
+      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+      !   ... temperature, salinity anomalie and depth
+          zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+          zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+          zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+      !   ... masked ratio alpha/beta
+          zalbet = fsalbt( zt, zs, zh )*umask(ji,jj,1)
+      !   ... local density gradient along i-bathymetric slope
+          zgdrho = zalbet*( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
+                     -    ( zsnb(ji+1,jj) - zsnb(ji,jj) )
+          zgdrho = zgdrho * umask(ji,jj,1)
+      !   ... sign of local i-gradient of density multiplied by the i-slope
+          zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+	  zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+          zalphax(ji,jj) = ( 0.5 + zsigna ) * ( 0.5-zsign ) * umask(ji,jj,1)
+        END DO
+      END DO
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+      !   ... temperature, salinity anomalie and depth
+          zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+          zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+          zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+      !   ... masked ratio alpha/beta
+          zalbet = fsalbt( zt, zs, zh )*vmask(ji,jj,1)
+      !   ... local density gradient along j-bathymetric slope
+          zgdrho = zalbet*( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
+                     -    ( zsnb(ji,jj+1) - zsnb(ji,jj) )
+          zgdrho = zgdrho * vmask(ji,jj,1)
+      !   ... sign of local j-gradient of density multiplied by the j-slope
+          zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+	  zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+          zalphay(ji,jj) = ( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+        END DO
+      END DO
+
+
+      CASE ( 1 )               ! Linear formulation function of temperature only
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+            zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+!gh            ! masked ratio alpha/beta
+            ! local density gradient along i-bathymetric slope
+            zgdrho =  ( ztnb(ji+1,jj) - ztnb(ji,jj) )   
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho    * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+	    zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zalphax(ji,jj) = ( 0.5 - zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
+         END DO
+      END DO
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+            ! temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+            zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+!gh             ! masked ratio alpha/beta
+            ! local density gradient along j-bathymetric slope
+            zgdrho =  ( ztnb(ji,jj+1) - ztnb(ji,jj) )   
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+	    zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj) = ( 0.5 - zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+       
+      CASE ( 2 )               ! Linear formulation function of temperature and salinity
+ DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+	    ! local density gradient along i-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji+1,jj) - zsnb(ji,jj) )   &
+                     -  ralpha*( ztnb(ji+1,jj) - ztnb(ji,jj) ) )
+            ! sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, - zgdrho * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+	    zsigna= SIGN( 0.5, zunb(ji,jj)*(  zdep(ji+1,jj) - zdep(ji,jj) ))
+            zalphax(ji,jj)=(0.5-zsigna)*(0.5-zsign)*umask(ji,jj,1)
+        END DO
+      END DO
+
+      DO jj = 1, jpjm1
+        DO ji = 1, fs_jpim1   ! vector opt.
+	   ! local density gradient along j-bathymetric slope
+            zgdrho = - ( rbeta*( zsnb(ji,jj+1) - zsnb(ji,jj) )   &
+                   -    ralpha*( ztnb(ji,jj+1) - ztnb(ji,jj) ) )   
+            ! sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )  
+	    zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj) = ( 0.5 - zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+
+       
+      CASE DEFAULT
+
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for neos = ', neos
+         nstop = nstop + 1
+
+      END SELECT
+
+      ! lateral boundary conditions on zalphax and zalphay   (unchanged sign)
+       CALL lbc_lnk( zalphax, 'U', 1. )   ;   CALL lbc_lnk( zalphay, 'V', 1. )
+
+
+      ! 3. Velocities that are exchanged between ajacent bottom boxes.
+      !---------------------------------------------------------------
+      ! ... is equal to zero but where bbl will work.
+       u_trc_bbl(:,:,:) = 0.e0
+       v_trc_bbl(:,:,:) = 0.e0
+       
+       
+!gh	  
+       IF( ln_zps ) THEN
+      ! partial steps correction   
+      
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+       jj = 1
+       DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+#else
+       DO jj = 1, jpjm1
+          DO ji = 1, jpim1
+#endif
+             iku  = mbku(ji  ,jj  )
+             ikv  = mbkv(ji  ,jj  )  
+             iku1 = mbkt(ji+1,jj  )
+             iku2 = mbkt(ji  ,jj  )
+             ikv1 = mbkt(ji  ,jj+1)
+             ikv2 = mbkt(ji  ,jj  )
+             ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+             ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+             
+             IF( MAX(iku,ikv) >  1 ) THEN
+                u_trc_bbl(ji,jj,iku) = zalphax(ji,jj) * un(ji,jj,iku) * ze3u / fse3u(ji,jj,iku)
+                v_trc_bbl(ji,jj,ikv) = zalphay(ji,jj) * vn(ji,jj,ikv) * ze3v / fse3v(ji,jj,ikv)       
+             ENDIF
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+          END DO
+#endif
+       END DO
+
+      ! lateral boundary conditions on u_trc_bbl and v_trc_bbl   (changed sign)
+       CALL lbc_lnk( u_trc_bbl, 'U', -1. )   ;   CALL lbc_lnk( v_trc_bbl, 'V', -1. )
+       
+    ELSE    ! z-coordinate - full steps or s-coordinate	 
+       ! if not partial step loop over the whole domain no lbc call
+
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+      jj = 1
+      DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#else
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+#endif
+            iku = mbku(ji,jj)
+            ikv = mbkv(ji,jj)
+            IF( MAX(iku,ikv) >  1 ) THEN
+               u_trc_bbl(ji,jj,iku) = zalphax(ji,jj) * un(ji,jj,iku) 
+               v_trc_bbl(ji,jj,ikv) = zalphay(ji,jj) * vn(ji,jj,ikv)       
+            ENDIF
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+         END DO
+#endif
+          END DO
+       
+       ENDIF
+       
+       DO jn = 1, jptra
+
+#if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+          jj = 1
+          DO ji = 1, jpij   ! vector opt. (forced unrolling)
+#else
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+#endif
+                ik = mbkt(ji,jj)                               ! index of the bottom ocean T-level
+                ztrb(ji,jj) = trb(ji,jj,ik,jn) * tmask(ji,jj,1)    ! masked now T at the ocean bottom 
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+             END DO
+#endif
+          END DO
+
+
+
+          ! 5. Along sigma advective trend
+          ! -------------------------------
+          ! ... Second order centered tracer flux at u and v-points
+       
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+          jj = 1
+          DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+          DO jj = 1, jpjm1
+             DO ji = 1, jpim1
+# endif
+                iku = mbku(ji,jj)
+                ikv = mbkv(ji,jj)
+                zfui = e2u(ji,jj) * fse3u(ji,jj,iku) * u_trc_bbl(ji,jj,iku)
+                zfvj = e1v(ji,jj) * fse3v(ji,jj,ikv) * v_trc_bbl(ji,jj,ikv)
+                ! upstream scheme
+                zwx(ji,jj) = ( ( zfui + ABS( zfui ) ) * ztrb(ji  ,jj  )   &
+                   &          +( zfui - ABS( zfui ) ) * ztrb(ji+1,jj  ) ) * 0.5
+                zwy(ji,jj) = ( ( zfvj + ABS( zfvj ) ) * ztrb(ji  ,jj  )   &
+                   &          +( zfvj - ABS( zfvj ) ) * ztrb(ji  ,jj+1) ) * 0.5
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+             END DO
+#endif
+          END DO
+	  
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+          jj = 1
+          DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+          DO jj = 2, jpjm1
+             DO ji = 2, jpim1
+# endif
+                ik = mbkt(ji,jj)
+                zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,ik) )
+                ! horizontal advective trends
+                ztra = - zbtr * (  zwx(ji,jj) - zwx(ji-1,jj  )   &
+                   &             + zwy(ji,jj) - zwy(ji  ,jj-1)  )
+ 
+                ! add it to the general tracer trends
+                tra(ji,jj,ik,jn) = tra(ji,jj,ik,jn) + ztra
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+             END DO
+#endif
+          END DO
+	  
+        END DO
+	
+        IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('bbl - adv')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF         
+       
+       ! 6. Vertical advection velocities
+       ! --------------------------------
+       ! ... computes divergence perturbation (velocties to be removed from upper t boxes :
+       DO jk= 1, jpkm1
+
+          DO jj=1, jpjm1
+             DO ji = 1, fs_jpim1   ! vertor opt.
+                zwu(ji,jj) = -e2u(ji,jj) * u_trc_bbl(ji,jj,jk) * fse3u(ji,jj,jk)
+                zwv(ji,jj) = -e1v(ji,jj) * v_trc_bbl(ji,jj,jk) * fse3v(ji,jj,jk)
+             END DO
+          END DO
+
+          ! ... horizontal divergence
+          DO jj = 2, jpjm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+                zhdivn(ji,jj,jk) = (  zwu(ji,jj) - zwu(ji-1,jj  )   &
+                   &                + zwv(ji,jj) - zwv(ji  ,jj-1)  ) / zbt
+             END DO
+          END DO
+       END DO
+
+
+       ! ... horizontal bottom divergence
+!gh
+       IF( ln_zps ) THEN 
+	  
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+          jj = 1
+          DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+          DO jj = 1, jpjm1
+             DO ji = 1, jpim1
+# endif
+                iku  = mbku(ji  ,jj  )
+                ikv  = mbkv(ji  ,jj  )  
+                iku1 = mbkt(ji+1,jj  )
+                iku2 = mbkt(ji  ,jj  )
+                ikv1 = mbkt(ji  ,jj+1)
+                ikv2 = mbkt(ji  ,jj  )
+                ze3u = MIN( fse3u(ji,jj,iku1), fse3u(ji,jj,iku2) ) 
+                ze3v = MIN( fse3v(ji,jj,ikv1), fse3v(ji,jj,ikv2) ) 
+                
+                zwu(ji,jj) = zalphax(ji,jj) * e2u(ji,jj) * ze3u  
+                zwv(ji,jj) = zalphay(ji,jj) * e1v(ji,jj) * ze3v
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+             END DO
+#endif
+          END DO
+	
+       ELSE
+
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+          jj = 1
+          DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
+# else
+          DO jj = 1, jpjm1
+             DO ji = 1, jpim1
+# endif
+                iku = mbku(ji,jj)
+                ikv = mbkv(ji,jj)
+                zwu(ji,jj) = zalphax(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,iku) 
+                zwv(ji,jj) = zalphay(ji,jj) * e1v(ji,jj) * fse3v(ji,jj,ikv) 
+#if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+             END DO
+#endif
+          END DO
+       ENDIF
+
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+       jj = 1
+       DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+# else
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+# endif
+             ik = mbkt(ji,jj)
+             zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,ik)
+             zhdivn(ji,jj,ik) =   &
+                &   (  zwu(ji  ,jj  ) * ( zunb(ji  ,jj  ) - un(ji  ,jj  ,ik) )   &
+                &    - zwu(ji-1,jj  ) * ( zunb(ji-1,jj  ) - un(ji-1,jj  ,ik) )   &
+                &    + zwv(ji  ,jj  ) * ( zvnb(ji  ,jj  ) - vn(ji  ,jj  ,ik) )   &
+                &    - zwv(ji  ,jj-1) * ( zvnb(ji  ,jj-1) - vn(ji  ,jj-1,ik) )   &
+                &   ) / zbt
+
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+          END DO
+# endif
+       END DO
+
+       ! 7. compute additional vertical velocity to be used in t boxes
+       ! -------------------------------------------------------------
+       
+       ! ... Computation from the bottom
+       ! Note that w_trc_bbl(:,:,jpk) has been set to 0 in trc_bbl_init
+       DO jk = jpkm1, 1, -1
+          DO jj= 2, jpjm1
+             DO ji = fs_2, fs_jpim1   ! vector opt.
+                w_trc_bbl(ji,jj,jk) = w_trc_bbl(ji,jj,jk+1) - fse3t(ji,jj,jk)*zhdivn(ji,jj,jk)
+             END DO
+          END DO
+       END DO
+
+      ! Boundary condition on w_bbl   (unchanged sign)
+      CALL lbc_lnk( w_trc_bbl, 'W', 1. )
+
+   END SUBROUTINE trc_bbl_adv
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcdmp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 4536)
@@ -0,0 +1,843 @@
+MODULE trcdmp
+   !!======================================================================
+   !!                       ***  MODULE  trcdmp  ***
+   !! Ocean physics: internal restoring trend on passive tracers
+   !!======================================================================
+#if  defined key_top  &&  defined key_trcdmp 
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!   'key_trcdmp'                                       internal damping
+   !!----------------------------------------------------------------------
+   !!   trc_dmp      : update the tracer trend with the internal damping
+   !!   trc_dmp_init : initialization, namlist read, parameters control
+   !!   trccof_zoom  : restoring coefficient for zoom domain
+   !!   trccof       : restoring coefficient for global domain
+   !!   cofdis       : compute the distance to the coastline
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE trctrp_lec      ! passive tracers transport
+   USE trcdta
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_dmp   ! routine called by step.F90
+
+   !! * Shared module variables
+   LOGICAL , PUBLIC, PARAMETER ::   lk_trcdmp = .TRUE.    !: internal damping flag
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) ::   &
+      restotr         ! restoring coeff. on tracers (s-1)
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcdmp.F90,v 1.12 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_dmp( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trc_dmp  ***
+      !!                  
+      !! ** Purpose :   Compute the passive tracer trend due to a newtonian damping
+      !!      of the tracer field towards given data field and add it to the
+      !!      general tracer trends.
+      !!
+      !! ** Method  :   Newtonian damping towards trdta computed 
+      !!      and add to the general tracer trends:
+      !!                     trn = tra + restotr * (trdta - trb)
+      !!         The trend is computed either throughout the water column
+      !!      (nlmdmptr=0) or in area of weak vertical mixing (nlmdmptr=1) or
+      !!      below the well mixed layer (nlmdmptr=2)
+      !!
+      !! ** Action  : - update the tracer trends tra with the newtonian 
+      !!                damping trends.
+      !!              - save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   7.0  !         (G. Madec)  Original code
+      !!        !  96-01  (G. Madec) 
+      !!        !  97-05  (H. Loukos)  adapted for passive tracers
+      !!   8.5  !  02-08  (G. Madec )  free form + modules
+      !!   9.0  !  04-03  (C. Ethe)    free form + modules
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk, jn     ! dummy loop indices
+      REAL(wp) ::   ztest, ztra, zdt   ! temporary scalars
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialization (first time-step only)
+      !    --------------
+      IF( kt == nittrc000 ) CALL trc_dmp_init
+
+      ! 1. Newtonian damping trends on tracer fields
+      ! --------------------------------------------
+      !    compute the newtonian damping trends depending on nmldmptr
+
+!!!      zdt  = rdt * FLOAT( ndttrc )
+
+      ! Initialize the input fields for newtonian damping
+      CALL dta_trc( kt )
+
+      DO jn = 1, jptra
+
+         IF( lutini(jn) ) THEN
+
+            SELECT CASE ( nmldmptr )
+
+            CASE( 0 )                ! newtonian damping throughout the water column
+
+               DO jk = 1, jpkm1
+                  DO jj = 2, jpjm1
+                     DO ji = fs_2, fs_jpim1   ! vector opt.
+                        ztra = restotr(ji,jj,jk,jn) * ( trdta(ji,jj,jk,jn) - trb(ji,jj,jk,jn) )
+                        ! add the trends to the general tracer trends
+!!                        trn(ji,jj,jk,jn) = trn(ji,jj,jk,jn) + ztra * zdt
+                        tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+#    if defined key_trc_diatrd
+                        ! save the trends for diagnostics
+                        IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),jpdiatrc-1) = ztra
+#    endif
+                     END DO
+                  END DO
+               END DO
+
+            CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+               DO jk = 1, jpkm1
+                  DO jj = 2, jpjm1
+                     DO ji = fs_2, fs_jpim1   ! vector opt.
+                        ztest = avt(ji,jj,jk) - 5.e-4
+                        IF( ztest < 0. ) THEN
+                           ztra = restotr(ji,jj,jk,jn) * ( trdta(ji,jj,jk,jn) - trb(ji,jj,jk,jn) )
+                        ELSE
+                           ztra = 0.e0
+                        ENDIF
+                        ! add the trends to the general tracer trends
+!!                        trn(ji,jj,jk,jn) = trn(ji,jj,jk,jn) + ztra * zdt
+                        tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra 
+#    if defined key_trc_diatrd
+                        ! save the trends for diagnostics
+                        IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),jpdiatrc-1) = ztra
+#    endif
+                     END DO
+                  END DO
+               END DO
+
+            CASE ( 2 )                ! no damping in the mixed layer 
+               DO jk = 1, jpkm1
+                  DO jj = 2, jpjm1
+                     DO ji = fs_2, fs_jpim1   ! vector opt.
+                        IF( fsdept(ji,jj,jk) >= hmlp (ji,jj) ) THEN
+                           ztra = restotr(ji,jj,jk,jn) * ( trdta(ji,jj,jk,jn) - trb(ji,jj,jk,jn) )
+                        ELSE
+                           ztra = 0.e0
+                        ENDIF
+                        ! add the trends to the general tracer trends
+!!                        trn(ji,jj,jk,jn) = trn(ji,jj,jk,jn) + ztra * zdt
+                        tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+#    if defined key_trc_diatrd
+                        ! save the trends for diagnostics
+                        IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),jpdiatrc-1) = ztra
+#    endif
+                     END DO
+                  END DO
+               END DO
+               
+            END SELECT
+
+         ENDIF
+
+      END DO
+
+     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('dmp')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+  
+      trb(:,:,:,:) = trn(:,:,:,:)
+   
+   END SUBROUTINE trc_dmp
+
+
+   SUBROUTINE trc_dmp_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_dmp_init  ***
+      !! 
+      !! ** Purpose :   Initialization for the newtonian damping 
+      !!
+      !! ** Method  :   read the nammbf namelist and check the parameters
+      !!      called by trc_dmp at the first timestep (nit000)
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)  Original code
+      !!----------------------------------------------------------------------
+
+      SELECT CASE ( ndmptr )
+
+      CASE ( -1 )               ! ORCA: damping in Red & Med Seas only
+         IF(lwp) WRITE(numout,*) '          tracer damping in the Med & Red seas only'
+
+      CASE ( 1:90 )             ! Damping poleward of 'ndmptr' degrees
+         IF(lwp) WRITE(numout,*) '          tracer damping poleward of', ndmptr, ' degrees'
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for ndmp = ', ndmp
+         CALL ctl_stop(ctmp1)
+
+      END SELECT
+
+
+      SELECT CASE ( nmldmptr )
+
+      CASE ( 0 )                ! newtonian damping throughout the water column
+         IF(lwp) WRITE(numout,*) '          tracer damping throughout the water column'
+
+      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+         IF(lwp) WRITE(numout,*) '          no tracer damping in the turbocline'
+
+      CASE ( 2 )                ! no damping in the mixed layer 
+         IF(lwp) WRITE(numout,*) '          no tracer damping in the mixed layer'
+
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nmldmp = ', nmldmp
+         CALL ctl_stop(ctmp1)
+
+
+      END SELECT
+
+
+      ! 3. Damping coefficients initialization
+     ! --------------------------------------
+
+         IF( lzoom ) THEN
+            CALL trccof_zoom
+         ELSE
+            CALL trccof
+         ENDIF
+ 
+   END SUBROUTINE trc_dmp_init
+
+
+   SUBROUTINE trccof_zoom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trccof_zoom  ***
+      !!
+      !! ** Purpose :   Compute the damping coefficient for zoom domain
+      !!
+      !! ** Method  : - set along closed boundary due to zoom a damping over
+      !!      6 points with a max time scale of 5 days.
+      !!              - ORCA arctic/antarctic zoom: set the damping along
+      !!      south/north boundary over a latitude strip.
+      !!
+      !! ** Action  : - restotr, the damping coeff. passive tracers
+      !!
+      !! History :
+      !!   9.0  !  03-09  (G. Madec)  Original code
+      !!   9.0  !  04-03  (C. Ethe)   adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jn       ! dummy loop indices
+      REAL(wp) ::   &
+         zlat, zlat0, zlat1, zlat2     ! temporary scalar
+      REAL(wp), DIMENSION(6)  ::   &
+         zfact                         ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      zfact(1) =  1.
+      zfact(2) =  1. 
+      zfact(3) = 11./12.
+      zfact(4) =  8./12.
+      zfact(5) =  4./12.
+      zfact(6) =  1./12.
+      zfact(:) = zfact(:) / ( 5. * rday )    ! 5 days max restoring time scale
+
+      restotr(:,:,:,:) = 0.e0
+
+      ! damping along the forced closed boundary over 6 grid-points
+      DO jn = 1, 6
+         IF( lzoom_w )   restotr( mi0(jn+jpizoom):mi1(jn+jpizoom), : , : , : ) = zfact(jn) ! west  closed
+         IF( lzoom_s )   restotr( : , mj0(jn+jpjzoom):mj1(jn+jpjzoom), : , : ) = zfact(jn) ! south closed 
+         IF( lzoom_e )   restotr( mi0(jpiglo+jpizoom-1-jn):mi1(jpiglo+jpizoom-1-jn) , : , : , : ) &
+                       &              = zfact(jn)                                 ! east  closed 
+         IF( lzoom_n )   restotr( : , mj0(jpjglo+jpjzoom-1-jn):mj1(jpjglo+jpjzoom-1-jn) , : , : ) &
+                       &              = zfact(jn)                                 ! north closed
+      END DO
+
+
+      IF( lzoom_arct .AND. lzoom_anta ) THEN
+
+         ! ====================================================
+         !  ORCA configuration : arctic zoom or antarctic zoom
+         ! ====================================================
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp .AND. lzoom_arct ) WRITE(numout,*) '              trccof_zoom : ORCA    Arctic zoom'
+         IF(lwp .AND. lzoom_arct ) WRITE(numout,*) '              trccof_zoom : ORCA Antarctic zoom'
+         IF(lwp) WRITE(numout,*)
+
+         ! ... Initialization : 
+         !     zlat0 : latitude strip where resto decreases
+         !     zlat1 : resto = 1 before zlat1
+         !     zlat2 : resto decreases from 1 to 0 between zlat1 and zlat2
+         restotr(:,:,:,:) = 0.e0
+         zlat0 = 10.
+         zlat1 = 30.
+         zlat2 = zlat1 + zlat0
+
+         ! ... Compute arrays resto ; value for internal damping : 5 days
+         DO jn = 1, jptra
+            DO jk = 2, jpkm1 
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zlat = ABS( gphit(ji,jj) )
+                     IF ( zlat1 <= zlat .AND. zlat <= zlat2 ) THEN
+                        restotr(ji,jj,jk,jn) = 0.5 * ( 1./(5.*rday) ) *   &
+                           ( 1. - COS(rpi*(zlat2-zlat)/zlat0) ) 
+                     ELSE IF ( zlat < zlat1 ) THEN
+                        restotr(ji,jj,jk,jn) = 1./(5.*rday)
+                     ENDIF
+                  END DO
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+      ! ... Mask resto array
+        DO jn = 1, jptra
+           restotr(:,:,:,jn) = restotr(:,:,:,jn) * tmask(:,:,:)
+        END DO
+
+
+   END SUBROUTINE trccof_zoom
+
+   SUBROUTINE trccof
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trccof  ***
+      !!
+      !! ** Purpose :   Compute the damping coefficient
+      !!
+      !! ** Method  :   Arrays defining the damping are computed for each grid
+      !!      point passive tracers (restotr)
+      !!      Damping depends on distance to coast, depth and latitude
+      !!
+      !! ** Action  : - restotr, the damping coeff. for passive tracers
+      !!
+      !! History :
+      !!   5.0  !  91-03  (O. Marti, G. Madec)  Original code
+      !!        !  92-06  (M. Imbard)  doctor norme
+      !!        !  96-01  (G. Madec) statement function for e3
+      !!        !  98-07  (M. Imbard, G. Madec) ORCA version
+      !!        !  00-08  (G. Madec, D. Ludicone) 
+      !!   8.2  !  04-03  (H. Loukos) adapted for passive tracers
+      !!        !  04-02  (O. Aumont, C. Ethe) rewritten for debuging and update
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE iom
+      USE ioipsl
+
+      !! * Local declarations
+      INTEGER ::  ji, jj, jk, jn    ! dummy loop indices
+      INTEGER ::   itime
+      INTEGER ::  ii0, ii1, ij0, ij1  !    "          "
+      INTEGER ::   &
+         idmp,     &  ! logical unit for file restoring damping term
+         icot         ! logical unit for file distance to the coast
+
+      CHARACTER (len=32) ::  clname, clname2, clname3
+      REAL(wp) ::   &
+         zdate0, zinfl, zlon,         & ! temporary scalars
+         zlat, zlat0, zlat1, zlat2,   & !    "         "
+         zsdmp, zbdmp                   !    "         "
+      REAL(wp), DIMENSION(jpk) ::   &
+         gdept, zhfac
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zmrs
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zdct
+      !!----------------------------------------------------------------------
+
+      ! ====================================
+      !  ORCA configuration : global domain
+      ! ====================================
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '              trccof : Global domain of ORCA'
+      IF(lwp) WRITE(numout,*) '              ------------------------------'
+
+
+      ! ... Initialization : 
+      !   zdct()      : distant to the coastline
+      !   resto()     : array of restoring coeff. 
+      
+      zdct (:,:,:) = 0.e0
+      restotr(:,:,:,:) = 0.e0
+
+
+      IF ( ndmptr > 0 ) THEN
+
+         !    ------------------------------------
+         !     Damping poleward of 'ndmptr' degrees
+         !    ------------------------------------
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '              Damping poleward of ', ndmptr,' deg.'
+         IF(lwp) WRITE(numout,*)
+
+         ! ... Distance to coast (zdct)
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' dtacof : distance to coast file'
+         CALL iom_open ( 'dist.coast.trc.nc', icot )
+         IF( icot > 0 ) THEN
+            CALL iom_get ( icot, jpdom_data, 'Tcoast', zdct )
+            CALL iom_close (icot)
+         ELSE
+            !   ... Compute and save the distance-to-coast array (output in zdct)
+            CALL cofdis( zdct )
+         ENDIF
+
+
+         ! ... Compute arrays resto 
+         !      zinfl : distance of influence for damping term
+         !      zlat0 : latitude strip where resto decreases
+         !      zlat1 : resto = 0 between -zlat1 and zlat1
+         !      zlat2 : resto increases from 0 to 1 between |zlat1| and |zlat2|
+         !          and resto = 1 between |zlat2| and 90 deg.
+         zinfl = 1000.e3
+         zlat0 = 10
+         zlat1 = ndmptr
+         zlat2 = zlat1 + zlat0
+
+         DO jn = 1, jptra
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zlat = ABS( gphit(ji,jj) )
+                  IF ( zlat1 <= zlat .AND. zlat <= zlat2 ) THEN
+                     restotr(ji,jj,1,jn) = 0.5 * ( 1. - COS(rpi*(zlat-zlat1)/zlat0 ) )
+                  ELSEIF ( zlat > zlat2 ) THEN
+                     restotr(ji,jj,1,jn) = 1.
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         !   ... North Indian ocean (20N/30N x 45E/100E) : resto=0
+         IF ( ndmptr == 20 ) THEN
+            DO jn = 1, jptra
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zlat = gphit(ji,jj)
+                     zlon = MOD( glamt(ji,jj), 360. )
+                     IF ( zlat1 < zlat .AND. zlat < zlat2 .AND.   &
+                        45.  < zlon .AND. zlon < 100. ) THEN
+                        restotr(ji,jj,1,jn) = 0.
+                     ENDIF
+                  END DO
+               END DO
+            END DO
+         ENDIF
+
+         zsdmp = 1./(sdmptr * rday)
+         zbdmp = 1./(bdmptr * rday)
+         DO jn = 1, jptra
+            DO jk = 2, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zdct(ji,jj,jk) = MIN( zinfl, zdct(ji,jj,jk) )
+
+                     !   ... Decrease the value in the vicinity of the coast
+                     restotr(ji,jj,jk,jn) = restotr(ji,jj,1,jn)*0.5   &
+                        &                 * ( 1. - COS( rpi*zdct(ji,jj,jk)/zinfl) )
+
+                     !   ... Vertical variation from zsdmp (sea surface) to zbdmp (bottom)
+                     restotr(ji,jj,jk,jn) = restotr(ji,jj,jk,jn)   &
+                        &                 * ( zbdmp + (zsdmp-zbdmp)*EXP(-fsdept(ji,jj,jk)/hdmptr) )
+                  END DO
+               END DO
+            END DO
+         END DO
+
+      ENDIF
+
+
+      IF( cp_cfg == "orca" .AND. ( ndmptr > 0 .OR. ndmptr == -1 ) ) THEN
+
+         !                                         ! =========================
+         !                                         !  Med and Red Sea damping
+         !                                         ! =========================
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) '              ORCA configuration: Damping in Med and Red Seas'
+
+
+         zmrs(:,:) = 0.e0                             ! damping term on the Med or Red Sea
+
+         SELECT CASE ( jp_cfg )
+            !                                           ! =======================
+         CASE ( 4 )                                     !  ORCA_R4 configuration 
+            !                                           ! =======================
+
+            ! Mediterranean Sea
+            ij0 =  50   ;   ij1 =  56
+            ii0 =  81   ;   ii1 =  91   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 =  50   ;   ij1 =  55
+            ii0 =  75   ;   ii1 =  80   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 =  52   ;   ij1 =  53
+            ii0 =  70   ;   ii1 =  74   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Smooth transition from 0 at surface to 1./rday at the 18th level in Med and Red Sea
+            DO jk = 1, 17
+               zhfac (jk) = 0.5*( 1.- COS( rpi*(jk-1)/16. ) ) / rday
+            END DO
+            DO jk = 18, jpkm1
+               zhfac (jk) = 1./rday
+            END DO
+
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration 
+            !                                        ! =======================
+
+            ! Mediterranean Sea
+            ij0 =  96   ;   ij1 = 110
+            ii0 = 157   ;   ii1 = 181   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 = 100   ;   ij1 = 110
+            ii0 = 144   ;   ii1 = 156   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ij0 = 100   ;   ij1 = 103
+            ii0 = 139   ;   ii1 = 143   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Gibraltar Strait
+            ij0 = 101   ;   ij1 = 102
+            ii0 = 139   ;   ii1 = 141   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.e0
+            ii0 = 142   ;   ii1 = 142   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ii0 = 143   ;   ii1 = 143   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40e0
+            ii0 = 144   ;   ii1 = 144   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.75e0
+            ! Red Sea
+            ij0 =  87   ;   ij1 =  96
+            ii0 = 147   ;   ii1 = 163   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Bab el Mandeb Strait
+            ij0 =  91   ;   ij1 =  91
+            ii0 = 153   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.80e0
+            ij0 =  90   ;   ij1 =  90
+            ii0 = 153   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40e0
+            ij0 =  89   ;   ij1 =  89
+            ii0 = 158   ;   ii1 = 160   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ij0 =  88   ;   ij1 =  88
+            ii0 = 160   ;   ii1 = 163   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.e0
+            ! Smooth transition from 0 at surface to 1./rday at the 18th level in Med and Red Sea
+            DO jk = 1, 17
+               zhfac (jk) = 0.5*( 1.- COS( rpi*(jk-1)/16. ) ) / rday
+            END DO
+            DO jk = 18, jpkm1
+               zhfac (jk) = 1./rday
+            END DO
+
+            !                                        ! =======================
+         CASE ( 05 )                                 !  ORCA_R05 configuration
+            !                                        ! =======================
+
+            ! Mediterranean Sea
+            ii0 = 568   ;   ii1 = 574 
+            ij0 = 324   ;   ij1 = 333   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ii0 = 575   ;   ii1 = 658
+            ij0 = 314   ;   ij1 = 366   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Black Sea (remaining part
+            ii0 = 641   ;   ii1 = 651
+            ij0 = 367   ;   ij1 = 372   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Gibraltar Strait
+            ii0 = 324   ;   ii1 = 333
+            ij0 = 565   ;   ij1 = 565   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0 / 90.e0
+            ij0 = 566   ;   ij1 = 566   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.40
+            ij0 = 567   ;   ij1 = 567   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 0.75
+            ! Red Sea
+            ii0 = 641   ;   ii1 = 665
+            ij0 = 270   ;   ij1 = 310   ;   zmrs( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 1.e0
+            ! Decrease before Bab el Mandeb Strait
+            ii0 = 666   ;   ii1 = 675
+            ij0 = 270   ;   ij1 = 290   
+            DO ji = mi0(ii0), mi1(ii1)
+               zmrs( ji , mj0(ij0):mj1(ij1) ) = 0.1 * ABS( FLOAT(ji - mi1(ii1)) )
+            END DO
+            zsdmp = 1./(sdmptr * rday)
+            zbdmp = 1./(bdmptr * rday)
+            DO jk = 1, jpk
+               zhfac (jk) = ( zbdmp + (zsdmp-zbdmp) * EXP(-fsdept(1,1,jk)/hdmptr) )
+            END DO
+
+            !                                       ! ========================
+         CASE ( 025 )                               !  ORCA_R025 configuration 
+
+            CALL ctl_stop( ' Not yet implemented in ORCA_R025' ) 
+
+         END SELECT
+
+         DO jn = 1, jptra
+            DO jk = 1, jpkm1
+               restotr(:,:,jk,jn) = zmrs(:,:) * zhfac(jk) + ( 1. - zmrs(:,:) ) * restotr(:,:,jk,jn)
+            END DO
+
+            ! Mask resto array and set to 0 first and last levels
+            restotr(:,:, : ,jn) = restotr(:,:,:,jn) * tmask(:,:,:)
+            restotr(:,:, 1 ,jn) = 0.e0
+            restotr(:,:,jpk,jn) = 0.e0
+         END DO
+
+      ELSE
+         !    ------------
+         !     No damping
+         !    ------------
+         CALL ctl_stop( 'Choose a correct value of ndmp or DO NOT defined key_tradmp' )
+
+      ENDIF
+
+        !    ----------------------------
+         !     Create Print damping array
+         !    ----------------------------
+         
+         ! ndmpftr   : = 1 create a damping.coeff NetCDF file
+
+      IF( ndmpftr == 1 ) THEN
+         DO jn = 1, jptra
+            IF(lwp) WRITE(numout,*) '  create damping.coeff.nc file  ',jn
+            itime   = 0
+            clname3 = 'damping.coeff'//ctrcnm(jn)
+            CALL ymds2ju( 0     , 1     , 1      , 0.e0 , zdate0 )
+            CALL restini( 'NONE', jpi   , jpj    , glamt, gphit,    &
+           &              jpk   , gdept , clname3, itime, zdate0,   &
+           &              rdt   , idmp  , domain_id=nidom)
+            CALL restput( idmp, 'Resto', jpi, jpj, jpk, 0 , restotr(:,:,:,jn)  )
+            CALL restclo( idmp )
+         END DO
+      ENDIF
+
+
+   END SUBROUTINE trccof
+
+
+   SUBROUTINE cofdis ( pdct )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE cofdis  ***
+      !!
+      !! ** Purpose :   Compute the distance between ocean T-points and the
+      !!      ocean model coastlines. Save the distance in a NetCDF file.
+      !!
+      !! ** Method  :   For each model level, the distance-to-coast is 
+      !!      computed as follows : 
+      !!       - The coastline is defined as the serie of U-,V-,F-points
+      !!      that are at the ocean-land bound.
+      !!       - For each ocean T-point, the distance-to-coast is then 
+      !!      computed as the smallest distance (on the sphere) between the 
+      !!      T-point and all the coastline points.
+      !!       - For land T-points, the distance-to-coast is set to zero.
+      !!      C A U T I O N : Computation not yet implemented in mpp case.
+      !!
+      !! ** Action  : - pdct, distance to the coastline (argument)
+      !!              - NetCDF file 'trc.dist.coast.nc' 
+      !!        
+      !! History :
+      !!   7.0  !  01-02  (M. Imbard)  Original code
+      !!   8.1  !  01-02  (G. Madec, E. Durand)
+      !!   8.5  !  02-08  (G. Madec, E. Durand)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE ioipsl
+
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
+         pdct                     ! distance to the coastline
+
+      !! * local declarations
+      INTEGER :: ji, jj, jk, jl      ! dummy loop indices
+      INTEGER :: iju, ijt            ! temporary integers
+      INTEGER :: icoast, itime
+      INTEGER ::   &
+         icot         ! logical unit for file distance to the coast
+      LOGICAL, DIMENSION(jpi,jpj) ::   &
+         llcotu, llcotv, llcotf   ! ???
+      CHARACTER (len=32) ::   clname
+      REAL(wp) ::   zdate0
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zxt, zyt, zzt,                 &  ! cartesian coordinates for T-points
+         zmask                             
+      REAL(wp), DIMENSION(3*jpi*jpj) ::   &
+         zxc, zyc, zzc, zdis      ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialization
+      ! -----------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cofdis : compute the distance to coastline'
+      IF(lwp) WRITE(numout,*) '~~~~~~'
+      IF(lwp) WRITE(numout,*)
+      IF( lk_mpp ) &
+           & CALL ctl_stop('         Computation not yet implemented with key_mpp_...', &
+           &               '         Rerun the code on another computer or ', &
+           &               '         create the "dist.coast.nc" file using IDL' )
+
+
+      pdct(:,:,:) = 0.e0
+      zxt(:,:) = cos( rad * gphit(:,:) ) * cos( rad * glamt(:,:) )
+      zyt(:,:) = cos( rad * gphit(:,:) ) * sin( rad * glamt(:,:) )
+      zzt(:,:) = sin( rad * gphit(:,:) )
+
+
+      ! 1. Loop on vertical levels
+      ! --------------------------
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         ! Define the coastline points (U, V and F)
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zmask(ji,jj) =  ( tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) &
+                   &           + tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk) )
+               llcotu(ji,jj) = ( tmask(ji,jj,  jk) + tmask(ji+1,jj  ,jk) == 1. ) 
+               llcotv(ji,jj) = ( tmask(ji,jj  ,jk) + tmask(ji  ,jj+1,jk) == 1. ) 
+               llcotf(ji,jj) = ( zmask(ji,jj) > 0. ) .AND. ( zmask(ji,jj) < 4. )
+            END DO
+         END DO
+
+         ! Lateral boundaries conditions
+         llcotu(:, 1 ) = umask(:,  2  ,jk) == 1
+         llcotu(:,jpj) = umask(:,jpjm1,jk) == 1
+         llcotv(:, 1 ) = vmask(:,  2  ,jk) == 1
+         llcotv(:,jpj) = vmask(:,jpjm1,jk) == 1
+         llcotf(:, 1 ) = fmask(:,  2  ,jk) == 1
+         llcotf(:,jpj) = fmask(:,jpjm1,jk) == 1
+
+         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+            llcotu( 1 ,:) = llcotu(jpim1,:)
+            llcotu(jpi,:) = llcotu(  2  ,:)
+            llcotv( 1 ,:) = llcotv(jpim1,:)
+            llcotv(jpi,:) = llcotv(  2  ,:)
+            llcotf( 1 ,:) = llcotf(jpim1,:)
+            llcotf(jpi,:) = llcotf(  2  ,:)
+         ELSE
+            llcotu( 1 ,:) = umask(  2  ,:,jk) == 1
+            llcotu(jpi,:) = umask(jpim1,:,jk) == 1
+            llcotv( 1 ,:) = vmask(  2  ,:,jk) == 1
+            llcotv(jpi,:) = vmask(jpim1,:,jk) == 1
+            llcotf( 1 ,:) = fmask(  2  ,:,jk) == 1
+            llcotf(jpi,:) = fmask(jpim1,:,jk) == 1
+         ENDIF
+         IF( nperio == 3 .OR. nperio == 4 ) THEN
+            DO ji = 1, jpim1
+               iju = jpi - ji + 1
+               llcotu(ji,jpj  ) = llcotu(iju,jpj-2)
+               llcotf(ji,jpj-1) = llcotf(iju,jpj-2)
+               llcotf(ji,jpj  ) = llcotf(iju,jpj-3)
+            END DO
+            DO ji = jpi/2, jpi-1
+               iju = jpi - ji + 1
+               llcotu(ji,jpjm1) = llcotu(iju,jpjm1)
+            END DO
+            DO ji = 2, jpi
+               ijt = jpi - ji + 2
+               llcotv(ji,jpj-1) = llcotv(ijt,jpj-2)
+               llcotv(ji,jpj  ) = llcotv(ijt,jpj-3)
+            END DO
+         ENDIF
+         IF( nperio == 5 .OR. nperio == 6 ) THEN
+            DO ji = 1, jpim1
+               iju = jpi - ji
+               llcotu(ji,jpj  ) = llcotu(iju,jpj-1)
+               llcotf(ji,jpj  ) = llcotf(iju,jpj-2)
+            END DO
+            DO ji = jpi/2, jpi-1
+               iju = jpi - ji
+               llcotf(ji,jpjm1) = llcotf(iju,jpjm1)
+            END DO
+            DO ji = 1, jpi
+               ijt = jpi - ji + 1
+               llcotv(ji,jpj  ) = llcotv(ijt,jpj-1)
+            END DO
+            DO ji = jpi/2+1, jpi
+               ijt = jpi - ji + 1
+               llcotv(ji,jpjm1) = llcotv(ijt,jpjm1)
+            END DO
+         ENDIF
+
+         ! Compute cartesian coordinates of coastline points
+         ! and the number of coastline points
+
+         icoast = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( llcotf(ji,jj) ) THEN
+                  icoast = icoast + 1
+                  zxc(icoast) = COS( rad*gphif(ji,jj) ) * COS( rad*glamf(ji,jj) )
+                  zyc(icoast) = COS( rad*gphif(ji,jj) ) * SIN( rad*glamf(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphif(ji,jj) )
+               ENDIF
+               IF( llcotu(ji,jj) ) THEN
+                  icoast = icoast+1
+                  zxc(icoast) = COS( rad*gphiu(ji,jj) ) * COS( rad*glamu(ji,jj) )
+                  zyc(icoast) = COS( rad*gphiu(ji,jj) ) * SIN( rad*glamu(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphiu(ji,jj) )
+               ENDIF
+               IF( llcotv(ji,jj) ) THEN
+                  icoast = icoast+1
+                  zxc(icoast) = COS( rad*gphiv(ji,jj) ) * COS( rad*glamv(ji,jj) )
+                  zyc(icoast) = COS( rad*gphiv(ji,jj) ) * SIN( rad*glamv(ji,jj) )
+                  zzc(icoast) = SIN( rad*gphiv(ji,jj) )
+               ENDIF
+            END DO
+         END DO
+
+         ! Distance for the T-points
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( tmask(ji,jj,jk) == 0. ) THEN
+                  pdct(ji,jj,jk) = 0.
+               ELSE
+                  DO jl = 1, icoast
+                     zdis(jl) = ( zxt(ji,jj) - zxc(jl) )**2   &
+                              + ( zyt(ji,jj) - zyc(jl) )**2   &
+                              + ( zzt(ji,jj) - zzc(jl) )**2
+                  END DO
+                  pdct(ji,jj,jk) = ra * SQRT( MINVAL( zdis(1:icoast) ) )
+               ENDIF
+            END DO
+         END DO
+         !                                                ! ===============
+      END DO                                              !   End of slab
+      !                                                   ! ===============
+
+
+      ! 2. Create the  distance to the coast file in NetCDF format
+      ! ----------------------------------------------------------    
+      clname = 'trc.dist.coast'
+      itime = 0
+      CALL ymds2ju( 0     , 1     , 1     , 0.e0 , zdate0 )
+      CALL restini( 'NONE', jpi   , jpj   , glamt, gphit ,   &
+                    jpk   , gdept , clname, itime, zdate0,   &
+                    rdt   , icot , domain_id=nidom         )
+      CALL restput( icot, 'Tcoast', jpi, jpj, jpk, 0, pdct )
+      CALL restclo( icot )
+
+   END SUBROUTINE cofdis
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO internal damping
+   !!----------------------------------------------------------------------
+   LOGICAL , PUBLIC, PARAMETER ::   lk_trcdmp = .FALSE.    !: internal damping flag
+CONTAINS
+   SUBROUTINE trc_dmp( kt )        ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_dmp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_dmp
+#endif
+
+   !!======================================================================
+END MODULE trcdmp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilap.F90	(revision 4536)
@@ -0,0 +1,231 @@
+MODULE trcldf_bilap
+   !!==============================================================================
+   !!                   ***  MODULE  trcldf_bilap  ***
+   !! TOP :  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_ldf_bilap : update the tracer trend with the horizontal diffusion
+   !!                   using a iso-level biharmonic operator
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and active tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_ldf_bilap   ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcldf_bilap.F90,v 1.12 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE trc_ldf_bilap( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ldf_bilap  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer tra diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   4th order diffusive operator along model level surfaces 
+      !!      evaluated using before fields (forward time scheme). The hor.
+      !!      diffusive trends of passive tracer is given by:
+      !!       * s-coordinate, the vertical scale 
+      !!      factors e3. are inside the derivatives:
+      !!      Laplacian of trb:
+      !!         zlt   = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(trb) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(trb) ]  }
+      !!      Multiply by the eddy diffusivity coef. and insure lateral bc:
+      !!        zlt   = ahtt * zlt
+      !!        call to lbc_lnk
+      !!      Bilaplacian (laplacian of zlt):
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ e2u*e3u/e1u di(zlt) ]
+      !!                                  + dj-1[ e1v*e3v/e2v dj(zlt) ]  }
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!      Laplacian of trb:
+      !!         zlt   = 1/(e1t*e2t) {  di-1[ e2u/e1u di(trb) ]
+      !!                              + dj-1[ e1v/e2v dj(trb) ] }
+      !!      Multiply by the eddy diffusivity coef. and insure lateral bc:
+      !!        zlt   = ahtt * zlt
+      !!        call to lbc_lnk
+      !!      Bilaplacian (laplacian of zlt):
+      !!         difft = 1/(e1t*e2t) {  di-1[ e2u/e1u di(zlt) ]
+      !!                              + dj-1[ e1v/e2v dj(zlt) ]  }
+      !!
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + difft 
+      !!
+      !! ** Action : - Update tra arrays with the before iso-level
+      !!               biharmonic mixing trend.
+      !!             - Save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!        !  91-11  (G. Madec)  Original code
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  96-01  (M. Imbard)  mpp exchange
+      !!        !  97-07  (G. Madec)  optimization, and ahtt
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-10  (MA Foujols E. Kestenare) use passive tracer coefficient
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  F90: Free form and module
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jn             ! dummy loop indices
+      INTEGER ::   iku, ikv                   ! temporary integers
+
+      REAL(wp) ::   ztra     ! temporary scalars
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   & 
+         zeeu, zeev, zbtr, zlt                 ! workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   & 
+         ztu, ztv                              ! workspace
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_ldf_bilap : iso-level biharmonic operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+      ! 
+
+      DO jn = 1, jptra
+                                                          ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+
+            ! 0. Initialization of metric arrays (for z- or s-coordinates)
+            ! ----------------------------------
+
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+#if ! defined key_zco 
+                  ! s-coordinates, vertical scale factor are used
+                  zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+                  zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+#else
+                  ! z-coordinates, no vertical scale factors
+                  zbtr(ji,jj) = 1. / ( e1t(ji,jj)*e2t(ji,jj) )
+                  zeeu(ji,jj) = e2u(ji,jj) / e1u(ji,jj) * umask(ji,jj,jk)
+                  zeev(ji,jj) = e1v(ji,jj) / e2v(ji,jj) * vmask(ji,jj,jk)
+#endif
+               END DO
+            END DO
+
+
+            ! 1. Laplacian
+            ! ------------
+
+            ! First derivative (gradient)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ztu(ji,jj,jk) = zeeu(ji,jj) * ( trb(ji+1,jj  ,jk,jn) - trb(ji,jj,jk,jn) )
+                  ztv(ji,jj,jk) = zeev(ji,jj) * ( trb(ji  ,jj+1,jk,jn) - trb(ji,jj,jk,jn) )
+               END DO
+            END DO
+
+            IF( ln_zps ) THEN
+               DO jj = 1, jpj-1
+                  DO ji = 1, jpi-1
+                     ! last level
+                     iku = MIN ( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                     ikv = MIN ( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                     IF( iku == jk ) THEN
+                        ztu(ji,jj,jk) = zeeu(ji,jj) * gtru(ji,jj,jn)
+                     ENDIF
+                     IF( ikv == jk ) THEN
+                        ztv(ji,jj,jk) = zeev(ji,jj) * gtrv(ji,jj,jn)
+                     ENDIF
+                  END DO
+               END DO
+            ENDIF
+
+            ! Second derivative (divergence)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlt(ji,jj) = zbtr(ji,jj) * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+               END DO
+            END DO
+
+            ! Multiply by the eddy diffusivity coefficient
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zlt(ji,jj) = fsahtrt(ji,jj,jk) * zlt(ji,jj)
+               END DO
+            END DO
+
+            ! Lateral boundary conditions on the laplacian zlt   (unchanged sgn)
+            CALL lbc_lnk( zlt, 'T', 1. )  
+
+            ! 2. Bilaplacian
+            ! --------------
+
+            ! third derivative (gradient)
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ztu(ji,jj,jk) = zeeu(ji,jj) * ( zlt(ji+1,jj  ) - zlt(ji,jj) )
+                  ztv(ji,jj,jk) = zeev(ji,jj) * ( zlt(ji  ,jj+1) - zlt(ji,jj) )
+               END DO
+            END DO
+
+            ! fourth derivative (divergence) and add to the general tracer trend
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! horizontal diffusive trends
+                  ztra = zbtr(ji,jj) * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  ! save the horizontal diffusive trends
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),4) = (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) ) * zbtr(ji,jj)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),5) = (  ztv(ji,jj,jk) - ztv(ji-1,jj,jk) ) * zbtr(ji,jj)
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           ! Horizontal slab
+         !                                                ! ===============
+#if defined key_trc_diatrd
+         ! Lateral boundary conditions on the laplacian zlt   (unchanged sgn)
+         IF (luttrd(jn)) CALL lbc_lnk( trtrd(:,:,:,ikeep(jn),5), 'T', 1. )  
+#endif
+      END DO
+
+     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf - bilap')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_ldf_bilap
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ldf_bilap( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_ldf_bilap: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_ldf_bilap
+#endif
+   !!==============================================================================
+END MODULE trcldf_bilap
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilapg.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilapg.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_bilapg.F90	(revision 4536)
@@ -0,0 +1,372 @@
+MODULE trcldf_bilapg
+   !!==============================================================================
+   !!                       ***  MODULE  trcldf_bilapg  ***
+   !! Ocean passive tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+#if defined key_top && defined key_ldfslp
+   !!----------------------------------------------------------------------
+   !!   'key_top'        and                                     TOP models
+   !!   'key_ldfslp'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   trc_ldf_bilapg : update the tracer trend with the horizontal diffusion
+   !!                    using an horizontal biharmonic operator in s-coordinate 
+   !!   ldfght         :  ???
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE lbclnk              ! ocean lateral boundary condition (or mpp link)
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_ldf_bilapg    ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE trc_ldf_bilapg( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE trc_ldf_bilapg  ***
+      !!                    
+      !! ** Purpose :   Compute the before horizontal passive tracer diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The lateral diffusive trends is provided by a 4th order
+      !!      operator rotated along geopotential surfaces. It is computed
+      !!      using before fields (forward in time) and geopotential slopes
+      !!      computed in routine inildf.
+      !!         -1- compute the geopotential harmonic operator applied to
+      !!      trb and multiply it by the eddy diffusivity coefficient
+      !!      (done by a call to ldfght routine, result in wk1 array).
+      !!      Applied the domain lateral boundary conditions by call to lbc_lnk
+      !!         -2- compute the geopotential harmonic operator applied to
+      !!      wk1 by a second call to ldfght routine (result in wk3 array).
+      !!         -3- Add this trend to the general trend (ta,sa):
+      !!            tra = tra + wk3
+      !!
+      !! ** Action : - Update tra arrays with the before geopotential 
+      !!               biharmonic mixing trend.
+      !!             - Save the trends  in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe)  adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn              ! dummy loop indices
+      REAL(wp) ::  ztra                       ! workspace   
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) ::   &
+         wk1, wk2               ! work array used for rotated biharmonic
+                                ! operator on tracers and/or momentum
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_ldf_bilapg : horizontal biharmonic operator in s-coordinate'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! 1. Laplacian of passive tracers trb * aht
+      ! ----------------------------- 
+      ! rotated harmonic operator applied to trb 
+      ! and multiply by aht (output in wk1 )
+
+      CALL ldfght ( trb, wk1, 1 )
+
+      DO jn = 1, jptra
+      ! Lateral boundary conditions on wk1   (unchanged sign)
+         CALL lbc_lnk( wk1(:,:,:,jn) , 'T', 1. )
+      END DO
+
+      ! 2. Bilaplacian of trb
+      ! -------------------------
+      ! rotated harmonic operator applied to wk1 (output in wk2 )
+
+      CALL ldfght ( wk1, wk2, 2 )
+
+
+      DO jn = 1, jptra
+         ! 3. Update the tracer trends                    (j-slab :   2, jpj-1)
+         ! ---------------------------
+         !                                                ! ===============
+         DO jj = 2, jpjm1                                 !  Vertical slab
+            !                                             ! ===============
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + wk2(ji,jj,jk,jn)
+#if defined key_trc_diatrd
+                  ! save the horizontal diffusive trends
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),3) = wk2(ji,jj,jk,jn)
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      END DO
+
+     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf - bilapg')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_ldf_bilapg
+
+
+   SUBROUTINE ldfght ( pt, plt, kaht )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldfght  ***
+      !!          
+      !! ** Purpose :   Apply a geopotential harmonic operator to pt and 
+      !!      multiply it by the eddy diffusivity coefficient (if kaht=1).
+      !!      Routine only used in s-coordinates (l_sco=T) with bilaplacian
+      !!      operator (ln_traldf_bilap=T) acting along geopotential surfaces
+      !!      (ln_traldf_hor).
+      !!
+      !! ** Method  :   The harmonic operator rotated along geopotential 
+      !!      surfaces is applied to pt using the slopes of geopotential
+      !!      surfaces computed in inildf routine. The result is provided in
+      !!      plt arrays. It is computed in 2 steps:
+      !!
+      !!      First step: horizontal part of the operator. It is computed on
+      !!      ==========  pt as follows (idem on ps)
+      !!      horizontal fluxes :
+      !!         zftu = e2u*e3u/e1u di[ pt ] - e2u*uslp dk[ mi(mk(pt)) ]
+      !!         zftv = e1v*e3v/e2v dj[ pt ] - e1v*vslp dk[ mj(mk(pt)) ]
+      !!      take the horizontal divergence of the fluxes (no divided by
+      !!      the volume element :
+      !!         plt  = di-1[ zftu ] +  dj-1[ zftv ]
+      !!
+      !!      Second step: vertical part of the operator. It is computed on
+      !!      ===========  pt as follows (idem on ps)
+      !!      vertical fluxes :
+      !!         zftw = e1t*e2t/e3w * (wslpi^2+wslpj^2)  dk-1[ pt ]
+      !!              -     e2t     *       wslpi        di[ mi(mk(pt)) ]
+      !!              -     e1t     *       wslpj        dj[ mj(mk(pt)) ]
+      !!      take the vertical divergence of the fluxes add it to the hori-
+      !!      zontal component, divide the result by the volume element and
+      !!      if kaht=1, multiply by the eddy diffusivity coefficient:
+      !!         plt  = aht / (e1t*e2t*e3t) { plt + dk[ zftw ] }
+      !!      else:
+      !!         plt  =  1  / (e1t*e2t*e3t) { plt + dk[ zftw ] }
+      !!
+      !! * Action :
+      !!      'key_trdtra' defined: the trend is saved for diagnostics.
+      !!
+      !! History :
+      !!   8.0  !  97-07  (G. Madec)  Original code
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe)  adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra), INTENT( in  ) ::   &
+         pt               ! tracer fields before for 1st call
+      !                   ! and laplacian of these fields for 2nd call.
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra), INTENT( out ) ::   &
+         plt              ! partial harmonic operator applied to
+      !                   ! pt components except
+      !                   ! second order vertical derivative term)
+      INTEGER, INTENT( in ) ::   &
+         kaht             ! =1 multiply the laplacian by the eddy diffusivity coeff.
+      !                   ! =2 no multiplication
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn             ! dummy loop indices
+      REAL(wp) ::   &
+         zabe1, zabe2, zmku, zmkv,     &  ! temporary scalars
+         zbtr, ztah, ztav, &
+         zcof0, zcof1, zcof2,          &
+         zcof3, zcof4
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zftu, zftv ,                   &  ! workspace
+         zdkt, zdk1t
+
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         zftw,                          &  ! workspace
+         zdit, zdjt, zdj1t
+
+      !!----------------------------------------------------------------------
+
+
+      DO jn = 1, jptra
+         !                               ! ********** !   ! ===============
+         DO jk = 1, jpkm1                ! First step !   ! Horizontal slab
+            !                            ! ********** !   ! ===============
+
+            ! I.1 Vertical gradient of pt and ps at level jk and jk+1
+            ! -------------------------------------------------------
+            !     surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+            zdk1t(:,:) = ( pt(:,:,jk,jn) - pt(:,:,jk+1,jn) ) * tmask(:,:,jk+1)
+
+            IF( jk == 1 ) THEN
+               zdkt(:,:) = zdk1t(:,:)
+            ELSE
+               zdkt(:,:) = ( pt(:,:,jk-1,jn) - pt(:,:,jk,jn) ) * tmask(:,:,jk)
+            ENDIF
+
+
+            ! I.2 Horizontal fluxes
+            ! ---------------------
+
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zabe1 = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+                  zabe2 = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+                  zmku=1./MAX( tmask(ji+1,jj,jk  )+tmask(ji,jj,jk+1)   &
+                              +tmask(ji+1,jj,jk+1)+tmask(ji,jj,jk  ),1. )
+                  zmkv=1./MAX( tmask(ji,jj+1,jk  )+tmask(ji,jj,jk+1)   &
+                              +tmask(ji,jj+1,jk+1)+tmask(ji,jj,jk  ),1. )
+
+                  zcof1= -e2u(ji,jj) * uslp(ji,jj,jk) * zmku
+                  zcof2= -e1v(ji,jj) * vslp(ji,jj,jk) * zmkv
+
+                  zftu(ji,jj)= umask(ji,jj,jk) *   &
+                     (  zabe1 *( pt(ji+1,jj,jk,jn) - pt(ji,jj,jk,jn) )   &
+                      + zcof1 *( zdkt (ji+1,jj) + zdk1t(ji,jj)           &
+                                +zdk1t(ji+1,jj) + zdkt (ji,jj) )  )
+
+                  zftv(ji,jj)= vmask(ji,jj,jk) *   &
+                     (  zabe2 *( pt(ji,jj+1,jk,jn) - pt(ji,jj,jk,jn) )   &
+                      + zcof2 *( zdkt (ji,jj+1) + zdk1t(ji,jj)           &
+                                +zdk1t(ji,jj+1) + zdkt (ji,jj) )  )
+               END DO
+            END DO
+
+
+            ! I.3 Second derivative (divergence) (not divided by the volume)
+            ! ---------------------
+
+            DO jj = 2 , jpjm1
+               DO ji = 2 , jpim1
+                  ztah = zftu(ji,jj) - zftu(ji-1,jj) + zftv(ji,jj) - zftv(ji,jj-1)
+                  plt(ji,jj,jk,jn) = ztah
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+
+         !                             ! ************ !   ! ===============
+         DO jj = 2, jpjm1              !  Second step !   ! Horizontal slab
+            !                          ! ************ !   ! ===============
+
+            ! II.1 horizontal tracer gradient
+            ! -------------------------------
+
+            DO jk = 1, jpk
+               DO ji = 1, jpim1
+                  zdit (ji,jk) = ( pt(ji+1,jj  ,jk,jn) - pt(ji,jj  ,jk,jn) ) * umask(ji,jj  ,jk)
+                  zdjt (ji,jk) = ( pt(ji  ,jj+1,jk,jn) - pt(ji,jj  ,jk,jn) ) * vmask(ji,jj  ,jk)
+                  zdj1t(ji,jk) = ( pt(ji  ,jj  ,jk,jn) - pt(ji,jj-1,jk,jn) ) * vmask(ji,jj-1,jk)
+               END DO
+            END DO
+
+
+            ! II.2 Vertical fluxes
+            ! --------------------
+
+            ! Surface and bottom vertical fluxes set to zero
+            zftw(:, 1 ) = 0.e0
+            zftw(:,jpk) = 0.e0
+
+            ! interior (2=<jk=<jpk-1)
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zcof0 = e1t(ji,jj) * e2t(ji,jj) / fse3w(ji,jj,jk)   &
+                     * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)        &
+                        + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+
+                  zmku =1./MAX(  umask(ji  ,jj,jk-1)+umask(ji-1,jj,jk)   &
+                                +umask(ji-1,jj,jk-1)+umask(ji  ,jj,jk), 1. )
+
+                  zmkv =1./MAX(  vmask(ji,jj  ,jk-1)+vmask(ji,jj-1,jk)   &
+                                +vmask(ji,jj-1,jk-1)+vmask(ji,jj  ,jk), 1. )
+
+                  zcof3 = - e2t(ji,jj) * wslpi (ji,jj,jk) * zmku
+                  zcof4 = - e1t(ji,jj) * wslpj (ji,jj,jk) * zmkv
+
+                  zftw(ji,jk) = tmask(ji,jj,jk) *   &
+                     (  zcof0 * ( pt  (ji,jj,jk-1,jn) - pt  (ji,jj,jk,jn) )   &
+                      + zcof3 * ( zdit (ji  ,jk-1) + zdit (ji-1,jk)           &
+                                 +zdit (ji-1,jk-1) + zdit (ji  ,jk) )         &
+                      + zcof4 * ( zdjt (ji  ,jk-1) + zdj1t(ji  ,jk)           &
+                                 +zdj1t(ji  ,jk-1) + zdjt (ji  ,jk) )  )
+               END DO
+            END DO
+
+
+            ! II.3 Divergence of vertical fluxes added to the horizontal divergence
+            ! ---------------------------------------------------------------------
+
+            IF( kaht == 1 ) THEN
+               ! multiply the laplacian by the eddy diffusivity coefficient
+               DO jk = 1, jpkm1
+                  DO ji = 2, jpim1
+                     ! eddy coef. divided by the volume element
+                     zbtr = fsahtrt(ji,jj,jk) / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                     ! vertical divergence
+                     ztav = zftw(ji,jk) - zftw(ji,jk+1)
+                     ! harmonic operator applied to (pt,ps) and multiply by aht
+                     plt(ji,jj,jk,jn) = ( plt(ji,jj,jk,jn) + ztav ) * zbtr
+                  END DO
+               END DO
+            ELSEIF( kaht == 2 ) THEN
+               ! second call, no multiplication
+               DO jk = 1, jpkm1
+                  DO ji = 2, jpim1
+                     ! inverse of the volume element
+                     zbtr = 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                     ! vertical divergence
+                     ztav = zftw(ji,jk) - zftw(ji,jk+1)
+                     ! harmonic operator applied to (pt,ps) 
+                     plt(ji,jj,jk,jn) = ( plt(ji,jj,jk,jn) + ztav ) * zbtr
+                  END DO
+               END DO
+            ELSE
+               IF(lwp) WRITE(numout,*) ' ldfght: kaht= 1 or 2, here =', kaht
+               IF(lwp) WRITE(numout,*) '         We stop'
+               STOP 'ldfght'
+            ENDIF
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      END DO
+
+   END SUBROUTINE ldfght
+
+#else  
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             NO rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ldf_bilapg( kt )               ! Dummy routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_ldf_bilapg: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_ldf_bilapg
+#endif
+
+   !!==============================================================================
+END MODULE trcldf_bilapg
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso.F90	(revision 4536)
@@ -0,0 +1,254 @@
+MODULE trcldf_iso
+   !!==============================================================================
+   !!                    ***  MODULE  trcldf_iso  ***
+   !! Ocean passive tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+#if defined key_top && defined key_ldfslp 
+   !!----------------------------------------------------------------------
+   !!   'key_top'          and                                   TOP models
+   !!   'key_ldfslp'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   trc_ldf_iso : update the tracer trend with the horizontal component
+   !!                 of iso neutral laplacian operator or horizontal 
+   !!                 laplacian operator in s-coordinate
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc      ! ocean dynamics and tracers variables
+   USE trc          ! ocean passive tracers variables
+   USE prtctl_trc   ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_ldf_iso  ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcldf_iso.F90,v 1.10 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ldf_iso( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ldf_iso  ***
+      !! 
+      !! ** Purpose :   Compute the before horizontal tracer  diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The horizontal component of the lateral diffusive trends 
+      !!      is provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      horizontal fluxes associated with the rotated lateral mixing:
+      !!         zftu = (aht+ahtb0) e2u*e3u/e1u di[ tb ]
+      !!               - aht       e2u*uslp    dk[ mi(mk(tb)) ]
+      !!         zftv = (aht+ahtb0) e1v*e3v/e2v dj[ tb ]
+      !!               - aht       e2u*vslp    dk[ mj(mk(tb)) ]
+      !!      add horizontal Eddy Induced advective fluxes (lk_traldf_eiv=T):
+      !!         zftu = zftu - dk-1[ aht e2u mi(wslpi) ] mi( tb ) 
+      !!         zftv = zftv - dk-1[ aht e1v mj(wslpj) ] mj( tb ) 
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ zftu ] +  dj-1[ zftv ]  }
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + difft
+      !!
+      !! ** Action  : - Update tra arrays with the before isopycnal or
+      !!                geopotential s-coord harmonic mixing trend.
+      !!              - Save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!        !  94-08  (G. Madec, M. Imbard)
+      !!        !  97-05  (G. Madec)  split into traldf and trazdf
+      !!        !  98-03  (L. Bopp, MA Foujols) passive tracer generalisation
+      !!        !  00-10  (MA Foujols E Kestenare) USE passive tracer coefficient
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!   9.0  !  04-03  (C. Ethe)  Free form, F90
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc       , zftu => ua,  &  ! use ua as workspace
+         &                zfsu => va      ! use va as workspace
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn             ! dummy loop indices
+      REAL(wp) ::   &
+         zabe1, zabe2, zcof1, zcof2,   &  ! temporary scalars
+         zmsku, zmskv, zbtr,           &
+#if defined key_trcldf_eiv
+         zcg1, zcg2, zuwk, zvwk,       &
+         zuwk1, zvwk1,                 &
+#endif
+         ztra
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zdkt, zdk1t            ! workspace
+
+#if defined key_trcldf_eiv
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zftug, zftvg
+
+#if defined key_trc_diatrd
+      REAL(wp) ::   &
+         ztagu, ztagv
+#endif
+
+#endif
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zftv                       ! workspace
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_ldf_iso : iso neutral lateral diffusion or'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   horizontal laplacian diffusion in s-coordinate'
+#if defined key_trcldf_eiv && defined key_diaeiv
+         u_trc_eiv(:,:,:) = 0.e0
+         v_trc_eiv(:,:,:) = 0.e0
+#endif
+      ENDIF
+
+
+      DO jn = 1, jptra
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            ! 1. Vertical tracer gradient at level jk and jk+1
+            ! ------------------------------------------------
+            ! surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+            zdk1t(:,:) = ( trb(:,:,jk,jn) - trb(:,:,jk+1,jn) ) * tmask(:,:,jk+1)
+
+            IF( jk == 1 ) THEN
+               zdkt(:,:) = zdk1t(:,:)
+            ELSE
+               zdkt(:,:) = ( trb(:,:,jk-1,jn) - trb(:,:,jk,jn) ) * tmask(:,:,jk)
+            ENDIF
+
+
+            ! 2. Horizontal fluxes
+            ! --------------------
+
+            DO jj = 1 , jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zabe1 = ( fsahtru(ji,jj,jk) + ahtrb0 ) * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+                  zabe2 = ( fsahtrv(ji,jj,jk) + ahtrb0 ) * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+                  zmsku = 1. / MAX(   tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
+                     + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+                  zmskv = 1. / MAX(   tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
+                     + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+                  zcof1 = -fsahtru(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku
+                  zcof2 = -fsahtrv(ji,jj,jk) * e1v(ji,jj) * vslp(ji,jj,jk) * zmskv
+
+                  zftu(ji,jj,jk) = umask(ji,jj,jk) * (   zabe1 * (   trb(ji+1,jj,jk,jn) - trb(ji,jj,jk,jn)  )   &
+                     &                              + zcof1 * (   zdkt (ji+1,jj) + zdk1t(ji,jj)      &
+                     &                                          + zdk1t(ji+1,jj) + zdkt (ji,jj)  )  )
+
+                  zftv(ji,jj,jk) = vmask(ji,jj,jk) * (   zabe2 * (   trb(ji,jj+1,jk,jn) - trb(ji,jj,jk,jn)  )   &
+                     &                              + zcof2 * (   zdkt (ji,jj+1) + zdk1t(ji,jj)      &
+                     &                                          + zdk1t(ji,jj+1) + zdkt (ji,jj)  )  )
+
+               END DO
+            END DO
+
+#   if defined key_trcldf_eiv
+            !                              ! ---------------------------------------!
+            !                              ! Eddy induced vertical advective fluxes !
+            !                              ! ---------------------------------------!
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zuwk = ( wslpi(ji,jj,jk  ) + wslpi(ji+1,jj,jk  ) ) * fsaeitru(ji,jj,jk  ) * umask(ji,jj,jk  )
+                  zuwk1= ( wslpi(ji,jj,jk+1) + wslpi(ji+1,jj,jk+1) ) * fsaeitru(ji,jj,jk+1) * umask(ji,jj,jk+1)
+                  zvwk = ( wslpj(ji,jj,jk  ) + wslpj(ji,jj+1,jk  ) ) * fsaeitrv(ji,jj,jk  ) * vmask(ji,jj,jk  )
+                  zvwk1= ( wslpj(ji,jj,jk+1) + wslpj(ji,jj+1,jk+1) ) * fsaeitrv(ji,jj,jk+1) * vmask(ji,jj,jk+1)
+
+                  zcg1= -0.25 * e2u(ji,jj) * umask(ji,jj,jk) * ( zuwk-zuwk1 )
+                  zcg2= -0.25 * e1v(ji,jj) * vmask(ji,jj,jk) * ( zvwk-zvwk1 )
+
+                  zftug(ji,jj) = zcg1 * ( trb(ji+1,jj,jk,jn) + trb(ji,jj,jk,jn) )
+                  zftvg(ji,jj) = zcg2 * ( trb(ji,jj+1,jk,jn) + trb(ji,jj,jk,jn) )
+
+                  zftu(ji,jj,jk) = zftu(ji,jj,jk) + zftug(ji,jj)
+                  zftv(ji,jj,jk) = zftv(ji,jj,jk) + zftvg(ji,jj)
+
+#   if defined key_diaeiv
+                  u_trc_eiv(ji,jj,jk) = -2. * zcg1 / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+                  v_trc_eiv(ji,jj,jk) = -2. * zcg2 / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+#   endif
+               END DO
+            END DO
+#   endif
+
+            ! II.4 Second derivative (divergence) and add to the general trend
+            ! ----------------------------------------------------------------
+
+            DO jj = 2 , jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr= 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ztra = zbtr * (  zftu(ji,jj,jk) - zftu(ji-1,jj  ,jk)   &
+                     &          + zftv(ji,jj,jk) - zftv(ji  ,jj-1,jk)  )
+                  tra (ji,jj,jk,jn) = tra (ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),4) = ( zftu(ji,jj,jk) - zftu(ji-1,jj,jk  ) ) * zbtr
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),5) = ( zftv(ji,jj,jk) - zftv(ji,jj-1,jk  ) ) * zbtr
+#endif
+               END DO
+            END DO
+
+#if defined key_trc_diatrd
+#   if defined key_trcldf_eiv
+            DO jj = 2 , jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr= 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztagu = ( zftug(ji,jj) - zftug(ji-1,jj  ) ) * zbtr
+                  ztagv = ( zftvg(ji,jj) - zftvg(ji  ,jj-1) ) * zbtr
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),4) = trtrd(ji,jj,jk,ikeep(jn),4) - ztagu
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),5) = trtrd(ji,jj,jk,ikeep(jn),5) - ztagv
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),7) = ztagu
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),8) = ztagv
+               END DO
+             END DO
+#   endif
+#endif
+
+            !                                          ! ===============
+         END DO                                        !   End of slab  
+         !                                             ! ===============
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf - iso')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_ldf_iso
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             No rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ldf_iso( kt )               ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_ldf_iso: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_ldf_iso
+#endif
+
+   !!==============================================================================
+END MODULE trcldf_iso
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso_zps.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso_zps.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_iso_zps.F90	(revision 4536)
@@ -0,0 +1,275 @@
+MODULE trcldf_iso_zps
+   !!==============================================================================
+   !!                   ***  MODULE  trcldf_iso_zps  ***
+   !! Ocean passive tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+#if defined key_top &&  defined key_ldfslp 
+   !!----------------------------------------------------------------------
+   !!   'key_top'          and                                   TOP models
+   !!   'key_ldfslp'               slope of the lateral diffusive direction
+   !!----------------------------------------------------------------------
+   !!   trc_ldf_iso_zps : update the tracer trend with the horizontal 
+   !!                     component of a iso-neutral laplacian operator
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_ldf_iso_zps  ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcldf_iso_zps.F90,v 1.11 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ldf_iso_zps( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ldf_iso_zps  ***
+      !!
+      !! ** Purpose :   Compute the before horizontal tracer  diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   The horizontal component of the lateral diffusive trends 
+      !!      is provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      horizontal fluxes associated with the rotated lateral mixing:
+      !!         zftu = (aht+ahtb0) e2u*e3u/e1u di[ tb ]
+      !!               - aht       e2u*uslp    dk[ mi(mk(trb)) ]
+      !!         zftv = (aht+ahtb0) e1v*e3v/e2v dj[ tb ]
+      !!               - aht       e2u*vslp    dk[ mj(mk(trb)) ]
+      !!      add horizontal Eddy Induced advective fluxes (lk_traldf_eiv=T):
+      !!         zftu = zftu - dk-1[ aht e2u mi(wslpi) ] mi( trb ) 
+      !!         zftv = zftv - dk-1[ aht e1v mj(wslpj) ] mj( trb ) 
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) {  di-1[ zftu ] +  dj-1[ zftv ]  }
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + difft
+      !!
+      !!      'key_trdtra' defined: the trend is saved for diagnostics.
+      !!
+      !!      macro-tasked on horizontal slab (jk-loop).
+      !!
+      !! ** Action :
+      !!         Update tra arrays with the before along level biharmonic
+      !!      mixing trend.
+      !!         Save in trtrd arrays the trends if 'key_trc_diatrd' defined
+      !!
+      !! History :
+      !!        !  94-08  (G. Madec, M. Imbard)
+      !!        !  97-05  (G. Madec)  split into traldf and trazdf
+      !!   8.5  !  02-08  (G. Madec)  Free form, F90
+      !!   9.0  !  04-03  (C. Ethe)  adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc       , zftu => ua,  &  ! use ua as workspace
+         &                zfsu => va      ! use va as workspace
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn          ! dummy loop indices
+      INTEGER ::   iku, ikv               ! temporary integer
+      REAL(wp) ::   &
+         zabe1, zabe2, zcof1, zcof2,   &  ! temporary scalars
+         zmsku, zmskv, zbtr, ztra       
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zdkt , zdk1t                     ! temporary workspace
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   & 
+         zftv, zgtbu, zgtbv               ! temporary workspace
+
+#if defined key_trcldf_eiv
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zftug, zftvg                    ! temporary workspace
+
+      REAL(wp) ::   &
+         zuwk, zvwk,                   &
+         zuwk1, zvwk1,                 &
+         zcg1,zcg2
+
+#if defined key_trc_diatrd
+      REAL(wp) ::   &
+         ztagu, ztagv
+#endif
+
+#endif
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_ldf_iso_zps : iso neutral laplacian diffusion in '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   z-coordinates with partial steps'
+#if defined key_trcldf_eiv && defined key_diaeiv
+         u_trc_eiv(:,:,:) = 0.e0
+         v_trc_eiv(:,:,:) = 0.e0
+#endif
+      ENDIF
+
+      DO jn = 1, jptra
+
+#if defined key_trcldf_eiv && key_trc_diatrd
+         ztagu = 0.e0
+         ztagv = 0.e0
+#endif
+
+         ! Horizontal passive tracer gradient 
+         DO jk = 1, jpk
+            DO jj = 1, jpj-1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zgtbu(ji,jj,jk) = tmask(ji,jj,jk) * ( trb(ji+1,jj  ,jk,jn) - trb(ji,jj,jk,jn) )
+                  zgtbv(ji,jj,jk) = tmask(ji,jj,jk) * ( trb(ji  ,jj+1,jk,jn) - trb(ji,jj,jk,jn) )
+               END DO
+            END DO
+         END DO
+         ! partial steps correction at the last level 
+         DO jj = 1, jpj-1
+            DO ji = 1, jpi-1
+               ! last level
+               iku = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+               ikv = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+               zgtbu(ji,jj,iku) = gtru(ji,jj,jn)               
+               zgtbv(ji,jj,ikv) = gtrv(ji,jj,jn)               
+            END DO
+         END DO
+
+         !                                                ! ===============
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !                                             ! ===============
+            ! 1. Vertical tracer gradient at level jk and jk+1
+            ! ------------------------------------------------
+            ! surface boundary condition: zdkt(jk=1)=zdkt(jk=2)
+
+            zdk1t(:,:) = ( trb(:,:,jk,jn) - trb(:,:,jk+1,jn) ) * tmask(:,:,jk+1)
+
+            IF( jk == 1 ) THEN
+               zdkt(:,:) = zdk1t(:,:)
+            ELSE
+               zdkt(:,:) = ( trb(:,:,jk-1,jn) - trb(:,:,jk,jn) ) * tmask(:,:,jk)
+            ENDIF
+
+
+            ! 2. Horizontal fluxes
+            ! --------------------
+
+            DO jj = 1 , jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zabe1 = ( fsahtru(ji,jj,jk) + ahtrb0 ) * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
+                  zabe2 = ( fsahtrv(ji,jj,jk) + ahtrb0 ) * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+
+                  zmsku = 1. / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
+                     + tmask(ji+1,jj,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+                  zmskv = 1. / MAX(  tmask(ji,jj+1,jk  ) + tmask(ji,jj,jk+1)   &
+                     + tmask(ji,jj+1,jk+1) + tmask(ji,jj,jk  ), 1. )
+
+                  zcof1 = -fsahtru(ji,jj,jk) * e2u(ji,jj) * uslp(ji,jj,jk) * zmsku
+                  zcof2 = -fsahtrv(ji,jj,jk) * e1v(ji,jj) * vslp(ji,jj,jk) * zmskv
+
+                  zftu(ji,jj,jk) = umask(ji,jj,jk) * (  zabe1 * zgtbu(ji,jj,jk)   &
+                     &                                + zcof1 * (  zdkt (ji+1,jj) + zdk1t(ji,jj)      &
+                     &                                           + zdk1t(ji+1,jj) + zdkt (ji,jj)  )  )
+                  zftv(ji,jj,jk) = vmask(ji,jj,jk) * (  zabe2 * zgtbv(ji,jj,jk)   &
+                     &                                + zcof2 * (  zdkt (ji,jj+1) + zdk1t(ji,jj)      &
+                     &                                           + zdk1t(ji,jj+1) + zdkt (ji,jj)  )  )
+               END DO
+            END DO
+
+# if defined key_trcldf_eiv
+            ! ---------------------------------------!
+            ! Eddy induced vertical advective fluxes !
+            ! ---------------------------------------!
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zuwk = ( wslpi(ji,jj,jk  ) + wslpi(ji+1,jj  ,jk  ) ) * fsaeitru(ji,jj,jk  ) * umask(ji,jj,jk  )
+                  zuwk1= ( wslpi(ji,jj,jk+1) + wslpi(ji+1,jj  ,jk+1) ) * fsaeitru(ji,jj,jk+1) * umask(ji,jj,jk+1)
+                  zvwk = ( wslpj(ji,jj,jk  ) + wslpj(ji  ,jj+1,jk  ) ) * fsaeitrv(ji,jj,jk  ) * vmask(ji,jj,jk  )
+                  zvwk1= ( wslpj(ji,jj,jk+1) + wslpj(ji  ,jj+1,jk+1) ) * fsaeitrv(ji,jj,jk+1) * vmask(ji,jj,jk+1)
+
+                  zcg1= -0.25 * e2u(ji,jj) * umask(ji,jj,jk) * ( zuwk-zuwk1 )
+                  zcg2= -0.25 * e1v(ji,jj) * vmask(ji,jj,jk) * ( zvwk-zvwk1 )
+
+                  zftug(ji,jj) = zcg1 * ( trb(ji+1,jj,jk,jn) + trb(ji,jj,jk,jn) )
+                  zftvg(ji,jj) = zcg2 * ( trb(ji,jj+1,jk,jn) + trb(ji,jj,jk,jn) )
+
+                  zftu(ji,jj,jk) = zftu(ji,jj,jk) + zftug(ji,jj)
+                  zftv(ji,jj,jk) = zftv(ji,jj,jk) + zftvg(ji,jj)
+
+#   if defined key_diaeiv
+                  u_trc_eiv(ji,jj,jk) = -2. * zcg1 / ( e2u(ji,jj) * fse3u(ji,jj,jk) )
+                  v_trc_eiv(ji,jj,jk) = -2. * zcg2 / ( e1v(ji,jj) * fse3v(ji,jj,jk) )
+#   endif
+               END DO
+            END DO
+# endif
+
+            ! II.4 Second derivative (divergence) and add to the general trend
+            ! ----------------------------------------------------------------
+
+            DO jj = 2 , jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr= 1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ztra = zbtr * ( zftu(ji,jj,jk) - zftu(ji-1,jj,jk) + zftv(ji,jj,jk) - zftv(ji,jj-1,jk)  )
+                  tra (ji,jj,jk,jn) = tra (ji,jj,jk,jn) + ztra
+#if defined key_trc_diatrd
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),4) = zbtr * ( zftu(ji,jj,jk) - zftu(ji-1,  jj,jk) )
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),5) = zbtr * ( zftv(ji,jj,jk) - zftv(ji  ,jj-1,jk) )
+#endif
+               END DO
+            END DO
+#if defined key_trc_diatrd
+#   if defined key_trcldf_eiv
+            DO jj = 2 , jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr= 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztagu = ( zftug(ji,jj) - zftug(ji-1,jj  ) ) * zbtr
+                  ztagv = ( zftvg(ji,jj) - zftvg(ji  ,jj-1) ) * zbtr
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),4) = trtrd(ji,jj,jk,ikeep(jn),4) - ztagu
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),5) = trtrd(ji,jj,jk,ikeep(jn),5) - ztagv
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),7) = ztagu
+                  IF (luttrd(jn)) trtrd (ji,jj,jk,ikeep(jn),8) = ztagv
+               END DO
+            END DO
+#   endif
+#endif
+            !                                          ! ===============
+         END DO                                        !   End of slab  
+         !                                             ! ===============
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf - iso/zps')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_ldf_iso_zps
+
+#else
+   !!----------------------------------------------------------------------
+   !!   default option :   Dummy code   NO rotation of the diffusive tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ldf_iso_zps( kt )               ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_ldf_iso_zps: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_ldf_iso_zps
+#endif
+
+   !!==============================================================================
+END MODULE trcldf_iso_zps
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_lap.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_lap.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcldf_lap.F90	(revision 4536)
@@ -0,0 +1,166 @@
+MODULE trcldf_lap
+   !!==============================================================================
+   !!                       ***  MODULE  trcldf_lap  ***
+   !! Ocean passive tracers:  horizontal component of the lateral tracer mixing trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_ldf_lap  : update the tracer trend with the horizontal diffusion
+   !!                 using a iso-level harmonic (laplacien) operator.
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_ldf_lap  ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE trc_ldf_lap( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ldf_lap  ***
+      !!                   
+      !! ** Purpose :   Compute the before horizontal tracer diffusive 
+      !!      trend and add it to the general trend of tracer equation.
+      !!
+      !! ** Method  :   Second order diffusive operator evaluated using before
+      !!      fields (forward time scheme). The horizontal diffusive trends of 
+      !!      the passive tracer is given by:
+      !!       * s-coordinate, the vertical scale 
+      !!      factors e3. are inside the derivatives:
+      !!          difft = 1/(e1t*e2t*e3t) {  di-1[ aht e2u*e3u/e1u di(trb) ]
+      !!                                   + dj-1[ aht e1v*e3v/e2v dj(trb) ] }
+      !!       * z-coordinate (default key), e3t=e3u=e3v, the trend becomes:
+      !!          difft = 1/(e1t*e2t) {  di-1[ aht e2u/e1u di(trb) ]
+      !!                               + dj-1[ aht e1v/e2v dj(trb) ] }
+      !!      Add this trend to the general tracer trend tra :
+      !!          tra = tra + difft
+      !!
+      !! ** Action  : - Update tra arrays with the before iso-level 
+      !!                harmonic mixing trend.
+      !!              - Save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   1.0  !  87-06  (P. Andrich, D. L Hostis)  Original code
+      !!        !  91-11  (G. Madec)
+      !!        !  95-02  (M. Levy)    passive tracers
+      !!        !  95-11  (G. Madec)  suppress volumetric scale factors
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe)   passive tracer
+      !!----------------------------------------------------------------------
+      USE oce_trc          , ztu => ua,  &  ! use ua as workspace
+         &                   ztv => va      ! use va as workspace
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      
+      !! * Local save
+      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
+         ze1ur, ze2vr, zbtr2              ! scale factor coefficients
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn         ! dummy loop indices
+      REAL(wp) ::   &
+         zabe1, zabe2, zbtr              ! temporary scalars
+
+      REAL(wp) ::   &
+         ztra, ztrax, ztray              ! workspace
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+      
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_ldf_lap : iso-level laplacian diffusion'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         ze1ur(:,:) = e2u(:,:) / e1u(:,:)
+         ze2vr(:,:) = e1v(:,:) / e2v(:,:)
+         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF
+ 
+      DO jn = 1, jptra
+         
+         !                                                  ! =============
+         DO jk = 1, jpkm1                                   ! Vertical slab
+            !                                               ! =============
+            ! 1. First derivative (gradient)
+            ! -------------------
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  IF ( ln_sco ) THEN
+                     zabe1 = fsahtru(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj) * fse3u(ji,jj,jk)
+                     zabe2 = fsahtrv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj) * fse3v(ji,jj,jk)
+                  ELSE
+                     zabe1 = fsahtru(ji,jj,jk) * umask(ji,jj,jk) * ze1ur(ji,jj)
+                     zabe2 = fsahtrv(ji,jj,jk) * vmask(ji,jj,jk) * ze2vr(ji,jj)
+                  ENDIF
+                  ztu(ji,jj,jk) = zabe1 * ( trb(ji+1,jj  ,jk,jn) - trb(ji,jj,jk,jn) )
+                  ztv(ji,jj,jk) = zabe2 * ( trb(ji  ,jj+1,jk,jn) - trb(ji,jj,jk,jn) )
+               END DO
+            END DO
+
+
+            ! 2. Second derivative (divergence)
+            ! --------------------
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  IF ( ln_sco ) THEN
+                     zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+                  ELSE
+                     zbtr = zbtr2(ji,jj)
+                  ENDIF
+                  ! horizontal diffusive trends
+                  ztrax = zbtr * ( ztu(ji,jj,jk) - ztu(ji-1,jj,jk) )
+                  ztray = zbtr * ( ztv(ji,jj,jk) - ztv(ji,jj-1,jk) )
+
+                  ! add it to the general tracer trends
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztrax + ztray
+
+#if defined key_trc_diatrd
+                  ! save the horizontal diffusive trends
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),4) = ztrax
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),5) = ztray
+#endif
+               END DO
+            END DO
+            !                                               ! =============
+         END DO                                             !  End of slab  
+         !                                                  ! =============
+
+      END DO
+
+     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ldf - lap')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_ldf_lap
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ldf_lap( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_ldf_lap: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_ldf_lap
+#endif
+
+   !!==============================================================================
+END MODULE trcldf_lap
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 4536)
@@ -0,0 +1,182 @@
+MODULE trcnxt
+   !!======================================================================
+   !!                       ***  MODULE  trcnxt  ***
+   !! Ocean passive tracers:  time stepping on passives tracers
+   !!======================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_nxt     : time stepping on passive tracers
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE trctrp_lec      ! pasive tracers transport
+   USE prtctl_trc      ! Print control for debbuging
+   USE agrif_top_update
+   USE agrif_top_interp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_nxt          ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nxt( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trcnxt  ***
+      !!
+      !! ** Purpose :   Compute the passive tracers fields at the 
+      !!      next time-step from their temporal trends and swap the fields.
+      !! 
+      !! ** Method  :   Apply lateral boundary conditions on (ua,va) through 
+      !!      call to lbc_lnk routine
+      !!   default:
+      !!      arrays swap
+      !!         (trn) = (tra) ; (tra) = (0,0)
+      !!         (trb) = (trn) 
+      !!
+      !!   For Arakawa or TVD Scheme : 
+      !!      A Asselin time filter applied on now tracers (trn) to avoid
+      !!      the divergence of two consecutive time-steps and tr arrays
+      !!      to prepare the next time_step:
+      !!         (trb) = (trn) + atfp [ (trb) + (tra) - 2 (trn) ]
+      !!         (trn) = (tra) ; (tra) = (0,0)
+      !!
+      !!
+      !! ** Action  : - update trb, trn
+      !!
+      !! History :
+      !!   7.0  !  91-11  (G. Madec)  Original code
+      !!        !  93-03  (M. Guyon)  symetrical conditions
+      !!        !  95-02  (M. Levy)   passive tracers 
+      !!        !  96-02  (G. Madec & M. Imbard)  opa release 8.0
+      !!   8.0  !  96-04  (A. Weaver)  Euler forward step
+      !!   8.2  !  99-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!        !  02-11  (C. Talandier, A-M Treguier) Open boundaries
+      !!   9.0  !  04-03  (C. Ethe) passive tracers 
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
+      REAL(wp) ::   zfact            ! temporary scalar
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_nxt : time stepping on passive tracers'
+      ENDIF
+
+
+      DO jn = 1, jptra
+
+         ! 0. Lateral boundary conditions on tra (T-point, unchanged sign)
+         ! ---------------------------------============
+         CALL lbc_lnk( tra(:,:,:,jn), 'T', 1. )   
+         
+         !                                                ! ===============
+         DO jk = 1, jpk                                   ! Horizontal slab
+            !                                             ! ===============
+            ! 1. Leap-frog scheme (only in explicit case, otherwise the 
+            ! -------------------  time stepping is already done in trczdf)
+            IF( l_trczdf_exp .AND. ( ln_trcadv_cen2 .OR. ln_trcadv_tvd) ) THEN
+               zfact = 2. * rdttra(jk) * FLOAT(ndttrc) 
+               IF( neuler == 0 .AND. kt == nittrc000 ) zfact = rdttra(jk) * FLOAT(ndttrc) 
+               tra(:,:,jk,jn) = ( trb(:,:,jk,jn) + zfact * tra(:,:,jk,jn) ) * tmask(:,:,jk)
+            ENDIF
+
+         END DO
+
+#if defined key_obc
+        CALL ctl_stop( '          Passive tracers and Open Boundary condition can not be used together ' &
+           &           '          Check in trc_nxt routine' )
+#endif
+
+#if defined key_agrif
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update tracers 
+      CALL Agrif_trc( kt )
+      !                                                ! ===============
+      DO jn = 1, jptra                                 ! Horizontal slab
+         !                                             ! ===============
+#endif
+
+         DO jk = 1, jpk  
+
+            ! 2. Time filter and swap of arrays
+            ! ---------------------------------
+            IF ( ln_trcadv_cen2 .OR. ln_trcadv_tvd  ) THEN
+
+               IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        trb(ji,jj,jk,jn) = trn(ji,jj,jk,jn)
+                        trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn)
+                        tra(ji,jj,jk,jn) = 0.
+                     END DO
+                  END DO
+               ELSE
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        trb(ji,jj,jk,jn) = atfp  * ( trb(ji,jj,jk,jn) + tra(ji,jj,jk,jn) ) + atfp1 * trn(ji,jj,jk,jn)
+                        trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn)
+                        tra(ji,jj,jk,jn) = 0.
+                     END DO
+                  END DO
+               ENDIF
+
+            ELSE
+!  case of smolar scheme or muscl
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     trb(ji,jj,jk,jn) = tra(ji,jj,jk,jn)
+                     trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn)
+                     tra(ji,jj,jk,jn) = 0.
+                  END DO
+               END DO
+
+            ENDIF
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('nxt')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+
+#if defined key_agrif
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Trc( kt )
+#endif      
+
+
+   END SUBROUTINE trc_nxt
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nxt( kt )  
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_nxt: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_nxt
+#endif
+   !!======================================================================
+END MODULE trcnxt
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcrad.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 4536)
@@ -0,0 +1,158 @@
+MODULE trcrad
+   !!======================================================================
+   !!                       ***  MODULE  trcrad  ***
+   !! Ocean passive tracers:  correction of negative concentrations
+   !!======================================================================
+   !! History :   -   !  01-01  (O. Aumont & E. Kestenare)  Original code
+   !!            1.0  !  04-03  (C. Ethe)  free form F90
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_rad    : correction of negative concentrations
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE lib_mpp
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_rad        ! routine called by trcstp.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+
+   SUBROUTINE trc_rad( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_rad  ***
+      !!
+      !! ** Purpose :   "crappy" routine to correct artificial negative
+      !!              concentrations due to isopycnal scheme
+      !!
+      !! ** Method  : - PISCES or LOBSTER: Set negative concentrations to zero
+      !!                while computing the corresponding tracer content that
+      !!                is added to the tracers. Then, adjust the tracer 
+      !!                concentration using a multiplicative factor so that 
+      !!                the total tracer concentration is preserved.
+      !!              - CFC: simply set to zero the negative CFC concentration
+      !!                (the total CFC content is not strictly preserved)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index      
+      !!
+      INTEGER  ::  ji, jj, jk, jn     ! dummy loop indices
+      REAL(wp) :: zvolk, ztrcorb, ztrmasb   ! temporary scalars
+      REAL(wp) :: zcoef, ztrcorn, ztrmasn   !    "         "
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_rad : Correct artificial negative concentrations '
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      IF( lk_cfc ) THEN                         ! CFC model
+         DO jn = 1, jptra
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     trn(ji,jj,jk,jn) = MAX( 0. , trn(ji,jj,jk,jn) )
+                     trb(ji,jj,jk,jn) = MAX( 0. , trb(ji,jj,jk,jn) )
+                  END DO
+               END DO
+            END DO
+         END DO
+      ENDIF 
+
+      IF( lk_pisces .OR. lk_lobster ) THEN      ! PISCES or LOBSTER bio-model
+         DO jn = 1, jptra
+            ztrcorb = 0.e0
+            ztrmasb = 0.e0
+            ztrcorn = 0.e0
+            ztrmasn = 0.e0
+            DO jk = 1, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zvolk  = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)   &
+# if defined key_off_degrad
+                        &   * facvol(ji,jj,jk)   &
+# endif
+                        &   * tmask(ji,jj,jk) * tmask_i(ji,jj)
+
+                     ztrcorb = ztrcorb + MIN( 0., trb(ji,jj,jk,jn) )  * zvolk
+                     ztrcorn = ztrcorn + MIN( 0., trn(ji,jj,jk,jn) )  * zvolk
+
+                     trb(ji,jj,jk,jn) = MAX( 0. , trb(ji,jj,jk,jn) )
+                     trn(ji,jj,jk,jn) = MAX( 0. , trn(ji,jj,jk,jn) )
+
+                     ztrmasb = ztrmasb + trb(ji,jj,jk,jn) * zvolk
+                     ztrmasn = ztrmasn + trn(ji,jj,jk,jn) * zvolk
+                  END DO
+               END DO
+            END DO
+            IF( lk_mpp ) THEN
+               CALL mpp_sum( ztrcorb )      ! sum over the global domain
+               CALL mpp_sum( ztrcorn )      ! sum over the global domain
+               CALL mpp_sum( ztrmasb )      ! sum over the global domain
+               CALL mpp_sum( ztrmasn )      ! sum over the global domain
+            ENDIF
+
+            IF( ztrcorb /= 0 ) THEN
+               zcoef = 1. + ztrcorb / ztrmasb
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                         trb(ji,jj,jk,jn) = MAX( 0. , trb(ji,jj,jk,jn) )               !!gm bug already done just above
+                        trb(ji,jj,jk,jn) = trb(ji,jj,jk,jn) * zcoef * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+
+            IF( ztrcorn /= 0 ) THEN
+               zcoef = 1. + ztrcorn / ztrmasn
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        trn(ji,jj,jk,jn) = MAX( 0. , trn(ji,jj,jk,jn) )                !!gm bug already done just above
+                        trn(ji,jj,jk,jn) = trn(ji,jj,jk,jn) * zcoef * tmask(ji,jj,jk)
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+            !
+         END DO
+         !
+      ENDIF
+      !
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('rad')")
+         CALL prt_ctl_trc_info( charout )
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+      !
+   END SUBROUTINE trc_rad
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                         NO TOP model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_rad( kt )              ! Empty routine
+      INTEGER, INTENT(in) ::   kt
+      WRITE(*,*) 'trc_rad: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_rad
+#endif
+   
+   !!======================================================================
+END MODULE trcrad
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 4536)
@@ -0,0 +1,122 @@
+MODULE trcsbc
+   !!==============================================================================
+   !!                       ***  MODULE  trcsbc  ***
+   !! Ocean passive tracers:  surface boundary condition
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_sbc      : update the tracer trend at ocean surface
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean  passive tracers variables
+   USE prtctl_trc          ! Print control for debbuging
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_sbc              ! routine called by step.F90
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trcsbc.F90,v 1.10 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sbc ( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_sbc  ***
+      !!                   
+      !! ** Purpose :   Compute the tracer surface boundary condition trend of
+      !!      (concentration/dilution effect) and add it to the general 
+      !!       trend of tracer equations.
+      !!
+      !! ** Method :
+      !!      * concentration/dilution effect:
+      !!            The surface freshwater flux modify the ocean volume
+      !!         and thus the concentration of a tracer as :
+      !!            tra = tra + emp * trn / e3t   for k=1
+      !!         where emp, the surface freshwater budget (evaporation minus
+      !!         precipitation minus runoff) given in kg/m2/s is divided
+      !!         by 1000 kg/m3 (density of plain water) to obtain m/s.
+      !!
+      !! ** Action  : - Update the 1st level of tra with the trend associated
+      !!                with the tracer surface boundary condition 
+      !!
+      !! History :
+      !!   8.2  !  98-10  (G. Madec, G. Roullet, M. Imbard)  Original code
+      !!   8.2  !  01-02  (D. Ludicone)  sea ice and free surface
+      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe)  adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER  ::   ji, jj, jn           ! dummy loop indices
+      REAL(wp) ::   ztra, zsrau, zse3t   ! temporary scalars
+      CHARACTER (len=22) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_sbc : Passive tracers surface boundary condition'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+      ENDIF
+
+      ! 0. initialization
+      zsrau = 1. / rauw
+      IF( .NOT. ln_sco )  zse3t = 1. / fse3t(1,1,1)
+#if defined key_trc_diatrd
+      DO jn = 1, jptra
+        IF (luttrd(jn)) trtrd(:,:,:,ikeep(jn),jpdiatrc) = 0.0
+      END DO
+#endif
+
+      DO jn = 1, jptra
+         ! 1. Concentration dillution effect on tra
+         DO jj = 2, jpj
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               IF( ln_sco ) zse3t = 1. / fse3t(ji,jj,1)
+               ! concent./dilut. effect
+               ztra = emps(ji,jj) * zsrau * trn(ji,jj,1,jn) * zse3t * tmask(ji,jj,1)
+               
+               ! add the trend to the general tracer trend
+               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + ztra
+#if defined key_trc_diatrd
+               IF (luttrd(jn)) trtrd(ji,jj,1,ikeep(jn),jpdiatrc) = trtrd(ji,jj,1,jn,jpdiatrc)+ztra
+#endif
+            END DO
+         END DO
+         
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sbc')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_sbc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      NO passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sbc (kt)              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_sbc: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sbc
+#endif
+   
+   !!======================================================================
+END MODULE trcsbc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 4536)
@@ -0,0 +1,142 @@
+MODULE trctrp
+   !!======================================================================
+   !!                       ***  MODULE trctrp  ***
+   !! Ocean Physics    : manage the passive tracer transport
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (C. Ethe) Original code
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_trp        : passive tracer transport
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! ocean dynamics and active tracers variables
+   USE trc             ! ocean passive tracers variables 
+   USE trctrp_lec      ! passive tracers transport parameters
+   USE prtctl_trc     ! Print control for debbuging
+
+   USE trcbbl          ! bottom boundary layer               (trc_bbl routine)
+   USE trcdmp          ! internal damping                    (trc_dmp routine)
+
+   USE trcldf_bilapg   ! lateral mixing               (trc_ldf_bilapg routine)
+   USE trcldf_bilap    ! lateral mixing                (trc_ldf_bilap routine)
+   USE trcldf_iso      ! lateral mixing                  (trc_ldf_iso routine)
+   USE trcldf_iso_zps  ! lateral mixing              (trc_ldf_iso_zps routine)
+   USE trcldf_lap      ! lateral mixing                  (trc_ldf_lap routine)
+ 
+   USE trcnxt          ! time-stepping                       (trc_nxt routine)
+   USE trcrad          ! positivity                          (trc_rad routine)
+
+   USE trcadv_cen2     ! 2nd order centered advection   (trc_adv_cen2 routine)
+   USE trcadv_muscl    ! MUSCL advection               (trc_adv_muscl routine)
+   USE trcadv_muscl2   ! MUSCL2 advection             (trc_adv_muscl2 routine)
+   USE trcadv_tvd      ! TVD advection                   (trc_adv_tvd routine)
+   USE trcadv_smolar   ! SMOLAR advection             (trc_adv_smolar routine)
+
+   USE trczdf_exp      ! vertical diffusion              (trc_zdf_exp routine)
+   USE trczdf_imp      ! vertical diffusion              (trc_zdf_exp routine)
+   USE trczdf_iso      ! vertical diffusion              (trc_zdf_exp routine)
+   USE trczdf_iso_vopt ! vertical diffusion              (trc_zdf_exp routine)
+   USE trcsbc          ! surface boundary condition          (trc_sbc routine)
+
+   USE zpshde_trc      ! partial step: hor. derivative   (zps_hde_trc routine)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_trp    ! called by trc_stp
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_trp( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_trp  ***
+      !!                      
+      !! ** Purpose :   Management of passive tracers transport
+      !! 
+      !! ** Method  : - Compute the passive tracers trends 
+      !!              - Update the passive tracers
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::  kt  ! ocean time-step index
+      !!
+      CHARACTER (len=25) :: charout
+      !! ---------------------------------------------------------------------
+
+                               CALL trc_sbc( kt )            ! surface boundary condition
+# if defined key_trcbbc
+!!gm bug : this should be control during the initialisation phase, not here!
+       CALL ctl_stop( '  Bottom heat flux not yet implemented with passive tracer         ' &
+           &          '  Check in trc_trp routine ' )
+# endif 
+      !                                                      ! bottom boundary condition
+      IF( lk_trcbbl_dif    )   CALL trc_bbl_dif( kt )            ! diffusive bottom boundary layer scheme
+      IF( lk_trcbbl_adv    )   CALL trc_bbl_adv( kt )            ! advective (and/or diffusive) bottom boundary layer scheme
+
+      IF( lk_trcdmp        )   CALL trc_dmp( kt )            ! internal damping trends
+
+      !                                                      ! horizontal & vertical advection
+      IF( ln_trcadv_cen2   )   CALL trc_adv_cen2  ( kt )         ! 2nd order centered scheme
+      IF( ln_trcadv_muscl  )   CALL trc_adv_muscl ( kt )         ! MUSCL scheme
+      IF( ln_trcadv_muscl2 )   CALL trc_adv_muscl2( kt )         ! MUSCL2 scheme
+      IF( ln_trcadv_tvd    )   CALL trc_adv_tvd   ( kt )         ! TVD scheme
+      IF( ln_trcadv_smolar )   CALL trc_adv_smolar( kt )         ! SMOLARKIEWICZ scheme
+
+ 
+      IF( n_cla == 1   ) THEN
+!!gm bug : this should be control during the initialisation phase, not here!
+         WRITE(ctmp1,*) ' Cross Land Advection not yet implemented with passive tracer n_cla = ',n_cla
+         CALL ctl_stop( ctmp1 )
+      ENDIF
+
+      !                                                      ! lateral mixing 
+      IF( l_trcldf_bilapg  )   CALL trc_ldf_bilapg ( kt )        ! s-coord. horizontal bilaplacian
+      IF( l_trcldf_bilap   )   CALL trc_ldf_bilap  ( kt )        ! iso-level bilaplacian 
+      IF( l_trcldf_iso     )   CALL trc_ldf_iso    ( kt )        ! iso-neutral laplacian 
+      IF( l_trcldf_iso_zps )   CALL trc_ldf_iso_zps( kt )        ! partial step iso-neutral laplacian
+      IF( l_trcldf_lap     )   CALL trc_ldf_lap    ( kt )        ! iso-level laplacian
+ 
+      !                                                      ! vertical diffusion
+      IF( l_trczdf_exp     )   CALL trc_zdf_exp     ( kt )       ! explicit time stepping (time splitting scheme)
+      IF( l_trczdf_imp     )   CALL trc_zdf_imp     ( kt )       ! implicit time stepping (euler backward)
+      IF( l_trczdf_iso     )   CALL trc_zdf_iso     ( kt )       ! isopycnal
+      IF( l_trczdf_iso_vo  )   CALL trc_zdf_iso_vopt( kt )       ! vector opt. isopycnal
+
+                               CALL trc_nxt( kt )            ! tracer fields at next time step
+ 
+                               CALL trc_rad( kt )            ! Correct artificial negative concentrations
+      !                                                      ! especially useful when isopycnal mixing is used
+      !                                                      
+
+      IF( ln_zps .AND. .NOT. lk_trccfg_1d )   &              ! Partial steps: now horizontal gradient of passive
+         &                     CALL zps_hde_trc( kt, trb, gtru, gtrv )       ! tracers at the bottom ocean level
+      !
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('TRP')")
+         CALL prt_ctl_trc_info( charout )
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+      !
+   END SUBROUTINE trc_trp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        No TOP models
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_trp( kt )              ! Empty routine
+      INTEGER, INTENT(in) ::   kt
+      WRITE(*,*) 'trc_trp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_trp
+#endif
+   
+   !!======================================================================
+END MODULE trctrp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_ctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_ctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_ctl.F90	(revision 4536)
@@ -0,0 +1,330 @@
+MODULE trctrp_ctl
+   !!======================================================================
+   !!                       ***  MODULE  trctrp_ctl  ***
+   !! TOP :   transport option control
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (C. Ethe) Original code
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_trp_ctl  : control the different options of transport
+   !!   trc_adv_ctl  : control the different options of the advection
+   !!   trc_ldf_ctl  : control the different options of the lateral diffusion
+   !!   trc_zdf_ctl  : control the different options of the vertical diffusion
+   !!   trc_dmp_ctl  : control the different options of the internal damping
+   !!----------------------------------------------------------------------
+   USE oce_trc       ! ocean dynamics and active tracers variables
+   USE trc           ! ocean passive tracers variables
+   USE trctrp_lec    ! passive tracers transport
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_trp_ctl   ! called by ???
+
+#if defined key_trcldf_eiv
+      LOGICAL, PARAMETER ::   lk_trcldf_eiv   = .TRUE.   !: eddy induced velocity flag
+#else   
+      LOGICAL, PARAMETER ::   lk_trcldf_eiv   = .FALSE.  !: eddy induced velocity flag
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_trp_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_trp_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between cpp options for 
+      !!                tracer transport
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      CALL trc_adv_ctl      ! Control of Advection scheme options
+
+      CALL trc_ldf_ctl      ! Control of Lateral diffusion scheme options
+
+      CALL trc_zdf_ctl      ! Control of Vertival diffusion scheme options
+
+      !                     ! Control of Newtonian damping  options
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** Tracer damping option'
+      ENDIF
+#if defined key_trcdmp
+      IF(lwp) WRITE(numout,*) '     key_trcdmp is defined:   Check trcdmp ROUTINE '
+      CALL trc_dmp_ctl
+#else
+      IF(lwp) WRITE(numout,*) '     No tracer damping'
+#endif
+      !
+   END SUBROUTINE trc_trp_ctl
+
+
+   SUBROUTINE trc_adv_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_adv_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between cpp options for 
+      !!              tracer advection schemes
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+      !!----------------------------------------------------------------------
+
+      ! Control of Advection scheme options
+      ! -----------------------------------
+     IF( lk_trccfg_1d ) THEN
+         ln_trcadv_cen2   = .FALSE.    ;  ln_trcadv_tvd    = .FALSE. ; ln_trcadv_muscl  = .FALSE.
+         ln_trcadv_muscl2 = .FALSE.    ;  ln_trcadv_smolar = .FALSE.
+         IF(lwp) WRITE(numout,*) ' *** 1D configuration : No advection on passive tracers '
+         IF(lwp) WRITE(numout,*) 
+      ELSE
+         ioptio = 0
+         IF( ln_trcadv_cen2   )   ioptio = ioptio + 1
+         IF( ln_trcadv_tvd    )   ioptio = ioptio + 1
+         IF( ln_trcadv_muscl  )   ioptio = ioptio + 1
+         IF( ln_trcadv_muscl2 )   ioptio = ioptio + 1
+         IF( ln_trcadv_smolar )   ioptio = ioptio + 1
+         
+         IF( lk_esopa ) THEN
+            IF(lwp) WRITE(numout,*) ' esopa control : the use of all scheme is forced'
+            ln_trcadv_cen2   = .TRUE.
+            ln_trcadv_tvd    = .TRUE.
+            ln_trcadv_muscl  = .TRUE.
+            ln_trcadv_muscl2 = .TRUE.
+            ln_trcadv_smolar = .TRUE.
+         ELSEIF( ioptio > 1 .OR. ioptio == 0 ) THEN
+            CALL ctl_stop( '  Choose one advection scheme in namelist nam_trcadv' )
+         ENDIF
+         
+         IF( n_cla == 1 .AND. .NOT. ln_trcadv_cen2 ) &
+            &    CALL ctl_stop( '    cross-land advection only with 2nd order advection scheme ' )
+      ENDIF
+      !
+   END SUBROUTINE trc_adv_ctl
+
+
+   SUBROUTINE trc_ldf_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ldf_ctl  ***
+      !! 
+      !! ** Purpose :   Control the consistency between cpp options for 
+      !!      tracer lateral diffusion 
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio               ! ???
+      LOGICAL ::   ll_print = .FALSE.   ! =T print eddy coef. in numout      
+      !!----------------------------------------------------------------------
+
+      ! Parameter control
+
+      IF( .NOT. ln_trcldf_diff .OR. lk_trccfg_1d ) THEN
+         l_trcldf_lap = .FALSE.   ;   l_trcldf_bilap   = .FALSE.   ;   l_trcldf_bilapg  = .FALSE.
+         l_trcldf_iso = .FALSE.   ;   l_trcldf_iso_zps = .FALSE.
+         l_trczdf_iso = .FALSE.   ;   l_trczdf_iso_vo  = .FALSE.
+         IF(lwp ) WRITE(numout,*) '*** No lateral diffusion on passive tracers '
+         IF(lwp ) WRITE(numout,*) 
+      ELSE
+         ! control the input
+         ioptio = 0
+         IF( ln_trcldf_lap   )   ioptio = ioptio + 1
+         IF( ln_trcldf_bilap )   ioptio = ioptio + 1
+         IF( ioptio /= 1 )   CALL ctl_stop( '    use ONE of the 2 lap/bilap operator type on tracer' )
+         
+         ioptio = 0
+         IF( ln_trcldf_level )   ioptio = ioptio + 1
+         IF( ln_trcldf_hor   )   ioptio = ioptio + 1
+         IF( ln_trcldf_iso   )   ioptio = ioptio + 1
+         IF( ioptio /= 1 )   CALL ctl_stop( '   use only ONE direction (level/hor/iso)' )
+         
+         ! ... Choice of the lateral scheme used
+         IF( lk_trcldf_eiv ) THEN
+            IF(lwp) WRITE(numout,*) '          eddy induced velocity on tracers'
+            IF( .NOT.ln_trcldf_iso .OR. ln_trcldf_bilap ) &
+               &      CALL ctl_stop( ' the eddy induced velocity on tracers ',&
+               &                     'requires isopycnal laplacian diffusion' )
+         ENDIF
+         
+         IF( ln_sco ) THEN          ! s-coordinates: rotation required for horizontal or isopycnal mixing
+            IF( ( ln_trcldf_iso .OR. ln_trcldf_hor ) .AND. .NOT.lk_ldfslp ) &
+               &      CALL ctl_stop( '  the rotation of the diffusive tensor require key_ldfslp' )
+         ELSE                       ! z-coordinates with/without partial step:
+            ln_trcldf_level = ln_trcldf_level .OR. ln_trcldf_hor      ! level diffusion = horizontal diffusion
+            ln_trcldf_hor   = .FALSE.
+            IF(lwp) WRITE(numout,*) '          horizontal mixing in z-coord or partial steps: force ln_trcldf_level = T'
+            IF(lwp) WRITE(numout,*) '                                                  and    force ln_trcldf_hor   = F'
+            IF( ln_trcldf_iso .AND. .NOT.lk_ldfslp ) &            ! rotation required for isopycnal mixing
+               &      CALL ctl_stop( ' the rotation of the diffusive tensor require key_ldfslp' )
+         ENDIF
+         
+         l_trcldf_lap     =  ln_trcldf_lap   .AND. ln_trcldf_level     ! iso-level   laplacian operator
+         l_trcldf_bilap   =  ln_trcldf_bilap .AND. ln_trcldf_level     ! iso-level bilaplacian operator
+         l_trcldf_bilapg  =  ln_trcldf_bilap .AND. ln_trcldf_hor       ! geopotential bilap. (s-coord)
+         l_trcldf_iso     =  ln_trcldf_lap   .AND.                  &  ! laplacian operator
+            &              ( ln_trcldf_iso   .OR.  ln_trcldf_hor )  &  ! iso-neutral (z-coord) or horizontal (s-coord)
+            &                                     .AND. .NOT.ln_zps
+         l_trcldf_iso_zps =  ln_trcldf_lap   .AND.                  &  ! laplacian operator
+            &              ( ln_trcldf_iso   .OR.  ln_trcldf_hor )  &  ! iso-neutral (partial steps)
+            &                                .AND. ln_zps              ! or geopotential in mixed partial steps/s-coord
+         l_trczdf_iso    = .FALSE.
+         l_trczdf_iso_vo = .FALSE.
+         IF( l_trcldf_iso     )   l_trczdf_iso = .TRUE.
+         IF( l_trcldf_iso_zps )   l_trczdf_iso = .TRUE.
+#if defined key_vectopt_memory
+         IF( l_trczdf_iso ) THEN
+            l_trczdf_iso    = .FALSE.
+            l_trczdf_iso_vo = .TRUE.
+         ENDIF
+#endif
+         
+         ioptio = 0
+         IF( l_trcldf_lap     )   ioptio = ioptio + 1
+         IF( l_trcldf_bilap   )   ioptio = ioptio + 1
+         IF( l_trcldf_bilapg  )   ioptio = ioptio + 1
+         IF( l_trcldf_iso     )   ioptio = ioptio + 1
+         IF( l_trcldf_iso_zps )   ioptio = ioptio + 1
+         IF( ioptio /= 1 ) &
+            &   CALL ctl_stop( '  this combination of operator and direction has not been implemented' )
+         
+         IF( lk_esopa ) THEN
+            l_trcldf_lap = .TRUE.   ;   l_trcldf_bilap   = .TRUE.   ;   l_trcldf_bilapg  = .TRUE.
+            l_trcldf_iso = .TRUE.   ;   l_trcldf_iso_zps = .TRUE.
+            l_trczdf_iso = .TRUE.   ;   l_trczdf_iso_vo  = .TRUE.
+            IF(lwp ) WRITE(numout,*) '          esopa test: use all lateral physics options'
+         ENDIF
+         
+         ! ... Space variation of eddy coefficients
+         ioptio = 0
+#if defined key_traldf_c3d || defined key_off_degrad
+         IF(lwp) WRITE(numout,*) 'tracer mixing coef. = F( latitude, longitude, depth)'
+         ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c2d && ! defined key_off_degrad
+         IF(lwp) WRITE(numout,*) 'tracer mixing coef. = F( latitude, longitude)'
+         ioptio = ioptio + 1
+#endif
+#if defined key_traldf_c1d && ! defined key_off_degrad
+         IF(lwp) WRITE(numout,*) 'tracer mixing coef. = F( depth )'
+         ioptio = ioptio + 1
+         IF( ln_sco ) &
+            &  CALL ctl_stop( '    key_traldf_c1d cannot be used in s-coordinate ' )
+#endif
+         IF( ioptio == 0 ) THEN
+            IF(lwp) WRITE(numout,*) ' tracer mixing coef. = constant (default option)'
+         ELSEIF( ioptio > 1 ) THEN
+            CALL ctl_stop( '  use only one of the following keys:',   &
+               &                 ' key_traldf_c3d, key_traldf_c2d, key_traldf_c1d' )
+         ENDIF
+         
+         IF( l_trcldf_bilap .OR. l_trcldf_bilapg ) THEN
+            IF(lwp) WRITE(numout,*) '  biharmonic tracer diffusion'
+            IF( ahtrc0 > 0 .AND. .NOT. lk_esopa ) &
+               &  CALL ctl_stop( '  The horizontal diffusivity coef. aht0 must be negative' )
+         ELSE
+            IF(lwp) WRITE(numout,*) ' harmonic tracer diffusion (default)'
+            IF( ahtrc0 < 0 .AND. .NOT. lk_esopa ) &
+               &  CALL ctl_stop( ' The horizontal diffusivity coef. aht0 must be positive' )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE trc_ldf_ctl
+
+
+   SUBROUTINE trc_zdf_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_ctl  ***
+      !! 
+      !! ** Purpose :   Control the consistency between cpp options for 
+      !!              tracer vertical diffusion
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      ! Parameter & key controls
+      ! ------------------------
+      ! ... vertical mixing
+      ! time stepping scheme (N.B. TKE && KPP scheme => force the use of implicit scheme)
+#if defined key_zdftke || defined key_zdfkpp
+      l_trczdf_exp = .FALSE.          ! use implicit scheme
+      l_trczdf_imp = .TRUE. 
+#else
+      IF( ln_trc_zdfexp  ) THEN  
+         l_trczdf_exp = .TRUE.           ! use explicit scheme
+         l_trczdf_imp = .FALSE.
+      ELSE
+         l_trczdf_exp = .FALSE.          ! use implicit scheme
+         l_trczdf_imp = .TRUE. 
+      ENDIF
+#endif
+
+      IF( l_trczdf_iso .OR. l_trczdf_iso_vo ) THEN  
+         l_trczdf_exp = .FALSE.          ! iso-neutral diffusion : 
+         l_trczdf_imp = .FALSE.          ! implicit scheme included in iso-neutral routine
+      ENDIF
+
+#if defined key_esopa
+      l_trczdf_exp = .TRUE.           ! esopa: use all options
+      l_trczdf_imp = .TRUE.
+#endif
+      !
+   END SUBROUTINE trc_zdf_ctl
+
+
+   SUBROUTINE trc_dmp_ctl
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_dmp_ctl  ***
+      !! 
+      !! ** Purpose :    Control the consistency between cpp options for 
+      !!              tracer newtonian damping 
+      !!----------------------------------------------------------------------
+#if defined key_trcdmp
+
+      SELECT CASE ( ndmptr )
+      !
+      CASE ( -1 )               ! ORCA: damping in Red & Med Seas only
+         IF(lwp) WRITE(numout,*) '          tracer damping in the Med & Red seas only'
+         !
+      CASE ( 1:90 )             ! Damping poleward of 'ndmptr' degrees
+         IF(lwp) WRITE(numout,*) '          tracer damping poleward of', ndmptr, ' degrees'
+         !
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nmldmp = ', ndmptr
+         CALL ctl_stop(ctmp1)
+         !
+      END SELECT
+
+      SELECT CASE ( nmldmptr )
+      !
+      CASE ( 0 )                ! newtonian damping throughout the water column
+         IF(lwp) WRITE(numout,*) '          tracer damping throughout the water column'
+         !
+      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
+         IF(lwp) WRITE(numout,*) '          no tracer damping in the turbocline'
+         !
+      CASE ( 2 )                ! no damping in the mixed layer 
+         IF(lwp) WRITE(numout,*) '          no tracer damping in the mixed layer'
+         !
+      CASE DEFAULT
+         WRITE(ctmp1,*) '          bad flag value for nmldmp = ', nmldmptr
+         CALL ctl_stop(ctmp1)
+         !
+      END SELECT
+#endif
+      !
+   END SUBROUTINE trc_dmp_ctl
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                        No TOP models
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_trp_ctl             ! Empty routine
+   END SUBROUTINE trc_trp_ctl
+#endif
+   
+  !!======================================================================
+END MODULE trctrp_ctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_lec.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_lec.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trctrp_lec.F90	(revision 4536)
@@ -0,0 +1,191 @@
+MODULE trctrp_lec
+   !!======================================================================
+   !!                       ***  MODULE  trctrp_lec  ***
+   !! TOP :   namelist read options for transport
+   !!======================================================================
+   !! History :   1.0  !  2004-03  (C. Ethe)  Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_trp_lec  : read the passive tracer namelist for transport
+   !!----------------------------------------------------------------------
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_trp_lec    ! routine called by step module
+ 
+   !                                                  !!: ** Advection (nam_traadv) **
+   LOGICAL , PUBLIC ::   ln_trcadv_cen2   = .FALSE.   !: 2nd order centered scheme flag
+   LOGICAL , PUBLIC ::   ln_trcadv_tvd    = .FALSE.   !: TVD scheme flag
+   LOGICAL , PUBLIC ::   ln_trcadv_muscl  = .FALSE.   !: MUSCL scheme flag
+   LOGICAL , PUBLIC ::   ln_trcadv_muscl2 = .FALSE.   !: MUSCL2 scheme flag
+   LOGICAL , PUBLIC ::   ln_trcadv_smolar = .TRUE.    !: Smolarkiewicz scheme flag
+
+   !                                                 !!: **  bottom boundary layer (nambbl) **
+   REAL(wp), PUBLIC ::   atrcbbl = 1.e+3              ! lateral coeff. for bottom boundary layer scheme (m2/s)
+
+   !                                                 !!: ** lateral mixing namelist (nam_trcldf) **
+   LOGICAL , PUBLIC ::   ln_trcldf_diff  = .FALSE.    !: flag of perform or not the lateral diff.
+   LOGICAL , PUBLIC ::   ln_trcldf_lap   = .TRUE.     !: laplacian operator
+   LOGICAL , PUBLIC ::   ln_trcldf_bilap = .FALSE.    !: bilaplacian operator
+   LOGICAL , PUBLIC ::   ln_trcldf_level = .FALSE.    !: iso-level direction
+   LOGICAL , PUBLIC ::   ln_trcldf_hor   = .FALSE.    !: horizontal (geopotential) direction
+   LOGICAL , PUBLIC ::   ln_trcldf_iso   = .TRUE.     !: iso-neutral direction
+
+   !                                                 !!: flag of the lateral diff. scheme used
+   LOGICAL , PUBLIC ::   l_trcldf_lap                 !: iso-level laplacian operator
+   LOGICAL , PUBLIC ::   l_trcldf_bilap               !: iso-level bilaplacian operator
+   LOGICAL , PUBLIC ::   l_trcldf_bilapg              !: geopotential bilap. (s-coord)
+   LOGICAL , PUBLIC ::   l_trcldf_iso                 !: iso-neutral laplacian or horizontal lapacian (s-coord)
+   LOGICAL , PUBLIC ::   l_trczdf_iso                 !: idem for the vertical component
+   LOGICAL , PUBLIC ::   l_trczdf_iso_vo              !: idem with vectopt_memory
+   LOGICAL , PUBLIC ::   l_trcldf_iso_zps             !: iso-neutral laplacian (partial steps)
+
+   !                                                 !!: ** Vertical diffusion (nam_trczdf) **
+   LOGICAL , PUBLIC ::   ln_trczdf_exp = .FALSE.      !: explicit vertical diffusion scheme flag
+
+   !                                                 !!: ** vertical diffusion (namzdf) **
+   INTEGER , PUBLIC ::   n_trczdf_exp = 3             !: number of sub-time step (explicit time stepping)
+
+   LOGICAL , PUBLIC ::   l_trczdf_exp     = .FALSE.   !: explicit vertical diffusion
+   LOGICAL , PUBLIC ::   l_trczdf_imp     = .FALSE.   !: implicit vertical diffusion
+
+#if defined key_trcdmp
+   !                                                 !!: ** newtonian damping namelist (nam_trcdmp) **
+   INTEGER  , PUBLIC ::   ndmptr   =   -1             !: = 0/-1/'latitude' for damping over tracers
+   INTEGER  , PUBLIC ::   ndmpftr  =    2             !: = 1 create a damping.coeff NetCDF file 
+   INTEGER  , PUBLIC ::   nmldmptr =    0             !: = 0/1/2 flag for damping in the mixed layer
+
+   !                                                 !!: ** newtonian damping (namdmp) **
+   REAL(wp) , PUBLIC ::   sdmptr   =   50.            !: surface time scale for internal damping (days)
+   REAL(wp) , PUBLIC ::   bdmptr   =  360.            !: bottom time scale for internal damping (days)
+   REAL(wp) , PUBLIC ::   hdmptr   =  800.            !: depth of transition between sdmp and bdmp (meters)
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_trp_lec
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_trp_lec  ***
+      !!                
+      !! ** Purpose :   Read Namelist for tracer transport option
+      !!----------------------------------------------------------------------
+      NAMELIST/namtrcadv/ ln_trcadv_cen2 , ln_trcadv_tvd,   &
+         &                 ln_trcadv_muscl, ln_trcadv_muscl2, ln_trcadv_smolar
+#if  defined key_trcbbl_dif   ||   defined key_trcbbl_adv 
+      NAMELIST/namtrcbbl/ atrcbbl
+#endif
+      NAMELIST/namtrcldf/  ln_trcldf_diff  , ln_trcldf_lap  , ln_trcldf_bilap, &
+         &                 ln_trcldf_level, ln_trcldf_hor, ln_trcldf_iso,   &
+         &                 ahtrc0, ahtrb0, aeivtr0, trcrat
+      NAMELIST/namtrczdf/ ln_trczdf_exp, n_trczdf_exp
+#if defined key_trcdmp
+      NAMELIST/namtrcdmp/ ndmptr, ndmpftr, nmldmptr, sdmptr, bdmptr, hdmptr
+#endif
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_trp_lec: read namelist for tracer transport'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
+
+      !                                ! tracer advection scheme
+      REWIND( numnat )                 !   ! Read Namelist namtrcadv
+      READ  ( numnat, namtrcadv )
+
+      IF(lwp) THEN                     !   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namtrcadv : chose a advection scheme for tracers'
+         WRITE(numout,*) '      2nd order advection scheme     ln_trcadv_cen2   = ', ln_trcadv_cen2
+         WRITE(numout,*) '      TVD advection scheme           ln_trcadv_tvd    = ', ln_trcadv_tvd
+         WRITE(numout,*) '      MUSCL  advection scheme        ln_trcadv_muscl  = ', ln_trcadv_muscl
+         WRITE(numout,*) '      MUSCL2 advection scheme        ln_trcadv_muscl2 = ', ln_trcadv_muscl2
+         WRITE(numout,*) '      SMOLARKIEWICZ advection scheme ln_trcadv_smolar = ', ln_trcadv_smolar
+      ENDIF
+
+#if  defined key_trcbbl_dif
+      !                                ! Bottom boundary layer 
+      REWIND( numnat )                 !   ! Read Namelist namtrcbbl
+      READ  ( numnat, namtrcbbl )
+
+      IF(lwp) THEN                     !   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namtrcbbl : set Diffusive Bottom Boundary Layer parameters'
+         WRITE(numout,*) '      bottom boundary layer coef.    atrcbbl = ', atrcbbl
+# if defined key_trcbbl_adv
+         WRITE(numout,*) '   * Advective Bottom Boundary Layer'
+# endif
+      ENDIF
+#endif
+
+      !                                ! Lateral physics on tracers   
+      REWIND( numnat )                 !   ! Read Namelist namtrcldf
+      READ  ( numnat, namtrcldf )
+
+      IF(lwp) THEN                     !   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namtrcldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '      perform lateral diffusion or not               ln_trcldf_diff  = ', ln_trcldf_diff
+         WRITE(numout,*) '      laplacian operator                             ln_trcldf_lap   = ', ln_trcldf_lap
+         WRITE(numout,*) '      bilaplacian operator                           ln_trcldf_bilap = ', ln_trcldf_bilap
+         WRITE(numout,*) '      iso-level                                      ln_trcldf_level = ', ln_trcldf_level
+         WRITE(numout,*) '      horizontal (geopotential)                      ln_trcldf_hor   = ', ln_trcldf_hor
+         WRITE(numout,*) '      iso-neutral                                    ln_trcldf_iso   = ', ln_trcldf_iso
+         WRITE(numout,*) '      lateral eddy diffusivity                              ahtrc0   = ', ahtrc0
+         WRITE(numout,*) '      background hor. diffusivity                            ahtrb0  = ', ahtrb0
+         WRITE(numout,*) '      eddy induced velocity coef.                           aeivtr0  = ', aeivtr0
+         WRITE(numout,*) '      ratio between passive and active tracer diffusion coef  trcrat = ', trcrat
+      ENDIF
+
+      !                                ! Vertical mixing
+      REWIND( numnat )                 !   ! Read namtrczdf namelist
+      READ  ( numnat, namtrczdf )
+
+      IF(lwp) THEN                     !   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namtrczdf : set vertical diffusion parameters'
+         WRITE(numout,*) '      time splitting / backward scheme ln_trczdf_exp = ', ln_trczdf_exp
+         WRITE(numout,*) '      number of time step               n_trczdf_exp = ', n_trczdf_exp
+      ENDIF
+
+# if defined key_trcdmp
+      !                                ! passive tracres damping term
+      REWIND( numnat )                 !   ! Read Namelist namtdp
+      READ  ( numnat, namtrcdmp )
+      IF( lzoom )   nmldmptr = 0           ! restoring to climatology at closed north or south boundaries
+
+      IF(lwp) THEN                     !   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namtrcdmp : set damping parameter'
+         WRITE(numout,*) '      tracers damping option         ndmptr   = ', ndmptr
+         WRITE(numout,*) '      create a damping.coeff file    ndmpftr  = ', ndmpftr
+         WRITE(numout,*) '      mixed layer damping option     nmldmptr = ', nmldmptr, '(zoom: forced to 0)'
+         WRITE(numout,*) '      surface time scale (days)      sdmptr   = ', sdmptr
+         WRITE(numout,*) '      bottom time scale (days)       bdmptr   = ', bdmptr
+         WRITE(numout,*) '      depth of transition (meters)   hdmptr   = ', hdmptr
+      ENDIF
+#endif
+      !
+   END SUBROUTINE trc_trp_lec
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                         No TOP model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_trp_lec              ! Empty routine
+   END SUBROUTINE trc_trp_lec
+#endif
+
+  !!======================================================================
+END MODULE trctrp_lec
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_exp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_exp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_exp.F90	(revision 4536)
@@ -0,0 +1,187 @@
+MODULE trczdf_exp
+   !!==============================================================================
+   !!                    ***  MODULE  trczdf_exp  ***
+   !! Ocean passive tracers:  vertical component of the tracer mixing trend using
+   !!                        an explicit time-stepping (time spllitting scheme)
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_zdf_exp  : update the tracer trend with the vertical diffusion
+   !!                  using an explicit time stepping
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc          ! ocean dynamics and active tracers variables
+   USE trc              ! ocean passive tracers variables
+   USE trctrp_lec       ! passive tracers transport
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_zdf_exp          ! routine called by step.F90
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpk) ::   &
+      rdttrc                     ! vertical profile of 2 x tracer time-step
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_zdf_exp( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_exp  ***
+      !!                   
+      !! ** Purpose :   Compute the trend due to the vertical tracer mixing 
+      !!      using an explicit time stepping and add it to the general trend 
+      !!      of the tracer equations.
+      !!
+      !! ** Method  :   The vertical diffusion of tracers  is given by:
+      !!         difft = dz( avt dz(trb) ) = 1/e3t dk+1( avt/e3w dk(trb) )
+      !!      It is evaluated with an Euler scheme, using a time splitting
+      !!      technique.
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend tra :
+      !!          tra = tra + dz( avt dz(t) ) if lk_zdfddm= T)
+      !!
+      !! ** Action : - Update tra with the before vertical diffusion trend
+      !!             - Save the trends  in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   6.0  !  90-10  (B. Blanke)  Original code
+      !!   7.0  !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  correction on tracer trend loops
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-05  (G. Madec)  vertical component of isopycnal
+      !!        !  97-07  (G. Madec)  geopotential diffusion in s-coord
+      !!        !  98-03  (L. Bopp MA Foujols) passive tracer generalisation
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-06  (O Aumont)  correct isopycnal scheme suppress
+      !!        !                     avt multiple correction
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+      
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jl, jn             ! dummy loop indices
+      REAL(wp) ::   &
+         zlavmr,                 &  ! ???
+         zave3r, ze3tr,          &  ! ???
+         ztra                  !
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         zwx, zwy
+      CHARACTER (len=22) :: charout
+      !!---------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_zdf_exp : vertical tracer mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+         ! time step = 2 rdttra with Arakawa or TVD advection scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)             ! restarting with Euler time stepping
+         ELSEIF( kt <= nittrc000 + ndttrc ) THEN
+            rdttrc(:) = 2. * rdttra(:) * FLOAT(ndttrc)         ! leapfrog
+         ENDIF
+      ELSE
+         rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)      
+      ENDIF
+
+
+      zlavmr = 1. / FLOAT( n_trczdf_exp )
+
+      DO jn = 1, jptra
+
+         !                                                ! ===============
+         DO jj = 2, jpjm1                                 !  Vertical slab
+            !                                             ! ===============
+            ! 1. Initializations
+            ! ------------------
+
+            ! Surface & bottom boundary conditions: no flux
+            DO ji = 2, jpim1
+               zwy(ji, 1 ) = 0.e0
+               zwy(ji,jpk) = 0.e0
+            END DO
+
+            ! zwx and zwz arrays set to before tracer values
+            DO jk = 1, jpk
+               DO ji = 2, jpim1
+                  zwx(ji,jk) = trb(ji,jj,jk,jn)
+               END DO
+            END DO
+
+
+            ! 2. Time splitting loop
+            ! ----------------------
+
+            DO jl = 1, n_trczdf_exp
+
+               ! first vertical derivative
+               ! double diffusion: fstravs(ji,jj,jk) = avt(ji,jj,jk) /= avs (key_trc_zdfddm) 
+               !                   fstravs(ji,jj,jk) = avs(ji,jj,jk) = avt
+               DO jk = 2, jpk
+                  DO ji = 2, jpim1
+                     zave3r = 1.e0 / fse3w(ji,jj,jk) 
+                     zwy(ji,jk) = fstravs(ji,jj,jk) * ( zwx(ji,jk-1) - zwx(ji,jk) ) * zave3r
+                  END DO
+               END DO
+
+
+               ! trend estimation at kt+l*2*rdt/n_zdfexp
+               DO jk = 1, jpkm1
+                  DO ji = 2, jpim1
+                     ze3tr = zlavmr / fse3t(ji,jj,jk)
+                     ! 2nd vertical derivative
+                     ztra = ( zwy(ji,jk) - zwy(ji,jk+1) ) * ze3tr
+                     ! update the tracer trends
+                     tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
+                     ! update tracer fields at kt+l*2*rdt/n_trczdf_exp
+                     zwx(ji,jk) = zwx(ji,jk) + rdttrc(jk) * ztra * tmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - exp')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_zdf_exp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      NO passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_zdf_exp (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_zdf_exp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_zdf_exp
+#endif
+   
+   !!==============================================================================
+END MODULE trczdf_exp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_imp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_imp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_imp.F90	(revision 4536)
@@ -0,0 +1,277 @@
+MODULE trczdf_imp
+   !!==============================================================================
+   !!                    ***  MODULE  trczdf_imp  ***
+   !! Ocean passive tracers:  vertical component of the tracer mixing trend
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_zdf_imp  : update the tracer trend with the vertical diffusion
+   !!                  using an implicit time-stepping.
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc             ! ocean dynamics and active tracers variables
+   USE trc                 ! ocean passive tracers variables
+   USE trctrp_lec          ! passive tracers transport
+   USE prtctl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_zdf_imp          ! routine called by step.F90
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpk) ::   &
+      rdttrc                     ! vertical profile of 2 x tracer time-step
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_zdf_imp( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_imp  ***
+      !!
+      !! ** Purpose :   Compute the trend due to the vertical tracer mixing 
+      !!      using an implicit time stepping and add it to the general trend
+      !!      of the tracer equations.
+      !!
+      !! ** Method  :   The vertical diffusion of tracers tra is given by:
+      !!          difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(tra) )
+      !!      It is thus evaluated using a backward time scheme
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend tra :
+      !!          tra = tra + dz( avt dz(t) )
+      !!         (tra = tra + dz( avs dz(t) ) if lk_zdfddmtrc=T)
+      !!
+      !! ** Action  : - Update tra with the before vertical diffusion trend
+      !!              - save the trends in trtrd ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   6.0  !  90-10  (B. Blanke)  Original code
+      !!   7.0  !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard)  correction on tracer trend loops
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-05  (G. Madec)  vertical component of isopycnal
+      !!        !  97-07  (G. Madec)  geopotential diffusion in s-coord
+      !!        !  98-03  (L. Bopp MA Foujols) passive tracer generalisation
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-06  (O Aumont)  correct isopycnal scheme suppress
+      !!        !                     avt multiple correction
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+      INTEGER ::   ikst, ikenm2, ikstp1
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jn             ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwd, zws, zwi,          &  ! ???
+         zwx, zwy, zwt              ! ???
+      REAL(wp) ::  ztra      ! temporary scalars
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) ::   &
+         ztrd
+      CHARACTER (len=22) :: charout
+      !!---------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_zdf_implicit : vertical tracer mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! 0. Local constant initialization
+      ! --------------------------------
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+         ! time step = 2 rdttra with Arakawa or TVD advection scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)             ! restarting with Euler time stepping
+         ELSEIF( kt <= nittrc000 + ndttrc ) THEN
+            rdttrc(:) = 2. * rdttra(:) * FLOAT(ndttrc)         ! leapfrog
+         ENDIF
+      ELSE
+         rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)      
+      ENDIF
+
+      DO jn = 1 , jptra
+
+	 ! Initialisation     
+	 zwd( 1 ,:,:) = 0.e0     ;     zwd(jpi,:,:) = 0.e0
+	 zws( 1 ,:,:) = 0.e0     ;     zws(jpi,:,:) = 0.e0
+	 zwi( 1 ,:,:) = 0.e0     ;     zwi(jpi,:,:) = 0.e0
+	 zwt( 1 ,:,:) = 0.e0     ;     zwt(jpi,:,:) = 0.e0     
+         zwt(  :,:,1) = 0.e0     ;     zwt(  :,:,jpk) = 0.e0
+         !                                          
+         ! 0. Matrix construction
+         ! ----------------------
+
+         ! Diagonal, inferior, superior
+         ! (including the bottom boundary condition via avs masked
+         DO jk = 1, jpkm1                                                     
+            DO jj = 2, jpjm1                                      
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwi(ji,jj,jk) = - rdttrc(jk) * fstravs(ji,jj,jk  ) /( fse3t(ji,jj,jk) * fse3w(ji,jj,jk  ) )
+                  zws(ji,jj,jk) = - rdttrc(jk) * fstravs(ji,jj,jk+1) /( fse3t(ji,jj,jk) * fse3w(ji,jj,jk+1) )
+                  zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zws(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Surface boudary conditions
+         DO jj = 2, jpjm1        
+            DO ji = fs_2, fs_jpim1
+               zwi(ji,jj,1) = 0.e0
+               zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+            END DO
+         END DO
+         
+         ! Second member construction
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1     
+               DO ji = fs_2, fs_jpim1
+                  zwy(ji,jj,jk) = trb(ji,jj,jk,jn) + rdttrc(jk) * tra(ji,jj,jk,jn)
+               END DO
+            END DO
+         END DO
+         
+         
+         ! Matrix inversion from the first level
+         !----------------------------------------------------------------------
+         !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+         !
+         !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+         !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+         !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+         !        (        ...               )( ...  ) ( ...  )
+         !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+         !
+         !   m is decomposed in the product of an upper and lower triangular matrix
+         !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+         !   The second member is in 2d array zwy
+         !   The solution is in 2d array zwx
+         !   The 3d arry zwt is a work space array
+         !   zwy is used and then used as a work space array : its value is modified!
+         !
+         !   N.B. the starting vertical index (ikst) is equal to 1 except for
+         !   the resolution of tke matrix where surface tke value is prescribed
+         !   so that ikstrt=2.
+        ikst = 1
+        ikstp1 = ikst + 1
+        ikenm2 = jpk - 2
+        
+        DO jj = 2, jpjm1
+           DO ji = fs_2, fs_jpim1
+              zwt(ji,jj,ikst) = zwd(ji,jj,ikst)
+           END DO
+        END DO
+        
+        DO jk = ikstp1, jpkm1
+           DO jj = 2, jpjm1
+              DO ji = fs_2, fs_jpim1
+                 zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwt(ji,jj,jk-1)
+              END DO
+           END DO
+        END DO
+        
+        DO jk = ikstp1, jpkm1
+           DO jj = 2, jpjm1
+              DO ji = fs_2, fs_jpim1
+                 zwy(ji,jj,jk) = zwy(ji,jj,jk) - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * zwy(ji,jj,jk-1)
+              END DO
+           END DO
+        END DO
+        
+        DO jj = 2, jpjm1
+           DO ji = fs_2, fs_jpim1
+              zwx(ji,jj,jpkm1) = zwy(ji,jj,jpkm1) / zwt(ji,jj,jpkm1)
+           END DO
+        END DO
+        
+        DO jk = ikenm2, ikst, -1
+           DO jj = 2, jpjm1
+              DO ji = fs_2, fs_jpim1
+                 zwx(ji,jj,jk) = ( zwy(ji,jj,jk) - zws(ji,jj,jk) * zwx(ji,jj,jk+1) ) / zwt(ji,jj,jk)
+              END DO
+           END DO
+        END DO
+
+         
+#if defined key_trc_diatrd
+         ! Compute and save the vertical diffusive of tracers trends
+#  if defined key_trcldf_iso
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztra = ( zwx(ji,jj,jk) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - tra(ji,jj,jk,jn) + trtrd(ji,jj,jk,ikeep(jn),6)
+               END DO
+            END DO
+         END DO
+#  else
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztra = ( zwx(ji,jj,jk) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - tra(ji,jj,jk,jn)
+               END DO
+            END DO
+         END DO
+#  endif
+#endif  
+         ! Save the masked passive tracer after in tra
+         ! (c a u t i o n:  tracer not its trend, Leap-frog scheme done
+         !                  it will not be done in tranxt)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  tra(ji,jj,jk,jn) = zwx(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+            ztrd(:,:,:,:) = 0.
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     ztrd(ji,jj,jk,jn) = ( zwx(ji,jj,jk) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - imp')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=ztrd, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_zdf_imp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                      NO passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_zdf_imp (kt )              ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_zdf_imp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_zdf_imp
+#endif
+   
+!!==============================================================================
+END MODULE trczdf_imp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso.F90	(revision 4536)
@@ -0,0 +1,462 @@
+MODULE trczdf_iso
+   !!==============================================================================
+   !!                    ***  MODULE  trczdf_iso  ***
+   !! Ocean passive tracers:  vertical component of the tracer mixing trend
+   !!==============================================================================
+#if defined key_top  &&  ( defined key_ldfslp   ||   defined key_esopa )
+   !!----------------------------------------------------------------------
+   !!   'key_top'       and                                      TOP models
+   !!   'key_ldfslp'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   trc_zdf_iso  : update the tracer trend with the vertical part of 
+   !!                  the isopycnal or geopotential s-coord. operator and
+   !!                  the vertical diffusion
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc          ! ocean dynamics and tracers variables
+   USE trc              ! ocean passive tracers variables 
+   USE lbclnk           ! ocean lateral boundary conditions (or mpp link)
+   USE trctrp_lec       ! passive tracers transport
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Accessibility
+   PUBLIC trc_zdf_iso    ! routine called by step.F90
+
+   !! * Module variable
+   REAL(wp), DIMENSION(jpk) ::   &
+      rdttrc                     ! vertical profile of 2 x tracer time-step
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trczdf_iso.F90,v 1.13 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_zdf_iso( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_iso  ***
+      !!
+      !! ** Purpose :
+      !!     Compute the trend due to the vertical tracer diffusion inclu-
+      !!     ding the vertical component of lateral mixing (only for second
+      !!     order operator, for fourth order it is already computed and
+      !!     add to the general trend in trcldf.F) and add it to the general
+      !!     trend of the tracer equations.
+      !!
+      !! ** Method :
+      !!         The vertical component of the lateral diffusive trends is
+      !!      provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      First part: vertical trends associated with the lateral mixing
+      !!      ==========  (excluding the vertical flux proportional to dk[t] )
+      !!      vertical fluxes associated with the rotated lateral mixing:
+      !!         zftw =-aht {  e2t*wslpi di[ mi(mk(trb)) ]
+      !!                     + e1t*wslpj dj[ mj(mk(trb)) ]  }
+      !!      save avt coef. resulting from vertical physics alone in zavt:
+      !!         zavt = avt
+      !!      update and save in zavt the vertical eddy viscosity coefficient:
+      !!         avt = avt + wslpi^2+wslj^2
+      !!      add vertical Eddy Induced advective fluxes ('lk_trcldf_eiv=T):
+      !!         zftw = zftw + { di[aht e2u mi(wslpi)]
+      !!                    +dj[aht e1v mj(wslpj)] } mk(trb)
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) dk[ zftw ] 
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + difft
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers tra  is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme, t=ta.
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend tra  :
+      !!         tra = tra + dz( avt dz(t) )
+      !!         (tra = tra + dz( avs dz(t) ) if lk_trc_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in diamld).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_trc_zdfddm=T )
+      !!
+      !!      'key_trc_diatrd' defined: trend saved for futher diagnostics.
+      !!
+      !!      macro-tasked on vertical slab (jj-loop)
+      !!
+      !! ** Action :
+      !!         Update tra arrays with the before vertical diffusion trend
+      !!         Save in trtrd arrays the trends if 'key_trc_diatrd' defined
+      !!
+      !! History :
+      !!   7.0  !  91-11  (G. Madec)  Original code
+      !!        !  92-06  (M. Imbard)  correction on tracer trend loops
+      !!        !  96-01  (G. Madec)  statement function for e3
+      !!        !  97-05  (G. Madec)  vertical component of isopycnal
+      !!        !  97-07  (G. Madec)  geopotential diffusion in s-coord
+      !!        !  98-03  (L. Bopp MA Foujols) passive tracer generalisation
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-06  (O Aumont)  correct isopycnal scheme suppress
+      !!        !                     avt multiple correction
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc               ,   &
+         zavs => va
+
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk, jn                 ! dummy loop indices
+      INTEGER ::   ikst, ikenm2, ikstp1       ! temporary integers
+      INTEGER ::   iku, ikv, ikv1             ! temporary integers
+
+      REAL(wp) ::   ztra
+      REAL(wp) ::   &
+         ztavg,                 &  ! ???
+         zcoef0, zcoef3,        &  ! ???
+         zcoef4, zavi,          &  ! ???
+         zbtr, zmku, zmkv,      &  !
+         ztav
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         zwd, zws, zwi,         &  ! ???
+         zwx, zwy, zwz, zwt        ! ???
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         ztfw, zdit, zdjt, zdj1t
+#if defined key_trcldf_eiv   ||   defined key_esopa
+      REAL(wp), DIMENSION(jpi,jpk) ::   &
+         ztfwg
+
+      REAL(wp) ::         &
+         zcoeg3,          &
+         zuwk, zvwk,      &
+         zuwki, zvwki
+#endif
+      CHARACTER (len=22) :: charout
+      !!---------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_zdf_iso : vertical mixing (including isopycnal component)'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+#if defined key_trcldf_eiv && defined key_diaeiv
+         w_trc_eiv(:,:,:) = 0.e0
+#endif
+      ENDIF
+
+      ! 0.0  Local constant initialization
+      ! --------------------------------
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+         ! time step = 2 rdttra with Arakawa or TVD advection scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)             ! restarting with Euler time stepping
+         ELSEIF( kt <= nittrc000 + ndttrc ) THEN
+            rdttrc(:) = 2. * rdttra(:) * FLOAT(ndttrc)         ! leapfrog
+         ENDIF
+      ELSE
+         rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)      
+      ENDIF
+
+
+
+      ! 0.1 Save avs in zavs to recover avs in output files
+      !---------------------------------------------------
+      zavs(:,:,:) = fstravs(:,:,:)
+
+
+
+      DO jn = 1, jptra
+
+         ztavg = 0.e0
+
+         !                                                ! ===============
+         DO jj = 2, jpjm1                                 !  Vertical slab
+            !                                             ! ===============
+
+            ! I. vertical trends associated with the lateral mixing
+            ! =====================================================
+            !  (excluding the vertical flux proportional to dk[t]
+
+
+            ! I.1 horizontal tracer gradient
+            ! ------------------------------
+
+            DO jk = 1, jpkm1
+               DO ji = 1, jpim1
+                  ! i-gradient of passive tracer at jj
+                  zdit (ji,jk) = ( trb(ji+1,jj,jk,jn)-trb(ji,jj,jk,jn) ) * umask(ji,jj,jk)
+                  ! j-gradient of passive tracer at jj
+                  zdjt (ji,jk) = ( trb(ji,jj+1,jk,jn)-trb(ji,jj,jk,jn) ) * vmask(ji,jj,jk)
+                  ! j-gradient of passive tracer at jj+1
+                  zdj1t(ji,jk) = ( trb(ji,jj,jk,jn)-trb(ji,jj-1,jk,jn) ) * vmask(ji,jj-1,jk)
+               END DO
+            END DO
+
+            IF( ln_zps ) THEN
+               ! partial steps correction at the bottom ocean level 
+               DO ji = 1, jpim1
+                  ! last ocean level
+                  iku  = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv  = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  ikv1 = MIN( mbathy(ji,jj), mbathy(ji  ,jj-1) ) - 1
+                  ! i-gradient of of passive tracer at jj
+                  zdit (ji,iku) = gtru(ji,jj,jn)
+                  ! j-gradient of of passive tracer at jj
+                  zdjt (ji,ikv) = gtrv(ji,jj,jn) 
+                  ! j-gradient of of passive tracer at jj+1
+                  zdj1t(ji,ikv1)= gtrv(ji,jj-1,jn)
+               END DO
+            ENDIF
+
+            ! I.2 Vertical fluxes
+            ! -------------------
+
+            ! Surface and bottom vertical fluxes set to zero
+            ztfw(:, 1 ) = 0.e0
+            ztfw(:,jpk) = 0.e0
+
+#if defined key_trcldf_eiv
+            ztfwg(:, 1 ) = 0.e0
+            ztfwg(:,jpk) = 0.e0
+#endif
+
+            ! interior (2=<jk=<jpk-1)
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zcoef0 = - fsahtw(ji,jj,jk) * tmask(ji,jj,jk)
+
+                  zmku = 1./MAX( umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)   &
+                     &          +umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk), 1. )
+
+                  zmkv = 1./MAX( vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)   &
+                     &          +vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk), 1. )
+
+                  zcoef3 = zcoef0 * e2t(ji,jj) * zmku * wslpi (ji,jj,jk)
+                  zcoef4 = zcoef0 * e1t(ji,jj) * zmkv * wslpj (ji,jj,jk)
+
+                  ztfw(ji,jk) = zcoef3 * ( zdit (ji  ,jk-1) + zdit (ji-1,jk)     &
+                     &                    +zdit (ji-1,jk-1) + zdit (ji  ,jk) )   &
+                     &        + zcoef4 * ( zdjt (ji  ,jk-1) + zdj1t(ji  ,jk)     &
+                     &                    +zdj1t(ji  ,jk-1) + zdjt (ji  ,jk) )
+
+               END DO
+            END DO
+
+
+            ! I.3  update and save of avt (and avs if double diffusive mixing)
+            ! ---------------------------
+
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+
+                  zavi = fsahtw(ji,jj,jk)*( wslpi(ji,jj,jk)*wslpi(ji,jj,jk)   &
+                     &                     +wslpj(ji,jj,jk)*wslpj(ji,jj,jk) )
+
+                  ! add isopycnal vertical coeff. to avs
+                  fstravs(ji,jj,jk) = fstravs(ji,jj,jk) + zavi
+
+               END DO
+            END DO
+
+#if defined key_trcldf_eiv
+            !                              ! ---------------------------------------!
+            !                              ! Eddy induced vertical advective fluxes !
+            !                              ! ---------------------------------------!
+#if defined key_traldf_c2d || defined key_traldf_c3d || defined key_off_degrad
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zuwki = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) )   &
+                     &  * fsaeitru(ji-1,jj,jk) * e2u(ji-1,jj)*umask(ji-1,jj,jk)
+                  zuwk  = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) )   &
+                     &  * fsaeitru(ji  ,jj,jk) * e2u(ji  ,jj)*umask(ji  ,jj,jk)
+                  zvwki = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) )   &
+                     &  * fsaeitrv(ji,jj-1,jk) * e1v(ji,jj-1)*vmask(ji,jj-1,jk)
+                  zvwk  = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) )   &
+                     &  * fsaeitrv(ji,jj  ,jk) * e1v(ji  ,jj)*vmask(ji  ,jj,jk)
+
+                  zcoeg3 = + 0.25 * tmask(ji,jj,jk) * ( zuwk - zuwki + zvwk - zvwki )
+
+                  ztfwg(ji,jk) = + zcoeg3 * ( trb(ji,jj,jk,jn) + trb(ji,jj,jk-1,jn) ) 
+                  ztfw(ji,jk) = ztfw(ji,jk) + ztfwg(ji,jk)
+
+# if defined key_diaeiv
+                  w_trc_eiv(ji,jj,jk) = -2. *  zcoeg3 / ( e1t(ji,jj)*e2t(ji,jj) )
+# endif
+               END DO
+            END DO
+
+#else
+            DO jk = 2, jpkm1
+               DO ji = 2, jpim1
+                  zuwki = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) )   &
+                     &  * e2u(ji-1,jj)*umask(ji-1,jj,jk)
+                  zuwk  = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) )   &
+                     &  * e2u(ji  ,jj)*umask(ji  ,jj,jk)
+                  zvwki = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) )   &
+                     &  * e1v(ji,jj-1)*vmask(ji,jj-1,jk)
+                  zvwk  = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) )   &
+                     &  * e1v(ji  ,jj)*vmask(ji  ,jj,jk)
+
+                  zcoeg3 = + 0.25 * tmask(ji,jj,jk) * fsaeitrw(ji,jj,jk)   &
+                     &            * ( zuwk - zuwki + zvwk - zvwki )
+
+                  ztfwg(ji,jk) = + zcoeg3 * ( trb(ji,jj,jk,jn) + trb(ji,jj,jk-1,jn) )
+                  ztfw(ji,jk) = ztfw(ji,jk) + ztfwg(ji,jk)
+
+# if defined key_diaeiv
+                  w_trc_eiv(ji,jj,jk) = -2. *  zcoeg3 / ( e1t(ji,jj)*e2t(ji,jj) )
+# endif
+               END DO
+            END DO
+#endif
+
+#endif
+
+
+            ! I.5 Divergence of vertical fluxes added to the general tracer trend
+            ! -------------------------------------------------------------------
+
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  zbtr =  1. / ( e1t(ji,jj)*e2t(ji,jj)*fse3t(ji,jj,jk) )
+                  ztav = (  ztfw(ji,jk) - ztfw(ji,jk+1)  ) * zbtr
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztav
+
+#if defined key_trc_diatrd
+#   if defined key_trcldf_eiv
+                  ztavg = ( ztfwg(ji,jk) - ztfwg(ji,jk+1) ) * zbtr
+                  !  WARNING trtrd(ji,jj,jk,6) used for vertical gent velocity trend
+                  !                           not for damping !!!
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),9) = ztavg
+#   endif
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztav - ztavg
+#endif
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      END DO
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - 1')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+      DO jn = 1, jptra
+         !                                                ! ===============
+         DO jj = 2, jpjm1                                 !  Vertical slab
+            !                                             ! ===============
+
+            ! II. Vertical trend associated with the vertical physics
+            ! =======================================================
+            !     (including the vertical flux proportional to dk[t] associated
+            !      with the lateral mixing, through the avt update)
+            !     dk[ avt dk[ (t,s) ] ] diffusive trends
+
+
+            ! Diagonal, inferior, superior
+            ! (including the bottom boundary condition via avs masked)
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  zwi(ji,jk) = - rdttrc(jk) * fstravs(ji,jj,jk  )   &
+                     /( fse3t(ji,jj,jk) * fse3w(ji,jj,jk  ) )
+                  zws(ji,jk) = - rdttrc(jk) * fstravs(ji,jj,jk+1)   &
+                     /( fse3t(ji,jj,jk) * fse3w(ji,jj,jk+1) )
+                  zwd(ji,jk) = 1. - zwi(ji,jk) - zws(ji,jk)
+               END DO
+            END DO
+
+            ! Surface boudary conditions
+            DO ji = 2, jpim1
+               zwi(ji,1) = 0.e0
+               zwd(ji,1) = 1. - zws(ji,1)
+            END DO
+
+            ! Second member construction
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  zwy(ji,jk) = trb(ji,jj,jk,jn) + rdttrc(jk) * tra(ji,jj,jk,jn)
+               END DO
+            END DO
+
+            ! Matrix inversion from the first level
+            ikst = 1
+#   include "zdf.matrixsolver.h90"
+#if defined key_trc_diatrd
+            ! Compute and save the vertical diffusive of tracers trends
+#  if defined key_trcldf_iso
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ztra = ( zwx(ji,jk) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - tra(ji,jj,jk,jn) + trtrd(ji,jj,jk,ikeep(jn),6)
+               END DO
+            END DO
+#  else
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  ztra = ( zwx(ji,jk) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - tra(ji,jj,jk,jn)
+               END DO
+            END DO
+#  endif
+#endif
+            ! Save the masked passive tracer after in tra
+            ! (c a u t i o n:  tracer not its trend, Leap-frog scheme done
+            !                  it will not be done in tranxt)
+            DO jk = 1, jpkm1
+               DO ji = 2, jpim1
+                  tra(ji,jj,jk,jn) = zwx(ji,jk)  * tmask(ji,jj,jk)
+               END DO
+            END DO
+            !                                             ! ===============
+         END DO                                           !   End of slab
+         !                                                ! ===============
+
+      END DO
+
+
+
+      ! III. recover the avt (avs) resulting from vertical physics only
+      !---------------------------------------------------------------
+      fstravs(:,:,:) = zavs(:,:,:)
+
+      
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - 2')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_zdf_iso
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module               NO rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_zdf_iso( kt )              ! empty routine
+      WRITE(*,*) 'trc_zdf_iso: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_zdf_iso
+#endif
+
+   !!==============================================================================
+END MODULE trczdf_iso
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso_vopt.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso_vopt.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/trczdf_iso_vopt.F90	(revision 4536)
@@ -0,0 +1,574 @@
+MODULE trczdf_iso_vopt
+   !!==============================================================================
+   !!                 ***  MODULE  trczdf_iso_vopt  ***
+   !! Ocean passive tracers:  vertical component of the tracer mixing trend
+   !!==============================================================================
+#if defined key_top  &&  ( defined key_ldfslp   ||   defined key_esopa )
+   !!----------------------------------------------------------------------
+   !!   'key_top'      and                                       TOP models
+   !!   'key_ldfslp'                  rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+   !!   trc_zdf_iso_vopt : Update the tracer trend with the vertical part of 
+   !!                  the isopycnal or geopotential s-coord. operator and
+   !!                  the vertical diffusion. vector optimization, use
+   !!                  k-j-i loops.
+   !!   trc_zdf_iso  :
+   !!   trc_zdf_zdf  :
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables 
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE trctrp_lec      ! passive tracers transport
+   USE prtctl_trc          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC trc_zdf_iso_vopt   !  routine called by step.F90
+
+   !! * Module variables
+   REAL(wp), DIMENSION(jpk) ::  &
+      rdttrc                          ! vertical profile of 2 x time-step
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trczdf_iso_vopt.F90,v 1.12 2007/10/12 09:26:30 opalod Exp $ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+   
+   SUBROUTINE trc_zdf_iso_vopt( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_iso_vopt  ***
+      !!
+      !! ** Purpose :
+      !! ** Method  :
+      !! ** Action  :
+      !!
+      !! History :
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe)   adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      CHARACTER (len=22) :: charout
+      !!---------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'trc_zdf_iso_vopt : vertical mixing computation'
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~~~~~~   is  iso-neutral diffusion : implicit vertical time stepping'
+#if defined key_trcldf_eiv && defined key_diaeiv 
+         w_trc_eiv(:,:,:) = 0.e0
+#endif
+      ENDIF
+
+
+      ! I. vertical extra-diagonal part of the rotated tensor
+      ! -----------------------------------------------------
+
+      CALL trc_zdf_iso
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - 1')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+      ! II. vertical diffusion (including the vertical diagonal part of the rotated tensor)
+      ! ----------------------
+
+      CALL trc_zdf_zdf( kt )
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('zdf - 2')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm,clinfo2='trd')
+      ENDIF
+
+   END SUBROUTINE trc_zdf_iso_vopt
+
+
+   SUBROUTINE trc_zdf_zdf( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE trc_zdf_zdf  ***
+      !!                    
+      !! ** Purpose :   Compute the trend due to the vertical tracer diffusion
+      !!     including the vertical component of lateral mixing (only for 2nd
+      !!     order operator, for fourth order it is already computed and add
+      !!     to the general trend in traldf.F) and add it to the general trend
+      !!     of the tracer equations.
+      !!
+      !! ** Method  :   The vertical component of the lateral diffusive trends
+      !!      is provided by a 2nd order operator rotated along neural or geo-
+      !!      potential surfaces to which an eddy induced advection can be 
+      !!      added. It is computed using before fields (forward in time) and 
+      !!      isopycnal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      Second part: vertical trend associated with the vertical physics
+      !!      ===========  (including the vertical flux proportional to dk[t]
+      !!                  associated with the lateral mixing, through the
+      !!                  update of avt)
+      !!      The vertical diffusion of tracers  is given by:
+      !!             difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=tra).
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + dz( avt dz(t) )
+      !!         (tra = tra + dz( avs dz(t) ) if lk_trc_zdfddm=T )
+      !!
+      !!      Third part: recover avt resulting from the vertical physics
+      !!      ==========  alone, for further diagnostics (for example to
+      !!                  compute the turbocline depth in diamld).
+      !!         avt = zavt
+      !!         (avs = zavs if lk_trc_zdfddm=T )
+      !!
+      !!      'key_trdtra' defined: trend saved for futher diagnostics.
+      !!
+      !!      macro-tasked on vertical slab (jj-loop)
+      !!
+      !! ** Action  : - Update tra with before vertical diffusion trend
+      !!              - Save the trend in trtrd  ('key_trc_diatrd')
+      !!
+      !! History :
+      !!   6.0  !  90-10  (B. Blanke)  Original code
+      !!   7.0  !  91-11 (G. Madec)
+      !!        !  92-06 (M. Imbard) correction on tracer trend loops
+      !!        !  96-01 (G. Madec) statement function for e3
+      !!        !  97-05 (G. Madec) vertical component of isopycnal
+      !!        !  97-07 (G. Madec) geopotential diffusion in s-coord
+      !!        !  98-03  (L. Bopp MA Foujols) passive tracer generalisation
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-06  (O Aumont)  correct isopycnal scheme suppress
+      !!        !                     avt multiple correction
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc, ONLY :   zwd   => ua,  &  ! ua, va used as
+                            zws   => va      ! workspace
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn                ! dummy loop indices
+      REAL(wp) ::   &
+         zavi, zrhs                          ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwi, zwt, zavsi                     ! temporary workspace arrays
+      REAL(wp) ::    ztra              !temporary scalars
+#  if defined key_trc_diatrd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrd
+#  endif
+      !!---------------------------------------------------------------------
+
+
+      ! I. Local constant initialization
+      ! --------------------------------
+      ! ... time step = 2 rdttra ex
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+         ! time step = 2 rdttra with Arakawa or TVD advection scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)             ! restarting with Euler time stepping
+         ELSEIF( kt <= nittrc000 + ndttrc ) THEN
+            rdttrc(:) = 2. * rdttra(:) * FLOAT(ndttrc)         ! leapfrog
+         ENDIF
+      ELSE
+         rdttrc(:) =  rdttra(:) * FLOAT(ndttrc)      
+      ENDIF
+
+      DO jn = 1, jptra
+         
+         zwd( 1 ,:,:)=0.e0     ;     zwd(jpi,:,:)=0.e0
+         zws( 1 ,:,:)=0.e0     ;     zws(jpi,:,:)=0.e0
+         zwi( 1 ,:,:)=0.e0     ;     zwi(jpi,:,:)=0.e0
+
+         zwt( 1 ,:,:)=0.e0     ;     zwt(jpi,:,:)=0.e0
+         zwt(  :,:,1)=0.e0     ;     zwt(:,:,jpk)= 0.e0
+         zavsi( 1 ,:,:)=0.e0   ;     zavsi(jpi,:,:)=0.e0 
+         zavsi(  :,:,1)=0.e0   ;     zavsi(:,:,jpk)=0.e0
+
+#  if defined key_trc_diatrd
+         ! save the tra trend
+         ztrd(:,:,:) = tra(:,:,:,jn)
+#  endif
+
+         ! II. Vertical trend associated with the vertical physics
+         ! =======================================================
+         !     (including the vertical flux proportional to dk[t] associated
+         !      with the lateral mixing, through the avt update)
+         !     dk[ avt dk[ (t,s) ] ] diffusive trends
+
+
+         ! II.0 Matrix construction
+         ! ------------------------        
+         ! update and save of avt (and avs if double diffusive mixing)
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zavi = fsahtw(ji,jj,jk) * (                 &   ! vertical mixing coef. due to lateral mixing
+                     &                           wslpi(ji,jj,jk) * wslpi(ji,jj,jk)      &
+                     &                         + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
+                  zavsi(ji,jj,jk) = fstravs(ji,jj,jk) + zavi        ! dd mixing: zavsi = total vertical mixing coef. on tracer
+
+               END DO
+            END DO
+         END DO
+
+
+         ! II.2 Vertical diffusion on tracer
+         ! ---------------------------========
+
+         ! Rebuild the Matrix as avt /= avs
+
+         ! Diagonal, inferior, superior  (including the bottom boundary condition via avs masked)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwi(ji,jj,jk) = - rdttrc(jk) * zavsi(ji,jj,jk  ) / ( fse3t(ji,jj,jk) * fse3w(ji,jj,jk  ) )
+                  zws(ji,jj,jk) = - rdttrc(jk) * zavsi(ji,jj,jk+1) / ( fse3t(ji,jj,jk) * fse3w(ji,jj,jk+1) )
+                  zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zws(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         ! Surface boudary conditions
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwi(ji,jj,1) = 0.e0
+               zwd(ji,jj,1) = 1. - zws(ji,jj,1)
+            END DO
+         END DO
+
+         !! Matrix inversion from the first level
+         !!----------------------------------------------------------------------
+         !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+         !
+         !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+         !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+         !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+         !        (        ...               )( ...  ) ( ...  )
+         !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+         !
+         !   m is decomposed in the product of an upper and lower triangular
+         !   matrix
+         !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+         !   The second member is in 2d array zwy
+         !   The solution is in 2d array zwx
+         !   The 3d arry zwt is a work space array
+         !   zwy is used and then used as a work space array : its value is modified!
+
+         ! first recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zwt(ji,jj,1) = zwd(ji,jj,1)
+            END DO
+         END DO
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1)  /zwt(ji,jj,jk-1)
+               END DO
+            END DO
+         END DO
+
+         ! second recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               tra(ji,jj,1,jn) = trb(ji,jj,1,jn) + rdttrc(1) * tra(ji,jj,1,jn)
+            END DO
+         END DO
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zrhs = trb(ji,jj,jk,jn) + rdttrc(jk) * tra(ji,jj,jk,jn)   ! zrhs=right hand side
+                  tra(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * tra(ji,jj,jk-1,jn)
+               END DO
+            END DO
+         END DO
+
+         ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk
+         ! Save the masked passive tracer after in tra
+         ! (c a u t i o n: passive tracer not its trend, Leap-frog scheme done it will not be done in tranxt)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               tra(ji,jj,jpkm1,jn) = tra(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+            END DO
+         END DO
+         DO jk = jpk-2, 1, -1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  tra(ji,jj,jk,jn) = ( tra(ji,jj,jk,jn) - zws(ji,jj,jk) * tra(ji,jj,jk+1,jn) ) / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+#if defined key_trc_diatrd
+         ! Compute and save the vertical diffusive passive tracer trends
+#  if defined key_trcldf_iso 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztra = ( tra(ji,jj,jk,jn) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - ztrd(ji,jj,jk) + trtrd(ji,jj,jk,ikeep(jn),6)
+               END DO
+            END DO
+         END DO
+#  else
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ztra = ( tra(ji,jj,jk,jn) - trb(ji,jj,jk,jn) ) / rdttrc(jk)
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - ztrd(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+#  endif
+#endif
+
+      END DO
+
+   END SUBROUTINE trc_zdf_zdf
+
+
+   SUBROUTINE trc_zdf_iso
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_zdf_iso  ***
+      !!
+      !! ** Purpose :
+      !!     Compute the trend due to the vertical tracer diffusion inclu-
+      !!     ding the vertical component of lateral mixing (only for second
+      !!     order operator, for fourth order it is already computed and
+      !!     add to the general trend in traldf.F) and add it to the general
+      !!     trend of the tracer equations.
+      !!
+      !! ** Method :
+      !!         The vertical component of the lateral diffusive trends is
+      !!      provided by a 2nd order operator rotated along neural or geopo-
+      !!      tential surfaces to which an eddy induced advection can be added
+      !!      It is computed using before fields (forward in time) and isopyc-
+      !!      nal or geopotential slopes computed in routine ldfslp.
+      !!
+      !!      First part: vertical trends associated with the lateral mixing
+      !!      ==========  (excluding the vertical flux proportional to dk[t] )
+      !!      vertical fluxes associated with the rotated lateral mixing:
+      !!         zftw =-aht {  e2t*wslpi di[ mi(mk(trb)) ]
+      !!                     + e1t*wslpj dj[ mj(mk(trb)) ]  }
+      !!      save avt coef. resulting from vertical physics alone in zavt:
+      !!         zavt = avt
+      !!      update and save in zavt the vertical eddy viscosity coefficient:
+      !!         avt = avt + wslpi^2+wslj^2
+      !!      add vertical Eddy Induced advective fluxes (lk_traldf_eiv=T):
+      !!         zftw = zftw + { di[aht e2u mi(wslpi)]
+      !!                    +dj[aht e1v mj(wslpj)] } mk(trb)
+      !!      take the horizontal divergence of the fluxes:
+      !!         difft = 1/(e1t*e2t*e3t) dk[ zftw ] 
+      !!      Add this trend to the general trend tra :
+      !!         tra = tra + difft
+      !!
+      !! ** Action :
+      !!         Update tra arrays with the before vertical diffusion trend
+      !!         Save in trtrd arrays the trends if 'key_trc_diatrd' defined
+      !!
+      !! History :
+      !!   6.0  !  90-10  (B. Blanke)  Original code
+      !!   7.0  !  91-11  (G. Madec)
+      !!        !  92-06  (M. Imbard) correction on tracer trend loops
+      !!        !  96-01  (G. Madec) statement function for e3
+      !!        !  97-05  (G. Madec) vertical component of isopycnal
+      !!        !  97-07  (G. Madec) geopotential diffusion in s-coord
+      !!        !  98-03  (L. Bopp MA Foujols) passive tracer generalisation
+      !!        !  00-05  (MA Foujols) add lbc for tracer trends
+      !!        !  00-06  (O Aumont)  correct isopycnal scheme suppress
+      !!        !                     avt multiple correction
+      !!        !  00-08  (G. Madec)  double diffusive mixing
+      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
+      !!   9.0  !  04-03  (C. Ethe )  adapted for passive tracers
+      !!---------------------------------------------------------------------
+      !! * Modules used
+      USE oce_trc, ONLY :   zwx => ua,  &  ! use ua, va as
+                            zwy => va      ! workspace arrays
+
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk,jn       ! dummy loop indices
+      INTEGER ::   iku, ikv
+      REAL(wp) ::   &
+         ztavg,                  &  ! temporary scalars
+         zcoef0, zcoef3,         &  !    "         "
+         zcoef4,                 &  !    "         "
+         zbtr, zmku, zmkv,       &  !    "         "
+#if defined key_trcldf_eiv
+         zcoeg3,                 &  !    "         "
+         zuwki, zvwki,           &  !    "         "
+         zuwk, zvwk,             &  !    "         "
+#endif
+         ztav
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
+         zwz, zwt, ztfw             ! temporary workspace arrays
+      !!---------------------------------------------------------------------
+
+      DO jn = 1, jptra
+
+         ! 0. Local constant initialization
+         ! --------------------------------
+         ztavg = 0.e0
+
+         zwx( 1 ,:,:)=0.e0     ;     zwx(jpi,:,:)=0.e0
+         zwy( 1 ,:,:)=0.e0     ;     zwy(jpi,:,:)=0.e0
+         zwz( 1 ,:,:)=0.e0     ;     zwz(jpi,:,:)=0.e0
+         zwt( 1 ,:,:)=0.e0     ;     zwt(jpi,:,:)=0.e0
+         ztfw( 1 ,:,:)=0.e0    ;     ztfw(jpi,:,:)=0.e0
+
+         ! I. Vertical trends associated with lateral mixing
+         ! -------------------------------------------------
+         !    (excluding the vertical flux proportional to dk[t] )
+
+
+         ! I.1 horizontal tracer gradient
+         ! ------------------------------
+
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! i-gradient of passive tracer at ji
+                  zwx (ji,jj,jk) = ( trb(ji+1,jj,jk,jn)-trb(ji,jj,jk,jn) ) * umask(ji,jj,jk)
+                  ! j-gradient of passive tracer at jj
+                  zwy (ji,jj,jk) = ( trb(ji,jj+1,jk,jn)-trb(ji,jj,jk,jn) ) * vmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( ln_zps ) THEN
+            ! partial steps correction at the bottom ocean level 
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! last ocean level
+                  iku  = MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1
+                  ikv  = MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1
+                  ! i-gradient of passive tracer
+                  zwx (ji,jj,iku) = gtru(ji,jj,jn)
+                  ! j-gradient of passive tracer
+                  zwy (ji,jj,ikv) = gtrv(ji,jj,jn)  
+               END DO
+            END DO
+         ENDIF
+
+
+         ! I.2 Vertical fluxes
+         ! -------------------
+
+         ! Surface and bottom vertical fluxes set to zero
+         ztfw(:,:, 1 ) = 0.e0
+         ztfw(:,:,jpk) = 0.e0
+
+         ! interior (2=<jk=<jpk-1)
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zcoef0 = - fsahtw(ji,jj,jk) * tmask(ji,jj,jk)
+
+                  zmku = 1./MAX(   umask(ji  ,jj,jk-1) + umask(ji-1,jj,jk)      &
+                     &           + umask(ji-1,jj,jk-1) + umask(ji  ,jj,jk), 1.  )
+
+                  zmkv = 1./MAX(   vmask(ji,jj  ,jk-1) + vmask(ji,jj-1,jk)      &
+                     &           + vmask(ji,jj-1,jk-1) + vmask(ji,jj  ,jk), 1.  )
+
+                  zcoef3 = zcoef0 * e2t(ji,jj) * zmku * wslpi (ji,jj,jk)
+                  zcoef4 = zcoef0 * e1t(ji,jj) * zmkv * wslpj (ji,jj,jk)
+
+                  ztfw(ji,jj,jk) = zcoef3 * (   zwx(ji  ,jj  ,jk-1) + zwx(ji-1,jj  ,jk)      &
+                     &                        + zwx(ji-1,jj  ,jk-1) + zwx(ji  ,jj  ,jk)  )   &
+                     &           + zcoef4 * (   zwy(ji  ,jj  ,jk-1) + zwy(ji  ,jj-1,jk)      &
+                     &                        + zwy(ji  ,jj-1,jk-1) + zwy(ji  ,jj  ,jk)  )
+               END DO
+            END DO
+         END DO
+
+#if defined key_trcldf_eiv
+         !                              ! ---------------------------------------!
+         !                              ! Eddy induced vertical advective fluxes !
+         !                              ! ---------------------------------------!
+         zwx(:,:, 1 ) = 0.e0
+         zwx(:,:,jpk) = 0.e0
+
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#   if defined key_traldf_c2d || defined key_traldf_c3d  || defined key_off_degrad
+                  zuwki = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) )   &
+                     &  * fsaeitru(ji-1,jj,jk) * e2u(ji-1,jj) * umask(ji-1,jj,jk)
+                  zuwk  = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) )   &
+                     &  * fsaeitru(ji  ,jj,jk) * e2u(ji  ,jj) * umask(ji  ,jj,jk)
+                  zvwki = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) )   &
+                     &  * fsaeitrv(ji,jj-1,jk) * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
+                  zvwk  = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) )   &
+                     &  * fsaeitrv(ji,jj  ,jk) * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
+
+                  zcoeg3 = + 0.25 * tmask(ji,jj,jk) * ( zuwk - zuwki + zvwk - zvwki )
+#   else
+                  zuwki = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) )   &
+                     &  * e2u(ji-1,jj) * umask(ji-1,jj,jk)
+                  zuwk  = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) )   &
+                     &  * e2u(ji  ,jj) * umask(ji  ,jj,jk)
+                  zvwki = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) )   &
+                     &  * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
+                  zvwk  = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) )   &
+                     &  * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
+
+                  zcoeg3 = + 0.25 * tmask(ji,jj,jk) * fsaeiw(ji,jj,jk)   &
+                     &            * ( zuwk - zuwki + zvwk - zvwki )
+#   endif
+                  zwx(ji,jj,jk) = + zcoeg3 * ( trb(ji,jj,jk,jn) + trb(ji,jj,jk-1,jn) )
+
+                  ztfw(ji,jj,jk) = ztfw(ji,jj,jk) + zwx(ji,jj,jk)
+#   if defined key_diaeiv
+                  w_trc_eiv(ji,jj,jk) = -2. * zcoeg3 / ( e1t(ji,jj)*e2t(ji,jj) )
+#   endif
+               END DO
+            END DO
+         END DO
+#endif
+
+         ! I.5 Divergence of vertical fluxes added to the general tracer trend
+         ! -------------------------------------------------------------------
+
+         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) )
+                  ztav = (  ztfw(ji,jj,jk) - ztfw(ji,jj,jk+1)  ) * zbtr
+                  tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztav
+#if defined key_trc_diatrd
+#   if defined key_trcldf_eiv
+                  ztavg = ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) ) * zbtr
+                  !  WARNING trtrd(ji,jj,jk,7) used for vertical gent velocity trend  not for damping !!!
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),9) = ztavg
+#   endif
+                  IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztav - ztavg
+#endif
+               END DO
+            END DO
+         END DO
+
+      END DO
+
+   END SUBROUTINE trc_zdf_iso
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :             NO rotation of the lateral mixing tensor
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_zdf_iso_vopt( kt )              ! empty routine
+      WRITE(*,*) 'trc_zdf_iso_vopt: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_zdf_iso_vopt
+#endif
+
+   !!==============================================================================
+END MODULE trczdf_iso_vopt
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/zpshde_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/zpshde_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/TRP/zpshde_trc.F90	(revision 4536)
@@ -0,0 +1,201 @@
+MODULE zpshde_trc
+   !!==============================================================================
+   !!                       ***  MODULE zpshde_trc   ***
+   !! Ocean passive tracers: 
+   !!==============================================================================
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!                  z-coordinate with partial steps
+   !!----------------------------------------------------------------------
+   !!   zps_hde_trc  :  Horizontal DErivative of passive tracers at the last
+   !!                   ocean level (Z-coord. with Partial Steps)
+   !!----------------------------------------------------------------------
+   !! * Modules used
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE lbclnk          ! lateral boundary conditions (or mpp link)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   !! * Routine accessibility
+   PUBLIC zps_hde_trc          ! routine called by step.F90
+
+   !! * module variables
+   INTEGER, DIMENSION(jpi,jpj) ::   &
+      mbatu, mbatv      ! bottom ocean level index at U- and V-points
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE zps_hde_trc ( kt, ptra, pgtru, pgtrv )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zps_hde_trc  ***
+      !!                    
+      !! ** Purpose :   Compute the horizontal derivative of passive tracers
+      !!      TRA at u- and v-points with a linear interpolation for z-coordinate
+      !!      with partial steps.
+      !!
+      !! ** Method  :   In z-coord with partial steps, scale factors on last 
+      !!      levels are different for each grid point, so that TRA points 
+      !!      are not at the same depth as in z-coord. To have horizontal
+      !!      gradients again, we interpolate TRA at the good depth : 
+      !!      Linear interpolation of TRA  
+      !!         Computation of di(trb) and dj(trb) by vertical interpolation:
+      !!          di(tra) = tra~ - tra(i,j,k) or tra(i+1,j,k) - tra~
+      !!          dj(tra) = tra~ - tra(i,j,k) or tra(i,j+1,k) - tra~
+      !!         This formulation computes the two cases:
+      !!                 CASE 1                   CASE 2  
+      !!         k-1  ___ ___________   k-1   ___ ___________
+      !!                  TRAi  TRA~             TRA~  TRAi+1
+      !!                  _____                        _____
+      !!         k        |   |TRAi+1   k         TRAi |   |
+      !!                  |   |____                ____|   |
+      !!              ___ |   |   |           ___  |   |   |
+      !!                  
+      !!      case 1->   e3w(i+1) >= e3w(i) ( and e3w(j+1) >= e3w(j) ) then
+      !!      tra~ = tra(i+1,j  ,k) + (e3w(i+1) - e3w(i)) * dk(TRAi+1)/e3w(i+1)
+      !!    ( tra~ = tra(i  ,j+1,k) + (e3w(j+1) - e3w(j)) * dk(TRAj+1)/e3w(j+1))
+      !!          or
+      !!      case 2->   e3w(i+1) <= e3w(i) ( and e3w(j+1) <= e3w(j) ) then
+      !!       tra~ = tra(i,j,k) + (e3w(i) - e3w(i+1)) * dk(TRAi)/e3w(i )
+      !!     ( tra~ = tra(i,j,k) + (e3w(j) - e3w(j+1)) * dk(TRAj)/e3w(j ) )
+      !!      
+      !!
+      !! ** Action  : - pgtru : horizontal gradient of TRA at U-points 
+      !!              - pgtrv : horizontal gradient of TRA at V-points 
+      !!
+      !! History :
+      !!   8.5  !  02-04  (A. Bozec)  Original code
+      !!   8.5  !  02-08  (G. Madec E. Durand)  Optimization and Free form
+      !!   9.0  !  04-03  (C. Ethe)  adapted for passive tracers
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in ) ::   kt ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra), INTENT( in ) ::   &
+         ptra                       ! 4D tracers fields
+      REAL(wp), DIMENSION(jpi,jpj,jptra), INTENT( out ) ::   &
+         pgtru,                 &  ! horizontal grad. of TRA u- and v-points 
+         pgtrv                     ! of the partial step level
+
+      !! * Local declarations
+      INTEGER ::   ji, jj,jn,     &  ! Dummy loop indices
+                   iku,ikv          ! partial step level at u- and v-points
+      REAL(wp), DIMENSION(jpi,jpj) ::   &
+         zti, ztj                   ! tempory arrays
+
+      REAL(wp), DIMENSION(jpi,jpj,jptra) ::   &
+         ztrai, ztraj               ! interpolated value of TRA
+
+      REAL(wp) ::   &
+         ze3wu, ze3wv,           &  ! temporary scalars
+         zmaxu1, zmaxu2,         &  !    "         "
+         zmaxv1, zmaxv2             !    "         "
+      !!----------------------------------------------------------------------
+
+      ! Initialization (first time-step only): compute mbatu and mbatv
+      IF( kt == nittrc000 ) THEN
+         mbatu(:,:) = 0
+         mbatv(:,:) = 0
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               mbatu(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji+1,jj  ) ) - 1, 2 )
+               mbatv(ji,jj) = MAX( MIN( mbathy(ji,jj), mbathy(ji  ,jj+1) ) - 1, 2 )
+            END DO
+         END DO
+         zti(:,:) = FLOAT( mbatu(:,:) )
+         ztj(:,:) = FLOAT( mbatv(:,:) )
+         ! lateral boundary conditions: T-point, sign unchanged
+         CALL lbc_lnk( zti , 'U', 1. )
+         CALL lbc_lnk( ztj , 'V', 1. )
+         mbatu(:,:) = MAX( INT( zti(:,:) ), 2 )
+         mbatv(:,:) = MAX( INT( ztj(:,:) ), 2 )
+      ENDIF
+      
+
+      DO jn = 1, jptra
+         ! Interpolation of passive tracers at the last ocean level
+# if defined key_vectopt_loop   &&   ! defined key_mpp_omp
+         jj = 1
+         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
+# else
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+# endif
+               ! last level
+               iku = mbatu(ji,jj)
+               ikv = mbatv(ji,jj)
+
+               ze3wu  = fse3w(ji+1,jj  ,iku) - fse3w(ji,jj,iku)
+               ze3wv  = fse3w(ji  ,jj+1,ikv) - fse3w(ji,jj,ikv)
+               zmaxu1 =  ze3wu / fse3w(ji+1,jj  ,iku)
+               zmaxu2 = -ze3wu / fse3w(ji  ,jj  ,iku)
+               zmaxv1 =  ze3wv / fse3w(ji  ,jj+1,ikv)
+               zmaxv2 = -ze3wv / fse3w(ji  ,jj  ,ikv)
+
+               ! i- direction
+
+               IF( ze3wu >= 0. ) THEN      ! case 1
+                  ! interpolated values of passive tracers
+                  ztrai(ji,jj,jn) = ptra(ji+1,jj,iku,jn) + zmaxu1 * ( ptra(ji+1,jj,iku-1,jn) - ptra(ji+1,jj,iku,jn) )
+                  ! gradient of passive tracers
+                  pgtru(ji,jj,jn) = umask(ji,jj,1) * ( ztrai(ji,jj,jn) - ptra(ji,jj,iku,jn) )
+               ELSE                        ! case 2
+                  ! interpolated values of passive tracers
+                  ztrai(ji,jj,jn) = ptra(ji,jj,iku,jn) + zmaxu2 * ( ptra(ji,jj,iku-1,jn) - ptra(ji,jj,iku,jn) )
+                  ! gradient of passive tracers
+                  pgtru(ji,jj,jn) = umask(ji,jj,1) * ( ptra(ji+1,jj,iku,jn) - ztrai (ji,jj,jn) )
+               ENDIF
+
+               ! j- direction
+
+               IF( ze3wv >= 0. ) THEN      ! case 1
+                  ! interpolated values of passive tracers
+                  ztraj(ji,jj,jn) = ptra(ji,jj+1,ikv,jn) + zmaxv1 * ( ptra(ji,jj+1,ikv-1,jn) - ptra(ji,jj+1,ikv,jn) )
+                  ! gradient of passive tracers
+                  pgtrv(ji,jj,jn) = vmask(ji,jj,1) * ( ztraj(ji,jj,jn) - ptra(ji,jj,ikv,jn) )
+               ELSE                        ! case 2
+                  ! interpolated values of passive tracers
+                  ztraj(ji,jj,jn) = ptra(ji,jj,ikv,jn) + zmaxv2 * ( ptra(ji,jj,ikv-1,jn) - ptra(ji,jj,ikv,jn) )
+                  ! gradient of passive tracers
+                  pgtrv(ji,jj,jn) = vmask(ji,jj,1) * ( ptra(ji,jj+1,ikv,jn) - ztraj(ji,jj,jn) )
+               ENDIF
+# if ! defined key_vectopt_loop   ||   defined key_mpp_omp
+            END DO
+# endif
+         END DO
+
+         ! Lateral boundary conditions on each gradient
+         CALL lbc_lnk( pgtru(:,:,jn) , 'U', -1. ) 
+         CALL lbc_lnk( pgtrv(:,:,jn) , 'V', -1. )
+
+      END DO
+
+   END SUBROUTINE zps_hde_trc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   USE par_kind
+CONTAINS
+   SUBROUTINE zps_hde_trc ( kt, ptra, pgtru, pgtrv ) ! Empty routine
+      INTEGER, INTENT( in) :: kt
+      REAL(wp), DIMENSION(:,:,:,:) :: ptra
+      REAL(wp) :: pgtru, pgtrv
+      WRITE(*,*) 'zps_hde_trc: You should not have seen this print! error?',   &
+         kt, ptra, pgtru, pgtrv
+   END SUBROUTINE zps_hde_trc
+#endif
+
+   !!======================================================================
+END MODULE zpshde_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/initrc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/initrc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/initrc.F90	(revision 4536)
@@ -0,0 +1,123 @@
+MODULE initrc
+   !!======================================================================
+   !!                         ***  MODULE initrc  ***
+   !! TOP :   Initialisation of passive tracers
+   !!======================================================================
+   !! History :    -   !  1991-03  ()  original code
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!              -   !  2005-10 (C. Ethe) print control
+   !!             2.0  !  2005-10 (C. Ethe, G. Madec) revised architecture
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   ini_trc    :  initialisation of passive tracers
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE trcrst
+   USE trcctl
+   USE trclec
+   USE trcdtr
+   USE trcini
+   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
+   
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   ini_trc   ! called by ???
+
+    !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+  
+CONTAINS
+   
+   SUBROUTINE ini_trc
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE ini_trc  ***
+      !!
+      !! ** Purpose :   Initialization of the passive tracer fields 
+      !!
+      !! ** Method  : - read namelist
+      !!              - control the consistancy 
+      !!              - compute specific initialisations
+      !!              - set initial tracer fields (either read restart 
+      !!                or read data or analytical formulation
+      !!---------------------------------------------------------------------
+      INTEGER ::   jk, jn    ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zbt   ! workspace: masked grid volume
+      CHARACTER (len=25) :: charout
+
+      !!---------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ini_trc : initial set up of the passive tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+      !                 ! masked grid volume
+      DO jk = 1, jpk
+         zbt(:,:,jk) = e1t(:,:) * e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
+      END DO
+#if defined key_off_degrad
+      DO jk = 1, jpk
+         zbt(:,:,:) = zbt(:,:,:) * facvol(:,:,jk)      ! degrad option: reduction by facvol
+      ENDDO
+#endif
+
+      !                 ! total volume of the ocean
+      areatot = SUM( zbt(:,:,:) )
+      IF( lk_mpp )   CALL mpp_sum( areatot )     ! sum over the global domain  
+
+      CALL trc_lec      ! READ passive tracers namelists
+
+      CALL trc_ctl      ! control consistency between parameters, cpp key and namelists
+
+      CALL trc_ini      ! computes some initializations
+
+      !                 ! set initial tracer values 
+      IF( lrsttr ) THEN   ;   CALL trc_rst_read      ! restart from a file
+      ELSE                ;   CALL trc_dtr           ! analytical formulation or from data
+      ENDIF
+
+      !                 ! Computation content of all tracers
+      trai = 0.e0
+      DO jn = 1, jptra
+         trai = trai + SUM( trn(:,:,:,jn) * zbt(:,:,:) )
+      END DO      
+      IF( lk_mpp )   CALL mpp_sum( trai )     ! sum over the global domain  
+
+
+      !                 ! control print
+      IF(lwp) WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
+      IF(lwp) WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
+      IF(lwp) WRITE(numout,*) '          *** Total inital content of all tracers  = ', trai
+      IF(lwp) WRITE(numout,*)
+
+      IF( ln_ctl )   CALL prt_ctl_trc_init      ! control print
+      !
+
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('ini ')")
+         CALL prt_ctl_trc_info( charout )
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+
+   END SUBROUTINE ini_trc
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ini_trc                      ! Dummy routine   
+   END SUBROUTINE ini_trc
+#endif
+
+   !!======================================================================
+END MODULE initrc 
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/oce_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/oce_trc.F90	(revision 4536)
@@ -0,0 +1,239 @@
+MODULE oce_trc
+   !!======================================================================
+   !!                      ***  MODULE  oce_trc  ***
+   !! TOP :   variables shared between ocean and passive tracers
+   !!======================================================================
+   !! History :   1.0  !  2004-03  (C. Ethe)  original code
+   !!             2.0  !  2007-12 (C. Ethe, G. Madec)  rewritting
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0,  LOCEAN-IPSL (2007)
+   !! $Header: $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+
+   !* Domain size *
+   USE par_oce , ONLY :   cp_cfg   =>   cp_cfg     !: name of the configuration
+   USE par_oce , ONLY :   jp_cfg   =>   jp_cfg     !: resolution of the configuration
+   USE par_oce , ONLY :   jpiglo   =>   jpiglo     !: first  dimension of global domain --> i
+   USE par_oce , ONLY :   jpjglo   =>   jpjglo     !: second dimension of global domain --> j
+   USE par_oce , ONLY :   jpi      =>   jpi        !: first  dimension of grid --> i 
+   USE par_oce , ONLY :   jpj      =>   jpj        !: second dimension of grid --> j  
+   USE par_oce , ONLY :   jpk      =>   jpk        !: number of levels  
+   USE par_oce , ONLY :   jpim1    =>   jpim1      !: jpi - 1
+   USE par_oce , ONLY :   jpjm1    =>   jpjm1      !: jpj - 1 
+   USE par_oce , ONLY :   jpkm1    =>   jpkm1      !: jpk - 1  
+   USE par_oce , ONLY :   jpij     =>   jpij       !: jpi x jpj
+   USE par_oce , ONLY :   jpidta   =>   jpidta     !: first horizontal dimension  > or = jpi
+   USE par_oce , ONLY :   jpjdta   =>   jpjdta     !: second horizontal dimension > or = jpj
+   USE par_oce , ONLY :   jpkdta   =>   jpkdta     !: number of levels            > or = jpk
+   USE par_oce , ONLY :   lk_esopa =>   lk_esopa   !: flag to activate the all option
+
+   !* IO manager *
+   USE in_out_manager      ! use all the variables
+   !* physical constants *
+   USE phycst              ! use all the variables
+
+   !* model domain *
+   USE dom_oce , ONLY :   lzoom      => lzoom        !: zoom flag
+   USE dom_oce , ONLY :   lzoom_e    => lzoom_e      !: East  zoom type flag
+   USE dom_oce , ONLY :   lzoom_w    => lzoom_w      !: West  zoom type flag
+   USE dom_oce , ONLY :   lzoom_s    => lzoom_s      !: South zoom type flag
+   USE dom_oce , ONLY :   lzoom_n    => lzoom_n      !: North zoom type flag
+   USE dom_oce , ONLY :   lzoom_arct => lzoom_arct   !: ORCA    arctic zoom flag
+   USE dom_oce , ONLY :   lzoom_anta => lzoom_anta   !: ORCA antarctic zoom flag
+   USE dom_oce , ONLY :   nperio     =>   nperio     !: type of lateral boundary condition       
+   USE dom_oce , ONLY :   nimpp      =>   nimpp      !: i index for mpp-subdomain left bottom
+   USE dom_oce , ONLY :   njmpp      =>   njmpp      !: j index for mpp-subdomain left bottom
+   USE dom_oce , ONLY :   nproc      =>   nproc      !: number for local processor
+   USE dom_oce , ONLY :   narea      =>   narea      !: number for local area
+   USE dom_oce , ONLY :   mig        =>   mig        !: local  ==> global  domain i-indice
+   USE dom_oce , ONLY :   mjg        =>   mjg        !: local  ==> global  domain i-indice
+   USE dom_oce , ONLY :   mi0        =>   mi0        !: global ==> local domain i-indice 
+   USE dom_oce , ONLY :   mi1        =>   mi1        !: (mi0=1 and mi1=0 if the global indice is not in the local one)
+   USE dom_oce , ONLY :   mj0        =>   mj0        !: global ==> local domain j-indice 
+   USE dom_oce , ONLY :   mj1        =>   mj1        !: (mj0=1 and mj1=0 if the global indice is not in the local one)
+   USE dom_oce , ONLY :   nidom      =>   nidom
+   USE dom_oce , ONLY :   nimppt     => nimppt     !:i-indexes for each processor
+   USE dom_oce , ONLY :   njmppt     => njmppt       !:j-indexes for each processor
+   USE dom_oce , ONLY :   ibonit     => ibonit       !:i-processor neighbour existence
+   USE dom_oce , ONLY :   ibonjt     => ibonjt       !:j- processor neighbour existence 
+   USE dom_oce , ONLY :   nlci       => nlci         !:i- & j-dimensions of the local subdomain
+   USE dom_oce , ONLY :   nlcj       => nlcj         !:
+   USE dom_oce , ONLY :   nldi       => nldi         !:first and last indoor i- and j-indexes
+   USE dom_oce , ONLY :   nlei       => nlei         !:
+   USE dom_oce , ONLY :   nldj       => nldj         !:
+   USE dom_oce , ONLY :   nlej       => nlej         !:
+   USE dom_oce , ONLY :   nlcit      => nlcit        !:dimensions of every i-subdomain
+   USE dom_oce , ONLY :   nlcjt      => nlcjt        !:dimensions of every j-subdomain
+   USE dom_oce , ONLY :   nldit      => nldit        !:first indoor index for each i-domain 
+   USE dom_oce , ONLY :   nleit      => nleit        !:last indoor index for each i-domain 
+   USE dom_oce , ONLY :   nldjt      => nldjt        !:first indoor index for each j-domain 
+   USE dom_oce , ONLY :   nlejt      => nlejt        !:last indoor index for each j-domain 
+ 
+   !* horizontal mesh *
+   USE dom_oce , ONLY :   glamt      =>   glamt      !: longitude of t-point (degre)  
+   USE dom_oce , ONLY :   glamu      =>   glamu      !: longitude of t-point (degre)  
+   USE dom_oce , ONLY :   glamv      =>   glamv      !: longitude of t-point (degre)  
+   USE dom_oce , ONLY :   glamf      =>   glamf      !: longitude of t-point (degre)  
+   USE dom_oce , ONLY :   gphit      =>   gphit      !: latitude  of t-point (degre)   
+   USE dom_oce , ONLY :   gphiu      =>   gphiu      !: latitude  of t-point (degre)   
+   USE dom_oce , ONLY :   gphiv      =>   gphiv      !: latitude  of t-point (degre)   
+   USE dom_oce , ONLY :   gphif      =>   gphif      !: latitude  of t-point (degre)   
+   USE dom_oce , ONLY :   e1t        =>   e1t        !: horizontal scale factors at t-point (m)  
+   USE dom_oce , ONLY :   e2t        =>   e2t        !: horizontal scale factors at t-point (m)   
+   USE dom_oce , ONLY :   e1u        =>   e1u        !: horizontal scale factors at u-point (m)
+   USE dom_oce , ONLY :   e2u        =>   e2u        !: horizontal scale factors at u-point (m)
+   USE dom_oce , ONLY :   e1v        =>   e1v        !: horizontal scale factors at v-point (m)
+   USE dom_oce , ONLY :   e2v        =>   e2v        !: horizontal scale factors at v-point (m)  
+
+   !* vertical mesh *
+   USE dom_oce , ONLY :   gdept_0    =>   gdept_0    !: reference depth of t-points (m)
+   USE dom_oce , ONLY :   e3t_0      =>   e3t_0      !: reference depth of t-points (m)  
+   USE dom_oce , ONLY :   e3w_0      =>   e3w_0      !: reference depth of w-points (m)
+   USE dom_oce , ONLY :   gdepw_0    =>   gdepw_0    !: reference depth of w-points (m)
+# if ! defined key_zco
+   USE dom_oce , ONLY :   gdep3w     =>  gdep3w      !: ???
+   USE dom_oce , ONLY :   gdept      =>  gdept       !: depth of t-points (m)
+   USE dom_oce , ONLY :   gdepw      =>  gdepw       !: depth of t-points (m)
+   USE dom_oce , ONLY :   e3t        =>  e3t         !: vertical scale factors at t-
+   USE dom_oce , ONLY :   e3u        =>  e3u         !: vertical scale factors at u-
+   USE dom_oce , ONLY :   e3v        =>  e3v         !: vertical scale factors v-
+   USE dom_oce , ONLY :   e3w        =>  e3w         !: w-points (m)
+   USE dom_oce , ONLY :   e3f        =>  e3f         !: f-points (m)
+   USE dom_oce , ONLY :   e3uw       =>  e3uw        !: uw-points (m)
+   USE dom_oce , ONLY :   e3vw       =>  e3vw        !: vw-points (m)
+# endif
+   USE dom_oce , ONLY :   ln_zps     =>  ln_zps      !: partial steps flag
+   USE dom_oce , ONLY :   ln_sco     =>  ln_sco      !: s-coordinate flag
+   USE dom_oce , ONLY :   ln_zco     =>  ln_zco      !: z-coordinate flag
+   USE dom_oce , ONLY :   lk_zco     =>  lk_zco      !: z-coordinate flag (1D or 3D arrays)
+   USE dom_oce , ONLY :   hbatt     =>   hbatt       !: ocean depth at the vertical of  t-point (m)
+   USE dom_oce , ONLY :   hbatu     =>   hbatu       !: ocean depth at the vertical of  u-point (m)
+   USE dom_oce , ONLY :   hbatv     =>   hbatv       !: ocean depth at the vertical of w-point (m)
+   USE dom_oce , ONLY :   gsigt     =>   gsigt       !: model level depth coefficient at T-levels
+   USE dom_oce , ONLY :   gsigw     =>   gsigw       !: model level depth coefficient at W-levels
+   USE dom_oce , ONLY :   gsi3w     =>   gsi3w       !: model level depth coef at w-levels (defined as the sum of e3w)
+   USE dom_oce , ONLY :   esigt     =>   esigt       !: vertical scale factor coef. at t-levels
+   USE dom_oce , ONLY :   esigw     =>   esigw       !: vertical scale factor coef. at w-levels
+
+   !* masks, bathymetry *
+   USE dom_oce , ONLY :   mbathy    =>   mbathy      !: number of ocean level (=0,  & 1, ... , jpk-1) 
+   USE dom_oce , ONLY :   tmask_i   =>   tmask_i     !: Interior mask at t-points
+   USE dom_oce , ONLY :   tmask     =>   tmask       !: land/ocean mask at t-points
+   USE dom_oce , ONLY :   umask     =>   umask       !: land/ocean mask at u-points   
+   USE dom_oce , ONLY :   vmask     =>   vmask       !: land/ocean mask at v-points 
+   USE dom_oce , ONLY :   fmask     =>   fmask       !: land/ocean mask at f-points 
+# if defined key_off_degrad
+   USE dom_oce , ONLY :   facvol    =>   facvol      !: volume factor for degradation
+# endif
+
+   !* time domain *
+   USE dom_oce , ONLY :   neuler    =>   neuler      !: restart euler forward option (0=Euler)
+   USE dom_oce , ONLY :   rdt       =>   rdt         !: time step for the dynamics 
+   USE dom_oce , ONLY :   atfp      =>   atfp        !: asselin time filter parameter
+   USE dom_oce , ONLY :   atfp1     =>   atfp1       !: asselin time filter coeff. (atfp1= 1-2*atfp)
+   USE dom_oce , ONLY :   rdttra    =>   rdttra      !: vertical profile of tracer time step
+   USE daymod  , ONLY :   ndastp    =>   ndastp      !: time step date in year/month/day aammjj
+   USE daymod  , ONLY :   nday_year =>   nday_year   !: curent day counted from jan 1st of the current year
+   USE daymod  , ONLY :   nyear     =>   nyear       !: Current year
+   USE daymod  , ONLY :   nmonth    =>   nmonth      !: Current month
+   USE daymod  , ONLY :   nday      =>   nday        !: Current day
+
+   !* ocean fields: here now and after fields *
+   USE oce , ONLY :   ua      =>    ua      !: i-horizontal velocity (m s-1) 
+   USE oce , ONLY :   va      =>    va      !: j-horizontal velocity (m s-1)
+   USE oce , ONLY :   un      =>    un      !: i-horizontal velocity (m s-1) 
+   USE oce , ONLY :   vn      =>    vn      !: j-horizontal velocity (m s-1)
+   USE oce , ONLY :   wn      =>    wn      !: vertical velocity (m s-1)  
+   USE oce , ONLY :   tn      =>    tn      !: pot. temperature (celsius)
+   USE oce , ONLY :   sn      =>    sn      !: salinity (psu)
+   USE oce , ONLY :   rhop    =>    rhop    !: potential volumic mass (kg m-3) 
+   USE oce , ONLY :   rhd     =>    rhd     !: in situ density anomalie rhd=(rho-rau0)/rau0 (no units)
+# if defined key_trc_diatrd
+   USE oce , ONLY :   hdivn   =>    hdivn   !: horizontal divergence (1/s)
+# endif
+
+
+   USE lib_mpp , ONLY :   lk_mpp    =>  lk_mpp       !: Mpp flag
+
+   USE dynspg_oce , ONLY :   lk_dynspg_rl   =>  lk_dynspg_rl      !: rigid lid flag
+
+   USE dom_oce , ONLY :   n_cla     =>   n_cla         !: flag (0/1) for cross land advection 
+
+
+
+   !* surface fluxes *
+# if defined key_flx_bulk_monthly || defined key_flx_bulk_daily || defined key_flx_core
+   USE blk_oce, ONLY :   vatm       =>    vatm       !: wind speed at sea surface (m s-1)
+# endif
+   USE taumod , ONLY :   taux       =>    taux       !: i-surface stress component
+   USE taumod , ONLY :   tauy       =>    tauy       !: j-surface stress component
+   USE ocesbc , ONLY :   qt         =>    qt         !: total surface heat flux (w m-2)   
+   USE ocesbc , ONLY :   qsr        =>    qsr        !: penetrative solar radiation (w m-2)  
+   USE ocesbc , ONLY :   emp        =>    emp        !: evaporation minus precipitation (kg m-2 s-2) 
+   USE ocesbc , ONLY :   emps       =>    emps       !: evaporation minus precipitation (kg m-2 s-2)
+   USE traqsr , ONLY :   xsi1       =>   xsi1        !: first depth of extinction
+   USE traqsr , ONLY :   ln_qsr_sms =>  ln_qsr_sms   !: flag to use or not the biological fluxes for light
+   USE flxrnf , ONLY :   upsrnfh    =>   upsrnfh     !: mixed adv scheme in runoffs vicinity (hori.) 
+   USE flxrnf , ONLY :   upsrnfz    =>   upsrnfz     !: mixed adv scheme in runoffs vicinity (vert.)
+   USE flxrnf , ONLY :   upsadv     =>   upsadv      !: mixed adv scheme in straits vicinity (hori.)
+
+   !* freezing area *
+   USE ocfzpt , ONLY :   freeze      =>    freeze     !: ice mask (0 or 1)  
+   USE ocfzpt , ONLY :   fzptn       =>    fzptn      !: now freezing temperature at ocean surface  
+
+   !* bottom boundary layer *
+# if   defined key_trabbl_dif   ||   defined key_trabbl_adv
+   USE trabbl , ONLY :   atrbbl   =>   atrbbl     !: lateral coeff. for bottom boundary layer scheme (m2/s)
+#  if defined key_off_tra
+   USE trabbl, ONLY :   bblx   => bblx         !: ???
+   USE trabbl, ONLY :   bbly   => bbly         !: ???
+#  endif
+# endif
+
+   !* lateral diffusivity (tracers) *
+   USE ldftra_oce , ONLY :   aht0    =>   aht0     !: horizontal eddy diffusivity for tracers (m2/s)
+   USE ldftra_oce , ONLY :   ahtb0   =>   ahtb0    !: background eddy diffusivity for isopycnal diff. (m2/s)
+   USE ldftra_oce , ONLY :   ahtu    =>   ahtu     !: lateral diffusivity coef. at u-points 
+   USE ldftra_oce , ONLY :   ahtv    =>   ahtv     !: lateral diffusivity coef. at v-points 
+   USE ldftra_oce , ONLY :   ahtw    =>   ahtw     !: lateral diffusivity coef. at w-points 
+   USE ldftra_oce , ONLY :   ahtt    =>   ahtt     !: lateral diffusivity coef. at t-points
+   USE ldftra_oce , ONLY :   aeiv0   =>   aeiv0    !: eddy induced velocity coefficient (m2/s) 
+   USE ldftra_oce , ONLY :   aeiu    =>   aeiu     !: eddy induced velocity coef. at u-points (m2/s)   
+   USE ldftra_oce , ONLY :   aeiv    =>   aeiv     !: eddy induced velocity coef. at v-points (m2/s) 
+   USE ldftra_oce , ONLY :   aeiw    =>   aeiw     !: eddy induced velocity coef. at w-points (m2/s) 
+
+   !* vertical diffusion *
+   USE zdf_oce , ONLY :   avt        =>   avt         !: vert. diffusivity coef. at w-point for temp  
+   USE zdf_oce , ONLY :   avt0       =>   avt0        !: vertical eddy diffusivity for tracers (m2/s)
+   USE zdf_oce , ONLY :   ln_zdfnpc  =>   ln_zdfnpc   !: convection: non-penetrative convection flag
+# if defined key_zdfddm
+   USE zdfddm  , ONLY :   avs        =>    avs        !: salinity vertical diffusivity coeff. at w-point
+# endif
+
+   !* mixing & mixed layer depth *
+   USE zdfmxl , ONLY :   hmld        =>   hmld        !: mixing layer depth (turbocline)
+   USE zdfmxl , ONLY :   hmlp        =>   hmlp        !: mixed layer depth  (rho=rho0+zdcrit) (m)
+   USE zdfmxl , ONLY :   hmlpt       =>   hmlpt       !: mixed layer depth at t-points (m)
+
+   !* direction of lateral diffusion *
+   USE ldfslp , ONLY :   lk_ldfslp  =>  lk_ldfslp     !: slopes flag
+# if   defined key_ldfslp
+   USE ldfslp , ONLY :   uslp       =>   uslp         !: i-direction slope at u-, w-points
+   USE ldfslp , ONLY :   vslp       =>   vslp         !: j-direction slope at v-, w-points
+   USE ldfslp , ONLY :   wslpi      =>   wslpi        !: i-direction slope at u-, w-points
+   USE ldfslp , ONLY :   wslpj      =>   wslpj        !: j-direction slope at v-, w-points
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE oce_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/par_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/par_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/par_trc.F90	(revision 4536)
@@ -0,0 +1,58 @@
+MODULE par_trc
+   !!======================================================================
+   !!                        ***  par_trc  ***
+   !! TOP :   set the passive tracers parameters
+   !!======================================================================
+   !! History :    -   !  1996-01  (M. Levy)  original code
+   !!              -   !  1999-07  (M. Levy)  for LOBSTER1 or NPZD model
+   !!              -   !  2000-04  (O. Aumont, M.A. Foujols)  HAMOCC3 and P3ZD
+   !!             1.0  !  2004-03  (C. Ethe) Free form and module
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+   !
+   USE par_lobster   ! LOBSTER model
+   USE par_pisces    ! PISCES  model
+   USE par_cfc       ! CFC 11 and 12 tracers
+   USE par_my_trc    ! user defined passive tracers
+
+   IMPLICIT NONE
+   PUBLIC
+
+   ! Passive tracers : Total size
+   ! ---------------               ! total number of passive tracers, of 2d and 3d output and trend arrays
+   INTEGER, PUBLIC, PARAMETER ::   jptra    =  jp_lobster    + jp_pisces     + jp_cfc     + jp_my_trc
+   INTEGER, PUBLIC, PARAMETER ::   jpdia2d  =  jp_lobster_2d + jp_pisces_2d  + jp_cfc_2d  + jp_my_trc_2d
+   INTEGER, PUBLIC, PARAMETER ::   jpdia3d  =  jp_lobster_3d + jp_pisces_3d  + jp_cfc_3d  + jp_my_trc_3d
+   !                     ! total number of sms diagnostic arrays
+   INTEGER, PUBLIC, PARAMETER ::   jpdiabio = jp_lobster_trd + jp_pisces_trd + jp_cfc_trd + jp_my_trc_trd
+   
+   !  1D configuration ("key_cfg_1d")
+   ! -----------------
+# if defined key_cfg_1d
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trccfg_1d   = .TRUE.   !: 1D pass. tracer configuration flag
+# else   
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trccfg_1d   = .FALSE.  !: 1D pass. tracer configuration flag
+# endif
+
+   ! Passive tracers : size for TRP trends diagnotics (used if 'key_trc_diatrd' defined)
+#if defined key_trcldf_eiv
+# if defined key_trcdmp
+   INTEGER, PARAMETER :: jpdiatrc = 11      !: trends: 3*(advection + diffusion + eiv ) + damping + sms
+# else
+   INTEGER, PARAMETER :: jpdiatrc = 10      !: trends: 3*(advection + diffusion + eiv )           + sms
+# endif
+#else
+# if defined key_trcdmp
+   INTEGER, PARAMETER :: jpdiatrc =  8      !: trends: 3*(advection + diffusion       ) + damping + sms
+# else
+   INTEGER, PARAMETER :: jpdiatrc =  7      !: trends: 3*(advection + diffusion       ) + damping + sms
+# endif
+#endif
+
+   !!======================================================================
+END MODULE par_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/prtctl_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/prtctl_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/prtctl_trc.F90	(revision 4536)
@@ -0,0 +1,471 @@
+MODULE prtctl_trc
+   !!======================================================================
+   !!                         ***  MODULE prtctl_trc  ***
+   !! TOP :   print all SUM trends for each processor domain
+   !!======================================================================
+   !! History :    -   !  2005-07  (C. Talandier) original code for OPA
+   !!             1.0  !  2005-10  (C. Ethe     ) adapted to passive tracer
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   prt_ctl_trc      :   control print in mpp for passive tracers
+   !!   prt_ctl_trc_info :   ???
+   !!   prt_ctl_trc_init :   ???
+   !!----------------------------------------------------------------------
+   USE par_trc          ! TOP parameters
+   USE oce_trc          ! ocean space and time domain variables
+   USE in_out_manager   ! I/O manager
+   USE lib_mpp          ! distributed memory computing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   numid_trc          !: logical unit 
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   nlditl , nldjtl    !: first, last indoor index for each i-domain
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   nleitl , nlejtl    !: first, last indoor index for each j-domain
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   nimpptl, njmpptl   !: i-, j-indexes for each processor
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   nlcitl , nlcjtl    !: dimensions of every subdomain
+   INTEGER , DIMENSION(:), ALLOCATABLE ::   ibonitl, ibonjtl
+
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   tra_ctl         !: previous trend values
+
+   PUBLIC prt_ctl_trc         ! called by all subroutines
+   PUBLIC prt_ctl_trc_info    !
+   PUBLIC prt_ctl_trc_init    ! called by opa.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE prt_ctl_trc( tab4d, mask, clinfo, ovlap, kdim, clinfo2 )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl  ***
+      !!
+      !! ** Purpose : - print sum control 3D arrays over the same area 
+      !!                in mono and mpp case. This way can be usefull when
+      !!                debugging a new parametrization in mono or mpp. 
+      !!
+      !! ** Method  : 2 possibilities exist when setting the ln_ctl parameter to
+      !!                .true. in the ocean namelist:
+      !!              - to debug a MPI run .vs. a mono-processor one; 
+      !!                the control print will be done over each sub-domain.
+      !!                The nictl[se] and njctl[se] parameters in the namelist must 
+      !!                be set to zero and [ij]splt to the corresponding splitted
+      !!                domain in MPI along respectively i-, j- directions.
+      !!              - to debug a mono-processor run over the whole domain/a specific area; 
+      !!                in the first case the nictl[se] and njctl[se] parameters must be set
+      !!                to zero else to the indices of the area to be controled. In both cases
+      !!                isplt and jsplt must be set to 1.
+      !!              - All arguments of the above calling sequence are optional so their
+      !!                name must be explicitly typed if used. For instance if the mask
+      !!                array tmask(:,:,:) must be passed through the prt_ctl subroutine, 
+      !!                it must looks like: CALL prt_ctl( mask=tmask ).
+      !!----------------------------------------------------------------------
+      REAL(wp)         , DIMENSION(:,:,:,:), INTENT(in), OPTIONAL ::   tab4d     ! 4D array
+      REAL(wp)         , DIMENSION(:,:,:)  , INTENT(in), OPTIONAL ::   mask      ! 3D mask to apply to the tab4d array
+      CHARACTER (len=*), DIMENSION(:)      , INTENT(in), OPTIONAL ::   clinfo    ! information about the tab3d array
+      CHARACTER (len=*)                    , INTENT(in), OPTIONAL ::   clinfo2   ! ???
+      INTEGER                              , INTENT(in), OPTIONAL ::   ovlap     ! overlap value
+      INTEGER                              , INTENT(in), OPTIONAL ::   kdim      ! k- direction for 4D arrays
+      !!
+      INTEGER  ::   overlap, jn, js, sind, eind, kdir, j_id
+      REAL(wp) ::   zsum, zvctl
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask, ztab3d
+      CHARACTER (len=20), DIMENSION(jptra) ::   cl
+      CHARACTER (len=10) ::   cl2
+      !!----------------------------------------------------------------------
+
+      !                                      ! Arrays, scalars initialization 
+      overlap       = 0
+      kdir          = jpkm1
+      zsum          = 0.e0
+      zvctl         = 0.e0
+      cl(:)         = ''
+      cl2           = ''
+      ztab3d(:,:,:) = 0.e0
+      zmask (:,:,:) = 1.e0
+
+      !                                      ! Control of optional arguments
+      IF( PRESENT(ovlap)   )   overlap       = ovlap
+      IF( PRESENT(kdim)    )   kdir          = kdim
+      IF( PRESENT(clinfo ) )   cl(:)         = clinfo(:)
+      IF( PRESENT(clinfo2) )   cl2           = clinfo2
+      IF( PRESENT(mask)    )   zmask (:,:,:) = mask(:,:,:)
+
+      IF( lk_mpp )   THEN      ! processor number
+         sind = narea
+         eind = narea
+      ELSE                     ! processors total number
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. the total number of processors ijsplt
+      DO js = sind, eind
+         !
+         ! Set logical unit
+         j_id = numid_trc( js - narea + 1 )
+         ! Set indices for the SUM control
+         IF( .NOT. lsp_area ) THEN
+            IF (lk_mpp )   THEN
+               nictls = MAX( 1, nlditl(js) - overlap )
+               nictle = nleitl(js) + overlap * MIN( 1, nlcitl(js) - nleitl(js)) 
+               njctls = MAX( 1, nldjtl(js) - overlap )
+               njctle = nlejtl(js) + overlap * MIN( 1, nlcjtl(js) - nlejtl(js))
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(js) == -1 .OR. ibonitl(js) == 2 )   nictls = MAX( 2, nictls )
+               IF( ibonitl(js) ==  1 .OR. ibonitl(js) == 2 )   nictle = MIN( nictle, nleitl(js) - 1 )
+               IF( ibonjtl(js) == -1 .OR. ibonjtl(js) == 2 )   njctls = MAX( 2, njctls )
+               IF( ibonjtl(js) ==  1 .OR. ibonjtl(js) == 2 )   njctle = MIN( njctle, nlejtl(js) - 1 )
+            ELSE
+               nictls = MAX( 1, nimpptl(js) + nlditl(js) - 1 - overlap )
+               nictle = nimpptl(js) + nleitl(js) - 1 + overlap * MIN( 1, nlcitl(js) - nleitl(js) ) 
+               njctls = MAX( 1, njmpptl(js) + nldjtl(js) - 1 - overlap )
+               njctle = njmpptl(js) + nlejtl(js) - 1 + overlap * MIN( 1, nlcjtl(js) - nlejtl(js) ) 
+               ! Do not take into account the bound of the domain
+               IF( ibonitl(js) == -1 .OR. ibonitl(js) == 2 )   nictls = MAX( 2, nictls )
+               IF( ibonjtl(js) == -1 .OR. ibonjtl(js) == 2 )   njctls = MAX( 2, njctls )
+               IF( ibonitl(js) ==  1 .OR. ibonitl(js) == 2 )   nictle = MIN( nictle, nimpptl(js) + nleitl(js) - 2 )
+               IF( ibonjtl(js) ==  1 .OR. ibonjtl(js) == 2 )   njctle = MIN( njctle, njmpptl(js) + nlejtl(js) - 2 )
+            ENDIF
+         ENDIF
+         !
+         IF( PRESENT(clinfo2) ) THEN
+            DO jn = 1, jptra
+               zvctl  = tra_ctl(jn,js)
+               ztab3d(:,:,:) = tab4d(:,:,:,jn)
+               zsum          = SUM( ztab3d(nictls:nictle,njctls:njctle,1:kdir)   &
+                  &                * zmask(nictls:nictle,njctls:njctle,1:kdir) )
+               WRITE(j_id,FMT="(3x,a,' : ',D23.16)") cl(jn), zsum-zvctl
+               tra_ctl(jn,js) = zsum
+            END DO
+         ELSE
+            DO jn = 1, jptra
+               ztab3d(:,:,:) = tab4d(:,:,:,jn)
+               zsum          = SUM( ztab3d(nictls:nictle,njctls:njctle,1:kdir)   &
+                  &               *  zmask(nictls:nictle,njctls:njctle,1:kdir) )
+               WRITE(j_id,FMT="(3x,a,' : ',D23.16)") cl(jn), zsum
+            END DO
+         ENDIF
+         !
+      END DO
+      !
+   END SUBROUTINE prt_ctl_trc
+
+
+   SUBROUTINE prt_ctl_trc_info( clinfo )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_trc_info  ***
+      !!
+      !! ** Purpose : - print information without any computation
+      !!----------------------------------------------------------------------
+      CHARACTER (len=*), INTENT(in) ::   clinfo      ! information to print
+      !! 
+      INTEGER ::   js, sind, eind, j_id
+      !!----------------------------------------------------------------------
+
+      IF( lk_mpp ) THEN      ! processor number
+         sind = narea
+         eind = narea
+      ELSE                   ! total number of processors
+         sind = 1
+         eind = ijsplt
+      ENDIF
+
+      ! Loop over each sub-domain, i.e. number of processors ijsplt
+      DO js = sind, eind
+         j_id = numid_trc(js - narea + 1)
+         WRITE(j_id,*) clinfo
+      END DO
+      !
+   END SUBROUTINE prt_ctl_trc_info
+
+
+   SUBROUTINE prt_ctl_trc_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE prt_ctl_trc_init  ***
+      !!
+      !! ** Purpose :   open ASCII files & compute indices
+      !!----------------------------------------------------------------------
+      INTEGER            ::   js, sind, eind, j_id
+      CHARACTER (len=31) :: clfile_out
+      CHARACTER (len=27) :: clb_name
+      CHARACTER (len=19) :: cl_run
+      !!----------------------------------------------------------------------
+
+      !                             ! Allocate arrays
+      ALLOCATE( nlditl (ijsplt) )
+      ALLOCATE( nldjtl (ijsplt) )
+      ALLOCATE( nleitl (ijsplt) )
+      ALLOCATE( nlejtl (ijsplt) )
+      ALLOCATE( nimpptl(ijsplt) )
+      ALLOCATE( njmpptl(ijsplt) )
+      ALLOCATE( nlcitl (ijsplt) )
+      ALLOCATE( nlcjtl (ijsplt) )
+      ALLOCATE( tra_ctl(jptra,ijsplt) )
+      ALLOCATE( ibonitl(ijsplt) )
+      ALLOCATE( ibonjtl(ijsplt) )
+
+      tra_ctl(:,:) = 0.e0           ! Initialization to zero
+
+      IF( lk_mpp ) THEN
+         sind = narea
+         eind = narea
+         clb_name = "('mpp.top.output_',I3.3)"
+         cl_run = 'MULTI processor run'
+         ! use indices for each area computed by mpp_init subroutine
+         nlditl(:) = nldit(:) 
+         nleitl(:) = nleit(:) 
+         nldjtl(:) = nldjt(:) 
+         nlejtl(:) = nlejt(:) 
+         !
+         nimpptl(:) = nimppt(:)
+         njmpptl(:) = njmppt(:)
+         !
+         nlcitl(:) = nlcit(:)
+         nlcjtl(:) = nlcjt(:)
+         !
+         ibonitl(:) = ibonit(:)
+         ibonjtl(:) = ibonjt(:)
+      ELSE
+         sind = 1
+         eind = ijsplt
+         clb_name = "('mono.top.output_',I3.3)"
+         cl_run   = 'MONO processor run '
+         ! compute indices for each area as done in mpp_init subroutine
+         CALL sub_dom
+      ENDIF
+
+      ALLOCATE( numid_trc(eind-sind+1) )
+
+      DO js = sind, eind
+         WRITE(clfile_out,FMT=clb_name) js-1
+         CALL ctlopn( numid_trc(js -narea + 1), clfile_out, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+            &         1, numout, .FALSE., 1 )
+         j_id = numid_trc(js -narea + 1)
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                 L O D Y C - I P S L'
+         WRITE(j_id,*) '                       N E M 0 '
+         WRITE(j_id,*) '            Ocean General Circulation Model'
+         WRITE(j_id,*) '               version TOP 1.0  (2005) '
+         WRITE(j_id,*)
+         WRITE(j_id,*) '                   PROC number: ', js
+         WRITE(j_id,*)
+         WRITE(j_id,FMT="(19x,a20)") cl_run
+
+         ! Print the SUM control indices
+         IF( .NOT. lsp_area )   THEN
+            IF ( lk_mpp )   THEN
+               nictls = nlditl(js) 
+               nictle = nleitl(js)
+               njctls = nldjtl(js)
+               njctle = nlejtl(js)
+            ELSE
+               nictls = nimpptl(js) + nlditl(js) - 1
+               nictle = nimpptl(js) + nleitl(js) - 1
+               njctls = njmpptl(js) + nldjtl(js) - 1
+               njctle = njmpptl(js) + nlejtl(js) - 1
+            ENDIF
+         ENDIF
+         WRITE(j_id,*) 
+         WRITE(j_id,*) 'prt_tra_ctl :  Sum control indices'
+         WRITE(j_id,*) '~~~~~~~'
+         WRITE(j_id,*)
+         WRITE(j_id,9000)'                                nlej   = ', nlejtl(js), '              '
+         WRITE(j_id,9000)'                  ------------- njctle = ', njctle, ' -------------'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9002)'           nictls = ', nictls,  '                           nictle = ', nictle
+         WRITE(j_id,9002)'           nldi   = ', nlditl(js),  '                           nlei   = ', nleitl(js)
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9001)'                  |                                       |'
+         WRITE(j_id,9004)'  njmpp  = ',njmpptl(js),'   ------------- njctls = ', njctls, ' -------------'
+         WRITE(j_id,9003)'           nimpp  = ', nimpptl(js), '        nldj   = ', nldjtl(js), '              '
+         WRITE(j_id,*)
+         WRITE(j_id,*)
+
+9000     FORMAT(a41,i4.4,a14)
+9001     FORMAT(a59)
+9002     FORMAT(a20,i4.4,a36,i3.3)
+9003     FORMAT(a20,i4.4,a17,i4.4)
+9004     FORMAT(a11,i4.4,a26,i4.4,a14)
+      END DO
+      !
+   END SUBROUTINE prt_ctl_trc_init
+
+
+   SUBROUTINE sub_dom
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sub_dom  ***
+      !!                    
+      !! ** Purpose :   Lay out the global domain over processors. 
+      !!                CAUTION: 
+      !!                This part has been extracted from the mpp_init
+      !!                subroutine and names of variables/arrays have been 
+      !!                slightly changed to avoid confusion but the computation
+      !!                is exactly the same. Any modification about indices of
+      !!                each sub-domain in the mppini.F90 module should be reported 
+      !!                here.
+      !!
+      !! ** Method  :   Global domain is distributed in smaller local domains.
+      !!                Periodic condition is a function of the local domain position
+      !!                (global boundary or neighbouring domain) and of the global
+      !!                periodic
+      !!                Type :         jperio global periodic condition
+      !!                               nperio local  periodic condition
+      !!
+      !! ** Action  : - set domain parameters
+      !!                    nimpp     : longitudinal index 
+      !!                    njmpp     : latitudinal  index
+      !!                    nperio    : lateral condition type 
+      !!                    narea     : number for local area
+      !!                    nlcil      : first dimension
+      !!                    nlcjl      : second dimension
+      !!                    nbondil    : mark for "east-west local boundary"
+      !!                    nbondjl    : mark for "north-south local boundary"
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, js               ! dummy loop indices
+      INTEGER ::   ii, ij                   ! temporary integers
+      INTEGER ::   irestil, irestjl         !    "          "
+      INTEGER ::   ijpi  , ijpj, nlcil      ! temporary logical unit
+      INTEGER ::   nlcjl , nbondil, nbondjl
+      INTEGER ::   nrecil, nrecjl, nldil, nleil, nldjl, nlejl
+      REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      INTEGER, DIMENSION(:,:), ALLOCATABLE ::   iimpptl, ijmpptl, ilcitl, ilcjtl   ! temporary workspace
+      !!----------------------------------------------------------------------
+
+      ! Dimension arrays for subdomains
+      ! -------------------------------
+      !  Computation of local domain sizes ilcitl() ilcjtl()
+      !  These dimensions depend on global sizes isplt,jsplt and jpiglo,jpjglo
+      !  The subdomains are squares leeser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap
+      !  array (cf. par_oce.F90).
+
+      ijpi = ( jpiglo-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
+      ijpj = ( jpjglo-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj
+
+      ALLOCATE( ilcitl (isplt,jsplt) )
+      ALLOCATE( ilcjtl (isplt,jsplt) )
+
+      nrecil  = 2 * jpreci
+      nrecjl  = 2 * jprecj
+      irestil = MOD( jpiglo - nrecil , isplt )
+      irestjl = MOD( jpjglo - nrecjl , jsplt )
+
+      IF(  irestil == 0 )   irestil = isplt
+      DO jj = 1, jsplt
+         DO ji = 1, irestil
+            ilcitl(ji,jj) = ijpi
+         END DO
+         DO ji = irestil+1, isplt
+            ilcitl(ji,jj) = ijpi -1
+         END DO
+      END DO
+      
+      IF( irestjl == 0 )   irestjl = jsplt
+      DO ji = 1, isplt
+         DO jj = 1, irestjl
+            ilcjtl(ji,jj) = ijpj
+         END DO
+         DO jj = irestjl+1, jsplt
+            ilcjtl(ji,jj) = ijpj -1
+         END DO
+      END DO
+      
+      zidom = nrecil
+      DO ji = 1, isplt
+         zidom = zidom + ilcitl(ji,1) - nrecil
+      END DO
+      
+      zjdom = nrecjl
+      DO jj = 1, jsplt
+         zjdom = zjdom + ilcjtl(1,jj) - nrecjl
+      END DO
+
+      ! Index arrays for subdomains
+      ! ---------------------------
+
+      ALLOCATE( iimpptl(isplt,jsplt) )
+      ALLOCATE( ijmpptl(isplt,jsplt) )
+      
+      iimpptl(:,:) = 1
+      ijmpptl(:,:) = 1
+      
+      IF( isplt > 1 ) THEN
+         DO jj = 1, jsplt
+            DO ji = 2, isplt
+               iimpptl(ji,jj) = iimpptl(ji-1,jj) + ilcitl(ji-1,jj) - nrecil
+            END DO
+         END DO
+      ENDIF
+
+      IF( jsplt > 1 ) THEN
+         DO jj = 2, jsplt
+            DO ji = 1, isplt
+               ijmpptl(ji,jj) = ijmpptl(ji,jj-1)+ilcjtl(ji,jj-1)-nrecjl
+            END DO
+         END DO
+      ENDIF
+      
+      ! Subdomain description
+      ! ---------------------
+
+      DO js = 1, ijsplt
+         ii = 1 + MOD( js-1, isplt )
+         ij = 1 + (js-1) / isplt
+         nimpptl(js) = iimpptl(ii,ij)
+         njmpptl(js) = ijmpptl(ii,ij)
+         nlcitl (js) = ilcitl (ii,ij)     
+         nlcil       = nlcitl (js)     
+         nlcjtl (js) = ilcjtl (ii,ij)     
+         nlcjl       = nlcjtl (js)
+         nbondjl = -1                                    ! general case
+         IF( js   >  isplt          )   nbondjl = 0      ! first row of processor
+         IF( js   >  (jsplt-1)*isplt )  nbondjl = 1     ! last  row of processor
+         IF( jsplt == 1             )   nbondjl = 2      ! one processor only in j-direction
+         ibonjtl(js) = nbondjl
+         
+         nbondil = 0                                     ! 
+         IF( MOD( js, isplt ) == 1 )   nbondil = -1      !
+         IF( MOD( js, isplt ) == 0 )   nbondil =  1      !
+         IF( isplt            == 1 )   nbondil =  2      ! one processor only in i-direction
+         ibonitl(js) = nbondil
+         
+         nldil =  1   + jpreci
+         nleil = nlcil - jpreci
+         IF( nbondil == -1 .OR. nbondil == 2 )   nldil = 1
+         IF( nbondil ==  1 .OR. nbondil == 2 )   nleil = nlcil
+         nldjl =  1   + jprecj
+         nlejl = nlcjl - jprecj
+         IF( nbondjl == -1 .OR. nbondjl == 2 )   nldjl = 1
+         IF( nbondjl ==  1 .OR. nbondjl == 2 )   nlejl = nlcjl
+         nlditl(js) = nldil
+         nleitl(js) = nleil
+         nldjtl(js) = nldjl
+         nlejtl(js) = nlejl
+      END DO
+
+      DEALLOCATE( iimpptl )
+      DEALLOCATE( ijmpptl )
+      DEALLOCATE( ilcitl )
+      DEALLOCATE( ilcjtl )
+      !
+   END SUBROUTINE sub_dom
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module :                                    NO passive tracer
+   !!----------------------------------------------------------------------
+#endif
+    
+   !!======================================================================
+END MODULE prtctl_trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/sms.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/sms.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/sms.F90	(revision 4536)
@@ -0,0 +1,43 @@
+MODULE sms
+   !!======================================================================
+   !!                        ***  sms  ***
+   !! passive tracers :   set the passive tracers variables
+   !!======================================================================
+   !! History :    -   !  2004-03  (C. Ethe)  Free form and module
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
+
+   IMPLICIT NONE
+   PUBLIC
+
+# if defined key_lobster
+   !!----------------------------------------------------------------------
+   !!   'key_lobster'                                     LOBSTER bio-model  
+   !!----------------------------------------------------------------------
+#  include "sms_lobster1.h90"
+
+# elif defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model                  
+   !!----------------------------------------------------------------------
+#  include "sms_pisces.h90"
+
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE sms
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/top_substitute.h90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/top_substitute.h90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/top_substitute.h90	(revision 4536)
@@ -0,0 +1,80 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  top_substitute.h90   ***
+   !!----------------------------------------------------------------------
+   !! ** purpose : Statement function file: to be include in all routines
+   !!              concerning passive tracer model 
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2004-03 (C. Ethe) Original code
+   !!             2.0  !  2007-12 (C. Ethe, G. Madec) new architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+    ! Lateral eddy diffusivity coefficient for passive tracer:
+    ! ========================================================
+#if defined key_traldf_c3d || defined key_off_degrad
+!   'key_traldf_c3d' :                 aht: 3D coefficient
+#       define fsahtrt(i,j,k)  trcrat * ahtt(i,j,k)
+#       define fsahtru(i,j,k)  trcrat * ahtu(i,j,k)
+#       define fsahtrv(i,j,k)  trcrat * ahtv(i,j,k)
+#       define fsahtrw(i,j,k)  trcrat * ahtw(i,j,k)
+#elif defined key_traldf_c2d
+!   'key_traldf_c2d' :                 aht: 2D coefficient
+#       define fsahtrt(i,j,k)  trcrat * ahtt(i,j)
+#       define fsahtru(i,j,k)  trcrat * ahtu(i,j)
+#       define fsahtrv(i,j,k)  trcrat * ahtv(i,j)
+#       define fsahtrw(i,j,k)  trcrat * ahtw(i,j)
+#elif defined key_traldf_c1d
+!   'key_traldf_c1d' :                 aht: 1D coefficient
+#       define fsahtrt(i,j,k)  trcrat * ahtt(k)
+#       define fsahtru(i,j,k)  trcrat * ahtu(k)
+#       define fsahtrv(i,j,k)  trcrat * ahtv(k)
+#       define fsahtrw(i,j,k)  trcrat * ahtw(k)
+#else
+!   Default option :             aht: Constant coefficient
+#       define fsahtrt(i,j,k)  ahtrc0
+#       define fsahtru(i,j,k)  ahtrc0
+#       define fsahtrv(i,j,k)  ahtrc0
+#       define fsahtrw(i,j,k)  ahtrc0
+#endif
+
+    ! Eddy induced velocity  coefficient for passive tracer:
+    ! ========================================================
+#if defined key_traldf_c3d || defined key_off_degrad
+!   'key_traldf_c3d' :                 eiv: 3D coefficient
+#       define fsaeitru(i,j,k)  trcrat * aeiu(i,j,k)
+#       define fsaeitrv(i,j,k)  trcrat * aeiv(i,j,k)
+#       define fsaeitrw(i,j,k)  trcrat * aeiw(i,j,k)
+#elif defined key_traldf_c2d
+!   'key_traldf_c2d' :                 eiv: 2D coefficient
+#       define fsaeitru(i,j,k)  trcrat * aeiu(i,j)
+#       define fsaeitrv(i,j,k)  trcrat * aeiv(i,j)
+#       define fsaeitrw(i,j,k)  trcrat * aeiw(i,j)
+#elif defined key_traldf_c1d
+!   'key_traldf_c1d' :                 eiv: 1D coefficient
+#       define fsaeitru(i,j,k)  trcrat * aeiu(k)
+#       define fsaeitrv(i,j,k)  trcrat * aeiv(k)
+#       define fsaeitrw(i,j,k)  trcrat * aeiw(k)
+#else
+!   Default option :             eiv: Constant coefficient
+#       define fsaeitru(i,j,k)  aeiv0
+#       define fsaeitrv(i,j,k)  aeiv0
+#       define fsaeitrw(i,j,k)  aeiv0
+#endif
+    ! mixing for passive tracer:
+    ! ========================================================
+#if defined key_trc_zdfddm
+!   'key_trc_zdfddm' :    avs 
+#       define fstravs(i,j,k)   avs(i,j,k)
+#else
+!   Defautl option :   avs = avt
+#       define fstravs(i,j,k)   avt(i,j,k)
+#endif
+
+! ========================================================
+#include "domzgr_substitute.h90"
+#include "ldfeiv_substitute.h90"
+#include "ldftra_substitute.h90"
+#include "vectopt_loop_substitute.h90"
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trc.F90	(revision 4536)
@@ -0,0 +1,148 @@
+MODULE trc
+   !!======================================================================
+   !!                      ***  MODULE  trc  ***
+   !! Passive tracers   :  module for tracers defined
+   !!======================================================================
+   !! History :    -   !  1996-01  (M. Levy)  Original code
+   !!              -   !  1999-07  (M. Levy)  for LOBSTER1 or NPZD model
+   !!              -   !  2000-04  (O. Aumont, M.A. Foujols)  HAMOCC3 and P3ZD
+   !!             1.0  !  2004-03  (C. Ethe)  Free form and module
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
+   
+   IMPLICIT NONE
+   PUBLIC
+
+   !! passive tracers names and units (read in namelist)
+   !! --------------------------------------------------
+   CHARACTER(len=12), PUBLIC, DIMENSION(jptra) ::   ctrcnm     !: tracer name 
+   CHARACTER(len=12), PUBLIC, DIMENSION(jptra) ::   ctrcun     !: tracer unit
+   CHARACTER(len=80), PUBLIC, DIMENSION(jptra) ::   ctrcnl     !: tracer long name 
+   
+   
+   !! parameters for the control of passive tracers
+   !! --------------------------------------------------
+   INTEGER, PUBLIC                   ::   numnat   !: the number of the passive tracer NAMELIST
+   LOGICAL, PUBLIC, DIMENSION(jptra) ::   lutini   !:  initialisation from FILE or not (NAMELIST)
+   INTEGER, PUBLIC, DIMENSION(jptra) ::   nutini   !: FORTRAN LOGICAL UNIT for initialisation file
+
+   !! passive tracers fields (before,now,after)
+   !! --------------------------------------------------
+   REAL(wp), PUBLIC ::   trai       !: initial total tracer
+   REAL(wp), PUBLIC ::   areatot    !: total volume 
+
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk,jptra) ::   trn   !: traceur concentration for actual time step
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk,jptra) ::   tra   !: traceur concentration for next time step
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk,jptra) ::   trb   !: traceur concentration for before time step
+
+
+   !! numerical parameter (NAMELIST)
+   !! --------------------------------------------------
+   REAL(wp), PUBLIC ::   rsc    !: tuning coefficient for anti-diffusion
+   REAL(wp), PUBLIC ::   rtrn   !: value for truncation
+
+   !! namelist parameters
+   !! --------------------------------------------------
+   INTEGER , PUBLIC ::   ncortrc     !: number of corrective phases
+   INTEGER , PUBLIC ::   ndttrc      !: frequency of step on passive tracers
+   INTEGER , PUBLIC ::   nittrc000   !: first time step of passive tracers model  
+   LOGICAL , PUBLIC ::   crosster    !: logical if true computes crossterms
+
+
+   !! isopycnal scheme for passive tracers
+   !! ------------------------------------  
+   REAL(wp), PUBLIC ::   ahtrb0     !: background diffusivity coefficient for passive tracer (m2/s)
+   REAL(wp), PUBLIC ::   trcrat     !: ratio between passive and active tracer coeff for diffusion
+   REAL(wp), PUBLIC ::   ahtrc0     !: horizontal eddy diffusivity for passive tracers (m2/s)
+   REAL(wp), PUBLIC ::   aeivtr0    !: eddy induced velocity coefficient (m2/s)
+   
+   
+   !! passive tracers restart (input and output)
+   !! ------------------------------------------  
+   LOGICAL , PUBLIC ::   lrsttr     !: boolean term for restart i/o for passive tracers (namelist)
+   INTEGER , PUBLIC ::   nutwrs     !: output FILE for passive tracers restart
+   INTEGER , PUBLIC ::   nutrst     !: logical unit for restart FILE for passive tracers
+   INTEGER , PUBLIC ::   nrsttr     !: control of the time step ( 0 or 1 ) for pass. tr.
+   
+   
+   !! interpolated gradient
+   !!--------------------------------------------------  
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jptra) ::   gtru   !: horizontal gradient at u-points at bottom ocean level
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jptra) ::   gtrv   !: horizontal gradient at v-points at bottom ocean level
+
+   
+# if defined key_trcldf_eiv && defined key_diaeiv
+   !! The three component of the eddy induced velocity
+   !! --------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk) ::   u_trc_eiv   !: u-eiv (m/s)
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk) ::   v_trc_eiv   !: v-eiv (m/s)
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk) ::   w_trc_eiv   !: w-eiv (m/s)
+# endif
+   
+   
+   !! information for outputs
+   !! --------------------------------------------------
+   INTEGER , PUBLIC ::   nwritetrc   !: time step frequency for concentration outputs (namelist)
+   
+# if defined key_trc_diaadd
+   !! additional 2D/3D outputs namelist
+   !! --------------------------------------------------
+   CHARACTER(len= 8), PUBLIC, DIMENSION (jpdia2d) ::   ctrc2d   !: 2d output field name
+   CHARACTER(len= 8), PUBLIC, DIMENSION (jpdia2d) ::   ctrc2u   !: 2d output field unit   
+   CHARACTER(len= 8), PUBLIC, DIMENSION (jpdia3d) ::   ctrc3d   !: 3d output field name
+   CHARACTER(len= 8), PUBLIC, DIMENSION (jpdia3d) ::   ctrc3u   !: 3d output field unit
+   CHARACTER(len=80), PUBLIC, DIMENSION (jpdia2d) ::   ctrc2l   !: 2d output field long name
+   CHARACTER(len=80), PUBLIC, DIMENSION (jpdia3d) ::   ctrc3l   !: 3d output field long name
+   
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,    jpdia2d) ::   trc2d   !:  additional 2d outputs  
+   REAL(wp), PUBLIC, DIMENSION (jpi,jpj,jpk,jpdia3d) ::   trc3d   !:  additional 3d outputs  
+   
+   
+   !! netcdf files and index common
+   !! --------------------------------------------------
+   INTEGER , PUBLIC ::   nwriteadd     !: frequency of additional arrays outputs(namelist)
+# endif
+   
+# if defined key_trc_diatrd
+   
+   !!  non conservative trends (biological, ...)
+   !! --------------------------------------------------
+   LOGICAL, PUBLIC, DIMENSION (jptra) ::   luttrd   !: large trends diagnostic to write or not (namelist)
+   
+   !!  Advection-diffusion trends
+   !! --------------------------------------------------
+   REAL(wp), PUBLIC, DIMENSION(:,:,:,:,:), ALLOCATABLE ::   trtrd   !: trends of the tracer equations
+   
+   INTEGER, PUBLIC, DIMENSION(jptra) :: ikeep ! indice of tracer for which dyn trends are stored
+   INTEGER, PUBLIC                   :: nkeep ! number of tracers for which dyn trends are stored 
+   !                                          ! (used to allocate trtrd buffer)
+
+   !! netcdf files and index common
+   !! --------------------------------------------------
+   INTEGER , PUBLIC ::   nwritetrd   !: frequency of additional arrays outputs(namelist)
+   
+# endif 
+   
+   !! passive tracers data read and at given time_step
+   !! --------------------------------------------------
+# if defined key_dtatrc
+   INTEGER , PUBLIC, DIMENSION(jptra) ::   numtr   !: logical unit for passive tracers data
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE trc
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcctl.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcctl.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcctl.F90	(revision 4536)
@@ -0,0 +1,119 @@
+MODULE trcctl
+   !!======================================================================
+   !!                         ***  MODULE trcctl  ***
+   !! TOP :   control the cpp options, files and namelist values of a run
+   !!======================================================================
+   !! History :   1.0  !  2005-03 (O. Aumont, A. El Moussaoui) original code
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_ctl    : control the cpp options, files and namelist values
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE sms
+   USE trctrp_ctl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_ctl      ! called by ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_ctl  ***
+      !!
+      !! ** Purpose :   control the cpp options, namelist and files 
+      !!              we use IF/ENDIF inside #IF defined option-cpp
+      !!              FILE name must not exceed 21 characters
+      !!----------------------------------------------------------------------
+      INTEGER ::   istop, jn
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ctl :   passive tracer option'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+
+      istop = 0      ! initialise to zero
+
+      ! restart for passive tracer (input)
+      IF( lrsttr ) THEN
+         IF(lwp) WRITE(numout,*) '       READ a restart FILE for passive tracer'
+         IF(lwp) WRITE(numout,*) ' '
+      ELSE
+         IF(lwp) WRITE(numout,*) '       no restart FILE'
+         IF(lwp) WRITE(numout,*)
+         DO jn = 1, jptra
+            IF( lutini(jn) ) THEN      ! OPEN input FILE only IF lutini(jn) is true
+               IF(lwp) WRITE(numout,*)  &
+                  '       READ an initial FILE  for passive tracer number :', jn, ' traceur : ', ctrcnm(jn) 
+            END IF
+         END DO
+      ENDIF
+
+      ! Don't USE non penetrative convective mixing option
+      ! it's not implemented for passive tracer
+      IF( ln_zdfnpc ) THEN
+         IF(lwp) WRITE (numout,*) ' ===>>>> : w a r n i n g '
+         IF(lwp) WRITE (numout,*) ' =======   ============= '
+         IF(lwp) WRITE (numout,*) ' STOP, this sheme is not implemented'
+         IF(lwp) WRITE (numout,*) ' in passive tracer model:'
+         IF(lwp) WRITE (numout,*) ' non penetrative convect. mixing scheme'
+         istop = istop + 1
+      ENDIF
+
+      ! transport scheme option
+      CALL trc_trp_ctl
+
+      ! SMS model
+      IF(lwp) WRITE(numout,*) '  '
+      IF(lwp) WRITE(numout,*) '       Source/Sink model option'
+      IF(lwp) WRITE(numout,*) '  '
+
+# if defined key_lobster
+#   include "trcctl.lobster1.h90"
+
+# elif defined key_pisces
+#   include "trcctl.pisces.h90"
+
+# elif defined key_cfc
+#   include "trcctl.cfc.h90"
+
+# else
+      IF(lwp) WRITE (numout,*) '       No Source/Sink '
+      IF(lwp) WRITE (numout,*)
+#endif
+
+      ! E r r o r  control
+      ! ------------------
+      IF( istop > 0  ) THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) istop,' E R R O R found : we stop'
+         IF(lwp)WRITE(numout,*) '  **************************'
+         IF(lwp)WRITE(numout,*)
+         STOP 'trcctl'
+      ENDIF
+      !
+   END SUBROUTINE trc_ctl
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ctl                      ! Dummy routine
+   END SUBROUTINE trc_ctl
+#endif
+
+   !!======================================================================
+END MODULE trcctl
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdia.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdia.F90	(revision 4536)
@@ -0,0 +1,64 @@
+MODULE trcdia
+   !!======================================================================
+   !!                       *** MODULE trcdia ***
+   !! TOP :   Output of passive tracers
+   !!======================================================================
+   !! History :   1.0  !  2005-03 (O. Aumont, A. El Moussaoui) original code
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_dia    :  output passive tracer fields
+   !!----------------------------------------------------------------------
+   USE trcdit
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_dia      ! called by ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_dia( kt, kindic )  
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_dia  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt, kindic
+      !!---------------------------------------------------------------------
+      
+      CALL trcdit_wr( kt, kindic )      ! outputs for tracer concentration
+
+# if defined key_trc_diatrd
+      CALL trcdid_wr( kt, kindic )      ! outputs for dynamical trends
+# endif
+
+# if defined key_trc_diaadd
+      CALL trcdii_wr( kt, kindic )      ! outputs for additional arrays
+# endif
+
+# if defined key_trc_diabio
+      CALL trcdib_wr( kt, kindic )      ! outputs for biological trends
+# endif
+      !
+   END SUBROUTINE trc_dia
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_dia                      ! Empty routine   
+   END SUBROUTINE trc_dia   
+#endif
+
+   !!======================================================================
+END MODULE trcdia
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdit.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdit.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdit.F90	(revision 4536)
@@ -0,0 +1,743 @@
+MODULE trcdit
+   !!======================================================================
+   !!                       *** MODULE trcdit ***
+   !! TOP :   Output of passive tracers
+   !! O.Aumont and A.El Moussaoui 03/05 F90 
+   !!======================================================================
+   !! History :    -   !  1995-01 (M. Levy)  Original code
+   !!              -   !  1998-01 (C. Levy) NETCDF format using ioipsl interface
+   !!              -   !  1999-01 (M.A. Foujols) adapted for passive tracer
+   !!              -   !  1999-09 (M.A. Foujols) split into three parts
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !! trcdit_wr   :
+   !! trcdid_wr   :
+   !! trcdii_wr   :
+   !! trcdib_wr   : 
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE dianam    ! build name of file (routine)
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp
+   USE ioipsl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trcdit_wr      ! caller in trcdia.F90
+   PUBLIC trcdid_wr      ! caller in trcdia.F90
+   PUBLIC trcdii_wr      ! caller in trcdia.F90
+   PUBLIC trcdib_wr      ! caller in trcdia.F90
+
+   INTEGER  ::   nit5      !: id for tracer output file
+   INTEGER  ::   ndepit5   !: id for depth mesh
+   INTEGER  ::   nhorit5   !: id for horizontal mesh
+   INTEGER  ::   ndimt50   !: number of ocean points in index array
+   INTEGER  ::   ndimt51   !: number of ocean points in index array
+   REAL(wp) ::   zjulian   !: ????   not DOCTOR !
+   INTEGER , DIMENSION (jpij*jpk) ::   ndext50   !: integer arrays for ocean 3D index
+   INTEGER , DIMENSION (jpij)     ::   ndext51   !: integer arrays for ocean surface index
+# if defined key_trc_diaadd
+   INTEGER  ::   nitd      !: id for additional array output file
+   INTEGER  ::   ndepitd   !: id for depth mesh
+   INTEGER  ::   nhoritd   !: id for horizontal mesh
+# endif
+# if defined key_trc_diatrd
+   INTEGER , DIMENSION (jptra) ::   nit6      !: id for additional array output file
+   INTEGER , DIMENSION (jptra) ::   ndepit6   !: id for depth mesh
+   INTEGER , DIMENSION (jptra) ::   nhorit6   !: id for horizontal mesh
+# endif
+# if defined key_trc_diabio
+   INTEGER  ::   ndepitb   !:  id for depth mesh
+   INTEGER  ::   nhoritb   !:  id for horizontal mesh
+# endif
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+      SUBROUTINE trcdit_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdit_wr  ***
+      !!
+      !! ** Purpose :   Standard output of passive tracer : concentration fields
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      INTEGER ::   jn
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) :: clhstnam, clop
+      CHARACTER (len=20) :: cltra, cltrau
+      CHARACTER (len=80) :: cltral
+      REAL(wp) :: zsto, zout, zdt
+      INTEGER  :: iimi, iima, ijmi, ijma, ipk, it
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.                  ! change it to true for more control print
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+# if defined key_diainstant
+      zsto = nwritetrc * rdt
+      clop = 'inst(only(x))'
+# else
+      zsto = zdt
+      clop = 'ave(only(x))'
+# endif
+      zout = nwritetrc * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define NETCDF files and fields at beginning of first time step
+      ! --------------------------------------------------------------
+
+      IF(ll_print)WRITE(numout,*)'trcdit_wr kt=',kt,' kindic ',kindic
+      
+      IF( kt == nittrc000 ) THEN
+
+         ! Compute julian date from starting date of the run
+         CALL ymds2ju( nyear, nmonth, nday, 0.0, zjulian )
+         IF(lwp)WRITE(numout,*)' '  
+         IF(lwp)WRITE(numout,*)' Date 0 used :', nittrc000                         &
+            &                 ,' YEAR ', nyear, ' MONTH ', nmonth, ' DAY ', nday   &
+            &                 ,'Julian day : ', zjulian    
+         IF(lwp) WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
+            &                    ' limit storage in depth = ', ipk
+
+
+! Define the NETCDF files for passive tracer concentration
+
+         CALL dia_nam( clhstnam, nwritetrc, 'ptrc_T' )
+         IF(lwp)WRITE(numout,*)" Name of NETCDF file ", clhstnam
+! Horizontal grid : glamt and gphit
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,     &
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         & 
+            &          0, zjulian, zdt, nhorit5, nit5 , domain_id=nidom)
+! Vertical grid for tracer : gdept
+         CALL histvert( nit5, 'deptht', 'Vertical T levels', &
+            &            'm', ipk, gdept_0, ndepit5)
+
+! Index of ocean points in 3D and 2D (surface)
+         CALL wheneq( jpi*jpj*ipk,tmask,1,1.,ndext50,ndimt50 )
+         CALL wheneq( jpi*jpj,tmask,1,1.,ndext51,ndimt51 )
+
+! Declare all the output fields as NETCDF variables
+
+! tracer concentrations
+         DO jn = 1, jptra
+           cltra  = ctrcnm(jn)   ! short title for tracer
+           cltral = ctrcnl(jn)   ! long title for tracer
+           cltrau = ctrcun(jn)   ! UNIT for tracer
+           CALL histdef( nit5, cltra, cltral, cltrau, jpi, jpj, nhorit5,  &
+         &               ipk, 1, ipk,  ndepit5, 32, clop, zsto, zout) 
+         END DO           
+
+         ! end netcdf files header
+         CALL histend( nit5 )
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdit_wr'
+         IF( ll_print )   CALL FLUSH(numout )
+
+      ENDIF
+
+      ! Start writing the tracer concentrations
+      ! ---------------------------------------
+
+      IF( lwp .AND. MOD( kt, nwritetrc ) == 0 ) THEN
+         WRITE(numout,*) 'trcdit_wr : write NetCDF passive tracer concentrations at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~~~~ '
+      ENDIF
+
+      DO jn = 1, jptra
+         cltra = ctrcnm(jn)      ! short title for tracer
+         CALL histwrite( nit5, cltra, it, trn(:,:,:,jn), ndimt50, ndext50 )
+      END DO 
+
+      ! synchronise file
+      IF( MOD( kt, nwritetrc ) == 0 .OR. kindic < 0 )   CALL histsync( nit5 )
+
+
+      ! close the file 
+      ! --------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nit5 )
+      !
+   END SUBROUTINE trcdit_wr
+
+# if defined key_trc_diatrd
+
+   SUBROUTINE trcdid_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdid_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : advection-diffusion trends
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      CHARACTER (len=10) ::   csuff
+      INTEGER  ::   jn, jl
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! 0. Initialisation
+      ! -----------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+      !
+      ! Define frequency of output and means
+      zdt = rdt
+#  if defined key_diainstant
+      zsto = nwritetrd * rdt
+      clop = 'inst(only(x))'
+#  else
+      zsto = zdt
+      clop = 'ave(only(x))'
+#  endif
+      zout = nwritetrd * zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define the NETCDF files (one per tracer)
+      IF( ll_print ) WRITE(numout,*) 'trcdid kt=', kt, ' kindic ', kindic
+      
+      
+      IF( kt == nittrc000 ) THEN
+
+         DO jn = 1, jptra
+            !
+            IF( luttrd(jn) ) THEN      ! Define the file for dynamical trends - one per each tracer IF required
+
+               IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
+                   &                   ' limit storage in depth = ', ipk
+               csuff='DY_'//ctrcnm(jn)
+               CALL dia_nam( clhstnam, nwritetrd, csuff )
+               IF(lwp)WRITE(numout,*)   " Name of NETCDF file for dynamical trends",   &
+                  &                     " of tracer number : ",clhstnam
+
+               CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,       &
+                  &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,   &
+                  &          0, zjulian, rdt, nhorit6(jn),           &
+                  &          nit6(jn) , domain_id=nidom )
+
+               ! Vertical grid for tracer trend - one per each tracer IF needed
+               CALL histvert( nit6(jn), 'deptht', 'Vertical T levels',   &
+                  &           'm', ipk, gdept_0, ndepit6(jn) ) 
+             END IF
+          END DO
+
+          ! Declare all the output fields as NETCDF variables
+
+          ! trends for tracer concentrations
+          DO jn = 1, jptra
+            IF( luttrd(jn) ) THEN
+                DO jl = 1, jpdiatrc
+                  IF( jl == 1 ) THEN
+                      ! short and long title for x advection for tracer
+                      WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 2 ) THEN
+                      ! short and long title for y advection for tracer
+                      WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 3 ) THEN
+                      ! short and long title for Z advection for tracer
+                      WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z advective trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 4 ) THEN
+                      ! short and long title for X diffusion for tracer
+                      WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 5 ) THEN
+                      ! short and long title for Y diffusion for tracer
+                      WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+                  IF( jl == 6 ) THEN
+                      ! short and long title for Z diffusion for tracer
+                      WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z diffusion trend for ",58a)')  &
+                         &      ctrcnl(jn)(1:58)
+                  END IF
+# if defined key_trc_ldfeiv
+                  IF( jl == 7 ) THEN
+                      ! short and long title for x gent velocity for tracer
+                      WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("X gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+                  IF( jl == 8 ) THEN
+                      ! short and long title for y gent velocity for tracer
+                      WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Y gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+                  IF( jl == 9 ) THEN
+                      ! short and long title for Z gent velocity for tracer
+                      WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Z gent velocity trend for ",53a)')  &
+                         &      ctrcnl(jn)(1:53)
+                  END IF
+# endif
+# if defined key_trcdmp
+                  IF( jl == jpdiatrc - 1 ) THEN
+                      ! last trends for tracer damping : short and long title
+                      WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Tracer damping trend for ",55a)')  &
+                         &      ctrcnl(jn)(1:55)
+                  END IF
+# endif
+                  IF( jl == jpdiatrc ) THEN
+                      ! last trends for tracer damping : short and long title
+                      WRITE (cltra,'("SBC_",16a)') ctrcnm(jn)
+                      WRITE (cltral,'("Surface boundary flux ",58a)')  &
+                      &      ctrcnl(jn)(1:58)
+                  END IF
+
+                  CALL FLUSH( numout )
+                  cltrau = ctrcun(jn)      ! UNIT for tracer /trends
+                  CALL histdef( nit6(jn), cltra, cltral, cltrau, jpi,jpj,  &
+                     &          nhorit6(jn), ipk, 1, ipk,  ndepit6(jn), 32, clop ,  &
+                     &          zsto,zout )
+               END DO
+            END IF
+         END DO
+
+         ! CLOSE netcdf Files
+          DO jn = 1, jptra
+             IF( luttrd(jn) )   CALL histend( nit6(jn) )
+          END DO
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdid'
+         IF(ll_print) CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! SOME diagnostics to DO first time
+
+      ! Start writing data
+      ! ---------------------
+
+      ! trends for tracer concentrations
+
+      IF( lwp .AND. MOD( kt, nwritetrd ) == 0 ) THEN
+         WRITE(numout,*) 'trcdid_wr : write NetCDF dynamical trends at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      DO jn = 1, jptra
+         IF( luttrd(jn) ) THEN
+            DO jl = 1, jpdiatrc
+               ! short titles 
+               IF( jl == 1)   WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)      ! x advection for tracer
+               IF( jl == 2)   WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)      ! z advection for tracer
+               IF( jl == 3)   WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)      ! z advection for tracer
+               IF( jl == 4)   WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)      ! x diffusion for tracer
+               IF( jl == 5)   WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)      ! y diffusion for tracer
+               IF( jl == 6)   WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)      ! z diffusion for tracer
+# if defined key_trcldf_eiv
+               IF( jl == 7)   WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)      ! x gent velocity for tracer
+               IF( jl == 8)   WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)      ! y gent velocity for tracer
+               IF( jl == 9)   WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)      ! z gent velocity for tracer
+# endif
+# if defined key_trcdmp
+               IF( jl == jpdiatrc - 1 )   WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)      ! damping
+# endif
+               IF( jl == jpdiatrc )   WRITE (cltra,'("SBC_",a)') ctrcnm(jn)      ! surface boundary conditions
+               !
+               CALL histwrite(nit6(jn), cltra, it, trtrd(:,:,:,ikeep(jn),jl)   &
+                  &          ,ndimt50, ndext50)
+            END DO
+         END IF
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwritetrd ) == 0 .OR. kindic < 0 ) THEN
+         DO jn = 1, jptra
+            IF (luttrd(jn))   CALL histsync( nit6(jn) )
+         END DO
+      ENDIF
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 ) THEN
+         DO jn = 1, jptra
+            IF( luttrd(jn) )   CALL histclo( nit6(jn) )
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE trcdid_wr
+
+# else
+   SUBROUTINE trcdid_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+      WRITE(*,*) 'trcdid_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdid_wr
+# endif
+
+#    if defined key_top && defined key_trc_diaadd
+
+   SUBROUTINE trcdii_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdii_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : additional 2D and 3D arrays
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      INTEGER  ::   jn
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+      !
+      ! Define frequency of output and means
+      zdt = rdt
+#  if defined key_diainstant
+      zsto=nwriteadd*zdt
+      clop='inst(only(x))'
+#  else
+      zsto=zdt
+      clop='ave(only(x))'
+#  endif
+      zout=nwriteadd*zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! 1. Define NETCDF files and fields at beginning of first time step
+      ! -----------------------------------------------------------------
+
+      IF( ll_print ) WRITE(numout,*) 'trcdii_wr kt=', kt, ' kindic ', kindic
+
+      IF( kt == nittrc000 ) THEN
+
+         ! Define the NETCDF files for additional arrays : 2D or 3D
+
+         ! Define the T grid file for tracer auxiliary files
+
+         CALL dia_nam( clhstnam, nwrite, 'diad_T' )
+         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
+
+         ! Define a netcdf FILE for 2d and 3d arrays
+
+         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,             &
+            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
+            &          0, zjulian, zdt, nhoritd, nitd , domain_id=nidom )
+
+         ! Vertical grid for 2d and 3d arrays
+
+         CALL histvert( nitd, 'deptht', 'Vertical T levels',   &
+            &           'm', ipk, gdept_0, ndepitd)
+
+         ! Declare all the output fields as NETCDF variables
+
+         ! more 3D horizontal arrays
+         DO jn = 1, jpdia3d
+            cltra  = ctrc3d(jn)   ! short title for 3D diagnostic
+            cltral = ctrc3l(jn)   ! long title for 3D diagnostic
+            cltrau = ctrc3u(jn)   ! UNIT for 3D diagnostic
+            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,   &
+               &          ipk, 1, ipk,  ndepitd, 32, clop, zsto, zout )
+         END DO
+
+         ! more 2D horizontal arrays
+         DO jn = 1, jpdia2d
+            cltra=ctrc2d(jn)    ! short title for 2D diagnostic
+            cltral=ctrc2l(jn)   ! long title for 2D diagnostic
+            cltrau=ctrc2u(jn)   ! UNIT for 2D diagnostic
+            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,  &
+               &          1, 1, 1,  -99, 32, clop, zsto, zout )
+         END DO
+
+         ! TODO: more 2D vertical sections arrays : I or J indice fixed
+
+         ! CLOSE netcdf Files
+         CALL histend( nitd )
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdii_wr'
+         IF( ll_print )   CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! 2. Start writing data
+      ! ---------------------
+
+      IF( lwp .AND. MOD( kt, nwriteadd ) == 0 ) THEN
+         WRITE(numout,*) 'trcdii_wr : write NetCDF additional arrays at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      ! more 3D horizontal arrays
+      DO jn = 1, jpdia3d
+         cltra = ctrc3d(jn)   ! short title for 3D diagnostic
+         CALL histwrite( nitd, cltra, it, trc3d(:,:,:,jn), ndimt50  &
+            &           ,ndext50)
+      END DO
+
+      ! more 2D horizontal arrays
+      DO jn = 1, jpdia2d
+         cltra = ctrc2d(jn)   ! short title for 2D diagnostic
+         CALL histwrite(nitd, cltra, it, trc2d(:,:,jn), ndimt51    &
+            &   ,ndext51)
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwriteadd ) == 0 .OR. kindic < 0 )   CALL histsync( nitd )
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo(nitd)
+      !
+END SUBROUTINE trcdii_wr
+
+# else
+   SUBROUTINE trcdii_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) :: kt, kindic
+      WRITE(*,*) 'trcdii_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdii_wr
+# endif
+
+# if defined key_trc_diabio
+
+   SUBROUTINE trcdib_wr( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trcdib_wr  ***
+      !!
+      !! ** Purpose :   output of passive tracer : biological fields
+      !!
+      !! ** Method  :   At the beginning of the first time step (nit000), define all
+      !!             the NETCDF files and fields for concentration of passive tracer
+      !!
+      !!        At each time step call histdef to compute the mean if necessary
+      !!        Each nwritetrc time step, output the instantaneous or mean fields
+      !!
+      !!        IF kindic <0, output of fields before the model interruption.
+      !!        IF kindic =0, time step loop
+      !!        IF kindic >0, output of fields before the time step loop
+      !!----------------------------------------------------------------------
+      USE sms
+      !!
+      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
+      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
+      !!
+      LOGICAL ::   ll_print = .FALSE.
+      CHARACTER (len=40) ::   clhstnam, clop
+      CHARACTER (len=20) ::   cltra, cltrau
+      CHARACTER (len=80) ::   cltral
+      INTEGER  ::   ji, jj, jk, jn
+      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it
+      REAL(wp) ::   zsto, zout, zdt
+      !!----------------------------------------------------------------------
+
+      ! Initialisation
+      ! --------------
+
+      ! local variable for debugging
+      ll_print = .FALSE.
+      ll_print = ll_print .AND. lwp
+
+      ! Define frequency of output and means
+      zdt = rdt
+#        if defined key_diainstant
+      zsto=nwritebio*zdt
+      clop='inst(only(x))'
+#        else
+      zsto=zdt
+      clop='ave(only(x))'
+#        endif
+      zout=nwritebio*zdt
+
+      ! Define indices of the horizontal output zoom and vertical limit storage      iimi = 1      ;      iima = jpi
+      iimi = 1      ;      iima = jpi
+      ijmi = 1      ;      ijma = jpj
+      ipk = jpk
+
+      ! define time axis
+      it = kt - nittrc000 + 1
+
+      ! Define NETCDF files and fields at beginning of first time step
+      ! --------------------------------------------------------------
+
+      IF(ll_print) WRITE(numout,*)'trcdib_wr kt=',kt,' kindic ',kindic
+
+      IF( kt == nittrc000 ) THEN
+
+         ! Define the NETCDF files for biological trends
+
+         CALL dia_nam(clhstnam,nwrite,'biolog')
+         IF(lwp)WRITE(numout,*) " Name of NETCDF file for biological trends ", clhstnam
+         ! Horizontal grid : glamt and gphit
+         CALL histbeg(clhstnam, jpi, glamt, jpj, gphit,      &
+            &    iimi, iima-iimi+1, ijmi, ijma-ijmi+1,          &
+            &    0, zjulian, rdt, nhoritb, nitb , domain_id=nidom)
+         ! Vertical grid for biological trends
+         CALL histvert(nitb, 'deptht', 'Vertical T levels',  &
+            &    'm', ipk, gdept_0, ndepitb)
+
+         ! Declare all the output fields as NETCDF variables
+         ! biological trends
+         DO jn = 1, jpdiabio
+            cltra  = ctrbio(jn)   ! short title for biological diagnostic
+            cltral = ctrbil(jn)   ! long title for biological diagnostic
+            cltrau = ctrbiu(jn)   ! UNIT for biological diagnostic
+            CALL histdef(nitb, cltra, cltral, cltrau, jpi, jpj, nhoritb,  &
+               &         ipk, 1, ipk,  ndepitb, 32, clop, zsto, zout)
+         END DO
+
+         ! CLOSE netcdf Files
+          CALL histend(nitb)
+
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdib_wr'
+         IF(ll_print) CALL FLUSH(numout )
+         !
+      ENDIF
+
+      ! Start writing data
+      ! ------------------
+
+      ! biological trends
+      IF( lwp .AND. MOD( kt, nwritebio ) == 0 ) THEN
+         WRITE(numout,*) 'trcdit_wr : write NetCDF biological trends at ', kt, 'time-step'
+         WRITE(numout,*) '~~~~~~ '
+      ENDIF
+
+      DO jn = 1, jpdiabio
+         cltra=ctrbio(jn)  ! short title for biological diagnostic
+         CALL histwrite(nitb, cltra, it, trbio(:,:,:,jn), ndimt50,ndext50)
+      END DO
+
+      ! synchronise FILE
+      IF( MOD( kt, nwritebio ) == 0 .OR. kindic < 0 )   CALL histsync( nitb )
+
+      ! Closing all files
+      ! -----------------
+      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nitb )
+      !
+   END SUBROUTINE trcdib_wr
+
+# else
+   SUBROUTINE trcdib_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+      WRITE(*,*) 'trcdib_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdib_wr
+# endif 
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trcdit_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+      WRITE(*,*) 'trcdit_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdit_wr
+   SUBROUTINE trcdid_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+      WRITE(*,*) 'trcdid_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdid_wr
+   SUBROUTINE trcdii_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) :: kt, kindic
+      WRITE(*,*) 'trcdii_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdii_wr
+   SUBROUTINE trcdib_wr( kt, kindic )                      ! Dummy routine
+      INTEGER, INTENT ( in ) ::   kt, kindic
+      WRITE(*,*) 'trcdib_wr: You should not have seen this print! error?', kt, kindic
+   END SUBROUTINE trcdib_wr
+#endif
+
+   !!======================================================================
+END MODULE trcdit
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdta.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdta.F90	(revision 4536)
@@ -0,0 +1,213 @@
+MODULE trcdta
+   !!======================================================================
+   !!                     ***  MODULE  trcdta  ***
+   !! TOP :  reads passive tracer data 
+   !!=====================================================================
+   !! History :   1.0  !  2002-04  (O. Aumont)  original code
+   !!              -   !  2004-03  (C. Ethe)  module
+   !!              -   !  2005-03  (O. Aumont, A. El Moussaoui) F90
+   !!----------------------------------------------------------------------
+#if  defined key_top  &&  defined key_dtatrc
+   !!----------------------------------------------------------------------
+   !!   'key_top'  and  'key_dtatrc'        TOP model + passive tracer data
+   !!----------------------------------------------------------------------
+   !!   dta_trc      : read ocean passive tracer data
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE par_trc
+   USE trc
+   USE lib_print
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dta_trc   ! called in trcdtr.F90 and trcdmp.F90
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk,jptra) ::   trdta   !: tracer data at given time-step
+
+   REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,2) ::   tracdta            ! tracer data at two consecutive times
+   INTEGER , DIMENSION(jptra) ::   nlectr      !: switch for reading once
+   INTEGER , DIMENSION(jptra) ::   ntrc1       !: number of first month when reading 12 monthly value
+   INTEGER , DIMENSION(jptra) ::   ntrc2       !: number of second month when reading 12 monthly value
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   !!----------------------------------------------------------------------
+   !!   Default case                                            NetCDF file
+   !!----------------------------------------------------------------------
+   
+   SUBROUTINE dta_trc( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE dta_trc  ***
+      !!
+      !! ** Purpose :   Reads passive tracer data (Levitus monthly data)
+      !!
+      !! ** Method  :   Read on unit numtr the interpolated tracer concentra-
+      !!      tion onto the global grid. Data begin at january. 
+      !!      The value is centered at the middle of month. 
+      !!      In the opa model, kt=1 agree with january 1. 
+      !!      At each time step, a linear interpolation is applied between 
+      !!      two monthly values.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step
+      !!
+      CHARACTER (len=39) ::   clname(jptra)
+      INTEGER, PARAMETER ::   jpmois  = 12        ! number of months
+      INTEGER ::   ji, jj, jn, jl 
+      INTEGER ::   imois, iman, i15, ik  ! temporary integers 
+      REAL(wp) ::   zxy, zl
+      !!----------------------------------------------------------------------
+
+      DO jn = 1, jptra
+
+         IF( lutini(jn) ) THEN 
+
+            IF ( kt == nittrc000 ) THEN
+               !! 3D tracer data
+               IF(lwp)WRITE(numout,*)
+               IF(lwp)WRITE(numout,*) ' dta_trc: reading tracer' 
+               IF(lwp)WRITE(numout,*) ' data file ', jn, ctrcnm(jn)
+               IF(lwp)WRITE(numout,*)
+               nlectr(jn) = 0
+            ENDIF
+            ! Initialization
+            iman = jpmois
+            i15  = nday/16
+            imois = nmonth + i15 -1
+            IF( imois == 0 ) imois = iman
+
+
+            ! First call kt=nit000
+            ! --------------------
+
+            IF ( kt == nittrc000 .AND. nlectr(jn) == 0 ) THEN
+               ntrc1(jn) = 0
+               IF(lwp) WRITE(numout,*) ' trc_dta : Levitus tracer data monthly fields'
+               ! open file 
+# if defined key_pisces
+               clname(jn) = 'LEVITUS_'//ctrcnm(jn)
+# else
+               clname(jn) = ctrcnm(jn)
+# endif
+               CALL iom_open ( clname(jn), numtr(jn) )              
+
+            ENDIF
+
+# if defined key_pisces
+            ! Read montly file
+            IF( ( kt == nittrc000 .AND. nlectr(jn) == 0)  .OR. imois /= ntrc1(jn) ) THEN
+               nlectr(jn) = 1
+
+               ! Calendar computation
+
+               ! ntrc1 number of the first file record used in the simulation
+               ! ntrc2 number of the last  file record
+
+               ntrc1(jn) = imois
+               ntrc2(jn) = ntrc1(jn) + 1
+               ntrc1(jn) = MOD( ntrc1(jn), iman )
+               IF ( ntrc1(jn) == 0 ) ntrc1(jn) = iman
+               ntrc2(jn) = MOD( ntrc2(jn), iman )
+               IF ( ntrc2(jn) == 0 ) ntrc2(jn) = iman
+               IF(lwp) WRITE(numout,*) 'first record file used ntrc1 ', ntrc1(jn) 
+               IF(lwp) WRITE(numout,*) 'last  record file used ntrc2 ', ntrc2(jn)
+
+               ! Read montly passive tracer data Levitus 
+
+               CALL iom_get ( numtr(jn), jpdom_data, ctrcnm(jn), tracdta(:,:,:,jn,1), ntrc1(jn) )
+               CALL iom_get ( numtr(jn), jpdom_data, ctrcnm(jn), tracdta(:,:,:,jn,2), ntrc2(jn) )
+
+               IF(lwp) THEN
+                  WRITE(numout,*)
+                  WRITE(numout,*) ' read tracer data ', ctrcnm(jn),' ok'
+                  WRITE(numout,*)
+               ENDIF
+
+               ! Apply Mask
+               DO jl = 1, 2
+                  tracdta(:,:,:  ,jn,jl) = tracdta(:,:,:,jn,jl) * tmask(:,:,:) 
+                  tracdta(:,:,jpk,jn,jl) = 0.
+                  IF( ln_zps ) THEN                ! z-coord. with partial steps
+                     DO jj = 1, jpj                ! interpolation of temperature at the last level
+                        DO ji = 1, jpi
+                           ik = mbathy(ji,jj) - 1
+                           IF( ik > 2 ) THEN
+                              zl = ( gdept(ik) - fsdept(ji,jj,ik) ) / ( gdept(ik) - gdept(ik-1) )
+                              tracdta(ji,jj,ik,jn,jl) = (1.-zl) * tracdta(ji,jj,ik  ,jn,jl)   &
+                                 &                    +     zl  * tracdta(ji,jj,ik-1,jn,jl)
+                           ENDIF
+                        END DO
+                     END DO
+                  ENDIF
+
+               END DO
+
+            ENDIF
+
+            IF(lwp) THEN
+               WRITE(numout,*) ctrcnm(jn), 'Levitus month ', ntrc1(jn), ntrc2(jn)
+               WRITE(numout,*)
+               WRITE(numout,*) ' Levitus month = ', ntrc1(jn), '  level = 1'
+               CALL prihre( tracdta(1,1,1,jn,1), jpi, jpj, 1, jpi, 20, 1   &
+                  &        ,jpj, 20, 1., numout )
+               WRITE(numout,*) ' Levitus month = ', ntrc1(jn), '  level = ',jpk/2
+               CALL prihre( tracdta(1,1,jpk/2,jn,1), jpi, jpj, 1, jpi,    &
+                  &         20, 1, jpj, 20, 1., numout )
+               WRITE(numout,*) ' Levitus month = ',ntrc1(jn),'  level = ',jpkm1
+               CALL prihre( tracdta(1,1,jpkm1,jn,1), jpi, jpj, 1, jpi,     &
+                  &         20, 1, jpj, 20, 1., numout )
+            ENDIF
+
+            ! At every time step compute temperature data
+            zxy = FLOAT( nday + 15 - 30 * i15 ) / 30.
+            trdta(:,:,:,jn) =  ( 1. - zxy ) * tracdta(:,:,:,jn,1)    &
+               &              +       zxy   * tracdta(:,:,:,jn,2) 
+
+            IF( jn == jpno3 )   trdta(:,:,:,jn) = trdta(:,:,:,jn) *   7.6e-6
+            IF( jn == jpdic )   trdta(:,:,:,jn) = trdta(:,:,:,jn) *   1.0e-6
+            IF( jn == jptal )   trdta(:,:,:,jn) = trdta(:,:,:,jn) *   1.0e-6
+            IF( jn == jpoxy )   trdta(:,:,:,jn) = trdta(:,:,:,jn) *  44.6e-6
+            IF( jn == jpsil )   trdta(:,:,:,jn) = trdta(:,:,:,jn) *   1.0e-6
+            IF( jn == jppo4 )   trdta(:,:,:,jn) = trdta(:,:,:,jn) * 122.0e-6
+
+            ! Close the file
+            ! --------------
+            
+            IF( kt == nitend )   CALL iom_close( numtr(jn) )
+
+# else
+            ! Read init file only
+            IF( kt == nittrc000  ) THEN
+               CALL iom_get ( numtr(jn), jpdom_data, ctrcnm(jn), trdta(:,:,:,jn), ntrc1(jn) )
+               trdta(:,:,:,jn) = trdta(:,:,:,jn) * tmask(:,:,:)
+               CALL iom_close ( numtr(jn) )
+            ENDIF 
+# endif
+
+         ENDIF
+
+      END DO
+      !
+   END SUBROUTINE dta_trc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                              NO 3D passive tracer data
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE dta_trc( kt )        ! Empty routine
+      WRITE(*,*) 'dta_trc: You should not have seen this print! error?', kt
+   END SUBROUTINE dta_trc
+#endif
+
+   !!======================================================================
+END MODULE trcdta
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdtr.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdtr.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcdtr.F90	(revision 4536)
@@ -0,0 +1,258 @@
+MODULE trcdtr
+   !!======================================================================
+   !!                         ***  MODULE trcdtr  ***
+   !! TOP :   computes or READ initial DATA for passive tracer
+   !!======================================================================
+   !! History :    -   !  1996-11  ()  original code
+   !!                  !  2000-12  (O. Aumont, E. Kestenare) add for POC in sediments
+   !!             1.0  !  2005-12  (O. Aumont, A. El Moussaoui) F90
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_dtr    :  computes or READ initial DATA for passive tracer
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE sms
+   USE trcdta
+   USE lib_mpp
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_dtr      ! called in ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_dtr
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_dtr  ***
+      !!
+      !! ** Purpose :   computes or READ initial DATA for passive tracer
+      !!
+      !! ** Method  : 
+      !!---------------------------------------------------------------------
+      INTEGER ::   jn 
+# if defined key_pisces
+      INTEGER ::   ji, jj, jk 
+      REAL(wp) ::   alka0, oxyg0, calc0, bioma0
+      REAL(wp) ::   silic1, po4, no3, caralk, bicarb, co3
+# endif
+      !!---------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_dtr : initialisation of the passive tracers'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+#if defined key_cfc
+      trn(:,:,:,:) = 0.0  ! CFC initialisation to zero
+ 
+#elif defined key_pisces
+      ! PISCES initialisation
+      ! ---------------------
+      sco2   =  2.300e-3
+      alka0  =  2.390e-3
+      oxyg0  =  1.800e-4
+      po4    =  2.165e-6 / po4r
+      bioma0 =  1.000e-8
+      silic1 = 91.510e-6
+      calc0  =  1.000e-6
+      no3    = 30.880e-6 * 7.6
+
+      trn(:,:,:,jpdic) = sco2
+      trn(:,:,:,jpdoc) = bioma0
+      trn(:,:,:,jptal) = alka0
+      trn(:,:,:,jpoxy) = oxyg0
+      trn(:,:,:,jpcal) = calc0
+      trn(:,:,:,jppo4) = po4
+      trn(:,:,:,jppoc) = bioma0
+#  if ! defined key_kriest
+      trn(:,:,:,jpgoc) = bioma0
+      trn(:,:,:,jpbfe) = bioma0 * 5.e-6
+#  else
+      trn(:,:,:,jpnum) = bioma0 / ( 6. *xkr_massp )
+#  endif
+      trn(:,:,:,jpsil) = silic1
+      trn(:,:,:,jpbsi) = bioma0 * 0.15
+      trn(:,:,:,jpdsi) = bioma0 * 5.e-6
+      trn(:,:,:,jpphy) = bioma0
+      trn(:,:,:,jpdia) = bioma0
+      trn(:,:,:,jpzoo) = bioma0
+      trn(:,:,:,jpmes) = bioma0
+      trn(:,:,:,jpfer) = 0.6E-9
+      trn(:,:,:,jpsfe) = bioma0 * 5.e-6
+      trn(:,:,:,jpdfe) = bioma0 * 5.e-6
+      trn(:,:,:,jpnfe) = bioma0 * 5.e-6
+      trn(:,:,:,jpnch) = bioma0 * 12. / 55.
+      trn(:,:,:,jpdch) = bioma0 * 12. / 55.
+      trn(:,:,:,jpno3) = no3
+      trn(:,:,:,jpnh4) = bioma0
+
+      ! Initialization of chemical variables of the carbon cycle
+      ! --------------------------------------------------------
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               caralk = trn(ji,jj,jk,jptal) - borat(ji,jj,jk) / (  1. + 1.E-8 / ( rtrn + akb3(ji,jj,jk) )  )
+               co3    = ( caralk - trn(ji,jj,jk,jpdic) ) *        tmask(ji,jj,jk)   &
+                  &   +                  0.5e-3          * ( 1. - tmask(ji,jj,jk) )
+               bicarb = (2.*trn(ji,jj,jk,jpdic)-caralk)
+               hi(ji,jj,jk) = ( ak23(ji,jj,jk) * bicarb / co3 ) *        tmask(ji,jj,jk)   &  
+                  &         +            1.e-9                  * ( 1. - tmask(ji,jj,jk) )
+          END DO
+        END DO
+      END DO
+
+      ! initialize the half saturation constant for silicate
+      ! ----------------------------------------------------
+      xksi(:,:) = 2.e-6
+
+      IF(lwp) WRITE(numout,*) 'Initialization of PISCES tracers done'
+      IF(lwp) WRITE(numout,*) ' '
+
+# elif defined key_lobster && ( defined key_eel_r6 || defined key_eel_r2 )
+      ! LOBSTER initialisation for EEL
+      ! ----------------------
+      ! here: analytical initialisation used in Levy et al. (2001)
+      
+      DO jk = 1, 7
+         trn(:,:,jk,jpdet) = 0.016 * tmask(:,:,jk)
+         trn(:,:,jk,jpzoo) = 0.018 * tmask(:,:,jk)
+         trn(:,:,jk,jpphy) = 0.036 * tmask(:,:,jk)
+         trn(:,:,jk,jpno3) = 1.e-5 * tmask(:,:,jk)
+         trn(:,:,jk,jpnh4) = 5.e-4 * tmask(:,:,jk)
+         trn(:,:,jk,jpdom) = 0.017 * tmask(:,:,jk)
+      END DO
+
+      trn(:,:, 8,jpdet) = 0.020   * tmask(:,:, 8)
+      trn(:,:, 8,jpzoo) = 0.027   * tmask(:,:, 8)
+      trn(:,:, 8,jpphy) = 0.041   * tmask(:,:, 8)
+      trn(:,:, 8,jpno3) = 0.00022 * tmask(:,:, 8)
+      trn(:,:, 8,jpnh4) = 0.0033  * tmask(:,:, 8)
+      trn(:,:, 8,jpdom) = 0.021   * tmask(:,:, 8)
+
+      trn(:,:, 9,jpdet) = 0.0556  * tmask(:,:, 9)
+      trn(:,:, 9,jpzoo) = 0.123   * tmask(:,:, 9)
+      trn(:,:, 9,jpphy) = 0.122   * tmask(:,:, 9)
+      trn(:,:, 9,jpno3) = 0.028   * tmask(:,:, 9)
+      trn(:,:, 9,jpnh4) = 0.024   * tmask(:,:, 9)
+      trn(:,:, 9,jpdom) = 0.06    * tmask(:,:, 9)
+
+      trn(:,:,10,jpdet) = 0.025   * tmask(:,:,10)
+      trn(:,:,10,jpzoo) = 0.016   * tmask(:,:,10)
+      trn(:,:,10,jpphy) = 0.029   * tmask(:,:,10)
+      trn(:,:,10,jpno3) = 2.462   * tmask(:,:,10)
+      trn(:,:,10,jpnh4) = 0.04    * tmask(:,:,10)
+      trn(:,:,10,jpdom) = 0.022   * tmask(:,:,10)
+
+      trn(:,:,11,jpdet) = 0.0057  * tmask(:,:,11)
+      trn(:,:,11,jpzoo) = 0.0005  * tmask(:,:,11)
+      trn(:,:,11,jpphy) = 0.0006  * tmask(:,:,11)
+      trn(:,:,11,jpno3) = 3.336   * tmask(:,:,11)
+      trn(:,:,11,jpnh4) = 0.005   * tmask(:,:,11)
+      trn(:,:,11,jpdom) = 0.004   * tmask(:,:,11)
+
+      trn(:,:,12,jpdet) = 0.002   * tmask(:,:,12)
+      trn(:,:,12,jpzoo) = 1.e-6   * tmask(:,:,12)
+      trn(:,:,12,jpphy) = 5.e-6   * tmask(:,:,12)
+      trn(:,:,12,jpno3) = 4.24    * tmask(:,:,12)
+      trn(:,:,12,jpnh4) = 0.001   * tmask(:,:,12)
+      trn(:,:,12,jpdom) = 3.e-5   * tmask(:,:,12)
+
+      DO jk=13,jpk
+        trn(:,:,jk,jpdet) = 0.e0
+        trn(:,:,jk,jpzoo) = 0.e0
+        trn(:,:,jk,jpphy) = 0.e0
+        trn(:,:,jk,jpnh4) = 0.e0
+        trn(:,:,jk,jpdom) = 0.e0
+      END DO
+
+      trn(:,:,13,jpno3) = 5.31  * tmask(:,:,13)
+      trn(:,:,14,jpno3) = 6.73  * tmask(:,:,14)
+      trn(:,:,15,jpno3) = 8.32  * tmask(:,:,15)
+      trn(:,:,16,jpno3) = 10.13 * tmask(:,:,16)
+      trn(:,:,17,jpno3) = 11.95 * tmask(:,:,17)
+      trn(:,:,18,jpno3) = 13.57 * tmask(:,:,18)
+      trn(:,:,19,jpno3) = 15.08 * tmask(:,:,19)
+      trn(:,:,20,jpno3) = 16.41 * tmask(:,:,20)
+      trn(:,:,21,jpno3) = 17.47 * tmask(:,:,21)
+      trn(:,:,22,jpno3) = 18.29 * tmask(:,:,22)
+      trn(:,:,23,jpno3) = 18.88 * tmask(:,:,23)
+      trn(:,:,24,jpno3) = 19.30 * tmask(:,:,24)
+      trn(:,:,25,jpno3) = 19.68 * tmask(:,:,25)
+      trn(:,:,26,jpno3) = 19.91 * tmask(:,:,26)
+      trn(:,:,27,jpno3) = 19.99 * tmask(:,:,27)
+      trn(:,:,28,jpno3) = 20.01 * tmask(:,:,28)
+      trn(:,:,29,jpno3) = 20.01 * tmask(:,:,29)
+      trn(:,:,30,jpno3) = 20.01 * tmask(:,:,30)
+
+# elif defined key_lobster && defined key_gyre
+      ! LOBSTER initialisation for GYRE
+      ! ----------------------
+      ! here:  init NO3=f(density) by asklod AS Kremeur 2005-07
+      trn(:,:,:,jpdet) = 0.1 * tmask(:,:,:)
+      trn(:,:,:,jpzoo) = 0.1 * tmask(:,:,:)
+      trn(:,:,:,jpnh4) = 0.1 * tmask(:,:,:)
+      trn(:,:,:,jpphy) = 0.1 * tmask(:,:,:)
+      trn(:,:,:,jpdom) = 1.0 * tmask(:,:,:)
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( rhd(ji,jj,jk) <= 24.5e-3 ) THEN
+                  trn(ji,jj,jk,jpno3) = 2. * tmask(ji,jj,jk)
+               ELSE
+                  trn(ji,jj,jk,jpno3) = ( 15.55 * ( rhd(ji,jj,jk) * 1000. ) - 380.11 ) * tmask(ji,jj,jk)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+# else
+      ! Default case 
+      ! ------------
+      DO jn = 1, jptra
+         trn(:,:,:,jn) = 0.1 * tmask(:,:,:)
+      END DO
+
+# endif
+
+# if defined key_dtatrc
+     ! Initialization of tracer from a file that may also be used for damping
+      CALL dta_trc( nittrc000 )
+      DO jn = 1, jptra
+        IF( lutini(jn) )   trn(:,:,:,jk) = trdta(:,:,:,jn) * tmask(:,:,:)   ! initialisation from file if required
+      END DO
+# endif
+
+      ! before field :
+      ! -------------
+      trb(:,:,:,:) = trn(:,:,:,:)
+
+# if defined key_lobster
+      !  initialize the POC in sediments
+      sedpocb(:,:) = 0.e0
+      sedpocn(:,:) = 0.e0
+      sedpoca(:,:) = 0.e0
+# endif
+      !
+   END SUBROUTINE trc_dtr 
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_dtr                      ! Empty routine   
+   END SUBROUTINE trc_dtr
+#endif
+
+   !!======================================================================
+END MODULE trcdtr
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcini.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcini.F90	(revision 4536)
@@ -0,0 +1,66 @@
+MODULE trcini
+   !!======================================================================
+   !!                         ***  MODULE trcini  ***
+   !! TOP :   Manage the passive tracer initialization
+   !!======================================================================
+   !! History :    -   !  2000-04  (O. Aumont, M.A. Foujols)  original code
+   !!             1.0  !  2005-03  (O. Aumont, A. El Moussaoui) F90
+   !!              -   !  2005-10  (C. Ethe) Module
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec) re-writing
+   !!----------------------------------------------------------------------
+   !!   trc_ini :   Initialization for passive tracer
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE trcini_cfc      ! CFC     initialisation
+   USE trcini_lobster  ! LOBSTER initialisation
+   USE trcini_pisces   ! PISCES  initialisation
+   USE trcini_my_trc   ! MY_TRC  initialisation
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini   ! called by ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini
+      !!-------------------------------------------------------------------
+      !!                    ***  ROUTINE trc_ini  ***
+      !!              
+      !! ** Purpose :   Initialization of passive tracer to zero
+      !!
+      !! ** Method  :   call the initialisation of each defined tracer
+      !!             model (LOBSTER, PISCES, CFC, MY_TRC)
+      !!-------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_ini : initial set up of the tracer models'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      !
+      IF( lk_lobster ) THEN   ;   CALL trc_ini_lobster      ! LOBSTER bio-model
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          LOBSTER not used'
+      ENDIF
+
+      IF( lk_pisces  ) THEN   ;   CALL trc_ini_pisces       ! PISCES  bio-model
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          PISCES not used'
+      ENDIF
+
+      IF( lk_cfc     ) THEN   ;   CALL trc_ini_cfc          ! CFC     tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          CFC not used'
+      ENDIF
+
+      IF( lk_my_trc  ) THEN   ;   CALL trc_ini_my_trc       ! MY_TRC  tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          MY_TRC not used'
+      ENDIF
+      !
+   END SUBROUTINE trc_ini
+
+   !!======================================================================
+END MODULE trcini
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclec.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclec.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclec.F90	(revision 4536)
@@ -0,0 +1,214 @@
+MODULE trclec
+   !!======================================================================
+   !!                       ***  MODULE trclec  ***
+   !! TOP :   Read and print options for the passive tracer run (namelist)
+   !!======================================================================
+   !! History :    -   !  1996-11  (M.A. Foujols, M. Levy)  original code
+   !!              -   !  1998-04  (M.A Foujols, L. Bopp) ahtrb0 for isopycnal mixing
+   !!              -   !  1999-10  (M.A. Foujols, M. Levy) separation of sms
+   !!              -   !  2000-07  (A. Estublier) add TVD and MUSCL : Tests on ndttrc
+   !!              -   !  2000-11  (M.A Foujols, E Kestenare) trcrat, ahtrc0 and aeivtr0
+   !!              -   !  2001-01 (E Kestenare) suppress ndttrc=1 for CEN2 and TVD schemes
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_lec    :  Read and print options for the passive tracer run (namelist)
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE trctrp_lec
+   USE trclsm
+
+   IMPLICIT NONE
+   PRIVATE 
+
+   PUBLIC trc_lec      ! called in ???
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lec
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_lec  ***
+      !!
+      !! ** Purpose :   READ and PRINT options for the passive tracer run (namelist) 
+      !!
+      !! ** Method  : - read namelist
+      !!---------------------------------------------------------------------
+      INTEGER ::  ji
+      CHARACTER (len=32) ::   clname
+      !!
+      NAMELIST/nattrc/ nwritetrc, lrsttr, nrsttr, ctrcnm, ctrcnl, ctrcun, lutini     ! general   
+      NAMELIST/natnum/ rsc, rtrn, ncortrc, ndttrc, crosster
+#if defined key_trc_diatrd
+      NAMELIST/natrtd/ luttrd, nwritetrd                                             ! dynamical trends
+#endif
+#if defined key_trc_diaadd
+      NAMELIST/natadd/ ctrc3d, ctrc3l, ctrc2d, ctrc2l, ctrc3u, ctrc2u, nwriteadd     ! additional diagnostics
+#endif
+      !!---------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_lec : read the passive tracer namelists'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+      clname = 'namelist.passivetrc'
+      CALL ctlopn( numnat, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+         &         1, numout, .FALSE., 1 )
+
+
+      ! Namelist nattrc (files)
+      ! ----------------------------------------------
+      nwritetrc = 10                 ! default values
+      lrsttr    = .FALSE.
+      nrsttr    =  0
+      DO ji = 1, jptra
+         WRITE(ctrcnm(ji),'("TR_",I1)'           ) ji
+         WRITE(ctrcnl(ji),'("TRACER NUMBER ",I1)') ji
+         ctrcun(ji) = 'mmole/m3'
+         lutini(ji) = .FALSE. 
+      END DO
+
+      REWIND( numnat )               ! read nattrc
+      READ  ( numnat, nattrc )
+
+      IF(lwp) THEN                   ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : nattrc'
+         WRITE(numout,*) '    frequency of outputs for passive tracers nwritetrc = ', nwritetrc  
+         WRITE(numout,*) '    restart LOGICAL for passive tr. lrsttr = ', lrsttr
+         WRITE(numout,*) '    control of time step for p. tr. nrsttr = ', nrsttr
+         DO ji = 1, jptra
+            WRITE(numout,*) '    tracer nb: ', ji, ' name = ', ctrcnm(ji), ctrcnl(ji), ' in unit = ',ctrcun(ji)
+            WRITE(numout,*) '    initial value in FILE : ',lutini(ji) 
+         END DO
+      ENDIF
+
+#if defined key_trc_diatrd
+
+      ! Namelist natrtd (transport trends)
+      ! ----------------------------------------------
+      nwritetrd = 10                 ! default values (no dynamical trend recording)
+      DO ji = 1, jptra
+         luttrd(ji) = .FALSE.
+      END DO
+
+      REWIND( numnat )               ! read natrtd
+      READ  ( numnat, natrtd )
+
+      nkeep=0
+      ikeep(:)=0
+      DO ji = 1, jptra
+         IF( luttrd(ji) ) THEN 
+             nkeep    = nkeep + 1
+             ikeep(ji)=nkeep
+         END IF 
+      END DO
+      IF( nkeep > 0 ) THEN  
+        IF(.NOT. ALLOCATED( trtrd ) )   ALLOCATE( trtrd(jpi,jpj,jpk,nkeep,jpdiatrc) ) 
+        trtrd(:,:,:,:,:) = 0.e0
+      ENDIF 
+
+      IF(lwp) THEN                   ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : natrtd'
+         WRITE(numout,*) '    frequency of outputs for dynamical trends nwritetrd = ', nwritetrd
+         DO ji = 1, jptra
+            WRITE(numout,*) '    keep dynamical trends for tracer number :', ji, luttrd(ji), ikeep(ji)
+         END DO
+         WRITE(numout,*) '    total = ', nkeep, ' tracers dyn trends saved'
+         WRITE(numout,*) '    size of trtrd = ', jpi*jpj*jpk*nkeep*jpdiatrc
+      ENDIF
+#endif
+
+#if defined key_trc_diaadd
+
+      ! Namelist natrtd (transport trends)
+      ! ----------------------------------------------
+      nwriteadd = 10                 ! default values 
+      !                                 ! 3D output arrays
+      DO ji = 1, jpdia3d
+         WRITE(ctrc3d(ji),'("3D_",I1)') ji                      ! short name
+         WRITE(ctrc3l(ji),'("3D DIAGNOSTIC NUMBER ",I2)') ji    ! long name
+         ctrc3u(ji) = ' '                                       ! units 
+      END DO
+      !                                 ! 2D output arrays
+      DO ji = 1, jpdia2d
+         WRITE(ctrc2d(ji),'("2D_",I1)') ji                      ! short name
+         WRITE(ctrc2l(ji),'("2D DIAGNOSTIC NUMBER ",I2)') ji    ! long name
+         ctrc2u(ji) = ' '                                       ! units
+      END DO
+
+      REWIND( numnat )               ! read natrtd
+      READ  ( numnat, natadd )
+
+      IF(lwp) THEN                   ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : natadd'
+         WRITE(numout,*) '    frequency of outputs for additional arrays nwriteadd = ', nwriteadd
+         DO ji = 1, jpdia3d
+            WRITE(numout,*) '    3d output field No :',ji,' names ',ctrc3d(ji), ctrc3l(ji), ' in ', ctrc3u(ji)
+         END DO
+         DO ji = 1, jpdia2d
+            WRITE(numout,*) '    2d output field No :',ji,' names ',ctrc2d(ji), ctrc2l(ji), ' in ', ctrc2u(ji)
+         END DO
+      ENDIF
+#endif
+
+      !! Namelist natnum :
+      !! -----------------
+      rsc      = 1.                 ! default values
+      rtrn     = 1.e-15
+      ncortrc  = 1
+      ndttrc   = 4
+      crosster = .FALSE.
+
+      REWIND( numnat )              ! read natnum
+      READ  ( numnat, natnum )
+
+      !!Chris  computes the first time step of tracer model
+      nittrc000 = nit000 + ndttrc - 1
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : natnum'
+         WRITE(numout,*)
+         WRITE(numout,*) ' tuning coefficient              rsc     = ', rsc
+         WRITE(numout,*) ' truncation value                rtrn    = ', rtrn
+         WRITE(numout,*) ' number of corrective phase      ncortrc = ', ncortrc
+         WRITE(numout,*) ' time step freq. for pass. trac. ndttrc  = ', ndttrc
+         WRITE(numout,*) ' 1st time step for pass. trac. nittrc000 = ', nittrc000
+         WRITE(numout,*) ' computes or not crossterms    crosster  = ', crosster
+      ENDIF
+
+      ! namelist of transport
+      ! ---------------------
+      CALL trc_trp_lec
+
+      ! namelist of SMS
+      ! ---------------      
+      CALL trc_lsm
+      !
+   END SUBROUTINE trc_lec
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lec                      ! Empty routine   
+   END SUBROUTINE trc_lec
+#endif
+
+   !!======================================================================
+END MODULE  trclec
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclsm.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclsm.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trclsm.F90	(revision 4536)
@@ -0,0 +1,77 @@
+MODULE trclsm
+   !!======================================================================
+   !!                         ***  MODULE trclsm  ***
+   !! TOP :   reads specific namelist for passive tracer sms terms
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (C. Ethe) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec) re-writing
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_lsm   : reads specific namelist for sms terms
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE trclsm_cfc      ! CFC     initialisation
+   USE trclsm_lobster  ! LOBSTER initialisation
+   USE trclsm_pisces   ! PISCES  initialisation
+   USE trclsm_my_trc   ! MY_TRC  initialisation
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE                             
+   PRIVATE
+
+   PUBLIC   trc_lsm      ! called in initrc.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_lsm
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_lsm  ***  
+      !!
+      !! ** Purpose :   read TOP namelists for the different tracers models
+      !!
+      !! ** Method  :   call the namelist read of each defined tracer
+      !!             model (LOBSTER, PISCES, CFC, MY_TRC)
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_lsm : read namelist of the TOP models'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      !
+      IF( lk_lobster ) THEN   ;   CALL trc_lsm_lobster      ! LOBSTER bio-model
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          LOBSTER not used'
+      ENDIF
+
+      IF( lk_pisces  ) THEN   ;   CALL trc_lsm_pisces      ! PISCES  bio-model
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          PISCES not used'
+      ENDIF
+
+      IF( lk_cfc     ) THEN   ;   CALL trc_lsm_cfc         ! CFC     tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          CFC not used'
+      ENDIF
+
+      IF( lk_my_trc  ) THEN   ;   CALL trc_lsm_my_trc      ! MY_TRC  tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          MY_TRC not used'
+      ENDIF
+      !
+   END SUBROUTINE trc_lsm
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_lsm                      ! Empty routine
+   END  SUBROUTINE trc_lsm
+#endif  
+
+   !!======================================================================
+END MODULE trclsm  
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcrst.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcrst.F90	(revision 4536)
@@ -0,0 +1,385 @@
+MODULE trcrst
+   !!======================================================================
+   !!                       ***  MODULE trcrst  ***
+   !! TOP :   create, write, read the restart files for passive tracers
+   !!======================================================================
+   !! History :   1.0  !  2007-02 (C. Ethe) adaptation from the ocean
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_rst_opn    : open  restart file
+   !!   trc_rst_read   : read  restart file
+   !!   trc_rst_wri    : write restart file
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE sms
+   USE trccfc          ! CFC variables
+   USE trctrp_lec   
+   USE lib_mpp
+   USE iom
+   
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   trc_rst_opn       ! called by ???
+   PUBLIC   trc_rst_read      ! called by ???
+   PUBLIC   trc_rst_wri       ! called by ???
+   
+   LOGICAL, PUBLIC ::   lrst_trc         !: logical to control the trc restart write 
+   INTEGER, PUBLIC ::   numrtr, numrtw   !: logical unit for trc restart (read and write)
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   
+CONTAINS
+   
+   SUBROUTINE trc_rst_opn( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_opn  ***
+      !!
+      !! ** purpose  :   output of sea-trc variable in a netcdf file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
+      CHARACTER(LEN=50)   ::   clname   ! trc output restart file name
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )  THEN
+         lrst_trc = .FALSE.
+# if defined key_off_tra
+         nitrst = nitend  ! in online version, already done in rst_opn routine defined in restart.F90 module
+# endif
+      ENDIF
+      
+      IF( kt == nitrst - ndttrc .OR. nitend - nit000 + 1 < 2 * ndttrc ) THEN
+         ! beware if model runs less than 2*ndttrc time step
+         ! beware of the format used to write kt (default is i8.8, that should be large enough)
+         IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
+         ELSE                        ;   WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         IF(lwp) WRITE(numout,*)
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_trc"
+         IF(lwp) WRITE(numout,*) '             open trc restart.output NetCDF file: '//clname
+         CALL iom_open( clname, numrtw, ldwrt = .TRUE., kiolib = jprstlib )
+         lrst_trc = .TRUE.
+      ENDIF
+      !
+   END SUBROUTINE trc_rst_opn
+
+
+   SUBROUTINE trc_rst_read 
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_opn  ***
+      !!
+      !! ** purpose  :   read passive tracer fields in restart files
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jn  
+      INTEGER  ::   iarak0
+      REAL(wp) ::   zkt, zarak0
+# if defined key_pisces 
+      REAL(wp) ::   ztrasum
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   caralk, bicarb, co3
+# endif
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_rst_read : read the TOP restart file'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN   ;   iarak0 = 1
+      ELSE                                           ;   iarak0 = 0
+      ENDIF
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '   the present run starts at the time step nit000 = ', nit000
+      IF(lwp .AND. iarak0 == 1 )   WRITE(numout,*) '   and needs previous fields for Arakawa sheme ??? '
+
+
+      ! Time domain : restart
+      ! -------------------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' *** passive tracer restart option'
+      SELECT CASE ( nrsttr )
+      CASE ( 0 )
+         IF(lwp) WRITE(numout,*) '    nrsttr = 0 no control of nit000'
+      CASE ( 1 )
+         IF(lwp) WRITE(numout,*) '    nrsttr = 1 we control the date of nit000'
+      CASE ( 2 )
+         IF(lwp) WRITE(numout,*) '    nrsttr = 2 the date adatrj is read in restart file'
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,*) '  ===>>>> nrsttr not equal 0, 1 or 2 : no control of the date'
+         IF(lwp) WRITE(numout,*) '  =======                  ========='
+      END SELECT
+
+      CALL iom_open( 'restart.trc', numrtr, kiolib = jprstlib )
+
+      CALL iom_get( numrtr, 'kt'   , zkt    )
+      CALL iom_get( numrtr, 'arak0', zarak0 )
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' Info on the restart file read : '
+      IF(lwp) WRITE(numout,*) '    time-step           : ', NINT( zkt    )
+      IF(lwp) WRITE(numout,*) '    arakawa option      : ', NINT( zarak0 )
+
+
+      IF( nittrc000 - NINT( zkt ) /= 1 .AND. nrsttr /= 0 )  &      ! control of date
+         &   CALL ctl_stop( ' ===>>>> : problem with nit000 for the restart', &
+         &                  ' verify the restart file or rerun with nrstdt = 0 (namelist)' )
+
+      IF( iarak0 /= NINT( zarak0 ) )   &                           ! Control of the scheme
+         & CALL ctl_stop( ' ===>>>> : problem with advection scheme', &
+         & ' it must be the same type for both restart and previous run', &
+         & ' centered or euler '  )
+
+
+      ! READ prognostic variables and computes diagnostic variable
+      DO jn = 1, jptra
+         CALL iom_get( numrtr, jpdom_local, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) ) 
+         CALL iom_get( numrtr, jpdom_local, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) ) 
+      END DO
+# if defined key_lobster
+      CALL iom_get( numrtr, jpdom_local, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) ) 
+      CALL iom_get( numrtr, jpdom_local, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) ) 
+# elif defined key_pisces
+      CALL iom_get( numrtr, jpdom_local, 'Silicalim', xksi(:,:) ) 
+      xksimax = xksi
+# elif defined key_cfc
+      DO jn = 1, jptra
+         CALL iom_get( numrtr, jpdom_local, 'qint'//ctrcnm(jn), qint(:,:,jn) ) 
+         CALL iom_get( numrtr, jpdom_local, 'qtr'//ctrcnm(jn) , qtr( :,:,jn) ) 
+      END DO
+# endif
+
+# if defined key_pisces 
+      !                                                         ! --------------------------- !
+      IF( cp_cfg == "orca" .AND. .NOT. lk_trccfg_1d ) THEN      ! ORCA condiguration (not 1D) !
+         !                                                      ! --------------------------- !
+         !                                                      ! set total alkalinity, phosphate, NO3 & silicate
+         !                          ! total alkalinity
+         ztrasum = 0.e0             ! ----------------
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztrasum = ztrasum + trn(ji,jj,jk,jptal) * tmask(ji,jj,jk) * tmask_i(ji,jj)  &
+#  if defined key_off_degrad
+                     &              * facvol(ji,jj,jk)   &
+#  endif
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztrasum )     ! sum over the global domain  
+
+         IF(lwp) WRITE(numout,*) 'TALK moyen ', ztrasum / areatot * 1.e6
+         ztrasum = ztrasum / areatot * 1.e6
+         trn(:,:,:,jptal) = trn(:,:,:,jptal) * 2391. / ztrasum
+
+         !                          ! phosphate
+         ztrasum = 0.e0             ! ---------
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztrasum = ztrasum + trn(ji,jj,jk,jppo4) * tmask(ji,jj,jk) * tmask_i(ji,jj)  &
+#  if defined key_off_degrad
+                     &              * facvol(ji,jj,jk)   &
+#  endif
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztrasum )     ! sum over the global domain  
+
+         IF(lwp) WRITE(numout,*) 'PO4 moyen ', ztrasum/areatot*1E6/122.
+         ztrasum = ztrasum / areatot * 1.e6 / 122.
+         trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * 2.165 / ztrasum
+
+         !                          ! NO3
+         ztrasum = 0.e0             ! ---
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztrasum = ztrasum + trn(ji,jj,jk,jpno3) * tmask(ji,jj,jk) * tmask_i(ji,jj)  &
+#  if defined key_off_degrad
+                     &              * facvol(ji,jj,jk)   &
+#  endif
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztrasum )     ! sum over the global domain  
+
+         IF(lwp) WRITE(numout,*) 'NO3 moyen ', ztrasum / areatot*1.e6 / 7.6
+         ztrasum = ztrasum / areatot * 1.e6 / 7.6
+         trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * 30.9 / ztrasum
+
+         !                          ! Silicate
+         ztrasum = 0.e0             ! --------
+         DO jk = 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztrasum = ztrasum + trn(ji,jj,jk,jpsil) * tmask(ji,jj,jk) * tmask_i(ji,jj)   &
+#  if defined key_off_degrad
+                     &              * facvol(ji,jj,jk)   &
+#  endif
+                     &              * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztrasum )     ! sum over the global domain  
+
+         IF(lwp) WRITE(numout,*) 'SiO3 moyen ', ztrasum / areatot * 1.e6
+         ztrasum = ztrasum / areatot * 1.e6
+         trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * 91.51 / ztrasum ) 
+         !
+      ENDIF
+
+!#if defined key_kriest
+!      !! Initialize number of particles from a standart restart file
+!      !! The name of big organic particles jpgoc has been only change
+!      !! and replace by jpnum but the values here are concentration
+!      trn(:,:,:,jppoc) = trn(:,:,:,jppoc) + trn(:,:,:,jpnum)
+!      trn(:,:,:,jpnum) = trn(:,:,:,jppoc) / ( 6. * xkr_massp )
+!#endif
+      !!  Set hi (???) from  total alcalinity, borat (???), akb3 (???) and ak23 (???)
+      !!  ---------------------------------------------------------------------
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               caralk = trn(ji,jj,jk,jptal) - borat(ji,jj,jk) / ( 1. + 1.e-8 / ( rtrn + akb3(ji,jj,jk) ) )
+               co3    = ( caralk - trn(ji,jj,jk,jpdic) ) *       tmask(ji,jj,jk)   &
+                  &   +             0.5e-3               * ( 1.- tmask(ji,jj,jk) )
+               bicarb = 2.* trn(ji,jj,jk,jpdic) - caralk
+               hi(ji,jj,jk) = ( ak23(ji,jj,jk) * bicarb / co3 )   *       tmask(ji,jj,jk)   &
+                  &         +             1.0e-9                  * ( 1.- tmask(ji,jj,jk) )
+            END DO
+         END DO
+      END DO
+# endif
+
+      CALL iom_close( numrtr )
+      !
+   END SUBROUTINE trc_rst_read
+
+
+   SUBROUTINE trc_rst_wri( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_wri  ***
+      !!
+      !! ** purpose  :   write passive tracer fields in restart files
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  :: ji, jj, jk, jn
+      REAL(wp) :: zdiag_var, zdiag_varmin, zdiag_varmax, zdiag_tot
+      REAL(wp) :: zder
+      !!----------------------------------------------------------------------
+
+      IF( MOD( kt, nstock ) == 0 .OR. kt == nitend ) THEN
+
+         ! 0. initialisations
+         ! ------------------
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+
+         CALL iom_rstput( kt, nitrst, numrtw, 'kt'   ,  REAL( kt, wp )  )
+
+         IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+            CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 1. )
+         ELSE
+            CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 0. )
+         ENDIF
+
+
+         ! prognostic variables
+         ! --------------------
+         DO jn = 1, jptra
+            CALL iom_rstput( kt, nitrst, numrtw, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
+            CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
+         END DO
+
+#if defined key_lobster
+         CALL iom_rstput( kt, nitrst, numrtw, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
+#elif defined key_pisces
+         CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
+
+#elif defined key_cfc
+         DO jn = 1, jptra
+            CALL iom_rstput( kt, nitrst, numrtw, 'qint'//ctrcnm(jn), qint(:,:,jn) )
+            CALL iom_rstput( kt, nitrst, numrtw, 'qtr'//ctrcnm(jn) , qtr (:,:,jn) )
+         END DO
+#endif
+
+         IF(lwp) WRITE(numout,*) '----TRACER STAT----'
+
+         zdiag_tot = 0.e0
+         DO jn = 1, jptra
+            zdiag_var    = 0.e0
+            zdiag_varmin = 0.e0
+            zdiag_varmax = 0.e0
+            DO ji = 1, jpi
+               DO jj = 1, jpj
+                  DO jk = 1,jpk
+                     zdiag_var = zdiag_var + trn(ji,jj,jk,jn) * tmask(ji,jj,jk) * tmask_i(ji,jj)   &
+#if defined key_off_degrad
+                        &   * facvol(ji,jj,jk)   &
+#endif
+                        &   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+
+            zdiag_varmin = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+            zdiag_varmax = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+
+            IF( lk_mpp ) THEN
+               CALL mpp_min( zdiag_varmin )      ! min over the global domain
+               CALL mpp_max( zdiag_varmax )      ! max over the global domain
+               CALL mpp_sum( zdiag_var    )      ! sum over the global domain
+            END IF
+
+            zdiag_tot = zdiag_tot + zdiag_var
+            zdiag_var = zdiag_var / areatot
+
+            IF(lwp) WRITE(numout,*) '   MEAN NO ', jn, ctrcnm(jn), ' = ', zdiag_var,   &
+               &                    ' MIN = ', zdiag_varmin, ' MAX = ', zdiag_varmax
+         END DO
+
+         zder = ( ( zdiag_tot - trai ) / trai ) * 100._wp
+         IF(lwp) WRITE(numout,*) '   Integral of all tracers over the full domain  = ', zdiag_tot
+         IF(lwp) WRITE(numout,*) '   Drift of the sum of all tracers =', zder, ' %'
+
+         CALL iom_close(numrtw)
+         !
+      ENDIF
+      !
+   END SUBROUTINE trc_rst_wri
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_rst_read                      ! Empty routines
+   END SUBROUTINE trc_rst_read
+   SUBROUTINE trc_rst_wri( kt )
+      INTEGER, INTENT ( in ) :: kt
+      WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_rst_wri   
+#endif
+
+   !!======================================================================
+END MODULE trcrst
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcsms.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcsms.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcsms.F90	(revision 4536)
@@ -0,0 +1,129 @@
+MODULE trcsms
+   !!======================================================================
+   !!                         ***  MODULE trcsms  ***
+   !! TOP :   Time loop of passive tracers sms
+   !!======================================================================
+   !! History :   1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_sms        :  Time loop of passive tracers sms
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trc             !
+   USE trccfc          ! CFC 11 & 12 
+   USE prtctl_trc      ! Print control for debbuging
+   USE trcbio
+   USE trcopt
+   USE trcsed
+   USE trcexp
+   USE p4zprg
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms    ! called in trcstp.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Header:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sms( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE ini_trc  ***
+      !!
+      !! ** Purpose :   Managment of the time loop of passive tracers sms 
+      !!
+      !! ** Method  : - ???
+      !! -------------------------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      IF ( MOD(kt,ndttrc) /= 0) RETURN      ! this ROUTINE is called only every ndttrc time step
+
+#if defined key_lobster
+
+      ! LOBSTER biological model
+      ! ------------------------
+
+      CALL trc_opt( kt )      ! optical model
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('OPT')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+
+      CALL trc_bio( kt )      ! biological model
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('BIO')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+
+      CALL trc_sed( kt )      ! sedimentation model
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('SED')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+ 
+      CALL trc_exp( kt )      ! export
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('EXP')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+
+#elif defined key_pisces
+
+      ! PISCES biological model
+      ! ------------------------
+
+      CALL p4z_prg( kt )      ! main program of PISCES 
+
+
+      !                      ! split in  SMS to be DONE here
+
+#elif defined key_cfc
+
+      ! CFC chemical model (code taken from K. Rodgers)
+      ! ------------------
+
+      IF( lk_cfc )   CALL trc_cfc( kt )      ! surface fluxes of CFC
+
+#endif
+
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sms ')")
+         CALL prt_ctl_trc_info( charout )
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+      !
+   END SUBROUTINE trc_sms
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                     No passive tracer
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_sms( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sms: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms
+#endif 
+
+   !!======================================================================
+END MODULE  trcsms
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcstp.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trcstp.F90	(revision 4536)
@@ -0,0 +1,81 @@
+MODULE trcstp
+   !!======================================================================
+   !!                       ***  MODULE trcstp  ***
+   !! TOP :   time stepping of TOP models (passive tracers)
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (C. Ethe) Original code
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_stp       : passive tracer system time-stepping
+   !!----------------------------------------------------------------------
+   USE oce_trc        ! ocean dynamics and active tracers variables
+   USE trc            ! ocean passive tracers variables 
+   USE trctrp         ! passive tracers transport
+   USE trcsms         ! passive tracers sources and sinks
+   USE prtctl_trc     ! Print control for debbuging
+   USE trcdia         ! passive tracer diagnostics
+   USE trcdit         ! ???
+   USE trcrst         ! ???
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_stp   ! called in step.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_stp( kt, kindic )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_stp  ***
+      !!                      
+      !! ** Purpose :   Time loop of TOP passive tracer
+      !! 
+      !! ** Method  :   Compute the passive tracers trends 
+      !!                Update the passive tracers
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kindic   ! ???
+      CHARACTER (len=25) :: charout
+      !!----------------------------------------------------------------------
+
+      IF( MOD( kt, ndttrc ) /= 0 )   RETURN            ! routine called only every ndttrc time step
+
+      IF(ln_ctl) THEN
+         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
+         CALL prt_ctl_trc_info(charout)
+      ENDIF
+
+                       CALL trc_rst_opn( kt )          ! Open tracer restart file 
+
+                       CALL trc_sms( kt )              ! sink and source of passive tracers
+
+                       CALL trc_trp( kt )              ! transport of passive tracers
+
+      IF( lrst_trc )   CALL trc_rst_wri( kt )          ! write tracer restart file
+
+                       CALL trc_dia( kt, kindic )      ! diagnostics
+      !
+   END SUBROUTINE trc_stp
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                          No TOP models
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_stp( kt )        ! Empty routine
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_stp
+#endif
+
+   !!======================================================================
+END MODULE trcstp
Index: /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trp_trc.F90
===================================================================
--- /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trp_trc.F90	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/NEMO/TOP_SRC/trp_trc.F90	(revision 4536)
@@ -0,0 +1,47 @@
+MODULE trp_trc
+   !!======================================================================
+   !!                         ***  MODULE trp_trc  ***
+   !! TOP :   TOP parameters used in TRP
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (C. Ethe) original code
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+
+   !! passive tracers number
+   USE par_trc, ONLY :   jptra    =>   jptra    !: number of passive tracers
+
+   !! passive tracers fields 
+   USE trc    , ONLY :   trai     =>   trai     !: initial total tracer
+   USE trc    , ONLY :   trb      =>   trb      !: tracer field (before)
+   USE trc    , ONLY :   tra      =>   tra      !: tracer field (now)
+   USE trc    , ONLY :   trn      =>   trn      !: tracer field (after)
+
+   !! time step
+   USE trc    , ONLY :   ndttrc   =>   ndttrc   !: frequency of step on passive tracers (NAMELIST)
+
+   !! non-centered advection scheme (smolarkiewicz)
+   USE trc    , ONLY :   rtrn     =>   rtrn     !: value for truncation (NAMELIST)
+   USE trc    , ONLY :   ctrcnm   =>   ctrcnm   !: value for truncation (NAMELIST)
+
+# if defined key_trc_diaadd
+   USE par_trc, ONLY :   jpdia2d  =>  jpdia2d   !: number of 2D passive tracers diag
+   USE par_trc, ONLY :   jpdia3d  =>  jpdia3d   !: number of 3D passive tracers diag
+   USE trc    , ONLY :   trc2d    =>   trc2d    !: additional 2D variable for ouputs
+   USE trc    , ONLY :   trc3d    =>   trc3d    !: additional 3D variable for ouputs
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE trp_trc
Index: /branches/2010_and_older/dev_001_GM/UTIL/fait_AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/UTIL/fait_AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/UTIL/fait_AA_make	(revision 4536)
@@ -0,0 +1,704 @@
+#!/bin/ksh
+#set -vx
+############################################################
+#
+# Purpose :
+# This script aims to create create the AA_make file
+# in the WORK directory. 
+# AA_make contains :
+#    - compilation options speccific to NEMO
+#    - compilation rules
+#    - dependancies
+# Running the modipsl/util/ins_make command is needed AFTER
+# fait_AA_make.
+#
+# Method :
+# We use temporary files to perform the following steps :
+#    1- search all CPP keys in the code
+#    2- write compilation rules 
+#    3- add compilation options add the beginning of AA_make 
+#    4- search and write dependancies
+#    5- add some specific rules (links creation in the WORK)
+#
+# Modification : - add F_F for .F file compiler option on aix
+#                - add KEY_CPP dependancy for source containing 
+#                              only #if defined CPP statement
+#
+############################################################
+#-
+echo "This script must be run while in the modipsl/modeles/NEMO directory"
+cd WORK
+pwd
+
+#-
+#- Search CPP keys ---
+liste_cle=$(egrep '^# *if[!( &]*def|^# *elif' *.[Fh] *.[Fh]90  2> /dev/null | grep key_ | sed 's/||/\
+/' | sed 's/\&\&/\
+/' | sed 's/^.*key_/key_/' | sed 's/ *[) ] *$//' | sort -u  )
+
+#-
+#- Write main compilation rules ---
+cat > tampon <<end
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all: 		diroce \$(EXEC_BIN)
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPA model is OK
+# Cleaning objects, libraries and executables
+clean:
+ifeq (\$(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		\$(RM) model.o \$(MODDIR)/oce/*.mod \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN)
+		@echo OPA model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/oce ] ; then mkdir ../../../lib/oce ; fi
+
+\$(EXEC_BIN) :	libioipsl firstagrif mpiagrif key keyverif src_file_list libagrif \$(MODEL_LIB) \$(IOIPSL_LIB) \$(AGRIF_LIB) agrif2model.o model.o
+ifeq (\$(AGRIF),use)
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model.o agrif2model.o \$(SXMODEL_LIB) \$(OASISMPI2_LIB) \$(IOIPSL_LIB) \$(AGRIF_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+else
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model.o \$(SXMODEL_LIB) \$(OASISMPI2_LIB) \$(IOIPSL_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+endif
+
+# Agrif library and conv
+libagrif :
+ifeq (\$(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../AGRIF ; \$(M_K) -f Makefile P_P="\$(AGRIF_MPI)" )
+	@cp -rf ../../AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../AGRIF/conv OPAFILES/. 
+	@cp -rf ../../AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq (\$(AGRIF),use)
+	@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+	@\$(F_C) \\
+#-Q- aix		-qsuffix=f=F90 \\
+#-Q- osxxlf		-qsuffix=f=F90 \\
+	\$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+	   OPAFILES/\$*.F90 || { mv \$(PREF).L \$(TMP) ; false ; exit ; }
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux			@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../IOIPSL/src ; \$(M_K) -f Makefile )
+
+# Main program
+model.o :	model.f90
+		@\$(F_C) \$(F_O) -c model.f90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : \$(MODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : \$(SXMODEL_LIB)
+
+# library dependancies
+\$(MODEL_LIB):	\$(LIB_OBJ)
+		@echo
+		@echo La bibliotheque est a jour
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+.f90.a :           
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		\$*.f90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) \$*.[of]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the .F90 files
+.F90.a :  
+ifeq (\$(AGRIF),use) 
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \\
+#-Q- linux		-SubloopScalar \\
+#-Q- lxiv8		-SubloopScalar \\
+#-Q- g95			-SubloopScalar \\
+#-Q- f95			-SubloopScalar \\
+#-Q- osf1			-SubloopScalar \\
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile \$*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC OPAFILES/\$*.F90 > OPAFILES/AGRIF_MODELFILES/\$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		OPAFILES/\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; } 
+else
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) \$*.[of]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the .F files
+.F.a :           
+ifeq (\$(AGRIF),use) 
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F > OPAFILES/\$*.F 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \\
+#-Q- linux		-SubloopScalar \\
+#-Q- lxiv8		-SubloopScalar \\
+#-Q- g95			-SubloopScalar \\
+#-Q- f95			-SubloopScalar \\
+#-Q- osf1			-SubloopScalar \\
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile \$*.F)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F OPAFILES/\$*.F
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC OPAFILES/\$*.F > OPAFILES/AGRIF_MODELFILES/\$*.F
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F OPAFILES/\$*.F
+		@\$(F_C) \$(P_P) \$(F_F) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		OPAFILES/\$*.F || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; } 
+else
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		\$*.F || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+endif
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) \$*.[of]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the library from the .f files 
+.f.a : 		
+		@\$(F_C) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sx8mercure		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+		\$*.f|| { if [ -f \$(PREF)\$*.L ] ; then mv \$*.L \$(TMP) ; fi ; false ; exit ; }
+#-Q- sxdkrz		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+#-Q- eshpux		@\$(A_X) \$(SXMODEL_LIB) \$*.o  > /dev/null
+		@\$(A_C) \$(MODEL_LIB) \$*.o  > /dev/null
+		@\$(RM) -f \$*.o
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux	@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$*.L \$(TMP) ; fi
+
+end
+#-
+#- Compilation options ---
+exec 1> AA_make
+MAIN="model"
+echo '# $Header$'
+echo '# some variables'
+echo 'TMP = ../../../tmp'
+echo '#-Q- sx8mercure  # Compiler options NEMO (CEA SX6-NEC) '
+echo '#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -C vopt -Wf"-P nh" -Wf',-pvctl noassume loopcnt=10000 -L transform' -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- sx8mercure  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- sx8mercure  F_F = $(F_O) -f3'
+echo '#-Q- sx8mercure  L_X = $(L_O) -ftrace'
+echo '#-Q- sx8brodie  # Compiler options NEMO (CEA SX6-NEC) '
+echo '#-Q- sx8brodie  F_O = -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- sx8brodie  F_F = $(F_O) -f3'
+echo '#-Q- sx8brodie  L_X = $(L_O)'
+echo '#-Q- sxdkrz  # Compiler options for NEMO (DKRZ SX6-NEC) '
+echo '#-Q- sxdkrz  F_O = -ew -sx6 -ftrace -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- sxdkrz  F_F = $(F_O) -f3'
+echo '#-Q- sxdkrz  L_X = $(L_O) -ftrace'
+echo '#-Q- eshpux  # Compiler options for NEMO (Earth Simulator)'
+echo '#-Q- eshpux  # for super perfs!'
+echo '#-Q- eshpux  # F_O = $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- eshpux  # regular options!'
+echo '#-Q- eshpux  F_O = $(FTRACE) -Wf,-A idbl4 -C vopt -P stack -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- eshpux  F_F = $(F_O) -f3'
+echo '#-Q- eshpux  L_X = $(L_O)'
+echo '#-Q- linux  # Compiler options for NEMO (pgf version)'
+echo '#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- linux  F_F = $(F_O)'-Mextend
+echo '#-Q- linux  L_X = -r8 -O3'
+echo '#-Q- lxiv7  # Compiler options for NEMO (ifc version)'
+echo '#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- lxiv7  F_F = $(F_O) -extend_source '
+echo '#-Q- lxiv7  L_X = -r8 -O3'
+echo '#-Q- lxiv8  # Compiler options for NEMO (ifort version)'
+echo '#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- lxiv8  F_F = $(F_O) -extend_source '
+echo '#-Q- lxiv8  L_X = -r8 -O3'
+echo '#-Q- g95  # Compiler options for NEMO (g95 version)'
+echo '#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)'
+echo '#-Q- g95  F_F = $(F_O)'-ffixed-form -ffixed-line-length-132
+echo '#-Q- g95  L_X = -r8 -O3'
+echo '#-Q- aix    # Compiler options for NEMO (aix version)'
+echo '#-Q- aix    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)' 
+echo '#-Q- aix    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)' 
+echo '#-Q- aix   L_O = $(F_P) -q64 -O3'
+echo '#-Q- aix   L_X = $(L_O)'
+echo '#-Q- osxxlf    # Compiler options for NEMO (osxxlf version)'
+echo '#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)' 
+echo '#-Q- osxxlf    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODDIR)/oce -I $(NCDF_INC)' 
+echo '#-Q- osxxlf    L_X = -qrealsize=8 -O3'
+
+echo 'PREF='
+echo '#-Q- sx8mercure	PREF=i.'
+echo '#-Q- sx8brodie	PREF=i.'
+echo '#-Q- sxdkrz	PREF=i.'
+echo '#-Q- eshpux	PREF=i.'
+echo ''
+echo '# add suffix to P_P'
+echo 'P_P := $(P_P:%=$(prefix)%)'
+echo ''
+echo '# Some tests to define variables related to Agrif compilation'
+echo '# Please do not change '
+echo 'ifneq (,$(findstring key_agrif,$(P_P)))'
+echo 'AGRIF=use'
+echo 'else'
+echo 'AGRIF=notuse'
+echo 'AGRIF_LIB='
+echo 'endif'
+echo 'ifneq (,$(findstring key_mpp_mpi,$(P_P)))'
+echo 'AGRIF_MPI=-DAGRIF_MPI'
+echo 'else'
+echo 'AGRIF_MPI='
+echo 'endif'
+
+echo ''
+# Write the cpp key list with one key by line
+echo 'KEY_LIST = \c'
+for i in ${liste_cle}
+do
+ echo "\\"
+ echo "     $i \c"
+done
+
+echo ''
+echo '# .o file list in the library'
+echo 'LIB_OBJ = \c'
+#
+# find all .f in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.f 2> /dev/null`
+do
+  bn=`basename $i .f`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+done
+
+# find all .f90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.f90  `
+do
+  bn=`basename $i .f90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+done
+
+# find all .F90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.F90  `
+do
+  bn=`basename $i .F90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+done
+
+# find all .F in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.F 2> /dev/null `
+do
+  bn=`basename $i .F`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)($bn.o)\c"
+  fi
+  fi
+ done
+
+echo ""
+
+cat tampon
+rm tampon
+#-
+#- Write all dependancies ---
+
+for fic in `ls *.f90 *.F90  *.F 2> /dev/null `
+do
+    if [ "${fic}" != "agrif2model.F90" ]
+    then
+    if [ "${fic}" != "${MAIN}.[Ff]" ]
+    then
+	i=0
+	j=0
+	dep=""
+	inc=""
+	inc2=""
+	inc3=""
+	luse0=""
+	luse1=""
+	luse2=""
+	luse3=""
+        key=""
+#- search include files (old ice model form, should it be suppressed ?)
+	for inc in `sed -n 's/^[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    dep="$dep\n$inc"
+	done
+
+#- take into account CPP dependancies  keys only (par_trc_trp example)
+	for key in `sed -n 's/^#[ 	eElL]*[iF][fF][ 	]*[dD][eE][fF][iI][nN][eE][dD][ 	]*//p' $fic | sort -u`
+	do
+	    j=1
+	done
+
+#- search include files on 3 levels
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    j=1
+	    dep="$dep\n$inc"
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    dep="$dep\n$inc2"
+		    #- search include  in include (third level !!!)
+		    for inc3 in `sed -n 's/^#[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc2 | sort -u`
+		    do
+			dep="$dep\n$inc3"
+		    done
+		done
+	done
+
+#- search USE in include files
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+		for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc | sort -u`
+		do
+	        if [ $fuse0 != "ioipsl" ] 
+                then
+                if [ $fuse0 != "Agrif_Util" ] 
+                then
+                if [ $fuse0 != "Agrif_Types" ] 
+                then
+                if [ $fuse0 != "netcdf" ] 
+                then
+		    lfuse0=$fuse0.f90
+		    [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		    luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)($fuse0.o)"
+                fi
+                fi
+                fi
+                fi
+		done
+
+#- search USE in  files included in included files and add to luse0
+
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc2 | sort -u`
+		    do
+	            if [ $fuse0 != "ioipsl" ] 
+                    then
+                    if [ $fuse0 != "Agrif_Util" ] 
+                    then
+                    if [ $fuse0 != "Agrif_Types" ] 
+                    then
+                    if [ $fuse0 != "netcdf" ] 
+                    then
+		        lfuse0=$fuse0.f90
+		        [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		        luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)($fuse0.o)"
+                    fi
+                    fi
+                    fi
+                    fi
+		    done
+  	        done
+	done
+
+#- search USE (and USE of USE and so on three levels)
+	for fuse1 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $fic | sort -u`
+	do
+	if [ $fuse1 != "ioipsl" ] 
+        then
+        if [ $fuse1 != "Agrif_Util" ] 
+        then
+        if [ $fuse1 != "Agrif_Types" ] 
+        then
+        if [ $fuse1 != "netcdf" ] 
+        then
+	    lfuse1=$fuse1.f90
+	    [ -f $fuse1.F90 ] && lfuse1=$fuse1.F90
+	    luse1="$luse1\n$lfuse1\n\$(MODEL_LIB)($fuse1.o)"
+		for fuse2 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse1 | sort -u`
+		do
+	        if [ $fuse2 != "ioipsl" ] 
+                then
+                if [ $fuse2 != "Agrif_Util" ] 
+                then
+                if [ $fuse2 != "Agrif_Types" ] 
+                then
+                if [ $fuse2 != "netcdf" ] 
+                then
+		    lfuse2=$fuse2.f90
+		    [ -f $fuse2.F90 ] && lfuse2=$fuse2.F90
+		    luse2="$luse2\n$lfuse2\n\$(MODEL_LIB)($fuse2.o)"
+		    # on cherche les USE  dans le fichier deja USE (3eme niveau! balaise!)
+		    for fuse3 in `sed -n 's/^#[  	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse2 | sort -u`
+		    do
+		    if [ $fuse3 != "ioipsl" ] 
+                    then
+                    if [ $fuse3 != "Agrif_Util" ] 
+                    then
+                    if [ $fuse3 != "Agrif_Types" ] 
+                    then
+                    if [ $fuse3 != "netcdf" ] 
+                    then
+			luse3="$luse3\n$lfuse3\n\$(MODEL_LIB)($fuse3.o)"
+                    fi		    
+                    fi		    
+                    fi		    
+                    fi		    
+                    done
+                fi
+                fi
+                fi
+                fi
+		done
+        fi
+        fi
+        fi
+        fi
+	done
+#-
+#-  dep contains all dependancies 
+	echo "\$(MODEL_LIB)(`echo $fic|awk -F. '{print $1}'`.o) :	\c"
+	for depele in `echo $luse3 | sort -u` `echo $luse2 | sort -u` `echo $luse1 | sort -u` `echo $luse0 | sort -u` `echo $dep | sort -u`
+	do
+	    echo "\\"
+ 	    echo "	$depele \c"
+ 	    let i=i+1 # pour signaler le premier
+	done
+
+#-
+#- add dependancies with IOIPSL library (if source files contains IOIPSL)
+        grep -i 'use *ioipsl' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(IOIPSL_LIB) \c")
+
+#-
+#- add dependancies with IOIPSL library (if source files contains Agrif_*)
+        grep -i 'use Agrif_*' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(AGRIF_LIB) \c")
+
+#-
+#- add dependancies with KEY_CPP (if source file includes cpp  keys)
+	if [ ${j} != "0" ] 
+        then 
+	  echo "\\"
+	  echo "	KEY_CPP \c" 
+	fi
+#-
+#- end with the file itself
+	     echo "\\"
+       	     echo "	$fic"
+    fi
+    fi
+echo $fic done >/dev/tty
+done
+#-
+#- Write some special rules ---
+echo '# agrif previous use'
+echo "firstagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo '	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "else"
+echo '	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "endif"
+#-
+echo '#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp'
+echo '#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC'
+echo '# recompile all in this case' 
+echo "mpiagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo "ifeq (,\$(AGRIF_MPI))"
+echo '	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce/*.mod $(MODEL_LIB) $(SXMODEL_LIB); fi'
+echo "endif"
+echo "endif"
+#-
+echo '# key changing control'
+echo "key: "
+echo "	@echo CHANGE of CPP KEYS yes/no ?"
+echo "	-@if [ \"\`cat KEY_CPP\`\" != \"\$(P_P:\$(prefix)%=%)\" ] ; then \\"
+echo "		echo CPP options changed ; echo \"\$(P_P:\$(prefix)%=%)\" > KEY_CPP ; fi "
+#-
+echo '# check key values'
+echo "keyverif:"
+echo '	@echo CHECKING KEY'
+echo '	@echo KEY USED : '
+echo '	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \'
+echo '	do \'
+echo '	echo $$v ;\'
+echo '        w=`echo $$v | cut -c1-3` ; \'
+echo '        if [ $$w = `echo "key"` ] ; then \'
+echo '        r=n ; \'
+echo '        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \'
+echo '           if [ $$r != "n" ] ; then \'
+echo '              echo "UNKNOWN KEY" ;\'
+echo '              false ;  \'
+echo '              exit ;  \'
+echo '           fi \'
+echo '        fi \'
+echo '	done'
+echo '# Checking the number of routines'
+echo "src_file_list: "
+echo '	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES '
+echo '	@$(RM) `ls | fgrep -v -f .patron` '
+echo '	@check=`grep OPA_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OPA_SRC files"                ; \'
+echo '	    ln -sf ../OPA_SRC/*.[Ffh]90          . ; \'
+echo '	    ln -sf ../OPA_SRC/DYN/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/TRA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/TRD/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/DIA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/DOM/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/OBC/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/FLO/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/LDF/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/ZDF/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/SOL/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/DTA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/SBC/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../OPA_SRC/IOM/*.[Ffh]90      . ; \'
+echo '  fi '
+echo '	@check=`grep LIM_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use LIM_SRC files"                ; \'
+echo '      ln -sf ../LIM_SRC/*.[Ffh]90          . ; \'
+echo '  fi '
+echo '	@check=`grep C1D_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use C1D_SRC files"                ; \'
+echo '      ln -sf ../C1D_SRC/*.[Ffh]90          . ; \'
+echo '  fi '
+echo '	@check=`grep TOP_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then  \'
+echo '	echo "   use TOP_SRC files"                ; \'
+echo '      \$(RM) trcstp.F90                      ; \'
+echo '      \$(RM) sms.F90                         ; \'
+echo '      \$(RM) initrc.F90                      ; \'
+echo '      ln -sf ../TOP_SRC/*.[Ffh]90          . ; \'
+echo '      ln -sf ../TOP_SRC/TRP/*.[Ffh]90      . ; \'
+echo '      ln -sf ../TOP_SRC/PISCES/*.[Ffh]90   . ; \'
+echo '      ln -sf ../TOP_SRC/LOBSTER/*.[Ffh]90  . ; \'
+echo '      ln -sf ../TOP_SRC/CFC/*.[Ffh]90      . ; \'
+echo '      ln -sf ../TOP_SRC/C14b/*.[Ffh]       . ; \'
+echo '      ln -sf ../TOP_SRC/MY_TRC/*.[Ffh]90   . ; \'
+echo '      ln -sf ../TOP_SRC/DUMMY/*.[Ffh]90    . ; \'
+echo '  fi '
+echo '	@check=`grep OFF_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OFF_SRC files"                ; \'
+echo '      ln -sf ../OFF_SRC/*.[Ffh]90          . ; \'
+echo '      ln -sf ../OFF_SRC/*/*.[Ffh]90        . ; \'
+echo '  fi '
+echo '	@check=`grep NST_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use NST_SRC files"                ; \'
+echo '      \$(RM) agrif_opa_interp.F90           ; \'
+echo '      \$(RM) agrif_opa_sponge.F90           ; \'
+echo '      \$(RM) agrif_opa_update.F90           ; \'
+echo '      ln -sf ../NST_SRC/*.[Ffh]90      .     ; \'
+echo '  fi '
+echo '	@\$(RM) tmplist'
+echo '	@ls -1 | fgrep -v -f .patron  >tmplist'
+echo '	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \'
+echo '	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \'
+echo '	\$(RM) model.o \$(MODEL_LIB) \$(SXMODEL_LIB) \$(EXEC_BIN) ; \'
+echo '	echo "Rebuilding the AA_make files" ; \'
+echo '	cd ..  ; ../UTIL/fait_AA_make ; echo " " ; \'
+echo '	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \'
+echo '	echo "========================================== " ; \'
+echo '	../../util/ins_make ; echo " " ;  false ; exit ; }'
+exec > /dev/null
+
Index: /branches/2010_and_older/dev_001_GM/UTIL/fait_config
===================================================================
--- /branches/2010_and_older/dev_001_GM/UTIL/fait_config	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/UTIL/fait_config	(revision 4536)
@@ -0,0 +1,174 @@
+#!/bin/ksh
+######################################################
+# Author : Rachid benshila for ESOPA
+# Contact : opatlod@lodyc.jussieu.fr
+#
+# This script aims to create the OPA/WORK directory 
+# with links to target directories for the sources
+# and to link in the WORK the BB_make and BB_make.ldef 
+# associated  to a chosen configuration
+#
+######################################################
+
+###################################
+#                                 #
+# Beginning of user modifications #
+#                                 #
+###################################
+#- Config name ---
+# To add a new configuration called NAME you have to change this script
+# 1. Add your configuration in LIST
+# 2. Add the directories needed for this config : set -A DIR_NAME DIR1 DIR2 ...
+# 3. Run fait_config NAME
+# If there is no directory config/NAME/scripts, and in this no BB_make.ldef, 
+# the config/ORCA2_LIM directory is copied under NAME
+#
+# Example 1 : in order to create a GYRE_TRC configuration :
+# 1. In this script, change LIST to LIST="ORCA2_LIM \nGYRE \nGYRE_TRC"
+# 2. In this script, add set -A DIR_GYRE_TRC OPA_SRC LIM_SRC TOP_SRC C1D_SRC, take care of the syntax
+# 3. Run fait_config GYRE_TRC
+# Example 2 : in order to create an OFFLINE_TRC configuration :
+# 1. In this script, change LIST to LIST="ORCA2_LIM \nGYRE \nOFFLINE_TRC"
+# 2. In this script, add set -A DIR_OFFLINE_TRC OFF_SRC TOP_SRC, take care of the syntax
+# 3. Run fait_config OFFLINE_TRC
+
+LIST="ORCA2_LIM \nGYRE \nORCA2_LIM_TRC \nOFFLINE_TRC"
+set -A DIR_ORCA2_LIM OPA_SRC LIM_SRC C1D_SRC NST_SRC
+set -A DIR_GYRE OPA_SRC LIM_SRC C1D_SRC 
+set -A DIR_ORCA2_LIM_TRC OPA_SRC LIM_SRC C1D_SRC TOP_SRC 
+set -A DIR_OFFLINE_TRC OFF_SRC TOP_SRC
+
+###################################
+#                                 #
+#    End of user modifications    #
+#                                 #
+###################################
+
+
+#- Some tests ---
+d_n=$(dirname $0); b_n=$(basename $0);
+
+if   [ ${#} -gt 1 ]; then
+    echo 'Only one configuration can be specified in:' 1>&2;
+    echo $LIST 1>&2;
+    exit 3;
+elif [ ${#} -eq 1 ]; then
+     m_n="${1}"
+elif [ ${#} -eq 0 ]; then
+    echo 'You must specify one configuration in :' 1>&2;
+    echo $LIST 1>&2;
+    echo 'You can also complete fait_config to add a new one'
+    exit 3;
+fi
+
+#- Create the WORK --
+d_m=`find ${d_n}/.. -name NEMO`  ;
+[ -d ${d_m}/WORK ] || mkdir ${d_m}/WORK;
+cd ${d_m}/WORK
+
+#- Clean links and librairies
+[ -f Makefile ] && gmake clean 
+[ -n "`\ls`" ] && \rm -rf * 
+
+#- Find the number of directories ---
+eval NDIR=\${#DIR_${m_n}[*]}
+
+#- Build a working array TAB containing the directories ---
+i=0
+while [ i -lt $NDIR ]
+do
+    eval  TAB[i]=\${DIR_${m_n}[i]}
+    let i=i+1
+done
+
+#- Creating the good links, at first on OPA_SRC ---
+if [ ${#TAB[*]} -ne 0 ] ; then
+    echo " Creating NEMO/WORK = ${TAB[*]} for ${m_n}"
+
+    i=0
+    while [ i -lt $NDIR ]
+    do
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../OPA_SRC/*.[Ffh]90 .
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../OPA_SRC/*/*.[Ffh]90 . && break
+	let i=$i+1
+    done
+
+    i=0
+    while [ i -lt $NDIR ]
+    do
+      if [ "${TAB[i]}" = "LIM_SRC" ]; then
+	  ln -sf ../LIM_SRC/*.[Ffh]90 .  
+      
+      elif [ "${TAB[i]}" = "C1D_SRC" ]; then
+	  ln -sf ../C1D_SRC/*.[Ffh]90 .  
+      
+      elif [ "${TAB[i]}" = "TOP_SRC" ]; then
+	  [ -f  trcstp.F90 ] && \rm trcstp.F90                    
+	  [ -f  sms.F90 ] && \rm sms.F90                    
+	  [ -f  initrc.F90 ] && \rm initrc.F90                    
+	  ln -sf ../TOP_SRC/*.[Ffh]90 .       
+	  ln -sf ../TOP_SRC/TRP/*.[Ffh]90 .        
+	  ln -sf ../TOP_SRC/PISCES/*.[Ffh]90 .  
+	  ln -sf ../TOP_SRC/LOBSTER/*.[Ffh]90 .
+	  ln -sf ../TOP_SRC/CFC/*.[Ffh]90 .        
+	  ln -sf ../TOP_SRC/C14b/*.[Ffh]90 .  
+	  ln -sf ../TOP_SRC/MY_TRC/*.[Ffh]90 .
+	  ln -sf ../TOP_SRC/DUMMY/*.[Ffh]90 .
+      
+      elif [ "${TAB[i]}" = "NST_SRC" ]; then
+	  [ -f  agrif_opa_interp.F90 ] && \rm agrif_opa_interp.F90                    
+	  [ -f  agrif_opa_sponge.F90 ] && \rm agrif_opa_sponge.F90                    
+	  [ -f  agrif_opa_update.F90 ] && \rm agrif_opa_update.F90                    
+	  ln -sf ../NST_SRC/*.[Ffh]90 .
+      
+      elif [ "${TAB[i]}" = "OFF_SRC" ]; then  
+	  ln -sf ../OFF_SRC/*.[Ffh]90 .
+	  ln -sf ../OFF_SRC/*/*.[Ffh]90 .
+      fi
+      let i=$i+1
+    done
+
+    [ ! -d ../../../config/${m_n} ] && \cp -R ../../../config/ORCA2_LIM ../../../config/${m_n} 
+    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make ; 
+    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
+
+else
+
+    echo "Configuration "${m_n}" not supported" 1>&2
+    echo 'Make your choice in :' 1>&2
+    echo $LIST 1>&2
+    echo 'You can also complete fait_config to add a new one'
+    exit 1
+
+fi 
+
+#- Building the standard list of source files ---
+cat >.patron <<"EOF" 
+CVS
+SRC_PARAM
+SRC_FILE_LIST
+tmplist
+AA_make
+KEY_CPP
+Makefile
+*?.o
+ i.?*
+*?.L
+.patron
+bloc.com
+para.com
+defcst.f
+fontbc.f
+icdyna.f
+thersf.f
+OPAFILES
+EOF
+ls -1 | fgrep -v -f .patron  >SRC_FILE_LIST ; cp SRC_FILE_LIST SRC_FILE_LIST.temp ;
+
+#- Writing KEY_CPP file ---
+sed -e /^P_P/\!d -e "s/P_P = //" AA_make.ldef > KEY_CPP;    
+
+#- Save new configuration an d directories names ---
+print ${m_n} ${TAB[*]} >.config 
+
+exit 0;
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make	(revision 4536)
@@ -0,0 +1,87 @@
+# $Header: /home/opalod/NEMOCVSROOT/CONFIG/ORCA2_LIM/AA_make,v 1.4 2005/03/23 10:07:37 opalod Exp $
+all: ioipsl $(RUN)
+
+ioipsl:
+#-Q- sx8brodie	(cd ../../modeles/IOIPSL/src; sxgmake;)
+#-Q- aix	(cd ../../modeles/IOIPSL/src; gmake;)
+
+$(filter-out mpi omp, $(RUN)): omp
+#-Q- aix	../../util/ins_make -t ax_mono -w $(NEMOLIB)/WORK
+	gmake -C WORK COMP=$@ clean > $(NEMOLIB)_logbook_$@.txt
+	gmake -C WORK COMP=$@ >> $(NEMOLIB)_logbook_$@.txt
+
+	cp ../../bin/opa_$(NEMOLIB)_$@  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/opa_$(NEMOLIB)_$@
+	cp ../VALID/2INSTALL/JOBS/job_$(NEMOLIB).ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/job_$(NEMOLIB).ksh
+	cp -p ../VALID/2INSTALL/JOBS/lance_batch.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/lance_batch.ksh
+	cp -p ../VALID/2INSTALL/JOBS/assessment.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/assessment.ksh
+	cp -p ../VALID/2INSTALL/JOBS/cron_jobs.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/cron_jobs.ksh
+	cp -p  specifs.txt $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/specifs.txt
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/jhd_sx8brodie_mon  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_sx8brodie_mon
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_sx8brodie.ksh
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_sx8brodie.ksh
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/jhd_ax_mono_mon  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_ax_mono_mon
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/CPU_time_aix.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_aix.ksh
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/MEM_size_aix.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_aix.ksh
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/jhd_osxxlf_mon  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_osxxlf_mon
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/CPU_time_osxxlf.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_osxxlf.ksh
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/MEM_size_osxxlf.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_osxxlf.ksh
+	( cd $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/ ; ./lance_batch.ksh $(NEMOLIB) $(MKTE) $(RTG) ; )
+
+omp: mpi
+ifeq ($(filter omp,$(RUN)),omp)
+	gmake -C WORK COMP=$@ clean > $(NEMOLIB)_logbook_$@.txt
+	gmake -C WORK COMP=$@ >> $(NEMOLIB)_logbook_$@.txt
+
+	cp ../../bin/opa_$(NEMOLIB)_$@  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/opa_$(NEMOLIB)_$@
+	cp ../VALID/2INSTALL/JOBS/job_$(NEMOLIB).ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/job_$(NEMOLIB).ksh
+	cp -p ../VALID/2INSTALL/JOBS/lance_batch.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/lance_batch.ksh
+	cp -p ../VALID/2INSTALL/JOBS/assessment.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/assessment.ksh
+	cp -p ../VALID/2INSTALL/JOBS/cron_jobs.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/cron_jobs.ksh
+	cp -p  specifs.txt $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/specifs.txt
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/jhd_sx8brodie_omp  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_sx8brodie_omp
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_sx8brodie.ksh
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_sx8brodie.ksh
+	( cd $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/ ; ./lance_batch.ksh $(NEMOLIB) $(MKTE) $(RTG) ; )
+else
+	@echo 'No omp compilation'
+endif
+
+mpi: memo
+ifeq ($(filter mpi,$(RUN)),mpi)
+#-Q- aix	../../util/ins_make -t aix -w $(NEMOLIB)/WORK
+	cp ./MY_SRC/par_oce.F90_keep ./MY_SRC/par_oce.F90 
+	gmake -C WORK COMP=$@ clean > $(NEMOLIB)_logbook_$@.txt
+	gmake -C WORK COMP=$@ >> $(NEMOLIB)_logbook_$@.txt
+	rm -f ./MY_SRC/par_oce.F90
+
+	cp ../../bin/opa_$(NEMOLIB)_$@  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/opa_$(NEMOLIB)_$@
+	cp ../VALID/2INSTALL/JOBS/job_$(NEMOLIB).ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/job_$(NEMOLIB).ksh
+	cp -p ../VALID/2INSTALL/JOBS/lance_batch.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/lance_batch.ksh
+	cp -p ../VALID/2INSTALL/JOBS/assessment.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/assessment.ksh
+	cp -p ../VALID/2INSTALL/JOBS/cron_jobs.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/cron_jobs.ksh
+	cp -p  specifs.txt $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/specifs.txt
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/jhd_sx8brodie_mpi  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_sx8brodie_mpi
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_sx8brodie.ksh
+#-Q- sx8brodie	cp ../VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_sx8brodie.ksh
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/jhd_aix_mpi  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_aix_mpi
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/CPU_time_aix.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_aix.ksh
+#-Q- aix	cp ../VALID/2INSTALL/JOBS/MEM_size_aix.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_aix.ksh
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/jhd_osxxlf_mpi  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/jhd_osxxlf_mpi
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/CPU_time_osxxlf.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/CPU_time_osxxlf.ksh
+#-Q- osxxlf	cp ../VALID/2INSTALL/JOBS/MEM_size_osxxlf.ksh  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/MEM_size_osxxlf.ksh
+	( cd $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/$@/ ; ./lance_batch.ksh $(NEMOLIB) $(MKTE) $(RTG) ; )
+
+else
+	@echo 'No mpi compilation'
+endif
+
+clean:
+	(cd ../../config/$(NEMOLIB)/WORK;  gmake clean ;)
+
+memo:
+#-Q- aix	../../util/ins_make -t ax_mono -w $(NEMOLIB)/WORK
+	gmake -C WORK COMP=$@ clean > $(NEMOLIB)_logbook_$@.txt
+	gmake -C WORK COMP=$@ >> $(NEMOLIB)_logbook_$@.txt
+
+	cp ../../bin/opa_$(NEMOLIB)_$@  $(WWDIR)/NEMO_VALID/W$(NEMOLIB)/opa_$(NEMOLIB)_$@
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make.ldef
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make.ldef	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/AA_make.ldef	(revision 4536)
@@ -0,0 +1,16 @@
+#---------------------------------------------------------------------
+#- Creation des elements relatifs a ORCA :
+#-      ORCA  (lib, executable : opa)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#---------------------------------------------------------------------
+LIBDIR = ../../../../lib
+BINDIR = ../../../../bin
+MODDIR = $(LIBDIR)
+NEMOLIB := $(shell awk '{ print $$1 }' ./WORK/.config)
+RUN=
+RTG=
+MKTE=
+WWDIR=/Users/ctlod/WORK/AZE/modipsl/config
+#---------------------------------------------------------------------
+#-
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_GYRE
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_GYRE	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_GYRE	(revision 4536)
@@ -0,0 +1,54 @@
+#---------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model (BB_make.ldef in scripts)
+#---------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+MODDIR = $(LIBDIR)
+NEMOLIB := $(shell awk '{ print $$1 }' .config)
+COMP=
+MODEL_LIB = $(LIBDIR)/oce_$(NEMOLIB)/$(COMP)
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxnec  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sx6nec  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sxdkrz  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxnec  AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sx6nec AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sxdkrc AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxnec  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sx6nec  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sxdkrz  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opa_$(NEMOLIB)_$(COMP)
+NBPRC = 6
+
+#-
+#- Key options for GYRE ocean configuration: Analytical forcing ---
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P = key_zco key_gyre key_dynspg_flt key_ldfslp key_zdftke key_vectopt_loop key_vectopt_memory   
+
+#-
+#- Prefix for preprocessing ---
+#-Q- sxnec  prefix = -D
+#-Q- sx6nec prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- ax_mono    prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ORCA2_LIM
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ORCA2_LIM	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ORCA2_LIM	(revision 4536)
@@ -0,0 +1,54 @@
+#----------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model + Sea Ice Model   (BB_make.ldef in scripts)
+#----------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+NEMOLIB := $(shell awk '{ print $$1 }' .config)
+COMP=
+MODDIR = $(LIBDIR)
+MODEL_LIB = $(LIBDIR)/oce_$(NEMOLIB)/$(COMP)
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxnec  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sx6nec IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sxdkrz IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxnec  AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sx6nec AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sxdkrc AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxnec  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sx6nec SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sxdkrz SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opa_$(NEMOLIB)_$(COMP)
+NBPRC = 6
+
+#-
+#- Key options for OPA ocean model + LIM sea ice model : ORCA_R2 - FORCED (CLIO)
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P = key_trabbl_dif key_vectopt_loop key_vectopt_memory key_orca_r2 key_ice_lim key_lim_fdd key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_dtatem key_dtasal key_tau_monthly key_flx_bulk_monthly key_trabbc key_zdftke key_zdfddm
+
+#-
+#- Prefix for preprocessing ---
+#-Q- sxnec  prefix = -D
+#-Q- sx6nec prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- ax_mono    prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ZAGRIF
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ZAGRIF	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/CONFIG_FILES/BB_make.ldef_ZAGRIF	(revision 4536)
@@ -0,0 +1,54 @@
+#----------------------------------------------------------------------
+#- NEMO SYSTEM : Ocean model + Sea Ice Model   (BB_make.ldef in scripts)
+#----------------------------------------------------------------------
+SHELL = /bin/sh
+#-
+#-Q- t3e     #--- Please use gmake instead of make
+#-Q- fjvpp   #--- Please use gmake instead of make
+
+#-
+#- Define the libraries ---
+LIBDIR = ../../../lib
+NEMOLIB := $(shell awk '{ print $$1 }' .config)
+COMP=
+MODDIR = $(LIBDIR)
+MODEL_LIB = $(LIBDIR)/oce_$(NEMOLIB)/$(COMP)
+IOIPSL_LIB = $(LIBDIR)/libioipsl.a
+#-Q- sxnec  IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sx6nec IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+#-Q- sxdkrz IOIPSL_LIB = $(LIBDIR)/libsxioipsl.a
+AGRIF_LIB = $(LIBDIR)/libagrif.a
+#-Q- sxnec  AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sx6nec AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+#-Q- sxdkrc AGRIF_LIB = $(LIBDIR)/libsxagrif.a
+SXMODEL_LIB = $(MODEL_LIB)
+#-Q- sxnec  SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sx6nec SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+#-Q- sxdkrz SXMODEL_LIB = $(LIBDIR)/oce/libsxopa.a
+OASISMPI2_LIB = 
+LIBMPI  =
+LIBMP   =
+EXEC_BIN = ../../../bin/opa_$(NEMOLIB)_$(COMP)
+NBPRC = 1
+
+#-
+#- Key options for OPA ocean model + LIM sea ice model : ORCA_R2 - FORCED (CLIO)
+#  Keys have to be written on one single line (does NOT accept "\")
+
+P_P = key_trabbl_dif key_vectopt_loop key_vectopt_memory key_orca_r2 key_ice_lim key_lim_fdd key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_dtatem key_dtasal key_tau_monthly key_flx_bulk_monthly key_trabbc key_zdftke key_zdfddm key_agrif
+
+#-
+#- Prefix for preprocessing ---
+#-Q- sxnec  prefix = -D
+#-Q- sx6nec prefix = -D
+#-Q- sx8brodie prefix = -D
+#-Q- eshpux prefix = -D
+#-Q- sxdkrz prefix = -D
+#-Q- linux  prefix = -D
+#-Q- lxiv7  prefix = -D
+#-Q- lxiv8  prefix = -D
+#-Q- g95    prefix = -D
+#-Q- aix    prefix = -WF,-D
+#-Q- ax_mono    prefix = -WF,-D
+#-Q- osxxlf prefix = -WF,-D
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_aix.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_aix.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_aix.ksh	(revision 4536)
@@ -0,0 +1,173 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zrunt  : run type to treat
+#     - zfile1 : mon run timing input file name
+#     - zfile2 : mpi run timing input file name
+#     - zconf  : configuration name
+#     - zout   : output file name
+#     - ztag   : tag name to which are compared files
+#     - zxis   : (0/1) reference timing files (do/do not) exist
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the aix target for 
+#        mon & mpi run 
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-r] [-a] [-b] [-c] [-o] [-t] [-x]"
+  echo "Options: These are optional argument"
+  echo " -r : run type to treat"
+  echo " -a : current version timing input file name"
+  echo " -b : reference version timing input file name"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " -x : (0/1) reference timing files (do/do not) exist"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zrunt=
+zfile1=
+zfile2=
+zconf=
+zout=
+ztag=
+zxis=1
+
+# Get arguments
+while getopts r:a:b:c:o:t:x: opt
+do
+  case "$opt" in
+    r) zrunt="$OPTARG";;
+    a) zfile1="$OPTARG";;
+    b) zfile2="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    x) zxis="$OPTARG";;
+    *) help_CPU_time;;
+  esac
+done
+
+# Check if results must be compare to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+case "${zrunt}" in
+
+     'mon' )
+
+           # OUTPUT TIMING OF THE MON RUN
+           ##############################
+           
+           if [ ${evaltag} -a ${zxis} == 0 ] ; then
+               # Get values from the reference tag
+               zreal=$( (awk '/wall clock time/           {print $6}' ${zfile2} ) )
+               zuser=$( (awk '/Total amount of time in u/ {print $9}' ${zfile2} ) )
+               zmemo=$( (awk '/Maximum resident set size/ {print $6/1024}' ${zfile2} ) )
+               zuzra=$( (awk '/Utilization rate/          {print $4}' ${zfile2} ) )
+               zcoin=$( (awk '/Computation intensity/     {print $4}' ${zfile2} ) )
+               # Print: Variable long name | current version values | reference version values | variations
+               echo "                                                 Current version     ${ztag} version       Variation " >> ${zout}
+               echo "                                                                 " >> ${zout}
+               awk '/wall clock time/            { creal=$6      ; printf("%-6s %.33s %8s %12.2f    | %12.2f      |     %7.2f % \n", " ", $0, "(sec) :"    , $6  , invar, ((creal-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '/Total amount of time in u/  { cuser=$9      ; printf("%-6s %.34s %7s %12.2f    | %12.2f      |     %7.2f % \n", " ", $0, "(sec) :"    , $9  , invar, ((cuser-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '/Maximum resident set size/  { cmflo=$6/1024 ; printf("%-6s %.26s %15s %12.2f    | %12.2f      |     %7.2f % \n", " ", $0, "(Mo) :"     ,cmflo, invar, ((cmflo-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout}
+               awk '/Utilization rate/           { cuzra=$4      ; printf("%-5s %.24s %18s %12.2f    | %12.2f      |     %7.2f % \n", " ", $0, "~100% (%) :", $4  , invar, ((cuzra-invar)/invar)*100 ) }' invar=${zuzra} ${zfile1} >> ${zout}
+               awk '/Computation intensity/      { ccoin=$4      ; printf("%-5s %.23s %19s %12.2f    | %12.2f      |     %7.2f % \n", " ", $0, "> 1  :"     , $4  , invar, ((ccoin-invar)/invar)*100 ) }' invar=${zcoin} ${zfile1} >> ${zout} 
+           else
+               # Print: Variable long name | current version values
+               echo "                                                 Current version " >> ${zout}
+               echo "                                                                 " >> ${zout}
+               awk '/wall clock time/            {printf("%-6s %.33s %8s %9.2f \n", " ", $0, "(sec) :"    , $6      ) }' ${zfile1} >> ${zout}
+               awk '/Total amount of time in u/  {printf("%-6s %.34s %7s %9.2f \n", " ", $0, "(sec) :"    , $9      ) }' ${zfile1} >> ${zout}
+               awk '/Maximum resident set size/  {printf("%-6s %.26s %15s %9.2f \n", " ", $0, "(Mo) :"     , $6/1024) }' ${zfile1} >> ${zout}
+               awk '/Utilization rate/           {printf("%-5s %.24s %18s %9.2f \n", " ", $0, "~100% (%) :", $4     ) }' ${zfile1} >> ${zout}
+               awk '/Computation intensity/      {printf("%-5s %.23s %19s %9.2f \n", " ", $0, "> 1  :"     , $4     ) }' ${zfile1} >> ${zout} 
+           fi 
+
+           ;;
+
+     'mpi' )
+           
+           # OUTPUT TIMING OF THE MPI RUN
+           ##############################
+           
+           if [ ${evaltag} -a ${zxis} == 0 ] ; then
+               # Get values from the reference tag
+               awk '/wall clock time/           {print}' ${zfile2} > temp1
+               awk '/Maximum resident set size/ {print}' ${zfile2} > temp2
+               awk '/Utilization rate/          {print}' ${zfile2} > temp3
+               awk '/Computation intensity/     {print}' ${zfile2} > temp4 
+           
+               zreal=$( (awk '/wall clock time/           {cum += $6} END {printf("%f", cum/NR) }'        temp1 ) )
+               zuser=$( (awk '/Total amount of time in u/ {cum += $9} END {printf("%f", cum )   }'        ${zfile2}) )
+               zmemo=$( (awk '/Maximum resident set size/ {cum += $6} END {printf("%f", cum/(1024*NR)) }' temp2 ) )
+               zuzra=$( (awk '/Utilization rate/          {cum += $4} END {printf("%f", cum/NR) }'        temp3 ) )
+               zcoin=$( (awk '/Computation intensity/     {cum += $4} END {printf("%f", cum/NR) }'        temp4 ) )
+           
+               # Get values from the current version
+               awk '/wall clock time/           {print}' ${zfile1} > temp1
+               awk '/Maximum resident set size/ {print}' ${zfile1} > temp2
+               awk '/Utilization rate/          {print}' ${zfile1} > temp3
+               awk '/Computation intensity/     {print}' ${zfile1} > temp4 
+           
+               echo "                                                 Current version     ${ztag} version       Variation " >> ${zout}
+               echo "                                                                                                     " >> ${zout}
+               awk '/wall clock time/           {cum += $6} END {printf("%-7s %-39s %1s %11.2f    |     %12.2f   |     %7.2f %\n" , " ", "Execution time (wall clock time)  (sec)", ":", cum/NR       , invar, ((cum/NR-invar)/invar)*100  ) }' invar=${zreal} temp1     >> ${zout}
+               awk '/Total amount of time in u/ {cum += $9} END {printf("%-7s %-39s %1s %11.2f    |     %12.2f   |     %7.2f %\n" , " ", "Total amount of time in user mode (sec)", ":", cum          , invar, ((cum-invar)/invar)*100  ) }'    invar=${zuser} ${zfile1} >> ${zout}
+               awk '/Maximum resident set size/ {cum += $6} END {printf("%-7s %-25s %15s %12.2f   |     %12.2f   |     %7.2f %\n", " ", "Maximum resident set size", "(Mo)  :"        , cum/(1024*NR), invar, ((cum/(1024*NR)-invar)/invar)*100  ) }'  invar=${zmemo} temp2     >> ${zout}
+               awk '/Utilization rate/          {cum += $4} END {printf("%-7s %-16s %24s %12.2f   |     %12.2f   |     %7.2f %\n", " ", "Utilization rate", "(%)   :"                 , cum/NR       , invar, ((cum/NR-invar)/invar)*100  ) }' invar=${zuzra} temp3     >> ${zout}
+               awk '/Computation intensity/     {cum += $4} END {printf("%-7s %-21s %19s %12.2f   |     %12.2f   |     %7.2f %\n", " ", "Computation intensity", ":"                  , cum/NR       , invar, ((cum/NR-invar)/invar)*100  ) }' invar=${zcoin} temp4     >> ${zout}
+           
+               echo "                                                                                                     " >> ${zout}
+           
+               \rm temp*
+           
+           else
+               # Get values from the current version
+               awk '/wall clock time/           {print}' ${zfile1} > temp1
+               awk '/Maximum resident set size/ {print}' ${zfile1} > temp2
+               awk '/Utilization rate/          {print}' ${zfile1} > temp3
+               awk '/Computation intensity/     {print}' ${zfile1} > temp4 
+           
+               echo "                                                 Current version " >> ${zout}
+               echo "                                                                 " >> ${zout}
+               awk '/wall clock time/           {cum += $6} END {printf("%-7s %-39s %1s %9.2f\n" , " ", "Execution time (wall clock time)  (sec)", ":", cum/NR ) }' temp1     >> ${zout}
+               awk '/Total amount of time in u/ {cum += $9} END {printf("%-7s %-39s %1s %9.2f\n" , " ", "Total amount of time in user mode (sec)", ":", cum ) }'    ${zfile1} >> ${zout}
+               awk '/Maximum resident set size/ {cum += $6} END {printf("%-7s %-25s %15s %9.2f\n", " ", "Maximum resident set size", "(Mo)  :", cum/(1024*NR) ) }'  temp2     >> ${zout}
+               awk '/Utilization rate/          {cum += $4} END {printf("%-7s %-16s %24s %9.2f\n", " ", "Utilization rate", "(%)   :", cum/NR ) }'                  temp3     >> ${zout}
+               awk '/Computation intensity/     {cum += $4} END {printf("%-7s %-21s %19s %9.2f\n", " ", "Computation intensity", ":", cum/NR ) }'                   temp4     >> ${zout}
+           
+               echo "                                                                                                     " >> ${zout}
+           
+               \rm temp*
+           fi
+
+           ;;
+esac
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_osxxlf.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_osxxlf.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_osxxlf.ksh	(revision 4536)
@@ -0,0 +1,182 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zfile1 : mon run timing input file name
+#     - zfile2 : mpi run timing input file name
+#     - zconf  : configuration name
+#     - zout   : output file name
+#     - ztag   : tag name to which are compared files
+#     - zxis   : (0/1) reference timing files (do/do not) exist
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the sx8brodie target for 
+#        mon, mpi & omp runs
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-r] [-a] [-b] [-c] [-o] [-t] [-x]"
+  echo "Options: These are optional argument"
+  echo " -r : run type to treat"
+  echo " -a : current version timing input file name"
+  echo " -b : reference version timing input file name"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " -x : (0/1) reference timing files (do/do not) exist"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zrunt=
+zfile1=
+zfile2=
+zconf=
+zout=
+ztag=
+zxis=1
+
+# Get arguments
+while getopts r:a:b:c:o:t:x: opt
+do
+  case "$opt" in
+    r) zrunt="$OPTARG";;
+    a) zfile1="$OPTARG";;
+    b) zfile2="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    x) zxis="$OPTARG";;
+    *) help_CPU_time;;
+  esac
+done
+
+# Check if results must be compare to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+case "${zrunt}" in
+
+     'mon' )
+
+           # OUTPUT TIMING OF THE MON/OMP RUN
+           ###################################
+           
+           if [ ${evaltag} == 0 -a ${zxis} == 0 ] ; then
+               # Get values from the reference tag
+               zreal=$( (awk '/Real/        {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '/User/        {print $NF}' ${zfile2} ) )
+               zmflo=$( (awk '/MFLOPS/ && ! /concurrent/      {print $NF}' ${zfile2} ) )
+               [ ${zrunt} = 'omp' ] && zmfli=$( (awk '/MFLOPS/ &&   /concurrent/      {print $NF}' ${zfile2} ) )
+               [ ${zrunt} = 'omp' ] && zmprc=$( (awk '/Max Concurrent Proc/           {print $NF}' ${zfile2} ) )
+               zvlen=$( (awk '/VLEN/        {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '/Memory Size/ {print $NF}' ${zfile2} ) )
+               # Print: Variable long name | current version values | reference version values | variations
+               echo "                                Current version    ${ztag} version    Variation " >> ${zout}
+               awk '/Real/         { creal=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((creal-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '/User/         { cuser=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cuser-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '/MFLOPS/ && ! /concurrent/      { cmflo=$3 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmflo-invar)/invar)*100 ) }' invar=${zmflo} ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/MFLOPS/ &&   /concurrent/      { cmfli=$4 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmfli-invar)/invar)*100 ) }' invar=${zmfli} ${zfile1} >> ${zout}
+               awk '/VLEN/         { cvlen=$3 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cvlen-invar)/invar)*100 ) }' invar=${zvlen} ${zfile1} >> ${zout}
+               awk '/Memory Size/  { cmemo=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmemo-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout} 
+               [ ${zrunt} = 'omp' ] && awk '/Max Concurrent Proc/  { cmprc=$5 ; printf("%-5s %.25s  %10i      | %10i    |   %7i \n", " ", $0, $NF, invar, (cmprc-invar) ) }' invar=${zmprc} ${zfile1} >> ${zout} 
+           else
+               # Print: Variable long name | current version values
+               echo "                                 Current version " >> ${zout}
+               awk '/Real/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/User/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/MFLOPS/ && ! /concurrent/     {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/MFLOPS/ &&   /concurrent/     {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/VLEN/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/Memory Size/ {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/Max Concurrent Proc/  { cmprc=$5 ; printf("%-5s %.25s  %10i\n", " ", $0, $NF ) }' ${zfile1} >> ${zout} 
+           fi 
+
+           ;;
+
+     'mpi' )
+           # OUTPUT TIMING OF THE MPI RUN
+           ##############################
+           
+           if [ ${evaltag} == 0 -a ${zxis} == 0 ] ; then
+               # Get reference tag information
+               # Syntax: 1) search pattern between // symbol, 2) print text of the last column (identified by $NF)
+               zreal=$( (awk '( /\[/ && /\]/ ) && /Real/                           {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '( /\[/ && /\]/ ) && /User/                           {print $NF}' ${zfile2} ) )
+               zmflo=$( (awk '( /\[/ && /\]/ ) && /MFLOPS/                         {print $NF}' ${zfile2} ) )
+               zvlen=$( (awk '( /\[/ && /\]/ ) && /Average Vector Length/          {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '( /\[/ && /\]/ ) && ! /Global/ && /Memory size used/ {print $NF}' ${zfile2} ) )
+           
+               # Print: Variable long name | current version values | reference version values | variations
+               # Syntax: 1) search pattern between // symbol, 2) print text & values following a format (printf) explicited between "" symbol
+               awk '/Global Data/ { printf( "        %.29s  Current version   %s version      Variation \n", $0, tag) }' tag=${ztag} ${zfile1} >> ${zout}
+               awk '/==========================/ { printf("        %s \n", $0) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Real/                  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /User/                  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /MFLOPS/                { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmflo} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Average Vector Length/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zvlen} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Memory size used/ && !/Global/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout}
+               echo " " >> ${zout} 
+           
+               # Get reference tag information (Overall data)
+               # Syntax: 1) search pattern between // symbol, 2) print text of the last column (identified by $NF)
+               zreal=$( (awk '!( /\[/ && /\]/ ) && /Real/                           {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/                {print $NF}' ${zfile2} ) )
+               zgflo=$( (awk '!( /\[/ && /\]/ ) && /GFLOPS/                         {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '!( /\[/ && /\]/ ) && ! /Global/ && /Memory size used/ {print $NF}' ${zfile2} ) )
+           
+               # Print: Variable long name | current version values 
+               # Syntax: 1) search pattern between // symbol, 2) print text & values following a format (printf) explicited between "" symbol
+               awk '/Overall Data/ { printf( "        %-28s  Current version   %s version       Variation \n", $0, tag) }' tag=${ztag} ${zfile1} >> ${zout}
+               echo "        =============" >> ${zout} 
+               awk '!( /\[/ && /\]/ ) && /Real/             { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /GFLOPS/           { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zgflo} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /Memory size used/ && !/Global/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout}
+               echo " " >> ${zout} 
+           
+           else
+           
+               # Print: Variable long name | current version values 
+               awk '/Global Data/ { printf( "        %.29s   Current version\n ", $0) }' ${zfile1} >> ${zout}
+               awk '/==========================/ { printf("%-7s %-.26s \n", " ", $0) } ' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Real/                  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /User/                  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /MFLOPS/                { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Average Vector Length/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Memory size used/ && ! /Global/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile2} >> ${zout}
+               echo " " >> ${zout} 
+           
+               # Print: Variable long name | current version values (Overall data)
+               awk '/Overall Data/ { printf( "        %-28s   Current version\n ", $0 ) }' ${zfile1} >> ${zout}
+               echo "        =============" >> ${zout} 
+               awk '!( /\[/ && /\]/ ) && /Real/             { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /GFLOPS/           { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /Memory size used/  && ! /Global/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               echo "" >> ${zout} 
+           fi
+           ;;
+esac
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/CPU_time_sx8brodie.ksh	(revision 4536)
@@ -0,0 +1,182 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zfile1 : mon run timing input file name
+#     - zfile2 : mpi run timing input file name
+#     - zconf  : configuration name
+#     - zout   : output file name
+#     - ztag   : tag name to which are compared files
+#     - zxis   : (0/1) reference timing files (do/do not) exist
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the sx8brodie target for 
+#        mon, mpi & omp runs
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-r] [-a] [-b] [-c] [-o] [-t] [-x]"
+  echo "Options: These are optional argument"
+  echo " -r : run type to treat"
+  echo " -a : current version timing input file name"
+  echo " -b : reference version timing input file name"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " -x : (0/1) reference timing files (do/do not) exist"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zrunt=
+zfile1=
+zfile2=
+zconf=
+zout=
+ztag=
+zxis=1
+
+# Get arguments
+while getopts r:a:b:c:o:t:x: opt
+do
+  case "$opt" in
+    r) zrunt="$OPTARG";;
+    a) zfile1="$OPTARG";;
+    b) zfile2="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    x) zxis="$OPTARG";;
+    *) help_CPU_time;;
+  esac
+done
+
+# Check if results must be compare to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+case "${zrunt}" in
+
+     'mon' | 'omp' )
+
+           # OUTPUT TIMING OF THE MON/OMP RUN
+           ###################################
+           
+           if [ ${evaltag} == 0 -a ${zxis} == 0 ] ; then
+               # Get values from the reference tag
+               zreal=$( (awk '/Real/        {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '/User/        {print $NF}' ${zfile2} ) )
+               zmflo=$( (awk '/MFLOPS/ && ! /concurrent/      {print $NF}' ${zfile2} ) )
+               [ ${zrunt} = 'omp' ] && zmfli=$( (awk '/MFLOPS/ &&   /concurrent/      {print $NF}' ${zfile2} ) )
+               [ ${zrunt} = 'omp' ] && zmprc=$( (awk '/Max Concurrent Proc/           {print $NF}' ${zfile2} ) )
+               zvlen=$( (awk '/VLEN/        {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '/Memory Size/ {print $NF}' ${zfile2} ) )
+               # Print: Variable long name | current version values | reference version values | variations
+               echo "                                Current version    ${ztag} version    Variation " >> ${zout}
+               awk '/Real/         { creal=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((creal-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '/User/         { cuser=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cuser-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '/MFLOPS/ && ! /concurrent/      { cmflo=$3 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmflo-invar)/invar)*100 ) }' invar=${zmflo} ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/MFLOPS/ &&   /concurrent/      { cmfli=$4 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmfli-invar)/invar)*100 ) }' invar=${zmfli} ${zfile1} >> ${zout}
+               awk '/VLEN/         { cvlen=$3 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cvlen-invar)/invar)*100 ) }' invar=${zvlen} ${zfile1} >> ${zout}
+               awk '/Memory Size/  { cmemo=$5 ; printf("%-5s %.25s  %10.2f      | %10.2f    |   %7.2f % \n", " ", $0, $NF, invar, ((cmemo-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout} 
+               [ ${zrunt} = 'omp' ] && awk '/Max Concurrent Proc/  { cmprc=$5 ; printf("%-5s %.25s  %10i      | %10i    |   %7i \n", " ", $0, $NF, invar, (cmprc-invar) ) }' invar=${zmprc} ${zfile1} >> ${zout} 
+           else
+               # Print: Variable long name | current version values
+               echo "                                 Current version " >> ${zout}
+               awk '/Real/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/User/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/MFLOPS/ && ! /concurrent/     {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/MFLOPS/ &&   /concurrent/     {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/VLEN/        {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               awk '/Memory Size/ {printf("%-5s %.25s  %10.2f\n", " ", $0, $NF ) }' ${zfile1} >> ${zout}
+               [ ${zrunt} = 'omp' ] && awk '/Max Concurrent Proc/  { cmprc=$5 ; printf("%-5s %.25s  %10i\n", " ", $0, $NF ) }' ${zfile1} >> ${zout} 
+           fi 
+
+           ;;
+
+     'mpi' )
+           # OUTPUT TIMING OF THE MPI RUN
+           ##############################
+           
+           if [ ${evaltag} == 0 -a ${zxis} == 0 ] ; then
+               # Get reference tag information
+               # Syntax: 1) search pattern between // symbol, 2) print text of the last column (identified by $NF)
+               zreal=$( (awk '( /\[/ && /\]/ ) && /Real/                           {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '( /\[/ && /\]/ ) && /User/                           {print $NF}' ${zfile2} ) )
+               zmflo=$( (awk '( /\[/ && /\]/ ) && /MFLOPS/                         {print $NF}' ${zfile2} ) )
+               zvlen=$( (awk '( /\[/ && /\]/ ) && /Average Vector Length/          {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '( /\[/ && /\]/ ) && ! /Global/ && /Memory size used/ {print $NF}' ${zfile2} ) )
+           
+               # Print: Variable long name | current version values | reference version values | variations
+               # Syntax: 1) search pattern between // symbol, 2) print text & values following a format (printf) explicited between "" symbol
+               awk '/Global Data/ { printf( "        %.29s  Current version   %s version      Variation \n", $0, tag) }' tag=${ztag} ${zfile1} >> ${zout}
+               awk '/==========================/ { printf("        %s \n", $0) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Real/                  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /User/                  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /MFLOPS/                { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmflo} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Average Vector Length/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zvlen} ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Memory size used/ && !/Global/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout}
+               echo " " >> ${zout} 
+           
+               # Get reference tag information (Overall data)
+               # Syntax: 1) search pattern between // symbol, 2) print text of the last column (identified by $NF)
+               zreal=$( (awk '!( /\[/ && /\]/ ) && /Real/                           {print $NF}' ${zfile2} ) )
+               zuser=$( (awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/                {print $NF}' ${zfile2} ) )
+               zgflo=$( (awk '!( /\[/ && /\]/ ) && /GFLOPS/                         {print $NF}' ${zfile2} ) )
+               zmemo=$( (awk '!( /\[/ && /\]/ ) && ! /Global/ && /Memory size used/ {print $NF}' ${zfile2} ) )
+           
+               # Print: Variable long name | current version values 
+               # Syntax: 1) search pattern between // symbol, 2) print text & values following a format (printf) explicited between "" symbol
+               awk '/Overall Data/ { printf( "        %-28s  Current version   %s version       Variation \n", $0, tag) }' tag=${ztag} ${zfile1} >> ${zout}
+               echo "        =============" >> ${zout} 
+               awk '!( /\[/ && /\]/ ) && /Real/             { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zreal} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/  { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zuser} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /GFLOPS/           { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zgflo} ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /Memory size used/ && !/Global/ { printf( "%-7s %.29s  %10.2f     |   %10.2f    |    %7.2f %\n", " ", $0 , $NF, invar, (($NF-invar)/invar)*100 ) }' invar=${zmemo} ${zfile1} >> ${zout}
+               echo " " >> ${zout} 
+           
+           else
+           
+               # Print: Variable long name | current version values 
+               awk '/Global Data/ { printf( "        %.29s   Current version\n ", $0) }' ${zfile1} >> ${zout}
+               awk '/==========================/ { printf("%-7s %-.26s \n", " ", $0) } ' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Real/                  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /User/                  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /MFLOPS/                { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Average Vector Length/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile1} >> ${zout}
+               awk '( /\[/ && /\]/ ) && /Memory size used/ && ! /Global/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF) }' ${zfile2} >> ${zout}
+               echo " " >> ${zout} 
+           
+               # Print: Variable long name | current version values (Overall data)
+               awk '/Overall Data/ { printf( "        %-28s   Current version\n ", $0 ) }' ${zfile1} >> ${zout}
+               echo "        =============" >> ${zout} 
+               awk '!( /\[/ && /\]/ ) && /Real/             { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && ! /OPS/ && /User/  { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /GFLOPS/           { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               awk '!( /\[/ && /\]/ ) && /Memory size used/  && ! /Global/ { printf( "%-7s %.29s  %10.2f \n", " ", $0 , $NF ) }' ${zfile1} >> ${zout}
+               echo "" >> ${zout} 
+           fi
+           ;;
+esac
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_aix.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_aix.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_aix.ksh	(revision 4536)
@@ -0,0 +1,101 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zxcm   : (0/1) mon${zconf}_err file (do/do not) exist"
+#     - zxrs   : (0/1) Ref memory_size.txt file (do/do not) exist"
+#     - zxrm   : (0/1) Ref mon${zconf}_err file (do/do not) exist"
+#     - zconf  : configuration name"
+#     - zout   : output file name"
+#     - ztag   : tag name to which are compared files"
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the sx8brodie target for 
+#        mon, mpi & omp runs
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-a] [-b] [-d] [-c] [-o] [-t]"
+  echo "Options: These are optional argument"
+  echo " -a : (0/1) mon${zconf}_err file (do/do not) exist"
+  echo " -b : (0/1) Ref memory_size.txt file (do/do not) exist"
+  echo " -d : (0/1) Ref mon${zconf}_err file (do/do not) exist"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zxcm=1
+zxrs=1
+zxrm=1
+zconf=
+zout=
+ztag=
+
+# Get arguments
+while getopts a:b:d:c:o:t: opt
+do
+  case "$opt" in
+    a) zxcm="$OPTARG";;
+    b) zxrs="$OPTARG";;
+    d) zxrm="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    *) help_MEM_size;;
+  esac
+done
+
+# Check if results must be compared to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+zfilecs='mon/LONG/memory_size.txt' ;  zfilers='mon/LONG/REF/memory_size.txt'
+zfilecm="mon/LONG/mon${zconf}_err"  ;  zfilerm="mon/LONG/REF/mon${zconf}_err"
+
+# If reference version files exist
+if [ ${evaltag} == 0 -a ${zxrm} == 0 ] ;  then
+    # Get values from the reference tag
+    Mo_stack_ms=$( (awk '/Stack/ {print $NF/(1024*1024) }' ${zfilers} ) )
+    Mo_stati_ms=$( (awk '/Stati/ {print $NF/(1024*1024) }' ${zfilers} ) )
+    if [ ${zxcm} == 0 ] ; then Mo_max_used=$( (awk '/resident/ {print $6/1024}' ${zfilerm} ) ) ; fi
+
+    # Print: Variable long name | current version values | reference version values | variations
+    echo "                                                 " >> ${zout}
+    echo "                                      Version    " >> ${zout}
+    echo "             Memory          Current /       \ ${ztag}        Variation " >> ${zout}
+    awk ' /Stack/ { val=$NF/(1024*1024) } END {printf("%-9s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Stack     (Mo) :", val, inck, ((val-inck)/inck)*100 ) }' inck=${Mo_stack_ms} ${zfilecs} >> ${zout}
+    awk ' /Stati/ { val=$NF/(1024*1024) } END {printf("%-8s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Static    (Mo) :", val, inti, ((val-inti)/inti)*100 ) }' inti=${Mo_stati_ms} ${zfilecs} >> ${zout}
+    if [ ${zxcm} == 0 ] ; then awk ' /resident/ { val=$6/1024 } END {printf("%-8s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Max. used (Mo) :", val, inus, ((val-inus)/inus)*100 ) }' inus=${Mo_max_used} ${zfilecm} >> ${zout} ; fi
+else
+    # Print: Variable long name | current version values
+    echo "                                                 " >> ${zout}
+    echo "             Memory          Current version "     >> ${zout}
+    awk ' /Stack/  {printf("%-9s %-.16s %11.1f\n ", " ", "Stack     (Mo) :", $NF/(1024*1024) ) }' ${zfilecs} >> ${zout}
+    awk ' /Stati/  {printf("%-8s %-.16s %11.1f\n ", " ", "Static    (Mo) :", $NF/(1024*1024) ) }' ${zfilecs} >> ${zout}
+    if [ ${zxcm} == 0 ] ; then awk ' /resident/ {printf("%-8s %-.16s %11.1f\n ", " ", "Max. used (Mo) :", $6/1024 ) }' ${zfilecm} >> ${zout} ; fi
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_osxxlf.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_osxxlf.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_osxxlf.ksh	(revision 4536)
@@ -0,0 +1,107 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zmxcu  : (0/1) mon${CONF}_err file (do/do not) exist"
+#     - zxrs   : (0/1) Ref memory_size.txt file (do/do not) exist"
+#     - zxrm   : (0/1) Ref mon${CONF}_err file (do/do not) exist"
+#     - zconf  : configuration name"
+#     - zout   : output file name"
+#     - ztag   : tag name to which are compared files"
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the osxxlf target for 
+#        mon, mpi runs
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-a] [-b] [-d] [-c] [-o] [-t]"
+  echo "Options: These are optional argument"
+  echo " -a : (0/1) mon${CONF}_err file (do/do not) exist"
+  echo " -b : (0/1) Ref memory_size.txt file (do/do not) exist"
+  echo " -d : (0/1) Ref mon${CONF}_err file (do/do not) exist"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zmxcu=1
+zxrs=1
+zxrm=1
+zconf=
+zout=
+ztag=
+
+# Get arguments
+while getopts a:b:d:c:o:t: opt
+do
+  case "$opt" in
+    a) zmxcu="$OPTARG";;
+    b) zxrs="$OPTARG";;
+    d) zxrm="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    *) help_MEM_size;;
+  esac
+done
+
+# Check if results must be compared to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+zfilecs='mon/LONG/memory_size.txt'
+zfilers='mon/LONG/REF/memory_size.txt'
+
+# Select only appropriate lines
+grep -v Stack ${zfilecs} | head -1 > temp_cs_sck
+tail -1 ${zfilecs}                 > temp_cs_sic
+
+# Select only appropriate lines
+grep -v Stack ${zfilers} | head -1 > temp_rs_sck
+tail -1 ${zfilers}                 > temp_rs_sic
+
+# If reference version files exist
+if [ ${evaltag} == 0 -a ${zxrs} == 0 ] ;  then
+    # Get values from the reference tag
+    Mo_stack_ms=$( (awk '{print $5/(1024*1024) }' temp_rs_sck ) )
+    Mo_stati_ms=$( (awk '{print $5/(1024*1024) }' temp_rs_sic ) )
+
+    # Print: Variable long name | current version values | reference version values | variations
+    echo "                                                 " >> ${zout}
+    echo "                                      Version    " >> ${zout}
+    echo "             Memory          Current /       \ ${ztag}        Variation " >> ${zout}
+    awk ' { val=$5/(1024*1024) } {printf("%-9s %-16s %8.1f      |   %8.1f     |    %5.1f \n ", " ", "Stack     (Mo) :", val, inck, ((val-inck)/inck)*100 ) }' inck=${Mo_stack_ms} temp_cs_sck >> ${zout}
+    awk ' { val=$5/(1024*1024) } {printf("%-8s %-16s %8.1f      |   %8.1f     |    %5.1f \n ", " ", "Static    (Mo) :", val, inti, ((val-inti)/inti)*100 ) }' inti=${Mo_stati_ms} temp_cs_sic >> ${zout}
+else
+    # Print: Variable long name | current version values
+    echo "                                                 " >> ${zout}
+    echo "             Memory          Current version "     >> ${zout}
+    awk ' {printf("%-9s %-.16s %11.1f\n ", " ", "Stack     (Mo) :", $5/(1024*1024) ) }' temp_cs_sck >> ${zout}
+    awk ' {printf("%-8s %-.16s %11.1f\n ", " ", "Static    (Mo) :", $5/(1024*1024) ) }' temp_cs_sic >> ${zout}
+fi
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/MEM_size_sx8brodie.ksh	(revision 4536)
@@ -0,0 +1,101 @@
+#!/bin/ksh
+##############################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is called by the assessment.ksh script for a 
+# given configuration 
+#
+# INPUT ARGS: 6
+#     - zxcm   : (0/1) mon${zconf}_err file (do/do not) exist"
+#     - zxrs   : (0/1) Ref memory_size.txt file (do/do not) exist"
+#     - zxrm   : (0/1) Ref mon${zconf}_err file (do/do not) exist"
+#     - zconf  : configuration name"
+#     - zout   : output file name"
+#     - ztag   : tag name to which are compared files"
+#
+# WORK: It aims to :
+#
+#      - Treat output timing from the sx8brodie target for 
+#        mon, mpi & omp runs
+#     *- compare it to a reference version 
+#
+# * this step is performed only if a reference tag 
+#   is specified with the -t option and if files exist.
+#   See the Makefile under ./config/HEAD directory
+#
+##############################################################
+#set -xv
+##############################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+#
+# help_CPU_time() To print help
+#
+function help_CPU_time
+{
+  echo "Usage: $nscript [-a] [-b] [-d] [-c] [-o] [-t]"
+  echo "Options: These are optional argument"
+  echo " -a : (0/1) mon${zconf}_err file (do/do not) exist"
+  echo " -b : (0/1) Ref memory_size.txt file (do/do not) exist"
+  echo " -d : (0/1) Ref mon${zconf}_err file (do/do not) exist"
+  echo " -c : configuration name"
+  echo " -o : output file name"
+  echo " -t : tag name to which are compared files"
+  echo " their values are not taken)"
+  exit 1
+}
+
+# Initialization
+zxcm=1
+zxrs=1
+zxrm=1
+zconf=
+zout=
+ztag=
+
+# Get arguments
+while getopts a:b:d:c:o:t: opt
+do
+  case "$opt" in
+    a) zxcm="$OPTARG";;
+    b) zxrs="$OPTARG";;
+    d) zxrm="$OPTARG";;
+    c) zconf="$OPTARG";;
+    o) zout="$OPTARG";;
+    t) ztag="$OPTARG";;
+    *) help_MEM_size;;
+  esac
+done
+
+# Check if results must be compared to the reference version
+test -n "${ztag}"
+evaltag=$?
+
+zfilecs='mon/LONG/memory_size.txt' ;  zfilers='mon/LONG/REF/memory_size.txt'
+zfilecm="mon/LONG/mon${zconf}_err"  ;  zfilerm="mon/LONG/REF/mon${zconf}_err"
+
+# If reference version files exist
+if [ ${evaltag} == 0 -a ${zxrm} == 0 ] ;  then
+    # Get values from the reference tag
+    Mo_stack_ms=$( (awk '/Stack/ {print $NF/(1024*1024) }' ${zfilers} ) )
+    Mo_stati_ms=$( (awk '/Stati/ {print $NF/(1024*1024) }' ${zfilers} ) )
+    if [ ${zxcm} == 0 ] ; then Mo_max_used=$( (awk '/Memory/ {print $NF}' ${zfilerm} ) ) ; fi
+
+    # Print: Variable long name | current version values | reference version values | variations
+    echo "                                                 " >> ${zout}
+    echo "                                      Version    " >> ${zout}
+    echo "             Memory          Current /       \ ${ztag}        Variation " >> ${zout}
+    awk ' /Stack/ { val=$NF/(1024*1024) } END {printf("%-9s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Stack     (Mo) :", val, inck, ((val-inck)/inck)*100 ) }' inck=${Mo_stack_ms} ${zfilecs} >> ${zout}
+    awk ' /Stati/ { val=$NF/(1024*1024) } END {printf("%-8s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Static    (Mo) :", val, inti, ((val-inti)/inti)*100 ) }' inti=${Mo_stati_ms} ${zfilecs} >> ${zout}
+    if [ ${zxcm} == 0 ] ; then awk ' /Memory/ { val=$NF } END {printf("%-8s %-16s %8.1f      |   %8.1f     |    %5.1f %\n ", " ", "Max. used (Mo) :", val, inus, ((val-inus)/inus)*100 ) }' inus=${Mo_max_used} ${zfilecm} >> ${zout} ; fi
+else
+    # Print: Variable long name | current version values
+    echo "                                                 " >> ${zout}
+    echo "             Memory          Current version "     >> ${zout}
+    awk ' /Stack/  {printf("%-9s %-.16s %11.1f\n ", " ", "Stack     (Mo) :", $NF/(1024*1024) ) }' ${zfilecs} >> ${zout}
+    awk ' /Stati/  {printf("%-8s %-.16s %11.1f\n ", " ", "Static    (Mo) :", $NF/(1024*1024) ) }' ${zfilecs} >> ${zout}
+    if [ ${zxcm} == 0 ] ; then awk ' /Memory/   {printf("%-8s %-.16s %11.1f\n ", " ", "Max. used (Mo) :", $NF ) }' ${zfilecm} >> ${zout} ; fi
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/assessment.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/assessment.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/assessment.ksh	(revision 4536)
@@ -0,0 +1,544 @@
+#!/bin/ksh
+######################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# It is automatically launched (by the cron_jobs.ksh 
+# script) when all runs (mon, mpi, (omp)) for a given 
+# configuration are finished 
+#
+# INPUT ARGS: 1 + 1 optional
+#     - CONF: configuration name (ORCA2_LIM, GYRE ..)
+#     - TODO: (optional) Arg=yes or empty to build 
+#             output files including timing results. 
+#             Specific to Zahir
+#
+# WORK: It aims to (for each standard configuration) :
+#
+#    I. Check Executable Memory size
+#       - from memory_size.txt output file
+#      *- compare it to a reference version 
+#
+#   II. Check CPU time used (if specified)
+#       - from timing output files
+#      *- compare it to a reference version 
+#
+#  III. Check the reproductibility between mon & mpi runs
+#       - making diff of solver.stat output files
+#
+#   IV. Check the restartability for mon & mpi runs
+#       - making diff of solver.stat output files
+#
+#    V.*Compare current results to a reference one
+#        
+#   VI. Send the assessment file "endjob.txt" using 
+#       user's e-mail
+#        
+# * this step is performed only if a reference tag 
+#   is passing through the specifs.txt file
+#   See the Makefile under ./config/HEAD directory
+#
+# It is based on the directories architecture below :
+#
+#         NEMO_VALID/WNAME_CONFIG/
+#                    |-- mon            --> MONO run
+#                    |   |-- 1_SHORT
+#                    |   |-- 2_SHORT
+#                    |   |-- LONG
+#                    |   `-- GTIME
+#                    |-- mpi            --> MPI run
+#                    |   |-- 1_SHORT
+#                    |   |-- 2_SHORT
+#                    |   |-- LONG
+#                    |   `-- GTIME
+#                    `-- omp            --> Open-MP run
+#                        |-- 1_SHORT
+#                        |-- 2_SHORT
+#                        |-- LONG
+#                        `-- GTIME
+#
+###########################################################
+#set -xv 
+###########################################################
+CONF=$1
+TODO=$2
+TARGET=osxxlf
+VERSION=$( ( awk '/test=/ { print $2 }' specifs.txt ) )
+LRTYPE="$( ( awk '/runs=/ { printf  "%s %s %s", $2 , $3 , $4}' specifs.txt ) )"
+VTIME=$( ( awk '/time=/ { print $2 }' specifs.txt ) )
+REF_TAG=$( (awk '/tagname=/ {print $2}' specifs.txt) )
+TITLE="NEMO VALIDATION ${VERSION} : $CONF on $TARGET"
+EMAIL='ctlod@locean-ipsl.upmc.fr'
+
+\rm endjob.txt 2> /dev/null
+touch endjob.txt
+
+###########################################################
+# checkfile() is a local function to check if a file exist
+# 2 arguments:
+#    - zf2check : file name to check
+#    - zoutfile : output file name to print results
+#    - zwork    : kind of prints to perform
+#    - zreprint : (optional) to avoid printing twice a message
+###########################################################
+################ Begin checkfile function #################
+function checkfile
+{
+# name of the file to check
+zf2check=$1
+# print output file name
+zoutfile=$2
+# white space prints
+zworkt=$3
+# Print a message only once
+zreprint=$4
+
+#set -x 
+
+test -n "${zreprint}"
+zrep=$?
+
+
+genf=$( basename ${zf2check} )
+
+case "${zworkt}" in
+      'NORM' )  blnk='       ' ;;
+      'DIFF' )  blnk=' '  ;;
+esac
+fmes4=" - file ${zf2check} doesn't exist "
+
+# Check file exists
+if [ -a ${zf2check} ] ; then
+    fmes1=" List ${genf} files and check date creation:   "
+    fmes2=" `ls -l ${zf2check}`           "
+    fmes3=" - file ${zf2check} is empty  "
+    [ ${zrep} == 0 ] && echo "${blnk}${fmes1}"  >> ${zoutfile}
+
+   # Check file is not empty
+   if [ -s ${zf2check} ] ; then
+       [ ${zoutfile} ] && echo "${blnk}${fmes2}" >> ${zoutfile}
+       xist=0 ; return ${xist}
+   else
+       [ ${zoutfile} ] &&  echo "${blnk}${fmes3}" >> ${zoutfile}
+       xist=1 ; return ${xist}
+   fi
+else
+   [ ${zoutfile} ] && echo "${blnk}${fmes4}" >> ${zoutfile}
+   xist=1 ; return ${xist}
+fi
+return
+}
+############### End checkfile function ###############
+######################################################
+
+# Get the name of the present script
+nscript=$( (basename $0) )
+
+###########################################################
+# mak_diff_file() is a local function which performs diff
+# on some files and print messages in the endjob.txt file
+# 7 input arguments:
+#    - zfex    : (0/1) (make/do not make) diff (files doesn't exist)
+#    - zfile1  : first input file name
+#    - zfile2  : second input file name
+#    - zruntype: run type (mon, mpi, omp)
+#    - zstream : stream of the run (long, stream_1, stream_2)
+#    - ztag    : the tag name to which are compared files
+#    - zkind   : kind of the check (repro/resta)
+###############################################################
+################ Begin mak_diff_file function #################
+function mak_diff_file
+{
+#
+# help_diff() To print help
+#
+function help_diff
+{
+  echo "Usage: ${nscript} [-x] [-a] [-b] [-r] [-s] [-t] [-k]"
+  echo "Options: These are optional argument"
+  echo " -x : (0/1) (make/do not make) diff "
+  echo " -a : first input file name"
+  echo " -b : second input file name"
+  echo " -r : run type (mon, mpi, omp)"
+  echo " -s : stream of the run (long, stream_1, stream_2)"
+  echo " -t : tag name to which are compared files"
+  echo " -k : kind of the check (repro/resta)" 
+  echo " their values are not taken)"
+  exit 1
+}
+
+##set -xv
+
+# Initialization
+zfex=1
+zfile1=
+zfile2=
+zruntype=
+zstream=
+ztag=
+zkind=none
+
+# Get arguments
+while getopts x:a:b:r:s:t:k: opt
+do
+  case "$opt" in
+    x) zfex="$OPTARG";;
+    a) zfile1="$OPTARG";;
+    b) zfile2="$OPTARG";;
+    r) zruntype="$OPTARG";;
+    s) zstream="$OPTARG";;
+    t) ztag="$OPTARG";;
+    k) zkind="$OPTARG";;
+    *) help_diff;;
+  esac
+done
+
+zgenf=$( basename ${zfile1} )
+zgenftrc=$( basename ${zfile1%.*} )
+
+case "$zkind" in
+  none ) 
+      zmesg1="                   Current run                                                     ${ztag} run   "
+      zmesg2="                   -----------                                                     --------------"
+      zmesg_NOK="        ${zstream} ${zgenf} is NOT identical to the version ${ztag} one"
+      zmesg_OK="        ${zstream} ${zgenf} IS IDENTICAL to the version ${ztag} one  "
+      zmesg_wht="        NO comparison between current ${zstream} and the version ${ztag} ${zgenf} "
+      bnam='cvref_'${zgenftrc}_${zstream}_${zruntype} ;;
+  repro ) 
+      zmesg1="                   mon run                                                         ${zruntype} run      "
+      zmesg2="                   -------                                                         -------      "
+      zmesg_NOK="        NO NO NO NO NO NO for the current version"
+      zmesg_OK="        YES YES YES YES YES YES YES YES for the current version "
+      zmesg_wht="        NO CONCLUSION !!!!!  "
+      bnam=${zkind}_${zgenftrc} ;;
+  resta ) 
+      zmesg1="                   LONG Stream                                                     SHORT Streams"
+      zmesg2="                   -----------                                                     -------------"
+      zmesg_NOK="        NO NO NO NO NO NO for the current version i.e. LONG stream != ( 1_SHORT + 2_SHORT ) streams "
+      zmesg_OK="        YES YES YES YES YES YES YES YES for the current version i.e. LONG stream = ( 1_SHORT + 2_SHORT ) streams "
+      zmesg_wht="        NO CONCLUSION !!!!!! "
+      bnam=${zkind}_${zgenftrc} ;;
+esac
+
+
+if [ ${zfex} == 0 ] ;  then
+    \rm ${bnam}.txt 2> /dev/null
+    echo "                                    Make difference between ${zgenf} files                       "  > ${bnam}.txt
+    echo "                                            ${zstream} ${zruntype} run                           " >> ${bnam}.txt
+    echo "${zmesg1}"                                                                                         >> ${bnam}.txt
+    echo "${zmesg2}"                                                                                         >> ${bnam}.txt
+    sdiff    ${zfile1} ${zfile2} >>  ${bnam}.txt
+    sdiff -s ${zfile1} ${zfile2} >>  ${bnam}_dd.txt
+
+    #---------
+    if [ ${zgenf} = 'ocean.output' ] ; then
+        echo "                                                                                                 " >> ${zstream}_head.txt
+        echo "                                    Make difference between ${zgenf} files                       "  > ${zstream}_head.txt
+        echo "                                            ${zstream} ${zruntype} run                           " >> ${zstream}_head.txt
+        echo "                   Current run                                                     ${ztag} run   " >> ${zstream}_head.txt
+        echo "                   -----------                                                     --------------" >> ${zstream}_head.txt
+        echo "                                                                                                 " >> ${zstream}_head.txt
+        zfout=${bnam}_dd.txt
+        zspmes=" See ${bnam}.txt file for full difference"
+    else
+        touch ${zstream}_head.txt
+        zfout=${bnam}.txt
+        zspmes=""
+    fi
+    #---------
+    if [ -s ${bnam}_dd.txt ] ; then
+    # Differences exist between solver.stat or ocean.output files
+       echo "                             " >> endjob.txt
+       echo "${zmesg_NOK}"                  >> endjob.txt
+       echo "           ${zspmes}         " >> endjob.txt
+       echo "                             " >> endjob.txt
+       cat ${zstream}_head.txt ${zfout}     >> endjob.txt
+       echo "                             " >> endjob.txt
+       echo "                             " >> endjob.txt
+    else
+       # No differences exist between solver.stat or ocean.output files
+       echo "                             " >> endjob.txt
+       echo "${zmesg_OK}"                   >> endjob.txt
+       echo "                             " >> endjob.txt
+    fi
+
+    \rm *_dd* *_head.txt 2> /dev/null
+
+else
+       # It is not possible to conclude because files are missing or empty
+       echo "                             " >> endjob.txt
+       echo "${zmesg_wht}"                  >> endjob.txt
+       echo "                             " >> endjob.txt
+fi
+
+return
+
+}
+############### End mak_diff_file function ####################
+###############################################################
+
+###########################################################
+# concat_perf() is a local function to gather performances
+# files (perfs_runtype.txt_xxxx) build with the hpmcount 
+# command on Zahir and standard(s) error output file(s)
+# runtypeCONFNAME_err
+# 1 argument:
+#    - zconf : configuration name
+#############################################################
+################ Begin concat_perf function #################
+function concat_perf
+{
+
+#set -x
+
+# name of the configuration
+zconf=$1
+
+# List of files to treat
+zcatfe[0]="mon/LONG/mon${zconf}_err"
+zcatfe[1]="mon/GTIME/mon${zconf}_err"
+zcatfe[2]="mpi/GTIME/mpi${zconf}_err"
+
+ind=0
+while [ ${ind} -lt 3 ] ; do
+
+       zpath=$( ( dirname ${zcatfe[${ind}]} ) )
+       zname=$( ( basename ${zcatfe[${ind}]} ) )
+       cd ${zpath}
+       cp ${zname} ${zname}_save
+       for kf in `ls perf*` ; do
+           cat ${kf} >> ${zname}
+       done
+       cd ../..
+       let ind=${ind}+1
+done
+
+return
+}
+############### End concat_perf function ###############
+########################################################
+
+
+# ###############################
+# 0. CURRENT VERSION NAME
+# ###############################
+echo " ############################                           "  > endjob.txt
+echo " CURRENT VERSION: $VERSION                              " >> endjob.txt
+echo " ############################                           " >> endjob.txt
+echo "                                                        " >> endjob.txt
+echo "                                                        " >> endjob.txt
+
+test -n "${TODO}"
+id2do=$?
+if [ ${id2do} == 0 -a ${TARGET} = 'aix' ] ; then concat_perf ${CONF} ; fi
+
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# ###############################
+# I. CHECK EXECUTABLE MEMORY SIZE
+# ###############################
+filecs='mon/LONG/memory_size.txt' ;  filers='mon/LONG/REF/memory_size.txt'
+filecm="mon/LONG/mon${CONF}_err"  ;  filerm="mon/LONG/REF/mon${CONF}_err"
+xfilecs=0  ; xfilecm=0 ; xfilers=0 ; xfilerm=0
+echo " ############################                           " >> endjob.txt
+echo " CHECK EXECUTABLE MEMORY SIZE                           " >> endjob.txt
+echo " ############################                           " >> endjob.txt
+echo "                                                        " >> endjob.txt
+#--------
+checkfile ${filecs} 'endjob.txt' DIFF yes ; xfilecs=$?
+checkfile ${filers} 'endjob.txt' DIFF     ; xfilers=$?
+checkfile ${filecm} 'endjob.txt' DIFF     ; xfilecm=$?
+checkfile ${filerm} 'endjob.txt' DIFF     ; xfilerm=$?
+
+# If current version files exist
+if [ ${xfilecs} == 0 ] ;  then
+
+    if [ ${REF_TAG} ] ; then 
+        ./MEM_size_${TARGET}.ksh -a ${xfilecm} -b ${xfilers} -d ${xfilerm} -c ${CONF} -o endjob.txt -t ${REF_TAG} 
+    else
+        ./MEM_size_${TARGET}.ksh -a ${xfilecm} -b ${xfilers} -d ${xfilerm} -c ${CONF} -o endjob.txt
+    fi
+
+else
+    echo "                                                    " >> endjob.txt
+    echo "   ---> NO memory size check                        " >> endjob.txt
+    echo "                                                    " >> endjob.txt
+fi
+#
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# #######################
+# II. CHECK CPU TIME USED
+# #######################
+if [ ${VTIME} = 'timing' ] ; then
+
+    echo "                                                        " >> endjob.txt
+    echo " ######################                                 " >> endjob.txt
+    echo " CHECK CPU TIME USED                                    " >> endjob.txt
+    echo " ######################                                 " >> endjob.txt
+    echo "                                                        " >> endjob.txt
+    #------
+
+    for runt in ${LRTYPE} ; do
+
+        echo "                                                    " >> endjob.txt
+        echo "   ---> Timing for the ${runt} run :                " >> endjob.txt
+        echo "        ----------------------------                " >> endjob.txt
+        echo "                                                    " >> endjob.txt
+
+        xfilecv=0 ; xfilerv=0
+
+        # Check that timing file for the ${runt} current version exist
+        filecv="${runt}/GTIME/${runt}${CONF}_err" 
+        checkfile ${filecv} 'endjob.txt' NORM yes ; xfilecv=$?
+
+        # Check that timing file for the ${runt} reference version exist
+        filerv="${runt}/GTIME/REF/${runt}${CONF}_err" 
+        checkfile ${filerv} 'endjob.txt' NORM ; xfilerv=$?
+        echo "                                                             " >> endjob.txt
+
+        if [ ${xfilecv} == 0 ] ; then 
+            if [ ${REF_TAG} ] ; then 
+                ./CPU_time_${TARGET}.ksh -r ${runt} -a ${filecv} -b ${filerv} -c ${CONF} -o endjob.txt -x ${xfilerv} -t ${REF_TAG} 
+            else
+                ./CPU_time_${TARGET}.ksh -r ${runt} -a ${filecv} -b ${filerv} -c ${CONF} -o endjob.txt -x ${xfilerv}
+            fi
+        fi
+
+    done
+
+fi
+
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# ########################################################
+# III. CHECK REPRODUCTIBILITY: mon .vs. mpi & mon .vs .omp
+# ########################################################
+echo "                                                        " >> endjob.txt
+echo " ######################                                 " >> endjob.txt
+echo " CHECK REPRODUCTIBILITY                                 " >> endjob.txt
+echo " ######################                                 " >> endjob.txt
+echo "                                                        " >> endjob.txt
+#------
+for runt in ${LRTYPE} ; do
+
+    if [ ${runt} != 'mon' ] ; then
+        echo "                                                    " >> endjob.txt
+        echo "   ---> Reproductibility mon .vs. ${runt} ? :       " >> endjob.txt
+        echo "        -------------------------------------       " >> endjob.txt
+
+        filemon="mon/LONG/solver.stat" ;  filexxx="${runt}/LONG/solver.stat"
+        xfilemon=0
+
+        checkfile ${filemon} 'endjob.txt' NORM yes ; xfilemon=$?
+        checkfile ${filexxx} 'endjob.txt' NORM ; xfilemon=$?
+        
+        mak_diff_file -x ${xfilemon} -a ${filemon} -b ${filexxx} -r ${runt} -s LONG -k repro
+    fi
+done
+
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# ##########################################
+# IV. CHECK RESTARTABILITY: mon mpi omp runs
+# ##########################################
+echo "                                                        " >> endjob.txt
+echo " ####################                                   " >> endjob.txt
+echo " CHECK RESTARTABILITY                                   " >> endjob.txt
+echo " ####################                                   " >> endjob.txt
+echo "                                                        " >> endjob.txt
+
+for runt in ${LRTYPE} ; do
+
+    echo "                                                    " >> endjob.txt
+    echo "   ---> ${runt} restartability ? :                  " >> endjob.txt
+    echo "        --------------------------                  " >> endjob.txt
+
+    file1="${runt}/1_SHORT/solver.stat" ;  file2="${runt}/2_SHORT/solver.stat" ; file3="${runt}/LONG/solver.stat"
+    xfile1=0
+    #-------
+    checkfile ${file1} 'endjob.txt' NORM yes ; xfile1=$?
+    checkfile ${file2} 'endjob.txt' NORM ; xfile1=$?
+    #
+    cat ${file1} ${file2}  > short_solver_${runt}.stat
+    mak_diff_file -x ${xfile1} -a ${file3} -b short_solver_${runt}.stat -r ${runt} -k resta
+    \rm short_solver_${runt}.stat
+    
+    #-------
+done
+
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# #######################################################
+# V. COMPARE CURRENT ${runt} RESULTS TO THE $REF_TAG ONES
+# #######################################################
+
+# This step is realised only if a reference tag ${REF_TAG} is specified
+if [ ${REF_TAG} ] ; then
+
+    echo "                                                        " >> endjob.txt
+    echo " ####################################################   " >> endjob.txt
+    echo " COMPARE CURRENT VERSION RESULTS TO THE $REF_TAG ONES   " >> endjob.txt
+    echo " ####################################################   " >> endjob.txt
+    echo "                                                        " >> endjob.txt
+
+    for runt in ${LRTYPE} ; do
+
+        echo "   -----------------------------------------------------------------------------" >> endjob.txt
+        echo "   ---> ${runt} results :  current version  |   ${REF_TAG} version  STREAM 1 & 2" >> endjob.txt
+        echo '                        solver.stat    .vs.    solver.stat         ' >> endjob.txt
+        echo '                        ocean.output   .vs.    ocean.output        ' >> endjob.txt
+
+        file1="${runt}/1_SHORT/solver.stat"          ;  file2="${runt}/2_SHORT/solver.stat"
+        filev1="${runt}/1_SHORT/REF/solver.stat"     ;  filev2="${runt}/2_SHORT/REF/solver.stat"
+        file_oc1="${runt}/1_SHORT/ocean.output"      ;  file_oc2="${runt}/2_SHORT/ocean.output"
+        file_roc1="${runt}/1_SHORT/REF/ocean.output" ;  file_roc2="${runt}/2_SHORT/REF/ocean.output"
+        xfilev1=0 ; xfilev2=0 ; xfile_oc1=0 ; xfile_oc2=0
+
+        echo "                                           " >> endjob.txt
+        echo "        STREAM 1 results :                 " >> endjob.txt
+        echo "        -----------------                  " >> endjob.txt
+        #
+        #-------
+        # solver.stat STREAM 1
+        checkfile ${file1}  'endjob.txt' NORM yes ; xfilev1=$?
+        checkfile ${filev1} 'endjob.txt' NORM ; xfilev1=$?
+    
+        mak_diff_file -x ${xfilev1} -a ${file1} -b ${filev1} -r ${runt} -s STREAM_1 -t ${REF_TAG}
+    
+        #-------
+        # ocean.output STREAM 1
+        checkfile ${file_oc1}  'endjob.txt' NORM yes ; xfile_oc1=$?
+        checkfile ${file_roc1} 'endjob.txt' NORM ; xfile_oc1=$?
+    
+        mak_diff_file -x ${xfile_oc1} -a ${file_oc1} -b ${file_roc1} -r ${runt} -s STREAM_1 -t ${REF_TAG}
+    
+        echo "                                           " >> endjob.txt
+        echo "        STREAM 2 results :                 " >> endjob.txt
+        echo "        -----------------                  " >> endjob.txt
+        #
+        #-------
+        # solver.stat STREAM 2
+        checkfile ${file2}  'endjob.txt' NORM yes ; xfilev2=$?
+        checkfile ${filev2} 'endjob.txt' NORM ; xfilev2=$?
+    
+        mak_diff_file -x ${xfilev2} -a ${file2} -b ${filev2} -r ${runt} -s STREAM_2 -t ${REF_TAG}
+    
+        #-------
+        # ocean.output STREAM 2
+        checkfile ${file_oc2}  'endjob.txt' NORM yes ; xfile_oc2=$?
+        checkfile ${file_roc2} 'endjob.txt' NORM ; xfile_oc2=$?
+    
+        mak_diff_file -x ${xfile_oc2} -a ${file_oc2} -b ${file_roc2} -r ${runt} -s STREAM_2 -t ${REF_TAG}
+    
+    done
+    #
+    #-------
+fi
+
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+# ###############################################
+# VI. SEND THE ASSESSMENT FILE REPORT "endjob.txt"
+# ###############################################
+mail -s "$TITLE" ${EMAIL} < endjob.txt
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/cron_jobs.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/cron_jobs.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/cron_jobs.ksh	(revision 4536)
@@ -0,0 +1,38 @@
+#!/usr/bin/ksh
+######################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# This script is launched by the lance_batch.ksh script
+# for a given configuration.
+# It aims to (for each standard configuration) check if
+# there are jobs in queue associated with the considered 
+# configuration. 
+# If jobs are still in queue it re-launched itself either
+# it launchs the assessment.ksh script 
+######################################################
+
+#set -xv
+
+CONF=$1
+LJOBS=qstat
+
+if [ ${CONF} == 'ORCA2_LIM' ] ; then
+CONFS=ORCA2
+elif [ ${CONF} == 'ZAGRIF' ] ; then
+CONFS=ZAGRI
+else
+CONFS=${CONF}
+fi
+
+JOBS_LIST=` ${LJOBS} |  grep -c ${CONFS}`
+if [ ${JOBS_LIST} = 0 ]
+then
+    sleep 60
+    ./assessment.ksh ${CONF} yes &
+    exit
+fi
+sleep 300
+./cron_jobs.ksh ${CONF} &
+exit
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_aix_mpi
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_aix_mpi	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_aix_mpi	(revision 4536)
@@ -0,0 +1,21 @@
+#!/bin/ksh
+############################################################################
+#### aix Header mpi
+############################################################################
+# Temps CPU max. en secondes (d'un processus)
+# @ cpu_limit  = 1000
+# Mémoire max. utilisée (ici 11 Go)
+# @ data_limit = 3gb
+# Type du travail
+# @ job_type = parallel
+# Nom du travail LoadLeveler
+# @ job_name   = 
+# Fichier de sortie standard du travail
+# @ output     = $(job_name)_std
+# Fichier de sortie d'erreur du travail
+# @ error      =  $(job_name)_err
+# Nombre de processus demandes
+# @ total_tasks = 8
+# @ queue
+#                                           
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_ax_mono_mon
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_ax_mono_mon	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_ax_mono_mon	(revision 4536)
@@ -0,0 +1,17 @@
+#!/bin/ksh
+############################################################################
+#### ax_mono Header mon
+############################################################################
+# Temps CPU max. en secondes (d'un processus)
+# @ cpu_limit  = 2000
+# Mémoire max. utilisée (ici 11 Go)
+# @ data_limit = 3gb
+# Nom du travail LoadLeveler
+# @ job_name   = 
+# Fichier de sortie standard du travail
+# @ output     = $(job_name)_std
+# Fichier de sortie d'erreur du travail
+# @ error      =  $(job_name)_err
+# @ queue
+#                                           
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mon
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mon	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mon	(revision 4536)
@@ -0,0 +1,4 @@
+#!/bin/ksh
+############################################################################
+#### osxxlf Header mon
+############################################################################
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mpi
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mpi	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_osxxlf_mpi	(revision 4536)
@@ -0,0 +1,4 @@
+#!/bin/ksh
+############################################################################
+#### osxxlf Header mpi
+############################################################################
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mon
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mon	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mon	(revision 4536)
@@ -0,0 +1,12 @@
+############################################################################
+#### sx8brodie Header mon
+############################################################################
+#PBS -S /bin/ksh                  # Shell used
+#PBS -l cputim_prc=00:20:00       # temps max (HH:MM:SS)
+#PBS -l cputim_job=00:40:00       # temps max (HH:MM:SS)
+#PBS -l memsz_job=3.0gb           # memoire max /job
+#PBS -N                           # Job name
+#PBS -e                           # error output file name
+#PBS -o                           # standard output file name
+
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mpi
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mpi	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_mpi	(revision 4536)
@@ -0,0 +1,13 @@
+############################################################################
+#### sx8brodie Header mpi
+############################################################################
+#PBS -S /bin/ksh                  # Shell used
+#PBS -q multi                     # classe multiple
+#PBS -l cpunum_job=8              # réservation de 8 processeurs
+#PBS -l cputim_prc=00:20:00       # temps max (HH:MM:SS)
+#PBS -l cputim_job=00:40:00       # temps max (HH:MM:SS)
+#PBS -l memsz_job=5.0gb           # memoire max /job
+#PBS -N                           # Job name
+#PBS -e                           # error output file name
+#PBS -o                           # standard output file name
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_omp
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_omp	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/jhd_sx8brodie_omp	(revision 4536)
@@ -0,0 +1,14 @@
+############################################################################
+#### sx8brodie Header omp
+############################################################################
+#PBS -S /bin/ksh                  # Shell used
+#PBS -q multi                     # classe multiple
+#PBS -l cpunum_job=8              # réservation de 8 processeurs
+#PBS -l cputim_prc=00:20:00       # temps max (HH:MM:SS)
+#PBS -l cputim_job=00:40:00       # temps max (HH:MM:SS)
+#PBS -l memsz_job=3.0gb           # memoire max /job
+#PBS -N                           # Job name
+#PBS -e                           # error output file name
+#PBS -o                           # standard output file name
+
+
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_GYRE.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_GYRE.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_GYRE.ksh	(revision 4536)
@@ -0,0 +1,237 @@
+set -xv
+
+CONF=GYRE
+# Variables changed by lance_batch.ksh script
+RUN=xxx
+NB_PROCS=xxx
+LAUNCH=xxx
+LEXE=xxx
+CPERF=xxx
+D_INPUT=xxx
+D_GET=xxx
+REF_TAG=xxx
+TSYMB=xxx
+
+# Variables changed by ins_valid.ksh script
+MAINDIR=/Users/ctlod/WORK/AZE
+WORK=/Users/ctlod/WORK/AZE/modipsl/config
+REF_OD=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+
+# Arguments
+# type = 'long' or '1_short' or '2_short'
+type=$1
+
+case ${type} in
+        'long' ) 
+             DIROUT='LONG'
+             ITERATIONS=360 ;;
+              
+        '1_short' ) 
+             DIROUT='1_SHORT'
+             ITERATIONS=180 ;;
+              
+        '2_short' ) 
+             DIROUT='2_SHORT'
+             ITERATIONS=180 ;;
+
+        'gtime' ) 
+             DIROUT='GTIME'
+             ITERATIONS=4320 ;;
+esac
+
+# Working directory
+cd ${TMPDIR}
+#-T- osxxlf cd ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/RUN
+#-T- osxxlf zback=$?
+#-T- osxxlf if [ ${zback} = 0 ] ; then rm -rf namelist* *.nc memory* solver.stat ocean.output* mpp.output* mono.output* ; fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Input files
+##############################################################
+##############################################################
+##############################################################
+# Ocean namelist
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/namelist namelist_f90
+sed -e /!/d  namelist_f90 > namelist
+
+# namelist modifications
+PAT_NIT000=$( grep 'nit000     =' namelist )
+PAT_NITEND=$( grep 'nitend     =' namelist )
+PAT_NSTOCK=$( grep 'nstock     =' namelist )
+PAT_NWRITE=$( grep 'nwrite     =' namelist )
+PAT_NRSTDT=$( grep 'nrstdt     =' namelist )
+PAT_NBITCM=$( grep 'nbit_cmp ='   namelist )
+PAT_NSOLVV=$( grep 'nsolv     =' namelist )
+PAT_RESTAR=$( grep 'ln_rstart  =' namelist )
+PAT_RESMLD=$( grep 'ln_trdmld_restart =' namelist )
+
+sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .false./" \
+-e "s/$PAT_NIT000/   nit000     =     1/" \
+-e "s/$PAT_NITEND/   nitend     =     ${ITERATIONS}/" \
+-e "s/$PAT_NSTOCK/   nstock     =     ${ITERATIONS}/" \
+-e "s/$PAT_NWRITE/   nwrite     =     60/" \
+-e "s/$PAT_NRSTDT/   nrstdt     =     0/" \
+-e "s/$PAT_NBITCM/   nbit_cmp =     1/" \
+-e "s/$PAT_NSOLVV/   nsolv     =      2/" \
+-e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .false./" \
+namelist > nam.tmp
+
+mv nam.tmp namelist
+
+# Analytical forcing
+
+# Get restarts files if needed
+if [ $type = '2_short' ]
+then
+    if [ ${RUN} = 'mon' -o ${RUN} = 'omp' ] ; then 
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart.nc restart.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld.nc restart_mld.nc
+    fi
+
+    if [ ${RUN} = 'mpi' ] ; then
+        typeset -Z4 i=0
+        while [ $i -lt $NB_PROCS ]
+        do
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_${i}.nc restart_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld_${i}.nc restart_mld_${i}.nc
+           let i=$i+1
+        done
+    fi
+
+    # namelist modifications
+    PAT_NIT000=$( grep 'nit000     =' namelist )
+    PAT_NITEND=$( grep 'nitend     =' namelist )
+    PAT_NRSTDT=$( grep 'nrstdt     =' namelist )
+    PAT_RESTAR=$( grep 'ln_rstart  =' namelist )
+    PAT_RESMLD=$( grep 'ln_trdmld_restart =' namelist )
+    ORCA_NIT000=$(( $ITERATIONS + 1 ))
+    ORCA_NITEND=$(( $ITERATIONS*2 ))
+    
+    sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .true./" \
+    -e "s/$PAT_NIT000/   nit000     =     $ORCA_NIT000/" \
+    -e "s/$PAT_NITEND/   nitend     =     $ORCA_NITEND/" \
+    -e "s/$PAT_NRSTDT/   nrstdt     =     2/" \
+    -e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .true./" \
+    namelist > nam.tmp
+    
+    mv nam.tmp namelist
+
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch run
+##############################################################
+##############################################################
+##############################################################
+
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_${RUN} opa_${CONF}_${RUN}
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_memo opa_${CONF}_memo
+chmod 777 opa_${CONF}_${RUN}
+chmod 777 opa_${CONF}_memo
+
+#
+# Profiling & Executable memory size
+####################################
+touch memory_size.txt
+
+case ${RUN} in
+        'mon' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie echo "Stack memory: $( (size opa_${CONF}_${RUN}) )"    >> memory_size.txt 
+#-T- sx8brodie echo "Static memory: $( (size opa_${CONF}_memo) )"   >> memory_size.txt  ;;
+#-T- aix     ;;
+#-T- ax_mono echo "Stack memory: $( (size opa_${CONF}_memo) )"    >> memory_size.txt 
+#-T- ax_mono echo "Static memory: $( (size opa_${CONF}_${RUN}) )"   >> memory_size.txt ;;
+#-T- osxxlf echo "Stack memory: $( (size opa_${CONF}_memo) )"    >> memory_size.txt 
+#-T- osxxlf echo "Static memory: $( (size opa_${CONF}_${RUN}) )"   >> memory_size.txt ;; 
+        'mpi' ) 
+#-T- sx8brodie export MPIPROGINF=detail ;;
+#-T- aix     ;;
+#-T- ax_mono ;;
+#-T- osxxlf  ;;
+        'omp' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie export OMP_NUM_THREADS=${NB_PROCS} ;;
+#-T- aix     ;;
+#-T- ax_mono ;;
+#-T- osxxlf  ;;
+esac
+#
+# >>>>>> EXECUTION < < < <
+##########################
+
+case ${RUN} in
+        'mon' | 'omp' ) 
+              ${CPERF} ./opa_${CONF}_${RUN} ;;
+        'mpi' ) 
+#-T- sx8brodie              ${CPERF} ${LEXE} ./opa_${CONF}_${RUN} ;;
+#-T- aix              ${CPERF} ${LEXE} ./opa_${CONF}_${RUN} ;;
+#-T- osxxlf   mpd&
+#-T- osxxlf   sleep 5
+#-T- osxxlf   ${CPERF} ${LEXE} ./opa_${CONF}_${RUN}
+#-T- osxxlf   mpdallexit ;;
+esac
+
+ls -l
+#
+
+##############################################################
+##############################################################
+##############################################################
+###             Save output files
+##############################################################
+##############################################################
+##############################################################
+case ${RUN} in
+	'mon' | 'omp' )
+               liste_files=' *abort* memory* namelist* perfs* solver.stat ocean.output layout* GYRE* restart* mono*' ;;
+	'mpi' )
+               liste_files=' *abort* namelist* solver.stat perfs* ocean.output* layout* GYRE* restart* mpp*' ;;
+esac
+
+# Ensure that all files saved are coming from the current run
+ind=1
+for k in $liste_files
+do
+   echo $k > temp
+   var=$( ( awk '{printf("%-.4s", varin ) } ' varin=$k temp ) )
+   if [ ${ind} = 1 -a ${var} == 'perf' ] ; then
+       kc='perf*'
+       rm -f ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/${kc}
+       ind=0
+   fi
+   cp $k ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/$k
+done
+
+##############################################################
+##############################################################
+##############################################################
+###             Retrieve some reference run files
+##############################################################
+##############################################################
+##############################################################
+if [ ${REF_TAG} ]
+then
+   STORE_DATA=${REF_OD}/${CONF}/${REF_TAG}/${RUN}/${DIROUT}
+   LFILES="solver.stat memory_size.txt ocean.output ${RUN}${CONF}_err"
+   for ref_file in ${LFILES}
+   do
+       ${D_GET} ${STORE_DATA}/${TSYMB}${ref_file} ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/REF/${ref_file}
+   done
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch restart job
+##############################################################
+##############################################################
+##############################################################
+if [ $type = '1_short' ] ; then
+    cd ${WORK}/NEMO_VALID/W${CONF}/${RUN}/2_SHORT
+    ${LAUNCH} job_${RUN}_2_short.ksh
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ORCA2_LIM.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ORCA2_LIM.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ORCA2_LIM.ksh	(revision 4536)
@@ -0,0 +1,254 @@
+set -xv
+
+CONF=ORCA2_LIM
+# Variables changed by lance_batch.ksh script
+RUN=xxx
+NB_PROCS=xxx
+LAUNCH=xxx
+LEXE=xxx
+CPERF=xxx
+D_INPUT=xxx
+D_GET=xxx
+REF_TAG=xxx
+TSYMB=xxx
+
+# Variables changed by ins_valid.ksh script
+MAINDIR=/Users/ctlod/WORK/AZE
+WORK=/Users/ctlod/WORK/AZE/modipsl/config
+REF_OD=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+
+# Arguments
+# type = 'long' or '1_short' or '2_short'
+type=$1
+
+case ${type} in
+        'long' ) 
+             DIROUT='LONG'
+             ITERATIONS=210 ;;
+              
+        '1_short' ) 
+             DIROUT='1_SHORT'
+             ITERATIONS=105 ;;
+              
+        '2_short' ) 
+             DIROUT='2_SHORT'
+             ITERATIONS=105 ;;
+
+        'gtime' ) 
+             DIROUT='GTIME'
+             ITERATIONS=5475 ;;
+esac
+
+# Working directory
+cd ${TMPDIR}
+#-T- osxxlf cd ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/RUN
+#-T- osxxlf zback=$?
+#-T- osxxlf if [ ${zback} = 0 ] ; then rm -rf namelist* *.nc memory* solver.stat ocean.output* mpp.output* mono.output* ; fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Input files
+##############################################################
+##############################################################
+##############################################################
+# Ocean namelist
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/namelist namelist_f90
+sed -e /!/d  namelist_f90 > namelist
+
+# Sea-Ice namelist
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/namelist_ice namelist_ice_f90
+sed -e /!/d  namelist_ice_f90 > namelist_ice
+
+# namelist modifications
+PAT_NIT000=$( grep 'nit000     =' namelist )
+PAT_NITEND=$( grep 'nitend     =' namelist )
+PAT_NSTOCK=$( grep 'nstock     =' namelist )
+PAT_NWRITE=$( grep 'nwrite     =' namelist )
+PAT_NRSTDT=$( grep 'nrstdt     =' namelist )
+PAT_NBITCM=$( grep 'nbit_cmp ='   namelist )
+PAT_TRACEN=$( grep 'ln_traadv_cen2   =' namelist )
+PAT_TRATVD=$( grep 'ln_traadv_tvd    =' namelist )
+PAT_LN_FWB=$( grep 'ln_fwb    =' namelist )
+PAT_N_CLAA=$( grep 'n_cla   =' namelist )
+PAT_NSOLVV=$( grep 'nsolv     =' namelist )
+PAT_RESTAR=$( grep 'ln_rstart  =' namelist )
+PAT_RESMLD=$( grep 'ln_trdmld_restart =' namelist )
+
+sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .false./" \
+-e "s/$PAT_NIT000/   nit000     =     1/" \
+-e "s/$PAT_NITEND/   nitend     =     ${ITERATIONS}/" \
+-e "s/$PAT_NSTOCK/   nstock     =     ${ITERATIONS}/" \
+-e "s/$PAT_NWRITE/   nwrite     =     75/" \
+-e "s/$PAT_NRSTDT/   nrstdt     =     0/" \
+-e "s/$PAT_NBITCM/   nbit_cmp =     1/" \
+-e "s/$PAT_TRACEN/   ln_traadv_cen2   =  .false./" \
+-e "s/$PAT_TRATVD/   ln_traadv_tvd    =  .true./" \
+-e "s/$PAT_LN_FWB/   ln_fwb    =  .false./" \
+-e "s/$PAT_N_CLAA/   n_cla   = 0/" \
+-e "s/$PAT_NSOLVV/   nsolv     =      2/" \
+-e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .false./" \
+namelist > nam.tmp
+
+mv nam.tmp namelist
+
+# Get forcing files
+${D_GET} ${D_INPUT}/ORCA2_LIM_nemo_v2.tar ORCA2_LIM_nemo_v2.tar
+tar xvf ORCA2_LIM_nemo_v2.tar
+rm -rf ORCA2_LIM_nemo_v2.tar
+
+# Get restarts files if needed
+if [ $type = '2_short' ]
+then
+    if [ ${RUN} = 'mon' -o ${RUN} = 'omp' ] ; then 
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart.nc restart.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*restart_ice.nc restart_ice_in.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld.nc restart_mld.nc
+    fi
+
+    if [ ${RUN} = 'mpi' ] ; then
+        typeset -Z4 i=0
+        while [ $i -lt $NB_PROCS ]
+        do
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_${i}.nc restart_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*restart_ice_${i}.nc restart_ice_in_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld_${i}.nc restart_mld_${i}.nc
+           let i=$i+1
+        done
+    fi
+
+    # namelist modifications
+    PAT_NIT000=$( grep 'nit000     =' namelist )
+    PAT_NITEND=$( grep 'nitend     =' namelist )
+    PAT_NRSTDT=$( grep 'nrstdt     =' namelist )
+    PAT_RESTAR=$( grep 'ln_rstart  =' namelist )
+    PAT_RESMLD=$( grep 'ln_trdmld_restart =' namelist )
+    ORCA_NIT000=$(( $ITERATIONS + 1 ))
+    ORCA_NITEND=$(( $ITERATIONS*2 ))
+    
+    sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .true./" \
+    -e "s/$PAT_NIT000/   nit000     =     $ORCA_NIT000/" \
+    -e "s/$PAT_NITEND/   nitend     =     $ORCA_NITEND/" \
+    -e "s/$PAT_NRSTDT/   nrstdt     =     2/" \
+    -e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .true./" \
+    namelist > nam.tmp
+    
+    mv nam.tmp namelist
+
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch run
+##############################################################
+##############################################################
+##############################################################
+
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_${RUN} opa_${CONF}_${RUN}
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_memo opa_${CONF}_memo
+chmod 777 opa_${CONF}_${RUN}
+chmod 777 opa_${CONF}_memo
+
+#
+# Profiling & Executable memory size
+####################################
+touch memory_size.txt
+
+case ${RUN} in
+        'mon' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie echo "Stack memory: $( (size opa_${CONF}_${RUN}) )"    >> memory_size.txt 
+#-T- sx8brodie echo "Static memory: $( (size opa_${CONF}_memo) )"   >> memory_size.txt  ;;
+#-T- aix     ;;
+#-T- ax_mono echo "Stack memory: $( (size opa_${CONF}_memo) )"    >> memory_size.txt 
+#-T- ax_mono echo "Static memory: $( (size opa_${CONF}_${RUN}) )"   >> memory_size.txt ;;
+#-T- osxxlf echo "Stack memory: $( (size opa_${CONF}_memo) )"    >> memory_size.txt 
+#-T- osxxlf echo "Static memory: $( (size opa_${CONF}_${RUN}) )"   >> memory_size.txt ;; 
+        'mpi' ) 
+#-T- sx8brodie export MPIPROGINF=detail ;;
+#-T- aix     ;;
+#-T- ax_mono ;;
+#-T- osxxlf  ;;
+        'omp' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie export OMP_NUM_THREADS=${NB_PROCS} ;;
+#-T- aix     ;;
+#-T- ax_mono ;;
+#-T- osxxlf  ;;
+esac
+#
+# >>>>>> EXECUTION < < < <
+##########################
+
+case ${RUN} in
+        'mon' | 'omp' ) 
+              ${CPERF} ./opa_${CONF}_${RUN} ;;
+        'mpi' ) 
+#-T- sx8brodie              ${CPERF} ${LEXE} ./opa_${CONF}_${RUN} ;;
+#-T- aix              ${CPERF} ${LEXE} ./opa_${CONF}_${RUN} ;;
+#-T- osxxlf   mpd&
+#-T- osxxlf   sleep 5
+#-T- osxxlf   ${CPERF} ${LEXE} ./opa_${CONF}_${RUN}
+#-T- osxxlf   mpdallexit ;;
+esac
+
+ls -l
+#
+
+##############################################################
+##############################################################
+##############################################################
+###             Save output files
+##############################################################
+##############################################################
+##############################################################
+case ${RUN} in
+	'mon' | 'omp' )
+               liste_files='*abort* memory* namelist* perfs* solver.stat ocean.output layout* ORCA2* restart* mono*' ;;
+	'mpi' )
+               liste_files='*abort* namelist* solver.stat perfs* ocean.output* layout* ORCA2* restart* mpp*' ;;
+esac
+
+# Ensure that all files saved are coming from the current run
+ind=1
+for k in $liste_files
+do
+   echo $k > temp
+   var=$( ( awk '{printf("%-.4s", varin ) } ' varin=$k temp ) )
+   if [ ${ind} = 1 -a ${var} == 'perf' ] ; then
+       kc='perf*'
+       rm -f ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/${kc}
+       ind=0
+   fi
+   cp $k ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/$k
+done
+
+##############################################################
+##############################################################
+##############################################################
+###             Retrieve some reference run files
+##############################################################
+##############################################################
+##############################################################
+if [ ${REF_TAG} ]
+then
+   STORE_DATA=${REF_OD}/${CONF}/${REF_TAG}/${RUN}/${DIROUT}
+   LFILES="solver.stat memory_size.txt ocean.output ${RUN}${CONF}_err"
+   for ref_file in ${LFILES}
+   do
+       ${D_GET} ${STORE_DATA}/${TSYMB}${ref_file} ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/REF/${ref_file}
+   done
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch restart job
+##############################################################
+##############################################################
+##############################################################
+if [ $type = '1_short' ] ; then
+    cd ${WORK}/NEMO_VALID/W${CONF}/${RUN}/2_SHORT
+    ${LAUNCH} job_${RUN}_2_short.ksh
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ZAGRIF.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ZAGRIF.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/job_ZAGRIF.ksh	(revision 4536)
@@ -0,0 +1,283 @@
+set -xv
+
+CONF=ZAGRIF
+# Variables changed by lance_batch.ksh script
+RUN=xxx
+NB_PROCS=xxx
+LAUNCH=xxx
+LEXE=xxx
+CPERF=xxx
+D_INPUT=xxx
+D_GET=xxx
+REF_TAG=xxx
+TSYMB=xxx
+
+# Variables changed by ins_valid.ksh script
+MAINDIR=/Users/ctlod/WORK/AZE
+WORK=/Users/ctlod/WORK/AZE/modipsl/config
+REF_OD=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+
+# Arguments
+# type = 'long' or '1_short' or '2_short'
+type=$1
+
+case ${type} in
+        'long' ) 
+             DIROUT='LONG'
+             ITERATIONS=210
+             NOUTPUT=75 ;;
+              
+        '1_short' ) 
+             DIROUT='1_SHORT'
+             ITERATIONS=105
+             NOUTPUT=75 ;;
+              
+        '2_short' ) 
+             DIROUT='2_SHORT'
+             ITERATIONS=105
+             NOUTPUT=75 ;;
+
+        'gtime' ) 
+             DIROUT='GTIME'
+             ITERATIONS=5475
+             NOUTPUT=75 ;;
+esac
+
+# Working directory
+cd ${TMPDIR}
+
+##############################################################
+##############################################################
+##############################################################
+###             Input files
+##############################################################
+##############################################################
+##############################################################
+# Ocean namelist
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/namelist namelist_f90
+sed -e /!/d  namelist_f90 > namelist
+
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/1_namelist 1_namelist_f90
+sed -e /!/d  1_namelist_f90 > 1_namelist
+
+# Sea-Ice namelist
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/namelist_ice namelist_ice_f90
+sed -e /!/d  namelist_ice_f90 > namelist_ice
+
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/1_namelist_ice 1_namelist_ice_f90
+sed -e /!/d  1_namelist_ice_f90 > 1_namelist_ice
+
+# AGRIF file
+cp ${MAINDIR}/modipsl/config/${CONF}/EXP00/AGRIF_FixedGrids.in AGRIF_FixedGrids.in
+
+for CHGFILE in `ls *namelist`
+do
+     # namelist modifications
+     PAT_NAMECF=$( grep 'cexper     =' ${CHGFILE} )
+     PAT_NIT000=$( grep 'nit000     =' ${CHGFILE} )
+     PAT_NITEND=$( grep 'nitend     =' ${CHGFILE} )
+     PAT_NSTOCK=$( grep 'nstock     =' ${CHGFILE} )
+     PAT_NWRITE=$( grep 'nwrite     =' ${CHGFILE} )
+     PAT_NRSTDT=$( grep 'nrstdt     =' ${CHGFILE} )
+     PAT_NBITCM=$( grep 'nbit_cmp ='   ${CHGFILE} )
+     PAT_TRACEN=$( grep 'ln_traadv_cen2   =' ${CHGFILE} )
+     PAT_TRATVD=$( grep 'ln_traadv_tvd    =' ${CHGFILE} )
+     PAT_LN_FWB=$( grep 'ln_fwb    =' ${CHGFILE} )
+     PAT_N_CLAA=$( grep 'n_cla   =' ${CHGFILE} )
+     PAT_NSOLVV=$( grep 'nsolv     =' ${CHGFILE} )
+     PAT_RESTAR=$( grep 'ln_rstart  =' ${CHGFILE} )
+     PAT_RESMLD=$( grep 'ln_trdmld_restart =' ${CHGFILE} )
+
+    if [ ${CHGFILE} = 'namelist' ] ; then
+        ORCA_NITEND=$(( $ITERATIONS   ))
+        ORCA_NSTOCK=$(( $NOUTPUT   ))
+        PAT_NAMECF_tmp="   cexper     =     \"${CONF}\""
+    else
+        ORCA_NITEND=$(( $ITERATIONS*2 ))
+        ORCA_NSTOCK=$(( $NOUTPUT*2   ))
+        PAT_NAMECF_tmp="$PAT_NAMECF"
+    fi
+
+     sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .false./" \
+     -e "s/$PAT_NAMECF/$PAT_NAMECF_tmp/" \
+     -e "s/$PAT_NIT000/   nit000     =     1/" \
+     -e "s/$PAT_NITEND/   nitend     =     ${ORCA_NITEND}/" \
+     -e "s/$PAT_NSTOCK/   nstock     =     ${ORCA_NITEND}/" \
+     -e "s/$PAT_NWRITE/   nwrite     =     ${ORCA_NSTOCK}/" \
+     -e "s/$PAT_NRSTDT/   nrstdt     =     0/" \
+     -e "s/$PAT_NBITCM/   nbit_cmp =     1/" \
+     -e "s/$PAT_TRACEN/   ln_traadv_cen2   =  .false./" \
+     -e "s/$PAT_TRATVD/   ln_traadv_tvd    =  .true./" \
+     -e "s/$PAT_LN_FWB/   ln_fwb    =  .false./" \
+     -e "s/$PAT_N_CLAA/   n_cla   = 0/" \
+     -e "s/$PAT_NSOLVV/   nsolv     =      2/" \
+     -e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .false./" \
+     ${CHGFILE} > nam.$$
+     
+     mv nam.$$ ${CHGFILE} && rm -f nam.$$
+done
+
+# Get forcing files
+${D_GET} ${D_INPUT}/ORCA2_LIM_nemo_v2.tar ORCA2_LIM_nemo_v2.tar
+tar xvf ORCA2_LIM_nemo_v2.tar
+rm -rf ORCA2_LIM_nemo_v2.tar
+
+# Get restarts files if needed
+if [ $type = '2_short' ]
+then
+    if [ ${RUN} = 'mon' -o ${RUN} = 'omp' ] ; then 
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/ZAGRI*_restart.nc restart.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/1_*restart.nc 1_restart.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/ZAGRI*restart_ice.nc restart_ice_in.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/1_*restart_ice.nc 1_restart_ice_in.nc
+        cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld.nc restart_mld.nc
+    fi
+
+    if [ ${RUN} = 'mpi' ] ; then
+        typeset -Z4 i=0
+        while [ $i -lt $NB_PROCS ]
+        do
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/ZAGRI*_restart_${i}.nc restart_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/1_*restart_${i}.nc 1_restart_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/ZAGRI*_restart_ice_${i}.nc restart_ice_in_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/1_*restart_ice_${i}.nc 1_restart_ice_in_${i}.nc
+           cp ${WORK}/NEMO_VALID/W${CONF}/${RUN}/1_SHORT/*_restart_mld_${i}.nc restart_mld_${i}.nc
+           let i=$i+1
+        done
+    fi
+
+    for CHGFILE in `ls *namelist`
+    do
+        # namelist modifications
+        PAT_NIT000=$( grep 'nit000     =' ${CHGFILE} )
+        PAT_NITEND=$( grep 'nitend     =' ${CHGFILE} )
+        PAT_NRSTDT=$( grep 'nrstdt     =' ${CHGFILE} )
+        PAT_RESTAR=$( grep 'ln_rstart  =' ${CHGFILE} )
+        PAT_RESMLD=$( grep 'ln_trdmld_restart =' ${CHGFILE} )
+
+        if [ ${CHGFILE} = 'namelist' ] ; then
+            ORCA_NIT000=$(( $ITERATIONS + 1 ))
+            ORCA_NITEND=$(( $ITERATIONS*2   ))
+        else
+            ORCA_NIT000=$(( $ITERATIONS*2 + 1 ))
+            ORCA_NITEND=$(( $ITERATIONS*4 ))
+        fi
+        
+        sed    -e "s/$PAT_RESTAR/   ln_rstart  =  .true./" \
+        -e "s/$PAT_NIT000/   nit000     =     $ORCA_NIT000/" \
+        -e "s/$PAT_NITEND/   nitend     =     $ORCA_NITEND/" \
+        -e "s/$PAT_NRSTDT/   nrstdt     =     2/" \
+        -e "s/$PAT_RESMLD/   ln_trdmld_restart  =  .true./" \
+        ${CHGFILE} > nam.$$
+        
+        mv nam.$$ ${CHGFILE} && rm -f nam.$$
+    done
+
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch run
+##############################################################
+##############################################################
+##############################################################
+
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_${RUN} opa_${CONF}_${RUN}
+cp ${WORK}/NEMO_VALID/W${CONF}/opa_${CONF}_memo opa_${CONF}_memo
+chmod 777 opa_${CONF}_${RUN}
+chmod 777 opa_${CONF}_memo
+
+#
+# Profiling & Executable memory size
+####################################
+touch memory_size.txt
+
+case ${RUN} in
+        'mon' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie echo "Stack memory: $( (size opa_${CONF}_${RUN}) )"    >> memory_size.txt 
+#-T- sx8brodie echo "Static memory: $( (size opa_${CONF}_memo) )"   >> memory_size.txt  ;;
+#-T- aix     ;;
+#-T- ax_mono echo "Stack memory: $( (size opa_${CONF}_memo) )"    >> memory_size.txt 
+#-T- ax_mono echo "Static memory: $( (size opa_${CONF}_${RUN}) )"   >> memory_size.txt ;;
+        'mpi' ) 
+#-T- sx8brodie export MPIPROGINF=detail ;;
+#-T- aix     ;;
+#-T- ax_mono ;;
+        'omp' ) 
+#-T- sx8brodie export F_PROGINF=detail
+#-T- sx8brodie export OMP_NUM_THREADS=${NB_PROCS}
+#-T- aix     ;;
+#-T- ax_mono ;;
+esac
+#
+# >>>>>> EXECUTION < < < <
+##########################
+
+case ${RUN} in
+        'mon' | 'omp' ) 
+              ${CPERF} ./opa_${CONF}_${RUN} ;;
+        'mpi' ) 
+              ${CPERF} ${LEXE} ./opa_${CONF}_${RUN} ;;
+esac
+
+ls -l
+#
+
+##############################################################
+##############################################################
+##############################################################
+###             Save output files
+##############################################################
+##############################################################
+##############################################################
+case ${RUN} in
+	'mon' | 'omp' )
+               liste_files=' *abort* memory* *namelist* perfs* solver.stat ocean.output 1_Agulhas* layout* ZAGRIF* restart* mono*' ;;
+	'mpi' )
+               liste_files=' *abort* *namelist* solver.stat perfs* ocean.output* layout* 1_Agulhas* ZAGRIF* restart* mpp*' ;;
+esac
+
+# Ensure that all files saved are coming from the current run
+ind=1
+for k in $liste_files
+do
+   echo $k > temp
+   var=$( ( awk '{printf("%-.4s", varin ) } ' varin=$k temp ) )
+   if [ ${ind} = 1 -a ${var} == 'perf' ] ; then
+       kc='perf*'
+       rm -f ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/${kc}
+       ind=0
+   fi
+   cp $k ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/$k
+done
+
+##############################################################
+##############################################################
+##############################################################
+###             Retrieve some reference run files
+##############################################################
+##############################################################
+##############################################################
+if [ ${REF_TAG} ]
+then
+   STORE_DATA=${REF_OD}/${CONF}/${REF_TAG}/${RUN}/${DIROUT}
+   LFILES="solver.stat memory_size.txt ocean.output ${RUN}${CONF}_err"
+   for ref_file in ${LFILES}
+   do
+       ${D_GET} ${STORE_DATA}/${TSYMB}${ref_file} ${WORK}/NEMO_VALID/W${CONF}/${RUN}/${DIROUT}/REF/${ref_file}
+   done
+fi
+
+##############################################################
+##############################################################
+##############################################################
+###             Launch restart job
+##############################################################
+##############################################################
+##############################################################
+if [ $type = '1_short' ] ; then
+    cd ${WORK}/NEMO_VALID/W${CONF}/${RUN}/2_SHORT
+    ${LAUNCH} job_${RUN}_2_short.ksh
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/lance_batch.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/lance_batch.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/JOBS/lance_batch.ksh	(revision 4536)
@@ -0,0 +1,273 @@
+#!/bin/ksh
+######################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# INPUT ARGS: 2 + 1 optional
+#     - CONF  : configuration name (ORCA2_LIM, GYRE ..)
+#     - MTIME : timing/no timing (timing or notiming)
+#     - REFTAG (optional): reference tag name to which current 
+#              version will be compare to
+#
+# WORK: This script aims to (for each standard configuration) :
+#
+#    I.   Take into account target's specificities 
+#         Variables below must be filled for a new target
+#         - W_XX   = name of target 
+#         - LAUN   = name of jobs launcher command
+#         - LLJOBS = name of jobs listing command
+#         - LSUB   = name of running command
+#         - LPERF  = name of timing command for the whole run
+#         - LJTIM  = required time for a one year run (/proc)
+#         - LJTIMJ = required time for a one year run (job)
+#         - CMDGET = name of specific command to retrieve files
+#         - SYMBOL = identifier associated to a platform which 
+#                    is used to name all outputs files
+#                    Ex: For Brodie, this symbol could be "B_" so
+#                    file names looks like B_solver.stat ...
+#
+#    II.  Build jobs
+#         - based on specific header depending on target, it must 
+#           be provided for a new target following samples
+#           jhd_[target_name]_mon for mono-processors runs
+#           jhd_[target_name]_mpi for multi-processors MPI runs
+#           jhd_[target_name]_omp for multi-processors OPen-MP runs
+#
+#    III. Launch jobs
+#         to test both reproductibility and restartability
+#         for each configuration NAME_CONF 
+#         & for each run type [mon, mpi, omp] 
+#         3 runs will be launched:
+#              - LONG
+#              - 1_SHORT
+#              - 2_SHORT
+#
+#    IV. Launch cron job
+#         Since no jobs (for a given configuration) are in 
+#         the batch queue, this cron will launch the assessment.ksh 
+#         script
+#
+##########################################################
+#set -xv
+##########################################################
+##### Begin Users modifications
+##########################################################
+# IODIR     : directory where to get ORCA2_LIM_nemo_v2.tar 
+# PRC       : total number of processors which will be used
+##########################################################
+IODIR=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+PRC=8
+TARGET=osxxlf
+##########################################################
+##### End   Users modifications
+##########################################################
+
+CONF=$1
+MTIME=$2
+REFTAG=$3
+RUN=$(basename `pwd`)
+
+# Specific case of Zahir:
+if [ ${RUN} = 'mon' -a ${TARGET} = 'aix' ] ; then TARGET=ax_mono ; fi
+
+# ---------------------------------------------------------------
+#  I. Take into account target's specificities 
+#     Select appropriate target lines in Job_${CONF}.ksh
+# ---------------------------------------------------------------
+if   [ ${TARGET} = 'sx8brodie' ]; then
+    W_XX='#-T- sx8brodie'
+    LAUN=qsub
+    LLJOBS=qstat
+    LSUB="mpirun -np ${PRC}"
+    LPERF=
+    LJTIM='01:20:00'
+    LJTIMJ='01:40:00'
+    CMDGET=mfget
+    SYMBOL=B_
+elif [ ${TARGET} = 'aix' ]; then
+    W_XX='#-T- aix'
+    LAUN=llsubmit
+    LLJOBS=Qstat
+    LSUB=
+    LPERF="poe hpmcount -o perfs_mpi.txt" 
+    LJTIM=4000
+    LJTIMJ=
+    CMDGET=mfget
+    SYMBOL=Z_
+elif [ ${TARGET} = 'ax_mono' ]; then
+    W_XX='#-T- ax_mono'
+    LAUN=llsubmit
+    LLJOBS=Qstat
+    LSUB=
+    LPERF="hpmcount -o perfs_mon.txt" 
+    LJTIM=30000
+    LJTIMJ=
+    CMDGET=mfget
+    SYMBOL=Z_
+elif [ ${TARGET} = 'osxxlf' ]; then
+    W_XX='#-T- osxxlf'
+    LAUN=
+    LLJOBS=
+    LSUB="mpirun -np ${PRC}"
+    LPERF=
+    LJTIM=
+    LJTIMJ=
+    CMDGET=cp
+    SYMBOL=D_
+else
+    echo '	#######################################'
+    echo ' 	You must give a target name :'
+    echo ' 	sx8brodie, aix, ax_mono or add one'
+    echo ' 	Have a look in lance_batch.ksh script'
+    echo '	#######################################'
+    stop
+fi
+
+sed -e "s/^$W_XX *//" job_${CONF}.ksh | grep -v '^#-T- ' > job_${CONF}.$$
+
+# --------------------------------------------------------------
+# II. Build jobs 
+#     Adapt header (batch jobs) and concatanate it with core job
+# --------------------------------------------------------------
+case ${TARGET} in
+     'osxxlf' )
+	  cp jhd_${TARGET}_${RUN} jhd_${TARGET}_${RUN}_tmp  ;;
+     'ax_mono' )
+          CAR_JNAM=$( grep '\# @ job_name' jhd_${TARGET}_${RUN} )
+          sed    -e "s/$CAR_JNAM/\# @ job_name = ${RUN}${CONF}/" \
+          jhd_${TARGET}_${RUN} > jhd_${TARGET}_${RUN}_tmp  ;;
+     'aix' )
+          CAR_JNAM=$( grep '\# @ job_name' jhd_${TARGET}_${RUN} )
+          CAR_JMPI=$( grep '\# @ total_tasks' jhd_${TARGET}_${RUN} )
+          sed    -e "s/$CAR_JNAM/\# @ job_name = ${RUN}${CONF}/" \
+          -e "s/$CAR_JMPI/\# @ total_tasks = ${PRC}/" \
+          jhd_${TARGET}_${RUN} > jhd_${TARGET}_${RUN}_tmp  ;;
+     'sx8brodie' )
+          CAR_JNAM=$( grep '\#PBS -N ' jhd_${TARGET}_${RUN} )
+          CAR_JNAMO=$( grep '\#PBS -o ' jhd_${TARGET}_${RUN} )
+          CAR_JNAME=$( grep '\#PBS -e ' jhd_${TARGET}_${RUN} )
+          if [ ${RUN} = 'mpi' -o ${RUN} = 'omp' ] ; then
+              CAR_JMPI=$( grep '\#PBS -l cpunum_job' jhd_${TARGET}_${RUN} )
+              sed    -e "s/$CAR_JNAM/\#PBS -N  ${RUN}${CONF}/" \
+              -e "s/$CAR_JNAMO/\#PBS -o  ${RUN}${CONF}_std/" \
+              -e "s/$CAR_JNAME/\#PBS -e  ${RUN}${CONF}_err/" \
+              -e "s/$CAR_JMPI/\#PBS -l cpunum_job=${PRC}/" \
+              jhd_${TARGET}_${RUN} > jhd_${TARGET}_${RUN}_tmp
+          else
+              sed    -e "s/$CAR_JNAM/\#PBS -N  ${RUN}${CONF}/" \
+              -e "s/$CAR_JNAMO/\#PBS -o  ${RUN}${CONF}_std/" \
+              -e "s/$CAR_JNAME/\#PBS -e  ${RUN}${CONF}_err/" \
+              jhd_${TARGET}_${RUN} > jhd_${TARGET}_${RUN}_tmp
+          fi ;;
+esac
+
+cat jhd_${TARGET}_${RUN}_tmp job_${CONF}.$$ > job_tmp_${RUN}.ksh
+rm -f job_${CONF}.$$ jhd_${TARGET}_${RUN}_tmp
+
+# -----------------------------------------------------------------------------
+# III. Launch jobs
+#      The 3 following jobs are created for the run [type]=mon,mpi,omp :
+#      - "job_[type]_long.ksh"      ---> long run
+#      - "job_[type]_1_short.ksh"   ---> stream 1 run
+#      - "job_[type]_2_short.ksh"   ---> stream 2 run
+#      - "job_[type]_gtime.ksh"     ---> one year run
+#      The first 2 as the last one are immediatly launched whereas "job_[type]_2_short.ksh"
+#      is launched only when the "job_[type]_1_short.ksh" short run is finished
+# -----------------------------------------------------------------------------
+jobnam[0]=long ; jobnam[1]=1_short ; jobnam[2]=2_short ; jobnam[3]=gtime 
+dirjob[0]=LONG ; dirjob[1]=1_SHORT ; dirjob[2]=2_SHORT ; dirjob[3]=GTIME 
+
+iloop=3
+if [ ${MTIME} = 'timing' ] ; then iloop=4 ; fi
+
+ind=0
+while [ $ind -lt ${iloop} ]
+do
+       CAR_TYPE_tmp=$( grep 'type=' job_tmp_${RUN}.ksh )
+       CAR_TYPE=`echo $CAR_TYPE_tmp | cut -f 1 -d " " `
+       CAR_RUN_tmp=$( grep 'RUN=xxx' job_tmp_${RUN}.ksh )
+       CAR_RUN=`echo $CAR_RUN_tmp | cut -f 1 -d " " `
+       CAR_MPP_tmp=$( grep 'NB_PROCS=xxx' job_tmp_${RUN}.ksh )
+       CAR_MPP=`echo $CAR_MPP_tmp | cut -f 1 -d " " `
+       CAR_SUB_tmp=$( grep 'LAUNCH=xxx' job_tmp_${RUN}.ksh )
+       CAR_SUB=`echo $CAR_SUB_tmp | cut -f 1 -d " " `
+       CAR_EXE_tmp=$( grep 'LEXE=xxx' job_tmp_${RUN}.ksh )
+       CAR_EXE=`echo $CAR_EXE_tmp | cut -f 1 -d " " `
+       CAR_PER_tmp=$( grep 'CPERF=xxx' job_tmp_${RUN}.ksh )
+       CAR_PER=`echo $CAR_PER_tmp | cut -f 1 -d " " `
+       CAR_MAN_tmp=$( grep 'MAINDIR=xxx' job_tmp_${RUN}.ksh )
+       CAR_MAN=`echo $CAR_MAN_tmp | cut -f 1 -d " " `
+       CAR_INP_tmp=$( grep 'D_INPUT=xxx' job_tmp_${RUN}.ksh )
+       CAR_INP=`echo $CAR_INP_tmp | cut -f 1 -d " " `
+       CAR_GET_tmp=$( grep 'D_GET=xxx' job_tmp_${RUN}.ksh )
+       CAR_GET=`echo $CAR_GET_tmp | cut -f 1 -d " " `
+       CAR_RTG_tmp=$( grep 'REF_TAG=xxx' job_tmp_${RUN}.ksh )
+       CAR_RTG=`echo $CAR_RTG_tmp | cut -f 1 -d " " `
+       CAR_TSY_tmp=$( grep 'TSYMB=xxx' job_tmp_${RUN}.ksh )
+       CAR_TSY=`echo $CAR_TSY_tmp | cut -f 1 -d " " `
+
+       sed    -e "s/$CAR_TYPE/type=${jobnam[$ind]}/" \
+       -e "s/$CAR_RUN/RUN=$RUN/" \
+       -e "s/$CAR_MPP/NB_PROCS=$PRC/" \
+       -e "s/$CAR_SUB/LAUNCH=$LAUN/" \
+       -e "s/$CAR_EXE/LEXE='$LSUB'/" \
+       -e "s/$CAR_PER/CPERF='$LPERF'/" \
+       -e "s?$CAR_INP?D_INPUT=$IODIR?" \
+       -e "s/$CAR_GET/D_GET=$CMDGET/" \
+       -e "s/$CAR_RTG/REF_TAG=$REFTAG/" \
+       -e "s/$CAR_TSY/TSYMB=$SYMBOL/" \
+       job_tmp_${RUN}.ksh > job_${RUN}_${jobnam[$ind]}.ksh
+
+       if [ ${jobnam[$ind]} = 'gtime' ] ; then
+
+           case ${TARGET} in
+                'ax_mono' | 'aix' )
+                     CAR_JTIM=$( grep '\# @ cpu_limit' job_${RUN}_${jobnam[$ind]}.ksh )
+                     sed    -e "s/$CAR_JTIM/\# @ cpu_limit = ${LJTIM}/" \
+                     job_${RUN}_${jobnam[$ind]}.ksh > job_${RUN}_${jobnam[$ind]}.ksh_tmp  ;;
+                'sx8brodie' )
+                     CAR_JTIMP=$( grep '\#PBS -l cputim_prc' job_${RUN}_${jobnam[$ind]}.ksh )
+                     CAR_JTIMJ=$( grep '\#PBS -l cputim_job' job_${RUN}_${jobnam[$ind]}.ksh )
+                     sed    -e "s/$CAR_JTIMP/\#PBS -l cputim_prc=${LJTIM}/" \
+                     -e "s/$CAR_JTIMJ/\#PBS -l cputim_job=${LJTIMJ}/" \
+                     job_${RUN}_${jobnam[$ind]}.ksh > job_${RUN}_${jobnam[$ind]}.ksh_tmp  ;;
+           esac
+           mv job_${RUN}_${jobnam[$ind]}.ksh_tmp job_${RUN}_${jobnam[$ind]}.ksh
+
+       fi
+
+       chmod 750 job_${RUN}_${jobnam[$ind]}.ksh
+
+       if [ ${jobnam[$ind]} != '2_short' ] ; then
+           mv job_${RUN}_${jobnam[$ind]}.ksh ${dirjob[$ind]}/.
+           cd ${dirjob[$ind]}
+           ${LAUN} job_${RUN}_${jobnam[$ind]}.ksh &
+           cd ../
+       else
+           mv job_${RUN}_${jobnam[$ind]}.ksh ${dirjob[$ind]}/.
+       fi
+
+       let ind=$ind+1
+done
+rm -f job_tmp_${RUN}.ksh
+
+# List all jobs submitted
+${LLJOBS}
+
+# -----------------------------------------------------------------------------
+# IV. Launch cron to be able to launch the assessment step
+# -----------------------------------------------------------------------------
+if [ ${RUN} == 'mon' ] ; then
+    cd ..
+    
+    CAR_LJOB_tmp=$( grep 'LJOBS=' cron_jobs.ksh )
+    CAR_LJOB=`echo $CAR_LJOB_tmp | cut -f 1 -d " " `
+    
+    sed    -e "s/$CAR_LJOB/LJOBS=${LLJOBS}/" cron_jobs.ksh > cron_jobs.$$
+    mv cron_jobs.$$ cron_jobs.ksh &&  rm -rf cron_jobs.$$
+    chmod 744 cron_jobs.ksh 
+
+    if [ ${TARGET} != 'osxxlf' ]; then
+        ./cron_jobs.ksh ${CONF} &
+    fi
+fi
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/MODIPSL_FILES/ins_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/MODIPSL_FILES/ins_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/MODIPSL_FILES/ins_make	(revision 4536)
@@ -0,0 +1,163 @@
+#!/bin/ksh
+# $Id: ins_make 108 2007-07-26 10:18:31Z bellier $
+#---------------------------------------------------------------------
+#- Installation of Makefiles according to an environment
+#---------------------------------------------------------------------
+function ins_make_Usage
+{
+echo "
+ins_make install the Makefile in the directories
+
+Usage :
+  ${b_n} [-h] [-v] [-d] [-p r] [-t h] [-w w] [-m m]
+
+Options :
+  -h   : help
+  -v   : verbose mode
+  -d   : debug mode
+  -p p : int and real precision I4R4/I4R8/I8R8/4/8
+  -t h : target host_name
+  -w w : directory Where to install the Makefile (recursive)
+  -m m : mpi context choosen for the coupling MPI1/MPI2
+
+Defaults :
+   -t local_host -p I4R8
+
+Example for remote host compilation :
+  ins_make -t sx8brodie
+"
+}
+#-  dirname and  basename
+d_n=${0%/*}; b_n=${0##*/};
+#- Retrieving and validation of the options
+x_v='silencious'; x_d='normal'; x_p="??"; x_t="??"; x_w="??"; x_m='??';
+while getopts :hvdp:m:t:w: V
+  do
+   case ${V} in
+    (h)  ins_make_Usage; exit 0;;
+    (v)  x_v='verbose';;
+    (d)  x_d='debug';;
+    (p)  x_p=${OPTARG};;
+    (t)  x_t=${OPTARG};;
+    (w)  x_w=${OPTARG};;
+    (m)  x_m=${OPTARG};;
+    (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
+         exit 2;;
+    (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
+         exit 2;;
+   esac
+  done
+shift $(($OPTIND-1));
+#-
+# Treatment of the options
+#-
+# Default INTEGER and REAL precision
+case ${x_p} in
+ ( I4R4 | 4 )  x_p='I4R4'; w_ip='4'; w_rp='4';;
+ ( I4R8 | ?? ) x_p='I4R8'; w_ip='4'; w_rp='8';;
+ ( I8R8 | 8 )  x_p='I8R8'; w_ip='8'; w_rp='8';;
+ (*)
+   echo 'Invalid precision ' 1>&2;
+   echo ${x_p}' (must be I4R4, I4R8, I8R8, 4 or 8)' 1>&2;
+   exit 1;;
+esac
+#-
+# Target_Host Name
+[[ ${x_t} = '??' ]] && \
+ { x_t=$(${d_n}/w_i_h);
+   { [[ ${?} != 0 ]] && \
+      { echo "Bad installation : w_i_h/uname unreachable" 1>&2;
+        exit 1; }; } || \
+     [[ ${x_t} = "Unknown" ]] && \
+      { echo "Local_Host not supported" 1>&2; exit 1; }; }
+#-
+MKTG=${d_n}'/AA_make.gdef'
+[[ ! -f "${MKTG}" ]] && { echo "${MKTG} unreachable ..."; exit 3; }
+#-
+W_XX=$(sed -n -e "s/^#-Q-  *\([^ ]*\).*$/\1/p" ${MKTG} | \
+       sort -u | sed -e "/${x_t}/!d");
+[[ '\?'"${W_XX}" != '\?'${x_t} ]] && \
+  { echo "Target_Host  "${x_t}"  not supported" 1>&2; exit 1; }
+#-
+case ${x_m} in
+ ( mpi1 | mpi2 | MPI1 | MPI2 | ?? );;
+ (*) echo "MPI context "${x_m}" not supported" 1>&2; exit 1;;
+esac
+#-
+[[ ${x_v} = 'verbose' ]] && \
+ { echo "";
+   echo '--- Mode         : '${x_v};
+   echo '--- Compilation  : '${x_d};
+   echo '--- Precision    : '${x_p};
+   echo '--- Target       : '${x_t};
+   echo '--- MPI context  : '${x_m}; }
+#-
+if [ '\?'${x_w} = '\?' ]; then
+l_rep=$(find ${d_n}/.. -name AA_make -print)
+else
+l_rep=$(find ${d_n}/../*/${x_w} -name AA_make -print)
+fi
+#-
+W_OS=${x_t};
+echo " ";
+echo "Installation of makefiles for $W_OS";
+echo " ";
+#-
+for i in ${l_rep}
+do
+  j=${i%/AA_make};
+  echo "Installation in ${j}";
+  MKTL="${j}"'/AA_make.ldef';
+  [[ ! -f "${MKTL}" ]] && { echo "${MKTL} unreachable ..."; exit 3; }
+  MKTR="${j}"'/AA_make';
+  cat ${MKTL} ${MKTG} ${MKTR} > mk1.$$;
+  W_PR='#-Q- '; W_XX=${W_PR}${x_t};
+  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
+#-
+# Default INTEGER and REAL precision
+  W_PR='#-P- '; W_XX=${W_PR}${x_p};
+  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk2.$$ > mk1.$$;
+#-
+# Handle the precision module "defprec.f90" in "IOIPSL/src"
+  [[ '!!'${j##*/modeles} = '!!/IOIPSL/src' ]] && \
+   { [[ ${x_v} = 'verbose' ]] && W_XX='-v' || W_XX="";
+     ${d_n}/ins_m_prec ${W_XX} -i ${w_ip} -r ${w_rp}; r_c=${?};
+     unset w_ip w_rp;
+     [[ ${r_c} != 0 ]] && exit ${r_c}; }
+#-
+# Debug
+  W_PR='#-D- ';
+  [[ ${x_d} = 'debug' ]] && W_XX=${W_PR}'MD' || W_XX=${W_PR}'MN';
+  sed -e "/^${W_XX} */ s///" -e "/^${W_PR}/d" mk1.$$ > mk2.$$;
+#-
+# Retrieve the path of the directory
+  mk_dir=$(cd ${j};/bin/pwd;)
+  W_XX='MAKE_DIR ='
+# Update the value
+  sed -e "s!^${W_XX}.*!${W_XX} ${mk_dir}!" mk2.$$ > mk1.$$
+  unset mk_dir;
+#-
+# Choice of mpi library for the coupling
+  W_XX='LIB_MPI ='; W_XX_BIS='LIB_MPI_BIS =';
+  case ${x_m} in
+   ( mpi1 | MPI1 )
+    lib_mpi='MPI1'; lib_mpi_bis='MPI1';
+    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
+        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
+      mk1.$$ > ${j}/Makefile;;
+   ( mpi2 | MPI2 )
+    lib_mpi='MPI2'; lib_mpi_bis='';
+    sed -e "s!^${W_XX}.*!${W_XX} ${lib_mpi}!" \
+        -e "s!^${W_XX_BIS}.*!${W_XX_BIS} ${lib_mpi_bis}!" \
+      mk1.$$ > ${j}/Makefile;;
+   (??) 
+    cp mk1.$$ ${j}/Makefile;;
+   (*) ;;
+  esac
+  unset lib_mpi lib_mpi_bis;
+done
+#-
+echo "";
+unset W_XX W_XX_BIS; rm -f mk1.$$ mk2.$$;
+#-
+exit 0;
Index: /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/ins_valid.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/ins_valid.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/2INSTALL/ins_valid.ksh	(revision 4536)
@@ -0,0 +1,282 @@
+#!/bin/ksh
+######################################################
+# Original : C. Talandier for ESOPA
+# Contact  : opatlod@locean-ipsl.upmc.fr
+#
+# This script aims to (for each standard configuration) :
+#  - I. Take into account specific files changes
+#       - ./modipsl/util/ins_make
+#       - ./modipsl/config/NAME_CONFIG/AA_make*
+#       - ./modipsl/config/NAME_CONFIG/scripts/BB_make.ldef
+#  - II. Build configuration's environment & dependencies
+#       - ./modipsl/config/NAME_CONFIG/WORK
+#       - ./modipsl/config/NAME_CONFIG/MY_SRC
+#       - ./modipsl/config/NAME_CONFIG/scripts/BB_make
+#  - III. Build results sub-directories in the OUTDIR 
+#         directory specified by user just below
+#         NEMO_VALID/WNAME_CONFIG/
+#                    |-- mon		--> MONO run
+#                    |   |-- 1_SHORT
+#                    |   |-- 2_SHORT
+#                    |   |-- LONG
+#                    |   `-- GTIME
+#                    |-- mpi		--> MPI run
+#                    |   |-- 1_SHORT
+#                    |   |-- 2_SHORT
+#                    |   |-- LONG
+#                    |   `-- GTIME
+#                    `-- omp		--> Open-MP run
+#                        |-- 1_SHORT
+#                        |-- 2_SHORT
+#                        |-- LONG
+#                        `-- GTIME
+#
+#  - IV. Modify lance_batch.ksh & assessment.ksh scripts
+#  - V. Preliminary compilations
+######################################################
+
+#set -xv
+
+##########################################################
+##### Begin Users modifications
+##########################################################
+# OUTDIR : working directory from which jobs will be launched 
+#          & results stored
+# INPUTD : directory where to get ORCA2_LIM_nemo_v2.tar 
+# REFDAT : directory where to get results from reference tags
+# DECOMP : total number of processors which will be used
+# MAIL   : give your e-mail
+# UAGRIF : one of the standard configurations is based on AGRIF yes/no
+##########################################################
+OUTDIR=/Users/ctlod/WORK/AZE/modipsl/config
+INPUTD=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+REFDAT=/Volumes/FENUA/ORCA2_LIM_nemo_v2_IO
+DECOMP=8
+MAIL="ctlod@locean-ipsl.upmc.fr"
+UAGRIF=yes
+##########################################################
+##### End   Users modifications
+##########################################################
+
+
+# Standard configurations
+NBCFG=3
+CONF[0]=ORCA2_LIM
+CONF[1]=GYRE
+CONF[2]=ZAGRIF
+LCLDIR=`pwd`
+
+# Use a modified modipsl script: ins_make
+# which allows to build Makefiles of a specific configuration
+# using the following syntax: ins_make -w NAME_CONF
+cp ./MODIPSL_FILES/ins_make ../../../util/.
+
+# Set following variable in AA_make.ldef script
+# - WWDIR = directory where to store results and jobs
+CAR_WORK_tmp=$( grep 'WWDIR=' ./CONFIG_FILES/AA_make.ldef )
+CAR_WORK=`echo $CAR_WORK_tmp | cut -f 1 -d " " `
+sed -e "s?${CAR_WORK}?WWDIR=${OUTDIR}?" ./CONFIG_FILES/AA_make.ldef > ./CONFIG_FILES/AA_make.ldef.$$ 
+mv ./CONFIG_FILES/AA_make.ldef.$$  ./CONFIG_FILES/AA_make.ldef && rm -f ./CONFIG_FILES/AA_make.ldef.$$
+
+# Get the current target name
+LOCTARG=`../../../util/w_i_h`
+
+# Loop over each standard configuration
+# #####################################
+ind=0
+while [ $ind -lt ${NBCFG} ]
+do
+       # I. Take into account specific changes
+       # #####################################
+       # Set following variables in job_NAME_CONF.ksh script
+       # - MAINDIR = directory where to get namelist input files
+       # - WORK    = directory where to store results
+       # - REF_OD  = directory where Are stored results from previous tags
+       cd ../../../.. ; NAME_ARCH=$( pwd ) ;
+       cd ${LCLDIR}
+       echo ${NAME_ARCH}
+       CAR_MAIN_tmp=$( grep 'MAINDIR=' ./JOBS/job_${CONF[${ind}]}.ksh )
+       CAR_MAIN=`echo $CAR_MAIN_tmp | cut -f 1 -d " " `
+       CAR_WORK_tmp=$( grep 'WORK=' ./JOBS/job_${CONF[${ind}]}.ksh )
+       CAR_WORK=`echo $CAR_WORK_tmp | cut -f 1 -d " " `
+       CAR_REFO_tmp=$( grep 'REF_OD=' ./JOBS/job_${CONF[${ind}]}.ksh  | head -1 )
+       CAR_REFO=`echo $CAR_REFO_tmp | cut -f 1 -d " " `
+       sed -e "s?${CAR_MAIN}?MAINDIR=${NAME_ARCH}?" -e "s?${CAR_WORK}?WORK=${OUTDIR}?" \
+       -e "s?${CAR_REFO}?REF_OD=${REFDAT}?" ./JOBS/job_${CONF[${ind}]}.ksh > ./JOBS/job_tmp.$$
+       mv ./JOBS/job_tmp.$$  ./JOBS/job_${CONF[${ind}]}.ksh && rm -f ./JOBS/job_tmp.$$
+
+       # II. Build configuration environment
+       # ###################################
+       (cd ../ ; ./use_cfg -n ${CONF[${ind}]} ;)
+echo '			'
+echo '	     >>>>>>>>   Configuration directories have been built:'
+echo "			./config/${CONF[${ind}]}/WORK"
+echo "			./config/${CONF[${ind}]}/MY_SRC"
+echo '			'
+
+       cp ./CONFIG_FILES/AA_make* ../../${CONF[${ind}]}/.
+       cp ./CONFIG_FILES/BB_make.ldef_${CONF[${ind}]} ../../${CONF[${ind}]}/scripts/BB_make.ldef
+
+       # Configuration dependencies
+       (cd ../../${CONF[${ind}]} ; ../VALID/fait_AA_make ; )
+echo '			'
+echo "             >>>>>>>>   Dependencies file ./config/${CONF[${ind}]}/BB_make have been re-built"
+echo '			'
+
+       # III. Build output sub-directories
+       # #################################
+       # Directories from where Jobs will be launched 
+       # and where results will be stored before analysed
+       cd ${OUTDIR}
+       if [ ! -d 'NEMO_VALID' ] ;  then
+           mkdir  NEMO_VALID
+       fi
+           cd NEMO_VALID
+       if [ ! -d W${CONF[${ind}]} ] ;  then
+           mkdir W${CONF[${ind}]}
+       fi
+       if [ ! -d W${CONF[${ind}]}/mon ] ;  then
+           mkdir W${CONF[${ind}]}/mon
+       fi
+       if [ ! -d W${CONF[${ind}]}/mon/LONG ] ;  then
+           mkdir W${CONF[${ind}]}/mon/LONG
+           mkdir W${CONF[${ind}]}/mon/LONG/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mon/LONG/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mon/GTIME ] ;  then
+           mkdir W${CONF[${ind}]}/mon/GTIME
+           mkdir W${CONF[${ind}]}/mon/GTIME/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mon/GTIME/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mon/1_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/mon/1_SHORT
+           mkdir W${CONF[${ind}]}/mon/1_SHORT/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mon/1_SHORT/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mon/2_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/mon/2_SHORT
+           mkdir W${CONF[${ind}]}/mon/2_SHORT/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mon/2_SHORT/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mpi ] ;  then
+           mkdir W${CONF[${ind}]}/mpi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mpi/LONG ] ;  then
+           mkdir W${CONF[${ind}]}/mpi/LONG
+           mkdir W${CONF[${ind}]}/mpi/LONG/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mpi/LONG/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mpi/GTIME ] ;  then
+           mkdir W${CONF[${ind}]}/mpi/GTIME
+           mkdir W${CONF[${ind}]}/mpi/GTIME/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mpi/GTIME/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mpi/1_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/mpi/1_SHORT
+           mkdir W${CONF[${ind}]}/mpi/1_SHORT/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mpi/1_SHORT/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/mpi/2_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/mpi/2_SHORT
+           mkdir W${CONF[${ind}]}/mpi/2_SHORT/REF
+	   if [ ${LOCTARG} = 'osxxlf' ] ; then mkdir W${CONF[${ind}]}/mpi/2_SHORT/RUN ; fi
+       fi
+       if [ ! -d W${CONF[${ind}]}/omp ] ;  then
+           mkdir W${CONF[${ind}]}/omp
+       fi
+       if [ ! -d W${CONF[${ind}]}/omp/LONG ] ;  then
+           mkdir W${CONF[${ind}]}/omp/LONG
+           mkdir W${CONF[${ind}]}/omp/LONG/REF
+       fi
+       if [ ! -d W${CONF[${ind}]}/omp/GTIME ] ;  then
+           mkdir W${CONF[${ind}]}/omp/GTIME
+           mkdir W${CONF[${ind}]}/omp/GTIME/REF
+       fi
+       if [ ! -d W${CONF[${ind}]}/omp/1_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/omp/1_SHORT
+           mkdir W${CONF[${ind}]}/omp/1_SHORT/REF
+       fi
+       if [ ! -d W${CONF[${ind}]}/omp/2_SHORT ] ;  then
+           mkdir W${CONF[${ind}]}/omp/2_SHORT
+           mkdir W${CONF[${ind}]}/omp/2_SHORT/REF
+       fi
+echo '			'
+echo '	     >>>>>>>>   The following sub-directories have been built '
+echo '                        under main directory '$( pwd )
+echo '			They are dedicated to store results'
+       tree W${CONF[${ind}]}
+echo '			'
+
+       cd ${LCLDIR}
+
+       let ind=$ind+1
+done
+
+
+# IV. Modify lance_batch.ksh & assessment.ksh scripts
+# ###################################################
+# Set following variables in lance_batch.ksh script
+# - IODIR = directory where to get ORCA2_LIM_nemo_v2.tar
+# - PRC   = total number of processors which will be used
+
+CAR_INPU_tmp=$( grep 'IODIR=' ./JOBS/lance_batch.ksh )
+CAR_INPU=`echo $CAR_INPU_tmp | cut -f 1 -d " " `
+CAR_PROC_tmp=$( grep 'PRC=' ./JOBS/lance_batch.ksh )
+CAR_PROC=`echo $CAR_PROC_tmp | cut -f 1 -d " " `
+CAR_TARG_tmp=$( grep 'TARGET=' ./JOBS/lance_batch.ksh | head -1)
+CAR_TARG=`echo $CAR_TARG_tmp | cut -f 1 -d " " `
+sed -e "s?${CAR_INPU}?IODIR=${INPUTD}?" -e "s?${CAR_PROC}?PRC=${DECOMP}?" \
+-e "s/${CAR_TARG}/TARGET=${LOCTARG}/" ./JOBS/lance_batch.ksh > ./JOBS/lance_batch.$$
+mv ./JOBS/lance_batch.$$  ./JOBS/lance_batch.ksh && rm -f ./JOBS/lance_batch.$$
+chmod 744 ./JOBS/lance_batch.ksh
+
+# Set following variables in assessment.ksh script
+# - TARGET = the current plateform 
+# - MAIL   = your e-mail
+CAR_TARG_tmp=$( grep 'TARGET=' ./JOBS/assessment.ksh )
+CAR_TARG=`echo $CAR_TARG_tmp | cut -f 1 -d " " `
+CAR_MAIL_tmp=$( grep 'EMAIL=' ./JOBS/assessment.ksh )
+CAR_MAIL=`echo $CAR_MAIL_tmp | cut -f 1 -d " " `
+sed -e "s/${CAR_TARG}/TARGET=${LOCTARG}/" -e "s/${CAR_MAIL}/EMAIL='${MAIL}'/" \
+./JOBS/assessment.ksh > ./JOBS/assessment.$$
+mv ./JOBS/assessment.$$  ./JOBS/assessment.ksh && rm -f ./JOBS/assessment.$$
+chmod 744 ./JOBS/assessment.ksh
+
+# V. Preliminary compilations
+# ###########################
+
+# IOIPSL compilation
+../../../util/ins_make -w IOIPSL
+if [ ${LOCTARG} = 'sx8brodie' ] ; then
+    (cd ../../../modeles/IOIPSL/src ; sxgmake ;)
+else
+    (cd ../../../modeles/IOIPSL/src ; gmake ;)
+fi
+echo '			'
+echo '	     >>>>>>>>   IOIPSL Makefile and compilation done'
+echo '			'
+
+# AGRIF compilation
+if [ ${UAGRIF} = 'yes' ] ;  then
+    ../../../util/ins_make -w AGRIF
+    (cd ../../../modeles/AGRIF/ ; gmake ;)
+    echo '			'
+    echo '			AGRIF Makefile and compilation done'
+    echo '			'
+fi
+
+
+echo '			'
+echo '			#############################################################'
+echo '             >>>>>>>>   Now set "by hand" the mpi domain decomposition indices jpni, '
+echo '                        jpnj & jpnij in par_oce.F90_keep files (keeping the "_keep" extension) '
+echo "                        in coherence with the ${DECOMP} total number of processors you just set "
+echo '                        Make this modification in the following directories:         '
+ind=0
+while [ $ind -lt ${NBCFG} ]
+do
+echo "                        ../config/${CONF[${ind}]}/MY_SRC"
+let ind=$ind+1
+done
+echo '			###########################################################'
+echo '			'
Index: /branches/2010_and_older/dev_001_GM/VALID/cfg.txt
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/cfg.txt	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/cfg.txt	(revision 4536)
@@ -0,0 +1,3 @@
+ORCA2_LIM OPA_SRC LIM_SRC C1D_SRC NST_SRC
+GYRE OPA_SRC LIM_SRC C1D_SRC
+ZAGRIF OPA_SRC LIM_SRC C1D_SRC NST_SRC
Index: /branches/2010_and_older/dev_001_GM/VALID/diff_nemo
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/diff_nemo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/diff_nemo	(revision 4536)
@@ -0,0 +1,34 @@
+#!/bin/ksh
+######################################################
+# Author : Rachid benshila for ESOPA
+# Contact : opatlod@lodyc.jussieu.fr
+#
+# This script to copy  a file from NEMO in the current 
+# directory
+#
+######################################################
+d_n=$(dirname $0); b_n=$(basename $0);
+d_file=$(dirname $1);b_file=$(basename $1);
+
+nemo_file=`find ${d_n}/../../modeles/NEMO/${d_file} -name ${b_file}`
+set -A nemo_tab $nemo_file
+
+if [ ${#nemo_tab[*]} -gt 1 ] ; then
+echo 'Multiple occurence found'
+echo ${nemo_tab[*]}
+echo 'Please specify one directory'
+exit
+fi
+if [ ${#nemo_tab[*]} -eq 0 ] ; then
+echo 'No occurence found'
+echo 'exiting'
+exit
+fi
+if [ ${#nemo_tab[*]} -eq 1 ] ; then
+diff ${b_file} ${nemo_file} 
+fi
+
+unset d_n
+unset b_n
+unset d_file
+unset b_file
Index: /branches/2010_and_older/dev_001_GM/VALID/env_cfg.csh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/env_cfg.csh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/env_cfg.csh	(revision 4536)
@@ -0,0 +1,24 @@
+#- Some tests ---
+set MODIPSL=$1
+if ( $1 == '' ) then
+echo 'error : usage source env_cfg.csh DIR/modipsl'
+exit
+endif 
+
+#- For the scripts
+alias getn ${MODIPSL}/config/UTIL/get_nemo
+alias difn ${MODIPSL}/config/UTIL/diff_nemo
+alias usec ${MODIPSL}/config/UTIL/use_cfg
+alias insm ${MODIPSL}/util/ins_make
+alias clrm ${MODIPSL}/util/clr_make
+alias inss ${MODIPSL}/util/ins_script
+alias faa  ${MODIPSL}/config/UTIL/fait_AA_make 
+
+#- To move easy
+alias cnw "chdir ${MODIPSL}/modeles/NEMO/WORK"
+alias cno "chdir ${MODIPSL}/modeles/NEMO/OPA_SRC"
+alias cnl "chdir ${MODIPSL}/modeles/NEMO/LIM_SRC"
+alias cnt "chdir ${MODIPSL}/modeles/NEMO/TOP_SRC"
+alias cco "chdir ${MODIPSL}/config"
+
+
Index: /branches/2010_and_older/dev_001_GM/VALID/env_cfg.ksh
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/env_cfg.ksh	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/env_cfg.ksh	(revision 4536)
@@ -0,0 +1,23 @@
+#- Some tests ---
+MODIPSL=$1
+if [ ${#MODIPSL} -eq 0 ]; then
+echo 'error : usage . env_cfg.ksh DIR/modipsl'
+fi
+
+#- For the scripts
+alias getn=${MODIPSL}/config/UTIL/get_nemo
+alias difn=${MODIPSL}/config/UTIL/diff_nemo
+alias usec=${MODIPSL}/config/UTIL/use_cfg
+alias insm=${MODIPSL}/util/ins_make
+alias clrm=${MODIPSL}/util/clr_make
+alias inss=${MODIPSL}/util/ins_script
+alias faa=${MODIPSL}/config/UTIL/fait_AA_make
+
+#- To move easy
+alias cnw="chdir ${MODIPSL}/modeles/NEMO/WORK"
+alias cno="chdir ${MODIPSL}/modeles/NEMO/OPA_SRC"
+alias cnl="chdir ${MODIPSL}/modeles/NEMO/LIM_SRC"
+alias cnt="chdir ${MODIPSL}/modeles/NEMO/TOP_SRC"
+alias cco="chdir ${MODIPSL}/config"
+
+
Index: /branches/2010_and_older/dev_001_GM/VALID/fait_AA_make
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/fait_AA_make	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/fait_AA_make	(revision 4536)
@@ -0,0 +1,751 @@
+#!/bin/ksh
+##set -vx
+############################################################
+#
+# Purpose :
+# This script aims to create create the AA_make file
+# in the WORK directory. 
+# AA_make contains :
+#    - compilation options speccific to NEMO
+#    - compilation rules
+#    - dependancies
+# Running the modipsl/util/ins_make command is needed AFTER
+# fait_AA_make.
+#
+# Method :
+# We use temporary files to perform the following steps :
+#    1- search all CPP keys in the code
+#    2- write compilation rules 
+#    3- add compilation options add the beginning of AA_make 
+#    4- search and write dependancies
+#    5- add some specific rules (links creation in the WORK)
+#
+############################################################
+#-
+echo "This script must be run from the ../modipsl/config/CONFIG_NAME directory"
+echo ""
+
+#- Save the previous BB_make file before its rebuild
+echo "Save the previous BB_make file before its rebuild"
+cp scripts/BB_make scripts/BB_make_save
+
+#- Start the BB_make rebuild step
+echo "Start the BB_make rebuild step"
+
+cd WORK
+pwd
+
+#-
+#- Search CPP keys ---
+liste_cle=$(egrep '^# *if[!( &]*def|^# *elif' *.[Fh] *.[Fh]90  2> /dev/null | grep key_ | sed 's/||/\
+/' | sed 's/\&\&/\
+/' | sed 's/^.*key_/key_/' | sed 's/ *[) ] *$//' | sort -u  )
+
+#-
+#- Write main compilation rules ---
+cat > tampon <<end
+
+.SUFFIXES: .f90 .F90 .F
+
+# Target
+all :	diroce libioipsl key keyverif src_file_list libagrif \$(IOIPSL_LIB) \$(AGRIF_LIB)
+		@echo --------------------------------------------
+		time gmake \$(EXEC_BIN) -j \$(NBPRC)
+		@echo --------------------------------------------
+		@cp SRC_FILE_LIST.temp SRC_FILE_LIST
+		@echo OPA model is OK
+
+# Cleaning objects, libraries and executables
+clean:
+ifeq (\$(AGRIF),use)
+		-@(cd OPAFILES; ./efface)
+endif
+		\$(RM) model.o \$(EXEC_BIN)
+		\$(RM) \$(MODDIR)/oce_\$(NEMOLIB)/\$(COMP)/*.mod
+		\$(RM) \$(MODEL_LIB)/*.o
+		\$(RM) ../../../tmp/tmp_\$(NEMOLIB)/\$(COMP)/* 
+		@echo OPA model \(.o .mod libraries and executables are removed\)
+
+# Dependancies
+diroce:
+		@if [ ! -d ../../../lib/oce_\$(NEMOLIB) ] ; then mkdir ../../../lib/oce_\$(NEMOLIB) ; fi
+		@if [ ! -d ../../../tmp/tmp_\$(NEMOLIB) ] ; then mkdir ../../../tmp/tmp_\$(NEMOLIB) ; fi
+		@if [ ! -d ../../../lib/oce_\$(NEMOLIB)/\$(COMP) ] ; then mkdir ../../../lib/oce_\$(NEMOLIB)/\$(COMP) ; fi
+		@if [ ! -d ../../../tmp/tmp_\$(NEMOLIB)/\$(COMP) ] ; then mkdir ../../../tmp/tmp_\$(NEMOLIB)/\$(COMP) ; fi
+
+\$(EXEC_BIN) :	 \$(MODEL_LIB) agrif2model.o model.o
+ifeq (\$(AGRIF),use)
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model.o agrif2model.o \$(MODEL_LIB)/*.o \$(OASISMPI2_LIB) \$(IOIPSL_LIB) \$(AGRIF_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+else
+		\$(F_L) \$(L_X) -o \$(EXEC_BIN) model.o \$(MODEL_LIB)/*.o \$(OASISMPI2_LIB) \$(IOIPSL_LIB) \$(NCDF_LIB) \$(LIBMPI) \$(LIBMP)
+endif
+
+# Agrif library and conv
+libagrif : firstagrif mpiagrif
+ifeq (\$(AGRIF),use)
+	@( if [ ! -d OPAFILES ]; then mkdir OPAFILES; fi )
+	@( if [ ! -d OPAFILES/AGRIF_INC ]; then mkdir OPAFILES/AGRIF_INC ; fi )
+	@( if [ ! -d OPAFILES/AGRIF_MODELFILES ]; then mkdir OPAFILES/AGRIF_MODELFILES ; fi )
+	@(cd ../../../modeles/AGRIF ; \$(M_K) -f Makefile P_P="\$(AGRIF_MPI)" )
+	@cp -rf ../../../modeles/AGRIF/agrif_opa.in OPAFILES/. 
+	@cp -rf ../../../modeles/AGRIF/conv OPAFILES/. 
+	@cp -rf ../../../modeles/AGRIF/efface OPAFILES/. 
+endif
+
+# Agrif interface with NEMO
+agrif2model.o :
+ifeq (\$(AGRIF),use)
+	@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+	@\$(F_C) \\
+#-Q- aix		-qsuffix=f=F90 \\
+#-Q- ax_mono		-qsuffix=f=F90 \\
+#-Q- osxxlf		-qsuffix=f=F90 \\
+	\$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+	   OPAFILES/\$*.F90 || { mv \$(PREF).L \$(TMP) ; false ; exit ; }
+endif
+
+# IOIPSL library 
+libioipsl :
+	(cd ../../../modeles/IOIPSL/src ; \$(M_K) -f Makefile )
+
+# Main program
+model.o :	\$(MODEL_LIB) model.f90
+		@\$(F_C) \$(F_O) -c model.f90
+
+# if the make script is stopped, one doesn't destroy library
+.PRECIOUS : \$(MODEL_LIB)
+#-Q- sxnec .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- sx6nec .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- sx8brodie .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- sxdkrz .PRECIOUS : \$(SXMODEL_LIB)
+#-Q- eshpux .PRECIOUS : \$(SXMODEL_LIB)
+
+# library dependancies
+\$(MODEL_LIB):	\$(LIB_OBJ)
+		@echo
+		@echo La bibliotheque est a jour
+		@echo
+
+# Default rules
+.DEFAULTS:
+
+# rules for the .f90 files
+\$(MODEL_LIB)/%.o : %.f90           
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+		\$*.f90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+		@mv \$*.o \$(MODEL_LIB)/.
+		@\$(RM) \$*.[f]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce_\$(NEMOLIB)/\$(COMP) ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- ax_mono		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the .F90 files
+\$(MODEL_LIB)/%.o : %.F90           
+ifeq (\$(AGRIF),use) 
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC \$*.F90 > OPAFILES/\$*.F90 
+		@(cd OPAFILES ; ./conv agrif_opa.in -rm \\
+#-Q- linux		-SubloopScalar \\
+#-Q- lxiv8		-SubloopScalar \\
+#-Q- g95			-SubloopScalar \\
+#-Q- f95			-SubloopScalar \\
+#-Q- osf1			-SubloopScalar \\
+		-comdirin ./ -comdirout AGRIF_MODELFILES/. -convfile \$*.F90)
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(P_C) \$(P_O) -IOPAFILES/AGRIF_INC OPAFILES/\$*.F90 > OPAFILES/AGRIF_MODELFILES/\$*.F90
+		-@mv -f OPAFILES/AGRIF_MODELFILES/\$*.F90 OPAFILES/\$*.F90
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+		OPAFILES/\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; } 
+else
+		@\$(F_C) \$(P_P) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+		\$*.F90 || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+endif
+		@mv \$*.o \$(MODEL_LIB)/.
+		@\$(RM) \$*.[f]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce_\$(NEMOLIB)/\$(COMP) ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- ax_mono		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the .F files
+\$(MODEL_LIB)/%.o : %.F           
+		@\$(F_C) \$(P_P) \$(F_F) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+		\$*.F || { if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi ; false ; exit ; }
+		@mv \$*.o \$(MODEL_LIB)/.
+		@\$(RM) \$*.[f]
+		@if [ -f \$*.mod ] ; then mv \$*.mod \$(MODDIR)/oce_\$(NEMOLIB)/\$(COMP) ; fi
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- ax_mono		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$(PREF)\$*.L \$(TMP) ; fi
+
+# rules for the library from the .f files 
+\$(MODEL_LIB)/%.o : %.f           
+		@\$(F_C) \$(F_O) \\
+#-Q- fjvpp		-Z \$*.L \\
+#-Q- sxnec		-R2 \\
+#-Q- sx6nec		-R2 \\
+#-Q- sx8brodie		-R2 \\
+#-Q- sxdkrz		-R2 \\
+#-Q- eshpux		-R2 \\
+#-Q- aix		-qsource \\
+#-Q- ax_mono		-qsource \\
+		\$*.f|| { if [ -f \$(PREF)\$*.L ] ; then mv \$*.L \$(TMP) ; fi ; false ; exit ; }
+		@mv \$*.o \$(MODEL_LIB)/.
+#-Q- aix		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- ax_mono		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- linux	@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+#-Q- osxxlf		@mv \$(PREF)\$*.lst \$(PREF)\$*.L
+		@if [ -f \$(PREF)\$*.L ] ; then mv \$*.L \$(TMP) ; fi
+
+end
+#-
+#- Compilation options ---
+exec 1> AA_make
+MAIN="model"
+echo '# $Header: /home/opalod/NEMOCVSROOT/VALID/fait_AA_make,v 1.22 2006/03/13 13:59:10 opalod Exp $'
+echo '# some variables'
+echo 'TMP = ../../../tmp/tmp_$(NEMOLIB)/$(COMP)'
+echo '#-Q- sxnec  # Compiler options for NEMO (IDRIS SX5-NEC) '
+echo '#-Q- sxnec  F_O = -dw -Wf\"-A idbl4\" -sx5 -ftrace -C vsafe -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- sx6nec  # Compiler options NEMO (CEA SX6-NEC) '
+echo '#-Q- sx6nec  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -C vsafe -Wf"-P nh" -Wf',-pvctl noassume loopcnt=10000 -L transform' -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- sx6nec  F_O = -size_t64 -dw -Wf\"-A dbl4\" -sx6 -ftrace -C vsafe -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- sx6nec  F_F = $(F_O)'
+echo '#-Q- sx6nec  L_X = $(L_O) -ftrace'
+echo '#-Q- sx8brodie  # Compiler options NEMO (CEA SX6-NEC) '
+echo '#-Q- sx8brodie  F_O = -dw -Wf\"-A idbl4\" -sx8 -C vopt -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- sx8brodie  F_F = $(F_O) -f3'
+echo '#-Q- sx8brodie  L_X = $(L_O)'
+echo '#-Q- sxdkrz  # Compiler options for NEMO (DKRZ SX6-NEC) '
+echo '#-Q- sxdkrz  F_O = -ew -sx6 -ftrace -C vsafe -Wf"-init stack=nan" -Wl"-f nan" -Wf"-P nh" -Wf"-pvctl noassume loopcnt=10000" -L transform -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- sxdkrz  F_F = $(F_O)'
+echo '#-Q- sxdkrz  L_X = $(L_O) -ftrace'
+echo '#-Q- eshpux  # Compiler options for NEMO (Earth Simulator)'
+echo '#-Q- eshpux  # for super perfs!'
+echo '#-Q- eshpux  # F_O = $(FTRACE) -pi nest=5 line=10000 expin=Fmpplib.F -Wf,-A idbl4 -C hopt -Wf"-P nh -O overlap" -Wf,-pvctl noassume loopcnt=10000 -L transform -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- eshpux  # regular options!'
+echo '#-Q- eshpux  F_O = $(FTRACE) -Wf,-A idbl4 -C vsafe -P stack -Wf"-P nh" -Wf,-pvctl noassume loopcnt=10000 -L transform -Wf,-pvctl nomsg -Wf"-O nomsg" -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- eshpux  F_F = $(F_O)'
+echo '#-Q- eshpux  L_X = $(L_O)'
+echo '#-Q- linux  # Compiler options for NEMO (pgf version)'
+echo '#-Q- linux  F_O = -Mlist -O3 -byteswapio -r8  -I $(MODDIR) -I$(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- linux  F_F = $(F_O)'
+echo '#-Q- linux  L_X = -r8 -O3'
+echo '#-Q- lxiv7  # Compiler options for NEMO (ifc version)'
+echo '#-Q- lxiv7  F_O = -O3 -r8  -I $(MODDIR) -I$(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- lxiv7  L_X = -r8 -O3'
+echo '#-Q- lxiv8  # Compiler options for NEMO (ifort version)'
+echo '#-Q- lxiv8  F_O = -O3 -r8  -I $(MODDIR) -I$(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- lxiv8  F_F = $(F_O) '
+echo '#-Q- lxiv8  L_X = -r8 -O3'
+echo '#-Q- g95  # Compiler options for NEMO (g95 version)'
+echo '#-Q- g95  F_O = -O3 -fno-second-underscore -r8 -funroll-all-loops -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)'
+echo '#-Q- g95  F_F = $(F_O)'
+echo '#-Q- g95  L_X = -r8 -O3'
+echo '#-Q- aix  # Compiler options for NEMO (aix version)'
+echo '#-Q- aix  F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- aix  F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- aix  L_O = $(F_P) -q64 -O3'
+echo '#-Q- aix  L_X = $(L_O)'
+echo '#-Q- ax_mono    # Compiler options for NEMO (aix version)'
+echo '#-Q- ax_mono    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- ax_mono    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qextname -qsource -q64 -qlargepage -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- ax_mono   L_O = $(F_P) -q64 -O3'
+echo '#-Q- ax_mono   L_X = $(L_O)'
+echo '#-Q- osxxlf    # Compiler options for NEMO (osxxlf version)'
+echo '#-Q- osxxlf    F_O = -O3 -qsave -qrealsize=8 -qsuffix=f=f90 -qsuffix=cpp=F90 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- osxxlf    F_F = -O3 -qsave -qrealsize=8 -qsuffix=f=f -qsuffix=cpp=F -qfixed=132 -qsource -qextname -qstrict -qmaxmem=-1 -I $(MODDIR) -I $(MODEL_LIB) -I $(NCDF_INC)' 
+echo '#-Q- osxxlf    L_X = -qrealsize=8 -O3'
+
+
+echo 'PREF='
+echo '#-Q- sxnec	PREF=i.'
+echo '#-Q- sx6nec	PREF=i.'
+echo '#-Q- sx8brodie	PREF=i.'
+echo '#-Q- sxdkrz	PREF=i.'
+echo '#-Q- eshpux	PREF=i.'
+echo ''
+echo '#Run type: mon, mpi or omp '
+echo 'ifeq ($(COMP),mon)'
+echo '#-Q- osxxlf  override F_C = xlf90 -c'
+echo '#-Q- osxxlf  override F_L = xlf90'
+echo 'endif'
+echo ''
+echo 'ifeq ($(COMP),memo)'
+echo '#-Q- sx8brodie  F_O := $(F_O) -P static'
+echo '#-Q- ax_mono    F_O := $(F_O) -qnosave'
+echo '#-Q- osxxlf     F_O := $(F_O) -qnosave'
+echo 'endif'
+echo ''
+echo 'ifeq ($(COMP),mpi)'
+echo 'P_P := $(P_P) key_mpp_mpi'
+echo '#-Q- osxxlf  override F_C = mpif90 -c'
+echo '#-Q- osxxlf  override F_L = mpif90'
+echo 'endif'
+echo ''
+echo 'ifeq ($(COMP),omp)'
+echo 'P_P := $(P_P) key_mpp_omp'
+echo '#-Q- sx8brodie F_O := $(F_O) -P auto'
+echo '#-Q- sx8brodie override F_F = $(F_O) '
+echo '#-Q- sx8brodie L_X := $(L_X) -P auto'
+echo 'endif'
+echo ''
+echo '# add suffix to P_P'
+echo 'P_P := $(P_P:%=$(prefix)%)'
+echo ''
+echo '# Some tests to define variables related to Agrif compilation'
+echo '# Please do not change '
+echo 'ifneq (,$(findstring key_agrif,$(P_P)))'
+echo 'AGRIF=use'
+echo 'else'
+echo 'AGRIF=notuse'
+echo 'AGRIF_LIB='
+echo 'endif'
+echo 'ifneq (,$(findstring key_mpp_mpi,$(P_P)))'
+echo 'AGRIF_MPI=-DAGRIF_MPI'
+echo 'else'
+echo 'AGRIF_MPI='
+echo 'endif'
+
+echo ''
+# Write the cpp key list with one key by line
+echo 'KEY_LIST = \c'
+for i in ${liste_cle}
+do
+ echo "\\"
+ echo "     $i \c"
+done
+
+echo ''
+echo '# .o file list in the library'
+echo 'LIB_OBJ = \c'
+#
+# find all .f in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.f 2> /dev/null`
+do
+  bn=`basename $i .f`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)/$bn.o\c"
+  fi
+  fi
+done
+
+# find all .f90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.f90  `
+do
+  bn=`basename $i .f90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)/$bn.o\c"
+  fi
+  fi
+done
+
+# find all .F90 in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.F90  `
+do
+  bn=`basename $i .F90`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)/$bn.o\c"
+  fi
+  fi
+done
+
+# find all .F in the current directory
+# build object files list  LIB_OBJ
+# one dependancy by line
+
+for i in `ls *.F 2> /dev/null `
+do
+  bn=`basename $i .F`
+  if [ "${bn}" != "${MAIN}" ] 
+  then 
+  if [ "${bn}" != "agrif2model" ] 
+  then 
+    echo "\\"
+    echo "		\$(MODEL_LIB)/$bn.o\c"
+  fi
+  fi
+ done
+
+echo ""
+
+cat tampon
+rm tampon
+#-
+#- Write all dependancies ---
+
+for fic in `ls *.f90 *.F90  *.F 2> /dev/null `
+do
+    if [ "${fic}" != "agrif2model.F90" ]
+    then
+    if [ "${fic}" != "${MAIN}.[Ff]" ]
+    then
+	i=0
+	j=0
+	dep=""
+	inc=""
+	inc2=""
+	inc3=""
+	luse0=""
+	luse1=""
+	luse2=""
+	luse3=""
+	key=""
+#- search include files (old ice model form, should it be suppressed ?)
+	for inc in `sed -n 's/^[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    dep="$dep\n$inc"
+	done
+
+#- take into account CPP dependancies  keys only (par_trc_trp example)
+	for key in `sed -n 's/^#[       eElL]*[iF][fF][         ]*[dD][eE][fF][iI][nN][eE][dD][         ]*//p' $fic | sort -u`
+	do
+	    j=1
+	done
+
+#- search include files on 3 levels
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+	    j=1
+	    dep="$dep\n$inc"
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    dep="$dep\n$inc2"
+		    #- search include  in include (third level !!!)
+		    for inc3 in `sed -n 's/^#[  	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc2 | sort -u`
+		    do
+			dep="$dep\n$inc3"
+		    done
+		done
+	done
+
+#- search USE in include files
+	for inc in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $fic | sort -u`
+	do
+		for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc | sort -u`
+		do
+	        if [ $fuse0 != "ioipsl" ] 
+                then
+	        if [ $fuse0 != "netcdf" ] 
+                then
+                if [ $fuse0 != "Agrif_Util" ] 
+                then
+                if [ $fuse0 != "Agrif_Types" ] 
+                then
+		    lfuse0=$fuse0.f90
+		    [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		    luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)/$fuse0.o"
+                fi
+                fi
+                fi
+                fi
+		done
+
+#- search USE in  files included in included files and add to luse0
+
+		for inc2 in `sed -n 's/^#[ 	]*[iI][nN][cC][lL][uU][dD][eE][ 	]*\(['\''"]\)\([^'\''"]*\)\1.*/\2/p' $inc | sort -u`
+		do
+		    for fuse0 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $inc2 | sort -u`
+		    do
+	            if [ $fuse0 != "ioipsl" ] 
+                    then
+	            if [ $fuse0 != "netcdf" ] 
+                    then
+                    if [ $fuse0 != "Agrif_Util" ] 
+                    then
+                    if [ $fuse0 != "Agrif_Types" ] 
+                    then
+		        lfuse0=$fuse0.f90
+		        [ -f $fuse0.F90 ] && lfuse0=$fuse0.F90
+		        luse0="$luse0\n$lfuse0\n\$(MODEL_LIB)/$fuse0.o"
+                    fi
+                    fi
+                    fi
+                    fi
+		    done
+  	        done
+	done
+
+#- search USE (and USE of USE and so on three levels)
+	for fuse1 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $fic | sort -u`
+	do
+	if [ $fuse1 != "ioipsl" ] 
+        then
+	if [ $fuse1 != "netcdf" ] 
+        then
+        if [ $fuse1 != "Agrif_Util" ] 
+        then
+        if [ $fuse1 != "Agrif_Types" ] 
+        then
+	    lfuse1=$fuse1.f90
+	    [ -f $fuse1.F90 ] && lfuse1=$fuse1.F90
+	    luse1="$luse1\n$lfuse1\n\$(MODEL_LIB)/$fuse1.o"
+		for fuse2 in `sed -n 's/^[ 	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse1 | sort -u`
+		do
+	        if [ $fuse2 != "ioipsl" ] 
+                then
+	        if [ $fuse2 != "netcdf" ] 
+                then
+                if [ $fuse2 != "Agrif_Util" ] 
+                then
+                if [ $fuse2 != "Agrif_Types" ] 
+                then
+		    lfuse2=$fuse2.f90
+		    [ -f $fuse2.F90 ] && lfuse2=$fuse2.F90
+		    luse2="$luse2\n$lfuse2\n\$(MODEL_LIB)/$fuse2.o"
+		    # on cherche les USE  dans le fichier deja USE (3eme niveau! balaise!)
+		    for fuse3 in `sed -n 's/^#[  	]*[uU][sS][eE] [ 	]*\([^!,;]*\).*/\1/p' $lfuse2 | sort -u`
+		    do
+		    if [ $fuse3 != "ioipsl" ] 
+                    then
+		    if [ $fuse3 != "netcdf" ] 
+                    then
+                    if [ $fuse3 != "Agrif_Util" ] 
+                    then
+                    if [ $fuse3 != "Agrif_Types" ] 
+                    then
+			luse3="$luse3\n$lfuse3\n\$(MODEL_LIB)/$fuse3.o"
+                    fi		    
+                    fi		    
+                    fi		    
+                    fi		    
+                    done
+                fi
+                fi
+                fi		    
+                fi
+		done
+        fi
+        fi		    
+        fi
+        fi
+	done
+#-
+#-  dep contains all dependancies 
+	echo "\$(MODEL_LIB)/`echo $fic|awk -F. '{print $1}'`.o :       \c"
+	for depele in `echo $luse3 | sort -u` `echo $luse2 | sort -u` `echo $luse1 | sort -u` `echo $luse0 | sort -u` `echo $dep | sort -u`
+	do
+	    echo "\\"
+ 	    echo "	$depele \c"
+ 	    let i=i+1 # pour signaler le premier
+	done
+
+#-
+#- add dependancies with IOIPSL library (if source files contains IOIPSL)
+        grep -i 'use *ioipsl' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(IOIPSL_LIB) \c")
+
+#-
+#- add dependancies with IOIPSL library (if source files contains Agrif_*)
+        grep -i 'use Agrif_*' ${fic} >/dev/null && ( echo "\\" ; echo "	\$(AGRIF_LIB) \c")
+
+#-
+#- on ajoute la dependance avecadd dependancies with KEY_CPP (if source file inclides cp  keys)
+	if [ ${j} != "0" ] 
+        then 
+	  echo "\\"
+	  echo "	KEY_CPP \c" 
+	fi
+#-
+#- end with the file itself
+	     echo "\\"
+       	     echo "	$fic"
+    fi
+    fi
+echo $fic done >/dev/tty
+done
+#-
+#- Write some special rules ---
+echo '# agrif previous use'
+echo "firstagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo '	@if [ -z "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) model.o $(MODDIR)/oce_$(NEMOLIB)/$(COMP)/*.mod $(SXMODEL_LIB); fi'
+echo "else"
+echo '	@if [ -n "`cat KEY_CPP | grep key_agrif`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce_$(NEMOLIB)/$(COMP)/*.mod $(SXMODEL_LIB); fi'
+echo "endif"
+#-
+echo '#- RB : this rule is a pretty miserable trick to be able to re-compile NEMP-AGRIF-mono after NEMO-AGRIF-mpp'
+echo '#- I guess the good correction should be in AGRIF/LIB/toamr.c for the conv, to remove useless allocation declarations in AGRIF_INC'
+echo '# recompile all in this case' 
+echo "mpiagrif:"
+echo "ifeq (\$(AGRIF),use)"
+echo "ifeq (,\$(AGRIF_MPI))"
+echo '	@if [ -n "`cat KEY_CPP | grep key_mpp_mpi`" ]; then $(RM) -r OPAFILES model.o $(MODDIR)/oce_$(NEMOLIB)/$(COMP)/*.mod $(SXMODEL_LIB); fi'
+echo "endif"
+echo "endif"
+#-
+echo '# key changing control'
+echo "key: "
+echo "	@echo CHANGE of CPP KEYS yes/no ?"
+echo "	-@if [ \"\`cat KEY_CPP\`\" != \"\$(P_P:\$(prefix)%=%)\" ] ; then \\"
+echo "		echo CPP options changed ; echo \"\$(P_P:\$(prefix)%=%)\" > KEY_CPP ; fi "
+#-
+echo '# check key values'
+echo "keyverif:"
+echo '	@echo CHECKING KEY'
+echo '	@echo KEY USED : '
+echo '	@for v in ` echo $(P_P:$(prefix)%=%) ` ; \'
+echo '	do \'
+echo '	echo $$v ;\'
+echo '        w=`echo $$v | cut -c1-3` ; \'
+echo '        if [ $$w = `echo "key"` ] ; then \'
+echo '        r=n ; \'
+echo '        echo " $(KEY_LIST) " | (grep $$v >/dev/null 2>&1) || r=o ; \'
+echo '           if [ $$r != "n" ] ; then \'
+echo '              echo "UNKNOWN KEY" ;\'
+echo '              false ;  \'
+echo '              exit ;  \'
+echo '           fi \'
+echo '        fi \'
+echo '	done'
+echo '# Checking the number of routines'
+echo "src_file_list: EMPTY"
+echo '	@echo CHECKING THE NUMBER AND NAMES OF SOURCE FILES '
+echo '	@$(RM) `ls | fgrep -v -f .patron` '
+echo '	@check=`grep OPA_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OPA_SRC files"                ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/*.[Ffh]90          . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/DYN/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/TRA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/TRD/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/DIA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/DOM/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/OBC/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/FLO/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/LDF/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/ZDF/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/SOL/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/DTA/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/SBC/*.[Ffh]90      . ; \'
+echo '	    ln -sf ../../../modeles/NEMO/OPA_SRC/IOM/*.[Ffh]90      . ; \'
+echo '  fi '
+echo '	@check=`grep LIM_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use LIM_SRC files"                ; \'
+echo '      ln -sf ../../../modeles/NEMO/LIM_SRC/*.[Ffh]90          . ; \'
+echo '  fi '
+echo '	@check=`grep NST_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use NST_SRC files"                ; \'
+echo '      \$(RM) agrif_opa_interp.F90           ; \'
+echo '      \$(RM) agrif_opa_sponge.F90           ; \'
+echo '      \$(RM) agrif_opa_update.F90           ; \'
+echo '      ln -sf ../../../modeles/NEMO/NST_SRC/*.[Ffh]90      .     ; \'
+echo '  fi '
+echo '	@check=`grep C1D_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use C1D_SRC files"                ; \'
+echo '      ln -sf ../../../modeles/NEMO/C1D_SRC/*.[Ffh]90          . ; \'
+echo '  fi '
+echo '	@check=`grep TOP_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then  \'
+echo '	echo "   use TOP_SRC files"                ; \'
+echo '      \$(RM) trcstp.F90                      ; \'
+echo '      \$(RM) sms.F90                         ; \'
+echo '      \$(RM) initrc.F90                      ; \'
+echo '      ln -sf ../../../modeles/NEMO/TOP_SRC/*.[Ffh]90          . ; \'
+echo '      ln -sf ../../../modeles/NEMO/TOP_SRC/SMS/*.[Ffh]        . ; \'
+echo '      ln -sf ../../../modeles/NEMO/TOP_SRC/SMS/*.[Ffh]90      . ; \'
+echo '      ln -sf ../../../modeles/NEMO/TOP_SRC/TRP/*.[Ffh]90      . ; \'
+echo '  fi '
+echo '	@check=`grep OFF_SRC .config`              ; \'
+echo '	if [ -n "$$check" ] ; then                   \'
+echo '	echo "   use OFF_SRC files"                ; \'
+echo '      ln -sf ../../../modeles/NEMO/OFF_SRC/*.[Ffh]90          . ; \'
+echo '      ln -sf ../../../modeles/NEMO/OFF_SRC/*/*.[Ffh]90        . ; \'
+echo '  fi '
+echo ' '
+echo '	@mn=`awk '"'"'{ print $$1 }'"'"' .config `  ; \'
+echo '  myrep=../../../config/$$mn/MY_SRC ; \'
+echo '  echo "*** Dealing with my modified source code, located in" $$myrep ; \'
+echo '  for i in `ls $$myrep` ; do \'
+echo '    [ -f $$i ] && \$(RM) $$i ;\'
+echo '  done ; \'
+echo '  myrep_list=`(cd $$myrep ; ls *.[Ffh]90 *.[Ffh] *.mk)` ; \'
+echo '  if [ -n "$$myrep_list" ] ; then \'
+echo '      for F in $$myrep_list; do \'
+echo '         echo "---> Reconstruct link to MY_SRC/$$F" ; \'
+echo '         ln -sf  $$myrep/$$F . ; \'
+echo '      done ; \'
+echo '  fi '
+echo ' '
+echo '	@\$(RM) tmplist'
+echo '	@ls -1 | fgrep -v -f .patron >tmplist'
+echo '	@cmp tmplist SRC_FILE_LIST.temp || { echo some routines have been added or suppressed ; \'
+echo '	sdiff -s tmplist SRC_FILE_LIST.temp ; cp tmplist SRC_FILE_LIST.temp ; \'
+echo '	\$(RM) model.o \$(MODEL_LIB)/*.o  \$(EXEC_BIN) ; \'
+echo '	echo "Rebuilding the AA_make files" ; \'
+echo '	cd ..  ; ../VALID/fait_AA_make ; echo " " ; \'
+echo '	echo "THE ins_make COMMAND in modipsl/util MUST BE RERUN PLEASE DO SO BEFORE gmake" ; \'
+echo '	echo "========================================== " ; \'
+echo '	../../util/ins_make -w \$(NEMOLIB) ; echo " " ;  false ; exit ; }'
+echo "EMPTY: "
+exec > /dev/null
+
Index: /branches/2010_and_older/dev_001_GM/VALID/get_nemo
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/get_nemo	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/get_nemo	(revision 4536)
@@ -0,0 +1,34 @@
+#!/bin/ksh
+######################################################
+# Author : Rachid benshila for ESOPA
+# Contact : opatlod@lodyc.jussieu.fr
+#
+# This script to copy  a file from NEMO in the current 
+# directory
+#
+######################################################
+d_n=$(dirname $0); b_n=$(basename $0);
+d_file=$(dirname $1);b_file=$(basename $1);
+
+nemo_file=`find ${d_n}/../../modeles/NEMO/${d_file} -name ${b_file}` 
+set -A nemo_tab $nemo_file
+
+if [ ${#nemo_tab[*]} -gt 1 ] ; then
+echo 'Multiple occurence found'
+echo ${nemo_tab[*]}
+echo 'Please specify one directory'
+exit
+fi
+if [ ${#nemo_tab[*]} -eq 0 ] ; then
+echo 'No occurence found'
+echo 'exiting'
+exit
+fi
+if [ ${#nemo_tab[*]} -eq 1 ] ; then
+\cp ${nemo_file} .
+fi
+
+unset d_n
+unset b_n
+unset d_file
+unset b_file
Index: /branches/2010_and_older/dev_001_GM/VALID/use_cfg
===================================================================
--- /branches/2010_and_older/dev_001_GM/VALID/use_cfg	(revision 4536)
+++ /branches/2010_and_older/dev_001_GM/VALID/use_cfg	(revision 4536)
@@ -0,0 +1,282 @@
+#!/bin/ksh
+######################################################
+# Author : Rachid benshila for ESOPA
+# Contact : opatlod@lodyc.jussieu.fr
+#
+# This script aims to create the OPA/WORK directory
+# and to link in the WORK the BB_make and BB_make.ldef 
+# associated  to a chosen configuration
+#
+######################################################
+d_n=$(dirname $0); b_n=$(basename $0);
+
+#set -xv
+
+#- Saisie et validation des options
+x_d="";
+x_n="";
+x_r="";
+while getopts :hld:n:r: V
+  do
+    case $V in
+      (h)  echo "Usage    : "${b_n} \
+                " [-h] [-l] [-d] [-p r] [-t h] ";
+           echo " -h      : help";
+           echo " -l      : list existing configurations";
+           echo " -n name : config name";
+           echo " -d dir  : choose directories";
+           echo "";
+           echo "Example to install a new configuration MY_CONFIG";
+           echo "with OPA_SRC and ICE_SRC ";
+           echo "use_cfg -n MY_CONFIG -d \"OPA_SRC ICE_SRC\"";
+           echo "";
+#           echo "Defaults     : ";
+           echo "";
+           exit 0;;
+      (d)  x_d=${OPTARG};;
+      (n)  x_n=${OPTARG};;
+      (r)  x_r=${OPTARG};;
+      (l)  cat ${d_n}/cfg.txt; exit;;
+      (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
+           exit 2;;
+      (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
+           exit 2;;
+    esac
+  done
+shift $(($OPTIND-1));
+
+#- Some tests ---
+m_n=${x_n}
+
+if [ ${#x_n} -eq 0 ]; then
+echo "Warning"
+echo "No configuration specified"
+echo "use_cfg -h for help"
+exit
+fi
+
+cat ${d_n}/cfg.txt | grep ${m_n} > ${d_n}/cfg.tmp
+read CONFIG TAB[0] TAB[1] TAB[2] TAB[3] TAB[4] TAB[5] < ${d_n}/cfg.tmp
+\rm ${d_n}/cfg.tmp
+
+if [ ${#CONFIG} -eq 0 ] ; then
+if [ ${#x_d} -eq 0 ] ; then
+
+echo "You are  installing a new configuration"
+echo -n " OPA_SRC [Y/n] "
+    read answer
+    answer=`echo $answer | sed 's/^[yY].*$/y/'`
+    if [  -z "$answer" -o "x$answer" = "xy" ]; then
+    TAB[1]=OPA_SRC   
+echo " OPA_SRC selected "
+echo "  "
+    else
+echo " OPA_SRC Not selected "
+echo "  "
+    fi
+unset answer
+echo -n " LIM_SRC [Y/n] "
+    read answer
+    answer=`echo $answer | sed 's/^[yY].*$/y/'`
+    if [  -z "$answer" -o "x$answer" = "xy" ]; then
+    TAB[2]=LIM_SRC   
+echo " LIM_SRC selected "
+echo "  "
+    else
+echo " LIM_SRC Not selected "
+echo "  "
+    fi
+unset answer
+echo -n " TOP_SRC [Y/n] "
+    read answer
+    answer=`echo $answer | sed 's/^[yY].*$/y/'`
+    if [  -z "$answer" -o "x$answer" = "xy" ]; then
+    TAB[3]=TOP_SRC   
+echo " TOP_SRC selected "
+echo "  "
+    else
+echo " TOP_SRC Not selected "
+echo "  "
+    fi
+unset answer   
+echo -n " C1D_SRC [Y/n] "
+    read answer
+    answer=`echo $answer | sed 's/^[yY].*$/y/'`
+    if [  -z "$answer" -o "x$answer" = "xy" ]; then
+    TAB[4]=C1D_SRC   
+echo " C1D_SRC selected "
+echo "  "
+    else
+echo " C1D_SRC Not selected "
+echo "  "
+    fi
+unset answer
+echo -n " NST_SRC [Y/n] "
+    read answer
+    answer=`echo $answer | sed 's/^[yY].*$/y/'`
+    if [  -z "$answer" -o "x$answer" = "xy" ]; then
+    TAB[5]=NST_SRC   
+echo " NST_SRC selected "
+echo "  "
+    else
+echo " NST_SRC Not selected "
+echo "  "
+    fi
+unset answer
+
+else
+set -A TAB ${x_d} 
+fi
+print ${m_n} ${TAB[*]} >> ${d_n}/cfg.txt
+fi
+
+
+#- Create the config  --
+r_cfg='ORCA2_LIM'
+if [ ${#x_r} -ne 0 ]; then
+r_cfg=${x_r}
+fi
+
+if  [ ! -d ${d_n}/../../config/${m_n} ]; then
+echo " The new configuration ${x_n} will be based on ${r_cfg} following files:"
+echo "`ls ../${r_cfg}/AA_make*` "
+echo "`ls ../${r_cfg}/scripts/BB_make*` "
+echo "`ls ../${r_cfg}/EXP00/*` "
+echo "`ls ../${r_cfg}/MY_SRC/*` "
+echo "  "
+\mkdir  ${d_n}/../../config/${m_n} 
+\mkdir  ${d_n}/../../config/${m_n}/scripts
+\mkdir  ${d_n}/../../config/${m_n}/EXP00
+\mkdir  ${d_n}/../../config/${m_n}/MY_SRC
+\cp -R ${d_n}/../../config/${r_cfg}/AA_make ${d_n}/../../config/${m_n}/. 
+\cp -R ${d_n}/../../config/${r_cfg}/AA_make.ldef ${d_n}/../../config/${m_n}/. 
+\cp -R ${d_n}/../../config/${r_cfg}/scripts/BB_make ${d_n}/../../config/${m_n}/scripts/. 
+\cp -R ${d_n}/../../config/${r_cfg}/scripts/BB_make.ldef ${d_n}/../../config/${m_n}/scripts/. 
+\cp -R ${d_n}/../../config/${r_cfg}/EXP00/* ${d_n}/../../config/${m_n}/EXP00/. 
+\cp -R ${d_n}/../../config/${r_cfg}/MY_SRC/* ${d_n}/../../config/${m_n}/MY_SRC/. 
+fi
+#- Create the WORK --
+d_m=`find ${d_n}/../.. -name ${m_n}`  ;
+[ -d ${d_m}/WORK ] || mkdir ${d_m}/WORK;
+cd ${d_m}/WORK
+
+#- Clean links and librairies
+[ -n "`\ls`" ] && \rm * 
+
+#- Find the number of directories ---
+NDIR=${#TAB[*]}
+
+#- Creating the good links, at first on OPA_SRC ---
+    echo " Creating ${m_n}/WORK = ${TAB[*]} for ${m_n}"
+
+    i=0
+    while [ i -lt $NDIR ]
+    do
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../../../modeles/NEMO/OPA_SRC/*.[Ffh]90 .
+	[ ${#TAB[i]} -ne 0 ] && [ "${TAB[i]}" = "OPA_SRC" ] && ln -sf ../../../modeles/NEMO/OPA_SRC/*/*.[Ffh]90 . && break
+	let i=$i+1
+    done
+
+    i=0
+    while [ i -lt $NDIR ]
+    do
+      if [ "${TAB[i]}" = "LIM_SRC" ]; then
+	  ln -sf ../../../modeles/NEMO/LIM_SRC/*.[Ffh]90 .  
+      
+      elif [ "${TAB[i]}" = "TOP_SRC" ]; then
+	  \rm trcstp.F90                    
+	  \rm sms.F90                    
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/*.[Ffh] .           
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/*.[Ffh]90 .       
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/SMS/*.[Ffh] .        
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/SMS/*.[Ffh]90 .  
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/TRP/*.[Ffh]90 .
+      
+      elif [ "${TAB[i]}" = "SRC_OFFLINE_TOP" ]; then  
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/*.[Ffh] .
+	  ln -sf ../../../modeles/NEMO/TOP_SRC/SMS/*.[Ffh] .
+	  ln -sf ../../../modeles/NEMO/SRC_OFFLINE_TOP/*.[Ffh] .
+
+      elif [ "${TAB[i]}" = "C1D_SRC" ]; then  
+	  ln -sf ../../../modeles/NEMO/C1D_SRC/*.[Ffh]90 .
+
+      elif [ "${TAB[i]}" = "NST_SRC" ]; then  
+	  ln -sf ../../../modeles/NEMO/NST_SRC/*.[Ffh]90 .
+      fi
+      let i=$i+1
+    done
+
+    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make ; 
+    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
+
+
+    if [ -d ../../../config/${m_n}/MY_SRC ]; then
+        f_list=`\ls ../../../config/${m_n}/MY_SRC/*.[Ffh]90`  ;
+        if [ ${#f_list} -ne 0 ] ; then
+            echo " "
+            echo " Files in the ../config/${m_n}/MY_SRC directory will be taken into account"
+            echo " "
+	    for i in `ls ../../../config/${m_n}/MY_SRC/*.[Ffh]90`
+	       do
+	       [ -f $i ] && \rm $i  
+	       [ -f ../../../config/${m_n}/MY_SRC/$i ] &&  ln -sf ../../../config/${m_n}/MY_SRC/${i} .
+	     done
+        fi
+    fi
+
+#- Building the standard list of source files ---
+cat >.patron <<"EOF" 
+CVS
+SRC_PARAM
+SRC_FILE_LIST
+tmplist
+AA_make
+KEY_CPP
+Makefile
+*?.o
+ i.?*
+*?.L
+.patron
+bloc.com
+para.com
+defcst.f
+fontbc.f
+icdyna.f
+thersf.f
+OPAFILES
+EOF
+
+[ ! -d ../../../config/${m_n}/scripts/Attic ] && \mkdir ../../../config/${m_n}/scripts/Attic
+
+#- Writing KEY_CPP file ---
+sed -e "s/#-Q- sxnec *//" -e /^P_P/\!d -e "s/P_P = //" AA_make.ldef > ../../../config/${m_n}/scripts/Attic/KEY_CPP  
+ln -sf ../../../config/${m_n}/scripts/Attic/KEY_CPP .  
+
+#- Creating SRC list ---
+ls -1 | fgrep -v -f .patron  > ../../../config/${m_n}/scripts/Attic/SRC_FILE_LIST
+ln -sf ../../../config/${m_n}/scripts/Attic/SRC_FILE_LIST .
+cp SRC_FILE_LIST SRC_FILE_LIST.temp   
+
+#- Save new configuration and directories names ---
+print ${m_n} ${TAB[*]} >.config 
+
+#- Create repository to store modified files
+[ ! -d ../../../config/${m_n}/MY_SRC ] && \mkdir ../../../config/${m_n}/MY_SRC
+cp ../../../modeles/NEMO/OPA_SRC/par_oce.F90 ../../../config/${m_n}/MY_SRC/par_oce.F90_keep
+if [ -d ../../../config/HEAD/2TEST ]; then
+    f_2test=`\ls ../../../config/HEAD/2TEST/*.[Ffh]90`  ;
+    if [ ${#f_2test} -ne 0 ] ; then
+        echo " "
+        echo " Files in the ../config/HEAD/2TEST directory will be taken into account"
+        echo " "
+        for i in `ls ../../../config/HEAD/2TEST/*.[Ffh]90`
+          do
+             ln -sf ../../../config/HEAD/2TEST/${i} ../../../config/${m_n}/MY_SRC/.
+          done
+    fi
+fi
+
+unset m_n
+unset TAB
+unset CONFIG
+exit 0;
